BmnRoot
Loading...
Searching...
No Matches
CbmKFParticlesFinder.cxx
Go to the documentation of this file.
1/*
2 *=====================================================
3 *
4 * CBM Level 1 Reconstruction
5 *
6 * Authors: M.Zyzak
7 *
8 * e-mail : m.zyzak@gsi.de
9 *
10 *=====================================================
11 *
12 * Finds Particles: Lambdas, K0...
13 *
14 */
15
17#include "CbmL1Def.h"
18
19#include "KFParticleFinder.h"
20#include "KFParticleSIMD.h"
21#include "CbmKFVertex.h"
22#include "CbmKFTrack.h"
23#include "CbmStsTrack.h"
24
25#include "TClonesArray.h"
26#include "TStopwatch.h"
27#include <iostream>
28
29#include "CbmTrackMatch.h"
30#include "CbmMCTrack.h"
31//for particle ID from global track
32#include "CbmTofHit.h"
33#include "CbmGlobalTrack.h"
34#include "CbmRichRing.h"
35#include "CbmTrdTrack.h"
36//for RICH identification
37#include "TSystem.h"
38// #include "CbmRichElectronIdAnn.h"
39
40#include "CbmL1PFFitter.h"
41
42using std::vector;
43using std::ios;
44
45CbmKFParticlesFinder::CbmKFParticlesFinder(float cuts[2][3], Int_t usePID, const char *name, const char *title, Int_t iVerbose):
46 FairTask(name,iVerbose),
47 fCuts(),
48 fusePID(usePID),
49 flistStsTracks(0),
50 fPrimVtx(0),
51 fParticles(),
52 flistStsTracksMatch(0),
53 flistMCTracks(0),
54 flsitGlobalTracks(0),
55 flistTofHits(0),
56 flistRichRings(0),
57 flistTrdTracks(0)
58// fElIdAnn(0)
59{
60 if(cuts)
61 {
62 for(int i=0; i<2; ++i)
63 for(int j=0; j<3; ++j)
64 fCuts[i][j] = cuts[i][j];
65 }
66 else
67 {
68 fCuts[0][0] = 3.;
69 fCuts[0][1] = 3.;
70 fCuts[0][2] = -100.;
71 fCuts[1][0] = 3.;
72 fCuts[1][1] = 3.;
73 fCuts[1][2] = -100.;
74 }
75}
76
80
84
86{
87 FairRootManager *fManger = FairRootManager::Instance();
88
89 flistStsTracks = (TClonesArray *) fManger->GetObject("StsTrack");
90 fPrimVtx = (CbmVertex*) fManger->GetObject("PrimaryVertex");
91 //for the particle id
92 flistStsTracksMatch = dynamic_cast<TClonesArray*>( fManger->GetObject("StsTrackMatch") );
93 flistMCTracks = dynamic_cast<TClonesArray*>( fManger->GetObject("MCTrack") );
94
95 if (fusePID == 2){
96 flsitGlobalTracks = dynamic_cast<TClonesArray*>( fManger->GetObject("GlobalTrack") );
97 flistTofHits = dynamic_cast<TClonesArray*>( fManger->GetObject("TofHit") );
98/* flistRichRings = dynamic_cast<TClonesArray*>( fManger->GetObject("RichRing") );
99 flistTrdTracks = dynamic_cast<TClonesArray*>( fManger->GetObject("TrdTrack") );
100
101// if (fRichGeoType != "compact" && fRichGeoType != "large"){
102// fRichGeoType = "compact";
103// }
104
105 std::string richANNFile = gSystem->Getenv("VMCWORKDIR");
106// if (fRichGeoType == "compact"){
107 richANNFile += "/parameters/rich/el_id_ann_weights_rich_compact.txt";
108// }
109// else if (fRichGeoType == "large"){
110// richANNFile += "/parameters/rich/el_id_ann_weights_rich.txt";
111// }
112
113 fElIdAnn = new CbmRichElectronIdAnn(richANNFile);
114 fElIdAnn->Init();*/
115 }
116
117 return kSUCCESS;
118}
119
121{
122 return ReInit();
123}
124
125void CbmKFParticlesFinder::Exec(Option_t * option)
126{
127 if(!flistStsTracks) return;
128// if(!fPrimVtx) return;
129
130 if(!flistStsTracksMatch) return;
131 if(!flistMCTracks) return;
132
133 vector<CbmStsTrack> vRTracks;
134 int nTracks = flistStsTracks->GetEntries();
135 vRTracks.resize(nTracks);
136 for(int iTr=0; iTr<nTracks; iTr++)
137 vRTracks[iTr] = *( (CbmStsTrack*) flistStsTracks->At(iTr));
138
139 CbmKFVertex kfVertex;
140 if(fPrimVtx)
141 kfVertex = CbmKFVertex(*fPrimVtx);
142
143 vector<int> vTrackPDG(vRTracks.size(), -1);
144 if(fusePID == 1)
145 {
146 for(int iTr=0; iTr<nTracks; iTr++)
147 {
148 CbmTrackMatch* stsTrackMatch = (CbmTrackMatch*)flistStsTracksMatch->At(iTr);
149 if(stsTrackMatch -> GetNofMCTracks() == 0) continue;
150 const int mcTrackId = stsTrackMatch->GetMCTrackId();
151 CbmMCTrack* mcTrack = (CbmMCTrack*)flistMCTracks->At(mcTrackId);
152 vTrackPDG[iTr] = mcTrack->GetPdgCode();
153 }
154 }
155
156 if(fusePID == 2)
157 {
158 if (NULL == flsitGlobalTracks) { Fatal("KF Particle Finder", "No GlobalTrack array!"); }
159 if (NULL == flistTofHits) { Fatal("KF Particle Finder", "No TOF hits array!"); }
160
161 const Double_t m2P = 0.867681;
162 const Double_t m2K = 0.243707;
163 const Double_t m2Pi = 0.019479835;
164
165 Double_t sP[3][5] = { {0.0243467, -0.00937908, 0.00970666, -0.00063638, 2.42128e-05},
166 {0.00691158, -0.000777367, 0.00671164, -0.000123594, -2.17075e-05},
167 {0.0055599, -0.00327273, 0.00981961, -0.00108836, 7.90106e-05} };
168
169// sP[0][0] = 0.0618927;
170// sP[0][1] = -0.0719277;
171// sP[0][2] = 0.0396255;
172// sP[0][3] = -0.00583356;
173// sP[0][4] = 0.000317072;
174//
175// sP[1][0] = 0.0291881;
176// sP[1][1] = -0.0904978;
177// sP[1][2] = 0.086161;
178// sP[1][3] = -0.0229688;
179// sP[1][4] = 0.00199382;
180//
181// sP[2][0] = 0.162171;
182// sP[2][1] = -0.194007;
183// sP[2][2] = 0.0893264;
184// sP[2][3] = -0.014626;
185// sP[2][4] = 0.00088203;
186
187 const Int_t PdgHypo[4] = {2212, 321, 211, -11};
188
189 for (Int_t igt = 0; igt < flsitGlobalTracks->GetEntriesFast(); igt++) {
190 const CbmGlobalTrack* globalTrack = static_cast<const CbmGlobalTrack*>(flsitGlobalTracks->At(igt));
191
192 Int_t stsTrackIndex = globalTrack->GetStsTrackIndex();
193 if( stsTrackIndex<0 ) continue;
194
195// Bool_t isElectronTRD = 0;
196// Bool_t isElectronRICH = 0;
197// Bool_t isElectron = 0;
198
199 FairTrackParam *stsPar = vRTracks[stsTrackIndex].GetParamFirst();
200 TVector3 mom;
201 stsPar->Momentum(mom);
202
203 Double_t p = mom.Mag();
204 Int_t q = stsPar->GetQp() > 0 ? 1 : -1;
205
206// if(flistRichRings)
207// {
208// Int_t richIndex = globalTrack->GetRichRingIndex();
209// if (richIndex > -1)
210// {
211// CbmRichRing* richRing = (CbmRichRing*)flistRichRings->At(richIndex);
212// if (richRing)
213// if(fElIdAnn->DoSelect(richRing, p) > -0.5) isElectronRICH = 1;
214// }
215// }
216//
217// if(flistTrdTracks)
218// {
219// Int_t trdIndex = globalTrack->GetTrdTrackIndex();
220// if (trdIndex > -1)
221// {
222// CbmTrdTrack* trdTrack = (CbmTrdTrack*)flistTrdTracks->At(trdIndex);
223// if (trdTrack)
224// if (trdTrack->GetPidANN() > 0.979) isElectronTRD = 1;
225// }
226// }
227
228 Double_t l = globalTrack->GetLength();
229 if( !((l>1000.) && (l<1400.)) ) continue;
230
231 Double_t time;
232 Int_t tofHitIndex = globalTrack->GetTofHitIndex();
233 if (tofHitIndex >= 0) {
234 const CbmTofHit* tofHit = static_cast<const CbmTofHit*>(flistTofHits->At(tofHitIndex));
235 if(!tofHit) continue;
236 time = tofHit->GetTime();
237 }
238 else
239 continue;
240
241 if( !((time>29.) && (time<50.)) ) continue;
242
243 Double_t m2 = p*p*(1./((l/time/29.9792458)*(l/time/29.9792458))-1.);
244
245 Double_t sigma[3];
246 sigma[0] = sP[0][0] + sP[0][1]*p + sP[0][2]*p*p + sP[0][3]*p*p*p + sP[0][4]*p*p*p*p;
247 sigma[1] = sP[1][0] + sP[1][1]*p + sP[1][2]*p*p + sP[1][3]*p*p*p + sP[1][4]*p*p*p*p;
248 sigma[2] = sP[2][0] + sP[2][1]*p + sP[2][2]*p*p + sP[2][3]*p*p*p + sP[2][4]*p*p*p*p;
249
250 Double_t dm2[3];
251 dm2[0] = fabs(m2 - m2P)/sigma[0];
252 dm2[1] = fabs(m2 - m2K)/sigma[1];
253 dm2[2] = fabs(m2 - m2Pi)/sigma[2];
254
255 int iPdg=2;
256 Double_t dm2min = dm2[2];
257
258// if(isElectronRICH && isElectronTRD)
259// {
260// if (p >= 1.) {
261// if (m2 < (0.01 + (p - 1.) * 0.09))
262// isElectron = 1;
263// }
264// else {
265// if (m2 < 0.0)
266// isElectron = 1;
267// }
268// }
269//
270// if(!isElectron)
271 {
272 if(p>12.) continue;
273 if(q>0)
274 {
275 if(dm2[1] < dm2min) { iPdg = 1; dm2min = dm2[1]; }
276 if(dm2[0] < dm2min) { iPdg = 0; dm2min = dm2[0]; }
277
278 if(dm2min > 2) iPdg=-1;
279 }
280 else
281 {
282 if(dm2[1] < dm2min) { iPdg = 1; dm2min = dm2[1]; }
283 if((dm2min>3) && (dm2[0] < dm2min)) { iPdg = 0; dm2min = dm2[0]; }
284
285 if(dm2min > 2) iPdg=-1;
286 }
287
288 if(iPdg > -1)
289 vTrackPDG[stsTrackIndex] = q*PdgHypo[iPdg];
290 }
291// else
292// vTrackPDG[stsTrackIndex] = q*PdgHypo[3];
293 }
294 }
295
296/*
297 for(int iTr=0; iTr<nTracks; iTr++)
298 {
299 if(vRTracks[iTr].GetParamFirst()->GetQp()<0) vTrackPDG[iTr] *= -1;
300 }*/
301
302 TStopwatch timerSelect;
303
304 fParticles.clear();
305 fChiToPrimVtx.clear();
306
307 CbmL1PFFitter fitter;
308
309// fitter.Fit(vRTracks); //assumed, that the initial fit should be fixed and must return good results!!!
310
311 vector<L1FieldRegion> vField;
312 fitter.GetChiToVertex(vRTracks, vField, fChiToPrimVtx, kfVertex, 3);
313
314// fitter.CalculateFieldRegion(vRTracks, vField);
315
316 vector<CbmKFTrack> vKFTrack(nTracks);
317 for(int iTr=0; iTr<nTracks; iTr++)
318 vKFTrack[iTr] = CbmKFTrack(vRTracks[iTr]);
319
320 KFParticleSIMD pVtx(kfVertex);
321 KFParticleFinder::FindParticles(vKFTrack, fChiToPrimVtx, vField, fParticles, pVtx, vTrackPDG, fCuts);
322// CbmKFParticleInterface::FindParticles(vKFTrack, ChiToPrimVtx, vField, fParticles, kfVertex, vTrackPDG, fCuts);
323
324 timerSelect.Stop();
325
326 static int NEv=0;
327 NEv++;
328 static double timeSelectCPU=0.;
329 static double timeSelectReal=0.;
330
331 timeSelectCPU += timerSelect.CpuTime();
332 timeSelectReal += timerSelect.RealTime();
333
334 if(NEv%100==0)
335 {
336 std::cout.setf(ios::fixed);
337 std::cout.setf(ios::showpoint);
338 std::cout.precision(9);
339 std::cout << " ---- Particle finder --- " << std::endl;
340 std::cout << "KF Particle Finder Times:" <<" Real - "<< timeSelectReal/NEv
341 << " CPU - "<< timeSelectCPU/NEv << std::endl << std::endl;
342 }
343}
344
friend F32vec4 fabs(const F32vec4 &a)
Definition P4_F32vec4.h:52
int i
Definition P4_F32vec4.h:22
Double_t GetLength() const
Int_t GetTofHitIndex() const
Int_t GetStsTrackIndex() const
void Exec(Option_t *option)
CbmKFParticlesFinder(float cuts[2][3]=0, Int_t usePID=0, const char *name="CbmKFParticlesFinder", const char *title="Cbm KF Particles Finder", Int_t iVerbose=1)
void GetChiToVertex(std::vector< CbmL1Track > &Tracks, std::vector< float > &chiToVtx, CbmKFVertex &primVtx)
Int_t GetPdgCode() const
Definition CbmMCTrack.h:56
Double_t GetTime() const
Definition CbmTofHit.h:57
Int_t GetMCTrackId() const
static void FindParticles(std::vector< CbmKFTrack > &vRTracks, std::vector< float > &ChiToPrimVtx, std::vector< L1FieldRegion > &vField, std::vector< KFParticle > &Particles, KFParticleSIMD &PrimVtx, const std::vector< int > &vTrackPDG, const float cuts[2][3]=DefaultCuts)