CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
trklet::KFin Class Reference

Class to emulate transformation of tracklet tracks and stubs into TMTT format. More...

#include <KFin.h>

Classes

struct  Stub
 
struct  Track
 

Public Member Functions

void consume (const tt::StreamsTrack &streamsTrack, const tt::StreamsStub &streamsStub)
 
 KFin (const edm::ParameterSet &iConfig, const tt::Setup *setup_, const trackerTFP::DataFormats *dataFormats, const trackerTFP::LayerEncoding *layerEncoding, const ChannelAssignment *channelAssignment, const Settings *settings, int region)
 
void produce (tt::StreamsStub &accpetedStubs, tt::StreamsTrack &acceptedTracks, tt::StreamsStub &lostStubs, tt::StreamsTrack &lostTracks)
 
 ~KFin ()
 

Private Member Functions

double digi (double val, double base) const
 
double redigi (double val, double baseLow, double baseHigh, int widthMultiplier) const
 

Private Attributes

double baseHcot_
 
double baseHinv2R_
 
double baseHphi_
 
double baseHphiT_
 
double baseHr_
 
double baseHz_
 
double baseHzT_
 
double baseInvCot_
 
double baseLcot_
 
double baseLinv2R_
 
double baseLphi_
 
double baseLphiT_
 
double baseLr_
 
double baseLz_
 
double baseLzT_
 
double baseUcot_
 
double baseUinv2R_
 
double baseUphi_
 
double baseUphiT_
 
double baseUr_
 
double baseUz_
 
double baseUzT_
 
const ChannelAssignmentchannelAssignment_
 
const trackerTFP::DataFormatsdataFormats_
 
bool enableTruncation_
 
std::vector< std::vector< Track * > > input_
 
const trackerTFP::LayerEncodinglayerEncoding_
 
const int region_
 
const Settingssettings_
 
const tt::Setupsetup_
 
std::vector< Stubstubs_
 
std::vector< Tracktracks_
 
bool useTTStubResiduals_
 

Detailed Description

Class to emulate transformation of tracklet tracks and stubs into TMTT format.

Author
Thomas Schuh
Date
2021, Dec

Definition at line 19 of file KFin.h.

Constructor & Destructor Documentation

◆ KFin()

trklet::KFin::KFin ( const edm::ParameterSet iConfig,
const tt::Setup setup_,
const trackerTFP::DataFormats dataFormats,
const trackerTFP::LayerEncoding layerEncoding,
const ChannelAssignment channelAssignment,
const Settings settings,
int  region 
)

Definition at line 14 of file KFin.cc.

References trackerTFP::DataFormats::base(), baseHcot_, baseHinv2R_, baseHphi_, baseHphiT_, baseHr_, baseHz_, baseHzT_, baseInvCot_, baseLcot_, baseLinv2R_, baseLphi_, baseLphiT_, baseLr_, baseLz_, baseLzT_, baseUcot_, baseUinv2R_, baseUphi_, baseUphiT_, baseUr_, baseUz_, baseUzT_, reco::ceil(), tt::Setup::hybridRangeR(), trklet::Settings::kphi1(), trklet::Settings::kr(), trklet::Settings::kz(), tt::Setup::outerRadius(), PVValHelper::phi, trklet::Settings::phi0_shift(), conifer::pow(), alignCSCRings::r, trklet::Settings::rinv_shift(), settings_, setup_, trklet::Settings::t_shift(), tt::Setup::widthDSPbu(), detailsBasic3DVector::z, and trklet::Settings::z0_shift().

21  : enableTruncation_(iConfig.getParameter<bool>("EnableTruncation")),
22  useTTStubResiduals_(iConfig.getParameter<bool>("UseTTStubResiduals")),
23  setup_(setup),
24  dataFormats_(dataFormats),
25  layerEncoding_(layerEncoding),
26  channelAssignment_(channelAssignment),
27  settings_(settings),
28  region_(region),
30  // unified tracklet digitisation granularity
34  baseUzT_ = settings_->kz() * pow(2, settings_->z0_shift());
35  baseUr_ = settings_->kr();
37  baseUz_ = settings_->kz();
38  // KF input format digitisation granularity (identical to TMTT)
39  baseLinv2R_ = dataFormats->base(Variable::inv2R, Process::kfin);
40  baseLphiT_ = dataFormats->base(Variable::phiT, Process::kfin);
41  baseLcot_ = dataFormats->base(Variable::cot, Process::kfin);
42  baseLzT_ = dataFormats->base(Variable::zT, Process::kfin);
43  baseLr_ = dataFormats->base(Variable::r, Process::kfin);
44  baseLphi_ = dataFormats->base(Variable::phi, Process::kfin);
45  baseLz_ = dataFormats->base(Variable::z, Process::kfin);
46  // Finer granularity (by powers of 2) than the TMTT one. Used to transform from Tracklet to TMTT base.
47  baseHinv2R_ = baseLinv2R_ * pow(2, floor(log2(baseUinv2R_ / baseLinv2R_)));
48  baseHphiT_ = baseLphiT_ * pow(2, floor(log2(baseUphiT_ / baseLphiT_)));
49  baseHcot_ = baseLcot_ * pow(2, floor(log2(baseUcot_ / baseLcot_)));
50  baseHzT_ = baseLzT_ * pow(2, floor(log2(baseUzT_ / baseLzT_)));
51  baseHr_ = baseLr_ * pow(2, floor(log2(baseUr_ / baseLr_)));
52  baseHphi_ = baseLphi_ * pow(2, floor(log2(baseUphi_ / baseLphi_)));
53  baseHz_ = baseLz_ * pow(2, floor(log2(baseUz_ / baseLz_)));
54  // calculate digitisation granularity used for inverted cot(theta)
55  const int baseShiftInvCot = ceil(log2(setup_->outerRadius() / setup_->hybridRangeR())) - setup_->widthDSPbu();
56  baseInvCot_ = pow(2, baseShiftInvCot);
57  }
double baseUcot_
Definition: KFin.h:116
bool enableTruncation_
Definition: KFin.h:92
double baseUzT_
Definition: KFin.h:117
constexpr int32_t ceil(float num)
double base(Variable v, Process p) const
Definition: DataFormats.h:492
double baseUinv2R_
Definition: KFin.h:114
double kz() const
Definition: Settings.h:336
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
double kphi1() const
Definition: Settings.h:333
double baseUphi_
Definition: KFin.h:119
double baseLr_
Definition: KFin.h:126
double baseHzT_
Definition: KFin.h:133
double baseHcot_
Definition: KFin.h:132
int widthDSPbu() const
Definition: Setup.h:141
constexpr int pow(int x)
Definition: conifer.h:24
const ChannelAssignment * channelAssignment_
Definition: KFin.h:102
double baseHphi_
Definition: KFin.h:135
double baseUr_
Definition: KFin.h:118
int phi0_shift() const
Definition: Settings.h:375
double baseInvCot_
Definition: KFin.h:138
double baseHinv2R_
Definition: KFin.h:130
bool useTTStubResiduals_
Definition: KFin.h:94
float float float z
double baseLz_
Definition: KFin.h:128
int t_shift() const
Definition: Settings.h:376
const int region_
Definition: KFin.h:106
const Settings * settings_
Definition: KFin.h:104
std::vector< std::vector< Track * > > input_
Definition: KFin.h:112
double baseLcot_
Definition: KFin.h:124
double baseHr_
Definition: KFin.h:134
double baseHphiT_
Definition: KFin.h:131
double hybridRangeR() const
Definition: Setup.h:302
int z0_shift() const
Definition: Settings.h:377
double outerRadius() const
Definition: Setup.h:241
double baseLinv2R_
Definition: KFin.h:122
double kr() const
Definition: Settings.h:338
double baseLzT_
Definition: KFin.h:125
double baseUphiT_
Definition: KFin.h:115
double baseHz_
Definition: KFin.h:136
int rinv_shift() const
Definition: Settings.h:374
double baseLphi_
Definition: KFin.h:127
double baseLphiT_
Definition: KFin.h:123
const trackerTFP::DataFormats * dataFormats_
Definition: KFin.h:98
const tt::Setup * setup_
Definition: KFin.h:96
const trackerTFP::LayerEncoding * layerEncoding_
Definition: KFin.h:100
double baseUz_
Definition: KFin.h:120

◆ ~KFin()

trklet::KFin::~KFin ( )
inline

Definition at line 28 of file KFin.h.

28 {}

Member Function Documentation

◆ consume()

void trklet::KFin::consume ( const tt::StreamsTrack streamsTrack,
const tt::StreamsStub streamsStub 
)

Definition at line 60 of file KFin.cc.

References funct::abs(), Reference_intrackfit_cff::barrel, tt::Setup::barrel(), baseInvCot_, tt::Setup::baseRegion(), baseUcot_, baseUinv2R_, baseUphi_, baseUphiT_, baseUr_, baseUz_, baseUzT_, tt::Setup::beamWindowZ(), channelAssignment_, trackerTFP::DataFormats::chosenRofPhi(), tt::Setup::chosenRofZ(), trackerTFP::cot, dataFormats_, tt::deltaPhi(), digi(), enableTruncation_, dqmdumpme::first, amptDefault_cfi::frame, l1trig_cff::hwPhi, tt::Setup::hybridDiskZ(), tt::Setup::hybridLayerR(), tt::Setup::hybridMaxCot(), tt::Setup::hybridRangePhi(), tt::Setup::indexLayerId(), input, input_, createfilelist::int, edm::Ref< C, T, F >::isNull(), trklet::Settings::kphi(), trklet::Settings::kphi1(), trklet::Settings::kz(), trklet::ChannelAssignment::layerId(), tt::Setup::layerId(), remoteMonitoring_LASER_era2018_cfg::limit, tt::Setup::maxEta(), trklet::Settings::nbitst(), beamSpotPI::nTracks, trklet::ChannelAssignment::numChannelsTrack(), tt::Setup::numFrames(), trklet::ChannelAssignment::numProjectionLayers(), trklet::ChannelAssignment::numSeedingLayers(), tt::Setup::offsetLayerDisks(), tt::Setup::offsetLayerId(), trklet::ChannelAssignment::offsetStub(), trklet::Settings::phiresidbits(), trackerTFP::phiT, conifer::pow(), tt::Setup::psModule(), region_, trklet::Settings::rresidbits(), trklet::ChannelAssignment::seedingLayers(), settings_, setup_, tt::Setup::stubPos(), tt::Setup::stubR(), stubs_, tt::Setup::tiltedLayerLimitZ(), tt::Setup::trackletLayerId(), tracks_, funct::true, useTTStubResiduals_, TTBV::val(), validateGeometry_cfg::valid, tt::Setup::widthAddrBRAM18(), trklet::Settings::zresidbits(), and trackerTFP::zT.

60  {
61  static const double maxCot = sinh(setup_->maxEta()) + setup_->beamWindowZ() / setup_->chosenRofZ();
62  static const int unusedMSBcot = floor(log2(baseUcot_ * pow(2, settings_->nbitst()) / (2. * maxCot)));
63  static const double baseCot =
64  baseUcot_ * pow(2, settings_->nbitst() - unusedMSBcot - 1 - setup_->widthAddrBRAM18());
65  const int offsetTrack = region_ * channelAssignment_->numChannelsTrack();
66  // count tracks and stubs to reserve container
67  int nTracks(0);
68  int nStubs(0);
69  for (int channel = 0; channel < channelAssignment_->numChannelsTrack(); channel++) {
70  const int channelTrack = offsetTrack + channel;
71  const int offsetStub = channelAssignment_->offsetStub(channelTrack);
72  const StreamTrack& streamTrack = streamsTrack[channelTrack];
73  input_[channel].reserve(streamTrack.size());
74  for (int frame = 0; frame < (int)streamTrack.size(); frame++) {
75  if (streamTrack[frame].first.isNull())
76  continue;
77  nTracks++;
78  for (int layer = 0; layer < channelAssignment_->numProjectionLayers(channel); layer++)
79  if (streamsStub[offsetStub + layer][frame].first.isNonnull())
80  nStubs++;
81  }
82  }
83  stubs_.reserve(nStubs + nTracks * channelAssignment_->numSeedingLayers());
84  tracks_.reserve(nTracks);
85  // store tracks and stubs
86  for (int channel = 0; channel < channelAssignment_->numChannelsTrack(); channel++) {
87  const int channelTrack = offsetTrack + channel;
88  const int offsetStub = channelAssignment_->offsetStub(channelTrack);
89  const StreamTrack& streamTrack = streamsTrack[channelTrack];
90  vector<Track*>& input = input_[channel];
91  for (int frame = 0; frame < (int)streamTrack.size(); frame++) {
92  const TTTrackRef& ttTrackRef = streamTrack[frame].first;
93  if (ttTrackRef.isNull()) {
94  input.push_back(nullptr);
95  continue;
96  }
97  //convert track parameter
98  const double r2Inv = digi(-ttTrackRef->rInv() / 2., baseUinv2R_);
99  const double phi0U =
100  digi(tt::deltaPhi(ttTrackRef->phi() - region_ * setup_->baseRegion() + setup_->hybridRangePhi() / 2.),
101  baseUphiT_);
102  const double phi0S = digi(phi0U - setup_->hybridRangePhi() / 2., baseUphiT_);
103  const double cot = digi(ttTrackRef->tanL(), baseUcot_);
104  const double z0 = digi(ttTrackRef->z0(), baseUzT_);
105  const double phiT = digi(phi0S + r2Inv * digi(dataFormats_->chosenRofPhi(), baseUr_), baseUphiT_);
106  const double zT = digi(z0 + cot * digi(setup_->chosenRofZ(), baseUr_), baseUzT_);
107  // kill tracks outside of fiducial range
108  if (abs(phiT) > setup_->baseRegion() / 2. || abs(zT) > setup_->hybridMaxCot() * setup_->chosenRofZ() ||
109  abs(z0) > setup_->beamWindowZ()) {
110  input.push_back(nullptr);
111  continue;
112  }
113  // convert stubs
114  vector<Stub*> stubs;
116  for (int layer = 0; layer < channelAssignment_->numProjectionLayers(channel); layer++) {
117  const FrameStub& frameStub = streamsStub[offsetStub + layer][frame];
118  const TTStubRef& ttStubRef = frameStub.first;
119  const int layerId = channelAssignment_->layerId(channel, layer);
120  if (ttStubRef.isNull())
121  continue;
122  // parse residuals from tt::Frame and take r and layerId from tt::TTStubRef
123  const bool barrel = setup_->barrel(ttStubRef);
124  const int layerIdTracklet = setup_->trackletLayerId(ttStubRef);
125  const double basePhi = barrel ? settings_->kphi1() : settings_->kphi(layerIdTracklet);
126  const double baseRZ = barrel ? settings_->kz(layerIdTracklet) : settings_->kz();
127  const int widthRZ = barrel ? settings_->zresidbits() : settings_->rresidbits();
128  TTBV hw(frameStub.second);
129  const TTBV hwRZ(hw, widthRZ, 0, true);
130  hw >>= widthRZ;
131  const TTBV hwPhi(hw, settings_->phiresidbits(), 0, true);
132  hw >>= settings_->phiresidbits();
133  const double r = digi(setup_->stubR(hw, ttStubRef) - dataFormats_->chosenRofPhi(), baseUr_);
134  double phi = hwPhi.val(basePhi);
135  if (basePhi > baseUphi_)
136  phi += baseUphi_ / 2.;
137  const double z = digi(hwRZ.val(baseRZ) * (barrel ? 1. : -cot), baseUz_);
138  // determine module type
139  bool psTilt;
140  if (barrel) {
141  const double posZ = (r + digi(dataFormats_->chosenRofPhi(), baseUr_)) * cot + z0 + z;
142  const int indexLayerId = setup_->indexLayerId(ttStubRef);
143  const double limit = setup_->tiltedLayerLimitZ(indexLayerId);
144  psTilt = abs(posZ) < limit;
145  } else
146  psTilt = setup_->psModule(ttStubRef);
147  if (useTTStubResiduals_) {
148  const GlobalPoint gp = setup_->stubPos(ttStubRef);
149  const double ttR = r;
150  const double ttZ = gp.z() - (z0 + (ttR + dataFormats_->chosenRofPhi()) * cot);
151  stubs_.emplace_back(ttStubRef, layerId, ttR, phi, ttZ, psTilt);
152  } else
153  stubs_.emplace_back(ttStubRef, layerId, r, phi, z, psTilt);
154  stubs.push_back(&stubs_.back());
155  }
156  // create fake seed stubs, since TrackBuilder doesn't output these stubs, required by the KF.
157  for (int layerId : channelAssignment_->seedingLayers(channel)) {
158  const vector<TTStubRef>& ttStubRefs = ttTrackRef->getStubRefs();
159  auto sameLayer = [this, layerId](const TTStubRef& ttStubRef) {
160  return setup_->layerId(ttStubRef) == layerId;
161  };
162  const TTStubRef& ttStubRef = *find_if(ttStubRefs.begin(), ttStubRefs.end(), sameLayer);
163  const bool barrel = setup_->barrel(ttStubRef);
164  double r;
165  if (barrel)
167  else {
168  r = (z0 +
170  digi(1. / digi(abs(cot), baseCot), baseInvCot_);
172  }
173  static constexpr double phi = 0.;
174  static constexpr double z = 0.;
175  // determine module type
176  bool psTilt;
177  if (barrel) {
178  const double posZ =
180  const int indexLayerId = setup_->indexLayerId(ttStubRef);
181  const double limit = digi(setup_->tiltedLayerLimitZ(indexLayerId), baseUz_);
182  psTilt = abs(posZ) < limit;
183  } else
184  psTilt = true;
185  const GlobalPoint gp = setup_->stubPos(ttStubRef);
186  const double ttR = gp.perp() - dataFormats_->chosenRofPhi();
187  const double ttZ = gp.z() - (z0 + (ttR + dataFormats_->chosenRofPhi()) * cot);
189  stubs_.emplace_back(ttStubRef, layerId, ttR, phi, ttZ, psTilt);
190  else
191  stubs_.emplace_back(ttStubRef, layerId, r, phi, z, psTilt);
192  stubs.push_back(&stubs_.back());
193  }
194  const bool valid = frame < setup_->numFrames() ? true : enableTruncation_;
195  tracks_.emplace_back(ttTrackRef, valid, r2Inv, phiT, cot, zT, stubs);
196  input.push_back(&tracks_.back());
197  }
198  }
199  }
double baseUcot_
Definition: KFin.h:116
double hybridDiskZ(int layerId) const
Definition: Setup.h:298
bool enableTruncation_
Definition: KFin.h:92
double baseUzT_
Definition: KFin.h:117
double baseUinv2R_
Definition: KFin.h:114
double kz() const
Definition: Settings.h:336
double hybridLayerR(int layerId) const
Definition: Setup.h:296
double hybridRangePhi() const
Definition: Setup.h:300
double hybridMaxCot() const
Definition: Setup.h:292
double kphi1() const
Definition: Settings.h:333
double chosenRofZ() const
Definition: Setup.h:413
double baseUphi_
Definition: KFin.h:119
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
std::vector< Stub > stubs_
Definition: KFin.h:110
const std::vector< int > & seedingLayers(int seedType) const
int numFrames() const
Definition: Setup.h:153
constexpr int pow(int x)
Definition: conifer.h:24
double digi(double val, double base) const
Definition: KFin.h:40
const ChannelAssignment * channelAssignment_
Definition: KFin.h:102
double baseUr_
Definition: KFin.h:118
double baseInvCot_
Definition: KFin.h:138
bool useTTStubResiduals_
Definition: KFin.h:94
std::vector< FrameTrack > StreamTrack
Definition: TTTypes.h:64
int offsetStub(int channelTrack) const
int rresidbits() const
Definition: Settings.h:403
static std::string const input
Definition: EdmProvDump.cc:50
double chosenRofPhi() const
Definition: DataFormats.h:508
double tiltedLayerLimitZ(int layer) const
Definition: Setup.h:165
int nbitst() const
Definition: Settings.h:370
double beamWindowZ() const
Definition: Setup.h:180
GlobalPoint stubPos(const TTStubRef &ttStubRef) const
Definition: Setup.cc:820
double maxEta() const
Definition: Setup.h:211
const int region_
Definition: KFin.h:106
int layerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:507
std::vector< Track > tracks_
Definition: KFin.h:108
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Settings * settings_
Definition: KFin.h:104
double stubR(const TTBV &hw, const TTStubRef &ttStubRef) const
Definition: Setup.cc:754
std::vector< std::vector< Track * > > input_
Definition: KFin.h:112
bool isNull() const
Checks for null.
Definition: Ref.h:235
int offsetLayerDisks() const
Definition: Setup.h:367
int offsetLayerId() const
Definition: Setup.h:369
int numProjectionLayers(int seedType) const
int widthAddrBRAM18() const
Definition: Setup.h:151
bool psModule(int dtcId) const
Definition: Setup.cc:318
double baseUphiT_
Definition: KFin.h:115
int trackletLayerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:514
int zresidbits() const
Definition: Settings.h:402
int phiresidbits() const
Definition: Settings.h:401
double deltaPhi(double lhs, double rhs=0.)
Definition: Setup.h:37
bool layerId(int seedType, const TTStubRef &ttStubRef, int &layerId) const
int indexLayerId(const TTStubRef &ttStubRef) const
Definition: Setup.cc:519
double baseRegion() const
Definition: Setup.h:184
const trackerTFP::DataFormats * dataFormats_
Definition: KFin.h:98
const tt::Setup * setup_
Definition: KFin.h:96
double kphi() const
Definition: Settings.h:332
bool barrel(const TTStubRef &ttStubRef) const
Definition: Setup.cc:524
double baseUz_
Definition: KFin.h:120

◆ digi()

double trklet::KFin::digi ( double  val,
double  base 
) const
inlineprivate

Definition at line 40 of file KFin.h.

References newFWLiteAna::base, MillePedeFileConverter_cfg::e, and heppy_batch::val.

Referenced by consume(), produce(), and redigi().

40 { return (floor(val / base + 1.e-12) + .5) * base; }
base
Main Program
Definition: newFWLiteAna.py:92

◆ produce()

void trklet::KFin::produce ( tt::StreamsStub accpetedStubs,
tt::StreamsTrack acceptedTracks,
tt::StreamsStub lostStubs,
tt::StreamsTrack lostTracks 
)

Definition at line 202 of file KFin.cc.

References funct::abs(), Reference_intrackfit_cff::barrel, tt::Setup::barrel(), baseHcot_, baseHinv2R_, baseHphi_, baseHphiT_, baseHr_, baseHz_, baseHzT_, baseLcot_, baseLinv2R_, baseLphi_, baseLphiT_, baseLr_, baseLz_, baseLzT_, tt::Setup::baseSector(), baseUcot_, baseUinv2R_, baseUphi_, baseUphiT_, baseUr_, baseUz_, baseUzT_, tt::Setup::beamWindowZ(), tt::Setup::boundarieEta(), reco::ceil(), channelAssignment_, trackerTFP::DataFormats::chosenRofPhi(), tt::Setup::chosenRofZ(), trackerTFP::cot, dataFormats_, digi(), HLT_2023v12_cff::dPhi, trklet::KFin::Stub::dPhi_, PVValHelper::dz, l1ctLayer1_cff::dZ, trklet::KFin::Stub::dZ_, cond::serialization::equal(), trackerTFP::DataFormats::format(), hfClusterShapes_cfi::hits, caHitNtupletGeneratorKernels::if(), input, input_, trackerTFP::DataFormat::inRange(), trackerTFP::inv2R, tt::Setup::kfMinLayers(), trklet::KFin::Stub::layer_, layerEncoding_, trackerTFP::LayerEncoding::layerIdKF(), tt::Setup::length2S(), tt::Setup::lengthPS(), isotracks_cff::lostTracks, tt::Setup::maxEta(), trackerTFP::LayerEncoding::maybePattern(), trklet::ChannelAssignment::numChannelsTrack(), tt::Setup::numLayers(), tt::Setup::numSectorsEta(), PVValHelper::phi, trklet::KFin::Stub::phi_, trackerTFP::phiT, tt::Setup::pitch2S(), tt::Setup::pitchPS(), conifer::pow(), tt::Setup::psModule(), trklet::KFin::Stub::psTilt_, alignCSCRings::r, trklet::KFin::Stub::r_, redigi(), region_, alignCSCRings::s, tt::Setup::scattering(), tt::Setup::sectorCot(), trackerTFP::sectorEta, trackerTFP::sectorPhi, setup_, TTBV::str(), tt::Setup::tbInnerRadius(), tt::Setup::tiltApproxIntercept(), tt::Setup::tiltApproxSlope(), tt::Setup::tiltUncertaintyR(), trackerTFP::DataFormat::toUnsigned(), HLT_2023v12_cff::track, tracks_, trackerTFP::DataFormat::ttBV(), trklet::KFin::Stub::ttStubRef_, trklet::KFin::Stub::valid_, trackerTFP::DataFormats::width(), tt::Setup::widthAddrBRAM18(), tt::Setup::widthDSPbu(), detailsBasic3DVector::z, trklet::KFin::Stub::z_, and trackerTFP::zT.

205  {
206  static constexpr int usedMSBpitchOverRaddr = 1;
207  static const double baseR =
208  baseLr_ *
209  pow(2, dataFormats_->width(Variable::r, Process::zht) - setup_->widthAddrBRAM18() + usedMSBpitchOverRaddr);
210  static const double baseRinvR =
211  baseLr_ * pow(2, dataFormats_->width(Variable::r, Process::zht) - setup_->widthAddrBRAM18());
212  static const double basePhi = baseLinv2R_ * baseLr_;
213  static const double baseInvR =
214  pow(2., ceil(log2(baseLr_ / setup_->tbInnerRadius())) - setup_->widthDSPbu()) / baseLr_;
215  static const double maxCot = sinh(setup_->maxEta()) + setup_->beamWindowZ() / setup_->chosenRofZ();
216  static constexpr int usedMSBCotLutaddr = 3;
217  static const double baseCotLut = pow(2., ceil(log2(maxCot)) - setup_->widthAddrBRAM18() + usedMSBCotLutaddr);
218  // base transform into high precision TMTT format
219  for (Track& track : tracks_) {
220  track.inv2R_ = redigi(track.inv2R_, baseUinv2R_, baseHinv2R_, setup_->widthDSPbu());
221  track.phiT_ = redigi(track.phiT_, baseUphiT_, baseHphiT_, setup_->widthDSPbu());
224  for (Stub* stub : track.stubs_) {
225  stub->r_ = redigi(stub->r_, baseUr_, baseHr_, setup_->widthDSPbu());
226  stub->phi_ = redigi(stub->phi_, baseUphi_, baseHphi_, setup_->widthDSPbu());
227  stub->z_ = redigi(stub->z_, baseUz_, baseHz_, setup_->widthDSPbu());
228  }
229  }
230  // find sector
231  for (Track& track : tracks_) {
232  const int sectorPhi = track.phiT_ < 0. ? 0 : 1;
233  track.phiT_ -= (sectorPhi - .5) * setup_->baseSector();
234  int sectorEta(-1);
235  for (; sectorEta < setup_->numSectorsEta(); sectorEta++)
236  if (track.zT_ < digi(setup_->chosenRofZ() * sinh(setup_->boundarieEta(sectorEta + 1)), baseHzT_))
237  break;
238  if (sectorEta >= setup_->numSectorsEta() || sectorEta <= -1) {
239  track.valid_ = false;
240  continue;
241  }
242  track.cot_ = track.cot_ - digi(setup_->sectorCot(sectorEta), baseHcot_);
243  track.zT_ = track.zT_ - digi(setup_->chosenRofZ() * setup_->sectorCot(sectorEta), baseHzT_);
244  track.sector_ = sectorPhi * setup_->numSectorsEta() + sectorEta;
245  }
246  // base transform into TMTT format
247  for (Track& track : tracks_) {
248  if (!track.valid_)
249  continue;
250  // store track parameter shifts
251  const double dinv2R = digi(track.inv2R_ - digi(track.inv2R_, baseLinv2R_), baseHinv2R_);
252  const double dphiT = digi(track.phiT_ - digi(track.phiT_, baseLphiT_), baseHphiT_);
253  const double dcot = digi(track.cot_ - digi(track.cot_, baseLcot_), baseHcot_);
254  const double dzT = digi(track.zT_ - digi(track.zT_, baseLzT_), baseHzT_);
255  // shift track parameter;
256  track.inv2R_ = digi(track.inv2R_, baseLinv2R_);
257  track.phiT_ = digi(track.phiT_, baseLphiT_);
258  track.cot_ = digi(track.cot_, baseLcot_);
259  track.zT_ = digi(track.zT_, baseLzT_);
260  // range checks
261  if (!dataFormats_->format(Variable::inv2R, Process::kfin).inRange(track.inv2R_, true))
262  track.valid_ = false;
263  if (!dataFormats_->format(Variable::phiT, Process::kfin).inRange(track.phiT_, true))
264  track.valid_ = false;
265  if (!dataFormats_->format(Variable::cot, Process::kfin).inRange(track.cot_, true))
266  track.valid_ = false;
267  if (!dataFormats_->format(Variable::zT, Process::kfin).inRange(track.zT_, true))
268  track.valid_ = false;
269  if (!track.valid_)
270  continue;
271  // adjust stub residuals by track parameter shifts
272  for (Stub* stub : track.stubs_) {
273  const double dphi = digi(dphiT + stub->r_ * dinv2R, baseHphi_);
274  const double r = stub->r_ + digi(dataFormats_->chosenRofPhi() - setup_->chosenRofZ(), baseHr_);
275  const double dz = digi(dzT + r * dcot, baseHz_);
276  stub->phi_ = digi(stub->phi_ + dphi, baseLphi_);
277  stub->z_ = digi(stub->z_ + dz, baseLz_);
278  // range checks
279  if (!dataFormats_->format(Variable::phi, Process::kfin).inRange(stub->phi_))
280  stub->valid_ = false;
281  if (!dataFormats_->format(Variable::z, Process::kfin).inRange(stub->z_))
282  stub->valid_ = false;
283  }
284  }
285  // encode layer id
286  for (Track& track : tracks_) {
287  if (!track.valid_)
288  continue;
289  const int sectorEta = track.sector_ % setup_->numSectorsEta();
290  const int zT = dataFormats_->format(Variable::zT, Process::kfin).toUnsigned(track.zT_);
291  const int cot = dataFormats_->format(Variable::cot, Process::kfin).toUnsigned(track.cot_);
292  track.maybe_ = TTBV(0, setup_->numLayers());
293  for (Stub* stub : track.stubs_) {
294  if (!stub->valid_)
295  continue;
296  // replace layerId by encoded layerId
297  stub->layer_ = layerEncoding_->layerIdKF(sectorEta, zT, cot, stub->layer_);
298  // kill stubs from layers which can't be crossed by track
299  if (stub->layer_ == -1)
300  stub->valid_ = false;
301  if (stub->valid_) {
302  if (track.maybe_[stub->layer_]) {
303  for (Stub* s : track.stubs_) {
304  if (s == stub)
305  break;
306  if (s->layer_ == stub->layer_)
307  s->valid_ = false;
308  }
309  } else
310  track.maybe_.set(stub->layer_);
311  }
312  }
313  // lookup maybe layers
314  track.maybe_ &= layerEncoding_->maybePattern(sectorEta, zT, cot);
315  }
316  // kill tracks with not enough layer
317  for (Track& track : tracks_) {
318  if (!track.valid_)
319  continue;
320  TTBV hits(0, setup_->numLayers());
321  for (const Stub* stub : track.stubs_)
322  if (stub->valid_)
323  hits.set(stub->layer_);
324  if (hits.count() < setup_->kfMinLayers())
325  track.valid_ = false;
326  }
327  // calculate stub uncertainties
328  for (Track& track : tracks_) {
329  if (!track.valid_)
330  continue;
331  const int sectorEta = track.sector_ % setup_->numSectorsEta();
332  const double inv2R = abs(track.inv2R_);
333  for (Stub* stub : track.stubs_) {
334  if (!stub->valid_)
335  continue;
336  const bool barrel = setup_->barrel(stub->ttStubRef_);
337  const bool ps = barrel ? setup_->psModule(stub->ttStubRef_) : stub->psTilt_;
338  const bool tilt = barrel ? (ps && !stub->psTilt_) : false;
339  const double length = ps ? setup_->lengthPS() : setup_->length2S();
340  const double pitch = ps ? setup_->pitchPS() : setup_->pitch2S();
341  const double pitchOverR = digi(pitch / (digi(stub->r_, baseR) + dataFormats_->chosenRofPhi()), basePhi);
342  const double r = digi(stub->r_, baseRinvR) + dataFormats_->chosenRofPhi();
343  const double sumdz = track.zT_ + stub->z_;
344  const double dZ = digi(sumdz - digi(setup_->chosenRofZ(), baseLr_) * track.cot_, baseLcot_ * baseLr_);
345  const double sumcot = track.cot_ + digi(setup_->sectorCot(sectorEta), baseHcot_);
346  const double cot = digi(abs(dZ * digi(1. / r, baseInvR) + sumcot), baseCotLut);
347  double lengthZ = length;
348  double lengthR = 0.;
349  if (!barrel) {
350  lengthZ = length * cot;
351  lengthR = length;
352  } else if (tilt) {
353  lengthZ = length * abs(setup_->tiltApproxSlope() * cot + setup_->tiltApproxIntercept());
354  lengthR = setup_->tiltUncertaintyR();
355  }
356  const double scat = digi(setup_->scattering(), baseLr_);
357  stub->dZ_ = lengthZ + baseLz_;
358  stub->dPhi_ = (scat + digi(lengthR, baseLr_)) * inv2R + pitchOverR;
359  stub->dPhi_ = digi(stub->dPhi_, baseLphi_) + baseLphi_;
360  }
361  }
362  // fill products StreamsStub& accpetedStubs, StreamsTrack& acceptedTracks, StreamsStub& lostStubs, StreamsTrack& lostTracks
363  auto frameTrack = [this](Track* track) {
364  const TTBV maybe(track->maybe_);
365  const TTBV sectorPhi(
366  dataFormats_->format(Variable::sectorPhi, Process::kfin).ttBV(track->sector_ / setup_->numSectorsEta()));
367  const TTBV sectorEta(
368  dataFormats_->format(Variable::sectorEta, Process::kfin).ttBV(track->sector_ % setup_->numSectorsEta()));
369  const TTBV inv2R(dataFormats_->format(Variable::inv2R, Process::kfin).ttBV(track->inv2R_));
370  const TTBV phiT(dataFormats_->format(Variable::phiT, Process::kfin).ttBV(track->phiT_));
371  const TTBV cot(dataFormats_->format(Variable::cot, Process::kfin).ttBV(track->cot_));
372  const TTBV zT(dataFormats_->format(Variable::zT, Process::kfin).ttBV(track->zT_));
373  return FrameTrack(track->ttTrackRef_,
374  Frame("1" + maybe.str() + sectorPhi.str() + sectorEta.str() + phiT.str() + inv2R.str() +
375  zT.str() + cot.str()));
376  };
377  auto frameStub = [this](Track* track, int layer) {
378  auto equal = [layer](Stub* stub) { return stub->valid_ && stub->layer_ == layer; };
379  const auto it = find_if(track->stubs_.begin(), track->stubs_.end(), equal);
380  if (it == track->stubs_.end() || !(*it)->valid_)
381  return FrameStub();
382  Stub* stub = *it;
383  const TTBV r(dataFormats_->format(Variable::r, Process::kfin).ttBV(stub->r_));
384  const TTBV phi(dataFormats_->format(Variable::phi, Process::kfin).ttBV(stub->phi_));
385  const TTBV z(dataFormats_->format(Variable::z, Process::kfin).ttBV(stub->z_));
386  const TTBV dPhi(dataFormats_->format(Variable::dPhi, Process::kfin).ttBV(stub->dPhi_));
387  const TTBV dZ(dataFormats_->format(Variable::dZ, Process::kfin).ttBV(stub->dZ_));
388  return FrameStub(stub->ttStubRef_, Frame("1" + r.str() + phi.str() + z.str() + dPhi.str() + dZ.str()));
389  };
390  auto invalid = [](Track* track) { return track && !track->valid_; };
391  auto acc = [invalid](int sum, Track* track) { return sum + (invalid(track) ? 1 : 0); };
392  const int offsetTrack = region_ * channelAssignment_->numChannelsTrack();
393  for (int channel = 0; channel < channelAssignment_->numChannelsTrack(); channel++) {
394  const int channelTrack = offsetTrack + channel;
395  const int offsetStub = channelTrack * setup_->numLayers();
396  vector<Track*>& input = input_[channel];
397  // fill lost tracks and stubs without gaps
398  const int lost = accumulate(input.begin(), input.end(), 0, acc);
399  lostTracks[channelTrack].reserve(lost);
400  for (int layer = 0; layer < setup_->numLayers(); layer++)
401  lostStubs[offsetStub + layer].reserve(lost);
402  for (Track* track : input) {
403  if (!track || track->valid_)
404  continue;
405  lostTracks[channelTrack].emplace_back(frameTrack(track));
406  for (int layer = 0; layer < setup_->numLayers(); layer++)
407  lostStubs[offsetStub + layer].emplace_back(frameStub(track, layer));
408  }
409  // fill accepted tracks and stubs with gaps
410  acceptedTracks[channelTrack].reserve(input.size());
411  for (int layer = 0; layer < setup_->numLayers(); layer++)
412  accpetedStubs[offsetStub + layer].reserve(input.size());
413  for (Track* track : input) {
414  if (!track || !track->valid_) { // fill gap
415  acceptedTracks[channelTrack].emplace_back(FrameTrack());
416  for (int layer = 0; layer < setup_->numLayers(); layer++)
417  accpetedStubs[offsetStub + layer].emplace_back(FrameStub());
418  continue;
419  }
420  acceptedTracks[channelTrack].emplace_back(frameTrack(track));
421  for (int layer = 0; layer < setup_->numLayers(); layer++)
422  accpetedStubs[offsetStub + layer].emplace_back(frameStub(track, layer));
423  }
424  }
425  }
double baseUcot_
Definition: KFin.h:116
bool inRange(double d, bool digi=false) const
Definition: DataFormats.h:106
double baseUzT_
Definition: KFin.h:117
constexpr int32_t ceil(float num)
double baseUinv2R_
Definition: KFin.h:114
std::bitset< TTBV::S_ > Frame
Definition: TTTypes.h:58
double length2S() const
Definition: Setup.h:173
double chosenRofZ() const
Definition: Setup.h:413
double baseUphi_
Definition: KFin.h:119
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:20
std::pair< TTStubRef, Frame > FrameStub
Definition: TTTypes.h:60
TTBV ttBV(int i) const
Definition: DataFormats.h:78
double baseLr_
Definition: KFin.h:126
double boundarieEta(int eta) const
Definition: Setup.h:417
double baseHzT_
Definition: KFin.h:133
double baseHcot_
Definition: KFin.h:132
int widthDSPbu() const
Definition: Setup.h:141
constexpr int pow(int x)
Definition: conifer.h:24
double digi(double val, double base) const
Definition: KFin.h:40
const ChannelAssignment * channelAssignment_
Definition: KFin.h:102
double baseHphi_
Definition: KFin.h:135
double lengthPS() const
Definition: Setup.h:175
double baseUr_
Definition: KFin.h:118
double baseHinv2R_
Definition: KFin.h:130
float float float z
TTBV maybePattern(int binEta, int binZT, int binCot) const
int kfMinLayers() const
Definition: Setup.h:489
bool equal(const T &first, const T &second)
Definition: Equal.h:32
static std::string const input
Definition: EdmProvDump.cc:50
int width(Variable v, Process p) const
Definition: DataFormats.h:490
double chosenRofPhi() const
Definition: DataFormats.h:508
double baseLz_
Definition: KFin.h:128
double pitch2S() const
Definition: Setup.h:169
std::pair< TTTrackRef, Frame > FrameTrack
Definition: TTTypes.h:62
double pitchPS() const
Definition: Setup.h:171
int numSectorsEta() const
Definition: Setup.h:411
double beamWindowZ() const
Definition: Setup.h:180
double tiltUncertaintyR() const
Definition: Setup.h:253
double baseSector() const
Definition: Setup.h:420
double maxEta() const
Definition: Setup.h:211
const int region_
Definition: KFin.h:106
std::vector< Track > tracks_
Definition: KFin.h:108
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::vector< Track * > > input_
Definition: KFin.h:112
double baseLcot_
Definition: KFin.h:124
double baseHr_
Definition: KFin.h:134
double baseHphiT_
Definition: KFin.h:131
double tiltApproxSlope() const
Definition: Setup.h:249
int numLayers() const
Definition: Setup.h:215
double baseLinv2R_
Definition: KFin.h:122
double baseLzT_
Definition: KFin.h:125
double redigi(double val, double baseLow, double baseHigh, int widthMultiplier) const
Definition: KFin.cc:428
int widthAddrBRAM18() const
Definition: Setup.h:151
bool psModule(int dtcId) const
Definition: Setup.cc:318
double tbInnerRadius() const
Definition: Setup.h:304
double baseUphiT_
Definition: KFin.h:115
double baseHz_
Definition: KFin.h:136
double scattering() const
Definition: Setup.h:255
int toUnsigned(int i) const
Definition: DataFormats.h:102
double tiltApproxIntercept() const
Definition: Setup.h:251
double baseLphi_
Definition: KFin.h:127
const int layerIdKF(int binEta, int binZT, int binCot, int layerId) const
double baseLphiT_
Definition: KFin.h:123
double sectorCot(int eta) const
Definition: Setup.h:428
const trackerTFP::DataFormats * dataFormats_
Definition: KFin.h:98
const tt::Setup * setup_
Definition: KFin.h:96
bool barrel(const TTStubRef &ttStubRef) const
Definition: Setup.cc:524
const trackerTFP::LayerEncoding * layerEncoding_
Definition: KFin.h:100
double baseUz_
Definition: KFin.h:120
const DataFormat & format(Variable v, Process p) const
Definition: DataFormats.h:506

◆ redigi()

double trklet::KFin::redigi ( double  val,
double  baseLow,
double  baseHigh,
int  widthMultiplier 
) const
private

Definition at line 428 of file KFin.cc.

References newFWLiteAna::base, digi(), conifer::pow(), HcalDetIdTransform::transform(), and heppy_batch::val.

Referenced by produce().

428  {
429  const double base = pow(2, 1 - widthMultiplier);
430  const double transform = digi(baseLow / baseHigh, base);
431  return (floor(val * transform / baseLow) + .5) * baseHigh;
432  }
base
Main Program
Definition: newFWLiteAna.py:92
constexpr int pow(int x)
Definition: conifer.h:24
double digi(double val, double base) const
Definition: KFin.h:40
unsigned transform(const HcalDetId &id, unsigned transformCode)

Member Data Documentation

◆ baseHcot_

double trklet::KFin::baseHcot_
private

Definition at line 132 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseHinv2R_

double trklet::KFin::baseHinv2R_
private

Definition at line 130 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseHphi_

double trklet::KFin::baseHphi_
private

Definition at line 135 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseHphiT_

double trklet::KFin::baseHphiT_
private

Definition at line 131 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseHr_

double trklet::KFin::baseHr_
private

Definition at line 134 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseHz_

double trklet::KFin::baseHz_
private

Definition at line 136 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseHzT_

double trklet::KFin::baseHzT_
private

Definition at line 133 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseInvCot_

double trklet::KFin::baseInvCot_
private

Definition at line 138 of file KFin.h.

Referenced by consume(), and KFin().

◆ baseLcot_

double trklet::KFin::baseLcot_
private

Definition at line 124 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseLinv2R_

double trklet::KFin::baseLinv2R_
private

Definition at line 122 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseLphi_

double trklet::KFin::baseLphi_
private

Definition at line 127 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseLphiT_

double trklet::KFin::baseLphiT_
private

Definition at line 123 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseLr_

double trklet::KFin::baseLr_
private

Definition at line 126 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseLz_

double trklet::KFin::baseLz_
private

Definition at line 128 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseLzT_

double trklet::KFin::baseLzT_
private

Definition at line 125 of file KFin.h.

Referenced by KFin(), and produce().

◆ baseUcot_

double trklet::KFin::baseUcot_
private

Definition at line 116 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ baseUinv2R_

double trklet::KFin::baseUinv2R_
private

Definition at line 114 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ baseUphi_

double trklet::KFin::baseUphi_
private

Definition at line 119 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ baseUphiT_

double trklet::KFin::baseUphiT_
private

Definition at line 115 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ baseUr_

double trklet::KFin::baseUr_
private

Definition at line 118 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ baseUz_

double trklet::KFin::baseUz_
private

Definition at line 120 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ baseUzT_

double trklet::KFin::baseUzT_
private

Definition at line 117 of file KFin.h.

Referenced by consume(), KFin(), and produce().

◆ channelAssignment_

const ChannelAssignment* trklet::KFin::channelAssignment_
private

Definition at line 102 of file KFin.h.

Referenced by consume(), and produce().

◆ dataFormats_

const trackerTFP::DataFormats* trklet::KFin::dataFormats_
private

Definition at line 98 of file KFin.h.

Referenced by consume(), and produce().

◆ enableTruncation_

bool trklet::KFin::enableTruncation_
private

Definition at line 92 of file KFin.h.

Referenced by consume().

◆ input_

std::vector<std::vector<Track*> > trklet::KFin::input_
private

Definition at line 112 of file KFin.h.

Referenced by consume(), and produce().

◆ layerEncoding_

const trackerTFP::LayerEncoding* trklet::KFin::layerEncoding_
private

Definition at line 100 of file KFin.h.

Referenced by produce().

◆ region_

const int trklet::KFin::region_
private

Definition at line 106 of file KFin.h.

Referenced by consume(), and produce().

◆ settings_

const Settings* trklet::KFin::settings_
private

Definition at line 104 of file KFin.h.

Referenced by consume(), and KFin().

◆ setup_

const tt::Setup* trklet::KFin::setup_
private

Definition at line 96 of file KFin.h.

Referenced by consume(), KFin(), produce(), and upgradeWorkflowComponents.UpgradeWorkflow::setup().

◆ stubs_

std::vector<Stub> trklet::KFin::stubs_
private

Definition at line 110 of file KFin.h.

Referenced by consume().

◆ tracks_

std::vector<Track> trklet::KFin::tracks_
private

Definition at line 108 of file KFin.h.

Referenced by consume(), and produce().

◆ useTTStubResiduals_

bool trklet::KFin::useTTStubResiduals_
private

Definition at line 94 of file KFin.h.

Referenced by consume().