100 typedef JRange<int> JRange_t;
111 JCondition_t condition;
119 JParser<> zap(
"Example program to plot quality data from data base."\
120 "\nThe condition and veto can be any TFormula compatible expression involving QA/QC parameters (see e.g. JQAQC.sh -h).");
125 zap[
'f'] =
make_field(inputFile,
"Optional input file instead of database.") =
"";
126 zap[
'o'] =
make_field(
outputFile,
"Output file containing histograms and n-tuple.") =
"quality.root";
128 zap[
'R'] =
make_field(runs,
"Run range") = JRange_t(1, JRange_t::getMaximum());
129 zap[
'S'] =
make_field(source,
"GIT versions") =
getGITTags(TRegexp(
"v.*\\..*\\..*"), JGITTags_t::key_type(
"2019-04-12"));
130 zap[
'Q'] =
make_field(condition,
"User defined conditions");
138 catch(
const exception &error) {
139 FATAL(error.what() << endl);
145 for (JCondition_t::const_iterator i = condition.begin(); i != condition.end(); ++i) {
150 FATAL(
"Invalid total weight: " << W << endl);
157 if (inputFile ==
"") {
168 ID = to_value<int>(detid);
176 selection += getSelector<JRuns>(
ID);
178 ResultSet& rs =
getResultSet(getTable<JRuns>(), selection);
181 if (TString(parameters.RUNSETUPNAME.c_str()).Contains(regexp)) {
182 setup.put(parameters);
195 JSelector selector = getSelector<JRunSummaryNumbers>(detid, runs.getLowerLimit(), runs.getUpperLimit());
197 selector.add(&JRunSummaryNumbers::SOURCE_NAME, *i);
201 ResultSet& rs =
getResultSet(getTable<JRunSummaryNumbers>(), selector);
203 for (JRunSummaryNumbers parameters; rs >>
parameters; ) {
204 if (setup.has(parameters.RUN)) {
205 zmap[parameters.RUN].insert(make_pair(parameters.PARAMETER_NAME, parameters.DATA_VALUE));
209 catch(
const exception& error) {}
211 for (map_type::const_iterator run = zmap.begin(); run != zmap.end(); ++run) {
216 quality.detector =
ID;
217 quality.run = run->first;
219 for (data_type::const_iterator p = run->second.begin(); p != run->second.end(); ++p) {
220 quality.put(p->first, p->second);
223 buffer.insert(quality);
227 catch(
const exception& error) {
228 FATAL(error.what() << endl);
233 ifstream
in(inputFile.c_str());
235 for (JRunQuality quality;
in >> quality; ) {
236 buffer.insert(quality);
242 if (buffer.empty()) {
243 FATAL(
"No data." << endl);
256 runs = JRange_t(buffer.begin()->run, buffer.rbegin()->run);
258 TH1D h0(
"h0", NULL, 1000, 0.0, 1.01);
259 TH1D
h1(
"h1", NULL, condition.size(), -0.5, condition.size() + 0.5);
262 h0.SetMaximum(1.1 * (runs.getUpperLimit() - runs.getLowerLimit()));
265 h1.SetMaximum(1.1 * (runs.getUpperLimit() - runs.getLowerLimit()));
267 JManager<TString, TH1D> zmap(
new TH1D(
"%", NULL,
268 runs.getLength() + 1,
269 runs.getLowerLimit() - 0.5,
270 runs.getUpperLimit() + 0.5));
274 for (JCondition_t::const_iterator i = condition.begin(); i != condition.end();++i) {
276 const string buffer = i->formula;
278 zmap[buffer]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(buffer <<
":upper"),
MAKE_CSTRING(i->range.getUpperLimit()), runs.getLowerLimit(), runs.getUpperLimit()));
279 zmap[buffer]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(buffer <<
":lower"),
MAKE_CSTRING(i->range.getLowerLimit()), runs.getLowerLimit(), runs.getUpperLimit()));
282 for (JCondition_t::const_iterator i = veto.begin(); i != veto.end();++i) {
284 const string buffer =
MAKE_STRING(
"VETO[" << i->formula <<
"]");
286 zmap[buffer]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(buffer <<
":upper"),
MAKE_CSTRING(i->range.getUpperLimit()), runs.getLowerLimit(), runs.getUpperLimit()));
287 zmap[buffer]->GetListOfFunctions()->Add(
new TF1(
MAKE_CSTRING(buffer <<
":lower"),
MAKE_CSTRING(i->range.getLowerLimit()), runs.getLowerLimit(), runs.getUpperLimit()));
294 for (
size_t i = 0; i != condition.size(); ++i) {
295 os <<
":" << (char) (
'a' + i);
300 TNtuple n1(
"n1",
"quality", os.str().c_str());
314 tuple.push_back((Float_t) quality->run);
318 for (
size_t i = 0; i != condition.size(); ++i) {
320 const JCondition& ps = condition[i];
321 const double y =
getResult(ps.formula, *quality);
323 DEBUG(ps.formula <<
' ' << y << endl);
325 tuple.push_back((Float_t) y);
327 TH1D* p = zmap[ps.formula];
329 p->SetBinContent(p->FindBin((
double) quality->run), y);
330 p->SetBinError (p->FindBin((
double) quality->run), 0.0);
336 h1.AddBinContent(i + 1, ps.range(y) ? 1.0 : 0.0);
339 const double Q = w/W;
341 tuple.push_back((Float_t) Q);
345 for (
size_t i = 0; i != veto.size(); ++i) {
347 const JCondition& ps = veto[i];
348 const double y =
getResult(ps.formula, *quality);
350 TH1D* p = zmap[
MAKE_STRING(
"VETO[" << ps.formula <<
"]")];
352 p->SetBinContent(p->FindBin((
double) quality->run), ps.range(y) ? 0.0 : 1.0);
353 p->SetBinError (p->FindBin((
double) quality->run), 0.0);
360 tuple.push_back((Float_t) V);
361 tuple.push_back((Float_t) setup.get(quality->run));
364 n1.Fill(tuple.data());
366 cout << setw(8) << quality->run <<
' ' <<
FIXED(5,3) << Q <<
' ' << setw(2) << V << endl;
371 for (Int_t i = 0; i <= h0.GetXaxis()->GetNbins(); ++i) {
372 h0.SetBinContent(i, (w += h0.GetBinContent(i)));
379 out << h0 <<
h1 << n1 << zmap;
Utility class to parse command line options.
std::vector< std::string > getGITTags(const TRegexp regexp, const JGITTags_t::key_type date)
Get selection of GIT tags.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
#define MAKE_CSTRING(A)
Make C-string.
then for HISTOGRAM in h0 h1
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary data structure for floating point format specification.
bool resetObject(JManager< JKey_t, JValue_t > *object, const bool reset=false)
Reset JManager object.
#define MAKE_STRING(A)
Make string.
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
#define ASSERT(A,...)
Assert macro.
T & getInstance(const T &object)
Get static instance from temporary object.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Double_t getResult(const TString &text, TObject *object=NULL)
Get result of given textual formula.
bool is_integer(const std::string &buffer)
Check if string is an integer.
ResultSet & getResultSet(const std::string &query)
Get result set.
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
#define DEBUG(A)
Message macros.