CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ElectronMCTruthFinder Class Reference

#include <ElectronMCTruthFinder.h>

Public Member Functions

 ElectronMCTruthFinder ()
 
std::vector< ElectronMCTruthfind (const std::vector< SimTrack > &simTracks, const std::vector< SimVertex > &simVertices)
 
virtual ~ElectronMCTruthFinder ()
 

Private Member Functions

void fill (const std::vector< SimTrack > &theSimTracks, const std::vector< SimVertex > &theSimVertices)
 

Private Attributes

std::map< unsigned, unsigned > geantToIndex_
 
PhotonMCTruthFinderthePhotonMCTruthFinder_
 

Detailed Description

Definition at line 13 of file ElectronMCTruthFinder.h.

Constructor & Destructor Documentation

◆ ElectronMCTruthFinder()

ElectronMCTruthFinder::ElectronMCTruthFinder ( )

Definition at line 5 of file ElectronMCTruthFinder.cc.

5 {}

◆ ~ElectronMCTruthFinder()

ElectronMCTruthFinder::~ElectronMCTruthFinder ( )
virtual

Definition at line 7 of file ElectronMCTruthFinder.cc.

7 {}

Member Function Documentation

◆ fill()

void ElectronMCTruthFinder::fill ( const std::vector< SimTrack > &  theSimTracks,
const std::vector< SimVertex > &  theSimVertices 
)
private

Definition at line 172 of file ElectronMCTruthFinder.cc.

References geantToIndex_, L1TkPrimaryVertex_cfi::nVtx, TrackCandidateProducer_cfi::simTracks, and HGCalValidator_cfi::simVertices.

Referenced by find().

172  {
173  //std::cout << " ElectronMCTruthFinder::fill " << std::endl;
174 
175  unsigned nVtx = simVertices.size();
176  unsigned nTks = simTracks.size();
177 
178  // Empty event, do nothin'
179  if (nVtx == 0)
180  return;
181 
182  // create a map associating geant particle id and position in the
183  // event SimTrack vector
184  for (unsigned it = 0; it < nTks; ++it) {
185  geantToIndex_[simTracks[it].trackId()] = it;
186  //std::cout << " ElectronMCTruthFinder::fill it " << it << " simTracks[it].trackId() " << simTracks[it].trackId() << std::endl;
187  }
188 }
std::map< unsigned, unsigned > geantToIndex_

◆ find()

std::vector< ElectronMCTruth > ElectronMCTruthFinder::find ( const std::vector< SimTrack > &  simTracks,
const std::vector< SimVertex > &  simVertices 
)

Now store the electron truth

here fill the electron

Definition at line 9 of file ElectronMCTruthFinder.cc.

References funct::abs(), MillePedeFileConverter_cfg::e, TrackingDataMCValidation_Standalone_cff::electronTracks, simKBmtfDigis_cfi::eLoss, fill(), geantToIndex_, caHitNtupletGeneratorKernels::if(), CoreSimTrack::momentum(), objects.autophobj::motherId, SimVertex::parentIndex(), CoreSimVertex::position(), mps_fire::result, CoreSimTrack::trackId(), CoreSimTrack::type(), and SimTrack::vertIndex().

10  {
11  //std::cout << " ElectronMCTruthFinder::find " << std::endl;
12 
13  std::vector<ElectronMCTruth> result;
14 
15  // Local variables
16  //const int SINGLE=1;
17  //const int DOUBLE=2;
18  //const int PYTHIA=3;
19  //const int ELECTRON_FLAV=1;
20  //const int PIZERO_FLAV=2;
21  //const int PHOTON_FLAV=3;
22 
23  //int ievtype=0;
24  //int ievflav=0;
25 
26  std::vector<SimTrack> electronTracks;
27  SimVertex primVtx;
28 
29  fill(theSimTracks, theSimVertices);
30 
31  int iPV = -1;
32  //int partType1=0;
33  //int partType2=0;
34  std::vector<SimTrack>::const_iterator iFirstSimTk = theSimTracks.begin();
35  if (!(*iFirstSimTk).noVertex()) {
36  iPV = (*iFirstSimTk).vertIndex();
37 
38  int vtxId = (*iFirstSimTk).vertIndex();
39  primVtx = theSimVertices[vtxId];
40 
41  //partType1 = (*iFirstSimTk).type();
42 
43  //std::cout << " Primary vertex id " << iPV << " first track type " << (*iFirstSimTk).type() << std::endl;
44  } else {
45  //std::cout << " First track has no vertex " << std::endl;
46  }
47 
48  // CLHEP::HepLorentzVector primVtxPos= primVtx.position();
49  math::XYZTLorentzVectorD primVtxPos(
50  primVtx.position().x(), primVtx.position().y(), primVtx.position().z(), primVtx.position().e());
51 
52  // Look at a second track
53  iFirstSimTk++;
54  //if ( iFirstSimTk!= theSimTracks.end() ) {
55  //
56  // if ( (*iFirstSimTk).vertIndex() == iPV) {
57  // partType2 = (*iFirstSimTk).type();
58  //
59  // //std::cout << " second track type " << (*iFirstSimTk).type() << " vertex " << (*iFirstSimTk).vertIndex() << std::endl;
60  //
61  // } else {
62  // //std::cout << " Only one kine track from Primary Vertex " << std::endl;
63  // }
64  //}
65 
66  //std::cout << " Loop over all particles " << std::endl;
67 
68  for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
69  if ((*iSimTk).noVertex())
70  continue;
71 
72  //int vertexId = (*iSimTk).vertIndex();
73  //SimVertex vertex = theSimVertices[vertexId];
74 
75  //std::cout << " Particle type " << (*iSimTk).type() << " Sim Track ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum() << " vertex position " << vertex.position() << " vertex ID " << vertexId << std::endl;
76  if ((*iSimTk).vertIndex() == iPV) {
77  if (std::abs((*iSimTk).type()) == 11) {
78  //std::cout << " Found a primary electron with ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum() << std::endl;
79  electronTracks.push_back(*iSimTk);
80  }
81  }
82  }
83 
85  std::vector<CLHEP::Hep3Vector> bremPos;
86  std::vector<CLHEP::HepLorentzVector> pBrem;
87  std::vector<float> xBrem;
88 
89  for (std::vector<SimTrack>::iterator iEleTk = electronTracks.begin(); iEleTk != electronTracks.end(); ++iEleTk) {
90  //std::cout << " Looping on the primary electron pt " << std::sqrt((*iEleTk).momentum().perp2()) << " electron track ID " << (*iEleTk).trackId() << std::endl;
91 
92  SimTrack trLast = (*iEleTk);
93  unsigned int eleId = (*iEleTk).trackId();
94  float remainingEnergy = trLast.momentum().e();
95  // CLHEP::HepLorentzVector motherMomentum = (*iEleTk).momentum();
96  // CLHEP::HepLorentzVector primEleMom = (*iEleTk).momentum();
97  math::XYZTLorentzVectorD motherMomentum(
98  (*iEleTk).momentum().x(), (*iEleTk).momentum().y(), (*iEleTk).momentum().z(), (*iEleTk).momentum().e());
99  math::XYZTLorentzVectorD primEleMom(motherMomentum);
100  int eleVtxIndex = (*iEleTk).vertIndex();
101 
102  bremPos.clear();
103  pBrem.clear();
104  xBrem.clear();
105 
106  for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
107  if ((*iSimTk).noVertex())
108  continue;
109  if ((*iSimTk).vertIndex() == iPV)
110  continue;
111 
112  //std::cout << " (*iEleTk)->trackId() " << (*iEleTk).trackId() << " (*iEleTk)->vertIndex() "<< (*iEleTk).vertIndex() << " (*iSimTk).vertIndex() " << (*iSimTk).vertIndex() << " (*iSimTk).type() " << (*iSimTk).type() << " (*iSimTk).trackId() " << (*iSimTk).trackId() << std::endl;
113 
114  int vertexId1 = (*iSimTk).vertIndex();
115  const SimVertex& vertex1 = theSimVertices[vertexId1];
116  int vertexId2 = trLast.vertIndex();
117  //SimVertex vertex2 = theSimVertices[vertexId2];
118 
119  int motherId = -1;
120 
121  if ((vertexId1 == vertexId2) && ((*iSimTk).type() == (*iEleTk).type()) && trLast.type() == 22) {
122  //std::cout << " Here a e/gamma brem vertex " << std::endl;
123 
124  //std::cout << " Secondary from electron: particle1 type " << (*iSimTk).type() << " trackId " << (*iSimTk).trackId() << " vertex ID " << vertexId1 << " vertex position " << std::sqrt(vertex1.position().perp2()) << " parent index "<< vertex1.parentIndex() << std::endl;
125 
126  //std::cout << " Secondary from electron: particle2 type " << trLast.type() << " trackId " << trLast.trackId()<< " vertex ID " << vertexId2 << " vertex position " << std::sqrt(vertex2.position().perp2()) << " parent index " << vertex2.parentIndex() << std::endl;
127 
128  //std::cout << " Electron pt " << std::sqrt((*iSimTk).momentum().perp2()) << " photon pt " << std::sqrt(trLast.momentum().perp2()) << "Mother electron pt " << sqrt(motherMomentum.perp2()) << std::endl;
129  //std::cout << " eleId " << eleId << std::endl;
130  float eLoss = remainingEnergy - ((*iSimTk).momentum() + trLast.momentum()).e();
131  //std::cout << " eLoss " << eLoss << std::endl;
132 
133  if (vertex1.parentIndex()) {
134  unsigned motherGeantId = vertex1.parentIndex();
135  std::map<unsigned, unsigned>::iterator association = geantToIndex_.find(motherGeantId);
136  if (association != geantToIndex_.end())
137  motherId = association->second;
138 
139  //int motherType = motherId == -1 ? 0 : theSimTracks[motherId].type();
140  //std::cout << " Parent to this vertex motherId " << motherId << " mother type " << motherType << " Sim track ID " << theSimTracks[motherId].trackId() << std::endl;
141  if (theSimTracks[motherId].trackId() == eleId) {
142  //std::cout << " ***** Found the Initial Mother Electron **** theSimTracks[motherId].trackId() " << theSimTracks[motherId].trackId() << " eleId " << eleId << std::endl;
143  eleId = (*iSimTk).trackId();
144  remainingEnergy = (*iSimTk).momentum().e();
145  motherMomentum = (*iSimTk).momentum();
146 
147  pBrem.push_back(CLHEP::HepLorentzVector(
148  trLast.momentum().px(), trLast.momentum().py(), trLast.momentum().pz(), trLast.momentum().e()));
149  bremPos.push_back(CLHEP::HepLorentzVector(
150  vertex1.position().x(), vertex1.position().y(), vertex1.position().z(), vertex1.position().t()));
151  xBrem.push_back(eLoss);
152  }
153 
154  } else {
155  //std::cout << " This vertex has no parent tracks " << std::endl;
156  }
157  }
158  trLast = (*iSimTk);
159 
160  } // End loop over all SimTracks
161  //std::cout << " Going to build the ElectronMCTruth: pBrem size " << pBrem.size() << std::endl;
163  CLHEP::HepLorentzVector tmpEleMom(primEleMom.px(), primEleMom.py(), primEleMom.pz(), primEleMom.e());
164  CLHEP::HepLorentzVector tmpVtxPos(primVtxPos.x(), primVtxPos.y(), primVtxPos.z(), primVtxPos.t());
165  result.push_back(ElectronMCTruth(tmpEleMom, eleVtxIndex, bremPos, pBrem, xBrem, tmpVtxPos, (*iEleTk)));
166 
167  } // End loop over primary electrons
168 
169  return result;
170 }
std::map< unsigned, unsigned > geantToIndex_
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
const math::XYZTLorentzVectorD & position() const
Definition: CoreSimVertex.h:21
void fill(const std::vector< SimTrack > &theSimTracks, const std::vector< SimVertex > &theSimVertices)
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:19
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:22
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:33
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int trackId() const
Definition: CoreSimTrack.h:31
int parentIndex() const
Definition: SimVertex.h:29

Member Data Documentation

◆ geantToIndex_

std::map<unsigned, unsigned> ElectronMCTruthFinder::geantToIndex_
private

Definition at line 24 of file ElectronMCTruthFinder.h.

Referenced by fill(), and find().

◆ thePhotonMCTruthFinder_

PhotonMCTruthFinder* ElectronMCTruthFinder::thePhotonMCTruthFinder_
private

Definition at line 25 of file ElectronMCTruthFinder.h.