2#include "BesTimerSvc/BesTimer.h"
3#include "BesTimerSvc/IBesTimerSvc.h"
4#include "EvTimeEvent/RecEsTime.h"
5#include "EventModel/EventHeader.h"
6#include "GaudiKernel/IDataManagerSvc.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/INTupleSvc.h"
9#include "GaudiKernel/IPartPropSvc.h"
10#include "GaudiKernel/IService.h"
11#include "GaudiKernel/ISvcLocator.h"
12#include "GaudiKernel/MsgStream.h"
13#include "GaudiKernel/NTuple.h"
14#include "GaudiKernel/PropertyMgr.h"
15#include "GaudiKernel/SmartDataPtr.h"
18#include "Identifier/Identifier.h"
19#include "Identifier/MdcID.h"
20#include "McTruth/DecayMode.h"
21#include "McTruth/McParticle.h"
22#include "McTruth/MdcMcHit.h"
23#include "MdcData/MdcHit.h"
24#include "MdcData/MdcRecoHitOnTrack.h"
25#include "MdcGeom/EntranceAngle.h"
26#include "MdcPrintSvc/IMdcPrintSvc.h"
27#include "MdcRawEvent/MdcDigi.h"
28#include "MdcRecoUtil/Pdt.h"
29#include "MdcTrkRecon/MdcMap.h"
30#include "MdcxReco/Mdcxprobab.h"
31#include "RawEvent/RawDataUtil.h"
34#include "TrackUtil/Helix.h"
35#include "TrkBase/TrkExchangePar.h"
36#include "TrkBase/TrkFit.h"
37#include "TrkBase/TrkHitList.h"
38#include "TrkFitter/TrkCircleMaker.h"
39#include "TrkFitter/TrkHelixFitter.h"
40#include "TrkFitter/TrkHelixMaker.h"
41#include "TrkFitter/TrkLineMaker.h"
50 : Algorithm( name, pSvcLocator ) {
52 declareProperty(
"debug", m_debug = 0 );
53 declareProperty(
"debugMap", m_debugMap = 0 );
54 declareProperty(
"debug2D", m_debug2D = 0 );
55 declareProperty(
"debugTrack", m_debugTrack = 0 );
56 declareProperty(
"debugStereo", m_debugStereo = 0 );
57 declareProperty(
"debugZs", m_debugZs = 0 );
58 declareProperty(
"debug3D", m_debug3D = 0 );
59 declareProperty(
"debugArbHit", m_debugArbHit = 0 );
60 declareProperty(
"hist", m_hist = 1 );
61 declareProperty(
"filter", m_filter = 0 );
63 declareProperty(
"keepBadTdc", m_keepBadTdc = 0 );
64 declareProperty(
"dropHot", m_dropHot = 0 );
65 declareProperty(
"keepUnmatch", m_keepUnmatch = 0 );
67 declareProperty(
"combineTracking", m_combineTracking =
false );
68 declareProperty(
"removeBadTrack", m_removeBadTrack = 0 );
69 declareProperty(
"dropTrkDrCut", m_dropTrkDrCut = 1. );
70 declareProperty(
"dropTrkDzCut", m_dropTrkDzCut = 10. );
71 declareProperty(
"dropTrkPtCut", m_dropTrkPtCut = 0.12 );
72 declareProperty(
"dropTrkChi2Cut", m_dropTrkChi2Cut = 10000. );
74 declareProperty(
"inputType", m_inputType = 0 );
76 declareProperty(
"mapCharge", m_mapCharge = -1 );
77 declareProperty(
"useHalf", m_useHalf = 0 );
78 declareProperty(
"mapHitStyle", m_mapHit = 0 );
79 declareProperty(
"nbinTheta", m_nBinTheta = 100 );
80 declareProperty(
"nbinRho", m_nBinRho = 100 );
81 declareProperty(
"rhoRange", m_rhoRange = 0.1 );
82 declareProperty(
"peakWidth", m_peakWidth = 3 );
83 declareProperty(
"peakHigh", m_peakHigh = 1 );
84 declareProperty(
"hitPro", m_hitPro = 0.4 );
86 declareProperty(
"recpos", m_recpos = 1 );
87 declareProperty(
"recneg", m_recneg = 1 );
88 declareProperty(
"combineSelf", m_combine = 1 );
89 declareProperty(
"z0CutCompareHough", m_z0Cut_compareHough = 10 );
92 declareProperty(
"n1", m_npart = 100 );
93 declareProperty(
"n2", m_n2 = 16 );
95 declareProperty(
"pdtFile", m_pdtFile =
"pdt.table" );
96 declareProperty(
"eventFile", m_evtFile =
"EventList" );
104 return StatusCode::SUCCESS;
110 MsgStream log(
msgSvc(), name() );
111 log << MSG::INFO <<
"in initialize()" << endmsg;
116 IPartPropSvc* p_PartPropSvc;
117 static const bool CREATEIFNOTTHERE(
true );
118 sc = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE );
119 if ( !sc.isSuccess() || 0 == p_PartPropSvc )
121 log << MSG::ERROR <<
" Could not initialize PartPropSvc" << endmsg;
124 m_particleTable = p_PartPropSvc->PDT();
128 sc = service(
"RawDataProviderSvc", irawDataProviderSvc );
129 m_rawDataProviderSvc = irawDataProviderSvc;
130 if ( sc.isFailure() )
132 log << MSG::FATAL << name() <<
" Could not load RawDataProviderSvc!" << endmsg;
133 return StatusCode::FAILURE;
138 sc = service(
"MdcGeomSvc", imdcGeomSvc );
139 m_mdcGeomSvc = imdcGeomSvc;
140 if ( sc.isFailure() )
142 log << MSG::FATAL <<
"Could not load MdcGeoSvc!" << endmsg;
143 return StatusCode::FAILURE;
147 sc = service(
"MagneticFieldSvc", m_pIMF );
148 if ( sc != StatusCode::SUCCESS )
149 { log << MSG::ERROR <<
"Unable to open Magnetic field service" << endmsg; }
150 m_bfield =
new BField( m_pIMF );
151 log << MSG::INFO <<
"field z = " << m_bfield->bFieldNominal() << endmsg;
159 sc = service(
"MdcCalibFunSvc", imdcCalibSvc );
160 m_mdcCalibFunSvc = imdcCalibSvc;
161 if ( sc.isFailure() )
163 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endmsg;
164 return StatusCode::FAILURE;
169 sc = service(
"MdcPrintSvc", imdcPrintSvc );
170 m_mdcPrintSvc = imdcPrintSvc;
171 if ( sc.isFailure() )
173 log << MSG::FATAL <<
"Could not load MdcPrintSvc!" << endmsg;
174 return StatusCode::FAILURE;
178 sc = service(
"BesTimerSvc", m_timersvc );
179 if ( sc.isFailure() )
181 log << MSG::WARNING <<
" Unable to locate BesTimerSvc" << endmsg;
182 return StatusCode::FAILURE;
184 m_timer_all = m_timersvc->addItem(
"Execution" );
185 m_timer_all->propName(
"nExecution" );
210 if ( sc.isFailure() )
212 log << MSG::FATAL <<
"Could not book Tuple !" << endmsg;
213 return StatusCode::FAILURE;
215 return StatusCode::SUCCESS;
223 if ( sc.isFailure() )
225 error() <<
"beginRun failed" << endmsg;
226 return StatusCode::FAILURE;
231 MsgStream log(
msgSvc(), name() );
232 log << MSG::INFO <<
"in execute()" << endmsg;
235 m_timer_all->start();
238 SmartDataPtr<RecEsTimeCol> evTimeCol( eventSvc(),
"/Event/Recon/RecEsTimeCol" );
241 log << MSG::WARNING <<
"Could not find EvTimeCol" << endmsg;
242 return StatusCode::SUCCESS;
246 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
247 if ( iter_evt != evTimeCol->end() )
249 m_bunchT0 = ( *iter_evt )->getTest() * 1.e-9;
255 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(),
"/Event/EventHeader" );
258 log << MSG::FATAL <<
"Could not find Event Header" << endmsg;
259 return StatusCode::FAILURE;
262 t_eventNum = eventHeader->eventNumber();
263 t_runNum = eventHeader->runNumber();
266 m_eventNum = eventHeader->eventNumber();
267 m_runNum = eventHeader->runNumber();
269 if ( m_debug > 0 ) cout <<
"begin evt " << eventHeader->eventNumber() << endl;
274 vector<RecMdcTrack*> vec_trackPatTds;
275 int nTdsTk = storeTracks( trackList_tds, hitList_tds, vec_trackPatTds );
279 RecMdcTrackCol::iterator iteritrk_pattsf = vec_trackPatTds.begin();
280 for ( ; iteritrk_pattsf != vec_trackPatTds.end(); iteritrk_pattsf++ )
282 cout <<
"in PATTSF LOST: " << ( *iteritrk_pattsf )->helix( 0 ) <<
" "
283 << ( *iteritrk_pattsf )->helix( 1 ) <<
" " << ( *iteritrk_pattsf )->helix( 2 )
284 <<
" " << ( *iteritrk_pattsf )->helix( 3 ) <<
" "
285 << ( *iteritrk_pattsf )->helix( 4 ) <<
" chi2 " << ( *iteritrk_pattsf )->chi2()
292 if ( m_debugArbHit > 0 ) m_par.
lPrint = 8;
304 lowPt_Evt.open( m_evtFile.c_str() );
307 while ( lowPt_Evt >> evtNum ) { evtlist.push_back( evtNum ); }
308 vector<int>::iterator iter_evt = find( evtlist.begin(), evtlist.end(), t_eventNum );
309 if ( iter_evt == evtlist.end() )
311 setFilterPassed(
false );
312 return StatusCode::SUCCESS;
314 else setFilterPassed(
true );
317 if ( m_inputType == -1 ) GetMcInfo();
320 if ( m_debug > 0 ) cout <<
"step1 : prepare digi " << endl;
324 bool debugTruth =
false;
325 if ( m_inputType == -1 ) debugTruth =
true;
326 if ( m_debug > 0 ) cout <<
"step2 : hits-> hough hit list " << endl;
330 if ( houghHitList.
nHit() < 10 || houghHitList.
nHit() > 500 )
return StatusCode::SUCCESS;
331 if ( m_debug > 0 ) houghHitList.
printAll();
332 if ( debugTruth ) houghHitList.
addTruthInfo( g_tkParTruth );
334 vector<MdcHit*> mdcHitCol_neg;
335 vector<MdcHit*> mdcHitCol_pos;
336 MdcDigiVec::iterator
iter = mdcDigiVec.begin();
338 for ( ;
iter != mdcDigiVec.end();
iter++ )
340 const MdcDigi* digi = ( *iter );
341 if (
HoughHit( digi ).driftTime() > 1000 ||
HoughHit( digi ).driftTime() <= 0 )
continue;
344 mdcHitCol_neg.push_back( mdcHit );
345 mdcHitCol_pos.push_back( mdcHit_pos );
349 new HoughMap( -1, houghHitList, m_mapHit, m_nBinTheta, m_nBinRho, -1. * m_rhoRange,
350 m_rhoRange, m_peakWidth, m_peakHigh, m_hitPro );
353 if ( m_hist ) m_nHit = houghHitList.
nHit();
354 if ( m_hist ) dumpHoughMap( *m_map );
357 if ( m_debug > 0 ) cout <<
"step3 : neg track list " << endl;
358 vector<HoughTrack*> vec_track_neg;
359 vector<HoughTrack*> vec_track2D_neg;
366 vector<vector<int>> stat_2d( 2, vector<int>( trackList_size, 0 ) );
367 vector<vector<int>> stat_3d( 2, vector<int>( trackList_size, 0 ) );
370 for (
int itrack = 0; itrack < trackList_size; itrack++ )
372 if ( m_debug > 0 ) cout <<
"begin track: " << itrack << endl;
374 if ( m_debug > 0 ) cout <<
" suppose charge -1 " << endl;
379 stat_2d[0][itrack] = track_neg.
fit2D( m_bunchT0 );
382 cout <<
" charge -1 stat2d " << stat_2d[0][itrack] <<
" " << track_charge_2d << endl;
384 if ( stat_2d[0][itrack] == 0 || track_charge_2d == 0 )
continue;
394 if ( m_debug > 0 ) cout <<
" nhitstereo -1 " << nHit3d <<
" " << track_charge_3d << endl;
396 if ( nHit3d < 3 || track_charge_3d == 0 )
continue;
399 if ( npair == 0 ) stat_3d[0][itrack] = track_neg.
fit3D();
403 if ( m_debug > 0 ) cout <<
" charge -1 stat3d " << stat_3d[0][itrack] <<
" " << endl;
405 if ( stat_3d[0][itrack] == 0 )
continue;
406 vec_track_neg.push_back( &track_neg );
506 std::sort( vec_track_neg.begin(), vec_track_neg.end(),
more_pt );
508 vector<MdcTrack*> vec_MdcTrack_neg;
509 for (
unsigned int i = 0; i < vec_track_neg.size(); i++ )
512 vec_MdcTrack_neg.push_back( mdcTrack );
514 cout <<
"trackneg: " << i <<
" pt " << vec_track_neg[i]->getPt3D() << endl;
515 if ( m_debug > 0 ) vec_track_neg[i]->print();
517 if ( m_debug > 0 ) cout <<
"step4 : judge neg track list " << endl;
518 judgeHit( mdcTrackList_neg, vec_MdcTrack_neg );
519 if ( m_debug > 0 ) cout <<
"finish - charge " << endl;
525 new HoughMap( 1, houghHitList, m_mapHit, m_nBinTheta, m_nBinRho, -1. * m_rhoRange,
526 m_rhoRange, m_peakWidth, m_peakHigh, m_hitPro );
527 if ( m_debug > 0 ) cout <<
"step5 : pos track list " << endl;
528 vector<HoughTrack*> vec_track_pos;
534 vector<vector<int>> stat_2d2( 2, vector<int>( tracklist_size2, 0 ) );
535 vector<vector<int>> stat_3d2( 2, vector<int>( tracklist_size2, 0 ) );
538 for (
int itrack = 0; itrack < tracklist_size2; itrack++ )
541 if ( m_debug > 0 ) cout <<
" suppose charge +1 " << endl;
546 stat_2d2[0][itrack] = track_pos.
fit2D( m_bunchT0 );
549 cout <<
" charge +1 stat2d " << stat_2d2[1][itrack] <<
" " << track_charge_2d << endl;
550 if ( stat_2d2[0][itrack] == 0 || track_charge_2d == 0 )
continue;
559 if ( m_debug > 0 ) cout <<
" nhitstereo +1 " << nHit3d <<
" " << track_charge_3d << endl;
560 if ( nHit3d < 3 || track_pos.
trackCharge3D() == 0 )
continue;
562 if ( npair == 0 ) stat_3d2[0][itrack] = track_pos.
fit3D();
563 else stat_3d2[0][itrack] = track_pos.
fit3D_inner();
566 if ( m_debug > 0 ) cout <<
" charge +1 stat3d " << stat_3d2[1][itrack] <<
" " << endl;
567 if ( stat_3d2[0][itrack] == 0 )
continue;
568 vec_track_pos.push_back( &track_pos );
574 std::sort( vec_track_pos.begin(), vec_track_pos.end(),
more_pt );
577 vector<MdcTrack*> vec_MdcTrack_pos;
578 for (
unsigned int i = 0; i < vec_track_pos.size(); i++ )
581 vec_MdcTrack_pos.push_back( mdcTrack );
583 cout <<
"trackpos : " << i <<
" pt " << vec_track_pos[i]->getPt3D() << endl;
584 if ( m_debug > 0 ) vec_track_pos[i]->print();
586 if ( m_debug > 0 ) cout <<
"step6 : judge pos track list " << endl;
587 judgeHit( mdcTrackList_pos, vec_MdcTrack_pos );
594 compareHough( mdcTrackList_neg );
595 compareHough( mdcTrackList_pos );
597 if ( mdcTrackList_neg.length() != 0 && mdcTrackList_pos.length() != 0 )
598 judgeChargeTrack( mdcTrackList_neg, mdcTrackList_pos );
600 mdcTrackList_neg += mdcTrackList_pos;
603 if ( m_combineTracking ) nTdsTk = comparePatTsf( mdcTrackList_neg, trackList_tds );
606 if ( m_debug > 0 ) cout <<
"step8 : store tds " << endl;
607 if ( m_debug > 0 ) cout <<
"store tds " << endl;
609 for (
unsigned int i = 0; i < mdcTrackList_neg.length(); i++ )
612 cout <<
"- charge size i : " << i <<
" " << mdcTrackList_neg.length() << endl;
614 mdcTrackList_neg[i]->storeTrack( tkId, trackList_tds, hitList_tds, tkStat );
616 delete mdcTrackList_neg[i];
618 if ( m_debug > 0 ) m_mdcPrintSvc->printRecMdcTrackCol();
621 double t_teventTime = m_timer_all->elapsed();
622 if ( m_hist ) m_time = t_teventTime;
624 if ( m_hist ) ntuple_evt->write();
628 if ( m_debug > 0 ) cout <<
"after delete map " << endl;
629 for (
int ihit = 0; ihit < mdcHitCol_neg.size(); ihit++ )
631 delete mdcHitCol_neg[ihit];
632 delete mdcHitCol_pos[ihit];
635 if ( m_debug > 0 ) cout <<
"after delete hit" << endl;
637 if ( m_debug > 0 ) cout <<
"end event " << endl;
639 return StatusCode::SUCCESS;
644 MsgStream log(
msgSvc(), name() );
646 log << MSG::INFO <<
"in finalize()" << endmsg;
648 return StatusCode::SUCCESS;
651int MdcHoughFinder::GetMcInfo() {
652 MsgStream log(
msgSvc(), name() );
654 SmartDataPtr<McParticleCol> mcParticleCol( eventSvc(),
"/Event/MC/McParticleCol" );
655 if ( !mcParticleCol )
657 log << MSG::ERROR <<
"Could not find McParticle" << endmsg;
661 g_tkParTruth.clear();
665 int t_pidTruth = -999;
667 McParticleCol::iterator iter_mc = mcParticleCol->begin();
668 for ( ; iter_mc != mcParticleCol->end(); iter_mc++ )
670 t_pidTruth = ( *iter_mc )->particleProperty();
672 if ( !( *iter_mc )->primaryParticle() )
continue;
676 int pid = t_pidTruth;
679 log << MSG::WARNING <<
"Wrong particle id" << endmsg;
684 IPartPropSvc* p_PartPropSvc;
685 static const bool CREATEIFNOTTHERE(
true );
686 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE );
687 if ( !PartPropStatus.isSuccess() || 0 == p_PartPropSvc )
688 { std::cout <<
" Could not initialize Particle Properties Service" << std::endl; }
689 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
690 if ( p_particleTable->particle( pid ) )
692 name = p_particleTable->particle( pid )->name();
693 t_qTruth = p_particleTable->particle( pid )->charge();
695 else if ( p_particleTable->particle( -pid ) )
697 name =
"anti " + p_particleTable->particle( -pid )->name();
698 t_qTruth = ( -1 ) * p_particleTable->particle( -pid )->charge();
704 std::cout << __FILE__ <<
" " << __LINE__ <<
" new helix with pos "
705 << ( *iter_mc )->initialPosition().v() <<
" mom "
706 << ( *iter_mc )->initialFourMomentum().v() <<
" q " << t_qTruth << std::endl;
707 Helix mchelix =
Helix( ( *iter_mc )->initialPosition().v(),
708 ( *iter_mc )->initialFourMomentum().v(), t_qTruth );
711 int mcTkId = ( *iter_mc )->trackIndex();
713 pair<int, const HepVector> p( mcTkId, mchelix.
a() );
714 g_tkParTruth.insert( p );
719 rho = -1. / fabs( mchelix.
radius() );
724 rho = 1. / fabs( mchelix.
radius() );
725 theta = mchelix.
phi0();
731 t_tanl = mchelix.
tanl();
750 m_pzTruth = mchelix.
momentum( 0. ).z();
751 m_pidTruth = t_pidTruth;
753 m_ptTruth = mchelix.
pt();
754 m_pTruth = mchelix.
momentum( 0. ).mag();
756 m_drTruth = mchelix.
dr();
757 m_phi0Truth = mchelix.
phi0();
758 m_omegaTruth = 1. / ( mchelix.
radius() );
759 m_dzTruth = mchelix.
dz();
760 m_tanl_mc = mchelix.
tanl();
781 g_firstHit.set( 0, 0, 0 );
782 SmartDataPtr<MdcMcHitCol> mdcMcHitCol( eventSvc(),
"/Event/MC/MdcMcHitCol" );
785 MdcMcHitCol::iterator iter_mchit = mdcMcHitCol->begin();
786 for ( ; iter_mchit != mdcMcHitCol->end(); iter_mchit++ )
788 if ( ( *iter_mchit )->getTrackIndex() == 0 )
790 g_firstHit.setX( ( *iter_mchit )->getPositionX() / 10. );
791 g_firstHit.setY( ( *iter_mchit )->getPositionY() / 10. );
792 g_firstHit.setZ( ( *iter_mchit )->getPositionZ() / 10. );
799 std::cout << __FILE__ <<
" Could not get MdcMcHitCol " << std::endl;
809 uint32_t getDigiFlag = 0;
814 MdcDigiVec mdcDigiVec = m_rawDataProviderSvc->getMdcDigiVec( getDigiFlag );
818void MdcHoughFinder::dumpHoughHitList(
const HoughHitList& houghhitlist ) {
820 int num_first_half = 0;
821 vector<double> vtemp, utemp;
822 double k, b, theta, rho, x_cross, y_cross;
823 std::vector<HoughHit>::const_iterator
iter = houghhitlist.
getList().begin();
825 int exit_multiturn = 0;
826 for (
int iHit = 0;
iter != houghhitlist.
getList().end();
iter++, iHit++ )
828 const HoughHit h = ( *iter );
835 m_u[iHit] = h.
getU();
836 m_v[iHit] = h.
getV();
838 m_r[iHit] = h.
getR();
848 if ( type < 0 ) type = 1;
849 if ( type == 0 && h.
getCirList() > 0 ) type = 2;
860 h.
getStyle() != -999 && utemp.size() < 10 )
865 m_nSig_Axial = nsig_axial;
866 m_exit_multiturn = exit_multiturn;
868 Leastfit( utemp, vtemp, k, b );
871 x_cross = -b / ( k + 1 / k );
872 y_cross = b / ( 1 + k * k );
873 rho = sqrt( x_cross * x_cross + y_cross * y_cross );
874 theta = atan2( y_cross, x_cross );
877 theta = theta +
M_PI;
882 m_theta_line = theta;
885 m_nHit = num_first_half;
888void MdcHoughFinder::dumpHoughMap(
const HoughMap& houghmap ) {
965void MdcHoughFinder::diffMap(
const HoughMap& houghmap,
const HoughMap& houghmap2 ) {
994void MdcHoughFinder::Leastfit( vector<double> u, vector<double>
v,
double& k,
double& b ) {
996 if ( N <= 2 )
return;
997 double*
x =
new double[N];
998 double* y =
new double[N];
999 for (
int i = 0; i < N; i++ )
1005 TF1* fpol1 =
new TF1(
"fpol1",
"pol1", -50, 50 );
1006 TGraph* tg =
new TGraph( N,
x, y );
1007 tg->Fit(
"fpol1",
"QN" );
1008 double ktemp = fpol1->GetParameter( 1 );
1009 double btemp = fpol1->GetParameter( 0 );
1023 vector<RecMdcTrack*>& vec_trackPatTds ) {
1024 MsgStream log(
msgSvc(), name() );
1027 DataObject* aTrackCol;
1028 DataObject* aRecHitCol;
1029 SmartIF<IDataManagerSvc> dataManSvc( eventSvc() );
1030 if ( !m_combineTracking )
1032 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol", aTrackCol );
1033 if ( aTrackCol != NULL )
1035 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol" );
1036 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol" );
1038 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol", aRecHitCol );
1039 if ( aRecHitCol != NULL )
1041 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol" );
1042 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol" );
1047 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol", aTrackCol );
1048 if ( aTrackCol ) { trackList_tds =
dynamic_cast<RecMdcTrackCol*
>( aTrackCol ); }
1054 if ( !sc.isSuccess() )
1056 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" << endmsg;
1061 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol", aRecHitCol );
1062 if ( aRecHitCol ) { hitList_tds =
dynamic_cast<RecMdcHitCol*
>( aRecHitCol ); }
1067 if ( !sc.isSuccess() )
1069 log << MSG::FATAL <<
" Could not register RecMdcHit collection" << endmsg;
1074 if ( m_removeBadTrack && m_combineTracking )
1077 cout <<
"PATTSF collect " << trackList_tds->size() <<
" track. " << endl;
1078 if ( trackList_tds->size() != 0 )
1080 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1081 for ( ; iter_pat != trackList_tds->end(); iter_pat++ )
1083 double d0 = ( *iter_pat )->helix( 0 );
1084 double kap = ( *iter_pat )->helix( 2 );
1085 double pt = 0.00001;
1086 if ( fabs( kap ) > 0.00001 ) pt = fabs( 1. / kap );
1087 double dz = ( *iter_pat )->helix( 3 );
1088 double chi2 = ( *iter_pat )->chi2();
1090 cout <<
"d0: " << d0 <<
" z0: " << dz <<
" pt " << pt <<
" chi2 " << chi2 << endl;
1093 if ( pt <= m_dropTrkPtCut )
1095 vec_trackPatTds.push_back( *iter_pat );
1097 HitRefVec rechits = ( *iter_pat )->getVecHits();
1098 HitRefVec::iterator hotIter = rechits.begin();
1099 while ( hotIter != rechits.end() )
1101 Identifier
id = ( *hotIter )->getMdcId();
1105 cout <<
"remove hit " << ( *hotIter )->getId() <<
"(" << layer <<
"," << wire
1107 hitList_tds->remove( *hotIter );
1117 cout <<
"after delete trackcol size : " << trackList_tds->size() << endl;
1122 if ( m_debug > 0 ) cout <<
" PATTSF find 0 track. " << endl;
1126 int nTdsTk = trackList_tds->size();
1131 cout <<
"length in clearMem " << list1.length() <<
" " << list2.length() << endl;
1137 for (
unsigned int j = 0; j < list1.length(); j++ )
1140 << &( list1[j]->track() ) << endl;
1144 cout <<
"not delete new trk " << endl;
1148 for (
unsigned int k = 0; k < list2.length(); k++ )
1151 << &( list2[k]->track() ) << endl;
1155 cout <<
"not delete new trk " << endl;
1161 cout <<
"delete i " << i << endl;
1170 if ( m_debug > 0 ) cout <<
"in judgeChargeTrack" << endl;
1171 if ( m_debug > 0 ) cout <<
"ntrack length neg : " << list1.length() << endl;
1172 if ( m_debug > 0 ) cout <<
"ntrack length pos : " << list2.length() << endl;
1173 for (
int itrack1 = 0; itrack1 < list1.
nTrack(); itrack1++ )
1175 MdcTrack* track_1 = list1[itrack1];
1177 double d0_1 = par1.
d0();
1178 double phi0_1 = par1.
phi0();
1179 double omega_1 = par1.
omega();
1180 double cr = fabs( 1. / par1.
omega() );
1181 double cx =
sin( par1.
phi0() ) * ( par1.
d0() + 1 / par1.
omega() ) *
1183 double cy = -1. *
cos( par1.
phi0() ) * ( par1.
d0() + 1 / par1.
omega() ) * -1;
1184 double z0_1 = par1.
z0();
1185 for (
int itrack2 = 0; itrack2 < list2.
nTrack(); itrack2++ )
1187 MdcTrack* track_2 = list2[itrack2];
1189 double d0_2 = par2.
d0();
1190 double phi0_2 = par2.
phi0();
1191 double omega_2 = par2.
omega();
1192 double cR = fabs( 1. / par2.
omega() );
1193 double cX =
sin( par2.
phi0() ) * ( par2.
d0() + 1 / par2.
omega() ) *
1195 double cY = -1. *
cos( par2.
phi0() ) * ( par2.
d0() + 1 / par2.
omega() ) * -1;
1196 double z0_2 = par2.
z0();
1198 double bestDiff = 1.0e+20;
1199 if ( fabs( cr ) * ( 1. - 0.25 ) <= fabs( cR ) &&
1200 fabs( cR ) <= fabs( cr ) * ( 1. + 0.25 ) )
1202 if ( fabs( cx - cX ) <= fabs( cr ) * ( 0.25 ) &&
1203 fabs( cy - cY ) <= fabs( cr ) * ( 0.25 ) )
1205 double diff = fabs( ( fabs( cr ) - fabs( cR ) ) * ( cx - cX ) * ( cy - cY ) );
1206 if ( diff < bestDiff ) { bestDiff = diff; }
1210 if ( bestDiff != 1.0e20 )
1214 cout <<
"There is ambiguous +- charge in the track list " << endl;
1215 cout <<
"z0_1 : " << z0_1 <<
" z0_2 : " << z0_2 << endl;
1218 if ( fabs( z0_1 ) >= fabs( z0_2 ) )
1224 if ( fabs( z0_1 ) < fabs( z0_2 ) )
1231 if ( bestDiff == 1.0e20 )
1233 if ( m_debug > 0 ) cout <<
" no (+-) track in hough" << endl;
1239void MdcHoughFinder::compareHough(
MdcTrackList& mdcTrackList ) {
1240 if ( m_debug > 0 ) cout <<
"in compareHough " << endl;
1241 if ( m_debug > 0 ) cout <<
"ntrack : " << mdcTrackList.length() << endl;
1242 for (
int itrack = 0; itrack < mdcTrackList.length(); itrack++ )
1244 MdcTrack* track = mdcTrackList[itrack];
1247 double pt = ( 1. / par.
omega() ) / 333.567;
1249 cout <<
"i Track : " << itrack <<
" nHit: " << nhit <<
" pt: " << pt << endl;
1253 for (
int itrack1 = 0; itrack1 < mdcTrackList.length(); itrack1++ )
1255 MdcTrack* track_1 = mdcTrackList[itrack1];
1258 double d0_1 = par1.
d0();
1259 double phi0_1 = par1.
phi0();
1260 double omega_1 = par1.
omega();
1261 double z0_1 = par1.
z0();
1262 double cr = fabs( 1. / par1.
omega() );
1263 double cx =
sin( par1.
phi0() ) * ( par1.
d0() + 1 / par1.
omega() ) *
1265 double cy = -1. *
cos( par1.
phi0() ) * ( par1.
d0() + 1 / par1.
omega() ) * -1;
1266 if ( m_debug > 0 ) cout <<
"circle 1 : " << cr <<
"," << cx <<
"," << cy << endl;
1268 for (
int itrack2 = itrack1 + 1; itrack2 < mdcTrackList.length(); itrack2++ )
1270 MdcTrack* track_2 = mdcTrackList[itrack2];
1273 double d0_2 = par2.
d0();
1274 double phi0_2 = par2.
phi0();
1275 double omega_2 = par2.
omega();
1276 double z0_2 = par2.
z0();
1277 double cR = fabs( 1. / par2.
omega() );
1278 double cX =
sin( par2.
phi0() ) * ( par2.
d0() + 1 / par2.
omega() ) *
1280 double cY = -1. *
cos( par2.
phi0() ) * ( par2.
d0() + 1 / par2.
omega() ) * -1;
1281 if ( m_debug > 0 ) cout <<
"circle 2 : " << cR <<
"," << cX <<
"," << cY << endl;
1283 double bestDiff = 1.0e+20;
1284 if ( fabs( cr ) * ( 1. - 0.25 ) <= fabs( cR ) &&
1285 fabs( cR ) <= fabs( cr ) * ( 1. + 0.25 ) )
1287 if ( fabs( cx - cX ) <= fabs( cr ) * ( 0.25 ) &&
1288 fabs( cy - cY ) <= fabs( cr ) * ( 0.25 ) )
1290 double diff = fabs( ( fabs( cr ) - fabs( cR ) ) * ( cx - cX ) * ( cy - cY ) );
1291 if ( diff < bestDiff ) { bestDiff = diff; }
1295 double zdiff = z0_1 - z0_2;
1296 if ( bestDiff != 1.0e20 && fabs( zdiff ) < 25. )
1298 if ( m_debug > 0 ) cout <<
"z0_1 : " << z0_1 <<
" z0_2 : " << z0_2 << endl;
1300 if ( nhit1 < nhit2 &&
1301 ( fabs( z0_1 ) > fabs( z0_2 ) && fabs( z0_1 ) > m_z0Cut_compareHough ) )
1303 if ( m_debug > 0 ) cout <<
"remove track1 " << 1. / par1.
omega() / 333.567 << endl;
1305 mdcTrackList.
remove( track_1 );
1312 if ( m_debug > 0 ) cout <<
"remove track2 " << 1. / par2.
omega() / 333.567 << endl;
1314 mdcTrackList.
remove( track_2 );
1318 if ( bestDiff == 1.0e20 )
1320 if ( m_debug > 0 ) cout <<
" no same track in hough" << endl;
1325int MdcHoughFinder::comparePatTsf(
MdcTrackList& mdcTrackList,
1335 for (
int itrack1 = 0; itrack1 < mdcTrackList.length(); itrack1++ )
1337 MdcTrack* track_1 = mdcTrackList[itrack1];
1340 double d0_1 = par1.
d0();
1341 double phi0_1 = par1.
phi0();
1342 double omega_1 = par1.
omega();
1343 double z0_1 = par1.
z0();
1344 double cr = fabs( 1. / par1.
omega() );
1345 double cx =
sin( par1.
phi0() ) * ( par1.
d0() + 1 / par1.
omega() ) *
1347 double cy = -1. *
cos( par1.
phi0() ) * ( par1.
d0() + 1 / par1.
omega() ) * -1;
1350 double bestDiff = 1.0e+20;
1351 double ptDiff = 0.0;
1353 vector<double>
a0, a1, a2, a3, a4;
1354 RecMdcTrackCol::iterator iterBest;
1355 RecMdcTrackCol::iterator iteritrk = trackList_tds->begin();
1357 for ( ; iteritrk != trackList_tds->end(); iteritrk++ )
1359 if ( m_debug > 0 ) cout <<
"being pattsf trk " << itrk << endl;
1360 double pt = ( *iteritrk )->pxy();
1361 a0.push_back( ( *iteritrk )->helix( 0 ) );
1362 a1.push_back( ( *iteritrk )->helix( 1 ) );
1363 a2.push_back( ( *iteritrk )->helix( 2 ) );
1364 a3.push_back( ( *iteritrk )->helix( 3 ) );
1365 a4.push_back( ( *iteritrk )->helix( 4 ) );
1366 cR = ( -333.567 ) / a2[itrk];
1367 cX = ( cR +
a0[itrk] ) *
cos( a1[itrk] );
1368 cY = ( cR +
a0[itrk] ) *
sin( a1[itrk] );
1371 cout <<
" compare PATTSF and HOUGH " << endl;
1372 cout <<
" fabs(cX) " << fabs( cX ) <<
"fabs(cx) " << fabs( cx ) << endl;
1373 cout <<
" fabs(cY) " << fabs( cY ) <<
"fabs(cy) " << fabs( cy ) << endl;
1374 cout <<
" fabs(cR) " << fabs( cR ) <<
"fabs(cr) " << fabs( cr ) << endl;
1375 cout <<
" fabs(cx-cX) " << fabs( cx - cX ) <<
"fabs(cy-cY) " << fabs( cy - cY )
1376 <<
" fabs(cr-cR) " << fabs( cr - cR ) << endl;
1379 if ( fabs( cr ) * ( 1. - 0.25 ) <= fabs( cR ) &&
1380 fabs( cR ) <= fabs( cr ) * ( 1. + 0.25 ) )
1382 if ( fabs( cx - cX ) <= fabs( cr ) * ( 0.25 ) &&
1383 fabs( cy - cY ) <= fabs( cr ) * ( 0.25 ) )
1385 double diff = fabs( ( fabs( cr ) - fabs( cR ) ) * ( cx - cX ) * ( cy - cY ) );
1386 if ( m_debug > 0 ) cout <<
" diff " << diff <<
" pt " << pt << endl;
1387 if ( fabs( pt ) > ptDiff )
1390 iterBest = iteritrk;
1402 if ( bestDiff != 1.0e20 )
1404 if ( m_debug > 0 ) cout <<
" same track pattsf & hough , then compare nhit. " << endl;
1405 double d0_pattsf = ( *iterBest )->helix( 0 );
1406 double z0_pattsf = ( *iterBest )->helix( 3 );
1407 double d0_hough = d0_1;
1408 double z0_hough = z0_1;
1409 int use_pattsf( 1 ), use_hough( 1 );
1410 if ( fabs( d0_pattsf ) > m_dropTrkDrCut || fabs( z0_pattsf ) > m_dropTrkDzCut )
1412 if ( fabs( d0_hough ) > m_dropTrkDrCut || fabs( z0_hough ) > m_dropTrkDzCut )
1414 if ( use_pattsf == 0 && use_hough == 1 )
1416 trackList_tds->remove( *iterBest );
1417 if ( m_debug > 0 ) cout <<
" use houghTrack, vertex pattsf wrong" << endl;
1419 if ( use_pattsf == 1 && use_hough == 0 )
1421 mdcTrackList.
remove( track_1 );
1423 if ( m_debug > 0 ) cout <<
" use pattsfTrack, vertex hough wrong" << endl;
1425 if ( ( use_pattsf == 0 && use_hough == 0 ) || ( use_pattsf == 1 && use_hough == 1 ) )
1427 int nhit_pattsf = ( ( *iterBest )->ndof() + 5 );
1428 int nhit_hough = nhit1;
1429 if ( m_debug > 0 ) cout <<
" nhit " << nhit_pattsf <<
" " << nhit_hough << endl;
1430 if ( nhit_pattsf > nhit_hough )
1432 mdcTrackList.
remove( track_1 );
1434 if ( m_debug > 0 ) cout <<
" use pattsfTrack " << endl;
1438 trackList_tds->remove( *iterBest );
1439 if ( m_debug > 0 ) cout <<
" use houghTrack " << endl;
1454 if ( bestDiff == 1.0e20 )
1456 if ( m_debug > 0 ) cout <<
" no same track in pattsf" << endl;
1462 if ( trackList_tds->size() != 0 )
1465 RecMdcTrackCol::iterator iter_pat = trackList_tds->begin();
1466 for ( ; iter_pat != trackList_tds->end(); iter_pat++, digi++ )
1468 ( *iter_pat )->setTrackId( digi );
1472 return trackList_tds->size();
1475int MdcHoughFinder::judgeHit(
MdcTrackList& list, vector<MdcTrack*>& trackCol ) {
1476 if ( m_debug > 0 ) cout <<
"in judgHit: " << endl;
1477 for (
unsigned int i = 0; i < trackCol.size(); i++ )
1481 list.append( trackCol[i] );
1487 MsgStream log(
msgSvc(), name() );
1488 NTuplePtr nt1(
ntupleSvc(),
"MdcHoughFinder/evt" );
1489 if ( nt1 ) { ntuple_evt = nt1; }
1492 ntuple_evt =
ntupleSvc()->book(
"MdcHoughFinder/evt", CLID_ColumnWiseTuple,
"evt" );
1495 ntuple_evt->addItem(
"eventNum", m_eventNum );
1496 ntuple_evt->addItem(
"runNum", m_runNum );
1498 ntuple_evt->addItem(
"nHit", m_nHit, 0, 6796 );
1567 ntuple_evt->addItem(
"nMapPk", m_nMapPk, 0, 100 );
1612 ntuple_evt->addItem(
"time", m_time );
1616 log << MSG::ERROR <<
"Cannot book tuple MdcHoughFinder/hough" << endmsg;
1617 return StatusCode::FAILURE;
1664 return StatusCode::SUCCESS;
DECLARE_COMPONENT(BesBdkRc)
HepGeom::Point3D< double > HepPoint3D
character *LEPTONflag integer iresonances real zeta5 real a0
std::vector< MdcDigi * > MdcDigiVec
vector< TrkRecoTrk * > vectrk_for_clean
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
bool more_pt(const HoughTrack *tracka, const HoughTrack *trackb)
double sin(const BesAngle a)
double cos(const BesAngle a)
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
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 IMdcCalibFunSvc *mdcCalibFunSvc)
static void setContext(TrkContextEv *context)
static void setCalib(const IMdcCalibFunSvc *mdcCalibFunSvc)
int addTruthInfo(std::map< int, const HepVector > mcTkPars)
const std::vector< HoughHit > & getList() const
const MdcDigi * digi() const
int getSlayerType() const
static void setBunchTime(double t0)
double getDriftDist() const
HepPoint3D getPointTruth() const
double getDriftDistTruth() const
static void setMdcGeomSvc(IMdcGeomSvc *geomSvc)
static void setMdcCalibFunSvc(const IMdcCalibFunSvc *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)
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 remove(MdcTrack *atrack)
static void readMCppTable(std::string filenm)
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