CMS 3D CMS Logo

HGCalTriggerCellThresholdCodecImpl.cc
Go to the documentation of this file.
1 
3 
4 
7  dataLength_(conf.getParameter<uint32_t>("DataLength")),
8  nCellsInModule_(conf.getParameter<uint32_t>("MaxCellsInModule")),
9  linLSB_(conf.getParameter<double>("linLSB")),
10  linnBits_(conf.getParameter<uint32_t>("linnBits")),
11  adcsaturation_(conf.getParameter<double>("adcsaturation")),
12  adcnBits_(conf.getParameter<uint32_t>("adcnBits")),
13  tdcsaturation_(conf.getParameter<double>("tdcsaturation")),
14  tdcnBits_(conf.getParameter<uint32_t>("tdcnBits")),
15  tdcOnsetfC_(conf.getParameter<double>("tdcOnsetfC")),
16  adcsaturationBH_(conf.getParameter<double>("adcsaturationBH")),
17  adcnBitsBH_(conf.getParameter<uint32_t>("adcnBitsBH")),
18  triggerCellTruncationBits_(conf.getParameter<uint32_t>("triggerCellTruncationBits")),
19  TCThreshold_fC_(conf.getParameter<double>("TCThreshold_fC")),
20  TCThresholdBH_MIP_(conf.getParameter<double>("TCThresholdBH_MIP")),
21  thickness_corrections_(conf.getParameter<std::vector<double>>("ThicknessCorrections"))
22 {
26  linMax_ = (0x1<<linnBits_)-1;
30 }
31 
32 
33 
34 std::vector<bool>
37 {
38  // First nCellsInModule_ bits are encoding the map of selected trigger cells
39  // Followed by size words of dataLength_ bits, corresponding to energy/transverse energy of
40  // the selected trigger cells
41 
42  // Convert payload into a map for later search
43  std::unordered_map<uint32_t, uint32_t> data_map; // (detid,energy)
44  size_t size=0;
45  for(const auto& triggercell : data.payload)
46  {
47  data_map.emplace(triggercell.detId(), triggercell.hwPt());
48  if (triggercell.hwPt()>0) size++;
49  }
50  std::vector<bool> result(nCellsInModule_ + dataLength_*size, 0);
51  // No data: return vector of 0
52  if(data.payload.size()==0) return result;
53  // All trigger cells are in the same module
54  // Loop on trigger cell ids in module and check if energy in the cell
55  size_t index = 0; // index in module
56  size_t idata = 0; // counter for the number of non-zero energy values
57  // Retrieve once the ordered list of trigger cells in this module
58  uint32_t module = geometry.getModuleFromTriggerCell(data.payload.begin()->detId());
59  HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
60  for(const auto& triggercell_id : trigger_cells_in_module)
61  {
62  // Find if this trigger cell has data
63  const auto& data_itr = data_map.find(triggercell_id);
64  // if not data, increase index and skip
65  if(data_itr==data_map.end())
66  {
67  index++;
68  continue;
69  }
70  // else fill result vector with data
71  // (set the corresponding adress bit and fill energy if >0)
72  if(index>=nCellsInModule_)
73  {
74  throw cms::Exception("BadGeometry")
75  << "Number of trigger cells in module too large for available data payload\n";
76  }
77  uint32_t value = data_itr->second;
78  if(value>0)
79  {
80  // Set map bit to 1
81  result[index] = 1;
82  // Saturate and truncate energy values
83  if(value+1>(0x1u<<triggerCellSaturationBits_)) value = (0x1<<triggerCellSaturationBits_)-1;
84  for(size_t i=0; i<dataLength_; i++)
85  {
86  // remove the lowest bits (=triggerCellTruncationBits_)
87  result[nCellsInModule_ + idata*dataLength_ + i] = static_cast<bool>(value & (0x1<<(i+triggerCellTruncationBits_)));
88  }
89  idata++;
90  }
91  index++;
92  }
93  return result;
94 }
95 
98 decode(const std::vector<bool>& data, const uint32_t module, const HGCalTriggerGeometryBase& geometry) const
99 {
101  result.reset();
102  // TODO: could eventually reserve result memory to the max size of trigger cells
103 
104  HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
105  size_t iselected = 0;
106  size_t index = 0;
107  for(const auto& triggercell : trigger_cells_in_module)
108  {
109  if(index>=nCellsInModule_)
110  {
111  throw cms::Exception("BadGeometry")
112  << "Number of trigger cells in module too large for available data payload\n";
113  }
114  if(data[index])
115  {
116  uint32_t value = 0;
117  for(size_t i=0;i<dataLength_;i++)
118  {
119  size_t ibit = nCellsInModule_+iselected*dataLength_+i;
120  if(data[ibit]) value |= (0x1<<i);
121  }
122  iselected++;
123  // Build trigger cell
124  if(value>0)
125  {
126  // Currently no hardware eta, phi and quality values
127  result.payload.emplace_back(reco::LeafCandidate::LorentzVector(),
128  value, 0, 0, 0, triggercell);
129  GlobalPoint point = geometry.getTriggerCellPosition(triggercell);
130  // 'value' is hardware, so p4 is meaningless, except for eta and phi
131  math::PtEtaPhiMLorentzVector p4((double)value/cosh(point.eta()), point.eta(), point.phi(), 0.);
132  result.payload.back().setP4(p4);
133  result.payload.back().setPosition(point);
134  }
135  }
136  index++;
137  }
138  return result;
139 }
140 
141 
142 void
144 linearize(const std::vector<HGCDataFrame<DetId,HGCSample>>& dataframes,
145  std::vector<std::pair<DetId, uint32_t > >& linearized_dataframes)
146 {
147  double amplitude = 0.;
148  uint32_t amplitude_int = 0;
149  const int kIntimeSample = 2;
150 
151  for(const auto& frame : dataframes) {//loop on DIGI
152  if(frame.id().det()==DetId::Forward) {
153  if (frame[kIntimeSample].mode()) {//TOT mode
154  amplitude =( floor(tdcOnsetfC_/adcLSB_) + 1.0 )* adcLSB_ + double(frame[kIntimeSample].data()) * tdcLSB_;
155  }
156  else {//ADC mode
157  amplitude = double(frame[kIntimeSample].data()) * adcLSB_;
158  }
159 
160  amplitude_int = uint32_t (floor(amplitude/linLSB_+0.5));
161  }
162  else if(frame.id().det()==DetId::Hcal) {
163  // no linearization here. Take the raw ADC data
164  amplitude_int = frame[kIntimeSample].data();
165  }
166  if (amplitude_int>linMax_) amplitude_int = linMax_;
167 
168  linearized_dataframes.push_back(std::make_pair (frame.id(), amplitude_int));
169  }
170 }
171 
172 
173 void
175 triggerCellSums(const HGCalTriggerGeometryBase& geometry, const std::vector<std::pair<DetId, uint32_t > >& linearized_dataframes, data_type& data)
176 {
177  if(linearized_dataframes.size()==0) return;
178  std::map<HGCalDetId, uint32_t> payload;
179  // sum energies in trigger cells
180  for(const auto& frame : linearized_dataframes)
181  {
182  DetId cellid(frame.first);
183  // find trigger cell associated to cell
184  uint32_t tcid = geometry.getTriggerCellFromCell(cellid);
185  HGCalDetId triggercellid( tcid );
186  payload.insert( std::make_pair(triggercellid, 0) ); // do nothing if key exists already
187  uint32_t value = frame.second;
188  // equalize value among cell thicknesses
189  if(cellid.det()==DetId::Forward)
190  {
191  int thickness = 0;
192  switch(cellid.subdetId())
193  {
195  thickness = geometry.eeTopology().dddConstants().waferTypeL(HGCalDetId(cellid).wafer())-1;
196  break;
198  thickness = geometry.fhTopology().dddConstants().waferTypeL(HGCalDetId(cellid).wafer())-1;
199  break;
200  default:
201  break;
202  };
203  double thickness_correction = thickness_corrections_.at(thickness);
204  value = (double)value*thickness_correction;
205  }
206  payload[triggercellid] += value; // 32 bits integer should be largely enough
207 
208  }
209  uint32_t module = geometry.getModuleFromTriggerCell(payload.begin()->first);
210  HGCalTriggerGeometryBase::geom_ordered_set trigger_cells_in_module = geometry.getOrderedTriggerCellsFromModule(module);
211  // fill data payload
212  for(const auto& id_value : payload)
213  {
214  // Store only energy value and detid
215  // No need position here
216  data.payload.emplace_back(reco::LeafCandidate::LorentzVector(),
217  id_value.second, 0, 0, 0, id_value.first.rawId());
218  }
219 }
220 
221 void
224 {
225  for (size_t i = 0; i<data.payload.size();i++){
227  if (data.payload[i].hwPt() < threshold) data.payload[i].setHwPt(0);
228  }
229 
230 }
231 
232 
size
Write out results.
void linearize(const std::vector< HGCDataFrame< DetId, HGCSample >> &, std::vector< std::pair< DetId, uint32_t > > &)
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned trigger_cell_det_id) const =0
const HGCalTopology & eeTopology() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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
void triggerCellSums(const HGCalTriggerGeometryBase &, const std::vector< std::pair< DetId, uint32_t > > &, data_type &)
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:37
std::vector< bool > encode(const data_type &, const HGCalTriggerGeometryBase &) const
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
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
HGCalTriggerCellThresholdCodecImpl(const edm::ParameterSet &conf)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
Definition: vlib.h:208
virtual unsigned getTriggerCellFromCell(const unsigned cell_det_id) const =0
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: LeafCandidate.h:23
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