Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:03:34

0001 #ifndef EcalSimAlgos_EcalTimeMapDigitizer_h
0002 #define EcalSimAlgos_EcalTimeMapDigitizer_h
0003 
0004 /** Turns hits into digis.  Assumes that 
0005     there's an ElectroncsSim class with the
0006     interface analogToDigital(const CaloSamples &, Digi &);
0007 */
0008 
0009 #include "CalibFormats/CaloObjects/interface/CaloTSamples.h"
0010 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0011 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0014 #include "CalibFormats/CaloObjects/interface/CaloTSamplesBase.h"
0015 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0016 #include "SimCalorimetry/EcalSimAlgos/interface/ComponentShapeCollection.h"
0017 
0018 class CaloSubdetectorGeometry;
0019 
0020 class EcalTimeMapDigitizer {
0021 public:
0022   struct time_average {
0023     static const unsigned short time_average_capacity = 10;  // this corresponds to the number of BX
0024     static const unsigned short waveform_capacity = EcalTimeDigi::WAVEFORMSAMPLES;  // this will give a waveform with
0025     static constexpr double waveform_granularity = 1.;                              // a granularity of 1ns
0026 
0027     const DetId id;
0028     float average_time[time_average_capacity];
0029     unsigned int nhits[time_average_capacity];
0030     float tot_energy[time_average_capacity];
0031     float waveform[waveform_capacity];
0032 
0033     time_average(const DetId& myId) : id(myId) {
0034       for (unsigned int i(0); i < time_average_capacity; ++i) {
0035         average_time[i] = 0;
0036         nhits[i] = 0;
0037         tot_energy[i] = 0;
0038       }
0039       for (unsigned int i(0); i < waveform_capacity; ++i) {
0040         waveform[i] = 0;
0041       }
0042     };
0043 
0044     void calculateAverage() {
0045       for (unsigned int i(0); i < time_average_capacity; ++i) {
0046         if (nhits[i] > 0)
0047           average_time[i] = average_time[i] / tot_energy[i];
0048         else
0049           average_time[i] = 0;
0050       }
0051     };
0052 
0053     void setZero() {
0054       for (unsigned int i(0); i < time_average_capacity; ++i) {
0055         average_time[i] = 0;
0056         nhits[i] = 0;
0057         tot_energy[i] = 0;
0058       }
0059       for (unsigned int i(0); i < waveform_capacity; ++i) {
0060         waveform[i] = 0;
0061       }
0062     };
0063 
0064     bool zero() {
0065       for (unsigned int i(0); i < time_average_capacity; ++i) {
0066         if (nhits[i] > 0)
0067           return false;
0068       }
0069       return true;
0070     };
0071   };
0072 
0073   typedef time_average TimeSamples;
0074 
0075   typedef EcalTimeDigi Digi;
0076 
0077   typedef std::vector<unsigned int> VecInd;
0078 
0079   explicit EcalTimeMapDigitizer(EcalSubdetector myDet, ComponentShapeCollection* componentShapes);
0080 
0081   virtual ~EcalTimeMapDigitizer();
0082 
0083   void add(const std::vector<PCaloHit>& hits, int bunchCrossing);
0084 
0085   void setGeometry(const CaloSubdetectorGeometry* geometry);
0086 
0087   void setEventSetup(const edm::EventSetup& eventSetup);
0088 
0089   void initializeMap();
0090 
0091   void run(EcalTimeDigiCollection& output);
0092 
0093   void finalizeHits();
0094 
0095   inline void setTimeLayerId(const int& layerId) { m_timeLayerId = layerId; };
0096 
0097   int getTimeLayerId() { return m_timeLayerId; };
0098 
0099   EcalSubdetector subdetector() { return m_subDet; };
0100 
0101   int minBunch() const;
0102 
0103   int maxBunch() const;
0104 
0105   void blankOutUsedSamples();  // blank out previously used elements
0106 
0107   /*   const CaloVHitFilter* hitFilter() const ; */
0108 
0109 private:
0110   TimeSamples* findSignal(const DetId& detId);
0111 
0112   VecInd& index();
0113 
0114   const VecInd& index() const;
0115 
0116   unsigned int samplesSize() const;
0117 
0118   unsigned int samplesSizeAll() const;
0119 
0120   const TimeSamples* operator[](unsigned int i) const;
0121 
0122   TimeSamples* operator[](unsigned int i);
0123 
0124   TimeSamples* vSam(unsigned int i);
0125 
0126   TimeSamples* vSamAll(unsigned int i);
0127 
0128   const TimeSamples* vSamAll(unsigned int i) const;
0129 
0130   EcalSubdetector m_subDet;
0131   //time difference between bunches
0132 
0133   static const int BUNCHSPACE = 25;
0134 
0135   static const float MIN_ENERGY_THRESHOLD;  //50 KeV threshold to consider a valid hit in the timing detector
0136 
0137   static const int m_minBunch = -4;
0138   static const int m_maxBunch = 5;
0139 
0140   int m_timeLayerId;
0141 
0142   ComponentShapeCollection* m_ComponentShapes;
0143 
0144   const CaloSubdetectorGeometry* m_geometry;
0145 
0146   double timeOfFlight(const DetId& detId, int layer) const;
0147 
0148   const ComponentShapeCollection* shapes() const;
0149 
0150   std::vector<TimeSamples> m_vSam;
0151 
0152   VecInd m_index;
0153 };
0154 
0155 #endif