CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Protected Member Functions | Private Attributes
HFShowerLibrary Class Reference

#include <HFShowerLibrary.h>

Classes

struct  Hit
 

Public Member Functions

std::vector< HitfillHits (const G4ThreeVector &p, const G4ThreeVector &v, int parCode, double parEnergy, bool &ok, double weight, double time, bool onlyLong=false)
 
std::vector< HitgetHits (const G4Step *aStep, bool &ok, double weight, bool onlyLong=false)
 
 HFShowerLibrary (const std::string &name, const HcalDDDSimConstants *hcons, const HcalSimulationParameters *hps, edm::ParameterSet const &p)
 
 ~HFShowerLibrary ()
 

Protected Member Functions

void extrapolate (int, double)
 
void getRecord (int, int)
 
void interpolate (int, double)
 
void loadEventInfo (TBranch *)
 
bool rInside (double r)
 
void storePhoton (int j)
 

Private Attributes

bool applyFidCut
 
double backProb
 
double dphi
 
TBranch * emBranch
 
int evtPerBin
 
std::unique_ptr< HFFibrefibre_
 
std::vector< double > gpar
 
TBranch * hadBranch
 
const HcalDDDSimConstantshcalConstant_
 
TFile * hf
 
float libVers
 
float listVersion
 
bool newForm
 
int nMomBin
 
int npe
 
HFShowerPhotonCollection pe
 
HFShowerPhotonCollectionphoto
 
HFShowerPhotonCollection photon
 
std::vector< double > pmom
 
double probMax
 
double rMax
 
double rMin
 
int totEvents
 
bool v3version
 
bool verbose
 

Detailed Description

Definition at line 29 of file HFShowerLibrary.h.

Constructor & Destructor Documentation

HFShowerLibrary::HFShowerLibrary ( const std::string &  name,
const HcalDDDSimConstants hcons,
const HcalSimulationParameters hps,
edm::ParameterSet const &  p 
)

Definition at line 23 of file HFShowerLibrary.cc.

References applyFidCut, backProb, dphi, emBranch, event(), evtPerBin, Exception, fibre_, personalPlayback::fp, edm::ParameterSet::getParameter(), GeV, gpar, hadBranch, hcalConstant_, hf, mps_fire::i, info(), libVers, listVersion, loadEventInfo(), Skims_PA_cff::name, newForm, nMomBin, AlCaHLTBitMon_ParallelJobs::p, photo, pmom, probMax, rMax, rMin, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, totEvents, and v3version.

27  : hcalConstant_(hcons), hf(nullptr), emBranch(nullptr), hadBranch(nullptr), npe(0) {
28  edm::ParameterSet m_HF = p.getParameter<edm::ParameterSet>("HFShower");
29  probMax = m_HF.getParameter<double>("ProbMax");
30 
31  edm::ParameterSet m_HS = p.getParameter<edm::ParameterSet>("HFShowerLibrary");
32  edm::FileInPath fp = m_HS.getParameter<edm::FileInPath>("FileName");
33  std::string pTreeName = fp.fullPath();
34  backProb = m_HS.getParameter<double>("BackProbability");
35  std::string emName = m_HS.getParameter<std::string>("TreeEMID");
36  std::string hadName = m_HS.getParameter<std::string>("TreeHadID");
37  std::string branchEvInfo = m_HS.getUntrackedParameter<std::string>(
38  "BranchEvt", "HFShowerLibraryEventInfos_hfshowerlib_HFShowerLibraryEventInfo");
39  std::string branchPre = m_HS.getUntrackedParameter<std::string>("BranchPre", "HFShowerPhotons_hfshowerlib_");
40  std::string branchPost = m_HS.getUntrackedParameter<std::string>("BranchPost", "_R.obj");
41  verbose = m_HS.getUntrackedParameter<bool>("Verbosity", false);
42  applyFidCut = m_HS.getParameter<bool>("ApplyFiducialCut");
43 
44  if (pTreeName.find(".") == 0)
45  pTreeName.erase(0, 2);
46  const char* nTree = pTreeName.c_str();
47  hf = TFile::Open(nTree);
48 
49  if (!hf->IsOpen()) {
50  edm::LogError("HFShower") << "HFShowerLibrary: opening " << nTree << " failed";
51  throw cms::Exception("Unknown", "HFShowerLibrary") << "Opening of " << pTreeName << " fails\n";
52  } else {
53  edm::LogVerbatim("HFShower") << "HFShowerLibrary: opening " << nTree << " successfully";
54  }
55 
56  newForm = (branchEvInfo.empty());
57  TTree* event(nullptr);
58  if (newForm)
59  event = (TTree*)hf->Get("HFSimHits");
60  else
61  event = (TTree*)hf->Get("Events");
62  if (event) {
63  TBranch* evtInfo(nullptr);
64  if (!newForm) {
65  std::string info = branchEvInfo + branchPost;
66  evtInfo = event->GetBranch(info.c_str());
67  }
68  if (evtInfo || newForm) {
69  loadEventInfo(evtInfo);
70  } else {
71  edm::LogError("HFShower") << "HFShowerLibrary: HFShowerLibrayEventInfo"
72  << " Branch does not exist in Event";
73  throw cms::Exception("Unknown", "HFShowerLibrary") << "Event information absent\n";
74  }
75  } else {
76  edm::LogError("HFShower") << "HFShowerLibrary: Events Tree does not "
77  << "exist";
78  throw cms::Exception("Unknown", "HFShowerLibrary") << "Events tree absent\n";
79  }
80 
81 #ifdef EDM_ML_DEBUG
82  std::stringstream ss;
83  ss << "HFShowerLibrary: Library " << libVers << " ListVersion " << listVersion << " Events Total " << totEvents
84  << " and " << evtPerBin << " per bin\n";
85  ss << "HFShowerLibrary: Energies (GeV) with " << nMomBin << " bins\n";
86  for (int i = 0; i < nMomBin; ++i) {
87  if (i / 10 * 10 == i && i > 0) {
88  ss << "\n";
89  }
90  ss << " " << pmom[i] / CLHEP::GeV;
91  }
92  edm::LogVerbatim("HFShower") << ss.str();
93 #endif
94  std::string nameBr = branchPre + emName + branchPost;
95  emBranch = event->GetBranch(nameBr.c_str());
96  if (verbose)
97  emBranch->Print();
98  nameBr = branchPre + hadName + branchPost;
99  hadBranch = event->GetBranch(nameBr.c_str());
100  if (verbose)
101  hadBranch->Print();
102 
103  v3version = false;
104  if (emBranch->GetClassName() == std::string("vector<float>")) {
105  v3version = true;
106  }
107 
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HFShower") << " HFShowerLibrary:Branch " << emName << " has " << emBranch->GetEntries()
110  << " entries and Branch " << hadName << " has " << hadBranch->GetEntries() << " entries"
111  << "\n HFShowerLibrary::No packing information -"
112  << " Assume x, y, z are not in packed form"
113  << "\n Maximum probability cut off " << probMax << " Back propagation of light prob. "
114  << backProb;
115 #endif
116  fibre_ = std::make_unique<HFFibre>(name, hcalConstant_, hps, p);
118 
119  //Radius (minimum and maximum)
120  std::vector<double> rTable = hcalConstant_->getRTableHF();
121  rMin = rTable[0];
122  rMax = rTable[rTable.size() - 1];
123 
124  //Delta phi
125  std::vector<double> phibin = hcalConstant_->getPhiTableHF();
126  dphi = phibin[0];
127 #ifdef EDM_ML_DEBUG
128  edm::LogVerbatim("HFShower") << "HFShowerLibrary: rMIN " << rMin / CLHEP::cm << " cm and rMax " << rMax / CLHEP::cm
129  << " (Half) Phi Width of wedge " << dphi / CLHEP::deg;
130 #endif
131  //Special Geometry parameters
132  gpar = hcalConstant_->getGparHF();
133 }
T getParameter(std::string const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
const double GeV
Definition: MathUtil.h:16
const HcalDDDSimConstants * hcalConstant_
std::unique_ptr< HFFibre > fibre_
std::vector< HFShowerPhoton > HFShowerPhotonCollection
void loadEventInfo(TBranch *)
std::vector< double > gpar
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
TBranch * emBranch
std::vector< double > pmom
Definition: event.py:1
TBranch * hadBranch
HFShowerLibrary::~HFShowerLibrary ( )

Definition at line 135 of file HFShowerLibrary.cc.

References hf, and photo.

135  {
136  if (hf)
137  hf->Close();
138  delete photo;
139 }
HFShowerPhotonCollection * photo

Member Function Documentation

void HFShowerLibrary::extrapolate ( int  type,
double  pin 
)
protected

Definition at line 511 of file HFShowerLibrary.cc.

References evtPerBin, getRecord(), createfilelist::int, dqmiolumiharvest::j, newForm, nMomBin, npe, pe, photo, photon, pmom, alignCSCRings::r, storePhoton(), totEvents, and w.

Referenced by fillHits().

511  {
512  int nrec = int(pin / pmom[nMomBin - 1]);
513  double w = (pin - pmom[nMomBin - 1] * nrec) / pmom[nMomBin - 1];
514  nrec++;
515 #ifdef EDM_ML_DEBUG
516  edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Extrapolate for Energy " << pin << " GeV with " << nMomBin
517  << " momentum bins and " << evtPerBin << " entries/bin -- "
518  << "total " << totEvents << " using " << nrec << " records";
519 #endif
520  std::vector<int> irc(nrec);
521 
522  for (int ir = 0; ir < nrec; ir++) {
523  double r = G4UniformRand();
524  irc[ir] = int(evtPerBin * 0.5 * r) + (nMomBin - 1) * evtPerBin + 1;
525  if (irc[ir] < 1) {
526  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[" << ir << "] = " << irc[ir] << " now set to 1";
527  irc[ir] = 1;
528  } else if (irc[ir] > totEvents) {
529  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[" << ir << "] = " << irc[ir] << " now set to "
530  << totEvents;
531  irc[ir] = totEvents;
532 #ifdef EDM_ML_DEBUG
533  } else {
534  edm::LogVerbatim("HFShower") << "HFShowerLibrary::Extrapolation use irc[" << ir << "] = " << irc[ir];
535 #endif
536  }
537  }
538 
539  pe.clear();
540  npe = 0;
541  int npold = 0;
542  for (int ir = 0; ir < nrec; ir++) {
543  if (irc[ir] > 0) {
544  getRecord(type, irc[ir]);
545  int nPhoton = (newForm) ? photo->size() : photon.size();
546  npold += nPhoton;
547  for (int j = 0; j < nPhoton; j++) {
548  double r = G4UniformRand();
549  if (ir != nrec - 1 || r < w) {
550  storePhoton(j);
551  }
552  }
553 #ifdef EDM_ML_DEBUG
554  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Record [" << ir << "] = " << irc[ir] << " npold = " << npold;
555 #endif
556  }
557  }
558 #ifdef EDM_ML_DEBUG
559  edm::LogVerbatim("HFShower") << "HFShowerLibrary:: uses " << npold << " photons";
560 #endif
561 
562  if (npe > npold || npold == 0)
563  edm::LogWarning("HFShower") << "HFShowerLibrary: Extrapolation Warning == " << nrec << " records " << irc[0] << ", "
564  << irc[1] << ", ... gives a buffer of " << npold << " photons and fills " << npe
565  << " *****";
566 #ifdef EDM_ML_DEBUG
567  else
568  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Extrapolation == " << nrec << " records " << irc[0] << ", "
569  << irc[1] << ", ... gives a buffer of " << npold << " photons and fills " << npe
570  << " PE";
571  for (int j = 0; j < npe; j++)
572  edm::LogVerbatim("HFShower") << "Photon " << j << " " << pe[j];
573 #endif
574 }
type
Definition: HCALResponse.h:21
void getRecord(int, int)
const double w
Definition: UKUtility.cc:23
HFShowerPhotonCollection pe
HFShowerPhotonCollection * photo
std::vector< double > pmom
void storePhoton(int j)
HFShowerPhotonCollection photon
std::vector< HFShowerLibrary::Hit > HFShowerLibrary::fillHits ( const G4ThreeVector &  p,
const G4ThreeVector &  v,
int  parCode,
double  parEnergy,
bool &  ok,
double  weight,
double  time,
bool  onlyLong = false 
)

Definition at line 182 of file HFShowerLibrary.cc.

References funct::abs(), applyFidCut, backProb, funct::cos(), HFShowerLibrary::Hit::depth, LEDCalibrationChannels::depth, dphi, JetChargeProducer_cfi::exp, extrapolate(), fibre_, gpar, mps_fire::i, createfilelist::int, interpolate(), G4TrackToParticleID::isGammaElectronPositron(), G4TrackToParticleID::isStableHadron(), MeV, nMomBin, npe, AlCaHLTBitMon_ParallelJobs::p, pe, pmom, HFShowerLibrary::Hit::position, probMax, alignCSCRings::r, diffTwoXMLs::r1, diffTwoXMLs::r2, rInside(), funct::sin(), MessageLogger_cff::threshold, HFShowerLibrary::Hit::time, geometryCSVtoXML::xx, geometryCSVtoXML::yy, z, and geometryCSVtoXML::zz.

Referenced by getHits().

189  {
190  std::vector<HFShowerLibrary::Hit> hit;
191  ok = false;
193  // shower is built only for gamma, e+- and stable hadrons
194  if (!isEM && !G4TrackToParticleID::isStableHadron(parCode)) {
195  return hit;
196  }
197  ok = true;
198 
199  // remove low-energy component
200  const double threshold = 50 * MeV;
201  if (pin < threshold) {
202  return hit;
203  }
204 
205  double pz = momDir.z();
206  double zint = hitPoint.z();
207 
208  // if particle moves from interaction point or "backwards (halo)
209  bool backward = (pz * zint < 0.) ? true : false;
210 
211  double sphi = sin(momDir.phi());
212  double cphi = cos(momDir.phi());
213  double ctheta = cos(momDir.theta());
214  double stheta = sin(momDir.theta());
215 
216  if (isEM) {
217  if (pin < pmom[nMomBin - 1]) {
218  interpolate(0, pin);
219  } else {
220  extrapolate(0, pin);
221  }
222  } else {
223  if (pin < pmom[nMomBin - 1]) {
224  interpolate(1, pin);
225  } else {
226  extrapolate(1, pin);
227  }
228  }
229 
230  int nHit = 0;
231  HFShowerLibrary::Hit oneHit;
232  for (int i = 0; i < npe; ++i) {
233  double zv = std::abs(pe[i].z()); // abs local z
234 #ifdef EDM_ML_DEBUG
235  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Hit " << i << " " << pe[i] << " zv " << zv;
236 #endif
237  if (zv <= gpar[1] && pe[i].lambda() > 0 && (pe[i].z() >= 0 || (zv > gpar[0] && (!onlyLong)))) {
238  int depth = 1;
239  if (onlyLong) {
240  } else if (!backward) { // fully valid only for "front" particles
241  if (pe[i].z() < 0)
242  depth = 2; // with "front"-simulated shower lib.
243  } else { // for "backward" particles - almost equal
244  double r = G4UniformRand(); // share between L and S fibers
245  if (r > 0.5)
246  depth = 2;
247  }
248 
249  // Updated coordinate transformation from local
250  // back to global using two Euler angles: phi and theta
251  double pex = pe[i].x();
252  double pey = pe[i].y();
253 
254  double xx = pex * ctheta * cphi - pey * sphi + zv * stheta * cphi;
255  double yy = pex * ctheta * sphi + pey * cphi + zv * stheta * sphi;
256  double zz = -pex * stheta + zv * ctheta;
257 
258  G4ThreeVector pos = hitPoint + G4ThreeVector(xx, yy, zz);
259  zv = std::abs(pos.z()) - gpar[4] - 0.5 * gpar[1];
260  G4ThreeVector lpos = G4ThreeVector(pos.x(), pos.y(), zv);
261 
262  zv = fibre_->zShift(lpos, depth, 0); // distance to PMT !
263 
264  double r = pos.perp();
265  double p = fibre_->attLength(pe[i].lambda());
266  double fi = pos.phi();
267  if (fi < 0)
268  fi += CLHEP::twopi;
269  int isect = int(fi / dphi) + 1;
270  isect = (isect + 1) / 2;
271  double dfi = ((isect * 2 - 1) * dphi - fi);
272  if (dfi < 0)
273  dfi = -dfi;
274  double dfir = r * sin(dfi);
275 #ifdef EDM_ML_DEBUG
276  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Position shift " << xx << ", " << yy << ", " << zz << ": "
277  << pos << " R " << r << " Phi " << fi << " Section " << isect << " R*Dfi " << dfir
278  << " Dist " << zv;
279 #endif
280  zz = std::abs(pos.z());
281  double r1 = G4UniformRand();
282  double r2 = G4UniformRand();
283  double r3 = backward ? G4UniformRand() : -9999.;
284  if (!applyFidCut)
285  dfir += gpar[5];
286 
287 #ifdef EDM_ML_DEBUG
288  edm::LogVerbatim("HFShower") << "HFShowerLibrary: rLimits " << rInside(r) << " attenuation " << r1 << ":"
289  << exp(-p * zv) << " r2 " << r2 << " r3 " << r3 << " rDfi " << gpar[5] << " zz "
290  << zz << " zLim " << gpar[4] << ":" << gpar[4] + gpar[1] << "\n"
291  << " rInside(r) :" << rInside(r) << " r1 <= exp(-p*zv) :" << (r1 <= exp(-p * zv))
292  << " r2 <= probMax :" << (r2 <= probMax * weight)
293  << " r3 <= backProb :" << (r3 <= backProb)
294  << " dfir > gpar[5] :" << (dfir > gpar[5]) << " zz >= gpar[4] :" << (zz >= gpar[4])
295  << " zz <= gpar[4]+gpar[1] :" << (zz <= gpar[4] + gpar[1]);
296 #endif
297  if (rInside(r) && r1 <= exp(-p * zv) && r2 <= probMax * weight && dfir > gpar[5] && zz >= gpar[4] &&
298  zz <= gpar[4] + gpar[1] && r3 <= backProb && (depth != 2 || zz >= gpar[4] + gpar[0])) {
299  oneHit.position = pos;
300  oneHit.depth = depth;
301  oneHit.time = (tSlice + (pe[i].t()) + (fibre_->tShift(lpos, depth, 1)));
302  hit.push_back(oneHit);
303 #ifdef EDM_ML_DEBUG
304  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Final Hit " << nHit << " position " << (hit[nHit].position)
305  << " Depth " << (hit[nHit].depth) << " Time " << tSlice << ":" << pe[i].t() << ":"
306  << fibre_->tShift(lpos, depth, 1) << ":" << (hit[nHit].time);
307 #endif
308  ++nHit;
309  }
310 #ifdef EDM_ML_DEBUG
311  else
312  edm::LogVerbatim("HFShower") << "HFShowerLibrary: REJECTED !!!";
313 #endif
314  if (onlyLong && zz >= gpar[4] + gpar[0] && zz <= gpar[4] + gpar[1]) {
315  r1 = G4UniformRand();
316  r2 = G4UniformRand();
317  if (rInside(r) && r1 <= exp(-p * zv) && r2 <= probMax && dfir > gpar[5]) {
318  oneHit.position = pos;
319  oneHit.depth = 2;
320  oneHit.time = (tSlice + (pe[i].t()) + (fibre_->tShift(lpos, 2, 1)));
321  hit.push_back(oneHit);
322 #ifdef EDM_ML_DEBUG
323  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Final Hit " << nHit << " position " << (hit[nHit].position)
324  << " Depth " << (hit[nHit].depth) << " Time " << tSlice << ":" << pe[i].t()
325  << ":" << fibre_->tShift(lpos, 2, 1) << ":" << (hit[nHit].time);
326 #endif
327  ++nHit;
328  }
329  }
330  }
331  }
332 
333 #ifdef EDM_ML_DEBUG
334  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Total Hits " << nHit << " out of " << npe << " PE";
335 #endif
336  if (nHit > npe && !onlyLong) {
337  edm::LogWarning("HFShower") << "HFShowerLibrary: Hit buffer " << npe << " smaller than " << nHit << " Hits";
338  }
339  return hit;
340 }
std::unique_ptr< HFFibre > fibre_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
HFShowerPhotonCollection pe
Definition: weight.py:1
static bool isStableHadron(int pdgCode)
const double MeV
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > gpar
std::vector< double > pmom
G4ThreeVector position
void extrapolate(int, double)
static bool isGammaElectronPositron(int pdgCode)
bool rInside(double r)
void interpolate(int, double)
std::vector< HFShowerLibrary::Hit > HFShowerLibrary::getHits ( const G4Step *  aStep,
bool &  ok,
double  weight,
bool  onlyLong = false 
)

Definition at line 141 of file HFShowerLibrary.cc.

References funct::cos(), fillHits(), GeV, gpar, funct::sin(), and HLT_2018_cff::track.

144  {
145  auto const preStepPoint = aStep->GetPreStepPoint();
146  auto const postStepPoint = aStep->GetPostStepPoint();
147  auto const track = aStep->GetTrack();
148  // Get Z-direction
149  auto const aParticle = track->GetDynamicParticle();
150  const G4ThreeVector& momDir = aParticle->GetMomentumDirection();
151  const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
152  int parCode = track->GetDefinition()->GetPDGEncoding();
153 
154  // VI: for ions use internally pdg code of alpha in order to keep
155  // consistency with previous simulation
156  if (track->GetDefinition()->IsGeneralIon()) {
157  parCode = 1000020040;
158  }
159 
160 #ifdef EDM_ML_DEBUG
161  G4String partType = track->GetDefinition()->GetParticleName();
162  const G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
163  double zoff = localPos.z() + 0.5 * gpar[1];
164 
165  edm::LogVerbatim("HFShower") << "HFShowerLibrary::getHits " << partType << " of energy "
166  << track->GetKineticEnergy() / GeV << " GeV weight= " << weight
167  << " onlyLong: " << onlyLong << " dir.orts " << momDir.x() << ", " << momDir.y() << ", "
168  << momDir.z() << " Pos x,y,z = " << hitPoint.x() << "," << hitPoint.y() << ","
169  << hitPoint.z() << " (" << zoff << ") sphi,cphi,stheta,ctheta = " << sin(momDir.phi())
170  << "," << cos(momDir.phi()) << ", " << sin(momDir.theta()) << "," << cos(momDir.theta());
171 #endif
172 
173  double tSlice = (postStepPoint->GetGlobalTime()) / CLHEP::nanosecond;
174 
175  // use kinetic energy for protons and ions
176  double pin = (track->GetDefinition()->GetBaryonNumber() > 0) ? preStepPoint->GetKineticEnergy()
177  : preStepPoint->GetTotalEnergy();
178 
179  return fillHits(hitPoint, momDir, parCode, pin, isKilled, weight, tSlice, onlyLong);
180 }
const double GeV
Definition: MathUtil.h:16
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Definition: weight.py:1
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< double > gpar
std::vector< Hit > fillHits(const G4ThreeVector &p, const G4ThreeVector &v, int parCode, double parEnergy, bool &ok, double weight, double time, bool onlyLong=false)
void HFShowerLibrary::getRecord ( int  type,
int  record 
)
protected

Definition at line 344 of file HFShowerLibrary.cc.

References emBranch, hadBranch, mps_fire::i, dqmiolumiharvest::j, newForm, photo, photon, OrderedSet::t, totEvents, and v3version.

Referenced by extrapolate(), and interpolate().

344  {
345  int nrc = record - 1;
346  photon.clear();
347  photo->clear();
348  if (type > 0) {
349  if (newForm) {
350  if (!v3version) {
351  hadBranch->SetAddress(&photo);
352  hadBranch->GetEntry(nrc + totEvents);
353  } else {
354  std::vector<float> t;
355  std::vector<float>* tp = &t;
356  hadBranch->SetAddress(&tp);
357  hadBranch->GetEntry(nrc + totEvents);
358  unsigned int tSize = t.size() / 5;
359  photo->reserve(tSize);
360  for (unsigned int i = 0; i < tSize; i++) {
361  photo->push_back(
362  HFShowerPhoton(t[i], t[1 * tSize + i], t[2 * tSize + i], t[3 * tSize + i], t[4 * tSize + i]));
363  }
364  }
365  } else {
366  hadBranch->SetAddress(&photon);
367  hadBranch->GetEntry(nrc);
368  }
369  } else {
370  if (newForm) {
371  if (!v3version) {
372  emBranch->SetAddress(&photo);
373  emBranch->GetEntry(nrc);
374  } else {
375  std::vector<float> t;
376  std::vector<float>* tp = &t;
377  emBranch->SetAddress(&tp);
378  emBranch->GetEntry(nrc);
379  unsigned int tSize = t.size() / 5;
380  photo->reserve(tSize);
381  for (unsigned int i = 0; i < tSize; i++) {
382  photo->push_back(
383  HFShowerPhoton(t[i], t[1 * tSize + i], t[2 * tSize + i], t[3 * tSize + i], t[4 * tSize + i]));
384  }
385  }
386  } else {
387  emBranch->SetAddress(&photon);
388  emBranch->GetEntry(nrc);
389  }
390  }
391 #ifdef EDM_ML_DEBUG
392  int nPhoton = (newForm) ? photo->size() : photon.size();
393  edm::LogVerbatim("HFShower") << "HFShowerLibrary::getRecord: Record " << record << " of type " << type << " with "
394  << nPhoton << " photons";
395  for (int j = 0; j < nPhoton; j++)
396  if (newForm)
397  edm::LogVerbatim("HFShower") << "Photon " << j << " " << photo->at(j);
398  else
399  edm::LogVerbatim("HFShower") << "Photon " << j << " " << photon[j];
400 #endif
401 }
type
Definition: HCALResponse.h:21
JetCorrectorParameters::Record record
Definition: classes.h:7
HFShowerPhotonCollection * photo
TBranch * emBranch
HFShowerPhotonCollection photon
TBranch * hadBranch
void HFShowerLibrary::interpolate ( int  type,
double  pin 
)
protected

Definition at line 434 of file HFShowerLibrary.cc.

References evtPerBin, getRecord(), GeV, createfilelist::int, dqmiolumiharvest::j, newForm, nMomBin, npe, pe, photo, photon, pmom, alignCSCRings::r, storePhoton(), totEvents, and w.

Referenced by fillHits().

434  {
435 #ifdef EDM_ML_DEBUG
436  edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Interpolate for Energy " << pin / GeV << " GeV with " << nMomBin
437  << " momentum bins and " << evtPerBin << " entries/bin -- total " << totEvents;
438 #endif
439  int irc[2] = {0, 0};
440  double w = 0.;
441  double r = G4UniformRand();
442 
443  if (pin < pmom[0]) {
444  w = pin / pmom[0];
445  irc[1] = int(evtPerBin * r) + 1;
446  irc[0] = 0;
447  } else {
448  for (int j = 0; j < nMomBin - 1; j++) {
449  if (pin >= pmom[j] && pin < pmom[j + 1]) {
450  w = (pin - pmom[j]) / (pmom[j + 1] - pmom[j]);
451  if (j == nMomBin - 2) {
452  irc[1] = int(evtPerBin * 0.5 * r);
453  } else {
454  irc[1] = int(evtPerBin * r);
455  }
456  irc[1] += (j + 1) * evtPerBin + 1;
457  r = G4UniformRand();
458  irc[0] = int(evtPerBin * r) + 1 + j * evtPerBin;
459  if (irc[0] < 0) {
460  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[0] = " << irc[0] << " now set to 0";
461  irc[0] = 0;
462  } else if (irc[0] > totEvents) {
463  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[0] = " << irc[0] << " now set to " << totEvents;
464  irc[0] = totEvents;
465  }
466  }
467  }
468  }
469  if (irc[1] < 1) {
470  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[1] = " << irc[1] << " now set to 1";
471  irc[1] = 1;
472  } else if (irc[1] > totEvents) {
473  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[1] = " << irc[1] << " now set to " << totEvents;
474  irc[1] = totEvents;
475  }
476 
477 #ifdef EDM_ML_DEBUG
478  edm::LogVerbatim("HFShower") << "HFShowerLibrary:: Select records " << irc[0] << " and " << irc[1] << " with weights "
479  << 1 - w << " and " << w;
480 #endif
481  pe.clear();
482  npe = 0;
483  int npold = 0;
484  for (int ir = 0; ir < 2; ir++) {
485  if (irc[ir] > 0) {
486  getRecord(type, irc[ir]);
487  int nPhoton = (newForm) ? photo->size() : photon.size();
488  npold += nPhoton;
489  for (int j = 0; j < nPhoton; j++) {
490  r = G4UniformRand();
491  if ((ir == 0 && r > w) || (ir > 0 && r < w)) {
492  storePhoton(j);
493  }
494  }
495  }
496  }
497 
498  if ((npe > npold || (npold == 0 && irc[0] > 0)) && !(npe == 0 && npold == 0))
499  edm::LogWarning("HFShower") << "HFShowerLibrary: Interpolation Warning =="
500  << " records " << irc[0] << " and " << irc[1] << " gives a buffer of " << npold
501  << " photons and fills " << npe << " *****";
502 #ifdef EDM_ML_DEBUG
503  else
504  edm::LogVerbatim("HFShower") << "HFShowerLibrary: Interpolation == records " << irc[0] << " and " << irc[1]
505  << " gives a buffer of " << npold << " photons and fills " << npe << " PE";
506  for (int j = 0; j < npe; j++)
507  edm::LogVerbatim("HFShower") << "Photon " << j << " " << pe[j];
508 #endif
509 }
type
Definition: HCALResponse.h:21
const double GeV
Definition: MathUtil.h:16
void getRecord(int, int)
const double w
Definition: UKUtility.cc:23
HFShowerPhotonCollection pe
HFShowerPhotonCollection * photo
std::vector< double > pmom
void storePhoton(int j)
HFShowerPhotonCollection photon
void HFShowerLibrary::loadEventInfo ( TBranch *  branch)
protected

Definition at line 403 of file HFShowerLibrary.cc.

References evtPerBin, GeV, mps_fire::i, libVers, listVersion, nMomBin, pmom, and totEvents.

Referenced by HFShowerLibrary().

403  {
404  if (branch) {
405  std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
406  branch->SetAddress(&eventInfoCollection);
407  branch->GetEntry(0);
408 #ifdef EDM_ML_DEBUG
409  edm::LogVerbatim("HFShower") << "HFShowerLibrary::loadEventInfo loads EventInfo Collection of size "
410  << eventInfoCollection.size() << " records";
411 #endif
412  totEvents = eventInfoCollection[0].totalEvents();
413  nMomBin = eventInfoCollection[0].numberOfBins();
414  evtPerBin = eventInfoCollection[0].eventsPerBin();
415  libVers = eventInfoCollection[0].showerLibraryVersion();
416  listVersion = eventInfoCollection[0].physListVersion();
417  pmom = eventInfoCollection[0].energyBins();
418  } else {
419 #ifdef EDM_ML_DEBUG
420  edm::LogVerbatim("HFShower") << "HFShowerLibrary::loadEventInfo loads EventInfo from hardwired"
421  << " numbers";
422 #endif
423  nMomBin = 16;
424  evtPerBin = 5000;
426  libVers = 1.1;
427  listVersion = 3.6;
428  pmom = {2, 3, 5, 7, 10, 15, 20, 30, 50, 75, 100, 150, 250, 350, 500, 1000};
429  }
430  for (int i = 0; i < nMomBin; i++)
431  pmom[i] *= GeV;
432 }
const double GeV
Definition: MathUtil.h:16
std::vector< double > pmom
bool HFShowerLibrary::rInside ( double  r)
protected

Definition at line 342 of file HFShowerLibrary.cc.

References rMax, and rMin.

Referenced by fillHits().

342 { return (r >= rMin && r <= rMax); }
void HFShowerLibrary::storePhoton ( int  j)
protected

Definition at line 576 of file HFShowerLibrary.cc.

References newForm, npe, pe, photo, and photon.

Referenced by extrapolate(), and interpolate().

576  {
577  if (newForm)
578  pe.push_back(photo->at(j));
579  else
580  pe.push_back(photon[j]);
581 #ifdef EDM_ML_DEBUG
582  edm::LogVerbatim("HFShower") << "HFShowerLibrary: storePhoton " << j << " npe " << npe << " " << pe[npe];
583 #endif
584  npe++;
585 }
HFShowerPhotonCollection pe
HFShowerPhotonCollection * photo
HFShowerPhotonCollection photon

Member Data Documentation

bool HFShowerLibrary::applyFidCut
private

Definition at line 70 of file HFShowerLibrary.h.

Referenced by fillHits(), and HFShowerLibrary().

double HFShowerLibrary::backProb
private

Definition at line 75 of file HFShowerLibrary.h.

Referenced by fillHits(), and HFShowerLibrary().

double HFShowerLibrary::dphi
private

Definition at line 76 of file HFShowerLibrary.h.

Referenced by fillHits(), and HFShowerLibrary().

TBranch* HFShowerLibrary::emBranch
private

Definition at line 68 of file HFShowerLibrary.h.

Referenced by getRecord(), and HFShowerLibrary().

int HFShowerLibrary::evtPerBin
private

Definition at line 71 of file HFShowerLibrary.h.

Referenced by extrapolate(), HFShowerLibrary(), interpolate(), and loadEventInfo().

std::unique_ptr<HFFibre> HFShowerLibrary::fibre_
private

Definition at line 66 of file HFShowerLibrary.h.

Referenced by fillHits(), and HFShowerLibrary().

std::vector<double> HFShowerLibrary::gpar
private

Definition at line 77 of file HFShowerLibrary.h.

Referenced by fillHits(), getHits(), and HFShowerLibrary().

TBranch * HFShowerLibrary::hadBranch
private

Definition at line 68 of file HFShowerLibrary.h.

Referenced by getRecord(), and HFShowerLibrary().

const HcalDDDSimConstants* HFShowerLibrary::hcalConstant_
private

Definition at line 65 of file HFShowerLibrary.h.

Referenced by HFShowerLibrary().

TFile* HFShowerLibrary::hf
private

Definition at line 67 of file HFShowerLibrary.h.

Referenced by HFShowerLibrary(), and ~HFShowerLibrary().

float HFShowerLibrary::libVers
private

Definition at line 72 of file HFShowerLibrary.h.

Referenced by HFShowerLibrary(), and loadEventInfo().

float HFShowerLibrary::listVersion
private

Definition at line 72 of file HFShowerLibrary.h.

Referenced by HFShowerLibrary(), and loadEventInfo().

bool HFShowerLibrary::newForm
private

Definition at line 70 of file HFShowerLibrary.h.

Referenced by extrapolate(), getRecord(), HFShowerLibrary(), interpolate(), and storePhoton().

int HFShowerLibrary::nMomBin
private

Definition at line 71 of file HFShowerLibrary.h.

Referenced by extrapolate(), fillHits(), HFShowerLibrary(), interpolate(), and loadEventInfo().

int HFShowerLibrary::npe
private

Definition at line 79 of file HFShowerLibrary.h.

Referenced by extrapolate(), fillHits(), interpolate(), and storePhoton().

HFShowerPhotonCollection HFShowerLibrary::pe
private

Definition at line 80 of file HFShowerLibrary.h.

Referenced by extrapolate(), fillHits(), interpolate(), and storePhoton().

HFShowerPhotonCollection* HFShowerLibrary::photo
private
HFShowerPhotonCollection HFShowerLibrary::photon
private

Definition at line 82 of file HFShowerLibrary.h.

Referenced by extrapolate(), getRecord(), interpolate(), and storePhoton().

std::vector<double> HFShowerLibrary::pmom
private

Definition at line 73 of file HFShowerLibrary.h.

Referenced by extrapolate(), fillHits(), HFShowerLibrary(), interpolate(), and loadEventInfo().

double HFShowerLibrary::probMax
private

Definition at line 75 of file HFShowerLibrary.h.

Referenced by fillHits(), and HFShowerLibrary().

double HFShowerLibrary::rMax
private

Definition at line 76 of file HFShowerLibrary.h.

Referenced by HFShowerLibrary(), and rInside().

double HFShowerLibrary::rMin
private

Definition at line 76 of file HFShowerLibrary.h.

Referenced by HFShowerLibrary(), and rInside().

int HFShowerLibrary::totEvents
private

Definition at line 71 of file HFShowerLibrary.h.

Referenced by extrapolate(), getRecord(), HFShowerLibrary(), interpolate(), and loadEventInfo().

bool HFShowerLibrary::v3version
private

Definition at line 70 of file HFShowerLibrary.h.

Referenced by getRecord(), and HFShowerLibrary().

bool HFShowerLibrary::verbose
private

Definition at line 70 of file HFShowerLibrary.h.