EnergyReco_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // \file EnergyReco_module.cc
4 //
5 // updated by Dom Brailsford (d.brailsford@lancaster.ac.uk)
6 // original module by Nick Grant (n.grant.3@warwick.ac.uk)
7 //
8 ///////////////////////////////////////////////////////////////////////
9 
10 #ifndef EnergyReco_H
11 #define EnergyReco_H
12 
13 //STL
14 #include <limits>
15 //ROOT
16 //ART
20 #include "fhiclcpp/ParameterSet.h"
23 //LArSoft
32 //DUNE
38 
39 namespace dune {
40 
41  class EnergyReco : public art::EDProducer {
42 
43  public:
44 
45  explicit EnergyReco(fhicl::ParameterSet const& pset);
46  void produce(art::Event& evt) override;
47 
48  private:
51  detinfo::DetectorPropertiesData const& detProp,
52  const art::Event& event);
53 
61 
63 
64 
66  }; // class EnergyReco
67 
68 //-----------------------------------------------------------------------------------------------------------------------------------------
69 
71  EDProducer(pset),
72  fWireLabel(pset.get<std::string>("WireLabel")),
73  fHitLabel(pset.get<std::string>("HitLabel")),
74  fTrackLabel(pset.get<std::string>("TrackLabel")),
75  fShowerLabel(pset.get<std::string>("ShowerLabel")),
76  fTrackToHitLabel(pset.get<std::string>("TrackToHitLabel")),
77  fShowerToHitLabel(pset.get<std::string>("ShowerToHitLabel")),
78  fHitToSpacePointLabel(pset.get<std::string>("HitToSpacePointLabel")),
79  fRecoMethod(pset.get<int>("RecoMethod")),
80  fNeutrinoEnergyRecoAlg(pset.get<fhicl::ParameterSet>("NeutrinoEnergyRecoAlg"),fTrackLabel,fShowerLabel,
82 {
83  produces<dune::EnergyRecoOutput>();
84  produces<art::Assns<dune::EnergyRecoOutput, recob::Track>>();
85  produces<art::Assns<dune::EnergyRecoOutput, recob::Shower>>();
86 }
87 
88 //-----------------------------------------------------------------------------------------------------------------------------------------
89 
91 {
92  std::unique_ptr<dune::EnergyRecoOutput> energyRecoOutput;
93  auto assnstrk = std::make_unique<art::Assns<dune::EnergyRecoOutput, recob::Track>>();
94  auto assnsshw = std::make_unique<art::Assns<dune::EnergyRecoOutput, recob::Shower>>();
95 
96  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
97  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataFor(evt, clockData);
98  art::Ptr<recob::Track> longestTrack(this->GetLongestTrack(evt));
99  art::Ptr<recob::Shower> highestChargeShower(this->GetHighestChargeShower(clockData, detProp, evt));
100 
101  if (fRecoMethod == 1)
102  energyRecoOutput = std::make_unique<dune::EnergyRecoOutput>(fNeutrinoEnergyRecoAlg.CalculateNeutrinoEnergy(longestTrack, evt));
103  else if (fRecoMethod == 2)
104  energyRecoOutput = std::make_unique<dune::EnergyRecoOutput>(fNeutrinoEnergyRecoAlg.CalculateNeutrinoEnergy(highestChargeShower, evt));
105  else if (fRecoMethod == 3)
106  energyRecoOutput = std::make_unique<dune::EnergyRecoOutput>(fNeutrinoEnergyRecoAlg.CalculateNeutrinoEnergy(evt));
107 
108  art::ProductID const prodId = evt.getProductID<dune::EnergyRecoOutput>();
109  art::EDProductGetter const* prodGetter = evt.productGetter(prodId);
110  art::Ptr<dune::EnergyRecoOutput> EnergyRecoOutputPtr{ prodId, 0U, prodGetter };
111  if (longestTrack.isAvailable()) assnstrk->addSingle(EnergyRecoOutputPtr, longestTrack);
112  if (highestChargeShower.isAvailable()) assnsshw->addSingle(EnergyRecoOutputPtr, highestChargeShower);
113  evt.put(std::move(energyRecoOutput));
114  evt.put(std::move(assnstrk));
115  evt.put(std::move(assnsshw));
116  }
117 
118 //-----------------------------------------------------------------------------------------------------------------------------------------
119 
121 {
123  const std::vector<art::Ptr<recob::Track> > tracks(dune_ana::DUNEAnaEventUtils::GetTracks(event, fTrackLabel));
124  if (0 == tracks.size())
125  return pTrack;
126 
127  double longestLength(std::numeric_limits<double>::lowest());
128  for (unsigned int iTrack = 0; iTrack < tracks.size(); ++iTrack)
129  {
130  const double length(tracks[iTrack]->Length());
131  if (length-longestLength > std::numeric_limits<double>::epsilon())
132  {
133  longestLength = length;
134  pTrack = tracks[iTrack];
135  }
136  }
137  return pTrack;
138 }
139 
140 //-----------------------------------------------------------------------------------------------------------------------------------------
141 
143  detinfo::DetectorPropertiesData const& detProp,
144  const art::Event &event)
145 {
147  const std::vector<art::Ptr<recob::Shower> > showers(dune_ana::DUNEAnaEventUtils::GetShowers(event, fShowerLabel));
148  if (0 == showers.size())
149  return pShower;
150 
151  double maxCharge(std::numeric_limits<double>::lowest());
152  for (unsigned int iShower = 0; iShower < showers.size(); ++iShower)
153  {
154  const std::vector<art::Ptr<recob::Hit> > showerHits(dune_ana::DUNEAnaHitUtils::GetHitsOnPlane(dune_ana::DUNEAnaShowerUtils::GetHits(showers[iShower],
155  event,fShowerToHitLabel),2));
156  const double showerCharge(dune_ana::DUNEAnaHitUtils::LifetimeCorrectedTotalHitCharge(clockData, detProp, showerHits));
157  if (showerCharge-maxCharge > std::numeric_limits<double>::epsilon())
158  {
159  maxCharge = showerCharge;
160  pShower = showers[iShower];
161  }
162  }
163  return pShower;
164 }
165 
167 
168 } // namespace dune
169 
170 #endif // EnergyReco_H
float Length(const PFPStruct &pfp)
Definition: PFPUtils.cxx:3303
Utility containing helpful functions for end users to access information about Hits.
ProductID getProductID(std::string const &instance_name="") const
Definition: DataViewImpl.h:338
std::string string
Definition: nybbler.cc:12
NeutrinoEnergyRecoAlg class.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fTrackToHitLabel
STL namespace.
art::Ptr< recob::Shower > GetHighestChargeShower(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const art::Event &event)
void produce(art::Event &evt) override
art framework interface to geometry description
static std::vector< art::Ptr< recob::Track > > GetTracks(const art::Event &evt, const std::string &label)
Get the tracks from the event. This function shouldn&#39;t be used as the basis of an analysis...
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Utility containing helpful functions for end users to access information about Showers.
def move(depos, offset)
Definition: depos.py:107
EDProductGetter const * productGetter(ProductID const pid) const
art::Ptr< recob::Track > GetLongestTrack(const art::Event &event)
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
Utility containing helpful functions for end users to access products from events.
NeutrinoEnergyRecoAlg fNeutrinoEnergyRecoAlg
static double LifetimeCorrectedTotalHitCharge(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit > > &hits)
get the total hit charge, corrected for lifetime
std::string fTrackLabel
std::string fWireLabel
Header file for the neutrino energy reconstruction algorithm. A heavily refactored version of Nick Gr...
Declaration of signal hit object.
std::string fShowerLabel
static std::vector< art::Ptr< recob::Hit > > GetHits(const art::Ptr< recob::Shower > &pShower, const art::Event &evt, const std::string &label)
Get the hits associated with the shower.
Contains all timing reference information for the detector.
std::string fShowerToHitLabel
Provides recob::Track data product.
bool isAvailable() const
Definition: Ptr.h:204
Declaration of basic channel signal object.
static std::vector< art::Ptr< recob::Shower > > GetShowers(const art::Event &evt, const std::string &label)
Get the showers from the event. This function shouldn&#39;t be used as the basis of an analysis...
EnergyReco(fhicl::ParameterSet const &pset)
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::string fHitToSpacePointLabel
Event finding and building.
dune::EnergyRecoOutput CalculateNeutrinoEnergy(const art::Ptr< recob::Track > &pMuonTrack, const art::Event &event)
Calculates neutrino energy using a muon track (the muon track may be ignored if it isn&#39;t of a suitabl...
static std::vector< art::Ptr< recob::Hit > > GetHitsOnPlane(const std::vector< art::Ptr< recob::Hit >> &hits, const geo::PlaneID::PlaneID_t planeID)
Get all hits on a specific plane.