4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/StatusCode.h"
21 Algorithm(name, pSvcLocator), m_mdcCalFlg(0), m_flgKalFit(0), m_evtType(0){
24 m_configFile =
"NULL";
30 declareProperty(
"MdcCalFlg", m_mdcCalFlg);
31 declareProperty(
"MdcKalmanFlg", m_flgKalFit);
32 declareProperty(
"Event", m_evtType);
33 declareProperty(
"HistOutput", m_histname);
34 declareProperty(
"ConfigFile", m_configFile);
35 declareProperty(
"WirePosCorFile", m_wpcFile);
36 declareProperty(
"NumEvtDisplay", m_nEvtDisp);
37 declareProperty(
"DistCalib", m_distCalib);
38 declareProperty(
"Ecm", m_ecm = 3.686);
40 m_initCalConstFlg =
false;
45 std::cout <<
"m_constmgr deleted" << std::endl;
48 std::cout <<
"delete m_mdccalib" << std::endl;
51 std::cout <<
"m_mdcevt deleted" << std::endl;
54 std::cout <<
"m_hlist deleted" << std::endl;
57 std::cout <<
"m_calconst deleted" << std::endl;
60 std::ofstream fend(
"endcal.out");
61 fend <<
"MdcCalib end." << std::endl;
65 std::cout <<
"MdcCalibAlg End." << std::endl;
70 MsgStream log(
msgSvc(), name() );
71 log << MSG::INFO <<
"MdcCalibAlg initialze() ..." << endreq;
72 log << MSG::INFO <<
"MdcCalFlg = " << m_mdcCalFlg << endreq;
74 if(
"NULL"==m_histname){
75 log << MSG::ERROR <<
"not defined histogram file." << endreq;
76 return StatusCode::FAILURE;
78 if(
"NULL"==m_configFile){
79 log << MSG::ERROR <<
"not defined MdcCalibConfig file." << endreq;
80 return StatusCode::FAILURE;
83 StatusCode sc = service(
"MdcGeomSvc", m_mdcGeomSvc);
84 if(sc != StatusCode::SUCCESS){
85 log << MSG::ERROR <<
"can not use MdcGeomSvc" << endreq;
88 sc = service(
"MdcCalibFunSvc", m_mdcFunSvc);
89 if( sc != StatusCode::SUCCESS ){
90 log << MSG::FATAL <<
"can not use MdcCalibFunSvc" << endreq;
93 sc = service (
"MdcUtilitySvc", m_mdcUtilitySvc);
94 if ( sc.isFailure() ){
95 log << MSG::FATAL <<
"Could not load MdcUtilitySvc!" << endreq;
98 string estver = getenv(
"ESTIMEALGROOT");
99 cout <<
"EsTimeAlg_ver: "<< estver << endl;
107 std::string strconfig;
108 std::string strcomment;
112 for(i=0; i<50; i++) fgTes[i] = -999;
113 ifstream fconfig( m_configFile.c_str() );
114 if( ! fconfig.is_open() ){
115 log << MSG::ERROR <<
"can not open config file " << m_configFile
116 <<
". Use defalt config parameters" << endreq;
117 return StatusCode::FAILURE;
119 log << MSG::INFO <<
"Open config file " << m_configFile << endreq;
120 while( fconfig >> strconfig ){
121 if(
'#' == strconfig[0]){
122 getline(fconfig, strcomment);
123 }
else if(
"FillNtuple" == strconfig){
125 }
else if(
"nEvtNtuple" == strconfig){
127 }
else if(
"FlagCalDetEffi" == strconfig){
129 }
else if(
"BoostPar" == strconfig){
131 }
else if(
"EsTimeFlag" == strconfig){
132 getline(fconfig, strTes);
133 int n = sscanf(strTes.c_str(),
"%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
134 fgTes+0, fgTes+1, fgTes+2, fgTes+3, fgTes+4,
135 fgTes+5, fgTes+6, fgTes+7, fgTes+8, fgTes+9,
136 fgTes+10, fgTes+11, fgTes+12, fgTes+13, fgTes+14,
137 fgTes+15, fgTes+16, fgTes+17, fgTes+18, fgTes+19);
138 for(i=0; i<n; i++) m_param.
esFlag[i] = fgTes[i];
140 }
else if(
"TimeShift" == strconfig){
142 }
else if(
"TesMin" == strconfig){
143 fconfig >> m_param.
tesMin;
144 }
else if(
"TesMax" == strconfig){
145 fconfig >> m_param.
tesMax;
146 }
else if(
"FlagIniCalConst" == strconfig){
148 }
else if(
"FlagUpdateTmInPreT0" == strconfig){
150 }
else if(
"InitT0" == strconfig){
151 fconfig >> m_param.
initT0;
152 }
else if(
"T0Shift" == strconfig){
154 }
else if(
"TminFitChindf" == strconfig){
156 }
else if(
"TmaxFitChindf" == strconfig){
158 }
else if(
"InitSigma" == strconfig){
160 }
else if(
"UpdateSigma" == strconfig){
162 }
else if(
"ResidualType" == strconfig){
164 }
else if(
"FixXtC0" == strconfig){
166 }
else if(
"FixXtEdge" == strconfig){
168 }
else if(
"FlagAdjacLayerCut" == strconfig){
170 }
else if(
"FlagBoundLayerCut" == strconfig){
172 }
else if(
"hitStatCut" == strconfig){
174 }
else if(
"nTrkCut" == strconfig){
176 }
else if(
"nHitLayCut" == strconfig){
178 }
else if(
"nHitCut" == strconfig){
180 }
else if(
"noiseCut" == strconfig){
182 }
else if(
"cosThetaCut" == strconfig){
184 }
else if(
"DrCut" == strconfig){
185 fconfig >> m_param.
drCut;
186 }
else if(
"DzCut" == strconfig){
187 fconfig >> m_param.
dzCut;
188 }
else if(
"MaximalDocaInner" == strconfig){
190 }
else if(
"MaximalDocaOuter" == strconfig){
192 }
else if(
"RawTimeFitRange" == strconfig){
203 >> m_param.
qmax[lay];
218 cout <<
"EsFlag for Mdc Calibration: ";
219 for(
int iEs=0; iEs<m_param.
nEsFlag; iEs++) cout << setw(6) << m_param.
esFlag[iEs];
222 m_hlist =
new TObjArray(0);
227 m_mdcevt -> setParam(m_param);
228 m_mdcevt -> setGeomSvc(m_mdcGeomSvc);
229 m_mdcevt -> setUtilSvc(m_mdcUtilitySvc);
231 if( 0 == m_mdcCalFlg ){
233 }
else if( 1 == m_mdcCalFlg ){
235 }
else if( 2 == m_mdcCalFlg ){
237 }
else if( 3 == m_mdcCalFlg ){
239 }
else if( 4 == m_mdcCalFlg ){
241 }
else if( 9 == m_mdcCalFlg ){
243 }
else if( 5 == m_mdcCalFlg ){
245 }
else if( 6 == m_mdcCalFlg ){
247 }
else if( 7 == m_mdcCalFlg ){
249 }
else if( 8 == m_mdcCalFlg ){
253 m_constmgr -> init(m_mdcGeomSvc, m_mdcFunSvc);
255 m_mdccalib -> setParam(m_param);
256 m_mdccalib ->
initialize(m_hlist, m_mdcGeomSvc, m_mdcFunSvc, m_mdcUtilitySvc);
260 return StatusCode::SUCCESS;
265 MsgStream log(
msgSvc(), name());
266 log << MSG::DEBUG <<
"MdcCalibAlg execute()" << endreq;
269 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
271 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
272 return( StatusCode::FAILURE);
274 int iRun = eventHeader->runNumber();
275 int iEvt = eventHeader->eventNumber();
276 if(0 == (m_nEvt % m_nEvtDisp))
277 std::cout <<
"Run " << iRun <<
", Event " << iEvt <<
", Total Event number " << m_nEvt << endl;
282 if( ! m_initCalConstFlg ){
288 m_constmgr -> rdConstTcds(m_calconst);
289 m_initCalConstFlg =
true;
293 if(m_flgKalFit) m_mdcevt -> setKalEvent();
294 else m_mdcevt -> setRecEvent();
298 m_mdccalib -> fillHist(m_mdcevt);
302 return StatusCode::SUCCESS;
307 MsgStream log(
msgSvc(), name());
308 log << MSG::INFO <<
"MdcCalibAlg finalize()" << endreq;
310 gStyle -> SetCanvasBorderMode(0);
311 gStyle -> SetCanvasColor(10);
312 gStyle -> SetOptFit(0011);
313 gStyle -> SetStatColor(10);
314 gStyle -> SetStatBorderSize(1);
315 gStyle -> SetStatFont(42);
316 gStyle -> SetStatFontSize(0.04);
317 gStyle -> SetStatX(0.9);
318 gStyle -> SetStatY(0.9);
319 gStyle -> SetPadColor(10);
320 gStyle -> SetFuncColor(2);
324 m_mdccalib -> updateConst(m_calconst);
325 m_constmgr -> wrtConst( m_calconst );
329 TFile fhist(m_histname.c_str(),
"recreate");
332 std::cout << m_histname <<
" was written" << std::endl;
336 return StatusCode::SUCCESS;
339void MdcCalibAlg::initParam(){
349 for(
int i=0; i<50; i++) m_param.
esFlag[i] = -999;
375 m_param.
drCut = 50.0;
376 m_param.
dzCut = 300.0;
386 m_param.
initTm[lay] = 300.0;
388 m_param.
qmin[lay] = 400;
389 m_param.
qmax[lay] = 1000;
void setEvtNoOffline(int evtNo)
void setEvtNoOnline(int evtNo)
double initTm[MdcCalNLayer]
int fgCalib[MdcCalNLayer]
double tminFitRange[MdcCalNLayer][2]
double qmax[MdcCalNLayer]
double qmin[MdcCalNLayer]
double resiCut[MdcCalNLayer]
double tmaxFitRange[MdcCalNLayer][2]
MdcCalibAlg(const std::string &name, ISvcLocator *pSvcLocator)