Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:51:59

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 /// \file F04Trajectory.cc
0027 /// \brief Implementation of the F04Trajectory class
0028 
0029 #include "F04Trajectory.hh"
0030 
0031 #include "F04TrajectoryPoint.hh"
0032 
0033 #include "G4AttDef.hh"
0034 #include "G4AttDefStore.hh"
0035 #include "G4AttValue.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4UIcommand.hh"
0038 #include "G4UnitsTable.hh"
0039 
0040 // #define G4ATTDEBUG
0041 #ifdef G4ATTDEBUG
0042 #  include "G4AttCheck.hh"
0043 #endif
0044 
0045 G4ThreadLocal G4Allocator<F04Trajectory>* F04TrajectoryAllocator = nullptr;
0046 
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 F04Trajectory::F04Trajectory() {}
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 F04Trajectory::F04Trajectory(const G4Track* aTrack)
0054 {
0055   G4ParticleDefinition* particleDefinition = aTrack->GetDefinition();
0056   fParticleName = particleDefinition->GetParticleName();
0057   fPDGCharge = particleDefinition->GetPDGCharge();
0058   fPDGEncoding = particleDefinition->GetPDGEncoding();
0059   fTrackID = aTrack->GetTrackID();
0060   fParentID = aTrack->GetParentID();
0061   fInitialMomentum = aTrack->GetMomentum();
0062   fpPointsContainer = new TrajectoryPointContainer();
0063   // Following is for the first trajectory point
0064   fpPointsContainer->push_back(new F04TrajectoryPoint(aTrack));
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 F04Trajectory::F04Trajectory(F04Trajectory& right) : G4VTrajectory()
0070 {
0071   fParticleName = right.fParticleName;
0072   fPDGCharge = right.fPDGCharge;
0073   fPDGEncoding = right.fPDGEncoding;
0074   fTrackID = right.fTrackID;
0075   fParentID = right.fParentID;
0076   fInitialMomentum = right.fInitialMomentum;
0077   fpPointsContainer = new TrajectoryPointContainer();
0078 
0079   for (size_t i = 0; i < right.fpPointsContainer->size(); ++i) {
0080     auto rightPoint = (F04TrajectoryPoint*)((*(right.fpPointsContainer))[i]);
0081     fpPointsContainer->push_back(new F04TrajectoryPoint(*rightPoint));
0082   }
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 F04Trajectory::~F04Trajectory()
0088 {
0089   for (size_t i = 0; i < fpPointsContainer->size(); ++i) {
0090     delete (*fpPointsContainer)[i];
0091   }
0092   fpPointsContainer->clear();
0093 
0094   delete fpPointsContainer;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 
0099 void F04Trajectory::ShowTrajectory(std::ostream& os) const
0100 {
0101   // Invoke the default implementation in G4VTrajectory...
0102   G4VTrajectory::ShowTrajectory(os);
0103   // ... or override with your own code here.
0104 }
0105 
0106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0107 
0108 void F04Trajectory::AppendStep(const G4Step* aStep)
0109 {
0110   fpPointsContainer->push_back(new F04TrajectoryPoint(aStep));
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 G4ParticleDefinition* F04Trajectory::GetParticleDefinition()
0116 {
0117   return (G4ParticleTable::GetParticleTable()->FindParticle(fParticleName));
0118 }
0119 
0120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0121 
0122 void F04Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
0123 {
0124   if (!secondTrajectory) return;
0125 
0126   auto second = (F04Trajectory*)secondTrajectory;
0127   G4int ent = second->GetPointEntries();
0128   // initial point of the second trajectory should not be merged
0129   for (G4int i = 1; i < ent; ++i) {
0130     fpPointsContainer->push_back((*(second->fpPointsContainer))[i]);
0131   }
0132   delete (*second->fpPointsContainer)[0];
0133   second->fpPointsContainer->clear();
0134 }
0135 
0136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0137 
0138 const std::map<G4String, G4AttDef>* F04Trajectory::GetAttDefs() const
0139 {
0140   G4bool isNew;
0141   std::map<G4String, G4AttDef>* store = G4AttDefStore::GetInstance("Trajectory", isNew);
0142 
0143   if (isNew) {
0144     G4String ID("ID");
0145     (*store)[ID] = G4AttDef(ID, "Track ID", "Bookkeeping", "", "G4int");
0146 
0147     G4String PID("PID");
0148     (*store)[PID] = G4AttDef(PID, "Parent ID", "Bookkeeping", "", "G4int");
0149 
0150     G4String PN("PN");
0151     (*store)[PN] = G4AttDef(PN, "Particle Name", "Physics", "", "G4String");
0152 
0153     G4String Ch("Ch");
0154     (*store)[Ch] = G4AttDef(Ch, "Charge", "Physics", "e+", "G4double");
0155 
0156     G4String PDG("PDG");
0157     (*store)[PDG] = G4AttDef(PDG, "PDG Encoding", "Physics", "", "G4int");
0158 
0159     G4String IMom("IMom");
0160     (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", "Physics",
0161                               "G4BestUnit", "G4ThreeVector");
0162 
0163     G4String IMag("IMag");
0164     (*store)[IMag] = G4AttDef(IMag, "Magnitude of momentum of track at start of trajectory",
0165                               "Physics", "G4BestUnit", "G4double");
0166 
0167     G4String NTP("NTP");
0168     (*store)[NTP] = G4AttDef(NTP, "No. of points", "Bookkeeping", "", "G4int");
0169   }
0170   return store;
0171 }
0172 
0173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0174 
0175 std::vector<G4AttValue>* F04Trajectory::CreateAttValues() const
0176 {
0177   auto values = new std::vector<G4AttValue>;
0178 
0179   values->push_back(G4AttValue("ID", G4UIcommand::ConvertToString(fTrackID), ""));
0180 
0181   values->push_back(G4AttValue("PID", G4UIcommand::ConvertToString(fParentID), ""));
0182 
0183   values->push_back(G4AttValue("PN", fParticleName, ""));
0184 
0185   values->push_back(G4AttValue("Ch", G4UIcommand::ConvertToString(fPDGCharge), ""));
0186 
0187   values->push_back(G4AttValue("PDG", G4UIcommand::ConvertToString(fPDGEncoding), ""));
0188 
0189   values->push_back(G4AttValue("IMom", G4BestUnit(fInitialMomentum, "Energy"), ""));
0190 
0191   values->push_back(G4AttValue("IMag", G4BestUnit(fInitialMomentum.mag(), "Energy"), ""));
0192 
0193   values->push_back(G4AttValue("NTP", G4UIcommand::ConvertToString(GetPointEntries()), ""));
0194 
0195 #ifdef G4ATTDEBUG
0196   G4cout << G4AttCheck(values, GetAttDefs());
0197 #endif
0198   return values;
0199 }