CMS 3D CMS Logo

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

Public Member Functions

 DeepMETProducer (const edm::ParameterSet &, const DeepMETCache *)
 
void produce (edm::Event &event, const edm::EventSetup &setup) override
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::GlobalCache< DeepMETCache > >
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
static void globalEndJob (DeepMETCache *)
 
static std::unique_ptr< DeepMETCacheinitializeGlobalCache (const edm::ParameterSet &)
 

Private Attributes

const bool ignore_leptons_
 
tensorflow::Tensor input_
 
tensorflow::Tensor input_cat0_
 
tensorflow::Tensor input_cat1_
 
tensorflow::Tensor input_cat2_
 
const unsigned int max_n_pf_
 
const float norm_
 
const edm::EDGetTokenT< std::vector< pat::PackedCandidate > > pf_token_
 
tensorflow::Session * session_
 

Static Private Attributes

static const std::unordered_map< int, int32_t > charge_embedding_ {{-1, 0}, {0, 1}, {1, 2}}
 
static const std::unordered_map< int, int32_t > pdg_id_embedding_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::GlobalCache< DeepMETCache > >
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
 

Detailed Description

Definition at line 15 of file DeepMETProducer.cc.

Constructor & Destructor Documentation

◆ DeepMETProducer()

DeepMETProducer::DeepMETProducer ( const edm::ParameterSet cfg,
const DeepMETCache cache 
)
explicit

Definition at line 52 of file DeepMETProducer.cc.

53  : pf_token_(consumes<std::vector<pat::PackedCandidate> >(cfg.getParameter<edm::InputTag>("pf_src"))),
54  norm_(cfg.getParameter<double>("norm_factor")),
55  ignore_leptons_(cfg.getParameter<bool>("ignore_leptons")),
56  max_n_pf_(cfg.getParameter<unsigned int>("max_n_pf")),
58  produces<pat::METCollection>();
59 
60  const tensorflow::TensorShape shape({1, max_n_pf_, 8});
61  const tensorflow::TensorShape cat_shape({1, max_n_pf_, 1});
62 
63  input_ = tensorflow::Tensor(tensorflow::DT_FLOAT, shape);
64  input_cat0_ = tensorflow::Tensor(tensorflow::DT_FLOAT, cat_shape);
65  input_cat1_ = tensorflow::Tensor(tensorflow::DT_FLOAT, cat_shape);
66  input_cat2_ = tensorflow::Tensor(tensorflow::DT_FLOAT, cat_shape);
67 }

References input_, input_cat0_, input_cat1_, input_cat2_, and max_n_pf_.

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 151 of file DeepMETProducer.cc.

151  {
153  desc.add<edm::InputTag>("pf_src", edm::InputTag("packedPFCandidates"));
154  desc.add<bool>("ignore_leptons", false);
155  desc.add<double>("norm_factor", 50.);
156  desc.add<unsigned int>("max_n_pf", 4500);
157  desc.add<std::string>("graph_path", "RecoMET/METPUSubtraction/data/deepmet/deepmet_v1_2018.pb");
158  descriptions.add("deepMETProducer", desc);
159 }

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), HLT_2018_cff::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ globalEndJob()

void DeepMETProducer::globalEndJob ( DeepMETCache cache)
static

Definition at line 149 of file DeepMETProducer.cc.

149 { delete cache->graph_def; }

References utilities::cache().

◆ initializeGlobalCache()

std::unique_ptr< DeepMETCache > DeepMETProducer::initializeGlobalCache ( const edm::ParameterSet params)
static

Definition at line 135 of file DeepMETProducer.cc.

135  {
136  // this method is supposed to create, initialize and return a DeepMETCache instance
137  std::unique_ptr<DeepMETCache> cache = std::make_unique<DeepMETCache>();
138 
139  // load the graph def and save it
140  std::string graphPath = params.getParameter<std::string>("graph_path");
141  if (!graphPath.empty()) {
142  graphPath = edm::FileInPath(graphPath).fullPath();
143  cache->graph_def = tensorflow::loadGraphDef(graphPath);
144  }
145 
146  return cache;
147 }

References utilities::cache(), edm::FileInPath::fullPath(), tensorflow::loadGraphDef(), CalibrationSummaryClient_cfi::params, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ produce()

void DeepMETProducer::produce ( edm::Event event,
const edm::EventSetup setup 
)
override

Definition at line 69 of file DeepMETProducer.cc.

69  {
70  auto const& pfs = event.get(pf_token_);
71 
72  const tensorflow::NamedTensorList input_list = {
73  {"input", input_}, {"input_cat0", input_cat0_}, {"input_cat1", input_cat1_}, {"input_cat2", input_cat2_}};
74 
75  // Set all inputs to zero
76  input_.flat<float>().setZero();
77  input_cat0_.flat<float>().setZero();
78  input_cat1_.flat<float>().setZero();
79  input_cat2_.flat<float>().setZero();
80 
81  size_t i_pf = 0;
82  float px_leptons = 0.;
83  float py_leptons = 0.;
84  const float scale = 1. / norm_;
85  for (const auto& pf : pfs) {
86  if (ignore_leptons_) {
87  int pdg_id = std::abs(pf.pdgId());
88  if (pdg_id == 11 || pdg_id == 13) {
89  px_leptons += pf.px();
90  py_leptons += pf.py();
91  continue;
92  }
93  }
94 
95  // fill the tensor
96  // PF keys [b'PF_dxy', b'PF_dz', b'PF_eta', b'PF_mass', b'PF_pt', b'PF_puppiWeight', b'PF_px', b'PF_py']
97  float* ptr = &input_.tensor<float, 3>()(0, i_pf, 0);
98  *ptr = pf.dxy();
99  *(++ptr) = pf.dz();
100  *(++ptr) = pf.eta();
101  *(++ptr) = pf.mass();
102  *(++ptr) = scale_and_rm_outlier(pf.pt(), scale);
103  *(++ptr) = pf.puppiWeight();
104  *(++ptr) = scale_and_rm_outlier(pf.px(), scale);
105  *(++ptr) = scale_and_rm_outlier(pf.py(), scale);
106  input_cat0_.tensor<float, 3>()(0, i_pf, 0) = charge_embedding_.at(pf.charge());
107  input_cat1_.tensor<float, 3>()(0, i_pf, 0) = pdg_id_embedding_.at(pf.pdgId());
108  input_cat2_.tensor<float, 3>()(0, i_pf, 0) = pf.fromPV();
109 
110  ++i_pf;
111  if (i_pf > max_n_pf_) {
112  break; // output a warning?
113  }
114  }
115 
116  std::vector<tensorflow::Tensor> outputs;
117  const std::vector<std::string> output_names = {"output/BiasAdd"};
118 
119  // run the inference and return met
121 
122  // The DNN directly estimates the missing px and py, not the recoil
123  float px = outputs[0].tensor<float, 2>()(0, 0) * norm_;
124  float py = outputs[0].tensor<float, 2>()(0, 1) * norm_;
125 
126  px -= px_leptons;
127  py -= py_leptons;
128 
129  auto pf_mets = std::make_unique<pat::METCollection>();
130  const reco::Candidate::LorentzVector p4(px, py, 0., std::hypot(px, py));
131  pf_mets->emplace_back(reco::MET(p4, {}));
132  event.put(std::move(pf_mets));
133 }

References funct::abs(), charge_embedding_, dqmMemoryStats::float, ignore_leptons_, input_, input_cat0_, input_cat1_, input_cat2_, max_n_pf_, eostools::move(), norm_, hltPfDeepFlavourJetTags_cfi::output_names, PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs, p4, HiggsValidation_cfi::pdg_id, pdg_id_embedding_, packedPFCandidateRefMixer_cfi::pf, pf_token_, multPhiCorr_741_25nsDY_cfi::px, multPhiCorr_741_25nsDY_cfi::py, tensorflow::run(), Scenarios_cff::scale, and session_.

Member Data Documentation

◆ charge_embedding_

const std::unordered_map<int, int32_t> DeepMETProducer::charge_embedding_ {{-1, 0}, {0, 1}, {1, 2}}
inlinestaticprivate

Definition at line 38 of file DeepMETProducer.cc.

Referenced by produce().

◆ ignore_leptons_

const bool DeepMETProducer::ignore_leptons_
private

Definition at line 28 of file DeepMETProducer.cc.

Referenced by produce().

◆ input_

tensorflow::Tensor DeepMETProducer::input_
private

Definition at line 33 of file DeepMETProducer.cc.

Referenced by DeepMETProducer(), and produce().

◆ input_cat0_

tensorflow::Tensor DeepMETProducer::input_cat0_
private

Definition at line 34 of file DeepMETProducer.cc.

Referenced by DeepMETProducer(), and produce().

◆ input_cat1_

tensorflow::Tensor DeepMETProducer::input_cat1_
private

Definition at line 35 of file DeepMETProducer.cc.

Referenced by DeepMETProducer(), and produce().

◆ input_cat2_

tensorflow::Tensor DeepMETProducer::input_cat2_
private

Definition at line 36 of file DeepMETProducer.cc.

Referenced by DeepMETProducer(), and produce().

◆ max_n_pf_

const unsigned int DeepMETProducer::max_n_pf_
private

Definition at line 29 of file DeepMETProducer.cc.

Referenced by DeepMETProducer(), and produce().

◆ norm_

const float DeepMETProducer::norm_
private

Definition at line 27 of file DeepMETProducer.cc.

Referenced by produce().

◆ pdg_id_embedding_

const std::unordered_map<int, int32_t> DeepMETProducer::pdg_id_embedding_
inlinestaticprivate
Initial value:
{
{-211, 0}, {-13, 1}, {-11, 2}, {0, 3}, {1, 4}, {2, 5}, {11, 6}, {13, 7}, {22, 8}, {130, 9}, {211, 10}}

Definition at line 39 of file DeepMETProducer.cc.

Referenced by produce().

◆ pf_token_

const edm::EDGetTokenT<std::vector<pat::PackedCandidate> > DeepMETProducer::pf_token_
private

Definition at line 26 of file DeepMETProducer.cc.

Referenced by produce().

◆ session_

tensorflow::Session* DeepMETProducer::session_
private

Definition at line 31 of file DeepMETProducer.cc.

Referenced by produce().

HiggsValidation_cfi.pdg_id
pdg_id
Definition: HiggsValidation_cfi.py:6
tensorflow::createSession
Session * createSession(SessionOptions &sessionOptions)
Definition: TensorFlow.cc:85
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
hltPfDeepFlavourJetTags_cfi.output_names
output_names
Definition: hltPfDeepFlavourJetTags_cfi.py:21
DeepMETProducer::charge_embedding_
static const std::unordered_map< int, int32_t > charge_embedding_
Definition: DeepMETProducer.cc:38
PatBasicFWLiteJetAnalyzer_Selector_cfg.outputs
outputs
Definition: PatBasicFWLiteJetAnalyzer_Selector_cfg.py:48
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
DeepMETProducer::input_cat2_
tensorflow::Tensor input_cat2_
Definition: DeepMETProducer.cc:36
DeepMETProducer::ignore_leptons_
const bool ignore_leptons_
Definition: DeepMETProducer.cc:28
DeepMETProducer::pf_token_
const edm::EDGetTokenT< std::vector< pat::PackedCandidate > > pf_token_
Definition: DeepMETProducer.cc:26
edm::FileInPath
Definition: FileInPath.h:64
reco::MET
Definition: MET.h:41
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
DeepMETProducer::input_cat0_
tensorflow::Tensor input_cat0_
Definition: DeepMETProducer.cc:34
utilities.cache
def cache(function)
Definition: utilities.py:3
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
DeepMETProducer::max_n_pf_
const unsigned int max_n_pf_
Definition: DeepMETProducer.cc:29
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
DeepMETProducer::norm_
const float norm_
Definition: DeepMETProducer.cc:27
tensorflow::NamedTensorList
std::vector< NamedTensor > NamedTensorList
Definition: TensorFlow.h:30
p4
double p4[4]
Definition: TauolaWrapper.h:92
looper.cfg
cfg
Definition: looper.py:297
tensorflow::loadGraphDef
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
eostools.move
def move(src, dest)
Definition: eostools.py:511
DeepMETProducer::input_cat1_
tensorflow::Tensor input_cat1_
Definition: DeepMETProducer.cc:35
DeepMETProducer::session_
tensorflow::Session * session_
Definition: DeepMETProducer.cc:31
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
tensorflow::run
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Definition: TensorFlow.cc:211
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DeepMETProducer::pdg_id_embedding_
static const std::unordered_map< int, int32_t > pdg_id_embedding_
Definition: DeepMETProducer.cc:39
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
DeepMETProducer::input_
tensorflow::Tensor input_
Definition: DeepMETProducer.cc:33
edm::InputTag
Definition: InputTag.h:15
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163