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

Auxiliary program to decompose detector to separate calibrations. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "Jeep/JeepToolkit.hh"
#include "Jeep/JPrint.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 decompose detector to separate calibrations.

Author
mdejong

Definition in file JDestructDetector.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JDestructDetector.cc.

24 {
25  using namespace std;
26  using namespace JPP;
27 
28  string detectorFile;
29  string outputFile;
30  double precision;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Auxiliary program to decompose detector to separate calibrations.");
36 
37  zap['a'] = make_field(detectorFile, "detector file");
38  zap['o'] = make_field(outputFile, "detector calibrations file (json format)") = "";
39  zap['p'] = make_field(precision) = 1.0e-3;
40  zap['d'] = make_field(debug) = 1;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48 
50 
51  try {
52  load(detectorFile, detector);
53  }
54  catch(const JException& error) {
55  FATAL(error);
56  }
57 
58  if (!hasDetectorAddressMap(detector.getID())) {
59  FATAL("No detector address map for detector identier " << detector.getID() << endl);
60  }
61 
62  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
63 
64 
65  // Test compatibility of modules with reference(s).
66 
67  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
68 
69  JModule buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
70 
71  const JRotation3D R = getRotation(buffer, *module);
72 
73  buffer.rotate(R);
74 
75  if (!JModule::compare(buffer, *module, precision)) {
76  ERROR("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl);
77  }
78  }
79 
80 
81  JPMTCalibration calibration;
82  JModulePosition position;
83  JModuleRotation rotation;
84 
85  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
86 
87  const JModule& buffer = getModule(demo.get(module->getID()), module->getID(), module->getLocation());
88 
89  position.push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
90  rotation.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
91 
92  for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
93  calibration.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
94  }
95  }
96 
97 
98  json js;
99 
100  js[Result_t] = OK_t;
101 
102  js[Data_t][0][PMTT0s_t] = json(calibration);
103  js[Data_t][0][DOMPositions_t] = json(position);
104  js[Data_t][0][DOMRotations_t] = json(rotation);
105 
106  if (outputFile != "") {
107 
108  ostream* out = open<ostream>(outputFile.c_str());
109 
110  *out << setw(2) << setprecision(8);
111  *out << js;
112 
113  close(out);
114  }
115 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Data structure for a composite optical module.
Definition: JModule.hh:50
static const std::string DOMPositions_t
static const std::string OK_t
Detector data structure.
Definition: JDetector.hh:80
Rotation matrix.
Definition: JRotation3D.hh:111
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
Lookup table for PMT addresses in detector.
Data structure for PMT calibration.
string outputFile
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
Definition: JTransitTime.sh:36
static const std::string Result_t
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
void close(std::istream *pf)
Close file.
Definition: JeepToolkit.hh:346
static const std::string DOMRotations_t
int getID() const
Get identifier.
Definition: JObjectID.hh:55
#define ERROR(A)
Definition: JMessage.hh:66
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
void rotate(const JRotation3D &R)
Rotate module.
Definition: JModule.hh:242
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
#define FATAL(A)
Definition: JMessage.hh:67
nlohmann::json json
Auxiliary data structure for module rotation.
Auxiliary data structure for module position.
static const std::string PMTT0s_t
static const std::string Data_t
Auxiliary data structure for PMT time calibration.
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
JPosition3D getPosition(const Vec &v)
Get position.