Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:24:32

0001 #ifndef RecoLocalCalo_HGCalRecAlgos_HGCalUncalibRecHitRecWeightsAlgo_HH
0002 #define RecoLocalCalo_HGCalRecAlgos_HGCalUncalibRecHitRecWeightsAlgo_HH
0003 
0004 /** \class HGalUncalibRecHitRecWeightsAlgo
0005   *  compute amplitude, pedestal, time jitter, chi2 of a pulse
0006   *  using a weights method, a la Ecal 
0007   *
0008   *  \author Valeri Andreev
0009   *  
0010   *
0011   */
0012 
0013 #include "RecoLocalCalo/HGCalRecAlgos/interface/HGCalUncalibRecHitRecAbsAlgo.h"
0014 #include <vector>
0015 #include <cmath>
0016 
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0019 
0020 template <class C>
0021 class HGCalUncalibRecHitRecWeightsAlgo {
0022 public:
0023   // destructor
0024   virtual ~HGCalUncalibRecHitRecWeightsAlgo<C>(){};
0025 
0026   void set_isSiFESim(const bool isSiFE) { isSiFESim_ = isSiFE; }
0027   bool isSiFESim() const { return isSiFESim_; }
0028 
0029   void set_ADCLSB(const double adclsb) { adcLSB_ = adclsb; }
0030   void set_TDCLSB(const double tdclsb) { tdcLSB_ = tdclsb; }
0031 
0032   void set_toaLSBToNS(const double lsb2ns) { toaLSBToNS_ = lsb2ns; }
0033 
0034   void set_tdcOnsetfC(const double tdcOnset) { tdcOnsetfC_ = tdcOnset; }
0035 
0036   void set_fCPerMIP(const std::vector<double>& fCPerMIP) {
0037     if (std::any_of(fCPerMIP.cbegin(), fCPerMIP.cend(), [](double conv) { return conv <= 0.0; })) {
0038       throw cms::Exception("BadConversionFactor") << "At least one of fCPerMIP is zero!" << std::endl;
0039     }
0040     fCPerMIP_ = fCPerMIP;
0041   }
0042 
0043   void setGeometry(const HGCalGeometry* geom) {
0044     if (geom)
0045       ddd_ = &(geom->topology().dddConstants());
0046     else
0047       ddd_ = nullptr;
0048   }
0049 
0050   /// Compute HGCUncalibratedRecHit from DataFrame
0051   virtual HGCUncalibratedRecHit makeRecHit(const C& dataFrame) {
0052     double amplitude_(-1.), pedestal_(-1.), jitter_(-1.), chi2_(-1.);
0053     uint32_t flag = 0;
0054 
0055     constexpr int iSample = 2;  //only in-time sample
0056     const auto& sample = dataFrame.sample(iSample);
0057 
0058     // Were digis done w/ the complete digitization and using signal shape?
0059     // (originally done only for the silicon, while for scitillator it was trivial. Fomr 11_ also scinti uses shape)
0060     if (isSiFESim_) {
0061       // mode == true: TDC readout was activated and amplitude comes from TimeOverThreshold
0062       if (sample.mode()) {
0063         flag = !sample.threshold();  // raise flag if busy cell
0064         // LG (23/06/2015):
0065         // to get a continuous energy spectrum we must add here the maximum value in fC ever
0066         // reported by the ADC. Namely: floor(tdcOnset/adcLSB_) * adcLSB_
0067         // need to increment by one so TDC doesn't overlap with ADC last bin
0068         // LG (11/04/2016):
0069         // offset the TDC upwards to reflect the bin center
0070         amplitude_ = (std::floor(tdcOnsetfC_ / adcLSB_) + 1.0) * adcLSB_ + (double(sample.data()) + 0.5) * tdcLSB_;
0071 
0072         if (sample.getToAValid()) {
0073           jitter_ = double(sample.toa()) * toaLSBToNS_;
0074         }
0075       } else {
0076         amplitude_ = double(sample.data()) * adcLSB_;  // why do we not have +0.5 here ?
0077         if (sample.getToAValid()) {
0078           jitter_ = double(sample.toa()) * toaLSBToNS_;
0079         }
0080       }  //isSiFESim_
0081     }    //mode()
0082 
0083     // trivial digitization, i.e. no signal shape
0084     else {
0085       amplitude_ = double(sample.data()) * adcLSB_;
0086     }
0087 
0088     int thickness = (ddd_ != nullptr) ? ddd_->waferType(dataFrame.id()) : 0;
0089     amplitude_ = amplitude_ / fCPerMIP_[thickness];
0090 
0091     LogDebug("HGCUncalibratedRecHit") << "isSiFESim_: " << isSiFESim_ << " ADC+: set the charge to: " << amplitude_
0092                                       << ' ' << sample.data() << ' ' << adcLSB_ << ' '
0093                                       << "               TDC+: set the ToA to: " << jitter_ << ' ' << sample.toa()
0094                                       << ' ' << toaLSBToNS_ << ' ' << tdcLSB_
0095                                       << "               getToAValid(): " << sample.getToAValid()
0096                                       << " mode(): " << sample.mode() << std::endl;
0097     LogDebug("HGCUncalibratedRecHit") << "Final uncalibrated amplitude : " << amplitude_ << std::endl;
0098 
0099     return HGCUncalibratedRecHit(dataFrame.id(), amplitude_, pedestal_, jitter_, chi2_, flag);
0100   }
0101 
0102 private:
0103   double adcLSB_, tdcLSB_, toaLSBToNS_, tdcOnsetfC_;
0104   bool isSiFESim_;
0105   std::vector<double> fCPerMIP_;
0106   const HGCalDDDConstants* ddd_;
0107 };
0108 #endif