1#include "GaudiKernel/MsgStream.h"
23 for(
int i=0;i<phlist.size();i++)
28 for(
int i=0;i<phlist.size();i++)
30 rms += pow((phlist[i]-mean),2);
33 rms = sqrt(rms/phlist.size());
43 MsgStream log(
msgSvc(), name());
44 log<<MSG::INFO<<
"DedxCalibLayerGain::BookHists()"<<endreq;
48 m_laygain =
new TH1F*[
layNo];
49 m_laygain_gaus =
new TH1F*[
layNo];
51 for(
int i=0; i<
layNo; i++)
54 hlabel<<
"dEdx_Lay_"<<i;
57 hlabel<<
"dEdx_gaus_Lay_"<<i;
64 MsgStream log(
msgSvc(), name());
65 log<<MSG::INFO<<
"DedxCalibLayerGain::FillHists()"<<endreq;
72 float runNO=0,evtNO=0,runFlag=0,pathlength=0,wid=0,layid=0,dd_in=0,driftdist=0,eangle=0,zhit=0,
costheta=0,tes=0,
ptrk=0;
77 cout<<
"runlist: "<<runlist.c_str()<<endl;
78 f =
new TFile(runlist.c_str());
79 n102 = (TTree*)
f->Get(
"n102");
93 n102->SetBranchAddress(
"ptrk1",&
ptrk);
95 for(
int j=0;j<n102->GetEntries();j++)
98 if(tes>1400)
continue;
99 if (
ptrk<0.1)
continue;
105 dedx =
exsvc->
StandardHitCorrec(0,runFlag,2,runNO,evtNO,pathlength,wid,layid,dedx,dd_in,eangle,
costheta);
107 m_laygain[(int)layid]->
Fill(dedx);
109 m_vector[(int)layid].push_back(dedx);
117 MsgStream log(
msgSvc(), name());
118 log<<MSG::INFO<<
"DedxCalibLayerGain::AnalyseHists()"<<endreq;
121 Double_t entry=0,mean=0,rms=0;
124 gStyle->SetOptFit(1111);
128 vector<double> phlist;
129 vector<double> phlist_gaus;
130 for(
int i=0; i<
layNo; i++)
132 entry = m_laygain[i]->GetEntries();
133 if(entry<10)
continue;
134 mean = m_laygain[i]->GetMean();
135 rms = m_laygain[i]->GetRMS();
136 binmax = m_laygain[i]->GetMaximumBin();
137 lp[1] = m_laygain[i]->GetBinCenter(binmax);
139 lp[0] = (m_laygain[i]->GetBinContent(binmax)+m_laygain[i]->GetBinContent(binmax-1)+m_laygain[i]->GetBinContent(binmax+1))/3;
143 func =
new TF1(
"mylan",
mylan,10,3000,4);
144 func->SetParameters(entry, mean, rms, -0.9);
148 func =
new TF1(
"landaun",
landaun,10,3000,3);
149 func->SetParameters(lp[0], lp[1], lp[2] );
153 func =
new TF1(
"Landau",
Landau,10,3000,2);
154 func->SetParameters(0.7*mean, rms );
158 func =
new TF1(
"Vavilov",
Vavilov,10,3000,2);
159 func->SetParameters(0.05, 0.6);
163 func =
new TF1(
"AsymGauss",
AsymGauss,10,3000,4);
164 func->SetParameters(entry, mean, rms, 1.0 );
166 func->SetLineWidth(2.1);
167 func->SetLineColor(2);
169 m_laygain[i]->Fit(func,
"r" );
173 for(
int j=0;j<m_vector[i].size();j+=100)
175 for(
int k=0;k<100;k++) phlist.push_back(m_vector[i][j+k]);
177 phlist_gaus.push_back(dedxt);
182 hlabel<<
"dEdx_gaus_Lay_"<<i;
186 for(
int j=0;j<phlist_gaus.size();j++) m_laygain_gaus[i]->
Fill(phlist_gaus[j]);
188 m_laygain_gaus[i]->Fit(
"gaus",
"Q");
196 MsgStream log(
msgSvc(), name());
197 log<<MSG::INFO<<
"DedxCalibLayerGain::WriteHists()"<<endreq;
201 double fitmean_gaus[
layNo]={0},fitmeanerr_gaus[
layNo]={0},fitsigma_gaus[
layNo]={0},layerg_gaus[
layNo]={0};
202 for(
int i=0; i<
layNo; i++)
204 fitmean_gaus[i] = m_laygain_gaus[i]->GetFunction(
"gaus")->GetParameter(1);
205 fitmeanerr_gaus[i] = m_laygain_gaus[i]->GetFunction(
"gaus")->GetParError(1);
206 fitsigma_gaus[i] = m_laygain_gaus[i]->GetFunction(
"gaus")->GetParameter(2);
208 entryNo[i] = m_laygain[i]->GetEntries();
209 mean[i] = m_laygain[i]->GetMean();
210 sigma[i] = m_laygain[i]->GetRMS();
211 proper[i] = m_laygain[i]->GetBinCenter(m_laygain[i]->GetMaximumBin());
212 if(entryNo[i]<10)
continue;
216 fitmean[i] = m_laygain[i]->GetFunction(
"mylan")->GetParameter(1);
217 fitmeanerr[i] = m_laygain[i]->GetFunction(
"mylan")->GetParError(1);
218 fitsigma[i] = m_laygain[i]->GetFunction(
"mylan")->GetParameter(2);
219 chisq[i] = (m_laygain[i]->GetFunction(
"mylan")-> GetChisquare())/(m_laygain[i]->GetFunction(
"mylan")-> GetNDF());
223 fitmean[i] = m_laygain[i]->GetFunction(
"landaun")->GetParameter(1);
224 fitmeanerr[i] = m_laygain[i]->GetFunction(
"landaun")->GetParError(1);
225 fitsigma[i] = m_laygain[i]->GetFunction(
"landaun")->GetParameter(2);
226 chisq[i] = (m_laygain[i]->GetFunction(
"landaun")-> GetChisquare())/(m_laygain[i]->GetFunction(
"landaun")-> GetNDF());
230 fitmean[i] = m_laygain[i]->GetFunction(
"Landau")->GetParameter(1);
231 fitmeanerr[i] = m_laygain[i]->GetFunction(
"Landau")->GetParError(1);
232 fitsigma[i] = m_laygain[i]->GetFunction(
"Landau")->GetParameter(2);
233 chisq[i] = (m_laygain[i]->GetFunction(
"Landau")-> GetChisquare())/(m_laygain[i]->GetFunction(
"Landau")-> GetNDF());
237 fitmean[i] = m_laygain[i]->GetFunction(
"Vavilov")->GetParameter(1);
238 fitmeanerr[i] = m_laygain[i]->GetFunction(
"Vavilov")->GetParError(1);
239 fitsigma[i] = m_laygain[i]->GetFunction(
"Vavilov")->GetParameter(2);
240 chisq[i] = (m_laygain[i]->GetFunction(
"Vavilov")-> GetChisquare())/(m_laygain[i]->GetFunction(
"Vavilov")-> GetNDF());
244 fitmean[i] = m_laygain[i]->GetFunction(
"AsymGauss")->GetParameter(1);
245 fitmeanerr[i] = m_laygain[i]->GetFunction(
"AsymGauss")->GetParError(1);
246 fitsigma[i] = m_laygain[i]->GetFunction(
"AsymGauss")->GetParameter(2);
247 chisq[i] = (m_laygain[i]->GetFunction(
"AsymGauss")-> GetChisquare())/(m_laygain[i]->GetFunction(
"AsymGauss")-> GetNDF());
252 double sum=0, sum_gaus=0, n=0;
253 for(
int i=4; i<
layNo; i++)
255 if(fitmean[i]>0 && fitmeanerr[i]>0 && fitmeanerr[i]<10 && fitsigma[i]>0 && fitsigma[i]<200 && entryNo[i]>1500)
258 sum_gaus+= fitmean_gaus[i];
264 cout<<
"average value of good layer: "<<sum<<endl;
266 for(
int i=0;i<
layNo;i++)
268 layerg[i] = fitmean[i]/sum;
269 layerg_gaus[i] = fitmean_gaus[i]/sum_gaus;
274 log<<MSG::INFO<<
"begin generating root file!!! "<<endreq;
275 TFile*
f =
new TFile(
m_rootfile.c_str(),
"recreate");
276 for(
int i=0;i<
layNo;i++)
278 m_laygain[i]->Write();
279 m_laygain_gaus[i]->Write();
282 TTree* layergcalib =
new TTree(
"layergcalib",
"layergcalib");
283 layergcalib->Branch(
"layerg_gaus", layerg_gaus,
"layerg_gaus[43]/D");
284 layergcalib->Branch(
"layerg", layerg,
"layerg[43]/D");
285 layergcalib->Branch(
"layer", layer,
"layer[43]/D");
286 layergcalib->Branch(
"entryNo", entryNo,
"entryNo[43]/D");
287 layergcalib->Branch(
"mean", mean,
"mean[43]/D");
288 layergcalib->Branch(
"sigma",
sigma,
"sigma[43]/D");
289 layergcalib->Branch(
"fitmean", fitmean,
"fitmean[43]/D");
290 layergcalib->Branch(
"fitmeanerr", fitmeanerr,
"fitmeanerr[43]/D");
291 layergcalib->Branch(
"fitsigma", fitsigma,
"fitsigma[43]/D");
292 layergcalib->Branch(
"chisq", chisq,
"chisq[43]/D");
293 layergcalib->Branch(
"fitmean_gaus", fitmean_gaus,
"fitmean_gaus[43]/D");
294 layergcalib->Branch(
"fitmeanerr_gaus", fitmeanerr_gaus,
"fitmeanerr_gaus[43]/D");
295 layergcalib->Branch(
"fitsigma_gaus", fitsigma_gaus,
"fitsigma_gaus[43]/D");
297 layergcalib->Write();
301 TCanvas c1(
"c1",
"canvas", 500, 400);
303 for(
int i=0;i<
layNo;i++)
305 m_laygain[i]->Draw();
310 for(
int i=0;i<
layNo;i++)
313 delete m_laygain_gaus[i];
void calculate(vector< double > phlist)
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)
DedxCalibLayerGain(const std::string &name, ISvcLocator *pSvcLocator)
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
vector< string > m_recFileVector
virtual double StandardHitCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, int evtNO, 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, int evtNO, double ex, double costheta, double t0) const =0
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
curve SetBranchAddress("CurveSize",&CurveSize)