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.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /tracking/src/G4Trajectory.cc (Version 11.3.0) and /tracking/src/G4Trajectory.cc (Version 9.6)


  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 // G4Trajectory class implementation           <<  26 //
                                                   >>  27 // $Id$
                                                   >>  28 //
                                                   >>  29 // ---------------------------------------------------------------
                                                   >>  30 //
                                                   >>  31 // G4Trajectory.cc
 27 //                                                 32 //
 28 // Contact:                                        33 // Contact:
 29 //   Questions and comments to this code shoul     34 //   Questions and comments to this code should be sent to
 30 //     Katsuya Amako  (e-mail: Katsuya.Amako@k     35 //     Katsuya Amako  (e-mail: Katsuya.Amako@kek.jp)
 31 //     Makoto  Asai   (e-mail: asai@slac.stanf <<  36 //     Makoto  Asai   (e-mail: asai@kekvax.kek.jp)
 32 //     Takashi Sasaki (e-mail: Takashi.Sasaki@     37 //     Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
 33 // ------------------------------------------- <<  38 //
                                                   >>  39 // ---------------------------------------------------------------
 34                                                    40 
 35 #include "G4Trajectory.hh"                         41 #include "G4Trajectory.hh"
 36                                                <<  42 #include "G4TrajectoryPoint.hh"
 37 #include "G4AttDef.hh"                         <<  43 #include "G4ParticleTable.hh"
 38 #include "G4AttDefStore.hh"                        44 #include "G4AttDefStore.hh"
                                                   >>  45 #include "G4AttDef.hh"
 39 #include "G4AttValue.hh"                           46 #include "G4AttValue.hh"
 40 #include "G4ParticleTable.hh"                  << 
 41 #include "G4TrajectoryPoint.hh"                << 
 42 #include "G4ClonedTrajectory.hh"               << 
 43 #include "G4UIcommand.hh"                          47 #include "G4UIcommand.hh"
 44 #include "G4UnitsTable.hh"                         48 #include "G4UnitsTable.hh"
 45 #include "G4AutoLock.hh"                       << 
 46                                                << 
 47 namespace {                                    << 
 48  G4Mutex CloneTrajectoryMutex = G4MUTEX_INITIA << 
 49 }                                              << 
 50                                                    49 
 51 // #define G4ATTDEBUG                          <<  50 //#define G4ATTDEBUG
 52 #ifdef G4ATTDEBUG                                  51 #ifdef G4ATTDEBUG
 53 #  include "G4AttCheck.hh"                     <<  52 #include "G4AttCheck.hh"
 54 #endif                                             53 #endif
 55                                                    54 
 56 G4Allocator<G4Trajectory>*& aTrajectoryAllocat <<  55 G4Allocator<G4Trajectory> aTrajectoryAllocator;
 57 {                                              <<  56 
 58   G4ThreadLocalStatic G4Allocator<G4Trajectory <<  57 G4Trajectory::G4Trajectory()
 59   return _instance;                            <<  58 :  positionRecord(0), fTrackID(0), fParentID(0),
 60 }                                              <<  59    PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""),
                                                   >>  60    initialKineticEnergy( 0. ), initialMomentum( G4ThreeVector() )
                                                   >>  61 {;}
 61                                                    62 
 62 G4Trajectory::G4Trajectory(const G4Track* aTra     63 G4Trajectory::G4Trajectory(const G4Track* aTrack)
 63 {                                                  64 {
 64   G4ParticleDefinition* fpParticleDefinition = <<  65    G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
 65   ParticleName = fpParticleDefinition->GetPart <<  66    ParticleName = fpParticleDefinition->GetParticleName();
 66   PDGCharge = fpParticleDefinition->GetPDGChar <<  67    PDGCharge = fpParticleDefinition->GetPDGCharge();
 67   PDGEncoding = fpParticleDefinition->GetPDGEn <<  68    PDGEncoding = fpParticleDefinition->GetPDGEncoding();
 68   fTrackID = aTrack->GetTrackID();             <<  69    fTrackID = aTrack->GetTrackID();
 69   fParentID = aTrack->GetParentID();           <<  70    fParentID = aTrack->GetParentID();
 70   initialKineticEnergy = aTrack->GetKineticEne <<  71    initialKineticEnergy = aTrack->GetKineticEnergy();
 71   initialMomentum = aTrack->GetMomentum();     <<  72    initialMomentum = aTrack->GetMomentum();
 72   positionRecord = new G4TrajectoryPointContai <<  73    positionRecord = new TrajectoryPointContainer();
 73                                                <<  74    // Following is for the first trajectory point
 74   // Following is for the first trajectory poi <<  75    positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
 75   positionRecord->push_back(new G4TrajectoryPo << 
 76 }                                                  76 }
 77                                                    77 
 78 G4Trajectory::G4Trajectory(G4Trajectory& right <<  78 G4Trajectory::G4Trajectory(G4Trajectory & right):G4VTrajectory()
 79 {                                                  79 {
 80   ParticleName = right.ParticleName;               80   ParticleName = right.ParticleName;
 81   PDGCharge = right.PDGCharge;                     81   PDGCharge = right.PDGCharge;
 82   PDGEncoding = right.PDGEncoding;                 82   PDGEncoding = right.PDGEncoding;
 83   fTrackID = right.fTrackID;                       83   fTrackID = right.fTrackID;
 84   fParentID = right.fParentID;                     84   fParentID = right.fParentID;
 85   initialKineticEnergy = right.initialKineticE     85   initialKineticEnergy = right.initialKineticEnergy;
 86   initialMomentum = right.initialMomentum;         86   initialMomentum = right.initialMomentum;
 87   positionRecord = new G4TrajectoryPointContai <<  87   positionRecord = new TrajectoryPointContainer();
 88                                                    88 
 89   for (auto& i : *right.positionRecord) {      <<  89   for(size_t i=0;i<right.positionRecord->size();i++)
 90     auto rightPoint = (G4TrajectoryPoint*)i;   <<  90   {
                                                   >>  91     G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
 91     positionRecord->push_back(new G4Trajectory     92     positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
 92   }                                                93   }
 93 }                                                  94 }
 94                                                    95 
 95 G4VTrajectory* G4Trajectory::CloneForMaster()  << 
 96 {                                              << 
 97   G4AutoLock lock(&CloneTrajectoryMutex);      << 
 98   auto* cloned = new G4ClonedTrajectory(*this) << 
 99   return cloned;                               << 
100 }                                              << 
101                                                << 
102 G4Trajectory::~G4Trajectory()                      96 G4Trajectory::~G4Trajectory()
103 {                                                  97 {
104   if (positionRecord != nullptr) {             <<  98   if (positionRecord) {
105     for (auto& i : *positionRecord) {          <<  99     //  positionRecord->clearAndDestroy();
106       delete i;                                << 100     size_t i;
                                                   >> 101     for(i=0;i<positionRecord->size();i++){
                                                   >> 102       delete  (*positionRecord)[i];
107     }                                             103     }
108     positionRecord->clear();                      104     positionRecord->clear();
109     delete positionRecord;                        105     delete positionRecord;
110   }                                               106   }
111 }                                                 107 }
112                                                   108 
113 void G4Trajectory::ShowTrajectory(std::ostream    109 void G4Trajectory::ShowTrajectory(std::ostream& os) const
114 {                                                 110 {
115   // Invoke the default implementation in G4VT    111   // Invoke the default implementation in G4VTrajectory...
116   G4VTrajectory::ShowTrajectory(os);              112   G4VTrajectory::ShowTrajectory(os);
117                                                << 
118   // ... or override with your own code here.     113   // ... or override with your own code here.
119 }                                                 114 }
120                                                   115 
                                                   >> 116 /***
121 void G4Trajectory::DrawTrajectory() const         117 void G4Trajectory::DrawTrajectory() const
122 {                                                 118 {
123   // Invoke the default implementation in G4VT    119   // Invoke the default implementation in G4VTrajectory...
124   G4VTrajectory::DrawTrajectory();                120   G4VTrajectory::DrawTrajectory();
                                                   >> 121   // ... or override with your own code here.
                                                   >> 122 }
                                                   >> 123 ***/
125                                                   124 
                                                   >> 125 void G4Trajectory::DrawTrajectory(G4int i_mode) const
                                                   >> 126 {
                                                   >> 127   // Invoke the default implementation in G4VTrajectory...
                                                   >> 128   G4VTrajectory::DrawTrajectory(i_mode);
126   // ... or override with your own code here.     129   // ... or override with your own code here.
127 }                                                 130 }
128                                                   131 
129 const std::map<G4String, G4AttDef>* G4Trajecto << 132 const std::map<G4String,G4AttDef>* G4Trajectory::GetAttDefs() const
130 {                                                 133 {
131   G4bool isNew;                                   134   G4bool isNew;
132   std::map<G4String, G4AttDef>* store = G4AttD << 135   std::map<G4String,G4AttDef>* store
                                                   >> 136     = G4AttDefStore::GetInstance("G4Trajectory",isNew);
133   if (isNew) {                                    137   if (isNew) {
                                                   >> 138 
134     G4String ID("ID");                            139     G4String ID("ID");
135     (*store)[ID] = G4AttDef(ID, "Track ID", "P << 140     (*store)[ID] = G4AttDef(ID,"Track ID","Physics","","G4int");
136                                                   141 
137     G4String PID("PID");                          142     G4String PID("PID");
138     (*store)[PID] = G4AttDef(PID, "Parent ID", << 143     (*store)[PID] = G4AttDef(PID,"Parent ID","Physics","","G4int");
139                                                   144 
140     G4String PN("PN");                            145     G4String PN("PN");
141     (*store)[PN] = G4AttDef(PN, "Particle Name << 146     (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
142                                                   147 
143     G4String Ch("Ch");                            148     G4String Ch("Ch");
144     (*store)[Ch] = G4AttDef(Ch, "Charge", "Phy << 149     (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","e+","G4double");
145                                                   150 
146     G4String PDG("PDG");                          151     G4String PDG("PDG");
147     (*store)[PDG] = G4AttDef(PDG, "PDG Encodin << 152     (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
148                                                   153 
149     G4String IKE("IKE");                          154     G4String IKE("IKE");
150     (*store)[IKE] = G4AttDef(IKE, "Initial kin << 155     (*store)[IKE] = 
                                                   >> 156       G4AttDef(IKE, "Initial kinetic energy",
                                                   >> 157          "Physics","G4BestUnit","G4double");
151                                                   158 
152     G4String IMom("IMom");                        159     G4String IMom("IMom");
153     (*store)[IMom] = G4AttDef(IMom, "Initial m << 160     (*store)[IMom] = G4AttDef(IMom, "Initial momentum",
                                                   >> 161             "Physics","G4BestUnit","G4ThreeVector");
154                                                   162 
155     G4String IMag("IMag");                        163     G4String IMag("IMag");
156     (*store)[IMag] =                           << 164     (*store)[IMag] = 
157       G4AttDef(IMag, "Initial momentum magnitu << 165       G4AttDef(IMag, "Initial momentum magnitude",
                                                   >> 166          "Physics","G4BestUnit","G4double");
158                                                   167 
159     G4String NTP("NTP");                          168     G4String NTP("NTP");
160     (*store)[NTP] = G4AttDef(NTP, "No. of poin << 169     (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
                                                   >> 170 
161   }                                               171   }
162   return store;                                   172   return store;
163 }                                                 173 }
164                                                   174 
165 std::vector<G4AttValue>* G4Trajectory::CreateA    175 std::vector<G4AttValue>* G4Trajectory::CreateAttValues() const
166 {                                                 176 {
167   auto values = new std::vector<G4AttValue>;   << 177   std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
168                                                   178 
169   values->push_back(G4AttValue("ID", G4UIcomma << 179   values->push_back
                                                   >> 180     (G4AttValue("ID",G4UIcommand::ConvertToString(fTrackID),""));
170                                                   181 
171   values->push_back(G4AttValue("PID", G4UIcomm << 182   values->push_back
                                                   >> 183     (G4AttValue("PID",G4UIcommand::ConvertToString(fParentID),""));
172                                                   184 
173   values->push_back(G4AttValue("PN", ParticleN << 185   values->push_back(G4AttValue("PN",ParticleName,""));
174                                                   186 
175   values->push_back(G4AttValue("Ch", G4UIcomma << 187   values->push_back
                                                   >> 188     (G4AttValue("Ch",G4UIcommand::ConvertToString(PDGCharge),""));
176                                                   189 
177   values->push_back(G4AttValue("PDG", G4UIcomm << 190   values->push_back
                                                   >> 191     (G4AttValue("PDG",G4UIcommand::ConvertToString(PDGEncoding),""));
178                                                   192 
179   values->push_back(G4AttValue("IKE", G4BestUn << 193   values->push_back
                                                   >> 194     (G4AttValue("IKE",G4BestUnit(initialKineticEnergy,"Energy"),""));
180                                                   195 
181   values->push_back(G4AttValue("IMom", G4BestU << 196   values->push_back
                                                   >> 197     (G4AttValue("IMom",G4BestUnit(initialMomentum,"Energy"),""));
182                                                   198 
183   values->push_back(G4AttValue("IMag", G4BestU << 199   values->push_back
                                                   >> 200     (G4AttValue("IMag",G4BestUnit(initialMomentum.mag(),"Energy"),""));
184                                                   201 
185   values->push_back(G4AttValue("NTP", G4UIcomm << 202   values->push_back
                                                   >> 203     (G4AttValue("NTP",G4UIcommand::ConvertToString(GetPointEntries()),""));
186                                                   204 
187 #ifdef G4ATTDEBUG                                 205 #ifdef G4ATTDEBUG
188   G4cout << G4AttCheck(values, GetAttDefs());  << 206   G4cout << G4AttCheck(values,GetAttDefs());
189 #endif                                            207 #endif
190                                                   208 
191   return values;                                  209   return values;
192 }                                                 210 }
193                                                   211 
194 void G4Trajectory::AppendStep(const G4Step* aS    212 void G4Trajectory::AppendStep(const G4Step* aStep)
195 {                                                 213 {
196   positionRecord->push_back(new G4TrajectoryPo << 214    positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->
                                                   >> 215                                  GetPosition() ));
197 }                                                 216 }
198                                                << 217   
199 G4ParticleDefinition* G4Trajectory::GetParticl    218 G4ParticleDefinition* G4Trajectory::GetParticleDefinition()
200 {                                                 219 {
201   return (G4ParticleTable::GetParticleTable()- << 220    return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
202 }                                                 221 }
203                                                   222 
204 void G4Trajectory::MergeTrajectory(G4VTrajecto    223 void G4Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
205 {                                                 224 {
206   if (secondTrajectory == nullptr) return;     << 225   if(!secondTrajectory) return;
207                                                   226 
208   auto seco = (G4Trajectory*)secondTrajectory; << 227   G4Trajectory* seco = (G4Trajectory*)secondTrajectory;
209   G4int ent = seco->GetPointEntries();            228   G4int ent = seco->GetPointEntries();
210   for (G4int i = 1; i < ent; ++i)  // initial  << 229   for(G4int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
211   {                                            << 230   { 
212     positionRecord->push_back((*(seco->positio    231     positionRecord->push_back((*(seco->positionRecord))[i]);
                                                   >> 232     //    positionRecord->push_back(seco->positionRecord->removeAt(1));
213   }                                               233   }
214   delete (*seco->positionRecord)[0];              234   delete (*seco->positionRecord)[0];
215   seco->positionRecord->clear();                  235   seco->positionRecord->clear();
216 }                                                 236 }
                                                   >> 237 
                                                   >> 238 
217                                                   239