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"
58#include "GaudiKernel/IPartPropSvc.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(
"pdtFile", m_pdtFile =
"pdt.table");
124 declareProperty(
"eventFile", m_evtFile=
"EventList");
133 return StatusCode::SUCCESS;
139 MsgStream log(
msgSvc(), name());
140 log << MSG::INFO <<
"in initialize()" << endreq;
145 IPartPropSvc* p_PartPropSvc;
146 static const bool CREATEIFNOTTHERE(
true);
147 sc = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
148 if (!sc.isSuccess() || 0 == p_PartPropSvc) {
149 log << MSG::ERROR <<
" Could not initialize PartPropSvc" << endreq;
152 m_particleTable = p_PartPropSvc->PDT();
156 sc = service (
"RawDataProviderSvc", irawDataProviderSvc);
158 if ( sc.isFailure() ){
159 log << MSG::FATAL << name()<<
" Could not load RawDataProviderSvc!" << endreq;
160 return StatusCode::FAILURE;
165 sc = service (
"MdcGeomSvc", imdcGeomSvc);
166 m_mdcGeomSvc =
dynamic_cast<MdcGeomSvc*
> (imdcGeomSvc);
167 if ( sc.isFailure() ){
168 log << MSG::FATAL <<
"Could not load MdcGeoSvc!" << endreq;
169 return StatusCode::FAILURE;
173 sc = service (
"MagneticFieldSvc",m_pIMF);
174 if(sc!=StatusCode::SUCCESS) {
175 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
177 m_bfield =
new BField(m_pIMF);
178 log << MSG::INFO <<
"field z = "<<m_bfield->
bFieldNominal()<< endreq;
186 sc = service (
"MdcCalibFunSvc", imdcCalibSvc);
188 if ( sc.isFailure() ){
189 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endreq;
190 return StatusCode::FAILURE;
195 sc = service (
"MdcPrintSvc", imdcPrintSvc);
196 m_mdcPrintSvc =
dynamic_cast<MdcPrintSvc*
> (imdcPrintSvc);
197 if ( sc.isFailure() ){
198 log << MSG::FATAL <<
"Could not load MdcPrintSvc!" << endreq;
199 return StatusCode::FAILURE;
203 sc = service(
"BesTimerSvc", m_timersvc);
204 if( sc.isFailure() ) {
205 log << MSG::WARNING <<
" Unable to locate BesTimerSvc" << endreq;
206 return StatusCode::FAILURE;
208 m_timer_all = m_timersvc->
addItem(
"Execution");
209 m_timer_all->
propName(
"nExecution");
235 if ( sc.isFailure() ){
236 log << MSG::FATAL <<
"Could not book Tuple !" << endreq;
237 return StatusCode::FAILURE;
239 return StatusCode::SUCCESS;
245 MsgStream log(
msgSvc(), name());
246 log << MSG::INFO <<
"in execute()" << endreq;
250 m_timer_all->
start();
253 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
255 log << MSG::WARNING <<
"Could not find EvTimeCol" << endreq;
256 return StatusCode::SUCCESS;
258 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
259 if (iter_evt != evTimeCol->end()){
260 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
266 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
268 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
269 return StatusCode::FAILURE;
272 t_eventNum=eventHeader->eventNumber();
273 t_runNum=eventHeader->runNumber();
275 m_eventNum=eventHeader->eventNumber();
276 m_runNum=eventHeader->runNumber();
278 if(m_debug>0) cout<<
"begin evt "<<eventHeader->eventNumber()<<endl;
283 vector<RecMdcTrack*> vec_trackPatTds;
284 int nTdsTk = storeTracks(trackList_tds,hitList_tds,vec_trackPatTds);
287 RecMdcTrackCol::iterator iteritrk_pattsf = vec_trackPatTds.begin();
288 for(;iteritrk_pattsf!=vec_trackPatTds.end();iteritrk_pattsf++){
289 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;
295 if(m_debugArbHit>0 ) m_par.
lPrint=8;
305 lowPt_Evt.open(m_evtFile.c_str());
308 while( lowPt_Evt >> evtNum) {
309 evtlist.push_back(evtNum);
311 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),t_eventNum);
312 if( iter_evt == evtlist.end() ) { setFilterPassed(
false);
return StatusCode::SUCCESS; }
313 else setFilterPassed(
true);
316 if(m_inputType == -1) GetMcInfo();
319 if(m_debug>0) cout<<
"step1 : prepare digi "<<endl;
323 bool debugTruth =
false;
324 if(m_inputType == -1) debugTruth=
true;
325 if(m_debug>0) cout<<
"step2 : hits-> hough hit list "<<endl;
328 if( houghHitList.
nHit() < 10 || houghHitList.
nHit()>500 )
return StatusCode::SUCCESS;
329 if(m_debug>0) houghHitList.
printAll();
332 vector<MdcHit*> mdcHitCol_neg;
333 vector<MdcHit*> mdcHitCol_pos;
334 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
335 for (;
iter != mdcDigiVec.end();
iter++) {
337 if(
HoughHit(digi).driftTime()>1000 ||
HoughHit(digi).driftTime()<=0 )
continue;
340 mdcHitCol_neg.push_back(mdcHit);
341 mdcHitCol_pos.push_back(mdcHit_pos);
344 HoughMap *m_map =
new HoughMap(-1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);
347 if(m_hist) m_nHit = houghHitList.
nHit();
348 if(m_hist) dumpHoughMap(*m_map);
351 if(m_debug>0) cout<<
"step3 : neg track list "<<endl;
352 vector<HoughTrack*> vec_track_neg;
353 vector<HoughTrack*> vec_track2D_neg;
358 vector< vector<int> > stat_2d(2,vector<int>(trackList_size,0) );
359 vector< vector<int> > stat_3d(2,vector<int>(trackList_size,0) );
362 for(
int itrack=0;itrack<trackList_size;itrack++){
363 if(m_debug>0) cout<<
"begin track: "<<itrack<<endl;
365 if(m_debug>0) cout<<
" suppose charge -1 "<<endl;
370 stat_2d[0][itrack] = track_neg.
fit2D(m_bunchT0);
372 if(m_debug>0) cout<<
" charge -1 stat2d "<<stat_2d[0][itrack]<<
" "<<track_charge_2d<<endl;
373 if( stat_2d[0][itrack] == 0 || track_charge_2d ==0 )
continue;
383 if(m_debug>0) cout<<
" nhitstereo -1 "<<nHit3d<<
" "<<track_charge_3d<<endl;
384 if( nHit3d <3 || track_charge_3d==0 )
continue;
387 if( npair==0 ) stat_3d[0][itrack] = track_neg.
fit3D();
391 if(m_debug>0) cout<<
" charge -1 stat3d "<<stat_3d[0][itrack]<<
" "<<endl;
392 if( stat_3d[0][itrack]==0 )
continue;
393 vec_track_neg.push_back( &track_neg );
493 std::sort ( vec_track_neg.begin(),vec_track_neg.end(),
more_pt);
495 vector<MdcTrack*> vec_MdcTrack_neg;
496 for(
unsigned int i =0;i<vec_track_neg.size();i++){
498 vec_MdcTrack_neg.push_back(mdcTrack);
499 if(m_debug>0) cout<<
"trackneg: "<<i<<
" pt "<<vec_track_neg[i]->getPt3D()<<endl;
500 if(m_debug>0) vec_track_neg[i]->print();
502 if(m_debug>0) cout<<
"step4 : judge neg track list "<<endl;
503 judgeHit(mdcTrackList_neg,vec_MdcTrack_neg);
504 if(m_debug>0) cout<<
"finish - charge "<<endl;
509 HoughMap *m_map2 =
new HoughMap(1,houghHitList,m_mapHit,m_nBinTheta,m_nBinRho,-1.*m_rhoRange,m_rhoRange,m_peakWidth,m_peakHigh,m_hitPro);
510 if(m_debug>0) cout<<
"step5 : pos track list "<<endl;
511 vector<HoughTrack*> vec_track_pos;
516 vector< vector<int> > stat_2d2(2,vector<int>(tracklist_size2,0) );
517 vector< vector<int> > stat_3d2(2,vector<int>(tracklist_size2,0) );
520 for(
int itrack=0;itrack<tracklist_size2;itrack++){
522 if(m_debug>0) cout<<
" suppose charge +1 "<<endl;
527 stat_2d2[0][itrack] = track_pos.
fit2D(m_bunchT0);
529 if(m_debug>0) cout<<
" charge +1 stat2d "<<stat_2d2[1][itrack]<<
" "<<track_charge_2d<<endl;
530 if( stat_2d2[0][itrack] == 0 || track_charge_2d==0 )
continue;
539 if(m_debug>0) cout<<
" nhitstereo +1 "<<nHit3d<<
" "<<track_charge_3d<<endl;
542 if( npair==0 ) stat_3d2[0][itrack] = track_pos.
fit3D();
543 else stat_3d2[0][itrack] = track_pos.
fit3D_inner();
546 if(m_debug>0) cout<<
" charge +1 stat3d "<<stat_3d2[1][itrack]<<
" "<<endl;
547 if( stat_3d2[0][itrack]==0 )
continue;
548 vec_track_pos.push_back( &track_pos );
554 std::sort ( vec_track_pos.begin(),vec_track_pos.end(),
more_pt);
557 vector<MdcTrack*> vec_MdcTrack_pos;
558 for(
unsigned int i =0;i<vec_track_pos.size();i++){
560 vec_MdcTrack_pos.push_back(mdcTrack);
561 if(m_debug>0) cout<<
"trackpos : "<<i<<
" pt "<<vec_track_pos[i]->getPt3D()<<endl;
562 if(m_debug>0) vec_track_pos[i]->print();
564 if(m_debug>0) cout<<
"step6 : judge pos track list "<<endl;
565 judgeHit(mdcTrackList_pos,vec_MdcTrack_pos);
571 compareHough(mdcTrackList_neg);
572 compareHough(mdcTrackList_pos);
574 if( mdcTrackList_neg.length()!=0 && mdcTrackList_pos.length()!=0 ) judgeChargeTrack(mdcTrackList_neg,mdcTrackList_pos);
576 mdcTrackList_neg+=mdcTrackList_pos;
579 if(m_combineTracking) nTdsTk = comparePatTsf(mdcTrackList_neg,trackList_tds);
582 if(m_debug>0) cout<<
"step8 : store tds "<<endl;
583 if(m_debug>0) cout<<
"store tds "<<endl;
585 for(
unsigned int i =0;i<mdcTrackList_neg.length();i++){
586 if(m_debug>0) cout<<
"- charge size i : "<<i<<
" "<<mdcTrackList_neg.length()<<endl;
588 mdcTrackList_neg[i]->storeTrack(tkId, trackList_tds, hitList_tds, tkStat);
590 delete mdcTrackList_neg[i];
595 double t_teventTime = m_timer_all->
elapsed();
596 if(m_hist) m_time = t_teventTime;
598 if( m_hist ) ntuple_evt->write();
602 if(m_debug>0) cout<<
"after delete map "<<endl;
603 for(
int ihit=0;ihit<mdcHitCol_neg.size();ihit++){
604 delete mdcHitCol_neg[ihit];
605 delete mdcHitCol_pos[ihit];
608 if(m_debug>0) cout<<
"after delete hit"<<endl;
610 if(m_debug>0) cout<<
"end event "<<endl;
612 return StatusCode::SUCCESS;
617 MsgStream log(
msgSvc(), name());
619 log << MSG::INFO<<
"in finalize()" << endreq;
621 return StatusCode::SUCCESS;
624int MdcHoughFinder::GetMcInfo(){
625 MsgStream log(
msgSvc(), name());
627 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
628 if (!mcParticleCol) {
629 log << MSG::ERROR <<
"Could not find McParticle" << endreq;
630 return StatusCode::FAILURE;
634 g_tkParTruth.clear();
638 int t_pidTruth = -999;
640 McParticleCol::iterator iter_mc = mcParticleCol->begin();
641 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
642 t_pidTruth = (*iter_mc)->particleProperty();
644 if(!(*iter_mc)->primaryParticle())
continue;
648 int pid = t_pidTruth;
650 log << MSG::WARNING <<
"Wrong particle id" <<endreq;
653 IPartPropSvc* p_PartPropSvc;
654 static const bool CREATEIFNOTTHERE(
true);
655 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
656 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
657 std::cout<<
" Could not initialize Particle Properties Service" << std::endl;
659 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
660 if( p_particleTable->particle(pid) ){
661 name = p_particleTable->particle(pid)->name();
662 t_qTruth = p_particleTable->particle(pid)->charge();
663 }
else if( p_particleTable->particle(-pid) ){
664 name =
"anti " + p_particleTable->particle(-pid)->name();
665 t_qTruth = (-1)*p_particleTable->particle(-pid)->charge();
670 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;
671 Helix mchelix =
Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qTruth);
674 int mcTkId = (*iter_mc)->trackIndex();
676 pair<int, const HepVector> p(mcTkId,mchelix.
a());
677 g_tkParTruth.insert(p);
681 else {rho =1./fabs(mchelix.
radius()) ; theta = mchelix.
phi0();}
686 t_tanl=mchelix.
tanl();
705 m_pidTruth = t_pidTruth;
707 m_ptTruth = mchelix.
pt();
708 m_pTruth = mchelix.
momentum(0.).mag();
710 m_drTruth = mchelix.
dr();
711 m_phi0Truth = mchelix.
phi0();
712 m_omegaTruth =1./(mchelix.
radius());
713 m_dzTruth = mchelix.
dz();
714 m_tanl_mc =mchelix.
tanl();
731 g_firstHit.set(0,0,0);
732 SmartDataPtr<MdcMcHitCol> mdcMcHitCol(eventSvc(),
"/Event/MC/MdcMcHitCol");
734 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
735 for (;iter_mchit != mdcMcHitCol->end(); iter_mchit++) {
736 if((*iter_mchit)->getTrackIndex()==0) {
737 g_firstHit.setX((*iter_mchit)->getPositionX()/10.);
738 g_firstHit.setY((*iter_mchit)->getPositionY()/10.);
739 g_firstHit.setZ((*iter_mchit)->getPositionZ()/10.);
744 std::cout<<__FILE__<<
" Could not get MdcMcHitCol "<<std::endl;
745 return StatusCode::FAILURE;
749 return StatusCode::SUCCESS;
754 uint32_t getDigiFlag = 0;
763void MdcHoughFinder::dumpHoughHitList(
const HoughHitList& houghhitlist){
765 int num_first_half=0;
766 vector<double> vtemp,utemp;
767 double k,
b,theta,rho,x_cross,y_cross;
768 std::vector<HoughHit>::const_iterator
iter = houghhitlist.
getList().begin();
770 int exit_multiturn=0;
779 m_u[iHit] = h.
getU();
780 m_v[iHit] = h.
getV();
782 m_r[iHit] = h.
getR();
792 if ( type <0 ) type=1;
805 m_nSig_Axial=nsig_axial;
806 m_exit_multiturn = exit_multiturn;
809 Leastfit(utemp,vtemp,k,
b);
812 x_cross = -
b/(k+1/k);
814 rho=sqrt(x_cross*x_cross+y_cross*y_cross);
815 theta=atan2(y_cross,x_cross);
827 m_nHit = num_first_half;
830void MdcHoughFinder::dumpHoughMap(
const HoughMap& houghmap){
907void MdcHoughFinder::diffMap(
const HoughMap& houghmap,
const HoughMap& houghmap2){
932void MdcHoughFinder::Leastfit(vector<double> u,vector<double>
v,
double& k ,
double&
b){
935 double *
x=
new double[N];
936 double *
y=
new double[N];
937 for(
int i=0;i<N;i++){
942 TF1 *fpol1=
new TF1(
"fpol1",
"pol1",-50,50);
943 TGraph *tg=
new TGraph(N,x,
y);
944 tg->Fit(
"fpol1",
"QN");
945 double ktemp =fpol1->GetParameter(1);
946 double btemp =fpol1->GetParameter(0);
959int MdcHoughFinder::storeTracks(
RecMdcTrackCol*& trackList_tds ,
RecMdcHitCol*& hitList_tds,vector<RecMdcTrack*>& vec_trackPatTds){
960 MsgStream log(
msgSvc(), name());
963 DataObject *aTrackCol;
964 DataObject *aRecHitCol;
965 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
966 if(!m_combineTracking){
967 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
968 if(aTrackCol !=
NULL) {
969 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
970 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
972 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
973 if(aRecHitCol !=
NULL) {
974 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
975 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
980 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
986 if(!sc.isSuccess()) {
987 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
988 return StatusCode::FAILURE;
992 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
998 if(!sc.isSuccess()) {
999 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
1000 return StatusCode::FAILURE;
1004 if(m_removeBadTrack && m_combineTracking) {
1005 if( m_debug>0 ) cout<<
"PATTSF collect "<<trackList_tds->size()<<
" track. "<<endl;
1006 if(trackList_tds->size()!=0){
1007 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1008 for(;iter_pat!=trackList_tds->end();iter_pat++){
1009 double d0=(*iter_pat)->helix(0);
1010 double kap = (*iter_pat)->helix(2);
1011 double pt = 0.00001;
1012 if(fabs(kap)>0.00001) pt = fabs(1./kap);
1013 double dz=(*iter_pat)->helix(3);
1014 double chi2=(*iter_pat)->chi2();
1015 if( m_debug>0) cout<<
"d0: "<<d0<<
" z0: "<<dz<<
" pt "<<pt<<
" chi2 "<<chi2<<endl;
1017 if( pt<=m_dropTrkPtCut ){
1018 vec_trackPatTds.push_back(*iter_pat);
1020 HitRefVec rechits = (*iter_pat)->getVecHits();
1021 HitRefVec::iterator hotIter = rechits.begin();
1022 while (hotIter!=rechits.end()) {
1026 if(m_debug>0) cout <<
"remove hit " << (*hotIter)->getId()<<
"("<<layer<<
","<<wire<<
")"<<endl;
1027 hitList_tds->remove(*hotIter);
1035 if( m_debug>0 ) cout<<
"after delete trackcol size : "<<trackList_tds->size()<<endl;
1038 if(m_debug>0) cout<<
" PATTSF find 0 track. "<<endl;
1042 int nTdsTk=trackList_tds->size();
1047 cout<<
"length in clearMem "<<list1.length()<<
" "<<list2.length()<<endl;
1052 for(
unsigned int j=0;j<list1.length();j++){
1053 cout<<
"-i j "<<i<<
" "<<j<<
" "<<
vectrk_for_clean[i]<<
" "<<&(list1[j]->track())<<endl;
1054 if(
vectrk_for_clean[i] == &(list1[j]->track()) ) {sametrk=1;cout<<
"not delete new trk "<<endl;}
1057 for(
unsigned int k=0;k<list2.length();k++){
1058 cout<<
"+i k "<<i<<
" "<<k<<
" "<<
vectrk_for_clean[i]<<
" "<<&(list2[k]->track())<<endl;
1059 if(
vectrk_for_clean[i] == &(list2[k]->track()) ) {sametrk=1;cout<<
"not delete new trk "<<endl;}
1063 cout<<
"delete i "<<i<<endl;
1072 if(m_debug>0) cout<<
"in judgeChargeTrack"<<endl;
1073 if(m_debug>0) cout<<
"ntrack length neg : "<<list1.length()<<endl;
1074 if(m_debug>0) cout<<
"ntrack length pos : "<<list2.length()<<endl;
1075 for(
int itrack1=0; itrack1<list1.
nTrack(); itrack1++){
1076 MdcTrack* track_1 = list1[itrack1];
1078 double d0_1 = par1.
d0();
1079 double phi0_1 = par1.
phi0();
1080 double omega_1 = par1.
omega();
1081 double cr=fabs(1./par1.
omega());
1083 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1084 double z0_1 = par1.
z0();
1085 for(
int itrack2=0; itrack2<list2.
nTrack(); itrack2++){
1086 MdcTrack* track_2 = list2[itrack2];
1088 double d0_2 = par2.
d0();
1089 double phi0_2 = par2.
phi0();
1090 double omega_2 = par2.
omega();
1091 double cR=fabs(1./par2.
omega());
1093 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1094 double z0_2= par2.
z0();
1096 double bestDiff = 1.0e+20;
1097 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1098 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1099 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1100 if(diff < bestDiff){
1106 if(bestDiff != 1.0e20) {
1108 cout<<
"There is ambiguous +- charge in the track list "<<endl;
1109 cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1112 if( fabs(z0_1) >= fabs(z0_2) ) { list1.
remove( track_1 ); itrack1--;
break;}
1113 if( fabs(z0_1) < fabs(z0_2) ) { list2.
remove( track_2 ); itrack2--;
break;}
1115 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no (+-) track in hough"<<endl; }
1120void MdcHoughFinder::compareHough(
MdcTrackList& mdcTrackList){
1121 if(m_debug>0) cout<<
"in compareHough "<<endl;
1122 if(m_debug>0) cout<<
"ntrack : "<<mdcTrackList.length()<<endl;
1123 for(
int itrack=0; itrack<mdcTrackList.length(); itrack++){
1124 MdcTrack* track = mdcTrackList[itrack];
1127 double pt = (1./par.
omega())/333.567;
1128 if(m_debug>0) cout<<
"i Track : "<<itrack<<
" nHit: "<<nhit<<
" pt: "<<pt<<endl;
1132 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1133 MdcTrack* track_1 = mdcTrackList[itrack1];
1136 double d0_1 = par1.
d0();
1137 double phi0_1 = par1.
phi0();
1138 double omega_1 = par1.
omega();
1139 double z0_1= par1.
z0();
1140 double cr=fabs(1./par1.
omega());
1142 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1143 if(m_debug>0) cout<<
"circle 1 : "<<cr<<
","<<cx<<
","<<cy<<endl;
1145 for(
int itrack2=itrack1+1; itrack2<mdcTrackList.length(); itrack2++){
1146 MdcTrack* track_2 = mdcTrackList[itrack2];
1149 double d0_2 = par2.
d0();
1150 double phi0_2 = par2.
phi0();
1151 double omega_2 = par2.
omega();
1152 double z0_2= par2.
z0();
1153 double cR=fabs(1./par2.
omega());
1155 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1156 if(m_debug>0) cout<<
"circle 2 : "<<cR<<
","<<cX<<
","<<cY<<endl;
1158 double bestDiff = 1.0e+20;
1159 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1160 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1161 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1162 if(diff < bestDiff){
1168 double zdiff = z0_1-z0_2;
1169 if(bestDiff != 1.0e20 && fabs(zdiff)<25.){
1170 if(m_debug>0) cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1172 if( nhit1<nhit2 && (fabs(z0_1)>fabs(z0_2) && fabs(z0_1)>m_z0Cut_compareHough) ){
1173 if(m_debug>0) cout<<
"remove track1 "<<1./par1.
omega()/333.567<<endl;
1175 mdcTrackList.
remove( track_1 );
1181 if(m_debug>0) cout<<
"remove track2 "<<1./par2.
omega()/333.567<<endl;
1183 mdcTrackList.
remove( track_2 );
1187 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no same track in hough"<<endl; }
1200 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1201 MdcTrack* track_1 = mdcTrackList[itrack1];
1204 double d0_1 = par1.
d0();
1205 double phi0_1 = par1.
phi0();
1206 double omega_1 = par1.
omega();
1207 double z0_1= par1.
z0();
1208 double cr=fabs(1./par1.
omega());
1210 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1213 double bestDiff = 1.0e+20;
1214 double ptDiff = 0.0;
1216 vector<double> a0,a1,a2,a3,a4;
1217 RecMdcTrackCol::iterator iterBest;
1218 RecMdcTrackCol::iterator iteritrk = trackList_tds->begin();
1220 for(;iteritrk!=trackList_tds->end();iteritrk++){
1221 if(m_debug>0) cout<<
"being pattsf trk "<<itrk<<endl;
1222 double pt=(*iteritrk)->pxy();
1223 a0.push_back( (*iteritrk)->helix(0) );
1224 a1.push_back( (*iteritrk)->helix(1) );
1225 a2.push_back( (*iteritrk)->helix(2) );
1226 a3.push_back( (*iteritrk)->helix(3) );
1227 a4.push_back( (*iteritrk)->helix(4) );
1228 cR=(-333.567)/a2[itrk];
1229 cX=(cR+a0[itrk])*
cos(a1[itrk]);
1230 cY=(cR+a0[itrk])*
sin(a1[itrk]);
1233 cout<<
" compare PATTSF and HOUGH "<<endl;
1234 cout<<
" fabs(cX) "<< fabs(cX)<<
"fabs(cx) "<<fabs(cx)<<endl;
1235 cout<<
" fabs(cY) "<< fabs(cY)<<
"fabs(cy) "<<fabs(cy)<<endl;
1236 cout<<
" fabs(cR) "<< fabs(cR)<<
"fabs(cr) "<<fabs(cr)<<endl;
1237 cout<<
" fabs(cx-cX) "<< fabs(cx-cX)<<
"fabs(cy-cY) "<<fabs(cy-cY)<<
" fabs(cr-cR) "<< fabs(cr-cR)<<endl;
1240 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1241 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1242 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1243 if(m_debug>0) cout<<
" diff "<<diff<<
" pt "<<pt<<endl;
1244 if( fabs(pt) > ptDiff){
1258 if(bestDiff != 1.0e20) {
1259 if(m_debug>0) cout<<
" same track pattsf & hough , then compare nhit. "<<endl;
1260 double d0_pattsf =(*iterBest)->helix(0);
1261 double z0_pattsf =(*iterBest)->helix(3);
1262 double d0_hough = d0_1;
1263 double z0_hough = z0_1;
1264 int use_pattsf(1),use_hough(1);
1265 if( fabs(d0_pattsf)>m_dropTrkDrCut || fabs(z0_pattsf)>m_dropTrkDzCut ) use_pattsf=0;
1266 if( fabs(d0_hough)>m_dropTrkDrCut || fabs(z0_hough)>m_dropTrkDzCut ) use_hough=0;
1267 if( use_pattsf==0 && use_hough==1 ) {
1268 trackList_tds->remove(*iterBest);
1269 if(m_debug>0) cout<<
" use houghTrack, vertex pattsf wrong"<<endl;
1271 if( use_pattsf==1 && use_hough==0 ) {
1272 mdcTrackList.
remove( track_1 );
1274 if(m_debug>0) cout<<
" use pattsfTrack, vertex hough wrong"<<endl;
1276 if( (use_pattsf==0 && use_hough==0) || (use_pattsf==1 && use_hough==1) ){
1277 int nhit_pattsf=( (*iterBest)->ndof()+5 );
1278 int nhit_hough = nhit1;
1279 if(m_debug>0) cout<<
" nhit "<<nhit_pattsf<<
" "<<nhit_hough<<endl;
1280 if( nhit_pattsf>nhit_hough ) {
1281 mdcTrackList.
remove( track_1 );
1283 if(m_debug>0) cout<<
" use pattsfTrack "<<endl;
1286 trackList_tds->remove(*iterBest);
1287 if(m_debug>0) cout<<
" use houghTrack "<<endl;
1302 if(bestDiff == 1.0e20) {
if(m_debug>0) cout<<
" no same track in pattsf"<<endl; }
1307 if(trackList_tds->size()!=0){
1309 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1310 for(;iter_pat!=trackList_tds->end();iter_pat++,digi++){
1311 (*iter_pat)->setTrackId(digi);
1315 return trackList_tds->size();
1318int MdcHoughFinder::judgeHit(
MdcTrackList& list,vector<MdcTrack*>& trackCol){
1319 if(m_debug>0) cout<<
"in judgHit: "<<endl;
1320 for(
unsigned int i =0;i<trackCol.size();i++){
1323 list.append(trackCol[i]);
1329 MsgStream log(
msgSvc(), name());
1330 NTuplePtr nt1(
ntupleSvc(),
"MdcHoughFinder/evt");
1334 ntuple_evt =
ntupleSvc()->book(
"MdcHoughFinder/evt", CLID_ColumnWiseTuple,
"evt");
1336 ntuple_evt->addItem(
"eventNum", m_eventNum);
1337 ntuple_evt->addItem(
"runNum", m_runNum);
1339 ntuple_evt->addItem(
"nHit", m_nHit,0, 6796);
1408 ntuple_evt->addItem(
"nMapPk", m_nMapPk, 0,100);
1454 ntuple_evt->addItem(
"time", m_time);
1456 }
else { log << MSG::ERROR <<
"Cannot book tuple MdcHoughFinder/hough" <<endmsg;
1457 return StatusCode::FAILURE;
1504 return StatusCode::SUCCESS;
double sin(const BesAngle a)
double cos(const BesAngle a)
HepGeom::Point3D< double > HepPoint3D
vector< TrkRecoTrk * > vectrk_for_clean
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
**********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
std::vector< MdcDigi * > MdcDigiVec
ObjectVector< RecMdcHit > RecMdcHitCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
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