CMS 3D CMS Logo

HFNoseSD.cc
Go to the documentation of this file.
1 // File: HFNoseSD.cc
3 // Description: Sensitive Detector class for High Granularity Calorimeter
5 
13 #include "G4LogicalVolumeStore.hh"
14 #include "G4LogicalVolume.hh"
15 #include "G4Step.hh"
16 #include "G4Track.hh"
17 #include "G4ParticleTable.hh"
18 #include "G4VProcess.hh"
19 #include "G4Trap.hh"
20 
21 #include <iostream>
22 #include <fstream>
23 #include <iomanip>
24 
25 //#define EDM_ML_DEBUG
26 
28  const HGCalDDDConstants* hgc,
29  const SensitiveDetectorCatalog& clg,
30  edm::ParameterSet const& p,
31  const SimTrackManager* manager)
32  : CaloSD(name,
33  clg,
34  p,
35  manager,
36  (float)(p.getParameter<edm::ParameterSet>("HFNoseSD").getParameter<double>("TimeSliceUnit")),
37  p.getParameter<edm::ParameterSet>("HFNoseSD").getParameter<bool>("IgnoreTrackID")),
38  hgcons_(hgc),
39  slopeMin_(0),
40  levelT1_(99),
41  levelT2_(99),
42  tan30deg_(std::tan(30.0 * CLHEP::deg)) {
43  numberingScheme_.reset(nullptr);
44  mouseBite_.reset(nullptr);
45 
46  edm::ParameterSet m_HFN = p.getParameter<edm::ParameterSet>("HFNoseSD");
47  eminHit_ = m_HFN.getParameter<double>("EminHit") * CLHEP::MeV;
48  fiducialCut_ = m_HFN.getParameter<bool>("FiducialCut");
49  distanceFromEdge_ = m_HFN.getParameter<double>("DistanceFromEdge");
50  storeAllG4Hits_ = m_HFN.getParameter<bool>("StoreAllG4Hits");
51  rejectMB_ = m_HFN.getParameter<bool>("RejectMouseBite");
52  waferRot_ = m_HFN.getParameter<bool>("RotatedWafer");
53  cornerMinMask_ = m_HFN.getParameter<int>("CornerMinMask");
54  angles_ = m_HFN.getUntrackedParameter<std::vector<double>>("WaferAngles");
55 
56  nameX_ = ((name.find("HFNoseHits") != std::string::npos) ? "HGCalHFNoseSensitive" : "HFNoseSensitive");
57 
58  if (storeAllG4Hits_) {
59  setUseMap(false);
61  }
62 
63 #ifdef EDM_ML_DEBUG
64  edm::LogVerbatim("HFNSim") << "**************************************************"
65  << "\n"
66  << "* *"
67  << "\n"
68  << "* Constructing a HFNoseSD with name " << name << "\n"
69  << "* *"
70  << "\n"
71  << "**************************************************";
72 #endif
73  edm::LogVerbatim("HFNSim") << "HFNoseSD:: Threshold for storing hits: " << eminHit_ << " for " << name;
74  edm::LogVerbatim("HFNSim") << "Flag for storing individual Geant4 Hits " << storeAllG4Hits_;
75  edm::LogVerbatim("HFNSim") << "Fiducial volume cut with cut from eta/phi "
76  << "boundary " << fiducialCut_ << " at " << distanceFromEdge_;
77  edm::LogVerbatim("HFNSim") << "Reject MosueBite Flag: " << rejectMB_ << " cuts along " << angles_.size()
78  << " axes: " << angles_[0] << ", " << angles_[1];
79 }
80 
81 double HFNoseSD::getEnergyDeposit(const G4Step* aStep) {
82  double r = aStep->GetPreStepPoint()->GetPosition().perp();
83  double z = std::abs(aStep->GetPreStepPoint()->GetPosition().z());
84 #ifdef EDM_ML_DEBUG
85  G4int parCode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
86  G4String parName = aStep->GetTrack()->GetDefinition()->GetParticleName();
87  G4LogicalVolume* lv = aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
88  edm::LogVerbatim("HFNSim") << "HFNoseSD: Hit from standard path from " << lv->GetName() << " for Track "
89  << aStep->GetTrack()->GetTrackID() << " (" << parCode << ":" << parName << ") R = " << r
90  << " Z = " << z << " slope = " << r / z << ":" << slopeMin_;
91 #endif
92  // Apply fiducial cut
93  if (r < z * slopeMin_) {
94 #ifdef EDM_ML_DEBUG
95  edm::LogVerbatim("HFNSim") << "HFNoseSD: Fiducial Volume cut";
96 #endif
97  return 0.0;
98  }
99 
100  double wt1 = getResponseWt(aStep->GetTrack());
101  double wt2 = aStep->GetTrack()->GetWeight();
102  double destep = weight_ * wt1 * (aStep->GetTotalEnergyDeposit());
103  if (wt2 > 0)
104  destep *= wt2;
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("HFNSim") << "HFNoseSD: weights= " << weight_ << ":" << wt1 << ":" << wt2 << " Total weight "
107  << weight_ * wt1 * wt2 << " deStep: " << aStep->GetTotalEnergyDeposit() << ":" << destep;
108 #endif
109  return destep;
110 }
111 
112 uint32_t HFNoseSD::setDetUnitId(const G4Step* aStep) {
113  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
114  const G4VTouchable* touch = preStepPoint->GetTouchable();
115 
116  //determine the exact position in global coordinates in the mass geometry
117  G4ThreeVector hitPoint = preStepPoint->GetPosition();
118  float globalZ = touch->GetTranslation(0).z();
119  int iz(globalZ > 0 ? 1 : -1);
120 
121  int layer, module, cell;
122  if ((touch->GetHistoryDepth() == levelT1_) || (touch->GetHistoryDepth() == levelT2_)) {
123  layer = touch->GetReplicaNumber(0);
124  module = -1;
125  cell = -1;
126 #ifdef EDM_ML_DEBUG
127  edm::LogVerbatim("HFNSim") << "DepthsTop: " << touch->GetHistoryDepth() << ":" << levelT1_ << ":" << levelT2_
128  << " name " << touch->GetVolume(0)->GetName() << " layer:module:cell " << layer << ":"
129  << module << ":" << cell;
130 #endif
131  } else {
132  layer = touch->GetReplicaNumber(3);
133  module = touch->GetReplicaNumber(2);
134  cell = touch->GetReplicaNumber(1);
135 #ifdef EDM_ML_DEBUG
136  edm::LogVerbatim("HFNSim") << "DepthsInside: " << touch->GetHistoryDepth() << " name "
137  << touch->GetVolume(0)->GetName() << " layer:module:cell " << layer << ":" << module
138  << ":" << cell;
139 #endif
140  }
141 #ifdef EDM_ML_DEBUG
142  G4Material* mat = aStep->GetPreStepPoint()->GetMaterial();
143  edm::LogVerbatim("HFNSim") << "Depths: " << touch->GetHistoryDepth() << " name " << touch->GetVolume(0)->GetName()
144  << ":" << touch->GetReplicaNumber(0) << " " << touch->GetVolume(1)->GetName() << ":"
145  << touch->GetReplicaNumber(1) << " " << touch->GetVolume(2)->GetName() << ":"
146  << touch->GetReplicaNumber(2) << " " << touch->GetVolume(3)->GetName() << ":"
147  << touch->GetReplicaNumber(3) << " " << touch->GetVolume(4)->GetName() << ":"
148  << touch->GetReplicaNumber(4) << " "
149  << " layer:module:cell " << layer << ":" << module << ":" << cell << " Material "
150  << mat->GetName() << ":" << mat->GetRadlen();
151 #endif
152  // The following statement should be examined later before elimination
153  if (aStep->GetPreStepPoint()->GetMaterial()->GetRadlen() > 100000.)
154  return 0;
155 
156  uint32_t id = setDetUnitId(layer, module, cell, iz, hitPoint);
157  if (rejectMB_ && id != 0) {
158  auto uv = HFNoseDetId(id).waferUV();
159 #ifdef EDM_ML_DEBUG
160  edm::LogVerbatim("HFNSim") << "ID " << std::hex << id << std::dec << " " << HFNoseDetId(id);
161 #endif
162  if (mouseBite_->exclude(hitPoint, iz, uv.first, uv.second)) {
163  id = 0;
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("HFNSim") << "Rejected by mousebite cutoff *****";
166 #endif
167  }
168  }
169  return id;
170 }
171 
172 void HFNoseSD::update(const BeginOfJob* job) {
173  if (hgcons_ != nullptr) {
176  levelT1_ = hgcons_->levelTop(0);
177  levelT2_ = hgcons_->levelTop(1);
178  double waferSize = hgcons_->waferSize(false);
179  double mouseBite = hgcons_->mouseBite(false);
180  mouseBiteCut_ = waferSize * tan30deg_ - mouseBite;
181 #ifdef EDM_ML_DEBUG
182  edm::LogVerbatim("HFNSim") << "HFNoseSD::Initialized with mode " << geom_mode_ << " Slope cut " << slopeMin_
183  << " top Level " << levelT1_ << ":" << levelT2_ << " wafer " << waferSize << ":"
184  << mouseBite;
185 #endif
186 
187  numberingScheme_ = std::make_unique<HFNoseNumberingScheme>(*hgcons_);
188  if (rejectMB_)
189  mouseBite_ = std::make_unique<HGCMouseBite>(*hgcons_, angles_, mouseBiteCut_, waferRot_);
190  } else {
191  throw cms::Exception("Unknown", "HFNoseSD") << "Cannot find HGCalDDDConstants for " << nameX_ << "\n";
192  }
193 }
194 
196 
197 bool HFNoseSD::filterHit(CaloG4Hit* aHit, double time) {
198  return ((time <= tmaxHit) && (aHit->getEnergyDeposit() > eminHit_));
199 }
200 
201 uint32_t HFNoseSD::setDetUnitId(int layer, int module, int cell, int iz, G4ThreeVector& pos) {
202  uint32_t id = numberingScheme_ ? numberingScheme_->getUnitID(layer, module, cell, iz, pos, weight_) : 0;
203  if (cornerMinMask_ > 2) {
205  id = 0;
206  }
207  return id;
208 }
209 
210 bool HFNoseSD::isItinFidVolume(const G4ThreeVector& pos) {
211  if (fiducialCut_) {
212  return (hgcons_->distFromEdgeHex(pos.x(), pos.y(), pos.z()) > distanceFromEdge_);
213  } else {
214  return true;
215  }
216 }
HFNoseSD::angles_
std::vector< double > angles_
Definition: HFNoseSD.h:53
HFNoseSD::numberingScheme_
std::unique_ptr< HFNoseNumberingScheme > numberingScheme_
Definition: HFNoseSD.h:43
HFNoseSD::initRun
void initRun() override
Definition: HFNoseSD.cc:195
SimTrackManager
Definition: SimTrackManager.h:35
electrons_cff.bool
bool
Definition: electrons_cff.py:366
CaloSD::tmaxHit
double tmaxHit
Definition: CaloSD.h:141
HFNoseSD::filterHit
bool filterHit(CaloG4Hit *, double) override
Definition: HFNoseSD.cc:197
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
HFNoseSD::distanceFromEdge_
double distanceFromEdge_
Definition: HFNoseSD.h:48
HFNoseSD.h
HGCalDDDConstants::geomMode
HGCalGeometryMode::GeometryMode geomMode() const
Definition: HGCalDDDConstants.h:54
edm
HLT enums.
Definition: AlignableModifier.h:19
HGCalGeometryMode.h
pos
Definition: PixelAliasList.h:18
HFNoseSD::storeAllG4Hits_
bool storeAllG4Hits_
Definition: HFNoseSD.h:50
protons_cff.time
time
Definition: protons_cff.py:35
MeV
const double MeV
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
HFNoseDetId.h
HFNoseSD::levelT1_
int levelT1_
Definition: HFNoseSD.h:49
HFNoseDetId
Definition: HFNoseDetId.h:22
HFNoseSD::fiducialCut_
bool fiducialCut_
Definition: HFNoseSD.h:51
HFNoseSD::mouseBiteCut_
double mouseBiteCut_
Definition: HFNoseSD.h:48
HGCalDDDConstants
Definition: HGCalDDDConstants.h:27
hgc_digi
Definition: HGCDigitizerTypes.h:10
HFNoseSD::isItinFidVolume
bool isItinFidVolume(const G4ThreeVector &)
Definition: HFNoseSD.cc:210
HFNoseSD::HFNoseSD
HFNoseSD(const std::string &, const HGCalDDDConstants *, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: HFNoseSD.cc:27
FastMath.h
CaloSD::getResponseWt
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:874
DetId
Definition: DetId.h:17
HFNoseSD::weight_
double weight_
Definition: HFNoseSD.h:47
HFNoseSD::rejectMB_
bool rejectMB_
Definition: HFNoseSD.h:51
HFNoseSD::cornerMinMask_
int cornerMinMask_
Definition: HFNoseSD.h:49
HFNoseSD::waferRot_
bool waferRot_
Definition: HFNoseSD.h:51
CaloG4Hit::getEnergyDeposit
double getEnergyDeposit() const
Definition: CaloG4Hit.h:78
DDAxes::z
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
BeginOfJob
Definition: BeginOfJob.h:8
HFNoseSD::geom_mode_
HGCalGeometryMode::GeometryMode geom_mode_
Definition: HFNoseSD.h:46
HGCalDDDConstants::mouseBite
double mouseBite(bool reco) const
Definition: HGCalDDDConstants.cc:897
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
CLHEP
Definition: CocoaGlobals.h:27
HFNoseDetId::waferUV
std::pair< int, int > waferUV() const
Definition: HFNoseDetId.h:81
edm::ParameterSet
Definition: ParameterSet.h:47
HFNoseSD::levelT2_
int levelT2_
Definition: HFNoseSD.h:49
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ParameterSet
Definition: Functions.h:16
HFNoseSD::setDetUnitId
uint32_t setDetUnitId(const G4Step *step) override
Definition: HFNoseSD.cc:112
HFNoseSD::getEnergyDeposit
double getEnergyDeposit(const G4Step *) override
Definition: HFNoseSD.cc:81
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
HFNoseSD::tan30deg_
const double tan30deg_
Definition: HFNoseSD.h:52
CaloSD::setNumberCheckedHits
void setNumberCheckedHits(int val)
Definition: CaloSD.h:119
TrackInformation.h
CaloG4Hit
Definition: CaloG4Hit.h:32
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HFNoseSD::mouseBite_
std::unique_ptr< HGCMouseBite > mouseBite_
Definition: HFNoseSD.h:44
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HFNoseSD::nameX_
std::string nameX_
Definition: HFNoseSD.h:45
callgraph.module
module
Definition: callgraph.py:61
HGCalDDDConstants::minSlope
double minSlope() const
Definition: HGCalDDDConstants.h:97
HFNoseSD::update
void update(const BeginOfJob *) override
This routine will be called when the appropriate signal arrives.
Definition: HFNoseSD.cc:172
std
Definition: JetResolutionObject.h:76
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
Exception
Definition: hltDiff.cc:245
HFNoseSD::hgcons_
const HGCalDDDConstants * hgcons_
Definition: HFNoseSD.h:42
HFNoseSD::eminHit_
double eminHit_
Definition: HFNoseSD.h:47
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
HGCalDDDConstants::distFromEdgeHex
double distFromEdgeHex(double x, double y, double z) const
Definition: HGCalDDDConstants.cc:280
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HFNoseSD::slopeMin_
double slopeMin_
Definition: HFNoseSD.h:47
Exception.h
HGCalDDDConstants::levelTop
int levelTop(int ind=0) const
Definition: HGCalDDDConstants.h:89
CaloSD::setUseMap
void setUseMap(bool val)
Definition: CaloSD.h:108
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGCalDDDConstants.h
HGCalDDDConstants::waferSize
double waferSize(bool reco) const
Definition: HGCalDDDConstants.h:183
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
HGCalDDDConstants::maskCell
bool maskCell(const DetId &id, int corners) const
Definition: HGCalDDDConstants.cc:764
CaloSD
Definition: CaloSD.h:39