174 if ( sc.isFailure() )
176 error() <<
"beginRun failed" << endmsg;
177 return StatusCode::FAILURE;
182 MsgStream log(
msgSvc(), name() );
183 log << MSG::INFO <<
"in execute()" << endmsg;
185 setFilterPassed(
false );
187 SmartDataPtr<Event::EventHeader> evtHead( eventSvc(),
"/Event/EventHeader" );
190 log << MSG::FATAL <<
"Could not retrieve event header" << endmsg;
191 return StatusCode::FAILURE;
193 long t_runNo = evtHead->runNumber();
194 long t_evtNo = evtHead->eventNumber();
196 std::cout <<
"sew " << ++i_evt <<
" run " << t_runNo <<
" evt " << t_evtNo << std::endl;
200 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc(),
"/Event/Recon/RecEsTimeCol" );
201 if ( !aevtimeCol || aevtimeCol->size() == 0 )
203 log << MSG::WARNING <<
"Could not find RecEsTimeCol" << endmsg;
204 return StatusCode::SUCCESS;
206 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
207 for ( ; iter_evt != aevtimeCol->end(); iter_evt++ ) { m_bunchT0 = ( *iter_evt )->getTest(); }
212 if ( !recMdcTrackCol || !recMdcHitCol )
return StatusCode::SUCCESS;
213 if ( 2 != recMdcTrackCol->size() )
216 return StatusCode::SUCCESS;
218 if ( m_debug ) std::cout << name() <<
" nTk==2 begin sewing" << std::endl;
221 double dParam[5] = { 0., 0., 0., 0., 0. };
224 RecMdcTrackCol::iterator besthel;
226 int besthelId = -999;
227 RecMdcTrackCol::iterator it = recMdcTrackCol->begin();
228 for (
int iTk = 0; it != recMdcTrackCol->end(); it++, iTk++ )
231 double Bz = m_bfield->bFieldNominal();
232 double d0 = -tk->
helix( 0 );
233 double phi0 = tk->
helix( 1 ) + CLHEP::halfpi;
234 double omega = Bz * tk->
helix( 2 ) / -333.567;
235 double z0 = tk->
helix( 3 );
236 double tanl = tk->
helix( 4 );
242 std::cout << __FILE__ <<
" " << __LINE__ <<
"tk" << iTk <<
"(" << d0 <<
"," << phi0
244 <<
"," << omega <<
"," << z0 <<
"," << tanl <<
")" << std::endl;
268 float bchisq = tk->
chi2();
269 int bndof = tk->
ndof();
278 if ( besthelId == -999 )
return StatusCode::SUCCESS;
285 std::cout << __FILE__ <<
" param diff: "
286 <<
"\n D0 " << dParam[0] <<
"\n Phi0 " << dParam[1] <<
"\n Omega " << dParam[2]
287 <<
"\n Z0 " << dParam[3] <<
"\n Tanl " << dParam[4] << std::endl;
292 m_csmcD0 = dParam[0];
293 m_csmcPhi0 = dParam[1];
294 m_csmcOmega = dParam[2];
295 m_csmcZ0 = dParam[3];
296 m_csmcTanl = dParam[4];
297 m_xtupleCsmcSew->write();
301 if ( ( fabs( dParam[0] ) > m_cosmicSewPar[0] ) ||
302 ( fabs( dParam[1] ) > m_cosmicSewPar[1] ) ||
303 ( fabs( dParam[2] ) > m_cosmicSewPar[2] ) ||
304 ( fabs( dParam[3] ) > m_cosmicSewPar[3] ) || ( fabs( dParam[4] ) > m_cosmicSewPar[4] ) )
306 if ( m_debug ) std::cout << __FILE__ <<
" 2 trk param not satisfied skip!" << std::endl;
309 if ( fabs( dParam[0] ) > m_cosmicSewPar[0] ) std::cout <<
" cut by d0 " << std::endl;
310 if ( fabs( dParam[1] ) > m_cosmicSewPar[1] ) std::cout <<
" cut by phi0 " << std::endl;
311 if ( fabs( dParam[2] ) > m_cosmicSewPar[2] ) std::cout <<
" cut by omega " << std::endl;
312 if ( fabs( dParam[3] ) > m_cosmicSewPar[3] ) std::cout <<
" cut by z0" << std::endl;
313 if ( fabs( dParam[4] ) > m_cosmicSewPar[4] ) std::cout <<
" cut by tanl" << std::endl;
316 return StatusCode::SUCCESS;
321 double Bz = m_bfield->bFieldNominal();
322 double d0 = -tk->
helix( 0 );
323 double phi0 = tk->
helix( 1 ) + CLHEP::halfpi;
324 double omega = Bz * tk->
helix( 2 ) / -333.567;
325 double z0 = tk->
helix( 3 );
326 double tanl = tk->
helix( 4 );
330 std::cout << __FILE__ <<
" best helix: No." << tk->
trackId() <<
" Pat param=(" << d0 <<
" "
331 << phi0 <<
" " << omega <<
" " << z0 <<
" " << tanl <<
")" << std::endl;
337 newTrack = linefactory.
makeTrack( tt, chisum, *m_context, m_bunchT0 * 1.e-9 );
342 newTrack = helixfactory.
makeTrack( tt, chisum, *m_context, m_bunchT0 * 1.e-9 );
348 it = recMdcTrackCol->begin();
349 for (
int iTk = 0; it != recMdcTrackCol->end(); it++, iTk++ )
353 HepVector helixPatPar = m_mdcUtilitySvc->besPar2PatPar( tk->
helix() );
366 if ( m_debug ) std::cout << __FILE__ <<
" sew fit failed!!!" << std::endl;
367 HitRefVec::iterator it = skippedHits.begin();
368 for ( ; it != skippedHits.end(); ++it ) {
delete it->data(); }
377 if ( m_lineFit ) { linefactory.
setFlipAndDrop( *newTrack,
false,
false ); }
381 std::cout << __FILE__ <<
" sew cosmic fit good " << std::endl;
382 newTrack->
print( std::cout );
385 SmartDataPtr<MdcHitCol> m_hitCol( eventSvc(),
"/Event/Hit/MdcHitCol" );
389 StatusCode sc = eventSvc()->registerObject(
"/Event/Hit/MdcHitCol", m_hitCol );
390 if ( !sc.isSuccess() )
392 std::cout <<
" Could not register MdcHitCol" << endmsg;
393 return StatusCode::FAILURE;
396 uint32_t getDigiFlag = 0;
397 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec( getDigiFlag );
398 const MdcDigi* m_digiMap[43][288];
399 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
400 for ( ;
iter != mdcDigiVec.end();
iter++ )
406 m_digiMap[layer][wire] = aDigi;
410 HitRefVec::iterator itHitSkipped = skippedHits.begin();
411 for ( ; itHitSkipped != skippedHits.end(); ++itHitSkipped )
418 HepVector helix = newFit->
helix( fltLen ).
params();
423 double doca = m_mdcUtilitySvc->docaPatPar( layer, wire, helix, err );
424 double newDoca = fabs( doca );
426 if ( flagLR == 0 ) { newDoca = -fabs( doca ); }
429 std::cout <<
"(" << layer <<
"," << wire <<
") new doca " << newDoca <<
" resid "
431 if ( m_debug >= 3 && fabs( fabs( newDoca ) - fabs( h->
getDriftDistLeft() ) ) > 0.02 )
432 std::cout <<
" bad resid " << fabs( fabs( newDoca ) - fabs( h->
getDriftDistLeft() ) )
436 MdcHit* thehit =
new MdcHit( m_digiMap[layer][wire], m_gm );
440 m_hitCol->push_back( thehit );
444 getInfo( helix, 0, poca, tempDir );
445 if ( m_debug > 3 ) std::cout <<
"track poca " << poca << std::endl;
448 getInfo( helix, docaFltLen, pos, dir );
450 if ( pos.y() > poca.y() )
452 int wireAmb = patAmbig( flagLR );
454 double tof = docaFltLen /
Constants::c + ( m_bunchT0 ) * 1.e-9;
461 double dist = thehit->
driftDist( tof, wireAmb, eAngle, dAngle, z );
462 double sigma = thehit->
sigma( dist, wireAmb, eAngle, dAngle, z );
464 if ( m_debug > 3 && fabs( fabs( h->
getDoca() ) - fabs( dist ) ) > 0.02 )
465 std::cout <<
"(" << layer <<
"," << wire <<
") old doca " << h->
getDoca()
483 store( newTrack, skippedHits );
485 setFilterPassed(
true );
489 if ( m_debug ) { m_mdcPrintSvc->printRecMdcTrackCol(); }
491 return StatusCode::SUCCESS;
506 SmartDataPtr<MdcHitCol> m_hitCol( eventSvc(),
"/Event/Hit/MdcHitCol" );
510 StatusCode sc = eventSvc()->registerObject(
"/Event/Hit/MdcHitCol", m_hitCol );
511 if ( !sc.isSuccess() )
513 std::cout <<
" Could not register MdcHitCol" << endmsg;
519 uint32_t getDigiFlag = 0;
520 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec( getDigiFlag );
521 if ( 0 == mdcDigiVec.size() )
523 std::cout <<
" No hits in MdcDigiVec" << std::endl;
526 const MdcDigi* m_digiMap[43][288];
527 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
528 for ( ;
iter != mdcDigiVec.end();
iter++ )
534 m_digiMap[layer][wire] = aDigi;
539 getInfo( helix, 0, poca, tempDir );
540 if ( m_debug > 3 ) std::cout <<
"track poca " << poca << std::endl;
542 HitRefVec::iterator itHit = recMdcHits.begin();
543 for ( ; itHit != recMdcHits.end(); ++itHit )
552 getInfo( helix, h->
getFltLen(), pos, dir );
553 int newAmbig = patAmbig( h->
getFlagLR() );
554 if ( pos.y() > poca.y() )
558 if ( m_debug > 3 ) std::cout <<
" Up track, change sign of fltLen " << std::endl;
560 int newFlagLR = bes3FlagLR( newAmbig );
562 if ( m_cosmicSewSkip && layer < 20 )
576 newSkippedHit->
setDoca( 999. );
581 skippedHits.push_back( newSkippedHit );
585 MdcHit* thehit =
new MdcHit( m_digiMap[layer][wire], m_gm );
589 m_hitCol->push_back( thehit );
595 std::cout << name() <<
" (" << layer <<
"," << wire <<
") fltLen " << h->
getFltLen()
596 <<
" newFltLen " << newFltLen <<
" newAmbig " << newAmbig <<
" pos.y() "
597 << pos.y() << std::endl;
606 MsgStream log(
msgSvc(), name() );
608 assert( aTrack != NULL );
611 SmartIF<IDataManagerSvc> dataManSvc( eventSvc() );
612 DataObject* aTrackCol;
613 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol", aTrackCol );
614 if ( aTrackCol != NULL )
616 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol" );
617 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol" );
620 DataObject* aRecHitCol;
621 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol", aRecHitCol );
622 if ( aRecHitCol != NULL )
624 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol" );
625 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol" );
633 if ( !sc.isSuccess() )
634 { log << MSG::FATAL <<
" Could not register RecMdcTrack collection" << endmsg; }
642 if ( !sc.isSuccess() )
643 { log << MSG::FATAL <<
" Could not register RecMdcHit collection" << endmsg; }
645 int trackId = trackList->size() - 1;
647 if ( m_debug ) std::cout << __FILE__ <<
" " << __LINE__ <<
" STORED" << std::endl;
652 mdcTrack.
storeTrack( trackId, trackList, hitList, tkStat );
655 RecMdcTrackCol::iterator it = trackList->begin();
658 HitRefVec::iterator itHit = hl.begin();
660 for ( ; itHit != hl.end(); ++itHit )
664 SmartRef<RecMdcHit> refHit( h );
665 hitRefVec.push_back( refHit );
669 std::cout << __FILE__ <<
" " << __LINE__ <<
"refHit stored " << ihl << std::endl;
671 HitRefVec::iterator itHitSkipped = skippedHits.begin();
673 for ( ; itHitSkipped != skippedHits.end(); ++itHitSkipped )
676 ( *itHitSkipped )->setTrkId( trackId );
677 hitList->push_back( *itHitSkipped );
678 SmartRef<RecMdcHit> refHitSkipped( *itHitSkipped );
679 hitRefVec.push_back( refHitSkipped );
682 std::cout << __FILE__ <<
" " << __LINE__ <<
"skippedHits stored " << iskipped << std::endl;
683 ( *it )->setVecHits( hitRefVec );
685 ( *it )->setNhits( ( *it )->getVecHits().size() );
686 ( *it )->setNster( -1 );
689 if ( ( *it )->helix( 2 ) < 0.00001 ) ( *it )->setNdof( ( *it )->getNhits() - 4 );
690 else ( *it )->setNdof( ( *it )->getNhits() - 5 );
693 std::cout << __FILE__ <<
" " << __LINE__ <<
" stored " << ( *it )->getVecHits().size()