Jpp  debug
the software that should make you happy
JConvertToPDF3D.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TKey.h"
10 #include "TH3.h"
11 #include "TString.h"
12 #include "TRegexp.h"
13 
14 #include "JGizmo/JRootObjectID.hh"
15 #include "JGizmo/JGizmoToolkit.hh"
16 
17 #include "Jeep/JParser.hh"
18 #include "Jeep/JMessage.hh"
19 
20 
21 /**
22  * \file
23  * Auxiliary program to convert 3D histograms to PDFs.
24  * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
25  *
26  * Possible operations (option <tt>-O <operation></tt>:
27  * - NXYZ\n
28  * make 3D PDF;
29  * - NXY\n
30  * make 2D PDF along x- and y-axis;
31  * - NXZ\n
32  * make 2D PDF along x- and z-axis;
33  * - NYZ\n
34  * make 2D PDF along y- and z-axis;
35  * - NX\n
36  * make PDF along x-axis;
37  * - NY\n
38  * make PDF along y-axis;
39  * - NZ\n
40  * make PDF along z-axis;
41  * - WXYZ\n
42  * divide bin contents by width of x-, y- and z-bin;
43  * - WXY\n
44  * divide bin contents by width of x- and y-bin;
45  * - WXZ\n
46  * divide bin contents by width of x- and z-bin;
47  * - WYZ\n
48  * divide bin contents by width of y- and z-bin;
49  * - WX\n
50  * divide bin contents by width of x-bin;
51  * - WY\n
52  * divide bin contents by width of y-bin;
53  * - WZ\n
54  * divide bin contents by width of z-bin;
55  * - E\n
56  * apply operation also to bin errors;
57  * \author mdejong
58  */
59 int main(int argc, char **argv)
60 {
61  using namespace std;
62  using namespace JPP;
63 
64  vector<JRootObjectID> inputFile;
65  string outputFile;
66  string option;
67  int debug;
68 
69  try {
70 
71  JParser<> zap("Auxiliary program to convert 2D histograms to PDFs.");
72 
73  zap['f'] = make_field(inputFile, "<input file>:<object name>");
74  zap['O'] = make_field(option);
75  zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "pdf.root";
76  zap['d'] = make_field(debug) = 1;
77 
78  zap(argc, argv);
79  }
80  catch(const exception &error) {
81  FATAL(error.what() << endl);
82  }
83 
84 
85  vector<TH3*> listOfObjects;
86 
87  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
88 
89  DEBUG("Input: " << *input << endl);
90 
91  TDirectory* dir = getDirectory(*input);
92 
93  if (dir == NULL) {
94  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
95  continue;
96  }
97 
98  const TRegexp regexp(input->getObjectName());
99 
100  TIter iter(dir->GetListOfKeys());
101 
102  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
103 
104  const TString tag(key->GetName());
105 
106  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
107 
108  // option match
109 
110  if (tag.Contains(regexp) && isTObject(key)) {
111 
112  TObject* object = key->ReadObj();
113 
114  TH3* h3 = dynamic_cast<TH3*>(object);
115 
116  if (h3 != NULL) {
117  listOfObjects.push_back(h3);
118  } else {
119  ERROR("Incompatible object " << object->GetName() << endl);
120  }
121  }
122  }
123  }
124 
125  TFile out(outputFile.c_str(), "recreate");
126 
127  for (vector<TH3*>::iterator h3 = listOfObjects.begin(); h3 != listOfObjects.end(); ++h3) {
128 
129  convertToPDF(**h3, option);
130 
131  (*h3)->Write();
132  }
133 
134  out.Write();
135  out.Close();
136 }
int main(int argc, char **argv)
string outputFile
General purpose messaging.
#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:69
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Utility class to parse command line options.
Definition: JParser.hh:1714
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
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).
Definition: JSTDTypes.hh:14
Definition: JRoot.hh:19