-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHFweight.h
82 lines (70 loc) · 2.31 KB
/
HFweight.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
#ifndef HFweight_h
#define HFweight_h
#include "TFile.h"
#include "TH1.h"
#include <iostream>
using namespace std;
class HFweight {
public:
enum HFside {
both,
plus,
minus,
track
};
HFweight(const char* weightfile = "/afs/cern.ch/work/e/echapon/public/DY_pA_2016/HFweight.root");
~HFweight();
double weight(double hiHF, HFside side=both, bool isPV1=false);
private:
const char* weightfile = "/afs/cern.ch/work/e/echapon/public/DY_pA_2016/HFweight.root";
TFile *f;
TH1F* h_hiHF_ratio;
TH1F* h_hiHFplus_ratio;
TH1F* h_hiHFminus_ratio;
TH1F* h_hiNtracks_ratio;
TH1F* h_hiHF_PV1_ratio;
TH1F* h_hiHFplus_PV1_ratio;
TH1F* h_hiHFminus_PV1_ratio;
TH1F* h_hiNtracks_PV1_ratio;
};
HFweight::HFweight(const char* weightfile) {
f = new TFile(weightfile);
if (!f || !f->IsOpen()) {
cout << "Error! could not find HF weight file " << weightfile << endl;
return;
} else {
cout << "Opened " << weightfile << " for HF weights." << endl;
}
h_hiHF_ratio = (TH1F*) f->Get("h_hiHF_ratio");
h_hiHFplus_ratio = (TH1F*) f->Get("h_hiHFplus_ratio");
h_hiHFminus_ratio = (TH1F*) f->Get("h_hiHFminus_ratio");
h_hiNtracks_ratio = (TH1F*) f->Get("h_hiNtracks_ratio");
h_hiHF_PV1_ratio = (TH1F*) f->Get("h_hiHF_PV1_ratio");
h_hiHFplus_PV1_ratio = (TH1F*) f->Get("h_hiHFplus_PV1_ratio");
h_hiHFminus_PV1_ratio = (TH1F*) f->Get("h_hiHFminus_PV1_ratio");
h_hiNtracks_PV1_ratio = (TH1F*) f->Get("h_hiNtracks_PV1_ratio");
}
HFweight::~HFweight() {
f->Close();
if (f) {
delete f;
f=0;
}
}
double HFweight::weight(double hiHF, HFweight::HFside side, bool isPV1) {
TH1F *hist;
if (side==both) hist = isPV1 ? h_hiHF_PV1_ratio : h_hiHF_ratio;
else if (side==plus) hist = isPV1 ? h_hiHFplus_PV1_ratio : h_hiHFplus_ratio;
else if (side==minus) hist = isPV1 ? h_hiHFminus_PV1_ratio : h_hiHFminus_ratio;
else if (side==track) hist = isPV1 ? h_hiNtracks_PV1_ratio : h_hiNtracks_ratio;
else {
cout << "Error, requesting unknown HF configuration!" << endl;
return 1;
}
if (!hist) {
cout << "Error, missing weight histo" << endl;
return 1;
}
return std::min(7.0 , hist->GetBinContent(hist->FindBin(hiHF)));
}
#endif // #ifndef HFweight_h