BOSS 6.6.4.p03
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
11
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];
31 stringstream hlabel;
32 for(int i=0; i<runNo; i++)
33 {
34 hlabel.str("");
35 hlabel<<"dEdx_Run_"<<i;
36 m_rungain[i] = new TH1F(hlabel.str().c_str(), hlabel.str().c_str(),NumHistBins,MinHistValue1,MaxHistValue1);
37 }
38}
39
41{
42 MsgStream log(msgSvc(), name());
43 log<<MSG::INFO<<"DedxCalibRunByRun::FillHists()"<<endreq;
44
45 TFile* f;
46 TTree* n103;
47 string runlist;
48
49 int ndedxhit=0;
50 double dEdx[100]={0},pathlength[100]={0},wid[100]={0},layid[100]={0},dd_in[100]={0},eangle[100]={0},zhit[100]={0};
51 double dedx=0;
52 float runNO=0,runFlag=0,costheta=0,tes=0;
53 vector<double> phlist;
54 for(int i=0; i<runNo; i++)
55 {
56 runlist = m_recFileVector[i];
57 f = new TFile(runlist.c_str());
58 n103 = (TTree*)f->Get("n103");
59 n103-> SetBranchAddress("ndedxhit", &ndedxhit);
60 n103-> SetBranchAddress("dEdx_hit",dEdx);
61 n103-> SetBranchAddress("pathlength_hit",pathlength);
62 n103-> SetBranchAddress("wid_hit",wid);
63 n103-> SetBranchAddress("layid_hit",layid);
64 n103-> SetBranchAddress("dd_in_hit",dd_in);
65 n103-> SetBranchAddress("eangle_hit",eangle);
66 n103-> SetBranchAddress("zhit_hit",zhit);
67 n103-> SetBranchAddress("runNO",&runNO);
68 n103-> SetBranchAddress("runFlag",&runFlag);
69 n103-> SetBranchAddress("costheta",&costheta);
70 n103-> SetBranchAddress("t0",&tes);
71 for(int j=0;j<n103->GetEntries();j++)
72 {
73 phlist.clear();
74 n103->GetEntry(j);
75 for(int k=0;k<ndedxhit;k++)
76 {
77 dEdx[k] = exsvc->StandardHitCorrec(0,runFlag,2,runNO,pathlength[k],wid[k],layid[k],dEdx[k],dd_in[k],eangle[k],costheta);
78 phlist.push_back(dEdx[k]);
79 }
80 dedx = cal_dedx_bitrunc(truncate, phlist);
81 dedx = exsvc->StandardTrackCorrec(0, runFlag, 2, runNO, dedx, costheta, tes);
82 m_rungain[i]->Fill(dedx);
83 m_hist->Fill(dedx);
84 }
85 cout<<"runNO = "<<runNO<<endl;
86 m_runNOVector.push_back(runNO);
87 }
88}
89
91{
92 MsgStream log(msgSvc(), name());
93 log<<MSG::INFO<<"DedxCalibRunByRun::AnalyseHists()"<<endreq;
94
95 m_hist->Fit("gaus", "Q" );
96 for(int i=0; i<runNo; i++)
97 {
98 m_rungain[i]->Fit("gaus", "Q" );
99 }
100}
101
103{
104 MsgStream log(msgSvc(), name());
105 log<<MSG::INFO<<"DedxCalibRunByRun::WriteHists()"<<endreq;
106
107 TFile* f = new TFile(m_rootfile.c_str(), "recreate");
108
109 Double_t gainpar=0, resolpar=0;
110 gainpar = m_hist -> GetFunction("gaus") -> GetParameter(1);
111 resolpar = m_hist -> GetFunction("gaus") -> GetParameter(2);
112
113 TTree* gain = new TTree("gaincalib", "gaincalib");
114 gain -> Branch("gain", &gainpar, "gain[1]/D");
115 gain->Fill();
116 TTree* resol = new TTree("resolcalib", "resolcalib");
117 resol -> Branch("resol", &resolpar, "resol[1]/D");
118 resol->Fill();
119
120 Int_t runno=0;
121 Double_t runmean=0, rungain=0, runresol=0;
122 TTree* runbyrun = new TTree("runcalib", "runcalib");
123 runbyrun -> Branch("runno", &runno, "runno/I");
124 runbyrun -> Branch("runmean", &runmean, "runmean/D");
125 runbyrun -> Branch("rungain", &rungain, "rungain/D");
126 runbyrun -> Branch("runresol", &runresol, "runresol/D");
127 for(int i=0; i<runNo; i++)
128 {
129 runno = m_runNOVector[i];
130 runmean = m_rungain[i] -> GetFunction("gaus") -> GetParameter(1);
131 runresol = m_rungain[i] -> GetFunction("gaus") -> GetParameter(2);
132 rungain = runmean/NormalMean;
133 cout<<"i = "<<i<<" runno = "<<runno <<" @ runmean = "<<runmean<<" @ rungain = "<<rungain<<" @ runresol = "<<runresol<<endl;
134 runbyrun -> Fill();
135 }
136
137 m_hist->Write();
138 for(int i=0; i<runNo; i++) m_rungain[i]->Write();
139 gain->Write();
140 resol -> Write();
141 runbyrun -> Write();
142
143 delete m_hist;
144 for(int i=0; i<runNo; i++) delete m_rungain[i];
145 delete gain;
146 delete resol;
147 delete runbyrun;
148 f->Close();
149}
data SetBranchAddress("time",&time)
#define MinHistValue1
#define MaxHistValue1
#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)
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, 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