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