BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcCalibAlg Class Reference

#include <MdcCalibAlg.h>

Inheritance diagram for MdcCalibAlg:

Public Member Functions

 MdcCalibAlg (const std::string &name, ISvcLocator *pSvcLocator)
 ~MdcCalibAlg ()
StatusCode initialize ()
StatusCode execute ()
StatusCode finalize ()

Detailed Description

Definition at line 40 of file MdcCalibAlg.h.

Constructor & Destructor Documentation

◆ MdcCalibAlg()

MdcCalibAlg::MdcCalibAlg ( const std::string & name,
ISvcLocator * pSvcLocator )

Definition at line 26 of file MdcCalibAlg.cxx.

27 : Algorithm( name, pSvcLocator ), m_mdcCalFlg( 0 ), m_flgKalFit( 0 ), m_evtType( 0 ) {
28
29 m_histname = "NULL";
30 m_configFile = "NULL";
31 m_nEvtDisp = 1000;
32 m_distCalib = false;
33 m_nEvt = 0;
34
35 // declare properties
36 declareProperty( "MdcCalFlg", m_mdcCalFlg );
37 declareProperty( "MdcKalmanFlg", m_flgKalFit );
38 declareProperty( "Event", m_evtType );
39 declareProperty( "HistOutput", m_histname );
40 declareProperty( "ConfigFile", m_configFile );
41 declareProperty( "WirePosCorFile", m_wpcFile );
42 declareProperty( "WireNoCal", m_fileWireNoCal );
43 declareProperty( "NumEvtDisplay", m_nEvtDisp );
44 declareProperty( "DistCalib", m_distCalib );
45 declareProperty( "Ecm", m_ecm = 3.686 );
46 declareProperty( "CombinePlusMinus", m_combPM = false );
47
48 m_initCalConstFlg = false;
49}

Referenced by MdcCalibAlg().

◆ ~MdcCalibAlg()

MdcCalibAlg::~MdcCalibAlg ( )

Definition at line 51 of file MdcCalibAlg.cxx.

51 {
52 delete m_constmgr;
53 std::cout << "m_constmgr deleted" << std::endl;
54
55 delete m_mdccalib;
56 std::cout << "delete m_mdccalib" << std::endl;
57
58 delete m_mdcevt;
59 std::cout << "m_mdcevt deleted" << std::endl;
60
61 delete m_hlist;
62 std::cout << "m_hlist deleted" << std::endl;
63
64 delete m_calconst;
65 std::cout << "m_calconst deleted" << std::endl;
66
67 std::ofstream fend( "endcal.out" );
68 fend << "MdcCalib end." << std::endl;
69 fend.close();
70
71 std::cout << "MdcCalibAlg End." << std::endl;
72}

Member Function Documentation

◆ execute()

StatusCode MdcCalibAlg::execute ( )

Definition at line 251 of file MdcCalibAlg.cxx.

251 {
252 MsgStream log( msgSvc(), name() );
253 log << MSG::DEBUG << "MdcCalibAlg execute()" << endmsg;
254
255 // display event number for debug
256 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
257 if ( !eventHeader )
258 {
259 log << MSG::FATAL << "Could not find Event Header" << endmsg;
260 return ( StatusCode::FAILURE );
261 }
262 int iRun = eventHeader->runNumber();
263 int iEvt = eventHeader->eventNumber();
264 if ( 0 == ( m_nEvt % m_nEvtDisp ) )
265 {
266 std::cout << "Run " << iRun << ", Event " << iEvt << ", Total Event number " << m_nEvt
267 << endl;
268 }
269
270 if ( m_nEvt <= 1 )
271 {
272 IDataProviderSvc* pCalibDataSvc;
273 StatusCode sc = service( "CalibDataSvc", pCalibDataSvc, true );
274 if ( !sc.isSuccess() )
275 {
276 log << MSG::ERROR << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
277 << endmsg;
278 return sc;
279 }
280
281 std::string fullPath = "/Calib/EsTimeCal";
282 SmartDataPtr<CalibData::EsTimeCalibData> TEst( pCalibDataSvc, fullPath );
283 if ( !TEst ) { cout << "ERROR EsTimeCalibData" << endl; }
284 else
285 {
286 int no = TEst->getTestCalibConstNo();
287 cout << "offset barrel t0=" << TEst->getToffsetb()
288 << " , offset endcap t0=" << TEst->getToffsete()
289 << " , bunch time =" << TEst->getBunchTime() << endl;
290 // double t0offset_b=TEst->getToffsetb();
291 // double t0offset_e=TEst->getToffsete();
292 // double bunchtime=TEst->getBunchTime();
293 }
294 }
295
296 m_mdcevt->setEvtNoOnline( iEvt );
297 m_mdcevt->setEvtNoOffline( m_nEvt );
298
299 if ( !m_initCalConstFlg )
300 {
301 // if((0 == m_mdcCalFlg) && (0 == m_param.fgIniCalConst)){
302 // m_calconst->initCalibConst();
303 // } else{
304 // m_constmgr -> rdConstTcds(m_calconst);
305 // }
306 m_constmgr->rdConstTcds( m_calconst );
307 m_initCalConstFlg = true;
308 }
309
310 if ( m_mdcCalFlg > 1 )
311 {
312 if ( m_flgKalFit ) m_mdcevt->setKalEvent();
313 else m_mdcevt->setRecEvent();
314 }
315
316 // fill histograms
317 m_mdccalib->fillHist( m_mdcevt );
318 m_mdcevt->clear();
319 m_nEvt++;
320
321 return StatusCode::SUCCESS;
322}
IMessageSvc * msgSvc()

◆ finalize()

StatusCode MdcCalibAlg::finalize ( )

Definition at line 325 of file MdcCalibAlg.cxx.

325 {
326 MsgStream log( msgSvc(), name() );
327 log << MSG::INFO << "MdcCalibAlg finalize()" << endmsg;
328
329 gStyle->SetCanvasBorderMode( 0 );
330 gStyle->SetCanvasColor( 10 );
331 gStyle->SetOptFit( 0011 );
332 gStyle->SetStatColor( 10 );
333 gStyle->SetStatBorderSize( 1 );
334 gStyle->SetStatFont( 42 );
335 gStyle->SetStatFontSize( 0.04 );
336 gStyle->SetStatX( 0.9 );
337 gStyle->SetStatY( 0.9 );
338 gStyle->SetPadColor( 10 );
339 gStyle->SetFuncColor( 2 );
340
341 // execute calibration and write new calibration data file
342 m_mdccalib->printCut();
343 if ( !m_distCalib )
344 {
345 m_mdccalib->updateConst( m_calconst );
346 m_constmgr->wrtConst( m_calconst );
347 }
348
349 // write histogram file
350 TFile fhist( m_histname.c_str(), "recreate" );
351 m_hlist->Write();
352 fhist.Close();
353 std::cout << m_histname << " was written" << std::endl;
354
355 // m_mdccalib->clear();
356
357 return StatusCode::SUCCESS;
358}

◆ initialize()

StatusCode MdcCalibAlg::initialize ( )

Definition at line 75 of file MdcCalibAlg.cxx.

75 {
76 MsgStream log( msgSvc(), name() );
77 log << MSG::INFO << "MdcCalibAlg initialze() ..." << endmsg;
78 log << MSG::INFO << "MdcCalFlg = " << m_mdcCalFlg << endmsg;
79
80 if ( "NULL" == m_histname )
81 {
82 log << MSG::ERROR << "not defined histogram file." << endmsg;
83 return StatusCode::FAILURE;
84 }
85 if ( "NULL" == m_configFile )
86 {
87 log << MSG::ERROR << "not defined MdcCalibConfig file." << endmsg;
88 return StatusCode::FAILURE;
89 }
90
91 StatusCode sc = service( "MdcGeomSvc", m_mdcGeomSvc );
92 if ( sc != StatusCode::SUCCESS ) { log << MSG::ERROR << "can not use MdcGeomSvc" << endmsg; }
93
94 sc = service( "MdcCalibFunSvc", m_mdcFunSvc );
95 if ( sc != StatusCode::SUCCESS )
96 { log << MSG::FATAL << "can not use MdcCalibFunSvc" << endmsg; }
97
98 sc = service( "MdcUtilitySvc", m_mdcUtilitySvc );
99 if ( sc.isFailure() ) { log << MSG::FATAL << "Could not load MdcUtilitySvc!" << endmsg; }
100
101 string estver = getenv( "ESTIMEALGROOT" );
102 cout << "EsTimeAlg_ver: " << estver << endl;
103
104 // initialize m_param
105 initParam();
106
107 // read mdc config parameters
108 int i;
109 int lay;
110 std::string strconfig;
111 std::string strcomment;
112 std::string strtmp;
113 std::string strTes;
114 int fgTes[50];
115 for ( i = 0; i < 50; i++ ) fgTes[i] = -999;
116 ifstream fconfig( m_configFile.c_str() );
117 if ( !fconfig.is_open() )
118 {
119 log << MSG::ERROR << "can not open config file " << m_configFile
120 << ". Use defalt config parameters" << endmsg;
121 return StatusCode::FAILURE;
122 }
123 else
124 {
125 log << MSG::INFO << "Open config file " << m_configFile << endmsg;
126 while ( fconfig >> strconfig )
127 {
128 if ( '#' == strconfig[0] ) { getline( fconfig, strcomment ); }
129 else if ( "FillNtuple" == strconfig ) { fconfig >> m_param.fillNtuple; }
130 else if ( "nEvtNtuple" == strconfig ) { fconfig >> m_param.nEvtNtuple; }
131 else if ( "FlagCalDetEffi" == strconfig ) { fconfig >> m_param.fgCalDetEffi; }
132 else if ( "BoostPar" == strconfig )
133 { fconfig >> m_param.boostPar[0] >> m_param.boostPar[1] >> m_param.boostPar[2]; }
134 else if ( "EsTimeCut" == strconfig ) { fconfig >> m_param.esCut; }
135 else if ( "EsTimeFlag" == strconfig )
136 {
137 getline( fconfig, strTes );
138 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", fgTes + 0,
139 fgTes + 1, fgTes + 2, fgTes + 3, fgTes + 4, fgTes + 5, fgTes + 6,
140 fgTes + 7, fgTes + 8, fgTes + 9, fgTes + 10, fgTes + 11, fgTes + 12,
141 fgTes + 13, fgTes + 14, fgTes + 15, fgTes + 16, fgTes + 17, fgTes + 18,
142 fgTes + 19 );
143 for ( i = 0; i < n; i++ ) m_param.esFlag[i] = fgTes[i];
144 m_param.nEsFlag = n;
145 }
146 else if ( "TimeShift" == strconfig ) { fconfig >> m_param.timeShift; }
147 else if ( "TesMin" == strconfig ) { fconfig >> m_param.tesMin; }
148 else if ( "TesMax" == strconfig ) { fconfig >> m_param.tesMax; }
149 else if ( "FlagIniCalConst" == strconfig ) { fconfig >> m_param.fgIniCalConst; }
150 else if ( "FlagUpdateTmInPreT0" == strconfig ) { fconfig >> m_param.preT0SetTm; }
151 else if ( "InitT0" == strconfig ) { fconfig >> m_param.initT0; }
152 else if ( "T0Shift" == strconfig ) { fconfig >> m_param.t0Shift; }
153 else if ( "TminFitChindf" == strconfig ) { fconfig >> m_param.tminFitChindf; }
154 else if ( "TmaxFitChindf" == strconfig ) { fconfig >> m_param.tmaxFitChindf; }
155 else if ( "InitSigma" == strconfig ) { fconfig >> m_param.initSigma; }
156 else if ( "UpdateSigma" == strconfig ) { fconfig >> m_param.calSigma; }
157 else if ( "ResidualType" == strconfig ) { fconfig >> m_param.resiType; }
158 else if ( "FixXtC0" == strconfig ) { fconfig >> m_param.fixXtC0; }
159 else if ( "FixXtEdge" == strconfig ) { fconfig >> m_param.fixXtEdge; }
160 else if ( "FlagAdjacLayerCut" == strconfig ) { fconfig >> m_param.fgAdjacLayerCut; }
161 else if ( "FlagBoundLayerCut" == strconfig ) { fconfig >> m_param.fgBoundLayerCut; }
162 else if ( "hitStatCut" == strconfig ) { fconfig >> m_param.hitStatCut; }
163 else if ( "nTrkCut" == strconfig )
164 { fconfig >> m_param.nTrkCut[0] >> m_param.nTrkCut[1]; }
165 else if ( "nHitLayCut" == strconfig ) { fconfig >> m_param.nHitLayCut; }
166 else if ( "nHitCut" == strconfig ) { fconfig >> m_param.nHitCut; }
167 else if ( "noiseCut" == strconfig ) { fconfig >> m_param.noiseCut; }
168 else if ( "cosmicDwTrk" == strconfig ) { fconfig >> m_param.cosmicDwTrk; }
169 else if ( "cosThetaCut" == strconfig )
170 { fconfig >> m_param.costheCut[0] >> m_param.costheCut[1]; }
171 else if ( "pCut" == strconfig ) { fconfig >> m_param.pCut[0] >> m_param.pCut[1]; }
172 else if ( "DrCut" == strconfig ) { fconfig >> m_param.drCut; }
173 else if ( "DzCut" == strconfig ) { fconfig >> m_param.dzCut; }
174 else if ( "MaximalDocaInner" == strconfig ) { fconfig >> m_param.maxDocaInner; }
175 else if ( "MaximalDocaOuter" == strconfig ) { fconfig >> m_param.maxDocaOuter; }
176 else if ( "charge" == strconfig ) { fconfig >> m_param.charge; }
177 else if ( "RawTimeFitRange" == strconfig )
178 {
179 for ( lay = 0; lay < MdcCalNLayer; lay++ )
180 {
181 fconfig >> strtmp >> m_param.fgCalib[lay] >> m_param.tminFitRange[lay][0] >>
182 m_param.tminFitRange[lay][1] >> m_param.tmaxFitRange[lay][0] >>
183 m_param.tmaxFitRange[lay][1] >> m_param.initTm[lay] >> m_param.resiCut[lay] >>
184 m_param.qmin[lay] >> m_param.qmax[lay];
185 }
186 }
187 }
188 fconfig.close();
189 }
190 // set single wire position calibration file
191 m_param.wpcFile = m_wpcFile;
192
193 // set event type
194 m_param.particle = m_evtType;
195
196 // set Ecm
197 m_param.ecm = m_ecm;
198
199 m_param.fgCombinePlusMinue = m_combPM;
200
201 cout << "EsFlag for Mdc Calibration: ";
202 for ( int iEs = 0; iEs < m_param.nEsFlag; iEs++ ) cout << setw( 6 ) << m_param.esFlag[iEs];
203 cout << endl;
204
205 ifstream fwirecal( m_fileWireNoCal.c_str() );
206 if ( fwirecal.is_open() )
207 {
208 cout << "open single wire calibration file: " << m_fileWireNoCal << endl;
209 int wid;
210 getline( fwirecal, strtmp );
211 cout << strtmp << endl;
212 while ( fwirecal >> wid )
213 {
214 m_param.fgWireCal[wid] = 0;
215 cout << "Wire " << wid << endl;
216 }
217 fwirecal.close();
218 }
219
220 m_hlist = new TObjArray( 0 );
221 m_constmgr = new MdcCalConstMgr();
222 m_calconst = new MdcCalibConst();
223
224 m_mdcevt = new MdcCalEvent();
225 m_mdcevt->setParam( m_param );
226 m_mdcevt->setGeomSvc( m_mdcGeomSvc );
227 m_mdcevt->setUtilSvc( m_mdcUtilitySvc );
228
229 if ( 0 == m_mdcCalFlg ) { m_mdccalib = new IniMdcCalib(); }
230 else if ( 1 == m_mdcCalFlg ) { m_mdccalib = new PreXtMdcCalib(); }
231 else if ( 2 == m_mdcCalFlg ) { m_mdccalib = new PreT0MdcCalib(); }
232 else if ( 3 == m_mdcCalFlg ) { m_mdccalib = new XtMdcCalib(); }
233 else if ( 4 == m_mdcCalFlg ) { m_mdccalib = new GrXtMdcCalib(); }
234 else if ( 9 == m_mdcCalFlg ) { m_mdccalib = new XtInteMdcCalib(); }
235 else if ( 5 == m_mdcCalFlg ) { m_mdccalib = new T0MdcCalib(); }
236 else if ( 6 == m_mdcCalFlg ) { m_mdccalib = new WrMdcCalib(); }
237 else if ( 7 == m_mdcCalFlg ) { m_mdccalib = new Wr2dMdcCalib(); }
238 else if ( 8 == m_mdcCalFlg ) { m_mdccalib = new QtMdcCalib(); }
239 // initialize and read the calibraion data from TCDS
240 m_constmgr->init( m_mdcGeomSvc, m_mdcFunSvc );
241
242 m_mdccalib->setParam( m_param );
243 m_mdccalib->initialize( m_hlist, m_mdcGeomSvc, m_mdcFunSvc, m_mdcUtilitySvc );
244
245 // if(0 == m_mdcCalFlg) m_calconst->initCalibConst();
246
247 return StatusCode::SUCCESS;
248}
const Int_t n
const int MdcCalNLayer
Definition MdcCalParams.h:6

The documentation for this class was generated from the following files: