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