BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalibTzero Class Reference

#include <DedxCalibTzero.h>

Inheritance diagram for DedxCalibTzero:

Public Member Functions

 DedxCalibTzero (const std::string &name, ISvcLocator *pSvcLocator)
 ~DedxCalibTzero ()
void initializing ()
void BookHists ()
void genNtuple ()
void FillHists ()
void AnalyseHists ()
void WriteHists ()
Public Member Functions inherited from DedxCalib
 DedxCalib (const std::string &name, ISvcLocator *pSvcLocator)
 ~DedxCalib ()
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()

Additional Inherited Members

Protected Member Functions inherited from DedxCalib
double cal_dedx_bitrunc (float truncate, std::vector< double > phlist)
double cal_dedx (float truncate, std::vector< double > phlist)
void getCurvePar ()
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)
void ReadRecFileList ()
Protected Attributes inherited from DedxCalib
IMdcGeomSvcgeosvc
IDedxCorrecSvcexsvc
float truncate
vector< double > Curve_Para
vector< double > Sigma_Para
int vFlag [3]
double m_dedx_exp [5]
double m_ex_sigma [5]
double m_pid_prob [5]
double m_chi_ex [5]
vector< string > m_recFileVector
int ParticleFlag
int m_calibflag
int m_phShapeFlag
std::string m_eventType
std::string m_recFileList
std::string m_rootfile
std::string m_curvefile

Detailed Description

Definition at line 13 of file DedxCalibTzero.h.

Constructor & Destructor Documentation

◆ DedxCalibTzero()

DedxCalibTzero::DedxCalibTzero ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 19 of file DedxCalibTzero.cxx.

20 : DedxCalib( name, pSvcLocator ) {
21 declareProperty( "Debug", m_debug = false );
22}
DedxCalib(const std::string &name, ISvcLocator *pSvcLocator)
Definition DedxCalib.cxx:12

◆ ~DedxCalibTzero()

DedxCalibTzero::~DedxCalibTzero ( )
inline

Definition at line 16 of file DedxCalibTzero.h.

16{};

Member Function Documentation

◆ AnalyseHists()

void DedxCalibTzero::AnalyseHists ( )
virtual

Implements DedxCalib.

Definition at line 184 of file DedxCalibTzero.cxx.

184 {
185 MsgStream log( msgSvc(), name() );
186 log << MSG::INFO << "DedxCalibTzero::AnalyseHists()" << endmsg;
187
188 gStyle->SetOptFit( 1111 );
189 for ( int i = 0; i < NumBinCalT0; i++ )
190 {
191 if ( m_debug ) cout << "num of bin " << i << endl;
192 if ( m_tzero[i]->Integral() > numcut ) m_tzero[i]->Fit( "gaus", "Q" );
193 if ( m_pos_tzero[i]->Integral() > numcut ) m_pos_tzero[i]->Fit( "gaus", "Q" );
194 if ( m_neg_tzero[i]->Integral() > numcut ) m_neg_tzero[i]->Fit( "gaus", "Q" );
195 if ( m_chi[i]->Integral() > numcut ) m_chi[i]->Fit( "gaus", "Q" );
196 if ( m_pos_chi[i]->Integral() > numcut ) m_pos_chi[i]->Fit( "gaus", "Q" );
197 if ( m_neg_chi[i]->Integral() > numcut ) m_neg_chi[i]->Fit( "gaus", "Q" );
198 }
199}
#define NumBinCalT0
#define numcut
IMessageSvc * msgSvc()

◆ BookHists()

void DedxCalibTzero::BookHists ( )
virtual

Implements DedxCalib.

Definition at line 24 of file DedxCalibTzero.cxx.

24 {
25 MsgStream log( msgSvc(), name() );
26 log << MSG::INFO << "DedxCalibTzero::BookHists()" << endmsg;
27
29
30 m_tzero = new TH1F*[NumBinCalT0];
31 m_pos_tzero = new TH1F*[NumBinCalT0];
32 m_neg_tzero = new TH1F*[NumBinCalT0];
33 m_chi = new TH1F*[NumBinCalT0];
34 m_pos_chi = new TH1F*[NumBinCalT0];
35 m_neg_chi = new TH1F*[NumBinCalT0];
36 stringstream hlabel;
37 for ( int i = 0; i < NumBinCalT0; i++ )
38 {
39 hlabel.str( "" );
40 hlabel << "dEdx_tzero" << i;
41 m_tzero[i] = new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins,
43 hlabel.str( "" );
44 hlabel << "pos_dEdx_tzero" << i;
45 m_pos_tzero[i] = new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins,
47 hlabel.str( "" );
48 hlabel << "neg_dEdx_tzero" << i;
49 m_neg_tzero[i] = new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins,
51 hlabel.str( "" );
52 hlabel << "chi_tzero" << i;
53 m_chi[i] = new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinChiValue,
55 hlabel.str( "" );
56 hlabel << "pos_chi_tzero" << i;
57 m_pos_chi[i] = new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins,
59 hlabel.str( "" );
60 hlabel << "neg_chi_tzero" << i;
61 m_neg_chi[i] = new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins,
63 }
64 hlabel.str( "" );
65 hlabel << "dEdxVsTzero";
66 m_dEdxVsTzero = new TH2F( hlabel.str().c_str(), "dEdx vs t0", NumBinTzero, TzeroMin,
68 m_dEdxVsTzero->GetXaxis()->SetTitle( "t0" );
69 m_dEdxVsTzero->GetYaxis()->SetTitle( "dE/dx" );
70 hlabel.str( "" );
71 hlabel << "pos_dEdxVsTzero";
72 m_pos_dEdxVsTzero = new TH2F( hlabel.str().c_str(), "positron dEdx vs t0", NumBinTzero,
74 m_pos_dEdxVsTzero->GetXaxis()->SetTitle( "pos t0" );
75 m_pos_dEdxVsTzero->GetYaxis()->SetTitle( "dE/dx" );
76 hlabel.str( "" );
77 hlabel << "neg_dEdxVsTzero";
78 m_neg_dEdxVsTzero = new TH2F( hlabel.str().c_str(), "electron dEdx vs tzero", NumBinTzero,
80 m_neg_dEdxVsTzero->GetXaxis()->SetTitle( "neg t0" );
81 m_neg_dEdxVsTzero->GetYaxis()->SetTitle( "dE/dx" );
82
83 Vec_dedx.clear();
84 Vec_tzero.clear();
85}
#define TzeroMin
#define MaxChiValue
#define MinChiValue
#define NumBinTzero
#define TzeroMax
void ReadRecFileList()
Definition DedxCalib.cxx:84

◆ FillHists()

void DedxCalibTzero::FillHists ( )
virtual

Implements DedxCalib.

Definition at line 87 of file DedxCalibTzero.cxx.

87 {
88 MsgStream log( msgSvc(), name() );
89 log << MSG::INFO << "DedxCalibTzero::FillHists()" << endmsg;
90
91 TFile* f;
92 TTree* n103;
93 string runlist;
94
95 int ndedxhit = 0;
96 double dEdx[100] = { 0 }, pathlength[100] = { 0 }, wid[100] = { 0 }, layid[100] = { 0 },
97 dd_in[100] = { 0 }, eangle[100] = { 0 }, zhit[100] = { 0 },
98 tzero_bin_low[NumBinCalT0] = { 0 }, tzero_bin_high[NumBinCalT0] = { 0 };
99 double dedx = 0;
100 float runNO = 0, evtNO = 0, runFlag = 0, costheta = 0, tes = 0, charge = 0, recalg = 0,
101 ptrk = 0, chidedx = 0;
102 int usedhit = 0;
103 for ( int i = 0; i < NumBinCalT0; i++ )
104 {
105 tzero_bin_low[i] = ( i == 0 ) ? 0 : ( tzero_bin_value[i - 1] + tzero_bin_value[i] ) / 2;
106 tzero_bin_high[i] = ( i == NumBinCalT0 - 1 )
107 ? TzeroMax
108 : ( tzero_bin_value[i] + tzero_bin_value[i + 1] ) / 2;
109 }
110 vector<double> phlist;
111 cout << "m_recFileVector.size()= " << m_recFileVector.size() << endl;
112 for ( unsigned int i = 0; i < m_recFileVector.size(); i++ )
113 {
114 runlist = m_recFileVector[i];
115 f = new TFile( runlist.c_str() );
116 n103 = (TTree*)f->Get( "n103" );
117 n103->SetBranchAddress( "ndedxhit", &ndedxhit );
118 n103->SetBranchAddress( "dEdx_hit", dEdx );
119 n103->SetBranchAddress( "pathlength_hit", pathlength );
120 n103->SetBranchAddress( "wid_hit", wid );
121 n103->SetBranchAddress( "layid_hit", layid );
122 n103->SetBranchAddress( "dd_in_hit", dd_in );
123 n103->SetBranchAddress( "eangle_hit", eangle );
124 n103->SetBranchAddress( "zhit_hit", zhit );
125 n103->SetBranchAddress( "runNO", &runNO );
126 n103->SetBranchAddress( "evtNO", &evtNO );
127 n103->SetBranchAddress( "runFlag", &runFlag );
128 n103->SetBranchAddress( "costheta", &costheta );
129 n103->SetBranchAddress( "t0", &tes );
130 n103->SetBranchAddress( "charge", &charge );
131 n103->SetBranchAddress( "recalg", &recalg );
132 n103->SetBranchAddress( "ndedxhit", &ndedxhit );
133 n103->SetBranchAddress( "ptrk", &ptrk );
134 n103->SetBranchAddress( "chidedx_e", &chidedx );
135 for ( int j = 0; j < n103->GetEntries(); j++ )
136 {
137 phlist.clear();
138 n103->GetEntry( j );
139 if ( costheta > CosthetaMax || costheta < CosthetaMin ) continue;
140 if ( tes > TzeroMax ) continue;
141 for ( int k = 0; k < ndedxhit; k++ )
142 {
143 dEdx[k] = exsvc->StandardHitCorrec( 0, runFlag, 2, runNO, evtNO, pathlength[k], wid[k],
144 layid[k], dEdx[k], dd_in[k], eangle[k], costheta );
145 phlist.push_back( dEdx[k] );
146 }
147 dedx = cal_dedx_bitrunc( truncate, phlist );
148 int iTes( 0 );
149 for ( ; iTes < NumBinCalT0; iTes++ )
150 if ( tes > tzero_bin_low[iTes] && tes <= tzero_bin_high[iTes] ) break;
151 if ( m_debug && i < 10 && j < 100 )
152 cout << "t0 " << tes << " iTes " << iTes << " dedx " << dedx << endl;
153 // if(m_debug) cout << "before cor, dedx " << pre_dedx << " with t0 " << tes << endl;
154 dedx = exsvc->StandardTrackCorrec( 0, runFlag, 2, runNO, evtNO, dedx, costheta, tes );
155 // if(m_debug) cout << "after cor, dedx " << dedx << " with gain " << pre_dedx/dedx <<
156 // endl;
157 m_tzero[iTes]->Fill( dedx );
158 m_dEdxVsTzero->Fill( tes, dedx );
159 if ( charge > 0 )
160 {
161 m_pos_tzero[iTes]->Fill( dedx );
162 m_pos_dEdxVsTzero->Fill( tes, dedx );
163 }
164 if ( charge < 0 )
165 {
166 m_neg_tzero[iTes]->Fill( dedx );
167 m_neg_dEdxVsTzero->Fill( tes, dedx );
168 }
169
170 usedhit = ndedxhit * truncate;
171 set_dEdx( 1, dedx, recalg, runFlag, usedhit, ptrk, acos( costheta ), 1.5, vFlag, tes );
172 double chi = m_chi_ex[ParticleFlag];
173 // cout<<"chidedx= "<<chidedx<<" particleType= "<<ParticleFlag<<" new chi= "<<chi<<endl;
174 m_chi[iTes]->Fill( chi );
175 if ( charge > 0 ) m_pos_chi[iTes]->Fill( chi );
176 if ( charge < 0 ) m_neg_chi[iTes]->Fill( chi );
177
178 Vec_dedx.push_back( dedx );
179 Vec_tzero.push_back( tes );
180 }
181 }
182}
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
double m_chi_ex[5]
Definition DedxCalib.h:48
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)
int ParticleFlag
Definition DedxCalib.h:52
int vFlag[3]
Definition DedxCalib.h:41
IDedxCorrecSvc * exsvc
Definition DedxCalib.h:29
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
vector< string > m_recFileVector
Definition DedxCalib.h:50
float truncate
Definition DedxCalib.h:32

◆ genNtuple()

void DedxCalibTzero::genNtuple ( )
inlinevirtual

Implements DedxCalib.

Definition at line 19 of file DedxCalibTzero.h.

19{}

◆ initializing()

void DedxCalibTzero::initializing ( )
inlinevirtual

Implements DedxCalib.

Definition at line 17 of file DedxCalibTzero.h.

17{}

◆ WriteHists()

void DedxCalibTzero::WriteHists ( )
virtual

Implements DedxCalib.

Definition at line 201 of file DedxCalibTzero.cxx.

201 {
202 MsgStream log( msgSvc(), name() );
203 log << MSG::INFO << "DedxCalibTzero::WriteHists()" << endmsg;
204
205 double fitentryNo[NumBinCalT0] = { 0 }, fitmean[NumBinCalT0] = { 0 },
206 fitmeanerr[NumBinCalT0] = { 0 }, fitsigma[NumBinCalT0] = { 0 },
207 gain[NumBinCalT0] = { 0 }, fitchisq[NumBinCalT0] = { 0 }, t0[NumBinCalT0] = { 0 },
208 fakegain[NumBinCalT0] = { 0 };
209 double pos_fitentryNo[NumBinCalT0] = { 0 }, pos_fitmean[NumBinCalT0] = { 0 },
210 pos_fitmeanerr[NumBinCalT0] = { 0 }, pos_fitsigma[NumBinCalT0] = { 0 },
211 pos_gain[NumBinCalT0] = { 0 }, pos_fitchisq[NumBinCalT0] = { 0 };
212 double neg_fitentryNo[NumBinCalT0] = { 0 }, neg_fitmean[NumBinCalT0] = { 0 },
213 neg_fitmeanerr[NumBinCalT0] = { 0 }, neg_fitsigma[NumBinCalT0] = { 0 },
214 neg_gain[NumBinCalT0] = { 0 }, neg_fitchisq[NumBinCalT0] = { 0 };
215
216 // double avegain(m_dEdxVsTzero->ProjectionX()->GetMean());
217 double avegain( 550. );
218
219 for ( int i = 0; i < NumBinCalT0; i++ )
220 {
221 t0[i] = tzero_bin_value[i];
222 fitentryNo[i] = m_tzero[i]->Integral();
223 if ( m_debug ) cout << "num of bin " << i << " with events " << fitentryNo[i] << endl;
224 if ( fitentryNo[i] <= numcut ) continue;
225 if ( m_debug )
226 cout << "get results at " << i << " bin with fit entries " << fitentryNo[i] << endl;
227 if ( m_tzero[i]->GetFunction( "gaus" ) )
228 {
229 fitmean[i] = m_tzero[i]->GetFunction( "gaus" )->GetParameter( 1 );
230 fitmeanerr[i] = m_tzero[i]->GetFunction( "gaus" )->GetParError( 1 );
231 fitsigma[i] = m_tzero[i]->GetFunction( "gaus" )->GetParameter( 2 );
232 gain[i] = fitmean[i] / avegain;
233 fakegain[i] = 1.0;
234 fitchisq[i] = ( m_tzero[i]->GetFunction( "gaus" )->GetChisquare() ) /
235 ( m_tzero[i]->GetFunction( "gaus" )->GetNDF() );
236 }
237 pos_fitentryNo[i] = m_pos_tzero[i]->Integral();
238 if ( pos_fitentryNo[i] <= numcut ) continue;
239 if ( m_debug )
240 cout << "get results at " << i << " bin with pos_fit entries " << pos_fitentryNo[i]
241 << endl;
242 if ( m_pos_tzero[i]->GetFunction( "gaus" ) )
243 {
244 pos_fitmean[i] = m_pos_tzero[i]->GetFunction( "gaus" )->GetParameter( 1 );
245 pos_fitmeanerr[i] = m_pos_tzero[i]->GetFunction( "gaus" )->GetParError( 1 );
246 pos_fitsigma[i] = m_pos_tzero[i]->GetFunction( "gaus" )->GetParameter( 2 );
247 pos_gain[i] = pos_fitmean[i] / avegain;
248 pos_fitchisq[i] = ( m_pos_tzero[i]->GetFunction( "gaus" )->GetChisquare() ) /
249 ( m_pos_tzero[i]->GetFunction( "gaus" )->GetNDF() );
250 }
251 neg_fitentryNo[i] = m_neg_tzero[i]->Integral();
252 if ( neg_fitentryNo[i] <= numcut ) continue;
253 if ( m_debug )
254 cout << "get results at " << i << " bin with neg_fit entries " << neg_fitentryNo[i]
255 << endl;
256 if ( m_neg_tzero[i]->GetFunction( "gaus" ) )
257 {
258 neg_fitmean[i] = m_neg_tzero[i]->GetFunction( "gaus" )->GetParameter( 1 );
259 neg_fitmeanerr[i] = m_neg_tzero[i]->GetFunction( "gaus" )->GetParError( 1 );
260 neg_fitsigma[i] = m_neg_tzero[i]->GetFunction( "gaus" )->GetParameter( 2 );
261 neg_gain[i] = neg_fitmean[i] / avegain;
262 neg_fitchisq[i] = ( m_neg_tzero[i]->GetFunction( "gaus" )->GetChisquare() ) /
263 ( m_neg_tzero[i]->GetFunction( "gaus" )->GetNDF() );
264 }
265 }
266
267 log << MSG::INFO << "begin generating root file!!! " << endmsg;
268 TFile* f = new TFile( m_rootfile.c_str(), "RECREATE" );
269 for ( int i = 0; i < NumBinCalT0; i++ )
270 {
271 m_chi[i]->Write();
272 m_pos_chi[i]->Write();
273 m_neg_chi[i]->Write();
274 m_tzero[i]->Write();
275 m_pos_tzero[i]->Write();
276 m_neg_tzero[i]->Write();
277 }
278 m_dEdxVsTzero->Write();
279 m_pos_dEdxVsTzero->Write();
280 m_neg_dEdxVsTzero->Write();
281
282 TTree* tzerocalib = new TTree( "gaincalib", "gaincalib" );
283 tzerocalib->Branch( "gain", &avegain, "gain/D" );
284 tzerocalib->Branch( "t0", t0, "t0[35]/D" );
285 tzerocalib->Branch( "dedx", gain, "dedx[35]/D" );
286 tzerocalib->Branch( "fakededx", fakegain, "fakededx[35]/D" );
287 tzerocalib->Branch( "fitmean", fitmean, "fitmean[35]/D" );
288 tzerocalib->Branch( "fitmeanerr", fitmeanerr, "fitmeanerr[35]/D" );
289 tzerocalib->Branch( "fitsigma", fitsigma, "fitsigma[35]/D" );
290 tzerocalib->Branch( "fitchisq", fitchisq, "fitchisq[35]/D" );
291 tzerocalib->Fill();
292 tzerocalib->Write();
293
294 TCanvas c1( "c1", "canvas", 500, 400 );
295 c1.Print( ( m_rootfile + ".ps[" ).c_str() );
296 tzerocalib->Draw( "dedx:t0" );
297 f->Close(); // delay this close for drawing plots
298
299 c1.Print( ( m_rootfile + ".ps" ).c_str() );
300 m_dEdxVsTzero->Draw();
301 c1.Print( ( m_rootfile + ".ps" ).c_str() );
302 m_pos_dEdxVsTzero->Draw();
303 c1.Print( ( m_rootfile + ".ps" ).c_str() );
304 m_neg_dEdxVsTzero->Draw();
305 c1.Print( ( m_rootfile + ".ps" ).c_str() );
306 for ( Int_t i = 0; i < NumBinCalT0; i++ )
307 {
308 m_tzero[i]->Draw();
309 c1.Print( ( m_rootfile + ".ps" ).c_str() );
310 }
311 for ( Int_t i = 0; i < NumBinCalT0; i++ )
312 {
313 m_pos_tzero[i]->Draw();
314 c1.Print( ( m_rootfile + ".ps" ).c_str() );
315 }
316 for ( Int_t i = 0; i < NumBinCalT0; i++ )
317 {
318 m_neg_tzero[i]->Draw();
319 c1.Print( ( m_rootfile + ".ps" ).c_str() );
320 }
321 c1.Print( ( m_rootfile + ".ps]" ).c_str() );
322 if ( m_debug ) cout << "before delete" << endl;
323 for ( Int_t i = 0; i < NumBinCalT0; i++ )
324 {
325 delete m_chi[i];
326 delete m_pos_chi[i];
327 delete m_neg_chi[i];
328 delete m_tzero[i];
329 delete m_pos_tzero[i];
330 delete m_neg_tzero[i];
331 }
332 delete m_dEdxVsTzero;
333 delete m_pos_dEdxVsTzero;
334 delete m_neg_dEdxVsTzero;
335}
std::string m_rootfile
Definition DedxCalib.h:57
char * c_str(Index i)

The documentation for this class was generated from the following files: