All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackCalorimetry_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrackCalorimetry
3 // Module Type: producer
4 // File: TrackCalorimetry_module.cc
5 //
6 // Title: Track Calorimetry Algorithim Class
7 // Author: Wes Ketchum (wketchum@lanl.gov), based on code the Calorimetry_module
8 //
9 // Description: Algorithm that produces a calorimetry object given a track
10 // Input: recob::Track, Assn<recob::Spacepoint,recob::Track>, Assn<recob::Hit,recob::Track>
11 // Output: anab::Calorimetry, (and Assn<anab::Calorimetry,recob::Track>)
12 //
13 // Generated at Tue Oct 21 15:54:15 2014 by Wesley Ketchum using artmod
14 // from cetpkgsupport v1_07_01.
15 ////////////////////////////////////////////////////////////////////////
16 
17 #include "art/Framework/Core/EDProducer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "art/Framework/Principal/Event.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "art/Framework/Services/Registry/ServiceHandle.h"
22 #include "fhiclcpp/ParameterSet.h"
23 
24 #include <memory>
25 
26 #include "TrackCalorimetryAlg.h"
31 #include "lardata/DetectorInfoServices/ServicePack.h" // lar::extractProviders()
35 
36 namespace calo {
37  class TrackCalorimetry;
38 }
39 
40 class calo::TrackCalorimetry : public art::EDProducer {
41 public:
42  explicit TrackCalorimetry(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.
47  TrackCalorimetry(TrackCalorimetry const&) = delete;
51 
52 private:
53  // Required functions.
54  void produce(art::Event& e) override;
55 
56  std::string fTrackModuleLabel;
57  std::string fHitModuleLabel;
58 
60 };
61 
62 calo::TrackCalorimetry::TrackCalorimetry(fhicl::ParameterSet const& p)
63  : EDProducer{p}
64  , fTrackModuleLabel(p.get<std::string>("TrackModuleLabel"))
65  , fHitModuleLabel(p.get<std::string>("HitModuleLabel"))
66  , fTrackCaloAlg(p.get<fhicl::ParameterSet>("TrackCalorimetryAlg"))
67 {
68  fTrackModuleLabel = p.get<std::string>("TrackModuleLabel");
69  fHitModuleLabel = p.get<std::string>("HitModuleLabel");
70 
71  produces<std::vector<anab::Calorimetry>>();
72  produces<art::Assns<recob::Track, anab::Calorimetry>>();
73 }
74 
75 void
77 {
78 
79  art::Handle<std::vector<recob::Track>> trackHandle;
80  e.getByLabel(fTrackModuleLabel, trackHandle);
81  std::vector<recob::Track> const& trackVector(*trackHandle);
82 
83  // Get Hits from event.
84  art::Handle<std::vector<recob::Hit>> hitHandle;
85  e.getByLabel(fHitModuleLabel, hitHandle);
86  std::vector<recob::Hit> const& hitVector(*hitHandle);
87 
88  // Get track<-->hit associations
89  art::Handle<art::Assns<recob::Track, recob::Hit>> assnTrackHitHandle;
90  e.getByLabel(fTrackModuleLabel, assnTrackHitHandle);
91  std::vector<std::vector<size_t>> hit_indices_per_track =
92  util::GetAssociatedVectorManyI(assnTrackHitHandle, trackHandle);
93 
94  // Make the container for the calo product to put onto the event.
95  std::unique_ptr<std::vector<anab::Calorimetry>> caloPtr(new std::vector<anab::Calorimetry>);
96  std::vector<anab::Calorimetry>& caloVector(*caloPtr);
97 
98  // Make a container for the track<-->calo associations.
99  // One entry per track, with entry equal to index in calorimetry collection of
100  // associated object.
101  std::vector<size_t> assnTrackCaloVector;
102  std::unique_ptr<art::Assns<recob::Track, anab::Calorimetry>> assnTrackCaloPtr(
103  new art::Assns<recob::Track, anab::Calorimetry>);
104 
105  auto const clock_data = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
106  auto const det_prop =
107  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clock_data);
108  fTrackCaloAlg.ExtractCalorimetry(
109  clock_data,
110  det_prop,
111  trackVector,
112  hitVector,
113  hit_indices_per_track,
114  caloVector,
115  assnTrackCaloVector,
116  lar::extractProviders<geo::Geometry, detinfo::LArPropertiesService>());
117 
118  //Make the associations for ART
119  for (size_t calo_iter = 0; calo_iter < assnTrackCaloVector.size(); calo_iter++) {
120  if (assnTrackCaloVector[calo_iter] == std::numeric_limits<size_t>::max()) continue;
121  art::Ptr<recob::Track> trk_ptr(trackHandle, assnTrackCaloVector[calo_iter]);
122  util::CreateAssn(e, caloVector, trk_ptr, *assnTrackCaloPtr, calo_iter);
123  }
124 
125  e.put(std::move(caloPtr));
126  e.put(std::move(assnTrackCaloPtr));
127 }
128 
129 DEFINE_ART_MODULE(calo::TrackCalorimetry)
Utilities to manage ProviderPack objects with art.
void produce(art::Event &e) override
TrackCalorimetry(fhicl::ParameterSet const &p)
pdgs p
Definition: selectors.fcl:22
process_name can override from command line with o or output calo
Definition: pid.fcl:40
Provides recob::Track data product.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
do i e
TrackCalorimetryAlg fTrackCaloAlg
art framework interface to geometry description
TrackCalorimetry & operator=(TrackCalorimetry const &)=delete