LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckCNNScore_module.cc
Go to the documentation of this file.
1 // Class: CheckCNNScore
3 // Plugin Type: analyzer (art v3_02_06)
4 // File: CheckCNNScore_module.cc
5 //
6 // Generated at Tue Oct 1 11:26:39 2019 by Tingjun Yang using cetskelgen
7 // from cetlib version v3_07_02.
9 
12 
20 #include "art_root_io/TFileService.h"
23 #include "fhiclcpp/ParameterSet.h"
24 
25 #include "TTree.h"
26 
27 #include <array>
28 #include <string>
29 #include <vector>
30 
31 namespace pdsp {
32  class CheckCNNScore;
33 }
34 
36 public:
37  explicit CheckCNNScore(fhicl::ParameterSet const& p);
38  // The compiler-generated destructor is fine for non-base
39  // classes without bare pointers or other resource use.
40 
41  // Plugins should not be copied or assigned.
42  CheckCNNScore(CheckCNNScore const&) = delete;
43  CheckCNNScore(CheckCNNScore&&) = delete;
44  CheckCNNScore& operator=(CheckCNNScore const&) = delete;
46 
47  // Required functions.
48  void analyze(art::Event const& e) override;
49 
50  // Selected optional functions.
51  void beginJob() override;
52 
53 private:
54  // Declare member data here.
55  // Input parameters
56  art::InputTag fNNetModuleLabel; // label of the module used for CNN tagging
57  art::InputTag fHitsModuleLabel; // label of hit finder module
58  std::vector<std::string> fNNOutputs; // label of network outputs
59 
60  TTree* ftree;
61  int run;
62  int subrun;
63  int event;
64  std::vector<short> channel;
65  std::vector<short> tpc;
66  std::vector<short> plane;
67  std::vector<short> wire;
68  std::vector<double> charge;
69  std::vector<double> peakt;
70  std::array<std::vector<double>, 4> scores;
71 };
72 
74  : EDAnalyzer{p}
75  , fNNetModuleLabel(p.get<art::InputTag>("NNetModuleLabel"))
76  , fHitsModuleLabel(p.get<art::InputTag>("HitsModuleLabel"))
77  , fNNOutputs(p.get<std::vector<std::string>>("NNOutputs"))
78 {}
79 
81 {
82 
83  run = e.run();
84  subrun = e.subRun();
85  event = e.id().event();
86  channel.clear();
87  tpc.clear();
88  plane.clear();
89  wire.clear();
90  charge.clear();
91  peakt.clear();
92  scores = {};
93 
95 
97  std::vector<art::Ptr<recob::Hit>> hitlist;
98  if (e.getByLabel(fHitsModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
99 
100  // loop over hits
101  // for (size_t h = 0; h < hitResults.size(); ++h) {
102  for (auto& hit : hitlist) {
103 
104  // Get cnn output for hit h
105  std::array<float, 4> cnn_out = hitResults.getOutput(hit);
106 
107  if (hit->WireID().Plane == 2) {
108  channel.push_back(hit->Channel());
109  tpc.push_back(hit->WireID().TPC);
110  plane.push_back(hit->WireID().Plane);
111  wire.push_back(hit->WireID().Wire);
112  charge.push_back(hit->Integral());
113  peakt.push_back(hit->PeakTime());
114  for (size_t i = 0; i < fNNOutputs.size(); ++i) {
115  scores[i].push_back(cnn_out[hitResults.getIndex(fNNOutputs[i])]);
116  }
117  // std::cout<<hit->WireID().TPC<<" "
118  // <<hit->WireID().Wire<<" "
119  // <<hit->PeakTime()<<" "
120  // <<cnn_out[hitResults.getIndex("el")]<<" "
121  // <<cnn_out[hitResults.getIndex("inel")]<<" "
122  // <<cnn_out[hitResults.getIndex("none")]<<std::endl;
123  }
124  }
125  if (!channel.empty()) ftree->Fill();
126 }
127 
129 {
130  art::ServiceHandle<art::TFileService> fileServiceHandle;
131  ftree = fileServiceHandle->make<TTree>("ftree", "hit info");
132  ftree->Branch("run", &run, "run/I");
133  ftree->Branch("event", &event, "event/I");
134  ftree->Branch("channel", &channel);
135  ftree->Branch("tpc", &tpc);
136  ftree->Branch("plane", &plane);
137  ftree->Branch("wire", &wire);
138  ftree->Branch("charge", &charge);
139  ftree->Branch("peakt", &peakt);
140  for (size_t i = 0; i < size(scores); ++i) {
141  ftree->Branch(Form("score_%ld", i), &scores[i]);
142  }
143 }
144 
SubRunNumber_t subRun() const
Definition: Event.cc:35
void analyze(art::Event const &e) override
std::vector< short > wire
Declaration of signal hit object.
std::array< std::vector< double >, 4 > scores
std::vector< short > plane
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
Definition: MVAReader.h:82
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
CheckCNNScore(fhicl::ParameterSet const &p)
std::vector< double > charge
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
CheckCNNScore & operator=(CheckCNNScore const &)=delete
Detector simulation of raw signals on wires.
art::InputTag fHitsModuleLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::vector< short > channel
art::InputTag fNNetModuleLabel
EventNumber_t event() const
Definition: EventID.h:116
std::vector< std::string > fNNOutputs
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
std::vector< double > peakt
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.cc:29
std::vector< short > tpc
std::array< float, N > getOutput(size_t key) const
Get copy of the MVA output vector at index "key".
Definition: MVAReader.h:127
EventID id() const
Definition: Event.cc:23
Event finding and building.