Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:05

0001 // -*- C++ -*-
0002 //
0003 // Package:    PFCand_NoPU_WithAM
0004 // Class:      PFCand_NoPU_WithAM
0005 //
0006 /**\class PF_PU_AssoMap PFCand_NoPU_WithAM.cc CommonTools/RecoUtils/plugins/PFCand_NoPU_WithAM.cc
0007 
0008  Description: Produces a collection of PFCandidates associated to the first vertex based on the association map
0009 
0010 */
0011 //
0012 // Original Author:  Matthias Geisler,32 4-B20,+41227676487,
0013 //         Created:  Thu Dec  1 16:07:41 CET 2011
0014 // $Id: PFCand_NoPU_WithAM.cc,v 1.5 2012/12/06 14:03:15 mgeisler Exp $
0015 //
0016 //
0017 #include "CommonTools/RecoUtils/interface/PFCand_NoPU_WithAM.h"
0018 
0019 // system include files
0020 #include <memory>
0021 #include <vector>
0022 
0023 // user include files
0024 
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/Run.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0030 
0031 #include "DataFormats/Common/interface/View.h"
0032 
0033 #include "DataFormats/TrackReco/interface/Track.h"
0034 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0035 #include "DataFormats/TrackReco/interface/TrackBase.h"
0036 
0037 using namespace edm;
0038 using namespace std;
0039 using namespace reco;
0040 
0041 //
0042 // constructors and destructor
0043 //
0044 PFCand_NoPU_WithAM::PFCand_NoPU_WithAM(const edm::ParameterSet& iConfig) {
0045   //now do what ever other initialization is needed
0046 
0047   input_AssociationType_ = iConfig.getParameter<InputTag>("AssociationType");
0048 
0049   token_PFCandToVertexAssMap_ =
0050       mayConsume<PFCandToVertexAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
0051   token_VertexToPFCandAssMap_ =
0052       mayConsume<VertexToPFCandAssMap>(iConfig.getParameter<InputTag>("VertexPFCandAssociationMap"));
0053 
0054   token_VertexCollection_ = mayConsume<VertexCollection>(iConfig.getParameter<InputTag>("VertexCollection"));
0055 
0056   input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
0057 
0058   //register your products
0059 
0060   if (input_AssociationType_.label() == "PFCandsToVertex") {
0061     produces<PFCandidateCollection>("P2V");
0062   } else {
0063     if (input_AssociationType_.label() == "VertexToPFCands") {
0064       produces<PFCandidateCollection>("V2P");
0065     } else {
0066       if (input_AssociationType_.label() == "Both") {
0067         produces<PFCandidateCollection>("P2V");
0068         produces<PFCandidateCollection>("V2P");
0069       } else {
0070         cout << "No correct InputTag for AssociationType!" << endl;
0071         cout << "Won't produce any PFCandiateCollection!" << endl;
0072       }
0073     }
0074   }
0075 }
0076 
0077 PFCand_NoPU_WithAM::~PFCand_NoPU_WithAM() {
0078   // do anything here that needs to be done at desctruction time
0079   // (e.g. close files, deallocate resources etc.)
0080 }
0081 
0082 //
0083 // member functions
0084 //
0085 
0086 // ------------ method called to produce the data  ------------
0087 void PFCand_NoPU_WithAM::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0088   unique_ptr<PFCandidateCollection> p2v_firstvertex(new PFCandidateCollection());
0089   unique_ptr<PFCandidateCollection> v2p_firstvertex(new PFCandidateCollection());
0090 
0091   bool p2vassmap = false;
0092   bool v2passmap = false;
0093 
0094   //get the input vertex<->pf-candidate association map
0095   Handle<PFCandToVertexAssMap> p2vAM;
0096   Handle<VertexToPFCandAssMap> v2pAM;
0097 
0098   string asstype = input_AssociationType_.label();
0099 
0100   if ((asstype == "PFCandsToVertex") || (asstype == "Both")) {
0101     if (iEvent.getByToken(token_PFCandToVertexAssMap_, p2vAM)) {
0102       p2vassmap = true;
0103     }
0104   }
0105 
0106   if ((asstype == "VertexToPFCands") || (asstype == "Both")) {
0107     if (iEvent.getByToken(token_VertexToPFCandAssMap_, v2pAM)) {
0108       v2passmap = true;
0109     }
0110   }
0111 
0112   if (!p2vassmap && !v2passmap) {
0113     cout << "No input collection could be found" << endl;
0114     return;
0115   }
0116 
0117   int negativeQuality = 0;
0118   if (input_MinQuality_ >= 2) {
0119     negativeQuality = -1;
0120   } else {
0121     if (input_MinQuality_ == 1) {
0122       negativeQuality = -2;
0123     } else {
0124       negativeQuality = -3;
0125     }
0126   }
0127 
0128   if (p2vassmap) {
0129     const PFCandQualityPairVector pfccoll = p2vAM->begin()->val;
0130 
0131     //get the candidates associated to the first vertex and store them in a pf-candidate collection
0132     for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++) {
0133       PFCandidateRef pfcand = pfccoll[pfccoll_ite].first;
0134       int quality = pfccoll[pfccoll_ite].second;
0135 
0136       if ((quality >= input_MinQuality_) || ((quality < 0) && (quality >= negativeQuality))) {
0137         p2v_firstvertex->push_back(*pfcand);
0138       }
0139     }
0140 
0141     iEvent.put(std::move(p2v_firstvertex), "P2V");
0142   }
0143 
0144   if (v2passmap) {
0145     //get the input vertex collection
0146     Handle<VertexCollection> input_vtxcollH;
0147     iEvent.getByToken(token_VertexCollection_, input_vtxcollH);
0148 
0149     VertexRef firstVertexRef(input_vtxcollH, 0);
0150 
0151     VertexToPFCandAssMap::const_iterator v2p_ite;
0152 
0153     for (v2p_ite = v2pAM->begin(); v2p_ite != v2pAM->end(); v2p_ite++) {
0154       PFCandidateRef pfcand = v2p_ite->key;
0155 
0156       for (unsigned v_ite = 0; v_ite < (v2p_ite->val).size(); v_ite++) {
0157         VertexRef vtxref = (v2p_ite->val)[v_ite].first;
0158         int quality = (v2p_ite->val)[v_ite].second;
0159 
0160         if ((vtxref == firstVertexRef) &&
0161             ((quality >= input_MinQuality_) || ((quality < 0) && (quality >= negativeQuality)))) {
0162           v2p_firstvertex->push_back(*pfcand);
0163         }
0164       }
0165     }
0166 
0167     iEvent.put(std::move(v2p_firstvertex), "V2P");
0168   }
0169 }
0170 
0171 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0172 void PFCand_NoPU_WithAM::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0173   //The following says we do not know what parameters are allowed so do no validation
0174   // Please change this to state exactly what you do use, even if it is no parameters
0175   edm::ParameterSetDescription desc;
0176   desc.setUnknown();
0177   descriptions.addDefault(desc);
0178 }
0179 
0180 //define this as a plug-in
0181 DEFINE_FWK_MODULE(PFCand_NoPU_WithAM);