Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JConvertToPDF1D.cc File Reference

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

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

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

Possible operations (option -O <operation>:

Definition in file JConvertToPDF1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 36 of file JConvertToPDF1D.cc.

37 {
38  using namespace std;
39  using namespace JPP;
40 
41  vector<JRootObjectID> inputFile;
42  string outputFile;
43  string option;
44  int debug;
45 
46  try {
47 
48  JParser<> zap("Auxiliary program to convert 1D histograms to PDFs.");
49 
50  zap['f'] = make_field(inputFile, "<input file>:<object name>");
51  zap['O'] = make_field(option);
52  zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "pdf.root";
53  zap['d'] = make_field(debug) = 1;
54 
55  zap(argc, argv);
56  }
57  catch(const exception &error) {
58  FATAL(error.what() << endl);
59  }
60 
61 
62  vector<TH1*> 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  TObject* object = key->ReadObj();
90 
91  TH1* h1 = dynamic_cast<TH1*>(object);
92 
93  try { h1 = dynamic_cast<TProfile&>(*object).ProjectionX(); } catch(exception&) {}
94 
95  if (h1 != NULL) {
96  listOfObjects.push_back(h1);
97  } else {
98  ERROR("Incompatible object " << object->GetName() << endl);
99  }
100  }
101  }
102  }
103 
104  TFile out(outputFile.c_str(), "recreate");
105 
106  for (vector<TH1*>::iterator h1 = listOfObjects.begin(); h1 != listOfObjects.end(); ++h1) {
107 
108  convertToPDF(**h1, option);
109 
110  (*h1)->Write();
111  }
112 
113  out.Write();
114  out.Close();
115 }
Utility class to parse command line options.
Definition: JParser.hh:1711
Definition: JRoot.hh:19
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62