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 236 of file LArG4ShowerLibFunctions.py.

Constructor & Destructor Documentation

◆ __init__()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.__init__ (   self)

Definition at line 237 of file LArG4ShowerLibFunctions.py.

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

Member Function Documentation

◆ drawHits()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.drawHits (   self)

Definition at line 543 of file LArG4ShowerLibFunctions.py.

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

◆ fromLibs()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.fromLibs (   self,
  libs 
)

Definition at line 266 of file LArG4ShowerLibFunctions.py.

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

◆ moveEta()

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

Definition at line 299 of file LArG4ShowerLibFunctions.py.

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

◆ printInfo()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.printInfo (   self)

Definition at line 476 of file LArG4ShowerLibFunctions.py.

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

◆ readFromFile()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.readFromFile (   self,
  filename 
)

Definition at line 309 of file LArG4ShowerLibFunctions.py.

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

◆ removeEta()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.removeEta (   self,
  eta 
)

Definition at line 304 of file LArG4ShowerLibFunctions.py.

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

◆ scaleEnergy()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.scaleEnergy (   self,
  scalefactor 
)

Definition at line 246 of file LArG4ShowerLibFunctions.py.

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

◆ truncate()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.truncate (   self,
  truncate 
)

Definition at line 252 of file LArG4ShowerLibFunctions.py.

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

◆ writeToFile()

def LArG4ShowerLibFunctions.EtaEnergyShowerLib.writeToFile (   self,
  filename 
)

Definition at line 389 of file LArG4ShowerLibFunctions.py.

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

Member Data Documentation

◆ comment

LArG4ShowerLibFunctions.EtaEnergyShowerLib.comment

Definition at line 245 of file LArG4ShowerLibFunctions.py.

◆ detector

LArG4ShowerLibFunctions.EtaEnergyShowerLib.detector

Definition at line 239 of file LArG4ShowerLibFunctions.py.

◆ geant

LArG4ShowerLibFunctions.EtaEnergyShowerLib.geant

Definition at line 243 of file LArG4ShowerLibFunctions.py.

◆ geometry

LArG4ShowerLibFunctions.EtaEnergyShowerLib.geometry

Definition at line 242 of file LArG4ShowerLibFunctions.py.

◆ library

LArG4ShowerLibFunctions.EtaEnergyShowerLib.library

Definition at line 238 of file LArG4ShowerLibFunctions.py.

◆ maxeta

LArG4ShowerLibFunctions.EtaEnergyShowerLib.maxeta

Definition at line 278 of file LArG4ShowerLibFunctions.py.

◆ mineta

LArG4ShowerLibFunctions.EtaEnergyShowerLib.mineta

Definition at line 277 of file LArG4ShowerLibFunctions.py.

◆ particle

LArG4ShowerLibFunctions.EtaEnergyShowerLib.particle

Definition at line 240 of file LArG4ShowerLibFunctions.py.

◆ phys

LArG4ShowerLibFunctions.EtaEnergyShowerLib.phys

Definition at line 244 of file LArG4ShowerLibFunctions.py.

◆ release

LArG4ShowerLibFunctions.EtaEnergyShowerLib.release

Definition at line 241 of file LArG4ShowerLibFunctions.py.


The documentation for this class was generated from the following file:
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
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:808
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
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:71
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
LArG4ShowerLibProcessing.truncate
truncate
Definition: LArG4ShowerLibProcessing.py:38