70 JParser<> zap(
"Auxiliary program for histogram operations.");
72 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
87 <<
"\n\"" << JOpera::SAME_AS_OPERATION() <<
"\" -> same as operation; or"
88 <<
"\n\"" << JOpera::SAME_AS_INPUT() <<
"\" -> same as input; else"
89 <<
"\nas specified")) = JOpera::SAME_AS_OPERATION();
94 catch(
const exception &error) {
95 FATAL(error.what() << endl);
103 DEBUG(
"Input: " << *input << endl);
108 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
112 const TRegexp regexp(input->getObjectName());
114 TIter iter(dir->GetListOfKeys());
116 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
118 const TString tag(key->GetName());
120 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
124 if (tag.Contains(regexp)) {
128 if (dynamic_cast<TH2*>(p) == NULL) {
129 FATAL(
"Object " << p->GetName() <<
" not compatible with histogram operations." << endl);
132 listOfObjects.push_back(p);
140 if (listOfObjects.size() == 0) {
142 FATAL(
"Number of histograms " << listOfObjects.size() <<
" = 0." << endl);
144 }
else if (listOfObjects.size() == 1 && (opera == JOpera::Add() ||
145 opera == JOpera::Subtract() ||
146 opera == JOpera::Multiply() ||
147 opera == JOpera::Divide() ||
148 opera == JOpera::Replace())) {
152 TH2*
h1 =
dynamic_cast<TH2*
>(listOfObjects[0]);
153 TF2* f1 =
dynamic_cast<TF2*
>(h1->GetListOfFunctions()->First());
156 FATAL(h1->GetName() <<
" has no associated function." << endl);
159 NOTICE(h1->GetName() <<
' ' << opera <<
' ' << f1->GetName() << endl);
161 if (
name == JOpera::SAME_AS_OPERATION())
162 h3 = (TH2*) h1->Clone(opera.c_str());
163 else if (
name == JOpera::SAME_AS_INPUT())
164 h3 = (TH2*) h1->Clone(h1->GetName());
166 h3 = (TH2*) h1->Clone(
name.c_str());
168 if (opera == JOpera::Add()) {
172 }
else if (opera == JOpera::Subtract()) {
176 }
else if (opera == JOpera::Multiply()) {
180 }
else if (opera == JOpera::Divide()) {
184 }
else if (opera == JOpera::Replace()) {
187 h3->Fill(0.0, 0.0, 0.0);
191 }
else if (listOfObjects.size() == 2) {
193 TH2* h1 =
dynamic_cast<TH2*
>(listOfObjects[0]);
194 TH2* h2 =
dynamic_cast<TH2*
>(listOfObjects[1]);
196 NOTICE(h1->GetName() <<
' ' << opera <<
' ' << h2->GetName() << endl);
198 if (
name == JOpera::SAME_AS_OPERATION())
199 h3 = (TH2*) h1->Clone(opera.c_str());
200 else if (
name == JOpera::SAME_AS_INPUT())
201 h3 = (TH2*) h1->Clone(h1->GetName());
203 h3 = (TH2*) h1->Clone(
name.c_str());
205 if (opera == JOpera::Add()) {
207 h3->Add (h1, h2, +1.0, +1.0);
209 }
else if (opera == JOpera::Subtract()) {
211 h3->Add (h1, h2, +1.0, -1.0);
213 }
else if (opera == JOpera::Multiply()) {
215 h3->Multiply(h1, h2, +1.0, +1.0);
217 }
else if (opera == JOpera::Divide()) {
219 h3->Divide (h1, h2, +1.0, +1.0);
221 }
else if (opera == JOpera::add() ||
222 opera == JOpera::subtract() ||
223 opera == JOpera::multiply() ||
224 opera == JOpera::divide()) {
226 for (Int_t i1 = 1; i1 <= h1->GetNbinsX(); ++i1) {
227 for (Int_t i2 = 1; i2 <= h1->GetNbinsY(); ++i2) {
229 const Double_t x = h1->GetXaxis()->GetBinCenter(i1);
230 const Double_t y = h1->GetYaxis()->GetBinCenter(i2);
232 const Int_t j1 = h2->GetXaxis()->FindBin(x);
233 const Int_t j2 = h2->GetYaxis()->FindBin(y);
235 const Double_t w1 = h1->GetBinContent(i1,i2);
236 const Double_t w2 = h2->GetBinContent(j1,j2);
240 if (opera == JOpera::add()) {
244 }
else if (opera == JOpera::subtract()) {
248 }
else if (opera == JOpera::multiply()) {
252 }
else if (opera == JOpera::divide()) {
255 ERROR(
"Bin " << h2->GetName() <<
"[" << j1 <<
"," << j2 <<
"] empty." << endl);
262 h3->SetBinContent(i1, i2, w3);
266 }
else if (opera == JOpera::efficiency() ||
268 opera == JOpera::sqrt()) {
270 for (Int_t i1 = 1; i1 <= h1->GetNbinsX(); ++i1) {
271 for (Int_t i2 = 1; i2 <= h1->GetNbinsY(); ++i2) {
273 const Double_t y1 = h1->GetBinContent(i1,i2);
274 const Double_t y2 = h2->GetBinContent(i1,i2);
276 Double_t w1 = h1->GetBinError(i1,i2);
277 Double_t w2 = h2->GetBinError(i1,i2);
282 if (opera == JOpera::efficiency()) {
285 ERROR(
"Bin " << h2->GetName() <<
"[" << i1 <<
"," << i2 <<
"] empty." << endl);
297 w3 = y3 * fabs(y3 - 1.0) * sqrt(w1*w1 + w2*w2);
302 w3 = sqrt(w1*w1 + w2*w2);
309 }
else if (opera == JOpera::sqrt()) {
311 y3 = (y1+y2) * (y1-y2);
321 h3->SetBinContent(i1, i2, y3);
322 h3->SetBinError (i1, i2, w3);
327 }
else if (opera == JOpera::Add() ||
328 opera == JOpera::Multiply()) {
332 TH2* h1 =
dynamic_cast<TH2*
>(*i);
334 NOTICE(h1->GetName() <<
' ' << opera << endl);
338 if (
name == JOpera::SAME_AS_OPERATION())
339 h3 = (TH2*) h1->Clone(opera.c_str());
340 else if (
name == JOpera::SAME_AS_INPUT())
341 h3 = (TH2*) h1->Clone(h1->GetName());
343 h3 = (TH2*) h1->Clone(
name.c_str());
347 if (opera == JOpera::Add()) {
349 h3->Add (h3, h1, +1.0, +1.0);
351 }
else if (opera == JOpera::Multiply()) {
353 h3->Multiply(h3, h1, +1.0, +1.0);
360 FATAL(
"Incompatible number of histograms " << listOfObjects.size() <<
" with option " << opera << endl);
Utility class to parse command line options.
then for HISTOGRAM in h0 h1
#define MAKE_STRING(A)
Make string.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
#define DEBUG(A)
Message macros.