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(
"d1", m_d1= 0.2);
124 declareProperty(
"d2", m_d2= 0.2);
126 declareProperty(
"pdtFile", m_pdtFile =
"pdt.table");
127 declareProperty(
"eventFile", m_evtFile=
"EventList");
136 return StatusCode::SUCCESS;
142 MsgStream log(
msgSvc(), name());
143 log << MSG::INFO <<
"in initialize()" << endreq;
148 IPartPropSvc* p_PartPropSvc;
149 static const bool CREATEIFNOTTHERE(
true);
150 sc = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
151 if (!sc.isSuccess() || 0 == p_PartPropSvc) {
152 log << MSG::ERROR <<
" Could not initialize PartPropSvc" << endreq;
155 m_particleTable = p_PartPropSvc->PDT();
159 sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
161 if ( sc.isFailure() ){
162 log << MSG::FATAL << name()<<
" Could not load RawDataProviderSvc!" << endreq;
163 return StatusCode::FAILURE;
168 sc = service (
"MdcGeomSvc", imdcGeomSvc);
169 m_mdcGeomSvc =
dynamic_cast<MdcGeomSvc*
> (imdcGeomSvc);
170 if ( sc.isFailure() ){
171 log << MSG::FATAL <<
"Could not load MdcGeoSvc!" << endreq;
172 return StatusCode::FAILURE;
176 sc = service (
"MagneticFieldSvc",m_pIMF);
177 if(sc!=StatusCode::SUCCESS) {
178 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
180 m_bfield =
new BField(m_pIMF);
181 log << MSG::INFO <<
"field z = "<<m_bfield->
bFieldNominal()<< endreq;
189 sc = service (
"MdcCalibFunSvc", imdcCalibSvc);
191 if ( sc.isFailure() ){
192 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endreq;
193 return StatusCode::FAILURE;
198 sc = service (
"MdcPrintSvc", imdcPrintSvc);
199 m_mdcPrintSvc =
dynamic_cast<MdcPrintSvc*
> (imdcPrintSvc);
200 if ( sc.isFailure() ){
201 log << MSG::FATAL <<
"Could not load MdcPrintSvc!" << endreq;
202 return StatusCode::FAILURE;
206 sc = service(
"BesTimerSvc", m_timersvc);
207 if( sc.isFailure() ) {
208 log << MSG::WARNING <<
" Unable to locate BesTimerSvc" << endreq;
209 return StatusCode::FAILURE;
211 m_timer_all = m_timersvc->
addItem(
"Execution");
212 m_timer_all->
propName(
"nExecution");
240 if ( sc.isFailure() ){
241 log << MSG::FATAL <<
"Could not book Tuple !" << endreq;
242 return StatusCode::FAILURE;
244 return StatusCode::SUCCESS;
250 MsgStream log(
msgSvc(), name());
251 log << MSG::INFO <<
"in execute()" << endreq;
255 m_timer_all->
start();
258 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
260 log << MSG::WARNING <<
"Could not find EvTimeCol" << endreq;
261 return StatusCode::SUCCESS;
263 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
264 if (iter_evt != evTimeCol->end()){
265 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
271 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
273 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
274 return StatusCode::FAILURE;
277 t_eventNum=eventHeader->eventNumber();
278 t_runNum=eventHeader->runNumber();
280 m_eventNum=eventHeader->eventNumber();
281 m_runNum=eventHeader->runNumber();
283 if(m_debug>0) cout<<
"begin evt "<<eventHeader->eventNumber()<<endl;
288 vector<RecMdcTrack*> vec_trackPatTds;
289 int nTdsTk = storeTracks(trackList_tds,hitList_tds,vec_trackPatTds);
292 RecMdcTrackCol::iterator iteritrk_pattsf = vec_trackPatTds.begin();
293 for(;iteritrk_pattsf!=vec_trackPatTds.end();iteritrk_pattsf++){
294 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;
300 if(m_debugArbHit>0 ) m_par.
lPrint=8;
310 lowPt_Evt.open(m_evtFile.c_str());
313 while( lowPt_Evt >> evtNum) {
314 evtlist.push_back(evtNum);
316 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),t_eventNum);
317 if( iter_evt == evtlist.end() ) { setFilterPassed(
false);
return StatusCode::SUCCESS; }
318 else setFilterPassed(
true);
321 if(m_inputType == -1) GetMcInfo();
324 if(m_debug>0) cout<<
"step1 : prepare digi "<<endl;
328 bool debugTruth =
false;
329 if(m_inputType == -1) debugTruth=
true;
330 if(m_debug>0) cout<<
"step2 : hits-> hough hit list "<<endl;
333 if( houghHitList.
nHit() < 10 || houghHitList.
nHit()>500 )
return StatusCode::SUCCESS;
334 if(m_debug>0) houghHitList.
printAll();
337 vector<MdcHit*> mdcHitCol_neg;
338 vector<MdcHit*> mdcHitCol_pos;
339 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
340 for (;
iter != mdcDigiVec.end();
iter++) {
342 if(
HoughHit(digi).driftTime()>1000 ||
HoughHit(digi).driftTime()<=0 )
continue;
345 mdcHitCol_neg.push_back(mdcHit);
346 mdcHitCol_pos.push_back(mdcHit_pos);
349 HoughMap *m_map =
new HoughMap(-1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);
352 if(m_hist) m_nHit = houghHitList.
nHit();
353 if(m_hist) dumpHoughMap(*m_map);
356 if(m_debug>0) cout<<
"step3 : neg track list "<<endl;
357 vector<HoughTrack*> vec_track_neg;
358 vector<HoughTrack*> vec_track2D_neg;
363 vector< vector<int> > stat_2d(2,vector<int>(trackList_size,0) );
364 vector< vector<int> > stat_3d(2,vector<int>(trackList_size,0) );
367 for(
int itrack=0;itrack<trackList_size;itrack++){
368 if(m_debug>0) cout<<
"begin track: "<<itrack<<endl;
370 if(m_debug>0) cout<<
" suppose charge -1 "<<endl;
375 stat_2d[0][itrack] = track_neg.
fit2D(m_bunchT0);
377 if(m_debug>0) cout<<
" charge -1 stat2d "<<stat_2d[0][itrack]<<
" "<<track_charge_2d<<endl;
378 if( stat_2d[0][itrack] == 0 || track_charge_2d ==0 )
continue;
388 if(m_debug>0) cout<<
" nhitstereo -1 "<<nHit3d<<
" "<<track_charge_3d<<endl;
389 if( nHit3d <3 || track_charge_3d==0 )
continue;
392 if( npair==0 ) stat_3d[0][itrack] = track_neg.
fit3D();
396 if(m_debug>0) cout<<
" charge -1 stat3d "<<stat_3d[0][itrack]<<
" "<<endl;
397 if( stat_3d[0][itrack]==0 )
continue;
398 vec_track_neg.push_back( &track_neg );
498 std::sort ( vec_track_neg.begin(),vec_track_neg.end(),
more_pt);
500 vector<MdcTrack*> vec_MdcTrack_neg;
501 for(
unsigned int i =0;i<vec_track_neg.size();i++){
503 vec_MdcTrack_neg.push_back(mdcTrack);
504 if(m_debug>0) cout<<
"trackneg: "<<i<<
" pt "<<vec_track_neg[i]->getPt3D()<<endl;
505 if(m_debug>0) vec_track_neg[i]->print();
507 if(m_debug>0) cout<<
"step4 : judge neg track list "<<endl;
508 judgeHit(mdcTrackList_neg,vec_MdcTrack_neg);
509 if(m_debug>0) cout<<
"finish - charge "<<endl;
514 HoughMap *m_map2 =
new HoughMap(1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);
515 if(m_debug>0) cout<<
"step5 : pos track list "<<endl;
516 vector<HoughTrack*> vec_track_pos;
521 vector< vector<int> > stat_2d2(2,vector<int>(tracklist_size2,0) );
522 vector< vector<int> > stat_3d2(2,vector<int>(tracklist_size2,0) );
525 for(
int itrack=0;itrack<tracklist_size2;itrack++){
527 if(m_debug>0) cout<<
" suppose charge +1 "<<endl;
532 stat_2d2[0][itrack] = track_pos.
fit2D(m_bunchT0);
534 if(m_debug>0) cout<<
" charge +1 stat2d "<<stat_2d2[1][itrack]<<
" "<<track_charge_2d<<endl;
535 if( stat_2d2[0][itrack] == 0 || track_charge_2d==0 )
continue;
544 if(m_debug>0) cout<<
" nhitstereo +1 "<<nHit3d<<
" "<<track_charge_3d<<endl;
547 if( npair==0 ) stat_3d2[0][itrack] = track_pos.
fit3D();
548 else stat_3d2[0][itrack] = track_pos.
fit3D_inner();
551 if(m_debug>0) cout<<
" charge +1 stat3d "<<stat_3d2[1][itrack]<<
" "<<endl;
552 if( stat_3d2[0][itrack]==0 )
continue;
553 vec_track_pos.push_back( &track_pos );
559 std::sort ( vec_track_pos.begin(),vec_track_pos.end(),
more_pt);
562 vector<MdcTrack*> vec_MdcTrack_pos;
563 for(
unsigned int i =0;i<vec_track_pos.size();i++){
565 vec_MdcTrack_pos.push_back(mdcTrack);
566 if(m_debug>0) cout<<
"trackpos : "<<i<<
" pt "<<vec_track_pos[i]->getPt3D()<<endl;
567 if(m_debug>0) vec_track_pos[i]->print();
569 if(m_debug>0) cout<<
"step6 : judge pos track list "<<endl;
570 judgeHit(mdcTrackList_pos,vec_MdcTrack_pos);
576 compareHough(mdcTrackList_neg);
577 compareHough(mdcTrackList_pos);
579 if( mdcTrackList_neg.length()!=0 && mdcTrackList_pos.length()!=0 ) judgeChargeTrack(mdcTrackList_neg,mdcTrackList_pos);
581 mdcTrackList_neg+=mdcTrackList_pos;
584 if(m_combineTracking) nTdsTk = comparePatTsf(mdcTrackList_neg,trackList_tds);
587 if(m_debug>0) cout<<
"step8 : store tds "<<endl;
588 if(m_debug>0) cout<<
"store tds "<<endl;
590 for(
unsigned int i =0;i<mdcTrackList_neg.length();i++){
591 if(m_debug>0) cout<<
"- charge size i : "<<i<<
" "<<mdcTrackList_neg.length()<<endl;
593 mdcTrackList_neg[i]->storeTrack(tkId, trackList_tds, hitList_tds, tkStat);
595 delete mdcTrackList_neg[i];
600 double t_teventTime = m_timer_all->
elapsed();
601 if(m_hist) m_time = t_teventTime;
603 if( m_hist ) ntuple_evt->write();
607 if(m_debug>0) cout<<
"after delete map "<<endl;
608 for(
int ihit=0;ihit<mdcHitCol_neg.size();ihit++){
609 delete mdcHitCol_neg[ihit];
610 delete mdcHitCol_pos[ihit];
613 if(m_debug>0) cout<<
"after delete hit"<<endl;
615 if(m_debug>0) cout<<
"end event "<<endl;
617 return StatusCode::SUCCESS;
622 MsgStream log(
msgSvc(), name());
624 log << MSG::INFO<<
"in finalize()" << endreq;
626 return StatusCode::SUCCESS;
629int MdcHoughFinder::GetMcInfo(){
630 MsgStream log(
msgSvc(), name());
632 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
633 if (!mcParticleCol) {
634 log << MSG::ERROR <<
"Could not find McParticle" << endreq;
635 return StatusCode::FAILURE;
639 g_tkParTruth.clear();
643 int t_pidTruth = -999;
645 McParticleCol::iterator iter_mc = mcParticleCol->begin();
646 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
647 t_pidTruth = (*iter_mc)->particleProperty();
649 if(!(*iter_mc)->primaryParticle())
continue;
653 int pid = t_pidTruth;
655 log << MSG::WARNING <<
"Wrong particle id" <<endreq;
658 IPartPropSvc* p_PartPropSvc;
659 static const bool CREATEIFNOTTHERE(
true);
660 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
661 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
662 std::cout<<
" Could not initialize Particle Properties Service" << std::endl;
664 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
665 if( p_particleTable->particle(pid) ){
666 name = p_particleTable->particle(pid)->name();
667 t_qTruth = p_particleTable->particle(pid)->charge();
668 }
else if( p_particleTable->particle(-pid) ){
669 name =
"anti " + p_particleTable->particle(-pid)->name();
670 t_qTruth = (-1)*p_particleTable->particle(-pid)->charge();
675 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;
676 Helix mchelix =
Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);
679 int mcTkId = (*iter_mc)->trackIndex();
681 pair<int, const HepVector> p(mcTkId,mchelix.
a());
682 g_tkParTruth.insert(p);
686 else {rho =1./fabs(mchelix.
radius()) ; theta = mchelix.
phi0();}
691 t_tanl=mchelix.
tanl();
710 m_pidTruth = t_pidTruth;
712 m_ptTruth = mchelix.
pt();
713 m_pTruth = mchelix.
momentum(0.).mag();
715 m_drTruth = mchelix.
dr();
716 m_phi0Truth = mchelix.
phi0();
717 m_omegaTruth =1./(mchelix.
radius());
718 m_dzTruth = mchelix.
dz();
719 m_tanl_mc =mchelix.
tanl();
736 g_firstHit.set(0,0,0);
737 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc(),
"/Event/MC/MdcMcHitCol");
739 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
740 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++) {
741 if((*iter_mchit)->getTrackIndex()==0) {
742 g_firstHit.setX((*iter_mchit)->getPositionX()/10.);
743 g_firstHit.setY((*iter_mchit)->getPositionY()/10.);
744 g_firstHit.setZ((*iter_mchit)->getPositionZ()/10.);
749 std::cout<<__FILE__<<
" Could not get MdcMcHitCol "<<std::endl;
750 return StatusCode::FAILURE;
754 return StatusCode::SUCCESS;
759 uint32_t getDigiFlag = 0;
768void MdcHoughFinder::dumpHoughHitList(
const HoughHitList& houghhitlist){
770 int num_first_half=0;
771 vector<double> vtemp,utemp;
772 double k,b,theta,rho,x_cross,y_cross;
773 std::vector<HoughHit>::const_iterator
iter = houghhitlist.
getList().begin();
775 int exit_multiturn=0;
784 m_u[iHit] = h.
getU();
785 m_v[iHit] = h.
getV();
787 m_r[iHit] = h.
getR();
797 if ( type <0 ) type=1;
810 m_nSig_Axial=nsig_axial;
811 m_exit_multiturn = exit_multiturn;
814 Leastfit(utemp,vtemp,k,b);
817 x_cross = -b/(k+1/k);
819 rho=sqrt(x_cross*x_cross+y_cross*y_cross);
820 theta=atan2(y_cross,x_cross);
832 m_nHit = num_first_half;
835void MdcHoughFinder::dumpHoughMap(
const HoughMap& houghmap){
912void MdcHoughFinder::diffMap(
const HoughMap& houghmap,
const HoughMap& houghmap2){
937void MdcHoughFinder::Leastfit(vector<double> u,vector<double>
v,
double& k ,
double& b){
940 double *
x=
new double[N];
941 double *y=
new double[N];
942 for(
int i=0;i<N;i++){
947 TF1 *fpol1=
new TF1(
"fpol1",
"pol1",-50,50);
948 TGraph *tg=
new TGraph(N,x,y);
949 tg->Fit(
"fpol1",
"QN");
950 double ktemp =fpol1->GetParameter(1);
951 double btemp =fpol1->GetParameter(0);
964int MdcHoughFinder::storeTracks(
RecMdcTrackCol*& trackList_tds ,
RecMdcHitCol*& hitList_tds,vector<RecMdcTrack*>& vec_trackPatTds){
965 MsgStream log(
msgSvc(), name());
968 DataObject *aTrackCol;
969 DataObject *aRecHitCol;
970 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
971 if(!m_combineTracking){
972 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
973 if(aTrackCol != NULL) {
974 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
975 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
977 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
978 if(aRecHitCol != NULL) {
979 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
980 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
985 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
991 if(!sc.isSuccess()) {
992 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
993 return StatusCode::FAILURE;
997 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
1003 if(!sc.isSuccess()) {
1004 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
1005 return StatusCode::FAILURE;
1009 if(m_removeBadTrack && m_combineTracking) {
1010 if( m_debug>0 ) cout<<
"PATTSF collect "<<trackList_tds->size()<<
" track. "<<endl;
1011 if(trackList_tds->size()!=0){
1012 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1013 for(;iter_pat!=trackList_tds->end();iter_pat++){
1014 double d0=(*iter_pat)->helix(0);
1015 double kap = (*iter_pat)->helix(2);
1016 double pt = 0.00001;
1017 if(fabs(kap)>0.00001) pt = fabs(1./kap);
1018 double dz=(*iter_pat)->helix(3);
1019 double chi2=(*iter_pat)->chi2();
1020 if( m_debug>0) cout<<
"d0: "<<d0<<
" z0: "<<dz<<
" pt "<<pt<<
" chi2 "<<chi2<<endl;
1022 if( pt<=m_dropTrkPtCut ){
1023 vec_trackPatTds.push_back(*iter_pat);
1025 HitRefVec rechits = (*iter_pat)->getVecHits();
1026 HitRefVec::iterator hotIter = rechits.begin();
1027 while (hotIter!=rechits.end()) {
1031 if(m_debug>0) cout <<
"remove hit " << (*hotIter)->getId()<<
"("<<layer<<
","<<wire<<
")"<<endl;
1032 hitList_tds->remove(*hotIter);
1040 if( m_debug>0 ) cout<<
"after delete trackcol size : "<<trackList_tds->size()<<endl;
1043 if(m_debug>0) cout<<
" PATTSF find 0 track. "<<endl;
1047 int nTdsTk=trackList_tds->size();
1052 cout<<
"length in clearMem "<<list1.length()<<
" "<<list2.length()<<endl;
1057 for(
unsigned int j=0;j<list1.length();j++){
1058 cout<<
"-i j "<<i<<
" "<<j<<
" "<<
vectrk_for_clean[i]<<
" "<<&(list1[j]->track())<<endl;
1059 if(
vectrk_for_clean[i] == &(list1[j]->track()) ) {sametrk=1;cout<<
"not delete new trk "<<endl;}
1062 for(
unsigned int k=0;k<list2.length();k++){
1063 cout<<
"+i k "<<i<<
" "<<k<<
" "<<
vectrk_for_clean[i]<<
" "<<&(list2[k]->track())<<endl;
1064 if(
vectrk_for_clean[i] == &(list2[k]->track()) ) {sametrk=1;cout<<
"not delete new trk "<<endl;}
1068 cout<<
"delete i "<<i<<endl;
1077 if(m_debug>0) cout<<
"in judgeChargeTrack"<<endl;
1078 if(m_debug>0) cout<<
"ntrack length neg : "<<list1.length()<<endl;
1079 if(m_debug>0) cout<<
"ntrack length pos : "<<list2.length()<<endl;
1080 for(
int itrack1=0; itrack1<list1.
nTrack(); itrack1++){
1081 MdcTrack* track_1 = list1[itrack1];
1083 double d0_1 = par1.
d0();
1084 double phi0_1 = par1.
phi0();
1085 double omega_1 = par1.
omega();
1086 double cr=fabs(1./par1.
omega());
1088 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1089 double z0_1 = par1.
z0();
1090 for(
int itrack2=0; itrack2<list2.
nTrack(); itrack2++){
1091 MdcTrack* track_2 = list2[itrack2];
1093 double d0_2 = par2.
d0();
1094 double phi0_2 = par2.
phi0();
1095 double omega_2 = par2.
omega();
1096 double cR=fabs(1./par2.
omega());
1098 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1099 double z0_2= par2.
z0();
1101 double bestDiff = 1.0e+20;
1102 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1103 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1104 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1105 if(diff < bestDiff){
1111 if(bestDiff != 1.0e20) {
1113 cout<<
"There is ambiguous +- charge in the track list "<<endl;
1114 cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1117 if( fabs(z0_1) >= fabs(z0_2) ) { list1.
remove( track_1 ); itrack1--;
break;}
1118 if( fabs(z0_1) < fabs(z0_2) ) { list2.
remove( track_2 ); itrack2--;
break;}
1120 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no (+-) track in hough"<<endl; }
1125void MdcHoughFinder::compareHough(
MdcTrackList& mdcTrackList){
1126 if(m_debug>0) cout<<
"in compareHough "<<endl;
1127 if(m_debug>0) cout<<
"ntrack : "<<mdcTrackList.length()<<endl;
1128 for(
int itrack=0; itrack<mdcTrackList.length(); itrack++){
1129 MdcTrack* track = mdcTrackList[itrack];
1132 double pt = (1./par.
omega())/333.567;
1133 if(m_debug>0) cout<<
"i Track : "<<itrack<<
" nHit: "<<nhit<<
" pt: "<<pt<<endl;
1137 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1138 MdcTrack* track_1 = mdcTrackList[itrack1];
1141 double d0_1 = par1.
d0();
1142 double phi0_1 = par1.
phi0();
1143 double omega_1 = par1.
omega();
1144 double z0_1= par1.
z0();
1145 double cr=fabs(1./par1.
omega());
1147 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1148 if(m_debug>0) cout<<
"circle 1 : "<<cr<<
","<<cx<<
","<<cy<<endl;
1150 for(
int itrack2=itrack1+1; itrack2<mdcTrackList.length(); itrack2++){
1151 MdcTrack* track_2 = mdcTrackList[itrack2];
1154 double d0_2 = par2.
d0();
1155 double phi0_2 = par2.
phi0();
1156 double omega_2 = par2.
omega();
1157 double z0_2= par2.
z0();
1158 double cR=fabs(1./par2.
omega());
1160 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1161 if(m_debug>0) cout<<
"circle 2 : "<<cR<<
","<<cX<<
","<<cY<<endl;
1163 double bestDiff = 1.0e+20;
1164 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1165 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1166 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1167 if(diff < bestDiff){
1173 double zdiff = z0_1-z0_2;
1174 if(bestDiff != 1.0e20 && fabs(zdiff)<25.){
1175 if(m_debug>0) cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1177 if( nhit1<nhit2 && (fabs(z0_1)>fabs(z0_2) && fabs(z0_1)>m_z0Cut_compareHough) ){
1178 if(m_debug>0) cout<<
"remove track1 "<<1./par1.
omega()/333.567<<endl;
1180 mdcTrackList.
remove( track_1 );
1186 if(m_debug>0) cout<<
"remove track2 "<<1./par2.
omega()/333.567<<endl;
1188 mdcTrackList.
remove( track_2 );
1192 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no same track in hough"<<endl; }
1205 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1206 MdcTrack* track_1 = mdcTrackList[itrack1];
1209 double d0_1 = par1.
d0();
1210 double phi0_1 = par1.
phi0();
1211 double omega_1 = par1.
omega();
1212 double z0_1= par1.
z0();
1213 double cr=fabs(1./par1.
omega());
1215 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1218 double bestDiff = 1.0e+20;
1219 double ptDiff = 0.0;
1221 vector<double> a0,a1,a2,a3,a4;
1222 RecMdcTrackCol::iterator iterBest;
1223 RecMdcTrackCol::iterator iteritrk = trackList_tds->begin();
1225 for(;iteritrk!=trackList_tds->end();iteritrk++){
1226 if(m_debug>0) cout<<
"being pattsf trk "<<itrk<<endl;
1227 double pt=(*iteritrk)->pxy();
1228 a0.push_back( (*iteritrk)->helix(0) );
1229 a1.push_back( (*iteritrk)->helix(1) );
1230 a2.push_back( (*iteritrk)->helix(2) );
1231 a3.push_back( (*iteritrk)->helix(3) );
1232 a4.push_back( (*iteritrk)->helix(4) );
1233 cR=(-333.567)/a2[itrk];
1234 cX=(cR+a0[itrk])*
cos(a1[itrk]);
1235 cY=(cR+a0[itrk])*
sin(a1[itrk]);
1238 cout<<
" compare PATTSF and HOUGH "<<endl;
1239 cout<<
" fabs(cX) "<< fabs(cX)<<
"fabs(cx) "<<fabs(cx)<<endl;
1240 cout<<
" fabs(cY) "<< fabs(cY)<<
"fabs(cy) "<<fabs(cy)<<endl;
1241 cout<<
" fabs(cR) "<< fabs(cR)<<
"fabs(cr) "<<fabs(cr)<<endl;
1242 cout<<
" fabs(cx-cX) "<< fabs(cx-cX)<<
"fabs(cy-cY) "<<fabs(cy-cY)<<
" fabs(cr-cR) "<< fabs(cr-cR)<<endl;
1245 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1246 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1247 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1248 if(m_debug>0) cout<<
" diff "<<diff<<
" pt "<<pt<<endl;
1249 if( fabs(pt) > ptDiff){
1263 if(bestDiff != 1.0e20) {
1264 if(m_debug>0) cout<<
" same track pattsf & hough , then compare nhit. "<<endl;
1265 double d0_pattsf =(*iterBest)->helix(0);
1266 double z0_pattsf =(*iterBest)->helix(3);
1267 double d0_hough = d0_1;
1268 double z0_hough = z0_1;
1269 int use_pattsf(1),use_hough(1);
1270 if( fabs(d0_pattsf)>m_dropTrkDrCut || fabs(z0_pattsf)>m_dropTrkDzCut ) use_pattsf=0;
1271 if( fabs(d0_hough)>m_dropTrkDrCut || fabs(z0_hough)>m_dropTrkDzCut ) use_hough=0;
1272 if( use_pattsf==0 && use_hough==1 ) {
1273 trackList_tds->remove(*iterBest);
1274 if(m_debug>0) cout<<
" use houghTrack, vertex pattsf wrong"<<endl;
1276 if( use_pattsf==1 && use_hough==0 ) {
1277 mdcTrackList.
remove( track_1 );
1279 if(m_debug>0) cout<<
" use pattsfTrack, vertex hough wrong"<<endl;
1281 if( (use_pattsf==0 && use_hough==0) || (use_pattsf==1 && use_hough==1) ){
1282 int nhit_pattsf=( (*iterBest)->ndof()+5 );
1283 int nhit_hough = nhit1;
1284 if(m_debug>0) cout<<
" nhit "<<nhit_pattsf<<
" "<<nhit_hough<<endl;
1285 if( nhit_pattsf>nhit_hough ) {
1286 mdcTrackList.
remove( track_1 );
1288 if(m_debug>0) cout<<
" use pattsfTrack "<<endl;
1291 trackList_tds->remove(*iterBest);
1292 if(m_debug>0) cout<<
" use houghTrack "<<endl;
1307 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no same track in pattsf"<<endl; }
1312 if(trackList_tds->size()!=0){
1314 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1315 for(;iter_pat!=trackList_tds->end();iter_pat++,digi++){
1316 (*iter_pat)->setTrackId(digi);
1320 return trackList_tds->size();
1323int MdcHoughFinder::judgeHit(
MdcTrackList& list,vector<MdcTrack*>& trackCol){
1324 if(m_debug>0) cout<<
"in judgHit: "<<endl;
1325 for(
unsigned int i =0;i<trackCol.size();i++){
1328 list.append(trackCol[i]);
1334 MsgStream log(
msgSvc(), name());
1335 NTuplePtr nt1(
ntupleSvc(),
"MdcHoughFinder/evt");
1339 ntuple_evt =
ntupleSvc()->book(
"MdcHoughFinder/evt", CLID_ColumnWiseTuple,
"evt");
1341 ntuple_evt->addItem(
"eventNum", m_eventNum);
1342 ntuple_evt->addItem(
"runNum", m_runNum);
1344 ntuple_evt->addItem(
"nHit", m_nHit,0, 6796);
1413 ntuple_evt->addItem(
"nMapPk", m_nMapPk, 0,100);
1459 ntuple_evt->addItem(
"time", m_time);
1461 }
else { log << MSG::ERROR <<
"Cannot book tuple MdcHoughFinder/hough" <<endmsg;
1462 return StatusCode::FAILURE;
1509 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
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 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