Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-10 09:28:25

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Material/MaterialInteraction.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 
0015 #include <memory>
0016 #include <utility>
0017 #include <vector>
0018 
0019 class TTree;
0020 
0021 namespace Acts {
0022 class Surface;
0023 class TrackingVolume;
0024 }  // namespace Acts
0025 
0026 namespace ActsPlugins {
0027 /// @addtogroup root_plugin
0028 /// @{
0029 
0030 /// Simple payload class that can be wrapped for reading
0031 /// and writing.
0032 class RootMaterialTrackIo {
0033  public:
0034   /// Configuration struct for material track I/O
0035   struct Config {
0036     /// Whether to store pre- and post-step information
0037     bool prePostStepInfo = false;
0038     /// Whether to store surface information
0039     bool surfaceInfo = false;
0040     /// Whether to store volume information
0041     bool volumeInfo = false;
0042     /// Whether to recalculate totals from the steps
0043     bool recalculateTotals = false;
0044   };
0045 
0046   /// Constructor from config struct
0047   ///
0048   /// @param cfg the configuration for the accessor
0049   explicit RootMaterialTrackIo(const Config& cfg) : m_cfg(cfg) {}
0050 
0051   /// Destructor
0052   ~RootMaterialTrackIo() = default;
0053 
0054   /// sets the branch connection for reading from a file
0055   ///
0056   /// @param materialChain the TTree to read the material track from
0057   void connectForRead(TTree& materialChain);
0058 
0059   /// sets the branch connection for writing to a file
0060   ///
0061   /// @param materialTree the TTree to write the material track to
0062   void connectForWrite(TTree& materialTree);
0063 
0064   /// Write the material track to the tree
0065   ///
0066   /// @param gctx the geometry context
0067   /// @param eventNum the event number to write
0068   /// @param materialTrack the material track to be written out
0069   ///
0070   /// @note the caller has to do the TTree::Fill() after this call
0071   void write(const Acts::GeometryContext& gctx, std::uint32_t eventNum,
0072              const Acts::RecordedMaterialTrack& materialTrack);
0073 
0074   /// Write the material track to the tree, without a geometry context
0075   ///
0076   /// For material tracks that are not associated to a geometry, e.g. straight
0077   /// from a Geant4 material recording. Without a geometry context, no surface
0078   /// information can be computed.
0079   ///
0080   /// @param eventNum the event number to write
0081   /// @param materialTrack the material track to be written out
0082   ///
0083   /// @throws std::invalid_argument if configured to store surface information
0084   ///
0085   /// @note the caller has to do the TTree::Fill() after this call
0086   void write(std::uint32_t eventNum,
0087              const Acts::RecordedMaterialTrack& materialTrack);
0088 
0089   /// Read the material track from the tree
0090   ///
0091   /// @note the caller has to do the TChain::GetEntry() before this call
0092   ///
0093   /// @return the material track
0094   Acts::RecordedMaterialTrack read() const;
0095 
0096   /// @return The current event ID
0097   std::uint32_t eventId() const;
0098 
0099  private:
0100   struct MateriaSummaryPayload {
0101     /// start global x
0102     float vX = 0;
0103     /// start global y
0104     float vY = 0;
0105     /// start global z
0106     float vZ = 0;
0107     /// start global momentum x
0108     float vPx = 0;
0109     /// start global momentum y
0110     float vPy = 0;
0111     /// start global momentum z
0112     float vPz = 0;
0113     /// start phi direction
0114     float vPhi = 0;
0115     /// start eta direction
0116     float vEta = 0;
0117     /// thickness in X0/L0
0118     float tX0 = 0;
0119     /// thickness in X0/L0
0120     float tL0 = 0;
0121   };
0122 
0123   struct MaterialStepPayload {
0124     /// (pre-)step x position (optional)
0125     std::vector<float> stepXs;
0126     /// (pre-)step y position (optional)
0127     std::vector<float> stepYs;
0128     /// (pre-)step z position (optional)
0129     std::vector<float> stepZs;
0130     /// (post-)step x position (optional)
0131     std::vector<float> stepXe;
0132     /// (post-)step y position (optional)
0133     std::vector<float> stepYe;
0134     /// (post-)step z position (optional)
0135     std::vector<float> stepZe;
0136 
0137     /// step x position
0138     std::vector<float> stepX;
0139     std::vector<float>* stepXPtr = &stepX;
0140     /// step y position
0141     std::vector<float> stepY;
0142     std::vector<float>* stepYPtr = &stepY;
0143     /// step z position
0144     std::vector<float> stepZ;
0145     std::vector<float>* stepZPtr = &stepZ;
0146     /// step radial position
0147     std::vector<float> stepR;
0148     /// step x direction
0149     std::vector<float> stepDx;
0150     std::vector<float>* stepDxPtr = &stepDx;
0151     /// step y direction
0152     std::vector<float> stepDy;
0153     std::vector<float>* stepDyPtr = &stepDy;
0154     /// step z direction
0155     std::vector<float> stepDz;
0156     std::vector<float>* stepDzPtr = &stepDz;
0157     /// step length
0158     std::vector<float> stepLength;
0159     std::vector<float>* stepLengthPtr = &stepLength;
0160     /// step material x0
0161     std::vector<float> stepMatX0;
0162     std::vector<float>* stepMatX0Ptr = &stepMatX0;
0163     /// step material l0
0164     std::vector<float> stepMatL0;
0165     std::vector<float>* stepMatL0Ptr = &stepMatL0;
0166     /// step material A
0167     std::vector<float> stepMatA;
0168     std::vector<float>* stepMatAPtr = &stepMatA;
0169     /// step material Z
0170     std::vector<float> stepMatZ;
0171     std::vector<float>* stepMatZPtr = &stepMatZ;
0172     /// step material rho
0173     std::vector<float> stepMatRho;
0174     std::vector<float>* stepMatRhoPtr = &stepMatRho;
0175     /// step material element
0176     std::vector<std::vector<unsigned int>> stepElementZ;
0177     std::vector<std::vector<unsigned int>>* stepElementZPtr = &stepElementZ;
0178     /// step material fraction of elements
0179     std::vector<std::vector<float>> stepFraction;
0180     std::vector<std::vector<float>>* stepFractionPtr = &stepFraction;
0181   };
0182 
0183   struct MaterialSurfacePayload {
0184     /// ID of the surface associated with the step
0185     std::vector<std::uint64_t> surfaceId;
0186     std::vector<std::uint64_t>* surfaceIdPtr = &surfaceId;
0187     /// x position of the center of the surface associated with the step
0188     std::vector<float> surfaceX;
0189     std::vector<float>* surfaceXPtr = &surfaceX;
0190     /// y position of the center of the surface associated with the step
0191     std::vector<float> surfaceY;
0192     std::vector<float>* surfaceYPtr = &surfaceY;
0193     /// z position of the center of the surface associated with the step
0194     std::vector<float> surfaceZ;
0195     std::vector<float>* surfaceZPtr = &surfaceZ;
0196     /// r position of the center of the surface associated with the step
0197     std::vector<float> surfaceR;
0198     /// distance to the surface
0199     std::vector<float> surfaceDistance;
0200     /// path correction when associating material to the given surface
0201     std::vector<float> surfacePathCorrection;
0202     std::vector<float>* surfacePathCorrectionPtr = &surfacePathCorrection;
0203   };
0204 
0205   struct MaterialVolumePayload {
0206     /// ID of the volume associated with the step
0207     std::vector<std::uint64_t> volumeId;
0208   };
0209 
0210   /// The configuration for the accessor
0211   Config m_cfg;
0212 
0213   /// Event identifier.
0214   std::uint32_t m_eventId = 0;
0215 
0216   /// The entry numbers for accessing events in increased order (there could be
0217   /// multiple entries corresponding to one event number)
0218   std::vector<long long> m_entryNumbers = {};
0219 
0220   /// The material summary payload
0221   MateriaSummaryPayload m_summaryPayload = {};
0222 
0223   /// The material step payload
0224   MaterialStepPayload m_stepPayload = {};
0225 
0226   /// The material surface payload
0227   MaterialSurfacePayload m_surfacePayload = {};
0228 
0229   /// The material volume payload
0230   MaterialVolumePayload m_volumePayload = {};
0231 };
0232 
0233 /// @}
0234 }  // namespace ActsPlugins