Jpp  15.0.1-rc.1-highqe
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JQuantiles1D.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TObject.h"
8 #include "TKey.h"
9 #include "TH1D.h"
10 #include "TString.h"
11 #include "TRegexp.h"
12 
13 #include "JGizmo/JRootObjectID.hh"
14 #include "JGizmo/JGizmoToolkit.hh"
15 
16 #include "Jeep/JPrint.hh"
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 
21 /**
22  * \file
23  *
24  * Auxiliary program to print quantiles from 1D histogram.
25  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
26  * \author mdejong
27  */
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
33  vector<JRootObjectID> inputFile;
35  bool reverse;
36  int debug;
37 
38  try {
39 
40  JParser<> zap("Auxiliary program to print quantiles from 1D histogram.");
41 
42  zap['f'] = make_field(inputFile);
43  zap['Q'] = make_field(Q);
44  zap['R'] = make_field(reverse);
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  if (Q.empty()) {
55  FATAL("No quantiles." << endl);
56  }
57 
58 
59  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
60 
61  DEBUG("Input: " << *input << endl);
62 
63  TDirectory* dir = getDirectory(*input);
64 
65  if (dir == NULL) {
66  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
67  continue;
68  }
69 
70  const TRegexp regexp(input->getObjectName());
71 
72  TIter iter(dir->GetListOfKeys());
73 
74  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
75 
76  const TString tag(key->GetName());
77 
78  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
79 
80  // option match
81 
82  if (tag.Contains(regexp)) {
83 
84  TObject* object = key->ReadObj();
85 
86  try {
87 
88  TH1& h1 = dynamic_cast<TH1&>(*object);
89 
90  Double_t W = 0.0;
91 
92  for (Int_t i = 0; i <= h1.GetXaxis()->GetNbins() + 1; ++i) {
93  W += h1.GetBinContent(i);
94  }
95 
96  if (W != 0.0) {
97 
98  Double_t w = 0.0;
99 
100  if (!reverse) {
101 
102  for (int i = 0, k = 0; i <= h1.GetXaxis()->GetNbins() + 1; ++i) {
103 
104  w += h1.GetBinContent(i);
105 
106  for ( ; k != (int) Q.size() && w >= Q[k]*W; ++k) {
107  cout << h1.GetName() << ' ' << FIXED(4,2) << Q[k] << ' ' << FIXED(10,5) << h1.GetXaxis()->GetBinCenter(i) << endl;
108  }
109 
110  }
111 
112  } else {
113 
114  for (int i = h1.GetXaxis()->GetNbins() + 1, k = 0; i >= 0; --i) {
115 
116  w += h1.GetBinContent(i);
117 
118  for ( ; k != (int) Q.size() && w >= Q[k]*W; ++k) {
119  cout << h1.GetName() << ' ' << FIXED(4,2) << Q[k] << ' ' << FIXED(10,5) << h1.GetXaxis()->GetBinCenter(i) << endl;
120  }
121  }
122  }
123  }
124  }
125  catch(exception&) {
126  ERROR("Not available for other objects than 1D histograms." << endl);
127  }
128  }
129  }
130  }
131 }
Utility class to parse command line options.
Definition: JParser.hh:1500
data_type w[N+1][M+1]
Definition: JPolint.hh:741
then fatal No hydrophone data file $HYDROPHONE_TXT fi sort gr k
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
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
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
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.