22 static std::unique_ptr<DeepMETCache> initializeGlobalCache(
const edm::ParameterSet&);
38 inline static const std::unordered_map<int, int32_t> charge_embedding_{{-1, 0}, {0, 1}, {1, 2}};
39 inline static const std::unordered_map<int, int32_t> pdg_id_embedding_{
40 {-211, 0}, {-13, 1}, {-11, 2}, {0, 3}, {1, 4}, {2, 5}, {11, 6}, {13, 7}, {22, 8}, {130, 9}, {211, 10}};
44 float scale_and_rm_outlier(
float val,
float scale) {
45 float ret_val = val *
scale;
46 if (ret_val > 1e6 || ret_val < -1e6)
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>();
60 const tensorflow::TensorShape shape({1,
max_n_pf_, 8});
61 const tensorflow::TensorShape cat_shape({1,
max_n_pf_, 1});
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);
76 input_.flat<
float>().setZero();
82 float px_leptons = 0.;
83 float py_leptons = 0.;
85 for (
const auto&
pf : pfs) {
88 if (pdg_id == 11 || pdg_id == 13) {
89 px_leptons +=
pf.px();
90 py_leptons +=
pf.py();
97 float* ptr = &
input_.tensor<
float, 3>()(0, i_pf, 0);
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);
116 std::vector<tensorflow::Tensor>
outputs;
117 const std::vector<std::string> output_names = {
"output/BiasAdd"};
123 float px = outputs[0].tensor<
float, 2>()(0, 0) *
norm_;
124 float py = outputs[0].tensor<
float, 2>()(0, 1) *
norm_;
129 auto pf_mets = std::make_unique<pat::METCollection>();
131 pf_mets->emplace_back(
reco::MET(p4, {}));
137 std::unique_ptr<DeepMETCache>
cache = std::make_unique<DeepMETCache>();
141 if (!graphPath.empty()) {
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);
Session * createSession(SessionOptions &sessionOptions)
T getParameter(std::string const &) const
std::vector< NamedTensor > NamedTensorList
const bool ignore_leptons_
std::atomic< tensorflow::GraphDef * > graph_def
void produce(edm::Event &event, const edm::EventSetup &setup) override
tensorflow::Tensor input_cat0_
GraphDef * loadGraphDef(const std::string &pbFile)
tensorflow::Tensor input_cat1_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def setup(process, global_tag, zero_tesla=False)
static void globalEndJob(DeepMETCache *)
static std::unique_ptr< DeepMETCache > initializeGlobalCache(const edm::ParameterSet &)
tensorflow::Tensor input_
DeepMETProducer(const edm::ParameterSet &, const DeepMETCache *)
#define DEFINE_FWK_MODULE(type)
static const std::unordered_map< int, int32_t > pdg_id_embedding_
Abs< T >::type abs(const T &t)
tensorflow::Session * session_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tensorflow::Tensor input_cat2_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
const unsigned int max_n_pf_
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, const std::vector< std::string > &targetNodes, std::vector< Tensor > *outputs)
std::string fullPath() const
static const std::unordered_map< int, int32_t > charge_embedding_
const edm::EDGetTokenT< std::vector< pat::PackedCandidate > > pf_token_