Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:12:59

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef EDM4HEP_MutableMCParticle_H
0004 #define EDM4HEP_MutableMCParticle_H
0005 
0006 #include "edm4hep/MCParticleObj.h"
0007 // Make the immutable class available from its mutable version but not vice versa
0008 #include "edm4hep/MCParticle.h"
0009 
0010 #include "edm4hep/Vector3d.h"
0011 #include "podio/RelationRange.h"
0012 #include <cmath>
0013 #include <cstdint>
0014 #include <edm4hep/FeatureFlags.h>
0015 #include <edm4hep/utils/bit_utils.h>
0016 #include <vector>
0017 
0018 #include "podio/utilities/MaybeSharedPtr.h"
0019 
0020 #include <cstdint>
0021 
0022 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0023 #include "nlohmann/json_fwd.hpp"
0024 #endif
0025 
0026 // forward declarations
0027 namespace edm4hep {
0028 class MCParticleCollection;
0029 }
0030 
0031 namespace edm4hep {
0032 
0033 /** @class MutableMCParticle
0034  *  The Monte Carlo particle - based on the lcio::MCParticle.
0035  *  @author: EDM4hep authors
0036  */
0037 class MutableMCParticle {
0038 
0039   friend class MCParticleCollection;
0040   friend class MCParticleMutableCollectionIterator;
0041   friend class MCParticle;
0042 
0043 public:
0044   using object_type = MCParticle;
0045   using collection_type = MCParticleCollection;
0046 
0047   /// default constructor
0048   MutableMCParticle() = default;
0049 
0050   /// Constructor initializing all members
0051   MutableMCParticle(const std::int32_t PDG, const std::int32_t generatorStatus, const std::int32_t simulatorStatus,
0052                     const float charge, const float time, const double mass, const edm4hep::Vector3d& vertex,
0053                     const edm4hep::Vector3d& endpoint, const edm4hep::Vector3d& momentum,
0054                     const edm4hep::Vector3d& momentumAtEndpoint, const std::int32_t helicity);
0055 
0056   /// copy constructor
0057   MutableMCParticle(const MutableMCParticle& other) = default;
0058 
0059   /// copy-assignment operator
0060   MutableMCParticle& operator=(MutableMCParticle other) &; // Rebind this to other's internal object
0061   MutableMCParticle&
0062   operator=(MutableMCParticle other) && = delete; // Prevent rebinding temporary as the changes wouldn't persist
0063 
0064   /// create a mutable deep-copy of the object with identical relations
0065   /// if cloneRelations=false, the relations are not cloned and will be empty
0066   MutableMCParticle clone(bool cloneRelations = true) const;
0067 
0068   /// destructor
0069   ~MutableMCParticle() = default;
0070 
0071 public:
0072   /// Access the PDG code of the particle
0073   std::int32_t getPDG() const;
0074 
0075   /// Access the status of the particle as defined by the generator
0076   std::int32_t getGeneratorStatus() const;
0077 
0078   /// Access the status of the particle from the simulation program - use BIT constants below
0079   std::int32_t getSimulatorStatus() const;
0080 
0081   /// Access the particle charge [e]
0082   float getCharge() const;
0083 
0084   /// Access the creation time of the particle in wrt. the event, e.g. for preassigned decays or decays in flight from
0085   /// the simulator [ns]
0086   float getTime() const;
0087 
0088   /// Access the mass of the particle [GeV]
0089   double getMass() const;
0090 
0091   /// Access the production vertex of the particle [mm]
0092   const edm4hep::Vector3d& getVertex() const;
0093 
0094   /// Access the endpoint of the particle [mm]
0095   const edm4hep::Vector3d& getEndpoint() const;
0096 
0097   /// Access the particle 3-momentum at the production vertex [GeV]
0098   const edm4hep::Vector3d& getMomentum() const;
0099 
0100   /// Access the particle 3-momentum at the endpoint [GeV]
0101   const edm4hep::Vector3d& getMomentumAtEndpoint() const;
0102 
0103   /// Access the particle helicity (9 if unset)
0104   std::int32_t getHelicity() const;
0105 
0106   /// Set the PDG code of the particle
0107   void setPDG(const std::int32_t PDG);
0108   /// Get mutable reference to PDG code of the particle
0109   std::int32_t& getPDG();
0110   /// Get reference to PDG code of the particle
0111   [[deprecated("use getPDG instead")]] std::int32_t& PDG();
0112 
0113   /// Set the status of the particle as defined by the generator
0114   void setGeneratorStatus(const std::int32_t generatorStatus);
0115   /// Get mutable reference to status of the particle as defined by the generator
0116   std::int32_t& getGeneratorStatus();
0117   /// Get reference to status of the particle as defined by the generator
0118   [[deprecated("use getGeneratorStatus instead")]] std::int32_t& generatorStatus();
0119 
0120   /// Set the status of the particle from the simulation program - use BIT constants below
0121   void setSimulatorStatus(const std::int32_t simulatorStatus);
0122   /// Get mutable reference to status of the particle from the simulation program - use BIT constants below
0123   std::int32_t& getSimulatorStatus();
0124   /// Get reference to status of the particle from the simulation program - use BIT constants below
0125   [[deprecated("use getSimulatorStatus instead")]] std::int32_t& simulatorStatus();
0126 
0127   /// Set the particle charge [e]
0128   void setCharge(const float charge);
0129   /// Get mutable reference to particle charge [e]
0130   float& getCharge();
0131   /// Get reference to particle charge [e]
0132   [[deprecated("use getCharge instead")]] float& charge();
0133 
0134   /// Set the creation time of the particle in wrt. the event, e.g. for preassigned decays or decays in flight from the
0135   /// simulator [ns]
0136   void setTime(const float time);
0137   /// Get mutable reference to creation time of the particle in wrt. the event, e.g. for preassigned decays or decays in
0138   /// flight from the simulator [ns]
0139   float& getTime();
0140   /// Get reference to creation time of the particle in wrt. the event, e.g. for preassigned decays or decays in flight
0141   /// from the simulator [ns]
0142   [[deprecated("use getTime instead")]] float& time();
0143 
0144   /// Set the mass of the particle [GeV]
0145   void setMass(const double mass);
0146   /// Get mutable reference to mass of the particle [GeV]
0147   double& getMass();
0148   /// Get reference to mass of the particle [GeV]
0149   [[deprecated("use getMass instead")]] double& mass();
0150 
0151   /// Set the production vertex of the particle [mm]
0152   void setVertex(const edm4hep::Vector3d& vertex);
0153   /// Get mutable reference to production vertex of the particle [mm]
0154   edm4hep::Vector3d& getVertex();
0155   /// Get reference to production vertex of the particle [mm]
0156   [[deprecated("use getVertex instead")]] edm4hep::Vector3d& vertex();
0157 
0158   /// Set the endpoint of the particle [mm]
0159   void setEndpoint(const edm4hep::Vector3d& endpoint);
0160   /// Get mutable reference to endpoint of the particle [mm]
0161   edm4hep::Vector3d& getEndpoint();
0162   /// Get reference to endpoint of the particle [mm]
0163   [[deprecated("use getEndpoint instead")]] edm4hep::Vector3d& endpoint();
0164 
0165   /// Set the particle 3-momentum at the production vertex [GeV]
0166   void setMomentum(const edm4hep::Vector3d& momentum);
0167   /// Get mutable reference to particle 3-momentum at the production vertex [GeV]
0168   edm4hep::Vector3d& getMomentum();
0169   /// Get reference to particle 3-momentum at the production vertex [GeV]
0170   [[deprecated("use getMomentum instead")]] edm4hep::Vector3d& momentum();
0171 
0172   /// Set the particle 3-momentum at the endpoint [GeV]
0173   void setMomentumAtEndpoint(const edm4hep::Vector3d& momentumAtEndpoint);
0174   /// Get mutable reference to particle 3-momentum at the endpoint [GeV]
0175   edm4hep::Vector3d& getMomentumAtEndpoint();
0176   /// Get reference to particle 3-momentum at the endpoint [GeV]
0177   [[deprecated("use getMomentumAtEndpoint instead")]] edm4hep::Vector3d& momentumAtEndpoint();
0178 
0179   /// Set the particle helicity (9 if unset)
0180   void setHelicity(const std::int32_t helicity);
0181   /// Get mutable reference to particle helicity (9 if unset)
0182   std::int32_t& getHelicity();
0183   /// Get reference to particle helicity (9 if unset)
0184   [[deprecated("use getHelicity instead")]] std::int32_t& helicity();
0185 
0186   void addToParents(const edm4hep::MCParticle&);
0187   std::size_t parents_size() const;
0188   edm4hep::MCParticle getParents(std::size_t) const;
0189   std::vector<edm4hep::MCParticle>::const_iterator parents_begin() const;
0190   std::vector<edm4hep::MCParticle>::const_iterator parents_end() const;
0191   podio::RelationRange<edm4hep::MCParticle> getParents() const;
0192   void addToDaughters(const edm4hep::MCParticle&);
0193   std::size_t daughters_size() const;
0194   edm4hep::MCParticle getDaughters(std::size_t) const;
0195   std::vector<edm4hep::MCParticle>::const_iterator daughters_begin() const;
0196   std::vector<edm4hep::MCParticle>::const_iterator daughters_end() const;
0197   podio::RelationRange<edm4hep::MCParticle> getDaughters() const;
0198 
0199   // define the bit positions for the simulation flag
0200   static const int BITCreatedInSimulation = 30;
0201   static const int BITBackscatter = 29;
0202   static const int BITVertexIsNotEndpointOfParent = 28;
0203   static const int BITDecayedInTracker = 27;
0204   static const int BITDecayedInCalorimeter = 26;
0205   static const int BITLeftDetector = 25;
0206   static const int BITStopped = 24;
0207   static const int BITOverlay = 23;
0208   /// return energy computed from momentum and mass
0209   double getEnergy() const {
0210     return std::sqrt(getMomentum()[0] * getMomentum()[0] + getMomentum()[1] * getMomentum()[1] +
0211                      getMomentum()[2] * getMomentum()[2] + getMass() * getMass());
0212   }
0213 
0214   /// True if the particle has been created by the simulation program (rather than the generator).
0215   bool isCreatedInSimulation() const { return utils::checkBit(getSimulatorStatus(), BITCreatedInSimulation); }
0216   /// True if the particle is the result of a backscatter from a calorimeter shower.
0217   bool isBackscatter() const { return utils::checkBit(getSimulatorStatus(), BITBackscatter); }
0218   /// True if the particle's vertex is not the endpoint of the  parent particle.
0219   bool vertexIsNotEndpointOfParent() const {
0220     return utils::checkBit(getSimulatorStatus(), BITVertexIsNotEndpointOfParent);
0221   }
0222   /// True if the particle has interacted in a tracking region.
0223   bool isDecayedInTracker() const { return utils::checkBit(getSimulatorStatus(), BITDecayedInTracker); }
0224   /// True if the particle has interacted in a calorimeter region.
0225   bool isDecayedInCalorimeter() const { return utils::checkBit(getSimulatorStatus(), BITDecayedInCalorimeter); }
0226   /// True if the particle has left the world volume undecayed.
0227   bool hasLeftDetector() const { return utils::checkBit(getSimulatorStatus(), BITLeftDetector); }
0228   /// True if the particle has been stopped by the simulation program.
0229   bool isStopped() const { return utils::checkBit(getSimulatorStatus(), BITStopped); }
0230   /// True if the particle has been overlaid by the simulation (or digitization)  program.
0231   bool isOverlay() const { return utils::checkBit(getSimulatorStatus(), BITOverlay); }
0232   /// Check if this particle has a set helicity
0233   bool hasHelicity() const noexcept { return getHelicity() != 9; }
0234 
0235   void setCreatedInSimulation(bool bitval) {
0236     setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITCreatedInSimulation, bitval));
0237   }
0238   void setBackscatter(bool bitval) { setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITBackscatter, bitval)); }
0239   void setVertexIsNotEndpointOfParent(bool bitval) {
0240     setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITVertexIsNotEndpointOfParent, bitval));
0241   }
0242   void setDecayedInTracker(bool bitval) {
0243     setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITDecayedInTracker, bitval));
0244   }
0245   void setDecayedInCalorimeter(bool bitval) {
0246     setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITDecayedInCalorimeter, bitval));
0247   }
0248   void setHasLeftDetector(bool bitval) {
0249     setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITLeftDetector, bitval));
0250   }
0251   void setStopped(bool bitval) { setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITStopped, bitval)); }
0252   void setOverlay(bool bitval) { setSimulatorStatus(utils::setBit(getSimulatorStatus(), BITOverlay, bitval)); }
0253 
0254   /// check whether the object is actually available
0255   bool isAvailable() const;
0256   /// disconnect from MCParticleObj instance
0257   void unlink() { m_obj = podio::utils::MaybeSharedPtr<MCParticleObj>{nullptr}; }
0258 
0259   bool operator==(const MutableMCParticle& other) const { return m_obj == other.m_obj; }
0260   bool operator==(const MCParticle& other) const;
0261 
0262   bool operator!=(const MutableMCParticle& other) const { return !(*this == other); }
0263   bool operator!=(const MCParticle& other) const { return !(*this == other); }
0264 
0265   // less comparison operator, so that objects can be e.g. stored in sets.
0266   bool operator<(const MutableMCParticle& other) const {
0267     return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other);
0268   }
0269 
0270   podio::ObjectID id() const { return getObjectID(); }
0271 
0272   const podio::ObjectID getObjectID() const;
0273 
0274   friend std::hash<MutableMCParticle>;
0275 
0276   friend void swap(MutableMCParticle& a, MutableMCParticle& b) {
0277     using std::swap;
0278     swap(a.m_obj, b.m_obj); // swap out the internal pointers
0279   }
0280 
0281 private:
0282   /// constructor from existing MCParticleObj
0283   explicit MutableMCParticle(podio::utils::MaybeSharedPtr<MCParticleObj> obj);
0284 
0285   podio::utils::MaybeSharedPtr<MCParticleObj> m_obj{new MCParticleObj{}, podio::utils::MarkOwned};
0286 };
0287 
0288 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0289 void to_json(nlohmann::json& j, const MutableMCParticle& value);
0290 #endif
0291 
0292 } // namespace edm4hep
0293 
0294 template <>
0295 struct std::hash<edm4hep::MutableMCParticle> {
0296   std::size_t operator()(const edm4hep::MutableMCParticle& obj) const {
0297     return std::hash<edm4hep::MCParticleObj*>{}(obj.m_obj.get());
0298   }
0299 };
0300 
0301 #endif