Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:41

0001 #ifndef MU_END_BASE_ELECTRONICS_SIM_H
0002 #define MU_END_BASE_ELECTRONICS_SIM_H
0003 
0004 /** \class CSCBaseElectronicsSim
0005  *
0006  * Commonalities between  CSCStripElectronicsSim and CSCWireElectronicsSim.
0007  *
0008  * \author Rick Wilkinson
0009  *
0010  * It has three non-virtual functions, so that's enough
0011  * to deserve a new class.
0012  * And since it has virtual functions it needs a virtual dtor.
0013  *
0014  */
0015 
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "SimMuon/CSCDigitizer/src/CSCAnalogSignal.h"
0018 #include <map>
0019 #include <vector>
0020 
0021 #include "DataFormats/Common/interface/DetSet.h"
0022 #include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
0023 
0024 // declarations
0025 class CSCLayer;
0026 class CSCChamberSpecs;
0027 class CSCDetectorHit;
0028 class CSCLayerGeometry;
0029 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0030 class DetId;
0031 class PSimHit;
0032 
0033 namespace CLHEP {
0034   class HepRandomEngine;
0035 }
0036 
0037 class CSCBaseElectronicsSim {
0038 public:
0039   typedef std::map<int, CSCAnalogSignal, std::less<int>> CSCSignalMap;
0040   typedef edm::DetSet<StripDigiSimLink> DigiSimLinks;
0041 
0042   // takes the input detector hits, turns them into DIGIs, and
0043   // stores them in the layer
0044   void simulate(const CSCLayer *layer, const std::vector<CSCDetectorHit> &inputHits, CLHEP::HepRandomEngine *);
0045 
0046   const DigiSimLinks &digiSimLinks() const { return theDigiSimLinks; }
0047 
0048   virtual ~CSCBaseElectronicsSim();
0049 
0050   /// for standalone apps who don't calculate it from the geometry
0051   void setLayerId(const CSCDetId &id) { theLayerId = id; }
0052 
0053 protected:
0054   // constructor protected, so this class must be a base class
0055   CSCBaseElectronicsSim(const edm::ParameterSet &p);
0056 
0057   void setLayer(const CSCLayer *layer);
0058   // initialize things that change from layer to layer
0059   virtual void initParameters() = 0;
0060 
0061   void fillAmpResponse();
0062   virtual float calculateAmpResponse(float t) const = 0;
0063 
0064   // this one turns CSCDetectorHits into CSCAnalogSignals
0065   CSCAnalogSignal amplifySignal(const CSCDetectorHit &);
0066 
0067   // returns readout element.  So wire 20 might be part of wire group 2.
0068   virtual int readoutElement(int element) const = 0;
0069 
0070   //  fills the member map of signals on strips, superimposing any duplicates
0071   void combineAnalogSignals(const std::vector<CSCAnalogSignal> &);
0072 
0073   void setNoise(float rmsNoise, float noiseSigmaThreshold);
0074 
0075   /// How long before & after the bunch crossing to simulate
0076   /// shortening the time can save CPU
0077   void setSignalTimeRange(double startTime, double stopTime) {
0078     theSignalStartTime = startTime;
0079     theSignalStopTime = stopTime;
0080   }
0081 
0082   void addNoise(CLHEP::HepRandomEngine *);
0083 
0084   CSCAnalogSignal &find(int element, CLHEP::HepRandomEngine *);
0085   // the returned signal will be the one stored in the
0086   // signal, not the original.  If another signal
0087   // is found on this element, they will be superimposed.
0088   CSCAnalogSignal &add(const CSCAnalogSignal &, CLHEP::HepRandomEngine *);
0089   virtual CSCAnalogSignal makeNoiseSignal(int element, CLHEP::HepRandomEngine *);
0090 
0091   /// how long, in ns, it takes a signal at pos to propagate to
0092   /// the readout edge.  This may be negative, since the timing
0093   /// may be calibrated to the center of the detector
0094   virtual float signalDelay(int element, float pos) const;
0095 
0096   /// creates links from Digi to SimTrack
0097   /// disabled for now
0098   virtual void addLinks(int channelIndex);
0099 
0100   /// lets users map channels to different indices for links
0101   virtual int channelIndex(int channel) const { return channel; }
0102 
0103   /// the CSCDetId corresponding to the current layer
0104   CSCDetId layerId() const { return theLayerId; }
0105 
0106   /// the average time-of-flight from the interaction point to the given
0107   /// detector
0108   double averageTimeOfFlight(const DetId &detId) const;
0109 
0110   // member data
0111   enum { NONE, CONSERVATIVE, RADICAL };
0112 
0113   const CSCChamberSpecs *theSpecs;
0114   const CSCLayerGeometry *theLayerGeometry;
0115   const CSCLayer *theLayer;  // the one currently being digitized
0116   CSCDetId theLayerId;
0117 
0118   CSCSignalMap theSignalMap;
0119   CSCAnalogSignal theAmpResponse;
0120 
0121   // Useful parameters
0122   float theBunchSpacing;
0123 
0124   // lets routines know whether new signals should
0125   //  have noise added, or just be empty.  If the
0126   //  noise hasn't been added yet, just make empty.
0127   bool theNoiseWasAdded;
0128 
0129   // the numbers of wire groups or strips in this layer
0130   int nElements;
0131 
0132   // amplifier parameters
0133   int theShapingTime;
0134   float thePeakTimeSigma;
0135   // used to correct the bunch timing so that the signal event
0136   // comes at BX zero.
0137   std::vector<double> theBunchTimingOffsets;
0138 
0139   // when the signal is to be simulated
0140   float theSignalStartTime;
0141   float theSignalStopTime;
0142 
0143   // size of time bins for signal shape, in ns
0144   float theSamplingTime;
0145 
0146   // time bins for pulse shape
0147   int theNumberOfSamples;
0148 
0149   // Which bit in the 16-bit time word corresponds to the zeroth beam crossing?
0150   int theOffsetOfBxZero;  // bit corresponding to bx 0 (counting from 0-15)
0151   /// Speed (cm/ns) that it takes for the signal to get from the element to the
0152   /// readout. Actually negative in strips, due to reflection effects.
0153   std::vector<double> theSignalPropagationSpeed;
0154   std::vector<double> theTimingCalibrationError;
0155   bool doNoise_;
0156 
0157   // keeps track of which hits contribute to which channels
0158   typedef std::multimap<int, CSCDetectorHit, std::less<int>> DetectorHitMap;
0159   DetectorHitMap theDetectorHitMap;
0160   DigiSimLinks theDigiSimLinks;
0161 };
0162 
0163 #endif