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 
17 
18 #include "G4SDManager.hh"
19 #include "G4Step.hh"
20 #include "G4Track.hh"
21 #include "G4VProcess.hh"
22 #include "G4ios.hh"
23 #include "G4Cerenkov.hh"
24 #include "G4ParticleTable.hh"
25 #include "G4PhysicalConstants.hh"
26 #include "CLHEP/Units/GlobalSystemOfUnits.h"
27 #include "CLHEP/Units/GlobalPhysicalConstants.h"
28 #include "Randomize.hh"
29 #include "G4Poisson.hh"
30 #include "G4TwoVector.hh"
31 
32 //#define EDM_ML_DEBUG
33 
35  const SensitiveDetectorCatalog& clg,
36  edm::ParameterSet const& p,
37  const SimTrackManager* manager)
38  : CaloSD(name, clg, p, manager) {
39  edm::ParameterSet m_ZdcSD = p.getParameter<edm::ParameterSet>("ZdcSD");
40  useShowerLibrary = m_ZdcSD.getParameter<bool>("UseShowerLibrary");
41  useShowerHits = m_ZdcSD.getParameter<bool>("UseShowerHits");
42  zdcHitEnergyCut = m_ZdcSD.getParameter<double>("ZdcHitEnergyCut") * CLHEP::GeV;
43  thFibDir = m_ZdcSD.getParameter<double>("FiberDirection");
44  verbosity = m_ZdcSD.getParameter<int>("Verbosity");
45  int verbn = verbosity / 10;
46  verbosity %= 10;
47  numberingScheme = std::make_unique<ZdcNumberingScheme>(verbn);
48 
49  edm::LogVerbatim("ForwardSim") << "***************************************************\n"
50  << "* *\n"
51  << "* Constructing a ZdcSD with name " << name << " *\n"
52  << "* *\n"
53  << "***************************************************";
54 
55  edm::LogVerbatim("ForwardSim") << "\nUse of shower library is set to " << useShowerLibrary
56  << "\nUse of Shower hits method is set to " << useShowerHits;
57 
58  edm::LogVerbatim("ForwardSim") << "\nEnergy Threshold Cut set to " << zdcHitEnergyCut / CLHEP::GeV << " (GeV)";
59 
60  if (useShowerLibrary) {
61  showerLibrary = std::make_unique<ZdcShowerLibrary>(name, p);
62  setParameterized(true);
63  } else {
64  showerLibrary.reset(nullptr);
65  }
66 }
67 
69  if (useShowerLibrary) {
70  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
71  showerLibrary->initRun(theParticleTable);
72  }
73  hits.clear();
74 }
75 
76 bool ZdcSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
77  if (useShowerLibrary)
78  getFromLibrary(aStep);
79 
80 #ifdef EDM_ML_DEBUG
81  edm::LogVerbatim("ZdcSD") << "ZdcSD::" << GetName() << " ID= " << aStep->GetTrack()->GetTrackID()
82  << " prID= " << aStep->GetTrack()->GetParentID()
83  << " Eprestep= " << aStep->GetPreStepPoint()->GetKineticEnergy()
84  << " step= " << aStep->GetStepLength() << " Edep= " << aStep->GetTotalEnergyDeposit();
85 #endif
86  if (useShowerHits) {
87  // check unitID
88  unsigned int unitID = setDetUnitId(aStep);
89  if (unitID == 0)
90  return false;
91 
92  auto const theTrack = aStep->GetTrack();
93  uint16_t depth = getDepth(aStep);
94 
95  double time = theTrack->GetGlobalTime() / nanosecond;
96  int primaryID = getTrackID(theTrack);
97  currentID[0].setID(unitID, time, primaryID, depth);
98  double energy = calculateCherenkovDeposit(aStep);
99 
100  // Russian Roulette
101  double wt2 = theTrack->GetWeight();
102  if (wt2 > 0.0) {
103  energy *= wt2;
104  }
105 
107  edepositEM = energy;
108  edepositHAD = 0;
109  } else {
110  edepositEM = 0;
112  }
113  if (!hitExists(aStep, 0) && energy > 0.) {
114 #ifdef EDM_ML_DEBUG
115  G4ThreeVector pre = aStep->GetPreStepPoint()->GetPosition();
116  edm::LogVerbatim("ZdcSD") << pre.x() << " " << pre.y() << " " << pre.z();
117 #endif
118  currentHit[0] = CaloSD::createNewHit(aStep, theTrack, 0);
119  }
120  }
121  return true;
122 }
123 
124 bool ZdcSD::getFromLibrary(const G4Step* aStep) {
125  bool ok = true;
126 
127  auto const preStepPoint = aStep->GetPreStepPoint();
128 
129  double etrack = preStepPoint->GetKineticEnergy();
130  int primaryID = setTrackID(aStep);
131 
132  hits.clear();
133 
134  // Reset entry point for new primary
135  resetForNewPrimary(aStep);
136 
137  if (etrack >= zdcHitEnergyCut) {
138  // create hits only if above threshold
139 
140 #ifdef EDM_ML_DEBUG
141  auto const theTrack = aStep->GetTrack();
142  edm::LogVerbatim("ForwardSim") << "----------------New track------------------------------\n"
143  << "Incident EnergyTrack: " << etrack << " MeV \n"
144  << "Zdc Cut Energy for Hits: " << zdcHitEnergyCut << " MeV \n"
145  << "ZdcSD::getFromLibrary " << hits.size() << " hits for " << GetName() << " of "
146  << primaryID << " with " << theTrack->GetDefinition()->GetParticleName() << " of "
147  << etrack << " MeV\n";
148 #endif
149  hits.swap(showerLibrary.get()->getHits(aStep, ok));
150  }
151 
152  incidentEnergy = etrack;
153  entrancePoint = preStepPoint->GetPosition();
154  for (unsigned int i = 0; i < hits.size(); i++) {
155  posGlobal = hits[i].position;
156  entranceLocal = hits[i].entryLocal;
157  double time = hits[i].time;
158  unsigned int unitID = hits[i].detID;
159  edepositHAD = hits[i].DeHad;
160  edepositEM = hits[i].DeEM;
161  currentID[0].setID(unitID, time, primaryID, 0);
162  processHit(aStep);
163 
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("ForwardSim") << "ZdcSD: Final Hit number:" << i << "-->"
166  << "New HitID: " << currentHit[0]->getUnitID()
167  << " New Hit trackID: " << currentHit[0]->getTrackID()
168  << " New EM Energy: " << currentHit[0]->getEM() / CLHEP::GeV
169  << " New HAD Energy: " << currentHit[0]->getHadr() / CLHEP::GeV
170  << " New HitEntryPoint: " << currentHit[0]->getEntryLocal()
171  << " New IncidentEnergy: " << currentHit[0]->getIncidentEnergy() / CLHEP::GeV
172  << " New HitPosition: " << posGlobal;
173 #endif
174  }
175  return ok;
176 }
177 
178 double ZdcSD::getEnergyDeposit(const G4Step* aStep) {
179  double NCherPhot = 0.;
180 
181  // preStepPoint information
182  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
183 
184  const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
185  const G4ThreeVector& hit_mom = preStepPoint->GetMomentumDirection();
186  G4double stepL = aStep->GetStepLength() / cm;
187  G4double beta = preStepPoint->GetBeta();
188  G4double charge = preStepPoint->GetCharge();
189  if (charge == 0.0)
190  return 0.0;
191 
192  // theTrack information
193  G4Track* theTrack = aStep->GetTrack();
194  G4String particleType = theTrack->GetDefinition()->GetParticleName();
195  G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
196 
197 #ifdef EDM_ML_DEBUG
198  const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
199 
200  // calculations
201  float costheta =
202  vert_mom.z() / sqrt(vert_mom.x() * vert_mom.x() + vert_mom.y() * vert_mom.y() + vert_mom.z() * vert_mom.z());
203  float theta = std::acos(std::min(std::max(costheta, -1.f), 1.f));
204  float eta = -std::log(std::tan(theta * 0.5f));
205  float phi = -100.;
206  if (vert_mom.x() != 0)
207  phi = std::atan2(vert_mom.y(), vert_mom.x());
208  if (phi < 0.)
209  phi += twopi;
210 
211  // Get the total energy deposit
212  double stepE = aStep->GetTotalEnergyDeposit();
213 
214  // postStepPoint information
215  G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
216  G4VPhysicalVolume* postPV = postStepPoint->GetPhysicalVolume();
217  std::string postnameVolume = ForwardName::getName(postPV->GetName());
218  std::string nameVolume = preStepPoint->GetPhysicalVolume()->GetName();
219  edm::LogVerbatim("ForwardSim") << "ZdcSD:: getEnergyDeposit: \n"
220  << " preStepPoint: " << nameVolume << "," << stepL << "," << stepE << "," << beta
221  << "," << charge << "\n"
222  << " postStepPoint: " << postnameVolume << "," << costheta << "," << theta << ","
223  << eta << "," << phi << "," << particleType << " id= " << theTrack->GetTrackID()
224  << " Etot(GeV)= " << theTrack->GetTotalEnergy() / CLHEP::GeV;
225 #endif
226  const double bThreshold = 0.67;
227  if (beta > bThreshold) {
228 #ifdef EDM_ML_DEBUG
229  edm::LogVerbatim("ForwardSim") << "ZdcSD:: getEnergyDeposit: pass ";
230 #endif
231  const float nMedium = 1.4925;
232  // float photEnSpectrDL = 10714.285714;
233  // photEnSpectrDL = (1./400.nm-1./700.nm)*10000000.cm/nm; /* cm-1 */
234 
235  const float photEnSpectrDE = 1.24;
236  // E = 2pi*(1./137.)*(eV*cm/370.)/lambda = 12.389184*(eV*cm)/lambda
237  // Emax = 12.389184*(eV*cm)/400nm*10-7cm/nm = 3.01 eV
238  // Emin = 12.389184*(eV*cm)/700nm*10-7cm/nm = 1.77 eV
239  // delE = Emax - Emin = 1.24 eV
240 
241  const float effPMTandTransport = 0.15;
242 
243  // Check these values
244  const float thFullRefl = 23.;
245  float thFullReflRad = thFullRefl * pi / 180.;
246 
247  float thFibDirRad = thFibDir * pi / 180.;
248 
249  // at which theta the point is located:
250  // float th1 = hitPoint.theta();
251 
252  // theta of charged particle in LabRF(hit momentum direction):
253  float costh = hit_mom.z() / sqrt(hit_mom.x() * hit_mom.x() + hit_mom.y() * hit_mom.y() + hit_mom.z() * hit_mom.z());
254  float th = acos(std::min(std::max(costh, -1.f), 1.f));
255  // just in case (can do both standard ranges of phi):
256  if (th < 0.)
257  th += CLHEP::twopi;
258 
259  // theta of cone with Cherenkov photons w.r.t.direction of charged part.:
260  float costhcher = 1. / (nMedium * beta);
261  float thcher = acos(std::min(std::max(costhcher, -1.f), 1.f));
262 
263  // diff thetas of charged part. and quartz direction in LabRF:
264  float DelFibPart = std::abs(th - thFibDirRad);
265 
266  // define real distances:
267  float d = std::abs(std::tan(th) - std::tan(thFibDirRad));
268 
269  float a = std::tan(thFibDirRad) + std::tan(std::abs(thFibDirRad - thFullReflRad));
270  float r = std::tan(th) + std::tan(std::abs(th - thcher));
271 
272  // define losses d_qz in cone of full reflection inside quartz direction
273  float d_qz = -1;
274 #ifdef EDM_ML_DEBUG
275  float variant = -1;
276 #endif
277  // if (d > (r+a))
278  if (DelFibPart > (thFullReflRad + thcher)) {
279 #ifdef EDM_ML_DEBUG
280  variant = 0.;
281 #endif
282  d_qz = 0.;
283  } else {
284  // if ((DelFibPart + thcher) < thFullReflRad ) [(d+r) < a]
285  if ((th + thcher) < (thFibDirRad + thFullReflRad) && (th - thcher) > (thFibDirRad - thFullReflRad)) {
286 #ifdef EDM_ML_DEBUG
287  variant = 1.;
288 #endif
289  d_qz = 1.;
290  } else {
291  // if ((thcher - DelFibPart ) > thFullReflRad ) [(r-d) > a]
292  if ((thFibDirRad + thFullReflRad) < (th + thcher) && (thFibDirRad - thFullReflRad) > (th - thcher)) {
293 #ifdef EDM_ML_DEBUG
294  variant = 2.;
295 #endif
296  d_qz = 0.;
297  } else {
298 #ifdef EDM_ML_DEBUG
299  variant = 3.; // d_qz is calculated below
300 #endif
301  // use crossed length of circles(cone projection) - dC1/dC2 :
302  float arg_arcos = 0.;
303  float tan_arcos = 2. * a * d;
304  if (tan_arcos != 0.)
305  arg_arcos = (r * r - a * a - d * d) / tan_arcos;
306  arg_arcos = std::abs(arg_arcos);
307  float th_arcos = acos(std::min(std::max(arg_arcos, -1.f), 1.f));
308  d_qz = th_arcos / CLHEP::twopi;
309  d_qz = std::abs(d_qz);
310 #ifdef EDM_ML_DEBUG
311  edm::LogVerbatim("ForwardSim") << " d_qz: " << r << "," << a << "," << d << " " << tan_arcos << " "
312  << arg_arcos;
313  edm::LogVerbatim("ForwardSim") << "," << arg_arcos;
314  edm::LogVerbatim("ForwardSim") << " " << d_qz;
315  edm::LogVerbatim("ForwardSim") << " " << th_arcos;
316  edm::LogVerbatim("ForwardSim") << "," << d_qz;
317 #endif
318  }
319  }
320  }
321  double meanNCherPhot = 0.;
322  int poissNCherPhot = 0;
323  if (d_qz > 0) {
324  meanNCherPhot = 370. * charge * charge * (1. - 1. / (nMedium * nMedium * beta * beta)) * photEnSpectrDE * stepL;
325 
326  poissNCherPhot = std::max((int)G4Poisson(meanNCherPhot), 0);
327  NCherPhot = poissNCherPhot * effPMTandTransport * d_qz;
328  }
329 
330 #ifdef EDM_ML_DEBUG
331  edm::LogVerbatim("ForwardSim") << "ZdcSD:: getEnergyDeposit: gED: " << stepE << "," << costh << "," << th << ","
332  << costhcher << "," << thcher << "," << DelFibPart << "," << d << "," << a << ","
333  << r << "," << hitPoint << "," << hit_mom << "," << vert_mom << "," << localPoint
334  << "," << charge << "," << beta << "," << stepL << "," << d_qz << "," << variant
335  << "," << meanNCherPhot << "," << poissNCherPhot << "," << NCherPhot;
336 #endif
337 
338  } else {
339  // determine failure mode: beta, charge, and/or nameVolume
340  if (beta <= bThreshold)
341  edm::LogVerbatim("ForwardSim") << "ZdcSD:: getEnergyDeposit: fail beta=" << beta;
342  }
343 
344  return NCherPhot;
345 }
346 
348 // Functions added by Oliver Suranyi //
350 
351 // Constants as global variables
352 const double RINDEX = 1.47;
353 const double NA = 0.22; // Numerical aperture, characteristic of the specific fiber
354 const double NAperRINDEX = NA / RINDEX;
355 const double EMAX = 4.79629 /*eV*/; // Maximum energy of PMT sensitivity range
356 const double EMIN = 1.75715 /*eV*/; // Minimum energy of PMT sensitivity range
357 const double ALPHA = /*1/137=*/0.0072973525693; // Fine structure constant
358 const double HBARC = 6.582119514E-16 /*eV*s*/ * 2.99792458E8 /*m/s*/; // hbar * c
359 
360 // Calculate the Cherenkov deposit corresponding to a G4Step
361 double ZdcSD::calculateCherenkovDeposit(const G4Step* aStep) {
362  const G4StepPoint* pPreStepPoint = aStep->GetPreStepPoint();
363  G4double charge = pPreStepPoint->GetCharge() / CLHEP::eplus;
364  if (charge == 0.0 || aStep->GetStepLength() < 1e-9 * CLHEP::mm)
365  return 0.0;
366 
367  const G4StepPoint* pPostStepPoint = aStep->GetPostStepPoint();
368 
369  G4ThreeVector pre = pPreStepPoint->GetPosition();
370  G4ThreeVector post = pPostStepPoint->GetPosition();
371 
372  //Convert step coordinates to local (fiber) coodinates
373  const G4ThreeVector localPre = setToLocal(pre, pPreStepPoint->GetTouchable());
374  const G4ThreeVector localPost = setToLocal(post, pPreStepPoint->GetTouchable());
375 
376  // Calculate the unit direction vector in local coordinates
377  const G4ThreeVector particleDirection = (localPost - localPre) / (localPost - localPre).mag();
378 
379  double beta = 0.5 * (pPreStepPoint->GetBeta() + pPostStepPoint->GetBeta());
380  double stepLength = aStep->GetStepLength() / 1000; // Geant4 stepLength is in "mm"
381 
382  int nPhotons; // Number of Cherenkov photons
383 
384  nPhotons = G4Poisson(calculateMeanNumberOfPhotons(charge, beta, stepLength));
385 
386  double totalE = 0.0;
387 
388  for (int i = 0; i < nPhotons; ++i) {
389  // uniform refractive index in PMT range -> uniform energy distribution
390  double photonE = EMIN + G4UniformRand() * (EMAX - EMIN);
391  // UPDATE: taking into account dispersion relation -> energy distribution
392 
393  if (G4UniformRand() > pmtEfficiency(convertEnergyToWavelength(photonE)))
394  continue;
395 
396  double omega = G4UniformRand() * twopi;
397  double cosTheta = std::min(1.0 / (beta * RINDEX), 1.0);
398  double sinTheta = std::sqrt((1. - cosTheta) * (1.0 + cosTheta));
399 
400 #ifdef EDM_ML_DEBUG
401  edm::LogVerbatim("ZdcSD") << "E_gamma: " << photonE << "\t omega: " << omega << "\t thetaC: " << cosTheta;
402 #endif
403  // Calculate momentum direction w.r.t primary particle (z-direction)
404  double px = photonE * sinTheta * std::cos(omega);
405  double py = photonE * sinTheta * std::sin(omega);
406  double pz = photonE * cosTheta;
407  G4ThreeVector photonMomentum(px, py, pz);
408 
409 #ifdef EDM_ML_DEBUG
410  edm::LogVerbatim("ZdcSD") << "pPR = (" << particleDirection.x() << "," << particleDirection.y() << ","
411  << particleDirection.z() << ")";
412  edm::LogVerbatim("ZdcSD") << "pCH = (" << px << "," << py << "," << pz << ")";
413 #endif
414  // Rotate to the fiber reference frame
415  photonMomentum.rotateUz(particleDirection);
416 
417 #ifdef EDM_ML_DEBUG
418  edm::LogVerbatim("ZdcSD") << "pLAB = (" << photonMomentum.x() << "," << photonMomentum.y() << ","
419  << photonMomentum.z() << ")";
420 #endif
421  // Get random position along G4Step
422  G4ThreeVector photonPosition = localPre + G4UniformRand() * (localPost - localPre);
423 
424  // 2D vectors to calculate impact position (x*,y*)
425  G4TwoVector r0(photonPosition);
426  G4TwoVector v0(photonMomentum);
427 
428  double R = 0.3; /*mm, fiber radius*/
429  double R2 = 0.3 * 0.3;
430 
431  if (r0.mag() < R && photonMomentum.z() < 0.0) {
432  // 2nd order polynomial coefficients
433  double a = v0.mag2();
434  double b = 2.0 * r0 * v0;
435  double c = r0.mag2() - R2;
436 
437  if (a < 1E-6)
438  totalE += 1; //photonE /*eV*/;
439  else {
440  // calculate intersection point - solving 2nd order polynomial
441  double t = (-b + sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
442  G4ThreeVector n(r0.x() + v0.x() * t, r0.y() + v0.y() * t, 0.0); // surface normal
443  double cosTheta = (n * photonMomentum) / (n.mag() * photonE); // cosine of incident angle
444 
445  if (cosTheta >= NAperRINDEX) // lightguide condition
446  totalE += 1; //photonE /*eV*/;
447  }
448  }
449 
450 #ifdef EDM_ML_DEBUG
451  edm::LogVerbatim("ZdcSD") << "r = (" << photonPosition.x() << "," << photonPosition.y() << "," << photonPosition.z()
452  << ")" << std::endl;
453 #endif
454  }
455 
456 #ifdef EDM_ML_DEBUG
457  if (nPhotons > 30) {
458  edm::LogVerbatim("ZdcSD") << totalE;
459 
460  if (totalE > 0)
461  edm::LogVerbatim("ZdcSD") << pre.x() << " " << pre.y() << " " << pre.z() << " " << totalE;
462  }
463 #endif
464  return totalE;
465 }
466 
467 // Calculate mean number of Cherenkov photons in the sensitivity range (300-650 nm)
468 // for a given step length for a particle with given charge and beta
469 double ZdcSD::calculateMeanNumberOfPhotons(double charge, double beta, double stepLength) {
470  // Return mean number of Cherenkov photons
471  return (ALPHA * charge * charge * stepLength) / HBARC * (EMAX - EMIN) * (1.0 - 1.0 / (beta * beta * RINDEX * RINDEX));
472 }
473 
474 // Evaluate photon pdf
475 double ZdcSD::photonEnergyDist(double charge, double beta, double E) {
476  const std::vector<double> ENERGY_TAB{1.75715, 1.81902, 1.88311, 1.94944, 2.0183, 2.08939, 2.16302, 2.23919,
477  2.31789, 2.39954, 2.48416, 2.57175, 2.66232, 2.75643, 2.85349, 2.95411,
478  3.05756, 3.16528, 3.2774, 3.39218, 3.5123, 3.6359, 3.76394, 3.89642,
479  4.03332, 4.17596, 4.32302, 4.47596, 4.63319, 4.79629};
480 
481  const std::vector<double> RINDEX_TAB{1.45517, 1.45572, 1.45631, 1.45693, 1.45758, 1.45826, 1.45899, 1.45976,
482  1.46057, 1.46144, 1.46238, 1.46337, 1.46444, 1.46558, 1.4668, 1.46812,
483  1.46953, 1.47105, 1.4727, 1.47447, 1.4764, 1.47847, 1.48071, 1.48315,
484  1.48579, 1.48868, 1.49182, 1.49526, 1.499, 1.5031};
485  double rIndex = evaluateFunction(ENERGY_TAB, RINDEX_TAB, E);
486  return (ALPHA * charge * charge) / HBARC * (1.0 - 1.0 / (beta * beta * rIndex * rIndex));
487 }
488 
489 // Generate a photon with the given minimum energy accourding to the energy distribution
490 double ZdcSD::generatePhotonEnergy(double charge, double beta, double Emin) {
491  double photonE;
492 
493  // Use rejection method
494  do {
495  photonE = G4UniformRand() * (EMAX - Emin) + Emin;
496  } while (G4UniformRand() > photonEnergyDist(photonE, charge, beta) / photonEnergyDist(EMAX, charge, beta));
497 
498  return photonE;
499 }
500 
501 // Calculate the integral: int_Emin^Emax 1/n(E)^2 dE
502 // The integral values are tabulated
503 double ZdcSD::calculateN2InvIntegral(double Emin) {
504  // Hardcoded minimum photon energy table (eV)
505  const std::vector<double> EMIN_TAB{1.75715, 1.81902, 1.88311, 1.94944, 2.0183, 2.08939, 2.16302, 2.23919,
506  2.31789, 2.39954, 2.48416, 2.57175, 2.66232, 2.75643, 2.85349, 2.95411,
507  3.05756, 3.16528, 3.2774, 3.39218, 3.5123, 3.6359, 3.76394, 3.89642,
508  4.03332, 4.17596, 4.32302, 4.47596, 4.63319};
509 
510  // Hardcoded integral values
511  const std::vector<double> INTEGRAL_TAB{1.39756, 1.36835, 1.33812, 1.30686, 1.27443, 1.24099, 1.20638, 1.17061,
512  1.1337, 1.09545, 1.05586, 1.01493, 0.972664, 0.928815, 0.883664, 0.836938,
513  0.788988, 0.739157, 0.687404, 0.634547, 0.579368, 0.522743, 0.464256, 0.40393,
514  0.341808, 0.27732, 0.211101, 0.142536, 0.0723891};
515  return evaluateFunction(EMIN_TAB, INTEGRAL_TAB, Emin);
516 }
517 
518 double ZdcSD::pmtEfficiency(double lambda) {
519  // Hardcoded wavelength values (nm)
520  const std::vector<double> LAMBDA_TAB{263.27, 265.98, 268.69, 271.39, 273.20, 275.90, 282.22, 282.22, 293.04,
521  308.38, 325.52, 346.26, 367.91, 392.27, 417.53, 440.98, 463.53, 484.28,
522  502.32, 516.75, 528.48, 539.30, 551.93, 564.56, 574.48, 584.41, 595.23,
523  606.96, 616.88, 625.00, 632.22, 637.63, 642.14, 647.55, 652.96, 656.57,
524  661.08, 666.49, 669.20, 673.71, 677.32, 680.93, 686.34, 692.65};
525 
526  // Hardcoded quantum efficiency values
527  const std::vector<double> EFF_TAB{2.215, 2.860, 3.659, 4.724, 5.989, 7.734, 9.806, 9.806, 12.322,
528  15.068, 17.929, 20.570, 22.963, 24.050, 23.847, 22.798, 20.445, 18.003,
529  15.007, 12.282, 9.869, 7.858, 6.373, 5.121, 4.077, 3.276, 2.562,
530  2.077, 1.669, 1.305, 1.030, 0.805, 0.629, 0.492, 0.388, 0.303,
531  0.239, 0.187, 0.144, 0.113, 0.088, 0.069, 0.054, 0.043};
532  //double efficiency = evaluateFunction(LAMBDA_TAB,EFF_TAB,lambda);
533 
534  // Using linear interpolation to calculate efficiency
535  for (int i = 0; i < 44 - 1; i++) {
536  if (lambda > LAMBDA_TAB[i] && lambda < LAMBDA_TAB[i + 1]) {
537  double a = (EFF_TAB[i] - EFF_TAB[i + 1]) / (LAMBDA_TAB[i] - LAMBDA_TAB[i + 1]);
538  double b = EFF_TAB[i] - a * LAMBDA_TAB[i];
539  return (a * lambda + b) / 100.0;
540  }
541  }
542 
543  return 0;
544 }
545 
546 // Evaluate a function given by set of datapoints
547 // Linear interpolation is used to calculate function value between datapoints
548 double ZdcSD::evaluateFunction(const std::vector<double>& X, const std::vector<double>& Y, double x) {
549  for (unsigned int i = 0; i < X.size() - 1; i++) {
550  if (x > X[i] && x < X[i + 1]) {
551 #ifdef EDM_ML_DEBUG
552  edm::LogVerbatim("ZdcSD") << X[i] << "\t" << Y[i] << "\t" << X[i + 1] << "\t" << Y[i + 1] << "\t" << x << "\t"
553  << linearInterpolation(X[i], Y[i], X[i + 1], Y[i + 1], x);
554 #endif
555  return linearInterpolation(X[i], Y[i], X[i + 1], Y[i + 1], x);
556  }
557  }
558 
559  if (fabs(X[0] - x) < 1E-8)
560  return Y[0];
561  else if (fabs(X[X.size() - 1] - x) < 1E-8)
562  return Y[X.size() - 1];
563  else
564  return NAN;
565 }
566 
567 // Do linear interpolation between two points
568 double ZdcSD::linearInterpolation(double x1, double y1, double x2, double y2, double z) {
569  if (x1 < x2)
570  return y1 + (z - x1) * (y2 - y1) / (x2 - x1);
571  else
572  return y2 + (z - x2) * (y1 - y2) / (x1 - x2);
573 }
574 
575 // Energy (eV) to wavelength (nm) conversion
576 double ZdcSD::convertEnergyToWavelength(double energy) { return (1240.0 / energy); }
577 
579 
580 uint32_t ZdcSD::setDetUnitId(const G4Step* aStep) {
581  return (numberingScheme == nullptr ? 0 : numberingScheme->getUnitID(aStep));
582 }
583 
584 int ZdcSD::setTrackID(const G4Step* aStep) {
585  auto const theTrack = aStep->GetTrack();
586  TrackInformation* trkInfo = (TrackInformation*)(theTrack->GetUserInformation());
587  int primaryID = trkInfo->getIDonCaloSurface();
588  if (primaryID == 0) {
589 #ifdef EDM_ML_DEBUG
590  auto const preStepPoint = aStep->GetPreStepPoint();
591  double etrack = preStepPoint->GetKineticEnergy();
592  edm::LogVerbatim("ZdcSD") << "ZdcSD: Problem with primaryID **** set by force to TkID **** "
593  << theTrack->GetTrackID() << " E " << etrack;
594 #endif
595  primaryID = theTrack->GetTrackID();
596  }
597  if (primaryID != previousID[0].trackID())
598  resetForNewPrimary(aStep);
599  return primaryID;
600 }
CaloG4Hit * currentHit[2]
Definition: CaloSD.h:152
float edepositEM
Definition: CaloSD.h:144
double convertEnergyToWavelength(double)
Definition: ZdcSD.cc:576
Log< level::Info, true > LogVerbatim
double thFibDir
Definition: ZdcSD.h:44
int getTrackID() const
Definition: CaloG4Hit.h:64
std::unique_ptr< ZdcNumberingScheme > numberingScheme
Definition: ZdcSD.h:47
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
math::XYZPoint getEntryLocal() const
Definition: CaloG4Hit.h:49
const double HBARC
Definition: ZdcSD.cc:358
double calculateN2InvIntegral(double)
Definition: ZdcSD.cc:503
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:913
Definition: CaloSD.h:40
int verbosity
Definition: ZdcSD.h:42
double getEM() const
Definition: CaloG4Hit.h:55
std::vector< ZdcShowerLibrary::Hit > hits
Definition: ZdcSD.h:49
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
#define X(str)
Definition: MuonsGrabber.cc:38
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:454
G4ThreeVector posGlobal
Definition: CaloSD.h:142
bool useShowerHits
Definition: ZdcSD.h:43
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:873
double calculateCherenkovDeposit(const G4Step *)
Definition: ZdcSD.cc:361
double evaluateFunction(const std::vector< double > &, const std::vector< double > &, double)
Definition: ZdcSD.cc:548
void processHit(const G4Step *step)
Definition: CaloSD.h:117
double calculateMeanNumberOfPhotons(double, double, double)
Definition: ZdcSD.cc:469
float float float z
double getHadr() const
Definition: CaloG4Hit.h:58
const Double_t pi
CaloG4Hit * createNewHit(const G4Step *, const G4Track *, int k)
Definition: CaloSD.cc:624
double generatePhotonEnergy(double, double, double)
Definition: ZdcSD.cc:490
const double EMIN
Definition: ZdcSD.cc:356
float edepositHAD
Definition: CaloSD.h:144
T sqrt(T t)
Definition: SSEVec.h:19
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:714
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int setTrackID(const G4Step *step) override
Definition: ZdcSD.cc:584
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]
bool ProcessHits(G4Step *step, G4TouchableHistory *tHistory) override
Definition: ZdcSD.cc:76
d
Definition: ztail.py:151
int getIDonCaloSurface() const
CaloHitID previousID[2]
Definition: CaloSD.h:146
ZdcSD(const std::string &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: ZdcSD.cc:34
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
Definition: CaloHitID.cc:41
double b
Definition: hdecay.h:120
void initRun() override
Definition: ZdcSD.cc:68
uint32_t getUnitID() const
Definition: CaloG4Hit.h:66
bool hitExists(const G4Step *, int k)
Definition: CaloSD.cc:462
double pmtEfficiency(double)
Definition: ZdcSD.cc:518
std::unique_ptr< ZdcShowerLibrary > showerLibrary
Definition: ZdcSD.h:46
float incidentEnergy
Definition: CaloSD.h:143
const double ALPHA
Definition: ZdcSD.cc:357
double a
Definition: hdecay.h:121
double zdcHitEnergyCut
Definition: ZdcSD.h:45
static bool isGammaElectronPositron(int pdgCode)
const double RINDEX
Definition: ZdcSD.cc:352
float x
std::string getName(const G4String &)
Definition: ForwardName.cc:3
CaloHitID currentID[2]
Definition: CaloSD.h:146
double photonEnergyDist(double, double, double)
Definition: ZdcSD.cc:475
double linearInterpolation(double, double, double, double, double)
Definition: ZdcSD.cc:568
const double NAperRINDEX
Definition: ZdcSD.cc:354
double getIncidentEnergy() const
Definition: CaloG4Hit.h:61
bool getFromLibrary(const G4Step *) override
Definition: ZdcSD.cc:124
Geom::Theta< T > theta() const
uint32_t setDetUnitId(const G4Step *step) override
Definition: ZdcSD.cc:580
bool useShowerLibrary
Definition: ZdcSD.h:43
G4ThreeVector entrancePoint
Definition: CaloSD.h:140
G4ThreeVector entranceLocal
Definition: CaloSD.h:141
const double EMAX
Definition: ZdcSD.cc:355
const double NA
Definition: ZdcSD.cc:353
double getEnergyDeposit(const G4Step *) override
Definition: ZdcSD.cc:178
void setParameterized(bool val)
Definition: CaloSD.h:114