14 #include "G4VPhysicalVolume.hh"
15 #include "G4NavigationHistory.hh"
18 #include "Randomize.hh"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 #include "CLHEP/Units/GlobalPhysicalConstants.h"
37 backProb = m_HS.getParameter<
double>(
"BackProbability");
40 std::string branchEvInfo = m_HS.getUntrackedParameter<
std::string>(
"BranchEvt",
"HFShowerLibraryEventInfos_hfshowerlib_HFShowerLibraryEventInfo");
41 std::string branchPre = m_HS.getUntrackedParameter<
std::string>(
"BranchPre",
"HFShowerPhotons_hfshowerlib_");
43 verbose = m_HS.getUntrackedParameter<
bool>(
"Verbosity",
false);
44 applyFidCut = m_HS.getParameter<
bool>(
"ApplyFiducialCut");
46 if (pTreeName.find(
".") == 0) pTreeName.erase(0,2);
47 const char* nTree = pTreeName.c_str();
48 hf = TFile::Open(nTree);
51 edm::LogError(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
54 <<
"Opening of " << pTreeName <<
" fails\n";
56 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
62 if (
newForm)
event = (TTree *)
hf ->Get(
"HFSimHits");
63 else event = (TTree *)
hf ->Get(
"Events");
68 evtInfo =
event->GetBranch(info.c_str());
73 edm::LogError(
"HFShower") <<
"HFShowerLibrary: HFShowerLibrayEventInfo"
74 <<
" Branch does not exist in Event";
76 <<
"Event information absent\n";
79 edm::LogError(
"HFShower") <<
"HFShowerLibrary: Events Tree does not "
82 <<
"Events tree absent\n";
87 <<
" Events Total " <<
totEvents <<
" and "
89 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Energies (GeV) with "
92 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: pmom[" <<
i <<
"] = "
95 std::string nameBr = branchPre + emName + branchPost;
96 emBranch =
event->GetBranch(nameBr.c_str());
98 nameBr = branchPre + hadName + branchPost;
99 hadBranch =
event->GetBranch(nameBr.c_str());
101 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary:Branch " << emName
102 <<
" has " <<
emBranch->GetEntries()
103 <<
" entries and Branch " << hadName
106 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::No packing information -"
107 <<
" Assume x, y, z are not in packed form";
109 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Maximum probability cut off "
110 << probMax <<
" Back propagation of light prob. "
132 emPDG = theParticleTable->FindParticle(parName=
"e-")->GetPDGEncoding();
133 epPDG = theParticleTable->FindParticle(parName=
"e+")->GetPDGEncoding();
134 gammaPDG = theParticleTable->FindParticle(parName=
"gamma")->GetPDGEncoding();
135 pi0PDG = theParticleTable->FindParticle(parName=
"pi0")->GetPDGEncoding();
136 etaPDG = theParticleTable->FindParticle(parName=
"eta")->GetPDGEncoding();
137 nuePDG = theParticleTable->FindParticle(parName=
"nu_e")->GetPDGEncoding();
138 numuPDG = theParticleTable->FindParticle(parName=
"nu_mu")->GetPDGEncoding();
139 nutauPDG= theParticleTable->FindParticle(parName=
"nu_tau")->GetPDGEncoding();
140 anuePDG = theParticleTable->FindParticle(parName=
"anti_nu_e")->GetPDGEncoding();
141 anumuPDG= theParticleTable->FindParticle(parName=
"anti_nu_mu")->GetPDGEncoding();
142 anutauPDG= theParticleTable->FindParticle(parName=
"anti_nu_tau")->GetPDGEncoding();
143 geantinoPDG= theParticleTable->FindParticle(parName=
"geantino")->GetPDGEncoding();
145 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Particle codes for e- = "
146 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = "
149 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = "
151 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = "
158 rMax = rTable[rTable.size()-1];
160 <<
" cm and rMax " <<
rMax/cm;
165 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: (Half) Phi Width of wedge "
170 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: " <<
gpar.size() <<
" gpar (cm)";
171 for (
unsigned int ig=0; ig<
gpar.size(); ig++)
172 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: gpar[" << ig <<
"] = "
173 <<
gpar[ig]/cm <<
" cm";
182 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
183 G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
184 G4Track * track = aStep->GetTrack();
186 const G4DynamicParticle *aParticle = track->GetDynamicParticle();
187 G4ThreeVector momDir = aParticle->GetMomentumDirection();
190 G4ThreeVector hitPoint = preStepPoint->GetPosition();
191 G4String partType = track->GetDefinition()->GetParticleName();
192 int parCode = track->GetDefinition()->GetPDGEncoding();
195 G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
196 double zoff = localPos.z() + 0.5*
gpar[1];
198 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: getHits " << partType
199 <<
" of energy " << pin/
GeV <<
" GeV"
200 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
201 <<
", " << momDir.z() <<
" Pos x,y,z = "
202 << hitPoint.x() <<
"," << hitPoint.y() <<
","
203 << hitPoint.z() <<
" (" << zoff
204 <<
") sphi,cphi,stheta,ctheta = " <<
sin(momDir.phi())
205 <<
"," <<
cos(momDir.phi()) <<
", " <<
sin(momDir.theta())
206 <<
"," <<
cos(momDir.theta());
209 double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
210 double pin = preStepPoint->GetTotalEnergy();
212 return fillHits(hitPoint,momDir,parCode,pin,ok,weight,tSlice,onlyLong);
216 G4ThreeVector & momDir,
217 int parCode,
double pin,
bool &
ok,
218 double weight,
double tSlice,
bool onlyLong) {
220 std::vector<HFShowerLibrary::Hit>
hit;
228 double pz = momDir.
z();
229 double zint = hitPoint.z();
233 if (pz * zint < 0.) backward = 1;
235 double sphi =
sin(momDir.phi());
236 double cphi =
cos(momDir.phi());
237 double ctheta =
cos(momDir.theta());
238 double stheta =
sin(momDir.theta());
256 for (
int i = 0;
i <
npe;
i++) {
259 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
261 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
262 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
265 }
else if (backward == 0) {
266 if (
pe[
i].
z() < 0) depth = 2;
268 double r = G4UniformRand();
269 if (r > 0.5) depth = 2;
275 double pex =
pe[
i].x();
276 double pey =
pe[
i].y();
278 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
279 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
280 double zz = -pex*stheta + zv*ctheta;
282 G4ThreeVector pos = hitPoint + G4ThreeVector(xx,yy,zz);
284 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
288 double r = pos.perp();
290 double fi = pos.phi();
291 if (fi < 0) fi += twopi;
292 int isect = int(fi/
dphi) + 1;
293 isect = (isect + 1) / 2;
294 double dfi = ((isect*2-1)*
dphi - fi);
295 if (dfi < 0) dfi = -dfi;
296 double dfir = r *
sin(dfi);
298 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Position shift " << xx
299 <<
", " << yy <<
", " << zz <<
": " << pos
300 <<
" R " << r <<
" Phi " << fi <<
" Section "
301 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
304 double r1 = G4UniformRand();
305 double r2 = G4UniformRand();
307 if (backward) r3 = G4UniformRand();
312 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
313 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi "
315 << zz <<
" zLim " <<
gpar[4] <<
":"
317 <<
" rInside(r) :" <<
rInside(r)
318 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
319 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
320 <<
" r3 <= backProb :" << (r3 <=
backProb)
321 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
322 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
323 <<
" zz <= gpar[4]+gpar[1] :"
328 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
332 hit.push_back(oneHit);
334 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
335 <<
" position " << (hit[nHit].position)
336 <<
" Depth " << (hit[nHit].depth) <<
" Time "
337 << tSlice <<
":" <<
pe[
i].t() <<
":"
344 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
347 r1 = G4UniformRand();
348 r2 = G4UniformRand();
349 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
353 hit.push_back(oneHit);
355 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
356 <<
" position " << (hit[nHit].position)
357 <<
" Depth " << (hit[nHit].depth) <<
" Time "
358 << tSlice <<
":" <<
pe[
i].t() <<
":"
369 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Total Hits " << nHit
370 <<
" out of " << npe <<
" PE";
372 if (nHit > npe && !onlyLong)
374 <<
" smaller than " << nHit <<
" Hits";
381 if (r >=
rMin && r <=
rMax)
return true;
408 LogDebug(
"HFShower") <<
"HFShowerLibrary::getRecord: Record " << record
409 <<
" of type " << type <<
" with " << nPhoton
411 for (
int j = 0;
j < nPhoton;
j++)
420 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
421 branch->SetAddress(&eventInfoCollection);
423 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
424 <<
" EventInfo Collection of size "
425 << eventInfoCollection.size() <<
" records";
426 totEvents = eventInfoCollection[0].totalEvents();
427 nMomBin = eventInfoCollection[0].numberOfBins();
428 evtPerBin = eventInfoCollection[0].eventsPerBin();
429 libVers = eventInfoCollection[0].showerLibraryVersion();
430 listVersion = eventInfoCollection[0].physListVersion();
431 pmom = eventInfoCollection[0].energyBins();
433 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
434 <<
" EventInfo from hardwired numbers";
440 pmom = {2,3,5,7,10,15,20,30,50,75,100,150,250,350,500,1000};
449 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/
GeV
450 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
455 double r = G4UniformRand();
465 if (j == nMomBin-2) {
475 << irc[0] <<
" now set to 0";
477 }
else if (irc[0] > totEvents) {
487 << irc[1] <<
" now set to 1";
489 }
else if (irc[1] > totEvents) {
496 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Select records " << irc[0]
497 <<
" and " << irc[1] <<
" with weights " << 1-w
503 for (
int ir=0; ir < 2; ir++) {
508 for (
int j=0;
j<nPhoton;
j++) {
510 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
517 if ((
npe > npold || (npold == 0 && irc[0] > 0)) && !(
npe == 0 && npold == 0))
518 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Interpolation Warning =="
519 <<
" records " << irc[0] <<
" and " << irc[1]
520 <<
" gives a buffer of " << npold
521 <<
" photons and fills " <<
npe <<
" *****";
524 LogDebug(
"HFShower") <<
"HFShowerLibrary: Interpolation == records "
525 << irc[0] <<
" and " << irc[1] <<
" gives a "
526 <<
"buffer of " << npold <<
" photons and fills "
539 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
540 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
542 <<
" using " << nrec <<
" records";
544 std::vector<int> irc(nrec);
546 for (
int ir=0; ir<nrec; ir++) {
547 double r = G4UniformRand();
551 <<
"] = " << irc[ir] <<
" now set to 1";
555 <<
"] = " << irc[ir] <<
" now set to "
560 LogDebug(
"HFShower") <<
"HFShowerLibrary::Extrapolation use irc["
561 << ir <<
"] = " << irc[ir];
569 for (
int ir=0; ir<nrec; ir++) {
574 for (
int j=0;
j<nPhoton;
j++) {
575 double r = G4UniformRand();
576 if (ir != nrec-1 || r < w) {
581 LogDebug(
"HFShower") <<
"HFShowerLibrary: Record [" << ir <<
"] = "
582 << irc[ir] <<
" npold = " << npold;
587 LogDebug(
"HFShower") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
590 if (
npe > npold || npold == 0)
591 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Extrapolation Warning == "
592 << nrec <<
" records " << irc[0] <<
", "
593 << irc[1] <<
", ... gives a buffer of " <<npold
594 <<
" photons and fills " <<
npe
598 LogDebug(
"HFShower") <<
"HFShowerLibrary: Extrapolation == " << nrec
599 <<
" records " << irc[0] <<
", " << irc[1]
600 <<
", ... gives a buffer of " << npold
601 <<
" photons and fills " << npe <<
" PE";
612 LogDebug(
"HFShower") <<
"HFShowerLibrary: storePhoton " << j <<
" npe "
623 LogDebug(
"HFShower") <<
"HFShowerLibrary:getDDDArray called for " << str
624 <<
" with nMin " << nmin;
631 const std::vector<double> & fvec = value.
doubles();
632 int nval = fvec.size();
635 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
636 <<
" bins " << nval <<
" < " << nmin
639 <<
"nval < nmin for array " << str <<
"\n";
643 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
644 <<
" bins " << nval <<
" < 2 ==> illegal"
645 <<
" (nmin=" << nmin <<
")";
647 <<
"nval < 2 for array " << str <<
"\n";
654 edm::LogError(
"HFShower") <<
"HFShowerLibrary : cannot get array " << str;
656 <<
"cannot get array " << str <<
"\n";
double tShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
std::vector< Hit > fillHits(G4ThreeVector &p, G4ThreeVector &v, int parCode, double parEnergy, bool &ok, double weight, double time, bool onlyLong=false)
T getParameter(std::string const &) const
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
void initRun(HcalDDDSimConstants *)
std::vector< Hit > getHits(G4Step *aStep, bool &ok, double weight, bool onlyLong=false)
Sin< T >::type sin(const T &t)
double attLength(double lambda)
HFShowerPhotonCollection pe
double zShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
type of data representation of DDCompactView
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
HFShowerLibrary(std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
const std::vector< double > & getRTableHF() const
Cos< T >::type cos(const T &t)
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::...
void loadEventInfo(TBranch *)
const std::vector< double > & getPhiTableHF() const
Abs< T >::type abs(const T &t)
std::vector< double > gpar
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &, int &)
HFShowerPhotonCollection * photo
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
const std::vector< double > & getGparHF() const
std::vector< double > pmom
void extrapolate(int, double)
HFShowerPhotonCollection photon
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
void interpolate(int, double)