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