Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFPVEfficiencies.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFPVEfficiencies.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  *
8  * KFParticle is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * KFParticle is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef KFPVEfficiencies_H
23 #define KFPVEfficiencies_H
24 
25 #ifndef HLTCA_STANDALONE
26 #include "TNamed.h"
27 #endif
28 
29 #include <map>
30 #include <iomanip>
31 #include "KFMCCounter.h"
32 
47 class KFPVEfficiencies: public TNamed
48 {
49  public:
50 
52  names(),
53  indices(),
54  ratio_reco(),
55  mc(),
56  reco(),
57  ratio_ghost(),
58  ratio_bg(),
59  ratio_clone(),
60  ghost(),
61  bg(),
62  clone()
63  {
64  AddCounter(Form("%s","PV"), Form("%-*s",12,"PV"));
65  AddCounter(Form("%s","PVtrigger"), Form("%-*s",12,"PV trigger"));
66  AddCounter(Form("%s","PVpileup"), Form("%-*s",12,"PV pileup "));
67  }
68 
69  virtual ~KFPVEfficiencies(){};
70 
71  virtual void AddCounter(TString shortname, TString name)
72  {
79  indices[shortname] = names.size();
80  names.push_back(name);
81 
83  mc.AddCounter();
84  reco.AddCounter();
85 
89  ghost.AddCounter();
90  bg.AddCounter();
91  clone.AddCounter();
92  };
93 
96  mc += a.mc; reco += a.reco;
97  ghost += a.ghost; bg += a.bg; clone += a.clone;
98  return *this;
99  };
100 
102  void CalcEff(){
103  ratio_reco = reco/mc;
104 
105  KFMCCounter<int> allReco = reco + ghost + bg;
106  ratio_ghost = ghost/allReco;
107  ratio_bg = bg/allReco;
108  ratio_clone = clone/allReco;
109  };
110 
111 
112  void Inc(bool isReco, int nClones, TString name)
113  {
121  const int index = indices[name];
122 
123  mc.counters[index]++;
124  if (isReco) reco.counters[index]++;
125  if(nClones > 0)
126  clone.counters[index] += nClones;
127  };
128 
129  void IncReco(bool isGhost, bool isBg, TString name)
130  {
136  const int index = indices[name];
137 
138  if (isGhost) ghost.counters[index]++;
139  if (isBg) bg.counters[index]++;
140  };
141 
143  void PrintEff(){
144  std::ios_base::fmtflags original_flags = std::cout.flags();
145  std::cout.setf(std::ios::fixed);
146  std::cout.setf(std::ios::showpoint);
147  std::cout.precision(3);
148  std::cout << " : "
149  << " Eff "
150  <<" / "<< " Ghost "
151  <<" / "<< "BackGr "
152  <<" / "<< "Clone "
153  <<" / "<< "N Ghost"
154  <<" / "<< "N BackGr"
155  <<" / "<< "N Reco "
156  <<" / "<< "N Clone "
157  <<" | "<< " N MC " << std::endl;
158 
159  int NCounters = mc.NCounters;
160  for (int iC = 0; iC < NCounters; iC++){
161  std::cout << names[iC]
162  << " : " << std::setw(6) << ratio_reco.counters[iC]
163  << " / " << std::setw(6) << ratio_ghost.counters[iC] // particles w\o MCParticle
164  << " / " << std::setw(6) << ratio_bg.counters[iC] // particles with incorrect MCParticle
165  << " / " << std::setw(6) << ratio_clone.counters[iC] // particles with incorrect MCParticle
166  << " / " << std::setw(6) << ghost.counters[iC]
167  << " / " << std::setw(7) << bg.counters[iC]
168  << " / " << std::setw(6) << reco.counters[iC]
169  << " / " << std::setw(7) << clone.counters[iC]
170  << " | " << std::setw(6) << mc.counters[iC] << std::endl;
171  }
172  std::cout.flags(original_flags);
173  };
174 
176  friend std::fstream & operator<<(std::fstream &strm, KFPVEfficiencies &a) {
177 
178  strm << a.ratio_reco;
179  strm << a.mc;
180  strm << a.reco;
181  strm << a.ratio_ghost;
182  strm << a.ratio_bg;
183  strm << a.ratio_clone;
184  strm << a.ghost;
185  strm << a.bg;
186  strm << a.clone;
187 
188  return strm;
189  }
191  friend std::fstream & operator>>(std::fstream &strm, KFPVEfficiencies &a){
192 
193  strm >> a.ratio_reco;
194  strm >> a.mc;
195  strm >> a.reco;
196  strm >> a.ratio_ghost;
197  strm >> a.ratio_bg;
198  strm >> a.ratio_clone;
199  strm >> a.ghost;
200  strm >> a.bg;
201  strm >> a.clone;
202 
203  return strm;
204  }
206  void AddFromFile(TString fileName)
207  {
208  std::fstream file(fileName.Data(),std::fstream::in);
209  file >> *this;
210  }
211 
212  private:
213  std::vector<TString> names;
214  std::map<TString, int> indices;
215 
217 
220 
224 
228 };
229 
230 #endif