1002 def readFromFile(self,filename) :
1003 log = logging.getLogger("FCALDistEtaShowerLib::readFromFile()")
1004 from ROOT import TFile
1005
1006 tfile = TFile(filename)
1007 try:
1008 ver = int(tfile.Get("version").GetVal())
1009 except Exception:
1010 print ("Not an FCALDistEtaEnergyLib: Broken file")
1011 tfile.Close()
1012 return False
1013
1014 if (ver != 5) :
1015 print ("Not an FCALDistEtaEnergyLib")
1016 tfile.Close()
1017 return False
1018 meta = tfile.Get("meta")
1019 libr = tfile.Get("library")
1020
1021 for event in meta :
1022 self.detector=str(event.detector)
1023 self.particle=str(event.particle)
1024 self.release=str(event.release)
1025 self.geometry=str(event.geometry)
1026 self.geant=str(event.geantVersion)
1027 self.phys=str(event.physicsList)
1028 self.comment=str(event.comment)
1029
1030 state = -1
1031 lastShower = False
1032 lastEta = False
1033
1034 log.debug("dector: %s", str(event.detector))
1035 log.debug("particle: %s", str(event.particle))
1036 log.debug("release: %s", str(event.release))
1037 log.debug("geometry: %s", str(event.geometry))
1038 log.debug("geant ver: %s", str(event.geantVersion))
1039 log.debug("physList: %s", str(event.physicsList))
1040 log.debug("comment: %s", str(event.comment))
1041
1042 for event in libr :
1043 log.debug("-------")
1044 log.debug("x=%f, y=%f, z=%f, e=%f",event.x,event.y,event.z,event.e)
1045 log.debug("beginnnig ev loop. lastShower: %s",str(lastShower))
1046 log.debug("beginnnig ev loop. state: %s",str(state))
1047
1048 if (state == -1) :
1049 log.debug("in state=-1")
1050
1051 self.xrod_cent = event.x
1052 self.yrod_cent = event.y
1053 self.step = event.z
1054 state = 0
1055 elif (state == 0) :
1056 log.debug("in state=0")
1057 log.debug("x=distsInCurEta, y=curEta")
1058
1059 distsInCurEta = event.x
1060 curEta = round(event.y,4)
1061 self.library[curEta] = {}
1062 if (distsInCurEta > 0) :
1063 state = 1
1064 elif (state == 1) :
1065 log.debug("in state=1")
1066 log.debug("x=showersInCurDist, y=curDist")
1067
1068 showersInCurDist = event.x
1069 curDist = round(event.y,4)
1070 self.library[curEta][curDist] = []
1071 distsInCurEta -= 1
1072 if (distsInCurEta == 0) :
1073 lastEta = True
1074 if (showersInCurDist > 0) :
1075 state = 2
1076 else :
1077 if (lastEta) :
1078 lastEta = False
1079 state = 0
1080 elif (state == 2) :
1081
1082 log.debug("in state=2")
1083 log.debug("x=hitsInCurShower, y=curShower.rSize, z=curShower.zSize, e=curShower.genEnergy")
1084
1085 hitsInCurShower = event.x
1086 rSize = event.y
1087 zSize = event.z
1088 genEnergy = event.e
1089 showersInCurDist -= 1
1090 if (showersInCurDist == 0) :
1091 lastShower = True
1092 curShower = StoredEnergyShower()
1093 curShower.egen = genEnergy
1094 curShower.rsize = rSize
1095 curShower.zsize = zSize
1096
1097 if (hitsInCurShower > 0) :
1098 state = 3
1099 else :
1100 log.debug("Appending shower to lib pos %s %s",curEta,curDist)
1101
1102 self.library[curEta][curDist].append(curShower)
1103 if (lastShower) :
1104 lastShower = False
1105 if (lastEta) :
1106 lastEta = False
1107 state = 0
1108 else :
1109 state = 1
1110 elif (state == 3) :
1111
1112 log.debug("in state=3")
1113 log.debug("x=hit.x, y=hit.y, z=hit.z, e=hit.e")
1114
1115 hit = FourVector()
1116 hit.e = event.e
1117 hit.x = event.x
1118 hit.y = event.y
1119 hit.z = event.z
1120 hit.time = event.time
1121 curShower.shower.append(hit)
1122 hitsInCurShower -= 1
1123 if (hitsInCurShower == 0) :
1124 log.debug("Appending shower+hit to lib pos %s %s",curEta,curDist)
1125
1126 self.library[curEta][curDist].append(curShower)
1127 if (lastShower) :
1128 lastShower = False
1129 if (lastEta) :
1130 lastEta = False
1131 state = 0
1132 else :
1133 state = 1
1134 else :
1135 state = 2
1136
1137 log.debug("ending ev loop. lastShower: %s", lastShower)
1138 log.debug("ending ev loop. state %s", state)
1139 if log.root.level == logging.DEBUG:
1140 input("Continue? Press Enter.")
1141
1142 tfile.Close()
1143 if (state != 0) :
1144 print ("FILE CORRUPTED!!")
1145 return False
1146 return True