File indexing completed on 2025-08-03 08:20:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #ifndef KFPVEfficiencies_H
0023 #define KFPVEfficiencies_H
0024
0025 #ifndef HLTCA_STANDALONE
0026 #include "TNamed.h"
0027 #endif
0028
0029 #include <map>
0030 #include <iomanip>
0031 #include "KFMCCounter.h"
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 class KFPVEfficiencies: public TNamed
0048 {
0049 public:
0050
0051 KFPVEfficiencies():
0052 names(),
0053 indices(),
0054 ratio_reco(),
0055 mc(),
0056 reco(),
0057 ratio_ghost(),
0058 ratio_bg(),
0059 ratio_clone(),
0060 ghost(),
0061 bg(),
0062 clone()
0063 {
0064 AddCounter(Form("%s","PV"), Form("%-*s",12,"PV"));
0065 AddCounter(Form("%s","PVtrigger"), Form("%-*s",12,"PV trigger"));
0066 AddCounter(Form("%s","PVpileup"), Form("%-*s",12,"PV pileup "));
0067 }
0068
0069 virtual ~KFPVEfficiencies(){};
0070
0071 virtual void AddCounter(TString shortname, TString name)
0072 {
0073
0074
0075
0076
0077
0078
0079 indices[shortname] = names.size();
0080 names.push_back(name);
0081
0082 ratio_reco.AddCounter();
0083 mc.AddCounter();
0084 reco.AddCounter();
0085
0086 ratio_ghost.AddCounter();
0087 ratio_bg.AddCounter();
0088 ratio_clone.AddCounter();
0089 ghost.AddCounter();
0090 bg.AddCounter();
0091 clone.AddCounter();
0092 };
0093
0094
0095 KFPVEfficiencies& operator+=(KFPVEfficiencies& a){
0096 mc += a.mc; reco += a.reco;
0097 ghost += a.ghost; bg += a.bg; clone += a.clone;
0098 return *this;
0099 };
0100
0101
0102 void CalcEff(){
0103 ratio_reco = reco/mc;
0104
0105 KFMCCounter<int> allReco = reco + ghost + bg;
0106 ratio_ghost = ghost/allReco;
0107 ratio_bg = bg/allReco;
0108 ratio_clone = clone/allReco;
0109 };
0110
0111
0112 void Inc(bool isReco, int nClones, TString name)
0113 {
0114
0115
0116
0117
0118
0119
0120
0121 const int index = indices[name];
0122
0123 mc.counters[index]++;
0124 if (isReco) reco.counters[index]++;
0125 if(nClones > 0)
0126 clone.counters[index] += nClones;
0127 };
0128
0129 void IncReco(bool isGhost, bool isBg, TString name)
0130 {
0131
0132
0133
0134
0135
0136 const int index = indices[name];
0137
0138 if (isGhost) ghost.counters[index]++;
0139 if (isBg) bg.counters[index]++;
0140 };
0141
0142
0143 void PrintEff(){
0144 std::ios_base::fmtflags original_flags = std::cout.flags();
0145 std::cout.setf(std::ios::fixed);
0146 std::cout.setf(std::ios::showpoint);
0147 std::cout.precision(3);
0148 std::cout << " : "
0149 << " Eff "
0150 <<" / "<< " Ghost "
0151 <<" / "<< "BackGr "
0152 <<" / "<< "Clone "
0153 <<" / "<< "N Ghost"
0154 <<" / "<< "N BackGr"
0155 <<" / "<< "N Reco "
0156 <<" / "<< "N Clone "
0157 <<" | "<< " N MC " << std::endl;
0158
0159 int NCounters = mc.NCounters;
0160 for (int iC = 0; iC < NCounters; iC++){
0161 std::cout << names[iC]
0162 << " : " << std::setw(6) << ratio_reco.counters[iC]
0163 << " / " << std::setw(6) << ratio_ghost.counters[iC]
0164 << " / " << std::setw(6) << ratio_bg.counters[iC]
0165 << " / " << std::setw(6) << ratio_clone.counters[iC]
0166 << " / " << std::setw(6) << ghost.counters[iC]
0167 << " / " << std::setw(7) << bg.counters[iC]
0168 << " / " << std::setw(6) << reco.counters[iC]
0169 << " / " << std::setw(7) << clone.counters[iC]
0170 << " | " << std::setw(6) << mc.counters[iC] << std::endl;
0171 }
0172 std::cout.flags(original_flags);
0173 };
0174
0175
0176 friend std::fstream & operator<<(std::fstream &strm, KFPVEfficiencies &a) {
0177
0178 strm << a.ratio_reco;
0179 strm << a.mc;
0180 strm << a.reco;
0181 strm << a.ratio_ghost;
0182 strm << a.ratio_bg;
0183 strm << a.ratio_clone;
0184 strm << a.ghost;
0185 strm << a.bg;
0186 strm << a.clone;
0187
0188 return strm;
0189 }
0190
0191 friend std::fstream & operator>>(std::fstream &strm, KFPVEfficiencies &a){
0192
0193 strm >> a.ratio_reco;
0194 strm >> a.mc;
0195 strm >> a.reco;
0196 strm >> a.ratio_ghost;
0197 strm >> a.ratio_bg;
0198 strm >> a.ratio_clone;
0199 strm >> a.ghost;
0200 strm >> a.bg;
0201 strm >> a.clone;
0202
0203 return strm;
0204 }
0205
0206 void AddFromFile(TString fileName)
0207 {
0208 std::fstream file(fileName.Data(),std::fstream::in);
0209 file >> *this;
0210 }
0211
0212 private:
0213 std::vector<TString> names;
0214 std::map<TString, int> indices;
0215
0216 KFMCCounter<double> ratio_reco;
0217
0218 KFMCCounter<int> mc;
0219 KFMCCounter<int> reco;
0220
0221 KFMCCounter<double> ratio_ghost;
0222 KFMCCounter<double> ratio_bg;
0223 KFMCCounter<double> ratio_clone;
0224
0225 KFMCCounter<int> ghost;
0226 KFMCCounter<int> bg;
0227 KFMCCounter<int> clone;
0228 };
0229
0230 #endif