CMS 3D CMS Logo

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

#include <HGCalTriggerCellBestChoiceCodecImpl.h>

Public Types

typedef HGCalTriggerCellBestChoiceDataPayload data_type
 

Public Member Functions

uint32_t adcnBits () const
 
double adcsaturation () const
 
void bestChoiceSelect (data_type &)
 
size_t dataLength () const
 
data_type decode (const std::vector< bool > &, const uint32_t, const HGCalTriggerGeometryBase &) const
 
std::vector< bool > encode (const data_type &, const HGCalTriggerGeometryBase &) const
 
 HGCalTriggerCellBestChoiceCodecImpl (const edm::ParameterSet &conf)
 
void linearize (const std::vector< HGCalDataFrame > &, std::vector< std::pair< DetId, uint32_t > > &)
 
double linLSB () const
 
uint32_t linnBits () const
 
size_t nCellsInModule () const
 
size_t nData () const
 
uint32_t tdcnBits () const
 
double tdcOnsetfC () const
 
double tdcsaturation () const
 
std::vector< double > ThicknessCorrections () const
 
uint32_t triggerCellSaturationBits () const
 
void triggerCellSums (const HGCalTriggerGeometryBase &, const std::vector< std::pair< DetId, uint32_t > > &, data_type &)
 
uint32_t triggerCellTruncationBits () const
 

Private Attributes

double adcLSB_
 
uint32_t adcnBits_
 
double adcsaturation_
 
size_t dataLength_
 
double linLSB_
 
uint32_t linMax_
 
uint32_t linnBits_
 
size_t nCellsInModule_
 
size_t nData_
 
double tdcLSB_
 
uint32_t tdcnBits_
 
double tdcOnsetfC_
 
double tdcsaturation_
 
std::vector< double > thickness_corrections_
 
uint32_t triggerCellSaturationBits_
 
uint32_t triggerCellTruncationBits_
 

Detailed Description

Definition at line 27 of file HGCalTriggerCellBestChoiceCodecImpl.h.

Member Typedef Documentation

Definition at line 30 of file HGCalTriggerCellBestChoiceCodecImpl.h.

Constructor & Destructor Documentation

HGCalTriggerCellBestChoiceCodecImpl::HGCalTriggerCellBestChoiceCodecImpl ( const edm::ParameterSet conf)

Definition at line 6 of file HGCalTriggerCellBestChoiceCodecImpl.cc.

References adcLSB_, adcnBits_, adcsaturation_, dataLength_, encode(), linMax_, linnBits_, nCellsInModule_, nData_, funct::pow(), tdcLSB_, tdcnBits_, tdcsaturation_, triggerCellSaturationBits_, and triggerCellTruncationBits_.

6  :
7  nData_(conf.getParameter<uint32_t>("NData")),
8  dataLength_(conf.getParameter<uint32_t>("DataLength")),
9  nCellsInModule_(conf.getParameter<uint32_t>("MaxCellsInModule")),
10  linLSB_(conf.getParameter<double>("linLSB")),
11  linnBits_(conf.getParameter<uint32_t>("linnBits")),
12  adcsaturation_(conf.getParameter<double>("adcsaturation")),
13  adcnBits_(conf.getParameter<uint32_t>("adcnBits")),
14  tdcsaturation_(conf.getParameter<double>("tdcsaturation")),
15  tdcnBits_(conf.getParameter<uint32_t>("tdcnBits")),
16  tdcOnsetfC_(conf.getParameter<double>("tdcOnsetfC")),
17  triggerCellTruncationBits_(conf.getParameter<uint32_t>("triggerCellTruncationBits")),
18  thickness_corrections_(conf.getParameter<std::vector<double>>("ThicknessCorrections"))
19 {
20  // Cannot have more selected cells than the max number of cells
24  linMax_ = (0x1<<linnBits_)-1;
26 }
T getParameter(std::string const &) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40

Member Function Documentation

uint32_t HGCalTriggerCellBestChoiceCodecImpl::adcnBits ( ) const
inline
double HGCalTriggerCellBestChoiceCodecImpl::adcsaturation ( ) const
inline
void HGCalTriggerCellBestChoiceCodecImpl::bestChoiceSelect ( data_type data)

Definition at line 229 of file HGCalTriggerCellBestChoiceCodecImpl.cc.

References a, b, l1t::L1Candidate::hwPt(), nData_, and HGCalTriggerCellBestChoiceDataPayload::payload.

Referenced by HGCalTriggerCellBestChoiceCodec::setDataPayloadImpl(), and triggerCellSums().

230 {
231  // sort, reverse order
232  sort(data.payload.begin(), data.payload.end(),
233  [](const l1t::HGCalTriggerCell& a,
234  const l1t::HGCalTriggerCell& b) -> bool
235  {
236  return a.hwPt() > b.hwPt();
237  }
238  );
239  // keep only the first trigger cells
240  if(data.payload.size()>nData_) data.payload.resize(nData_);
241 }
int hwPt() const
Definition: L1Candidate.h:48
double b
Definition: hdecay.h:120
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
size_t HGCalTriggerCellBestChoiceCodecImpl::dataLength ( ) const
inline
HGCalTriggerCellBestChoiceCodecImpl::data_type HGCalTriggerCellBestChoiceCodecImpl::decode ( const std::vector< bool > &  data,
const uint32_t  module,
const HGCalTriggerGeometryBase geometry 
) const

Definition at line 97 of file HGCalTriggerCellBestChoiceCodecImpl.cc.

References dataLength_, PV3DBase< T, PVType, FrameType >::eta(), Exception, HGCalTriggerGeometryBase::getOrderedTriggerCellsFromModule(), HGCalTriggerGeometryBase::getTriggerCellPosition(), mps_fire::i, linearize(), nCellsInModule_, nData_, p4, HGCalTriggerCellBestChoiceDataPayload::payload, PV3DBase< T, PVType, FrameType >::phi(), point, HGCalTriggerCellBestChoiceDataPayload::reset(), and mps_fire::result.

Referenced by HGCalTriggerCellBestChoiceCodec::decodeImpl(), and encode().

98 {
100  result.reset();
101  // TODO: could eventually reserve result memory to the max size of trigger cells
103  {
104  throw cms::Exception("BadData")
105  << "decode: data length ("<<data.size()<<") inconsistent with codec parameters:\n"\
106  << " : Map size = "<<nCellsInModule_<<"\n"\
107  << " : Number of energy values = "<<nData_<<"\n"\
108  << " : Energy value length = "<<dataLength_<<"\n";
109  }
111  size_t iselected = 0;
112  size_t index = 0;
113  for(const auto& triggercell : trigger_cells_in_module)
114  {
115  if(index>=nCellsInModule_)
116  {
117  throw cms::Exception("BadGeometry")
118  << "Number of trigger cells in module too large for available data payload\n";
119  }
120  if(data[index])
121  {
122  uint32_t value = 0;
123  for(size_t i=0;i<dataLength_;i++)
124  {
125  size_t ibit = nCellsInModule_+iselected*dataLength_+i;
126  if(data[ibit]) value |= (0x1<<i);
127  }
128  iselected++;
129  // Build trigger cell
130  if(value>0)
131  {
132  // Currently no hardware eta, phi and quality values
133  result.payload.emplace_back(reco::LeafCandidate::LorentzVector(),
134  value, 0, 0, 0, triggercell);
135  GlobalPoint point = geometry.getTriggerCellPosition(triggercell);
136  // 'value' is hardware, so p4 is meaningless, except for eta and phi
137  math::PtEtaPhiMLorentzVector p4((double)value/cosh(point.eta()), point.eta(), point.phi(), 0.);
138  result.payload.back().setP4(p4);
139  result.payload.back().setPosition(point);
140  }
141  }
142  index++;
143  }
144  return result;
145 }
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned trigger_cell_det_id) const =0
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
double p4[4]
Definition: TauolaWrapper.h:92
Definition: value.py:1
std::set< unsigned > geom_ordered_set
T eta() const
Definition: PV3DBase.h:76
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
HGCalTriggerCellBestChoiceDataPayload data_type
Definition: vlib.h:208
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
virtual GlobalPoint getTriggerCellPosition(const unsigned trigger_cell_det_id) const =0
std::vector< bool > HGCalTriggerCellBestChoiceCodecImpl::encode ( const data_type data,
const HGCalTriggerGeometryBase geometry 
) const

Definition at line 32 of file HGCalTriggerCellBestChoiceCodecImpl.cc.

References dataLength_, decode(), Exception, HGCalTriggerGeometryBase::getModuleFromTriggerCell(), HGCalTriggerGeometryBase::getOrderedTriggerCellsFromModule(), mps_fire::i, nCellsInModule_, nData_, HGCalTriggerCellBestChoiceDataPayload::payload, mps_fire::result, triggerCellSaturationBits_, and triggerCellTruncationBits_.

Referenced by HGCalTriggerCellBestChoiceCodec::encodeImpl(), and HGCalTriggerCellBestChoiceCodecImpl().

33 {
34  // First nCellsInModule_ bits are encoding the map of selected trigger cells
35  // Followed by nData_ words of dataLength_ bits, corresponding to energy/transverse energy of
36  // the selected trigger cells
37  std::vector<bool> result(nCellsInModule_ + dataLength_*nData_, false);
38  // No data: return vector of 0
39  if(data.payload.empty()) return result;
40  // All trigger cells are in the same module
41  // Retrieve once the ordered list of trigger cells in this module
42  uint32_t module = geometry.getModuleFromTriggerCell(data.payload.begin()->detId());
43  HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
44  // Convert payload into a map for later search
45  std::unordered_map<uint32_t, uint32_t> data_map; // (detid,energy)
46  for(const auto& triggercell : data.payload)
47  {
48  data_map.emplace(triggercell.detId(), triggercell.hwPt());
49  }
50  // Loop on trigger cell ids in module and check if energy in the cell
51  size_t index = 0; // index in module
52  size_t idata = 0; // counter for the number of non-zero energy values
53  for(const auto& triggercell_id : trigger_cells_in_module)
54  {
55  // Find if this trigger cell has data
56  const auto& data_itr = data_map.find(triggercell_id);
57  // if not data, increase index and skip
58  if(data_itr==data_map.end())
59  {
60  index++;
61  continue;
62  }
63  // else fill result vector with data
64  // (set the corresponding adress bit and fill energy if >0)
65  if(index>=nCellsInModule_)
66  {
67  throw cms::Exception("BadGeometry")
68  << "Number of trigger cells in module too large for available data payload\n";
69  }
70  uint32_t value = data_itr->second;
71  if(value>0)
72  {
73  if(idata>=nData_)
74  {
75  throw cms::Exception("BadData")
76  << "encode: Number of non-zero trigger cells larger than codec parameter\n"\
77  << " : Number of energy values = "<<nData_<<"\n";
78  }
79  // Set map bit to 1
80  result[index] = true;
81  // Saturate and truncate energy values
82  if(value+1>(0x1u<<triggerCellSaturationBits_)) value = (0x1<<triggerCellSaturationBits_)-1;
83  for(size_t i=0; i<dataLength_; i++)
84  {
85  // remove the lowest bits (=triggerCellTruncationBits_)
86  result[nCellsInModule_ + idata*dataLength_ + i] = static_cast<bool>(value & (0x1<<(i+triggerCellTruncationBits_)));
87  }
88  idata++;
89  }
90  index++;
91  }
92  return result;
93 }
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned trigger_cell_det_id) const =0
Definition: value.py:1
virtual unsigned getModuleFromTriggerCell(const unsigned trigger_cell_det_id) const =0
std::set< unsigned > geom_ordered_set
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Definition: vlib.h:208
void HGCalTriggerCellBestChoiceCodecImpl::linearize ( const std::vector< HGCalDataFrame > &  dataframes,
std::vector< std::pair< DetId, uint32_t > > &  linearized_dataframes 
)

Definition at line 150 of file HGCalTriggerCellBestChoiceCodecImpl.cc.

References adcLSB_, CustomPhysics_cfi::amplitude, data, DetId::Forward, DetId::Hcal, linLSB_, linMax_, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, tdcLSB_, tdcOnsetfC_, and triggerCellSums().

Referenced by decode(), and HGCalTriggerCellBestChoiceCodec::setDataPayloadImpl().

152 {
153  double amplitude = 0.;
154  uint32_t amplitude_int = 0;
155  const int kIntimeSample = 2;
156 
157  for(const auto& frame : dataframes) {//loop on DIGI
158  if(frame.id().det()==DetId::Forward) {
159  if (frame[kIntimeSample].mode()) {//TOT mode
160  amplitude =( floor(tdcOnsetfC_/adcLSB_) + 1.0 )* adcLSB_ + double(frame[kIntimeSample].data()) * tdcLSB_;
161  }
162  else {//ADC mode
163  amplitude = double(frame[kIntimeSample].data()) * adcLSB_;
164  }
165 
166  amplitude_int = uint32_t (floor(amplitude/linLSB_+0.5));
167  }
168  else if(frame.id().det()==DetId::Hcal) {
169  // no linearization here. Take the raw ADC data
170  amplitude_int = frame[kIntimeSample].data();
171  }
172  if (amplitude_int>linMax_) amplitude_int = linMax_;
173 
174  linearized_dataframes.push_back(std::make_pair (frame.id(), amplitude_int));
175  }
176 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double HGCalTriggerCellBestChoiceCodecImpl::linLSB ( ) const
inline
uint32_t HGCalTriggerCellBestChoiceCodecImpl::linnBits ( ) const
inline
size_t HGCalTriggerCellBestChoiceCodecImpl::nCellsInModule ( ) const
inline
size_t HGCalTriggerCellBestChoiceCodecImpl::nData ( ) const
inline
uint32_t HGCalTriggerCellBestChoiceCodecImpl::tdcnBits ( ) const
inline
double HGCalTriggerCellBestChoiceCodecImpl::tdcOnsetfC ( ) const
inline
double HGCalTriggerCellBestChoiceCodecImpl::tdcsaturation ( ) const
inline
std::vector<double> HGCalTriggerCellBestChoiceCodecImpl::ThicknessCorrections ( ) const
inline
uint32_t HGCalTriggerCellBestChoiceCodecImpl::triggerCellSaturationBits ( ) const
inline
void HGCalTriggerCellBestChoiceCodecImpl::triggerCellSums ( const HGCalTriggerGeometryBase geometry,
const std::vector< std::pair< DetId, uint32_t > > &  linearized_dataframes,
data_type data 
)

Definition at line 181 of file HGCalTriggerCellBestChoiceCodecImpl.cc.

References bestChoiceSelect(), HGCalTopology::dddConstants(), DetId::det(), HGCalTriggerGeometryBase::eeTopology(), HGCalTriggerGeometryBase::fhTopology(), DetId::Forward, HGCalTriggerGeometryBase::getModuleFromTriggerCell(), HGCalTriggerGeometryBase::getOrderedTriggerCellsFromModule(), HGCalTriggerGeometryBase::getTriggerCellFromCell(), HGCEE, HGCHEF, HGCalTriggerCellBestChoiceDataPayload::payload, jets_cff::payload, DetId::subdetId(), thickness_corrections_, relativeConstraints::value, and HGCalDDDConstants::waferTypeL().

Referenced by linearize(), and HGCalTriggerCellBestChoiceCodec::setDataPayloadImpl().

182 {
183  if(linearized_dataframes.empty()) return;
184  std::map<HGCalDetId, uint32_t> payload;
185  // sum energies in trigger cells
186  for(const auto& frame : linearized_dataframes)
187  {
188  DetId cellid(frame.first);
189  // find trigger cell associated to cell
190  uint32_t tcid = geometry.getTriggerCellFromCell(cellid);
191  HGCalDetId triggercellid( tcid );
192  payload.insert( std::make_pair(triggercellid, 0) ); // do nothing if key exists already
193  uint32_t value = frame.second;
194  // equalize value among cell thicknesses
195  if(cellid.det()==DetId::Forward)
196  {
197  int thickness = 0;
198  switch(cellid.subdetId())
199  {
201  thickness = geometry.eeTopology().dddConstants().waferTypeL(HGCalDetId(cellid).wafer())-1;
202  break;
204  thickness = geometry.fhTopology().dddConstants().waferTypeL(HGCalDetId(cellid).wafer())-1;
205  break;
206  default:
207  break;
208  };
209  double thickness_correction = thickness_corrections_.at(thickness);
210  value = (double)value*thickness_correction;
211  }
212  payload[triggercellid] += value; // 32 bits integer should be largely enough
213 
214  }
215  uint32_t module = geometry.getModuleFromTriggerCell(payload.begin()->first);
216  HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
217  // fill data payload
218  for(const auto& id_value : payload)
219  {
220  // Store only energy value and detid
221  // No need position here
222  data.payload.emplace_back(reco::LeafCandidate::LorentzVector(),
223  id_value.second, 0, 0, 0, id_value.first.rawId());
224  }
225 }
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned trigger_cell_det_id) const =0
const HGCalTopology & eeTopology() const
int waferTypeL(int wafer) const
Definition: value.py:1
Definition: DetId.h:18
virtual unsigned getModuleFromTriggerCell(const unsigned trigger_cell_det_id) const =0
const HGCalDDDConstants & dddConstants() const
std::set< unsigned > geom_ordered_set
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Definition: vlib.h:208
virtual unsigned getTriggerCellFromCell(const unsigned cell_det_id) const =0
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
const HGCalTopology & fhTopology() const
uint32_t HGCalTriggerCellBestChoiceCodecImpl::triggerCellTruncationBits ( ) const
inline

Member Data Documentation

double HGCalTriggerCellBestChoiceCodecImpl::adcLSB_
private
uint32_t HGCalTriggerCellBestChoiceCodecImpl::adcnBits_
private
double HGCalTriggerCellBestChoiceCodecImpl::adcsaturation_
private
size_t HGCalTriggerCellBestChoiceCodecImpl::dataLength_
private
double HGCalTriggerCellBestChoiceCodecImpl::linLSB_
private

Definition at line 65 of file HGCalTriggerCellBestChoiceCodecImpl.h.

Referenced by linearize().

uint32_t HGCalTriggerCellBestChoiceCodecImpl::linMax_
private
uint32_t HGCalTriggerCellBestChoiceCodecImpl::linnBits_
private
size_t HGCalTriggerCellBestChoiceCodecImpl::nCellsInModule_
private
size_t HGCalTriggerCellBestChoiceCodecImpl::nData_
private
double HGCalTriggerCellBestChoiceCodecImpl::tdcLSB_
private
uint32_t HGCalTriggerCellBestChoiceCodecImpl::tdcnBits_
private
double HGCalTriggerCellBestChoiceCodecImpl::tdcOnsetfC_
private

Definition at line 72 of file HGCalTriggerCellBestChoiceCodecImpl.h.

Referenced by linearize().

double HGCalTriggerCellBestChoiceCodecImpl::tdcsaturation_
private
std::vector<double> HGCalTriggerCellBestChoiceCodecImpl::thickness_corrections_
private

Definition at line 77 of file HGCalTriggerCellBestChoiceCodecImpl.h.

Referenced by triggerCellSums().

uint32_t HGCalTriggerCellBestChoiceCodecImpl::triggerCellSaturationBits_
private
uint32_t HGCalTriggerCellBestChoiceCodecImpl::triggerCellTruncationBits_
private