diff --git a/inc/TrkCount.hh b/inc/TrkCount.hh index 68cdcbe7..328cbe3d 100644 --- a/inc/TrkCount.hh +++ b/inc/TrkCount.hh @@ -1,24 +1,14 @@ #ifndef TrkCount_HH #define TrkCount_HH #include -// root -// // TrkCount: counts track types and track-related quantities in an event (MARKED FOR REMOVAL) // Dave Brown, LBNL 7/8/2016 +// Modified by Sam Grant, ANL 12/22/2025 namespace mu2e { struct TrkCount { - static const int MAX_COUNTS = 50; - // int _ncounts; - int _counts[MAX_COUNTS]; // number of tracks in collection - // int _overlaps[MAX_COUNTS]; // number of shared hits between candidate track and this track + int ntrk = 0; // number of distinct physical tracks collection - int _nde = 0; // number of downstreameMinus tracks - int _nue = 0; // number of upstreameMinus tracks - int _ndm = 0; // number of downstreammuMinus tracks - int _ndec = 0; // Number of calo clusters matched to the best dem track. - int _ndeo = 0; // number of shared hits between primary and next-best track - int _ndmo = 0; // number of shared hits between primary and muon-fit track void reset() { *this = TrkCount(); } }; } diff --git a/src/EventNtupleMaker_module.cc b/src/EventNtupleMaker_module.cc index 487d1793..da44ce54 100644 --- a/src/EventNtupleMaker_module.cc +++ b/src/EventNtupleMaker_module.cc @@ -459,12 +459,8 @@ namespace mu2e { } // hit counting branch _ntuple->Branch("hitcount",&_hcnt); - // track counting branches - for (BranchIndex i_branch = 0; i_branch < _allBranches.size(); ++i_branch) { - BranchConfig i_branchConfig = _allBranches.at(i_branch); - std::string leafname = i_branchConfig.branch(); - _ntuple->Branch(("tcnt.n"+leafname).c_str(),&_tcnt._counts[i_branch]); - } + // track counting branch + _ntuple->Branch("tcnt",&_tcnt); // create all track branches for (BranchIndex i_branch = 0; i_branch < _allBranches.size(); ++i_branch) { @@ -660,9 +656,23 @@ namespace mu2e { event.getByLabel(_conf.mcTrajectoriesTag(),_mcTrajectories); if(_fillcalomc)event.getByLabel(_conf.caloClusterMCTag(),_ccmcch); } - // fill track counts - for (BranchIndex i_branch = 0; i_branch < _allBranches.size(); ++i_branch) { - _tcnt._counts[i_branch] = (_allKSPCHs.at(i_branch))->size(); + + // + // fill track counts: count unique PDG hypotheses + // + std::map pdgCounts; + for (BranchIndex i_branch = 0; i_branch < _allBranches.size() && i_branch < _allKSPCHs.size(); ++i_branch) { + const auto& kseedptr_coll_h = _allKSPCHs.at(i_branch); + const auto& kseedptr_coll = *kseedptr_coll_h; + for (size_t i_kseedptr = 0; i_kseedptr < kseedptr_coll.size(); ++i_kseedptr) { + const auto& kseedptr = kseedptr_coll[i_kseedptr]; + pdgCounts[kseedptr->particle()]++; + } + } + // the number of tracks is the max count of any PDG hypothesis + _tcnt.ntrk = 0; + for (const auto& pair : pdgCounts) { + _tcnt.ntrk = std::max(_tcnt.ntrk, pair.second); } // find extra MCStep collections @@ -978,7 +988,6 @@ namespace mu2e { // calorimeter info _infoStructHelper.fillTrkCaloHitInfo(kseed, _allTCHIs.at(i_branch)); // fillTrkCaloHitInfo handles whether there is a calo hit or not if (kseed.hasCaloCluster()) { - _tcnt._ndec = 1; // only 1 possible calo hit at the moment FIXME: should work with the above // test if(_conf.debug()>0){ auto const& tch = kseed.caloHit();