CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalVFELinearizationImpl.cc
Go to the documentation of this file.
2 
3 #include <cmath>
4 
6  : linLSB_(conf.getParameter<double>("linLSB")),
7  adcsaturation_(conf.getParameter<double>("adcsaturation")),
8  tdcnBits_(conf.getParameter<uint32_t>("tdcnBits")),
9  tdcOnset_(conf.getParameter<double>("tdcOnset")),
10  adcnBits_(conf.getParameter<uint32_t>("adcnBits")),
11  tdcsaturation_(conf.getParameter<double>("tdcsaturation")),
12  linnBits_(conf.getParameter<uint32_t>("linnBits")),
13  oot_coefficients_(conf.getParameter<std::vector<double>>("oot_coefficients")) {
14  constexpr int kOot_order = 2;
15  if (oot_coefficients_.size() != kOot_order) {
16  throw cms::Exception("BadConfiguration") << "OOT subtraction needs " << kOot_order << " coefficients";
17  }
18  adcLSB_ = std::ldexp(adcsaturation_, -adcnBits_);
19  tdcLSB_ = std::ldexp(tdcsaturation_, -tdcnBits_);
20  linMax_ = (0x1 << linnBits_) - 1;
21 }
22 
23 void HGCalVFELinearizationImpl::linearize(const std::vector<HGCalDataFrame>& dataframes,
24  std::vector<std::pair<DetId, uint32_t>>& linearized_dataframes) {
25  constexpr int kIntimeSample = 2;
26  constexpr int kOuttime1Sample = 1; // in time - 1;
27  constexpr int kOuttime2Sample = 0; // in time - 2;
28 
29  for (const auto& frame : dataframes) { //loop on DIGI
30  double amplitude = 0.;
31  if (frame[kIntimeSample].mode()) { //TOT mode
32  amplitude = (std::floor(tdcOnset_ / adcLSB_) + 1.0) * adcLSB_ + double(frame[kIntimeSample].data()) * tdcLSB_;
33  } else { //ADC mode
34  double data = frame[kIntimeSample].data();
35  // applies OOT PU subtraction only in the ADC mode
36  if (!frame[kOuttime1Sample].mode()) {
37  data += oot_coefficients_[kOuttime1Sample] * frame[kOuttime1Sample].data();
38  if (!frame[kOuttime2Sample].mode()) {
39  data += oot_coefficients_[kOuttime2Sample] * frame[kOuttime2Sample].data();
40  }
41  }
42  amplitude = std::max(0., data) * adcLSB_;
43  }
44  uint32_t amplitude_int = uint32_t(std::floor(amplitude / linLSB_ + 0.5));
45  if (amplitude_int == 0)
46  continue;
47  if (amplitude_int > linMax_)
48  amplitude_int = linMax_;
49 
50  linearized_dataframes.emplace_back(frame.id(), amplitude_int);
51  }
52 }
HGCalVFELinearizationImpl(const edm::ParameterSet &conf)
std::vector< double > oot_coefficients_
void linearize(const std::vector< HGCalDataFrame > &, std::vector< std::pair< DetId, uint32_t >> &)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79