CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PATPhotonProducer.cc
Go to the documentation of this file.
1 
46 
47 namespace pat {
48 
50  public:
52  ~PATPhotonProducer() override;
53 
54  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58  private:
59  // configurables
64 
70 
75 
77 
82 
85  std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>> genMatchTokens_;
86 
87  // tools
89 
90  typedef std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> IsoDepositMaps;
91  typedef std::vector<edm::Handle<edm::ValueMap<double>>> IsolationValueMaps;
92  typedef std::pair<pat::IsolationKeys, edm::InputTag> IsolationLabel;
93  typedef std::vector<IsolationLabel> IsolationLabels;
94 
96  pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_; // better here than recreate at each event
97  std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit>>> isoDepositTokens_;
98  std::vector<edm::EDGetTokenT<edm::ValueMap<double>>> isolationValueTokens_;
99 
102 
105  template <typename T>
106  void readIsolationLabels(const edm::ParameterSet& iConfig,
107  const char* psetName,
110 
113 
116 
118  typedef std::pair<std::string, edm::InputTag> NameTag;
119  std::vector<NameTag> photIDSrcs_;
120  std::vector<edm::EDGetTokenT<edm::ValueMap<Bool_t>>> photIDTokens_;
121 
123  //PUPPI isolation tokens
128 
131 
133 
136  };
137 
138 } // namespace pat
139 
140 template <typename T>
142  const char* psetName,
145  labels.clear();
146 
147  if (iConfig.exists(psetName)) {
148  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>(psetName);
149 
150  if (depconf.exists("tracker"))
151  labels.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
152  if (depconf.exists("ecal"))
153  labels.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
154  if (depconf.exists("hcal"))
155  labels.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
156  if (depconf.exists("pfAllParticles")) {
157  labels.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
158  }
159  if (depconf.exists("pfChargedHadrons")) {
160  labels.push_back(
161  std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons")));
162  }
163  if (depconf.exists("pfChargedAll")) {
164  labels.push_back(std::make_pair(pat::PfChargedAllIso, depconf.getParameter<edm::InputTag>("pfChargedAll")));
165  }
166  if (depconf.exists("pfPUChargedHadrons")) {
167  labels.push_back(
168  std::make_pair(pat::PfPUChargedHadronIso, depconf.getParameter<edm::InputTag>("pfPUChargedHadrons")));
169  }
170  if (depconf.exists("pfNeutralHadrons")) {
171  labels.push_back(
172  std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons")));
173  }
174  if (depconf.exists("pfPhotons")) {
175  labels.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons")));
176  }
177  if (depconf.exists("user")) {
178  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
179  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
181  for (; it != ed; ++it, ++key) {
182  labels.push_back(std::make_pair(pat::IsolationKeys(key), *it));
183  }
184  }
185 
186  tokens = edm::vector_transform(
187  labels, [this](IsolationLabel const& label) { return consumes<edm::ValueMap<T>>(label.second); });
188  }
189  tokens = edm::vector_transform(
190  labels, [this](IsolationLabel const& label) { return consumes<edm::ValueMap<T>>(label.second); });
191 }
192 
193 using namespace pat;
194 
196  :
197 
198  ecalClusterToolsESGetTokens_{consumesCollector()},
199  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation")
200  : edm::ParameterSet(),
201  consumesCollector(),
202  false),
203  useUserData_(iConfig.exists("userData")),
204  ecalTopologyToken_{esConsumes()},
205  ecalGeometryToken_{esConsumes()} {
206  // initialize the configurables
207  photonToken_ = consumes<edm::View<reco::Photon>>(iConfig.getParameter<edm::InputTag>("photonSource"));
208  electronToken_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electronSource"));
209  hConversionsToken_ = consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionSource"));
210  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
211  embedSuperCluster_ = iConfig.getParameter<bool>("embedSuperCluster");
212  embedSeedCluster_ = iConfig.getParameter<bool>("embedSeedCluster");
213  embedBasicClusters_ = iConfig.getParameter<bool>("embedBasicClusters");
214  embedPreshowerClusters_ = iConfig.getParameter<bool>("embedPreshowerClusters");
215  embedRecHits_ = iConfig.getParameter<bool>("embedRecHits");
216  reducedBarrelRecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection");
217  reducedBarrelRecHitCollectionToken_ = mayConsume<EcalRecHitCollection>(reducedBarrelRecHitCollection_);
218  reducedEndcapRecHitCollection_ = iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection");
219  reducedEndcapRecHitCollectionToken_ = mayConsume<EcalRecHitCollection>(reducedEndcapRecHitCollection_);
220  // MC matching configurables
221  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
222  if (addGenMatch_) {
223  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
224  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
225  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection>>(
226  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
227  } else {
228  genMatchTokens_ = edm::vector_transform(
229  iConfig.getParameter<std::vector<edm::InputTag>>("genParticleMatch"),
230  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
231  }
232  }
233  // Efficiency configurables
234  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
235  if (addEfficiencies_) {
236  efficiencyLoader_ =
237  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
238  }
239  // PFCluster Isolation maps
240  addPuppiIsolation_ = iConfig.getParameter<bool>("addPuppiIsolation");
241  if (addPuppiIsolation_) {
242  PUPPIIsolation_charged_hadrons_ =
243  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
244  PUPPIIsolation_neutral_hadrons_ =
245  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
246  PUPPIIsolation_photons_ =
247  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
248  }
249  addPFClusterIso_ = iConfig.getParameter<bool>("addPFClusterIso");
250  if (addPFClusterIso_) {
251  ecalPFClusterIsoT_ = consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("ecalPFClusterIsoMap"));
252  auto hcPFC = iConfig.getParameter<edm::InputTag>("hcalPFClusterIsoMap");
253  if (not hcPFC.label().empty())
254  hcalPFClusterIsoT_ = consumes<edm::ValueMap<float>>(hcPFC);
255  }
256 
257  // photon ID configurables
258  addPhotonID_ = iConfig.getParameter<bool>("addPhotonID");
259  if (addPhotonID_) {
260  // it might be a single photon ID
261  if (iConfig.existsAs<edm::InputTag>("photonIDSource")) {
262  photIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("photonIDSource")));
263  }
264  // or there might be many of them
265  if (iConfig.existsAs<edm::ParameterSet>("photonIDSources")) {
266  // please don't configure me twice
267  if (!photIDSrcs_.empty()) {
268  throw cms::Exception("Configuration")
269  << "PATPhotonProducer: you can't specify both 'photonIDSource' and 'photonIDSources'\n";
270  }
271  // read the different photon ID names
272  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("photonIDSources");
273  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
274  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
275  photIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
276  }
277  }
278  // but in any case at least once
279  if (photIDSrcs_.empty())
280  throw cms::Exception("Configuration") << "PATPhotonProducer: id addPhotonID is true, you must specify either:\n"
281  << "\tInputTag photonIDSource = <someTag>\n"
282  << "or\n"
283  << "\tPSet photonIDSources = { \n"
284  << "\t\tInputTag <someName> = <someTag> // as many as you want \n "
285  << "\t}\n";
286  }
287  photIDTokens_ = edm::vector_transform(
288  photIDSrcs_, [this](NameTag const& tag) { return mayConsume<edm::ValueMap<Bool_t>>(tag.second); });
289  // Resolution configurables
290  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
291  if (addResolutions_) {
292  resolutionLoader_ =
293  pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"), consumesCollector());
294  }
295  // Check to see if the user wants to add user data
296  if (useUserData_) {
297  userDataHelper_ =
298  PATUserDataHelper<Photon>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
299  }
300  // produces vector of photons
301  produces<std::vector<Photon>>();
302 
303  // read isoDeposit labels, for direct embedding
304  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
305  // read isolation value labels, for direct embedding
306  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_, isolationValueTokens_);
307 
308  saveRegressionData_ = iConfig.getParameter<bool>("saveRegressionData");
309 }
310 
311 PATPhotonProducer::~PATPhotonProducer() {}
312 
314  // switch off embedding (in unschedules mode)
315  if (iEvent.isRealData()) {
316  addGenMatch_ = false;
317  embedGenMatch_ = false;
318  }
319 
322 
323  // Get the vector of Photon's from the event
325  iEvent.getByToken(photonToken_, photons);
326 
327  // for conversion veto selection
329  iEvent.getByToken(hConversionsToken_, hConversions);
330 
331  // Get the collection of electrons from the event
333  iEvent.getByToken(electronToken_, hElectrons);
334 
335  // Get the beamspot
336  edm::Handle<reco::BeamSpot> beamSpotHandle;
337  iEvent.getByToken(beamLineToken_, beamSpotHandle);
338 
339  EcalClusterLazyTools lazyTools(iEvent,
343 
344  // prepare the MC matching
345  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(genMatchTokens_.size());
346  if (addGenMatch_) {
347  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
348  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
349  }
350  }
351 
352  if (isolator_.enabled())
353  isolator_.beginEvent(iEvent, iSetup);
354 
356  efficiencyLoader_.newEvent(iEvent);
358  resolutionLoader_.newEvent(iEvent, iSetup);
359 
360  IsoDepositMaps deposits(isoDepositTokens_.size());
361  for (size_t j = 0, nd = isoDepositTokens_.size(); j < nd; ++j) {
362  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
363  }
364 
365  IsolationValueMaps isolationValues(isolationValueTokens_.size());
366  for (size_t j = 0; j < isolationValueTokens_.size(); ++j) {
367  iEvent.getByToken(isolationValueTokens_[j], isolationValues[j]);
368  }
369 
370  // prepare ID extraction
371  std::vector<edm::Handle<edm::ValueMap<Bool_t>>> idhandles;
372  std::vector<pat::Photon::IdPair> ids;
373  if (addPhotonID_) {
374  idhandles.resize(photIDSrcs_.size());
375  ids.resize(photIDSrcs_.size());
376  for (size_t i = 0; i < photIDSrcs_.size(); ++i) {
377  iEvent.getByToken(photIDTokens_[i], idhandles[i]);
378  ids[i].first = photIDSrcs_[i].first;
379  }
380  }
381 
382  //value maps for puppi isolation
383  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
384  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
385  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
386  if (addPuppiIsolation_) {
387  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
388  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
389  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
390  }
391 
392  // loop over photons
393  std::vector<Photon>* PATPhotons = new std::vector<Photon>();
394  for (edm::View<reco::Photon>::const_iterator itPhoton = photons->begin(); itPhoton != photons->end(); itPhoton++) {
395  // construct the Photon from the ref -> save ref to original object
396  unsigned int idx = itPhoton - photons->begin();
397  edm::RefToBase<reco::Photon> photonRef = photons->refAt(idx);
398  edm::Ptr<reco::Photon> photonPtr = photons->ptrAt(idx);
399  Photon aPhoton(photonRef);
400  auto phoPtr = photons->ptrAt(idx);
401  if (embedSuperCluster_)
402  aPhoton.embedSuperCluster();
403  if (embedSeedCluster_)
404  aPhoton.embedSeedCluster();
406  aPhoton.embedBasicClusters();
408  aPhoton.embedPreshowerClusters();
409 
410  std::vector<DetId> selectedCells;
411  bool barrel = itPhoton->isEB();
412  //loop over sub clusters
413  if (embedBasicClusters_) {
414  for (reco::CaloCluster_iterator clusIt = itPhoton->superCluster()->clustersBegin();
415  clusIt != itPhoton->superCluster()->clustersEnd();
416  ++clusIt) {
417  //get seed (max energy xtal)
418  DetId seed = lazyTools.getMaximum(**clusIt).first;
419  //get all xtals in 5x5 window around the seed
420  std::vector<DetId> dets5x5 =
423  selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
424 
425  //get all xtals belonging to cluster
426  for (const std::pair<DetId, float>& hit : (*clusIt)->hitsAndFractions()) {
427  selectedCells.push_back(hit.first);
428  }
429  }
430  }
431 
432  //remove duplicates
433  std::sort(selectedCells.begin(), selectedCells.end());
434  std::unique(selectedCells.begin(), selectedCells.end());
435 
436  // Retrieve the corresponding RecHits
437 
438  edm::Handle<EcalRecHitCollection> recHitsEBHandle;
439  iEvent.getByToken(reducedBarrelRecHitCollectionToken_, recHitsEBHandle);
440  edm::Handle<EcalRecHitCollection> recHitsEEHandle;
441  iEvent.getByToken(reducedEndcapRecHitCollectionToken_, recHitsEEHandle);
442 
443  //orginal code would throw an exception via the handle not being valid but now it'll just have a null pointer error
444  //should have little effect, if its not barrel or endcap, something very bad has happened elsewhere anyways
445  const EcalRecHitCollection* recHits = nullptr;
446  if (photonRef->superCluster()->seed()->hitsAndFractions().at(0).first.subdetId() == EcalBarrel)
447  recHits = recHitsEBHandle.product();
448  else if (photonRef->superCluster()->seed()->hitsAndFractions().at(0).first.subdetId() == EcalEndcap)
449  recHits = recHitsEEHandle.product();
450 
451  EcalRecHitCollection selectedRecHits;
452 
453  unsigned nSelectedCells = selectedCells.size();
454  for (unsigned icell = 0; icell < nSelectedCells; ++icell) {
455  EcalRecHitCollection::const_iterator it = recHits->find(selectedCells[icell]);
456  if (it != recHits->end()) {
457  selectedRecHits.push_back(*it);
458  }
459  }
460  selectedRecHits.sort();
461  if (embedRecHits_)
462  aPhoton.embedRecHits(&selectedRecHits);
463 
464  // store the match to the generated final state muons
465  if (addGenMatch_) {
466  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
467  reco::GenParticleRef genPhoton = (*genMatches[i])[photonRef];
468  aPhoton.addGenParticleRef(genPhoton);
469  }
470  if (embedGenMatch_)
471  aPhoton.embedGenParticle();
472  }
473 
474  if (efficiencyLoader_.enabled()) {
475  efficiencyLoader_.setEfficiencies(aPhoton, photonRef);
476  }
477 
478  if (resolutionLoader_.enabled()) {
480  }
481 
482  // here comes the extra functionality
483  if (isolator_.enabled()) {
484  isolator_.fill(*photons, idx, isolatorTmpStorage_);
485  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
486  // better to loop backwards, so the vector is resized less times
487  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
488  ed = isolatorTmpStorage_.rend();
489  it != ed;
490  ++it) {
491  aPhoton.setIsolation(it->first, it->second);
492  }
493  }
494 
495  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
496  aPhoton.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[photonRef]);
497  }
498 
499  for (size_t j = 0; j < isolationValues.size(); ++j) {
500  aPhoton.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[photonRef]);
501  }
502 
503  // add photon ID info
504  if (addPhotonID_) {
505  for (size_t i = 0; i < photIDSrcs_.size(); ++i) {
506  ids[i].second = (*idhandles[i])[photonRef];
507  }
508  aPhoton.setPhotonIDs(ids);
509  }
510 
511  if (useUserData_) {
512  userDataHelper_.add(aPhoton, iEvent, iSetup);
513  }
514 
515  // set conversion veto selection
516  bool passelectronveto = false;
517  if (hConversions.isValid()) {
518  // this is recommended method
519  passelectronveto = !ConversionTools::hasMatchedPromptElectron(
520  photonRef->superCluster(), *hElectrons, *hConversions, beamSpotHandle->position());
521  }
522  aPhoton.setPassElectronVeto(passelectronveto);
523 
524  // set electron veto using pixel seed (not recommended but many analysis groups are still using since it is powerful method to remove electrons)
525  aPhoton.setHasPixelSeed(photonRef->hasPixelSeed());
526 
527  // set seed energy
528  aPhoton.setSeedEnergy(photonRef->superCluster()->seed()->energy());
529 
530  // set input variables for regression energy correction
531  if (saveRegressionData_) {
532  EcalRegressionData ecalRegData;
533  ecalRegData.fill(*(photonRef->superCluster()),
534  recHitsEBHandle.product(),
535  recHitsEEHandle.product(),
538  -1);
539 
540  aPhoton.setEMax(ecalRegData.eMax());
541  aPhoton.setE2nd(ecalRegData.e2nd());
542  aPhoton.setE3x3(ecalRegData.e3x3());
543  aPhoton.setETop(ecalRegData.eTop());
544  aPhoton.setEBottom(ecalRegData.eBottom());
545  aPhoton.setELeft(ecalRegData.eLeft());
546  aPhoton.setERight(ecalRegData.eRight());
547  aPhoton.setSee(ecalRegData.sigmaIEtaIEta());
548  aPhoton.setSep(
549  ecalRegData.sigmaIEtaIPhi() * ecalRegData.sigmaIEtaIEta() *
550  ecalRegData
551  .sigmaIPhiIPhi()); //there is a conflict on what sigmaIEtaIPhi actually is, regression and ID have it differently, this may change in later releases
552  aPhoton.setSpp(ecalRegData.sigmaIPhiIPhi());
553 
554  aPhoton.setMaxDR(ecalRegData.maxSubClusDR());
555  aPhoton.setMaxDRDPhi(ecalRegData.maxSubClusDRDPhi());
556  aPhoton.setMaxDRDEta(ecalRegData.maxSubClusDRDEta());
557  aPhoton.setMaxDRRawEnergy(ecalRegData.maxSubClusDRRawEnergy());
567 
568  aPhoton.setCryPhi(ecalRegData.seedCrysPhiOrY());
569  aPhoton.setCryEta(ecalRegData.seedCrysEtaOrX());
570  aPhoton.setIEta(ecalRegData.seedCrysIEtaOrIX());
571  aPhoton.setIPhi(ecalRegData.seedCrysIPhiOrIY());
572  } else {
573  aPhoton.setEMax(0);
574  aPhoton.setE2nd(0);
575  aPhoton.setE3x3(0);
576  aPhoton.setETop(0);
577  aPhoton.setEBottom(0);
578  aPhoton.setELeft(0);
579  aPhoton.setERight(0);
580  aPhoton.setSee(0);
581  aPhoton.setSep(0);
582  aPhoton.setSpp(0);
583 
584  aPhoton.setMaxDR(0);
585  aPhoton.setMaxDRDPhi(0);
586  aPhoton.setMaxDRDEta(0);
587  aPhoton.setMaxDRRawEnergy(0);
588  aPhoton.setSubClusRawE1(0);
589  aPhoton.setSubClusRawE2(0);
590  aPhoton.setSubClusRawE3(0);
591  aPhoton.setSubClusDPhi1(0);
592  aPhoton.setSubClusDPhi2(0);
593  aPhoton.setSubClusDPhi3(0);
594  aPhoton.setSubClusDEta1(0);
595  aPhoton.setSubClusDEta2(0);
596  aPhoton.setSubClusDEta3(0);
597 
598  aPhoton.setCryPhi(0);
599  aPhoton.setCryEta(0);
600  aPhoton.setIEta(0);
601  aPhoton.setIPhi(0);
602  }
603 
604  if (addPuppiIsolation_)
605  aPhoton.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[phoPtr],
606  (*PUPPIIsolation_neutral_hadrons)[phoPtr],
607  (*PUPPIIsolation_photons)[phoPtr]);
608  else
609  aPhoton.setIsolationPUPPI(-999., -999., -999.);
610 
611  // Get PFCluster Isolation
612  if (addPFClusterIso_) {
614  edm::Handle<edm::ValueMap<float>> ecalPFClusterIsoMapH;
615  iEvent.getByToken(ecalPFClusterIsoT_, ecalPFClusterIsoMapH);
616  newPFIsol.sumEcalClusterEt = (*ecalPFClusterIsoMapH)[photonRef];
617  edm::Handle<edm::ValueMap<float>> hcalPFClusterIsoMapH;
619  iEvent.getByToken(hcalPFClusterIsoT_, hcalPFClusterIsoMapH);
620  newPFIsol.sumHcalClusterEt = (*hcalPFClusterIsoMapH)[photonRef];
621  } else {
622  newPFIsol.sumHcalClusterEt = -999.;
623  }
624  aPhoton.setPflowIsolationVariables(newPFIsol);
625  }
626 
627  // add the Photon to the vector of Photons
628  PATPhotons->push_back(aPhoton);
629  }
630 
631  // sort Photons in ET
632  std::sort(PATPhotons->begin(), PATPhotons->end(), eTComparator_);
633 
634  // put genEvt object in Event
635  std::unique_ptr<std::vector<Photon>> myPhotons(PATPhotons);
636  iEvent.put(std::move(myPhotons));
637  if (isolator_.enabled())
639 }
640 
641 // ParameterSet description for module
644  iDesc.setComment("PAT photon producer module");
645 
646  // input source
647  iDesc.add<edm::InputTag>("photonSource", edm::InputTag("no default"))->setComment("input collection");
648  iDesc.add<edm::InputTag>("electronSource", edm::InputTag("no default"))->setComment("input collection");
649  iDesc.add<edm::InputTag>("conversionSource", edm::InputTag("allConversions"))->setComment("input collection");
650 
651  iDesc.add<edm::InputTag>("reducedBarrelRecHitCollection", edm::InputTag("reducedEcalRecHitsEB"));
652  iDesc.add<edm::InputTag>("reducedEndcapRecHitCollection", edm::InputTag("reducedEcalRecHitsEE"));
653 
654  iDesc.ifValue(
655  edm::ParameterDescription<bool>("addPFClusterIso", false, true),
657  "ecalPFClusterIsoMap", edm::InputTag("photonEcalPFClusterIsolationProducer"), true) and
659  "hcalPFClusterIsoMap", edm::InputTag("photonHcalPFClusterIsolationProducer"), true)) or
660  false >> (edm::ParameterDescription<edm::InputTag>("ecalPFClusterIsoMap", edm::InputTag(""), true) and
661  edm::ParameterDescription<edm::InputTag>("hcalPFClusterIsoMap", edm::InputTag(""), true)));
662 
663  iDesc.ifValue(
664  edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
666  "puppiIsolationChargedHadrons", edm::InputTag("egmPhotonPUPPIIsolation", "h+-DR030-"), true) and
668  "puppiIsolationNeutralHadrons", edm::InputTag("egmPhotonPUPPIIsolation", "h0-DR030-"), true) and
670  "puppiIsolationPhotons", edm::InputTag("egmPhotonPUPPIIsolation", "gamma-DR030-"), true)) or
671  false >> edm::EmptyGroupDescription());
672 
673  iDesc.add<bool>("embedSuperCluster", true)->setComment("embed external super cluster");
674  iDesc.add<bool>("embedSeedCluster", true)->setComment("embed external seed cluster");
675  iDesc.add<bool>("embedBasicClusters", true)->setComment("embed external basic clusters");
676  iDesc.add<bool>("embedPreshowerClusters", true)->setComment("embed external preshower clusters");
677  iDesc.add<bool>("embedRecHits", true)->setComment("embed external RecHits");
678 
679  // MC matching configurables
680  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
681  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
682  std::vector<edm::InputTag> emptySourceVector;
683  iDesc
684  .addNode(edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
685  edm::ParameterDescription<std::vector<edm::InputTag>>("genParticleMatch", emptySourceVector, true))
686  ->setComment("input with MC match information");
687 
689 
690  // photon ID configurables
691  iDesc.add<bool>("addPhotonID", true)->setComment("add photon ID variables");
692  edm::ParameterSetDescription photonIDSourcesPSet;
693  photonIDSourcesPSet.setAllowAnything();
694  iDesc
695  .addNode(edm::ParameterDescription<edm::InputTag>("photonIDSource", edm::InputTag(), true) xor
696  edm::ParameterDescription<edm::ParameterSetDescription>("photonIDSources", photonIDSourcesPSet, true))
697  ->setComment("input with photon ID variables");
698 
699  // IsoDeposit configurables
700  edm::ParameterSetDescription isoDepositsPSet;
701  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
702  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
703  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
704  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
705  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
706  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
707  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
708  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
709  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
710  isoDepositsPSet.addOptional<std::vector<edm::InputTag>>("user");
711  iDesc.addOptional("isoDeposits", isoDepositsPSet);
712 
713  // isolation values configurables
714  edm::ParameterSetDescription isolationValuesPSet;
715  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
716  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
717  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
718  isolationValuesPSet.addOptional<edm::InputTag>("pfAllParticles");
719  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
720  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
721  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
722  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
723  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
724  isolationValuesPSet.addOptional<std::vector<edm::InputTag>>("user");
725  iDesc.addOptional("isolationValues", isolationValuesPSet);
726 
727  // Efficiency configurables
728  edm::ParameterSetDescription efficienciesPSet;
729  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
730  iDesc.add("efficiencies", efficienciesPSet);
731  iDesc.add<bool>("addEfficiencies", false);
732 
733  // Check to see if the user wants to add user data
734  edm::ParameterSetDescription userDataPSet;
736  iDesc.addOptional("userData", userDataPSet);
737 
738  edm::ParameterSetDescription isolationPSet;
739  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
740  iDesc.add("userIsolation", isolationPSet);
741 
742  iDesc.addNode(edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true))
743  ->setComment("input with high level selection");
744 
745  iDesc.add<bool>("saveRegressionData", true)->setComment("save regression input variables");
746 
747  descriptions.add("PATPhotonProducer", iDesc);
748 }
749 
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
float sigmaIPhiIPhi() const
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
Definition: Photon.h:560
void setSpp(float s)
Definition: Photon.h:266
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases)
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
const std::vector< float > & subClusRawEnergy() const
Analysis-level Photon class.
Definition: Photon.h:46
void setIEta(float i)
Definition: Photon.h:308
pat::PATUserDataHelper< pat::Photon > userDataHelper_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
float maxSubClusDRRawEnergy() const
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
float maxSubClusDRDEta() const
edm::EDGetTokenT< EcalRecHitCollection > reducedEndcapRecHitCollectionToken_
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps
void setSubClusDPhi3(float s)
Definition: Photon.h:291
std::pair< std::string, edm::InputTag > NameTag
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels, std::vector< edm::EDGetTokenT< edm::ValueMap< T >>> &tokens)
void setE2nd(float e)
Definition: Photon.h:251
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
void setAllowAnything()
allow any parameter label/value pairs
void setSee(float s)
Definition: Photon.h:264
std::vector< edm::EDGetTokenT< edm::ValueMap< Bool_t > > > photIDTokens_
void fill(const reco::SuperCluster &superClus, const EcalRecHitCollection *ebRecHits, const EcalRecHitCollection *eeRecHits, const CaloGeometry *geom, const CaloTopology *topology, const reco::VertexCollection *vertices)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setMaxDRRawEnergy(float m)
Definition: Photon.h:277
static bool hasMatchedPromptElectron(const reco::SuperClusterRef &sc, const reco::GsfElectronCollection &eleCol, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
void embedSeedCluster()
method to store the electron&#39;s seedcluster internally
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
edm::EDGetTokenT< edm::View< reco::Photon > > photonToken_
def unique
Definition: tier0.py:24
std::vector< EcalRecHit >::const_iterator const_iterator
bool exists(std::string const &parameterName) const
checks if a parameter exists
void setSubClusDPhi2(float s)
Definition: Photon.h:289
float eLeft() const
edm::EDGetTokenT< edm::ValueMap< float > > ecalPFClusterIsoT_
void push_back(T const &t)
float seedCrysPhiOrY() const
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
void embedRecHits(const EcalRecHitCollection *rechits)
method to store the RecHits internally - can be called from the PATElectronProducer ...
void setIsolationPUPPI(float chargedhadrons_, float neutralhadrons_, float photons_)
Sets PUPPI isolation.
Definition: Photon.h:193
pat::helper::KinResolutionsLoader resolutionLoader_
float sigmaIEtaIEta() const
edm::EDGetTokenT< edm::ValueMap< float > > hcalPFClusterIsoT_
GreaterByEt< Photon > eTComparator_
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
const CaloGeometry * ecalGeometry_
float sigmaIEtaIPhi() const
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
void setIPhi(float i)
Definition: Photon.h:306
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
bool isRealData() const
Definition: EventBase.h:62
const std::string names[nVars_]
edm::InputTag reducedEndcapRecHitCollection_
std::vector< IsolationLabel > IsolationLabels
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
static void fillDescription(edm::ParameterSetDescription &iDesc)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
bool getData(T &iHolder) const
Definition: EventSetup.h:122
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:55
IsolationLabels isoDepositLabels_
char const * label
void setIsolation(IsolationKeys key, float value)
Definition: Photon.h:171
void setComment(std::string const &value)
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void setELeft(float e)
Definition: Photon.h:259
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Photon.h:217
int iEvent
Definition: GenABIO.cc:224
void setEMax(float e)
Definition: Photon.h:249
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
const CaloTopology * ecalTopology_
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
void setERight(float e)
Definition: Photon.h:261
float seedCrysIPhiOrIY() const
IsolationLabels isolationValueLabels_
void setMaxDRDEta(float m)
Definition: Photon.h:275
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
void embedGenParticle()
Definition: PATObject.h:768
pat::helper::EfficiencyLoader efficiencyLoader_
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
float maxSubClusDR() const
void setPhotonIDs(const std::vector< IdPair > &ids)
Definition: Photon.h:106
float seedCrysIEtaOrIX() const
def move
Definition: eostools.py:511
void embedBasicClusters()
method to store the electron&#39;s basic clusters
tuple key
prepare the HTCondor submission files and eventually submit them
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_photons_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void setPassElectronVeto(bool flag)
Definition: Photon.h:239
void setETop(float e)
Definition: Photon.h:255
float maxSubClusDRDPhi() const
void setSeedEnergy(float e)
Definition: Photon.h:246
void setSubClusDPhi1(float s)
Definition: Photon.h:287
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< NameTag > photIDSrcs_
bool isValid() const
Definition: HandleBase.h:70
void setSubClusDEta1(float s)
Definition: Photon.h:294
pat::helper::MultiIsolator isolator_
float seedCrysEtaOrX() const
void embedPreshowerClusters()
method to store the electron&#39;s preshower clusters
void setCryEta(float c)
Definition: Photon.h:303
const_iterator end() const
void embedSuperCluster()
method to store the photon&#39;s supercluster internally
Definition: DetId.h:17
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
ESData get(edm::EventSetup const &eventSetup) const
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:751
void setCryPhi(float c)
Definition: Photon.h:301
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
void setHasPixelSeed(bool flag)
Definition: Photon.h:242
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_charged_hadrons_
T const * product() const
Definition: Handle.h:70
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
void setSubClusDEta2(float s)
Definition: Photon.h:296
void setMaxDR(float m)
Definition: Photon.h:271
bool hasPixelSeed() const
Bool flagging photons having a non-zero size vector of Ref to electornPixel seeds.
Definition: Photon.h:79
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
void setSubClusRawE2(float s)
Definition: Photon.h:282
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:17
const std::vector< float > & subClusDEta() const
void setEBottom(float e)
Definition: Photon.h:257
void setMaxDRDPhi(float m)
Definition: Photon.h:273
iterator find(key_type k)
const std::vector< float > & subClusDPhi() const
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
void setSubClusDEta3(float s)
Definition: Photon.h:298
size_type size() const
const edm::ESGetToken< CaloTopology, CaloTopologyRecord > ecalTopologyToken_
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
float eRight() const
void setSubClusRawE1(float s)
Definition: Photon.h:280
std::pair< pat::IsolationKeys, edm::InputTag > IsolationLabel
PATPhotonProducer(const edm::ParameterSet &iConfig)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > ecalGeometryToken_
void setSubClusRawE3(float s)
Definition: Photon.h:284
edm::EDGetTokenT< EcalRecHitCollection > reducedBarrelRecHitCollectionToken_
const PflowIsolationVariables & getPflowIsolationVariables() const
Get Particle Flow Isolation variables block.
Definition: Photon.h:557
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
edm::InputTag reducedBarrelRecHitCollection_
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void setE3x3(float e)
Definition: Photon.h:253
float eBottom() const
edm::EDGetTokenT< reco::ConversionCollection > hConversionsToken_
void setSep(float s)
Definition: Photon.h:268
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:84
Produces the pat::Photon.
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_