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 
18  : trackID_(0),
19  particleID_(0),
20  parentID_(0),
21  momentum_(math::XYZVectorD(0., 0., 0.)),
22  totalEnergy_(0),
23  vertexPosition_(math::XYZVectorD(0., 0., 0.)),
24  globalTime_(0),
25  localTime_(0),
26  properTime_(0),
27  creatorProcess_(nullptr),
28  weight_(0),
29  storeTrack_(false),
30  saved_(false) {
31  if (g4trk != nullptr) {
32  TrackInformationExtractor extractor;
33  trackID_ = g4trk->GetTrackID();
35  parentID_ = g4trk->GetParentID();
36  momentum_ = math::XYZVectorD(g4trk->GetMomentum().x(), g4trk->GetMomentum().y(), g4trk->GetMomentum().z());
37  totalEnergy_ = g4trk->GetTotalEnergy();
38  vertexPosition_ = math::XYZVectorD(g4trk->GetPosition().x(), g4trk->GetPosition().y(), g4trk->GetPosition().z());
39  globalTime_ = g4trk->GetGlobalTime();
40  localTime_ = g4trk->GetLocalTime();
41  properTime_ = g4trk->GetProperTime();
42  creatorProcess_ = g4trk->GetCreatorProcess();
43  storeTrack_ = extractor(g4trk).storeTrack();
44  saved_ = false;
46  // V.I. weight is computed in the same way as before
47  // without usage of G4Track::GetWeight()
48  weight_ = 10000 * genParticleID_;
49 #ifdef DEBUG
50  LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_ << " with mother "
51  << parentID_;
52 #endif
53  }
54 }
55 
56 void TrackWithHistory::checkAtEnd(const G4Track* gt) {
57  math::XYZVectorD vposdir(gt->GetVertexPosition().x(), gt->GetVertexPosition().y(), gt->GetVertexPosition().z());
58  math::XYZVectorD vmomdir(
59  gt->GetVertexMomentumDirection().x(), gt->GetVertexMomentumDirection().y(), gt->GetVertexMomentumDirection().z());
60  bool ok = true;
61  double epsilon = 1.e-6;
62  double eps2 = epsilon * epsilon;
63  if ((vertexPosition_ - vposdir).Mag2() > eps2) {
64  edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
65  << "\nAt construction: " << vertexPosition_ << "\nAt end: " << vposdir;
66  ok = false;
67  }
68  math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
69  if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
70  edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
71  << "\nAt construction: " << momentum_.Unit()
72  << "\nAt end: " << vmomdir;
73  ok = false;
74  }
75  if (!ok)
76  throw SimG4Exception("TrackWithHistory::checkAtEnd failed");
77 }
78 
79 int TrackWithHistory::extractGenID(const G4Track* gt) const {
80  void* vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
81  if (vgprimary == nullptr)
82  return -1;
83  // replace old-style cast with appropriate new-style cast...
84  G4PrimaryParticle* gprimary = (G4PrimaryParticle*)vgprimary;
86  return ext(gprimary).id();
87 }
#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)