CMS 3D CMS Logo

SSDigitizerAlgorithm.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
5 
9 
10 // Geometry
13 
15 
16 using namespace edm;
17 
18 namespace {
19  double nFactorial(int n);
20  double aScalingConstant(int N, int i);
21 } // namespace
22 namespace {
23  double nFactorial(int n) { return std::tgamma(n + 1); }
24  double aScalingConstant(int N, int i) {
25  return std::pow(-1, (double)i) * nFactorial(N) * nFactorial(N + 2) /
26  (nFactorial(N - i) * nFactorial(N + 2 - i) * nFactorial(i));
27  }
28 } // namespace
29 
31  if (use_LorentzAngle_DB_) // Get Lorentz angle from DB record
32  siPhase2OTLorentzAngle_ = &es.getData(siPhase2OTLorentzAngleToken_);
33 
34  if (use_deadmodule_DB_) // Get Bad Channel (SiStripBadStrip) from DB
35  badChannelPayload_ = &es.getData(badChannelToken_);
36 
37  geom_ = &es.getData(geomToken_);
38 }
39 
41  : Phase2TrackerDigitizerAlgorithm(conf.getParameter<ParameterSet>("AlgorithmCommon"),
42  conf.getParameter<ParameterSet>("SSDigitizerAlgorithm"),
43  iC),
44  hitDetectionMode_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm").getParameter<int>("HitDetectionMode")),
45  pulseShapeParameters_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm")
46  .getParameter<std::vector<double> >("PulseShapeParameters")),
47  deadTime_(conf.getParameter<ParameterSet>("SSDigitizerAlgorithm").getParameter<double>("CBCDeadTime")),
48  geomToken_(iC.esConsumes()) {
51 
52  if (use_deadmodule_DB_) {
53  std::string badChannelLabel_ = conf.getParameter<ParameterSet>("SSDigitizerAlgorithm")
54  .getUntrackedParameter<std::string>("BadChannelLabel", "");
55  badChannelToken_ = iC.esConsumes(edm::ESInputTag{"", badChannelLabel_});
56  }
57 
58  pixelFlag_ = false;
59  LogDebug("SSDigitizerAlgorithm ") << "SSDigitizerAlgorithm constructed "
60  << "Configuration parameters:"
61  << "Threshold/Gain = "
62  << "threshold in electron Endcap = " << theThresholdInE_Endcap_
63  << "threshold in electron Barrel = " << theThresholdInE_Barrel_ << " "
64  << theElectronPerADC_ << " " << theAdcFullScale_ << " The delta cut-off is set to "
65  << tMax_ << " pix-inefficiency " << addPixelInefficiency_;
67 }
68 SSDigitizerAlgorithm::~SSDigitizerAlgorithm() { LogDebug("SSDigitizerAlgorithm") << "SSDigitizerAlgorithm deleted"; }
69 //
70 // -- Select the Hit for Digitization
71 //
72 bool SSDigitizerAlgorithm::select_hit(const PSimHit& hit, double tCorr, double& sigScale) const {
73  bool result = false;
75  result = select_hit_sampledMode(hit, tCorr, sigScale);
77  result = select_hit_latchedMode(hit, tCorr, sigScale);
78  else {
79  double toa = hit.tof() - tCorr;
80  result = (toa > theTofLowerCut_ && toa < theTofUpperCut_);
81  }
82  return result;
83 }
84 //
85 // -- Select Hits in Sampled Mode
86 //
87 bool SSDigitizerAlgorithm::select_hit_sampledMode(const PSimHit& hit, double tCorr, double& sigScale) const {
88  double toa = hit.tof() - tCorr;
89  double sampling_time = bx_time;
90 
91  DetId det_id = DetId(hit.detUnitId());
92  float theThresholdInE =
94 
95  sigScale = getSignalScale(sampling_time - toa);
96  return (sigScale * hit.energyLoss() / GeVperElectron_ > theThresholdInE);
97 }
98 //
99 // -- Select Hits in Hit Detection Mode
100 //
101 bool SSDigitizerAlgorithm::select_hit_latchedMode(const PSimHit& hit, double tCorr, double& sigScale) const {
102  float toa = hit.tof() - tCorr;
103  toa -= hit.eventId().bunchCrossing() * bx_time;
104 
105  float sampling_time = (-1) * (hit.eventId().bunchCrossing() + 1) * bx_time;
106 
107  DetId det_id = DetId(hit.detUnitId());
108  float theThresholdInE =
110 
111  bool lastPulse = true;
112  bool aboveThr = false;
113  for (float i = deadTime_; i <= bx_time; i++) {
114  sigScale = getSignalScale(sampling_time - toa + i);
115 
116  aboveThr = (sigScale * hit.energyLoss() / GeVperElectron_ > theThresholdInE);
117  if (!lastPulse && aboveThr)
118  return true;
119 
120  lastPulse = aboveThr;
121  }
122  return false;
123 }
125  constexpr size_t max_par = 6;
126  if (pulseShapeParameters_.size() < max_par)
127  return -1;
128  double xOffset = pulseShapeParameters_[0];
129  double tau = pulseShapeParameters_[1];
130  double r = pulseShapeParameters_[2];
131  double theta = pulseShapeParameters_[3];
132  int nTerms = static_cast<int>(pulseShapeParameters_[4]);
133 
134  double fN = 0;
135  double xx = x - xOffset;
136  if (xx < 0)
137  return 0;
138 
139  for (int i = 0; i < nTerms; i++) {
140  double angularTerm = 0;
141  double temporalTerm = 0;
142  double rTerm = std::pow(r, i) / (std::pow(tau, 2. * i) * ::nFactorial(i + 2));
143  for (int j = 0; j <= i; j++) {
144  angularTerm += std::pow(std::cos(theta), (double)(i - j)) * std::pow(std::sin(theta), (double)j);
145  temporalTerm += ::aScalingConstant(i, j) * std::pow(xx, (double)(i - j)) * std::pow(tau, (double)j);
146  }
147  double fi = rTerm * angularTerm * temporalTerm;
148 
149  fN += fi;
150  }
151  return fN;
152 }
153 double SSDigitizerAlgorithm::signalShape(double x) const {
154  double xOffset = pulseShapeParameters_[0];
155  double tau = pulseShapeParameters_[1];
156  double maxCharge = pulseShapeParameters_[5];
157 
158  double xx = x - xOffset;
159  return maxCharge * (std::exp(-xx / tau) * std::pow(xx / tau, 2.) * cbc3PulsePolarExpansion(x));
160 }
162  for (size_t i = 0; i < interpolationPoints; i++) {
163  float val = i / interpolationStep;
164 
165  pulseShapeVec_.push_back(signalShape(val));
166  }
167 }
169  double res = 0.0;
170  int len = pulseShapeVec_.size();
171 
172  if (xval < 0.0 || xval * interpolationStep >= len)
173  return res;
174 
175  unsigned int lower = std::floor(xval) * interpolationStep;
176  unsigned int upper = std::ceil(xval) * interpolationStep;
177  for (size_t i = lower + 1; i < upper * interpolationStep; i++) {
178  float val = i * 0.1;
179  if (val > xval) {
180  res = pulseShapeVec_[i - 1];
181  break;
182  }
183  }
184  return res;
185 }
186 //
187 // -- Compare Signal with Threshold
188 //
190  float charge,
191  float thr) const {
192  return (charge >= thr);
193 }
194 //
195 // -- Read Bad Channels from the Condidion DB and kill channels/module accordingly
196 //
198  uint32_t detId = pixdet->geographicalId().rawId();
199 
200  signal_map_type& theSignal = _signal[detId];
201  signal_map_type signalNew;
202 
204  for (std::vector<unsigned int>::const_iterator badChannel = range.first; badChannel != range.second; ++badChannel) {
205  const auto& firstStrip = badChannelPayload_->decodePhase2(*badChannel).firstStrip;
206  const auto& channelRange = badChannelPayload_->decodePhase2(*badChannel).range;
207 
208  for (int index = 0; index < channelRange; index++) {
209  for (auto& s : theSignal) {
210  auto& channel = s.first;
211  if (channel == firstStrip + index)
212  s.second.set(0.);
213  }
214  }
215  }
216 }
unsigned short range
bool select_hit_latchedMode(const PSimHit &hit, double tCorr, double &sigScale) const
double signalShape(double x) const
constexpr int32_t ceil(float num)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
bool select_hit_sampledMode(const PSimHit &hit, double tCorr, double &sigScale) const
double getSignalScale(double xval) const
const Range getRange(const uint32_t detID) const
std::map< int, digitizerUtility::Ph2Amplitude, std::less< int > > signal_map_type
Definition: Electron.h:6
static constexpr size_t interpolationPoints
SSDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
bool isAboveThreshold(const digitizerUtility::SimHitInfo *hitInfo, float charge, float thr) const override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
std::vector< double > pulseShapeVec_
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
void init(const edm::EventSetup &es) override
Definition: DetId.h:17
#define N
Definition: blowfish.cc:9
unsigned short firstStrip
std::vector< double > pulseShapeParameters_
double cbc3PulsePolarExpansion(double x) const
bool select_hit(const PSimHit &hit, double tCorr, double &sigScale) const override
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static constexpr float bx_time
void module_killing_DB(const Phase2TrackerGeomDetUnit *pixdet) override
HLT enums.
edm::ESGetToken< SiStripBadStrip, SiPhase2OuterTrackerBadStripRcd > badChannelToken_
data decodePhase2(const unsigned int &value) const
std::pair< ContainerIterator, ContainerIterator > Range
const SiStripBadStrip * badChannelPayload_
float x
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
edm::ESGetToken< SiPhase2OuterTrackerLorentzAngle, SiPhase2OuterTrackerLorentzAngleSimRcd > siPhase2OTLorentzAngleToken_
static constexpr int interpolationStep
#define LogDebug(id)