Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:25

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 optical/wls/src/WLSTrajectory.cc
0028 /// \brief Implementation of the WLSTrajectory class
0029 //
0030 //
0031 
0032 #include "WLSTrajectory.hh"
0033 
0034 #include "WLSTrajectoryPoint.hh"
0035 
0036 #include "G4AttDef.hh"
0037 #include "G4AttDefStore.hh"
0038 #include "G4AttValue.hh"
0039 #include "G4Colour.hh"
0040 #include "G4ParticleTable.hh"
0041 #include "G4ParticleTypes.hh"
0042 #include "G4Polyline.hh"
0043 #include "G4Polymarker.hh"
0044 #include "G4UIcommand.hh"
0045 #include "G4UnitsTable.hh"
0046 #include "G4VVisManager.hh"
0047 #include "G4VisAttributes.hh"
0048 
0049 G4ThreadLocal G4Allocator<WLSTrajectory>* WLSTrajectoryAllocator = nullptr;
0050 
0051 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0052 
0053 WLSTrajectory::WLSTrajectory(const G4Track* aTrack)
0054 {
0055   fParticleDefinition = aTrack->GetDefinition();
0056   fParticleName = fParticleDefinition->GetParticleName();
0057   fPDGCharge = fParticleDefinition->GetPDGCharge();
0058   fPDGEncoding = fParticleDefinition->GetPDGEncoding();
0059   fTrackID = aTrack->GetTrackID();
0060   fParentID = aTrack->GetParentID();
0061   fInitialMomentum = aTrack->GetMomentum();
0062   fpPointsContainer = new WLSTrajectoryPointContainer();
0063   // Following is for the first trajectory point
0064   fpPointsContainer->push_back(new WLSTrajectoryPoint(aTrack));
0065 }
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 WLSTrajectory::WLSTrajectory(WLSTrajectory& right) : G4VTrajectory()
0070 {
0071   fParticleDefinition = right.fParticleDefinition;
0072   fParticleName = right.fParticleName;
0073   fPDGCharge = right.fPDGCharge;
0074   fPDGEncoding = right.fPDGEncoding;
0075   fTrackID = right.fTrackID;
0076   fParentID = right.fParentID;
0077   fInitialMomentum = right.fInitialMomentum;
0078   fpPointsContainer = new WLSTrajectoryPointContainer();
0079 
0080   for (size_t i = 0; i < right.fpPointsContainer->size(); ++i) {
0081     auto rightPoint = (WLSTrajectoryPoint*)((*(right.fpPointsContainer))[i]);
0082     fpPointsContainer->push_back(new WLSTrajectoryPoint(*rightPoint));
0083   }
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0087 
0088 WLSTrajectory::~WLSTrajectory()
0089 {
0090   for (size_t i = 0; i < fpPointsContainer->size(); ++i) {
0091     delete (*fpPointsContainer)[i];
0092   }
0093   fpPointsContainer->clear();
0094   delete fpPointsContainer;
0095 }
0096 
0097 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0098 
0099 void WLSTrajectory::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 WLSTrajectory::AppendStep(const G4Step* aStep)
0109 {
0110   fpPointsContainer->push_back(new WLSTrajectoryPoint(aStep));
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 G4ParticleDefinition* WLSTrajectory::GetParticleDefinition()
0116 {
0117   return (G4ParticleTable::GetParticleTable()->FindParticle(fParticleName));
0118 }
0119 
0120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0121 
0122 void WLSTrajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
0123 {
0124   if (!secondTrajectory) return;
0125 
0126   auto second = (WLSTrajectory*)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>* WLSTrajectory::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>* WLSTrajectory::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   return values;
0196 }