CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes | Private Member Functions
deep_tau::DeepTauBase Class Referenceabstract

#include <DeepTauBase.h>

Inheritance diagram for deep_tau::DeepTauBase:
edm::stream::EDProducer< edm::GlobalCache< DeepTauCache > > DeepTauId DPFIsolation

Classes

struct  Output
 
struct  TauDiscInfo
 

Public Types

enum  BasicDiscriminator {
  ChargedIsoPtSum, NeutralIsoPtSum, NeutralIsoPtSumWeight, FootprintCorrection,
  PhotonPtSumOutsideSignalCone, PUcorrPtSum
}
 
using CandidateCollection = edm::View< reco::Candidate >
 
using Cutter = TauWPThreshold
 
using CutterPtr = std::unique_ptr< Cutter >
 
using ElectronCollection = pat::ElectronCollection
 
using LorentzVectorXYZ = ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > >
 
using MuonCollection = pat::MuonCollection
 
using OutputCollection = std::map< std::string, Output >
 
using TauCollection = edm::View< reco::BaseTau >
 
using TauDiscriminator = reco::TauDiscriminatorContainer
 
using TauRef = edm::Ref< TauCollection >
 
using TauRefProd = edm::RefProd< TauCollection >
 
using WPList = std::vector< CutterPtr >
 
- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< DeepTauCache > >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Public Member Functions

 DeepTauBase (const edm::ParameterSet &cfg, const OutputCollection &outputs, const DeepTauCache *cache)
 
void produce (edm::Event &event, const edm::EventSetup &es) override
 
 ~DeepTauBase () override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< DeepTauCache > >
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void globalEndJob (const DeepTauCache *cache)
 
static std::unique_ptr< DeepTauCacheinitializeGlobalCache (const edm::ParameterSet &cfg)
 

Public Attributes

uint8_t andPrediscriminants_
 
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
 
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
 

Protected Attributes

const DeepTauCachecache_
 
const bool is_online_
 
OutputCollection outputs_
 
edm::EDGetTokenT< CandidateCollectionpfcandToken_
 
edm::EDGetTokenT< TauCollectiontausToken_
 
edm::EDGetTokenT< reco::VertexCollectionvtxToken_
 
std::map< std::string, WPListworkingPoints_
 

Static Protected Attributes

static const std::vector< BasicDiscriminatorrequiredBasicDiscriminators_
 
static const std::vector< BasicDiscriminatorrequiredBasicDiscriminatorsdR03_
 
static const std::map< BasicDiscriminator, std::string > stringFromDiscriminator_
 

Private Member Functions

virtual void createOutputs (edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
 
virtual tensorflow::Tensor getPredictions (edm::Event &event, edm::Handle< TauCollection > taus)=0
 

Detailed Description

Definition at line 66 of file DeepTauBase.h.

Member Typedef Documentation

◆ CandidateCollection

Definition at line 70 of file DeepTauBase.h.

◆ Cutter

Definition at line 76 of file DeepTauBase.h.

◆ CutterPtr

using deep_tau::DeepTauBase::CutterPtr = std::unique_ptr<Cutter>

Definition at line 77 of file DeepTauBase.h.

◆ ElectronCollection

Definition at line 73 of file DeepTauBase.h.

◆ LorentzVectorXYZ

using deep_tau::DeepTauBase::LorentzVectorXYZ = ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> >

Definition at line 75 of file DeepTauBase.h.

◆ MuonCollection

Definition at line 74 of file DeepTauBase.h.

◆ OutputCollection

using deep_tau::DeepTauBase::OutputCollection = std::map<std::string, Output>

Definition at line 91 of file DeepTauBase.h.

◆ TauCollection

Definition at line 69 of file DeepTauBase.h.

◆ TauDiscriminator

Definition at line 68 of file DeepTauBase.h.

◆ TauRef

Definition at line 71 of file DeepTauBase.h.

◆ TauRefProd

Definition at line 72 of file DeepTauBase.h.

◆ WPList

Definition at line 78 of file DeepTauBase.h.

Member Enumeration Documentation

◆ BasicDiscriminator

Enumerator
ChargedIsoPtSum 
NeutralIsoPtSum 
NeutralIsoPtSumWeight 
FootprintCorrection 
PhotonPtSumOutsideSignalCone 
PUcorrPtSum 

Definition at line 115 of file DeepTauBase.h.

Constructor & Destructor Documentation

◆ DeepTauBase()

deep_tau::DeepTauBase::DeepTauBase ( const edm::ParameterSet cfg,
const OutputCollection outputs,
const DeepTauCache cache 
)

Definition at line 84 of file DeepTauBase.cc.

87  : tausToken_(consumes<TauCollection>(cfg.getParameter<edm::InputTag>("taus"))),
88  pfcandToken_(consumes<CandidateCollection>(cfg.getParameter<edm::InputTag>("pfcands"))),
89  vtxToken_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>("vertices"))),
90  is_online_(cfg.getParameter<bool>("is_online")),
91  outputs_(outputCollection),
92  cache_(cache) {
93  for (const auto& output_desc : outputs_) {
94  produces<TauDiscriminator>(output_desc.first);
95  const auto& cut_list = cfg.getParameter<std::vector<std::string>>(output_desc.first + "WP");
96  for (const std::string& cut_str : cut_list) {
97  workingPoints_[output_desc.first].push_back(std::make_unique<Cutter>(cut_str));
98  }
99  }
100 
101  // prediscriminant operator
102  // require the tau to pass the following prediscriminants
103  const edm::ParameterSet& prediscriminantConfig = cfg.getParameter<edm::ParameterSet>("Prediscriminants");
104 
105  // determine boolean operator used on the prediscriminants
106  std::string pdBoolOperator = prediscriminantConfig.getParameter<std::string>("BooleanOperator");
107  // convert string to lowercase
108  transform(pdBoolOperator.begin(), pdBoolOperator.end(), pdBoolOperator.begin(), ::tolower);
109 
110  if (pdBoolOperator == "and") {
111  andPrediscriminants_ = 0x1; //use chars instead of bools so we can do a bitwise trick later
112  } else if (pdBoolOperator == "or") {
113  andPrediscriminants_ = 0x0;
114  } else {
115  throw cms::Exception("TauDiscriminationProducerBase")
116  << "PrediscriminantBooleanOperator defined incorrectly, options are: AND,OR";
117  }
118 
119  // get the list of prediscriminants
120  std::vector<std::string> prediscriminantsNames =
121  prediscriminantConfig.getParameterNamesForType<edm::ParameterSet>();
122 
123  for (auto const& iDisc : prediscriminantsNames) {
124  const edm::ParameterSet& iPredisc = prediscriminantConfig.getParameter<edm::ParameterSet>(iDisc);
125  const edm::InputTag& label = iPredisc.getParameter<edm::InputTag>("Producer");
126  double cut = iPredisc.getParameter<double>("cut");
127 
128  if (is_online_) {
129  TauDiscInfo<reco::PFTauDiscriminator> thisDiscriminator;
130  thisDiscriminator.label = label;
131  thisDiscriminator.cut = cut;
132  thisDiscriminator.disc_token = consumes<reco::PFTauDiscriminator>(label);
133  recoPrediscriminants_.push_back(thisDiscriminator);
134  } else {
135  TauDiscInfo<pat::PATTauDiscriminator> thisDiscriminator;
136  thisDiscriminator.label = label;
137  thisDiscriminator.cut = cut;
138  thisDiscriminator.disc_token = consumes<pat::PATTauDiscriminator>(label);
139  patPrediscriminants_.push_back(thisDiscriminator);
140  }
141  }
142  }

References andPrediscriminants_, looper::cfg, TkAlMuonSelectors_cfi::cut, deep_tau::DeepTauBase::TauDiscInfo< ConsumeType >::cut, deep_tau::DeepTauBase::TauDiscInfo< ConsumeType >::disc_token, Exception, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), is_online_, label, deep_tau::DeepTauBase::TauDiscInfo< ConsumeType >::label, outputs_, patPrediscriminants_, recoPrediscriminants_, AlCaHLTBitMon_QueryRunRegistry::string, HcalDetIdTransform::transform(), and workingPoints_.

◆ ~DeepTauBase()

deep_tau::DeepTauBase::~DeepTauBase ( )
inlineoverride

Definition at line 94 of file DeepTauBase.h.

94 {}

Member Function Documentation

◆ createOutputs()

void deep_tau::DeepTauBase::createOutputs ( edm::Event event,
const tensorflow::Tensor &  pred,
edm::Handle< TauCollection taus 
)
privatevirtual

Definition at line 175 of file DeepTauBase.cc.

175  {
176  for (const auto& output_desc : outputs_) {
177  auto result = output_desc.second.get_value(taus, pred, workingPoints_.at(output_desc.first), is_online_);
178  event.put(std::move(result), output_desc.first);
179  }
180  }

References is_online_, eostools::move(), outputs_, mps_fire::result, Tau3MuMonitor_cff::taus, and workingPoints_.

Referenced by produce().

◆ getPredictions()

virtual tensorflow::Tensor deep_tau::DeepTauBase::getPredictions ( edm::Event event,
edm::Handle< TauCollection taus 
)
privatepure virtual

Implemented in DeepTauId, and DPFIsolation.

Referenced by produce().

◆ globalEndJob()

static void deep_tau::DeepTauBase::globalEndJob ( const DeepTauCache cache)
inlinestatic

Definition at line 99 of file DeepTauBase.h.

99 {}

◆ initializeGlobalCache()

std::unique_ptr< DeepTauCache > deep_tau::DeepTauBase::initializeGlobalCache ( const edm::ParameterSet cfg)
static

Definition at line 182 of file DeepTauBase.cc.

182  {
183  const auto graph_name_vector = cfg.getParameter<std::vector<std::string>>("graph_file");
184  std::map<std::string, std::string> graph_names;
185  for (const auto& entry : graph_name_vector) {
186  const size_t sep_pos = entry.find(':');
187  std::string entry_name, graph_file;
188  if (sep_pos != std::string::npos) {
189  entry_name = entry.substr(0, sep_pos);
190  graph_file = entry.substr(sep_pos + 1);
191  } else {
192  entry_name = "";
193  graph_file = entry;
194  }
195  graph_file = edm::FileInPath(graph_file).fullPath();
196  if (graph_names.count(entry_name))
197  throw cms::Exception("DeepTauCache") << "Duplicated graph entries";
198  graph_names[entry_name] = graph_file;
199  }
200  bool mem_mapped = cfg.getParameter<bool>("mem_mapped");
201  return std::make_unique<DeepTauCache>(graph_names, mem_mapped);
202  }

References looper::cfg, mps_splice::entry, edm::FileInPath::fullPath(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ produce()

void deep_tau::DeepTauBase::produce ( edm::Event event,
const edm::EventSetup es 
)
override

Definition at line 144 of file DeepTauBase.cc.

144  {
146  event.getByToken(tausToken_, taus);
147  edm::ProductID tauProductID = taus.id();
148 
149  // load prediscriminators
150  size_t nPrediscriminants =
152  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
153  edm::ProductID discKeyId;
154  if (is_online_) {
155  recoPrediscriminants_[iDisc].fill(event);
156  discKeyId = recoPrediscriminants_[iDisc].handle->keyProduct().id();
157  } else {
158  patPrediscriminants_[iDisc].fill(event);
159  discKeyId = patPrediscriminants_[iDisc].handle->keyProduct().id();
160  }
161 
162  // Check to make sure the product is correct for the discriminator.
163  // If not, throw a more informative exception.
164  if (tauProductID != discKeyId) {
165  throw cms::Exception("MisconfiguredPrediscriminant")
166  << "The tau collection has product ID: " << tauProductID
167  << " but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
168  }
169  }
170 
171  const tensorflow::Tensor& pred = getPredictions(event, taus);
172  createOutputs(event, pred, taus);
173  }

References createOutputs(), Exception, getPredictions(), is_online_, patPrediscriminants_, recoPrediscriminants_, Tau3MuMonitor_cff::taus, and tausToken_.

Member Data Documentation

◆ andPrediscriminants_

uint8_t deep_tau::DeepTauBase::andPrediscriminants_

Definition at line 111 of file DeepTauBase.h.

Referenced by DeepTauBase(), and DeepTauId::getPredictions().

◆ cache_

const DeepTauCache* deep_tau::DeepTauBase::cache_
protected

◆ is_online_

const bool deep_tau::DeepTauBase::is_online_
protected

Definition at line 133 of file DeepTauBase.h.

Referenced by createOutputs(), DeepTauBase(), DeepTauId::getPredictions(), and produce().

◆ outputs_

OutputCollection deep_tau::DeepTauBase::outputs_
protected

◆ patPrediscriminants_

std::vector<TauDiscInfo<pat::PATTauDiscriminator> > deep_tau::DeepTauBase::patPrediscriminants_

Definition at line 112 of file DeepTauBase.h.

Referenced by DeepTauBase(), DeepTauId::getPredictions(), and produce().

◆ pfcandToken_

edm::EDGetTokenT<CandidateCollection> deep_tau::DeepTauBase::pfcandToken_
protected

Definition at line 130 of file DeepTauBase.h.

Referenced by DPFIsolation::getPredictions(), and DeepTauId::getPredictions().

◆ recoPrediscriminants_

std::vector<TauDiscInfo<reco::PFTauDiscriminator> > deep_tau::DeepTauBase::recoPrediscriminants_

Definition at line 113 of file DeepTauBase.h.

Referenced by DeepTauBase(), DeepTauId::getPredictions(), and produce().

◆ requiredBasicDiscriminators_

const std::vector< bd > deep_tau::DeepTauBase::requiredBasicDiscriminators_
staticprotected
Initial value:
= {bd::ChargedIsoPtSum,
bd::NeutralIsoPtSum,
bd::NeutralIsoPtSumWeight,
bd::PhotonPtSumOutsideSignalCone,
bd::PUcorrPtSum}

Definition at line 138 of file DeepTauBase.h.

Referenced by DeepTauId::getPredictions().

◆ requiredBasicDiscriminatorsdR03_

const std::vector< bd > deep_tau::DeepTauBase::requiredBasicDiscriminatorsdR03_
staticprotected
Initial value:
= {bd::ChargedIsoPtSum,
bd::NeutralIsoPtSum,
bd::NeutralIsoPtSumWeight,
bd::PhotonPtSumOutsideSignalCone,
bd::FootprintCorrection}

Definition at line 139 of file DeepTauBase.h.

Referenced by DeepTauId::getPredictions().

◆ stringFromDiscriminator_

const std::map< bd, std::string > deep_tau::DeepTauBase::stringFromDiscriminator_
staticprotected
Initial value:
{
{bd::ChargedIsoPtSum, "ChargedIsoPtSum"},
{bd::NeutralIsoPtSum, "NeutralIsoPtSum"},
{bd::NeutralIsoPtSumWeight, "NeutralIsoPtSumWeight"},
{bd::FootprintCorrection, "TauFootprintCorrection"},
{bd::PhotonPtSumOutsideSignalCone, "PhotonPtSumOutsideSignalCone"},
{bd::PUcorrPtSum, "PUcorrPtSum"}}

Definition at line 137 of file DeepTauBase.h.

Referenced by DeepTauId::matchDiscriminatorIndices().

◆ tausToken_

edm::EDGetTokenT<TauCollection> deep_tau::DeepTauBase::tausToken_
protected

Definition at line 129 of file DeepTauBase.h.

Referenced by produce().

◆ vtxToken_

edm::EDGetTokenT<reco::VertexCollection> deep_tau::DeepTauBase::vtxToken_
protected

Definition at line 131 of file DeepTauBase.h.

Referenced by DPFIsolation::getPredictions(), and DeepTauId::getPredictions().

◆ workingPoints_

std::map<std::string, WPList> deep_tau::DeepTauBase::workingPoints_
protected

Definition at line 132 of file DeepTauBase.h.

Referenced by createOutputs(), and DeepTauBase().

deep_tau::DeepTauBase::cache_
const DeepTauCache * cache_
Definition: DeepTauBase.h:135
deep_tau::DeepTauBase::NeutralIsoPtSumWeight
Definition: DeepTauBase.h:118
deep_tau::DeepTauBase::patPrediscriminants_
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauBase.h:112
deep_tau::DeepTauBase::ChargedIsoPtSum
Definition: DeepTauBase.h:116
deep_tau::DeepTauBase::pfcandToken_
edm::EDGetTokenT< CandidateCollection > pfcandToken_
Definition: DeepTauBase.h:130
deep_tau::DeepTauBase::FootprintCorrection
Definition: DeepTauBase.h:119
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
Tau3MuMonitor_cff.taus
taus
Definition: Tau3MuMonitor_cff.py:7
mps_splice.entry
entry
Definition: mps_splice.py:68
deep_tau::DeepTauBase::vtxToken_
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: DeepTauBase.h:131
deep_tau::DeepTauBase::PUcorrPtSum
Definition: DeepTauBase.h:121
edm::Handle< TauCollection >
edm::FileInPath
Definition: FileInPath.h:64
deep_tau::DeepTauBase::workingPoints_
std::map< std::string, WPList > workingPoints_
Definition: DeepTauBase.h:132
deep_tau::DeepTauBase::NeutralIsoPtSum
Definition: DeepTauBase.h:117
deep_tau::DeepTauBase::getPredictions
virtual tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus)=0
deep_tau::DeepTauBase::is_online_
const bool is_online_
Definition: DeepTauBase.h:133
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
utilities.cache
def cache(function)
Definition: utilities.py:3
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
deep_tau::DeepTauBase::outputs_
OutputCollection outputs_
Definition: DeepTauBase.h:134
edm::ParameterSet
Definition: ParameterSet.h:47
edm::ParameterSet::getParameterNamesForType
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
deep_tau::DeepTauBase::PhotonPtSumOutsideSignalCone
Definition: DeepTauBase.h:120
looper.cfg
cfg
Definition: looper.py:297
eostools.move
def move(src, dest)
Definition: eostools.py:511
deep_tau::DeepTauBase::recoPrediscriminants_
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauBase.h:113
Exception
Definition: hltDiff.cc:246
deep_tau::DeepTauBase::createOutputs
virtual void createOutputs(edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
Definition: DeepTauBase.cc:175
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
deep_tau::DeepTauBase::andPrediscriminants_
uint8_t andPrediscriminants_
Definition: DeepTauBase.h:111
mps_fire.result
result
Definition: mps_fire.py:311
cms::Exception
Definition: Exception.h:70
event
Definition: event.py:1
deep_tau::DeepTauBase::tausToken_
edm::EDGetTokenT< TauCollection > tausToken_
Definition: DeepTauBase.h:129
edm::InputTag
Definition: InputTag.h:15
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::ProductID
Definition: ProductID.h:27
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163