ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/interface/CutsAndHistos.h
Revision: 1.5
Committed: Mon Aug 22 12:15:03 2011 UTC (13 years, 8 months ago) by arizzi
Content type: text/plain
Branch: MAIN
Changes since 1.4: +5 -11 lines
Log Message:
start implementing signal selection as a stack of cuts

File Contents

# User Rev Content
1 tboccali 1.1 #ifndef CUTANDHISTOS_H
2     #define CUTANDHISTOS_H
3     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEvent.h"
4     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbProxy.h"
5     #include <string>
6     #include <sstream>
7     #include <vector>
8     #include <TROOT.h>
9     #include <TFile.h>
10    
11     class VHbbEvent;
12    
13     class Histos {
14     public:
15     virtual void book(TFile &f, std::string suffix) = 0;
16     virtual void fill(VHbbProxy &, float w) = 0;
17     };
18    
19     class Cut {
20     public:
21     virtual bool pass(VHbbProxy &) = 0;
22     virtual std::string name() = 0;
23     virtual bool operator()(VHbbProxy &iProxy) {return pass(iProxy); }
24     };
25    
26 arizzi 1.3 class NoCut : public Cut {
27     public:
28     virtual bool pass(VHbbProxy &) { return true;}
29     virtual std::string name() {return "NoCut"; }
30     };
31    
32 arizzi 1.2 /// One parameter cut class
33     class PCut : public Cut
34     {
35     public:
36     PCut(float cut) : m_cut(cut) {}
37     void setCut(float cut) {m_cut=cut;}
38    
39     std::string cutValueString()
40     {
41     std::stringstream s;
42     s << m_cut;
43     return s.str();
44     }
45    
46     private:
47     float m_cut;
48    
49     };
50    
51 tboccali 1.1 class CutSet : public Cut {
52     public:
53     void add(Cut *c) {cuts.push_back(c);}
54 arizzi 1.5 bool pass(VHbbProxy &iProxy, int limitCuts=99999) {
55 tboccali 1.1 bool result=true;
56 arizzi 1.5 for(size_t i=0; i< cuts.size() && i < limitCuts; i++)
57 tboccali 1.1 if( ! (cuts.at(i)->pass(iProxy)) )
58     result=false;
59     return result;
60     }
61 arizzi 1.5 std::string name(int limitCuts = 99999) {
62 tboccali 1.1 std::stringstream s;
63 arizzi 1.5 for(size_t i=0; i< cuts.size() && i < limitCuts; i++) {
64 tboccali 1.1 s << "_" << cuts.at(i)->name();
65     }
66     return s.str();
67     }
68    
69     private:
70     std::vector<Cut *> cuts;
71    
72     };
73    
74 arizzi 1.2
75     ///CutSet of PCut, with scanning functions
76 arizzi 1.5 // to be implemented still
77 arizzi 1.2 class PCutSet : public Cut {
78     public:
79     void add(PCut *c) {cuts.push_back(c);}
80     bool pass(VHbbProxy &iProxy) {
81     bool result=true;
82     for(size_t i=0; i< cuts.size(); i++)
83     if( ! (cuts.at(i)->pass(iProxy)) )
84     result=false;
85     return result;
86     }
87     std::string name() {
88     std::stringstream s;
89     for(size_t i=0; i< cuts.size(); i++) {
90     s << "_" << cuts.at(i)->name();
91     }
92     return s.str();
93     }
94    
95     private:
96     std::vector<PCut *> cuts;
97    
98     };
99    
100    
101    
102 tboccali 1.1 class CutsAndHistos {
103     public:
104     CutsAndHistos() {}
105 arizzi 1.2 CutsAndHistos(Cut * c, std::vector<Histos *> & h):
106     cut(c),
107 tboccali 1.1 histos(h) {}
108 arizzi 1.2 CutsAndHistos(Cut * c, Histos * h):
109     cut(c) {
110     histos.push_back(h);
111     }
112     //TODO: implement destructor for all pointers received
113 tboccali 1.1
114     void book(TFile &f) {
115 arizzi 1.2 std::string suffix=cut->name();
116 tboccali 1.1 for(size_t i=0; i< histos.size(); i++)
117     histos.at(i)->book(f,suffix);
118     }
119    
120     void process(VHbbProxy & iProxy,float w)
121     {
122 arizzi 1.2 if(cut->pass(iProxy))
123 tboccali 1.1 for(size_t i=0; i< histos.size(); i++)
124     histos.at(i)->fill(iProxy,w);
125     }
126    
127    
128 arizzi 1.2 Cut * cut;
129 tboccali 1.1 std::vector<Histos *> histos;
130    
131     };
132    
133    
134    
135    
136     #endif