CMS 3D CMS Logo

ETLElectronicsSim.cc
Go to the documentation of this file.
2 
4 #include "CLHEP/Random/RandGaussQ.h"
5 
6 using namespace mtd;
7 
9  : geom_(nullptr),
10  debug_(pset.getUntrackedParameter<bool>("debug", false)),
11  bxTime_(pset.getParameter<double>("bxTime")),
12  integratedLum_(pset.getParameter<double>("IntegratedLuminosity")),
13  fluence_(pset.getParameter<std::string>("FluenceVsRadius")),
14  lgadGain_(pset.getParameter<std::string>("LGADGainVsFluence")),
15  timeRes2_(pset.getParameter<std::string>("TimeResolution2")),
16  adcNbits_(pset.getParameter<uint32_t>("adcNbits")),
17  tdcNbits_(pset.getParameter<uint32_t>("tdcNbits")),
18  adcSaturation_MIP_(pset.getParameter<double>("adcSaturation_MIP")),
19  adcLSB_MIP_(adcSaturation_MIP_ / std::pow(2., adcNbits_)),
20  adcBitSaturation_(std::pow(2, adcNbits_) - 1),
21  adcThreshold_MIP_(pset.getParameter<double>("adcThreshold_MIP")),
22  toaLSB_ns_(pset.getParameter<double>("toaLSB_ns")),
23  tdcBitSaturation_(std::pow(2, tdcNbits_) - 1) {}
24 
28  geom_ = geom.product();
29 }
30 
33  CLHEP::HepRandomEngine* hre) const {
34  MTDSimHitData chargeColl, toa;
35 
36  std::vector<double> emptyV;
37  std::vector<double> radius(1);
38  std::vector<double> fluence(1);
39  std::vector<double> gain(1);
40 
41  for (MTDSimHitDataAccumulator::const_iterator it = input.begin(); it != input.end(); it++) {
42  chargeColl.fill(0.f);
43  toa.fill(0.f);
44 
45  ETLDetId detId = it->first.detid_;
46  DetId geoId = detId.geographicalId();
47  const MTDGeomDet* thedet = geom_->idToDet(geoId);
48  if (thedet == nullptr)
49  throw cms::Exception("EtlElectronicsSim") << "GeographicalID: " << std::hex << geoId.rawId() << " ("
50  << detId.rawId() << ") is invalid!" << std::dec << std::endl;
51  const PixelTopology& topo = static_cast<const PixelTopology&>(thedet->topology());
52 
53  Local3DPoint local_point(topo.localX(it->first.row_), topo.localY(it->first.column_), 0.);
54  const auto& global_point = thedet->toGlobal(local_point);
55 
56  for (size_t i = 0; i < it->second.hit_info[0].size(); i++) {
57  if ((it->second).hit_info[0][i] < adcThreshold_MIP_)
58  continue;
59 
60  // time of arrival
61  float finalToA = (it->second).hit_info[1][i];
62 
63  // calculate the LGAD gain as a function of the fluence at R = radius
64  radius[0] = global_point.perp();
65  fluence[0] = integratedLum_ * fluence_.evaluate(radius, emptyV);
66  gain[0] = lgadGain_.evaluate(fluence, emptyV);
67  if (gain[0] <= 0.)
68  throw cms::Exception("EtlElectronicsSim") << "Null or negative LGAD gain!" << std::endl;
69 
70  // Gaussian smearing of the time of arrival
71  double sigmaToA = sqrt(timeRes2_.evaluate(gain, emptyV));
72 
73  if (sigmaToA > 0.)
74  finalToA += CLHEP::RandGaussQ::shoot(hre, 0., sigmaToA);
75 
76  // fill the time and charge arrays
77  const unsigned int ibucket = std::floor(finalToA / bxTime_);
78  if ((i + ibucket) >= chargeColl.size())
79  continue;
80 
81  chargeColl[i + ibucket] += (it->second).hit_info[0][i];
82 
83  if (toa[i + ibucket] == 0. || (finalToA - ibucket * bxTime_) < toa[i + ibucket])
84  toa[i + ibucket] = finalToA - ibucket * bxTime_;
85  }
86 
87  // run the shaper to create a new data frame
88  ETLDataFrame rawDataFrame(it->first.detid_);
89  runTrivialShaper(rawDataFrame, chargeColl, toa, it->first.row_, it->first.column_);
90  updateOutput(output, rawDataFrame);
91  }
92 }
93 
95  const mtd::MTDSimHitData& chargeColl,
96  const mtd::MTDSimHitData& toa,
97  const uint8_t row,
98  const uint8_t col) const {
99  bool debug = debug_;
100 #ifdef EDM_ML_DEBUG
101  for (int it = 0; it < (int)(chargeColl.size()); it++)
102  debug |= (chargeColl[it] > adcThreshold_MIP_);
103 #endif
104 
105  if (debug)
106  edm::LogVerbatim("ETLElectronicsSim") << "[runTrivialShaper]" << std::endl;
107 
108  //set new ADCs
109  for (int it = 0; it < (int)(chargeColl.size()); it++) {
110  //brute force saturation, maybe could to better with an exponential like saturation
111  const uint32_t adc = std::min((uint32_t)std::floor(chargeColl[it] / adcLSB_MIP_), adcBitSaturation_);
112  const uint32_t tdc_time = std::min((uint32_t)std::floor(toa[it] / toaLSB_ns_), tdcBitSaturation_);
113  ETLSample newSample;
114  newSample.set(chargeColl[it] > adcThreshold_MIP_, false, tdc_time, adc, row, col);
115  dataFrame.setSample(it, newSample);
116 
117  if (debug)
118  edm::LogVerbatim("ETLElectronicsSim") << adc << " (" << chargeColl[it] << "/" << adcLSB_MIP_ << ") ";
119  }
120 
121  if (debug) {
122  std::ostringstream msg;
123  dataFrame.print(msg);
124  edm::LogVerbatim("ETLElectronicsSim") << msg.str() << std::endl;
125  }
126 }
127 
128 void ETLElectronicsSim::updateOutput(ETLDigiCollection& coll, const ETLDataFrame& rawDataFrame) const {
129  int itIdx(9);
130  if (rawDataFrame.size() <= itIdx + 2)
131  return;
132 
133  ETLDataFrame dataFrame(rawDataFrame.id());
134  dataFrame.resize(dfSIZE);
135  bool putInEvent(false);
136  for (int it = 0; it < dfSIZE; ++it) {
137  dataFrame.setSample(it, rawDataFrame[itIdx - 2 + it]);
138  if (it == 2)
139  putInEvent = rawDataFrame[itIdx - 2 + it].threshold();
140  }
141 
142  if (putInEvent) {
143  coll.push_back(dataFrame);
144  }
145 }
ETLElectronicsSim::bxTime_
const float bxTime_
Definition: ETLElectronicsSim.h:49
MTDDigiGeometryRecord
Definition: MTDDigiGeometryRecord.h:15
FTLDataFrameT::print
void print(std::ostream &out=std::cout)
Definition: FTLDataFrameT.h:62
FTLDataFrameT::id
const D & id() const
det id
Definition: FTLDataFrameT.h:31
ETLElectronicsSim::integratedLum_
const float integratedLum_
Definition: ETLElectronicsSim.h:50
ETLElectronicsSim::timeRes2_
const reco::FormulaEvaluator timeRes2_
Definition: ETLElectronicsSim.h:53
electrons_cff.bool
bool
Definition: electrons_cff.py:393
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
min
T min(T a, T b)
Definition: MathUtil.h:58
ETLElectronicsSim::adcThreshold_MIP_
const float adcThreshold_MIP_
Definition: ETLElectronicsSim.h:62
ETLElectronicsSim.h
cuy.col
col
Definition: cuy.py:1010
TrackerGeomDet
Definition: TrackerGeomDet.h:6
ETLElectronicsSim::toaLSB_ns_
const float toaLSB_ns_
Definition: ETLElectronicsSim.h:63
edm::SortedCollection
Definition: SortedCollection.h:49
GeomDet::topology
virtual const Topology & topology() const
Definition: GeomDet.cc:67
mps_check.msg
tuple msg
Definition: mps_check.py:285
ETLSample::set
void set(bool thr, bool mode, uint16_t toa, uint16_t data, uint8_t row, uint8_t col)
Definition: ETLSample.h:48
ETLDetId
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
ETLElectronicsSim::updateOutput
void updateOutput(ETLDigiCollection &coll, const ETLDataFrame &rawDataFrame) const
Definition: ETLElectronicsSim.cc:128
edm::SortedCollection::push_back
void push_back(T const &t)
Definition: SortedCollection.h:188
ETLElectronicsSim::ETLElectronicsSim
ETLElectronicsSim(const edm::ParameterSet &pset)
Definition: ETLElectronicsSim.cc:8
ETLElectronicsSim::fluence_
const reco::FormulaEvaluator fluence_
Definition: ETLElectronicsSim.h:51
ecalLiteDTU::adc
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
Definition: EcalLiteDTUSample.h:12
DetId
Definition: DetId.h:17
debug
#define debug
Definition: HDRShower.cc:19
MTDGeometry::idToDet
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:171
mtd_digitizer::MTDSimHitData
std::array< MTDSimData_t, nSamples > MTDSimHitData
Definition: MTDDigitizerTypes.h:15
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
ETLElectronicsSim::debug_
const bool debug_
Definition: ETLElectronicsSim.h:48
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
FTLDataFrameT::setSample
void setSample(int i, const S &sample)
Definition: FTLDataFrameT.h:58
edm::ESHandle
Definition: DTSurvey.h:22
ETLSample
wrapper for a data word
Definition: ETLSample.h:13
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
ETLDetId::geographicalId
ETLDetId geographicalId() const
Definition: ETLDetId.h:108
Point3DBase< float, LocalTag >
PixelTopology
Definition: PixelTopology.h:10
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
ETLElectronicsSim::runTrivialShaper
void runTrivialShaper(ETLDataFrame &dataFrame, const mtd::MTDSimHitData &chargeColl, const mtd::MTDSimHitData &toa, const uint8_t row, const uint8_t column) const
Definition: ETLElectronicsSim.cc:94
ETLElectronicsSim::adcLSB_MIP_
const float adcLSB_MIP_
Definition: ETLElectronicsSim.h:60
createfilelist.int
int
Definition: createfilelist.py:10
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
ETLElectronicsSim::getEventSetup
void getEventSetup(const edm::EventSetup &evt)
Definition: ETLElectronicsSim.cc:25
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
FTLDataFrameT
Readout digi for HGC.
Definition: FTLDataFrameT.h:14
ETLElectronicsSim::tdcBitSaturation_
const uint32_t tdcBitSaturation_
Definition: ETLElectronicsSim.h:64
FTLDataFrameT::resize
void resize(size_t s)
allow to set size
Definition: FTLDataFrameT.h:51
ETLElectronicsSim::lgadGain_
const reco::FormulaEvaluator lgadGain_
Definition: ETLElectronicsSim.h:52
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
reco::FormulaEvaluator::evaluate
double evaluate(V const &iVariables, P const &iParameters) const
Definition: FormulaEvaluator.h:73
Exception
Definition: hltDiff.cc:246
mtd_digitizer::MTDSimHitDataAccumulator
std::unordered_map< MTDCellId, MTDCellInfo > MTDSimHitDataAccumulator
Definition: MTDDigitizerTypes.h:39
PixelTopology::localY
virtual float localY(float mpY) const =0
ETLElectronicsSim::geom_
const MTDGeometry * geom_
Definition: ETLElectronicsSim.h:46
ETLElectronicsSim::adcBitSaturation_
const uint32_t adcBitSaturation_
Definition: ETLElectronicsSim.h:61
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
PixelTopology::localX
virtual float localX(float mpX) const =0
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
FTLDataFrameT::size
int size() const
total number of samples in the digi
Definition: FTLDataFrameT.h:46
mtd_digitizer
Definition: MTDDigitizer.h:35
ETLElectronicsSim::run
void run(const mtd::MTDSimHitDataAccumulator &input, ETLDigiCollection &output, CLHEP::HepRandomEngine *hre) const
Definition: ETLElectronicsSim.cc:31
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ETLElectronicsSim::dfSIZE
static constexpr int dfSIZE
Definition: ETLElectronicsSim.h:43