LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BeamFlashTrackMatchTagger_module.cc
Go to the documentation of this file.
1 // Class: BeamFlashTrackMatchTagger
3 // Module Type: producer
4 // File: BeamFlashTrackMatchTagger_module.cc
5 // Author: Wes Ketchum, based on code from Ben Jones
6 //
7 // Description: Module that compares all tracks to the flash during the
8 // beam gate, and determines if that track is consistent with
9 // having produced that flash.
10 // Input: recob::OpFlash, recob::Track
11 // Output: anab::CosmicTag (and Assn<anab::CosmicTag,recob::Track>)
12 //
13 // Generated at Sat Aug 16 15:57:53 2014 by Wesley Ketchum using artmod
14 // from cetpkgsupport v1_06_02.
16 
21 #include "fhiclcpp/ParameterSet.h"
22 
23 #include <memory>
24 
26 #include "HitTagAssociatorAlg.h"
30 #include "lardata/DetectorInfoServices/ServicePack.h" // lar::extractProviders()
34 
35 namespace cosmic {
37 }
38 
40 public:
42  // The destructor generated by the compiler is fine for classes
43  // without bare pointers or other resource use.
44 
45  // Plugins should not be copied or assigned.
50  void produce(art::Event& e) override;
51 
52 private:
53  // Declare member data here.
55  std::string fTrackModuleLabel;
56  std::string fFlashModuleLabel;
57 
60  std::string fHitModuleLabel;
61 };
62 
64  : EDProducer{p}
65  , fAlg(p.get<fhicl::ParameterSet>("BeamFlashTrackMatchAlgParams"))
66  , fTrackModuleLabel(p.get<std::string>("TrackModuleLabel"))
67  , fFlashModuleLabel(p.get<std::string>("FlashModuleLabel"))
68  , fHitTagAssnsAlg(p.get<fhicl::ParameterSet>("HitTagAssociatorAlgParams"))
69  , fMakeHitTagAssns(p.get<bool>("MakeHitTagAssns", false))
70  , fHitModuleLabel(p.get<std::string>("HitModuleLabel", "dummy_hit"))
71 {
72  produces<std::vector<anab::CosmicTag>>();
73  produces<art::Assns<recob::Track, anab::CosmicTag>>();
74  if (fMakeHitTagAssns) produces<art::Assns<recob::Hit, anab::CosmicTag>>();
75 }
76 
78 {
79  // services and providers we'll be using
80  auto providers = lar::extractProviders<geo::Geometry, detinfo::LArPropertiesService>();
81 
83  phot::PhotonVisibilityService const& pvs(*pvsHandle);
85  opdet::OpDigiProperties const& opdigip(*opdigipHandle);
86 
87  //Get Flashes from event.
89  evt.getByLabel(fFlashModuleLabel, flashHandle);
90  std::vector<recob::OpFlash> const& flashVector(*flashHandle);
91 
92  //Get Tracks from event.
94  evt.getByLabel(fTrackModuleLabel, trackHandle);
95  std::vector<recob::Track> const& trackVector(*trackHandle);
96 
97  //Make the containger for the tag product to put onto the event.
98  std::unique_ptr<std::vector<anab::CosmicTag>> cosmicTagPtr(new std::vector<anab::CosmicTag>);
99  std::vector<anab::CosmicTag>& cosmicTagVector(*cosmicTagPtr);
100 
101  //Make a container for the track<-->tag associations.
102  //One entry per track, with entry equal to index in cosmic tag collection of associated tag.
103  std::vector<size_t> assnTrackTagVector;
104  std::unique_ptr<art::Assns<recob::Track, anab::CosmicTag>> assnTrackTag(
106 
107  //run the alg!
109  flashVector, trackVector, cosmicTagVector, assnTrackTagVector, providers, pvs, opdigip);
110 
111  //Make the associations for ART
112  for (size_t track_iter = 0; track_iter < assnTrackTagVector.size(); track_iter++) {
113  if (assnTrackTagVector[track_iter] == std::numeric_limits<size_t>::max()) continue;
114  art::Ptr<recob::Track> trk_ptr(trackHandle, track_iter);
115  util::CreateAssn(evt, cosmicTagVector, trk_ptr, *assnTrackTag, assnTrackTagVector[track_iter]);
116  }
117 
118  //make hit<--> tag associations, if requested
119  if (fMakeHitTagAssns) {
120 
121  //Get Hits from event.
123  evt.getByLabel(fHitModuleLabel, hitHandle);
124 
125  //Get track<-->hit associations
127  evt.getByLabel(fTrackModuleLabel, assnHitTrackHandle);
128  std::vector<std::vector<size_t>> track_indices_per_hit =
129  util::GetAssociatedVectorManyI(assnHitTrackHandle, hitHandle);
130 
131  std::vector<std::vector<size_t>> assnHitTagVector;
132  std::unique_ptr<art::Assns<recob::Hit, anab::CosmicTag>> assnHitTag(
134 
136  track_indices_per_hit, assnTrackTagVector, assnHitTagVector);
137 
138  //Make the associations for ART
139  for (size_t hit_iter = 0; hit_iter < assnHitTagVector.size(); hit_iter++) {
140  art::Ptr<recob::Hit> hit_ptr(hitHandle, hit_iter);
141  for (size_t tag_iter = 0; tag_iter < assnHitTagVector[hit_iter].size(); tag_iter++)
143  evt, cosmicTagVector, hit_ptr, *assnHitTag, assnHitTagVector[hit_iter][tag_iter]);
144  }
145 
146  evt.put(std::move(assnHitTag));
147  } //end if makes hit<-->tag associations
148 
149  //put the data on the event
150  evt.put(std::move(cosmicTagPtr));
151  evt.put(std::move(assnTrackTag));
152 }
153 
void MakeHitTagAssociations(std::vector< std::vector< size_t >> const &bridges_per_hit, std::vector< std::vector< size_t >> const &tags_per_bridges, std::vector< std::vector< size_t >> &tags_per_hit)
Utilities to manage ProviderPack objects with art.
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
void RunCompatibilityCheck(std::vector< recob::OpFlash > const &, std::vector< recob::Track > const &, std::vector< anab::CosmicTag > &, std::vector< size_t > &, Providers_t, phot::PhotonVisibilityService const &, opdet::OpDigiProperties const &)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
BeamFlashTrackMatchTagger(fhicl::ParameterSet const &p)
BeamFlashTrackMatchTagger & operator=(BeamFlashTrackMatchTagger const &)=delete
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.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
TCEvent evt
Definition: DataStructs.cxx:8
Float_t e
Definition: plot.C:35
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U >> h, art::Handle< std::vector< T >> index_p)
art framework interface to geometry description