14 #include "G4VPhysicalVolume.hh"
15 #include "G4NavigationHistory.hh"
18 #include "Randomize.hh"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
36 backProb = m_HS.getParameter<
double>(
"BackProbability");
39 std::string branchEvInfo = m_HS.getUntrackedParameter<
std::string>(
"BranchEvt",
"HFShowerLibraryEventInfos_hfshowerlib_HFShowerLibraryEventInfo");
40 std::string branchPre = m_HS.getUntrackedParameter<
std::string>(
"BranchPre",
"HFShowerPhotons_hfshowerlib_");
42 verbose = m_HS.getUntrackedParameter<
bool>(
"Verbosity",
false);
43 applyFidCut = m_HS.getParameter<
bool>(
"ApplyFiducialCut");
45 if (pTreeName.find(
".") == 0) pTreeName.erase(0,2);
46 const char* nTree = pTreeName.c_str();
47 hf = TFile::Open(nTree);
50 edm::LogError(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
53 <<
"Opening of " << pTreeName <<
" fails\n";
55 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
59 TTree*
event = (TTree *)
hf ->Get(
"Events");
62 TBranch *evtInfo =
event->GetBranch(info.c_str());
66 edm::LogError(
"HFShower") <<
"HFShowerLibrary: HFShowerLibrayEventInfo"
67 <<
" Branch does not exist in Event";
69 <<
"Event information absent\n";
72 edm::LogError(
"HFShower") <<
"HFShowerLibrary: Events Tree does not "
75 <<
"Events tree absent\n";
80 <<
" Events Total " <<
totEvents <<
" and "
82 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Energies (GeV) with "
85 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: pmom[" <<
i <<
"] = "
86 <<
pmom[
i]/GeV <<
" GeV";
88 std::string nameBr = branchPre + emName + branchPost;
89 emBranch =
event->GetBranch(nameBr.c_str());
91 nameBr = branchPre + hadName + branchPost;
92 hadBranch =
event->GetBranch(nameBr.c_str());
94 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary:Branch " << emName
96 <<
" entries and Branch " << hadName
99 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::No packing information -"
100 <<
" Assume x, y, z are not in packed form";
102 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Maximum probability cut off "
103 << probMax <<
" Back propagation of light prob. "
106 G4String attribute =
"ReadOutName";
109 DDValue ddv(attribute,value,0);
119 std::vector<double> rTable =
getDDDArray(
"rTable",sv,nR);
123 <<
" cm and rMax " <<
rMax/cm;
127 std::vector<double> etaTable =
getDDDArray(
"etaTable",sv,nEta);
128 int nPhi = nEta + nR - 2;
129 std::vector<double> phibin =
getDDDArray(
"phibin",sv,nPhi);
130 dphi = phibin[nEta-1];
131 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: (Half) Phi Width of wedge "
137 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: " << ngpar <<
" gpar (cm)";
138 for (
int ig=0; ig<ngpar; ig++)
139 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: gpar[" << ig <<
"] = "
140 <<
gpar[ig]/cm <<
" cm";
142 edm::LogError(
"HFShower") <<
"HFShowerLibrary: cannot get filtered "
143 <<
" view for " << attribute <<
" matching "
146 <<
"cannot match " << attribute <<
" to " << name <<
"\n";
163 emPDG = theParticleTable->FindParticle(parName=
"e-")->GetPDGEncoding();
164 epPDG = theParticleTable->FindParticle(parName=
"e+")->GetPDGEncoding();
165 gammaPDG = theParticleTable->FindParticle(parName=
"gamma")->GetPDGEncoding();
166 pi0PDG = theParticleTable->FindParticle(parName=
"pi0")->GetPDGEncoding();
167 etaPDG = theParticleTable->FindParticle(parName=
"eta")->GetPDGEncoding();
168 nuePDG = theParticleTable->FindParticle(parName=
"nu_e")->GetPDGEncoding();
169 numuPDG = theParticleTable->FindParticle(parName=
"nu_mu")->GetPDGEncoding();
170 nutauPDG= theParticleTable->FindParticle(parName=
"nu_tau")->GetPDGEncoding();
171 anuePDG = theParticleTable->FindParticle(parName=
"anti_nu_e")->GetPDGEncoding();
172 anumuPDG= theParticleTable->FindParticle(parName=
"anti_nu_mu")->GetPDGEncoding();
173 anutauPDG= theParticleTable->FindParticle(parName=
"anti_nu_tau")->GetPDGEncoding();
174 geantinoPDG= theParticleTable->FindParticle(parName=
"geantino")->GetPDGEncoding();
176 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Particle codes for e- = "
177 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = "
180 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = "
182 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = "
193 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
194 G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
195 G4Track * track = aStep->GetTrack();
197 const G4DynamicParticle *aParticle = track->GetDynamicParticle();
198 G4ThreeVector momDir = aParticle->GetMomentumDirection();
201 G4ThreeVector hitPoint = preStepPoint->GetPosition();
202 G4String partType = track->GetDefinition()->GetParticleName();
203 int parCode = track->GetDefinition()->GetPDGEncoding();
205 std::vector<HFShowerLibrary::Hit>
hit;
213 double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
214 double pin = preStepPoint->GetTotalEnergy();
215 double pz = momDir.
z();
216 double zint = hitPoint.z();
220 if (pz * zint < 0.) backward = 1;
222 double sphi =
sin(momDir.phi());
223 double cphi =
cos(momDir.phi());
224 double ctheta =
cos(momDir.theta());
225 double stheta =
sin(momDir.theta());
228 G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
229 double zoff = localPos.z() + 0.5*
gpar[1];
231 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: getHits " << partType
232 <<
" of energy " << pin/GeV <<
" GeV"
233 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
234 <<
", " << momDir.z() <<
" Pos x,y,z = "
235 << hitPoint.x() <<
"," << hitPoint.y() <<
","
236 << hitPoint.z() <<
" (" << zoff
237 <<
") sphi,cphi,stheta,ctheta = " << sphi
238 <<
"," << cphi <<
", " << stheta <<
"," << ctheta;
257 for (
int i = 0;
i <
npe;
i++) {
260 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
262 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
263 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
266 }
else if (backward == 0) {
267 if (
pe[
i].
z() < 0) depth = 2;
269 double r = G4UniformRand();
270 if (r > 0.5) depth = 2;
276 double pex =
pe[
i].x();
277 double pey =
pe[
i].y();
279 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
280 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
281 double zz = -pex*stheta + zv*ctheta;
283 G4ThreeVector
pos = hitPoint + G4ThreeVector(xx,yy,zz);
285 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
289 double r = pos.perp();
291 double fi = pos.phi();
292 if (fi < 0) fi += twopi;
293 int isect = int(fi/
dphi) + 1;
294 isect = (isect + 1) / 2;
295 double dfi = ((isect*2-1)*
dphi - fi);
296 if (dfi < 0) dfi = -dfi;
297 double dfir = r *
sin(dfi);
299 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Position shift " << xx
300 <<
", " << yy <<
", " << zz <<
": " << pos
301 <<
" R " << r <<
" Phi " << fi <<
" Section "
302 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
305 double r1 = G4UniformRand();
306 double r2 = G4UniformRand();
308 if (backward) r3 = G4UniformRand();
313 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
314 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi "
316 << zz <<
" zLim " <<
gpar[4] <<
":"
318 <<
" rInside(r) :" <<
rInside(r)
319 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
320 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
321 <<
" r3 <= backProb :" << (r3 <=
backProb)
322 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
323 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
324 <<
" zz <= gpar[4]+gpar[1] :"
329 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
331 oneHit.
depth = depth;
333 hit.push_back(oneHit);
335 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
336 <<
" position " << (hit[nHit].position)
337 <<
" Depth " << (hit[nHit].depth) <<
" Time "
338 << tSlice <<
":" <<
pe[
i].t() <<
":"
345 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
348 r1 = G4UniformRand();
349 r2 = G4UniformRand();
350 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
354 hit.push_back(oneHit);
356 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
357 <<
" position " << (hit[nHit].position)
358 <<
" Depth " << (hit[nHit].depth) <<
" Time "
359 << tSlice <<
":" <<
pe[
i].t() <<
":"
370 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Total Hits " << nHit
371 <<
" out of " << npe <<
" PE";
373 if (nHit > npe && !onlyLong)
375 <<
" smaller than " << nHit <<
" Hits";
382 if (r >=
rMin && r <=
rMax)
return true;
398 int nPhoton =
photon.size();
399 LogDebug(
"HFShower") <<
"HFShowerLibrary::getRecord: Record " << record
400 <<
" of type " << type <<
" with " << nPhoton
402 for (
int j = 0;
j < nPhoton;
j++)
409 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
410 branch->SetAddress(&eventInfoCollection);
412 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
413 <<
" EventInfo Collection of size "
414 << eventInfoCollection.size() <<
" records";
415 totEvents = eventInfoCollection[0].totalEvents();
416 nMomBin = eventInfoCollection[0].numberOfBins();
417 evtPerBin = eventInfoCollection[0].eventsPerBin();
418 libVers = eventInfoCollection[0].showerLibraryVersion();
419 listVersion = eventInfoCollection[0].physListVersion();
420 pmom = eventInfoCollection[0].energyBins();
421 for (
unsigned int i=0;
i<
pmom.size();
i++)
428 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/GeV
429 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
434 double r = G4UniformRand();
444 if (j == nMomBin-2) {
454 << irc[0] <<
" now set to 0";
456 }
else if (irc[0] > totEvents) {
466 << irc[1] <<
" now set to 1";
468 }
else if (irc[1] > totEvents) {
475 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Select records " << irc[0]
476 <<
" and " << irc[1] <<
" with weights " << 1-w
482 for (
int ir=0; ir < 2; ir++) {
485 int nPhoton =
photon.size();
487 for (
int j=0;
j<nPhoton;
j++) {
489 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
496 if (
npe > npold || (npold == 0 && irc[0] > 0))
497 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Interpolation Warning =="
498 <<
" records " << irc[0] <<
" and " << irc[1]
499 <<
" gives a buffer of " << npold
500 <<
" photons and fills " <<
npe <<
" *****";
503 LogDebug(
"HFShower") <<
"HFShowerLibrary: Interpolation == records "
504 << irc[0] <<
" and " << irc[1] <<
" gives a "
505 <<
"buffer of " << npold <<
" photons and fills "
518 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
519 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
521 <<
" using " << nrec <<
" records";
523 std::vector<int> irc(nrec);
525 for (
int ir=0; ir<nrec; ir++) {
526 double r = G4UniformRand();
530 <<
"] = " << irc[ir] <<
" now set to 1";
534 <<
"] = " << irc[ir] <<
" now set to "
539 LogDebug(
"HFShower") <<
"HFShowerLibrary::Extrapolation use irc["
540 << ir <<
"] = " << irc[ir];
548 for (
int ir=0; ir<nrec; ir++) {
551 int nPhoton =
photon.size();
553 for (
int j=0;
j<nPhoton;
j++) {
554 double r = G4UniformRand();
555 if (ir != nrec-1 || r < w) {
560 LogDebug(
"HFShower") <<
"HFShowerLibrary: Record [" << ir <<
"] = "
561 << irc[ir] <<
" npold = " << npold;
566 LogDebug(
"HFShower") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
569 if (
npe > npold || npold == 0)
570 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Extrapolation Warning == "
571 << nrec <<
" records " << irc[0] <<
", "
572 << irc[1] <<
", ... gives a buffer of " <<npold
573 <<
" photons and fills " <<
npe
577 LogDebug(
"HFShower") <<
"HFShowerLibrary: Extrapolation == " << nrec
578 <<
" records " << irc[0] <<
", " << irc[1]
579 <<
", ... gives a buffer of " << npold
580 <<
" photons and fills " << npe <<
" PE";
590 LogDebug(
"HFShower") <<
"HFShowerLibrary: storePhoton " << j <<
" npe "
601 LogDebug(
"HFShower") <<
"HFShowerLibrary:getDDDArray called for " << str
602 <<
" with nMin " << nmin;
609 const std::vector<double> & fvec = value.
doubles();
610 int nval = fvec.size();
613 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
614 <<
" bins " << nval <<
" < " << nmin
617 <<
"nval < nmin for array " << str <<
"\n";
621 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
622 <<
" bins " << nval <<
" < 2 ==> illegal"
623 <<
" (nmin=" << nmin <<
")";
625 <<
"nval < 2 for array " << str <<
"\n";
632 edm::LogError(
"HFShower") <<
"HFShowerLibrary : cannot get array " << str;
634 <<
"cannot get array " << str <<
"\n";
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)
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)
double zShift(G4ThreeVector point, int depth, int fromEndAbs=0)
Cos< T >::type cos(const T &t)
double tShift(G4ThreeVector point, int depth, int fromEndAbs=0)
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 *)
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.