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
29 
33 //#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
34 
35 //
36 // class declaration
37 //
38 
39 namespace AlCaGammaJet {
40  struct Counters {
42  mutable std::atomic<unsigned int> nProcessed_, nSelected_;
43  };
44 } // namespace AlCaGammaJet
45 
46 class AlCaGammaJetSelector : public edm::stream::EDFilter<edm::GlobalCache<AlCaGammaJet::Counters> > {
47 public:
49  ~AlCaGammaJetSelector() override;
50 
51  static std::unique_ptr<AlCaGammaJet::Counters> initializeGlobalCache(edm::ParameterSet const&) {
52  return std::make_unique<AlCaGammaJet::Counters>();
53  }
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56  bool filter(edm::Event&, const edm::EventSetup&) override;
57  void endStream() override;
58  static void globalEndJob(const AlCaGammaJet::Counters* counters);
59 
60 private:
61  void beginRun(edm::Run const&, edm::EventSetup const&) override {}
62  void endRun(edm::Run const&, edm::EventSetup const&) override {}
64  void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override {}
66 
67  // ----------member data ---------------------------
68 
69  unsigned int nProcessed_, nSelected_;
70 
75 };
76 
77 //
78 // constants, enums and typedefs
79 //
80 
81 //
82 // static data member definitions
83 //
84 
85 //
86 // constructors and destructor
87 //
89  nProcessed_ = 0;
90  nSelected_ = 0;
91 
92  // get input
93  labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
94  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
95  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
96  minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
97 
98  // Register consumption
99  tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
100  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
101 }
102 
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.addDefault(desc);
119 }
120 
121 // ------------ method called on each new Event ------------
123  nProcessed_++;
124 
125  // Access the collections from iEvent
127  iEvent.getByToken(tok_Photon_, phoHandle);
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 
135  iEvent.getByToken(tok_PFJet_, pfjetHandle);
136  if (!pfjetHandle.isValid()) {
137  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
138  return false; // do not filter
139  }
140  const reco::PFJetCollection pfjets = *(pfjetHandle.product());
141 
142  // Check the conditions for a good event
143  if (!(select(photons, pfjets)))
144  return false;
145 
146  //std::cout << "good event\n";
147  nSelected_++;
148  return true;
149 }
150 
152  globalCache()->nProcessed_ += nProcessed_;
153  globalCache()->nSelected_ += nSelected_;
154 }
155 
156 // ------------ method called once each job just after ending the event loop ------------
157 
159  edm::LogWarning("AlCaGammaJet") << "Finds " << count->nSelected_ << " good events out of " << count->nProcessed_;
160 }
161 
163  // Check the requirement for minimum pT
164  if (photons.empty())
165  return false;
166  bool ok(false);
167  for (reco::PFJetCollection::const_iterator itr = jets.begin(); itr != jets.end(); ++itr) {
168  if (itr->pt() >= minPtJet_) {
169  ok = true;
170  break;
171  }
172  }
173  if (!ok)
174  return ok;
175  for (reco::PhotonCollection::const_iterator itr = photons.begin(); itr != photons.end(); ++itr) {
176  if (itr->pt() >= minPtPhoton_)
177  return ok;
178  }
179  return false;
180 }
181 
182 //define this as a plug-in
AlCaGammaJetSelector::endStream
void endStream() override
Definition: AlCaGammaJetSelector.cc:151
AlCaGammaJetSelector::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: AlCaGammaJetSelector.cc:64
AlCaGammaJetSelector::minPtPhoton_
double minPtPhoton_
Definition: AlCaGammaJetSelector.cc:72
AlCaGammaJetSelector::labelPhoton_
edm::InputTag labelPhoton_
Definition: AlCaGammaJetSelector.cc:71
AlCaGammaJetSelector::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: AlCaGammaJetSelector.cc:63
edm::Handle::product
T const * product() const
Definition: Handle.h:70
AlCaGammaJet::Counters
Definition: AlCaGammaJetSelector.cc:40
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< reco::PhotonCollection >
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
PFJetCollection.h
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
AlCaGammaJetSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: AlCaGammaJetSelector.cc:110
PhotonFwd.h
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
AlCaGammaJetSelector::filter
bool filter(edm::Event &, const edm::EventSetup &) override
Definition: AlCaGammaJetSelector.cc:122
AlCaGammaJet::Counters::nSelected_
std::atomic< unsigned int > nSelected_
Definition: AlCaGammaJetSelector.cc:42
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle< reco::PhotonCollection >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
AlCaGammaJetSelector::tok_PFJet_
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
Definition: AlCaGammaJetSelector.cc:74
AlCaGammaJetSelector::AlCaGammaJetSelector
AlCaGammaJetSelector(const edm::ParameterSet &, const AlCaGammaJet::Counters *count)
Definition: AlCaGammaJetSelector.cc:88
MakerMacros.h
Photon.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
AlCaGammaJetSelector::nProcessed_
unsigned int nProcessed_
Definition: AlCaGammaJetSelector.cc:69
AlCaGammaJetSelector::nSelected_
unsigned int nSelected_
Definition: AlCaGammaJetSelector.cc:69
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaGammaJet
Definition: AlCaGammaJetSelector.cc:39
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
AlCaGammaJetSelector::~AlCaGammaJetSelector
~AlCaGammaJetSelector() override
Definition: AlCaGammaJetSelector.cc:103
iEvent
int iEvent
Definition: GenABIO.cc:224
AlCaGammaJetSelector::select
bool select(const reco::PhotonCollection &, const reco::PFJetCollection &)
Definition: AlCaGammaJetSelector.cc:162
BPHMonitor_cfi.photons
photons
Definition: BPHMonitor_cfi.py:91
edm::EventSetup
Definition: EventSetup.h:57
AlCaGammaJetSelector::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaGammaJetSelector.cc:62
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
AlCaGammaJetSelector::tok_Photon_
edm::EDGetTokenT< reco::PhotonCollection > tok_Photon_
Definition: AlCaGammaJetSelector.cc:73
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
AlCaGammaJet::Counters::Counters
Counters()
Definition: AlCaGammaJetSelector.cc:41
reco::PFJetCollection
std::vector< PFJet > PFJetCollection
collection of PFJet objects
Definition: PFJetCollection.h:14
Frameworkfwd.h
AlCaGammaJetSelector::initializeGlobalCache
static std::unique_ptr< AlCaGammaJet::Counters > initializeGlobalCache(edm::ParameterSet const &)
Definition: AlCaGammaJetSelector.cc:51
AlCaGammaJet::Counters::nProcessed_
std::atomic< unsigned int > nProcessed_
Definition: AlCaGammaJetSelector.cc:42
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlCaGammaJetSelector::minPtJet_
double minPtJet_
Definition: AlCaGammaJetSelector.cc:72
reco::PhotonCollection
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
EDFilter.h
AlCaGammaJetSelector::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: AlCaGammaJetSelector.cc:61
ParameterSet.h
AlCaGammaJetSelector
Definition: AlCaGammaJetSelector.cc:46
AlCaGammaJetSelector::globalEndJob
static void globalEndJob(const AlCaGammaJet::Counters *counters)
Definition: AlCaGammaJetSelector.cc:158
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::stream::EDFilter
Definition: EDFilter.h:38
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
AlCaGammaJetSelector::labelPFJet_
edm::InputTag labelPFJet_
Definition: AlCaGammaJetSelector.cc:71
edm::InputTag
Definition: InputTag.h:15