1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/IDataManagerSvc.h"
7#include "GaudiKernel/PropertyMgr.h"
8#include "GaudiKernel/INTupleSvc.h"
9#include "EventModel/EventHeader.h"
10#include "ReconEvent/ReconEvent.h"
11#include "ExtEvent/RecExtTrack.h"
12#include "MdcRecEvent/RecMdcTrack.h"
13#include "EmcRecEventModel/RecEmcEventModel.h"
14#include "MdcRawEvent/MdcDigi.h"
15#include "TofRawEvent/TofDigi.h"
16#include "EmcRawEvent/EmcDigi.h"
17#include "MucRawEvent/MucDigi.h"
18#include "McTruth/McKine.h"
19#include "McTruth/McParticle.h"
20#include "McTruth/MdcMcHit.h"
21#include "McTruth/TofMcHit.h"
22#include "McTruth/EmcMcHit.h"
23#include "McTruth/MucMcHit.h"
24#include "McTruth/McRelTableDefs.h"
25#include "Identifier/Identifier.h"
26#include "Identifier/MucID.h"
27#include "GaudiKernel/IPartPropSvc.h"
29#include "MucRecAlg/MucRecTrkExt.h"
30#include "MucRecAlg/MucRecTrkExtParameter.h"
31#include "MucGeomSvc/IMucGeomSvc.h"
32#include "MucGeomSvc/MucGeoGeneral.h"
33#include "MucGeomSvc/MucGeoGap.h"
34#include "MucGeomSvc/MucGeoStrip.h"
35#include "MucGeomSvc/MucConstant.h"
36#include "MucRecEvent/MucRecHit.h"
37#include "MucRecEvent/MucRecHitContainer.h"
38#include "MucRecEvent/RecMucTrack.h"
50 Algorithm(name, pSvcLocator)
53 declareProperty(
"ExtTrackSeedMode", m_ExtTrackSeedMode = 1);
54 declareProperty(
"CompareWithMcHit", m_CompareWithMcHit = 0);
55 declareProperty(
"FittingMethod", m_fittingMethod = 1);
56 declareProperty(
"EmcShowerSeedMode",m_EmcShowerSeedMode = 0);
57 declareProperty(
"MucHitSeedMode", m_MucHitSeedMode = 0);
58 declareProperty(
"ConfigFile", m_configFile =
"MucConfig.xml");
59 declareProperty(
"Blind", m_Blind =
false);
60 declareProperty(
"NtOutput", m_NtOutput = 0);
61 declareProperty(
"MsOutput", m_MsOutput =
false);
62 declareProperty(
"FilterFile", m_filter_filename);
69 MsgStream log(
msgSvc(), name());
70 log << MSG::INFO <<
"in initialize()" << endreq;
73 IPartPropSvc* p_PartPropSvc;
74 static const bool CREATEIFNOTTHERE(
true);
75 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
76 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
77 log << MSG::WARNING <<
" Could not initialize Particle Properties Service" << endreq;
78 return PartPropStatus;
80 m_particleTable = p_PartPropSvc->PDT();
86 m_NHitsFoundTotal = 0;
88 m_NHitsMisFoundTotal = 0;
89 m_NHitsLostByMdcTotal = 0;
90 m_NHitsLostByExtTotal = 0;
93 m_NTracksRecoTotal = 0;
94 m_NTracksLostByMdcTotal = 0;
95 m_NTracksLostByExtTotal = 0;
96 m_NTracksMdcGhostTotal = 0;
98 for(
int i = 0; i < 20; i++) m_NHitsLost.push_back(0);
99 for(
int i = 0; i < 10; i++) m_NHitsLostInGap.push_back(0);
102 StatusCode sc = service(
"MucGeomSvc", mucGeomSvc);
103 if (sc == StatusCode::SUCCESS) {
108 return StatusCode::FAILURE;
110 m_MucRecHitContainer = 0;
117 if ( nt1 ) { m_tuple = nt1;}
120 m_tuple =
ntupleSvc()->book (
"FILE401/T", CLID_RowWiseTuple,
"MucTrkRecon N-Tuple");
122 sc = m_tuple->addItem (
"posx", m_posx);
123 sc = m_tuple->addItem (
"posy", m_posy);
124 sc = m_tuple->addItem (
"posz", m_posz);
125 sc = m_tuple->addItem (
"posx_ext", m_posx_ext);
126 sc = m_tuple->addItem (
"posy_ext", m_posy_ext);
127 sc = m_tuple->addItem (
"posz_ext", m_posz_ext);
128 sc = m_tuple->addItem (
"posxsigma", m_posx_sigma);
129 sc = m_tuple->addItem (
"posysigma", m_posy_sigma);
130 sc = m_tuple->addItem (
"poszsigma", m_posz_sigma);
131 sc = m_tuple->addItem (
"Depth", m_depth);
132 sc = m_tuple->addItem (
"Distance",m_Distance);
133 sc = m_tuple->addItem (
"MaxHits", m_MaxHits);
134 sc = m_tuple->addItem (
"Chi2", m_Chi2);
135 sc = m_tuple->addItem (
"Dist_x", m_Dist_x);
136 sc = m_tuple->addItem (
"Dist_y", m_Dist_y);
137 sc = m_tuple->addItem (
"Dist_z", m_Dist_z);
138 sc = m_tuple->addItem (
"px_mc", m_px_mc);
139 sc = m_tuple->addItem (
"py_mc", m_py_mc);
140 sc = m_tuple->addItem (
"pz_mc", m_pz_mc);
141 sc = m_tuple->addItem (
"emctrack",m_emctrack);
142 sc = m_tuple->addItem (
"muchasdigi",m_muc_digi);
144 sc = m_tuple->addItem (
"part", m_part);
145 sc = m_tuple->addItem (
"seg", m_seg);
146 sc = m_tuple->addItem (
"gap", m_gap);
147 sc = m_tuple->addItem (
"strip", m_strip);
148 sc = m_tuple->addItem (
"diff", m_diff);
149 sc = m_tuple->addItem (
"distance",m_distance);
150 sc = m_tuple->addItem (
"run", m_run);
151 sc = m_tuple->addItem (
"event", m_event);
155 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple) << endmsg;
162 if ( m_filter_filename ==
"") {
163 m_filter_filename =getenv(
"MUCRECALGROOT");
164 m_filter_filename +=
"/share/filter.txt";
167 if (m_filter_filename.size()) {
168 std::ifstream infile(m_filter_filename.c_str());
170 while (!infile.eof()) {
171 FilterEvent filterevt;
172 infile >> filterevt.bossver >> filterevt.runid >> filterevt.eventid;
173 if ((!infile.good()) || (infile.eof())) {
177 m_filter_event.push_back(filterevt);
186 return StatusCode::SUCCESS;
192 MsgStream log(
msgSvc(), name());
193 log << MSG::INFO <<
"in execute()" << endreq;
196 StatusCode sc = StatusCode::SUCCESS;
201 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
203 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
207 log << MSG::INFO <<
"Event: "<<m_totalEvent<<
"\tcurrent run: "<<eventHeader->runNumber()<<
"\tcurrent event: "<< eventHeader->eventNumber()<<endreq;
209event = eventHeader->eventNumber();
210run = eventHeader->runNumber();
212 string release = getenv(
"BES_RELEASE");
216 for (std::vector<FilterEvent>::iterator it = m_filter_event.begin();
217 it != m_filter_event.end(); ++it) {
218 const FilterEvent& fe = (*it);
219 if (
release == fe.bossver && run == fe.runid && event == fe.eventid) {
220 cout <<
"SKIP: " << fe.bossver <<
" "
222 << fe.eventid << std::endl;
223 return StatusCode::SUCCESS;
228 if(m_CompareWithMcHit==1){
229 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
230 if (!mcParticleCol) {
231 log << MSG::FATAL <<
"Could not find McParticle" << endreq;
235 McParticleCol::iterator iter_mc = mcParticleCol->begin();
239 int pid = (*iter_mc)->particleProperty();
245 if(m_particleTable->particle( pid )){
246 charge = (int)m_particleTable->particle( pid )->charge();
247 mass = m_particleTable->particle( pid )->mass();
249 else log << MSG::ERROR <<
"no this particle id in particle table, please check data" <<endreq;
250 }
else if ( pid <0 ) {
251 if(m_particleTable->particle( -pid )){
252 charge = (int)m_particleTable->particle( -pid )->charge();
254 mass = m_particleTable->particle( -pid )->mass();
256 else log << MSG::ERROR <<
"no this particle id in particle table, please check data" <<endreq;
258 log << MSG::WARNING <<
"wrong particle id, please check data" <<endreq;
267 HepLorentzVector initialMomentum = (*iter_mc)->initialFourMomentum();
268 HepLorentzVector initialPos = (*iter_mc)->initialPosition();
270 m_px_mc = initialMomentum.px();
271 m_py_mc = initialMomentum.py();
272 m_pz_mc = initialMomentum.pz();
276 log << MSG::INFO <<
" particleId = " << (*iter_mc)->particleProperty() << endreq;
281 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),
"/Event/Digi/MucDigiCol");
283 log << MSG::FATAL <<
"Could not find MUC digi" << endreq;
284 return( StatusCode::FAILURE);
286 MucDigiCol::iterator iter4 = mucDigiCol->begin();
287 for (;iter4 != mucDigiCol->end(); iter4++, digiId++) {
289 log << MSG::INFO <<
"Total MUC digis:\t" << digiId << endreq;
290 if( digiId == 0 )
return ( StatusCode::SUCCESS);
323 if (m_CompareWithMcHit) {
327 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
328 if (!mcParticleCol) {
329 log << MSG::FATAL <<
"Could not find McParticle" << endreq;
332 McParticleCol::iterator iter_mc = mcParticleCol->begin();
335 SmartDataPtr<Event::MucMcHitCol> aMucMcHitCol(eventSvc(),
"/Event/MC/MucMcHitCol");
337 log << MSG::WARNING <<
"Could not find MucMcHitCol" << endreq;
341 log << MSG::DEBUG <<
"MucMcHitCol contains " << aMucMcHitCol->size() <<
" Hits " << endreq;
342 MucMcHitCol::iterator iter_MucMcHit = aMucMcHitCol->begin();
343 for (; iter_MucMcHit != aMucMcHitCol->end(); iter_MucMcHit++) {
344 mucID = (*iter_MucMcHit)->identify();
346 log << MSG::DEBUG <<
" MucMcHit " <<
" : "
351 <<
" Track Id " << (*iter_MucMcHit)->getTrackIndex()
352 <<
" pos x " << (*iter_MucMcHit)->getPositionX()
353 <<
" pos y " << (*iter_MucMcHit)->getPositionY()
354 <<
" pos z " << (*iter_MucMcHit)->getPositionZ()
358 for (iter_mc = mcParticleCol->begin(); iter_mc != mcParticleCol->end(); iter_mc++) {
359 if ( (*iter_mc)->trackIndex() == (*iter_MucMcHit)->getTrackIndex() ) {
360 assocMcPart = *iter_mc;
364 if (assocMcPart == 0) {
365 log << MSG::WARNING <<
"No Corresponding Mc Particle found for this MucMcHit" << endreq;
368 MucMcHit *assocMucMcHit = *iter_MucMcHit;
371 if (relMcMuc == 0) log << MSG::DEBUG <<
"relMcMuc not created " << endreq;
374 if(!addstat)
delete relMcMuc;
378 log << MSG::DEBUG <<
" Fill McPartToMucHitTab, size " << assocMcMuc.
size() << endreq;
379 iter_mc = mcParticleCol->begin();
380 for (;iter_mc != mcParticleCol->end(); iter_mc++) {
381 log << MSG::DEBUG <<
" Track index " << (*iter_mc)->trackIndex()
382 <<
" particleId = " << (*iter_mc)->particleProperty()
385 vector< McPartToMucHitRel* > vecMucMcHit = assocMcMuc.
getRelByFirst(*iter_mc);
386 vector< McPartToMucHitRel* >::iterator iter_MucMcHit = vecMucMcHit.begin();
387 for (; iter_MucMcHit != vecMucMcHit.end(); iter_MucMcHit++) {
388 mucID = (*iter_MucMcHit)->getSecond()->identify();
392 <<
" MC Particle index "
393 << (*iter_MucMcHit)->getFirst()->trackIndex()
394 <<
" contains " <<
" MucMcHit "
421 if (!m_MucRecHitContainer) {
424 m_MucRecHitContainer->
Clear();
428 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
429 DataObject *mucRecHitCol;
430 eventSvc()->findObject(
"/Event/Recon/MucRecHitCol",mucRecHitCol);
431 if(mucRecHitCol != NULL) {
432 dataManSvc->clearSubTree(
"/Event/Recon/MucRecHitCol");
433 eventSvc()->unregisterObject(
"/Event/Recon/MucRecHitCol");
436 sc = eventSvc()->registerObject(
"/Event/Recon/MucRecHitCol", aMucRecHitCol);
438 log << MSG::ERROR <<
"/Event/Recon/MucRecHitCol not registerd!" << endreq;
439 return( StatusCode::FAILURE);
442 log << MSG::INFO <<
"Add digis" << endreq;
443 MucDigiCol::iterator iter_Muc = mucDigiCol->begin();
445 for (;iter_Muc != mucDigiCol->end(); iter_Muc++, mucDigiId++) {
446 mucID = (*iter_Muc)->identify();
452 m_MucRecHitContainer->
AddHit(part, seg, gap, strip);
454 log << MSG::DEBUG <<
" digit" << mucDigiId <<
" : "
458 <<
" strip " << strip
467 DataObject *aReconEvent ;
468 eventSvc()->findObject(
"/Event/Recon",aReconEvent);
469 if(aReconEvent==NULL) {
472 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon",aReconEvent);
473 if(sc!=StatusCode::SUCCESS) {
474 log << MSG::FATAL <<
"Could not register ReconEvent" <<endreq;
475 return( StatusCode::FAILURE);
478 StatusCode fr = eventSvc()->findObject(
"/Event/Recon",aReconEvent);
479 if(fr!=StatusCode::SUCCESS) {
480 log << MSG::WARNING <<
"Could not find register ReconEvent, will create it" <<endreq;
481 StatusCode sc = eventSvc()->registerObject(
"/Event/Recon",aReconEvent);
482 if(sc!=StatusCode::SUCCESS) {
483 log << MSG::FATAL <<
"Could not register ReconEvent" <<endreq;
484 return( StatusCode::FAILURE);
488 DataObject *mucTrackCol;
489 eventSvc()->findObject(
"/Event/Recon/RecMucTrackCol",mucTrackCol);
490 if(mucTrackCol != NULL) {
491 dataManSvc->clearSubTree(
"/Event/Recon/RecMucTrackCol");
492 eventSvc()->unregisterObject(
"/Event/Recon/RecMucTrackCol");
495 sc = eventSvc()->registerObject(
"/Event/Recon/RecMucTrackCol", aRecMucTrackCol);
496 if(sc!=StatusCode::SUCCESS) {
497 log << MSG::FATAL <<
"Could not register MUC track collection" << endreq;
498 return( StatusCode::FAILURE);
502 SmartDataPtr<RecMucTrackCol> findRecMucTrackCol(eventSvc(),
"/Event/Recon/RecMucTrackCol");
503 if (!findRecMucTrackCol) {
504 log << MSG::FATAL <<
"Could not find RecMucTrackCol" << endreq;
505 return( StatusCode::FAILURE);
507 aRecMucTrackCol->clear();
513 SmartDataPtr<RecExtTrackCol> aExtTrackCol(eventSvc(),
"/Event/Recon/RecExtTrackCol");
515 log << MSG::WARNING <<
"Can't find ExtTrackCol in TDS!" << endreq;
519 SmartDataPtr<RecMdcTrackCol> aMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
521 log << MSG::WARNING <<
"Can't find MdcTrackCol in TDS!" << endreq;
527 SmartDataPtr<RecEmcShowerCol> aShowerCol(eventSvc(),
"/Event/Recon/RecEmcShowerCol");
529 log << MSG::WARNING <<
"Could not find RecEmcShowerCol" << endreq;
543 log << MSG::INFO <<
"Add tracks info, ExtTrackSeedMode = " << m_ExtTrackSeedMode <<
", EmcShowerSeedMode = " << m_EmcShowerSeedMode << endreq;
545 if (m_ExtTrackSeedMode == 1)
547 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
548 if (!mcParticleCol) {
549 log << MSG::FATAL <<
"Could not find McParticle" << endreq;
551 return( StatusCode::SUCCESS);
553 McParticleCol::iterator iter_mc = mcParticleCol->begin();
555 int trackIndex = -99;
556 for (
int iTrack = 0;iter_mc != mcParticleCol->end(); iter_mc++, iTrack++) {
557 if(!(*iter_mc)->primaryParticle())
continue;
558 int pid = (*iter_mc)->particleProperty();
563 if(m_particleTable->particle( pid )){
564 charge = (int)m_particleTable->particle( pid )->charge();
565 mass = m_particleTable->particle( pid )->mass();
567 else log << MSG::ERROR <<
"no this particle id in particle table, please check data" <<endreq;
570 if(m_particleTable->particle( -pid )){
571 charge = (int)m_particleTable->particle( -pid )->charge();
573 mass = m_particleTable->particle( -pid )->mass();
575 else log << MSG::ERROR <<
"no this particle id in particle table, please check data" <<endreq;
577 log << MSG::WARNING <<
"wrong particle id, please check data" <<endreq;
582 <<
" neutral particle charge = 0!!! ...just skip it !"
587 trackIndex = (*iter_mc)->trackIndex();
588 log << MSG::DEBUG <<
"iTrack " << iTrack <<
" index " << trackIndex
589 <<
" particleId = " << (*iter_mc)->particleProperty()
594 aTrack->
setId(muctrackId);
596 HepLorentzVector initialMomentum = (*iter_mc)->initialFourMomentum();
597 HepLorentzVector initialPos = (*iter_mc)->initialPosition();
598 float theta0 = initialMomentum.theta();
599 float phi0 = initialMomentum.phi();
603 float x0 = initialPos.x();
604 float y0 = initialPos.y();
605 float z0 = initialPos.z();
607 Hep3Vector startPos(x0, y0, z0);
608 Hep3Vector startP(initialMomentum.px(), initialMomentum.py(), initialMomentum.pz());
609 log << MSG::DEBUG <<
"startP " << startP <<
" startPos "<<startPos<< endreq;
610 Hep3Vector endPos(0, 0, 0), endP;
616 aTrack->
SetExtMucPos( endPos.x(), endPos.y(), endPos.z() );
618 aTrack->
SetMucPos( endPos.x(), endPos.y(), endPos.z() );
632 log << MSG::INFO <<
"Add track, trkIndex: " << trackIndex <<
"\tmucTrkId: " << muctrackId << endreq;
633 aRecMucTrackCol->add(aTrack);
637 else if (m_ExtTrackSeedMode == 2)
639 if (!aExtTrackCol || !aMdcTrackCol) {
640 log << MSG::WARNING <<
"Can't find ExtTrackCol or MdcTrackCol in TDS!" << endreq;
641 return StatusCode::SUCCESS;
644 int trackIndex = -99;
651 RecExtTrackCol::iterator iter_ExtTrack = aExtTrackCol->begin();
652 RecMdcTrackCol::iterator iter_MdcTrack = aMdcTrackCol->begin();
654 for (;iter_ExtTrack != aExtTrackCol->end() && iter_MdcTrack != aMdcTrackCol->end(); iter_ExtTrack++, iter_MdcTrack++, iExtTrack++)
656 trackIndex = (*iter_ExtTrack)->GetTrackId();
657 log << MSG::DEBUG <<
"iExtTrack " << iExtTrack <<
" index " << trackIndex <<
" MucPos "
658 << iExtTrack << (*iter_ExtTrack)->mucPosition().x() <<
" "
659 << (*iter_ExtTrack)->mucPosition().y() <<
" "
660 << (*iter_ExtTrack)->mucPosition().z() <<
" r "
661 << (*iter_ExtTrack)->mucPosition().r() << endreq;
663 if((*iter_ExtTrack)->mucPosition().x() == -99 &&
664 (*iter_ExtTrack)->mucPosition().y() == -99 &&
665 (*iter_ExtTrack)->mucPosition().z() == -99)
667 log << MSG::INFO <<
"Bad ExtTrack, trackIndex: " << trackIndex <<
", skip" << endreq;
672 krechi = (*iter_ExtTrack)->MucKalchi2();
673 kdof= (*iter_ExtTrack)->MucKaldof();
674 kdep = (*iter_ExtTrack)->MucKaldepth();
675 kbrLay = (*iter_ExtTrack)->MucKalbrLastLayer();
676 kecLay = (*iter_ExtTrack)->MucKalecLastLayer();
677 if(kdof<=0)krechi = 0.;
678 else krechi = krechi/kdof;
683 aTrack->
setId(muctrackId);
697 Hep3Vector mdcMomentum = (*iter_MdcTrack)->p3();
698 Hep3Vector mucPos = (*iter_ExtTrack)->mucPosition();
699 Hep3Vector mucMomentum = (*iter_ExtTrack)->mucMomentum();
702 aTrack->
SetMdcMomentum( mdcMomentum.x(), mdcMomentum.y(), mdcMomentum.z() );
703 aTrack->
SetExtMucPos( mucPos.x(), mucPos.y(), mucPos.z() );
706 aTrack->
SetMucPos( mucPos.x(), mucPos.y(), mucPos.z() );
707 aTrack->
SetMucMomentum( mucMomentum.x(), mucMomentum.y(), mucMomentum.z() );
709 aTrack->
SetCurrentDir( mucMomentum.x(), mucMomentum.y(), mucMomentum.z() );
712 log << MSG::INFO <<
"Add track, trkIndex: " << trackIndex <<
"\tmucTrkId: " << muctrackId << endreq;
713 aRecMucTrackCol->add(aTrack);
717 else if(m_ExtTrackSeedMode == 3)
721 log << MSG::WARNING <<
"Can't find MdcTrackCol in TDS!" << endreq;
722 return StatusCode::SUCCESS;
725 log<< MSG::INFO <<
"Mdc track size: "<<aMdcTrackCol->size()<<endreq;
727 int trackIndex = -99;
728 for(RecMdcTrackCol::iterator iter_mdc1 = aMdcTrackCol->begin(); iter_mdc1 != aMdcTrackCol->end(); iter_mdc1++){
733 trackIndex = (*iter_mdc1)->trackId();
734 HepVector helix = (*iter_mdc1)->helix();
737 float x0 = helix[0] *
cos(helix[1]);
738 float y0 = helix[0] *
sin(helix[1]);
745 float dx = -1*
sin(helix[1]);
746 float dy =
cos(helix[1]);
753 aTrack->
setId(muctrackId);
759 Hep3Vector mucPos(x0,y0,z0);
760 Hep3Vector mucMomentum(dx,dy,dz);
771 log << MSG::INFO <<
"Add track, trkIndex: " << trackIndex <<
"\tmucTrkId: " << muctrackId << endreq;
772 aRecMucTrackCol->add(aTrack);
776 else {log << MSG::INFO <<
"ExtTrackSeedMode error!"<<endreq; }
779 if(m_EmcShowerSeedMode == 1)
781 int trackIndex = 999;
782 RecEmcShowerCol::iterator iShowerCol;
783 for(iShowerCol=aShowerCol->begin(); iShowerCol!=aShowerCol->end(); iShowerCol++)
791 aTrack->
setId(muctrackId);
794 Hep3Vector mucPos = (*iShowerCol)->position();
795 Hep3Vector mucMomentum = (*iShowerCol)->position();
797 aTrack->
SetExtMucPos( mucPos.x(), mucPos.y(), mucPos.z() );
800 aTrack->
SetMucPos( mucPos.x(), mucPos.y(), mucPos.z() );
801 aTrack->
SetMucMomentum( mucMomentum.x(), mucMomentum.y(), mucMomentum.z() );
803 aTrack->
SetCurrentDir( mucMomentum.x(), mucMomentum.y(), mucMomentum.z() );
807 log << MSG::INFO <<
"Add track, trkIndex: " << trackIndex <<
"\tmucTrkId: " << muctrackId << endreq;
808 aRecMucTrackCol->add(aTrack);
814 log << MSG::DEBUG <<
" track container filled " << endreq;
817 log << MSG::INFO <<
"Start tracking..." << endreq;
820 for(
int iTrack = 0; iTrack < (int)aRecMucTrackCol->size(); iTrack++)
822 log << MSG::DEBUG <<
"iTrack " << iTrack << endreq;
823 aTrack = (*aRecMucTrackCol)[iTrack];
828 if(currentPos.mag() <
kMinor) {
829 log << MSG::WARNING <<
"No MUC intersection in track " << iTrack << endreq;
834 int firstHitFound[2] = { 0, 0};
835 int firstHitGap[2] = {-1, -1};
845 float xInsct, yInsct, zInsct;
846 aTrack->
Project(iPart, iGap, xInsct, yInsct, zInsct, seg);
847 if(m_MsOutput) cout <<
"part " << iPart <<
" gap " << iGap <<
" x " << xInsct <<
" y " << yInsct <<
" z " << zInsct <<
" seg " << seg << endl;
849 if(seg == -1)
continue;
853 for(
int iDeltaSeg = 0; iDeltaSeg <
kNSegSearch; iDeltaSeg++)
868 for (
int iHit = 0; iHit < m_MucRecHitContainer->
GetGapHitCount(iPart, iSeg, iGap); iHit++)
870 log << MSG::DEBUG <<
"iSeg " << iSeg <<
" iHit " << iHit << endreq;
871 MucRecHit* pHit = m_MucRecHitContainer->
GetHit(iPart, iSeg, iGap, iHit);
875 log << MSG::WARNING <<
"MucRecTrkExt: null pointer to pHit" << endreq;
884 log << MSG::DEBUG <<
"distance = " << setw(8) << dX <<
" size " << setw(4) << window << endreq;
888 m_part = iPart; m_seg = iSeg; m_gap = iGap; m_strip = pHit->
Strip();
889 m_diff = -99; m_tuple->write();
892 if (fabs(dX) < window)
914 if (firstHitGap[orient] == -1) firstHitGap[orient] = iGap;
915 firstHitFound[orient] = 1;
918 log << MSG::DEBUG <<
" part " << iPart <<
" seg " << iSeg <<
" gap " << iGap
919 <<
" strip " << setw(2) << pHit->
Strip() <<
" attatched" << endreq;
920 log << MSG::DEBUG <<
"current total hits " << aTrack->
GetTotalHits() << endreq;
923 m_NHitsLostInGap[iGap]++;
934 if(m_ExtTrackSeedMode != 3 && !m_Blind) {
935 if (firstHitFound[orient] && firstHitGap[orient] != iGap) aTrack->
CorrectDir();
943 aTrack->
LineFit(m_fittingMethod);
945 log << MSG::INFO <<
"Fit track done! trackIndex: " << aTrack->
trackId() <<
", mucId: " << aTrack->
id() <<
", RecMode: " << aTrack->
GetRecMode() << endreq;
949 m_depth = aTrack->
depth();
952 m_Chi2 = aTrack->
chi2();
960 m_emctrack = m_emcrec;
966 vector<MucRecHit*> attachedHits = aTrack->
GetHits();
968 vector<float> distanceHits = aTrack->
getDistHits();
972 for(
int i=0; i< expectedHits.size(); i++)
978 for(
int j=0; j< attachedHits.size(); j++)
982 if(attachedHits.size()==distanceHits.size())
984 m_part = jhit->
Part(); m_seg = jhit->
Seg(); m_gap = jhit->
Gap();
985 m_strip = jhit->
Strip();
986 m_distance = distanceHits[j];
987 m_Distance = distanceHits_quad[j];
1000 log << MSG::DEBUG <<
"track Index " << aTrack->
trackId()
1001 << setw(2) << mucDigiCol->size() - nHitsAttached <<
" of "
1002 << setw(2) << mucDigiCol->size() <<
" lost " << endreq;
1012 if(m_MucHitSeedMode == 1)
1014 MucRecHit *pHit = 0 ,*pHit0 = 0, *pHit1 = 0;
1021 bool hit0 =
false, hit1 =
false;
int firstgap0 = -1, firstgap1 = -1;
int nStrip0 = 0, nStrip1 = 0;
1022 Hep3Vector posHit0, posHit1;
1026 for (
int iHit0 = 0; iHit0 < count; iHit0++)
1029 pHit = m_MucRecHitContainer->
GetHit(iPart, iSeg, iGap, iHit0);
1031 log << MSG::FATAL <<
"MucRecRoadFinder-E10 " <<
" part " << iPart
1032 <<
" seg " << iSeg <<
" gap " << iGap <<
" null pointer"
1041 if(orient == 1 && hit0 ==
false){
1045 if(iGap == firstgap0){
1050 if(orient == 0 && hit1 ==
false){
1054 if(iGap == firstgap1){
1079 int trackIndex = 999;
1082 aTrack->
setId(muctrackId);
1087 Hep3Vector mucPos, mucMomentum;
1089 mucMomentum.set(posHit0.x(),posHit0.y(),posHit1.z());
1090 mucPos = mucMomentum * 0.9;
1093 mucMomentum.set(posHit0.x(),posHit1.y(),posHit0.z()*0.5+posHit1.z()*0.5);
1094 mucPos = mucMomentum * 0.9;
1097 aTrack->
SetExtMucPos( mucPos.x(), mucPos.y(), mucPos.z() );
1100 aTrack->
SetMucPos( mucPos.x(), mucPos.y(), mucPos.z() );
1101 aTrack->
SetMucMomentum( mucMomentum.x(), mucMomentum.y(), mucMomentum.z() );
1103 aTrack->
SetCurrentDir( mucMomentum.x(), mucMomentum.y(), mucMomentum.z() );
1106 aRecMucTrackCol->add(aTrack);
1112 m_depth = aTrack->
depth();
1115 m_Chi2 = aTrack->
chi2();
1131 int nTracksTotal = 0;
1132 int nTracksFound = 0;
1133 int nTracksLost = 0;
1134 int nTracksLostByExt = 0;
1135 int nTracksMisFound = 0;
1137 int nDigisTotal = 0;
1141 int nHitsMisFound = 0;
1347 m_NDigisTotal += nDigisTotal;
1348 m_NHitsTotal += nHitsTotal;
1349 m_NHitsFoundTotal += nHitsFound;
1350 m_NHitsLostTotal += nHitsLost;
1351 m_NHitsMisFoundTotal += nHitsMisFound;
1354 m_NTracksTotal += nTracksTotal;
1355 m_NTracksRecoTotal += nTracksFound;
1356 m_NTracksLostByMdcTotal += nTracksLost;
1357 m_NTracksLostByExtTotal += nTracksLostByExt;
1358 m_NTracksMdcGhostTotal += nTracksMisFound;
1359 if (aRecMucTrackCol->size() > 0)
1361 RecMucTrack *aRecMucTrack = (*aRecMucTrackCol)[0];
1376 if(m_NtOutput>=1) m_tuple->write();
1377 return StatusCode::SUCCESS;
1383 MsgStream log(
msgSvc(), name());
1384 log << MSG::INFO <<
"in finalize()" << endreq;
1386 log << MSG::INFO <<
" In " << m_NDigisTotal <<
" total MucDigis " << endreq;
1387 log << MSG::INFO <<
" In " << m_NHitsTotal <<
" total MucMcHits " << endreq;
1388 log << MSG::INFO << m_NHitsFoundTotal <<
" hits found in Reco tracks, " << endreq;
1389 log << MSG::INFO << m_NHitsLostTotal <<
" hits lost (not found), of which "
1390 << m_NHitsLostByMdcTotal <<
" lost because Mdc track not constructed "
1391 << m_NHitsLostByExtTotal <<
" lost because Ext track not intersect with muc " << endreq;
1392 log << MSG::INFO << m_NHitsMisFoundTotal <<
" hits mis found (not belong to this track, but mis attached)" << endreq;
1394 log << MSG::INFO <<
" In " << m_NTracksTotal <<
" total Mc tracks " << endreq;
1395 log << MSG::INFO << m_NTracksRecoTotal <<
" tracks found " << endreq;
1396 log << MSG::INFO << m_NTracksLostByMdcTotal <<
" tracks lost because Mdc track not constructed " << endreq;
1397 log << MSG::INFO << m_NTracksLostByExtTotal <<
" tracks lost because Ext track not intersect with muc " << endreq;
1398 log << MSG::INFO << m_NTracksMdcGhostTotal <<
" tracks are Mdc ghost tracks " << endreq;
1417 return StatusCode::SUCCESS;
1423 MsgStream log(
msgSvc(), name());
1432 int firstHitFound[2] = { 0, 0};
1433 int firstHitGap[2] = {-1, -1};
1441 float xInsct, yInsct, zInsct;
1442 aTrack->
Project(iPart, iGap, xInsct, yInsct, zInsct, seg);
1443 log << MSG::INFO <<
"part " << iPart <<
" gap " << iGap <<
" x " << xInsct <<
" y " << yInsct <<
" z " << zInsct <<
" seg " << seg << endreq;
1453 for(
int iDeltaSeg = 0; iDeltaSeg <
kNSegSearch; iDeltaSeg++)
1465 for (
int iHit = 0; iHit < m_MucRecHitContainer->
GetGapHitCount(iPart, iSeg, iGap); iHit++)
1467 log << MSG::DEBUG <<
"iSeg " << iSeg <<
" iHit " << iHit << endreq;
1468 MucRecHit* pHit = m_MucRecHitContainer->
GetHit(iPart, iSeg, iGap, iHit);
1472 log << MSG::WARNING <<
"MucRecTrkExt: null pointer to pHit" << endreq;
1479 log << MSG::DEBUG <<
"distance = " << setw(8) << dX <<
" size " << setw(4) << window << endreq;
1482 if (fabs(dX) < window)
1508 if (firstHitGap[orient] == -1) firstHitGap[orient] = iGap;
1509 firstHitFound[orient] = 1;
1513 log << MSG::DEBUG <<
" part " << iPart <<
" seg " << iSeg <<
" gap " << iGap
1514 <<
" strip " << setw(2) << pHit->
Strip() <<
" attatched" << endreq;
1515 log << MSG::DEBUG <<
"current total hits " << aTrack->
GetTotalHits() << endreq;
1519 m_NHitsLostInGap[iGap]++;
1531 if (firstHitFound[orient] && firstHitGap[orient] != iGap) aTrack->
CorrectDir();
1539 aTrack->
LineFit(m_fittingMethod);
1550 if(mom.mag()<0.6) mom_id = 0;
1551 else if(mom.mag()<0.8) mom_id = 1;
1552 else if(mom.mag()<1) mom_id = 2;
double sin(const BesAngle a)
double cos(const BesAngle a)
const int kDeltaSeg[kNSegSearch]
const float kWindowSize_Mom_Gap[4][9]
const float kFirstHitWindowRatio
ObjectVector< MucRecHit > MucRecHitCol
ObjectVector< RecMucTrack > RecMucTrackCol
void setkalbrLastLayer(int br)
int maxHitsInLayer() const
void setkalecLastLayer(int ec)
void setkalRechi2(double ch)
void setkalDepth(double de)
void init()
Initialize the internal pointer to an ObjectList of relations.
unsigned long size() const
This method returns the number of relations in the table.
bool addRelation(Relation< T1, T2 > *rel)
std::vector< Relation< T1, T2 > * > getRelByFirst(const T1 *pobj) const
MucGeoGap * GetGap(const int part, const int seg, const int gap) const
Get a pointer to the gap identified by (part,seg,gap).
static MucGeoGeneral * Instance()
Get a pointer to the single instance of MucGeoGeneral.
static int barrel_ec(const Identifier &id)
Values of different levels.
static int layer(const Identifier &id)
static int channel(const Identifier &id)
static int segment(const Identifier &id)
static value_type getPartNum()
static value_type getSegNum(int part)
static value_type getGapNum(int part)
void Clear()
Remove all hit objects from the container, and destroy them.
MucRecHit * GetHit(const MucRecHitID hitID)
Get a MucRecHit object by hit identifier.
void AddHit(const Identifier id)
void SetMucRecHitCol(MucRecHitCol *p)
int GetGapHitCount(const MucRecHitID gapID)
How many hits are there in this gap?
Hep3Vector GetCenterPos() const
Get Center position of the strip (global coords).
int Part() const
Get Part.
int Strip() const
Get Strip.
void SetHitMode(int recmode)
void TrackFinding(RecMucTrack *aTrack)
float getWindowSize(Hep3Vector mom, int part, int seg, int gap)
MucRecTrkExt(const std::string &name, ISvcLocator *pSvcLocator)
int GetTotalHits() const
How many hits in all does this track contain?
void LineFit(int fittingMethod)
Line fit with hits on a seg with max hits.
void CorrectPos()
Correct current position of this trajectory.
void CorrectDir()
Correct direction of this trajectory.
void ComputeTrackInfo(int fittingmethod)
Get corresponding monte carlo track pointer.
void pushExtDistHits(float dist)
vector< float > getExtDistHits() const
void SetMdcMomentum(const float px, const float py, const float pz)
set start moment of the track in Mdc.
Hep3Vector getMucPos() const
start position of this track in Muc.
Hep3Vector getMucPosSigma() const
void AttachInsct(Hep3Vector insct)
Attach the intersection to this trajectory.
void SetExtMucPos(const float x, const float y, const float z)
set start position of ext track in Muc. (compute from MdcPos MdcMomentum or get from ExtTrack)
void SetExtTrackID(int id)
set Ext track id. for compute from mdc myself
void SetMdcPos(const float x, const float y, const float z)
set start position of the track in Mdc.
void SetCurrentDir(const float x, const float y, const float z)
set current direction of the trajectory.
void SetExtTrack(RecExtTrack *extTrack)
set Ext track point.
void setTrackId(const int trackId)
set the index for this track.
Hep3Vector GetExtMucDistance() const
Distance match of the ext track with muc track in first layer.
void GetMdcExtTrack(Hep3Vector mdcStartPos, Hep3Vector mdcStartMomentum, int charge, Hep3Vector &mucStartPos, Hep3Vector &mucStartMomentum)
compute ext track myself from mdc.
Hep3Vector GetMucStripPos() const
Hep3Vector GetCurrentDir() const
Current direction.
Hep3Vector getMdcMomentum() const
momentum of this track in Mdc
Hep3Vector CalculateInsct(const int part, const int seg, const int gap)
Calculate intersection from all hits attached on this gap.
void Project(const int &part, const int &gap, float &x, float &y, float &z, int &seg)
Where does the trajectory of this track intersect a specific gap?
vector< float > getQuadDistHits() const
void SetMucMomentum(const float px, const float py, const float pz)
set start moment of the track in Muc.
Hep3Vector GetCurrentInsct() const
Current intersection.
void SetExtMucMomentum(const float px, const float py, const float pz)
set start moment of ext track in Muc.
vector< MucRecHit * > GetHits() const
Get all hits on this track.
void AttachHit(MucRecHit *hit)
set corresponding monte carlo track pointer.
Hep3Vector GetCurrentPos() const
Current position.
void SetCurrentInsct(const float x, const float y, const float z)
set current intersection of the trajectory with strip plane.
void SetCurrentPos(const float x, const float y, const float z)
set current position of the trajectory.
vector< MucRecHit * > GetExpectedHits() const
void SetRecMode(int recmode)
void SetMucPos(const float x, const float y, const float z)
set start position of the track in Muc. (after line fit and correction)
float GetHitDistance2(const MucRecHit *hit)
no abs value
vector< float > getDistHits() const
Event::Relation< Event::McParticle, Event::MucMcHit > McPartToMucHitRel