Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
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
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 */
34int 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}
string outputFile
This file is automatically created by make.
Data structure for detector geometry and calibration.
int main(int argc, char **argv)
Dynamic ROOT object management.
General purpose messaging.
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
ROOT I/O of application specific meta data.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Scanning of objects from a single file according a format that follows from the extension of each fil...
Auxiliary class for specifying selection of database data.
Detector data structure.
Definition JDetector.hh:96
Logical location of module.
Definition JLocation.hh:40
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
Object reading from a list of files.
virtual bool hasNext() override
Check availability of next element.
static const std::string FITTOT_FNAME
Definition JFitToT.hh:38
static const std::string FITTOT_SUFFIX
Definition JFitToT.hh:37
static const char * FITTOT_GAIN_PARNAME
Definition JFitToT.hh:40
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition JDB.hh:438
const char * getTable()
Get table name.
Definition JDB.hh:373
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition JDB.hh:108
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).
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
Auxiliary data structure for sequence of same character.
Definition JManip.hh:330
Detector file.
Definition JHead.hh:227
Auxiliary data structure to store high-voltage versus gain data and interpolate the nominal high-volt...
void AddPoint(Double_t HV, Double_t gain, Double_t gainError)
Add point to diagram.
Wrapper class for server name.
Definition JDB.hh:54
Template definition for getting table specific selector.
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72