Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JCompareDetector.cc File Reference

Auxiliary program to find differences between two detector files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "JTools/JRange.hh"
#include "JTools/JConstants.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to find differences between two detector files.

Author
mjongen

Definition in file JCompareDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file JCompareDetector.cc.

50 {
51  using namespace std;
52 
53  string detectorFile_a;
54  string detectorFile_b;
55  string outputFile;
56  double precision;
57  int debug;
58 
59  try {
60 
61  JParser<> zap("Auxiliary program to find differences between two detector files.");
62 
63  zap['a'] = make_field(detectorFile_a);
64  zap['b'] = make_field(detectorFile_b);
65  zap['o'] = make_field(outputFile) = "";
66  zap['p'] = make_field(precision) = 0.001; // [ns,m]
67  zap['d'] = make_field(debug) = 3;
68 
69  zap(argc, argv);
70  }
71  catch(const exception &error) {
72  FATAL(error.what() << endl);
73  }
74 
75  using namespace JPP;
76 
77  JDetector detector_a;
78  JDetector detector_b;
79 
80  try {
81  load(detectorFile_a, detector_a);
82  }
83  catch(const JException& error) {
84  FATAL(error);
85  }
86 
87  try {
88  load(detectorFile_b, detector_b);
89  }
90  catch(const JException& error) {
91  FATAL(error);
92  }
93 
94 
95  bool is_equal = true;
96 
97  const JModuleRouter module_router_a(detector_a);
98  const JModuleRouter module_router_b(detector_b);
99 
100 
101  // compare detector IDs
102 
103  if (detector_a.getID() != detector_b.getID()) {
104 
105  DEBUG("* Unequal detector IDs = "
106  << detector_a.getID() << " (A) and " << endl
107  << detector_b.getID() << " (B)." << endl
108  << endl);
109 
110  is_equal = false;
111  }
112 
113 
114  // check whether the same modules are present in the file
115 
116  for (JDetector::iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
117 
118  if (!module_router_b.hasModule(module->getID())) {
119 
120  DEBUG("* Module " << module->getID() << " is in A (" << module->getString() << "," << module->getFloor() << ") but not in B" << endl);
121 
122  is_equal = false;
123  }
124  }
125 
126  for (JDetector::iterator module = detector_b.begin(); module != detector_b.end(); ++module) {
127 
128  if (!module_router_a.hasModule(module->getID())) {
129 
130  DEBUG("* Module " << module->getID() << " is in B (" << module->getString() << "," << module->getFloor() << ") but not in A" << endl);
131 
132  is_equal = false;
133  }
134  }
135  DEBUG(endl);
136 
137 
138  // compare the modules that the files have in common
139 
140  DEBUG("Comparing module by module." << endl);
141 
142  for (JDetector::iterator module_a = detector_a.begin(); module_a != detector_a.end(); ++module_a) {
143 
144  if (!module_router_b.hasModule(module_a->getID())) {
145 
146  continue;
147 
148  is_equal = false;
149  }
150 
151  const JModule* module_b = &module_router_b.getModule(module_a->getID());
152 
153  DEBUG(" Module " << module_a->getID());
154 
155  // string and floor numbers
156 
157  if (module_a->getLocation() == module_b->getLocation()) {
158 
159  DEBUG(" (" << module_a->getString() << "," << module_a->getFloor() << ")" << endl);
160 
161  } else {
162 
163  DEBUG(endl);
164  DEBUG(" * different location: "
165  << "(" << module_a->getString() << "," << module_a->getFloor() << ") (A), "
166  << "(" << module_b->getString() << "," << module_b->getFloor() << ") (B)" << endl);
167 
168  is_equal = false;
169  }
170 
171  // average DOM positions
172 
173  if (module_a->getPosition().getDistance(module_b->getPosition()) > precision) {
174 
175  DEBUG(" * different position: "
176  << module_a->getPosition() << " (A), "
177  << module_b->getPosition() << " (B)"
178  << ", diff = " << JPosition3D(module_b->getPosition()-module_a->getPosition()) << endl);
179 
180  is_equal = false;
181  }
182 
183  // number of PMTs
184 
185  if (module_a->size() != module_b->size()) {
186 
187  DEBUG(" * different number of PMTs: "
188  << module_a->size() << " (A), "
189  << module_b->size() << " (B)" << endl);
190 
191  is_equal = false;
192  }
193 
194  // average T0
195 
196  const double T0A = getT0(*module_a);
197  const double T0B = getT0(*module_b);
198 
199  if (fabs(T0A-T0B) > precision) {
200 
201  DEBUG(" * different average T0: "
202  << T0A << " (A), " << T0B << " (B)"
203  << ", B - A = " << T0B - T0A
204  << endl);
205 
206  is_equal = false;
207  }
208 
209  // comparing by PMT
210 
211  // T0
212 
213  for (unsigned int pmt = 0; pmt != module_a->size() && pmt != module_b->size(); ++pmt) {
214 
215  const JPMT& pmt_a = module_a->getPMT(pmt);
216  const JPMT& pmt_b = module_b->getPMT(pmt);
217 
218  if (fabs(pmt_a.getT0() - pmt_b.getT0()) > precision) {
219 
220  DEBUG(" * different T0 PMT " << pmt << ": "
221  << pmt_a.getT0() << " (A), "
222  << pmt_b.getT0() << " (B)"
223  << ", B - A = " << pmt_b.getT0() - pmt_a.getT0()
224  << endl);
225 
226  is_equal = false;
227  }
228  }
229 
230  // positions
231 
232  for (unsigned int pmt = 0; pmt != module_a->size() && pmt != module_b->size(); ++pmt) {
233 
234  const JPMT& pmt_a = module_a->getPMT(pmt);
235  const JPMT& pmt_b = module_b->getPMT(pmt);
236 
237  // PMT positions
238 
239  if (pmt_a.getPosition().getDistance(pmt_b.getPosition()) > precision) {
240 
241  DEBUG(" * different PMT position: "
242  << pmt_a.getPosition() << " (A" << pmt << "), "
243  << pmt_b.getPosition() << " (B" << pmt << ")"
244  << ", diff = " << JPosition3D(pmt_b.getPosition()-pmt_a.getPosition()) << endl);
245 
246  is_equal = false;
247  }
248  }
249 
250  // status
251 
252  for (unsigned int pmt = 0; pmt != module_a->size() && pmt != module_b->size(); ++pmt) {
253 
254  const JPMT& pmt_a = module_a->getPMT(pmt);
255  const JPMT& pmt_b = module_b->getPMT(pmt);
256 
257  if (pmt_a.getStatus() != pmt_b.getStatus()) {
258 
259  DEBUG(" * different status PMT " << pmt << ": "
260  << pmt_a.getStatus() << " (A), "
261  << pmt_b.getStatus() << " (B)"
262  << endl);
263 
264  is_equal = false;
265  }
266  }
267  }
268  DEBUG(endl);
269 
270 
271  if (outputFile != "") {
272 
273  typedef JRange<int> JRange_t;
274 
275  const JRange_t string = combine(JRange_t(detector_a.begin(), detector_a.end(), &JModule::getString),
276  JRange_t(detector_b.begin(), detector_b.end(), &JModule::getString));
277  const JRange_t floor = combine(JRange_t(detector_a.begin(), detector_a.end(), &JModule::getFloor),
278  JRange_t(detector_b.begin(), detector_b.end(), &JModule::getFloor));
279 
280  TFile out(outputFile.c_str(), "recreate");
281 
282  TH2D M2("M2", NULL,
283  string.getLength() + 1,
284  string.getLowerLimit() - 0.5,
285  string.getUpperLimit() + 0.5,
286  floor.getLength() + 1,
287  floor.getLowerLimit() - 0.5,
288  floor.getUpperLimit() + 0.5);
289 
290  TH2D* X2 = (TH2D*) M2.Clone("X2");
291  TH2D* Y2 = (TH2D*) M2.Clone("Y2");
292  TH2D* Z2 = (TH2D*) M2.Clone("Z2");
293  TH2D* T2 = (TH2D*) M2.Clone("T2");
294 
295  for( JDetector::iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
296  if( !module_router_b.hasModule(module->getID()) ) {
297  M2.Fill(module->getString(), module->getFloor(), -1.0);
298  }
299  }
300 
301  for( JDetector::iterator module = detector_b.begin(); module != detector_b.end(); ++module) {
302  if( !module_router_a.hasModule(module->getID()) ) {
303  M2.Fill(module->getString(), module->getFloor(), +1.0);
304  }
305  }
306 
307  for( JDetector::iterator module_a = detector_a.begin(); module_a != detector_a.end(); ++module_a) {
308 
309  if (!module_router_b.hasModule(module_a->getID())) {
310  continue;
311  }
312 
313  const JModule* module_b = &module_router_b.getModule(module_a->getID());
314 
315  X2->Fill(module_a->getString(), module_a->getFloor(), module_a->getX() - module_b->getX());
316  Y2->Fill(module_a->getString(), module_a->getFloor(), module_a->getY() - module_b->getY());
317  Z2->Fill(module_a->getString(), module_a->getFloor(), module_a->getZ() - module_b->getZ());
318  T2->Fill(module_a->getString(), module_a->getFloor(), getT0(*module_a) - getT0(*module_b));
319  }
320 
321  TH1D *hb = new TH1D("deltaPhiPmts", NULL, 90, -180.0, 180.0);
322 
323  for (JDetector::iterator module_a = detector_a.begin(); module_a != detector_a.end(); ++module_a) {
324 
325  if (!module_router_b.hasModule(module_a->getID())) {
326  continue;
327  }
328 
329  const JModule* module_b = &module_router_b.getModule(module_a->getID());
330 
331  for (unsigned int pmt = 0; pmt != module_a->size() && pmt != module_b->size(); ++pmt) {
332 
333  const JPMT& pmt_a = module_a->getPMT(pmt);
334  const JPMT& pmt_b = module_b->getPMT(pmt);
335 
336  hb->Fill((pmt_a.getPhi() - pmt_b.getPhi()) * 180.0/PI);
337  }
338  }
339 
340  out.Write();
341  out.Close();
342  }
343 
344  ASSERT(is_equal);
345 
346  return 0;
347 }
Utility class to parse command line options.
Definition: JParser.hh:1410
static const double PI
Constants.
Definition: JConstants.hh:20
string outputFile
#define ASSERT(A)
Assert macro.
Definition: JMessage.hh:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:59
JRange< T, JComparator_t > combine(const JRange< T, JComparator_t > &first, const JRange< T, JComparator_t > &second)
Combine ranges.
Definition: JRange.hh:590
#define FATAL(A)
Definition: JMessage.hh:65
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60