BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcCalibAlg.cxx
Go to the documentation of this file.
1// MdcCalibAlg
2// 2006/01/09 Wu Linghui IHEP
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/StatusCode.h"
6
9
12#include "GaudiKernel/DataSvc.h"
16
17#include <iostream>
18#include <fstream>
19#include <cstring>
20
21#include "TStyle.h"
22
23using namespace Event;
24
25/////////////////////////////////////////////////////////////////////////////
26DECLARE_COMPONENT(MdcCalibAlg)
27MdcCalibAlg::MdcCalibAlg(const std::string& name, ISvcLocator* pSvcLocator) :
28 Algorithm(name, pSvcLocator), m_mdcCalFlg(0), m_flgKalFit(0), m_evtType(0){
29
30 m_histname = "NULL";
31 m_configFile = "NULL";
32 m_nEvtDisp = 1000;
33 m_distCalib = false;
34 m_nEvt = 0;
35
36 // declare properties
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);
48
49 m_initCalConstFlg = false;
50}
51
53 delete m_constmgr;
54 std::cout << "m_constmgr deleted" << std::endl;
55
56 delete m_mdccalib;
57 std::cout << "delete m_mdccalib" << std::endl;
58
59 delete m_mdcevt;
60 std::cout << "m_mdcevt deleted" << std::endl;
61
62 delete m_hlist;
63 std::cout << "m_hlist deleted" << std::endl;
64
65 delete m_calconst;
66 std::cout << "m_calconst deleted" << std::endl;
67
68 std::ofstream fend("endcal.out");
69 fend << "MdcCalib end." << std::endl;
70 fend.close();
71
72 std::cout << "MdcCalibAlg End." << std::endl;
73}
74
75// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
77 MsgStream log( msgSvc(), name() );
78 log << MSG::INFO << "MdcCalibAlg initialze() ..." << endreq;
79 log << MSG::INFO << "MdcCalFlg = " << m_mdcCalFlg << endreq;
80
81 if("NULL"==m_histname){
82 log << MSG::ERROR << "not defined histogram file." << endreq;
83 return StatusCode::FAILURE;
84 }
85 if("NULL"==m_configFile){
86 log << MSG::ERROR << "not defined MdcCalibConfig file." << endreq;
87 return StatusCode::FAILURE;
88 }
89
90 StatusCode sc = service("MdcGeomSvc", m_mdcGeomSvc);
91 if(sc != StatusCode::SUCCESS){
92 log << MSG::ERROR << "can not use MdcGeomSvc" << endreq;
93 }
94
95 sc = service("MdcCalibFunSvc", m_mdcFunSvc);
96 if( sc != StatusCode::SUCCESS ){
97 log << MSG::FATAL << "can not use MdcCalibFunSvc" << endreq;
98 }
99
100 sc = service ("MdcUtilitySvc", m_mdcUtilitySvc);
101 if ( sc.isFailure() ){
102 log << MSG::FATAL << "Could not load MdcUtilitySvc!" << endreq;
103 }
104
105 string estver = getenv("ESTIMEALGROOT");
106 cout << "EsTimeAlg_ver: "<< estver << endl;
107
108 // initialize m_param
109 initParam();
110
111 // read mdc config parameters
112 int i;
113 int lay;
114 std::string strconfig;
115 std::string strcomment;
116 std::string strtmp;
117 std::string strTes;
118 int fgTes[50];
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;
125 } else {
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){
131 fconfig >> m_param.fillNtuple;
132 } else if("nEvtNtuple" == strconfig){
133 fconfig >> m_param.nEvtNtuple;
134 }else if("FlagCalDetEffi" == strconfig){
135 fconfig >> m_param.fgCalDetEffi;
136 }else if("BoostPar" == strconfig){
137 fconfig >> m_param.boostPar[0] >> m_param.boostPar[1] >> m_param.boostPar[2];
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];
148 m_param.nEsFlag = n;
149 } else if("TimeShift" == strconfig){
150 fconfig >> m_param.timeShift;
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){
156 fconfig >> m_param.fgIniCalConst;
157 } else if("FlagUpdateTmInPreT0" == strconfig){
158 fconfig >> m_param.preT0SetTm;
159 } else if("InitT0" == strconfig){
160 fconfig >> m_param.initT0;
161 } else if("T0Shift" == strconfig){
162 fconfig >> m_param.t0Shift;
163 } else if("TminFitChindf" == strconfig){
164 fconfig >> m_param.tminFitChindf;
165 } else if("TmaxFitChindf" == strconfig){
166 fconfig >> m_param.tmaxFitChindf;
167 } else if("InitSigma" == strconfig){
168 fconfig >> m_param.initSigma;
169 } else if("UpdateSigma" == strconfig){
170 fconfig >> m_param.calSigma;
171 } else if("ResidualType" == strconfig){
172 fconfig >> m_param.resiType;
173 } else if("FixXtC0" == strconfig){
174 fconfig >> m_param.fixXtC0;
175 } else if("FixXtEdge" == strconfig){
176 fconfig >> m_param.fixXtEdge;
177 } else if("FlagAdjacLayerCut" == strconfig){
178 fconfig >> m_param.fgAdjacLayerCut;
179 } else if("FlagBoundLayerCut" == strconfig){
180 fconfig >> m_param.fgBoundLayerCut;
181 } else if("hitStatCut" == strconfig){
182 fconfig >> m_param.hitStatCut;
183 } else if("nTrkCut" == strconfig){
184 fconfig >> m_param.nTrkCut[0] >> m_param.nTrkCut[1];
185 } else if("nHitLayCut" == strconfig){
186 fconfig >> m_param.nHitLayCut;
187 } else if("nHitCut" == strconfig){
188 fconfig >> m_param.nHitCut;
189 } else if("noiseCut" == strconfig){
190 fconfig >> m_param.noiseCut;
191 } else if("cosmicDwTrk" == strconfig){
192 fconfig >> m_param.cosmicDwTrk;
193 } else if("cosThetaCut" == strconfig){
194 fconfig >> m_param.costheCut[0] >> m_param.costheCut[1];
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){
202 fconfig >> m_param.maxDocaInner;
203 }else if("MaximalDocaOuter" == strconfig){
204 fconfig >> m_param.maxDocaOuter;
205 } else if("charge" == strconfig){
206 fconfig >> m_param.charge;
207 } else if("RawTimeFitRange" == strconfig){
208 for(lay=0; lay<MdcCalNLayer; lay++){
209 fconfig >> strtmp
210 >> m_param.fgCalib[lay]
211 >> m_param.tminFitRange[lay][0]
212 >> m_param.tminFitRange[lay][1]
213 >> m_param.tmaxFitRange[lay][0]
214 >> m_param.tmaxFitRange[lay][1]
215 >> m_param.initTm[lay]
216 >> m_param.resiCut[lay]
217 >> m_param.qmin[lay]
218 >> m_param.qmax[lay];
219 }
220 }
221 }
222 fconfig.close();
223 }
224 // set single wire position calibration file
225 m_param.wpcFile = m_wpcFile;
226
227 // set event type
228 m_param.particle = m_evtType;
229
230 // set Ecm
231 m_param.ecm = m_ecm;
232
233 m_param.fgCombinePlusMinue = m_combPM;
234
235 cout << "EsFlag for Mdc Calibration: ";
236 for(int iEs=0; iEs<m_param.nEsFlag; iEs++) cout << setw(6) << m_param.esFlag[iEs];
237 cout << endl;
238
239 ifstream fwirecal(m_fileWireNoCal.c_str());
240 if(fwirecal.is_open()){
241 cout << "open single wire calibration file: " << m_fileWireNoCal << endl;
242 int wid;
243 getline(fwirecal, strtmp);
244 cout << strtmp << endl;
245 while(fwirecal >> wid){
246 m_param.fgWireCal[wid] = 0;
247 cout << "Wire " << wid << endl;
248 }
249 fwirecal.close();
250 }
251
252 m_hlist = new TObjArray(0);
253 m_constmgr = new MdcCalConstMgr();
254 m_calconst = new MdcCalibConst();
255
256 m_mdcevt = new MdcCalEvent();
257 m_mdcevt -> setParam(m_param);
258 m_mdcevt -> setGeomSvc(m_mdcGeomSvc);
259 m_mdcevt -> setUtilSvc(m_mdcUtilitySvc);
260
261 if( 0 == m_mdcCalFlg ){
262 m_mdccalib = new IniMdcCalib();
263 }else if( 1 == m_mdcCalFlg ){
264 m_mdccalib = new PreXtMdcCalib();
265 }else if( 2 == m_mdcCalFlg ){
266 m_mdccalib = new PreT0MdcCalib();
267 }else if( 3 == m_mdcCalFlg ){
268 m_mdccalib = new XtMdcCalib();
269 }else if( 4 == m_mdcCalFlg ){
270 m_mdccalib = new GrXtMdcCalib();
271 }else if( 9 == m_mdcCalFlg ){
272 m_mdccalib = new XtInteMdcCalib();
273 }else if( 5 == m_mdcCalFlg ){
274 m_mdccalib = new T0MdcCalib();
275 }else if( 6 == m_mdcCalFlg ){
276 m_mdccalib = new WrMdcCalib();
277 }else if( 7 == m_mdcCalFlg ){
278 m_mdccalib = new Wr2dMdcCalib();
279 }else if( 8 == m_mdcCalFlg ){
280 m_mdccalib = new QtMdcCalib();
281 }
282 // initialize and read the calibraion data from TCDS
283 m_constmgr -> init(m_mdcGeomSvc, m_mdcFunSvc);
284
285 m_mdccalib -> setParam(m_param);
286 m_mdccalib -> initialize(m_hlist, m_mdcGeomSvc, m_mdcFunSvc, m_mdcUtilitySvc);
287
288// if(0 == m_mdcCalFlg) m_calconst->initCalibConst();
289
290 return StatusCode::SUCCESS;
291}
292
293// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
295 MsgStream log(msgSvc(), name());
296 log << MSG::DEBUG << "MdcCalibAlg execute()" << endreq;
297
298 // display event number for debug
299 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
300 if (!eventHeader) {
301 log << MSG::FATAL << "Could not find Event Header" << endreq;
302 return( StatusCode::FAILURE);
303 }
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;
308 }
309
310 if(m_nEvt<=1){
311 IDataProviderSvc* pCalibDataSvc;
312 StatusCode sc = service("CalibDataSvc", pCalibDataSvc, true);
313 if ( !sc.isSuccess() ) {
314 log << MSG::ERROR
315 << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
316 << endreq;
317 return sc;
318 }
319
320 std::string fullPath = "/Calib/EsTimeCal";
321 SmartDataPtr<CalibData::EsTimeCalibData> TEst(pCalibDataSvc, fullPath);
322 if(!TEst){ cout<<"ERROR EsTimeCalibData"<<endl;}
323 else{
324 int no = TEst->getTestCalibConstNo();
325 cout <<"offset barrel t0="<< TEst->getToffsetb()
326 <<" , offset endcap t0="<< TEst->getToffsete()
327 <<" , bunch time ="<<TEst->getBunchTime()
328 <<endl;
329 // double t0offset_b=TEst->getToffsetb();
330 // double t0offset_e=TEst->getToffsete();
331 // double bunchtime=TEst->getBunchTime();
332 }
333 }
334
335 m_mdcevt->setEvtNoOnline(iEvt);
336 m_mdcevt->setEvtNoOffline(m_nEvt);
337
338 if( ! m_initCalConstFlg ){
339// if((0 == m_mdcCalFlg) && (0 == m_param.fgIniCalConst)){
340// m_calconst->initCalibConst();
341// } else{
342// m_constmgr -> rdConstTcds(m_calconst);
343// }
344 m_constmgr -> rdConstTcds(m_calconst);
345 m_initCalConstFlg = true;
346 }
347
348 if(m_mdcCalFlg > 1){
349 if(m_flgKalFit) m_mdcevt -> setKalEvent();
350 else m_mdcevt -> setRecEvent();
351 }
352
353 // fill histograms
354 m_mdccalib -> fillHist(m_mdcevt);
355 m_mdcevt -> clear();
356 m_nEvt++;
357
358 return StatusCode::SUCCESS;
359}
360
361// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
363 MsgStream log(msgSvc(), name());
364 log << MSG::INFO << "MdcCalibAlg finalize()" << endreq;
365
366 gStyle -> SetCanvasBorderMode(0);
367 gStyle -> SetCanvasColor(10);
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);
377
378 // execute calibration and write new calibration data file
379 m_mdccalib -> printCut();
380 if(!m_distCalib){
381 m_mdccalib -> updateConst(m_calconst);
382 m_constmgr -> wrtConst( m_calconst );
383 }
384
385 // write histogram file
386 TFile fhist(m_histname.c_str(), "recreate");
387 m_hlist -> Write();
388 fhist.Close();
389 std::cout << m_histname << " was written" << std::endl;
390
391 // m_mdccalib->clear();
392
393 return StatusCode::SUCCESS;
394}
395
396void MdcCalibAlg::initParam(){
397 m_param.fillNtuple = 0;
398 m_param.nEvtNtuple = 10000;
399 m_param.fgCalDetEffi = 0;
400 m_param.ecm = 3.686;
401 m_param.boostPar[0] = 0.011;
402 m_param.boostPar[1] = 0.0;
403 m_param.boostPar[2] = 0.0;
404 m_param.particle = 0;
405 m_param.esCut = true;
406 m_param.nEsFlag = 0;
407 for(int i=0; i<50; i++) m_param.esFlag[i] = -999;
408 m_param.timeShift = 0.0;
409 m_param.tesMin = 0.0;
410 m_param.tesMax = 9999.0;
411 m_param.fgIniCalConst = 2;
412 m_param.preT0SetTm = true;
413 m_param.initT0 = 50.0;
414 m_param.timeShift = 0.0;
415 m_param.t0Shift = 0.0;
416 m_param.tminFitChindf = 20.0;
417 m_param.tmaxFitChindf = 20.0;
418 m_param.initSigma = 0.16; // mm
419 m_param.resiType = 1;
420 m_param.resiType = 0;
421 m_param.fixXtC0 = 0;
422 m_param.fixXtEdge = 0;
423 m_param.fgAdjacLayerCut = 0;
424 m_param.fgBoundLayerCut = 0;
425 m_param.hitStatCut = 0;
426 m_param.nTrkCut[0] = 2;
427 m_param.nTrkCut[1] = 2;
428 m_param.nHitLayCut = 35;
429 m_param.nHitCut = 0;
430 m_param.noiseCut = false;
431 m_param.cosmicDwTrk = false;
432 m_param.costheCut[0] = -1.0;
433 m_param.costheCut[1] = 1.0;
434 m_param.pCut[0] = 0.0; // GeV
435 m_param.pCut[1] = 10.0; // GeV
436 m_param.drCut = 50.0; // mm
437 m_param.dzCut = 300.0; // mm
438 m_param.maxDocaInner = 8.0; // mm
439 m_param.maxDocaOuter = 12.0; // mm
440 m_param.charge = 0;
441
442 for(int lay=0; lay<MdcCalNLayer; lay++){
443 m_param.fgCalib[lay] = 1;
444 m_param.tminFitRange[lay][0] = 0.0;
445 m_param.tminFitRange[lay][1] = 100.0;
446 m_param.tmaxFitRange[lay][0] = 120.0;
447 m_param.tmaxFitRange[lay][1] = 400.0;
448 m_param.initTm[lay] = 300.0;
449 m_param.resiCut[lay] = 1.2;
450 m_param.qmin[lay] = 400;
451 m_param.qmax[lay] = 1000;
452 }
453
454 for(int i=0; i<MdcCalTotCell; i++) m_param.fgWireCal[i] = 1;
455}
const int no
curve Write()
const Int_t n
const int MdcCalNLayer
Definition MdcCalParams.h:6
const int MdcCalTotCell
Definition MdcCalParams.h:9
IMessageSvc * msgSvc()
gStyle SetCanvasColor(0)
void setEvtNoOffline(int evtNo)
Definition MdcCalEvent.h:39
void setEvtNoOnline(int evtNo)
Definition MdcCalEvent.h:36
double maxDocaOuter
double initTm[MdcCalNLayer]
double costheCut[2]
int fgCalib[MdcCalNLayer]
std::string wpcFile
double pCut[2]
double tminFitRange[MdcCalNLayer][2]
double initSigma
double maxDocaInner
bool fgCombinePlusMinue
double boostPar[3]
double qmax[MdcCalNLayer]
double tminFitChindf
double timeShift
int esFlag[50]
double qmin[MdcCalNLayer]
double tmaxFitChindf
double resiCut[MdcCalNLayer]
int fgWireCal[MdcCalTotCell]
double tmaxFitRange[MdcCalNLayer][2]
StatusCode execute()
StatusCode initialize()
StatusCode finalize()
Definition Event.h:21