NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
CutFlowCounter.h
Go to the documentation of this file.
1//***************************************************************************************
4//***************************************************************************************
5
6#pragma once
7
8#include "NAGASH/Result.h"
9
10namespace NAGASH
11{
55 class CutFlowCounter : public Result
56 {
57 private:
58 std::vector<double> SumE;
59 std::vector<double> SumW;
60 std::map<std::string, uint64_t> CutPointNames;
61 std::vector<std::string> CutPointNamesVector;
62
63 public:
69 CutFlowCounter(std::shared_ptr<MSGTool> msg, std::shared_ptr<ConfigTool> config, const TString &name, const TString &fname = "")
70 : Result(msg, config, name, fname) {}
71
74 void BookCutPoint(const std::string &name)
75 {
76 CutPointNames.emplace(std::pair<std::string, uint64_t>(name, SumE.size()));
77 SumE.emplace_back(0);
78 SumW.emplace_back(0);
79 CutPointNamesVector.emplace_back(name);
80 }
81
85 void Record(uint64_t point, double w = 1)
86 {
87 if (point < SumE.size())
88 {
89 SumE[point] += 1;
90 SumW[point] += w;
91 }
92 else
93 {
94 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Record");
95 MSGUser()->MSG_WARNING("Cut point ", point, " does not exist!");
96 }
97 }
98
102 void Record(const std::string &point, double w = 1)
103 {
104 if (auto result = CutPointNames.find(point); result != CutPointNames.end())
105 {
106 SumE[result->second] += 1;
107 SumW[result->second] += w;
108 }
109 else
110 {
111 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Record");
112 MSGUser()->MSG_WARNING("Cut point ", point, " does not exist!");
113 }
114 }
115
118 void Combine(std::shared_ptr<Result> result)
119 {
120 auto subCounter = std::dynamic_pointer_cast<std::remove_pointer<decltype(this)>::type>(result);
121 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Combine");
122 if (subCounter != nullptr)
123 {
124 if (CutPointNames != subCounter->CutPointNames)
125 {
126 MSGUser()->MSG_WARNING("Two cut flow counter are note the same (", GetResultName(), " and ", subCounter->GetResultName(), ")");
127 return;
128 }
129
130 for (size_t i = 0; i < SumE.size(); ++i)
131 {
132 SumE[i] += subCounter->SumE[i];
133 SumW[i] += subCounter->SumW[i];
134 }
135 }
136 }
137
140 double GetEntries(uint32_t point)
141 {
142 if (point < SumE.size())
143 {
144 return SumE[point];
145 }
146 else
147 {
148 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Record");
149 MSGUser()->MSG_WARNING("Cut point ", point, " does not exist!");
150 }
151 }
152
155 double GetEntries(const std::string &point)
156 {
157 if (auto result = CutPointNames.find(point); result != CutPointNames.end())
158 {
159 return SumE[result->second];
160 }
161 else
162 {
163 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Record");
164 MSGUser()->MSG_WARNING("Cut point ", point, " does not exist!");
165 }
166 }
167
170 double GetSumW(uint32_t point)
171 {
172 if (point < SumW.size())
173 {
174 return SumW[point];
175 }
176 else
177 {
178 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Record");
179 MSGUser()->MSG_WARNING("Cut point ", point, " does not exist!");
180 }
181 }
182
185 double GetSumW(const std::string &point)
186 {
187 if (auto result = CutPointNames.find(point); result != CutPointNames.end())
188 {
189 return SumW[result->second];
190 }
191 else
192 {
193 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::Record");
194 MSGUser()->MSG_WARNING("Cut point ", point, " does not exist!");
195 }
196 }
197
200 {
201 auto guard = MSGUser()->StartTitleWithGuard("CutFlowCounter::PrintSummary");
202 MSGUser()->MSG_INFO("Summary of cut flow counter ", GetResultName());
203 for (size_t i = 0; i < SumE.size(); ++i)
204 MSGUser()->MSG_INFO("Cut point ", CutPointNamesVector[i], " Entries : ", SumE[i], " SumW : ", SumW[i], " Eff : ", SumW[i] / SumW[0], " Relative Eff : ", i == 0 ? 1 : SumW[i] / SumW[i - 1]);
205 }
206 };
207
208}
Store the cut flow with user defined cuts.
void Record(uint64_t point, double w=1)
Record a entry that pass a cut.
double GetEntries(const std::string &point)
Get the total entries of a cut point.
void BookCutPoint(const std::string &name)
Book a cut point.
void Record(const std::string &point, double w=1)
Record a entry that pass a cut.
double GetEntries(uint32_t point)
Get the total entries of a cut point.
double GetSumW(uint32_t point)
Get the sum of weights of a cut point.
double GetSumW(const std::string &point)
Get the sum of weights of a cut point.
std::vector< double > SumW
std::vector< double > SumE
std::vector< std::string > CutPointNamesVector
void PrintSummary()
Print the summary of the cut flow.
CutFlowCounter(std::shared_ptr< MSGTool > msg, std::shared_ptr< ConfigTool > config, const TString &name, const TString &fname="")
Constructor.
void Combine(std::shared_ptr< Result > result)
Combine the cut flow with another cut flow.
std::map< std::string, uint64_t > CutPointNames
Provide virtual interface to manipulate all the results inside NAGASH.
Definition Result.h:68
std::shared_ptr< MSGTool > msg
Definition Result.h:99
const TString & GetResultName()
Definition Result.h:70
std::shared_ptr< MSGTool > MSGUser()
Return the internal MSGTool.
Definition Result.h:106
std::shared_ptr< ConfigTool > config
Definition Result.h:100