Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 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 "JROOT/JManager.hh"
#include "JGizmo/JGizmoToolkit.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 32 of file JPlotPMTParameters2D.cc.

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['P'] = make_field(inputFile, "PMT calibration data file(s)");
52  zap['o'] = make_field(outputFile, "output file.") = "pmt_parameters.root";
53  zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis") = " ";
54  zap['A'] = make_field(showPMTAddress, "show PMT address on y-axis");
55  zap['L'] = make_field(labelInterval, "interval between x-axis bins for which labels are shown") = 1;
56  zap['d'] = make_field(debug, "debug") = 0;
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 
77  const JDetectorAddressMap& demo = getDetectorAddressMap(detector.getID());
78 
80 
81  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
82  parameters.push_back(JPMTParametersMap(i->c_str()));
83  }
84 
85 
86  const int NUMBER_OF_FILES = parameters.size();
87 
88  JManager<string, TH2D> manager(new TH2D("%", NULL,
89  NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5,
90  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5));
91 
92  manager->Sumw2(kFALSE);
93 
94  if (regexp != " ") {
95 
96  const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval;
97 
98  const TPRegexp buffer(regexp);
99 
100  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
101 
102  if(i%n == 0)
103  manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer, TString(inputFile[i].c_str())));
104  else
105  manager->GetXaxis()->SetBinLabel(i+1 , " ");
106  }
107  }
108 
109  for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) {
110 
111  DEBUG("Module " << setw(10) << module->getID() << endl);
112 
113  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
114 
115  for (int i = 0; i != NUMBER_OF_FILES; ++i) {
116 
117  const JProperties properties = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt)).getProperties();
118 
119  for (JProperties::const_iterator p = properties.begin(); p != properties.end(); ++p) {
120 
121  try {
122  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->SetBinContent(i + 1, pmt + 1, p->second.getValue<const double>());
123  }
124  catch(const exception& error) {}
125 
126  try {
127  manager[MAKE_CSTRING(module->getID() << "." << p->first)]->SetBinContent(i + 1, pmt + 1, p->second.getValue<const bool>() ? 1.0 : 0.0);
128  }
129  catch(const exception& error) {}
130  }
131 
132  const JPMTParameters buffer = parameters[i].getPMTParameters(JPMTIdentifier(module->getID(), pmt));
133 
134  manager[MAKE_CSTRING(module->getID() << "." << "EFFICIENCY")]->SetBinContent(i + 1, pmt + 1, getSurvivalProbability(buffer) * buffer.QE);
135  }
136  }
137  }
138 
139  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
140  i->second->Sumw2(kFALSE);
141  }
142 
143  if (showPMTAddress){
144 
145  for (JManager<string, TH2D>::iterator i = manager.begin(); i != manager.end(); ++i) {
146 
147  int id;
148 
149  istringstream(i->first) >> id;
150 
151  setAxisLabels(*i->second, "Y", demo.get(id));
152  }
153  }
154 
155  manager.Write(outputFile.c_str());
156 }
Utility class to parse command line options.
Definition: JParser.hh:1500
General exception.
Definition: JException.hh:23
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:151
Lookup table for PMT addresses in detector.
string outputFile
boost::property_tree::ptree parse(std::string str)
Definition: configure.hh:24
const int n
Definition: JPolint.hh:660
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
Detector file.
Definition: JHead.hh:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
void setAxisLabels(TAxis *axis, const JModuleAddressMap &memo)
Set axis with PMT address labels.
Auxiliary class for map of PMT parameters.
int debug
debug level
Definition: JSirene.cc:63
JDetectorAddressMap & getDetectorAddressMap()
Get detector address map.
#define FATAL(A)
Definition: JMessage.hh:67
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
double getSurvivalProbability(const JPMTParameters &parameters)
Get model dependent probability that a one photo-electron hit survives the simulation of the PMT assu...
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Data structure for PMT parameters.
do set_variable DETECTOR_TXT $WORKDIR detector
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
Definition: JDAQ.hh:26
double QE
relative quantum efficiency