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 hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () 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 86 of file DeepTauBase.cc.

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

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 177 of file DeepTauBase.cc.

177  {
178  for (const auto& output_desc : outputs_) {
179  const WPList* working_points = nullptr;
180  if (workingPoints_.find(output_desc.first) != workingPoints_.end()) {
181  working_points = &workingPoints_.at(output_desc.first);
182  }
183  auto result = output_desc.second.get_value(taus, pred, working_points, is_online_);
184  event.put(std::move(result), output_desc.first);
185  }
186  }

References is_online_, eostools::move(), outputs_, mps_fire::result, Tau3MuMonitor_cff::taus, FWLite::working_points, 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 188 of file DeepTauBase.cc.

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

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 146 of file DeepTauBase.cc.

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

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

◆ 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
deep_tau::DeepTauBase::WPList
std::vector< CutterPtr > WPList
Definition: DeepTauBase.h:78
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:36
edm::ParameterSet::getParameterNamesForType
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:168
deep_tau::DeepTauBase::PhotonPtSumOutsideSignalCone
Definition: DeepTauBase.h:120
looper.cfg
cfg
Definition: looper.py:297
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
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:177
deep_tau::DeepTauBase::andPrediscriminants_
uint8_t andPrediscriminants_
Definition: DeepTauBase.h:111
mps_fire.result
result
Definition: mps_fire.py:303
cms::Exception
Definition: Exception.h:70
event
Definition: event.py:1
FWLite.working_points
working_points
Definition: FWLite.py:121
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