BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalibWireGain.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
16DedxCalibWireGain::DedxCalibWireGain(const std::string& name, ISvcLocator* pSvcLocator): DedxCalib(name, pSvcLocator){}
17
18const int wireNo = 6796;
19
21{
22 MsgStream log(msgSvc(), name());
23 log<<MSG::INFO<<"DedxCalibWireGain::BookHists()"<<endreq;
24
26
27 m_wiregain = new TH1F*[wireNo];
28 stringstream hlabel;
29 for(int i=0; i<wireNo; i++)
30 {
31 hlabel.str("");
32 hlabel<<"dEdx_Wire_"<<i;
33 m_wiregain[i] = new TH1F(hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue, MaxHistValue);
34 }
35}
36
38{
39 MsgStream log(msgSvc(), name());
40 log<<MSG::INFO<<"DedxCalibWireGain::FillHists()"<<endreq;
41
42 TFile* f;
43 TTree* n102;
44 string runlist;
45
46 double dedx=0;
47 float runNO=0,runFlag=0,pathlength=0,wid=0,layid=0,dd_in=0,driftdist=0,eangle=0,zhit=0,costheta=0,tes=0,ptrk=0;
48 cout<<"m_recFileVector.size()= "<<m_recFileVector.size()<<endl;
49 for(int i=0; i<m_recFileVector.size(); i++)
50 {
51 runlist = m_recFileVector[i];
52 cout<<"runlist: "<<runlist.c_str()<<endl;
53 f = new TFile(runlist.c_str());
54 n102 = (TTree*)f->Get("n102");
55 n102-> SetBranchAddress("adc_raw",&dedx);
56 n102-> SetBranchAddress("path_rphi",&pathlength);
57 n102-> SetBranchAddress("wire",&wid);
58 n102-> SetBranchAddress("layer",&layid);
59 n102-> SetBranchAddress("doca_in",&dd_in);
60 n102-> SetBranchAddress("driftdist",&driftdist);
61 n102-> SetBranchAddress("eangle",&eangle);
62 n102-> SetBranchAddress("zhit",&zhit);
63 n102-> SetBranchAddress("runNO",&runNO);
64 n102-> SetBranchAddress("runFlag",&runFlag);
65 n102-> SetBranchAddress("costheta1",&costheta);
66 n102-> SetBranchAddress("t01",&tes);
67 n102->SetBranchAddress("ptrk1",&ptrk);
68
69 for(int j=0;j<n102->GetEntries();j++)
70 {
71 n102->GetEntry(j);
72 if(tes>1400) continue;
73 if (ptrk<0.1) continue;
74 if(layid <8)
75 {if(dedx<MinADCValuecut || dedx>MaxADCValuecut || pathlength>RPhi_PathMaxCut || pathlength<Iner_RPhi_PathMinCut || driftdist>Iner_DriftDistCut) continue;}
76 else
77 {if(dedx<MinADCValuecut || dedx>MaxADCValuecut || pathlength>RPhi_PathMaxCut || pathlength<Out_RPhi_PathMinCut || driftdist>Out_DriftDistCut) continue;}
78 dedx = exsvc->StandardHitCorrec(0,runFlag,2,runNO,pathlength,wid,layid,dedx,dd_in,eangle,costheta);
79 dedx = exsvc->StandardTrackCorrec(0, runFlag, 2, runNO, dedx, costheta, tes);
80 m_wiregain[(int)wid]->Fill(dedx);
81 }
82 }
83}
84
86{
87 MsgStream log(msgSvc(), name());
88 log<<MSG::INFO<<"DedxCalibWireGain::AnalyseHists()"<<endreq;
89
90 TF1* func;
91 Double_t entry=0,mean=0,rms=0;
92 Double_t binmax=0;
93 Double_t lp[3]={0};
94 gStyle->SetOptFit(1111);
95 for(int wire=0; wire<wireNo; wire++)
96 {
97 entry = m_wiregain[wire]->Integral();
98 if(entry<10) continue;
99 mean = m_wiregain[wire]->GetMean();
100 rms = m_wiregain[wire]->GetRMS();
101 binmax = m_wiregain[wire]->GetMaximumBin();
102 lp[1] = m_wiregain[wire]->GetBinCenter(binmax);
103 lp[2] = 200;
104 lp[0] = (m_wiregain[wire]->GetBinContent(binmax)+m_wiregain[wire]->GetBinContent(binmax-1)+m_wiregain[wire]->GetBinContent(binmax+1))/3;
105
106 if(m_phShapeFlag==0)
107 {
108 func = new TF1("mylan",mylan,10,3000,4);
109 func->SetParameters(entry, mean, rms, -0.8);
110 func->SetParLimits(0, 0, entry);
111 func->SetParLimits(1, 0, mean);
112 func->SetParLimits(2, 10, rms);
113 func->SetParLimits(3, -3, 3);
114 }
115 else if(m_phShapeFlag==1)
116 {
117 func = new TF1("landaun",landaun,10,3000,3);
118 func->SetParameters(lp[0], lp[1], lp[2] );
119 }
120 else if(m_phShapeFlag==2)
121 {
122 func = new TF1("Landau",Landau,10,3000,2);
123 func->SetParameters(0.7*mean, rms );
124 }
125 else if(m_phShapeFlag==3)
126 {
127 func = new TF1("Vavilov",Vavilov,10,3000,2);
128 func->SetParameters(0.05, 0.6);
129 }
130 else if(m_phShapeFlag==4)
131 {
132 func = new TF1("AsymGauss",AsymGauss,10,3000,4);
133 func->SetParameters(entry, mean, rms, 1.0 );
134 }
135 func->SetLineWidth(2.1);
136 func->SetLineColor(2);
137
138 m_wiregain[wire]->Fit(func, "rq", "", mean-rms, mean+rms/2 );
139 }
140}
141
143{
144 MsgStream log(msgSvc(), name());
145 log<<MSG::INFO<<"DedxCalibWireGain::WriteHists()"<<endreq;
146
147
148 double entryNo[wireNo]={0},mean[wireNo]={0},sigma[wireNo]={0},proper[wireNo]={0},fitmean[wireNo]={0},fitmeanerr[wireNo]={0},fitsigma[wireNo]={0},wireg[wireNo]={0},wire[wireNo]={0},chisq[wireNo]={0};
149 for(int i=0; i<wireNo; i++)
150 {
151 entryNo[i] = m_wiregain[i]->Integral();
152 mean[i] = m_wiregain[i]->GetMean();
153 sigma[i] = m_wiregain[i]->GetRMS();
154 proper[i] = m_wiregain[i]->GetBinCenter(m_wiregain[i]->GetMaximumBin());
155 if(entryNo[i]<10) continue;
156
157 if(m_phShapeFlag==0)
158 {
159 fitmean[i] = m_wiregain[i]->GetFunction("mylan")->GetParameter(1);
160 fitmeanerr[i] = m_wiregain[i]->GetFunction("mylan")->GetParError(1);
161 fitsigma[i] = m_wiregain[i]->GetFunction("mylan")->GetParameter(2);
162 chisq[i] = (m_wiregain[i]->GetFunction("mylan")-> GetChisquare())/(m_wiregain[i]->GetFunction("mylan")-> GetNDF());
163 }
164 else if(m_phShapeFlag==1)
165 {
166 fitmean[i] = m_wiregain[i]->GetFunction("landaun")->GetParameter(1);
167 fitmeanerr[i] = m_wiregain[i]->GetFunction("landaun")->GetParError(1);
168 fitsigma[i] = m_wiregain[i]->GetFunction("landaun")->GetParameter(2);
169 chisq[i] = (m_wiregain[i]->GetFunction("landaun")-> GetChisquare())/(m_wiregain[i]->GetFunction("landaun")-> GetNDF());
170 }
171 else if(m_phShapeFlag==2)
172 {
173 fitmean[i] = m_wiregain[i]->GetFunction("Landau")->GetParameter(1);
174 fitmeanerr[i] = m_wiregain[i]->GetFunction("Landau")->GetParError(1);
175 fitsigma[i] = m_wiregain[i]->GetFunction("Landau")->GetParameter(2);
176 chisq[i] = (m_wiregain[i]->GetFunction("Landau")-> GetChisquare())/(m_wiregain[i]->GetFunction("Landau")-> GetNDF());
177 }
178 else if(m_phShapeFlag==3)
179 {
180 fitmean[i] = m_wiregain[i]->GetFunction("Vavilov")->GetParameter(1);
181 fitmeanerr[i] = m_wiregain[i]->GetFunction("Vavilov")->GetParError(1);
182 fitsigma[i] = m_wiregain[i]->GetFunction("Vavilov")->GetParameter(2);
183 chisq[i] = (m_wiregain[i]->GetFunction("Vavilov")-> GetChisquare())/(m_wiregain[i]->GetFunction("Vavilov")-> GetNDF());
184 }
185 else if(m_phShapeFlag==4)
186 {
187 fitmean[i] = m_wiregain[i]->GetFunction("AsymGauss")->GetParameter(1);
188 fitmeanerr[i] = m_wiregain[i]->GetFunction("AsymGauss")->GetParError(1);
189 fitsigma[i] = m_wiregain[i]->GetFunction("AsymGauss")->GetParameter(2);
190 chisq[i] = (m_wiregain[i]->GetFunction("AsymGauss")-> GetChisquare())/(m_wiregain[i]->GetFunction("AsymGauss")-> GetNDF());
191 }
192 //cout<<"fitmean[i]= "<<fitmean[i]<<" fitmeanerr[i]= "<<fitmeanerr[i]<<" fitsigma[i]= "<<fitsigma[i]<<endl;
193 }
194
195 double Norm=0, count=0;
196 for(int i=188; i<wireNo; i++)
197 {
198 if(fitmean[i]>0 && fitmeanerr[i]>0 && fitmeanerr[i]<10 && fitsigma[i]>0 && fitsigma[i]<200 && entryNo[i]>1500)
199 {
200 Norm += fitmean[i];
201 count++;
202 }
203 }
204 Norm/=count;
205 cout<<"count= "<<count<<" average value of good wire: "<<Norm<<endl;
206 // double Norm(550); // use 550 instead of average because we will handle wireg later outside of the program
207
208 for(int i=0;i<wireNo;i++)
209 {
210 wireg[i] = fitmean[i]/Norm;
211 wire[i] = i;
212 }
213
214
215 log<<MSG::INFO<<"begin generating root file!!! "<<endreq;
216 TFile* f = new TFile(m_rootfile.c_str(), "recreate");
217 for(int i=0;i<wireNo;i++) m_wiregain[i]->Write();
218
219 TTree* wiregcalib = new TTree("wiregcalib", "wiregcalib");
220 wiregcalib->Branch("wireg", wireg, "wireg[6796]/D");
221 wiregcalib->Branch("wire", wire, "wire[6796]/D");
222 wiregcalib->Branch("entryNo", entryNo, "entryNo[6796]/D");
223 wiregcalib->Branch("proper", proper, "proper[6796]/D");
224 wiregcalib->Branch("mean", mean, "mean[6796]/D");
225 wiregcalib->Branch("sigma", sigma, "sigma[6796]/D");
226 wiregcalib->Branch("fitmean", fitmean, "fitmean[6796]/D");
227 wiregcalib->Branch("fitmeanerr", fitmeanerr, "fitmeanerr[6796]/D");
228 wiregcalib->Branch("fitsigma", fitsigma, "fitsigma[6796]/D");
229 wiregcalib->Branch("chisq", chisq, "chisq[6796]/D");
230 wiregcalib->Fill();
231 wiregcalib->Write();
232
233 f->Close();
234
235 TCanvas c1("c1", "canvas", 500, 400);
236 c1.Print((m_rootfile+".ps[").c_str());
237 for(int i=0;i<wireNo;i++)
238 {
239 m_wiregain[i]->Draw();
240 c1.Print((m_rootfile+".ps").c_str());
241 }
242 c1.Print((m_rootfile+".ps]").c_str());
243
244 for(int i=0;i<wireNo;i++) delete m_wiregain[i];
245
246}
data SetBranchAddress("time",&time)
double Landau(double *x, double *par)
#define MaxADCValuecut
double Vavilov(double *x, double *par)
#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)
const int wireNo
IMessageSvc * msgSvc()
DedxCalibWireGain(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
vector< string > m_recFileVector
Definition: DedxCalib.h:48
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
TCanvas * c1
Definition: tau_mode.c:75