BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
tofcalgsec.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/Property.h"
3#include "GaudiKernel/SmartRef.h"
4#include "GaudiKernel/IDataProviderSvc.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/SmartDataLocator.h"
8#include "EventModel/Event.h"
9#include "EventModel/EventModel.h"
10#include "TofRecEvent/RecBTofCalHit.h"
11#include "TofRecEvent/RecETofCalHit.h"
12#include "tofcalgsec/TofCalibManager.h"
13#include "tofcalgsec/TofCalib.h"
14#include "tofcalgsec/calib_barrel_left.h"
15#include "tofcalgsec/calib_barrel_right.h"
16#include "tofcalgsec/calib_barrel_left_offset1_bunch0_3.h"
17#include "tofcalgsec/calib_barrel_left_offset1_bunch1_3.h"
18#include "tofcalgsec/calib_barrel_left_offset1_bunch2_3.h"
19#include "tofcalgsec/calib_barrel_left_offset1_bunch3_3.h"
20#include "tofcalgsec/calib_barrel_left_offset2_bunch0_3.h"
21#include "tofcalgsec/calib_barrel_left_offset2_bunch1_3.h"
22#include "tofcalgsec/calib_barrel_left_offset2_bunch2_3.h"
23#include "tofcalgsec/calib_barrel_left_offset2_bunch3_3.h"
24#include "tofcalgsec/calib_barrel_right_offset1_bunch0_3.h"
25#include "tofcalgsec/calib_barrel_right_offset1_bunch1_3.h"
26#include "tofcalgsec/calib_barrel_right_offset1_bunch2_3.h"
27#include "tofcalgsec/calib_barrel_right_offset1_bunch3_3.h"
28#include "tofcalgsec/calib_barrel_right_offset2_bunch0_3.h"
29#include "tofcalgsec/calib_barrel_right_offset2_bunch1_3.h"
30#include "tofcalgsec/calib_barrel_right_offset2_bunch2_3.h"
31#include "tofcalgsec/calib_barrel_right_offset2_bunch3_3.h"
32#include "tofcalgsec/calib_barrel_left_offset1_bunch0_4.h"
33#include "tofcalgsec/calib_barrel_left_offset1_bunch1_4.h"
34#include "tofcalgsec/calib_barrel_left_offset1_bunch2_4.h"
35#include "tofcalgsec/calib_barrel_left_offset1_bunch3_4.h"
36#include "tofcalgsec/calib_barrel_left_offset2_bunch0_4.h"
37#include "tofcalgsec/calib_barrel_left_offset2_bunch1_4.h"
38#include "tofcalgsec/calib_barrel_left_offset2_bunch2_4.h"
39#include "tofcalgsec/calib_barrel_left_offset2_bunch3_4.h"
40#include "tofcalgsec/calib_barrel_right_offset1_bunch0_4.h"
41#include "tofcalgsec/calib_barrel_right_offset1_bunch1_4.h"
42#include "tofcalgsec/calib_barrel_right_offset1_bunch2_4.h"
43#include "tofcalgsec/calib_barrel_right_offset1_bunch3_4.h"
44#include "tofcalgsec/calib_barrel_right_offset2_bunch0_4.h"
45#include "tofcalgsec/calib_barrel_right_offset2_bunch1_4.h"
46#include "tofcalgsec/calib_barrel_right_offset2_bunch2_4.h"
47#include "tofcalgsec/calib_barrel_right_offset2_bunch3_4.h"
48#include "tofcalgsec/calib_barrel_atten.h"
49#include "tofcalgsec/calib_barrel_veff.h"
50#include "tofcalgsec/calib_endcap_left.h"
51#include "tofcalgsec/calib_endcap_veff.h"
52#include "tofcalgsec/TofCalibFit.h"
53#include "tofcalgsec/calib_barrel_q0.h"
54#include "tofcalgsec/calib_barrel_common.h"
55#include "tofcalgsec/calib_barrel_sigma.h"
56#include "tofcalgsec/calib_endcap_sigma.h"
57#include "tofcalgsec/calib_endcap_atten.h"
58#include "tofcalgsec/calib_etf_left.h"
59#include "tofcalgsec/calib_etf_right.h"
60#include "tofcalgsec/calib_etf_combine.h"
61#include "tofcalgsec/calib_mc_etf_left.h"
62#include "tofcalgsec/calib_mc_etf_right.h"
63#include "tofcalgsec/calib_mc_etf_combine.h"
64#include "tofcalgsec/calib_etf_veff.h"
65#include "tofcalgsec/calib_etf_bunch.h"
66#include "tofcalgsec/tofcalgsec.h"
67#include "TSystem.h"
68#include <stdlib.h>
69
70
71tofcalgsec::tofcalgsec(const std::string& name, ISvcLocator* pSvcLocator):Algorithm(name,pSvcLocator){
72 //set default values
73 m_calibItem="111111111";
74 //declares
75 declareProperty("Online", m_online );
76 declareProperty("Calibration", m_calibration );
77 declareProperty("WorkDir", m_workdir );
78 declareProperty("InputDataDir", m_datafile_dir );
79 declareProperty("InputDataFiles_Barrel", m_datafile_barrel );
80 declareProperty("InputDataFiles_Endcap", m_datafile_endcap );
81 declareProperty("InputDataFiles_Etf", m_datafile_etf );
82 declareProperty("CalibItem", m_calibItem );
83 declareProperty("TimeCorrelationZBin", m_tcorrzbin = 23 );
84 declareProperty("BarrelSigmaZBin", m_barrelzbin = 5 );
85 declareProperty("EndcapSigmaRBin", m_endcaprbin = 5 );
86 declareProperty("EndcapQRBin", m_endcapQrbin = 5 );
87}
88
89
91
92 MsgStream log(msgSvc(), name());
93 log<<MSG::INFO<< "tofcalgsec::initialize()!" <<endreq;
94
95 if( m_online ) {
96 NTuplePtr nt1(ntupleSvc(),"TofCalib/btrk");
97 NTuplePtr nt2(ntupleSvc(),"TofCalib/etrk");
98 NTuplePtr nt3(ntupleSvc(),"TofCalib/etf");
99 if ( nt1 || nt2 || nt3 ) {
100 mtuple_barrel = nt1;
101 mtuple_endcap = nt2;
102 mtuple_etf = nt3;
103 }
104 else {
105 mtuple_barrel = ntupleSvc()->book("TofCalib/btrk",CLID_ColumnWiseTuple,"TofCalib");
106 mtuple_endcap = ntupleSvc()->book("TofCalib/etrk",CLID_ColumnWiseTuple,"TofCalib");
107 mtuple_etf = ntupleSvc()->book("TofCalib/etf", CLID_ColumnWiseTuple,"TofCalib");
108
109 if( mtuple_barrel ) {
110 m_checkbarrel = new TofCalibCheck( mtuple_barrel );
111 }
112 else{
113 log << MSG::ERROR <<"Cannot book N-tuple:" << long(mtuple_barrel) <<endmsg;
114 return StatusCode::FAILURE;
115 }
116 if( mtuple_endcap ) {
117 m_checkendcap = new TofCalibCheck( mtuple_endcap );
118 }
119 else{
120 log << MSG::ERROR <<"Cannot book N-tuple:" << long(mtuple_endcap) <<endmsg;
121 return StatusCode::FAILURE;
122 }
123 if( mtuple_etf ) {
124 m_checketf = new TofCalibCheck( mtuple_etf );
125 }
126 else{
127 log << MSG::ERROR <<"Cannot book N-tuple:" << long(mtuple_etf) <<endmsg;
128 return StatusCode::FAILURE;
129 }
130 }
131 }
132 else {
133 m_calibration = true; // offline
134 }
135
136 if( !m_online || m_calibration ) {
137 // check workdir
138 std::cout<<" tofcalgsec checks your configurations ..."<<std::endl;
139 void *pdir=0;
140 if((pdir=gSystem->OpenDirectory(m_workdir.c_str()))==0){//dir exists?
141 std::cerr<<"WorkDir "<<m_workdir<<" doesn't exist "<<std::endl;
142 if(gSystem->MakeDirectory(m_workdir.c_str())==-1){//mkdir,fail to create?
143 std::cerr<<" Fail to create directory : "<<m_workdir
144 <<" Specify ./ as current work directory"<<std::endl;
145 m_workdir="./";
146 }
147 }
148 else{
149 gSystem->FreeDirectory(pdir);
150 pdir=0;
151 }
152 }
153
154 if( !m_online ) {
155 void *pdir=0;
156 if( (pdir=gSystem->OpenDirectory(m_datafile_dir.c_str())) ) {
157 FileStat_t fs;
158 std::vector<string>::iterator it = m_datafile_barrel.begin();
159 for( ; it!=m_datafile_barrel.end(); it++ ) {
160 if( (*it).size()>0 ) {
161 std::string thefile = (m_datafile_dir+"/"+(*it));
162 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
163 m_barrelfile.push_back(thefile);
164 }
165 else{
166 std::cerr<<" File "<<thefile<<" doesn't exist! "<<std::endl;
167 }
168 }
169 }
170 it = m_datafile_endcap.begin();
171 for( ; it!=m_datafile_endcap.end(); it++ ) {
172 if( (*it).size()>0 ) {
173 std::string thefile=(m_datafile_dir+"/"+(*it));
174 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
175 m_endcapfile.push_back(thefile);
176 }
177 else{
178 std::cerr<<" File "<<thefile<<" doesn't exist! "<<std::endl;
179 }
180 }
181 }
182 it = m_datafile_etf.begin();
183 for( ; it!=m_datafile_etf.end(); it++ ) {
184 if( (*it).size()>0 ) {
185 std::string thefile=(m_datafile_dir+"/"+(*it));
186 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
187 m_etffile.push_back(thefile);
188 }
189 else{
190 std::cerr<<" File "<<thefile<<" doesn't exist! "<<std::endl;
191 }
192 }
193 }
194 gSystem->FreeDirectory(pdir);
195 pdir=0;
196 }
197 else {
198 std::cerr<<" Error : Please specify the InputDataDir which contains input data files for calibration "<<std::endl;
199 exit(0);
200 }
201 }
202
203 if( !m_online || m_calibration ) {
204 std::cout<<"******************* Report of before Calibration ********************"<<std::endl
205 <<"* WorkDir = "<<m_workdir<<" [ results are save in this directory ] "<<std::endl
206 <<"* WorkMode = "<<(m_online?"OnLine":"OffLine")<<" [ run alone or with other algorithms ] "<<std::endl
207 <<"* CalibItem = "<<m_calibItem<<" [ which calibraions you perform ]"<<std::endl;
208 }
209
210 if( !m_online ) {
211 std::cout <<"* ==> InputDataDir : "<<m_datafile_dir<<std::endl
212 <<"* ===>Files of Barrel : ";
213 for( std::vector<std::string>::iterator it=m_barrelfile.begin(); it!=m_barrelfile.end(); it++ ) {
214 std::cout << "'" << (*it) << "' ";
215 }
216 std::cout << std::endl
217 <<"* ===>Files of Endcap : ";
218 for( std::vector<std::string>::iterator it=m_endcapfile.begin(); it!=m_endcapfile.end(); it++ ) {
219 std::cout << "'" << (*it) << "' ";
220 }
221 std::cout << std::endl
222 <<"* ===>Files of Etf : ";
223 for( std::vector<std::string>::iterator it=m_etffile.begin(); it!=m_etffile.end(); it++ ) {
224 std::cout << "'" << (*it) << "' ";
225 }
226 std::cout << std::endl;
227 }
228 std::cout<<"*********************************************************************"<<std::endl;
229
230 return StatusCode::SUCCESS;
231}
232
233
235 MsgStream log(msgSvc(), name());
236 log << MSG::INFO << "tofcalgsec::beginRun()" << endreq;
237 return StatusCode::SUCCESS;
238}
239
240
242 MsgStream log(msgSvc(), name());
243 log << MSG::INFO << "start "<<"tofcalgsec::execute()" << endreq;
244
245 if( m_online ) {
246 SmartDataPtr<RecBTofCalHitCol> bhitcol(eventSvc(),"/Event/Recon/RecBTofCalHitCol");
247 if( bhitcol ) {
248 m_checkbarrel->FillBarrelCol( bhitcol );
249 if( m_calibration ) {
251 manager->dataSet()->setBarrelData( bhitcol );
252 }
253 }
254 else{
255 // log << MSG::ERROR << " Can't get /Event/Recon/RecBTofCalHitCol in TDS!" << endreq;
256 // return StatusCode::SUCCESS;
257 }
258
259 SmartDataPtr<RecETofCalHitCol> ehitcol(eventSvc(),"/Event/Recon/RecETofCalHitCol");
260 if( ehitcol ) {
261 m_checkendcap->FillEndcapCol( ehitcol );
262 if( m_calibration ) {
264 }
265 }
266 else{
267 // log << MSG::ERROR << " Can't get /Event/Recon/RecETofCalHitCol in TDS!" <<endreq;
268 // return StatusCode::SUCCESS;
269 }
270
271 if( bhitcol ) {
272 m_checketf->FillEtfCol( bhitcol );
273 if( m_calibration ) {
275 }
276 }
277 else{
278 // log << MSG::ERROR << " Can't get /Event/Recon/RecBTofCalHitCol in TDS!" << endreq;
279 // return StatusCode::SUCCESS;
280 }
281
282 }
283
284 log << MSG::INFO << "end "<<"tofcalgsec::execute()" << endreq;
285 return StatusCode::SUCCESS;
286}
287
288
290 MsgStream log(msgSvc(), name());
291 log << MSG::INFO << "tofcalgsec::endRun()" << endreq;
292 return StatusCode::SUCCESS;
293}
294
295
297
298 MsgStream log(msgSvc(), name());
299 log << MSG::INFO << "tofcalgsec::finalize()" << endreq;
300
301 if( m_online && !m_calibration ) {
302 if( m_checkbarrel ) { delete m_checkbarrel; }
303 if( m_checkendcap ) { delete m_checkendcap; }
304 if( m_checketf ) { delete m_checketf; }
305 return StatusCode::SUCCESS;
306 }
307
309 if( !m_online ) {
310 if( m_barrelfile.empty() ) {
311 std::cout << " No barrle data files are valid, exit " << std::endl;
312 exit(0);
313 }
314 else {
315 manager->dataSet()->setBarrelDataFiles( m_barrelfile );
316 }
317 if( m_endcapfile.empty() ) {
318 std::cout << " No endcap data files are valid, exit " << std::endl;
319 exit(0);
320 }
321 else {
322 manager->dataSet()->setEndcapDataFiles( m_endcapfile );
323 }
324 if( m_etffile.empty() ) {
325 std::cout << " No etf data files are valid, exit " << std::endl;
326 exit(0);
327 }
328 else {
329 manager->dataSet()->setEtfDataFiles( m_etffile );
330 }
331 }
332
333 // barrel attenuation length calibration
334 if( testbit(5) ) {
335 manager->addCalib( new calib_barrel_atten(), 1 );
336 manager->addCalib( new calib_barrel_q0(), 1 );
337 }
338 // barrel effective velocity calibration
339 if( testbit(4) ) {
340 manager->addCalib( new calib_barrel_veff(), 1 );
341 }
342 // barrel time calibration
343 if( testbit(7) ) {
344 manager->addCalib( new calib_barrel_left(), 1 );
345 if (testbit(8)){
346 manager->addCalib( new calib_barrel_left_offset1_bunch0_4(), true );
347 manager->addCalib( new calib_barrel_left_offset1_bunch1_4(), true );
348 manager->addCalib( new calib_barrel_left_offset1_bunch2_4(), true );
349 manager->addCalib( new calib_barrel_left_offset1_bunch3_4(), true );
350 manager->addCalib( new calib_barrel_left_offset2_bunch0_4(), true );
351 manager->addCalib( new calib_barrel_left_offset2_bunch1_4(), true );
352 manager->addCalib( new calib_barrel_left_offset2_bunch2_4(), true );
353 manager->addCalib( new calib_barrel_left_offset2_bunch3_4(), true );
354 }
355 if( !testbit(8) ) {
356 manager->addCalib( new calib_barrel_left_offset1_bunch0_3(), true );
357 manager->addCalib( new calib_barrel_left_offset1_bunch1_3(), true );
358 manager->addCalib( new calib_barrel_left_offset1_bunch2_3(), true );
359 manager->addCalib( new calib_barrel_left_offset1_bunch3_3(), true );
360 manager->addCalib( new calib_barrel_left_offset2_bunch0_3(), true );
361 manager->addCalib( new calib_barrel_left_offset2_bunch1_3(), true );
362 manager->addCalib( new calib_barrel_left_offset2_bunch2_3(), true );
363 manager->addCalib( new calib_barrel_left_offset2_bunch3_3(), true );
364 }
365 manager->addCalib( new calib_barrel_right(), 1 );
366 if( testbit(8) ) {
367 manager->addCalib( new calib_barrel_right_offset1_bunch0_4(), true );
368 manager->addCalib( new calib_barrel_right_offset1_bunch1_4(), true );
369 manager->addCalib( new calib_barrel_right_offset1_bunch2_4(), true );
370 manager->addCalib( new calib_barrel_right_offset1_bunch3_4(), true );
371 manager->addCalib( new calib_barrel_right_offset2_bunch0_4(), true );
372 manager->addCalib( new calib_barrel_right_offset2_bunch1_4(), true );
373 manager->addCalib( new calib_barrel_right_offset2_bunch2_4(), true );
374 manager->addCalib( new calib_barrel_right_offset2_bunch3_4(), true );
375 }
376 if( !testbit(8) ) {
377 manager->addCalib( new calib_barrel_right_offset1_bunch0_3(), true );
378 manager->addCalib( new calib_barrel_right_offset1_bunch1_3(), true );
379 manager->addCalib( new calib_barrel_right_offset1_bunch2_3(), true );
380 manager->addCalib( new calib_barrel_right_offset1_bunch3_3(), true );
381 manager->addCalib( new calib_barrel_right_offset2_bunch0_3(), true );
382 manager->addCalib( new calib_barrel_right_offset2_bunch1_3(), true );
383 manager->addCalib( new calib_barrel_right_offset2_bunch2_3(), true );
384 manager->addCalib( new calib_barrel_right_offset2_bunch3_3(), true );
385 }
386 }
387 // barrel sigma calibration
388 if( testbit(6) ) {
389 manager->addCalib( new calib_barrel_common(m_tcorrzbin), true );
390 manager->addCalib( new calib_barrel_sigma(m_barrelzbin), true );
391 }
392
393 // endcap attenuation length calibration
394 if( testbit(1) ) {
395 manager->addCalib( new calib_endcap_atten(m_endcapQrbin), false );
396 }
397 // endcap effective velocity calibration
398 if( testbit(0) ) {
399 manager->addCalib( new calib_endcap_veff(), false );
400 }
401 // endcap time calibration
402 if( testbit(3) ) {
403 manager->addCalib( new calib_endcap_left(), 0 );
404 }
405 // endcap sigma calibration
406 if( testbit(2) ) {
407 manager->addCalib( new calib_endcap_sigma(m_endcaprbin), false );
408 }
409 // etf effective velocity calibration
410 if( testbit(9) ) {
411 manager->addCalib( new calib_etf_veff(), 2 );
412 }
413 // monte carlo etf time calibration
414 if( testbit(11) ) {
415 manager->addCalib( new calib_mc_etf_combine(), 2 );
416 manager->addCalib( new calib_mc_etf_left(), 2 );
417 manager->addCalib( new calib_mc_etf_right(), 2 );
418 }
419 // etf time calibration
420 if( testbit(10) ) {
421 manager->addCalib( new calib_etf_combine(), 2 );
422 manager->addCalib( new calib_etf_left(), 2 );
423 manager->addCalib( new calib_etf_right(), 2 );
424 }
425 // etf bunch offset
426 if( testbit(12) ) {
427 if (testbit(8)){
428 manager->addCalib( new calib_etf_bunch(4), false );
429 }
430 if (!testbit(8)){
431 manager->addCalib( new calib_etf_bunch(3), false );
432 }
433 }
434
435 manager->doCalibration();
436
437 manager->fillTxt( m_workdir );
438 manager->fillRoot( m_workdir );
439
440 return StatusCode::SUCCESS;
441}
442
443
void FillEndcapCol(RecETofCalHitCol &)
void FillBarrelCol(RecBTofCalHitCol &)
void FillEtfCol(RecBTofCalHitCol &)
void addCalib(TofCalib *cal_item1, int isbarrel)
static TofCalibManager * getManager()
void fillRoot(string &dir)
void fillTxt(string &dir)
void setEtfDataFiles(std::vector< std::string > &)
Definition: TofDataSet.cxx:251
void setEtfData(RecBTofCalHitCol &)
Definition: TofDataSet.cxx:311
void setEndcapDataFiles(std::vector< std::string > &)
Definition: TofDataSet.cxx:228
void setBarrelData(RecBTofCalHitCol &)
Definition: TofDataSet.cxx:274
void setBarrelDataFiles(std::vector< std::string > &)
Definition: TofDataSet.cxx:205
void setEndcapData(RecETofCalHitCol &)
Definition: TofDataSet.cxx:293
tofcalgsec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: tofcalgsec.cxx:71
StatusCode finalize()
Definition: tofcalgsec.cxx:296
StatusCode initialize()
Definition: tofcalgsec.cxx:90
StatusCode beginRun()
Definition: tofcalgsec.cxx:234
StatusCode execute()
Definition: tofcalgsec.cxx:241
StatusCode endRun()
Definition: tofcalgsec.cxx:289