CMS 3D CMS Logo

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 
42  struct Counters {
44  mutable std::atomic<unsigned int> nProcessed_, nSelected_;
45  };
46 } // namespace alCaGammaJetSelector
47 
48 class AlCaGammaJetSelector : public edm::stream::EDFilter<edm::GlobalCache<alCaGammaJetSelector::Counters> > {
49 public:
51  ~AlCaGammaJetSelector() override = default;
52 
53  static std::unique_ptr<alCaGammaJetSelector::Counters> initializeGlobalCache(edm::ParameterSet const&) {
54  return std::make_unique<alCaGammaJetSelector::Counters>();
55  }
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58  bool filter(edm::Event&, const edm::EventSetup&) override;
59  void endStream() override;
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 //
92  nProcessed_ = 0;
93  nSelected_ = 0;
94 
95  // get input
96  labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
97  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
98  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
99  minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
100 
101  // Register consumption
102  tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
103  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
104 }
105 
106 //
107 // member functions
108 //
109 
110 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
112  //The following says we do not know what parameters are allowed so do no validation
113  // Please change this to state exactly what you do use, even if it is no parameters
115  desc.add<edm::InputTag>("PhoInput", edm::InputTag("gedPhotons"));
116  desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS"));
117  desc.add<double>("MinPtJet", 10.0);
118  desc.add<double>("MinPtPhoton", 10.0);
119  descriptions.add("alcaGammaJetSelector", desc);
120 }
121 
122 // ------------ method called on each new Event ------------
124  nProcessed_++;
125 
126  // Access the collections from iEvent
127  auto const& phoHandle = iEvent.getHandle(tok_Photon_);
128  if (!phoHandle.isValid()) {
129  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
130  return false; // do not filter
131  }
132  const reco::PhotonCollection photons = *(phoHandle.product());
133 
134  auto const& pfjetHandle = iEvent.getHandle(tok_PFJet_);
135  if (!pfjetHandle.isValid()) {
136  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
137  return false; // do not filter
138  }
139  const reco::PFJetCollection pfjets = *(pfjetHandle.product());
140 
141  // Check the conditions for a good event
142  if (!(select(photons, pfjets)))
143  return false;
144 
145  edm::LogVerbatim("AlCaGammaJet") << "good event\n";
146  nSelected_++;
147  return true;
148 }
149 
151  globalCache()->nProcessed_ += nProcessed_;
152  globalCache()->nSelected_ += nSelected_;
153 }
154 
155 // ------------ method called once each job just after ending the event loop ------------
156 
158  edm::LogWarning("AlCaGammaJet") << "Finds " << count->nSelected_ << " good events out of " << count->nProcessed_;
159 }
160 
162  // Check the requirement for minimum pT
163  if (photons.empty())
164  return false;
165  bool ok(false);
166  for (reco::PFJetCollection::const_iterator itr = jets.begin(); itr != jets.end(); ++itr) {
167  if (itr->pt() >= minPtJet_) {
168  ok = true;
169  break;
170  }
171  }
172  if (!ok)
173  return ok;
174  for (reco::PhotonCollection::const_iterator itr = photons.begin(); itr != photons.end(); ++itr) {
175  if (itr->pt() >= minPtPhoton_)
176  return ok;
177  }
178  return false;
179 }
180 
181 //define this as a plug-in
Log< level::Info, true > LogVerbatim
~AlCaGammaJetSelector() override=default
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void globalEndJob(const alCaGammaJetSelector::Counters *counters)
std::atomic< unsigned int > nSelected_
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
AlCaGammaJetSelector(const edm::ParameterSet &, const alCaGammaJetSelector::Counters *count)
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ CellNeighborsVector< TrackerTraits > const CellTracksVector< TrackerTraits > const OuterHitOfCell< TrackerTraits > const int32_t uint32_t Counters * counters
int iEvent
Definition: GenABIO.cc:224
bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void beginRun(edm::Run const &, edm::EventSetup const &) override
std::vector< PFJet > PFJetCollection
collection of PFJet objects
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< reco::PhotonCollection > tok_Photon_
static std::unique_ptr< alCaGammaJetSelector::Counters > initializeGlobalCache(edm::ParameterSet const &)
Definition: Run.h:45
std::atomic< unsigned int > nProcessed_