// $Id$ // // File: DParticle_factory_THROWN.cc // Created: Sat Oct 4 22:04:56 EDT 2008 // Creator: davidl (on Darwin Amelia.local 8.11.1 i386) // #include using namespace std; #include #include #include #include #include "DParticle_factory_THROWN.h" #include #include #include #include #include #include using namespace jana; //------------------ // Constructor //------------------ DParticle_factory_THROWN::DParticle_factory_THROWN() { fitter = NULL; hitselector = NULL; } //------------------ // brun //------------------ jerror_t DParticle_factory_THROWN::brun(jana::JEventLoop *loop, int runnumber) { // Get pointer to DTrackFitter object that actually fits a track vector fitters; loop->Get(fitters); if(fitters.size()<1){ _DBG_<<"Unable to get a DTrackFitter object! NO Charged track fitting will be done!"<(fitters[0]); // Warn user if something happened that caused us NOT to get a fitter object pointer if(!fitter){ _DBG_<<"ERROR: Unable to get a DTrackFitter object! Chisq for DParticle:THROWN will NOT be calculated!"< hitselectors; loop->Get(hitselectors); if(hitselectors.size()<1){ _DBG_<<"ERROR: Unable to get a DTrackHitSelector object! NO DParticle:THROWN objects will be created!"< mcthrowns; vector cdctrackhits; vector fdcpseudos; loop->Get(mcthrowns); loop->Get(cdctrackhits); loop->Get(fdcpseudos, "CORRECTED"); for(unsigned int i=0; i< mcthrowns.size(); i++){ const DMCThrown *thrown = mcthrowns[i]; const DKinematicData *kd_thrown = thrown; if(fabs(thrown->charge())<1)continue; // First, copy over the DKinematicData part DParticle *particle = new DParticle; DKinematicData *kd_particle = particle; *kd_particle = *kd_thrown; // Add DMCThrown as associated object particle->AddAssociatedObject(thrown); // We need to swim a reference trajectory here. To avoid the overhead // of allocating/deallocating them every event, we keep a pool and // re-use them. If the pool is not big enough, then add one to the // pool. if(rt_pool.size()<=_data.size()){ // This is a little ugly, but only gets called a few times throughout the life of the process // Note: these never get deleted, even at the end of process. DApplication* dapp = dynamic_cast(loop->GetJApplication()); rt_pool.push_back(new DReferenceTrajectory(dapp->GetBfield())); } DReferenceTrajectory *rt = rt_pool[_data.size()]; particle->rt = rt; DVector3 pos = particle->position(); DVector3 mom = particle->momentum(); rt->Swim(pos, mom, particle->charge()); // Find hits that should be on this track and add them as associated objects vector cdchits; vector fdchits; if(hitselector)hitselector->GetCDCHits(DTrackHitSelector::kWireBased, rt, cdctrackhits, cdchits); if(hitselector)hitselector->GetFDCHits(DTrackHitSelector::kWireBased, rt, fdcpseudos, fdchits); for(unsigned int i=0; iAddAssociatedObject(cdchits[i]); for(unsigned int i=0; iAddAssociatedObject(fdchits[i]); // We want to get chisq and Ndof values for this track using the hits from above. // We do this using the DTrackFitter object. This more or less guarantees that the // chisq calculation is done in the same way as it is for track fitting. Note // that no fitting is actually done here so this should be reasonably fast if(fitter){ fitter->Reset(); fitter->AddHits(cdchits); fitter->AddHits(fdchits); double chisq; int Ndof; fitter->ChiSq(DTrackFitter::kTimeBased, rt, &chisq, &Ndof); particle->chisq = chisq; particle->Ndof = Ndof; }else{ particle->chisq = 0.0; particle->Ndof = 0; } _data.push_back(particle); } return NOERROR; }