1#include "GaudiKernel/MsgStream.h"
12#include "DedxCalibAlg/DedxCalibEAng.h"
22 MsgStream log(
msgSvc(), name());
23 log<<MSG::INFO<<
"DedxCalibEAng::BookHists()"<<endreq;
34 hlabel<<
"dEdx"<<
"_eang"<<i;
37 hlabel<<
"pos_dEdx"<<
"_eang"<<i;
40 hlabel<<
"neg_dEdx"<<
"_eang"<<i;
47 hlabel<<
"pos_dEdxVsEAng";
50 hlabel<<
"neg_dEdxVsEAng";
57 MsgStream log(
msgSvc(), name());
58 log<<MSG::INFO<<
"DedxCalibEAng::FillHists()"<<endreq;
65 float runNO=0,runFlag=0,pathlength=0,wid=0,layid=0,dd_in=0,driftdist=0,eangle=0,zhit=0,costheta=0,tes=0,ptrk=0,charge=0;
70 cout<<
"runlist: "<<runlist.c_str()<<endl;
71 f =
new TFile(runlist.c_str());
72 n102 = (TTree*)
f->Get(
"n102");
85 n102->SetBranchAddress(
"ptrk1",&ptrk);
86 n102->SetBranchAddress(
"charge",&charge);
88 for(
int j=0;j<n102->GetEntries();j++)
91 if(eangle >0.25) eangle = eangle -0.5;
92 else if(eangle <-0.25) eangle = eangle +0.5;
95 if(tes>1400)
continue;
96 if (ptrk<0.1)
continue;
97 if(layid <4)
continue;
104 dedx =
exsvc->
StandardHitCorrec(0,runFlag,2,runNO,pathlength,wid,layid,dedx,dd_in,eangle,costheta);
106 m_eangle[iEAng]->Fill(dedx);
107 if(charge>0) m_pos_eangle[iEAng]->Fill(dedx);
108 if(charge<0) m_neg_eangle[iEAng]->Fill(dedx);
116 MsgStream log(
msgSvc(), name());
117 log<<MSG::INFO<<
"DedxCalibEAng::AnalyseHists()"<<endreq;
120 Double_t entry=0,mean=0,rms=0;
123 gStyle->SetOptFit(1111);
126 entry = m_eangle[ip]->Integral();
127 if(entry<10)
continue;
128 mean = m_eangle[ip]->GetMean();
129 rms = m_eangle[ip]->GetRMS();
130 binmax = m_eangle[ip]->GetMaximumBin();
131 lp[1] = m_eangle[ip]->GetBinCenter(binmax);
133 lp[0] = (m_eangle[ip]->GetBinContent(binmax)+m_eangle[ip]->GetBinContent(binmax-1)+m_eangle[ip]->GetBinContent(binmax+1))/3;
137 func =
new TF1(
"mylan",
mylan,10,3000,4);
138 func->SetParLimits(0, 0, entry);
139 func->SetParLimits(1, 0, mean);
140 func->SetParLimits(2, 10, rms);
141 func->SetParLimits(3, -1, 0);
142 func->SetParameters(entry/36., mean-200, rms/2.3, -0.5);
146 func =
new TF1(
"landaun",
landaun,10,3000,3);
147 func->SetParameters(lp[0], lp[1], lp[2] );
151 func =
new TF1(
"Landau",
Landau,10,3000,2);
152 func->SetParameters(0.7*mean, rms );
156 func =
new TF1(
"Vavilov",
Vavilov,10,3000,2);
157 func->SetParameters(0.05, 0.6);
161 func =
new TF1(
"AsymGauss",
AsymGauss,10,3000,4);
162 func->SetParameters(entry, mean, rms, 1.0 );
164 func->SetLineWidth(2.1);
165 func->SetLineColor(2);
167 m_eangle[ip]->Fit(func,
"rq" );
168 m_pos_eangle[ip]->Fit(func,
"rq");
169 m_neg_eangle[ip]->Fit(func,
"rq");
175 MsgStream log(
msgSvc(), name());
176 log<<MSG::INFO<<
"DedxCalibEAng::WriteHists()"<<endreq;
190 entryNo[ip]= m_eangle[ip]->Integral();
191 mean[ip] = m_eangle[ip]->GetMean();
192 sigma[ip] = m_eangle[ip]->GetRMS();
193 pos_entryNo[ip]= m_pos_eangle[ip]->Integral();
194 pos_mean[ip] = m_pos_eangle[ip]->GetMean();
195 pos_sigma[ip] = m_pos_eangle[ip]->GetRMS();
196 neg_entryNo[ip]= m_neg_eangle[ip]->Integral();
197 neg_mean[ip] = m_neg_eangle[ip]->GetMean();
198 neg_sigma[ip] = m_neg_eangle[ip]->GetRMS();
199 if(entryNo[ip]<10 || pos_entryNo[ip]<10 || neg_entryNo[ip]<10)
continue;
203 fitmean[ip] = m_eangle[ip]->GetFunction(
"mylan")->GetParameter(1);
204 fitmeanerr[ip] = m_eangle[ip]->GetFunction(
"mylan")->GetParError(1);
205 fitsigma[ip] = m_eangle[ip]->GetFunction(
"mylan")->GetParameter(2);
206 chisq[ip] = (m_eangle[ip]->GetFunction(
"mylan")-> GetChisquare())/(m_eangle[ip]->GetFunction(
"mylan")-> GetNDF());
208 pos_fitmean[ip] = m_pos_eangle[ip]->GetFunction(
"mylan")->GetParameter(1);
209 pos_fitmeanerr[ip] = m_pos_eangle[ip]->GetFunction(
"mylan")->GetParError(1);
210 pos_fitsigma[ip] = m_pos_eangle[ip]->GetFunction(
"mylan")->GetParameter(2);
211 pos_chisq[ip] = (m_pos_eangle[ip]->GetFunction(
"mylan")-> GetChisquare())/(m_pos_eangle[ip]->GetFunction(
"mylan")-> GetNDF());
213 neg_fitmean[ip] = m_neg_eangle[ip]->GetFunction(
"mylan")->GetParameter(1);
214 neg_fitmeanerr[ip] = m_neg_eangle[ip]->GetFunction(
"mylan")->GetParError(1);
215 neg_fitsigma[ip] = m_neg_eangle[ip]->GetFunction(
"mylan")->GetParameter(2);
216 neg_chisq[ip] = (m_neg_eangle[ip]->GetFunction(
"mylan")-> GetChisquare())/(m_neg_eangle[ip]->GetFunction(
"mylan")-> GetNDF());
220 fitmean[ip] = m_eangle[ip]->GetFunction(
"landaun")->GetParameter(1);
221 fitmeanerr[ip] = m_eangle[ip]->GetFunction(
"landaun")->GetParError(1);
222 fitsigma[ip] = m_eangle[ip]->GetFunction(
"landaun")->GetParameter(2);
223 chisq[ip] = (m_eangle[ip]->GetFunction(
"landaun")-> GetChisquare())/(m_eangle[ip]->GetFunction(
"mylan")-> GetNDF());
225 pos_fitmean[ip] = m_pos_eangle[ip]->GetFunction(
"landaun")->GetParameter(1);
226 pos_fitmeanerr[ip] = m_pos_eangle[ip]->GetFunction(
"landaun")->GetParError(1);
227 pos_fitsigma[ip] = m_pos_eangle[ip]->GetFunction(
"landaun")->GetParameter(2);
228 pos_chisq[ip] = (m_pos_eangle[ip]->GetFunction(
"landaun")-> GetChisquare())/(m_pos_eangle[ip]->GetFunction(
"landaun")-> GetNDF());
230 neg_fitmean[ip] = m_neg_eangle[ip]->GetFunction(
"landaun")->GetParameter(1);
231 neg_fitmeanerr[ip] = m_neg_eangle[ip]->GetFunction(
"landaun")->GetParError(1);
232 neg_fitsigma[ip] = m_neg_eangle[ip]->GetFunction(
"landaun")->GetParameter(2);
233 neg_chisq[ip] = (m_neg_eangle[ip]->GetFunction(
"landaun")-> GetChisquare())/(m_neg_eangle[ip]->GetFunction(
"landaun")-> GetNDF());
237 fitmean[ip] = m_eangle[ip]->GetFunction(
"Landau")->GetParameter(1);
238 fitmeanerr[ip] = m_eangle[ip]->GetFunction(
"Landau")->GetParError(1);
239 fitsigma[ip] = m_eangle[ip]->GetFunction(
"Landau")->GetParameter(2);
240 chisq[ip] = (m_eangle[ip]->GetFunction(
"Landau")-> GetChisquare())/(m_eangle[ip]->GetFunction(
"Landau")-> GetNDF());
242 pos_fitmean[ip] = m_pos_eangle[ip]->GetFunction(
"Landau")->GetParameter(1);
243 pos_fitmeanerr[ip] = m_pos_eangle[ip]->GetFunction(
"Landau")->GetParError(1);
244 pos_fitsigma[ip] = m_pos_eangle[ip]->GetFunction(
"Landau")->GetParameter(2);
245 pos_chisq[ip] = (m_pos_eangle[ip]->GetFunction(
"Landau")-> GetChisquare())/(m_pos_eangle[ip]->GetFunction(
"Landau")-> GetNDF());
247 neg_fitmean[ip] = m_neg_eangle[ip]->GetFunction(
"Landau")->GetParameter(1);
248 neg_fitmeanerr[ip] = m_neg_eangle[ip]->GetFunction(
"Landau")->GetParError(1);
249 neg_fitsigma[ip] = m_neg_eangle[ip]->GetFunction(
"Landau")->GetParameter(2);
250 neg_chisq[ip] = (m_neg_eangle[ip]->GetFunction(
"Landau")-> GetChisquare())/(m_neg_eangle[ip]->GetFunction(
"Landau")-> GetNDF());
254 fitmean[ip] = m_eangle[ip]->GetFunction(
"Vavilov")->GetParameter(1);
255 fitmeanerr[ip] = m_eangle[ip]->GetFunction(
"Vavilov")->GetParError(1);
256 fitsigma[ip] = m_eangle[ip]->GetFunction(
"Vavilov")->GetParameter(2);
257 chisq[ip] = (m_eangle[ip]->GetFunction(
"Vavilov")-> GetChisquare())/(m_eangle[ip]->GetFunction(
"Vavilov")-> GetNDF());
259 pos_fitmean[ip] = m_pos_eangle[ip]->GetFunction(
"Vavilov")->GetParameter(1);
260 pos_fitmeanerr[ip] = m_pos_eangle[ip]->GetFunction(
"Vavilov")->GetParError(1);
261 pos_fitsigma[ip] = m_pos_eangle[ip]->GetFunction(
"Vavilov")->GetParameter(2);
262 pos_chisq[ip] = (m_pos_eangle[ip]->GetFunction(
"Vavilov")-> GetChisquare())/(m_pos_eangle[ip]->GetFunction(
"Vavilov")-> GetNDF());
264 neg_fitmean[ip] = m_neg_eangle[ip]->GetFunction(
"Vavilov")->GetParameter(1);
265 neg_fitmeanerr[ip] = m_neg_eangle[ip]->GetFunction(
"Vavilov")->GetParError(1);
266 neg_fitsigma[ip] = m_neg_eangle[ip]->GetFunction(
"Vavilov")->GetParameter(2);
267 neg_chisq[ip] = (m_neg_eangle[ip]->GetFunction(
"Vavilov")-> GetChisquare())/(m_neg_eangle[ip]->GetFunction(
"Vavilov")-> GetNDF());
271 fitmean[ip] = m_eangle[ip]->GetFunction(
"AsymGauss")->GetParameter(1);
272 fitmeanerr[ip] = m_eangle[ip]->GetFunction(
"AsymGauss")->GetParError(1);
273 fitsigma[ip] = m_eangle[ip]->GetFunction(
"AsymGauss")->GetParameter(2);
274 chisq[ip] = (m_eangle[ip]->GetFunction(
"AsymGauss")-> GetChisquare())/(m_eangle[ip]->GetFunction(
"AsymGauss")-> GetNDF());
276 pos_fitmean[ip] = m_pos_eangle[ip]->GetFunction(
"AsymGauss")->GetParameter(1);
277 pos_fitmeanerr[ip] = m_pos_eangle[ip]->GetFunction(
"AsymGauss")->GetParError(1);
278 pos_fitsigma[ip] = m_pos_eangle[ip]->GetFunction(
"AsymGauss")->GetParameter(2);
279 pos_chisq[ip] = (m_pos_eangle[ip]->GetFunction(
"AsymGauss")-> GetChisquare())/(m_pos_eangle[ip]->GetFunction(
"AsymGauss")-> GetNDF());
281 neg_fitmean[ip] = m_neg_eangle[ip]->GetFunction(
"AsymGauss")->GetParameter(1);
282 neg_fitmeanerr[ip] = m_neg_eangle[ip]->GetFunction(
"AsymGauss")->GetParError(1);
283 neg_fitsigma[ip] = m_neg_eangle[ip]->GetFunction(
"AsymGauss")->GetParameter(2);
284 neg_chisq[ip] = (m_neg_eangle[ip]->GetFunction(
"AsymGauss")-> GetChisquare())/(m_neg_eangle[ip]->GetFunction(
"AsymGauss")-> GetNDF());
286 if(entryNo[ip]>1500 && fitmean[ip]>0 && fitmeanerr[ip]>0 && fitmeanerr[ip]<10 && fitsigma[ip]>0 && fitsigma[ip]<200)
294 cout<<
"count= "<<
count<<
" average value of eangle bins: "<<Norm<<endl;
297 if(entryNo[i]>10 && fitmean[i]>0 && fitsigma[i]>0) gain[i]=fitmean[i]/Norm;
302 if(pos_entryNo[i]>10 && pos_fitmean[i]>0 && pos_fitsigma[i]>0) pos_gain[i]=pos_fitmean[i]/Norm;
303 else pos_gain[i] = 0;
304 if(neg_entryNo[i]>10 && neg_fitmean[i]>0 && neg_fitsigma[i]>0) neg_gain[i]=neg_fitmean[i]/Norm;
305 else neg_gain[i] = 0;
307 m_EAngAverdE -> SetBinContent(i+1, gain[i]);
308 m_EAngAverdE->SetBinError(i+1, fitmeanerr[i]/Norm);
310 if(pos_gain[i] != 0){
311 m_pos_EAngAverdE -> SetBinContent(i+1, pos_gain[i]);
312 m_pos_EAngAverdE->SetBinError(i+1, pos_fitmeanerr[i]/Norm);
314 if(neg_gain[i] != 0){
315 m_neg_EAngAverdE -> SetBinContent(i+1, neg_gain[i]);
316 m_neg_EAngAverdE->SetBinError(i+1, neg_fitmeanerr[i]/Norm);
320 log<<MSG::INFO<<
"begin getting calibration constant!!! "<<endreq;
322 int denangle_entry[1] = {100};
323 m_EAngAverdE->Fit(
"pol1",
"r",
"",-0.25,0.25);
324 double par0 = m_EAngAverdE->GetFunction(
"pol1")->GetParameter(0);
325 double par1 = m_EAngAverdE->GetFunction(
"pol1")->GetParameter(1);
329 for(
int i=0;i<
NumSlices;i++) denangle[i] = gain[i];
331 log<<MSG::INFO<<
"begin generating root file!!! "<<endreq;
332 TFile*
f =
new TFile(
m_rootfile.c_str(),
"recreate");
335 m_eangle[ip]->Write();
336 m_pos_eangle[ip]->Write();
337 m_neg_eangle[ip]->Write();
339 m_EAngAverdE->Write();
340 m_pos_EAngAverdE->Write();
341 m_neg_EAngAverdE->Write();
343 TTree* entracalib =
new TTree(
"entracalib",
"entracalib");
344 entracalib->Branch(
"1denangle", denangle,
"denangle[100]/D");
345 entracalib->Branch(
"1denangle_entry", denangle_entry,
"denangle_entry[1]/I");
347 entracalib-> Write();
349 TTree* ddgcalib =
new TTree(
"ddgcalib",
"ddgcalib");
350 ddgcalib -> Branch(
"hits", entryNo,
"entryNo[100]/D");
351 ddgcalib -> Branch(
"mean", mean,
"mean[100]/D");
352 ddgcalib -> Branch(
"sigma", sigma,
"sigma[100]/D");
353 ddgcalib -> Branch(
"fitmean", fitmean,
"fitmean[100]/D");
354 ddgcalib -> Branch(
"fitmeanerr", fitmeanerr,
"fitmeanerr[100]/D");
355 ddgcalib -> Branch(
"chi", fitsigma,
"fitsigma[100]/D");
356 ddgcalib -> Branch(
"gain", gain,
"gain[100]/D");
357 ddgcalib -> Branch(
"chisq", chisq,
"chisq[100]/D");
358 ddgcalib -> Branch(
"pos_hits", pos_entryNo,
"pos_entryNo[100]/D");
359 ddgcalib -> Branch(
"pos_mean", pos_mean,
"pos_mean[100]/D");
360 ddgcalib -> Branch(
"pos_sigma", pos_sigma,
"pos_sigma[100]/D");
361 ddgcalib -> Branch(
"pos_fitmean", pos_fitmean,
"pos_fitmean[100]/D");
362 ddgcalib -> Branch(
"pos_fitmeanerr", pos_fitmeanerr,
"pos_fitmeanerr[100]/D");
363 ddgcalib -> Branch(
"pos_chi", pos_fitsigma,
"pos_fitsigma[100]/D");
364 ddgcalib -> Branch(
"pos_gain", pos_gain,
"pos_gain[100]/D");
365 ddgcalib -> Branch(
"pos_chisq", pos_chisq,
"pos_chisq[100]/D");
366 ddgcalib -> Branch(
"neg_hits", neg_entryNo,
"neg_entryNo[100]/D");
367 ddgcalib -> Branch(
"neg_mean", neg_mean,
"neg_mean[100]/D");
368 ddgcalib -> Branch(
"neg_sigma", neg_sigma,
"neg_sigma[100]/D");
369 ddgcalib -> Branch(
"neg_fitmean", neg_fitmean,
"neg_fitmean[100]/D");
370 ddgcalib -> Branch(
"neg_fitmeanerr", neg_fitmeanerr,
"neg_fitmeanerr[100]/D");
371 ddgcalib -> Branch(
"neg_chi", neg_fitsigma,
"neg_fitsigma[100]/D");
372 ddgcalib -> Branch(
"neg_gain", neg_gain,
"neg_gain[100]/D");
373 ddgcalib -> Branch(
"neg_chisq", neg_chisq,
"neg_chisq[100]/D");
374 ddgcalib -> Branch(
"Ip_eangle", Ip_eangle,
"Ip_eangle[100]/D");
375 ddgcalib -> Branch(
"eangle", eangle,
"eangle[100]/D");
380 TCanvas c1(
"c1",
"canvas", 500, 400);
382 m_EAngAverdE->Draw();
384 m_pos_EAngAverdE->Draw();
386 m_neg_EAngAverdE->Draw();
390 m_eangle[ip]->Draw();
395 m_pos_eangle[ip]->Draw();
400 m_neg_eangle[ip]->Draw();
408 delete m_pos_eangle[ip];
409 delete m_neg_eangle[ip];
412 delete m_pos_EAngAverdE;
413 delete m_neg_EAngAverdE;
data SetBranchAddress("time",&time)
DOUBLE_PRECISION count[3]
double Landau(double *x, double *par)
double Vavilov(double *x, double *par)
#define Iner_DriftDistCut
double landaun(double *x, double *par)
double AsymGauss(double *x, double *par)
double mylan(double *x, double *par)
DedxCalibEAng(const std::string &name, ISvcLocator *pSvcLocator)
vector< string > m_recFileVector
virtual double StandardHitCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, double pathl, int wid, int layid, double adc, double dd, double eangle, double costheta) const =0
virtual double StandardTrackCorrec(int calib_rec_Flag, int typFlag, int ntpFlag, int runNO, double ex, double costheta, double t0) const =0
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")