CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackWithHistory.cc
Go to the documentation of this file.
6 
8 
9 #include "G4VProcess.hh"
10 
11 #include <iostream>
12 
13 G4Allocator<TrackWithHistory> TrackWithHistoryAllocator;
14 
15 //#define DEBUG
16 
18 
19 TrackWithHistory::TrackWithHistory(const G4Track * g4trk) :
20  trackID_(0),particleID_(0),parentID_(0),momentum_(math::XYZVectorD(0.,0.,0.)),
21  totalEnergy_(0),vertexPosition_(math::XYZVectorD(0.,0.,0.)),globalTime_(0),
22  localTime_(0),properTime_(0),creatorProcess_(0),weight_(0),
23  storeTrack_(false),saved_(false) {
24 
26  if (g4trk!=0) {
27  TrackInformationExtractor extractor;
28  trackID_ = g4trk->GetTrackID();
30  parentID_ = g4trk->GetParentID();
31  momentum_ = math::XYZVectorD(g4trk->GetMomentum().x(),g4trk->GetMomentum().y(),g4trk->GetMomentum().z());
32  totalEnergy_ = g4trk->GetTotalEnergy();
33  vertexPosition_ = math::XYZVectorD(g4trk->GetPosition().x(),g4trk->GetPosition().y(),g4trk->GetPosition().z());
34  globalTime_ = g4trk->GetGlobalTime();
35  localTime_ = g4trk->GetLocalTime();
36  properTime_ = g4trk->GetProperTime();
37  creatorProcess_ = g4trk->GetCreatorProcess();
38  weight_ = g4trk->GetWeight();
39  storeTrack_ = extractor(g4trk).storeTrack();
40  saved_ = false;
41  genParticleID_ = extractGenID( g4trk);
42 #ifdef DEBUG
43  LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_
44  << " with mother " << parentID_;
45 #endif
46  }
47 }
48 
49 void TrackWithHistory::checkAtEnd(const G4Track * gt) {
50 
51  math::XYZVectorD vposdir(gt->GetVertexPosition().x(),gt->GetVertexPosition().y(),gt->GetVertexPosition().z());
52  math::XYZVectorD vmomdir(gt->GetVertexMomentumDirection().x(),gt->GetVertexMomentumDirection().y(),gt->GetVertexMomentumDirection().z());
53  bool ok = true;
54  double epsilon = 1.e-6;
55  double eps2 = epsilon*epsilon;
56  if ((vertexPosition_-vposdir).Mag2() > eps2) {
57  edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
58  << "\nAt construction: " << vertexPosition_
59  << "\nAt end: " << vposdir;
60  ok = false;
61  }
62  math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
63  if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
64  edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
65  << "\nAt construction: " << momentum_.Unit()
66  << "\nAt end: " << vmomdir;
67  ok = false;
68  }
69  if (!ok) throw SimG4Exception("TrackWithHistory::checkAtEnd failed");
70 }
71 
72 int TrackWithHistory::extractGenID(const G4Track* gt) const {
73  void * vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
74  if (vgprimary == 0) return -1;
75  // replace old-style cast with appropriate new-style cast...
76  G4PrimaryParticle* gprimary = (G4PrimaryParticle*) vgprimary;
78  return ext(gprimary).id();
79 }
#define LogDebug(id)
const G4VProcess * creatorProcess_
int extractGenID(const G4Track *gt) const
math::XYZVectorD vertexPosition_
math::XYZVectorD momentum_
unsigned int trackID_
static G4TrackToParticleID * theG4TrackToParticleID
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:9
G4Allocator< TrackWithHistory > TrackWithHistoryAllocator
void checkAtEnd(const G4Track *)
int particleID(const G4Track *)
DTRecHit1DPair & gt
const double epsilon
TrackWithHistory(const G4Track *g4track)