Jpp
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 
10 #include "JDAQ/JDAQ.hh"
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;
34  typedef multimap<string, JRange_t> map_type;
35 
36  string detectorFile;
37  string inputFile;
38  string outputFile;
39  map_type parameters;
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 }
JDAQ.hh
JMessage.hh
JPrint.hh
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:456
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
JDETECTOR::getNumberOfStrings
int getNumberOfStrings(const JDetector &detector)
Get number of strings.
Definition: JDetectorToolkit.hh:378
JDETECTOR::getNumberOfFloors
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
Definition: JDetectorToolkit.hh:414
main
int main(int argc, char **argv)
Definition: JPlotPMTSystematics.cc:28
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
JRange.hh
debug
int debug
debug level
Definition: JSirene.cc:59
JParser.hh
JDetectorToolkit.hh
std::multimap
Definition: JSTDTypes.hh:17
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
KM3NETDAQ
KM3NeT DAQ data structures and auxiliaries.
Definition: DataQueue.cc:39
p1
TPaveText * p1
Definition: JDrawModule3D.cc:35
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37