ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/src/CutFlow.cc
Revision: 1.7
Committed: Wed Feb 6 00:24:27 2013 UTC (12 years, 3 months ago) by ahart
Content type: text/plain
Branch: MAIN
Changes since 1.6: +1 -1 lines
Log Message:
Fill the first bin of the minus-one histograms once per event.

File Contents

# Content
1 #include "OSUT3Analysis/AnaTools/interface/CutFlow.h"
2
3 CutFlow::CutFlow (const edm::Service<TFileService> &fs, const string &prefix)
4 {
5 sw_.Start ();
6 string cutFlowName = "cutFlow",
7 selectionName = "selection",
8 minusOneName = "minusOne";
9
10 prefix_ = prefix;
11 if (prefix_ != "")
12 {
13 cutFlowName = prefix_ + "CutFlow";
14 selectionName = prefix_ + "Selection";
15 minusOneName = prefix_ + "MinusOne";
16 }
17
18 TH1::SetDefaultSumw2 ();
19 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 minusOne_ = fs->make<TH1D> (minusOneName.c_str (), "", 1, 0.0, 1.0);
22
23 cutFlow_->GetXaxis ()->SetBinLabel (1, "Total");
24 selection_->GetXaxis ()->SetBinLabel (1, "Total");
25 minusOne_->GetXaxis ()->SetBinLabel (1, "Total");
26 }
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 minusOne_->SetBins (cutNames_.size () + 1, 0.0, cutNames_.size () + 1.0);
46
47 cutFlow_->GetXaxis ()->SetBinLabel (cutNames_.size () + 1, cutName.c_str ());
48 selection_->GetXaxis ()->SetBinLabel (cutNames_.size () + 1, cutName.c_str ());
49 minusOne_->GetXaxis ()->SetBinLabel (cutNames_.size () + 1, cutName.c_str ());
50 }
51
52 return cuts_[cutName];
53 }
54
55 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 void
67 CutFlow::fillCutFlow (double w)
68 {
69 bool fillCumulative = true, fillComplement = true;
70 double complement = -1.0;
71
72 cutFlow_->Fill (0.5, w);
73 selection_->Fill (0.5, w);
74 minusOne_->Fill (0.5, w);
75 for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
76 {
77 if (cuts_[*cut])
78 {
79 double binCenter = selection_->GetBinCenter (cut - cutNames_.begin () + 2);
80
81 selection_->Fill (binCenter, w);
82 if (fillCumulative)
83 cutFlow_->Fill (binCenter, w);
84 }
85 else
86 {
87 fillCumulative = false;
88 if (complement < 0.0)
89 complement = minusOne_->GetBinCenter (cut - cutNames_.begin () + 2);
90 else
91 fillComplement = false;
92 }
93 }
94 if (fillCumulative)
95 {
96 for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
97 {
98 double binCenter = minusOne_->GetBinCenter (cut - cutNames_.begin () + 2);
99
100 minusOne_->Fill (binCenter, w);
101 }
102 }
103 if (!fillCumulative && fillComplement)
104 minusOne_->Fill (complement, w);
105 }
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 clog << endl;
124 clog << "=============================================" << endl;
125 clog << endl;
126
127 clog << "CPU Time: ";
128 if (days)
129 clog << days << " days, ";
130 if (days || hours)
131 clog << hours << " hours, ";
132 if (days || hours || minutes)
133 clog << minutes << " minutes, ";
134 if (days || hours || minutes || cpu)
135 clog << cpu << " seconds" << endl;
136
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 clog << "Real Time: ";
145 if (days)
146 clog << days << " days, ";
147 if (days || hours)
148 clog << hours << " hours, ";
149 if (days || hours || minutes)
150 clog << minutes << " minutes, ";
151 if (days || hours || minutes || cpu)
152 clog << real << " seconds" << endl;
153 }
154
155 void
156 CutFlow::outputCutFlow ()
157 {
158 int totalEvents;
159 string title = prefix_;
160
161 clog << endl;
162 clog << "=============================================" << endl;
163 clog << endl;
164
165 if (prefix_ != "")
166 {
167 title[0] = toupper (title[0]);
168 title += " Cuts";
169 clog << title << endl;
170 }
171
172 clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
173 clog << setw (15) << left << "Cut Name" << right << setw (16) << "Events" << setw (16) << "Cumulative Eff." << setw (16) << "Individual Eff." << setw (16) << "Minus One" << endl;
174 clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
175 totalEvents = cutFlow_->GetBinContent (1);
176 clog << setw (15) << left << "Total:" << right << setw (16) << totalEvents << setw (16) << "100%" << setw (16) << "100%" << setw (16) << "0%" << endl;
177 for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
178 {
179 double cutFlow = cutFlow_->GetBinContent (cut - cutNames_.begin () + 2),
180 selection = selection_->GetBinContent (cut - cutNames_.begin () + 2),
181 minusOne = minusOne_->GetBinContent (cut - cutNames_.begin () + 2);
182
183 clog << setw (15) << left << (*cut + ":") << right << setw (16) << cutFlow << setw (15) << 100.0 * (cutFlow / (double) totalEvents) << "%"
184 << setw (15) << 100.0 * (selection / (double) totalEvents) << "%"
185 << setw (15) << 100.0 * (minusOne / (double) totalEvents) << "%" << endl;
186 }
187 clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
188 }