Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JTunePMTThreshold.cc File Reference

Auxiliary program to compute the PMT thresholds according to the small time-over-threshold fraction. More...

#include <string>
#include <iostream>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "km3net-dataformat/online/JDAQHeader.hh"
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JPersons.hh"
#include "JDB/JPMTThreshold.hh"
#include "JDB/JDetectorIntegration.hh"
#include "JCalibrate/JCalibrateToT.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JTools/JRange.hh"
#include "JLang/JLangToolkit.hh"
#include "JLang/JComparator.hh"
#include "JROOT/JRootFileReader.hh"
#include "JSon/JSon.hh"
#include "JSystem/JDateAndTime.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (const int argc, const char *const argv[])
 

Detailed Description

Auxiliary program to compute the PMT thresholds according to the small time-over-threshold fraction.

Author
acreusot, mdejong

Definition in file JTunePMTThreshold.cc.

Function Documentation

◆ main()

int main ( const int argc,
const char *const argv[] )

Definition at line 67 of file JTunePMTThreshold.cc.

68{
69 using namespace std;
70 using namespace JPP;
71
73
74 JServer server;
75 string usr;
76 string pwd;
77 string cookie;
78 vector<string> inputFile;
79 string outputFile;
80 JRange_t range;
81 double fraction;
82 string testType;
83 int debug;
84
85 try {
86
87 JParser<> zap("Auxiliary program to compute the PMT thresholds according to the small time-over-threshold fraction.");
88
89 zap['s'] = make_field(server) = getServernames();
90 zap['u'] = make_field(usr) = "";
91 zap['!'] = make_field(pwd) = "";
92 zap['C'] = make_field(cookie) = "";
93 zap['f'] = make_field(inputFile, "list of file names (output of JCalibrateToT)");
94 zap['o'] = make_field(outputFile, "output file for JSon") = "";
95 zap['x'] = make_field(range, "integration range for noise.") = JRange_t(0.0, 8.0);
96 zap['t'] = make_field(fraction, "maximal fraction of signal allowed for noise.") = 0.5;
97 zap['T'] = make_field(testType, "test type") = "TH-TUNING-SEA-v1";
98 zap['d'] = make_field(debug, "debug.") = 2;
99
100 zap(argc, argv);
101 }
102 catch(const exception& error) {
103 FATAL(error.what() << endl);
104 }
105
106
107 if (inputFile.empty()) {
108 FATAL("No input files.");
109 }
110
111 JDateAndTime timer;
112 JPersons person;
113
114 try {
115
116 JDB::reset(usr, pwd, cookie);
117
118 ResultSet& rs = getResultSet(getTable<JPersons>(), getSelector<JPersons>(JDB::get()->User()));
119
120 rs >> person;
121
122 rs.Close();
123 }
124 catch(const exception& error) {
125 FATAL(error.what() << endl);
126 }
127
128
129 const JDAQHeader header = getDAQHeader(inputFile[0].c_str());
130 const int ID = header.getDetectorID();
131
132 typedef map<int, JDetectorIntegration> module_type;
133 typedef map<int, module_type> detector_type;
134
135 detector_type detector;
136
137 try {
138
140
141 for (JDetectorIntegration parameters; rs >> parameters; ) {
142 detector[parameters.DOMID][parameters.CABLEPOS] = parameters;
143 }
144
145 rs.Close();
146 }
147 catch(const exception& error) {
148 FATAL(error.what() << endl);
149 }
150
151
152 struct parameters_type {
153 int threshold;
154 double signal;
155 double noise;
156 };
157
160
161 map_type data;
162 vector<int> runs;
163
164 for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
165
166 const JDAQHeader header = getDAQHeader(i->c_str());
167
168 ASSERT(header.getDetectorID() == ID, "file: " << *i);
169
170 runs.push_back(header.getRunNumber());
171
172 const JPMTThreshold getPMTThreshold(header.getDetectorID(), header.getRunNumber());
173
174 TFile* in = TFile::Open(i->c_str(), "exist");
175
176 if (in == NULL || !in->IsOpen()) {
177 FATAL("File: " << *i << " not opened." << endl);
178 }
179
180 for (detector_type::const_iterator module = detector.begin(); module != detector.end(); ++module) {
181
182 if (!module->second.empty()) {
183
184 TH2D* h2s = (TH2D*) in->Get(MAKE_CSTRING(module->first << _2SToT));
185
186 if (h2s != NULL) {
187
188 for (int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
189
190 double noise = 0.0;
191 double signal = 0.0;
192
193 for (int iy = 1; iy <= h2s->GetYaxis()->GetNbins(); ++iy) {
194
195 const double x = h2s->GetYaxis()->GetBinCenter(iy);
196 const double y = h2s->GetBinContent(ix, iy);
197
198 signal += y;
199
200 if (range(x)) {
201 noise += y;
202 }
203 }
204
205 const JUPI_t upi = module->second.at(ix-1).PMTUPI;
206
207 data[upi].push_back({ getPMTThreshold(upi).value, signal, noise});
208 }
209
210 } else {
211
212 WARNING("No histogram for module " << module->first << "; skip." << endl);
213 }
214 }
215 }
216
217 in->Close();
218 }
219
220
222
223 for (map_type::iterator i = data.begin(); i != data.end(); ++i) {
224
225 sort(i->second.begin(), i->second.end(), make_comparator(&parameters_type::threshold));
226
227 int threshold = i->second.begin()->threshold;
228
229 for (data_type::const_iterator p = i->second.begin(); p != i->second.end(); ++p) {
230
231 if (p->noise <= fraction * p->signal) {
232
233 threshold = p->threshold;
234
235 break;
236 }
237 }
238
239 if (debug >= debug_t || threshold > i->second.begin()->threshold) {
240
241 cout << "PMT " << left << setw(32) << i->first << " -> " << right << setw(3) << threshold << " (" << i->second.begin()->threshold << ")" << endl;
242
243 for (data_type::const_iterator p = i->second.begin(); p != i->second.end(); ++p) {
244 DEBUG(setw(3) << p->threshold << ' ' << FIXED(7,0) << p->noise << "/" << FIXED(7,0) << p->signal << ' ' << (p->noise <= fraction * p->signal) << endl);
245 }
246 }
247
248 calibration.push_back(JPMTThresholdCalibration_t(i->first.toString(), OK_t, threshold, runs));
249 }
250
251
252 if (outputFile != "") {
253
254 json js;
255
256 js[User_t] = person.LOGIN;
257 js[Location_t] = person.LOCATIONID;
258 js[Start_t + Time_t] = timer.toString();
259 js[End_t + Time_t] = timer().toString();
260 js[Test_t + Type_t] = testType;
261 js[Tests_t] = json(calibration);
262
263 ofstream out(outputFile.c_str());
264
265 out << setw(2) << setprecision(8);
266 out << js;
267
268 out.close();
269 }
270}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define WARNING(A)
Definition JMessage.hh:65
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:57
nlohmann::json json
Auxiliary class for PMT thresholds.
Utility class to parse command line options.
Definition JParser.hh:1664
Range of values.
Definition JRange.hh:42
int getDetectorID() const
Get detector identifier.
int getRunNumber() const
Get run number.
static const char *const _2SToT
Histogram naming.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition JDB.hh:442
const char * getTable()
Get table name.
Definition JDB.hh:377
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition JDB.hh:108
@ debug_t
debug
Definition JMessage.hh:29
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::vector< event_type > data_type
Definition JPerth.cc:105
static const std::string Tests_t
static const std::string User_t
static const std::string Location_t
static const std::string Time_t
static const std::string Test_t
static const std::string OK_t
static const std::string End_t
static const std::string Type_t
static const std::string Start_t
std::map< int, range_type > map_type
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Type definition of range.
Definition JHead.hh:43
Calibration.
Definition JHead.hh:330
Detector file.
Definition JHead.hh:227
Wrapper class for server name.
Definition JDB.hh:54
Universal product identifier (UPI).
Definition JUPI_t.hh:33
Template definition for getting table specific selector.
Data structure for PMT threshold calibration.
Auxiliary class for date and time.
std::string toString() const
Get ASCII formatted date and time.