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