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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 6.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
 25 //                                                 22 //
 26 // G4Trajectory class implementation           <<  23 //
                                                   >>  24 // $Id: G4Trajectory.cc,v 1.24 2004/06/11 14:30:20 gcosmo Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-06-02 $
                                                   >>  26 //
                                                   >>  27 //
                                                   >>  28 // ---------------------------------------------------------------
                                                   >>  29 //
                                                   >>  30 // G4Trajectory.cc
 27 //                                                 31 //
 28 // Contact:                                        32 // Contact:
 29 //   Questions and comments to this code shoul     33 //   Questions and comments to this code should be sent to
 30 //     Katsuya Amako  (e-mail: Katsuya.Amako@k     34 //     Katsuya Amako  (e-mail: Katsuya.Amako@kek.jp)
 31 //     Makoto  Asai   (e-mail: asai@slac.stanf <<  35 //     Makoto  Asai   (e-mail: asai@kekvax.kek.jp)
 32 //     Takashi Sasaki (e-mail: Takashi.Sasaki@     36 //     Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
 33 // ------------------------------------------- <<  37 //
                                                   >>  38 // ---------------------------------------------------------------
 34                                                    39 
 35 #include "G4Trajectory.hh"                         40 #include "G4Trajectory.hh"
 36                                                <<  41 #include "G4TrajectoryPoint.hh"
 37 #include "G4AttDef.hh"                         <<  42 #include "G4ParticleTable.hh"
 38 #include "G4AttDefStore.hh"                        43 #include "G4AttDefStore.hh"
                                                   >>  44 #include "G4AttDef.hh"
 39 #include "G4AttValue.hh"                           45 #include "G4AttValue.hh"
 40 #include "G4ParticleTable.hh"                  << 
 41 #include "G4TrajectoryPoint.hh"                << 
 42 #include "G4ClonedTrajectory.hh"               << 
 43 #include "G4UIcommand.hh"                      << 
 44 #include "G4UnitsTable.hh"                         46 #include "G4UnitsTable.hh"
 45 #include "G4AutoLock.hh"                       <<  47 #include <strstream>
 46                                                << 
 47 namespace {                                    << 
 48  G4Mutex CloneTrajectoryMutex = G4MUTEX_INITIA << 
 49 }                                              << 
 50                                                    48 
 51 // #define G4ATTDEBUG                          <<  49 G4Allocator<G4Trajectory> aTrajectoryAllocator;
 52 #ifdef G4ATTDEBUG                              << 
 53 #  include "G4AttCheck.hh"                     << 
 54 #endif                                         << 
 55                                                    50 
 56 G4Allocator<G4Trajectory>*& aTrajectoryAllocat <<  51 G4Trajectory::G4Trajectory()
 57 {                                              <<  52 :  positionRecord(0), fTrackID(0), fParentID(0),
 58   G4ThreadLocalStatic G4Allocator<G4Trajectory <<  53    PDGEncoding( 0 ), PDGCharge(0.0), ParticleName(""),
 59   return _instance;                            <<  54    initialMomentum( G4ThreeVector() )
 60 }                                              <<  55 {;}
 61                                                    56 
 62 G4Trajectory::G4Trajectory(const G4Track* aTra     57 G4Trajectory::G4Trajectory(const G4Track* aTrack)
 63 {                                                  58 {
 64   G4ParticleDefinition* fpParticleDefinition = <<  59    G4ParticleDefinition * fpParticleDefinition = aTrack->GetDefinition();
 65   ParticleName = fpParticleDefinition->GetPart <<  60    ParticleName = fpParticleDefinition->GetParticleName();
 66   PDGCharge = fpParticleDefinition->GetPDGChar <<  61    PDGCharge = fpParticleDefinition->GetPDGCharge();
 67   PDGEncoding = fpParticleDefinition->GetPDGEn <<  62    PDGEncoding = fpParticleDefinition->GetPDGEncoding();
 68   fTrackID = aTrack->GetTrackID();             <<  63    fTrackID = aTrack->GetTrackID();
 69   fParentID = aTrack->GetParentID();           <<  64    fParentID = aTrack->GetParentID();
 70   initialKineticEnergy = aTrack->GetKineticEne <<  65    initialMomentum = aTrack->GetMomentum();
 71   initialMomentum = aTrack->GetMomentum();     <<  66    positionRecord = new TrajectoryPointContainer();
 72   positionRecord = new G4TrajectoryPointContai <<  67    // Following is for the first trajectory point
 73                                                <<  68    positionRecord->push_back(new G4TrajectoryPoint(aTrack->GetPosition()));
 74   // Following is for the first trajectory poi << 
 75   positionRecord->push_back(new G4TrajectoryPo << 
 76 }                                                  69 }
 77                                                    70 
 78 G4Trajectory::G4Trajectory(G4Trajectory& right <<  71 G4Trajectory::G4Trajectory(G4Trajectory & right):G4VTrajectory()
 79 {                                                  72 {
 80   ParticleName = right.ParticleName;               73   ParticleName = right.ParticleName;
 81   PDGCharge = right.PDGCharge;                     74   PDGCharge = right.PDGCharge;
 82   PDGEncoding = right.PDGEncoding;                 75   PDGEncoding = right.PDGEncoding;
 83   fTrackID = right.fTrackID;                       76   fTrackID = right.fTrackID;
 84   fParentID = right.fParentID;                     77   fParentID = right.fParentID;
 85   initialKineticEnergy = right.initialKineticE << 
 86   initialMomentum = right.initialMomentum;         78   initialMomentum = right.initialMomentum;
 87   positionRecord = new G4TrajectoryPointContai <<  79   positionRecord = new TrajectoryPointContainer();
 88                                                    80 
 89   for (auto& i : *right.positionRecord) {      <<  81   for(size_t i=0;i<right.positionRecord->size();i++)
 90     auto rightPoint = (G4TrajectoryPoint*)i;   <<  82   {
                                                   >>  83     G4TrajectoryPoint* rightPoint = (G4TrajectoryPoint*)((*(right.positionRecord))[i]);
 91     positionRecord->push_back(new G4Trajectory     84     positionRecord->push_back(new G4TrajectoryPoint(*rightPoint));
 92   }                                                85   }
 93 }                                                  86 }
 94                                                    87 
 95 G4VTrajectory* G4Trajectory::CloneForMaster()  << 
 96 {                                              << 
 97   G4AutoLock lock(&CloneTrajectoryMutex);      << 
 98   auto* cloned = new G4ClonedTrajectory(*this) << 
 99   return cloned;                               << 
100 }                                              << 
101                                                << 
102 G4Trajectory::~G4Trajectory()                      88 G4Trajectory::~G4Trajectory()
103 {                                                  89 {
104   if (positionRecord != nullptr) {             <<  90   //  positionRecord->clearAndDestroy();
105     for (auto& i : *positionRecord) {          <<  91   size_t i;
106       delete i;                                <<  92   for(i=0;i<positionRecord->size();i++){
107     }                                          <<  93     delete  (*positionRecord)[i];
108     positionRecord->clear();                   << 
109     delete positionRecord;                     << 
110   }                                                94   }
                                                   >>  95   positionRecord->clear();
                                                   >>  96 
                                                   >>  97   delete positionRecord;
111 }                                                  98 }
112                                                    99 
113 void G4Trajectory::ShowTrajectory(std::ostream    100 void G4Trajectory::ShowTrajectory(std::ostream& os) const
114 {                                                 101 {
115   // Invoke the default implementation in G4VT    102   // Invoke the default implementation in G4VTrajectory...
116   G4VTrajectory::ShowTrajectory(os);              103   G4VTrajectory::ShowTrajectory(os);
117                                                << 
118   // ... or override with your own code here.     104   // ... or override with your own code here.
119 }                                                 105 }
120                                                   106 
121 void G4Trajectory::DrawTrajectory() const      << 107 void G4Trajectory::DrawTrajectory(G4int i_mode) const
122 {                                                 108 {
123   // Invoke the default implementation in G4VT    109   // Invoke the default implementation in G4VTrajectory...
124   G4VTrajectory::DrawTrajectory();             << 110   G4VTrajectory::DrawTrajectory(i_mode);
125                                                << 
126   // ... or override with your own code here.     111   // ... or override with your own code here.
127 }                                                 112 }
128                                                   113 
129 const std::map<G4String, G4AttDef>* G4Trajecto << 114 const std::map<G4String,G4AttDef>* G4Trajectory::GetAttDefs() const
130 {                                                 115 {
131   G4bool isNew;                                   116   G4bool isNew;
132   std::map<G4String, G4AttDef>* store = G4AttD << 117   std::map<G4String,G4AttDef>* store
                                                   >> 118     = G4AttDefStore::GetInstance("G4Trajectory",isNew);
133   if (isNew) {                                    119   if (isNew) {
                                                   >> 120 
134     G4String ID("ID");                            121     G4String ID("ID");
135     (*store)[ID] = G4AttDef(ID, "Track ID", "P << 122     (*store)[ID] = G4AttDef(ID,"Track ID","Bookkeeping","","G4int");
136                                                   123 
137     G4String PID("PID");                          124     G4String PID("PID");
138     (*store)[PID] = G4AttDef(PID, "Parent ID", << 125     (*store)[PID] = G4AttDef(PID,"Parent ID","Bookkeeping","","G4int");
139                                                   126 
140     G4String PN("PN");                            127     G4String PN("PN");
141     (*store)[PN] = G4AttDef(PN, "Particle Name << 128     (*store)[PN] = G4AttDef(PN,"Particle Name","Physics","","G4String");
142                                                   129 
143     G4String Ch("Ch");                            130     G4String Ch("Ch");
144     (*store)[Ch] = G4AttDef(Ch, "Charge", "Phy << 131     (*store)[Ch] = G4AttDef(Ch,"Charge","Physics","","G4double");
145                                                   132 
146     G4String PDG("PDG");                          133     G4String PDG("PDG");
147     (*store)[PDG] = G4AttDef(PDG, "PDG Encodin << 134     (*store)[PDG] = G4AttDef(PDG,"PDG Encoding","Physics","","G4int");
148                                                << 
149     G4String IKE("IKE");                       << 
150     (*store)[IKE] = G4AttDef(IKE, "Initial kin << 
151                                                   135 
152     G4String IMom("IMom");                        136     G4String IMom("IMom");
153     (*store)[IMom] = G4AttDef(IMom, "Initial m << 137     (*store)[IMom] = G4AttDef(IMom, "Momentum of track at start of trajectory",
154                                                << 138             "Physics","","G4ThreeVector");
155     G4String IMag("IMag");                     << 
156     (*store)[IMag] =                           << 
157       G4AttDef(IMag, "Initial momentum magnitu << 
158                                                   139 
159     G4String NTP("NTP");                          140     G4String NTP("NTP");
160     (*store)[NTP] = G4AttDef(NTP, "No. of poin << 141     (*store)[NTP] = G4AttDef(NTP,"No. of points","Physics","","G4int");
                                                   >> 142 
161   }                                               143   }
162   return store;                                   144   return store;
163 }                                                 145 }
164                                                   146 
165 std::vector<G4AttValue>* G4Trajectory::CreateA    147 std::vector<G4AttValue>* G4Trajectory::CreateAttValues() const
166 {                                                 148 {
167   auto values = new std::vector<G4AttValue>;   << 149   char c[100];
168                                                << 150   std::ostrstream s(c,100);
169   values->push_back(G4AttValue("ID", G4UIcomma << 
170                                                << 
171   values->push_back(G4AttValue("PID", G4UIcomm << 
172                                                   151 
173   values->push_back(G4AttValue("PN", ParticleN << 152   std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
174                                                   153 
175   values->push_back(G4AttValue("Ch", G4UIcomma << 154   s.seekp(std::ios::beg);
                                                   >> 155   s << fTrackID << std::ends;
                                                   >> 156   values->push_back(G4AttValue("ID",c,""));
176                                                   157 
177   values->push_back(G4AttValue("PDG", G4UIcomm << 158   s.seekp(std::ios::beg);
                                                   >> 159   s << fParentID << std::ends;
                                                   >> 160   values->push_back(G4AttValue("PID",c,""));
178                                                   161 
179   values->push_back(G4AttValue("IKE", G4BestUn << 162   values->push_back(G4AttValue("PN",ParticleName,""));
180                                                   163 
181   values->push_back(G4AttValue("IMom", G4BestU << 164   s.seekp(std::ios::beg);
                                                   >> 165   s << PDGCharge << std::ends;
                                                   >> 166   values->push_back(G4AttValue("Ch",c,""));
182                                                   167 
183   values->push_back(G4AttValue("IMag", G4BestU << 168   s.seekp(std::ios::beg);
                                                   >> 169   s << PDGEncoding << std::ends;
                                                   >> 170   values->push_back(G4AttValue("PDG",c,""));
184                                                   171 
185   values->push_back(G4AttValue("NTP", G4UIcomm << 172   s.seekp(std::ios::beg);
                                                   >> 173   s << G4BestUnit(initialMomentum,"Energy") << std::ends;
                                                   >> 174   values->push_back(G4AttValue("IMom",c,""));
186                                                   175 
187 #ifdef G4ATTDEBUG                              << 176   s.seekp(std::ios::beg);
188   G4cout << G4AttCheck(values, GetAttDefs());  << 177   s << GetPointEntries() << std::ends;
189 #endif                                         << 178   values->push_back(G4AttValue("NTP",c,""));
190                                                   179 
191   return values;                                  180   return values;
192 }                                                 181 }
193                                                   182 
194 void G4Trajectory::AppendStep(const G4Step* aS    183 void G4Trajectory::AppendStep(const G4Step* aStep)
195 {                                                 184 {
196   positionRecord->push_back(new G4TrajectoryPo << 185    positionRecord->push_back( new G4TrajectoryPoint(aStep->GetPostStepPoint()->
                                                   >> 186                                  GetPosition() ));
197 }                                                 187 }
198                                                << 188   
199 G4ParticleDefinition* G4Trajectory::GetParticl    189 G4ParticleDefinition* G4Trajectory::GetParticleDefinition()
200 {                                                 190 {
201   return (G4ParticleTable::GetParticleTable()- << 191    return (G4ParticleTable::GetParticleTable()->FindParticle(ParticleName));
202 }                                                 192 }
203                                                   193 
204 void G4Trajectory::MergeTrajectory(G4VTrajecto    194 void G4Trajectory::MergeTrajectory(G4VTrajectory* secondTrajectory)
205 {                                                 195 {
206   if (secondTrajectory == nullptr) return;     << 196   if(!secondTrajectory) return;
207                                                   197 
208   auto seco = (G4Trajectory*)secondTrajectory; << 198   G4Trajectory* seco = (G4Trajectory*)secondTrajectory;
209   G4int ent = seco->GetPointEntries();            199   G4int ent = seco->GetPointEntries();
210   for (G4int i = 1; i < ent; ++i)  // initial  << 200   for(G4int i=1;i<ent;i++) // initial point of the second trajectory should not be merged
211   {                                            << 201   { 
212     positionRecord->push_back((*(seco->positio    202     positionRecord->push_back((*(seco->positionRecord))[i]);
                                                   >> 203     //    positionRecord->push_back(seco->positionRecord->removeAt(1));
213   }                                               204   }
214   delete (*seco->positionRecord)[0];              205   delete (*seco->positionRecord)[0];
215   seco->positionRecord->clear();                  206   seco->positionRecord->clear();
216 }                                                 207 }
                                                   >> 208 
                                                   >> 209 
217                                                   210