Skip to content

Commit

Permalink
Merge pull request #3279 from VinInn/VertexLoopInPFPhotonIsolationCal…
Browse files Browse the repository at this point in the history
…culator

Reco -- Fix vertex loop in PFPhotonIsolationCalculator
  • Loading branch information
ktf committed Apr 14, 2014
2 parents 3e3d205 + 77cb53a commit 3c0efc4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 51 deletions.
37 changes: 10 additions & 27 deletions CommonTools/ParticleFlow/src/PFPileUpAlgo.cc
Expand Up @@ -42,37 +42,20 @@ void PFPileUpAlgo::process(const PFCollection & pfCandidates,
int
PFPileUpAlgo::chargedHadronVertex( const reco::VertexCollection& vertices, const reco::PFCandidate& pfcand ) const {


reco::TrackBaseRef trackBaseRef( pfcand.trackRef() );

auto const & track = pfcand.trackRef();
size_t iVertex = 0;
unsigned index=0;
unsigned nFoundVertex = 0;
typedef reco::VertexCollection::const_iterator IV;
typedef reco::Vertex::trackRef_iterator IT;
unsigned int index=0;
unsigned int nFoundVertex = 0;
float bestweight=0;
for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv, ++index) {

const reco::Vertex& vtx = *iv;

// loop on tracks in vertices
for(IT iTrack=vtx.tracks_begin();
iTrack!=vtx.tracks_end(); ++iTrack) {

const reco::TrackBaseRef& baseRef = *iTrack;

// one of the tracks in the vertex is the same as
// the track considered in the function
if(baseRef == trackBaseRef ) {
float w = vtx.trackWeight(baseRef);
//select the vertex for which the track has the highest weight
if (w > bestweight){
for( auto const & vtx : vertices) {
float w = vtx.trackWeight(track);
//select the vertex for which the track has the highest weight
if (w > bestweight){
bestweight=w;
iVertex=index;
nFoundVertex++;
}
}
}
}
++index;
}

if (nFoundVertex>0){
Expand All @@ -89,7 +72,7 @@ PFPileUpAlgo::chargedHadronVertex( const reco::VertexCollection& vertices, const
double ztrack = pfcand.vertex().z();
bool foundVertex = false;
index = 0;
for(IV iv=vertices.begin(); iv!=vertices.end(); ++iv, ++index) {
for(auto iv=vertices.begin(); iv!=vertices.end(); ++iv, ++index) {

double dz = fabs(ztrack - iv->z());
if(dz<dzmin) {
Expand Down
36 changes: 12 additions & 24 deletions RecoEgamma/PhotonIdentification/src/PFPhotonIsolationCalculator.cc
Expand Up @@ -684,39 +684,27 @@ if(fabs(dxy) > 0.2)
//--------------------------------------------------------------------------------------------------
reco::VertexRef PFPhotonIsolationCalculator::chargedHadronVertex( edm::Handle< reco::VertexCollection > verticesColl, const reco::PFCandidate& pfcand ){

//code copied from Florian's PFNoPU class
//code copied from Florian's PFNoPU class (corrected removing the double loop....)

reco::TrackBaseRef trackBaseRef( pfcand.trackRef() );
auto const & track = pfcand.trackRef();

size_t iVertex = 0;
unsigned index=0;
unsigned nFoundVertex = 0;
unsigned int index=0;
unsigned int nFoundVertex = 0;

float bestweight=0;

const reco::VertexCollection& vertices = *(verticesColl.product());

for( reco::VertexCollection::const_iterator iv=vertices.begin(); iv!=vertices.end(); ++iv, ++index) {

const reco::Vertex& vtx = *iv;

// loop on tracks in vertices
for(reco::Vertex::trackRef_iterator iTrack=vtx.tracks_begin();iTrack!=vtx.tracks_end(); ++iTrack) {
const reco::TrackBaseRef& baseRef = *iTrack;

// one of the tracks in the vertex is the same as
// the track considered in the function
if(baseRef == trackBaseRef ) {
float w = vtx.trackWeight(baseRef);
//select the vertex for which the track has the highest weight
if (w > bestweight){
bestweight=w;
iVertex=index;
nFoundVertex++;
}
}
for( auto const & vtx : vertices) {
float w = vtx.trackWeight(track); // 0 if does not belong here
//select the vertex for which the track has the highest weight
if (w > bestweight){ // should we break here?
bestweight=w;
iVertex=index;
nFoundVertex++;
}

++index;
}


Expand Down

0 comments on commit 3c0efc4

Please sign in to comment.