15 #include "G4VPhysicalVolume.hh" 16 #include "G4NavigationHistory.hh" 19 #include "G4ParticleTable.hh" 20 #include "Randomize.hh" 21 #include "CLHEP/Units/SystemOfUnits.h" 22 #include "CLHEP/Units/PhysicalConstants.h" 39 backProb = m_HS.getParameter<
double>(
"BackProbability");
42 std::string branchEvInfo = m_HS.getUntrackedParameter<
std::string>(
"BranchEvt",
"HFShowerLibraryEventInfos_hfshowerlib_HFShowerLibraryEventInfo");
43 std::string branchPre = m_HS.getUntrackedParameter<
std::string>(
"BranchPre",
"HFShowerPhotons_hfshowerlib_");
45 verbose = m_HS.getUntrackedParameter<
bool>(
"Verbosity",
false);
46 applyFidCut = m_HS.getParameter<
bool>(
"ApplyFiducialCut");
48 if (pTreeName.find(
".") == 0) pTreeName.erase(0,2);
49 const char* nTree = pTreeName.c_str();
50 hf = TFile::Open(nTree);
53 edm::LogError(
"HFShower") <<
"HFShowerLibrary: opening " << nTree
56 <<
"Opening of " << pTreeName <<
" fails\n";
62 newForm = (branchEvInfo.empty());
63 TTree*
event(
nullptr);
64 if (
newForm)
event = (TTree *)
hf ->Get(
"HFSimHits");
65 else event = (TTree *)
hf ->Get(
"Events");
67 TBranch *evtInfo(
nullptr);
70 evtInfo =
event->GetBranch(info.c_str());
75 edm::LogError(
"HFShower") <<
"HFShowerLibrary: HFShowerLibrayEventInfo" 76 <<
" Branch does not exist in Event";
78 <<
"Event information absent\n";
81 edm::LogError(
"HFShower") <<
"HFShowerLibrary: Events Tree does not " 84 <<
"Events tree absent\n";
90 ss <<
"HFShowerLibrary: Energies (GeV) with " <<
nMomBin <<
" bins\n";
92 if(
i/10*10 ==
i &&
i > 0) { ss <<
"\n"; }
97 std::string nameBr = branchPre + emName + branchPost;
98 emBranch =
event->GetBranch(nameBr.c_str());
100 nameBr = branchPre + hadName + branchPost;
101 hadBranch =
event->GetBranch(nameBr.c_str());
110 <<
" has " <<
emBranch->GetEntries()
111 <<
" entries and Branch " << hadName
114 <<
"\n HFShowerLibrary::No packing information -" 115 <<
" Assume x, y, z are not in packed form" 116 <<
"\n Maximum probability cut off " 117 << probMax <<
" Back propagation of light prob. " 137 rMax = rTable[rTable.size()-1];
143 <<
" cm and rMax " <<
rMax/cm
144 <<
" (Half) Phi Width of wedge " 156 auto const preStepPoint = aStep->GetPreStepPoint();
157 auto const postStepPoint = aStep->GetPostStepPoint();
158 auto const track = aStep->GetTrack();
160 auto const aParticle =
track->GetDynamicParticle();
161 const G4ThreeVector& momDir = aParticle->GetMomentumDirection();
162 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
163 int parCode =
track->GetDefinition()->GetPDGEncoding();
167 if(
track->GetDefinition()->IsGeneralIon()) { parCode = 1000020040; }
170 G4String partType =
track->GetDefinition()->GetParticleName();
171 const G4ThreeVector localPos =
172 preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
173 double zoff = localPos.z() + 0.5*
gpar[1];
176 <<
" of energy " << pin/
GeV <<
" GeV" 177 <<
" weight= " << weight <<
" onlyLong: " << onlyLong
178 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
179 <<
", " << momDir.z() <<
" Pos x,y,z = " 180 << hitPoint.x() <<
"," << hitPoint.y() <<
"," 181 << hitPoint.z() <<
" (" << zoff
182 <<
") sphi,cphi,stheta,ctheta = " <<
sin(momDir.phi())
183 <<
"," <<
cos(momDir.phi()) <<
", " <<
sin(momDir.theta())
184 <<
"," <<
cos(momDir.theta());
187 double tSlice = (postStepPoint->GetGlobalTime())/CLHEP::nanosecond;
190 double pin = (
track->GetDefinition()->GetBaryonNumber() > 0)
191 ? preStepPoint->GetKineticEnergy() : preStepPoint->GetTotalEnergy();
193 return fillHits(hitPoint,momDir,parCode,pin,isKilled,weight,tSlice,onlyLong);
197 const G4ThreeVector & momDir,
198 int parCode,
double pin,
bool &
ok,
199 double weight,
double tSlice,
bool onlyLong) {
201 std::vector<HFShowerLibrary::Hit>
hit;
212 if(pin < threshold) {
return hit; }
214 double pz = momDir.z();
215 double zint = hitPoint.z();
218 bool backward = (pz * zint < 0.) ?
true :
false;
220 double sphi =
sin(momDir.phi());
221 double cphi =
cos(momDir.phi());
222 double ctheta =
cos(momDir.theta());
223 double stheta =
sin(momDir.theta());
241 for (
int i = 0;
i <
npe; ++
i) {
246 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
247 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
250 }
else if (!backward) {
251 if (
pe[
i].
z() < 0) depth = 2;
253 double r = G4UniformRand();
254 if (r > 0.5) depth = 2;
260 double pex =
pe[
i].x();
261 double pey =
pe[
i].y();
263 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
264 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
265 double zz = -pex*stheta + zv*ctheta;
267 G4ThreeVector
pos = hitPoint + G4ThreeVector(xx,yy,zz);
269 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
273 double r = pos.perp();
275 double fi = pos.phi();
276 if (fi < 0) fi += CLHEP::twopi;
278 isect = (isect + 1) / 2;
279 double dfi = ((isect*2-1)*
dphi - fi);
280 if (dfi < 0) dfi = -dfi;
281 double dfir = r *
sin(dfi);
284 <<
", " << yy <<
", " << zz <<
": " << pos
285 <<
" R " << r <<
" Phi " << fi <<
" Section " 286 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
289 double r1 = G4UniformRand();
290 double r2 = G4UniformRand();
291 double r3 = backward ? G4UniformRand() : -9999.;
296 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
297 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi " 299 << zz <<
" zLim " <<
gpar[4] <<
":" 301 <<
" rInside(r) :" <<
rInside(r)
302 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
303 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
304 <<
" r3 <= backProb :" << (r3 <=
backProb)
305 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
306 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
307 <<
" zz <= gpar[4]+gpar[1] :" 312 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
316 hit.push_back(oneHit);
319 <<
" position " << (hit[nHit].position)
320 <<
" Depth " << (hit[nHit].depth) <<
" Time " 321 << tSlice <<
":" <<
pe[
i].t() <<
":" 328 else LogDebug(
"HFShower") <<
"HFShowerLibrary: REJECTED !!!";
331 r1 = G4UniformRand();
332 r2 = G4UniformRand();
333 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
337 hit.push_back(oneHit);
340 <<
" position " << (hit[nHit].position)
341 <<
" Depth " << (hit[nHit].depth) <<
" Time " 342 << tSlice <<
":" <<
pe[
i].t() <<
":" 354 <<
" out of " << npe <<
" PE";
356 if (nHit > npe && !onlyLong) {
358 <<
" smaller than " << nHit <<
" Hits";
380 std::vector<float>
t;
381 std::vector<float> *tp=&
t;
384 unsigned int tSize=t.size()/5;
385 photo->reserve(tSize);
386 for (
unsigned int i=0;
i<tSize;
i++ ) {
387 photo->push_back(
HFShowerPhoton( t[
i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
401 std::vector<float>
t;
402 std::vector<float> *tp=&
t;
405 unsigned int tSize=t.size()/5;
406 photo->reserve(tSize);
407 for (
unsigned int i=0;
i<tSize;
i++ ) {
408 photo->push_back(
HFShowerPhoton( t[
i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
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);
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();
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();
472 for (
int j=0; j<
nMomBin-1; j++) {
473 if (pin >=
pmom[j] && pin <
pmom[j+1]) {
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 " 538 for (
int j=0; j<
npe; j++)
539 LogDebug(
"HFShower") <<
"Photon " << j <<
" " <<
pe[j];
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";
612 for (
int j=0; j<
npe; j++)
613 LogDebug(
"HFShower") <<
"Photon " << j <<
" " <<
pe[j];
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";
666 <<
"cannot get array " << str <<
"\n";
double tShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
T getParameter(std::string const &) const
std::vector< Hit > getHits(const G4Step *aStep, bool &ok, double weight, bool onlyLong=false)
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
void initRun(const HcalDDDSimConstants *)
Sin< T >::type sin(const T &t)
double attLength(double lambda)
HFShowerPhotonCollection pe
double zShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
Compact representation of the geometrical detector hierarchy.
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
static bool isStableHadron(int pdgCode)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
const std::vector< double > & getRTableHF() const
Cos< T >::type cos(const T &t)
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)
static bool isGammaElectronPositron(int pdgCode)
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
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 interpolate(int, double)
void initRun(G4ParticleTable *, const HcalDDDSimConstants *)