CMS 3D CMS Logo

TrackWithHistory.cc
Go to the documentation of this file.
6 
8 
9 #include "G4VProcess.hh"
10 
11 #include <iostream>
12 
13 G4ThreadLocal G4Allocator<TrackWithHistory> *fpTrackWithHistoryAllocator = nullptr;
14 
15 //#define DEBUG
16 
17 TrackWithHistory::TrackWithHistory(const G4Track * g4trk) :
18  trackID_(0),particleID_(0),parentID_(0),momentum_(math::XYZVectorD(0.,0.,0.)),
19  totalEnergy_(0),vertexPosition_(math::XYZVectorD(0.,0.,0.)),globalTime_(0),
20  localTime_(0),properTime_(0),creatorProcess_(nullptr),weight_(0),
21  storeTrack_(false),saved_(false) {
22 
23  if (g4trk!=nullptr) {
24  TrackInformationExtractor extractor;
25  trackID_ = g4trk->GetTrackID();
27  parentID_ = g4trk->GetParentID();
28  momentum_ = math::XYZVectorD(g4trk->GetMomentum().x(),g4trk->GetMomentum().y(),g4trk->GetMomentum().z());
29  totalEnergy_ = g4trk->GetTotalEnergy();
30  vertexPosition_ = math::XYZVectorD(g4trk->GetPosition().x(),g4trk->GetPosition().y(),g4trk->GetPosition().z());
31  globalTime_ = g4trk->GetGlobalTime();
32  localTime_ = g4trk->GetLocalTime();
33  properTime_ = g4trk->GetProperTime();
34  creatorProcess_ = g4trk->GetCreatorProcess();
35  storeTrack_ = extractor(g4trk).storeTrack();
36  saved_ = false;
37  genParticleID_ = extractGenID( g4trk);
38  // V.I. weight is computed in the same way as before
39  // without usage of G4Track::GetWeight()
40  weight_ = 10000*genParticleID_;
41 #ifdef DEBUG
42  LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_
43  << " with mother " << parentID_;
44 #endif
45  }
46 }
47 
48 void TrackWithHistory::checkAtEnd(const G4Track * gt) {
49 
50  math::XYZVectorD vposdir(gt->GetVertexPosition().x(),gt->GetVertexPosition().y(),gt->GetVertexPosition().z());
51  math::XYZVectorD vmomdir(gt->GetVertexMomentumDirection().x(),gt->GetVertexMomentumDirection().y(),gt->GetVertexMomentumDirection().z());
52  bool ok = true;
53  double epsilon = 1.e-6;
54  double eps2 = epsilon*epsilon;
55  if ((vertexPosition_-vposdir).Mag2() > eps2) {
56  edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
57  << "\nAt construction: " << vertexPosition_
58  << "\nAt end: " << vposdir;
59  ok = false;
60  }
61  math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
62  if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
63  edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
64  << "\nAt construction: " << momentum_.Unit()
65  << "\nAt end: " << vmomdir;
66  ok = false;
67  }
68  if (!ok) throw SimG4Exception("TrackWithHistory::checkAtEnd failed");
69 }
70 
71 int TrackWithHistory::extractGenID(const G4Track* gt) const {
72  void * vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
73  if (vgprimary == nullptr) return -1;
74  // replace old-style cast with appropriate new-style cast...
75  G4PrimaryParticle* gprimary = (G4PrimaryParticle*) vgprimary;
77  return ext(gprimary).id();
78 }
#define LogDebug(id)
const G4VProcess * creatorProcess_
G4ThreadLocal G4Allocator< TrackWithHistory > * fpTrackWithHistoryAllocator
int extractGenID(const G4Track *gt) const
math::XYZVectorD vertexPosition_
math::XYZVectorD momentum_
#define nullptr
unsigned int trackID_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
void checkAtEnd(const G4Track *)
static int particleID(const G4Track *)
Definition: Error.h:16
Definition: memstream.h:15
TrackWithHistory(const G4Track *g4track)