182 MsgStream log(
msgSvc(), name());
183 log << MSG::INFO <<
"TofRec in execute()!" << endreq;
185 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
187 log << MSG::FATAL <<
"TofRec could not find Event Header!" << endreq;
188 return StatusCode::FAILURE;
190 int run = eventHeader->runNumber();
191 int event = eventHeader->eventNumber();
192 if( ( event % 1000 == 0 ) && m_printOutInfo ) {
193 std::cout <<
"run:" << run <<
" event: " <<
event << std::endl;
195 log << MSG::INFO <<
"run= " << run <<
" event= " <<
event << endreq;
201 if( m_acceleratorStatus ==
"Colliding" ) {
203 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
204 if( !estimeCol || ( estimeCol->size() == 0 ) ) {
205 log << MSG::WARNING <<
"TofRec Could not find RecEsTimeCol! Run = " << run <<
" Event = " <<
event << endreq;
206 return StatusCode::SUCCESS;
208 RecEsTimeCol::iterator iter_ESTime=estimeCol->begin();
209 double t0 = (*iter_ESTime)->getTest();
210 int t0Stat = (*iter_ESTime)->getStat();
211 log << MSG::INFO <<
"t0= " << t0 <<
" t0Stat= " << t0Stat << endreq;
214 SmartDataPtr<RecMdcKalTrackCol> mdcKalTrackCol(eventSvc(),
"/Event/Recon/RecMdcKalTrackCol");
215 if( !mdcKalTrackCol ) {
216 log << MSG::WARNING <<
"No MdcKalTrackCol in TDS! Run = " << run <<
" Event = " <<
event << endreq;
217 return StatusCode::SUCCESS;
221 SmartDataPtr<RecExtTrackCol> extTrackCol(eventSvc(),
"/Event/Recon/RecExtTrackCol");
223 log << MSG::WARNING <<
"No ExtTrackCol in TDS! Run = " << run <<
" Event = " <<
event << endreq;
224 return StatusCode::SUCCESS;
227 if( m_printOutInfo ) { m_printOut->
setExtTrackNum( extTrackCol->size() ); }
228 if( m_checkDigi && m_checkDigiExt ) { m_checkdigi_tuple->
FillCol( *eventHeader, mdcKalTrackCol, extTrackCol ); }
232 if( m_forCalibration ) {
233 if( m_printOutInfo ) { m_printOut->
addNumber(0); }
235 if( t0Stat%10 != 1 )
return StatusCode::SUCCESS;
236 if( m_printOutInfo ) { m_printOut->
addNumber(1); }
238 if( extTrackCol->size() != 2 )
return StatusCode::SUCCESS;
239 if( m_printOutInfo ) { m_printOut->
addNumber(2); }
241 SmartDataPtr<RecMdcTrackCol> mdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
243 log << MSG::FATAL <<
"Could NOT find RecMdcTrackCol in TDS! Run = " << run <<
" Event = " <<
event << endreq;
244 return StatusCode::SUCCESS;
246 if( mdcTrackCol->size() != 2 )
return StatusCode::SUCCESS;
247 if( m_printOutInfo ) { m_printOut->
addNumber(3); }
249 SmartDataPtr<RecEmcShowerCol> emcShowerCol(eventSvc(),
"/Event/Recon/RecEmcShowerCol");
250 if( !emcShowerCol ) {
251 log << MSG::FATAL <<
"Could NOT find EmcRecShowerCol in TDS! Run = " << run <<
" Event = " <<
event << endreq;
252 return StatusCode::SUCCESS;
254 if( m_printOutInfo ) { m_printOut->
addNumber(4); }
256 if( emcShowerCol->size() < 2 )
return StatusCode::SUCCESS;
257 if( m_printOutInfo ) { m_printOut->
addNumber(5); }
259 RecMdcTrackCol::iterator iter_mdc1 = mdcTrackCol->begin();
260 RecMdcTrackCol::iterator iter_mdc2 = mdcTrackCol->begin() + 1;
262 RecMdcKalTrackCol::iterator iter_kal1 = mdcKalTrackCol->begin();
263 RecMdcKalTrackCol::iterator iter_kal2 = mdcKalTrackCol->begin() + 1;
265 RecExtTrackCol::iterator iter_ext1 = extTrackCol->begin();
266 RecExtTrackCol::iterator iter_ext2 = extTrackCol->begin() + 1;
267 Hep3Vector extPos1 = (*iter_ext1)->emcPosition();
268 Hep3Vector extPos2 = (*iter_ext2)->emcPosition();
270 RecEmcShowerCol::iterator iter_emc1 = emcShowerCol->begin();
271 RecEmcShowerCol::iterator iter_emc2 = emcShowerCol->begin() + 1;
272 Hep3Vector emcPos1((*iter_emc1)->x(),(*iter_emc1)->y(),(*iter_emc1)->z());
273 Hep3Vector emcPos2((*iter_emc2)->x(),(*iter_emc2)->y(),(*iter_emc2)->z());
275 Hep3Vector pep = (*iter_mdc1)->p3();
276 Hep3Vector pem = (*iter_mdc2)->p3();
277 double delta_angle = 180.0 - pep.angle( pem.unit() )*180.0/
pi;
278 double delta_phi =
abs( (*iter_mdc1)->phi() - (*iter_mdc2)->phi() )*180.0/
pi;
280 Hep3Vector distant1 = extPos1 - emcPos1;
281 Hep3Vector distant2 = extPos2 - emcPos1;
282 if( distant1.r() > distant2.r() ) {
283 RecEmcShowerCol::iterator iter_tmp = iter_emc1;
284 iter_emc1 = iter_emc2;
285 iter_emc2 = iter_tmp;
286 Hep3Vector emc_tmp = emcPos1;
290 distant1 = extPos1 - emcPos1;
291 distant2 = extPos2 - emcPos2;
293 double e1 = (*iter_emc1)->energy();
294 double e2 = (*iter_emc2)->energy();
296 RecEmcShowerCol::iterator iter_emc = emcShowerCol->begin();
297 for( ; iter_emc != emcShowerCol->end(); iter_emc++ ) {
298 etot += (*iter_emc)->energy();
301 if( m_checkDigi ) { m_checkdigi_tuple->
FillCol( *eventHeader, extTrackCol, mdcTrackCol, emcShowerCol, mdcKalTrackCol ); }
303 if( ( (*iter_mdc1)->charge() + (*iter_mdc2)->charge() )!= 0 )
return StatusCode::SUCCESS;
304 if( m_printOutInfo ) { m_printOut->
addNumber(6); }
307 if( delta_angle > 10.0 )
return StatusCode::SUCCESS;
308 if( m_printOutInfo ) { m_printOut->
addNumber(7); }
310 if( m_calibData ==
"Bhabha" ) {
311 if( (*iter_kal1)->getStat(1,0)!=0 || (*iter_kal2)->getStat(1,0)!=0 )
return StatusCode::SUCCESS;
312 if( m_printOutInfo ) { m_printOut->
addNumber(8); }
314 if( m_data ==
"jpsi" ) {
315 if( distant1.r()>6.0 || distant2.r()>6.0 )
return StatusCode::SUCCESS;
316 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
317 if( (*iter_mdc1)->x()<-0.2 || (*iter_mdc1)->x()>0.4 || (*iter_mdc1)->y()<-0.5 || (*iter_mdc1)->y()>0.1 || abs((*iter_mdc1)->z())>4.0 )
return StatusCode::SUCCESS;
318 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
319 if( (*iter_mdc2)->x()<-0.2 || (*iter_mdc2)->x()>0.4 || (*iter_mdc2)->y()<-0.5 || (*iter_mdc2)->y()>0.1 || abs((*iter_mdc2)->z())>4.0 )
return StatusCode::SUCCESS;
320 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
321 if( delta_phi<174.0 || delta_phi>186.0 )
return StatusCode::SUCCESS;
322 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
323 if(
e1 < 1.1 ||
e2 < 1.1 )
return StatusCode::SUCCESS;
324 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
327 else if( m_data ==
"psip" ) {
328 if( distant1.r()>6.0 || distant2.r()>6.0 )
return StatusCode::SUCCESS;
329 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
330 if( (*iter_mdc1)->x()<-0.2 || (*iter_mdc1)->x()>0.4 || (*iter_mdc1)->y()<-0.5 || (*iter_mdc1)->y()>0.1 || abs((*iter_mdc1)->z())>4.0 )
return StatusCode::SUCCESS;
331 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
332 if( (*iter_mdc2)->x()<-0.2 || (*iter_mdc2)->x()>0.4 || (*iter_mdc2)->y()<-0.5 || (*iter_mdc2)->y()>0.1 || abs((*iter_mdc2)->z())>4.0 )
return StatusCode::SUCCESS;
333 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
334 if( delta_phi<174.0 || delta_phi>183.0 )
return StatusCode::SUCCESS;
335 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
336 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
337 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
340 else if( m_data ==
"psipp10" ) {
341 if( distant1.r()>6.0 || distant2.r()>6.0 )
return StatusCode::SUCCESS;
342 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
343 if( (*iter_mdc1)->x()<-0.2 || (*iter_mdc1)->x()>1.2 || (*iter_mdc1)->y()<-0.9 || (*iter_mdc1)->y()>0.5 || abs((*iter_mdc1)->z())>6.0 )
return StatusCode::SUCCESS;
344 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
345 if( (*iter_mdc2)->x()<-0.2 || (*iter_mdc2)->x()>1.2 || (*iter_mdc2)->y()<-0.9 || (*iter_mdc2)->y()>0.5 || abs((*iter_mdc2)->z())>6.0 )
return StatusCode::SUCCESS;
346 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
347 if( delta_phi<174.0 || delta_phi>186.0 )
return StatusCode::SUCCESS;
348 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
349 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
350 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
353 else if( m_data ==
"psipp11" ) {
354 if( distant1.r()>6.0 || distant2.r()>6.0 )
return StatusCode::SUCCESS;
355 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
356 if( (*iter_mdc1)->x()<-0.15 || (*iter_mdc1)->x()>0.3 || (*iter_mdc1)->y()<-0.3 || (*iter_mdc1)->y()>0.15 || abs((*iter_mdc1)->z())>6.0 )
return StatusCode::SUCCESS;
357 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
358 if( (*iter_mdc2)->x()<-0.15 || (*iter_mdc2)->x()>0.3 || (*iter_mdc2)->y()<-0.3 || (*iter_mdc2)->y()>0.15 || abs((*iter_mdc2)->z())>6.0 )
return StatusCode::SUCCESS;
359 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
360 if( delta_phi<174.0 || delta_phi>184.0 )
return StatusCode::SUCCESS;
361 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
362 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
363 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
366 else if( m_data ==
"psip12" ) {
367 if( distant1.r()>6.0 || distant2.r()>6.0 )
return StatusCode::SUCCESS;
368 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
369 if( (*iter_mdc1)->x()<-0.25 || (*iter_mdc1)->x()>0.3 || (*iter_mdc1)->y()<-0.3 || (*iter_mdc1)->y()>0.15 || abs((*iter_mdc1)->z())>6.0 )
return StatusCode::SUCCESS;
370 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
371 if( (*iter_mdc2)->x()<-0.25 || (*iter_mdc2)->x()>0.3 || (*iter_mdc2)->y()<-0.3 || (*iter_mdc2)->y()>0.15 || abs((*iter_mdc2)->z())>6.0 )
return StatusCode::SUCCESS;
372 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
373 if( delta_phi<172.0 || delta_phi>188.0 )
return StatusCode::SUCCESS;
374 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
375 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
376 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
379 else if( m_data ==
"jpsi12" ) {
380 if( distant1.r()>6.0 || distant2.r()>6.0 )
return StatusCode::SUCCESS;
381 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
382 if( (*iter_mdc1)->x()<-0.2 || (*iter_mdc1)->x()>0.4 || (*iter_mdc1)->y()<-0.4 || (*iter_mdc1)->y()>0.2 || abs((*iter_mdc1)->z())>4.0 )
return StatusCode::SUCCESS;
383 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
384 if( (*iter_mdc2)->x()<-0.2 || (*iter_mdc2)->x()>0.4 || (*iter_mdc2)->y()<-0.4 || (*iter_mdc2)->y()>0.2 || abs((*iter_mdc2)->z())>4.0 )
return StatusCode::SUCCESS;
385 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
386 if( delta_phi<172.0 || delta_phi>188.0 )
return StatusCode::SUCCESS;
387 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
388 if(
e1 < 1.1 ||
e2 < 1.1 )
return StatusCode::SUCCESS;
389 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
391 if( (
etot -
e1 -
e2 ) > 0.3 )
return StatusCode::SUCCESS;
392 if( m_printOutInfo ) { m_printOut->
addNumber(14); }
394 else if( m_calibData ==
"Dimu" ) {
395 if( (*iter_kal1)->getStat(1,1)!=0 || (*iter_kal2)->getStat(1,1)!=0 )
return StatusCode::SUCCESS;
396 if( m_printOutInfo ) { m_printOut->
addNumber(8); }
397 if(
e1 > 0.5 ||
e2 > 0.5 )
return StatusCode::SUCCESS;
398 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
405 RecExtTrackCol::iterator iter_track = extTrackCol->begin();
406 for( ; iter_track < extTrackCol->end(); iter_track++ ) {
407 RecMdcKalTrackCol::iterator iter_kal = mdcKalTrackCol->begin();
408 for( ; iter_kal != mdcKalTrackCol->end(); iter_kal++ ) {
409 if( (*iter_kal)->trackId() == (*iter_track)->trackId() )
break;
412 if( iter_kal != mdcKalTrackCol->end() ) {
413 for(
unsigned int i=0; i<5; i++ ) {
414 kal[i] = (*iter_kal)->getStat( 1, i );
418 tof->
setExtTrack( (*iter_track), kal, t0, t0Stat );
420 if( tofTrackVec->size()>0 ) {
421 std::vector<TofTrack*>::iterator iterExt = tofTrackVec->begin();
422 for( ; iterExt < tofTrackVec->end(); iterExt++ ) {
423 if( (*iterExt)->isNoHit() )
continue;
428 tofTrackVec->push_back( tof );
431 if( m_printOutInfo ) {
437 if( tofDataMap.empty() ) {
438 log << MSG::WARNING <<
"No Tof Data Map in RawDataProviderSvc! Run=" << run <<
" Event=" <<
event << endreq;
441 if( m_checkDigi && m_checkDigiRaw ) {
442 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc(),
"/Event/Digi/TofDigiCol");
444 log << MSG::ERROR <<
"TofRec could not find Tof digi! Event = " <<
event << endreq;
446 else { m_checkdigi_tuple->
FillCol( *eventHeader, tofDigiCol, t0, t0Stat ); }
448 m_checkdigi_tuple->
FillCol( *eventHeader, tofDataMap, t0, t0Stat );
451 std::vector<int> deadId;
452 if( m_forCalibration ) {
453 for(
unsigned int i=0; i<5; i++ ) {
455 if( identmp != 0x2fffffff ) {
456 deadId.push_back( identmp );
459 if( identmp != 0x2fffffff ) {
460 deadId.push_back( identmp );
463 if( identmp != 0x2fffffff ) {
464 deadId.push_back( identmp );
469 std::vector<TofTrack*>::iterator
iter = tofTrackVec->begin();
470 for( ;
iter < tofTrackVec->end();
iter++ ) {
471 if( (*iter)->isNoHit() )
continue;
472 (*iter)->setTofData( tofDataMap );
474 if( (*iter)->isNoHit() )
continue;
475 (*iter)->match( m_forCalibration, deadId, tofTrackVec );
479 iter = tofTrackVec->begin();
480 for( ;
iter < tofTrackVec->end();
iter++ ) {
482 (*iter)->setCalibration();
485 if( m_checkTrigger ) {
487 SmartDataPtr<TrigData> trigData(eventSvc(),
"/Event/Trig/TrigData");
489 log << MSG::FATAL <<
"Could not find Trigger Data for physics analysis" << endreq;
497 if( ( run < 0 ) && m_checkMcTruth ) {
498 SmartDataPtr<TofMcHitCol> tofMcCol(eventSvc(),
"/Event/MC/TofMcHitCol");
499 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
500 if ( !tofMcCol || !mcParticleCol ) {
501 m_checkdigi_tuple->
Fill_TofTrack( *eventHeader, *
iter, t0, t0Stat, mdcKalTrackCol );
504 m_checkdigi_tuple->
Fill_TofTrack( *eventHeader, *
iter, t0, t0Stat, mdcKalTrackCol, tofMcCol, mcParticleCol, m_calibData );
508 m_checkdigi_tuple->
Fill_TofTrack( *eventHeader, *
iter, t0, t0Stat, mdcKalTrackCol );
514 tds.
RegisterTDS( eventHeader->runNumber(), eventHeader->eventNumber(), tofTrackVec, m_forCalibration, m_calibData );
519 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),
"/Event/Recon/RecTofTrackCol");
521 log << MSG::FATAL <<
"TofRec could not find RecTofTrackCol!" << endreq;
522 return StatusCode::FAILURE;
525 if( m_saveRootFile ) {
526 m_checkdata_tuple->
FillCol( *eventHeader, tofTrackCol, mdcKalTrackCol );
530 if( m_forCalibration ) {
531 SmartDataPtr<RecBTofCalHitCol> bhitCol(eventSvc(),
"/Event/Recon/RecBTofCalHitCol");
533 log << MSG::WARNING <<
"TofRec could not find RecBTofCalHitCol!" << endreq;
536 if( m_saveRootFile ) {
537 m_checkdata_tuple->
FillCol( *eventHeader, bhitCol );
541 SmartDataPtr<RecETofCalHitCol> ehitCol(eventSvc(),
"/Event/Recon/RecETofCalHitCol");
543 log << MSG::WARNING <<
"TofRec could not find RecETofCalHitCol!" << endreq;
546 if( m_saveRootFile ) {
547 m_checkdata_tuple->
FillCol( *eventHeader, ehitCol );
554 log << MSG::FATAL <<
"In TofRec: AcceleratorStatus is NOT correct! m_acceleratorStatus = " << m_acceleratorStatus << endreq;
555 return StatusCode::FAILURE;
558 return StatusCode::SUCCESS;