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

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

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TH1D.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 1D histograms.

Author
mdejong

Definition in file JZoom1D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 29 of file JZoom1D.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 double precision;
40 int debug;
41
42 try {
43
44 JParser<> zap("Auxiliary program to zoom 1D histograms.");
45
46 zap['f'] = make_field(inputFile, "<input file>:<object name>");
47 zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "zoom.root";
48 zap['x'] = make_field(X, "x-abscissa range") = JPARSER::initialised();
49 zap['p'] = make_field(precision) = 1.0e-16;
50 zap['d'] = make_field(debug) = 1;
51
52 zap(argc, argv);
53 }
54 catch(const exception &error) {
55 FATAL(error.what() << endl);
56 }
57
58 vector<TObject*> listOfObjects;
59
60 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
61
62 DEBUG("Input: " << *input << endl);
63
64 TDirectory* dir = getDirectory(*input);
65
66 if (dir == NULL) {
67 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
68 continue;
69 }
70
71 const TRegexp regexp(input->getObjectName());
72
73 TIter iter(dir->GetListOfKeys());
74
75 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
76
77 const TString tag(key->GetName());
78
79 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
80
81 // option match
82
83 if (tag.Contains(regexp) && isTObject(key)) {
84
85 TH1D* ha = dynamic_cast<TH1D*>(key->ReadObj());
86
87 if (ha != NULL) {
88
89 const Int_t ix1 = max(ha->GetXaxis()->FindBin(X.getLowerLimit()), 1);
90 const Int_t ix2 = min(ha->GetXaxis()->FindBin(X.getUpperLimit()), ha->GetXaxis()->GetNbins());
91
92 DEBUG("zoom: "
93 << "[" << ix1 << "," << ix2 << "]" << endl);
94
95 TH1D* hb = new TH1D(MAKE_CSTRING(ha->GetName() << ".zoom"), NULL,
96 ix2 - ix1 + 1, ha->GetXaxis()->GetBinLowEdge(ix1), ha->GetXaxis()->GetBinUpEdge(ix2));
97
98 if (fabs(ha->GetXaxis()->GetBinWidth(1) - hb->GetXaxis()->GetBinWidth(1)) > precision) {
99 FATAL("Binwidth x " << FIXED(9,5) << ha->GetXaxis()->GetBinWidth(1) << " != " << FIXED(9,5) << hb->GetXaxis()->GetBinWidth(1) << endl);
100 }
101
102 for (Int_t ix = ix1; ix <= ix2; ++ix) {
103
104 hb->SetBinContent(ix - ix1 + 1, ha->GetBinContent(ix));
105
106 if (ha->GetSumw2N()) {
107 hb->SetBinError(ix - ix1 + 1, ha->GetBinError(ix));
108 }
109 }
110
111 listOfObjects.push_back(hb);
112 }
113 }
114 }
115 }
116
117 if (!listOfObjects.empty()) {
118
119 TFile out(outputFile.c_str(), "recreate");
120
121 for (vector<TObject*>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
122 (*i)->Write();
123 }
124
125 out.Write();
126 out.Close();
127 }
128}
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