BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalibDocaEAng.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2
3#include <sstream>
4#include <string>
5#include "TTree.h"
6#include "TH1F.h"
7#include "TH2F.h"
8#include "TF1.h"
9#include "TFile.h"
10#include "TStyle.h"
11#include "TCanvas.h"
12
13#include "DedxCalibAlg/DedxCalibDocaEAng.h"
14
15using namespace std;
16const double pMin=0.2;
17const double pMax=2.1;
19
20DedxCalibDocaEAng::DedxCalibDocaEAng(const std::string& name, ISvcLocator* pSvcLocator): DedxCalib(name, pSvcLocator){
21 declareProperty("Debug", m_debug=false);
22 declareProperty("Idoca", m_idoca_test=1);
23 declareProperty("Ieang", m_ieang_test=1);
24}
25
27{
28 MsgStream log(msgSvc(), name());
29 log<<MSG::INFO<<"DedxCalibDocaEAng::BookHists()"<<endreq;
30
32
33 m_docaeangle = new TH1F**[NumSlicesDoca];
34 stringstream hlabel;
35 for(int i=0;i<NumSlicesDoca;i++)
36 {
37 m_docaeangle[i] = new TH1F*[NumSlicesEAng];
38 for(int j=0;j<NumSlicesEAng;j++)
39 {
40 hlabel.str("");
41 hlabel<<"dEdx_doca"<<i<<"_eang"<<j;
42 m_docaeangle[i][j] = new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue, MaxHistValue);
43 }
44 }
45 hlabel.str("");
46 hlabel<<"dEdxVsDocaEAng";
47 m_DocaEAngAverdE = new TH2F(hlabel.str().c_str(),"dEdx vs Doca & EAng",NumSlicesDoca,DocaMin,DocaMax,NumSlicesEAng,PhiMin,PhiMax);
48}
49
51{
52 MsgStream log(msgSvc(), name());
53 log<<MSG::INFO<<"DedxCalibDocaEAng::FillHists()"<<endreq;
54
55 TFile* f, *f_test(0);
56 TTree* n103, *t_test(0);
57 string runlist;
58
59 double doca_test(0), eang_test(0);
60 int ndedxhit=0;
61 double dEdx[100]={0},pathlength[100]={0},wid[100]={0},layid[100]={0},dd_in[100]={0},eangle[100]={0},zhit[100]={0};
62 float runNO=0,runFlag=0,costheta=0,tes=0,charge=0,recalg=0,ptrk=0,chidedx=0;
63 cout<<"m_recFileVector.size()= "<<m_recFileVector.size()<<endl;
64 if(m_debug){ f_test = new TFile("doca_eangle_test.root","recreate");
65 t_test = new TTree("inftest", "information for test doca eangle calibration");
66 t_test->Branch("idoca", &m_idoca_test, "idoca/I");
67 t_test->Branch("ieang", &m_ieang_test, "ieang/I");
68 t_test->Branch("doca", &doca_test, "doca/D");
69 t_test->Branch("eang", &eang_test, "eang/D");
70 }
71
72 for(unsigned int i=0; i<m_recFileVector.size(); i++){
73 runlist = m_recFileVector[i];
74 cout<<"runlist: "<<runlist.c_str()<<endl;
75 f = new TFile(runlist.c_str());
76
77 n103 = (TTree*)f->Get("n103");
78 n103-> SetBranchAddress("ndedxhit", &ndedxhit);
79 n103-> SetBranchAddress("dEdx_hit",dEdx);
80 n103-> SetBranchAddress("pathlength_hit",pathlength);
81 n103-> SetBranchAddress("wid_hit",wid);
82 n103-> SetBranchAddress("layid_hit",layid);
83 n103-> SetBranchAddress("dd_in_hit",dd_in);
84 n103-> SetBranchAddress("eangle_hit",eangle);
85 n103-> SetBranchAddress("zhit_hit",zhit);
86 n103-> SetBranchAddress("runNO",&runNO);
87 n103-> SetBranchAddress("runFlag",&runFlag);
88 n103-> SetBranchAddress("costheta",&costheta);
89 n103-> SetBranchAddress("t0",&tes);
90 n103-> SetBranchAddress("charge",&charge);
91 n103-> SetBranchAddress("recalg",&recalg);
92 n103-> SetBranchAddress("ptrk",&ptrk);
93 n103-> SetBranchAddress("chidedx_e",&chidedx);
94 for(int j=0;j<n103->GetEntries();j++){
95 n103->GetEntry(j);
96 if(ptrk>pMax || ptrk<pMin) continue;
97 if(tes>1400) continue;
98 for(int k=0;k<ndedxhit;k++){
99 dd_in[k] = dd_in[k]/doca_norm[int(layid[k])];
100 if(eangle[k] >0.25) eangle[k] = eangle[k] -0.5;
101 else if(eangle[k] <-0.25) eangle[k] = eangle[k] +0.5;
102 if(eangle[k]>PhiMin && eangle[k]<PhiMax && dd_in[k]>DocaMin && dd_in[k]<DocaMax)
103 {
104 // if(layid[k] <4) continue;
105 // else if(layid[k] <8)
106 // {if(dEdx[k]<MinADCValuecut || dEdx[k]>MaxADCValuecut || pathlength[k]>RPhi_PathMaxCut || pathlength[k]<Iner_RPhi_PathMinCut || driftdist[k]>Iner_DriftDistCut) continue;}
107 // else
108 // {if(dEdx[k]<MinADCValuecut || dEdx[k]>MaxADCValuecut || pathlength[k]>RPhi_PathMaxCut || pathlength[k]<Out_RPhi_PathMinCut || driftdist[k]>Out_DriftDistCut) continue;}
109 int iDoca =(Int_t)floor((dd_in[k]-DocaMin)/StepDoca);
110 int iEAng = 0;
111 for(int i =0; i<14; i++)
112 {
113 if(eangle[k] < Eangle_value_cut[i] || eangle[k] >= Eangle_value_cut[i+1]) continue;
114 else if(eangle[k] >= Eangle_value_cut[i] && eangle[k] < Eangle_value_cut[i+1])
115 {
116 for(int m =0; m<i; m++)
117 {
118 iEAng += Eangle_cut_bin[m];
119 }
120 double eangle_bin_cut_step = (Eangle_value_cut[i+1] - Eangle_value_cut[i])/Eangle_cut_bin[i];
121 int temp_bin = int((eangle[k]-Eangle_value_cut[i])/eangle_bin_cut_step);
122 iEAng += temp_bin;
123 }
124 }
125 if(m_debug && (iDoca==m_idoca_test) && (iEAng==m_ieang_test)){
126 doca_test = dd_in[k];
127 eang_test = eangle[k];
128 t_test->Fill();
129 cout << "dedx before cor: " << dEdx[k]*1.5/pathlength[k] << endl;
130 }
131 dEdx[k] = exsvc->StandardHitCorrec(0,runFlag,2,runNO,pathlength[k],wid[k],layid[k],dEdx[k],(dd_in[k])*(doca_norm[int(layid[k])]),eangle[k],costheta);
132 dEdx[k] = exsvc->StandardTrackCorrec(0, runFlag, 2, runNO, dEdx[k], costheta, tes);
133 m_docaeangle[iDoca][iEAng]->Fill(dEdx[k]);
134 if(m_debug && (iDoca==m_idoca_test) && (iEAng==m_ieang_test)){
135 cout << "dedx after cor: " << dEdx[k] << endl << endl;
136 }
137 } // end of if(eangle, doca) are normal
138 } // end of loop in k, hit list
139 } // end of loop in j, entry list
140 }// end of loop in i, filelist
141 if(m_debug){ f_test->cd(); t_test->Write(); f_test->Close(); }
142} // end of FillHists()
143
145{
146 MsgStream log(msgSvc(), name());
147 log<<MSG::INFO<<"DedxCalibDocaEAng::AnalyseHists()"<<endreq;
148
149 TF1* func;
150 Double_t entry=0,mean=0,rms=0;
151 Double_t binmax=0;
152 Double_t lp[3]={0};
153 gStyle->SetOptFit(1111);
154 for(Int_t id=0;id<NumSlicesDoca;id++)
155 {
156 for(Int_t ip=0;ip<NumSlicesEAng;ip++)
157 {
158 entry = m_docaeangle[id][ip]->GetEntries();
159 if(entry<10) continue;
160 mean = m_docaeangle[id][ip]->GetMean();
161 rms = m_docaeangle[id][ip]->GetRMS();
162 binmax = m_docaeangle[id][ip]->GetMaximumBin();
163 lp[1] = m_docaeangle[id][ip]->GetBinCenter(binmax);
164 lp[2] = 200;
165 lp[0] = (m_docaeangle[id][ip]->GetBinContent(binmax)+m_docaeangle[id][ip]->GetBinContent(binmax-1)+m_docaeangle[id][ip]->GetBinContent(binmax+1))/3;
166
167 if(m_phShapeFlag==0)
168 {
169 func = new TF1("mylan",mylan,10,3000,4);
170 func->SetParameters(entry, mean, rms, -0.8);
171 func->SetParLimits(0, 0, entry);
172 func->SetParLimits(1, 0, mean);
173 func->SetParLimits(2, 10, rms);
174 func->SetParLimits(3, -1, 0);
175 func->SetParameters(entry/36., mean-200, rms/2.3, -0.5);
176 }
177 else if(m_phShapeFlag==1)
178 {
179 func = new TF1("landaun",landaun,10,3000,3);
180 func->SetParameters(lp[0], lp[1], lp[2] );
181 }
182 else if(m_phShapeFlag==2)
183 {
184 func = new TF1("Landau",Landau,10,3000,2);
185 func->SetParameters(0.7*mean, rms );
186 }
187 else if(m_phShapeFlag==3)
188 {
189 func = new TF1("Vavilov",Vavilov,10,3000,2);
190 func->SetParameters(0.05, 0.6);
191 }
192 else if(m_phShapeFlag==4)
193 {
194 func = new TF1("AsymGauss",AsymGauss,10,3000,4);
195 func->SetParameters(entry, mean, rms, 1.0 );
196 }
197 func->SetLineWidth(2.1);
198 func->SetLineColor(2);
199
200 m_docaeangle[id][ip]->Fit(func, "r");
201 }
202 }
203}
204
206{
207 MsgStream log(msgSvc(), name());
208 log<<MSG::INFO<<"DedxCalibDocaEAng::WriteHists()"<<endreq;
209
210 const int totalNo = NumSlicesDoca*NumSlicesEAng;
211 double Out_entryNo[totalNo]={0},Out_mean[totalNo]={0},Out_sigma[totalNo]={0},Out_fitmean[totalNo]={0},Out_fitmeanerr[totalNo]={0},Out_fitsigma[totalNo]={0},Out_gain[totalNo]={0};
212 double Iner_entryNo[totalNo]={0},Iner_mean[totalNo]={0},Iner_sigma[totalNo]={0},Iner_fitmean[totalNo]={0},Iner_fitmeanerr[totalNo]={0},Iner_fitsigma[totalNo]={0},Iner_gain[totalNo]={0};
213 double Id_doca[totalNo]={0},Ip_eangle[totalNo]={0},doca[totalNo]={0},eangle[totalNo]={0},chisq[totalNo]={0};
214
215 double Norm(0), count(0);
216 for(Int_t id=0;id<NumSlicesDoca;id++)
217 {
218 for(Int_t ip=0;ip<NumSlicesEAng;ip++)
219 {
220 Id_doca[id*NumSlicesEAng+ip] = id;
221 Ip_eangle[id*NumSlicesEAng+ip] = ip;
222 doca[id*NumSlicesEAng+ip] = (id+0.5)*StepDoca + DocaMin;
223 int iE=0,i=0;
224 for(;i<14;i++)
225 {
226 if(ip>=iE && ip<iE+Eangle_cut_bin[i]) break;
227 iE=iE+Eangle_cut_bin[i];
228 }
229 //cout<<"iE= "<<iE<<" Eangle_cut_bin["<<i<<"]= "<<Eangle_cut_bin[i]<<endl;
230 eangle[id*NumSlicesEAng+ip] = Eangle_value_cut[i] + (ip-iE+0.5)*(Eangle_value_cut[i+1]-Eangle_value_cut[i])/Eangle_cut_bin[i];
231 //cout<<"eangle["<<id<<"]["<<ip<<"]= "<<eangle[id*NumSlicesEAng+ip]<<endl;
232
233 Out_entryNo[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetEntries();
234 Out_mean[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetMean();
235 Out_sigma[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetRMS();
236 //cout<<"Out_entryNo["<<id<<"]["<<ip<<"]= "<<Out_entryNo[id*NumSlicesEAng+ip]<<" "<<Out_mean[id*NumSlicesEAng+ip]<<" "<<Out_sigma[id*NumSlicesEAng+ip]<<endl;
237 if(Out_entryNo[id*NumSlicesEAng+ip]<10) continue;
238
239 if(m_phShapeFlag==0)
240 {
241 Out_fitmean[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("mylan")->GetParameter(1);
242 Out_fitmeanerr[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("mylan")->GetParError(1);
243 Out_fitsigma[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("mylan")->GetParameter(2);
244 //cout<<Out_fitmean[id*NumSlicesEAng+ip]<<" "<<Out_fitmeanerr[id*NumSlicesEAng+ip]<<" "<<Out_fitsigma[id*NumSlicesEAng+ip]<<endl;
245 chisq[id*NumSlicesEAng+ip] = (m_docaeangle[id][ip]->GetFunction("mylan")-> GetChisquare())/(m_docaeangle[id][ip]->GetFunction("mylan")-> GetNDF());
246 }
247 if(m_phShapeFlag==1)
248 {
249 Out_fitmean[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("landaun")->GetParameter(1);
250 Out_fitmeanerr[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("landaun")->GetParError(1);
251 Out_fitsigma[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("landaun")->GetParameter(2);
252 chisq[id*NumSlicesEAng+ip] = (m_docaeangle[id][ip]->GetFunction("landaun")-> GetChisquare())/(m_docaeangle[id][ip]->GetFunction("landaun")-> GetNDF());
253 }
254 if(m_phShapeFlag==2)
255 {
256 Out_fitmean[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("Landau")->GetParameter(1);
257 Out_fitmeanerr[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("Landau")->GetParError(1);
258 Out_fitsigma[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("Landau")->GetParameter(2);
259 chisq[id*NumSlicesEAng+ip] = (m_docaeangle[id][ip]->GetFunction("Landau")-> GetChisquare())/(m_docaeangle[id][ip]->GetFunction("Landau")-> GetNDF());
260 }
261 if(m_phShapeFlag==3)
262 {
263 Out_fitmean[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("Vavilov")->GetParameter(1);
264 Out_fitmeanerr[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("Vavilov")->GetParError(1);
265 Out_fitsigma[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("Vavilov")->GetParameter(2);
266 chisq[id*NumSlicesEAng+ip] = (m_docaeangle[id][ip]->GetFunction("Vavilov")-> GetChisquare())/(m_docaeangle[id][ip]->GetFunction("Vavilov")-> GetNDF());
267 }
268 if(m_phShapeFlag==4)
269 {
270 Out_fitmean[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("AsymGauss")->GetParameter(1);
271 Out_fitmeanerr[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("AsymGauss")->GetParError(1);
272 Out_fitsigma[id*NumSlicesEAng+ip] = m_docaeangle[id][ip]->GetFunction("AsymGauss")->GetParameter(2);
273 chisq[id*NumSlicesEAng+ip] = (m_docaeangle[id][ip]->GetFunction("AsymGauss")-> GetChisquare())/(m_docaeangle[id][ip]->GetFunction("AsymGauss")-> GetNDF());
274 }
275
276 m_DocaEAngAverdE -> SetBinContent(id+1, ip+1, Out_fitmean[id*NumSlicesEAng+ip]);
277 if(Out_fitmean[id*NumSlicesEAng+ip]>0 && Out_fitmeanerr[id*NumSlicesEAng+ip]>0 && Out_fitmeanerr[id*NumSlicesEAng+ip]<10 && Out_fitsigma[id*NumSlicesEAng+ip]>0 && Out_fitsigma[id*NumSlicesEAng+ip]<200){
278 Norm += (Out_fitmean[id*NumSlicesEAng+ip])*(Out_entryNo[id*NumSlicesEAng+ip]);
279 count += Out_entryNo[id*NumSlicesEAng+ip];
280 }
281 } // end of loop in ip
282 } // end of loop in id
283 Norm = Norm/count;
284 cout<<"count= "<<count<<" average value of doca eangle bins: "<<Norm<<endl;
285 for(Int_t i=0;i<totalNo;i++)
286 {
287 if(Out_entryNo[i]>10 && Out_fitmean[i]>0 && Out_fitsigma[i]>0) Out_gain[i]=Out_fitmean[i]/Norm;
288 else Out_gain[i] = 0;
289 }
290
291 log<<MSG::INFO<<"begin generating root file!!! "<<endreq;
292 TFile* f = new TFile(m_rootfile.c_str(), "recreate");
293 for(Int_t id=0;id<NumSlicesDoca;id++)
294 {
295 for(Int_t ip=0;ip<NumSlicesEAng;ip++)
296 {
297 m_docaeangle[id][ip]->Write();
298 }
299 }
300 m_DocaEAngAverdE->Write();
301
302 TTree* ddgcalib = new TTree("ddgcalib", "ddgcalib");
303 ddgcalib -> Branch("Out_hits", Out_entryNo, "Out_entryNo[1600]/D");
304 ddgcalib -> Branch("Out_mean", Out_mean, "Out_mean[1600]/D");
305 ddgcalib -> Branch("Out_sigma", Out_sigma, "Out_sigma[1600]/D");
306 ddgcalib -> Branch("Out_fitmean", Out_fitmean, "Out_fitmean[1600]/D");
307 ddgcalib -> Branch("Out_fitmeanerr", Out_fitmeanerr, "Out_fitmeanerr[1600]/D");
308 ddgcalib -> Branch("Out_chi", Out_fitsigma, "Out_fitsigma[1600]/D");
309 ddgcalib -> Branch("Out_gain", Out_gain, "Out_gain[1600]/D");
310 ddgcalib -> Branch("Iner_hits", Iner_entryNo, "Iner_entryNo[1600]/D");
311 ddgcalib -> Branch("Iner_mean", Iner_mean, "Iner_mean[1600]/D");
312 ddgcalib -> Branch("Iner_sigma", Iner_sigma, "Iner_sigma[1600]/D");
313 ddgcalib -> Branch("Iner_fitmean", Iner_fitmean, "Iner_fitmean[1600]/D");
314 ddgcalib -> Branch("Iner_fitmeanerr", Iner_fitmeanerr, "Iner_fitmeanerr[1600]/D");
315 ddgcalib -> Branch("Iner_chi", Iner_fitsigma, "Iner_fitsigma[1600]/D");
316 ddgcalib -> Branch("Iner_gain", Iner_gain, "Iner_gain[1600]/D");
317 ddgcalib -> Branch("Id_doca", Id_doca, "Id_doca[1600]/D");
318 ddgcalib -> Branch("Ip_eangle", Ip_eangle, "Ip_eangle[1600]/D");
319 ddgcalib -> Branch("chisq", chisq, "chisq[1600]/D");
320 ddgcalib -> Branch("doca", doca, "doca[1600]/D");
321 ddgcalib -> Branch("eangle", eangle, "eangle[1600]/D");
322 ddgcalib -> Fill();
323 ddgcalib -> Write();
324 f->Close();
325
326 TCanvas c1("c1", "canvas", 500, 400);
327 c1.Print((m_rootfile+".ps[").c_str());
328 for(Int_t id=0;id<NumSlicesDoca;id++)
329 {
330 for(Int_t ip=0;ip<NumSlicesEAng;ip++)
331 {
332 m_docaeangle[id][ip]->Draw();
333 c1.Print((m_rootfile+".ps").c_str());
334 }
335 }
336 c1.Print((m_rootfile+".ps]").c_str());
337
338 for(Int_t id=0;id<NumSlicesDoca;id++)
339 {
340 for(Int_t ip=0;ip<NumSlicesEAng;ip++)
341 {
342 delete m_docaeangle[id][ip];
343 }
344 }
345 delete m_DocaEAngAverdE;
346}
data SetBranchAddress("time",&time)
const double StepDoca
const double pMin
const double pMax
DOUBLE_PRECISION count[3]
double Landau(double *x, double *par)
double Vavilov(double *x, double *par)
double landaun(double *x, double *par)
double AsymGauss(double *x, double *par)
double mylan(double *x, double *par)
DedxCalibDocaEAng(const std::string &name, ISvcLocator *pSvcLocator)
void ReadRecFileList()
Definition: DedxCalib.cxx:89
virtual double StandardHitCorrec(int calib_rec_Flag, int runFlag, int ntpFlag, int runNO, 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, double ex, double costheta, double t0) const =0