CMS 3D CMS Logo

HGCalUncalibRecHitRecWeightsAlgo.h
Go to the documentation of this file.
1 #ifndef RecoLocalCalo_HGCalRecAlgos_HGCalUncalibRecHitRecWeightsAlgo_HH
2 #define RecoLocalCalo_HGCalRecAlgos_HGCalUncalibRecHitRecWeightsAlgo_HH
3 
14 #include <vector>
15 #include <cmath>
16 
19 
21 
22 template<class C> class HGCalUncalibRecHitRecWeightsAlgo
23 {
24  public:
25  // destructor
27 
28  void set_isSiFESim(const bool isSiFE) { isSiFESim_ = isSiFE; }
29  bool isSiFESim() const { return isSiFESim_; }
30 
31  void set_ADCLSB(const double adclsb) { adcLSB_ = adclsb; }
32  void set_TDCLSB(const double tdclsb) { tdcLSB_ = tdclsb; }
33 
34  void set_toaLSBToNS(const double lsb2ns) { toaLSBToNS_ = lsb2ns; }
35 
36  void set_tdcOnsetfC(const double tdcOnset) { tdcOnsetfC_ = tdcOnset; }
37 
38  void set_fCPerMIP(const std::vector<double>& fCPerMIP) {
39  if( std::any_of(fCPerMIP.cbegin(),
40  fCPerMIP.cend(),
41  [](double conv){ return conv <= 0.0; }) ) {
42  throw cms::Exception("BadConversionFactor") << "At least one of fCPerMIP is zero!" << std::endl;
43  }
45  }
46 
47  void setGeometry(const HGCalGeometry* geom) {
48  if ( geom ) ddd_ = &(geom->topology().dddConstants());
49  else ddd_ = nullptr;
50  }
51 
53  virtual HGCUncalibratedRecHit makeRecHit( const C& dataFrame ) {
54  double amplitude_(-1.), pedestal_(-1.), jitter_(-1.), chi2_(-1.);
55  uint32_t flag = 0;
56 
57  constexpr int iSample=2; //only in-time sample
58  const auto& sample = dataFrame.sample(iSample);
59 
60  // are we using the SiFE Simulation?
61  if( isSiFESim_ ) {
62  // mode == true means TDC readout was activated
63  if( sample.mode() ) {
64  flag = !sample.threshold(); //raise flag if busy cell
65  // LG (23/06/2015):
66  //to get a continuous energy spectrum we must add here the maximum value in fC ever
67  //reported by the ADC. Namely: floor(tdcOnset/adcLSB_) * adcLSB_
68  // need to increment by one so TDC doesn't overlap with ADC last bin
69  // LG (11/04/2016):
70  // offset the TDC upwards to reflect the bin center
71  amplitude_ = ( std::floor(tdcOnsetfC_/adcLSB_) + 1.0 )* adcLSB_ + ( double(sample.data()) + 0.5) * tdcLSB_;
72  if(sample.getToAValid()) jitter_ = double(sample.toa()) * toaLSBToNS_;
73  LogDebug("HGCUncalibratedRecHit") << "TDC+: set the charge to: " << amplitude_ << ' ' << sample.data()
74  << ' ' << tdcLSB_ << std::endl
75  << "TDC+: set the ToA to: " << jitter_ << ' '
76  << sample.toa() << ' ' << toaLSBToNS_ << ' '
77  << " flag=" << flag << std::endl;
78  } else {
79  amplitude_ = double(sample.data()) * adcLSB_;
80  if(sample.getToAValid()) jitter_ = double(sample.toa()) * toaLSBToNS_;
81  LogDebug("HGCUncalibratedRecHit") << "ADC+: set the charge to: " << amplitude_ << ' ' << sample.data()
82  << ' ' << adcLSB_ << ' '
83  << "TDC+: set the ToA to: " << jitter_ << ' '
84  << sample.toa() << ' ' << toaLSBToNS_ << ' '<< std::endl;
85  }
86  } else {
87  amplitude_ = double(sample.data()) * adcLSB_;
88  LogDebug("HGCUncalibratedRecHit") << "ADC+: set the charge to: " << amplitude_ << ' ' << sample.data()
89  << ' ' << adcLSB_ << ' ' << std::endl;
90  }
91 
92  int thickness = 1;
93  if( ddd_ != nullptr ) {
94  HGCalDetId hid(dataFrame.id());
95  thickness = ddd_->waferTypeL(hid.wafer());
96  }
97  amplitude_ = amplitude_/fCPerMIP_[thickness-1];
98 
99  LogDebug("HGCUncalibratedRecHit") << "Final uncalibrated amplitude : " << amplitude_ << std::endl;
100 
101  return HGCUncalibratedRecHit( dataFrame.id(), amplitude_, pedestal_, jitter_, chi2_, flag);
102  }
103 
104  private:
106  bool isSiFESim_;
107  std::vector<double> fCPerMIP_;
109 };
110 #endif
#define LogDebug(id)
void setGeometry(const HGCalGeometry *geom)
static HepMC::IO_HEPEVT conv
#define constexpr
virtual HGCUncalibratedRecHit makeRecHit(const C &dataFrame)
Compute parameters.
const HGCalTopology & topology() const
Definition: HGCalGeometry.h:99
int waferTypeL(int wafer) const
const HGCalDDDConstants & dddConstants() const
void set_fCPerMIP(const std::vector< double > &fCPerMIP)