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
61 TTree*
event(
nullptr);
62 if (
newForm)
event = (TTree *)
hf ->Get(
"HFSimHits");
63 else event = (TTree *)
hf ->Get(
"Events");
65 TBranch *evtInfo(
nullptr);
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());
108 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary:Branch " << emName
109 <<
" has " <<
emBranch->GetEntries()
110 <<
" entries and Branch " << hadName
113 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::No packing information -" 114 <<
" Assume x, y, z are not in packed form";
116 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Maximum probability cut off " 117 << probMax <<
" Back propagation of light prob. " 140 emPDG = theParticleTable->FindParticle(parName=
"e-")->GetPDGEncoding();
141 epPDG = theParticleTable->FindParticle(parName=
"e+")->GetPDGEncoding();
142 gammaPDG = theParticleTable->FindParticle(parName=
"gamma")->GetPDGEncoding();
143 pi0PDG = theParticleTable->FindParticle(parName=
"pi0")->GetPDGEncoding();
144 etaPDG = theParticleTable->FindParticle(parName=
"eta")->GetPDGEncoding();
145 nuePDG = theParticleTable->FindParticle(parName=
"nu_e")->GetPDGEncoding();
146 numuPDG = theParticleTable->FindParticle(parName=
"nu_mu")->GetPDGEncoding();
147 nutauPDG= theParticleTable->FindParticle(parName=
"nu_tau")->GetPDGEncoding();
148 anuePDG = theParticleTable->FindParticle(parName=
"anti_nu_e")->GetPDGEncoding();
149 anumuPDG= theParticleTable->FindParticle(parName=
"anti_nu_mu")->GetPDGEncoding();
150 anutauPDG= theParticleTable->FindParticle(parName=
"anti_nu_tau")->GetPDGEncoding();
151 geantinoPDG= theParticleTable->FindParticle(parName=
"geantino")->GetPDGEncoding();
153 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Particle codes for e- = " 154 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = " 157 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = " 159 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = " 166 rMax = rTable[rTable.size()-1];
168 <<
" cm and rMax " <<
rMax/cm;
173 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: (Half) Phi Width of wedge " 178 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: " <<
gpar.size() <<
" gpar (cm)";
179 for (
unsigned int ig=0; ig<
gpar.size(); ig++)
180 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: gpar[" << ig <<
"] = " 181 <<
gpar[ig]/cm <<
" cm";
190 const G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
191 const G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
192 const G4Track *
track = aStep->GetTrack();
194 const G4DynamicParticle *aParticle = track->GetDynamicParticle();
195 const G4ThreeVector& momDir = aParticle->GetMomentumDirection();
197 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
198 G4String partType = track->GetDefinition()->GetParticleName();
199 int parCode = track->GetDefinition()->GetPDGEncoding();
202 G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
203 double zoff = localPos.z() + 0.5*
gpar[1];
205 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: getHits " << partType
206 <<
" of energy " << pin/
GeV <<
" GeV" 207 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
208 <<
", " << momDir.z() <<
" Pos x,y,z = " 209 << hitPoint.x() <<
"," << hitPoint.y() <<
"," 210 << hitPoint.z() <<
" (" << zoff
211 <<
") sphi,cphi,stheta,ctheta = " <<
sin(momDir.phi())
212 <<
"," <<
cos(momDir.phi()) <<
", " <<
sin(momDir.theta())
213 <<
"," <<
cos(momDir.theta());
216 double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
217 double pin = preStepPoint->GetTotalEnergy();
219 return fillHits(hitPoint,momDir,parCode,pin,ok,weight,tSlice,onlyLong);
223 const G4ThreeVector & momDir,
224 int parCode,
double pin,
bool &
ok,
225 double weight,
double tSlice,
bool onlyLong) {
227 std::vector<HFShowerLibrary::Hit>
hit;
235 double pz = momDir.
z();
236 double zint = hitPoint.z();
240 if (pz * zint < 0.) backward = 1;
242 double sphi =
sin(momDir.phi());
243 double cphi =
cos(momDir.phi());
244 double ctheta =
cos(momDir.theta());
245 double stheta =
sin(momDir.theta());
263 for (
int i = 0;
i <
npe;
i++) {
266 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
268 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
269 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
272 }
else if (backward == 0) {
273 if (
pe[
i].
z() < 0) depth = 2;
275 double r = G4UniformRand();
276 if (r > 0.5) depth = 2;
282 double pex =
pe[
i].x();
283 double pey =
pe[
i].y();
285 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
286 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
287 double zz = -pex*stheta + zv*ctheta;
289 G4ThreeVector
pos = hitPoint + G4ThreeVector(xx,yy,zz);
291 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
295 double r = pos.perp();
297 double fi = pos.phi();
298 if (fi < 0) fi += twopi;
300 isect = (isect + 1) / 2;
301 double dfi = ((isect*2-1)*
dphi - fi);
302 if (dfi < 0) dfi = -dfi;
303 double dfir = r *
sin(dfi);
305 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Position shift " << xx
306 <<
", " << yy <<
", " << zz <<
": " << pos
307 <<
" R " << r <<
" Phi " << fi <<
" Section " 308 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
311 double r1 = G4UniformRand();
312 double r2 = G4UniformRand();
314 if (backward) r3 = G4UniformRand();
319 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
320 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi " 322 << zz <<
" zLim " <<
gpar[4] <<
":" 324 <<
" rInside(r) :" <<
rInside(r)
325 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
326 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
327 <<
" r3 <= backProb :" << (r3 <=
backProb)
328 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
329 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
330 <<
" zz <= gpar[4]+gpar[1] :" 335 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
339 hit.push_back(oneHit);
341 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
342 <<
" position " << (hit[nHit].position)
343 <<
" Depth " << (hit[nHit].depth) <<
" Time " 344 << tSlice <<
":" <<
pe[
i].t() <<
":" 351 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
354 r1 = G4UniformRand();
355 r2 = G4UniformRand();
356 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
360 hit.push_back(oneHit);
362 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
363 <<
" position " << (hit[nHit].position)
364 <<
" Depth " << (hit[nHit].depth) <<
" Time " 365 << tSlice <<
":" <<
pe[
i].t() <<
":" 376 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Total Hits " << nHit
377 <<
" out of " << npe <<
" PE";
379 if (nHit > npe && !onlyLong)
381 <<
" smaller than " << nHit <<
" Hits";
388 if (r >=
rMin && r <=
rMax)
return true;
404 std::vector<float>
t;
405 std::vector<float> *tp=&
t;
408 unsigned int tSize=t.size()/5;
409 photo->reserve(tSize);
410 for (
unsigned int i=0;
i<tSize;
i++ ) {
411 photo->push_back(
HFShowerPhoton( t[
i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
425 std::vector<float>
t;
426 std::vector<float> *tp=&
t;
429 unsigned int tSize=t.size()/5;
430 photo->reserve(tSize);
431 for (
unsigned int i=0;
i<tSize;
i++ ) {
432 photo->push_back(
HFShowerPhoton( t[
i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
442 LogDebug(
"HFShower") <<
"HFShowerLibrary::getRecord: Record " << record
443 <<
" of type " << type <<
" with " << nPhoton
445 for (
int j = 0; j < nPhoton; j++)
454 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
455 branch->SetAddress(&eventInfoCollection);
457 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads " 458 <<
" EventInfo Collection of size " 459 << eventInfoCollection.size() <<
" records";
460 totEvents = eventInfoCollection[0].totalEvents();
461 nMomBin = eventInfoCollection[0].numberOfBins();
462 evtPerBin = eventInfoCollection[0].eventsPerBin();
463 libVers = eventInfoCollection[0].showerLibraryVersion();
464 listVersion = eventInfoCollection[0].physListVersion();
465 pmom = eventInfoCollection[0].energyBins();
467 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads " 468 <<
" EventInfo from hardwired numbers";
474 pmom = {2,3,5,7,10,15,20,30,50,75,100,150,250,350,500,1000};
483 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/
GeV 484 <<
" GeV with " <<
nMomBin <<
" momentum bins and " 489 double r = G4UniformRand();
496 for (
int j=0; j<
nMomBin-1; j++) {
497 if (pin >=
pmom[j] && pin <
pmom[j+1]) {
499 if (j == nMomBin-2) {
509 << irc[0] <<
" now set to 0";
511 }
else if (irc[0] > totEvents) {
521 << irc[1] <<
" now set to 1";
523 }
else if (irc[1] > totEvents) {
530 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Select records " << irc[0]
531 <<
" and " << irc[1] <<
" with weights " << 1-w
537 for (
int ir=0; ir < 2; ir++) {
542 for (
int j=0; j<nPhoton; j++) {
544 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
551 if ((
npe > npold || (npold == 0 && irc[0] > 0)) && !(
npe == 0 && npold == 0))
552 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Interpolation Warning ==" 553 <<
" records " << irc[0] <<
" and " << irc[1]
554 <<
" gives a buffer of " << npold
555 <<
" photons and fills " <<
npe <<
" *****";
558 LogDebug(
"HFShower") <<
"HFShowerLibrary: Interpolation == records " 559 << irc[0] <<
" and " << irc[1] <<
" gives a " 560 <<
"buffer of " << npold <<
" photons and fills " 562 for (
int j=0; j<
npe; j++)
563 LogDebug(
"HFShower") <<
"Photon " << j <<
" " <<
pe[j];
573 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
574 <<
" GeV with " <<
nMomBin <<
" momentum bins and " 576 <<
" using " << nrec <<
" records";
578 std::vector<int> irc(nrec);
580 for (
int ir=0; ir<nrec; ir++) {
581 double r = G4UniformRand();
585 <<
"] = " << irc[ir] <<
" now set to 1";
589 <<
"] = " << irc[ir] <<
" now set to " 594 LogDebug(
"HFShower") <<
"HFShowerLibrary::Extrapolation use irc[" 595 << ir <<
"] = " << irc[ir];
603 for (
int ir=0; ir<nrec; ir++) {
608 for (
int j=0; j<nPhoton; j++) {
609 double r = G4UniformRand();
610 if (ir != nrec-1 || r < w) {
615 LogDebug(
"HFShower") <<
"HFShowerLibrary: Record [" << ir <<
"] = " 616 << irc[ir] <<
" npold = " << npold;
621 LogDebug(
"HFShower") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
624 if (
npe > npold || npold == 0)
625 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Extrapolation Warning == " 626 << nrec <<
" records " << irc[0] <<
", " 627 << irc[1] <<
", ... gives a buffer of " <<npold
628 <<
" photons and fills " <<
npe 632 LogDebug(
"HFShower") <<
"HFShowerLibrary: Extrapolation == " << nrec
633 <<
" records " << irc[0] <<
", " << irc[1]
634 <<
", ... gives a buffer of " << npold
635 <<
" photons and fills " << npe <<
" PE";
636 for (
int j=0; j<
npe; j++)
637 LogDebug(
"HFShower") <<
"Photon " << j <<
" " <<
pe[j];
646 LogDebug(
"HFShower") <<
"HFShowerLibrary: storePhoton " << j <<
" npe " 657 LogDebug(
"HFShower") <<
"HFShowerLibrary:getDDDArray called for " << str
658 <<
" with nMin " << nmin;
665 const std::vector<double> & fvec = value.
doubles();
666 int nval = fvec.size();
669 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
670 <<
" bins " << nval <<
" < " << nmin
673 <<
"nval < nmin for array " << str <<
"\n";
677 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
678 <<
" bins " << nval <<
" < 2 ==> illegal" 679 <<
" (nmin=" << nmin <<
")";
681 <<
"nval < 2 for array " << str <<
"\n";
690 <<
"cannot get array " << str <<
"\n";
double tShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
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 *.
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)
HFShowerLibrary(const std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
std::vector< Hit > fillHits(const G4ThreeVector &p, const G4ThreeVector &v, int parCode, double parEnergy, bool &ok, double weight, double time, bool onlyLong=false)
HFShowerPhotonCollection photon
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
void interpolate(int, double)