ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArG4
LArG4Barrel
src
MapEta.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
MapEta.h
"
6
7
// For reading the data files in Athena.
8
#ifndef LARG4_STAND_ALONE
9
#include "
PathResolver/PathResolver.h
"
10
#include "
CxxUtils/trapping_fp.h
"
11
#endif
12
13
#include <iostream>
14
#include <fstream>
15
16
MapEta::MapEta
(
int
isampling)
17
:
m_directory
(
"/afs/cern.ch/atlas/offline/data/lar/calo_data"
),
18
m_init
(0),
19
m_nx
(0),
20
m_ny
(0),
21
m_resp
(nullptr),
22
m_xt0
(nullptr),
23
m_xt1
(nullptr),
24
m_xt2
(nullptr)
25
{
26
Initialize
(isampling);
27
}
28
29
MapEta::~MapEta
()
30
{
31
if
(
m_resp
)
delete
[]
m_resp
;
32
if
(
m_xt0
)
delete
[]
m_xt0
;
33
if
(
m_xt1
)
delete
[]
m_xt1
;
34
if
(
m_xt2
)
delete
[]
m_xt2
;
35
}
36
37
38
void
MapEta::SetDirectory
(
const
std::string& dir)
39
{
40
m_directory
=dir;
41
}
42
43
void
MapEta::Initialize
(
int
isampling)
44
{
45
if
(
m_init
==1)
return
;
46
if
(isampling < 1 || isampling >3)
return
;
47
std::string filename{};
48
if
(isampling==1) filename =
"deta_strip.map"
;
49
if
(isampling==2) filename =
"deta_middle.map"
;
50
if
(isampling==3) filename =
"eta_trans.map"
;
51
std::string fileLocation;
52
#ifdef LARG4_STAND_ALONE
53
// The stand-alone program expects to find the file via AFS.
54
fileLocation =
m_directory
+
"/"
+ filename;
55
#else
56
// In Athena, the PathResolver tool will find the file for us.
57
std::cout <<
"filename "
<< filename << std::endl;
58
//std::string larLocation = PathResolver::find_directory("lar","DATAPATH");
59
//fileLocation=larLocation+"/calo_data/"+filename;
60
std::string larLocation =
PathResolver::find_directory
(
"LArG4Barrel"
,
"ATLASCALDATA"
);
61
fileLocation=larLocation+
"/"
+filename;
62
std::cout <<
"fileLocation "
<< fileLocation << std::endl;
63
#endif
64
65
std::ifstream in(fileLocation);
66
if
(in)
67
{
68
#ifndef LARG4_STAND_ALONE
69
// Tell clang to optimize assuming that FP operations may trap.
70
CXXUTILS_TRAPPING_FP
;
71
#endif
72
73
in>>
m_nx
>>
m_xmin
>>
m_xmax
>>
m_ny
>>
m_ymin
>>
m_ymax
;
74
if
(
m_nx
>0 &&
m_ny
>0 &&
m_nx
<10000 &&
m_ny
<10000){
//coverity issue. This is a tainted variable protection, 10000 can be changed if required.
75
m_deltax
=(
m_xmax
-
m_xmin
)/((
float
)
m_nx
);
76
m_deltay
=(
m_ymax
-
m_ymin
)/((
float
)
m_ny
);
77
// what is written as xmax in the map is x of last point + delta x
78
// (such that npoint = (xmax-xmin)/deltax
79
// to get the real last point in the map we should subtract deltax
80
m_xmax
=
m_xmax
-
m_deltax
;
81
m_ymax
=
m_ymax
-
m_deltay
;
82
m_resp
=
new
float
[
m_ny
*
m_nx
];
83
m_xt0
=
new
float
[
m_ny
*
m_nx
];
84
m_xt1
=
new
float
[
m_ny
*
m_nx
];
85
m_xt2
=
new
float
[
m_ny
*
m_nx
];
86
int
ii,jj;
87
for
(
int
ix=0;ix<
m_nx
;ix++) {
88
for
(
int
iy=0;iy<
m_ny
;iy++) {
89
in>>ii>>jj>>
m_resp
[ix+iy*
m_nx
]>>
m_xt0
[ix+iy*
m_nx
]>>
m_xt1
[ix+iy*
m_nx
]>>
m_xt2
[ix+iy*
m_nx
];
90
if
(ii != ix || jj != iy) std::cout <<
"MapEta: inconsistency when reading map..."
<< std::endl;
91
}
92
}
93
94
std::cout <<
"Eta Map read "
<<
" Nbins "
<<
m_nx
<<
" "
<<
m_ny
95
<<
" bin size*1000 "
<< 1000*
m_deltax
<<
" "
<< 1000*
m_deltay
96
<<
" X range "
<<
m_xmin
<<
" "
<<
m_xmax
97
<<
" Y range "
<<
m_ymin
<<
" "
<<
m_ymax
<< std::endl;
98
m_init
=1;
99
}
100
else
{
101
std::cout <<
"Error in MapEta::Initialize: nx or ny out of limits."
<< std::endl;
102
return
;
103
}
104
}
105
else
{
106
std::cout <<
"Error in MapEta::Initialize: The file could not be open."
<< std::endl;
107
return
;
108
}
109
}
110
111
void
MapEta::GetData
(
double
x
,
double
y
,
double
* resp,
double
* xt0,
double
* xt1,
double
* xt2)
const
112
{
113
*resp=1;
114
*xt0=1;
115
*xt1=0;
116
*xt2=0;
117
if
(
m_nx
==0 ||
m_ny
==0)
return
;
118
if
(
x
<
m_xmin
)
x
=
m_xmin
+0.01*
m_deltax
;
119
if
(
x
>=
m_xmax
)
x
=
m_xmax
-0.01*
m_deltax
;
120
if
(
y
<
m_ymin
)
y
=
m_ymin
+0.01*
m_deltay
;
121
if
(
y
>=
m_ymax
)
y
=
m_ymax
-0.01*
m_deltay
;
122
123
int
ix,iy;
124
ix = (int) ((
x
-
m_xmin
)/
m_deltax
);
125
iy = (int) ((
y
-
m_ymin
)/
m_deltay
);
126
float
x0 = ((float) ix)*
m_deltax
+
m_xmin
;
127
float
x1 = x0+
m_deltax
;
128
float
y0 = ((float) iy)*
m_deltay
+
m_ymin
;
129
float
y1 = y0+
m_deltay
;
130
131
132
if
(ix<0 || ix+1 >=
m_nx
|| iy<0 || iy+1 >=
m_ny
) {
133
std::cout <<
"MapEta: Out of range "
<< ix <<
" "
<< iy << std::endl;
134
return
;
135
}
136
double
w[4];
137
w[0]=(x1-
x
)*(y1-
y
);
138
w[1]=(
x
-x0)*(y1-
y
);
139
w[2]=(x1-
x
)*(
y
-y0);
140
w[3]=(
x
-x0)*(
y
-y0);
141
142
double
sumw=0.;
143
*resp=0;
144
*xt0=0;
145
for
(
int
i=0;i<2;i++) {
146
for
(
int
j=0;j<2;j++) {
147
int
n=ix+i+(iy+j)*
m_nx
;
148
int
m=i+2*j;
149
sumw +=w[m];
150
*resp +=
m_resp
[n]*w[m];
151
*xt0 +=
m_xt0
[n]*w[m];
152
*xt1 +=
m_xt1
[n]*w[m];
153
*xt2 +=
m_xt2
[n]*w[m];
154
}
155
}
156
const
double
inv_sumw = 1. / sumw;
157
if
(sumw>0.) {
158
*resp = *resp*inv_sumw;
159
*xt0 = *xt0*inv_sumw;
160
*xt1 = *xt1*inv_sumw;
161
*xt2 = *xt2*inv_sumw;
162
}
163
164
}
165
void
MapEta::GetData0
(
double
x
,
double
y
,
double
* resp)
const
166
{
167
*resp=1;
168
if
(
m_nx
==0 ||
m_ny
==0)
return
;
169
if
(
x
<
m_xmin
)
x
=
m_xmin
+0.01*
m_deltax
;
170
if
(
x
>=
m_xmax
)
x
=
m_xmax
-0.01*
m_deltax
;
171
if
(
y
<
m_ymin
)
y
=
m_ymin
+0.01*
m_deltay
;
172
if
(
y
>=
m_ymax
)
y
=
m_ymax
-0.01*
m_deltay
;
173
174
int
ix,iy;
175
ix = (int) ((
x
-
m_xmin
)/
m_deltax
);
176
iy = (int) ((
y
-
m_ymin
)/
m_deltay
);
177
float
x0 = ((float) ix)*
m_deltax
+
m_xmin
;
178
float
x1 = x0+
m_deltax
;
179
float
y0 = ((float) iy)*
m_deltay
+
m_ymin
;
180
float
y1 = y0+
m_deltay
;
181
182
if
(ix<0 || ix+1 >=
m_nx
|| iy<0 || iy+1 >=
m_ny
) {
183
std::cout <<
"MapEta: Out of range "
<< ix <<
" "
<< iy << std::endl;
184
return
;
185
}
186
double
w[4];
187
w[0]=(x1-
x
)*(y1-
y
);
188
w[1]=(
x
-x0)*(y1-
y
);
189
w[2]=(x1-
x
)*(
y
-y0);
190
w[3]=(
x
-x0)*(
y
-y0);
191
192
double
sumw=0.;
193
*resp = 0;
194
for
(
int
i=0;i<2;i++) {
195
for
(
int
j=0;j<2;j++) {
196
int
n=ix+i+(iy+j)*
m_nx
;
197
int
m=i+2*j;
198
sumw +=w[m];
199
*resp +=
m_resp
[n]*w[m];
200
}
201
}
202
if
(sumw>0.) *resp = *resp/sumw;
203
else
*resp = 1;
204
205
}
MapEta.h
PathResolver.h
y
#define y
x
#define x
MapEta::GetData0
void GetData0(double x, double y, double *resp) const
Definition
MapEta.cxx:165
MapEta::m_xmin
float m_xmin
Definition
MapEta.h:17
MapEta::m_deltax
float m_deltax
Definition
MapEta.h:18
MapEta::m_deltay
float m_deltay
Definition
MapEta.h:18
MapEta::m_xt2
float * m_xt2
Definition
MapEta.h:22
MapEta::m_nx
int m_nx
Definition
MapEta.h:16
MapEta::m_ymin
float m_ymin
Definition
MapEta.h:17
MapEta::SetDirectory
void SetDirectory(const std::string &dir)
Definition
MapEta.cxx:38
MapEta::Initialize
void Initialize(int isampling)
Definition
MapEta.cxx:43
MapEta::m_ymax
float m_ymax
Definition
MapEta.h:17
MapEta::m_ny
int m_ny
Definition
MapEta.h:16
MapEta::m_xmax
float m_xmax
Definition
MapEta.h:17
MapEta::GetData
void GetData(double x, double y, double *resp, double *xt0, double *xt1, double *xt2) const
Definition
MapEta.cxx:111
MapEta::MapEta
MapEta(int isampling)
Definition
MapEta.cxx:16
MapEta::m_directory
std::string m_directory
Definition
MapEta.h:14
MapEta::m_xt0
float * m_xt0
Definition
MapEta.h:20
MapEta::m_init
int m_init
Definition
MapEta.h:15
MapEta::~MapEta
~MapEta()
Definition
MapEta.cxx:29
MapEta::m_resp
float * m_resp
Definition
MapEta.h:19
MapEta::m_xt1
float * m_xt1
Definition
MapEta.h:21
PathResolver::find_directory
static std::string find_directory(const std::string &logical_file_name, const std::string &search_path)
Definition
PathResolver.cxx:249
trapping_fp.h
Tell the compiler to optimize assuming that FP may trap.
CXXUTILS_TRAPPING_FP
#define CXXUTILS_TRAPPING_FP
Definition
trapping_fp.h:24
Generated on
for ATLAS Offline Software by
1.17.0