CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
20 //#define DebugLog
21 
23  edm::ParameterSet const & p) : cherenkov(0) {
24 
25  edm::ParameterSet m_HF = p.getParameter<edm::ParameterSet>("HFShowerPMT");
26  pePerGeV = m_HF.getParameter<double>("PEPerGeVPMT");
27 
28  G4String attribute = "ReadOutName";
29  G4String value = name;
30  DDSpecificsFilter filter0;
31  DDValue ddv0(attribute,value,0);
33  DDFilteredView fv0(cpv);
34  fv0.addFilter(filter0);
35  if (fv0.firstChild()) {
37 
38  //Special Geometry parameters
39  rTable = getDDDArray("rTable",sv0);
40  edm::LogInfo("HFShower") << "HFShowerPMT: " << rTable.size()
41  << " rTable (cm)";
42  for (unsigned int ig=0; ig<rTable.size(); ig++)
43  edm::LogInfo("HFShower") << "HFShowerPMT: rTable[" << ig << "] = "
44  << rTable[ig]/cm << " cm";
45  } else {
46  edm::LogError("HFShower") << "HFShowerPMT: cannot get filtered "
47  << " view for " << attribute << " matching "
48  << value;
49  throw cms::Exception("Unknown", "HFShowerPMT")
50  << "cannot match " << attribute << " to " << name <<"\n";
51  }
52 
53  attribute = "Volume";
54  value = "HFPMT";
55  DDSpecificsFilter filter1;
56  DDValue ddv1(attribute,value,0);
58  DDFilteredView fv1(cpv);
59  fv1.addFilter(filter1);
60  if (fv1.firstChild()) {
62  std::vector<double> neta;
63  neta = getDDDArray("indexPMTR",sv1);
64  for (unsigned int ii=0; ii<neta.size(); ii++) {
65  int index = static_cast<int>(neta[ii]);
66  int ir=-1, ifib=-1;
67  if (index >= 0) {
68  ir = index/10; ifib = index%10;
69  }
70  pmtR1.push_back(ir);
71  pmtFib1.push_back(ifib);
72  }
73  neta = getDDDArray("indexPMTL",sv1);
74  for (unsigned int ii=0; ii<neta.size(); ii++) {
75  int index = static_cast<int>(neta[ii]);
76  int ir=-1, ifib=-1;
77  if (index >= 0) {
78  ir = index/10; ifib = index%10;
79  }
80  pmtR2.push_back(ir);
81  pmtFib2.push_back(ifib);
82  }
83  edm::LogInfo("HFShower") << "HFShowerPMT: gets the Index matches for "
84  << neta.size() << " PMTs";
85  for (unsigned int ii=0; ii<neta.size(); ii++)
86  edm::LogInfo("HFShower") << "HFShowerPMT: rIndexR[" << ii << "] = "
87  << pmtR1[ii] << " fibreR[" << ii << "] = "
88  << pmtFib1[ii] << " rIndexL[" << ii << "] = "
89  << pmtR2[ii] << " fibreL[" << ii << "] = "
90  << pmtFib2[ii];
91  } else {
92  edm::LogWarning("HFShower") << "HFShowerPMT: cannot get filtered "
93  << " view for " << attribute << " matching "
94  << value;
95  }
96 
97  cherenkov = new HFCherenkov(m_HF);
98 }
99 
101  if (cherenkov) delete cherenkov;
102 }
103 
104 double HFShowerPMT::getHits(G4Step * aStep) {
105 
106  indexR = indexF = -1;
107 
108  G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
109  const G4VTouchable* touch = preStepPoint->GetTouchable();
110  int boxNo = touch->GetReplicaNumber(2);
111  int pmtNo = touch->GetReplicaNumber(1);
112  if (boxNo <= 1) {
113  indexR = pmtR1[pmtNo-1];
114  indexF = pmtFib1[pmtNo-1];
115  } else {
116  indexR = pmtR2[pmtNo-1];
117  indexF = pmtFib2[pmtNo-1];
118  }
119 
120 #ifdef DebugLog
121  double edep = aStep->GetTotalEnergyDeposit();
122  LogDebug("HFShower") << "HFShowerPMT: Box " << boxNo << " PMT "
123  << pmtNo << " Mapped Indices " << indexR << ", "
124  << indexF << " Edeposit " << edep/MeV << " MeV; PE "
125  << edep*pePerGeV/GeV;
126 #endif
127 
128  double photons = 0;
129  if (indexR >= 0 && indexF > 0) {
130  G4Track *aTrack = aStep->GetTrack();
131  G4ParticleDefinition *particleDef = aTrack->GetDefinition();
132  double stepl = aStep->GetStepLength();
133  double beta = preStepPoint->GetBeta();
134  G4ThreeVector pDir = aTrack->GetDynamicParticle()->GetMomentumDirection();
135  G4ThreeVector localMom = preStepPoint->GetTouchable()->GetHistory()->
136  GetTopTransform().TransformAxis(pDir);
137  photons = cherenkov->computeNPEinPMT(particleDef, beta, localMom.x(),
138  localMom.y(), localMom.z(), stepl);
139 #ifdef DebugLog
140  LogDebug("HFShower") << "HFShowerPMT::getHits: for particle "
141  << particleDef->GetParticleName() << " Step " << stepl
142  << " Beta " << beta << " Direction " << pDir
143  << " Local " << localMom << " p.e. " << photons;
144 #endif
145 
146  }
147  return photons;
148 }
149 
151 
152  double r = 0.;
153  if (indexR >= 0 && indexR+1 < (int)(rTable.size()))
154  r = 0.5*(rTable[indexR]+rTable[indexR+1]);
155 #ifdef DebugLog
156  else
157  LogDebug("HFShower") << "HFShowerPMT::getRadius: R " << indexR
158  << " F " << indexF;
159 #endif
160  if (indexF == 2) r =-r;
161 #ifdef DebugLog
162  LogDebug("HFShower") << "HFShowerPMT: Radius (" << indexR << "/" << indexF
163  << ") " << r;
164 #endif
165  return r;
166 }
167 
168 std::vector<double> HFShowerPMT::getDDDArray(const std::string & str,
169  const DDsvalues_type & sv) {
170 
171 #ifdef DebugLog
172  LogDebug("HFShower") << "HFShowerPMT:getDDDArray called for " << str;
173 #endif
174  DDValue value(str);
175  if (DDfetch(&sv,value)) {
176 #ifdef DebugLog
177  LogDebug("HFShower") << value;
178 #endif
179  const std::vector<double> & fvec = value.doubles();
180  int nval = fvec.size();
181  if (nval < 2) {
182  edm::LogError("HFShower") << "HFShowerPMT: # of " << str
183  << " bins " << nval << " < 2 ==> illegal";
184  throw cms::Exception("Unknown", "HFShowerPMT")
185  << "nval < 2 for array " << str << "\n";
186  }
187 
188  return fvec;
189  } else {
190  edm::LogError("HFShower") << "HFShowerPMT: cannot get array " << str;
191  throw cms::Exception("Unknown", "HFShowerPMT")
192  << "cannot get array " << str << "\n";
193  }
194 }
#define LogDebug(id)
const double beta
T getParameter(std::string const &) const
double getRadius()
Definition: HFShowerPMT.cc:150
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:134
void addFilter(const DDFilter &, log_op op=AND)
std::vector< double > rTable
Definition: HFShowerPMT.h:38
std::vector< int > pmtFib1
Definition: HFShowerPMT.h:39
int ii
Definition: cuy.py:588
type of data representation of DDCompactView
Definition: DDCompactView.h:77
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:102
virtual ~HFShowerPMT()
Definition: HFShowerPMT.cc:100
int computeNPEinPMT(G4ParticleDefinition *pDef, double pBeta, double u, double v, double w, double step_length)
Definition: HFCherenkov.cc:229
double pePerGeV
Definition: HFShowerPMT.h:36
std::vector< int > pmtR2
Definition: HFShowerPMT.h:40
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &)
Definition: HFShowerPMT.cc:168
DDsvalues_type mergedSpecifics() const
double getHits(G4Step *aStep)
Definition: HFShowerPMT.cc:104
bool firstChild()
set the current node to the first child ...
void setCriteria(const DDValue &nameVal, comp_op, log_op l=AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:285
HFCherenkov * cherenkov
Definition: HFShowerPMT.h:35
HFShowerPMT(std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
Definition: HFShowerPMT.cc:22
std::vector< int > pmtFib2
Definition: HFShowerPMT.h:40
std::vector< int > pmtR1
Definition: HFShowerPMT.h:39
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:37