Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGetInputTuneHV.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  int debug;
47 
48  try {
49 
50  JParser<> zap("Program to create input data for HV-tuning.");
51 
52  zap['u'] = make_field(usr) = "";
53  zap['!'] = make_field(pwd) = "";
54  zap['C'] = make_field(cookie) = "";
55  zap['f'] = make_field(inputFiles, "map of run numbers to file names (i.e. to the output of JFitToT)");
56  zap['a'] = make_field(detectorFile, "detector file");
57  zap['o'] = make_field(outputFile, "output file");
58  zap['d'] = make_field(debug, "debug") = 1;
59 
60  zap(argc, argv);
61  }
62  catch(const exception &error) {
63  FATAL(error.what() << endl);
64  }
65 
66 
68 
69  JManager<string, TMultiGraph> manager(new TMultiGraph(), "%.HVxG");
70 
71  try {
72 
73  load(detectorFile, detector);
74 
75  JDB::reset(usr, pwd, cookie);
76 
77  // Extract gain and high-voltage data
78 
79  for (map<int, string>::const_iterator fileIt = inputFiles.cbegin(); fileIt != inputFiles.cend(); ++fileIt) {
80 
81  const int runNr = fileIt->first;
82 
83  NOTICE("Extracting Gain-/HV-data for run " << runNr << endl);
84 
85  {
86  TFile fitData(fileIt->second.c_str(), "READ");
87 
89  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), selector);
90 
91  for (JPMTHVRunSettings table; rs >> table; ) {
92 
93  const int domID = detector.getModule(JLocation(table.DUID, table.FLOORID)).getID();
94  const string pmtID = MAKE_STRING(right << domID << '.' << FILL(2,'0') << table.PMTINTID);
95 
96  const TH1* h1 = (TH1*) fitData.Get(MAKE_CSTRING(pmtID << FITTOT_SUFFIX));
97  const TF1* f1 = (h1 != NULL ? h1->GetFunction(FITTOT_FNAME.c_str()) : NULL);
98 
99  JHVInterpolator interpolator(*(manager[pmtID]));
100 
101  if (f1 != NULL) {
102 
103  const int Ngain = f1->GetParNumber(FITTOT_GAIN_PARNAME);
104 
105  const double gain = f1->GetParameter(Ngain);
106  const double gainError = f1->GetParError (Ngain);
107 
108  interpolator.AddPoint(table.HV_VALUE, gain, gainError);
109  }
110  }
111 
112  rs.Close();
113  }
114  }
115 
116  } catch (const exception& error) {
117 
118  FATAL(error.what() << endl);
119  }
120 
121 
122  // Write output
123 
124  TFile out(outputFile.c_str(), "RECREATE");
125 
126  putObject(&out, JMeta(argc, argv));
127 
128  out << manager;
129 
130  out.Close();
131 }
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
Detector data structure.
Definition: JDetector.hh:80
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:69
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 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
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
#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
General purpose messaging.
Auxiliary data structure for sequence of same character.
Definition: JManip.hh:328
#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
void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
Add point to diagram.
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.