// $Id$ // // File: DTrack_factory_Kalman.cc // Created: Wed Sep 3 09:33:40 EDT 2008 // Creator: davidl (on Darwin harriet.jlab.org 8.11.1 i386) // // This is an exact copy of the DTrack_factory.cc file except // it is hardwired to use the "Kalman" tagged track fitting // algorithm. This is so one can get tracks fit by the Kalman // and ALT1 methods simultaneously in the same program for the // same event. #include #include using namespace std; #include "DTrack_factory_Kalman.h" #include #include #include #include using namespace jana; //------------------ // CDCSortByRincreasing //------------------ bool static 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 static 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; } //------------------ // init //------------------ jerror_t DTrack_factory_Kalman::init(void) { fitter = NULL; DEBUG_LEVEL = 0; gPARMS->SetDefaultParameter("TRKFIT:DEBUG_LEVEL", DEBUG_LEVEL); return NOERROR; } //------------------ // brun //------------------ jerror_t DTrack_factory_Kalman::brun(jana::JEventLoop *loop, int runnumber) { // Get pointer to DTrackFitter object that actually fits a track vector fitters; loop->Get(fitters, "Kalman"); 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:MASS_HYPOTHESES", MASS_HYPOTHESES); // Parse MASS_HYPOTHESES string to make list of masses to try if(MASS_HYPOTHESES.length()>0){ string &str = MASS_HYPOTHESES; unsigned int cutAt; while( (cutAt = str.find(",")) != (unsigned int)str.npos ){ if(cutAt > 0)mass_hypotheses.push_back(atof(str.substr(0,cutAt).c_str())); str = str.substr(cutAt+1); } if(str.length() > 0)mass_hypotheses.push_back(atof(str.c_str())); }else{ mass_hypotheses.push_back(0.0); // If empty string is specified, assume they want massless particle } return NOERROR; } //------------------ // evnt //------------------ jerror_t DTrack_factory_Kalman::evnt(JEventLoop *loop, int eventnumber) { if(!fitter)return NOERROR; // Get candidates and hits vector candidates; loop->Get(candidates); // Loop over candidates for(unsigned int i=0; iGetDMagneticFieldMap())); DReferenceTrajectory *rt = rtv[_data.size()]; // Loop over potential particle masses until one is found that gives a chisq/Ndof<3.0 // If none does, then use the one with the smallest chisq DTrack *best_track = NULL; double best_fom = 0.0; for(unsigned int j=0; j1){_DBG__;_DBG_<<"---- Starting wire based fit for candidate "<SetFitType(DTrackFitter::kWireBased); DTrackFitter::fit_status_t status = fitter->FindHitsAndFitTrack(*candidate, rt, loop, mass_hypotheses[j]); DTrack *dtrack = NULL; switch(status){ case DTrackFitter::kFitNotDone: _DBG_<<"Fitter returned kFitNotDone. This should never happen!!"<Ndof < 1){ if(DEBUG_LEVEL>1)_DBG_<<"-- new track with mass "<1)_DBG_<<"-- first successful fit this candidate with mass: "< best_fom){ if(DEBUG_LEVEL>1)_DBG_<<"-- new best track with mass "<1)_DBG_<<"-- keeping best track with mass "<mass()<<" (old chisq/Ndof="<<(best_track->chisq/best_track->Ndof)<<" , new chisq/Ndof="<<(dtrack->chisq/dtrack->Ndof)<<") (old fom="<2)_DBG_<<"adding wire-based track for candidate "<GetDMagneticFieldMap())); DReferenceTrajectory *rt = rtv[_data.size()]; DTrack *track = new DTrack; // Copy over DKinematicData part DKinematicData *track_kd = track; *track_kd = fitter->GetFitParameters(); 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->candidateid = candidate->id; // 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 i=0; iAddAssociatedObject(cdchits[i]); for(unsigned int i=0; iAddAssociatedObject(fdchits[i]); // Add DTrackCandidate as associated object track->AddAssociatedObject(candidate); return track; } //------------------ // GetFOM //------------------ double DTrack_factory_Kalman::GetFOM(DTrack *dtrack) { //double range_out_fom = GetRangeOutFOM(dtrack); double chisq_per_dof = dtrack->chisq/(double)dtrack->Ndof; return chisq_per_dof; //double total_fom = exp(-pow(range_out_fom/0.5, 2.0))*exp(-pow(chisq_per_dof/2.0, 2.0)); //return total_fom; }