26 bool UseRatioForResponse = c1.
getValue<
bool>(
"UseRatioForResponse");
27 std::vector<double> pt_vec = c1.
getVector<
double>(
"RefPtBoundaries");
28 std::vector<double> eta_vec = c1.
getVector<
double>(
"EtaBoundaries");
29 if (!c1.
check())
return 0;
32 const int MAX_NETA = 83;
33 const int MAX_NREFPTBINS = 30;
34 int NRefPtBins = pt_vec.size()-1;
35 int NETA = eta_vec.size()-1;
38 double e,mR,eR,sR,seR,mRBarrel,eRBarrel,sRBarrel,seRBarrel,
r,
c;
39 double mCaloPt,eCaloPt,sCaloPt,mRefPt,eRefPt,sRefPt;
40 double mRefPtEtaBin,eRefPtEtaBin,sRefPtEtaBin,mCaloPtEtaBin,eCaloPtEtaBin,sCaloPtEtaBin;
41 double EtaBoundaries[MAX_NETA],RefPtBoundaries[MAX_NREFPTBINS];
42 std::vector<std::string> HistoNamesList;
43 for(j=0;j<=NRefPtBins;j++)
44 RefPtBoundaries[j] = pt_vec[j];
46 EtaBoundaries[j] = eta_vec[j];
50 TH1F *BarrelCorrection;
51 TH1F *MeanRefPt_Barrel;
52 TH1F *MeanCaloPt_Barrel;
53 TH1F *MeanRefPt_EtaBin[MAX_NETA];
54 TH1F *MeanCaloPt_EtaBin[MAX_NETA];
55 TH1F *ResponseVsEta_RefPt[MAX_NREFPTBINS];
56 TH1F *CorrectionVsEta_RefPt[MAX_NREFPTBINS];
60 inf =
new TFile(HistoFilename.c_str(),
"r");
61 if (inf->IsZombie())
return(0);
62 TIter
next(inf->GetListOfKeys());
63 while ((key = (TKey*)
next()))
64 HistoNamesList.push_back(key->GetName());
65 outf =
new TFile(FitterFilename.c_str(),
"RECREATE");
66 TDirectory *dir_Response = (TDirectory*)outf->mkdir(
"FittedHistograms");
67 BarrelResponse =
new TH1F(
"Response",
"Response",NRefPtBins,RefPtBoundaries);
68 BarrelCorrection =
new TH1F(
"Correction",
"Correction",NRefPtBins,RefPtBoundaries);
69 MeanRefPt_Barrel =
new TH1F(
"MeanRefPt",
"MeanRefPt",NRefPtBins,RefPtBoundaries);
70 MeanCaloPt_Barrel =
new TH1F(
"MeanCaloPt",
"MeanCaloPt",NRefPtBins,RefPtBoundaries);
73 std::cout<<
"************* Fitting Response Histograms in multiple Eta bins. ************"<<std::endl;
74 for(etabin=0;etabin<
NETA;etabin++)
76 sprintf(name,
"MeanRefPt_Eta%d",etabin);
77 MeanRefPt_EtaBin[etabin] =
new TH1F(name,name,NRefPtBins,RefPtBoundaries);
78 sprintf(name,
"MeanCaloPt_Eta%d",etabin);
79 MeanCaloPt_EtaBin[etabin] =
new TH1F(name,name,NRefPtBins,RefPtBoundaries);
81 for (j=0; j<NRefPtBins; j++)
83 std::cout<<
"RefJetPt Bin: ["<<RefPtBoundaries[
j]<<
","<<RefPtBoundaries[j+1]<<
"] GeV"<<std::endl;
84 sprintf(name,
"ptRef_RefPt%d_Barrel",j);
86 h = (TH1F*)inf->Get(name);
87 GetMEAN(h,mRefPt,eRefPt,sRefPt);
88 sprintf(name,
"ptCalo_RefPt%d_Barrel",j);
90 h = (TH1F*)inf->Get(name);
91 GetMEAN(h,mCaloPt,eCaloPt,sCaloPt);
92 sprintf(name,
"Response_RefPt%d_Barrel",j);
94 h = (TH1F*)inf->Get(name);
95 GetMPV(name,h,dir_Response,mRBarrel,eRBarrel,sRBarrel,seRBarrel);
97 MeanRefPt_Barrel->SetBinContent(j+1,mRefPt);
98 MeanRefPt_Barrel->SetBinError(j+1,eRefPt);
100 MeanCaloPt_Barrel->SetBinContent(j+1,mCaloPt);
101 MeanCaloPt_Barrel->SetBinError(j+1,eCaloPt);
104 BarrelResponse->SetBinContent(j+1,r);
105 BarrelResponse->SetBinError(j+1,e);
108 BarrelCorrection->SetBinContent(j+1,c);
109 BarrelCorrection->SetBinError(j+1,e);
111 sprintf(name,
"Response_vs_Eta_RefPt%d",j);
112 ResponseVsEta_RefPt[
j] =
new TH1F(name,name,NETA,EtaBoundaries);
113 sprintf(name,
"Correction_vs_Eta_RefPt%d",j);
114 CorrectionVsEta_RefPt[
j] =
new TH1F(name,name,NETA,EtaBoundaries);
115 for(etabin=0;etabin<
NETA;etabin++)
118 sprintf(name,
"Response_RefPt%d_Eta%d",j,etabin);
120 h = (TH1F*)inf->Get(name);
121 GetMPV(name,h,dir_Response,mR,eR,sR,seR);
122 sprintf(name,
"ptRef_RefPt%d_Eta%d",j,etabin);
124 h = (TH1F*)inf->Get(name);
125 GetMEAN(h,mRefPtEtaBin,eRefPtEtaBin,sRefPtEtaBin);
126 sprintf(name,
"ptCalo_RefPt%d_Eta%d",j,etabin);
128 h = (TH1F*)inf->Get(name);
129 GetMEAN(h,mCaloPtEtaBin,eCaloPtEtaBin,sCaloPtEtaBin);
131 MeanRefPt_EtaBin[etabin]->SetBinContent(j+1,mRefPtEtaBin);
132 MeanRefPt_EtaBin[etabin]->SetBinError(j+1,eRefPtEtaBin);
134 MeanCaloPt_EtaBin[etabin]->SetBinContent(j+1,mCaloPtEtaBin);
135 MeanCaloPt_EtaBin[etabin]->SetBinError(j+1,eCaloPtEtaBin);
138 ResponseVsEta_RefPt[
j]->SetBinContent(etabin+1,r);
139 ResponseVsEta_RefPt[
j]->SetBinError(etabin+1,e);
142 CorrectionVsEta_RefPt[
j]->SetBinContent(etabin+1,c);
143 CorrectionVsEta_RefPt[
j]->SetBinError(etabin+1,e);
149 std::cout<<
"************* Fitting Response Histograms in single eta bin. ************"<<std::endl;
150 for (j=0; j<NRefPtBins; j++)
152 std::cout<<
"RefJetPt Bin: ["<<RefPtBoundaries[
j]<<
","<<RefPtBoundaries[j+1]<<
"] GeV"<<std::endl;
153 sprintf(name,
"ptRef_RefPt%d",j);
155 h = (TH1F*)inf->Get(name);
156 GetMEAN(h,mRefPt,eRefPt,sRefPt);
157 sprintf(name,
"ptCalo_RefPt%d",j);
159 h = (TH1F*)inf->Get(name);
160 GetMEAN(h,mCaloPt,eCaloPt,sCaloPt);
161 sprintf(name,
"Response_RefPt%d",j);
163 h = (TH1F*)inf->Get(name);
164 GetMPV(name,h,dir_Response,mRBarrel,eRBarrel,sRBarrel,seRBarrel);
166 MeanRefPt_Barrel->SetBinContent(j+1,mRefPt);
167 MeanRefPt_Barrel->SetBinError(j+1,eRefPt);
169 MeanCaloPt_Barrel->SetBinContent(j+1,mCaloPt);
170 MeanCaloPt_Barrel->SetBinError(j+1,eCaloPt);
173 BarrelResponse->SetBinContent(j+1,r);
174 BarrelResponse->SetBinError(j+1,e);
177 BarrelCorrection->SetBinContent(j+1,c);
178 BarrelCorrection->SetBinError(j+1,e);
183 MeanRefPt_Barrel->Write();
184 MeanCaloPt_Barrel->Write();
185 BarrelResponse->Write();
186 BarrelCorrection->Write();
189 for(etabin=0;etabin<
NETA;etabin++)
191 MeanRefPt_EtaBin[etabin]->Write();
192 MeanCaloPt_EtaBin[etabin]->Write();
194 for(j=0;j<NRefPtBins;j++)
196 ResponseVsEta_RefPt[
j]->Write();
197 CorrectionVsEta_RefPt[
j]->Write();
void CalculateResponse(bool UseRatioForResponse, double x, double ex, double y, double ey, double &r, double &e)
std::vector< T > getVector(const std::string &name)
int main(int argc, char **argv)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
T getValue(const std::string &name)
void GetMPV(char name[100], TH1F *histo, TDirectory *Dir, double &peak, double &error, double &sigma, double &err_sigma)
void GetMEAN(TH1F *histo, double &peak, double &error, double &sigma)
void CalculateCorrection(bool UseRatioForResponse, double x, double ex, double y, double ey, double &c, double &e)
bool parse(int argc, char **argv)
bool HistoExists(std::vector< std::string > LIST, std::string hname)