Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFParticleBase.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFParticleBase.h
1 /*
2  * This file is part of KFParticle package
3  * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
4  * 2007-2019 Goethe University of Frankfurt
5  * 2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
6  * 2007-2019 Maksym Zyzak
7  * 2007-2019 Sergey Gorbunov
8  *
9  * KFParticle is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * KFParticle is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
23 
24 #ifndef KFPARTICLEBASE_H
25 #define KFPARTICLEBASE_H
26 
27 #ifdef __ROOT__ //for the STAR experiment
28 #define HomogeneousField
29 #endif
30 
31 #ifdef HLTCA_STANDALONE
32 #include "RootTypesDef.h"
33 #else
34 #include "TObject.h"
35 #endif
36 
37 #include <vector>
38 
48 class KFParticleBase :public TObject {
49 
50  public:
51 
57  virtual void GetFieldValue(const float xyz[], float B[]) const = 0;
58 
60  virtual float GetDStoPoint( const float xyz[3], float dsdr[6] ) const = 0;
61 
62  float GetDStoPointLine( const float xyz[3], float dsdr[6] ) const;
63  float GetDStoPointBz( float B, const float xyz[3], float dsdr[6], const float* param=0) const;
64  float GetDStoPointBy( float By, const float xyz[3], float dsdr[6] ) const;
65  float GetDStoPointB( const float* B, const float xyz[3], float dsdr[6] ) const;
66  float GetDStoPointCBM( const float xyz[3], float dsdr[6] ) const;
67 
69  virtual void GetDStoParticle( const KFParticleBase &p, float dS[2], float dsdr[4][6] ) const = 0;
70 
71  void GetDStoParticleLine( const KFParticleBase &p, float dS[2], float dsdr[4][6] ) const ;
72  void GetDStoParticleBz( float Bz, const KFParticleBase &p, float dS[2], float dsdr[4][6], const float* param1=0, const float* param2=0 ) const ;
73  void GetDStoParticleBy( float B, const KFParticleBase &p, float dS[2], float dsdr[4][6] ) const ;
74  void GetDStoParticleCBM( const KFParticleBase &p, float dS[2], float dsdr[4][6] ) const ;
75 
77  virtual void Transport( float dS, const float dsdr[6], float P[], float C[], float* dsdr1=0, float* F=0, float* F1=0 ) const = 0;
78 
79 
81  virtual ~KFParticleBase() { ; }
82 
83  void Initialize( const float Param[], const float Cov[], Int_t Charge, float Mass );
84  void Initialize();
85 
87  void SetMassHypo(float m) { fMassHypo = m;}
88  const float& GetMassHypo() const { return fMassHypo; }
89  const float& GetSumDaughterMass() const {return SumDaughterMass;}
90 
91  //*
92  //* ACCESSORS
93  //*
94 
95  //* Simple accessors
96 
97  float GetX () const { return fP[0]; }
98  float GetY () const { return fP[1]; }
99  float GetZ () const { return fP[2]; }
100  float GetPx () const { return fP[3]; }
101  float GetPy () const { return fP[4]; }
102  float GetPz () const { return fP[5]; }
103  float GetE () const { return fP[6]; }
104  float GetS () const { return fP[7]; }
105  char GetQ () const { return fQ; }
106  float GetChi2 () const { return fChi2; }
107  Int_t GetNDF () const { return fNDF; }
108 
109  const float& X () const { return fP[0]; }
110  const float& Y () const { return fP[1]; }
111  const float& Z () const { return fP[2]; }
112  const float& Px () const { return fP[3]; }
113  const float& Py () const { return fP[4]; }
114  const float& Pz () const { return fP[5]; }
115  const float& E () const { return fP[6]; }
116  const float& S () const { return fP[7]; }
117  const char& Q () const { return fQ; }
118  const float& Chi2 () const { return fChi2; }
119  const Int_t& NDF () const { return fNDF; }
120 
121  float GetParameter ( Int_t i ) const { return fP[i]; }
122  float GetCovariance( Int_t i ) const { return fC[i]; }
123  float GetCovariance( Int_t i, Int_t j ) const { return fC[IJ(i,j)]; }
124 
125  //* Accessors with calculations( &value, &estimated sigma )
126  //* error flag returned (0 means no error during calculations)
127 
128  Int_t GetMomentum ( float &p, float &error ) const ;
129  Int_t GetPt ( float &pt, float &error ) const ;
130  Int_t GetEta ( float &eta, float &error ) const ;
131  Int_t GetPhi ( float &phi, float &error ) const ;
132  Int_t GetMass ( float &m, float &error ) const ;
133  Int_t GetDecayLength ( float &l, float &error ) const ;
134  Int_t GetDecayLengthXY ( float &l, float &error ) const ;
135  Int_t GetLifeTime ( float &ctau,float &error ) const ;
136  Int_t GetR ( float &r, float &error ) const ;
137 
138  //*
139  //* MODIFIERS
140  //*
141 
142  float & X () { return fP[0]; }
143  float & Y () { return fP[1]; }
144  float & Z () { return fP[2]; }
145  float & Px () { return fP[3]; }
146  float & Py () { return fP[4]; }
147  float & Pz () { return fP[5]; }
148  float & E () { return fP[6]; }
149  float & S () { return fP[7]; }
150  char & Q () { return fQ; }
151  float & Chi2 () { return fChi2; }
152  Int_t & NDF () { return fNDF; }
153 
154  float & Parameter ( Int_t i ) { return fP[i]; }
155  float & Covariance( Int_t i ) { return fC[i]; }
156  float & Covariance( Int_t i, Int_t j ) { return fC[IJ(i,j)]; }
157 
158 
159  //*
160  //* CONSTRUCTION OF THE PARTICLE BY ITS DAUGHTERS AND MOTHER
161  //* USING THE KALMAN FILTER METHOD
162  //*
163 
164 
165  //* Simple way to add daughter ex. D0+= Pion;
166 
167  void operator +=( const KFParticleBase &Daughter );
168 
169  //* Add daughter track to the particle
170 
171  void AddDaughter( const KFParticleBase &Daughter );
172  void SubtractDaughter( const KFParticleBase &Daughter );
173 
174  void AddDaughterWithEnergyFit( const KFParticleBase &Daughter );
175  void AddDaughterWithEnergyFitMC( const KFParticleBase &Daughter );
176 
177  //* Set production vertex
178 
179  void SetProductionVertex( const KFParticleBase &Vtx );
180 
181  //* Set mass constraint
182 
183  void SetNonlinearMassConstraint( float Mass );
184  void SetMassConstraint( float Mass, float SigmaMass = 0 );
185 
186  //* Set no decay length for resonances
187 
188  void SetNoDecayLength();
189 
190 
191  //* Everything in one go
192 
193  void Construct( const KFParticleBase *vDaughters[], Int_t nDaughters, const KFParticleBase *ProdVtx=0, float Mass=-1 );
194 
195  //Transport functions
196  void TransportToDecayVertex();
198  void TransportToDS( float dS, const float* dsdr );
199  void TransportBz( float Bz, float dS, const float* dsdr, float P[], float C[], float* dsdr1=0, float* F=0, float* F1=0 ) const;
200  void TransportCBM( float dS, const float* dsdr, float P[], float C[], float* dsdr1=0, float* F=0, float* F1=0 ) const;
201 
202  //*
203  //* OTHER UTILITIES
204  //*
205 
206  //* Calculate distance from another object [cm]
207 
208  float GetDistanceFromVertex( const float vtx[] ) const;
209  float GetDistanceFromVertex( const KFParticleBase &Vtx ) const;
210  float GetDistanceFromParticle( const KFParticleBase &p ) const;
211 
212  //* Calculate sqrt(Chi2/ndf) deviation from vertex
213  //* v = [xyz], Cv=[Cxx,Cxy,Cyy,Cxz,Cyz,Czz]-covariance matrix
214 
215  float GetDeviationFromVertex( const float v[], const float Cv[]=0 ) const;
216  float GetDeviationFromVertex( const KFParticleBase &Vtx ) const;
217  float GetDeviationFromParticle( const KFParticleBase &p ) const;
218 
219  void SubtractFromVertex( KFParticleBase &Vtx ) const;
220  void SubtractFromParticle( KFParticleBase &Vtx ) const;
221 
222  static void GetArmenterosPodolanski(KFParticleBase& positive, KFParticleBase& negative, float QtAlfa[2] );
223  void RotateXY(float angle, float Vtx[3]);
224 
225  int Id() const { return fId; }
226  int NDaughters() const { return fDaughtersIds.size(); }
227  const std::vector<int>& DaughterIds() const { return fDaughtersIds; }
228  void CleanDaughtersId() { fDaughtersIds.clear(); }
229 
230  void SetId( int id ) { fId = id; }
231  void AddDaughterId( int id ) { fDaughtersIds.push_back(id); }
232 
233  void SetPDG ( int pdg ) { fPDG = pdg; }
234  int GetPDG () const { return fPDG; }
235 
236 #ifdef __ROOT__ //for the STAR experiment
237  virtual void Print(Option_t *opt="") const;
238  Int_t IdTruth() const { return fIdTruth;}
239  Int_t QaTruth() const { return fQuality; }
240  Int_t IdParentMcVx() const {return fIdParentMcVx;}
241  Int_t IdParentVx() const {return IdParentMcVx();}
242  void SetParentID(Int_t id=0) {fParentID = id;}
243  Int_t GetParentID() const {return fParentID;}
244  void SetIdParentMcVx(Int_t id) {fIdParentMcVx = id;}
245  void SetIdTruth(Int_t idtru,Int_t qatru=0) {fIdTruth = (UShort_t) idtru; fQuality = (UShort_t) qatru;}
246  virtual void Clear(Option_t * /*option*/ ="");
247 #endif
248 
249  static void InvertCholetsky3(float a[6]);
250  static void MultQSQt( const float Q[], const float S[], float SOut[], const int kN );
251 
252  protected:
254  static Int_t IJ( Int_t i, Int_t j ){
255  return ( j<=i ) ? i*(i+1)/2+j :j*(j+1)/2+i;
256  }
258  float & Cij( Int_t i, Int_t j ){ return fC[IJ(i,j)]; }
259  void TransportLine( float S, const float* dsdr, float P[], float C[], float* dsdr1, float* F, float* F1 ) const ;
260  bool GetMeasurement( const KFParticleBase& daughter, float m[], float V[], float D[3][3] ) ;
261  void SetMassConstraint( float *mP, float *mC, float mJ[7][7], float mass );
262 
263  float fP[8];
264  float fC[36];
265  float fChi2;
266  float fSFromDecay;
268  float fMassHypo;
269  Int_t fNDF;
270  int fId;
271 #ifdef __ROOT__ //for the STAR experiment
272  Short_t fParentID;
273  Short_t fIdTruth;
274  Short_t fQuality;
275  Short_t fIdParentMcVx;
276 #endif
278  char fQ;
279 
285  int fPDG;
286 
291  std::vector<int> fDaughtersIds;
292 
293 #ifndef KFParticleStandalone
294  ClassDef( KFParticleBase, 2 )
295 #endif
296 };
297 
298 #ifdef __ROOT__ //for the STAR experiment
299 std::ostream& operator<<(std::ostream& os, KFParticleBase const & particle);
300 #endif
301 
302 #endif