13 #include "CLHEP/Random/RandGaussQ.h"
14 #include "CLHEP/Units/GlobalPhysicalConstants.h"
15 #include "CLHEP/Units/GlobalSystemOfUnits.h"
17 #include <boost/bind/bind.hpp>
21 using namespace boost::placeholders;
28 theComparatorThreshold(20.),
29 theComparatorNoise(0.),
30 theComparatorRMSOffset(2.),
31 theComparatorSaturation(1057.),
32 theComparatorWait(50.),
33 theComparatorDeadTime(100.),
36 nScaBins_(
p.getParameter<
int>(
"nScaBins")),
37 doSuppression_(
p.getParameter<
bool>(
"doSuppression")),
38 doCrosstalk_(
p.getParameter<
bool>(
"doCrosstalk")),
39 theStripConditions(nullptr),
40 theCrosstalkGenerator(nullptr),
41 theComparatorClockJump(2),
42 sca_time_bin_size(50.),
43 sca_peak_bin(
p.getParameter<
int>(
"scaPeakBin")),
44 theComparatorTimeBinOffset(
p.getParameter<double>(
"comparatorTimeBinOffset")),
45 theComparatorTimeOffset(
p.getParameter<double>(
"comparatorTimeOffset")),
46 theComparatorSamplingTime(
p.getParameter<double>(
"comparatorSamplingTime")),
47 theSCATimingOffsets(
p.getParameter<
std::
vector<double>>(
"scaTimingOffsets")) {
98 CLHEP::HepRandomEngine *engine)
const {
106 std::list<int> comparatorsWithSignal;
107 CSCSignalMap::iterator signalMapItr;
111 comparatorsWithSignal.push_back(((*signalMapItr).first - 1) / 2);
114 comparatorsWithSignal.unique();
115 for (std::list<int>::iterator listItr = comparatorsWithSignal.begin(); listItr != comparatorsWithSignal.end();
117 int iComparator = *listItr;
128 float comparatorTime =
time;
144 if (height1 > height2) {
145 mainSignal = &signal1;
146 float leftStrip = 0.;
147 if (iComparator > 0) {
153 output = (leftStrip < height2);
154 strip = iComparator * 2 + 1;
157 mainSignal = &signal2;
158 float rightStrip = 0.;
163 output = (height1 < rightStrip);
164 strip = iComparator * 2 + 2;
187 if ((bxFloat >= 0) && (bxFloat < 16))
188 timeWord = (1 << static_cast<int>(bxFloat));
191 result.push_back(newDigi);
197 float resetThreshold = 1;
198 while (time < theSignalStopTime && mainSignal->
getValue(
time) > resetThreshold) {
211 for (std::vector<CSCComparatorDigi>::const_iterator compItr = comparators.begin(); compItr != comparators.end();
214 result.push_back(compItr->getStrip());
242 std::list<int>::const_iterator keyStripItr = keyStrips.begin();
244 for (; keyStripItr != keyStrips.end(); ++keyStripItr) {
246 for (
int istrip = (*keyStripItr) -
window; istrip <= (*keyStripItr) +
window; ++istrip) {
256 std::list<int> cfebsToRead;
257 for (; keyStripItr != keyStrips.end(); ++keyStripItr) {
259 cfebsToRead.push_back(cfeb);
262 if (remainder <
window && cfeb != 0) {
263 cfebsToRead.push_back(cfeb - 1);
267 if (remainder >= 16 -
window && cfeb != maxCFEBs) {
268 cfebsToRead.push_back(cfeb + 1);
272 cfebsToRead.unique();
275 for (std::list<int>::const_iterator cfebItr = cfebsToRead.begin(); cfebItr != cfebsToRead.end(); ++cfebItr) {
276 for (
int i = 1;
i <= 16; ++
i) {
277 result.push_back((*cfebItr) * 16 +
i);
290 CLHEP::HepRandomEngine *engine) {
295 std::vector<CSCComparatorDigi> comparatorOutputs;
298 if (!comparatorOutputs.empty()) {
310 CLHEP::HepRandomEngine *engine) {
312 std::vector<CSCStripDigi> stripDigis;
313 stripDigis.reserve(stripsToDo.size());
314 for (std::list<int>::const_iterator stripItr = stripsToDo.begin(); stripItr != stripsToDo.end(); ++stripItr) {
315 createDigi(*stripItr,
find(*stripItr, engine), stripDigis, engine);
319 digis.put(stripRange,
layerId());
325 std::vector<CSCAnalogSignal> realSignals;
328 for (; mapI != mapEnd; ++mapI) {
329 realSignals.push_back((*mapI).second);
332 std::vector<CSCAnalogSignal>::iterator realSignalItr = realSignals.begin(), realSignalsEnd = realSignals.end();
333 for (; realSignalItr != realSignalsEnd; ++realSignalItr) {
334 int thisStrip = (*realSignalItr).getElement();
337 int otherStrip = thisStrip - 1;
338 addCrosstalk(*realSignalItr, thisStrip, otherStrip, engine);
341 int otherStrip = thisStrip + 1;
342 addCrosstalk(*realSignalItr, thisStrip, otherStrip, engine);
350 CLHEP::HepRandomEngine *engine) {
351 float capacitiveCrosstalk, resistiveCrosstalk;
352 bool leftRight = (otherStrip > thisStrip);
360 crosstalkSignal *= -1.;
366 std::vector<CSCStripDigi> &
result,
367 CLHEP::HepRandomEngine *engine) {
378 for (
int scaBin = 0; scaBin <
nScaBins_; ++scaBin) {
387 result.push_back(newDigi);
389 LogTrace(
"CSCStripElectronicsSim") <<
"CSCStripElectronicsSim: CSCStripDigi " << newDigi;
394 for (
unsigned scaBin = 0; scaBin < scaCounts.size(); ++scaBin) {
395 scaCounts[scaBin] =
std::min(scaCounts[scaBin], 4095);
403 CLHEP::HepRandomEngine *engine) {
408 std::list<int> chamberKeyStrips;
410 comparatorItr != comparators.end();
414 std::vector<CSCComparatorDigi> layerComparators((*comparatorItr).second.first, (*comparatorItr).second.second);
415 std::list<int> layerKeyStrips =
getKeyStrips(layerComparators);
416 chamberKeyStrips.insert(chamberKeyStrips.end(), layerKeyStrips.begin(), layerKeyStrips.end());
419 chamberKeyStrips.sort();
420 chamberKeyStrips.unique();
426 std::list<int> keyStrips, stripsRead;
434 unsigned int expectedSize = isGanged ? 10 : 12;
435 assert(stripsRead.size() == expectedSize);
438 unsigned int expectedSize = isGanged ? 16 : 48;
439 assert(stripsRead.size() == expectedSize);
440 assert(stripsRead.front() == 1);