Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:29

0001 #ifndef __SimTracker_SiPhase2Digitizer_DigitizerUtility_h
0002 #define __SimTracker_SiPhase2Digitizer_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 
0012 namespace DigitizerUtility {
0013 
0014   class SimHitInfo {
0015   public:
0016     SimHitInfo(const PSimHit* hitp, float corrTime, size_t hitIndex, uint32_t tofBin)
0017         : eventId_(hitp->eventId()), trackId_(hitp->trackId()), hitIndex_(hitIndex), tofBin_(tofBin), time_(corrTime) {}
0018 
0019     uint32_t hitIndex() const { return hitIndex_; };
0020     uint32_t tofBin() const { return tofBin_; };
0021     EncodedEventId eventId() const { return eventId_; };
0022     uint32_t trackId() const { return trackId_; };
0023     float time() const { return time_; };
0024 
0025   private:
0026     EncodedEventId eventId_;
0027     uint32_t trackId_;
0028     uint32_t hitIndex_;
0029     uint32_t tofBin_;
0030     float time_;
0031   };
0032 
0033   class Amplitude {
0034   public:
0035     Amplitude() : _amp(0.0) {}
0036     Amplitude(float amp, const PSimHit* hitp, float frac = 0, float tcor = 0, size_t hitIndex = 0, uint32_t tofBin = 0)
0037         : _amp(amp) {
0038       if (frac > 0) {
0039         if (hitp != nullptr)
0040           _simInfoList.push_back({frac, std::make_unique<SimHitInfo>(hitp, tcor, hitIndex, tofBin)});
0041         else
0042           _simInfoList.push_back({frac, nullptr});
0043       }
0044     }
0045 
0046     // can be used as a float by convers.
0047     operator float() const { return _amp; }
0048     float ampl() const { return _amp; }
0049     const std::vector<std::pair<float, std::unique_ptr<SimHitInfo> > >& simInfoList() const { return _simInfoList; }
0050 
0051     void operator+=(const Amplitude& other) {
0052       _amp += other._amp;
0053       // in case of digi from the noise, the MC information need not be there
0054       for (auto const& ic : other.simInfoList()) {
0055         if (ic.first > -0.5)
0056           _simInfoList.push_back({ic.first, std::make_unique<SimHitInfo>(*ic.second)});
0057       }
0058     }
0059     void operator+=(const float& amp) { _amp += amp; }
0060     void set(const float amplitude) {  // Used to reset the amplitude
0061       _amp = amplitude;
0062     }
0063 
0064   private:
0065     float _amp;
0066     std::vector<std::pair<float, std::unique_ptr<SimHitInfo> > > _simInfoList;
0067   };
0068 
0069   //*********************************************************
0070   // Define a class for 3D ionization points and energy
0071   //*********************************************************
0072   class EnergyDepositUnit {
0073   public:
0074     EnergyDepositUnit() : _energy(0), _position(0, 0, 0) {}
0075     EnergyDepositUnit(float energy, float x, float y, float z) : _energy(energy), _position(x, y, z) {}
0076     EnergyDepositUnit(float energy, Local3DPoint position) : _energy(energy), _position(position) {}
0077     float x() const { return _position.x(); }
0078     float y() const { return _position.y(); }
0079     float z() const { return _position.z(); }
0080     float energy() const { return _energy; }
0081 
0082     // Allow migration between pixel cells
0083     void migrate_position(const Local3DPoint& pos) { _position = pos; }
0084 
0085   private:
0086     float _energy;
0087     Local3DPoint _position;
0088   };
0089 
0090   //**********************************************************
0091   // define class to store signals on the collection surface
0092   //**********************************************************
0093   class SignalPoint {
0094   public:
0095     SignalPoint() : _pos(0, 0), _time(0), _amplitude(0), _sigma_x(1.), _sigma_y(1.), _hitp(nullptr) {}
0096 
0097     SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, float a = 1.0)
0098         : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(nullptr) {}
0099 
0100     SignalPoint(float x, float y, float sigma_x, float sigma_y, float t, const PSimHit& hit, float a = 1.0)
0101         : _pos(x, y), _time(t), _amplitude(a), _sigma_x(sigma_x), _sigma_y(sigma_y), _hitp(&hit) {}
0102 
0103     const LocalPoint& position() const { return _pos; }
0104     float x() const { return _pos.x(); }
0105     float y() const { return _pos.y(); }
0106     float sigma_x() const { return _sigma_x; }
0107     float sigma_y() const { return _sigma_y; }
0108     float time() const { return _time; }
0109     float amplitude() const { return _amplitude; }
0110     const PSimHit& hit() { return *_hitp; }
0111     SignalPoint& set_amplitude(float amp) {
0112       _amplitude = amp;
0113       return *this;
0114     }
0115 
0116   private:
0117     LocalPoint _pos;
0118     float _time;
0119     float _amplitude;
0120     float _sigma_x;  // gaussian sigma in the x direction (cm)
0121     float _sigma_y;  //    "       "          y direction (cm) */
0122     const PSimHit* _hitp;
0123   };
0124   struct DigiSimInfo {
0125     int sig_tot;
0126     bool ot_bit;
0127     std::vector<std::pair<float, SimHitInfo*> > simInfoList;
0128   };
0129 }  // namespace DigitizerUtility
0130 #endif