All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
8 #include "art/Framework/Core/EDProducer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
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 
25 class trk::TrackContainmentTagger : public art::EDProducer {
26 public:
27  explicit TrackContainmentTagger(fhicl::ParameterSet const & p);
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 {
53  art::ServiceHandle<art::TFileService const> tfs;
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 
64  fAlg.setMakeCosmicTags();
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){
81  art::Handle< std::vector<recob::Track> > trackHandle;
82  e.getByLabel(fTrackModuleLabels[i_l],trackHandle);
83  trackVectors.push_back(*trackHandle);
84  trackHandles.push_back(trackHandle);
85  }
86 
87  art::ServiceHandle<geo::Geometry const> geoHandle;
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 
105 DEFINE_ART_MODULE(trk::TrackContainmentTagger)
std::vector< std::string > fTrackModuleLabels
pdgs p
Definition: selectors.fcl:22
void produce(art::Event &e) override
TrackContainmentTagger(fhicl::ParameterSet const &p)
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.
do i e
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description