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_etf_veff.h"
62#include "tofcalgsec/calib_etf_bunch.h"
63#include "tofcalgsec/tofcalgsec.h"
70 m_calibItem=
"111111111";
72 declareProperty(
"Online", m_online );
73 declareProperty(
"Calibration", m_calibration );
74 declareProperty(
"WorkDir", m_workdir );
75 declareProperty(
"InputDataDir", m_datafile_dir );
76 declareProperty(
"InputDataFiles_Barrel", m_datafile_barrel );
77 declareProperty(
"InputDataFiles_Endcap", m_datafile_endcap );
78 declareProperty(
"InputDataFiles_Etf", m_datafile_etf );
79 declareProperty(
"CalibItem", m_calibItem );
80 declareProperty(
"TimeCorrelationZBin", m_tcorrzbin = 23 );
81 declareProperty(
"BarrelSigmaZBin", m_barrelzbin = 5 );
82 declareProperty(
"EndcapSigmaRBin", m_endcaprbin = 5 );
83 declareProperty(
"EndcapQRBin", m_endcapQrbin = 5 );
89 MsgStream log(
msgSvc(), name());
90 log<<MSG::INFO<<
"tofcalgsec::initialize()!" <<endreq;
93 NTuplePtr nt1(
ntupleSvc(),
"TofCalib/btrk");
94 NTuplePtr nt2(
ntupleSvc(),
"TofCalib/etrk");
95 NTuplePtr nt3(
ntupleSvc(),
"TofCalib/etf");
96 if ( nt1 || nt2 || nt3 ) {
102 mtuple_barrel =
ntupleSvc()->book(
"TofCalib/btrk",CLID_ColumnWiseTuple,
"TofCalib");
103 mtuple_endcap =
ntupleSvc()->book(
"TofCalib/etrk",CLID_ColumnWiseTuple,
"TofCalib");
104 mtuple_etf =
ntupleSvc()->book(
"TofCalib/etf", CLID_ColumnWiseTuple,
"TofCalib");
106 if( mtuple_barrel ) {
110 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(mtuple_barrel) <<endmsg;
111 return StatusCode::FAILURE;
113 if( mtuple_endcap ) {
117 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(mtuple_endcap) <<endmsg;
118 return StatusCode::FAILURE;
124 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(mtuple_etf) <<endmsg;
125 return StatusCode::FAILURE;
130 m_calibration =
true;
133 if( !m_online || m_calibration ) {
135 std::cout<<
" tofcalgsec checks your configurations ..."<<std::endl;
137 if((pdir=gSystem->OpenDirectory(m_workdir.c_str()))==0){
138 std::cerr<<
"WorkDir "<<m_workdir<<
" doesn't exist "<<std::endl;
139 if(gSystem->MakeDirectory(m_workdir.c_str())==-1){
140 std::cerr<<
" Fail to create directory : "<<m_workdir
141 <<
" Specify ./ as current work directory"<<std::endl;
146 gSystem->FreeDirectory(pdir);
153 if( (pdir=gSystem->OpenDirectory(m_datafile_dir.c_str())) ) {
155 std::vector<string>::iterator it = m_datafile_barrel.begin();
156 for( ; it!=m_datafile_barrel.end(); it++ ) {
157 if( (*it).size()>0 ) {
158 std::string thefile = (m_datafile_dir+
"/"+(*it));
159 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
160 m_barrelfile.push_back(thefile);
163 std::cerr<<
" File "<<thefile<<
" doesn't exist! "<<std::endl;
167 it = m_datafile_endcap.begin();
168 for( ; it!=m_datafile_endcap.end(); it++ ) {
169 if( (*it).size()>0 ) {
170 std::string thefile=(m_datafile_dir+
"/"+(*it));
171 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
172 m_endcapfile.push_back(thefile);
175 std::cerr<<
" File "<<thefile<<
" doesn't exist! "<<std::endl;
179 it = m_datafile_etf.begin();
180 for( ; it!=m_datafile_etf.end(); it++ ) {
181 if( (*it).size()>0 ) {
182 std::string thefile=(m_datafile_dir+
"/"+(*it));
183 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
184 m_etffile.push_back(thefile);
187 std::cerr<<
" File "<<thefile<<
" doesn't exist! "<<std::endl;
191 gSystem->FreeDirectory(pdir);
195 std::cerr<<
" Error : Please specify the InputDataDir which contains input data files for calibration "<<std::endl;
200 if( !m_online || m_calibration ) {
201 std::cout<<
"******************* Report of before Calibration ********************"<<std::endl
202 <<
"* WorkDir = "<<m_workdir<<
" [ results are save in this directory ] "<<std::endl
203 <<
"* WorkMode = "<<(m_online?
"OnLine":
"OffLine")<<
" [ run alone or with other algorithms ] "<<std::endl
204 <<
"* CalibItem = "<<m_calibItem<<
" [ which calibraions you perform ]"<<std::endl;
208 std::cout <<
"* ==> InputDataDir : "<<m_datafile_dir<<std::endl
209 <<
"* ===>Files of Barrel : ";
210 for( std::vector<std::string>::iterator it=m_barrelfile.begin(); it!=m_barrelfile.end(); it++ ) {
211 std::cout <<
"'" << (*it) <<
"' ";
213 std::cout << std::endl
214 <<
"* ===>Files of Endcap : ";
215 for( std::vector<std::string>::iterator it=m_endcapfile.begin(); it!=m_endcapfile.end(); it++ ) {
216 std::cout <<
"'" << (*it) <<
"' ";
218 std::cout << std::endl
219 <<
"* ===>Files of Etf : ";
220 for( std::vector<std::string>::iterator it=m_etffile.begin(); it!=m_etffile.end(); it++ ) {
221 std::cout <<
"'" << (*it) <<
"' ";
223 std::cout << std::endl;
225 std::cout<<
"*********************************************************************"<<std::endl;
227 return StatusCode::SUCCESS;
232 MsgStream log(
msgSvc(), name());
233 log << MSG::INFO <<
"tofcalgsec::beginRun()" << endreq;
234 return StatusCode::SUCCESS;
239 MsgStream log(
msgSvc(), name());
240 log << MSG::INFO <<
"start "<<
"tofcalgsec::execute()" << endreq;
243 SmartDataPtr<RecBTofCalHitCol> bhitcol(eventSvc(),
"/Event/Recon/RecBTofCalHitCol");
246 if( m_calibration ) {
256 SmartDataPtr<RecETofCalHitCol> ehitcol(eventSvc(),
"/Event/Recon/RecETofCalHitCol");
259 if( m_calibration ) {
270 if( m_calibration ) {
281 log << MSG::INFO <<
"end "<<
"tofcalgsec::execute()" << endreq;
282 return StatusCode::SUCCESS;
287 MsgStream log(
msgSvc(), name());
288 log << MSG::INFO <<
"tofcalgsec::endRun()" << endreq;
289 return StatusCode::SUCCESS;
295 MsgStream log(
msgSvc(), name());
296 log << MSG::INFO <<
"tofcalgsec::finalize()" << endreq;
298 if( m_online && !m_calibration ) {
299 if( m_checkbarrel ) {
delete m_checkbarrel; }
300 if( m_checkendcap ) {
delete m_checkendcap; }
301 if( m_checketf ) {
delete m_checketf; }
302 return StatusCode::SUCCESS;
307 if( m_barrelfile.empty() ) {
308 std::cout <<
" No barrle data files are valid, exit " << std::endl;
314 if( m_endcapfile.empty() ) {
315 std::cout <<
" No endcap data files are valid, exit " << std::endl;
321 if( m_etffile.empty() ) {
322 std::cout <<
" No etf data files are valid, exit " << std::endl;
426 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)