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
125 // determine detector; sector/tower and impact coordinates given volumename and position
126 void getDetIDandSecID(TString const& volname, math_utils::Vector3D<float> const& x,
127 math_utils::Vector3D<float>& xDet, int& detector, int& sector) const;
128
129 // Define sensitive volumes
130 void defineSensitiveVolumes();
131
132 // Methods to calculate the light outpu
133 Bool_t calculateTableIndexes(int& ibeta, int& iangle, int& iradius);
134
135 void resetHitIndices();
136
137 // common function for hit creation (can be called from multiple interfaces)
138 bool createOrAddHit(int detector,
139 int sector,
140 int currentMediumid,
141 bool issecondary,
142 int nphe,
143 int trackn,
144 int parent,
145 float tof,
146 float trackenergy,
147 math_utils::Vector3D<float> const& xImp,
148 float eDep, float x, float y, float z, float px, float py, float pz)
149 {
150 // A new hit is created when there is nothing yet for this det + sector
151 if (mCurrentHitsIndices[detector - 1][sector] == -1) {
152 mTotLightPMC = mTotLightPMQ = 0;
153 if (currentMediumid == mMediumPMCid) {
154 mTotLightPMC = nphe;
155 } else if (currentMediumid == mMediumPMQid) {
156 mTotLightPMQ = nphe;
157 }
158
159 math_utils::Vector3D<float> pos(x, y, z);
160 math_utils::Vector3D<float> mom(px, py, pz);
161 addHit(trackn, parent, issecondary, trackenergy, detector, sector,
162 pos, mom, tof, xImp, eDep, mTotLightPMC, mTotLightPMQ);
163 // stack->addHit(GetDetId());
164 mCurrentHitsIndices[detector - 1][sector] = mHits->size() - 1;
165
166 mXImpact = xImp;
167 return true;
168 } else {
169 auto& curHit = (*mHits)[mCurrentHitsIndices[detector - 1][sector]];
170 // summing variables that needs to be updated (Eloss and light yield)
171 curHit.setNoNumContributingSteps(curHit.getNumContributingSteps() + 1);
172 int nPMC{0}, nPMQ{0};
173 if (currentMediumid == mMediumPMCid) {
174 mTotLightPMC += nphe;
175 nPMC = nphe;
176 } else if (currentMediumid == mMediumPMQid) {
177 mTotLightPMQ += nphe;
178 nPMQ = nphe;
179 }
180 if (nphe > 0) {
181 curHit.SetEnergyLoss(curHit.GetEnergyLoss() + eDep);
182 curHit.setPMCLightYield(curHit.getPMCLightYield() + nPMC);
183 curHit.setPMQLightYield(curHit.getPMQLightYield() + nPMQ);
184 }
185 return true;
186 }
187 }
188
189 // helper function taking care of writing the photon response pattern at certain moments
190 void flushSpatialResponse();
191
192 float mTrackEta;
193 float mPrimaryEnergy;
194 math_utils::Vector3D<float> mXImpact;
195 float mTotLightPMC;
196 float mTotLightPMQ;
197 int32_t mMediumPMCid = -1;
198 int32_t mMediumPMQid = -2;
199
200 //
202 std::vector<o2::zdc::Hit>* mHits;
203
204 float mLumiLength = 0; // TODO: make part of configurable params
205 float mTCLIAAPERTURE = 3.5; // TODO: make part of configurable params
206 float mTCLIAAPERTURENEG = 3.5; // TODO: make part of configurable params
207 float mVCollSideCCentreY = 0.; // TODO: make part of configurable params
208
209 int mZNENVVolID = -1; // the volume id for the neutron det envelope volume
210 int mZPENVVolID = -1; // the volume id for the proton det envelope volume
211 int mZEMVolID = -1; // the volume id for the e-m envelope volume
212
213 // last principal track entered for each of the 5 detectors
214 // this is the main trackID causing showering/response in the detectors
215 int mLastPrincipalTrackEntered = -1;
216
217 static constexpr int NUMDETS = 5; // number of detectors
218 static constexpr int NUMSECS = 5; // number of (max) possible sectors (including COMMON one)
219
220 // current hits per detector and per sector FOR THE CURRENT track first entering a detector
221 // (as given by mLastPrincipalTrackEntered)
222 // This is given as index where to find in mHits container
223 int mCurrentHitsIndices[NUMDETS][NUMSECS] = {-1};
224
225 static constexpr int ZNRADIUSBINS = 18;
226 static constexpr int ZPRADIUSBINS = 28;
227 static constexpr int ANGLEBINS = 90;
228
229 float mLightTableZN[4][ANGLEBINS][ZNRADIUSBINS] = {1.};
230 float mLightTableZP[4][ANGLEBINS][ZPRADIUSBINS] = {1.};
231
232 SpatialPhotonResponse mNeutronResponseImage;
233 // there is only one proton detector per side
234 SpatialPhotonResponse mProtonResponseImage;
235
236 TParticle mCurrentPrincipalParticle{};
237
238 // collecting the responses for the current event
239 using ParticlePhotonResponse = std::vector<std::pair<TParticle,
240 std::pair<SpatialPhotonResponse, SpatialPhotonResponse>>>;
241
242 ParticlePhotonResponse mResponses;
243 ParticlePhotonResponse* mResponsesPtr = &mResponses;
244
245// fastsim model wrapper
246#ifdef ZDC_FASTSIM_ONNX
247 fastsim::NeuralFastSimulation* mFastSimClassifier = nullptr;
248 fastsim::NeuralFastSimulation* mFastSimModelNeutron = nullptr;
249 fastsim::NeuralFastSimulation* mFastSimModelProton = nullptr;
250
251 // Scalers for models inputs
252 fastsim::processors::StandardScaler* mClassifierScaler = nullptr;
253 fastsim::processors::StandardScaler* mModelScalerNeutron = nullptr;
254 fastsim::processors::StandardScaler* mModelScalerProton = nullptr;
255
256 // container for fastsim model responses
257 using FastSimResults = std::vector<std::array<long, 5>>;
258 FastSimResults mFastSimResults;
259
260 // converts FastSim model results to Hit
261 bool FastSimToHits(const Ort::Value& response, const TParticle& particle, int detector);
262
263 // determines detector geometry "pixel sizes"
264 constexpr std::pair<const int, const int> determineDetectorSize(int detector)
265 {
266 if (detector == ZNA || detector == ZNC) {
268 } else if (detector == ZPA || detector == ZPC) {
270 } else {
271 return {-1, -1};
272 }
273 }
274#endif
275
276 template <typename Det>
277 friend class o2::base::DetImpl;
278 ClassDefOverride(Detector, 1);
279};
280} // namespace o2::zdc
281
282#ifdef USESHM
283namespace o2
284{
285namespace base
286{
287template <>
288struct UseShm<o2::zdc::Detector> {
289 static constexpr bool value = true;
290};
291} // namespace base
292} // namespace o2
293#endif
294
295#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:605
void BeginPrimary() final
void addAlignableVolumes() const override
declare alignable volumes of detector
Definition Detector.h:110
void ConstructGeometry() final
Definition Detector.cxx:323
void Register() override
Definition Detector.cxx:301
void InitializeO2Detector() final
Definition Detector.cxx:181
void FinishPrimary() final
~Detector() override=default
Bool_t ProcessHits(FairVolume *v=nullptr) final
Definition Detector.cxx:385
void EndOfEvent() final
Definition Detector.cxx:292
bool createHitsFromImage(SpatialPhotonResponse const &image, int detector)
Definition Detector.cxx:531
void Reset() final
Definition Detector.cxx:315
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 ...
Defining DataPointCompositeObject explicitly as copiable.