All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
32 #include "art/Framework/Core/EDAnalyzer.h"
33 #include "art/Framework/Core/ModuleMacros.h"
34 #include "canvas/Persistency/Common/FindManyP.h"
35 #include "art/Framework/Principal/Event.h"
36 #include "fhiclcpp/ParameterSet.h"
37 #include "art/Framework/Principal/Handle.h"
38 #include "canvas/Persistency/Common/Ptr.h"
39 #include "art/Framework/Services/Registry/ServiceHandle.h"
40 #include "messagefacility/MessageLogger/MessageLogger.h"
41 #include "cetlib/pow.h" // cet::sum_of_squares()
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 
57 
58 calo::CaloChecker::CaloChecker(fhicl::ParameterSet const& config):
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 
66 void calo::CaloChecker::analyze(const art::Event &evt) {
67  art::Handle< std::vector<recob::Track> > trackListHandle;
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 
262 DEFINE_ART_MODULE(calo::CaloChecker)
Functions to help with numbers.
CaloChecker(fhicl::ParameterSet const &config)
Declaration of signal hit object.
Class to keep data related to recob::Hit associated with recob::Track.
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other echo the stabs desc and the stab type Stabs symbols are echo used to hold debugging information For more echo see *Note or object file format specific echo echo For Mac OS X
void analyze(const art::Event &evt) override
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
process_name can override from command line with o or output calo
Definition: pid.fcl:40
T abs(T value)
std::vector< std::string > fCaloLabels
Provides recob::Track data product.
Encapsulate the geometry of a wire.
bool equal(double a, double b)
Comparison tolerance, in centimeters.
Encapsulate the construction of a single detector plane.
Interface for experiment-specific channel quality info provider.
do i e
TCEvent evt
Definition: DataStructs.cxx:8
Interface for experiment-specific service for channel quality info.
Collection of Physical constants used in LArSoft.
Utility functions to extract information from recob::Track
BEGIN_PROLOG could also be cout