Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JQuantiles2D.cc File Reference

Auxiliary program to extract quantiles from 2D histogram. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TObject.h"
#include "TKey.h"
#include "TH2.h"
#include "TH1D.h"
#include "TString.h"
#include "TRegexp.h"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to extract quantiles from 2D histogram.

The option -f corresponds to <file name>:<object name>.

Author
mdejong

Definition in file JQuantiles2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JQuantiles2D.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34 
35  vector<JRootObjectID> inputFile;
36  string outputFile;
38  bool reverse;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Auxiliary program to extract quantiles from 2D histogram.");
44 
45  zap['f'] = make_field(inputFile);
46  zap['o'] = make_field(outputFile) = "quantiles.root";
47  zap['Q'] = make_field(Q);
48  zap['R'] = make_field(reverse);
49  zap['d'] = make_field(debug) = 0;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57 
58  if (Q.empty()) {
59  FATAL("No quantiles." << endl);
60  }
61 
62  TFile out(outputFile.c_str(), "recreate");
63 
64 
65  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
66 
67  DEBUG("Input: " << *input << endl);
68 
69  TDirectory* dir = getDirectory(*input);
70 
71  if (dir == NULL) {
72  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
73  continue;
74  }
75 
76  const TRegexp regexp(input->getObjectName());
77 
78  TIter iter(dir->GetListOfKeys());
79 
80  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
81 
82  const TString tag(key->GetName());
83 
84  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
85 
86  // option match
87 
88  if (tag.Contains(regexp)) {
89 
90  TObject* object = key->ReadObj();
91 
92  try {
93 
94  TH2& h2 = dynamic_cast<TH2&>(*object);
95 
96  vector<TH1D*> h1(Q.size(), NULL);
97 
98  for (size_t i = 0; i != Q.size(); ++i) {
99 
100  ostringstream os;
101 
102  os << h2.GetName();
103  os << i << "[" << setw(3) << (int) (100.0 * Q[i]) << "%]";
104 
105  DEBUG("Creating 1D histogram: " << os.str() << endl);
106 
107  TAxis* axis = h2.GetXaxis();
108 
109  if (axis->IsVariableBinSize())
110  h1[i] = new TH1D(os.str().c_str(), NULL, axis->GetNbins(), axis->GetXbins()->GetArray());
111  else
112  h1[i] = new TH1D(os.str().c_str(), NULL, axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
113  }
114 
115 
116  for (Int_t i = 1; i <= h2.GetXaxis()->GetNbins(); ++i) {
117 
118  Double_t W = 0.0;
119 
120  for (Int_t j = 0; j <= h2.GetYaxis()->GetNbins() + 1; ++j) {
121  W += h2.GetBinContent(i,j);
122  }
123 
124  if (W != 0.0) {
125 
126  Double_t w = 0.0;
127 
128  if (!reverse) {
129 
130  for (int j = 0, k = 0; j <= h2.GetYaxis()->GetNbins() + 1; ++j) {
131 
132  w += h2.GetBinContent(i,j);
133 
134  for ( ; k != (int) h1.size() && w >= Q[k]*W; ++k) {
135  h1[k]->SetBinContent(i, h2.GetYaxis()->GetBinCenter(j));
136  }
137  }
138 
139  } else {
140 
141  for (int j = h2.GetYaxis()->GetNbins() + 1, k = 0; j >= 0; --j) {
142 
143  w += h2.GetBinContent(i,j);
144 
145  for ( ; k != (int) h1.size() && w >= Q[k]*W; ++k) {
146  h1[k]->SetBinContent(i, h2.GetYaxis()->GetBinCenter(j));
147  }
148  }
149  }
150  }
151  }
152 
153  out.cd();
154 
155  for (vector<TH1D*>::iterator i = h1.begin(); i != h1.end(); ++i) {
156  (*i)->Write();
157  }
158  }
159  catch(exception&) {
160  ERROR("Not available for other objects than 2D histograms." << endl);
161  }
162  }
163  }
164  }
165 
166  out.Write();
167  out.Close();
168 }
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
Definition: JRoot.hh:19
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
string outputFile
#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
#define FATAL(A)
Definition: JMessage.hh:67
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.
int j
Definition: JPolint.hh:666