File indexing completed on 2024-04-06 11:58:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <iostream>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDFilter.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0031
0032 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0033 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0034 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0035
0036
0037
0038
0039
0040
0041 namespace alCaGammaJetSelector {
0042 struct Counters {
0043 Counters() : nProcessed_(0), nSelected_(0) {}
0044 mutable std::atomic<unsigned int> nProcessed_, nSelected_;
0045 };
0046 }
0047
0048 class AlCaGammaJetSelector : public edm::stream::EDFilter<edm::GlobalCache<alCaGammaJetSelector::Counters> > {
0049 public:
0050 explicit AlCaGammaJetSelector(const edm::ParameterSet&, const alCaGammaJetSelector::Counters* count);
0051 ~AlCaGammaJetSelector() override = default;
0052
0053 static std::unique_ptr<alCaGammaJetSelector::Counters> initializeGlobalCache(edm::ParameterSet const&) {
0054 return std::make_unique<alCaGammaJetSelector::Counters>();
0055 }
0056
0057 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0058 bool filter(edm::Event&, const edm::EventSetup&) override;
0059 void endStream() override;
0060 static void globalEndJob(const alCaGammaJetSelector::Counters* counters);
0061
0062 private:
0063 void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0064 void endRun(edm::Run const&, edm::EventSetup const&) override {}
0065 void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0066 void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
0067 bool select(const reco::PhotonCollection&, const reco::PFJetCollection&);
0068
0069
0070
0071 unsigned int nProcessed_, nSelected_;
0072
0073 edm::InputTag labelPhoton_, labelPFJet_;
0074 double minPtJet_, minPtPhoton_;
0075 edm::EDGetTokenT<reco::PhotonCollection> tok_Photon_;
0076 edm::EDGetTokenT<reco::PFJetCollection> tok_PFJet_;
0077 };
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 AlCaGammaJetSelector::AlCaGammaJetSelector(const edm::ParameterSet& iConfig,
0091 const alCaGammaJetSelector::Counters* counters) {
0092 nProcessed_ = 0;
0093 nSelected_ = 0;
0094
0095
0096 labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
0097 labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
0098 minPtJet_ = iConfig.getParameter<double>("MinPtJet");
0099 minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
0100
0101
0102 tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
0103 tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
0104 }
0105
0106
0107
0108
0109
0110
0111 void AlCaGammaJetSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0112
0113
0114 edm::ParameterSetDescription desc;
0115 desc.add<edm::InputTag>("PhoInput", edm::InputTag("gedPhotons"));
0116 desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS"));
0117 desc.add<double>("MinPtJet", 10.0);
0118 desc.add<double>("MinPtPhoton", 10.0);
0119 descriptions.add("alcaGammaJetSelector", desc);
0120 }
0121
0122
0123 bool AlCaGammaJetSelector::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0124 nProcessed_++;
0125
0126
0127 auto const& phoHandle = iEvent.getHandle(tok_Photon_);
0128 if (!phoHandle.isValid()) {
0129 edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
0130 return false;
0131 }
0132 const reco::PhotonCollection photons = *(phoHandle.product());
0133
0134 auto const& pfjetHandle = iEvent.getHandle(tok_PFJet_);
0135 if (!pfjetHandle.isValid()) {
0136 edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
0137 return false;
0138 }
0139 const reco::PFJetCollection pfjets = *(pfjetHandle.product());
0140
0141
0142 if (!(select(photons, pfjets)))
0143 return false;
0144
0145 edm::LogVerbatim("AlCaGammaJet") << "good event\n";
0146 nSelected_++;
0147 return true;
0148 }
0149
0150 void AlCaGammaJetSelector::endStream() {
0151 globalCache()->nProcessed_ += nProcessed_;
0152 globalCache()->nSelected_ += nSelected_;
0153 }
0154
0155
0156
0157 void AlCaGammaJetSelector::globalEndJob(const alCaGammaJetSelector::Counters* count) {
0158 edm::LogWarning("AlCaGammaJet") << "Finds " << count->nSelected_ << " good events out of " << count->nProcessed_;
0159 }
0160
0161 bool AlCaGammaJetSelector::select(const reco::PhotonCollection& photons, const reco::PFJetCollection& jets) {
0162
0163 if (photons.empty())
0164 return false;
0165 bool ok(false);
0166 for (reco::PFJetCollection::const_iterator itr = jets.begin(); itr != jets.end(); ++itr) {
0167 if (itr->pt() >= minPtJet_) {
0168 ok = true;
0169 break;
0170 }
0171 }
0172 if (!ok)
0173 return ok;
0174 for (reco::PhotonCollection::const_iterator itr = photons.begin(); itr != photons.end(); ++itr) {
0175 if (itr->pt() >= minPtPhoton_)
0176 return ok;
0177 }
0178 return false;
0179 }
0180
0181
0182 DEFINE_FWK_MODULE(AlCaGammaJetSelector);