CMS 3D CMS Logo

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