Jpp  17.2.1-pre0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPlotPMTParameters.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 
10 #include "JDetector/JDetector.hh"
16 #include "JROOT/JManager.hh"
17 #include "JGizmo/JGizmoToolkit.hh"
18 
19 #include "Jeep/JPrint.hh"
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 namespace {
24 
26 
27  /**
28  * Get efficiency.
29  *
30  * \param parameters PMT parameters
31  * \return efficiency
32  */
33  inline double getEfficiency(const JPMTParameters& parameters)
34  {
35  return getSurvivalProbability(parameters) * parameters.QE;
36  }
37 
38  static const char* const EFFICIENCY = "EFFICIENCY";
39 }
40 
41 
42 /**
43  * \file
44  * Auxiliary application to plot PMT parameters.
45  * \author mdejong
46  */
47 
48 int main(int argc, char **argv)
49 {
50  using namespace std;
51  using namespace JPP;
52  using namespace KM3NETDAQ;
53 
54  string detectorFile;
56  string outputFile;
57  bool showPMTAddress;
58  int debug;
59 
60  try {
61 
62  JParser<> zap("Auxiliary application to plot PMT parameters.");
63 
64  zap['a'] = make_field(detectorFile, "detector file.");
65  zap['o'] = make_field(outputFile, "output file.") = "pmt_parameters.root";
66  zap['P'] = make_field(parameters, "PMT calibration data (or corresponding file name)");
67  zap['A'] = make_field(showPMTAddress, "show PMT address on y-axis");
68  zap['d'] = make_field(debug, "debug") = 0;
69 
70  zap(argc, argv);
71  }
72  catch(const exception &error) {
73  FATAL(error.what() << endl);
74  }
75 
77 
78  try {
79  load(detectorFile, detector);
80  }
81  catch(const JException& error) {
82  FATAL(error);
83  }
84 
85  if (detector.empty()) {
86  FATAL("Empty detector." << endl);
87  }
88 
89  JManager<string, TH1D> manager(new TH1D("%", NULL, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
90 
91  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
92 
93  DEBUG("Module " << setw(10) << module->getID() << endl);
94 
95  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
96 
97  const JProperties properties = parameters.getPMTParameters(JPMTIdentifier(module->getID(), pmt)).getProperties();
98 
99  for (JProperties::const_iterator p = properties.begin(); p != properties.end(); ++p) {
100 
101  double value = 0.0;
102 
103  try { value = (p->second.getValue<const double>()); } catch(const exception& error) {}
104  try { value = (p->second.getValue<const bool>() ? 1.0 : 0.0); } catch(const exception& error) {}
105 
106  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->SetBinContent(pmt + 1, value);
107  }
108 
109  double value = getEfficiency(parameters.getPMTParameters(JPMTIdentifier(module->getID(), pmt)));
110 
111  manager[MAKE_CSTRING(module->getID() << "." << EFFICIENCY)]->SetBinContent(pmt + 1, value);
112  }
113  }
114 
115  if (showPMTAddress) {
116 
117  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
118 
119  for (JManager<string, TH1D>::iterator i = manager.begin(); i != manager.end(); ++i) {
120 
121  int id;
122 
123  istringstream(i->first) >> id;
124 
125  setAxisLabels(*i->second, "X", demo.get(id));
126  }
127  }
128 
129  manager.Write(outputFile.c_str());
130 }
Utility class to parse command line options.
Definition: JParser.hh:1517
General exception.
Definition: JException.hh:23
int main(int argc, char *argv[])
Definition: Main.cc:15
Detector data structure.
Definition: JDetector.hh:89
Utility class to parse parameter values.
Definition: JProperties.hh:496
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
Lookup table for PMT addresses in detector.
Dynamic ROOT object management.
string outputFile
Data structure for detector geometry and calibration.
const JModuleAddressMap & get(const int id) const
Get module address map.
Detector specific mapping between logical positions and readout channels of PMTs in optical modules...
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:226
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
Set axis with PMT address labels.
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
Auxiliary class for map of PMT parameters.
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
Data structure for PMT parameters.
do set_variable DETECTOR_TXT $WORKDIR detector
KM3NeT DAQ constants, bit handling, etc.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
double QE
relative quantum efficiency
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62