File indexing completed on 2025-08-05 08:15:14
0001 #include "TrackingPerformanceCheck.h"
0002
0003 #include <phool/getClass.h>
0004 #include <fun4all/Fun4AllServer.h>
0005
0006 #include <g4main/PHG4TruthInfoContainer.h>
0007 #include <g4main/PHG4Particle.h>
0008 #include <g4main/PHG4VtxPoint.h>
0009
0010 #include <g4hough/SvtxVertexMap.h>
0011 #include <g4hough/SvtxVertex.h>
0012 #include <g4hough/SvtxTrackMap.h>
0013 #include <g4hough/SvtxTrack.h>
0014 #include <g4hough/SvtxClusterMap.h>
0015 #include <g4hough/SvtxCluster.h>
0016
0017 #include <g4eval/SvtxEvalStack.h>
0018 #include <g4eval/SvtxTrackEval.h>
0019 #include <g4eval/SvtxVertexEval.h>
0020 #include <g4eval/SvtxTruthEval.h>
0021
0022 #include "TMath.h"
0023 #include <TH1F.h>
0024 #include <TH2F.h>
0025 #include <TH1D.h>
0026 #include <TH2D.h>
0027 #include "TString.h"
0028
0029 #include <iostream>
0030
0031 using namespace std;
0032
0033 TrackingPerformanceCheck::TrackingPerformanceCheck(const string &name) :
0034 SubsysReco(name),
0035 fLayerTPCBegins(7),
0036 fReconstructable_TPCHits(30),
0037 fFair_ClustersContribution(20),
0038 fGTrack_Chi2NDF(2.0),
0039 fGTrack_TPCClusters(20)
0040 {
0041 }
0042
0043 int TrackingPerformanceCheck::Init(PHCompositeNode *topNode) {
0044
0045 Fun4AllServer *se = Fun4AllServer::instance();
0046
0047 const int nptbinsPONE = 52;
0048 Int_t nptbins = nptbinsPONE - 1;
0049 Double_t ptbins[nptbinsPONE];
0050 ptbins[0] = 0.2;
0051 for(int i=1; i!=9; ++i)
0052 ptbins[i] = 0.2 + i*0.2;
0053 for(int i=0; i!=11; ++i)
0054 ptbins[9+i] = 2.0 + i*0.5;
0055 for(int i=0; i!=10; ++i)
0056 ptbins[20+i] = 8.0 + i*1.0;
0057 for(int i=0; i!=12; ++i)
0058 ptbins[30+i] = 18.0 + i*2.0;
0059 for(int i=0; i!=10; ++i)
0060 ptbins[42+i] = 45.0 + i*5.0;
0061
0062 for(int i=0; i!=nptbinsPONE; ++i) std::cout << i << " " << ptbins[i] << std::endl;
0063
0064 fHNEvents = new TH1F("Events","Events",1,-0.5,0.5);
0065 se->registerHisto(fHNEvents);
0066
0067 TString sTname[5] = {"AllG4Particles","Primaries","Embedded","Reconstructables","RecoMatched"};
0068 for(int i=0; i!=5; ++i) {
0069 fHTN[i] = new TH1F(Form("Truths%d_N",i),Form("Number of %s",sTname[i].Data()),50,-0.5,49.5);
0070 fHTPt[i] = new TH1F(Form("Truths%d_Pt",i),Form("%s Pt",sTname[i].Data()),nptbins,ptbins);
0071 fHTPhi[i] = new TH1F(Form("Truths%d_Phi",i),Form("%s Phi",sTname[i].Data()),100,0,TMath::TwoPi());
0072 fHTEta[i] = new TH1F(Form("Truths%d_Eta",i),Form("%s Eta",sTname[i].Data()),100,-10,+10);
0073 se->registerHisto(fHTN[i]);
0074 se->registerHisto(fHTPt[i]);
0075 se->registerHisto(fHTPhi[i]);
0076 se->registerHisto(fHTEta[i]);
0077 if(i<2) continue;
0078 fHTNHits[i] = new TH1F(Form("Truths%d_Hits",i),Form("Number of TPCHits in %s",sTname[i].Data()),61,-0.5,60.5);
0079 se->registerHisto(fHTNHits[i]);
0080 if(i<4) continue;
0081 fHTChi2[i] = new TH2F(Form("Truths%d_Chi2NDF",i),Form("%s Chi2NDF;PT;CHI2NDF",sTname[i].Data()),nptbins,ptbins,100,0,5);
0082 fHTDca2D[i] = new TH2F( Form("Truths%d_Dca2D",i),Form("%s Dca2D;PT;DCA2D",sTname[i].Data()),nptbins,ptbins,200,-0.003,+0.003);
0083 fHTNClustersContribution[i] = new TH2F(Form("Truths%d_NClusters",i), Form("%s Number of Clusters Matched",sTname[i].Data()), nptbins,ptbins,70,-0.5,69.5);
0084 fHTPtResolution[i] = new TH2F(Form("Truths%d_ResPt",i), Form("%s PtResolution;PT;REL DIFF",sTname[i].Data()), nptbins,ptbins,400,-1.1,+1.1);
0085 fHTPtResolution2[i] = new TH2F(Form("Truths%d_Res2Pt",i), Form("%s PtResolution2;PT;DIFF",sTname[i].Data()), nptbins,ptbins,400,-0.2,+0.2);
0086 fHTPhiResolution[i] = new TH2F(Form("Truths%d_ResPhi",i), Form("%s PhiResolution;PT;REL DIFF",sTname[i].Data()), nptbins,ptbins,200,-0.1,+0.1);
0087 fHTEtaResolution[i] = new TH2F(Form("Truths%d_ResEta",i), Form("%s EtaResolution;PT;REL DIFF",sTname[i].Data()), nptbins,ptbins,200,-0.1,+0.1);
0088 se->registerHisto(fHTChi2[i]);
0089 se->registerHisto(fHTDca2D[i]);
0090 se->registerHisto(fHTNClustersContribution[i]);
0091 se->registerHisto(fHTPtResolution[i]);
0092 se->registerHisto(fHTPtResolution2[i]);
0093 se->registerHisto(fHTPhiResolution[i]);
0094 se->registerHisto(fHTEtaResolution[i]);
0095 }
0096
0097 TString sRname[4] = {"AllTracks","GoodTracks","GTracksM2R","GTracksExcess"};
0098 for(int i=0; i!=4; ++i) {
0099 fHRN[i] = new TH1F(Form("Tracks%d_N",i),Form("Number of %s",sRname[i].Data()),100,-0.5,1999.5);
0100 fHRPt[i] = new TH1F(Form("Tracks%d_Pt",i),Form("%s Pt",sRname[i].Data()),nptbins,ptbins);
0101 fHRPhi[i] = new TH1F(Form("Tracks%d_Phi",i),Form("%s Phi",sRname[i].Data()),100,0,TMath::TwoPi());
0102 fHREta[i] = new TH1F(Form("Tracks%d_Eta",i),Form("%s Eta",sRname[i].Data()),100,-1.5,+1.5);
0103 fHRTPCClus[i] = new TH2F(Form("Tracks%d_TPCClus",i),Form("%s TPCCLus;PT;TPCClusters",sRname[i].Data()),nptbins,ptbins,70,-0.5,69.5);
0104 fHRChi2[i] = new TH2F(Form("Tracks%d_Chi2NDF",i),Form("%s Chi2NDF;PT;CHI2NDF",sRname[i].Data()),nptbins,ptbins,100,0,5);
0105 fHRDca2D[i] = new TH2F( Form("Tracks%d_Dca2D",i),Form("%s Dca2D;PT;DCA2D",sRname[i].Data()),nptbins,ptbins,200,-0.003,+0.003);
0106 se->registerHisto(fHRN[i]);
0107 se->registerHisto(fHRPt[i]);
0108 se->registerHisto(fHRPhi[i]);
0109 se->registerHisto(fHREta[i]);
0110 se->registerHisto(fHRTPCClus[i]);
0111 se->registerHisto(fHRChi2[i]);
0112 se->registerHisto(fHRDca2D[i]);
0113 if(i<2) continue;
0114 fHRPtResolution[i] = new TH2F(Form("Tracks%d_ResPt",i), Form("%s PtResolution;PT;REL DIFF",sRname[i].Data()), nptbins,ptbins,400,-1.5,+1.5);
0115 fHRPtResolution2[i] = new TH2F(Form("Tracks%d_Res2Pt",i), Form("%s PtResolution2;PT;DIFF",sRname[i].Data()), nptbins,ptbins,400,-0.2,+0.2);
0116 fHRPhiResolution[i] = new TH2F(Form("Tracks%d_ResPhi",i), Form("%s PhiResolution;PT;REL DIFF",sRname[i].Data()), nptbins,ptbins,200,-0.1,+0.1);
0117 fHREtaResolution[i] = new TH2F(Form("Tracks%d_ResEta",i), Form("%s EtaResolution;PT;REL DIFF",sRname[i].Data()), nptbins,ptbins,200,-0.1,+0.1);
0118 fHRNClustersContribution[i] = new TH2F(Form("Tracks%d_NClustersContri",i), Form("%s Number of Clusters Contribution",sRname[i].Data()), nptbins,ptbins,70,-0.5,69.5);
0119 se->registerHisto(fHRPtResolution[i]);
0120 se->registerHisto(fHRPtResolution2[i]);
0121 se->registerHisto(fHRPhiResolution[i]);
0122 se->registerHisto(fHREtaResolution[i]);
0123 se->registerHisto(fHRNClustersContribution[i]);
0124 }
0125
0126 fHNVertexes = new TH1F("Vertexes_N","Number of Vertexes",10,-0.5,9.5);
0127 se->registerHisto(fHNVertexes);
0128 return 0;
0129 }
0130
0131 int TrackingPerformanceCheck::process_event(PHCompositeNode *topNode) {
0132
0133 fHNEvents->Fill(0);
0134 fEmbedded.clear();
0135 PHG4TruthInfoContainer* truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode,"G4TruthInfo");
0136 SvtxTrackMap *trackmap = findNode::getClass<SvtxTrackMap>(topNode,"SvtxTrackMap");
0137 SvtxClusterMap *clustermap = findNode::getClass<SvtxClusterMap>(topNode,"SvtxClusterMap");
0138 SvtxVertexMap* vertexmap = findNode::getClass<SvtxVertexMap>(topNode,"SvtxVertexMap");
0139 if (!truthinfo) {
0140 cerr << PHWHERE << " ERROR: Can't find G4TruthInfo" << endl;
0141 exit(-1);
0142 }
0143 if (!trackmap) {
0144 cerr << PHWHERE << " ERROR: Can't find SvtxTrackMap" << endl;
0145 exit(-1);
0146 }
0147 if (!vertexmap) {
0148 cerr << PHWHERE << " ERROR: Can't find SvtxVertexMap" << endl;
0149 exit(-1);
0150 }
0151
0152
0153 std::pair< std::map<int,int>::const_iterator, std::map<int,int>::const_iterator > rangeE = truthinfo->GetEmbeddedTrkIds();
0154 for(std::map<int,int>::const_iterator iterE=rangeE.first; iterE!=rangeE.second; ++iterE) {
0155 int tid = (*iterE).first;
0156 int tem = (*iterE).second;
0157 if (tem > 0)
0158 fEmbedded.insert( std::make_pair(tid,tem) );
0159 }
0160
0161
0162 SvtxEvalStack svtxevalstack(topNode);
0163 SvtxTruthEval *trutheval = svtxevalstack.get_truth_eval();
0164 SvtxTrackEval *trackeval = svtxevalstack.get_track_eval();
0165
0166 PHG4TruthInfoContainer::Range range = truthinfo->GetParticleRange();
0167 int nA=0;
0168 int nB=0;
0169 int nC=0;
0170 int nD=0;
0171 for(PHG4TruthInfoContainer::ConstIterator iter = range.first;
0172 iter != range.second;
0173 ++iter) {
0174 PHG4Particle* g4particle = iter->second;
0175 if(!g4particle) continue;
0176 nA++;
0177 float px = g4particle->get_px();
0178 float py = g4particle->get_py();
0179 float pz = g4particle->get_pz();
0180 float pt = TMath::Sqrt( px*px + py*py );
0181 float p = TMath::Sqrt( px*px + py*py + pz*pz );
0182 float phi = TMath::Pi()+TMath::ATan2(-py,-px);
0183 float eta = 1.e30;
0184 if(p != TMath::Abs(pz)) eta = 0.5*TMath::Log((p+pz)/(p-pz));
0185 fHTPt[0]->Fill(pt);
0186 fHTPhi[0]->Fill(phi);
0187 fHTEta[0]->Fill(eta);
0188 if( iter->first < 0 ) continue;
0189 nB++;
0190 fHTPt[1]->Fill(pt);
0191 fHTPhi[1]->Fill(phi);
0192 fHTEta[1]->Fill(eta);
0193 int id = g4particle->get_track_id();
0194 std::map<int,int>::iterator embeddedflag = fEmbedded.find(id);
0195 if(embeddedflag==fEmbedded.end()) continue;
0196 if((*embeddedflag).second==0) continue;
0197
0198 nC++;
0199
0200 std::set<PHG4Hit*> g4hits = trutheval->all_truth_hits(g4particle);
0201 bool hit[70];
0202 for(int i=0; i!=70; ++i) hit[i] = false;
0203 for(std::set<PHG4Hit*>::iterator iter = g4hits.begin();
0204 iter != g4hits.end();
0205 ++iter) {
0206 PHG4Hit *candidate = *iter;
0207 unsigned int lyr = candidate->get_layer();
0208 hit[lyr] = true;
0209 }
0210 int nhits = 0;
0211 for(int i=fLayerTPCBegins; i!=70; ++i) if(hit[i]) nhits++;
0212 fHTPt[2]->Fill(pt);
0213 fHTPhi[2]->Fill(phi);
0214 fHTEta[2]->Fill(eta);
0215 fHTNHits[2]->Fill( nhits );
0216
0217 if(nhits<fReconstructable_TPCHits) continue;
0218 (*embeddedflag).second = 2;
0219 nD++;
0220 fHTPt[3]->Fill(pt);
0221 fHTPhi[3]->Fill(phi);
0222 fHTEta[3]->Fill(eta);
0223 fHTNHits[3]->Fill( nhits );
0224 SvtxTrack *best = trackeval->best_track_from(g4particle);
0225 if(!best) continue;
0226
0227 float rpx = best->get_px();
0228 float rpy = best->get_py();
0229 float rpz = best->get_pz();
0230 float rpt = TMath::Sqrt( rpx*rpx + rpy*rpy );
0231 float rp = TMath::Sqrt( rpx*rpx + rpy*rpy + rpz*rpz );
0232 float rphi = TMath::Pi()+TMath::ATan2(-rpy,-rpx);
0233 float reta = 1.e30;
0234 if(rp != TMath::Abs(rpz)) reta = 0.5*TMath::Log((rp+rpz)/(rp-rpz));
0235 int nclusterscontrib = int( trackeval->get_nclusters_contribution(best,g4particle) );
0236 if(nclusterscontrib<fFair_ClustersContribution) continue;
0237 float rdca2d = best->get_dca2d();
0238 int ndf = int(best->get_ndf());
0239 float chi2ndf = -1;
0240 if(ndf!=0) chi2ndf = best->get_chisq() / ndf;
0241 float ptreldiff = (rpt-pt)/pt;
0242 float ptdiff = rpt-pt;
0243 float phireldiff = (rphi-phi)/phi;
0244 float etareldiff = (reta-eta)/eta;
0245 fHTPt[4]->Fill(pt);
0246 fHTPhi[4]->Fill(phi);
0247 fHTEta[4]->Fill(eta);
0248 fHTNHits[4]->Fill( nhits );
0249 fHTChi2[4]->Fill(chi2ndf,ptreldiff);
0250 fHTDca2D[4]->Fill(pt,rdca2d);
0251 fHTPtResolution[4]->Fill(pt,ptreldiff);
0252 fHTPtResolution2[4]->Fill(pt,ptdiff);
0253 fHTPhiResolution[4]->Fill(pt,phireldiff);
0254 fHTEtaResolution[4]->Fill(pt,etareldiff);
0255 fHTNClustersContribution[4]->Fill(pt, nclusterscontrib );
0256 }
0257 fHTN[0]->Fill(nA);
0258 fHTN[1]->Fill(nB);
0259 fHTN[2]->Fill(nC);
0260 fHTN[3]->Fill(nD);
0261
0262
0263 nA = 0;
0264 nB = 0;
0265 nC = 0;
0266 nD = 0;
0267
0268 for(SvtxTrackMap::Iter iter = trackmap->begin();
0269 iter != trackmap->end(); ++iter) {
0270
0271 nA++;
0272 SvtxTrack *track = iter->second;
0273 if (!track) continue;
0274
0275 int tpcclus=0;
0276 for (SvtxTrack::ConstClusterIter iter = track->begin_clusters();
0277 iter != track->end_clusters(); ++iter) {
0278 unsigned int cluster_id = *iter;
0279 SvtxCluster* cluster = clustermap->get(cluster_id);
0280 if(!cluster) continue;
0281 int lyr = cluster->get_layer();
0282 if(lyr>=fLayerTPCBegins) tpcclus++;
0283 }
0284 float rpx = track->get_px();
0285 float rpy = track->get_py();
0286 float rpz = track->get_pz();
0287 float rpt = TMath::Sqrt( rpx*rpx + rpy*rpy );
0288 float rp = TMath::Sqrt( rpx*rpx + rpy*rpy + rpz*rpz );
0289 float rphi = TMath::Pi()+TMath::ATan2(-rpy,-rpx);
0290 float reta = 1.e30;
0291 if(rp != TMath::Abs(rpz)) reta = 0.5*TMath::Log((rp+rpz)/(rp-rpz));
0292 float rdca2d = track->get_dca2d();
0293 int ndf = int(track->get_ndf());
0294 float chi2ndf = -1;
0295 if(ndf!=0) chi2ndf = track->get_chisq() / ndf;
0296 fHRPt[0]->Fill(rpt);
0297 fHRPhi[0]->Fill(rphi);
0298 fHREta[0]->Fill(reta);
0299 fHRTPCClus[0]->Fill(rpt,tpcclus);
0300 fHRChi2[0]->Fill(rpt,chi2ndf);
0301 fHRDca2D[0]->Fill(rpt,rdca2d);
0302 if(chi2ndf>fGTrack_Chi2NDF) continue;
0303 if(tpcclus<fGTrack_TPCClusters) continue;
0304
0305 nB++;
0306 fHRPt[1]->Fill(rpt);
0307 fHRPhi[1]->Fill(rphi);
0308 fHREta[1]->Fill(reta);
0309 fHRTPCClus[1]->Fill(rpt,tpcclus);
0310 fHRChi2[1]->Fill(rpt,chi2ndf);
0311 fHRDca2D[1]->Fill(rpt,rdca2d);
0312
0313 PHG4Particle* g4particle = trackeval->max_truth_particle_by_nclusters(track);
0314 if(!g4particle) continue;
0315
0316
0317
0318
0319
0320 int id = g4particle->get_track_id();
0321 std::map<int,int>::iterator embeddedflag = fEmbedded.find(id);
0322 if(embeddedflag==fEmbedded.end()) continue;
0323
0324 if((*embeddedflag).second==0) continue;
0325
0326 if((*embeddedflag).second==1) continue;
0327 if((*embeddedflag).second>1) (*embeddedflag).second++;
0328
0329
0330 nC++;
0331 float px = g4particle->get_px();
0332 float py = g4particle->get_py();
0333 float pz = g4particle->get_pz();
0334 float pt = TMath::Sqrt( px*px + py*py );
0335 float p = TMath::Sqrt( px*px + py*py + pz*pz );
0336 float phi = TMath::Pi()+TMath::ATan2(-py,-px);
0337 float eta = 1.e30;
0338 if(p != TMath::Abs(pz)) eta = 0.5*TMath::Log((p+pz)/(p-pz));
0339 int nclusterscontrib = int( trackeval->get_nclusters_contribution(track,g4particle) );
0340 float ptreldiff = (rpt-pt)/pt;
0341 float ptdiff = rpt-pt;
0342 float phireldiff = (rphi-phi)/phi;
0343 float etareldiff = (reta-eta)/eta;
0344 fHRPt[2]->Fill(rpt);
0345 fHRPhi[2]->Fill(rphi);
0346 fHREta[2]->Fill(reta);
0347 fHRTPCClus[2]->Fill(rpt,tpcclus);
0348 fHRChi2[2]->Fill(rpt,chi2ndf);
0349 fHRDca2D[2]->Fill(rpt,rdca2d);
0350 fHRPtResolution[2]->Fill(pt,ptreldiff);
0351 fHRPtResolution2[2]->Fill(pt,ptdiff);
0352 fHRPhiResolution[2]->Fill(pt,phireldiff);
0353 fHREtaResolution[2]->Fill(pt,etareldiff);
0354 fHRNClustersContribution[2]->Fill(pt, nclusterscontrib);
0355 if((*embeddedflag).second<4) continue;
0356
0357 nD++;
0358 fHRPt[3]->Fill(rpt);
0359 fHRPhi[3]->Fill(rphi);
0360 fHREta[3]->Fill(reta);
0361 fHRTPCClus[2]->Fill(rpt,tpcclus);
0362 fHRChi2[3]->Fill(rpt,chi2ndf);
0363 fHRDca2D[3]->Fill(rpt,rdca2d);
0364 fHRPt[3]->Fill(rpt);
0365 fHRPhi[3]->Fill(rphi);
0366 fHREta[3]->Fill(reta);
0367 fHRChi2[3]->Fill(rpt,chi2ndf);
0368 fHRDca2D[3]->Fill(rpt,rdca2d);
0369 fHRPtResolution[3]->Fill(pt,ptreldiff);
0370 fHRPtResolution2[3]->Fill(pt,ptdiff);
0371 fHRPhiResolution[3]->Fill(pt,phireldiff);
0372 fHREtaResolution[3]->Fill(pt,etareldiff);
0373 fHRNClustersContribution[3]->Fill(pt, nclusterscontrib );
0374 }
0375 fHRN[0]->Fill( nA );
0376 fHRN[1]->Fill( nB );
0377 fHRN[2]->Fill( nC );
0378 fHRN[3]->Fill( nD );
0379
0380
0381
0382
0383
0384 nA=0;
0385 for (SvtxVertexMap::Iter iter = vertexmap->begin();
0386 iter != vertexmap->end();
0387 ++iter) {
0388 nA++;
0389
0390
0391
0392
0393
0394 }
0395 fHNVertexes->Fill(nA);
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408 return 0;
0409 }
0410
0411 int TrackingPerformanceCheck::End(PHCompositeNode *topNode) {
0412 return 0;
0413 }