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