1 #include "../interface/MultiDraw.hh"
5 #include "TStopwatch.h"
7 #include "TTreeFormula.h"
10 void MultiDraw(TTree *inTree, TObjArray *Formulae, TObjArray *Weights,
11 TObjArray *Hists, UInt_t ListLen) {
13 unsigned long NumEvents = inTree->GetEntries();
15 std::vector<TTreeFormula *> v_vars(ListLen,
nullptr);
16 std::vector<TTreeFormula *> v_weights(ListLen,
nullptr);
17 std::vector<TH1D *> v_hists(ListLen,
nullptr);
18 std::vector<TH2F *> v_hists2d(ListLen,
nullptr);
20 std::vector<double> r_vars(ListLen, 0.);
21 std::vector<double> r_weights(ListLen, 0.);
22 std::vector<unsigned> i_vars(ListLen, 0);
23 std::vector<unsigned> i_weights(ListLen, 0);
24 std::map<std::string, unsigned> map_vars;
25 std::map<std::string, unsigned> map_weights;
28 for (
unsigned idx = 0; idx < ListLen; ++idx) {
30 auto const& itv = map_vars.find(Formulae->At(idx)->GetTitle());
31 if (itv == map_vars.end()) {
32 map_vars[Formulae->At(idx)->GetTitle()] = idx;
33 v_vars[idx] =
static_cast<TTreeFormula *
>(Formulae->At(idx));
36 i_vars[idx] = itv->second;
39 auto const& itw = map_weights.find(Weights->At(idx)->GetTitle());
40 if (itw == map_weights.end()) {
41 map_weights[Weights->At(idx)->GetTitle()] = idx;
42 v_weights[idx] =
static_cast<TTreeFormula *
>(Weights->At(idx));
45 i_weights[idx] = itw->second;
48 v_vars[idx] =
static_cast<TTreeFormula *
>(Formulae->At(idx));
50 v_weights[idx] =
static_cast<TTreeFormula *
>(Weights->At(idx));
54 v_hists[idx] =
dynamic_cast<TH1D *
>(Hists->At(idx));
55 v_hists2d[idx] =
dynamic_cast<TH2F *
>(Hists->At(idx));
60 double commonWeight = 1.;
61 double treeWeight = inTree->GetWeight();
62 Int_t TreeNumber = -1;
65 for (i = 0; i < NumEvents; i++) {
68 std::cout.precision(2);
70 double nTodo = NumEvents - i, perSecond = 20000 / s.RealTime();
71 Int_t seconds = (Int_t)(nTodo / perSecond),
72 minutes = (Int_t)(seconds / 60.);
73 seconds -= (Int_t)(minutes * 60.);
75 std::cout <<
"Done " << (double(i) / (double(NumEvents)) * 100.0f)
77 if (minutes) std::cout << minutes <<
" minutes ";
78 std::cout << seconds <<
" seconds remain. \r";
84 if (TreeNumber != inTree->GetTreeNumber()) {
85 treeWeight = inTree->GetWeight();
86 TreeNumber = inTree->GetTreeNumber();
89 inTree->LoadTree(inTree->GetEntryNumber(i));
91 commonWeight *= treeWeight;
93 for (
unsigned j = 0; j < ListLen; j++) {
95 r_vars[j] = v_vars[j]->EvalInstance();
98 r_weights[j] = v_weights[j]->EvalInstance();
100 Value = r_vars[i_vars[j]];
101 Weight = r_weights[i_weights[j]] * commonWeight;
102 if (v_hists[j] && Weight) {
103 v_hists[j]->Fill(Value, Weight);
108 if (v_hists2d[j] && j >= 1 && Weight) {
109 v_hists2d[j]->Fill(Value, r_vars[i_vars[j-1]], Weight);
void MultiDraw(TTree *inTree, TObjArray *Formulae, TObjArray *Weights, TObjArray *Hists, UInt_t ListLen)