58 MsgStream log(
msgSvc(), name() );
59 log << MSG::INFO <<
"DedxCalibLayerGain::FillHists()" << endmsg;
66 float runNO = 0, evtNO = 0, runFlag = 0, pathlength = 0, wid = 0, layid = 0, dd_in = 0,
67 driftdist = 0, eangle = 0, zhit = 0, costheta = 0, tes = 0, ptrk = 0;
72 cout <<
"runlist: " << runlist.c_str() << endl;
73 f =
new TFile( runlist.c_str() );
74 n102 = (TTree*)
f->Get(
"n102" );
75 n102->SetBranchAddress(
"adc_raw", &dedx );
76 n102->SetBranchAddress(
"path_rphi", &pathlength );
77 n102->SetBranchAddress(
"wire", &wid );
78 n102->SetBranchAddress(
"layer", &layid );
79 n102->SetBranchAddress(
"doca_in", &dd_in );
80 n102->SetBranchAddress(
"driftdist", &driftdist );
81 n102->SetBranchAddress(
"eangle", &eangle );
82 n102->SetBranchAddress(
"zhit", &zhit );
83 n102->SetBranchAddress(
"runNO", &runNO );
84 n102->SetBranchAddress(
"evtNO", &evtNO );
85 n102->SetBranchAddress(
"runFlag", &runFlag );
86 n102->SetBranchAddress(
"costheta1", &costheta );
87 n102->SetBranchAddress(
"t01", &tes );
88 n102->SetBranchAddress(
"ptrk1", &ptrk );
90 for (
int j = 0; j < n102->GetEntries(); j++ )
93 if ( tes > 1400 )
continue;
94 if ( ptrk < 0.1 )
continue;
108 dedx =
exsvc->StandardHitCorrec( 0, runFlag, 2, runNO, evtNO, pathlength, wid, layid,
109 dedx, dd_in, eangle, costheta );
110 dedx =
exsvc->StandardTrackCorrec( 0, runFlag, 2, runNO, evtNO, dedx, costheta, tes );
111 m_laygain[(int)layid]->Fill( dedx );
113 m_vector[(int)layid].push_back( dedx );
119 MsgStream log(
msgSvc(), name() );
120 log << MSG::INFO <<
"DedxCalibLayerGain::AnalyseHists()" << endmsg;
123 Double_t entry = 0, mean = 0, rms = 0;
125 Double_t lp[3] = { 0 };
126 gStyle->SetOptFit( 1111 );
130 vector<double> phlist;
131 vector<double> phlist_gaus;
132 for (
int i = 0; i <
layNo; i++ )
134 entry = m_laygain[i]->GetEntries();
135 if ( entry < 10 )
continue;
136 mean = m_laygain[i]->GetMean();
137 rms = m_laygain[i]->GetRMS();
138 binmax = m_laygain[i]->GetMaximumBin();
139 lp[1] = m_laygain[i]->GetBinCenter( binmax );
142 ( m_laygain[i]->GetBinContent( binmax ) + m_laygain[i]->GetBinContent( binmax - 1 ) +
143 m_laygain[i]->GetBinContent( binmax + 1 ) ) /
148 func =
new TF1(
"mylan",
mylan, 10, 3000, 4 );
149 func->SetParameters( entry, mean, rms, -0.9 );
153 func =
new TF1(
"landaun",
landaun, 10, 3000, 3 );
154 func->SetParameters( lp[0], lp[1], lp[2] );
158 func =
new TF1(
"Landau",
Landau, 10, 3000, 2 );
159 func->SetParameters( 0.7 * mean, rms );
163 func =
new TF1(
"Vavilov",
Vavilov, 10, 3000, 2 );
164 func->SetParameters( 0.05, 0.6 );
168 func =
new TF1(
"AsymGauss",
AsymGauss, 10, 3000, 4 );
169 func->SetParameters( entry, mean, rms, 1.0 );
171 func->SetLineWidth( 2.1 );
172 func->SetLineColor( 2 );
174 m_laygain[i]->Fit( func,
"r" );
177 for (
int j = 0; j < m_vector[i].size(); j += 100 )
179 for (
int k = 0; k < 100; k++ ) phlist.push_back( m_vector[i][j + k] );
181 phlist_gaus.push_back( dedxt );
186 hlabel <<
"dEdx_gaus_Lay_" << i;
189 m_laygain_gaus[i] =
new TH1F( hlabel.str().c_str(), hlabel.str().c_str(),
NumHistBins,
191 for (
int j = 0; j < phlist_gaus.size(); j++ ) m_laygain_gaus[i]->Fill( phlist_gaus[j] );
193 m_laygain_gaus[i]->Fit(
"gaus",
"Q" );
198 MsgStream log(
msgSvc(), name() );
199 log << MSG::INFO <<
"DedxCalibLayerGain::WriteHists()" << endmsg;
201 double entryNo[
layNo] = { 0 }, mean[
layNo] = { 0 }, sigma[
layNo] = { 0 },
202 proper[
layNo] = { 0 }, fitmean[
layNo] = { 0 }, fitmeanerr[
layNo] = { 0 },
204 chisq[
layNo] = { 0 };
205 double fitmean_gaus[
layNo] = { 0 }, fitmeanerr_gaus[
layNo] = { 0 },
206 fitsigma_gaus[
layNo] = { 0 }, layerg_gaus[
layNo] = { 0 };
207 for (
int i = 0; i <
layNo; i++ )
209 fitmean_gaus[i] = m_laygain_gaus[i]->GetFunction(
"gaus" )->GetParameter( 1 );
210 fitmeanerr_gaus[i] = m_laygain_gaus[i]->GetFunction(
"gaus" )->GetParError( 1 );
211 fitsigma_gaus[i] = m_laygain_gaus[i]->GetFunction(
"gaus" )->GetParameter( 2 );
213 entryNo[i] = m_laygain[i]->GetEntries();
214 mean[i] = m_laygain[i]->GetMean();
215 sigma[i] = m_laygain[i]->GetRMS();
216 proper[i] = m_laygain[i]->GetBinCenter( m_laygain[i]->GetMaximumBin() );
217 if ( entryNo[i] < 10 )
continue;
221 fitmean[i] = m_laygain[i]->GetFunction(
"mylan" )->GetParameter( 1 );
222 fitmeanerr[i] = m_laygain[i]->GetFunction(
"mylan" )->GetParError( 1 );
223 fitsigma[i] = m_laygain[i]->GetFunction(
"mylan" )->GetParameter( 2 );
224 chisq[i] = ( m_laygain[i]->GetFunction(
"mylan" )->GetChisquare() ) /
225 ( m_laygain[i]->GetFunction(
"mylan" )->GetNDF() );
229 fitmean[i] = m_laygain[i]->GetFunction(
"landaun" )->GetParameter( 1 );
230 fitmeanerr[i] = m_laygain[i]->GetFunction(
"landaun" )->GetParError( 1 );
231 fitsigma[i] = m_laygain[i]->GetFunction(
"landaun" )->GetParameter( 2 );
232 chisq[i] = ( m_laygain[i]->GetFunction(
"landaun" )->GetChisquare() ) /
233 ( m_laygain[i]->GetFunction(
"landaun" )->GetNDF() );
237 fitmean[i] = m_laygain[i]->GetFunction(
"Landau" )->GetParameter( 1 );
238 fitmeanerr[i] = m_laygain[i]->GetFunction(
"Landau" )->GetParError( 1 );
239 fitsigma[i] = m_laygain[i]->GetFunction(
"Landau" )->GetParameter( 2 );
240 chisq[i] = ( m_laygain[i]->GetFunction(
"Landau" )->GetChisquare() ) /
241 ( m_laygain[i]->GetFunction(
"Landau" )->GetNDF() );
245 fitmean[i] = m_laygain[i]->GetFunction(
"Vavilov" )->GetParameter( 1 );
246 fitmeanerr[i] = m_laygain[i]->GetFunction(
"Vavilov" )->GetParError( 1 );
247 fitsigma[i] = m_laygain[i]->GetFunction(
"Vavilov" )->GetParameter( 2 );
248 chisq[i] = ( m_laygain[i]->GetFunction(
"Vavilov" )->GetChisquare() ) /
249 ( m_laygain[i]->GetFunction(
"Vavilov" )->GetNDF() );
253 fitmean[i] = m_laygain[i]->GetFunction(
"AsymGauss" )->GetParameter( 1 );
254 fitmeanerr[i] = m_laygain[i]->GetFunction(
"AsymGauss" )->GetParError( 1 );
255 fitsigma[i] = m_laygain[i]->GetFunction(
"AsymGauss" )->GetParameter( 2 );
256 chisq[i] = ( m_laygain[i]->GetFunction(
"AsymGauss" )->GetChisquare() ) /
257 ( m_laygain[i]->GetFunction(
"AsymGauss" )->GetNDF() );
263 double sum = 0, sum_gaus = 0,
n = 0;
264 for (
int i = 4; i <
layNo; i++ )
266 if ( fitmean[i] > 0 && fitmeanerr[i] > 0 && fitmeanerr[i] < 10 && fitsigma[i] > 0 &&
267 fitsigma[i] < 200 && entryNo[i] > 1500 )
270 sum_gaus += fitmean_gaus[i];
276 cout <<
"average value of good layer: " << sum << endl;
278 for (
int i = 0; i <
layNo; i++ )
280 layerg[i] = fitmean[i] / sum;
281 layerg_gaus[i] = fitmean_gaus[i] / sum_gaus;
285 log << MSG::INFO <<
"begin generating root file!!! " << endmsg;
286 TFile*
f =
new TFile(
m_rootfile.c_str(),
"recreate" );
287 for (
int i = 0; i <
layNo; i++ )
289 m_laygain[i]->Write();
290 m_laygain_gaus[i]->Write();
293 TTree* layergcalib =
new TTree(
"layergcalib",
"layergcalib" );
294 layergcalib->Branch(
"layerg_gaus", layerg_gaus,
"layerg_gaus[43]/D" );
295 layergcalib->Branch(
"layerg", layerg,
"layerg[43]/D" );
296 layergcalib->Branch(
"layer", layer,
"layer[43]/D" );
297 layergcalib->Branch(
"entryNo", entryNo,
"entryNo[43]/D" );
298 layergcalib->Branch(
"mean", mean,
"mean[43]/D" );
299 layergcalib->Branch(
"sigma", sigma,
"sigma[43]/D" );
300 layergcalib->Branch(
"fitmean", fitmean,
"fitmean[43]/D" );
301 layergcalib->Branch(
"fitmeanerr", fitmeanerr,
"fitmeanerr[43]/D" );
302 layergcalib->Branch(
"fitsigma", fitsigma,
"fitsigma[43]/D" );
303 layergcalib->Branch(
"chisq", chisq,
"chisq[43]/D" );
304 layergcalib->Branch(
"fitmean_gaus", fitmean_gaus,
"fitmean_gaus[43]/D" );
305 layergcalib->Branch(
"fitmeanerr_gaus", fitmeanerr_gaus,
"fitmeanerr_gaus[43]/D" );
306 layergcalib->Branch(
"fitsigma_gaus", fitsigma_gaus,
"fitsigma_gaus[43]/D" );
308 layergcalib->Write();
312 TCanvas c1(
"c1",
"canvas", 500, 400 );
314 for (
int i = 0; i <
layNo; i++ )
316 m_laygain[i]->Draw();
321 for (
int i = 0; i <
layNo; i++ )
324 delete m_laygain_gaus[i];