LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
shower::EMShower Class Reference
Inheritance diagram for shower::EMShower:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 EMShower (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
void reconfigure (fhicl::ParameterSet const &p)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Attributes

art::InputTag fHitsModuleLabel
 
art::InputTag fClusterModuleLabel
 
art::InputTag fTrackModuleLabel
 
art::InputTag fPFParticleModuleLabel
 
art::InputTag fVertexModuleLabel
 
art::InputTag fCNNEMModuleLabel
 
EMShowerAlg fEMShowerAlg
 
bool fSaveNonCompleteShowers
 
bool fFindBadPlanes
 
bool fMakeSpacePoints
 
bool fUseCNNtoIDEMPFP
 
bool fUseCNNtoIDEMHit
 
double fMinTrackLikeScore
 
art::ServiceHandle< geo::GeometryfGeom
 
detinfo::DetectorProperties const * fDetProp = lar::providerFrom<detinfo::DetectorPropertiesService>()
 
int fShower
 
int fPlane
 
int fDebug
 

Detailed Description

Definition at line 59 of file EMShower_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

shower::EMShower::EMShower ( fhicl::ParameterSet const &  pset)

Definition at line 88 of file EMShower_module.cc.

References reconfigure().

88  : fEMShowerAlg(pset.get<fhicl::ParameterSet>("EMShowerAlg")) {
89  this->reconfigure(pset);
90  produces<std::vector<recob::Shower> >();
91  produces<std::vector<recob::SpacePoint> >();
92  produces<art::Assns<recob::Shower, recob::Hit> >();
93  produces<art::Assns<recob::Shower, recob::Cluster> >();
94  produces<art::Assns<recob::Shower, recob::Track> >();
95  produces<art::Assns<recob::Shower, recob::SpacePoint> >();
96  produces<art::Assns<recob::SpacePoint, recob::Hit> >();
97 }
void reconfigure(fhicl::ParameterSet const &p)
EMShowerAlg fEMShowerAlg

Member Function Documentation

template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void shower::EMShower::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 118 of file EMShower_module.cc.

References shower::EMShowerAlg::AssociateClustersAndTracks(), art::PtrVector< T >::begin(), shower::EMShowerAlg::CheckShowerPlanes(), anab::MVAReader< T, N >::create(), util::CreateAssn(), DEFINE_ART_MODULE, art::InputTag::encode(), art::PtrVector< T >::end(), fClusterModuleLabel, fCNNEMModuleLabel, fDebug, fEMShowerAlg, fFindBadPlanes, fHitsModuleLabel, art::fill_ptr_vector(), shower::EMShowerAlg::FindInitialTrack(), shower::EMShowerAlg::FindShowers(), fMakeSpacePoints, fMinTrackLikeScore, fPFParticleModuleLabel, fPlane, fSaveNonCompleteShowers, fShower, fTrackModuleLabel, fUseCNNtoIDEMHit, fUseCNNtoIDEMPFP, fVertexModuleLabel, art::DataViewImpl::getByLabel(), hits(), art::Handle< T >::isValid(), art::Ptr< T >::key(), shower::EMShowerAlg::MakeShower(), shower::EMShowerAlg::MakeSpacePoints(), shower::EMShowerAlg::OrderShowerHits(), recob::PFParticle::PdgCode(), art::PtrVector< T >::push_back(), art::Event::put(), recob::Shower::set_id(), recob::Shower::ShowerStart(), art::PtrVector< T >::size(), lar::dump::vector(), and recob::Vertex::XYZ().

118  {
119 
120  // Output -- showers and associations with hits and clusters
121  std::unique_ptr<std::vector<recob::Shower> > showers(new std::vector<recob::Shower>);
122  std::unique_ptr<std::vector<recob::SpacePoint> > spacePoints(new std::vector<recob::SpacePoint>);
123  std::unique_ptr<art::Assns<recob::Shower, recob::Cluster> > clusterAssociations(new art::Assns<recob::Shower, recob::Cluster>);
124  std::unique_ptr<art::Assns<recob::Shower, recob::Hit> > hitShowerAssociations(new art::Assns<recob::Shower, recob::Hit>);
125  std::unique_ptr<art::Assns<recob::Shower, recob::Track> > trackAssociations(new art::Assns<recob::Shower, recob::Track>);
126  std::unique_ptr<art::Assns<recob::Shower, recob::SpacePoint> > spShowerAssociations(new art::Assns<recob::Shower, recob::SpacePoint>);
127  std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit> > hitSpAssociations(new art::Assns<recob::SpacePoint, recob::Hit>);
128 
129  // Event has hits, tracks and clusters found already
130 
131  // Hits
133  std::vector<art::Ptr<recob::Hit> > hits;
134  if (evt.getByLabel(fHitsModuleLabel,hitHandle))
135  art::fill_ptr_vector(hits, hitHandle);
136 
137  // Tracks
139  std::vector<art::Ptr<recob::Track> > tracks;
140  if (evt.getByLabel(fTrackModuleLabel,trackHandle))
141  art::fill_ptr_vector(tracks, trackHandle);
142 
143  // Clusters
145  std::vector<art::Ptr<recob::Cluster> > clusters;
146  if (evt.getByLabel(fClusterModuleLabel,clusterHandle))
147  art::fill_ptr_vector(clusters, clusterHandle);
148 
149  // PFParticles
151  std::vector<art::Ptr<recob::PFParticle> > pfps;
152  if (evt.getByLabel(fPFParticleModuleLabel, pfpHandle))
153  art::fill_ptr_vector(pfps, pfpHandle);
154 
155  // PFParticles
157  std::vector<art::Ptr<recob::Vertex> > vertices;
158  if (evt.getByLabel(fVertexModuleLabel, vtxHandle))
159  art::fill_ptr_vector(vertices, vtxHandle);
160 
161  // Associations
162  art::FindManyP<recob::Hit> fmh(clusterHandle, evt, fClusterModuleLabel);
163  art::FindManyP<recob::Track> fmt(hitHandle, evt, fTrackModuleLabel);
166 
167  // Make showers
168  std::vector<std::vector<int> > newShowers;
169  std::vector<unsigned int> pfParticles;
170 
171  std::map<int,std::vector<int> > clusterToTracks;
172  std::map<int,std::vector<int> > trackToClusters;
173 
174  if (!pfpHandle.isValid()) {
175 
176  // Map between tracks and clusters
177  fEMShowerAlg.AssociateClustersAndTracks(clusters, fmh, fmt, clusterToTracks, trackToClusters);
178 
179  // Make initial showers
180  std::vector<std::vector<int> > initialShowers = fEMShowerAlg.FindShowers(trackToClusters);
181 
182  // Deal with views in which 2D reconstruction failed
183  std::vector<int> clustersToIgnore;
184  if (fFindBadPlanes)
185  clustersToIgnore = fEMShowerAlg.CheckShowerPlanes(initialShowers, clusters, fmh);
186  if (clustersToIgnore.size() > 0) {
187  clusterToTracks.clear();
188  trackToClusters.clear();
189  fEMShowerAlg.AssociateClustersAndTracks(clusters, fmh, fmt, clustersToIgnore, clusterToTracks, trackToClusters);
190  newShowers = fEMShowerAlg.FindShowers(trackToClusters);
191  }
192  else
193  newShowers = initialShowers;
194 
195  }
196 
197  else {
198 
199  // Use pfparticle information
201  for (size_t ipfp = 0; ipfp<pfps.size(); ++ipfp){
202  art::Ptr<recob::PFParticle> pfp = pfps[ipfp];
203  if (fCNNEMModuleLabel!="" && fUseCNNtoIDEMPFP){//use CNN to identify EM pfparticle
205  if (!hitResults){
206  throw cet::exception("EMShower") <<"Cannot get MVA results from "<<fCNNEMModuleLabel;
207  }
208  int trkLikeIdx = hitResults->getIndex("track");
209  int emLikeIdx = hitResults->getIndex("em");
210  if ((trkLikeIdx < 0) || (emLikeIdx < 0)){
211  throw cet::exception("EMShower") << "No em/track labeled columns in MVA data products.";
212  }
213  if (fmcp.isValid()){//find clusters
214  std::vector<art::Ptr<recob::Hit>> pfphits;
215  std::vector<art::Ptr<recob::Cluster> > clus = fmcp.at(ipfp);
216  for (size_t iclu = 0; iclu<clus.size(); ++iclu){
217  std::vector<art::Ptr<recob::Hit> > ClusterHits = fmh.at(clus[iclu].key());
218  pfphits.insert(pfphits.end(), ClusterHits.begin(), ClusterHits.end());
219  }
220  if (pfphits.size()){//find hits
221  auto vout = hitResults->getOutput(pfphits);
222  double trk_like = -1, trk_or_em = vout[trkLikeIdx] + vout[emLikeIdx];
223  if (trk_or_em > 0){
224  trk_like = vout[trkLikeIdx] / trk_or_em;
225  if (trk_like<fMinTrackLikeScore){ //EM like
226  std::vector<int> clusters;
227  for (size_t iclu = 0; iclu<clus.size(); ++iclu){
228  clusters.push_back(clus[iclu].key());
229  }
230  if (clusters.size()){
231  newShowers.push_back(clusters);
232  pfParticles.push_back(ipfp);
233  }
234  }
235  }
236  }
237  }
238  else{
239  throw cet::exception("EMShower") <<"Cannot get associated cluster for PFParticle "<<fPFParticleModuleLabel.encode()<<"["<<ipfp<<"]";
240  }
241  }
242  else if (pfp->PdgCode()==11){ //shower particle
243  if (fmcp.isValid()){
244  std::vector<int> clusters;
245  std::vector<art::Ptr<recob::Cluster> > clus = fmcp.at(ipfp);
246  for (size_t iclu = 0; iclu<clus.size(); ++iclu){
247  clusters.push_back(clus[iclu].key());
248  }
249  if (clusters.size()){
250  newShowers.push_back(clusters);
251  pfParticles.push_back(ipfp);
252  }
253  }
254  }
255  }
256  }
257 
258  // Make output larsoft products
259  int showerNum = 0;
260  for (std::vector<std::vector<int> >::iterator newShower = newShowers.begin(); newShower != newShowers.end(); ++newShower, ++showerNum) {
261 
262  if (showerNum != fShower and fShower != -1) continue;
263 
264  // New shower
265  if (fDebug > 0)
266  std::cout << std::endl << std::endl << "Start shower " << showerNum << std::endl;
267 
268  // New associations
269  art::PtrVector<recob::Hit> showerHits;
270  art::PtrVector<recob::Cluster> showerClusters;
271  art::PtrVector<recob::Track> showerTracks;
272  art::PtrVector<recob::SpacePoint> showerSpacePoints_p;
273 
274  std::vector<int> associatedTracks;
275 
276  // Make showers and associations
277  for (std::vector<int>::iterator showerCluster = (*newShower).begin(); showerCluster != (*newShower).end(); ++showerCluster) {
278 
279  // Clusters
280  art::Ptr<recob::Cluster> cluster = clusters.at(*showerCluster);
281  showerClusters.push_back(cluster);
282 
283  // Hits
284  std::vector<art::Ptr<recob::Hit> > showerClusterHits = fmh.at(cluster.key());
285  if (fCNNEMModuleLabel!="" && fUseCNNtoIDEMHit){//use CNN to identify EM hits
287  if (!hitResults){
288  throw cet::exception("EMShower") <<"Cannot get MVA results from "<<fCNNEMModuleLabel.encode();
289  }
290  int trkLikeIdx = hitResults->getIndex("track");
291  int emLikeIdx = hitResults->getIndex("em");
292  if ((trkLikeIdx < 0) || (emLikeIdx < 0)){
293  throw cet::exception("EMShower") << "No em/track labeled columns in MVA data products.";
294  }
295  for (auto & showerHit : showerClusterHits){
296  auto vout = hitResults->getOutput(showerHit);
297  double trk_like = -1, trk_or_em = vout[trkLikeIdx] + vout[emLikeIdx];
298  if (trk_or_em > 0){
299  trk_like = vout[trkLikeIdx] / trk_or_em;
300  if (trk_like<fMinTrackLikeScore){ //EM like
301  showerHits.push_back(showerHit);
302  }
303  }
304  }
305  }
306  else{
307  for (std::vector<art::Ptr<recob::Hit> >::iterator showerClusterHit = showerClusterHits.begin(); showerClusterHit != showerClusterHits.end(); ++showerClusterHit)
308  showerHits.push_back(*showerClusterHit);
309  }
310  // Tracks
311  if (!pfpHandle.isValid()) { // Only do this for non-pfparticle mode
312  std::vector<int> clusterTracks = clusterToTracks.at(*showerCluster);
313  for (std::vector<int>::iterator clusterTracksIt = clusterTracks.begin(); clusterTracksIt != clusterTracks.end(); ++clusterTracksIt)
314  if (std::find(associatedTracks.begin(), associatedTracks.end(), *clusterTracksIt) == associatedTracks.end())
315  associatedTracks.push_back(*clusterTracksIt);
316  }
317  }
318 
319  if (!pfpHandle.isValid()) { // For non-pfparticles, get space points from tracks
320  // Tracks and space points
321  for (std::vector<int>::iterator associatedTracksIt = associatedTracks.begin(); associatedTracksIt != associatedTracks.end(); ++associatedTracksIt) {
322  art::Ptr<recob::Track> showerTrack = tracks.at(*associatedTracksIt);
323  showerTracks.push_back(showerTrack);
324  }
325  }
326 
327  else { // For pfparticles, get space points from hits
329  for (size_t ihit = 0; ihit<showerHits.size(); ++ihit){
330  if (fmspp.isValid()){
331  std::vector<art::Ptr<recob::SpacePoint> > spacePoints_pfp = fmspp.at(ihit);
332  for (std::vector<art::Ptr<recob::SpacePoint> >::iterator spacePointsIt = spacePoints_pfp.begin(); spacePointsIt != spacePoints_pfp.end(); ++spacePointsIt)
333  showerSpacePoints_p.push_back(*spacePointsIt);
334  }
335  }
336  }
337 
338  if (!pfpHandle.isValid()) {
339 
340  // First, order the hits into the correct shower order in each plane
341  if (fDebug > 1)
342  std::cout << " ------------------ Ordering shower hits -------------------- " << std::endl;
343  std::map<int,std::vector<art::Ptr<recob::Hit> > > showerHitsMap = fEMShowerAlg.OrderShowerHits(showerHits, fPlane);
344  if (fDebug > 1)
345  std::cout << " ------------------ End ordering shower hits -------------------- " << std::endl;
346 
347  // Find the track at the start of the shower
348  std::unique_ptr<recob::Track> initialTrack;
349  std::map<int,std::vector<art::Ptr<recob::Hit> > > initialTrackHits;
350  fEMShowerAlg.FindInitialTrack(showerHitsMap, initialTrack, initialTrackHits, fPlane);
351 
352  // Make space points
353  std::vector<std::vector<art::Ptr<recob::Hit> > > hitAssns;
354  std::vector<recob::SpacePoint> showerSpacePoints;
355  if (fMakeSpacePoints)
356  showerSpacePoints = fEMShowerAlg.MakeSpacePoints(showerHitsMap, hitAssns);
357  else {
358  for (art::PtrVector<recob::Track>::const_iterator trackIt = showerTracks.begin(); trackIt != showerTracks.end(); ++trackIt) {
359  const std::vector<art::Ptr<recob::SpacePoint> > trackSpacePoints = fmsp.at(trackIt->key());
360  for (std::vector<art::Ptr<recob::SpacePoint> >::const_iterator trackSpIt = trackSpacePoints.begin(); trackSpIt != trackSpacePoints.end(); ++trackSpIt) {
361  showerSpacePoints.push_back(*(*trackSpIt));
362  hitAssns.push_back(std::vector<art::Ptr<recob::Hit> >());
363  }
364  }
365  }
366 
367  // Save space points
368  int firstSpacePoint = spacePoints->size(), nSpacePoint = 0;
369  for (std::vector<recob::SpacePoint>::const_iterator sspIt = showerSpacePoints.begin(); sspIt != showerSpacePoints.end(); ++sspIt, ++nSpacePoint) {
370  spacePoints->emplace_back(sspIt->XYZ(), sspIt->ErrXYZ(), sspIt->Chisq(), spacePoints->size());
371  util::CreateAssn(*this, evt, *(spacePoints.get()), hitAssns.at(nSpacePoint), *(hitSpAssociations.get()));
372  }
373  int lastSpacePoint = spacePoints->size();
374 
375  // Make shower object and associations
376  recob::Shower shower = fEMShowerAlg.MakeShower(showerHits, initialTrack, initialTrackHits);
377  shower.set_id(showerNum);
378  if ( fSaveNonCompleteShowers or (!fSaveNonCompleteShowers and shower.ShowerStart() != TVector3(0,0,0)) ) {
379  showers->push_back(shower);
380  util::CreateAssn(*this, evt, *(showers.get()), showerHits, *(hitShowerAssociations.get()));
381  util::CreateAssn(*this, evt, *(showers.get()), showerClusters, *(clusterAssociations.get()));
382  util::CreateAssn(*this, evt, *(showers.get()), showerTracks, *(trackAssociations.get()));
383  util::CreateAssn(*this, evt, *(showers.get()), *(spacePoints.get()), *(spShowerAssociations.get()), firstSpacePoint, lastSpacePoint);
384  }
385  else
386  mf::LogInfo("EMShower") << "Discarding shower " << showerNum << " due to incompleteness (SaveNonCompleteShowers == false)";
387  }
388 
389  else { // pfParticle
390 
391  if (vertices.size()) {
392  //found the most upstream vertex
393  TVector3 nuvtx(0,0,DBL_MAX);
394  for (auto & vtx: vertices){
395  double xyz[3];
396  vtx->XYZ(xyz);
397  if (xyz[2]<nuvtx.Z()){
398  nuvtx.SetXYZ(xyz[0], xyz[1], xyz[2]);
399  }
400  }
401 
402  TVector3 shwvtx(0,0,0);
403  double mindis = DBL_MAX;
404  for (auto &sp : showerSpacePoints_p){
405  double dis = sqrt(pow(nuvtx.X()-sp->XYZ()[0],2)+pow(nuvtx.X()-sp->XYZ()[1],2)+pow(nuvtx.X()-sp->XYZ()[2],2));
406  if (dis<mindis){
407  mindis = dis;
408  shwvtx.SetXYZ(sp->XYZ()[0], sp->XYZ()[1], sp->XYZ()[2]);
409  }
410  }
411 
412  art::Ptr<recob::Vertex> bestvtx;
413  mindis = DBL_MAX;
414  for (auto & vtx: vertices){
415  double xyz[3];
416  vtx->XYZ(xyz);
417  double dis = sqrt(pow(xyz[0]-shwvtx.X(),2)+pow(xyz[1]-shwvtx.Y(),2)+pow(xyz[2]-shwvtx.Z(),2));
418  if (dis<mindis){
419  mindis = dis;
420  bestvtx = vtx;
421  }
422  }
423 
424  int iok = 0;
425 
426  recob::Shower shower = fEMShowerAlg.MakeShower(showerHits, bestvtx, iok);
427  //shower.set_id(showerNum);
428  if (iok==0) {
429  showers->push_back(shower);
430  showers->back().set_id(showers->size()-1);
431  util::CreateAssn(*this, evt, *(showers.get()), showerHits, *(hitShowerAssociations.get()));
432  util::CreateAssn(*this, evt, *(showers.get()), showerClusters, *(clusterAssociations.get()));
433  util::CreateAssn(*this, evt, *(showers.get()), showerTracks, *(trackAssociations.get()));
434  util::CreateAssn(*this, evt, *(showers.get()), showerSpacePoints_p, *(spShowerAssociations.get()));
435  }
436  }
437 
438  }
439 
440  }
441 
442  // Put in event
443  evt.put(std::move(showers));
444  evt.put(std::move(spacePoints));
445  evt.put(std::move(hitShowerAssociations));
446  evt.put(std::move(clusterAssociations));
447  evt.put(std::move(trackAssociations));
448  evt.put(std::move(spShowerAssociations));
449  evt.put(std::move(hitSpAssociations));
450 
451 }
key_type key() const
Definition: Ptr.h:356
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
Definition: Vertex.cxx:37
const TVector3 & ShowerStart() const
Definition: Shower.h:192
art::InputTag fClusterModuleLabel
intermediate_table::iterator iterator
std::vector< recob::SpacePoint > MakeSpacePoints(std::map< int, std::vector< art::Ptr< recob::Hit > > > hits, std::vector< std::vector< art::Ptr< recob::Hit > > > &hitAssns)
Makes space points from the shower hits in each plane.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
iterator begin()
Definition: PtrVector.h:223
art::InputTag fVertexModuleLabel
std::map< int, std::vector< art::Ptr< recob::Hit > > > OrderShowerHits(const art::PtrVector< recob::Hit > &shower, int plane)
Takes the hits associated with a shower and orders them so they follow the direction of the shower...
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
Cluster finding and building.
art::InputTag fTrackModuleLabel
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void set_id(const int id)
Definition: Shower.h:128
bool isValid() const
Definition: Handle.h:190
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
void hits()
Definition: readHits.C:15
std::vector< std::vector< int > > FindShowers(std::map< int, std::vector< int > > const &trackToClusters)
Makes showers given a map between tracks and all clusters associated with them.
intermediate_table::const_iterator const_iterator
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
std::string encode() const
Definition: InputTag.cc:36
void AssociateClustersAndTracks(std::vector< art::Ptr< recob::Cluster > > const &clusters, art::FindManyP< recob::Hit > const &fmh, art::FindManyP< recob::Track > const &fmt, std::map< int, std::vector< int > > &clusterToTracks, std::map< int, std::vector< int > > &trackToClusters)
Map associated tracks and clusters together given their associated hits.
Definition: EMShowerAlg.cxx:43
iterator end()
Definition: PtrVector.h:237
art::InputTag fHitsModuleLabel
art::InputTag fCNNEMModuleLabel
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.
art::InputTag fPFParticleModuleLabel
size_type size() const
Definition: PtrVector.h:308
void FindInitialTrack(const std::map< int, std::vector< art::Ptr< recob::Hit > > > &hits, std::unique_ptr< recob::Track > &initialTrack, std::map< int, std::vector< art::Ptr< recob::Hit > > > &initialTrackHits, int plane)
Finds the initial track-like part of the shower and the hits in all views associated with it...
data_t::const_iterator const_iterator
Definition: PtrVector.h:61
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
recob::Shower MakeShower(art::PtrVector< recob::Hit > const &hits, std::unique_ptr< recob::Track > const &initialTrack, std::map< int, std::vector< art::Ptr< recob::Hit > > > const &initialTrackHits)
Makes a recob::Shower object given the hits in the shower and the initial track-like part...
std::vector< int > CheckShowerPlanes(std::vector< std::vector< int > > const &initialShowers, std::vector< art::Ptr< recob::Cluster > > const &clusters, art::FindManyP< recob::Hit > const &fmh)
Takes the initial showers found and tries to resolve issues where one bad view ruins the event...
EMShowerAlg fEMShowerAlg
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void shower::EMShower::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 99 of file EMShower_module.cc.

References fClusterModuleLabel, fCNNEMModuleLabel, fDebug, shower::EMShowerAlg::fDebug, fEMShowerAlg, fFindBadPlanes, fHitsModuleLabel, fMakeSpacePoints, fMinTrackLikeScore, fPFParticleModuleLabel, fPlane, fSaveNonCompleteShowers, fShower, fTrackModuleLabel, fUseCNNtoIDEMHit, fUseCNNtoIDEMPFP, fVertexModuleLabel, and fhicl::ParameterSet::get().

Referenced by EMShower().

99  {
100  fHitsModuleLabel = p.get<art::InputTag>("HitsModuleLabel");
101  fClusterModuleLabel = p.get<art::InputTag>("ClusterModuleLabel");
102  fTrackModuleLabel = p.get<art::InputTag>("TrackModuleLabel");
103  fPFParticleModuleLabel = p.get<art::InputTag>("PFParticleModuleLabel","");
104  fVertexModuleLabel = p.get<art::InputTag>("VertexModuleLabel","");
105  fCNNEMModuleLabel = p.get<art::InputTag>("CNNEMModuleLabel","");
106  fFindBadPlanes = p.get<bool> ("FindBadPlanes");
107  fSaveNonCompleteShowers = p.get<bool> ("SaveNonCompleteShowers");
108  fMakeSpacePoints = p.get<bool> ("MakeSpacePoints");
109  fUseCNNtoIDEMPFP = p.get<bool> ("UseCNNtoIDEMPFP");
110  fUseCNNtoIDEMHit = p.get<bool> ("UseCNNtoIDEMHit");
111  fMinTrackLikeScore = p.get<double> ("MinTrackLikeScore");
112  fShower = p.get<int>("Shower",-1);
113  fPlane = p.get<int>("Plane",-1);
114  fDebug = p.get<int>("Debug",0);
116 }
art::InputTag fClusterModuleLabel
art::InputTag fVertexModuleLabel
art::InputTag fTrackModuleLabel
art::InputTag fHitsModuleLabel
art::InputTag fCNNEMModuleLabel
art::InputTag fPFParticleModuleLabel
EMShowerAlg fEMShowerAlg
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

art::InputTag shower::EMShower::fClusterModuleLabel
private

Definition at line 69 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

art::InputTag shower::EMShower::fCNNEMModuleLabel
private

Definition at line 69 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

int shower::EMShower::fDebug
private

Definition at line 84 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

Definition at line 79 of file EMShower_module.cc.

EMShowerAlg shower::EMShower::fEMShowerAlg
private

Definition at line 70 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

bool shower::EMShower::fFindBadPlanes
private

Definition at line 72 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

art::ServiceHandle<geo::Geometry> shower::EMShower::fGeom
private

Definition at line 78 of file EMShower_module.cc.

art::InputTag shower::EMShower::fHitsModuleLabel
private

Definition at line 69 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

bool shower::EMShower::fMakeSpacePoints
private

Definition at line 73 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

double shower::EMShower::fMinTrackLikeScore
private

Definition at line 76 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

art::InputTag shower::EMShower::fPFParticleModuleLabel
private

Definition at line 69 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

int shower::EMShower::fPlane
private

Definition at line 82 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

bool shower::EMShower::fSaveNonCompleteShowers
private

Definition at line 71 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

int shower::EMShower::fShower
private

Definition at line 81 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

art::InputTag shower::EMShower::fTrackModuleLabel
private

Definition at line 69 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

bool shower::EMShower::fUseCNNtoIDEMHit
private

Definition at line 75 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

bool shower::EMShower::fUseCNNtoIDEMPFP
private

Definition at line 74 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().

art::InputTag shower::EMShower::fVertexModuleLabel
private

Definition at line 69 of file EMShower_module.cc.

Referenced by produce(), and reconfigure().


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