Skip to content

Commit

Permalink
Emulation of DRin and DR added. Emulation of KFin altered. (cms-sw#205)
Browse files Browse the repository at this point in the history
* Emulation of DRin and DR added. Emulation of KFin altered.

* code-format.

* fix of L1TrackNtupleMaker_cfg.py for HYBRID_NEWKF

* Added seed stub IDs to TrackBuilder output. (cms-sw#202)

* chenges to make cmssw checking out L1Trigger/TrackerDTC and SimTracker/TrackTriggerAssociation.

* code format

* review comments...

* 2 bugs eliminated, tuned for simple f/w.

* Ians comment.

---------

Co-authored-by: Andrew Hart <ahart@cern.ch>
  • Loading branch information
2 people authored and tomalin committed Aug 25, 2023
1 parent bea1f37 commit 2f6cad7
Show file tree
Hide file tree
Showing 33 changed files with 2,222 additions and 549 deletions.
64 changes: 50 additions & 14 deletions L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h
Expand Up @@ -22,12 +22,28 @@ namespace trklet {
ChannelAssignment() {}
ChannelAssignment(const edm::ParameterSet& iConfig, const tt::Setup* setup);
~ChannelAssignment() {}
// sets channelId of given TTTrackRef from TrackBuilder or PurgeDuplicate (if enabled), return false if track outside pt range
bool channelId(const TTTrackRef& ttTrackRef, int& channelId);
// number of used channels for tracks
// returns channelId of given TTTrackRef from TrackBuilder
int channelId(const TTTrackRef& ttTrackRef) const;
// number of used TB channels for tracks
int numChannelsTrack() const { return numChannelsTrack_; }
// number of used channels for stubs
// number of used TB channels for stubs
int numChannelsStub() const { return numChannelsStub_; }
// number of bits used to represent layer id [barrel: 0-5, discs: 6-10]
int widthLayerId() const { return widthLayerId_; }
// number of bits used to represent stub id for projected stubs
int widthStubId() const { return widthStubId_; }
// number of bits used to represent stub id for seed stubs
int widthSeedStubId() const { return widthSeedStubId_; }
// number of bits used to distinguish between tilted and untilded barrel modules or 2S and PS endcap modules
int widthPSTilt() const { return widthPSTilt_; }
// depth of fifos within systolic array
int depthMemory() const { return depthMemory_; }
// number of comparison modules used in each DR node
int numComparisonModules() const { return numComparisonModules_; }
// min number of shared stubs to identify duplicates
int minIdenticalStubs() const { return minIdenticalStubs_; }
// number of DR nodes
int numNodesDR() const { return numNodesDR_; }
// number of used seed types in tracklet algorithm
int numSeedTypes() const { return numSeedTypes_; }
// sets layerId (0-7 in sequence the seed type projects to) of given TTStubRef and seedType, returns false if seeed stub
Expand All @@ -42,29 +58,49 @@ namespace trklet {
int offsetStub(int channelTrack) const;
// seed layers for given seed type id
const std::vector<int>& seedingLayers(int seedType) const { return seedTypesSeedLayers_.at(seedType); }
//
// returns SensorModule::Type for given TTStubRef
tt::SensorModule::Type type(const TTStubRef& ttStubRef) const { return setup_->type(ttStubRef); }
//
int layerId(int seedType, int channel) const { return seedTypesProjectionLayers_.at(seedType).at(channel); }
//
// layers a seed types can project to using default layer id [barrel: 1-6, discs: 11-15]
int layerId(int seedType, int channel) const;
// returns TBout channel Id for given seed type and default layer id [barrel: 1-6, discs: 11-15], returns -1 if layerId and seedType are inconsistent
int channelId(int seedType, int layerId) const;
// max number of seeding layers
int numSeedingLayers() const { return numSeedingLayers_; }
// return DR node for given ttTrackRef
int nodeDR(const TTTrackRef& ttTrackRef) const;

private:
// helper class to store configurations
const tt::Setup* setup_;
// use tracklet seed type as channel id if False, binned track pt used if True
bool useDuplicateRemoval_;
// pt Boundaries in GeV, last boundary is infinity
std::vector<double> boundaries_;
// DRin parameter
edm::ParameterSet pSetDRin_;
// number of bits used to represent layer id [barrel: 0-5, discs: 6-10]
int widthLayerId_;
// number of bits used to represent stub id for projected stubs
int widthStubId_;
// number of bits used to represent stub id for seed stubs
int widthSeedStubId_;
// number of bits used to distinguish between tilted and untilded barrel modules or 2S and PS endcap modules
int widthPSTilt_;
// depth of fifos within systolic array
int depthMemory_;
// positive pt Boundaries in GeV (symmetric negatives are assumed), first boundary is pt cut, last boundary is infinity, defining ot bins used by DR
std::vector<double> ptBoundaries_;
// DRin parameter
edm::ParameterSet pSetDR_;
// number of comparison modules used in each DR node
int numComparisonModules_;
// min number of shared stubs to identify duplicates [default: 3]
int minIdenticalStubs_;
// number of DR nodes
int numNodesDR_;
// seed type names
std::vector<std::string> seedTypeNames_;
// number of used seed types in tracklet algorithm
int numSeedTypes_;
// number of used channels for tracks
// number of used TB channels for tracks
int numChannelsTrack_;
// number of used channels for stubs
// number of used TB channels for stubs
int numChannelsStub_;
// seeding layers of seed types using default layer id [barrel: 1-6, discs: 11-15]
std::vector<std::vector<int>> seedTypesSeedLayers_;
Expand Down
82 changes: 82 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/DR.h
@@ -0,0 +1,82 @@
#ifndef L1Trigger_TrackFindingTracklet_DR_h
#define L1Trigger_TrackFindingTracklet_DR_h

#include "L1Trigger/TrackTrigger/interface/Setup.h"
#include "L1Trigger/TrackerTFP/interface/DataFormats.h"
#include "L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h"

#include <vector>

namespace trklet {

/*! \class trklet::DR
* \brief Class to bit- and clock-accurate emulate duplicate removal
* DR identifies duplicates based on pairs of tracks that share stubs in at least 3 layers.
* It keeps the first such track in each pair.
* \author Thomas Schuh
* \date 2023, Feb
*/
class DR {
public:
DR(const edm::ParameterSet& iConfig,
const tt::Setup* setup_,
const trackerTFP::DataFormats* dataFormats,
const ChannelAssignment* channelAssignment,
int region);
~DR() {}
// read in and organize input tracks and stubs
void consume(const tt::StreamsTrack& streamsTrack, const tt::StreamsStub& streamsStub);
// fill output products
void produce(tt::StreamsStub& accpetedStubs,
tt::StreamsTrack& acceptedTracks,
tt::StreamsStub& lostStubs,
tt::StreamsTrack& lostTracks);

private:
struct Stub {
// take only 7 lsb of stubId into account
static constexpr int lsbMod = pow(2, 7);
Stub(const tt::FrameStub& frame, bool seed, int layerId, int stubId, int channel)
: frame_(frame), seed_(seed), layerId_(layerId), stubId_(stubId), channel_(channel) {}
bool operator==(const Stub& s) const { return (s.stubId_ % lsbMod) == (stubId_ % lsbMod); }
tt::FrameStub frame_;
// true if stub was part of the seed
bool seed_;
// det layer id [0-5] barrel [6-10] endcap discs
int layerId_;
// all stubs id
int stubId_;
// kf layer id
int channel_;
};
struct Track {
// max number of stubs a track may formed of (we allow only one stub per layer)
static constexpr int max_ = 7;
Track() { stubs_.reserve(max_); }
Track(const tt::FrameTrack& frame, const std::vector<Stub*>& stubs) : frame_(frame), stubs_(stubs) {}
tt::FrameTrack frame_;
std::vector<Stub*> stubs_;
};
// compares two tracks, returns true if those are considered duplicates
bool equalEnough(Track* t0, Track* t1) const;
// true if truncation is enbaled
bool enableTruncation_;
// provides run-time constants
const tt::Setup* setup_;
// provides dataformats
const trackerTFP::DataFormats* dataFormats_;
// helper class to assign tracks to channel
const ChannelAssignment* channelAssignment_;
// processing region (0 - 8) aka processing phi nonant
const int region_;
// storage of input tracks
std::vector<Track> tracks_;
// storage of input stubs
std::vector<Stub> stubs_;
// h/w liked organized pointer to input tracks
std::vector<std::vector<Track*>> input_;
};

} // namespace trklet

#endif
169 changes: 169 additions & 0 deletions L1Trigger/TrackFindingTracklet/interface/DRin.h
@@ -0,0 +1,169 @@
#ifndef L1Trigger_TrackFindingTracklet_DRin_h
#define L1Trigger_TrackFindingTracklet_DRin_h

#include "L1Trigger/TrackTrigger/interface/Setup.h"
#include "L1Trigger/TrackerTFP/interface/DataFormats.h"
#include "L1Trigger/TrackerTFP/interface/LayerEncoding.h"
#include "L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h"
#include "L1Trigger/TrackFindingTracklet/interface/Settings.h"

#include <vector>
#include <deque>

namespace trklet {

/*! \class trklet::DRin
* \brief Class to emulate transformation of tracklet tracks and stubs into TMTT format
* and routing of seed type streams into inv2R streams
* \author Thomas Schuh
* \date 2023, Jan
*/
class DRin {
public:
DRin(const edm::ParameterSet& iConfig,
const tt::Setup* setup_,
const trackerTFP::DataFormats* dataFormats,
const trackerTFP::LayerEncoding* layerEncoding,
const ChannelAssignment* channelAssignment,
const Settings* settings,
int region);
~DRin() {}
// read in and organize input tracks and stubs
void consume(const tt::StreamsTrack& streamsTrack, const tt::StreamsStub& streamsStub);
// fill output products
void produce(tt::StreamsStub& accpetedStubs,
tt::StreamsTrack& acceptedTracks,
tt::StreamsStub& lostStubs,
tt::StreamsTrack& lostTracks);

private:
// truncates double precision of val into base precision, +1.e-12 restores robustness of addition of 2 digitised values
double digi(double val, double base) const { return (floor(val / base + 1.e-12) + .5) * base; }
// basetransformation of val from baseLow into baseHigh using widthMultiplier bit multiplication
double redigi(double val, double baseLow, double baseHigh, int widthMultiplier) const;
struct Stub {
Stub(const TTStubRef& ttStubRef,
int layer,
int layerDet,
bool seed,
int stubId,
double r,
double phi,
double z,
bool psTilt)
: valid_(true),
ttStubRef_(ttStubRef),
layer_(layer),
layerDet_(layerDet),
layerKF_(-1),
seed_(seed),
stubId_(stubId),
r_(r),
phi_(phi),
z_(z),
psTilt_(psTilt) {}
bool valid_;
TTStubRef ttStubRef_;
// layers a seed types can project to using default layer id [barrel: 1-6, discs: 11-15]
int layer_;
// layer id [0-5] barrel [6-10] end cap discs
int layerDet_;
// layer id [0-6] counted from inside-out along track
int layerKF_;
// true if stub was part of the seed
bool seed_;
// traclet stub id
int stubId_;
// radius w.r.t. chosenRofPhi in cm
double r_;
// phi residual in rad
double phi_;
// z residual in cm
double z_;
// true if barrel tilted module or encap PS module
bool psTilt_;
};
struct Track {
static constexpr int max_ = 8;
Track() { stubs_.reserve(max_); }
Track(const TTTrackRef& ttTrackRef,
bool valid,
double inv2R,
double phiT,
double cot,
double zT,
const std::vector<Stub*>& stubs)
: ttTrackRef_(ttTrackRef),
valid_(valid),
sector_(-1),
inv2R_(inv2R),
phiT_(phiT),
cot_(cot),
zT_(zT),
stubs_(stubs) {}
TTTrackRef ttTrackRef_;
bool valid_;
TTBV maybe_;
int sector_;
double inv2R_;
double phiT_;
double cot_;
double zT_;
std::vector<Stub*> stubs_;
};
// remove and return first element of deque, returns nullptr if empty
template <class T>
T* pop_front(std::deque<T*>& ts) const;
// true if truncation is enbaled
bool enableTruncation_;
// stub residuals are recalculated from seed parameter and TTStub position
bool useTTStubResiduals_;
// provides run-time constants
const tt::Setup* setup_;
// provides dataformats
const trackerTFP::DataFormats* dataFormats_;
// helper class to encode layer
const trackerTFP::LayerEncoding* layerEncoding_;
// helper class to assign tracks to channel
const ChannelAssignment* channelAssignment_;
// provides tracklet constants
const Settings* settings_;
// processing region (0 - 8) aka processing phi nonant
const int region_;
// storage of input tracks
std::vector<Track> tracks_;
// storage of input stubs
std::vector<Stub> stubs_;
// h/w liked organized pointer to input tracks
std::vector<std::vector<Track*>> input_;
// unified tracklet digitisation granularity
double baseUinv2R_;
double baseUphiT_;
double baseUcot_;
double baseUzT_;
double baseUr_;
double baseUphi_;
double baseUz_;
// KF input format digitisation granularity (identical to TMTT)
double baseLinv2R_;
double baseLphiT_;
double baseLcot_;
double baseLzT_;
double baseLr_;
double baseLphi_;
double baseLz_;
// Finer granularity (by powers of 2) than the TMTT one. Used to transform from Tracklet to TMTT base.
double baseHinv2R_;
double baseHphiT_;
double baseHcot_;
double baseHzT_;
double baseHr_;
double baseHphi_;
double baseHz_;
// digitisation granularity used for inverted cot(theta)
double baseInvCot_;
};

} // namespace trklet

#endif

0 comments on commit 2f6cad7

Please sign in to comment.