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

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 > >
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

 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
 
 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 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

Constructor & Destructor Documentation

◆ DeepTauBase()

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

Definition at line 91 of file DeepTauBase.cc.

References andPrediscriminants_, looper::cfg, deep_tau::DeepTauBase::TauDiscInfo< ConsumeType >::cut, DMR_cfg::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_.

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

◆ ~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 182 of file DeepTauBase.cc.

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

Referenced by produce().

182  {
183  for (const auto& output_desc : outputs_) {
184  const WPList* working_points = nullptr;
185  if (workingPoints_.find(output_desc.first) != workingPoints_.end()) {
186  working_points = &workingPoints_.at(output_desc.first);
187  }
188  auto result = output_desc.second.get_value(taus, pred, working_points, is_online_);
189  event.put(std::move(result), output_desc.first);
190  }
191  }
working_points
Definition: FWLite.py:134
std::vector< CutterPtr > WPList
Definition: DeepTauBase.h:78
OutputCollection outputs_
Definition: DeepTauBase.h:134
std::map< std::string, WPList > workingPoints_
Definition: DeepTauBase.h:132
def move(src, dest)
Definition: eostools.py:511

◆ getPredictions()

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

Implemented in DeepTauId.

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

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

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

◆ produce()

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

Definition at line 151 of file DeepTauBase.cc.

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

151  {
153  event.getByToken(tausToken_, taus);
154  edm::ProductID tauProductID = taus.id();
155 
156  // load prediscriminators
157  size_t nPrediscriminants =
159  for (size_t iDisc = 0; iDisc < nPrediscriminants; ++iDisc) {
160  edm::ProductID discKeyId;
161  if (is_online_) {
162  recoPrediscriminants_[iDisc].fill(event);
163  discKeyId = recoPrediscriminants_[iDisc].handle->keyProduct().id();
164  } else {
165  patPrediscriminants_[iDisc].fill(event);
166  discKeyId = patPrediscriminants_[iDisc].handle->keyProduct().id();
167  }
168 
169  // Check to make sure the product is correct for the discriminator.
170  // If not, throw a more informative exception.
171  if (tauProductID != discKeyId) {
172  throw cms::Exception("MisconfiguredPrediscriminant")
173  << "The tau collection has product ID: " << tauProductID
174  << " but the pre-discriminator is keyed with product ID: " << discKeyId << std::endl;
175  }
176  }
177 
178  const tensorflow::Tensor& pred = getPredictions(event, taus);
179  createOutputs(event, pred, taus);
180  }
edm::EDGetTokenT< TauCollection > tausToken_
Definition: DeepTauBase.h:129
virtual tensorflow::Tensor getPredictions(edm::Event &event, edm::Handle< TauCollection > taus)=0
virtual void createOutputs(edm::Event &event, const tensorflow::Tensor &pred, edm::Handle< TauCollection > taus)
Definition: DeepTauBase.cc:182
std::vector< TauDiscInfo< pat::PATTauDiscriminator > > patPrediscriminants_
Definition: DeepTauBase.h:112
std::vector< TauDiscInfo< reco::PFTauDiscriminator > > recoPrediscriminants_
Definition: DeepTauBase.h:113
Definition: event.py:1

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

Definition at line 134 of file DeepTauBase.h.

Referenced by createOutputs(), DeepTauBase(), and DeepTauId::GetOutputs().

◆ 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 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 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().