LArSoft  v10_06_00
Liquid Argon Software toolkit - https://larsoft.org/
NuGraphAnalyzer_module.cc
Go to the documentation of this file.
1 // Class: NuGraphAnalyzer
3 // Plugin Type: analyzer (Unknown Unknown)
4 // File: NuGraphAnalyzer_module.cc
5 //
6 // Generated at Mon Nov 20 13:42:17 2023 by Giuseppe Cerati using cetskelgen
7 // from version .
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
20 // saving output
21 #include "TTree.h"
22 #include "art_root_io/TFileService.h"
23 
28 
29 class NuGraphAnalyzer;
30 
31 using std::vector;
32 
34 public:
35  explicit NuGraphAnalyzer(fhicl::ParameterSet const& p);
36  // The compiler-generated destructor is fine for non-base
37  // classes without bare pointers or other resource use.
38 
39  // Plugins should not be copied or assigned.
40  NuGraphAnalyzer(NuGraphAnalyzer const&) = delete;
41  NuGraphAnalyzer(NuGraphAnalyzer&&) = delete;
42  NuGraphAnalyzer& operator=(NuGraphAnalyzer const&) = delete;
44 
45  // Required functions.
46  void analyze(art::Event const& e) override;
47 
48 private:
49  // Declare member data here.
50  TTree *_treeHit, *_treeEvt;
53  float _vtx_x, _vtx_y, _vtx_z;
54  std::string nglabel;
55 };
56 
58  : EDAnalyzer{p}, nglabel{p.get<std::string>("NuGraphLabel", "NuGraph")}
59 {
60  // Call appropriate consumes<>() for any products to be retrieved by this module.
62  _treeHit = tfs->make<TTree>("NuGraphHitOutput", "NuGraphHitOutput");
63  _treeHit->Branch("run", &_run, "run/I");
64  _treeHit->Branch("subrun", &_subrun, "subrun/I");
65  _treeHit->Branch("event", &_event, "event/I");
66  _treeHit->Branch("id", &_id, "id/I");
67  _treeHit->Branch("wire", &_wire, "wire/I");
68  _treeHit->Branch("plane", &_plane, "plane/I");
69  _treeHit->Branch("tpc", &_tpc, "tpc/I");
70  _treeHit->Branch("cryo", &_cryo, "cryo/I");
71  _treeHit->Branch("x_filter", &_x_filter, "x_filter/F");
72  _treeHit->Branch("MIP", &_MIP, "MIP/F");
73  _treeHit->Branch("HIP", &_HIP, "HIP/F");
74  _treeHit->Branch("shower", &_shower, "shower/F");
75  _treeHit->Branch("michel", &_michel, "michel/F");
76  _treeHit->Branch("diffuse", &_diffuse, "diffuse/F");
77  _treeHit->Branch("time", &_time, "time/F");
78  _treeEvt = tfs->make<TTree>("NuGraphEventOutput", "NuGraphEventOutput");
79  _treeEvt->Branch("run", &_run, "run/I");
80  _treeEvt->Branch("subrun", &_subrun, "subrun/I");
81  _treeEvt->Branch("event", &_event, "event/I");
82  _treeEvt->Branch("vtx_x", &_vtx_x, "vtx_x/F");
83  _treeEvt->Branch("vtx_y", &_vtx_y, "vtx_y/F");
84  _treeEvt->Branch("vtx_z", &_vtx_z, "vtx_z/F");
85 }
86 
88 {
89 
90  auto GNNDescription = e.getHandle<anab::MVADescription<5>>(art::InputTag(nglabel, "semantic"));
91 
92  auto const& hitsWithScores = proxy::getCollection<std::vector<recob::Hit>>(
93  e,
94  GNNDescription->dataTag(), //tag of the hit collection we ran the GNN on
95  proxy::withParallelData<anab::FeatureVector<1>>(art::InputTag(nglabel, "filter")),
97 
98  std::cout << hitsWithScores.size() << std::endl;
99  for (auto& h : hitsWithScores) {
100  const auto& assocFilter = h.get<anab::FeatureVector<1>>();
101  const auto& assocSemantic = h.get<anab::FeatureVector<5>>();
102  _event = e.event();
103  _subrun = e.subRun();
104  _run = e.run();
105  _id = h.index();
106  _x_filter = assocFilter.at(0);
107  _MIP = assocSemantic.at(GNNDescription->getIndex("MIP"));
108  _HIP = assocSemantic.at(GNNDescription->getIndex("HIP"));
109  _shower = assocSemantic.at(GNNDescription->getIndex("shower"));
110  _michel = assocSemantic.at(GNNDescription->getIndex("michel"));
111  _diffuse = assocSemantic.at(GNNDescription->getIndex("diffuse"));
112  _wire = h->WireID().Wire;
113  _plane = h->WireID().Plane;
114  _tpc = h->WireID().TPC;
115  _cryo = h->WireID().Cryostat;
116  _time = h->PeakTime();
117  _treeHit->Fill();
118  }
119 
120  auto PredVertexColl = e.getHandle<std::vector<recob::Vertex>>(art::InputTag(nglabel, "vertex"));
121  if (PredVertexColl.isValid() && PredVertexColl->size() > 0) { //there should be only one
122  _vtx_x = PredVertexColl->at(0).position().X();
123  _vtx_y = PredVertexColl->at(0).position().Y();
124  _vtx_z = PredVertexColl->at(0).position().Z();
125  _treeEvt->Fill();
126  }
127 }
128 
NuGraphAnalyzer(fhicl::ParameterSet const &p)
Declaration of signal hit object.
Base utilities for the implementation of data product facades.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
auto withParallelData(Args &&...args)
Helper function to merge an auxiliary data product into the proxy.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void analyze(art::Event const &e) override
Handle< PROD > getHandle(SelectorBase const &) const
float at(size_t index) const
Definition: MVAOutput.h:94
NuGraphAnalyzer & operator=(NuGraphAnalyzer const &)=delete
Float_t e
Definition: plot.C:35
size_t size() const
Definition: MVAOutput.h:199