-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMixedEventWriterOperator.h
130 lines (93 loc) · 3.73 KB
/
MixedEventWriterOperator.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#pragma once
#include <algorithm>
#include <math.h>
#include "BaseOperator.h"
#include "BTagFilterOperator.h"
#include "JetPairingOperator.h"
#include "Hemisphere.h"
#include "Event.h"
template <class EventClass> class MixedEventWriterOperator : public BaseOperator<EventClass> {
public:
unsigned int nDataReplica_;
unsigned int nNoEvtInfo_;
// variables to save in branches
float_t evtWeight = 1.;
std::vector<alp::Jet> mix_jets_;
std::vector<alp::Hemisphere> fhems_;
std::vector<alp::Hemisphere> orhems_;
// a pointer to avoid undeclared label
std::vector<alp::Jet> * mix_jets_ptr_;
std::vector<alp::Hemisphere> * fhems_ptr_;
std::vector<alp::Hemisphere> * orhems_ptr_;
// hemisphere combinations to save
std::vector<std::vector<std::size_t>> combs_;
bool getRealEvtFr_;
std::vector<std::string> weights_;
TTree tree_{"mix_tree","Tree wth mixed events"};
MixedEventWriterOperator(std::vector<std::vector<std::size_t>> combs = {{1,1}}, bool getRealEvtFr = false, const std::vector<std::string> & weights = {}) :
mix_jets_ptr_(&mix_jets_),
fhems_ptr_(&fhems_),
orhems_ptr_(&orhems_),
combs_(combs),
getRealEvtFr_(getRealEvtFr),
weights_(weights) {}
virtual ~MixedEventWriterOperator() {}
virtual void init(TDirectory * tdir) {
nDataReplica_ = 0;
nNoEvtInfo_ = 0;
tree_.Branch("evtWeight", &evtWeight, "evtWeight/F");
tree_.Branch("Jets","std::vector<alp::Jet>",
&mix_jets_ptr_, 64000, 1);
tree_.Branch("Hems","std::vector<alp::Hemisphere>",
&fhems_ptr_, 64000, 1);
tree_.Branch("OrHems","std::vector<alp::Hemisphere>",
&orhems_ptr_, 64000, 1);
tree_.SetDirectory(tdir);
tree_.AutoSave();
}
virtual bool process( EventClass & ev ) {
const auto & bm_hems = ev.best_match_hems_;
evtWeight = 1.;
if(weights_.size()>0) evtWeight *= ev.eventInfo_.eventWeight(weights_); //multiplied all weights from cfg
else evtWeight *= ev.evtWeight_;
for (const auto & comb : combs_) {
auto h_i = comb.at(0);
auto h_j = comb.at(1);
// clear vectors
mix_jets_.clear();
fhems_.clear();
orhems_.clear();
// references for easy access
const auto jets_i = bm_hems.at(0).at(h_i).jets_;
const auto jets_j = bm_hems.at(1).at(h_j).jets_;
mix_jets_.insert(mix_jets_.end(), jets_i.begin(), jets_i.end());
mix_jets_.insert(mix_jets_.end(), jets_j.begin(), jets_j.end());
auto hems_i = bm_hems.at(0).at(h_i);
auto hems_j = bm_hems.at(1).at(h_j);
fhems_.emplace_back(hems_i);
fhems_.emplace_back(hems_j);
if(getRealEvtFr_){
if(fhems_.at(0).evtnum() == 0 || fhems_.at(1).evtnum() == 0 ||
fhems_.at(0).run() == 0 || fhems_.at(1).run() == 0 ||
fhems_.at(0).lumiblock() == 0 || fhems_.at(1).lumiblock() == 0) nNoEvtInfo_++;
else if(fhems_.at(0).evtnum() == fhems_.at(1).evtnum() &&
fhems_.at(0).run() == fhems_.at(1).run() &&
fhems_.at(0).lumiblock() == fhems_.at(1).lumiblock()) nDataReplica_++;
}
const auto orhems_i = bm_hems.at(0).at(0);
const auto orhems_j = bm_hems.at(1).at(0);
orhems_.emplace_back(orhems_i);
orhems_.emplace_back(orhems_j);
// fill tree with combination
tree_.Fill();
}
return true;
}
virtual bool output( TFile * tfile) {
if(getRealEvtFr_){
std::cout<< "evts with null hems evt info: " << nNoEvtInfo_ << std::endl;
std::cout<< "data evts replica: " << nDataReplica_ << std::endl;
}
return true;
}
};