Jpp  19.1.0
the software that should make you happy
JDB/JPlotPMTParameters.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 
9 #include "JDB/JDB.hh"
10 #include "JDB/JSelector.hh"
13 #include "JDB/JPBSSequence.hh"
14 #include "JDB/JProductRouter.hh"
15 #include "JDB/JDBToolkit.hh"
16 
17 #include "JDetector/JDetector.hh"
22 
23 #include "JROOT/JManager.hh"
24 
25 #include "Jeep/JParser.hh"
26 #include "Jeep/JMessage.hh"
27 
28 
29 /**
30  * \file
31  *
32  * Auxiliary application to plot PMT parameters as a function of variant.
33  * \author mdejong
34  */
35 int main(int argc, char **argv)
36 {
37  using namespace std;
38  using namespace JPP;
39 
40  JServer server;
41  string usr;
42  string pwd;
43  string cookie;
44  string detectorFile;
45  string inputFile;
46  JPMTParametersMap parameters;
47  string outputFile;
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Auxiliary application to plot PMT parameters as a function of variant.");
53 
54  zap['s'] = make_field(server) = getServernames();
55  zap['u'] = make_field(usr) = "";
56  zap['!'] = make_field(pwd) = "";
57  zap['C'] = make_field(cookie) = "";
58  zap['a'] = make_field(detectorFile, "detector file.");
59  zap['f'] = make_field(inputFile, "output of JPrintDB -q \"integration\" -c \";\" -W1") = "";
60  zap['o'] = make_field(outputFile, "output file.") = "pmt_parameters.root";
61  zap['P'] = make_field(parameters, "PMT calibration data (or corresponding file name)");
62  zap['d'] = make_field(debug) = 1;
63 
64  zap(argc, argv);
65  }
66  catch(const exception &error) {
67  FATAL(error.what() << endl);
68  }
69 
70 
72 
73  try {
74  load(detectorFile, detector);
75  }
76  catch(const JException& error) {
77  FATAL(error);
78  }
79 
80  const JLocationRouter router(detector);
81 
82  JDetectorIntegration_t integration;
83 
84  string detid = "";
85 
86  try {
87 
88  JDB::reset(usr, pwd, cookie);
89 
90  detid = getDetector(detector.getID());
91  }
92  catch(const exception& error) {
93  FATAL(error.what() << endl);
94  }
95 
96  if (inputFile != "") {
97 
98  integration.load(inputFile.c_str());
99 
100  } else {
101 
102  DEBUG("Reading database table " << getTable<JDetectorIntegration_t>() << endl);
103 
104  try {
105 
106  ResultSet& rs = getResultSet(getTable<JDetectorIntegration_t>());
107 
108  if (! (rs >> integration)) {
109  THROW(JDatabaseException, "Error reading " << getTable<JDetectorIntegration_t>());
110  }
111  }
112  catch(const exception& error) {
113  FATAL(error.what() << endl);
114  }
115  }
116 
117  integration.configure(detid);
118 
119  const JProductRouter product(integration, getPBSSequences(PBS::PMT));
120 
121  JDetectorIntegration_t::range_type range = integration.find(PBS::PMT);
122 
123  JManager<string, TH1D> H1(new TH1D("TTS_ns[%]", NULL, 100, 0.0, 4.0));
124  JManager<string, TH1D> H2(new TH1D("QE[%]", NULL, 100, 0.0, 2.0));
125  JManager<string, TH1D> H3(new TH1D("gain[%]", NULL, 100, 0.0, 2.0));
126  JManager<string, TH1D> H4(new TH1D("gainSpread[%]", NULL, 100, 0.0, 1.0));
127 
128  for (JDetectorIntegration_t::range_const_iterator i = range.first; i != range.second; ++i) {
129 
130  const JUPI_t upi = integration[i->second].content.getUPI();
131  const JLocation_t location = product.getLocation(upi);
132 
133  DEBUG("PMT " << left << setw(24) << upi.getVariant() << right << ' ' << location << endl);
134 
135  if (location.is_valid()) {
136 
137  const JModule& module = router.getModule(JLocation(location.string, location.floor));
138  const JPMTParameters& buffer = parameters.getPMTParameters(JPMTIdentifier(module.getID(), location.position));
139 
140  H1[upi.getVariant()]->Fill(buffer.TTS_ns);
141  H2[upi.getVariant()]->Fill(buffer.QE);
142  H3[upi.getVariant()]->Fill(buffer.gain);
143  H4[upi.getVariant()]->Fill(buffer.gainSpread);
144  }
145  }
146 
147  TFile out(outputFile.c_str(), "recreate");
148 
149  out << H1 << H2 << H3 << H4;
150 
151  out.Write();
152  out.Close();
153 }
JDAQPMTIdentifier PMT
Command line options.
string outputFile
int main(int argc, char **argv)
Data structure for detector geometry and calibration.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Direct access to location in detector data structure.
Dynamic ROOT object management.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Detector data structure.
Definition: JDetector.hh:96
Router for direct addressing of location data in detector data structure.
const JModule & getModule(const JLocation &location) const
Get module parameters.
Logical location of module.
Definition: JLocation.hh:40
Data structure for a composite optical module.
Definition: JModule.hh:75
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Data structure for PMT parameters.
double QE
relative quantum efficiency
double gainSpread
gain spread [unit]
double TTS_ns
transition time spread [ns]
Database exception.
Definition: JException.hh:684
General exception.
Definition: JException.hh:24
int getID() const
Get identifier.
Definition: JObjectID.hh:50
Utility class to parse command line options.
Definition: JParser.hh:1698
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:304
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:437
static JGetPBSSequences getPBSSequences
Function object to get PBS sequences as a function of PBS.
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
Definition: JDBToolkit.hh:378
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:107
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
void reset(T &value)
Reset value.
Definition: JSTDTypes.hh:14
Detector file.
Definition: JHead.hh:227
void load(const char *const file_name, const std::string &separator=";")
Load detector integration from CSV formatted input file.
void configure(const std::string &detid, const bool option=false)
Configure detector integration for given detector identifier.
map_type::const_iterator range_const_iterator
range_type find(const JUPI_t &upi) const
Find range of products with given UPI.
Auxiliary data structure for location of product in detector.
Definition: JLocation_t.hh:26
int string
position in detector
Definition: JLocation_t.hh:105
bool is_valid() const
Check validity of location.
Definition: JLocation_t.hh:59
int floor
position in string
Definition: JLocation_t.hh:106
int position
position in floor
Definition: JLocation_t.hh:107
Auxiliary class to map UPI to location in detector.
JLocation_t getLocation(const JUPI_t &upi) const
Get location of product with given UPI.
Wrapper class for server name.
Definition: JDB.hh:53
Universal product identifier (UPI).
Definition: JUPI_t.hh:32
const std::string & getVariant() const
Get variant.
Definition: JUPI_t.hh:111