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/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 
0014 #include <array>
0015 #include <tuple>
0016 #include <vector>
0017 
0018 class TTree;
0019 
0020 namespace Acts {
0021 class GeometryIdentifier;
0022 }
0023 
0024 namespace ActsPlugins {
0025 
0026 /// @brief Helper class to manage the I/O of measurements and associated clusters
0027 /// to and from ROOT files.
0028 class RootMeasurementIo {
0029  public:
0030   // Configuration struct
0031   struct Config {
0032     // Indicate the reconstruction indices to be stored
0033     std::vector<Acts::BoundIndices>& recoIndices;
0034 
0035     // Indicate the cluster indices to be stored
0036     std::vector<Acts::BoundIndices>& clusterIndices;
0037   };
0038 
0039   /// Constructor from configuration struct
0040   ///
0041   /// @param config the configuration for the accessor
0042   explicit RootMeasurementIo(const Config& config);
0043 
0044   /// @brief sets the branch connection for writing to a file
0045   ///
0046   /// @param measurementTree the TTree to write the measurement track to
0047   void connectForWrite(TTree& measurementTree);
0048 
0049   /// Convenience function to register identification
0050   ///
0051   /// @param evnt The event number
0052   /// @param geoId The geometry identifier of the measurement
0053   void fillIdentification(int evnt, const Acts::GeometryIdentifier& geoId);
0054 
0055   /// Convenience function to register the truth parameters
0056   ///
0057   /// @param lp The true local position
0058   /// @param xt The true 4D global position
0059   /// @param dir The true particle direction
0060   /// @param angles The incident angles
0061   void fillTruthParameters(const Acts::Vector2& lp, const Acts::Vector4& xt,
0062                            const Acts::Vector3& dir,
0063                            const std::pair<double, double> angles);
0064 
0065   /// Convenience function to fill bound parameters
0066   ///  - abstracted to be used in different contexts
0067   ///
0068   /// @param measurement The measurement parameters
0069   /// @param variances The measurement variances (assumed diagonally)
0070   /// @param subspaceIndex The subspace indices of the measurement
0071   void fillBoundMeasurement(const std::vector<double>& measurement,
0072                             const std::vector<double>& variances,
0073                             const std::vector<unsigned int>& subspaceIndex);
0074 
0075   /// Fill global information of the cluster/measurement
0076   ///
0077   /// @param pos The global position of the cluster
0078   void fillGlobalPosition(const Acts::Vector3& pos);
0079 
0080   /// Convenience function to fill the cluster information
0081   ///  - abstracted to be used in different contexts
0082   ///
0083   /// @param channels The channel information
0084   void fillCluster(const std::vector<std::tuple<int, int, float>>& channels);
0085 
0086   /// Clear the payload
0087   void clear();
0088 
0089  private:
0090   // Names of the bound parameters
0091   static constexpr std::array<std::string, Acts::eBoundSize> bNames = {
0092       "loc0", "loc1", "phi", "theta", "qop", "time"};
0093 
0094   /// The configuration for the accessor
0095   Config m_cfg;
0096 
0097   struct MeasurementPayload {
0098     // Identification parameters
0099     int eventNr = 0;
0100     int volumeID = 0;
0101     int layerID = 0;
0102     int surfaceID = 0;
0103     int extraID = 0;
0104 
0105     // Reconstructed information
0106     std::array<float, Acts::eBoundSize> recBound = {};
0107     std::array<float, Acts::eBoundSize> varBound = {};
0108 
0109     float recGx = 0.;
0110     float recGy = 0.;
0111     float recGz = 0.;
0112 
0113     // Truth parameters
0114     std::array<float, Acts::eBoundSize> trueBound = {};
0115     float trueGx = 0.;
0116     float trueGy = 0.;
0117     float trueGz = 0.;
0118     float incidentPhi = 0.;
0119     float incidentTheta = 0.;
0120 
0121     // Residuals and pulls
0122     std::array<float, Acts::eBoundSize> residual = {};
0123     std::array<float, Acts::eBoundSize> pull = {};
0124   };
0125 
0126   struct ClusterPayload {
0127     // Cluster information
0128     int nch = 0;
0129     std::array<int, 2> clusterSize = {0, 0};
0130     std::array<std::vector<int>, 2> chId;
0131     std::vector<float> chValue = {};
0132   };
0133 
0134   MeasurementPayload m_measurementPayload;
0135   ClusterPayload m_clusterPayload;
0136 };
0137 }  // namespace ActsPlugins