Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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>:

  • N
    make PDF;
  • W
    divide bin contents by width of bin;
  • E
    apply operation also to bin errors;
    Author
    mdejong

Definition in file JConvertToPDF1D.cc.

Function Documentation

◆ main()

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}
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:72
#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).