CMS 3D CMS Logo

PixelDigitizerAlgorithm.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
6 
11 
12 // Geometry
21 
22 using namespace edm;
23 using namespace sipixelobjects;
24 
26  if (use_ineff_from_db_) // load gain calibration service fromdb...
27  theSiPixelGainCalibrationService_->setESObjects(es);
28 
29  if (use_deadmodule_DB_)
30  siPixelBadModule_ = &es.getData(siPixelBadModuleToken_);
31 
32  if (use_LorentzAngle_DB_) // Get Lorentz angle from DB record
33  siPixelLorentzAngle_ = &es.getData(siPixelLorentzAngleToken_);
34 
35  // gets the map and geometry from the DB (to kill ROCs)
36  fedCablingMap_ = &es.getData(fedCablingMapToken_);
37  geom_ = &es.getData(geomToken_);
38  if (useChargeReweighting_) {
39  theSiPixelChargeReweightingAlgorithm_->init(es);
40  }
41 }
42 
44  : Phase2TrackerDigitizerAlgorithm(conf.getParameter<ParameterSet>("AlgorithmCommon"),
45  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm"),
46  iC),
47  odd_row_interchannelCoupling_next_row_(conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
48  .getParameter<double>("Odd_row_interchannelCoupling_next_row")),
49  even_row_interchannelCoupling_next_row_(conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
50  .getParameter<double>("Even_row_interchannelCoupling_next_row")),
51  odd_column_interchannelCoupling_next_column_(
52  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
53  .getParameter<double>("Odd_column_interchannelCoupling_next_column")),
54  even_column_interchannelCoupling_next_column_(
55  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
56  .getParameter<double>("Even_column_interchannelCoupling_next_column")),
57  apply_timewalk_(conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm").getParameter<bool>("ApplyTimewalk")),
58  timewalk_model_(
59  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm").getParameter<edm::ParameterSet>("TimewalkModel")),
60  fedCablingMapToken_(iC.esConsumes()),
61  geomToken_(iC.esConsumes()) {
66  pixelFlag_ = true;
67  LogDebug("PixelDigitizerAlgorithm") << "Algorithm constructed "
68  << "Configuration parameters:"
69  << "Threshold/Gain = "
70  << "threshold in electron Endcap = " << theThresholdInE_Endcap_
71  << "threshold in electron Barrel = " << theThresholdInE_Barrel_ << " "
73  << " The delta cut-off is set to " << tMax_ << " pix-inefficiency "
75 }
76 
77 PixelDigitizerAlgorithm::~PixelDigitizerAlgorithm() { LogDebug("PixelDigitizerAlgorithm") << "Algorithm deleted"; }
78 
79 //
80 // -- Select the Hit for Digitization
81 //
82 bool PixelDigitizerAlgorithm::select_hit(const PSimHit& hit, double tCorr, double& sigScale) const {
83  // in case of signal-shape emulation do not apply [TofLower,TofUpper] selection
84  double toa = hit.tof() - tCorr;
85  return apply_timewalk_ || (toa >= theTofLowerCut_ && toa < theTofUpperCut_);
86 }
87 
88 // ======================================================================
89 //
90 // Add Cross-talk contribution
91 //
92 // ======================================================================
94  if (!pixelFlag_)
95  return;
96 
97  const Phase2TrackerTopology* topol = &pixdet->specificTopology();
98 
99  // cross-talk calculation valid for the case of 25x100 pixels
100  const float pitch_first = 0.0025;
101  const float pitch_second = 0.0100;
102 
103  // 0.5 um tolerance when comparing the pitch to accommodate the small changes in different TK geometrie (temporary fix)
104  const double pitch_tolerance(0.0005);
105 
106  if (std::abs(topol->pitch().first - pitch_first) > pitch_tolerance ||
107  std::abs(topol->pitch().second - pitch_second) > pitch_tolerance)
108  return;
109 
110  uint32_t detID = pixdet->geographicalId().rawId();
111  signal_map_type& theSignal = _signal[detID];
112  signal_map_type signalNew;
113 
114  int numRows = topol->nrows();
115  int numColumns = topol->ncolumns();
116 
117  for (auto& s : theSignal) {
118  float signalInElectrons = s.second.ampl(); // signal in electrons
119 
120  auto hitChan = PixelDigi::channelToPixel(s.first);
121 
122  float signalInElectrons_odd_row_Xtalk_next_row = signalInElectrons * odd_row_interchannelCoupling_next_row_;
123  float signalInElectrons_even_row_Xtalk_next_row = signalInElectrons * even_row_interchannelCoupling_next_row_;
124  float signalInElectrons_odd_column_Xtalk_next_column =
126  float signalInElectrons_even_column_Xtalk_next_column =
128 
129  // subtract the charge which will be shared
130  s.second.set(signalInElectrons - signalInElectrons_odd_row_Xtalk_next_row -
131  signalInElectrons_even_row_Xtalk_next_row - signalInElectrons_odd_column_Xtalk_next_column -
132  signalInElectrons_even_column_Xtalk_next_column);
133 
134  if (hitChan.first != 0) {
135  auto XtalkPrev = std::make_pair(hitChan.first - 1, hitChan.second);
136  int chanXtalkPrev = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
137  : Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
138  if (hitChan.first % 2 == 1)
139  signalNew.emplace(chanXtalkPrev,
140  digitizerUtility::Ph2Amplitude(signalInElectrons_even_row_Xtalk_next_row, nullptr, -1.0));
141  else
142  signalNew.emplace(chanXtalkPrev,
143  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_row_Xtalk_next_row, nullptr, -1.0));
144  }
145  if (hitChan.first < numRows - 1) {
146  auto XtalkNext = std::make_pair(hitChan.first + 1, hitChan.second);
147  int chanXtalkNext = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
148  : Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
149  if (hitChan.first % 2 == 1)
150  signalNew.emplace(chanXtalkNext,
151  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_row_Xtalk_next_row, nullptr, -1.0));
152  else
153  signalNew.emplace(chanXtalkNext,
154  digitizerUtility::Ph2Amplitude(signalInElectrons_even_row_Xtalk_next_row, nullptr, -1.0));
155  }
156 
157  if (hitChan.second != 0) {
158  auto XtalkPrev = std::make_pair(hitChan.first, hitChan.second - 1);
159  int chanXtalkPrev = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
160  : Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
161  if (hitChan.second % 2 == 1)
162  signalNew.emplace(
163  chanXtalkPrev,
164  digitizerUtility::Ph2Amplitude(signalInElectrons_even_column_Xtalk_next_column, nullptr, -1.0));
165  else
166  signalNew.emplace(
167  chanXtalkPrev,
168  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_column_Xtalk_next_column, nullptr, -1.0));
169  }
170  if (hitChan.second < numColumns - 1) {
171  auto XtalkNext = std::make_pair(hitChan.first, hitChan.second + 1);
172  int chanXtalkNext = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
173  : Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
174  if (hitChan.second % 2 == 1)
175  signalNew.emplace(
176  chanXtalkNext,
177  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_column_Xtalk_next_column, nullptr, -1.0));
178  else
179  signalNew.emplace(
180  chanXtalkNext,
181  digitizerUtility::Ph2Amplitude(signalInElectrons_even_column_Xtalk_next_column, nullptr, -1.0));
182  }
183  }
184  for (auto const& l : signalNew) {
185  int chan = l.first;
186  auto iter = theSignal.find(chan);
187  if (iter != theSignal.end()) {
188  iter->second += l.second.ampl();
189  } else {
190  theSignal.emplace(chan, digitizerUtility::Ph2Amplitude(l.second.ampl(), nullptr, -1.0));
191  }
192  }
193 }
194 
196  : x_(pset.getParameter<std::vector<double>>("charge")), y_(pset.getParameter<std::vector<double>>("delay")) {
197  if (x_.size() != y_.size())
198  throw cms::Exception("Configuration")
199  << "Timewalk model error: the number of charge values does not match the number of delay values!";
200 }
201 
203  auto it = std::lower_bound(x_.begin(), x_.end(), x);
204  if (it == x_.begin())
205  return y_.front();
206  if (it == x_.end())
207  return y_.back();
208  int index = std::distance(x_.begin(), it);
209  double x_high = *it;
210  double x_low = *(--it);
211  double p = (x - x_low) / (x_high - x_low);
212  return p * y_[index] + (1 - p) * y_[index - 1];
213 }
214 
216  threshold_values = pset.getParameter<std::vector<double>>("ThresholdValues");
217  const auto& curve_psetvec = pset.getParameter<std::vector<edm::ParameterSet>>("Curves");
218  if (threshold_values.size() != curve_psetvec.size())
219  throw cms::Exception("Configuration")
220  << "Timewalk model error: the number of threshold values does not match the number of curves.";
221  for (const auto& curve_pset : curve_psetvec)
222  curves.emplace_back(curve_pset);
223 }
224 
225 double PixelDigitizerAlgorithm::TimewalkModel::operator()(double q_in, double q_threshold) const {
226  auto index = find_closest_index(threshold_values, q_threshold);
227  return curves[index](q_in);
228 }
229 
230 std::size_t PixelDigitizerAlgorithm::TimewalkModel::find_closest_index(const std::vector<double>& vec,
231  double value) const {
232  auto it = std::lower_bound(vec.begin(), vec.end(), value);
233  if (it == vec.begin())
234  return 0;
235  else if (it == vec.end())
236  return vec.size() - 1;
237  else {
238  auto it_upper = it;
239  auto it_lower = --it;
240  auto closest = (value - *it_lower > *it_upper - value) ? it_upper : it_lower;
241  return std::distance(vec.begin(), closest);
242  }
243 }
244 //
245 // -- Compare Signal with Threshold
246 //
248  float charge,
249  float thr) const {
250  if (charge < thr)
251  return false;
252  if (apply_timewalk_ && hitInfo) {
253  float corrected_time = hitInfo->time();
254  double time = corrected_time + timewalk_model_(charge, thr);
255  return (time >= theTofLowerCut_ && time < theTofUpperCut_);
256  } else
257  return true;
258 }
259 //
260 // -- Read Bad Channels from the Condidion DB and kill channels/module accordingly
261 //
263  bool isbad = false;
264  uint32_t detID = pixdet->geographicalId().rawId();
265  int ncol = pixdet->specificTopology().ncolumns();
266  if (ncol < 0)
267  return;
268  std::vector<SiPixelQuality::disabledModuleType> disabledModules = siPixelBadModule_->getBadComponentList();
269 
271  for (const auto& mod : disabledModules) {
272  if (detID == mod.DetID) {
273  isbad = true;
274  badmodule = mod;
275  break;
276  }
277  }
278 
279  if (!isbad)
280  return;
281 
282  signal_map_type& theSignal = _signal[detID]; // check validity
283  if (badmodule.errorType == 0) { // this is a whole dead module.
284  for (auto& s : theSignal)
285  s.second.set(0.); // reset amplitude
286  } else { // all other module types: half-modules and single ROCs.
287  // Get Bad ROC position:
288  // follow the example of getBadRocPositions in CondFormats/SiPixelObjects/src/SiPixelQuality.cc
289  std::vector<GlobalPixel> badrocpositions;
290  for (size_t j = 0; j < static_cast<size_t>(ncol); j++) {
291  if (siPixelBadModule_->IsRocBad(detID, j)) {
292  std::vector<CablingPathToDetUnit> path = fedCablingMap_->pathToDetUnit(detID);
293  for (auto const& p : path) {
294  const PixelROC* myroc = fedCablingMap_->findItem(p);
295  if (myroc->idInDetUnit() == j) {
296  LocalPixel::RocRowCol local = {39, 25}; //corresponding to center of ROC row, col
297  GlobalPixel global = myroc->toGlobal(LocalPixel(local));
298  badrocpositions.push_back(global);
299  break;
300  }
301  }
302  }
303  }
304 
305  for (auto& s : theSignal) {
306  std::pair<int, int> ip;
307  if (pixelFlag_)
308  ip = PixelDigi::channelToPixel(s.first);
309  else
311 
312  for (auto const& p : badrocpositions) {
313  for (auto& k : badPixels_) {
314  if (p.row == k.getParameter<int>("row") && ip.first == k.getParameter<int>("row") &&
315  std::abs(ip.second - p.col) < k.getParameter<int>("col")) {
316  s.second.set(0.);
317  }
318  }
319  }
320  }
321  }
322 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > siPixelBadModuleToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
bool IsRocBad(const uint32_t &detid, const short &rocNb) const
void init(const edm::EventSetup &es) override
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:69
virtual int ncolumns() const =0
int closest(std::vector< int > const &vec, int value)
void module_killing_DB(const Phase2TrackerGeomDetUnit *pixdet) override
virtual int nrows() const =0
std::vector< sipixelobjects::CablingPathToDetUnit > pathToDetUnit(uint32_t rawDetId) const final
std::map< int, digitizerUtility::Ph2Amplitude, std::less< int > > signal_map_type
identify pixel inside single ROC
Definition: LocalPixel.h:7
const TimewalkModel timewalk_model_
static int pixelToChannel(int row, int col)
Definition: PixelDigi.h:75
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
void add_cross_talk(const Phase2TrackerGeomDetUnit *pixdet) override
const std::vector< disabledModuleType > getBadComponentList() const
double operator()(double q_in, double q_threshold) const
GlobalPixel toGlobal(const LocalPixel &loc) const
Definition: PixelROC.h:55
static PackedDigiType pixelToChannel(unsigned int row, unsigned int col)
TimewalkCurve(const edm::ParameterSet &pset)
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const final
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
bool select_hit(const PSimHit &hit, double tCorr, double &sigScale) const override
TimewalkModel(const edm::ParameterSet &pset)
PixelDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
row and collumn in ROC representation
Definition: LocalPixel.h:13
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
bool isAboveThreshold(const digitizerUtility::SimHitInfo *hitInfo, float charge, float thr) const override
std::size_t find_closest_index(const std::vector< double > &vec, double value) const
static std::pair< unsigned int, unsigned int > channelToPixel(unsigned int ch)
HLT enums.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleSimRcd > siPixelLorentzAngleToken_
virtual std::pair< float, float > pitch() const =0
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:37
#define LogDebug(id)