LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CaloChecker_module.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <limits> // std::numeric_limits<>
3 #include <optional>
4 #include <string>
5 
9 
10 #include "larcorealg/CoreUtils/NumericUtils.h" // util::absDiff()
13 #include "lardata/ArtDataHelper/TrackUtils.h" // lar::util::TrackPitchInView()
21 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
22 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
23 
26 
27 // ROOT includes
28 #include <TF1.h>
29 #include <TGraph.h>
30 #include <TMath.h>
31 
39 #include "cetlib/pow.h" // cet::sum_of_squares()
40 #include "fhiclcpp/ParameterSet.h"
42 
43 namespace calo {
44 
45  class CaloChecker : public art::EDAnalyzer {
46  public:
47  explicit CaloChecker(fhicl::ParameterSet const& config);
48  void analyze(const art::Event& evt) override;
49 
50  private:
51  std::vector<std::string> fCaloLabels;
52  std::string fTrackLabel;
53  };
54 
55 } // end namespace calo
56 
58  : EDAnalyzer{config}
59  , fCaloLabels(config.get<std::vector<std::string>>("CaloLabels"))
60  , fTrackLabel(config.get<std::string>("TrackLabel"))
61 {
62  assert(fCaloLabels.size() >= 2);
63 }
64 
66 {
68  std::vector<art::Ptr<recob::Track>> tracklist;
69  if (evt.getByLabel(fTrackLabel, trackListHandle)) {
70  art::fill_ptr_vector(tracklist, trackListHandle);
71  }
72 
73  std::vector<art::FindManyP<anab::Calorimetry>> calos;
74  for (const std::string& l : fCaloLabels) {
75  calos.emplace_back(tracklist, evt, l);
76  }
77 
78  float EPS = 1e-3;
79 
80  for (unsigned trk_i = 0; trk_i < tracklist.size(); trk_i++) {
81  std::vector<art::Ptr<anab::Calorimetry>> base = calos[0].at(trk_i);
82 
83  std::cout << "New Track!\n";
84  std::cout << "Base calo (" << fCaloLabels[0] << ") n calo: " << base.size() << std::endl;
85  for (unsigned plane = 0; plane < base.size(); plane++) {
86  std::cout << "N points on plane (" << plane << ") ID (" << base[plane]->PlaneID()
87  << ") n points: " << base[plane]->dEdx().size() << std::endl;
88  }
89 
90  for (unsigned i = 1; i < fCaloLabels.size(); i++) {
91  bool equal = true;
92  std::vector<art::Ptr<anab::Calorimetry>> othr = calos[i].at(trk_i);
93  if (base.size() != othr.size()) {
94  equal = false;
95  std::cout << "Track: " << trk_i << " calo (" << fCaloLabels[0] << ") has (" << base.size()
96  << "). Calo (" << fCaloLabels[i] << ") has size (" << othr.size() << ") mismatch."
97  << std::endl;
98  }
99 
100  for (unsigned plane = 0; plane < base.size(); plane++) {
101  // check plane index
102  if (base[plane]->PlaneID() != othr[plane]->PlaneID()) {
103  equal = false;
104  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
105  << ") plane " << plane << ": ";
106  std::cout << "Plane ID mismatch (" << base[plane]->PlaneID() << ") ("
107  << othr[plane]->PlaneID() << ")" << std::endl;
108  }
109 
110  // check the range
111  if (abs(base[plane]->Range() - othr[plane]->Range()) > EPS) {
112  equal = false;
113  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
114  << ") plane " << plane << ": ";
115  std::cout << "Range mismatch (" << base[plane]->Range() << ") (" << othr[plane]->Range()
116  << ")" << std::endl;
117  }
118 
119  // check the kinetic energy
120  if (abs(base[plane]->KineticEnergy() - othr[plane]->KineticEnergy()) > EPS) {
121  equal = false;
122  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
123  << ") plane " << plane << ": ";
124  std::cout << "KineticEnergy mismatch (" << base[plane]->KineticEnergy() << ") ("
125  << othr[plane]->KineticEnergy() << ")" << std::endl;
126  }
127 
128  // check dE dx
129  const std::vector<float>& base_dedx = base[plane]->dEdx();
130  const std::vector<float>& othr_dedx = othr[plane]->dEdx();
131 
132  if (base_dedx.size() == othr_dedx.size()) {
133  for (unsigned i_dedx = 0; i_dedx < base_dedx.size(); i_dedx++) {
134  if (abs(base_dedx[i_dedx] - othr_dedx[i_dedx]) > EPS) {
135  equal = false;
136  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
137  << fCaloLabels[i] << ") plane " << plane << ": ";
138  std::cout << "dEdx mismatch at index: " << i_dedx << " (" << base_dedx[i_dedx]
139  << ") (" << othr_dedx[i_dedx] << ")" << std::endl;
140  }
141  }
142  }
143  else {
144  equal = false;
145  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
146  << ") plane " << plane << ": "
147  << "dEdx size mismatch (" << base_dedx.size() << ") (" << othr_dedx.size()
148  << ")" << std::endl;
149  }
150 
151  // check dQdx
152  const std::vector<float>& base_dqdx = base[plane]->dQdx();
153  const std::vector<float>& othr_dqdx = othr[plane]->dQdx();
154 
155  if (base_dqdx.size() == othr_dqdx.size()) {
156  for (unsigned i_dqdx = 0; i_dqdx < base_dqdx.size(); i_dqdx++) {
157  if (abs(base_dqdx[i_dqdx] - othr_dqdx[i_dqdx]) > EPS) {
158  equal = false;
159  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
160  << fCaloLabels[i] << ") plane " << plane << ": ";
161  std::cout << "dQdx mismatch at index: " << i_dqdx << " (" << base_dqdx[i_dqdx]
162  << ") (" << othr_dqdx[i_dqdx] << ")" << std::endl;
163  }
164  }
165  }
166  else {
167  equal = false;
168  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
169  << ") plane " << plane << ": "
170  << "dQdx size mismatch (" << base_dqdx.size() << ") (" << othr_dqdx.size()
171  << ")" << std::endl;
172  }
173 
174  // check Residual Range
175  const std::vector<float>& base_rr = base[plane]->ResidualRange();
176  const std::vector<float>& othr_rr = othr[plane]->ResidualRange();
177 
178  if (base_rr.size() == othr_rr.size()) {
179  for (unsigned i_rr = 0; i_rr < base_rr.size(); i_rr++) {
180  if (abs(base_rr[i_rr] - othr_rr[i_rr]) > EPS) {
181  equal = false;
182  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
183  << fCaloLabels[i] << ") plane " << plane << ": ";
184  std::cout << "ResidualRange mismatch at index: " << i_rr << " (" << base_rr[i_rr]
185  << ") (" << othr_rr[i_rr] << ")" << std::endl;
186  }
187  }
188  }
189  else {
190  equal = false;
191  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
192  << ") plane " << plane << ": "
193  << "ResidualRange size mismatch (" << base_rr.size() << ") (" << othr_rr.size()
194  << ")" << std::endl;
195  }
196 
197  // check DeadWireRC
198  const std::vector<float>& base_dwrr = base[plane]->DeadWireResRC();
199  const std::vector<float>& othr_dwrr = othr[plane]->DeadWireResRC();
200 
201  if (base_dwrr.size() == othr_dwrr.size()) {
202  for (unsigned i_dwrr = 0; i_dwrr < base_dwrr.size(); i_dwrr++) {
203  if (abs(base_dwrr[i_dwrr] - othr_dwrr[i_dwrr]) > EPS) {
204  equal = false;
205  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
206  << fCaloLabels[i] << ") plane " << plane << ": ";
207  std::cout << "DeadWireResRC mismatch at index: " << i_dwrr << " ("
208  << base_dwrr[i_dwrr] << ") (" << othr_dwrr[i_dwrr] << ")" << std::endl;
209  }
210  }
211  }
212  else {
213  equal = false;
214  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
215  << ") plane " << plane << ": "
216  << "DeadWireResRC size mismatch (" << base_dwrr.size() << ") ("
217  << othr_dwrr.size() << ")" << std::endl;
218  }
219 
220  // check Track Pitch
221  const std::vector<float>& base_tpv = base[plane]->TrkPitchVec();
222  const std::vector<float>& othr_tpv = othr[plane]->TrkPitchVec();
223 
224  if (base_tpv.size() == othr_tpv.size()) {
225  for (unsigned i_tpv = 0; i_tpv < base_tpv.size(); i_tpv++) {
226  if (abs(base_tpv[i_tpv] - othr_tpv[i_tpv]) > EPS) {
227  equal = false;
228  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
229  << fCaloLabels[i] << ") plane " << plane << ": ";
230  std::cout << "TrkPitchVec mismatch at index: " << i_tpv << " (" << base_tpv[i_tpv]
231  << ") (" << othr_tpv[i_tpv] << ")" << std::endl;
232  }
233  }
234  }
235  else {
236  equal = false;
237  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
238  << ") plane " << plane << ": "
239  << "TrkPitchVec size mismatch (" << base_tpv.size() << ") (" << othr_tpv.size()
240  << ")" << std::endl;
241  }
242 
243  // check TP Indices
244  const std::vector<size_t>& base_tpi = base[plane]->TpIndices();
245  const std::vector<size_t>& othr_tpi = othr[plane]->TpIndices();
246 
247  if (base_tpi.size() == othr_tpi.size()) {
248  for (unsigned i_tpi = 0; i_tpi < base_tpi.size(); i_tpi++) {
249  if (base_tpi[i_tpi] != othr_tpi[i_tpi]) {
250  equal = false;
251  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
252  << fCaloLabels[i] << ") plane " << plane << ": ";
253  std::cout << "TpIndices mismatch at index: " << i_tpi << " (" << base_tpi[i_tpi]
254  << ") (" << othr_tpi[i_tpi] << ")" << std::endl;
255  }
256  }
257  }
258  else {
259  equal = false;
260  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
261  << ") plane " << plane << ": "
262  << "TpIndices size mismatch (" << base_tpi.size() << ") (" << othr_tpi.size()
263  << ")" << std::endl;
264  }
265 
266  // check XYZ
267  const std::vector<geo::Point_t>& base_xyz = base[plane]->XYZ();
268  const std::vector<geo::Point_t>& othr_xyz = othr[plane]->XYZ();
269 
270  if (base_xyz.size() == othr_xyz.size()) {
271  for (unsigned i_xyz = 0; i_xyz < base_xyz.size(); i_xyz++) {
272  if (abs(base_xyz[i_xyz].X() - othr_xyz[i_xyz].X()) > EPS ||
273  abs(base_xyz[i_xyz].Y() - othr_xyz[i_xyz].Y()) > EPS ||
274  abs(base_xyz[i_xyz].Z() - othr_xyz[i_xyz].Z()) > EPS) {
275  equal = false;
276  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") ("
277  << fCaloLabels[i] << ") plane " << plane << ": ";
278  std::cout << "XYZ mismatch at index: " << i_xyz;
279  std::cout << "X (" << base_xyz[i_xyz].X() << ") (" << othr_xyz[i_xyz].X() << ") ";
280  std::cout << "Y (" << base_xyz[i_xyz].Y() << ") (" << othr_xyz[i_xyz].Y() << ") ";
281  std::cout << "Z (" << base_xyz[i_xyz].Z() << ") (" << othr_xyz[i_xyz].Z() << ") "
282  << std::endl;
283  }
284  }
285  }
286  else {
287  equal = false;
288  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i]
289  << ") plane " << plane << ": "
290  << "XYZ size mismatch (" << base_xyz.size() << ") (" << othr_xyz.size() << ")"
291  << std::endl;
292  }
293  }
294 
295  if (equal) {
296  std::cout << "Track: " << trk_i << " calo (" << fCaloLabels[0] << ") is equal to calo ("
297  << fCaloLabels[i] << ")" << std::endl;
298  }
299  }
300  }
301 }
302 
Functions to help with numbers.
CaloChecker(fhicl::ParameterSet const &config)
Declaration of signal hit object.
Float_t Y
Definition: plot.C:37
constexpr auto abs(T v)
Returns the absolute value of the argument.
Class to keep data related to recob::Hit associated with recob::Track.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
void analyze(const art::Event &evt) override
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
Float_t Z
Definition: plot.C:37
std::vector< std::string > fCaloLabels
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
Provides recob::Track data product.
Encapsulate the geometry of a wire.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Collection of Physical constants used in LArSoft.
Float_t e
Definition: plot.C:35
Float_t X
Definition: plot.C:37
Utility functions to extract information from recob::Track
calorimetry