Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DTrackHitSelectorTHROWN.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTrackHitSelectorTHROWN.cc
4 // Created: Mon Mar 9 09:03:03 EDT 2009
5 // Creator: davidl (on Darwin harriet.jlab.org 9.6.0 i386)
6 //
7 
9 #include <TRACKING/DMCThrown.h>
10 #include <TRACKING/DMCTrackHit.h>
11 #include <GlueX.h>
12 
14 
15 
16 //---------------------------------
17 // DTrackHitSelectorTHROWN (Constructor)
18 //---------------------------------
20 {
21  HS_DEBUG_LEVEL = 0;
22  gPARMS->SetDefaultParameter("TRKFIT:HS_DEBUG_LEVEL", HS_DEBUG_LEVEL);
23 }
24 
25 //---------------------------------
26 // ~DTrackHitSelectorTHROWN (Destructor)
27 //---------------------------------
29 {
30 
31 }
32 
33 //---------------------------------
34 // GetCDCHits
35 //---------------------------------
36 void DTrackHitSelectorTHROWN::GetCDCHits(fit_type_t fit_type, const DReferenceTrajectory *rt, const vector<const DCDCTrackHit*> &cdchits_in, vector<const DCDCTrackHit*> &cdchits_out,int N) const
37 {
38  /// Find the hits for the track indicated by the given reference trajectory using truth points.
39  ///
40  /// This will look through the list of charged tracks in DMCThrown and find
41  /// the thrown track that most closely matches the starting parameters in
42  /// "rt". Then, it will look through the DCDCTrackHit objects in cdchits_in
43  /// and attempt to match them up with CDC hits in the DMCTrackHit objects.
44  /// In this way, truth information can be used to generate a list of the
45  /// CDC hits that belong with "rt".
46 
47  // Get the MC track number
48  int track = FindTrackNumber(rt);
49  if(track<1)return;
50 
51  // Get the DMCTrackHit objects
52  vector<const DMCTrackHit*> mctrackhits;
53  loop->Get(mctrackhits);
54 
55  // Here is the hard part. We need to match the hits in cdchits_in with hits
56  // in DMCTrackHit objects. We do this by checking on the distance the truth
57  // point is from the wire and comparing it to the drift+tof time.
58  for(unsigned int i=0; i<cdchits_in.size(); i++){
59  const DCDCTrackHit *hit = cdchits_in[i];
60 
61  const DMCTrackHit* mchit = GetMCTrackHit(hit->wire, hit->tdrift*55.0E-4, mctrackhits, track);
62  if(mchit)cdchits_out.push_back(cdchits_in[i]);
63  }
64 }
65 
66 //---------------------------------
67 // GetFDCHits
68 //---------------------------------
69 void DTrackHitSelectorTHROWN::GetFDCHits(fit_type_t fit_type, const DReferenceTrajectory *rt, const vector<const DFDCPseudo*> &fdchits_in, vector<const DFDCPseudo*> &fdchits_out,int N) const
70 {
71  /// Find the hits for the track indicated by the given reference trajectory using truth points.
72  ///
73  /// This will look through the list of charged tracks in DMCThrown and find
74  /// the thrown track that most closely matches the starting parameters in
75  /// "rt". Then, it will look through the DFDCPseudo objects in cdchits_in
76  /// and attempt to match them up with FDC hits in the DMCTrackHit objects.
77  /// In this way, truth information can be used to generate a list of the
78  /// FDC hits that belong with "rt".
79 
80  // Get the MC track number
81  int track = FindTrackNumber(rt);
82  if(track<1)return;
83 
84  // Get the DMCTrackHit objects
85  vector<const DMCTrackHit*> mctrackhits;
86  loop->Get(mctrackhits);
87 
88  // Here is the hard part. We need to match the hits in cdchits_in with hits
89  // in DMCTrackHit objects. We do this by checking on the distance the truth
90  // point is from the wire and comparing it to the drift+tof time.
91  for(unsigned int i=0; i<fdchits_in.size(); i++){
92  const DFDCPseudo *hit = fdchits_in[i];
93 
94  const DMCTrackHit* mchit = GetMCTrackHit(hit->wire, hit->time*55.0E-4, mctrackhits, track);
95  if(mchit)fdchits_out.push_back(fdchits_in[i]);
96  }
97 }
98 
99 //---------------------------------
100 // FindTrackNumber
101 //---------------------------------
103 {
104  if(rt->Nswim_steps<1)return 0;
105  DVector3 &mom = rt->swim_steps[0].mom;
106 
107  vector<const DMCThrown*> throwns;
108  loop->Get(throwns);
109 
110  int myid = 0;
111  double min_chisq=1.0E8;
112  for(unsigned int i=0; i<throwns.size(); i++){
113  const DMCThrown *thrown = throwns[i];
114  DVector3 mc_mom = thrown->momentum();
115 
116  if(mom.Mag()<1.0E-9)continue; // Thrown momentum should be > 1eV/c
117 
118  // Round-off errors can cause cos_phi to be outside the allowed range of -1 to +1
119  // Force it to be inside that range in necessary.
120  double cos_phi = mom.Dot(mc_mom)/mom.Mag()/mc_mom.Mag();
121  if(cos_phi>1.)cos_phi=1.0;
122  if(cos_phi<-1.)cos_phi=-1.0;
123 
124  double delta_pt = (mom.Pt()-mc_mom.Pt())/mc_mom.Pt();
125  double delta_theta = (mom.Theta() - mc_mom.Theta())*1000.0; // in milliradians
126  double delta_phi = acos(cos_phi)*1000.0; // in milliradians
127  double chisq = pow(delta_pt/0.04, 2.0) + pow(delta_theta/20.0, 2.0) + pow(delta_phi/20.0, 2.0);
128 
129  if(chisq<min_chisq)myid = thrown->myid;
130  }
131 
132  return myid;
133 }
134 
135 //---------------------------------
136 // GetMCTrackHit
137 //---------------------------------
138 const DMCTrackHit* DTrackHitSelectorTHROWN::GetMCTrackHit(const DCoordinateSystem *wire, double rdrift, vector<const DMCTrackHit*> &mctrackhits, int trackno_filter)
139 {
140  /// Identify the DMCTrackHit object (if any) that best matches a hit on
141  /// a given wire with a given drift distance.
142  ///
143  /// This is static function and so can be used outside of this class.
144  /// As such, the list of DMCTrackHits must be supplied by the caller.
145  /// Also, the trackno_filter parameter is optional for use on checking
146  /// only hits originating from a specific thrown track.
147 
148  // We can decide whether this is a CDC or FDC wire based on the z-component.
149  // We do this to make it quicker and easier to run through the DMCTrackHits
150  // below. Note that wire->udir points along the wire.
151  DetectorSystem_t sys = acos(wire->udir.Z())*57.3 > 10.0 ? SYS_FDC:SYS_CDC;
152 
153  const DMCTrackHit *best_mchit = NULL;
154  double best_resi = 1.0E6;
155  double resi_min = 1.0E6, resiu_min=1.0E6;
156  for(unsigned int j=0; j<mctrackhits.size(); j++){
157  const DMCTrackHit *mchit = mctrackhits[j];
158  if(mchit->system!=sys) continue;
159  if((trackno_filter>0) && (mchit->track!=trackno_filter)) continue;
160  if((trackno_filter>0) && (!mchit->primary)) continue;
161 
162  // Find the vector pointing from the wire to the truth point
163  DVector3 pos_truth(mchit->r*cos(mchit->phi), mchit->r*sin(mchit->phi), mchit->z);
164  double u = (pos_truth - wire->origin).Dot(wire->udir);
165  DVector3 pos_wire_truth = wire->origin + u*wire->udir;
166  DVector3 pos_diff = pos_truth - pos_wire_truth;
167  double r = pos_diff.Mag();
168 
169  // Now, we need to convert the drift time to a distance and compare it
170  // to the distance of the truth hit. Since that includes time-of-flight,
171  // the comparison needs to be loose enough to accomodate that.
172  // The tof should add at most about 6-7 ns to the time which is less
173  // than 400 microns.
174  double resi = rdrift - r;
175 
176  // Distance of truth point past end of wire in either direction. i.e.
177  // a positive value is past the end, a negative value is within the
178  // wire length.
179  double resiu = fabs(u) - wire->L/2.0;
180 
181  if(fabs(resi)<fabs(resi_min))resi_min=resi;
182  if(resiu<resiu_min)resiu_min=resiu;
183 
184  if((fabs(resi)<0.3) && (resiu<4.0)){ // Check if truth point is within 2mm of drift time
185 
186  // A truth point is roughly the same distance from this wire as indicated
187  // by the drift time. Check if this is the best match so far.
188  if(fabs(resi)<fabs(best_resi)){
189  best_resi = resi;
190  best_mchit = mchit;
191  }
192  }
193  }
194 
195  return best_mchit;
196 }
197 
Definition: track.h:16
DTrackHitSelectorTHROWN(jana::JEventLoop *loop)
const DCDCWire * wire
Definition: DCDCTrackHit.h:37
TVector3 DVector3
Definition: DVector3.h:14
void GetFDCHits(fit_type_t fit_type, const DReferenceTrajectory *rt, const vector< const DFDCPseudo * > &fdchits_in, vector< const DFDCPseudo * > &fdchits_out, int N=0) const
const DFDCWire * wire
DFDCWire for this wire.
Definition: DFDCPseudo.h:92
DetectorSystem_t
Definition: GlueX.h:15
class DFDCPseudo: definition for a reconstructed point in the FDC
Definition: DFDCPseudo.h:74
static const DMCTrackHit * GetMCTrackHit(const DCoordinateSystem *wire, double rdrift, vector< const DMCTrackHit * > &mctrackhits, int trackno_filter=-1)
The DTrackHitSelector class is a base class for algorithms that will select hits from the drift chamb...
Definition: GlueX.h:17
DetectorSystem_t system
particle type
Definition: DMCTrackHit.h:25
float z
coordinates of hit in cm and rad
Definition: DMCTrackHit.h:20
Definition: GlueX.h:18
void GetCDCHits(fit_type_t fit_type, const DReferenceTrajectory *rt, const vector< const DCDCTrackHit * > &cdchits_in, vector< const DCDCTrackHit * > &cdchits_out, int N=0) const
double time
time corresponding to this pseudopoint.
Definition: DFDCPseudo.h:93
double sin(double)
int primary
primary track=1 not primary track=0
Definition: DMCTrackHit.h:23
const DVector3 & momentum(void) const
int FindTrackNumber(const DReferenceTrajectory *rt) const
int track
Track number.
Definition: DMCTrackHit.h:21
union @6::@8 u
int myid
id of this particle from original generator
Definition: DMCThrown.h:22