Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Functions
JConvertToPDF2D.cc File Reference

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

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TH2.h"
#include "TProfile2D.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 2D histograms to PDFs.

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

Possible operations (option -O <operation>:

Definition in file JConvertToPDF2D.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 44 of file JConvertToPDF2D.cc.

45 {
46  using namespace std;
47  using namespace JPP;
48 
49  vector<JRootObjectID> inputFile;
50  string outputFile;
51  string option;
52  int debug;
53 
54  try {
55 
56  JParser<> zap("Auxiliary program to convert 2D histograms to PDFs.");
57 
58  zap['f'] = make_field(inputFile, "<input file>:<object name>");
59  zap['O'] = make_field(option);
60  zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "pdf.root";
61  zap['d'] = make_field(debug) = 1;
62 
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69 
70  vector<TH2*> listOfObjects;
71 
72  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
73 
74  DEBUG("Input: " << *input << endl);
75 
76  TDirectory* dir = getDirectory(*input);
77 
78  if (dir == NULL) {
79  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
80  continue;
81  }
82 
83  const TRegexp regexp(input->getObjectName());
84 
85  TIter iter(dir->GetListOfKeys());
86 
87  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
88 
89  const TString tag(key->GetName());
90 
91  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
92 
93  // option match
94 
95  if (tag.Contains(regexp) && isTObject(key)) {
96 
97  TObject* object = key->ReadObj();
98 
99  TH2* h2 = dynamic_cast<TH2*>(object);
100 
101  try { h2 = dynamic_cast<TProfile2D&>(*object).ProjectionXY(); } catch(exception&) {}
102 
103  if (h2 != NULL) {
104  listOfObjects.push_back(h2);
105  } else {
106  ERROR("Incompatible object " << object->GetName() << endl);
107  }
108  }
109  }
110  }
111 
112  TFile out(outputFile.c_str(), "recreate");
113 
114  for (vector<TH2*>::iterator h2 = listOfObjects.begin(); h2 != listOfObjects.end(); ++h2) {
115 
116  convertToPDF(**h2, option);
117 
118  (*h2)->Write();
119  }
120 
121  out.Write();
122  out.Close();
123 }
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