-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeWeightHisto.C
76 lines (57 loc) · 2.38 KB
/
makeWeightHisto.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
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
#include <iostream>
#include <stdexcept>
#include <TFile.h>
#include <TH1D.h>
#include "ConfigParser.C"
using namespace std;
void makeWeightHisto(ConfigParser * conf)
{
TString hist_name = conf->get("rwt_var");
TString primary_name = conf->get("primary_name");
TString secondary_name = conf->get("secondary_name");
TString primary_histos = conf->get("histo_output_dir")+"ct_Z_Base_"+conf->get("signal_region")+".root";
TString weight_from;
if (conf->get("weight_from") == ""){
weight_from="G_Base";
}
else{
weight_from=conf->get("weight_from");
}
TString secondary_histos = conf->get("histo_output_dir")+"ct_"+weight_from+"_"+conf->get("signal_region")+".root";
TString output_location = conf->get("histo_output_dir")+"ct_"+hist_name+"_"+conf->get("signal_region")+"_rwt.root";
TFile * f_primary = TFile::Open(primary_histos , "READ"); //typically location to data hist
TFile * f_secondary = TFile::Open(secondary_histos, "READ"); //typically location to zjets hist
cout<<"Found input files for reweighting"<<endl;
TH1D * h_primary;
TH1D * h_secondary;
TH1D * h_primary_scaled;
TH1D * h_secondary_scaled;
if (f_primary && f_secondary) {
h_primary = (TH1D*)f_primary->Get(primary_name+"_"+hist_name)->Clone("h_"+primary_name);
h_secondary = (TH1D*)f_secondary->Get(secondary_name+"_"+hist_name)->Clone("h_"+secondary_name);
}
else{
cout<<"Error, could not open baseline files, please check they exist where specified and try again"<<endl;
exit(1);
}
cout<<"Retrived Histograms"<<endl;
TH1D * h_ratio_unscaled = (TH1D*) h_primary->Clone("h_"+hist_name+"_ratio_unscaled");
h_ratio_unscaled->Divide(h_secondary);
h_primary_scaled=(TH1D*) h_primary->Clone("h_"+primary_name+"_scaled");
h_secondary_scaled=(TH1D*) h_secondary->Clone("h_"+secondary_name+"_scaled");
h_secondary_scaled->Scale(1./h_secondary->GetSumOfWeights());
h_primary_scaled->Scale(1./h_primary->GetSumOfWeights());
TH1D * h_ratio = (TH1D*) h_primary_scaled->Clone("h_"+hist_name+"_ratio");
h_ratio->Divide(h_secondary_scaled);
TFile * file = TFile::Open(output_location,"RECREATE");
file->cd();
h_ratio->Write();
h_ratio_unscaled->Write();
h_primary->Write();
h_secondary->Write();
h_primary_scaled->Write();
h_secondary_scaled->Write();
file->Close();
cout<<"Reweight histogram succesfully made at "<<output_location<<endl;
return ;
}