--- UserCode/kiesel/TreeWriter/treeWriter.cc 2013/04/24 13:24:30 1.22 +++ UserCode/kiesel/TreeWriter/treeWriter.cc 2013/04/25 17:37:32 1.26 @@ -70,10 +70,17 @@ std::vector* getVectorFromMap( map return vec; } +float deltaPhi( float phi1, float phi2) { + float result = phi1 - phi2; + while (result > M_PI) result -= 2*M_PI; + while (result <= -M_PI) result += 2*M_PI; + return result; +} + // useful functions float deltaR( const TLorentzVector& v1, const TLorentzVector& v2 ) { // deltaR = sqrt ( deltaEta^2 + deltaPhi^2 ) - return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) ); + return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(deltaPhi(v1.Phi(),v2.Phi()), 2) ); } float effectiveAreaElectron( float eta ) { @@ -472,18 +479,19 @@ void TreeWriter::Loop() { tree::Particle thisGenParticle; for( std::vector::iterator it = event->genParticles.begin(); it != event->genParticles.end(); ++it ) { - if( it->status == 3 ) { // hard interaction - switch( std::abs(it->pdgId) ) { - thisGenParticle.pt = it->momentum.Pt(); - thisGenParticle.eta = it->momentum.Eta(); - thisGenParticle.phi = it->momentum.Phi(); - case 22: // photon - if( thisGenParticle.pt > 75 ) - genPhoton.push_back( thisGenParticle ); - case 11: // electron - if( thisGenParticle.pt > 20 ) // pt cut is lower to estimate fake rate in all pt bins - genElectron.push_back( thisGenParticle ); - } + if( it->momentum.Pt() < 20 ) continue; + thisGenParticle.pt = it->momentum.Pt(); + thisGenParticle.eta = it->momentum.Eta(); + thisGenParticle.phi = it->momentum.Phi(); + switch( std::abs(it->pdgId) ) { + case 22: // photon + genPhoton.push_back( thisGenParticle ); + break; + case 11: // electron + // Demand a W boson as mother particle of electron + if( abs(event->genParticles[it->motherIndex].pdgId) == 24 ) + genElectron.push_back( thisGenParticle ); + break; } }