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;
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 }
TrackWithHistory::parentID_
int parentID_
Definition: TrackWithHistory.h:69
TrackWithHistory::TrackWithHistory
TrackWithHistory(const G4Track *g4track)
Definition: TrackWithHistory.cc:17
ext
Definition: memstream.h:15
TrackWithHistory::weight_
double weight_
Definition: TrackWithHistory.h:78
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
TrackWithHistory::trackID_
unsigned int trackID_
Definition: TrackWithHistory.h:67
TrackWithHistory::localTime_
double localTime_
Definition: TrackWithHistory.h:75
SimG4Exception
Definition: SimG4Exception.h:13
TrackWithHistory::checkAtEnd
void checkAtEnd(const G4Track *)
Definition: TrackWithHistory.cc:57
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
TrackWithHistory::totalEnergy_
double totalEnergy_
Definition: TrackWithHistory.h:72
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
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:77
TrackInformationExtractor
Definition: TrackInformationExtractor.h:20
submitPVValidationJobs.gt
list gt
Definition: submitPVValidationJobs.py:663
TrackWithHistory::vertexPosition_
math::XYZVectorD vertexPosition_
Definition: TrackWithHistory.h:73
TrackWithHistory::storeTrack_
bool storeTrack_
Definition: TrackWithHistory.h:79
fpTrackWithHistoryAllocator
G4ThreadLocal G4Allocator< TrackWithHistory > * fpTrackWithHistoryAllocator
Definition: TrackWithHistory.cc:13
TrackWithHistory::saved_
bool saved_
Definition: TrackWithHistory.h:80
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:71
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
TrackWithHistory::globalTime_
double globalTime_
Definition: TrackWithHistory.h:74
TrackWithHistory::crossedBoundary_
bool crossedBoundary_
Definition: TrackWithHistory.h:83
TrackWithHistory::extractGenID
int extractGenID(const G4Track *gt) const
Definition: TrackWithHistory.cc:80
TrackWithHistory::particleID_
int particleID_
Definition: TrackWithHistory.h:68
G4TrackToParticleID.h
math
Definition: choleskyInversion.h:19
TrackInformationExtractor.h
TrackWithHistory::genParticleID_
int genParticleID_
Definition: TrackWithHistory.h:70
TrackWithHistory.h
TrackWithHistory::properTime_
double properTime_
Definition: TrackWithHistory.h:76