Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11_2_X] EMTF Emulator Update to Add Displaced Muon pT & Dxy Assignment #32642

Merged
merged 9 commits into from
Feb 11, 2021
16 changes: 16 additions & 0 deletions DataFormats/L1TMuon/interface/EMTFTrack.h
Original file line number Diff line number Diff line change
@@ -60,6 +60,8 @@ namespace l1t {
second_bx(-99),
pt(-99),
pt_XML(-99),
pt_dxy(-99),
dxy(-99),
zone(-99),
ph_num(-99),
ph_q(-99),
@@ -70,6 +72,8 @@ namespace l1t {
phi_loc(-99),
phi_glob(-999),
gmt_pt(-99),
gmt_pt_dxy(-99),
gmt_dxy(-99),
gmt_phi(-999),
gmt_eta(-999),
gmt_quality(-99),
@@ -135,6 +139,8 @@ namespace l1t {
void set_second_bx(int bits) { second_bx = bits; }
void set_pt(float val) { pt = val; }
void set_pt_XML(float val) { pt_XML = val; }
void set_pt_dxy(float val) { pt_dxy = val; }
void set_dxy(float val) { dxy = val; }
void set_zone(int bits) { zone = bits; }
void set_ph_num(int bits) { ph_num = bits; }
void set_ph_q(int bits) { ph_q = bits; }
@@ -145,6 +151,8 @@ namespace l1t {
void set_phi_loc(float val) { phi_loc = val; }
void set_phi_glob(float val) { phi_glob = val; }
void set_gmt_pt(int bits) { gmt_pt = bits; }
void set_gmt_pt_dxy(int bits) { gmt_pt_dxy = bits; }
void set_gmt_dxy(int bits) { gmt_dxy = bits; }
void set_gmt_phi(int bits) { gmt_phi = bits; }
void set_gmt_eta(int bits) { gmt_eta = bits; }
void set_gmt_quality(int bits) { gmt_quality = bits; }
@@ -169,6 +177,8 @@ namespace l1t {
int Second_BX() const { return second_bx; }
float Pt() const { return pt; }
float Pt_XML() const { return pt_XML; }
float Pt_dxy() const { return pt_dxy; }
float Dxy() const { return dxy; }
int Zone() const { return zone; }
int Ph_num() const { return ph_num; }
int Ph_q() const { return ph_q; }
@@ -179,6 +189,8 @@ namespace l1t {
float Phi_loc() const { return phi_loc; }
float Phi_glob() const { return phi_glob; }
int GMT_pt() const { return gmt_pt; }
int GMT_pt_dxy() const { return gmt_pt_dxy; }
int GMT_dxy() const { return gmt_dxy; }
int GMT_phi() const { return gmt_phi; }
int GMT_eta() const { return gmt_eta; }
int GMT_quality() const { return gmt_quality; }
@@ -209,6 +221,8 @@ namespace l1t {
int second_bx; // -3 - +3.
float pt; // 0 - 255
float pt_XML; // 0 - 999
float pt_dxy; // 0 - 127
float dxy; // 0 - 3
int zone; // 0 - 3.
int ph_num;
int ph_q;
@@ -219,6 +233,8 @@ namespace l1t {
float phi_loc; // -22 - 60 (Range? - AWB 03.03.17)
float phi_glob; // +/-180.
int gmt_pt;
int gmt_pt_dxy;
int gmt_dxy;
int gmt_phi;
int gmt_eta;
int gmt_quality;
1 change: 1 addition & 0 deletions L1Trigger/L1TMuonEndCap/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@
<use name="FWCore/ParameterSet"/>
<use name="DataFormats/L1TMuon"/>
<use name="L1Trigger/L1TMuon"/>
<use name="PhysicsTools/TensorFlow"/>
7 changes: 7 additions & 0 deletions L1Trigger/L1TMuonEndCap/interface/Common.h
Original file line number Diff line number Diff line change
@@ -64,6 +64,13 @@ namespace emtf {
template <typename T>
using zone_array = std::array<T, NUM_ZONES>;

// NN features and predictions
constexpr int NUM_FEATURES = 23; // NN features
constexpr int NUM_PREDICTIONS = 2; // NN outputs

using Feature = std::array<float, NUM_FEATURES>;
using Prediction = std::array<float, NUM_PREDICTIONS>;

} // namespace emtf

#endif
5 changes: 5 additions & 0 deletions L1Trigger/L1TMuonEndCap/interface/EMTFSetup.h
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#include "L1Trigger/L1TMuonEndCap/interface/VersionControl.h"
#include "L1Trigger/L1TMuonEndCap/interface/SectorProcessorLUT.h"
#include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngine.h"
#include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineDxy.h"

class EMTFSetup {
public:
@@ -35,6 +36,8 @@ class EMTFSetup {

PtAssignmentEngine* getPtAssignmentEngine() const { return pt_assign_engine_.get(); }

PtAssignmentEngineDxy* getPtAssignmentEngineDxy() const { return pt_assign_engine_dxy_.get(); }

// Setters
//void set_fw_version(unsigned version) { fw_ver_ = version; }
//void set_pt_lut_version(unsigned version) { pt_lut_ver_ = version; }
@@ -62,6 +65,8 @@ class EMTFSetup {

// Polymorphic class
std::unique_ptr<PtAssignmentEngine> pt_assign_engine_;
// Displaced muon pT assignment
std::unique_ptr<PtAssignmentEngineDxy> pt_assign_engine_dxy_;

// Version numbers. Note: may be different from those in ConditionHelper
unsigned fw_ver_;
7 changes: 6 additions & 1 deletion L1Trigger/L1TMuonEndCap/interface/PtAssignment.h
Original file line number Diff line number Diff line change
@@ -4,11 +4,13 @@
#include "L1Trigger/L1TMuonEndCap/interface/Common.h"

class PtAssignmentEngine;
class PtAssignmentEngineDxy;
class PtAssignmentEngineAux;

class PtAssignment {
public:
void configure(PtAssignmentEngine* pt_assign_engine,
PtAssignmentEngineDxy* pt_assign_engine_dxy,
int verbose,
int endcap,
int sector,
@@ -20,7 +22,8 @@ class PtAssignment {
bool bugNegPt,
bool bugGMTPhi,
bool promoteMode7,
int modeQualVer);
int modeQualVer,
std::string pbFileName);

void process(EMTFTrackCollection& best_tracks);

@@ -29,6 +32,8 @@ class PtAssignment {
private:
PtAssignmentEngine* pt_assign_engine_;

PtAssignmentEngineDxy* pt_assign_engine_dxy_;

int verbose_, endcap_, sector_, bx_;

bool bugGMTPhi_, promoteMode7_;
4 changes: 4 additions & 0 deletions L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineAux.h
Original file line number Diff line number Diff line change
@@ -14,8 +14,10 @@ class PtAssignmentEngineAux {
public:
// Functions for GMT quantities
int getGMTPt(float pt) const;
int getGMTPtDxy(float pt) const;

float getPtFromGMTPt(int gmt_pt) const;
float getPtFromGMTPtDxy(int gmt_pt_dxy) const;

int getGMTPhi(int phi) const;
int getGMTPhiV2(int phi) const;
@@ -25,6 +27,8 @@ class PtAssignmentEngineAux {
int getGMTQuality(int mode, int theta, bool promoteMode7, int version) const;

std::pair<int, int> getGMTCharge(int mode, const std::vector<int>& phidiffs) const;

int getGMTDxy(float dxy) const;
};

#endif
42 changes: 42 additions & 0 deletions L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineDxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef L1TMuonEndCap_PtAssignmentEngineDxy_h
#define L1TMuonEndCap_PtAssignmentEngineDxy_h

#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <array>

#include "L1Trigger/L1TMuonEndCap/interface/Common.h"
#include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineAux2017.h"
#include "PhysicsTools/TensorFlow/interface/TensorFlow.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"

class PtAssignmentEngineDxy {
public:
explicit PtAssignmentEngineDxy();
virtual ~PtAssignmentEngineDxy();

void configure(int verbose, const std::string pbFileNameDxy);

const PtAssignmentEngineAux2017& aux() const;

virtual void calculate_pt_dxy(const EMTFTrack& track, emtf::Feature& feature, emtf::Prediction& prediction) const;

virtual void preprocessing_dxy(const EMTFTrack& track, emtf::Feature& feature) const;

virtual void call_tensorflow_dxy(const emtf::Feature& feature, emtf::Prediction& prediction) const;

protected:
int verbose_;

tensorflow::GraphDef* graphDefDxy_;
tensorflow::Session* sessionDxy_;
std::string pbFileNameDxy_;
std::string pbFilePathDxy_;
std::string inputNameDxy_;
std::vector<std::string> outputNamesDxy_;
};

#endif
1 change: 1 addition & 0 deletions L1Trigger/L1TMuonEndCap/interface/VersionControl.h
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ class VersionControl {
bool readPtLUTFile_, fixMode15HighPt_;
bool bug9BitDPhi_, bugMode7CLCT_, bugNegPt_, bugGMTPhi_, promoteMode7_;
int modeQualVer_;
std::string pbFileName_;
};

#endif
2 changes: 2 additions & 0 deletions L1Trigger/L1TMuonEndCap/python/simEmtfDigis_cfi.py
Original file line number Diff line number Diff line change
@@ -121,6 +121,8 @@
BugGMTPhi = cms.bool(False), # Some drift in uGMT phi conversion, off by up to a few degrees
PromoteMode7 = cms.bool(False), # Assign station 2-3-4 tracks with |eta| > 1.6 SingleMu quality
ModeQualVer = cms.int32(2), # Version 2 contains modified mode-quality mapping for 2018

ProtobufFileName = cms.string('model_graph.displ.5.pb'), # Protobuf file name to be used by NN based pT assignment
),

)
5 changes: 5 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/EMTFSetup.cc
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ EMTFSetup::EMTFSetup(const edm::ParameterSet& iConfig)
version_control_(iConfig),
sector_processor_lut_(),
pt_assign_engine_(nullptr),
pt_assign_engine_dxy_(nullptr),
fw_ver_(0),
pt_lut_ver_(0),
pc_lut_ver_(0) {
@@ -27,7 +28,11 @@ EMTFSetup::EMTFSetup(const edm::ParameterSet& iConfig)
throw cms::Exception("L1TMuonEndCap") << "Cannot recognize the era option: " << era();
}

// No era setup for displaced pT assignment engine
pt_assign_engine_dxy_ = std::make_unique<PtAssignmentEngineDxy>();

emtf_assert(pt_assign_engine_ != nullptr);
emtf_assert(pt_assign_engine_dxy_ != nullptr);
}

EMTFSetup::~EMTFSetup() {}
2 changes: 2 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/MicroGMTConverter.cc
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ void MicroGMTConverter::convert(const int global_event_BX,
int sector = in_track.Sector() - 1;

out_cand.setHwPt(in_track.GMT_pt());
out_cand.setHwPtUnconstrained(in_track.GMT_pt_dxy());
out_cand.setHwDXY(in_track.GMT_dxy());
out_cand.setHwPhi(in_track.GMT_phi());
out_cand.setHwEta(in_track.GMT_eta());
out_cand.setHwSign(in_track.GMT_charge());
39 changes: 37 additions & 2 deletions L1Trigger/L1TMuonEndCap/src/PtAssignment.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "L1Trigger/L1TMuonEndCap/interface/PtAssignment.h"

#include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngine.h"
#include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineDxy.h"

void PtAssignment::configure(PtAssignmentEngine* pt_assign_engine,
PtAssignmentEngineDxy* pt_assign_engine_dxy,
int verbose,
int endcap,
int sector,
@@ -14,18 +16,24 @@ void PtAssignment::configure(PtAssignmentEngine* pt_assign_engine,
bool bugNegPt,
bool bugGMTPhi,
bool promoteMode7,
int modeQualVer) {
int modeQualVer,
std::string pbFileName) {
emtf_assert(pt_assign_engine != nullptr);
emtf_assert(pt_assign_engine_dxy != nullptr);

pt_assign_engine_ = pt_assign_engine;

pt_assign_engine_dxy_ = pt_assign_engine_dxy;

verbose_ = verbose;
endcap_ = endcap;
sector_ = sector;
bx_ = bx;

pt_assign_engine_->configure(verbose_, readPtLUTFile, fixMode15HighPt, bug9BitDPhi, bugMode7CLCT, bugNegPt);

pt_assign_engine_dxy_->configure(verbose_, pbFileName);

bugGMTPhi_ = bugGMTPhi;
promoteMode7_ = promoteMode7;
modeQualVer_ = modeQualVer;
@@ -61,11 +69,17 @@ void PtAssignment::process(EMTFTrackCollection& best_tracks) {
gmt_eta = (gmt_eta < 0) ? ~(-gmt_eta) : gmt_eta;
}

// Assign pT
// Assign prompt & displaced pT
address_t address = 0;
float xmlpt = 0.;
float pt = 0.;
int gmt_pt = 0;

float pt_dxy = 0.;
float dxy = 0.;
int gmt_pt_dxy = 0;
int gmt_dxy = 0;

if (track.Mode() != 1) {
address = pt_assign_engine_->calculate_address(track);
xmlpt = pt_assign_engine_->calculate_pt(address);
@@ -90,6 +104,23 @@ void PtAssignment::process(EMTFTrackCollection& best_tracks) {

pt = (gmt_pt <= 0) ? 0 : (gmt_pt - 1) * 0.5; // Decode integer pT (result is in 0.5 GeV step)

// Calculate displaced pT and d0 using NN
emtf::Feature feature;
emtf::Prediction prediction;

feature.fill(0);
prediction.fill(0);

pt_assign_engine_dxy_->calculate_pt_dxy(track, feature, prediction);

pt_dxy = std::abs(1.0 / prediction.at(0));
dxy = prediction.at(1);

gmt_pt_dxy = aux().getGMTPtDxy(pt_dxy);
gmt_dxy = aux().getGMTDxy(dxy);

pt_dxy = aux().getPtFromGMTPtDxy(gmt_pt_dxy);

int gmt_quality = 0;
if (track.Mode() != 1) {
gmt_quality = aux().getGMTQuality(track.Mode(), track.Theta_fp(), promoteMode7_, modeQualVer_);
@@ -124,9 +155,13 @@ void PtAssignment::process(EMTFTrackCollection& best_tracks) {
track.set_PtLUT(tmp_LUT);
track.set_pt_XML(xmlpt);
track.set_pt(pt);
track.set_pt_dxy(pt_dxy);
track.set_dxy(dxy);
track.set_charge((gmt_charge.second == 1) ? ((gmt_charge.first == 1) ? -1 : +1) : 0);

track.set_gmt_pt(gmt_pt);
track.set_gmt_pt_dxy(gmt_pt_dxy);
track.set_gmt_dxy(gmt_dxy);
track.set_gmt_phi(gmt_phi);
track.set_gmt_eta(gmt_eta);
track.set_gmt_quality(gmt_quality);
26 changes: 26 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/PtAssignmentEngineAux.cc
Original file line number Diff line number Diff line change
@@ -16,11 +16,37 @@ int PtAssignmentEngineAux::getGMTPt(float pt) const {
return gmt_pt;
}

int PtAssignmentEngineAux::getGMTPtDxy(float pt) const {
// compressed pt = pt*1 (scale) + 1 (pt = 0 is empty candidate)
int gmt_pt_dxy = (pt * 1) + 1;
gmt_pt_dxy = (gmt_pt_dxy > 255) ? 255 : gmt_pt_dxy;
return gmt_pt_dxy;
}

int PtAssignmentEngineAux::getGMTDxy(float dxy) const {
int gmt_dxy = 0;
if (std::abs(dxy) < 25.) {
gmt_dxy = 0;
} else if (std::abs(dxy) < 50.) {
gmt_dxy = 1;
} else if (std::abs(dxy) < 75.) {
gmt_dxy = 2;
} else {
gmt_dxy = 3;
}
return gmt_dxy;
}

float PtAssignmentEngineAux::getPtFromGMTPt(int gmt_pt) const {
float pt = (gmt_pt <= 0) ? 0 : 0.5 * (gmt_pt - 1);
return pt;
}

float PtAssignmentEngineAux::getPtFromGMTPtDxy(int gmt_pt_dxy) const {
float pt = (gmt_pt_dxy <= 0) ? 0 : 1.0 * (gmt_pt_dxy - 1);
return pt;
}

int PtAssignmentEngineAux::getGMTPhi(int phi) const {
// convert phi into gmt scale according to DN15-017
// full scale is -16 to 100, or 116 values, covers range -10 to 62.5 deg
262 changes: 262 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/PtAssignmentEngineDxy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
#include "L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineDxy.h"

#include <cassert>
#include <iostream>
#include <sstream>

#include "helper.h" // assert_no_abort

PtAssignmentEngineDxy::PtAssignmentEngineDxy() : graphDefDxy_(nullptr), sessionDxy_(nullptr) {}

PtAssignmentEngineDxy::~PtAssignmentEngineDxy() {
if (sessionDxy_ != nullptr) {
tensorflow::closeSession(sessionDxy_);
}
delete graphDefDxy_;
}

void PtAssignmentEngineDxy::configure(int verbose, const std::string pbFileNameDxy) {
verbose_ = verbose;

pbFileNameDxy_ = pbFileNameDxy;
std::string pbFilePathDxy_ = "L1Trigger/L1TMuon/data/emtf_luts/" + pbFileNameDxy_;

inputNameDxy_ = "batch_normalization_1_input";
outputNamesDxy_ = {"dense_4/BiasAdd"};

if (graphDefDxy_ == nullptr) {
graphDefDxy_ = tensorflow::loadGraphDef(edm::FileInPath(pbFilePathDxy_).fullPath());
}
emtf_assert(graphDefDxy_ != nullptr);

if (sessionDxy_ == nullptr) {
sessionDxy_ = tensorflow::createSession(graphDefDxy_);
}

emtf_assert(sessionDxy_ != nullptr);
}

const PtAssignmentEngineAux2017& PtAssignmentEngineDxy::aux() const {
static const PtAssignmentEngineAux2017 instance;
return instance;
}

void PtAssignmentEngineDxy::calculate_pt_dxy(const EMTFTrack& track,
emtf::Feature& feature,
emtf::Prediction& prediction) const {
// This is called for each track instead of for entire track collection as was done in Phase-2 implementation
preprocessing_dxy(track, feature);
call_tensorflow_dxy(feature, prediction);
return;
}

void PtAssignmentEngineDxy::preprocessing_dxy(const EMTFTrack& track, emtf::Feature& feature) const {
// Mimic Phase-1 EMTF input calculations
// 6 delta Phis: S1-S2, S1-S3, S1-S4, S2-S3, S2-S4, S3-S4
// 6 delta Thetas: S1-S2, S1-S3, S1-S4, S2-S3, S2-S4, S3-S4
// 4 bends : set to zero if no CSC hit and thus RPC hit is used
// 1 FR bit: for ME1 only
// 1 Ring bit: for ME1 only
// 1 track Theta taken from stub coordinate in ME2, ME3, ME4 (in this priority)
// 4 RPC bits indicating if ME or RE hit was used in each station (S1, S2, S3, S4)
// Total: 23 variables
std::array<float, 6> x_dphi;
std::array<float, 6> x_dtheta;
std::array<float, 4> x_bend_emtf;
std::array<float, 1> x_fr_emtf;
std::array<float, 1> x_trk_theta;
std::array<float, 1> x_me11ring;
std::array<float, 4> x_rpcbit;

// Initialize to zeros
x_dphi.fill(0);
x_dtheta.fill(0);
//
x_bend_emtf.fill(0);
x_fr_emtf.fill(0);
x_trk_theta.fill(0);
x_me11ring.fill(0);
x_rpcbit.fill(0);

EMTFPtLUT data = track.PtLUT();

const int invalid_dtheta = 127;
const int invalid_dphi = 8191;

// // Variables to extract from the PtLUT
int dPhi_12, dPhi_13, dPhi_14, dPhi_23, dPhi_24, dPhi_34;
int dTh_12, dTh_13, dTh_14, dTh_23, dTh_24, dTh_34;
int fr_1;
int bend_1, bend_2, bend_3, bend_4;
int rpc_1, rpc_2, rpc_3, rpc_4;
int St1_ring2 = data.st1_ring2;

int pat1 = -99, pat2 = -99, pat3 = -99, pat4 = -99;

// // Which stations have hits
int st1 = (track.Mode() >= 8);
int st2 = ((track.Mode() % 8) >= 4);
int st3 = ((track.Mode() % 4) >= 2);
int st4 = ((track.Mode() % 2) == 1);

// Get valid pattern values
if (st1)
pat1 = data.cpattern[0];
if (st2)
pat2 = data.cpattern[1];
if (st3)
pat3 = data.cpattern[2];
if (st4)
pat4 = data.cpattern[3];

// F/R bit
fr_1 = data.fr[0];

// RPC hit in station
rpc_1 = (st1 ? (pat1 == 0) : 0);
rpc_2 = (st2 ? (pat2 == 0) : 0);
rpc_3 = (st3 ? (pat3 == 0) : 0);
rpc_4 = (st4 ? (pat4 == 0) : 0);

// Calculate bends from patterns
bend_1 = aux().calcBendFromPattern(pat1, track.Endcap());
bend_2 = aux().calcBendFromPattern(pat2, track.Endcap());
bend_3 = aux().calcBendFromPattern(pat3, track.Endcap());
bend_4 = aux().calcBendFromPattern(pat4, track.Endcap());

// Invalid bend value is 0 in the NN
if (bend_1 == -99)
bend_1 = 0;
if (bend_2 == -99)
bend_2 = 0;
if (bend_3 == -99)
bend_3 = 0;
if (bend_4 == -99)
bend_4 = 0;

// In the emulator RPCs get assigned abs(bend) = 5. This needs to be 0 for the NN.
if (std::abs(bend_1) == 5 && rpc_1 == 1)
bend_1 = 0;
if (std::abs(bend_2) == 5 && rpc_2 == 1)
bend_2 = 0;
if (std::abs(bend_3) == 5 && rpc_3 == 1)
bend_3 = 0;
if (std::abs(bend_4) == 5 && rpc_4 == 1)
bend_4 = 0;

// Calculate delta phi
dPhi_12 = (data.delta_ph[0] != invalid_dphi) ? data.delta_ph[0] * (data.sign_ph[0] ? 1 : -1) : 0;
dPhi_13 = (data.delta_ph[1] != invalid_dphi) ? data.delta_ph[1] * (data.sign_ph[1] ? 1 : -1) : 0;
dPhi_14 = (data.delta_ph[2] != invalid_dphi) ? data.delta_ph[2] * (data.sign_ph[2] ? 1 : -1) : 0;
dPhi_23 = (data.delta_ph[3] != invalid_dphi) ? data.delta_ph[3] * (data.sign_ph[3] ? 1 : -1) : 0;
dPhi_24 = (data.delta_ph[4] != invalid_dphi) ? data.delta_ph[4] * (data.sign_ph[4] ? 1 : -1) : 0;
dPhi_34 = (data.delta_ph[5] != invalid_dphi) ? data.delta_ph[5] * (data.sign_ph[5] ? 1 : -1) : 0;

// Calculate delta theta
dTh_12 = (data.delta_th[0] != invalid_dtheta) ? data.delta_th[0] * (data.sign_th[0] ? 1 : -1) : 0;
dTh_13 = (data.delta_th[1] != invalid_dtheta) ? data.delta_th[1] * (data.sign_th[1] ? 1 : -1) : 0;
dTh_14 = (data.delta_th[2] != invalid_dtheta) ? data.delta_th[2] * (data.sign_th[2] ? 1 : -1) : 0;
dTh_23 = (data.delta_th[3] != invalid_dtheta) ? data.delta_th[3] * (data.sign_th[3] ? 1 : -1) : 0;
dTh_24 = (data.delta_th[4] != invalid_dtheta) ? data.delta_th[4] * (data.sign_th[4] ? 1 : -1) : 0;
dTh_34 = (data.delta_th[5] != invalid_dtheta) ? data.delta_th[5] * (data.sign_th[5] ? 1 : -1) : 0;

// Set dPhi and dTheta values to 0 if there was no hit in the station
if (!st1) {
dPhi_12 = 0;
dPhi_13 = 0;
dPhi_14 = 0;

dTh_12 = 0;
dTh_13 = 0;
dTh_14 = 0;
}
if (!st2) {
dPhi_12 = 0;
dPhi_23 = 0;
dPhi_24 = 0;

dTh_12 = 0;
dTh_23 = 0;
dTh_24 = 0;
}
if (!st3) {
dPhi_13 = 0;
dPhi_23 = 0;
dPhi_34 = 0;

dTh_13 = 0;
dTh_23 = 0;
dTh_34 = 0;
}
if (!st4) {
dPhi_14 = 0;
dPhi_24 = 0;
dPhi_34 = 0;

dTh_14 = 0;
dTh_24 = 0;
dTh_34 = 0;
}

// Set NN inputs

// NN was trained with the wrong sign convention. TO BE CHANGED LATER!
x_dphi[0] = dPhi_12;
x_dphi[1] = dPhi_13;
x_dphi[2] = dPhi_14;
x_dphi[3] = dPhi_23;
x_dphi[4] = dPhi_24;
x_dphi[5] = dPhi_34;

// NN was trained with the wrong sign convention. TO BE CHANGED LATER!
x_dtheta[0] = dTh_12;
x_dtheta[1] = dTh_13;
x_dtheta[2] = dTh_14;
x_dtheta[3] = dTh_23;
x_dtheta[4] = dTh_24;
x_dtheta[5] = dTh_34;

// NN was trained with the wrong sign convention. TO BE CHANGED LATER!
x_bend_emtf[0] = bend_1;
x_bend_emtf[1] = bend_2;
x_bend_emtf[2] = bend_3;
x_bend_emtf[3] = bend_4;

x_fr_emtf[0] = fr_1;
x_trk_theta[0] = track.Theta_fp();
x_me11ring[0] = St1_ring2;

x_rpcbit[0] = rpc_1;
x_rpcbit[1] = rpc_2;
x_rpcbit[2] = rpc_3;
x_rpcbit[3] = rpc_4;

feature = {{x_dphi[0], x_dphi[1], x_dphi[2], x_dphi[3], x_dphi[4], x_dphi[5],
x_dtheta[0], x_dtheta[1], x_dtheta[2], x_dtheta[3], x_dtheta[4], x_dtheta[5],
x_bend_emtf[0], x_bend_emtf[1], x_bend_emtf[2], x_bend_emtf[3], x_fr_emtf[0], x_trk_theta[0],
x_me11ring[0], x_rpcbit[0], x_rpcbit[1], x_rpcbit[2], x_rpcbit[3]}};
return;
}

void PtAssignmentEngineDxy::call_tensorflow_dxy(const emtf::Feature& feature, emtf::Prediction& prediction) const {
tensorflow::Tensor input(tensorflow::DT_FLOAT, {1, emtf::NUM_FEATURES});
std::vector<tensorflow::Tensor> outputs;
emtf_assert(feature.size() == emtf::NUM_FEATURES);

float* d = input.flat<float>().data();
std::copy(feature.begin(), feature.end(), d);
tensorflow::run(sessionDxy_, {{inputNameDxy_, input}}, outputNamesDxy_, &outputs);
emtf_assert(outputs.size() == 1);
emtf_assert(prediction.size() == emtf::NUM_PREDICTIONS);

const float reg_pt_scale = 100.0; // a scale factor applied to regression during training
const float reg_dxy_scale = 1.0; // a scale factor applied to regression during training

prediction.at(0) = outputs[0].matrix<float>()(0, 0);
prediction.at(1) = outputs[0].matrix<float>()(0, 1);

// Remove scale factor used during training
prediction.at(0) /= reg_pt_scale;
prediction.at(1) /= reg_dxy_scale;
return;
}
5 changes: 4 additions & 1 deletion L1Trigger/L1TMuonEndCap/src/SectorProcessor.cc
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ void SectorProcessor::process_single_bx(int bx,
auto tp_geom_ = &(setup_->getGeometryTranslator());
auto pc_lut_ = &(setup_->getSectorProcessorLUT());
auto pt_assign_engine_ = setup_->getPtAssignmentEngine();
auto pt_assign_engine_dxy_ = setup_->getPtAssignmentEngineDxy();

// ___________________________________________________________________________
// Configure
@@ -150,6 +151,7 @@ void SectorProcessor::process_single_bx(int bx,

PtAssignment pt_assign;
pt_assign.configure(pt_assign_engine_,
pt_assign_engine_dxy_,
verbose_,
endcap_,
sector_,
@@ -161,7 +163,8 @@ void SectorProcessor::process_single_bx(int bx,
cfg.bugNegPt_,
cfg.bugGMTPhi_,
cfg.promoteMode7_,
cfg.modeQualVer_);
cfg.modeQualVer_,
cfg.pbFileName_);

std::map<int, TriggerPrimitiveCollection> selected_dt_map;
std::map<int, TriggerPrimitiveCollection> selected_csc_map;
1 change: 1 addition & 0 deletions L1Trigger/L1TMuonEndCap/src/VersionControl.cc
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ VersionControl::VersionControl(const edm::ParameterSet& iConfig) : config_(iConf
bugGMTPhi_ = spPAParams16.getParameter<bool>("BugGMTPhi");
promoteMode7_ = spPAParams16.getParameter<bool>("PromoteMode7");
modeQualVer_ = spPAParams16.getParameter<int>("ModeQualVer");
pbFileName_ = spPAParams16.getParameter<std::string>("ProtobufFileName");
}

VersionControl::~VersionControl() {}