CMS 3D CMS Logo

HFShowerPMT.cc
Go to the documentation of this file.
1 // File: HFShowerPMT.cc
3 // Description: Parametrized version of HF hits
5 
10 
12 
13 #include "G4NavigationHistory.hh"
14 #include "G4VPhysicalVolume.hh"
15 #include "G4Step.hh"
16 #include "G4Track.hh"
17 #include "CLHEP/Units/GlobalPhysicalConstants.h"
18 #include "CLHEP/Units/GlobalSystemOfUnits.h"
19 #include <sstream>
20 
21 //#define EDM_ML_DEBUG
22 
24  : cherenkov(nullptr) {
25  edm::ParameterSet m_HF = p.getParameter<edm::ParameterSet>("HFShowerPMT");
26  pePerGeV = m_HF.getParameter<double>("PEPerGeVPMT");
27 
28  //Special Geometry parameters
29  std::string attribute = "Volume";
30  std::string value = "HFPMT";
31  DDSpecificsMatchesValueFilter filter1{DDValue(attribute, value, 0)};
32  DDFilteredView fv1(cpv, filter1);
33  if (fv1.firstChild()) {
35  std::vector<double> neta;
36  neta = getDDDArray("indexPMTR", sv1);
37  for (unsigned int ii = 0; ii < neta.size(); ii++) {
38  int index = static_cast<int>(neta[ii]);
39  int ir = -1, ifib = -1;
40  if (index >= 0) {
41  ir = index / 10;
42  ifib = index % 10;
43  }
44  pmtR1.push_back(ir);
45  pmtFib1.push_back(ifib);
46  }
47  neta = getDDDArray("indexPMTL", sv1);
48  for (unsigned int ii = 0; ii < neta.size(); ii++) {
49  int index = static_cast<int>(neta[ii]);
50  int ir = -1, ifib = -1;
51  if (index >= 0) {
52  ir = index / 10;
53  ifib = index % 10;
54  }
55  pmtR2.push_back(ir);
56  pmtFib2.push_back(ifib);
57  }
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("HFShower") << "HFShowerPMT: gets the Index matches for " << neta.size() << " PMTs";
60  for (unsigned int ii = 0; ii < neta.size(); ii++) {
61  edm::LogVerbatim("HFShower") << "HFShowerPMT: rIndexR[" << ii << "] = " << pmtR1[ii] << " fibreR[" << ii
62  << "] = " << pmtFib1[ii] << " rIndexL[" << ii << "] = " << pmtR2[ii] << " fibreL["
63  << ii << "] = " << pmtFib2[ii];
64  }
65 #endif
66  } else {
67  edm::LogWarning("HFShower") << "HFShowerPMT: cannot get filtered "
68  << " view for " << attribute << " matching " << value;
69  }
70 
71  cherenkov = new HFCherenkov(m_HF);
72 }
73 
75  if (cherenkov)
76  delete cherenkov;
77 }
78 
80  // Special Geometry parameters
81  rTable = hcons->getRTableHF();
82  std::stringstream sss;
83  for (unsigned int ig = 0; ig < rTable.size(); ++ig) {
84  if (ig / 10 * 10 == ig) {
85  sss << "\n";
86  }
87  sss << " " << rTable[ig] / cm;
88  }
89  edm::LogVerbatim("HFShowerPMT") << "HFShowerPMT: " << rTable.size() << " rTable(cm):" << sss.str();
90 }
91 
92 double HFShowerPMT::getHits(const G4Step* aStep) {
93  indexR = indexF = -1;
94 
95  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
96  const G4VTouchable* touch = preStepPoint->GetTouchable();
97  int boxNo = touch->GetReplicaNumber(2);
98  int pmtNo = touch->GetReplicaNumber(1);
99  if (boxNo <= 1) {
100  indexR = pmtR1[pmtNo - 1];
101  indexF = pmtFib1[pmtNo - 1];
102  } else {
103  indexR = pmtR2[pmtNo - 1];
104  indexF = pmtFib2[pmtNo - 1];
105  }
106 
107 #ifdef EDM_ML_DEBUG
108  double edep = aStep->GetTotalEnergyDeposit();
109  edm::LogVerbatim("HFShower") << "HFShowerPMT: Box " << boxNo << " PMT " << pmtNo << " Mapped Indices " << indexR
110  << ", " << indexF << " Edeposit " << edep / MeV << " MeV; PE " << edep * pePerGeV / GeV;
111 #endif
112 
113  double photons = 0;
114  if (indexR >= 0 && indexF > 0) {
115  G4Track* aTrack = aStep->GetTrack();
116  G4ParticleDefinition* particleDef = aTrack->GetDefinition();
117  double stepl = aStep->GetStepLength();
118  double beta = preStepPoint->GetBeta();
119  G4ThreeVector pDir = aTrack->GetDynamicParticle()->GetMomentumDirection();
120  G4ThreeVector localMom = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformAxis(pDir);
121  photons = cherenkov->computeNPEinPMT(particleDef, beta, localMom.x(), localMom.y(), localMom.z(), stepl);
122 #ifdef EDM_ML_DEBUG
123  edm::LogVerbatim("HFShower") << "HFShowerPMT::getHits: for particle " << particleDef->GetParticleName() << " Step "
124  << stepl << " Beta " << beta << " Direction " << pDir << " Local " << localMom
125  << " p.e. " << photons;
126 #endif
127  }
128  return photons;
129 }
130 
132  double r = 0.;
133  if (indexR >= 0 && indexR + 1 < (int)(rTable.size()))
134  r = 0.5 * (rTable[indexR] + rTable[indexR + 1]);
135 #ifdef EDM_ML_DEBUG
136  else
137  edm::LogVerbatim("HFShower") << "HFShowerPMT::getRadius: R " << indexR << " F " << indexF;
138 #endif
139  if (indexF == 2)
140  r = -r;
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HFShower") << "HFShowerPMT: Radius (" << indexR << "/" << indexF << ") " << r;
143 #endif
144  return r;
145 }
146 
147 std::vector<double> HFShowerPMT::getDDDArray(const std::string& str, const DDsvalues_type& sv) {
148 #ifdef EDM_ML_DEBUG
149  edm::LogVerbatim("HFShower") << "HFShowerPMT:getDDDArray called for " << str;
150 #endif
151  DDValue value(str);
152  if (DDfetch(&sv, value)) {
153 #ifdef EDM_ML_DEBUG
154  edm::LogVerbatim("HFShower") << value;
155 #endif
156  const std::vector<double>& fvec = value.doubles();
157  int nval = fvec.size();
158  if (nval < 2) {
159  edm::LogError("HFShower") << "HFShowerPMT: # of " << str << " bins " << nval << " < 2 ==> illegal";
160  throw cms::Exception("Unknown", "HFShowerPMT") << "nval < 2 for array " << str << "\n";
161  }
162 
163  return fvec;
164  } else {
165  edm::LogError("HFShower") << "HFShowerPMT: cannot get array " << str;
166  throw cms::Exception("Unknown", "HFShowerPMT") << "cannot get array " << str << "\n";
167  }
168 }
T getParameter(std::string const &) const
double getRadius()
Definition: HFShowerPMT.cc:131
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:140
const double GeV
Definition: MathUtil.h:16
void initRun(const HcalDDDSimConstants *)
Definition: HFShowerPMT.cc:79
std::vector< double > rTable
Definition: HFShowerPMT.h:35
std::vector< int > pmtFib1
Definition: HFShowerPMT.h:36
#define nullptr
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
virtual ~HFShowerPMT()
Definition: HFShowerPMT.cc:74
const double MeV
double pePerGeV
Definition: HFShowerPMT.h:33
double getHits(const G4Step *aStep)
Definition: HFShowerPMT.cc:92
std::vector< int > pmtR2
Definition: HFShowerPMT.h:37
const std::vector< double > & getRTableHF() const
Definition: value.py:1
ii
Definition: cuy.py:590
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &)
Definition: HFShowerPMT.cc:147
HFShowerPMT(const std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
Definition: HFShowerPMT.cc:23
DDsvalues_type mergedSpecifics() const
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
bool firstChild()
set the current node to the first child ...
HFCherenkov * cherenkov
Definition: HFShowerPMT.h:32
#define str(s)
std::vector< int > pmtFib2
Definition: HFShowerPMT.h:37
std::vector< int > pmtR1
Definition: HFShowerPMT.h:36
int computeNPEinPMT(const G4ParticleDefinition *pDef, double pBeta, double u, double v, double w, double step_length)
Definition: HFCherenkov.cc:221