Project
Loading...
Searching...
No Matches
Detector.h
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#ifndef ALICEO2_ZDC_DETECTOR_H_
13#define ALICEO2_ZDC_DETECTOR_H_
14
15#include <vector> // for vector
16#include "TGeoManager.h" // for gGeoManager, TGeoManager (ptr only)
17#include "DetectorsBase/GeometryManager.h" // for getSensID
18#include "DetectorsBase/Detector.h" // for Detector
19#include "DetectorsCommonDataFormats/DetID.h" // for Detector
20#include "ZDCBase/Geometry.h"
21#include "DataFormatsZDC/Hit.h"
23#include "TParticle.h"
24#include <utility>
25#include "ZDCBase/Constants.h"
26
27// inclusions and forward decl for fast sim
28#ifdef ZDC_FASTSIM_ONNX
29
30#if __has_include(<onnxruntime/core/session/onnxruntime_cxx_api.h>)
31#include <onnxruntime/core/session/onnxruntime_cxx_api.h>
32#else
33#include <onnxruntime_cxx_api.h>
34#endif
35
36namespace o2::zdc
37{
38namespace fastsim
39{
40class NeuralFastSimulation;
41namespace processors
42{
43class StandardScaler;
44}
45} // namespace fastsim
46} // namespace o2::zdc
47#endif
48
49class FairVolume;
50
51namespace o2::zdc
52{
53
54class Detector : public o2::base::DetImpl<Detector>
55{
56 public:
59 kCuZn = 2,
62 kPb = 5,
63 kCu = 6,
64 kFe = 7,
69 kAir = 12,
70 kAl = 13,
71 kGraphite = 14
72 };
73
74 Detector(Bool_t active = true);
75
76// if building fastsim non trivial destructor is required
77#ifdef ZDC_FASTSIM_ONNX
78 ~Detector() override;
79#endif
80#ifndef ZDC_FASTSIM_ONNX
81 ~Detector() override = default;
82#endif
83
84 void InitializeO2Detector() final;
85
86 Bool_t ProcessHits(FairVolume* v = nullptr) final;
87
88 bool createHitsFromImage(SpatialPhotonResponse const& image, int detector);
89
90 void Register() override;
91
93 std::vector<o2::zdc::Hit>* getHits(int32_t iColl) const
94 {
95 if (iColl == 0) {
96 return mHits;
97 }
98 return nullptr;
99 }
100
101 void Reset() final;
102 void EndOfEvent() final;
103 void FinishPrimary() final;
104
105 void BeginPrimary() final;
106
107 void ConstructGeometry() final;
108
109 void createMaterials();
110 void addAlignableVolumes() const override {}
111
112 o2::zdc::Hit* addHit(int32_t trackID, int32_t parentID, int32_t sFlag, float primaryEnergy, int32_t detID, int32_t secID,
114 int32_t nphePMC, int32_t nphePMQ);
115
116 private:
118 Detector(const Detector& rhs);
119
120 void createAsideBeamLine();
121 void createCsideBeamLine();
122 void createMagnets();
123 void createDetectors();
124 void createZNZP();
125 void createZEM();
126
129 static Bool_t withZEM();
130
131 // determine detector; sector/tower and impact coordinates given volumename and position
132 void getDetIDandSecID(TString const& volname, math_utils::Vector3D<float> const& x,
133 math_utils::Vector3D<float>& xDet, int& detector, int& sector) const;
134
135 // Define sensitive volumes
136 void defineSensitiveVolumes();
137
138 // Methods to calculate the light outpu
139 Bool_t calculateTableIndexes(int& ibeta, int& iangle, int& iradius);
140
141 void resetHitIndices();
142
143 // common function for hit creation (can be called from multiple interfaces)
144 bool createOrAddHit(int detector,
145 int sector,
146 int currentMediumid,
147 bool issecondary,
148 int nphe,
149 int trackn,
150 int parent,
151 float tof,
152 float trackenergy,
153 math_utils::Vector3D<float> const& xImp,
154 float eDep, float x, float y, float z, float px, float py, float pz)
155 {
156 // A new hit is created when there is nothing yet for this det + sector
157 if (mCurrentHitsIndices[detector - 1][sector] == -1) {
158 mTotLightPMC = mTotLightPMQ = 0;
159 if (currentMediumid == mMediumPMCid) {
160 mTotLightPMC = nphe;
161 } else if (currentMediumid == mMediumPMQid) {
162 mTotLightPMQ = nphe;
163 }
164
165 math_utils::Vector3D<float> pos(x, y, z);
166 math_utils::Vector3D<float> mom(px, py, pz);
167 addHit(trackn, parent, issecondary, trackenergy, detector, sector,
168 pos, mom, tof, xImp, eDep, mTotLightPMC, mTotLightPMQ);
169 // stack->addHit(GetDetId());
170 mCurrentHitsIndices[detector - 1][sector] = mHits->size() - 1;
171
172 mXImpact = xImp;
173 return true;
174 } else {
175 auto& curHit = (*mHits)[mCurrentHitsIndices[detector - 1][sector]];
176 // summing variables that needs to be updated (Eloss and light yield)
177 curHit.setNoNumContributingSteps(curHit.getNumContributingSteps() + 1);
178 int nPMC{0}, nPMQ{0};
179 if (currentMediumid == mMediumPMCid) {
180 mTotLightPMC += nphe;
181 nPMC = nphe;
182 } else if (currentMediumid == mMediumPMQid) {
183 mTotLightPMQ += nphe;
184 nPMQ = nphe;
185 }
186 if (nphe > 0) {
187 curHit.SetEnergyLoss(curHit.GetEnergyLoss() + eDep);
188 curHit.setPMCLightYield(curHit.getPMCLightYield() + nPMC);
189 curHit.setPMQLightYield(curHit.getPMQLightYield() + nPMQ);
190 }
191 return true;
192 }
193 }
194
195 // helper function taking care of writing the photon response pattern at certain moments
196 void flushSpatialResponse();
197
198 float mTrackEta;
199 float mPrimaryEnergy;
200 math_utils::Vector3D<float> mXImpact;
201 float mTotLightPMC;
202 float mTotLightPMQ;
203 int32_t mMediumPMCid = -1;
204 int32_t mMediumPMQid = -2;
205
206 //
208 std::vector<o2::zdc::Hit>* mHits;
209
210 float mLumiLength = 0; // TODO: make part of configurable params
211 float mTCLIAAPERTURE = 3.5; // TODO: make part of configurable params
212 float mTCLIAAPERTURENEG = 3.5; // TODO: make part of configurable params
213 float mVCollSideCCentreY = 0.; // TODO: make part of configurable params
214
215 int mZNENVVolID = -1; // the volume id for the neutron det envelope volume
216 int mZPENVVolID = -1; // the volume id for the proton det envelope volume
217 int mZEMVolID = -1; // the volume id for the e-m envelope volume
218
219 // last principal track entered for each of the 5 detectors
220 // this is the main trackID causing showering/response in the detectors
221 int mLastPrincipalTrackEntered = -1;
222
223 static constexpr int NUMDETS = 5; // number of detectors
224 static constexpr int NUMSECS = 5; // number of (max) possible sectors (including COMMON one)
225
226 // current hits per detector and per sector FOR THE CURRENT track first entering a detector
227 // (as given by mLastPrincipalTrackEntered)
228 // This is given as index where to find in mHits container
229 int mCurrentHitsIndices[NUMDETS][NUMSECS] = {-1};
230
231 static constexpr int ZNRADIUSBINS = 18;
232 static constexpr int ZPRADIUSBINS = 28;
233 static constexpr int ANGLEBINS = 90;
234
235 float mLightTableZN[4][ANGLEBINS][ZNRADIUSBINS] = {1.};
236 float mLightTableZP[4][ANGLEBINS][ZPRADIUSBINS] = {1.};
237
238 SpatialPhotonResponse mNeutronResponseImage;
239 // there is only one proton detector per side
240 SpatialPhotonResponse mProtonResponseImage;
241
242 TParticle mCurrentPrincipalParticle{};
243
244 // collecting the responses for the current event
245 using ParticlePhotonResponse = std::vector<std::pair<TParticle,
246 std::pair<SpatialPhotonResponse, SpatialPhotonResponse>>>;
247
248 ParticlePhotonResponse mResponses;
249 ParticlePhotonResponse* mResponsesPtr = &mResponses;
250
251// fastsim model wrapper
252#ifdef ZDC_FASTSIM_ONNX
253 fastsim::NeuralFastSimulation* mFastSimClassifier = nullptr;
254 fastsim::NeuralFastSimulation* mFastSimModelNeutron = nullptr;
255 fastsim::NeuralFastSimulation* mFastSimModelProton = nullptr;
256
257 // Scalers for models inputs
258 fastsim::processors::StandardScaler* mClassifierScaler = nullptr;
259 fastsim::processors::StandardScaler* mModelScalerNeutron = nullptr;
260 fastsim::processors::StandardScaler* mModelScalerProton = nullptr;
261
262 // container for fastsim model responses
263 using FastSimResults = std::vector<std::array<long, 5>>;
264 FastSimResults mFastSimResults;
265
266 // converts FastSim model results to Hit
267 bool FastSimToHits(const Ort::Value& response, const TParticle& particle, int detector);
268
269 // determines detector geometry "pixel sizes"
270 constexpr std::pair<const int, const int> determineDetectorSize(int detector)
271 {
272 if (detector == ZNA || detector == ZNC) {
274 } else if (detector == ZPA || detector == ZPC) {
276 } else {
277 return {-1, -1};
278 }
279 }
280#endif
281
282 template <typename Det>
283 friend class o2::base::DetImpl;
284 ClassDefOverride(Detector, 1);
285};
286} // namespace o2::zdc
287
288#ifdef USESHM
289namespace o2
290{
291namespace base
292{
293template <>
294struct UseShm<o2::zdc::Detector> {
295 static constexpr bool value = true;
296};
297} // namespace base
298} // namespace o2
299#endif
300
301#endif
Definition of the Detector class.
Definition of the ZDC Hit class.
Definition of the GeometryManager class.
uint16_t pos
Definition RawData.h:3
Visualizing spatial photon response in ZDC neutron and proton calorimeters.
Detector()
Default Constructor.
Definition Detector.cxx:36
std::vector< o2::zdc::Hit > * getHits(int32_t iColl) const
Gets the produced collections.
Definition Detector.h:93
o2::zdc::Hit * addHit(int32_t trackID, int32_t parentID, int32_t sFlag, float primaryEnergy, int32_t detID, int32_t secID, math_utils::Vector3D< float > pos, math_utils::Vector3D< float > mom, float tof, math_utils::Vector3D< float > xImpact, double energyloss, int32_t nphePMC, int32_t nphePMQ)
Definition Detector.cxx:614
void BeginPrimary() final
void addAlignableVolumes() const override
declare alignable volumes of detector
Definition Detector.h:110
void ConstructGeometry() final
Definition Detector.cxx:331
void Register() override
Definition Detector.cxx:309
void InitializeO2Detector() final
Definition Detector.cxx:183
void FinishPrimary() final
~Detector() override=default
Bool_t ProcessHits(FairVolume *v=nullptr) final
Definition Detector.cxx:394
void EndOfEvent() final
Definition Detector.cxx:300
bool createHitsFromImage(SpatialPhotonResponse const &image, int detector)
Definition Detector.cxx:540
void Reset() final
Definition Detector.cxx:323
static constexpr double ZNDIVISION[2]
Definition Geometry.h:30
static constexpr double ZPSECTORS[2]
Definition Geometry.h:38
static constexpr double ZNSECTORS[2]
Definition Geometry.h:29
static constexpr double ZPDIVISION[2]
Definition Geometry.h:39
GLeglImageOES image
Definition glcorearb.h:4021
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...