1#include "CgemMdcFitAlg/CgemMdcFitAlg.h"
2#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/IPartPropSvc.h"
18#include "HepPDT/ParticleDataTable.hh"
19#include "Identifier/MdcID.h"
20#include "BField/BField.h"
21#include "MagneticField/IMagneticFieldSvc.h"
22#include "TrkFitter/TrkContextEv.h"
23#include "EventModel/EventHeader.h"
24#include "EvTimeEvent/RecEsTime.h"
25#include "McTruth/McParticle.h"
26#include "TrackUtil/Helix.h"
27#include "MdcRawEvent/MdcDigi.h"
28#include "MdcData/MdcHit.h"
29#include "MdcData/MdcRecoHitOnTrack.h"
30#include "CgemData/CgemHitOnTrack.h"
31#include "TrkFitter/TrkHelixMaker.h"
32#include "TrkFitter/TrkCircleMaker.h"
33#include "TrkFitter/TrkLineMaker.h"
34#include "TrkBase/TrkHitList.h"
35#include "TrkBase/TrkExchangePar.h"
36#include "TrkBase/TrkFit.h"
37#include "TrkBase/TrkRecoTrk.h"
38#include "MdcTrkRecon/MdcSeg.h"
39#include "MdcTrkRecon/MdcTrackParams.h"
50const CgemGeomSvc* CgemMdcFitAlg::m_cgemGeomSvc=NULL;
51const MdcDetector* CgemMdcFitAlg::m_mdcDetector=NULL;
61 Algorithm(name, pSvcLocator)
63 declareProperty(
"debug" ,m_debug = 0 );
64 declareProperty(
"tuple" ,m_tuple = 0 );
65 declareProperty(
"change" ,m_changeTDS = 2 );
66 declareProperty(
"debugArbHit" ,m_debugArbHit= 0 );
67 declareProperty(
"fit2D" ,m_fit2D= 1 );
68 declareProperty(
"drCut" ,m_drCut= 1. );
69 declareProperty(
"dzCut" ,m_dzCut= 10. );
70 declareProperty(
"filter" ,m_filter= 0 );
71 declareProperty(
"eventFile" ,m_evtFile=
"EventList" );
72 declareProperty(
"compareTrack" ,m_compareTrack= 0 );
73 declareProperty(
"removeBadTrack",m_removeBadTrack= 0 );
78 MsgStream log(
msgSvc(), name());
79 log << MSG::INFO <<
"In CgemMdcFitAlg initialize()" << endreq;
84 sc = service (
"MagneticFieldSvc",pIMF);
85 if(sc!=StatusCode::SUCCESS) {
86 log << MSG::ERROR <<
"Unable to open Magnetic field service"<<endreq;
89 log << MSG::INFO <<
"field z = "<<bfield->
bFieldNominal()<< endreq;
93 sc = service (
"MdcCalibFunSvc", imdcCalibSvc);
95 if ( sc.isFailure() ){
96 log << MSG::FATAL <<
"Could not load MdcCalibFunSvc!" << endreq;
97 return StatusCode::FAILURE;
101 sc = service (
"CgemCalibFunSvc", icgemCalibSvc);
103 if ( sc.isFailure() ){
104 log << MSG::FATAL <<
"Could not load CgemCalibFunSvc!" << endreq;
105 return StatusCode::FAILURE;
109 sc = service (
"CgemGeomSvc",icgemGeomSvc);
110 m_cgemGeomSvc =
dynamic_cast<CgemGeomSvc*
>(icgemGeomSvc);
111 if ( sc.isFailure() ){
112 log << MSG::FATAL <<
"Could not load CgemGeomSvc!" << endreq;
113 return StatusCode::FAILURE;
117 if(m_tuple) sc = bookTuple();
119 return StatusCode::SUCCESS;
127 MsgStream log(
msgSvc(), name());
128 log << MSG::INFO <<
"In CgemMdcFitAlg execute()" << endreq;
130 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
132 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
133 return StatusCode::FAILURE;
135 int run = eventHeader->runNumber();
136 int evt = eventHeader->eventNumber();
137 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
138 if (!recMdcTrackCol){
139 log << MSG::WARNING <<
"Could not find RecMdcTrackCol" << endreq;
140 return StatusCode::SUCCESS;
143 SmartDataPtr<RecEsTimeCol> evTimeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
145 log << MSG::WARNING<<
"Could not retrieve RecEsTimeCol" << endreq;
146 return StatusCode::SUCCESS;
148 RecEsTimeCol::iterator iter_evt = evTimeCol->begin();
149 if (iter_evt != evTimeCol->end()){
150 m_bunchT0 = (*iter_evt)->getTest()*1.e-9;
154 SmartDataPtr<MdcDigiCol> mdcDigiCol(evtSvc(),
"/Event/Digi/MdcDigiCol");
156 log << MSG::FATAL <<
"Could not find MdcDigiCol!" << endreq;
157 return StatusCode::SUCCESS;
162 lowPt_Evt.open(m_evtFile.c_str());
165 while( lowPt_Evt >> evtNum) {
166 evtlist.push_back(evtNum);
168 vector<int>::iterator iter_evt = find(evtlist.begin(),evtlist.end(),evt);
169 if( iter_evt == evtlist.end() ) { setFilterPassed(
false);
return StatusCode::SUCCESS; }
170 else setFilterPassed(
true);
173 if(m_debug)cout<<endl;
174 if(m_debug)cout<<
"run:"<<run<<
" event:"<<evt<<endl;
175 if(m_tuple)getMcTruth();
176 if(m_debug)cout<<
"tracks before fitting: "<<recMdcTrackCol->size()<<endl;
181 m_nTrkRec = recMdcTrackCol->size();
184 for(RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();itTrk != recMdcTrackCol->end();itTrk++)
186 HitRefVec vechits = (*itTrk)->getVecHits();
187 HitRefVec::iterator itHit = vechits.begin();
188 for( ; itHit != vechits.end(); itHit++)
190 double tdc = (*itHit)->getTdc();
191 double adc = (*itHit)->getAdc();
192 const Identifier mdcid = (*itHit)->getMdcId();
196 MdcDigiCol::iterator iterDigi = mdcDigiCol->begin();
197 for(; iterDigi != mdcDigiCol->end(); iterDigi++ ) {
198 if((*iterDigi)->identify() == mdcid)
break;
200 if(tdc==0)tdc = (*iterDigi)->getTimeChannel();
204 vector<MdcHit*>::iterator imdcHit = mdcHitCol.begin();
205 for(;imdcHit != mdcHitCol.end();imdcHit++){
206 if((*imdcHit)->mdcId() == mdcid){
216 mdcHitCol.push_back(mdcHit);
221 if(m_debugArbHit>0 ) m_par.
lPrint=8;
232 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
233 for(
int itrk=0;itTrk != recMdcTrackCol->end(); itrk++,itTrk++)
290 m_trkidRec[itrk] = (*itTrk)->trackId();
291 m_drRec[itrk] = (*itTrk)->helix(0);
292 m_phi0Rec[itrk] = (*itTrk)->helix(1);
293 m_kappaRec[itrk] = (*itTrk)->helix(2);
294 m_dzRec[itrk] = (*itTrk)->helix(3);
295 m_tanlRec[itrk] = (*itTrk)->helix(4);
296 m_chargeRec[itrk] = (*itTrk)->charge() ;
297 m_statRec[itrk] = (*itTrk)->stat() ;
298 m_nhitsRec[itrk] = (*itTrk)->getNhits() ;
299 m_nclusterRec[itrk]= (*itTrk)->getNcluster() ;
300 m_nsterRec[itrk] = (*itTrk)->nster() ;
301 m_ndofRec[itrk] = (*itTrk)->ndof() ;
302 m_chi2Rec[itrk] = (*itTrk)->chi2() ;
303 m_pxRec[itrk] = (*itTrk)->px() ;
304 m_pyRec[itrk] = (*itTrk)->py() ;
305 m_pzRec[itrk] = (*itTrk)->pz() ;
306 m_pxyRec[itrk] = (*itTrk)->pxy() ;
307 m_pRec[itrk] = (*itTrk)->p() ;
308 m_xRec[itrk] = (*itTrk)->x() ;
309 m_yRec[itrk] = (*itTrk)->y() ;
310 m_zRec[itrk] = (*itTrk)->z() ;
311 m_rRec[itrk] = (*itTrk)->r() ;
312 m_thetaRec[itrk] = (*itTrk)->theta() ;
313 m_phiRec[itrk] = (*itTrk)->phi() ;
314 m_fiTermRec[itrk] = (*itTrk)->getFiTerm() ;
317 if(m_debug)cout<<
"fitting track: "<<itrk<<endl;
321 bool permitFlips =
true;
322 bool lPickHits =
true;
323 int trkId = (*itTrk)->trackId();
324 double dr = (*itTrk)->helix(0);
325 double phi0 = (*itTrk)->helix(1);
326 double kappa = (*itTrk)->helix(2);
327 double dz = (*itTrk)->helix(3);
328 double tanl = (*itTrk)->helix(4);
329 if(m_debug)cout<<
"helix parameters before fitting: "<<setw(12)<<dr<<
" "<<setw(12)<<phi0<<
" "<<setw(12)<<kappa<<
" "<<setw(12)<<dz<<
" "<<setw(12)<<tanl<<endl;
342 if (m_debug && fit_circle.
failure()){cout<<
"fit: "<<fit_circle<<endl;}
343 if (m_debug && check_circle.
failure()){cout<<
"check: "<<check_circle<<endl;}
350 if(phi0<0)phi0+=2*
M_PI;
351 kappa = par.
omega()*333.567;
352 if(m_debug)cout<<
"helix parameters after 2D fitting: "<<setw(12)<<dr<<
" "<<setw(12)<<phi0<<
" "<<setw(12)<<kappa<<
" "<<setw(12)<<dz<<
" "<<setw(12)<<tanl<<endl;
366 if (m_debug && fit_helix.
failure()){cout<<
"fit: "<<fit_helix<<endl;}
367 if (m_debug && check_helix.
failure()){cout<<
"check: "<<check_helix<<endl;}
373 if(phi0<0)phi0+=2*
M_PI;
374 kappa = par.
omega()*333.567;
377 if(m_debug)cout<<
"helix parameters after fitting: "<<setw(12)<<dr<<
" "<<setw(12)<<phi0<<
" "<<setw(12)<<kappa<<
" "<<setw(12)<<dz<<
" "<<setw(12)<<tanl<<endl<<endl;
381 if(m_changeTDS ==1)
updateTracks(trkId,helixTrk,(*itTrk),trkStat);
389 mdcTrackList.append(mdcTrack);
396 if(m_removeBadTrack){
398 if(m_debug>0 && nDeleted>0)cout<<nDeleted<<
" tracks have been deleted by MdcTrackList..arbitrateHits()"<<endl;
401 storeTracks(trackList_tds, hitList_tds,mdcTrackList);
405 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
406 if (!recMdcTrackCol){
407 log << MSG::WARNING <<
"Could not find RecMdcTrackCol" << endreq;
408 return StatusCode::SUCCESS;
410 m_nTrkFit = recMdcTrackCol->size();
411 RecMdcTrackCol::iterator itTrk = recMdcTrackCol->begin();
412 for(
int itrk=0;itTrk != recMdcTrackCol->end(); itrk++,itTrk++)
415 m_trkidFit[itrk] = (*itTrk)->trackId();
416 m_drFit[itrk] = (*itTrk)->helix(0);
417 m_phi0Fit[itrk] = (*itTrk)->helix(1);
418 m_kappaFit[itrk] = (*itTrk)->helix(2);
419 m_dzFit[itrk] = (*itTrk)->helix(3);
420 m_tanlFit[itrk] = (*itTrk)->helix(4);
421 m_chargeFit[itrk] = (*itTrk)->charge() ;
422 m_statFit[itrk] = (*itTrk)->stat() ;
423 m_nhitsFit[itrk] = (*itTrk)->getNhits() ;
424 m_nclusterFit[itrk]= (*itTrk)->getNcluster() ;
425 m_nsterFit[itrk] = (*itTrk)->nster() ;
426 m_ndofFit[itrk] = (*itTrk)->ndof() ;
427 m_chi2Fit[itrk] = (*itTrk)->chi2() ;
428 m_pxFit[itrk] = (*itTrk)->px() ;
429 m_pyFit[itrk] = (*itTrk)->py() ;
430 m_pzFit[itrk] = (*itTrk)->pz() ;
431 m_pxyFit[itrk] = (*itTrk)->pxy() ;
432 m_pFit[itrk] = (*itTrk)->p() ;
433 m_xFit[itrk] = (*itTrk)->x() ;
434 m_yFit[itrk] = (*itTrk)->y() ;
435 m_zFit[itrk] = (*itTrk)->z() ;
436 m_rFit[itrk] = (*itTrk)->r() ;
437 m_thetaFit[itrk] = (*itTrk)->theta() ;
438 m_phiFit[itrk] = (*itTrk)->phi() ;
439 m_fiTermFit[itrk] = (*itTrk)->getFiTerm() ;
444 if(m_tuple)ntuple_evt->write();
446 vector<MdcHit*>::iterator imdcHit = mdcHitCol.begin();
447 for(;imdcHit != mdcHitCol.end();imdcHit++){
451 return StatusCode::SUCCESS;
457 MsgStream log(
msgSvc(), name());
458 log << MSG::INFO<<
"In CgemMdcFitAlg finalize()" << endreq;
460 return StatusCode::SUCCESS;
494 HitRefVec::iterator itHit = vechits.begin();
495 for( ; itHit != vechits.end(); itHit++)
497 double flight = (*itHit)->getFltLen();
498 double tdc = (*itHit)->getTdc();
499 double adc = (*itHit)->getAdc();
500 const Identifier mdcid = (*itHit)->getMdcId();
505 vector<MdcHit*>::iterator imdcHit = mdcHitCol.begin();
506 for(;imdcHit != mdcHitCol.end();imdcHit++){
507 if((*imdcHit)->mdcId() == mdcid){
509 tdc = (*imdcHit)->tdcIndex();
514 mdcHit =
new MdcHit(mdcDigi,m_mdcDetector);
516 vector<MdcHit*>::iterator imdcHit = mdcHitCol.begin();
517 for(;imdcHit != mdcHitCol.end();imdcHit++){
518 if((*imdcHit)->mdcId() == mdcid){
525 err.
setFailure(10,
"fit failed,track type error!");
537 if(m_debug>1)cout<<
"layer: "<<layer<<
" view: "<<mdcHit->
layer()->
view()<<
" wire: "<<wire<<endl;
538 if(mdcHit->
driftTime(m_bunchT0,0)>1000)
continue;
546 ClusterRefVec::iterator itCluster = clusterRefVec.begin();
547 for( ; itCluster != clusterRefVec.end(); itCluster++)
554 if(m_debug>1)cout<<
"layer: "<<recCgemCluster->
getlayerid()<<
" flag: "<<recCgemCluster->
getflag()<<
" clusterId: "<<recCgemCluster->
getclusterid()<<endl;
569 if(trackType==
helixType)m_dropTrkNhitCut=9;
570 m_dropTrkChi2Cut=99999;
571 m_dropTrkChi2NdfCut=99999;
590 chi2=trkFit->
chisq();
596 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track radius cut "<<
abs(1/(par.
omega()))<<
" < "<<0.03 <<std::endl;
600 bool badQuality =
false;
601 if(fabs(chi2)>m_qualityFactor*m_dropTrkChi2Cut ){
603 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by chi2 "<<chi2<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkChi2Cut <<std::endl;
607 if( fabs(par.
d0())>m_qualityFactor*m_dropTrkDrCut) {
609 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by d0 "<<par.
d0()<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkDrCut <<std::endl;
613 if( fabs(par.
z0())>m_qualityFactor*m_dropTrkDzCut && trackType ==
helixType) {
615 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by z0 "<<par.
z0()<<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkDzCut <<std::endl;
619 if( (fabs(chi2)/qhits->
nHit()) > m_qualityFactor*m_dropTrkChi2NdfCut) {
621 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by chi2/ndf "<<(fabs(chi2)/qhits->
nHit()) <<
" > "<<m_qualityFactor<<
" * "<<m_dropTrkChi2NdfCut<<std::endl;
625 if( nActiveHit <= m_dropTrkNhitCut) {
627 std::cout<<__FILE__<<
" "<<__LINE__<<
" drop track by nhit "<<nActiveHit <<
" <= "<<m_dropTrkNhitCut<<std::endl;
632 if( badQuality) fit_stat=0;
643 double _phi0=par.
phi0();
644 double _omega=par.
omega();
653 int _charge=trkFit->
charge();
654 cout <<
" global 3d fit success"<<endl;
656 trkRecoTrk->
print(std::cout);
657 double _circleR=_charge/par.
omega();
659 double _circleY= -1.*
cos(par.
phi0()) *(par.
d0()+1/par.
omega()) * -1;
660 double pxy=fabs(_circleR/333.567);
662 double pxyz=_charge*sqrt(pxy*pxy+pz*pz);
666 cout<<
" circle after globle 3d: "<<
"("<<_circleX<<
","<<_circleY<<
","<<_circleR<<
")"<<endl;
667 cout<<
"pt_rec: "<<_pt<<endl;
668 cout<<
"pz_rec: "<<_pz<<endl;
669 cout<<
"p_rec: "<<_p<<endl;
672 cout<<
" hot list:"<<endl;
674 int lay=((
MdcHit*)(hotIter->hit()))->layernumber();
675 int wir=((
MdcHit*)(hotIter->hit()))->wirenumber();
678 cout <<
"(" <<((
MdcHit*)(hotIter->hit()))->layernumber()
679 <<
","<<((
MdcHit*)(hotIter->hit()))->wirenumber()
680 <<
":"<<hotIter->isActive()<<
") ";
686 <<
":"<<hotIter->isActive()<<
") ";
693 if (hotIter->isActive()==1) nfit3d++;
697 cout<<
" in 3D fit number of Active hits : "<<_nfit<<endl;
714 MsgStream log(
msgSvc(), name());
717 DataObject *aTrackCol;
718 DataObject *aRecHitCol;
719 SmartIF<IDataManagerSvc> dataManSvc(eventSvc());
720 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
721 if(aTrackCol != NULL) {
722 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcTrackCol");
723 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcTrackCol");
725 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
726 if(aRecHitCol != NULL) {
727 dataManSvc->clearSubTree(
"/Event/Recon/RecMdcHitCol");
728 eventSvc()->unregisterObject(
"/Event/Recon/RecMdcHitCol");
733 eventSvc()->findObject(
"/Event/Recon/RecMdcTrackCol",aTrackCol);
739 if(!sc.isSuccess()) {
740 log << MSG::FATAL <<
" Could not register RecMdcTrack collection" <<endreq;
741 return StatusCode::FAILURE;
745 eventSvc()->findObject(
"/Event/Recon/RecMdcHitCol",aRecHitCol);
751 if(!sc.isSuccess()) {
752 log << MSG::FATAL <<
" Could not register RecMdcHit collection" <<endreq;
753 return StatusCode::FAILURE;
758 if(m_debug>0)cout<<
"tracks after fitting: "<<mdcTrackList.length()<<endl;
759 for(
int i =0;i<mdcTrackList.length();i++){
761 mdcTrackList[i]->storeTrack(i, trackList_tds, hitList_tds, trkStat);
762 delete mdcTrackList[i];
765 return StatusCode::SUCCESS;
776 if (fitresult == 0)
return;
783 double Bz = theField.
bFieldZ();
800 nHits = aList->
nHit();
807 double chisq = fitresult->
chisq();
808 int nDof = fitresult->
nDof();
810 double fltLenPoca = 0.0;
813 double phi0 = helix.
phi0();
814 double tanDip = helix.
tanDip();
816 double d0 = helix.
d0();
829 double pxy = fitresult->
pt();
830 if (pxy == 0.) helixPar[2] = 9999.;
831 else helixPar[2] =
q/fabs(pxy);
832 if(pxy>9999.) helixPar[2] = 0.00001;
834 helixPar[3] = helix.
z0();
836 helixPar[4] = tanDip;
839 HepSymMatrix mS(helix.
params().num_row(),0);
842 mS[2][2]=-333.567/Bz;
845 HepSymMatrix mVy = helix.
covariance().similarity(mS);
848 for (
int ie = 0 ; ie < 5 ; ie ++){
849 for (
int je = ie ; je < 5 ; je ++) {
850 errorMat[k] = mVy[ie][je];
855 px = pxy * (-
sin(helixPar[1]));
856 py = pxy *
cos(helixPar[1]);
857 pz = pxy * helixPar[4];
858 p = sqrt(pxy*pxy + pz*pz);
860 double theta = acos(pz/p);
861 double phi = atan2(py,px);
866 recMdcTrack->
setPx(px);
867 recMdcTrack->
setPy(py);
868 recMdcTrack->
setPz(pz);
869 recMdcTrack->
setP(p);
873 recMdcTrack->
setX(poca.x());
874 recMdcTrack->
setY(poca.y());
875 recMdcTrack->
setZ(poca.z());
876 recMdcTrack->
setR(sqrt(poca.x()*poca.x() + poca.y()*poca.y()));
896 double fiTerm = 999.;
899 for (;hot!=aList->
end();hot++){
904 bool findhit =
false;
908 HitRefVec::iterator itHit = vechits.begin();
909 for( ; itHit != vechits.end(); itHit++)
913 recMdcHit = (*itHit);
918 if(!findhit)
continue;
921 recMdcHit->
setId(hitId);
933 double hotWireAmbig = recoHot->
wireAmbig();
934 double driftDist = fabs(recoHot->
drift());
935 double sigma = recoHot->
hitRms();
936 double doca = fabs(recoHot->
dcaToWire());
938 if ( hotWireAmbig == 1){
941 }
else if( hotWireAmbig == -1){
943 }
else if( hotWireAmbig == 0){
957 double res=999.,rese=999.;
958 if (recoHot->
resid(res,rese,
false)){
972 double fltLen = recoHot->
fltLen();
986 if (layerId >= maxLayerId){
987 maxLayerId = layerId;
990 if (layerId < minLayerId){
991 minLayerId = layerId;
1004 SmartRef<RecMdcHit> refHit(recMdcHit);
1005 hitRefVec.push_back(refHit);
1012 clusterRefVec.push_back(recCgemCluster);
1016 std::sort(clusterRefVec.begin(),clusterRefVec.end(),
sortCluster);
1019 if (fiTermHot!=NULL){
1020 fiTerm=(1./sqrt(1.+tanDip*tanDip))*fiTermHot->
fltLen()*helix.
omega();
1054void CgemMdcFitAlg::getMcTruth(){
1055 MsgStream log(
msgSvc(), name());
1058 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
1059 if (!mcParticleCol) {
1060 log << MSG::ERROR<<
"Could not find McParticle" << endreq;
1064 bool findJpsi=
false;
1065 if(m_debug>1) cout<<
"size_mcParticleCol "<<mcParticleCol->size()<< endl;
1066 McParticleCol::iterator iter_mc = mcParticleCol->begin();
1067 for (;iter_mc != mcParticleCol->end(); iter_mc++ ) {
1068 if(!(*iter_mc)->primaryParticle())
continue;
1069 int pdg=(*iter_mc)->particleProperty();
1070 if(pdg==443) findJpsi=
true;
1073 t_pidTruth[itrk] = (*iter_mc)->particleProperty();
1075 if(m_debug>1) cout<<
"tk "<<itrk<<
" pid="<< t_pidTruth[itrk]<< endl;
1078 t_t0Truth=(*iter_mc)->initialPosition().t();
1083 int pid = t_pidTruth[itrk];
1085 log << MSG::WARNING <<
"Wrong particle id" <<endreq;
1088 IPartPropSvc* p_PartPropSvc;
1089 static const bool CREATEIFNOTTHERE(
true);
1090 StatusCode PartPropStatus = service(
"PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE);
1091 if (!PartPropStatus.isSuccess() || 0 == p_PartPropSvc) {
1092 cout<<
" Could not initialize Particle Properties Service" << endl;
1094 HepPDT::ParticleDataTable* p_particleTable = p_PartPropSvc->PDT();
1096 if( p_particleTable->particle(pid) ){
1097 name = p_particleTable->particle(pid)->name();
1098 t_qMC[itrk] = p_particleTable->particle(pid)->charge();
1099 }
else if( p_particleTable->particle(-pid) ){
1100 name =
"anti " + p_particleTable->particle(-pid)->name();
1101 t_qMC[itrk] = (-1.)*p_particleTable->particle(-pid)->charge();
1105 t_vrMC[itrk] = sqrt((*iter_mc)->initialPosition().x()*(*iter_mc)->initialPosition().x() + (*iter_mc)->initialPosition().y()*(*iter_mc)->initialPosition().y()) ;
1106 t_vzMC[itrk] = (*iter_mc)->initialPosition().z();
1107 t_pxMC[itrk] = (*iter_mc)->initialFourMomentum().px();
1108 t_pyMC[itrk] = (*iter_mc)->initialFourMomentum().py();
1109 t_pzMC[itrk] = (*iter_mc)->initialFourMomentum().pz();
1110 t_ptMC[itrk] = sqrt(t_pxMC[itrk]*t_pxMC[itrk] + t_pyMC[itrk]*t_pyMC[itrk]);
1111 t_pMC[itrk] = sqrt(t_ptMC[itrk]*t_ptMC[itrk] + t_pzMC[itrk]*t_pzMC[itrk]);
1112 Hep3Vector p3(t_pxMC[itrk],t_pyMC[itrk],t_pzMC[itrk]);
1114 t_costhetaMC[itrk] = t_pzMC[itrk]/t_pMC[itrk];
1117 t_phiMC[itrk] = p3.phi();
1119 Helix mchelix =
Helix((*iter_mc)->initialPosition().v(), (*iter_mc)->initialFourMomentum().v(), t_qMC[itrk]);
1121 int trkId = (*iter_mc)->trackIndex();
1122 double dr = mchelix.
dr() ;
1123 double phi0 = mchelix.
phi0() ;
1124 double kappa = mchelix.
kappa();
1125 double dz = mchelix.
dz() ;
1126 double tanl = mchelix.
tanl() ;
1127 if(m_debug>0)cout<<
"MCtruth helix parameters: dr, phi0, kappa, dz, tanl ---> "<<dr<<
" "<<phi0<<
" "<<kappa<<
" "<<dz<<
" "<<tanl<<endl;
1129 m_trkidMC[itrk] = trkId;
1131 m_phi0MC[itrk] = phi0 ;
1132 m_kappaMC[itrk] = kappa;
1134 m_tanlMC[itrk] = tanl ;
1135 m_qMC[itrk] = t_qMC[itrk];
1136 m_costhetaMC[itrk] = t_costhetaMC[itrk];
1137 m_phiMC[itrk] = t_phiMC[itrk];
1138 m_vzMC[itrk] = t_vzMC[itrk];
1139 m_vrMC[itrk] = t_vrMC[itrk];
1140 m_pxMC[itrk] = t_pxMC[itrk];
1141 m_pyMC[itrk] = t_pyMC[itrk];
1142 m_pzMC[itrk] = t_pzMC[itrk];
1143 m_ptMC[itrk] = t_ptMC[itrk];
1144 m_pMC[itrk] = t_pMC[itrk];
1148 m_nTrkMC = t_nTrkMC;
1186 if(m_debug>1) cout<<
"ntrack : "<<mdcTrackList.length()<<endl;
1187 for(
int itrack=0; itrack<mdcTrackList.length(); itrack++){
1188 MdcTrack* track = mdcTrackList[itrack];
1191 double pt = (1./par.
omega())/333.567;
1192 if(m_debug>1) cout<<
"i Track : "<<itrack<<
" nHit: "<<nhit<<
" pt: "<<pt<<endl;
1195 for(
int itrack1=0; itrack1<mdcTrackList.length(); itrack1++){
1196 MdcTrack* track_1 = mdcTrackList[itrack1];
1199 double d0_1 = par1.
d0();
1200 double phi0_1 = par1.
phi0();
1201 double omega_1 = par1.
omega();
1202 double z0_1= par1.
z0();
1203 double cr=fabs(1./par1.
omega());
1205 double cy= -1.*
cos(par1.
phi0()) *(par1.
d0()+1/par1.
omega()) * -1;
1206 if(m_debug>1) cout<<
"circle 1 : "<<cr<<
","<<cx<<
","<<cy<<endl;
1208 for(
int itrack2=itrack1+1; itrack2<mdcTrackList.length(); itrack2++){
1209 MdcTrack* track_2 = mdcTrackList[itrack2];
1212 double d0_2 = par2.
d0();
1213 double phi0_2 = par2.
phi0();
1214 double omega_2 = par2.
omega();
1215 double z0_2= par2.
z0();
1216 double cR=fabs(1./par2.
omega());
1218 double cY= -1.*
cos(par2.
phi0()) *(par2.
d0()+1/par2.
omega()) * -1;
1219 if(m_debug>1) cout<<
"circle 2 : "<<cR<<
","<<cX<<
","<<cY<<endl;
1221 double bestDiff = 1.0e+20;
1222 if(fabs(cr)*(1.-0.25) <= fabs(cR) && fabs(cR) <= fabs(cr)*(1.+0.25)){
1223 if(fabs(cx-cX) <= fabs(cr)*(0.25)&& fabs(cy-cY) <= fabs(cr)*(0.25) ){
1224 double diff = fabs((fabs(cr)-fabs(cR))*(cx-cX)*(cy-cY));
1225 if(diff < bestDiff){
1231 double zdiff = z0_1-z0_2;
1232 if(bestDiff != 1.0e20 && fabs(zdiff)<25.){
1233 if(m_debug>1) cout<<
"z0_1 : "<<z0_1<<
" z0_2 : "<<z0_2<<endl;
1234 if( nhit1<nhit2 && (fabs(z0_1)>fabs(z0_2) && fabs(z0_1)>dzCut) ){
1235 if(m_debug>0) cout<<
"remove track1 "<<1./par1.
omega()/333.567<<endl;
1237 mdcTrackList.
remove( track_1 );
1243 if(m_debug>0) cout<<
"remove track2 "<<1./par2.
omega()/333.567<<endl;
1245 mdcTrackList.
remove( track_2 );
1249 if(bestDiff == 1.0e20) {
if(m_debug>1) cout<<
" no same track in hough"<<endl; }
1254StatusCode CgemMdcFitAlg::bookTuple(){
1255 MsgStream log(
msgSvc(), name());
1256 NTuplePtr nt1(
ntupleSvc(),
"CgemMdcFitAlg/evt");
1260 ntuple_evt =
ntupleSvc()->book(
"CgemMdcFitAlg/evt", CLID_ColumnWiseTuple,
"evt");
1262 ntuple_evt->addItem(
"run" , m_run);
1263 ntuple_evt->addItem(
"event" , m_event);
1264 ntuple_evt->addItem(
"nTrkRec" , m_nTrkRec , 0,100);
1265 ntuple_evt->addItem(
"trkidRec", m_nTrkRec , m_trkidRec);
1266 ntuple_evt->addItem(
"drRec" , m_nTrkRec , m_drRec );
1267 ntuple_evt->addItem(
"phi0Rec" , m_nTrkRec , m_phi0Rec );
1268 ntuple_evt->addItem(
"kappaRec", m_nTrkRec , m_kappaRec);
1269 ntuple_evt->addItem(
"dzRec" , m_nTrkRec , m_dzRec );
1270 ntuple_evt->addItem(
"tanlRec" , m_nTrkRec , m_tanlRec );
1271 ntuple_evt->addItem(
"chargeRec" , m_nTrkRec , m_chargeRec );
1272 ntuple_evt->addItem(
"statRec" , m_nTrkRec , m_statRec );
1273 ntuple_evt->addItem(
"nhitsRec" , m_nTrkRec , m_nhitsRec );
1274 ntuple_evt->addItem(
"nclusterRec" , m_nTrkRec , m_nclusterRec );
1275 ntuple_evt->addItem(
"nsterRec" , m_nTrkRec , m_nsterRec );
1276 ntuple_evt->addItem(
"ndofRec" , m_nTrkRec , m_ndofRec );
1277 ntuple_evt->addItem(
"chi2Rec" , m_nTrkRec , m_chi2Rec );
1278 ntuple_evt->addItem(
"pxRec" , m_nTrkRec , m_pxRec );
1279 ntuple_evt->addItem(
"pyRec" , m_nTrkRec , m_pyRec );
1280 ntuple_evt->addItem(
"pzRec" , m_nTrkRec , m_pzRec );
1281 ntuple_evt->addItem(
"pxyRec" , m_nTrkRec , m_pxyRec );
1282 ntuple_evt->addItem(
"pRec" , m_nTrkRec , m_pRec );
1283 ntuple_evt->addItem(
"xRec" , m_nTrkRec , m_xRec );
1284 ntuple_evt->addItem(
"yRec" , m_nTrkRec , m_yRec );
1285 ntuple_evt->addItem(
"zRec" , m_nTrkRec , m_zRec );
1286 ntuple_evt->addItem(
"rRec" , m_nTrkRec , m_rRec );
1287 ntuple_evt->addItem(
"thetaRec" , m_nTrkRec , m_thetaRec );
1288 ntuple_evt->addItem(
"phiRec" , m_nTrkRec , m_phiRec );
1289 ntuple_evt->addItem(
"fiTermRec" , m_nTrkRec , m_fiTermRec );
1291 ntuple_evt->addItem(
"nTrkFit" , m_nTrkFit , 0,100);
1292 ntuple_evt->addItem(
"trkidFit", m_nTrkFit , m_trkidFit);
1293 ntuple_evt->addItem(
"drFit" , m_nTrkFit , m_drFit );
1294 ntuple_evt->addItem(
"phi0Fit" , m_nTrkFit , m_phi0Fit );
1295 ntuple_evt->addItem(
"kappaFit", m_nTrkFit , m_kappaFit);
1296 ntuple_evt->addItem(
"dzFit" , m_nTrkFit , m_dzFit );
1297 ntuple_evt->addItem(
"tanlFit" , m_nTrkFit , m_tanlFit );
1298 ntuple_evt->addItem(
"chargeFit" , m_nTrkFit , m_chargeFit );
1299 ntuple_evt->addItem(
"statFit" , m_nTrkFit , m_statFit );
1300 ntuple_evt->addItem(
"nhitsFit" , m_nTrkFit , m_nhitsFit );
1301 ntuple_evt->addItem(
"nclusterFit" , m_nTrkFit , m_nclusterFit );
1302 ntuple_evt->addItem(
"nsterFit" , m_nTrkFit , m_nsterFit );
1303 ntuple_evt->addItem(
"ndofFit" , m_nTrkFit , m_ndofFit );
1304 ntuple_evt->addItem(
"chi2Fit" , m_nTrkFit , m_chi2Fit );
1305 ntuple_evt->addItem(
"pxFit" , m_nTrkFit , m_pxFit );
1306 ntuple_evt->addItem(
"pyFit" , m_nTrkFit , m_pyFit );
1307 ntuple_evt->addItem(
"pzFit" , m_nTrkFit , m_pzFit );
1308 ntuple_evt->addItem(
"pxyFit" , m_nTrkFit , m_pxyFit );
1309 ntuple_evt->addItem(
"pFit" , m_nTrkFit , m_pFit );
1310 ntuple_evt->addItem(
"xFit" , m_nTrkFit , m_xFit );
1311 ntuple_evt->addItem(
"yFit" , m_nTrkFit , m_yFit );
1312 ntuple_evt->addItem(
"zFit" , m_nTrkFit , m_zFit );
1313 ntuple_evt->addItem(
"rFit" , m_nTrkFit , m_rFit );
1314 ntuple_evt->addItem(
"thetaFit" , m_nTrkFit , m_thetaFit );
1315 ntuple_evt->addItem(
"phiFit" , m_nTrkFit , m_phiFit );
1316 ntuple_evt->addItem(
"fiTermFit" , m_nTrkFit , m_fiTermFit );
1318 ntuple_evt->addItem(
"nTrkMC" , m_nTrkMC , 0,100);
1319 ntuple_evt->addItem(
"trkidMC", m_nTrkMC , m_trkidMC);
1320 ntuple_evt->addItem(
"drMC" , m_nTrkMC , m_drMC );
1321 ntuple_evt->addItem(
"phi0MC" , m_nTrkMC , m_phi0MC );
1322 ntuple_evt->addItem(
"kappaMC", m_nTrkMC , m_kappaMC);
1323 ntuple_evt->addItem(
"dzMC" , m_nTrkMC , m_dzMC );
1324 ntuple_evt->addItem(
"tanlMC" , m_nTrkMC , m_tanlMC );
1325 ntuple_evt->addItem(
"qMC" , m_nTrkMC , m_qMC );
1326 ntuple_evt->addItem(
"costhetaMC" , m_nTrkMC , m_costhetaMC );
1327 ntuple_evt->addItem(
"phiMC" , m_nTrkMC , m_phiMC );
1328 ntuple_evt->addItem(
"vzMC" , m_nTrkMC , m_vzMC );
1329 ntuple_evt->addItem(
"vrMC" , m_nTrkMC , m_vrMC );
1330 ntuple_evt->addItem(
"pxMC" , m_nTrkMC , m_pxMC );
1331 ntuple_evt->addItem(
"pyMC" , m_nTrkMC , m_pyMC );
1332 ntuple_evt->addItem(
"pzMC" , m_nTrkMC , m_pzMC );
1333 ntuple_evt->addItem(
"ptMC" , m_nTrkMC , m_ptMC );
1334 ntuple_evt->addItem(
"pMC" , m_nTrkMC , m_pMC );
1337 return StatusCode::SUCCESS;
bool sortCluster(const RecCgemCluster *clusterA, const RecCgemCluster *clusterB)
double abs(const EvtComplex &c)
HepGeom::Point3D< double > HepPoint3D
double sin(const BesAngle a)
double cos(const BesAngle a)
ObjectVector< RecMdcHit > RecMdcHitCol
SmartRefVector< RecCgemCluster > ClusterRefVec
ObjectVector< RecMdcTrack > RecMdcTrackCol
SmartRefVector< RecMdcHit > HitRefVec
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
double bFieldNominal() const
void setCgemCalibFunSvc(const CgemCalibFunSvc *svc)
const RecCgemCluster * baseHit() const
void setCgemGeomSvc(const CgemGeomSvc *svc)
CgemMdcFitAlg(const std::string &name, ISvcLocator *pSvcLocator)
void updateTracks(int trackId, TrkRecoTrk *trkRecoTrk, RecMdcTrack *recMdcTrack, int trkStat)
void compareTracks(MdcTrackList &mdcTrackList, double dzCut)
TrkErrCode check(TrkRecoTrk *trkRecoTrk, TrackType trackType)
TrkErrCode fit(RecMdcTrack *recMdcTrack, TrkRecoTrk *trkRecoTrk, TrackType trackType)
void setFirstLayer(const int id)
void setPxy(const double pxy)
void setTrackId(const int trackId)
void setPy(const double py)
void setZ(const double z)
void setNster(const int ns)
void setX(const double x)
void setError(double err[15])
void setNdof(const int ndof)
void setTheta(const double theta)
void setStat(const int stat)
void setP(const double p)
void setHelix(double helix[5])
void setPoca(double poca[3])
void setR(const double r)
void setCharge(const int charge)
void setLastLayer(const int id)
void setY(const double y)
void setChi2(const double chi)
void setPhi(const double phi)
void setPz(const double pz)
void setPx(const double px)
double dr(void) const
returns an element of parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
value_type get_value() const
double entranceAngle() const
const MdcLayer * layer() const
const MdcDigi * digi() const
void setCalibSvc(const MdcCalibFunSvc *calibSvc)
unsigned layernumber() const
unsigned wirenumber() const
unsigned adcIndex() const
double driftTime(double tof, double z) const
void setCountPropTime(const bool count)
double driftDist(double, int, double, double, double) const
const MdcLayer * layer() const
unsigned tdcIndex() const
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
const MdcHit * mdcHit() const
void setNoInner(bool noInnerFlag)
void remove(MdcTrack *atrack)
virtual Identifier identify() const
int getclusterid(void) const
int getlayerid(void) const
int getsheetid(void) const
void setMdcId(Identifier mdcid)
void setErrDriftDistRight(double erddr)
void setFltLen(double fltLen)
void setErrDriftDistLeft(double erddl)
void setDriftDistLeft(double ddl)
void setDoca(double doca)
void setChisqAdd(double pChisq)
void setZhit(double zhit)
void setDriftT(double driftT)
void setDriftDistRight(double ddr)
void setEntra(double entra)
const HitRefVec getVecHits(void) const
void setVecClusters(ClusterRefVec vecclusters)
void setPivot(const HepPoint3D &pivot)
void setVecHits(HitRefVec vechits)
void setFiTerm(double fiterm)
const ClusterRefVec getVecClusters() const
void setNcluster(int ncluster)
virtual void getInfo(double fltLen, HepPoint3D &pos, Hep3Vector &direction) const =0
virtual double pt(double fltL=0.) const =0
virtual double chisq() const =0
virtual int charge() const =0
virtual int nDof() const =0
virtual const TrkDifTraj & traj() const =0
virtual HepPoint3D position(double fltL) const =0
void setSuccess(int i, const char *str=0)
void setFailure(int i, const char *str=0)
const HepVector & params() const
const HepSymMatrix & covariance() const
virtual TrkExchangePar helix(double fltL) const =0
hot_iterator begin() const
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
const TrkHotList & hotList() const
double resid(bool exclude=false) const
const TrkRep * getParentRep() const
TrkErrCode getFitStuff(HepVector &derivs, double &deltaChi) const
hot_iterator begin() const
virtual int nActive(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual int nHit(TrkEnums::TrkViewInfo view=TrkEnums::bothView) const =0
virtual void print(std::ostream &) const
const BField & bField() const
const TrkFit * fitResult() const
virtual double arrivalTime(double fltL) const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const
TrkRecoTrk * makeTrack(const TrkExchangePar &helix, const double chi2, const TrkContext &, double trackT0) const
_EXTERN_ std::string RecMdcTrackCol
_EXTERN_ std::string RecMdcHitCol