CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
L1GTTInputProducer Class Reference

#include <L1Trigger/L1TTrackMatch/plugins/L1GTTInputProducer.cc>

Inheritance diagram for L1GTTInputProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 L1GTTInputProducer (const edm::ParameterSet &)
 
 ~L1GTTInputProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Types

enum  ConversionBitWidths {
  kEtaMagSize = 3, kEtaFracSize = 5, kEtaInputSize = 16, kPTMagSize = 7,
  kPTFracSize = 3, kPTInputSize = 15, kEtaOutputSize = kEtaMagSize + kEtaFracSize, kPTOutputSize = kPTMagSize + kPTFracSize
}
 
typedef TTTrack_TrackWord::tanl_t in_eta_t
 
typedef TTTrack_TrackWord::rinv_t in_pt_t
 
typedef TTTrack< Ref_Phase2TrackerDigi_L1Track
 
typedef ap_uint< 1 > out_charge_t
 
typedef ap_fixed< kEtaOutputSize, kEtaMagSize, AP_RND_CONV, AP_SAT > out_eta_t
 
typedef ap_ufixed< kPTOutputSize, kPTMagSize, AP_RND_CONV, AP_SAT > out_pt_t
 
typedef std::vector< L1TrackTTTrackCollection
 
typedef edm::View< L1TrackTTTrackCollectionView
 

Private Member Functions

void generate_eta_lut ()
 
void generate_pt_lut ()
 
bool getEtaBits (const L1Track &track, out_eta_t &etaBits, double &expected, double &maxErrPerc, double &maxErrEpsilon) const
 
bool getPtBits (const L1Track &track, out_pt_t &ptBits, out_charge_t &chargeBit, double &expected, double &maxErrPerc, double &maxErrEpsilon, double &minErrPerc, double &minExpected) const
 
double indexTanLambda2Eta (unsigned int indexTanLambda) const
 
double inverseRT2InversePT (unsigned int indexRT) const
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 
template<typename T >
int sgn (T val) const
 
double unpackSignedValue (unsigned int bits, unsigned int nBits, double lsb) const
 

Private Attributes

int debug_
 
std::vector< out_eta_teta_lut_
 
const edm::EDGetTokenT< TTTrackCollectionViewl1TracksToken_
 
const std::string outputCollectionName_
 
std::vector< out_pt_tpt_lut_
 

Static Private Attributes

static constexpr double kEtaErrThresh = 0.0485
 
static constexpr unsigned int kEtaLutSize = (1 << (ConversionBitWidths::kEtaOutputSize - 1))
 
static constexpr double kPTErrThresh = 5
 
static constexpr unsigned int kPtLutSize = (1 << ConversionBitWidths::kPTOutputSize)
 
static constexpr double kSynchrotron = (1.0 / (0.3 * 3.8))
 
static constexpr unsigned int Npars4 = 4
 
static constexpr unsigned int Npars5 = 5
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Description: Takes in L1TTracks and outputs the same tracks, but with modifications to the underlying track word. The modifications convert from Rinv –> pt and tanL –> eta.

Implementation: [Notes on implementation]

Definition at line 50 of file L1GTTInputProducer.cc.

Member Typedef Documentation

◆ in_eta_t

Definition at line 85 of file L1GTTInputProducer.cc.

◆ in_pt_t

Definition at line 87 of file L1GTTInputProducer.cc.

◆ L1Track

Definition at line 81 of file L1GTTInputProducer.cc.

◆ out_charge_t

typedef ap_uint<1> L1GTTInputProducer::out_charge_t
private

Definition at line 88 of file L1GTTInputProducer.cc.

◆ out_eta_t

typedef ap_fixed<kEtaOutputSize, kEtaMagSize, AP_RND_CONV, AP_SAT> L1GTTInputProducer::out_eta_t
private

Definition at line 84 of file L1GTTInputProducer.cc.

◆ out_pt_t

typedef ap_ufixed<kPTOutputSize, kPTMagSize, AP_RND_CONV, AP_SAT> L1GTTInputProducer::out_pt_t
private

Definition at line 86 of file L1GTTInputProducer.cc.

◆ TTTrackCollection

typedef std::vector<L1Track> L1GTTInputProducer::TTTrackCollection
private

Definition at line 82 of file L1GTTInputProducer.cc.

◆ TTTrackCollectionView

Definition at line 83 of file L1GTTInputProducer.cc.

Member Enumeration Documentation

◆ ConversionBitWidths

Enumerator
kEtaMagSize 
kEtaFracSize 
kEtaInputSize 
kPTMagSize 
kPTFracSize 
kPTInputSize 
kEtaOutputSize 
kPTOutputSize 

Definition at line 61 of file L1GTTInputProducer.cc.

61  {
62  kEtaMagSize = 3, // eta output magnitude size; MAG + FRAC should be <= kEtaInputSize
63  kEtaFracSize = 5, // eta output fraction size; MAG + FRAC should be <= kEtaInputSize
64  kEtaInputSize = 16, // size of tan(lambda)
65 
66  kPTMagSize = 7, // magnitude output size; MAG + FRAC should be <= kPTInputSize
67  kPTFracSize = 3, // fraction output size; MAG + FRAC should be <= kPTInputSize
68  kPTInputSize = 15, // size of 1/R
69 
70  kEtaOutputSize = kEtaMagSize + kEtaFracSize, // total bit width for eta
71  kPTOutputSize = kPTMagSize + kPTFracSize, // total bit width for pT
72  };

Constructor & Destructor Documentation

◆ L1GTTInputProducer()

L1GTTInputProducer::L1GTTInputProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 123 of file L1GTTInputProducer.cc.

References generate_eta_lut(), generate_pt_lut(), and outputCollectionName_.

124  : l1TracksToken_(consumes<TTTrackCollectionView>(iConfig.getParameter<edm::InputTag>("l1TracksInputTag"))),
125  outputCollectionName_(iConfig.getParameter<std::string>("outputCollectionName")),
126  debug_(iConfig.getParameter<int>("debug")) {
127  // Generate the required luts
129  generate_pt_lut();
130 
131  // Define EDM output to be written to file (if required)
132  produces<TTTrackCollection>(outputCollectionName_);
133  produces<std::vector<double>>("L1GTTInputTrackPtExpected");
134  produces<std::vector<double>>("L1GTTInputTrackEtaExpected");
135 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::EDGetTokenT< TTTrackCollectionView > l1TracksToken_
const std::string outputCollectionName_

◆ ~L1GTTInputProducer()

L1GTTInputProducer::~L1GTTInputProducer ( )
override

Definition at line 137 of file L1GTTInputProducer.cc.

137 {}

Member Function Documentation

◆ fillDescriptions()

void L1GTTInputProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 528 of file L1GTTInputProducer.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

528  {
529  // L1GTTInputProducer
531  desc.add<int>("debug", 0)->setComment("Verbosity levels: 0, 1, 2, 3");
532  desc.add<edm::InputTag>("l1TracksInputTag", edm::InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks"));
533  desc.add<std::string>("outputCollectionName", "Level1TTTracksConverted");
534  descriptions.addWithDefaultLabel(desc);
535 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ generate_eta_lut()

void L1GTTInputProducer::generate_eta_lut ( )
private

generate_lut: calculate the lut and write it to a file

  • argument:None
  • return (void): None
  • method: 1) iterates through all possibilities of the input value 2) finds values of eta from input values 3) stores the values of eta in an array (lut) 4) writes out the array into a file (eta_lut.h)

Definition at line 153 of file L1GTTInputProducer.cc.

References debug_, eta_lut_, mps_fire::i, indexTanLambda2Eta(), kEtaInputSize, kEtaLutSize, kEtaOutputSize, dqm-mbProfile::log, and funct::pow().

Referenced by L1GTTInputProducer().

153  {
154  // initialize lut array
155  eta_lut_.reserve(kEtaLutSize);
156 
157  // iterate through all values in the lut
158  for (unsigned int i = 0; i < kEtaLutSize; i++) {
159  // -1 to ignore sign bit for input
160  unsigned int index = ((i + 0.5) * pow(2, (int)(kEtaInputSize - kEtaOutputSize)));
161  double newValue = indexTanLambda2Eta(index); // map out the index to the represented eta
162  out_eta_t out_eta = newValue; // cast it to fxp
163  eta_lut_[i] = out_eta; // add value for the lut
164  }
165 
166  if (debug_ >= 3) {
167  edm::LogInfo log("L1GTTInputProducer");
168  log << "generate_eta_lut::The eta_lut_[" << kEtaLutSize << "] values are ... \n";
169  for (unsigned int i = 0; i < kEtaLutSize; i++) {
170  log << "\t" << i << "\t" << eta_lut_[i] << "\n";
171  }
172  }
173 }
static constexpr unsigned int kEtaLutSize
std::vector< out_eta_t > eta_lut_
ap_fixed< kEtaOutputSize, kEtaMagSize, AP_RND_CONV, AP_SAT > out_eta_t
double indexTanLambda2Eta(unsigned int indexTanLambda) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ generate_pt_lut()

void L1GTTInputProducer::generate_pt_lut ( )
private

Definition at line 175 of file L1GTTInputProducer.cc.

References debug_, mps_fire::i, inverseRT2InversePT(), kPTInputSize, kPtLutSize, kPTOutputSize, dqm-mbProfile::log, funct::pow(), and pt_lut_.

Referenced by L1GTTInputProducer().

175  {
176  // initialize lut array
177  pt_lut_.reserve(kPtLutSize); // generate lut
178 
179  // iterate through all values in the lut
180  for (unsigned int i = 0; i < kPtLutSize; i++) {
181  unsigned int index = (i + 0.5) * pow(2, (int)(kPTInputSize - 1 - kPTOutputSize));
182  double newValue = inverseRT2InversePT(index); //map out the index to the represented 1/pT
183  out_pt_t out_pt = 1.0 / newValue; // take the reciprocal and cast as an AP fixed-point (1/pt ==> pt)
184  pt_lut_[i] = out_pt; // setting the i-th value for the lut
185  }
186 
187  if (debug_ >= 3) {
188  edm::LogInfo log("L1GTTInputProducer");
189  log << "generate_pt_lut::The pt_lut_[" << kPtLutSize << "] values are ... \n";
190  for (unsigned int i = 0; i < kPtLutSize; i++) {
191  log << "\t" << i << "\t" << pt_lut_[i] << "\n";
192  }
193  }
194 }
ap_ufixed< kPTOutputSize, kPTMagSize, AP_RND_CONV, AP_SAT > out_pt_t
static constexpr unsigned int kPtLutSize
std::vector< out_pt_t > pt_lut_
double inverseRT2InversePT(unsigned int indexRT) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ getEtaBits()

bool L1GTTInputProducer::getEtaBits ( const L1Track track,
out_eta_t etaBits,
double &  expected,
double &  maxErrPerc,
double &  maxErrEpsilon 
) const
private

Definition at line 246 of file L1GTTInputProducer.cc.

References funct::abs(), debug_, dumpMFGeometry_cfg::delta, eta_lut_, indexTanLambda2Eta(), kEtaErrThresh, kEtaInputSize, kEtaOutputSize, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::mask, funct::pow(), Validation_hcalonly_cfi::sign, HLT_2023v12_cff::track, and relativeConstraints::value.

Referenced by produce().

247  {
248  // Conver the input to an ap_uint
249  in_eta_t value = track.getTanlWord();
250 
251  // Get the expected outcome (floating point)
252  out_eta_t maxValuePossible = pow(2, 15); // saturate at max value possible for fxp
253  expected = indexTanLambda2Eta(value); // expected value for eta
254  if (expected > maxValuePossible) {
255  expected = maxValuePossible;
256  }
257 
258  // Converted value (emulation)
259  // Masking and shifting converts the efficient bit representation into an index
260  // Start by setting up the masks
261  in_eta_t indexTanLambda = value;
262  in_eta_t mask = ~0; // mask (all 1's)
263  bool sign = indexTanLambda.range(kEtaInputSize - 1, kEtaInputSize - 1); // sign bit of indexTanLambda
264  mask *= sign; // all 0's for positive numbers, all 1's for negative numbers
265 
266  // Take the absolute value of indexTanLambda (2's complement)
267  indexTanLambda ^= mask;
268  indexTanLambda += sign;
269 
270  // Find the value for eta, not |eta|
271  indexTanLambda =
272  indexTanLambda >>
273  (kEtaInputSize -
274  kEtaOutputSize); // Don't subtract 1 because we now want to take into account the sign bit of the output
275  indexTanLambda =
276  (indexTanLambda < (1 << (kEtaOutputSize - 1))) ? indexTanLambda : in_eta_t((1 << (kEtaOutputSize - 1)) - 1);
277  etaBits = eta_lut_[indexTanLambda];
278 
279  // Reinacting the sign
280  out_eta_t maskOut;
281  maskOut.V = ~0;
282  maskOut *= sign;
283  etaBits ^= maskOut;
284  etaBits.V += sign;
285 
286  // Compare the floating point calculation to the emulation
287  double delta = std::abs(expected - etaBits.to_double());
288  double perc_diff = (delta / std::abs(expected)) * 100.; // calc percentage error
289  if (delta > maxErrEpsilon) {
290  maxErrPerc = perc_diff;
291  maxErrEpsilon = delta;
292  }
293 
294  if (delta >= kEtaErrThresh) {
295  edm::LogError("L1GTTInputProducer") << "getEtaBits::MISMATCH!!!\n"
296  << "\tTTTrack tanL = " << track.tanL() << "\n"
297  << "\tTTTrack eta = " << track.momentum().eta() << "\n"
298  << "\tTTTrack_TrackWord = " << track.getTrackWord().to_string(2) << "\n"
299  << "\tTTTrack_TrackWord tanlWord = " << track.getTanlWord() << " ("
300  << track.getTanlWord().to_string(2) << ")\n"
301  << "\tin_eta_t value = " << value << " (" << value.to_string(2) << ")\n"
302  << "\tExpected value = " << expected << "\n"
303  << "\tCalculated eta = " << etaBits.to_double() << " (" << etaBits.to_string(2)
304  << ") @ index " << indexTanLambda << "\n"
305  << "\tDelta = " << delta << "\tpercentage error = " << perc_diff;
306  return true;
307  } else {
308  if (debug_ >= 2) {
309  edm::LogInfo("L1GTTInputProducer")
310  << "getEtaBits::SUCCESS (TTTrack, floating eta calculation, bitwise calculation, initial index, lut index) = "
311  << "(" << track.momentum().eta() << ", " << expected << ", " << etaBits << ", " << value << ", "
312  << indexTanLambda << ")";
313  }
314  }
315 
316  return false;
317 }
TTTrack_TrackWord::tanl_t in_eta_t
Log< level::Error, false > LogError
std::vector< out_eta_t > eta_lut_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ap_fixed< kEtaOutputSize, kEtaMagSize, AP_RND_CONV, AP_SAT > out_eta_t
Definition: value.py:1
Log< level::Info, false > LogInfo
static constexpr double kEtaErrThresh
double indexTanLambda2Eta(unsigned int indexTanLambda) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ getPtBits()

bool L1GTTInputProducer::getPtBits ( const L1Track track,
out_pt_t ptBits,
out_charge_t chargeBit,
double &  expected,
double &  maxErrPerc,
double &  maxErrEpsilon,
double &  minErrPerc,
double &  minExpected 
) const
private

Definition at line 319 of file L1GTTInputProducer.cc.

References funct::abs(), ALCARECOTkAlJpsiMuMu_cff::charge, debug_, dumpMFGeometry_cfg::delta, inverseRT2InversePT(), kPTErrThresh, kPTInputSize, kPTOutputSize, ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::mask, funct::pow(), pt_lut_, EcalSCDynamicDPhiParametersESProducer_cfi::saturation, sgn(), Validation_hcalonly_cfi::sign, HLT_2023v12_cff::track, and relativeConstraints::value.

Referenced by produce().

326  {
327  // Convert the input to an ap_uint
328  in_pt_t value = track.getRinvWord();
329  in_pt_t value_initial = value;
330 
331  // Get the expected outcome (floating point)
332  out_pt_t maxValuePossible = pow(2, 16); // saturate at max value possible for fxp
333  expected = 1.0 / inverseRT2InversePT(value); // expected value for inverse
334  bool saturation = true;
335  if (std::abs(expected) > maxValuePossible) {
336  expected = maxValuePossible;
337  } else {
338  saturation = false;
339  }
340 
341  // Converted value (emulation)
342  // Masking and shifting converts the efficient bit representation into an index
343  // Start by setting up the masks
344  in_pt_t mask = ~0; // mask (all 1's)
345  bool sign = value.range(kPTInputSize - 1, kPTInputSize - 1); // sign bit of value
346  mask *= sign; // all 0's for positive numbers, all 1's for negative numbers
347 
348  // Take the absolute value of value (2's complement)
349  value ^= mask;
350  value += sign;
351 
352  // Shift the value so that the index changes when the LSB of the output changes
353  value = value >> (kPTInputSize - 1 - (kPTOutputSize));
354 
355  // Get the pt from the LUT
356  ptBits = pt_lut_[value];
357 
358  // Set the charge bit
359  chargeBit = sign;
360  double charge = 1. - (2 * chargeBit.to_uint());
361 
362  // Compare the floating point calculation to the emulation
363  double delta = std::abs(expected - (charge * ptBits.to_double()));
364  double perc_diff = (delta / std::abs(expected)) * 100.;
365 
366  if (delta > maxErrEpsilon) {
367  maxErrPerc = perc_diff;
368  maxErrEpsilon = delta;
369  } else if (delta < minExpected && !saturation && minErrPerc > 100.0) {
370  minErrPerc = perc_diff;
371  minExpected = expected;
372  }
373 
374  if (std::abs(perc_diff) >= kPTErrThresh && !saturation) {
375  edm::LogError("L1GTTInputProducer") << "getPtBits::MISMATCH!!!\n"
376  << "\tTTTrack Rinv = " << track.rInv() << "\n"
377  << "\tTTTrack pt = " << track.momentum().transverse() << "\n"
378  << "\tTTTrack_TrackWord = " << track.getTrackWord().to_string(2) << "\n"
379  << "\tTTTrack_TrackWord RinvWord = " << track.getRinvWord() << " ("
380  << track.getRinvWord().to_string(2) << ")\n"
381  << "\tin_pt_t value = " << value_initial << " (" << value_initial.to_string(2)
382  << ")\n"
383  << "\tExpected value = " << expected << "\n"
384  << "\tCalculated pt = " << ptBits.to_double() << " (" << ptBits.to_string(2)
385  << ") @ index " << value << "\n"
386  << "\tcharge = " << charge << " (bit = " << chargeBit << ")\n"
387  << "\tDelta = " << delta << "\tpercentage error = " << perc_diff;
388  return true;
389  } else {
390  if (debug_ >= 2) {
391  edm::LogInfo("L1GTTInputProducer") << "getPtBits::SUCCESS (TTTrack, floating pt calculation, charge, bitwise "
392  "calculation, initial index, lut index) = "
393  << "(" << sgn(track.rInv()) * track.momentum().transverse() << ", " << expected
394  << ", " << charge << ", " << ptBits << ", " << value_initial << ", " << value
395  << ")";
396  }
397  }
398 
399  return false;
400 }
ap_ufixed< kPTOutputSize, kPTMagSize, AP_RND_CONV, AP_SAT > out_pt_t
int sgn(T val) const
Log< level::Error, false > LogError
TTTrack_TrackWord::rinv_t in_pt_t
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
Log< level::Info, false > LogInfo
std::vector< out_pt_t > pt_lut_
static constexpr double kPTErrThresh
double inverseRT2InversePT(unsigned int indexRT) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ indexTanLambda2Eta()

double L1GTTInputProducer::indexTanLambda2Eta ( unsigned int  indexTanLambda) const
private

indexTanLambda2Eta: calculates eta from tan(lambda)

  • argument: indexTanLambda (int): the index representation for tan(lambda)
  • formula: f(x) = -1*ln(tan((pi/2-atan(x))/2)), where x = tan(lambda)
  • return (double): eta

Definition at line 220 of file L1GTTInputProducer.cc.

References debug_, PVValHelper::eta, kEtaInputSize, dqm-mbProfile::log, M_PI, TTTrack_TrackWord::stepTanL, funct::tan(), theta(), and unpackSignedValue().

Referenced by generate_eta_lut(), and getEtaBits().

220  {
221  double tanl = unpackSignedValue(indexTanLambda, kEtaInputSize, TTTrack_TrackWord::stepTanL);
222  double theta = (M_PI / 2.0) - atan(tanl);
223  double eta = -1.0 * log(tan(theta / 2.0));
224  if (debug_ >= 3) {
225  edm::LogInfo("L1GTTInputProducer") << "indexTanLambda2Eta::tanl index = " << indexTanLambda << "\n"
226  << "indexTanLambda2Eta::tanl value = " << tanl << "\n"
227  << "indexTanLambda2Eta::theta = " << theta << "\n"
228  << "indexTanLambda2Eta::eta = " << eta;
229  }
230  return eta;
231 }
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static constexpr double stepTanL
#define M_PI
Log< level::Info, false > LogInfo
double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const
Geom::Theta< T > theta() const

◆ inverseRT2InversePT()

double L1GTTInputProducer::inverseRT2InversePT ( unsigned int  indexRT) const
private

inverseRT2InversePT: calculates 1/pT from 1/rT

  • argument: indexRT (int): the index representation for 1/rT
  • formula: f(x) = 100.*(1/(0.3*3.8))*x , where x = 1/R
  • return (double): 1/pT

Definition at line 241 of file L1GTTInputProducer.cc.

References kPTInputSize, kSynchrotron, TTTrack_TrackWord::stepRinv, and unpackSignedValue().

Referenced by generate_pt_lut(), and getPtBits().

241  {
242  double inverseRT = unpackSignedValue(indexRT, kPTInputSize, TTTrack_TrackWord::stepRinv);
243  return 100.0 * kSynchrotron * inverseRT; // multiply by 100 to convert from cm to m
244 }
static constexpr double stepRinv
static constexpr double kSynchrotron
double unpackSignedValue(unsigned int bits, unsigned int nBits, double lsb) const

◆ produce()

void L1GTTInputProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
overrideprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 403 of file L1GTTInputProducer.cc.

References debug_, Exception, getEtaBits(), getPtBits(), iEvent, kEtaErrThresh, kPTErrThresh, kPTInputSize, l1TracksToken_, eostools::move(), Npars4, Npars5, outputCollectionName_, and HLT_2023v12_cff::track.

403  {
404  auto vTTTrackOutput = std::make_unique<TTTrackCollection>();
405  auto vPtOutput = std::make_unique<std::vector<double>>();
406  auto vEtaOutput = std::make_unique<std::vector<double>>();
407 
408  edm::Handle<TTTrackCollectionView> l1TracksHandle;
409  iEvent.getByToken(l1TracksToken_, l1TracksHandle);
410 
411  out_charge_t chargeBit = 0;
412  out_pt_t ptBits = 0;
413  out_eta_t etaBits = 0;
414  in_pt_t ptBitsShifted = 0;
415  in_eta_t etaBitsShifted = 0;
416  unsigned int error_pt_c = 0; // error counter
417  unsigned int error_eta_c = 0; // error counter
418  double expectedPt = 0.0; // expected value of the pt
419  double expectedEta = 0.0; // expected value of the eta
420  double maxErrPercPt = 0.0; // stores the maximum error percentage
421  double maxErrPercEta = 0.0; // stores the maximum error percentage
422  double maxErrEpsilonPt = 0.0; // keeps track of epsilon for max error
423  double maxErrEpsilonEta = 0.0; // keeps track of epsilon for max error
424  double minErrPercPt = 10000000.0; // stores the maximum error percentage
425  double minExpectedPt = 10000000.0; // keeps track of epsilon for max error
426 
427  unsigned int nOutput = l1TracksHandle->size();
428  vTTTrackOutput->reserve(nOutput);
429  vPtOutput->reserve(nOutput);
430  vEtaOutput->reserve(nOutput);
431  for (const auto& track : *l1TracksHandle) {
432  if (!(track.nFitPars() == Npars4 || track.nFitPars() == Npars5)) {
433  throw cms::Exception("nFitPars unknown")
434  << "L1GTTInputProducer::produce method is called with numFitPars_ = " << track.nFitPars()
435  << ". The only possible values are 4/5.";
436  }
437 
438  // Fill the vector of tracks
439  vTTTrackOutput->push_back(track);
440  auto& currentTrackRef = vTTTrackOutput->back();
441  if (debug_ >= 2) {
442  edm::LogInfo("L1GTTInputProducer") << "produce::word before anything "
443  << currentTrackRef.getTrackWord().to_string(2);
444  }
445 
446  // Do an initial setting of the bits based on the floating point values
447  currentTrackRef.setTrackWordBits();
448  if (debug_ >= 2) {
449  edm::LogInfo("L1GTTInputProducer") << "produce::word after initial setting of the track word "
450  << currentTrackRef.getTrackWord().to_string(2);
451  }
452 
453  // Do the conversions
454  error_pt_c += getPtBits(
455  currentTrackRef, ptBits, chargeBit, expectedPt, maxErrPercPt, maxErrEpsilonPt, minErrPercPt, minExpectedPt);
456  error_eta_c += getEtaBits(currentTrackRef, etaBits, expectedEta, maxErrPercEta, maxErrEpsilonEta);
457 
458  // Assign the exat same bits to an ap_uint
459  ptBitsShifted = ptBits.range();
460  etaBitsShifted = etaBits.range();
461 
462  // Shift the bits so that the decimal is in the right spot for the GTT software
463  ptBitsShifted = ptBitsShifted << 2;
464  etaBitsShifted = etaBitsShifted << 8;
465 
466  // Set the MSB for the pt to the sign of the incoming word
467  ptBitsShifted.set(kPTInputSize - 1, chargeBit);
468 
469  // Set the correct bits based on the converted quanteties and the existing track word components
470  currentTrackRef.setTrackWord(currentTrackRef.getValidWord(),
471  ptBitsShifted,
472  currentTrackRef.getPhiWord(),
473  etaBitsShifted,
474  currentTrackRef.getZ0Word(),
475  currentTrackRef.getD0Word(),
476  currentTrackRef.getChi2RPhiWord(),
477  currentTrackRef.getChi2RZWord(),
478  currentTrackRef.getBendChi2Word(),
479  currentTrackRef.getHitPatternWord(),
480  currentTrackRef.getMVAQualityWord(),
481  currentTrackRef.getMVAOtherWord());
482  if (debug_ >= 2) {
483  edm::LogInfo("L1GTTInputProducer") << "produce::charge after all conversions " << chargeBit << "\n"
484  << "produce::ptBits after all conversions " << ptBits.to_string(2) << " ("
485  << ptBitsShifted.to_string(2) << " = " << ptBitsShifted.to_uint() << ")\n"
486  << "produce::etaBits after all conversions " << etaBits.to_string(2) << " ("
487  << etaBitsShifted.to_string(2) << " = " << etaBitsShifted.to_uint() << ")\n"
488  << "produce::word after all conversions "
489  << vTTTrackOutput->back().getTrackWord().to_string(2);
490  }
491 
492  // Fill the remaining outputs
493  vPtOutput->push_back(expectedPt);
494  vEtaOutput->push_back(expectedEta);
495  }
496 
497  if (debug_ >= 1) {
498  edm::LogInfo("L1GTTInputProducer") << "\nNumber of converted tracks: " << nOutput << "\n\n"
499  << "q/r ==> pt conversion:\n"
500  << "\tError Threshold: " << kPTErrThresh << "%\n"
501  << "\tMax error: " << maxErrEpsilonPt
502  << " GeV difference with percentage: " << maxErrPercPt << "% @ "
503  << 100.0 * maxErrEpsilonPt / maxErrPercPt << " GeV"
504  << "\n"
505  << "\tError @ max range: " << minExpectedPt
506  << " GeV with precentage: " << minErrPercPt << "%"
507  << "\n"
508  << "\tTotal number of errors: " << error_pt_c << "\n\n"
509  << "tan(lambda) ==> eta conversion:\n"
510  << "\tError Threshold: " << kEtaErrThresh << "\n"
511  << "\tMax error: " << maxErrEpsilonEta << " with percentage: " << maxErrPercEta
512  << "% @ " << 100.0 * maxErrEpsilonEta / maxErrPercEta << "\n"
513  << "\tTotal number of errors: " << error_eta_c;
514  }
515 
516  if (error_pt_c + error_eta_c) {
517  edm::LogError("L1GTTInputProducer") << "produce::" << error_pt_c << "/" << error_eta_c
518  << " pt/eta mismatches detected!!!";
519  }
520 
521  // Put the outputs into the event
522  iEvent.put(std::move(vTTTrackOutput), outputCollectionName_);
523  iEvent.put(std::move(vPtOutput), "L1GTTInputTrackPtExpected");
524  iEvent.put(std::move(vEtaOutput), "L1GTTInputTrackEtaExpected");
525 }
const edm::EDGetTokenT< TTTrackCollectionView > l1TracksToken_
const std::string outputCollectionName_
ap_ufixed< kPTOutputSize, kPTMagSize, AP_RND_CONV, AP_SAT > out_pt_t
TTTrack_TrackWord::tanl_t in_eta_t
Log< level::Error, false > LogError
TTTrack_TrackWord::rinv_t in_pt_t
int iEvent
Definition: GenABIO.cc:224
static constexpr unsigned int Npars5
ap_fixed< kEtaOutputSize, kEtaMagSize, AP_RND_CONV, AP_SAT > out_eta_t
Log< level::Info, false > LogInfo
bool getEtaBits(const L1Track &track, out_eta_t &etaBits, double &expected, double &maxErrPerc, double &maxErrEpsilon) const
static constexpr double kEtaErrThresh
static constexpr unsigned int Npars4
static constexpr double kPTErrThresh
bool getPtBits(const L1Track &track, out_pt_t &ptBits, out_charge_t &chargeBit, double &expected, double &maxErrPerc, double &maxErrEpsilon, double &minErrPerc, double &minExpected) const
def move(src, dest)
Definition: eostools.py:511

◆ sgn()

template<typename T >
int L1GTTInputProducer::sgn ( T  val) const
inlineprivate

Definition at line 107 of file L1GTTInputProducer.cc.

References heppy_batch::val.

Referenced by getPtBits().

107  {
108  return (T(0) < val) - (val < T(0));
109  } // From https://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
long double T

◆ unpackSignedValue()

double L1GTTInputProducer::unpackSignedValue ( unsigned int  bits,
unsigned int  nBits,
double  lsb 
) const
private

Definition at line 196 of file L1GTTInputProducer.cc.

References cms::cuda::assert(), ALPAKA_ACCELERATOR_NAMESPACE::pixelClustering::pixelStatus::bits, and l1tHGCalVFEProducer_cfi::lsb.

Referenced by indexTanLambda2Eta(), and inverseRT2InversePT().

196  {
197  // Check that none of the bits above the nBits-1 bit, in a range of [0, nBits-1], are set.
198  // This makes sure that it isn't possible for the value represented by 'bits' to be
199  // any bigger than ((1 << nBits) - 1).
200  assert((bits >> nBits) == 0);
201 
202  // Convert from twos compliment to C++ signed integer (normal digitized value)
203  int digitizedValue = bits;
204  if (bits & (1 << (nBits - 1))) { // check if the 'bits' is negative
205  digitizedValue -= (1 << nBits);
206  }
207 
208  // Convert to floating point value
209  return (double(digitizedValue) + 0.5) * lsb;
210 }
assert(be >=bs)

Member Data Documentation

◆ debug_

int L1GTTInputProducer::debug_
private

◆ eta_lut_

std::vector<out_eta_t> L1GTTInputProducer::eta_lut_
private

Definition at line 117 of file L1GTTInputProducer.cc.

Referenced by generate_eta_lut(), and getEtaBits().

◆ kEtaErrThresh

constexpr double L1GTTInputProducer::kEtaErrThresh = 0.0485
staticprivate

Definition at line 74 of file L1GTTInputProducer.cc.

Referenced by getEtaBits(), and produce().

◆ kEtaLutSize

constexpr unsigned int L1GTTInputProducer::kEtaLutSize = (1 << (ConversionBitWidths::kEtaOutputSize - 1))
staticprivate

Definition at line 79 of file L1GTTInputProducer.cc.

Referenced by generate_eta_lut().

◆ kPTErrThresh

constexpr double L1GTTInputProducer::kPTErrThresh = 5
staticprivate

Definition at line 76 of file L1GTTInputProducer.cc.

Referenced by getPtBits(), and produce().

◆ kPtLutSize

constexpr unsigned int L1GTTInputProducer::kPtLutSize = (1 << ConversionBitWidths::kPTOutputSize)
staticprivate

Definition at line 78 of file L1GTTInputProducer.cc.

Referenced by generate_pt_lut().

◆ kSynchrotron

constexpr double L1GTTInputProducer::kSynchrotron = (1.0 / (0.3 * 3.8))
staticprivate

Definition at line 77 of file L1GTTInputProducer.cc.

Referenced by inverseRT2InversePT().

◆ l1TracksToken_

const edm::EDGetTokenT<TTTrackCollectionView> L1GTTInputProducer::l1TracksToken_
private

Definition at line 113 of file L1GTTInputProducer.cc.

Referenced by produce().

◆ Npars4

constexpr unsigned int L1GTTInputProducer::Npars4 = 4
staticprivate

Definition at line 59 of file L1GTTInputProducer.cc.

Referenced by produce().

◆ Npars5

constexpr unsigned int L1GTTInputProducer::Npars5 = 5
staticprivate

Definition at line 60 of file L1GTTInputProducer.cc.

Referenced by produce().

◆ outputCollectionName_

const std::string L1GTTInputProducer::outputCollectionName_
private

Definition at line 114 of file L1GTTInputProducer.cc.

Referenced by L1GTTInputProducer(), and produce().

◆ pt_lut_

std::vector<out_pt_t> L1GTTInputProducer::pt_lut_
private

Definition at line 116 of file L1GTTInputProducer.cc.

Referenced by generate_pt_lut(), and getPtBits().