Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Functions
JConvertToPDF3D.cc File Reference

Auxiliary program to convert 3D histograms to PDFs. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TH3.h"
#include "TString.h"
#include "TRegexp.h"
#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 convert 3D histograms to PDFs.

The option -f corresponds to <file name>:<object name>.

Possible operations (option -O <operation>:

Definition in file JConvertToPDF3D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 59 of file JConvertToPDF3D.cc.

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 }
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:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Utility class to parse command line options.
Definition: JParser.hh:1698
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