Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 /// \file field/field04/src/F04Trajectory.cc << 28 /// \brief Implementation of the F04Trajectory << 29 // 27 // 30 28 31 #include "F04Trajectory.hh" << 32 << 33 #include "F04TrajectoryPoint.hh" << 34 << 35 #include "G4AttDef.hh" 29 #include "G4AttDef.hh" 36 #include "G4AttDefStore.hh" << 37 #include "G4AttValue.hh" 30 #include "G4AttValue.hh" 38 #include "G4ParticleTable.hh" << 31 #include "G4AttDefStore.hh" >> 32 39 #include "G4UIcommand.hh" 33 #include "G4UIcommand.hh" 40 #include "G4UnitsTable.hh" 34 #include "G4UnitsTable.hh" 41 35 42 // #define G4ATTDEBUG << 36 #include "F04Trajectory.hh" >> 37 #include "F04TrajectoryPoint.hh" >> 38 #include "G4ParticleTable.hh" >> 39 >> 40 //#define G4ATTDEBUG 43 #ifdef G4ATTDEBUG 41 #ifdef G4ATTDEBUG 44 # include "G4AttCheck.hh" << 42 #include "G4AttCheck.hh" 45 #endif 43 #endif 46 44 47 G4ThreadLocal G4Allocator<F04Trajectory>* F04T << 45 G4Allocator<F04Trajectory> aTrajectoryAllocator; 48 46 49 //....oooOO0OOooo........oooOO0OOooo........oo << 47 F04Trajectory::F04Trajectory() 50 << 48 : fpPointsContainer(0), fTrackID(0), fParentID(0), 51 F04Trajectory::F04Trajectory() {} << 49 PDGCharge(0.0), PDGEncoding(0), ParticleName(""), 52 << 50 initialMomentum(G4ThreeVector()) {;} 53 //....oooOO0OOooo........oooOO0OOooo........oo << 54 51 55 F04Trajectory::F04Trajectory(const G4Track* aT 52 F04Trajectory::F04Trajectory(const G4Track* aTrack) 56 { 53 { 57 G4ParticleDefinition* particleDefinition = a << 54 G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition(); 58 fParticleName = particleDefinition->GetParti << 55 ParticleName = fpParticleDefinition->GetParticleName(); 59 fPDGCharge = particleDefinition->GetPDGCharg << 56 PDGCharge = fpParticleDefinition->GetPDGCharge(); 60 fPDGEncoding = particleDefinition->GetPDGEnc << 57 PDGEncoding = fpParticleDefinition->GetPDGEncoding(); 61 fTrackID = aTrack->GetTrackID(); << 58 fTrackID = aTrack->GetTrackID(); 62 fParentID = aTrack->GetParentID(); << 59 fParentID = aTrack->GetParentID(); 63 fInitialMomentum = aTrack->GetMomentum(); << 60 initialMomentum = aTrack->GetMomentum(); 64 fpPointsContainer = new TrajectoryPointConta << 61 fpPointsContainer = new TrajectoryPointContainer(); 65 // Following is for the first trajectory poi << 62 // Following is for the first trajectory point 66 fpPointsContainer->push_back(new F04Trajecto << 63 fpPointsContainer->push_back(new F04TrajectoryPoint(aTrack)); 67 } << 64 } 68 << 65 69 //....oooOO0OOooo........oooOO0OOooo........oo << 66 F04Trajectory::F04Trajectory(F04Trajectory & right) : G4VTrajectory() 70 << 67 { 71 F04Trajectory::F04Trajectory(F04Trajectory& ri << 68 ParticleName = right.ParticleName; 72 { << 69 PDGCharge = right.PDGCharge; 73 fParticleName = right.fParticleName; << 70 PDGEncoding = right.PDGEncoding; 74 fPDGCharge = right.fPDGCharge; << 71 fTrackID = right.fTrackID; 75 fPDGEncoding = right.fPDGEncoding; << 72 fParentID = right.fParentID; 76 fTrackID = right.fTrackID; << 73 initialMomentum = right.initialMomentum; 77 fParentID = right.fParentID; << 74 fpPointsContainer = new TrajectoryPointContainer(); 78 fInitialMomentum = right.fInitialMomentum; << 75 79 fpPointsContainer = new TrajectoryPointConta << 76 for(size_t i=0;i<right.fpPointsContainer->size();++i) { 80 << 77 F04TrajectoryPoint* rightPoint 81 for (size_t i = 0; i < right.fpPointsContain << 78 = (F04TrajectoryPoint*)((*(right.fpPointsContainer))[i]); 82 auto rightPoint = (F04TrajectoryPoint*)((* << 79 fpPointsContainer->push_back(new F04TrajectoryPoint(*rightPoint)); 83 fpPointsContainer->push_back(new F04Trajec << 80 } 84 } << 85 } 81 } 86 82 87 //....oooOO0OOooo........oooOO0OOooo........oo << 88 << 89 F04Trajectory::~F04Trajectory() 83 F04Trajectory::~F04Trajectory() 90 { 84 { 91 for (size_t i = 0; i < fpPointsContainer->si << 85 for(size_t i=0;i<fpPointsContainer->size();++i){ 92 delete (*fpPointsContainer)[i]; << 86 delete (*fpPointsContainer)[i]; 93 } << 87 } 94 fpPointsContainer->clear(); << 88 fpPointsContainer->clear(); 95 89 96 delete fpPointsContainer; << 90 delete fpPointsContainer; 97 } 91 } 98 92 99 //....oooOO0OOooo........oooOO0OOooo........oo << 100 << 101 void F04Trajectory::ShowTrajectory(std::ostrea 93 void F04Trajectory::ShowTrajectory(std::ostream& os) const 102 { 94 { 103 // Invoke the default implementation in G4VT << 95 // Invoke the default implementation in G4VTrajectory... 104 G4VTrajectory::ShowTrajectory(os); << 96 G4VTrajectory::ShowTrajectory(os); 105 // ... or override with your own code here. << 97 // ... or override with your own code here. 106 } 98 } 107 99 108 //....oooOO0OOooo........oooOO0OOooo........oo << 100 void F04Trajectory::DrawTrajectory(G4int i_mode) const >> 101 { >> 102 // Invoke the default implementation in G4VTrajectory... >> 103 G4VTrajectory::DrawTrajectory(i_mode); >> 104 // ... or override with your own code here. >> 105 } 109 106 110 void F04Trajectory::AppendStep(const G4Step* a 107 void F04Trajectory::AppendStep(const G4Step* aStep) 111 { 108 { 112 fpPointsContainer->push_back(new F04Trajecto << 109 fpPointsContainer->push_back(new F04TrajectoryPoint(aStep)); 113 } 110 } 114 111 115 //....oooOO0OOooo........oooOO0OOooo........oo << 116 << 117 G4ParticleDefinition* F04Trajectory::GetPartic 112 G4ParticleDefinition* F04Trajectory::GetParticleDefinition() 118 { 113 { 119 return (G4ParticleTable::GetParticleTable()- << 114 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName)); 120 } 115 } 121 116 122 //....oooOO0OOooo........oooOO0OOooo........oo << 123 << 124 void F04Trajectory::MergeTrajectory(G4VTraject 117 void F04Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) 125 { 118 { 126 if (!secondTrajectory) return; << 119 if(!secondTrajectory) return; 127 120 128 auto second = (F04Trajectory*)secondTrajecto << 121 F04Trajectory* second = (F04Trajectory*)secondTrajectory; 129 G4int ent = second->GetPointEntries(); << 122 G4int ent = second->GetPointEntries(); 130 // initial point of the second trajectory sh << 123 // initial point of the second trajectory should not be merged 131 for (G4int i = 1; i < ent; ++i) { << 124 for(G4int i=1; i<ent; ++i) { 132 fpPointsContainer->push_back((*(second->fp << 125 fpPointsContainer->push_back((*(second->fpPointsContainer))[i]); 133 } << 126 } 134 delete (*second->fpPointsContainer)[0]; << 127 delete (*second->fpPointsContainer)[0]; 135 second->fpPointsContainer->clear(); << 128 second->fpPointsContainer->clear(); 136 } 129 } 137 130 138 //....oooOO0OOooo........oooOO0OOooo........oo << 131 const std::map<G4String,G4AttDef>* F04Trajectory::GetAttDefs() const 139 << 140 const std::map<G4String, G4AttDef>* F04Traject << 141 { 132 { 142 G4bool isNew; << 133 G4bool isNew; 143 std::map<G4String, G4AttDef>* store = G4AttD << 134 std::map<G4String,G4AttDef>* store >> 135 = G4AttDefStore::GetInstance("Trajectory",isNew); 144 136 145 if (isNew) { << 137 if (isNew) { 146 G4String ID("ID"); << 147 (*store)[ID] = G4AttDef(ID, "Track ID", "B << 148 138 149 G4String PID("PID"); << 139 G4String ID("ID"); 150 (*store)[PID] = G4AttDef(PID, "Parent ID", << 140 (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int"); 151 141 152 G4String PN("PN"); << 142 G4String PID("PID"); 153 (*store)[PN] = G4AttDef(PN, "Particle Name << 143 (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int"); 154 144 155 G4String Ch("Ch"); << 145 G4String PN("PN"); 156 (*store)[Ch] = G4AttDef(Ch, "Charge", "Phy << 146 (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String"); 157 147 158 G4String PDG("PDG"); << 148 G4String Ch("Ch"); 159 (*store)[PDG] = G4AttDef(PDG, "PDG Encodin << 149 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double"); 160 150 161 G4String IMom("IMom"); << 151 G4String PDG("PDG"); 162 (*store)[IMom] = G4AttDef(IMom, "Momentum << 152 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int"); 163 "G4BestUnit", "G << 164 153 165 G4String IMag("IMag"); << 154 G4String IMom("IMom"); 166 (*store)[IMag] = G4AttDef(IMag, "Magnitude << 155 (*store)[IMom] = G4AttDef(IMom, 167 "Physics", "G4Be << 156 "Momentum of track at start of trajectory", >> 157 "Physics","G4BestUnit","G4ThreeVector"); 168 158 169 G4String NTP("NTP"); << 159 G4String IMag("IMag"); 170 (*store)[NTP] = G4AttDef(NTP, "No. of poin << 160 (*store)[IMag] = G4AttDef(IMag, 171 } << 161 "Magnitude of momentum of track at start of trajectory", 172 return store; << 162 "Physics","G4BestUnit","G4double"); 173 } << 163 >> 164 G4String NTP("NTP"); >> 165 (*store)[NTP] = G4AttDef(NTP,"No. of points","Bookkeeping","","G4int"); 174 166 175 //....oooOO0OOooo........oooOO0OOooo........oo << 167 } >> 168 return store; >> 169 } 176 170 177 std::vector<G4AttValue>* F04Trajectory::Create 171 std::vector<G4AttValue>* F04Trajectory::CreateAttValues() const 178 { 172 { 179 auto values = new std::vector<G4AttValue>; << 173 std::vector<G4AttValue>* values = new std::vector<G4AttValue>; 180 174 181 values->push_back(G4AttValue("ID", G4UIcomma << 175 values->push_back >> 176 (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),"")); 182 177 183 values->push_back(G4AttValue("PID", G4UIcomm << 178 values->push_back >> 179 (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),"")); 184 180 185 values->push_back(G4AttValue("PN", fParticle << 181 values->push_back(G4AttValue("PN",ParticleName,"")); 186 182 187 values->push_back(G4AttValue("Ch", G4UIcomma << 183 values->push_back >> 184 (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),"")); 188 185 189 values->push_back(G4AttValue("PDG", G4UIcomm << 186 values->push_back >> 187 (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),"")); 190 188 191 values->push_back(G4AttValue("IMom", G4BestU << 189 values->push_back >> 190 (G4AttValue("IMom",G4BestUnit(initialMomentum,"Energy"),"")); 192 191 193 values->push_back(G4AttValue("IMag", G4BestU << 192 values->push_back >> 193 (G4AttValue("IMag",G4BestUnit(initialMomentum.mag(),"Energy"),"")); 194 194 195 values->push_back(G4AttValue("NTP", G4UIcomm << 195 values->push_back >> 196 (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),"")); 196 197 197 #ifdef G4ATTDEBUG 198 #ifdef G4ATTDEBUG 198 G4cout << G4AttCheck(values, GetAttDefs()); << 199 G4cout << G4AttCheck(values,GetAttDefs()); 199 #endif 200 #endif 200 return values; << 201 return values; 201 } 202 } 202 203