Public Member Functions | Private Attributes | List of all members
vertex::VertexCheater Class Reference
Inheritance diagram for vertex::VertexCheater:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 VertexCheater (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string fCheatedTrackLabel
 label for module creating recob::Track objects More...
 
std::string fCheatedShowerLabel
 label for module creating recob::Shower objects More...
 
std::string fG4ModuleLabel
 label for module running G4 and making particles, etc More...
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 32 of file VertexCheater_module.cc.

Constructor & Destructor Documentation

vertex::VertexCheater::VertexCheater ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 50 of file VertexCheater_module.cc.

51  : EDProducer{pset}
52  {
53  fCheatedTrackLabel = pset.get< std::string >("CheatedTrackLabel", "track" );
54  fCheatedShowerLabel = pset.get< std::string >("CheatedShowerLabel", "shower" );
55  fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel", "largeant");
56 
57  produces< std::vector<recob::Vertex> >();
58  produces< art::Assns<recob::Vertex, recob::Shower> >();
59  produces< art::Assns<recob::Vertex, recob::Track> >();
60  produces< art::Assns<recob::Vertex, recob::Hit> >();
61 
62  }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fCheatedTrackLabel
label for module creating recob::Track objects
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
std::string fCheatedShowerLabel
label for module creating recob::Shower objects

Member Function Documentation

void vertex::VertexCheater::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 65 of file VertexCheater_module.cc.

66  {
68 
69  // grab the sim::ParticleList
70  const sim::ParticleList& plist = pi_serv->ParticleList();
71 
72  // grab the showers that have been reconstructed
74  evt.getByLabel(fCheatedShowerLabel, showercol);
75 
76  // make a vector of them - we aren't writing anything out to a file
77  // so no need for a art::PtrVector here
78  std::vector< art::Ptr<recob::Shower> > showers;
79  try{
80  art::fill_ptr_vector(showers, showercol);
81  }
82  catch(cet::exception &e){
83  mf::LogWarning("VertexCheater") << "showers: " << e;
84  }
85 
86  // grab the tracks that have been reconstructed
88  evt.getByLabel(fCheatedTrackLabel, trackcol);
89 
90  // make a vector of them - we aren't writing anything out to a file
91  // so no need for a art::PtrVector here
92  std::vector< art::Ptr<recob::Track> > tracks;
93  try{
94  art::fill_ptr_vector(tracks, trackcol);
95  }
96  catch(cet::exception &e){
97  mf::LogWarning("VertexCheater") << "tracks: " << e;
98  }
99 
100  art::FindManyP<recob::Hit> fmhs(showers, evt, fCheatedShowerLabel);
101  art::FindManyP<recob::Hit> fmht(tracks, evt, fCheatedTrackLabel);
102 
103  // loop over the prongs and figure out which primaries they are associated with
104  std::vector< art::Ptr<recob::Shower> >::iterator shwitr = showers.begin();
105  std::vector< art::Ptr<recob::Track> >::iterator trkitr = tracks.begin();
106 
107  // protect against events where there are either no tracks or no showers
108  if(tracks.size() < 1) trkitr = tracks.end();
109  if(showers.size() < 1) shwitr = showers.end();
110 
111  // make a map of eve id's to collections of prongs
112  std::map<int, std::vector< std::pair<size_t, art::Ptr<recob::Shower> > > > eveShowerMap;
113  std::map<int, std::vector< std::pair<size_t, art::Ptr<recob::Track> > > > eveTrackMap;
114 
115  // make a map of eve id's to the number of prongs corresponding to that id
116  std::vector<int> eveIDs;
117 
118  // loop over all showers
119  for(size_t s = 0; s < showers.size(); ++s){
120 
121  std::pair<size_t, art::Ptr<recob::Shower> > idxShw(s, showers[s]);
122 
123  // in the ProngCheater module we set the prong ID to be
124  // the particle track ID creating the energy depositions
125  // of the prong
126  int prongID = showers[s]->ID();
127 
128  // now get the mother particle of this prong if it exists
129  // set the eveID to the mother particle track ID, or to the
130  // ID of this prong if it is primary and mother ID = 0
131  int eveID = plist[prongID]->Mother();
132  if( eveID < 1 ) eveID = prongID;
133 
134  if(std::find(eveIDs.begin(), eveIDs.end(), eveID) == eveIDs.end())
135  eveIDs.push_back(eveID);
136 
137  // now we want to associate all prongs having the same
138  // eve ID, so look to see if there are other prongs with that
139  // ID
140  eveShowerMap[eveID].push_back(idxShw);
141 
142  mf::LogInfo("VertexCheater") << "shower: " << prongID << " has mother " << eveID;
143 
144  }// end loop over showers
145 
146  // loop over all tracks
147  for(size_t t = 0; t < tracks.size(); ++t){
148 
149  std::pair<size_t, art::Ptr<recob::Track> > idxTrk(t, tracks[t]);
150 
151  // in the ProngCheater module we set the prong ID to be
152  // the particle track ID creating the energy depositions
153  // of the prong
154  int prongID = tracks[t]->ID();
155 
156  // now get the mother particle of this prong if it exists
157  // set the eveID to the mother particle track ID, or to the
158  // ID of this prong if it is primary and mother ID = 0
159  int eveID = plist[prongID]->Mother();
160  if( eveID < 1 ) eveID = prongID;
161 
162  if(std::find(eveIDs.begin(), eveIDs.end(), eveID) == eveIDs.end())
163  eveIDs.push_back(eveID);
164 
165  // now we want to associate all prongs having the same
166  // eve ID, so look to see if there are other prongs with that
167  // ID
168  eveTrackMap[eveID].push_back(idxTrk);
169 
170  mf::LogInfo("VertexCheater") << "track: " << prongID << " has mother " << eveID;
171 
172  }// end loop over tracks
173 
174  std::unique_ptr< std::vector<recob::Vertex> > vertexcol(new std::vector<recob::Vertex>);
175  std::unique_ptr< art::Assns<recob::Vertex, recob::Shower> > vsassn(new art::Assns<recob::Vertex, recob::Shower>);
176  std::unique_ptr< art::Assns<recob::Vertex, recob::Track> > vtassn(new art::Assns<recob::Vertex, recob::Track>);
177  std::unique_ptr< art::Assns<recob::Vertex, recob::Hit> > vhassn(new art::Assns<recob::Vertex, recob::Hit>);
178 
179  // loop over the eve ID values and make Vertexs
180  for(auto const& eveID : eveIDs){
181 
182  // Vertex objects require PtrVectors of showers and tracks as well
183  // as a vertex position for their constructor
186  std::vector<size_t> idxShw;
187  std::vector<size_t> idxTrk;
188 
189  // first get the showers
190  if(eveShowerMap.find(eveID) != eveShowerMap.end()){
191  auto const& eveShowers = eveShowerMap[eveID];
192  for(auto const& is : eveShowers){
193  ptrvshw.push_back(is.second);
194  idxShw.push_back(is.first);
195  } // end loop over showers for this particle
196  } // end find showers for this particle
197 
198  // now the tracks
199  if(eveTrackMap.find(eveID) != eveTrackMap.end()){
200  auto const& eveTracks = eveTrackMap[eveID];
201  for(auto const& it : eveTracks){
202  ptrvtrk.push_back(it.second);
203  idxTrk.push_back(it.first);
204  } // end loop over tracks for this particle
205  } // end find tracks for this particle
206 
207  double xyz[3] = { plist[eveID]->Vx(),
208  plist[eveID]->Vy(),
209  plist[eveID]->Vz() };
210 
211  // add a vector to the collection.
212  vertexcol->push_back(recob::Vertex(xyz, eveID));
213 
214  // associate the vertex with its showers and tracks
215 
216  if( ptrvtrk.size() > 0 ){
217  util::CreateAssn(*this, evt, *vertexcol, ptrvtrk, *vtassn);
218 
219  // get the hits associated with each track and associate those with the vertex
220  for(auto const& i : idxTrk){
221  std::vector< art::Ptr<recob::Hit> > hits = fmht.at(i);
222  util::CreateAssn(*this, evt, *vertexcol, hits, *vhassn);
223  }
224  }
225 
226  if( ptrvshw.size() > 0 ){
227  util::CreateAssn(*this, evt, *vertexcol, ptrvshw, *vsassn);
228  // get the hits associated with each shower and associate those with the vertex
229  for(auto const& i : idxShw){
230  std::vector< art::Ptr<recob::Hit> > hits = fmhs.at(i);
231  util::CreateAssn(*this, evt, *vertexcol, hits, *vhassn);
232  }
233  }
234 
235  mf::LogInfo("VertexCheater") << "adding vertex: \n"
236  << vertexcol->back()
237  << "\nto collection.";
238 
239  } // end loop over the eve ID values
240 
241  evt.put(std::move(vertexcol));
242  evt.put(std::move(vsassn));
243  evt.put(std::move(vtassn));
244  evt.put(std::move(vhassn));
245 
246  return;
247 
248  } // end produce
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fCheatedTrackLabel
label for module creating recob::Track objects
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
def move(depos, offset)
Definition: depos.py:107
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.
size_type size() const
Definition: PtrVector.h:302
const sim::ParticleList & ParticleList() const
std::string fCheatedShowerLabel
label for module creating recob::Shower objects
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

std::string vertex::VertexCheater::fCheatedShowerLabel
private

label for module creating recob::Shower objects

Definition at line 41 of file VertexCheater_module.cc.

std::string vertex::VertexCheater::fCheatedTrackLabel
private

label for module creating recob::Track objects

Definition at line 40 of file VertexCheater_module.cc.

std::string vertex::VertexCheater::fG4ModuleLabel
private

label for module running G4 and making particles, etc

Definition at line 42 of file VertexCheater_module.cc.


The documentation for this class was generated from the following file: