All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCParticleHitMatching_module.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 /// Class: MCParticleHitMatching
3 /// Module Type: producer
4 /// File: MCParticleHitMatching_module.cc
5 ///
6 /// Author: Wesley Ketchum and Yun-Tse Tsai
7 /// E-mail address: wketchum@fnal.gov and yuntse@stanford.edu
8 ///
9 /// This module uses the larsoft backtracker to match hits to truth-level
10 /// MCParticles (from LArG4 output). It originated from MCTruthT0Matching
11 /// module, and follows a similar strategy. All MCParticles matching the hit
12 /// are associated, with information on the amount of contributing energy and
13 /// number of electrons stored in assn metadata.
14 ///
15 /// Input: MCParticles (via Backtracker) and recob::Hit collection
16 /// Output: recob::Hit/simb::MCParticle assns, with BackTrackerHitMatchingData.
17 ///
18 /////////////////////////////////////////////////////////////////////////////
19 
20 // Framework includes
21 #include "art/Framework/Core/EDProducer.h"
22 #include "art/Framework/Core/ModuleMacros.h"
23 #include "art/Framework/Principal/Event.h"
24 #include "art/Utilities/make_tool.h"
25 #include "fhiclcpp/ParameterSet.h"
26 
27 #include <memory>
28 
29 // LArSoft
31 
33 
34 #include "nusimdata/SimulationBase/MCParticle.h"
35 
36 namespace t0 {
37  class MCParticleHitMatching;
38 
39 class MCParticleHitMatching : public art::EDProducer
40 {
41 public:
42  explicit MCParticleHitMatching(fhicl::ParameterSet const & p);
43  // The destructor generated by the compiler is fine for classes
44  // without bare pointers or other resource use.
45 
46  // Plugins should not be copied or assigned.
51 
52 private:
53  // Required functions.
54  void produce(art::Event & e) override;
55 
56  // For keeping track of the replacement backtracker
57  std::unique_ptr<IHitParticleAssociations> fHitParticleAssociations;
58  bool fOverrideRealData; ///< if real data, tell it to run anyway (=0)
59 };
60 
61 
62 MCParticleHitMatching::MCParticleHitMatching(fhicl::ParameterSet const & pset)
63  : EDProducer{pset}
64 {
65  // Get the tool for MC Truth matching
66  //const fhicl::ParameterSet& hitPartAssnsParams = pset.get<fhicl::ParameterSet>("HitParticleAssociations"); // unused
67 
68  fOverrideRealData = pset.get<bool>("OverrideRealData", false);
69 
70  // Get the tool for MC Truth matching
71  fHitParticleAssociations = art::make_tool<IHitParticleAssociations>(pset.get<fhicl::ParameterSet>("HitParticleAssociations"));
72 
73  produces<HitParticleAssociations> ();
74 }
75 
77 {
78  if(evt.isRealData() && !fOverrideRealData) return;
79 
80  std::unique_ptr<HitParticleAssociations> MCPartHitassn( new HitParticleAssociations);
81 
82  fHitParticleAssociations->CreateHitParticleAssociations(evt, MCPartHitassn.get());
83 
84  evt.put(std::move(MCPartHitassn));
85 } // Produce
86 
87 DEFINE_ART_MODULE(MCParticleHitMatching)
88 } // end namespace
MCParticleHitMatching(fhicl::ParameterSet const &p)
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
MCParticleHitMatching & operator=(MCParticleHitMatching const &)=delete
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
bool fOverrideRealData
if real data, tell it to run anyway (=0)
void produce(art::Event &e) override
do i e
std::unique_ptr< IHitParticleAssociations > fHitParticleAssociations
TCEvent evt
Definition: DataStructs.cxx:8