CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SSDigitizerAlgorithm.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
5 
9 
10 // Geometry
13 
14 using namespace edm;
15 
16 namespace {
17  double nFactorial(int n);
18  double aScalingConstant(int N, int i);
19 } // namespace
20 namespace {
21  double nFactorial(int n) { return std::tgamma(n + 1); }
22  double aScalingConstant(int N, int i) {
23  return std::pow(-1, (double)i) * nFactorial(N) * nFactorial(N + 2) /
24  (nFactorial(N - i) * nFactorial(N + 2 - i) * nFactorial(i));
25  }
26 } // namespace
27 
29  if (use_LorentzAngle_DB_) { // Get Lorentz angle from DB record
30  siPhase2OTLorentzAngle_ = &es.getData(siPhase2OTLorentzAngleToken_);
31  }
32 
33  geom_ = &es.getData(geomToken_);
34 }
35 
37  : Phase2TrackerDigitizerAlgorithm(conf.getParameter<ParameterSet>("AlgorithmCommon"),
38  conf.getParameter<ParameterSet>("SSDigitizerAlgorithm"),
39  iC),
40  hitDetectionMode_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm").getParameter<int>("HitDetectionMode")),
41  pulseShapeParameters_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm")
42  .getParameter<std::vector<double> >("PulseShapeParameters")),
43  deadTime_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm").getParameter<double>("CBCDeadTime")),
44  geomToken_(iC.esConsumes()) {
47  pixelFlag_ = false;
48  LogDebug("SSDigitizerAlgorithm ") << "SSDigitizerAlgorithm constructed "
49  << "Configuration parameters:"
50  << "Threshold/Gain = "
51  << "threshold in electron Endcap = " << theThresholdInE_Endcap_
52  << "threshold in electron Barrel = " << theThresholdInE_Barrel_ << " "
53  << theElectronPerADC_ << " " << theAdcFullScale_ << " The delta cut-off is set to "
54  << tMax_ << " pix-inefficiency " << addPixelInefficiency_;
56 }
57 SSDigitizerAlgorithm::~SSDigitizerAlgorithm() { LogDebug("SSDigitizerAlgorithm") << "SSDigitizerAlgorithm deleted"; }
58 //
59 // -- Select the Hit for Digitization
60 //
61 bool SSDigitizerAlgorithm::select_hit(const PSimHit& hit, double tCorr, double& sigScale) const {
62  bool result = false;
64  result = select_hit_sampledMode(hit, tCorr, sigScale);
66  result = select_hit_latchedMode(hit, tCorr, sigScale);
67  else {
68  double toa = hit.tof() - tCorr;
69  result = (toa > theTofLowerCut_ && toa < theTofUpperCut_);
70  }
71  return result;
72 }
73 //
74 // -- Select Hits in Sampled Mode
75 //
76 bool SSDigitizerAlgorithm::select_hit_sampledMode(const PSimHit& hit, double tCorr, double& sigScale) const {
77  double toa = hit.tof() - tCorr;
78  double sampling_time = bx_time;
79 
80  DetId det_id = DetId(hit.detUnitId());
81  float theThresholdInE =
83 
84  sigScale = getSignalScale(sampling_time - toa);
85  return (sigScale * hit.energyLoss() / GeVperElectron_ > theThresholdInE);
86 }
87 //
88 // -- Select Hits in Hit Detection Mode
89 //
90 bool SSDigitizerAlgorithm::select_hit_latchedMode(const PSimHit& hit, double tCorr, double& sigScale) const {
91  float toa = hit.tof() - tCorr;
92  toa -= hit.eventId().bunchCrossing() * bx_time;
93 
94  float sampling_time = (-1) * (hit.eventId().bunchCrossing() + 1) * bx_time;
95 
96  DetId det_id = DetId(hit.detUnitId());
97  float theThresholdInE =
99 
100  bool lastPulse = true;
101  bool aboveThr = false;
102  for (float i = deadTime_; i <= bx_time; i++) {
103  sigScale = getSignalScale(sampling_time - toa + i);
104 
105  aboveThr = (sigScale * hit.energyLoss() / GeVperElectron_ > theThresholdInE);
106  if (!lastPulse && aboveThr)
107  return true;
108 
109  lastPulse = aboveThr;
110  }
111  return false;
112 }
114  constexpr size_t max_par = 6;
115  if (pulseShapeParameters_.size() < max_par)
116  return -1;
117  double xOffset = pulseShapeParameters_[0];
118  double tau = pulseShapeParameters_[1];
119  double r = pulseShapeParameters_[2];
120  double theta = pulseShapeParameters_[3];
121  int nTerms = static_cast<int>(pulseShapeParameters_[4]);
122 
123  double fN = 0;
124  double xx = x - xOffset;
125  if (xx < 0)
126  return 0;
127 
128  for (int i = 0; i < nTerms; i++) {
129  double angularTerm = 0;
130  double temporalTerm = 0;
131  double rTerm = std::pow(r, i) / (std::pow(tau, 2. * i) * ::nFactorial(i + 2));
132  for (int j = 0; j <= i; j++) {
133  angularTerm += std::pow(std::cos(theta), (double)(i - j)) * std::pow(std::sin(theta), (double)j);
134  temporalTerm += ::aScalingConstant(i, j) * std::pow(xx, (double)(i - j)) * std::pow(tau, (double)j);
135  }
136  double fi = rTerm * angularTerm * temporalTerm;
137 
138  fN += fi;
139  }
140  return fN;
141 }
142 double SSDigitizerAlgorithm::signalShape(double x) const {
143  double xOffset = pulseShapeParameters_[0];
144  double tau = pulseShapeParameters_[1];
145  double maxCharge = pulseShapeParameters_[5];
146 
147  double xx = x - xOffset;
148  return maxCharge * (std::exp(-xx / tau) * std::pow(xx / tau, 2.) * cbc3PulsePolarExpansion(x));
149 }
151  for (size_t i = 0; i < interpolationPoints; i++) {
152  float val = i / interpolationStep;
153 
154  pulseShapeVec_.push_back(signalShape(val));
155  }
156 }
158  double res = 0.0;
159  int len = pulseShapeVec_.size();
160 
161  if (xval < 0.0 || xval * interpolationStep >= len)
162  return res;
163 
164  unsigned int lower = std::floor(xval) * interpolationStep;
165  unsigned int upper = std::ceil(xval) * interpolationStep;
166  for (size_t i = lower + 1; i < upper * interpolationStep; i++) {
167  float val = i * 0.1;
168  if (val > xval) {
169  res = pulseShapeVec_[i - 1];
170  break;
171  }
172  }
173  return res;
174 }
175 //
176 // -- Compare Signal with Threshold
177 //
179  float charge,
180  float thr) const {
181  return (charge >= thr);
182 }
constexpr int32_t ceil(float num)
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:76
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
static constexpr size_t interpolationPoints
tuple result
Definition: mps_fire.py:311
SSDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
double signalShape(double x) const
int bunchCrossing() const
get the detector field from this detid
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
bool isAboveThreshold(const DigitizerUtility::SimHitInfo *hitInfo, float charge, float thr) const override
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
EncodedEventId eventId() const
Definition: PSimHit.h:108
static constexpr auto TOB
std::vector< double > pulseShapeVec_
void init(const edm::EventSetup &es) override
double getSignalScale(double xval) const
Definition: DetId.h:17
#define N
Definition: blowfish.cc:9
constexpr int16_t xOffset
std::vector< double > pulseShapeParameters_
bool select_hit(const PSimHit &hit, double tCorr, double &sigScale) const override
bool select_hit_latchedMode(const PSimHit &hit, double tCorr, double &sigScale) const
static constexpr float bx_time
double cbc3PulsePolarExpansion(double x) const
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:79
bool select_hit_sampledMode(const PSimHit &hit, double tCorr, double &sigScale) const
float x
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
edm::ESGetToken< SiPhase2OuterTrackerLorentzAngle, SiPhase2OuterTrackerLorentzAngleSimRcd > siPhase2OTLorentzAngleToken_
static constexpr int interpolationStep
unsigned int detUnitId() const
Definition: PSimHit.h:97
#define LogDebug(id)