ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/src/CutFlow.cc
Revision: 1.2
Committed: Mon Jul 23 09:28:55 2012 UTC (12 years, 9 months ago) by ahart
Content type: text/plain
Branch: MAIN
CVS Tags: mytag_0_0_0, V00-00-03, V00-00-02
Changes since 1.1: +36 -36 lines
Log Message:
Change cout to clog.

File Contents

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