Jpp test-rotations-old-533-g2bdbdb559
the software that should make you happy
Loading...
Searching...
No Matches
JZoom3D.cc File Reference

Auxiliary program to zoom 3D histograms. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TH3D.h"
#include "TString.h"
#include "TRegexp.h"
#include "JTools/JRange.hh"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to zoom 3D histograms.

Author
mdejong

Definition in file JZoom3D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 29 of file JZoom3D.cc.

30{
31 using namespace std;
32 using namespace JPP;
33
34 typedef JRange<double> JRange_t;
35
36 vector<JRootObjectID> inputFile;
37 string outputFile;
38 JRange_t X;
39 JRange_t Y;
40 JRange_t Z;
41 double precision;
42 int debug;
43
44 try {
45
46 JParser<> zap("Auxiliary program to zoom 3D histograms.");
47
48 zap['f'] = make_field(inputFile, "<input file>:<object name>");
49 zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "zoom.root";
50 zap['x'] = make_field(X, "x-abscissa range") = JPARSER::initialised();
51 zap['y'] = make_field(Y, "y-abscissa range") = JPARSER::initialised();
52 zap['z'] = make_field(Z, "z-abscissa range") = JPARSER::initialised();
53 zap['p'] = make_field(precision) = 1.0e-16;
54 zap['d'] = make_field(debug) = 1;
55
56 zap(argc, argv);
57 }
58 catch(const exception &error) {
59 FATAL(error.what() << endl);
60 }
61
62 vector<TObject*> listOfObjects;
63
64 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
65
66 DEBUG("Input: " << *input << endl);
67
68 TDirectory* dir = getDirectory(*input);
69
70 if (dir == NULL) {
71 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
72 continue;
73 }
74
75 const TRegexp regexp(input->getObjectName());
76
77 TIter iter(dir->GetListOfKeys());
78
79 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
80
81 const TString tag(key->GetName());
82
83 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
84
85 // option match
86
87 if (tag.Contains(regexp) && isTObject(key)) {
88
89 TH3D* ha = dynamic_cast<TH3D*>(key->ReadObj());
90
91 if (ha != NULL) {
92
93 const Int_t ix1 = max(ha->GetXaxis()->FindBin(X.getLowerLimit()), 1);
94 const Int_t ix2 = min(ha->GetXaxis()->FindBin(X.getUpperLimit()), ha->GetXaxis()->GetNbins());
95 const Int_t iy1 = max(ha->GetYaxis()->FindBin(Y.getLowerLimit()), 1);
96 const Int_t iy2 = min(ha->GetYaxis()->FindBin(Y.getUpperLimit()), ha->GetYaxis()->GetNbins());
97 const Int_t iz1 = max(ha->GetZaxis()->FindBin(Z.getLowerLimit()), 1);
98 const Int_t iz2 = min(ha->GetZaxis()->FindBin(Z.getUpperLimit()), ha->GetZaxis()->GetNbins());
99
100 DEBUG("zoom: "
101 << "[" << ix1 << "," << ix2 << "]" << " x "
102 << "[" << iy1 << "," << iy2 << "]" << " x "
103 << "[" << iz1 << "," << iz2 << "]" << endl);
104
105 TH3D* hb = new TH3D(MAKE_CSTRING(ha->GetName() << ".zoom"), NULL,
106 ix2 - ix1 + 1, ha->GetXaxis()->GetBinLowEdge(ix1), ha->GetXaxis()->GetBinUpEdge(ix2),
107 iy2 - iy1 + 1, ha->GetYaxis()->GetBinLowEdge(iy1), ha->GetYaxis()->GetBinUpEdge(iy2),
108 iz2 - iz1 + 1, ha->GetZaxis()->GetBinLowEdge(iz1), ha->GetZaxis()->GetBinUpEdge(iz2));
109
110 if (fabs(ha->GetXaxis()->GetBinWidth(1) - hb->GetXaxis()->GetBinWidth(1)) > precision) {
111 FATAL("Binwidth x " << FIXED(9,5) << ha->GetXaxis()->GetBinWidth(1) << " != " << FIXED(9,5) << hb->GetXaxis()->GetBinWidth(1) << endl);
112 }
113 if (fabs(ha->GetYaxis()->GetBinWidth(1) - hb->GetYaxis()->GetBinWidth(1)) > precision) {
114 FATAL("Binwidth y " << FIXED(9,5) << ha->GetYaxis()->GetBinWidth(1) << " != " << FIXED(9,5) << hb->GetYaxis()->GetBinWidth(1) << endl);
115 }
116 if (fabs(ha->GetZaxis()->GetBinWidth(1) - hb->GetZaxis()->GetBinWidth(1)) > precision) {
117 FATAL("Binwidth z " << FIXED(9,5) << ha->GetZaxis()->GetBinWidth(1) << " != " << FIXED(9,5) << hb->GetZaxis()->GetBinWidth(1) << endl);
118 }
119
120 for (Int_t ix = ix1; ix <= ix2; ++ix) {
121 for (Int_t iy = iy1; iy <= iy2; ++iy) {
122 for (Int_t iz = iz1; iz <= iz2; ++iz) {
123
124 hb->SetBinContent(ix - ix1 + 1, iy - iy1 + 1, iz - iz1 + 1, ha->GetBinContent(ix, iy, iz));
125
126 if (ha->GetSumw2N()) {
127 hb->SetBinError(ix - ix1 + 1, iy - iy1 + 1, iz - iz1 + 1, ha->GetBinError(ix, iy, iz));
128 }
129 }
130 }
131 }
132
133 listOfObjects.push_back(hb);
134 }
135 }
136 }
137 }
138
139 if (!listOfObjects.empty()) {
140
141 TFile out(outputFile.c_str(), "recreate");
142
143 for (vector<TObject*>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
144 (*i)->Write();
145 }
146
147 out.Write();
148 out.Close();
149 }
150}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
Utility class to parse command line options.
Definition JParser.hh:1698
Range of values.
Definition JRange.hh:42
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.
Definition JManip.hh:448
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68