Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
software/JCalibrate/JHVGainGraph.cc
Go to the documentation of this file.
1 
2 #include "Jeep/JPrint.hh"
3 #include "Jeep/JParser.hh"
4 #include "Jeep/JMessage.hh"
5 
6 #include "JSupport/JMeta.hh"
7 
8 #include "dbclient/KM3NeTDBClient.h"
9 
10 #include "JDB/JDB.hh"
11 #include "JDB/JDBToolkit.hh"
12 #include "JDB/JDBincludes.hh"
13 #include "JDB/JSelector.hh"
15 
16 #include "JDetector/JDetector.hh"
18 
19 #include "JCalibrate/JFitToT.hh"
21 
22 #include "JROOT/JManager.hh"
23 
24 #include "TFile.h"
25 
26 
27 /**
28  * \file
29  *
30  * Program to create input data for HV-tuning.
31  * \author bjung
32  */
33 int main(int argc, char **argv)
34 {
35  using namespace std;
36  using namespace JPP;
37 
38  string usr;
39  string pwd;
40  string cookie;
41 
42  map<int, string> inputFiles;
43  string detectorFile;
44  string outputFile;
45 
46  bool loglog = true;
47  double base = 10.0;
48 
49  int debug;
50 
51  try {
52 
53  JProperties properties;
54 
55  properties.insert(gmake_property(loglog));
56  properties.insert(gmake_property(base));
57 
58  JParser<> zap("Program to create input data for HV-tuning.");
59 
60  zap['u'] = make_field(usr) = "";
61  zap['!'] = make_field(pwd) = "";
62  zap['C'] = make_field(cookie) = "";
63  zap['f'] = make_field(inputFiles, "map of run numbers to file names (i.e. to the output of JFitToT)");
64  zap['a'] = make_field(detectorFile, "detector file");
65  zap['o'] = make_field(outputFile, "output file");
66  zap['@'] = make_field(properties) = JPARSER::initialised();
67  zap['d'] = make_field(debug, "debug") = 1;
68 
69  zap(argc, argv);
70  }
71  catch(const exception &error) {
72  FATAL(error.what() << endl);
73  }
74 
75 
77 
79 
80  try {
81 
82  load(detectorFile, detector);
83 
84  JDB::reset(usr, pwd, cookie);
85 
86  // Extract gain and high-voltage data
87 
88  for (map<int, string>::const_iterator fileIt = inputFiles.cbegin(); fileIt != inputFiles.cend(); ++fileIt) {
89 
90  const int runNr = fileIt->first;
91 
92  NOTICE("Extracting Gain-/HV-data for run " << runNr << endl);
93 
94  {
95  TFile fitData(fileIt->second.c_str(), "READ");
96 
98  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), selector);
99 
100  for (JPMTHVRunSettings table; rs >> table; ) {
101 
102  const int domID = detector.getModule(JLocation(table.DUID, table.FLOORID)).getID();
103  const string pmtID = MAKE_STRING(right << domID << '.' << FILL(2,'0') << table.PMTINTID);
104 
105  const TH1* h1 = (TH1*) fitData.Get(MAKE_CSTRING(pmtID << FITTOT_SUFFIX));
106  const TF1* f1 = (h1 != NULL ? h1->GetFunction(FITTOT_FNAME.c_str()) : NULL);
107 
108  JHVGainGraph* HVGainData = manager[pmtID];
109 
110  if (f1 != NULL) {
111 
112  const int Ngain = f1->GetParNumber(FITTOT_GAIN_PARNAME);
113 
114  const double gain = f1->GetParameter(Ngain);
115  const double gainError = f1->GetParError (Ngain);
116 
117  HVGainData->AddPoint(table.HV_VALUE, gain, gainError);
118  }
119  }
120 
121  rs.Close();
122  }
123  }
124 
125  } catch (const exception& error) {
126 
127  FATAL(error.what() << endl);
128  }
129 
130 
131  // Write output
132 
133  TFile out(outputFile.c_str(), "RECREATE");
134 
135  putObject(&out, JMeta(argc, argv));
136 
137  out << manager;
138 
139  out.Close();
140 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object
Detector data structure.
Definition: JDetector.hh:80
Utility class to parse parameter values.
Definition: JProperties.hh:496
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
Dynamic ROOT object management.
Auxiliary class for specifying selection of database data.
string outputFile
Data structure for detector geometry and calibration.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
static const std::string FITTOT_SUFFIX
Definition: JFitToT.hh:36
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
static const char * FITTOT_GAIN_PARNAME
Definition: JFitToT.hh:39
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
Definition: JHVGainGraph.hh:35
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
Add point to diagram.
static const std::string HVGAINGRAPH_SUFFIX
Definition: JHVGainGraph.hh:27
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:327
#define FATAL(A)
Definition: JMessage.hh:67
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
Definition: JToT.sh:45
void reset(T &value)
Reset value.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
do set_variable DETECTOR_TXT $WORKDIR detector
Template definition for getting table specific selector.
static const std::string FITTOT_FNAME
Definition: JFitToT.hh:37
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.