Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JQuantiles1D.cc File Reference

Auxiliary program to print quantiles from 1D histogram. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TObject.h"
#include "TKey.h"
#include "TH1D.h"
#include "TString.h"
#include "TRegexp.h"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JPrint.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 print quantiles from 1D histogram.


The option -f corresponds to <file name>:<object name>.
The computation of the quantiles includes under and overflows.

Author
mdejong

Definition in file JQuantiles1D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 29 of file JQuantiles1D.cc.

30{
31 using namespace std;
32 using namespace JPP;
33
34 vector<JRootObjectID> inputFile;
36 bool reverse;
37 int debug;
38
39 try {
40
41 JParser<> zap("Auxiliary program to print quantiles from 1D histogram.");
42
43 zap['f'] = make_field(inputFile);
44 zap['Q'] = make_field(Q);
45 zap['R'] = make_field(reverse);
46 zap['d'] = make_field(debug) = 0;
47
48 zap(argc, argv);
49 }
50 catch(const exception &error) {
51 FATAL(error.what() << endl);
52 }
53
54
55 if (Q.empty()) {
56 FATAL("No quantiles." << endl);
57 }
58
59
60 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
61
62 DEBUG("Input: " << *input << endl);
63
64 TDirectory* dir = getDirectory(*input);
65
66 if (dir == NULL) {
67 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
68 continue;
69 }
70
71 const TRegexp regexp(input->getObjectName());
72
73 TIter iter(dir->GetListOfKeys());
74
75 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
76
77 const TString tag(key->GetName());
78
79 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
80
81 // option match
82
83 if (tag.Contains(regexp) && isTObject(key)) {
84
85 TObject* object = key->ReadObj();
86
87 try {
88
89 TH1& h1 = dynamic_cast<TH1&>(*object);
90
91 Double_t W = 0.0;
92
93 for (Int_t ix = 0; ix <= h1.GetXaxis()->GetNbins() + 1; ++ix) {
94 W += h1.GetBinContent(ix);
95 }
96
97 if (W != 0.0) {
98
99 Double_t w = 0.0;
100
101 if (!reverse) {
102
103 for (int ix = 0, k = 0; ix <= h1.GetXaxis()->GetNbins() + 1; ++ix) {
104
105 w += h1.GetBinContent(ix);
106
107 for ( ; k != (int) Q.size() && w >= Q[k]*W; ++k) {
108 cout << h1.GetName() << ' ' << FIXED(4,2) << Q[k] << ' ' << FIXED(20,10) << h1.GetXaxis()->GetBinCenter(ix) << endl;
109 }
110
111 }
112
113 } else {
114
115 for (int ix = h1.GetXaxis()->GetNbins() + 1, k = 0; ix >= 0; --ix) {
116
117 w += h1.GetBinContent(ix);
118
119 for ( ; k != (int) Q.size() && w >= Q[k]*W; ++k) {
120 cout << h1.GetName() << ' ' << FIXED(4,2) << Q[k] << ' ' << FIXED(20,10) << h1.GetXaxis()->GetBinCenter(ix) << endl;
121 }
122 }
123 }
124 }
125 }
126 catch(exception&) {
127 ERROR("Not available for other objects than 1D histograms." << endl);
128 }
129 }
130 }
131 }
132}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448