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 noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept 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_
 
bool setTrackWordBits_
 

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 124 of file L1GTTInputProducer.cc.

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

125  : l1TracksToken_(consumes<TTTrackCollectionView>(iConfig.getParameter<edm::InputTag>("l1TracksInputTag"))),
126  outputCollectionName_(iConfig.getParameter<std::string>("outputCollectionName")),
127  setTrackWordBits_(iConfig.getParameter<bool>("setTrackWordBits")),
128  debug_(iConfig.getParameter<int>("debug")) {
129  // Generate the required luts
131  generate_pt_lut();
132 
133  // Define EDM output to be written to file (if required)
134  produces<TTTrackCollection>(outputCollectionName_);
135  produces<std::vector<double>>("L1GTTInputTrackPtExpected");
136  produces<std::vector<double>>("L1GTTInputTrackEtaExpected");
137 }
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 139 of file L1GTTInputProducer.cc.

139 {}

Member Function Documentation

◆ fillDescriptions()

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

Definition at line 531 of file L1GTTInputProducer.cc.

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

531  {
532  // L1GTTInputProducer
534  desc.add<int>("debug", 0)->setComment("Verbosity levels: 0, 1, 2, 3");
535  desc.add<edm::InputTag>("l1TracksInputTag", edm::InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks"));
536  desc.add<std::string>("outputCollectionName", "Level1TTTracksConverted");
537  desc.add<bool>("setTrackWordBits", true)
538  ->setComment(
539  "flag indicated whether the TTTrack_TrackWord should be set from float parameters or skipped (if TrackWord "
540  "set by e.g. GTTFileReader decoding)");
541  descriptions.addWithDefaultLabel(desc);
542 }
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 155 of file L1GTTInputProducer.cc.

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

Referenced by L1GTTInputProducer().

155  {
156  // initialize lut array
157  eta_lut_.reserve(kEtaLutSize);
158 
159  // iterate through all values in the lut
160  for (unsigned int i = 0; i < kEtaLutSize; i++) {
161  // -1 to ignore sign bit for input
162  unsigned int index = ((i + 0.5) * pow(2, (int)(kEtaInputSize - kEtaOutputSize)));
163  double newValue = indexTanLambda2Eta(index); // map out the index to the represented eta
164  out_eta_t out_eta = newValue; // cast it to fxp
165  eta_lut_[i] = out_eta; // add value for the lut
166  }
167 
168  if (debug_ >= 3) {
169  edm::LogInfo log("L1GTTInputProducer");
170  log << "generate_eta_lut::The eta_lut_[" << kEtaLutSize << "] values are ... \n";
171  for (unsigned int i = 0; i < kEtaLutSize; i++) {
172  log << "\t" << i << "\t" << eta_lut_[i] << "\n";
173  }
174  }
175 }
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 177 of file L1GTTInputProducer.cc.

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

Referenced by L1GTTInputProducer().

177  {
178  // initialize lut array
179  pt_lut_.reserve(kPtLutSize); // generate lut
180 
181  // iterate through all values in the lut
182  for (unsigned int i = 0; i < kPtLutSize; i++) {
183  unsigned int index = (i + 0.5) * pow(2, (int)(kPTInputSize - 1 - kPTOutputSize));
184  double newValue = inverseRT2InversePT(index); //map out the index to the represented 1/pT
185  out_pt_t out_pt = 1.0 / newValue; // take the reciprocal and cast as an AP fixed-point (1/pt ==> pt)
186  pt_lut_[i] = out_pt; // setting the i-th value for the lut
187  }
188 
189  if (debug_ >= 3) {
190  edm::LogInfo log("L1GTTInputProducer");
191  log << "generate_pt_lut::The pt_lut_[" << kPtLutSize << "] values are ... \n";
192  for (unsigned int i = 0; i < kPtLutSize; i++) {
193  log << "\t" << i << "\t" << pt_lut_[i] << "\n";
194  }
195  }
196 }
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 248 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_2024v14_cff::track, and relativeConstraints::value.

Referenced by produce().

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

Referenced by produce().

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

References debug_, PVValHelper::eta, kEtaInputSize, CrabHelper::log, M_PI, TTTrack_TrackWord::stepTanL, funct::tan(), tauSpinnerTable_cfi::theta, and unpackSignedValue().

Referenced by generate_eta_lut(), and getEtaBits().

222  {
223  double tanl = unpackSignedValue(indexTanLambda, kEtaInputSize, TTTrack_TrackWord::stepTanL);
224  double theta = (M_PI / 2.0) - atan(tanl);
225  double eta = -1.0 * log(tan(theta / 2.0));
226  if (debug_ >= 3) {
227  edm::LogInfo("L1GTTInputProducer") << "indexTanLambda2Eta::tanl index = " << indexTanLambda << "\n"
228  << "indexTanLambda2Eta::tanl value = " << tanl << "\n"
229  << "indexTanLambda2Eta::theta = " << theta << "\n"
230  << "indexTanLambda2Eta::eta = " << eta;
231  }
232  return eta;
233 }
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

◆ 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 243 of file L1GTTInputProducer.cc.

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

Referenced by generate_pt_lut(), and getPtBits().

243  {
244  double inverseRT = unpackSignedValue(indexRT, kPTInputSize, TTTrack_TrackWord::stepRinv);
245  return 100.0 * kSynchrotron * inverseRT; // multiply by 100 to convert from cm to m
246 }
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 405 of file L1GTTInputProducer.cc.

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

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

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

Referenced by indexTanLambda2Eta(), and inverseRT2InversePT().

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

Referenced by generate_pt_lut(), and getPtBits().

◆ setTrackWordBits_

bool L1GTTInputProducer::setTrackWordBits_
private

Definition at line 115 of file L1GTTInputProducer.cc.

Referenced by produce().