00001 #include "RecoEgamma/EgammaMCTools/interface/ElectronMCTruthFinder.h"
00002
00003
00004 #include <algorithm>
00005
00006 ElectronMCTruthFinder::ElectronMCTruthFinder() {
00007
00008
00009 }
00010
00011 ElectronMCTruthFinder::~ElectronMCTruthFinder()
00012 {
00013
00014 }
00015
00016
00017 std::vector<ElectronMCTruth> ElectronMCTruthFinder::find(std::vector<SimTrack> theSimTracks, std::vector<SimVertex> theSimVertices ) {
00018
00019
00020
00021
00022
00023 std::vector<ElectronMCTruth> result;
00024
00025
00026 const int SINGLE=1;
00027 const int DOUBLE=2;
00028 const int PYTHIA=3;
00029 const int ELECTRON_FLAV=1;
00030 const int PIZERO_FLAV=2;
00031 const int PHOTON_FLAV=3;
00032
00033 int ievtype=0;
00034 int ievflav=0;
00035
00036
00037 std::vector<SimTrack> electronTracks;
00038 SimVertex primVtx;
00039
00040 fill(theSimTracks, theSimVertices);
00041
00042 int iPV=-1;
00043 int partType1=0;
00044 int partType2=0;
00045 std::vector<SimTrack>::iterator iFirstSimTk = theSimTracks.begin();
00046 if ( !(*iFirstSimTk).noVertex() ) {
00047 iPV = (*iFirstSimTk).vertIndex();
00048
00049 int vtxId = (*iFirstSimTk).vertIndex();
00050 primVtx = theSimVertices[vtxId];
00051
00052 partType1 = (*iFirstSimTk).type();
00053
00054
00055
00056 } else {
00057
00058 }
00059
00060
00061 math::XYZTLorentzVectorD primVtxPos(primVtx.position().x(),
00062 primVtx.position().y(),
00063 primVtx.position().z(),
00064 primVtx.position().e());
00065
00066
00067 iFirstSimTk++;
00068 if ( iFirstSimTk!= theSimTracks.end() ) {
00069
00070 if ( (*iFirstSimTk).vertIndex() == iPV) {
00071 partType2 = (*iFirstSimTk).type();
00072
00073
00074
00075 } else {
00076
00077 }
00078 }
00079
00080
00081
00082 int npv=0;
00083 for (std::vector<SimTrack>::iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk){
00084 if ( (*iSimTk).noVertex() ) continue;
00085
00086 int vertexId = (*iSimTk).vertIndex();
00087 SimVertex vertex = theSimVertices[vertexId];
00088
00089
00090 if ( (*iSimTk).vertIndex() == iPV ) {
00091 npv++;
00092 if ( fabs((*iSimTk).type() ) == 11) {
00093
00094 electronTracks.push_back( *iSimTk );
00095 }
00096 }
00097 }
00098
00099
00100
00101 if(npv > 4) {
00102 ievtype = PYTHIA;
00103 } else if(npv == 1) {
00104 if( abs(partType1) == 11 ) {
00105 ievtype = SINGLE; ievflav = ELECTRON_FLAV;
00106 } else if(partType1 == 111) {
00107 ievtype = SINGLE; ievflav = PIZERO_FLAV;
00108 } else if(partType1 == 22) {
00109 ievtype = SINGLE; ievflav = PHOTON_FLAV;
00110 }
00111 } else if(npv == 2) {
00112 if ( abs(partType1) == 11 && abs(partType2) == 11 ) {
00113 ievtype = DOUBLE; ievflav = ELECTRON_FLAV;
00114 } else if(partType1 == 111 && partType2 == 111) {
00115 ievtype = DOUBLE; ievflav = PIZERO_FLAV;
00116 } else if(partType1 == 22 && partType2 == 22) {
00117 ievtype = DOUBLE; ievflav = PHOTON_FLAV;
00118 }
00119 }
00120
00121
00122
00124 std::vector<Hep3Vector> bremPos;
00125 std::vector<HepLorentzVector> pBrem;
00126 std::vector<float> xBrem;
00127
00128
00129 for (std::vector<SimTrack>::iterator iEleTk = electronTracks.begin(); iEleTk != electronTracks.end(); ++iEleTk){
00130
00131
00132
00133
00134 SimTrack trLast =(*iEleTk);
00135 int eleId = (*iEleTk).trackId();
00136 float remainingEnergy =trLast.momentum().e();
00137
00138
00139 math::XYZTLorentzVectorD motherMomentum((*iEleTk).momentum().x(),
00140 (*iEleTk).momentum().y(),
00141 (*iEleTk).momentum().z(),
00142 (*iEleTk).momentum().e());
00143 math::XYZTLorentzVectorD primEleMom(motherMomentum);
00144 int eleVtxIndex= (*iEleTk).vertIndex();
00145
00146 bremPos.clear();
00147 pBrem.clear();
00148 xBrem.clear();
00149
00150
00151 for (std::vector<SimTrack>::iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk){
00152
00153 if ( (*iSimTk).noVertex() ) continue;
00154 if ( (*iSimTk).vertIndex() == iPV ) continue;
00155
00156
00157
00158 int vertexId1 = (*iSimTk).vertIndex();
00159 SimVertex vertex1 = theSimVertices[vertexId1];
00160 int vertexId2 = trLast.vertIndex();
00161 SimVertex vertex2 = theSimVertices[vertexId2];
00162
00163
00164 int motherId=-1;
00165
00166 if( ( vertexId1 == vertexId2 ) && ( (*iSimTk).type() == (*iEleTk).type() ) && trLast.type() == 22 ) {
00167
00168
00169
00170
00171
00172
00173
00174
00175 float eLoss = remainingEnergy - ( (*iSimTk).momentum() + trLast.momentum()).e();
00176
00177
00178
00179 if ( vertex1.parentIndex() ) {
00180
00181 unsigned motherGeantId = vertex1.parentIndex();
00182 std::map<unsigned, unsigned >::iterator association = geantToIndex_.find( motherGeantId );
00183 if(association != geantToIndex_.end() )
00184 motherId = association->second;
00185
00186 int motherType = motherId == -1 ? 0 : theSimTracks[motherId].type();
00187
00188 if ( theSimTracks[motherId].trackId() == eleId ) {
00189
00190
00191 eleId= (*iSimTk).trackId();
00192 remainingEnergy = (*iSimTk).momentum().e();
00193 motherMomentum = (*iSimTk).momentum();
00194
00195
00196 pBrem.push_back( HepLorentzVector(trLast.momentum().px(),trLast.momentum().py(),
00197 trLast.momentum().pz(),trLast.momentum().e()) );
00198 bremPos.push_back( HepLorentzVector(vertex1.position().x(),vertex1.position().y(),
00199 vertex1.position().z(),vertex1.position().t()) );
00200 xBrem.push_back(eLoss);
00201
00202 }
00203
00204
00205
00206
00207 } else {
00208
00209 }
00210
00211 }
00212 trLast=(*iSimTk);
00213
00214 }
00215
00217 HepLorentzVector tmpEleMom(primEleMom.px(),primEleMom.py(),
00218 primEleMom.pz(),primEleMom.e() ) ;
00219 HepLorentzVector tmpVtxPos(primVtxPos.x(),primVtxPos.y(),primVtxPos.z(),primVtxPos.t());
00220 result.push_back ( ElectronMCTruth( tmpEleMom, eleVtxIndex, bremPos, pBrem, xBrem, tmpVtxPos,(*iEleTk) ) ) ;
00221
00222
00223 }
00224
00225
00226
00227 return result;
00228 }
00229
00230
00231
00232 void ElectronMCTruthFinder::fill(std::vector<SimTrack>& simTracks,
00233 std::vector<SimVertex>& simVertices ) {
00234
00235
00236 unsigned nVtx = simVertices.size();
00237 unsigned nTks = simTracks.size();
00238
00239
00240 if ( nVtx == 0 ) return;
00241
00242
00243
00244 for( unsigned it=0; it<nTks; ++it ) {
00245 geantToIndex_[ simTracks[it].trackId() ] = it;
00246
00247
00248 }
00249
00250
00251 }