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 /// \file runAndEvent/RE01/src/RE01Trajectory. << 27 /// \brief Implementation of the RE01Trajector << 28 // 26 // >> 27 // $Id: RE01Trajectory.cc,v 1.5 2010-11-08 22:16:28 asaim Exp $ >> 28 // GEANT4 tag $Name: geant4-09-04-patch-01 $ 29 // 29 // 30 // << 31 << 32 #include "RE01Trajectory.hh" << 33 30 34 #include "RE01TrackInformation.hh" << 35 31 36 #include "G4AttDef.hh" << 32 #include "RE01Trajectory.hh" 37 #include "G4AttDefStore.hh" << 38 #include "G4AttValue.hh" << 39 #include "G4Circle.hh" << 40 #include "G4Colour.hh" << 41 #include "G4DynamicParticle.hh" << 42 #include "G4ParticleTable.hh" 33 #include "G4ParticleTable.hh" 43 #include "G4ParticleTypes.hh" 34 #include "G4ParticleTypes.hh" 44 #include "G4Polyline.hh" 35 #include "G4Polyline.hh" 45 #include "G4PrimaryParticle.hh" << 36 #include "G4Circle.hh" >> 37 #include "G4Colour.hh" >> 38 #include "G4AttDefStore.hh" >> 39 #include "G4AttDef.hh" >> 40 #include "G4AttValue.hh" 46 #include "G4UIcommand.hh" 41 #include "G4UIcommand.hh" 47 #include "G4UnitsTable.hh" << 48 #include "G4VVisManager.hh" << 49 #include "G4VisAttributes.hh" 42 #include "G4VisAttributes.hh" >> 43 #include "G4VVisManager.hh" >> 44 #include "G4UnitsTable.hh" >> 45 #include "G4DynamicParticle.hh" >> 46 #include "G4PrimaryParticle.hh" >> 47 #include "RE01TrackInformation.hh" 50 48 51 G4ThreadLocal G4Allocator<RE01Trajectory>* myT << 49 G4Allocator<RE01Trajectory> myTrajectoryAllocator; >> 50 >> 51 RE01Trajectory::RE01Trajectory() >> 52 :G4VTrajectory() >> 53 { >> 54 fpParticleDefinition = 0; >> 55 ParticleName = ""; >> 56 PDGCharge = 0; >> 57 PDGEncoding = 0; >> 58 fTrackID = 0; >> 59 fParentID = 0; >> 60 fTrackStatus = 0; >> 61 positionRecord = 0; >> 62 momentum = G4ThreeVector(0.,0.,0.); >> 63 vertexPosition = G4ThreeVector(0.,0.,0.); >> 64 globalTime = 0.; >> 65 } 52 66 53 //....oooOO0OOooo........oooOO0OOooo........oo << 54 RE01Trajectory::RE01Trajectory(const G4Track* 67 RE01Trajectory::RE01Trajectory(const G4Track* aTrack) 55 : G4VTrajectory(), fPositionRecord(0), fPart << 68 :G4VTrajectory() 56 { 69 { 57 fParticleDefinition = aTrack->GetDefinition( << 70 fpParticleDefinition = aTrack->GetDefinition(); 58 fParticleName = fParticleDefinition->GetPart << 71 ParticleName = fpParticleDefinition->GetParticleName(); 59 fPDGCharge = fParticleDefinition->GetPDGChar << 72 PDGCharge = fpParticleDefinition->GetPDGCharge(); 60 fPDGEncoding = fParticleDefinition->GetPDGEn << 73 PDGEncoding = fpParticleDefinition->GetPDGEncoding(); 61 if (fParticleName == "unknown") { << 74 if(ParticleName=="unknown") 62 G4PrimaryParticle* pp = aTrack->GetDynamic << 75 { 63 if (pp) { << 76 G4PrimaryParticle*pp = aTrack->GetDynamicParticle()->GetPrimaryParticle(); 64 if (pp->GetCharge() < DBL_MAX) fPDGCharg << 77 if(pp) 65 fPDGEncoding = pp->GetPDGcode(); << 78 { 66 if (pp->GetG4code() != 0) { << 79 if(pp->GetCharge()<DBL_MAX) PDGCharge = pp->GetCharge(); 67 fParticleName += " : "; << 80 PDGEncoding = pp->GetPDGcode(); 68 fParticleName += pp->GetG4code()->GetP << 81 if(pp->GetG4code()!=0) 69 } << 82 { 70 } << 83 ParticleName += " : "; 71 } << 84 ParticleName += pp->GetG4code()->GetParticleName(); 72 fTrackID = aTrack->GetTrackID(); << 85 } 73 RE01TrackInformation* trackInfo = (RE01Track << 86 } 74 fTrackStatus = trackInfo->GetTrackingStatus( << 87 } 75 if (fTrackStatus == 1) { << 88 fTrackID = aTrack->GetTrackID(); 76 fParentID = aTrack->GetParentID(); << 89 RE01TrackInformation* trackInfo 77 } << 90 = (RE01TrackInformation*)(aTrack->GetUserInformation()); 78 else if (fTrackStatus == 2) { << 91 fTrackStatus = trackInfo->GetTrackingStatus(); 79 fParentID = trackInfo->GetSourceTrackID(); << 92 if(fTrackStatus == 1) 80 } << 93 { fParentID = aTrack->GetParentID(); } 81 else { << 94 else if(fTrackStatus == 2) 82 fParentID = -1; << 95 { fParentID = trackInfo->GetSourceTrackID(); } 83 } << 96 else 84 fPositionRecord = new RE01TrajectoryPointCon << 97 { fParentID = -1; } 85 fPositionRecord->push_back(new G4TrajectoryP << 98 positionRecord = new RE01TrajectoryPointContainer(); 86 fMomentum = aTrack->GetMomentum(); << 99 positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition())); 87 fVertexPosition = aTrack->GetPosition(); << 100 momentum = aTrack->GetMomentum(); 88 fGlobalTime = aTrack->GetGlobalTime(); << 101 vertexPosition = aTrack->GetPosition(); >> 102 globalTime = aTrack->GetGlobalTime(); >> 103 } >> 104 >> 105 RE01Trajectory::RE01Trajectory(RE01Trajectory & right) >> 106 :G4VTrajectory() >> 107 { >> 108 ParticleName = right.ParticleName; >> 109 fpParticleDefinition = right.fpParticleDefinition; >> 110 PDGCharge = right.PDGCharge; >> 111 PDGEncoding = right.PDGEncoding; >> 112 fTrackID = right.fTrackID; >> 113 fParentID = right.fParentID; >> 114 fTrackStatus = right.fTrackStatus; >> 115 positionRecord = new RE01TrajectoryPointContainer(); >> 116 for(size_t i=0;i<right.positionRecord->size();i++) >> 117 { >> 118 G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]); >> 119 positionRecord->push_back(new G4TrajectoryPoint(*rightPoint)); >> 120 } >> 121 momentum = right.momentum; >> 122 vertexPosition = right.vertexPosition; >> 123 globalTime = right.globalTime; 89 } 124 } 90 125 91 //....oooOO0OOooo........oooOO0OOooo........oo << 92 RE01Trajectory::~RE01Trajectory() 126 RE01Trajectory::~RE01Trajectory() 93 { 127 { 94 size_t i; 128 size_t i; 95 for (i = 0; i < fPositionRecord->size(); i++ << 129 for(i=0;i<positionRecord->size();i++){ 96 delete (*fPositionRecord)[i]; << 130 delete (*positionRecord)[i]; 97 } 131 } 98 fPositionRecord->clear(); << 132 positionRecord->clear(); 99 133 100 delete fPositionRecord; << 134 delete positionRecord; 101 } 135 } 102 136 103 //....oooOO0OOooo........oooOO0OOooo........oo << 104 void RE01Trajectory::ShowTrajectory(std::ostre 137 void RE01Trajectory::ShowTrajectory(std::ostream& os) const 105 { 138 { 106 os << G4endl << "TrackID =" << fTrackID << " << 139 os << G4endl << "TrackID =" << fTrackID 107 << " : TrackStatus=" << fTrackStatus << G << 140 << " : ParentID=" << fParentID << " : TrackStatus=" << fTrackStatus << G4endl; 108 os << "Particle name : " << fParticleName << << 141 os << "Particle name : " << ParticleName << " PDG code : " << PDGEncoding 109 << " Charge : " << fPDGCharge << G4endl; << 142 << " Charge : " << PDGCharge << G4endl; 110 os << "Original momentum : " << G4BestUnit(f << 143 os << "Original momentum : " << 111 os << "Vertex : " << G4BestUnit(fVertexPosit << 144 G4BestUnit(momentum,"Energy") << G4endl; 112 << " Global time : " << G4BestUnit(fGlob << 145 os << "Vertex : " << G4BestUnit(vertexPosition,"Length") 113 os << " Current trajectory has " << fPositi << 146 << " Global time : " << G4BestUnit(globalTime,"Time") << G4endl; 114 << 147 os << " Current trajectory has " << positionRecord->size() 115 for (size_t i = 0; i < fPositionRecord->size << 148 << " points." << G4endl; 116 G4TrajectoryPoint* aTrajectoryPoint = (G4T << 149 117 os << "Point[" << i << "]" << 150 for( size_t i=0 ; i < positionRecord->size() ; i++){ 118 << " Position= " << aTrajectoryPoint->G << 151 G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*positionRecord)[i]); 119 } << 152 os << "Point[" << i << "]" >> 153 << " Position= " << aTrajectoryPoint->GetPosition() << G4endl; >> 154 } 120 } 155 } 121 156 122 //....oooOO0OOooo........oooOO0OOooo........oo << 157 void RE01Trajectory::DrawTrajectory(G4int /*i_mode*/) const 123 void RE01Trajectory::DrawTrajectory() const << 124 { 158 { 125 G4VVisManager* pVVisManager = G4VVisManager: << 126 G4ThreeVector pos; << 127 159 128 G4Polyline pPolyline; << 160 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 129 for (size_t i = 0; i < fPositionRecord->size << 161 G4ThreeVector pos; 130 G4TrajectoryPoint* aTrajectoryPoint = (G4T << 131 pos = aTrajectoryPoint->GetPosition(); << 132 pPolyline.push_back(pos); << 133 } << 134 162 135 G4Colour colour(0.2, 0.2, 0.2); << 163 G4Polyline pPolyline; 136 if (fParticleDefinition == G4Gamma::GammaDef << 164 for (size_t i = 0; i < positionRecord->size() ; i++) { 137 colour = G4Colour(0., 0., 1.); << 165 G4TrajectoryPoint* aTrajectoryPoint = (G4TrajectoryPoint*)((*positionRecord)[i]); 138 else if (fParticleDefinition == G4Electron:: << 166 pos = aTrajectoryPoint->GetPosition(); 139 || fParticleDefinition == G4Positro << 167 pPolyline.push_back( pos ); 140 colour = G4Colour(1., 1., 0.); << 168 } 141 else if (fParticleDefinition == G4MuonMinus: << 169 142 || fParticleDefinition == G4MuonPlu << 170 G4Colour colour(0.2,0.2,0.2); 143 colour = G4Colour(0., 1., 0.); << 171 if(fpParticleDefinition==G4Gamma::GammaDefinition()) 144 else if (fParticleDefinition->GetParticleTyp << 172 colour = G4Colour(0.,0.,1.); 145 if (fPDGCharge != 0.) << 173 else if(fpParticleDefinition==G4Electron::ElectronDefinition() 146 colour = G4Colour(1., 0., 0.); << 174 ||fpParticleDefinition==G4Positron::PositronDefinition()) 147 else << 175 colour = G4Colour(1.,1.,0.); 148 colour = G4Colour(0.5, 0., 0.); << 176 else if(fpParticleDefinition==G4MuonMinus::MuonMinusDefinition() 149 } << 177 ||fpParticleDefinition==G4MuonPlus::MuonPlusDefinition()) 150 else if (fParticleDefinition->GetParticleTyp << 178 colour = G4Colour(0.,1.,0.); 151 if (fPDGCharge != 0.) << 179 else if(fpParticleDefinition->GetParticleType()=="meson") 152 colour = G4Colour(0., 1., 1.); << 180 { 153 else << 181 if(PDGCharge!=0.) 154 colour = G4Colour(0., 0.5, 0.5); << 182 colour = G4Colour(1.,0.,0.); 155 } << 183 else 156 << 184 colour = G4Colour(0.5,0.,0.); 157 G4VisAttributes attribs(colour); << 185 } 158 pPolyline.SetVisAttributes(attribs); << 186 else if(fpParticleDefinition->GetParticleType()=="baryon") 159 if (pVVisManager) pVVisManager->Draw(pPolyli << 187 { >> 188 if(PDGCharge!=0.) >> 189 colour = G4Colour(0.,1.,1.); >> 190 else >> 191 colour = G4Colour(0.,0.5,0.5); >> 192 } >> 193 >> 194 G4VisAttributes attribs(colour); >> 195 pPolyline.SetVisAttributes(attribs); >> 196 if(pVVisManager) pVVisManager->Draw(pPolyline); 160 } 197 } 161 198 162 //....oooOO0OOooo........oooOO0OOooo........oo << 199 const std::map<G4String,G4AttDef>* RE01Trajectory::GetAttDefs() const 163 const std::map<G4String, G4AttDef>* RE01Trajec << 164 { 200 { 165 G4bool isNew; 201 G4bool isNew; 166 std::map<G4String, G4AttDef>* store = G4AttD << 202 std::map<G4String,G4AttDef>* store >> 203 = G4AttDefStore::GetInstance("RE01Trajectory",isNew); 167 if (isNew) { 204 if (isNew) { 168 G4String id("ID"); << 169 (*store)[id] = G4AttDef(id, "Track ID", "B << 170 205 171 G4String pid("PID"); << 206 G4String ID("ID"); 172 (*store)[pid] = G4AttDef(pid, "Parent ID", << 207 (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int"); 173 208 174 G4String status("Status"); << 209 G4String PID("PID"); 175 (*store)[status] = G4AttDef(status, "Track << 210 (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int"); 176 211 177 G4String pn("PN"); << 212 G4String Status("Status"); 178 (*store)[pn] = G4AttDef(pn, "Particle Name << 213 (*store)[Status] = G4AttDef(Status,"Track Status","Bookkeeping","","G4int"); 179 214 180 G4String ch("Ch"); << 215 G4String PN("PN"); 181 (*store)[ch] = G4AttDef(ch, "Charge", "Phy << 216 (*store)[PN] = G4AttDef(PN,"Particle Name","Bookkeeping","","G4String"); 182 217 183 G4String pdg("PDG"); << 218 G4String Ch("Ch"); 184 (*store)[pdg] = G4AttDef(pdg, "PDG Encodin << 219 (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double"); 185 220 186 G4String imom("IMom"); << 221 G4String PDG("PDG"); 187 (*store)[imom] = G4AttDef(imom, "Momentum << 222 (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Bookkeeping","","G4int"); 188 "G4BestUnit", "G << 189 223 190 G4String imag("IMag"); << 224 G4String IMom("IMom"); 191 (*store)[imag] = G4AttDef(imag, "Magnitude << 225 (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory", 192 "Physics", "G4Be << 226 "Physics","G4BestUnit","G4ThreeVector"); 193 227 194 G4String vtxPos("VtxPos"); << 228 G4String IMag("IMag"); 195 (*store)[vtxPos] = << 229 (*store)[IMag] = 196 G4AttDef(vtxPos, "Vertex position", "Phy << 230 G4AttDef(IMag, "Magnitude of momentum of track at start of trajectory", >> 231 "Physics","G4BestUnit","G4double"); >> 232 >> 233 G4String VtxPos("VtxPos"); >> 234 (*store)[VtxPos] = G4AttDef(VtxPos, "Vertex position", >> 235 "Physics","G4BestUnit","G4ThreeVector"); >> 236 >> 237 G4String NTP("NTP"); >> 238 (*store)[NTP] = G4AttDef(NTP,"No. of points","Bookkeeping","","G4int"); 197 239 198 G4String ntp("NTP"); << 199 (*store)[ntp] = G4AttDef(ntp, "No. of poin << 200 } 240 } 201 return store; 241 return store; 202 } 242 } 203 243 204 //....oooOO0OOooo........oooOO0OOooo........oo << 205 std::vector<G4AttValue>* RE01Trajectory::Creat 244 std::vector<G4AttValue>* RE01Trajectory::CreateAttValues() const 206 { 245 { 207 std::vector<G4AttValue>* values = new std::v 246 std::vector<G4AttValue>* values = new std::vector<G4AttValue>; 208 247 209 values->push_back(G4AttValue("ID", G4UIcomma << 248 values->push_back >> 249 (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),"")); 210 250 211 values->push_back(G4AttValue("PID", G4UIcomm << 251 values->push_back >> 252 (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),"")); 212 253 213 values->push_back(G4AttValue("Status", G4UIc << 254 values->push_back >> 255 (G4AttValue("Status",G4UIcommand::ConvertToString(fTrackStatus),"")); 214 256 215 values->push_back(G4AttValue("PN", fParticle << 257 values->push_back(G4AttValue("PN",ParticleName,"")); 216 258 217 values->push_back(G4AttValue("Ch", G4UIcomma << 259 values->push_back >> 260 (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),"")); 218 261 219 values->push_back(G4AttValue("PDG", G4UIcomm << 262 values->push_back >> 263 (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),"")); 220 264 221 values->push_back(G4AttValue("IMom", G4BestU << 265 values->push_back >> 266 (G4AttValue("IMom",G4BestUnit(momentum,"Energy"),"")); 222 267 223 values->push_back(G4AttValue("IMag", G4BestU << 268 values->push_back >> 269 (G4AttValue("IMag",G4BestUnit(momentum.mag(),"Energy"),"")); 224 270 225 values->push_back(G4AttValue("VtxPos", G4Bes << 271 values->push_back >> 272 (G4AttValue("VtxPos",G4BestUnit(vertexPosition,"Length"),"")); 226 273 227 values->push_back(G4AttValue("NTP", G4UIcomm << 274 values->push_back >> 275 (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),"")); 228 276 229 return values; 277 return values; 230 } 278 } 231 279 232 //....oooOO0OOooo........oooOO0OOooo........oo << 233 void RE01Trajectory::AppendStep(const G4Step* 280 void RE01Trajectory::AppendStep(const G4Step* aStep) 234 { 281 { 235 fPositionRecord->push_back(new G4TrajectoryP << 282 positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()-> >> 283 GetPosition() )); >> 284 } >> 285 >> 286 G4ParticleDefinition* RE01Trajectory::GetParticleDefinition() >> 287 { >> 288 return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName)); 236 } 289 } 237 290 238 //....oooOO0OOooo........oooOO0OOooo........oo << 239 void RE01Trajectory::MergeTrajectory(G4VTrajec 291 void RE01Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory) 240 { 292 { 241 if (!secondTrajectory) return; << 293 if(!secondTrajectory) return; 242 294 243 RE01Trajectory* seco = (RE01Trajectory*)seco 295 RE01Trajectory* seco = (RE01Trajectory*)secondTrajectory; 244 G4int ent = seco->GetPointEntries(); 296 G4int ent = seco->GetPointEntries(); 245 // << 297 for(int i=1;i<ent;i++) // initial point of the second trajectory should not be merged 246 // initial point of the second trajectory sh << 298 { 247 for (int i = 1; i < ent; i++) { << 299 positionRecord->push_back((*(seco->positionRecord))[i]); 248 fPositionRecord->push_back((*(seco->fPosit << 249 } 300 } 250 delete (*seco->fPositionRecord)[0]; << 301 delete (*seco->positionRecord)[0]; 251 seco->fPositionRecord->clear(); << 302 seco->positionRecord->clear(); >> 303 252 } 304 } >> 305 >> 306 >> 307 253 308