Jpp  16.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

int main ( int  argc,
char **  argv 
)

Definition at line 42 of file JConvertToPDF2D.cc.

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