CMS 3D CMS Logo

AlCaGammaJetProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <string>
4 // user include files
13 
31 
34 #include <iostream>
35 
36 //
37 // class declaration
38 //
39 
41 public:
42  explicit AlCaGammaJetProducer(const edm::ParameterSet&);
43  ~AlCaGammaJetProducer() override = default;
44  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
45  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
46 
47 private:
48  bool select(const reco::PhotonCollection&, const reco::PFJetCollection&) const;
49 
50  // ----------member data ---------------------------
51 
55 
71 
87 };
88 
90  // Take input
91  labelPhoton_ = iConfig.getParameter<edm::InputTag>("PhoInput");
92  labelPFJet_ = iConfig.getParameter<edm::InputTag>("PFjetInput");
93  labelHBHE_ = iConfig.getParameter<edm::InputTag>("HBHEInput");
94  labelHF_ = iConfig.getParameter<edm::InputTag>("HFInput");
95  labelHO_ = iConfig.getParameter<edm::InputTag>("HOInput");
96  labelTrigger_ = iConfig.getParameter<edm::InputTag>("TriggerResults");
97  labelPFCandidate_ = iConfig.getParameter<edm::InputTag>("particleFlowInput");
98  labelVertex_ = iConfig.getParameter<edm::InputTag>("VertexInput");
99  labelPFMET_ = iConfig.getParameter<edm::InputTag>("METInput");
100  labelGsfEle_ = iConfig.getParameter<edm::InputTag>("gsfeleInput");
101  labelRho_ = iConfig.getParameter<edm::InputTag>("rhoInput");
102  labelConv_ = iConfig.getParameter<edm::InputTag>("ConversionsInput");
103  labelBeamSpot_ = iConfig.getParameter<edm::InputTag>("BeamSpotInput");
104  labelLoosePhot_ = iConfig.getParameter<edm::InputTag>("PhoLoose");
105  labelTightPhot_ = iConfig.getParameter<edm::InputTag>("PhoTight");
106  minPtJet_ = iConfig.getParameter<double>("MinPtJet");
107  minPtPhoton_ = iConfig.getParameter<double>("MinPtPhoton");
108 
109  tok_Photon_ = consumes<reco::PhotonCollection>(labelPhoton_);
110  tok_PFJet_ = consumes<reco::PFJetCollection>(labelPFJet_);
111  tok_HBHE_ = consumes<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_);
112  tok_HF_ = consumes<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_);
113  tok_HO_ = consumes<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_);
114  tok_TrigRes_ = consumes<edm::TriggerResults>(labelTrigger_);
115  tok_PFCand_ = consumes<reco::PFCandidateCollection>(labelPFCandidate_);
116  tok_Vertex_ = consumes<reco::VertexCollection>(labelVertex_);
117  tok_PFMET_ = consumes<reco::PFMETCollection>(labelPFMET_);
118  tok_loosePhoton_ = consumes<edm::ValueMap<Bool_t>>(labelLoosePhot_);
119  tok_tightPhoton_ = consumes<edm::ValueMap<Bool_t>>(labelTightPhot_);
120  tok_GsfElec_ = consumes<reco::GsfElectronCollection>(labelGsfEle_);
121  tok_Rho_ = consumes<double>(labelRho_);
122  tok_Conv_ = consumes<reco::ConversionCollection>(labelConv_);
123  tok_BS_ = consumes<reco::BeamSpot>(labelBeamSpot_);
124 
125  // register your products
126  put_photon_ = produces<reco::PhotonCollection>(labelPhoton_.encode());
127  put_pfJet_ = produces<reco::PFJetCollection>(labelPFJet_.encode());
128  put_hbhe_ = produces<edm::SortedCollection<HBHERecHit, edm::StrictWeakOrdering<HBHERecHit>>>(labelHBHE_.encode());
129  put_hf_ = produces<edm::SortedCollection<HFRecHit, edm::StrictWeakOrdering<HFRecHit>>>(labelHF_.encode());
130  put_ho_ = produces<edm::SortedCollection<HORecHit, edm::StrictWeakOrdering<HORecHit>>>(labelHO_.encode());
131  put_trigger_ = produces<edm::TriggerResults>(labelTrigger_.encode());
132  put_loosePhot_ = produces<std::vector<Bool_t>>(labelLoosePhot_.encode());
133  put_tightPhot_ = produces<std::vector<Bool_t>>(labelTightPhot_.encode());
134  put_rho_ = produces<double>(labelRho_.encode());
135  put_pfCandidate_ = produces<reco::PFCandidateCollection>(labelPFCandidate_.encode());
136  put_vertex_ = produces<reco::VertexCollection>(labelVertex_.encode());
137  put_pfMET_ = produces<reco::PFMETCollection>(labelPFMET_.encode());
138  put_gsfEle_ = produces<reco::GsfElectronCollection>(labelGsfEle_.encode());
139  put_conv_ = produces<reco::ConversionCollection>(labelConv_.encode());
140  put_beamSpot_ = produces<reco::BeamSpot>(labelBeamSpot_.encode());
141 }
142 
144  // Check the requirement for minimum pT
145  if (ph.empty())
146  return false;
147  bool ok(false);
148  for (reco::PFJetCollection::const_iterator itr = jt.begin(); itr != jt.end(); ++itr) {
149  if (itr->pt() >= minPtJet_) {
150  ok = true;
151  break;
152  }
153  }
154  if (!ok)
155  return ok;
156  for (reco::PhotonCollection::const_iterator itr = ph.begin(); itr != ph.end(); ++itr) {
157  if (itr->pt() >= minPtPhoton_)
158  return ok;
159  }
160  return false;
161 }
162 
163 // ------------ method called to produce the data ------------
165  // Access the collections from iEvent
166  auto const& phoHandle = iEvent.getHandle(tok_Photon_);
167  if (!phoHandle.isValid()) {
168  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get the product " << labelPhoton_;
169  return;
170  }
171  const reco::PhotonCollection& photon = *(phoHandle.product());
172 
173  auto const& pfjet = iEvent.getHandle(tok_PFJet_);
174  if (!pfjet.isValid()) {
175  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFJet_;
176  return;
177  }
178  const reco::PFJetCollection& pfjets = *(pfjet.product());
179 
180  auto const& pfc = iEvent.getHandle(tok_PFCand_);
181  if (!pfc.isValid()) {
182  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFCandidate_;
183  return;
184  }
185  const reco::PFCandidateCollection& pfcand = *(pfc.product());
186 
187  auto const& vt = iEvent.getHandle(tok_Vertex_);
188  if (!vt.isValid()) {
189  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelVertex_;
190  return;
191  }
192  const reco::VertexCollection& vtx = *(vt.product());
193 
194  auto const& pfmt = iEvent.getHandle(tok_PFMET_);
195  if (!pfmt.isValid()) {
196  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelPFMET_;
197  return;
198  }
199  const reco::PFMETCollection& pfmet = *(pfmt.product());
200 
201  auto const& hbhe = iEvent.getHandle(tok_HBHE_);
202  if (!hbhe.isValid()) {
203  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHBHE_;
204  return;
205  }
207 
208  auto const& ho = iEvent.getHandle(tok_HO_);
209  if (!ho.isValid()) {
210  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHO_;
211  return;
212  }
214 
215  auto const& hf = iEvent.getHandle(tok_HF_);
216  if (!hf.isValid()) {
217  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelHF_;
218  return;
219  }
221 
222  auto const& trig = iEvent.getHandle(tok_TrigRes_);
223  if (!trig.isValid()) {
224  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelTrigger_;
225  return;
226  }
227  const edm::TriggerResults& trigres = *(trig.product());
228 
229  auto const& rh = iEvent.getHandle(tok_Rho_);
230  if (!rh.isValid()) {
231  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelRho_;
232  return;
233  }
234  const double rho_val = *(rh.product());
235 
236  auto const& gsf = iEvent.getHandle(tok_GsfElec_);
237  if (!gsf.isValid()) {
238  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelGsfEle_;
239  return;
240  }
241  const reco::GsfElectronCollection& gsfele = *(gsf.product());
242 
243  auto const& con = iEvent.getHandle(tok_Conv_);
244  if (!con.isValid()) {
245  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelConv_;
246  return;
247  }
248  const reco::ConversionCollection& conv = *(con.product());
249 
250  auto const& bs = iEvent.getHandle(tok_BS_);
251  if (!bs.isValid()) {
252  edm::LogWarning("AlCaGammaJet") << "AlCaGammaJetProducer: Error! can't get product " << labelBeamSpot_;
253  return;
254  }
255  const reco::BeamSpot& beam = *(bs.product());
256 
257  // declare variables
258  // copy from standard place, if the event is useful
259  reco::BeamSpot miniBeamSpotCollection(
260  beam.position(), beam.sigmaZ(), beam.dxdz(), beam.dydz(), beam.BeamWidthX(), beam.covariance(), beam.type());
261 
262  std::vector<Bool_t> miniLoosePhoton{};
263  std::vector<Bool_t> miniTightPhoton{};
264 
265  // See if this event is useful
266  bool accept = select(photon, pfjets);
267  if (accept) {
268  iEvent.emplace(put_photon_, photon);
269  iEvent.emplace(put_pfJet_, pfjets);
270  iEvent.emplace(put_hbhe_, Hithbhe);
271  iEvent.emplace(put_hf_, Hithf);
272  iEvent.emplace(put_ho_, Hitho);
273  iEvent.emplace(put_trigger_, trigres);
274  iEvent.emplace(put_pfCandidate_, pfcand);
275  iEvent.emplace(put_vertex_, vtx);
276  iEvent.emplace(put_pfMET_, pfmet);
277  iEvent.emplace(put_gsfEle_, gsfele);
278  iEvent.emplace(put_rho_, rho_val);
279  iEvent.emplace(put_conv_, conv);
280 
281  auto const& loosePhotonQual = iEvent.getHandle(tok_loosePhoton_);
282  auto const& tightPhotonQual = iEvent.getHandle(tok_tightPhoton_);
283  if (loosePhotonQual.isValid() && tightPhotonQual.isValid()) {
284  miniLoosePhoton.reserve(photon.size());
285  miniTightPhoton.reserve(photon.size());
286  for (int iPho = 0; iPho < int(photon.size()); ++iPho) {
287  edm::Ref<reco::PhotonCollection> photonRef(phoHandle, iPho);
288  if (!photonRef) {
289  edm::LogVerbatim("AlCaGammaJet") << "failed ref";
290  miniLoosePhoton.push_back(-1);
291  miniTightPhoton.push_back(-1);
292  } else {
293  miniLoosePhoton.push_back((*loosePhotonQual)[photonRef]);
294  miniTightPhoton.push_back((*tightPhotonQual)[photonRef]);
295  }
296  }
297  }
298  } else {
309  iEvent.emplace(put_rho_, double{});
311  }
312 
313  //Put them in the event
314  iEvent.emplace(put_beamSpot_, std::move(miniBeamSpotCollection));
315  iEvent.emplace(put_loosePhot_, std::move(miniLoosePhoton));
316  iEvent.emplace(put_tightPhot_, std::move(miniTightPhoton));
317 
318  return;
319 }
320 
323  desc.add<edm::InputTag>("PhoInput", edm::InputTag("gedPhotons"));
324  desc.add<edm::InputTag>("PFjetInput", edm::InputTag("ak4PFJetsCHS"));
325  desc.add<edm::InputTag>("HBHEInput", edm::InputTag("hbhereco"));
326  desc.add<edm::InputTag>("HFInput", edm::InputTag("hfreco"));
327  desc.add<edm::InputTag>("HOInput", edm::InputTag("horeco"));
328  desc.add<edm::InputTag>("METInput", edm::InputTag("pfMet"));
329  desc.add<edm::InputTag>("TriggerResults", edm::InputTag("TriggerResults::HLT"));
330  desc.add<edm::InputTag>("gsfeleInput", edm::InputTag("gedGsfElectrons"));
331  desc.add<edm::InputTag>("particleFlowInput", edm::InputTag("particleFlow"));
332  desc.add<edm::InputTag>("VertexInput", edm::InputTag("offlinePrimaryVertices"));
333  desc.add<edm::InputTag>("ConversionsInput", edm::InputTag("allConversions"));
334  desc.add<edm::InputTag>("rhoInput", edm::InputTag("fixedGridRhoFastjetAll"));
335  desc.add<edm::InputTag>("BeamSpotInput", edm::InputTag("offlineBeamSpot"));
336  desc.add<edm::InputTag>("PhoLoose", edm::InputTag("PhotonIDProdGED", "PhotonCutBasedIDLoose"));
337  desc.add<edm::InputTag>("PhoTight", edm::InputTag("PhotonIDProdGED", "PhotonCutBasedIDTight"));
338  desc.add<double>("MinPtJet", 10.0);
339  desc.add<double>("MinPtPhoton", 10.0);
340  descriptions.add("alcaGammaJetProducer", desc);
341 }
342 
Log< level::Info, true > LogVerbatim
~AlCaGammaJetProducer() override=default
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDPutTokenT< double > put_rho_
std::string encode() const
Definition: InputTag.cc:159
edm::EDPutTokenT< std::vector< Bool_t > > put_tightPhot_
edm::EDPutTokenT< reco::PhotonCollection > put_photon_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< edm::ValueMap< Bool_t > > tok_tightPhoton_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< reco::BeamSpot > tok_BS_
bool accept(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
Definition: TopDQMHelpers.h:31
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
edm::EDGetTokenT< edm::SortedCollection< HBHERecHit, edm::StrictWeakOrdering< HBHERecHit > > > tok_HBHE_
int iEvent
Definition: GenABIO.cc:224
AlCaGammaJetProducer(const edm::ParameterSet &)
edm::EDPutTokenT< edm::SortedCollection< HBHERecHit, edm::StrictWeakOrdering< HBHERecHit > > > put_hbhe_
edm::EDGetTokenT< reco::VertexCollection > tok_Vertex_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDPutTokenT< edm::SortedCollection< HORecHit, edm::StrictWeakOrdering< HORecHit > > > put_ho_
bool select(const reco::PhotonCollection &, const reco::PFJetCollection &) const
edm::EDPutTokenT< edm::SortedCollection< HFRecHit, edm::StrictWeakOrdering< HFRecHit > > > put_hf_
edm::EDPutTokenT< reco::PFJetCollection > put_pfJet_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< edm::SortedCollection< HFRecHit, edm::StrictWeakOrdering< HFRecHit > > > tok_HF_
edm::EDGetTokenT< double > tok_Rho_
edm::EDPutTokenT< std::vector< Bool_t > > put_loosePhot_
edm::EDGetTokenT< reco::PFJetCollection > tok_PFJet_
edm::EDPutTokenT< edm::TriggerResults > put_trigger_
edm::EDPutTokenT< reco::BeamSpot > put_beamSpot_
edm::EDPutTokenT< reco::VertexCollection > put_vertex_
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
void add(std::string const &label, ParameterSetDescription const &psetDescription)
EPOS::IO_EPOS conv
edm::EDGetTokenT< reco::PFMETCollection > tok_PFMET_
edm::EDPutTokenT< reco::GsfElectronCollection > put_gsfEle_
edm::EDGetTokenT< reco::ConversionCollection > tok_Conv_
edm::EDPutTokenT< reco::PFCandidateCollection > put_pfCandidate_
edm::EDPutTokenT< reco::ConversionCollection > put_conv_
edm::EDGetTokenT< edm::TriggerResults > tok_TrigRes_
std::vector< PFJet > PFJetCollection
collection of PFJet objects
std::vector< reco::PFMET > PFMETCollection
collection of PFMET objects
edm::EDGetTokenT< edm::SortedCollection< HORecHit, edm::StrictWeakOrdering< HORecHit > > > tok_HO_
edm::EDGetTokenT< reco::GsfElectronCollection > tok_GsfElec_
edm::EDGetTokenT< reco::PhotonCollection > tok_Photon_
Log< level::Warning, false > LogWarning
edm::EDGetTokenT< edm::ValueMap< Bool_t > > tok_loosePhoton_
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::PFCandidateCollection > tok_PFCand_
edm::EDPutTokenT< reco::PFMETCollection > put_pfMET_