CMS 3D CMS Logo

HcalTB02SD.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalTestBeam
4 // Class : HcalTB02SD
5 //
6 // Implementation:
7 // Sensitive Detector class for Hcal Test Beam 2002 detectors
8 //
9 // Original Author:
10 // Created: Sun 21 10:14:34 CEST 2006
11 //
12 
13 // system include files
14 
15 // user include files
25 #include "HcalTB02SD.h"
28 
29 #include "G4Step.hh"
30 #include "G4Track.hh"
31 #include "G4VProcess.hh"
32 
33 #include "G4SystemOfUnits.hh"
34 
35 //
36 // constructors and destructor
37 //
38 
40  const edm::EventSetup& es,
41  const SensitiveDetectorCatalog& clg,
42  edm::ParameterSet const& p,
43  const SimTrackManager* manager)
44  : CaloSD(name, es, clg, p, manager), numberingScheme(nullptr) {
45  edm::ParameterSet m_SD = p.getParameter<edm::ParameterSet>("HcalTB02SD");
46  useBirk = m_SD.getUntrackedParameter<bool>("UseBirkLaw", false);
47  birk1 = m_SD.getUntrackedParameter<double>("BirkC1", 0.013) * (g / (MeV * cm2));
48  birk2 = m_SD.getUntrackedParameter<double>("BirkC2", 0.0568);
49  birk3 = m_SD.getUntrackedParameter<double>("BirkC3", 1.75);
50  useWeight = true;
51 
53  if (name == "EcalHitsEB") {
54  scheme = dynamic_cast<HcalTB02NumberingScheme*>(new HcalTB02XtalNumberingScheme());
55  useBirk = false;
56  } else if (name == "HcalHits") {
57  scheme = dynamic_cast<HcalTB02NumberingScheme*>(new HcalTB02HcalNumberingScheme());
58  useWeight = false;
59  } else {
60  edm::LogWarning("HcalTBSim") << "HcalTB02SD: ReadoutName " << name << " not supported\n";
61  }
62 
63  if (scheme)
64  setNumberingScheme(scheme);
65  LogDebug("HcalTBSim") << "***************************************************"
66  << "\n"
67  << "* *"
68  << "\n"
69  << "* Constructing a HcalTB02SD with name " << GetName() << "\n"
70  << "* *"
71  << "\n"
72  << "***************************************************";
73  edm::LogInfo("HcalTBSim") << "HcalTB02SD:: Use of Birks law is set to " << useBirk
74  << " with three constants kB = " << birk1 << ", C1 = " << birk2
75  << ", C2 = " << birk3;
76 
77  if (useWeight)
78  initMap(name, es);
79 }
80 
82  if (numberingScheme)
83  delete numberingScheme;
84 }
85 
86 //
87 // member functions
88 //
89 
90 double HcalTB02SD::getEnergyDeposit(const G4Step* aStep) {
91  auto const preStepPoint = aStep->GetPreStepPoint();
92  auto const& nameVolume = preStepPoint->GetPhysicalVolume()->GetName();
93 
94  // take into account light collection curve for crystals
95  double weight = 1.;
96  if (useWeight)
97  weight *= curve_LY(nameVolume, preStepPoint);
98  if (useBirk)
99  weight *= getAttenuation(aStep, birk1, birk2, birk3);
100  double edep = aStep->GetTotalEnergyDeposit() * weight;
101  LogDebug("HcalTBSim") << "HcalTB02SD:: " << nameVolume << " Light Collection Efficiency " << weight
102  << " Weighted Energy Deposit " << edep / MeV << " MeV";
103  return edep;
104 }
105 
106 uint32_t HcalTB02SD::setDetUnitId(const G4Step* aStep) {
107  return (numberingScheme == nullptr ? 0 : (uint32_t)(numberingScheme->getUnitID(aStep)));
108 }
109 
111  if (scheme != nullptr) {
112  edm::LogInfo("HcalTBSim") << "HcalTB02SD: updates numbering scheme for " << GetName();
113  if (numberingScheme)
114  delete numberingScheme;
116  }
117 }
118 
121  es.get<IdealGeometryRecord>().get(cpv);
122 
123  G4String attribute = "ReadOutName";
124  DDSpecificsMatchesValueFilter filter{DDValue(attribute, sd, 0)};
125  DDFilteredView fv(*cpv, filter);
126  fv.firstChild();
127 
128  bool dodet = true;
129  while (dodet) {
130  const DDSolid& sol = fv.logicalPart().solid();
131  const std::vector<double>& paras = sol.parameters();
132  G4String name = sol.name().name();
133  LogDebug("HcalTBSim") << "HcalTB02SD::initMap (for " << sd << "): Solid " << name << " Shape " << sol.shape()
134  << " Parameter 0 = " << paras[0];
135  if (sol.shape() == DDSolidShape::ddtrap) {
136  double dz = 2 * paras[0];
137  lengthMap.insert(std::pair<G4String, double>(name, dz));
138  }
139  dodet = fv.next();
140  }
141  LogDebug("HcalTBSim") << "HcalTB02SD: Length Table for " << attribute << " = " << sd << ":";
142  std::map<G4String, double>::const_iterator it = lengthMap.begin();
143  int i = 0;
144  for (; it != lengthMap.end(); it++, i++) {
145  LogDebug("HcalTBSim") << " " << i << " " << it->first << " L = " << it->second;
146  }
147 }
148 
149 double HcalTB02SD::curve_LY(const G4String& nameVolume, const G4StepPoint* stepPoint) {
150  double weight = 1.;
151  G4ThreeVector localPoint = setToLocal(stepPoint->GetPosition(), stepPoint->GetTouchable());
152  double crlength = crystalLength(nameVolume);
153  double dapd = 0.5 * crlength - localPoint.z();
154  if (dapd >= -0.1 || dapd <= crlength + 0.1) {
155  if (dapd <= 100.)
156  weight = 1.05 - dapd * 0.0005;
157  } else {
158  edm::LogWarning("HcalTBSim") << "HcalTB02SD: light coll curve : wrong "
159  << "distance to APD " << dapd << " crlength = " << crlength
160  << " crystal name = " << nameVolume << " z of localPoint = " << localPoint.z()
161  << " take weight = " << weight;
162  }
163  LogDebug("HcalTBSim") << "HcalTB02SD, light coll curve : " << dapd << " crlength = " << crlength
164  << " crystal name = " << nameVolume << " z of localPoint = " << localPoint.z()
165  << " take weight = " << weight;
166  return weight;
167 }
168 
169 double HcalTB02SD::crystalLength(const G4String& name) {
170  double length = 230.;
171  std::map<G4String, double>::const_iterator it = lengthMap.find(name);
172  if (it != lengthMap.end())
173  length = it->second;
174  return length;
175 }
#define LogDebug(id)
T getParameter(std::string const &) const
double birk2
Definition: HcalTB02SD.h:52
T getUntrackedParameter(std::string const &, T const &) const
std::map< G4String, double > lengthMap
Definition: HcalTB02SD.h:53
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:121
HcalTB02NumberingScheme * numberingScheme
Definition: HcalTB02SD.h:49
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
void initMap(const std::string &, const edm::EventSetup &)
Definition: HcalTB02SD.cc:119
const N & name() const
Definition: DDBase.h:59
double crystalLength(const G4String &)
Definition: HcalTB02SD.cc:169
Definition: CaloSD.h:38
#define nullptr
double getEnergyDeposit(const G4Step *) override
Definition: HcalTB02SD.cc:90
Definition: weight.py:1
uint32_t setDetUnitId(const G4Step *step) override
Definition: HcalTB02SD.cc:106
bool useWeight
Definition: HcalTB02SD.h:50
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
bool useBirk
Definition: HcalTB02SD.h:51
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
HcalTB02SD(const std::string &, const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: HcalTB02SD.cc:39
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
~HcalTB02SD() override
Definition: HcalTB02SD.cc:81
const double MeV
double curve_LY(const G4String &, const G4StepPoint *)
Definition: HcalTB02SD.cc:149
double birk3
Definition: HcalTB02SD.h:52
bool next()
set current node to the next node in the filtered tree
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:119
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:291
void setNumberingScheme(HcalTB02NumberingScheme *scheme)
Definition: HcalTB02SD.cc:110
virtual int getUnitID(const G4Step *aStep) const =0
double sd
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:434
T get() const
Definition: EventSetup.h:73
bool firstChild()
set the current node to the first child ...
static TrackerG4SimHitNumberingScheme & numberingScheme(const GeometricDet &det)
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
double birk1
Definition: HcalTB02SD.h:52