29int main(
int argc,
char **argv)
45 JParser<> zap(
"Auxiliary program to zoom 2D histograms.");
47 zap[
'f'] =
make_field(inputFile,
"<input file>:<object name>");
56 catch(
const exception &error) {
57 FATAL(error.what() << endl);
62 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
64 DEBUG(
"Input: " << *input << endl);
66 TDirectory* dir = getDirectory(*input);
69 ERROR(
"File: " << input->getFullFilename() <<
" not opened." << endl);
73 const TRegexp regexp(input->getObjectName());
75 TIter iter(dir->GetListOfKeys());
77 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
79 const TString tag(key->GetName());
81 DEBUG(
"Key: " << tag <<
" match = " << tag.Contains(regexp) << endl);
85 if (tag.Contains(regexp) && isTObject(key)) {
87 TH2D* ha =
dynamic_cast<TH2D*
>(key->ReadObj());
91 const Int_t ix1 = max(ha->GetXaxis()->FindBin(X.getLowerLimit()), 1);
92 const Int_t ix2 = min(ha->GetXaxis()->FindBin(X.getUpperLimit()), ha->GetXaxis()->GetNbins());
93 const Int_t iy1 = max(ha->GetYaxis()->FindBin(Y.getLowerLimit()), 1);
94 const Int_t iy2 = min(ha->GetYaxis()->FindBin(Y.getUpperLimit()), ha->GetYaxis()->GetNbins());
97 <<
"[" << ix1 <<
"," << ix2 <<
"]" <<
" x "
98 <<
"[" << iy1 <<
"," << iy2 <<
"]" << endl);
100 TH2D* hb =
new TH2D(
MAKE_CSTRING(ha->GetName() <<
".zoom"), NULL,
101 ix2 - ix1 + 1, ha->GetXaxis()->GetBinLowEdge(ix1), ha->GetXaxis()->GetBinUpEdge(ix2),
102 iy2 - iy1 + 1, ha->GetYaxis()->GetBinLowEdge(iy1), ha->GetYaxis()->GetBinUpEdge(iy2));
104 if (fabs(ha->GetXaxis()->GetBinWidth(1) - hb->GetXaxis()->GetBinWidth(1)) > precision) {
105 FATAL(
"Binwidth x " <<
FIXED(9,5) << ha->GetXaxis()->GetBinWidth(1) <<
" != " <<
FIXED(9,5) << hb->GetXaxis()->GetBinWidth(1) << endl);
107 if (fabs(ha->GetYaxis()->GetBinWidth(1) - hb->GetYaxis()->GetBinWidth(1)) > precision) {
108 FATAL(
"Binwidth y " <<
FIXED(9,5) << ha->GetYaxis()->GetBinWidth(1) <<
" != " <<
FIXED(9,5) << hb->GetYaxis()->GetBinWidth(1) << endl);
111 for (Int_t ix = ix1; ix <= ix2; ++ix) {
112 for (Int_t iy = iy1; iy <= iy2; ++iy) {
114 hb->SetBinContent(ix - ix1 + 1, iy - iy1 + 1, ha->GetBinContent(ix, iy));
116 if (ha->GetSumw2N()) {
117 hb->SetBinError(ix - ix1 + 1, iy - iy1 + 1, ha->GetBinError(ix, iy));
122 listOfObjects.push_back(hb);
128 if (!listOfObjects.empty()) {
132 for (vector<TObject*>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {