1#include "MdcHoughFinder/Hough.h"
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/SmartDataPtr.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/IPartPropSvc.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/IService.h"
10#include "GaudiKernel/NTuple.h"
11#include "GaudiKernel/INTupleSvc.h"
12#include "EventModel/EventHeader.h"
13#include "MdcRawEvent/MdcDigi.h"
14#include "Identifier/Identifier.h"
15#include "Identifier/MdcID.h"
20#include "EvTimeEvent/RecEsTime.h"
21#include "MdcGeom/EntranceAngle.h"
22#include "RawEvent/RawDataUtil.h"
23#include "MdcData/MdcHit.h"
25#include "McTruth/DecayMode.h"
26#include "McTruth/McParticle.h"
27#include "TrackUtil/Helix.h"
28#include "MdcRecoUtil/Pdt.h"
30#include "TrkBase/TrkFit.h"
31#include "TrkBase/TrkHitList.h"
32#include "TrkBase/TrkExchangePar.h"
33#include "TrkFitter/TrkHelixMaker.h"
34#include "TrkFitter/TrkCircleMaker.h"
35#include "TrkFitter/TrkLineMaker.h"
36#include "TrkFitter/TrkHelixFitter.h"
37#include "MdcxReco/Mdcxprobab.h"
38#include "MdcData/MdcRecoHitOnTrack.h"
39#include "MdcPrintSvc/IMdcPrintSvc.h"
41#include "MdcHoughFinder/HoughTrackList.h"
42#include "MdcHoughFinder/HoughTrack.h"
45#include "EvTimeEvent/RecEsTime.h"
47#include "McTruth/MdcMcHit.h"
48#include "TrkBase/TrkFit.h"
49#include "TrkBase/TrkHitList.h"
50#include "TrkBase/TrkExchangePar.h"
51#include "TrkFitter/TrkHelixMaker.h"
52#include "TrkFitter/TrkCircleMaker.h"
53#include "TrkFitter/TrkLineMaker.h"
54#include "TrkFitter/TrkHelixFitter.h"
55#include "MdcPrintSvc/IMdcPrintSvc.h"
56#include "MdcGeom/EntranceAngle.h"
57#include "TrackUtil/Helix.h"
58#include "GaudiKernel/IPartPropSvc.h"
59#include "MdcRecoUtil/Pdt.h"
60#include "RawEvent/RawDataUtil.h"
61#include "MdcData/MdcHit.h"
62#include "MdcTrkRecon/MdcMap.h"
67#include "BesTimerSvc/IBesTimerSvc.h"
68#include "BesTimerSvc/BesTimerSvc.h"
69#include "BesTimerSvc/BesTimer.h"
77 Algorithm(name, pSvcLocator)
80 declareProperty(
"debug", m_debug = 0);
81 declareProperty(
"debugMap", m_debugMap = 0);
82 declareProperty(
"debug2D", m_debug2D = 0);
83 declareProperty(
"debugTrack", m_debugTrack = 0);
84 declareProperty(
"debugStereo", m_debugStereo= 0);
85 declareProperty(
"debugZs", m_debugZs= 0);
86 declareProperty(
"debug3D", m_debug3D= 0);
87 declareProperty(
"debugArbHit", m_debugArbHit= 0);
88 declareProperty(
"hist", m_hist = 1);
89 declareProperty(
"filter", m_filter= 0);
91 declareProperty(
"keepBadTdc", m_keepBadTdc = 0);
92 declareProperty(
"dropHot", m_dropHot= 0);
93 declareProperty(
"keepUnmatch", m_keepUnmatch = 0);
95 declareProperty(
"combineTracking",m_combineTracking =
false);
96 declareProperty(
"removeBadTrack", m_removeBadTrack = 0);
97 declareProperty(
"dropTrkDrCut", m_dropTrkDrCut= 1.);
98 declareProperty(
"dropTrkDzCut", m_dropTrkDzCut= 10.);
99 declareProperty(
"dropTrkPtCut", m_dropTrkPtCut= 0.12);
100 declareProperty(
"dropTrkChi2Cut", m_dropTrkChi2Cut = 10000.);
102 declareProperty(
"inputType", m_inputType = 0);
104 declareProperty(
"mapCharge", m_mapCharge= -1);
105 declareProperty(
"useHalf", m_useHalf= 0);
106 declareProperty(
"mapHitStyle", m_mapHit= 0);
107 declareProperty(
"nbinTheta", m_nBinTheta = 100);
108 declareProperty(
"nbinRho", m_nBinRho = 100);
109 declareProperty(
"rhoRange", m_rhoRange = 0.1);
110 declareProperty(
"peakWidth", m_peakWidth= 3);
111 declareProperty(
"peakHigh", m_peakHigh= 1);
112 declareProperty(
"hitPro", m_hitPro= 0.4);
114 declareProperty(
"recpos", m_recpos= 1);
115 declareProperty(
"recneg", m_recneg= 1);
116 declareProperty(
"combineSelf", m_combine= 1);
117 declareProperty(
"z0CutCompareHough", m_z0Cut_compareHough= 10);
120 declareProperty(
"n1", m_npart= 100);
121 declareProperty(
"n2", m_n2= 16);
123 declareProperty(
"dsigma", m_dsigma= 1);
124 declareProperty(
"dsigma2", m_dsigma2= 2);
126 declareProperty(
"pdtFile", m_pdtFile =
"pdt.table");
127 declareProperty(
"sigmaFile", m_sigmaFile =
"sigma.table");
128 declareProperty(
"eventFile", m_evtFile=
"EventList");
137 return StatusCode::SUCCESS;
143 MsgStream log(
msgSvc(), name());
144 log << MSG::INFO <<
"in initialize()" << endreq;
149 IPartPropSvc* p_PartPropSvc;
150 static const bool CREATEIFNOTTHERE(
true);
151 sc = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
152 if (!sc.isSuccess() || 0 == p_PartPropSvc) {
153 log << MSG::ERROR <<
" Could not initialize PartPropSvc" << endreq;
156 m_particleTable = p_PartPropSvc->PDT();
160 sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
162 if ( sc.isFailure() ){
163 log << MSG::FATAL << name()<<
" Could not load RawDataProviderSvc!" << endreq;
164 return StatusCode::FAILURE;
169 sc = service (
"MdcGeomSvc", imdcGeomSvc);
170 m_mdcGeomSvc =
dynamic_cast<MdcGeomSvc*
> (imdcGeomSvc);
171 if ( sc.isFailure() ){
172 log << MSG::FATAL <<
"Could not load MdcGeoSvc!" << endreq;
173 return StatusCode::FAILURE;
177 sc = service (
"MagneticFieldSvc",m_pIMF);
178 if(sc!=StatusCode::SUCCESS) {
179 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
181 m_bfield =
new BField(m_pIMF);
182 log << MSG::INFO <<
"field z = "<<m_bfield->
bFieldNominal()<< endreq;
190 sc = service (
"MdcCalibFunSvc", imdcCalibSvc);
192 if ( sc.isFailure() ){
193 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endreq;
194 return StatusCode::FAILURE;
199 sc = service (
"MdcPrintSvc", imdcPrintSvc);
200 m_mdcPrintSvc =
dynamic_cast<MdcPrintSvc*
> (imdcPrintSvc);
201 if ( sc.isFailure() ){
202 log << MSG::FATAL <<
"Could not load MdcPrintSvc!" << endreq;
203 return StatusCode::FAILURE;
207 sc = service(
"BesTimerSvc", m_timersvc);
208 if( sc.isFailure() ) {
209 log << MSG::WARNING <<
" Unable to locate BesTimerSvc" << endreq;
210 return StatusCode::FAILURE;
212 m_timer_all = m_timersvc->
addItem(
"Execution");
213 m_timer_all->
propName(
"nExecution");
242 if ( sc.isFailure() ){
243 log << MSG::FATAL <<
"Could not book Tuple !" << endreq;
244 return StatusCode::FAILURE;
246 return StatusCode::SUCCESS;
252 MsgStream log(
msgSvc(), name());
253 log << MSG::INFO <<
"in execute()" << endreq;
257 m_timer_all->
start();
260 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
262 log << MSG::WARNING <<
"Could not find EvTimeCol" << endreq;
263 return StatusCode::SUCCESS;
265 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
266 if (iter_evt != evTimeCol->end()){
267 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
273 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
275 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
276 return StatusCode::FAILURE;
279 t_eventNum=eventHeader->eventNumber();
280 t_runNum=eventHeader->runNumber();
282 m_eventNum=eventHeader->eventNumber();
283 m_runNum=eventHeader->runNumber();
285 if(m_debug>0) cout<<
"begin evt "<<eventHeader->eventNumber()<<endl;
290 vector<RecMdcTrack*> vec_trackPatTds;
291 int nTdsTk = storeTracks(trackList_tds,hitList_tds,vec_trackPatTds);
294 RecMdcTrackCol::iterator iteritrk_pattsf = vec_trackPatTds.begin();
295 for(;iteritrk_pattsf!=vec_trackPatTds.end();iteritrk_pattsf++){
296 cout<<
"in PATTSF LOST: "<<(*iteritrk_pattsf)->helix(0)<<
" "<<(*iteritrk_pattsf)->helix(1)<<
" "<<(*iteritrk_pattsf)->helix(2)<<
" "<<(*iteritrk_pattsf)->helix(3)<<
" "<<(*iteritrk_pattsf)->helix(4)<<
" chi2 "<<(*iteritrk_pattsf)->chi2()<<endl;
302 if(m_debugArbHit>0 ) m_par.
lPrint=8;
312 lowPt_Evt.open(m_evtFile.c_str());
315 while( lowPt_Evt >> evtNum) {
316 evtlist.push_back(evtNum);
318 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),t_eventNum);
319 if( iter_evt == evtlist.end() ) { setFilterPassed(
false);
return StatusCode::SUCCESS; }
320 else setFilterPassed(
true);
323 if(m_inputType == -1) GetMcInfo();
326 if(m_debug>0) cout<<
"step1 : prepare digi "<<endl;
330 bool debugTruth =
false;
331 if(m_inputType == -1) debugTruth=
true;
332 if(m_debug>0) cout<<
"step2 : hits-> hough hit list "<<endl;
335 if( houghHitList.
nHit() < 10 || houghHitList.
nHit()>500 )
return StatusCode::SUCCESS;
336 if(m_debug>0) houghHitList.
printAll();
339 vector<MdcHit*> mdcHitCol_neg;
340 vector<MdcHit*> mdcHitCol_pos;
341 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
342 for (;
iter != mdcDigiVec.end();
iter++) {
344 if(
HoughHit(digi).driftTime()>1000 ||
HoughHit(digi).driftTime()<=0 )
continue;
347 mdcHitCol_neg.push_back(mdcHit);
348 mdcHitCol_pos.push_back(mdcHit_pos);
351 HoughMap *m_map =
new HoughMap(-1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);
354 if(m_hist) m_nHit = houghHitList.
nHit();
355 if(m_hist) dumpHoughMap(*m_map);
358 if(m_debug>0) cout<<
"step3 : neg track list "<<endl;
359 vector<HoughTrack*> vec_track_neg;
360 vector<HoughTrack*> vec_track2D_neg;
365 vector< vector<int> > stat_2d(2,vector<int>(trackList_size,0) );
366 vector< vector<int> > stat_3d(2,vector<int>(trackList_size,0) );
369 for(
int itrack=0;itrack<trackList_size;itrack++){
370 if(m_debug>0) cout<<
"begin track: "<<itrack<<endl;
372 if(m_debug>0) cout<<
" suppose charge -1 "<<endl;
377 stat_2d[0][itrack] = track_neg.
fit2D(m_bunchT0);
379 if(m_debug>0) cout<<
" charge -1 stat2d "<<stat_2d[0][itrack]<<
" "<<track_charge_2d<<endl;
380 if( stat_2d[0][itrack] == 0 || track_charge_2d ==0 )
continue;
390 if(m_debug>0) cout<<
" nhitstereo -1 "<<nHit3d<<
" "<<track_charge_3d<<endl;
391 if( nHit3d <3 || track_charge_3d==0 )
continue;
394 if( npair==0 ) stat_3d[0][itrack] = track_neg.
fit3D();
398 if(m_debug>0) cout<<
" charge -1 stat3d "<<stat_3d[0][itrack]<<
" "<<endl;
399 if( stat_3d[0][itrack]==0 )
continue;
400 vec_track_neg.push_back( &track_neg );
500 std::sort ( vec_track_neg.begin(),vec_track_neg.end(),
more_pt);
502 vector<MdcTrack*> vec_MdcTrack_neg;
503 for(
unsigned int i =0;i<vec_track_neg.size();i++){
505 vec_MdcTrack_neg.push_back(mdcTrack);
506 if(m_debug>0) cout<<
"trackneg: "<<i<<
" pt "<<vec_track_neg[i]->getPt3D()<<endl;
507 if(m_debug>0) vec_track_neg[i]->print();
509 if(m_debug>0) cout<<
"step4 : judge neg track list "<<endl;
510 judgeHit(mdcTrackList_neg,vec_MdcTrack_neg);
511 if(m_debug>0) cout<<
"finish - charge "<<endl;
516 HoughMap *m_map2 =
new HoughMap(1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);
517 if(m_debug>0) cout<<
"step5 : pos track list "<<endl;
518 vector<HoughTrack*> vec_track_pos;
523 vector< vector<int> > stat_2d2(2,vector<int>(tracklist_size2,0) );
524 vector< vector<int> > stat_3d2(2,vector<int>(tracklist_size2,0) );
527 for(
int itrack=0;itrack<tracklist_size2;itrack++){
529 if(m_debug>0) cout<<
" suppose charge +1 "<<endl;
534 stat_2d2[0][itrack] = track_pos.
fit2D(m_bunchT0);
536 if(m_debug>0) cout<<
" charge +1 stat2d "<<stat_2d2[1][itrack]<<
" "<<track_charge_2d<<endl;
537 if( stat_2d2[0][itrack] == 0 || track_charge_2d==0 )
continue;
546 if(m_debug>0) cout<<
" nhitstereo +1 "<<nHit3d<<
" "<<track_charge_3d<<endl;
549 if( npair==0 ) stat_3d2[0][itrack] = track_pos.
fit3D();
550 else stat_3d2[0][itrack] = track_pos.
fit3D_inner();
553 if(m_debug>0) cout<<
" charge +1 stat3d "<<stat_3d2[1][itrack]<<
" "<<endl;
554 if( stat_3d2[0][itrack]==0 )
continue;
555 vec_track_pos.push_back( &track_pos );
561 std::sort ( vec_track_pos.begin(),vec_track_pos.end(),
more_pt);
564 vector<MdcTrack*> vec_MdcTrack_pos;
565 for(
unsigned int i =0;i<vec_track_pos.size();i++){
567 vec_MdcTrack_pos.push_back(mdcTrack);
568 if(m_debug>0) cout<<
"trackpos : "<<i<<
" pt "<<vec_track_pos[i]->getPt3D()<<endl;
569 if(m_debug>0) vec_track_pos[i]->print();
571 if(m_debug>0) cout<<
"step6 : judge pos track list "<<endl;
572 judgeHit(mdcTrackList_pos,vec_MdcTrack_pos);
578 compareHough(mdcTrackList_neg);
579 compareHough(mdcTrackList_pos);
581 if( mdcTrackList_neg.length()!=0 && mdcTrackList_pos.length()!=0 ) judgeChargeTrack(mdcTrackList_neg,mdcTrackList_pos);
583 mdcTrackList_neg+=mdcTrackList_pos;
586 if(m_combineTracking) nTdsTk = comparePatTsf(mdcTrackList_neg,trackList_tds);
589 if(m_debug>0) cout<<
"step8 : store tds "<<endl;
590 if(m_debug>0) cout<<
"store tds "<<endl;
592 for(
unsigned int i =0;i<mdcTrackList_neg.length();i++){
593 if(m_debug>0) cout<<
"- charge size i : "<<i<<
" "<<mdcTrackList_neg.length()<<endl;
595 mdcTrackList_neg[i]->storeTrack(tkId, trackList_tds, hitList_tds, tkStat);
597 delete mdcTrackList_neg[i];
602 double t_teventTime = m_timer_all->
elapsed();
603 if(m_hist) m_time = t_teventTime;
605 if( m_hist ) ntuple_evt->write();
609 if(m_debug>0) cout<<
"after delete map "<<endl;
610 for(
int ihit=0;ihit<mdcHitCol_neg.size();ihit++){
611 delete mdcHitCol_neg[ihit];
612 delete mdcHitCol_pos[ihit];
615 if(m_debug>0) cout<<
"after delete hit"<<endl;
617 if(m_debug>0) cout<<
"end event "<<endl;
619 return StatusCode::SUCCESS;
624 MsgStream log(
msgSvc(), name());
626 log << MSG::INFO<<
"in finalize()" << endreq;
628 return StatusCode::SUCCESS;
631int MdcHoughFinder::GetMcInfo(){
632 MsgStream log(
msgSvc(), name());
634 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
635 if (!mcParticleCol) {
636 log << MSG::ERROR <<
"Could not find McParticle" << endreq;
637 return StatusCode::FAILURE;
641 g_tkParTruth.clear();
645 int t_pidTruth = -999;
647 McParticleCol::iterator iter_mc = mcParticleCol->begin();
648 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
649 t_pidTruth = (*iter_mc)->particleProperty();
651 if(!(*iter_mc)->primaryParticle())
continue;
655 int pid = t_pidTruth;
657 log << MSG::WARNING <<
"Wrong particle id" <<endreq;
660 IPartPropSvc* p_PartPropSvc;
661 static const bool CREATEIFNOTTHERE(
true);
662 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
663 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
664 std::cout<<
" Could not initialize Particle Properties Service" << std::endl;
666 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
667 if( p_particleTable->particle(pid) ){
668 name = p_particleTable->particle(pid)->name();
669 t_qTruth = p_particleTable->particle(pid)->charge();
670 }
else if( p_particleTable->particle(-pid) ){
671 name =
"anti " + p_particleTable->particle(-pid)->name();
672 t_qTruth = (-1)*p_particleTable->particle(-pid)->charge();
677 if(m_debug>1) std::cout<<__FILE__<<
" "<<__LINE__<<
" new helix with pos "<<(*iter_mc)->initialPosition().v()<<
" mom "<<(*iter_mc)->initialFourMomentum().v()<<
" q "<<t_qTruth<<std::endl;
678 Helix mchelix =
Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);
681 int mcTkId = (*iter_mc)->trackIndex();
683 pair<int, const HepVector> p(mcTkId,mchelix.
a());
684 g_tkParTruth.insert(p);
688 else {rho =1./fabs(mchelix.
radius()) ; theta = mchelix.
phi0();}
693 t_tanl=mchelix.
tanl();
712 m_pidTruth = t_pidTruth;
714 m_ptTruth = mchelix.
pt();
715 m_pTruth = mchelix.
momentum(0.).mag();
717 m_drTruth = mchelix.
dr();
718 m_phi0Truth = mchelix.
phi0();
719 m_omegaTruth =1./(mchelix.
radius());
720 m_dzTruth = mchelix.
dz();
721 m_tanl_mc =mchelix.
tanl();
738 g_firstHit.set(0,0,0);
739 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc(),
"/Event/MC/MdcMcHitCol");
741 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
742 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++) {
743 if((*iter_mchit)->getTrackIndex()==0) {
744 g_firstHit.setX((*iter_mchit)->getPositionX()/10.);
745 g_firstHit.setY((*iter_mchit)->getPositionY()/10.);
746 g_firstHit.setZ((*iter_mchit)->getPositionZ()/10.);
751 std::cout<<__FILE__<<
" Could not get MdcMcHitCol "<<std::endl;
752 return StatusCode::FAILURE;
756 return StatusCode::SUCCESS;
761 uint32_t getDigiFlag = 0;
770void MdcHoughFinder::dumpHoughHitList(
const HoughHitList& houghhitlist){
772 int num_first_half=0;
773 vector<double> vtemp,utemp;
774 double k,b,theta,rho,x_cross,y_cross;
775 std::vector<HoughHit>::const_iterator
iter = houghhitlist.
getList().begin();
777 int exit_multiturn=0;
786 m_u[iHit] = h.
getU();
787 m_v[iHit] = h.
getV();
789 m_r[iHit] = h.
getR();
799 if ( type <0 ) type=1;
812 m_nSig_Axial=nsig_axial;
813 m_exit_multiturn = exit_multiturn;
816 Leastfit(utemp,vtemp,k,b);
819 x_cross = -b/(k+1/k);
821 rho=sqrt(x_cross*x_cross+y_cross*y_cross);
822 theta=atan2(y_cross,x_cross);
834 m_nHit = num_first_half;
837void MdcHoughFinder::dumpHoughMap(
const HoughMap& houghmap){
914void MdcHoughFinder::diffMap(
const HoughMap& houghmap,
const HoughMap& houghmap2){
939void MdcHoughFinder::Leastfit(vector<double> u,vector<double>
v,
double& k ,
double& b){
942 double *
x=
new double[N];
943 double *y=
new double[N];
944 for(
int i=0;i<N;i++){
949 TF1 *fpol1=
new TF1(
"fpol1",
"pol1",-50,50);
950 TGraph *tg=
new TGraph(N,x,y);
951 tg->Fit(
"fpol1",
"QN");
952 double ktemp =fpol1->GetParameter(1);
953 double btemp =fpol1->GetParameter(0);
966int MdcHoughFinder::storeTracks(
RecMdcTrackCol*& trackList_tds ,
RecMdcHitCol*& hitList_tds,vector<RecMdcTrack*>& vec_trackPatTds){
967 MsgStream log(
msgSvc(), name());
970 DataObject *aTrackCol;
971 DataObject *aRecHitCol;
972 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
973 if(!m_combineTracking){
974 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
975 if(aTrackCol != NULL) {
976 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
977 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
979 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
980 if(aRecHitCol != NULL) {
981 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
982 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
987 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
993 if(!sc.isSuccess()) {
994 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
995 return StatusCode::FAILURE;
999 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
1001 hitList_tds =
dynamic_cast<RecMdcHitCol*
> (aRecHitCol);
1005 if(!sc.isSuccess()) {
1006 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
1007 return StatusCode::FAILURE;
1011 if(m_removeBadTrack && m_combineTracking) {
1012 if( m_debug>0 ) cout<<
"PATTSF collect "<<trackList_tds->size()<<
" track. "<<endl;
1013 if(trackList_tds->size()!=0){
1014 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1015 for(;iter_pat!=trackList_tds->end();iter_pat++){
1016 double d0=(*iter_pat)->helix(0);
1017 double kap = (*iter_pat)->helix(2);
1018 double pt = 0.00001;
1019 if(fabs(kap)>0.00001) pt = fabs(1./kap);
1020 double dz=(*iter_pat)->helix(3);
1021 double chi2=(*iter_pat)->chi2();
1022 if( m_debug>0) cout<<
"d0: "<<d0<<
" z0: "<<dz<<
" pt "<<pt<<
" chi2 "<<chi2<<endl;
1024 if( pt<=m_dropTrkPtCut ){
1025 vec_trackPatTds.push_back(*iter_pat);
1027 HitRefVec rechits = (*iter_pat)->getVecHits();
1028 HitRefVec::iterator hotIter = rechits.begin();
1029 while (hotIter!=rechits.end()) {
1033 if(m_debug>0) cout <<
"remove hit " << (*hotIter)->getId()<<
"("<<layer<<
","<<wire<<
")"<<endl;
1034 hitList_tds->remove(*hotIter);
1042 if( m_debug>0 ) cout<<
"after delete trackcol size : "<<trackList_tds->size()<<endl;
1045 if(m_debug>0) cout<<
" PATTSF find 0 track. "<<endl;
1049 int nTdsTk=trackList_tds->size();
1054 cout<<
"length in clearMem "<<list1.length()<<
" "<<list2.length()<<endl;
1059 for(
unsigned int j=0;j<list1.length();j++){
1060 cout<<
"-i j "<<i<<
" "<<j<<
" "<<
vectrk_for_clean[i]<<
" "<<&(list1[j]->track())<<endl;
1061 if(
vectrk_for_clean[i] == &(list1[j]->track()) ) {sametrk=1;cout<<
"not delete new trk "<<endl;}
1064 for(
unsigned int k=0;k<list2.length();k++){
1065 cout<<
"+i k "<<i<<
" "<<k<<
" "<<
vectrk_for_clean[i]<<
" "<<&(list2[k]->track())<<endl;
1066 if(
vectrk_for_clean[i] == &(list2[k]->track()) ) {sametrk=1;cout<<
"not delete new trk "<<endl;}
1070 cout<<
"delete i "<<i<<endl;
1079 if(m_debug>0) cout<<
"in judgeChargeTrack"<<endl;
1080 if(m_debug>0) cout<<
"ntrack length neg : "<<list1.length()<<endl;
1081 if(m_debug>0) cout<<
"ntrack length pos : "<<list2.length()<<endl;
1082 for(
int itrack1=0; itrack1<list1.
nTrack(); itrack1++){
1083 MdcTrack* track_1 = list1[itrack1];
1085 double d0_1 = par1.
d0();
1086 double phi0_1 = par1.
phi0();
1087 double omega_1 = par1.
omega();
1088 double cr=fabs(1./par1.
omega());
1090 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1091 double z0_1 = par1.
z0();
1092 for(
int itrack2=0; itrack2<list2.
nTrack(); itrack2++){
1093 MdcTrack* track_2 = list2[itrack2];
1095 double d0_2 = par2.
d0();
1096 double phi0_2 = par2.
phi0();
1097 double omega_2 = par2.
omega();
1098 double cR=fabs(1./par2.
omega());
1100 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1101 double z0_2= par2.
z0();
1103 double bestDiff = 1.0e+20;
1104 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1105 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1106 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1107 if(diff < bestDiff){
1113 if(bestDiff != 1.0e20) {
1115 cout<<
"There is ambiguous +- charge in the track list "<<endl;
1116 cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1119 if( fabs(z0_1) >= fabs(z0_2) ) { list1.
remove( track_1 ); itrack1--;
break;}
1120 if( fabs(z0_1) < fabs(z0_2) ) { list2.
remove( track_2 ); itrack2--;
break;}
1122 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no (+-) track in hough"<<endl; }
1127void MdcHoughFinder::compareHough(
MdcTrackList& mdcTrackList){
1128 if(m_debug>0) cout<<
"in compareHough "<<endl;
1129 if(m_debug>0) cout<<
"ntrack : "<<mdcTrackList.length()<<endl;
1130 for(
int itrack=0; itrack<mdcTrackList.length(); itrack++){
1131 MdcTrack* track = mdcTrackList[itrack];
1134 double pt = (1./par.
omega())/333.567;
1135 if(m_debug>0) cout<<
"i Track : "<<itrack<<
" nHit: "<<nhit<<
" pt: "<<pt<<endl;
1139 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1140 MdcTrack* track_1 = mdcTrackList[itrack1];
1145 double d0_1 = par1.
d0();
1146 double phi0_1 = par1.
phi0();
1147 double omega_1 = par1.
omega();
1148 double z0_1= par1.
z0();
1149 double cr=fabs(1./par1.
omega());
1151 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1152 if(m_debug>0) cout<<
"circle 1 : "<<cr<<
","<<cx<<
","<<cy<<endl;
1154 for(
int itrack2=itrack1+1; itrack2<mdcTrackList.length(); itrack2++){
1155 MdcTrack* track_2 = mdcTrackList[itrack2];
1160 double d0_2 = par2.
d0();
1161 double phi0_2 = par2.
phi0();
1162 double omega_2 = par2.
omega();
1163 double z0_2= par2.
z0();
1164 double cR=fabs(1./par2.
omega());
1166 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1167 if(m_debug>0) cout<<
"circle 2 : "<<cR<<
","<<cX<<
","<<cY<<endl;
1169 double bestDiff = 1.0e+20;
1170 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1171 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1172 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1173 if(diff < bestDiff){
1179 double zdiff = z0_1-z0_2;
1180 if(bestDiff != 1.0e20 && fabs(zdiff)<25.){
1181 if(m_debug>0) cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1184 if( chi2_1/nhit1 > chi2_2/nhit2 ){
1185 if(m_debug>0) cout<<
"remove track1 "<<1./par1.
omega()/333.567<<endl;
1187 mdcTrackList.
remove( track_1 );
1193 if(m_debug>0) cout<<
"remove track2 "<<1./par2.
omega()/333.567<<endl;
1195 mdcTrackList.
remove( track_2 );
1199 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no same track in hough"<<endl; }
1212 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1213 MdcTrack* track_1 = mdcTrackList[itrack1];
1218 double d0_1 = par1.
d0();
1219 double phi0_1 = par1.
phi0();
1220 double omega_1 = par1.
omega();
1221 double z0_1= par1.
z0();
1222 double cr=fabs(1./par1.
omega());
1224 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1227 double bestDiff = 1.0e+20;
1228 double ptDiff = 0.0;
1230 vector<double> a0,a1,a2,a3,a4;
1231 RecMdcTrackCol::iterator iterBest;
1232 RecMdcTrackCol::iterator iteritrk = trackList_tds->begin();
1234 vector< RecMdcTrackCol::iterator > iter_pat_temp;
1235 for(;iteritrk!=trackList_tds->end();iteritrk++){
1236 if(m_debug>0) cout<<
"being pattsf trk "<<itrk<<endl;
1237 double pt=(*iteritrk)->pxy();
1238 a0.push_back( (*iteritrk)->helix(0) );
1239 a1.push_back( (*iteritrk)->helix(1) );
1240 a2.push_back( (*iteritrk)->helix(2) );
1241 a3.push_back( (*iteritrk)->helix(3) );
1242 a4.push_back( (*iteritrk)->helix(4) );
1243 cR=(-333.567)/a2[itrk];
1244 cX=(cR+a0[itrk])*
cos(a1[itrk]);
1245 cY=(cR+a0[itrk])*
sin(a1[itrk]);
1248 cout<<
" compare PATTSF and HOUGH "<<endl;
1249 cout<<
" fabs(cX) "<< fabs(cX)<<
"fabs(cx) "<<fabs(cx)<<endl;
1250 cout<<
" fabs(cY) "<< fabs(cY)<<
"fabs(cy) "<<fabs(cy)<<endl;
1251 cout<<
" fabs(cR) "<< fabs(cR)<<
"fabs(cr) "<<fabs(cr)<<endl;
1252 cout<<
" fabs(cx-cX) "<< fabs(cx-cX)<<
"fabs(cy-cY) "<<fabs(cy-cY)<<
" fabs(cr-cR) "<< fabs(cr-cR)<<endl;
1255 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1256 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1257 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1258 if(m_debug>0) cout<<
" diff "<<diff<<
" pt "<<pt<<endl;
1259 iter_pat_temp.push_back(iteritrk);
1260 if( fabs(pt) > ptDiff){
1274 if(bestDiff != 1.0e20) {
1275 for(
int itrkter = 0;itrkter<iter_pat_temp.size();itrkter++){
1276 iterBest = iter_pat_temp[itrkter];
1277 if(m_debug>0) cout<<
" same track pattsf & hough , then compare nhit. "<<endl;
1278 double d0_pattsf =(*iterBest)->helix(0);
1279 double z0_pattsf =(*iterBest)->helix(3);
1280 double d0_hough = d0_1;
1281 double z0_hough = z0_1;
1282 int use_pattsf(1),use_hough(1);
1283 if( fabs(d0_pattsf)>m_dropTrkDrCut || fabs(z0_pattsf)>m_dropTrkDzCut ) use_pattsf=0;
1284 if( fabs(d0_hough)>m_dropTrkDrCut || fabs(z0_hough)>m_dropTrkDzCut ) use_hough=0;
1285 if( use_pattsf==0 && use_hough==1 ) {
1286 trackList_tds->remove(*iterBest);
1287 if(m_debug>0) cout<<
" use houghTrack, vertex pattsf wrong"<<endl;
1289 if( use_pattsf==1 && use_hough==0 ) {
1290 mdcTrackList.
remove( track_1 );
1292 if(m_debug>0) cout<<
" use pattsfTrack, vertex hough wrong"<<endl;
1295 if( (use_pattsf==0 && use_hough==0) || (use_pattsf==1 && use_hough==1) ){
1296 int nhit_pattsf=( (*iterBest)->ndof()+5 );
1297 double chi2_2 = (*iterBest)->chi2();
1298 int nhit_hough = nhit1;
1299 if(m_debug>0) cout<<
" nhit "<<nhit_pattsf<<
" "<<nhit_hough<<endl;
1300 if( nhit_pattsf>chi2_1) {
1301 mdcTrackList.
remove( track_1 );
1303 if(m_debug>0) cout<<
" use pattsfTrack "<<endl;
1307 trackList_tds->remove(*iterBest);
1308 if(m_debug>0) cout<<
" use houghTrack "<<endl;
1324 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no same track in pattsf"<<endl; }
1329 if(trackList_tds->size()!=0){
1331 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1332 for(;iter_pat!=trackList_tds->end();iter_pat++,digi++){
1333 (*iter_pat)->setTrackId(digi);
1337 return trackList_tds->size();
1340int MdcHoughFinder::judgeHit(
MdcTrackList& list,vector<MdcTrack*>& trackCol){
1341 if(m_debug>0) cout<<
"in judgHit: "<<endl;
1342 for(
unsigned int i =0;i<trackCol.size();i++){
1345 list.append(trackCol[i]);
1351 MsgStream log(
msgSvc(), name());
1352 NTuplePtr nt1(
ntupleSvc(),
"MdcHoughFinder/evt");
1356 ntuple_evt =
ntupleSvc()->book(
"MdcHoughFinder/evt", CLID_ColumnWiseTuple,
"evt");
1358 ntuple_evt->addItem(
"eventNum", m_eventNum);
1359 ntuple_evt->addItem(
"runNum", m_runNum);
1361 ntuple_evt->addItem(
"nHit", m_nHit,0, 6796);
1430 ntuple_evt->addItem(
"nMapPk", m_nMapPk, 0,100);
1476 ntuple_evt->addItem(
"time", m_time);
1478 }
else { log << MSG::ERROR <<
"Cannot book tuple MdcHoughFinder/hough" <<endmsg;
1479 return StatusCode::FAILURE;
1526 return StatusCode::SUCCESS;
std::vector< MdcDigi * > MdcDigiVec
HepGeom::Point3D< double > HepPoint3D
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
double sin(const BesAngle a)
double cos(const BesAngle a)
vector< TrkRecoTrk * > vectrk_for_clean
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
double bFieldNominal() const
void propName(std::string name)
float elapsed(void) const
double cosTheta(void) const
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
double radius(void) const
returns radious of helix.
double dr(void) const
returns an element of parameters.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
static void setContext(TrkContextEv *context)
static void setCalib(const MdcCalibFunSvc *mdcCalibFunSvc)
static void setContext(TrkContextEv *context)
static void setCalib(const MdcCalibFunSvc *mdcCalibFunSvc)
int addTruthInfo(std::map< int, const HepVector > mcTkPars)
const std::vector< HoughHit > & getList() const
static void setMdcGeomSvc(MdcGeomSvc *geomSvc)
const MdcDigi * digi() const
int getSlayerType() const
static void setBunchTime(double t0)
double getDriftDist() const
HepPoint3D getPointTruth() const
double getDriftDistTruth() const
static void setMdcCalibFunSvc(const MdcCalibFunSvc *calibSvc)
int getPeakNumber() const
const HoughPeak & getPeak(int i) const
int getTrackNumber() const
const HoughTrack & getTrack(int i) const
static double m_dSigma_cut
static double m_dSigma_cut2
HoughTrack & getTrack(int i)
void setHoughHitList(vector< HoughHit > vec_hit)
int fit2D(double bunchtime)
void setMdcHit(const vector< MdcHit * > *mdchit)
void setCharge(int charge)
virtual BesTimer * addItem(const std::string &name)=0
static MdcDetector * instance()
MdcHoughFinder(const std::string &name, ISvcLocator *pSvcLocator)
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
void printRecMdcTrackCol() const
void remove(MdcTrack *atrack)
static void readMCppTable(std::string filenm)
MdcDigiVec & getMdcDigiVec(uint32_t control=0)
int getTrackIndex() const
virtual double chisq() const =0
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
virtual int nHit(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
const TrkFit * fitResult() const
_EXTERN_ std::string RecMdcTrackCol
_EXTERN_ std::string RecMdcHitCol