Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-04 02:55:05

0001 // system include files
0002 #include <memory>
0003 #include <string>
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/global/EDProducer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 
0014 #include "DataFormats/DetId/interface/DetId.h"
0015 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0016 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0017 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0018 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
0019 #include "DataFormats/HcalRecHit/interface/HFRecHit.h"
0020 #include "DataFormats/HcalRecHit/interface/HORecHit.h"
0021 #include "DataFormats/Common/interface/ValueMap.h"
0022 #include "DataFormats/Common/interface/TriggerResults.h"
0023 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0024 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0025 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0026 #include "DataFormats/METReco/interface/PFMET.h"
0027 #include "DataFormats/METReco/interface/PFMETCollection.h"
0028 #include "DataFormats/VertexReco/interface/Vertex.h"
0029 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0030 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0031 
0032 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0033 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0034 #include <iostream>
0035 
0036 //
0037 // class declaration
0038 //
0039 
0040 class AlCaGammaJetProducer : public edm::global::EDProducer<> {
0041 public:
0042   explicit AlCaGammaJetProducer(const edm::ParameterSet&);
0043   ~AlCaGammaJetProducer() override = default;
0044   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0046 
0047 private:
0048   bool select(const reco::PhotonCollection&, const reco::PFJetCollection&) const;
0049 
0050   // ----------member data ---------------------------
0051 
0052   edm::InputTag labelPhoton_, labelPFJet_, labelHBHE_, labelHF_, labelHO_, labelTrigger_, labelPFCandidate_,
0053       labelVertex_, labelPFMET_, labelGsfEle_, labelRho_, labelConv_, labelBeamSpot_, labelLoosePhot_, labelTightPhot_;
0054   double minPtJet_, minPtPhoton_;
0055 
0056   edm::EDGetTokenT<reco::PhotonCollection> tok_Photon_;
0057   edm::EDGetTokenT<reco::PFJetCollection> tok_PFJet_;
0058   edm::EDGetTokenT<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>> tok_HBHE_;
0059   edm::EDGetTokenT<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>> tok_HF_;
0060   edm::EDGetTokenT<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>> tok_HO_;
0061   edm::EDGetTokenT<edm::TriggerResults> tok_TrigRes_;
0062   edm::EDGetTokenT<reco::PFCandidateCollection> tok_PFCand_;
0063   edm::EDGetTokenT<reco::VertexCollection> tok_Vertex_;
0064   edm::EDGetTokenT<reco::PFMETCollection> tok_PFMET_;
0065   edm::EDGetTokenT<reco::GsfElectronCollection> tok_GsfElec_;
0066   edm::EDGetTokenT<double> tok_Rho_;
0067   edm::EDGetTokenT<reco::ConversionCollection> tok_Conv_;
0068   edm::EDGetTokenT<reco::BeamSpot> tok_BS_;
0069   edm::EDGetTokenT<edm::ValueMap<Bool_t>> tok_loosePhoton_;
0070   edm::EDGetTokenT<edm::ValueMap<Bool_t>> tok_tightPhoton_;
0071 
0072   edm::EDPutTokenT<reco::PhotonCollection> put_photon_;
0073   edm::EDPutTokenT<reco::PFJetCollection> put_pfJet_;
0074   edm::EDPutTokenT<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>> put_hbhe_;
0075   edm::EDPutTokenT<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>> put_hf_;
0076   edm::EDPutTokenT<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>> put_ho_;
0077   edm::EDPutTokenT<edm::TriggerResults> put_trigger_;
0078   edm::EDPutTokenT<std::vector<Bool_t>> put_loosePhot_;
0079   edm::EDPutTokenT<std::vector<Bool_t>> put_tightPhot_;
0080   edm::EDPutTokenT<double> put_rho_;
0081   edm::EDPutTokenT<reco::PFCandidateCollection> put_pfCandidate_;
0082   edm::EDPutTokenT<reco::VertexCollection> put_vertex_;
0083   edm::EDPutTokenT<reco::PFMETCollection> put_pfMET_;
0084   edm::EDPutTokenT<reco::GsfElectronCollection> put_gsfEle_;
0085   edm::EDPutTokenT<reco::ConversionCollection> put_conv_;
0086   edm::EDPutTokenT<reco::BeamSpot> put_beamSpot_;
0087 };
0088 
0089 AlCaGammaJetProducer::AlCaGammaJetProducer(const edm::ParameterSet& iConfig) {
0090   // Take input
0091   labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
0092   labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
0093   labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHEInput");
0094   labelHF_ = iConfig.getParameter<edm::InputTag>("HFInput");
0095   labelHO_ = iConfig.getParameter<edm::InputTag>("HOInput");
0096   labelTrigger_ = iConfig.getParameter<edm::InputTag>("TriggerResults");
0097   labelPFCandidate_ = iConfig.getParameter<edm::InputTag>("particleFlowInput");
0098   labelVertex_ = iConfig.getParameter<edm::InputTag>("VertexInput");
0099   labelPFMET_ = iConfig.getParameter<edm::InputTag>("METInput");
0100   labelGsfEle_ = iConfig.getParameter<edm::InputTag>("gsfeleInput");
0101   labelRho_ = iConfig.getParameter<edm::InputTag>("rhoInput");
0102   labelConv_ = iConfig.getParameter<edm::InputTag>("ConversionsInput");
0103   labelBeamSpot_ = iConfig.getParameter<edm::InputTag>("BeamSpotInput");
0104   labelLoosePhot_ = iConfig.getParameter<edm::InputTag>("PhoLoose");
0105   labelTightPhot_ = iConfig.getParameter<edm::InputTag>("PhoTight");
0106   minPtJet_ = iConfig.getParameter<double>("MinPtJet");
0107   minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
0108 
0109   tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
0110   tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
0111   tok_HBHE_ = consumes<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_);
0112   tok_HF_ = consumes<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_);
0113   tok_HO_ = consumes<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_);
0114   tok_TrigRes_ = consumes<edm::TriggerResults>(labelTrigger_);
0115   tok_PFCand_ = consumes<reco::PFCandidateCollection>(labelPFCandidate_);
0116   tok_Vertex_ = consumes<reco::VertexCollection>(labelVertex_);
0117   tok_PFMET_ = consumes<reco::PFMETCollection>(labelPFMET_);
0118   tok_loosePhoton_ = consumes<edm::ValueMap<Bool_t>>(labelLoosePhot_);
0119   tok_tightPhoton_ = consumes<edm::ValueMap<Bool_t>>(labelTightPhot_);
0120   tok_GsfElec_ = consumes<reco::GsfElectronCollection>(labelGsfEle_);
0121   tok_Rho_ = consumes<double>(labelRho_);
0122   tok_Conv_ = consumes<reco::ConversionCollection>(labelConv_);
0123   tok_BS_ = consumes<reco::BeamSpot>(labelBeamSpot_);
0124 
0125   // register your products
0126   put_photon_ = produces<reco::PhotonCollection>(labelPhoton_.encode());
0127   put_pfJet_ = produces<reco::PFJetCollection>(labelPFJet_.encode());
0128   put_hbhe_ = produces<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_.encode());
0129   put_hf_ = produces<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_.encode());
0130   put_ho_ = produces<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_.encode());
0131   put_trigger_ = produces<edm::TriggerResults>(labelTrigger_.encode());
0132   put_loosePhot_ = produces<std::vector<Bool_t>>(labelLoosePhot_.encode());
0133   put_tightPhot_ = produces<std::vector<Bool_t>>(labelTightPhot_.encode());
0134   put_rho_ = produces<double>(labelRho_.encode());
0135   put_pfCandidate_ = produces<reco::PFCandidateCollection>(labelPFCandidate_.encode());
0136   put_vertex_ = produces<reco::VertexCollection>(labelVertex_.encode());
0137   put_pfMET_ = produces<reco::PFMETCollection>(labelPFMET_.encode());
0138   put_gsfEle_ = produces<reco::GsfElectronCollection>(labelGsfEle_.encode());
0139   put_conv_ = produces<reco::ConversionCollection>(labelConv_.encode());
0140   put_beamSpot_ = produces<reco::BeamSpot>(labelBeamSpot_.encode());
0141 }
0142 
0143 bool AlCaGammaJetProducer::select(const reco::PhotonCollection& ph, const reco::PFJetCollection& jt) const {
0144   // Check the requirement for minimum pT
0145   if (ph.empty())
0146     return false;
0147   bool ok(false);
0148   for (reco::PFJetCollection::const_iterator itr = jt.begin(); itr != jt.end(); ++itr) {
0149     if (itr->pt() >= minPtJet_) {
0150       ok = true;
0151       break;
0152     }
0153   }
0154   if (!ok)
0155     return ok;
0156   for (reco::PhotonCollection::const_iterator itr = ph.begin(); itr != ph.end(); ++itr) {
0157     if (itr->pt() >= minPtPhoton_)
0158       return ok;
0159   }
0160   return false;
0161 }
0162 
0163 // ------------ method called to produce the data  ------------
0164 void AlCaGammaJetProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0165   // Access the collections from iEvent
0166   auto const& phoHandle = iEvent.getHandle(tok_Photon_);
0167   if (!phoHandle.isValid()) {
0168     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
0169     return;
0170   }
0171   const reco::PhotonCollection& photon = *(phoHandle.product());
0172 
0173   auto const& pfjet = iEvent.getHandle(tok_PFJet_);
0174   if (!pfjet.isValid()) {
0175     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
0176     return;
0177   }
0178   const reco::PFJetCollection& pfjets = *(pfjet.product());
0179 
0180   auto const& pfc = iEvent.getHandle(tok_PFCand_);
0181   if (!pfc.isValid()) {
0182     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFCandidate_;
0183     return;
0184   }
0185   const reco::PFCandidateCollection& pfcand = *(pfc.product());
0186 
0187   auto const& vt = iEvent.getHandle(tok_Vertex_);
0188   if (!vt.isValid()) {
0189     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelVertex_;
0190     return;
0191   }
0192   const reco::VertexCollection& vtx = *(vt.product());
0193 
0194   auto const& pfmt = iEvent.getHandle(tok_PFMET_);
0195   if (!pfmt.isValid()) {
0196     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFMET_;
0197     return;
0198   }
0199   const reco::PFMETCollection& pfmet = *(pfmt.product());
0200 
0201   auto const& hbhe = iEvent.getHandle(tok_HBHE_);
0202   if (!hbhe.isValid()) {
0203     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHBHE_;
0204     return;
0205   }
0206   const edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>& Hithbhe = *(hbhe.product());
0207 
0208   auto const& ho = iEvent.getHandle(tok_HO_);
0209   if (!ho.isValid()) {
0210     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHO_;
0211     return;
0212   }
0213   const edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>& Hitho = *(ho.product());
0214 
0215   auto const& hf = iEvent.getHandle(tok_HF_);
0216   if (!hf.isValid()) {
0217     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHF_;
0218     return;
0219   }
0220   const edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>& Hithf = *(hf.product());
0221 
0222   auto const& trig = iEvent.getHandle(tok_TrigRes_);
0223   if (!trig.isValid()) {
0224     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelTrigger_;
0225     return;
0226   }
0227   const edm::TriggerResults& trigres = *(trig.product());
0228 
0229   auto const& rh = iEvent.getHandle(tok_Rho_);
0230   if (!rh.isValid()) {
0231     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelRho_;
0232     return;
0233   }
0234   const double rho_val = *(rh.product());
0235 
0236   auto const& gsf = iEvent.getHandle(tok_GsfElec_);
0237   if (!gsf.isValid()) {
0238     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelGsfEle_;
0239     return;
0240   }
0241   const reco::GsfElectronCollection& gsfele = *(gsf.product());
0242 
0243   auto const& con = iEvent.getHandle(tok_Conv_);
0244   if (!con.isValid()) {
0245     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelConv_;
0246     return;
0247   }
0248   const reco::ConversionCollection& conv = *(con.product());
0249 
0250   auto const& bs = iEvent.getHandle(tok_BS_);
0251   if (!bs.isValid()) {
0252     edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelBeamSpot_;
0253     return;
0254   }
0255   const reco::BeamSpot& beam = *(bs.product());
0256 
0257   // declare variables
0258   // copy from standard place, if the event is useful
0259   reco::BeamSpot miniBeamSpotCollection(
0260       beam.position(), beam.sigmaZ(), beam.dxdz(), beam.dydz(), beam.BeamWidthX(), beam.covariance(), beam.type());
0261 
0262   std::vector<Bool_t> miniLoosePhoton{};
0263   std::vector<Bool_t> miniTightPhoton{};
0264 
0265   // See if this event is useful
0266   bool accept = select(photon, pfjets);
0267   if (accept) {
0268     iEvent.emplace(put_photon_, photon);
0269     iEvent.emplace(put_pfJet_, pfjets);
0270     iEvent.emplace(put_hbhe_, Hithbhe);
0271     iEvent.emplace(put_hf_, Hithf);
0272     iEvent.emplace(put_ho_, Hitho);
0273     iEvent.emplace(put_trigger_, trigres);
0274     iEvent.emplace(put_pfCandidate_, pfcand);
0275     iEvent.emplace(put_vertex_, vtx);
0276     iEvent.emplace(put_pfMET_, pfmet);
0277     iEvent.emplace(put_gsfEle_, gsfele);
0278     iEvent.emplace(put_rho_, rho_val);
0279     iEvent.emplace(put_conv_, conv);
0280 
0281     auto const& loosePhotonQual = iEvent.getHandle(tok_loosePhoton_);
0282     auto const& tightPhotonQual = iEvent.getHandle(tok_tightPhoton_);
0283     if (loosePhotonQual.isValid() && tightPhotonQual.isValid()) {
0284       miniLoosePhoton.reserve(photon.size());
0285       miniTightPhoton.reserve(photon.size());
0286       for (int iPho = 0; iPho < int(photon.size()); ++iPho) {
0287         edm::Ref<reco::PhotonCollection> photonRef(phoHandle, iPho);
0288         if (!photonRef) {
0289           edm::LogVerbatim("AlCaGammaJet") << "failed ref";
0290           miniLoosePhoton.push_back(-1);
0291           miniTightPhoton.push_back(-1);
0292         } else {
0293           miniLoosePhoton.push_back((*loosePhotonQual)[photonRef]);
0294           miniTightPhoton.push_back((*tightPhotonQual)[photonRef]);
0295         }
0296       }
0297     }
0298   } else {
0299     iEvent.emplace(put_photon_, reco::PhotonCollection{});
0300     iEvent.emplace(put_pfJet_, reco::PFJetCollection{});
0301     iEvent.emplace(put_hbhe_, edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>{});
0302     iEvent.emplace(put_hf_, edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>{});
0303     iEvent.emplace(put_ho_, edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>{});
0304     iEvent.emplace(put_trigger_, edm::TriggerResults{});
0305     iEvent.emplace(put_pfCandidate_, reco::PFCandidateCollection{});
0306     iEvent.emplace(put_vertex_, reco::VertexCollection{});
0307     iEvent.emplace(put_pfMET_, reco::PFMETCollection{});
0308     iEvent.emplace(put_gsfEle_, reco::GsfElectronCollection{});
0309     iEvent.emplace(put_rho_, double{});
0310     iEvent.emplace(put_conv_, reco::ConversionCollection{});
0311   }
0312 
0313   //Put them in the event
0314   iEvent.emplace(put_beamSpot_, std::move(miniBeamSpotCollection));
0315   iEvent.emplace(put_loosePhot_, std::move(miniLoosePhoton));
0316   iEvent.emplace(put_tightPhot_, std::move(miniTightPhoton));
0317 
0318   return;
0319 }
0320 
0321 void AlCaGammaJetProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0322   edm::ParameterSetDescription desc;
0323   desc.add<edm::InputTag>("PhoInput", edm::InputTag("gedPhotons"));
0324   desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS"));
0325   desc.add<edm::InputTag>("HBHEInput", edm::InputTag("hbhereco"));
0326   desc.add<edm::InputTag>("HFInput", edm::InputTag("hfreco"));
0327   desc.add<edm::InputTag>("HOInput", edm::InputTag("horeco"));
0328   desc.add<edm::InputTag>("METInput", edm::InputTag("pfMet"));
0329   desc.add<edm::InputTag>("TriggerResults", edm::InputTag("TriggerResults::HLT"));
0330   desc.add<edm::InputTag>("gsfeleInput", edm::InputTag("gedGsfElectrons"));
0331   desc.add<edm::InputTag>("particleFlowInput", edm::InputTag("particleFlow"));
0332   desc.add<edm::InputTag>("VertexInput", edm::InputTag("offlinePrimaryVertices"));
0333   desc.add<edm::InputTag>("ConversionsInput", edm::InputTag("allConversions"));
0334   desc.add<edm::InputTag>("rhoInput", edm::InputTag("fixedGridRhoFastjetAll"));
0335   desc.add<edm::InputTag>("BeamSpotInput", edm::InputTag("offlineBeamSpot"));
0336   desc.add<edm::InputTag>("PhoLoose", edm::InputTag("PhotonIDProdGED", "PhotonCutBasedIDLoose"));
0337   desc.add<edm::InputTag>("PhoTight", edm::InputTag("PhotonIDProdGED", "PhotonCutBasedIDTight"));
0338   desc.add<double>("MinPtJet", 10.0);
0339   desc.add<double>("MinPtPhoton", 10.0);
0340   descriptions.add("alcaGammaJetProducer", desc);
0341 }
0342 
0343 DEFINE_FWK_MODULE(AlCaGammaJetProducer);