Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-15 01:07:55

0001 // -*- C++ -*-
0002 //
0003 // Package:    JetPlusTracks
0004 // Class:      JetPlusTrackAddonSeedProducer
0005 //
0006 /**\class JetPlusTrackAddonSeedProducer JetPlusTrackAddonSeedProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Olga Kodolova,40 R-A12,+41227671273,
0015 //         Created:  Fri Feb 19 10:14:02 CET 2010
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/stream/EDProducer.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0030 #include "FWCore/Utilities/interface/InputTag.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032 
0033 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
0034 #include "DataFormats/JetReco/interface/CaloJet.h"
0035 #include "DataFormats/JetReco/interface/TrackJetCollection.h"
0036 #include "DataFormats/JetReco/interface/TrackJet.h"
0037 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0038 #include "DataFormats/TrackReco/interface/Track.h"
0039 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0040 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0041 
0042 #include "DataFormats/Math/interface/deltaPhi.h"
0043 #include "DataFormats/Math/interface/deltaR.h"
0044 
0045 #include <string>
0046 
0047 using namespace std;
0048 class JetPlusTrackAddonSeedProducer : public edm::stream::EDProducer<> {
0049 public:
0050   explicit JetPlusTrackAddonSeedProducer(const edm::ParameterSet&);
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052   void produce(edm::Event&, const edm::EventSetup&) override;
0053 
0054 private:
0055   const double dRcone_;
0056   const bool usePAT_;
0057   const edm::EDGetTokenT<edm::View<reco::CaloJet> > input_jets_token_;
0058   const edm::EDGetTokenT<edm::View<reco::TrackJet> > input_trackjets_token_;
0059   const edm::EDGetTokenT<reco::VertexCollection> input_vertex_token_;
0060   const edm::EDGetTokenT<std::vector<pat::PackedCandidate> > tokenPFCandidates_;
0061   const edm::EDGetTokenT<CaloTowerCollection> input_ctw_token_;
0062 };
0063 
0064 JetPlusTrackAddonSeedProducer::JetPlusTrackAddonSeedProducer(const edm::ParameterSet& iConfig)
0065     : dRcone_(iConfig.getParameter<double>("dRcone")),
0066       usePAT_(iConfig.getParameter<bool>("UsePAT")),
0067       input_jets_token_(consumes<edm::View<reco::CaloJet> >(iConfig.getParameter<edm::InputTag>("srcCaloJets"))),
0068       input_trackjets_token_(consumes<edm::View<reco::TrackJet> >(iConfig.getParameter<edm::InputTag>("srcTrackJets"))),
0069       input_vertex_token_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("srcPVs"))),
0070       tokenPFCandidates_(consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("PFCandidates"))),
0071       input_ctw_token_(consumes<CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("towerMaker"))) {
0072   //register your products
0073   produces<reco::CaloJetCollection>();
0074 }
0075 
0076 void JetPlusTrackAddonSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& iDescriptions) {
0077   edm::ParameterSetDescription desc;
0078   desc.add<double>("dRcone", 0.4);
0079   desc.add<bool>("UsePAT", false);
0080   desc.add<edm::InputTag>("srcCaloJets", edm::InputTag("ak4CaloJets"));
0081   desc.add<edm::InputTag>("srcTrackJets", edm::InputTag("ak4TrackJets"));
0082   desc.add<edm::InputTag>("srcPVs", edm::InputTag("primaryVertex"));
0083   desc.add<edm::InputTag>("PFCandidates", edm::InputTag("PFCandidates"));
0084   desc.add<edm::InputTag>("towerMaker", edm::InputTag("towerMaker"));
0085   iDescriptions.addWithDefaultLabel(desc);
0086 }
0087 
0088 // ------------ method called to produce the data  ------------
0089 void JetPlusTrackAddonSeedProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0090   using namespace edm;
0091   // get stuff from Event
0092   auto const& jets = iEvent.get(input_jets_token_);
0093   auto const& jetsTrackJets = iEvent.get(input_trackjets_token_);
0094   auto pCaloOut = std::make_unique<reco::CaloJetCollection>();
0095 
0096   for (auto const& jet : jetsTrackJets) {
0097     int iflag = 0;
0098     for (auto const& oldjet : jets) {
0099       double dr2 = deltaR2(jet, oldjet);
0100       if (dr2 < dRcone_ * dRcone_) {
0101         iflag = 1;
0102       }
0103     }  // Calojets
0104 
0105     if (iflag == 1)
0106       continue;
0107     double caloen = 0.;
0108     double hadinho = 0.;
0109     double hadinhb = 0.;
0110     double hadinhe = 0.;
0111     double hadinhf = 0.;
0112     double emineb = 0.;
0113     double eminee = 0.;
0114     double eminhf = 0.;
0115     double eefraction = 0.;
0116     double hhfraction = 0.;
0117     int ncand = 0;
0118 
0119     if (usePAT_) {
0120       auto const& pfCandidates = iEvent.get(tokenPFCandidates_);
0121       for (auto const& pf : pfCandidates) {
0122         double dr2 = deltaR2(jet, pf);
0123         if (dr2 > dRcone_ * dRcone_)
0124           continue;
0125         // jetconstit
0126         caloen = caloen + pf.energy() * pf.caloFraction();
0127         hadinho += 0.;
0128         if (std::abs(pf.eta()) <= 1.4) {
0129           hadinhb += pf.energy() * pf.caloFraction() * pf.hcalFraction();
0130           emineb += pf.energy() * pf.caloFraction() * (1. - pf.hcalFraction());
0131         } else if (std::abs(pf.eta()) < 3.) {
0132           hadinhe += pf.energy() * pf.caloFraction() * pf.hcalFraction();
0133           eminee += pf.energy() * pf.caloFraction() * (1. - pf.hcalFraction());
0134         } else {
0135           hadinhf += pf.energy() * pf.caloFraction() * pf.hcalFraction();
0136           eminhf += pf.energy() * pf.caloFraction() * (1. - pf.hcalFraction());
0137         }
0138         ncand++;
0139       }  // pfcandidates
0140     } else {
0141       auto const& cts = iEvent.get(input_ctw_token_);
0142       for (auto const& ct : cts) {
0143         double dr2 = deltaR2(jet, ct);
0144         if (dr2 > dRcone_ * dRcone_)
0145           continue;
0146         caloen = caloen + ct.energy();
0147         hadinho += ct.energyInHO();
0148         hadinhb += ct.energyInHB();
0149         hadinhe += ct.energyInHE();
0150         hadinhf += 0.5 * ct.energyInHF();
0151         emineb += ct.energy() - ct.energyInHB() - ct.energyInHO();
0152         eminee += ct.energy() - ct.energyInHE();
0153         eminhf += 0.5 * ct.energyInHF();
0154         ncand++;
0155       }
0156     }
0157     eefraction = (emineb + eminee) / caloen;
0158     hhfraction = (hadinhb + hadinhe + hadinhf + hadinho) / caloen;
0159 
0160     double trackp = jet.p();
0161     if (caloen <= 0.)
0162       caloen = 0.001;
0163     math::XYZTLorentzVector pcalo4(caloen * jet.p4() / trackp);
0164     reco::CaloJet::Specific calospe;
0165     calospe.mTowersArea = ncand;
0166     calospe.mHadEnergyInHO = hadinho;
0167     calospe.mHadEnergyInHB = hadinhb;
0168     calospe.mHadEnergyInHE = hadinhe;
0169     calospe.mHadEnergyInHF = hadinhf;
0170     calospe.mEmEnergyInEB = emineb;
0171     calospe.mEmEnergyInEE = eminee;
0172     calospe.mEmEnergyInHF = eminhf;
0173     calospe.mEnergyFractionEm = eefraction / caloen;
0174     calospe.mEnergyFractionHadronic = hhfraction / caloen;
0175 
0176     reco::CaloJet mycalo(pcalo4, jet.primaryVertex()->position(), calospe);
0177     mycalo.setJetArea(M_PI * dRcone_ * dRcone_);
0178     pCaloOut->push_back(mycalo);
0179 
0180   }  // trackjets
0181   iEvent.put(std::move(pCaloOut));
0182 }
0183 
0184 //define this as a plug-in
0185 #include "FWCore/Framework/interface/MakerMacros.h"
0186 
0187 DEFINE_FWK_MODULE(JetPlusTrackAddonSeedProducer);