CMS 3D CMS Logo

PATTauProducer.cc
Go to the documentation of this file.
2 
8 
14 
20 
23 
24 #include <vector>
25 #include <memory>
26 
27 using namespace pat;
28 
30  : isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation")
31  : edm::ParameterSet(),
32  consumesCollector(),
33  false),
34  useUserData_(iConfig.exists("userData")) {
35  firstOccurence_ = true;
36  // initialize the configurables
37  baseTauToken_ = consumes<edm::View<reco::BaseTau>>(iConfig.getParameter<edm::InputTag>("tauSource"));
38  tauTransverseImpactParameterSrc_ = iConfig.getParameter<edm::InputTag>("tauTransverseImpactParameterSource");
39  tauTransverseImpactParameterToken_ = consumes<PFTauTIPAssociationByRef>(tauTransverseImpactParameterSrc_);
40  pfTauToken_ = consumes<reco::PFTauCollection>(iConfig.getParameter<edm::InputTag>("tauSource"));
41  embedIsolationTracks_ = iConfig.getParameter<bool>("embedIsolationTracks");
42  embedLeadTrack_ = iConfig.getParameter<bool>("embedLeadTrack");
43  embedSignalTracks_ = iConfig.getParameter<bool>("embedSignalTracks");
44  embedLeadPFCand_ = iConfig.getParameter<bool>("embedLeadPFCand");
45  embedLeadPFChargedHadrCand_ = iConfig.getParameter<bool>("embedLeadPFChargedHadrCand");
46  embedLeadPFNeutralCand_ = iConfig.getParameter<bool>("embedLeadPFNeutralCand");
47  embedSignalPFCands_ = iConfig.getParameter<bool>("embedSignalPFCands");
48  embedSignalPFChargedHadrCands_ = iConfig.getParameter<bool>("embedSignalPFChargedHadrCands");
49  embedSignalPFNeutralHadrCands_ = iConfig.getParameter<bool>("embedSignalPFNeutralHadrCands");
50  embedSignalPFGammaCands_ = iConfig.getParameter<bool>("embedSignalPFGammaCands");
51  embedIsolationPFCands_ = iConfig.getParameter<bool>("embedIsolationPFCands");
52  embedIsolationPFChargedHadrCands_ = iConfig.getParameter<bool>("embedIsolationPFChargedHadrCands");
53  embedIsolationPFNeutralHadrCands_ = iConfig.getParameter<bool>("embedIsolationPFNeutralHadrCands");
54  embedIsolationPFGammaCands_ = iConfig.getParameter<bool>("embedIsolationPFGammaCands");
55  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
56  if (addGenMatch_) {
57  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
58  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
60  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
61  } else {
63  iConfig.getParameter<std::vector<edm::InputTag>>("genParticleMatch"),
64  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
65  }
66  }
67  addGenJetMatch_ = iConfig.getParameter<bool>("addGenJetMatch");
68  if (addGenJetMatch_) {
69  embedGenJetMatch_ = iConfig.getParameter<bool>("embedGenJetMatch");
71  consumes<edm::Association<reco::GenJetCollection>>(iConfig.getParameter<edm::InputTag>("genJetMatch"));
72  }
73  addTauJetCorrFactors_ = iConfig.getParameter<bool>("addTauJetCorrFactors");
75  iConfig.getParameter<std::vector<edm::InputTag>>("tauJetCorrFactorsSource"),
76  [this](edm::InputTag const& tag) { return mayConsume<edm::ValueMap<TauJetCorrFactors>>(tag); });
77  // tau ID configurables
78  addTauID_ = iConfig.getParameter<bool>("addTauID");
79  if (addTauID_) {
80  // read the different tau ID names
81  edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
82  std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
83  for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
84  tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
85  }
86  // but in any case at least once
87  if (tauIDSrcs_.empty())
88  throw cms::Exception("Configuration") << "PATTauProducer: id addTauID is true, you must specify either:\n"
89  << "\tPSet tauIDSources = { \n"
90  << "\t\tInputTag <someName> = <someTag> // as many as you want \n "
91  << "\t}\n";
92  }
94  tauIDSrcs_, [this](NameTag const& tag) { return mayConsume<reco::PFTauDiscriminator>(tag.second); });
95  skipMissingTauID_ = iConfig.getParameter<bool>("skipMissingTauID");
96  // IsoDeposit configurables
97  if (iConfig.exists("isoDeposits")) {
98  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
99  if (depconf.exists("tracker"))
100  isoDepositLabels_.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
101  if (depconf.exists("ecal"))
102  isoDepositLabels_.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
103  if (depconf.exists("hcal"))
104  isoDepositLabels_.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
105  if (depconf.exists("pfAllParticles"))
106  isoDepositLabels_.push_back(
107  std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
108  if (depconf.exists("pfChargedHadron"))
109  isoDepositLabels_.push_back(
110  std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadron")));
111  if (depconf.exists("pfNeutralHadron"))
112  isoDepositLabels_.push_back(
113  std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadron")));
114  if (depconf.exists("pfGamma"))
115  isoDepositLabels_.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfGamma")));
116 
117  if (depconf.exists("user")) {
118  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
119  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
120  int key = UserBaseIso;
121  for (; it != ed; ++it, ++key) {
122  isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
123  }
124  }
125  }
127  edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys, edm::InputTag> const& label) {
128  return consumes<edm::ValueMap<IsoDeposit>>(label.second);
129  });
130  // Efficiency configurables
131  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
132  if (addEfficiencies_) {
134  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
135  }
136  // Resolution configurables
137  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
138  if (addResolutions_) {
140  }
141  // Check to see if the user wants to add user data
142  if (useUserData_) {
143  userDataHelper_ = PATUserDataHelper<Tau>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
144  }
145  // produces vector of taus
146  produces<std::vector<Tau>>();
147 }
148 
150 
152  // switch off embedding (in unschedules mode)
153  if (iEvent.isRealData()) {
154  addGenMatch_ = false;
155  embedGenMatch_ = false;
156  addGenJetMatch_ = false;
157  }
158 
159  // Get the collection of taus from the event
161  try {
162  iEvent.getByToken(baseTauToken_, anyTaus);
163  } catch (const edm::Exception& e) {
164  edm::LogWarning("DataSource") << "WARNING! No Tau collection found. This missing input will not block the job. "
165  "Instead, an empty tau collection is being be produced.";
166  auto patTaus = std::make_unique<std::vector<Tau>>();
167  iEvent.put(std::move(patTaus));
168  return;
169  }
170 
171  if (isolator_.enabled())
172  isolator_.beginEvent(iEvent, iSetup);
173 
175  efficiencyLoader_.newEvent(iEvent);
177  resolutionLoader_.newEvent(iEvent, iSetup);
178 
179  std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> deposits(isoDepositTokens_.size());
180  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
181  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
182  }
183 
184  // prepare the MC matching
185  std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(genMatchTokens_.size());
186  if (addGenMatch_) {
187  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
188  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
189  }
190  }
191 
193  if (addGenJetMatch_)
194  iEvent.getByToken(genJetMatchToken_, genJetMatch);
195 
196  // read in the jet correction factors ValueMap
197  std::vector<edm::ValueMap<TauJetCorrFactors>> tauJetCorrs;
198  if (addTauJetCorrFactors_) {
199  for (size_t i = 0; i < tauJetCorrFactorsTokens_.size(); ++i) {
201  iEvent.getByToken(tauJetCorrFactorsTokens_[i], tauJetCorr);
202  tauJetCorrs.push_back(*tauJetCorr);
203  }
204  }
205 
206  auto patTaus = std::make_unique<std::vector<Tau>>();
207 
208  bool first = true; // this is introduced to issue warnings only for the first tau-jet
209  for (size_t idx = 0, ntaus = anyTaus->size(); idx < ntaus; ++idx) {
210  edm::RefToBase<reco::BaseTau> tausRef = anyTaus->refAt(idx);
211  edm::Ptr<reco::BaseTau> tausPtr = anyTaus->ptrAt(idx);
212 
213  Tau aTau(tausRef);
214  if (embedLeadTrack_)
215  aTau.embedLeadTrack();
216  if (embedSignalTracks_)
217  aTau.embedSignalTracks();
219  aTau.embedIsolationTracks();
220  if (embedLeadPFCand_) {
221  if (aTau.isPFTau())
222  aTau.embedLeadPFCand();
223  else
224  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
225  "from a reco::PFTau is impossible.\n";
226  }
228  if (aTau.isPFTau())
230  else
231  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
232  "from a reco::PFTau is impossible.\n";
233  }
235  if (aTau.isPFTau())
236  aTau.embedLeadPFNeutralCand();
237  else
238  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
239  "from a reco::PFTau is impossible.\n";
240  }
241  if (embedSignalPFCands_) {
242  if (aTau.isPFTau())
243  aTau.embedSignalPFCands();
244  else
245  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
246  "from a reco::PFTau is impossible.\n";
247  }
249  if (aTau.isPFTau())
251  else
252  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
253  "from a reco::PFTau is impossible.\n";
254  }
256  if (aTau.isPFTau())
258  else
259  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
260  "from a reco::PFTau is impossible.\n";
261  }
263  if (aTau.isPFTau())
265  else
266  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
267  "from a reco::PFTau is impossible.\n";
268  }
270  if (aTau.isPFTau())
271  aTau.embedIsolationPFCands();
272  else
273  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
274  "from a reco::PFTau is impossible.\n";
275  }
277  if (aTau.isPFTau())
279  else
280  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
281  "from a reco::PFTau is impossible.\n";
282  }
284  if (aTau.isPFTau())
286  else
287  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
288  "from a reco::PFTau is impossible.\n";
289  }
291  if (aTau.isPFTau())
293  else
294  edm::LogWarning("Type Error") << "Embedding a PFTau-specific information into a pat::Tau which wasn't made "
295  "from a reco::PFTau is impossible.\n";
296  }
297 
298  if (addTauJetCorrFactors_) {
299  // add additional JetCorrs to the jet
300  for (unsigned int i = 0; i < tauJetCorrs.size(); ++i) {
301  const TauJetCorrFactors& tauJetCorr = tauJetCorrs[i][tausRef];
302  // uncomment for debugging
303  // tauJetCorr.print();
304  aTau.addJECFactors(tauJetCorr);
305  }
306  std::vector<std::string> levels = tauJetCorrs[0][tausRef].correctionLabels();
307  if (std::find(levels.begin(), levels.end(), "L2L3Residual") != levels.end()) {
308  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L2L3Residual"));
309  } else if (std::find(levels.begin(), levels.end(), "L3Absolute") != levels.end()) {
310  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("L3Absolute"));
311  } else {
312  aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel("Uncorrected"));
313  if (first) {
314  edm::LogWarning("L3Absolute not found")
315  << "L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
316  << "of module " << tauJetCorrs[0][tausRef].jecSet() << " jets will remain"
317  << " uncorrected.";
318  first = false;
319  }
320  }
321  }
322 
323  // store the match to the generated final state muons
324  if (addGenMatch_) {
325  for (size_t i = 0, n = genMatches.size(); i < n; ++i) {
326  reco::GenParticleRef genTau = (*genMatches[i])[tausRef];
327  aTau.addGenParticleRef(genTau);
328  }
329  if (embedGenMatch_)
330  aTau.embedGenParticle();
331  }
332 
333  // store the match to the visible part of the generated tau
334  if (addGenJetMatch_) {
335  reco::GenJetRef genJetTau = (*genJetMatch)[tausRef];
336  if (genJetTau.isNonnull() && genJetTau.isAvailable()) {
337  aTau.setGenJet(genJetTau);
338  } // leave empty if no match found
339  }
340 
341  // prepare ID extraction
342  if (addTauID_) {
343  std::string missingDiscriminators;
344  std::vector<pat::Tau::IdPair> ids(tauIDSrcs_.size());
345  auto const& tausDeref = *tausRef;
346  for (size_t i = 0; i < tauIDSrcs_.size(); ++i) {
347  if (typeid(tausDeref) == typeid(reco::PFTau)) {
348  //std::cout << "filling PFTauDiscriminator '" << tauIDSrcs_[i].first << "' into pat::Tau object..." << std::endl;
349  edm::Handle<reco::PFTauCollection> pfTauCollection;
350  iEvent.getByToken(pfTauToken_, pfTauCollection);
351 
353  iEvent.getByToken(pfTauIDTokens_[i], pfTauIdDiscr);
354 
355  if (skipMissingTauID_ && !pfTauIdDiscr.isValid()) {
356  if (!missingDiscriminators.empty()) {
357  missingDiscriminators += ", ";
358  }
359  missingDiscriminators += tauIDSrcs_[i].first;
360  continue;
361  }
362  ids[i].first = tauIDSrcs_[i].first;
363  ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
364  } else {
365  throw cms::Exception("Type Mismatch")
366  << "PATTauProducer: unsupported datatype '" << typeid(tausDeref).name() << "' for tauSource\n";
367  }
368  }
369  if (!missingDiscriminators.empty() && firstOccurence_) {
370  edm::LogWarning("DataSource") << "The following tau discriminators have not been found in the event:\n"
371  << missingDiscriminators << "\n"
372  << "They will not be embedded into the pat::Tau object.\n"
373  << "Note: this message will be printed only at first occurence.";
374  firstOccurence_ = false;
375  }
376  aTau.setTauIDs(ids);
377  }
378 
379  // extraction of reconstructed tau decay mode
380  // (only available for PFTaus)
381  if (aTau.isPFTau()) {
383  iEvent.getByToken(pfTauToken_, pfTaus);
384  reco::PFTauRef pfTauRef(pfTaus, idx);
385 
386  aTau.setDecayMode(pfTauRef->decayMode());
387  }
388 
389  // extraction of variables needed to rerun MVA isolation and anti-electron discriminator on MiniAOD
390  if (!aTau.pfEssential_.empty()) {
392  iEvent.getByToken(pfTauToken_, pfTaus);
393  reco::PFTauRef pfTauRef(pfTaus, idx);
394  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
395  float ecalEnergy = 0;
396  float hcalEnergy = 0;
397  float sumPhiTimesEnergy = 0.;
398  float sumEtaTimesEnergy = 0.;
399  float sumEnergy = 0.;
400  float leadChargedCandPt = -99;
401  float leadChargedCandEtaAtEcalEntrance = -99;
402  const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
403  for (const auto& it : signalCands) {
404  const reco::PFCandidate* icand = dynamic_cast<const reco::PFCandidate*>(it.get());
405  if (icand != nullptr) {
406  ecalEnergy += icand->ecalEnergy();
407  hcalEnergy += icand->hcalEnergy();
408  sumPhiTimesEnergy += icand->positionAtECALEntrance().phi() * icand->energy();
409  sumEtaTimesEnergy += icand->positionAtECALEntrance().eta() * icand->energy();
410  sumEnergy += icand->energy();
411  const reco::Track* track = nullptr;
412  if (icand->trackRef().isNonnull())
413  track = icand->trackRef().get();
414  else if (icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull())
415  track = icand->muonRef()->innerTrack().get();
416  else if (icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull())
417  track = icand->muonRef()->globalTrack().get();
418  else if (icand->muonRef().isNonnull() && icand->muonRef()->outerTrack().isNonnull())
419  track = icand->muonRef()->outerTrack().get();
420  else if (icand->gsfTrackRef().isNonnull())
421  track = icand->gsfTrackRef().get();
422  if (track) {
423  if (track->pt() > leadChargedCandPt) {
424  leadChargedCandEtaAtEcalEntrance = icand->positionAtECALEntrance().eta();
425  leadChargedCandPt = track->pt();
426  }
427  }
428  } else {
429  // TauReco@MiniAOD: individual ECAL and HCAL energies currently not available for PackedCandidates
430  // (see above implementation for PFCandidates).
431  // Should be added if available, as well as on-the-fly computation of position at ECAL entrance
432  sumEnergy += it->energy();
433  const reco::Track* track = it->bestTrack();
434  if (track != nullptr) {
435  if (track->pt() > leadChargedCandPt) {
436  leadChargedCandPt = track->pt();
437  }
438  }
439  }
440  }
441  aTauPFEssential.ecalEnergy_ = ecalEnergy;
442  aTauPFEssential.hcalEnergy_ = hcalEnergy;
443  aTauPFEssential.ptLeadChargedCand_ = leadChargedCandPt;
444  aTauPFEssential.etaAtEcalEntranceLeadChargedCand_ = leadChargedCandEtaAtEcalEntrance;
445  if (sumEnergy != 0.) {
446  aTauPFEssential.phiAtEcalEntrance_ = sumPhiTimesEnergy / sumEnergy;
447  aTauPFEssential.etaAtEcalEntrance_ = sumEtaTimesEnergy / sumEnergy;
448  } else {
449  aTauPFEssential.phiAtEcalEntrance_ = -99.;
450  aTauPFEssential.etaAtEcalEntrance_ = -99.;
451  }
452  float leadingTrackNormChi2 = 0;
453  float ecalEnergyLeadChargedHadrCand = -99.;
454  float hcalEnergyLeadChargedHadrCand = -99.;
455  float emFraction = -1.;
456  float myHCALenergy = 0.;
457  float myECALenergy = 0.;
458  const reco::CandidatePtr& leadingPFCharged = pfTauRef->leadChargedHadrCand();
459  if (leadingPFCharged.isNonnull()) {
460  const reco::PFCandidate* pfCandPtr = dynamic_cast<const reco::PFCandidate*>(leadingPFCharged.get());
461  if (pfCandPtr != nullptr) { // PFTau made from PFCandidates
462  ecalEnergyLeadChargedHadrCand = pfCandPtr->ecalEnergy();
463  hcalEnergyLeadChargedHadrCand = pfCandPtr->hcalEnergy();
464  reco::TrackRef trackRef = pfCandPtr->trackRef();
465  if (trackRef.isNonnull()) {
466  leadingTrackNormChi2 = trackRef->normalizedChi2();
467  for (const auto& isoPFCand : pfTauRef->isolationPFCands()) {
468  myHCALenergy += isoPFCand->hcalEnergy();
469  myECALenergy += isoPFCand->ecalEnergy();
470  }
471  for (const auto& signalPFCand : pfTauRef->signalPFCands()) {
472  myHCALenergy += signalPFCand->hcalEnergy();
473  myECALenergy += signalPFCand->ecalEnergy();
474  }
475  if (myHCALenergy + myECALenergy != 0.) {
476  emFraction = myECALenergy / (myHCALenergy + myECALenergy);
477  }
478  }
479  } else {
480  const pat::PackedCandidate* packedCandPtr = dynamic_cast<const pat::PackedCandidate*>(leadingPFCharged.get());
481  if (packedCandPtr != nullptr) {
482  // TauReco@MiniAOD: Update code below if ecal/hcal energies are available.
483  const reco::Track* track = packedCandPtr->hasTrackDetails() ? &packedCandPtr->pseudoTrack() : nullptr;
484  if (track != nullptr) {
485  leadingTrackNormChi2 = track->normalizedChi2();
486  }
487  }
488  }
489  }
490 
491  aTauPFEssential.emFraction_ = emFraction;
492  aTauPFEssential.leadingTrackNormChi2_ = leadingTrackNormChi2;
493  aTauPFEssential.ecalEnergyLeadChargedHadrCand_ = ecalEnergyLeadChargedHadrCand;
494  aTauPFEssential.hcalEnergyLeadChargedHadrCand_ = hcalEnergyLeadChargedHadrCand;
495  // extraction of tau lifetime information
496  if (!tauTransverseImpactParameterSrc_.label().empty()) {
497  edm::Handle<PFTauTIPAssociationByRef> tauLifetimeInfos;
498  iEvent.getByToken(tauTransverseImpactParameterToken_, tauLifetimeInfos);
499  const reco::PFTauTransverseImpactParameter& tauLifetimeInfo = *(*tauLifetimeInfos)[pfTauRef];
500  pat::tau::TauPFEssential& aTauPFEssential = aTau.pfEssential_[0];
501  aTauPFEssential.dxy_PCA_ = tauLifetimeInfo.dxy_PCA();
502  aTauPFEssential.dxy_ = tauLifetimeInfo.dxy();
503  aTauPFEssential.dxy_error_ = tauLifetimeInfo.dxy_error();
504  aTauPFEssential.hasSV_ = tauLifetimeInfo.hasSecondaryVertex();
505  aTauPFEssential.flightLength_ = tauLifetimeInfo.flightLength();
506  aTauPFEssential.flightLengthSig_ = tauLifetimeInfo.flightLengthSig();
507  aTauPFEssential.ip3d_ = tauLifetimeInfo.ip3d();
508  aTauPFEssential.ip3d_error_ = tauLifetimeInfo.ip3d_error();
509  }
510  }
511 
512  // Isolation
513  if (isolator_.enabled()) {
515  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
516  // better to loop backwards, so the vector is resized less times
517  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
518  ed = isolatorTmpStorage_.rend();
519  it != ed;
520  ++it) {
521  aTau.setIsolation(it->first, it->second);
522  }
523  }
524 
525  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
526  aTau.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[tausRef]);
527  }
528 
529  if (efficiencyLoader_.enabled()) {
530  efficiencyLoader_.setEfficiencies(aTau, tausRef);
531  }
532 
533  if (resolutionLoader_.enabled()) {
535  }
536 
537  if (useUserData_) {
538  userDataHelper_.add(aTau, iEvent, iSetup);
539  }
540 
541  patTaus->push_back(aTau);
542  }
543 
544  // sort taus in pT
545  std::sort(patTaus->begin(), patTaus->end(), pTTauComparator_);
546 
547  // put genEvt object in Event
548  iEvent.put(std::move(patTaus));
549 
550  // clean up
551  if (isolator_.enabled())
553 }
554 
555 template <typename TauCollectionType, typename TauDiscrType>
557  size_t tauIdx,
558  const edm::Handle<TauDiscrType>& tauIdDiscr) {
559  edm::Ref<TauCollectionType> tauRef(tauCollection, tauIdx);
560  return (*tauIdDiscr)[tauRef];
561 }
562 
563 // ParameterSet description for module
566  iDesc.setComment("PAT tau producer module");
567 
568  // input source
569  iDesc.add<edm::InputTag>("tauSource", edm::InputTag())->setComment("input collection");
570 
571  // embedding
572  iDesc.add<bool>("embedIsolationTracks", false)->setComment("embed external isolation tracks");
573  iDesc.add<bool>("embedLeadTrack", false)->setComment("embed external leading track");
574  iDesc.add<bool>("embedLeadTracks", false)->setComment("embed external signal tracks");
575 
576  // MC matching configurables
577  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
578  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
579  std::vector<edm::InputTag> emptySourceVector;
580  iDesc
581  .addNode(edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
582  edm::ParameterDescription<std::vector<edm::InputTag>>("genParticleMatch", emptySourceVector, true))
583  ->setComment("input with MC match information");
584 
585  // MC jet matching variables
586  iDesc.add<bool>("addGenJetMatch", true)->setComment("add MC jet matching");
587  iDesc.add<bool>("embedGenJetMatch", false)->setComment("embed MC jet matched jet information");
588  iDesc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));
589 
591 
592  // tau ID configurables
593  iDesc.add<bool>("addTauID", true)->setComment("add tau ID variables");
594  edm::ParameterSetDescription tauIDSourcesPSet;
595  tauIDSourcesPSet.setAllowAnything();
596  iDesc
598  edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, true))
599  ->setComment("input with tau ID variables");
600  // (Dis)allow to skip missing tauId sources
601  iDesc.add<bool>("skipMissingTauID", false)
602  ->setComment("allow to skip a tau ID variable when not present in the event");
603 
604  // IsoDeposit configurables
605  edm::ParameterSetDescription isoDepositsPSet;
606  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
607  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
608  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
609  isoDepositsPSet.addOptional<edm::InputTag>("pfAllParticles");
610  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadron");
611  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadron");
612  isoDepositsPSet.addOptional<edm::InputTag>("pfGamma");
613  isoDepositsPSet.addOptional<std::vector<edm::InputTag>>("user");
614  iDesc.addOptional("isoDeposits", isoDepositsPSet);
615 
616  // Efficiency configurables
617  edm::ParameterSetDescription efficienciesPSet;
618  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
619  iDesc.add("efficiencies", efficienciesPSet);
620  iDesc.add<bool>("addEfficiencies", false);
621 
622  // Check to see if the user wants to add user data
623  edm::ParameterSetDescription userDataPSet;
625  iDesc.addOptional("userData", userDataPSet);
626 
627  edm::ParameterSetDescription isolationPSet;
628  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
629  iDesc.add("userIsolation", isolationPSet);
630 }
631 
633 
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
~PATTauProducer() override
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:220
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
std::pair< std::string, edm::InputTag > NameTag
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:115
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
void embedIsolationPFCands()
method to store the isolation candidates internally
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:572
void embedIsolationPFGammaCands()
method to store the isolation gamma candidates internally
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setAllowAnything()
allow any parameter label/value pairs
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
pat::helper::EfficiencyLoader efficiencyLoader_
void embedLeadTrack()
method to store the leading track internally
bool exists(std::string const &parameterName) const
checks if a parameter exists
void embedSignalPFChargedHadrCands()
method to store the signal charged hadrons candidates internally
pat::helper::KinResolutionsLoader resolutionLoader_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
float getTauIdDiscriminator(const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)
void setDecayMode(int)
set decay mode
void setTauIDs(const std::vector< IdPair > &ids)
Definition: Tau.h:347
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
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_]
bool isAvailable() const
Definition: Ref.h:537
const math::XYZPointF & positionAtECALEntrance() const
Definition: PFCandidate.h:362
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Lepton.h:191
bool embedIsolationPFChargedHadrCands_
Definition: HeavyIon.h:7
static void fillDescription(edm::ParameterSetDescription &iDesc)
reco::TrackRef trackRef() const
Definition: PFCandidate.cc:408
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:168
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:55
char const * label
void setComment(std::string const &value)
void embedSignalPFCands()
method to store the signal candidates internally
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameterToken_
pat::helper::MultiIsolator isolator_
void embedGenParticle()
Definition: PATObject.h:773
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
bool embedIsolationPFNeutralHadrCands_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
double pt() const
track transverse momentum
Definition: TrackBase.h:602
double energy() const final
energy
pat::PATUserDataHelper< pat::Tau > userDataHelper_
virtual const reco::Track & pseudoTrack() const
genJetMatch
switch on/off embedding of matched genJet&#39;s
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
bool embedSignalPFNeutralHadrCands_
std::vector< pat::tau::TauPFEssential > pfEssential_
Definition: Tau.h:493
void embedIsolationPFNeutralHadrCands()
method to store the isolation neutral hadrons candidates internally
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void embedLeadPFChargedHadrCand()
method to store the leading charged hadron candidate internally
bool isValid() const
Definition: HandleBase.h:70
void embedIsolationPFChargedHadrCands()
method to store the isolation charged hadrons candidates internally
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:421
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:146
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
void setGenJet(const reco::GenJetRef &ref)
set the matched GenJet
Definition: Tau.py:1
void embedLeadPFNeutralCand()
method to store the leading neutral candidate internally
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:756
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
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
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
edm::InputTag tauTransverseImpactParameterSrc_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
std::string const & label() const
Definition: InputTag.h:36
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void initializeJEC(unsigned int level, const unsigned int set=0)
initialize the jet to a given JEC level during creation starting from Uncorrected ...
void embedSignalPFNeutralHadrCands()
method to store the signal neutral hadrons candidates internally
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
void addJECFactors(const TauJetCorrFactors &jec)
add more sets of energy correction factors
Definition: Tau.h:412
PATTauProducer(const edm::ParameterSet &iConfig)
HLT enums.
reco::GsfTrackRef gsfTrackRef() const
Definition: PFCandidate.cc:440
double hcalEnergy() const
return corrected Hcal energy
Definition: PFCandidate.h:232
void embedSignalTracks()
method to store the signal tracks internally
bool isPFTau() const
Returns true if this pat::Tau was made from a reco::PFTau.
Definition: Tau.h:121
void embedSignalPFGammaCands()
method to store the signal gamma candidates internally
bool embedSignalPFChargedHadrCands_
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
void embedIsolationTracks()
method to store the isolation tracks internally
std::vector< NameTag > tauIDSrcs_
edm::EDGetTokenT< reco::PFTauCollection > pfTauToken_
def move(src, dest)
Definition: eostools.py:511
GreaterByPt< Tau > pTTauComparator_
Produces pat::Tau&#39;s.
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:84
void embedLeadPFCand()