CMS 3D CMS Logo

ETLElectronicsSim.cc
Go to the documentation of this file.
2 
5 #include "CLHEP/Random/RandGaussQ.h"
6 
7 using namespace mtd;
8 
10  : geomToken_(iC.esConsumes()),
11  geom_(nullptr),
12  bxTime_(pset.getParameter<double>("bxTime")),
13  integratedLum_(pset.getParameter<double>("IntegratedLuminosity")),
14  adcNbits_(pset.getParameter<uint32_t>("adcNbits")),
15  tdcNbits_(pset.getParameter<uint32_t>("tdcNbits")),
16  adcSaturation_MIP_(pset.getParameter<double>("adcSaturation_MIP")),
17  adcLSB_MIP_(adcSaturation_MIP_ / std::pow(2., adcNbits_)),
18  adcBitSaturation_(std::pow(2, adcNbits_) - 1),
19  adcThreshold_MIP_(pset.getParameter<double>("adcThreshold_MIP")),
20  iThreshold_MIP_(pset.getParameter<double>("iThreshold_MIP")),
21  toaLSB_ns_(pset.getParameter<double>("toaLSB_ns")),
22  tdcBitSaturation_(std::pow(2, tdcNbits_) - 1),
23  referenceChargeColl_(pset.getParameter<double>("referenceChargeColl")),
24  noiseLevel_(pset.getParameter<double>("noiseLevel")),
25  sigmaDistorsion_(pset.getParameter<double>("sigmaDistorsion")),
26  sigmaTDC_(pset.getParameter<double>("sigmaTDC")),
27  formulaLandauNoise_(pset.getParameter<std::string>("formulaLandauNoise")) {}
28 
30 
33  CLHEP::HepRandomEngine* hre) const {
34  MTDSimHitData chargeColl, toa1, toa2, tot;
35 
36  std::vector<double> emptyV;
37  std::vector<double> radius(1);
38  std::vector<double> fluence(1);
39  std::vector<double> chOverMPV(1);
40 
41  for (MTDSimHitDataAccumulator::const_iterator it = input.begin(); it != input.end(); it++) {
42  chargeColl.fill(0.f);
43  toa1.fill(0.f);
44  toa2.fill(0.f);
45  tot.fill(0.f);
46 
47  ETLDetId detId = it->first.detid_;
48  DetId geoId = detId.geographicalId();
49  const MTDGeomDet* thedet = geom_->idToDet(geoId);
50  if (thedet == nullptr)
51  throw cms::Exception("EtlElectronicsSim") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
52  << detId.rawId() << ") is invalid!" << std::dec << std::endl;
53 
54  const PixelTopology& topo = static_cast<const PixelTopology&>(thedet->topology());
55  Local3DPoint local_point(topo.localX(it->first.row_), topo.localY(it->first.column_), 0.);
56 
57  //Here we are sampling over all the buckets. However for the ETL there should be only one bucket at i = 0
58  for (size_t i = 0; i < it->second.hit_info[0].size(); i++) {
59  if ((it->second).hit_info[0][i] == 0) {
60  continue;
61  }
62  if ((it->second).hit_info[0][i] < adcThreshold_MIP_)
63  continue;
64  // time of arrival
65  double finalToA = (it->second).hit_info[1][i];
66  double finalToC = (it->second).hit_info[1][i];
67 
68  // fill the time and charge arrays
69  const unsigned int ibucket = std::floor(finalToA / bxTime_);
70  if ((i + ibucket) >= chargeColl.size())
71  continue;
72 
73  //Calculate the jitter
74  double SignalToNoise =
75  etlPulseShape_.maximum() * ((it->second).hit_info[0][i] / referenceChargeColl_) / noiseLevel_;
76  double sigmaJitter1 = etlPulseShape_.timeOfMax() / SignalToNoise;
77  double sigmaJitter2 = (etlPulseShape_.fallTime() - etlPulseShape_.timeOfMax()) / SignalToNoise;
78  //Calculate the distorsion
80  //Calculate the TDC
81  double sigmaTDC = sigmaTDC_;
82  //Calculate the Landau Noise
83  chOverMPV[0] = (it->second).hit_info[0][i] / (it->second).hit_info[2][i];
84  double sigmaLN = formulaLandauNoise_.evaluate(chOverMPV, emptyV);
85  double sigmaToA = sqrt(sigmaJitter1 * sigmaJitter1 + sigmaDistorsion * sigmaDistorsion + sigmaTDC * sigmaTDC +
86  sigmaLN * sigmaLN);
87  double sigmaToC = sqrt(sigmaJitter2 * sigmaJitter2 + sigmaDistorsion * sigmaDistorsion + sigmaTDC * sigmaTDC +
88  sigmaLN * sigmaLN);
89  double smearing1 = 0.0;
90  double smearing2 = 0.0;
91 
92  if (sigmaToA > 0. && sigmaToC > 0.) {
93  smearing1 = CLHEP::RandGaussQ::shoot(hre, 0., sigmaToA);
94  smearing2 = CLHEP::RandGaussQ::shoot(hre, 0., sigmaToC);
95  }
96 
97  finalToA += smearing1;
98  finalToC += smearing1 + smearing2;
99 
100  std::array<float, 3> times = etlPulseShape_.timeAtThr(
101  (it->second).hit_info[0][i] / referenceChargeColl_, iThreshold_MIP_, iThreshold_MIP_);
102 
103  //The signal is below the threshold
104  if (times[0] == 0 && times[1] == 0 && times[2] == 0) {
105  continue;
106  }
107  //The signal is considered to be below the threshold
108  finalToA += times[0];
109  finalToC += times[2];
110  if (finalToA >= finalToC)
111  continue;
112  chargeColl[i + ibucket] += (it->second).hit_info[0][i];
113 
114  if (toa1[i + ibucket] == 0. || (finalToA - ibucket * bxTime_) < toa1[i + ibucket]) {
115  toa1[i + ibucket] = finalToA - ibucket * bxTime_;
116  toa2[i + ibucket] = finalToC - ibucket * bxTime_;
117  }
118 
119  tot[i + ibucket] = finalToC - finalToA;
120  }
121  // Run the shaper to create a new data frame
122  ETLDataFrame rawDataFrame(it->first.detid_);
123  runTrivialShaper(rawDataFrame, chargeColl, toa1, tot, it->first.row_, it->first.column_);
124  updateOutput(output, rawDataFrame);
125  }
126 }
127 
129  const mtd::MTDSimHitData& chargeColl,
130  const mtd::MTDSimHitData& toa,
131  const mtd::MTDSimHitData& tot,
132  const uint8_t row,
133  const uint8_t col) const {
134 #ifdef EDM_ML_DEBUG
135  bool dumpInfo(false);
136  for (int it = 0; it < (int)(chargeColl.size()); it++) {
137  if (chargeColl[it] > adcThreshold_MIP_) {
138  dumpInfo = true;
139  break;
140  }
141  }
142  if (dumpInfo) {
143  LogTrace("ETLElectronicsSim") << "[runTrivialShaper]";
144  }
145 #endif
146 
147  //set new ADCs. Notice that we are only interested in the first element of the array for the ETL
148  for (int it = 0; it < (int)(chargeColl.size()); it++) {
149  //brute force saturation, maybe could to better with an exponential like saturation
150  const uint32_t adc = std::min((uint32_t)std::floor(chargeColl[it] / adcLSB_MIP_), adcBitSaturation_);
151  const uint32_t tdc_time1 = std::min((uint32_t)std::floor(toa[it] / toaLSB_ns_), tdcBitSaturation_);
152  const uint32_t tdc_time2 = std::min((uint32_t)std::floor(tot[it] / toaLSB_ns_), tdcBitSaturation_);
153  //If time over threshold is 0 the event is assumed to not pass the threshold
154  bool thres = true;
155  if (tdc_time2 == 0 || chargeColl[it] < adcThreshold_MIP_)
156  thres = false;
157 
158  ETLSample newSample;
159  newSample.set(thres, false, tdc_time1, tdc_time2, adc, row, col);
160 
161  //ETLSample newSample;
162  dataFrame.setSample(it, newSample);
163 
164 #ifdef EDM_ML_DEBUG
165  if (dumpInfo) {
166  LogTrace("ETLElectronicsSim") << adc << " (" << chargeColl[it] << "/" << adcLSB_MIP_ << ") ";
167  }
168 #endif
169  }
170 
171 #ifdef EDM_ML_DEBUG
172  if (dumpInfo) {
173  std::ostringstream msg;
174  dataFrame.print(msg);
175  LogTrace("ETLElectronicsSim") << msg.str();
176  }
177 #endif
178 }
179 
180 void ETLElectronicsSim::updateOutput(ETLDigiCollection& coll, const ETLDataFrame& rawDataFrame) const {
181  int itIdx(9);
182  if (rawDataFrame.size() <= itIdx + 2)
183  return;
184 
185  ETLDataFrame dataFrame(rawDataFrame.id());
186  dataFrame.resize(dfSIZE);
187  bool putInEvent(false);
188  for (int it = 0; it < dfSIZE; ++it) {
189  dataFrame.setSample(it, rawDataFrame[itIdx - 2 + it]);
190  if (it == 2)
191  putInEvent = rawDataFrame[itIdx - 2 + it].threshold();
192  }
193 
194  if (putInEvent) {
195  coll.push_back(dataFrame);
196  }
197 }
std::array< float, 3 > timeAtThr(const float scale, const float threshold1, const float threshold2) const
Definition: MTDShapeBase.cc:13
const edm::ESGetToken< MTDGeometry, MTDDigiGeometryRecord > geomToken_
static constexpr int dfSIZE
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const reco::FormulaEvaluator formulaLandauNoise_
double evaluate(V const &iVariables, P const &iParameters) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void updateOutput(ETLDigiCollection &coll, const ETLDataFrame &rawDataFrame) const
std::array< MTDSimData_t, nSamples > MTDSimHitData
virtual const Topology & topology() const
Definition: GeomDet.cc:67
void push_back(T const &t)
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
const float toaLSB_ns_
wrapper for a data word
Definition: ETLSample.h:13
float fallTime() const
Definition: MTDShapeBase.cc:79
const ETLPulseShape etlPulseShape_
#define LogTrace(id)
const float referenceChargeColl_
static std::string const input
Definition: EdmProvDump.cc:50
virtual float localX(float mpX) const =0
int size() const
total number of samples in the digi
Definition: FTLDataFrameT.h:45
void resize(size_t s)
allow to set size
Definition: FTLDataFrameT.h:50
ETLElectronicsSim(const edm::ParameterSet &pset, edm::ConsumesCollector iC)
T sqrt(T t)
Definition: SSEVec.h:23
const D & id() const
det id
Definition: FTLDataFrameT.h:30
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:171
void set(bool thr, bool mode, uint16_t toa, uint16_t tot, uint16_t data, uint8_t row, uint8_t col)
Definition: ETLSample.h:53
double f[11][100]
void setSample(int i, const S &sample)
Definition: FTLDataFrameT.h:57
def dumpInfo(run)
Definition: getInfo.py:88
float maximum() const
Definition: MTDShapeBase.cc:77
const float sigmaDistorsion_
Definition: DetId.h:17
const uint32_t adcBitSaturation_
double timeOfMax() const
Definition: MTDShapeBase.cc:75
virtual float localY(float mpY) const =0
const float iThreshold_MIP_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const uint32_t tdcBitSaturation_
tuple msg
Definition: mps_check.py:286
const float adcLSB_MIP_
void runTrivialShaper(ETLDataFrame &dataFrame, const mtd::MTDSimHitData &chargeColl, const mtd::MTDSimHitData &toa1, const mtd::MTDSimHitData &toa2, const uint8_t row, const uint8_t column) const
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:16
const float noiseLevel_
col
Definition: cuy.py:1009
Readout digi for HGC.
Definition: FTLDataFrameT.h:14
Definition: output.py:1
void getEventSetup(const edm::EventSetup &evt)
void run(const mtd::MTDSimHitDataAccumulator &input, ETLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
void print(std::ostream &out=std::cout)
Definition: FTLDataFrameT.h:61
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
const MTDGeometry * geom_
uint16_t *__restrict__ uint16_t const *__restrict__ adc
const float adcThreshold_MIP_