4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/StatusCode.h"
12#include "GaudiKernel/DataSvc.h"
28 Algorithm(name, pSvcLocator), m_mdcCalFlg(0), m_flgKalFit(0), m_evtType(0){
31 m_configFile =
"NULL";
37 declareProperty(
"MdcCalFlg", m_mdcCalFlg);
38 declareProperty(
"MdcKalmanFlg", m_flgKalFit);
39 declareProperty(
"Event", m_evtType);
40 declareProperty(
"HistOutput", m_histname);
41 declareProperty(
"ConfigFile", m_configFile);
42 declareProperty(
"WirePosCorFile", m_wpcFile);
43 declareProperty(
"WireNoCal", m_fileWireNoCal);
44 declareProperty(
"NumEvtDisplay", m_nEvtDisp);
45 declareProperty(
"DistCalib", m_distCalib);
46 declareProperty(
"Ecm", m_ecm = 3.686);
47 declareProperty(
"CombinePlusMinus", m_combPM =
false);
49 m_initCalConstFlg =
false;
54 std::cout <<
"m_constmgr deleted" << std::endl;
57 std::cout <<
"delete m_mdccalib" << std::endl;
60 std::cout <<
"m_mdcevt deleted" << std::endl;
63 std::cout <<
"m_hlist deleted" << std::endl;
66 std::cout <<
"m_calconst deleted" << std::endl;
68 std::ofstream fend(
"endcal.out");
69 fend <<
"MdcCalib end." << std::endl;
72 std::cout <<
"MdcCalibAlg End." << std::endl;
77 MsgStream log(
msgSvc(), name() );
78 log << MSG::INFO <<
"MdcCalibAlg initialze() ..." << endreq;
79 log << MSG::INFO <<
"MdcCalFlg = " << m_mdcCalFlg << endreq;
81 if(
"NULL"==m_histname){
82 log << MSG::ERROR <<
"not defined histogram file." << endreq;
83 return StatusCode::FAILURE;
85 if(
"NULL"==m_configFile){
86 log << MSG::ERROR <<
"not defined MdcCalibConfig file." << endreq;
87 return StatusCode::FAILURE;
90 StatusCode sc = service(
"MdcGeomSvc", m_mdcGeomSvc);
91 if(sc != StatusCode::SUCCESS){
92 log << MSG::ERROR <<
"can not use MdcGeomSvc" << endreq;
95 sc = service(
"MdcCalibFunSvc", m_mdcFunSvc);
96 if( sc != StatusCode::SUCCESS ){
97 log << MSG::FATAL <<
"can not use MdcCalibFunSvc" << endreq;
100 sc = service (
"MdcUtilitySvc", m_mdcUtilitySvc);
101 if ( sc.isFailure() ){
102 log << MSG::FATAL <<
"Could not load MdcUtilitySvc!" << endreq;
105 string estver = getenv(
"ESTIMEALGROOT");
106 cout <<
"EsTimeAlg_ver: "<< estver << endl;
114 std::string strconfig;
115 std::string strcomment;
119 for(i=0; i<50; i++) fgTes[i] = -999;
120 ifstream fconfig( m_configFile.c_str() );
121 if( ! fconfig.is_open() ){
122 log << MSG::ERROR <<
"can not open config file " << m_configFile
123 <<
". Use defalt config parameters" << endreq;
124 return StatusCode::FAILURE;
126 log << MSG::INFO <<
"Open config file " << m_configFile << endreq;
127 while( fconfig >> strconfig ){
128 if(
'#' == strconfig[0]){
129 getline(fconfig, strcomment);
130 }
else if(
"FillNtuple" == strconfig){
132 }
else if(
"nEvtNtuple" == strconfig){
134 }
else if(
"FlagCalDetEffi" == strconfig){
136 }
else if(
"BoostPar" == strconfig){
138 }
else if(
"EsTimeCut" == strconfig){
139 fconfig >> m_param.
esCut;
140 }
else if(
"EsTimeFlag" == strconfig){
141 getline(fconfig, strTes);
142 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",
143 fgTes+0, fgTes+1, fgTes+2, fgTes+3, fgTes+4,
144 fgTes+5, fgTes+6, fgTes+7, fgTes+8, fgTes+9,
145 fgTes+10, fgTes+11, fgTes+12, fgTes+13, fgTes+14,
146 fgTes+15, fgTes+16, fgTes+17, fgTes+18, fgTes+19);
147 for(i=0; i<
n; i++) m_param.
esFlag[i] = fgTes[i];
149 }
else if(
"TimeShift" == strconfig){
151 }
else if(
"TesMin" == strconfig){
152 fconfig >> m_param.
tesMin;
153 }
else if(
"TesMax" == strconfig){
154 fconfig >> m_param.
tesMax;
155 }
else if(
"FlagIniCalConst" == strconfig){
157 }
else if(
"FlagUpdateTmInPreT0" == strconfig){
159 }
else if(
"InitT0" == strconfig){
160 fconfig >> m_param.
initT0;
161 }
else if(
"T0Shift" == strconfig){
163 }
else if(
"TminFitChindf" == strconfig){
165 }
else if(
"TmaxFitChindf" == strconfig){
167 }
else if(
"InitSigma" == strconfig){
169 }
else if(
"UpdateSigma" == strconfig){
171 }
else if(
"ResidualType" == strconfig){
173 }
else if(
"FixXtC0" == strconfig){
175 }
else if(
"FixXtEdge" == strconfig){
177 }
else if(
"FlagAdjacLayerCut" == strconfig){
179 }
else if(
"FlagBoundLayerCut" == strconfig){
181 }
else if(
"hitStatCut" == strconfig){
183 }
else if(
"nTrkCut" == strconfig){
185 }
else if(
"nHitLayCut" == strconfig){
187 }
else if(
"nHitCut" == strconfig){
189 }
else if(
"noiseCut" == strconfig){
191 }
else if(
"cosmicDwTrk" == strconfig){
193 }
else if(
"cosThetaCut" == strconfig){
195 }
else if(
"pCut" == strconfig){
196 fconfig >> m_param.
pCut[0] >> m_param.
pCut[1];
197 }
else if(
"DrCut" == strconfig){
198 fconfig >> m_param.
drCut;
199 }
else if(
"DzCut" == strconfig){
200 fconfig >> m_param.
dzCut;
201 }
else if(
"MaximalDocaInner" == strconfig){
203 }
else if(
"MaximalDocaOuter" == strconfig){
205 }
else if(
"charge" == strconfig){
206 fconfig >> m_param.
charge;
207 }
else if(
"RawTimeFitRange" == strconfig){
218 >> m_param.
qmax[lay];
235 cout <<
"EsFlag for Mdc Calibration: ";
236 for(
int iEs=0; iEs<m_param.
nEsFlag; iEs++) cout << setw(6) << m_param.
esFlag[iEs];
239 ifstream fwirecal(m_fileWireNoCal.c_str());
240 if(fwirecal.is_open()){
241 cout <<
"open single wire calibration file: " << m_fileWireNoCal << endl;
243 getline(fwirecal, strtmp);
244 cout << strtmp << endl;
245 while(fwirecal >> wid){
247 cout <<
"Wire " << wid << endl;
252 m_hlist =
new TObjArray(0);
257 m_mdcevt -> setParam(m_param);
258 m_mdcevt -> setGeomSvc(m_mdcGeomSvc);
259 m_mdcevt -> setUtilSvc(m_mdcUtilitySvc);
261 if( 0 == m_mdcCalFlg ){
263 }
else if( 1 == m_mdcCalFlg ){
265 }
else if( 2 == m_mdcCalFlg ){
267 }
else if( 3 == m_mdcCalFlg ){
269 }
else if( 4 == m_mdcCalFlg ){
271 }
else if( 9 == m_mdcCalFlg ){
273 }
else if( 5 == m_mdcCalFlg ){
275 }
else if( 6 == m_mdcCalFlg ){
277 }
else if( 7 == m_mdcCalFlg ){
279 }
else if( 8 == m_mdcCalFlg ){
283 m_constmgr -> init(m_mdcGeomSvc, m_mdcFunSvc);
285 m_mdccalib -> setParam(m_param);
286 m_mdccalib ->
initialize(m_hlist, m_mdcGeomSvc, m_mdcFunSvc, m_mdcUtilitySvc);
290 return StatusCode::SUCCESS;
295 MsgStream log(
msgSvc(), name());
296 log << MSG::DEBUG <<
"MdcCalibAlg execute()" << endreq;
299 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
301 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
302 return( StatusCode::FAILURE);
304 int iRun = eventHeader->runNumber();
305 int iEvt = eventHeader->eventNumber();
306 if(0 == (m_nEvt % m_nEvtDisp)){
307 std::cout <<
"Run " << iRun <<
", Event " << iEvt <<
", Total Event number " << m_nEvt << endl;
311 IDataProviderSvc* pCalibDataSvc;
312 StatusCode sc = service(
"CalibDataSvc", pCalibDataSvc,
true);
313 if ( !sc.isSuccess() ) {
315 <<
"Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
320 std::string fullPath =
"/Calib/EsTimeCal";
321 SmartDataPtr<CalibData::EsTimeCalibData> TEst(pCalibDataSvc, fullPath);
322 if(!TEst){ cout<<
"ERROR EsTimeCalibData"<<endl;}
324 int no = TEst->getTestCalibConstNo();
325 cout <<
"offset barrel t0="<< TEst->getToffsetb()
326 <<
" , offset endcap t0="<< TEst->getToffsete()
327 <<
" , bunch time ="<<TEst->getBunchTime()
338 if( ! m_initCalConstFlg ){
344 m_constmgr -> rdConstTcds(m_calconst);
345 m_initCalConstFlg =
true;
349 if(m_flgKalFit) m_mdcevt -> setKalEvent();
350 else m_mdcevt -> setRecEvent();
354 m_mdccalib -> fillHist(m_mdcevt);
358 return StatusCode::SUCCESS;
363 MsgStream log(
msgSvc(), name());
364 log << MSG::INFO <<
"MdcCalibAlg finalize()" << endreq;
366 gStyle -> SetCanvasBorderMode(0);
368 gStyle -> SetOptFit(0011);
369 gStyle -> SetStatColor(10);
370 gStyle -> SetStatBorderSize(1);
371 gStyle -> SetStatFont(42);
372 gStyle -> SetStatFontSize(0.04);
373 gStyle -> SetStatX(0.9);
374 gStyle -> SetStatY(0.9);
375 gStyle -> SetPadColor(10);
376 gStyle -> SetFuncColor(2);
379 m_mdccalib -> printCut();
381 m_mdccalib -> updateConst(m_calconst);
382 m_constmgr -> wrtConst( m_calconst );
386 TFile fhist(m_histname.c_str(),
"recreate");
389 std::cout << m_histname <<
" was written" << std::endl;
393 return StatusCode::SUCCESS;
396void MdcCalibAlg::initParam(){
405 m_param.
esCut =
true;
407 for(
int i=0; i<50; i++) m_param.
esFlag[i] = -999;
434 m_param.
pCut[0] = 0.0;
435 m_param.
pCut[1] = 10.0;
436 m_param.
drCut = 50.0;
437 m_param.
dzCut = 300.0;
448 m_param.
initTm[lay] = 300.0;
450 m_param.
qmin[lay] = 400;
451 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]
int fgWireCal[MdcCalTotCell]
double tmaxFitRange[MdcCalNLayer][2]