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 }
TrackWithHistory::parentID_
int parentID_
Definition: TrackWithHistory.h:55
TrackWithHistory::TrackWithHistory
TrackWithHistory(const G4Track *g4track)
Definition: TrackWithHistory.cc:17
ext
Definition: memstream.h:15
TrackWithHistory::weight_
double weight_
Definition: TrackWithHistory.h:64
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
TrackWithHistory::trackID_
unsigned int trackID_
Definition: TrackWithHistory.h:53
TrackWithHistory::localTime_
double localTime_
Definition: TrackWithHistory.h:61
SimG4Exception
Definition: SimG4Exception.h:13
TrackWithHistory::checkAtEnd
void checkAtEnd(const G4Track *)
Definition: TrackWithHistory.cc:56
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
TrackWithHistory::totalEnergy_
double totalEnergy_
Definition: TrackWithHistory.h:58
G4TrackToParticleID::particleID
static int particleID(const G4Track *)
Definition: G4TrackToParticleID.cc:7
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
GenParticleInfoExtractor.h
GenParticleInfoExtractor
Definition: GenParticleInfoExtractor.h:8
TrackWithHistory::creatorProcess_
const G4VProcess * creatorProcess_
Definition: TrackWithHistory.h:63
TrackInformationExtractor
Definition: TrackInformationExtractor.h:20
TrackWithHistory::vertexPosition_
math::XYZVectorD vertexPosition_
Definition: TrackWithHistory.h:59
TrackWithHistory::storeTrack_
bool storeTrack_
Definition: TrackWithHistory.h:65
fpTrackWithHistoryAllocator
G4ThreadLocal G4Allocator< TrackWithHistory > * fpTrackWithHistoryAllocator
Definition: TrackWithHistory.cc:13
edm::LogWarning
Definition: MessageLogger.h:141
TrackWithHistory::saved_
bool saved_
Definition: TrackWithHistory.h:66
math::XYZVectorD
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
SimG4Exception.h
TrackWithHistory::momentum_
math::XYZVectorD momentum_
Definition: TrackWithHistory.h:57
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
TrackWithHistory::globalTime_
double globalTime_
Definition: TrackWithHistory.h:60
TrackWithHistory::extractGenID
int extractGenID(const G4Track *gt) const
Definition: TrackWithHistory.cc:79
TrackWithHistory::particleID_
int particleID_
Definition: TrackWithHistory.h:54
G4TrackToParticleID.h
math
Definition: choleskyInversion.h:19
TrackInformationExtractor.h
TrackWithHistory::genParticleID_
int genParticleID_
Definition: TrackWithHistory.h:56
TrackWithHistory.h
TrackWithHistory::properTime_
double properTime_
Definition: TrackWithHistory.h:62