CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

CSCBaseElectronicsSim Class Reference

#include <CSCBaseElectronicsSim.h>

Inheritance diagram for CSCBaseElectronicsSim:
CSCStripElectronicsSim CSCWireElectronicsSim

List of all members.

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
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
virtual float calculateAmpResponse (float t) const =0
virtual int channelIndex (int channel) const
 lets users map channels to different indices for links
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
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]
Enumerator:
NONE 
CONSERVATIVE 
RADICAL 

Definition at line 112 of file CSCBaseElectronicsSim.h.


Constructor & Destructor Documentation

CSCBaseElectronicsSim::~CSCBaseElectronicsSim ( ) [virtual]

Definition at line 40 of file CSCBaseElectronicsSim.cc.

References theRandGaussQ.

{
  delete theRandGaussQ;
}
CSCBaseElectronicsSim::CSCBaseElectronicsSim ( const edm::ParameterSet p) [protected]

Definition at line 13 of file CSCBaseElectronicsSim.cc.

References theBunchTimingOffsets.

: 
  theSpecs(0),
  theLayerGeometry(0),
  theLayer(0),
  theSignalMap(),
  theAmpResponse(),
  theBunchSpacing(25.),
  theNoiseWasAdded(false),
  nElements(0),
  theShapingTime(p.getParameter<int>("shapingTime")),
  thePeakTimeSigma(p.getParameter<double>("peakTimeSigma")),
  theBunchTimingOffsets(p.getParameter<std::vector<double> >("bunchTimingOffsets")),
  theSignalStartTime(p.getParameter<double>("signalStartTime")),
  theSignalStopTime(p.getParameter<double>("signalStopTime")),
  theSamplingTime(p.getParameter<double>("samplingTime")),
  theNumberOfSamples(static_cast<int>((theSignalStopTime-theSignalStartTime)/theSamplingTime)),
  theOffsetOfBxZero(p.getParameter<int>("timeBitForBxZero")),
  theSignalPropagationSpeed(p.getParameter<std::vector<double> >("signalSpeed")),
  theTimingCalibrationError(p.getParameter<std::vector<double> >("timingCalibrationError")),
  doNoise_(p.getParameter<bool>("doNoise")),
  theRandGaussQ(0)
{
  assert(theBunchTimingOffsets.size() == 11);
}

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().

                                                                           {
  int element = signal.getElement();
  CSCAnalogSignal & newSignal = find(element);
  newSignal.superimpose(signal);
  return newSignal;
}
void CSCBaseElectronicsSim::addLinks ( int  channelIndex) [protected, virtual]

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().

                                                     {
  std::pair<DetectorHitMap::iterator, DetectorHitMap::iterator> channelHitItr 
    = theDetectorHitMap.equal_range(channelIndex);

  // find the fraction contribution for each SimTrack
  std::map<int,float> simTrackChargeMap;
  std::map<int, EncodedEventId> eventIdMap;
  float totalCharge = 0;
  for( DetectorHitMap::iterator hitItr = channelHitItr.first; 
                                hitItr != channelHitItr.second; ++hitItr){
    const PSimHit * hit = hitItr->second.getSimHit();
    // might be zero for unit tests and such
    if(hit != 0) {
      int simTrackId = hitItr->second.getSimHit()->trackId();
      float charge = hitItr->second.getCharge();
      std::map<int,float>::iterator chargeItr = simTrackChargeMap.find(simTrackId);
      if( chargeItr == simTrackChargeMap.end() ) {
        simTrackChargeMap[simTrackId] = charge;
        eventIdMap[simTrackId] = hit->eventId();
      } else {
        chargeItr->second += charge;
      }
      totalCharge += charge;
    }
  }

  for(std::map<int,float>::iterator chargeItr = simTrackChargeMap.begin(); 
                          chargeItr != simTrackChargeMap.end(); ++chargeItr) {
    int simTrackId = chargeItr->first;
    theDigiSimLinks.push_back( StripDigiSimLink(channelIndex, simTrackId,  
                                  eventIdMap[simTrackId], chargeItr->second/totalCharge ) );
    
  }
}
void CSCBaseElectronicsSim::addNoise ( ) [protected]

Definition at line 141 of file CSCBaseElectronicsSim.cc.

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

Referenced by simulate().

                                     {
  for(CSCSignalMap::iterator mapI = theSignalMap.begin(); 
      mapI!=  theSignalMap.end(); ++mapI) {
    // superimpose electronics noise
    (*mapI).second.superimpose(makeNoiseSignal((*mapI).first));
    // DON'T do amp gain variations.  Handled in strips by calibration code
    // and variations in the shaper peaking time.
     double timeOffset = theRandGaussQ->fire((*mapI).second.getTimeOffset(), thePeakTimeSigma);
    (*mapI).second.setTimeOffset(timeOffset);
  }
  theNoiseWasAdded = true;
}
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().

                                                                        {
  int element = readoutElement(detectorHit.getElement());

  float readoutTime = detectorHit.getTime() 
                    + signalDelay(element, detectorHit.getPosition());

  // start from the amp response, and modify it.
  CSCAnalogSignal thisSignal(theAmpResponse);
  thisSignal *= detectorHit.getCharge();
  thisSignal.setTimeOffset(readoutTime);
  thisSignal.setElement(element);
  // keep track of links between digis and hits
  theDetectorHitMap.insert( DetectorHitMap::value_type(channelIndex(element), detectorHit) );
  return thisSignal;
} 
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 [protected, pure virtual]

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by fillAmpResponse().

virtual int CSCBaseElectronicsSim::channelIndex ( int  channel) const [inline, protected, virtual]

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().

{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().

{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().

                                            {
  std::vector<float> ampBinValues(theNumberOfSamples);
  int i = 0;
  for( ; i < theNumberOfSamples; ++i) {
    ampBinValues[i] = calculateAmpResponse(i*theSamplingTime);
    // truncate any entries that are trivially small
    if(i>5 && ampBinValues[i] < 0.000001) break;
  }
  ampBinValues.resize(i);
  theAmpResponse = CSCAnalogSignal(0, theSamplingTime, ampBinValues, 1., 0.);

  LogTrace("CSCBaseElectronicsSim") << 
    "CSCBaseElectronicsSim: dump of theAmpResponse follows...\n"
         << theAmpResponse;
}
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().

                                                         {
  if(element <= 0 || element > nElements) {
    LogTrace("CSCBaseElectronicsSim") << "CSCBaseElectronicsSim: bad element = " << element << 
         ". There are " << nElements  << " elements.";
    edm::LogError("Error in CSCBaseElectronicsSim:  element out of bounds");
  }
  CSCSignalMap::iterator signalMapItr = theSignalMap.find(element);
  if(signalMapItr == theSignalMap.end()) {
    CSCAnalogSignal newSignal;
    if(theNoiseWasAdded) {
      newSignal = makeNoiseSignal(element);
    } else {
      std::vector<float> emptyV(theNumberOfSamples);
      newSignal = CSCAnalogSignal(element, theSamplingTime, emptyV, 0., theSignalStartTime);
    }
    signalMapItr = theSignalMap.insert( std::pair<int, CSCAnalogSignal>(element, newSignal) ).first;
  }
  return (*signalMapItr).second;
}
virtual void CSCBaseElectronicsSim::initParameters ( ) [protected, pure virtual]

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by setLayer().

CSCDetId CSCBaseElectronicsSim::layerId ( ) const [inline, protected]
CSCAnalogSignal CSCBaseElectronicsSim::makeNoiseSignal ( int  element) [protected, virtual]

Reimplemented in CSCStripElectronicsSim.

Definition at line 134 of file CSCBaseElectronicsSim.cc.

References theNumberOfSamples, theSamplingTime, and theSignalStartTime.

Referenced by addNoise(), and find().

                                                                  {
  std::vector<float> binValues(theNumberOfSamples);
  // default is empty
  return CSCAnalogSignal(element, theSamplingTime, binValues, 0., theSignalStartTime);
} 
virtual int CSCBaseElectronicsSim::readoutElement ( int  element) const [protected, pure virtual]

Implemented in CSCStripElectronicsSim, and CSCWireElectronicsSim.

Referenced by amplifySignal(), and simulate().

void CSCBaseElectronicsSim::setLayer ( const CSCLayer layer) [protected]
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 ExpressReco_HICollisions_FallBack::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().

{
  if(theRandGaussQ) delete theRandGaussQ;
  theRandGaussQ = new CLHEP::RandGaussQ(engine);
}
void CSCBaseElectronicsSim::setSignalTimeRange ( double  startTime,
double  stopTime 
) [inline, protected]

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.

                                                             {
    theSignalStartTime = startTime;
    theSignalStopTime = stopTime;
  }
float CSCBaseElectronicsSim::signalDelay ( int  element,
float  pos 
) const [protected, virtual]

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, ExpressReco_HICollisions_FallBack::speed, theSignalPropagationSpeed, and theSpecs.

Referenced by amplifySignal().

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

Definition at line 53 of file CSCBaseElectronicsSim.cc.

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

Referenced by CSCDigitizer::doAction().

{
  theNoiseWasAdded = false;

  {
    theSignalMap.clear();
    theDetectorHitMap.clear();
    setLayer(layer);
    // can we swap for efficiency?
    theDigiSimLinks = DigiSimLinks(layerId().rawId());
  }
  
  {
    size_t nHits = detectorHits.size();
      // turn each detector hit into an analog signal
    for( size_t i = 0; i < nHits; ++i) {
      int element = readoutElement( detectorHits[i].getElement() );

      // skip if  hit element is not part of a readout element
      // e.g. wire in non-readout group
      if ( element != 0 ) add( amplifySignal(detectorHits[i]) );
    }
  }
  
  {
    if(doNoise_) {
      addNoise();
    }
  }
} 

Member Data Documentation

Reimplemented in CSCStripElectronicsSim.

Definition at line 120 of file CSCBaseElectronicsSim.h.

Referenced by amplifySignal(), and fillAmpResponse().

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

Definition at line 161 of file CSCBaseElectronicsSim.h.

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

Definition at line 128 of file CSCBaseElectronicsSim.h.

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

Definition at line 135 of file CSCBaseElectronicsSim.h.

Referenced by addNoise().

CLHEP::RandGaussQ* CSCBaseElectronicsSim::theRandGaussQ [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().

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