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  storeTrack_ = extractor(g4trk).storeTrack();
39  saved_ = false;
40  genParticleID_ = extractGenID( g4trk);
41  // V.I. weight is computed in the same way as before
42  // without usage of G4Track::GetWeight()
43  weight_ = 10000*genParticleID_;
44 #ifdef DEBUG
45  LogDebug("TrackInformation") << " TrackWithHistory : created history for " << trackID_
46  << " with mother " << parentID_;
47 #endif
48  }
49 }
50 
51 void TrackWithHistory::checkAtEnd(const G4Track * gt) {
52 
53  math::XYZVectorD vposdir(gt->GetVertexPosition().x(),gt->GetVertexPosition().y(),gt->GetVertexPosition().z());
54  math::XYZVectorD vmomdir(gt->GetVertexMomentumDirection().x(),gt->GetVertexMomentumDirection().y(),gt->GetVertexMomentumDirection().z());
55  bool ok = true;
56  double epsilon = 1.e-6;
57  double eps2 = epsilon*epsilon;
58  if ((vertexPosition_-vposdir).Mag2() > eps2) {
59  edm::LogWarning("TrackInformation") << "TrackWithHistory vertex position check failed"
60  << "\nAt construction: " << vertexPosition_
61  << "\nAt end: " << vposdir;
62  ok = false;
63  }
64  math::XYZVectorD dirDiff = momentum_.Unit() - vmomdir;
65  if (dirDiff.Mag2() > eps2 && momentum_.Unit().R() > eps2) {
66  edm::LogWarning("TrackInformation") << "TrackWithHistory momentum direction check failed"
67  << "\nAt construction: " << momentum_.Unit()
68  << "\nAt end: " << vmomdir;
69  ok = false;
70  }
71  if (!ok) throw SimG4Exception("TrackWithHistory::checkAtEnd failed");
72 }
73 
74 int TrackWithHistory::extractGenID(const G4Track* gt) const {
75  void * vgprimary = gt->GetDynamicParticle()->GetPrimaryParticle();
76  if (vgprimary == 0) return -1;
77  // replace old-style cast with appropriate new-style cast...
78  G4PrimaryParticle* gprimary = (G4PrimaryParticle*) vgprimary;
80  return ext(gprimary).id();
81 }
#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)