13 #include "CLHEP/Units/GlobalPhysicalConstants.h"
14 #include "CLHEP/Units/GlobalSystemOfUnits.h"
15 #include "CLHEP/Random/RandGaussQ.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(0),
38 theCrosstalkGenerator(0),
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"))
111 CLHEP::HepRandomEngine* engine)
const {
121 std::list<int> comparatorsWithSignal;
122 CSCSignalMap::iterator signalMapItr;
127 comparatorsWithSignal.push_back( ((*signalMapItr).first-1)/2 );
130 comparatorsWithSignal.unique();
131 for(std::list<int>::iterator listItr = comparatorsWithSignal.begin();
132 listItr != comparatorsWithSignal.end(); ++listItr) {
133 int iComparator = *listItr;
146 float comparatorTime =
time;
162 if(height1 > height2) {
163 mainSignal = &signal1;
164 float leftStrip = 0.;
165 if(iComparator > 0) {
170 output = (leftStrip < height2);
171 strip = iComparator*2 + 1;
174 mainSignal = &signal2;
175 float rightStrip = 0.;
180 output = (height1 < rightStrip);
181 strip = iComparator*2 + 2;
204 if ( (bxFloat>= 0) && (bxFloat<16) )
205 timeWord = (1 <<
static_cast<int>(bxFloat) );
208 result.push_back(newDigi);
214 float resetThreshold = 1;
224 sort(result.begin(), result.end());
232 for(std::vector<CSCComparatorDigi>::const_iterator compItr = comparators.begin();
233 compItr != comparators.end(); ++compItr)
237 result.push_back(compItr->getStrip());
264 std::list<int>::const_iterator keyStripItr = keyStrips.begin();
267 for( ; keyStripItr != keyStrips.end(); ++keyStripItr)
270 for(
int istrip = (*keyStripItr)-
window; istrip <= (*keyStripItr)+
window; ++istrip)
284 std::list<int> cfebsToRead;
285 for( ; keyStripItr != keyStrips.end(); ++keyStripItr)
288 cfebsToRead.push_back(cfeb);
291 if(remainder < window && cfeb != 0)
293 cfebsToRead.push_back(cfeb-1);
297 if(remainder >= 16-window && cfeb != maxCFEBs)
299 cfebsToRead.push_back(cfeb+1);
303 cfebsToRead.unique();
306 for(std::list<int>::const_iterator cfebItr = cfebsToRead.begin();
307 cfebItr != cfebsToRead.end(); ++cfebItr)
309 for(
int i = 1;
i <= 16; ++
i)
311 result.push_back((*cfebItr)*16 +
i);
329 CLHEP::HepRandomEngine* engine)
335 std::vector<CSCComparatorDigi> comparatorOutputs;
338 if(!comparatorOutputs.empty())
341 comparatorOutputs.end());
342 comparators.put(range,
layerId());
353 CLHEP::HepRandomEngine* engine)
356 std::vector<CSCStripDigi> stripDigis;
357 stripDigis.reserve(stripsToDo.size());
358 for(std::list<int>::const_iterator stripItr = stripsToDo.begin();
359 stripItr != stripsToDo.end(); ++stripItr)
361 createDigi( *stripItr,
find(*stripItr, engine), stripDigis, engine);
365 digis.put(stripRange,
layerId());
372 std::vector<CSCAnalogSignal> realSignals;
375 for( ; mapI != mapEnd; ++mapI) {
376 realSignals.push_back((*mapI).second);
379 std::vector<CSCAnalogSignal>::iterator realSignalItr = realSignals.begin(),
380 realSignalsEnd = realSignals.end();
381 for( ; realSignalItr != realSignalsEnd; ++realSignalItr)
383 int thisStrip = (*realSignalItr).getElement();
386 int otherStrip = thisStrip - 1;
387 addCrosstalk(*realSignalItr, thisStrip, otherStrip, engine);
390 int otherStrip = thisStrip + 1;
391 addCrosstalk(*realSignalItr, thisStrip, otherStrip, engine);
398 int thisStrip,
int otherStrip,
399 CLHEP::HepRandomEngine* engine)
401 float capacitiveCrosstalk, resistiveCrosstalk;
402 bool leftRight = (otherStrip > thisStrip);
405 capacitiveCrosstalk, resistiveCrosstalk);
411 crosstalkSignal *= -1.;
418 CLHEP::HepRandomEngine* engine)
431 for(
int scaBin = 0; scaBin <
nScaBins_; ++scaBin) {
433 scaCounts[scaBin] =
static_cast< int >
434 ( pedestal + signal.
getValue(t) * gain );
441 result.push_back(newDigi);
443 LogTrace(
"CSCStripElectronicsSim") << newDigi;
450 for(
unsigned scaBin = 0; scaBin < scaCounts.size(); ++scaBin) {
451 scaCounts[scaBin] =
std::min(scaCounts[scaBin], 4095);
460 CLHEP::HepRandomEngine* engine)
466 std::list<int> chamberKeyStrips;
468 comparatorItr != comparators.end(); ++comparatorItr)
471 if(
CSCDetId((*comparatorItr).first).chamberId() == chamberId)
473 std::vector<CSCComparatorDigi> layerComparators((*comparatorItr).second.first, (*comparatorItr).second.second);
474 std::list<int> layerKeyStrips =
getKeyStrips(layerComparators);
475 chamberKeyStrips.insert(chamberKeyStrips.end(), layerKeyStrips.begin(), layerKeyStrips.end());
478 chamberKeyStrips.sort();
479 chamberKeyStrips.unique();
487 std::list<int> keyStrips, stripsRead;
496 unsigned int expectedSize = isGanged ? 10 : 12;
497 assert(stripsRead.size() == expectedSize);
502 unsigned int expectedSize = isGanged ? 16 : 48;
503 assert(stripsRead.size() == expectedSize);
504 assert(stripsRead.front() == 1);
std::vector< double > theBunchTimingOffsets
const CSCLayer * theLayer
const CSCChamberSpecs * theSpecs
CSCSignalMap theSignalMap
const CSCLayerGeometry * theLayerGeometry
bool SortSignalsByTotal(const CSCAnalogSignal &s1, const CSCAnalogSignal &s2)
std::vector< int > const & getADCCounts() const
Get ADC readings.
double theComparatorTimeOffset
virtual float pedestal(const CSCDetId &detId, int channel) const =0
in ADC counts
std::list< int > getKeyStripsFromMC() const
get ths strips that have detector hits
void addCrosstalk(CLHEP::HepRandomEngine *)
float calculateAmpResponse(float t) const
virtual void crosstalk(const CSCDetId &detId, int channel, double stripLength, bool leftRight, float &capacitive, float &resistive) const =0
void runComparator(std::vector< CSCComparatorDigi > &result, CLHEP::HepRandomEngine *)
float theComparatorDeadTime
int numberOfStrips() const
const Plane & surface() const
The nominal surface of the GeomDet.
void setADCCounts(const std::vector< int > &ADCCounts)
CSCStripConditions * theStripConditions
virtual ~CSCStripElectronicsSim()
void setLayer(const CSCLayer *layer)
float comparatorReading(const CSCAnalogSignal &signal, float time, CLHEP::HepRandomEngine *) const
calculates the comparator reading, including saturation and offsets
std::vector< double > theSCATimingOffsets
std::list< int > channelsToRead(const std::list< int > &keyStrips, int window) const
float theComparatorRMSOffset
void noisify(const CSCDetId &detId, CSCAnalogSignal &signal, CLHEP::HepRandomEngine *)
superimposes noise, in fC, on the signal
Abs< T >::type abs(const T &t)
CSCAnalogSignal makeNoiseSignal(int element, CLHEP::HepRandomEngine *) override
CSCDetId chamberId() const
void fillMissingLayer(const CSCLayer *layer, const CSCComparatorDigiCollection &comparators, CSCStripDigiCollection &digis, CLHEP::HepRandomEngine *)
CSCCrosstalkGenerator * theCrosstalkGenerator
void superimpose(const CSCAnalogSignal &signal2)
void initParameters()
initialization for each layer
void doSaturation(CSCStripDigi &digi)
int channel(int strip) const
float theComparatorThreshold
float calculateAmpResponse(float t) const
virtual void addLinks(int channelIndex)
DetectorHitMap theDetectorHitMap
CSCStripElectronicsSim(const edm::ParameterSet &p)
configurable parameters
double theComparatorTimeBinOffset
void setParameters(float crosstalk, float delay, float resistiveFraction)
std::list< int > getKeyStrips(const std::vector< CSCComparatorDigi > &comparators) const
finds the key strips from these comparators
CSCAnalogSignal getCrosstalk(const CSCAnalogSignal &inputSignal) const
float theComparatorSaturation
virtual int readoutElement(int strip) const
CSCDetId layerId() const
the CSCDetId corresponding to the current layer
double theComparatorSamplingTime
CSCAnalogSignal & find(int element, CLHEP::HepRandomEngine *)
void fillDigis(CSCStripDigiCollection &digis, CSCComparatorDigiCollection &comparators, CLHEP::HepRandomEngine *)
float theAverageTimeOfFlight
float getValue(float t) const
virtual float smearedGain(const CSCDetId &detId, int channel, CLHEP::HepRandomEngine *) const
virtual int channelIndex(int channel) const
lets users map channels to different indices for links
std::pair< const_iterator, const_iterator > Range
virtual float length() const
const PositionType & position() const
CSCStripAmpResponse theAmpResponse
void createDigi(int istrip, const CSCAnalogSignal &signal, std::vector< CSCStripDigi > &result, CLHEP::HepRandomEngine *)
void fillStripDigis(const std::list< int > &keyStrips, CSCStripDigiCollection &digis, CLHEP::HepRandomEngine *)
std::vector< double > theTimingCalibrationError