32{
35
40
41 try {
42
43 JParser<> zap(
"Auxiliary program to rebin ROOT histograms.");
44
45 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
49
50 zap(argc, argv);
51 }
52 catch(const exception &error) {
53 FATAL(error.what() << endl);
54 }
55
56
57 if (X.empty()) {
58 FATAL(
"No abscissa values." << endl);
59 }
60
62
63 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
64
65 DEBUG(
"Input: " << *input << endl);
66
68
69 if (dir == NULL) {
70 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
71 continue;
72 }
73
74 const TRegexp regexp(input->getObjectName());
75
76 TIter iter(dir->GetListOfKeys());
77
78 for (TKey* key; (
key = (TKey*) iter.Next()) != NULL; ) {
79
80 const TString tag(
key->GetName());
81
82 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
83
84
85
86 if (tag.Contains(regexp) &&
isTObject(key)) {
87
89
90 try {
91
92 TH1D& h0 = dynamic_cast<TH1D&>(*object);
93
94 TH1D h1(h0.GetName(), NULL, X.size() - 1, X.data());
95
96 for (int ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
97
98 const Double_t
xmin = h0.GetXaxis()->FindBin(h1.GetXaxis()->GetBinLowEdge(ix));
99 const Double_t
xmax = h0.GetXaxis()->FindBin(h1.GetXaxis()->GetBinUpEdge (ix));
100
101 const Int_t imin =
xmin;
102 const Int_t imax =
xmax;
103
104 if (imax != imin) {
105
106 Double_t Y = 0.0;
107 Double_t Z = 0.0;
108 Double_t W = 0.0;
109
110 for (Int_t i = imin; i != imax; ++i) {
111
112 const Double_t
y = h0.GetBinContent(i);
113 const Double_t z = h0.GetBinWidth (i);
114 const Double_t w = h0.GetBinError (i);
115
117 Z += z;
118 W += w*z * w*z;
119 }
120
121 Y = Y / Z;
122 W = sqrt(W) / Z;
123
124 h1.SetBinContent(ix, Y);
125 h1.SetBinError (ix, W);
126
127 } else {
128
129 ERROR(
"Invalid bin " << ix <<
" [" <<
FIXED(9,3) << xmin <<
"," <<
FIXED(9,3) << xmax <<
"]" <<
" -> " << imin <<
' ' << imax << endl);
130 }
131 }
132
133 out.WriteTObject(&h1);
134 }
135 catch(exception&) {}
136 }
137 }
138 }
139
140 out.Write();
141 out.Close();
142}
#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).
Auxiliary data structure for floating point format specification.