RecoStats_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 // Class: RecoStats
3 // Module Type: analyzer
4 // File: RecoStatistics_module.cc
5 // Author: D.Stefan and R.Sulej
6 //
7 // Various tests of the reco properties specific to ProtoDUNE SP. Started
8 // with reco charge per TPC, for the purpose of optimizing the decision
9 // on the locations of the instrumented TPC's.
10 //
11 //////////////////////////////////////////////////////////////////////////
12 
20 #include "art_root_io/TFileService.h"
21 
22 #include "canvas/Persistency/Common/FindManyP.h"
24 #include "fhiclcpp/types/Atom.h"
25 #include "fhiclcpp/types/Table.h"
26 
28 
36 
37 #include "TH2.h"
38 #include "TTree.h"
39 
40 namespace pdune
41 {
42  class RecoStats;
43 }
44 
46 public:
47 
48  struct Config {
49  using Name = fhicl::Name;
51 
53  Name("EmTrkModuleLabel"), Comment("tag of hits classifier")
54  };
55 
57  Name("CalorimetryAlg"), Comment("calo alg to calibrate hit adc to energy")
58  };
59  };
61 
62  explicit RecoStats(Parameters const& config);
63 
64  RecoStats(RecoStats const &) = delete;
65  RecoStats(RecoStats &&) = delete;
66  RecoStats & operator = (RecoStats const &) = delete;
67  RecoStats & operator = (RecoStats &&) = delete;
68 
69  void analyze(art::Event const & e) override;
70  void beginJob() override;
71  void endJob() override;
72 
73 private:
74  template <size_t N> bool fillChargeHistos(const art::Event & evt,
75  detinfo::DetectorClocksData const& clockData,
76  detinfo::DetectorPropertiesData const& detProp);
77  void fillChargeHisto(detinfo::DetectorClocksData const& clockData,
78  detinfo::DetectorPropertiesData const& detProp,
79  TH2F* histo, const std::vector<art::Ptr<recob::Hit>> & hits);
80  double getHitMeV(detinfo::DetectorClocksData const& clockData,
81  detinfo::DetectorPropertiesData const& detProp,
82  const recob::Hit & hit) const;
83  void ResetVars();
84 
86  std::unordered_map<int, std::pair<int, int>> mapTPCtoXY;
87 
91 
92  TTree *fTree;
93 
94  int fRun, fEvent;
95 
96  float fEkGen, fEkDep; // <- to be filled
97 
98  // ******** FHiCL parameters: ********
100 
102 };
103 
106  fCalorimetryAlg(config().CalorimetryAlg())
107 {
109  fElectronsToGeV = 1./larParameters->GeVToElectrons();
110 
111  mapTPCtoXY[0] = std::make_pair(-1, -1); // <- in case something falls into not active tpc
112  mapTPCtoXY[1] = std::make_pair(0, 1); // <- make 2D histo bins looking like in evd ortho
113  mapTPCtoXY[2] = std::make_pair(0, 0);
114  mapTPCtoXY[3] = std::make_pair(-1, -1);
115  mapTPCtoXY[4] = std::make_pair(-1, -1);
116  mapTPCtoXY[5] = std::make_pair(1, 1);
117  mapTPCtoXY[6] = std::make_pair(1, 0);
118  mapTPCtoXY[7] = std::make_pair(-1, -1);
119  mapTPCtoXY[8] = std::make_pair(-1, -1);
120  mapTPCtoXY[9] = std::make_pair(2, 1);
121  mapTPCtoXY[10] = std::make_pair(2, 0);
122  mapTPCtoXY[11] = std::make_pair(-1, -1);
123 }
124 
126 {
128 
129  fEmChargePerTpcHist = tfs->make<TH2F>("EmChargePerTPC", "EM charge reconstucted", 3, 0., 3., 2, 0., 2.);
130  fHadChargePerTpcHist = tfs->make<TH2F>("HadChargePerTPC", "hadronic charge reconstucted", 3, 0., 3., 2, 0., 2.);
131  fChargePerTpcHist = tfs->make<TH2F>("ChargePerTPC", "total charge reconstucted", 3, 0., 3., 2, 0., 2.);
132 
133  fTree = tfs->make<TTree>("events", "summary tree");
134  fTree->Branch("fRun", &fRun, "fRun/I");
135  fTree->Branch("fEvent", &fEvent, "fEvent/I");
136  fTree->Branch("fEkGen", &fEkGen, "fEkGen/F");
137  fTree->Branch("fEkDep", &fEkDep, "fEkDep/F");
138 }
139 
141 {
142 }
143 
144 template <size_t N>
146  detinfo::DetectorClocksData const& clockData,
147  detinfo::DetectorPropertiesData const& detProp)
148 {
149  float trackLikeThr = 0.63; // should move to fcl params
150  geo::View_t view = geo::kZ; // can move to fcl params
151 
153  if (!cluResults) { return false; }
154 
155  int trkLikeIdx = cluResults->getIndex("track");
156  int emLikeIdx = cluResults->getIndex("em");
157  if ((trkLikeIdx < 0) || (emLikeIdx < 0)) { return false; }
158 
159  const art::FindManyP< recob::Hit > hitsFromClusters(cluResults->dataHandle(), evt, cluResults->dataTag());
160  const auto & cnnOuts = cluResults->outputs();
161  const auto & clusters = cluResults->items();
162 
163  for (size_t i = 0; i < clusters.size(); ++i)
164  {
165  if (clusters[i].View() == view) { continue; } // take just one view
166 
167  double trackLike, trkOrEm = cnnOuts[i][trkLikeIdx] + cnnOuts[i][emLikeIdx];
168  if (trkOrEm > 0) { trackLike = cnnOuts[i][trkLikeIdx] / trkOrEm; }
169  else { trackLike = 0; }
170 
171  if (trackLike > trackLikeThr)
172  {
173  fillChargeHisto(clockData, detProp, fHadChargePerTpcHist, hitsFromClusters.at(i));
174  }
175  else
176  {
177  fillChargeHisto(clockData, detProp, fEmChargePerTpcHist, hitsFromClusters.at(i));
178  }
179  fillChargeHisto(clockData, detProp, fChargePerTpcHist, hitsFromClusters.at(i));
180  }
181  return true;
182 }
183 
185  detinfo::DetectorPropertiesData const& detProp,
186  TH2F* histo, const std::vector<art::Ptr<recob::Hit>> & hits)
187 {
188  for (const auto & h : hits)
189  {
190  auto xy = mapTPCtoXY[ h->WireID().TPC ];
191  histo->Fill(xy.first, xy.second, getHitMeV(clockData, detProp, *h));
192  }
193 }
194 
196  detinfo::DetectorPropertiesData const& detProp,
197  const recob::Hit & hit) const
198 {
199  double adc = hit.Integral();
200  if (!std::isnormal(adc) || (adc < 0)) adc = 0.0;
201 
202  unsigned short plane = hit.WireID().Plane;
203  double tdrift = hit.PeakTime();
204  double dqel = fCalorimetryAlg.ElectronsFromADCArea(adc, plane);
205 
206  double correllifetime = fCalorimetryAlg.LifetimeCorrection(clockData, detProp, tdrift, 0); // for the moment T0 = 0 (beam particles)
207  double dq = dqel * correllifetime * fElectronsToGeV * 1000;
208  if (!std::isnormal(dq) || (dq < 0)) dq = 0.0;
209 
210  return dq;
211 }
212 
214 {
215  ResetVars();
216 
217  fRun = evt.run();
218  fEvent = evt.id().event();
219 
220  // try to dig out 4- or 3-output MVA data product
221  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
222  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataFor(evt, clockData);
223  if (!fillChargeHistos<4>(evt, clockData, detProp) &&
224  !fillChargeHistos<3>(evt, clockData, detProp))
225  {
226  throw cet::exception("PMAlgTrackMaker") << "No EM/track MVA data products." << std::endl;
227  }
228 
229  fTree->Fill();
230 }
231 
233 {
234  fRun = 0;
235  fEvent = 0;
236  fEkGen = 0;
237  fEkDep = 0;
238 }
239 
Store parameters for running LArG4.
void beginJob() override
RecoStats & operator=(RecoStats const &)=delete
double getHitMeV(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const recob::Hit &hit) const
AdcChannelData::View View
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
geo::WireID WireID() const
Definition: Hit.h:233
struct vector vector
ChannelGroupService::Name Name
int16_t adc
Definition: CRTFragment.hh:202
Planes which measure Z direction.
Definition: geo_types.h:132
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
void analyze(art::Event const &e) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
double ElectronsFromADCArea(double area, unsigned short plane) const
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
bool fillChargeHistos(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp)
static Config * config
Definition: config.cpp:1054
RunNumber_t run() const
Definition: DataViewImpl.cc:71
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Detector simulation of raw signals on wires.
void endJob() override
fhicl::Table< calo::CalorimetryAlg::Config > CalorimetryAlg
fhicl::Atom< art::InputTag > EmTrkModuleLabel
void fillChargeHisto(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, TH2F *histo, const std::vector< art::Ptr< recob::Hit >> &hits)
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
Declaration of signal hit object.
#define Comment
Contains all timing reference information for the detector.
EventNumber_t event() const
Definition: EventID.h:116
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
calo::CalorimetryAlg fCalorimetryAlg
TCEvent evt
Definition: DataStructs.cxx:7
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
RecoStats(Parameters const &config)
std::unordered_map< int, std::pair< int, int > > mapTPCtoXY
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
EventID id() const
Definition: Event.cc:34
double GeVToElectrons() const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
art::InputTag fEmTrkModuleLabel