CMS 3D CMS Logo

Static Public Member Functions

PFCand_NoPU_WithAM_Algos Class Reference

#include <PFCand_NoPU_WithAM_Algos.h>

List of all members.

Static Public Member Functions

static std::auto_ptr
< PFCandVertexAssMap
SortAssociationMap (PFCandVertexAssMap *)

Detailed Description

Definition at line 39 of file PFCand_NoPU_WithAM_Algos.h.


Member Function Documentation

auto_ptr< PFCandVertexAssMap > PFCand_NoPU_WithAM_Algos::SortAssociationMap ( PFCandVertexAssMap pfcvertexassInput) [static]

Definition at line 71 of file PFCand_NoPU_WithAM_Algos.cc.

References edm::AssociationMap< Tag >::begin(), edm::AssociationMap< Tag >::end(), edm::Ref< C, T, F >::key(), and edm::second().

Referenced by PFCand_AssoMap::produce().

{
        //create a new PFCandVertexAssMap for the Output which will be sorted
        auto_ptr<PFCandVertexAssMap> pfcvertexassOutput(new PFCandVertexAssMap() );

        //Create and fill a vector of pairs of vertex and the summed (pT)**2 of the pfcandidates associated to the vertex 
        VertexPtsumVector vertexptsumvector;

        //loop over all vertices in the association map
        for(PFCandVertexAssMap::const_iterator assomap_ite=pfcvertexassInput->begin(); assomap_ite!=pfcvertexassInput->end(); assomap_ite++){

          const VertexRef assomap_vertexref = assomap_ite->key;
          const PFCandQualityPairVector pfccoll = assomap_ite->val;

          float ptsum = 0;
 
          PFCandidateRef pfcandref;

          //get the pfcandidates associated to the vertex and calculate the pT**2
          for(unsigned int pfccoll_ite=0; pfccoll_ite<pfccoll.size(); pfccoll_ite++){

            pfcandref = pfccoll[pfccoll_ite].first;
            double man_pT = pfcandref->pt();
            if(man_pT>0.) ptsum+=man_pT*man_pT;

          }

          vertexptsumvector.push_back(make_pair(assomap_vertexref,ptsum));

        }

        while (vertexptsumvector.size()!=0){

          VertexRef vertexref_highestpT;
          float highestpT = 0.;
          int highestpT_index = 0;

          for(unsigned int vtxptsumvec_ite=0; vtxptsumvec_ite<vertexptsumvector.size(); vtxptsumvec_ite++){
 
            if(vertexptsumvector[vtxptsumvec_ite].second>highestpT){

              vertexref_highestpT = vertexptsumvector[vtxptsumvec_ite].first;
              highestpT = vertexptsumvector[vtxptsumvec_ite].second;
              highestpT_index = vtxptsumvec_ite;
        
            }

          }
          
          //loop over all vertices in the association map
          for(PFCandVertexAssMap::const_iterator assomap_ite=pfcvertexassInput->begin(); assomap_ite!=pfcvertexassInput->end(); assomap_ite++){

            const VertexRef assomap_vertexref = assomap_ite->key;
            const PFCandQualityPairVector pfccoll = assomap_ite->val;

            //if the vertex from the association map the vertex with the highest pT 
            //insert all associated pfcandidates in the output Association Map
            if(assomap_vertexref==vertexref_highestpT) 
              for(unsigned int pfccoll_ite=0; pfccoll_ite<pfccoll.size(); pfccoll_ite++) 
                pfcvertexassOutput->insert(assomap_vertexref,pfccoll[pfccoll_ite]);
 
          }

          vertexptsumvector.erase(vertexptsumvector.begin()+highestpT_index);   

        }

        return pfcvertexassOutput;

}