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