ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/AnaTools/src/CutFlow.cc
(Generate patch)

Comparing UserCode/OSUT3Analysis/AnaTools/src/CutFlow.cc (file contents):
Revision 1.2 by ahart, Mon Jul 23 09:28:55 2012 UTC vs.
Revision 1.7 by ahart, Wed Feb 6 00:24:27 2013 UTC

# Line 1 | Line 1
1   #include "OSUT3Analysis/AnaTools/interface/CutFlow.h"
2  
3 < CutFlow::CutFlow (map<string, TH1D *> &hists1D, const edm::Service<TFileService> &fs, const string &prefix)
3 > CutFlow::CutFlow (const edm::Service<TFileService> &fs, const string &prefix)
4   {
5    sw_.Start ();
6    string cutFlowName = "cutFlow",
7           selectionName = "selection",
8 <         complementarySelectionName = "complementarySelection";
8 >         minusOneName = "minusOne";
9  
10    prefix_ = prefix;
11    if (prefix_ != "")
12      {
13        cutFlowName = prefix_ + "CutFlow";
14        selectionName = prefix_ + "Selection";
15 <      complementarySelectionName = prefix_ + "ComplementarySelection";
15 >      minusOneName = prefix_ + "MinusOne";
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];
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 ()
# Line 46 | Line 42 | CutFlow::operator[] (const string &cutNa
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 <      complementarySelection_->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 <      complementarySelection_->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 ()
67 > CutFlow::fillCutFlow (double w)
68   {
69    bool fillCumulative = true, fillComplement = true;
70    double complement = -1.0;
71  
72 <  cutFlow_->Fill (0.5);
73 <  selection_->Fill (0.5);
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);
81 >          selection_->Fill (binCenter, w);
82            if (fillCumulative)
83 <            cutFlow_->Fill (binCenter);
83 >            cutFlow_->Fill (binCenter, w);
84          }
85        else
86          {
87            fillCumulative = false;
88            if (complement < 0.0)
89 <            complement = complementarySelection_->GetBinCenter (cut - cutNames_.begin () + 2);
89 >            complement = minusOne_->GetBinCenter (cut - cutNames_.begin () + 2);
90            else
91              fillComplement = false;
92          }
93      }
94    if (fillCumulative)
95      {
88      complementarySelection_->Fill (0.5);
96        for (vector<string>::const_iterator cut = cutNames_.begin (); cut != cutNames_.end (); cut++)
97          {
98 <          double binCenter = complementarySelection_->GetBinCenter (cut - cutNames_.begin () + 2);
98 >          double binCenter = minusOne_->GetBinCenter (cut - cutNames_.begin () + 2);
99  
100 <          complementarySelection_->Fill (binCenter);
100 >          minusOne_->Fill (binCenter, w);
101          }
102      }
103    if (!fillCumulative && fillComplement)
104 <    complementarySelection_->Fill (complement);
104 >    minusOne_->Fill (complement, w);
105   }
106  
107   void
# Line 148 | Line 155 | CutFlow::outputTime ()
155   void
156   CutFlow::outputCutFlow ()
157   {
158 <  int totalEvents, totalEventsComplement;
158 >  int totalEvents;
159    string title = prefix_;
160  
161    clog << endl;
# Line 162 | Line 169 | CutFlow::outputCutFlow ()
169        clog << title << endl;
170      }
171  
172 <  clog << setw (75) << setfill ('-') << '-' << setfill (' ') << endl;
173 <  clog << setw (25) << left << "Cut Name" << right << setw (25) << "Cut Flow" << setw (25) << "Efficiency" << endl;
174 <  clog << setw (75) << setfill ('-') << '-' << setfill (' ') << endl;
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 (25) << left << "Total:" << right << setw (25) << totalEvents << setw (25) << "100%" << endl;
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 <
181 <      clog << setw (25) << left << (*cut + ":") << right << setw (25) << cutFlow << setw (24) << 100.0 * (cutFlow / (double) totalEvents) << "%" << endl;
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 (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;
187 >  clog << setw (80) << setfill ('-') << '-' << setfill (' ') << endl;
188   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines