13 #include "CLHEP/Random/RandGaussQ.h"
14 #include "CLHEP/Units/GlobalPhysicalConstants.h"
15 #include "CLHEP/Units/GlobalSystemOfUnits.h"
17 #include "boost/bind.hpp"
26 theComparatorThreshold(20.),
27 theComparatorNoise(0.),
28 theComparatorRMSOffset(2.),
29 theComparatorSaturation(1057.),
30 theComparatorWait(50.),
31 theComparatorDeadTime(100.),
34 nScaBins_(
p.getParameter<
int>(
"nScaBins")),
35 doSuppression_(
p.getParameter<
bool>(
"doSuppression")),
36 doCrosstalk_(
p.getParameter<
bool>(
"doCrosstalk")),
37 theStripConditions(nullptr),
38 theCrosstalkGenerator(nullptr),
39 theComparatorClockJump(2),
40 sca_time_bin_size(50.),
41 sca_peak_bin(
p.getParameter<
int>(
"scaPeakBin")),
42 theComparatorTimeBinOffset(
p.getParameter<double>(
"comparatorTimeBinOffset")),
43 theComparatorTimeOffset(
p.getParameter<double>(
"comparatorTimeOffset")),
44 theComparatorSamplingTime(
p.getParameter<double>(
"comparatorSamplingTime")),
45 theSCATimingOffsets(
p.getParameter<
std::
vector<double>>(
"scaTimingOffsets")) {
96 CLHEP::HepRandomEngine *engine)
const {
104 std::list<int> comparatorsWithSignal;
105 CSCSignalMap::iterator signalMapItr;
109 comparatorsWithSignal.push_back(((*signalMapItr).first - 1) / 2);
112 comparatorsWithSignal.unique();
113 for (std::list<int>::iterator listItr = comparatorsWithSignal.begin(); listItr != comparatorsWithSignal.end();
115 int iComparator = *listItr;
126 float comparatorTime =
time;
142 if (height1 > height2) {
143 mainSignal = &signal1;
144 float leftStrip = 0.;
145 if (iComparator > 0) {
151 output = (leftStrip < height2);
152 strip = iComparator * 2 + 1;
155 mainSignal = &signal2;
156 float rightStrip = 0.;
161 output = (height1 < rightStrip);
162 strip = iComparator * 2 + 2;
185 if ((bxFloat >= 0) && (bxFloat < 16))
186 timeWord = (1 << static_cast<int>(bxFloat));
189 result.push_back(newDigi);
195 float resetThreshold = 1;
196 while (time < theSignalStopTime && mainSignal->
getValue(
time) > resetThreshold) {
209 for (std::vector<CSCComparatorDigi>::const_iterator compItr = comparators.begin(); compItr != comparators.end();
212 result.push_back(compItr->getStrip());
240 std::list<int>::const_iterator keyStripItr = keyStrips.begin();
242 for (; keyStripItr != keyStrips.end(); ++keyStripItr) {
244 for (
int istrip = (*keyStripItr) -
window; istrip <= (*keyStripItr) +
window; ++istrip) {
254 std::list<int> cfebsToRead;
255 for (; keyStripItr != keyStrips.end(); ++keyStripItr) {
257 cfebsToRead.push_back(cfeb);
260 if (remainder <
window && cfeb != 0) {
261 cfebsToRead.push_back(cfeb - 1);
265 if (remainder >= 16 -
window && cfeb != maxCFEBs) {
266 cfebsToRead.push_back(cfeb + 1);
270 cfebsToRead.unique();
273 for (std::list<int>::const_iterator cfebItr = cfebsToRead.begin(); cfebItr != cfebsToRead.end(); ++cfebItr) {
274 for (
int i = 1;
i <= 16; ++
i) {
275 result.push_back((*cfebItr) * 16 +
i);
288 CLHEP::HepRandomEngine *engine) {
293 std::vector<CSCComparatorDigi> comparatorOutputs;
296 if (!comparatorOutputs.empty()) {
308 CLHEP::HepRandomEngine *engine) {
310 std::vector<CSCStripDigi> stripDigis;
311 stripDigis.reserve(stripsToDo.size());
312 for (std::list<int>::const_iterator stripItr = stripsToDo.begin(); stripItr != stripsToDo.end(); ++stripItr) {
313 createDigi(*stripItr,
find(*stripItr, engine), stripDigis, engine);
317 digis.put(stripRange,
layerId());
323 std::vector<CSCAnalogSignal> realSignals;
326 for (; mapI != mapEnd; ++mapI) {
327 realSignals.push_back((*mapI).second);
330 std::vector<CSCAnalogSignal>::iterator realSignalItr = realSignals.begin(), realSignalsEnd = realSignals.end();
331 for (; realSignalItr != realSignalsEnd; ++realSignalItr) {
332 int thisStrip = (*realSignalItr).getElement();
335 int otherStrip = thisStrip - 1;
336 addCrosstalk(*realSignalItr, thisStrip, otherStrip, engine);
339 int otherStrip = thisStrip + 1;
340 addCrosstalk(*realSignalItr, thisStrip, otherStrip, engine);
348 CLHEP::HepRandomEngine *engine) {
349 float capacitiveCrosstalk, resistiveCrosstalk;
350 bool leftRight = (otherStrip > thisStrip);
358 crosstalkSignal *= -1.;
364 std::vector<CSCStripDigi> &
result,
365 CLHEP::HepRandomEngine *engine) {
376 for (
int scaBin = 0; scaBin <
nScaBins_; ++scaBin) {
385 result.push_back(newDigi);
387 LogTrace(
"CSCStripElectronicsSim") << newDigi;
392 for (
unsigned scaBin = 0; scaBin < scaCounts.size(); ++scaBin) {
393 scaCounts[scaBin] =
std::min(scaCounts[scaBin], 4095);
401 CLHEP::HepRandomEngine *engine) {
406 std::list<int> chamberKeyStrips;
408 comparatorItr != comparators.end();
412 std::vector<CSCComparatorDigi> layerComparators((*comparatorItr).second.first, (*comparatorItr).second.second);
413 std::list<int> layerKeyStrips =
getKeyStrips(layerComparators);
414 chamberKeyStrips.insert(chamberKeyStrips.end(), layerKeyStrips.begin(), layerKeyStrips.end());
417 chamberKeyStrips.sort();
418 chamberKeyStrips.unique();
424 std::list<int> keyStrips, stripsRead;
432 unsigned int expectedSize = isGanged ? 10 : 12;
433 assert(stripsRead.size() == expectedSize);
436 unsigned int expectedSize = isGanged ? 16 : 48;
437 assert(stripsRead.size() == expectedSize);
438 assert(stripsRead.front() == 1);