BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxCalib.cxx
Go to the documentation of this file.
1#include "GaudiKernel/Bootstrap.h"
2#include "GaudiKernel/PropertyMgr.h"
3#include "GaudiKernel/StatusCode.h"
4
5#include <fstream>
6#include <string>
7#include "TFile.h"
8#include "TTree.h"
9
11//DECLARE_COMPONENT(DedxCalib)
12DedxCalib::DedxCalib(const std::string& name, ISvcLocator* pSvcLocator) : Algorithm(name, pSvcLocator)
13{
14 declareProperty("ParticleType",ParticleFlag=-1);
15 declareProperty("EventType", m_eventType = "isBhabha");
16 declareProperty("CalibFlag",m_calibflag=63);
17 declareProperty("PhShapeFlag",m_phShapeFlag=0);
18 declareProperty("TruncRate",truncate = 0.7);
19 declareProperty("RecFileList", m_recFileList = "no file");
20 declareProperty("RootFile",m_rootfile = "no file");
21 declareProperty("CurveFile",m_curvefile = std::string("no rootfile"));
22}
23
25{
26 MsgStream log(msgSvc(), name());
27 log << MSG::INFO << "DedxCalib initialze()" << endreq;
28
29 StatusCode gesc = service("MdcGeomSvc", geosvc);
30 if (gesc == StatusCode::SUCCESS)
31 {
32 log << MSG::INFO <<"MdcGeomSvc is running"<<endreq;
33 }
34 else
35 {
36 log << MSG::ERROR <<"MdcGeomSvc is failed"<<endreq;
37 return StatusCode::SUCCESS;
38 }
39
40 StatusCode scex = service("DedxCorrecSvc", exsvc);
41 if (scex == StatusCode::SUCCESS) {
42 log << MSG::INFO <<"Hi, DedxCorrectSvc is running"<<endl;
43 } else {
44 log << MSG::ERROR <<"DedxCorrectSvc is failed"<<endl;
45 return StatusCode::SUCCESS;
46 }
48
50 BookHists();
52
53 return StatusCode::SUCCESS;
54}
55
57{
58 MsgStream log(msgSvc(), name());
59 log << MSG::INFO << "DedxCalib execute()" << endreq;
60
61 genNtuple();
62 FillHists();
64 WriteHists();
65
66 return StatusCode::SUCCESS;
67}
68
70{
71 MsgStream log(msgSvc(), name());
72 log << MSG::INFO << "DedxCalib finalize()" << endreq;
73
74 return StatusCode::SUCCESS;
75}
76
78
80
82
84
86
88
90{
91
92 MsgStream log(msgSvc(), name());
93 log<<MSG::INFO<<"DedxCalib::ReadRecFileList()"<<endreq;
94
95 ifstream filea(m_recFileList.c_str(),ifstream::in);
96 cout<<m_recFileList.c_str()<<endl;
97
98 string runlist;
99 filea>>runlist;
100 do
101 {
102 m_recFileVector.push_back(runlist);
103 cout<<runlist.c_str()<<endl;
104 filea>>runlist;
105 }while(filea);
106}
107
108double DedxCalib::cal_dedx_bitrunc(float truncate, std::vector<double> phlist)
109{
110 sort(phlist.begin(),phlist.end());
111 int smpl = (int)(phlist.size()*(truncate+0.05));
112 int min_cut = (int)( phlist.size()*0.05 + 0.5 );
113 double qSum = 0;
114 unsigned i = 0;
115 for(vector<double>::iterator ql= phlist.begin();ql!=phlist.end();ql++)
116 {
117 i++;
118 if(i<= smpl && i>=min_cut ) qSum += (*ql);
119 }
120 double trunc=-99;
121 int usedhit = smpl-min_cut+1;
122 if(usedhit>0) trunc=qSum/usedhit;
123
124 return trunc;
125}
126
127double DedxCalib::cal_dedx(float truncate, std::vector<double> phlist)
128{
129 sort(phlist.begin(),phlist.end());
130 int smpl = (int)(phlist.size()*(truncate+0.05));
131 int min_cut = 0;
132 double qSum = 0;
133 unsigned i = 0;
134 for(vector<double>::iterator ql= phlist.begin();ql!=phlist.end();ql++)
135 {
136 i++;
137 if(i<= smpl && i>=min_cut ) qSum += (*ql);
138 }
139 double trunc=-99;
140 int usedhit = smpl-min_cut+1;
141 if(usedhit>0) trunc=qSum/usedhit;
142
143 return trunc;
144}
145
147//void DedxCalib::getCurvePar(int runflag)
148{
149 if(m_curvefile=="no rootfile")
150 {
151 cout<<"no curve file! can not calculate chi!!! "<<endl;
152 return;
153 }
154
155 double Curve[100];
156 double Sigma[100];
158 TFile* f = new TFile(m_curvefile.c_str());
159 TTree *curve = (TTree*) f->Get("curve");
160 TTree *sigma = (TTree*) f->Get("sigma");
161 curve->SetBranchAddress("CurveSize",&CurveSize);
162 curve->SetBranchAddress("curve",Curve);
163 sigma->SetBranchAddress("SigmaSize",&SigmaSize);
164 sigma->SetBranchAddress("sigma",Sigma);
165 curve->GetEntry(0);
166 sigma->GetEntry(0);
167
168 for(int i=0; i<CurveSize; i++) // get the dedx curve parameters
169 {
170 cout<<Curve[i]<<endl;
171 if(i==0) vFlag[0] = (int) Curve[i]; //first element is dedx curve version
172 else Curve_Para.push_back(Curve[i]); //dedx curve parameters
173 }
174 for(int i=0; i<SigmaSize; i++)
175 {
176 cout<<Sigma[i]<<endl;
177 if(i==0) vFlag[1] = (int) Sigma[i]; //dedx sigma version: 2: psip; 3:jpsi
178 else Sigma_Para.push_back(Sigma[i]); //dedx sigma parameters
179 }
180 //if(runflag>0) vFlag[2]=0;
181 //else vFlag[2]=1;
182}
183
184void DedxCalib::set_dEdx( int landau, float dEdx, int trkalg, int runflag, int dedxhit_use, float ptrk, float theta, float pl_rp, int vflag[3] , double t0)
185{
186 //landau: 1:landau distribution; 0:gaus distribution
187 //pl_rp: 1.5, not know what
188 //getCurvePar(runflag);
189 if(runflag>0) vFlag[2]=0;
190 else vFlag[2]=1;
191
192 //some old data with old methods
193 if(runflag ==1 || runflag ==2 )
194 dedx_pid_exp_old( landau, runflag, (float)dEdx, (int)dedxhit_use,
195 (float)ptrk, (float)theta, (float)t0,(float)pl_rp,
197 //for 2009 psip data and after
198 else
199 dedx_pid_exp( vflag, (float)dEdx, trkalg,(int)dedxhit_use,
200 (float)ptrk, (float)theta, (float)t0,(float)pl_rp,
202}
TTree * sigma
ifstream filea("../CurConstRoot/DedxCurConst_data_minrun-maxrun_bossversion.dat", ifstream::in)
int SigmaSize
TTree * curve
int CurveSize
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
void dedx_pid_exp_old(int landau, int runflag, float dedx, int Nohit, float mom, float theta, float t0, float lsamp, double dedx_exp[5], double ex_sigma[5], double pid_prob[5], double chi_dedx[5])
void dedx_pid_exp(int vflag[3], float dedx, int trkalg, int Nohit, float mom, float theta, float t0, float lsamp, double dedx_exp[5], double ex_sigma[5], double pid_prob[5], double chi_dedx[5], std::vector< double > &par, std::vector< double > &sig_par)
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for Sigma
Definition FoamA.h:83
IMessageSvc * msgSvc()
int vflag[3]
Curve parameter vars.
std::string m_curvefile
Definition DedxCalib.h:56
double m_chi_ex[5]
Definition DedxCalib.h:46
StatusCode finalize()
Definition DedxCalib.cxx:69
void set_dEdx(int landau, float dEdx, int trkalg, int runflag, int dedxhit_use, float ptrk, float theta, float pl_rp, int vflag[3], double t0)
double cal_dedx(float truncate, std::vector< double > phlist)
DedxCalib(const std::string &name, ISvcLocator *pSvcLocator)
Definition DedxCalib.cxx:12
int ParticleFlag
Definition DedxCalib.h:50
void ReadRecFileList()
Definition DedxCalib.cxx:89
int m_phShapeFlag
Definition DedxCalib.h:52
std::string m_rootfile
Definition DedxCalib.h:55
std::string m_recFileList
Definition DedxCalib.h:54
int vFlag[3]
Definition DedxCalib.h:41
virtual void genNtuple()=0
Definition DedxCalib.cxx:79
vector< double > Sigma_Para
Definition DedxCalib.h:40
virtual void WriteHists()=0
Definition DedxCalib.cxx:87
void getCurvePar()
double m_pid_prob[5]
Definition DedxCalib.h:45
IDedxCorrecSvc * exsvc
Definition DedxCalib.h:30
vector< double > Curve_Para
Definition DedxCalib.h:39
virtual void AnalyseHists()=0
Definition DedxCalib.cxx:85
StatusCode execute()
Definition DedxCalib.cxx:56
double m_dedx_exp[5]
Definition DedxCalib.h:43
virtual void BookHists()=0
Definition DedxCalib.cxx:81
StatusCode initialize()
Definition DedxCalib.cxx:24
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
double m_ex_sigma[5]
Definition DedxCalib.h:44
virtual void FillHists()=0
Definition DedxCalib.cxx:83
vector< string > m_recFileVector
Definition DedxCalib.h:48
virtual void initializing()=0
Definition DedxCalib.cxx:77
IMdcGeomSvc * geosvc
Definition DedxCalib.h:29
int m_calibflag
Definition DedxCalib.h:51
std::string m_eventType
Definition DedxCalib.h:53
float truncate
Definition DedxCalib.h:33
virtual void set_flag(int calib_F)=0
double Curve[100]
float ptrk