Jpp  15.0.2
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  JServer server;
40  string usr;
41  string pwd;
42  string cookie;
43 
44  map<int, string> inputFiles;
45  string detectorFile;
46  string outputFile;
47 
48  int debug;
49 
50  try {
51 
52  JParser<> zap("Program to create input data for HV-tuning.");
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['f'] = make_field(inputFiles, "map of run numbers to file names (i.e. to the output of JFitToT)");
59  zap['a'] = make_field(detectorFile, "detector file");
60  zap['o'] = make_field(outputFile, "output file");
61  zap['d'] = make_field(debug, "debug") = 1;
62 
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69 
71 
72  JManager<string, TMultiGraph> manager(new TMultiGraph(), "%.HVxG");
73 
74  try {
75 
76  load(detectorFile, detector);
77 
78  JDB::reset(usr, pwd, cookie);
79 
80  // Extract gain and high-voltage data
81 
82  for (map<int, string>::const_iterator fileIt = inputFiles.cbegin(); fileIt != inputFiles.cend(); ++fileIt) {
83 
84  const int runNr = fileIt->first;
85 
86  NOTICE("Extracting Gain-/HV-data for run " << runNr << endl);
87 
88  {
89  TFile fitData(fileIt->second.c_str(), "READ");
90 
92  ResultSet& rs = getResultSet(getTable<JPMTHVRunSettings>(), selector);
93 
94  for (JPMTHVRunSettings table; rs >> table; ) {
95 
96  const int domID = detector.getModule(JLocation(table.DUID, table.FLOORID)).getID();
97  const string pmtID = MAKE_STRING(right << domID << '.' << FILL(2,'0') << table.CABLEPOS);
98 
99  const TH1* h1 = (TH1*) fitData.Get(MAKE_CSTRING(pmtID << FITTOT_SUFFIX));
100  const TF1* f1 = (h1 != NULL ? h1->GetFunction(FITTOT_FNAME.c_str()) : NULL);
101 
102  JHVInterpolator interpolator(*(manager[pmtID]));
103 
104  if (f1 != NULL) {
105 
106  const int Ngain = f1->GetParNumber(FITTOT_GAIN_PARNAME);
107 
108  const double gain = f1->GetParameter(Ngain);
109  const double gainError = f1->GetParError (Ngain);
110 
111  interpolator.AddPoint(table.HV_VALUE, gain, gainError);
112  }
113  }
114 
115  rs.Close();
116  }
117  }
118 
119  } catch (const exception& error) {
120 
121  FATAL(error.what() << endl);
122  }
123 
124 
125  // Write output
126 
127  TFile out(outputFile.c_str(), "RECREATE");
128 
129  putObject(out, JMeta(argc, argv));
130 
131  for (map<int, string>::const_iterator i = inputFiles.cbegin(); i != inputFiles.cend(); ++i) {
132  for (JSingleFileScanner<JMeta> in(i->second); in.hasNext(); ) {
133  putObject(out, *in.next());
134  }
135  }
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
Detector data structure.
Definition: JDetector.hh:89
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
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
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
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:47
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:432
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:98
Wrapper class for server name.
Definition: JDB.hh:42
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:41
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.