Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTrackTimeBased_factory_StraightLine.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTrackTimeBased_factory_StraightLine.cc
4 // Created: Wed Mar 13 10:00:17 EDT 2019
5 // Creator: staylor (on Linux ifarm1402.jlab.org 3.10.0-327.el7.x86_64 x86_64)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 using namespace std;
12 
14 #include <CDC/DCDCTrackHit.h>
15 #include <FDC/DFDCPseudo.h>
16 #include <BCAL/DBCALShower.h>
17 #include <FCAL/DFCALShower.h>
18 #include <TOF/DTOFPoint.h>
19 #include <START_COUNTER/DSCHit.h>
20 
21 using namespace jana;
22 
23 //------------------
24 // init
25 //------------------
27 {
28  CDC_MATCH_CUT=2.;
29  gPARMS->SetDefaultParameter("TRKFIT:CDC_MATCH_CUT",CDC_MATCH_CUT);
30  FDC_MATCH_CUT=1.25;
31  gPARMS->SetDefaultParameter("TRKFIT:FDC_MATCH_CUT",FDC_MATCH_CUT);
32 
33 
34  return NOERROR;
35 }
36 
37 //------------------
38 // brun
39 //------------------
40 jerror_t DTrackTimeBased_factory_StraightLine::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
41 {
42  // Get the geometry
43  DApplication* dapp=dynamic_cast<DApplication*>(eventLoop->GetJApplication());
44  const DGeometry *geom = dapp->GetDGeometry(runnumber);
45 
46  // Get the particle ID algorithms
47  eventLoop->GetSingle(dPIDAlgorithm);
48 
49  // Outer detector geometry parameters
50  if (geom->GetDIRCZ(dDIRCz)==false) dDIRCz=1000.;
51  geom->GetFCALZ(dFCALz);
52  vector<double>tof_face;
53  geom->Get("//section/composition/posXYZ[@volume='ForwardTOF']/@X_Y_Z",
54  tof_face);
55  vector<double>tof_plane;
56  geom->Get("//composition[@name='ForwardTOF']/posXYZ[@volume='forwardTOF']/@X_Y_Z/plane[@value='0']", tof_plane);
57  dTOFz=tof_face[2]+tof_plane[2];
58  geom->Get("//composition[@name='ForwardTOF']/posXYZ[@volume='forwardTOF']/@X_Y_Z/plane[@value='1']", tof_plane);
59  dTOFz+=tof_face[2]+tof_plane[2];
60  dTOFz*=0.5; // mid plane between tof planes
61 
62  // Get start counter geometry;
63  if (geom->GetStartCounterGeom(sc_pos,sc_norm)){
64  // Create vector of direction vectors in scintillator planes
65  for (int i=0;i<30;i++){
66  vector<DVector3>temp;
67  for (unsigned int j=0;j<sc_pos[i].size()-1;j++){
68  double dx=sc_pos[i][j+1].x()-sc_pos[i][j].x();
69  double dy=sc_pos[i][j+1].y()-sc_pos[i][j].y();
70  double dz=sc_pos[i][j+1].z()-sc_pos[i][j].z();
71  temp.push_back(DVector3(dx/dz,dy/dz,1.));
72  }
73  sc_dir.push_back(temp);
74  }
75  SC_END_NOSE_Z=sc_pos[0][12].z();
76  SC_BARREL_R=sc_pos[0][0].Perp();
77  SC_PHI_SECTOR1=sc_pos[0][0].Phi();
78  }
79 
80  // Get pointer to TrackFinder object
81  vector<const DTrackFinder *> finders;
82  eventLoop->Get(finders);
83 
84  if(finders.size()<1){
85  _DBG_<<"Unable to get a DTrackFinder object!"<<endl;
86  return RESOURCE_UNAVAILABLE;
87  }
88 
89  // Drop the const qualifier from the DTrackFinder pointer
90  finder = const_cast<DTrackFinder*>(finders[0]);
91 
92  // Get pointer to DTrackFitter object that actually fits a track
93  vector<const DTrackFitter *> fitters;
94  eventLoop->Get(fitters,"StraightTrack");
95  if(fitters.size()<1){
96  _DBG_<<"Unable to get a DTrackFitter object!"<<endl;
97  return RESOURCE_UNAVAILABLE;
98  }
99 
100  // Drop the const qualifier from the DTrackFitter pointer
101  fitter = const_cast<DTrackFitter*>(fitters[0]);
102 
103  return NOERROR;
104 }
105 
106 //------------------
107 // evnt
108 //------------------
109 jerror_t DTrackTimeBased_factory_StraightLine::evnt(JEventLoop *loop, uint64_t eventnumber)
110 {
111  // Get wire-based tracks
112  vector<const DTrackWireBased*> tracks;
113  loop->Get(tracks);
114 
115  // Get hits
116  vector<const DCDCTrackHit *>cdchits;
117  loop->Get(cdchits);
118  vector<const DFDCPseudo *>fdchits;
119  loop->Get(fdchits);
120 
121  // get start counter hits
122  vector<const DSCHit*>sc_hits;
123  loop->Get(sc_hits);
124 
125  // Get TOF points
126  vector<const DTOFPoint*> tof_points;
127  loop->Get(tof_points);
128 
129  // Get BCAL and FCAL showers
130  vector<const DBCALShower*>bcal_showers;
131  loop->Get(bcal_showers);
132 
133  vector<const DFCALShower*>fcal_showers;
134  loop->Get(fcal_showers);
135 
136  // Start with wire-based results, refit with drift times
137  for (unsigned int i=0;i<tracks.size();i++){
138  // Reset the fitter
139  fitter->Reset();
141 
142  const DTrackWireBased *track = tracks[i];
143  DVector3 pos=track->position();
144  DVector3 dir=track->momentum();
145  // Select hits that belong to the track
146  for (unsigned int j=0;j<cdchits.size();j++){
147  double d=finder->FindDoca(pos,dir,cdchits[j]->wire->origin,
148  cdchits[j]->wire->udir);
149  if (d<CDC_MATCH_CUT) fitter->AddHit(cdchits[j]);
150  }
151  for (unsigned int i=0;i<fdchits.size();i++){
152  double pz=dir.z();
153  double tx=dir.x()/pz;
154  double ty=dir.y()/pz;
155  double dz=fdchits[i]->wire->origin.z()-pos.z();
156  DVector2 predpos(pos.x()+tx*dz,pos.y()+ty*dz);
157  DVector2 diff=predpos-fdchits[i]->xy;
158  if (diff.Mod()<FDC_MATCH_CUT) fitter->AddHit(fdchits[i]);
159  }
160 
161  // Estimate t0 for this track
162  double t0=0.;
163  DetectorSystem_t t0_detector=SYS_NULL;
164  GetStartTime(track,sc_hits,tof_points,bcal_showers,fcal_showers,t0,
165  t0_detector);
166 
167  // Fit the track using the list of hits we gathered above
168  if (fitter->FitTrack(pos,dir,1.,0.,t0,t0_detector)==DTrackFitter::kFitSuccess){
169  DTrackTimeBased *timebased_track = new DTrackTimeBased();
170  timebased_track->candidateid=track->candidateid;
171  *static_cast<DTrackingData*>(timebased_track) = fitter->GetFitParameters();
172  timebased_track->chisq = fitter->GetChisq();
173  timebased_track->Ndof = fitter->GetNdof();
174  timebased_track->setPID(PiPlus);
175  timebased_track->FOM = TMath::Prob(timebased_track->chisq, timebased_track->Ndof);
176  timebased_track->pulls =std::move(fitter->GetPulls());
177  timebased_track->extrapolations=std::move(fitter->GetExtrapolations());
178  timebased_track->IsSmoothed = fitter->GetIsSmoothed();
179 
180  // Add hits used as associated objects
181  vector<const DCDCTrackHit*> cdchits_on_track = fitter->GetCDCFitHits();
182  vector<const DFDCPseudo*> fdchits_on_track = fitter->GetFDCFitHits();
183 
184  for (unsigned int k=0;k<cdchits_on_track.size();k++){
185  timebased_track->AddAssociatedObject(cdchits_on_track[k]);
186  }
187  for (unsigned int k=0;k<fdchits_on_track.size();k++){
188  timebased_track->AddAssociatedObject(fdchits_on_track[k]);
189  }
190  timebased_track->measured_cdc_hits_on_track = cdchits_on_track.size();
191  timebased_track->measured_fdc_hits_on_track = fdchits_on_track.size();
192 
193  timebased_track->AddAssociatedObject(track);
194  timebased_track->dCDCRings = dPIDAlgorithm->Get_CDCRingBitPattern(cdchits_on_track);
195  timebased_track->dFDCPlanes = dPIDAlgorithm->Get_FDCPlaneBitPattern(fdchits_on_track);
196 
197  // TODO: figure out the potential hits on straight line tracks
198  timebased_track->potential_cdc_hits_on_track = 0;
199  timebased_track->potential_fdc_hits_on_track = 0;
200 
201  _data.push_back(timebased_track);
202 
203  }
204  }
205 
206  return NOERROR;
207 }
208 
209 //------------------
210 // erun
211 //------------------
213 {
214  return NOERROR;
215 }
216 
217 //------------------
218 // fini
219 //------------------
221 {
222  return NOERROR;
223 }
224 
225 // Get an estimate for the start time for this track
226 void
228  vector<const DSCHit*>&sc_hits,
229  vector<const DTOFPoint*>&tof_points,
230  vector<const DBCALShower*>&bcal_showers,
231  vector<const DFCALShower*>&fcal_showers,
232  double &t0,DetectorSystem_t &t0_detector) const {
233  t0=track->t0();
234  t0_detector=track->t0_detector();
235  double track_t0=t0;
236  double locStartTime = track_t0; // initial guess from tracking
237 
238  // Get start time estimate from Start Counter
239  if (dPIDAlgorithm->Get_StartTime(track->extrapolations.at(SYS_START),sc_hits,locStartTime)){
240  t0=locStartTime;
241  t0_detector=SYS_START;
242  return;
243  }
244 
245  // Get start time estimate from TOF
246  locStartTime = track_t0; // initial guess from tracking
247  if (dPIDAlgorithm->Get_StartTime(track->extrapolations.at(SYS_TOF),tof_points,locStartTime)){
248  t0=locStartTime;
249  t0_detector=SYS_TOF;
250  return;
251  }
252 
253  // Get start time estimate from FCAL
254  locStartTime = track_t0; // initial guess from tracking
255  if (dPIDAlgorithm->Get_StartTime(track->extrapolations.at(SYS_FCAL),fcal_showers,locStartTime)){
256  t0=locStartTime;
257  t0_detector=SYS_FCAL;
258  return;
259  }
260 
261  // Get start time estimate from BCAL
262  locStartTime=track_t0;
263  if (dPIDAlgorithm->Get_StartTime(track->extrapolations.at(SYS_BCAL),bcal_showers,locStartTime)){
264  t0=locStartTime;
265  t0_detector=SYS_BCAL;
266  return;
267  }
268 }
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
int GetNdof(void) const
Definition: DTrackFitter.h:155
Definition: track.h:16
DApplication * dapp
vector< pull_t > & GetPulls(void)
Definition: DTrackFitter.h:162
float chisq
Chi-squared for the track (not chisq/dof!)
jerror_t init(void)
Called once at program start.
double t0(void) const
Definition: DTrackingData.h:23
The DTrackFitter class is a base class for different charged track fitting algorithms. It does not actually fit the track itself, but provides the interface and some common support features most algorthims will need to implement.
Definition: DTrackFitter.h:61
TVector2 DVector2
Definition: DVector2.h:9
TVector3 DVector3
Definition: DVector3.h:14
Definition: GlueX.h:16
bool Get(string xpath, string &sval) const
Definition: DGeometry.h:50
const DVector3 & position(void) const
bool GetIsSmoothed(void) const
Definition: DTrackFitter.h:160
unsigned int potential_cdc_hits_on_track
DetectorSystem_t
Definition: GlueX.h:15
bool GetFCALZ(double &z_fcal) const
z-location of front face of CCAL in cm
Definition: DGeometry.cc:1718
oid_t candidateid
id of DTrackCandidate corresponding to this track
Definition: GlueX.h:19
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
unsigned int dFDCPlanes
void Reset(void)
Definition: DTrackFitter.cc:94
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
const map< DetectorSystem_t, vector< Extrapolation_t > > & GetExtrapolations(void) const
Definition: DTrackFitter.h:163
TLatex tx
double GetChisq(void) const
Definition: DTrackFitter.h:154
Definition: GlueX.h:20
jerror_t fini(void)
Called after last event of last event source has been processed.
void SetFitType(fit_type_t type)
Definition: DTrackFitter.h:170
DGeometry * GetDGeometry(unsigned int run_number)
Definition: GlueX.h:22
#define _DBG_
Definition: HDEVIO.h:12
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
void GetStartTime(const DTrackWireBased *track, vector< const DSCHit * > &sc_hits, vector< const DTOFPoint * > &tof_points, vector< const DBCALShower * > &bcal_showers, vector< const DFCALShower * > &fcal_showers, double &t0, DetectorSystem_t &t0_detector) const
unsigned int potential_fdc_hits_on_track
int Ndof
Number of degrees of freedom in the fit.
const vector< const DCDCTrackHit * > & GetCDCFitHits(void) const
Definition: DTrackFitter.h:139
void setPID(Particle_t locPID)
const vector< const DFDCPseudo * > & GetFDCFitHits(void) const
Definition: DTrackFitter.h:140
unsigned int dCDCRings
vector< DTrackFitter::pull_t > pulls
Holds pulls used in chisq calc. (not including off-diagonals)
void AddHit(const DCDCTrackHit *cdchit)
unsigned int measured_cdc_hits_on_track
const DVector3 & momentum(void) const
fit_status_t FitTrack(const DVector3 &pos, const DVector3 &mom, double q, double mass, double t0=QuietNaN, DetectorSystem_t t0_det=SYS_NULL)
DetectorSystem_t t0_detector(void) const
Definition: DTrackingData.h:25
const DTrackFitter * fitter
oid_t candidateid
which DTrackCandidate this came from
map< DetectorSystem_t, vector< DTrackFitter::Extrapolation_t > > extrapolations
bool GetDIRCZ(double &z_dirc) const
z-location of DIRC in cm
Definition: DGeometry.cc:1735
TDirectory * dir
Definition: bcal_hist_eff.C:31
TH2F * temp
unsigned int measured_fdc_hits_on_track
bool GetStartCounterGeom(vector< vector< DVector3 > > &pos, vector< vector< DVector3 > > &norm) const
Definition: DGeometry.cc:1983
const DTrackingData & GetFitParameters(void) const
Definition: DTrackFitter.h:153