Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DChargedTrackHypothesis.h
Go to the documentation of this file.
1 #ifndef _DChargedTrackHypothesis_
2 #define _DChargedTrackHypothesis_
3 
4 #include <vector>
5 #include <string>
6 #include <memory>
7 #include <limits>
8 
9 #include "DResettable.h"
10 #include <PID/DKinematicData.h>
12 #include <PID/DDetectorMatches.h>
13 
14 using namespace std;
15 
17 {
18  public:
19  JOBJECT_PUBLIC(DChargedTrackHypothesis);
20 
21  //CONSTRUCTORS & OPERATORS
23  DChargedTrackHypothesis(const DChargedTrackHypothesis& locSourceData, bool locShareTrackingFlag = false,
24  bool locShareTimingFlag = false, bool locShareKinematicsFlag = false);
25  DChargedTrackHypothesis(const DTrackTimeBased* locSourceData);
26  DChargedTrackHypothesis& operator=(const DChargedTrackHypothesis& locSourceData);
27 
28  void Reset(void);
29  void Release(void);
30 
31  //SHARE RESOURCES
32  void Share_FromInput(const DChargedTrackHypothesis* locSourceData, bool locShareTrackingFlag, bool locShareTimingFlag, bool locShareKinematicsFlag);
33 
34  //GETTERS
35 
36  //Tracking
37  unsigned int Get_NDF_DCdEdx(void) const{return dTrackingInfo->dNDF_DCdEdx;}
38  double Get_ChiSq_DCdEdx(void) const{return dTrackingInfo->dChiSq_DCdEdx;}
39  const DTrackTimeBased* Get_TrackTimeBased(void) const{return dTrackingInfo->dTrackTimeBased;}
40 
41  //Timing
42  double t0(void) const{return dTimingInfo->dt0;}
43  double t0_err(void) const{return dTimingInfo->dt0_err;}
44  double t1(void) const;
45  double t1_err(void) const;
46  DetectorSystem_t t0_detector(void) const{return dTimingInfo->dt0_detector;}
47  DetectorSystem_t t1_detector(void) const;
48  double Get_TimeAtPOCAToVertex(void) const{return dTimingInfo->dTimeAtPOCAToVertex;}
49  unsigned int Get_NDF_Timing(void) const{return dTimingInfo->dNDF_Timing;}
50  double Get_ChiSq_Timing(void) const{return dTimingInfo->dChiSq_Timing;}
51  double Get_PathLength(void) const;
52  double measuredBeta(void) const{return Get_PathLength()/(29.9792458*(t1() - t0()));}
53 
54  //totals for overall PID determination
55  unsigned int Get_NDF(void) const{return dTimingInfo->dNDF;}
56  double Get_ChiSq(void) const{return dTimingInfo->dChiSq;}
57  double Get_FOM(void) const{return dTimingInfo->dFOM;}
58 
59  //Match params (return nullptr if no match)
60  shared_ptr<const DSCHitMatchParams> Get_SCHitMatchParams(void) const{return dTrackingInfo->dSCHitMatchParams;}
61  shared_ptr<const DTOFHitMatchParams> Get_TOFHitMatchParams(void) const{return dTrackingInfo->dTOFHitMatchParams;}
62  shared_ptr<const DBCALShowerMatchParams> Get_BCALShowerMatchParams(void) const{return dTrackingInfo->dBCALShowerMatchParams;}
63  shared_ptr<const DFCALShowerMatchParams> Get_FCALShowerMatchParams(void) const{return dTrackingInfo->dFCALShowerMatchParams;}
64  shared_ptr<const DDIRCMatchParams> Get_DIRCMatchParams(void) const{return dTrackingInfo->dDIRCMatchParams;}
65 
66 
67 
68  //SETTERS
69 
70  //Timing
71  void Set_T0(double locT0, double locT0Error, DetectorSystem_t locT0Detector);
72  void Set_TimeAtPOCAToVertex(double locTimeAtPOCAToVertex){dTimingInfo->dTimeAtPOCAToVertex = locTimeAtPOCAToVertex;}
73  void Set_ChiSq_Timing(double locChiSq, unsigned int locNDF);
74  void Set_ChiSq_Overall(double locChiSq, unsigned int locNDF, double locFOM);
75 
76  //Tracking
77  void Set_TrackTimeBased(const DTrackTimeBased* locTrackTimeBased){dTrackingInfo->dTrackTimeBased = locTrackTimeBased;}
78  void Set_ChiSq_DCdEdx(double locChiSq, unsigned int locNDF);
79 
80  //Match params
81  void Set_SCHitMatchParams(shared_ptr<const DSCHitMatchParams> locMatchParams){dTrackingInfo->dSCHitMatchParams = locMatchParams;}
82  void Set_TOFHitMatchParams(shared_ptr<const DTOFHitMatchParams> locMatchParams){dTrackingInfo->dTOFHitMatchParams = locMatchParams;}
83  void Set_BCALShowerMatchParams(shared_ptr<const DBCALShowerMatchParams> locMatchParams){dTrackingInfo->dBCALShowerMatchParams = locMatchParams;}
84  void Set_FCALShowerMatchParams(shared_ptr<const DFCALShowerMatchParams> locMatchParams){dTrackingInfo->dFCALShowerMatchParams = locMatchParams;}
85  void Set_DIRCMatchParams(shared_ptr<const DDIRCMatchParams> locMatchParams){dTrackingInfo->dDIRCMatchParams = locMatchParams;}
86 
87  void toStrings(vector<pair<string,string> > &items) const
88  {
89  AddString(items, "candidate","%d", dTrackingInfo->dTrackTimeBased->candidateid);
91  AddString(items, "Track_ChiSq", "%f", dTrackingInfo->dTrackTimeBased->chisq);
92  AddString(items, "dEdx_ChiSq", "%f", dTrackingInfo->dChiSq_DCdEdx);
93  AddString(items, "TOF_ChiSq", "%f", dTimingInfo->dChiSq_Timing);
94  AddString(items, "PID_ChiSq", "%f", dTimingInfo->dChiSq);
95  AddString(items, "PID_FOM", "%f", dTimingInfo->dFOM);
96  }
97 
98  class DTimingInfo : public DResettable
99  {
100  public:
101  void Reset(void);
102  void Release(void){};
103 
104  //t0 is RF time at track poca to common vertex
105  double dt0 = 0.0;
106  double dt0_err = 0.0;
107  DetectorSystem_t dt0_detector = SYS_NULL;
108 
109  unsigned int dNDF_Timing = 0;
110  double dChiSq_Timing = 0.0;
111 
112  //technically, these can depend on the tracking chisq also, but no one in their right mind would change the tracking dE/dx info
113  unsigned int dNDF = 0; //total NDF used for PID determination
114  double dChiSq = 0.0; //total chi-squared used for PID determination
115  double dFOM = 0.0; //overall FOM for PID determination
116 
117  //problem: how to store timing information accurately?
118 
119  //at the comboing stage, we don't want to evaluate the timing at the track POCA to the beamline, because that can be inaccurate
120  //e.g. for very-low-theta tracks this position is not well defined
121  //instead, we want to evaluate it at the POCA to the reconstructed vertex position on a combo-by-combo basis
122 
123  //however, to save memory, we want to share the kinematics (including time!) with the original (non-combo) hypothesis:
124  //both are valid points on the track, and we don't want to recompute the covariance matrix (TONS of memory needed), etc.
125  //So, that means we need to store the time at the poca to the vertex separately
126  double dTimeAtPOCAToVertex = 0.0;
127  };
128 
129  class DTrackingInfo : public DResettable
130  {
131  public:
132  void Reset(void);
133  void Release(void){Reset();};
134 
135  unsigned int dNDF_DCdEdx = 0;
136  double dChiSq_DCdEdx = 0.0;
137 
138  const DTrackTimeBased* dTrackTimeBased = nullptr; //can get candidateid from here
139 
140  shared_ptr<const DSCHitMatchParams> dSCHitMatchParams = nullptr;
141  shared_ptr<const DTOFHitMatchParams> dTOFHitMatchParams = nullptr;
142  shared_ptr<const DBCALShowerMatchParams> dBCALShowerMatchParams = nullptr;
143  shared_ptr<const DFCALShowerMatchParams> dFCALShowerMatchParams = nullptr;
144  shared_ptr<const DDIRCMatchParams> dDIRCMatchParams = nullptr;
145  };
146 
147  private:
148 
149  //memory of object in shared_ptr is managed automatically: deleted automatically when no references are left
150  shared_ptr<DTimingInfo> dTimingInfo = nullptr;
151  shared_ptr<DTrackingInfo> dTrackingInfo = nullptr;
152 
153  //RESOURCE POOLS
154  static thread_local shared_ptr<DResourcePool<DTimingInfo>> dResourcePool_TimingInfo;
155  static thread_local shared_ptr<DResourcePool<DTrackingInfo>> dResourcePool_TrackingInfo;
156 };
157 
158 /************************************************************** CONSTRUCTORS & OPERATORS ***************************************************************/
159 
161 dTimingInfo(dResourcePool_TimingInfo->Get_SharedResource()), dTrackingInfo(dResourcePool_TrackingInfo->Get_SharedResource()) {}
162 
163 inline DChargedTrackHypothesis::DChargedTrackHypothesis(const DChargedTrackHypothesis& locSourceData, bool locShareTrackingFlag,
164  bool locShareTimingFlag, bool locShareKinematicsFlag) : DKinematicData(locSourceData, locShareKinematicsFlag)
165 {
166  //Default is NOT to share: create a new, independent copy of the input data (tracked separately from input so it can be modified)
167  if(locShareTrackingFlag)
168  dTrackingInfo = locSourceData.dTrackingInfo;
169  else
170  {
171  dTrackingInfo = dResourcePool_TrackingInfo->Get_SharedResource();
172  *dTrackingInfo = *(locSourceData.dTrackingInfo);
173  }
174 
175  if(locShareTimingFlag)
176  dTimingInfo = locSourceData.dTimingInfo;
177  else
178  {
179  dTimingInfo = dResourcePool_TimingInfo->Get_SharedResource();
180  *dTimingInfo = *(locSourceData.dTimingInfo);
181  }
182 }
183 
185  DKinematicData(*static_cast<const DKinematicData*>(locSourceData), true)
186 {
187  //Default is TO share kinematic data
188  dTrackingInfo = dResourcePool_TrackingInfo->Get_SharedResource();
189  dTimingInfo = dResourcePool_TimingInfo->Get_SharedResource();
190  dTrackingInfo->dTrackTimeBased = locSourceData;
191 }
192 
194 {
195  //Replace current data with a new, independent copy of the input data: tracked separately from input so it can be modified
196  DKinematicData::operator=(locSourceData);
197  if((dTimingInfo == locSourceData.dTimingInfo) && (dTrackingInfo == locSourceData.dTrackingInfo))
198  return *this; //guard against self-assignment
199  dTimingInfo = dResourcePool_TimingInfo->Get_SharedResource();
200  *dTimingInfo = *(locSourceData.dTimingInfo);
201  dTrackingInfo = dResourcePool_TrackingInfo->Get_SharedResource();
202  *dTrackingInfo = *(locSourceData.dTrackingInfo);
203  return *this;
204 }
205 
206 /********************************************************************** GETTERS ************************************************************************/
207 
209 {
210  if(Get_BCALShowerMatchParams() != nullptr)
211  return SYS_BCAL;
212  else if(Get_TOFHitMatchParams() != nullptr)
213  return SYS_TOF;
214  else if(Get_FCALShowerMatchParams() != nullptr)
215  return SYS_FCAL;
216  else if(Get_SCHitMatchParams() != nullptr)
217  return SYS_START;
218  return SYS_NULL;
219 }
220 
222 {
223  auto locPathLength = 0.0;
224  if(Get_BCALShowerMatchParams() != nullptr)
225  locPathLength = Get_BCALShowerMatchParams()->dPathLength;
226  else if(Get_TOFHitMatchParams() != nullptr)
227  locPathLength = Get_TOFHitMatchParams()->dPathLength;
228  else if(Get_FCALShowerMatchParams() != nullptr)
229  locPathLength = Get_FCALShowerMatchParams()->dPathLength;
230  else if(Get_SCHitMatchParams() != nullptr)
231  locPathLength = Get_SCHitMatchParams()->dPathLength;
232  else
233  return std::numeric_limits<double>::quiet_NaN();
234 
235  //correct for the fact that t0 is reported at the poca to the vertex, and the path length above is to the POCA to the beamline
236  return locPathLength + (time() - Get_TimeAtPOCAToVertex())/(29.9792458*lorentzMomentum().Beta());
237 }
238 
239 inline double DChargedTrackHypothesis::t1(void) const
240 {
241  auto locDetector = t1_detector();
242  if(locDetector == SYS_BCAL)
243  return Get_BCALShowerMatchParams()->dBCALShower->t;
244  else if(locDetector == SYS_TOF)
245  return Get_TOFHitMatchParams()->dTOFPoint->t;
246  else if(locDetector == SYS_FCAL)
247  return Get_FCALShowerMatchParams()->dFCALShower->getTime();
248  else if(locDetector == SYS_START)
249  return Get_SCHitMatchParams()->dHitTime;
250  return std::numeric_limits<double>::quiet_NaN();
251 }
252 
253 inline double DChargedTrackHypothesis::t1_err(void) const
254 {
255  auto locDetector = t1_detector();
256  if(locDetector == SYS_BCAL)
257  return sqrt(Get_BCALShowerMatchParams()->dBCALShower->ExyztCovariance(4, 4));
258  else if(locDetector == SYS_TOF)
259  return Get_TOFHitMatchParams()->dTOFPoint->tErr;
260  else if(locDetector == SYS_FCAL)
261  return sqrt(Get_FCALShowerMatchParams()->dFCALShower->ExyztCovariance(4, 4));
262  else if(locDetector == SYS_FCAL)
263  return sqrt(Get_SCHitMatchParams()->dHitTimeVariance);
264  return std::numeric_limits<double>::quiet_NaN();
265 }
266 
267 /********************************************************************** SETTERS ************************************************************************/
268 
269 inline void DChargedTrackHypothesis::Share_FromInput(const DChargedTrackHypothesis* locSourceData, bool locShareTrackingFlag, bool locShareTimingFlag, bool locShareKinematicsFlag)
270 {
271  if(locShareTrackingFlag)
272  dTrackingInfo = const_cast<DChargedTrackHypothesis*>(locSourceData)->dTrackingInfo;
273  if(locShareTimingFlag)
274  dTimingInfo = const_cast<DChargedTrackHypothesis*>(locSourceData)->dTimingInfo;
275  if(locShareKinematicsFlag)
276  Share_FromInput_Kinematics(static_cast<const DKinematicData*>(locSourceData));
277 }
278 
279 inline void DChargedTrackHypothesis::Set_T0(double locT0, double locT0Error, DetectorSystem_t locT0Detector)
280 {
281  dTimingInfo->dt0 = locT0;
282  dTimingInfo->dt0_err = locT0Error;
283  dTimingInfo->dt0_detector = locT0Detector;
284 }
285 
286 inline void DChargedTrackHypothesis::Set_ChiSq_Timing(double locChiSq, unsigned int locNDF)
287 {
288  dTimingInfo->dChiSq_Timing = locChiSq;
289  dTimingInfo->dNDF_Timing = locNDF;
290 }
291 
292 inline void DChargedTrackHypothesis::Set_ChiSq_DCdEdx(double locChiSq, unsigned int locNDF)
293 {
294  dTrackingInfo->dChiSq_DCdEdx = locChiSq;
295  dTrackingInfo->dNDF_DCdEdx = locNDF;
296 }
297 
298 inline void DChargedTrackHypothesis::Set_ChiSq_Overall(double locChiSq, unsigned int locNDF, double locFOM)
299 {
300  dTimingInfo->dChiSq = locChiSq;
301  dTimingInfo->dNDF = locNDF;
302  dTimingInfo->dFOM = locFOM;
303 }
304 
306 {
308  dTimingInfo = dResourcePool_TimingInfo->Get_SharedResource(); //not safe to reset individually, since you don't know what it's shared with
309  dTrackingInfo = dResourcePool_TrackingInfo->Get_SharedResource(); //not safe to reset individually, since you don't know what it's shared with
310 }
311 
313 {
315  dTimingInfo = nullptr;
316  dTrackingInfo = nullptr;
317 }
318 
320 {
321  dt0 = 0.0;
322  dt0_err = 0.0;
324  dNDF_Timing = 0;
325  dChiSq_Timing = 0.0;
326  dNDF = 0;
327  dChiSq = 0.0;
328  dFOM = 0.0;
329  dTimeAtPOCAToVertex = 0.0;
330 }
331 
333 {
334  dNDF_DCdEdx = 0;
335  dChiSq_DCdEdx = 0.0;
336  dTrackTimeBased = nullptr;
337  dSCHitMatchParams = nullptr;
338  dTOFHitMatchParams = nullptr;
339  dBCALShowerMatchParams = nullptr;
340  dFCALShowerMatchParams = nullptr;
341 }
342 
343 #endif // _DChargedTrackHypothesis_
void Set_ChiSq_Overall(double locChiSq, unsigned int locNDF, double locFOM)
virtual void Release(void)
double Get_ChiSq_Timing(void) const
DChargedTrackHypothesis & operator=(const DChargedTrackHypothesis &locSourceData)
void Set_DIRCMatchParams(shared_ptr< const DDIRCMatchParams > locMatchParams)
void Set_TrackTimeBased(const DTrackTimeBased *locTrackTimeBased)
Definition: GlueX.h:16
void Set_FCALShowerMatchParams(shared_ptr< const DFCALShowerMatchParams > locMatchParams)
double Get_TimeAtPOCAToVertex(void) const
const DTrackTimeBased * Get_TrackTimeBased(void) const
void Set_BCALShowerMatchParams(shared_ptr< const DBCALShowerMatchParams > locMatchParams)
DKinematicData & operator=(const DKinematicData &locSourceData)
static thread_local shared_ptr< DResourcePool< DTrackingInfo > > dResourcePool_TrackingInfo
DetectorSystem_t
Definition: GlueX.h:15
double measuredBeta(void) const
shared_ptr< DTrackingInfo > dTrackingInfo
unsigned int Get_NDF_Timing(void) const
double Get_PathLength(void) const
Definition: GlueX.h:19
shared_ptr< const DTOFHitMatchParams > Get_TOFHitMatchParams(void) const
void Set_T0(double locT0, double locT0Error, DetectorSystem_t locT0Detector)
void Set_ChiSq_DCdEdx(double locChiSq, unsigned int locNDF)
unsigned int Get_NDF_DCdEdx(void) const
double time(void) const
void Set_TimeAtPOCAToVertex(double locTimeAtPOCAToVertex)
void Share_FromInput(const DChargedTrackHypothesis *locSourceData, bool locShareTrackingFlag, bool locShareTimingFlag, bool locShareKinematicsFlag)
Definition: GlueX.h:20
TLatex * t1
void Share_FromInput_Kinematics(const DKinematicData *locSourceData)
Definition: GlueX.h:22
shared_ptr< DTimingInfo > dTimingInfo
shared_ptr< const DDIRCMatchParams > Get_DIRCMatchParams(void) const
void Set_SCHitMatchParams(shared_ptr< const DSCHitMatchParams > locMatchParams)
shared_ptr< const DSCHitMatchParams > Get_SCHitMatchParams(void) const
DLorentzVector lorentzMomentum(void) const
double sqrt(double)
shared_ptr< const DFCALShowerMatchParams > Get_FCALShowerMatchParams(void) const
double Get_ChiSq_DCdEdx(void) const
unsigned int Get_NDF(void) const
virtual void Reset(void)
DetectorSystem_t t0_detector(void) const
void Set_TOFHitMatchParams(shared_ptr< const DTOFHitMatchParams > locMatchParams)
shared_ptr< const DBCALShowerMatchParams > Get_BCALShowerMatchParams(void) const
void toStrings(vector< pair< string, string > > &items) const
static thread_local shared_ptr< DResourcePool< DTimingInfo > > dResourcePool_TimingInfo
DetectorSystem_t t1_detector(void) const
void toStrings(vector< pair< string, string > > &items) const
void Set_ChiSq_Timing(double locChiSq, unsigned int locNDF)