ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/src/CutFlow.cc
Revision: 1.6
Committed: Fri Feb 1 01:05:13 2013 UTC (12 years, 3 months ago) by ahart
Content type: text/plain
Branch: MAIN
Changes since 1.5: +14 -14 lines
Log Message:
Rename the rejection cut flow to something more intuitive and correct: "minus one". This cut flow contains the numbers of events that would result if the cut in question were removed.

File Contents

# User Rev Content
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.6 minusOneName = "minusOne";
9 ahart 1.1
10     prefix_ = prefix;
11     if (prefix_ != "")
12     {
13     cutFlowName = prefix_ + "CutFlow";
14     selectionName = prefix_ + "Selection";
15 ahart 1.6 minusOneName = prefix_ + "MinusOne";
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 ahart 1.6 minusOne_ = fs->make<TH1D> (minusOneName.c_str (), "", 1, 0.0, 1.0);
22 ahart 1.3
23     cutFlow_->GetXaxis ()->SetBinLabel (1, "Total");
24     selection_->GetXaxis ()->SetBinLabel (1, "Total");
25 ahart 1.6 minusOne_->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.6 minusOne_->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.6 minusOne_->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 ahart 1.5 CutFlow::fillCutFlow (double w)
68 ahart 1.1 {
69     bool fillCumulative = true, fillComplement = true;
70     double complement = -1.0;
71    
72 ahart 1.5 cutFlow_->Fill (0.5, w);
73     selection_->Fill (0.5, w);
74 ahart 1.1 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 ahart 1.5 selection_->Fill (binCenter, w);
81 ahart 1.1 if (fillCumulative)
82 ahart 1.5 cutFlow_->Fill (binCenter, w);
83 ahart 1.1 }
84     else
85     {
86     fillCumulative = false;
87     if (complement < 0.0)
88 ahart 1.6 complement = minusOne_->GetBinCenter (cut - cutNames_.begin () + 2);
89 ahart 1.1 else
90     fillComplement = false;
91     }
92     }
93     if (fillCumulative)
94     {
95 ahart 1.6 minusOne_->Fill (0.5, w);
96 ahart 1.1 for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
97     {
98 ahart 1.6 double binCenter = minusOne_->GetBinCenter (cut - cutNames_.begin () + 2);
99 ahart 1.1
100 ahart 1.6 minusOne_->Fill (binCenter, w);
101 ahart 1.1 }
102     }
103     if (!fillCumulative && fillComplement)
104 ahart 1.6 minusOne_->Fill (complement, w);
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 ahart 1.6 clog << setw (15) << left << "Cut Name" << right << setw (16) << "Events" << setw (16) << "Cumulative Eff." << setw (16) << "Individual Eff." << setw (16) << "Minus One" << endl;
174 ahart 1.3 clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
175 ahart 1.1 totalEvents = cutFlow_->GetBinContent (1);
176 ahart 1.4 clog << setw (15) << left << "Total:" << right << setw (16) << totalEvents << setw (16) << "100%" << setw (16) << "100%" << setw (16) << "0%" << 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 ahart 1.6 minusOne = minusOne_->GetBinContent (cut - cutNames_.begin () + 2);
182 ahart 1.3
183 ahart 1.4 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 ahart 1.6 << setw (15) << 100.0 * (minusOne / (double) totalEvents) << "%" << endl;
186 ahart 1.1 }
187 ahart 1.3 clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
188 ahart 1.1 }