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 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 
24 // user include files
30 
34 //#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
35 
36 //
37 // class declaration
38 //
39 
40 namespace AlCaGammaJet {
41  struct Counters {
43  mutable std::atomic<unsigned int> nProcessed_, nSelected_;
44  };
45 }
46 
47 
48 class AlCaGammaJetSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaGammaJet::Counters> > {
49 
50 public:
52  ~AlCaGammaJetSelector() override;
53 
54  static std::unique_ptr<AlCaGammaJet::Counters> initializeGlobalCache(edm::ParameterSet const& ) {
55  return std::make_unique<AlCaGammaJet::Counters>();
56  }
57 
58  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
59  bool filter(edm::Event&, const edm::EventSetup&) override;
60  void endStream() override;
61  static void globalEndJob(const AlCaGammaJet::Counters* counters);
62 
63 private:
64 
65  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
66  void endRun(edm::Run const&, edm::EventSetup const&) override {}
68  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
70 
71  // ----------member data ---------------------------
72 
73  unsigned int nProcessed_, nSelected_;
74 
76  double minPtJet_, minPtPhoton_;
79 
80 };
81 
82 //
83 // constants, enums and typedefs
84 //
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  nProcessed_ = 0;
95  nSelected_ = 0;
96 
97  // get input
98  labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
99  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
100  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
101  minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
102 
103  // Register consumption
104  tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
105  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
106 
107 }
108 
110 
111 //
112 // member functions
113 //
114 
115 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
117  //The following says we do not know what parameters are allowed so do no validation
118  // Please change this to state exactly what you do use, even if it is no parameters
120  desc.add<edm::InputTag>("PhoInput", edm::InputTag("gedPhotons"));
121  desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS"));
122  desc.add<double>("MinPtJet", 10.0);
123  desc.add<double>("MinPtPhoton", 10.0);
124  descriptions.addDefault(desc);
125 }
126 
127 // ------------ method called on each new Event ------------
129  nProcessed_++;
130 
131  // Access the collections from iEvent
133  iEvent.getByToken(tok_Photon_,phoHandle);
134  if (!phoHandle.isValid()) {
135  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
136  return false; // do not filter
137  }
138  const reco::PhotonCollection photons = *(phoHandle.product());
139 
141  iEvent.getByToken(tok_PFJet_,pfjetHandle);
142  if (!pfjetHandle.isValid()) {
143  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
144  return false; // do not filter
145  }
146  const reco::PFJetCollection pfjets = *(pfjetHandle.product());
147 
148  // Check the conditions for a good event
149  if (!(select(photons, pfjets))) return false;
150 
151  //std::cout << "good event\n";
152  nSelected_++;
153  return true;
154 
155 }
156 
158  globalCache()->nProcessed_ += nProcessed_;
159  globalCache()->nSelected_ += nSelected_;
160 }
161 
162 // ------------ method called once each job just after ending the event loop ------------
163 
165  edm::LogWarning("AlCaGammaJet") << "Finds " << count->nSelected_
166  <<" good events out of "
167  << count->nProcessed_;
168 }
169 
171  const reco::PFJetCollection &jets) {
172 
173  // Check the requirement for minimum pT
174  if (photons.empty()) return false;
175  bool ok(false);
176  for (reco::PFJetCollection::const_iterator itr=jets.begin();
177  itr!=jets.end(); ++itr) {
178  if (itr->pt() >= minPtJet_) {
179  ok = true;
180  break;
181  }
182  }
183  if (!ok) return ok;
184  for (reco::PhotonCollection::const_iterator itr=photons.begin();
185  itr!=photons.end(); ++itr) {
186  if (itr->pt() >= minPtPhoton_) return ok;
187  }
188  return false;
189 }
190 
191 //define this as a plug-in
T getParameter(std::string const &) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
static void globalEndJob(const AlCaGammaJet::Counters *counters)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
std::atomic< unsigned int > nSelected_
AlCaGammaJetSelector(const edm::ParameterSet &, const AlCaGammaJet::Counters *count)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
vector< PseudoJet > jets
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool filter(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
void endRun(edm::Run const &, edm::EventSetup const &) override
T const * product() const
Definition: Handle.h:81
bool select(const reco::PhotonCollection &, const reco::PFJetCollection &)
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
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
edm::EDGetTokenT< reco::PhotonCollection > tok_Photon_
Definition: Run.h:43