Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:23

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 TChain;
0020 class TTree;
0021 
0022 namespace Acts {
0023 class Surface;
0024 class TrackingVolume;
0025 }  // namespace Acts
0026 
0027 namespace ActsPlugins {
0028 
0029 /// Simple payload class that can be wrapped for reading
0030 /// and writing.
0031 class RootMaterialTrackIo {
0032  public:
0033   struct Config {
0034     /// Whether to store pre- and post-step information
0035     bool prePostStepInfo = false;
0036     /// Whether to store surface information
0037     bool surfaceInfo = false;
0038     /// Whether to store volume information
0039     bool volumeInfo = false;
0040     /// Whether to recalculate totals from the steps
0041     bool recalculateTotals = false;
0042   };
0043 
0044   /// @brief Constructor from config struct
0045   ///
0046   /// @param cfg the configuration for the accessor
0047   explicit RootMaterialTrackIo(const Config& cfg) : m_cfg(cfg) {}
0048 
0049   /// @brief Destructor
0050   ~RootMaterialTrackIo() = default;
0051 
0052   /// @brief sets the branch connection for reading from a file
0053   ///
0054   /// @param materialChain the TChain to read the material track from
0055   void connectForRead(TChain& materialChain);
0056 
0057   /// @brief sets the branch connection for writing to a file
0058   ///
0059   /// @param materialTree the TTree to write the material track to
0060   void connectForWrite(TTree& materialTree);
0061 
0062   /// @brief Write the material track to the tree
0063   ///
0064   /// @param gctx the geometry context
0065   /// @param eventNum the event number to write
0066   /// @param materialTrack the material track to be written out
0067   ///
0068   /// @note the caller has to do the TTree::Fill() after this call
0069   void write(const Acts::GeometryContext& gctx, std::uint32_t eventNum,
0070              const Acts::RecordedMaterialTrack& materialTrack);
0071 
0072   /// @brief Read the material track from the tree
0073   ///
0074   /// @note the caller has to do the TChain::GetEntry() before this call
0075   ///
0076   /// @return the material track
0077   Acts::RecordedMaterialTrack read() const;
0078 
0079  private:
0080   struct MateriaSummaryPayload {
0081     /// start global x
0082     float vX = 0;
0083     /// start global y
0084     float vY = 0;
0085     /// start global z
0086     float vZ = 0;
0087     /// start global momentum x
0088     float vPx = 0;
0089     /// start global momentum y
0090     float vPy = 0;
0091     /// start global momentum z
0092     float vPz = 0;
0093     /// start phi direction
0094     float vPhi = 0;
0095     /// start eta direction
0096     float vEta = 0;
0097     /// thickness in X0/L0
0098     float tX0 = 0;
0099     /// thickness in X0/L0
0100     float tL0 = 0;
0101   };
0102 
0103   struct MaterialStepPayload {
0104     /// (pre-)step x position (optional)
0105     std::vector<float> stepXs;
0106     /// (pre-)step y position (optional)
0107     std::vector<float> stepYs;
0108     /// (pre-)step z position (optional)
0109     std::vector<float> stepZs;
0110     /// (post-)step x position (optional)
0111     std::vector<float> stepXe;
0112     /// (post-)step y position (optional)
0113     std::vector<float> stepYe;
0114     /// (post-)step z position (optional)
0115     std::vector<float> stepZe;
0116 
0117     /// step x position
0118     std::vector<float> stepX;
0119     std::vector<float>* stepXPtr = &stepX;
0120     /// step y position
0121     std::vector<float> stepY;
0122     std::vector<float>* stepYPtr = &stepY;
0123     /// step z position
0124     std::vector<float> stepZ;
0125     std::vector<float>* stepZPtr = &stepZ;
0126     /// step radial position
0127     std::vector<float> stepR;
0128     /// step x direction
0129     std::vector<float> stepDx;
0130     std::vector<float>* stepDxPtr = &stepDx;
0131     /// step y direction
0132     std::vector<float> stepDy;
0133     std::vector<float>* stepDyPtr = &stepDy;
0134     /// step z direction
0135     std::vector<float> stepDz;
0136     std::vector<float>* stepDzPtr = &stepDz;
0137     /// step length
0138     std::vector<float> stepLength;
0139     std::vector<float>* stepLengthPtr = &stepLength;
0140     /// step material x0
0141     std::vector<float> stepMatX0;
0142     std::vector<float>* stepMatX0Ptr = &stepMatX0;
0143     /// step material l0
0144     std::vector<float> stepMatL0;
0145     std::vector<float>* stepMatL0Ptr = &stepMatL0;
0146     /// step material A
0147     std::vector<float> stepMatA;
0148     std::vector<float>* stepMatAPtr = &stepMatA;
0149     /// step material Z
0150     std::vector<float> stepMatZ;
0151     std::vector<float>* stepMatZPtr = &stepMatZ;
0152     /// step material rho
0153     std::vector<float> stepMatRho;
0154     std::vector<float>* stepMatRhoPtr = &stepMatRho;
0155   };
0156 
0157   struct MaterialSurfacePayload {
0158     /// ID of the surface associated with the step
0159     std::vector<std::uint64_t> surfaceId;
0160     std::vector<std::uint64_t>* surfaceIdPtr = &surfaceId;
0161     /// x position of the center of the surface associated with the step
0162     std::vector<float> surfaceX;
0163     std::vector<float>* surfaceXPtr = &surfaceX;
0164     /// y position of the center of the surface associated with the step
0165     std::vector<float> surfaceY;
0166     std::vector<float>* surfaceYPtr = &surfaceY;
0167     /// z position of the center of the surface associated with the step
0168     std::vector<float> surfaceZ;
0169     std::vector<float>* surfaceZPtr = &surfaceZ;
0170     /// r position of the center of the surface associated with the step
0171     std::vector<float> surfaceR;
0172     /// distance to the surface
0173     std::vector<float> surfaceDistance;
0174     /// path correction when associating material to the given surface
0175     std::vector<float> surfacePathCorrection;
0176     std::vector<float>* surfacePathCorrectionPtr = &surfacePathCorrection;
0177   };
0178 
0179   struct MaterialVolumePayload {
0180     /// ID of the volume associated with the step
0181     std::vector<std::uint64_t> volumeId;
0182   };
0183 
0184   /// The configuration for the accessor
0185   Config m_cfg;
0186 
0187   /// Event identifier.
0188   std::uint32_t m_eventId = 0;
0189 
0190   /// The entry numbers for accessing events in increased order (there could be
0191   /// multiple entries corresponding to one event number)
0192   std::vector<long long> m_entryNumbers = {};
0193 
0194   /// The material summary payload
0195   MateriaSummaryPayload m_summaryPayload = {};
0196 
0197   /// The material step payload
0198   MaterialStepPayload m_stepPayload = {};
0199 
0200   /// The material surface payload
0201   MaterialSurfacePayload m_surfacePayload = {};
0202 
0203   /// The material volume payload
0204   MaterialVolumePayload m_volumePayload = {};
0205 };
0206 
0207 }  // namespace ActsPlugins