CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PixelDigitizerAlgorithm.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 
6 
11 
12 // Geometry
15 
16 using namespace edm;
17 using namespace sipixelobjects;
18 
20  if (use_ineff_from_db_) // load gain calibration service fromdb...
21  theSiPixelGainCalibrationService_->setESObjects(es);
22 
23  if (use_deadmodule_DB_)
24  siPixelBadModule_ = &es.getData(siPixelBadModuleToken_);
25 
26  if (use_LorentzAngle_DB_) // Get Lorentz angle from DB record
27  siPixelLorentzAngle_ = &es.getData(siPixelLorentzAngleToken_);
28 
29  // gets the map and geometry from the DB (to kill ROCs)
30  fedCablingMap_ = &es.getData(fedCablingMapToken_);
31  geom_ = &es.getData(geomToken_);
32 }
33 
35  : Phase2TrackerDigitizerAlgorithm(conf.getParameter<ParameterSet>("AlgorithmCommon"),
36  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm"),
37  iC),
38  odd_row_interchannelCoupling_next_row_(conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
39  .getParameter<double>("Odd_row_interchannelCoupling_next_row")),
40  even_row_interchannelCoupling_next_row_(conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
41  .getParameter<double>("Even_row_interchannelCoupling_next_row")),
42  odd_column_interchannelCoupling_next_column_(
43  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
44  .getParameter<double>("Odd_column_interchannelCoupling_next_column")),
45  even_column_interchannelCoupling_next_column_(
46  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm")
47  .getParameter<double>("Even_column_interchannelCoupling_next_column")),
48  apply_timewalk_(conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm").getParameter<bool>("ApplyTimewalk")),
49  timewalk_model_(
50  conf.getParameter<ParameterSet>("PixelDigitizerAlgorithm").getParameter<edm::ParameterSet>("TimewalkModel")),
51  fedCablingMapToken_(iC.esConsumes()),
52  geomToken_(iC.esConsumes()) {
57  pixelFlag_ = true;
58  LogDebug("PixelDigitizerAlgorithm") << "Algorithm constructed "
59  << "Configuration parameters:"
60  << "Threshold/Gain = "
61  << "threshold in electron Endcap = " << theThresholdInE_Endcap_
62  << "threshold in electron Barrel = " << theThresholdInE_Barrel_ << " "
64  << " The delta cut-off is set to " << tMax_ << " pix-inefficiency "
66 }
67 PixelDigitizerAlgorithm::~PixelDigitizerAlgorithm() { LogDebug("PixelDigitizerAlgorithm") << "Algorithm deleted"; }
68 //
69 // -- Select the Hit for Digitization
70 //
71 bool PixelDigitizerAlgorithm::select_hit(const PSimHit& hit, double tCorr, double& sigScale) const {
72  double time = hit.tof() - tCorr;
73  return (time >= theTofLowerCut_ && time < theTofUpperCut_);
74 }
75 
76 // ======================================================================
77 //
78 // Add Cross-talk contribution
79 //
80 // ======================================================================
82  if (!pixelFlag_)
83  return;
84 
85  const Phase2TrackerTopology* topol = &pixdet->specificTopology();
86 
87  // cross-talk calculation valid for the case of 25x100 pixels
88  const float pitch_first = 0.0025;
89  const float pitch_second = 0.0100;
90 
91  // 0.5 um tolerance when comparing the pitch to accommodate the small changes in different TK geometrie (temporary fix)
92  const double pitch_tolerance(0.0005);
93 
94  if (std::abs(topol->pitch().first - pitch_first) > pitch_tolerance ||
95  std::abs(topol->pitch().second - pitch_second) > pitch_tolerance)
96  return;
97 
98  uint32_t detID = pixdet->geographicalId().rawId();
99  signal_map_type& theSignal = _signal[detID];
100  signal_map_type signalNew;
101 
102  int numRows = topol->nrows();
103  int numColumns = topol->ncolumns();
104 
105  for (auto& s : theSignal) {
106  float signalInElectrons = s.second.ampl(); // signal in electrons
107 
108  auto hitChan = PixelDigi::channelToPixel(s.first);
109 
110  float signalInElectrons_odd_row_Xtalk_next_row = signalInElectrons * odd_row_interchannelCoupling_next_row_;
111  float signalInElectrons_even_row_Xtalk_next_row = signalInElectrons * even_row_interchannelCoupling_next_row_;
112  float signalInElectrons_odd_column_Xtalk_next_column =
114  float signalInElectrons_even_column_Xtalk_next_column =
116 
117  // subtract the charge which will be shared
118  s.second.set(signalInElectrons - signalInElectrons_odd_row_Xtalk_next_row -
119  signalInElectrons_even_row_Xtalk_next_row - signalInElectrons_odd_column_Xtalk_next_column -
120  signalInElectrons_even_column_Xtalk_next_column);
121 
122  if (hitChan.first != 0) {
123  auto XtalkPrev = std::make_pair(hitChan.first - 1, hitChan.second);
124  int chanXtalkPrev = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
125  : Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
126  if (hitChan.first % 2 == 1)
127  signalNew.emplace(chanXtalkPrev,
128  DigitizerUtility::Amplitude(signalInElectrons_even_row_Xtalk_next_row, nullptr, -1.0));
129  else
130  signalNew.emplace(chanXtalkPrev,
131  DigitizerUtility::Amplitude(signalInElectrons_odd_row_Xtalk_next_row, nullptr, -1.0));
132  }
133  if (hitChan.first < numRows - 1) {
134  auto XtalkNext = std::make_pair(hitChan.first + 1, hitChan.second);
135  int chanXtalkNext = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
136  : Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
137  if (hitChan.first % 2 == 1)
138  signalNew.emplace(chanXtalkNext,
139  DigitizerUtility::Amplitude(signalInElectrons_odd_row_Xtalk_next_row, nullptr, -1.0));
140  else
141  signalNew.emplace(chanXtalkNext,
142  DigitizerUtility::Amplitude(signalInElectrons_even_row_Xtalk_next_row, nullptr, -1.0));
143  }
144 
145  if (hitChan.second != 0) {
146  auto XtalkPrev = std::make_pair(hitChan.first, hitChan.second - 1);
147  int chanXtalkPrev = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second)
148  : Phase2TrackerDigi::pixelToChannel(XtalkPrev.first, XtalkPrev.second);
149  if (hitChan.second % 2 == 1)
150  signalNew.emplace(chanXtalkPrev,
151  DigitizerUtility::Amplitude(signalInElectrons_even_column_Xtalk_next_column, nullptr, -1.0));
152  else
153  signalNew.emplace(chanXtalkPrev,
154  DigitizerUtility::Amplitude(signalInElectrons_odd_column_Xtalk_next_column, nullptr, -1.0));
155  }
156  if (hitChan.second < numColumns - 1) {
157  auto XtalkNext = std::make_pair(hitChan.first, hitChan.second + 1);
158  int chanXtalkNext = pixelFlag_ ? PixelDigi::pixelToChannel(XtalkNext.first, XtalkNext.second)
159  : Phase2TrackerDigi::pixelToChannel(XtalkNext.first, XtalkNext.second);
160  if (hitChan.second % 2 == 1)
161  signalNew.emplace(chanXtalkNext,
162  DigitizerUtility::Amplitude(signalInElectrons_odd_column_Xtalk_next_column, nullptr, -1.0));
163  else
164  signalNew.emplace(chanXtalkNext,
165  DigitizerUtility::Amplitude(signalInElectrons_even_column_Xtalk_next_column, nullptr, -1.0));
166  }
167  }
168  for (auto const& l : signalNew) {
169  int chan = l.first;
170  auto iter = theSignal.find(chan);
171  if (iter != theSignal.end()) {
172  iter->second += l.second.ampl();
173  } else {
174  theSignal.emplace(chan, DigitizerUtility::Amplitude(l.second.ampl(), nullptr, -1.0));
175  }
176  }
177 }
178 
180  : x_(pset.getParameter<std::vector<double>>("charge")), y_(pset.getParameter<std::vector<double>>("delay")) {
181  if (x_.size() != y_.size())
182  throw cms::Exception("Configuration")
183  << "Timewalk model error: the number of charge values does not match the number of delay values!";
184 }
185 
187  auto it = std::lower_bound(x_.begin(), x_.end(), x);
188  if (it == x_.begin())
189  return y_.front();
190  if (it == x_.end())
191  return y_.back();
192  int index = std::distance(x_.begin(), it);
193  double x_high = *it;
194  double x_low = *(--it);
195  double p = (x - x_low) / (x_high - x_low);
196  return p * y_[index] + (1 - p) * y_[index - 1];
197 }
198 
200  threshold_values = pset.getParameter<std::vector<double>>("ThresholdValues");
201  const auto& curve_psetvec = pset.getParameter<std::vector<edm::ParameterSet>>("Curves");
202  if (threshold_values.size() != curve_psetvec.size())
203  throw cms::Exception("Configuration")
204  << "Timewalk model error: the number of threshold values does not match the number of curves.";
205  for (const auto& curve_pset : curve_psetvec)
206  curves.emplace_back(curve_pset);
207 }
208 
209 double PixelDigitizerAlgorithm::TimewalkModel::operator()(double q_in, double q_threshold) const {
210  auto index = find_closest_index(threshold_values, q_threshold);
211  return curves[index](q_in);
212 }
213 
214 std::size_t PixelDigitizerAlgorithm::TimewalkModel::find_closest_index(const std::vector<double>& vec,
215  double value) const {
216  auto it = std::lower_bound(vec.begin(), vec.end(), value);
217  if (it == vec.begin())
218  return 0;
219  else if (it == vec.end())
220  return vec.size() - 1;
221  else {
222  auto it_upper = it;
223  auto it_lower = --it;
224  auto closest = (value - *it_lower > *it_upper - value) ? it_upper : it_lower;
225  return std::distance(vec.begin(), closest);
226  }
227 }
228 //
229 // -- Compare Signal with Threshold
230 //
232  float charge,
233  float thr) const {
234  if (charge < thr)
235  return false;
236  if (apply_timewalk_ && hitInfo) {
237  float corrected_time = hitInfo->time();
238  double time = corrected_time + timewalk_model_(charge, thr);
239  return (time >= theTofLowerCut_ && time < theTofUpperCut_);
240  } else
241  return true;
242 }
edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > siPixelBadModuleToken_
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:76
void init(const edm::EventSetup &es) override
static std::pair< int, int > channelToPixel(int ch)
Definition: PixelDigi.h:69
virtual int ncolumns() const =0
tuple chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, &quot;NDC&quot;) lumi.SetBorderSize( 0 ) lumi...
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual int nrows() const =0
const TimewalkModel timewalk_model_
static int pixelToChannel(int row, int col)
Definition: PixelDigi.h:75
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void add_cross_talk(const Phase2TrackerGeomDetUnit *pixdet) override
bool isAboveThreshold(const DigitizerUtility::SimHitInfo *hitInfo, float charge, float thr) const override
static PackedDigiType pixelToChannel(unsigned int row, unsigned int col)
TimewalkCurve(const edm::ParameterSet &pset)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
std::map< int, DigitizerUtility::Amplitude, std::less< int > > signal_map_type
bool select_hit(const PSimHit &hit, double tCorr, double &sigScale) const override
TimewalkModel(const edm::ParameterSet &pset)
std::size_t find_closest_index(const std::vector< double > &vec, double value) const
double operator()(double q_in, double q_threshold) const
PixelDigitizerAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleSimRcd > siPixelLorentzAngleToken_
virtual std::pair< float, float > pitch() const =0
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
#define LogDebug(id)