CMS 3D CMS Logo

HFShowerLibrary.cc
Go to the documentation of this file.
1 // File: HFShowerLibrary.cc
3 // Description: Shower library for Very forward hadron calorimeter
5 
11 
13 
14 #include "G4VPhysicalVolume.hh"
15 #include "G4NavigationHistory.hh"
16 #include "G4Step.hh"
17 #include "G4Track.hh"
18 #include "Randomize.hh"
19 #include "CLHEP/Units/GlobalSystemOfUnits.h"
20 #include "CLHEP/Units/GlobalPhysicalConstants.h"
21 
22 //#define DebugLog
23 
25  edm::ParameterSet const & p) : fibre(nullptr),hf(nullptr),
26  emBranch(nullptr),
27  hadBranch(nullptr),
28  npe(0) {
29 
30 
31  edm::ParameterSet m_HF = p.getParameter<edm::ParameterSet>("HFShower");
32  probMax = m_HF.getParameter<double>("ProbMax");
33 
34  edm::ParameterSet m_HS= p.getParameter<edm::ParameterSet>("HFShowerLibrary");
35  edm::FileInPath fp = m_HS.getParameter<edm::FileInPath>("FileName");
36  std::string pTreeName = fp.fullPath();
37  backProb = m_HS.getParameter<double>("BackProbability");
38  std::string emName = m_HS.getParameter<std::string>("TreeEMID");
39  std::string hadName = m_HS.getParameter<std::string>("TreeHadID");
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_");
42  std::string branchPost = m_HS.getUntrackedParameter<std::string>("BranchPost","_R.obj");
43  verbose = m_HS.getUntrackedParameter<bool>("Verbosity",false);
44  applyFidCut = m_HS.getParameter<bool>("ApplyFiducialCut");
45 
46  if (pTreeName.find(".") == 0) pTreeName.erase(0,2);
47  const char* nTree = pTreeName.c_str();
48  hf = TFile::Open(nTree);
49 
50  if (!hf->IsOpen()) {
51  edm::LogError("HFShower") << "HFShowerLibrary: opening " << nTree
52  << " failed";
53  throw cms::Exception("Unknown", "HFShowerLibrary")
54  << "Opening of " << pTreeName << " fails\n";
55  } else {
56  edm::LogInfo("HFShower") << "HFShowerLibrary: opening " << nTree
57  << " successfully";
58  }
59 
60  newForm = (branchEvInfo == "");
61  TTree* event(nullptr);
62  if (newForm) event = (TTree *) hf ->Get("HFSimHits");
63  else event = (TTree *) hf ->Get("Events");
64  if (event) {
65  TBranch *evtInfo(nullptr);
66  if (!newForm) {
67  std::string info = branchEvInfo + branchPost;
68  evtInfo = event->GetBranch(info.c_str());
69  }
70  if (evtInfo || newForm) {
71  loadEventInfo(evtInfo);
72  } else {
73  edm::LogError("HFShower") << "HFShowerLibrary: HFShowerLibrayEventInfo"
74  << " Branch does not exist in Event";
75  throw cms::Exception("Unknown", "HFShowerLibrary")
76  << "Event information absent\n";
77  }
78  } else {
79  edm::LogError("HFShower") << "HFShowerLibrary: Events Tree does not "
80  << "exist";
81  throw cms::Exception("Unknown", "HFShowerLibrary")
82  << "Events tree absent\n";
83  }
84 
85  edm::LogInfo("HFShower") << "HFShowerLibrary: Library " << libVers
86  << " ListVersion " << listVersion
87  << " Events Total " << totEvents << " and "
88  << evtPerBin << " per bin";
89  edm::LogInfo("HFShower") << "HFShowerLibrary: Energies (GeV) with "
90  << nMomBin << " bins";
91  for (int i=0; i<nMomBin; i++)
92  edm::LogInfo("HFShower") << "HFShowerLibrary: pmom[" << i << "] = "
93  << pmom[i]/GeV << " GeV";
94 
95  std::string nameBr = branchPre + emName + branchPost;
96  emBranch = event->GetBranch(nameBr.c_str());
97  if (verbose) emBranch->Print();
98  nameBr = branchPre + hadName + branchPost;
99  hadBranch = event->GetBranch(nameBr.c_str());
100  if (verbose) hadBranch->Print();
101 
102  v3version=false;
103  if ( emBranch->GetClassName() == std::string("vector<float>") ) {
104  v3version=true;
105  }
106 
107 
108  edm::LogInfo("HFShower") << "HFShowerLibrary:Branch " << emName
109  << " has " << emBranch->GetEntries()
110  << " entries and Branch " << hadName
111  << " has " << hadBranch->GetEntries()
112  << " entries";
113  edm::LogInfo("HFShower") << "HFShowerLibrary::No packing information -"
114  << " Assume x, y, z are not in packed form";
115 
116  edm::LogInfo("HFShower") << "HFShowerLibrary: Maximum probability cut off "
117  << probMax << " Back propagation of light prob. "
118  << backProb ;
119 
120  fibre = new HFFibre(name, cpv, p);
122  emPDG = epPDG = gammaPDG = 0;
123  pi0PDG = etaPDG = nuePDG = numuPDG = nutauPDG= 0;
125 }
126 
128  if (hf) hf->Close();
129  if (fibre) delete fibre;
130  fibre = nullptr;
131  if (photo) delete photo;
132 }
133 
134 void HFShowerLibrary::initRun(G4ParticleTable * theParticleTable,
135  HcalDDDSimConstants* hcons) {
136 
137  if (fibre) fibre->initRun(hcons);
138 
139  G4String parName;
140  emPDG = theParticleTable->FindParticle(parName="e-")->GetPDGEncoding();
141  epPDG = theParticleTable->FindParticle(parName="e+")->GetPDGEncoding();
142  gammaPDG = theParticleTable->FindParticle(parName="gamma")->GetPDGEncoding();
143  pi0PDG = theParticleTable->FindParticle(parName="pi0")->GetPDGEncoding();
144  etaPDG = theParticleTable->FindParticle(parName="eta")->GetPDGEncoding();
145  nuePDG = theParticleTable->FindParticle(parName="nu_e")->GetPDGEncoding();
146  numuPDG = theParticleTable->FindParticle(parName="nu_mu")->GetPDGEncoding();
147  nutauPDG= theParticleTable->FindParticle(parName="nu_tau")->GetPDGEncoding();
148  anuePDG = theParticleTable->FindParticle(parName="anti_nu_e")->GetPDGEncoding();
149  anumuPDG= theParticleTable->FindParticle(parName="anti_nu_mu")->GetPDGEncoding();
150  anutauPDG= theParticleTable->FindParticle(parName="anti_nu_tau")->GetPDGEncoding();
151  geantinoPDG= theParticleTable->FindParticle(parName="geantino")->GetPDGEncoding();
152 #ifdef DebugLog
153  edm::LogInfo("HFShower") << "HFShowerLibrary: Particle codes for e- = "
154  << emPDG << ", e+ = " << epPDG << ", gamma = "
155  << gammaPDG << ", pi0 = " << pi0PDG << ", eta = "
156  << etaPDG << ", geantino = " << geantinoPDG
157  << "\n nu_e = " << nuePDG << ", nu_mu = "
158  << numuPDG << ", nu_tau = " << nutauPDG
159  << ", anti_nu_e = " << anuePDG << ", anti_nu_mu = "
160  << anumuPDG << ", anti_nu_tau = " << anutauPDG;
161 #endif
162 
163  //Radius (minimum and maximum)
164  std::vector<double> rTable = hcons->getRTableHF();
165  rMin = rTable[0];
166  rMax = rTable[rTable.size()-1];
167  edm::LogInfo("HFShower") << "HFShowerLibrary: rMIN " << rMin/cm
168  << " cm and rMax " << rMax/cm;
169 
170  //Delta phi
171  std::vector<double> phibin = hcons->getPhiTableHF();
172  dphi = phibin[0];
173  edm::LogInfo("HFShower") << "HFShowerLibrary: (Half) Phi Width of wedge "
174  << dphi/deg;
175 
176  //Special Geometry parameters
177  gpar = hcons->getGparHF();
178  edm::LogInfo("HFShower") << "HFShowerLibrary: " <<gpar.size() <<" gpar (cm)";
179  for (unsigned int ig=0; ig<gpar.size(); ig++)
180  edm::LogInfo("HFShower") << "HFShowerLibrary: gpar[" << ig << "] = "
181  << gpar[ig]/cm << " cm";
182 }
183 
184 
185 std::vector<HFShowerLibrary::Hit> HFShowerLibrary::getHits(G4Step * aStep,
186  bool & ok,
187  double weight,
188  bool onlyLong) {
189 
190  G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
191  G4StepPoint * postStepPoint = aStep->GetPostStepPoint();
192  G4Track * track = aStep->GetTrack();
193  // Get Z-direction
194  const G4DynamicParticle *aParticle = track->GetDynamicParticle();
195  G4ThreeVector momDir = aParticle->GetMomentumDirection();
196  // double mom = aParticle->GetTotalMomentum();
197 
198  G4ThreeVector hitPoint = preStepPoint->GetPosition();
199  G4String partType = track->GetDefinition()->GetParticleName();
200  int parCode = track->GetDefinition()->GetPDGEncoding();
201 
202 #ifdef DebugLog
203  G4ThreeVector localPos = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
204  double zoff = localPos.z() + 0.5*gpar[1];
205  // if (zoff < 0) zoff = 0;
206  edm::LogInfo("HFShower") << "HFShowerLibrary: getHits " << partType
207  << " of energy " << pin/GeV << " GeV"
208  << " dir.orts " << momDir.x() << ", " <<momDir.y()
209  << ", " << momDir.z() << " Pos x,y,z = "
210  << hitPoint.x() << "," << hitPoint.y() << ","
211  << hitPoint.z() << " (" << zoff
212  << ") sphi,cphi,stheta,ctheta = " << sin(momDir.phi())
213  << "," << cos(momDir.phi()) << ", " << sin(momDir.theta())
214  << "," << cos(momDir.theta());
215 #endif
216 
217  double tSlice = (postStepPoint->GetGlobalTime())/nanosecond;
218  double pin = preStepPoint->GetTotalEnergy();
219 
220  return fillHits(hitPoint,momDir,parCode,pin,ok,weight,tSlice,onlyLong);
221 }
222 
223 std::vector<HFShowerLibrary::Hit> HFShowerLibrary::fillHits(G4ThreeVector & hitPoint,
224  G4ThreeVector & momDir,
225  int parCode, double pin, bool & ok,
226  double weight, double tSlice,bool onlyLong) {
227 
228  std::vector<HFShowerLibrary::Hit> hit;
229  ok = false;
230  if (parCode == pi0PDG || parCode == etaPDG || parCode == nuePDG ||
231  parCode == numuPDG || parCode == nutauPDG || parCode == anuePDG ||
232  parCode == anumuPDG || parCode == anutauPDG || parCode == geantinoPDG)
233  return hit;
234  ok = true;
235 
236  double pz = momDir.z();
237  double zint = hitPoint.z();
238 
239  // if particle moves from interaction point or "backwards (halo)
240  int backward = 0;
241  if (pz * zint < 0.) backward = 1;
242 
243  double sphi = sin(momDir.phi());
244  double cphi = cos(momDir.phi());
245  double ctheta = cos(momDir.theta());
246  double stheta = sin(momDir.theta());
247 
248  if (parCode == emPDG || parCode == epPDG || parCode == gammaPDG ) {
249  if (pin<pmom[nMomBin-1]) {
250  interpolate(0, pin);
251  } else {
252  extrapolate(0, pin);
253  }
254  } else {
255  if (pin<pmom[nMomBin-1]) {
256  interpolate(1, pin);
257  } else {
258  extrapolate(1, pin);
259  }
260  }
261 
262  int nHit = 0;
263  HFShowerLibrary::Hit oneHit;
264  for (int i = 0; i < npe; i++) {
265  double zv = std::abs(pe[i].z()); // abs local z
266 #ifdef DebugLog
267  edm::LogInfo("HFShower") << "HFShowerLibrary: Hit " << i << " " << pe[i] << " zv " << zv;
268 #endif
269  if (zv <= gpar[1] && pe[i].lambda() > 0 &&
270  (pe[i].z() >= 0 || (zv > gpar[0] && (!onlyLong)))) {
271  int depth = 1;
272  if (onlyLong) {
273  } else if (backward == 0) { // fully valid only for "front" particles
274  if (pe[i].z() < 0) depth = 2;// with "front"-simulated shower lib.
275  } else { // for "backward" particles - almost equal
276  double r = G4UniformRand(); // share between L and S fibers
277  if (r > 0.5) depth = 2;
278  }
279 
280 
281  // Updated coordinate transformation from local
282  // back to global using two Euler angles: phi and theta
283  double pex = pe[i].x();
284  double pey = pe[i].y();
285 
286  double xx = pex*ctheta*cphi - pey*sphi + zv*stheta*cphi;
287  double yy = pex*ctheta*sphi + pey*cphi + zv*stheta*sphi;
288  double zz = -pex*stheta + zv*ctheta;
289 
290  G4ThreeVector pos = hitPoint + G4ThreeVector(xx,yy,zz);
291  zv = std::abs(pos.z()) - gpar[4] - 0.5*gpar[1];
292  G4ThreeVector lpos = G4ThreeVector(pos.x(),pos.y(),zv);
293 
294  zv = fibre->zShift(lpos,depth,0); // distance to PMT !
295 
296  double r = pos.perp();
297  double p = fibre->attLength(pe[i].lambda());
298  double fi = pos.phi();
299  if (fi < 0) fi += twopi;
300  int isect = int(fi/dphi) + 1;
301  isect = (isect + 1) / 2;
302  double dfi = ((isect*2-1)*dphi - fi);
303  if (dfi < 0) dfi = -dfi;
304  double dfir = r * sin(dfi);
305 #ifdef DebugLog
306  edm::LogInfo("HFShower") << "HFShowerLibrary: Position shift " << xx
307  << ", " << yy << ", " << zz << ": " << pos
308  << " R " << r << " Phi " << fi << " Section "
309  << isect << " R*Dfi " << dfir << " Dist " << zv;
310 #endif
311  zz = std::abs(pos.z());
312  double r1 = G4UniformRand();
313  double r2 = G4UniformRand();
314  double r3 = -9999.;
315  if (backward) r3 = G4UniformRand();
316  if (!applyFidCut) dfir += gpar[5];
317 
318 #ifdef DebugLog
319  edm::LogInfo("HFShower") << "HFShowerLibrary: rLimits " << rInside(r)
320  << " attenuation " << r1 <<":" << exp(-p*zv)
321  << " r2 " << r2 << " r3 " << r3 << " rDfi "
322  << gpar[5] << " zz "
323  << zz << " zLim " << gpar[4] << ":"
324  << gpar[4]+gpar[1] << "\n"
325  << " rInside(r) :" << rInside(r)
326  << " r1 <= exp(-p*zv) :" << (r1 <= exp(-p*zv))
327  << " r2 <= probMax :" << (r2 <= probMax*weight)
328  << " r3 <= backProb :" << (r3 <= backProb)
329  << " dfir > gpar[5] :" << (dfir > gpar[5])
330  << " zz >= gpar[4] :" << (zz >= gpar[4])
331  << " zz <= gpar[4]+gpar[1] :"
332  << (zz <= gpar[4]+gpar[1]);
333 #endif
334  if (rInside(r) && r1 <= exp(-p*zv) && r2 <= probMax*weight &&
335  dfir > gpar[5] && zz >= gpar[4] && zz <= gpar[4]+gpar[1] &&
336  r3 <= backProb && (depth != 2 || zz >= gpar[4]+gpar[0])) {
337  oneHit.position = pos;
338  oneHit.depth = depth;
339  oneHit.time = (tSlice+(pe[i].t())+(fibre->tShift(lpos,depth,1)));
340  hit.push_back(oneHit);
341 #ifdef DebugLog
342  edm::LogInfo("HFShower") << "HFShowerLibrary: Final Hit " << nHit
343  <<" position " << (hit[nHit].position)
344  << " Depth " << (hit[nHit].depth) <<" Time "
345  << tSlice << ":" << pe[i].t() << ":"
346  << fibre->tShift(lpos,depth,1) << ":"
347  << (hit[nHit].time);
348 #endif
349  nHit++;
350  }
351 #ifdef DebugLog
352  else LogDebug("HFShower") << "HFShowerLibrary: REJECTED !!!";
353 #endif
354  if (onlyLong && zz >= gpar[4]+gpar[0] && zz <= gpar[4]+gpar[1]) {
355  r1 = G4UniformRand();
356  r2 = G4UniformRand();
357  if (rInside(r) && r1 <= exp(-p*zv) && r2 <= probMax && dfir > gpar[5]){
358  oneHit.position = pos;
359  oneHit.depth = 2;
360  oneHit.time = (tSlice+(pe[i].t())+(fibre->tShift(lpos,2,1)));
361  hit.push_back(oneHit);
362 #ifdef DebugLog
363  edm::LogInfo("HFShower") << "HFShowerLibrary: Final Hit " << nHit
364  << " position " << (hit[nHit].position)
365  << " Depth " << (hit[nHit].depth) <<" Time "
366  << tSlice << ":" << pe[i].t() << ":"
367  << fibre->tShift(lpos,2,1) << ":"
368  << (hit[nHit].time);
369 #endif
370  nHit++;
371  }
372  }
373  }
374  }
375 
376 #ifdef DebugLog
377  edm::LogInfo("HFShower") << "HFShowerLibrary: Total Hits " << nHit
378  << " out of " << npe << " PE";
379 #endif
380  if (nHit > npe && !onlyLong)
381  edm::LogWarning("HFShower") << "HFShowerLibrary: Hit buffer " << npe
382  << " smaller than " << nHit << " Hits";
383  return hit;
384 
385 }
386 
388 
389  if (r >= rMin && r <= rMax) return true;
390  else return false;
391 }
392 
394 
395  int nrc = record-1;
396  photon.clear();
397  photo->clear();
398  if (type > 0) {
399  if (newForm) {
400  if ( !v3version ) {
401  hadBranch->SetAddress(&photo);
402  hadBranch->GetEntry(nrc+totEvents);
403  }
404  else{
405  std::vector<float> t;
406  std::vector<float> *tp=&t;
407  hadBranch->SetAddress(&tp);
408  hadBranch->GetEntry(nrc+totEvents);
409  unsigned int tSize=t.size()/5;
410  photo->reserve(tSize);
411  for ( unsigned int i=0; i<tSize; i++ ) {
412  photo->push_back( HFShowerPhoton( t[i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
413  }
414  }
415  } else {
416  hadBranch->SetAddress(&photon);
417  hadBranch->GetEntry(nrc);
418  }
419  } else {
420  if (newForm) {
421  if (!v3version) {
422  emBranch->SetAddress(&photo);
423  emBranch->GetEntry(nrc);
424  }
425  else{
426  std::vector<float> t;
427  std::vector<float> *tp=&t;
428  emBranch->SetAddress(&tp);
429  emBranch->GetEntry(nrc);
430  unsigned int tSize=t.size()/5;
431  photo->reserve(tSize);
432  for ( unsigned int i=0; i<tSize; i++ ) {
433  photo->push_back( HFShowerPhoton( t[i], t[1*tSize+i], t[2*tSize+i], t[3*tSize+i], t[4*tSize+i] ) );
434  }
435  }
436  } else {
437  emBranch->SetAddress(&photon);
438  emBranch->GetEntry(nrc);
439  }
440  }
441 #ifdef DebugLog
442  int nPhoton = (newForm) ? photo->size() : photon.size();
443  LogDebug("HFShower") << "HFShowerLibrary::getRecord: Record " << record
444  << " of type " << type << " with " << nPhoton
445  << " photons";
446  for (int j = 0; j < nPhoton; j++)
447  if (newForm) LogDebug("HFShower") << "Photon " << j << " " << photo->at(j);
448  else LogDebug("HFShower") << "Photon " << j << " " << photon[j];
449 #endif
450 }
451 
453 
454  if (branch) {
455  std::vector<HFShowerLibraryEventInfo> eventInfoCollection;
456  branch->SetAddress(&eventInfoCollection);
457  branch->GetEntry(0);
458  edm::LogInfo("HFShower") << "HFShowerLibrary::loadEventInfo loads "
459  << " EventInfo Collection of size "
460  << eventInfoCollection.size() << " records";
461  totEvents = eventInfoCollection[0].totalEvents();
462  nMomBin = eventInfoCollection[0].numberOfBins();
463  evtPerBin = eventInfoCollection[0].eventsPerBin();
464  libVers = eventInfoCollection[0].showerLibraryVersion();
465  listVersion = eventInfoCollection[0].physListVersion();
466  pmom = eventInfoCollection[0].energyBins();
467  } else {
468  edm::LogInfo("HFShower") << "HFShowerLibrary::loadEventInfo loads "
469  << " EventInfo from hardwired numbers";
470  nMomBin = 16;
471  evtPerBin = 5000;
473  libVers = 1.1;
474  listVersion = 3.6;
475  pmom = {2,3,5,7,10,15,20,30,50,75,100,150,250,350,500,1000};
476  }
477  for (int i=0; i<nMomBin; i++)
478  pmom[i] *= GeV;
479 }
480 
481 void HFShowerLibrary::interpolate(int type, double pin) {
482 
483 #ifdef DebugLog
484  LogDebug("HFShower") << "HFShowerLibrary:: Interpolate for Energy " <<pin/GeV
485  << " GeV with " << nMomBin << " momentum bins and "
486  << evtPerBin << " entries/bin -- total " << totEvents;
487 #endif
488  int irc[2]={0,0};
489  double w = 0.;
490  double r = G4UniformRand();
491 
492  if (pin<pmom[0]) {
493  w = pin/pmom[0];
494  irc[1] = int(evtPerBin*r) + 1;
495  irc[0] = 0;
496  } else {
497  for (int j=0; j<nMomBin-1; j++) {
498  if (pin >= pmom[j] && pin < pmom[j+1]) {
499  w = (pin-pmom[j])/(pmom[j+1]-pmom[j]);
500  if (j == nMomBin-2) {
501  irc[1] = int(evtPerBin*0.5*r);
502  } else {
503  irc[1] = int(evtPerBin*r);
504  }
505  irc[1] += (j+1)*evtPerBin + 1;
506  r = G4UniformRand();
507  irc[0] = int(evtPerBin*r) + 1 + j*evtPerBin;
508  if (irc[0]<0) {
509  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[0] = "
510  << irc[0] << " now set to 0";
511  irc[0] = 0;
512  } else if (irc[0] > totEvents) {
513  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[0] = "
514  << irc[0] << " now set to "<< totEvents;
515  irc[0] = totEvents;
516  }
517  }
518  }
519  }
520  if (irc[1]<1) {
521  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[1] = "
522  << irc[1] << " now set to 1";
523  irc[1] = 1;
524  } else if (irc[1] > totEvents) {
525  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[1] = "
526  << irc[1] << " now set to "<< totEvents;
527  irc[1] = totEvents;
528  }
529 
530 #ifdef DebugLog
531  LogDebug("HFShower") << "HFShowerLibrary:: Select records " << irc[0]
532  << " and " << irc[1] << " with weights " << 1-w
533  << " and " << w;
534 #endif
535  pe.clear();
536  npe = 0;
537  int npold = 0;
538  for (int ir=0; ir < 2; ir++) {
539  if (irc[ir]>0) {
540  getRecord (type, irc[ir]);
541  int nPhoton = (newForm) ? photo->size() : photon.size();
542  npold += nPhoton;
543  for (int j=0; j<nPhoton; j++) {
544  r = G4UniformRand();
545  if ((ir==0 && r > w) || (ir > 0 && r < w)) {
546  storePhoton (j);
547  }
548  }
549  }
550  }
551 
552  if ((npe > npold || (npold == 0 && irc[0] > 0)) && !(npe == 0 && npold == 0))
553  edm::LogWarning("HFShower") << "HFShowerLibrary: Interpolation Warning =="
554  << " records " << irc[0] << " and " << irc[1]
555  << " gives a buffer of " << npold
556  << " photons and fills " << npe << " *****";
557 #ifdef DebugLog
558  else
559  LogDebug("HFShower") << "HFShowerLibrary: Interpolation == records "
560  << irc[0] << " and " << irc[1] << " gives a "
561  << "buffer of " << npold << " photons and fills "
562  << npe << " PE";
563  for (int j=0; j<npe; j++)
564  LogDebug("HFShower") << "Photon " << j << " " << pe[j];
565 #endif
566 }
567 
568 void HFShowerLibrary::extrapolate(int type, double pin) {
569 
570  int nrec = int(pin/pmom[nMomBin-1]);
571  double w = (pin - pmom[nMomBin-1]*nrec)/pmom[nMomBin-1];
572  nrec++;
573 #ifdef DebugLog
574  LogDebug("HFShower") << "HFShowerLibrary:: Extrapolate for Energy " << pin
575  << " GeV with " << nMomBin << " momentum bins and "
576  << evtPerBin << " entries/bin -- total " << totEvents
577  << " using " << nrec << " records";
578 #endif
579  std::vector<int> irc(nrec);
580 
581  for (int ir=0; ir<nrec; ir++) {
582  double r = G4UniformRand();
583  irc[ir] = int(evtPerBin*0.5*r) +(nMomBin-1)*evtPerBin + 1;
584  if (irc[ir]<1) {
585  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[" << ir
586  << "] = " << irc[ir] << " now set to 1";
587  irc[ir] = 1;
588  } else if (irc[ir] > totEvents) {
589  edm::LogWarning("HFShower") << "HFShowerLibrary:: Illegal irc[" << ir
590  << "] = " << irc[ir] << " now set to "
591  << totEvents;
592  irc[ir] = totEvents;
593 #ifdef DebugLog
594  } else {
595  LogDebug("HFShower") << "HFShowerLibrary::Extrapolation use irc["
596  << ir << "] = " << irc[ir];
597 #endif
598  }
599  }
600 
601  pe.clear();
602  npe = 0;
603  int npold = 0;
604  for (int ir=0; ir<nrec; ir++) {
605  if (irc[ir]>0) {
606  getRecord (type, irc[ir]);
607  int nPhoton = (newForm) ? photo->size() : photon.size();
608  npold += nPhoton;
609  for (int j=0; j<nPhoton; j++) {
610  double r = G4UniformRand();
611  if (ir != nrec-1 || r < w) {
612  storePhoton (j);
613  }
614  }
615 #ifdef DebugLog
616  LogDebug("HFShower") << "HFShowerLibrary: Record [" << ir << "] = "
617  << irc[ir] << " npold = " << npold;
618 #endif
619  }
620  }
621 #ifdef DebugLog
622  LogDebug("HFShower") << "HFShowerLibrary:: uses " << npold << " photons";
623 #endif
624 
625  if (npe > npold || npold == 0)
626  edm::LogWarning("HFShower") << "HFShowerLibrary: Extrapolation Warning == "
627  << nrec << " records " << irc[0] << ", "
628  << irc[1] << ", ... gives a buffer of " <<npold
629  << " photons and fills " << npe
630  << " *****";
631 #ifdef DebugLog
632  else
633  LogDebug("HFShower") << "HFShowerLibrary: Extrapolation == " << nrec
634  << " records " << irc[0] << ", " << irc[1]
635  << ", ... gives a buffer of " << npold
636  << " photons and fills " << npe << " PE";
637  for (int j=0; j<npe; j++)
638  LogDebug("HFShower") << "Photon " << j << " " << pe[j];
639 #endif
640 }
641 
643 
644  if (newForm) pe.push_back(photo->at(j));
645  else pe.push_back(photon[j]);
646 #ifdef DebugLog
647  LogDebug("HFShower") << "HFShowerLibrary: storePhoton " << j << " npe "
648  << npe << " " << pe[npe];
649 #endif
650  npe++;
651 }
652 
653 std::vector<double> HFShowerLibrary::getDDDArray(const std::string & str,
654  const DDsvalues_type & sv,
655  int & nmin) {
656 
657 #ifdef DebugLog
658  LogDebug("HFShower") << "HFShowerLibrary:getDDDArray called for " << str
659  << " with nMin " << nmin;
660 #endif
661  DDValue value(str);
662  if (DDfetch(&sv,value)) {
663 #ifdef DebugLog
664  LogDebug("HFShower") << value;
665 #endif
666  const std::vector<double> & fvec = value.doubles();
667  int nval = fvec.size();
668  if (nmin > 0) {
669  if (nval < nmin) {
670  edm::LogError("HFShower") << "HFShowerLibrary : # of " << str
671  << " bins " << nval << " < " << nmin
672  << " ==> illegal";
673  throw cms::Exception("Unknown", "HFShowerLibrary")
674  << "nval < nmin for array " << str << "\n";
675  }
676  } else {
677  if (nval < 2) {
678  edm::LogError("HFShower") << "HFShowerLibrary : # of " << str
679  << " bins " << nval << " < 2 ==> illegal"
680  << " (nmin=" << nmin << ")";
681  throw cms::Exception("Unknown", "HFShowerLibrary")
682  << "nval < 2 for array " << str << "\n";
683  }
684  }
685  nmin = nval;
686 
687  return fvec;
688  } else {
689  edm::LogError("HFShower") << "HFShowerLibrary : cannot get array " << str;
690  throw cms::Exception("Unknown", "HFShowerLibrary")
691  << "cannot get array " << str << "\n";
692  }
693 }
#define LogDebug(id)
double tShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
Definition: HFFibre.cc:112
std::vector< Hit > fillHits(G4ThreeVector &p, G4ThreeVector &v, int parCode, double parEnergy, bool &ok, double weight, double time, bool onlyLong=false)
type
Definition: HCALResponse.h:21
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
Definition: DDValue.cc:140
static const TGPicture * info(bool iBackgroundIsBlack)
const double GeV
Definition: MathUtil.h:16
void getRecord(int, int)
const double w
Definition: UKUtility.cc:23
void initRun(HcalDDDSimConstants *)
Definition: HFFibre.cc:77
JetCorrectorParameters::Record record
Definition: classes.h:7
std::vector< Hit > getHits(G4Step *aStep, bool &ok, double weight, bool onlyLong=false)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
double attLength(double lambda)
Definition: HFFibre.cc:94
HFShowerPhotonCollection pe
double zShift(const G4ThreeVector &point, int depth, int fromEndAbs=0)
Definition: HFFibre.cc:124
Definition: weight.py:1
#define nullptr
type of data representation of DDCompactView
Definition: DDCompactView.h:90
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
HFShowerLibrary(std::string &name, const DDCompactView &cpv, edm::ParameterSet const &p)
std::vector< HFShowerPhoton > HFShowerPhotonCollection
const std::vector< double > & getRTableHF() const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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::...
Definition: DDsvalues.h:20
void loadEventInfo(TBranch *)
const std::vector< double > & getPhiTableHF() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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
TBranch * emBranch
const std::vector< double > & getGparHF() const
std::vector< double > pmom
G4ThreeVector position
void extrapolate(int, double)
void storePhoton(int j)
HFShowerPhotonCollection photon
bool rInside(double r)
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
void interpolate(int, double)
TBranch * hadBranch