CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
45  crossedBoundary_ = false;
47  // V.I. weight is computed in the same way as before
48  // without usage of G4Track::GetWeight()
49  weight_ = 10000 * genParticleID_;
50 #ifdef DEBUG
51  LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_ << " with mother "
52  << parentID_;
53 #endif
54  }
55 }
56 
57 void TrackWithHistory::checkAtEnd(const G4Track* gt) {
58  math::XYZVectorD vposdir(gt->GetVertexPosition().x(), gt->GetVertexPosition().y(), gt->GetVertexPosition().z());
59  math::XYZVectorD vmomdir(
60  gt->GetVertexMomentumDirection().x(), gt->GetVertexMomentumDirection().y(), gt->GetVertexMomentumDirection().z());
61  bool ok = true;
62  double epsilon = 1.e-6;
63  double eps2 = epsilon * epsilon;
64  if ((vertexPosition_ - vposdir).Mag2() > eps2) {
65  edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
66  << "\nAt construction: " << vertexPosition_ << "\nAt end: " << vposdir;
67  ok = false;
68  }
69  math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
70  if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
71  edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
72  << "\nAt construction: " << momentum_.Unit()
73  << "\nAt end: " << vmomdir;
74  ok = false;
75  }
76  if (!ok)
77  throw SimG4Exception("TrackWithHistory::checkAtEnd 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
int extractGenID(const G4Track *gt) const
math::XYZVectorD vertexPosition_
math::XYZVectorD momentum_
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 *)
Log< level::Warning, false > LogWarning
TrackWithHistory(const G4Track *g4track)
#define LogDebug(id)