CMS 3D CMS Logo

ZdcShowerLibrary.cc
Go to the documentation of this file.
1 // File: ZdcShowerLibrary.cc
3 // Description: Shower library for the Zero Degree Calorimeter
4 // E. Garcia June 2008
6 
13 
14 #include "G4VPhysicalVolume.hh"
15 #include "G4Step.hh"
16 #include "G4Track.hh"
17 #include "Randomize.hh"
18 #include "CLHEP/Units/GlobalSystemOfUnits.h"
19 
21  edm::ParameterSet const & p) {
22  edm::ParameterSet m_HS = p.getParameter<edm::ParameterSet>("ZdcShowerLibrary");
23  verbose = m_HS.getUntrackedParameter<int>("Verbosity",0);
24 
25  npe = 9; // number of channels or fibers where the energy will be deposited
26  hits.reserve(npe);
27 }
28 
30 }
31 
32 std::vector<ZdcShowerLibrary::Hit> & ZdcShowerLibrary::getHits(const G4Step * aStep, bool & ok) {
33 
34  const G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
35  const G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
36  const G4Track * track = aStep->GetTrack();
37 
38  const G4DynamicParticle *aParticle = track->GetDynamicParticle();
39  const G4ThreeVector& momDir = aParticle->GetMomentumDirection();
40  double energy = preStepPoint->GetKineticEnergy();
41  G4ThreeVector hitPoint = preStepPoint->GetPosition();
42  const G4ThreeVector& hitPointOrig = preStepPoint->GetPosition();
43  G4int parCode = track->GetDefinition()->GetPDGEncoding();
44 
45  hits.clear();
46 
47  ok = false;
49  bool isHad = G4TrackToParticleID::isStableHadronIon(track);
50  if (!isEM && !isHad)
51  return hits;
52  ok = true;
53 
54  G4ThreeVector pos;
55  G4ThreeVector posLocal;
56  double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
57 
58  int nHit = 0;
60  bool side = false;
61  int channel = 0;
62  double xx,yy,zz;
63  double xxlocal, yylocal, zzlocal;
64 
65  ZdcShowerLibrary::Hit oneHit;
66  side = (hitPointOrig.z() > 0.) ? true : false;
67 
68  float xWidthEM = std::abs(theXChannelBoundaries[0] - theXChannelBoundaries[1]);
69  float zWidthEM = std::abs(theZSectionBoundaries[0] - theZSectionBoundaries[1]);
71 
72  for (int i = 0; i < npe; i++) {
73  if(i < 5){
74  section = HcalZDCDetId::EM;
75  channel = i+1;
76  xxlocal = theXChannelBoundaries[i]+(xWidthEM/2.);
77  xx = xxlocal + X0;
78  yy = 0.0;
79  yylocal = yy + Y0;
80  zzlocal = theZSectionBoundaries[0]+(zWidthEM/2.);
81  zz = (hitPointOrig.z() > 0.) ? zzlocal + Z0 : zzlocal - Z0;
82  pos = G4ThreeVector(xx,yy,zz);
83  posLocal = G4ThreeVector(xxlocal,yylocal,zzlocal);
84  }
85  if(i > 4){
86  section = HcalZDCDetId::HAD;
87  channel = i - 4;
88  xxlocal = 0.0;
89  xx = xxlocal + X0;
90  yylocal = 0;
91  yy = yylocal + Y0;
92  zzlocal = (hitPointOrig.z() > 0.) ?
93  theZHadChannelBoundaries[i-5] + (zWidthHAD/2.) : theZHadChannelBoundaries[i-5] - (zWidthHAD/2.);
94  zz = (hitPointOrig.z() > 0.) ? zzlocal + Z0 : zzlocal - Z0;
95  pos = G4ThreeVector(xx,yy,zz);
96  posLocal = G4ThreeVector(xxlocal,yylocal,zzlocal);
97  }
98 
99  oneHit.position = pos;
100  oneHit.entryLocal = posLocal;
101  oneHit.depth = channel;
102  oneHit.time = tSlice;
103  oneHit.detID = HcalZDCDetId(section,side,channel);
104 
105 
106  // Note: coodinates of hit are relative to center of detector (X0,Y0,Z0)
107  hitPoint.setX(hitPointOrig.x()-X0);
108  hitPoint.setY(hitPointOrig.y()-Y0);
109  double setZ= (hitPointOrig.z()> 0.) ? hitPointOrig.z()- Z0 : fabs(hitPointOrig.z()) - Z0;
110  hitPoint.setZ(setZ);
111 
112  int dE = getEnergyFromLibrary(hitPoint,momDir,energy,parCode,section,side,channel);
113 
114  if (isEM) {
115  oneHit.DeEM = dE;
116  oneHit.DeHad = 0.;
117  } else {
118  oneHit.DeEM = 0;
119  oneHit.DeHad = dE;
120  }
121 
122  hits.push_back(oneHit);
123 
124  LogDebug("ZdcShower")
125  << "\nZdcShowerLibrary:Generated Hit " << nHit
126  <<" orig hit pos " << hitPointOrig
127  <<" orig hit pos local coord" << hitPoint
128  <<" new position " << (hits[nHit].position)
129  <<" Channel " <<(hits[nHit].depth)
130  <<" side "<< side
131  <<" Time " <<(hits[nHit].time)
132  <<" DetectorID " << (hits[nHit].detID)
133  <<" Had Energy " << (hits[nHit].DeHad)
134  <<" EM Energy " << (hits[nHit].DeEM)
135  <<"\n";
136  nHit++;
137  }
138  return hits;
139 }
140 
141 
142 int ZdcShowerLibrary::getEnergyFromLibrary(const G4ThreeVector& hitPoint, const G4ThreeVector& momDir, double energy,
143  G4int parCode,HcalZDCDetId::Section section, bool side, int channel){
144  int nphotons = -1;
145 
146  energy =energy/GeV;
147 
148  LogDebug("ZdcShower")
149  <<"\n ZdcShowerLibrary::getEnergyFromLibrary input/output variables:"
150  <<" phi: "<<59.2956*momDir.phi()
151  <<" theta: "<<59.2956*momDir.theta()
152  <<" xin : "<<hitPoint.x()
153  <<" yin : "<<hitPoint.y()
154  <<" zin : "<<hitPoint.z()
155  <<" track en: " <<energy<< "(GeV)"
156  <<" section: "<<section
157  <<" side: "<<side
158  <<" channel: "<< channel
159  <<" partID: "<<parCode;
160 
161  double eav = 0.;
162  double esig = 0.;
163  double edis = 0.;
164 
165  float xin = hitPoint.x();
166  float yin = hitPoint.y();
167  float fact = 0.;
168 
170 
171  if(section == 1 && !isEM){
172  if(channel < 5 )
173  if(((theXChannelBoundaries[channel-1])< (xin + X0)) && ((xin + X0)<= theXChannelBoundaries[channel]))fact= 0.18;
174  if(channel ==5 )
175  if(theXChannelBoundaries[channel-1]< xin + X0)fact = 0.18;
176  }
177 
178  if(section == 2 && !isEM){
179  if(channel == 1)fact = 0.34;
180  if(channel == 2)fact = 0.24;
181  if(channel == 3)fact = 0.17;
182  if(channel == 4)fact = 0.07;
183  }
184  if(section == 1 && isEM){
185  if(channel < 5 )
186  if(((theXChannelBoundaries[channel-1])< (xin + X0)) && ((xin + X0)<= theXChannelBoundaries[channel]))fact= 1.;
187  if(channel ==5 )
188  if(theXChannelBoundaries[channel-1]< xin + X0)fact = 1.0;
189  }
190 
191  //change to cm for parametrization
192  yin = yin/cm;
193  xin = xin/cm;
194 
195  if (isEM){
196  eav = ((((((-0.0002*xin-2.0e-13)*xin+0.0022)*xin+1.0e-11)*xin-0.0217)*xin-3.0e-10)*xin+1.0028)*
197  (((0.0001*yin + 0.0056)*yin + 0.0508)*yin + 1.0)*300.0*pow((energy/300.0),0.99); // EM
198  esig = ((((((0.0005*xin - 1.0e-12)*xin - 0.0052)*xin + 5.0e-11)*xin + 0.032)*xin -
199  2.0e-10)*xin + 1.0)*(((0.0006*yin + 0.0071)*yin - 0.031)*yin + 1.0)*30.0*pow((energy/300.0),0.54);// EM
200  edis = 1.0;
201  }else{
202  eav = ((((((-0.0002*xin-2.0e-13)*xin+0.0022)*xin+1.0e-11)*xin-0.0217)*xin-3.0e-10)*xin+1.0028)*
203  (((0.0001*yin + 0.0056)*yin + 0.0508)*yin + 1.0)*300.0*pow((energy/300.0),1.12);// HD
204  esig = ((((((0.0005*xin - 1.0e-12)*xin - 0.0052)*xin + 5.0e-11)*xin + 0.032)*xin -
205  2.0e-10)*xin + 1.0)*(((0.0006*yin + 0.0071)*yin - 0.031)*yin + 1.0)*54.0*pow((energy/300.0),0.93); //HD
206  edis = 3.0;
207  }
208 
209  if(eav <0. || edis <0.){
210  LogDebug("ZdcShower")
211  <<" Negative everage energy from parametrization \n"
212  <<" xin: "<<xin<< "(cm)"
213  <<" yin: "<<yin<< "(cm)"
214  <<" track en: " <<energy<< "(GeV)"
215  <<" eaverage: "<<eav/GeV << " (GeV)"
216  <<" esigma: "<<esig/GeV << " (GeV)"
217  <<" edist: "<<edis << " (GeV)"
218  <<" dE hit: "<<nphotons/GeV<< " (GeV)";
219  return 0;
220  }
221 
222  // Convert from GeV to MeV for the code
223  eav = eav*GeV;
224  esig= esig*GeV;
225 
226  while(nphotons == -1 || nphotons > int(eav + 5.*esig))
227  nphotons = (int)(fact*photonFluctuation(eav, esig, edis));
228 
229  LogDebug("ZdcShower")
230  //std::cout
231  <<" track en: " <<energy<< "(GeV)"
232  <<" eaverage: "<<eav/GeV << " (GeV)"
233  <<" esigma: "<<esig/GeV << " (GeV)"
234  <<" edist: "<<edis << " (GeV)"
235  <<" dE hit: "<<nphotons/GeV<< " (GeV)";
236 
237  return nphotons;
238 }
239 
240 int ZdcShowerLibrary::photonFluctuation(double eav, double esig,double edis){
241  int nphot=0;
242  double efluct = 0.;
243  if(edis == 1.0) efluct = eav+esig*CLHEP::RandGaussQ::shoot();
244  if(edis == 3.0) efluct = eav+esig*CLHEP::RandLandau::shoot();
245  nphot = int(efluct);
246  if(nphot<0)nphot = 0;
247  return nphot;
248 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const double GeV
Definition: MathUtil.h:16
G4ThreeVector entryLocal
static const double Z0
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
int getEnergyFromLibrary(const G4ThreeVector &posHit, const G4ThreeVector &momDir, double energy, G4int parCode, HcalZDCDetId::Section section, bool side, int channel)
static const double theXChannelBoundaries[]
std::vector< ZdcShowerLibrary::Hit > hits
static const double theZHadChannelBoundaries[]
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const double theZSectionBoundaries[]
static bool isStableHadronIon(const G4Track *)
int photonFluctuation(double eav, double esig, double edis)
const double fact
static bool isGammaElectronPositron(int pdgCode)
std::vector< Hit > & getHits(const G4Step *aStep, bool &ok)
static const double Y0
ZdcShowerLibrary(const std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
static const double X0
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40