18 #include "Randomize.hh"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 #include "CLHEP/Units/GlobalPhysicalConstants.h"
52 if (pTreeName.find(
".") == 0) pTreeName.erase(0,2);
53 const char* nTree = pTreeName.c_str();
54 hf = TFile::Open(nTree);
57 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary: opening " << nTree
60 <<
"Opening of " << pTreeName <<
" fails\n";
62 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: opening " << nTree
68 if (
newForm)
event = (TTree *)
hf ->Get(
"HFSimHits");
69 else event = (TTree *)
hf ->Get(
"Events");
74 evtInfo =
event->GetBranch(info.c_str());
79 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary: HFShowerLibrayEventInfo"
80 <<
" Branch does not exist in Event";
82 <<
"Event information absent\n";
85 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary: Events Tree does not "
88 <<
"Events tree absent\n";
93 <<
" Events Total " <<
totEvents <<
" and "
96 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Energies (GeV) with "
100 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: pmom[" <<
i <<
"] = "
103 std::string nameBr = branchPre + emName + branchPost;
104 emBranch =
event->GetBranch(nameBr.c_str());
106 nameBr = branchPre + hadName + branchPost;
107 hadBranch =
event->GetBranch(nameBr.c_str());
109 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary:Branch " << emName
110 <<
" has " <<
emBranch->GetEntries()
111 <<
" entries and Branch " << hadName
115 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary::No packing information -"
116 <<
" Assume x, y, z are not in packed form";
118 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Maximum probability cut off "
119 << probMax <<
" Back propagation of light prob. "
133 edm::LogInfo(
"FastCalorimetry") <<
"initHFShowerLibrary::initialization";
142 DDValue ddv(attribute,value,0);
151 std::vector<double> rTable =
getDDDArray(
"rTable",sv,nR);
155 <<
" cm and rMax " <<
rMax/cm;
158 std::vector<double> etaTable =
getDDDArray(
"etaTable",sv,nEta);
159 int nPhi = nEta + nR - 2;
160 std::vector<double> phibin =
getDDDArray(
"phibin",sv,nPhi);
161 dphi = phibin[nEta-1];
162 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: (Half) Phi Width of wedge "
168 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: " << ngpar <<
" gpar (cm)";
170 for (
int ig=0; ig<ngpar; ig++)
171 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: gpar[" << ig <<
"] = "
172 <<
gpar[ig]/cm <<
" cm";
174 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary: cannot get filtered "
175 <<
" view for " << attribute <<
" matching "
178 <<
"cannot match " << attribute <<
" to " << name <<
"\n";
196 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Particle codes for e- = "
197 <<
emPDG <<
", e+ = " <<
epPDG <<
", gamma = "
200 <<
"\n nu_e = " <<
nuePDG <<
", nu_mu = "
202 <<
", anti_nu_e = " <<
anuePDG <<
", anti_nu_mu = "
210 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: recoHFShowerLibrary ";
215 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: we should not be here ";
232 int parCode = myTrack.
type();
233 std::vector<FastHFShowerLibrary::Hit> hits =
234 getHits(vertex, direction, parCode, eGen, ok, weight,
false);
236 for (
unsigned int i=0;
i<hits.size(); ++
i) {
237 G4ThreeVector pos = hits[
i].position;
238 int depth = hits[
i].depth;
239 double time = hits[
i].time;
249 std::map<CaloHitID,float>::iterator cellitr;
250 cellitr =
hitMap.find(current_id);
251 if(cellitr==
hitMap.end()) {
252 hitMap.insert(std::pair<CaloHitID,float>(current_id,1.0));
254 cellitr->second += 1.0;
267 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary::isItinFidVolume:#PMT= "
268 << npmt <<
" for hit point " << hitPoint;
270 if (npmt <= 0) flag =
false;
273 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary::isItinFidVolume: point "
274 << hitPoint <<
" return flag " <<
flag;
280 const G4ThreeVector & momDir,
int parCode,
double pin,
281 bool &
ok,
double weight,
bool onlyLong) {
283 std::vector<FastHFShowerLibrary::Hit>
hit;
291 double tSlice = 0.1*hitPoint.mag()/29.98;
292 double pz = momDir.
z();
293 double zint = hitPoint.z();
297 if (pz * zint < 0.) backward = 1;
299 double sphi =
sin(momDir.phi());
300 double cphi =
cos(momDir.phi());
301 double ctheta =
cos(momDir.theta());
302 double stheta =
sin(momDir.theta());
305 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: getHits " << parCode
306 <<
" of energy " << pin/
GeV <<
" GeV"
307 <<
" dir.orts " << momDir.x() <<
", " <<momDir.y()
308 <<
", " << momDir.z() <<
" Pos x,y,z = "
309 << hitPoint.x() <<
"," << hitPoint.y() <<
","
310 << hitPoint.z() <<
","
311 <<
" sphi,cphi,stheta,ctheta = " << sphi
312 <<
"," << cphi <<
", " << stheta <<
"," << ctheta;
331 for (
int i = 0;
i <
npe;
i++) {
335 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Hit " <<
i <<
" " <<
pe[
i] <<
" zv " << zv;
338 if (zv <=
gpar[1] &&
pe[
i].lambda() > 0 &&
339 (
pe[
i].
z() >= 0 || (zv >
gpar[0] && (!onlyLong)))) {
342 }
else if (backward == 0) {
343 if (
pe[
i].
z() < 0) depth = 2;
345 double r = G4UniformRand();
346 if (r > 0.5) depth = 2;
352 double pex =
pe[
i].x();
353 double pey =
pe[
i].y();
355 double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
356 double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
357 double zz = -pex*stheta + zv*ctheta;
359 G4ThreeVector pos = hitPoint + G4ThreeVector(xx,yy,zz);
361 G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
365 double r = pos.perp();
367 double fi = pos.phi();
368 if (fi < 0) fi += twopi;
369 int isect = int(fi/
dphi) + 1;
370 isect = (isect + 1) / 2;
371 double dfi = ((isect*2-1)*
dphi - fi);
372 if (dfi < 0) dfi = -dfi;
373 double dfir = r *
sin(dfi);
376 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Position shift " << xx
377 <<
", " << yy <<
", " << zz <<
": " << pos
378 <<
" R " << r <<
" Phi " << fi <<
" Section "
379 << isect <<
" R*Dfi " << dfir <<
" Dist " << zv;
383 double r1 = G4UniformRand();
384 double r2 = G4UniformRand();
386 if (backward) r3 = G4UniformRand();
391 <<
" attenuation " << r1 <<
":" <<
exp(-p*zv)
392 <<
" r2 " << r2 <<
" r3 " << r3 <<
" rDfi "
394 << zz <<
" zLim " <<
gpar[4] <<
":"
396 <<
" rInside(r) :" <<
rInside(r)
397 <<
" r1 <= exp(-p*zv) :" << (r1 <=
exp(-p*zv))
398 <<
" r2 <= probMax :" << (r2 <=
probMax*weight)
399 <<
" r3 <= backProb :" << (r3 <=
backProb)
400 <<
" dfir > gpar[5] :" << (dfir >
gpar[5])
401 <<
" zz >= gpar[4] :" << (zz >=
gpar[4])
402 <<
" zz <= gpar[4]+gpar[1] :"
408 r3 <= backProb && (depth != 2 || zz >=
gpar[4]+
gpar[0])) {
413 hit.push_back(oneHit);
415 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Final Hit " << nHit
416 <<
" position " << (hit[nHit].position)
417 <<
" Depth " << (hit[nHit].depth) <<
" Time "
418 << tSlice <<
":" <<
pe[
i].t() <<
":"
425 else LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary: REJECTED !!!";
428 r1 = G4UniformRand();
429 r2 = G4UniformRand();
430 if (
rInside(r) && r1 <=
exp(-p*zv) && r2 <= probMax && dfir >
gpar[5]){
434 hit.push_back(oneHit);
436 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Final Hit " << nHit
437 <<
" position " << (hit[nHit].position)
438 <<
" Depth " << (hit[nHit].depth) <<
" Time "
439 << tSlice <<
":" <<
pe[
i].t() <<
":"
450 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary: Total Hits " << nHit
451 <<
" out of " << npe <<
" PE";
454 if (nHit > npe && !onlyLong)
455 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary: Hit buffer " << npe
456 <<
" smaller than " << nHit <<
" Hits";
463 if (r >=
rMin && r <=
rMax)
return true;
491 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary::getRecord: Record " << record
492 <<
" of type " << type <<
" with " << nPhoton
494 for (
int j = 0;
j < nPhoton;
j++)
503 std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
504 branch->SetAddress(&eventInfoCollection);
506 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary::loadEventInfo loads "
507 <<
" EventInfo Collection of size "
508 << eventInfoCollection.size() <<
" records";
509 totEvents = eventInfoCollection[0].totalEvents();
510 nMomBin = eventInfoCollection[0].numberOfBins();
511 evtPerBin = eventInfoCollection[0].eventsPerBin();
512 libVers = eventInfoCollection[0].showerLibraryVersion();
513 listVersion = eventInfoCollection[0].physListVersion();
514 pmom = eventInfoCollection[0].energyBins();
516 edm::LogInfo(
"FastCalorimetry") <<
"HFShowerLibrary::loadEventInfo loads "
517 <<
" EventInfo from hardwired numbers";
523 pmom = {2,3,5,7,10,15,20,30,50,75,100,150,250,350,500,1000};
532 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary:: Interpolate for Energy " <<pin/
GeV
533 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
539 double r = G4UniformRand();
549 if (j == nMomBin-2) {
558 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary:: Illegal irc[0] = "
559 << irc[0] <<
" now set to 0";
561 }
else if (irc[0] > totEvents) {
562 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary:: Illegal irc[0] = "
570 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary:: Illegal irc[1] = "
571 << irc[1] <<
" now set to 1";
574 }
else if (irc[1] > totEvents) {
575 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary:: Illegal irc[1] = "
582 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary:: Select records " << irc[0]
583 <<
" and " << irc[1] <<
" with weights " << 1-w
590 for (
int ir=0; ir < 2; ir++) {
595 for (
int j=0;
j<nPhoton;
j++) {
597 if ((ir==0 && r > w) || (ir > 0 && r < w)) {
604 if ((
npe > npold || (npold == 0 && irc[0] > 0)) && !(
npe == 0 && npold == 0))
605 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary: Interpolation Warning =="
606 <<
" records " << irc[0] <<
" and " << irc[1]
607 <<
" gives a buffer of " << npold
608 <<
" photons and fills " <<
npe <<
" *****";
611 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary: Interpolation == records "
612 << irc[0] <<
" and " << irc[1] <<
" gives a "
613 <<
"buffer of " << npold <<
" photons and fills "
616 LogDebug(
"FastCalorimetry") <<
"Photon " <<
j <<
" " <<
pe[
j];
627 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary:: Extrapolate for Energy " << pin
628 <<
" GeV with " <<
nMomBin <<
" momentum bins and "
630 <<
" using " << nrec <<
" records";
633 std::vector<int> irc(nrec);
635 for (
int ir=0; ir<nrec; ir++) {
636 double r = G4UniformRand();
639 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary:: Illegal irc[" << ir
640 <<
"] = " << irc[ir] <<
" now set to 1";
643 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary:: Illegal irc[" << ir
644 <<
"] = " << irc[ir] <<
" now set to "
649 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary::Extrapolation use irc["
650 << ir <<
"] = " << irc[ir];
658 for (
int ir=0; ir<nrec; ir++) {
663 for (
int j=0;
j<nPhoton;
j++) {
664 double r = G4UniformRand();
665 if (ir != nrec-1 || r < w) {
670 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary: Record [" << ir <<
"] = "
671 << irc[ir] <<
" npold = " << npold;
676 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary:: uses " << npold <<
" photons";
679 if (
npe > npold || npold == 0)
680 edm::LogWarning(
"FastCalorimetry") <<
"HFShowerLibrary: Extrapolation Warning == "
681 << nrec <<
" records " << irc[0] <<
", "
682 << irc[1] <<
", ... gives a buffer of " <<npold
683 <<
" photons and fills " <<
npe
687 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary: Extrapolation == " << nrec
688 <<
" records " << irc[0] <<
", " << irc[1]
689 <<
", ... gives a buffer of " << npold
690 <<
" photons and fills " << npe <<
" PE";
692 LogDebug(
"FastCalorimetry") <<
"Photon " <<
j <<
" " <<
pe[
j];
701 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary: storePhoton " << j <<
" npe "
713 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary:getDDDArray called for " << str
714 <<
" with nMin " << nmin;
720 LogDebug(
"FastCalorimetry") <<
"HFShowerLibrary:getDDDArray value " <<
value;
723 const std::vector<double> & fvec = value.
doubles();
724 int nval = fvec.size();
727 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary : # of " << str
728 <<
" bins " << nval <<
" < " << nmin
731 <<
"nval < nmin for array " << str <<
"\n";
735 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary : # of " << str
736 <<
" bins " << nval <<
" < 2 ==> illegal"
737 <<
" (nmin=" << nmin <<
")";
739 <<
"nval < 2 for array " << str <<
"\n";
746 edm::LogError(
"FastCalorimetry") <<
"HFShowerLibrary : cannot get array " << str;
749 <<
"cannot get array " << str <<
"\n";
T getParameter(std::string const &) const
HcalNumberingScheme * numberingScheme
T getUntrackedParameter(std::string const &, T 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< double > getDDDArray(const std::string &, const DDsvalues_type &, int &)
const RawParticle & vfcalEntrance() const
The particle at VFCAL entrance.
void recoHFShowerLibrary(const FSimTrack &myTrack)
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id)
Sin< T >::type sin(const T &t)
HFShowerPhotonCollection pe
void loadEventInfo(TBranch *)
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
static int PMTNumber(const G4ThreeVector &pe_effect)
static TrackerG4SimHitNumberingScheme & numberingScheme(const DDCompactView &cpv, const GeometricDet &det)
HcalNumberingFromDDD * numberingFromDDD
void interpolate(int, double)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
double tShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
std::vector< Hit > getHits(const G4ThreeVector &p, const G4ThreeVector &v, int parCode, double parEnergy, bool &ok, double weight, bool onlyLong=false)
void extrapolate(int, double)
Cos< T >::type cos(const T &t)
double Y() const
y of vertex
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::...
double attLength(double lambda)
double Z() const
z of vertex
Abs< T >::type abs(const T &t)
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
const XYZTLorentzVector & vertex() const
the vertex fourvector
HFShowerPhotonCollection photon
FastHFShowerLibrary(edm::ParameterSet const &p)
DDsvalues_type mergedSpecifics() const
double X() const
x of vertex
std::vector< double > gpar
std::vector< std::vector< double > > tmp
int type() const
particle type (HEP PDT convension)
double zShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
int id() const
the index in FBaseSimEvent and other vectors
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 const initHFShowerLibrary(const edm::EventSetup &)
HcalID unitID(int det, const CLHEP::Hep3Vector &pos, int depth, int lay=-1) const
std::map< CaloHitID, float > hitMap
bool isItinFidVolume(G4ThreeVector &)
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.