BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalibRunByRun.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2
3#include "TF1.h"
4#include "TFile.h"
5#include "TH1F.h"
6#include "TTree.h"
7#include <sstream>
8#include <string>
9
12using namespace std;
13
14int runNo = 0;
15
16DedxCalibRunByRun::DedxCalibRunByRun( const std::string& name, ISvcLocator* pSvcLocator )
17 : DedxCalib( name, pSvcLocator ) {}
18
20 MsgStream log( msgSvc(), name() );
21 log << MSG::INFO << "DedxCalibRunByRun::BookHists()" << endmsg;
22
24 runNo = m_recFileVector.size();
25
26 m_hist = new TH1F( "dEdx_allRun", "dEdx_allRun", NumHistBins, MinHistValue1, MaxHistValue1 );
27 m_hist->GetXaxis()->SetTitle( "dE/dx" );
28 m_hist->GetYaxis()->SetTitle( "entries" );
29 m_rungain = new TH1F*[runNo * NumEvtBlocksInRun];
30 stringstream hlabel;
31 for ( int i = 0; i < runNo; i++ )
32 {
33 for ( int j = 0; j < NumEvtBlocksInRun; j++ )
34 {
35 hlabel.str( "" );
36 hlabel << "dEdx_Run_" << i << "_sub_" << j;
37 m_rungain[i * NumEvtBlocksInRun + j] =
38 new TH1F( hlabel.str().c_str(), hlabel.str().c_str(), NumHistBins, MinHistValue1,
40 }
41 }
42}
43
45 MsgStream log( msgSvc(), name() );
46 log << MSG::INFO << "DedxCalibRunByRun::FillHists()" << endmsg;
47
48 TFile* f;
49 TTree* n103;
50 string runlist;
51
52 int ndedxhit = 0;
53 double dEdx[100] = { 0 }, pathlength[100] = { 0 }, wid[100] = { 0 }, layid[100] = { 0 },
54 dd_in[100] = { 0 }, eangle[100] = { 0 }, zhit[100] = { 0 };
55 double dedx = 0;
56 float runNO = 0, evtNO = 0, runFlag = 0, costheta = 0, tes = 0;
57 vector<double> phlist;
58 for ( int i = 0; i < runNo; i++ )
59 {
60 runlist = m_recFileVector[i];
61 f = new TFile( runlist.c_str() );
62 n103 = (TTree*)f->Get( "n103" );
63 n103->SetBranchAddress( "ndedxhit", &ndedxhit );
64 n103->SetBranchAddress( "dEdx_hit", dEdx );
65 n103->SetBranchAddress( "pathlength_hit", pathlength );
66 n103->SetBranchAddress( "wid_hit", wid );
67 n103->SetBranchAddress( "layid_hit", layid );
68 n103->SetBranchAddress( "dd_in_hit", dd_in );
69 n103->SetBranchAddress( "eangle_hit", eangle );
70 n103->SetBranchAddress( "zhit_hit", zhit );
71 n103->SetBranchAddress( "runNO", &runNO );
72 n103->SetBranchAddress( "evtNO", &evtNO );
73 n103->SetBranchAddress( "runFlag", &runFlag );
74 n103->SetBranchAddress( "costheta", &costheta );
75 n103->SetBranchAddress( "t0", &tes );
76 int m( 0 ); // count for events in a block
77 int index( 0 );
78 float evtfrom( 0 );
79 struct runevt m_runevt;
80 for ( int j = 0; j < n103->GetEntries(); j++ )
81 {
82 phlist.clear();
83 n103->GetEntry( j );
84 for ( int k = 0; k < ndedxhit; k++ )
85 {
86 dEdx[k] = exsvc->StandardHitCorrec( 0, runFlag, 2, runNO, evtNO, pathlength[k], wid[k],
87 layid[k], dEdx[k], dd_in[k], eangle[k], costheta );
88 phlist.push_back( dEdx[k] );
89 }
90 dedx = cal_dedx_bitrunc( truncate, phlist );
91 dedx = exsvc->StandardTrackCorrec( 0, runFlag, 2, runNO, evtNO, dedx, costheta, tes );
92 m_rungain[i * NumEvtBlocksInRun + index]->Fill( dedx );
93 m_hist->Fill( dedx );
94 m++;
95 if ( m == NumEvtInBlocks )
96 {
97 m_runevt.runno = runNO;
98 m_runevt.evtfrom = evtfrom;
99 m_runevt.evtto = evtNO;
100 m_runevt.global_index = i * NumEvtBlocksInRun + index;
101 m_runevt.local_index = index;
102 m_evtNOVector.push_back( m_runevt );
103 evtfrom = evtNO + 1;
104 index++;
105 m = 0;
106 }
107 if ( index == NumEvtBlocksInRun )
108 {
109 log << MSG::FATAL << "DedxCalibRunByRun: Too many events in a run!!!" << endmsg;
110 break;
111 }
112 }
113 if ( index ) m_evtNOVector.pop_back();
114 else
115 {
116 m_runevt.runno = runNO;
117 m_runevt.evtfrom = 0;
118 m_runevt.global_index = i * NumEvtBlocksInRun;
119 m_runevt.local_index = 0;
120 }
121 m_runevt.evtto = MaxNumEvt;
122 m_evtNOVector.push_back( m_runevt );
123 cout << "runNO = " << m_runevt.runno << endl;
124 }
125}
126
128 MsgStream log( msgSvc(), name() );
129 log << MSG::INFO << "DedxCalibRunByRun::AnalyseHists()" << endmsg;
130
131 m_hist->Fit( "gaus", "Q" );
132 for ( int i = 0; i < runNo; i++ )
133 {
134 for ( int j = 0; j < NumEvtBlocksInRun; j++ )
135 { m_rungain[i * NumEvtBlocksInRun + j]->Fit( "gaus", "Q" ); }
136 }
137}
138
140 MsgStream log( msgSvc(), name() );
141 log << MSG::INFO << "DedxCalibRunByRun::WriteHists()" << endmsg;
142
143 TFile* f = new TFile( m_rootfile.c_str(), "recreate" );
144
145 Double_t gainpar = 0, resolpar = 0;
146 gainpar = m_hist->GetFunction( "gaus" )->GetParameter( 1 );
147 resolpar = m_hist->GetFunction( "gaus" )->GetParameter( 2 );
148
149 TTree* gain = new TTree( "gaincalib", "gaincalib" );
150 gain->Branch( "gain", &gainpar, "gain[1]/D" );
151 gain->Fill();
152 TTree* resol = new TTree( "resolcalib", "resolcalib" );
153 resol->Branch( "resol", &resolpar, "resol[1]/D" );
154 resol->Fill();
155
156 Int_t runno( 0 ), evtfrom( 0 ), evtto( 0 ), index( 0 ), global_index( 0 );
157 Double_t runmean = 0, rungain = 0, runresol = 0;
158 TTree* runbyrun = new TTree( "runcalib", "runcalib" );
159 runbyrun->Branch( "runno", &runno, "runno/I" );
160 runbyrun->Branch( "index", &index, "index/I" );
161 runbyrun->Branch( "evtfrom", &evtfrom, "evtfrom/I" );
162 runbyrun->Branch( "evtto", &evtto, "evtto/I" );
163 runbyrun->Branch( "runmean", &runmean, "runmean/D" );
164 runbyrun->Branch( "rungain", &rungain, "rungain/D" );
165 runbyrun->Branch( "runresol", &runresol, "runresol/D" );
166 vector<struct runevt>::iterator p;
167 p = m_evtNOVector.begin();
168 while ( p != m_evtNOVector.end() )
169 {
170 runno = ( *p ).runno;
171 evtfrom = ( *p ).evtfrom;
172 evtto = ( *p ).evtto;
173 index = ( *p ).local_index;
174 global_index = ( *p ).global_index;
175 runmean = m_rungain[global_index]->GetFunction( "gaus" )->GetParameter( 1 );
176 runresol = m_rungain[global_index]->GetFunction( "gaus" )->GetParameter( 2 );
177 rungain = runmean / NormalMean;
178 cout << " runno = " << runno << " @ evtfrom = " << evtfrom << " @ evtto " << evtto
179 << " @ index " << index << " @ runmean = " << runmean
180 << " @ rungain = " << rungain << " @ runresol = " << runresol << endl;
181 runbyrun->Fill();
182 m_rungain[global_index]->Write();
183 p++;
184 }
185
186 m_hist->Write();
187 gain->Write();
188 resol->Write();
189 runbyrun->Write();
190
191 delete m_hist;
192 for ( int i = 0; i < runNo; i++ )
193 {
194 for ( int j = 0; j < NumEvtBlocksInRun; j++ ) delete m_rungain[i * NumEvtBlocksInRun + j];
195 }
196 delete gain;
197 delete resol;
198 delete runbyrun;
199 f->Close();
200}
DECLARE_COMPONENT(BesBdkRc)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
int runNo
Definition DQA_TO_DB.cxx:13
#define MinHistValue1
#define MaxHistValue1
#define NumEvtBlocksInRun
#define NumEvtInBlocks
#define MaxNumEvt
IMessageSvc * msgSvc()
DedxCalibRunByRun(const std::string &name, ISvcLocator *pSvcLocator)
DedxCalib(const std::string &name, ISvcLocator *pSvcLocator)
Definition DedxCalib.cxx:12
void ReadRecFileList()
Definition DedxCalib.cxx:84
std::string m_rootfile
Definition DedxCalib.h:57
IDedxCorrecSvc * exsvc
Definition DedxCalib.h:29
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
vector< string > m_recFileVector
Definition DedxCalib.h:50
float truncate
Definition DedxCalib.h:32