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 <<
"] = "
93 <<
pmom[
i]/GeV <<
" GeV";
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. "
113 G4String attribute =
"ReadOutName";
116 DDValue ddv(attribute,value,0);
126 std::vector<double> rTable =
getDDDArray(
"rTable",sv,nR);
130 <<
" cm and rMax " <<
rMax/cm;
134 std::vector<double> etaTable =
getDDDArray(
"etaTable",sv,nEta);
135 int nPhi = nEta + nR - 2;
136 std::vector<double> phibin =
getDDDArray(
"phibin",sv,nPhi);
137 dphi = phibin[nEta-1];
138 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: (Half) Phi Width of wedge "
144 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: " << ngpar <<
" gpar (cm)";
145 for (
int ig=0; ig<ngpar; ig++)
146 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: gpar[" << ig <<
"] = "
147 <<
gpar[ig]/cm <<
" cm";
149 edm::LogError(
"HFShower") <<
"HFShowerLibrary: cannot get filtered "
150 <<
" view for " << attribute <<
" matching "
153 <<
"cannot match " << attribute <<
" to " << name <<
"\n";
172 emPDG = theParticleTable->FindParticle(parName=
"e-")->GetPDGEncoding();
173 epPDG = theParticleTable->FindParticle(parName=
"e+")->GetPDGEncoding();
174 gammaPDG = theParticleTable->FindParticle(parName=
"gamma")->GetPDGEncoding();
175 pi0PDG = theParticleTable->FindParticle(parName=
"pi0")->GetPDGEncoding();
176 etaPDG = theParticleTable->FindParticle(parName=
"eta")->GetPDGEncoding();
177 nuePDG = theParticleTable->FindParticle(parName=
"nu_e")->GetPDGEncoding();
178 numuPDG = theParticleTable->FindParticle(parName=
"nu_mu")->GetPDGEncoding();
179 nutauPDG= theParticleTable->FindParticle(parName=
"nu_tau")->GetPDGEncoding();
180 anuePDG = theParticleTable->FindParticle(parName=
"anti_nu_e")->GetPDGEncoding();
181 anumuPDG= theParticleTable->FindParticle(parName=
"anti_nu_mu")->GetPDGEncoding();
182 anutauPDG= theParticleTable->FindParticle(parName=
"anti_nu_tau")->GetPDGEncoding();
183 geantinoPDG= theParticleTable->FindParticle(parName=
"geantino")->GetPDGEncoding();
185 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Particle codes for e- = "
186 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = "
189 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = "
191 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = "
202 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
203 G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
204 G4Track * track = aStep->GetTrack();
206 const G4DynamicParticle *aParticle = track->GetDynamicParticle();
207 G4ThreeVector momDir = aParticle->GetMomentumDirection();
210 G4ThreeVector hitPoint = preStepPoint->GetPosition();
211 G4String partType = track->GetDefinition()->GetParticleName();
212 int parCode = track->GetDefinition()->GetPDGEncoding();
214 std::vector<HFShowerLibrary::Hit>
hit;
222 double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
223 double pin = preStepPoint->GetTotalEnergy();
224 double pz = momDir.
z();
225 double zint = hitPoint.z();
229 if (pz * zint < 0.) backward = 1;
231 double sphi =
sin(momDir.phi());
232 double cphi =
cos(momDir.phi());
233 double ctheta =
cos(momDir.theta());
234 double stheta =
sin(momDir.theta());
237 G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
238 double zoff = localPos.z() + 0.5*
gpar[1];
240 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: getHits " << partType
241 <<
" of energy " << pin/GeV <<
" GeV"
242 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
243 <<
", " << momDir.z() <<
" Pos x,y,z = "
244 << hitPoint.x() <<
"," << hitPoint.y() <<
","
245 << hitPoint.z() <<
" (" << zoff
246 <<
") sphi,cphi,stheta,ctheta = " << sphi
247 <<
"," << cphi <<
", " << stheta <<
"," << ctheta;
266 for (
int i = 0;
i <
npe;
i++) {
269 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
271 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
272 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
275 }
else if (backward == 0) {
276 if (
pe[
i].
z() < 0) depth = 2;
278 double r = G4UniformRand();
279 if (r > 0.5) depth = 2;
285 double pex =
pe[
i].x();
286 double pey =
pe[
i].y();
288 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
289 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
290 double zz = -pex*stheta + zv*ctheta;
292 G4ThreeVector pos = hitPoint + G4ThreeVector(xx,yy,zz);
294 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
298 double r = pos.perp();
300 double fi = pos.phi();
301 if (fi < 0) fi += twopi;
302 int isect = int(fi/
dphi) + 1;
303 isect = (isect + 1) / 2;
304 double dfi = ((isect*2-1)*
dphi - fi);
305 if (dfi < 0) dfi = -dfi;
306 double dfir = r *
sin(dfi);
308 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Position shift " << xx
309 <<
", " << yy <<
", " << zz <<
": " << pos
310 <<
" R " << r <<
" Phi " << fi <<
" Section "
311 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
314 double r1 = G4UniformRand();
315 double r2 = G4UniformRand();
317 if (backward) r3 = G4UniformRand();
322 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
323 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi "
325 << zz <<
" zLim " <<
gpar[4] <<
":"
327 <<
" rInside(r) :" <<
rInside(r)
328 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
329 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
330 <<
" r3 <= backProb :" << (r3 <=
backProb)
331 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
332 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
333 <<
" zz <= gpar[4]+gpar[1] :"
338 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
340 oneHit.
depth = depth;
342 hit.push_back(oneHit);
344 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
345 <<
" position " << (hit[nHit].position)
346 <<
" Depth " << (hit[nHit].depth) <<
" Time "
347 << tSlice <<
":" <<
pe[
i].t() <<
":"
354 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
357 r1 = G4UniformRand();
358 r2 = G4UniformRand();
359 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
363 hit.push_back(oneHit);
365 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
366 <<
" position " << (hit[nHit].position)
367 <<
" Depth " << (hit[nHit].depth) <<
" Time "
368 << tSlice <<
":" <<
pe[
i].t() <<
":"
379 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Total Hits " << nHit
380 <<
" out of " << npe <<
" PE";
382 if (nHit > npe && !onlyLong)
384 <<
" smaller than " << nHit <<
" Hits";
391 if (r >=
rMin && r <=
rMax)
return true;
418 LogDebug(
"HFShower") <<
"HFShowerLibrary::getRecord: Record " << record
419 <<
" of type " << type <<
" with " << nPhoton
421 for (
int j = 0;
j < nPhoton;
j++)
430 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
431 branch->SetAddress(&eventInfoCollection);
433 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
434 <<
" EventInfo Collection of size "
435 << eventInfoCollection.size() <<
" records";
436 totEvents = eventInfoCollection[0].totalEvents();
437 nMomBin = eventInfoCollection[0].numberOfBins();
438 evtPerBin = eventInfoCollection[0].eventsPerBin();
439 libVers = eventInfoCollection[0].showerLibraryVersion();
440 listVersion = eventInfoCollection[0].physListVersion();
441 pmom = eventInfoCollection[0].energyBins();
443 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
444 <<
" EventInfo from hardwired numbers";
450 pmom = {2,3,5,7,10,15,20,30,50,75,100,150,250,350,500,1000};
459 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/GeV
460 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
465 double r = G4UniformRand();
475 if (j == nMomBin-2) {
485 << irc[0] <<
" now set to 0";
487 }
else if (irc[0] > totEvents) {
497 << irc[1] <<
" now set to 1";
499 }
else if (irc[1] > totEvents) {
506 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Select records " << irc[0]
507 <<
" and " << irc[1] <<
" with weights " << 1-w
513 for (
int ir=0; ir < 2; ir++) {
518 for (
int j=0;
j<nPhoton;
j++) {
520 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
527 if ((
npe > npold || (npold == 0 && irc[0] > 0)) && !(
npe == 0 && npold == 0))
528 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Interpolation Warning =="
529 <<
" records " << irc[0] <<
" and " << irc[1]
530 <<
" gives a buffer of " << npold
531 <<
" photons and fills " <<
npe <<
" *****";
534 LogDebug(
"HFShower") <<
"HFShowerLibrary: Interpolation == records "
535 << irc[0] <<
" and " << irc[1] <<
" gives a "
536 <<
"buffer of " << npold <<
" photons and fills "
549 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
550 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
552 <<
" using " << nrec <<
" records";
554 std::vector<int> irc(nrec);
556 for (
int ir=0; ir<nrec; ir++) {
557 double r = G4UniformRand();
561 <<
"] = " << irc[ir] <<
" now set to 1";
565 <<
"] = " << irc[ir] <<
" now set to "
570 LogDebug(
"HFShower") <<
"HFShowerLibrary::Extrapolation use irc["
571 << ir <<
"] = " << irc[ir];
579 for (
int ir=0; ir<nrec; ir++) {
584 for (
int j=0;
j<nPhoton;
j++) {
585 double r = G4UniformRand();
586 if (ir != nrec-1 || r < w) {
591 LogDebug(
"HFShower") <<
"HFShowerLibrary: Record [" << ir <<
"] = "
592 << irc[ir] <<
" npold = " << npold;
597 LogDebug(
"HFShower") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
600 if (
npe > npold || npold == 0)
601 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Extrapolation Warning == "
602 << nrec <<
" records " << irc[0] <<
", "
603 << irc[1] <<
", ... gives a buffer of " <<npold
604 <<
" photons and fills " <<
npe
608 LogDebug(
"HFShower") <<
"HFShowerLibrary: Extrapolation == " << nrec
609 <<
" records " << irc[0] <<
", " << irc[1]
610 <<
", ... gives a buffer of " << npold
611 <<
" photons and fills " << npe <<
" PE";
622 LogDebug(
"HFShower") <<
"HFShowerLibrary: storePhoton " << j <<
" npe "
633 LogDebug(
"HFShower") <<
"HFShowerLibrary:getDDDArray called for " << str
634 <<
" with nMin " << nmin;
641 const std::vector<double> & fvec = value.
doubles();
642 int nval = fvec.size();
645 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
646 <<
" bins " << nval <<
" < " << nmin
649 <<
"nval < nmin for array " << str <<
"\n";
653 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
654 <<
" bins " << nval <<
" < 2 ==> illegal"
655 <<
" (nmin=" << nmin <<
")";
657 <<
"nval < 2 for array " << str <<
"\n";
664 edm::LogError(
"HFShower") <<
"HFShowerLibrary : cannot get array " << str;
666 <<
"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)
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
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 &)
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
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)
HFShowerPhotonCollection photon
void interpolate(int, double)
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.