File indexing completed on 2024-04-06 12:24:56
0001 #include "RecoEgamma/EgammaMCTools/interface/ElectronMCTruthFinder.h"
0002
0003 #include <algorithm>
0004
0005 ElectronMCTruthFinder::ElectronMCTruthFinder() {}
0006
0007 ElectronMCTruthFinder::~ElectronMCTruthFinder() {}
0008
0009 std::vector<ElectronMCTruth> ElectronMCTruthFinder::find(const std::vector<SimTrack>& theSimTracks,
0010 const std::vector<SimVertex>& theSimVertices) {
0011
0012
0013 std::vector<ElectronMCTruth> result;
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 std::vector<SimTrack> electronTracks;
0027 SimVertex primVtx;
0028
0029 fill(theSimTracks, theSimVertices);
0030
0031 int iPV = -1;
0032
0033
0034 std::vector<SimTrack>::const_iterator iFirstSimTk = theSimTracks.begin();
0035 if (!(*iFirstSimTk).noVertex()) {
0036 iPV = (*iFirstSimTk).vertIndex();
0037
0038 int vtxId = (*iFirstSimTk).vertIndex();
0039 primVtx = theSimVertices[vtxId];
0040
0041
0042
0043
0044 } else {
0045
0046 }
0047
0048
0049 math::XYZTLorentzVectorD primVtxPos(
0050 primVtx.position().x(), primVtx.position().y(), primVtx.position().z(), primVtx.position().e());
0051
0052
0053 iFirstSimTk++;
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
0069 if ((*iSimTk).noVertex())
0070 continue;
0071
0072
0073
0074
0075
0076 if ((*iSimTk).vertIndex() == iPV) {
0077 if (std::abs((*iSimTk).type()) == 11) {
0078
0079 electronTracks.push_back(*iSimTk);
0080 }
0081 }
0082 }
0083
0084
0085 std::vector<CLHEP::Hep3Vector> bremPos;
0086 std::vector<CLHEP::HepLorentzVector> pBrem;
0087 std::vector<float> xBrem;
0088
0089 for (std::vector<SimTrack>::iterator iEleTk = electronTracks.begin(); iEleTk != electronTracks.end(); ++iEleTk) {
0090
0091
0092 SimTrack trLast = (*iEleTk);
0093 unsigned int eleId = (*iEleTk).trackId();
0094 float remainingEnergy = trLast.momentum().e();
0095
0096
0097 math::XYZTLorentzVectorD motherMomentum(
0098 (*iEleTk).momentum().x(), (*iEleTk).momentum().y(), (*iEleTk).momentum().z(), (*iEleTk).momentum().e());
0099 math::XYZTLorentzVectorD primEleMom(motherMomentum);
0100 int eleVtxIndex = (*iEleTk).vertIndex();
0101
0102 bremPos.clear();
0103 pBrem.clear();
0104 xBrem.clear();
0105
0106 for (std::vector<SimTrack>::const_iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
0107 if ((*iSimTk).noVertex())
0108 continue;
0109 if ((*iSimTk).vertIndex() == iPV)
0110 continue;
0111
0112
0113
0114 int vertexId1 = (*iSimTk).vertIndex();
0115 const SimVertex& vertex1 = theSimVertices[vertexId1];
0116 int vertexId2 = trLast.vertIndex();
0117
0118
0119 int motherId = -1;
0120
0121 if ((vertexId1 == vertexId2) && ((*iSimTk).type() == (*iEleTk).type()) && trLast.type() == 22) {
0122
0123
0124
0125
0126
0127
0128
0129
0130 float eLoss = remainingEnergy - ((*iSimTk).momentum() + trLast.momentum()).e();
0131
0132
0133 if (vertex1.parentIndex()) {
0134 unsigned motherGeantId = vertex1.parentIndex();
0135 std::map<unsigned, unsigned>::iterator association = geantToIndex_.find(motherGeantId);
0136 if (association != geantToIndex_.end())
0137 motherId = association->second;
0138
0139
0140
0141 if (theSimTracks[motherId].trackId() == eleId) {
0142
0143 eleId = (*iSimTk).trackId();
0144 remainingEnergy = (*iSimTk).momentum().e();
0145 motherMomentum = (*iSimTk).momentum();
0146
0147 pBrem.push_back(CLHEP::HepLorentzVector(
0148 trLast.momentum().px(), trLast.momentum().py(), trLast.momentum().pz(), trLast.momentum().e()));
0149 bremPos.push_back(CLHEP::HepLorentzVector(
0150 vertex1.position().x(), vertex1.position().y(), vertex1.position().z(), vertex1.position().t()));
0151 xBrem.push_back(eLoss);
0152 }
0153
0154 } else {
0155
0156 }
0157 }
0158 trLast = (*iSimTk);
0159
0160 }
0161
0162
0163 CLHEP::HepLorentzVector tmpEleMom(primEleMom.px(), primEleMom.py(), primEleMom.pz(), primEleMom.e());
0164 CLHEP::HepLorentzVector tmpVtxPos(primVtxPos.x(), primVtxPos.y(), primVtxPos.z(), primVtxPos.t());
0165 result.push_back(ElectronMCTruth(tmpEleMom, eleVtxIndex, bremPos, pBrem, xBrem, tmpVtxPos, (*iEleTk)));
0166
0167 }
0168
0169 return result;
0170 }
0171
0172 void ElectronMCTruthFinder::fill(const std::vector<SimTrack>& simTracks, const std::vector<SimVertex>& simVertices) {
0173
0174
0175 unsigned nVtx = simVertices.size();
0176 unsigned nTks = simTracks.size();
0177
0178
0179 if (nVtx == 0)
0180 return;
0181
0182
0183
0184 for (unsigned it = 0; it < nTks; ++it) {
0185 geantToIndex_[simTracks[it].trackId()] = it;
0186
0187 }
0188 }