// $Id$ // // File: DTrack_factory.cc // Created: Wed Sep 3 09:33:40 EDT 2008 // Creator: davidl (on Darwin harriet.jlab.org 8.11.1 i386) // #include #include using namespace std; #include "DTrack_factory.h" #include #include #include #include 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; } //------------------ // init //------------------ jerror_t DTrack_factory::init(void) { fitter = NULL; return NOERROR; } //------------------ // brun //------------------ jerror_t DTrack_factory::brun(jana::JEventLoop *loop, int runnumber) { // Get pointer to TrackFitter 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!"< candidates; vector cdctrackhits; vector fdcpseudos; loop->Get(candidates); loop->Get(cdctrackhits); loop->Get(fdcpseudos); // Loop over candidates for(unsigned int i=0; iGetDMagneticFieldMap())); DReferenceTrajectory *rt = rtv[_data.size()]; // Swim a reference trajectory with this candidate's parameters rt->Swim(candidate->position(), candidate->momentum(), candidate->charge()); if(rt->Nswim_steps<1)continue; #if 0 // Get CDC and FDC hits from candidate vector cdchits; vector fdchits; candidate->Get(cdchits); candidate->Get(fdchits); sort(cdchits.begin(), cdchits.end(), CDCSortByRincreasing); sort(fdchits.begin(), fdchits.end(), FDCSortByZincreasing); #endif // Setup fitter to do fit fitter->Reset(); AddCDCTrackHits(rt, cdctrackhits); AddFDCPseudoHits(rt, fdcpseudos); fitter->SetFitType(DTrackFitter::kWireBased); // Do the fit DTrackFitter::fit_status_t status = fitter->FitTrack(*candidate); switch(status){ case DTrackFitter::kFitNotDone: _DBG_<<"Fitter returned kFitNotDone. This should never happen!!"< &cdctrackhits) { /// Determine the probability that for each CDC hit that it came from the track with the given trajectory. /// /// This will calculate a probability for each CDC hit that /// it came from the track represented by the given /// DReference trajectory. The probability is based on /// the residual between the distance of closest approach /// of the trajectory to the wire and the drift time. // Calculate beta of particle assuming its a pion for now. If the // particles is really a proton or an electron, the residual // calculated below will only be off by a little. double TOF_MASS = 0.13957018; double beta = 1.0/sqrt(1.0+TOF_MASS*TOF_MASS/rt->swim_steps[0].mom.Mag2()); // The error on the residual. This should include the // error from measurement,track parameters, and multiple // scattering. //double sigma = sqrt(pow(SIGMA_CDC,2.0) + pow(0.4000,2.0)); double sigma = 0.8/sqrt(12.0); // Minimum probability of hit belonging to wire and still be accepted double MIN_HIT_PROB = 0.2; for(unsigned int j=0; jDistToRT(hit->wire, &s); // Distance using drift time // NOTE: Right now we assume pions for the TOF // and a constant drift velocity of 55um/ns double tof = s/(beta*3E10*1E-9); double dist = (hit->tdrift - tof)*55E-4; // Residual //double resi = dist - doca; double resi = doca - 0.4; double chisq = pow(resi/sigma, 2.0); // Use chi-sq probaility function with Ndof=1 to calculate probability double probability = TMath::Prob(chisq/4.0, 1); if(probability>=MIN_HIT_PROB)fitter->AddHit(hit); if(debug_level>10)_DBG_<<"s="<