1 |
ahart |
1.1 |
#include "OSUT3Analysis/AnaTools/interface/CutFlow.h"
|
2 |
|
|
|
3 |
ahart |
1.3 |
CutFlow::CutFlow (const edm::Service<TFileService> &fs, const string &prefix)
|
4 |
ahart |
1.1 |
{
|
5 |
|
|
sw_.Start ();
|
6 |
|
|
string cutFlowName = "cutFlow",
|
7 |
|
|
selectionName = "selection",
|
8 |
ahart |
1.3 |
rejectionName = "rejection";
|
9 |
ahart |
1.1 |
|
10 |
|
|
prefix_ = prefix;
|
11 |
|
|
if (prefix_ != "")
|
12 |
|
|
{
|
13 |
|
|
cutFlowName = prefix_ + "CutFlow";
|
14 |
|
|
selectionName = prefix_ + "Selection";
|
15 |
ahart |
1.3 |
rejectionName = prefix_ + "Rejection";
|
16 |
ahart |
1.1 |
}
|
17 |
|
|
|
18 |
|
|
TH1::SetDefaultSumw2 ();
|
19 |
ahart |
1.3 |
cutFlow_ = fs->make<TH1D> (cutFlowName.c_str (), "", 1, 0.0, 1.0);
|
20 |
|
|
selection_ = fs->make<TH1D> (selectionName.c_str (), "", 1, 0.0, 1.0);
|
21 |
|
|
rejection_ = fs->make<TH1D> (rejectionName.c_str (), "", 1, 0.0, 1.0);
|
22 |
|
|
|
23 |
|
|
cutFlow_->GetXaxis ()->SetBinLabel (1, "Total");
|
24 |
|
|
selection_->GetXaxis ()->SetBinLabel (1, "Total");
|
25 |
|
|
rejection_->GetXaxis ()->SetBinLabel (1, "Total");
|
26 |
ahart |
1.1 |
}
|
27 |
|
|
|
28 |
|
|
CutFlow::~CutFlow ()
|
29 |
|
|
{
|
30 |
|
|
sw_.Stop ();
|
31 |
|
|
outputTime ();
|
32 |
|
|
outputCutFlow ();
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
bool &
|
36 |
|
|
CutFlow::operator[] (const string &cutName)
|
37 |
|
|
{
|
38 |
|
|
if (!cuts_.count (cutName))
|
39 |
|
|
{
|
40 |
|
|
cutNames_.push_back (cutName);
|
41 |
|
|
cuts_[cutName] = false;
|
42 |
|
|
|
43 |
|
|
cutFlow_->SetBins (cutNames_.size () + 1, 0.0, cutNames_.size () + 1.0);
|
44 |
|
|
selection_->SetBins (cutNames_.size () + 1, 0.0, cutNames_.size () + 1.0);
|
45 |
ahart |
1.3 |
rejection_->SetBins (cutNames_.size () + 1, 0.0, cutNames_.size () + 1.0);
|
46 |
ahart |
1.1 |
|
47 |
|
|
cutFlow_->GetXaxis ()->SetBinLabel (cutNames_.size () + 1, cutName.c_str ());
|
48 |
|
|
selection_->GetXaxis ()->SetBinLabel (cutNames_.size () + 1, cutName.c_str ());
|
49 |
ahart |
1.3 |
rejection_->GetXaxis ()->SetBinLabel (cutNames_.size () + 1, cutName.c_str ());
|
50 |
ahart |
1.1 |
}
|
51 |
|
|
|
52 |
|
|
return cuts_[cutName];
|
53 |
|
|
}
|
54 |
|
|
|
55 |
ahart |
1.3 |
bool
|
56 |
|
|
CutFlow::pass () const
|
57 |
|
|
{
|
58 |
|
|
for (map<string, bool>::const_iterator cut = cuts_.begin (); cut != cuts_.end (); cut++)
|
59 |
|
|
{
|
60 |
|
|
if (!cut->second)
|
61 |
|
|
return false;
|
62 |
|
|
}
|
63 |
|
|
return true;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
ahart |
1.1 |
void
|
67 |
|
|
CutFlow::fillCutFlow ()
|
68 |
|
|
{
|
69 |
|
|
bool fillCumulative = true, fillComplement = true;
|
70 |
|
|
double complement = -1.0;
|
71 |
|
|
|
72 |
|
|
cutFlow_->Fill (0.5);
|
73 |
|
|
selection_->Fill (0.5);
|
74 |
|
|
for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
|
75 |
|
|
{
|
76 |
|
|
if (cuts_[*cut])
|
77 |
|
|
{
|
78 |
|
|
double binCenter = selection_->GetBinCenter (cut - cutNames_.begin () + 2);
|
79 |
|
|
|
80 |
|
|
selection_->Fill (binCenter);
|
81 |
|
|
if (fillCumulative)
|
82 |
|
|
cutFlow_->Fill (binCenter);
|
83 |
|
|
}
|
84 |
|
|
else
|
85 |
|
|
{
|
86 |
|
|
fillCumulative = false;
|
87 |
|
|
if (complement < 0.0)
|
88 |
ahart |
1.3 |
complement = rejection_->GetBinCenter (cut - cutNames_.begin () + 2);
|
89 |
ahart |
1.1 |
else
|
90 |
|
|
fillComplement = false;
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
if (fillCumulative)
|
94 |
|
|
{
|
95 |
ahart |
1.3 |
rejection_->Fill (0.5);
|
96 |
ahart |
1.1 |
for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
|
97 |
|
|
{
|
98 |
ahart |
1.3 |
double binCenter = rejection_->GetBinCenter (cut - cutNames_.begin () + 2);
|
99 |
ahart |
1.1 |
|
100 |
ahart |
1.3 |
rejection_->Fill (binCenter);
|
101 |
ahart |
1.1 |
}
|
102 |
|
|
}
|
103 |
|
|
if (!fillCumulative && fillComplement)
|
104 |
ahart |
1.3 |
rejection_->Fill (complement);
|
105 |
ahart |
1.1 |
}
|
106 |
|
|
|
107 |
|
|
void
|
108 |
|
|
CutFlow::outputTime ()
|
109 |
|
|
{
|
110 |
|
|
double cpu, real;
|
111 |
|
|
int days, hours, minutes;
|
112 |
|
|
|
113 |
|
|
cpu = sw_.CpuTime ();
|
114 |
|
|
real = sw_.RealTime ();
|
115 |
|
|
|
116 |
|
|
days = (int) (cpu / (60.0 * 60.0 * 24.0));
|
117 |
|
|
cpu -= days * (60.0 * 60.0 * 24.0);
|
118 |
|
|
hours = (int) (cpu / (60.0 * 60.0));
|
119 |
|
|
cpu -= hours * (60.0 * 60.0);
|
120 |
|
|
minutes = (int) (cpu / 60.0);
|
121 |
|
|
cpu -= minutes * 60.0;
|
122 |
|
|
|
123 |
ahart |
1.2 |
clog << endl;
|
124 |
|
|
clog << "=============================================" << endl;
|
125 |
|
|
clog << endl;
|
126 |
ahart |
1.1 |
|
127 |
ahart |
1.2 |
clog << "CPU Time: ";
|
128 |
ahart |
1.1 |
if (days)
|
129 |
ahart |
1.2 |
clog << days << " days, ";
|
130 |
ahart |
1.1 |
if (days || hours)
|
131 |
ahart |
1.2 |
clog << hours << " hours, ";
|
132 |
ahart |
1.1 |
if (days || hours || minutes)
|
133 |
ahart |
1.2 |
clog << minutes << " minutes, ";
|
134 |
ahart |
1.1 |
if (days || hours || minutes || cpu)
|
135 |
ahart |
1.2 |
clog << cpu << " seconds" << endl;
|
136 |
ahart |
1.1 |
|
137 |
|
|
days = (int) (real / (60.0 * 60.0 * 24.0));
|
138 |
|
|
real -= days * (60.0 * 60.0 * 24.0);
|
139 |
|
|
hours = (int) (real / (60.0 * 60.0));
|
140 |
|
|
real -= hours * (60.0 * 60.0);
|
141 |
|
|
minutes = (int) (real / 60.0);
|
142 |
|
|
real -= minutes * 60.0;
|
143 |
|
|
|
144 |
ahart |
1.2 |
clog << "Real Time: ";
|
145 |
ahart |
1.1 |
if (days)
|
146 |
ahart |
1.2 |
clog << days << " days, ";
|
147 |
ahart |
1.1 |
if (days || hours)
|
148 |
ahart |
1.2 |
clog << hours << " hours, ";
|
149 |
ahart |
1.1 |
if (days || hours || minutes)
|
150 |
ahart |
1.2 |
clog << minutes << " minutes, ";
|
151 |
ahart |
1.1 |
if (days || hours || minutes || cpu)
|
152 |
ahart |
1.2 |
clog << real << " seconds" << endl;
|
153 |
ahart |
1.1 |
}
|
154 |
|
|
|
155 |
|
|
void
|
156 |
|
|
CutFlow::outputCutFlow ()
|
157 |
|
|
{
|
158 |
ahart |
1.3 |
int totalEvents;
|
159 |
ahart |
1.1 |
string title = prefix_;
|
160 |
|
|
|
161 |
ahart |
1.2 |
clog << endl;
|
162 |
|
|
clog << "=============================================" << endl;
|
163 |
|
|
clog << endl;
|
164 |
ahart |
1.1 |
|
165 |
|
|
if (prefix_ != "")
|
166 |
|
|
{
|
167 |
|
|
title[0] = toupper (title[0]);
|
168 |
|
|
title += " Cuts";
|
169 |
ahart |
1.2 |
clog << title << endl;
|
170 |
ahart |
1.1 |
}
|
171 |
|
|
|
172 |
ahart |
1.3 |
clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
|
173 |
|
|
clog << setw (16) << left << "Cut Name" << right << setw (16) << "Cut Flow" << setw (16) << "Efficiency" << setw (16) << "Selection" << setw (16) << "Rejection" << endl;
|
174 |
|
|
clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
|
175 |
ahart |
1.1 |
totalEvents = cutFlow_->GetBinContent (1);
|
176 |
ahart |
1.2 |
clog << setw (25) << left << "Total:" << right << setw (25) << totalEvents << setw (25) << "100%" << endl;
|
177 |
ahart |
1.1 |
for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
|
178 |
|
|
{
|
179 |
ahart |
1.3 |
double cutFlow = cutFlow_->GetBinContent (cut - cutNames_.begin () + 2),
|
180 |
|
|
selection = selection_->GetBinContent (cut - cutNames_.begin () + 2),
|
181 |
|
|
rejection = rejection_->GetBinContent (cut - cutNames_.begin () + 2);
|
182 |
|
|
|
183 |
|
|
clog << setw (16) << left << (*cut + ":") << right << setw (16) << cutFlow << setw (16) << 100.0 * (cutFlow / (double) totalEvents) << "%"
|
184 |
|
|
<< setw (16) << 100.0 * (selection / (double) totalEvents) << "%"
|
185 |
|
|
<< setw (16) << 100.0 * (rejection / (double) totalEvents) << "%" << endl;
|
186 |
ahart |
1.1 |
}
|
187 |
ahart |
1.3 |
clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
|
188 |
ahart |
1.2 |
clog << endl;
|
189 |
ahart |
1.1 |
}
|