CMS 3D CMS Logo

ZdcSD.cc
Go to the documentation of this file.
1 // File: ZdcSD.cc
3 // Date: 03.01
4 // Description: Sensitive Detector class for Zdc
5 // Modifications:
12 
13 #include "G4SDManager.hh"
14 #include "G4Step.hh"
15 #include "G4Track.hh"
16 #include "G4VProcess.hh"
17 #include "G4ios.hh"
18 #include "G4Cerenkov.hh"
19 #include "G4ParticleTable.hh"
20 #include "CLHEP/Units/GlobalSystemOfUnits.h"
21 #include "CLHEP/Units/GlobalPhysicalConstants.h"
22 #include "Randomize.hh"
23 #include "G4Poisson.hh"
24 
26  const edm::EventSetup& es,
27  const SensitiveDetectorCatalog& clg,
28  edm::ParameterSet const& p,
29  const SimTrackManager* manager)
30  : CaloSD(name, es, clg, p, manager) {
31  edm::ParameterSet m_ZdcSD = p.getParameter<edm::ParameterSet>("ZdcSD");
32  useShowerLibrary = m_ZdcSD.getParameter<bool>("UseShowerLibrary");
33  useShowerHits = m_ZdcSD.getParameter<bool>("UseShowerHits");
34  zdcHitEnergyCut = m_ZdcSD.getParameter<double>("ZdcHitEnergyCut") * GeV;
35  thFibDir = m_ZdcSD.getParameter<double>("FiberDirection");
36  verbosity = m_ZdcSD.getParameter<int>("Verbosity");
37  int verbn = verbosity / 10;
38  verbosity %= 10;
40 
41  edm::LogVerbatim("ZdcSD") << "***************************************************\n"
42  << "* *\n"
43  << "* Constructing a ZdcSD with name " << name << " *\n"
44  << "* *\n"
45  << "***************************************************";
46 
47  edm::LogVerbatim("ZdcSD") << "\nUse of shower library is set to " << useShowerLibrary
48  << "\nUse of Shower hits method is set to " << useShowerHits;
49 
50  edm::LogVerbatim("ZdcSD") << "\nEnergy Threshold Cut set to " << zdcHitEnergyCut / GeV << " (GeV)";
51 
52  if (useShowerLibrary) {
53  showerLibrary.reset(new ZdcShowerLibrary(name, p));
54  setParameterized(true);
55  } else {
56  showerLibrary.reset(nullptr);
57  }
58 }
59 
60 void ZdcSD::initRun() { hits.clear(); }
61 
62 bool ZdcSD::getFromLibrary(const G4Step* aStep) {
63  bool ok = true;
64 
65  auto const preStepPoint = aStep->GetPreStepPoint();
66  auto const theTrack = aStep->GetTrack();
67 
68  double etrack = preStepPoint->GetKineticEnergy();
69  int primaryID = setTrackID(aStep);
70 
71  hits.clear();
72 
73  // Reset entry point for new primary
74  resetForNewPrimary(aStep);
75 
76  if (etrack >= zdcHitEnergyCut) {
77  // create hits only if above threshold
78 
79  LogDebug("ForwardSim") << "----------------New track------------------------------\n"
80  << "Incident EnergyTrack: " << etrack << " MeV \n"
81  << "Zdc Cut Energy for Hits: " << zdcHitEnergyCut << " MeV \n"
82  << "ZdcSD::getFromLibrary " << hits.size() << " hits for " << GetName() << " of "
83  << primaryID << " with " << theTrack->GetDefinition()->GetParticleName() << " of " << etrack
84  << " MeV\n";
85 
86  hits.swap(showerLibrary.get()->getHits(aStep, ok));
87  }
88 
89  incidentEnergy = etrack;
90  entrancePoint = preStepPoint->GetPosition();
91  for (unsigned int i = 0; i < hits.size(); i++) {
92  posGlobal = hits[i].position;
93  entranceLocal = hits[i].entryLocal;
94  double time = hits[i].time;
95  unsigned int unitID = hits[i].detID;
96  edepositHAD = hits[i].DeHad;
97  edepositEM = hits[i].DeEM;
98  currentID.setID(unitID, time, primaryID, 0);
99  processHit(aStep);
100 
101  LogDebug("ForwardSim") << "ZdcSD: Final Hit number:" << i << "-->"
102  << "New HitID: " << currentHit->getUnitID()
103  << " New Hit trackID: " << currentHit->getTrackID()
104  << " New EM Energy: " << currentHit->getEM() / GeV
105  << " New HAD Energy: " << currentHit->getHadr() / GeV
106  << " New HitEntryPoint: " << currentHit->getEntryLocal()
107  << " New IncidentEnergy: " << currentHit->getIncidentEnergy() / GeV
108  << " New HitPosition: " << posGlobal;
109  }
110  return ok;
111 }
112 
113 double ZdcSD::getEnergyDeposit(const G4Step* aStep) {
114  double NCherPhot = 0.;
115 
116  // preStepPoint information
117  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
118  G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
119  const G4String& nameVolume = currentPV->GetName();
120 
121  const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
122  const G4ThreeVector& hit_mom = preStepPoint->GetMomentumDirection();
123  G4double stepL = aStep->GetStepLength() / cm;
124  G4double beta = preStepPoint->GetBeta();
125  G4double charge = preStepPoint->GetCharge();
126 
127  // postStepPoint information
128  G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
129  G4VPhysicalVolume* postPV = postStepPoint->GetPhysicalVolume();
130  const G4String& postnameVolume = postPV->GetName();
131 
132  // theTrack information
133  G4Track* theTrack = aStep->GetTrack();
134  G4String particleType = theTrack->GetDefinition()->GetParticleName();
135  const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
136  G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
137 
138  // calculations
139  float costheta =
140  vert_mom.z() / sqrt(vert_mom.x() * vert_mom.x() + vert_mom.y() * vert_mom.y() + vert_mom.z() * vert_mom.z());
141  float theta = std::acos(std::min(std::max(costheta, -1.f), 1.f));
142  float eta = -std::log(std::tan(theta * 0.5f));
143  float phi = -100.;
144  if (vert_mom.x() != 0)
145  phi = std::atan2(vert_mom.y(), vert_mom.x());
146  if (phi < 0.)
147  phi += twopi;
148 
149  // Get the total energy deposit
150  double stepE = aStep->GetTotalEnergyDeposit();
151  LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: \n"
152  << " preStepPoint: " << nameVolume << "," << stepL << "," << stepE << "," << beta << ","
153  << charge << "\n"
154  << " postStepPoint: " << postnameVolume << "," << costheta << "," << theta << "," << eta
155  << "," << phi << "," << particleType << " id= " << theTrack->GetTrackID()
156  << " Etot(GeV)= " << theTrack->GetTotalEnergy() / GeV;
157 
158  const double bThreshold = 0.67;
159  if ((beta > bThreshold) && (charge != 0) && (nameVolume == "ZDC_EMFiber" || nameVolume == "ZDC_HadFiber")) {
160  LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: pass ";
161 
162  const float nMedium = 1.4925;
163  // float photEnSpectrDL = 10714.285714;
164  // photEnSpectrDL = (1./400.nm-1./700.nm)*10000000.cm/nm; /* cm-1 */
165 
166  const float photEnSpectrDE = 1.24;
167  // E = 2pi*(1./137.)*(eV*cm/370.)/lambda = 12.389184*(eV*cm)/lambda
168  // Emax = 12.389184*(eV*cm)/400nm*10-7cm/nm = 3.01 eV
169  // Emin = 12.389184*(eV*cm)/700nm*10-7cm/nm = 1.77 eV
170  // delE = Emax - Emin = 1.24 eV
171 
172  const float effPMTandTransport = 0.15;
173 
174  // Check these values
175  const float thFullRefl = 23.;
176  float thFullReflRad = thFullRefl * pi / 180.;
177 
178  float thFibDirRad = thFibDir * pi / 180.;
179 
180  // at which theta the point is located:
181  // float th1 = hitPoint.theta();
182 
183  // theta of charged particle in LabRF(hit momentum direction):
184  float costh = hit_mom.z() / sqrt(hit_mom.x() * hit_mom.x() + hit_mom.y() * hit_mom.y() + hit_mom.z() * hit_mom.z());
185  float th = acos(std::min(std::max(costh, -1.f), 1.f));
186  // just in case (can do both standard ranges of phi):
187  if (th < 0.)
188  th += twopi;
189 
190  // theta of cone with Cherenkov photons w.r.t.direction of charged part.:
191  float costhcher = 1. / (nMedium * beta);
192  float thcher = acos(std::min(std::max(costhcher, -1.f), 1.f));
193 
194  // diff thetas of charged part. and quartz direction in LabRF:
195  float DelFibPart = std::abs(th - thFibDirRad);
196 
197  // define real distances:
198  float d = std::abs(std::tan(th) - std::tan(thFibDirRad));
199 
200  float a = std::tan(thFibDirRad) + std::tan(std::abs(thFibDirRad - thFullReflRad));
201  float r = std::tan(th) + std::tan(std::abs(th - thcher));
202 
203  // define losses d_qz in cone of full reflection inside quartz direction
204  float d_qz = -1;
205  float variant = -1;
206 
207  // if (d > (r+a))
208  if (DelFibPart > (thFullReflRad + thcher)) {
209  variant = 0.;
210  d_qz = 0.;
211  } else {
212  // if ((DelFibPart + thcher) < thFullReflRad ) [(d+r) < a]
213  if ((th + thcher) < (thFibDirRad + thFullReflRad) && (th - thcher) > (thFibDirRad - thFullReflRad)) {
214  variant = 1.;
215  d_qz = 1.;
216  } else {
217  // if ((thcher - DelFibPart ) > thFullReflRad ) [(r-d) > a]
218  if ((thFibDirRad + thFullReflRad) < (th + thcher) && (thFibDirRad - thFullReflRad) > (th - thcher)) {
219  variant = 2.;
220  d_qz = 0.;
221  } else {
222  variant = 3.; // d_qz is calculated below
223 
224  // use crossed length of circles(cone projection) - dC1/dC2 :
225  float arg_arcos = 0.;
226  float tan_arcos = 2. * a * d;
227  if (tan_arcos != 0.)
228  arg_arcos = (r * r - a * a - d * d) / tan_arcos;
229  // std::cout.testOut << " d_qz: " << r << "," << a << "," << d << " " << tan_arcos << " " << arg_arcos;
230  arg_arcos = std::abs(arg_arcos);
231  // std::cout.testOut << "," << arg_arcos;
232  float th_arcos = acos(std::min(std::max(arg_arcos, -1.f), 1.f));
233  // std::cout.testOut << " " << th_arcos;
234  d_qz = th_arcos / twopi;
235  // std::cout.testOut << " " << d_qz;
236  d_qz = std::abs(d_qz);
237  // std::cout.testOut << "," << d_qz;
238  }
239  }
240  }
241  double meanNCherPhot = 0.;
242  int poissNCherPhot = 0;
243  if (d_qz > 0) {
244  meanNCherPhot = 370. * charge * charge * (1. - 1. / (nMedium * nMedium * beta * beta)) * photEnSpectrDE * stepL;
245 
246  poissNCherPhot = std::max((int)G4Poisson(meanNCherPhot), 0);
247  NCherPhot = poissNCherPhot * effPMTandTransport * d_qz;
248  }
249 
250  LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: gED: " << stepE << "," << costh << "," << th << ","
251  << costhcher << "," << thcher << "," << DelFibPart << "," << d << "," << a << "," << r << ","
252  << hitPoint << "," << hit_mom << "," << vert_mom << "," << localPoint << "," << charge << ","
253  << beta << "," << stepL << "," << d_qz << "," << variant << "," << meanNCherPhot << ","
254  << poissNCherPhot << "," << NCherPhot;
255  // --constants-----------------
256  // << "," << photEnSpectrDE
257  // << "," << nMedium
258  // << "," << bThreshold
259  // << "," << thFibDirRad
260  // << "," << thFullReflRad
261  // << "," << effPMTandTransport
262  // --other variables-----------
263  // << "," << curprocess
264  // << "," << nameProcess
265  // << "," << name
266  // << "," << rad
267  // << "," << mat
268 
269  } else {
270  // determine failure mode: beta, charge, and/or nameVolume
271  if (beta <= bThreshold)
272  LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: fail beta=" << beta;
273  if (charge == 0)
274  LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: fail charge=0";
275  if (!(nameVolume == "ZDC_EMFiber" || nameVolume == "ZDC_HadFiber"))
276  LogDebug("ForwardSim") << "ZdcSD:: getEnergyDeposit: fail nv=" << nameVolume;
277  }
278 
279  return NCherPhot;
280 }
281 
282 uint32_t ZdcSD::setDetUnitId(const G4Step* aStep) {
283  return (numberingScheme.get() == nullptr ? 0 : numberingScheme.get()->getUnitID(aStep));
284 }
285 
287  if (scheme != nullptr) {
288  edm::LogVerbatim("ZdcSD") << "ZdcSD: updates numbering scheme for " << GetName();
289  numberingScheme.reset(scheme);
290  }
291 }
CaloSD::edepositHAD
float edepositHAD
Definition: CaloSD.h:129
SimTrackManager
Definition: SimTrackManager.h:35
CaloG4Hit::getTrackID
int getTrackID() const
Definition: CaloG4Hit.h:64
mps_fire.i
i
Definition: mps_fire.py:355
ZdcSD::setNumberingScheme
void setNumberingScheme(ZdcNumberingScheme *scheme)
Definition: ZdcSD.cc:286
ESTransientHandle.h
MessageLogger.h
ZdcSD::thFibDir
double thFibDir
Definition: ZdcSD.h:35
CaloSD::currentHit
CaloG4Hit * currentHit
Definition: CaloSD.h:135
ZdcSD::numberingScheme
std::unique_ptr< ZdcNumberingScheme > numberingScheme
Definition: ZdcSD.h:39
ZdcSD::hits
std::vector< ZdcShowerLibrary::Hit > hits
Definition: ZdcSD.h:40
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
ZdcSD::useShowerHits
bool useShowerHits
Definition: ZdcSD.h:34
min
T min(T a, T b)
Definition: MathUtil.h:58
CaloG4Hit::getUnitID
uint32_t getUnitID() const
Definition: CaloG4Hit.h:65
zMuMuMuonUserData.beta
beta
Definition: zMuMuMuonUserData.py:10
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CaloSD::edepositEM
float edepositEM
Definition: CaloSD.h:129
ZdcSD::ZdcSD
ZdcSD(const std::string &, const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: ZdcSD.cc:25
CaloG4Hit::getEntryLocal
math::XYZPoint getEntryLocal() const
Definition: CaloG4Hit.h:49
ZdcSD.h
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
ZdcSD::verbosity
int verbosity
Definition: ZdcSD.h:33
CaloSD::setTrackID
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:592
CaloHitID::setID
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
Definition: CaloHitID.cc:40
PVValHelper::eta
Definition: PVValidationHelpers.h:69
ZdcNumberingScheme
Definition: ZdcNumberingScheme.h:13
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
CaloSD::entrancePoint
G4ThreeVector entrancePoint
Definition: CaloSD.h:125
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
CaloSD::processHit
void processHit(const G4Step *step)
Definition: CaloSD.h:103
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
CaloSD::posGlobal
G4ThreeVector posGlobal
Definition: CaloSD.h:127
CaloSD::currentID
CaloHitID currentID
Definition: CaloSD.h:131
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
CaloG4Hit::getEM
double getEM() const
Definition: CaloG4Hit.h:55
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
a
double a
Definition: hdecay.h:119
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
CaloSD::incidentEnergy
float incidentEnergy
Definition: CaloSD.h:128
GeV
const double GeV
Definition: MathUtil.h:16
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
edm::LogVerbatim
Definition: MessageLogger.h:297
CaloSD::resetForNewPrimary
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:422
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:57
TrackInformation.h
generator_cfi.scheme
scheme
Definition: generator_cfi.py:22
alignCSCRings.r
r
Definition: alignCSCRings.py:93
DDAxes::phi
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
g4SimHits_cfi.ZdcShowerLibrary
ZdcShowerLibrary
Definition: g4SimHits_cfi.py:517
ZdcSD::setDetUnitId
uint32_t setDetUnitId(const G4Step *step) override
Definition: ZdcSD.cc:282
CaloSD::setParameterized
void setParameterized(bool val)
Definition: CaloSD.h:100
CaloG4Hit::getIncidentEnergy
double getIncidentEnergy() const
Definition: CaloG4Hit.h:61
CaloSD::entranceLocal
G4ThreeVector entranceLocal
Definition: CaloSD.h:126
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
ZdcSD::zdcHitEnergyCut
double zdcHitEnergyCut
Definition: ZdcSD.h:36
ztail.d
d
Definition: ztail.py:151
pi
const Double_t pi
Definition: trackSplitPlot.h:36
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ZdcSD::initRun
void initRun() override
Definition: ZdcSD.cc:60
PbPb_ZMuSkimMuonDPG_cff.particleType
particleType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:27
ZdcSD::useShowerLibrary
bool useShowerLibrary
Definition: ZdcSD.h:34
ntuplemaker.time
time
Definition: ntuplemaker.py:310
ZdcSD::showerLibrary
std::unique_ptr< ZdcShowerLibrary > showerLibrary
Definition: ZdcSD.h:38
CaloG4Hit::getHadr
double getHadr() const
Definition: CaloG4Hit.h:58
ZdcSD::getEnergyDeposit
double getEnergyDeposit(const G4Step *) override
Definition: ZdcSD.cc:113
CaloSD
Definition: CaloSD.h:38
ZdcSD::getFromLibrary
bool getFromLibrary(const G4Step *) override
Definition: ZdcSD.cc:62