CaloChecker_module.cc
Go to the documentation of this file.
1 #include <string>
2 #include <optional>
3 #include <cmath>
4 #include <limits> // std::numeric_limits<>
5 
9 
19 #include "lardata/ArtDataHelper/TrackUtils.h" // lar::util::TrackPitchInView()
22 #include "larcorealg/CoreUtils/NumericUtils.h" // util::absDiff()
23 
26 
27 // ROOT includes
28 #include <TMath.h>
29 #include <TGraph.h>
30 #include <TF1.h>
31 
34 #include "canvas/Persistency/Common/FindManyP.h"
36 #include "fhiclcpp/ParameterSet.h"
41 #include "cetlib/pow.h" // cet::sum_of_squares()
42 
43 namespace calo {
44 
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;
53 };
54 
55 } // end namespace calo
56 
57 
59  EDAnalyzer{config},
60  fCaloLabels(config.get<std::vector<std::string>>("CaloLabels")),
61  fTrackLabel(config.get<std::string>("TrackLabel"))
62 {
63  assert(fCaloLabels.size() >= 2);
64 }
65 
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() << ") n points: " << base[plane]->dEdx().size() << std::endl;
87  }
88 
89  for (unsigned i = 1; i < fCaloLabels.size(); i++) {
90  bool equal = true;
91  std::vector<art::Ptr<anab::Calorimetry>> othr = calos[i].at(trk_i);
92  if (base.size() != othr.size()) {
93  equal = false;
94  std::cout << "Track: " << trk_i << " calo (" << fCaloLabels[0] << ") has (" << base.size() << "). Calo (" << fCaloLabels[i] << ") has size (" << othr.size() << ") mismatch." << std::endl;
95  }
96 
97  for (unsigned plane = 0; plane < base.size(); plane++) {
98  // check plane index
99  if (base[plane]->PlaneID() != othr[plane]->PlaneID()) {
100  equal = false;
101  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
102  std::cout << "Plane ID mismatch (" << base[plane]->PlaneID() << ") (" << othr[plane]->PlaneID() << ")" << std::endl;
103  }
104 
105  // check the range
106  if (abs(base[plane]->Range() - othr[plane]->Range()) > EPS) {
107  equal = false;
108  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
109  std::cout << "Range mismatch (" << base[plane]->Range() << ") (" << othr[plane]->Range() << ")" << std::endl;
110  }
111 
112  // check the kinetic energy
113  if (abs(base[plane]->KineticEnergy() - othr[plane]->KineticEnergy()) > EPS) {
114  equal = false;
115  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
116  std::cout << "KineticEnergy mismatch (" << base[plane]->KineticEnergy() << ") (" << othr[plane]->KineticEnergy() << ")" << std::endl;
117  }
118 
119  // check dE dx
120  const std::vector<float> &base_dedx = base[plane]->dEdx();
121  const std::vector<float> &othr_dedx = othr[plane]->dEdx();
122 
123  if (base_dedx.size() == othr_dedx.size()) {
124  for (unsigned i_dedx = 0; i_dedx < base_dedx.size(); i_dedx++) {
125  if (abs(base_dedx[i_dedx] - othr_dedx[i_dedx]) > EPS) {
126  equal = false;
127  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
128  std::cout << "dEdx mismatch at index: " << i_dedx << " (" << base_dedx[i_dedx] << ") (" << othr_dedx[i_dedx] << ")" << std::endl;
129  }
130  }
131  }
132  else {
133  equal = false;
134  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "dEdx size mismatch (" << base_dedx.size() << ") (" << othr_dedx.size() << ")" << std::endl;
135  }
136 
137  // check dQdx
138  const std::vector<float> &base_dqdx = base[plane]->dQdx();
139  const std::vector<float> &othr_dqdx = othr[plane]->dQdx();
140 
141  if (base_dqdx.size() == othr_dqdx.size()) {
142  for (unsigned i_dqdx = 0; i_dqdx < base_dqdx.size(); i_dqdx++) {
143  if (abs(base_dqdx[i_dqdx] - othr_dqdx[i_dqdx]) > EPS) {
144  equal = false;
145  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
146  std::cout << "dQdx mismatch at index: " << i_dqdx << " (" << base_dqdx[i_dqdx] << ") (" << othr_dqdx[i_dqdx] << ")" << std::endl;
147  }
148  }
149  }
150  else {
151  equal = false;
152  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "dQdx size mismatch (" << base_dqdx.size() << ") (" << othr_dqdx.size() << ")" << std::endl;
153  }
154 
155  // check Residual Range
156  const std::vector<float> &base_rr = base[plane]->ResidualRange();
157  const std::vector<float> &othr_rr = othr[plane]->ResidualRange();
158 
159  if (base_rr.size() == othr_rr.size()) {
160  for (unsigned i_rr = 0; i_rr < base_rr.size(); i_rr++) {
161  if (abs(base_rr[i_rr] - othr_rr[i_rr]) > EPS) {
162  equal = false;
163  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
164  std::cout << "ResidualRange mismatch at index: " << i_rr << " (" << base_rr[i_rr] << ") (" << othr_rr[i_rr] << ")" << std::endl;
165  }
166  }
167  }
168  else {
169  equal = false;
170  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "ResidualRange size mismatch (" << base_rr.size() << ") (" << othr_rr.size() << ")" << std::endl;
171  }
172 
173  // check DeadWireRC
174  const std::vector<float> &base_dwrr = base[plane]->DeadWireResRC();
175  const std::vector<float> &othr_dwrr = othr[plane]->DeadWireResRC();
176 
177  if (base_dwrr.size() == othr_dwrr.size()) {
178  for (unsigned i_dwrr = 0; i_dwrr < base_dwrr.size(); i_dwrr++) {
179  if (abs(base_dwrr[i_dwrr] - othr_dwrr[i_dwrr]) > EPS) {
180  equal = false;
181  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
182  std::cout << "DeadWireResRC mismatch at index: " << i_dwrr << " (" << base_dwrr[i_dwrr] << ") (" << othr_dwrr[i_dwrr] << ")" << std::endl;
183  }
184  }
185  }
186  else {
187  equal = false;
188  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "DeadWireResRC size mismatch (" << base_dwrr.size() << ") (" << othr_dwrr.size() << ")" << std::endl;
189  }
190 
191  // check Track Pitch
192  const std::vector<float> &base_tpv = base[plane]->TrkPitchVec();
193  const std::vector<float> &othr_tpv = othr[plane]->TrkPitchVec();
194 
195  if (base_tpv.size() == othr_tpv.size()) {
196  for (unsigned i_tpv = 0; i_tpv < base_tpv.size(); i_tpv++) {
197  if (abs(base_tpv[i_tpv] - othr_tpv[i_tpv]) > EPS) {
198  equal = false;
199  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
200  std::cout << "TrkPitchVec mismatch at index: " << i_tpv << " (" << base_tpv[i_tpv] << ") (" << othr_tpv[i_tpv] << ")" << std::endl;
201  }
202  }
203  }
204  else {
205  equal = false;
206  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "TrkPitchVec size mismatch (" << base_tpv.size() << ") (" << othr_tpv.size() << ")" << std::endl;
207  }
208 
209  // check TP Indices
210  const std::vector<size_t> &base_tpi = base[plane]->TpIndices();
211  const std::vector<size_t> &othr_tpi = othr[plane]->TpIndices();
212 
213  if (base_tpi.size() == othr_tpi.size()) {
214  for (unsigned i_tpi = 0; i_tpi < base_tpi.size(); i_tpi++) {
215  if (base_tpi[i_tpi] != othr_tpi[i_tpi]) {
216  equal = false;
217  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
218  std::cout << "TpIndices mismatch at index: " << i_tpi << " (" << base_tpi[i_tpi] << ") (" << othr_tpi[i_tpi] << ")" << std::endl;
219  }
220  }
221  }
222  else {
223  equal = false;
224  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "TpIndices size mismatch (" << base_tpi.size() << ") (" << othr_tpi.size() << ")" << std::endl;
225  }
226 
227  // check XYZ
228  const std::vector<geo::Point_t> &base_xyz = base[plane]->XYZ();
229  const std::vector<geo::Point_t> &othr_xyz = othr[plane]->XYZ();
230 
231  if (base_xyz.size() == othr_xyz.size()) {
232  for (unsigned i_xyz = 0; i_xyz < base_xyz.size(); i_xyz++) {
233  if (abs(base_xyz[i_xyz].X() - othr_xyz[i_xyz].X()) > EPS ||
234  abs(base_xyz[i_xyz].Y() - othr_xyz[i_xyz].Y()) > EPS ||
235  abs(base_xyz[i_xyz].Z() - othr_xyz[i_xyz].Z()) > EPS) {
236  equal = false;
237  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": ";
238  std::cout << "XYZ mismatch at index: " << i_xyz;
239  std::cout << "X (" << base_xyz[i_xyz].X() << ") (" << othr_xyz[i_xyz].X() << ") ";
240  std::cout << "Y (" << base_xyz[i_xyz].Y() << ") (" << othr_xyz[i_xyz].Y() << ") ";
241  std::cout << "Z (" << base_xyz[i_xyz].Z() << ") (" << othr_xyz[i_xyz].Z() << ") " << std::endl;
242  }
243  }
244  }
245  else {
246  equal = false;
247  std::cout << "Track: " << trk_i << " calos (" << fCaloLabels[0] << ") (" << fCaloLabels[i] << ") plane " << plane << ": " << "XYZ size mismatch (" << base_xyz.size() << ") (" << othr_xyz.size() << ")" << std::endl;
248  }
249 
250  }
251 
252  if (equal) {
253  std::cout << "Track: " << trk_i << " calo (" << fCaloLabels[0] << ") is equal to calo (" << fCaloLabels[i] << ")" << std::endl;
254  }
255 
256  }
257  }
258 
259 
260 }
261 
Functions to help with numbers.
CaloChecker(fhicl::ParameterSet const &config)
std::string string
Definition: nybbler.cc:12
Class to keep data related to recob::Hit associated with recob::Track.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
static QStrList * l
Definition: config.cpp:1044
void analyze(const art::Event &evt) override
T abs(T value)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
std::vector< std::string > fCaloLabels
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
Encapsulate the geometry of a wire.
Declaration of signal hit object.
Encapsulate the construction of a single detector plane.
Provides recob::Track data product.
Interface for experiment-specific channel quality info provider.
detail::Node< FrameID, bool > PlaneID
Definition: CRTID.h:125
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
Interface for experiment-specific service for channel quality info.
Collection of Physical constants used in LArSoft.
Utility functions to extract information from recob::Track
calorimetry
QTextStream & endl(QTextStream &s)