CMS 3D CMS Logo

HGCalTriggerCellBestChoiceCodecImpl.cc
Go to the documentation of this file.
1 
3 
4 
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 }
27 
28 
29 
30 std::vector<bool>
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 }
94 
97 decode(const std::vector<bool>& data, const uint32_t module, const HGCalTriggerGeometryBase& geometry) const
98 {
100  result.reset();
101  // TODO: could eventually reserve result memory to the max size of trigger cells
102  if(data.size()!=nCellsInModule_+dataLength_*nData_)
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  }
110  HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
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 }
146 
147 
148 void
150 linearize(const std::vector<HGCDataFrame<DetId,HGCSample>>& dataframes,
151  std::vector<std::pair<DetId, uint32_t > >& linearized_dataframes)
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 }
177 
178 
179 void
181 triggerCellSums(const HGCalTriggerGeometryBase& geometry, const std::vector<std::pair<DetId, uint32_t > >& linearized_dataframes, data_type& data)
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 }
226 
227 void
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 }
242 
243 
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned trigger_cell_det_id) const =0
void linearize(const std::vector< HGCDataFrame< DetId, HGCSample >> &, std::vector< std::pair< DetId, uint32_t > > &)
const HGCalTopology & eeTopology() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
void triggerCellSums(const HGCalTriggerGeometryBase &, const std::vector< std::pair< DetId, uint32_t > > &, data_type &)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
data_type decode(const std::vector< bool > &, const uint32_t, const HGCalTriggerGeometryBase &) const
double p4[4]
Definition: TauolaWrapper.h:92
int waferTypeL(int wafer) const
Definition: value.py:1
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
Definition: DetId.h:18
int hwPt() const
Definition: L1Candidate.h:48
virtual unsigned getModuleFromTriggerCell(const unsigned trigger_cell_det_id) const =0
const HGCalDDDConstants & dddConstants() const
HGCalTriggerCellBestChoiceCodecImpl(const edm::ParameterSet &conf)
double b
Definition: hdecay.h:120
std::set< unsigned > geom_ordered_set
Readout digi for HGC.
Definition: HGCDataFrame.h:14
T eta() const
Definition: PV3DBase.h:76
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
Definition: vlib.h:208
virtual unsigned getTriggerCellFromCell(const unsigned cell_det_id) const =0
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
std::vector< bool > encode(const data_type &, const HGCalTriggerGeometryBase &) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
const HGCalTopology & fhTopology() const
*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