RecoHitsEff_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 // Class: RecoHitsEff
3 // Module Type: analyzer
4 // File: RecoHitsEff_module.cc
5 // Author: D.Stefan and R.Sulej
6 //
7 // Check of hit efficiency reconstruction.
8 // It helps to tests various disambiguation algorithms.
9 //
10 //////////////////////////////////////////////////////////////////////////
11 
19 #include "art_root_io/TFileService.h"
20 
22 #include "fhiclcpp/types/Atom.h"
23 #include "fhiclcpp/types/Table.h"
24 
26 
32 
33 #include "TTree.h"
34 
35 namespace pdune
36 {
37  class RecoHitsEff;
38 }
39 
41 public:
42 
43  struct Config {
44  using Name = fhicl::Name;
46 
48  Name("HitModuleLabel"), Comment("tag of hits producer")
49  };
50 
52  Name("HitDCheatLabel"), Comment("tag of dcheat hits producer")
53  };
54 
56  Name("Plane"), Comment("check hit disambiguation in selected plane only")
57  };
58  };
60 
61  explicit RecoHitsEff(Parameters const& config);
62 
63  RecoHitsEff(RecoHitsEff const &) = delete;
64  RecoHitsEff(RecoHitsEff &&) = delete;
65  RecoHitsEff & operator = (RecoHitsEff const &) = delete;
66  RecoHitsEff & operator = (RecoHitsEff &&) = delete;
67 
68  void analyze(art::Event const & e) override;
69  void beginJob() override;
70 
71 private:
72 
73  void ResetVars();
74 
75  TTree *fTree;
76 
77  int fRun, fEvent;
78  int fNhits; int fNdcheat;
79  int fMatching;
80 
83  int fPlane;
84 };
85 
87  fHitModuleLabel(config().HitModuleLabel()),
88  fHitDCheatLabel(config().HitDCheatLabel()),
89  fPlane(config().Plane())
90 {
91 }
92 
94 {
96 
97  fTree = tfs->make<TTree>("events", "summary tree");
98  fTree->Branch("fRun", &fRun, "fRun/I");
99  fTree->Branch("fEvent", &fEvent, "fEvent/I");
100  fTree->Branch("fPlane", &fPlane, "fPlane/I");
101  fTree->Branch("fNhits", &fNhits, "fNhits/I");
102  fTree->Branch("fNdcheat", &fNdcheat, "fNdcheat/I");
103  fTree->Branch("fMatching", &fMatching, "fMatching/I");
104 }
105 
107 {
108  ResetVars();
109 
110  fRun = evt.run();
111  fEvent = evt.id().event();
112 
113  auto const & hitList = *evt.getValidHandle< std::vector<recob::Hit> >(fHitModuleLabel);
114 
115  std::vector< size_t > hits;
116  // get and sort hits
117  int plane = 0;
118  for (size_t k = 0; k < hitList.size(); ++k)
119  {
120  plane = hitList[k].WireID().Plane;
121  if (plane != fPlane) continue;
122  fNhits++;
123 
124  hits.push_back(k);
125  }
126 
127  auto const & dcheatList = *evt.getValidHandle< std::vector<recob::Hit> >(fHitDCheatLabel);
128 
129  std::vector< size_t > hitsdc;
130  // get and short hits_dc
131  for (size_t k = 0; k < dcheatList.size(); ++k)
132  {
133  plane = dcheatList[k].WireID().Plane;
134  if (plane != fPlane) continue;
135  fNdcheat++;
136 
137  hitsdc.push_back(k);
138  }
139 
140  std::cout << " fNhits " << fNhits << std::endl;
141  std::cout << " fNdcheat " << fNdcheat << std::endl;
142 
143  for (auto const h: hits)
144  {
145  for (auto const hdc: hitsdc)
146  {
147  if ((hitList[h].PeakTime() == dcheatList[hdc].PeakTime()) && (hitList[h].WireID() == dcheatList[hdc].WireID()))
148  {
149  fMatching++;
150  }
151  }
152  }
153 
154  std::cout << " fMatching " << fMatching << std::endl;
155 
156  fTree->Fill();
157 }
158 
160 {
161  fRun = 0;
162  fEvent = 0;
163  fNhits = 0;
164  fNdcheat = 0;
165  fMatching = 0;
166 }
167 
Store parameters for running LArG4.
void beginJob() override
fhicl::Atom< art::InputTag > HitDCheatLabel
RecoHitsEff & operator=(RecoHitsEff const &)=delete
ChannelGroupService::Name Name
void analyze(art::Event const &e) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art::InputTag fHitModuleLabel
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
static Config * config
Definition: config.cpp:1054
art::InputTag fHitDCheatLabel
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
fhicl::Atom< art::InputTag > HitModuleLabel
RunNumber_t run() const
Definition: DataViewImpl.cc:71
Declaration of signal hit object.
RecoHitsEff(Parameters const &config)
#define Comment
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
EventID id() const
Definition: Event.cc:34
QTextStream & endl(QTextStream &s)