|
| 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 | +/// \file Hit.h |
| 13 | +/// \brief Generic hit type for externally injected (CAD-derived) sensitive detectors |
| 14 | +/// |
| 15 | +/// o2::ext::Hit is a deliberately rich, detector-agnostic hit. A single external |
| 16 | +/// hit type lets an arbitrary number of o2::ext::ExternalDetector instances (each |
| 17 | +/// tied to a different DetID) share one wire format, so that the o2-sim hit merger |
| 18 | +/// only ever has to know how to (de)serialize this one type, independently of how |
| 19 | +/// many external detectors are configured or what their sensitive action does. |
| 20 | +/// |
| 21 | +/// It stores entrance and exit position, the momentum, energy and energy loss, the |
| 22 | +/// time, the track length in the volume, the PDG code and the MC status flags at |
| 23 | +/// entrance/exit, so that most information an external sensitive action might want |
| 24 | +/// to keep is available downstream. |
| 25 | + |
| 26 | +#ifndef ALICEO2_EXT_HIT_H |
| 27 | +#define ALICEO2_EXT_HIT_H |
| 28 | + |
| 29 | +#include "SimulationDataFormat/BaseHits.h" // for BasicXYZEHit |
| 30 | +#include "CommonUtils/ShmAllocator.h" |
| 31 | +#include "Rtypes.h" |
| 32 | +#include "TVector3.h" |
| 33 | +#include <iosfwd> |
| 34 | + |
| 35 | +namespace o2::ext |
| 36 | +{ |
| 37 | + |
| 38 | +class Hit : public o2::BasicXYZEHit<float, float> |
| 39 | +{ |
| 40 | + public: |
| 41 | + enum HitStatus_t { |
| 42 | + kTrackEntering = 0x1, |
| 43 | + kTrackInside = 0x1 << 1, |
| 44 | + kTrackExiting = 0x1 << 2, |
| 45 | + kTrackOut = 0x1 << 3, |
| 46 | + kTrackStopped = 0x1 << 4, |
| 47 | + kTrackAlive = 0x1 << 5 |
| 48 | + }; |
| 49 | + |
| 50 | + Hit() = default; |
| 51 | + |
| 52 | + /// \param trackID index of the MCTrack |
| 53 | + /// \param sensorID index of the sensitive volume (per-detector running id) |
| 54 | + /// \param startPos coordinates at entrance to the active volume [cm] |
| 55 | + /// \param endPos coordinates at exit of the active volume [cm] |
| 56 | + /// \param startMom momentum of the track at entrance [GeV] |
| 57 | + /// \param startE total energy at entrance [GeV] |
| 58 | + /// \param endTime time at exit [ns] |
| 59 | + /// \param eLoss energy deposited in the volume [GeV] |
| 60 | + /// \param startStatus MC status flags at entrance |
| 61 | + /// \param endStatus MC status flags at exit |
| 62 | + /// \param pdg PDG code of the track (optional) |
| 63 | + /// \param length track length inside the volume [cm] (optional) |
| 64 | + Hit(int trackID, unsigned short sensorID, const TVector3& startPos, const TVector3& endPos, |
| 65 | + const TVector3& startMom, double startE, double endTime, double eLoss, |
| 66 | + unsigned char startStatus, unsigned char endStatus, int pdg = 0, float length = 0.f) |
| 67 | + : BasicXYZEHit(endPos.X(), endPos.Y(), endPos.Z(), endTime, eLoss, trackID, sensorID), |
| 68 | + mMomentum(startMom.Px(), startMom.Py(), startMom.Pz()), |
| 69 | + mPosStart(startPos.X(), startPos.Y(), startPos.Z()), |
| 70 | + mE(startE), |
| 71 | + mLength(length), |
| 72 | + mPdg(pdg), |
| 73 | + mTrackStatusEnd(endStatus), |
| 74 | + mTrackStatusStart(startStatus) |
| 75 | + { |
| 76 | + } |
| 77 | + |
| 78 | + // entrance position |
| 79 | + math_utils::Point3D<float> GetPosStart() const { return mPosStart; } |
| 80 | + float GetStartX() const { return mPosStart.X(); } |
| 81 | + float GetStartY() const { return mPosStart.Y(); } |
| 82 | + float GetStartZ() const { return mPosStart.Z(); } |
| 83 | + void SetPosStart(const math_utils::Point3D<float>& p) { mPosStart = p; } |
| 84 | + |
| 85 | + // momentum / energy |
| 86 | + math_utils::Vector3D<float> GetMomentum() const { return mMomentum; } |
| 87 | + math_utils::Vector3D<float>& GetMomentum() { return mMomentum; } |
| 88 | + float GetPx() const { return mMomentum.X(); } |
| 89 | + float GetPy() const { return mMomentum.Y(); } |
| 90 | + float GetPz() const { return mMomentum.Z(); } |
| 91 | + float GetE() const { return mE; } |
| 92 | + float GetTotalEnergy() const { return mE; } |
| 93 | + |
| 94 | + // extra bookkeeping |
| 95 | + float GetLength() const { return mLength; } |
| 96 | + void SetLength(float l) { mLength = l; } |
| 97 | + int GetPdg() const { return mPdg; } |
| 98 | + void SetPdg(int pdg) { mPdg = pdg; } |
| 99 | + |
| 100 | + // status flags |
| 101 | + unsigned char GetStatusStart() const { return mTrackStatusStart; } |
| 102 | + unsigned char GetStatusEnd() const { return mTrackStatusEnd; } |
| 103 | + bool IsEntering() const { return mTrackStatusEnd & kTrackEntering; } |
| 104 | + bool IsInside() const { return mTrackStatusEnd & kTrackInside; } |
| 105 | + bool IsExiting() const { return mTrackStatusEnd & kTrackExiting; } |
| 106 | + bool IsOut() const { return mTrackStatusEnd & kTrackOut; } |
| 107 | + bool IsStopped() const { return mTrackStatusEnd & kTrackStopped; } |
| 108 | + bool IsAlive() const { return mTrackStatusEnd & kTrackAlive; } |
| 109 | + |
| 110 | + friend std::ostream& operator<<(std::ostream& of, const Hit& point) |
| 111 | + { |
| 112 | + of << "-I- o2::ext::Hit for track " << point.GetTrackID() << " in sensor " << point.GetDetectorID(); |
| 113 | + return of; |
| 114 | + } |
| 115 | + |
| 116 | + private: |
| 117 | + math_utils::Vector3D<float> mMomentum; ///< momentum at entrance |
| 118 | + math_utils::Point3D<float> mPosStart; ///< position at entrance (base mPos holds the exit position) |
| 119 | + float mE; ///< total energy at entrance |
| 120 | + float mLength; ///< track length inside the volume |
| 121 | + int mPdg; ///< PDG code of the track |
| 122 | + unsigned char mTrackStatusEnd; ///< MC status flag at exit |
| 123 | + unsigned char mTrackStatusStart; ///< MC status flag at entrance |
| 124 | + |
| 125 | + ClassDefNV(Hit, 1); |
| 126 | +}; |
| 127 | + |
| 128 | +} // namespace o2::ext |
| 129 | + |
| 130 | +#ifdef USESHM |
| 131 | +namespace std |
| 132 | +{ |
| 133 | +template <> |
| 134 | +class allocator<o2::ext::Hit> : public o2::utils::ShmAllocator<o2::ext::Hit> |
| 135 | +{ |
| 136 | +}; |
| 137 | +} // namespace std |
| 138 | +#endif |
| 139 | + |
| 140 | +#endif // ALICEO2_EXT_HIT_H |
0 commit comments