CheckCNNScore_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // 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.
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "art_root_io/TFileService.h"
18 #include "fhiclcpp/ParameterSet.h"
22 
23 #include "TTree.h"
24 
25 namespace pdsp {
26  class CheckCNNScore;
27 }
28 
30 public:
31  explicit CheckCNNScore(fhicl::ParameterSet const& p);
32  // The compiler-generated destructor is fine for non-base
33  // classes without bare pointers or other resource use.
34 
35  // Plugins should not be copied or assigned.
36  CheckCNNScore(CheckCNNScore const&) = delete;
37  CheckCNNScore(CheckCNNScore&&) = delete;
38  CheckCNNScore& operator=(CheckCNNScore const&) = delete;
40 
41  // Required functions.
42  void analyze(art::Event const& e) override;
43 
44  // Selected optional functions.
45  void beginJob() override;
46 
47 private:
48  // Declare member data here.
49  // Input parameters
50  art::InputTag fNNetModuleLabel; // label of the module used for CNN tagging
51  art::InputTag fHitsModuleLabel; // label of hit finder module
52 
53  TTree* ftree;
54  int run;
55  int subrun;
56  int event;
57  std::vector<short> channel;
58  std::vector<short> tpc;
59  std::vector<short> plane;
60  std::vector<short> wire;
61  std::vector<double> charge;
62  std::vector<double> peakt;
63  std::vector<double> score_inel;
64  std::vector<double> score_el;
65  std::vector<double> score_none;
66 };
67 
69  : EDAnalyzer{p}
70  , fNNetModuleLabel(p.get<art::InputTag>("NNetModuleLabel"))
71  , fHitsModuleLabel(p.get<art::InputTag>("HitsModuleLabel"))
72 {}
73 
74 void
76 {
77 
78  run = e.run();
79  subrun = e.subRun();
80  event = e.id().event();
81  channel.clear();
82  tpc.clear();
83  plane.clear();
84  wire.clear();
85  charge.clear();
86  peakt.clear();
87  score_inel.clear();
88  score_el.clear();
89  score_none.clear();
90 
92 
94  std::vector<art::Ptr<recob::Hit>> hitlist;
95  if (e.getByLabel(fHitsModuleLabel, hitListHandle)) art::fill_ptr_vector(hitlist, hitListHandle);
96 
97  // loop over hits
98  // for (size_t h = 0; h < hitResults.size(); ++h) {
99  for (auto& hit : hitlist) {
100 
101  // Get cnn output for hit h
102  std::array<float, 3> cnn_out = hitResults.getOutput(hit);
103 
104  if (hit->WireID().Plane == 2) {
105  channel.push_back(hit->Channel());
106  tpc.push_back(hit->WireID().TPC);
107  plane.push_back(hit->WireID().Plane);
108  wire.push_back(hit->WireID().Wire);
109  charge.push_back(hit->Integral());
110  peakt.push_back(hit->PeakTime());
111  score_inel.push_back(cnn_out[hitResults.getIndex("inel")]);
112  score_el.push_back(cnn_out[hitResults.getIndex("el")]);
113  score_none.push_back(cnn_out[hitResults.getIndex("none")]);
114  // std::cout<<hit->WireID().TPC<<" "
115  // <<hit->WireID().Wire<<" "
116  // <<hit->PeakTime()<<" "
117  // <<cnn_out[hitResults.getIndex("el")]<<" "
118  // <<cnn_out[hitResults.getIndex("inel")]<<" "
119  // <<cnn_out[hitResults.getIndex("none")]<<std::endl;
120  }
121  }
122  if (!channel.empty()) ftree->Fill();
123 }
124 
125 void
127 {
128  art::ServiceHandle<art::TFileService> fileServiceHandle;
129  ftree = fileServiceHandle->make<TTree>("ftree", "hit info");
130  ftree->Branch("run", &run, "run/I");
131  ftree->Branch("event", &event, "event/I");
132  ftree->Branch("channel", &channel);
133  ftree->Branch("tpc", &tpc);
134  ftree->Branch("plane", &plane);
135  ftree->Branch("wire", &wire);
136  ftree->Branch("charge", &charge);
137  ftree->Branch("peakt", &peakt);
138  ftree->Branch("score_inel", &score_inel);
139  ftree->Branch("score_el", &score_el);
140  ftree->Branch("score_none", &score_none);
141 }
142 
void analyze(art::Event const &e) override
std::vector< short > wire
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.h:25
std::vector< double > score_inel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
CheckCNNScore(fhicl::ParameterSet const &p)
std::vector< double > charge
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
p
Definition: test.py:223
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
CheckCNNScore & operator=(CheckCNNScore const &)=delete
RunNumber_t run() const
Definition: DataViewImpl.cc:71
std::vector< double > score_none
Detector simulation of raw signals on wires.
art::InputTag fHitsModuleLabel
Declaration of signal hit object.
std::vector< short > channel
art::InputTag fNNetModuleLabel
EventNumber_t event() const
Definition: EventID.h:116
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::vector< double > peakt
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:129
EventID id() const
Definition: Event.cc:34
Event finding and building.
std::vector< double > score_el