ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
LArG4ShowerLibFunctions.EtaEnergyShowerLib Class Reference
Collaboration diagram for LArG4ShowerLibFunctions.EtaEnergyShowerLib:

Public Member Functions

def __init__ (self)
 
def scaleEnergy (self, scalefactor)
 
def truncate (self, truncate)
 
def fromLibs (self, libs)
 
def moveEta (self, oldEta, newEta)
 
def removeEta (self, eta)
 
def readFromFile (self, filename)
 
def writeToFile (self, filename)
 
def printInfo (self)
 
def drawHits (self)
 

Public Attributes

 library
 
 detector
 
 particle
 
 release
 
 geometry
 
 geant
 
 phys
 
 comment
 
 mineta
 
 maxeta
 

Detailed Description

Definition at line 237 of file LArG4ShowerLibFunctions.py.

Constructor & Destructor Documentation

◆ __init__()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.__init__ (   self)

Definition at line 238 of file LArG4ShowerLibFunctions.py.

238  def __init__(self) :
239  self.library = {} # key (float) - eta, value (list) - list of StoredEnergyShower objs
240  self.detector= ""
241  self.particle= ""
242  self.release= ""
243  self.geometry= ""
244  self.geant= ""
245  self.phys= ""
246  self.comment= ""

Member Function Documentation

◆ drawHits()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.drawHits (   self)

Definition at line 544 of file LArG4ShowerLibFunctions.py.

544  def drawHits(self):
545  from ROOT import TH3F
546  from math import sqrt,copysign,log10
547  hits = TH3F("HITS","Hits Distrib",50,1,1000,101,-300,300,100,0,500)
548  containmentZ = TH3F("CONTZ","ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
549  containmentR = TH3F("CONTR","ContR Distrib",50,1,1000,101,-300,300,100,0,500)
550  for etabin in self.library.values():
551  for storedShower in etabin :
552  containmentR.Fill(log10(storedShower.egen)*333,storedShower.rsize,storedShower.zsize,10)
553  containmentR.Fill(log10(storedShower.egen)*333,-storedShower.rsize,storedShower.zsize,10)
554  containmentZ.Fill(log10(storedShower.egen)*333,0,storedShower.zsize,10)
555  for hit in storedShower.shower :
556  hits.Fill(log10(storedShower.egen)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
557  return hits,containmentZ,containmentR
558 

◆ fromLibs()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.fromLibs (   self,
  libs 
)

Definition at line 267 of file LArG4ShowerLibFunctions.py.

267  def fromLibs(self,libs) :
268  for lib in libs :
269  if not isinstance(lib,self.__class__):
270  print ("ERROR: Different types of libs")
271  return False
272  self.detector = libs[0].detector
273  self.particle = libs[0].particle
274  self.release = libs[0].release
275  self.geometry = libs[0].geometry
276  self.geant = libs[0].geant
277  self.phys = libs[0].phys
278  self.mineta = libs[0].mineta
279  self.maxeta = libs[0].maxeta
280  self.comment = libs[0].comment
281  etas = set(libs[0].library.keys())
282  for lib in libs :
283  if ( self.detector != lib.detector or
284  self.particle != lib.particle or
285  self.release != lib.release or
286  self.geometry != lib.geometry or
287  self.geant != lib.geant or
288  self.phys != lib.phys or
289  self.mineta != lib.mineta or
290  self.maxeta != lib.maxeta or
291  etas != set(lib.library.keys()) ) :
292  print ("ERROR: DIFFERENT LIBS!!!")
293  return False
294  for lib in libs :
295  for k,v in lib.library.items():
296  self.library.setdefault(k,set()).update(v)
297  for k,v in self.library.items():
298  self.library[k] = list(v)
299  return True

◆ moveEta()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.moveEta (   self,
  oldEta,
  newEta 
)

Definition at line 300 of file LArG4ShowerLibFunctions.py.

300  def moveEta(self,oldEta,newEta) :
301  if not (oldEta in self.library.keys()) :
302  return False
303  self.library[newEta] = self.library.pop(oldEta)
304  return True

◆ printInfo()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.printInfo (   self)

Definition at line 477 of file LArG4ShowerLibFunctions.py.

477  def printInfo(self) :
478  print ("VERSION: EtaEnergyLib","PARTICLE:",self.particle,"DETECTOR:",self.detector)
479  print (self.release, self.geometry, self.geant, self.phys)
480  print (self.comment)
481  ebins = [1,2,5,10,20,50,100,200,500,1000]
482  etas = sorted(self.library.keys())
483  print ("Number of etabins:",str(len(etas)))
484  print ("MinEta:",self.mineta,"MaxEta:",self.maxeta)
485  fstot = 0
486  for eta in etas :
487  fstot +=len(self.library[eta])
488  print ("Number of showers:",str(fstot))
489  print ("-"*(12+len(ebins)*8)) #horizontal line
490  infostr = "|etas|ebins|"
491  for ebin in ebins : #header for energy bins
492  infostr += ("<%d" %ebin).rjust(7) #str(ebin).rjust(7)
493  infostr += "|"
494  print (infostr)
495  print ("-"*(12+len(ebins)*8)) #horizontal line
496  for etalow,etahigh in zip(etas,(etas[1:] + [self.maxeta])) : #looping over eta bins
497  prevebin = 0
498  erec = {}
499  egen = {}
500  hits = {}
501  count = {}
502  for ebin in ebins : # for all energy bins
503  count[ebin] = 0
504  erec[ebin] = 0.
505  egen[ebin] = 0.
506  hits[ebin] = 0.
507  for shower in self.library[etalow] :
508  if (shower.egen <= ebin) and (shower.egen > prevebin) :
509  count[ebin] += 1
510  egenshow = shower.egen
511  erecshow = 0
512  for hit in shower.shower :
513  erecshow += hit.e
514  erec[ebin] += erecshow
515  egen[ebin] += egenshow
516  hits[ebin] += len(shower.shower)
517  if (count[ebin] > 0) :
518  hits[ebin] /= count[ebin]
519  prevebin = ebin
520  infostr = "|#" # |
521  infostr+= str(round(etalow,5)).rjust(9) # | eta header
522  infostr+= "|" # |\
523  infostr2 = "|Hits"
524  infostr2+= str(round(etahigh,3)).rjust(6) # | eta header
525  infostr2+= "|" # |
526  infostr3 = "|ErecEgen"
527  infostr3+= " ".rjust(2) # | eta header
528  infostr3+= "|" # |
529  for ebin in ebins :
530  infostr+= str(count[ebin]).rjust(7) #print the number of showers
531  if (egen[ebin] > 0) :
532  infostr2+= ("%.2f" %(hits[ebin])).rjust(7)
533  infostr3+= ("%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
534  else :
535  infostr2+= ("%.2f" %(hits[ebin])).rjust(7)
536  infostr3+= "0.0".rjust(7) #else print "xxx"
537  infostr+="|"
538  infostr2+="|"
539  infostr3+="|"
540  print (infostr)
541  print (infostr2)
542  print (infostr3)
543  print ("-"*(12+len(ebins)*8)) #horizontal line

◆ readFromFile()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.readFromFile (   self,
  filename 
)

Definition at line 310 of file LArG4ShowerLibFunctions.py.

310  def readFromFile(self,filename) :
311  from ROOT import TFile
312  #from sets import Set
313  tfile = TFile(filename)
314  try:
315  ver = int(tfile.Get("version").GetVal())
316  except Exception:
317  print ("Not an EtaEnergyLib: Broken file")
318  tfile.Close()
319  return False
320 
321  if (ver != 1) : #<<<<<<<<<<<<<<<<<<<<<<-------------- lib ver
322  print ("Not an EtaEnergyLib")
323  tfile.Close()
324  return False
325  meta = tfile.Get("meta")
326  libr = tfile.Get("library")
327 
328  for event in meta :
329  self.detector=str(event.detector)
330  self.particle=str(event.particle)
331  self.release=str(event.release)
332  self.geometry=str(event.geometry)
333  self.geant=str(event.geantVersion)
334  self.phys=str(event.physicsList)
335  self.comment=str(event.comment)
336 
337  state = 0
338  lastShower = False
339 
340  for event in libr : #this is quite unclear, but easy to implement
341  if (state == 0) : #eta bin header
342  showersInCurEta = event.x
343  curEta = round(event.y,4)
344  self.mineta = event.z
345  self.maxeta = event.e
346  self.library[curEta] = []
347  if (showersInCurEta > 0) :
348  state = 1 #go to shower header
349  elif (state == 1) : #shower header
350  hitsInCurShower = event.x
351  rSize = event.y
352  zSize = event.z
353  genEnergy = event.e
354  showersInCurEta -= 1
355  if (showersInCurEta == 0) : #last shower
356  lastShower = True
357  curShower = StoredEnergyShower()
358  curShower.egen = genEnergy
359  curShower.rsize = rSize
360  curShower.zsize = zSize
361  #curShower["hits"] = []
362  if (hitsInCurShower > 0) :
363  state = 2 #go to hits
364  else : #empty shower
365  self.library[curEta].append(curShower)
366  if (lastShower) : #special case of last shower in bin being the empty one
367  lastShower = False
368  state = 0 #next bin
369  elif (state == 2) :
370  hit = FourVector()
371  hit.e = event.e
372  hit.x = event.x
373  hit.y = event.y
374  hit.z = event.z
375  hit.time = event.time
376  curShower.shower.append(hit)
377  hitsInCurShower -= 1
378  if (hitsInCurShower == 0) : #last hit
379  self.library[curEta].append(curShower)
380  if (lastShower) : # end of eta bin
381  lastShower = False
382  state = 0
383  else : #not yet
384  state = 1
385  tfile.Close()
386  if (state != 0) :
387  print ("FILE CORRUPTED!!")
388  return False
389  return True

◆ removeEta()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.removeEta (   self,
  eta 
)

Definition at line 305 of file LArG4ShowerLibFunctions.py.

305  def removeEta(self,eta) :
306  if not (eta in self.library.keys()) :
307  return False
308  self.library.pop(eta)
309  return True

◆ scaleEnergy()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.scaleEnergy (   self,
  scalefactor 
)

Definition at line 247 of file LArG4ShowerLibFunctions.py.

247  def scaleEnergy(self,scalefactor) :
248  for etabin in self.library.values():
249  for storedShower in etabin :
250  for hit in storedShower.shower :
251  hit.e *= scalefactor
252  self.comment += " SCALED: "+str(scalefactor)

◆ truncate()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.truncate (   self,
  truncate 
)

Definition at line 253 of file LArG4ShowerLibFunctions.py.

253  def truncate(self,truncate) :
254  showers = []
255  for eta,etabin in self.library.items():
256  for storedShower in etabin :
257  showers += [(eta,storedShower)]
258  if len(showers) <= truncate :
259  print ("WARNING: Size of the library is already less:",truncate,"<",len(showers))
260  return
261  from random import randint
262  while (len(showers) > truncate) :
263  rand = randint(0,len(showers)-1)
264  self.library[showers[rand][0]].remove(showers[rand][1])
265  del showers[rand]
266  return

◆ writeToFile()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.writeToFile (   self,
  filename 
)

Definition at line 390 of file LArG4ShowerLibFunctions.py.

390  def writeToFile(self,filename) :
391  from ROOT import TFile,TTree,TParameter
392  from ROOT import gROOT, addressof
393  gROOT.ProcessLine(
394  "struct MyMetaStruct {\
395  Char_t detector[40];\
396  Char_t release[40];\
397  Char_t geometry[40];\
398  Char_t geant[40];\
399  Char_t phys[40];\
400  Char_t comment[400];\
401  Int_t particle;\
402  };" )
403  from ROOT import MyMetaStruct
404  gROOT.ProcessLine(
405  "struct MyStruct {\
406  Float_t x;\
407  Float_t y;\
408  Float_t z;\
409  Float_t e;\
410  Float_t time;\
411  };" )
412  from ROOT import MyStruct
413 
414  tfile = TFile(filename,"RECREATE")
415 
416  ver = TParameter(int)("version",1) #<<<<<<<<<<<<<<<<<<<<<<-------------- lib ver
417  ver.Write("version")
418 
419  meta = TTree()
420  libr = TTree()
421 
422  mmstruct = MyMetaStruct()
423 
424  mmstruct.detector = "%s" % (str(self.detector))
425  mmstruct.particle = int(self.particle)
426  mmstruct.release = "%s" % (str(self.release))
427  mmstruct.geometry = "%s" % (str(self.geometry))
428  mmstruct.geant = "%s" % (str(self.geant))
429  mmstruct.phys = "%s" % (str(self.phys))
430  mmstruct.comment = "%s" % (str(self.comment))
431 
432  meta.Branch("detector",addressof(mmstruct,"detector"),"detector/C")
433  meta.Branch("particle",addressof(mmstruct,"particle"),"particle/I")
434  meta.Branch("release",addressof(mmstruct,"release"),"release/C")
435  meta.Branch("geometry",addressof(mmstruct,"geometry"),"geometry/C")
436  meta.Branch("geantVersion",addressof(mmstruct,"geant"),"geantVersion/C")
437  meta.Branch("physicsList",addressof(mmstruct,"phys"),"physicsList/C")
438  meta.Branch("comment",addressof(mmstruct,"comment"),"physicsList/C")
439 
440  meta.Fill()
441 
442  mstruct = MyStruct()
443 
444  libr.Branch("x",addressof(mstruct,"x"),"x/F")
445  libr.Branch("y",addressof(mstruct,"y"),"y/F")
446  libr.Branch("z",addressof(mstruct,"z"),"z/F")
447  libr.Branch("e",addressof(mstruct,"e"),"e/F")
448  libr.Branch("time",addressof(mstruct,"time"),"time/F")
449 
450  etas = self.library.keys()
451 
452  for eta in sorted(etas) :
453  mstruct.x = len(self.library[eta])
454  mstruct.y = eta
455  mstruct.z = self.mineta
456  mstruct.e = self.maxeta
457  mstruct.time = 0
458  libr.Fill()
459  self.library[eta].sort(key=lambda x: x.egen)
460  for storedShower in self.library[eta] :
461  mstruct.x = len(storedShower.shower)
462  mstruct.y = storedShower.rsize
463  mstruct.z = storedShower.zsize
464  mstruct.e = storedShower.egen
465  mstruct.time = 0
466  libr.Fill()
467  for hit in storedShower.shower:
468  mstruct.e = hit.e
469  mstruct.x = hit.x
470  mstruct.y = hit.y
471  mstruct.z = hit.z
472  mstruct.time = hit.time
473  libr.Fill()
474  meta.Write("meta")
475  libr.Write("library")
476  tfile.Close()

Member Data Documentation

◆ comment

LArG4ShowerLibFunctions.EtaEnergyShowerLib.comment

Definition at line 246 of file LArG4ShowerLibFunctions.py.

◆ detector

LArG4ShowerLibFunctions.EtaEnergyShowerLib.detector

Definition at line 240 of file LArG4ShowerLibFunctions.py.

◆ geant

LArG4ShowerLibFunctions.EtaEnergyShowerLib.geant

Definition at line 244 of file LArG4ShowerLibFunctions.py.

◆ geometry

LArG4ShowerLibFunctions.EtaEnergyShowerLib.geometry

Definition at line 243 of file LArG4ShowerLibFunctions.py.

◆ library

LArG4ShowerLibFunctions.EtaEnergyShowerLib.library

Definition at line 239 of file LArG4ShowerLibFunctions.py.

◆ maxeta

LArG4ShowerLibFunctions.EtaEnergyShowerLib.maxeta

Definition at line 279 of file LArG4ShowerLibFunctions.py.

◆ mineta

LArG4ShowerLibFunctions.EtaEnergyShowerLib.mineta

Definition at line 278 of file LArG4ShowerLibFunctions.py.

◆ particle

LArG4ShowerLibFunctions.EtaEnergyShowerLib.particle

Definition at line 241 of file LArG4ShowerLibFunctions.py.

◆ phys

LArG4ShowerLibFunctions.EtaEnergyShowerLib.phys

Definition at line 245 of file LArG4ShowerLibFunctions.py.

◆ release

LArG4ShowerLibFunctions.EtaEnergyShowerLib.release

Definition at line 242 of file LArG4ShowerLibFunctions.py.


The documentation for this class was generated from the following file:
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
systematicsTool.readFromFile
def readFromFile(filename, regexFilter=None, regexVeto=None)
Definition: systematicsTool.py:789
systematicsTool.writeToFile
def writeToFile(histDict, fOut)
Definition: systematicsTool.py:1035
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
WriteBchToCool.update
update
Definition: WriteBchToCool.py:67
LArG4ShowerLibProcessing.truncate
truncate
Definition: LArG4ShowerLibProcessing.py:39