CMS 3D CMS Logo

TmpSimEvent.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  g4vertices_.reserve(2000);
13  g4tracks_.reserve(4000);
14 }
15 
17 
19  for (auto& ptr : g4tracks_) {
20  delete ptr;
21  }
22  g4tracks_.clear();
23  for (auto& ptr : g4vertices_) {
24  delete ptr;
25  }
26  g4vertices_.clear();
27 }
28 
30  const double invgev = 1.0 / CLHEP::GeV;
31  for (auto& trk : g4tracks_) {
32  int ip = trk->part();
33  const math::XYZVectorD& mom = trk->momentum();
34  math::XYZTLorentzVectorD p(mom.x() * invgev, mom.y() * invgev, mom.z() * invgev, trk->energy() * invgev);
35  int iv = trk->ivert();
36  int ig = trk->igenpart();
37  int id = trk->id();
38  // ip = particle ID as PDG
39  // pp = 4-momentum in GeV
40  // iv = corresponding TmpSimVertex index
41  // ig = corresponding GenParticle index
42  SimTrack t = SimTrack(ip, p, iv, ig, trk->trackerSurfacePosition(), trk->trackerSurfaceMomentum());
43  t.setTrackId(id);
44  t.setEventId(EncodedEventId(0));
45  t.setCrossedBoundaryVars(
46  trk->crossedBoundary(), trk->getIDAtBoundary(), trk->getPositionAtBoundary(), trk->getMomentumAtBoundary());
47  c.push_back(t);
48  }
49  std::stable_sort(c.begin(), c.end(), IdSort());
50 }
51 
53  const double invcm = 1.0 / CLHEP::cm;
54  // index of the vertex is needed to make SimVertex object
55  for (unsigned int i = 0; i < g4vertices_.size(); ++i) {
57  auto pos = vtx->vertexPosition();
58  math::XYZVectorD v3(pos.x() * invcm, pos.y() * invcm, pos.z() * invcm);
59  float t = (float)(vtx->vertexGlobalTime() / CLHEP::second);
60  int iv = vtx->parentIndex();
61  // v3 = position in cm
62  // t = global time in second
63  // iv = index of the parent in the SimEvent SimTrack container (-1 if no parent)
64  SimVertex v = SimVertex(v3, t, iv, i);
65  v.setProcessType((unsigned int)vtx->processType());
66  v.setEventId(EncodedEventId(0));
67  c.push_back(v);
68  }
69 }
int32_t *__restrict__ iv
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
std::vector< TmpSimTrack * > g4tracks_
Definition: TmpSimEvent.h:43
void clear()
Definition: TmpSimEvent.cc:18
std::vector< TmpSimVertex * > g4vertices_
Definition: TmpSimEvent.h:44
bool operator()(const SimTrack &a, const SimTrack &b)
Definition: TmpSimEvent.cc:8
U second(std::pair< T, U > const &p)
static const float invgev
Definition: TimingSD.cc:32
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
void load(edm::SimTrackContainer &c) const
Definition: TmpSimEvent.cc:29
std::vector< SimVertex > SimVertexContainer
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
std::vector< SimTrack > SimTrackContainer