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

Public Member Functions

def __init__ (self)
 
def scaleEnergy (self, scalefactor)
 
def truncate (self, truncate)
 
def moveDist (self, oldDist, newDist)
 
def removeDist (self, dist)
 
def fromLibs (self, libs)
 
def readFromFile (self, filename)
 
def writeToFile (self, filename)
 
def printInfo (self)
 
def drawHits (self)
 

Public Attributes

 library
 
 detector
 
 particle
 
 release
 
 geometry
 
 geant
 
 phys
 
 comment
 
 xrod_cent
 
 yrod_cent
 
 step
 

Detailed Description

Definition at line 559 of file LArG4ShowerLibFunctions.py.

Constructor & Destructor Documentation

◆ __init__()

def LArG4ShowerLibFunctions.FCALDistShowerLib.__init__ (   self)

Definition at line 560 of file LArG4ShowerLibFunctions.py.

560  def __init__(self) :
561  self.library = {} # key (float) - dist, value (list) - list of StoredEnergyShower objs
562  self.detector= ""
563  self.particle= ""
564  self.release= ""
565  self.geometry= ""
566  self.geant= ""
567  self.phys= ""
568  self.comment= ""
569  self.xrod_cent = 0.0
570  self.yrod_cent = 0.0
571  self.step = 0.0

Member Function Documentation

◆ drawHits()

def LArG4ShowerLibFunctions.FCALDistShowerLib.drawHits (   self)

Definition at line 880 of file LArG4ShowerLibFunctions.py.

880  def drawHits(self):
881  from ROOT import TH3F
882  from math import sqrt,copysign,log10
883  hits = TH3F("HITS","Hits Distrib",50,1,1000,101,-300,300,100,0,500)
884  containmentZ = TH3F("CONTZ","ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
885  containmentR = TH3F("CONTR","ContR Distrib",50,1,1000,101,-300,300,100,0,500)
886  for distbin in self.library.values():
887  for storedShower in distbin :
888  containmentR.Fill(log10(storedShower.egen)*333,storedShower.rsize,storedShower.zsize,10)
889  containmentR.Fill(log10(storedShower.egen)*333,-storedShower.rsize,storedShower.zsize,10)
890  containmentZ.Fill(log10(storedShower.egen)*333,0,storedShower.zsize,10)
891  for hit in storedShower.shower :
892  hits.Fill(log10(storedShower.egen)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
893  return hits,containmentZ,containmentR
894 

◆ fromLibs()

def LArG4ShowerLibFunctions.FCALDistShowerLib.fromLibs (   self,
  libs 
)

Definition at line 602 of file LArG4ShowerLibFunctions.py.

602  def fromLibs(self,libs) :
603  for lib in libs :
604  if not isinstance(lib,self.__class__):
605  print ("ERROR: Different types of libs")
606  return False
607  self.detector = libs[0].detector
608  self.particle = libs[0].particle
609  self.release = libs[0].release
610  self.geometry = libs[0].geometry
611  self.geant = libs[0].geant
612  self.phys = libs[0].phys
613  self.comment = libs[0].comment
614  self.xrod_cent = libs[0].xrod_cent
615  self.yrod_cent = libs[0].yrod_cent
616  self.step = libs[0].step
617  dists = set(libs[0].library.keys())
618  for lib in libs :
619  if ( self.detector != lib.detector or
620  self.particle != lib.particle or
621  self.release != lib.release or
622  self.geometry != lib.geometry or
623  self.geant != lib.geant or
624  self.phys != lib.phys or
625  self.xrod_cent != lib.xrod_cent or
626  self.yrod_cent != lib.yrod_cent or
627  self.step != lib.step or
628  dists != set(lib.library.keys()) ) :
629  print ("ERROR: DIFFERENT LIBS!!!")
630  return False
631  for lib in libs :
632  for k,v in lib.library.items():
633  self.library.setdefault(k,set()).update(v)
634  for k,v in self.library.items():
635  self.library[k] = list(v)
636  return True

◆ moveDist()

def LArG4ShowerLibFunctions.FCALDistShowerLib.moveDist (   self,
  oldDist,
  newDist 
)

Definition at line 592 of file LArG4ShowerLibFunctions.py.

592  def moveDist(self,oldDist,newDist) :
593  if not (oldDist in self.library.keys()) :
594  return False
595  self.library[newDist] = self.library.pop(oldDist)
596  return True

◆ printInfo()

def LArG4ShowerLibFunctions.FCALDistShowerLib.printInfo (   self)

Definition at line 813 of file LArG4ShowerLibFunctions.py.

813  def printInfo(self) :
814  print ("VERSION: FCALDistEnergyLib","PARTICLE:",self.particle,"DETECTOR:",self.detector)
815  print (self.release, self.geometry, self.geant, self.phys)
816  print ("xrodcent:",self.xrod_cent,"yrodcent:",self.yrod_cent,"step:",self.step)
817  print (self.comment)
818  ebins = [1,2,5,10,20,50,100,200,500,1000]
819  dists = sorted(self.library.keys())
820  print ("Number of etabins:",str(len(dists)))
821  fstot = 0
822  for dist in dists :
823  fstot +=len(self.library[dist])
824  print ("Number of showers:",str(fstot))
825  print ("-"*(13+len(ebins)*8)) #horizontal line
826  infostr = "|dists|ebins|"
827  for ebin in ebins : #header for energy bins
828  infostr += ("<%d" %ebin).rjust(7) #str(ebin).rjust(7)
829  infostr += "|"
830  print (infostr)
831  print ("-"*(13+len(ebins)*8)) #horizontal line
832  for distlow,disthigh in zip(dists,(dists[1:] + [4.5])) : #looping over eta bins
833  prevebin = 0
834  erec = {}
835  egen = {}
836  hits = {}
837  count = {}
838  for ebin in ebins : # for all energy bins
839  count[ebin] = 0
840  erec[ebin] = 0.
841  egen[ebin] = 0.
842  hits[ebin] = 0.
843  for shower in self.library[distlow] :
844  if (shower.egen <= ebin) and (shower.egen > prevebin) :
845  count[ebin] += 1
846  egenshow = shower.egen
847  erecshow = 0
848  for hit in shower.shower :
849  erecshow += hit.e
850  erec[ebin] += erecshow
851  egen[ebin] += egenshow
852  hits[ebin] += len(shower.shower)
853  if (count[ebin] > 0) :
854  hits[ebin] /= count[ebin]
855  prevebin = ebin
856  infostr = "|#" # |
857  infostr+= str(round(distlow,5)).rjust(10) # | eta header
858  infostr+= "|" # |\
859  infostr2 = "|Hits"
860  infostr2+= str(round(disthigh,3)).rjust(7) # | eta header
861  infostr2+= "|" # |
862  infostr3 = "|ErecEgen"
863  infostr3+= " ".rjust(3) # | eta header
864  infostr3+= "|" # |
865  for ebin in ebins :
866  infostr+= str(count[ebin]).rjust(7) #print the number of showers
867  if (egen[ebin] > 0) :
868  infostr2+= ("%.2f" %(hits[ebin])).rjust(7)
869  infostr3+= ("%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
870  else :
871  infostr2+= ("%.2f" %(hits[ebin])).rjust(7)
872  infostr3+= "0.0".rjust(7) #else print "xxx"
873  infostr+="|"
874  infostr2+="|"
875  infostr3+="|"
876  print (infostr)
877  print (infostr2)
878  print (infostr3)
879  print ("-"*(12+len(ebins)*8)) #horizontal line

◆ readFromFile()

def LArG4ShowerLibFunctions.FCALDistShowerLib.readFromFile (   self,
  filename 
)

Definition at line 637 of file LArG4ShowerLibFunctions.py.

637  def readFromFile(self,filename) :
638  from ROOT import TFile
639  #from sets import Set
640  tfile = TFile(filename)
641  try:
642  ver = int(tfile.Get("version").GetVal())
643  except Exception:
644  print ("Not an FCALDistEnergyLib: Broken file")
645  tfile.Close()
646  return False
647  if (ver != 4) : #<<<<<<<<<<<<<<<<<<<<<<-------------- lib ver
648  print ("Not an FCALDistEnergyLib")
649  tfile.Close()
650  return False
651  meta = tfile.Get("meta")
652  libr = tfile.Get("library")
653 
654  for event in meta :
655  self.detector=str(event.detector)
656  self.particle=str(event.particle)
657  self.release=str(event.release)
658  self.geometry=str(event.geometry)
659  self.geant=str(event.geantVersion)
660  self.phys=str(event.physicsList)
661  self.comment=str(event.comment)
662 
663  state = -1
664  lastShower = False
665 
666  for event in libr : #this is quite unclear, but easy to implement
667  if (state == -1) : #library header (calculator parameters)
668  self.xrod_cent = event.x
669  self.yrod_cent = event.y
670  self.step = event.z
671  state = 0
672  elif (state == 0) : #eta bin header
673  showersInCurDist = event.x
674  curDist = round(event.y,4)
675  self.library[curDist] = []
676  if (showersInCurDist > 0) :
677  state = 1 #go to shower header
678  elif (state == 1) : #shower header
679  hitsInCurShower = event.x
680  rSize = event.y
681  zSize = event.z
682  genEnergy = event.e
683  showersInCurDist -= 1
684  if (showersInCurDist == 0) : #last shower
685  lastShower = True
686  curShower = StoredEnergyShower()
687  curShower.egen = genEnergy
688  curShower.rsize = rSize
689  curShower.zsize = zSize
690  #curShower["hits"] = []
691  if (hitsInCurShower > 0) :
692  state = 2 #go to hits
693  else : #empty shower
694  self.library[curDist].append(curShower)
695  if (lastShower) : #special case of last shower in bin being the empty one
696  lastShower = False
697  state = 0 #next bin
698  elif (state == 2) :
699  hit = FourVector()
700  hit.e = event.e
701  hit.x = event.x
702  hit.y = event.y
703  hit.z = event.z
704  hit.time = event.time
705  curShower.shower.append(hit)
706  hitsInCurShower -= 1
707  if (hitsInCurShower == 0) : #last hit
708  self.library[curDist].append(curShower)
709  if (lastShower) : # end of eta bin
710  lastShower = False
711  state = 0
712  else : #not yet
713  state = 1
714  tfile.Close()
715  if (state != 0) :
716  print ("FILE CORRUPTED!!")
717  return False
718  return True

◆ removeDist()

def LArG4ShowerLibFunctions.FCALDistShowerLib.removeDist (   self,
  dist 
)

Definition at line 597 of file LArG4ShowerLibFunctions.py.

597  def removeDist(self,dist) :
598  if not (dist in self.library.keys()) :
599  return False
600  self.library.pop(dist)
601  return True

◆ scaleEnergy()

def LArG4ShowerLibFunctions.FCALDistShowerLib.scaleEnergy (   self,
  scalefactor 
)

Definition at line 572 of file LArG4ShowerLibFunctions.py.

572  def scaleEnergy(self,scalefactor) :
573  for distbin in self.library.values():
574  for storedShower in distbin :
575  for hit in storedShower.shower :
576  hit.e *= scalefactor
577  self.comment += " SCALED: "+str(scalefactor)

◆ truncate()

def LArG4ShowerLibFunctions.FCALDistShowerLib.truncate (   self,
  truncate 
)

Definition at line 578 of file LArG4ShowerLibFunctions.py.

578  def truncate(self,truncate) :
579  showers = []
580  for dist,distbin in self.library.items():
581  for storedShower in distbin :
582  showers += [(dist,storedShower)]
583  if len(showers) <= truncate :
584  print ("WARNING: Size of the library is already less:",truncate,"<",len(showers))
585  return
586  from random import randint
587  while (len(showers) > truncate) :
588  rand = randint(0,len(showers)-1)
589  self.library[showers[rand][0]].remove(showers[rand][1])
590  del showers[rand]
591  return

◆ writeToFile()

def LArG4ShowerLibFunctions.FCALDistShowerLib.writeToFile (   self,
  filename 
)

Definition at line 719 of file LArG4ShowerLibFunctions.py.

719  def writeToFile(self,filename) :
720  from ROOT import TFile,TTree,TParameter
721  from ROOT import gROOT, addressof
722  gROOT.ProcessLine(
723  "struct MyMetaStruct {\
724  Char_t detector[40];\
725  Char_t release[40];\
726  Char_t geometry[40];\
727  Char_t geant[40];\
728  Char_t phys[40];\
729  Char_t comment[400];\
730  Int_t particle;\
731  };" )
732  from ROOT import MyMetaStruct
733  gROOT.ProcessLine(
734  "struct MyStruct {\
735  Float_t x;\
736  Float_t y;\
737  Float_t z;\
738  Float_t e;\
739  Float_t time;\
740  };" )
741  from ROOT import MyStruct
742 
743  tfile = TFile(filename,"RECREATE")
744 
745  ver = TParameter(int)("version",4) #<<<<<<<<<<<<<<<<<<<<<<-------------- lib ver
746  ver.Write("version")
747 
748  meta = TTree()
749  libr = TTree()
750 
751  mmstruct = MyMetaStruct()
752 
753  mmstruct.detector = "%s" % (str(self.detector))
754  mmstruct.particle = int(self.particle)
755  mmstruct.release = "%s" % (str(self.release))
756  mmstruct.geometry = "%s" % (str(self.geometry))
757  mmstruct.geant = "%s" % (str(self.geant))
758  mmstruct.phys = "%s" % (str(self.phys))
759  mmstruct.comment = "%s" % (str(self.comment))
760 
761  meta.Branch("detector",addressof(mmstruct,"detector"),"detector/C")
762  meta.Branch("particle",addressof(mmstruct,"particle"),"particle/I")
763  meta.Branch("release",addressof(mmstruct,"release"),"release/C")
764  meta.Branch("geometry",addressof(mmstruct,"geometry"),"geometry/C")
765  meta.Branch("geantVersion",addressof(mmstruct,"geant"),"geantVersion/C")
766  meta.Branch("physicsList",addressof(mmstruct,"phys"),"physicsList/C")
767  meta.Branch("comment",addressof(mmstruct,"comment"),"physicsList/C")
768 
769  meta.Fill()
770 
771  mstruct = MyStruct()
772 
773  libr.Branch("x",addressof(mstruct,"x"),"x/F")
774  libr.Branch("y",addressof(mstruct,"y"),"y/F")
775  libr.Branch("z",addressof(mstruct,"z"),"z/F")
776  libr.Branch("e",addressof(mstruct,"e"),"e/F")
777  libr.Branch("time",addressof(mstruct,"time"),"time/F")
778 
779  mstruct.x = self.xrod_cent
780  mstruct.y = self.yrod_cent
781  mstruct.z = self.step
782  mstruct.e = 0
783  mstruct.time = 0
784  libr.Fill()
785 
786  dists = sorted(self.library.keys())
787 
788  for dist in dists :
789  mstruct.x = len(self.library[dist])
790  mstruct.y = dist
791  mstruct.z = 0
792  mstruct.e = 0
793  mstruct.time = 0
794  libr.Fill()
795  self.library[dist].sort(key=lambda x: x.egen)
796  for storedShower in self.library[dist] :
797  mstruct.x = len(storedShower.shower)
798  mstruct.y = storedShower.rsize
799  mstruct.z = storedShower.zsize
800  mstruct.e = storedShower.egen
801  mstruct.time = 0
802  libr.Fill()
803  for hit in storedShower.shower:
804  mstruct.e = hit.e
805  mstruct.x = hit.x
806  mstruct.y = hit.y
807  mstruct.z = hit.z
808  mstruct.time = hit.time
809  libr.Fill()
810  meta.Write("meta")
811  libr.Write("library")
812  tfile.Close()

Member Data Documentation

◆ comment

LArG4ShowerLibFunctions.FCALDistShowerLib.comment

Definition at line 568 of file LArG4ShowerLibFunctions.py.

◆ detector

LArG4ShowerLibFunctions.FCALDistShowerLib.detector

Definition at line 562 of file LArG4ShowerLibFunctions.py.

◆ geant

LArG4ShowerLibFunctions.FCALDistShowerLib.geant

Definition at line 566 of file LArG4ShowerLibFunctions.py.

◆ geometry

LArG4ShowerLibFunctions.FCALDistShowerLib.geometry

Definition at line 565 of file LArG4ShowerLibFunctions.py.

◆ library

LArG4ShowerLibFunctions.FCALDistShowerLib.library

Definition at line 561 of file LArG4ShowerLibFunctions.py.

◆ particle

LArG4ShowerLibFunctions.FCALDistShowerLib.particle

Definition at line 563 of file LArG4ShowerLibFunctions.py.

◆ phys

LArG4ShowerLibFunctions.FCALDistShowerLib.phys

Definition at line 567 of file LArG4ShowerLibFunctions.py.

◆ release

LArG4ShowerLibFunctions.FCALDistShowerLib.release

Definition at line 564 of file LArG4ShowerLibFunctions.py.

◆ step

LArG4ShowerLibFunctions.FCALDistShowerLib.step

Definition at line 571 of file LArG4ShowerLibFunctions.py.

◆ xrod_cent

LArG4ShowerLibFunctions.FCALDistShowerLib.xrod_cent

Definition at line 569 of file LArG4ShowerLibFunctions.py.

◆ yrod_cent

LArG4ShowerLibFunctions.FCALDistShowerLib.yrod_cent

Definition at line 570 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