CGEM BOSS 6.6.5.f
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/tofcalgsec.h"
59#include "TSystem.h"
60#include <stdlib.h>
61
62
63tofcalgsec::tofcalgsec(const std::string& name, ISvcLocator* pSvcLocator):Algorithm(name,pSvcLocator){
64 //set default values
65 m_calibItem="111111111";
66 //declares
67 declareProperty("Online", m_online );
68 declareProperty("Calibration", m_calibration );
69 declareProperty("WorkDir", m_workdir );
70 declareProperty("InputDataDir", m_datafile_dir );
71 declareProperty("InputDataFiles_Barrel", m_datafile_barrel );
72 declareProperty("InputDataFiles_Endcap", m_datafile_endcap );
73 declareProperty("CalibItem", m_calibItem );
74 declareProperty("TimeCorrelationZBin", m_tcorrzbin = 23 );
75 declareProperty("BarrelSigmaZBin", m_barrelzbin = 5 );
76 declareProperty("EndcapSigmaRBin", m_endcaprbin = 5 );
77 declareProperty("EndcapQRBin", m_endcapQrbin = 5 );
78}
79
80
82
83 MsgStream log(msgSvc(), name());
84 log<<MSG::INFO<< "tofcalgsec::initialize()!" <<endreq;
85
86 if( m_online ) {
87 NTuplePtr nt1(ntupleSvc(),"TofCalib/btrk");
88 NTuplePtr nt2(ntupleSvc(),"TofCalib/etrk");
89 if ( nt1 || nt2 ) {
90 mtuple_barrel = nt1;
91 mtuple_endcap = nt2;
92 }
93 else {
94 mtuple_barrel = ntupleSvc()->book("TofCalib/btrk",CLID_ColumnWiseTuple,"TofCalib");
95 mtuple_endcap = ntupleSvc()->book("TofCalib/etrk",CLID_ColumnWiseTuple,"TofCalib");
96
97 if( mtuple_barrel ) {
98 m_checkbarrel = new TofCalibCheck( mtuple_barrel );
99 }
100 else{
101 log << MSG::ERROR <<"Cannot book N-tuple:" << long(mtuple_barrel) <<endmsg;
102 return StatusCode::FAILURE;
103 }
104 if( mtuple_endcap ) {
105 m_checkendcap = new TofCalibCheck( mtuple_endcap );
106 }
107 else{
108 log << MSG::ERROR <<"Cannot book N-tuple:" << long(mtuple_endcap) <<endmsg;
109 return StatusCode::FAILURE;
110 }
111 }
112 }
113 else {
114 m_calibration = true; // offline
115 }
116
117 if( !m_online || m_calibration ) {
118 // check workdir
119 std::cout<<" tofcalgsec checks your configurations ..."<<std::endl;
120 void *pdir=0;
121 if((pdir=gSystem->OpenDirectory(m_workdir.c_str()))==0){//dir exists?
122 std::cerr<<"WorkDir "<<m_workdir<<" doesn't exist "<<std::endl;
123 if(gSystem->MakeDirectory(m_workdir.c_str())==-1){//mkdir,fail to create?
124 std::cerr<<" Fail to create directory : "<<m_workdir
125 <<" Specify ./ as current work directory"<<std::endl;
126 m_workdir="./";
127 }
128 }
129 else{
130 gSystem->FreeDirectory(pdir);
131 pdir=0;
132 }
133 }
134
135 if( !m_online ) {
136 void *pdir=0;
137 if( (pdir=gSystem->OpenDirectory(m_datafile_dir.c_str())) ) {
138 FileStat_t fs;
139 std::vector<string>::iterator it = m_datafile_barrel.begin();
140 for( ; it!=m_datafile_barrel.end(); it++ ) {
141 if( (*it).size()>0 ) {
142 std::string thefile = (m_datafile_dir+"/"+(*it));
143 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
144 m_barrelfile.push_back(thefile);
145 }
146 else{
147 std::cerr<<" File "<<thefile<<" doesn't exist! "<<std::endl;
148 }
149 }
150 }
151 it = m_datafile_endcap.begin();
152 for( ; it!=m_datafile_endcap.end(); it++ ) {
153 if( (*it).size()>0 ) {
154 std::string thefile=(m_datafile_dir+"/"+(*it));
155 if( gSystem->GetPathInfo(thefile.c_str(),fs)==0 ) {
156 m_endcapfile.push_back(thefile);
157 }
158 else{
159 std::cerr<<" File "<<thefile<<" doesn't exist! "<<std::endl;
160 }
161 }
162 }
163 gSystem->FreeDirectory(pdir);
164 pdir=0;
165 }
166 else {
167 std::cerr<<" Error : Please specify the InputDataDir which contains input data files for calibration "<<std::endl;
168 exit(0);
169 }
170 }
171
172 if( !m_online || m_calibration ) {
173 std::cout<<"******************* Report of before Calibration ********************"<<std::endl
174 <<"* WorkDir = "<<m_workdir<<" [ results are save in this directory ] "<<std::endl
175 <<"* WorkMode = "<<(m_online?"OnLine":"OffLine")<<" [ run alone or with other algorithms ] "<<std::endl
176 <<"* CalibItem = "<<m_calibItem<<" [ which calibraions you perform ]"<<std::endl;
177 }
178
179 if( !m_online ) {
180 std::cout <<"* ==> InputDataDir : "<<m_datafile_dir<<std::endl
181 <<"* ===>Files of Barrel : ";
182 for( std::vector<std::string>::iterator it=m_barrelfile.begin(); it!=m_barrelfile.end(); it++ ) {
183 std::cout << "'" << (*it) << "' ";
184 }
185 std::cout << std::endl
186 <<"* ===>Files of Endcap : ";
187 for( std::vector<std::string>::iterator it=m_endcapfile.begin(); it!=m_endcapfile.end(); it++ ) {
188 std::cout << "'" << (*it) << "' ";
189 }
190 std::cout << std::endl;
191 }
192 std::cout<<"*********************************************************************"<<std::endl;
193
194 return StatusCode::SUCCESS;
195}
196
197
199 MsgStream log(msgSvc(), name());
200 log << MSG::INFO << "tofcalgsec::beginRun()" << endreq;
201 return StatusCode::SUCCESS;
202}
203
204
206 MsgStream log(msgSvc(), name());
207 log << MSG::INFO << "start "<<"tofcalgsec::execute()" << endreq;
208
209 if( m_online ) {
210 SmartDataPtr<RecBTofCalHitCol> bhitcol(eventSvc(),"/Event/Recon/RecBTofCalHitCol");
211 if( bhitcol ) {
212 m_checkbarrel->FillCol( bhitcol );
213 if( m_calibration ) {
215 manager->dataSet()->setBarrelData( bhitcol );
216 }
217 }
218 else{
219 // log << MSG::ERROR << " Can't get /Event/Recon/RecBTofCalHitCol in TDS!" << endreq;
220 // return StatusCode::SUCCESS;
221 }
222
223 SmartDataPtr<RecETofCalHitCol> ehitcol(eventSvc(),"/Event/Recon/RecETofCalHitCol");
224 if( ehitcol ) {
225 m_checkendcap->FillCol( ehitcol );
226 if( m_calibration ) {
228 }
229 }
230 else{
231 // log << MSG::ERROR << " Can't get /Event/Recon/RecETofCalHitCol in TDS!" <<endreq;
232 // return StatusCode::SUCCESS;
233 }
234 }
235
236 log << MSG::INFO << "end "<<"tofcalgsec::execute()" << endreq;
237 return StatusCode::SUCCESS;
238}
239
240
242 MsgStream log(msgSvc(), name());
243 log << MSG::INFO << "tofcalgsec::endRun()" << endreq;
244 return StatusCode::SUCCESS;
245}
246
247
249
250 MsgStream log(msgSvc(), name());
251 log << MSG::INFO << "tofcalgsec::finalize()" << endreq;
252
253 if( m_online && !m_calibration ) {
254 if( m_checkbarrel ) { delete m_checkbarrel; }
255 if( m_checkendcap ) { delete m_checkendcap; }
256 return StatusCode::SUCCESS;
257 }
258
260 if( !m_online ) {
261 if( m_barrelfile.empty() ) {
262 std::cout << " No barrle data files are valid, exit " << std::endl;
263 exit(0);
264 }
265 else {
266 manager->dataSet()->setBarrelDataFiles( m_barrelfile );
267 }
268 if( m_endcapfile.empty() ) {
269 std::cout << " No endcap data files are valid, exit " << std::endl;
270 exit(0);
271 }
272 else {
273 manager->dataSet()->setEndcapDataFiles( m_endcapfile );
274 }
275 }
276
277 // barrel attenuation length calibration
278 if( testbit(5) ) {
279 manager->addCalib( new calib_barrel_atten(), true );
280 manager->addCalib( new calib_barrel_q0(), true );
281 }
282 // barrel effective velocity calibration
283 if( testbit(4) ) {
284 manager->addCalib( new calib_barrel_veff(), true );
285 }
286 // barrel time calibration
287 if( testbit(7) ) {
288 manager->addCalib( new calib_barrel_left(), true );
289 if (testbit(8)){
290 manager->addCalib( new calib_barrel_left_offset1_bunch0_4(), true );
291 manager->addCalib( new calib_barrel_left_offset1_bunch1_4(), true );
292 manager->addCalib( new calib_barrel_left_offset1_bunch2_4(), true );
293 manager->addCalib( new calib_barrel_left_offset1_bunch3_4(), true );
294 manager->addCalib( new calib_barrel_left_offset2_bunch0_4(), true );
295 manager->addCalib( new calib_barrel_left_offset2_bunch1_4(), true );
296 manager->addCalib( new calib_barrel_left_offset2_bunch2_4(), true );
297 manager->addCalib( new calib_barrel_left_offset2_bunch3_4(), true );
298 }
299 if (!testbit(8)){
300 manager->addCalib( new calib_barrel_left_offset1_bunch0_3(), true );
301 manager->addCalib( new calib_barrel_left_offset1_bunch1_3(), true );
302 manager->addCalib( new calib_barrel_left_offset1_bunch2_3(), true );
303 manager->addCalib( new calib_barrel_left_offset1_bunch3_3(), true );
304 manager->addCalib( new calib_barrel_left_offset2_bunch0_3(), true );
305 manager->addCalib( new calib_barrel_left_offset2_bunch1_3(), true );
306 manager->addCalib( new calib_barrel_left_offset2_bunch2_3(), true );
307 manager->addCalib( new calib_barrel_left_offset2_bunch3_3(), true );
308 }
309 manager->addCalib( new calib_barrel_right(), true );
310 if (testbit(8)){
311 manager->addCalib( new calib_barrel_right_offset1_bunch0_4(), true );
312 manager->addCalib( new calib_barrel_right_offset1_bunch1_4(), true );
313 manager->addCalib( new calib_barrel_right_offset1_bunch2_4(), true );
314 manager->addCalib( new calib_barrel_right_offset1_bunch3_4(), true );
315 manager->addCalib( new calib_barrel_right_offset2_bunch0_4(), true );
316 manager->addCalib( new calib_barrel_right_offset2_bunch1_4(), true );
317 manager->addCalib( new calib_barrel_right_offset2_bunch2_4(), true );
318 manager->addCalib( new calib_barrel_right_offset2_bunch3_4(), true );
319 }
320 if (!testbit(8)){
321 manager->addCalib( new calib_barrel_right_offset1_bunch0_3(), true );
322 manager->addCalib( new calib_barrel_right_offset1_bunch1_3(), true );
323 manager->addCalib( new calib_barrel_right_offset1_bunch2_3(), true );
324 manager->addCalib( new calib_barrel_right_offset1_bunch3_3(), true );
325 manager->addCalib( new calib_barrel_right_offset2_bunch0_3(), true );
326 manager->addCalib( new calib_barrel_right_offset2_bunch1_3(), true );
327 manager->addCalib( new calib_barrel_right_offset2_bunch2_3(), true );
328 manager->addCalib( new calib_barrel_right_offset2_bunch3_3(), true );
329 }
330 }
331 // barrel sigma calibration
332 if( testbit(6) ) {
333 manager->addCalib( new calib_barrel_common(m_tcorrzbin), true );
334 manager->addCalib( new calib_barrel_sigma(m_barrelzbin), true );
335 }
336
337 // endcap attenuation length calibration
338 if( testbit(1) ) {
339 manager->addCalib( new calib_endcap_atten(m_endcapQrbin),false );
340 }
341 // endcap effective velocity calibration
342 if( testbit(0) ) {
343 manager->addCalib( new calib_endcap_veff(),false );
344 }
345 // endcap time calibration
346 if( testbit(3) ) {
347 manager->addCalib( new calib_endcap_left(), false );
348 }
349 // endcap sigma calibration
350 if( testbit(2) ) {
351 manager->addCalib( new calib_endcap_sigma(m_endcaprbin), false );
352 }
353
354 manager->doCalibration();
355
356 manager->fillTxt( m_workdir );
357 manager->fillRoot( m_workdir );
358
359 return StatusCode::SUCCESS;
360}
361
362
void FillCol(RecBTofCalHitCol &)
void addCalib(TofCalib *cal_item1, bool isbarrel)
static TofCalibManager * getManager()
void fillRoot(string &dir)
void fillTxt(string &dir)
void setEndcapDataFiles(std::vector< std::string > &)
Definition: TofDataSet.cxx:196
void setBarrelData(RecBTofCalHitCol &)
Definition: TofDataSet.cxx:219
void setBarrelDataFiles(std::vector< std::string > &)
Definition: TofDataSet.cxx:173
void setEndcapData(RecETofCalHitCol &)
Definition: TofDataSet.cxx:237
tofcalgsec(const std::string &name, ISvcLocator *pSvcLocator)
Definition: tofcalgsec.cxx:63
StatusCode finalize()
Definition: tofcalgsec.cxx:248
StatusCode initialize()
Definition: tofcalgsec.cxx:81
StatusCode beginRun()
Definition: tofcalgsec.cxx:198
StatusCode execute()
Definition: tofcalgsec.cxx:205
StatusCode endRun()
Definition: tofcalgsec.cxx:241