PandaRoot
KFPartEfficiencies.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef KFPartEfficiencies_H
14 #define KFPartEfficiencies_H
15 
16 #include "TNamed.h"
17 #include "Counters.h"
18 #include <iomanip>
19 
20 using std::setw;
21 
22 class KFPartEfficiencies : public TNamed {
23  public:
24  KFPartEfficiencies() : names(), indices(), ratio_reco(), mc(), reco(), ratio_ghost(), ratio_bg(), ratio_clone(), ghost(), bg(), clone()
25  {
26  // add total efficiency
27  // AddCounter("piPlus" ,"PiPlus efficiency");
28  // AddCounter("piMinus" ,"PiMinus efficiency");
29  int mPartPDG[nParticles] = {
30  310, 3122, -3122, 3312, -3312, 3334, -3334, // strange meson and hyperons
31  313, -313, 323, -323, // K* resonances
32  3224, 3114, -3114, -3224, // sigma resonances
33  3124, -3124, // Lambda resonances
34  3324, -3324, 1003314, -1003314, // Xi resonances
35  1003334, -100334, // Omega resonances
36  3000, // exotics
37  333, 113, // vector mesons, hadron chanel
38  100113, 200113, // light vector mesons
39  22, // dielectrons
40  443, 100443, // J/Psi
41  421, -421, 100421, -100421, // D0
42  411, -411, // D+, D-
43  431, -431, // Ds+, Ds-
44  4122, -4122, // Lambdac
45  10421, -10421, 10411, -10411, 20411, -20411,
46  3001 // H->Lambda p pi
47  };
48  TString mPartName[nParticles] = {"ks",
49  "lambda",
50  "lambdab",
51  "xi-",
52  "xi+",
53  "omega-",
54  "omega+",
55  "k*0",
56  "k*0b",
57  "k*+",
58  "k*-",
59  "sigma*+",
60  "sigma*-",
61  "sigma*+b",
62  "sigma*-b",
63  "lambda*",
64  "lambda*b",
65  "xi*0",
66  "xi*0b",
67  "xi*-_{#Lambda,K}",
68  "xi*+_{#Lambda,K}",
69  "omega*-",
70  "omega*+",
71  "Hdb",
72  "phi_{KK}",
73  "rho_{#pi#pi}",
74  "rho_{ee}",
75  "rho_{#mu#mu}",
76  "gamma",
77  "J#Psi_ee",
78  "J#Psi_#mu#mu",
79  "D0",
80  "D0b",
81  "D0_4",
82  "D0b_4",
83  "D+",
84  "D-",
85  "Ds+",
86  "Ds-",
87  "lambdac",
88  "lambdacb",
89  "D*0",
90  "D*0b",
91  "D*+",
92  "D*-",
93  "D*+_4",
94  "D*-_4",
95  "H0"};
96  TString mPartTitle[nParticles] = {
97  "KShort ", // 0
98  "Lambda ", // 1
99  "Lambda b ", // 2
100  "Xi- ", // 3
101  "Xi+ ", // 4
102  "Omega- ", // 5
103  "Omega+ ", // 6
104  "K*0 ", // 7
105  "K*0 b ", // 8
106  "K*+ ", // 9
107  "K*- ", // 10
108  "Sigma*+ ", // 11
109  "Sigma*- ", // 12
110  "Sigma*+ b", // 13
111  "Sigma*- b", // 14
112  "Lambda* ", // 15
113  "Lambda* b", // 16
114  "Xi*0 ", // 17
115  "Xi*0 b ", // 18
116  "Xi*-_lk ", // 19
117  "Xi*+_lk ", // 20
118  "Omega*- ", // 21
119  "Omega*+ ", // 22
120  "Hdb ", // 23
121  "phi_kk ", // 24
122  "rho_pipi ", // 25
123  "rho_ee ", // 26
124  "rho_mm ", // 27
125  "gamma ", // 28
126  "JPsi_ee ", // 29
127  "JPsi_mm ", // 30
128  "D0 ", // 31
129  "D0b ", // 32
130  "D0_4 ", // 33
131  "D0b_4 ", // 34
132  "D+ ", // 35
133  "D- ", // 36
134  "Ds+ ", // 37
135  "Ds- ", // 38
136  "Lambdac ", // 39
137  "Lambdac b", // 40
138  "D*0 ", // 41
139  "D*0 b ", // 42
140  "D*+ ", // 43
141  "D*- ", // 44
142  "D*+_4 ", // 45
143  "D*-_4 ", // 46
144  "H0 " // 47
145  };
146 
147  float mPartMHistoMin[nParticles] = {0.3, 1., 1., 1., 1., 1., 1., 0.6, 0.6, 0.6, 0.6, 1., 1., 1., 1., 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.8, 1.8, 1.,
148  0.6, 0.1, 0.1, 0.1, 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.8, 1.};
149  float mPartMHistoMax[nParticles] = {1.3, 2., 2., 3., 3., 3., 3., 2.6, 2.6, 2.6, 2.6, 3., 3., 3., 3., 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.8, 3.8, 3.,
150  1.6, 2.1, 2.1, 2.1, 3., 4., 4., 3., 3., 3., 3., 3., 3., 3., 3., 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.8, 3.};
151  // set decay mode
152  partDaughterPdg.resize(nParticles);
153 
154  partDaughterPdg[0].push_back(211); // K0s -> pi+ pi-
155  partDaughterPdg[0].push_back(-211);
156 
157  partDaughterPdg[1].push_back(2212); // Lambda -> p pi-
158  partDaughterPdg[1].push_back(-211);
159 
160  partDaughterPdg[2].push_back(-2212); // Lambda_bar -> p- pi+
161  partDaughterPdg[2].push_back(211);
162 
163  partDaughterPdg[3].push_back(3122); // Ksi- -> Lambda pi-
164  partDaughterPdg[3].push_back(-211);
165 
166  partDaughterPdg[4].push_back(-3122); // Ksi+ -> Lambda_bar pi+
167  partDaughterPdg[4].push_back(211);
168 
169  partDaughterPdg[5].push_back(3122); // Omega- -> Lambda K-
170  partDaughterPdg[5].push_back(-321);
171 
172  partDaughterPdg[6].push_back(-3122); // Omega+ -> Lambda_bar K+
173  partDaughterPdg[6].push_back(321);
174 
175  partDaughterPdg[7].push_back(321); // K*0 -> K+ pi-
176  partDaughterPdg[7].push_back(-211);
177 
178  partDaughterPdg[8].push_back(-321); // K*0_bar -> K- pi+
179  partDaughterPdg[8].push_back(211);
180 
181  partDaughterPdg[9].push_back(310); // K*+ -> K0s pi+
182  partDaughterPdg[9].push_back(211);
183 
184  partDaughterPdg[10].push_back(310); // K*- -> K0s pi-
185  partDaughterPdg[10].push_back(-211);
186 
187  partDaughterPdg[11].push_back(3122); // Sigma+ -> Lambda pi+
188  partDaughterPdg[11].push_back(211);
189 
190  partDaughterPdg[12].push_back(3122); // Sigma- -> Lambda pi-
191  partDaughterPdg[12].push_back(-211);
192 
193  partDaughterPdg[13].push_back(-3122); // Sigma+_bar -> Lambda_bar pi+
194  partDaughterPdg[13].push_back(211);
195 
196  partDaughterPdg[14].push_back(-3122); // Sigma-_bar -> Lambda_bar pi-
197  partDaughterPdg[14].push_back(-211);
198 
199  partDaughterPdg[15].push_back(2212); // Lambda* -> p K-
200  partDaughterPdg[15].push_back(-321);
201 
202  partDaughterPdg[16].push_back(-2212); // Lambda*_bar -> p- K+
203  partDaughterPdg[16].push_back(321);
204 
205  partDaughterPdg[17].push_back(3312); // Xi*0 -> Xi- pi+
206  partDaughterPdg[17].push_back(211);
207 
208  partDaughterPdg[18].push_back(-3312); // Xi*0_bar -> Xi+ pi-
209  partDaughterPdg[18].push_back(-211);
210 
211  partDaughterPdg[19].push_back(3122); // Xi*- -> Lambda K-
212  partDaughterPdg[19].push_back(-321);
213 
214  partDaughterPdg[20].push_back(-3122); // Xi*+ -> Lambda_bar K+
215  partDaughterPdg[20].push_back(321);
216 
217  partDaughterPdg[21].push_back(3312); // Omega*- -> Xi- pi+ K-
218  partDaughterPdg[21].push_back(211);
219  partDaughterPdg[21].push_back(-321);
220 
221  partDaughterPdg[22].push_back(-3312); // Omega*- -> Xi+ pi- K+
222  partDaughterPdg[22].push_back(-211);
223  partDaughterPdg[22].push_back(321);
224 
225  partDaughterPdg[23].push_back(3122); // H-dibar -> Lambda Lambda
226  partDaughterPdg[23].push_back(3122);
227 
228  partDaughterPdg[24].push_back(321); // phi -> K+ K-
229  partDaughterPdg[24].push_back(-321);
230 
231  partDaughterPdg[25].push_back(211); // rho, omega, phi -> pi+ pi-
232  partDaughterPdg[25].push_back(-211);
233 
234  partDaughterPdg[26].push_back(11); // rho, omega, phi -> e+ e-
235  partDaughterPdg[26].push_back(-11);
236 
237  partDaughterPdg[27].push_back(13); // rho, omega, phi -> mu+ mu-
238  partDaughterPdg[27].push_back(-13);
239 
240  partDaughterPdg[28].push_back(11); // gamma -> e+ e-
241  partDaughterPdg[28].push_back(-11);
242 
243  partDaughterPdg[29].push_back(11); // JPsi -> e+ e-
244  partDaughterPdg[29].push_back(-11);
245 
246  partDaughterPdg[30].push_back(13); // JPsi -> mu+ mu-
247  partDaughterPdg[30].push_back(-13);
248 
249  partDaughterPdg[31].push_back(211); // D0 -> pi+ K-
250  partDaughterPdg[31].push_back(-321);
251 
252  partDaughterPdg[32].push_back(-211); // D0_bar -> K+ pi-
253  partDaughterPdg[32].push_back(321);
254 
255  partDaughterPdg[33].push_back(211); // D0 -> pi+ pi+ pi- K-
256  partDaughterPdg[33].push_back(211);
257  partDaughterPdg[33].push_back(-211);
258  partDaughterPdg[33].push_back(-321);
259 
260  partDaughterPdg[34].push_back(-211); // D0_bar -> pi- pi- pi+ K+
261  partDaughterPdg[34].push_back(-211);
262  partDaughterPdg[34].push_back(211);
263  partDaughterPdg[34].push_back(321);
264 
265  partDaughterPdg[35].push_back(-321); // D+ -> K- pi+ pi+
266  partDaughterPdg[35].push_back(211);
267  partDaughterPdg[35].push_back(211);
268 
269  partDaughterPdg[36].push_back(321); // D- -> K+ pi- pi-
270  partDaughterPdg[36].push_back(-211);
271  partDaughterPdg[36].push_back(-211);
272 
273  partDaughterPdg[37].push_back(-321); // Ds+ -> K- K+ pi+
274  partDaughterPdg[37].push_back(321);
275  partDaughterPdg[37].push_back(211);
276 
277  partDaughterPdg[38].push_back(321); // Ds- -> K+ K- pi-
278  partDaughterPdg[38].push_back(-321);
279  partDaughterPdg[38].push_back(-211);
280 
281  partDaughterPdg[39].push_back(211); // Lambdac -> pi+ K- p
282  partDaughterPdg[39].push_back(-321);
283  partDaughterPdg[39].push_back(2212);
284 
285  partDaughterPdg[40].push_back(-211); // Lambdac_bar -> pi- K+ p-
286  partDaughterPdg[40].push_back(321);
287  partDaughterPdg[40].push_back(-2212);
288 
289  partDaughterPdg[41].push_back(411); // D*0 -> D+ pi-
290  partDaughterPdg[41].push_back(-211);
291 
292  partDaughterPdg[42].push_back(-411); // D*0_bar -> D- pi+
293  partDaughterPdg[42].push_back(211);
294 
295  partDaughterPdg[43].push_back(421); // D*+ -> D0 pi+
296  partDaughterPdg[43].push_back(211);
297 
298  partDaughterPdg[44].push_back(-421); // D*- -> D0_bar pi-
299  partDaughterPdg[44].push_back(-211);
300 
301  partDaughterPdg[45].push_back(421); // D*+ -> D04 pi+
302  partDaughterPdg[45].push_back(211);
303 
304  partDaughterPdg[46].push_back(-421); // D*- -> D04_bar pi-
305  partDaughterPdg[46].push_back(-211);
306 
307  partDaughterPdg[47].push_back(3122); // H0-> Lambda pi- p
308  partDaughterPdg[47].push_back(-211);
309  partDaughterPdg[47].push_back(2212);
310 
311  for (int iP = 0; iP < nParticles; iP++) {
312  partPDG[iP] = mPartPDG[iP];
313  partName[iP] = mPartName[iP];
314  partTitle[iP] = mPartTitle[iP];
315  partMHistoMin[iP] = mPartMHistoMin[iP];
316  partMHistoMax[iP] = mPartMHistoMax[iP];
317  }
318 
319  for (int iP = 0; iP < nParticles; iP++) {
320  AddCounter(Form("%s", partName[iP].Data()), Form("%-*s", 14, partTitle[iP].Data()));
321  AddCounter(Form("%s_prim", partName[iP].Data()), Form("%s Prim", partTitle[iP].Data()));
322  AddCounter(Form("%s_sec", partName[iP].Data()), Form("%s Sec ", partTitle[iP].Data()));
323  }
324 
325  for (int iP = 0; iP < nParticles; iP++)
326  fPdgToIndex[mPartPDG[iP]] = iP;
327  }
328 
329  virtual ~KFPartEfficiencies(){};
330 
331  int GetParticleIndex(int pdg)
332  {
333  std::map<int, int>::iterator it;
334  it = fPdgToIndex.find(pdg);
335  if (it != fPdgToIndex.end())
336  return it->second;
337  else
338  return -1;
339  }
340 
341  virtual void AddCounter(TString shortname, TString name)
342  {
343  indices[shortname] = names.size();
344  names.push_back(name);
345 
346  ratio_reco.AddCounter();
347  mc.AddCounter();
348  reco.AddCounter();
349 
350  ratio_ghost.AddCounter();
351  ratio_bg.AddCounter();
352  ratio_clone.AddCounter();
353  ghost.AddCounter();
354  bg.AddCounter();
355  clone.AddCounter();
356  };
357 
359  {
360  mc += a.mc;
361  reco += a.reco;
362  ghost += a.ghost;
363  bg += a.bg;
364  clone += a.clone;
365  return *this;
366  };
367 
368  void CalcEff()
369  {
370  ratio_reco = reco / mc;
371 
372  TTracksCatCounters<int> allReco = reco + ghost + bg;
373  ratio_ghost = ghost / allReco;
374  ratio_bg = bg / allReco;
375  ratio_clone = clone / allReco;
376  };
377 
378  void Inc(bool isReco, int nClones, TString name)
379  {
380  const int index = indices[name];
381 
382  mc.counters[index]++;
383  if (isReco)
384  reco.counters[index]++;
385  if (nClones > 0)
386  clone.counters[index] += nClones;
387  };
388 
389  void IncReco(bool isGhost, bool isBg, TString name)
390  {
391  const int index = indices[name];
392 
393  if (isGhost)
394  ghost.counters[index]++;
395  if (isBg)
396  bg.counters[index]++;
397  };
398 
399  void PrintEff()
400  {
401 
402  // save original cout flags
403  std::ios_base::fmtflags coutFlags = cout.flags();
404 
405  std::cout.setf(ios::fixed);
406  std::cout.setf(ios::showpoint);
407  std::cout.precision(3);
408  std::cout << "Particle : "
409  << " Eff "
410  << " / "
411  << " Ghost "
412  << " / "
413  << "BackGr "
414  << " / "
415  << "N Ghost"
416  << " / "
417  << "N BackGr"
418  << " / "
419  << "N Reco "
420  << " / "
421  << "N Clone "
422  << " | "
423  << " N MC " << std::endl;
424 
425  int NCounters = mc.NCounters;
426  for (int iC = 0; iC < NCounters; iC++) {
427  std::cout << names[iC] << " : " << setw(6) << ratio_reco.counters[iC] << " / " << setw(6) << ratio_ghost.counters[iC] // particles w\o MCParticle
428  << " / " << setw(6) << ratio_bg.counters[iC] // particles with incorrect MCParticle
429  << " / " << setw(6) << ghost.counters[iC] << " / " << setw(7) << bg.counters[iC] << " / " << setw(6) << reco.counters[iC] << " / " << setw(7)
430  << clone.counters[iC] << " | " << setw(6) << mc.counters[iC] << std::endl;
431  }
432 
433  // restore original cout flags
434  cout.flags(coutFlags);
435  };
436 
437  friend std::fstream &operator<<(std::fstream &strm, KFPartEfficiencies &a)
438  {
439 
440  strm << a.ratio_reco;
441  strm << a.mc;
442  strm << a.reco;
443  strm << a.ratio_ghost;
444  strm << a.ratio_bg;
445  strm << a.ratio_clone;
446  strm << a.ghost;
447  strm << a.bg;
448  strm << a.clone;
449 
450  return strm;
451  }
452 
453  friend std::fstream &operator>>(std::fstream &strm, KFPartEfficiencies &a)
454  {
455 
456  strm >> a.ratio_reco;
457  strm >> a.mc;
458  strm >> a.reco;
459  strm >> a.ratio_ghost;
460  strm >> a.ratio_bg;
461  strm >> a.ratio_clone;
462  strm >> a.ghost;
463  strm >> a.bg;
464  strm >> a.clone;
465 
466  return strm;
467  }
468 
469  void AddFromFile(TString fileName)
470  {
471  std::fstream file(fileName.Data(), fstream::in);
472  file >> *this;
473  }
474 
475  static const int nParticles = 48;
479  vector<vector<int>> partDaughterPdg;
482 
483  // ClassDef(KFPartEfficiencies,1);
484 
485  private:
486  vector<TString> names; // names counters indexed by index of counter
487  map<TString, int> indices; // indices of counters indexed by a counter shortname
488 
489  map<int, int> fPdgToIndex;
490 
491  TTracksCatCounters<double> ratio_reco;
492 
495 
496  TTracksCatCounters<double> ratio_ghost;
498  TTracksCatCounters<double> ratio_clone;
499 
501  TTracksCatCounters<int> bg; // background
502  TTracksCatCounters<int> clone; // background
503 };
504 
505 #endif
void Inc(bool isReco, int nClones, TString name)
friend std::fstream & operator>>(std::fstream &strm, KFPartEfficiencies &a)
void IncReco(bool isGhost, bool isBg, TString name)
vector< vector< int > > partDaughterPdg
float partMHistoMin[nParticles]
TString partTitle[nParticles]
TString partName[nParticles]
KFPartEfficiencies & operator+=(KFPartEfficiencies &a)
friend std::fstream & operator<<(std::fstream &strm, KFPartEfficiencies &a)
static const int nParticles
int GetParticleIndex(int pdg)
void AddFromFile(TString fileName)
virtual void AddCounter(TString shortname, TString name)
int partPDG[nParticles]
float partMHistoMax[nParticles]