Jpp
JPlotPMTParameters2D.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"
17 #include "JGizmo/JManager.hh"
18 #include "JGizmo/JGizmoToolkit.hh"
19 #include "JROOT/JRootToolkit.hh"
20 
21 #include "Jeep/JPrint.hh"
22 #include "Jeep/JParser.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  * Auxiliary application to plot PMT parameters.
29  * \author mdejong
30  */
31 
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36  using namespace KM3NETDAQ;
37 
38  string detectorFile;
39  vector<string> inputFile;
40  string outputFile;
41  string regexp;
42  int labelInterval;
43  bool showPMTAddress;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Auxiliary application to plot PMT parameters.");
49 
50  zap['a'] = make_field(detectorFile, "detector file." );
51  zap['o'] = make_field(outputFile, "output file." ) = "pmt_parameters.root";
52  zap['P'] = make_field(inputFile, "PMT calibration data file" );
53  zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis" ) = " ";
54  zap['d'] = make_field(debug, "debug" ) = 0;
55  zap['A'] = make_field(showPMTAddress, "show PMT address on Y axis" );
56  zap['L'] = make_field(labelInterval, "Interval between x-axis bins for which labels are shown") = 1;
57 
58  zap(argc, argv);
59  }
60  catch(const exception &error) {
61  FATAL(error.what() << endl);
62  }
63 
65 
66  try {
67  load(detectorFile, detector);
68  }
69  catch(const JException& error) {
70  FATAL(error);
71  }
72 
73  if (detector.empty()) {
74  FATAL("Empty detector." << endl);
75  }
76  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
77 
78  vector<JPMTParametersMap> parameters;
79 
80  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
81  parameters.push_back(JPMTParametersMap(i->c_str()));
82  }
83 
84 
85  const int NUMBER_OF_FILES = parameters.size();
86 
87  JManager<string, TH2D> manager(new TH2D("%", NULL,
88  NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5,
89  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
90 
91  if (regexp != " "){
92 
93  int n = (NUMBER_OF_FILES < labelInterval)? 1 : labelInterval;
94  TPRegexp pregexp (regexp);
95 
96  for (int i=0 ; i != NUMBER_OF_FILES ; ++i){
97  if(i%n==0)
98  manager->GetXaxis()->SetBinLabel(i+1 , parse(pregexp , TString(inputFile[i].c_str())));
99  else
100  manager->GetXaxis()->SetBinLabel(i+1 , " ");
101  }
102  }
103 
104  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
105 
106  DEBUG("Module " << setw(10) << module->getID() << endl);
107 
108  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
109 
110  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
111 
112  const JProperties properties = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt)).getProperties();
113 
114  for (JProperties::const_iterator p = properties.begin(); p != properties.end(); ++p) {
115 
116  try {
117  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->Fill((Double_t) i, (Double_t) pmt, p->second.getValue<const double>());
118  }
119  catch(const exception& error) {}
120 
121  try {
122  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->Fill((Double_t) i, (Double_t) pmt, p->second.getValue<const bool>() ? 1.0 : 0.0);
123  }
124  catch(const exception& error) {}
125  }
126 
127  const JPMTParameters buffer = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt));
128 
129  manager[MAKE_CSTRING(module->getID() << "." << "EFFICIENCY")]->Fill((Double_t) i, (Double_t) pmt, getSurvivalProbability(buffer) * buffer.QE);
130  }
131  }
132  }
133 
134  if (showPMTAddress){
135 
136  TPRegexp r ("(\\d{8}).");
137 
138  for (JManager<string, TH2D>::iterator it = manager.begin(); it != manager.end(); ++it) {
139  TString id = parse(r , TString(it->second->GetName()));
140  JModuleAddressMap memo = demo.get(id.IsDigit() ? id.Atoi() : -1);
141  setAxisLabels(it->second->GetYaxis(), memo);
142  }
143  }
144 
145  manager.Write(outputFile.c_str());
146 }
JPMTParametersMap.hh
JDAQ.hh
JManager::Write
void Write(TFile &out)
Write histograms to file.
Definition: JHistogramToolkit.hh:227
JManager< string, TH2D >
JMessage.hh
main
int main(int argc, char **argv)
Definition: JPlotPMTParameters2D.cc:32
JPrint.hh
JDETECTOR::getSurvivalProbability
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
Definition: JPMTParametersToolkit.hh:32
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
JDetectorAddressMap.hh
JTOOLS::n
const int n
Definition: JPolint.hh:628
std::vector
Definition: JSTDTypes.hh:12
KM3NETDAQ::NUMBER_OF_PMTS
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JGIZMO::JManager
Auxiliary class to manage set of compatible ROOT objects (e.g.
Definition: JManager.hh:40
JGizmoToolkit.hh
JDETECTOR::JModuleAddressMap
Lookup table for PMT addresses in optical module.
Definition: JModuleAddressMap.hh:82
JManager.hh
JDETECTOR::JPMTParameters::getPMTParameters
const JPMTParameters & getPMTParameters() const
Get PMT parameters.
Definition: JPMTParameters.hh:95
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
MAKE_CSTRING
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:708
detail::parse
boost::property_tree::ptree parse(std::string str)
Definition: configure.hh:24
debug
int debug
debug level
Definition: JSirene.cc:59
JDetectorAddressMapToolkit.hh
JDETECTOR::JPMTParametersMap
Auxiliary class for map of PMT parameters.
Definition: JPMTParametersMap.hh:88
JRootToolkit.hh
JParser.hh
JDetectorToolkit.hh
JGIZMO::setAxisLabels
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
initialize axis with PMT address labels
Definition: JGizmoToolkit.hh:603
JPMTParametersToolkit.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JPMTIdentifier
PMT identifier.
Definition: JPMTIdentifier.hh:30
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JEEP::JProperties
Utility class to parse parameter values.
Definition: JProperties.hh:496
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
JDETECTOR::JDetectorAddressMap
Lookup table for PMT addresses in detector.
Definition: JDetectorAddressMap.hh:25
JTOOLS::r
data_type r[M+1]
Definition: JPolint.hh:709
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JDETECTOR::JPMTParameters::QE
double QE
relative quantum efficiency
Definition: JPMTParameters.hh:216
JDETECTOR::JPMTParameters
Data structure for PMT parameters.
Definition: JPMTParameters.hh:29
JLANG::JException
General exception.
Definition: JException.hh:23
JDETECTOR::JDetectorAddressMap::get
const JModuleAddressMap & get(const int id) const
Get module address map.
Definition: JDetectorAddressMap.hh:69
JDETECTOR::getDetectorAddressMap
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
Definition: JDetectorAddressMapToolkit.hh:363