Project
Loading...
Searching...
No Matches
SpatialPhotonResponse.cxx
Go to the documentation of this file.
1
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3
// All rights not expressly granted are reserved.
4
//
5
// This software is distributed under the terms of the GNU General Public
6
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7
//
8
// In applying this license CERN does not waive the privileges and immunities
9
// granted to it by virtue of its status as an Intergovernmental Organization
10
// or submit itself to any jurisdiction.
11
12
#include "
ZDCSimulation/SpatialPhotonResponse.h
"
13
#include "
ZDCBase/Constants.h
"
14
#include <cmath>
15
#include <iostream>
16
17
using namespace
o2::zdc
;
18
19
SpatialPhotonResponse::SpatialPhotonResponse
(
int
Nx,
int
Ny,
double
lowerx,
20
double
lowery,
double
lengthx,
double
lengthy) : mNx{Nx},
21
mNy{Ny},
22
mLxOfCell{lengthx / Nx},
23
mLyOfCell{lengthy / Ny},
24
mInvLxOfCell{1. / mLxOfCell},
25
mInvLyOfCell{1. / mLyOfCell},
26
mLowerX{lowerx},
27
mLowerY{lowery}
28
{
29
mImageData.resize(Nx);
30
for
(
int
x
= 0;
x
< Nx; ++
x
) {
31
mImageData[
x
].resize(Ny);
32
}
33
// now the image should be null initialized
34
std::cout <<
" Image initialized with "
<< mNx <<
" x "
<< mNy <<
" pixels "
;
35
}
36
37
void
SpatialPhotonResponse::addPhoton
(
double
x
,
double
y
,
int
nphotons)
38
{
39
const
int
xpixel = (int)(std::floor((
x
- mLowerX) * mInvLxOfCell));
40
const
int
ypixel = (int)(std::floor((
y
- mLowerY) * mInvLyOfCell));
41
if
(nphotons < 0) {
42
std::cerr <<
"negative photon number\n"
;
43
return
;
44
}
45
if
(xpixel < 0 || xpixel >= mNx) {
46
std::cerr <<
"X-PIXEL OUT OF RANGE "
<< xpixel <<
" "
<<
x
<<
" , "
<<
y
<<
"\n"
;
47
return
;
48
}
49
if
(ypixel < 0 || ypixel >= mNy) {
50
std::cerr <<
"Y-PIXEL OUT OF RANGE "
<< ypixel <<
" "
<<
x
<<
" , "
<<
y
<<
"\n"
;
51
return
;
52
}
53
mImageData[xpixel][ypixel] += nphotons;
54
mPhotonSum += nphotons;
55
}
56
57
// will print pixel 0 == (0,0) at the lower left corner
58
void
SpatialPhotonResponse::printToScreen
()
const
59
{
60
std::cout <<
"Response START "
<< mPhotonSum <<
" ----\n"
;
61
for
(
int
y
= mNy - 1;
y
>= 0; --
y
) {
62
{
63
for
(
int
x
= 0;
x
< mNx; ++
x
) {
64
const
auto
val
= mImageData[
x
][
y
];
65
if
(
val
< 0) {
66
std::cerr <<
"SHIT\n"
;
67
}
68
std::cout << ((
val
< 10) ?
std::to_string
(
val
) :
"x"
);
69
}
70
std::cout <<
"\n"
;
71
}
72
}
73
std::cout <<
"Response END ----\n"
;
74
}
75
76
void
SpatialPhotonResponse::reset
()
77
{
78
mPhotonSum = 0;
79
for
(
int
x
= 0;
x
< mNx; ++
x
) {
80
{
81
for
(
int
y
= 0;
y
< mNy; ++
y
) {
82
mImageData[
x
][
y
] = 0;
83
}
84
}
85
}
86
mTime = 0;
87
mDetectorID = -1;
88
}
89
90
std::array<int, 5>
SpatialPhotonResponse::getPhotonsPerChannel
()
const
91
{
92
std::array<int, 5> photonsum = {0, 0, 0, 0, 0};
93
if
(mPhotonSum == 0) {
94
return
photonsum;
95
}
96
97
if
(mDetectorID == -1) {
98
std::cerr <<
"SpatialPhotonResponse has no detectorID "
;
99
return
photonsum;
100
}
101
102
auto
determineChannel = [](
int
detector,
int
x
,
int
y
,
int
Nx,
int
Ny) {
103
if
((
x
+
y
) % 2 == 0) {
104
return
(
int
)
ChannelTypeZNP::Common
;
105
}
106
107
if
(detector ==
DetectorID::ZNA
|| detector ==
DetectorID::ZNC
) {
108
if
(
x
< Nx / 2) {
109
if
(
y
< Ny / 2) {
110
return
(
int
)
ChannelTypeZNP::Ch1
;
111
}
else
{
112
return
(
int
)
ChannelTypeZNP::Ch3
;
113
}
114
}
else
{
115
if
(
y
>= Ny / 2) {
116
return
(
int
)
ChannelTypeZNP::Ch4
;
117
}
else
{
118
return
(
int
)
ChannelTypeZNP::Ch2
;
119
}
120
}
121
}
122
123
if
(detector ==
DetectorID::ZPA
|| detector ==
DetectorID::ZPC
) {
124
auto
i
= (int)(4.f *
x
/ Nx);
125
return
(
int
)(
i
+ 1);
126
}
127
return
-1;
128
};
129
130
int
sum
= 0;
131
for
(
int
x
= 0;
x
< mNx; ++
x
) {
132
// loop over y = rows
133
for
(
int
y
= 0;
y
< mNy; ++
y
) {
134
// get channel
135
int
channel = determineChannel(mDetectorID,
x
,
y
, mNx, mNy);
136
photonsum[channel] += mImageData[
x
][
y
];
137
sum
+= 0;
138
}
139
}
140
// assert (mPhotonSum == photonsum[0] + photonsum[1] + photonsum[2] + photonsum[3] + photonsum[4]);
141
142
return
photonsum;
143
}
144
145
void
SpatialPhotonResponse::printErrMsg(
const
char
*
str
)
const
146
{
147
std::cerr <<
str
<<
"\n"
;
148
}
Constants.h
sum
std::vector< double > sum
Definition
G4ScoringMerger.cxx:31
i
int32_t i
Definition
GPUCommonAlgorithm.h:451
SpatialPhotonResponse.h
Visualizing spatial photon response in ZDC neutron and proton calorimeters.
o2::zdc::SpatialPhotonResponse::printToScreen
void printToScreen() const
Definition
SpatialPhotonResponse.cxx:58
o2::zdc::SpatialPhotonResponse::addPhoton
void addPhoton(double x, double y, int nphotons)
Definition
SpatialPhotonResponse.cxx:37
o2::zdc::SpatialPhotonResponse::reset
void reset()
Definition
SpatialPhotonResponse.cxx:76
o2::zdc::SpatialPhotonResponse::SpatialPhotonResponse
SpatialPhotonResponse()=default
o2::zdc::SpatialPhotonResponse::getPhotonsPerChannel
std::array< int, 5 > getPhotonsPerChannel() const
Definition
SpatialPhotonResponse.cxx:90
x
GLint GLenum GLint x
Definition
glcorearb.h:403
y
GLint y
Definition
glcorearb.h:270
val
GLuint GLfloat * val
Definition
glcorearb.h:1582
o2::zdc
Definition
ZDCConstants.h:23
o2::zdc::Ch2
@ Ch2
Definition
Constants.h:46
o2::zdc::Ch1
@ Ch1
Definition
Constants.h:45
o2::zdc::Ch3
@ Ch3
Definition
Constants.h:47
o2::zdc::Common
@ Common
Definition
Constants.h:44
o2::zdc::Ch4
@ Ch4
Definition
Constants.h:48
o2::zdc::ZNA
@ ZNA
Definition
Constants.h:37
o2::zdc::ZNC
@ ZNC
Definition
Constants.h:40
o2::zdc::ZPC
@ ZPC
Definition
Constants.h:41
o2::zdc::ZPA
@ ZPA
Definition
Constants.h:38
std::to_string
std::string to_string(gsl::span< T, Size > span)
Definition
common.h:52
str
const std::string str
Definition
test_ransEncodeDecode.cxx:37
Detectors
ZDC
simulation
src
SpatialPhotonResponse.cxx
Generated on Fri Oct 2 2026 18:34:49 for Project by
1.9.8