// $Id$ // // File: DTrackTimeBased_factory_Kalman.cc // Created: Thu Sep 4 14:02:44 EDT 2008 // Creator: davidl (on Darwin harriet.jlab.org 8.11.1 i386) // // This is a copy of the DTrackTimeBased_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 "DTrackTimeBased_factory_Kalman.h" #include #include #include #include using namespace jana; //------------------ // init //------------------ jerror_t DTrackTimeBased_factory_Kalman::init(void) { fitter = NULL; DEBUG_LEVEL = 0; MOMENTUM_CUT_FOR_DEDX=0.5; gPARMS->SetDefaultParameter("TRKFIT:DEBUG_LEVEL", DEBUG_LEVEL); gPARMS->SetDefaultParameter("TRKFIT:MOMENTUM_CUT_FOR_DEDX",MOMENTUM_CUT_FOR_DEDX); return NOERROR; } //------------------ // brun //------------------ jerror_t DTrackTimeBased_factory_Kalman::brun(jana::JEventLoop *loop, int runnumber) { // Get pointer to TrackFitter 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); // Reserve the first mass hypothesis slot for the one decided on by the wire-base fit mass_hypotheses.push_back(0.0); // 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())); } return NOERROR; } //------------------ // evnt //------------------ jerror_t DTrackTimeBased_factory_Kalman::evnt(JEventLoop *loop, int eventnumber) { if(!fitter)return NOERROR; // Get candidates and hits vector tracks; loop->Get(tracks,"Kalman"); // Loop over candidates for(unsigned int i=0; iGetDMagneticFieldMap())); DReferenceTrajectory *rt = rtv[_data.size()]; // Copy in the mass from the wire-based fit as the first one to try mass_hypotheses[0] = track->mass(); // 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 DTrackTimeBased *best_track = NULL; double best_fom = 0.0; for(unsigned int j=0; j1.0E-5)break; // Don't try the same mass twice! if(j!=0 && mass_hypotheses[j]==mass_hypotheses[0])continue; if(DEBUG_LEVEL>1){_DBG__;_DBG_<<"---- Starting time based fit with mass: "<SetFitType(DTrackFitter::kTimeBased); DTrackFitter::fit_status_t status = fitter->FindHitsAndFitTrack(*track, rt, loop, mass_hypotheses[j]); DTrackTimeBased *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="<GetDMagneticFieldMap())); DReferenceTrajectory *rt = rtv[_data.size()]; DTrackTimeBased *timebased_track = new DTrackTimeBased; // Copy over DKinematicData part DKinematicData *track_kd = timebased_track; *track_kd = fitter->GetFitParameters(); rt->SetMass(track_kd->mass()); rt->Swim(timebased_track->position(), timebased_track->momentum(), timebased_track->charge()); timebased_track->rt = rt; timebased_track->chisq = fitter->GetChisq(); timebased_track->Ndof = fitter->GetNdof(); timebased_track->trackid = track->id; // Add hits used as associated objects const vector &cdchits = fitter->GetCDCFitHits(); const vector &fdchits = fitter->GetFDCFitHits(); for(unsigned int i=0; iAddAssociatedObject(cdchits[i]); for(unsigned int i=0; iAddAssociatedObject(fdchits[i]); // Add DTrack object as associate object timebased_track->AddAssociatedObject(track); return timebased_track; } //------------------ // GetFOM //------------------ double DTrackTimeBased_factory_Kalman::GetFOM(DTrackTimeBased *dtrack) { double dedx,mean_path_length,p_avg; unsigned int num_hits=0; if (fitter->GetdEdx(dtrack->rt,dedx,mean_path_length,p_avg,num_hits) ==NOERROR){ dtrack->setdEdx(dedx); double dedx_sigma=fitter->GetdEdxSigma(num_hits,mean_path_length); double dedx_most_probable=fitter->GetdEdx(p_avg,dtrack->rt->GetMass(),mean_path_length); //figure of merit double prob=TMath::Prob(fitter->GetChisq(),fitter->GetNdof()); return ( prob*dedx_sigma/fabs(dedx/dedx_most_probable-1.) ); } // If we got here, GetdEdx failed for this track dtrack->setdEdx(0.); return 0.; }