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"
8 
9 #include "dbclient/KM3NeTDBClient.h"
10 
11 #include "JDB/JDB.hh"
12 #include "JDB/JDBToolkit.hh"
13 #include "JDB/JDBincludes.hh"
14 #include "JDB/JSelector.hh"
16 
17 #include "JDetector/JDetector.hh"
19 
20 #include "JCalibrate/JFitToT.hh"
22 
23 #include "JROOT/JManager.hh"
24 
25 #include "TFile.h"
26 
27 
28 /**
29  * \file
30  *
31  * Program to create input data for HV-tuning.
32  * \author bjung
33  */
34 int main(int argc, char **argv)
35 {
36  using namespace std;
37  using namespace JPP;
38 
39  string usr;
40  string pwd;
41  string cookie;
42 
43  map<int, string> inputFiles;
44  string detectorFile;
45  string outputFile;
46 
47  int debug;
48 
49  try {
50 
51  JParser<> zap("Program to create input data for HV-tuning.");
52 
53  zap['u'] = make_field(usr) = "";
54  zap['!'] = make_field(pwd) = "";
55  zap['C'] = make_field(cookie) = "";
56  zap['f'] = make_field(inputFiles, "map of run numbers to file names (i.e. to the output of JFitToT)");
57  zap['a'] = make_field(detectorFile, "detector file");
58  zap['o'] = make_field(outputFile, "output file");
59  zap['d'] = make_field(debug, "debug") = 1;
60 
61  zap(argc, argv);
62  }
63  catch(const exception &error) {
64  FATAL(error.what() << endl);
65  }
66 
67 
69 
70  JManager<string, TMultiGraph> manager(new TMultiGraph(), "%.HVxG");
71 
72  try {
73 
74  load(detectorFile, detector);
75 
76  JDB::reset(usr, pwd, cookie);
77 
78  // Extract gain and high-voltage data
79 
80  for (map<int, string>::const_iterator fileIt = inputFiles.cbegin(); fileIt != inputFiles.cend(); ++fileIt) {
81 
82  const int runNr = fileIt->first;
83 
84  NOTICE("Extracting Gain-/HV-data for run " << runNr << endl);
85 
86  {
87  TFile fitData(fileIt->second.c_str(), "READ");
88 
90  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), selector);
91 
92  for (JPMTHVRunSettings table; rs >> table; ) {
93 
94  const int domID = detector.getModule(JLocation(table.DUID, table.FLOORID)).getID();
95  const string pmtID = MAKE_STRING(right << domID << '.' << FILL(2,'0') << table.PMTINTID);
96 
97  const TH1* h1 = (TH1*) fitData.Get(MAKE_CSTRING(pmtID << FITTOT_SUFFIX));
98  const TF1* f1 = (h1 != NULL ? h1->GetFunction(FITTOT_FNAME.c_str()) : NULL);
99 
100  JHVInterpolator interpolator(*(manager[pmtID]));
101 
102  if (f1 != NULL) {
103 
104  const int Ngain = f1->GetParNumber(FITTOT_GAIN_PARNAME);
105 
106  const double gain = f1->GetParameter(Ngain);
107  const double gainError = f1->GetParError (Ngain);
108 
109  interpolator.AddPoint(table.HV_VALUE, gain, gainError);
110  }
111  }
112 
113  rs.Close();
114  }
115  }
116 
117  } catch (const exception& error) {
118 
119  FATAL(error.what() << endl);
120  }
121 
122 
123  // Write output
124 
125  TFile out(outputFile.c_str(), "RECREATE");
126 
127  putObject(&out, JMeta(argc, argv));
128 
129  for (map<int, string>::const_iterator fileIt = inputFiles.cbegin(); fileIt != inputFiles.cend(); ++fileIt) {
130  for (JSingleFileScanner<JMeta> in(fileIt->second); in.hasNext(); ) {
131  putObject(&out, *in.next());
132  }
133  }
134 
135  out << manager;
136 
137  out.Close();
138 }
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
Scanning of objects from a single file according a format that follows from the extension of each fil...
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
Object reading from a list of files.
do set_variable DETECTOR_TXT $WORKDIR detector
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
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.