177 MsgStream log(
msgSvc(), name() );
178 log << MSG::INFO <<
"in execute()" << endmsg;
183 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(),
"/Event/EventHeader" );
186 log << MSG::FATAL <<
"Could not find Event Header" << endmsg;
187 return ( StatusCode::FAILURE );
189 log << MSG::INFO <<
"Run: " << eventHeader->runNumber()
190 <<
" Event: " << eventHeader->eventNumber() << endmsg;
192 event = eventHeader->eventNumber();
193 run = eventHeader->runNumber();
196 string release = getenv(
"BES_RELEASE" );
200 for ( std::vector<FilterEvent>::iterator it = m_filter_event.begin();
201 it != m_filter_event.end(); ++it )
203 const FilterEvent& fe = ( *it );
204 if (
release == fe.bossver && run == fe.runid && event == fe.eventid )
206 cout <<
"SKIP: " << fe.bossver <<
" " << fe.runid <<
" " << fe.eventid << std::endl;
207 return StatusCode::SUCCESS;
215 Hep3Vector cosmicMom;
216 if ( m_mccosmic == 1 )
218 SmartDataPtr<McParticleCol> mcParticleCol( eventSvc(),
"/Event/MC/McParticleCol" );
219 if ( !mcParticleCol )
221 log << MSG::FATAL <<
"Could not find McParticle" << endmsg;
222 return ( StatusCode::FAILURE );
225 McParticleCol::iterator iter_mc = mcParticleCol->begin();
226 for ( ; iter_mc != mcParticleCol->end(); iter_mc++, digiId++ )
228 log << MSG::DEBUG <<
" particleId = " << ( *iter_mc )->particleProperty() << endmsg;
229 int pid = ( *iter_mc )->particleProperty();
231 if ( fabs( pid ) != 13 )
continue;
233 HepLorentzVector initialMomentum = ( *iter_mc )->initialFourMomentum();
234 Hep3Vector startP( initialMomentum.px(), initialMomentum.py(), initialMomentum.pz() );
235 Hep3Vector rotate( -initialMomentum.px(), initialMomentum.pz(), initialMomentum.py() );
237 if ( m_NtOutput >= 1 )
239 m_px_mc = initialMomentum.px();
240 m_py_mc = initialMomentum.py();
241 m_pz_mc = initialMomentum.pz();
243 m_theta_mc = rotate.theta();
244 m_phi_mc = rotate.phi();
246 m_theta_mc_pipe = startP.theta();
247 m_phi_mc_pipe = startP.phi();
312 SmartDataPtr<MucDigiCol> mucDigiCol( eventSvc(),
"/Event/Digi/MucDigiCol" );
315 log << MSG::FATAL <<
"Could not find MUC digi" << endmsg;
316 return ( StatusCode::FAILURE );
319 MucDigiCol::iterator iter4 = mucDigiCol->begin();
321 for ( ; iter4 != mucDigiCol->end(); iter4++, digiId++ ) {}
322 log << MSG::INFO <<
"MUC digis:: " << digiId << endmsg;
323 if ( digiId == 0 )
return ( StatusCode::SUCCESS );
335 aMucRecHitContainer->Clear();
338 aMucRecHitContainer->SetMucRecHitCol( aMucRecHitCol );
340 SmartIF<IDataManagerSvc> dataManSvc( eventSvc() );
341 DataObject* mucRecHitCol;
342 eventSvc()->findObject(
"/Event/Recon/MucRecHitCol", mucRecHitCol );
343 if ( mucRecHitCol != NULL )
345 dataManSvc->clearSubTree(
"/Event/Recon/MucRecHitCol" );
346 eventSvc()->unregisterObject(
"/Event/Recon/MucRecHitCol" );
349 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon/MucRecHitCol",
350 aMucRecHitContainer->GetMucRecHitCol() );
352 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
354 for ( ; iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++ )
356 mucID = ( *iterMuc )->identify();
364 aMucRecHitContainer->AddHit( part, seg, gap, strip );
365 log << MSG::INFO <<
" digit" << mucDigiId <<
" : "
366 <<
" part " << part <<
" seg " << seg <<
" gap " << gap <<
" strip " << strip
370 DataObject* aReconEvent;
371 eventSvc()->findObject(
"/Event/Recon", aReconEvent );
372 if ( aReconEvent == NULL )
376 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon", aReconEvent );
377 if ( sc != StatusCode::SUCCESS )
379 log << MSG::FATAL <<
"Could not register ReconEvent" << endmsg;
380 return ( StatusCode::FAILURE );
383 StatusCode fr = eventSvc()->findObject(
"/Event/Recon", aReconEvent );
384 if ( fr != StatusCode::SUCCESS )
386 log << MSG::WARNING <<
"Could not find register ReconEvent, will create it" << endmsg;
387 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon", aReconEvent );
388 if ( sc != StatusCode::SUCCESS )
390 log << MSG::FATAL <<
"Could not register ReconEvent" << endmsg;
391 return ( StatusCode::FAILURE );
397 DataObject* mucTrackCol;
398 eventSvc()->findObject(
"/Event/Recon/RecMucTrackCol", mucTrackCol );
399 if ( mucTrackCol != NULL )
401 dataManSvc->clearSubTree(
"/Event/Recon/RecMucTrackCol" );
402 eventSvc()->unregisterObject(
"/Event/Recon/RecMucTrackCol" );
406 sc = eventSvc()->registerObject(
"/Event/Recon/RecMucTrackCol", aMucTrackCol );
407 aMucTrackCol->clear();
410 SmartDataPtr<RecMucTrackCol> findMucTrackCol( eventSvc(),
"/Event/Recon/RecMucTrackCol" );
411 if ( !findMucTrackCol )
413 log << MSG::FATAL <<
"Could not find RecMucTrackCol" << endmsg;
414 return ( StatusCode::FAILURE );
416 aMucTrackCol->clear();
418 log << MSG::INFO <<
"MaxHitsRec : " << m_maxHitsRec << endmsg;
419 if ( digiId > m_maxHitsRec )
420 return StatusCode::SUCCESS;
427 else if ( m_united == 1 )
432 aMucRecHitContainer->Clear();
434 SmartDataPtr<MucRecHitCol> aMucRecHitCol( eventSvc(),
"/Event/Recon/MucRecHitCol" );
435 if ( aMucRecHitCol == NULL ) { log << MSG::WARNING <<
"MucRecHitCol is NULL" << endmsg; }
437 aMucRecHitContainer->SetMucRecHitCol( aMucRecHitCol );
439 SmartDataPtr<RecMucTrackCol> mucTrackCol( eventSvc(),
"/Event/Recon/RecMucTrackCol" );
440 if ( mucTrackCol == NULL ) { log << MSG::WARNING <<
"aMucTrackCol is NULL" << endmsg; }
442 log << MSG::INFO <<
"mucTrackCol size: " << mucTrackCol->size()
443 <<
" hitCol size: " << aMucRecHitCol->size() << endmsg;
444 aMucTrackCol = mucTrackCol;
447 SmartDataPtr<RecExtTrackCol> aExtTrackCol( eventSvc(),
"/Event/Recon/RecExtTrackCol" );
448 if ( !aExtTrackCol ) { log << MSG::WARNING <<
"Can't find ExtTrackCol in TDS!" << endmsg; }
450 SmartDataPtr<RecMdcTrackCol> aMdcTrackCol( eventSvc(),
"/Event/Recon/RecMdcTrackCol" );
451 if ( !aMdcTrackCol ) { log << MSG::WARNING <<
"Can't find MdcTrackCol in TDS!" << endmsg; }
453 if ( aExtTrackCol && aMdcTrackCol ) trackId = aMdcTrackCol->size();
454 muctrackId = aMucTrackCol->size();
459 SmartDataPtr<RecEmcShowerCol> aShowerCol( eventSvc(),
"/Event/Recon/RecEmcShowerCol" );
462 log << MSG::WARNING <<
"Could not find RecEmcShowerCol" << endmsg;
467 RecEmcShowerCol::iterator iShowerCol;
468 for ( iShowerCol = aShowerCol->begin(); iShowerCol != aShowerCol->end(); iShowerCol++ )
476 if ( ( ( *iShowerCol )->position() ).phi() > 0 &&
477 ( ( *iShowerCol )->position() ).phi() < 3.1415926 )
482 if ( m_NtOutput >= 1 )
485 m_emcDown = hasEmcDown;
504 log << MSG::INFO <<
"Muc 2D 3D Road Container created" << endmsg;
514 int count0, count1,
count, iGap0, iGap1;
521 for (
int iOrient = 0; iOrient < 2; iOrient++ )
525 for (
int iLoop = 0; iLoop < nLoops; iLoop++ )
529 if ( m_seedtype == 1 )
537 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
542 for ( ; iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++ )
544 mucID = ( *iterMuc )->identify();
550 if ( ( part == 1 && gap % 2 == 0 ) || ( part != 1 && gap % 2 == 1 ) ) orient = 1;
552 if ( part == iPart && seg == iSeg && orient == iOrient && setgap0 == 0 )
557 if ( part == iPart && seg == iSeg && orient == iOrient && setgap0 == 1 &&
564 cout <<
"Find seed gap in ( " << iPart <<
" " << iSeg <<
" ) gap0: " << iGap0
565 <<
" gap1: " << iGap1 << endl;
574 if ( iGap1 == iGap0 )
continue;
576 count0 = aMucRecHitContainer->GetGapHitCount( iPart, iSeg, iGap0 );
577 for (
int iHit0 = 0; iHit0 < count0; iHit0++ )
580 pHit0 = aMucRecHitContainer->GetHit( iPart, iSeg, iGap0, iHit0 );
583 log << MSG::FATAL <<
"MucRecRoadFinder-E10 "
584 <<
" part " << iPart <<
" seg " << iSeg <<
" gap " << iGap0
585 <<
" null pointer" << endl;
591 if ( m_united == 1 && pHit0->
GetHitMode() != -1 )
continue;
593 count1 = aMucRecHitContainer->GetGapHitCount( iPart, iSeg, iGap1 );
595 cout <<
"part " << iPart <<
" seg " << iSeg <<
" orient " << iOrient
596 <<
" gap0 " << iGap0 <<
" count0 " << count0 <<
" gap1 " << iGap1
597 <<
" count1 " << count1 << endl;
598 for (
int iHit1 = 0; iHit1 < count1; iHit1++ )
601 pHit1 = aMucRecHitContainer->GetHit( iPart, iSeg, iGap1, iHit1 );
604 log << MSG::ERROR <<
"MucRecRoadFinder-E10 "
605 <<
" part " << iPart <<
" seg " << iSeg <<
" gap " << iGap1
606 <<
" null pointer" << endl;
612 if ( m_united == 1 && pHit1->GetHitMode() != -1 )
continue;
617 new MucRec2DRoad( iPart, iSeg, iOrient, 0.0, 0.0, 3000.0 );
620 log << MSG::FATAL <<
"MucRecRoadFinder-E20 "
621 <<
"failed to create 2D road!" << endmsg;
627 log << MSG::ERROR <<
"pHit0->GetGap(), null pointer" << endmsg;
638 pHit1->SetHitSeed(
true );
643 <<
", hitId= " << pHit0->
Part() <<
" " << pHit0->
Seg() <<
" "
644 << pHit0->
Gap() <<
" " << pHit0->
Strip() << endl;
647 if ( pHit1->GetGap()->Orient() == iOrient )
657 <<
", hitId= " << pHit1->Part() <<
" " << pHit1->Seg() <<
" "
658 << pHit1->Gap() <<
" " << pHit1->Strip() << endl;
661 cout <<
"Hit cout " << road2D->
GetTotalHits() <<
", slope "
669 for (
int i = 0; i < length; i++ )
673 float dXmin = kInfinity;
684 count = aMucRecHitContainer->GetGapHitCount( iPart, iSeg, iGap );
685 for (
int iHit = 0; iHit <
count; iHit++ )
687 pHit = aMucRecHitContainer->GetHit( iPart, iSeg, iGap, iHit );
690 log << MSG::FATAL <<
"MucRecRoadFinder-E20 null cluster pointer pHit"
698 if ( m_united == 1 && pHit->
GetHitMode() != -1 )
continue;
703 cout <<
"dX = " << dX <<
" Win = " << Win
704 <<
", hit: " << pHit->
Part() <<
" " << pHit->
Seg() <<
" "
705 << pHit->
Gap() <<
" " << pHit->
Strip() << endl;
711 if ( iGap == iGap0 || iGap == iGap1 )
725 if ( m_onlyseedfit == 0 ) road2D->
AttachHit( pHit );
728 if ( iGap == iGap0 || iGap == iGap1 ) road2D->
AttachHit( pHit );
743 bool lastGapOK =
false;
747 log << MSG::INFO <<
" 2D lastGap " << road2D->
GetLastGap() <<
" < "
754 bool firedGapsOK =
false;
763 bool duplicateRoad =
false;
764 int maxSharedHits = 0, sharedHits = 0;
767 for (
int index = 0; index < (int)p2DRoad0C->size(); index++ )
768 { sharedHits = ( *p2DRoad0C )[index]->GetNSharedHits( road2D ); }
769 if ( maxSharedHits < sharedHits ) maxSharedHits = sharedHits;
773 for (
int index = 0; index < (int)p2DRoad1C->size(); index++ )
774 { sharedHits = ( *p2DRoad1C )[index]->GetNSharedHits( road2D ); }
775 if ( maxSharedHits < sharedHits ) maxSharedHits = sharedHits;
781 duplicateRoad =
true;
782 log << MSG::INFO <<
" maxSharedHits " << maxSharedHits <<
" > "
792 if ( lastGapOK && firedGapsOK && !duplicateRoad )
796 log << MSG::INFO <<
"Add a road0" << endmsg;
797 p2DRoad0C->add( road2D );
801 log << MSG::INFO <<
"Add a road1" << endmsg;
802 p2DRoad1C->add( road2D );
809 vector<MucRecHit*> road2DHits = road2D->
GetHits();
810 for (
int i = 0; i < road2DHits.size(); i++ )
813 if ( ihit->
Gap() == iGap0 || ihit->
Gap() == iGap1 )
830 int print2DRoadInfo = 0;
831 if ( print2DRoadInfo == 1 )
834 cout <<
"In 2DRoad container : " << endl
835 <<
" Num of 2DRoad0 = " << p2DRoad0C->size() << endl
838 for (
int iRoad = 0; iRoad < (int)p2DRoad0C->size(); iRoad++ )
842 cout <<
" " << iRoad <<
"th 2DRoad0 :" << endl
843 <<
" Part = " << road->
GetPart() << endl
844 <<
" Seg = " << road->
GetSeg() << endl
845 <<
" Orient = " << road->
GetOrient() << endl
846 <<
" LastGap = " << road->
GetLastGap() << endl
849 <<
" Slope = " << road->
GetSlope() << endl
855 cout <<
" Num of 2DRoad1 = " << p2DRoad1C->size() << endl << endl;
857 for (
int iRoad = 0; iRoad < (int)p2DRoad1C->size(); iRoad++ )
861 cout <<
" " << iRoad <<
"th 2DRoad1 :" << endl
862 <<
" Part = " << road->
GetPart() << endl
863 <<
" Seg = " << road->
GetSeg() << endl
864 <<
" Orient = " << road->
GetOrient() << endl
865 <<
" LastGap = " << road->
GetLastGap() << endl
868 <<
" Slope = " << road->
GetSlope() << endl
877 for (
int iRoad0 = 0; iRoad0 < (int)p2DRoad0C->size(); iRoad0++ )
880 for (
int iRoad1 = 0; iRoad1 < (int)p2DRoad1C->size(); iRoad1++ )
885 if ( !( road0 && road1 ) )
887 cout <<
"Null pointer to road0 or road1: "
888 <<
"road0 = " << road0 <<
"road1 = " << road1 << endl;
909 bool lastGapDeltaOK =
false;
911 else { cout <<
"LastGapDelta = " << road3D->
GetLastGapDelta() << endl; }
913 bool totalHitsDeltaOK =
false;
920 bool chiSquareCutOK =
false;
924 else { cout <<
"xChiSquare = " << xChiSquare <<
"yChiSquare = " << yChiSquare << endl; }
926 bool minLastGapOK =
false;
928 else { log << MSG::INFO <<
" minLastGap = " << road3D->
GetLastGap() << endmsg; }
930 bool duplicateRoad =
false;
931 int maxSharedHits = 0, sharedHits = 0;
932 for (
int i = 0; i < (int)p3DRoadC->size(); i++ )
934 sharedHits = ( *p3DRoadC )[i]->GetNSharedHits( road3D );
935 if ( maxSharedHits < sharedHits ) maxSharedHits = sharedHits;
941 duplicateRoad =
true;
942 log << MSG::INFO <<
" MaxShareHits = " << maxSharedHits << endmsg;
945 if ( lastGapDeltaOK && totalHitsDeltaOK && chiSquareCutOK && minLastGapOK &&
948 float vx, vy, x0, y0;
949 float slope1 = 100, slope0 = 100;
967 log << MSG::INFO <<
"Add a 3D Road ... " << endmsg;
969 float startx = 0.0, starty = 0.0, startz = 0.0;
970 float sigmax = 0.0, sigmay = 0.0, sigmaz = 0.0;
971 road3D->
ProjectWithSigma( 0, startx, starty, startz, sigmax, sigmay, sigmaz );
977 float sign = vy / fabs( vy );
978 float signx = vx / fabs( vx );
982 if ( road3D->
GetSeg() > 4 )
989 else if ( road3D->
GetSeg() < 2 )
995 else if ( road3D->
GetSeg() >= 3 && road3D->
GetSeg() <= 4 )
1008 else if ( road3D->
GetPart() == 0 )
1016 else if ( road3D->
GetPart() == 2 )
1028 Hep3Vector mom( vx, vy, vz );
1038 startx -= vx / mom.mag();
1039 starty -= vy / mom.mag();
1040 startz -= vz / mom.mag();
1046 aTrack->
SetMucPos( startx, starty, startz );
1055 aTrack->
setId( muctrackId );
1060 aMucTrackCol->add( aTrack );
1062 p3DRoadC->add( road3D );
1066 vector<MucRecHit*> attachedHits = aTrack->
GetHits();
1068 vector<float> distanceHits = aTrack->
getDistHits();
1070 for (
int i = 0; i < expectedHits.size(); i++ )
1077 vector<int> multiHit;
1078 for (
int i = 0; i < attachedHits.size(); i++ )
1084 for (
int k = 0; k < attachedHits.size(); k++ )
1087 if ( ( ihit->
Part() == khit->
Part() ) && ( ihit->
Seg() == khit->
Seg() ) &&
1088 ( ihit->
Gap() == khit->
Gap() ) )
1091 multiHit.push_back( hitnum );
1095 for (
int i = 0; i < expectedHits.size(); i++ )
1104 for (
int j = 0; j < attachedHits.size(); j++ )
1111 if ( ( jhit->
Part() == ihit->
Part() ) && ( jhit->
Seg() == ihit->
Seg() ) &&
1112 ( jhit->
Gap() == ihit->
Gap() ) && attachedHits.size() == distanceHits.size() )
1117 if ( m_NtOutput >= 2 )
1120 m_part = ihit->
Part();
1121 m_seg = ihit->
Seg();
1122 m_gap = ihit->
Gap();
1123 m_strip = jhit->
Strip();
1125 m_dist = distanceHits[j];
1128 m_angle_cosmic = -999;
1129 m_angle_updown = -999;
1137 m_multihit = multiHit[j];
1138 m_run = eventHeader->runNumber();
1139 m_event = eventHeader->eventNumber();
1148 if ( m_NtOutput >= 2 )
1150 m_part = ihit->
Part();
1151 m_seg = ihit->
Seg();
1152 m_gap = ihit->
Gap();
1153 m_strip = ihit->
Strip();
1156 m_angle_updown = -999;
1157 m_angle_cosmic = -999;
1163 m_run = eventHeader->runNumber();
1164 m_event = eventHeader->eventNumber();
1219 for (
int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++ )
1221 aaTrack = ( *aMucTrackCol )[iTrack];
1227 double px, py, pz, p, theta, phi;
1232 if ( py < 0 )
continue;
1234 if ( m_NtOutput >= 1 )
1237 m_angle_updown = -999;
1239 if ( m_angle_cosmic > 1.57 ) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
1240 m_run = eventHeader->runNumber();
1241 m_event = eventHeader->eventNumber();
1243 Hep3Vector rotate( -px, pz, py );
1244 theta = rotate.theta();
1258 Hep3Vector mucPos = aaTrack->
getMucPos();
1259 double posx, posy, posz;
1268 m_projx = posx - px / py * posy;
1269 m_projz = posz - pz / py * posy;
1274 if ( m_NtOutput >= 1 )
1277 m_mucDown = hasMucDown;
1282 if ( aMucTrackCol->size() >= 2 && forCosmic == 1 )
1284 for (
int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++ )
1286 log << MSG::DEBUG <<
"iTrack " << iTrack <<
" / " << (int)aMucTrackCol->size() << endmsg;
1287 aaTrack = ( *aMucTrackCol )[iTrack];
1288 if ( aaTrack->
trackId() >= 0 )
continue;
1291 for (
int jTrack = iTrack + 1; jTrack < (int)aMucTrackCol->size(); jTrack++ )
1293 bbTrack = ( *aMucTrackCol )[jTrack];
1299 if ( fabs( mom_a.angle( mom_b ) - 3.1415926 ) < 0.2 )
1308 if ( m_NtOutput >= 1 )
1310 m_angle_cosmic = cosmicMom.angle( mom_a );
1311 if ( cosmicMom.angle( mom_a ) > 1.57 )
1312 m_angle_cosmic = 3.14159265 - cosmicMom.angle( mom_a );
1314 m_angle_updown = fabs( mom_a.angle( mom_b ) - 3.1415926 );
1320 m_theta_pipe = -999;
1327 m_theta_mc_pipe = -999;
1328 m_phi_mc_pipe = -999;
1336 if ( p3DRoadC->size() != 0 )
1338 log << MSG::INFO <<
"In 3DRoad container : "
1339 <<
" Num of 3DRoad = " << p3DRoadC->size() << endmsg;
1341 int print2DRoadInfo = 0;
1342 if ( print2DRoadInfo == 1 )
1344 for (
int iRoad = 0; iRoad < (int)p3DRoadC->size(); iRoad++ )
1348 <<
" " << iRoad <<
"th 3DRoad :" << endl
1349 <<
" Part = " << road->
GetPart() << endl
1350 <<
" Seg = " << road->
GetSeg() << endl
1358 <<
" SlopeZX = " << road->
GetSlopeZX() << endl
1360 <<
" SlopeZY = " << road->
GetSlopeZY() << endl
1362 <<
" Hits Info : " << endl;
1371 for (
int i = 0; i < p3DRoadC->size(); i++ )
delete ( *p3DRoadC )[i];
1372 for (
int i = 0; i < p2DRoad0C->size(); i++ )
delete ( *p2DRoad0C )[i];
1373 for (
int i = 0; i < p2DRoad1C->size(); i++ )
delete ( *p2DRoad1C )[i];
1382 return StatusCode::SUCCESS;