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"
73 m_calibItem=
"111111111";
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 );
92 MsgStream log(
msgSvc(), name());
93 log<<MSG::INFO<<
"tofcalgsec::initialize()!" <<endreq;
96 NTuplePtr nt1(
ntupleSvc(),
"TofCalib/btrk");
97 NTuplePtr nt2(
ntupleSvc(),
"TofCalib/etrk");
98 NTuplePtr nt3(
ntupleSvc(),
"TofCalib/etf");
99 if ( nt1 || nt2 || nt3 ) {
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");
109 if( mtuple_barrel ) {
113 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(mtuple_barrel) <<endmsg;
114 return StatusCode::FAILURE;
116 if( mtuple_endcap ) {
120 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(mtuple_endcap) <<endmsg;
121 return StatusCode::FAILURE;
127 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(mtuple_etf) <<endmsg;
128 return StatusCode::FAILURE;
133 m_calibration =
true;
136 if( !m_online || m_calibration ) {
138 std::cout<<
" tofcalgsec checks your configurations ..."<<std::endl;
140 if((pdir=gSystem->OpenDirectory(m_workdir.c_str()))==0){
141 std::cerr<<
"WorkDir "<<m_workdir<<
" doesn't exist "<<std::endl;
142 if(gSystem->MakeDirectory(m_workdir.c_str())==-1){
143 std::cerr<<
" Fail to create directory : "<<m_workdir
144 <<
" Specify ./ as current work directory"<<std::endl;
149 gSystem->FreeDirectory(pdir);
156 if( (pdir=gSystem->OpenDirectory(m_datafile_dir.c_str())) ) {
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);
166 std::cerr<<
" File "<<thefile<<
" doesn't exist! "<<std::endl;
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);
178 std::cerr<<
" File "<<thefile<<
" doesn't exist! "<<std::endl;
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);
190 std::cerr<<
" File "<<thefile<<
" doesn't exist! "<<std::endl;
194 gSystem->FreeDirectory(pdir);
198 std::cerr<<
" Error : Please specify the InputDataDir which contains input data files for calibration "<<std::endl;
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;
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) <<
"' ";
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) <<
"' ";
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) <<
"' ";
226 std::cout << std::endl;
228 std::cout<<
"*********************************************************************"<<std::endl;
230 return StatusCode::SUCCESS;
235 MsgStream log(
msgSvc(), name());
236 log << MSG::INFO <<
"tofcalgsec::beginRun()" << endreq;
237 return StatusCode::SUCCESS;
242 MsgStream log(
msgSvc(), name());
243 log << MSG::INFO <<
"start "<<
"tofcalgsec::execute()" << endreq;
246 SmartDataPtr<RecBTofCalHitCol> bhitcol(eventSvc(),
"/Event/Recon/RecBTofCalHitCol");
249 if( m_calibration ) {
259 SmartDataPtr<RecETofCalHitCol> ehitcol(eventSvc(),
"/Event/Recon/RecETofCalHitCol");
262 if( m_calibration ) {
273 if( m_calibration ) {
284 log << MSG::INFO <<
"end "<<
"tofcalgsec::execute()" << endreq;
285 return StatusCode::SUCCESS;
290 MsgStream log(
msgSvc(), name());
291 log << MSG::INFO <<
"tofcalgsec::endRun()" << endreq;
292 return StatusCode::SUCCESS;
298 MsgStream log(
msgSvc(), name());
299 log << MSG::INFO <<
"tofcalgsec::finalize()" << endreq;
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;
310 if( m_barrelfile.empty() ) {
311 std::cout <<
" No barrle data files are valid, exit " << std::endl;
317 if( m_endcapfile.empty() ) {
318 std::cout <<
" No endcap data files are valid, exit " << std::endl;
324 if( m_etffile.empty() ) {
325 std::cout <<
" No etf data files are valid, exit " << std::endl;
440 return StatusCode::SUCCESS;
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 > &)
void setEtfData(RecBTofCalHitCol &)
void setEndcapDataFiles(std::vector< std::string > &)
void setBarrelData(RecBTofCalHitCol &)
void setBarrelDataFiles(std::vector< std::string > &)
void setEndcapData(RecETofCalHitCol &)
tofcalgsec(const std::string &name, ISvcLocator *pSvcLocator)
bool testbit(unsigned int n)