1 |
|
2 |
#include "RA2/Selection/interface/Selection.h"
|
3 |
#include <iostream>
|
4 |
#include <iomanip>
|
5 |
|
6 |
Selection::Selection(const edm::ParameterSet& iConfig) :
|
7 |
sequence_( iConfig.getParameter<edm::ParameterSet>("selections") ),
|
8 |
filterSelection_( iConfig.getParameter<std::vector<std::string> >("filterSelection") ),
|
9 |
weightName_(iConfig.getParameter<edm::InputTag>("weightName") ),
|
10 |
Nevents(0)
|
11 |
{
|
12 |
// Translate filterSelection strings into selector indices
|
13 |
//filterSelectionIndices_.reserve(filterSelection_.size());
|
14 |
for ( size_t i=0; i<filterSelection_.size(); ++i ) {
|
15 |
filterSelectionIndices_.push_back(sequence_.selectorIndex(filterSelection_[i]));
|
16 |
SelectionStats_.push_back( Selection::TStatistics() );
|
17 |
}
|
18 |
|
19 |
// List all selectors and selection variables
|
20 |
edm::LogVerbatim("Selection") << "Selectors are:" << std::endl;
|
21 |
for ( std::vector<const SusyEventSelector*>::const_iterator it = sequence_.selectors().begin();
|
22 |
it != sequence_.selectors().end(); ++it )
|
23 |
{
|
24 |
edm::LogVerbatim("Selection") << " * " << (*it)->name()
|
25 |
<< " selects on following "
|
26 |
<< (*it)->numberOfVariables() << " variable(s):";
|
27 |
for ( unsigned int i=0; i<(*it)->numberOfVariables(); ++i )
|
28 |
edm::LogVerbatim("Selection") << " - " << (*it)->variableNames()[i];
|
29 |
edm::LogVerbatim("Selection") << std::endl;
|
30 |
}
|
31 |
|
32 |
|
33 |
}
|
34 |
|
35 |
|
36 |
//________________________________________________________________________________________
|
37 |
Selection::~Selection() { }
|
38 |
|
39 |
|
40 |
// ------------ method called on each new Event ------------
|
41 |
bool
|
42 |
Selection::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
|
43 |
{
|
44 |
// Retrieve the decision of each selector module
|
45 |
SelectorDecisions decisions = sequence_.decisions(iEvent);
|
46 |
|
47 |
edm::Handle< double > event_weight;
|
48 |
iEvent.getByLabel(weightName_, event_weight);
|
49 |
weight_ = (event_weight.isValid() ? (*event_weight) : 1.0);
|
50 |
++Nevents;
|
51 |
|
52 |
bool dec(true);
|
53 |
for ( size_t i=0; i<filterSelectionIndices_.size(); ++i ){ // only "filter selection"
|
54 |
//Filter decision
|
55 |
dec = dec && decisions.decision(filterSelectionIndices_[i]);
|
56 |
|
57 |
//Statistics
|
58 |
SelectionStats_[i].NTotal += weight_;
|
59 |
if (decisions.decision(i)) SelectionStats_[i].NSelected += weight_;
|
60 |
if (decisions.cumulativeDecision(i)) SelectionStats_[i].NCumulative += weight_;
|
61 |
if (decisions.complementaryDecision(i)){
|
62 |
SelectionStats_[i].Nminus1total += weight_;
|
63 |
if (decisions.decision(i)) SelectionStats_[i].Nminus1 += weight_;
|
64 |
}
|
65 |
}
|
66 |
|
67 |
// Cutflow-Analysis
|
68 |
/*
|
69 |
std::ostringstream dbg;
|
70 |
dbg << "selector decisions " << std::endl
|
71 |
<< " name, 2xdecision, 2xcompl. decision, 2xcumul. decision" << std::endl;
|
72 |
for ( size_t i=0; i<filterSelectionIndices_.size(); ++i ) {
|
73 |
std::string name = sequence_.selectorName(i);
|
74 |
size_t idxFromName = sequence_.selectorIndex(name);
|
75 |
dbg << " " << name
|
76 |
<< " " << decisions.decision(i)
|
77 |
<< " " << decisions.decision(idxFromName)
|
78 |
<< " " << decisions.complementaryDecision(i)
|
79 |
<< " " << decisions.complementaryDecision(idxFromName)
|
80 |
<< " " << decisions.cumulativeDecision(i)
|
81 |
<< " " << decisions.cumulativeDecision(idxFromName)
|
82 |
<< std::endl;
|
83 |
}
|
84 |
dbg << " global decision = ("<<dec<<") " << decisions.globalDecision();
|
85 |
std::cout << dbg.str() <<std::endl;
|
86 |
|
87 |
std::ostringstream dbg1;
|
88 |
std::vector<double> vars = sequence_.values();
|
89 |
dbg1 << "All variable values" << std::endl;
|
90 |
for ( size_t i=0; i<sequence_.variableNames().size(); ++i ) {
|
91 |
dbg1 << sequence_.variableNames()[i] << " " << vars[i] << std::endl;
|
92 |
}
|
93 |
*/
|
94 |
return dec;
|
95 |
|
96 |
}
|
97 |
|
98 |
//________________________________________________________________________________________
|
99 |
// Called once per job, at start
|
100 |
void
|
101 |
Selection::beginJob(const edm::EventSetup&) {}
|
102 |
|
103 |
//________________________________________________________________________________________
|
104 |
// Called once per job, at end
|
105 |
|
106 |
void
|
107 |
Selection::endJob()
|
108 |
{
|
109 |
std::ostringstream dbg;
|
110 |
dbg << "\nStatistical CutFlow Analysis\n"
|
111 |
<< "----------------------------\n";
|
112 |
if (SelectionStats_.size()>0) {
|
113 |
dbg << "Total events = " << SelectionStats_[0].NTotal
|
114 |
<< ", average weight = " << SelectionStats_[0].NTotal/Nevents<<"\n";
|
115 |
}
|
116 |
dbg << " variable cut (eff) n-1 (eff) cumulative (eff)";
|
117 |
for ( size_t i=0; i<filterSelectionIndices_.size(); ++i )
|
118 |
dbg << "\n"
|
119 |
<< std::setw(20) << sequence_.selectorName(i)
|
120 |
<< " " <<std::setw(10)<< SelectionStats_[i].NSelected << " (" << std::setw(10) << SelectionStats_[i].Eff()<<")"
|
121 |
<< " " <<std::setw(10)<< SelectionStats_[i].Nminus1total << " (" <<std::setw(10) << SelectionStats_[i].EffNminus1()<<")"
|
122 |
<< " " <<std::setw(10)<< SelectionStats_[i].NCumulative << " (" <<std::setw(10) << SelectionStats_[i].EffCumulative()<<")";
|
123 |
//edm::LogVerbatim("Selection") << dbg.str() << std::endl;
|
124 |
std::cout << dbg.str() << std::endl;
|
125 |
}
|
126 |
|
127 |
|
128 |
//define this as a plug-in
|
129 |
DEFINE_FWK_MODULE(Selection);
|