Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:19

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