181 {
182
183 MsgStream log(
msgSvc(), name());
184 log << MSG::INFO << "MrpcRec in execute()!" << endreq;
185
186 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
187 if( !eventHeader ) {
188 log << MSG::FATAL << "MrpcRec could not find Event Header!" << endreq;
189 return StatusCode::FAILURE;
190 }
191 int run = eventHeader->runNumber();
192 int event = eventHeader->eventNumber();
193 if( ( event % 1000 == 0 ) && m_printOutInfo ) {
194 std::cout << "run:" << run << " event: " << event << std::endl;
195 }
196 log << MSG::INFO << "run= " << run << " event= " << event << endreq;
197
200
201
202 if( m_acceleratorStatus == "Colliding" ) {
203
204 SmartDataPtr<RecEsTimeCol> estimeCol(eventSvc(),"/Event/Recon/RecEsTimeCol");
205 if( !estimeCol || ( estimeCol->size() == 0 ) ) {
206 log << MSG::WARNING << "MrpcRec Could not find RecEsTimeCol! Run = " << run << " Event = " << event << endreq;
207 return StatusCode::SUCCESS;
208 }
209 RecEsTimeCol::iterator iter_ESTime=estimeCol->begin();
210 double t0 = (*iter_ESTime)->getTest();
211 int t0Stat = (*iter_ESTime)->getStat();
212 log << MSG::INFO << "t0= " << t0 << " t0Stat= " << t0Stat << endreq;
213
214
215 SmartDataPtr<RecMdcKalTrackCol> mdcKalTrackCol(eventSvc(),"/Event/Recon/RecMdcKalTrackCol");
216 if( !mdcKalTrackCol ) {
217 log << MSG::WARNING << "No MdcKalTrackCol in TDS! Run = " << run << " Event = " << event << endreq;
218 return StatusCode::SUCCESS;
219 }
220
221
222 SmartDataPtr<RecExtTrackCol> extTrackCol(eventSvc(),"/Event/Recon/RecExtTrackCol");
223 if( !extTrackCol ) {
224 log << MSG::WARNING << "No ExtTrackCol in TDS! Run = " << run << " Event = " << event << endreq;
225 return StatusCode::SUCCESS;
226 }
227 else {
228 if( m_printOutInfo ) { m_printOut->
setExtTrackNum( extTrackCol->size() ); }
229 if( m_checkDigi && m_checkDigiExt ) { m_checkdigi_tuple->
FillCol( *eventHeader, mdcKalTrackCol, extTrackCol ); }
230 }
231
232
233 if( m_forCalibration ) {
234 if( m_printOutInfo ) { m_printOut->
addNumber(0); }
235
236 if( t0Stat%10 != 1 ) return StatusCode::SUCCESS;
237 if( m_printOutInfo ) { m_printOut->
addNumber(1); }
238
239 if( extTrackCol->size() != 2 ) return StatusCode::SUCCESS;
240 if( m_printOutInfo ) { m_printOut->
addNumber(2); }
241
242 SmartDataPtr<RecMdcTrackCol> mdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
243 if( !mdcTrackCol ) {
244 log << MSG::FATAL << "Could NOT find RecMdcTrackCol in TDS! Run = " << run << " Event = " << event << endreq;
245 return StatusCode::SUCCESS;
246 }
247 if( mdcTrackCol->size() != 2 ) return StatusCode::SUCCESS;
248 if( m_printOutInfo ) { m_printOut->
addNumber(3); }
249
250 SmartDataPtr<RecEmcShowerCol> emcShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
251 if( !emcShowerCol ) {
252 log << MSG::FATAL << "Could NOT find EmcRecShowerCol in TDS! Run = " << run << " Event = " << event << endreq;
253 return StatusCode::SUCCESS;
254 }
255 if( m_printOutInfo ) { m_printOut->
addNumber(4); }
256
257 if( emcShowerCol->size() < 2 ) return StatusCode::SUCCESS;
258 if( m_printOutInfo ) { m_printOut->
addNumber(5); }
259
260 RecMdcTrackCol::iterator iter_mdc1 = mdcTrackCol->begin();
261 RecMdcTrackCol::iterator iter_mdc2 = mdcTrackCol->begin() + 1;
262
263 RecMdcKalTrackCol::iterator iter_kal1 = mdcKalTrackCol->begin();
264 RecMdcKalTrackCol::iterator iter_kal2 = mdcKalTrackCol->begin() + 1;
265
266 RecExtTrackCol::iterator iter_ext1 = extTrackCol->begin();
267 RecExtTrackCol::iterator iter_ext2 = extTrackCol->begin() + 1;
268 Hep3Vector extPos1 = (*iter_ext1)->emcPosition();
269 Hep3Vector extPos2 = (*iter_ext2)->emcPosition();
270
271 RecEmcShowerCol::iterator iter_emc1 = emcShowerCol->begin();
272 RecEmcShowerCol::iterator iter_emc2 = emcShowerCol->begin() + 1;
273 Hep3Vector emcPos1((*iter_emc1)->x(),(*iter_emc1)->y(),(*iter_emc1)->z());
274 Hep3Vector emcPos2((*iter_emc2)->x(),(*iter_emc2)->y(),(*iter_emc2)->z());
275
276 Hep3Vector pep = (*iter_mdc1)->p3();
277 Hep3Vector pem = (*iter_mdc2)->p3();
278 double delta_angle = 180.0 - pep.angle( pem.unit() )*180.0/
pi;
279 double delta_phi =
abs( (*iter_mdc1)->phi() - (*iter_mdc2)->phi() )*180.0/
pi;
280
281 Hep3Vector distant1 = extPos1 - emcPos1;
282 Hep3Vector distant2 = extPos2 - emcPos1;
283 if( distant1.r() > distant2.r() ) {
284 RecEmcShowerCol::iterator iter_tmp = iter_emc1;
285 iter_emc1 = iter_emc2;
286 iter_emc2 = iter_tmp;
287 Hep3Vector emc_tmp = emcPos1;
288 emcPos1 = emcPos2;
289 emcPos2 = emc_tmp;
290 }
291 distant1 = extPos1 - emcPos1;
292 distant2 = extPos2 - emcPos2;
293
294 double e1 = (*iter_emc1)->energy();
295 double e2 = (*iter_emc2)->energy();
297 RecEmcShowerCol::iterator iter_emc = emcShowerCol->begin();
298 for( ; iter_emc != emcShowerCol->end(); iter_emc++ ) {
299 etot += (*iter_emc)->energy();
300 }
301
302 if( m_checkDigi ) { m_checkdigi_tuple->
FillCol( *eventHeader, extTrackCol, mdcTrackCol, emcShowerCol, mdcKalTrackCol ); }
303
304 if( ( (*iter_mdc1)->charge() + (*iter_mdc2)->charge() )!= 0 ) return StatusCode::SUCCESS;
305 if( m_printOutInfo ) { m_printOut->
addNumber(6); }
306
307
308 if( delta_angle > 10.0 ) return StatusCode::SUCCESS;
309 if( m_printOutInfo ) { m_printOut->
addNumber(7); }
310
311 if( m_calibData == "Bhabha" ) {
312 if( (*iter_kal1)->getStat(1,0)!=0 || (*iter_kal2)->getStat(1,0)!=0 ) return StatusCode::SUCCESS;
313 if( m_printOutInfo ) { m_printOut->
addNumber(8); }
314
315 if( m_data == "jpsi" ) {
316 if( distant1.r()>6.0 || distant2.r()>6.0 ) return StatusCode::SUCCESS;
317 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
318 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;
319 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
320 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;
321 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
322 if( delta_phi<174.0 || delta_phi>186.0 ) return StatusCode::SUCCESS;
323 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
324 if(
e1 < 1.1 ||
e2 < 1.1 )
return StatusCode::SUCCESS;
325 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
326 }
327
328 else if( m_data == "psip" ) {
329 if( distant1.r()>6.0 || distant2.r()>6.0 ) return StatusCode::SUCCESS;
330 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
331 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;
332 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
333 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;
334 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
335 if( delta_phi<174.0 || delta_phi>183.0 ) return StatusCode::SUCCESS;
336 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
337 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
338 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
339 }
340
341 else if( m_data == "psipp10" ) {
342 if( distant1.r()>6.0 || distant2.r()>6.0 ) return StatusCode::SUCCESS;
343 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
344 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;
345 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
346 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;
347 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
348 if( delta_phi<174.0 || delta_phi>186.0 ) return StatusCode::SUCCESS;
349 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
350 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
351 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
352 }
353
354 else if( m_data == "psipp11" ) {
355 if( distant1.r()>6.0 || distant2.r()>6.0 ) return StatusCode::SUCCESS;
356 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
357 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;
358 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
359 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;
360 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
361 if( delta_phi<174.0 || delta_phi>184.0 ) return StatusCode::SUCCESS;
362 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
363 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
364 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
365 }
366
367 else if( m_data == "psip12" ) {
368 if( distant1.r()>6.0 || distant2.r()>6.0 ) return StatusCode::SUCCESS;
369 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
370 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;
371 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
372 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;
373 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
374 if( delta_phi<172.0 || delta_phi>188.0 ) return StatusCode::SUCCESS;
375 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
376 if(
e1 < 1.4 ||
e2 < 1.4 )
return StatusCode::SUCCESS;
377 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
378 }
379
380 else if( m_data == "jpsi12" ) {
381 if( distant1.r()>6.0 || distant2.r()>6.0 ) return StatusCode::SUCCESS;
382 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
383 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;
384 if( m_printOutInfo ) { m_printOut->
addNumber(10); }
385 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;
386 if( m_printOutInfo ) { m_printOut->
addNumber(11); }
387 if( delta_phi<172.0 || delta_phi>188.0 ) return StatusCode::SUCCESS;
388 if( m_printOutInfo ) { m_printOut->
addNumber(12); }
389 if(
e1 < 1.1 ||
e2 < 1.1 )
return StatusCode::SUCCESS;
390 if( m_printOutInfo ) { m_printOut->
addNumber(13); }
391 }
392 if( (
etot -
e1 -
e2 ) > 0.3 )
return StatusCode::SUCCESS;
393 if( m_printOutInfo ) { m_printOut->
addNumber(14); }
394 }
395 else if( m_calibData == "Dimu" ) {
396 if( (*iter_kal1)->getStat(1,1)!=0 || (*iter_kal2)->getStat(1,1)!=0 ) return StatusCode::SUCCESS;
397 if( m_printOutInfo ) { m_printOut->
addNumber(8); }
398 if(
e1 > 0.5 ||
e2 > 0.5 )
return StatusCode::SUCCESS;
399 if( m_printOutInfo ) { m_printOut->
addNumber(9); }
400 }
401
402 }
403
404
406 RecExtTrackCol::iterator iter_track = extTrackCol->begin();
407 for( ; iter_track < extTrackCol->end(); iter_track++ ) {
408 RecMdcKalTrackCol::iterator iter_kal = mdcKalTrackCol->begin();
409 for( ; iter_kal != mdcKalTrackCol->end(); iter_kal++ ) {
410 if( (*iter_kal)->trackId() == (*iter_track)->trackId() ) break;
411 }
412 int kal[5] = {-1};
413 if( iter_kal != mdcKalTrackCol->end() ) {
414 for( unsigned int i=0; i<5; i++ ) {
415 kal[i] = (*iter_kal)->getStat( 1, i );
416 }
417 }
419 tof->
setExtTrack( (*iter_track), kal, t0, t0Stat );
420
421 if( tofTrackVec->size()>0 ) {
422 std::vector<MrpcTrack*>::iterator iterExt = tofTrackVec->begin();
423 for( ; iterExt < tofTrackVec->end(); iterExt++ ) {
424 if( (*iterExt)->isNoHit() ) continue;
426 }
427 }
428
429 tofTrackVec->push_back( tof );
430 }
431
432 if( m_printOutInfo ) {
434 }
435
436
438 if( tofDataMap.empty() ) {
439 log << MSG::WARNING << "No Tof Data Map in RawDataProviderSvc! Run=" << run << " Event=" << event << endreq;
440 }
441
442 if( m_checkDigi && m_checkDigiRaw ) {
443 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc(),"/Event/Digi/TofDigiCol");
444 if( !tofDigiCol ) {
445 log << MSG::ERROR << "MrpcRec could not find Tof digi! Event = " << event << endreq;
446 }
447 else { m_checkdigi_tuple->
FillCol( *eventHeader, tofDigiCol, t0, t0Stat ); }
448
449 m_checkdigi_tuple->
FillCol( *eventHeader, tofDataMap, t0, t0Stat );
450 }
451
452 std::vector<int> deadId;
453 if( m_forCalibration ) {
454 for( unsigned int i=0; i<5; i++ ) {
456 if( identmp != 0x2fffffff ) {
457 deadId.push_back( identmp );
458 }
460 if( identmp != 0x2fffffff ) {
461 deadId.push_back( identmp );
462 }
464 if( identmp != 0x2fffffff ) {
465 deadId.push_back( identmp );
466 }
467 }
468 }
469
470 std::vector<MrpcTrack*>::iterator
iter = tofTrackVec->begin();
471 for( ;
iter < tofTrackVec->end();
iter++ ) {
472 if( (*iter)->isNoHit() ) continue;
473 (*iter)->setTofData( tofDataMap,m_neighborhood );
475 if( (*iter)->isNoHit() ) continue;
476 (*iter)->match( m_forCalibration, deadId, tofTrackVec );
478 }
479
480 iter = tofTrackVec->begin();
481 for( ;
iter < tofTrackVec->end();
iter++ ) {
482
483 (*iter)->setCalibration();
484
485 if( m_checkDigi ) {
486 if( m_checkTrigger ) {
487
488 SmartDataPtr<TrigData> trigData(eventSvc(), "/Event/Trig/TrigData");
489 if (!trigData) {
490 log << MSG::FATAL << "Could not find Trigger Data for physics analysis" << endreq;
492 }
493 else {
495 }
496 }
497 else {
498 if( ( run < 0 ) && m_checkMcTruth ) {
499 SmartDataPtr<TofMcHitCol> tofMcCol(eventSvc(),"/Event/MC/TofMcHitCol");
500 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
501 if ( !tofMcCol || !mcParticleCol ) {
502 m_checkdigi_tuple->
Fill_TofTrack( *eventHeader, *
iter, t0, t0Stat, mdcKalTrackCol );
503 }
504 else {
505 m_checkdigi_tuple->
Fill_TofTrack( *eventHeader, *
iter, t0, t0Stat, mdcKalTrackCol, tofMcCol, mcParticleCol, m_calibData );
506 }
507 }
508 else {
509 m_checkdigi_tuple->
Fill_TofTrack( *eventHeader, *
iter, t0, t0Stat, mdcKalTrackCol );
510 }
511 }
512 }
513 }
514
515 tds.
RegisterTDS( eventHeader->runNumber(), eventHeader->eventNumber(), tofTrackVec, m_forCalibration, m_calibData );
516
518
519
520 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),"/Event/Recon/RecTofTrackCol");
521 if (!tofTrackCol) {
522 log << MSG::FATAL << "MrpcRec could not find RecTofTrackCol!" << endreq;
523 return StatusCode::FAILURE;
524 }
525 else{
526 if( m_saveRootFile ) {
527 m_checkdata_tuple->
FillCol( *eventHeader, tofTrackCol, mdcKalTrackCol );
528 }
529 }
530
531 if( m_forCalibration ) {
532 SmartDataPtr<RecBTofCalHitCol> bhitCol(eventSvc(),"/Event/Recon/RecBTofCalHitCol");
533 if (!bhitCol) {
534 log << MSG::WARNING << "MrpcRec could not find RecBTofCalHitCol!" << endreq;
535 }
536 else {
537 if( m_saveRootFile ) {
538 m_checkdata_tuple->
FillCol( *eventHeader, bhitCol );
539 }
540 }
541
542 SmartDataPtr<RecETofCalHitCol> ehitCol(eventSvc(),"/Event/Recon/RecETofCalHitCol");
543 if (!ehitCol) {
544 log << MSG::WARNING << "MrpcRec could not find RecETofCalHitCol!" << endreq;
545 }
546 else {
547 if( m_saveRootFile ) {
548 m_checkdata_tuple->
FillCol( *eventHeader, ehitCol );
549 }
550 }
551 }
552
553 }
554 else {
555 log << MSG::FATAL << "In MrpcRec: AcceleratorStatus is NOT correct! m_acceleratorStatus = " << m_acceleratorStatus << endreq;
556 return StatusCode::FAILURE;
557 }
558
559 return StatusCode::SUCCESS;
560
561}
double abs(const EvtComplex &c)
IRawDataProviderSvc * tofDigiSvc
std::vector< MrpcTrack * > TofTrackVec
std::multimap< unsigned int, TofData * > TofDataMap
virtual TofDataMap & tofDataMapTof(double estime=0)=0
virtual const int BrWest(unsigned int No)=0
virtual const int BrEast(unsigned int No)=0
virtual const int Endcap(unsigned int No)=0
void FillCol(Event::EventHeader &, RecTofTrackCol &, RecMdcKalTrackCol &)
void Fill_TofTrack(Event::EventHeader &, MrpcTrack *&, double, int)
void FillCol(Event::EventHeader &, TofDigiCol &, double, int)
void setExtTrackNum(unsigned int ntrk)
void setTrack3(MrpcTrack *&tof)
void setTrack2(MrpcTrack *&tof)
void setTrack1Col(std::vector< MrpcTrack * > *&tofTrackVec)
void addNumber(unsigned int i)
StatusCode RegisterNullRecTofTrackCol()
StatusCode RegisterTDS(int runNumber, int eventNumber, std::vector< MrpcTrack * > *&tofTrackVec, bool m_forCalibration, std::string m_calibData)
void clearTofTrackVec(std::vector< MrpcTrack * > *&tofTrackVec)
void getMultiHit(MrpcTrack *&)
void setExtTrack(RecExtTrack *extTrack, int kal[5], double t0, int t0Stat)