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  if (regexp != " "){
94 
95  const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval;
96 
97  const TPRegexp buffer(regexp);
98 
99  for (int i = 0; i != NUMBER_OF_FILES; ++i){
100 
101  if(i%n == 0)
102  manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(inputFile[i].c_str())));
103  else
104  manager->GetXaxis()->SetBinLabel(i+1 , " ");
105  }
106  }
107 
108  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
109 
110  DEBUG("Module " << setw(10) << module->getID() << endl);
111 
112  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
113 
114  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
115 
116  const JProperties properties = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt)).getProperties();
117 
118  for (JProperties::const_iterator p = properties.begin(); p != properties.end(); ++p) {
119 
120  try {
121  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->Fill((Double_t) i, (Double_t) pmt, p->second.getValue<const double>());
122  }
123  catch(const exception& error) {}
124 
125  try {
126  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->Fill((Double_t) i, (Double_t) pmt, p->second.getValue<const bool>() ? 1.0 : 0.0);
127  }
128  catch(const exception& error) {}
129  }
130 
131  const JPMTParameters buffer = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt));
132 
133  manager[MAKE_CSTRING(module->getID() << "." << "EFFICIENCY")]->Fill((Double_t) i, (Double_t) pmt, getSurvivalProbability(buffer) * buffer.QE);
134  }
135  }
136  }
137 
138  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
139  i->second->Sumw2(kFALSE);
140  }
141 
142  if (showPMTAddress){
143 
144  TPRegexp buffer("(\\d{8}).");
145 
146  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
147 
148  TString id = parse(buffer, TString(i->second->GetName()));
149  JModuleAddressMap memo = demo.get(id.IsDigit() ? id.Atoi() : -1);
150 
151  setAxisLabels(i->second->GetYaxis(), memo);
152  }
153  }
154 
155  manager.Write(outputFile.c_str());
156 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition: JScale.hh:47
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
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
*fatal Wrong number of arguments esac cp v $DETECTOR $WORKDIR detector detx for((i=0;$i!=2;++i))
Data structure for PMT parameters.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62