1#include "GaudiKernel/MsgStream.h"
12#include "DedxCalibAlg/DedxCalibTzero.h"
20 declareProperty(
"Debug", m_debug=
false);
25 MsgStream log(
msgSvc(), name());
26 log<<MSG::INFO<<
"DedxCalibTzero::BookHists()"<<endreq;
39 hlabel<<
"dEdx_tzero"<<i;
42 hlabel<<
"pos_dEdx_tzero"<<i;
45 hlabel<<
"neg_dEdx_tzero"<<i;
48 hlabel<<
"chi_tzero"<<i;
51 hlabel<<
"pos_chi_tzero"<<i;
54 hlabel<<
"neg_chi_tzero"<<i;
58 hlabel<<
"dEdxVsTzero";
60 m_dEdxVsTzero->GetXaxis()->SetTitle(
"t0");
61 m_dEdxVsTzero->GetYaxis()->SetTitle(
"dE/dx");
63 hlabel<<
"pos_dEdxVsTzero";
65 m_pos_dEdxVsTzero->GetXaxis()->SetTitle(
"pos t0");
66 m_pos_dEdxVsTzero->GetYaxis()->SetTitle(
"dE/dx");
68 hlabel<<
"neg_dEdxVsTzero";
70 m_neg_dEdxVsTzero->GetXaxis()->SetTitle(
"neg t0");
71 m_neg_dEdxVsTzero->GetYaxis()->SetTitle(
"dE/dx");
79 MsgStream log(
msgSvc(), name());
80 log<<MSG::INFO<<
"DedxCalibTzero::FillHists()"<<endreq;
87 double dEdx[100]={0},pathlength[100]={0},wid[100]={0},layid[100]={0},dd_in[100]={0},eangle[100]={0},zhit[100]={0}, tzero_bin_low[
NumBinCalT0]={0}, tzero_bin_high[
NumBinCalT0]={0};
92 tzero_bin_low[i] = (i==0) ? 0 : (tzero_bin_value[i-1] + tzero_bin_value[i])/2;
93 tzero_bin_high[i] = (i==
NumBinCalT0-1) ?
TzeroMax : (tzero_bin_value[i] + tzero_bin_value[i+1])/2;
95 vector<double> phlist;
100 f =
new TFile(runlist.c_str());
101 n103 = (TTree*)
f->Get(
"n103");
120 for(
int j=0;j<n103->GetEntries();j++)
126 for(
int k=0;k<ndedxhit;k++)
128 dEdx[k] =
exsvc->
StandardHitCorrec(0,runFlag,2,runNO,evtNO,pathlength[k],wid[k],layid[k],dEdx[k],dd_in[k],eangle[k],
costheta);
129 phlist.push_back(dEdx[k]);
133 for(;iTes<
NumBinCalT0;iTes++)
if(tes>tzero_bin_low[iTes] && tes<=tzero_bin_high[iTes])
break;
134 if(m_debug && i<10 && j<100) cout <<
"t0 " << tes <<
" iTes " << iTes <<
" dedx " << dedx << endl;
138 m_tzero[iTes]->Fill(dedx);
139 m_dEdxVsTzero->Fill(tes,dedx);
140 if(
charge>0){ m_pos_tzero[iTes]->Fill(dedx); m_pos_dEdxVsTzero->Fill(tes,dedx); }
141 if(
charge<0){ m_neg_tzero[iTes]->Fill(dedx); m_neg_dEdxVsTzero->Fill(tes,dedx); }
147 m_chi[iTes]->Fill(chi);
148 if(
charge>0) m_pos_chi[iTes]->Fill(chi);
149 if(
charge<0) m_neg_chi[iTes]->Fill(chi);
151 Vec_dedx.push_back(dedx);
152 Vec_tzero.push_back(tes);
159 MsgStream log(
msgSvc(), name());
160 log<<MSG::INFO<<
"DedxCalibTzero::AnalyseHists()"<<endreq;
162 gStyle->SetOptFit(1111);
164 if(m_debug) cout <<
"num of bin " << i << endl;
165 if(m_tzero[i]->Integral()>
numcut) m_tzero[i]->Fit(
"gaus",
"Q" );
166 if(m_pos_tzero[i]->Integral()>
numcut) m_pos_tzero[i]->Fit(
"gaus",
"Q" );
167 if(m_neg_tzero[i]->Integral()>
numcut) m_neg_tzero[i]->Fit(
"gaus",
"Q" );
168 if(m_chi[i]->Integral()>
numcut) m_chi[i]->Fit(
"gaus",
"Q" );
169 if(m_pos_chi[i]->Integral()>
numcut) m_pos_chi[i]->Fit(
"gaus",
"Q" );
170 if(m_neg_chi[i]->Integral()>
numcut) m_neg_chi[i]->Fit(
"gaus",
"Q" );
176 MsgStream log(
msgSvc(), name());
177 log<<MSG::INFO<<
"DedxCalibTzero::WriteHists()"<<endreq;
184 double avegain(550.);
187 t0[i] = tzero_bin_value[i];
188 fitentryNo[i] = m_tzero[i]->Integral();
189 if(m_debug) cout <<
"num of bin " << i <<
" with events " << fitentryNo[i] << endl;
190 if(fitentryNo[i]<=
numcut)
continue;
191 if(m_debug) cout <<
"get results at " << i <<
" bin with fit entries " << fitentryNo[i] << endl;
192 if(m_tzero[i]->GetFunction(
"gaus")){
193 fitmean[i] = m_tzero[i]->GetFunction(
"gaus")->GetParameter(1);
194 fitmeanerr[i] = m_tzero[i]->GetFunction(
"gaus")->GetParError(1);
195 fitsigma[i] = m_tzero[i]->GetFunction(
"gaus")->GetParameter(2);
196 gain[i] = fitmean[i]/avegain;
198 fitchisq[i] = (m_tzero[i]->GetFunction(
"gaus")->GetChisquare())/(m_tzero[i]->GetFunction(
"gaus")->GetNDF());
200 pos_fitentryNo[i] = m_pos_tzero[i]->Integral();
201 if(pos_fitentryNo[i]<=
numcut)
continue;
202 if(m_debug) cout <<
"get results at " << i <<
" bin with pos_fit entries " << pos_fitentryNo[i] << endl;
203 if(m_pos_tzero[i]->GetFunction(
"gaus")){
204 pos_fitmean[i] = m_pos_tzero[i]->GetFunction(
"gaus")->GetParameter(1);
205 pos_fitmeanerr[i] = m_pos_tzero[i]->GetFunction(
"gaus")->GetParError(1);
206 pos_fitsigma[i] = m_pos_tzero[i]->GetFunction(
"gaus")->GetParameter(2);
207 pos_gain[i] = pos_fitmean[i]/avegain;
208 pos_fitchisq[i] = (m_pos_tzero[i]->GetFunction(
"gaus")->GetChisquare())/(m_pos_tzero[i]->GetFunction(
"gaus")->GetNDF());
210 neg_fitentryNo[i] = m_neg_tzero[i]->Integral();
211 if(neg_fitentryNo[i]<=
numcut)
continue;
212 if(m_debug) cout <<
"get results at " << i <<
" bin with neg_fit entries " << neg_fitentryNo[i] << endl;
213 if(m_neg_tzero[i]->GetFunction(
"gaus")){
214 neg_fitmean[i] = m_neg_tzero[i]->GetFunction(
"gaus")->GetParameter(1);
215 neg_fitmeanerr[i] = m_neg_tzero[i]->GetFunction(
"gaus")->GetParError(1);
216 neg_fitsigma[i] = m_neg_tzero[i]->GetFunction(
"gaus")->GetParameter(2);
217 neg_gain[i] = neg_fitmean[i]/avegain;
218 neg_fitchisq[i] = (m_neg_tzero[i]->GetFunction(
"gaus")->GetChisquare())/(m_neg_tzero[i]->GetFunction(
"gaus")->GetNDF());
222 log<<MSG::INFO<<
"begin generating root file!!! "<<endreq;
223 TFile*
f =
new TFile(
m_rootfile.c_str(),
"RECREATE");
226 m_pos_chi[i]->Write();
227 m_neg_chi[i]->Write();
229 m_pos_tzero[i]->Write();
230 m_neg_tzero[i]->Write();
232 m_dEdxVsTzero->Write();
233 m_pos_dEdxVsTzero->Write();
234 m_neg_dEdxVsTzero->Write();
236 TTree *tzerocalib =
new TTree(
"gaincalib",
"gaincalib");
237 tzerocalib->Branch(
"gain", &avegain,
"gain/D");
238 tzerocalib->Branch(
"t0", t0,
"t0[35]/D");
239 tzerocalib->Branch(
"dedx", gain,
"dedx[35]/D");
240 tzerocalib->Branch(
"fakededx", fakegain,
"fakededx[35]/D");
241 tzerocalib->Branch(
"fitmean", fitmean,
"fitmean[35]/D");
242 tzerocalib->Branch(
"fitmeanerr", fitmeanerr,
"fitmeanerr[35]/D");
243 tzerocalib->Branch(
"fitsigma", fitsigma,
"fitsigma[35]/D");
244 tzerocalib->Branch(
"fitchisq", fitchisq,
"fitchisq[35]/D");
248 TCanvas c1(
"c1",
"canvas", 500, 400);
250 tzerocalib->Draw(
"dedx:t0");
254 m_dEdxVsTzero->Draw();
256 m_pos_dEdxVsTzero->Draw();
258 m_neg_dEdxVsTzero->Draw();
265 m_pos_tzero[i]->Draw();
269 m_neg_tzero[i]->Draw();
273 if(m_debug) cout <<
"before delete" << endl;
279 delete m_pos_tzero[i];
280 delete m_neg_tzero[i];
282 delete m_dEdxVsTzero;
283 delete m_pos_dEdxVsTzero;
284 delete m_neg_dEdxVsTzero;
data SetBranchAddress("time",&time)
DedxCalibTzero(const std::string &name, ISvcLocator *pSvcLocator)
void set_dEdx(int landau, float dEdx, int trkalg, int runflag, int dedxhit_use, float ptrk, float theta, float pl_rp, int vflag[3], double t0)
vector< string > m_recFileVector
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
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")