BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalibLayerGain.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 "TF1.h"
8#include "TFile.h"
9#include "TStyle.h"
10#include "TCanvas.h"
11
13
14using namespace std;
15
16DedxCalibLayerGain::DedxCalibLayerGain(const std::string& name, ISvcLocator* pSvcLocator): DedxCalib(name, pSvcLocator){}
17
18const int layNo = 43;
20void calculate(vector<double> phlist)
21{
22 double mean=0,rms=0;
23 for(int i=0;i<phlist.size();i++)
24 {
25 mean+=phlist[i];
26 }
27 mean/=phlist.size();
28 for(int i=0;i<phlist.size();i++)
29 {
30 rms += pow((phlist[i]-mean),2);
31 }
32 //cout<<"phlist.size()= "<<phlist.size()<<" rms= "<<rms<<endl;
33 rms = sqrt(rms/phlist.size());
34 //cout<<"mean = "<<mean<<" rms= "<<rms<<endl;
35 m_mean = mean;
36 m_rms = rms;
37}
38double getMean() {return m_mean;}
39double getRms() {return m_rms;}
40
42{
43 MsgStream log(msgSvc(), name());
44 log<<MSG::INFO<<"DedxCalibLayerGain::BookHists()"<<endreq;
45
47
48 m_laygain = new TH1F*[layNo];
49 m_laygain_gaus = new TH1F*[layNo];
50 stringstream hlabel;
51 for(int i=0; i<layNo; i++)
52 {
53 hlabel.str("");
54 hlabel<<"dEdx_Lay_"<<i;
55 m_laygain[i] = new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue, MaxHistValue);
56 hlabel.str("");
57 hlabel<<"dEdx_gaus_Lay_"<<i;
58 m_laygain_gaus[i] = new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue1, MaxHistValue1);
59 }
60}
61
63{
64 MsgStream log(msgSvc(), name());
65 log<<MSG::INFO<<"DedxCalibLayerGain::FillHists()"<<endreq;
66
67 TFile* f;
68 TTree* n102;
69 string runlist;
70
71 double dedx=0;
72 float runNO=0,evtNO=0,runFlag=0,pathlength=0,wid=0,layid=0,dd_in=0,driftdist=0,eangle=0,zhit=0,costheta=0,tes=0,ptrk=0;
73 cout<<"m_recFileVector.size()= "<<m_recFileVector.size()<<endl;
74 for(int i=0; i<m_recFileVector.size(); i++)
75 {
76 runlist = m_recFileVector[i];
77 cout<<"runlist: "<<runlist.c_str()<<endl;
78 f = new TFile(runlist.c_str());
79 n102 = (TTree*)f->Get("n102");
80 n102-> SetBranchAddress("adc_raw",&dedx);
81 n102-> SetBranchAddress("path_rphi",&pathlength);
82 n102-> SetBranchAddress("wire",&wid);
83 n102-> SetBranchAddress("layer",&layid);
84 n102-> SetBranchAddress("doca_in",&dd_in);
85 n102-> SetBranchAddress("driftdist",&driftdist);
86 n102-> SetBranchAddress("eangle",&eangle);
87 n102-> SetBranchAddress("zhit",&zhit);
88 n102-> SetBranchAddress("runNO",&runNO);
89 n102-> SetBranchAddress("evtNO",&evtNO);
90 n102-> SetBranchAddress("runFlag",&runFlag);
91 n102-> SetBranchAddress("costheta1",&costheta);
92 n102-> SetBranchAddress("t01",&tes);
93 n102->SetBranchAddress("ptrk1",&ptrk);
94
95 for(int j=0;j<n102->GetEntries();j++)
96 {
97 n102->GetEntry(j);
98 if(tes>1400) continue;
99 if (ptrk<0.1) continue;
100 //if(wid>=6731 && wid<=6739) continue;
101 if(layid <8)
102 {if(dedx<MinADCValuecut || dedx>MaxADCValuecut || pathlength>RPhi_PathMaxCut || pathlength<Iner_RPhi_PathMinCut || driftdist>Iner_DriftDistCut) continue;}
103 else
104 {if(dedx<MinADCValuecut || dedx>MaxADCValuecut || pathlength>RPhi_PathMaxCut || pathlength<Out_RPhi_PathMinCut || driftdist>Out_DriftDistCut) continue;}
105 dedx = exsvc->StandardHitCorrec(0,runFlag,2,runNO,evtNO,pathlength,wid,layid,dedx,dd_in,eangle,costheta);
106 dedx = exsvc->StandardTrackCorrec(0, runFlag, 2, runNO, evtNO, dedx, costheta, tes);
107 m_laygain[(int)layid]->Fill(dedx);
108
109 m_vector[(int)layid].push_back(dedx);
110 }
111 }
112
113}
114
116{
117 MsgStream log(msgSvc(), name());
118 log<<MSG::INFO<<"DedxCalibLayerGain::AnalyseHists()"<<endreq;
119
120 TF1* func;
121 Double_t entry=0,mean=0,rms=0;
122 Double_t binmax=0;
123 Double_t lp[3]={0};
124 gStyle->SetOptFit(1111);
125
126 stringstream hlabel;
127 double dedxt;
128 vector<double> phlist;
129 vector<double> phlist_gaus;
130 for(int i=0; i<layNo; i++)
131 {
132 entry = m_laygain[i]->GetEntries();
133 if(entry<10) continue;
134 mean = m_laygain[i]->GetMean();
135 rms = m_laygain[i]->GetRMS();
136 binmax = m_laygain[i]->GetMaximumBin();
137 lp[1] = m_laygain[i]->GetBinCenter(binmax);
138 lp[2] = 200;
139 lp[0] = (m_laygain[i]->GetBinContent(binmax)+m_laygain[i]->GetBinContent(binmax-1)+m_laygain[i]->GetBinContent(binmax+1))/3;
140
141 if(m_phShapeFlag==0)
142 {
143 func = new TF1("mylan",mylan,10,3000,4);
144 func->SetParameters(entry, mean, rms, -0.9);
145 }
146 else if(m_phShapeFlag==1)
147 {
148 func = new TF1("landaun",landaun,10,3000,3);
149 func->SetParameters(lp[0], lp[1], lp[2] );
150 }
151 else if(m_phShapeFlag==2)
152 {
153 func = new TF1("Landau",Landau,10,3000,2);
154 func->SetParameters(0.7*mean, rms );
155 }
156 else if(m_phShapeFlag==3)
157 {
158 func = new TF1("Vavilov",Vavilov,10,3000,2);
159 func->SetParameters(0.05, 0.6);
160 }
161 else if(m_phShapeFlag==4)
162 {
163 func = new TF1("AsymGauss",AsymGauss,10,3000,4);
164 func->SetParameters(entry, mean, rms, 1.0 );
165 }
166 func->SetLineWidth(2.1);
167 func->SetLineColor(2);
168
169 m_laygain[i]->Fit(func, "r" );
170
171
172 //******* begin truncated dedx fitting **************************//
173 for(int j=0;j<m_vector[i].size();j+=100)
174 {
175 for(int k=0;k<100;k++) phlist.push_back(m_vector[i][j+k]);
176 dedxt = cal_dedx_bitrunc(truncate, phlist);
177 phlist_gaus.push_back(dedxt);
178 phlist.clear();
179 }
180
181 hlabel.str("");
182 hlabel<<"dEdx_gaus_Lay_"<<i;
183 calculate(phlist_gaus);
184 //cout<<getMean()-10*getRms()<<" "<<getMean()+10*getRms()<<endl;
185 m_laygain_gaus[i] = new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, getMean()-10*getRms(), getMean()+10*getRms());
186 for(int j=0;j<phlist_gaus.size();j++) m_laygain_gaus[i]->Fill(phlist_gaus[j]);
187 phlist_gaus.clear();
188 m_laygain_gaus[i]->Fit("gaus","Q");
189
190
191 }
192}
193
195{
196 MsgStream log(msgSvc(), name());
197 log<<MSG::INFO<<"DedxCalibLayerGain::WriteHists()"<<endreq;
198
199
200 double entryNo[layNo]={0},mean[layNo]={0},sigma[layNo]={0},proper[layNo]={0},fitmean[layNo]={0},fitmeanerr[layNo]={0},fitsigma[layNo]={0},layerg[layNo]={0},layer[layNo]={0},chisq[layNo]={0};
201 double fitmean_gaus[layNo]={0},fitmeanerr_gaus[layNo]={0},fitsigma_gaus[layNo]={0},layerg_gaus[layNo]={0};
202 for(int i=0; i<layNo; i++)
203 {
204 fitmean_gaus[i] = m_laygain_gaus[i]->GetFunction("gaus")->GetParameter(1);
205 fitmeanerr_gaus[i] = m_laygain_gaus[i]->GetFunction("gaus")->GetParError(1);
206 fitsigma_gaus[i] = m_laygain_gaus[i]->GetFunction("gaus")->GetParameter(2);
207
208 entryNo[i] = m_laygain[i]->GetEntries();
209 mean[i] = m_laygain[i]->GetMean();
210 sigma[i] = m_laygain[i]->GetRMS();
211 proper[i] = m_laygain[i]->GetBinCenter(m_laygain[i]->GetMaximumBin());
212 if(entryNo[i]<10) continue;
213
214 if(m_phShapeFlag==0)
215 {
216 fitmean[i] = m_laygain[i]->GetFunction("mylan")->GetParameter(1);
217 fitmeanerr[i] = m_laygain[i]->GetFunction("mylan")->GetParError(1);
218 fitsigma[i] = m_laygain[i]->GetFunction("mylan")->GetParameter(2);
219 chisq[i] = (m_laygain[i]->GetFunction("mylan")-> GetChisquare())/(m_laygain[i]->GetFunction("mylan")-> GetNDF());
220 }
221 else if(m_phShapeFlag==1)
222 {
223 fitmean[i] = m_laygain[i]->GetFunction("landaun")->GetParameter(1);
224 fitmeanerr[i] = m_laygain[i]->GetFunction("landaun")->GetParError(1);
225 fitsigma[i] = m_laygain[i]->GetFunction("landaun")->GetParameter(2);
226 chisq[i] = (m_laygain[i]->GetFunction("landaun")-> GetChisquare())/(m_laygain[i]->GetFunction("landaun")-> GetNDF());
227 }
228 else if(m_phShapeFlag==2)
229 {
230 fitmean[i] = m_laygain[i]->GetFunction("Landau")->GetParameter(1);
231 fitmeanerr[i] = m_laygain[i]->GetFunction("Landau")->GetParError(1);
232 fitsigma[i] = m_laygain[i]->GetFunction("Landau")->GetParameter(2);
233 chisq[i] = (m_laygain[i]->GetFunction("Landau")-> GetChisquare())/(m_laygain[i]->GetFunction("Landau")-> GetNDF());
234 }
235 else if(m_phShapeFlag==3)
236 {
237 fitmean[i] = m_laygain[i]->GetFunction("Vavilov")->GetParameter(1);
238 fitmeanerr[i] = m_laygain[i]->GetFunction("Vavilov")->GetParError(1);
239 fitsigma[i] = m_laygain[i]->GetFunction("Vavilov")->GetParameter(2);
240 chisq[i] = (m_laygain[i]->GetFunction("Vavilov")-> GetChisquare())/(m_laygain[i]->GetFunction("Vavilov")-> GetNDF());
241 }
242 else if(m_phShapeFlag==4)
243 {
244 fitmean[i] = m_laygain[i]->GetFunction("AsymGauss")->GetParameter(1);
245 fitmeanerr[i] = m_laygain[i]->GetFunction("AsymGauss")->GetParError(1);
246 fitsigma[i] = m_laygain[i]->GetFunction("AsymGauss")->GetParameter(2);
247 chisq[i] = (m_laygain[i]->GetFunction("AsymGauss")-> GetChisquare())/(m_laygain[i]->GetFunction("AsymGauss")-> GetNDF());
248 }
249 //cout<<"fitmean[i]= "<<fitmean[i]<<" fitmeanerr[i]= "<<fitmeanerr[i]<<" fitsigma[i]= "<<fitsigma[i]<<endl;
250 }
251
252 double sum=0, sum_gaus=0, n=0;
253 for(int i=4; i<layNo; i++)
254 {
255 if(fitmean[i]>0 && fitmeanerr[i]>0 && fitmeanerr[i]<10 && fitsigma[i]>0 && fitsigma[i]<200 && entryNo[i]>1500)
256 {
257 sum += fitmean[i];
258 sum_gaus+= fitmean_gaus[i];
259 n++;
260 }
261 }
262 sum/=n;
263 sum_gaus/=n;
264 cout<<"average value of good layer: "<<sum<<endl;
265
266 for(int i=0;i<layNo;i++)
267 {
268 layerg[i] = fitmean[i]/sum;
269 layerg_gaus[i] = fitmean_gaus[i]/sum_gaus;
270 layer[i] = i;
271 }
272
273
274 log<<MSG::INFO<<"begin generating root file!!! "<<endreq;
275 TFile* f = new TFile(m_rootfile.c_str(), "recreate");
276 for(int i=0;i<layNo;i++)
277 {
278 m_laygain[i]->Write();
279 m_laygain_gaus[i]->Write();
280 }
281
282 TTree* layergcalib = new TTree("layergcalib", "layergcalib");
283 layergcalib->Branch("layerg_gaus", layerg_gaus, "layerg_gaus[43]/D");
284 layergcalib->Branch("layerg", layerg, "layerg[43]/D");
285 layergcalib->Branch("layer", layer, "layer[43]/D");
286 layergcalib->Branch("entryNo", entryNo, "entryNo[43]/D");
287 layergcalib->Branch("mean", mean, "mean[43]/D");
288 layergcalib->Branch("sigma", sigma, "sigma[43]/D");
289 layergcalib->Branch("fitmean", fitmean, "fitmean[43]/D");
290 layergcalib->Branch("fitmeanerr", fitmeanerr, "fitmeanerr[43]/D");
291 layergcalib->Branch("fitsigma", fitsigma, "fitsigma[43]/D");
292 layergcalib->Branch("chisq", chisq, "chisq[43]/D");
293 layergcalib->Branch("fitmean_gaus", fitmean_gaus, "fitmean_gaus[43]/D");
294 layergcalib->Branch("fitmeanerr_gaus", fitmeanerr_gaus, "fitmeanerr_gaus[43]/D");
295 layergcalib->Branch("fitsigma_gaus", fitsigma_gaus, "fitsigma_gaus[43]/D");
296 layergcalib->Fill();
297 layergcalib->Write();
298
299 f->Close();
300
301 TCanvas c1("c1", "canvas", 500, 400);
302 c1.Print((m_rootfile+".ps[").c_str());
303 for(int i=0;i<layNo;i++)
304 {
305 m_laygain[i]->Draw();
306 c1.Print((m_rootfile+".ps").c_str());
307 }
308 c1.Print((m_rootfile+".ps]").c_str());
309
310 for(int i=0;i<layNo;i++)
311 {
312 delete m_laygain[i];
313 delete m_laygain_gaus[i];
314 }
315}
TTree * sigma
curve Fill()
double m_rms
const int layNo
double getMean()
double getRms()
void calculate(vector< double > phlist)
double m_mean
double Landau(double *x, double *par)
#define MaxADCValuecut
#define MinHistValue1
double Vavilov(double *x, double *par)
#define MaxHistValue1
#define Iner_DriftDistCut
#define RPhi_PathMaxCut
#define MinHistValue
double landaun(double *x, double *par)
#define Out_DriftDistCut
double AsymGauss(double *x, double *par)
#define NumHistBins
#define MaxHistValue
double mylan(double *x, double *par)
IMessageSvc * msgSvc()
DedxCalibLayerGain(const std::string &name, ISvcLocator *pSvcLocator)
void ReadRecFileList()
Definition: DedxCalib.cxx:89
int m_phShapeFlag
Definition: DedxCalib.h:52
std::string m_rootfile
Definition: DedxCalib.h:55
IDedxCorrecSvc * exsvc
Definition: DedxCalib.h:30
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
Definition: DedxCalib.cxx:108
vector< string > m_recFileVector
Definition: DedxCalib.h:48
float truncate
Definition: DedxCalib.h:33
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")
curve SetBranchAddress("CurveSize",&CurveSize)
float costheta
float ptrk