All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PandoraMetadataPrinter.cc
Go to the documentation of this file.
1 /**
2  * \file PandoraMetadataPrinter.cc
3  *
4  *
5  * Author:
6  */
7 
8 #include <iostream>
9 #include <array>
10 
11 #include "canvas/Utilities/InputTag.h"
12 #include "core/SelectionBase.hh"
13 #include "core/Event.hh"
14 #include "core/Experiment.hh"
15 #include "core/ProviderManager.hh"
16 
23 #include "canvas/Persistency/Common/FindManyP.h"
24 #include "fhiclcpp/ParameterSet.h"
25 
26 #include "TH1D.h"
27 #include "TGraph.h"
28 
29 namespace ana {
30  namespace SBNOsc {
31 
32 /**
33  * \class PandoraMetadataPrinter
34  * \brief Electron neutrino event selection
35  */
37 public:
38  /** Constructor. */
40 
41  /**
42  * Initialization.
43  *
44  * \param config A configuration, as a FHiCL ParameterSet object
45  */
46  void Initialize(fhicl::ParameterSet* config=NULL) {
47  fPandoraTags = config ? config->get<std::vector<std::string>>("PandoraTags", {"pandora"}) : std::vector<std::string>(1,"pandora");
48  event_ind = 0;
49  }
50 
51  /** Finalize and write objects to the output file. */
52  void Finalize() {
53  }
54 
55  /**
56  * Process one event.
57  *
58  * \param ev A single event, as a gallery::Event
59  * \param Reconstructed interactions
60  * \return True to keep event
61  */
62  bool ProcessEvent(const gallery::Event& ev, const std::vector<event::Interaction> &truth, std::vector<event::RecoInteraction>& reco) {
63  std::cout << "\nNew Event!\n";
64  for (unsigned j = 0; j < fPandoraTags.size(); j++) {
65  auto const &slices_handle = ev.getValidHandle<std::vector<recob::Slice>>(fPandoraTags[j]);
66  auto const &particles_handle = ev.getValidHandle<std::vector<recob::PFParticle>>(fPandoraTags[j]);
67 
68  art::FindManyP<recob::PFParticle, void> slice_to_particle(slices_handle, ev, fPandoraTags[j]);
69  art::FindManyP<larpandoraobj::PFParticleMetadata, void> particles_to_metadata(particles_handle, ev, fPandoraTags[j]);
70 
71  for (unsigned i = 0; i < slices_handle->size(); i++) {
72  std::cout << "New Slice!\n";
73  const recob::Slice &slice = (*slices_handle)[i];
74  const std::vector<art::Ptr<recob::PFParticle>> slice_particles = slice_to_particle.at(i);
75  for (unsigned k = 0; k < slice_particles.size(); k++) {
76  const art::Ptr<recob::PFParticle> pfp_part = slice_particles[k];
77  if (pfp_part->IsPrimary()) {
78  const larpandoraobj::PFParticleMetadata &meta = *particles_to_metadata.at(pfp_part->Self()).at(0);
79  auto const &properties = meta.GetPropertiesMap();
80  if (properties.count("NuScore")) {
81  std::cout << "NuScore: " << properties.at("NuScore") << std::endl;
82  }
83  }
84  }
85  }
86  }
87 
88  // print particle information
89  for (unsigned j = 0; j < fPandoraTags.size(); j++) {
90  auto const &particles_handle = ev.getValidHandle<std::vector<recob::PFParticle>>(fPandoraTags[j]);
91  art::FindManyP<larpandoraobj::PFParticleMetadata, void> particles_to_metadata(particles_handle, ev, fPandoraTags[j]);
92  std::cout << "TAG: " << fPandoraTags[j] << std::endl;
93  for (unsigned i = 0; i < particles_handle->size(); i++) {
94  std::cout << "Particle PDG: " << particles_handle->at(i).PdgCode() << std::endl;
95  std::vector<art::Ptr<larpandoraobj::PFParticleMetadata>> metadatas = particles_to_metadata.at(i);
96  if (metadatas.size() > 0) {
97  assert(metadatas.size() == 1);
98  const larpandoraobj::PFParticleMetadata &metadata = *metadatas[0];
99  std::cout << "New PFParticle!\n";
100  for (auto const &prop_pair: metadata.GetPropertiesMap()) {
101  std::cout << prop_pair.first << " " << prop_pair.second << std::endl;
102  }
103  }
104  }
105  }
106  return false;
107  }
108 
109 protected:
110  std::vector<std::string> fPandoraTags;
111  unsigned event_ind;
112 };
113 
114  } // namespace SBNOsc
115 } // namespace ana
117 
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
process_name opflashCryoW ana
process_name standard_reco_uboone reco
Metadata associated to PFParticles.
Electron neutrino event selection.
const PropertiesMap & GetPropertiesMap() const
#define DECLARE_SBN_PROCESSOR(classname)
void Initialize(fhicl::ParameterSet *config=NULL)
Base class for event selections.
pdgs k
Definition: selectors.fcl:22
BEGIN_PROLOG could also be cout