CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
< StripDigiSimLink
DigiSimLinks
 

Public Member Functions

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

Protected Types

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

Protected Member Functions

CSCAnalogSignaladd (const CSCAnalogSignal &)
 
virtual void addLinks (int channelIndex)
 
void addNoise ()
 
CSCAnalogSignal amplifySignal (const CSCDetectorHit &)
 
double averageTimeOfFlight (const DetId &detId) const
 the average time-of-flight from the interaction point to the given detector More...
 
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)
 
virtual void initParameters ()=0
 
CSCDetId layerId () const
 the CSCDetId corresponding to the current layer More...
 
virtual CSCAnalogSignal makeNoiseSignal (int element)
 
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
 
CLHEP::RandGaussQ * theRandGaussQ
 
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 34 of file CSCBaseElectronicsSim.h.

Member Typedef Documentation

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

Definition at line 38 of file CSCBaseElectronicsSim.h.

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

Definition at line 159 of file CSCBaseElectronicsSim.h.

Definition at line 39 of file CSCBaseElectronicsSim.h.

Member Enumeration Documentation

anonymous enum
protected

Constructor & Destructor Documentation

CSCBaseElectronicsSim::~CSCBaseElectronicsSim ( )
virtual

Definition at line 40 of file CSCBaseElectronicsSim.cc.

References theRandGaussQ.

41 {
42  delete theRandGaussQ;
43 }
CLHEP::RandGaussQ * theRandGaussQ
CSCBaseElectronicsSim::CSCBaseElectronicsSim ( const edm::ParameterSet p)
protected

Definition at line 13 of file CSCBaseElectronicsSim.cc.

References theBunchTimingOffsets.

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

Member Function Documentation

CSCAnalogSignal & CSCBaseElectronicsSim::add ( const CSCAnalogSignal signal)
protected

Definition at line 176 of file CSCBaseElectronicsSim.cc.

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

Referenced by simulate().

176  {
177  int element = signal.getElement();
178  CSCAnalogSignal & newSignal = find(element);
179  newSignal.superimpose(signal);
180  return newSignal;
181 }
int getElement() const
constructor from time and amp shape
void superimpose(const CSCAnalogSignal &signal2)
CSCAnalogSignal & find(int element)
void CSCBaseElectronicsSim::addLinks ( int  channelIndex)
protectedvirtual

creates links from Digi to SimTrack disabled for now

Definition at line 194 of file CSCBaseElectronicsSim.cc.

References DeDxDiscriminatorTools::charge(), PSimHit::eventId(), edm::DetSet< T >::push_back(), theDetectorHitMap, and theDigiSimLinks.

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

194  {
195  std::pair<DetectorHitMap::iterator, DetectorHitMap::iterator> channelHitItr
196  = theDetectorHitMap.equal_range(channelIndex);
197 
198  // find the fraction contribution for each SimTrack
199  std::map<int,float> simTrackChargeMap;
200  std::map<int, EncodedEventId> eventIdMap;
201  float totalCharge = 0;
202  for( DetectorHitMap::iterator hitItr = channelHitItr.first;
203  hitItr != channelHitItr.second; ++hitItr){
204  const PSimHit * hit = hitItr->second.getSimHit();
205  // might be zero for unit tests and such
206  if(hit != 0) {
207  int simTrackId = hitItr->second.getSimHit()->trackId();
208  float charge = hitItr->second.getCharge();
209  std::map<int,float>::iterator chargeItr = simTrackChargeMap.find(simTrackId);
210  if( chargeItr == simTrackChargeMap.end() ) {
211  simTrackChargeMap[simTrackId] = charge;
212  eventIdMap[simTrackId] = hit->eventId();
213  } else {
214  chargeItr->second += charge;
215  }
216  totalCharge += charge;
217  }
218  }
219 
220  for(std::map<int,float>::iterator chargeItr = simTrackChargeMap.begin();
221  chargeItr != simTrackChargeMap.end(); ++chargeItr) {
222  int simTrackId = chargeItr->first;
224  eventIdMap[simTrackId], chargeItr->second/totalCharge ) );
225 
226  }
227 }
void push_back(const T &t)
Definition: DetSet.h:69
double charge(const std::vector< uint8_t > &Ampls)
EncodedEventId eventId() const
Definition: PSimHit.h:105
virtual int channelIndex(int channel) const
lets users map channels to different indices for links
void CSCBaseElectronicsSim::addNoise ( )
protected

Definition at line 141 of file CSCBaseElectronicsSim.cc.

References makeNoiseSignal(), theNoiseWasAdded, thePeakTimeSigma, theRandGaussQ, and theSignalMap.

Referenced by simulate().

141  {
142  for(CSCSignalMap::iterator mapI = theSignalMap.begin();
143  mapI!= theSignalMap.end(); ++mapI) {
144  // superimpose electronics noise
145  (*mapI).second.superimpose(makeNoiseSignal((*mapI).first));
146  // DON'T do amp gain variations. Handled in strips by calibration code
147  // and variations in the shaper peaking time.
148  double timeOffset = theRandGaussQ->fire((*mapI).second.getTimeOffset(), thePeakTimeSigma);
149  (*mapI).second.setTimeOffset(timeOffset);
150  }
151  theNoiseWasAdded = true;
152 }
virtual CSCAnalogSignal makeNoiseSignal(int element)
CLHEP::RandGaussQ * theRandGaussQ
CSCAnalogSignal CSCBaseElectronicsSim::amplifySignal ( const CSCDetectorHit detectorHit)
protected

Definition at line 117 of file CSCBaseElectronicsSim.cc.

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

Referenced by simulate().

117  {
118  int element = readoutElement(detectorHit.getElement());
119 
120  float readoutTime = detectorHit.getTime()
121  + signalDelay(element, detectorHit.getPosition());
122 
123  // start from the amp response, and modify it.
124  CSCAnalogSignal thisSignal(theAmpResponse);
125  thisSignal *= detectorHit.getCharge();
126  thisSignal.setTimeOffset(readoutTime);
127  thisSignal.setElement(element);
128  // keep track of links between digis and hits
129  theDetectorHitMap.insert( DetectorHitMap::value_type(channelIndex(element), detectorHit) );
130  return thisSignal;
131 }
float getPosition() const
int getElement() const
virtual float signalDelay(int element, float pos) const
float getCharge() const
float getTime() const
virtual int readoutElement(int element) const =0
Container::value_type value_type
virtual int channelIndex(int channel) const
lets users map channels to different indices for links
double CSCBaseElectronicsSim::averageTimeOfFlight ( const DetId detId) const
protected

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

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

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by fillAmpResponse().

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

lets users map channels to different indices for links

Reimplemented in CSCWireElectronicsSim.

Definition at line 103 of file CSCBaseElectronicsSim.h.

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

103 {return channel;}
void CSCBaseElectronicsSim::combineAnalogSignals ( const std::vector< CSCAnalogSignal > &  )
protected
const DigiSimLinks& CSCBaseElectronicsSim::digiSimLinks ( ) const
inline

Definition at line 48 of file CSCBaseElectronicsSim.h.

References theDigiSimLinks.

Referenced by CSCDigitizer::doAction().

48 {return theDigiSimLinks;}
void CSCBaseElectronicsSim::fillAmpResponse ( )
protected

Definition at line 98 of file CSCBaseElectronicsSim.cc.

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

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

98  {
99  std::vector<float> ampBinValues(theNumberOfSamples);
100  int i = 0;
101  for( ; i < theNumberOfSamples; ++i) {
102  ampBinValues[i] = calculateAmpResponse(i*theSamplingTime);
103  // truncate any entries that are trivially small
104  if(i>5 && ampBinValues[i] < 0.000001) break;
105  }
106  ampBinValues.resize(i);
107  theAmpResponse = CSCAnalogSignal(0, theSamplingTime, ampBinValues, 1., 0.);
108 
109  LogTrace("CSCBaseElectronicsSim") <<
110  "CSCBaseElectronicsSim: dump of theAmpResponse follows...\n"
111  << theAmpResponse;
112 }
int i
Definition: DBlmapReader.cc:9
virtual float calculateAmpResponse(float t) const =0
#define LogTrace(id)
CSCAnalogSignal & CSCBaseElectronicsSim::find ( int  element)
protected

Definition at line 155 of file CSCBaseElectronicsSim.cc.

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

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

155  {
156  if(element <= 0 || element > nElements) {
157  LogTrace("CSCBaseElectronicsSim") << "CSCBaseElectronicsSim: bad element = " << element <<
158  ". There are " << nElements << " elements.";
159  edm::LogError("Error in CSCBaseElectronicsSim: element out of bounds");
160  }
161  CSCSignalMap::iterator signalMapItr = theSignalMap.find(element);
162  if(signalMapItr == theSignalMap.end()) {
163  CSCAnalogSignal newSignal;
164  if(theNoiseWasAdded) {
165  newSignal = makeNoiseSignal(element);
166  } else {
167  std::vector<float> emptyV(theNumberOfSamples);
168  newSignal = CSCAnalogSignal(element, theSamplingTime, emptyV, 0., theSignalStartTime);
169  }
170  signalMapItr = theSignalMap.insert( std::pair<int, CSCAnalogSignal>(element, newSignal) ).first;
171  }
172  return (*signalMapItr).second;
173 }
virtual CSCAnalogSignal makeNoiseSignal(int element)
#define LogTrace(id)
virtual void CSCBaseElectronicsSim::initParameters ( )
protectedpure virtual

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by setLayer().

CSCDetId CSCBaseElectronicsSim::layerId ( ) const
inlineprotected
CSCAnalogSignal CSCBaseElectronicsSim::makeNoiseSignal ( int  element)
protectedvirtual

Reimplemented in CSCStripElectronicsSim.

Definition at line 134 of file CSCBaseElectronicsSim.cc.

References theNumberOfSamples, theSamplingTime, and theSignalStartTime.

Referenced by addNoise(), and find().

134  {
135  std::vector<float> binValues(theNumberOfSamples);
136  // default is empty
137  return CSCAnalogSignal(element, theSamplingTime, binValues, 0., theSignalStartTime);
138 }
virtual int CSCBaseElectronicsSim::readoutElement ( int  element) const
protectedpure virtual

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by amplifySignal(), and simulate().

void CSCBaseElectronicsSim::setLayer ( const CSCLayer layer)
protected

Definition at line 86 of file CSCBaseElectronicsSim.cc.

References CSCLayer::chamber(), CSCDetId, GeomDet::geographicalId(), CSCLayer::geometry(), initParameters(), DetId::rawId(), CSCChamber::specs(), theLayer, theLayerGeometry, theLayerId, and theSpecs.

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

87 {
88  // fill the specs member data
89  theSpecs = layer->chamber()->specs();
90  theLayerGeometry = layer->geometry();
91 
92  theLayer = layer;
95 }
const CSCChamberSpecs * theSpecs
const CSCLayerGeometry * theLayerGeometry
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const CSCChamberSpecs * specs() const
Definition: CSCChamber.h:42
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
virtual void initParameters()=0
const CSCChamber * chamber() const
Definition: CSCLayer.h:52
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
void CSCBaseElectronicsSim::setLayerId ( const CSCDetId id)
inline

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

Definition at line 53 of file CSCBaseElectronicsSim.h.

References errorMatrix2Lands_multiChannel::id, and theLayerId.

void CSCBaseElectronicsSim::setNoise ( float  rmsNoise,
float  noiseSigmaThreshold 
)
protected
void CSCBaseElectronicsSim::setRandomEngine ( CLHEP::HepRandomEngine &  engine)

Definition at line 46 of file CSCBaseElectronicsSim.cc.

References theRandGaussQ.

Referenced by CSCDigitizer::setRandomEngine().

47 {
48  if(theRandGaussQ) delete theRandGaussQ;
49  theRandGaussQ = new CLHEP::RandGaussQ(engine);
50 }
CLHEP::RandGaussQ * theRandGaussQ
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 79 of file CSCBaseElectronicsSim.h.

References theSignalStartTime, and theSignalStopTime.

79  {
80  theSignalStartTime = startTime;
81  theSignalStopTime = stopTime;
82  }
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 184 of file CSCBaseElectronicsSim.cc.

References CSCChamberSpecs::chamberType(), pos, theSignalPropagationSpeed, and theSpecs.

Referenced by amplifySignal().

184  {
185  // readout is on top edge of chamber for strips, right edge
186  // for wires.
187  // zero calibrated to chamber center
188  float distance = -1. * pos;
190  return distance / speed;
191 }
const CSCChamberSpecs * theSpecs
std::vector< double > theSignalPropagationSpeed
int chamberType() const
void CSCBaseElectronicsSim::simulate ( const CSCLayer layer,
const std::vector< CSCDetectorHit > &  inputHits 
)

Definition at line 53 of file CSCBaseElectronicsSim.cc.

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

Referenced by CSCDigitizer::doAction().

55 {
56  theNoiseWasAdded = false;
57 
58  {
59  theSignalMap.clear();
60  theDetectorHitMap.clear();
61  setLayer(layer);
62  // can we swap for efficiency?
64  }
65 
66  {
67  size_t nHits = detectorHits.size();
68  // turn each detector hit into an analog signal
69  for( size_t i = 0; i < nHits; ++i) {
70  int element = readoutElement( detectorHits[i].getElement() );
71 
72  // skip if hit element is not part of a readout element
73  // e.g. wire in non-readout group
74  if ( element != 0 ) add( amplifySignal(detectorHits[i]) );
75  }
76  }
77 
78  {
79  if(doNoise_) {
80  addNoise();
81  }
82  }
83 }
int i
Definition: DBlmapReader.cc:9
CSCAnalogSignal amplifySignal(const CSCDetectorHit &)
void setLayer(const CSCLayer *layer)
edm::DetSet< StripDigiSimLink > DigiSimLinks
virtual int readoutElement(int element) const =0
CSCAnalogSignal & add(const CSCAnalogSignal &)
CSCDetId layerId() const
the CSCDetId corresponding to the current layer

Member Data Documentation

bool CSCBaseElectronicsSim::doNoise_
protected
int CSCBaseElectronicsSim::nElements
protected
CSCAnalogSignal CSCBaseElectronicsSim::theAmpResponse
protected

Definition at line 120 of file CSCBaseElectronicsSim.h.

Referenced by amplifySignal(), and fillAmpResponse().

float CSCBaseElectronicsSim::theBunchSpacing
protected
std::vector<double> CSCBaseElectronicsSim::theBunchTimingOffsets
protected
DetectorHitMap CSCBaseElectronicsSim::theDetectorHitMap
protected
DigiSimLinks CSCBaseElectronicsSim::theDigiSimLinks
protected

Definition at line 161 of file CSCBaseElectronicsSim.h.

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

const CSCLayer* CSCBaseElectronicsSim::theLayer
protected
const CSCLayerGeometry* CSCBaseElectronicsSim::theLayerGeometry
protected
CSCDetId CSCBaseElectronicsSim::theLayerId
protected
bool CSCBaseElectronicsSim::theNoiseWasAdded
protected

Definition at line 128 of file CSCBaseElectronicsSim.h.

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

int CSCBaseElectronicsSim::theNumberOfSamples
protected
int CSCBaseElectronicsSim::theOffsetOfBxZero
protected
float CSCBaseElectronicsSim::thePeakTimeSigma
protected

Definition at line 135 of file CSCBaseElectronicsSim.h.

Referenced by addNoise().

CLHEP::RandGaussQ* CSCBaseElectronicsSim::theRandGaussQ
protected
float CSCBaseElectronicsSim::theSamplingTime
protected
int CSCBaseElectronicsSim::theShapingTime
protected
CSCSignalMap CSCBaseElectronicsSim::theSignalMap
protected
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 154 of file CSCBaseElectronicsSim.h.

Referenced by signalDelay().

float CSCBaseElectronicsSim::theSignalStartTime
protected
float CSCBaseElectronicsSim::theSignalStopTime
protected
const CSCChamberSpecs* CSCBaseElectronicsSim::theSpecs
protected
std::vector<double> CSCBaseElectronicsSim::theTimingCalibrationError
protected