31{
34
38 bool reverse;
40
41 try {
42
43 JParser<> zap(
"Auxiliary program to extract quantiles from 2D histogram.");
44
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
63
64
65 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
66
67 DEBUG(
"Input: " << *input << endl);
68
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
87
88 if (tag.Contains(regexp) &&
isTObject(key)) {
89
91
92 try {
93
94 TH2& h2 = dynamic_cast<TH2&>(*object);
95
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
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}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Utility class to parse command line options.
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).