All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CRHitRemovalByPCA Class Reference
Inheritance diagram for CRHitRemovalByPCA:

Public Member Functions

 CRHitRemovalByPCA (fhicl::ParameterSet const &pset)
 
virtual void produce (art::Event &e)
 
virtual void endJob ()
 End job method. More...
 

Private Member Functions

void removeTaggedHits (const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle > > &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, std::set< const recob::PFParticle * > &taggedParticles, art::PtrVector< recob::Hit > &hitVec)
 

Private Attributes

std::string fCosmicProducerLabel
 Module that produced the PCA based cosmic tags. More...
 
std::string fHitProducerLabel
 The full collection of hits. More...
 
std::string fPFParticleProducerLabel
 PFParticle producer. More...
 
double fCosmicTagThreshold
 Thresholds for tagging. More...
 
int fNumEvent
 Number of events seen. More...
 
int fNumCRRejects
 Number of tracks produced. More...
 

Detailed Description

Definition at line 70 of file CRHitRemovalByPCA_module.cc.

Constructor & Destructor Documentation

CRHitRemovalByPCA::CRHitRemovalByPCA ( fhicl::ParameterSet const &  pset)
explicit

Constructor.

Arguments:

pset - Fcl parameters.

Definition at line 111 of file CRHitRemovalByPCA_module.cc.

111  :
112  EDProducer{pset},
113  fNumEvent(0),
114  fNumCRRejects(0)
115 {
116  fCosmicProducerLabel = pset.get<std::string>("CosmicProducerLabel");
117  fHitProducerLabel = pset.get<std::string>("HitProducerLabel");
118  fPFParticleProducerLabel = pset.get<std::string>("PFParticleProducerLabel");
119  fCosmicTagThreshold = pset.get<double> ("CosmicTagThreshold");
120 
121  produces<std::vector<recob::Hit> >();
122 
123  // Report.
124  mf::LogInfo("CRHitRemovalByPCA") << "CRHitRemovalByPCA configured\n";
125 }
std::string fCosmicProducerLabel
Module that produced the PCA based cosmic tags.
std::string fPFParticleProducerLabel
PFParticle producer.
int fNumCRRejects
Number of tracks produced.
int fNumEvent
Number of events seen.
double fCosmicTagThreshold
Thresholds for tagging.
std::string fHitProducerLabel
The full collection of hits.

Member Function Documentation

void CRHitRemovalByPCA::endJob ( )
virtual

End job method.

Definition at line 346 of file CRHitRemovalByPCA_module.cc.

347 {
348  double aveCRPerEvent = fNumEvent > 0 ? double(fNumCRRejects) / double(fNumEvent) : 0.;
349 
350  mf::LogInfo("CRHitRemovalByPCA")
351  << "CRHitRemovalByPCA statistics:\n"
352  << " Number of events = " << fNumEvent << "\n"
353  << " Number of Cosmic Rays found = " << fNumCRRejects
354  << ", " << aveCRPerEvent << " average/event";
355 }
int fNumCRRejects
Number of tracks produced.
int fNumEvent
Number of events seen.
void CRHitRemovalByPCA::produce ( art::Event &  evt)
virtual

Produce method.

Arguments:

evt - Art event.

This is the primary method. The goal is to produce a list of recob::Hit objects which are a "clean" subset of all hits and which are believed to be due to a neutrino interaction. It does this by considering input CosmicTag objects, relating them to PFParticles/Tracks and removing the hits associated to those objects which are believed to be Cosmic Rays.

Definition at line 140 of file CRHitRemovalByPCA_module.cc.

141 {
142  ++fNumEvent;
143 
144  // Start by looking up the original hits
145  art::Handle< std::vector<recob::Hit> > hitHandle;
146  evt.getByLabel(fHitProducerLabel, hitHandle);
147 
148  // If there are no hits then there should be no output
149  if (!hitHandle.isValid()) return;
150 
151  // If there are hits then we are going to output something so get a new
152  // output hit vector
153  std::unique_ptr<std::vector<recob::Hit> > outputHits(new std::vector<recob::Hit>);
154 
155  // And fill it with the complete original list of hits
156  *outputHits = *hitHandle;
157 
158  // Recover the PFParticles that are responsible for making the tracks
159  art::Handle<std::vector<recob::PFParticle> > pfParticleHandle;
160  evt.getByLabel(fPFParticleProducerLabel, pfParticleHandle);
161 
162  // Without a valid collection of PFParticles we can't do the hit removal
163  if (!pfParticleHandle.isValid())
164  {
165  evt.put(std::move(outputHits));
166  return;
167  }
168 
169  // Recover the clusters so we can do associations to the hits
170  // In theory the clusters come from the same producer as the PFParticles
171  art::Handle<std::vector<recob::Cluster> > clusterHandle;
172  evt.getByLabel(fPFParticleProducerLabel, clusterHandle);
173 
174  // If there are no clusters then something is really wrong
175  if (!clusterHandle.isValid())
176  {
177  evt.put(std::move(outputHits));
178  return;
179  }
180 
181  // Recover the list of cosmic tags
182  art::Handle< std::vector<anab::CosmicTag> > cosmicTagHandle;
183  evt.getByLabel(fCosmicProducerLabel, cosmicTagHandle);
184 
185  // No cosmic tags then nothing to do here
186  if (!cosmicTagHandle.isValid() || cosmicTagHandle->empty())
187  {
188  evt.put(std::move(outputHits));
189  return;
190  }
191 
192  // Start recovering the necessary associations
193  // Start by finding the associations going from cosmic tags to PFParticles
194  art::FindManyP<recob::PFParticle> cosmicTagToPFPartAssns(cosmicTagHandle, evt, fCosmicProducerLabel);
195 
196  // From PFParticles we go to clusters
197  art::FindManyP<recob::Cluster> clusterAssns(pfParticleHandle, evt, fPFParticleProducerLabel);
198 
199  // Likewise, recover the collection of associations to hits
200  art::FindManyP<recob::Hit> clusterHitAssns(clusterHandle, evt, fPFParticleProducerLabel);
201 
202  // Container to contain the "bad" hits...
203  art::PtrVector<recob::Hit> taggedHits;
204 
205  // No point double counting hits
206  std::set<const recob::PFParticle*> taggedSet;
207 
208  // Start the identification of hits to remove. The outer loop is over the various producers of
209  // the CosmicTag objects we're examininig
210  for(size_t crIdx = 0; crIdx != cosmicTagHandle->size(); crIdx++)
211  {
212  art::Ptr<anab::CosmicTag> cosmicTag(cosmicTagHandle, crIdx);
213 
214  // If this was tagged as a CR muon then we have work to do!
215  if (cosmicTag->CosmicScore() > fCosmicTagThreshold)
216  {
217  // Recover the associated PFParticle
218  std::vector<art::Ptr<recob::PFParticle> > pfPartVec = cosmicTagToPFPartAssns.at(crIdx);
219 
220  if (pfPartVec.empty()) continue;
221 
222  art::Ptr<recob::PFParticle> pfParticle = pfPartVec.front();
223 
224  // Again, most likely needless
225  if (!pfParticle) continue;
226 
227  // A cosmic ray must be a primary (by fiat)
228  if (!pfParticle->IsPrimary()) continue;
229 
230  // Avoid double counting if more than one tagger running
231  if (taggedSet.find(pfParticle.get()) != taggedSet.end()) continue;
232 
233  // Remove all hits associated to this particle and its daughters
234  removeTaggedHits(pfParticle.get(), pfParticleHandle, clusterAssns, clusterHitAssns, taggedSet, taggedHits);
235  }
236  }
237 
238  // Are there any tagged hits?
239  if (!taggedHits.empty())
240  {
241  // First order of business is to attempt to restore any hits which are shared between a tagged
242  // CR PFParticle and an untagged one. We can do this by going through the PFParticles and
243  // "removing" hits which are in the not tagged set.
244  art::PtrVector<recob::Hit> untaggedHits;
245 
246  for(const auto& pfParticle : *pfParticleHandle)
247  {
248  if (taggedSet.find(&pfParticle) != taggedSet.end()) continue;
249 
250  // Recover the clusters associated to the input PFParticle
251  std::vector<art::Ptr<recob::Cluster> > clusterVec = clusterAssns.at(pfParticle.Self());
252 
253  // Loop over the clusters and grab the associated hits
254  for(const auto& cluster : clusterVec)
255  {
256  std::vector<art::Ptr<recob::Hit> > clusHitVec = clusterHitAssns.at(cluster->ID());
257  untaggedHits.insert(untaggedHits.end(), clusHitVec.begin(), clusHitVec.end());
258  }
259  }
260 
261  // Filter out the hits we want to save
262  FilterHits(taggedHits, untaggedHits);
263 
264  // The below is rather ugly but there is an interplay between art::Ptr's and the
265  // actual pointers to objects that I might be missing and this is what I see how to do
266  // First move all the original art::Ptr hits into a local art::PtrVector
267  art::PtrVector<recob::Hit> originalHits;
268 
269  // Fill this one hit at a time...
270  for(size_t hitIdx = 0; hitIdx != hitHandle->size(); hitIdx++)
271  {
272  art::Ptr<recob::Hit> hit(hitHandle, hitIdx);
273 
274  originalHits.push_back(hit);
275  }
276 
277  // Remove the cosmic ray tagged hits
278  FilterHits(originalHits, taggedHits);
279 
280  // Clear the current outputHits vector since we're going to refill...
281  outputHits->clear();
282 
283  // Now make the new list of output hits
284  for (const auto& hit : originalHits)
285  {
286  // Kludge to remove out of time hits
287  if (hit->StartTick() > 6400 || hit->EndTick() < 3200) continue;
288 
289  outputHits->emplace_back(*hit);
290  }
291  }
292 
293  // Add tracks and associations to event.
294  evt.put(std::move(outputHits));
295 }
process_name cluster
Definition: cheaterreco.fcl:51
std::string fCosmicProducerLabel
Module that produced the PCA based cosmic tags.
process_name hit
Definition: cheaterreco.fcl:51
std::string fPFParticleProducerLabel
PFParticle producer.
int fNumEvent
Number of events seen.
double fCosmicTagThreshold
Thresholds for tagging.
void removeTaggedHits(const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle > > &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, std::set< const recob::PFParticle * > &taggedParticles, art::PtrVector< recob::Hit > &hitVec)
std::string fHitProducerLabel
The full collection of hits.
TCEvent evt
Definition: DataStructs.cxx:8
void CRHitRemovalByPCA::removeTaggedHits ( const recob::PFParticle pfParticle,
const art::Handle< std::vector< recob::PFParticle > > &  pfParticleHandle,
const art::FindManyP< recob::Cluster > &  partToClusAssns,
const art::FindManyP< recob::Hit > &  clusToHitAssns,
std::set< const recob::PFParticle * > &  taggedParticles,
art::PtrVector< recob::Hit > &  hitVec 
)
private

Hit removal method

Arguments:

pfParticle - the top level PFParticle to have hits removed pfParticleHandle - handle to the PFParticle objects partToClusAssns - list of PFParticle to Cluster associations clusToHitAssns - list of Cluster to Hit associations hitVec - the current list of hits

This recursively called method will remove all hits associated to an input PFParticle and, in addition, will call itself for all daughters of the input PFParticle

Definition at line 312 of file CRHitRemovalByPCA_module.cc.

318 {
319  // Recover the clusters associated to the input PFParticle
320  std::vector<art::Ptr<recob::Cluster> > clusterVec = partToClusAssns.at(pfParticle->Self());
321 
322  // Record this PFParticle as tagged
323  taggedParticles.insert(pfParticle);
324 
325  // Loop over the clusters and grab the associated hits
326  for(const auto& cluster : clusterVec)
327  {
328  std::vector<art::Ptr<recob::Hit> > clusHitVec = clusToHitAssns.at(cluster->ID());
329  hitVec.insert(hitVec.end(), clusHitVec.begin(), clusHitVec.end());
330  }
331 
332  // Loop over the daughters of this particle and remove their hits as well
333  for(const auto& daughterId : pfParticle->Daughters())
334  {
335  art::Ptr<recob::PFParticle> daughter(pfParticleHandle, daughterId);
336 
337  removeTaggedHits(daughter.get(), pfParticleHandle, partToClusAssns, clusToHitAssns, taggedParticles, hitVec);
338  }
339 
340  return;
341 }
const std::vector< size_t > & Daughters() const
Returns the collection of daughter particles.
Definition: PFParticle.h:114
size_t Self() const
Returns the index of this particle.
Definition: PFParticle.h:92
process_name cluster
Definition: cheaterreco.fcl:51
void removeTaggedHits(const recob::PFParticle *pfParticle, const art::Handle< std::vector< recob::PFParticle > > &pfParticleHandle, const art::FindManyP< recob::Cluster > &partToClusAssns, const art::FindManyP< recob::Hit > &clusToHitAssns, std::set< const recob::PFParticle * > &taggedParticles, art::PtrVector< recob::Hit > &hitVec)

Member Data Documentation

std::string CRHitRemovalByPCA::fCosmicProducerLabel
private

Module that produced the PCA based cosmic tags.

Definition at line 91 of file CRHitRemovalByPCA_module.cc.

double CRHitRemovalByPCA::fCosmicTagThreshold
private

Thresholds for tagging.

Definition at line 95 of file CRHitRemovalByPCA_module.cc.

std::string CRHitRemovalByPCA::fHitProducerLabel
private

The full collection of hits.

Definition at line 92 of file CRHitRemovalByPCA_module.cc.

int CRHitRemovalByPCA::fNumCRRejects
private

Number of tracks produced.

Definition at line 99 of file CRHitRemovalByPCA_module.cc.

int CRHitRemovalByPCA::fNumEvent
private

Number of events seen.

Definition at line 98 of file CRHitRemovalByPCA_module.cc.

std::string CRHitRemovalByPCA::fPFParticleProducerLabel
private

PFParticle producer.

Definition at line 93 of file CRHitRemovalByPCA_module.cc.


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