CMS 3D CMS Logo

HGCalTB16SD01.cc
Go to the documentation of this file.
10 
11 #include "CLHEP/Units/GlobalSystemOfUnits.h"
12 #include "G4LogicalVolumeStore.hh"
13 #include "G4Material.hh"
14 #include "G4Step.hh"
15 #include "G4Track.hh"
16 
17 #include <string>
18 
19 //#define EDM_ML_DEBUG
20 
21 class HGCalTB16SD01 : public CaloSD {
22  public:
25  const SimTrackManager*);
26  ~HGCalTB16SD01() override = default;
27  uint32_t setDetUnitId(const G4Step* step) override;
28  static uint32_t packIndex(int det, int lay, int x, int y);
29  static void unpackIndex(const uint32_t& idx, int& det, int& lay, int& x,
30  int& y);
31 
32  protected:
33  double getEnergyDeposit(const G4Step*) override;
34 
35  private:
36  void initialize(const G4StepPoint* point);
37 
39  bool useBirk_;
40  double birk1_, birk2_, birk3_;
42  G4Material* matScin_;
43 };
44 
46  const SensitiveDetectorCatalog& clg,
47  edm::ParameterSet const& p,
48  const SimTrackManager* manager)
49  : CaloSD(name, cpv, clg, p, manager), initialize_(true) {
50  // Values from NIM 80 (1970) 239-244: as implemented in Geant3
51  edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HGCalTestBeamSD");
52  matName_ = m_HC.getParameter<std::string>("Material");
53  useBirk_ = m_HC.getParameter<bool>("UseBirkLaw");
54  birk1_ = m_HC.getParameter<double>("BirkC1") * (g / (MeV * cm2));
55  birk2_ = m_HC.getParameter<double>("BirkC2");
56  birk3_ = m_HC.getParameter<double>("BirkC3");
57  matScin_ = nullptr;
58 
59  edm::LogVerbatim("HGCSim")
60  << "HGCalTB16SD01:: Use of Birks law is set to " << useBirk_ << " for "
61  << matName_ << " with three constants kB = " << birk1_
62  << ", C1 = " << birk2_ << ", C2 = " << birk3_;
63 }
64 
65 double HGCalTB16SD01::getEnergyDeposit(const G4Step* aStep) {
66  auto const point = aStep->GetPreStepPoint();
68  double destep = aStep->GetTotalEnergyDeposit();
69  double wt2 = aStep->GetTrack()->GetWeight();
70  double weight = (wt2 > 0.0) ? wt2 : 1.0;
71  if (useBirk_ && matScin_ == point->GetMaterial()) {
72  weight *= getAttenuation(aStep, birk1_, birk2_, birk3_);
73  }
74 #ifdef EDM_ML_DEBUG
75  edm::LogVerbatim("HGCSim")
76  << "HGCalTB16SD01: Detector "
77  << point->GetTouchable()->GetVolume()->GetName() << " with "
78  << point->GetMaterial()->GetName() << " weight " << weight << ":" << wt2;
79 #endif
80  return weight * destep;
81 }
82 
83 uint32_t HGCalTB16SD01::setDetUnitId(const G4Step* aStep) {
84  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
85  const G4VTouchable* touch = preStepPoint->GetTouchable();
86 
87  int det(1), x(0), y(0);
88  int lay = (touch->GetReplicaNumber(0));
89 
90  return packIndex(det, lay, x, y);
91 }
92 
93 uint32_t HGCalTB16SD01::packIndex(int det, int lay, int x, int y) {
94  int ix = 0, ixx = x;
95  if (x < 0) {
96  ix = 1;
97  ixx = -x;
98  }
99  int iy = 0, iyy = y;
100  if (y < 0) {
101  iy = 1;
102  iyy = -y;
103  }
104  uint32_t idx = (det & 15) << 28; // bits 28-31
105  idx += (lay & 127) << 21; // bits 21-27
106  idx += (iy & 1) << 19; // bit 19
107  idx += (iyy & 511) << 10; // bits 10-18
108  idx += (ix & 1) << 9; // bit 9
109  idx += (ixx & 511); // bits 0-8
110 
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("HGCSim")
113  << "HGCalTB16SD01: Detector " << det << " Layer " << lay << " x " << x
114  << " " << ix << " " << ixx << " y " << y << " " << iy << " " << iyy
115  << " ID " << std::hex << idx << std::dec;
116 #endif
117  return idx;
118 }
119 
120 void HGCalTB16SD01::unpackIndex(const uint32_t& idx, int& det, int& lay, int& x,
121  int& y) {
122  det = (idx >> 28) & 15;
123  lay = (idx >> 21) & 127;
124  y = (idx >> 10) & 511;
125  if (((idx >> 19) & 1) == 1) y = -y;
126  x = (idx)&511;
127  if (((idx >> 9) & 1) == 1) x = -x;
128 }
129 
130 void HGCalTB16SD01::initialize(const G4StepPoint* point) {
131  if (matName_ == point->GetMaterial()->GetName()) {
132  matScin_ = point->GetMaterial();
133  initialize_ = false;
134  }
135 #ifdef EDM_ML_DEBUG
136  edm::LogVerbatim("HGCSim") << "HGCalTB16SD01: Material pointer for "
137  << matName_ << " is initialized to : " << matScin_;
138 #endif
139 }
140 
144 
T getParameter(std::string const &) const
double getEnergyDeposit(const G4Step *) override
Definition: CaloSD.h:38
int iyy[18][41][3]
Definition: weight.py:1
int ixx[18][41][3]
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
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
HGCalTB16SD01(const std::string &, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
G4Material * matScin_
void initialize(const G4StepPoint *point)
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:438
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