Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:57

0001 /*
0002  * PATPuppiJetSpecificProducer
0003  *
0004  * Author: Andreas Hinzmann
0005  *
0006  * Compute weighted constituent multiplicites for PUPPI PAT jets
0007  *
0008  */
0009 
0010 #include "FWCore/Framework/interface/global/EDProducer.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 
0017 #include "FWCore/Utilities/interface/Exception.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 
0020 #include "DataFormats/PatCandidates/interface/Jet.h"
0021 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0022 #include "DataFormats/Common/interface/ValueMap.h"
0023 
0024 class PATPuppiJetSpecificProducer : public edm::global::EDProducer<> {
0025 public:
0026   explicit PATPuppiJetSpecificProducer(const edm::ParameterSet& cfg);
0027   ~PATPuppiJetSpecificProducer() override {}
0028   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0029   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0030 
0031 private:
0032   // input collection
0033   edm::InputTag srcjets_;
0034   edm::EDGetTokenT<edm::View<pat::Jet> > jets_token;
0035 };
0036 
0037 PATPuppiJetSpecificProducer::PATPuppiJetSpecificProducer(const edm::ParameterSet& cfg) {
0038   srcjets_ = cfg.getParameter<edm::InputTag>("src");
0039   jets_token = consumes<edm::View<pat::Jet> >(srcjets_);
0040 
0041   produces<edm::ValueMap<float> >("puppiMultiplicity");
0042   produces<edm::ValueMap<float> >("neutralPuppiMultiplicity");
0043   produces<edm::ValueMap<float> >("neutralHadronPuppiMultiplicity");
0044   produces<edm::ValueMap<float> >("photonPuppiMultiplicity");
0045   produces<edm::ValueMap<float> >("HFHadronPuppiMultiplicity");
0046   produces<edm::ValueMap<float> >("HFEMPuppiMultiplicity");
0047 }
0048 
0049 void PATPuppiJetSpecificProducer::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup& es) const {
0050   edm::Handle<edm::View<pat::Jet> > jets;
0051   evt.getByToken(jets_token, jets);
0052 
0053   std::vector<float> puppiMultiplicities;
0054   std::vector<float> neutralPuppiMultiplicities;
0055   std::vector<float> neutralHadronPuppiMultiplicities;
0056   std::vector<float> photonPuppiMultiplicities;
0057   std::vector<float> HFHadronPuppiMultiplicities;
0058   std::vector<float> HFEMPuppiMultiplicities;
0059 
0060   for (auto const& c : *jets) {
0061     float puppiMultiplicity = 0;
0062     float neutralPuppiMultiplicity = 0;
0063     float neutralHadronPuppiMultiplicity = 0;
0064     float photonPuppiMultiplicity = 0;
0065     float HFHadronPuppiMultiplicity = 0;
0066     float HFEMPuppiMultiplicity = 0;
0067 
0068     for (unsigned i = 0; i < c.numberOfDaughters(); i++) {
0069       const pat::PackedCandidate& dau = static_cast<const pat::PackedCandidate&>(*c.daughter(i));
0070       auto weight = dau.puppiWeight();
0071       puppiMultiplicity += weight;
0072       // This logic is taken from RecoJets/JetProducers/src/JetSpecific.cc
0073       switch (std::abs(dau.pdgId())) {
0074         case 130:  //PFCandidate::h0 :    // neutral hadron
0075           neutralHadronPuppiMultiplicity += weight;
0076           neutralPuppiMultiplicity += weight;
0077           break;
0078         case 22:  //PFCandidate::gamma:   // photon
0079           photonPuppiMultiplicity += weight;
0080           neutralPuppiMultiplicity += weight;
0081           break;
0082         case 1:  // PFCandidate::h_HF :    // hadron in HF
0083           HFHadronPuppiMultiplicity += weight;
0084           neutralPuppiMultiplicity += weight;
0085           break;
0086         case 2:  //PFCandidate::egamma_HF :    // electromagnetic in HF
0087           HFEMPuppiMultiplicity += weight;
0088           neutralPuppiMultiplicity += weight;
0089           break;
0090       }
0091     }
0092 
0093     puppiMultiplicities.push_back(puppiMultiplicity);
0094     neutralPuppiMultiplicities.push_back(neutralPuppiMultiplicity);
0095     neutralHadronPuppiMultiplicities.push_back(neutralHadronPuppiMultiplicity);
0096     photonPuppiMultiplicities.push_back(photonPuppiMultiplicity);
0097     HFHadronPuppiMultiplicities.push_back(HFHadronPuppiMultiplicity);
0098     HFEMPuppiMultiplicities.push_back(HFEMPuppiMultiplicity);
0099   }
0100 
0101   std::unique_ptr<edm::ValueMap<float> > puppiMultiplicities_out(new edm::ValueMap<float>());
0102   edm::ValueMap<float>::Filler puppiMultiplicities_filler(*puppiMultiplicities_out);
0103   puppiMultiplicities_filler.insert(jets, puppiMultiplicities.begin(), puppiMultiplicities.end());
0104   puppiMultiplicities_filler.fill();
0105   evt.put(std::move(puppiMultiplicities_out), "puppiMultiplicity");
0106 
0107   std::unique_ptr<edm::ValueMap<float> > neutralPuppiMultiplicities_out(new edm::ValueMap<float>());
0108   edm::ValueMap<float>::Filler neutralPuppiMultiplicities_filler(*neutralPuppiMultiplicities_out);
0109   neutralPuppiMultiplicities_filler.insert(jets, neutralPuppiMultiplicities.begin(), neutralPuppiMultiplicities.end());
0110   neutralPuppiMultiplicities_filler.fill();
0111   evt.put(std::move(neutralPuppiMultiplicities_out), "neutralPuppiMultiplicity");
0112 
0113   std::unique_ptr<edm::ValueMap<float> > neutralHadronPuppiMultiplicities_out(new edm::ValueMap<float>());
0114   edm::ValueMap<float>::Filler neutralHadronPuppiMultiplicities_filler(*neutralHadronPuppiMultiplicities_out);
0115   neutralHadronPuppiMultiplicities_filler.insert(
0116       jets, neutralHadronPuppiMultiplicities.begin(), neutralHadronPuppiMultiplicities.end());
0117   neutralHadronPuppiMultiplicities_filler.fill();
0118   evt.put(std::move(neutralHadronPuppiMultiplicities_out), "neutralHadronPuppiMultiplicity");
0119 
0120   std::unique_ptr<edm::ValueMap<float> > photonPuppiMultiplicities_out(new edm::ValueMap<float>());
0121   edm::ValueMap<float>::Filler photonPuppiMultiplicities_filler(*photonPuppiMultiplicities_out);
0122   photonPuppiMultiplicities_filler.insert(jets, photonPuppiMultiplicities.begin(), photonPuppiMultiplicities.end());
0123   photonPuppiMultiplicities_filler.fill();
0124   evt.put(std::move(photonPuppiMultiplicities_out), "photonPuppiMultiplicity");
0125 
0126   std::unique_ptr<edm::ValueMap<float> > HFHadronPuppiMultiplicities_out(new edm::ValueMap<float>());
0127   edm::ValueMap<float>::Filler HFHadronPuppiMultiplicities_filler(*HFHadronPuppiMultiplicities_out);
0128   HFHadronPuppiMultiplicities_filler.insert(
0129       jets, HFHadronPuppiMultiplicities.begin(), HFHadronPuppiMultiplicities.end());
0130   HFHadronPuppiMultiplicities_filler.fill();
0131   evt.put(std::move(HFHadronPuppiMultiplicities_out), "HFHadronPuppiMultiplicity");
0132 
0133   std::unique_ptr<edm::ValueMap<float> > HFEMPuppiMultiplicities_out(new edm::ValueMap<float>());
0134   edm::ValueMap<float>::Filler HFEMPuppiMultiplicities_filler(*HFEMPuppiMultiplicities_out);
0135   HFEMPuppiMultiplicities_filler.insert(jets, HFEMPuppiMultiplicities.begin(), HFEMPuppiMultiplicities.end());
0136   HFEMPuppiMultiplicities_filler.fill();
0137   evt.put(std::move(HFEMPuppiMultiplicities_out), "HFEMPuppiMultiplicity");
0138 }
0139 
0140 void PATPuppiJetSpecificProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0141   edm::ParameterSetDescription desc;
0142   desc.add<edm::InputTag>("src", edm::InputTag("slimmedJets"));
0143   descriptions.add("patPuppiJetSpecificProducer", desc);
0144 }
0145 
0146 #include "FWCore/Framework/interface/MakerMacros.h"
0147 
0148 DEFINE_FWK_MODULE(PATPuppiJetSpecificProducer);