Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DKinFitParticle.h
Go to the documentation of this file.
1 #ifndef _DKinFitParticle_
2 #define _DKinFitParticle_
3 
4 #include <set>
5 #include <math.h>
6 #include <memory>
7 
8 #include "DResettable.h"
9 #include "TVector3.h"
10 #include "TLorentzVector.h"
11 #include "TMatrixFSym.h"
12 
13 using namespace std;
14 
16 {
22 };
23 
25 {
26  d_EPull = 0,
34 };
35 
36 class DKinFitter;
37 class DKinFitUtils;
42 class DKinFitUtils_GlueX;
43 
45 {
46  friend class DKinFitter;
47  friend class DKinFitUtils;
50  friend class DKinFitConstraint_P4;
51  friend class DKinFitConstraint_Mass;
52  friend class DKinFitUtils_GlueX;
53 
54  public:
55 
56  //STRUCTORS
57  DKinFitParticle(void);
59 
60  //RESET AND PRINT
61  void Reset(void);
62  void Release(void);
63  void Print_ParticleParams(void) const;
64 
65  //SETTERS
66  void Set_KinFitParticleType(DKinFitParticleType locKinFitParticleType){dKinFitParticleType = locKinFitParticleType;}
67  void Set_PID(int locPID){dPID = locPID;}
68  void Set_Charge(char locCharge){dCharge = locCharge;}
69  void Set_Mass(double locMass){dMass = locMass;}
70 
71  void Set_Position(TVector3 locPosition){dSpacetimeVertex.SetVect(locPosition);}
72  void Set_Time(double locTime){dSpacetimeVertex.SetT(locTime);}
73  void Set_SpacetimeVertex(TLorentzVector locSpacetimeVertex){dSpacetimeVertex = locSpacetimeVertex;}
74 
75  void Set_Momentum(TVector3 locMomentum){dMomentum = locMomentum;}
76  void Set_CovarianceMatrix(const shared_ptr<TMatrixFSym>& locCovarianceMatrix){dCovarianceMatrix = std::const_pointer_cast<const TMatrixFSym>(locCovarianceMatrix);}
77  void Set_CovarianceMatrix(const shared_ptr<const TMatrixFSym>& locCovarianceMatrix){dCovarianceMatrix = locCovarianceMatrix;}
78  void Set_ShowerEnergy(double locShowerEnergy){dShowerEnergy = locShowerEnergy;}
79  void Set_PathLength(double locPathLength){dPathLength = locPathLength;}
80  void Set_PathLengthUncertainty(double locPathLengthUncertainty){dPathLengthUncertainty = locPathLengthUncertainty;}
81  void Set_RestFrameLifetimeUncertainty(double locRestFrameLifetimeUncertainty){dRestFrameLifetimeUncertainty = locRestFrameLifetimeUncertainty;}
82  void Set_RestFrameLifetime(double locRestFrameLifetime){dRestFrameLifetime = locRestFrameLifetime;}
83 
84  void Set_CommonVertex(TVector3 locCommonVertex){dCommonSpacetimeVertex.SetVect(locCommonVertex);}
85  void Set_CommonTime(double locCommonTime){dCommonSpacetimeVertex.SetT(locCommonTime);}
86  void Set_CommonSpacetimeVertex(TLorentzVector locCommonSpacetimeVertex){dCommonSpacetimeVertex = locCommonSpacetimeVertex;}
87 
88  void Set_PxParamIndex(char locPxParamIndex){dPxParamIndex = locPxParamIndex;}
89  void Set_VxParamIndex(char locVxParamIndex){dVxParamIndex = locVxParamIndex;}
90  void Set_TParamIndex(char locTParamIndex){dTParamIndex = locTParamIndex;}
91  void Set_CommonVxParamIndex(char locCommonVxParamIndex){dCommonVxParamIndex = locCommonVxParamIndex;}
92  void Set_CommonTParamIndex(char locCommonTParamIndex){dCommonTParamIndex = locCommonTParamIndex;}
93  void Set_EParamIndex(char locEParamIndex){dEParamIndex = locEParamIndex;}
94 
95  void Set_IsNeutralShowerFlag(bool locIsNeutralShowerFlag){dIsNeutralShowerFlag = locIsNeutralShowerFlag;}
96  void Set_VertexConstraintFlag(unsigned char locVertexConstraintFlag){dVertexConstraintFlag = locVertexConstraintFlag;}
97 
98  void Set_VertexP4AtProductionVertex(bool locVertexP4AtProductionVertex){dVertexP4AtProductionVertex = locVertexP4AtProductionVertex;}
99  void Set_FromInitialState(const set<shared_ptr<DKinFitParticle>>& locFromInitialState){dFromInitialState = locFromInitialState;}
100  void Set_FromFinalState(const set<shared_ptr<DKinFitParticle>>& locFromFinalState){dFromFinalState = locFromFinalState;}
101 
102  //GETTERS
103  int Get_PID(void) const{return dPID;}
104  double Get_Energy(void) const{return sqrt(dMass*dMass + dMomentum.Mag2());}
105  char Get_Charge(void) const{return dCharge;}
106  TLorentzVector Get_P4(void) const{return TLorentzVector(dMomentum, Get_Energy());}
107  TVector3 Get_Momentum(void) const{return dMomentum;}
108  TVector3 Get_Position(void) const{return dSpacetimeVertex.Vect();}
109  double Get_Mass(void) const{return dMass;}
110  double Get_Beta(void) const{return dMomentum.Mag()/(Get_Energy());}
111  double Get_Time(void) const{return dSpacetimeVertex.T();}
112  double Get_ShowerEnergy(void) const{return dShowerEnergy;}
113  double Get_PathLength(void) const{return dPathLength;}
114  double Get_PathLengthUncertainty(void) const{return dPathLengthUncertainty;}
115  double Get_RestFrameLifetimeUncertainty(void) const{return dRestFrameLifetimeUncertainty;}
116  double Get_RestFrameLifetime(void) const{return dRestFrameLifetime;}
117  shared_ptr<const TMatrixFSym> Get_CovarianceMatrix(void) const{return dCovarianceMatrix;}
118  TLorentzVector Get_SpacetimeVertex(void) const{return dSpacetimeVertex;}
119  TVector3 Get_CommonVertex(void) const{return dCommonSpacetimeVertex.Vect();}
120  double Get_CommonTime(void) const{return dCommonSpacetimeVertex.T();}
121  TLorentzVector Get_CommonSpacetimeVertex(void) const{return dCommonSpacetimeVertex;}
122 
123  unsigned char Get_VertexConstraintFlag(void) const{return dVertexConstraintFlag;}
124  bool Get_FitCommonVertexFlag(void) const{return (dCommonVxParamIndex >= 0);}
125  bool Get_FitCommonTimeFlag(void) const{return (dCommonTParamIndex >= 0);}
126  DKinFitParticleType Get_KinFitParticleType(void) const{return dKinFitParticleType;}
127 
128  set<shared_ptr<DKinFitParticle>> Get_FromInitialState(void) const{return dFromInitialState;}
129  set<shared_ptr<DKinFitParticle>> Get_FromFinalState(void) const{return dFromFinalState;}
130  set<shared_ptr<DKinFitParticle>> Get_FromAllParticles(void) const;
131 
132  bool Get_VertexP4AtProductionVertex(void) const{return dVertexP4AtProductionVertex;}
133 
134  char Get_PxParamIndex(void) const{return dPxParamIndex;}
135  char Get_VxParamIndex(void) const{return dVxParamIndex;}
136  char Get_TParamIndex(void) const{return dTParamIndex;}
137  char Get_CommonVxParamIndex(void) const{return dCommonVxParamIndex;}
138  char Get_CommonTParamIndex(void) const{return dCommonTParamIndex;}
139  char Get_EParamIndex(void) const{return dEParamIndex;}
140 
141  int Get_CovMatrixEParamIndex(void) const{return ((dCovarianceMatrix == NULL) ? -1 : ((dCovarianceMatrix->GetNcols() >= 7) ? -1 : 0));}
142  int Get_CovMatrixPxParamIndex(void) const{return ((dCovarianceMatrix == NULL) ? -1 : ((dCovarianceMatrix->GetNcols() >= 7) ? 0 : -1));}
143  int Get_CovMatrixVxParamIndex(void) const{return ((dCovarianceMatrix == NULL) ? -1 : ((dCovarianceMatrix->GetNcols() >= 7) ? 3 : 1));}
144  int Get_CovMatrixTParamIndex(void) const{return ((dCovarianceMatrix == NULL) ? -1 : ((dCovarianceMatrix->GetNcols() >= 7) ? 6 : 4));}
145 
146  bool Get_IsNeutralShowerFlag(void) const{return dIsNeutralShowerFlag;}
147 
148  private:
149 
151 
152  int dPID; //PDG PID
153  char dCharge;
154  double dMass;
155 
156  //p, x, & t must all coincide: t & p at point x (for charged tracks p is a function of x in a b-field!)
157  TLorentzVector dSpacetimeVertex;
158  TLorentzVector dCommonSpacetimeVertex; //if not in vertex/time fit, will be same as dSpacetimeVertex
159 
161  TVector3 dMomentum; //must be the value of the momentum at dSpacetimeVertex
162 
163  //is 7x7 for detected charged particles, either 7x7 (particles) or 5x5 (showers) for neutrals
164  //for decaying particles, is 11x11 if involved in 2 vertex fits (otherwise 7x7): includes common vertex
165  shared_ptr<const TMatrixFSym> dCovarianceMatrix;
166  //5x5 format: E, x, y, z, t
167  //7x7 format: px, py, pz, x, y, z, t
168  //11x11 format: px, py, pz, x, y, z, t, common x, common y, common z, common t
169 
170  double dPathLength;
172  double dRestFrameLifetime; //is 0 unless decaying particle in 2 vertex fits
173  double dRestFrameLifetimeUncertainty; //is 0 unless decaying particle in 2 vertex fits
174 
175  unsigned char dVertexConstraintFlag; //unused unless in vertex fit //can choose between equations //only for non-accelerating particles not constrained in time
176 
183 
184  //Decaying particles are reconstructed from these particles //ignored if not decaying
185  set<shared_ptr<DKinFitParticle>> dFromInitialState;
186  set<shared_ptr<DKinFitParticle>> dFromFinalState;
187 
188  //true if the object's p3, v3, & t are defined at its production vertex (& common v & t are at decay vertex). else at it's decay vertex (& common v & t are at production vertex)
189  //note: if a decaying particle is not in a vertex fit, then this quantity doesn't matter (default true)
191 
193 };
194 
196 {
197  Reset();
198 }
199 
200 inline void DKinFitParticle::Reset(void)
201 {
202  dPID = 0;
203  dCharge = 0;
204  dMass = 0.0;
205  dSpacetimeVertex.SetXYZT(0.0, 0.0, 0.0, 0.0);
206  dCommonSpacetimeVertex.SetXYZT(0.0, 0.0, 0.0, 0.0);
207  dShowerEnergy = 0.0;
208  dMomentum.SetXYZ(0.0, 0.0, 0.0);
209  dCovarianceMatrix = NULL;
210  dPathLength = 0.0;
211  dPathLengthUncertainty = 0.0;
212  dRestFrameLifetime = 0.0;
213  dRestFrameLifetimeUncertainty = 0.0;
214 
215  dVertexConstraintFlag = 0;
216 
217  dKinFitParticleType = d_DetectedParticle;
218 
219  dEParamIndex = -1;
220  dPxParamIndex = -1;
221  dVxParamIndex = -1;
222  dTParamIndex = -1;
223  dCommonVxParamIndex = -1;
224  dCommonTParamIndex = -1;
225 
226  dFromInitialState.clear();
227  dFromFinalState.clear();
228 
229  dVertexP4AtProductionVertex = false;
230  dIsNeutralShowerFlag = false;
231 }
232 
233 inline void DKinFitParticle::Release(void)
234 {
235  dCovarianceMatrix = nullptr;
236  dFromInitialState.clear();
237  dFromFinalState.clear();
238 }
239 
240 inline set<shared_ptr<DKinFitParticle>> DKinFitParticle::Get_FromAllParticles(void) const
241 {
242  //get all of the particles this particle is derived from, excluding decaying particles
243  set<shared_ptr<DKinFitParticle>> locFromAllParticles;
244 
245  //from initial state
246  for(auto& locKinFitParticle : dFromInitialState)
247  {
248  locFromAllParticles.insert(locKinFitParticle);
249  if(locKinFitParticle->Get_KinFitParticleType() == d_DecayingParticle)
250  {
251  auto locNewParticles = locKinFitParticle->Get_FromAllParticles();
252  locFromAllParticles.insert(locNewParticles.begin(), locNewParticles.end());
253  }
254  }
255 
256  //from initial state
257  for(auto& locKinFitParticle : dFromFinalState)
258  {
259  locFromAllParticles.insert(locKinFitParticle);
260  if(locKinFitParticle->Get_KinFitParticleType() == d_DecayingParticle)
261  {
262  auto locNewParticles = locKinFitParticle->Get_FromAllParticles();
263  locFromAllParticles.insert(locNewParticles.begin(), locNewParticles.end());
264  }
265  }
266 
267  return locFromAllParticles;
268 }
269 
271 {
272  cout << "DKinFitParticle: Particle Type Enum, pointer: " << dKinFitParticleType << ", " << this << endl;
273 
274  cout << "DKinFitParticle: Particle PID, Q, Mass = " << dPID << ", " << int(dCharge) << ", " << dMass << endl;
275  cout << "DKinFitParticle: Particle P3, V3, T, path length = " << dMomentum.Px() << ", " << dMomentum.Py() << ", " << dMomentum.Pz() << ", ";
276  cout << dSpacetimeVertex.X() << ", " << dSpacetimeVertex.Y() << ", " << dSpacetimeVertex.Z() << ", " << dSpacetimeVertex.T() << ", " << dPathLength << endl;
277  cout << "DKinFitParticle: Particle Common V3, Common T, ShowerE = " << dCommonSpacetimeVertex.X() << ", " << dCommonSpacetimeVertex.Y();
278  cout << ", " << dCommonSpacetimeVertex.Z() << ", " << dCommonSpacetimeVertex.T() << ", " << dShowerEnergy << endl;
279 
280  cout << "DKinFitParticle: FitCommonVertexFlag, FitCommonTimeFlag, dVertexP4AtProductionVertex, dIsNeutralShowerFlag = ";
281  cout << Get_FitCommonVertexFlag() << ", " << Get_FitCommonTimeFlag() << ", " << dVertexP4AtProductionVertex << ", " << dIsNeutralShowerFlag << endl;
282  if(dCovarianceMatrix != NULL)
283  {
284  cout << "DKinFitParticle: CovMatrix Diagonal Terms: ";
285  for(int loc_i = 0; loc_i < dCovarianceMatrix->GetNcols(); ++loc_i)
286  cout << (*dCovarianceMatrix)(loc_i, loc_i) << ", ";
287  cout << endl;
288  }
289 
290  cout << "DKinFitParticle: Particle E, Px, Vx, Common Vx, T, Common T indices = " << int(dEParamIndex) << ", " << int(dPxParamIndex) << ", ";
291  cout << int(dVxParamIndex) << ", " << int(dCommonVxParamIndex) << ", " << int(dTParamIndex) << ", " << int(dCommonTParamIndex) << endl;
292 
293  cout << "dFromInitialState size, PIDs: " << dFromInitialState.size();
294  for(auto& locKinFitParticle : dFromInitialState)
295  cout << ", " << locKinFitParticle->Get_PID();
296  cout << endl;
297 
298  cout << "dFromFinalState size, PIDs: " << dFromFinalState.size();
299  for(auto& locKinFitParticle : dFromFinalState)
300  cout << ", " << locKinFitParticle->Get_PID();
301  cout << endl;
302 
303  auto locFromAllParticles = Get_FromAllParticles();
304  cout << "FromAllButDecaying size, PIDs: " << locFromAllParticles.size();
305  for(auto& locKinFitParticle : locFromAllParticles)
306  cout << ", " << locKinFitParticle->Get_PID();
307  cout << endl;
308 }
309 
310 #endif // _DKinFitParticle_
311 
int Get_PID(void) const
bool Get_FitCommonVertexFlag(void) const
char Get_Charge(void) const
int Get_CovMatrixVxParamIndex(void) const
char Get_TParamIndex(void) const
char Get_CommonVxParamIndex(void) const
DKinFitPullType
void Set_CommonTParamIndex(char locCommonTParamIndex)
set< shared_ptr< DKinFitParticle > > Get_FromInitialState(void) const
set< shared_ptr< DKinFitParticle > > Get_FromAllParticles(void) const
void Set_PathLength(double locPathLength)
double Get_RestFrameLifetimeUncertainty(void) const
void Set_VertexP4AtProductionVertex(bool locVertexP4AtProductionVertex)
void Set_PID(int locPID)
void Set_Momentum(TVector3 locMomentum)
int Get_CovMatrixEParamIndex(void) const
void Set_PathLengthUncertainty(double locPathLengthUncertainty)
DKinFitParticleType
void Set_CommonSpacetimeVertex(TLorentzVector locCommonSpacetimeVertex)
double Get_Beta(void) const
double Get_Mass(void) const
int Get_CovMatrixTParamIndex(void) const
double Get_RestFrameLifetime(void) const
double Get_ShowerEnergy(void) const
void Set_PxParamIndex(char locPxParamIndex)
void Set_CovarianceMatrix(const shared_ptr< const TMatrixFSym > &locCovarianceMatrix)
void Set_ShowerEnergy(double locShowerEnergy)
void Set_RestFrameLifetime(double locRestFrameLifetime)
void Set_CovarianceMatrix(const shared_ptr< TMatrixFSym > &locCovarianceMatrix)
double dRestFrameLifetimeUncertainty
double Get_PathLengthUncertainty(void) const
unsigned char Get_VertexConstraintFlag(void) const
void Print_ParticleParams(void) const
void Set_Charge(char locCharge)
set< shared_ptr< DKinFitParticle > > dFromInitialState
void Set_CommonVxParamIndex(char locCommonVxParamIndex)
set< shared_ptr< DKinFitParticle > > Get_FromFinalState(void) const
char Get_PxParamIndex(void) const
void Set_Mass(double locMass)
void Set_CommonVertex(TVector3 locCommonVertex)
TLorentzVector Get_SpacetimeVertex(void) const
void Set_KinFitParticleType(DKinFitParticleType locKinFitParticleType)
TLorentzVector dCommonSpacetimeVertex
bool Get_IsNeutralShowerFlag(void) const
TLorentzVector dSpacetimeVertex
bool Get_FitCommonTimeFlag(void) const
double Get_PathLength(void) const
void Release(void)
void Set_FromInitialState(const set< shared_ptr< DKinFitParticle >> &locFromInitialState)
double sqrt(double)
set< shared_ptr< DKinFitParticle > > dFromFinalState
char Get_EParamIndex(void) const
char Get_VxParamIndex(void) const
void Set_RestFrameLifetimeUncertainty(double locRestFrameLifetimeUncertainty)
shared_ptr< const TMatrixFSym > Get_CovarianceMatrix(void) const
void Set_Position(TVector3 locPosition)
double Get_CommonTime(void) const
char Get_CommonTParamIndex(void) const
void Set_VertexConstraintFlag(unsigned char locVertexConstraintFlag)
void Set_VxParamIndex(char locVxParamIndex)
void Set_SpacetimeVertex(TLorentzVector locSpacetimeVertex)
DKinFitParticleType Get_KinFitParticleType(void) const
DKinFitParticleType dKinFitParticleType
bool dVertexP4AtProductionVertex
shared_ptr< const TMatrixFSym > dCovarianceMatrix
void Set_TParamIndex(char locTParamIndex)
TVector3 Get_Position(void) const
void Set_CommonTime(double locCommonTime)
void Set_FromFinalState(const set< shared_ptr< DKinFitParticle >> &locFromFinalState)
double dPathLengthUncertainty
unsigned char dVertexConstraintFlag
double Get_Time(void) const
TVector3 Get_CommonVertex(void) const
void Set_EParamIndex(char locEParamIndex)
int Get_CovMatrixPxParamIndex(void) const
TLorentzVector Get_P4(void) const
void Set_IsNeutralShowerFlag(bool locIsNeutralShowerFlag)
double Get_Energy(void) const
TVector3 Get_Momentum(void) const
bool Get_VertexP4AtProductionVertex(void) const
TLorentzVector Get_CommonSpacetimeVertex(void) const
void Set_Time(double locTime)