Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
software
JGizmo
JConvertToPDF2D.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
#include <vector>
6
7
#include "TROOT.h"
8
#include "TFile.h"
9
#include "TKey.h"
10
#include "TH2.h"
11
#include "TProfile2D.h"
12
#include "TString.h"
13
#include "TRegexp.h"
14
15
#include "
JGizmo/JRootObjectID.hh
"
16
#include "
JGizmo/JGizmoToolkit.hh
"
17
18
#include "
Jeep/JParser.hh
"
19
#include "
Jeep/JMessage.hh
"
20
21
22
/**
23
* \file
24
* Auxiliary program to convert 2D histograms to PDFs.
25
* The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
26
*
27
* Possible operations (option <tt>-O <operation></tt>:
28
* - NXY\n
29
* make 2D PDF;
30
* - NX\n
31
* make PDF along x-axis;
32
* - NY\n
33
* make PDF along y-axis;
34
* - WX\n
35
* divide bin contents by width of x-bin;
36
* - WY\n
37
* divide bin contents by width of y-bin;
38
* - E\n
39
* apply operation also to bin errors;
40
* \author mdejong
41
*/
42
int
main
(
int
argc,
char
**argv)
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)) {
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
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1500
TObject
Definition:
JRoot.hh:19
outputFile
string outputFile
Definition:
JDAQTimesliceSelector.cc:37
std::vector
Definition:
JSTDTypes.hh:12
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1961
JGIZMO::convertToPDF
void convertToPDF(TH1 &h1, const std::string &option="NW", const double factor=1.0)
Convert 1D histogram to PDF.
Definition:
JGizmoToolkit.hh:677
ERROR
#define ERROR(A)
Definition:
JMessage.hh:66
JGizmoToolkit.hh
debug
int debug
debug level
Definition:
JSirene.cc:63
JRootObjectID.hh
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JGIZMO::getDirectory
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Definition:
JGizmoToolkit.hh:129
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5