CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_fCPerMIP(const std::vector<double>& fCPerMIP) {
37  if (std::any_of(fCPerMIP.cbegin(), fCPerMIP.cend(), [](double conv) { return conv <= 0.0; })) {
38  throw cms::Exception("BadConversionFactor") << "At least one of fCPerMIP is zero!" << std::endl;
39  }
41  }
42 
44  if (geom)
45  ddd_ = &(geom->topology().dddConstants());
46  else
47  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  // Were digis done w/ the complete digitization and using signal shape?
59  // (originally done only for the silicon, while for scitillator it was trivial. Fomr 11_ also scinti uses shape)
60  if (isSiFESim_) {
61  // mode == true: TDC readout was activated and amplitude comes from TimeOverThreshold
62  if (sample.mode()) {
63  flag = !sample.threshold(); // raise flag if busy cell
64  // LG (23/06/2015):
65  // to get a continuous energy spectrum we must add here the maximum value in fC ever
66  // reported by the ADC. Namely: floor(tdcOnset/adcLSB_) * adcLSB_
67  // need to increment by one so TDC doesn't overlap with ADC last bin
68  // LG (11/04/2016):
69  // offset the TDC upwards to reflect the bin center
70  amplitude_ = (std::floor(tdcOnsetfC_ / adcLSB_) + 1.0) * adcLSB_ + (double(sample.data()) + 0.5) * tdcLSB_;
71 
72  if (sample.getToAValid()) {
73  jitter_ = double(sample.toa()) * toaLSBToNS_;
74  }
75  } else {
76  amplitude_ = double(sample.data()) * adcLSB_; // why do we not have +0.5 here ?
77  if (sample.getToAValid()) {
78  jitter_ = double(sample.toa()) * toaLSBToNS_;
79  }
80  } //isSiFESim_
81  } //mode()
82 
83  // trivial digitization, i.e. no signal shape
84  else {
85  amplitude_ = double(sample.data()) * adcLSB_;
86  }
87 
88  int thickness = (ddd_ != nullptr) ? ddd_->waferType(dataFrame.id()) : 0;
89  amplitude_ = amplitude_ / fCPerMIP_[thickness];
90 
91  LogDebug("HGCUncalibratedRecHit") << "isSiFESim_: " << isSiFESim_ << " ADC+: set the charge to: " << amplitude_
92  << ' ' << sample.data() << ' ' << adcLSB_ << ' '
93  << " TDC+: set the ToA to: " << jitter_ << ' ' << sample.toa()
94  << ' ' << toaLSBToNS_ << ' ' << tdcLSB_
95  << " getToAValid(): " << sample.getToAValid()
96  << " mode(): " << sample.mode() << std::endl;
97  LogDebug("HGCUncalibratedRecHit") << "Final uncalibrated amplitude : " << amplitude_ << std::endl;
98 
99  return HGCUncalibratedRecHit(dataFrame.id(), amplitude_, pedestal_, jitter_, chi2_, flag);
100  }
101 
102 private:
105  std::vector<double> fCPerMIP_;
107 };
108 #endif
void setGeometry(const HGCalGeometry *geom)
virtual HGCUncalibratedRecHit makeRecHit(const C &dataFrame)
Compute HGCUncalibratedRecHit from DataFrame.
const HGCalTopology & topology() const
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:98
EPOS::IO_EPOS conv
void set_fCPerMIP(const std::vector< double > &fCPerMIP)
int waferType(DetId const &id, bool fromFile=false) const
#define LogDebug(id)