30 std::vector<double> pt_vec = c1.
getVector<
double>(
"RefPtBoundaries");
31 std::vector<double> eta_vec = c1.
getVector<
double>(
"EtaBoundaries");
32 if (!c1.
check())
return 0;
35 const int MAX_NETA = 83;
36 const int MAX_NREFPTBINS = 30;
37 const int NCaloPtValues = 18;
38 int NRefPtBins = pt_vec.size()-1;
39 int NETA = eta_vec.size()-1;
40 if (NETA<2)
return(0);
41 int i,auxi,etabin,ptbin;
44 double MinCaloPt[MAX_NETA],MaxCaloPt[MAX_NETA];
45 double correction_x[MAX_NREFPTBINS],correction_y[MAX_NREFPTBINS],correction_ex[MAX_NREFPTBINS],correction_ey[MAX_NREFPTBINS];
46 double cor_rel[MAX_NREFPTBINS],ref_pt,calo_pt,control_pt;
47 double L3_resp[5],L2_cor[10];
51 TH1F *hcorrection[MAX_NREFPTBINS];
53 TF1 *Correction[MAX_NETA];
54 TF1 *L2Correction[MAX_NETA];
56 std::ifstream L3ResponseFile;
58 TGraph *g_L2Correction[MAX_NETA];
59 TGraphErrors *g_EtaCorrection[MAX_NETA];
60 double aux_CaloPt[NCaloPtValues] = {10,15,20,30,40,50,75,100,150,200,300,400,500,750,1000,1500,2000,3000};
61 std::vector<std::string> HistoNamesList;
62 inf =
new TFile(FitterFilename.c_str(),
"r");
63 if (inf->IsZombie())
return(0);
64 TIter
next(inf->GetListOfKeys());
65 while ((key = (TKey*)
next()))
66 HistoNamesList.push_back(key->GetName());
68 L3ResponseFile.open(L3ResponseTxtFilename.c_str());
69 L3ResponseFile>>L3_resp[0]>>L3_resp[1]>>L3_resp[2]>>L3_resp[3]>>L3_resp[4];
70 L3Response =
new TF1(
"L3Response",
"[0]-[1]/(pow(log10(x),[2])+[3])+[4]/x",pt_vec[0],pt_vec[NRefPtBins-1]);
72 L3Response->SetParameter(i,L3_resp[i]);
73 L3ResponseFile.close();
75 for (i=0;i<NRefPtBins;i++)
77 sprintf(name,
"Correction_vs_Eta_RefPt%d",i);
79 hcorrection[
i] = (TH1F*)inf->Get(name);
81 for (etabin=0;etabin<
NETA;etabin++)
83 sprintf(name,
"MeanCaloPt_Eta%d",etabin);
85 h = (TH1F*)inf->Get(name);
88 for (ptbin=0;ptbin<NRefPtBins;ptbin++)
90 cor = hcorrection[ptbin]->GetBinContent(etabin+1);
91 e_cor = hcorrection[ptbin]->GetBinError(etabin+1);
92 if (cor>0 && e_cor>0.0001 && e_cor<0.3)
94 correction_x[auxi] = h->GetBinContent(ptbin+1);
95 correction_ex[auxi] = 0.;
96 correction_y[auxi] = cor;
97 correction_ey[auxi] = e_cor;
101 sprintf(name,
"Correction%d",etabin);
104 MaxCaloPt[etabin]=correction_x[auxi-1];
105 MinCaloPt[etabin]=correction_x[1];
107 sprintf(func,
"[0]+[1]/(pow(log10(x),[2])+[3])");
109 sprintf(func,
"[0]+[1]*log10(x)+[2]*pow(log10(x),2)");
110 Correction[etabin] =
new TF1(name,func,MinCaloPt[etabin],MaxCaloPt[etabin]);
114 std::cout<<name<<
": not enough points"<<std::endl;
116 correction_x[0] = 10;
117 correction_x[1] = 100;
118 correction_ex[0] = 0.;
119 correction_ex[1] = 0.;
120 correction_y[0] = 1.;
121 correction_y[1] = 1.;
122 correction_ey[0] = 0.;
123 correction_ey[1] = 0.;
125 Correction[etabin] =
new TF1(name,func,10,100);
126 MaxCaloPt[etabin] = 0;
127 MinCaloPt[etabin] = 0;
129 g_EtaCorrection[etabin] =
new TGraphErrors(auxi,correction_x,correction_y,correction_ex,correction_ey);
130 Correction[etabin]->SetParameter(0,0.);
131 Correction[etabin]->SetParameter(1,0.);
132 Correction[etabin]->SetParameter(2,0.);
133 Correction[etabin]->SetParameter(3,0.);
134 g_EtaCorrection[etabin]->Fit(name,
"RQ");
135 std::cout<<name<<
" fitted....."<<std::endl;
138 for(ptbin=0;ptbin<NCaloPtValues;ptbin++)
140 calo_pt = aux_CaloPt[ptbin];
141 if (calo_pt>=MinCaloPt[etabin] && calo_pt<=MaxCaloPt[etabin])
143 ref_pt = calo_pt*Correction[etabin]->Eval(calo_pt);
144 control_pt = ref_pt*(L3Response->Eval(ref_pt));
145 cor_rel[auxi] = control_pt/calo_pt;
146 correction_x[auxi] = calo_pt;
150 sprintf(name,
"L2Correction%d",etabin);
153 sprintf(func,
"[0]+[1]*log10(x)+[2]*pow(log10(x),2)");
155 sprintf(func,
"[0]+[1]*log10(x)");
160 correction_x[0] = 10;
161 correction_x[1] = 100;
166 g_L2Correction[etabin] =
new TGraph(auxi,correction_x,cor_rel);
167 L2Correction[etabin] =
new TF1(name,func,correction_x[0],correction_x[auxi-1]);
168 L2Correction[etabin]->SetParameter(0,0.);
169 L2Correction[etabin]->SetParameter(1,0.);
170 L2Correction[etabin]->SetParameter(2,0.);
171 L2Correction[etabin]->SetParameter(3,0.);
172 L2Correction[etabin]->SetParameter(4,0.);
173 L2Correction[etabin]->SetParameter(5,0.);
174 g_L2Correction[etabin]->Fit(name,
"RQ");
175 std::cout<<name<<
" fitted....."<<std::endl;
178 L2File.open(L2CorrectionTxtFilename.c_str());
179 L2File.setf(ios::right);
180 for(etabin=0;etabin<
NETA;etabin++)
183 L2_cor[i] = L2Correction[etabin]->GetParameter(i);
184 L2File << setw(11) << eta_vec[etabin]
185 << setw(11) << eta_vec[etabin+1]
186 << setw(11) << (int)8
187 << setw(12) << MinCaloPt[etabin]
188 << setw(12) << MaxCaloPt[etabin]
189 << setw(13) << L2_cor[0]
190 << setw(13) << L2_cor[1]
191 << setw(13) << L2_cor[2]
192 << setw(13) << L2_cor[3]
193 << setw(13) << L2_cor[4]
194 << setw(13) << L2_cor[5]
198 std::cout<<L2CorrectionTxtFilename<<
" written...."<<std::endl;
199 outf =
new TFile(L2OutputROOTFilename.c_str(),
"RECREATE");
200 for(etabin=0;etabin<
NETA;etabin++)
202 sprintf(name,
"Correction_EtaBin%d",etabin);
203 g_EtaCorrection[etabin]->Write(name);
204 sprintf(name,
"L2Correction_EtaBin%d",etabin);
205 g_L2Correction[etabin]->Write(name);
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::vector< T > getVector(const std::string &name)
T getValue(const std::string &name)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
bool parse(int argc, char **argv)
bool HistoExists(std::vector< std::string > LIST, std::string hname)