CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CommonTools/RecoUtils/plugins/PFCand_NoPU_WithAM.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    PFCand_NoPU_WithAM
00004 // Class:      PFCand_NoPU_WithAM
00005 // 
00011 //
00012 // Original Author:  Matthias Geisler,32 4-B20,+41227676487,
00013 //         Created:  Thu Dec  1 16:07:41 CET 2011
00014 // $Id: PFCand_NoPU_WithAM.cc,v 1.6 2012/12/20 13:14:12 mgeisler Exp $
00015 //
00016 //
00017 #include "CommonTools/RecoUtils/interface/PFCand_NoPU_WithAM.h"
00018 
00019 // system include files
00020 #include <memory>
00021 #include <vector>
00022 
00023 // user include files
00024 
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/Framework/interface/Run.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028 
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 
00031 #include "DataFormats/Common/interface/View.h"
00032 
00033 #include "DataFormats/TrackReco/interface/Track.h"
00034 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00035 #include "DataFormats/TrackReco/interface/TrackBase.h"
00036    
00037 using namespace edm;
00038 using namespace std;
00039 using namespace reco;
00040 
00041 //
00042 // constructors and destructor
00043 //
00044 PFCand_NoPU_WithAM::PFCand_NoPU_WithAM(const edm::ParameterSet& iConfig)
00045 {
00046    //now do what ever other initialization is needed
00047 
00048         input_AssociationType_ = iConfig.getParameter<InputTag>("AssociationType");
00049 
00050         input_VertexPFCandAssociationMap_ = iConfig.getParameter<InputTag>("VertexPFCandAssociationMap");
00051 
00052         input_VertexCollection_ = iConfig.getParameter<InputTag>("VertexCollection");
00053 
00054         input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
00055 
00056    //register your products
00057 
00058         if ( input_AssociationType_.label() == "PFCandsToVertex" ) {
00059           produces<PFCandidateCollection>("P2V");
00060         } else {
00061           if ( input_AssociationType_.label() == "VertexToPFCands" ) {
00062             produces<PFCandidateCollection>("V2P");
00063           } else {
00064             if ( input_AssociationType_.label() == "Both" ) {
00065               produces<PFCandidateCollection>("P2V");
00066               produces<PFCandidateCollection>("V2P");
00067             } else {
00068               cout << "No correct InputTag for AssociationType!" << endl;
00069               cout << "Won't produce any PFCandiateCollection!" << endl;
00070             }
00071           }
00072         }
00073   
00074 }
00075 
00076 
00077 PFCand_NoPU_WithAM::~PFCand_NoPU_WithAM()
00078 {
00079  
00080    // do anything here that needs to be done at desctruction time
00081    // (e.g. close files, deallocate resources etc.)
00082 
00083 }
00084 
00085 //
00086 // member functions
00087 //
00088 
00089 // ------------ method called to produce the data  ------------
00090 void
00091 PFCand_NoPU_WithAM::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00092 {
00093 
00094         auto_ptr<PFCandidateCollection> p2v_firstvertex(new PFCandidateCollection() );
00095         auto_ptr<PFCandidateCollection> v2p_firstvertex(new PFCandidateCollection() );
00096 
00097         bool p2vassmap = false;
00098         bool v2passmap = false;
00099   
00100         //get the input vertex<->pf-candidate association map
00101         Handle<PFCandToVertexAssMap> p2vAM;
00102         Handle<VertexToPFCandAssMap> v2pAM;
00103         
00104         string asstype = input_AssociationType_.label();
00105 
00106         if ( ( asstype == "PFCandsToVertex" ) || ( asstype == "Both" ) ) {
00107           if ( iEvent.getByLabel(input_VertexPFCandAssociationMap_, p2vAM ) ) {
00108             p2vassmap = true;
00109           }
00110         }
00111 
00112         if ( ( asstype == "VertexToPFCands" ) || ( asstype == "Both" ) ) {
00113           if ( iEvent.getByLabel(input_VertexPFCandAssociationMap_, v2pAM ) ) {
00114             v2passmap = true;
00115           }
00116         }
00117 
00118         if ( !p2vassmap && !v2passmap ) {
00119           cout << "No input collection could be found" << endl;
00120           return;
00121         }
00122 
00123         int negativeQuality = 0;
00124         if ( input_MinQuality_ >= 2) {
00125           negativeQuality = -1;
00126         } else {
00127           if ( input_MinQuality_ == 1) {
00128             negativeQuality = -2;
00129           } else{
00130             negativeQuality = -3;
00131           } 
00132         } 
00133 
00134         if ( p2vassmap ){
00135 
00136           const PFCandQualityPairVector pfccoll = p2vAM->begin()->val;
00137 
00138           //get the candidates associated to the first vertex and store them in a pf-candidate collection
00139           for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++){
00140      
00141             PFCandidateRef pfcand = pfccoll[pfccoll_ite].first;
00142             int quality = pfccoll[pfccoll_ite].second;
00143 
00144             if ( (quality>=input_MinQuality_) || ( (quality<0) && (quality>=negativeQuality) ) ) { 
00145               p2v_firstvertex->push_back(*pfcand);
00146 
00147             }
00148 
00149           }
00150 
00151           iEvent.put( p2v_firstvertex, "P2V" );
00152 
00153         } 
00154 
00155         if ( v2passmap ) {
00156  
00157           //get the input vertex collection
00158           Handle<VertexCollection> input_vtxcollH;
00159           iEvent.getByLabel(input_VertexCollection_,input_vtxcollH);
00160 
00161           VertexRef firstVertexRef(input_vtxcollH,0);
00162 
00163           VertexToPFCandAssMap::const_iterator v2p_ite;
00164 
00165           for(v2p_ite=v2pAM->begin(); v2p_ite!=v2pAM->end(); v2p_ite++){
00166 
00167             PFCandidateRef pfcand = v2p_ite->key;
00168     
00169             for(unsigned v_ite = 0; v_ite<(v2p_ite->val).size(); v_ite++){
00170 
00171               VertexRef vtxref = (v2p_ite->val)[v_ite].first;
00172               int quality = (v2p_ite->val)[v_ite].second;
00173 
00174               if ( (vtxref==firstVertexRef) && ( (quality>=input_MinQuality_) || ( (quality<0) && (quality>=negativeQuality) ) ) ) {
00175                  v2p_firstvertex->push_back(*pfcand);
00176               }
00177 
00178             }
00179 
00180           }
00181 
00182           iEvent.put( v2p_firstvertex, "V2P" );
00183 
00184         }
00185 }
00186 
00187 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00188 void
00189 PFCand_NoPU_WithAM::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00190   //The following says we do not know what parameters are allowed so do no validation
00191   // Please change this to state exactly what you do use, even if it is no parameters
00192   edm::ParameterSetDescription desc;
00193   desc.setUnknown();
00194   descriptions.addDefault(desc);
00195 }
00196 
00197 //define this as a plug-in
00198 DEFINE_FWK_MODULE(PFCand_NoPU_WithAM);