Skip to content

Commit

Permalink
L1 tk dev 12 0 0 pre4 hph (cms-sw#94)
Browse files Browse the repository at this point in the history
* First Commit

* Code Format

* Fix Typo

* Naming Rule

* Chris' 2nd Comment

Co-authored-by: Jack Li <jingyan.li@cern.ch>
  • Loading branch information
Jingyan95 and Jingyan95 committed Oct 15, 2021
1 parent 08774df commit 3b2f139
Show file tree
Hide file tree
Showing 14 changed files with 626 additions and 25 deletions.
6 changes: 3 additions & 3 deletions L1Trigger/TrackFindingTMTT/src/KFbase.cc
Expand Up @@ -729,9 +729,9 @@ namespace tmtt {
// Fixes to layermap when "maybe layer" used
if (settings_->kfUseMaybeLayers()) {
switch (kfEtaReg) {
case 5: //case 5: B1 B2 (B3+B4)* D1 D2 D3+D4 D5+D6 -- B3 is combined with B4 and is flagged as "maybe layer"
case 5: //case 5: B1 B2 (B3+B4)* D1 D2 D3 D4+D5 -- B3 is combined with B4 and is flagged as "maybe layer"
if (layerIDreduced == 6) {
kalmanLay = 5;
kalmanLay = 6;
}
break;
case 6: //case 6: B1* B2* D1 D2 D3 D4 D5 -- B1 and B2 are flagged as "maybe layer"
Expand All @@ -758,7 +758,7 @@ namespace tmtt {
}
break;
//case 5: // B1 B2 B3+B4 D1 D2 D3 D4/D5
case 5: // B1 B2 B3 D1+B4 D2 D3 D4/D5
case 5:
if (layerIDreduced == 5) {
kalmanLay = 5;
} else if (layerIDreduced == 7) {
Expand Down
8 changes: 8 additions & 0 deletions L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc
Expand Up @@ -94,6 +94,7 @@

#include "L1Trigger/TrackTrigger/interface/StubPtConsistency.h"
#include "L1Trigger/TrackTrigger/interface/TrackQuality.h"
#include "L1Trigger/TrackTrigger/interface/HitPatternHelper.h"

//////////////
// STD HEADERS
Expand Down Expand Up @@ -185,9 +186,11 @@ class L1FPGATrackProducer : public edm::one::EDProducer<edm::one::WatchRuns> {

// helper class to store DTC configuration
trackerDTC::Setup setup_;
const hph::Setup* setupHPH_;

// Setup token
edm::ESGetToken<trackerDTC::Setup, trackerDTC::SetupRcd> esGetToken_;
edm::ESGetToken<hph::Setup, hph::SetupRcd> esGetTokenHPH_;

/// ///////////////// ///
/// MANDATORY METHODS ///
Expand Down Expand Up @@ -233,6 +236,7 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig)

// book ES product
esGetToken_ = esConsumes<trackerDTC::Setup, trackerDTC::SetupRcd, edm::Transition::BeginRun>();
esGetTokenHPH_ = esConsumes<hph::Setup, hph::SetupRcd, edm::Transition::BeginRun>();

// --------------------------------------------------------------------------------
// set options in Settings based on inputs from configuration files
Expand Down Expand Up @@ -302,6 +306,10 @@ void L1FPGATrackProducer::beginRun(const edm::Run& run, const edm::EventSetup& i
settings.setBfield(mMagneticFieldStrength);

setup_ = iSetup.getData(esGetToken_);
setupHPH_ = &iSetup.getData(esGetTokenHPH_);
if (trackQuality_) {
trackQualityModel_->setHPHSetup(setupHPH_);
}

// initialize the tracklet event processing (this sets all the processing & memory modules, wiring, etc)
eventProcessor.init(settings);
Expand Down
Expand Up @@ -6,6 +6,8 @@

from SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff import *

from L1Trigger.TrackTrigger.ProducerHPH_cff import *

# prompt hybrid emulation
TTTrackAssociatorFromPixelDigis.TTTracks = cms.VInputTag(cms.InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks") )

Expand Down
Expand Up @@ -30,6 +30,7 @@
process.load('FWCore.MessageService.MessageLogger_cfi')
process.MessageLogger.L1track = dict(limit = -1)
process.MessageLogger.Tracklet = dict(limit = -1)
process.MessageLogger.TrackTriggerHPH = dict(limit = -1)

if GEOMETRY == "D49":
print("using geometry " + GEOMETRY + " (tilted)")
Expand Down
169 changes: 169 additions & 0 deletions L1Trigger/TrackTrigger/interface/HitPatternHelper.h
@@ -0,0 +1,169 @@
// This is a helper function that can be used to decode hitpattern, which is a 7-bit integer produced by KF.
//
// There are three classes declared in HitPatternHelper (HPH) namesapce:
// 1)SensorModule: This is used to store important information about the sensor modules. For example r,z coordinates.
// 2)Setup: This is used to produce a collection of <SensorModule> needed by HPH.
// 3)HitPatternHelper: This is used to decode hitpattern with the help of the information from sensor modules and layermap.
//
// Two predictions on which layers particles will hit are made using different information:
// i)Loop over sensor modules and make predictions based on spatial coordinates of tracks. This prediction is considered more accurate.
// ii)Make predictions based on a hard-coded layermap. This prediction is considered less accurate and is used by Old KF to encode hitpattern.
//
//
// Created by J.Li on 1/23/21.
//

#ifndef L1Trigger_TrackTrigger_interface_HitPatternHelper_h
#define L1Trigger_TrackTrigger_interface_HitPatternHelper_h

#include "FWCore/Framework/interface/data_default_record_trait.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "L1Trigger/TrackTrigger/interface/HitPatternHelperRcd.h"

#include <bitset>
#include <iostream>
#include <vector>

using namespace std;
using namespace edm;

namespace hph {

class SensorModule {
public:
SensorModule() {}
SensorModule(
bool isBarrel, bool isPS, int numColumns, int layerId, double r, double z, double pitchCol, double tilt);
~SensorModule() {}

bool isBarrel() const { return isBarrel_; }
bool isPS() const { return isPS_; }
bool isMaybe() const { return isMaybe_; }
int numColumns() const { return numColumns_; }
int layerId() const { return layerId_; }
double r() const { return r_; }
double z() const { return z_; }
double pitchCol() const { return pitchCol_; }
double tilt() const { return tilt_; }
double sin() const { return sin_; }
double cos() const { return cos_; }

void setMaybe() { isMaybe_ = true; }

private:
bool isBarrel_;
bool isPS_;
bool isMaybe_;
int numColumns_;
int layerId_;
double r_;
double z_;
double pitchCol_;
double tilt_;
double sin_;
double cos_;
};

class Setup {
public:
Setup() {}
Setup(const edm::ParameterSet& iConfig,
const TrackerGeometry& trackerGeometry,
const TrackerTopology& trackerTopology);
~Setup() {}

static auto smallerR(SensorModule lhs, SensorModule rhs) { return lhs.r() < rhs.r(); }
static auto smallerZ(SensorModule lhs, SensorModule rhs) { return lhs.z() < rhs.z(); }
static auto equalRZ(SensorModule lhs, SensorModule rhs) {
return abs(lhs.r() - rhs.r()) < delta_ && abs(lhs.z() - rhs.z()) < delta_;
}
std::vector<SensorModule> sensorModules() const { return sensorModules_; }

bool hphDebug() const { return iConfig_.getParameter<bool>("hphDebug"); }
bool useNewKF() const { return iConfig_.getParameter<bool>("useNewKF"); }
double chosenRofZ() const { return iConfig_.getParameter<double>("chosenRofZ"); }
double deltaTanL() const { return iConfig_.getParameter<double>("deltaTanL"); }

private:
edm::ParameterSet iConfig_;
const TrackerGeometry* trackerGeometry_;
const TrackerTopology* trackerTopology_;
static constexpr double delta_ = 1.e-3;
std::vector<SensorModule> sensorModules_;
};

class HitPatternHelper {
public:
HitPatternHelper() {}
HitPatternHelper(const Setup* setup, int hitpattern, double cot, double z0);
~HitPatternHelper() {}

int etaSector() { return etaSector_; } //Eta sectors defined in KF
int numExpLayer() { return numExpLayer_; } //The number of layers KF expects
int numMissingPS() { return numMissingPS_; } //The number of PS layers that are missing
int numMissing2S() { return numMissing2S_; } //The number of 2S layers that are missing
int numPS() { return numPS_; } //The number of PS layers are found in hitpattern
int num2S() { return num2S_; } //The number of 2S layers are found in hitpattern
int numMissingInterior1() {
return numMissingInterior1_;
} //The number of missing interior layers (using only hitpattern)
int numMissingInterior2() {
return numMissingInterior2_;
} //The number of missing interior layers (using hitpattern and sensor modules)
std::vector<int> binary() { return binary_; } //11-bit hitmask needed by TrackQuality.cc (0~5->L1~L6;6~10->D1~D5)
static auto smallerID(SensorModule lhs, SensorModule rhs) { return lhs.layerId() < rhs.layerId(); }
static auto equalID(SensorModule lhs, SensorModule rhs) { return lhs.layerId() == rhs.layerId(); }

int ReducedId(
int layerId); //Converts layer id (1~6->L1~L6;11~15->D1~D5) to reduced layer id (0~5->L1~L6;6~10->D1~D5)
int findLayer(int layerId); //Search for a layer id from sensor modules

private:
int etaSector_;
int hitpattern_;
int numExpLayer_;
int numMissingLayer_;
int numMissingPS_;
int numMissing2S_;
int numPS_;
int num2S_;
int numMissingInterior1_;
int numMissingInterior2_;
double cot_;
double z0_;
const Setup* setup_;
std::vector<SensorModule> layers_; //Sensor modules that particles are expected to hit
std::vector<int> binary_;
bool hphDebug_;
bool useNewKF_;
float chosenRofZ_;
float deltaTanL_;
std::vector<float> etaRegions_ = {
-2.4, -2.08, -1.68, -1.26, -0.90, -0.62, -0.41, -0.20, 0.0, 0.20, 0.41, 0.62, 0.90, 1.26, 1.68, 2.08, 2.4};

//Layermap used in Old KF
//Ultimate config is assumed (with maybe layer)
//Index across is kalman layer
//Index down is eta sector
//Element is layer id where barrel layers=1,2,3,4,5,6 & endcap wheels=11,12,13,14,15; 0 is invalid.
std::vector<int> hitmap_[8][7] = {
{{1}, {2}, {3}, {4}, {5}, {6}, {0}},
{{1}, {2}, {3}, {4}, {5}, {6}, {0}},
{{1}, {2}, {3}, {4}, {5}, {6}, {0}},
{{1}, {2}, {3}, {4}, {5}, {6}, {0}},
{{1}, {2}, {3}, {4}, {5, 11}, {6, 12}, {13}},
{{1}, {2}, {3, 4}, {11}, {12}, {13}, {14, 15}},
{{1}, {2}, {11}, {12}, {13}, {14}, {15}},
{{1}, {11}, {12}, {13}, {14}, {15}, {0}},
};
};

} // namespace hph

EVENTSETUP_DATA_DEFAULT_RECORD(hph::Setup, hph::SetupRcd);

#endif
24 changes: 24 additions & 0 deletions L1Trigger/TrackTrigger/interface/HitPatternHelperRcd.h
@@ -0,0 +1,24 @@
//
// Created by J.Li on 1/23/21.
//

#ifndef L1Trigger_TrackTrigger_interface_HitPatternHelperRcd_h
#define L1Trigger_TrackTrigger_interface_HitPatternHelperRcd_h

#include "FWCore/Framework/interface/DependentRecordImplementation.h"

#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"

#include "FWCore/Utilities/interface/mplVector.h"

namespace hph {

typedef edm::mpl::Vector<TrackerDigiGeometryRecord, TrackerTopologyRcd> Rcds;

// record of hph::SetupRcd
class SetupRcd : public edm::eventsetup::DependentRecordImplementation<SetupRcd, Rcds> {};

} // namespace hph

#endif
6 changes: 6 additions & 0 deletions L1Trigger/TrackTrigger/interface/TrackQuality.h
Expand Up @@ -26,6 +26,8 @@ C.Brown 28/07/20
#include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h"

#include "L1Trigger/TrackTrigger/interface/HitPatternHelper.h"

class TrackQuality {
public:
// Enum class used for determining prediction behaviour in setTrackQuality
Expand Down Expand Up @@ -60,6 +62,8 @@ class TrackQuality {
std::string const& ONNXInputName,
std::vector<std::string> const& featureNames);

void setHPHSetup(const hph::Setup* setup);

private:
// Private Member Data
QualityAlgorithm qualityAlgorithm_ = QualityAlgorithm::None;
Expand All @@ -73,5 +77,7 @@ class TrackQuality {
float minPt_;
int nStubsmin_;
float ONNXInvRScaling_;
const hph::Setup* setup_;
bool useHPH;
};
#endif
47 changes: 47 additions & 0 deletions L1Trigger/TrackTrigger/plugins/ProducerHPH.cc
@@ -0,0 +1,47 @@
//
// Created by J.Li on 1/23/21.
//

#include "FWCore/Framework/interface/ModuleFactory.h"
#include "FWCore/Framework/interface/ESProducer.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "FWCore/Utilities/interface/ESInputTag.h"
#include "DataFormats/Provenance/interface/ParameterSetID.h"
#include "L1Trigger/TrackTrigger/interface/HitPatternHelper.h"

#include <memory>

using namespace std;
using namespace edm;

namespace hph {

class ProducerHPH : public ESProducer {
public:
ProducerHPH(const ParameterSet& iConfig);
~ProducerHPH() override {}
unique_ptr<Setup> produce(const SetupRcd& Rcd);

private:
const ParameterSet iConfig_;
ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> getTokenTrackerGeometry_;
ESGetToken<TrackerTopology, TrackerTopologyRcd> getTokenTrackerTopology_;
};

ProducerHPH::ProducerHPH(const ParameterSet& iConfig) : iConfig_(iConfig) {
auto cc = setWhatProduced(this);
getTokenTrackerGeometry_ = cc.consumes();
getTokenTrackerTopology_ = cc.consumes();
}

unique_ptr<Setup> ProducerHPH::produce(const SetupRcd& Rcd) {
const TrackerGeometry& trackerGeometry = Rcd.get(getTokenTrackerGeometry_);
const TrackerTopology& trackerTopology = Rcd.get(getTokenTrackerTopology_);
return make_unique<Setup>(iConfig_, trackerGeometry, trackerTopology);
}

} // namespace hph

DEFINE_FWK_EVENTSETUP_MODULE(hph::ProducerHPH);
5 changes: 5 additions & 0 deletions L1Trigger/TrackTrigger/python/ProducerHPH_cff.py
@@ -0,0 +1,5 @@
import FWCore.ParameterSet.Config as cms

from L1Trigger.TrackTrigger.ProducerHPH_cfi import HitPatternHelper_params

HitPatternHelperSetup = cms.ESProducer("hph::ProducerHPH", HitPatternHelper_params)
10 changes: 10 additions & 0 deletions L1Trigger/TrackTrigger/python/ProducerHPH_cfi.py
@@ -0,0 +1,10 @@
import FWCore.ParameterSet.Config as cms

HitPatternHelper_params = cms.PSet (

HPHdebug = cms.bool(False),
useNewKF = cms.bool(False),
chosenRofZ = cms.double(50.0),
deltaTanL = cms.double(0.125)

)
8 changes: 8 additions & 0 deletions L1Trigger/TrackTrigger/src/ES_HitPatternHelper.cc
@@ -0,0 +1,8 @@
//
// Created by J.Li on 1/23/21.
//

#include "FWCore/Utilities/interface/typelookup.h"
#include "L1Trigger/TrackTrigger/interface/HitPatternHelper.h"

TYPELOOKUP_DATA_REG(hph::Setup);

0 comments on commit 3b2f139

Please sign in to comment.