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