BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalibTzero.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2
3#include <sstream>
4#include <string>
5#include "TFile.h"
6#include "TF1.h"
7#include "TH1F.h"
8#include "TTree.h"
9#include "TStyle.h"
10#include "TCanvas.h"
11
12#include "DedxCalibAlg/DedxCalibTzero.h"
13
14#define Size 700000
15#define numcut 50
16
17using namespace std;
18
19DedxCalibTzero::DedxCalibTzero(const std::string& name, ISvcLocator* pSvcLocator): DedxCalib(name, pSvcLocator){
20 declareProperty("Debug", m_debug=false);
21}
22
24{
25 MsgStream log(msgSvc(), name());
26 log<<MSG::INFO<<"DedxCalibTzero::BookHists()"<<endreq;
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 hlabel.str("");
39 hlabel<<"dEdx_tzero"<<i;
40 m_tzero[i]=new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue, MaxHistValue);
41 hlabel.str("");
42 hlabel<<"pos_dEdx_tzero"<<i;
43 m_pos_tzero[i]=new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue, MaxHistValue);
44 hlabel.str("");
45 hlabel<<"neg_dEdx_tzero"<<i;
46 m_neg_tzero[i]=new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue, MaxHistValue);
47 hlabel.str("");
48 hlabel<<"chi_tzero"<<i;
49 m_chi[i]=new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinChiValue, MaxChiValue);
50 hlabel.str("");
51 hlabel<<"pos_chi_tzero"<<i;
52 m_pos_chi[i]=new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinChiValue, MaxChiValue);
53 hlabel.str("");
54 hlabel<<"neg_chi_tzero"<<i;
55 m_neg_chi[i]=new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinChiValue, MaxChiValue);
56 }
57 hlabel.str("");
58 hlabel<<"dEdxVsTzero";
59 m_dEdxVsTzero = new TH2F(hlabel.str().c_str(),"dEdx vs t0",NumBinTzero, TzeroMin, TzeroMax, NumHistBins, MinHistValue, MaxHistValue);
60 m_dEdxVsTzero->GetXaxis()->SetTitle("t0");
61 m_dEdxVsTzero->GetYaxis()->SetTitle("dE/dx");
62 hlabel.str("");
63 hlabel<<"pos_dEdxVsTzero";
64 m_pos_dEdxVsTzero = new TH2F(hlabel.str().c_str(),"positron dEdx vs t0",NumBinTzero, TzeroMin, TzeroMax, NumHistBins, MinHistValue, MaxHistValue);
65 m_pos_dEdxVsTzero->GetXaxis()->SetTitle("pos t0");
66 m_pos_dEdxVsTzero->GetYaxis()->SetTitle("dE/dx");
67 hlabel.str("");
68 hlabel<<"neg_dEdxVsTzero";
69 m_neg_dEdxVsTzero = new TH2F(hlabel.str().c_str(),"electron dEdx vs tzero",NumBinTzero, TzeroMin, TzeroMax, NumHistBins, MinHistValue, MaxHistValue);
70 m_neg_dEdxVsTzero->GetXaxis()->SetTitle("neg t0");
71 m_neg_dEdxVsTzero->GetYaxis()->SetTitle("dE/dx");
72
73 Vec_dedx.clear();
74 Vec_tzero.clear();
75}
76
78{
79 MsgStream log(msgSvc(), name());
80 log<<MSG::INFO<<"DedxCalibTzero::FillHists()"<<endreq;
81
82 TFile* f;
83 TTree* n103;
84 string runlist;
85
86 int ndedxhit=0;
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};
88 double dedx=0;
89 float runNO=0,evtNO=0,runFlag=0,costheta=0,tes=0,charge=0,recalg=0,ptrk=0,chidedx=0;
90 int usedhit=0;
91 for(int i=0; i<NumBinCalT0; i++){
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;
94 }
95 vector<double> phlist;
96 cout<<"m_recFileVector.size()= "<<m_recFileVector.size()<<endl;
97 for(unsigned int i=0; i<m_recFileVector.size(); i++)
98 {
99 runlist = m_recFileVector[i];
100 f = new TFile(runlist.c_str());
101 n103 = (TTree*)f->Get("n103");
102 n103-> SetBranchAddress("ndedxhit", &ndedxhit);
103 n103-> SetBranchAddress("dEdx_hit",dEdx);
104 n103-> SetBranchAddress("pathlength_hit",pathlength);
105 n103-> SetBranchAddress("wid_hit",wid);
106 n103-> SetBranchAddress("layid_hit",layid);
107 n103-> SetBranchAddress("dd_in_hit",dd_in);
108 n103-> SetBranchAddress("eangle_hit",eangle);
109 n103-> SetBranchAddress("zhit_hit",zhit);
110 n103-> SetBranchAddress("runNO",&runNO);
111 n103-> SetBranchAddress("evtNO",&evtNO);
112 n103-> SetBranchAddress("runFlag",&runFlag);
113 n103-> SetBranchAddress("costheta",&costheta);
114 n103-> SetBranchAddress("t0",&tes);
115 n103-> SetBranchAddress("charge",&charge);
116 n103-> SetBranchAddress("recalg",&recalg);
117 n103-> SetBranchAddress("ndedxhit",&ndedxhit);
118 n103-> SetBranchAddress("ptrk",&ptrk);
119 n103-> SetBranchAddress("chidedx_e",&chidedx);
120 for(int j=0;j<n103->GetEntries();j++)
121 {
122 phlist.clear();
123 n103->GetEntry(j);
125 if(tes>TzeroMax) continue;
126 for(int k=0;k<ndedxhit;k++)
127 {
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]);
130 }
131 dedx = cal_dedx_bitrunc(truncate, phlist);
132 int iTes(0);
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;
135 //if(m_debug) cout << "before cor, dedx " << pre_dedx << " with t0 " << tes << endl;
136 dedx = exsvc->StandardTrackCorrec(0, runFlag, 2, runNO, evtNO, dedx, costheta, tes);
137 //if(m_debug) cout << "after cor, dedx " << dedx << " with gain " << pre_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); }
142
143 usedhit = ndedxhit*truncate;
144 set_dEdx(1,dedx,recalg,runFlag,usedhit,ptrk,acos(costheta),1.5,vFlag,tes);
145 double chi = m_chi_ex[ParticleFlag];
146 //cout<<"chidedx= "<<chidedx<<" particleType= "<<ParticleFlag<<" new chi= "<<chi<<endl;
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);
150
151 Vec_dedx.push_back(dedx);
152 Vec_tzero.push_back(tes);
153 }
154 }
155}
156
158{
159 MsgStream log(msgSvc(), name());
160 log<<MSG::INFO<<"DedxCalibTzero::AnalyseHists()"<<endreq;
161
162 gStyle->SetOptFit(1111);
163 for(int i=0; i<NumBinCalT0; i++){
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" );
171 }
172}
173
175{
176 MsgStream log(msgSvc(), name());
177 log<<MSG::INFO<<"DedxCalibTzero::WriteHists()"<<endreq;
178
179 double fitentryNo[NumBinCalT0]={0},fitmean[NumBinCalT0]={0},fitmeanerr[NumBinCalT0]={0},fitsigma[NumBinCalT0]={0},gain[NumBinCalT0]={0},fitchisq[NumBinCalT0]={0},t0[NumBinCalT0]={0},fakegain[NumBinCalT0]={0};
180 double pos_fitentryNo[NumBinCalT0]={0},pos_fitmean[NumBinCalT0]={0},pos_fitmeanerr[NumBinCalT0]={0},pos_fitsigma[NumBinCalT0]={0},pos_gain[NumBinCalT0]={0},pos_fitchisq[NumBinCalT0]={0};
181 double neg_fitentryNo[NumBinCalT0]={0},neg_fitmean[NumBinCalT0]={0},neg_fitmeanerr[NumBinCalT0]={0},neg_fitsigma[NumBinCalT0]={0},neg_gain[NumBinCalT0]={0},neg_fitchisq[NumBinCalT0]={0};
182
183 // double avegain(m_dEdxVsTzero->ProjectionX()->GetMean());
184 double avegain(550.);
185
186 for(int i=0;i<NumBinCalT0;i++){
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;
197 fakegain[i] = 1.0;
198 fitchisq[i] = (m_tzero[i]->GetFunction("gaus")->GetChisquare())/(m_tzero[i]->GetFunction("gaus")->GetNDF());
199 }
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());
209 }
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());
219 }
220 }
221
222 log<<MSG::INFO<<"begin generating root file!!! "<<endreq;
223 TFile* f = new TFile(m_rootfile.c_str(), "RECREATE");
224 for(int i=0;i<NumBinCalT0;i++){
225 m_chi[i]->Write();
226 m_pos_chi[i]->Write();
227 m_neg_chi[i]->Write();
228 m_tzero[i]->Write();
229 m_pos_tzero[i]->Write();
230 m_neg_tzero[i]->Write();
231 }
232 m_dEdxVsTzero->Write();
233 m_pos_dEdxVsTzero->Write();
234 m_neg_dEdxVsTzero->Write();
235
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");
245 tzerocalib->Fill();
246 tzerocalib->Write();
247
248 TCanvas c1("c1", "canvas", 500, 400);
249 c1.Print((m_rootfile+".ps[").c_str());
250 tzerocalib->Draw("dedx:t0");
251 f->Close(); // delay this close for drawing plots
252
253 c1.Print((m_rootfile+".ps").c_str());
254 m_dEdxVsTzero->Draw();
255 c1.Print((m_rootfile+".ps").c_str());
256 m_pos_dEdxVsTzero->Draw();
257 c1.Print((m_rootfile+".ps").c_str());
258 m_neg_dEdxVsTzero->Draw();
259 c1.Print((m_rootfile+".ps").c_str());
260 for(Int_t i=0;i<NumBinCalT0;i++){
261 m_tzero[i]->Draw();
262 c1.Print((m_rootfile+".ps").c_str());
263 }
264 for(Int_t i=0;i<NumBinCalT0;i++){
265 m_pos_tzero[i]->Draw();
266 c1.Print((m_rootfile+".ps").c_str());
267 }
268 for(Int_t i=0;i<NumBinCalT0;i++){
269 m_neg_tzero[i]->Draw();
270 c1.Print((m_rootfile+".ps").c_str());
271 }
272 c1.Print((m_rootfile+".ps]").c_str());
273 if(m_debug) cout << "before delete" << endl;
274 for(Int_t i=0;i<NumBinCalT0;i++){
275 delete m_chi[i];
276 delete m_pos_chi[i];
277 delete m_neg_chi[i];
278 delete m_tzero[i];
279 delete m_pos_tzero[i];
280 delete m_neg_tzero[i];
281 }
282 delete m_dEdxVsTzero;
283 delete m_pos_dEdxVsTzero;
284 delete m_neg_dEdxVsTzero;
285}
data SetBranchAddress("time",&time)
#define numcut
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)
Definition: DedxCalib.cxx:184
void ReadRecFileList()
Definition: DedxCalib.cxx:89
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
Definition: DedxCalib.cxx:108
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")
float costheta
float charge
float ptrk