CMS 3D CMS Logo

G4SimEvent.cc
Go to the documentation of this file.
3 
4 #include "G4SystemOfUnits.hh"
5 
6 class IdSort {
7 public:
8  bool operator()(const SimTrack& a, const SimTrack& b) { return a.trackId() < b.trackId(); }
9 };
10 
12  : hepMCEvent_(nullptr),
13  weight_(0),
14  collisionPoint_(math::XYZTLorentzVectorD(0., 0., 0., 0.)),
15  nparam_(0),
16  param_(0) {
17  g4vertices_.reserve(2000);
18  g4tracks_.reserve(4000);
19 }
20 
22 
24  // per suggestion by Chris Jones, it's faster
25  // that delete back() and pop_back()
26  for (auto& ptr : g4tracks_) {
27  delete ptr;
28  }
29  g4tracks_.clear();
30  for (auto& ptr : g4vertices_) {
31  delete ptr;
32  }
33  g4vertices_.clear();
34 }
35 
37  for (auto& trk : g4tracks_) {
38  int ip = trk->part();
40  trk->momentum().x() / GeV, trk->momentum().y() / GeV, trk->momentum().z() / GeV, trk->energy() / GeV);
41  int iv = trk->ivert();
42  int ig = trk->igenpart();
43  int id = trk->id();
44  math::XYZVectorD tkpos(trk->trackerSurfacePosition().x() / cm,
45  trk->trackerSurfacePosition().y() / cm,
46  trk->trackerSurfacePosition().z() / cm);
47  math::XYZTLorentzVectorD tkmom(trk->trackerSurfaceMomentum().x() / GeV,
48  trk->trackerSurfaceMomentum().y() / GeV,
49  trk->trackerSurfaceMomentum().z() / GeV,
50  trk->trackerSurfaceMomentum().e() / GeV);
51  // ip = particle ID as PDG
52  // pp = 4-momentum
53  // iv = corresponding G4SimVertex index
54  // ig = corresponding GenParticle index
55  SimTrack t = SimTrack(ip, p, iv, ig, tkpos, tkmom);
56  t.setTrackId(id);
57  t.setEventId(EncodedEventId(0));
58  if (trk->crossedBoundary())
59  t.setCrossedBoundaryVars(
60  trk->crossedBoundary(), trk->getIDAtBoundary(), trk->getPositionAtBoundary(), trk->getMomentumAtBoundary());
61  c.push_back(t);
62  }
63  std::stable_sort(c.begin(), c.end(), IdSort());
64 }
65 
67  for (unsigned int i = 0; i < g4vertices_.size(); ++i) {
69  //
70  // starting 1_1_0_pre3, SimVertex stores in cm !!!
71  //
72  math::XYZVectorD v3(vtx->vertexPosition().x() / cm, vtx->vertexPosition().y() / cm, vtx->vertexPosition().z() / cm);
73  float t = vtx->vertexGlobalTime() / second;
74  int iv = vtx->parentIndex();
75  // vv = position
76  // t = global time
77  // iv = index of the parent in the SimEvent SimTrack container (-1 if no parent)
78  SimVertex v = SimVertex(v3, t, iv, i);
79  v.setProcessType(vtx->processType());
80  v.setEventId(EncodedEventId(0));
81  c.push_back(v);
82  }
83 }
int32_t *__restrict__ iv
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
bool operator()(const SimTrack &a, const SimTrack &b)
Definition: G4SimEvent.cc:8
std::vector< G4SimTrack * > g4tracks_
Definition: G4SimEvent.h:43
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
void load(edm::SimTrackContainer &c) const
Definition: G4SimEvent.cc:36
U second(std::pair< T, U > const &p)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
void clear()
Definition: G4SimEvent.cc:23
std::vector< SimVertex > SimVertexContainer
struct @714 param_
double b
Definition: hdecay.h:118
virtual ~G4SimEvent()
Definition: G4SimEvent.cc:21
double a
Definition: hdecay.h:119
std::vector< G4SimVertex * > g4vertices_
Definition: G4SimEvent.h:44
std::vector< SimTrack > SimTrackContainer