CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/CommonTools/RecoUtils/plugins/PFCand_AssoMap.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    PFCand_AssoMap
00004 // Class:      PFCand_AssoMap
00005 // 
00010 //
00011 // Original Author:  Matthias Geisler
00012 //         Created:  Wed Apr 18 14:48:37 CEST 2012
00013 // $Id: PFCand_AssoMap.cc,v 1.4 2012/08/28 14:16:51 mgeisler Exp $
00014 //
00015 //
00016 #include "CommonTools/RecoUtils/interface/PFCand_AssoMap.h"
00017 
00018 // system include files
00019 #include <memory>
00020 #include <vector>
00021 #include <string>
00022 
00023 // user include files
00024 #include "FWCore/Framework/interface/Frameworkfwd.h"
00025 #include "FWCore/Framework/interface/EDProducer.h"
00026 
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/Run.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032 #include "FWCore/Utilities/interface/InputTag.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "DataFormats/Common/interface/AssociationMap.h"
00036 #include "DataFormats/Common/interface/Handle.h"
00037 #include "DataFormats/Common/interface/OneToManyWithQuality.h"
00038 #include "DataFormats/Common/interface/OneToManyWithQualityGeneric.h"
00039 #include "DataFormats/Common/interface/View.h"
00040 
00041 #include "DataFormats/TrackReco/interface/Track.h"
00042 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00043 #include "DataFormats/TrackReco/interface/TrackBase.h"
00044 #include "DataFormats/VertexReco/interface/Vertex.h"
00045 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00046 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00047 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00048 
00049 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00050 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00051 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
00052 #include "DataFormats/EgammaCandidates/interface/ConversionFwd.h"
00053 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00054 #include <DataFormats/EgammaReco/interface/SuperCluster.h>
00055 #include <DataFormats/EgammaReco/interface/SuperClusterFwd.h>
00056 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00057 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00058 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00059 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00060 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00061 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertex.h"
00062 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertexFwd.h"
00063 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
00064 #include "DataFormats/Candidate/interface/VertexCompositeCandidateFwd.h"
00065 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00066 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00067 
00068 #include "RecoEgamma/EgammaTools/interface/ConversionTools.h"
00069 
00070 //
00071 // constants, enums and typedefs
00072 //
00073    
00074 using namespace edm;
00075 using namespace std;
00076 using namespace reco;
00077 
00078 typedef AssociationMap<OneToManyWithQuality< VertexCollection, PFCandidateCollection, float> > PFCandVertexAssMap;
00079 
00080 typedef pair<PFCandidateRef, float> PFCandQualityPair;
00081 typedef vector< PFCandQualityPair > PFCandQualityPairVector;
00082 
00083 typedef pair<VertexRef, PFCandQualityPair> VertexPfcQuality;
00084 
00085 
00086 typedef pair<TrackRef, float> TrackQualityPair;
00087 
00088 typedef pair<VertexRef, TrackQualityPair> VertexTrackQuality;
00089 
00090 
00091 //
00092 // static data member definitions
00093 //
00094 
00095 //
00096 // constructors and destructor
00097 //
00098 PFCand_AssoMap::PFCand_AssoMap(const edm::ParameterSet& iConfig):PF_PU_AssoMapAlgos(iConfig)
00099 {
00100    //register your products
00101 
00102         produces<PFCandVertexAssMap>();
00103 
00104    //now do what ever other initialization is needed
00105 
00106         input_PFCandidates_ = iConfig.getParameter<InputTag>("PFCandidateCollection");
00107 
00108   
00109 }
00110 
00111 
00112 PFCand_AssoMap::~PFCand_AssoMap()
00113 {
00114 }
00115 
00116 
00117 //
00118 // member functions
00119 //
00120 
00121 // ------------ method called to produce the data  ------------
00122 void
00123 PFCand_AssoMap::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00124 {
00125 
00126         //std::cout << "<PFCand_AssoMap::produce>:" << std::endl;
00127 
00128         auto_ptr<PFCandVertexAssMap> pfCandAM(new PFCandVertexAssMap() );
00129   
00130         //get the input pfCandidateCollection
00131         Handle<PFCandidateCollection> pfCandInH;
00132         iEvent.getByLabel(input_PFCandidates_,pfCandInH);
00133 
00134         if ( !PF_PU_AssoMapAlgos::GetInputCollections(iEvent,iSetup) ) return;
00135 
00136         VertexRef FirstVtxRef = PF_PU_AssoMapAlgos::GetFirstVertex();
00137    
00138         for( unsigned i=0; i<pfCandInH->size(); i++ ) {
00139      
00140           PFCandidateRef candref(pfCandInH, i);
00141 
00142           float weight;
00143 
00144           VertexPfcQuality VtxPfcQual;
00145 
00146           TrackRef PFCtrackref = candref->trackRef();
00147 
00148           if ( PFCtrackref.isNull() ){
00149      
00150             //the pfcand has no reference to a general track, therefore its mostly uncharged
00151             //it will allways be associated to the first vertex,
00152             //this was found out to be the best solution w.r.t. jet-pt response
00153             //weight set to -3.
00154 
00155             weight = -3.;              
00156             VtxPfcQual = make_pair(FirstVtxRef, make_pair(candref, weight));         
00157 
00158           } else {
00159 
00160             VertexTrackQuality VtxTrkQual = PF_PU_AssoMapAlgos::DoTrackAssociation(PFCtrackref, iSetup);
00161             VtxPfcQual = make_pair(VtxTrkQual.first, make_pair(candref, VtxTrkQual.second.second)); 
00162 
00163           }
00164 
00165           //std::cout << "associating candidate: Pt = " << VtxPfcQual.second.first->pt() << "," 
00166           //            << " eta = " << VtxPfcQual.second.first->eta() << ", phi = " << VtxPfcQual.second.first->phi() 
00167           //            << " to vertex: z = " << VtxPfcQual.first->position().z() << " with quality q = " << VtxPfcQual.second.second << std::endl;
00168     
00169           // Insert the best vertex and the pair of candidate and the quality of this association in the map
00170           pfCandAM->insert(VtxPfcQual.first, VtxPfcQual.second);
00171 
00172         }
00173 
00174         iEvent.put( PFCand_NoPU_WithAM_Algos::SortAssociationMap( &(*pfCandAM) ) );
00175 
00176 }
00177 
00178 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00179 void
00180 PFCand_AssoMap::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00181   //The following says we do not know what parameters are allowed so do no validation
00182   // Please change this to state exactly what you do use, even if it is no parameters
00183   edm::ParameterSetDescription desc;
00184   desc.setUnknown();
00185   descriptions.addDefault(desc);
00186 }
00187 
00188 //define this as a plug-in
00189 DEFINE_FWK_MODULE(PFCand_AssoMap);