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>
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_tofDelay(const double tofDelay) { tofDelay_ = tofDelay; }
37 
38  void set_fCPerMIP(const std::vector<double>& fCPerMIP) {
39  if (std::any_of(fCPerMIP.cbegin(), fCPerMIP.cend(), [](double conv) { return conv <= 0.0; })) {
40  throw cms::Exception("BadConversionFactor") << "At least one of fCPerMIP is zero!" << std::endl;
41  }
43  }
44 
46  geom_ = geom.isValid() ? geom.product() : nullptr;
47  if (isSiFESim_ && geom_)
48  ddd_ = &(geom_->topology().dddConstants());
49  else
50  ddd_ = nullptr;
51  return geom_ != nullptr;
52  }
53 
55  virtual HGCUncalibratedRecHit makeRecHit(const C& dataFrame) {
56  double amplitude_(-1.), pedestal_(-1.), jitter_(-99.), chi2_(-1.);
57  uint32_t flag = 0;
58 
59  constexpr int iSample = 2; //only in-time sample
60  const auto& sample = dataFrame.sample(iSample);
61 
62  // Were digis done w/ the complete digitization and using signal shape?
63  // (originally done only for the silicon, while for scitillator it was trivial. Fomr 11_ also scinti uses shape)
64  if (isSiFESim_) {
65  // mode == true: TDC readout was activated and amplitude comes from TimeOverThreshold
66  if (sample.mode()) {
67  flag = !sample.threshold(); // raise flag if busy cell
68  // LG (23/06/2015):
69  // to get a continuous energy spectrum we must add here the maximum value in fC ever
70  // reported by the ADC. Namely: floor(tdcOnset/adcLSB_) * adcLSB_
71  // need to increment by one so TDC doesn't overlap with ADC last bin
72  // LG (11/04/2016):
73  // offset the TDC upwards to reflect the bin center
74  amplitude_ = (std::floor(tdcOnsetfC_ / adcLSB_) + 1.0) * adcLSB_ + (double(sample.data()) + 0.5) * tdcLSB_;
75  } else {
76  amplitude_ = double(sample.data()) * adcLSB_; // why do we not have +0.5 here ?
77  } //isSiFESim_
78  } //mode()
79 
80  // trivial digitization, i.e. no signal shape
81  else {
82  amplitude_ = double(sample.data()) * adcLSB_;
83  }
84 
85  if (sample.getToAValid()) {
86  const auto& dist2center = geom_ ? geom_->getPosition(dataFrame.id()).mag() : 0;
87  jitter_ = double(sample.toa()) * toaLSBToNS_ - dist2center / c_cm_ns - tofDelay_;
88  }
89 
90  int thickness = (ddd_ != nullptr) ? ddd_->waferType(dataFrame.id()) : 0;
91  amplitude_ = amplitude_ / fCPerMIP_[thickness];
92 
93  LogDebug("HGCUncalibratedRecHit") << "isSiFESim_: " << isSiFESim_ << " ADC+: set the charge to: " << amplitude_
94  << ' ' << sample.data() << ' ' << adcLSB_ << ' '
95  << " TDC+: set the ToA to: " << jitter_ << ' ' << sample.toa()
96  << ' ' << toaLSBToNS_ << ' ' << tdcLSB_
97  << " getToAValid(): " << sample.getToAValid()
98  << " mode(): " << sample.mode() << std::endl;
99  LogDebug("HGCUncalibratedRecHit") << "Final uncalibrated amplitude : " << amplitude_ << std::endl;
100 
101  return HGCUncalibratedRecHit(dataFrame.id(), amplitude_, pedestal_, jitter_, chi2_, flag);
102  }
103 
104 private:
105  static constexpr float c_cm_ns = CLHEP::c_light * CLHEP::ns / CLHEP::cm;
108  std::vector<double> fCPerMIP_;
111 };
112 #endif
bool setGeometry(const edm::ESHandle< HGCalGeometry > &geom)
virtual HGCUncalibratedRecHit makeRecHit(const C &dataFrame)
Compute HGCUncalibratedRecHit from DataFrame.
int waferType(DetId const &id, bool fromFile=false) const
const HGCalTopology & topology() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
EPOS::IO_EPOS conv
GlobalPoint getPosition(const DetId &id, bool debug=false) const
void set_fCPerMIP(const std::vector< double > &fCPerMIP)
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:98
#define LogDebug(id)