All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExampleSelection.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <TH2D.h>
4 #include "fhiclcpp/ParameterSet.h"
5 #include "gallery/ValidHandle.h"
6 #include "canvas/Utilities/InputTag.h"
7 #include "nusimdata/SimulationBase/MCTruth.h"
8 #include "nusimdata/SimulationBase/MCNeutrino.h"
10 #include "ExampleSelection.h"
11 #include "ExampleTools.h"
12 #include "core/Event.hh"
13 #include "util/Interaction.hh"
14 #include "core/ProviderManager.hh"
15 
16 namespace ana {
17  namespace ExampleAnalysis {
18 
20  : SelectionBase(), fNuCount(0), fEventCounter(0) {}
21 
22 
23 void ExampleSelection::Initialize(fhicl::ParameterSet* config) {
24  // Make a histogram
25  fNuVertexXZHist = new TH2D("nu_vtx_XZ", "",
26  100, -1000, 1000, 100, -1000, 1000);
27 
28  // Load configuration parameters
29  fMyParam = 0;
30  fTruthTag = { "generator" };
31 
32  if (config) {
33  fhicl::ParameterSet pconfig = \
34  config->get<fhicl::ParameterSet>("ExampleAnalysis");
35 
36  fMyParam = pconfig.get<int>("parameter", 0);
37 
38  fTruthTag = \
39  { pconfig.get<std::string>("MCTruthTag", "generator") };
40  }
41 
42  // Add custom branches
43  AddBranch("nucount", &fNuCount);
44  AddBranch("myvar", &fMyVar);
45 
46  // Use LArSoft service functions via the ProviderManager
47  if (fProviderManager) {
48  std::cout << "Detector: "
50  << std::endl;
51  }
52 
53  // Use some library code
54  hello();
55 }
56 
57 
59  // Output our histograms to the ROOT file
60  fOutputFile->cd();
61  fNuVertexXZHist->Write();
62 }
63 
64 
66  const gallery::Event& ev,
67  const std::vector<event::Interaction>& truth,
68  std::vector<event::RecoInteraction>& reco) {
69  if (fEventCounter % 10 == 0) {
70  std::cout << "ExampleSelection: Processing event "
71  << fEventCounter << std::endl;
72  }
73  fEventCounter++;
74 
75  // Grab a data product from the event
76  auto const& mctruths = \
77  *ev.getValidHandle<std::vector<simb::MCTruth>>(fTruthTag);
78 
79  // Fill in the custom branches
80  fNuCount = mctruths.size(); // Number of neutrinos in this event
81  fMyVar = fMyParam;
82 
83  // Iterate through the neutrinos
84  for (size_t i=0; i<mctruths.size(); i++) {
85  auto const& mctruth = mctruths.at(i);
86 
87  // Fill neutrino vertex position histogram
88  if (mctruth.NeutrinoSet()) {
89  fNuVertexXZHist->Fill(mctruth.GetNeutrino().Nu().Vx(),
90  mctruth.GetNeutrino().Nu().Vz());
91  }
92  // Add in the "reconstructed" interaction
93  //
94  // Contruct truth information from the provided vector
95  event::RecoInteraction interaction(i);
96  // get "reconstructed" energy
97  interaction.reco_energy = util::ECCQE(mctruth.GetNeutrino().Nu().Momentum().Vect(), mctruth.GetNeutrino().Lepton().E());
98  reco.push_back(interaction);
99  }
100 
101  return true;
102 }
103 
104  } // namespace ExampleAnalysis
105 } // namespace ana
106 
107 
108 // This line must be included for all selections!
110 
TH2D * fNuVertexXZHist
Neutrino vertex XZ projection.
void Initialize(fhicl::ParameterSet *config=NULL)
double ECCQE(const TVector3 &l_momentum, double l_energy)
Definition: Interaction.cxx:7
TFile * fOutputFile
The output ROOT file.
An example selection analysis.
process_name opflashCryoW ana
bool ProcessEvent(const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
const geo::GeometryCore * GetGeometryProvider() const
Access the description of detector geometry.
Contains truth level information and additional fields for selection-defined reconstruction informati...
Definition: Event.hh:178
float reco_energy
Reconstructed neutrino energy [GeV].
Definition: Event.hh:195
process_name standard_reco_uboone reco
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
#define DECLARE_SBN_PROCESSOR(classname)
unsigned fEventCounter
Count processed events.
int fMyParam
A parameter from the configuration file.
ProviderManager * fProviderManager
Interface for provider access.
int fNuCount
Number of neutrino interactions in the event.
TBranch * AddBranch(std::string name, T *obj)
int fMyVar
Another variable of interest.
art::InputTag fTruthTag
art tag for MCTruth information
BEGIN_PROLOG could also be cout