Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <memory>
0002 #include <vector>
0003 
0004 #include "FWCore/Framework/interface/global/EDProducer.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/Utilities/interface/StreamID.h"
0010 #include "DataFormats/PatCandidates/interface/Jet.h"
0011 #include "DataFormats/JetReco/interface/PileupJetIdentifier.h"
0012 
0013 class PileupJetIDVarProducer : public edm::global::EDProducer<> {
0014 public:
0015   explicit PileupJetIDVarProducer(const edm::ParameterSet& iConfig)
0016       : srcJet_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("srcJet"))),
0017         srcPileupJetId_(
0018             consumes<edm::ValueMap<StoredPileupJetIdentifier>>(iConfig.getParameter<edm::InputTag>("srcPileupJetId"))) {
0019     produces<edm::ValueMap<float>>("dR2Mean");
0020     produces<edm::ValueMap<float>>("majW");
0021     produces<edm::ValueMap<float>>("minW");
0022     produces<edm::ValueMap<float>>("frac01");
0023     produces<edm::ValueMap<float>>("frac02");
0024     produces<edm::ValueMap<float>>("frac03");
0025     produces<edm::ValueMap<float>>("frac04");
0026     produces<edm::ValueMap<float>>("ptD");
0027     produces<edm::ValueMap<float>>("beta");
0028     produces<edm::ValueMap<float>>("pull");
0029     produces<edm::ValueMap<float>>("jetR");
0030     produces<edm::ValueMap<float>>("jetRchg");
0031     produces<edm::ValueMap<int>>("nCharged");
0032   }
0033   ~PileupJetIDVarProducer() override{};
0034 
0035   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0036 
0037 private:
0038   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0039 
0040   // ----------member data ---------------------------
0041   edm::EDGetTokenT<edm::View<pat::Jet>> srcJet_;
0042   edm::EDGetTokenT<edm::ValueMap<StoredPileupJetIdentifier>> srcPileupJetId_;
0043 };
0044 
0045 // ------------ method called to produce the data  ------------
0046 void PileupJetIDVarProducer::produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0047   edm::Handle<edm::View<pat::Jet>> srcJet;
0048   edm::Handle<edm::ValueMap<StoredPileupJetIdentifier>> srcPileupJetId;
0049 
0050   iEvent.getByToken(srcJet_, srcJet);
0051   iEvent.getByToken(srcPileupJetId_, srcPileupJetId);
0052 
0053   unsigned int nJet = srcJet->size();
0054 
0055   std::vector<float> dR2Mean(nJet, -1);
0056   std::vector<float> majW(nJet, -1);
0057   std::vector<float> minW(nJet, -1);
0058   std::vector<float> frac01(nJet, -1);
0059   std::vector<float> frac02(nJet, -1);
0060   std::vector<float> frac03(nJet, -1);
0061   std::vector<float> frac04(nJet, -1);
0062   std::vector<float> ptD(nJet, -1);
0063   std::vector<float> beta(nJet, -1);
0064   std::vector<float> pull(nJet, -1);
0065   std::vector<float> jetR(nJet, -1);
0066   std::vector<float> jetRchg(nJet, -1);
0067   std::vector<int> nCharged(nJet, -1);
0068 
0069   for (unsigned int ij = 0; ij < nJet; ij++) {
0070     auto jet = srcJet->ptrAt(ij);
0071 
0072     edm::RefToBase<pat::Jet> jetRef = srcJet->refAt(ij);
0073 
0074     dR2Mean[ij] = (*srcPileupJetId)[jetRef].dR2Mean();
0075     majW[ij] = (*srcPileupJetId)[jetRef].majW();
0076     minW[ij] = (*srcPileupJetId)[jetRef].minW();
0077     frac01[ij] = (*srcPileupJetId)[jetRef].frac01();
0078     frac02[ij] = (*srcPileupJetId)[jetRef].frac02();
0079     frac03[ij] = (*srcPileupJetId)[jetRef].frac03();
0080     frac04[ij] = (*srcPileupJetId)[jetRef].frac04();
0081     ptD[ij] = (*srcPileupJetId)[jetRef].ptD();
0082     beta[ij] = (*srcPileupJetId)[jetRef].beta();
0083     pull[ij] = (*srcPileupJetId)[jetRef].pull();
0084     jetR[ij] = (*srcPileupJetId)[jetRef].jetR();
0085     jetRchg[ij] = (*srcPileupJetId)[jetRef].jetRchg();
0086     nCharged[ij] = (*srcPileupJetId)[jetRef].nCharged();
0087   }
0088 
0089   std::unique_ptr<edm::ValueMap<float>> dR2MeanV(new edm::ValueMap<float>());
0090   edm::ValueMap<float>::Filler filler_dR2Mean(*dR2MeanV);
0091   filler_dR2Mean.insert(srcJet, dR2Mean.begin(), dR2Mean.end());
0092   filler_dR2Mean.fill();
0093   iEvent.put(std::move(dR2MeanV), "dR2Mean");
0094 
0095   std::unique_ptr<edm::ValueMap<float>> majWV(new edm::ValueMap<float>());
0096   edm::ValueMap<float>::Filler filler_majW(*majWV);
0097   filler_majW.insert(srcJet, majW.begin(), majW.end());
0098   filler_majW.fill();
0099   iEvent.put(std::move(majWV), "majW");
0100 
0101   std::unique_ptr<edm::ValueMap<float>> minWV(new edm::ValueMap<float>());
0102   edm::ValueMap<float>::Filler filler_minW(*minWV);
0103   filler_minW.insert(srcJet, minW.begin(), minW.end());
0104   filler_minW.fill();
0105   iEvent.put(std::move(minWV), "minW");
0106 
0107   std::unique_ptr<edm::ValueMap<float>> frac01V(new edm::ValueMap<float>());
0108   edm::ValueMap<float>::Filler filler_frac01(*frac01V);
0109   filler_frac01.insert(srcJet, frac01.begin(), frac01.end());
0110   filler_frac01.fill();
0111   iEvent.put(std::move(frac01V), "frac01");
0112 
0113   std::unique_ptr<edm::ValueMap<float>> frac02V(new edm::ValueMap<float>());
0114   edm::ValueMap<float>::Filler filler_frac02(*frac02V);
0115   filler_frac02.insert(srcJet, frac02.begin(), frac02.end());
0116   filler_frac02.fill();
0117   iEvent.put(std::move(frac02V), "frac02");
0118 
0119   std::unique_ptr<edm::ValueMap<float>> frac03V(new edm::ValueMap<float>());
0120   edm::ValueMap<float>::Filler filler_frac03(*frac03V);
0121   filler_frac03.insert(srcJet, frac03.begin(), frac03.end());
0122   filler_frac03.fill();
0123   iEvent.put(std::move(frac03V), "frac03");
0124 
0125   std::unique_ptr<edm::ValueMap<float>> frac04V(new edm::ValueMap<float>());
0126   edm::ValueMap<float>::Filler filler_frac04(*frac04V);
0127   filler_frac04.insert(srcJet, frac04.begin(), frac04.end());
0128   filler_frac04.fill();
0129   iEvent.put(std::move(frac04V), "frac04");
0130 
0131   std::unique_ptr<edm::ValueMap<float>> ptDV(new edm::ValueMap<float>());
0132   edm::ValueMap<float>::Filler filler_ptD(*ptDV);
0133   filler_ptD.insert(srcJet, ptD.begin(), ptD.end());
0134   filler_ptD.fill();
0135   iEvent.put(std::move(ptDV), "ptD");
0136 
0137   std::unique_ptr<edm::ValueMap<float>> betaV(new edm::ValueMap<float>());
0138   edm::ValueMap<float>::Filler filler_beta(*betaV);
0139   filler_beta.insert(srcJet, beta.begin(), beta.end());
0140   filler_beta.fill();
0141   iEvent.put(std::move(betaV), "beta");
0142 
0143   std::unique_ptr<edm::ValueMap<float>> pullV(new edm::ValueMap<float>());
0144   edm::ValueMap<float>::Filler filler_pull(*pullV);
0145   filler_pull.insert(srcJet, pull.begin(), pull.end());
0146   filler_pull.fill();
0147   iEvent.put(std::move(pullV), "pull");
0148 
0149   std::unique_ptr<edm::ValueMap<float>> jetRV(new edm::ValueMap<float>());
0150   edm::ValueMap<float>::Filler filler_jetR(*jetRV);
0151   filler_jetR.insert(srcJet, jetR.begin(), jetR.end());
0152   filler_jetR.fill();
0153   iEvent.put(std::move(jetRV), "jetR");
0154 
0155   std::unique_ptr<edm::ValueMap<float>> jetRchgV(new edm::ValueMap<float>());
0156   edm::ValueMap<float>::Filler filler_jetRchg(*jetRchgV);
0157   filler_jetRchg.insert(srcJet, jetRchg.begin(), jetRchg.end());
0158   filler_jetRchg.fill();
0159   iEvent.put(std::move(jetRchgV), "jetRchg");
0160 
0161   std::unique_ptr<edm::ValueMap<int>> nChargedV(new edm::ValueMap<int>());
0162   edm::ValueMap<int>::Filler filler_nCharged(*nChargedV);
0163   filler_nCharged.insert(srcJet, nCharged.begin(), nCharged.end());
0164   filler_nCharged.fill();
0165   iEvent.put(std::move(nChargedV), "nCharged");
0166 }
0167 
0168 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0169 void PileupJetIDVarProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0170   //The following says we do not know what parameters are allowed so do no validation
0171   // Please change this to state exactly what you do use, even if it is no parameters
0172   edm::ParameterSetDescription desc;
0173   desc.add<edm::InputTag>("srcJet")->setComment("jet input collection");
0174   desc.add<edm::InputTag>("srcPileupJetId")->setComment("StoredPileupJetIdentifier name");
0175   std::string modname;
0176   modname += "PileupJetIDVarProducer";
0177   descriptions.add(modname, desc);
0178 }
0179 
0180 //define this as a plug-in
0181 DEFINE_FWK_MODULE(PileupJetIDVarProducer);