Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPlotPMTSystematics.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 #include "TH2D.h"
9 
11 
12 #include "JDetector/JDetector.hh"
14 
15 #include "JTools/JRange.hh"
16 
17 #include "Jeep/JPrint.hh"
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 /**
23  * \file
24  * Auxiliary application to convert PMT parameters text file to ROOT histograms.
25  * \author mkarel
26  */
27 
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
33  typedef JRange<double> JRange_t;
35 
36  string detectorFile;
37  string inputFile;
38  string outputFile;
40  int debug;
41 
42  try {
43 
44  JParser<> zap;
45 
46  zap['a'] = make_field(detectorFile);
47  zap['f'] = make_field(inputFile);
48  zap['o'] = make_field(outputFile) = "PMTsystematics.root";
49  zap['p'] = make_field(parameters);
50  zap['d'] = make_field(debug) = 1;
51 
52  zap(argc, argv);
53  }
54  catch(const exception &error) {
55  FATAL(error.what() << endl);
56  }
57 
58  using namespace KM3NETDAQ;
59 
60  JDetector detector;
61 
62  try {
63  load(detectorFile, detector);
64  }
65  catch(const JException& error) {
66  FATAL(error);
67  }
68 
69  if (detector.empty()) {
70  FATAL("Empty detector." << endl);
71  }
72 
73  const int number_of_strings = getNumberOfStrings(detector);
74  const int number_of_floors = getNumberOfFloors (detector);
75 
76  const int ny = number_of_strings * number_of_floors;
77 
78 
79  TFile* in = TFile::Open(inputFile.c_str(), "read");
80 
81  if (in == NULL) {
82  FATAL("No data in inputfile " << inputFile << endl);
83  }
84 
85  TFile out(outputFile.c_str(),"recreate");
86 
87  for (map_type::const_iterator i = parameters.begin(); i != parameters.end(); ++i) {
88 
89  const string key = i->first;
90  const JRange_t range = i->second;
91 
92  TH1D h1(MAKE_CSTRING(key << ".1D"),
93  NULL,
94  100, range.first, range.second);
95 
96  TH2D h2(MAKE_CSTRING(key << ".2D"),
97  NULL,
98  NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5,
99  ny, -0.5, ny - 0.5);
100 
101  // fill
102 
103  for (size_t dom = 0; dom != detector.size(); ++dom) {
104 
105  const JModule& module = detector.at(dom);
106 
107  TH1D* p1 = (TH1D*) in->Get(MAKE_CSTRING(module.getID() << ".1" << key));
108 
109  if (p1 == NULL) {
110  continue;
111  }
112 
113  const int iy = (module.getString() - 1) * number_of_floors + module.getFloor();
114 
115  for (int pmt = 0; pmt != NUMBER_OF_PMTS; ++pmt) {
116 
117  const double value = p1->GetBinContent(pmt+1);
118 
119  h1.Fill(value);
120 
121  h2.SetBinContent(pmt+1, iy, value);
122  }
123  }
124 
125  // axis labels
126 
127  h1.GetXaxis()->SetTitle(key.c_str());
128  h1.GetYaxis()->SetTitle("PMTs");
129 
130  h2.GetXaxis()->SetTitle("PMT DAQ index");
131 
132  for (size_t dom = 0; dom != detector.size(); ++dom) {
133 
134  const JModule& module = detector.at(dom);
135 
136  h2.GetYaxis()->SetBinLabel(dom+1, MAKE_CSTRING(""
137  << setw(3) << setfill('0') << module.getString() << ' '
138  << setw(2) << setfill('0') << module.getFloor()));
139  }
140 
141  h2.GetZaxis()->SetTitle(key.c_str());
142 
143  // write
144  h2.Write();
145  h1.Write();
146  }
147 
148  out.Close();
149 }
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
TPaveText * p1
*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
string outputFile
Data structure for detector geometry and calibration.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
General purpose messaging.
static const JStringCounter getNumberOfStrings
Function object to count unique strings.
#define FATAL(A)
Definition: JMessage.hh:67
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Auxiliary class to define a range between two values.
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
std::map< int, range_type > map_type
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
int debug
debug level