BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnPadGenerator.cxx
Go to the documentation of this file.
1
2
#include "
BmnPadGenerator.h
"
3
4
#include <fairlogger/Logger.h>
5
6
void
BmnPadGenerator::LoadPTFrom
(
string
FileName)
7
{
8
LOGF(info,
"LoadPTFrom start"
);
9
std::ifstream in(FileName, std::ios::binary);
10
if
(!in) {
11
LOG(error) <<
"failed to open file"
;
12
return
;
13
}
14
LOG(debug) << in.rdbuf();
15
try
{
16
pt::read_json(FileName,
_TreeScheme
);
17
}
catch
(pt::ptree_error& exc) {
18
LOG(error) <<
"LoadPTFrom exception: "
<< exc.what() << std::endl;
19
return
;
20
}
21
_pad
=
GeneratePadBranch
(
_TreeScheme
);
22
LOGF(info,
"pad tree generated"
);
23
return
;
24
}
25
26
PadInfo
*
BmnPadGenerator::GeneratePadNode
(pt::ptree& propTree)
27
{
28
PadInfo
* info =
nullptr
;
29
try
{
30
boost::optional<string> clOpt = propTree.get_optional<
string
>(
"Class"
);
31
if
(!clOpt)
32
return
info;
33
string
clName = clOpt.get();
34
TClass
* cl =
TClass::GetClass
(clName.c_str());
35
printf(
"cl name %s\n"
, cl->
GetName
());
36
ROOT::NewFunc_t
histNew = cl->
GetNew
();
37
string
name = propTree.get<
string
>(
"Name"
);
38
string
title = propTree.get<
string
>(
"Title"
);
39
string
variable = propTree.get<
string
>(
"Variable"
);
40
// string selection = propTree.get<string>("Selection");
41
printf(
"Hist name %s\n"
, name.c_str());
42
vector<float> dimVec;
43
boost::optional<pt::ptree>
dim
= propTree.get_child(
"Dimensions"
);
44
if
(
dim
) {
45
for
(
auto
v
=
dim
.get().begin();
v
!=
dim
.get().end();
v
++) {
46
dimVec.push_back(stof((*v).second.data()));
47
printf(
"%f\n"
, dimVec.back());
48
}
49
}
else
50
dimVec.resize(3, 0);
// default 1Dim histogram
51
info =
new
PadInfo
();
52
info->
name
= name;
53
info->
variable
= variable;
54
boost::optional<string> opt = propTree.get_optional<
string
>(
"Options"
);
55
if
(opt) {
56
info->
opt
= opt.get();
57
printf(
"info opt %s\n"
, info->
opt
.c_str());
58
}
59
boost::optional<string> sel = propTree.get_optional<
string
>(
"Selection"
);
60
if
(sel) {
61
info->
selection
= sel.get();
62
}
63
TH1
* h =
nullptr
;
64
switch
(dimVec.size()) {
65
case
3:
66
h =
static_cast<
TH1
*
>
(histNew(0));
67
h->
SetBins
(dimVec[0], dimVec[1], dimVec[2]);
68
h->
SetName
(name.c_str());
69
h->
SetTitle
(title.c_str());
70
_HM
->Add(name, h);
71
info->
current
= h;
//_HM->H1(name);
72
break
;
73
case
6:
74
h =
static_cast<
TH2
*
>
(histNew(0));
75
h->
SetBins
(dimVec[0], dimVec[1], dimVec[2], dimVec[3], dimVec[4], dimVec[5]);
76
h->
SetName
(name.c_str());
77
h->
SetTitle
(title.c_str());
78
_HM
->Add(name, h);
79
info->
current
= h;
//_HM->H2(name);
80
break
;
81
case
9:
82
h =
static_cast<
TH3
*
>
(histNew(0));
83
h->
SetBins
(dimVec[0], dimVec[1], dimVec[2], dimVec[3], dimVec[4], dimVec[5], dimVec[6], dimVec[7],
84
dimVec[8]);
85
h->
SetName
(name.c_str());
86
h->
SetTitle
(title.c_str());
87
_HM
->Add(name, h);
88
info->
current
= h;
89
break
;
90
default
:
91
throw
string(
"Wrong dimensions!"
);
92
break
;
93
}
94
// boost::optional<pt::ptree> axes = propTree.get_child("Dimensions");
95
info->
temp
=
static_cast<
TH1
*
>
(info->
current
->
Clone
((name +
"_temp"
).c_str()));
96
}
catch
(std::exception& ex) {
97
printf(
"Exception for node: %s\n"
, ex.what());
98
if
(info) {
99
delete
info;
100
info =
nullptr
;
101
}
102
}
103
return
info;
104
}
105
106
BmnPadBranch
*
BmnPadGenerator::GeneratePadBranch
(pt::ptree& propTree)
107
{
108
BmnPadBranch
* branch =
nullptr
;
109
try
{
110
branch =
new
BmnPadBranch
();
111
boost::optional<uint32_t> optDivX = propTree.get_optional<uint32_t>(
"DivX"
);
112
boost::optional<uint32_t> optDivY = propTree.get_optional<uint32_t>(
"DivY"
);
113
uint32_t divX = optDivX ? *optDivX : 1;
114
uint32_t divY = optDivY ? *optDivY : 1;
115
branch->
SetDivXY
(divX, divY);
116
printf(
"%d : %d \n"
, divX, divY);
117
118
if
((divX == 1) && (divY == 1)) {
119
PadInfo
* info =
GeneratePadNode
(propTree);
120
branch->
SetPadInfo
(info);
121
}
else
{
122
// string name = propTree.get<string>("Name");
123
// string title = propTree.get<string>("Title");
124
// printf("title %s\n", title.c_str());
125
126
boost::optional<pt::ptree&> pads = propTree.get_child_optional(
"Pads"
);
127
if
(pads) {
128
for
(
auto
&
v
: pads.get()) {
129
printf(
"Parsing pad content: %s\n"
,
v
.second.data().c_str());
130
BmnPadBranch
* b =
GeneratePadBranch
(
v
.second);
131
branch->
AddBranch
(b);
132
}
133
}
134
}
135
136
}
catch
(std::exception& ex) {
137
printf(
"Exception for branch: %s\n"
, ex.what());
138
if
(branch) {
139
delete
branch;
140
branch =
nullptr
;
141
}
142
}
143
return
branch;
144
}
145
146
void
BmnPadGenerator::PadTree2Canvas
(
BmnPadBranch
* br,
TVirtualPad
* pad)
147
{
148
if
((!br) || (!pad)) {
149
printf(
"No pad data! Skipping.\n"
);
150
return
;
151
}
152
if
(
PadInfo
* info = br->
GetPadInfo
()) {
153
info->padPtr = pad;
154
}
else
{
155
vector<BmnPadBranch*>& bvec = br->
GetBranchesRef
();
156
pad->
Divide
(br->
GetDivX
(), br->
GetDivY
());
157
for
(
size_t
i
= 0;
i
< std::min((
size_t
)(br->
GetDivX
() * br->
GetDivY
()), bvec.size());
i
++) {
158
TVirtualPad
* innerPad = pad->
cd
(
i
+ 1);
159
BmnPadBranch
* innerBr = bvec[
i
];
160
PadTree2Canvas
(innerBr, innerPad);
161
}
162
}
163
return
;
164
}
v
__m128 v
Definition
P4_F32vec4.h:1
i
int i
Definition
P4_F32vec4.h:22
BmnPadGenerator.h
BmnPadBranch
Node of pad tree.
Definition
BmnPadBranch.h:15
BmnPadBranch::GetBranchesRef
vector< BmnPadBranch * > & GetBranchesRef()
Definition
BmnPadBranch.h:34
BmnPadBranch::SetPadInfo
void SetPadInfo(PadInfo *p)
Definition
BmnPadBranch.h:45
BmnPadBranch::AddBranch
void AddBranch(BmnPadBranch *b)
Definition
BmnPadBranch.h:47
BmnPadBranch::SetDivXY
void SetDivXY(uint32_t x, uint32_t y)
Definition
BmnPadBranch.h:39
BmnPadBranch::GetDivX
uint32_t GetDivX()
Definition
BmnPadBranch.h:36
BmnPadBranch::GetPadInfo
PadInfo * GetPadInfo()
Definition
BmnPadBranch.h:32
BmnPadBranch::GetDivY
uint32_t GetDivY()
Definition
BmnPadBranch.h:37
BmnPadGenerator::_pad
BmnPadBranch * _pad
Definition
BmnPadGenerator.h:68
BmnPadGenerator::PadTree2Canvas
static void PadTree2Canvas(BmnPadBranch *br, TVirtualPad *pad)
Create pad structure in the canvas from the pad tree and associate pad branch instances with the pad ...
Definition
BmnPadGenerator.cxx:146
BmnPadGenerator::GeneratePadBranch
BmnPadBranch * GeneratePadBranch(pt::ptree &PropTree)
Generate pad branch tree from the boost property tree.
Definition
BmnPadGenerator.cxx:106
BmnPadGenerator::_TreeScheme
pt::ptree _TreeScheme
Definition
BmnPadGenerator.h:69
BmnPadGenerator::GeneratePadNode
PadInfo * GeneratePadNode(pt::ptree &PropTree)
Definition
BmnPadGenerator.cxx:26
BmnPadGenerator::LoadPTFrom
void LoadPTFrom(string FileName)
Load pad tree from json config.
Definition
BmnPadGenerator.cxx:6
BmnPadGenerator::_HM
std::unique_ptr< BmnHistManager > _HM
Definition
BmnPadGenerator.h:67
PadInfo
Storage for pad content and it's options.
Definition
PadInfo.h:20
PadInfo::name
string name
Definition
PadInfo.h:89
PadInfo::selection
string selection
Definition
PadInfo.h:91
PadInfo::opt
string opt
Definition
PadInfo.h:88
PadInfo::variable
string variable
Definition
PadInfo.h:90
PadInfo::current
TH1 * current
Definition
PadInfo.h:78
PadInfo::temp
TH1 * temp
Definition
PadInfo.h:76
TClass
TClass::GetClass
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
TClass::GetNew
ROOT::NewFunc_t GetNew() const
TH1
TH1::SetTitle
void SetTitle(const char *title) override
TH1::SetName
void SetName(const char *name) override
TH1::SetBins
virtual void SetBins(Int_t nx, const Double_t *xBins)
TH1::Clone
TObject * Clone(const char *newname="") const override
TH2
TH3
TNamed::GetName
const char * GetName() const override
TVirtualPad
TVirtualPad::cd
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
TVirtualPad::Divide
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)=0
dim
const UInt_t dim
Definition
MpdVHLLEGenerator.h:22
ROOT::NewFunc_t
void *(* NewFunc_t)(void *)
QA
BmnPadGenerator.cxx
Generated on
for BmnRoot by
1.17.0