CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
PFRecoTauDiscriminationByIsolationContainer Class Reference
Inheritance diagram for PFRecoTauDiscriminationByIsolationContainer:
TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType > edm::stream::EDProducer<>

Classes

struct  FootprintCorrection
 

Public Types

enum  StoredRawType {
  None, SumPt, PUsumPt, Occupancy,
  FootPrintCorrection, PhotonSumPt
}
 
- Public Types inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >
typedef std::vector< TauType > TauCollection
 
typedef edm::Ref< TauCollectionTauRef
 
typedef edm::RefProd< TauCollectionTauRefProd
 
- 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
 

Public Member Functions

void beginEvent (const edm::Event &evt, const edm::EventSetup &evtSetup) override
 
reco::SingleTauDiscriminatorContainer discriminate (const PFTauRef &pfTau) const override
 
 PFRecoTauDiscriminationByIsolationContainer (const edm::ParameterSet &pset)
 
double weightedSum (const std::vector< CandidatePtr > &inColl_, double eta, double phi) const
 
 ~PFRecoTauDiscriminationByIsolationContainer () override
 
- Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >
virtual TauDiscriminatorDataType discriminate (const TauRef &tau) const =0
 
virtual void endEvent (edm::Event &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 TauDiscriminationProducerBase (const edm::ParameterSet &iConfig)
 
 TauDiscriminationProducerBase ()
 
 ~TauDiscriminationProducerBase () 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)
 
- Static Public Member Functions inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >
static void fillProducerDescriptions (edm::ParameterSetDescription &desc)
 
static std::string getTauTypeString ()
 helper method to retrieve tau type name, e.g. to build correct cfi getter More...
 

Private Attributes

std::vector< bool > applyDeltaBetaCorrection_
 
bool applyFootprintCorrection_
 
bool applyRhoCorrection_
 
std::vector< bool > calculateWeights_
 
std::vector< reco::CandidatePtrchargedPFCandidatesInEvent_
 
double customIsoCone_
 
double deltaBetaCollectionCone_
 
double deltaBetaFactorThisEvent_
 
std::unique_ptr< TFormula > deltaBetaFormula_
 
bool deltaBetaNeeded_
 
std::vector< std::unique_ptr< FootprintCorrection > > footprintCorrections_
 
bool gammasNeeded_
 
std::vector< bool > includeGammas_
 
std::vector< bool > includeTracks_
 
std::vector< std::vector< double > > maxAbsValue_
 
std::vector< std::vector< double > > maxRelValue_
 
double minPtForNoIso_
 
std::string moduleLabel_
 
std::vector< std::vector< double > > offsetRelValue_
 
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCand_token
 
edm::InputTag pfCandSrc_
 
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsGeneralQCuts_
 
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
 
std::unique_ptr< tau::RecoTauQualityCuts > qcuts_
 
edm::ParameterSet qualityCutsPSet_
 
std::vector< std::vector< int > > rawValue_reference_
 
edm::EDGetTokenT< double > rho_token
 
double rhoConeSize_
 
double rhoCorrectionThisEvent_
 
edm::InputTag rhoProducer_
 
double rhoThisEvent_
 
double rhoUEOffsetCorrection_
 
std::vector< StoredRawTypestoreRawValue_
 
bool tracksNeeded_
 
std::vector< bool > useAllPFCandsForWeights_
 
int verbosity_
 
edm::EDGetTokenT< reco::VertexCollectionvertex_token
 
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
 
edm::InputTag vertexSrc_
 
double weightGammas_
 
bool weightsNeeded_
 

Additional Inherited Members

- Protected Attributes inherited from TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >
std::string moduleLabel_
 
double prediscriminantFailValue_
 
edm::EDGetTokenT< TauCollectionTau_token
 
size_t tauIndex_
 
edm::InputTag TauProducer_
 

Detailed Description

Definition at line 30 of file PFRecoTauDiscriminationByIsolationContainer.cc.

Member Enumeration Documentation

◆ StoredRawType

Constructor & Destructor Documentation

◆ PFRecoTauDiscriminationByIsolationContainer()

PFRecoTauDiscriminationByIsolationContainer::PFRecoTauDiscriminationByIsolationContainer ( const edm::ParameterSet pset)
inlineexplicit

Definition at line 33 of file PFRecoTauDiscriminationByIsolationContainer.cc.

References HLT_2024v10_cff::deltaBetaPUTrackPtCutOverride, HLT_2024v10_cff::deltaBetaPUTrackPtCutOverride_val, Exception, reco::tau::factorizePUQCuts(), newFWLiteAna::found, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterSet(), mps_fire::i, dqmiolumiharvest::j, eostools::move(), IntegrityClient_cfi::Occupancy, hltrates_dqm_sourceclient-live_cfg::offset, muonDTDigis_cfi::pset, corrVsCorr::selection, HLT_2024v10_cff::storeRawFootprintCorrection, and AlCaHLTBitMon_QueryRunRegistry::string.

35  moduleLabel_(pset.getParameter<std::string>("@module_label")),
36  qualityCutsPSet_(pset.getParameter<edm::ParameterSet>("qualityCuts")) {
37  // RIC: multiply neutral isolation by a flat factor.
38  // Useful, for instance, to combine charged and neutral isolations
39  // with different relative weights
40  weightGammas_ = pset.getParameter<double>("WeightECALIsolation");
41 
42  // RIC: allow to relax the isolation completely beyond a given tau pt
43  minPtForNoIso_ = pset.getParameter<double>("minTauPtForNoIso");
44 
45  // Get configs for raw values
46  bool storeRawFootprintCorrection = false;
47  deltaBetaNeeded_ = false;
48  weightsNeeded_ = false;
49  tracksNeeded_ = false;
50  gammasNeeded_ = false;
51  storeRawValue_.clear();
52  auto const& rawDefs = pset.getParameter<std::vector<edm::ParameterSet>>("IDdefinitions");
53  std::vector<std::string> idnames;
54  for (auto const& rawDefsEntry : rawDefs) {
55  idnames.push_back(rawDefsEntry.getParameter<std::string>("IDname"));
56  // Can only store one type
57  int numStoreOptions = 0;
58  if (rawDefsEntry.getParameter<bool>("storeRawSumPt")) {
59  storeRawValue_.push_back(SumPt);
60  ++numStoreOptions;
61  }
62  if (rawDefsEntry.getParameter<bool>("storeRawOccupancy")) {
63  storeRawValue_.push_back(Occupancy);
64  ++numStoreOptions;
65  }
66  if (rawDefsEntry.getParameter<bool>("storeRawPUsumPt")) {
67  storeRawValue_.push_back(PUsumPt);
68  ++numStoreOptions;
69  }
70  if (rawDefsEntry.getParameter<bool>("storeRawFootprintCorrection")) {
73  ++numStoreOptions;
74  }
75  if (rawDefsEntry.getParameter<bool>("storeRawPhotonSumPt_outsideSignalCone")) {
76  storeRawValue_.push_back(PhotonSumPt);
77  ++numStoreOptions;
78  }
79  if (numStoreOptions != 1) {
80  throw cms::Exception("BadIsoConfig")
81  << "Multiple or none of 'store sum pt' and/or 'store occupancy' options are set."
82  << " These options are mutually exclusive.";
83  }
84 
85  includeGammas_.push_back(rawDefsEntry.getParameter<bool>("ApplyDiscriminationByECALIsolation"));
86  if (includeGammas_.back())
87  gammasNeeded_ = true;
88  calculateWeights_.push_back(rawDefsEntry.getParameter<bool>("ApplyDiscriminationByWeightedECALIsolation"));
89  if (calculateWeights_.back())
90  weightsNeeded_ = true;
91  includeTracks_.push_back(rawDefsEntry.getParameter<bool>("ApplyDiscriminationByTrackerIsolation"));
92  if (includeTracks_.back())
93  tracksNeeded_ = true;
94  applyDeltaBetaCorrection_.push_back(rawDefsEntry.getParameter<bool>("applyDeltaBetaCorrection"));
95  if (applyDeltaBetaCorrection_.back())
96  deltaBetaNeeded_ = true;
97  useAllPFCandsForWeights_.push_back(rawDefsEntry.getParameter<bool>("UseAllPFCandsForWeights"));
98 
99  // sanity check2 - can't use weighted and unweighted iso at the same time
100  if (includeGammas_.back() && calculateWeights_.back()) {
101  throw cms::Exception("BadIsoConfig")
102  << "Both 'ApplyDiscriminationByECALIsolation' and 'ApplyDiscriminationByWeightedECALIsolation' "
103  << "have been set to true. These options are mutually exclusive.";
104  }
105  }
106 
107  // Get configs for WPs - negative cut values are used to switch of the condition
108  std::vector<edm::ParameterSet> wpDefs = pset.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
109  for (std::vector<edm::ParameterSet>::iterator wpDefsEntry = wpDefs.begin(); wpDefsEntry != wpDefs.end();
110  ++wpDefsEntry) {
111  maxAbsValue_.push_back(wpDefsEntry->getParameter<std::vector<double>>("maximumAbsoluteValues"));
112  maxRelValue_.push_back(wpDefsEntry->getParameter<std::vector<double>>("maximumRelativeValues"));
113  offsetRelValue_.push_back(wpDefsEntry->getParameter<std::vector<double>>("relativeValueOffsets"));
114  auto refRawIDNames = wpDefsEntry->getParameter<std::vector<std::string>>("referenceRawIDNames");
115  if (!maxAbsValue_.back().empty() && maxAbsValue_.back().size() != refRawIDNames.size())
116  throw cms::Exception("BadIsoConfig")
117  << "WP configuration: Length of 'maximumAbsoluteValues' does not match length of 'referenceRawIDNames'!";
118  if (!maxRelValue_.back().empty() && maxRelValue_.back().size() != refRawIDNames.size())
119  throw cms::Exception("BadIsoConfig")
120  << "WP configuration: Length of 'maximumRelativeValues' does not match length of 'referenceRawIDNames'!";
121  if (!offsetRelValue_.back().empty() && offsetRelValue_.back().size() != refRawIDNames.size())
122  throw cms::Exception("BadIsoConfig")
123  << "WP configuration: Length of 'relativeValueOffsets' does not match length of 'referenceRawIDNames'!";
124  else if (offsetRelValue_.back().empty())
125  offsetRelValue_.back().assign(refRawIDNames.size(), 0.0);
126  rawValue_reference_.push_back(std::vector<int>(refRawIDNames.size()));
127  for (size_t i = 0; i < refRawIDNames.size(); i++) {
128  bool found = false;
129  for (size_t j = 0; j < idnames.size(); j++) {
130  if (refRawIDNames[i] == idnames[j]) {
131  rawValue_reference_.back()[i] = j;
132  found = true;
133  break;
134  }
135  }
136  if (!found)
137  throw cms::Exception("BadIsoConfig")
138  << "WP configuration: Requested raw ID '" << refRawIDNames[i] << "' not defined!";
139  }
140  }
141 
142  customIsoCone_ = pset.getParameter<double>("customOuterCone");
143 
144  applyFootprintCorrection_ = pset.getParameter<bool>("applyFootprintCorrection");
146  edm::VParameterSet cfgFootprintCorrections = pset.getParameter<edm::VParameterSet>("footprintCorrections");
147  for (edm::VParameterSet::const_iterator cfgFootprintCorrection = cfgFootprintCorrections.begin();
148  cfgFootprintCorrection != cfgFootprintCorrections.end();
149  ++cfgFootprintCorrection) {
150  std::string selection = cfgFootprintCorrection->getParameter<std::string>("selection");
151  std::string offset = cfgFootprintCorrection->getParameter<std::string>("offset");
152  auto footprintCorrection = std::make_unique<FootprintCorrection>(selection, offset);
153  footprintCorrections_.push_back(std::move(footprintCorrection));
154  }
155  }
156 
157  // Get the quality cuts specific to the isolation region
158  edm::ParameterSet isolationQCuts = qualityCutsPSet_.getParameterSet("isolationQualityCuts");
159 
160  qcuts_ = std::make_unique<tau::RecoTauQualityCuts>(isolationQCuts);
161 
162  vertexAssociator_ = std::make_unique<tau::RecoTauVertexAssociator>(qualityCutsPSet_, consumesCollector());
163 
165  // Factorize the isolation QCuts into those that are used to
166  // select PU and those that are not.
167  std::pair<edm::ParameterSet, edm::ParameterSet> puFactorizedIsoQCuts =
168  reco::tau::factorizePUQCuts(isolationQCuts);
169 
170  // Determine the pt threshold for the PU tracks
171  // First check if the user specifies explicitly the cut.
172  // For that the user has to provide a >= 0 value for the PtCutOverride.
173  bool deltaBetaPUTrackPtCutOverride = pset.getParameter<bool>("deltaBetaPUTrackPtCutOverride");
175  double deltaBetaPUTrackPtCutOverride_val = pset.getParameter<double>("deltaBetaPUTrackPtCutOverride_val");
176  puFactorizedIsoQCuts.second.addParameter<double>("minTrackPt", deltaBetaPUTrackPtCutOverride_val);
177  } else {
178  // Secondly take it from the minGammaEt
179  puFactorizedIsoQCuts.second.addParameter<double>("minTrackPt",
180  isolationQCuts.getParameter<double>("minGammaEt"));
181  }
182 
183  pileupQcutsPUTrackSelection_ = std::make_unique<tau::RecoTauQualityCuts>(puFactorizedIsoQCuts.first);
184 
185  pileupQcutsGeneralQCuts_ = std::make_unique<tau::RecoTauQualityCuts>(puFactorizedIsoQCuts.second);
186 
187  pfCandSrc_ = pset.getParameter<edm::InputTag>("particleFlowSrc");
188  pfCand_token = consumes<edm::View<reco::Candidate>>(pfCandSrc_);
189  vertexSrc_ = pset.getParameter<edm::InputTag>("vertexSrc");
190  vertex_token = consumes<reco::VertexCollection>(vertexSrc_);
191  deltaBetaCollectionCone_ = pset.getParameter<double>("isoConeSizeForDeltaBeta");
192  std::string deltaBetaFactorFormula = pset.getParameter<string>("deltaBetaFactor");
193  deltaBetaFormula_ = std::make_unique<TFormula>("DB_corr", deltaBetaFactorFormula.c_str());
194  }
195 
196  applyRhoCorrection_ = pset.getParameter<bool>("applyRhoCorrection");
197  if (applyRhoCorrection_) {
198  rhoProducer_ = pset.getParameter<edm::InputTag>("rhoProducer");
199  rho_token = consumes<double>(rhoProducer_);
200  rhoConeSize_ = pset.getParameter<double>("rhoConeSize");
201  rhoUEOffsetCorrection_ = pset.getParameter<double>("rhoUEOffsetCorrection");
202  }
203 
204  verbosity_ = pset.getParameter<int>("verbosity");
205  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
TauDiscriminationProducerBase< reco::PFTau, reco::TauDiscriminatorContainer, reco::SingleTauDiscriminatorContainer, reco::PFTauDiscriminator > PFTauDiscriminationContainerProducerBase
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:35
selection
main part
Definition: corrVsCorr.py:100
ParameterSet const & getParameterSet(std::string const &) const
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
std::vector< std::unique_ptr< FootprintCorrection > > footprintCorrections_
std::pair< edm::ParameterSet, edm::ParameterSet > factorizePUQCuts(const edm::ParameterSet &inputSet)
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCand_token
def move(src, dest)
Definition: eostools.py:511

◆ ~PFRecoTauDiscriminationByIsolationContainer()

PFRecoTauDiscriminationByIsolationContainer::~PFRecoTauDiscriminationByIsolationContainer ( )
inlineoverride

Definition at line 207 of file PFRecoTauDiscriminationByIsolationContainer.cc.

207 {}

Member Function Documentation

◆ beginEvent()

void PFRecoTauDiscriminationByIsolationContainer::beginEvent ( const edm::Event evt,
const edm::EventSetup evtSetup 
)
overridevirtual

Reimplemented from TauDiscriminationProducerBase< TauType, TauDiscriminator, TauDiscriminatorDataType, ConsumeType >.

Definition at line 298 of file PFRecoTauDiscriminationByIsolationContainer.cc.

References reco::Candidate::charge(), mps_fire::i, zmumugammaAnalyzer_cfi::pfCandidates, and AlignmentTracksFromVertexSelector_cfi::vertices.

299  {
300  // NB: The use of the PV in this context is necessitated by its use in
301  // applying quality cuts to the different objects in the isolation cone
302  // The vertex associator contains the logic to select the appropriate vertex
303  // We need to pass it the event so it can load the vertices.
304  vertexAssociator_->setEvent(event);
305 
306  // If we are applying the delta beta correction, we need to get the PF
307  // candidates from the event so we can find the PU tracks.
309  // Collect all the PF pile up tracks
311  event.getByToken(pfCand_token, pfCandidates);
313  chargedPFCandidatesInEvent_.reserve(pfCandidates->size());
314  size_t numPFCandidates = pfCandidates->size();
315  for (size_t i = 0; i < numPFCandidates; ++i) {
316  reco::CandidatePtr pfCandidate(pfCandidates, i);
317  if (pfCandidate->charge() != 0) {
318  chargedPFCandidatesInEvent_.push_back(pfCandidate);
319  }
320  }
321  // Count all the vertices in the event, to parameterize the DB
322  // correction factor
324  event.getByToken(vertex_token, vertices);
325  size_t nVtxThisEvent = vertices->size();
326  deltaBetaFactorThisEvent_ = deltaBetaFormula_->Eval(nVtxThisEvent);
327  }
328 
329  if (applyRhoCorrection_) {
330  edm::Handle<double> rhoHandle_;
331  event.getByToken(rho_token, rhoHandle_);
332  rhoThisEvent_ = (*rhoHandle_ - rhoUEOffsetCorrection_) * (3.14159) * rhoConeSize_ * rhoConeSize_;
333  }
334 }
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCand_token
Definition: event.py:1

◆ discriminate()

reco::SingleTauDiscriminatorContainer PFRecoTauDiscriminationByIsolationContainer::discriminate ( const PFTauRef pfTau) const
override

Definition at line 336 of file PFRecoTauDiscriminationByIsolationContainer.cc.

References gather_cfg::cout, reco::deltaR(), HGC3DClusterGenMatchSelector_cfi::dR, relativeConstraints::empty, PVValHelper::eta, ALCARECOTkAlBeamHalo_cff::filter, mps_fire::i, edm::Ref< C, T, F >::isNonnull(), dqmiolumiharvest::j, dqm-mbProfile::log, LogDebug, LogTrace, SiStripPI::min, eostools::move(), IntegrityClient_cfi::Occupancy, reco::LeafCandidate::p4(), reco::phi(), edm::OwnVector< T, P >::push_back(), edm::OwnVector< T, P >::reserve(), mps_fire::result, reco::LeafCandidate::setP4(), and trackerHitRTTI::vector.

337  {
338  LogDebug("discriminate") << " tau: Pt = " << pfTau->pt() << ", eta = " << pfTau->eta() << ", phi = " << pfTau->phi();
339  LogDebug("discriminate") << *pfTau;
340 
341  // collect the objects we are working with (ie tracks, tracks+gammas, etc)
342  std::vector<CandidatePtr> isoCharged_;
343  std::vector<CandidatePtr> isoNeutral_;
344  std::vector<CandidatePtr> isoPU_;
345  std::vector<CandidatePtr> isoPUall_;
346  CandidateCollection isoNeutralWeight_;
347  CandidateCollection isoNeutralWeight_UseAllPFCands_;
348  std::vector<CandidatePtr> chPV_;
349  std::vector<CandidatePtr> chPVall_;
350  isoCharged_.reserve(pfTau->isolationChargedHadrCands().size());
351  isoNeutral_.reserve(pfTau->isolationGammaCands().size());
352  isoPU_.reserve(std::min(100UL, chargedPFCandidatesInEvent_.size()));
353  isoPUall_.reserve(std::min(100UL, chargedPFCandidatesInEvent_.size()));
354  isoNeutralWeight_.reserve(pfTau->isolationGammaCands().size());
355  isoNeutralWeight_UseAllPFCands_.reserve(pfTau->isolationGammaCands().size());
356 
357  chPV_.reserve(std::min(50UL, chargedPFCandidatesInEvent_.size()));
358  chPVall_.reserve(std::min(50UL, chargedPFCandidatesInEvent_.size()));
359 
360  // Get the primary vertex associated to this tau
361  reco::VertexRef pv = vertexAssociator_->associatedVertex(*pfTau);
362  // Let the quality cuts know which the vertex to use when applying selections
363  // on dz, etc.
364  if (verbosity_) {
365  if (pv.isNonnull()) {
366  LogTrace("discriminate") << "pv: x = " << pv->position().x() << ", y = " << pv->position().y()
367  << ", z = " << pv->position().z();
368  } else {
369  LogTrace("discriminate") << "pv: N/A";
370  }
371  if (pfTau->leadChargedHadrCand().isNonnull()) {
372  LogTrace("discriminate") << "leadPFChargedHadron:"
373  << " Pt = " << pfTau->leadChargedHadrCand()->pt() << ","
374  << " eta = " << pfTau->leadChargedHadrCand()->eta() << ","
375  << " phi = " << pfTau->leadChargedHadrCand()->phi();
376  } else {
377  LogTrace("discriminate") << "leadPFChargedHadron: N/A";
378  }
379  }
380 
381  // CV: isolation is not well defined in case primary vertex or leading charged hadron do not exist
382  if (!(pv.isNonnull() && pfTau->leadChargedHadrCand().isNonnull()))
383  return 0.;
384 
385  qcuts_->setPV(pv);
386  qcuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
387 
390  pileupQcutsGeneralQCuts_->setLeadTrack(*pfTau->leadChargedHadrCand());
392  pileupQcutsPUTrackSelection_->setLeadTrack(*pfTau->leadChargedHadrCand());
393  }
394 
395  // Load the tracks if they are being used.
396  if (tracksNeeded_) {
397  for (auto const& cand : pfTau->isolationChargedHadrCands()) {
398  if (qcuts_->filterCandRef(cand)) {
399  LogTrace("discriminate") << "adding charged iso cand with pt " << cand->pt();
400  isoCharged_.push_back(cand);
401  }
402  }
403  }
404  if (gammasNeeded_ || weightsNeeded_) {
405  for (auto const& cand : pfTau->isolationGammaCands()) {
406  if (qcuts_->filterCandRef(cand)) {
407  LogTrace("discriminate") << "adding neutral iso cand with pt " << cand->pt();
408  isoNeutral_.push_back(cand);
409  }
410  }
411  }
412 
415 
416  // If desired, get PU tracks.
418  // First select by inverted the DZ/track weight cuts. True = invert
419  if (verbosity_) {
420  std::cout << "Initial PFCands: " << chargedPFCandidatesInEvent_.size() << std::endl;
421  }
422 
423  std::vector<CandidatePtr> allPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_, true);
424 
425  std::vector<CandidatePtr> allNPU = pileupQcutsPUTrackSelection_->filterCandRefs(chargedPFCandidatesInEvent_);
426  LogTrace("discriminate") << "After track cuts: " << allPU.size();
427 
428  // Now apply the rest of the cuts, like pt, and TIP, tracker hits, etc
429  std::vector<CandidatePtr> cleanPU = pileupQcutsGeneralQCuts_->filterCandRefs(allPU);
430 
431  std::vector<CandidatePtr> cleanNPU = pileupQcutsGeneralQCuts_->filterCandRefs(allNPU);
432 
433  LogTrace("discriminate") << "After cleaning cuts: " << cleanPU.size();
434 
435  // Only select PU tracks inside the isolation cone.
436  DRFilter deltaBetaFilter(pfTau->p4(), 0, deltaBetaCollectionCone_);
437  for (auto const& cand : cleanPU) {
438  if (deltaBetaFilter(cand))
439  isoPU_.push_back(cand);
440  }
441 
442  for (auto const& cand : cleanNPU) {
443  if (deltaBetaFilter(cand))
444  chPV_.push_back(cand);
445  }
446  LogTrace("discriminate") << "After cone cuts: " << isoPU_.size() << " " << chPV_.size();
447  isoPUall_ = std::move(allPU);
448  chPVall_ = std::move(allNPU);
449  }
450 
451  if (weightsNeeded_) {
452  for (auto const& isoObject : isoNeutral_) {
453  if (isoObject->charge() != 0) {
454  // weight only neutral objects
455  isoNeutralWeight_.push_back(*isoObject);
456  isoNeutralWeight_UseAllPFCands_.push_back(*isoObject);
457  continue;
458  }
459 
460  double eta = isoObject->eta();
461  double phi = isoObject->phi();
462  {
463  double sumNPU = 0.5 * log(weightedSum(chPV_, eta, phi));
464 
465  double sumPU = 0.5 * log(weightedSum(isoPU_, eta, phi));
466  LeafCandidate neutral(*isoObject);
467  if ((sumNPU + sumPU) > 0)
468  neutral.setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.p4());
469 
470  isoNeutralWeight_.push_back(neutral);
471  }
472  {
473  double sumNPU = 0.5 * log(weightedSum(chPVall_, eta, phi));
474 
475  double sumPU = 0.5 * log(weightedSum(isoPUall_, eta, phi));
476  LeafCandidate neutral(*isoObject);
477  if ((sumNPU + sumPU) > 0)
478  neutral.setP4(((sumNPU) / (sumNPU + sumPU)) * neutral.p4());
479 
480  isoNeutralWeight_UseAllPFCands_.push_back(neutral);
481  }
482  }
483  }
484 
485  // Check if we want a custom iso cone
486  if (customIsoCone_ >= 0.) {
487  DRFilter filter(pfTau->p4(), 0, customIsoCone_);
488  DRFilter2 filter2(pfTau->p4(), 0, customIsoCone_);
489  std::vector<CandidatePtr> isoCharged_filter;
490  std::vector<CandidatePtr> isoNeutral_filter;
491  // Remove all the objects not in our iso cone
492  for (auto const& isoObject : isoCharged_) {
493  if (filter(isoObject))
494  isoCharged_filter.push_back(isoObject);
495  }
496  isoCharged_ = isoCharged_filter;
497  for (auto const& isoObject : isoNeutral_) {
498  if (filter(isoObject))
499  isoNeutral_filter.push_back(isoObject);
500  }
501  isoNeutral_ = isoNeutral_filter;
502  {
503  CandidateCollection isoNeutralWeight_filter;
504  for (auto const& isoObject : isoNeutralWeight_) {
505  if (filter2(isoObject))
506  isoNeutralWeight_filter.push_back(isoObject);
507  }
508  isoNeutralWeight_ = isoNeutralWeight_filter;
509  }
510  {
511  CandidateCollection isoNeutralWeight_filter;
512  for (auto const& isoObject : isoNeutralWeight_UseAllPFCands_) {
513  if (filter2(isoObject))
514  isoNeutralWeight_filter.push_back(isoObject);
515  }
516  isoNeutralWeight_UseAllPFCands_ = isoNeutralWeight_filter;
517  }
518  }
519 
520  //Now all needed incredients are ready. Loop over all ID configurations and produce output
522  for (size_t i = 0; i < includeGammas_.size(); i++) {
523  //--- nObjects requirement
524  int neutrals = isoNeutral_.size();
525 
526  if (applyDeltaBetaCorrection_.at(i)) {
527  neutrals -= TMath::Nint(deltaBetaFactorThisEvent_ * isoPU_.size());
528  }
529  if (neutrals < 0) {
530  neutrals = 0;
531  }
532 
533  int nOccupants = isoCharged_.size() + neutrals;
534 
535  double footprintCorrection_value = 0.;
537  for (std::vector<std::unique_ptr<FootprintCorrection>>::const_iterator footprintCorrection =
538  footprintCorrections_.begin();
539  footprintCorrection != footprintCorrections_.end();
540  ++footprintCorrection) {
541  if ((*footprintCorrection)->selection_(*pfTau)) {
542  footprintCorrection_value = (*footprintCorrection)->offset_(*pfTau);
543  }
544  }
545  }
546 
547  double totalPt = 0.;
548  double puPt = 0.;
549  //--- Sum PT requirement
550  if (storeRawValue_.at(i) == SumPt || storeRawValue_.at(i) == PUsumPt) {
551  double chargedPt = 0.;
552  double neutralPt = 0.;
553  double weightedNeutralPt = 0.;
554  if (includeTracks_.at(i)) {
555  for (auto const& isoObject : isoCharged_) {
556  chargedPt += isoObject->pt();
557  }
558  }
559 
560  if (calculateWeights_.at(i)) {
561  if (useAllPFCandsForWeights_.at(i)) {
562  for (auto const& isoObject : isoNeutralWeight_UseAllPFCands_) {
563  weightedNeutralPt += isoObject.pt();
564  }
565  } else {
566  for (auto const& isoObject : isoNeutralWeight_) {
567  weightedNeutralPt += isoObject.pt();
568  }
569  }
570  } else if (includeGammas_.at(i)) {
571  for (auto const& isoObject : isoNeutral_) {
572  neutralPt += isoObject->pt();
573  }
574  }
575  for (auto const& isoObject : isoPU_) {
576  puPt += isoObject->pt();
577  }
578  LogTrace("discriminate") << "chargedPt = " << chargedPt;
579  LogTrace("discriminate") << "neutralPt = " << neutralPt;
580  LogTrace("discriminate") << "weighted neutral Pt = " << weightedNeutralPt;
581  LogTrace("discriminate") << "puPt = " << puPt << " (delta-beta corr. = " << (deltaBetaFactorThisEvent_ * puPt)
582  << ")";
583 
584  if (calculateWeights_.at(i)) {
585  neutralPt = weightedNeutralPt;
586  }
587 
588  if (applyDeltaBetaCorrection_.at(i)) {
589  neutralPt -= (deltaBetaFactorThisEvent_ * puPt);
590  }
591 
593  neutralPt -= footprintCorrection_value;
594  }
595 
596  if (applyRhoCorrection_) {
597  neutralPt -= rhoThisEvent_;
598  }
599 
600  if (neutralPt < 0.) {
601  neutralPt = 0.;
602  }
603 
604  totalPt = chargedPt + weightGammas_ * neutralPt;
605  }
606 
607  double photonSumPt_outsideSignalCone = 0.;
608  if (storeRawValue_.at(i) == PhotonSumPt) {
609  const std::vector<reco::CandidatePtr>& signalGammas = pfTau->signalGammaCands();
610  for (std::vector<reco::CandidatePtr>::const_iterator signalGamma = signalGammas.begin();
611  signalGamma != signalGammas.end();
612  ++signalGamma) {
613  double dR = deltaR(pfTau->eta(), pfTau->phi(), (*signalGamma)->eta(), (*signalGamma)->phi());
614  if (dR > pfTau->signalConeSize())
615  photonSumPt_outsideSignalCone += (*signalGamma)->pt();
616  }
617  }
618 
619  // We did error checking in the constructor, so this is safe.
620  if (storeRawValue_.at(i) == SumPt) {
621  result.rawValues.push_back(totalPt);
622  } else if (storeRawValue_.at(i) == PUsumPt) {
624  result.rawValues.push_back(puPt);
625  else if (applyRhoCorrection_)
626  result.rawValues.push_back(rhoThisEvent_);
627  else
628  result.rawValues.push_back(0.);
629  } else if (storeRawValue_.at(i) == Occupancy) {
630  result.rawValues.push_back(nOccupants);
631  } else if (storeRawValue_.at(i) == FootPrintCorrection) {
632  result.rawValues.push_back(footprintCorrection_value);
633  } else if (storeRawValue_.at(i) == PhotonSumPt) {
634  result.rawValues.push_back(photonSumPt_outsideSignalCone);
635  }
636  }
637  for (size_t i = 0; i < rawValue_reference_.size(); i++) {
638  bool pass = true;
639  if (minPtForNoIso_ > 0. && pfTau->pt() > minPtForNoIso_)
640  LogDebug("discriminate") << "tau pt = " << pfTau->pt() << "\t min cutoff pt = " << minPtForNoIso_;
641  else {
642  for (size_t j = 0; j < rawValue_reference_[i].size(); j++) {
643  double rawValue = result.rawValues[rawValue_reference_[i][j]];
644  LogTrace("discriminate") << "Iso sum = " << rawValue << " (max_abs = " << maxAbsValue_[i][j]
645  << ", max_rel = " << maxRelValue_[i][j] << ", offset_rel = " << offsetRelValue_[i][j]
646  << ")";
647  if (!maxAbsValue_[i].empty() && maxAbsValue_[i][j] >= 0.0)
648  pass = rawValue <= maxAbsValue_[i][j];
649  if (!maxRelValue_[i].empty() && maxRelValue_[i][j] >= 0.0)
650  pass = rawValue <= maxRelValue_[i][j] * (pfTau->pt() - offsetRelValue_[i][j]);
651  if (!pass)
652  break; // do not pass if one of the conditions in the j list fails
653  }
654  }
655  result.workingPoints.push_back(pass);
656  }
657  return result;
658 }
double weightedSum(const std::vector< CandidatePtr > &inColl_, double eta, double phi) const
std::unique_ptr< tau::RecoTauQualityCuts > pileupQcutsPUTrackSelection_
std::unique_ptr< tau::RecoTauVertexAssociator > vertexAssociator_
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
#define LogTrace(id)
std::vector< std::unique_ptr< FootprintCorrection > > footprintCorrections_
void push_back(D *&d)
Definition: OwnVector.h:326
def move(src, dest)
Definition: eostools.py:511
void reserve(size_t)
Definition: OwnVector.h:320
#define LogDebug(id)

◆ fillDescriptions()

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

Definition at line 660 of file PFRecoTauDiscriminationByIsolationContainer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), submitPVResolutionJobs::desc, reco::tau::RecoTauQualityCuts::fillDescriptions(), ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

660  {
661  // pfRecoTauDiscriminationByIsolationContainer
663  desc.add<edm::InputTag>("PFTauProducer", edm::InputTag("pfRecoTauProducer"));
664 
665  edm::ParameterSetDescription desc_qualityCuts;
667  desc.add<edm::ParameterSetDescription>("qualityCuts", desc_qualityCuts);
668 
669  desc.add<double>("minTauPtForNoIso", -99.0);
670  desc.add<edm::InputTag>("vertexSrc", edm::InputTag("offlinePrimaryVertices"));
671  desc.add<double>("rhoConeSize", 0.5);
672  desc.add<edm::InputTag>("rhoProducer", edm::InputTag("fixedGridRhoFastjetAll"));
673 
674  {
676  vpsd1.add<std::string>("selection");
677  vpsd1.add<std::string>("offset");
678  desc.addVPSet("footprintCorrections", vpsd1, {});
679  }
680 
681  desc.add<std::string>("deltaBetaFactor", "0.38");
682  desc.add<bool>("applyFootprintCorrection", false);
683  {
684  edm::ParameterSetDescription pset_Prediscriminants;
685  pset_Prediscriminants.add<std::string>("BooleanOperator", "and");
686  {
688  psd1.add<double>("cut", 0.5);
689  psd1.add<edm::InputTag>("Producer", edm::InputTag("pfRecoTauDiscriminationByLeadingTrackFinding"));
690  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("leadTrack", psd1);
691  }
692  {
694  psd1.add<double>("cut", 0.5);
695  psd1.add<edm::InputTag>("Producer", edm::InputTag("hpsPFTauDiscriminationByDecayModeFindingNewDMs"));
696  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("decayMode", psd1);
697  }
698  {
700  psd1.add<double>("cut", 0.5);
701  psd1.add<edm::InputTag>("Producer", edm::InputTag("hpsPFTauDiscriminationByLooseChargedIsolation"));
702  pset_Prediscriminants.addOptional<edm::ParameterSetDescription>("preIso", psd1);
703  }
704  desc.add<edm::ParameterSetDescription>("Prediscriminants", pset_Prediscriminants);
705  }
706 
707  desc.add<int>("verbosity", 0);
708 
709  desc.add<bool>("deltaBetaPUTrackPtCutOverride", false);
710  desc.add<bool>("applyRhoCorrection", false);
711 
712  desc.add<double>("WeightECALIsolation", 1.0);
713  desc.add<double>("rhoUEOffsetCorrection", 1.0);
714  desc.add<double>("deltaBetaPUTrackPtCutOverride_val", -1.5);
715  desc.add<double>("isoConeSizeForDeltaBeta", 0.5);
716  desc.add<double>("customOuterCone", -1.0);
717  desc.add<edm::InputTag>("particleFlowSrc", edm::InputTag("particleFlow"));
718 
719  // options for various stored ID raw values
720  edm::ParameterSetDescription desc_idlist;
721  desc_idlist.add<string>("IDname"); //not needed by producer but required for mapping at PAT level
722  desc_idlist.add<bool>("storeRawSumPt", false);
723  desc_idlist.add<bool>("storeRawPUsumPt", false);
724  desc_idlist.add<bool>("storeRawOccupancy", false);
725  desc_idlist.add<bool>("storeRawFootprintCorrection", false);
726  desc_idlist.add<bool>("storeRawPhotonSumPt_outsideSignalCone", false);
727  desc_idlist.add<bool>("ApplyDiscriminationByECALIsolation", false);
728  desc_idlist.add<bool>("ApplyDiscriminationByWeightedECALIsolation", false);
729  desc_idlist.add<bool>("ApplyDiscriminationByTrackerIsolation", false);
730  desc_idlist.add<bool>("applyDeltaBetaCorrection", false);
731  desc_idlist.add<bool>("UseAllPFCandsForWeights", false);
732  desc.addVPSet("IDdefinitions", desc_idlist, {});
733  // options for various stored ID WPs
734  edm::ParameterSetDescription desc_idwplist;
735  desc_idwplist.add<string>("IDname"); //not needed by producer but required for mapping at PAT level
736  desc_idwplist.add<std::vector<string>>("referenceRawIDNames")
737  ->setComment(
738  "List of raw IDs defined in 'IDdefinitions' to pass all respective conditions defined in "
739  "'maximumAbsoluteValues', 'maximumRelativeValues' , and 'relativeValueOffsets'");
740  desc_idwplist.add<std::vector<double>>("maximumAbsoluteValues", {});
741  desc_idwplist.add<std::vector<double>>("maximumRelativeValues", {});
742  desc_idwplist.add<std::vector<double>>("relativeValueOffsets", {});
743  desc.addVPSet("IDWPdefinitions", desc_idwplist, {});
744 
745  descriptions.add("pfRecoTauDiscriminationByIsolationContainer", desc);
746 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
static void fillDescriptions(edm::ParameterSetDescription &descriptions)
Declare all parameters read from python config file.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)

◆ weightedSum()

double PFRecoTauDiscriminationByIsolationContainer::weightedSum ( const std::vector< CandidatePtr > &  inColl_,
double  eta,
double  phi 
) const
inline

Definition at line 212 of file PFRecoTauDiscriminationByIsolationContainer.cc.

References reco::deltaR2(), PVValHelper::eta, MillePedeFileConverter_cfg::out, and reco::phi().

212  {
213  double out = 1.0;
214  for (auto const& inObj_ : inColl_) {
215  double sum = (inObj_->pt() * inObj_->pt()) / (deltaR2(eta, phi, inObj_->eta(), inObj_->phi()));
216  if (sum > 1.0)
217  out *= sum;
218  }
219  return out;
220  }

Member Data Documentation

◆ applyDeltaBetaCorrection_

std::vector<bool> PFRecoTauDiscriminationByIsolationContainer::applyDeltaBetaCorrection_
private

◆ applyFootprintCorrection_

bool PFRecoTauDiscriminationByIsolationContainer::applyFootprintCorrection_
private

◆ applyRhoCorrection_

bool PFRecoTauDiscriminationByIsolationContainer::applyRhoCorrection_
private

◆ calculateWeights_

std::vector<bool> PFRecoTauDiscriminationByIsolationContainer::calculateWeights_
private

◆ chargedPFCandidatesInEvent_

std::vector<reco::CandidatePtr> PFRecoTauDiscriminationByIsolationContainer::chargedPFCandidatesInEvent_
private

◆ customIsoCone_

double PFRecoTauDiscriminationByIsolationContainer::customIsoCone_
private

◆ deltaBetaCollectionCone_

double PFRecoTauDiscriminationByIsolationContainer::deltaBetaCollectionCone_
private

◆ deltaBetaFactorThisEvent_

double PFRecoTauDiscriminationByIsolationContainer::deltaBetaFactorThisEvent_
private

◆ deltaBetaFormula_

std::unique_ptr<TFormula> PFRecoTauDiscriminationByIsolationContainer::deltaBetaFormula_
private

◆ deltaBetaNeeded_

bool PFRecoTauDiscriminationByIsolationContainer::deltaBetaNeeded_
private

◆ footprintCorrections_

std::vector<std::unique_ptr<FootprintCorrection> > PFRecoTauDiscriminationByIsolationContainer::footprintCorrections_
private

◆ gammasNeeded_

bool PFRecoTauDiscriminationByIsolationContainer::gammasNeeded_
private

◆ includeGammas_

std::vector<bool> PFRecoTauDiscriminationByIsolationContainer::includeGammas_
private

◆ includeTracks_

std::vector<bool> PFRecoTauDiscriminationByIsolationContainer::includeTracks_
private

◆ maxAbsValue_

std::vector<std::vector<double> > PFRecoTauDiscriminationByIsolationContainer::maxAbsValue_
private

◆ maxRelValue_

std::vector<std::vector<double> > PFRecoTauDiscriminationByIsolationContainer::maxRelValue_
private

◆ minPtForNoIso_

double PFRecoTauDiscriminationByIsolationContainer::minPtForNoIso_
private

◆ moduleLabel_

std::string PFRecoTauDiscriminationByIsolationContainer::moduleLabel_
private

◆ offsetRelValue_

std::vector<std::vector<double> > PFRecoTauDiscriminationByIsolationContainer::offsetRelValue_
private

◆ pfCand_token

edm::EDGetTokenT<edm::View<reco::Candidate> > PFRecoTauDiscriminationByIsolationContainer::pfCand_token
private

◆ pfCandSrc_

edm::InputTag PFRecoTauDiscriminationByIsolationContainer::pfCandSrc_
private

◆ pileupQcutsGeneralQCuts_

std::unique_ptr<tau::RecoTauQualityCuts> PFRecoTauDiscriminationByIsolationContainer::pileupQcutsGeneralQCuts_
private

◆ pileupQcutsPUTrackSelection_

std::unique_ptr<tau::RecoTauQualityCuts> PFRecoTauDiscriminationByIsolationContainer::pileupQcutsPUTrackSelection_
private

◆ qcuts_

std::unique_ptr<tau::RecoTauQualityCuts> PFRecoTauDiscriminationByIsolationContainer::qcuts_
private

◆ qualityCutsPSet_

edm::ParameterSet PFRecoTauDiscriminationByIsolationContainer::qualityCutsPSet_
private

◆ rawValue_reference_

std::vector<std::vector<int> > PFRecoTauDiscriminationByIsolationContainer::rawValue_reference_
private

◆ rho_token

edm::EDGetTokenT<double> PFRecoTauDiscriminationByIsolationContainer::rho_token
private

◆ rhoConeSize_

double PFRecoTauDiscriminationByIsolationContainer::rhoConeSize_
private

◆ rhoCorrectionThisEvent_

double PFRecoTauDiscriminationByIsolationContainer::rhoCorrectionThisEvent_
private

◆ rhoProducer_

edm::InputTag PFRecoTauDiscriminationByIsolationContainer::rhoProducer_
private

◆ rhoThisEvent_

double PFRecoTauDiscriminationByIsolationContainer::rhoThisEvent_
private

◆ rhoUEOffsetCorrection_

double PFRecoTauDiscriminationByIsolationContainer::rhoUEOffsetCorrection_
private

◆ storeRawValue_

std::vector<StoredRawType> PFRecoTauDiscriminationByIsolationContainer::storeRawValue_
private

◆ tracksNeeded_

bool PFRecoTauDiscriminationByIsolationContainer::tracksNeeded_
private

◆ useAllPFCandsForWeights_

std::vector<bool> PFRecoTauDiscriminationByIsolationContainer::useAllPFCandsForWeights_
private

◆ verbosity_

int PFRecoTauDiscriminationByIsolationContainer::verbosity_
private

◆ vertex_token

edm::EDGetTokenT<reco::VertexCollection> PFRecoTauDiscriminationByIsolationContainer::vertex_token
private

◆ vertexAssociator_

std::unique_ptr<tau::RecoTauVertexAssociator> PFRecoTauDiscriminationByIsolationContainer::vertexAssociator_
private

◆ vertexSrc_

edm::InputTag PFRecoTauDiscriminationByIsolationContainer::vertexSrc_
private

◆ weightGammas_

double PFRecoTauDiscriminationByIsolationContainer::weightGammas_
private

◆ weightsNeeded_

bool PFRecoTauDiscriminationByIsolationContainer::weightsNeeded_
private