All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BeamFlashTrackMatchTagger_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // 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.
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 "fhiclcpp/ParameterSet.h"
22 
23 #include <memory>
24 
28 #include "lardata/DetectorInfoServices/ServicePack.h" // lar::extractProviders()
33 #include "HitTagAssociatorAlg.h"
34 
35 namespace cosmic {
37 }
38 
39 class cosmic::BeamFlashTrackMatchTagger : public art::EDProducer {
40 public:
41  explicit BeamFlashTrackMatchTagger(fhicl::ParameterSet const & p);
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 
53 private:
54 
55  // Declare member data here.
57  std::string fTrackModuleLabel;
58  std::string fFlashModuleLabel;
59 
62  std::string fHitModuleLabel;
63 
64 };
65 
66 
68  : EDProducer{p},
69  fAlg(p.get<fhicl::ParameterSet>("BeamFlashTrackMatchAlgParams")),
70  fTrackModuleLabel(p.get<std::string>("TrackModuleLabel")),
71  fFlashModuleLabel(p.get<std::string>("FlashModuleLabel")),
72  fHitTagAssnsAlg(p.get<fhicl::ParameterSet>("HitTagAssociatorAlgParams")),
73  fMakeHitTagAssns(p.get<bool>("MakeHitTagAssns",false)),
74  fHitModuleLabel(p.get<std::string>("HitModuleLabel","dummy_hit"))
75 {
76  produces< std::vector<anab::CosmicTag> >();
77  produces< art::Assns<recob::Track, anab::CosmicTag> >();
78  if(fMakeHitTagAssns) produces< art::Assns<recob::Hit, anab::CosmicTag> >();
79 }
80 
82 {
83  // services and providers we'll be using
84  auto providers = lar::extractProviders<
87  >();
88 
89  art::ServiceHandle<phot::PhotonVisibilityService const> pvsHandle;
90  phot::PhotonVisibilityService const& pvs(*pvsHandle);
91  art::ServiceHandle<opdet::OpDigiProperties const> opdigipHandle;
92  opdet::OpDigiProperties const& opdigip(*opdigipHandle);
93 
94  //Get Flashes from event.
95  art::Handle< std::vector<recob::OpFlash> > flashHandle;
96  evt.getByLabel(fFlashModuleLabel, flashHandle);
97  std::vector<recob::OpFlash> const& flashVector(*flashHandle);
98 
99  //Get Tracks from event.
100  art::Handle< std::vector<recob::Track> > trackHandle;
101  evt.getByLabel(fTrackModuleLabel, trackHandle);
102  std::vector<recob::Track> const& trackVector(*trackHandle);
103 
104  //Make the containger for the tag product to put onto the event.
105  std::unique_ptr< std::vector<anab::CosmicTag> > cosmicTagPtr ( new std::vector<anab::CosmicTag>);
106  std::vector<anab::CosmicTag> & cosmicTagVector(*cosmicTagPtr);
107 
108  //Make a container for the track<-->tag associations.
109  //One entry per track, with entry equal to index in cosmic tag collection of associated tag.
110  std::vector<size_t> assnTrackTagVector;
111  std::unique_ptr< art::Assns<recob::Track,anab::CosmicTag> > assnTrackTag(new art::Assns<recob::Track,anab::CosmicTag>);
112 
113  //run the alg!
114  fAlg.RunCompatibilityCheck(flashVector, trackVector,
115  cosmicTagVector, assnTrackTagVector,
116  providers, pvs, opdigip);
117 
118 
119  //Make the associations for ART
120  for(size_t track_iter=0; track_iter<assnTrackTagVector.size(); track_iter++){
121  if(assnTrackTagVector[track_iter]==std::numeric_limits<size_t>::max()) continue;
122  art::Ptr<recob::Track> trk_ptr(trackHandle,track_iter);
123  util::CreateAssn(*this, evt, cosmicTagVector, trk_ptr, *assnTrackTag, assnTrackTagVector[track_iter]);
124  }
125 
126  //make hit<--> tag associations, if requested
127  if(fMakeHitTagAssns){
128 
129  //Get Hits from event.
130  art::Handle< std::vector<recob::Hit> > hitHandle;
131  evt.getByLabel(fHitModuleLabel, hitHandle);
132 
133  //Get track<-->hit associations
134  art::Handle< art::Assns<recob::Hit,recob::Track> > assnHitTrackHandle;
135  evt.getByLabel(fTrackModuleLabel,assnHitTrackHandle);
136  std::vector< std::vector<size_t> >
137  track_indices_per_hit = util::GetAssociatedVectorManyI(assnHitTrackHandle,
138  hitHandle);
139 
140  std::vector< std::vector<size_t> > assnHitTagVector;
141  std::unique_ptr< art::Assns<recob::Hit,anab::CosmicTag> > assnHitTag(new art::Assns<recob::Hit,anab::CosmicTag>);
142 
143  fHitTagAssnsAlg.MakeHitTagAssociations(track_indices_per_hit,
144  assnTrackTagVector,
145  assnHitTagVector);
146 
147  //Make the associations for ART
148  for(size_t hit_iter=0; hit_iter<assnHitTagVector.size(); hit_iter++){
149  art::Ptr<recob::Hit> hit_ptr(hitHandle,hit_iter);
150  for(size_t tag_iter=0; tag_iter<assnHitTagVector[hit_iter].size(); tag_iter++)
151  util::CreateAssn(*this, evt, cosmicTagVector, hit_ptr, *assnHitTag, assnHitTagVector[hit_iter][tag_iter]);
152  }
153 
154  evt.put( std::move(assnHitTag));
155  }//end if makes hit<-->tag associations
156 
157  //put the data on the event
158  evt.put(std::move(cosmicTagPtr));
159  evt.put(std::move(assnTrackTag));
160 
161 }
162 
163 DEFINE_ART_MODULE(cosmic::BeamFlashTrackMatchTagger)
Utilities to manage ProviderPack objects with art.
ProviderPackFromServices< Services...> extractProviders()
Returns a provider pack with providers from specified services.
Definition: ServicePack.h:54
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
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.
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
BEGIN_PROLOG cosmic
do i e
TCEvent evt
Definition: DataStructs.cxx:8
art framework interface to geometry description