ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/interface/CutsAndHistos.h
Revision: 1.3
Committed: Tue Jun 5 09:10:01 2012 UTC (12 years, 11 months ago) by bortigno
Content type: text/plain
Branch: MAIN
CVS Tags: lhcp_UnblindFix, hcp_Unblind, lhcp_11April, LHCP_PreAppFixAfterFreeze, LHCP_PreAppFreeze, workingVersionAfterHCP, hcpApproval, hcpPreApp, ICHEP8TeV, ichep8TeV, HEAD
Changes since 1.2: +1 -1 lines
Log Message:
8TeV

File Contents

# User Rev Content
1 bortigno 1.1 #ifndef CUTSANDHISTOS_H
2     #define CUTSANDHISTOS_H
3     #include <string>
4     #include <sstream>
5     #include <vector>
6     #include <TROOT.h>
7     #include <TFile.h>
8 bortigno 1.2 #include "ntupleReader.hpp"
9     #include "samples.hpp"
10 bortigno 1.1
11     enum VType{ Zmm, Zee, Wmn, Wen, Znn } iType;
12    
13     class Histos {
14     public:
15     virtual void book(TFile &f, std::string suffix) = 0;
16     virtual void fill( ntupleReader &event, float w) = 0;
17     // virtual Histos * clone() =0;
18     };
19    
20     class Cut {
21     public:
22     virtual bool pass( ntupleReader &event ) = 0;
23     virtual std::string name() = 0;
24     virtual bool operator()(ntupleReader &event) {return pass(event); }
25     };
26    
27     class CutSample : public Cut {
28     public:
29     virtual bool pass( ntupleReader &event ) = 0;
30     virtual bool pass( ntupleReader &event, Sample &sample ) = 0;
31     virtual double weight( ntupleReader &event, Sample &sample ) = 0;
32     virtual std::string name() = 0;
33     virtual bool operator()(ntupleReader &event) {return pass(event); }
34     };
35    
36     class NoCut : public Cut {
37     public:
38     virtual bool pass( ntupleReader &event ) { return true;}
39     virtual std::string name() {return "NoCut"; }
40     };
41    
42     /// One parameter cut class
43     class PCut : public Cut
44     {
45     public:
46     PCut(){}
47     PCut(float cut) : m_cut(cut) {}
48     PCut(float minCut, float maxCut) : m_cut(minCut), M_cut(maxCut) {}
49     void setCut(float cut) {m_cut=cut;}
50     void setCut(float minCut, float maxCut) {m_cut=minCut; M_cut=maxCut;}
51     std::string cutValueString()
52     {
53     std::stringstream s;
54     s << m_cut;
55     return s.str();
56     }
57     float m_cut;
58     float M_cut;
59     };
60    
61     class CutSet : public Cut {
62     public:
63     void add(Cut *c) {cuts.push_back(c);}
64     void drop(Cut *c) { pastes.push_back(c);}
65     int size(){ return cuts.size(); }
66     bool pass(ntupleReader &event) {
67     bool result=true;
68     for(size_t i=0; i< cuts.size() ; i++)
69     if( ! (cuts.at(i)->pass(event)) )
70     result=false;
71     for(size_t i=0; i< pastes.size() ; i++)
72     if( (pastes.at(i)->pass(event)) )
73     result=true;
74     return result;
75     }
76     std::string name() {
77     std::stringstream s;
78     for(size_t i=0; i< cuts.size() ; i++) {
79     s << "_" << cuts.at(i)->name();
80     }
81     return s.str();
82     }
83    
84     private:
85     std::vector<Cut *> cuts;
86     std::vector<Cut *> pastes;
87    
88     };
89    
90    
91     ///CutSet of PCut, with scanning functions
92     // to be implemented still
93     class PCutSet : public Cut {
94     public:
95     void add(PCut *c) {cuts.push_back(c);}
96     void drop(PCut *c) { pastes.push_back(c);}
97     int size(){ return cuts.size(); }
98     bool pass(ntupleReader &event) {
99     bool result=true;
100     for(size_t i=0; i< cuts.size(); i++)
101     if( ! (cuts.at(i)->pass(event)) )
102     result=false;
103     for(size_t i=0; i< pastes.size() ; i++)
104     if( (pastes.at(i)->pass(event)) )
105     result=true;
106     return result;
107     }
108     bool pass(ntupleReader &event, int n) {
109     bool result=true;
110     for(size_t i=0; i< n; i++){
111     if( ! (cuts.at(i)->pass(event)) )
112     result=false;
113     for(size_t i=0; i< pastes.size() ; i++)
114     if( (pastes.at(i)->pass(event)) )
115     result=true;
116     }
117     return result;
118     }
119     std::string name() {
120     std::stringstream s;
121     for(size_t i=0; i< cuts.size(); i++) {
122     s << "_" << cuts.at(i)->name();
123     }
124     return s.str();
125     }
126     PCut * getCut( int i ) { return cuts.at(i); }
127    
128     private:
129     std::vector<PCut *> cuts;
130     std::vector<PCut *> pastes;
131    
132     };
133    
134    
135    
136     class CutsAndHistos {
137     public:
138     CutsAndHistos() {}
139     CutsAndHistos(CutSample * c, std::vector<Histos *> & h):
140     cutS(c),
141     histos(h) {
142     suffix=cutS->name(); }
143     CutsAndHistos(CutSample * c, Histos * h):
144     cutS(c) {
145     histos.push_back(h);
146     suffix=cutS->name(); }
147     CutsAndHistos(Cut * c, std::vector<Histos *> & h):
148     cut(c),
149     histos(h) {
150     suffix=cut->name(); }
151     CutsAndHistos(Cut * c, Histos * h):
152     cut(c) {
153     histos.push_back(h);
154     suffix=cut->name();
155     }
156    
157     //TODO: implement destructor for all pointers received
158    
159     void book(TFile &f) {
160     for(size_t i=0; i< histos.size(); i++)
161     histos.at(i)->book(f,suffix);
162     }
163    
164     void process(ntupleReader &event, float w)
165     {
166     if(cutS->pass(event))
167     for(size_t i=0; i< histos.size(); i++)
168     histos.at(i)->fill(event,w);
169     }
170    
171     void process(ntupleReader &event, float w, Sample &s)
172     {
173     if(cutS->pass(event,s))
174     for(size_t i=0; i< histos.size(); i++)
175 bortigno 1.3 histos.at(i)->fill(event, (w * cutS->weight(event,s)) );
176 bortigno 1.1 }
177    
178     Cut * cut;
179     CutSample * cutS;
180     std::vector<Histos *> histos;
181    
182     private:
183     std::string suffix;
184     };
185    
186     #endif
187