CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
PATTauHybridProducer Class Reference
Inheritance diagram for PATTauHybridProducer:
edm::stream::EDProducer<>

Public Member Functions

 PATTauHybridProducer (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~PATTauHybridProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Types

enum  tauId_min_idx : size_t { tauId_min_idx::hpsnew = 0, tauId_min_idx::last }
 
enum  tauId_utag_idx : size_t {
  tauId_utag_idx::dm = 0, tauId_utag_idx::vsjet, tauId_utag_idx::vse, tauId_utag_idx::vsmu,
  tauId_utag_idx::ptcorr, tauId_utag_idx::qconf, tauId_utag_idx::pdm0, tauId_utag_idx::pdm1,
  tauId_utag_idx::pdm2, tauId_utag_idx::pdm10, tauId_utag_idx::pdm11, tauId_utag_idx::last
}
 

Private Member Functions

void fillTauFromJet (reco::PFTau &pfTau, const reco::JetBaseRef &jet)
 

Private Attributes

bool addGenJetMatch_
 
const float chargeAssignmentProbMin_
 
const bool checkTauScoreIsBest_
 
const float dR2Max_
 
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
 
const float jetEtaMax_
 
const float jetPtMin_
 
edm::EDGetTokenT< pat::JetCollectionjetsToken_
 
const std::string tagPrefix_
 
const std::map< std::string, int > tagToDM_
 
const float tauScoreMin_
 
edm::EDGetTokenT< pat::TauCollectiontausToken_
 
const bool usePFLeptonsAsChargedHadrons_
 
std::vector< std::string > utagJetScoreNames_
 
const std::string UTagLabel_
 
std::vector< std::string > utagLepScoreNames_
 
std::string UtagPtCorrName_
 
std::vector< std::string > utagTauScoreNames_
 
const float vsJetMin_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 14 of file PATTauHybridProducer.cc.

Member Enumeration Documentation

◆ tauId_min_idx

enum PATTauHybridProducer::tauId_min_idx : size_t
strongprivate
Enumerator
hpsnew 
last 

Definition at line 42 of file PATTauHybridProducer.cc.

42 : size_t { hpsnew = 0, last };

◆ tauId_utag_idx

enum PATTauHybridProducer::tauId_utag_idx : size_t
strongprivate
Enumerator
dm 
vsjet 
vse 
vsmu 
ptcorr 
qconf 
pdm0 
pdm1 
pdm2 
pdm10 
pdm11 
last 

Definition at line 41 of file PATTauHybridProducer.cc.

41 : size_t { dm = 0, vsjet, vse, vsmu, ptcorr, qconf, pdm0, pdm1, pdm2, pdm10, pdm11, last };

Constructor & Destructor Documentation

◆ PATTauHybridProducer()

PATTauHybridProducer::PATTauHybridProducer ( const edm::ParameterSet cfg)
explicit

Definition at line 44 of file PATTauHybridProducer.cc.

45  : tausToken_(consumes<pat::TauCollection>(cfg.getParameter<edm::InputTag>("src"))),
46  jetsToken_(consumes<pat::JetCollection>(cfg.getParameter<edm::InputTag>("jetSource"))),
47  addGenJetMatch_(cfg.getParameter<bool>("addGenJetMatch")),
48  dR2Max_(std::pow(cfg.getParameter<double>("dRMax"), 2)),
49  jetPtMin_(cfg.getParameter<double>("jetPtMin")),
50  jetEtaMax_(cfg.getParameter<double>("jetEtaMax")),
51  UTagLabel_(cfg.getParameter<std::string>("UTagLabel")),
52  tagPrefix_(cfg.getParameter<std::string>("tagPrefix")),
53  UtagPtCorrName_(cfg.getParameter<std::string>("UtagPtCorrName")),
54  tauScoreMin_(cfg.getParameter<double>("tauScoreMin")),
55  vsJetMin_(cfg.getParameter<double>("vsJetMin")),
56  chargeAssignmentProbMin_(cfg.getParameter<double>("chargeAssignmentProbMin")),
57  checkTauScoreIsBest_(cfg.getParameter<bool>("checkTauScoreIsBest")),
58  usePFLeptonsAsChargedHadrons_(cfg.getParameter<bool>("usePFLeptonsAsChargedHadrons")),
59  tagToDM_({{"1h0p", 0}, {"1h1or2p", 1}, {"1h1p", 1}, {"1h2p", 2}, {"3h0p", 10}, {"3h1p", 11}}) {
60  // Read the different Unified Tagger score names
61  std::vector<std::string> UTagScoreNames = cfg.getParameter<std::vector<std::string>>("UTagScoreNames");
62  for (const auto& scoreName : UTagScoreNames) {
63  // Check that discriminator matches tagger specified
64  if (scoreName.find(UTagLabel_) == std::string::npos)
65  continue;
66  size_t labelLength = scoreName.find(':') == std::string::npos ? 0 : scoreName.find(':') + 1;
67  std::string name = scoreName.substr(labelLength);
68  if (name.find("prob") == std::string::npos)
69  continue;
70  if (name.find("probtau") != std::string::npos)
71  utagTauScoreNames_.push_back(name);
72  else if (name == "probele" || name == "probmu")
73  utagLepScoreNames_.push_back(name);
74  else if (name.find("data") == std::string::npos && name.find("mc") == std::string::npos)
75  utagJetScoreNames_.push_back(name);
76  if (UtagPtCorrName_.find(':') != std::string::npos)
77  UtagPtCorrName_ = UtagPtCorrName_.substr(UtagPtCorrName_.find(':') + 1);
78  // GenJet matching
79  if (addGenJetMatch_) {
81  consumes<edm::Association<reco::GenJetCollection>>(cfg.getParameter<edm::InputTag>("genJetMatch"));
82  }
83  }
84 
85  produces<std::vector<pat::Tau>>();
86  //FIXME: produce a separate collection for PNet-recovered taus?
87 }
edm::EDGetTokenT< pat::JetCollection > jetsToken_
std::vector< std::string > utagTauScoreNames_
const float chargeAssignmentProbMin_
const std::map< std::string, int > tagToDM_
std::vector< std::string > utagJetScoreNames_
const std::string UTagLabel_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
edm::EDGetTokenT< pat::TauCollection > tausToken_
const bool usePFLeptonsAsChargedHadrons_
const std::string tagPrefix_
std::vector< std::string > utagLepScoreNames_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~PATTauHybridProducer()

PATTauHybridProducer::~PATTauHybridProducer ( )
inlineoverride

Definition at line 17 of file PATTauHybridProducer.cc.

17 {};

Member Function Documentation

◆ fillDescriptions()

void PATTauHybridProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 426 of file PATTauHybridProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

426  {
427  // patTauHybridProducer
429 
430  desc.add<edm::InputTag>("src", edm::InputTag("slimmedTaus"));
431  desc.add<edm::InputTag>("jetSource", edm::InputTag("slimmedJetsUpdated"));
432  desc.add<double>("dRMax", 0.4);
433  desc.add<double>("jetPtMin", 20.0);
434  desc.add<double>("jetEtaMax", 2.5);
435  desc.add<std::string>("UTagLabel", "pfParticleNetAK4JetTags");
436  desc.add<std::string>("tagPrefix", "byUTag")->setComment("Prefix to be set for PUPPI or CHS tagger");
437  desc.add<std::vector<std::string>>("UTagScoreNames", {})
438  ->setComment("Output nodes for Unified Tagger (different for PNet vs UParT)");
439  desc.add<std::string>("UtagPtCorrName", "ptcorr");
440  desc.add<double>("tauScoreMin", -1)->setComment("Minimal value of the best tau score to built recovery tau");
441  desc.add<double>("vsJetMin", -1)->setComment("Minimal value of UTag tau-vs-jet discriminant to built recovery tau");
442  desc.add<bool>("checkTauScoreIsBest", false)
443  ->setComment("If true, recovery tau is built only if one of tau scores is the highest");
444  desc.add<double>("chargeAssignmentProbMin", 0.2)
445  ->setComment("Minimal value of charge assignment probability to built recovery tau (0,0.5)");
446  desc.add<bool>("addGenJetMatch", true)->setComment("add MC genTauJet matching");
447  desc.add<edm::InputTag>("genJetMatch", edm::InputTag("tauGenJetMatch"));
448  desc.add<bool>("usePFLeptonsAsChargedHadrons", true)
449  ->setComment("If true, all charged particles are used as charged hadron candidates");
450 
451  descriptions.addWithDefaultLabel(desc);
452 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ fillTauFromJet()

void PATTauHybridProducer::fillTauFromJet ( reco::PFTau pfTau,
const reco::JetBaseRef jet 
)
private

Definition at line 331 of file PATTauHybridProducer.cc.

References funct::abs(), reco::LeafCandidate::charge(), reco::PFTau::decayMode(), SiPixelRawToDigiRegional_cfi::deltaPhi, HLTMuonOfflineAnalyzer_cfi::deltaR2, dR2Max, edm::Ptr< T >::isNonnull(), edm::Ptr< T >::isNull(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, metsig::jet, reco::PFTau::kThreeProng0PiZero, reco::PFTau::leadChargedHadrCand(), reco::tau::pfCandidatesByPdgId(), reco::tau::pfChargedCands(), reco::tau::pfGammas(), funct::pow(), reco::PFTau::setisolationChargedHadrCands(), reco::PFTau::setisolationGammaCands(), reco::PFTau::setleadCand(), reco::PFTau::setleadChargedHadrCand(), reco::PFTau::setsignalChargedHadrCands(), reco::PFTau::setsignalGammaCands(), reco::PFTau::signalConeSize(), and usePFLeptonsAsChargedHadrons_.

Referenced by produce().

331  {
332  // Use tools as in PFTau builders to select tau decay products and isolation candidates
333  typedef std::vector<reco::CandidatePtr> CandPtrs;
334 
335  // Get the charged hadron candidates
336  CandPtrs pfChs, pfChsSig;
337  // Check if we want to include electrons and muons in "charged hadron"
338  // collection. This is the preferred behavior, as the PF lepton selections
339  // are very loose.
341  pfChs = reco::tau::pfCandidatesByPdgId(*jet, 211);
342  } else {
343  pfChs = reco::tau::pfChargedCands(*jet);
344  }
345  // take 1st charged candidate with charge as of tau (collection is pt-sorted)
346  if (pfTau.charge() == 0 || pfChs.size() == 1) {
347  pfTau.setleadChargedHadrCand(pfChs[0]);
348  pfTau.setleadCand(pfChs[0]);
349  pfChsSig.push_back(pfChs[0]);
350  pfChs.erase(pfChs.begin());
351  } else {
352  for (CandPtrs::iterator it = pfChs.begin(); it != pfChs.end();) {
353  if ((*it)->charge() == pfTau.charge()) {
354  pfTau.setleadChargedHadrCand(*it);
355  pfTau.setleadCand(*it);
356  pfChsSig.push_back(*it);
357  it = pfChs.erase(it);
358  break;
359  } else {
360  ++it;
361  }
362  }
363  // In case of lack of candidate with charge same as of tau use leading charged candidate
364  if (pfTau.leadChargedHadrCand().isNull() && !pfChs.empty()) {
365  pfTau.setleadChargedHadrCand(pfChs[0]);
366  pfTau.setleadCand(pfChs[0]);
367  pfChsSig.push_back(pfChs[0]);
368  pfChs.erase(pfChs.begin());
369  }
370  }
371  // if more than one charged decay product is expected add all inside signal
372  // cone around the leading track
373  const double dR2Max = std::pow(pfTau.signalConeSize(), 2);
375  for (CandPtrs::iterator it = pfChs.begin(); it != pfChs.end();) {
376  if (deltaR2((*it)->p4(), pfTau.leadChargedHadrCand()->p4()) < dR2Max) {
377  pfChsSig.push_back(*it);
378  it = pfChs.erase(it);
379  } else {
380  ++it;
381  }
382  }
383  }
384  // Clean isolation candidates from low-pt and leptonic ones
385  pfChs.erase(std::remove_if(pfChs.begin(),
386  pfChs.end(),
387  [](auto const& cand) { return cand->pt() < 0.5 || std::abs(cand->pdgId()) != 211; }),
388  pfChs.end());
389  // Set charged candidates
390  pfTau.setsignalChargedHadrCands(pfChsSig);
391  pfTau.setisolationChargedHadrCands(pfChs);
392 
393  // Get the gamma candidates (pi0 decay products)
394  CandPtrs pfGammas, pfGammasSig;
396  // In case of lack of leading charged candidate substiute it with leading gamma candidate
397  if (pfTau.leadChargedHadrCand().isNull() && !pfGammas.empty()) {
399  pfTau.setleadCand(pfGammas[0]);
400  pfGammasSig.push_back(pfGammas[0]);
401  pfGammas.erase(pfGammas.begin());
402  }
403  // Clean gamma candidates from low-pt ones
404  pfGammas.erase(std::remove_if(pfGammas.begin(), pfGammas.end(), [](auto const& cand) { return cand->pt() < 0.5; }),
405  pfGammas.end());
406  // if decay mode with pi0s is expected look for signal gamma candidates
407  // within eta-phi strips around leading track
408  if (pfTau.decayMode() % 5 != 0 && pfTau.leadChargedHadrCand().isNonnull()) {
409  for (CandPtrs::iterator it = pfGammas.begin(); it != pfGammas.end();) {
410  if (std::abs((*it)->eta() - pfTau.leadChargedHadrCand()->eta()) <
411  std::clamp(0.2 * std::pow((*it)->pt(), -0.66), 0.05, 0.15) &&
412  deltaPhi((*it)->phi(), pfTau.leadChargedHadrCand()->phi()) <
413  std::clamp(0.35 * std::pow((*it)->pt(), -0.71), 0.05, 0.3)) {
414  pfGammasSig.push_back(*it);
415  it = pfGammas.erase(it);
416  } else {
417  ++it;
418  }
419  }
420  }
421  // Set gamma candidates
422  pfTau.setsignalGammaCands(pfGammasSig);
424 }
std::vector< CandidatePtr > pfCandidatesByPdgId(const Jet &jet, int pdgId, bool sort=true)
const double dR2Max
void setsignalChargedHadrCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:77
double signalConeSize() const
Size of signal cone.
Definition: PFTau.h:174
const CandidatePtr & leadChargedHadrCand() const
Definition: PFTau.cc:63
void setleadCand(const CandidatePtr &)
Definition: PFTau.cc:69
std::vector< CandidatePtr > pfChargedCands(const Jet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
void setisolationChargedHadrCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:92
void setleadChargedHadrCand(const CandidatePtr &)
Definition: PFTau.cc:67
bool isNull() const
Checks for null.
Definition: Ptr.h:144
std::vector< reco::CandidatePtr > CandPtrs
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:148
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const bool usePFLeptonsAsChargedHadrons_
hadronicDecayMode decayMode() const
Definition: PFTau.cc:325
void setisolationGammaCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:100
void setsignalGammaCands(const std::vector< reco::CandidatePtr > &)
Definition: PFTau.cc:85
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
int charge() const final
electric charge
std::vector< CandidatePtr > pfGammas(const Jet &jet, bool sort=true)
Extract all pfGammas from a PFJet.

◆ produce()

void PATTauHybridProducer::produce ( edm::Event evt,
const edm::EventSetup es 
)
override

Definition at line 89 of file PATTauHybridProducer.cc.

References funct::abs(), addGenJetMatch_, chargeAssignmentProbMin_, checkTauScoreIsBest_, HLTMuonOfflineAnalyzer_cfi::deltaR2, dm, ALPAKA_ACCELERATOR_NAMESPACE::dR2(), dR2Max_, fillTauFromJet(), dqmdumpme::first, jetProducer_cfi::genJetMatch, genJetMatchToken_, edm::Event::getByToken(), hpsnew, mps_fire::i, ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets::if(), edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), edm::EventBase::isRealData(), metsig::jet, jetEtaMax_, jetPtMin_, PDWG_EXODelayedJetMET_cff::jets, jetsToken_, reco::PFTau::kNull, last, muonTagProbeFilters_cff::matched, eostools::move(), pdm0, pdm1, pdm10, pdm11, pdm2, ptcorr, edm::Event::put(), submitPVResolutionJobs::q, qconf, offlineSlimmedPrimaryVertices_cfi::score, edm::second(), pat::Tau::setGenJet(), reco::LeafCandidate::setPdgId(), pat::Tau::setTauIDs(), tagPrefix_, tagToDM_, pat::Tau::tauIDs(), tauScoreMin_, tausToken_, utagJetScoreNames_, UTagLabel_, utagLepScoreNames_, UtagPtCorrName_, utagTauScoreNames_, vse, vsjet, vsJetMin_, and vsmu.

89  {
90  // Get the vector of taus
92  evt.getByToken(tausToken_, inputTaus);
93 
94  auto outputTaus = std::make_unique<std::vector<pat::Tau>>();
95  outputTaus->reserve(inputTaus->size());
96 
97  // Get the vector of jets
100 
101  // Switch off gen-matching for real data
102  if (evt.isRealData()) {
103  addGenJetMatch_ = false;
104  }
106  if (addGenJetMatch_)
108 
109  // Minimal HPS-like tauID list
110  std::vector<pat::Tau::IdPair> tauIds_minimal((size_t)tauId_min_idx::last);
111  tauIds_minimal[(size_t)tauId_min_idx::hpsnew] = std::make_pair("decayModeFindingNewDMs", -1);
112 
113  // Unified Tagger tauID list
114  std::vector<pat::Tau::IdPair> tauIds_utag((size_t)tauId_utag_idx::last);
115  tauIds_utag[(size_t)tauId_utag_idx::dm] = std::make_pair(tagPrefix_ + "DecayMode", reco::PFTau::kNull);
116  tauIds_utag[(size_t)tauId_utag_idx::vsjet] = std::make_pair(tagPrefix_ + "VSjetraw", -1);
117  tauIds_utag[(size_t)tauId_utag_idx::vse] = std::make_pair(tagPrefix_ + "VSeraw", -1);
118  tauIds_utag[(size_t)tauId_utag_idx::vsmu] = std::make_pair(tagPrefix_ + "VSmuraw", -1);
119  tauIds_utag[(size_t)tauId_utag_idx::ptcorr] = std::make_pair(tagPrefix_ + "PtCorr", 1);
120  tauIds_utag[(size_t)tauId_utag_idx::qconf] = std::make_pair(tagPrefix_ + "QConf", 0);
121  tauIds_utag[(size_t)tauId_utag_idx::pdm0] = std::make_pair(tagPrefix_ + "Prob1h0pi0", -1);
122  tauIds_utag[(size_t)tauId_utag_idx::pdm1] = std::make_pair(tagPrefix_ + "Prob1h1pi0", -1);
123  tauIds_utag[(size_t)tauId_utag_idx::pdm2] = std::make_pair(tagPrefix_ + "Prob1h2pi0", -1);
124  tauIds_utag[(size_t)tauId_utag_idx::pdm10] = std::make_pair(tagPrefix_ + "Prob3h0pi0", -1);
125  tauIds_utag[(size_t)tauId_utag_idx::pdm11] = std::make_pair(tagPrefix_ + "Prob3h1pi0", -1);
126 
127  std::set<unsigned int> matched_taus;
128  size_t jet_idx = 0;
129  for (const auto& jet : *jets) {
130  jet_idx++;
131  if (jet.pt() < jetPtMin_)
132  continue;
133  if (std::abs(jet.eta()) > jetEtaMax_)
134  continue;
135  size_t tau_idx = 0;
136  bool matched = false;
137 
138  // Analyse Tagger scores
139  std::pair<std::string, float> bestUtagTauScore("probtauundef", -1);
140  float sumOfUtagTauScores = 0;
141  std::vector<float> tauPerDMScores(5);
142  float plusChargeProb = 0;
143  for (const auto& scoreName : utagTauScoreNames_) {
144  float score = jet.bDiscriminator(UTagLabel_ + ":" + scoreName);
145  sumOfUtagTauScores += score;
146  if (scoreName.find("taup") != std::string::npos)
147  plusChargeProb += score;
148  if (score > bestUtagTauScore.second) {
149  bestUtagTauScore.second = score;
150  bestUtagTauScore.first = scoreName;
151  }
152  if (scoreName.find("1h0p") != std::string::npos)
153  tauPerDMScores[0] += score;
154  else if (scoreName.find("1h1") !=
155  std::string::
156  npos) //Note: final "p" in "1p" ommited to enble matching also with "1h1or2p" from early trainings
157  tauPerDMScores[1] += score;
158  else if (scoreName.find("1h2p") != std::string::npos)
159  tauPerDMScores[2] += score;
160  else if (scoreName.find("3h0p") != std::string::npos)
161  tauPerDMScores[3] += score;
162  else if (scoreName.find("3h1p") != std::string::npos)
163  tauPerDMScores[4] += score;
164  }
165  if (sumOfUtagTauScores > 0)
166  plusChargeProb /= sumOfUtagTauScores;
167 
168  float sumOfUtagEleScores = 0, sumOfUtagMuScores = 0;
169  bool isTauScoreBest = (sumOfUtagTauScores > 0);
170  for (const auto& scoreName : utagLepScoreNames_) {
171  float score = jet.bDiscriminator(UTagLabel_ + ":" + scoreName);
172  if (scoreName.find("ele") != std::string::npos)
173  sumOfUtagEleScores += score;
174  else if (scoreName.find("mu") != std::string::npos)
175  sumOfUtagMuScores += score;
176  if (score > bestUtagTauScore.second)
177  isTauScoreBest = false;
178  }
179  if (checkTauScoreIsBest_ && isTauScoreBest) { //if needed iterate over jet scores
180  for (const auto& scoreName : utagJetScoreNames_)
181  if (jet.bDiscriminator(UTagLabel_ + ":" + scoreName) > bestUtagTauScore.second)
182  isTauScoreBest = false;
183  }
184 
185  // Unified Tagger discriminants vs jets, electrons and muons
186  tauIds_utag[(size_t)tauId_utag_idx::vsjet].second =
187  sumOfUtagTauScores /
188  (1. - sumOfUtagEleScores -
189  sumOfUtagMuScores); //vsJet: tau scores by sum of tau and jet scores or equally by 1 - sum of lepton scores
190  tauIds_utag[(size_t)tauId_utag_idx::vse].second =
191  sumOfUtagTauScores /
192  (sumOfUtagTauScores + sumOfUtagEleScores); //vsEle: tau scores by sum of tau and ele scores
193  tauIds_utag[(size_t)tauId_utag_idx::vsmu].second =
194  sumOfUtagTauScores / (sumOfUtagTauScores + sumOfUtagMuScores); //vsMu: tau scores by sum of tau and mu scores
195 
196  // Decay mode and charge of the highest tau score
197  int bestCharge = 0;
198  size_t pos =
199  bestUtagTauScore.first.find("tau") + 3; //this is well defined by constraction as name is "probtauXXXX"
200  const char q = (pos < bestUtagTauScore.first.size()) ? bestUtagTauScore.first[pos] : 'u';
201  if (q == 'm') { //minus
202  pos++;
203  bestCharge = -1;
204  } else if (q == 'p') { //plus
205  pos++;
206  bestCharge = 1;
207  }
208  auto UtagDM = tagToDM_.find(bestUtagTauScore.first.substr(pos));
209  if (UtagDM != tagToDM_.end())
210  tauIds_utag[(size_t)tauId_utag_idx::dm].second = UtagDM->second;
211 
212  // Unified tagger Pt correction
213  float ptcorr = jet.bDiscriminator(UTagLabel_ + ":" + UtagPtCorrName_);
214  if (ptcorr > -1000.) // -1000. is default for not found discriminantor
215  tauIds_utag[(size_t)tauId_utag_idx::ptcorr].second = ptcorr;
216 
217  // Unified Tagger charge confidence
218  tauIds_utag[(size_t)tauId_utag_idx::qconf].second = (plusChargeProb - 0.5);
219 
220  // Unified Tagger per decay mode normalised score
221  tauIds_utag[(size_t)tauId_utag_idx::pdm0].second = tauPerDMScores[0] / sumOfUtagTauScores;
222  tauIds_utag[(size_t)tauId_utag_idx::pdm1].second = tauPerDMScores[1] / sumOfUtagTauScores;
223  tauIds_utag[(size_t)tauId_utag_idx::pdm2].second = tauPerDMScores[2] / sumOfUtagTauScores;
224  tauIds_utag[(size_t)tauId_utag_idx::pdm10].second = tauPerDMScores[3] / sumOfUtagTauScores;
225  tauIds_utag[(size_t)tauId_utag_idx::pdm11].second = tauPerDMScores[4] / sumOfUtagTauScores;
226 
227  // Search for matching tau
228  for (const auto& inputTau : *inputTaus) {
229  tau_idx++;
230  if (matched_taus.count(tau_idx - 1) > 0)
231  continue;
232  float dR2 = deltaR2(jet, inputTau);
233  // select 1st found match rather than best match (both should be equivalent for reasonable dRMax)
234  if (dR2 < dR2Max_) {
235  matched_taus.insert(tau_idx - 1);
236  pat::Tau outputTau(inputTau);
237  const size_t nTauIds = inputTau.tauIDs().size();
238  std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_utag.size());
239  for (size_t i = 0; i < nTauIds; ++i)
240  tauIds[i] = inputTau.tauIDs()[i];
241  for (size_t i = 0; i < tauIds_utag.size(); ++i) {
242  if ((tauIds_utag[i].first.find("PtCorr") != std::string::npos) &&
243  (inputTau.tauID("decayModeFindingNewDMs") == -1)) {
244  // if jet is matched to a recovered tau (i.e. non-HPS) then the Pt Correction
245  // should be adjusted so that it can still be applied as PtCorr * TauPt
246  // (as the original PtCorr will be w.r.t the jet pT, but recovered tau
247  // pT is not necessarily set by same jet algorithm if adding both CHS
248  // and PUPPI based taggers)
249  tauIds[nTauIds + i].first = tauIds_utag[i].first;
250  tauIds[nTauIds + i].second = tauIds_utag[i].second * jet.correctedP4("Uncorrected").pt() / inputTau.pt();
251  } else {
252  tauIds[nTauIds + i] = tauIds_utag[i];
253  }
254  }
255  outputTau.setTauIDs(tauIds);
256  matched = true;
257  outputTaus->push_back(outputTau);
258 
259  break;
260  }
261  } // end of tau loop
262  if (matched)
263  continue;
264 
265  // Accept only jets passing minimal tau-like selection, i.e. with one of the tau score being globally the best and above some threshold, and with good quality of charge assignment
266  if ((checkTauScoreIsBest_ && !isTauScoreBest) || bestUtagTauScore.second < tauScoreMin_ ||
267  tauIds_utag[(size_t)tauId_utag_idx::vsjet].second < vsJetMin_ ||
268  std::abs(0.5 - plusChargeProb) < chargeAssignmentProbMin_)
269  continue;
270 
271  // Build taus from non-matched jets
272  // "Null" pftau with raw (uncorrected) jet kinematics
273  reco::PFTau pfTauFromJet(bestCharge, jet.correctedP4("Uncorrected"));
274  // Set PDGid
275  pfTauFromJet.setPdgId(bestCharge < 0 ? 15 : -15);
276  // and decay mode predicted by unified Tagger
277  pfTauFromJet.setDecayMode(
278  static_cast<const reco::PFTau::hadronicDecayMode>(int(tauIds_utag[(size_t)tauId_utag_idx::dm].second)));
279  // Fill tau content using only jet consistunets within cone around leading
280  // charged particle
281  // FIXME: more sophisticated finding of tau constituents will be considered later
282  pfTauFromJet.setSignalConeSize(
283  std::clamp(3.6 / jet.correctedP4("Uncorrected").pt(), 0.08, 0.12)); // shrinking cone in function of jet-Pt
284  const edm::Ref<pat::JetCollection> jetRef(jets, jet_idx - 1);
285  fillTauFromJet(pfTauFromJet, reco::JetBaseRef(jetRef));
286 
287  // PATTau
288  pat::Tau outputTauFromJet(pfTauFromJet);
289  // Add tauIDs
290  std::vector<pat::Tau::IdPair> newtauIds(tauIds_minimal.size() + tauIds_utag.size());
291  for (size_t i = 0; i < tauIds_minimal.size(); ++i)
292  newtauIds[i] = tauIds_minimal[i];
293  for (size_t i = 0; i < tauIds_utag.size(); ++i)
294  newtauIds[tauIds_minimal.size() + i] = tauIds_utag[i];
295  outputTauFromJet.setTauIDs(newtauIds);
296  // Add genTauJet match
297  if (addGenJetMatch_) {
298  reco::GenJetRef genJetTau = (*genJetMatch)[jetRef];
299  if (genJetTau.isNonnull() && genJetTau.isAvailable()) {
300  outputTauFromJet.setGenJet(genJetTau);
301  }
302  }
303  outputTaus->push_back(outputTauFromJet);
304 
305  } // end of jet loop
306 
307  // Taus non-matched to jets (usually at pt-threshold or/and eta boundaries)
308  if (matched_taus.size() < inputTaus->size()) {
309  for (size_t iTau = 0; iTau < inputTaus->size(); ++iTau) {
310  if (matched_taus.count(iTau) > 0)
311  continue;
312  const pat::Tau& inputTau = inputTaus->at(iTau);
313  pat::Tau outputTau(inputTau);
314  const size_t nTauIds = inputTau.tauIDs().size();
315  std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_utag.size());
316  for (size_t i = 0; i < nTauIds; ++i)
317  tauIds[i] = inputTau.tauIDs()[i];
318  for (size_t i = 0; i < tauIds_utag.size(); ++i) {
319  tauIds[nTauIds + i] = tauIds_utag[i];
320  tauIds[nTauIds + i].second =
321  (i != (size_t)tauId_utag_idx::ptcorr ? (i != (size_t)tauId_utag_idx::qconf ? -1 : 0) : 1);
322  }
323  outputTau.setTauIDs(tauIds);
324  outputTaus->push_back(outputTau);
325  }
326  } //non-matched taus
327 
328  evt.put(std::move(outputTaus));
329 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EDGetTokenT< pat::JetCollection > jetsToken_
std::vector< std::string > utagTauScoreNames_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
const std::vector< IdPair > & tauIDs() const
Definition: Tau.h:349
U second(std::pair< T, U > const &p)
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
const float chargeAssignmentProbMin_
bool isAvailable() const
Definition: Ref.h:541
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::map< std::string, int > tagToDM_
genJetMatch
switch on/off embedding of matched genJet&#39;s
std::vector< std::string > utagJetScoreNames_
Analysis-level tau class.
Definition: Tau.h:53
const std::string UTagLabel_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
void fillTauFromJet(reco::PFTau &pfTau, const reco::JetBaseRef &jet)
edm::EDGetTokenT< pat::TauCollection > tausToken_
const std::string tagPrefix_
bool isRealData() const
Definition: EventBase.h:66
std::vector< std::string > utagLepScoreNames_
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
void setPdgId(int pdgId) final
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ addGenJetMatch_

bool PATTauHybridProducer::addGenJetMatch_
private

Definition at line 27 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ chargeAssignmentProbMin_

const float PATTauHybridProducer::chargeAssignmentProbMin_
private

Definition at line 36 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ checkTauScoreIsBest_

const bool PATTauHybridProducer::checkTauScoreIsBest_
private

Definition at line 37 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ dR2Max_

const float PATTauHybridProducer::dR2Max_
private

Definition at line 29 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ genJetMatchToken_

edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > PATTauHybridProducer::genJetMatchToken_
private

Definition at line 28 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ jetEtaMax_

const float PATTauHybridProducer::jetEtaMax_
private

Definition at line 29 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ jetPtMin_

const float PATTauHybridProducer::jetPtMin_
private

Definition at line 29 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ jetsToken_

edm::EDGetTokenT<pat::JetCollection> PATTauHybridProducer::jetsToken_
private

Definition at line 26 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ tagPrefix_

const std::string PATTauHybridProducer::tagPrefix_
private

Definition at line 31 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ tagToDM_

const std::map<std::string, int> PATTauHybridProducer::tagToDM_
private

Definition at line 40 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ tauScoreMin_

const float PATTauHybridProducer::tauScoreMin_
private

Definition at line 36 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ tausToken_

edm::EDGetTokenT<pat::TauCollection> PATTauHybridProducer::tausToken_
private

Definition at line 25 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ usePFLeptonsAsChargedHadrons_

const bool PATTauHybridProducer::usePFLeptonsAsChargedHadrons_
private

Definition at line 38 of file PATTauHybridProducer.cc.

Referenced by fillTauFromJet().

◆ utagJetScoreNames_

std::vector<std::string> PATTauHybridProducer::utagJetScoreNames_
private

Definition at line 33 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ UTagLabel_

const std::string PATTauHybridProducer::UTagLabel_
private

Definition at line 30 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ utagLepScoreNames_

std::vector<std::string> PATTauHybridProducer::utagLepScoreNames_
private

Definition at line 34 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ UtagPtCorrName_

std::string PATTauHybridProducer::UtagPtCorrName_
private

Definition at line 35 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ utagTauScoreNames_

std::vector<std::string> PATTauHybridProducer::utagTauScoreNames_
private

Definition at line 32 of file PATTauHybridProducer.cc.

Referenced by produce().

◆ vsJetMin_

const float PATTauHybridProducer::vsJetMin_
private

Definition at line 36 of file PATTauHybridProducer.cc.

Referenced by produce().