Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JPlotDetectorParameters2D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 
6 #include "TROOT.h"
7 #include "TFile.h"
8 #include "TH2D.h"
9 
11 #include "JDetector/JDetector.hh"
14 #include "JROOT/JManager.hh"
15 #include "JGizmo/JGizmoToolkit.hh"
16 #include "JROOT/JRootToolkit.hh"
17 
18 #include "Jeep/JPrint.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 /**
24  * \file
25  * Auxiliary application to plot detector parameters.
26  *
27  * \author mdejong, rgruiz
28  */
29 
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34  using namespace KM3NETDAQ;
35 
36  vector<string> detectorFileA;
37  vector<string> detectorFileB;
38  string outputFile;
39  string regexp;
40  int labelInterval;
41  int debug;
42 
43  try {
44 
45  JParser<> zap("Auxiliary application to plot detector parameters.");
46 
47  zap['a'] = make_field(detectorFileA, "detector file.");
48  zap['b'] = make_field(detectorFileB, "detector file.") = JPARSER::initialised();
49  zap['o'] = make_field(outputFile, "output file.") = "detector_parameters.root";
50  zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis") = " ";
51  zap['L'] = make_field(labelInterval, "interval between x-axis bins for which labels are shown") = 1;
52  zap['d'] = make_field(debug, "debug") = 2;
53 
54  zap(argc, argv);
55  }
56  catch(const exception &error) {
57  FATAL(error.what() << endl);
58  }
59 
60 
61  if (detectorFileA.empty()) {
62  FATAL("No detector file specified." << endl);
63  }
64 
65  if (detectorFileB.size() != 0 && detectorFileB.size() != detectorFileA.size()) {
66  FATAL("Detector file size " << detectorFileA.size() << " != " << detectorFileB.size() << endl);
67  }
68 
69 
70  const int NUMBER_OF_FILES = detectorFileA.size();
71 
72  JManager<string, TH2D> manager(new TH2D("%", NULL,
73  NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5,
74  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
75 
76  manager->Sumw2(kFALSE);
77 
78  if (regexp != " "){
79 
80  const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval;
81 
82  const TPRegexp buffer(regexp);
83 
84  for (int i = 0; i != NUMBER_OF_FILES; ++i){
85 
86  if(i%n == 0)
87  manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(detectorFileA[i].c_str())));
88  else
89  manager->GetXaxis()->SetBinLabel(i+1 , " ");
90  }
91  }
92 
93 
94  if (detectorFileB.empty()) {
95 
97 
98  try {
99  load(detectorFileA[0], detector);
100  }
101  catch(const JException& error) {
102  FATAL(error);
103  }
104 
105  if (detector.empty()) {
106  FATAL("Empty detector." << endl);
107  }
108 
109 
110  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
111 
112  NOTICE("Histogram " << detectorFileA[i] << " relative to " << detectorFileA[0] << endl);
113 
114  JDetector buffer;
115 
116  try {
117  load(detectorFileA[i], buffer);
118  }
119  catch(const JException& error) {
120  FATAL(error);
121  }
122 
123  JModuleRouter router(buffer);
124 
125  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
126 
127  TH2D* h2 = manager[MAKE_CSTRING(module->getID() << "." << "t0")];
128 
129  for (size_t pmt = 0; pmt != module->size(); ++pmt) {
130  h2->SetBinContent(i+1, pmt+1, router.getModule(module->getID()).getPMT(pmt).getT0() - module->getPMT(pmt).getT0());
131  }
132  }
133  }
134 
135  } else {
136 
137  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
138 
139  NOTICE("Histogram " << detectorFileA[i] << " relative to " << detectorFileB[i] << endl);
140 
141  JDetector detectorA;
142  JDetector detectorB;
143 
144  try {
145  load(detectorFileA[i], detectorA);
146  load(detectorFileB[i], detectorB);
147  }
148  catch(const JException& error) {
149  FATAL(error);
150  }
151 
152  JModuleRouter router(detectorB);
153 
154  for (JDetector::iterator module = detectorA.begin(); module != detectorA.end(); ++module) {
155 
156  TH2D* h2 = manager[MAKE_CSTRING(module->getID() << "." << "t0")];
157 
158  for (size_t pmt = 0; pmt != module->size(); ++pmt) {
159  h2->SetBinContent(i+1, pmt+1, router.getModule(module->getID()).getPMT(pmt).getT0() - module->getPMT(pmt).getT0());
160  }
161  }
162  }
163  }
164 
165 
166  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
167  i->second->Sumw2(kFALSE);
168  }
169 
170  manager.Write(outputFile.c_str());
171 }
string outputFile
KM3NeT DAQ constants, bit handling, etc.
Data structure for detector geometry and calibration.
Dynamic ROOT object management.
General purpose messaging.
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Direct access to module in detector data structure.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
int main(int argc, char **argv)
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:72
double getT0() const
Get time offset.
Detector data structure.
Definition: JDetector.hh:96
Router for direct addressing of module data in detector data structure.
const JModule & getModule(const JObjectID &id) const
Get module parameters.
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:172
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1698
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:304
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const int n
Definition: JPolint.hh:786
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
boost::property_tree::ptree parse(std::string str)
Definition: configure.hh:24
Definition: JSTDTypes.hh:14
Detector file.
Definition: JHead.hh:227
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68