Jpp
15.0.0-rc.2
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
software
JGizmo
JProject3D.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
#include <vector>
6
#include <cmath>
7
8
#include "TROOT.h"
9
#include "TFile.h"
10
#include "TKey.h"
11
#include "TH3.h"
12
#include "TProfile3D.h"
13
#include "TString.h"
14
#include "TRegexp.h"
15
16
#include "
JGizmo/JRootObjectID.hh
"
17
#include "
JGizmo/JGizmoToolkit.hh
"
18
19
#include "
Jeep/JParser.hh
"
20
#include "
Jeep/JMessage.hh
"
21
22
23
/**
24
* \file
25
* Auxiliary program to project 3D histograms.
26
* \author mdejong
27
*/
28
int
main
(
int
argc,
char
**argv)
29
{
30
using namespace
std;
31
using namespace
JPP;
32
33
vector<JRootObjectID>
inputFile;
34
string
outputFile
;
35
char
project;
36
int
debug
;
37
38
try
{
39
40
JParser<>
zap(
"Auxiliary program to project 3D histograms."
);
41
42
zap[
'f'
] =
make_field
(inputFile,
"<input file>:<object name>"
);
43
zap[
'P'
] =
make_field
(project,
"projection"
) =
' '
,
'x'
,
'X'
,
'y'
,
'Y'
,
'z'
,
'Z'
;
44
zap[
'o'
] =
make_field
(
outputFile
,
"ROOT file with histogram(s)"
) =
"project.root"
;
45
zap[
'd'
] =
make_field
(
debug
) = 1;
46
47
zap(argc, argv);
48
}
49
catch
(
const
exception &error) {
50
FATAL
(error.what() << endl);
51
}
52
53
const
bool
px = (project ==
'x'
|| project ==
'X'
);
// projection on x-axis
54
const
bool
py = (project ==
'y'
|| project ==
'Y'
);
// projection on y-axis
55
const
bool
pz = (project ==
'z'
|| project ==
'Z'
);
// projection on z-axis
56
57
if
((px ? 1 : 0) +
58
(py ? 1 : 0) +
59
(pz ? 1 : 0) != 1) {
60
FATAL
(
"Invalid operation: "
61
<< (px ?
""
:
"no"
) <<
" X projection "
<<
" and "
62
<< (py ?
""
:
"no"
) <<
" Y projection "
<<
" and "
63
<< (pz ?
""
:
"no"
) <<
" Z projection "
<< endl);
64
}
65
66
vector<TObject*>
listOfObjects;
67
68
for
(
vector<JRootObjectID>::const_iterator
input = inputFile.begin(); input != inputFile.end(); ++input) {
69
70
DEBUG
(
"Input: "
<< *input << endl);
71
72
TDirectory* dir =
getDirectory
(*input);
73
74
if
(dir == NULL) {
75
ERROR
(
"File: "
<< input->getFullFilename() <<
" not opened."
<< endl);
76
continue
;
77
}
78
79
const
TRegexp regexp(input->getObjectName());
80
81
TIter iter(dir->GetListOfKeys());
82
83
for
(TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
84
85
const
TString tag(key->GetName());
86
87
DEBUG
(
"Key: "
<< tag <<
" match = "
<< tag.Contains(regexp) << endl);
88
89
// option match
90
91
if
(tag.Contains(regexp)) {
92
93
TH3* h3 =
dynamic_cast<
TH3*
>
(key->ReadObj());
94
95
if
(h3 != NULL) {
96
97
if
(px)
98
listOfObjects.push_back(h3->ProjectionX(
MAKE_CSTRING
(h3->GetName() <<
"_px"
)));
99
else
if
(py)
100
listOfObjects.push_back(h3->ProjectionY(
MAKE_CSTRING
(h3->GetName() <<
"_py"
)));
101
else
if
(pz)
102
listOfObjects.push_back(h3->ProjectionZ(
MAKE_CSTRING
(h3->GetName() <<
"_pz"
)));
103
}
104
}
105
}
106
}
107
108
if
(!listOfObjects.empty()) {
109
110
TFile out(
outputFile
.c_str(),
"recreate"
);
111
112
for
(
vector<TObject*>::const_iterator
i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
113
(*i)->Write();
114
}
115
116
out.Write();
117
out.Close();
118
}
119
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1500
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
MAKE_CSTRING
#define MAKE_CSTRING(A)
Make C-string.
Definition:
JPrint.hh:151
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
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.
DEBUG
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
Definition:
JCalibratePMT.sh:21
JGIZMO::getDirectory
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
Definition:
JGizmoToolkit.hh:131
Generated by
1.8.5