30 std::vector<double> pt_vec = c1.
getVector<
double>(
"RefPtBoundaries");
31 std::vector<double> eta_vec = c1.
getVector<
double>(
"EtaBoundaries");
36 const int MAX_NREFPTBINS = 30;
37 int NRefPtBins = pt_vec.size() - 1;
39 int i, auxi_cor, auxi_resp;
40 double Correction[MAX_NREFPTBINS] = {};
41 double CorrectionError[MAX_NREFPTBINS] = {};
42 double Response[MAX_NREFPTBINS] = {};
43 double ResponseError[MAX_NREFPTBINS] = {};
44 double xCaloPt[MAX_NREFPTBINS] = {};
45 double exCaloPt[MAX_NREFPTBINS] = {};
46 double xRefPt[MAX_NREFPTBINS] = {};
47 double exRefPt[MAX_NREFPTBINS] = {};
48 double MinCaloPt, MaxCaloPt, MinRefPt, MaxRefPt;
49 double cor, e_cor, resp, e_resp;
52 TH1F *hCor, *hResp, *hRef, *hCalo;
57 TVirtualFitter *fitter;
58 TMatrixD *COV_Cor, *COV_Resp;
59 std::ofstream L3CorrectionFile, L3ResponseFile;
60 L3CorrectionFile.open(L3CorrectionTxtFilename.c_str());
61 L3ResponseFile.open(L3ResponseTxtFilename.c_str());
63 std::vector<std::string> HistoNamesList;
64 inf =
new TFile(FitterFilename.c_str(),
"r");
67 TIter
next(inf->GetListOfKeys());
68 while ((key = (TKey *)
next()))
69 HistoNamesList.push_back(key->GetName());
71 sprintf(name,
"MeanCaloPt");
74 hCalo = (TH1F *)inf->Get(name);
76 sprintf(name,
"MeanRefPt");
79 hRef = (TH1F *)inf->Get(name);
81 sprintf(name,
"Correction");
84 hCor = (TH1F *)inf->Get(name);
85 sprintf(name,
"Response");
88 hResp = (TH1F *)inf->Get(name);
91 std::cout <<
"RefPt bin" << setw(12) <<
"<CaloPt>" << setw(12) <<
"Correction" << setw(12) <<
"Error" << setw(12)
92 <<
"<RefPt>" << setw(12) <<
"Response" << setw(12) <<
"Error" << std::endl;
93 for (i = 0; i < NRefPtBins; i++) {
94 cor = hCor->GetBinContent(i + 1);
95 e_cor = hCor->GetBinError(i + 1);
96 std::cout <<
"[" << pt_vec[
i] <<
"," << pt_vec[i + 1] <<
"]" << setw(12) << hCalo->GetBinContent(i + 1) << setw(12)
97 << cor << setw(12) << e_cor;
98 resp = hResp->GetBinContent(i + 1);
99 e_resp = hResp->GetBinError(i + 1);
100 std::cout << setw(12) << hRef->GetBinContent(i + 1) << setw(12) << resp << setw(12) << e_resp << std::endl;
101 if (cor > 0 && e_cor > 0.000001 && e_cor < 0.2) {
102 Correction[auxi_cor] = cor;
103 CorrectionError[auxi_cor] = e_cor;
104 xCaloPt[auxi_cor] = hCalo->GetBinContent(i + 1);
105 exCaloPt[auxi_cor] = hCalo->GetBinError(i + 1);
108 if (resp > 0 && e_resp > 0.000001 && e_resp < 0.2) {
109 Response[auxi_resp] = resp;
110 ResponseError[auxi_resp] = e_resp;
111 xRefPt[auxi_resp] = hRef->GetBinContent(i + 1);
112 exRefPt[auxi_resp] = hRef->GetBinError(i + 1);
116 g_Cor =
new TGraphErrors(auxi_cor, xCaloPt, Correction, exCaloPt, CorrectionError);
117 sprintf(name,
"CorFit");
118 CorFit =
new TF1(name,
"[0]+[1]/(pow(log10(x),[2])+[3])", xCaloPt[1], xCaloPt[auxi_cor - 1]);
119 CorFit->SetParameter(0, 1.);
120 CorFit->SetParameter(1, 7.);
121 CorFit->SetParameter(2, 4.);
122 CorFit->SetParameter(3, 4.);
123 std::cout <<
"Fitting correction in the range: " << xCaloPt[1] <<
" " << xCaloPt[auxi_cor - 1] << std::endl;
124 g_Cor->Fit(CorFit,
"RQ");
125 fitter = TVirtualFitter::GetFitter();
126 COV_Cor =
new TMatrixD(4, 4, fitter->GetCovarianceMatrix());
127 g_Resp =
new TGraphErrors(auxi_resp, xRefPt, Response, exRefPt, ResponseError);
128 sprintf(name,
"RespFit");
129 RespFit =
new TF1(name,
"[0]-[1]/(pow(log10(x),[2])+[3])+[4]/x", xRefPt[0], xRefPt[auxi_resp - 1]);
130 RespFit->SetParameter(0, 1.);
131 RespFit->SetParameter(1, 1.);
132 RespFit->SetParameter(2, 1.);
133 RespFit->SetParameter(3, 1.);
134 RespFit->SetParameter(4, 1.);
135 std::cout <<
"Fitting response in the range: " << xRefPt[0] <<
" " << xRefPt[auxi_resp - 1] << std::endl;
136 g_Resp->Fit(RespFit,
"RQ");
137 fitter = TVirtualFitter::GetFitter();
138 COV_Resp =
new TMatrixD(5, 5, fitter->GetCovarianceMatrix());
144 CorFit->SetRange(MinCaloPt, MaxCaloPt);
145 RespFit->SetRange(MinRefPt, MaxRefPt);
147 L3CorrectionFile.setf(ios::left);
148 L3CorrectionFile << setw(12) << -5.191 << setw(12) << 5.191 << setw(12) << (
int)6 << setw(12) << MinCaloPt << setw(12)
149 << MaxCaloPt << setw(12) << CorFit->GetParameter(0) << setw(12) << CorFit->GetParameter(1)
150 << setw(12) << CorFit->GetParameter(2) << setw(12) << CorFit->GetParameter(3);
151 L3CorrectionFile.close();
153 L3ResponseFile.setf(ios::left);
154 L3ResponseFile << setw(12) << RespFit->GetParameter(0) << setw(12) << RespFit->GetParameter(1) << setw(12)
155 << RespFit->GetParameter(2) << setw(12) << RespFit->GetParameter(3) << setw(12)
156 << RespFit->GetParameter(4);
157 L3ResponseFile.close();
159 outf =
new TFile(L3OutputROOTFilename.c_str(),
"RECREATE");
160 g_Cor->Write(
"Correction_vs_CaloPt");
161 COV_Cor->Write(
"CovMatrix_Correction");
162 g_Resp->Write(
"Response_vs_RefPt");
163 COV_Resp->Write(
"CovMatrix_Resp");
std::vector< T > getVector(const std::string &name)
T getValue(const std::string &name)
bool parse(int argc, char **argv)
bool HistoExists(std::vector< std::string > LIST, std::string hname)