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

Constructor & Destructor Documentation

◆ __init__()

def LArG4ShowerLibFunctions.FCALDistShowerLib.__init__ (   self)

Definition at line 559 of file LArG4ShowerLibFunctions.py.

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

Member Function Documentation

◆ drawHits()

def LArG4ShowerLibFunctions.FCALDistShowerLib.drawHits (   self)

Definition at line 879 of file LArG4ShowerLibFunctions.py.

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

◆ fromLibs()

def LArG4ShowerLibFunctions.FCALDistShowerLib.fromLibs (   self,
  libs 
)

Definition at line 601 of file LArG4ShowerLibFunctions.py.

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

◆ moveDist()

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

Definition at line 591 of file LArG4ShowerLibFunctions.py.

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

◆ printInfo()

def LArG4ShowerLibFunctions.FCALDistShowerLib.printInfo (   self)

Definition at line 812 of file LArG4ShowerLibFunctions.py.

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

◆ readFromFile()

def LArG4ShowerLibFunctions.FCALDistShowerLib.readFromFile (   self,
  filename 
)

Definition at line 636 of file LArG4ShowerLibFunctions.py.

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

◆ removeDist()

def LArG4ShowerLibFunctions.FCALDistShowerLib.removeDist (   self,
  dist 
)

Definition at line 596 of file LArG4ShowerLibFunctions.py.

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

◆ scaleEnergy()

def LArG4ShowerLibFunctions.FCALDistShowerLib.scaleEnergy (   self,
  scalefactor 
)

Definition at line 571 of file LArG4ShowerLibFunctions.py.

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

◆ truncate()

def LArG4ShowerLibFunctions.FCALDistShowerLib.truncate (   self,
  truncate 
)

Definition at line 577 of file LArG4ShowerLibFunctions.py.

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

◆ writeToFile()

def LArG4ShowerLibFunctions.FCALDistShowerLib.writeToFile (   self,
  filename 
)

Definition at line 718 of file LArG4ShowerLibFunctions.py.

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

Member Data Documentation

◆ comment

LArG4ShowerLibFunctions.FCALDistShowerLib.comment

Definition at line 567 of file LArG4ShowerLibFunctions.py.

◆ detector

LArG4ShowerLibFunctions.FCALDistShowerLib.detector

Definition at line 561 of file LArG4ShowerLibFunctions.py.

◆ geant

LArG4ShowerLibFunctions.FCALDistShowerLib.geant

Definition at line 565 of file LArG4ShowerLibFunctions.py.

◆ geometry

LArG4ShowerLibFunctions.FCALDistShowerLib.geometry

Definition at line 564 of file LArG4ShowerLibFunctions.py.

◆ library

LArG4ShowerLibFunctions.FCALDistShowerLib.library

Definition at line 560 of file LArG4ShowerLibFunctions.py.

◆ particle

LArG4ShowerLibFunctions.FCALDistShowerLib.particle

Definition at line 562 of file LArG4ShowerLibFunctions.py.

◆ phys

LArG4ShowerLibFunctions.FCALDistShowerLib.phys

Definition at line 566 of file LArG4ShowerLibFunctions.py.

◆ release

LArG4ShowerLibFunctions.FCALDistShowerLib.release

Definition at line 563 of file LArG4ShowerLibFunctions.py.

◆ step

LArG4ShowerLibFunctions.FCALDistShowerLib.step

Definition at line 570 of file LArG4ShowerLibFunctions.py.

◆ xrod_cent

LArG4ShowerLibFunctions.FCALDistShowerLib.xrod_cent

Definition at line 568 of file LArG4ShowerLibFunctions.py.

◆ yrod_cent

LArG4ShowerLibFunctions.FCALDistShowerLib.yrod_cent

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