Jpp  18.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMergeTimeOffsets.cc File Reference

Auxiliary program to merge the time offsets of two detector files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JModuleRouter.hh"
#include "JCalibrate/JTDC_t.hh"
#include "JLang/JObjectIO.hh"
#include "JSupport/JMeta.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 merge the time offsets of two detector files.

Author
acreusot, mdejong

Definition in file JMergeTimeOffsets.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JMergeTimeOffsets.cc.

24 {
25  using namespace std;
26  using namespace JPP;
27 
29 
30  pair_type detectorFile_a;
31  pair_type detectorFile_b;
32  string outputFile;
33  double precision;
34  int debug;
35 
36  try {
37 
38  JParser<> zap("Auxiliary program to merge the time offsets of two detector files."\
39  "\nThe TDC constraints correspond to those used in conjuction with the detector file.");
40 
41  zap['a'] = make_field(detectorFile_a, "<detector file> <TDC file>");
42  zap['b'] = make_field(detectorFile_b, "<detector file> <TDC file>");
43  zap['o'] = make_field(outputFile) = "";
44  zap['p'] = make_field(precision) = 1.0e-3;
45  zap['d'] = make_field(debug) = 1;
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53 
54  JDetector detector_a;
55  JDetector detector_b;
56 
57  try {
58  load(detectorFile_a.first, detector_a);
59  load(detectorFile_b.first, detector_b);
60  }
61  catch(const std::exception& error) {
62  FATAL(error.what());
63  }
64 
65  if (detector_a.getID() != detector_b.getID()) {
66  FATAL("Detector identifier " << detector_a.getID() << " != " << detector_b.getID() << endl);
67  }
68 
69  const JModuleRouter router(detector_b);
70 
71  for (JDetector::iterator module = detector_a.begin(); module != detector_a.end(); ++module) {
72 
73  if (!router.hasModule(module->getID())) {
74  FATAL("Missing module " << module->getID() << " in " << detectorFile_b.first << endl);
75  }
76 
77  for (size_t pmt = 0; pmt != module->size(); ++pmt) {
78 
79  if (detectorFile_a.second.has(module->getID(), pmt)) {
80 
81  if (detectorFile_b.second.has(module->getID(), pmt))
82  ASSERT(fabs((*module)[pmt].getT0() - router.getModule(module->getID())[pmt].getT0()) <= precision,
83  "PMT " << setw(10) << module->getID() << '.' << FILL(2,'0') << pmt << FILL() << " constraint.");
84  else
85  (*module)[pmt].setCalibration(router.getModule(module->getID())[pmt].getCalibration());
86  }
87  }
88  }
89 
90  NOTICE("Store calibration data on file " << outputFile << endl);
91 
92  detector_a.comment.add(JMeta(argc, argv));
93 
94  store(outputFile, detector_a);
95 }
Utility class to parse command line options.
Definition: JParser.hh:1514
JCombinatorics::pair_type pair_type
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
string outputFile
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level