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
13#include "ZDCBase/Constants.h"
14#include <cmath>
15#include <iostream>
16
17using namespace o2::zdc;
18
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
37void 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
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
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
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
145void SpatialPhotonResponse::printErrMsg(const char* str) const
146{
147 std::cerr << str << "\n";
148}
int32_t i
Visualizing spatial photon response in ZDC neutron and proton calorimeters.
void addPhoton(double x, double y, int nphotons)
std::array< int, 5 > getPhotonsPerChannel() const
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
GLint GLenum GLint x
Definition glcorearb.h:403
GLint y
Definition glcorearb.h:270
GLuint GLfloat * val
Definition glcorearb.h:1582
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
const std::string str