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 
21 #include "fhiclcpp/ParameterSet.h"
22 
23 #include <memory>
24 
27 #include "lardata/DetectorInfoServices/ServicePack.h" // lar::extractProviders()
31 #include "HitTagAssociatorAlg.h"
32 
33 namespace cosmic {
34  class BeamFlashTrackMatchTagger;
35 }
36 
38 public:
40  // The destructor generated by the compiler is fine for classes
41  // without bare pointers or other resource use.
42 
43  // Plugins should not be copied or assigned.
48  void produce(art::Event & e) override;
49 
50 
51 private:
52 
53  // Declare member data here.
57 
61 
62 };
63 
64 
66  : EDProducer{p},
67  fAlg(p.get<fhicl::ParameterSet>("BeamFlashTrackMatchAlgParams")),
68  fTrackModuleLabel(p.get<std::string>("TrackModuleLabel")),
69  fFlashModuleLabel(p.get<std::string>("FlashModuleLabel")),
70  fHitTagAssnsAlg(p.get<fhicl::ParameterSet>("HitTagAssociatorAlgParams")),
71  fMakeHitTagAssns(p.get<bool>("MakeHitTagAssns",false)),
72  fHitModuleLabel(p.get<std::string>("HitModuleLabel","dummy_hit"))
73 {
74  produces< std::vector<anab::CosmicTag> >();
75  produces< art::Assns<recob::Track, anab::CosmicTag> >();
76  if(fMakeHitTagAssns) produces< art::Assns<recob::Hit, anab::CosmicTag> >();
77 }
78 
80 {
81  // services and providers we'll be using
82  auto providers = lar::extractProviders<
85  >();
86 
88  phot::PhotonVisibilityService const& pvs(*pvsHandle);
90  opdet::OpDigiProperties const& opdigip(*opdigipHandle);
91 
92  //Get Flashes from event.
94  evt.getByLabel(fFlashModuleLabel, flashHandle);
95  std::vector<recob::OpFlash> const& flashVector(*flashHandle);
96 
97  //Get Tracks from event.
99  evt.getByLabel(fTrackModuleLabel, trackHandle);
100  std::vector<recob::Track> const& trackVector(*trackHandle);
101 
102  //Make the containger for the tag product to put onto the event.
103  std::unique_ptr< std::vector<anab::CosmicTag> > cosmicTagPtr ( new std::vector<anab::CosmicTag>);
104  std::vector<anab::CosmicTag> & cosmicTagVector(*cosmicTagPtr);
105 
106  //Make a container for the track<-->tag associations.
107  //One entry per track, with entry equal to index in cosmic tag collection of associated tag.
108  std::vector<size_t> assnTrackTagVector;
109  std::unique_ptr< art::Assns<recob::Track,anab::CosmicTag> > assnTrackTag(new art::Assns<recob::Track,anab::CosmicTag>);
110 
111  //run the alg!
112  fAlg.RunCompatibilityCheck(flashVector, trackVector,
113  cosmicTagVector, assnTrackTagVector,
114  providers, pvs, opdigip);
115 
116 
117  //Make the associations for ART
118  for(size_t track_iter=0; track_iter<assnTrackTagVector.size(); track_iter++){
119  if(assnTrackTagVector[track_iter]==std::numeric_limits<size_t>::max()) continue;
120  art::Ptr<recob::Track> trk_ptr(trackHandle,track_iter);
121  util::CreateAssn(*this, evt, cosmicTagVector, trk_ptr, *assnTrackTag, assnTrackTagVector[track_iter]);
122  }
123 
124  //make hit<--> tag associations, if requested
125  if(fMakeHitTagAssns){
126 
127  //Get Hits from event.
129  evt.getByLabel(fHitModuleLabel, hitHandle);
130 
131  //Get track<-->hit associations
133  evt.getByLabel(fTrackModuleLabel,assnHitTrackHandle);
134  std::vector< std::vector<size_t> >
135  track_indices_per_hit = util::GetAssociatedVectorManyI(assnHitTrackHandle,
136  hitHandle);
137 
138  std::vector< std::vector<size_t> > assnHitTagVector;
139  std::unique_ptr< art::Assns<recob::Hit,anab::CosmicTag> > assnHitTag(new art::Assns<recob::Hit,anab::CosmicTag>);
140 
141  fHitTagAssnsAlg.MakeHitTagAssociations(track_indices_per_hit,
142  assnTrackTagVector,
143  assnHitTagVector);
144 
145  //Make the associations for ART
146  for(size_t hit_iter=0; hit_iter<assnHitTagVector.size(); hit_iter++){
147  art::Ptr<recob::Hit> hit_ptr(hitHandle,hit_iter);
148  for(size_t tag_iter=0; tag_iter<assnHitTagVector[hit_iter].size(); tag_iter++)
149  util::CreateAssn(*this, evt, cosmicTagVector, hit_ptr, *assnHitTag, assnHitTagVector[hit_iter][tag_iter]);
150  }
151 
152  evt.put( std::move(assnHitTag));
153  }//end if makes hit<-->tag associations
154 
155  //put the data on the event
156  evt.put(std::move(cosmicTagPtr));
157  evt.put(std::move(assnTrackTag));
158 
159 }
160 
ProviderPackFromServices< Services... > extractProviders()
Returns a provider pack with providers from specified services.
Definition: ServicePack.h:54
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
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 &)
art framework interface to geometry description
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
static int max(int a, int b)
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
BeamFlashTrackMatchTagger(fhicl::ParameterSet const &p)
BeamFlashTrackMatchTagger & operator=(BeamFlashTrackMatchTagger const &)=delete
Declaration of signal hit object.
std::vector< std::vector< size_t > > GetAssociatedVectorManyI(art::Handle< art::Assns< T, U > > h, art::Handle< std::vector< T > > index_p)
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)
TCEvent evt
Definition: DataStructs.cxx:7