CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
CSCBaseElectronicsSim Class Referenceabstract

#include <CSCBaseElectronicsSim.h>

Inheritance diagram for CSCBaseElectronicsSim:
CSCStripElectronicsSim CSCWireElectronicsSim

Public Types

typedef std::map< int, CSCAnalogSignal, std::less< int > > CSCSignalMap
 
typedef edm::DetSet< StripDigiSimLinkDigiSimLinks
 

Public Member Functions

const DigiSimLinksdigiSimLinks () const
 
void setLayerId (const CSCDetId &id)
 for standalone apps who don't calculate it from the geometry More...
 
void simulate (const CSCLayer *layer, const std::vector< CSCDetectorHit > &inputHits, CLHEP::HepRandomEngine *)
 
virtual ~CSCBaseElectronicsSim ()
 

Protected Types

enum  { NONE, CONSERVATIVE, RADICAL }
 
typedef std::multimap< int, CSCDetectorHit, std::less< int > > DetectorHitMap
 

Protected Member Functions

CSCAnalogSignaladd (const CSCAnalogSignal &, CLHEP::HepRandomEngine *)
 
virtual void addLinks (int channelIndex)
 
void addNoise (CLHEP::HepRandomEngine *)
 
CSCAnalogSignal amplifySignal (const CSCDetectorHit &)
 
double averageTimeOfFlight (const DetId &detId) const
 
virtual float calculateAmpResponse (float t) const =0
 
virtual int channelIndex (int channel) const
 lets users map channels to different indices for links More...
 
void combineAnalogSignals (const std::vector< CSCAnalogSignal > &)
 
 CSCBaseElectronicsSim (const edm::ParameterSet &p)
 
void fillAmpResponse ()
 
CSCAnalogSignalfind (int element, CLHEP::HepRandomEngine *)
 
virtual void initParameters ()=0
 
CSCDetId layerId () const
 the CSCDetId corresponding to the current layer More...
 
virtual CSCAnalogSignal makeNoiseSignal (int element, CLHEP::HepRandomEngine *)
 
virtual int readoutElement (int element) const =0
 
void setLayer (const CSCLayer *layer)
 
void setNoise (float rmsNoise, float noiseSigmaThreshold)
 
void setSignalTimeRange (double startTime, double stopTime)
 
virtual float signalDelay (int element, float pos) const
 

Protected Attributes

bool doNoise_
 
int nElements
 
CSCAnalogSignal theAmpResponse
 
float theBunchSpacing
 
std::vector< double > theBunchTimingOffsets
 
DetectorHitMap theDetectorHitMap
 
DigiSimLinks theDigiSimLinks
 
const CSCLayertheLayer
 
const CSCLayerGeometrytheLayerGeometry
 
CSCDetId theLayerId
 
bool theNoiseWasAdded
 
int theNumberOfSamples
 
int theOffsetOfBxZero
 
float thePeakTimeSigma
 
float theSamplingTime
 
int theShapingTime
 
CSCSignalMap theSignalMap
 
std::vector< double > theSignalPropagationSpeed
 
float theSignalStartTime
 
float theSignalStopTime
 
const CSCChamberSpecstheSpecs
 
std::vector< double > theTimingCalibrationError
 

Detailed Description

Commonalities between CSCStripElectronicsSim and CSCWireElectronicsSim.

Author
Rick Wilkinson

It has three non-virtual functions, so that's enough to deserve a new class. And since it has virtual functions it needs a virtual dtor.

Definition at line 37 of file CSCBaseElectronicsSim.h.

Member Typedef Documentation

◆ CSCSignalMap

typedef std::map<int, CSCAnalogSignal, std::less<int> > CSCBaseElectronicsSim::CSCSignalMap

Definition at line 39 of file CSCBaseElectronicsSim.h.

◆ DetectorHitMap

typedef std::multimap<int, CSCDetectorHit, std::less<int> > CSCBaseElectronicsSim::DetectorHitMap
protected

Definition at line 158 of file CSCBaseElectronicsSim.h.

◆ DigiSimLinks

Definition at line 40 of file CSCBaseElectronicsSim.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Constructor & Destructor Documentation

◆ ~CSCBaseElectronicsSim()

CSCBaseElectronicsSim::~CSCBaseElectronicsSim ( )
virtual

Definition at line 38 of file CSCBaseElectronicsSim.cc.

38 {}

◆ CSCBaseElectronicsSim()

CSCBaseElectronicsSim::CSCBaseElectronicsSim ( const edm::ParameterSet p)
protected

Definition at line 15 of file CSCBaseElectronicsSim.cc.

References cms::cuda::assert(), and theBunchTimingOffsets.

16  : theSpecs(nullptr),
17  theLayerGeometry(nullptr),
18  theLayer(nullptr),
19  theSignalMap(),
21  theBunchSpacing(25.),
22  theNoiseWasAdded(false),
23  nElements(0),
24  theShapingTime(p.getParameter<int>("shapingTime")),
25  thePeakTimeSigma(p.getParameter<double>("peakTimeSigma")),
26  theBunchTimingOffsets(p.getParameter<std::vector<double>>("bunchTimingOffsets")),
27  theSignalStartTime(p.getParameter<double>("signalStartTime")),
28  theSignalStopTime(p.getParameter<double>("signalStopTime")),
29  theSamplingTime(p.getParameter<double>("samplingTime")),
31  theOffsetOfBxZero(p.getParameter<int>("timeBitForBxZero")),
32  theSignalPropagationSpeed(p.getParameter<std::vector<double>>("signalSpeed")),
33  theTimingCalibrationError(p.getParameter<std::vector<double>>("timingCalibrationError")),
34  doNoise_(p.getParameter<bool>("doNoise")) {
35  assert(theBunchTimingOffsets.size() == 11);
36 }
std::vector< double > theBunchTimingOffsets
const CSCChamberSpecs * theSpecs
const CSCLayerGeometry * theLayerGeometry
assert(be >=bs)
std::vector< double > theSignalPropagationSpeed
std::vector< double > theTimingCalibrationError

Member Function Documentation

◆ add()

CSCAnalogSignal & CSCBaseElectronicsSim::add ( const CSCAnalogSignal signal,
CLHEP::HepRandomEngine *  engine 
)
protected

Definition at line 151 of file CSCBaseElectronicsSim.cc.

References find(), CSCAnalogSignal::getElement(), and CSCAnalogSignal::superimpose().

Referenced by counter.Counter::register(), and simulate().

151  {
152  int element = signal.getElement();
153  CSCAnalogSignal &newSignal = find(element, engine);
154  newSignal.superimpose(signal);
155  return newSignal;
156 }
void superimpose(const CSCAnalogSignal &signal2)
CSCAnalogSignal & find(int element, CLHEP::HepRandomEngine *)
int getElement() const
constructor from time and amp shape

◆ addLinks()

void CSCBaseElectronicsSim::addLinks ( int  channelIndex)
protectedvirtual

creates links from Digi to SimTrack disabled for now

Definition at line 167 of file CSCBaseElectronicsSim.cc.

References channelIndex(), ALCARECOTkAlJpsiMuMu_cff::charge, edm::DetSet< T >::push_back(), theDetectorHitMap, and theDigiSimLinks.

Referenced by CSCStripElectronicsSim::createDigi(), and CSCWireElectronicsSim::fillDigis().

167  {
168  std::pair<DetectorHitMap::iterator, DetectorHitMap::iterator> channelHitItr =
169  theDetectorHitMap.equal_range(channelIndex);
170 
171  // find the fraction contribution for each SimTrack
172  std::map<int, float> simTrackChargeMap;
173  std::map<int, EncodedEventId> eventIdMap;
174  float totalCharge = 0;
175  for (DetectorHitMap::iterator hitItr = channelHitItr.first; hitItr != channelHitItr.second; ++hitItr) {
176  const PSimHit *hit = hitItr->second.getSimHit();
177  // might be zero for unit tests and such
178  if (hit != nullptr) {
179  int simTrackId = hitItr->second.getSimHit()->trackId();
180  float charge = hitItr->second.getCharge();
181  std::map<int, float>::iterator chargeItr = simTrackChargeMap.find(simTrackId);
182  if (chargeItr == simTrackChargeMap.end()) {
183  simTrackChargeMap[simTrackId] = charge;
184  eventIdMap[simTrackId] = hit->eventId();
185  } else {
186  chargeItr->second += charge;
187  }
188  totalCharge += charge;
189  }
190  }
191 
192  for (std::map<int, float>::iterator chargeItr = simTrackChargeMap.begin(); chargeItr != simTrackChargeMap.end();
193  ++chargeItr) {
194  int simTrackId = chargeItr->first;
196  StripDigiSimLink(channelIndex, simTrackId, eventIdMap[simTrackId], chargeItr->second / totalCharge));
197  }
198 }
void push_back(const T &t)
Definition: DetSet.h:66
virtual int channelIndex(int channel) const
lets users map channels to different indices for links

◆ addNoise()

void CSCBaseElectronicsSim::addNoise ( CLHEP::HepRandomEngine *  engine)
protected

Definition at line 119 of file CSCBaseElectronicsSim.cc.

References makeNoiseSignal(), theNoiseWasAdded, thePeakTimeSigma, theSignalMap, and hgcalLayerClusters_cfi::timeOffset.

Referenced by simulate().

119  {
120  for (CSCSignalMap::iterator mapI = theSignalMap.begin(); mapI != theSignalMap.end(); ++mapI) {
121  // superimpose electronics noise
122  (*mapI).second.superimpose(makeNoiseSignal((*mapI).first, engine));
123  // DON'T do amp gain variations. Handled in strips by calibration code
124  // and variations in the shaper peaking time.
125  double timeOffset = CLHEP::RandGaussQ::shoot(engine, (*mapI).second.getTimeOffset(), thePeakTimeSigma);
126  (*mapI).second.setTimeOffset(timeOffset);
127  }
128  theNoiseWasAdded = true;
129 }
virtual CSCAnalogSignal makeNoiseSignal(int element, CLHEP::HepRandomEngine *)

◆ amplifySignal()

CSCAnalogSignal CSCBaseElectronicsSim::amplifySignal ( const CSCDetectorHit detectorHit)
protected

Definition at line 98 of file CSCBaseElectronicsSim.cc.

References channelIndex(), CSCDetectorHit::getCharge(), CSCDetectorHit::getElement(), CSCDetectorHit::getPosition(), CSCDetectorHit::getTime(), readoutElement(), signalDelay(), theAmpResponse, and theDetectorHitMap.

Referenced by simulate().

98  {
99  int element = readoutElement(detectorHit.getElement());
100 
101  float readoutTime = detectorHit.getTime() + signalDelay(element, detectorHit.getPosition());
102 
103  // start from the amp response, and modify it.
104  CSCAnalogSignal thisSignal(theAmpResponse);
105  thisSignal *= detectorHit.getCharge();
106  thisSignal.setTimeOffset(readoutTime);
107  thisSignal.setElement(element);
108  // keep track of links between digis and hits
109  theDetectorHitMap.insert(DetectorHitMap::value_type(channelIndex(element), detectorHit));
110  return thisSignal;
111 }
float getPosition() const
float getTime() const
virtual int readoutElement(int element) const =0
int getElement() const
float getCharge() const
virtual float signalDelay(int element, float pos) const
virtual int channelIndex(int channel) const
lets users map channels to different indices for links

◆ averageTimeOfFlight()

double CSCBaseElectronicsSim::averageTimeOfFlight ( const DetId detId) const
protected

the average time-of-flight from the interaction point to the given detector

◆ calculateAmpResponse()

virtual float CSCBaseElectronicsSim::calculateAmpResponse ( float  t) const
protectedpure virtual

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by fillAmpResponse().

◆ channelIndex()

virtual int CSCBaseElectronicsSim::channelIndex ( int  channel) const
inlineprotectedvirtual

lets users map channels to different indices for links

Reimplemented in CSCWireElectronicsSim.

Definition at line 101 of file CSCBaseElectronicsSim.h.

Referenced by addLinks(), amplifySignal(), and CSCStripElectronicsSim::createDigi().

101 { return channel; }

◆ combineAnalogSignals()

void CSCBaseElectronicsSim::combineAnalogSignals ( const std::vector< CSCAnalogSignal > &  )
protected

◆ digiSimLinks()

const DigiSimLinks& CSCBaseElectronicsSim::digiSimLinks ( ) const
inline

Definition at line 46 of file CSCBaseElectronicsSim.h.

References theDigiSimLinks.

Referenced by CSCDigitizer::doAction().

46 { return theDigiSimLinks; }

◆ fillAmpResponse()

void CSCBaseElectronicsSim::fillAmpResponse ( )
protected

Definition at line 83 of file CSCBaseElectronicsSim.cc.

References calculateAmpResponse(), mps_fire::i, LogTrace, theAmpResponse, theNumberOfSamples, and theSamplingTime.

Referenced by CSCStripElectronicsSim::CSCStripElectronicsSim(), and CSCWireElectronicsSim::CSCWireElectronicsSim().

83  {
84  std::vector<float> ampBinValues(theNumberOfSamples);
85  int i = 0;
86  for (; i < theNumberOfSamples; ++i) {
87  ampBinValues[i] = calculateAmpResponse(i * theSamplingTime);
88  // truncate any entries that are trivially small
89  if (i > 5 && ampBinValues[i] < 0.000001)
90  break;
91  }
92  ampBinValues.resize(i);
93  theAmpResponse = CSCAnalogSignal(0, theSamplingTime, ampBinValues, 1., 0.);
94 
95  LogTrace("CSCBaseElectronicsSim") << "CSCBaseElectronicsSim: dump of theAmpResponse follows...\n" << theAmpResponse;
96 }
virtual float calculateAmpResponse(float t) const =0
#define LogTrace(id)

◆ find()

CSCAnalogSignal & CSCBaseElectronicsSim::find ( int  element,
CLHEP::HepRandomEngine *  engine 
)
protected

Definition at line 131 of file CSCBaseElectronicsSim.cc.

References LogTrace, makeNoiseSignal(), nElements, theNoiseWasAdded, theNumberOfSamples, theSamplingTime, theSignalMap, and theSignalStartTime.

Referenced by add(), CSCStripElectronicsSim::addCrosstalk(), CSCStripElectronicsSim::fillStripDigis(), and CSCStripElectronicsSim::runComparator().

131  {
132  if (element <= 0 || element > nElements) {
133  LogTrace("CSCBaseElectronicsSim") << "CSCBaseElectronicsSim: bad element = " << element << ". There are "
134  << nElements << " elements.";
135  edm::LogError("Error in CSCBaseElectronicsSim: element out of bounds");
136  }
137  CSCSignalMap::iterator signalMapItr = theSignalMap.find(element);
138  if (signalMapItr == theSignalMap.end()) {
139  CSCAnalogSignal newSignal;
140  if (theNoiseWasAdded) {
141  newSignal = makeNoiseSignal(element, engine);
142  } else {
143  std::vector<float> emptyV(theNumberOfSamples);
144  newSignal = CSCAnalogSignal(element, theSamplingTime, emptyV, 0., theSignalStartTime);
145  }
146  signalMapItr = theSignalMap.insert(std::pair<int, CSCAnalogSignal>(element, newSignal)).first;
147  }
148  return (*signalMapItr).second;
149 }
Log< level::Error, false > LogError
virtual CSCAnalogSignal makeNoiseSignal(int element, CLHEP::HepRandomEngine *)
#define LogTrace(id)

◆ initParameters()

virtual void CSCBaseElectronicsSim::initParameters ( )
protectedpure virtual

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by setLayer().

◆ layerId()

CSCDetId CSCBaseElectronicsSim::layerId ( ) const
inlineprotected

◆ makeNoiseSignal()

CSCAnalogSignal CSCBaseElectronicsSim::makeNoiseSignal ( int  element,
CLHEP::HepRandomEngine *   
)
protectedvirtual

Reimplemented in CSCStripElectronicsSim.

Definition at line 113 of file CSCBaseElectronicsSim.cc.

References theNumberOfSamples, theSamplingTime, and theSignalStartTime.

Referenced by addNoise(), and find().

113  {
114  std::vector<float> binValues(theNumberOfSamples);
115  // default is empty
116  return CSCAnalogSignal(element, theSamplingTime, binValues, 0., theSignalStartTime);
117 }

◆ readoutElement()

virtual int CSCBaseElectronicsSim::readoutElement ( int  element) const
protectedpure virtual

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by amplifySignal(), and simulate().

◆ setLayer()

void CSCBaseElectronicsSim::setLayer ( const CSCLayer layer)
protected

Definition at line 73 of file CSCBaseElectronicsSim.cc.

References GeomDet::geographicalId(), initParameters(), pixelTopology::layer, DetId::rawId(), theLayer, theLayerGeometry, theLayerId, and theSpecs.

Referenced by CSCStripElectronicsSim::fillMissingLayer(), and simulate().

73  {
74  // fill the specs member data
75  theSpecs = layer->chamber()->specs();
76  theLayerGeometry = layer->geometry();
77 
78  theLayer = layer;
81 }
const CSCChamberSpecs * theSpecs
const CSCLayerGeometry * theLayerGeometry
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual void initParameters()=0

◆ setLayerId()

void CSCBaseElectronicsSim::setLayerId ( const CSCDetId id)
inline

for standalone apps who don't calculate it from the geometry

Definition at line 51 of file CSCBaseElectronicsSim.h.

References l1ctLayer2EG_cff::id, and theLayerId.

◆ setNoise()

void CSCBaseElectronicsSim::setNoise ( float  rmsNoise,
float  noiseSigmaThreshold 
)
protected

◆ setSignalTimeRange()

void CSCBaseElectronicsSim::setSignalTimeRange ( double  startTime,
double  stopTime 
)
inlineprotected

How long before & after the bunch crossing to simulate shortening the time can save CPU

Definition at line 77 of file CSCBaseElectronicsSim.h.

References BeamSpotPI::startTime, theSignalStartTime, and theSignalStopTime.

◆ signalDelay()

float CSCBaseElectronicsSim::signalDelay ( int  element,
float  pos 
) const
protectedvirtual

how long, in ns, it takes a signal at pos to propagate to the readout edge. This may be negative, since the timing may be calibrated to the center of the detector

Definition at line 158 of file CSCBaseElectronicsSim.cc.

References CSCChamberSpecs::chamberType(), HLT_2022v15_cff::distance, HLTSiStripMonitoring_cff::speed, theSignalPropagationSpeed, and theSpecs.

Referenced by amplifySignal().

158  {
159  // readout is on top edge of chamber for strips, right edge
160  // for wires.
161  // zero calibrated to chamber center
162  float distance = -1. * pos;
164  return distance / speed;
165 }
int chamberType() const
const CSCChamberSpecs * theSpecs
std::vector< double > theSignalPropagationSpeed

◆ simulate()

void CSCBaseElectronicsSim::simulate ( const CSCLayer layer,
const std::vector< CSCDetectorHit > &  inputHits,
CLHEP::HepRandomEngine *  engine 
)

Definition at line 40 of file CSCBaseElectronicsSim.cc.

References add(), addNoise(), amplifySignal(), doNoise_, AlCaHLTBitMon_QueryRunRegistry::getElement(), mps_fire::i, pixelTopology::layer, layerId(), nHits, readoutElement(), setLayer(), theDetectorHitMap, theDigiSimLinks, theNoiseWasAdded, and theSignalMap.

Referenced by CSCDigitizer::doAction().

42  {
43  theNoiseWasAdded = false;
44 
45  {
46  theSignalMap.clear();
47  theDetectorHitMap.clear();
48  setLayer(layer);
49  // can we swap for efficiency?
51  }
52 
53  {
54  size_t nHits = detectorHits.size();
55  // turn each detector hit into an analog signal
56  for (size_t i = 0; i < nHits; ++i) {
57  int element = readoutElement(detectorHits[i].getElement());
58 
59  // skip if hit element is not part of a readout element
60  // e.g. wire in non-readout group
61  if (element != 0)
62  add(amplifySignal(detectorHits[i]), engine);
63  }
64  }
65 
66  {
67  if (doNoise_) {
68  addNoise(engine);
69  }
70  }
71 }
CSCDetId layerId() const
the CSCDetId corresponding to the current layer
CSCAnalogSignal amplifySignal(const CSCDetectorHit &)
void setLayer(const CSCLayer *layer)
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
edm::DetSet< StripDigiSimLink > DigiSimLinks
virtual int readoutElement(int element) const =0
void addNoise(CLHEP::HepRandomEngine *)
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
CSCAnalogSignal & add(const CSCAnalogSignal &, CLHEP::HepRandomEngine *)

Member Data Documentation

◆ doNoise_

bool CSCBaseElectronicsSim::doNoise_
protected

◆ nElements

int CSCBaseElectronicsSim::nElements
protected

◆ theAmpResponse

CSCAnalogSignal CSCBaseElectronicsSim::theAmpResponse
protected

Definition at line 119 of file CSCBaseElectronicsSim.h.

Referenced by amplifySignal(), and fillAmpResponse().

◆ theBunchSpacing

float CSCBaseElectronicsSim::theBunchSpacing
protected

◆ theBunchTimingOffsets

std::vector<double> CSCBaseElectronicsSim::theBunchTimingOffsets
protected

◆ theDetectorHitMap

DetectorHitMap CSCBaseElectronicsSim::theDetectorHitMap
protected

◆ theDigiSimLinks

DigiSimLinks CSCBaseElectronicsSim::theDigiSimLinks
protected

Definition at line 160 of file CSCBaseElectronicsSim.h.

Referenced by addLinks(), digiSimLinks(), and simulate().

◆ theLayer

const CSCLayer* CSCBaseElectronicsSim::theLayer
protected

◆ theLayerGeometry

const CSCLayerGeometry* CSCBaseElectronicsSim::theLayerGeometry
protected

◆ theLayerId

CSCDetId CSCBaseElectronicsSim::theLayerId
protected

◆ theNoiseWasAdded

bool CSCBaseElectronicsSim::theNoiseWasAdded
protected

Definition at line 127 of file CSCBaseElectronicsSim.h.

Referenced by addNoise(), find(), and simulate().

◆ theNumberOfSamples

int CSCBaseElectronicsSim::theNumberOfSamples
protected

◆ theOffsetOfBxZero

int CSCBaseElectronicsSim::theOffsetOfBxZero
protected

◆ thePeakTimeSigma

float CSCBaseElectronicsSim::thePeakTimeSigma
protected

Definition at line 134 of file CSCBaseElectronicsSim.h.

Referenced by addNoise().

◆ theSamplingTime

float CSCBaseElectronicsSim::theSamplingTime
protected

◆ theShapingTime

int CSCBaseElectronicsSim::theShapingTime
protected

◆ theSignalMap

CSCSignalMap CSCBaseElectronicsSim::theSignalMap
protected

◆ theSignalPropagationSpeed

std::vector<double> CSCBaseElectronicsSim::theSignalPropagationSpeed
protected

Speed (cm/ns) that it takes for the signal to get from the element to the readout. Actually negative in strips, due to reflection effects.

Definition at line 153 of file CSCBaseElectronicsSim.h.

Referenced by signalDelay().

◆ theSignalStartTime

float CSCBaseElectronicsSim::theSignalStartTime
protected

◆ theSignalStopTime

float CSCBaseElectronicsSim::theSignalStopTime
protected

◆ theSpecs

const CSCChamberSpecs* CSCBaseElectronicsSim::theSpecs
protected

◆ theTimingCalibrationError

std::vector<double> CSCBaseElectronicsSim::theTimingCalibrationError
protected