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 |
/// One parameter cut class
|
27 |
class PCut : public Cut
|
28 |
{
|
29 |
public:
|
30 |
PCut(float cut) : m_cut(cut) {}
|
31 |
void setCut(float cut) {m_cut=cut;}
|
32 |
|
33 |
std::string cutValueString()
|
34 |
{
|
35 |
std::stringstream s;
|
36 |
s << m_cut;
|
37 |
return s.str();
|
38 |
}
|
39 |
|
40 |
private:
|
41 |
float m_cut;
|
42 |
|
43 |
};
|
44 |
|
45 |
class CutSet : public Cut {
|
46 |
public:
|
47 |
void add(Cut *c) {cuts.push_back(c);}
|
48 |
bool pass(VHbbProxy &iProxy) {
|
49 |
bool result=true;
|
50 |
for(size_t i=0; i< cuts.size(); i++)
|
51 |
if( ! (cuts.at(i)->pass(iProxy)) )
|
52 |
result=false;
|
53 |
return result;
|
54 |
}
|
55 |
std::string name() {
|
56 |
std::stringstream s;
|
57 |
for(size_t i=0; i< cuts.size(); i++) {
|
58 |
s << "_" << cuts.at(i)->name();
|
59 |
}
|
60 |
return s.str();
|
61 |
}
|
62 |
|
63 |
private:
|
64 |
std::vector<Cut *> cuts;
|
65 |
|
66 |
};
|
67 |
|
68 |
|
69 |
///CutSet of PCut, with scanning functions
|
70 |
class PCutSet : public Cut {
|
71 |
public:
|
72 |
void add(PCut *c) {cuts.push_back(c);}
|
73 |
bool pass(VHbbProxy &iProxy) {
|
74 |
bool result=true;
|
75 |
for(size_t i=0; i< cuts.size(); i++)
|
76 |
if( ! (cuts.at(i)->pass(iProxy)) )
|
77 |
result=false;
|
78 |
return result;
|
79 |
}
|
80 |
std::string name() {
|
81 |
std::stringstream s;
|
82 |
for(size_t i=0; i< cuts.size(); i++) {
|
83 |
s << "_" << cuts.at(i)->name();
|
84 |
}
|
85 |
return s.str();
|
86 |
}
|
87 |
|
88 |
private:
|
89 |
std::vector<PCut *> cuts;
|
90 |
|
91 |
};
|
92 |
|
93 |
|
94 |
|
95 |
class CutsAndHistos {
|
96 |
public:
|
97 |
CutsAndHistos() {}
|
98 |
CutsAndHistos(Cut * c, std::vector<Histos *> & h):
|
99 |
cut(c),
|
100 |
histos(h) {}
|
101 |
CutsAndHistos(Cut * c, Histos * h):
|
102 |
cut(c) {
|
103 |
histos.push_back(h);
|
104 |
}
|
105 |
//TODO: implement destructor for all pointers received
|
106 |
|
107 |
void book(TFile &f) {
|
108 |
std::string suffix=cut->name();
|
109 |
for(size_t i=0; i< histos.size(); i++)
|
110 |
histos.at(i)->book(f,suffix);
|
111 |
}
|
112 |
|
113 |
void process(VHbbProxy & iProxy,float w)
|
114 |
{
|
115 |
if(cut->pass(iProxy))
|
116 |
for(size_t i=0; i< histos.size(); i++)
|
117 |
histos.at(i)->fill(iProxy,w);
|
118 |
}
|
119 |
|
120 |
|
121 |
Cut * cut;
|
122 |
std::vector<Histos *> histos;
|
123 |
|
124 |
};
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
#endif
|