forked from BSM3G/Plotter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeWeighter.C
28 lines (24 loc) · 1002 Bytes
/
makeWeighter.C
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
void makeWeighter() {
TFile* Datafile = new TFile("Data.root");
TFile* MCfile = new TFile("MC.root");
TFile* extrafile = new TFile("extra.root");
Datafile->cd("METCut");
TH1D* Data = (TH1D*)gDirectory->FindObjectAny("NVertices");
MCfile->cd("METCut");
TH1D* MC = (TH1D*)gDirectory->FindObjectAny("NVertices");
double allData = Data->Integral();
double allMC = MC->Integral();
double factor = allMC/allData;
TFile* newfile = new TFile("newWeight.root", "RECREATE");
newfile->cd();
TH1D* weight = new TH1D("extra", "extra", 100, 0, 100);
for(int i = 0; i < weight->GetXaxis()->GetNbins(); ++i) {
if(MC->GetBinContent(i+1) == 0) continue;
double tmp = Data->GetBinContent(i+1)*factor/MC->GetBinContent(i+1);
weight->SetBinContent(i+1, tmp);
cout << (i+1) << " | " << tmp << " | " <<
tmp*MC->GetBinContent(i+1) << " | " << ((tmp!=0) ? Data->GetBinContent(i+1)/(tmp*MC->GetBinContent(i+1)) : 0) << endl;
}
weight->Write();
newfile->Close();
}