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
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand All @@ -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; }
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions L1Trigger/L1TMuonEndCap/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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:
Expand All @@ -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; }
Expand Down Expand Up @@ -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_;
Expand Down
7 changes: 6 additions & 1 deletion L1Trigger/L1TMuonEndCap/interface/PtAssignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,7 +22,8 @@ class PtAssignment {
bool bugNegPt,
bool bugGMTPhi,
bool promoteMode7,
int modeQualVer);
int modeQualVer,
std::string pbFileName);

void process(EMTFTrackCollection& best_tracks);

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

PtAssignmentEngineDxy* pt_assign_engine_dxy_;

int verbose_, endcap_, sector_, bx_;

bool bugGMTPhi_, promoteMode7_;
Expand Down
4 changes: 4 additions & 0 deletions L1Trigger/L1TMuonEndCap/interface/PtAssignmentEngineAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Up @@ -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
Expand Up @@ -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
),

)
Expand Down
5 changes: 5 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/EMTFSetup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {}
Expand Down
2 changes: 2 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/MicroGMTConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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_);
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions L1Trigger/L1TMuonEndCap/src/PtAssignmentEngineAux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading