// $Id: DTrackWireBased_factory.cc 5612 2009-10-15 20:51:25Z staylor $ // // File: DTrackWireBased_factory.cc // Created: Wed Sep 3 09:33:40 EDT 2008 // Creator: davidl (on Darwin harriet.jlab.org 8.11.1 i386) // #include #include #include using namespace std; #include "DTrackWireBased_factory.h" #include #include #include #include #include #include #define C_EFFECTIVE 15. using namespace jana; //------------------ // CDCSortByRincreasing //------------------ bool CDCSortByRincreasing(const DCDCTrackHit* const &hit1, const DCDCTrackHit* const &hit2) { // use the ring number to sort by R(decreasing) and then straw(increasing) if(hit1->wire->ring == hit2->wire->ring){ return hit1->wire->straw < hit2->wire->straw; } return hit1->wire->ring < hit2->wire->ring; } //------------------ // FDCSortByZincreasing //------------------ bool FDCSortByZincreasing(const DFDCPseudo* const &hit1, const DFDCPseudo* const &hit2) { // use the layer number to sort by Z(decreasing) and then wire(increasing) if(hit1->wire->layer == hit2->wire->layer){ return hit1->wire->wire < hit2->wire->wire; } return hit1->wire->layer < hit2->wire->layer; } //------------------ // count_common_members //------------------ template static unsigned int count_common_members(vector &a, vector &b) { unsigned int n=0; for(unsigned int i=0; iSetDefaultParameter("TRKFIT:DEBUG_LEVEL",DEBUG_LEVEL); return NOERROR; } //------------------ // brun //------------------ jerror_t DTrackWireBased_factory::brun(jana::JEventLoop *loop, int runnumber) { // Get the geometry DApplication* dapp=dynamic_cast(loop->GetJApplication()); geom = dapp->GetDGeometry(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_<<"Unable to get a DTrackFitter object! NO Charged track fitting will be done!"<SetDefaultParameter("TRKFIT:SKIP_MASS_HYPOTHESES_WIRE_BASED", SKIP_MASS_HYPOTHESES_WIRE_BASED); USE_HITS_FROM_CANDIDATE=false; gPARMS->SetDefaultParameter("TRKFIT:USE_HITS_FROM_CANDIDATE", USE_HITS_FROM_CANDIDATE); MIN_FIT_P = 0.050; // GeV gPARMS->SetDefaultParameter("TRKFIT:MIN_FIT_P", MIN_FIT_P, "Minimum fit momentum in GeV/c for fit to be considered successful"); if (SKIP_MASS_HYPOTHESES_WIRE_BASED==false){ ostringstream locMassStream_Positive, locMassStream_Negative; locMassStream_Positive << ParticleMass(PiPlus) << ", " << ParticleMass(KPlus) << ", " << ParticleMass(Proton); locMassStream_Negative << ParticleMass(PiMinus) << ", " << ParticleMass(KMinus); string MASS_HYPOTHESES_POSITIVE = locMassStream_Positive.str(); string MASS_HYPOTHESES_NEGATIVE = locMassStream_Negative.str(); cout << "pos stream = " << MASS_HYPOTHESES_POSITIVE << endl; cout << "neg stream = " << MASS_HYPOTHESES_NEGATIVE << endl; // string MASS_HYPOTHESES_POSITIVE = "0.13957,0.493677,0.93827"; // string MASS_HYPOTHESES_NEGATIVE = "0.13957,0.493677"; gPARMS->SetDefaultParameter("TRKFIT:MASS_HYPOTHESES_POSITIVE", MASS_HYPOTHESES_POSITIVE); gPARMS->SetDefaultParameter("TRKFIT:MASS_HYPOTHESES_NEGATIVE", MASS_HYPOTHESES_NEGATIVE); // Parse MASS_HYPOTHESES strings to make list of masses to try SplitString(MASS_HYPOTHESES_POSITIVE, mass_hypotheses_positive, ","); SplitString(MASS_HYPOTHESES_NEGATIVE, mass_hypotheses_negative, ","); if(mass_hypotheses_positive.size()==0)mass_hypotheses_positive.push_back(0.0); // If empty string is specified, assume they want massless particle if(mass_hypotheses_negative.size()==0)mass_hypotheses_negative.push_back(0.0); // If empty string is specified, assume they want massless particle } if(DEBUG_HISTS){ dapp->Lock(); // Histograms may already exist. (Another thread may have created them) // Try and get pointers to the existing ones. dapp->Unlock(); } // Get the particle ID algorithms vector locPIDAlgorithms; loop->Get(locPIDAlgorithms); if(locPIDAlgorithms.size() < 1){ _DBG_<<"Unable to get a DParticleID object! NO PID will be done!"<(locPIDAlgorithms[0]); return NOERROR; } //------------------ // evnt //------------------ jerror_t DTrackWireBased_factory::evnt(JEventLoop *loop, int eventnumber) { if(!fitter)return NOERROR; if(rtv.size() > MAX_DReferenceTrajectoryPoolSize){ for(size_t loc_i = MAX_DReferenceTrajectoryPoolSize; loc_i < rtv.size(); ++loc_i) delete rtv[loc_i]; rtv.resize(MAX_DReferenceTrajectoryPoolSize); } // Get candidates and hits vector candidates; loop->Get(candidates); if (candidates.size()==0) return NOERROR; // Count the number of tracks we'll be fitting unsigned int Ntracks_to_fit = 0; if (SKIP_MASS_HYPOTHESES_WIRE_BASED){ Ntracks_to_fit=candidates.size(); } else{ for(unsigned int i=0; icharge()<0.0 ? mass_hypotheses_negative.size():mass_hypotheses_positive.size(); } } // Deallocate some reference trajectories occasionally unsigned int rts_to_keep = 10; if(Ntracks_to_fit>rts_to_keep)rts_to_keep=Ntracks_to_fit; for(unsigned int i=rts_to_keep; imomentum().Mag()GetDMagneticFieldMap())); } DReferenceTrajectory *rt = rtv[_data.size()]; if(locNumInitialReferenceTrajectories == rtv.size()) //didn't create a new one rt->Reset(); rt->SetDGeometry(geom); rt->q = candidate->charge(); if (SKIP_MASS_HYPOTHESES_WIRE_BASED){ DoFit(i,candidate,rt,loop,0.13957); } else{ // Choose list of mass hypotheses based on charge of candidate vector mass_hypotheses; if(candidate->charge()<0.0){ mass_hypotheses = mass_hypotheses_negative; }else{ mass_hypotheses = mass_hypotheses_positive; } if ((!isfinite(candidate->momentum().Mag())) || (!isfinite(candidate->position().Mag()))) _DBG_ << "Invalid seed data for event "<< eventnumber <<"..."<1){_DBG__;_DBG_<<"---- Starting wire based fit with mass: "<2)_DBG_<<"Looking for clones of wire-based tracks ..."< indexes_to_delete; for(unsigned int i=0; i<_data.size()-1; i++){ DTrackWireBased *dtrack1 = _data[i]; vector cdchits1; vector fdchits1; dtrack1->Get(cdchits1); dtrack1->Get(fdchits1); JObject::oid_t cand1=dtrack1->candidateid; for(unsigned int j=i+1; j<_data.size(); j++){ DTrackWireBased *dtrack2 = _data[j]; if (dtrack2->candidateid==cand1) continue; if (dtrack2->mass() != dtrack1->mass())continue; vector cdchits2; vector fdchits2; dtrack2->Get(cdchits2); dtrack2->Get(fdchits2); // Count number of cdc and fdc hits in common unsigned int Ncdc = count_common_members(cdchits1, cdchits2); unsigned int Nfdc = count_common_members(fdchits1, fdchits2); if(Ncdc!=cdchits1.size() && Ncdc!=cdchits2.size())continue; if(Nfdc!=fdchits1.size() && Nfdc!=fdchits2.size())continue; unsigned int total = Ncdc + Nfdc; unsigned int total1 = cdchits1.size()+fdchits1.size(); unsigned int total2 = cdchits2.size()+fdchits2.size(); if(total!=total1 && total!=total2)continue; if(total1candidateid=cand1; indexes_to_delete.insert(i); }else{ indexes_to_delete.insert(j); } } } if(DEBUG_LEVEL>2)_DBG_<<"Found "< new_data; for(unsigned int i=0; i<_data.size(); i++){ if(indexes_to_delete.find(i)==indexes_to_delete.end()){ new_data.push_back(_data[i]); }else{ delete _data[i]; if(DEBUG_LEVEL>1)_DBG_<<"Deleting clone wire-based track "<Reset(); fitter->SetFitType(DTrackFitter::kWireBased); // Get the hits from the track candidate vectormyfdchits; candidate->GetT(myfdchits); fitter->AddHits(myfdchits); vectormycdchits; candidate->GetT(mycdchits); fitter->AddHits(mycdchits); status=fitter->FitTrack(candidate->position(),candidate->momentum(), candidate->charge(),mass,0.); } else{ fitter->SetFitType(DTrackFitter::kWireBased); // Swim a reference trajectory using the candidate starting momentum // and position rt->SetMass(mass); rt->Swim(candidate->position(),candidate->momentum(),candidate->charge()); status=fitter->FindHitsAndFitTrack(*candidate,rt,loop,mass); if (status==DTrackFitter::kFitNotDone){ // Get the hits from the candidate vectormyfdchits; candidate->GetT(myfdchits); fitter->AddHits(myfdchits); vectormycdchits; candidate->GetT(mycdchits); fitter->AddHits(mycdchits); status=fitter->FitTrack(candidate->position(),candidate->momentum(), candidate->charge(),mass,0.); } } // Check the status of the fit switch(status){ case DTrackFitter::kFitNotDone: _DBG_<<"Fitter returned kFitNotDone. This should never happen!!"<GetFitParameters(); track_kd->setPID(dPIDAlgorithm->IDTrack(track_kd->charge(), track_kd->mass())); track_kd->setTime(track_kd->t0()); // Fill reference trajectory rt->Reset(); rt->q = candidate->charge(); rt->SetMass(track_kd->mass()); rt->Swim(track->position(), track->momentum(), track->charge()); track->rt = rt; track->chisq = fitter->GetChisq(); track->Ndof = fitter->GetNdof(); track->pulls = fitter->GetPulls(); track->candidateid = c_id+1; // Add hits used as associated objects vector cdchits = fitter->GetCDCFitHits(); vector fdchits = fitter->GetFDCFitHits(); sort(cdchits.begin(), cdchits.end(), CDCSortByRincreasing); sort(fdchits.begin(), fdchits.end(), FDCSortByZincreasing); for(unsigned int m=0; mAddAssociatedObject(cdchits[m]); for(unsigned int m=0; mAddAssociatedObject(fdchits[m]); // Add DTrackCandidate as associated object track->AddAssociatedObject(candidate); _data.push_back(track); break; } default: break; } }