Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrintQuantiles.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <sstream>
5 #include <cmath>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TObject.h"
10 #include "TKey.h"
11 #include "TH1.h"
12 #include "TRegexp.h"
13 
14 #include "JGizmo/JRootObjectID.hh"
15 #include "JGizmo/JGizmoToolkit.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 #include "Jeep/JPrint.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Auxiliary program to print quantiles from ROOT histograms.
26  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
27  *
28  * \author mdejong
29  */
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34 
35  vector<JRootObjectID> inputFile;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Auxiliary program to print quantiles from ROOT histograms.");
42 
43  zap['f'] = make_field(inputFile, "<input file>:<object name>");
44  zap['Q'] = make_field(Q, "quantiles");
45  zap['d'] = make_field(debug) = 0;
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53 
54  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
55 
56  DEBUG("Input: " << *input << endl);
57 
58  TDirectory* dir = getDirectory(*input);
59 
60  if (dir == NULL) {
61  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
62  continue;
63  }
64 
65  const TRegexp regexp(input->getObjectName());
66 
67  TIter iter(dir->GetListOfKeys());
68 
69  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
70 
71  const TString tag(key->GetName());
72 
73  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
74 
75  // option match
76 
77  if (tag.Contains(regexp)) {
78 
79  TObject* object = key->ReadObj();
80 
81  TH1* h1 = dynamic_cast<TH1*>(object);
82 
83  if (h1 != NULL) {
84 
85  vector<Double_t> X(Q.size(), 0.0);
86 
87  h1->GetQuantiles(Q.size(), X.data(), Q.data());
88 
89  for (vector<Double_t>::const_iterator i = X.begin(); i != X.end(); ++i) {
90  cout << ' ' << *i;
91  }
92 
93  cout << endl;
94  }
95  }
96  }
97  }
98 }
Utility class to parse command line options.
Definition: JParser.hh:1500
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
Definition: Main.cc:15
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
then break fi done getCenter read X Y Z let X
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.