-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathWeightSumOperator.h
47 lines (32 loc) · 1020 Bytes
/
WeightSumOperator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "BaseOperator.h"
template <class EventClass> class WeightSumOperator : public BaseOperator<EventClass> {
public:
TH1D h_wsum {"h_wsum", "number of events", 1, 0., 1.};
std::vector<std::string> weights_;
double w_sum_ = 0.;
std::string dirname_;
WeightSumOperator(const std::vector<std::string> & weights = {}) :
weights_(weights) {}
virtual ~WeightSumOperator() {}
virtual void init(TDirectory * tdir) {
h_wsum.SetDirectory(tdir);
h_wsum.Sumw2();
dirname_ = tdir->GetPath(); //debug - improve
}
virtual bool process( EventClass & ev ) {
float w = 1.0;
w*=ev.eventInfo_.eventWeight(weights_);
h_wsum.Fill(0.5, w);
w_sum_+= w;
return true;
}
virtual bool output ( std::ostream & os ) {
os << "w_sum: " << h_wsum.GetBinContent(1) << std::endl;
return true;
}
virtual std::string get_name() {
auto name = "weightSum";
return name;
}
};