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

Auxiliary application to plot PMT parameters. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTParametersToolkit.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JGizmo/JManager.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "JROOT/JRootToolkit.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 application to plot PMT parameters.

Author
mdejong, rgruiz

Definition in file JPlotPMTParameters2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file JPlotPMTParameters2D.cc.

34 {
35  using namespace std;
36  using namespace JPP;
37  using namespace KM3NETDAQ;
38 
39  string detectorFile;
40  vector<string> inputFile;
41  string outputFile;
42  string regexp;
43  int labelInterval;
44  bool showPMTAddress;
45  int debug;
46 
47  try {
48 
49  JParser<> zap("Auxiliary application to plot PMT parameters.");
50 
51  zap['a'] = make_field(detectorFile, "detector file.");
52  zap['P'] = make_field(inputFile, "PMT calibration data file(s)");
53  zap['o'] = make_field(outputFile, "output file.") = "pmt_parameters.root";
54  zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis") = " ";
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  zap['d'] = make_field(debug, "debug") = 0;
58 
59  zap(argc, argv);
60  }
61  catch(const exception &error) {
62  FATAL(error.what() << endl);
63  }
64 
66 
67  try {
68  load(detectorFile, detector);
69  }
70  catch(const JException& error) {
71  FATAL(error);
72  }
73 
74  if (detector.empty()) {
75  FATAL("Empty detector." << endl);
76  }
77 
78  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
79 
81 
82  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
83  parameters.push_back(JPMTParametersMap(i->c_str()));
84  }
85 
86 
87  const int NUMBER_OF_FILES = parameters.size();
88 
89  JManager<string, TH2D> manager(new TH2D("%", NULL,
90  NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5,
91  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
92 
93  manager->Sumw2(kFALSE);
94 
95  if (regexp != " "){
96 
97  const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval;
98 
99  const TPRegexp buffer(regexp);
100 
101  for (int i = 0; i != NUMBER_OF_FILES; ++i){
102 
103  if(i%n == 0)
104  manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(inputFile[i].c_str())));
105  else
106  manager->GetXaxis()->SetBinLabel(i+1 , " ");
107  }
108  }
109 
110  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
111 
112  DEBUG("Module " << setw(10) << module->getID() << endl);
113 
114  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
115 
116  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
117 
118  const JProperties properties = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt)).getProperties();
119 
120  for (JProperties::const_iterator p = properties.begin(); p != properties.end(); ++p) {
121 
122  try {
123  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->SetBinContent(i + 1, pmt + 1, p->second.getValue<const double>());
124  }
125  catch(const exception& error) {}
126 
127  try {
128  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->SetBinContent(i + 1, pmt + 1, p->second.getValue<const bool>() ? 1.0 : 0.0);
129  }
130  catch(const exception& error) {}
131  }
132 
133  const JPMTParameters buffer = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt));
134 
135  manager[MAKE_CSTRING(module->getID() << "." << "EFFICIENCY")]->SetBinContent(i + 1, pmt + 1, getSurvivalProbability(buffer) * buffer.QE);
136  }
137  }
138  }
139 
140  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
141  i->second->Sumw2(kFALSE);
142  }
143 
144  if (showPMTAddress){
145 
146  TPRegexp buffer("(\\d{8}).");
147 
148  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
149 
150  TString id = parse(buffer, TString(i->second->GetName()));
151  JModuleAddressMap memo = demo.get(id.IsDigit() ? id.Atoi() : -1);
152 
153  setAxisLabels(i->second->GetYaxis(), memo);
154  }
155  }
156 
157  manager.Write(outputFile.c_str());
158 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Detector data structure.
Definition: JDetector.hh:80
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:708
Lookup table for PMT addresses in detector.
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
JValue_t second
Definition: JPair.hh:129
boost::property_tree::ptree parse(std::string str)
Definition: configure.hh:24
Auxiliary class to manage set of compatible ROOT objects (e.g.
Definition: JManager.hh:42
Lookup table for PMT addresses in optical module.
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
initialize axis with PMT address labels
Auxiliary class for map of PMT parameters.
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.
#define FATAL(A)
Definition: JMessage.hh:67
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
alias put_queue eval echo n
Definition: qlib.csh:19
Data structure for PMT parameters.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
double QE
relative quantum efficiency
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62