14 #include "G4VPhysicalVolume.hh"
15 #include "G4NavigationHistory.hh"
18 #include "Randomize.hh"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
35 std::string pTreeName = fp.
fullPath();
36 backProb = m_HS.getParameter<
double>(
"BackProbability");
37 std::string emName = m_HS.getParameter<std::string>(
"TreeEMID");
38 std::string hadName = m_HS.getParameter<std::string>(
"TreeHadID");
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_");
41 std::string branchPost = m_HS.getUntrackedParameter<std::string>(
"BranchPost",
"_R.obj");
42 verbose = m_HS.getUntrackedParameter<
bool>(
"Verbosity",
false);
44 if (pTreeName.find(
".") == 0) pTreeName.erase(0,2);
45 const char* nTree = pTreeName.c_str();
46 hf = TFile::Open(nTree);
49 edm::LogError(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
52 <<
"Opening of " << pTreeName <<
" fails\n";
54 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
58 TTree*
event = (TTree *)
hf ->Get(
"Events");
60 std::string
info = branchEvInfo + branchPost;
61 TBranch *evtInfo =
event->GetBranch(info.c_str());
65 edm::LogError(
"HFShower") <<
"HFShowerLibrary: HFShowerLibrayEventInfo"
66 <<
" Branch does not exist in Event";
68 <<
"Event information absent\n";
71 edm::LogError(
"HFShower") <<
"HFShowerLibrary: Events Tree does not "
74 <<
"Events tree absent\n";
79 <<
" Events Total " <<
totEvents <<
" and "
81 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Energies (GeV) with "
84 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: pmom[" <<
i <<
"] = "
85 <<
pmom[
i]/GeV <<
" GeV";
87 std::string nameBr = branchPre + emName + branchPost;
88 emBranch =
event->GetBranch(nameBr.c_str());
90 nameBr = branchPre + hadName + branchPost;
91 hadBranch =
event->GetBranch(nameBr.c_str());
93 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary:Branch " << emName
95 <<
" entries and Branch " << hadName
98 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::No packing information -"
99 <<
" Assume x, y, z are not in packed form";
101 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Maximum probability cut off "
102 << probMax <<
" Back propagation of light prob. "
105 G4String attribute =
"ReadOutName";
108 DDValue ddv(attribute,value,0);
118 std::vector<double> rTable =
getDDDArray(
"rTable",sv,nR);
122 <<
" cm and rMax " <<
rMax/cm;
126 std::vector<double> etaTable =
getDDDArray(
"etaTable",sv,nEta);
127 int nPhi = nEta + nR - 2;
128 std::vector<double> phibin =
getDDDArray(
"phibin",sv,nPhi);
129 dphi = phibin[nEta-1];
130 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: (Half) Phi Width of wedge "
136 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: " << ngpar <<
" gpar (cm)";
137 for (
int ig=0; ig<ngpar; ig++)
138 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: gpar[" << ig <<
"] = "
139 <<
gpar[ig]/cm <<
" cm";
141 edm::LogError(
"HFShower") <<
"HFShowerLibrary: cannot get filtered "
142 <<
" view for " << attribute <<
" matching "
145 <<
"cannot match " << attribute <<
" to " << name <<
"\n";
162 emPDG = theParticleTable->FindParticle(parName=
"e-")->GetPDGEncoding();
163 epPDG = theParticleTable->FindParticle(parName=
"e+")->GetPDGEncoding();
164 gammaPDG = theParticleTable->FindParticle(parName=
"gamma")->GetPDGEncoding();
165 pi0PDG = theParticleTable->FindParticle(parName=
"pi0")->GetPDGEncoding();
166 etaPDG = theParticleTable->FindParticle(parName=
"eta")->GetPDGEncoding();
167 nuePDG = theParticleTable->FindParticle(parName=
"nu_e")->GetPDGEncoding();
168 numuPDG = theParticleTable->FindParticle(parName=
"nu_mu")->GetPDGEncoding();
169 nutauPDG= theParticleTable->FindParticle(parName=
"nu_tau")->GetPDGEncoding();
170 anuePDG = theParticleTable->FindParticle(parName=
"anti_nu_e")->GetPDGEncoding();
171 anumuPDG= theParticleTable->FindParticle(parName=
"anti_nu_mu")->GetPDGEncoding();
172 anutauPDG= theParticleTable->FindParticle(parName=
"anti_nu_tau")->GetPDGEncoding();
173 geantinoPDG= theParticleTable->FindParticle(parName=
"geantino")->GetPDGEncoding();
175 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: Particle codes for e- = "
176 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = "
179 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = "
181 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = "
191 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
192 G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
193 G4Track * track = aStep->GetTrack();
195 const G4DynamicParticle *aParticle = track->GetDynamicParticle();
196 G4ThreeVector momDir = aParticle->GetMomentumDirection();
199 G4ThreeVector hitPoint = preStepPoint->GetPosition();
200 G4String partType = track->GetDefinition()->GetParticleName();
201 int parCode = track->GetDefinition()->GetPDGEncoding();
203 std::vector<HFShowerLibrary::Hit>
hit;
211 double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
212 double pin = preStepPoint->GetTotalEnergy();
213 double pz = momDir.
z();
214 double zint = hitPoint.z();
218 if (pz * zint < 0.) backward = 1;
220 double sphi =
sin(momDir.phi());
221 double cphi =
cos(momDir.phi());
222 double ctheta =
cos(momDir.theta());
223 double stheta =
sin(momDir.theta());
226 G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
227 double zoff = localPos.z() + 0.5*
gpar[1];
229 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary: getHits " << partType
230 <<
" of energy " << pin/GeV <<
" GeV"
231 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
232 <<
", " << momDir.z() <<
" Pos x,y,z = "
233 << hitPoint.x() <<
"," << hitPoint.y() <<
","
234 << hitPoint.z() <<
" (" << zoff
235 <<
") sphi,cphi,stheta,ctheta = " << sphi
236 <<
"," << cphi <<
", " << stheta <<
"," << ctheta;
255 for (
int i = 0;
i <
npe;
i++) {
258 LogDebug(
"HFShower") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
260 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
261 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
264 }
else if (backward == 0) {
265 if (
pe[
i].
z() < 0) depth = 2;
267 double r = G4UniformRand();
268 if (r > 0.5) depth = 2;
274 double pex =
pe[
i].x();
275 double pey =
pe[
i].y();
277 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
278 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
279 double zz = -pex*stheta + zv*ctheta;
281 G4ThreeVector
pos = hitPoint + G4ThreeVector(xx,yy,zz);
283 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
287 double r = pos.perp();
289 double fi = pos.phi();
290 if (fi < 0) fi += twopi;
291 int isect = int(fi/
dphi) + 1;
292 isect = (isect + 1) / 2;
293 double dfi = ((isect*2-1)*
dphi - fi);
294 if (dfi < 0) dfi = -dfi;
295 double dfir = r *
sin(dfi);
297 LogDebug(
"HFShower") <<
"HFShowerLibrary: Position shift " << xx
298 <<
", " << yy <<
", " << zz <<
": " << pos
299 <<
" R " << r <<
" Phi " << fi <<
" Section "
300 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
303 double r1 = G4UniformRand();
304 double r2 = G4UniformRand();
306 if(backward) r3 = G4UniformRand();
310 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
311 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi "
313 << zz <<
" zLim " <<
gpar[4] <<
":"
315 <<
" rInside(r) :" <<
rInside(r)
316 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
317 <<
" r2 <= probMax :" << (r2 <=
probMax)
318 <<
" r3 <= backProb :" << (r3 <=
backProb)
319 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
320 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
321 <<
" zz <= gpar[4]+gpar[1] :"
324 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5] &&
326 (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
328 oneHit.
depth = depth;
330 hit.push_back(oneHit);
332 LogDebug(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
333 <<
" position " << (hit[nHit].position) <<
" Depth "
334 << (hit[nHit].depth) <<
" Time " << tSlice <<
":"
336 <<
":" << (hit[nHit].time);
341 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
344 r1 = G4UniformRand();
345 r2 = G4UniformRand();
346 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
350 hit.push_back(oneHit);
352 LogDebug(
"HFShower") <<
"HFShowerLibrary: Final Hit " << nHit
353 <<
" position " << (hit[nHit].position) <<
" Depth "
354 << (hit[nHit].depth) <<
" Time " << tSlice <<
":"
356 <<
":" << (hit[nHit].time);
365 LogDebug(
"HFShower") <<
"HFShowerLibrary: Total Hits " << nHit
366 <<
" out of " << npe <<
" PE";
368 if (nHit > npe && !onlyLong)
370 <<
" smaller than " << nHit <<
" Hits";
377 if (r >=
rMin && r <=
rMax)
return true;
395 LogDebug(
"HFShower") <<
"HFShowerLibrary::getRecord: Record " << record
396 <<
" of type " << type <<
" with " << nPhoton
398 for (
int j = 0;
j < nPhoton;
j++)
405 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
406 branch->SetAddress(&eventInfoCollection);
408 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary::loadEventInfo loads "
409 <<
" EventInfo Collection of size "
410 << eventInfoCollection.size() <<
" records";
411 totEvents = eventInfoCollection[0].totalEvents();
412 nMomBin = eventInfoCollection[0].numberOfBins();
413 evtPerBin = eventInfoCollection[0].eventsPerBin();
414 libVers = eventInfoCollection[0].showerLibraryVersion();
415 listVersion = eventInfoCollection[0].physListVersion();
416 pmom = eventInfoCollection[0].energyBins();
417 for (
unsigned int i=0;
i<
pmom.size();
i++)
424 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/GeV
425 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
430 double r = G4UniformRand();
440 if (j == nMomBin-2) {
450 << irc[0] <<
" now set to 0";
452 }
else if (irc[0] > totEvents) {
462 << irc[1] <<
" now set to 1";
464 }
else if (irc[1] > totEvents) {
471 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Select records " << irc[0]
472 <<
" and " << irc[1] <<
" with weights " << 1-w
478 for (
int ir=0; ir < 2; ir++) {
481 int nPhoton =
photon.size();
483 for (
int j=0;
j<nPhoton;
j++) {
485 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
492 if (
npe > npold || (npold == 0 && irc[0] > 0))
493 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Interpolation Warning =="
494 <<
" records " << irc[0] <<
" and " << irc[1]
495 <<
" gives a buffer of " << npold
496 <<
" photons and fills " <<
npe <<
" *****";
499 LogDebug(
"HFShower") <<
"HFShowerLibrary: Interpolation == records "
500 << irc[0] <<
" and " << irc[1] <<
" gives a "
501 <<
"buffer of " << npold <<
" photons and fills "
514 LogDebug(
"HFShower") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
515 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
517 <<
" using " << nrec <<
" records";
519 std::vector<int> irc(nrec);
521 for (
int ir=0; ir<nrec; ir++) {
522 double r = G4UniformRand();
526 <<
"] = " << irc[ir] <<
" now set to 1";
530 <<
"] = " << irc[ir] <<
" now set to "
535 LogDebug(
"HFShower") <<
"HFShowerLibrary::Extrapolation use irc["
536 << ir <<
"] = " << irc[ir];
544 for (
int ir=0; ir<nrec; ir++) {
547 int nPhoton =
photon.size();
549 for (
int j=0;
j<nPhoton;
j++) {
550 double r = G4UniformRand();
551 if (ir != nrec-1 || r < w) {
556 LogDebug(
"HFShower") <<
"HFShowerLibrary: Record [" << ir <<
"] = "
557 << irc[ir] <<
" npold = " << npold;
562 edm::LogInfo(
"HFShower") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
565 if (
npe > npold || npold == 0)
566 edm::LogWarning(
"HFShower") <<
"HFShowerLibrary: Extrapolation Warning == "
567 << nrec <<
" records " << irc[0] <<
", "
568 << irc[1] <<
", ... gives a buffer of " <<npold
569 <<
" photons and fills " <<
npe
573 LogDebug(
"HFShower") <<
"HFShowerLibrary: Extrapolation == " << nrec
574 <<
" records " << irc[0] <<
", " << irc[1]
575 <<
", ... gives a buffer of " << npold
576 <<
" photons and fills " << npe <<
" PE";
586 LogDebug(
"HFShower") <<
"HFShowerLibrary: storePhoton " << j <<
" npe "
597 LogDebug(
"HFShower") <<
"HFShowerLibrary:getDDDArray called for " << str
598 <<
" with nMin " << nmin;
605 const std::vector<double> & fvec = value.
doubles();
606 int nval = fvec.size();
609 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
610 <<
" bins " << nval <<
" < " << nmin
613 <<
"nval < nmin for array " << str <<
"\n";
617 edm::LogError(
"HFShower") <<
"HFShowerLibrary : # of " << str
618 <<
" bins " << nval <<
" < 2 ==> illegal"
619 <<
" (nmin=" << nmin <<
")";
621 <<
"nval < 2 for array " << str <<
"\n";
628 edm::LogError(
"HFShower") <<
"HFShowerLibrary : cannot get array " << str;
630 <<
"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
std::vector< Hit > getHits(G4Step *aStep, bool &ok, bool onlyLong=false)
void addFilter(const DDFilter &, log_op op=AND)
Sin< T >::type sin(const T &t)
double attLength(double lambda)
Exp< T >::type exp(const T &t)
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
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
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)
std::string fullPath() const
void interpolate(int, double)
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.