00147 {
00148
00149 MsgStream log(msgSvc(), name());
00150 log << MSG::INFO << "in execute()" << endreq;
00151
00152
00153 int event, run;
00154
00155 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00156 if (!eventHeader) {
00157 log << MSG::FATAL << "Could not find Event Header" << endreq;
00158 return( StatusCode::FAILURE);
00159 }
00160 log << MSG::INFO << "Run: " << eventHeader->runNumber() << " Event: " << eventHeader->eventNumber() << endreq;
00161
00162 int digiId;
00163
00164
00165
00166 Hep3Vector cosmicMom;
00167 if(m_mccosmic==1){
00168 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),"/Event/MC/McParticleCol");
00169 if (!mcParticleCol) {
00170 log << MSG::FATAL << "Could not find McParticle" << endreq;
00171 return( StatusCode::FAILURE);
00172 }
00173
00174 McParticleCol::iterator iter_mc = mcParticleCol->begin();
00175 for (;iter_mc != mcParticleCol->end(); iter_mc++, digiId++) {
00176 log << MSG::DEBUG
00177 << " particleId = " << (*iter_mc)->particleProperty()
00178 << endreq;
00179 int pid = (*iter_mc)->particleProperty();
00180
00181 if(fabs(pid)!=13) continue;
00182
00183 HepLorentzVector initialMomentum = (*iter_mc)->initialFourMomentum();
00184 Hep3Vector startP(initialMomentum.px(), initialMomentum.py(), initialMomentum.pz());
00185 Hep3Vector rotate(-initialMomentum.px(),initialMomentum.pz(),initialMomentum.py());
00186
00187 if(m_NtOutput>=1){
00188 m_px_mc = initialMomentum.px();
00189 m_py_mc = initialMomentum.py();
00190 m_pz_mc = initialMomentum.pz();
00191
00192 m_theta_mc = rotate.theta();
00193 m_phi_mc = rotate.phi();
00194
00195 m_theta_mc_pipe = startP.theta();
00196 m_phi_mc_pipe = startP.phi();
00197
00198
00199 }
00200
00201
00202 cosmicMom = startP;
00203
00204 }
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),"/Event/Digi/MucDigiCol");
00263 if (!mucDigiCol) {
00264 log << MSG::FATAL << "Could not find MUC digi" << endreq;
00265 return( StatusCode::FAILURE);
00266 }
00267
00268 MucDigiCol::iterator iter4 = mucDigiCol->begin();
00269 digiId = 0;
00270 for (;iter4 != mucDigiCol->end(); iter4++, digiId++) {
00271 }
00272 log << MSG::INFO << "MUC digis:: " << digiId << endreq;
00273 if( digiId == 0) return( StatusCode::SUCCESS );
00274
00275
00276 RecMucTrackCol *aMucTrackCol;
00277 int trackId = -1;
00278 int muctrackId = -1;
00279
00280 if(m_united != 1)
00281 {
00282 Identifier mucID;
00283 if (!aMucRecHitContainer) {
00284 aMucRecHitContainer = new MucRecHitContainer();
00285 }
00286 aMucRecHitContainer->Clear();
00287
00288 MucRecHitCol *aMucRecHitCol = new MucRecHitCol();
00289 aMucRecHitContainer->SetMucRecHitCol(aMucRecHitCol);
00290
00291 IDataManagerSvc *dataManSvc = dynamic_cast<IDataManagerSvc*> (eventSvc());
00292 DataObject *mucRecHitCol;
00293 eventSvc()->findObject("/Event/Recon/MucRecHitCol",mucRecHitCol);
00294 if(mucRecHitCol != NULL) {
00295 dataManSvc->clearSubTree("/Event/Recon/MucRecHitCol");
00296 eventSvc()->unregisterObject("/Event/Recon/MucRecHitCol");
00297 }
00298
00299 StatusCode sc = eventSvc()->registerObject("/Event/Recon/MucRecHitCol", aMucRecHitContainer->GetMucRecHitCol());
00300
00301 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
00302 int mucDigiId = 0;
00303 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
00304 mucID = (*iterMuc)->identify();
00305 int part = MucID::barrel_ec(mucID);
00306 int seg = MucID::segment(mucID);
00307 int gap = MucID::layer(mucID);
00308 int strip = MucID::channel(mucID);
00309
00310
00311
00312 aMucRecHitContainer->AddHit(part, seg, gap, strip);
00313 log << MSG::INFO << " digit" << mucDigiId << " : "
00314 << " part " << part
00315 << " seg " << seg
00316 << " gap " << gap
00317 << " strip " << strip
00318 << endreq;
00319 }
00320
00321 DataObject *aReconEvent ;
00322 eventSvc()->findObject("/Event/Recon",aReconEvent);
00323 if(aReconEvent==NULL) {
00324
00325 aReconEvent = new ReconEvent();
00326 StatusCode sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
00327 if(sc!=StatusCode::SUCCESS) {
00328 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
00329 return( StatusCode::FAILURE);
00330 }
00331 }
00332 StatusCode fr = eventSvc()->findObject("/Event/Recon",aReconEvent);
00333 if(fr!=StatusCode::SUCCESS) {
00334 log << MSG::WARNING << "Could not find register ReconEvent, will create it" <<endreq;
00335 StatusCode sc = eventSvc()->registerObject("/Event/Recon",aReconEvent);
00336 if(sc!=StatusCode::SUCCESS) {
00337 log << MSG::FATAL << "Could not register ReconEvent" <<endreq;
00338 return( StatusCode::FAILURE);
00339 }
00340 }
00341
00342
00343
00344 DataObject *mucTrackCol;
00345 eventSvc()->findObject("/Event/Recon/RecMucTrackCol",mucTrackCol);
00346 if(mucTrackCol != NULL) {
00347 dataManSvc->clearSubTree("/Event/Recon/RecMucTrackCol");
00348 eventSvc()->unregisterObject("/Event/Recon/RecMucTrackCol");
00349 }
00350
00351 aMucTrackCol = new RecMucTrackCol();
00352 sc = eventSvc()->registerObject("/Event/Recon/RecMucTrackCol", aMucTrackCol);
00353 aMucTrackCol->clear();
00354
00355
00356 SmartDataPtr<RecMucTrackCol> findMucTrackCol(eventSvc(),"/Event/Recon/RecMucTrackCol");
00357 if (!findMucTrackCol) {
00358 log << MSG::FATAL << "Could not find RecMucTrackCol" << endreq;
00359 return( StatusCode::FAILURE);
00360 }
00361 aMucTrackCol->clear();
00362
00363
00364 log << MSG::INFO <<"MaxHitsRec : "<<m_maxHitsRec<< endreq;
00365 if(digiId> m_maxHitsRec) return StatusCode::SUCCESS;
00366
00367
00368
00369 trackId = 0;
00370 muctrackId = 0;
00371 }
00372 else if(m_united == 1){
00373
00374 Identifier mucID;
00375 if (!aMucRecHitContainer) {
00376 aMucRecHitContainer = new MucRecHitContainer();
00377 }
00378 aMucRecHitContainer->Clear();
00379
00380 SmartDataPtr<MucRecHitCol> aMucRecHitCol (eventSvc(),"/Event/Recon/MucRecHitCol");
00381 if(aMucRecHitCol == NULL) {
00382 log << MSG::WARNING << "MucRecHitCol is NULL" << endreq;
00383 }
00384
00385 aMucRecHitContainer->SetMucRecHitCol(aMucRecHitCol);
00386
00387 SmartDataPtr<RecMucTrackCol> mucTrackCol (eventSvc(),"/Event/Recon/RecMucTrackCol");
00388 if(mucTrackCol == NULL) {
00389 log << MSG::WARNING << "aMucTrackCol is NULL" << endreq;
00390 }
00391
00392 log << MSG::INFO <<"mucTrackCol size: "<<mucTrackCol->size()<<" hitCol size: "<<aMucRecHitCol->size()<<endreq;
00393 aMucTrackCol = mucTrackCol;
00394
00395
00396 SmartDataPtr<RecExtTrackCol> aExtTrackCol(eventSvc(),"/Event/Recon/RecExtTrackCol");
00397 if (!aExtTrackCol) {
00398 log << MSG::WARNING << "Can't find ExtTrackCol in TDS!" << endreq;
00399 }
00400
00401 SmartDataPtr<RecMdcTrackCol> aMdcTrackCol(eventSvc(),"/Event/Recon/RecMdcTrackCol");
00402 if (!aMdcTrackCol) {
00403 log << MSG::WARNING << "Can't find MdcTrackCol in TDS!" << endreq;
00404 }
00405
00406 if( aExtTrackCol && aMdcTrackCol ) trackId = aMdcTrackCol->size();
00407 muctrackId = aMucTrackCol->size();
00408 }
00409
00410 int hasEmcUp = 0;
00411 int hasEmcDown = 0;
00412 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
00413 if (!aShowerCol) {
00414 log << MSG::WARNING << "Could not find RecEmcShowerCol" << endreq;
00415
00416 }
00417 else{
00418 RecEmcShowerCol::iterator iShowerCol;
00419 for(iShowerCol=aShowerCol->begin();
00420 iShowerCol!=aShowerCol->end();
00421 iShowerCol++){
00422
00423
00424
00425
00426
00427
00428 if(((*iShowerCol)->position()).phi()>0&&((*iShowerCol)->position()).phi()<3.1415926) hasEmcUp++;
00429 else hasEmcDown++;
00430 }
00431 }
00432 if(m_NtOutput >= 1){
00433 m_emcUp = hasEmcUp; m_emcDown = hasEmcDown;
00434 }
00435
00436
00437 m_NEvent++;
00438 MucRec3DRoadContainer *p3DRoadC = new MucRec3DRoadContainer();
00439
00440 if (!p3DRoadC) {
00441 p3DRoadC = new MucRec3DRoadContainer();
00442 }
00443 p3DRoadC->clear();
00444
00445 MucRec2DRoadContainer *p2DRoad0C = new MucRec2DRoadContainer();
00446
00447 if (!p2DRoad0C) {
00448 p2DRoad0C = new MucRec2DRoadContainer();
00449 }
00450 p2DRoad0C->clear();
00451
00452 MucRec2DRoadContainer *p2DRoad1C = new MucRec2DRoadContainer();
00453
00454 if (!p2DRoad1C) {
00455 p2DRoad1C = new MucRec2DRoadContainer();
00456 }
00457 p2DRoad1C->clear();
00458 log << MSG::INFO << "Muc 2D 3D Road Container created" << endreq;
00459
00460
00461
00462
00463
00464
00465
00466
00467 MucRecHit *pHit0 = 0, *pHit1 = 0;
00468 int count0, count1, count, iGap0, iGap1;
00469 int orient;
00470
00471 for (int iPart = 0; iPart < (int)MucID::getPartNum(); iPart++) {
00472 for (int iSeg = 0; iSeg < (int)MucID::getSegNum(iPart); iSeg++) {
00473 for (int iOrient = 0; iOrient < 2; iOrient++) {
00474 int nLoops = 1;
00475 if(m_seedtype == 1) nLoops = kNSeedLoops;
00476 for (int iLoop = 0; iLoop < nLoops; iLoop++) {
00477
00478 int length = kSearchLength[iLoop][iPart][iOrient];
00479 if(m_seedtype == 1){
00480 iGap0 = kSearchOrder[iLoop][iPart][iOrient][0];
00481 iGap1 = kSearchOrder[iLoop][iPart][iOrient][1];
00482 }
00483 else {
00484 int setgap0 = 0;
00485 MucDigiCol::iterator iterMuc = mucDigiCol->begin();
00486 int mucDigiId = 0;
00487 Identifier mucID;
00488 iGap0 = 0; iGap1 = 0;
00489 for (;iterMuc != mucDigiCol->end(); iterMuc++, mucDigiId++) {
00490 mucID = (*iterMuc)->identify();
00491 int part = MucID::barrel_ec(mucID);
00492 int seg = MucID::segment(mucID);
00493 int gap = MucID::layer(mucID);
00494 int strip = MucID::channel(mucID);
00495 int orient = 0;
00496 if ( (part == 1 && gap % 2 == 0) || (part != 1 && gap % 2 == 1) ) orient = 1;
00497
00498 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 0){
00499 iGap0 = gap;
00500 setgap0 = 1;
00501 }
00502 if(part == iPart && seg == iSeg && orient == iOrient && setgap0 == 1 && gap != iGap0 ){
00503 iGap1 = gap;
00504 }
00505 }
00506 }
00507
00508 if(m_MsOutput) cout <<"Find seed gap in ( "<<iPart<<" "<<iSeg<<" ) gap0: "<<iGap0<<" gap1: "<<iGap1<<endl;
00509
00510
00511 if(iGap0 > iGap1){
00512 int tempGap = iGap0;
00513 iGap0 = iGap1;
00514 iGap1 = tempGap;
00515 }
00516 if(iGap1 == iGap0) continue;
00517
00518 count0 = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap0);
00519 for (int iHit0 = 0; iHit0 < count0; iHit0++) {
00520
00521 pHit0 = aMucRecHitContainer->GetHit(iPart, iSeg, iGap0, iHit0);
00522 if (!pHit0) {
00523 log << MSG::FATAL << "MucRecRoadFinder-E10 " << " part " << iPart
00524 << " seg " << iSeg << " gap " << iGap0 << " null pointer"
00525 << endl;
00526 }
00527 else {
00528
00529
00530 if(m_united == 1 && pHit0->GetHitMode() != -1) continue;
00531
00532 count1 = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap1);
00533 if(m_MsOutput) cout << "part " << iPart << " seg " << iSeg << " orient " << iOrient
00534 << " gap0 " << iGap0 << " count0 " << count0
00535 << " gap1 " << iGap1 << " count1 " << count1 << endl;
00536 for (int iHit1 = 0; iHit1 < count1; iHit1++) {
00537
00538 pHit1 = aMucRecHitContainer->GetHit(iPart, iSeg, iGap1, iHit1);
00539 if (!pHit1) {
00540 log << MSG::ERROR << "MucRecRoadFinder-E10 " << " part " << iPart
00541 << " seg " << iSeg << " gap " << iGap1 << " null pointer"
00542 << endl;
00543 } else {
00544
00545
00546 if(m_united == 1 && pHit1->GetHitMode() != -1) continue;
00547
00548
00549
00550 MucRec2DRoad *road2D = new MucRec2DRoad(iPart, iSeg, iOrient, 0.0, 0.0, 3000.0);
00551 if (!road2D) {
00552 log << MSG::FATAL << "MucRecRoadFinder-E20 " << "failed to create 2D road!" << endreq;
00553 continue;
00554 }
00555 road2D->SetMaxNSkippedGaps(kMaxSkippedGaps);
00556
00557 if (!pHit0->GetGap()) log << MSG::ERROR << "pHit0->GetGap(), null pointer" << endreq;
00558 if (pHit0->GetGap()->Orient() == iOrient) {
00559
00560
00561
00562
00563
00564 bool isseed = true;
00565 pHit0->SetHitSeed(true);
00566 pHit1->SetHitSeed(true);
00567
00568 road2D->AttachHit(pHit0);
00569 if(m_MsOutput) cout << "pHit0 attached, " << road2D->GetTotalHits()
00570 << ", hitId= "<<pHit0->Part()<<" "<<pHit0->Seg()<<" "<<pHit0->Gap()<<" "<<pHit0->Strip()<<endl;
00571 }
00572
00573 if (pHit1->GetGap()->Orient() == iOrient) {
00574
00575
00576
00577
00578 road2D->AttachHit(pHit1);
00579 if(m_MsOutput) cout << "pHit1 attached, " << road2D->GetTotalHits()
00580 << ", hitId= "<<pHit1->Part()<<" "<<pHit1->Seg()<<" "<<pHit1->Gap()<<" "<<pHit1->Strip()<<endl;
00581 }
00582 if(m_MsOutput) cout << "Hit cout " << road2D->GetTotalHits() << ", slope " << road2D->GetSlope() << endl;
00583
00584
00585
00586
00587
00588
00589 for (int i = 0; i < length; i++) {
00590 int iGap = kSearchOrder[iLoop][iPart][iOrient][i];
00591
00592 float dXmin = kInfinity;
00593 MucRecHit *pHit = 0;
00594
00595 float Win = kWindowSize[iPart][iGap];
00596
00597
00598
00599
00600
00601
00602
00603 count = aMucRecHitContainer->GetGapHitCount(iPart, iSeg, iGap);
00604 for (int iHit = 0; iHit < count; iHit++) {
00605 pHit = aMucRecHitContainer->GetHit(iPart, iSeg, iGap, iHit);
00606 if (!pHit) {
00607 log << MSG::FATAL << "MucRecRoadFinder-E20 null cluster pointer pHit" << endreq;
00608 continue;
00609 }
00610 else {
00611
00612
00613 if(m_united == 1 && pHit->GetHitMode() != -1) continue;
00614
00615
00616 float dX = road2D->GetHitDistance(pHit);
00617 if(m_MsOutput) cout<<"dX = "<<dX<<" Win = "<<Win<<", hit: "<<pHit->Part()<<" "<<pHit->Seg()<<" "<<pHit->Gap()<<" "<<pHit->Strip()<<endl;
00618
00619 if (dX < Win) {
00620
00621
00622 if(iGap == iGap0 || iGap == iGap1) {
00623 if(pHit->GetHitMode() == -1){
00624 pHit->SetHitMode(3);
00625 }
00626 else if(pHit->GetHitMode() == 3){
00627 pHit->SetHitMode(4);
00628 }
00629 }
00630
00631 if(m_onlyseedfit == 0)road2D->AttachHit(pHit);
00632 else {
00633 if(iGap == iGap0 || iGap == iGap1) road2D->AttachHit(pHit);
00634 else road2D->AttachHitNoFit(pHit);
00635 }
00636 }
00637 }
00638 }
00639
00640
00641 }
00642
00643
00644
00645
00646
00647
00648
00649
00650 bool lastGapOK = false;
00651 if ( road2D->GetLastGap() >= kMinLastGap2D ) {
00652 lastGapOK = true;
00653 }
00654 else {
00655 log<<MSG::INFO << " 2D lastGap " << road2D->GetLastGap() << " < " << kMinLastGap2D << endreq;
00656 }
00657
00658
00659
00660
00661 bool firedGapsOK = false;
00662 if (road2D->GetNGapsWithHits() >= kMinFiredGaps) {
00663 firedGapsOK = true;
00664 }
00665 else {
00666 log<<MSG::INFO << " 2D firedGaps " << road2D->GetNGapsWithHits() << " < " << kMinFiredGaps << endreq;
00667 }
00668
00669
00670 bool duplicateRoad = false;
00671 int maxSharedHits = 0, sharedHits = 0;
00672 if (iOrient == 0) {
00673 for (int index = 0; index < (int)p2DRoad0C->size(); index++) {
00674 sharedHits =(*p2DRoad0C)[index]->GetNSharedHits(road2D);
00675 }
00676 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
00677 }
00678 else {
00679 for (int index = 0; index < (int)p2DRoad1C->size(); index++) {
00680 sharedHits = (*p2DRoad1C)[index]->GetNSharedHits(road2D);
00681 }
00682 if (maxSharedHits < sharedHits) maxSharedHits = sharedHits;
00683 }
00684
00685 if(road2D->GetTotalHits() == maxSharedHits
00686 || maxSharedHits >= kMinSharedHits2D ) {
00687 duplicateRoad = true;
00688 log<<MSG::INFO << " maxSharedHits " << maxSharedHits << " > " << kMinSharedHits2D << endreq;
00689 }
00690
00691
00692
00693
00694
00695
00696
00697 if (lastGapOK && firedGapsOK && !duplicateRoad) {
00698 if (iOrient == 0) {
00699 log<<MSG::INFO << "Add a road0" << endreq;
00700 p2DRoad0C->add(road2D);
00701 }
00702 else {
00703 log<<MSG::INFO << "Add a road1" << endreq;
00704 p2DRoad1C->add(road2D);
00705 }
00706 }
00707 else {
00708
00709
00710 vector<MucRecHit*> road2DHits = road2D->GetHits();
00711 for(int i=0; i< road2DHits.size(); i++)
00712 {
00713 MucRecHit *ihit = road2DHits[i];
00714 if(ihit->Gap() == iGap0 || ihit->Gap() == iGap1){
00715 if(ihit->GetHitMode() == 3) ihit->SetHitMode(-1);
00716 if(ihit->GetHitMode() == 4) ihit->SetHitMode(3);
00717 }
00718 }
00719 delete road2D;
00720 }
00721 }
00722 }
00723 }
00724 }
00725 }
00726 }
00727 }
00728 }
00729
00730 int print2DRoadInfo = 0;
00731 if (print2DRoadInfo == 1) {
00732
00733 cout << "In 2DRoad container : " << endl
00734 << " Num of 2DRoad0 = " << p2DRoad0C->size() << endl
00735 << endl;
00736
00737 for (int iRoad = 0; iRoad < (int)p2DRoad0C->size(); iRoad++) {
00738
00739 MucRec2DRoad *road = (*p2DRoad0C)[iRoad];
00740 cout << " " << iRoad << "th 2DRoad0 :" << endl
00741 << " Part = " << road->GetPart() << endl
00742 << " Seg = " << road->GetSeg() << endl
00743 << " Orient = " << road->GetOrient() << endl
00744 << " LastGap = " << road->GetLastGap() << endl
00745 << " TotalHits = " << road->GetTotalHits() << endl
00746 << " DOF = " << road->GetDegreesOfFreedom() << endl
00747 << " Slope = " << road->GetSlope() << endl
00748 << " Intercept = " << road->GetIntercept() << endl
00749 << endl;
00750
00751 }
00752
00753 cout << " Num of 2DRoad1 = " << p2DRoad1C->size() << endl
00754 << endl;
00755
00756 for ( int iRoad = 0; iRoad < (int)p2DRoad1C->size(); iRoad++) {
00757
00758 MucRec2DRoad *road = (*p2DRoad1C)[iRoad];
00759 cout << " " << iRoad << "th 2DRoad1 :" << endl
00760 << " Part = " << road->GetPart() << endl
00761 << " Seg = " << road->GetSeg() << endl
00762 << " Orient = " << road->GetOrient() << endl
00763 << " LastGap = " << road->GetLastGap() << endl
00764 << " TotalHits = " << road->GetTotalHits() << endl
00765 << " DOF = " << road->GetDegreesOfFreedom() << endl
00766 << " Slope = " << road->GetSlope() << endl
00767 << " Intercept = " << road->GetIntercept() << endl
00768 << endl;
00769
00770 }
00771 }
00772
00773
00774
00775 for ( int iRoad0 = 0; iRoad0 < (int)p2DRoad0C->size(); iRoad0++) {
00776 MucRec2DRoad *road0 = (*p2DRoad0C)[iRoad0];
00777 for ( int iRoad1 = 0; iRoad1 < (int)p2DRoad1C->size(); iRoad1++){
00778 MucRec2DRoad *road1 = (*p2DRoad1C)[iRoad1];
00779
00780
00781 if ( !(road0 &&road1) ) {
00782 cout << "Null pointer to road0 or road1: "
00783 << "road0 = " << road0
00784 << "road1 = " << road1
00785 << endl;
00786 continue;
00787 }
00788
00789
00790 if ( (road0->GetPart() != road1->GetPart())
00791 || (road0->GetSeg() != road1->GetSeg()) ) {
00792 continue;
00793 }
00794
00795 MucRec3DRoad *road3D = new MucRec3DRoad(road0, road1);
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808 bool lastGapDeltaOK = false;
00809 if ( road3D->GetLastGapDelta() <= kMaxDeltaLastGap ) {
00810 lastGapDeltaOK = true;
00811 }
00812 else {
00813 cout << "LastGapDelta = " << road3D->GetLastGapDelta() << endl;
00814 }
00815
00816 bool totalHitsDeltaOK = false;
00817 if ( road3D->GetTotalHitsDelta() <= kMaxDeltaTotalHits ) {
00818 totalHitsDeltaOK = true;
00819 }
00820 else {
00821
00822 }
00823
00824 bool chiSquareCutOK = false;
00825 float xChiSquare = road0->GetReducedChiSquare();
00826 float yChiSquare = road1->GetReducedChiSquare();
00827 if ( xChiSquare <= kMaxXChisq
00828 && yChiSquare <= kMaxYChisq ) {
00829 chiSquareCutOK = true;
00830 }
00831 else {
00832 cout << "xChiSquare = " << xChiSquare
00833 << "yChiSquare = " << yChiSquare
00834 << endl;
00835 }
00836
00837 bool minLastGapOK = false;
00838 if ( road3D->GetLastGap() >= kMinLastGap3D ) {
00839 minLastGapOK = true;
00840 }
00841 else {
00842 log<<MSG::INFO << " minLastGap = " << road3D->GetLastGap() << endreq;
00843 }
00844
00845 bool duplicateRoad = false;
00846 int maxSharedHits = 0, sharedHits = 0;
00847 for ( int i = 0; i < (int)p3DRoadC->size(); i++){
00848 sharedHits =(*p3DRoadC)[i]->GetNSharedHits(road3D);
00849 if ( maxSharedHits < sharedHits) maxSharedHits = sharedHits;
00850
00851
00852 }
00853 if(road3D->GetTotalHits() == maxSharedHits
00854 || maxSharedHits >= kMinSharedHits2D ) {
00855 duplicateRoad = true;
00856 log<<MSG::INFO << " MaxShareHits = " << maxSharedHits << endreq;
00857 }
00858
00859 if ( lastGapDeltaOK &&
00860 totalHitsDeltaOK &&
00861 chiSquareCutOK &&
00862 minLastGapOK &&
00863 !duplicateRoad ) {
00864 float vx, vy, x0, y0;
00865 float slope1 = 100, slope0 = 100;
00866 if(fabs(road1->GetSlope())<100) slope1 = road1->GetSlope();
00867 if(fabs(road0->GetSlope())<100) slope0 = road0->GetSlope();
00868
00869 if ( road3D->GetPart() == 1 ){
00870 road3D->TransformPhiRToXY( slope1, slope0,
00871 road1->GetIntercept(), road0->GetIntercept(),
00872 vx, vy, x0, y0);
00873 }
00874 else {
00875 vx = slope1;
00876 x0 = road1->GetIntercept();
00877 vy = slope0;
00878 y0 = road0->GetIntercept();
00879 }
00880 road3D->SetSimpleFitParams(vx, x0, vy, y0);
00881
00882 log<<MSG::INFO << "Add a 3D Road ... " << endreq;
00883
00884 float startx = 0.0, starty = 0.0, startz = 0.0;
00885 float sigmax = 0.0, sigmay = 0.0, sigmaz = 0.0;
00886 road3D->ProjectWithSigma(0, startx, starty, startz, sigmax, sigmay, sigmaz);
00887
00888
00889
00890
00891 float vz = 1;
00892 float sign = vy/fabs(vy);
00893 float signx = vx/fabs(vx);
00894
00895 if(road3D->GetPart() == 1){
00896 if(road3D->GetSeg() > 4){
00897
00898 vx *= -sign;
00899 vy *= -sign;
00900 vz *= -sign;
00901 }
00902 else if(road3D->GetSeg()<2){
00903 vx *= signx;
00904 vy *= signx;
00905 vz *= signx;
00906 }
00907 else if(road3D->GetSeg()>=3 && road3D->GetSeg()<=4){
00908 vx *= -signx;
00909 vy *= -signx;
00910 vz *= -signx;
00911 }
00912 else{
00913 vx *= sign;
00914 vy *= sign;
00915 vz *= sign;
00916 }
00917 }
00918 else if(road3D->GetPart() == 0){
00919
00920
00921
00922
00923
00924 }
00925 else if(road3D->GetPart() == 2){
00926
00927
00928 vx *= -1;
00929 vy *= -1;
00930 vz *= -1;
00931
00932
00933
00934
00935 }
00936
00937
00938 Hep3Vector mom(vx, vy, vz);
00939
00941
00942
00943
00944
00945 startx /= 10; starty /= 10; startz /= 10;
00946 startx -= vx/mom.mag(); starty -= vy/mom.mag(); startz -= vz/mom.mag();
00947
00948
00949 RecMucTrack *aTrack = new RecMucTrack();
00950 aTrack->SetExtMucPos(startx, starty, startz);
00951 aTrack->SetExtMucMomentum(vx, vy, vz);
00952 aTrack->SetMucPos(startx, starty, startz);
00953 aTrack->SetMucMomentum(vx, vy, vz);
00954 aTrack->SetCurrentPos( startx, starty, startz);
00955 aTrack->SetCurrentDir( vx, vy, vz);
00956 aTrack->SetRecMode(3);
00957
00958
00959
00960 aTrack->setTrackId(trackId);
00961 aTrack->setId(muctrackId);
00962 trackId++;
00963 muctrackId++;
00964
00965
00966 aMucTrackCol->add(aTrack);
00967 TrackFinding(aTrack);
00968 p3DRoadC->add(road3D);
00969
00971
00972 vector<MucRecHit*> attachedHits = aTrack->GetHits();
00973 vector<MucRecHit*> expectedHits = aTrack->GetExpectedHits();
00974 vector<float> distanceHits = aTrack->getDistHits();
00975
00976 for(int i=0; i< expectedHits.size(); i++)
00977 {
00978 MucRecHit *ihit = expectedHits[i];
00979
00980 }
00981
00982 vector<int> multiHit;
00983 for(int i=0; i< attachedHits.size(); i++)
00984 {
00985 MucRecHit *ihit = attachedHits[i];
00986
00987
00988 int hitnum = 0;
00989 for(int k=0; k < attachedHits.size(); k++){
00990 MucRecHit *khit = attachedHits[k];
00991 if((ihit->Part()==khit->Part())&&(ihit->Seg()==khit->Seg())&&(ihit->Gap()==khit->Gap()))
00992 hitnum++;
00993 }
00994 multiHit.push_back(hitnum);
00995
00996
00997 }
00998
00999 for(int i=0; i< expectedHits.size(); i++)
01000 {
01001
01002 MucRecHit *ihit = expectedHits[i];
01003
01004
01005 int diff = -999;
01006
01007 for(int j=0; j< attachedHits.size(); j++){
01008 MucRecHit *jhit = attachedHits[j];
01009
01010
01011
01012 if((jhit->Part()==ihit->Part())&&(jhit->Seg()==ihit->Seg())&&(jhit->Gap()==ihit->Gap())&&attachedHits.size()==distanceHits.size())
01013 {
01014 diff = ihit->Strip() - jhit->Strip();
01015
01016
01017 if(m_NtOutput>=2){
01018
01019 m_part = ihit->Part(); m_seg = ihit->Seg(); m_gap = ihit->Gap();
01020 m_strip = jhit->Strip();
01021 m_diff = diff;
01022 m_dist = distanceHits[j];
01023
01024
01025 m_angle_cosmic = -999;
01026 m_angle_updown = -999;
01027
01028
01029
01030 m_ngapwithhits = aTrack->numLayers();
01031 m_nhit = aTrack->numHits();
01032 m_maxhit = aTrack->maxHitsInLayer();
01033 m_multihit = multiHit[j];
01034 m_run = eventHeader->runNumber();
01035 m_event = eventHeader->eventNumber();
01036
01037 m_tuple->write();
01038 }
01039 }
01040
01041
01042 }
01043
01044
01045
01046 if(diff == -999) {
01047 if(m_NtOutput>=2){
01048 m_part = ihit->Part(); m_seg = ihit->Seg(); m_gap = ihit->Gap();
01049 m_strip = ihit->Strip();
01050 m_diff = diff;
01051 m_dist = -999;
01052 m_angle_updown = -999;
01053 m_angle_cosmic = -999;
01054
01055
01056
01057 m_ngapwithhits = aTrack->numLayers();
01058 m_run = eventHeader->runNumber();
01059 m_event = eventHeader->eventNumber();
01060
01061 }
01062 }
01063
01064
01065 }
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01097
01098
01099
01100 }
01101 else {
01102
01103 delete road3D;
01104
01105 }
01106 }
01107 }
01108
01109
01110
01111 RecMucTrack *aaTrack = 0;
01112 RecMucTrack *bbTrack = 0;
01113
01114 int hasMucUp = 0;
01115 int hasMucDown = 0;
01116 for(int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
01117 aaTrack = (*aMucTrackCol)[iTrack];
01118 if((aaTrack->getMucMomentum()).phi()<3.1415926&&(aaTrack->getMucMomentum()).phi()>0) hasMucUp++;
01119 else hasMucDown++;
01120
01121
01122 double px,py,pz,p,theta,phi;
01123 px = (aaTrack->getMucMomentum()).x();
01124 py = (aaTrack->getMucMomentum()).y();
01125 pz = (aaTrack->getMucMomentum()).z();
01126
01127 if(py<0)continue;
01128
01129 if(m_NtOutput>=1){
01130
01131 m_angle_updown = -999;
01132 m_angle_cosmic = cosmicMom.angle(aaTrack->getMucMomentum());
01133 if(m_angle_cosmic>1.57) m_angle_cosmic = 3.14159265 - m_angle_cosmic;
01134 m_run = eventHeader->runNumber();
01135 m_event = eventHeader->eventNumber();
01136
01137 Hep3Vector rotate(-px,pz,py);
01138 theta = rotate.theta();
01139 phi = rotate.phi();
01140
01141 m_px = px; m_py = py; m_pz = pz;
01142 m_theta = theta; m_phi = phi;
01143 m_theta_pipe = (aaTrack->getMucMomentum()).theta();
01144 m_phi_pipe = (aaTrack->getMucMomentum()).phi();
01145
01146
01147
01148
01149 Hep3Vector mucPos = aaTrack->getMucPos();
01150 double posx, posy, posz;
01151 posx = mucPos.x(); posy = mucPos.y(); posz = mucPos.z();
01152
01153 m_projx = -999; m_projz = -999;
01154 if(py!=0){
01155 m_projx = posx - px/py*posy;
01156 m_projz = posz - pz/py*posy;
01157 }
01158
01159 }
01160
01161 }
01162 if(m_NtOutput>=1){
01163 m_mucUp = hasMucUp; m_mucDown = hasMucDown;
01164 m_tuple->write();
01165 }
01166
01167 int forCosmic = 0;
01168 if(aMucTrackCol->size()>=2 && forCosmic == 1){
01169 for(int iTrack = 0; iTrack < (int)aMucTrackCol->size(); iTrack++) {
01170 log << MSG::DEBUG << "iTrack " << iTrack << " / " <<(int)aMucTrackCol->size()<<endreq;
01171 aaTrack = (*aMucTrackCol)[iTrack];
01172 if(aaTrack->trackId()>=0) continue;
01173 aaTrack->setTrackId(iTrack);
01174
01175 for(int jTrack = iTrack+1; jTrack < (int)aMucTrackCol->size(); jTrack++){
01176 bbTrack = (*aMucTrackCol)[jTrack];
01177
01178 Hep3Vector mom_a = aaTrack->getMucMomentum();
01179 Hep3Vector mom_b = bbTrack->getMucMomentum();
01180
01181
01182 if(fabs(mom_a.angle(mom_b) - 3.1415926)<0.2)
01183 {
01184 bbTrack->setTrackId(iTrack);
01185
01186
01187
01188
01189
01190 }
01191
01192 if(m_NtOutput>=1){
01193 m_angle_cosmic = cosmicMom.angle(mom_a);
01194 if(cosmicMom.angle(mom_a)>1.57) m_angle_cosmic = 3.14159265 - cosmicMom.angle(mom_a);
01195
01196 m_angle_updown = fabs(mom_a.angle(mom_b) - 3.1415926);
01197 m_px = -999; m_py = -999; m_pz = -999; m_theta = -999; m_phi = -999; m_theta_pipe = -999; m_phi_pipe = -999;
01198 m_px_mc = -999; m_py_mc = -999; m_pz_mc = -999; m_theta_mc = -999; m_phi_mc = -999;
01199 m_theta_mc_pipe = -999; m_phi_mc_pipe = -999;
01200
01201
01202 }
01203 }
01204
01205 }
01206
01207
01208 }
01209
01210 if( p3DRoadC->size() !=0 ) {
01211 log<<MSG::INFO << "In 3DRoad container : "
01212 << " Num of 3DRoad = " << p3DRoadC->size() <<endreq;
01213
01214 int print2DRoadInfo = 0;
01215 if (print2DRoadInfo == 1) {
01216 for ( int iRoad = 0; iRoad < (int)p3DRoadC->size(); iRoad++) {
01217 MucRec3DRoad *road = (*p3DRoadC)[iRoad];
01218 cout << endl << " " << iRoad << "th 3DRoad :" << endl
01219 << " Part = " << road->GetPart() << endl
01220 << " Seg = " << road->GetSeg() << endl
01221 << " NumGapsWithHits = " << road->GetNGapsWithHits() << endl
01222 << " TotalHits = " << road->GetTotalHits() << endl
01223 << " MaxHitsPerGap = " << road->GetMaxHitsPerGap() << endl
01224 << " LastGapDelta = " << road->GetLastGapDelta() << endl
01225 << " TotalHitsDelta = " << road->GetTotalHitsDelta() << endl
01226 << " DegreesOfFreedom = " << road->GetDegreesOfFreedom() << endl
01227 << " ReducedChiSquare = " << road->GetReducedChiSquare() << endl
01228 << " SlopeZX = " << road->GetSlopeZX() << endl
01229 << " InterceptZX = " << road->GetInterceptZX() << endl
01230 << " SlopeZY = " << road->GetSlopeZY() << endl
01231 << " InterceptZY = " << road->GetInterceptZY() << endl
01232 << " Hits Info : " << endl;
01233
01234 }
01235 }
01236
01237 m_NEventReco ++;
01238 }
01239
01240
01241 for(int i = 0 ; i < p3DRoadC->size(); i++)
01242 delete (*p3DRoadC)[i];
01243 for(int i = 0 ; i < p2DRoad0C->size(); i++)
01244 delete (*p2DRoad0C)[i];
01245 for(int i = 0 ; i < p2DRoad1C->size(); i++)
01246 delete (*p2DRoad1C)[i];
01247
01248 p3DRoadC->clear();
01249 p2DRoad0C->clear();
01250 p2DRoad1C->clear();
01251 delete p3DRoadC;
01252 delete p2DRoad0C;
01253 delete p2DRoad1C;
01254 return StatusCode::SUCCESS;
01255 }