LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrackContainmentTagger_module.cc
Go to the documentation of this file.
1 // Class: TrackContainmentTagger
3 // Module Type: producer
4 // File: TrackContainmentTagger_module.cc
5 //
7 
12 #include "art_root_io/TFileService.h"
13 #include "fhiclcpp/ParameterSet.h"
14 
15 #include "TTree.h"
16 
20 
21 namespace trk {
22  class TrackContainmentTagger;
23 }
24 
26 public:
28  // The destructor generated by the compiler is fine for classes
29  // without bare pointers or other resource use.
30 
31  // Plugins should not be copied or assigned.
36 
37  // Required functions.
38  void produce(art::Event& e) override;
39 
40 private:
41  // Declare member data here.
43 
44  std::vector<std::string> fTrackModuleLabels;
45  std::vector<bool> fApplyTags;
46 };
47 
49 {
51  fAlg.SetupOutputTree(tfs->make<TTree>("myanatree", "MyAnalysis Tree"));
52 
53  fAlg.Configure(p.get<fhicl::ParameterSet>("TrackContainmentAlg"));
54  fTrackModuleLabels = p.get<std::vector<std::string>>("TrackModuleLabels");
55  fApplyTags =
56  p.get<std::vector<bool>>("ApplyTags", std::vector<bool>(fTrackModuleLabels.size(), true));
57 
58  if (fApplyTags.size() != fTrackModuleLabels.size())
59  throw cet::exception("TrackContainmentTagger::TrackContainmentTagger")
60  << "ApplyTags not same size as TrackModuleLabels. ABORT!!!";
61 
63 
64  produces<std::vector<anab::CosmicTag>>();
65  produces<art::Assns<recob::Track, anab::CosmicTag>>();
66 }
67 
69 {
70 
71  std::unique_ptr<std::vector<anab::CosmicTag>> cosmicTagTrackVector(
72  new std::vector<anab::CosmicTag>);
73  std::unique_ptr<art::Assns<recob::Track, anab::CosmicTag>> assnOutCosmicTagTrack(
75 
76  fAlg.SetRunEvent(e.run(), e.event());
77 
78  std::vector<std::vector<recob::Track>> trackVectors;
79  std::vector<art::Handle<std::vector<recob::Track>>> trackHandles;
80  for (size_t i_l = 0; i_l < fTrackModuleLabels.size(); ++i_l) {
82  e.getByLabel(fTrackModuleLabels[i_l], trackHandle);
83  trackVectors.push_back(*trackHandle);
84  trackHandles.push_back(trackHandle);
85  }
86 
88  fAlg.ProcessTracks(trackVectors, *geoHandle);
89 
90  auto const& cosmicTags = fAlg.GetTrackCosmicTags();
91 
92  for (size_t i_tc = 0; i_tc < cosmicTags.size(); ++i_tc) {
93  if (!fApplyTags[i_tc]) continue;
94  for (size_t i_t = 0; i_t < fAlg.GetTrackCosmicTags()[i_tc].size(); ++i_t) {
95  cosmicTagTrackVector->emplace_back(fAlg.GetTrackCosmicTags()[i_tc][i_t]);
97  *cosmicTagTrackVector,
98  art::Ptr<recob::Track>(trackHandles[i_tc], i_t),
99  *assnOutCosmicTagTrack);
100  }
101  }
102 
103  e.put(std::move(cosmicTagTrackVector));
104  e.put(std::move(assnOutCosmicTagTrack));
105 }
106 
void setMakeCosmicTags(bool flag=true)
void ProcessTracks(std::vector< std::vector< recob::Track >> const &, geo::GeometryCore const &)
std::vector< std::string > fTrackModuleLabels
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
void produce(art::Event &e) override
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
TrackContainmentTagger(fhicl::ParameterSet const &p)
EventNumber_t event() const
Definition: Event.cc:41
void Configure(fhicl::ParameterSet const &)
void SetRunEvent(unsigned int const &, unsigned int const &)
TrackContainmentTagger & operator=(TrackContainmentTagger 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.
std::vector< std::vector< anab::CosmicTag > > const & GetTrackCosmicTags()
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.cc:29
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33