VtxScore_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: VtxScore
3 // Plugin Type: analyzer (art v3_02_06)
4 // File: VtxScore_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 VtxScore;
27 }
28 
29 
31 public:
32  explicit VtxScore(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  VtxScore(VtxScore const&) = delete;
38  VtxScore(VtxScore&&) = delete;
39  VtxScore& operator=(VtxScore const&) = delete;
40  VtxScore& operator=(VtxScore&&) = 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 
96  std::vector<art::Ptr<recob::Hit> > hitlist;
97  auto hitListHandle = e.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel);
98  if (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,3> 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  score_inel.push_back(cnn_out[hitResults.getIndex("inel")]);
115  score_el.push_back(cnn_out[hitResults.getIndex("el")]);
116  score_none.push_back(cnn_out[hitResults.getIndex("none")]);
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  ftree->Branch("score_inel", &score_inel);
141  ftree->Branch("score_el", &score_el);
142  ftree->Branch("score_none", &score_none);
143 }
144 
std::vector< double > score_el
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
void analyze(art::Event const &e) override
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 > plane
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art::InputTag fNNetModuleLabel
std::vector< short > wire
std::vector< double > score_none
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
VtxScore & operator=(VtxScore const &)=delete
std::vector< double > charge
p
Definition: test.py:223
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
void beginJob() override
Detector simulation of raw signals on wires.
VtxScore(fhicl::ParameterSet const &p)
Declaration of signal hit object.
std::vector< double > score_inel
std::vector< double > peakt
EventNumber_t event() const
Definition: EventID.h:116
art::InputTag fHitsModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
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
std::vector< short > tpc
std::vector< short > channel
Event finding and building.