Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-28 03:59:07

0001 /**
0002   \class    pat::PATCompositeCandidateProducer PATCompositeCandidateProducer.h "PhysicsTools/PatAlgos/interface/PATCompositeCandidateProducer.h"
0003   \brief    Produces the pat::CompositeCandidate
0004 
0005    The PATCompositeCandidateProducer produces the analysis-level pat::CompositeCandidate starting from
0006    any collection of Candidates
0007 
0008   \author   Salvatore Rappoccio
0009   \version  $Id: PATCompositeCandidateProducer.h,v 1.3 2009/06/25 23:49:35 gpetrucc Exp $
0010 */
0011 
0012 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0013 #include "CommonTools/Utils/interface/EtComparator.h"
0014 #include "CommonTools/Utils/interface/StringObjectFunction.h"
0015 #include "DataFormats/Common/interface/Association.h"
0016 #include "DataFormats/Common/interface/ValueMap.h"
0017 #include "DataFormats/Common/interface/View.h"
0018 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0019 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0020 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/stream/EDProducer.h"
0023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Utilities/interface/Exception.h"
0026 #include "PhysicsTools/PatAlgos/interface/EfficiencyLoader.h"
0027 #include "PhysicsTools/PatAlgos/interface/KinResolutionsLoader.h"
0028 #include "PhysicsTools/PatAlgos/interface/MultiIsolator.h"
0029 #include "PhysicsTools/PatAlgos/interface/PATUserDataHelper.h"
0030 #include "PhysicsTools/PatAlgos/interface/VertexingHelper.h"
0031 
0032 namespace pat {
0033 
0034   class PATCompositeCandidateProducer : public edm::stream::EDProducer<> {
0035   public:
0036     explicit PATCompositeCandidateProducer(const edm::ParameterSet& iConfig);
0037     ~PATCompositeCandidateProducer() override;
0038 
0039     void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0040 
0041   private:
0042     // configurables
0043     const edm::EDGetTokenT<edm::View<reco::CompositeCandidate> > srcToken_;  // list of reco::CompositeCandidates
0044 
0045     const bool useUserData_;
0046     pat::PATUserDataHelper<pat::CompositeCandidate> userDataHelper_;
0047 
0048     const bool addEfficiencies_;
0049     pat::helper::EfficiencyLoader efficiencyLoader_;
0050 
0051     const bool addResolutions_;
0052     pat::helper::KinResolutionsLoader resolutionLoader_;
0053   };
0054 
0055 }  // namespace pat
0056 
0057 using namespace pat;
0058 using namespace std;
0059 using namespace edm;
0060 
0061 PATCompositeCandidateProducer::PATCompositeCandidateProducer(const ParameterSet& iConfig)
0062     : srcToken_(consumes<edm::View<reco::CompositeCandidate> >(iConfig.getParameter<InputTag>("src"))),
0063       useUserData_(iConfig.exists("userData")),
0064       userDataHelper_(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector()),
0065       addEfficiencies_(iConfig.getParameter<bool>("addEfficiencies")),
0066       addResolutions_(iConfig.getParameter<bool>("addResolutions")) {
0067   // Efficiency configurables
0068   if (addEfficiencies_) {
0069     efficiencyLoader_ =
0070         pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
0071   }
0072 
0073   // Resolution configurables
0074   if (addResolutions_) {
0075     resolutionLoader_ =
0076         pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"), consumesCollector());
0077   }
0078 
0079   // produces vector of particles
0080   produces<vector<pat::CompositeCandidate> >();
0081 }
0082 
0083 PATCompositeCandidateProducer::~PATCompositeCandidateProducer() {}
0084 
0085 void PATCompositeCandidateProducer::produce(Event& iEvent, const EventSetup& iSetup) {
0086   // Get the vector of CompositeCandidate's from the event
0087   Handle<View<reco::CompositeCandidate> > cands;
0088   iEvent.getByToken(srcToken_, cands);
0089 
0090   if (efficiencyLoader_.enabled())
0091     efficiencyLoader_.newEvent(iEvent);
0092   if (resolutionLoader_.enabled())
0093     resolutionLoader_.newEvent(iEvent, iSetup);
0094 
0095   auto myCompositeCandidates = std::make_unique<vector<pat::CompositeCandidate> >();
0096 
0097   if (cands.isValid()) {
0098     View<reco::CompositeCandidate>::const_iterator ibegin = cands->begin(), iend = cands->end(), i = ibegin;
0099     for (; i != iend; ++i) {
0100       pat::CompositeCandidate cand(*i);
0101 
0102       if (useUserData_) {
0103         userDataHelper_.add(cand, iEvent, iSetup);
0104       }
0105 
0106       if (efficiencyLoader_.enabled())
0107         efficiencyLoader_.setEfficiencies(cand, cands->refAt(i - cands->begin()));
0108       if (resolutionLoader_.enabled())
0109         resolutionLoader_.setResolutions(cand);
0110 
0111       myCompositeCandidates->push_back(std::move(cand));
0112     }
0113 
0114   }  // end if the two handles are valid
0115 
0116   iEvent.put(std::move(myCompositeCandidates));
0117 }
0118 
0119 #include "FWCore/Framework/interface/MakerMacros.h"
0120 
0121 DEFINE_FWK_MODULE(PATCompositeCandidateProducer);