CMS 3D CMS Logo

HGCalTB16SD01.cc
Go to the documentation of this file.
4 
5 #include "CLHEP/Units/GlobalSystemOfUnits.h"
6 #include "G4LogicalVolumeStore.hh"
7 #include "G4Material.hh"
8 #include "G4Step.hh"
9 #include "G4Track.hh"
10 
11 #include <string>
12 
13 //#define EDM_ML_DEBUG
14 
15 class HGCalTB16SD01 : public CaloSD {
16 public:
18  const edm::EventSetup&,
20  edm::ParameterSet const&,
21  const SimTrackManager*);
22  ~HGCalTB16SD01() override = default;
23  uint32_t setDetUnitId(const G4Step* step) override;
24  static uint32_t packIndex(int det, int lay, int x, int y);
25  static void unpackIndex(const uint32_t& idx, int& det, int& lay, int& x, int& y);
26 
27 protected:
28  double getEnergyDeposit(const G4Step*) override;
29 
30 private:
31  void initialize(const G4StepPoint* point);
32 
34  bool useBirk_;
35  double birk1_, birk2_, birk3_;
37  G4Material* matScin_;
38 };
39 
41  const edm::EventSetup& es,
42  const SensitiveDetectorCatalog& clg,
43  edm::ParameterSet const& p,
44  const SimTrackManager* manager)
45  : CaloSD(name, es, clg, p, manager), initialize_(true) {
46  // Values from NIM 80 (1970) 239-244: as implemented in Geant3
47  edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HGCalTestBeamSD");
48  matName_ = m_HC.getParameter<std::string>("Material");
49  useBirk_ = m_HC.getParameter<bool>("UseBirkLaw");
50  birk1_ = m_HC.getParameter<double>("BirkC1") * (g / (MeV * cm2));
51  birk2_ = m_HC.getParameter<double>("BirkC2");
52  birk3_ = m_HC.getParameter<double>("BirkC3");
53  matScin_ = nullptr;
54 
55  edm::LogVerbatim("HGCSim") << "HGCalTB16SD01:: Use of Birks law is set to " << useBirk_ << " for " << matName_
56  << " with three constants kB = " << birk1_ << ", C1 = " << birk2_ << ", C2 = " << birk3_;
57 }
58 
59 double HGCalTB16SD01::getEnergyDeposit(const G4Step* aStep) {
60  auto const point = aStep->GetPreStepPoint();
61  if (initialize_)
63  double destep = aStep->GetTotalEnergyDeposit();
64  double wt2 = aStep->GetTrack()->GetWeight();
65  double weight = (wt2 > 0.0) ? wt2 : 1.0;
66  if (useBirk_ && matScin_ == point->GetMaterial()) {
67  weight *= getAttenuation(aStep, birk1_, birk2_, birk3_);
68  }
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("HGCSim") << "HGCalTB16SD01: Detector " << point->GetTouchable()->GetVolume()->GetName() << " with "
71  << point->GetMaterial()->GetName() << " weight " << weight << ":" << wt2;
72 #endif
73  return weight * destep;
74 }
75 
76 uint32_t HGCalTB16SD01::setDetUnitId(const G4Step* aStep) {
77  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
78  const G4VTouchable* touch = preStepPoint->GetTouchable();
79 
80  int det(1), x(0), y(0);
81  int lay = (touch->GetReplicaNumber(0));
82 
83  return packIndex(det, lay, x, y);
84 }
85 
86 uint32_t HGCalTB16SD01::packIndex(int det, int lay, int x, int y) {
87  int ix = 0, ixx = x;
88  if (x < 0) {
89  ix = 1;
90  ixx = -x;
91  }
92  int iy = 0, iyy = y;
93  if (y < 0) {
94  iy = 1;
95  iyy = -y;
96  }
97  uint32_t idx = (det & 15) << 28; // bits 28-31
98  idx += (lay & 127) << 21; // bits 21-27
99  idx += (iy & 1) << 19; // bit 19
100  idx += (iyy & 511) << 10; // bits 10-18
101  idx += (ix & 1) << 9; // bit 9
102  idx += (ixx & 511); // bits 0-8
103 
104 #ifdef EDM_ML_DEBUG
105  edm::LogVerbatim("HGCSim") << "HGCalTB16SD01: Detector " << det << " Layer " << lay << " x " << x << " " << ix << " "
106  << ixx << " y " << y << " " << iy << " " << iyy << " ID " << std::hex << idx << std::dec;
107 #endif
108  return idx;
109 }
110 
111 void HGCalTB16SD01::unpackIndex(const uint32_t& idx, int& det, int& lay, int& x, int& y) {
112  det = (idx >> 28) & 15;
113  lay = (idx >> 21) & 127;
114  y = (idx >> 10) & 511;
115  if (((idx >> 19) & 1) == 1)
116  y = -y;
117  x = (idx)&511;
118  if (((idx >> 9) & 1) == 1)
119  x = -x;
120 }
121 
122 void HGCalTB16SD01::initialize(const G4StepPoint* point) {
123  if (matName_ == point->GetMaterial()->GetName()) {
124  matScin_ = point->GetMaterial();
125  initialize_ = false;
126  }
127 #ifdef EDM_ML_DEBUG
128  edm::LogVerbatim("HGCSim") << "HGCalTB16SD01: Material pointer for " << matName_
129  << " is initialized to : " << matScin_;
130 #endif
131 }
132 
136 
T getParameter(std::string const &) const
double getEnergyDeposit(const G4Step *) override
HGCalTB16SD01(const std::string &, const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: CaloSD.h:38
int iyy[18][41][3]
Definition: weight.py:1
int ixx[18][41][3]
static void unpackIndex(const uint32_t &idx, int &det, int &lay, int &x, int &y)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::string matName_
const double MeV
HGCalTB16SD01 HGCalTB1601SensitiveDetector
uint32_t setDetUnitId(const G4Step *step) override
~HGCalTB16SD01() override=default
G4Material * matScin_
void initialize(const G4StepPoint *point)
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:434
step
Definition: StallMonitor.cc:94
static uint32_t packIndex(int det, int lay, int x, int y)
#define DEFINE_SENSITIVEDETECTOR(type)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5