TrackContainmentTagger_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrackContainmentTagger
3 // Module Type: producer
4 // File: TrackContainmentTagger_module.cc
5 //
6 ////////////////////////////////////////////////////////////////////////
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 
42  // Declare member data here.
44 
45  std::vector<std::string> fTrackModuleLabels;
46  std::vector<bool> fApplyTags;
47 };
48 
49 
51  : EDProducer{p}
52 {
54  fAlg.SetupOutputTree(tfs->make<TTree>("myanatree","MyAnalysis Tree"));
55 
56  fAlg.Configure(p.get<fhicl::ParameterSet>("TrackContainmentAlg"));
57  fTrackModuleLabels = p.get< std::vector<std::string> >("TrackModuleLabels");
58  fApplyTags = p.get< std::vector<bool> >("ApplyTags",std::vector<bool>(fTrackModuleLabels.size(),true));
59 
60  if(fApplyTags.size()!=fTrackModuleLabels.size())
61  throw cet::exception("TrackContainmentTagger::TrackContainmentTagger")
62  << "ApplyTags not same size as TrackModuleLabels. ABORT!!!";
63 
65 
66  produces< std::vector<anab::CosmicTag> >();
67  produces< art::Assns<recob::Track, anab::CosmicTag> >();
68 }
69 
71 {
72 
73  std::unique_ptr< std::vector< anab::CosmicTag > > cosmicTagTrackVector( new std::vector<anab::CosmicTag> );
74  std::unique_ptr< art::Assns<recob::Track, anab::CosmicTag > > assnOutCosmicTagTrack( new art::Assns<recob::Track, anab::CosmicTag>);
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]);
96  util::CreateAssn(*this, e, *cosmicTagTrackVector, art::Ptr<recob::Track>(trackHandles[i_tc],i_t), *assnOutCosmicTagTrack );
97  }
98  }
99 
100  e.put(std::move(cosmicTagTrackVector));
101  e.put(std::move(assnOutCosmicTagTrack));
102 
103 }
104 
EventNumber_t event() const
Definition: DataViewImpl.cc:85
void setMakeCosmicTags(bool flag=true)
std::vector< std::string > fTrackModuleLabels
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void produce(art::Event &e) override
art framework interface to geometry description
void ProcessTracks(std::vector< std::vector< recob::Track > > const &, geo::GeometryCore const &)
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
TrackContainmentTagger(fhicl::ParameterSet const &p)
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.
void Configure(fhicl::ParameterSet const &)
void SetRunEvent(unsigned int const &, unsigned int const &)
RunNumber_t run() const
Definition: DataViewImpl.cc:71
TrackContainmentTagger & operator=(TrackContainmentTagger const &)=delete
std::vector< std::vector< anab::CosmicTag > > const & GetTrackCosmicTags()
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33