LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EventCheater_module.cc
Go to the documentation of this file.
1 //
3 // EventCheater module
4 //
5 // brebel@fnal.gov
6 //
8 #include <string>
9 
10 // ROOT includes
11 
12 // LArSoft includes
19 
20 // Framework includes
28 #include "fhiclcpp/ParameterSet.h"
30 
32 namespace event {
33  class EventCheater : public art::EDProducer {
34  public:
35  explicit EventCheater(fhicl::ParameterSet const& pset);
36 
37  private:
38  void produce(art::Event& evt);
39 
40  std::string fCheatedVertexLabel;
41  std::string fG4ModuleLabel;
42  };
43 }
44 
45 namespace event {
46 
47  //--------------------------------------------------------------------
49  {
50  fCheatedVertexLabel = pset.get<std::string>("CheatedVertexLabel", "prong");
51  fG4ModuleLabel = pset.get<std::string>("G4ModuleLabel", "largeant");
52 
53  produces<std::vector<recob::Event>>();
54  produces<art::Assns<recob::Event, recob::Vertex>>();
55  produces<art::Assns<recob::Event, recob::Hit>>();
56  }
57 
58  //--------------------------------------------------------------------
60  {
61 
63  evt.getView(fG4ModuleLabel, pcol);
64 
66 
67  // make a map of the track id for each sim::Particle to its entry in the
68  // collection of sim::Particles
69  std::map<int, int> trackIDToPColEntry;
70  for (size_t p = 0; p < pcol.vals().size(); ++p)
71  trackIDToPColEntry[pcol.vals().at(p)->TrackId()] = p;
72 
73  // grab the vertices that have been reconstructed
75  evt.getByLabel(fCheatedVertexLabel, vertexcol);
76 
78 
79  // make a vector of them - we aren't writing anything out to a file
80  // so no need for a art::PtrVector here
81  std::vector<art::Ptr<recob::Vertex>> vertices;
82  art::fill_ptr_vector(vertices, vertexcol);
83 
84  // loop over the vertices and figure out which primaries they are associated with
85  std::vector<art::Ptr<recob::Vertex>>::iterator vertexitr = vertices.begin();
86 
87  // make a map of primary product id's to collections of vertices
88  std::map<art::Ptr<simb::MCTruth>, std::vector<art::Ptr<recob::Vertex>>> vertexMap;
89  std::map<art::Ptr<simb::MCTruth>, std::vector<art::Ptr<recob::Vertex>>>::iterator vertexMapItr =
90  vertexMap.begin();
91 
92  // loop over all prongs
93  while (vertexitr != vertices.end()) {
94 
95  size_t pcolEntry = trackIDToPColEntry.find((*vertexitr)->ID())->second;
96  const art::Ptr<simb::MCTruth> primary = fo.at(pcolEntry);
97 
98  vertexMap[primary].push_back(*vertexitr);
99 
100  vertexitr++;
101  } // end loop over vertices
102 
103  std::unique_ptr<std::vector<recob::Event>> eventcol(new std::vector<recob::Event>);
104  std::unique_ptr<art::Assns<recob::Event, recob::Vertex>> evassn(
106  std::unique_ptr<art::Assns<recob::Event, recob::Hit>> ehassn(
108 
109  // loop over the map and associate all vertex objects with an event
110  for (vertexMapItr = vertexMap.begin(); vertexMapItr != vertexMap.end(); vertexMapItr++) {
111 
113 
114  std::vector<art::Ptr<recob::Vertex>> verts((*vertexMapItr).second);
115 
116  // add an event to the collection.
117  eventcol->push_back(recob::Event(eventcol->size() - 1));
118 
119  // associate the event with its vertices
120  util::CreateAssn(evt, *eventcol, verts, *evassn);
121 
122  // get the hits associated with each vertex and associate those with the event
123  for (size_t p = 0; p < ptrvs.size(); ++p) {
124  std::vector<art::Ptr<recob::Hit>> hits = fm.at(p);
125  util::CreateAssn(evt, *eventcol, hits, *ehassn);
126  }
127 
128  mf::LogInfo("EventCheater") << "adding event: \n" << eventcol->back() << "\nto collection";
129 
130  } // end loop over the map
131 
132  evt.put(std::move(eventcol));
133  evt.put(std::move(evassn));
134  evt.put(std::move(ehassn));
135 
136  return;
137 
138  } // end produce
139 
140 } // end namespace
141 
142 namespace event {
143 
145 
146 }
std::string fCheatedVertexLabel
label for module creating recob::Vertex objects
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
void produce(art::Event &evt)
Particle class.
auto & vals() noexcept
Definition: View.h:68
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
Definition: fwd.h:46
size_type size() const
Definition: PtrVector.h:302
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
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.
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
EventCheater(fhicl::ParameterSet const &pset)
Event finding and building.