Public Member Functions | Private Attributes | List of all members
cosmic::TrackPFParticleMatch Class Reference
Inheritance diagram for cosmic::TrackPFParticleMatch:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 TrackPFParticleMatch (fhicl::ParameterSet const &p)
 
void produce (art::Event &e) override
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string fPFParticleModuleLabel
 
std::string fTrackModuleLabel
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 30 of file TrackPFParticleMatch_module.cc.

Constructor & Destructor Documentation

cosmic::TrackPFParticleMatch::TrackPFParticleMatch ( fhicl::ParameterSet const &  p)
explicit

Definition at line 43 of file TrackPFParticleMatch_module.cc.

44  : EDProducer{p}
45 {
46  fPFParticleModuleLabel = p.get< std::string >("PFParticleModuleLabel");
47  fTrackModuleLabel = p.get< std::string >("TrackModuleLabel", "track");
48 
49  // Call appropriate Produces<>() functions here.
50  produces< art::Assns<recob::Track, recob::PFParticle>>();
51 }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
p
Definition: test.py:223

Member Function Documentation

void cosmic::TrackPFParticleMatch::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 53 of file TrackPFParticleMatch_module.cc.

54 {
55  // Instatiate the output
56  std::unique_ptr< art::Assns<recob::Track, recob::PFParticle > > trackPFParticleAssns( new art::Assns<recob::Track, recob::PFParticle>);
57 
58  // Recover handle for PFParticles
60  evt.getByLabel( fPFParticleModuleLabel, pfParticleHandle);
61 
62  // Recover the clusters so we can do associations to the hits
63  // In theory the clusters come from the same producer as the PFParticles
65  evt.getByLabel(fPFParticleModuleLabel, clusterHandle);
66 
67  if (!(pfParticleHandle.isValid() && clusterHandle.isValid()))
68  {
69  evt.put( std::move(trackPFParticleAssns) );
70  return;
71  }
72 
73  // Recover the handle for the tracks
75  evt.getByLabel( fTrackModuleLabel, trackHandle);
76 
77  if (!trackHandle.isValid())
78  {
79  evt.put( std::move(trackPFParticleAssns) );
80  return;
81  }
82 
83  // The strategy will be to build sets of maps which will enable us to go from hit to either Track or PFParticle
84  using HitToTrackMap = std::map<int, std::vector<art::Ptr<recob::Track>>>; // Allows for hit sharing
85 
86  // Build out the track/hit map first
87  // Recover the track/hit associations
88  art::FindManyP<recob::Hit> trackHitAssns(trackHandle, evt, fTrackModuleLabel);
89 
90  // Get an empty map
91  HitToTrackMap hitToTrackMap;
92 
93  // Fill it
94  for(size_t idx = 0; idx < trackHandle->size(); idx++)
95  {
96  art::Ptr<recob::Track> track(trackHandle, idx);
97 
98  std::vector<art::Ptr<recob::Hit>> trackHitVec = trackHitAssns.at(track.key());
99 
100  for (const auto& hitPtr : trackHitVec)
101  {
102  hitToTrackMap[hitPtr.key()].push_back(track);
103  }
104  }
105 
106  // Now we walk up the remaining list of associations needed to go from CR tags to hits
107  // We'll need to go from tracks to PFParticles
108  // From PFParticles we go to clusters
109  art::FindManyP<recob::Cluster> clusterAssns(pfParticleHandle, evt, fPFParticleModuleLabel);
110 
111  // Likewise, recover the collection of associations to hits
112  art::FindManyP<recob::Hit> clusterHitAssns(clusterHandle, evt, fPFParticleModuleLabel);
113 
114  // We'll store this info in a rather complicated data structure...
115  using TrackToPFParticleHitMap = std::map<art::Ptr<recob::Track>, std::map<art::Ptr<recob::PFParticle>,std::vector<art::Ptr<recob::Hit>>>>;
116 
117  TrackToPFParticleHitMap trackToPFParticleHitMap;
118 
119  // Now we go through the PFParticles and match hits to tracks
120  for(size_t idx = 0; idx < pfParticleHandle->size(); idx++)
121  {
122  art::Ptr<recob::PFParticle> pfParticle(pfParticleHandle, idx);
123 
124  // Recover associated clusters
125  std::vector<art::Ptr<recob::Cluster>> clusterVec = clusterAssns.at(pfParticle.key());
126 
127  // Loop through the clusters
128  for(const auto& cluster : clusterVec)
129  {
130  // Recover associated hits
131  std::vector<art::Ptr<recob::Hit>> hitVec = clusterHitAssns.at(cluster.key());
132 
133  // Loop through hits and look for associated track
134  for(const auto& hit : hitVec)
135  {
136  HitToTrackMap::iterator hitToTrackItr = hitToTrackMap.find(hit.key());
137 
138  if (hitToTrackItr != hitToTrackMap.end())
139  {
140  for(auto& track : hitToTrackItr->second)
141  trackToPFParticleHitMap[track][pfParticle].push_back(hit);
142  }
143  }
144  }
145  }
146 
147  // Ok, now we can create the associations
148  for (auto& trackMapItr : trackToPFParticleHitMap)
149  {
150  std::vector<art::Ptr<recob::PFParticle>> pfParticleVec;
151 
152  for(auto& pfParticleMapItr : trackMapItr.second)
153  {
154  // We need to make sure we don't associate the case where the hits are from crossing tracks
155  // which would be an illegal association.
156  // Two things to check: that more than one view is matched in the hits
157  // That some fraction of the matched hits are from the track
158  int nHitsPerView[] = {0,0,0};
159 
160  for(const auto& hit : pfParticleMapItr.second)
161  {
162  nHitsPerView[hit->View()]++;
163  }
164 
165  int nViewsWithHits(0);
166 
167  for(auto& nHits : nHitsPerView) if (nHits > 0) nViewsWithHits++;
168 
169  if (nViewsWithHits < 2) continue;
170 
171  // Get the hits associated to the track again
172  std::vector<art::Ptr<recob::Hit>> trackHitVec = trackHitAssns.at(trackMapItr.first.key());
173 
174  // Fraction of hits from track shared with PFParticle
175  float sharedHitFrac = float(pfParticleMapItr.second.size()) / float(trackHitVec.size());
176 
177  if (sharedHitFrac < 0.3) continue;
178 
179  // Ok, this is an association to make
180  pfParticleVec.push_back(pfParticleMapItr.first);
181  }
182 
183  util::CreateAssn(*this, evt, trackMapItr.first, pfParticleVec, *trackPFParticleAssns);
184  }
185 
186  evt.put( std::move(trackPFParticleAssns));
187 
188  return;
189 
190 } // end of produce
intermediate_table::iterator iterator
Cluster finding and building.
bool isValid() const noexcept
Definition: Handle.h:191
def move(depos, offset)
Definition: depos.py:107
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Detector simulation of raw signals on wires.
TCEvent evt
Definition: DataStructs.cxx:7

Member Data Documentation

std::string cosmic::TrackPFParticleMatch::fPFParticleModuleLabel
private

Definition at line 38 of file TrackPFParticleMatch_module.cc.

std::string cosmic::TrackPFParticleMatch::fTrackModuleLabel
private

Definition at line 39 of file TrackPFParticleMatch_module.cc.


The documentation for this class was generated from the following file: