BOSS 8.0.0
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 "TFile.h"
6#include "TTree.h"
7#include <fstream>
8#include <string>
9
11// DECLARE_COMPONENT(DedxCalib)
12DedxCalib::DedxCalib( const std::string& name, ISvcLocator* pSvcLocator )
13 : Algorithm( name, pSvcLocator ) {
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 MsgStream log( msgSvc(), name() );
26 log << MSG::INFO << "DedxCalib initialze()" << endmsg;
27
28 StatusCode gesc = service( "MdcGeomSvc", geosvc );
29 if ( gesc == StatusCode::SUCCESS ) { log << MSG::INFO << "MdcGeomSvc is running" << endmsg; }
30 else
31 {
32 log << MSG::ERROR << "MdcGeomSvc is failed" << endmsg;
33 return StatusCode::SUCCESS;
34 }
35
36 StatusCode scex = service( "DedxCorrecSvc", exsvc );
37 if ( scex == StatusCode::SUCCESS )
38 { log << MSG::INFO << "Hi, DedxCorrectSvc is running" << endl; }
39 else
40 {
41 log << MSG::ERROR << "DedxCorrectSvc is failed" << endl;
42 return StatusCode::SUCCESS;
43 }
44 exsvc->set_flag( m_calibflag );
45
47 BookHists();
49
50 return StatusCode::SUCCESS;
51}
52
53StatusCode DedxCalib::execute() {
54 MsgStream log( msgSvc(), name() );
55 log << MSG::INFO << "DedxCalib execute()" << endmsg;
56
57 genNtuple();
58 FillHists();
60 WriteHists();
61
62 return StatusCode::SUCCESS;
63}
64
65StatusCode DedxCalib::finalize() {
66 MsgStream log( msgSvc(), name() );
67 log << MSG::INFO << "DedxCalib finalize()" << endmsg;
68
69 return StatusCode::SUCCESS;
70}
71
73
75
77
79
81
83
85
86 MsgStream log( msgSvc(), name() );
87 log << MSG::INFO << "DedxCalib::ReadRecFileList()" << endmsg;
88
89 ifstream filea( m_recFileList.c_str(), ifstream::in );
90 cout << m_recFileList.c_str() << endl;
91
92 string runlist;
93 filea >> runlist;
94 do {
95 m_recFileVector.push_back( runlist );
96 cout << runlist.c_str() << endl;
97 filea >> runlist;
98 } while ( filea );
99}
100
101double DedxCalib::cal_dedx_bitrunc( float truncate, std::vector<double> phlist ) {
102 sort( phlist.begin(), phlist.end() );
103 int smpl = (int)( phlist.size() * ( truncate + 0.05 ) );
104 int min_cut = (int)( phlist.size() * 0.05 + 0.5 );
105 double qSum = 0;
106 unsigned i = 0;
107 for ( vector<double>::iterator ql = phlist.begin(); ql != phlist.end(); ql++ )
108 {
109 i++;
110 if ( i <= smpl && i >= min_cut ) qSum += ( *ql );
111 }
112 double trunc = -99;
113 int usedhit = smpl - min_cut + 1;
114 if ( usedhit > 0 ) trunc = qSum / usedhit;
115
116 return trunc;
117}
118
119double DedxCalib::cal_dedx( float truncate, std::vector<double> phlist ) {
120 sort( phlist.begin(), phlist.end() );
121 int smpl = (int)( phlist.size() * ( truncate + 0.05 ) );
122 int min_cut = 0;
123 double qSum = 0;
124 unsigned i = 0;
125 for ( vector<double>::iterator ql = phlist.begin(); ql != phlist.end(); ql++ )
126 {
127 i++;
128 if ( i <= smpl && i >= min_cut ) qSum += ( *ql );
129 }
130 double trunc = -99;
131 int usedhit = smpl - min_cut + 1;
132 if ( usedhit > 0 ) trunc = qSum / usedhit;
133
134 return trunc;
135}
136
138// void DedxCalib::getCurvePar(int runflag)
139{
140 if ( m_curvefile == "no rootfile" )
141 {
142 cout << "no curve file! can not calculate chi!!! " << endl;
143 return;
144 }
145
146 double Curve[100];
147 double Sigma[100];
148 int CurveSize, SigmaSize;
149 TFile* f = new TFile( m_curvefile.c_str() );
150 TTree* curve = (TTree*)f->Get( "curve" );
151 TTree* sigma = (TTree*)f->Get( "sigma" );
152 curve->SetBranchAddress( "CurveSize", &CurveSize );
153 curve->SetBranchAddress( "curve", Curve );
154 sigma->SetBranchAddress( "SigmaSize", &SigmaSize );
155 sigma->SetBranchAddress( "sigma", Sigma );
156 curve->GetEntry( 0 );
157 sigma->GetEntry( 0 );
158
159 for ( int i = 0; i < CurveSize; i++ ) // get the dedx curve parameters
160 {
161 cout << Curve[i] << endl;
162 if ( i == 0 ) vFlag[0] = (int)Curve[i]; // first element is dedx curve version
163 else Curve_Para.push_back( Curve[i] ); // dedx curve parameters
164 }
165 for ( int i = 0; i < SigmaSize; i++ )
166 {
167 cout << Sigma[i] << endl;
168 if ( i == 0 ) vFlag[1] = (int)Sigma[i]; // dedx sigma version: 2: psip; 3:jpsi
169 else Sigma_Para.push_back( Sigma[i] ); // dedx sigma parameters
170 }
171 // if(runflag>0) vFlag[2]=0;
172 // else vFlag[2]=1;
173}
174
175void DedxCalib::set_dEdx( int landau, float dEdx, int trkalg, int runflag, int dedxhit_use,
176 float ptrk, float theta, float pl_rp, int vflag[3], double t0 ) {
177 // landau: 1:landau distribution; 0:gaus distribution
178 // pl_rp: 1.5, not know what
179 // getCurvePar(runflag);
180 if ( runflag > 0 ) vFlag[2] = 0;
181 else vFlag[2] = 1;
182
183 // some old data with old methods
184 if ( runflag == 1 || runflag == 2 )
185 dedx_pid_exp_old( landau, runflag, (float)dEdx, (int)dedxhit_use, (float)ptrk,
186 (float)theta, (float)t0, (float)pl_rp, m_dedx_exp, m_ex_sigma,
188 // for 2009 psip data and after
189 else
190 dedx_pid_exp( vflag, (float)dEdx, trkalg, (int)dedxhit_use, (float)ptrk, (float)theta,
191 (float)t0, (float)pl_rp, m_dedx_exp, m_ex_sigma, m_pid_prob, m_chi_ex,
193}
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()
std::string m_curvefile
Definition DedxCalib.h:58
double m_chi_ex[5]
Definition DedxCalib.h:48
StatusCode finalize()
Definition DedxCalib.cxx:65
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:52
void ReadRecFileList()
Definition DedxCalib.cxx:84
int m_phShapeFlag
Definition DedxCalib.h:54
std::string m_rootfile
Definition DedxCalib.h:57
std::string m_recFileList
Definition DedxCalib.h:56
int vFlag[3]
Definition DedxCalib.h:41
virtual void genNtuple()=0
Definition DedxCalib.cxx:74
vector< double > Sigma_Para
Definition DedxCalib.h:40
virtual void WriteHists()=0
Definition DedxCalib.cxx:82
void getCurvePar()
double m_pid_prob[5]
Definition DedxCalib.h:47
IDedxCorrecSvc * exsvc
Definition DedxCalib.h:29
vector< double > Curve_Para
Definition DedxCalib.h:39
virtual void AnalyseHists()=0
Definition DedxCalib.cxx:80
StatusCode execute()
Definition DedxCalib.cxx:53
double m_dedx_exp[5]
Definition DedxCalib.h:45
virtual void BookHists()=0
Definition DedxCalib.cxx:76
StatusCode initialize()
Definition DedxCalib.cxx:24
double cal_dedx_bitrunc(float truncate, std::vector< double > phlist)
double m_ex_sigma[5]
Definition DedxCalib.h:46
virtual void FillHists()=0
Definition DedxCalib.cxx:78
vector< string > m_recFileVector
Definition DedxCalib.h:50
virtual void initializing()=0
Definition DedxCalib.cxx:72
IMdcGeomSvc * geosvc
Definition DedxCalib.h:28
int m_calibflag
Definition DedxCalib.h:53
std::string m_eventType
Definition DedxCalib.h:55
float truncate
Definition DedxCalib.h:32