CMS 3D CMS Logo

TrackWithHistory.cc
Go to the documentation of this file.
5 
7 
8 #include "G4VProcess.hh"
9 
10 #include <iostream>
11 
12 G4ThreadLocal G4Allocator<TrackWithHistory>* fpTrackWithHistoryAllocator = nullptr;
13 
14 //#define DEBUG
15 
17  : trackID_(0),
18  particleID_(0),
19  parentID_(0),
20  momentum_(math::XYZVectorD(0., 0., 0.)),
21  totalEnergy_(0),
22  vertexPosition_(math::XYZVectorD(0., 0., 0.)),
23  globalTime_(0),
24  localTime_(0),
25  properTime_(0),
26  creatorProcess_(nullptr),
27  weight_(0),
28  storeTrack_(false),
29  saved_(false) {
30  if (g4trk != nullptr) {
31  TrackInformationExtractor extractor;
32  trackID_ = g4trk->GetTrackID();
34  parentID_ = g4trk->GetParentID();
35  momentum_ = math::XYZVectorD(g4trk->GetMomentum().x(), g4trk->GetMomentum().y(), g4trk->GetMomentum().z());
36  totalEnergy_ = g4trk->GetTotalEnergy();
37  vertexPosition_ = math::XYZVectorD(g4trk->GetPosition().x(), g4trk->GetPosition().y(), g4trk->GetPosition().z());
38  globalTime_ = g4trk->GetGlobalTime();
39  localTime_ = g4trk->GetLocalTime();
40  properTime_ = g4trk->GetProperTime();
41  creatorProcess_ = g4trk->GetCreatorProcess();
42  storeTrack_ = extractor(g4trk).storeTrack();
43  saved_ = false;
44  crossedBoundary_ = 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 
76  if (!ok)
77  G4Exception("TrackWithHistory::checkAtEnd()", "mc001", FatalException, "check at track end failed");
78 }
79 
80 int TrackWithHistory::extractGenID(const G4Track* gt) const {
81  void* vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
82  if (vgprimary == nullptr)
83  return -1;
84  // replace old-style cast with appropriate new-style cast...
85  G4PrimaryParticle* gprimary = (G4PrimaryParticle*)vgprimary;
87  return ext(gprimary).id();
88 }
const G4VProcess * creatorProcess_
G4ThreadLocal G4Allocator< TrackWithHistory > * fpTrackWithHistoryAllocator
math::XYZVectorD vertexPosition_
math::XYZVectorD momentum_
unsigned int trackID_
int extractGenID(const G4Track *gt) const
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 *)
Log< level::Warning, false > LogWarning
Definition: memstream.h:15
TrackWithHistory(const G4Track *g4track)
#define LogDebug(id)