Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:04

0001 #include "L1Trigger/L1THGCal/interface/veryfrontend/HGCalVFELinearizationImpl.h"
0002 
0003 #include <cmath>
0004 
0005 HGCalVFELinearizationImpl::HGCalVFELinearizationImpl(const edm::ParameterSet& conf)
0006     : linLSB_(conf.getParameter<double>("linLSB")),
0007       adcsaturation_(conf.getParameter<double>("adcsaturation")),
0008       tdcnBits_(conf.getParameter<uint32_t>("tdcnBits")),
0009       tdcOnset_(conf.getParameter<double>("tdcOnset")),
0010       adcnBits_(conf.getParameter<uint32_t>("adcnBits")),
0011       tdcsaturation_(conf.getParameter<double>("tdcsaturation")),
0012       linnBits_(conf.getParameter<uint32_t>("linnBits")),
0013       oot_coefficients_(conf.getParameter<std::vector<double>>("oot_coefficients")) {
0014   constexpr int kOot_order = 2;
0015   if (oot_coefficients_.size() != kOot_order) {
0016     throw cms::Exception("BadConfiguration") << "OOT subtraction needs " << kOot_order << " coefficients";
0017   }
0018   adcLSB_ = std::ldexp(adcsaturation_, -adcnBits_);
0019   tdcLSB_ = std::ldexp(tdcsaturation_, -tdcnBits_);
0020   linMax_ = (0x1 << linnBits_) - 1;
0021 }
0022 
0023 void HGCalVFELinearizationImpl::linearize(const std::vector<HGCalDataFrame>& dataframes,
0024                                           std::vector<std::pair<DetId, uint32_t>>& linearized_dataframes) {
0025   constexpr int kIntimeSample = 2;
0026   constexpr int kOuttime1Sample = 1;  // in time - 1;
0027   constexpr int kOuttime2Sample = 0;  // in time - 2;
0028 
0029   for (const auto& frame : dataframes) {  //loop on DIGI
0030     double amplitude = 0.;
0031     if (frame[kIntimeSample].mode()) {  //TOT mode
0032       amplitude = (std::floor(tdcOnset_ / adcLSB_) + 1.0) * adcLSB_ + double(frame[kIntimeSample].data()) * tdcLSB_;
0033     } else {  //ADC mode
0034       double data = frame[kIntimeSample].data();
0035       // applies OOT PU subtraction only in the ADC mode
0036       if (!frame[kOuttime1Sample].mode()) {
0037         data += oot_coefficients_[kOuttime1Sample] * frame[kOuttime1Sample].data();
0038         if (!frame[kOuttime2Sample].mode()) {
0039           data += oot_coefficients_[kOuttime2Sample] * frame[kOuttime2Sample].data();
0040         }
0041       }
0042       amplitude = std::max(0., data) * adcLSB_;
0043     }
0044     uint32_t amplitude_int = uint32_t(std::floor(amplitude / linLSB_ + 0.5));
0045     if (amplitude_int == 0)
0046       continue;
0047     if (amplitude_int > linMax_)
0048       amplitude_int = linMax_;
0049 
0050     linearized_dataframes.emplace_back(frame.id(), amplitude_int);
0051   }
0052 }