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