All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCParticleTreePrinter.cc
Go to the documentation of this file.
1 /**
2  * \file MCParticleTreePrinter.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 
20 #include "fhiclcpp/ParameterSet.h"
22 #include "nusimdata/SimulationBase/MCParticle.h"
24 #include "canvas/Persistency/Common/FindManyP.h"
25 #include "nusimdata/SimulationBase/MCTruth.h"
26 #include "TH1D.h"
27 #include "TGraph.h"
28 
29 namespace ana {
30  namespace SBNOsc {
31 
32 /**
33  * \class MCParticleTreePrinter
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  fMCParticleTag = config ? config->get<std::string>("MCParticleTag", "largeant") : "largeant";
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 << "New Event!\n";
64  auto const &mcparticle_handle = ev.getValidHandle<std::vector<simb::MCParticle>>(fMCParticleTag);;
65  const std::vector<simb::MCParticle> &mcparticles = *mcparticle_handle;
66  art::FindManyP<simb::MCTruth, sim::GeneratedParticleInfo> particles_to_truth(mcparticle_handle, ev, fMCParticleTag);
67  for (unsigned i = 0; i < mcparticles.size(); i++) {
68  const simb::MCParticle &part = mcparticles[i];
69  std::cout << "TrackID: " << part.TrackId() << " Mother: " << part.Mother() << " index: " << i<< std::endl;
70  const sim::GeneratedParticleInfo &info = *particles_to_truth.data(i).at(0);
71  const simb::MCTruth &mctruth = *particles_to_truth.at(i).at(0);
72  std::cout << "Info index: " << info.generatedParticleIndex() << std::endl;
73  if (info.generatedParticleIndex() < mctruth.NParticles()) {
74  int gen_track_id = mctruth.GetParticle(info.generatedParticleIndex()).TrackId();
75  std::cout << "Gen track ID: " << gen_track_id << std::endl;
76  }
77  }
78  return false;
79  }
80 
81 protected:
82  std::string fMCParticleTag;
83  unsigned event_ind;
84 };
85 
86  } // namespace SBNOsc
87 } // namespace ana
89 
void Initialize(fhicl::ParameterSet *config=NULL)
Contains data associated to particles from detector simulation.
process_name opflashCryoW ana
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
Simulation objects for optical detectors.
process_name standard_reco_uboone reco
Electron neutrino event selection.
#define DECLARE_SBN_PROCESSOR(classname)
Base class for event selections.
Contains information about a generated particle.
GeneratedParticleIndex_t generatedParticleIndex() const
Returns the generated particle index.
BEGIN_PROLOG could also be cout