Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-02 08:28:24

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4ClonedSmoothTrajectory
0027 //
0028 // Class description:
0029 //
0030 // This class is identical to G4SmoothTrajectory class, but uses the
0031 // singleton G4Allocator so that the master thread can safely
0032 // delete the object instantiated by worker threads in sub-event
0033 // parallel mode. This class object should be instantiated as
0034 // a clone of G4SmoothTrajectory object.
0035 //
0036 // Makoto Asai (JLab) - Oct.2024
0037 // --------------------------------------------------------------------
0038 #ifndef G4ClonedSmoothTrajectory_hh
0039 #define G4ClonedSmoothTrajectory_hh 1
0040 
0041 #include "G4Allocator.hh"
0042 #include "G4ParticleDefinition.hh"  // Include from 'particle+matter'
0043 #include "G4ClonedSmoothTrajectoryPoint.hh"  // Include from 'tracking'
0044 #include "G4Step.hh"
0045 #include "G4Track.hh"
0046 #include "G4VTrajectory.hh"
0047 #include "G4ios.hh"  // Include from 'system'
0048 #include "globals.hh"  // Include from 'global'
0049 
0050 #include "trkgdefs.hh"
0051 #include <stdlib.h>  // Include from 'system'
0052 
0053 #include <vector>
0054 
0055 class G4Polyline;
0056 class G4SmoothTrajectory;
0057 
0058 class G4ClonedSmoothTrajectory : public G4VTrajectory
0059 {
0060   using G4TrajectoryPointContainer = std::vector<G4VTrajectoryPoint*>;
0061 
0062  public:
0063   // Constructors/Destructor
0064   //
0065   G4ClonedSmoothTrajectory() = default;
0066   G4ClonedSmoothTrajectory(const G4SmoothTrajectory&);
0067   ~G4ClonedSmoothTrajectory() override;
0068 
0069   // Operators
0070   //
0071   inline G4bool operator==(const G4ClonedSmoothTrajectory& r) const;
0072   inline void* operator new(size_t);
0073   inline void operator delete(void*);
0074 
0075   // Get/Set functions
0076   //
0077   inline G4int GetTrackID() const override { return fTrackID; }
0078   inline G4int GetParentID() const override { return fParentID; }
0079   inline G4String GetParticleName() const override { return ParticleName; }
0080   inline G4double GetCharge() const override { return PDGCharge; }
0081   inline G4int GetPDGEncoding() const override { return PDGEncoding; }
0082   inline G4double GetInitialKineticEnergy() const { return initialKineticEnergy; }
0083   inline G4ThreeVector GetInitialMomentum() const override { return initialMomentum; }
0084 
0085   // Other member functions
0086   //
0087   void ShowTrajectory(std::ostream& os = G4cout) const override;
0088   void DrawTrajectory() const override;
0089   void AppendStep(const G4Step* aStep) override;
0090   G4int GetPointEntries() const override { return (G4int)positionRecord->size(); }
0091   G4VTrajectoryPoint* GetPoint(G4int i) const override { return (*positionRecord)[i]; }
0092   void MergeTrajectory(G4VTrajectory* secondTrajectory) override;
0093 
0094   G4ParticleDefinition* GetParticleDefinition();
0095 
0096   // Get method for HEPRep style attributes
0097   //
0098   const std::map<G4String, G4AttDef>* GetAttDefs() const override;
0099   std::vector<G4AttValue>* CreateAttValues() const override;
0100 
0101  private:
0102   G4TrajectoryPointContainer* positionRecord = nullptr;
0103   G4int fTrackID = 0;
0104   G4int fParentID = 0;
0105   G4int PDGEncoding = 0;
0106   G4double PDGCharge = 0.0;
0107   G4String ParticleName = "";
0108   G4double initialKineticEnergy = 0.0;
0109   G4ThreeVector initialMomentum;
0110 };
0111 
0112 extern G4TRACKING_DLL G4Allocator<G4ClonedSmoothTrajectory>*& aClonedSmoothTrajectoryAllocator();
0113 
0114 inline void* G4ClonedSmoothTrajectory::operator new(size_t)
0115 {
0116   if (aClonedSmoothTrajectoryAllocator() == nullptr) {
0117     aClonedSmoothTrajectoryAllocator() = new G4Allocator<G4ClonedSmoothTrajectory>;
0118   }
0119   return (void*)aClonedSmoothTrajectoryAllocator()->MallocSingle();
0120 }
0121 
0122 inline void G4ClonedSmoothTrajectory::operator delete(void* aTrajectory)
0123 {
0124   aClonedSmoothTrajectoryAllocator()->FreeSingle((G4ClonedSmoothTrajectory*)aTrajectory);
0125 }
0126 
0127 inline G4bool G4ClonedSmoothTrajectory::operator==(const G4ClonedSmoothTrajectory& r) const
0128 {
0129   return (this == &r);
0130 }
0131 
0132 #endif