Go to the documentation of this file.00001 #include "RecoEgamma/EgammaMCTools/interface/PizeroMCTruthFinder.h"
00002 #include "RecoEgamma/EgammaMCTools/interface/PhotonMCTruthFinder.h"
00003 #include "RecoEgamma/EgammaMCTools/interface/ElectronMCTruthFinder.h"
00004
00005
00006 #include <algorithm>
00007
00008 PizeroMCTruthFinder::PizeroMCTruthFinder() {
00009
00010 thePhotonMCTruthFinder_ = new PhotonMCTruthFinder();
00011 theElectronMCTruthFinder_ = new ElectronMCTruthFinder();
00012
00013
00014 }
00015
00016 PizeroMCTruthFinder::~PizeroMCTruthFinder()
00017 {
00018
00019 delete thePhotonMCTruthFinder_;
00020 delete theElectronMCTruthFinder_;
00021 std::cout << "~PizeroMCTruthFinder" << std::endl;
00022 }
00023
00024 std::vector<PizeroMCTruth> PizeroMCTruthFinder::find(std::vector<SimTrack> theSimTracks, std::vector<SimVertex> theSimVertices ) {
00025 std::cout << " PizeroMCTruthFinder::find " << std::endl;
00026
00027
00028 std::vector<PhotonMCTruth> mcPhotons=thePhotonMCTruthFinder_->find (theSimTracks, theSimVertices);
00029
00030 std::vector<PizeroMCTruth> result;
00031 std::vector<PhotonMCTruth> photonsFromPizero;
00032 std::vector<ElectronMCTruth> electronsFromPizero;
00033
00034
00035 const int SINGLE=1;
00036 const int DOUBLE=2;
00037 const int PYTHIA=3;
00038 const int ELECTRON_FLAV=1;
00039 const int PIZERO_FLAV=2;
00040 const int PHOTON_FLAV=3;
00041
00042 int ievtype=0;
00043 int ievflav=0;
00044
00045 std::vector<SimTrack> pizeroTracks;
00046 SimVertex primVtx;
00047
00048
00049 fill(theSimTracks, theSimVertices);
00050
00051 int iPV=-1;
00052 int partType1=0;
00053 int partType2=0;
00054 std::vector<SimTrack>::iterator iFirstSimTk = theSimTracks.begin();
00055 if ( !(*iFirstSimTk).noVertex() ) {
00056 iPV = (*iFirstSimTk).vertIndex();
00057
00058 int vtxId = (*iFirstSimTk).vertIndex();
00059 primVtx = theSimVertices[vtxId];
00060
00061 partType1 = (*iFirstSimTk).type();
00062 std::cout << " Primary vertex id " << iPV << " first track type " << (*iFirstSimTk).type() << std::endl;
00063 } else {
00064 std::cout << " First track has no vertex " << std::endl;
00065 }
00066
00067
00068 math::XYZTLorentzVectorD primVtxPos(primVtx.position().x(),
00069 primVtx.position().y(),
00070 primVtx.position().z(),
00071 primVtx.position().e());
00072
00073
00074 iFirstSimTk++;
00075 if ( iFirstSimTk!= theSimTracks.end() ) {
00076
00077 if ( (*iFirstSimTk).vertIndex() == iPV) {
00078 partType2 = (*iFirstSimTk).type();
00079 std::cout << " second track type " << (*iFirstSimTk).type() << " vertex " << (*iFirstSimTk).vertIndex() << std::endl;
00080
00081 } else {
00082 std::cout << " Only one kine track from Primary Vertex " << std::endl;
00083 }
00084 }
00085
00086 int npv=0;
00087
00088 for (std::vector<SimTrack>::iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk){
00089 if ( (*iSimTk).noVertex() ) continue;
00090
00091 int vertexId = (*iSimTk).vertIndex();
00092 SimVertex vertex = theSimVertices[vertexId];
00093
00094 std::cout << " Particle type " << (*iSimTk).type() << " Sim Track ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum() << " vertex position " << vertex.position() << std::endl;
00095
00096 if ( (*iSimTk).vertIndex() == iPV ) {
00097 npv++;
00098 if ( std::abs((*iSimTk).type() ) == 111) {
00099
00100 std::cout << " Found a primary pizero with ID " << (*iSimTk).trackId() << " momentum " << (*iSimTk).momentum() << std::endl;
00101
00102 pizeroTracks.push_back( *iSimTk );
00103
00104
00105 math::XYZTLorentzVectorD momentum((*iSimTk).momentum().x(),
00106 (*iSimTk).momentum().y(),
00107 (*iSimTk).momentum().z(),
00108 (*iSimTk).momentum().e());
00109
00110
00111 }
00112 }
00113 }
00114
00115
00116 std::cout << " There are " << npv << " particles originating in the PV " << std::endl;
00117
00118 if(npv > 4) {
00119 ievtype = PYTHIA;
00120 } else if(npv == 1) {
00121 if( std::abs(partType1) == 11 ) {
00122 ievtype = SINGLE; ievflav = ELECTRON_FLAV;
00123 } else if(partType1 == 111) {
00124 ievtype = SINGLE; ievflav = PIZERO_FLAV;
00125 } else if(partType1 == 22) {
00126 ievtype = SINGLE; ievflav = PHOTON_FLAV;
00127 }
00128 } else if(npv == 2) {
00129 if ( std::abs(partType1) == 11 && std::abs(partType2) == 11 ) {
00130 ievtype = DOUBLE; ievflav = ELECTRON_FLAV;
00131 } else if(partType1 == 111 && partType2 == 111) {
00132 ievtype = DOUBLE; ievflav = PIZERO_FLAV;
00133 } else if(partType1 == 22 && partType2 == 22) {
00134 ievtype = DOUBLE; ievflav = PHOTON_FLAV;
00135 }
00136 }
00137
00138
00139
00140 for (std::vector<SimTrack>::iterator iPizTk = pizeroTracks.begin(); iPizTk != pizeroTracks.end(); ++iPizTk){
00141 std::cout << " Looping on the primary pizero pt " << sqrt((*iPizTk).momentum().perp2()) << " pizero track ID " << (*iPizTk).trackId() << std::endl;
00142
00143 photonsFromPizero.clear();
00144 std::cout << " mcPhotons.size " << mcPhotons.size() << std::endl;
00145 for ( std::vector<PhotonMCTruth>::iterator iPho=mcPhotons.begin(); iPho !=mcPhotons.end(); ++iPho ){
00146 int phoVtxIndex = (*iPho).vertexInd();
00147 SimVertex phoVtx = theSimVertices[phoVtxIndex];
00148 unsigned int phoParentInd= phoVtx.parentIndex();
00149 std::cout << " photon parent vertex index " << phoParentInd << std::endl;
00150
00151 if (phoParentInd == (*iPizTk).trackId()) {
00152 std::cout << "Matched Photon ID " << (*iPho).trackId() << " vtx " << phoParentInd << " with pizero " << (*iPizTk).trackId() << std::endl;
00153 photonsFromPizero.push_back( *iPho);
00154
00155 }
00156 }
00157 std::cout << " Photon matching the pizero vertex " << photonsFromPizero.size() <<std::endl;
00158
00159
00160
00161 CLHEP::HepLorentzVector tmpMom( (*iPizTk).momentum().px(), (*iPizTk).momentum().py(),
00162 (*iPizTk).momentum().pz(), (*iPizTk).momentum().e() ) ;
00163 CLHEP::HepLorentzVector tmpPos( primVtx.position().x(), primVtx.position().y(),
00164 primVtx.position().z(), primVtx.position().t() ) ;
00165 result.push_back( PizeroMCTruth ( tmpMom, photonsFromPizero, tmpPos ) );
00166
00167
00168 }
00169
00170
00171 std::cout << " Pizero size " << result.size() << std::endl;
00172
00173
00174 return result;
00175 }
00176
00177
00178
00179 void PizeroMCTruthFinder::fill(std::vector<SimTrack>& simTracks,
00180 std::vector<SimVertex>& simVertices ) {
00181
00182
00183 unsigned nVtx = simVertices.size();
00184 unsigned nTks = simTracks.size();
00185
00186
00187 if ( nVtx == 0 ) return;
00188
00189
00190
00191 for( unsigned it=0; it<nTks; ++it ) {
00192 geantToIndex_[ simTracks[it].trackId() ] = it;
00193 std::cout << " PizeroMCTruthFinder::fill it " << it << " simTracks[it].trackId() " << simTracks[it].trackId() << std::endl;
00194
00195 }
00196
00197
00198 }