173 MsgStream log(
msgSvc(), name());
174 log << MSG::INFO <<
"in execute()" << endreq;
179 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
181 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
182 return( StatusCode::FAILURE);
184 log << MSG::INFO <<
"Run: " << eventHeader->runNumber() <<
" Event: " << eventHeader->eventNumber() << endreq;
186event = eventHeader->eventNumber();
187run = eventHeader->runNumber();
190 string release = getenv(
"BES_RELEASE");
194 for (std::vector<FilterEvent>::iterator it = m_filter_event.begin();
195 it != m_filter_event.end(); ++it) {
196 const FilterEvent& fe = (*it);
197 if (
release == fe.bossver && run == fe.runid && event == fe.eventid) {
198 cout <<
"SKIP: " << fe.bossver <<
" "
200 << fe.eventid << std::endl;
201 return StatusCode::SUCCESS;
209 Hep3Vector cosmicMom;
211 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
212 if (!mcParticleCol) {
213 log << MSG::FATAL <<
"Could not find McParticle" << endreq;
214 return( StatusCode::FAILURE);
217 McParticleCol::iterator iter_mc = mcParticleCol->begin();
218 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
220 <<
" particleId = " << (*iter_mc)->particleProperty()
222 int pid = (*iter_mc)->particleProperty();
224 if(fabs(pid)!=13)
continue;
226 HepLorentzVector initialMomentum = (*iter_mc)->initialFourMomentum();
227 Hep3Vector startP(initialMomentum.px(), initialMomentum.py(), initialMomentum.pz());
228 Hep3Vector rotate(-initialMomentum.px(),initialMomentum.pz(),initialMomentum.py());
231 m_px_mc = initialMomentum.px();
232 m_py_mc = initialMomentum.py();
233 m_pz_mc = initialMomentum.pz();
235 m_theta_mc = rotate.theta();
236 m_phi_mc = rotate.phi();
238 m_theta_mc_pipe = startP.theta();
239 m_phi_mc_pipe = startP.phi();
305 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),
"/Event/Digi/MucDigiCol");
307 log << MSG::FATAL <<
"Could not find MUC digi" << endreq;
308 return( StatusCode::FAILURE);
311 MucDigiCol::iterator iter4 = mucDigiCol->begin();
313 for (;iter4 != mucDigiCol->end(); iter4++, digiId++) {
315 log << MSG::INFO <<
"MUC digis:: " << digiId << endreq;
316 if( digiId == 0)
return( StatusCode::SUCCESS );
326 if (!aMucRecHitContainer) {
329 aMucRecHitContainer->
Clear();
335 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
336 DataObject *mucRecHitCol;
337 eventSvc()->findObject(
"/Event/Recon/MucRecHitCol",mucRecHitCol);
338 if(mucRecHitCol != NULL) {
339 dataManSvc->clearSubTree(
"/Event/Recon/MucRecHitCol");
340 eventSvc()->unregisterObject(
"/Event/Recon/MucRecHitCol");
343 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon/MucRecHitCol", aMucRecHitContainer->
GetMucRecHitCol());
345 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
347 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
348 mucID = (*iterMuc)->identify();
356 aMucRecHitContainer->
AddHit(part, seg, gap, strip);
357 log << MSG::INFO <<
" digit" << mucDigiId <<
" : "
361 <<
" strip " << strip
365 DataObject *aReconEvent ;
366 eventSvc()->findObject(
"/Event/Recon",aReconEvent);
367 if(aReconEvent==NULL) {
370 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon",aReconEvent);
371 if(sc!=StatusCode::SUCCESS) {
372 log << MSG::FATAL <<
"Could not register ReconEvent" <<endreq;
373 return( StatusCode::FAILURE);
376 StatusCode fr = eventSvc()->findObject(
"/Event/Recon",aReconEvent);
377 if(fr!=StatusCode::SUCCESS) {
378 log << MSG::WARNING <<
"Could not find register ReconEvent, will create it" <<endreq;
379 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon",aReconEvent);
380 if(sc!=StatusCode::SUCCESS) {
381 log << MSG::FATAL <<
"Could not register ReconEvent" <<endreq;
382 return( StatusCode::FAILURE);
388 DataObject *mucTrackCol;
389 eventSvc()->findObject(
"/Event/Recon/RecMucTrackCol",mucTrackCol);
390 if(mucTrackCol != NULL) {
391 dataManSvc->clearSubTree(
"/Event/Recon/RecMucTrackCol");
392 eventSvc()->unregisterObject(
"/Event/Recon/RecMucTrackCol");
396 sc = eventSvc()->registerObject(
"/Event/Recon/RecMucTrackCol", aMucTrackCol);
397 aMucTrackCol->clear();
400 SmartDataPtr<RecMucTrackCol> findMucTrackCol(eventSvc(),
"/Event/Recon/RecMucTrackCol");
401 if (!findMucTrackCol) {
402 log << MSG::FATAL <<
"Could not find RecMucTrackCol" << endreq;
403 return( StatusCode::FAILURE);
405 aMucTrackCol->clear();
408 log << MSG::INFO <<
"MaxHitsRec : "<<m_maxHitsRec<< endreq;
409 if(digiId> m_maxHitsRec)
return StatusCode::SUCCESS;
416 else if(m_united == 1){
419 if (!aMucRecHitContainer) {
422 aMucRecHitContainer->
Clear();
424 SmartDataPtr<MucRecHitCol> aMucRecHitCol (eventSvc(),
"/Event/Recon/MucRecHitCol");
425 if(aMucRecHitCol == NULL) {
426 log << MSG::WARNING <<
"MucRecHitCol is NULL" << endreq;
431 SmartDataPtr<RecMucTrackCol> mucTrackCol (eventSvc(),
"/Event/Recon/RecMucTrackCol");
432 if(mucTrackCol == NULL) {
433 log << MSG::WARNING <<
"aMucTrackCol is NULL" << endreq;
436 log << MSG::INFO <<
"mucTrackCol size: "<<mucTrackCol->size()<<
" hitCol size: "<<aMucRecHitCol->size()<<endreq;
437 aMucTrackCol = mucTrackCol;
440 SmartDataPtr<RecExtTrackCol> aExtTrackCol(eventSvc(),
"/Event/Recon/RecExtTrackCol");
442 log << MSG::WARNING <<
"Can't find ExtTrackCol in TDS!" << endreq;
445 SmartDataPtr<RecMdcTrackCol> aMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
447 log << MSG::WARNING <<
"Can't find MdcTrackCol in TDS!" << endreq;
450 if( aExtTrackCol && aMdcTrackCol ) trackId = aMdcTrackCol->size();
451 muctrackId = aMucTrackCol->size();
456 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),
"/Event/Recon/RecEmcShowerCol");
458 log << MSG::WARNING <<
"Could not find RecEmcShowerCol" << endreq;
462 RecEmcShowerCol::iterator iShowerCol;
463 for(iShowerCol=aShowerCol->begin();
464 iShowerCol!=aShowerCol->end();
472 if(((*iShowerCol)->position()).phi()>0&&((*iShowerCol)->position()).phi()<3.1415926) hasEmcUp++;
477 m_emcUp = hasEmcUp; m_emcDown = hasEmcDown;
502 log << MSG::INFO <<
"Muc 2D 3D Road Container created" << endreq;
512 int count0, count1, count, iGap0, iGap1;
517 for (
int iOrient = 0; iOrient < 2; iOrient++) {
520 for (
int iLoop = 0; iLoop < nLoops; iLoop++) {
529 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
532 iGap0 = 0; iGap1 = 0;
533 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
534 mucID = (*iterMuc)->identify();
540 if ( (part == 1 && gap % 2 == 0) || (part != 1 && gap % 2 == 1) ) orient = 1;
542 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 0){
546 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 1 && gap != iGap0 ){
552 if(m_MsOutput) cout <<
"Find seed gap in ( "<<iPart<<
" "<<iSeg<<
" ) gap0: "<<iGap0<<
" gap1: "<<iGap1<<endl;
560 if(iGap1 == iGap0)
continue;
563 for (
int iHit0 = 0; iHit0 < count0; iHit0++) {
565 pHit0 = aMucRecHitContainer->
GetHit(iPart, iSeg, iGap0, iHit0);
567 log << MSG::FATAL <<
"MucRecRoadFinder-E10 " <<
" part " << iPart
568 <<
" seg " << iSeg <<
" gap " << iGap0 <<
" null pointer"
574 if(m_united == 1 && pHit0->
GetHitMode() != -1)
continue;
577 if(m_MsOutput) cout <<
"part " << iPart <<
" seg " << iSeg <<
" orient " << iOrient
578 <<
" gap0 " << iGap0 <<
" count0 " << count0
579 <<
" gap1 " << iGap1 <<
" count1 " << count1 << endl;
580 for (
int iHit1 = 0; iHit1 < count1; iHit1++) {
582 pHit1 = aMucRecHitContainer->
GetHit(iPart, iSeg, iGap1, iHit1);
584 log << MSG::ERROR <<
"MucRecRoadFinder-E10 " <<
" part " << iPart
585 <<
" seg " << iSeg <<
" gap " << iGap1 <<
" null pointer"
590 if(m_united == 1 && pHit1->GetHitMode() != -1)
continue;
596 log << MSG::FATAL <<
"MucRecRoadFinder-E20 " <<
"failed to create 2D road!" << endreq;
601 if (!pHit0->
GetGap()) log << MSG::ERROR <<
"pHit0->GetGap(), null pointer" << endreq;
610 pHit1->SetHitSeed(
true);
613 if(m_MsOutput) cout <<
"pHit0 attached, " << road2D->
GetTotalHits()
614 <<
", hitId= "<<pHit0->
Part()<<
" "<<pHit0->
Seg()<<
" "<<pHit0->
Gap()<<
" "<<pHit0->
Strip()<<endl;
617 if (pHit1->GetGap()->Orient() == iOrient) {
623 if(m_MsOutput) cout <<
"pHit1 attached, " << road2D->
GetTotalHits()
624 <<
", hitId= "<<pHit1->Part()<<
" "<<pHit1->Seg()<<
" "<<pHit1->Gap()<<
" "<<pHit1->Strip()<<endl;
626 if(m_MsOutput) cout <<
"Hit cout " << road2D->
GetTotalHits() <<
", slope " << road2D->
GetSlope() << endl;
633 for (
int i = 0; i <
length; i++) {
636 float dXmin = kInfinity;
648 for (
int iHit = 0; iHit < count; iHit++) {
649 pHit = aMucRecHitContainer->
GetHit(iPart, iSeg, iGap, iHit);
651 log << MSG::FATAL <<
"MucRecRoadFinder-E20 null cluster pointer pHit" << endreq;
657 if(m_united == 1 && pHit->
GetHitMode() != -1)
continue;
661 if(m_MsOutput) cout<<
"dX = "<<dX<<
" Win = "<<Win<<
", hit: "<<pHit->
Part()<<
" "<<pHit->
Seg()<<
" "<<pHit->
Gap()<<
" "<<pHit->
Strip()<<endl;
666 if(iGap == iGap0 || iGap == iGap1) {
675 if(m_onlyseedfit == 0)road2D->
AttachHit(pHit);
677 if(iGap == iGap0 || iGap == iGap1) road2D->
AttachHit(pHit);
694 bool lastGapOK =
false;
705 bool firedGapsOK =
false;
714 bool duplicateRoad =
false;
715 int maxSharedHits = 0, sharedHits = 0;
717 for (
int index = 0; index < (int)p2DRoad0C->size(); index++) {
718 sharedHits =(*p2DRoad0C)[index]->GetNSharedHits(road2D);
720 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
723 for (
int index = 0; index < (int)p2DRoad1C->size(); index++) {
724 sharedHits = (*p2DRoad1C)[index]->GetNSharedHits(road2D);
726 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
731 duplicateRoad =
true;
732 log<<MSG::INFO <<
" maxSharedHits " << maxSharedHits <<
" > " <<
kMinSharedHits2D << endreq;
741 if (lastGapOK && firedGapsOK && !duplicateRoad) {
743 log<<MSG::INFO <<
"Add a road0" << endreq;
744 p2DRoad0C->add(road2D);
747 log<<MSG::INFO <<
"Add a road1" << endreq;
748 p2DRoad1C->add(road2D);
754 vector<MucRecHit*> road2DHits = road2D->
GetHits();
755 for(
int i=0; i< road2DHits.size(); i++)
758 if(ihit->
Gap() == iGap0 || ihit->
Gap() == iGap1){
774 int print2DRoadInfo = 0;
775 if (print2DRoadInfo == 1) {
777 cout <<
"In 2DRoad container : " << endl
778 <<
" Num of 2DRoad0 = " << p2DRoad0C->size() << endl
781 for (
int iRoad = 0; iRoad < (int)p2DRoad0C->size(); iRoad++) {
784 cout <<
" " << iRoad <<
"th 2DRoad0 :" << endl
785 <<
" Part = " << road->
GetPart() << endl
786 <<
" Seg = " << road->
GetSeg() << endl
787 <<
" Orient = " << road->
GetOrient() << endl
788 <<
" LastGap = " << road->
GetLastGap() << endl
791 <<
" Slope = " << road->
GetSlope() << endl
797 cout <<
" Num of 2DRoad1 = " << p2DRoad1C->size() << endl
800 for (
int iRoad = 0; iRoad < (int)p2DRoad1C->size(); iRoad++) {
803 cout <<
" " << iRoad <<
"th 2DRoad1 :" << endl
804 <<
" Part = " << road->
GetPart() << endl
805 <<
" Seg = " << road->
GetSeg() << endl
806 <<
" Orient = " << road->
GetOrient() << endl
807 <<
" LastGap = " << road->
GetLastGap() << endl
810 <<
" Slope = " << road->
GetSlope() << endl
819 for (
int iRoad0 = 0; iRoad0 < (int)p2DRoad0C->size(); iRoad0++) {
821 for (
int iRoad1 = 0; iRoad1 < (int)p2DRoad1C->size(); iRoad1++){
825 if ( !(road0 &&road1) ) {
826 cout <<
"Null pointer to road0 or road1: "
827 <<
"road0 = " << road0
828 <<
"road1 = " << road1
852 bool lastGapDeltaOK =
false;
854 lastGapDeltaOK =
true;
860 bool totalHitsDeltaOK =
false;
862 totalHitsDeltaOK =
true;
868 bool chiSquareCutOK =
false;
873 chiSquareCutOK =
true;
876 cout <<
"xChiSquare = " << xChiSquare
877 <<
"yChiSquare = " << yChiSquare
881 bool minLastGapOK =
false;
886 log<<MSG::INFO <<
" minLastGap = " << road3D->
GetLastGap() << endreq;
889 bool duplicateRoad =
false;
890 int maxSharedHits = 0, sharedHits = 0;
891 for (
int i = 0; i < (int)p3DRoadC->size(); i++){
892 sharedHits =(*p3DRoadC)[i]->GetNSharedHits(road3D);
893 if ( maxSharedHits < sharedHits) maxSharedHits = sharedHits;
899 duplicateRoad =
true;
900 log<<MSG::INFO <<
" MaxShareHits = " << maxSharedHits << endreq;
903 if ( lastGapDeltaOK &&
908 float vx, vy, x0, y0;
909 float slope1 = 100, slope0 = 100;
926 log<<MSG::INFO <<
"Add a 3D Road ... " << endreq;
928 float startx = 0.0, starty = 0.0, startz = 0.0;
929 float sigmax = 0.0, sigmay = 0.0, sigmaz = 0.0;
930 road3D->
ProjectWithSigma(0, startx, starty, startz, sigmax, sigmay, sigmaz);
936 float sign = vy/fabs(vy);
937 float signx = vx/fabs(vx);
946 else if(road3D->
GetSeg()<2){
962 else if(road3D->
GetPart() == 0){
969 else if(road3D->
GetPart() == 2){
982 Hep3Vector mom(vx, vy, vz);
989 startx /= 10; starty /= 10; startz /= 10;
990 startx -= vx/mom.mag(); starty -= vy/mom.mag(); startz -= vz/mom.mag();
996 aTrack->
SetMucPos(startx, starty, startz);
1005 aTrack->
setId(muctrackId);
1010 aMucTrackCol->add(aTrack);
1012 p3DRoadC->add(road3D);
1016 vector<MucRecHit*> attachedHits = aTrack->
GetHits();
1018 vector<float> distanceHits = aTrack->
getDistHits();
1020 for(
int i=0; i< expectedHits.size(); i++)
1026 vector<int> multiHit;
1027 for(
int i=0; i< attachedHits.size(); i++)
1033 for(
int k=0; k < attachedHits.size(); k++){
1038 multiHit.push_back(hitnum);
1043 for(
int i=0; i< expectedHits.size(); i++)
1051 for(
int j=0; j< attachedHits.size(); j++){
1056 if((jhit->
Part()==ihit->
Part())&&(jhit->
Seg()==ihit->
Seg())&&(jhit->
Gap()==ihit->
Gap())&&attachedHits.size()==distanceHits.size())
1063 m_part = ihit->
Part(); m_seg = ihit->
Seg(); m_gap = ihit->
Gap();
1064 m_strip = jhit->
Strip();
1066 m_dist = distanceHits[j];
1069 m_angle_cosmic = -999;
1070 m_angle_updown = -999;
1077 m_multihit = multiHit[j];
1078 m_run = eventHeader->runNumber();
1079 m_event = eventHeader->eventNumber();
1092 m_part = ihit->
Part(); m_seg = ihit->
Seg(); m_gap = ihit->
Gap();
1093 m_strip = ihit->
Strip();
1096 m_angle_updown = -999;
1097 m_angle_cosmic = -999;
1102 m_run = eventHeader->runNumber();
1103 m_event = eventHeader->eventNumber();
1160 for(
int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
1161 aaTrack = (*aMucTrackCol)[iTrack];
1166 double px,py,pz,p,theta,phi;
1175 m_angle_updown = -999;
1177 if(m_angle_cosmic>1.57) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
1178 m_run = eventHeader->runNumber();
1179 m_event = eventHeader->eventNumber();
1181 Hep3Vector rotate(-px,pz,py);
1182 theta = rotate.theta();
1185 m_px = px; m_py = py; m_pz = pz;
1186 m_theta = theta; m_phi = phi;
1193 Hep3Vector mucPos = aaTrack->
getMucPos();
1194 double posx, posy, posz;
1195 posx = mucPos.x(); posy = mucPos.y(); posz = mucPos.z();
1197 m_projx = -999; m_projz = -999;
1199 m_projx = posx - px/py*posy;
1200 m_projz = posz - pz/py*posy;
1207 m_mucUp = hasMucUp; m_mucDown = hasMucDown;
1212 if(aMucTrackCol->size()>=2 && forCosmic == 1){
1213 for(
int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
1214 log << MSG::DEBUG <<
"iTrack " << iTrack <<
" / " <<(int)aMucTrackCol->size()<<endreq;
1215 aaTrack = (*aMucTrackCol)[iTrack];
1216 if(aaTrack->
trackId()>=0)
continue;
1219 for(
int jTrack = iTrack+1; jTrack < (int)aMucTrackCol->size(); jTrack++){
1220 bbTrack = (*aMucTrackCol)[jTrack];
1226 if(fabs(mom_a.angle(mom_b) - 3.1415926)<0.2)
1237 m_angle_cosmic = cosmicMom.angle(mom_a);
1238 if(cosmicMom.angle(mom_a)>1.57) m_angle_cosmic = 3.14159265 - cosmicMom.angle(mom_a);
1240 m_angle_updown = fabs(mom_a.angle(mom_b) - 3.1415926);
1241 m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
1242 m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
1243 m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
1254 if( p3DRoadC->size() !=0 ) {
1255 log<<MSG::INFO <<
"In 3DRoad container : "
1256 <<
" Num of 3DRoad = " << p3DRoadC->size() <<endreq;
1258 int print2DRoadInfo = 0;
1259 if (print2DRoadInfo == 1) {
1260 for (
int iRoad = 0; iRoad < (int)p3DRoadC->size(); iRoad++) {
1262 cout << endl <<
" " << iRoad <<
"th 3DRoad :" << endl
1263 <<
" Part = " << road->
GetPart() << endl
1264 <<
" Seg = " << road->
GetSeg() << endl
1272 <<
" SlopeZX = " << road->
GetSlopeZX() << endl
1274 <<
" SlopeZY = " << road->
GetSlopeZY() << endl
1276 <<
" Hits Info : " << endl;
1285 for(
int i = 0 ; i < p3DRoadC->size(); i++)
1286 delete (*p3DRoadC)[i];
1287 for(
int i = 0 ; i < p2DRoad0C->size(); i++)
1288 delete (*p2DRoad0C)[i];
1289 for(
int i = 0 ; i < p2DRoad1C->size(); i++)
1290 delete (*p2DRoad1C)[i];
1298 return StatusCode::SUCCESS;