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