MichelHitCounter_module.cc
Go to the documentation of this file.
1 // Example module showing how to access and count
2 // michel elctron hits in reconstruction
3 
20 
23 #include "canvas/Persistency/Common/FindManyP.h"
29 #include "art_root_io/TFileService.h"
31 #include "fhiclcpp/ParameterSet.h"
33 
35 
36 #include "TTree.h"
37 
38 #include <fstream>
39 
40 namespace MichelReco {
41 
42 class MichelReco;
43 
44 class MichelReco : public art::EDAnalyzer {
45 public:
46  explicit MichelReco(fhicl::ParameterSet const & p);
47  // The destructor generated by the compiler is fine for classes
48  // without bare pointers or other resource use.
49 
50  // Plugins should not be copied or assigned.
51  MichelReco(MichelReco const &) = delete;
52  MichelReco(MichelReco &&) = delete;
53  MichelReco & operator = (MichelReco const &) = delete;
54  MichelReco & operator = (MichelReco &&) = delete;
55 
56  // Required functions.
57  void analyze(art::Event const & e) override;
58 
59  // Selected optional functions
60  void beginJob() override;
61  void endJob() override;
62  void beginRun(const art::Run& run) override;
63  void reconfigure(fhicl::ParameterSet const& p) ;
64 
65 private:
66  // My parameters
67  size_t fEvNumber; // Event number for each event
68  int fNMichelHits; // Total number of Michel hits in events
69 
70  // Input parameters
71  art::InputTag fNNetModuleLabel; // label of the module used for CNN tagging
72 };
73 
74 
76  :
77  EDAnalyzer(p)
78 {
79  reconfigure(p);
80 }
81 
83 {
85 }
86 
87 void MichelReco::endJob()
88 {
89  mf::LogVerbatim("MichelReco") << "MichelHitCounter finished job";
90  mf::LogVerbatim("MichelReco") << fNMichelHits << " michel hits found";
91 }
92 
93 void MichelReco::beginRun(const art::Run&)
94 {
96 }
97 
99 {
100  // keep track of progress
101  fEvNumber = evt.id().event();
102  mf::LogVerbatim("MichelReco") << "MichelReco module on event " << fEvNumber;
103 
104  // Helper to get hits and the 4 associated CNN outputs
105  // CNN Outputs: EM, Track, Michel, Empty
106  anab::MVAReader<recob::Hit,4> hitResults(evt, fNNetModuleLabel);
107 
108  // loop over hits
109  for (size_t h = 0; h < hitResults.size(); ++h) {
110 
111  // Get cnn output for hit h
112  std::array<float,4> cnn_out = hitResults.getOutput(h);
113 
114  // Compare michel cnn output to treshold to decide if Michel hit
115  // Example using 0.5, needs to be optimised with clustering
116  // e.g. 0.9 used for event selection
117  if (cnn_out[hitResults.getIndex("michel")] > 0.5) {
118  fNMichelHits += 1;
119  }
120 
121  } // End of loop over hits
122 
123 }
124 
126 {
127 
128  fNMichelHits = 0;
129  fNNetModuleLabel = p.get<std::string>("NNetModuleLabel");
130  return;
131 }
132 
133 } // MichelReco namespace
134 
def analyze(root, level, gtrees, gbranches, doprint)
Definition: rootstat.py:69
Store parameters for running LArG4.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
virtual void beginRun(Run const &)
Definition: EDAnalyzer.cc:115
Container of LAr voxel information.
std::string string
Definition: nybbler.cc:12
virtual void analyze(Event const &)=0
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
Definition: MVAReader.h:82
Particle class.
virtual void endJob()
Definition: EDAnalyzer.cc:95
art framework interface to geometry description
Definition: Run.h:17
virtual void beginJob()
Definition: EDAnalyzer.cc:91
const double e
Encapsulates the information we want store for a voxel.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void beginJob()
Definition: Breakpoints.cc:14
virtual void reconfigure(fhicl::ParameterSet const &pset)
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
size_t size() const
Get the number of contained items (no. of data product objects equal to no. of feature vectors)...
Definition: MVAReader.h:67
Observer & operator=(Observer const &)=delete
Implementation of the Projection Matching Algorithm.
Declaration of signal hit object.
Provides recob::Track data product.
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
Collection of Physical constants used in LArSoft.
std::array< float, N > getOutput(size_t key) const
Get copy of the MVA output vector at index "key".
Definition: MVAReader.h:129
EventID id() const
Definition: Event.cc:34