Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:08

0001 #include "FillTruthRecoMatchTree.h"
0002 
0003 #include <TFile.h>
0004 #include <TH2D.h>
0005 #include <TTree.h>
0006 #include <fun4all/Fun4AllReturnCodes.h>
0007 #include <fun4all/PHTFileServer.h>
0008 #include <g4main/PHG4TruthInfoContainer.h>
0009 #include <g4tracking/EmbRecoMatch.h>
0010 #include <g4tracking/EmbRecoMatchContainer.h>
0011 #include <g4tracking/TrkrTruthTrack.h>
0012 #include <g4tracking/TrkrTruthTrackContainer.h>
0013 #include <phool/PHCompositeNode.h>
0014 #include <phool/PHDataNode.h>
0015 #include <phool/PHIODataNode.h>
0016 #include <phool/PHNode.h>
0017 #include <phool/PHNodeIterator.h>
0018 #include <phool/PHObject.h>  // for PHObject
0019 #include <phool/getClass.h>
0020 #include <phool/phool.h>  // for PHWHERE
0021 #include <trackbase/TrkrCluster.h>
0022 #include <trackbase/TrkrClusterContainer.h>
0023 #include <trackbase/TrkrDefs.h>
0024 #include <trackbase_historic/SvtxPHG4ParticleMap_v1.h>
0025 #include <trackbase_historic/SvtxTrack.h>
0026 #include <trackbase_historic/SvtxTrackMap.h>
0027 #include <iostream>
0028 
0029 using std::cout;
0030 using std::endl;
0031 //____________________________________________________________________________..
0032 FillTruthRecoMatchTree::FillTruthRecoMatchTree(
0033     bool _fill_clusters, bool _fill_SvUnMatched, float _cluster_nzwidths, float _cluster_nphiwidths, const std::string& _outfile_name)
0034   : m_cluster_comp{_cluster_nphiwidths, _cluster_nzwidths}
0035   , m_fill_clusters{_fill_clusters}
0036   , m_fill_SvU{_fill_SvUnMatched}
0037   , m_outfile_name{_outfile_name}
0038 {
0039   m_cluscntr.set_comparer(&m_cluster_comp);
0040   PHTFileServer::get().open(m_outfile_name, "RECREATE");
0041 
0042   h2_G4_nPixelsPhi = new TH2D("G4_nPixelsPhi", "PHG4 Emb Tracks; cluster pixel width Phi; layer",
0043                               100, -0.5, 99.5, 56, -0.5, 55.5);
0044   h2_G4_nPixelsZ = new TH2D("G4_nPixelsZ", "PHG4 Emb Tracks; cluster pixel width Z; layer",
0045                             100, -0.5, 99.5, 56, -0.5, 55.5);
0046   h2_Sv_nPixelsPhi = new TH2D("Sv_nPixelsPhi", "Svtx Reco Tracks; cluster pixel width Phi; layer",
0047                               100, -0.5, 99.5, 56, -0.5, 55.5);
0048   h2_Sv_nPixelsZ = new TH2D("Sv_nPixelsZ", "Svtx Reco Tracks; cluster pixel width Z; layer",
0049                             100, -0.5, 99.5, 56, -0.5, 55.5);
0050 
0051   m_ttree = new TTree("T", "Tracks (and sometimes clusters)");
0052 
0053   m_ttree->Branch("event", &nevent);
0054   m_ttree->Branch("nphg4_part", &nphg4_part);
0055   m_ttree->Branch("centrality", &centrality);
0056   m_ttree->Branch("ntrackmatches", &ntrackmatches);
0057   m_ttree->Branch("nphg4", &nphg4);
0058   m_ttree->Branch("nsvtx", &nsvtx);
0059 
0060   m_ttree->Branch("trackid", &b_trackid);
0061   m_ttree->Branch("is_G4track", &b_is_g4track);
0062   m_ttree->Branch("is_Svtrack", &b_is_Svtrack);
0063   m_ttree->Branch("is_matched", &b_is_matched);
0064 
0065   m_ttree->Branch("trkpt", &b_trkpt);
0066   m_ttree->Branch("trketa", &b_trketa);
0067   m_ttree->Branch("trkphi", &b_trkphi);
0068 
0069   m_ttree->Branch("nclus", &b_nclus);
0070   m_ttree->Branch("nclustpc", &b_nclustpc);
0071   m_ttree->Branch("nclusmvtx", &b_nclusmvtx);
0072   m_ttree->Branch("nclusintt", &b_nclusintt);
0073   m_ttree->Branch("matchrat", &b_matchrat);
0074   m_ttree->Branch("matchrat_intt", &b_matchrat_intt);
0075   m_ttree->Branch("matchrat_mvtx", &b_matchrat_mvtx);
0076   m_ttree->Branch("matchrat_tpc", &b_matchrat_tpc);
0077 
0078   if (m_fill_clusters)
0079   {
0080     m_ttree->Branch("clus_match", &b_clusmatch);
0081     m_ttree->Branch("clus_x", &b_clus_x);
0082     m_ttree->Branch("clus_y", &b_clus_y);
0083     m_ttree->Branch("clus_z", &b_clus_z);
0084     m_ttree->Branch("clus_r", &b_clus_r);
0085     m_ttree->Branch("clus_layer", &b_clus_layer);
0086     m_ttree->Branch("nphibins", &b_clus_nphibins);
0087     m_ttree->Branch("nzbins", &b_clus_ntbins);
0088   }
0089 }
0090 
0091 //____________________________________________________________________________..
0092 FillTruthRecoMatchTree::~FillTruthRecoMatchTree() = default;
0093 
0094 //____________________________________________________________________________..
0095 int FillTruthRecoMatchTree::Init(PHCompositeNode* topNode)
0096 {
0097   if (Verbosity() > 1)
0098   {
0099     std::cout << " Beginning FillTruthRecoMatchTree " << std::endl;
0100     topNode->print();
0101   }
0102 
0103   return Fun4AllReturnCodes::EVENT_OK;
0104 }
0105 
0106 //____________________________________________________________________________..
0107 int FillTruthRecoMatchTree::InitRun(PHCompositeNode* topNode)
0108 {
0109   auto init_status = m_cluster_comp.init(topNode);
0110   if (init_status == Fun4AllReturnCodes::ABORTRUN)
0111   {
0112     return init_status;
0113   }
0114 
0115   if (createNodes(topNode) != Fun4AllReturnCodes::EVENT_OK)
0116   {
0117     return Fun4AllReturnCodes::ABORTEVENT;
0118   }
0119 
0120   return Fun4AllReturnCodes::EVENT_OK;
0121 }
0122 
0123 int FillTruthRecoMatchTree::createNodes(PHCompositeNode* topNode)
0124 {
0125   PHNodeIterator iter(topNode);
0126 
0127   PHCompositeNode* dstNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "DST"));
0128 
0129   if (!dstNode)
0130   {
0131     std::cout << PHWHERE << " DST node is missing, quitting" << std::endl;
0132     std::cerr << PHWHERE << " DST node is missing, quitting" << std::endl;
0133     throw std::runtime_error("Failed to find DST node in FillTruthRecoMatchTree::createNodes");
0134   }
0135 
0136   m_EmbRecoMatchContainer = findNode::getClass<EmbRecoMatchContainer>(topNode, "TRKR_EMBRECOMATCHCONTAINER");
0137   if (!m_EmbRecoMatchContainer)
0138   {
0139     std::cout << PHWHERE << " Cannot find node TRKR_EMBRECOMATCHCONTAINER on node tree; quitting " << std::endl;
0140     std::cerr << PHWHERE << " Cannot find node TRKR_EMBRECOMATCHCONTAINER on node tree; quitting " << std::endl;
0141     throw std::runtime_error(" Cannot find node TRKR_EMBRECOMATCHCONTAINER on node tree; quitting");
0142   }
0143 
0144   PHCompositeNode* svtxNode = dynamic_cast<PHCompositeNode*>(iter.findFirst("PHCompositeNode", "SVTX"));
0145   if (!svtxNode)
0146   {
0147     svtxNode = new PHCompositeNode("SVTX");
0148     dstNode->addNode(svtxNode);
0149   }
0150 
0151   m_PHG4TruthInfoContainer = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
0152   if (!m_PHG4TruthInfoContainer)
0153   {
0154     std::cout << "Could not locate G4TruthInfo node when running "
0155               << "\"TruthRecoTrackMatching\" module." << std::endl;
0156     return Fun4AllReturnCodes::ABORTEVENT;
0157   }
0158 
0159   m_SvtxTrackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
0160   if (!m_SvtxTrackMap)
0161   {
0162     std::cout << "Could not locate SvtxTrackMap node when running "
0163               << "\"TruthRecoTrackMatching\" module." << std::endl;
0164     return Fun4AllReturnCodes::ABORTEVENT;
0165   }
0166 
0167   /* m_TruthClusterContainer = findNode::getClass<TrkrClusterContainer>(topNode, */
0168   /*     "TRKR_TRUTHCLUSTERCONTAINER"); */
0169   /* if (!m_TruthClusterContainer) */
0170   /* { */
0171   /*   std::cout << "Could not locate TRKR_TRUTHCLUSTERCONTAINER node when running " */
0172   /*     << "\"TruthRecoTrackMatching\" module." << std::endl; */
0173   /*   return Fun4AllReturnCodes::ABORTEVENT; */
0174   /* } */
0175 
0176   /* m_RecoClusterContainer = findNode::getClass<TrkrClusterContainer>(topNode, "TRKR_CLUSTER"); */
0177   /* if (!m_RecoClusterContainer) */
0178   /* { */
0179   /*   std::cout << "Could not locate TRKR_CLUSTER node when running " */
0180   /*     << "\"TruthRecoTrackMatching\" module." << std::endl; */
0181   /*   return Fun4AllReturnCodes::ABORTEVENT; */
0182   /* } */
0183 
0184   m_TrkrTruthTrackContainer = findNode::getClass<TrkrTruthTrackContainer>(topNode,
0185                                                                           "TRKR_TRUTHTRACKCONTAINER");
0186   if (!m_TrkrTruthTrackContainer)
0187   {
0188     std::cout << "Could not locate TRKR_TRUTHTRACKCONTAINER node when running "
0189               << "\"TruthRecoTrackMatching\" module." << std::endl;
0190     return Fun4AllReturnCodes::ABORTEVENT;
0191   }
0192 
0193   return Fun4AllReturnCodes::EVENT_OK;
0194 }
0195 
0196 int FillTruthRecoMatchTree::process_event(PHCompositeNode* /*topNode*/)
0197 {
0198   if (Verbosity() > 5)
0199   {
0200     cout << " FillTruthRecoMatchTree::process_event() " << endl;
0201   }
0202 
0203   // fill in the event data
0204   ++nevent;
0205   nphg4 = m_TrkrTruthTrackContainer->getMap().size();
0206   nsvtx = m_SvtxTrackMap->size();
0207   ntrackmatches = m_EmbRecoMatchContainer->getMatches().size();
0208   // get centrality later...
0209 
0210   // fill in pixel widths on truth tracks
0211   for (auto hitsetkey : m_cluscntr.get_PHG4_clusters()->getHitSetKeys())
0212   {
0213     float layer = (float) TrkrDefs::getLayer(hitsetkey);
0214     auto range = m_cluscntr.get_PHG4_clusters()->getClusters(hitsetkey);
0215     for (auto iter = range.first; iter != range.second; ++iter)
0216     {
0217       auto& cluster = iter->second;
0218       h2_G4_nPixelsPhi->Fill((float) cluster->getPhiSize(), layer);
0219       h2_G4_nPixelsZ->Fill((float) cluster->getZSize(), layer);
0220     }
0221   }
0222   // fill in pixel widths on reco tracks
0223   for (auto hitsetkey : m_cluscntr.get_SVTX_clusters()->getHitSetKeys())
0224   {
0225     float layer = (float) TrkrDefs::getLayer(hitsetkey);
0226     auto range = m_cluscntr.get_SVTX_clusters()->getClusters(hitsetkey);
0227     for (auto iter = range.first; iter != range.second; ++iter)
0228     {
0229       auto& cluster = iter->second;
0230       h2_Sv_nPixelsPhi->Fill((float) cluster->getPhiSize(), layer);
0231       h2_Sv_nPixelsZ->Fill((float) cluster->getZSize(), layer);
0232     }
0233   }
0234 
0235   nphg4_part = 0;
0236   const auto range = m_PHG4TruthInfoContainer->GetPrimaryParticleRange();
0237   for (PHG4TruthInfoContainer::ConstIterator iter = range.first;
0238        iter != range.second; ++iter)
0239   {
0240     nphg4_part++;
0241   }
0242 
0243   // unmatched tracks are only entered once
0244   // matches can repeat a given svtx or phg4 track, depending on the
0245   // parameters in teh matching in filltruthrecomatchtree
0246   //
0247   // (1) fill unmatched phg4
0248   // (2) fill unmatched svtx
0249   // (3) fill matched phg4 and svtx
0250   clear_clusvecs(" nothing ");
0251 
0252   if (Verbosity() > 2)
0253   {
0254     std::cout << " getting" << (int) m_EmbRecoMatchContainer->getMatches().size() << std::endl;
0255   }
0256   for (auto& match : m_EmbRecoMatchContainer->getMatches())
0257   {
0258     unsigned int g4_trkid = match->idTruthTrack();
0259     int sv_trkid = match->idRecoTrack();
0260 
0261     auto g4trk = m_TrkrTruthTrackContainer->getTruthTrack(g4_trkid);
0262     auto svtrk = m_SvtxTrackMap->get(sv_trkid);
0263 
0264     m_cluscntr.addClusKeys(g4trk);
0265     m_cluscntr.addClusKeys(svtrk);
0266     m_cluscntr.find_matches();
0267 
0268     // <- <- <- <- G4 Matched Tracks
0269     b_is_matched = true;
0270     b_is_g4track = true;
0271     b_is_Svtrack = false;
0272 
0273     b_trackid = g4_trkid;
0274     b_trkpt = g4trk->getPt();
0275     b_trketa = g4trk->getPseudoRapidity();
0276     b_trkphi = g4trk->getPhi();
0277 
0278     auto cnt = m_cluscntr.phg4_cntclus();
0279     auto cnt_match = m_cluscntr.phg4_cnt_matchedclus();
0280 
0281     b_nclus = cnt[4];
0282     b_nclusmvtx = cnt[0];
0283     b_nclusintt = cnt[1];
0284     b_nclustpc = cnt[2];
0285 
0286     b_matchrat = (float) cnt_match[4] / cnt[4];
0287     b_matchrat_mvtx = (float) cnt_match[0] / cnt[0];
0288     b_matchrat_intt = (float) cnt_match[1] / cnt[1];
0289     b_matchrat_tpc = (float) cnt_match[2] / cnt[2];
0290 
0291     if (m_fill_clusters)
0292     {
0293       auto clusters = m_cluscntr.phg4_clusloc_unmatched();
0294       for (auto& loc : clusters)
0295       {
0296         b_clusmatch.push_back(false);
0297         b_clus_layer.push_back(std::get<0>(loc));
0298         auto x = std::get<1>(loc)[0];
0299         auto y = std::get<1>(loc)[1];
0300         b_clus_x.push_back(x);
0301         b_clus_y.push_back(y);
0302         b_clus_z.push_back(std::get<1>(loc)[2]);
0303         b_clus_r.push_back(pow(x * x + y * y, 0.5));
0304         b_clus_nphibins.push_back(std::get<2>(loc));
0305         b_clus_ntbins.push_back(std::get<3>(loc));
0306       }
0307 
0308       clusters = m_cluscntr.clusloc_matched();
0309       for (auto& loc : clusters)
0310       {
0311         b_clusmatch.push_back(true);
0312         b_clus_layer.push_back(std::get<0>(loc));
0313         auto x = std::get<1>(loc)[0];
0314         auto y = std::get<1>(loc)[1];
0315         b_clus_x.push_back(x);
0316         b_clus_y.push_back(y);
0317         b_clus_z.push_back(std::get<1>(loc)[2]);
0318         b_clus_r.push_back(pow(x * x + y * y, 0.5));
0319         b_clus_nphibins.push_back(std::get<2>(loc));
0320         b_clus_ntbins.push_back(std::get<3>(loc));
0321       }
0322     }
0323     m_ttree->Fill();
0324     clear_clusvecs();
0325     /* clear_clusvecs("apple0 g4_matched"); */
0326 
0327     // <- <- <- <- Svtx Matched Tracks
0328     b_is_g4track = false;
0329     b_is_Svtrack = true;
0330     b_trackid = sv_trkid;
0331     b_trkpt = svtrk->get_pt();
0332     b_trketa = svtrk->get_eta();
0333     b_trkphi = svtrk->get_phi();
0334 
0335     cnt = m_cluscntr.svtx_cntclus();
0336     b_nclus = cnt[4];
0337     b_nclusmvtx = cnt[0];
0338     b_nclusintt = cnt[1];
0339     b_nclustpc = cnt[2];
0340 
0341     b_matchrat = (float) cnt_match[4] / cnt[4];
0342     b_matchrat_mvtx = (float) cnt_match[0] / cnt[0];
0343     b_matchrat_intt = (float) cnt_match[1] / cnt[1];
0344     b_matchrat_tpc = (float) cnt_match[2] / cnt[2];
0345 
0346     /* int _ = 0; */
0347     if (m_fill_clusters)
0348     {
0349       auto clusters = m_cluscntr.svtx_clusloc_unmatched();
0350       for (auto& loc : clusters)
0351       {
0352         b_clusmatch.push_back(false);
0353         b_clus_layer.push_back(std::get<0>(loc));
0354         auto x = std::get<1>(loc)[0];
0355         auto y = std::get<1>(loc)[1];
0356         /* if (_==0) cout << " apple x: " << x << " y: " << y << endl; */
0357         /* _ += 1; */
0358         b_clus_x.push_back(x);
0359         b_clus_y.push_back(y);
0360         b_clus_z.push_back(std::get<1>(loc)[2]);
0361         b_clus_r.push_back(pow(x * x + y * y, 0.5));
0362         b_clus_nphibins.push_back(std::get<2>(loc));
0363         b_clus_ntbins.push_back(std::get<3>(loc));
0364       }
0365 
0366       clusters = m_cluscntr.clusloc_matched();
0367       for (auto& loc : clusters)
0368       {
0369         b_clusmatch.push_back(true);
0370         b_clus_layer.push_back(std::get<0>(loc));
0371         auto x = std::get<1>(loc)[0];
0372         auto y = std::get<1>(loc)[1];
0373         b_clus_x.push_back(x);
0374         b_clus_y.push_back(y);
0375         b_clus_z.push_back(std::get<1>(loc)[2]);
0376         b_clus_r.push_back(pow(x * x + y * y, 0.5));
0377         b_clus_nphibins.push_back(std::get<2>(loc));
0378         b_clus_ntbins.push_back(std::get<3>(loc));
0379       }
0380     }
0381     m_ttree->Fill();
0382     clear_clusvecs();
0383     /* clear_clusvecs("apple1 s4_matched"); */
0384   }
0385 
0386   // <- <- <- <- G4 un-matched Tracks
0387   b_is_matched = false;
0388   b_is_g4track = true;
0389   b_is_Svtrack = false;
0390   for (auto& g4_trkid : m_EmbRecoMatchContainer->ids_TruthUnmatched())
0391   {
0392     auto g4trk = m_TrkrTruthTrackContainer->getTruthTrack(g4_trkid);
0393     m_cluscntr.addClusKeys(g4trk);
0394 
0395     b_trackid = g4_trkid;
0396     b_trkpt = g4trk->getPt();
0397     b_trketa = g4trk->getPseudoRapidity();
0398     b_trkphi = g4trk->getPhi();
0399 
0400     auto cnt = m_cluscntr.phg4_cntclus();
0401     b_nclus = cnt[4];
0402     b_nclusmvtx = cnt[0];
0403     b_nclusintt = cnt[1];
0404     b_nclustpc = cnt[2];
0405 
0406     if (m_fill_clusters)
0407     {
0408       auto clusters = m_cluscntr.phg4_clusloc_all();
0409       for (auto& loc : clusters)
0410       {
0411         b_clusmatch.push_back(false);
0412         b_clus_layer.push_back(std::get<0>(loc));
0413         auto x = std::get<1>(loc)[0];
0414         auto y = std::get<1>(loc)[1];
0415         b_clus_x.push_back(x);
0416         b_clus_y.push_back(y);
0417         b_clus_z.push_back(std::get<1>(loc)[2]);
0418         b_clus_r.push_back(pow(x * x + y * y, 0.5));
0419         b_clus_nphibins.push_back(std::get<2>(loc));
0420         b_clus_ntbins.push_back(std::get<3>(loc));
0421       }
0422       // this is an unmatched track, so there are no matched clusters
0423     }
0424     m_ttree->Fill();
0425     clear_clusvecs();
0426     /* clear_clusvecs("apple2 g4_unmatched"); */
0427   }
0428 
0429   // <- <- <- <- Svtx un-matched Tracks
0430   b_is_matched = false;
0431   b_is_matched = false;
0432   b_is_g4track = false;
0433   b_is_Svtrack = true;
0434 
0435   // just put in all svtx tracks, period...
0436   if (m_fill_SvU)
0437   {
0438     for (auto sv_trkid : G4Eval::unmatchedSvtxTrkIds(m_EmbRecoMatchContainer, m_SvtxTrackMap))
0439     {
0440       auto svtrk = m_SvtxTrackMap->get(sv_trkid);
0441       m_cluscntr.addClusKeys(svtrk);
0442       b_trackid = sv_trkid;
0443       b_trkpt = svtrk->get_pt();
0444       b_trketa = svtrk->get_eta();
0445       b_trkphi = svtrk->get_phi();
0446 
0447       auto cnt = m_cluscntr.svtx_cntclus();
0448       b_nclus = cnt[4];
0449       b_nclusmvtx = cnt[0];
0450       b_nclusintt = cnt[1];
0451       b_nclustpc = cnt[2];
0452 
0453       if (m_fill_clusters)
0454       {
0455         auto clusters = m_cluscntr.svtx_clusloc_all();
0456         for (auto& loc : clusters)
0457         {
0458           b_clusmatch.push_back(false);
0459           b_clus_layer.push_back(std::get<0>(loc));
0460           auto x = std::get<1>(loc)[0];
0461           auto y = std::get<1>(loc)[1];
0462           b_clus_x.push_back(x);
0463           b_clus_y.push_back(y);
0464           b_clus_z.push_back(std::get<1>(loc)[2]);
0465           b_clus_r.push_back(pow(x * x + y * y, 0.5));
0466           b_clus_nphibins.push_back(std::get<2>(loc));
0467           b_clus_ntbins.push_back(std::get<3>(loc));
0468         }
0469       }
0470       m_ttree->Fill();
0471       clear_clusvecs();
0472     }
0473   }
0474 
0475   if (Verbosity() > 100)
0476   {
0477     print_mvtx_diagnostics();
0478   }
0479   return Fun4AllReturnCodes::EVENT_OK;
0480 }
0481 
0482 void FillTruthRecoMatchTree::print_mvtx_diagnostics()
0483 {
0484   std::cout << "To do: "
0485             << " (1)  number of truth tracks and total number of mvtx and ratio " << std::endl
0486             << " (2)  ditto for reco tracks " << std::endl;
0487 
0488   double n_PHG4_tracks = m_TrkrTruthTrackContainer->getMap().size();
0489   // count how many mvtx clusters in the phg4 tracks
0490   double n_in_PHG4_tracks{0.};
0491   for (auto& pair : m_TrkrTruthTrackContainer->getMap())
0492   {
0493     m_cluscntr.addClusKeys(pair.second);
0494     n_in_PHG4_tracks += m_cluscntr.phg4_cntclus()[0];
0495   }
0496   // count how mant mvtx clusters in truth container (should be the same)
0497   double n_in_PHG4_clusters{0.};
0498   for (auto hitsetkey : m_cluscntr.get_PHG4_clusters()->getHitSetKeys())
0499   {
0500     if (TrkrDefs::getLayer(hitsetkey) > 2)
0501     {
0502       continue;
0503     }
0504     auto range = m_cluscntr.get_PHG4_clusters()->getClusters(hitsetkey);
0505     for (auto r = range.first; r != range.second; ++r)
0506     {
0507       n_in_PHG4_clusters += 1.;
0508     }
0509   }
0510 
0511   // count how many svtx tracks
0512   double n_SVTX_tracks = m_SvtxTrackMap->size();
0513   // count how many mvtx clusters in svtx tracks
0514   double n_in_SVTX_tracks{0.};
0515   for (auto& entry : *m_SvtxTrackMap)
0516   {
0517     m_cluscntr.addClusKeys(entry.second);
0518     n_in_SVTX_tracks += m_cluscntr.svtx_cntclus()[0];
0519   }
0520   // count how many mvtx are total in the container
0521   double n_in_SVTX_clusters{0.};
0522   for (auto hitsetkey : m_cluscntr.get_SVTX_clusters()->getHitSetKeys())
0523   {
0524     if (TrkrDefs::getLayer(hitsetkey) > 2)
0525     {
0526       continue;
0527     }
0528     auto range = m_cluscntr.get_SVTX_clusters()->getClusters(hitsetkey);
0529     for (auto r = range.first; r != range.second; ++r)
0530     {
0531       n_in_SVTX_clusters += 1.;
0532     }
0533   }
0534 
0535   std::cout << Form(
0536                    "MVTX"
0537                    "\nPHG4:  Tracks(%.0f)   Clusters In tracks(%.0f)   Total (%.0f)"
0538                    "\n       ave. per track: %6.3f   ratio in all tracks: %6.2f",
0539                    n_PHG4_tracks, n_in_PHG4_tracks, n_in_PHG4_clusters, (n_in_PHG4_tracks / n_PHG4_tracks), (n_in_PHG4_tracks / n_in_PHG4_clusters))
0540             << std::endl;
0541   std::cout << Form(
0542                    "\nSVTX:  Tracks(%.0f)   Clusters In tracks(%.0f)   Total (%.0f)"
0543                    "\n       ave. per track: %6.3f   ratio in all tracks: %6.2f",
0544                    n_SVTX_tracks, n_in_SVTX_tracks, n_in_SVTX_clusters, (n_in_SVTX_tracks / n_SVTX_tracks), (n_in_SVTX_tracks / n_in_SVTX_clusters))
0545             << std::endl;
0546 }
0547 
0548 int FillTruthRecoMatchTree::End(PHCompositeNode* /*unused*/)
0549 {
0550   if (Verbosity() > 2)
0551   {
0552     std::cout << PHWHERE << ": ending FillTruthRecoMatchTree" << std::endl;
0553   }
0554   PHTFileServer::get().cd(m_outfile_name);
0555 
0556   h2_G4_nPixelsPhi->Write();
0557   h2_G4_nPixelsZ->Write();
0558   h2_Sv_nPixelsPhi->Write();
0559   h2_Sv_nPixelsZ->Write();
0560 
0561   m_ttree->Write();
0562   return Fun4AllReturnCodes::EVENT_OK;
0563 }
0564 
0565 void FillTruthRecoMatchTree::clear_clusvecs(const std::string& tag)
0566 {
0567   /* cout << " banana |" << tag << "|"<<endl; */
0568   if (tag != "")
0569   {
0570     cout << endl
0571          << " pear printing " << tag << " x(" << b_clus_x.size() << ") ";
0572     for (auto x : b_clus_x)
0573     {
0574       cout << x << " ";
0575     }
0576     cout << endl;
0577   }
0578   // Tracks and clustes
0579   b_clusmatch.clear();
0580   b_clus_x.clear();
0581   b_clus_y.clear();
0582   b_clus_z.clear();
0583   b_clus_r.clear();
0584   b_clus_layer.clear();
0585   b_clus_nphibins.clear();
0586   b_clus_ntbins.clear();
0587 }