CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlCaGammaJetSelector.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Calibration/HcalAlCaRecoProducers/AlCaGammaJetSelector
4 // Class: AlCaGammaJetSelector
5 //
13 //
14 // Original Author: Andrius Juodagalvis
15 // Created: Fri, 15 Aug 2015 12:09:55 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 
23 // user include files
31 
35 //#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
36 
37 //
38 // class declaration
39 //
40 
41 namespace AlCaGammaJet {
42  struct Counters {
44  mutable std::atomic<unsigned int> nProcessed_, nSelected_;
45  };
46 } // namespace AlCaGammaJet
47 
48 class AlCaGammaJetSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaGammaJet::Counters> > {
49 public:
51  ~AlCaGammaJetSelector() override = default;
52 
53  static std::unique_ptr<AlCaGammaJet::Counters> initializeGlobalCache(edm::ParameterSet const&) {
54  return std::make_unique<AlCaGammaJet::Counters>();
55  }
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58  bool filter(edm::Event&, const edm::EventSetup&) override;
59  void endStream() override;
60  static void globalEndJob(const AlCaGammaJet::Counters* counters);
61 
62 private:
63  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
64  void endRun(edm::Run const&, edm::EventSetup const&) override {}
66  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
68 
69  // ----------member data ---------------------------
70 
71  unsigned int nProcessed_, nSelected_;
72 
77 };
78 
79 //
80 // constants, enums and typedefs
81 //
82 
83 //
84 // static data member definitions
85 //
86 
87 //
88 // constructors and destructor
89 //
91  nProcessed_ = 0;
92  nSelected_ = 0;
93 
94  // get input
95  labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
96  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
97  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
98  minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
99 
100  // Register consumption
101  tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
102  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
103 }
104 
105 //
106 // member functions
107 //
108 
109 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
111  //The following says we do not know what parameters are allowed so do no validation
112  // Please change this to state exactly what you do use, even if it is no parameters
114  desc.add<edm::InputTag>("PhoInput", edm::InputTag("gedPhotons"));
115  desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS"));
116  desc.add<double>("MinPtJet", 10.0);
117  desc.add<double>("MinPtPhoton", 10.0);
118  descriptions.add("alcaGammaJetSelector", desc);
119 }
120 
121 // ------------ method called on each new Event ------------
123  nProcessed_++;
124 
125  // Access the collections from iEvent
126  auto const& phoHandle = iEvent.getHandle(tok_Photon_);
127  if (!phoHandle.isValid()) {
128  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
129  return false; // do not filter
130  }
131  const reco::PhotonCollection photons = *(phoHandle.product());
132 
133  auto const& pfjetHandle = iEvent.getHandle(tok_PFJet_);
134  if (!pfjetHandle.isValid()) {
135  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
136  return false; // do not filter
137  }
138  const reco::PFJetCollection pfjets = *(pfjetHandle.product());
139 
140  // Check the conditions for a good event
141  if (!(select(photons, pfjets)))
142  return false;
143 
144  edm::LogVerbatim("AlCaGammaJet") << "good event\n";
145  nSelected_++;
146  return true;
147 }
148 
150  globalCache()->nProcessed_ += nProcessed_;
151  globalCache()->nSelected_ += nSelected_;
152 }
153 
154 // ------------ method called once each job just after ending the event loop ------------
155 
157  edm::LogWarning("AlCaGammaJet") << "Finds " << count->nSelected_ << " good events out of " << count->nProcessed_;
158 }
159 
161  // Check the requirement for minimum pT
162  if (photons.empty())
163  return false;
164  bool ok(false);
165  for (reco::PFJetCollection::const_iterator itr = jets.begin(); itr != jets.end(); ++itr) {
166  if (itr->pt() >= minPtJet_) {
167  ok = true;
168  break;
169  }
170  }
171  if (!ok)
172  return ok;
173  for (reco::PhotonCollection::const_iterator itr = photons.begin(); itr != photons.end(); ++itr) {
174  if (itr->pt() >= minPtPhoton_)
175  return ok;
176  }
177  return false;
178 }
179 
180 //define this as a plug-in
Log< level::Info, true > LogVerbatim
~AlCaGammaJetSelector() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void globalEndJob(const AlCaGammaJet::Counters *counters)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
std::atomic< unsigned int > nSelected_
AlCaGammaJetSelector(const edm::ParameterSet &, const AlCaGammaJet::Counters *count)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
int iEvent
Definition: GenABIO.cc:224
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t uint32_t CAHitNtupletGeneratorKernelsGPU::Counters * counters
vector< PseudoJet > jets
bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void endRun(edm::Run const &, edm::EventSetup const &) override
bool select(const reco::PhotonCollection &, const reco::PFJetCollection &)
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static std::unique_ptr< AlCaGammaJet::Counters > initializeGlobalCache(edm::ParameterSet const &)
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< PFJet > PFJetCollection
collection of PFJet objects
std::atomic< unsigned int > nProcessed_
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< reco::PhotonCollection > tok_Photon_
Definition: Run.h:45