15 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
32 #ifndef HLTCA_STANDALONE
44 #include "TParticlePDG.h"
45 #include "TDatabasePDG.h"
49 #include "Riostream.h"
56 PndFTSTopoPerformance::PndFTSTopoPerformance():fTopoReconstructor(0),fPrimVertices(),fFindParticlesMode(3)
60 void PndFTSTopoPerformance::SetNewEvent(
66 assert( PndFTSCAPerformance::Instance().GetSubPerformance(
"Global Performance") != 0 );
68 PndFTSParticlePerformanceBase::SetNewEvent(tracker, hitLabels, mcTracks, localMCPoints);
70 nRecoTracks = fTracker->NTracks();
75 assert( fTracker != 0 );
77 fTopoReconstructor = TopoReconstructor;
80 void PndFTSTopoPerformance::CheckMCTracks()
82 mcData = PndFTSCAPerformance::Instance().GetSubPerformance(
"Global Performance")->GetMCData();
86 for( ;(iPrimMC->
MotherId() != -1) && (iPrimMC < (*fMCTracks).Data() + nMCTracks); iPrimMC++);
87 if (iPrimMC < (*fMCTracks).Data() + nMCTracks) {
89 primVertex.
SetX( iPrimMC->
X() );
90 primVertex.
SetY( iPrimMC->
Y() );
91 primVertex.
SetZ( iPrimMC->
Z() );
92 fPrimVertices.push_back(primVertex);
96 void PndFTSTopoPerformance::GetMCParticles()
100 vMCParticles.clear();
103 for(
int iMC=0; iMC < nMCTracks; iMC++)
110 vMCParticles.push_back( part );
113 const unsigned int nMCParticles = vMCParticles.size();
114 for (
unsigned int iP = 0; iP < nMCParticles; iP++ ) {
116 for(
unsigned int iP2 = 0; iP2 < nMCParticles; iP2++) {
125 for(
unsigned int iMC=0; iMC < vMCParticles.size(); iMC++)
142 void PndFTSTopoPerformance::FindReconstructableMCParticles()
144 const unsigned int nMCParticles = vMCParticles.size();
146 for (
unsigned int iP = 0; iP < nMCParticles; iP++ ) {
148 CheckMCParticleIsReconstructable(part);
152 void PndFTSTopoPerformance::CheckMCParticleIsReconstructable(
KFMCParticle &part)
157 if ( part.
GetPDG() == -211 ||
168 switch ( fFindParticlesMode ) {
176 PndFTSCAPerformance::Instance().GetSubPerformance(
"Global Performance")->GetMCData()[iMCPart];
187 PndFTSCAPerformance::Instance().GetSubPerformance(
"Global Performance")->GetMCData()[iMCPart];
200 for(
int iPart=0; iPart<fParteff.nParticles; iPart++)
202 if(part.
GetPDG() == fParteff.partPDG[iPart])
204 const unsigned int nDaughters = fParteff.partDaughterPdg[iPart].size();
206 vector<int> pdg(nDaughters);
208 for(
unsigned int iD=0; iD<nDaughters; iD++)
211 vector<bool> isDaughterFound(nDaughters);
212 for(
unsigned int iDMC=0; iDMC<nDaughters; iDMC++)
213 isDaughterFound[iDMC] = 0;
216 for(
unsigned int iDMC=0; iDMC<nDaughters; iDMC++)
217 for(
unsigned int iD=0; iD<nDaughters; iD++)
218 if(pdg[iD] == fParteff.partDaughterPdg[iPart][iDMC]) isDaughterFound[iDMC] = 1;
220 for(
unsigned int iDMC=0; iDMC<nDaughters; iDMC++)
221 isReco = isReco && isDaughterFound[iDMC];
229 const unsigned int nD = dIds.size();
231 for (
unsigned int iD = 0; iD < nD &&
reco; iD++ ) {
233 CheckMCParticleIsReconstructable(dp);
240 void PndFTSTopoPerformance::MatchParticles()
243 MCtoRParticleId.clear();
244 RtoMCParticleId.clear();
245 MCtoRParticleId.resize(vMCParticles.size());
246 RtoMCParticleId.resize(fTopoReconstructor->GetParticles().size() );
249 for(
unsigned int iRP = 0; iRP < fTopoReconstructor->GetParticles().size(); iRP++ ) {
251 const KFParticle &rPart = fTopoReconstructor->GetParticles()[iRP];
256 const int mcTrackId = recoData[rTrackId].GetMCTrackId();
294 for (
unsigned int iMP = 0; iMP < vMCParticles.size(); iMP++ ) {
298 MCtoRParticleId[iMP].ids.push_back(iRP);
299 RtoMCParticleId[iRP].ids.push_back(iMP);
302 MCtoRParticleId[iMP].idsMI.push_back(iRP);
303 RtoMCParticleId[iRP].idsMI.push_back(iMP);
312 for(
unsigned int iRP = 0; iRP < fTopoReconstructor->GetParticles().size(); iRP++ ) {
314 const KFParticle &rPart = fTopoReconstructor->GetParticles()[iRP];
315 const unsigned int NRDaughters = rPart.
NDaughters();
316 if (NRDaughters < 2)
continue;
322 if ( !RtoMCParticleId[rdId].IsMatched() )
continue;
323 const int mdId = RtoMCParticleId[rdId].GetBestMatch();
324 mmId = vMCParticles[mdId].GetMotherId();
327 for ( ; iD < NRDaughters; iD++ ) {
329 if ( !RtoMCParticleId[rdId].IsMatched() )
break;
330 const int mdId = RtoMCParticleId[rdId].GetBestMatch();
331 if( vMCParticles[mdId].GetMotherId() != mmId )
break;
333 if ( iD == NRDaughters && mmId > -1 ) {
337 MCtoRParticleId[mmId].ids.push_back(iRP);
338 RtoMCParticleId[iRP].ids.push_back(mmId);
341 MCtoRParticleId[mmId].idsMI.push_back(iRP);
342 RtoMCParticleId[iRP].idsMI.push_back(mmId);
348 void PndFTSTopoPerformance::MatchTracks()
350 recoData = PndFTSCAPerformance::Instance().GetSubPerformance(
"Global Performance")->GetRecoData();
352 FindReconstructableMCParticles();
354 CalculateEfficiency();
358 void PndFTSTopoPerformance::CalculateEfficiency()
362 const int NRP = fTopoReconstructor->GetParticles().size();
363 for (
int iP = 0; iP < NRP; ++iP ) {
365 const KFParticle &part = fTopoReconstructor->GetParticles()[iP];
366 const int pdg = part.
GetPDG();
368 const bool isBG = RtoMCParticleId[iP].idsMI.size() != 0;
369 const bool isGhost = !RtoMCParticleId[iP].IsMatched();
371 for(
int iPart=0; iPart<fParteff.nParticles; iPart++)
372 if ( pdg == fParteff.partPDG[iPart] )
373 partEff.
IncReco(isGhost, isBG, fParteff.partName[iPart].Data());
376 const int NMP = vMCParticles.size();
377 for (
int iP = 0; iP < NMP; ++iP ) {
380 const int pdg = part.
GetPDG();
383 const bool isReco = MCtoRParticleId[iP].ids.size() != 0;
384 const int nClones = MCtoRParticleId[iP].ids.size() - 1;
386 for(
int iPart=0; iPart<fParteff.nParticles; iPart++)
388 if ( pdg == fParteff.partPDG[iPart] ) {
389 partEff.
Inc(isReco, nClones, fParteff.partName[iPart].Data());
391 partEff.
Inc(isReco, nClones, (fParteff.partName[iPart]+
"_prim").Data());
393 partEff.
Inc(isReco, nClones, (fParteff.partName[iPart]+
"_sec").Data());
408 cout <<
" ---- KF Particle finder --- " << endl;
412 cout <<
"ACCUMULATED STAT : " << fNEvents <<
" EVENTS " << endl << endl;
420 void PndFTSTopoPerformance::FillHistos()
422 PndFTSParticlePerformanceBase::FillHistos();
424 const int nParticles = fTopoReconstructor->fRTrackIds.size();
426 for(
int iP = 0; iP < nParticles; iP++){
428 const int itr = fTopoReconstructor->fRTrackIds[iP];
429 const int iMC = recoData[itr].GetMCTrackId();
444 KFParticle &
p = fTopoReconstructor->fKFPTopoReconstructor->GetParticle(iP);
446 float mcParPoint[6]={0};
456 for(
int iMCPoint=0; iMCPoint<nMCPoints; iMCPoint++)
459 mcPoint = points[iMCPoint];
462 if (
fabs(p.
X() - mcPoint.
X()) < 2.
f) {
463 if (
fabs(p.
Y() - mcPoint.
Y()) < 2.
f) {
464 if (
fabs(p.
Z() - mcPoint.
Z()) < 2.
f) {
471 if(MCindex == -1)
break;
474 const float mcX = mcPoint.
X();
475 const float mcY = mcPoint.
Y();
476 const float mcZ = mcPoint.
Z();
477 const float mcPx = mcPoint.
Px();
478 const float mcPy = mcPoint.
Py();
479 const float mcPz = mcPoint.
Pz();
484 mcParPoint[3] = mcPx;
485 mcParPoint[4] = mcPy;
486 mcParPoint[5] = mcPz;
489 if (
CAMath::Sqrt( mcPx*mcPx + mcPy*mcPy ) < 0.010 )
break;
493 GetHisto(
"resX")->Fill ( pTmp.
GetX() -
mcX );
494 GetHisto(
"resY")->Fill ( pTmp.
GetY() -
mcY );
495 GetHisto(
"resZ")->Fill ( pTmp.
GetZ() -
mcZ );
496 GetHisto(
"resPx")->Fill( pTmp.
GetPx() - mcPx );
497 GetHisto(
"resPy")->Fill( pTmp.
GetPy() - mcPy );
498 GetHisto(
"resPz")->Fill( pTmp.
GetPz() - mcPz );
514 const float mcX = mc.
X();
515 const float mcY = mc.
Y();
516 const float mcZ = mc.
Z();
517 const float mcPx = mc.
Px();
518 const float mcPy = mc.
Py();
519 const float mcPz = mc.
Pz();
523 const double vertex[3] = {
mcX,
mcY, mcZ };
531 mcMotherPDG = mcMother.
PDG();
598 if (
CAMath::Sqrt( mcPx*mcPx + mcPy*mcPy ) < 0.010 )
break;
603 GetHisto(
"resAtProdPointX")->Fill ( pTmp.
GetX() -
mcX );
604 GetHisto(
"resAtProdPointY")->Fill ( pTmp.
GetY() -
mcY );
605 GetHisto(
"resAtProdPointZ")->Fill ( pTmp.
GetZ() -
mcZ );
606 GetHisto(
"resAtProdPointPx")->Fill( pTmp.
GetPx() - mcPx );
607 GetHisto(
"resAtProdPointPy")->Fill( pTmp.
GetPy() - mcPy );
608 GetHisto(
"resAtProdPointPz")->Fill( pTmp.
GetPz() - mcPz );
610 if ( pTmp.
GetErrX() > 0 ) GetHisto(
"pullAtProdPointX")->Fill ( ( pTmp.
GetX() -
mcX ) / pTmp.
GetErrX() );
611 if ( pTmp.
GetErrY() > 0 ) GetHisto(
"pullAtProdPointY")->Fill ( ( pTmp.
GetY() -
mcY ) / pTmp.
GetErrY() );
612 if ( pTmp.
GetErrZ() > 0 ) GetHisto(
"pullAtProdPointZ")->Fill ( ( pTmp.
GetZ() -
mcZ ) / pTmp.
GetErrZ() );
613 if ( pTmp.
GetErrPx() > 0 ) GetHisto(
"pullAtProdPointPx")->Fill( ( pTmp.
GetPx() - mcPx ) / pTmp.
GetErrPx() );
614 if ( pTmp.
GetErrPy() > 0 ) GetHisto(
"pullAtProdPointPy")->Fill( ( pTmp.
GetPy() - mcPy ) / pTmp.
GetErrPy() );
615 if ( pTmp.
GetErrPz() > 0 ) GetHisto(
"pullAtProdPointPz")->Fill( ( pTmp.
GetPz() - mcPz ) / pTmp.
GetErrPz() );
621 if (fPrimVertices.size() == 0)
break;
624 const float mcX = fPrimVertices[0].X();
625 const float mcY = fPrimVertices[0].Y();
626 const float mcZ = fPrimVertices[0].Z();
629 KFParticle &pTmp = fTopoReconstructor->fKFPTopoReconstructor->GetPrimVertex();
633 GetHisto(
"resVertexX")->Fill ( pTmp.
GetX() -
mcX );
634 GetHisto(
"resVertexY")->Fill ( pTmp.
GetY() -
mcY );
635 GetHisto(
"resVertexZ")->Fill ( pTmp.
GetZ() -
mcZ );
646 for(
unsigned int iP=0; iP<fTopoReconstructor->GetParticles().size(); iP++)
649 int iParticle = fParteff.GetParticleIndex(fTopoReconstructor->GetParticles()[iP].GetPDG());
650 if(iParticle < 0)
continue;
662 KFParticle TempPart = fTopoReconstructor->GetParticles()[iP];
665 Pt = TempPart.
GetPt();
670 Int_t ndf = TempPart.
GetNDF();
671 Double_t prob = TMath::Prob(chi2, ndf);
684 dL =
sqrt(TempPart.
X()*TempPart.
X() + TempPart.
Y()*TempPart.
Y() + TempPart.
Z()*TempPart.
Z() );
687 hPartParam[iParticle][ 0]->Fill(M);
688 hPartParam[iParticle][ 1]->Fill(P);
689 hPartParam[iParticle][ 2]->Fill(Pt);
690 hPartParam[iParticle][ 3]->Fill(Rapidity);
691 hPartParam[iParticle][ 4]->Fill(dL);
692 hPartParam[iParticle][ 5]->Fill(cT);
693 hPartParam[iParticle][ 6]->Fill(chi2/ndf);
694 hPartParam[iParticle][ 7]->Fill(prob);
695 hPartParam[iParticle][ 8]->Fill(Theta);
696 hPartParam[iParticle][ 9]->Fill(Phi);
697 hPartParam[iParticle][10]->Fill(Z);
698 hPartParam[iParticle][11]->Fill(l[0]/dl[0]);
701 hPartParam2D[iParticle][0]->Fill(Rapidity,Pt,1);
703 if(!RtoMCParticleId[iP].IsMatchedWithPdg())
705 if(!RtoMCParticleId[iP].IsMatched())
708 hPartParamGhost[iParticle][ 0]->Fill(M);
709 hPartParamGhost[iParticle][ 1]->Fill(P);
710 hPartParamGhost[iParticle][ 2]->Fill(Pt);
711 hPartParamGhost[iParticle][ 3]->Fill(Rapidity);
712 hPartParamGhost[iParticle][ 4]->Fill(dL);
713 hPartParamGhost[iParticle][ 5]->Fill(cT);
714 hPartParamGhost[iParticle][ 6]->Fill(chi2/ndf);
715 hPartParamGhost[iParticle][ 7]->Fill(prob);
716 hPartParamGhost[iParticle][ 8]->Fill(Theta);
717 hPartParamGhost[iParticle][ 9]->Fill(Phi);
718 hPartParamGhost[iParticle][10]->Fill(Z);
719 hPartParamGhost[iParticle][11]->Fill(l[0]/dl[0]);
721 hPartParam2DGhost[iParticle][0]->Fill(Rapidity,Pt,1);
727 hPartParamBG[iParticle][ 0]->Fill(M);
728 hPartParamBG[iParticle][ 1]->Fill(P);
729 hPartParamBG[iParticle][ 2]->Fill(Pt);
730 hPartParamBG[iParticle][ 3]->Fill(Rapidity);
731 hPartParamBG[iParticle][ 4]->Fill(dL);
732 hPartParamBG[iParticle][ 5]->Fill(cT);
733 hPartParamBG[iParticle][ 6]->Fill(chi2/ndf);
734 hPartParamBG[iParticle][ 7]->Fill(prob);
735 hPartParamBG[iParticle][ 8]->Fill(Theta);
736 hPartParamBG[iParticle][ 9]->Fill(Phi);
737 hPartParamBG[iParticle][10]->Fill(Z);
738 hPartParamBG[iParticle][11]->Fill(l[0]/dl[0]);
740 hPartParam2DBG[iParticle][0]->Fill(Rapidity,Pt,1);
745 hPartParamSignal[iParticle][ 0]->Fill(M);
746 hPartParamSignal[iParticle][ 1]->Fill(P);
747 hPartParamSignal[iParticle][ 2]->Fill(Pt);
748 hPartParamSignal[iParticle][ 3]->Fill(Rapidity);
749 hPartParamSignal[iParticle][ 4]->Fill(dL);
750 hPartParamSignal[iParticle][ 5]->Fill(cT);
751 hPartParamSignal[iParticle][ 6]->Fill(chi2/ndf);
752 hPartParamSignal[iParticle][ 7]->Fill(prob);
753 hPartParamSignal[iParticle][ 8]->Fill(Theta);
754 hPartParamSignal[iParticle][ 9]->Fill(Phi);
755 hPartParamSignal[iParticle][10]->Fill(Z);
756 hPartParamSignal[iParticle][11]->Fill(l[0]/dl[0]);
758 hPartParam2DSignal[iParticle][0]->Fill(Rapidity,Pt,1);
760 int iMCPart = RtoMCParticleId[iP].GetBestMatchWithPdg();
769 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(mcTrack.
PDG());
771 const float mcX = mcDaughter.
X();
772 const float mcY = mcDaughter.
Y();
773 const float mcZ = mcDaughter.
Z();
774 const float mcPx = mcTrack.
Par(3)*mcTrack.
P();
775 const float mcPy = mcTrack.
Par(4)*mcTrack.
P();
776 const float mcPz = mcTrack.
Par(5)*mcTrack.
P();
782 for(
int iPar=0; iPar<3; iPar++)
786 if(error < 0.) { error = 1.e20;}
790 for(
int iPar=3; iPar<7; iPar++)
794 if(error < 0.) { error = 1.e20;}
798 Double_t massMC = (particlePDG) ? particlePDG->Mass() :0.13957;
803 mcParam[8] = { decayVtx[0], decayVtx[1], decayVtx[2],
804 mcPx, mcPy, mcPz,
Emc, massMC };
805 for(
int iPar=0; iPar < 7; iPar++ )
807 res[iPar] = recParam[iPar] - mcParam[iPar];
808 if(
fabs(errParam[iPar]) > 1.e-20) pull[iPar] = res[iPar]/errParam[iPar];
811 res[7] = M - mcParam[7];
812 if(
fabs(ErrM) > 1.e-20) pull[7] = res[7]/ErrM;
814 for(
int iPar=0; iPar < 8; iPar++ )
816 hFitQA[iParticle][iPar]->Fill(res[iPar]);
817 hFitQA[iParticle][iPar+8]->Fill(pull[iPar]);
869 if(!MCtoRParticleId[mcDaughterId].IsMatched())
continue;
872 int recDaughterId = MCtoRParticleId[mcDaughterId].GetBestMatch();
874 KFParticle Daughter = fTopoReconstructor->GetParticles()[recDaughterId];
877 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(mcTrack.
PDG());
879 const float mcX = mcTrack.
X();
880 const float mcY = mcTrack.
Y();
881 const float mcZ = mcTrack.
Z();
882 const float mcPx = mcTrack.
Px();
883 const float mcPy = mcTrack.
Py();
884 const float mcPz = mcTrack.
Pz();
889 Double_t massMC = (particlePDG) ? particlePDG->Mass() :0.13957;
895 mcPx, mcPy, mcPz,
Emc, massMC };
896 for(
int iPar=0; iPar < 7; iPar++ )
899 if(error < 0.) { error = 1.e20;}
901 res[iPar] = Daughter.
GetParameter(iPar) - mcParam[iPar];
902 if(
fabs(error) > 1.e-20) pull[iPar] = res[iPar]/
error;
904 res[7] = M - mcParam[7];
905 if(
fabs(ErrM) > 1.e-20) pull[7] = res[7]/ErrM;
907 for(
int iPar=0; iPar < 8; iPar++ )
909 hFitDaughtersQA[iParticle][iPar]->Fill(res[iPar]);
910 hFitDaughtersQA[iParticle][iPar+8]->Fill(pull[iPar]);
916 for(
unsigned int iP=0; iP<fTopoReconstructor->GetParticles().size(); iP++)
918 const KFParticle &rPart = fTopoReconstructor->GetParticles()[iP];
919 const unsigned int NRDaughters = rPart.
NDaughters();
920 if (NRDaughters > 1)
break;
921 if( RtoMCParticleId[iP].GetBestMatch()<0 )
continue;
923 KFMCParticle &mPart = vMCParticles[ RtoMCParticleId[iP].GetBestMatch() ];
932 int iParticle = fParteff.GetParticleIndex(mMotherPart.
GetPDG());
933 float chiPrim = fTopoReconstructor->GetChiPrim()[iP];
935 hTrackParameters[iParticle]->Fill(chiPrim );
941 float mcPVx[3]={0.f};
942 for(
int iMC=0; iMC<nMCTracks; ++iMC)
947 mcPVx[0]=mcTrack.
X();
948 mcPVx[1]=mcTrack.
Y();
949 mcPVx[2]=mcTrack.
Z();
954 KFParticle & vtx = fTopoReconstructor->GetPrimVertex();
955 double dRPVr[3] = {vtx.
X()-mcPVx[0],
961 for(
unsigned int iHPV=0; iHPV<3; ++iHPV)
962 hPVFitQa[iHPV]->
Fill(dRPVr[iHPV]);
963 for(
unsigned int iHPV=3; iHPV<6; ++iHPV)
964 hPVFitQa[iHPV]->
Fill(dRPVp[iHPV-3]);
968 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE
static const float MinTrackPurity
Double_t GetMomentum() const
Double_t GetRapidity() const
void Inc(bool isReco, int nClones, TString name)
friend F32vec4 sqrt(const F32vec4 &a)
static T Sqrt(const T &x)
Double_t * CovarianceMatrix()
void GetDistanceToVertexLine(const KFParticleBaseSIMD &Vertex, fvec &l, fvec &dl, fvec *isParticleFromVertex=0) const
Double_t GetDStoPoint(const Double_t xyz[]) const
void IncReco(bool isGhost, bool isBg, TString name)
Double_t GetTheta() const
static void error(int no)
void TransportToPoint(const Double_t xyz[])
const vector< int > & GetDaughterIds() const
Double_t GetCovariance(int i) const
void TransportToDS(Double_t dS)
friend F32vec4 fabs(const F32vec4 &a)
void SetMCTrackID(int id)
HISThit_ene Fill(sum_hit_ene)
Double_t GetErrPz() const
bool IsReconstructable() const
const Double_t & X() const
void SetAsReconstructable()
const std::vector< int > & DaughterIds() const
const Double_t & Z() const
Double_t GetErrPx() const
Double_t GetLifeTime() const
Double_t GetErrPy() const
static const int nParticles
Double_t GetParameter(int i) const
const Double_t & Y() const
Double_t GetDecayLength() const
int FirstMCPointID() const