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
60 TTree*
event = (TTree *)
hf ->Get(
"Events");
63 TBranch *evtInfo =
event->GetBranch(info.c_str());
67 edm::LogError(
"HFShower") <<
"HFShowerLibrary: HFShowerLibrayEventInfo"
68 <<
" Branch does not exist in Event";
70 <<
"Event information absent\n";
73 edm::LogError(
"HFShower") <<
"HFShowerLibrary: Events Tree does not "
76 <<
"Events tree absent\n";
81 <<
" Events Total " <<
totEvents <<
" and "
83 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Energies (GeV) with "
86 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: pmom[" <<
i <<
"] = "
87 <<
pmom[
i]/GeV <<
" GeV";
89 std::string nameBr = branchPre + emName + branchPost;
90 emBranch =
event->GetBranch(nameBr.c_str());
92 nameBr = branchPre + hadName + branchPost;
93 hadBranch =
event->GetBranch(nameBr.c_str());
95 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary:Branch " << emName
97 <<
" entries and Branch " << hadName
100 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::No packing information -"
101 <<
" Assume x, y, z are not in packed form";
103 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Maximum probability cut off "
104 << probMax <<
" Back propagation of light prob. "
107 G4String attribute =
"ReadOutName";
110 DDValue ddv(attribute,value,0);
120 std::vector<double> rTable =
getDDDArray(
"rTable",sv,nR);
124 <<
" cm and rMax " <<
rMax/cm;
128 std::vector<double> etaTable =
getDDDArray(
"etaTable",sv,nEta);
129 int nPhi = nEta + nR - 2;
130 std::vector<double> phibin =
getDDDArray(
"phibin",sv,nPhi);
131 dphi = phibin[nEta-1];
132 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: (Half) Phi Width of wedge "
138 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: " << ngpar <<
" gpar (cm)";
139 for (
int ig=0; ig<ngpar; ig++)
140 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: gpar[" << ig <<
"] = "
141 <<
gpar[ig]/cm <<
" cm";
143 edm::LogError(
"HFShower") <<
"HFShowerLibrary: cannot get filtered "
144 <<
" view for " << attribute <<
" matching "
147 <<
"cannot match " << attribute <<
" to " << name <<
"\n";
164 emPDG = theParticleTable->FindParticle(parName=
"e-")->GetPDGEncoding();
165 epPDG = theParticleTable->FindParticle(parName=
"e+")->GetPDGEncoding();
166 gammaPDG = theParticleTable->FindParticle(parName=
"gamma")->GetPDGEncoding();
167 pi0PDG = theParticleTable->FindParticle(parName=
"pi0")->GetPDGEncoding();
168 etaPDG = theParticleTable->FindParticle(parName=
"eta")->GetPDGEncoding();
169 nuePDG = theParticleTable->FindParticle(parName=
"nu_e")->GetPDGEncoding();
170 numuPDG = theParticleTable->FindParticle(parName=
"nu_mu")->GetPDGEncoding();
171 nutauPDG= theParticleTable->FindParticle(parName=
"nu_tau")->GetPDGEncoding();
172 anuePDG = theParticleTable->FindParticle(parName=
"anti_nu_e")->GetPDGEncoding();
173 anumuPDG= theParticleTable->FindParticle(parName=
"anti_nu_mu")->GetPDGEncoding();
174 anutauPDG= theParticleTable->FindParticle(parName=
"anti_nu_tau")->GetPDGEncoding();
175 geantinoPDG= theParticleTable->FindParticle(parName=
"geantino")->GetPDGEncoding();
177 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Particle codes for e- = "
178 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = "
181 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = "
183 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = "
194 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
195 G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
196 G4Track * track = aStep->GetTrack();
198 const G4DynamicParticle *aParticle = track->GetDynamicParticle();
199 G4ThreeVector momDir = aParticle->GetMomentumDirection();
202 G4ThreeVector hitPoint = preStepPoint->GetPosition();
203 G4String partType = track->GetDefinition()->GetParticleName();
204 int parCode = track->GetDefinition()->GetPDGEncoding();
206 std::vector<HFShowerLibrary::Hit>
hit;
214 double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
215 double pin = preStepPoint->GetTotalEnergy();
216 double pz = momDir.
z();
217 double zint = hitPoint.z();
221 if (pz * zint < 0.) backward = 1;
223 double sphi =
sin(momDir.phi());
224 double cphi =
cos(momDir.phi());
225 double ctheta =
cos(momDir.theta());
226 double stheta =
sin(momDir.theta());
229 G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
230 double zoff = localPos.z() + 0.5*
gpar[1];
232 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: getHits " << partType
233 <<
" of energy " << pin/GeV <<
" GeV"
234 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
235 <<
", " << momDir.z() <<
" Pos x,y,z = "
236 << hitPoint.x() <<
"," << hitPoint.y() <<
","
237 << hitPoint.z() <<
" (" << zoff
238 <<
") sphi,cphi,stheta,ctheta = " << sphi
239 <<
"," << cphi <<
", " << stheta <<
"," << ctheta;
258 for (
int i = 0;
i <
npe;
i++) {
261 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
263 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
264 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
267 }
else if (backward == 0) {
268 if (
pe[
i].
z() < 0) depth = 2;
270 double r = G4UniformRand();
271 if (r > 0.5) depth = 2;
277 double pex =
pe[
i].x();
278 double pey =
pe[
i].y();
280 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
281 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
282 double zz = -pex*stheta + zv*ctheta;
284 G4ThreeVector pos = hitPoint + G4ThreeVector(xx,yy,zz);
286 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
290 double r = pos.perp();
292 double fi = pos.phi();
293 if (fi < 0) fi += twopi;
294 int isect = int(fi/
dphi) + 1;
295 isect = (isect + 1) / 2;
296 double dfi = ((isect*2-1)*
dphi - fi);
297 if (dfi < 0) dfi = -dfi;
298 double dfir = r *
sin(dfi);
300 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Position shift " << xx
301 <<
", " << yy <<
", " << zz <<
": " << pos
302 <<
" R " << r <<
" Phi " << fi <<
" Section "
303 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
306 double r1 = G4UniformRand();
307 double r2 = G4UniformRand();
309 if (backward) r3 = G4UniformRand();
314 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
315 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi "
317 << zz <<
" zLim " <<
gpar[4] <<
":"
319 <<
" rInside(r) :" <<
rInside(r)
320 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
321 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
322 <<
" r3 <= backProb :" << (r3 <=
backProb)
323 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
324 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
325 <<
" zz <= gpar[4]+gpar[1] :"
330 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
332 oneHit.
depth = depth;
334 hit.push_back(oneHit);
336 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
337 <<
" position " << (hit[nHit].position)
338 <<
" Depth " << (hit[nHit].depth) <<
" Time "
339 << tSlice <<
":" <<
pe[
i].t() <<
":"
346 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
349 r1 = G4UniformRand();
350 r2 = G4UniformRand();
351 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
355 hit.push_back(oneHit);
357 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
358 <<
" position " << (hit[nHit].position)
359 <<
" Depth " << (hit[nHit].depth) <<
" Time "
360 << tSlice <<
":" <<
pe[
i].t() <<
":"
371 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Total Hits " << nHit
372 <<
" out of " << npe <<
" PE";
374 if (nHit > npe && !onlyLong)
376 <<
" smaller than " << nHit <<
" Hits";
383 if (r >=
rMin && r <=
rMax)
return true;
399 int nPhoton =
photon.size();
400 LogDebug(
"HFShower") <<
"HFShowerLibrary::getRecord: Record " << record
401 <<
" of type " << type <<
" with " << nPhoton
403 for (
int j = 0;
j < nPhoton;
j++)
410 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
411 branch->SetAddress(&eventInfoCollection);
413 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
414 <<
" EventInfo Collection of size "
415 << eventInfoCollection.size() <<
" records";
416 totEvents = eventInfoCollection[0].totalEvents();
417 nMomBin = eventInfoCollection[0].numberOfBins();
418 evtPerBin = eventInfoCollection[0].eventsPerBin();
419 libVers = eventInfoCollection[0].showerLibraryVersion();
420 listVersion = eventInfoCollection[0].physListVersion();
421 pmom = eventInfoCollection[0].energyBins();
422 for (
unsigned int i=0;
i<
pmom.size();
i++)
429 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/GeV
430 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
435 double r = G4UniformRand();
445 if (j == nMomBin-2) {
455 << irc[0] <<
" now set to 0";
457 }
else if (irc[0] > totEvents) {
467 << irc[1] <<
" now set to 1";
469 }
else if (irc[1] > totEvents) {
476 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Select records " << irc[0]
477 <<
" and " << irc[1] <<
" with weights " << 1-w
483 for (
int ir=0; ir < 2; ir++) {
486 int nPhoton =
photon.size();
488 for (
int j=0;
j<nPhoton;
j++) {
490 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
497 if (
npe > npold || (npold == 0 && irc[0] > 0))
498 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Interpolation Warning =="
499 <<
" records " << irc[0] <<
" and " << irc[1]
500 <<
" gives a buffer of " << npold
501 <<
" photons and fills " <<
npe <<
" *****";
504 LogDebug(
"HFShower") <<
"HFShowerLibrary: Interpolation == records "
505 << irc[0] <<
" and " << irc[1] <<
" gives a "
506 <<
"buffer of " << npold <<
" photons and fills "
519 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
520 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
522 <<
" using " << nrec <<
" records";
524 std::vector<int> irc(nrec);
526 for (
int ir=0; ir<nrec; ir++) {
527 double r = G4UniformRand();
531 <<
"] = " << irc[ir] <<
" now set to 1";
535 <<
"] = " << irc[ir] <<
" now set to "
540 LogDebug(
"HFShower") <<
"HFShowerLibrary::Extrapolation use irc["
541 << ir <<
"] = " << irc[ir];
549 for (
int ir=0; ir<nrec; ir++) {
552 int nPhoton =
photon.size();
554 for (
int j=0;
j<nPhoton;
j++) {
555 double r = G4UniformRand();
556 if (ir != nrec-1 || r < w) {
561 LogDebug(
"HFShower") <<
"HFShowerLibrary: Record [" << ir <<
"] = "
562 << irc[ir] <<
" npold = " << npold;
567 LogDebug(
"HFShower") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
570 if (
npe > npold || npold == 0)
571 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Extrapolation Warning == "
572 << nrec <<
" records " << irc[0] <<
", "
573 << irc[1] <<
", ... gives a buffer of " <<npold
574 <<
" photons and fills " <<
npe
578 LogDebug(
"HFShower") <<
"HFShowerLibrary: Extrapolation == " << nrec
579 <<
" records " << irc[0] <<
", " << irc[1]
580 <<
", ... gives a buffer of " << npold
581 <<
" photons and fills " << npe <<
" PE";
591 LogDebug(
"HFShower") <<
"HFShowerLibrary: storePhoton " << j <<
" npe "
602 LogDebug(
"HFShower") <<
"HFShowerLibrary:getDDDArray called for " << str
603 <<
" with nMin " << nmin;
610 const std::vector<double> & fvec = value.
doubles();
611 int nval = fvec.size();
614 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
615 <<
" bins " << nval <<
" < " << nmin
618 <<
"nval < nmin for array " << str <<
"\n";
622 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
623 <<
" bins " << nval <<
" < 2 ==> illegal"
624 <<
" (nmin=" << nmin <<
")";
626 <<
"nval < 2 for array " << str <<
"\n";
633 edm::LogError(
"HFShower") <<
"HFShowerLibrary : cannot get array " << str;
635 <<
"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 addFilter(const DDFilter &, log_op op=AND)
std::vector< Hit > getHits(G4Step *aStep, bool &ok, double weight, bool onlyLong=false)
Sin< T >::type sin(const T &t)
double attLength(double lambda)
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)
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 *)
Abs< T >::type abs(const T &t)
std::vector< double > gpar
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &, int &)
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
std::vector< HFShowerPhoton > photon
std::vector< HFShowerPhoton > pe
std::vector< double > pmom
DDsvalues_type mergedSpecifics() const
void initRun(G4ParticleTable *theParticleTable)
void extrapolate(int, double)
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)
void interpolate(int, double)
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.