test
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  //Special Geometry parameters
29  std::string attribute = "Volume";
30  std::string value = "HFPMT";
31  DDSpecificsFilter filter1;
32  DDValue ddv1(attribute,value,0);
33  filter1.setCriteria(ddv1,DDCompOp::equals);
34  DDFilteredView fv1(cpv);
35  fv1.addFilter(filter1);
36  if (fv1.firstChild()) {
38  std::vector<double> neta;
39  neta = getDDDArray("indexPMTR",sv1);
40  for (unsigned int ii=0; ii<neta.size(); ii++) {
41  int index = static_cast<int>(neta[ii]);
42  int ir=-1, ifib=-1;
43  if (index >= 0) {
44  ir = index/10; ifib = index%10;
45  }
46  pmtR1.push_back(ir);
47  pmtFib1.push_back(ifib);
48  }
49  neta = getDDDArray("indexPMTL",sv1);
50  for (unsigned int ii=0; ii<neta.size(); ii++) {
51  int index = static_cast<int>(neta[ii]);
52  int ir=-1, ifib=-1;
53  if (index >= 0) {
54  ir = index/10; ifib = index%10;
55  }
56  pmtR2.push_back(ir);
57  pmtFib2.push_back(ifib);
58  }
59  edm::LogInfo("HFShower") << "HFShowerPMT: gets the Index matches for "
60  << neta.size() << " PMTs";
61  for (unsigned int ii=0; ii<neta.size(); ii++)
62  edm::LogInfo("HFShower") << "HFShowerPMT: rIndexR[" << ii << "] = "
63  << pmtR1[ii] << " fibreR[" << ii << "] = "
64  << pmtFib1[ii] << " rIndexL[" << ii << "] = "
65  << pmtR2[ii] << " fibreL[" << ii << "] = "
66  << pmtFib2[ii];
67  } else {
68  edm::LogWarning("HFShower") << "HFShowerPMT: cannot get filtered "
69  << " view for " << attribute << " matching "
70  << value;
71  }
72 
73  cherenkov = new HFCherenkov(m_HF);
74 }
75 
77  if (cherenkov) delete cherenkov;
78 }
79 
80 void HFShowerPMT::initRun(G4ParticleTable *, HcalDDDSimConstants* hcons) {
81 
82  // Special Geometry parameters
83  rTable = hcons->getRTableHF();
84  edm::LogInfo("HFShower") << "HFShowerPMT: " << rTable.size()
85  << " rTable (cm)";
86  for (unsigned int ig=0; ig<rTable.size(); ig++)
87  edm::LogInfo("HFShower") << "HFShowerPMT: rTable[" << ig << "] = "
88  << rTable[ig]/cm << " cm";
89 }
90 
91 double HFShowerPMT::getHits(G4Step * aStep) {
92 
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 DebugLog
108  double edep = aStep->GetTotalEnergyDeposit();
109  LogDebug("HFShower") << "HFShowerPMT: Box " << boxNo << " PMT "
110  << pmtNo << " Mapped Indices " << indexR << ", "
111  << indexF << " Edeposit " << edep/MeV << " MeV; PE "
112  << edep*pePerGeV/GeV;
113 #endif
114 
115  double photons = 0;
116  if (indexR >= 0 && indexF > 0) {
117  G4Track *aTrack = aStep->GetTrack();
118  G4ParticleDefinition *particleDef = aTrack->GetDefinition();
119  double stepl = aStep->GetStepLength();
120  double beta = preStepPoint->GetBeta();
121  G4ThreeVector pDir = aTrack->GetDynamicParticle()->GetMomentumDirection();
122  G4ThreeVector localMom = preStepPoint->GetTouchable()->GetHistory()->
123  GetTopTransform().TransformAxis(pDir);
124  photons = cherenkov->computeNPEinPMT(particleDef, beta, localMom.x(),
125  localMom.y(), localMom.z(), stepl);
126 #ifdef DebugLog
127  LogDebug("HFShower") << "HFShowerPMT::getHits: for particle "
128  << particleDef->GetParticleName() << " Step " << stepl
129  << " Beta " << beta << " Direction " << pDir
130  << " Local " << localMom << " p.e. " << photons;
131 #endif
132 
133  }
134  return photons;
135 }
136 
138 
139  double r = 0.;
140  if (indexR >= 0 && indexR+1 < (int)(rTable.size()))
141  r = 0.5*(rTable[indexR]+rTable[indexR+1]);
142 #ifdef DebugLog
143  else
144  LogDebug("HFShower") << "HFShowerPMT::getRadius: R " << indexR
145  << " F " << indexF;
146 #endif
147  if (indexF == 2) r =-r;
148 #ifdef DebugLog
149  LogDebug("HFShower") << "HFShowerPMT: Radius (" << indexR << "/" << indexF
150  << ") " << r;
151 #endif
152  return r;
153 }
154 
155 std::vector<double> HFShowerPMT::getDDDArray(const std::string & str,
156  const DDsvalues_type & sv) {
157 
158 #ifdef DebugLog
159  LogDebug("HFShower") << "HFShowerPMT:getDDDArray called for " << str;
160 #endif
161  DDValue value(str);
162  if (DDfetch(&sv,value)) {
163 #ifdef DebugLog
164  LogDebug("HFShower") << value;
165 #endif
166  const std::vector<double> & fvec = value.doubles();
167  int nval = fvec.size();
168  if (nval < 2) {
169  edm::LogError("HFShower") << "HFShowerPMT: # of " << str
170  << " bins " << nval << " < 2 ==> illegal";
171  throw cms::Exception("Unknown", "HFShowerPMT")
172  << "nval < 2 for array " << str << "\n";
173  }
174 
175  return fvec;
176  } else {
177  edm::LogError("HFShower") << "HFShowerPMT: cannot get array " << str;
178  throw cms::Exception("Unknown", "HFShowerPMT")
179  << "cannot get array " << str << "\n";
180  }
181 }
#define LogDebug(id)
const double beta
T getParameter(std::string const &) const
double getRadius()
Definition: HFShowerPMT.cc:137
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:139
const double GeV
Definition: MathUtil.h:16
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
std::vector< double > rTable
Definition: HFShowerPMT.h:40
std::vector< int > pmtFib1
Definition: HFShowerPMT.h:41
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:80
virtual ~HFShowerPMT()
Definition: HFShowerPMT.cc:76
int computeNPEinPMT(G4ParticleDefinition *pDef, double pBeta, double u, double v, double w, double step_length)
Definition: HFCherenkov.cc:229
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
Definition: HFShowerPMT.cc:80
const double MeV
double pePerGeV
Definition: HFShowerPMT.h:38
std::vector< int > pmtR2
Definition: HFShowerPMT.h:42
const std::vector< double > & getRTableHF() const
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:155
DDsvalues_type mergedSpecifics() const
double getHits(G4Step *aStep)
Definition: HFShowerPMT.cc:91
bool firstChild()
set the current node to the first child ...
HFCherenkov * cherenkov
Definition: HFShowerPMT.h:37
HFShowerPMT(std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
Definition: HFShowerPMT.cc:22
std::vector< int > pmtFib2
Definition: HFShowerPMT.h:42
std::vector< int > pmtR1
Definition: HFShowerPMT.h:41
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:245
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:32