CMS 3D CMS Logo

HGCScintSD.cc
Go to the documentation of this file.
1 // File: HGCScintSD.cc
3 // Description: Sensitive Detector class for the Scintillator part of
4 // High Granularity Calorimeter
6 
23 #include "G4LogicalVolumeStore.hh"
24 #include "G4LogicalVolume.hh"
25 #include "G4Step.hh"
26 #include "G4Track.hh"
27 #include "G4ParticleTable.hh"
28 #include "G4VProcess.hh"
29 #include "G4Trap.hh"
30 
31 #include <iostream>
32 #include <fstream>
33 #include <iomanip>
34 
35 //#define EDM_ML_DEBUG
36 
38  const SensitiveDetectorCatalog & clg,
39  edm::ParameterSet const & p,
40  const SimTrackManager* manager):
41  CaloSD(name, cpv, clg, p, manager,
42  (float)(p.getParameter<edm::ParameterSet>("HGCSD").getParameter<double>("TimeSliceUnit")),
43  p.getParameter<edm::ParameterSet>("HGCSD").getParameter<bool>("IgnoreTrackID")),
44  hgcons_(nullptr), slopeMin_(0), levelT1_(99), levelT2_(99) {
45 
46  numberingScheme_.reset(nullptr);
47 
48  edm::ParameterSet m_HGC = p.getParameter<edm::ParameterSet>("HGCScintSD");
49  eminHit_ = m_HGC.getParameter<double>("EminHit")*CLHEP::MeV;
50  fiducialCut_ = m_HGC.getParameter<bool>("FiducialCut");
51  distanceFromEdge_= m_HGC.getParameter<double>("DistanceFromEdge");
52  useBirk_ = m_HGC.getParameter<bool>("UseBirkLaw");
53  birk1_ = m_HGC.getParameter<double>("BirkC1")*(CLHEP::g/(CLHEP::MeV*CLHEP::cm2));
54  birk2_ = m_HGC.getParameter<double>("BirkC2");
55  birk3_ = m_HGC.getParameter<double>("BirkC3");
56  storeAllG4Hits_ = m_HGC.getParameter<bool>("StoreAllG4Hits");
57 
58  if (storeAllG4Hits_) {
59  setUseMap(false);
61  }
62 
63  //this is defined in the hgcsens.xml
64  G4String myName = name;
66  nameX_ = "HGCal";
67  if (myName.find("HitsHEback")!=std::string::npos) {
69  nameX_ = "HGCalHEScintillatorSensitive";
70  }
71 
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCSim")<< "**************************************************"
74  << "\n"
75  << "* *"
76  << "\n"
77  << "* Constructing a HGCScintSD with name " << name << "\n"
78  << "* *"
79  << "\n"
80  << "**************************************************";
81 #endif
82  edm::LogVerbatim("HGCSim") << "HGCScintSD:: Threshold for storing hits: "
83  << eminHit_ << " for " << nameX_ << " detector "
84  << mydet_;
85  edm::LogVerbatim("HGCSim") << "Flag for storing individual Geant4 Hits "
86  << storeAllG4Hits_;
87  edm::LogVerbatim("HGCSim") << "Fiducial volume cut with cut from eta/phi "
88  << "boundary " << fiducialCut_ << " at "
90  edm::LogVerbatim("HGCSim") << "Use of Birks law is set to " << useBirk_
91  << " with three constants kB = " << birk1_
92  << ", C1 = " << birk2_ << ", C2 = " << birk3_;
93 }
94 
95 double HGCScintSD::getEnergyDeposit(const G4Step* aStep) {
96 
97  double r = aStep->GetPreStepPoint()->GetPosition().perp();
98  double z = std::abs(aStep->GetPreStepPoint()->GetPosition().z());
99 #ifdef EDM_ML_DEBUG
100  G4int parCode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
101  G4String parName = aStep->GetTrack()->GetDefinition()->GetParticleName();
102  G4LogicalVolume* lv =
103  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
104  edm::LogVerbatim("HGCSim") << "HGCScintSD: Hit from standard path from "
105  << lv->GetName() << " for Track "
106  << aStep->GetTrack()->GetTrackID() << " ("
107  << parCode << ":" << parName << ") R = " << r
108  << " Z = " << z << " slope = " << r/z << ":"
109  << slopeMin_;
110 #endif
111  // Apply fiducial cut
112  if (r < z*slopeMin_) {
113 #ifdef EDM_ML_DEBUG
114  edm::LogVerbatim("HGCSim") << "HGCScintSD: Fiducial Volume cut";
115 #endif
116  return 0.0;
117  }
118 
119  double wt1 = getResponseWt(aStep->GetTrack());
120  double wt2 = aStep->GetTrack()->GetWeight();
121  double wt3 = (useBirk_ ? getAttenuation(aStep, birk1_, birk2_, birk3_) :
122  1.0);
123  double destep = weight_*wt1*wt3*(aStep->GetTotalEnergyDeposit());
124  if (wt2 > 0) destep *= wt2;
125 #ifdef EDM_ML_DEBUG
126  edm::LogVerbatim("HGCalSim") << "HGCScintSD: weights= " << weight_ << ":"
127  << wt1 << ":" << wt2 << ":" << wt3
128  << " Total weight " << weight_*wt1*wt2*wt3
129  << " deStep: " <<aStep->GetTotalEnergyDeposit()
130  << ":" <<destep;
131 #endif
132  return destep;
133 }
134 
135 uint32_t HGCScintSD::setDetUnitId(const G4Step * aStep) {
136 
137  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
138  const G4VTouchable* touch = preStepPoint->GetTouchable();
139 
140  //determine the exact position in global coordinates in the mass geometry
141  G4ThreeVector hitPoint = preStepPoint->GetPosition();
142  float globalZ = touch->GetTranslation(0).z();
143  int iz( globalZ>0 ? 1 : -1);
144 
145  int layer, module, cell;
146  if ((touch->GetHistoryDepth() == levelT1_) ||
147  (touch->GetHistoryDepth() == levelT2_)) {
148  layer = touch->GetReplicaNumber(0);
149  module = -1;
150  cell = -1;
151 #ifdef EDM_ML_DEBUG
152  edm::LogVerbatim("HGCSim") << "DepthsTop: " << touch->GetHistoryDepth()
153  << ":" << levelT1_ << ":" << levelT2_
154  << " name " << touch->GetVolume(0)->GetName()
155  << " layer:module:cell " << layer << ":"
156  << module << ":" << cell;
157 #endif
158  } else {
159  layer = touch->GetReplicaNumber(3);
160  module = touch->GetReplicaNumber(2);
161  cell = touch->GetReplicaNumber(1);
162 #ifdef EDM_ML_DEBUG
163  edm::LogVerbatim("HGCSim") << "DepthsInside: " << touch->GetHistoryDepth()
164  << " name " << touch->GetVolume(0)->GetName()
165  << " layer:module:cell " << layer << ":"
166  << module << ":" << cell;
167 #endif
168  }
169 #ifdef EDM_ML_DEBUG
170  G4Material* mat = aStep->GetPreStepPoint()->GetMaterial();
171  edm::LogVerbatim("HGCSim") << "Depths: " << touch->GetHistoryDepth()
172  << " name " << touch->GetVolume(0)->GetName()
173  << ":" << touch->GetReplicaNumber(0) << " "
174  << touch->GetVolume(1)->GetName()
175  << ":" << touch->GetReplicaNumber(1) << " "
176  << touch->GetVolume(2)->GetName()
177  << ":" << touch->GetReplicaNumber(2) << " "
178  << touch->GetVolume(3)->GetName()
179  << ":" << touch->GetReplicaNumber(3) << " "
180  << touch->GetVolume(4)->GetName()
181  << ":" << touch->GetReplicaNumber(4) << " "
182  << " layer:module:cell " << layer << ":"
183  << module << ":" << cell << " Material "
184  << mat->GetName() << ":" << mat->GetRadlen();
185 #endif
186  // The following statement should be examined later before elimination
187  if (aStep->GetPreStepPoint()->GetMaterial()->GetRadlen() > 100000.) return 0;
188 
189  uint32_t id = setDetUnitId (layer, module, cell, iz, hitPoint);
190  if (!isItinFidVolume(hitPoint)) {
191 #ifdef EDM_ML_DEBUG
192  edm::LogVerbatim("HGCSim") << "ID " << std::hex << id << std::dec
193  << " " << HGCScintillatorDetId(id)
194  << " is rejected by fiducilal volume cut";
195 #endif
196  id = 0;
197  }
198  return id;
199 }
200 
201 void HGCScintSD::update(const BeginOfJob * job) {
202 
203  const edm::EventSetup* es = (*job)();
205  es->get<IdealGeometryRecord>().get(nameX_,hdc);
206  if (hdc.isValid()) {
207  hgcons_ = hdc.product();
210  levelT1_ = hgcons_->levelTop(0);
211  levelT2_ = hgcons_->levelTop(1);
212 #ifdef EDM_ML_DEBUG
213  edm::LogVerbatim("HGCSim") << "HGCScintSD::Initialized with mode "
214  << geom_mode_ << " Slope cut " << slopeMin_
215  << " top Level " << levelT1_ << ":" << levelT2_;
216 #endif
217 
219  } else {
220  throw cms::Exception("Unknown", "HGCScintSD") << "Cannot find HGCalDDDConstants for " << nameX_ << "\n";
221  }
222 }
223 
225 }
226 
227 bool HGCScintSD::filterHit(CaloG4Hit* aHit, double time) {
228  return ((time <= tmaxHit) && (aHit->getEnergyDeposit() > eminHit_));
229 }
230 
231 uint32_t HGCScintSD::setDetUnitId (int layer, int module, int cell, int iz,
232  G4ThreeVector &pos) {
233  uint32_t id = numberingScheme_ ?
234  numberingScheme_->getUnitID(layer, module, cell, iz, pos, weight_) : 0;
235  return id;
236 }
237 
238 bool HGCScintSD::isItinFidVolume (const G4ThreeVector& pos) {
239  if (fiducialCut_) {
240  return (hgcons_->distFromEdgeTrap(pos.x(),pos.y(),pos.z()) > distanceFromEdge_);
241  } else {
242  return true;
243  }
244 }
double birk2_
Definition: HGCScintSD.h:53
T getParameter(std::string const &) const
HGCalGeometryMode::GeometryMode geom_mode_
Definition: HGCScintSD.h:48
int levelT2_
Definition: HGCScintSD.h:50
void setNumberCheckedHits(int val)
Definition: CaloSD.h:111
double birk1_
Definition: HGCScintSD.h:53
Definition: CaloSD.h:37
double distanceFromEdge_
Definition: HGCScintSD.h:49
#define nullptr
uint32_t setDetUnitId(const G4Step *step) override
Definition: HGCScintSD.cc:135
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
int levelT1_
Definition: HGCScintSD.h:50
void setUseMap(bool val)
Definition: CaloSD.h:100
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
bool fiducialCut_
Definition: HGCScintSD.h:51
bool useBirk_
Definition: HGCScintSD.h:52
const HGCalDDDConstants * hgcons_
Definition: HGCScintSD.h:44
HGCScintSD(const std::string &, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: HGCScintSD.cc:37
const double MeV
double distFromEdgeTrap(double x, double y, double z) const
double weight_
Definition: HGCScintSD.h:53
bool isItinFidVolume(const G4ThreeVector &)
Definition: HGCScintSD.cc:238
double minSlope() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGCalGeometryMode::GeometryMode geomMode() const
void initRun() override
Definition: HGCScintSD.cc:224
double tmaxHit
Definition: CaloSD.h:134
double getEnergyDeposit(const G4Step *) override
Definition: HGCScintSD.cc:95
double eminHit_
Definition: HGCScintSD.h:49
double slopeMin_
Definition: HGCScintSD.h:49
std::unique_ptr< HGCalNumberingScheme > numberingScheme_
Definition: HGCScintSD.h:45
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:462
std::string nameX_
Definition: HGCScintSD.h:47
HLT enums.
T get() const
Definition: EventSetup.h:62
DetId::Detector mydet_
Definition: HGCScintSD.h:46
int levelTop(int ind=0) const
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:652
Definition: vlib.h:208
void update(const BeginOfJob *) override
This routine will be called when the appropriate signal arrives.
Definition: HGCScintSD.cc:201
double birk3_
Definition: HGCScintSD.h:53
double getEnergyDeposit() const
Definition: CaloG4Hit.h:81
bool storeAllG4Hits_
Definition: HGCScintSD.h:51
bool filterHit(CaloG4Hit *, double) override
Definition: HGCScintSD.cc:227