Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef SimTracker_Common_DigitizerUtility_h
0002 #define SimTracker_Common_DigitizerUtility_h
0003 
0004 #include <map>
0005 #include <memory>
0006 #include <vector>
0007 #include <iostream>
0008 
0009 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0010 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
0011 #include "SimTracker/Common/interface/SimHitInfoForLinks.h"
0012 
0013 namespace digitizerUtility {
0014 
0015   class SimHitInfo {
0016   public:
0017     SimHitInfo(const PSimHit* hitp, float corrTime, size_t hitIndex, uint32_t tofBin)
0018         : eventId_(hitp->eventId()), trackId_(hitp->trackId()), hitIndex_(hitIndex), tofBin_(tofBin), time_(corrTime) {}
0019 
0020     uint32_t hitIndex() const { return hitIndex_; };
0021     uint32_t tofBin() const { return tofBin_; };
0022     EncodedEventId eventId() const { return eventId_; };
0023     uint32_t trackId() const { return trackId_; };
0024     float time() const { return time_; };
0025 
0026   private:
0027     EncodedEventId eventId_;
0028     uint32_t trackId_;
0029     uint32_t hitIndex_;
0030     uint32_t tofBin_;
0031     float time_;
0032   };
0033 
0034   //===================================================================================================
0035   class Amplitude {
0036   public:
0037     Amplitude() : _amp(0.0) {}
0038     Amplitude(float amp, float frac) : _amp(amp), _frac(1, frac) {
0039       //in case of digi from noisypixels
0040       //the MC information are removed
0041       if (_frac[0] < -0.5) {
0042         _frac.pop_back();
0043       }
0044     }
0045 
0046     Amplitude(float amp, const PSimHit* hitp, size_t hitIndex, size_t hitInd4CR, unsigned int tofBin, float frac)
0047         : _amp(amp), _frac(1, frac) {
0048       //in case of digi from noisypixels
0049       //the MC information are removed
0050       if (_frac[0] < -0.5) {
0051         _frac.pop_back();
0052       } else {
0053         _hitInfos.emplace_back(hitp, hitIndex, tofBin, hitInd4CR, amp);
0054       }
0055     }
0056 
0057     // can be used as a float by convers.
0058     operator float() const { return _amp; }
0059     float ampl() const { return _amp; }
0060     const std::vector<float>& individualampl() const { return _frac; }
0061     const std::vector<SimHitInfoForLinks>& hitInfos() const { return _hitInfos; }
0062 
0063     void operator+=(const Amplitude& other) {
0064       _amp += other._amp;
0065       //in case of contribution of noise to the digi
0066       //the MC information are removed
0067       if (other._frac[0] > -0.5) {
0068         if (!other._hitInfos.empty()) {
0069           _hitInfos.insert(_hitInfos.end(), other._hitInfos.begin(), other._hitInfos.end());
0070         }
0071         _frac.insert(_frac.end(), other._frac.begin(), other._frac.end());
0072       }
0073     }
0074     void operator+=(const float& amp) { _amp += amp; }
0075 
0076     void set(const float amplitude) {  // Used to reset the amplitude
0077       _amp = amplitude;
0078     }
0079     /*     void setind (const float indamplitude) {  // Used to reset the amplitude */
0080     /*       _frac = idamplitude; */
0081     /*     } */
0082   private:
0083     float _amp;
0084     std::vector<float> _frac;
0085     std::vector<SimHitInfoForLinks> _hitInfos;
0086   };  // end class Amplitude
0087 
0088   //===================================================================================================
0089   class Ph2Amplitude {
0090   public:
0091     Ph2Amplitude() : _amp(0.0) {}
0092     Ph2Amplitude(
0093         float amp, const PSimHit* hitp, float frac = 0, float tcor = 0, size_t hitIndex = 0, uint32_t tofBin = 0)
0094         : _amp(amp) {
0095       if (frac > 0) {
0096         if (hitp != nullptr)
0097           _simInfoList.push_back({frac, std::make_unique<SimHitInfo>(hitp, tcor, hitIndex, tofBin)});
0098         else
0099           _simInfoList.push_back({frac, nullptr});
0100       }
0101     }
0102 
0103     // can be used as a float by convers.
0104     operator float() const { return _amp; }
0105     float ampl() const { return _amp; }
0106     const std::vector<std::pair<float, std::unique_ptr<SimHitInfo> > >& simInfoList() const { return _simInfoList; }
0107 
0108     void operator+=(const Ph2Amplitude& other) {
0109       _amp += other._amp;
0110       // in case of digi from the noise, the MC information need not be there
0111       for (auto const& ic : other.simInfoList()) {
0112         if (ic.first > -0.5)
0113           _simInfoList.push_back({ic.first, std::make_unique<SimHitInfo>(*ic.second)});
0114       }
0115     }
0116     void operator+=(const float& amp) { _amp += amp; }
0117     void set(const float amplitude) {  // Used to reset the amplitude
0118       _amp = amplitude;
0119     }
0120 
0121   private:
0122     float _amp;
0123     std::vector<std::pair<float, std::unique_ptr<SimHitInfo> > > _simInfoList;
0124   };  // end class Ph2Amplitude
0125 
0126   //*********************************************************
0127   // Define a class for 3D ionization points and energy
0128   //*********************************************************
0129   class EnergyDepositUnit {
0130   public:
0131     EnergyDepositUnit() : _energy(0), _position(0, 0, 0) {}
0132     EnergyDepositUnit(float energy, float x, float y, float z) : _energy(energy), _position(x, y, z) {}
0133     EnergyDepositUnit(float energy, Local3DPoint position) : _energy(energy), _position(position) {}
0134     float x() const { return _position.x(); }
0135     float y() const { return _position.y(); }
0136     float z() const { return _position.z(); }
0137     float energy() const { return _energy; }
0138 
0139     // Allow migration between pixel cells
0140     void migrate_position(const Local3DPoint& pos) { _position = pos; }
0141 
0142   private:
0143     float _energy;
0144     Local3DPoint _position;
0145   };
0146 
0147   //**********************************************************
0148   // define class to store signals on the collection surface
0149   //**********************************************************
0150   class SignalPoint {
0151   public:
0152     SignalPoint() : _pos(0, 0), _time(0), _amplitude(0), _sigma_x(1.), _sigma_y(1.), _hitp(nullptr) {}
0153 
0154     SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, float a = 1.0)
0155         : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(nullptr) {}
0156 
0157     SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, const PSimHit& hit, float a = 1.0)
0158         : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(&hit) {}
0159 
0160     const LocalPoint& position() const { return _pos; }
0161     float x() const { return _pos.x(); }
0162     float y() const { return _pos.y(); }
0163     float sigma_x() const { return _sigma_x; }
0164     float sigma_y() const { return _sigma_y; }
0165     float time() const { return _time; }
0166     float amplitude() const { return _amplitude; }
0167     const PSimHit& hit() { return *_hitp; }
0168     SignalPoint& set_amplitude(float amp) {
0169       _amplitude = amp;
0170       return *this;
0171     }
0172 
0173   private:
0174     LocalPoint _pos;
0175     float _time;
0176     float _amplitude;
0177     float _sigma_x;  // gaussian sigma in the x direction (cm)
0178     float _sigma_y;  //    "       "          y direction (cm) */
0179     const PSimHit* _hitp;
0180   };
0181   struct DigiSimInfo {
0182     int sig_tot;
0183     bool ot_bit;
0184     std::vector<std::pair<float, SimHitInfo*> > simInfoList;
0185   };
0186 }  // namespace digitizerUtility
0187 #endif