25 bool UseRatioForResponse = c1.
getValue<
bool>(
"UseRatioForResponse");
26 std::vector<double> pt_vec = c1.
getVector<
double>(
"RefPtBoundaries");
27 std::vector<double> eta_vec = c1.
getVector<
double>(
"EtaBoundaries");
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];
45 for (j = 0; j <=
NETA; 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");
63 TIter
next(inf->GetListOfKeys());
64 while ((key = (TKey *)
next()))
65 HistoNamesList.push_back(key->GetName());
66 outf =
new TFile(FitterFilename.c_str(),
"RECREATE");
67 TDirectory *dir_Response =
68 (TDirectory *)outf->mkdir(
"FittedHistograms");
69 BarrelResponse =
new TH1F(
"Response",
"Response", NRefPtBins, RefPtBoundaries);
70 BarrelCorrection =
new TH1F(
"Correction",
"Correction", NRefPtBins, RefPtBoundaries);
71 MeanRefPt_Barrel =
new TH1F(
"MeanRefPt",
"MeanRefPt", NRefPtBins, RefPtBoundaries);
72 MeanCaloPt_Barrel =
new TH1F(
"MeanCaloPt",
"MeanCaloPt", NRefPtBins, RefPtBoundaries);
75 std::cout <<
"************* Fitting Response Histograms in multiple Eta bins. ************" << std::endl;
76 for (etabin = 0; etabin <
NETA; etabin++) {
77 sprintf(name,
"MeanRefPt_Eta%d", etabin);
78 MeanRefPt_EtaBin[etabin] =
new TH1F(name, name, NRefPtBins, RefPtBoundaries);
79 sprintf(name,
"MeanCaloPt_Eta%d", etabin);
80 MeanCaloPt_EtaBin[etabin] =
new TH1F(name, name, NRefPtBins, RefPtBoundaries);
82 for (j = 0; j < NRefPtBins; j++)
84 std::cout <<
"RefJetPt Bin: [" << RefPtBoundaries[
j] <<
"," << RefPtBoundaries[j + 1] <<
"] GeV" << std::endl;
85 sprintf(name,
"ptRef_RefPt%d_Barrel", j);
88 h = (TH1F *)inf->Get(name);
89 GetMEAN(h, mRefPt, eRefPt, sRefPt);
90 sprintf(name,
"ptCalo_RefPt%d_Barrel", j);
93 h = (TH1F *)inf->Get(name);
94 GetMEAN(h, mCaloPt, eCaloPt, sCaloPt);
95 sprintf(name,
"Response_RefPt%d_Barrel", j);
98 h = (TH1F *)inf->Get(name);
99 GetMPV(name, h, dir_Response, mRBarrel, eRBarrel, sRBarrel, seRBarrel);
101 MeanRefPt_Barrel->SetBinContent(j + 1, mRefPt);
102 MeanRefPt_Barrel->SetBinError(j + 1, eRefPt);
104 MeanCaloPt_Barrel->SetBinContent(j + 1, mCaloPt);
105 MeanCaloPt_Barrel->SetBinError(j + 1, eCaloPt);
107 CalculateResponse(UseRatioForResponse, mRefPt, eRefPt, mRBarrel, eRBarrel, r, e);
108 BarrelResponse->SetBinContent(j + 1, r);
109 BarrelResponse->SetBinError(j + 1, e);
112 BarrelCorrection->SetBinContent(j + 1, c);
113 BarrelCorrection->SetBinError(j + 1, e);
115 sprintf(name,
"Response_vs_Eta_RefPt%d", j);
116 ResponseVsEta_RefPt[
j] =
new TH1F(name, name, NETA, EtaBoundaries);
117 sprintf(name,
"Correction_vs_Eta_RefPt%d", j);
118 CorrectionVsEta_RefPt[
j] =
new TH1F(name, name, NETA, EtaBoundaries);
119 for (etabin = 0; etabin <
NETA; etabin++)
122 sprintf(name,
"Response_RefPt%d_Eta%d", j, etabin);
125 h = (TH1F *)inf->Get(name);
126 GetMPV(name, h, dir_Response, mR, eR, sR, seR);
127 sprintf(name,
"ptRef_RefPt%d_Eta%d", j, etabin);
130 h = (TH1F *)inf->Get(name);
131 GetMEAN(h, mRefPtEtaBin, eRefPtEtaBin, sRefPtEtaBin);
132 sprintf(name,
"ptCalo_RefPt%d_Eta%d", j, etabin);
135 h = (TH1F *)inf->Get(name);
136 GetMEAN(h, mCaloPtEtaBin, eCaloPtEtaBin, sCaloPtEtaBin);
138 MeanRefPt_EtaBin[etabin]->SetBinContent(j + 1, mRefPtEtaBin);
139 MeanRefPt_EtaBin[etabin]->SetBinError(j + 1, eRefPtEtaBin);
141 MeanCaloPt_EtaBin[etabin]->SetBinContent(j + 1, mCaloPtEtaBin);
142 MeanCaloPt_EtaBin[etabin]->SetBinError(j + 1, eCaloPtEtaBin);
144 CalculateResponse(UseRatioForResponse, mRefPtEtaBin, eRefPtEtaBin, mR, eR, r, e);
145 ResponseVsEta_RefPt[
j]->SetBinContent(etabin + 1, r);
146 ResponseVsEta_RefPt[
j]->SetBinError(etabin + 1, e);
149 CorrectionVsEta_RefPt[
j]->SetBinContent(etabin + 1, c);
150 CorrectionVsEta_RefPt[
j]->SetBinError(etabin + 1, e);
155 std::cout <<
"************* Fitting Response Histograms in single eta bin. ************" << std::endl;
156 for (j = 0; j < NRefPtBins; j++)
158 std::cout <<
"RefJetPt Bin: [" << RefPtBoundaries[
j] <<
"," << RefPtBoundaries[j + 1] <<
"] GeV" << std::endl;
159 sprintf(name,
"ptRef_RefPt%d", j);
162 h = (TH1F *)inf->Get(name);
163 GetMEAN(h, mRefPt, eRefPt, sRefPt);
164 sprintf(name,
"ptCalo_RefPt%d", j);
167 h = (TH1F *)inf->Get(name);
168 GetMEAN(h, mCaloPt, eCaloPt, sCaloPt);
169 sprintf(name,
"Response_RefPt%d", j);
172 h = (TH1F *)inf->Get(name);
173 GetMPV(name, h, dir_Response, mRBarrel, eRBarrel, sRBarrel, seRBarrel);
175 MeanRefPt_Barrel->SetBinContent(j + 1, mRefPt);
176 MeanRefPt_Barrel->SetBinError(j + 1, eRefPt);
178 MeanCaloPt_Barrel->SetBinContent(j + 1, mCaloPt);
179 MeanCaloPt_Barrel->SetBinError(j + 1, eCaloPt);
181 CalculateResponse(UseRatioForResponse, mRefPt, eRefPt, mRBarrel, eRBarrel, r, e);
182 BarrelResponse->SetBinContent(j + 1, r);
183 BarrelResponse->SetBinError(j + 1, e);
186 BarrelCorrection->SetBinContent(j + 1, c);
187 BarrelCorrection->SetBinError(j + 1, e);
192 MeanRefPt_Barrel->Write();
193 MeanCaloPt_Barrel->Write();
194 BarrelResponse->Write();
195 BarrelCorrection->Write();
197 for (etabin = 0; etabin <
NETA; etabin++) {
198 MeanRefPt_EtaBin[etabin]->Write();
199 MeanCaloPt_EtaBin[etabin]->Write();
201 for (j = 0; j < NRefPtBins; j++) {
202 ResponseVsEta_RefPt[
j]->Write();
203 CorrectionVsEta_RefPt[
j]->Write();
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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)
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)