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  double time = hit.tof() - tCorr;
84  return (time >= theTofLowerCut_ && time < theTofUpperCut_);
85 }
86 
87 // ======================================================================
88 //
89 // Add Cross-talk contribution
90 //
91 // ======================================================================
93  if (!pixelFlag_)
94  return;
95 
96  const Phase2TrackerTopology* topol = &pixdet->specificTopology();
97 
98  // cross-talk calculation valid for the case of 25x100 pixels
99  const float pitch_first = 0.0025;
100  const float pitch_second = 0.0100;
101 
102  // 0.5 um tolerance when comparing the pitch to accommodate the small changes in different TK geometrie (temporary fix)
103  const double pitch_tolerance(0.0005);
104 
105  if (std::abs(topol->pitch().first - pitch_first) > pitch_tolerance ||
106  std::abs(topol->pitch().second - pitch_second) > pitch_tolerance)
107  return;
108 
109  uint32_t detID = pixdet->geographicalId().rawId();
110  signal_map_type& theSignal = _signal[detID];
111  signal_map_type signalNew;
112 
113  int numRows = topol->nrows();
114  int numColumns = topol->ncolumns();
115 
116  for (auto& s : theSignal) {
117  float signalInElectrons = s.second.ampl(); // signal in electrons
118 
119  auto hitChan = PixelDigi::channelToPixel(s.first);
120 
121  float signalInElectrons_odd_row_Xtalk_next_row = signalInElectrons * odd_row_interchannelCoupling_next_row_;
122  float signalInElectrons_even_row_Xtalk_next_row = signalInElectrons * even_row_interchannelCoupling_next_row_;
123  float signalInElectrons_odd_column_Xtalk_next_column =
125  float signalInElectrons_even_column_Xtalk_next_column =
127 
128  // subtract the charge which will be shared
129  s.second.set(signalInElectrons - signalInElectrons_odd_row_Xtalk_next_row -
130  signalInElectrons_even_row_Xtalk_next_row - signalInElectrons_odd_column_Xtalk_next_column -
131  signalInElectrons_even_column_Xtalk_next_column);
132 
133  if (hitChan.first != 0) {
134  auto XtalkPrev = std::make_pair(hitChan.first - 1, hitChan.second);
135  int chanXtalkPrev = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
136  : Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
137  if (hitChan.first % 2 == 1)
138  signalNew.emplace(chanXtalkPrev,
139  digitizerUtility::Ph2Amplitude(signalInElectrons_even_row_Xtalk_next_row, nullptr, -1.0));
140  else
141  signalNew.emplace(chanXtalkPrev,
142  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_row_Xtalk_next_row, nullptr, -1.0));
143  }
144  if (hitChan.first < numRows - 1) {
145  auto XtalkNext = std::make_pair(hitChan.first + 1, hitChan.second);
146  int chanXtalkNext = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
147  : Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
148  if (hitChan.first % 2 == 1)
149  signalNew.emplace(chanXtalkNext,
150  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_row_Xtalk_next_row, nullptr, -1.0));
151  else
152  signalNew.emplace(chanXtalkNext,
153  digitizerUtility::Ph2Amplitude(signalInElectrons_even_row_Xtalk_next_row, nullptr, -1.0));
154  }
155 
156  if (hitChan.second != 0) {
157  auto XtalkPrev = std::make_pair(hitChan.first, hitChan.second - 1);
158  int chanXtalkPrev = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
159  : Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
160  if (hitChan.second % 2 == 1)
161  signalNew.emplace(
162  chanXtalkPrev,
163  digitizerUtility::Ph2Amplitude(signalInElectrons_even_column_Xtalk_next_column, nullptr, -1.0));
164  else
165  signalNew.emplace(
166  chanXtalkPrev,
167  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_column_Xtalk_next_column, nullptr, -1.0));
168  }
169  if (hitChan.second < numColumns - 1) {
170  auto XtalkNext = std::make_pair(hitChan.first, hitChan.second + 1);
171  int chanXtalkNext = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
172  : Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
173  if (hitChan.second % 2 == 1)
174  signalNew.emplace(
175  chanXtalkNext,
176  digitizerUtility::Ph2Amplitude(signalInElectrons_odd_column_Xtalk_next_column, nullptr, -1.0));
177  else
178  signalNew.emplace(
179  chanXtalkNext,
180  digitizerUtility::Ph2Amplitude(signalInElectrons_even_column_Xtalk_next_column, nullptr, -1.0));
181  }
182  }
183  for (auto const& l : signalNew) {
184  int chan = l.first;
185  auto iter = theSignal.find(chan);
186  if (iter != theSignal.end()) {
187  iter->second += l.second.ampl();
188  } else {
189  theSignal.emplace(chan, digitizerUtility::Ph2Amplitude(l.second.ampl(), nullptr, -1.0));
190  }
191  }
192 }
193 
195  : x_(pset.getParameter<std::vector<double>>("charge")), y_(pset.getParameter<std::vector<double>>("delay")) {
196  if (x_.size() != y_.size())
197  throw cms::Exception("Configuration")
198  << "Timewalk model error: the number of charge values does not match the number of delay values!";
199 }
200 
202  auto it = std::lower_bound(x_.begin(), x_.end(), x);
203  if (it == x_.begin())
204  return y_.front();
205  if (it == x_.end())
206  return y_.back();
207  int index = std::distance(x_.begin(), it);
208  double x_high = *it;
209  double x_low = *(--it);
210  double p = (x - x_low) / (x_high - x_low);
211  return p * y_[index] + (1 - p) * y_[index - 1];
212 }
213 
215  threshold_values = pset.getParameter<std::vector<double>>("ThresholdValues");
216  const auto& curve_psetvec = pset.getParameter<std::vector<edm::ParameterSet>>("Curves");
217  if (threshold_values.size() != curve_psetvec.size())
218  throw cms::Exception("Configuration")
219  << "Timewalk model error: the number of threshold values does not match the number of curves.";
220  for (const auto& curve_pset : curve_psetvec)
221  curves.emplace_back(curve_pset);
222 }
223 
224 double PixelDigitizerAlgorithm::TimewalkModel::operator()(double q_in, double q_threshold) const {
225  auto index = find_closest_index(threshold_values, q_threshold);
226  return curves[index](q_in);
227 }
228 
229 std::size_t PixelDigitizerAlgorithm::TimewalkModel::find_closest_index(const std::vector<double>& vec,
230  double value) const {
231  auto it = std::lower_bound(vec.begin(), vec.end(), value);
232  if (it == vec.begin())
233  return 0;
234  else if (it == vec.end())
235  return vec.size() - 1;
236  else {
237  auto it_upper = it;
238  auto it_lower = --it;
239  auto closest = (value - *it_lower > *it_upper - value) ? it_upper : it_lower;
240  return std::distance(vec.begin(), closest);
241  }
242 }
243 //
244 // -- Compare Signal with Threshold
245 //
247  float charge,
248  float thr) const {
249  if (charge < thr)
250  return false;
251  if (apply_timewalk_ && hitInfo) {
252  float corrected_time = hitInfo->time();
253  double time = corrected_time + timewalk_model_(charge, thr);
254  return (time >= theTofLowerCut_ && time < theTofUpperCut_);
255  } else
256  return true;
257 }
258 //
259 // -- Read Bad Channels from the Condidion DB and kill channels/module accordingly
260 //
262  bool isbad = false;
263  uint32_t detID = pixdet->geographicalId().rawId();
264  int ncol = pixdet->specificTopology().ncolumns();
265  if (ncol < 0)
266  return;
267  std::vector<SiPixelQuality::disabledModuleType> disabledModules = siPixelBadModule_->getBadComponentList();
268 
270  for (const auto& mod : disabledModules) {
271  if (detID == mod.DetID) {
272  isbad = true;
273  badmodule = mod;
274  break;
275  }
276  }
277 
278  if (!isbad)
279  return;
280 
281  signal_map_type& theSignal = _signal[detID]; // check validity
282  if (badmodule.errorType == 0) { // this is a whole dead module.
283  for (auto& s : theSignal)
284  s.second.set(0.); // reset amplitude
285  } else { // all other module types: half-modules and single ROCs.
286  // Get Bad ROC position:
287  // follow the example of getBadRocPositions in CondFormats/SiPixelObjects/src/SiPixelQuality.cc
288  std::vector<GlobalPixel> badrocpositions;
289  for (size_t j = 0; j < static_cast<size_t>(ncol); j++) {
290  if (siPixelBadModule_->IsRocBad(detID, j)) {
291  std::vector<CablingPathToDetUnit> path = fedCablingMap_->pathToDetUnit(detID);
292  for (auto const& p : path) {
293  const PixelROC* myroc = fedCablingMap_->findItem(p);
294  if (myroc->idInDetUnit() == j) {
295  LocalPixel::RocRowCol local = {39, 25}; //corresponding to center of ROC row, col
296  GlobalPixel global = myroc->toGlobal(LocalPixel(local));
297  badrocpositions.push_back(global);
298  break;
299  }
300  }
301  }
302  }
303 
304  for (auto& s : theSignal) {
305  std::pair<int, int> ip;
306  if (pixelFlag_)
307  ip = PixelDigi::channelToPixel(s.first);
308  else
310 
311  for (auto const& p : badrocpositions) {
312  for (auto& k : badPixels_) {
313  if (p.row == k.getParameter<int>("row") && ip.first == k.getParameter<int>("row") &&
314  std::abs(ip.second - p.col) < k.getParameter<int>("col")) {
315  s.second.set(0.);
316  }
317  }
318  }
319  }
320  }
321 }
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)