Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
CaloGeomMapping.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file CaloGeomMapping.cc
1
#include "
CaloGeomMapping.h
"
2
3
#include <
cdbobjects/CDBTTree.h
>
4
5
#include <
ffamodules/CDBInterface.h
>
6
7
#include <
fun4all/Fun4AllReturnCodes.h
>
8
#include <
fun4all/SubsysReco.h
>
// for SubsysReco
9
10
#include <
phool/PHCompositeNode.h
>
11
#include <
phool/PHIODataNode.h
>
// for PHIODataNode
12
#include <
phool/PHNode.h
>
13
#include <
phool/PHNodeIterator.h
>
// for PHNodeIterator
14
#include <
phool/PHObject.h
>
15
#include <
phool/getClass.h
>
16
#include <
phool/phool.h
>
// for PHWHERE
17
18
#include <calobase/RawTowerDefs.h>
// for encode_towerid
19
#include <calobase/RawTowerGeom.h>
// for RawTowerGeom
20
#include <calobase/RawTowerGeomContainer.h>
// for RawTowerGeomC...
21
#include <calobase/RawTowerGeomContainer_Cylinderv1.h>
22
#include <calobase/RawTowerGeomv1.h>
23
24
#include <cstdlib>
// for exit
25
#include <exception>
// for exception
26
#include <iostream>
// for operator<<, endl
27
#include <cmath>
// for fabs, atan, cos
28
#include <stdexcept>
// for runtime_error
29
#include <utility>
// for pair
30
31
//____________________________________________________________________________..
32
CaloGeomMapping::CaloGeomMapping
(
const
std::string
&
name
):
33
SubsysReco
(name),
34
m_Detector(
"CEMC"
),
35
m_RawTowerGeomContainer(nullptr)
36
{
37
std::cout <<
"CaloGeomMapping::CaloGeomMapping(const std::string &name) Calling ctor"
<< std::endl;
38
}
39
40
//____________________________________________________________________________..
41
CaloGeomMapping::~CaloGeomMapping
()
42
{
43
std::cout <<
"CaloGeomMapping::~CaloGeomMapping() Calling dtor"
<< std::endl;
44
}
45
46
//____________________________________________________________________________..
47
int
CaloGeomMapping::Init
(
PHCompositeNode
*topNode)
48
{
49
std::cout <<
"CaloGeomMapping::Init(PHCompositeNode *topNode) Initializing"
<< std::endl;
50
51
/* std::cout << "Printing node tree before new node creation:" << std::endl; */
52
/* topNode->print(); */
53
try
54
{
55
CreateGeomNode
(topNode);
56
}
57
catch
(std::exception &
e
)
58
{
59
std::cout << e.what() << std::endl;
60
exit(1);
61
}
62
/* std::cout << "Printing node tree after new node creation:" << std::endl; */
63
/* topNode->print(); */
64
return
Fun4AllReturnCodes::EVENT_OK
;
65
}
66
67
//____________________________________________________________________________..
68
/*
69
int CaloGeomMapping::InitRun(PHCompositeNode *topNode)
70
{
71
std::cout << "CaloGeomMapping::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
72
return Fun4AllReturnCodes::EVENT_OK;
73
}
74
75
//____________________________________________________________________________..
76
int CaloGeomMapping::process_event(PHCompositeNode *topNode)
77
{
78
std::cout << "CaloGeomMapping::process_event(PHCompositeNode *topNode) Processing Event" << std::endl;
79
return Fun4AllReturnCodes::EVENT_OK;
80
}
81
82
//____________________________________________________________________________..
83
int CaloGeomMapping::ResetEvent(PHCompositeNode *topNode)
84
{
85
std::cout << "CaloGeomMapping::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
86
return Fun4AllReturnCodes::EVENT_OK;
87
}
88
89
//____________________________________________________________________________..
90
int CaloGeomMapping::EndRun(const int runnumber)
91
{
92
std::cout << "CaloGeomMapping::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
93
return Fun4AllReturnCodes::EVENT_OK;
94
}
95
96
//____________________________________________________________________________..
97
int CaloGeomMapping::End(PHCompositeNode *topNode)
98
{
99
std::cout << "CaloGeomMapping::End(PHCompositeNode *topNode) This is the End..." << std::endl;
100
return Fun4AllReturnCodes::EVENT_OK;
101
}
102
103
//____________________________________________________________________________..
104
int CaloGeomMapping::Reset(PHCompositeNode *topNode)
105
{
106
std::cout << "CaloGeomMapping::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
107
return Fun4AllReturnCodes::EVENT_OK;
108
}
109
110
//____________________________________________________________________________..
111
void CaloGeomMapping::Print(const std::string &what) const
112
{
113
std::cout << "CaloGeomMapping::Print(const std::string &what) const Printing info for " << what << std::endl;
114
}
115
*/
116
117
void
CaloGeomMapping::CreateGeomNode
(
PHCompositeNode
* topNode)
118
{
119
PHNodeIterator
iter(topNode);
120
PHCompositeNode
*runNode =
dynamic_cast<
PHCompositeNode
*
>
(iter.
findFirst
(
"PHCompositeNode"
,
"RUN"
));
121
if
(!runNode)
122
{
123
std::cout <<
PHWHERE
<<
"Run Node missing, doing nothing."
<< std::endl;
124
throw
std::runtime_error(
"Failed to find Run node in CaloGeomMapping::CreateGeomNode"
);
125
}
126
127
PHNodeIterator
runIter(runNode);
128
PHCompositeNode
*RunDetNode =
dynamic_cast<
PHCompositeNode
*
>
(runIter.
findFirst
(
"PHCompositeNode"
,
m_Detector
));
129
if
(!RunDetNode)
130
{
131
RunDetNode =
new
PHCompositeNode
(
m_Detector
);
132
runNode->
addNode
(RunDetNode);
133
}
134
135
const
RawTowerDefs::CalorimeterId
caloid =
RawTowerDefs::convert_name_to_caloid
(
m_Detector
);
136
m_TowerGeomNodeName
=
"TOWERGEOM_"
+
m_Detector
;
137
m_RawTowerGeomContainer
= findNode::getClass<RawTowerGeomContainer>(topNode,
m_TowerGeomNodeName
);
138
if
(!
m_RawTowerGeomContainer
)
139
{
140
m_RawTowerGeomContainer
=
new
RawTowerGeomContainer_Cylinderv1
(caloid);
141
// add it to the node tree
142
PHIODataNode<PHObject>
*newNode =
new
PHIODataNode<PHObject>
(
m_RawTowerGeomContainer
,
m_TowerGeomNodeName
,
"PHObject"
);
143
RunDetNode->
addNode
(newNode);
144
}
145
146
// Get the geometry mapping file from the Conditions Database
147
std::string
inName=
CDBInterface::instance
()->
getUrl
(
"CALO_TOWER_GEOMETRY"
);
148
CDBTTree
* cdbttree =
new
CDBTTree
(inName);
149
cdbttree->
LoadCalibrations
();
150
151
std::string
parName;
152
std::string
parBase;
153
// Set the radius, thickness, number of eta and phi bins
154
if
(
m_Detector
==
"CEMC"
)
155
{
156
parBase =
"cemc"
;
157
m_RawTowerGeomContainer
->
set_radius
(93.5);
158
m_RawTowerGeomContainer
->
set_thickness
(20.4997);
159
m_RawTowerGeomContainer
->
set_phibins
(256);
160
m_RawTowerGeomContainer
->
set_etabins
(96);
161
// m_RawTowerGeomContainer->set_phistep(m_PhiStep);
162
// m_RawTowerGeomContainer->set_phimin(m_PhiMin);
163
}
164
if
(
m_Detector
==
"HCALIN"
)
165
{
166
parBase =
"hcalin"
;
167
m_RawTowerGeomContainer
->
set_radius
(115);
168
m_RawTowerGeomContainer
->
set_thickness
(25.005);
169
m_RawTowerGeomContainer
->
set_phibins
(64);
170
m_RawTowerGeomContainer
->
set_etabins
(24);
171
// m_RawTowerGeomContainer->set_phistep(m_PhiStep);
172
// m_RawTowerGeomContainer->set_phimin(m_PhiMin);
173
}
174
if
(
m_Detector
==
"HCALOUT"
)
175
{
176
parBase =
"hcalout"
;
177
m_RawTowerGeomContainer
->
set_radius
(177.423);
178
m_RawTowerGeomContainer
->
set_thickness
(96.894);
179
m_RawTowerGeomContainer
->
set_phibins
(64);
180
m_RawTowerGeomContainer
->
set_etabins
(24);
181
// m_RawTowerGeomContainer->set_phistep(m_PhiStep);
182
// m_RawTowerGeomContainer->set_phimin(m_PhiMin);
183
}
184
185
// Set the eta and phi bounds of each bin
186
for
(
int
ibin
= 0;
ibin
<
m_RawTowerGeomContainer
->
get_etabins
();
ibin
++)
187
{
188
parName = parBase +
"_eta_"
;
189
double
first, second;
190
first = cdbttree->
GetDoubleValue
(
ibin
, parName +
"first"
);
191
second = cdbttree->
GetDoubleValue
(
ibin
, parName +
"second"
);
192
const
std::pair<double, double> range(first, second);
193
m_RawTowerGeomContainer
->
set_etabounds
(
ibin
, range);
194
/* std::cout << "Setting eta bounds for bin " << ibin << ", range is " << first << " - " << second << "\n"; */
195
}
196
for
(
int
ibin
= 0;
ibin
<
m_RawTowerGeomContainer
->
get_phibins
();
ibin
++)
197
{
198
parName = parBase +
"_phi_"
;
199
double
first, second;
200
first = cdbttree->
GetDoubleValue
(
ibin
, parName +
"first"
);
201
second = cdbttree->
GetDoubleValue
(
ibin
, parName +
"second"
);
202
const
std::pair<double, double> range(first, second);
203
m_RawTowerGeomContainer
->
set_phibounds
(
ibin
, range);
204
/* std::cout << "Setting phi bounds for bin " << ibin << ", range is " << first << " - " << second << "\n"; */
205
}
206
207
// Populate container with RawTowerGeom objects
208
for
(
int
ieta=0; ieta<
m_RawTowerGeomContainer
->
get_etabins
(); ieta++)
209
{
210
for
(
int
iphi=0; iphi<
m_RawTowerGeomContainer
->
get_phibins
(); iphi++)
211
{
212
// build tower geom here
213
const
RawTowerDefs::keytype
key =
214
RawTowerDefs::encode_towerid
(caloid, ieta, iphi);
215
216
double
r
=
m_RawTowerGeomContainer
->
get_radius
();
217
const
double
x
(r * cos(
m_RawTowerGeomContainer
->
get_phicenter
(iphi)));
218
const
double
y
(r * sin(
m_RawTowerGeomContainer
->
get_phicenter
(iphi)));
219
/* const double z(r / tan(PHG4Utils::get_theta(m_RawTowerGeomContainer->get_etacenter(ieta)))); */
220
const
double
z
(r / tan(2*atan(exp(-1*
m_RawTowerGeomContainer
->
get_etacenter
(ieta)))));
221
/* const double x(0); */
222
/* const double y(0); */
223
/* const double z(0); */
224
225
RawTowerGeom
*
tg
=
m_RawTowerGeomContainer
->
get_tower_geometry
(key);
226
if
(tg)
227
{
228
if
(
Verbosity
() > 0)
229
{
230
std::cout <<
"CaloGeomMapping::CreateGeomNode - Tower geometry "
<< key <<
" already exists"
<< std::endl;
231
}
232
233
if
(fabs(tg->
get_center_x
() -
x
) > 1
e
-4)
234
{
235
std::cout <<
"CaloGeomMapping::CreateGeomNode - Fatal Error - duplicated Tower geometry "
<< key <<
" with existing x = "
<< tg->
get_center_x
() <<
" and expected x = "
<< x
236
<< std::endl;
237
238
exit(1);
239
}
240
if
(fabs(tg->
get_center_y
() -
y
) > 1
e
-4)
241
{
242
std::cout <<
"CaloGeomMapping::CreateGeomNode - Fatal Error - duplicated Tower geometry "
<< key <<
" with existing y = "
<< tg->
get_center_y
() <<
" and expected y = "
<< y
243
<< std::endl;
244
exit(1);
245
}
246
if
(fabs(tg->
get_center_z
() -
z
) > 1
e
-4)
247
{
248
std::cout <<
"CaloGeomMapping::CreateGeomNode - Fatal Error - duplicated Tower geometry "
<< key <<
" with existing z= "
<< tg->
get_center_z
() <<
" and expected z = "
<< z
249
<< std::endl;
250
exit(1);
251
}
252
}
253
else
254
{
255
if
(
Verbosity
() > 0)
256
{
257
std::cout <<
"CaloGeomMapping::CreateGeomNode - building tower geometry "
<< key <<
""
<< std::endl;
258
}
259
260
tg =
new
RawTowerGeomv1
(key);
261
262
tg->
set_center_x
(x);
263
tg->
set_center_y
(y);
264
tg->
set_center_z
(z);
265
m_RawTowerGeomContainer
->
add_tower_geometry
(tg);
266
/* std::cout << "Added new RawTowerGeom " << tg << "; more details:\n"; */
267
/* tg->identify(); */
268
}
269
}
270
}
// end loop over eta, phi bins
271
}
// end of building RawTowerGeomContainer
272
273
void
CaloGeomMapping::set_detector_name
(
const
std::string
&
name
)
274
{
275
m_Detector
=
name
;
276
}
277
278
std::string
CaloGeomMapping::get_detector_name
()
279
{
280
return
m_Detector
;
281
}
coresoftware
blob
master
offline
packages
CaloReco
CaloGeomMapping.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:05
using
1.8.2 with
sPHENIX GitHub integration