6 __author__ =
'Radist Morse radist.morse@gmail.com'
33 return self.
egen == other.egen
47 if not isinstance(lib,self.__class__):
48 print (
"ERROR: Different types of libs")
54 self.
geant = libs[0].geant
55 self.
phys = libs[0].phys
57 if ( self.
detector != lib.detector
or
61 self.
geant != lib.geant
or
62 self.
phys != lib.phys ) :
63 print (
"ERROR: DIFFERENT LIBS!!!")
65 from datetime
import datetime
71 from ROOT
import TFile
72 tfile = TFile(filename)
74 ver =
int(tfile.Get(
"version").GetVal())
76 print (
"Not a TestShowerLib: Broken file")
80 print (
"Not a TestShowerLib")
83 meta = tfile.Get(
"meta")
84 libr = tfile.Get(
"library")
91 self.
phys=
str(event.physicsList)
103 curShower.vertex.x = event.x
104 curShower.vertex.y = event.y
105 curShower.vertex.z = event.z
106 curShower.zsize = event.time
107 hitsInCurShower = event.e
110 curShower.momentum.x = event.x
111 curShower.momentum.y = event.y
112 curShower.momentum.z = event.z
113 curShower.momentum.e = event.e
114 curShower.rsize = event.time
115 if (hitsInCurShower > 0) :
126 hit.time = event.time
127 curShower.shower.append(hit)
129 if (hitsInCurShower == 0) :
134 print (
"FILE CORRUPTED!!")
138 from ROOT
import TFile,TTree,TParameter
139 from ROOT
import gROOT, addressof
141 "struct MyMetaStruct {\
142 Char_t detector[40];\
144 Char_t geometry[40];\
147 Char_t comment[400];\
150 from ROOT
import MyMetaStruct
159 from ROOT
import MyStruct
161 tfile = TFile(filename,
"RECREATE")
163 ver = TParameter(int)(
"version",10)
169 mmstruct = MyMetaStruct()
175 mmstruct.geant =
"%s" % (
str(self.
geant))
176 mmstruct.phys =
"%s" % (
str(self.
phys))
179 meta.Branch(
"detector",addressof(mmstruct,
"detector"),
"detector/C")
180 meta.Branch(
"particle",addressof(mmstruct,
"particle"),
"particle/I")
181 meta.Branch(
"release",addressof(mmstruct,
"release"),
"release/C")
182 meta.Branch(
"geometry",addressof(mmstruct,
"geometry"),
"geometry/C")
183 meta.Branch(
"geantVersion",addressof(mmstruct,
"geant"),
"geantVersion/C")
184 meta.Branch(
"physicsList",addressof(mmstruct,
"phys"),
"physicsList/C")
185 meta.Branch(
"comment",addressof(mmstruct,
"comment"),
"physicsList/C")
191 libr.Branch(
"x",addressof(mstruct,
"x"),
"x/F")
192 libr.Branch(
"y",addressof(mstruct,
"y"),
"y/F")
193 libr.Branch(
"z",addressof(mstruct,
"z"),
"z/F")
194 libr.Branch(
"e",addressof(mstruct,
"e"),
"e/F")
195 libr.Branch(
"time",addressof(mstruct,
"time"),
"time/F")
197 for storedShower
in self.
library :
198 mstruct.x = storedShower.vertex.x
199 mstruct.y = storedShower.vertex.y
200 mstruct.z = storedShower.vertex.z
201 mstruct.time = storedShower.zsize
202 mstruct.e = len(storedShower.shower)
204 mstruct.x = storedShower.momentum.x
205 mstruct.y = storedShower.momentum.y
206 mstruct.z = storedShower.momentum.z
207 mstruct.e = storedShower.momentum.e
208 mstruct.time = storedShower.rsize
210 for hit
in storedShower.shower:
215 mstruct.time = hit.time
218 libr.Write(
"library")
223 from ROOT
import TH3F
224 from math
import sqrt,copysign,log10
225 hits = TH3F(
"HITS",
"Hits Distrib",50,1,1000,101,-300,300,100,0,500)
226 containmentZ = TH3F(
"CONTZ",
"ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
227 containmentR = TH3F(
"CONTR",
"ContR Distrib",50,1,1000,101,-300,300,100,0,500)
228 for storedShower
in self.library :
229 containmentR.Fill(log10(storedShower.momentum.e)*333,storedShower.rsize,storedShower.zsize/2,10)
230 containmentR.Fill(log10(storedShower.momentum.e)*333,-storedShower.rsize,storedShower.zsize/2,10)
231 containmentZ.Fill(log10(storedShower.momentum.e)*333,0,storedShower.zsize,10)
232 for hit
in storedShower.shower :
233 hits.Fill(log10(storedShower.momentum.e)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
234 return hits,containmentZ,containmentR
248 for storedShower
in etabin :
249 for hit
in storedShower.shower :
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))
260 from random
import randint
261 while (len(showers) > truncate) :
262 rand = randint(0,len(showers)-1)
268 if not isinstance(lib,self.__class__):
269 print (
"ERROR: Different types of libs")
275 self.
geant = libs[0].geant
276 self.
phys = libs[0].phys
280 etas =
set(libs[0].library.keys())
282 if ( self.
detector != lib.detector
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!!!")
294 for k,v
in lib.library.items():
310 from ROOT
import TFile
312 tfile = TFile(filename)
314 ver =
int(tfile.Get(
"version").GetVal())
316 print (
"Not an EtaEnergyLib: Broken file")
321 print (
"Not an EtaEnergyLib")
324 meta = tfile.Get(
"meta")
325 libr = tfile.Get(
"library")
333 self.
phys=
str(event.physicsList)
341 showersInCurEta = event.x
342 curEta =
round(event.y,4)
346 if (showersInCurEta > 0) :
349 hitsInCurShower = event.x
354 if (showersInCurEta == 0) :
357 curShower.egen = genEnergy
358 curShower.rsize = rSize
359 curShower.zsize = zSize
361 if (hitsInCurShower > 0) :
374 hit.time = event.time
375 curShower.shower.append(hit)
377 if (hitsInCurShower == 0) :
386 print (
"FILE CORRUPTED!!")
390 from ROOT
import TFile,TTree,TParameter
391 from ROOT
import gROOT, addressof
393 "struct MyMetaStruct {\
394 Char_t detector[40];\
396 Char_t geometry[40];\
399 Char_t comment[400];\
402 from ROOT
import MyMetaStruct
411 from ROOT
import MyStruct
413 tfile = TFile(filename,
"RECREATE")
415 ver = TParameter(int)(
"version",1)
421 mmstruct = MyMetaStruct()
427 mmstruct.geant =
"%s" % (
str(self.
geant))
428 mmstruct.phys =
"%s" % (
str(self.
phys))
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")
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")
452 mstruct.x = len(self.
library[eta])
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
466 for hit
in storedShower.shower:
471 mstruct.time = hit.time
474 libr.Write(
"library")
477 print (
"VERSION: EtaEnergyLib",
"PARTICLE:",self.
particle,
"DETECTOR:",self.
detector)
480 ebins = [1,2,5,10,20,50,100,200,500,1000]
482 print (
"Number of etabins:",
str(len(etas)))
487 print (
"Number of showers:",
str(fstot))
488 print (
"-"*(12+len(ebins)*8))
489 infostr =
"|etas|ebins|"
491 infostr += (
"<%d" %ebin).rjust(7)
494 print (
"-"*(12+len(ebins)*8))
495 for etalow,etahigh
in zip(etas,(etas[1:] + [self.
maxeta])) :
506 for shower
in self.
library[etalow] :
507 if (shower.egen <= ebin)
and (shower.egen > prevebin) :
509 egenshow = shower.egen
511 for hit
in shower.shower :
513 erec[ebin] += erecshow
514 egen[ebin] += egenshow
515 hits[ebin] += len(shower.shower)
516 if (count[ebin] > 0) :
517 hits[ebin] /= count[ebin]
520 infostr+=
str(
round(etalow,5)).rjust(9)
523 infostr2+=
str(
round(etahigh,3)).rjust(6)
525 infostr3 =
"|ErecEgen"
526 infostr3+=
" ".rjust(2)
529 infostr+=
str(count[ebin]).rjust(7)
530 if (egen[ebin] > 0) :
531 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
532 infostr3+= (
"%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
534 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
535 infostr3+=
"0.0".rjust(7)
542 print (
"-"*(12+len(ebins)*8))
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)
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
573 for storedShower
in distbin :
574 for hit
in storedShower.shower :
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))
585 from random
import randint
586 while (len(showers) > truncate) :
587 rand = randint(0,len(showers)-1)
603 if not isinstance(lib,self.__class__):
604 print (
"ERROR: Different types of libs")
610 self.
geant = libs[0].geant
611 self.
phys = libs[0].phys
615 self.
step = libs[0].step
616 dists =
set(libs[0].library.keys())
618 if ( self.
detector != lib.detector
or
622 self.
geant != lib.geant
or
623 self.
phys != lib.phys
or
626 self.
step != lib.step
or
627 dists !=
set(lib.library.keys()) ) :
628 print (
"ERROR: DIFFERENT LIBS!!!")
631 for k,v
in lib.library.items():
637 from ROOT
import TFile
639 tfile = TFile(filename)
641 ver =
int(tfile.Get(
"version").GetVal())
643 print (
"Not an FCALDistEnergyLib: Broken file")
647 print (
"Not an FCALDistEnergyLib")
650 meta = tfile.Get(
"meta")
651 libr = tfile.Get(
"library")
659 self.
phys=
str(event.physicsList)
672 showersInCurDist = event.x
673 curDist =
round(event.y,4)
675 if (showersInCurDist > 0) :
678 hitsInCurShower = event.x
682 showersInCurDist -= 1
683 if (showersInCurDist == 0) :
686 curShower.egen = genEnergy
687 curShower.rsize = rSize
688 curShower.zsize = zSize
690 if (hitsInCurShower > 0) :
703 hit.time = event.time
704 curShower.shower.append(hit)
706 if (hitsInCurShower == 0) :
715 print (
"FILE CORRUPTED!!")
719 from ROOT
import TFile,TTree,TParameter
720 from ROOT
import gROOT, addressof
722 "struct MyMetaStruct {\
723 Char_t detector[40];\
725 Char_t geometry[40];\
728 Char_t comment[400];\
731 from ROOT
import MyMetaStruct
740 from ROOT
import MyStruct
742 tfile = TFile(filename,
"RECREATE")
744 ver = TParameter(int)(
"version",4)
750 mmstruct = MyMetaStruct()
756 mmstruct.geant =
"%s" % (
str(self.
geant))
757 mmstruct.phys =
"%s" % (
str(self.
phys))
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")
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")
780 mstruct.z = self.
step
788 mstruct.x = len(self.
library[dist])
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
802 for hit
in storedShower.shower:
807 mstruct.time = hit.time
810 libr.Write(
"library")
813 print (
"VERSION: FCALDistEnergyLib",
"PARTICLE:",self.
particle,
"DETECTOR:",self.
detector)
817 ebins = [1,2,5,10,20,50,100,200,500,1000]
819 print (
"Number of etabins:",
str(len(dists)))
822 fstot +=len(self.
library[dist])
823 print (
"Number of showers:",
str(fstot))
824 print (
"-"*(13+len(ebins)*8))
825 infostr =
"|dists|ebins|"
827 infostr += (
"<%d" %ebin).rjust(7)
830 print (
"-"*(13+len(ebins)*8))
831 for distlow,disthigh
in zip(dists,(dists[1:] + [4.5])) :
842 for shower
in self.
library[distlow] :
843 if (shower.egen <= ebin)
and (shower.egen > prevebin) :
845 egenshow = shower.egen
847 for hit
in shower.shower :
849 erec[ebin] += erecshow
850 egen[ebin] += egenshow
851 hits[ebin] += len(shower.shower)
852 if (count[ebin] > 0) :
853 hits[ebin] /= count[ebin]
856 infostr+=
str(
round(distlow,5)).rjust(10)
859 infostr2+=
str(
round(disthigh,3)).rjust(7)
861 infostr3 =
"|ErecEgen"
862 infostr3+=
" ".rjust(3)
865 infostr+=
str(count[ebin]).rjust(7)
866 if (egen[ebin] > 0) :
867 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
868 infostr3+= (
"%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
870 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
871 infostr3+=
"0.0".rjust(7)
878 print (
"-"*(12+len(ebins)*8))
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)
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
910 for distbin
in etabin.values():
911 for storedShower
in distbin :
912 for hit
in storedShower.shower :
916 log = logging.getLogger(
"FCALDistEtaShowerLib::truncate()")
919 for dist,distbin
in etabin.items():
920 log.info(
"Number of showers in %s %s is %d",
str(eta),
str(dist),len(distbin))
921 for storedShower
in distbin :
922 showers += [(eta, dist, storedShower)]
923 log.info(
"total number of showers: %d", len(showers))
925 log.info(
"will not remove from eta-dist bins with less then %d showers", nShowersMin)
926 if len(showers) <= truncate :
927 log.warning(
"Size of the library is already less: %d < %d",truncate,len(showers))
929 from random
import randint
930 while (len(showers) > truncate) :
931 rand = randint(0,len(showers)-1)
932 if len(self.
library[showers[rand][0]][showers[rand][1]]) < nShowersMin:
934 self.
library[showers[rand][0]][showers[rand][1]].
remove(showers[rand][2])
940 if (oldDist
in etabin.keys()) :
941 etabin[newDist] = etabin.pop(oldDist)
952 if (dist
in etabin.keys()) :
963 if not isinstance(lib,self.__class__):
964 print (
"ERROR: Different types of libs")
970 self.
geant = libs[0].geant
971 self.
phys = libs[0].phys
975 self.
step = libs[0].step
976 etas =
set(libs[0].library.keys())
978 if ( self.
detector != lib.detector
or
982 self.
geant != lib.geant
or
983 self.
phys != lib.phys
or
986 self.
step != lib.step
or
987 etas !=
set(lib.library.keys()) ) :
988 print (
"ERROR: DIFFERENT LIBS!!!")
990 for eta
in libs[0].library.keys() :
991 if (
set(libs[0].library[eta].
keys()) !=
set(lib.library[eta].
keys())) :
992 print (
"ERROR: DIFFERENT LIBS!!!")
995 for k,v
in lib.library.items():
996 for ki,vi
in v.items():
997 self.
library.setdefault(k,dict()).setdefault(ki,
set()).update(vi)
999 for ki,vi
in v.items():
1003 log = logging.getLogger(
"FCALDistEtaShowerLib::readFromFile()")
1004 from ROOT
import TFile
1006 tfile = TFile(filename)
1008 ver =
int(tfile.Get(
"version").GetVal())
1010 print (
"Not an FCALDistEtaEnergyLib: Broken file")
1015 print (
"Not an FCALDistEtaEnergyLib")
1018 meta = tfile.Get(
"meta")
1019 libr = tfile.Get(
"library")
1027 self.
phys=
str(event.physicsList)
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))
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))
1049 log.debug(
"in state=-1")
1056 log.debug(
"in state=0")
1057 log.debug(
"x=distsInCurEta, y=curEta")
1059 distsInCurEta = event.x
1060 curEta =
round(event.y,4)
1062 if (distsInCurEta > 0) :
1065 log.debug(
"in state=1")
1066 log.debug(
"x=showersInCurDist, y=curDist")
1068 showersInCurDist = event.x
1069 curDist =
round(event.y,4)
1070 self.
library[curEta][curDist] = []
1072 if (distsInCurEta == 0) :
1074 if (showersInCurDist > 0) :
1082 log.debug(
"in state=2")
1083 log.debug(
"x=hitsInCurShower, y=curShower.rSize, z=curShower.zSize, e=curShower.genEnergy")
1085 hitsInCurShower = event.x
1089 showersInCurDist -= 1
1090 if (showersInCurDist == 0) :
1093 curShower.egen = genEnergy
1094 curShower.rsize = rSize
1095 curShower.zsize = zSize
1097 if (hitsInCurShower > 0) :
1100 log.debug(
"Appending shower to lib pos %s %s",curEta,curDist)
1112 log.debug(
"in state=3")
1113 log.debug(
"x=hit.x, y=hit.y, z=hit.z, e=hit.e")
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)
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.")
1144 print (
"FILE CORRUPTED!!")
1148 from ROOT
import TFile,TTree,TParameter
1149 from ROOT
import gROOT, addressof
1151 "struct MyMetaStruct {\
1152 Char_t detector[40];\
1153 Char_t release[40];\
1154 Char_t geometry[40];\
1157 Char_t comment[400];\
1160 from ROOT
import MyMetaStruct
1169 from ROOT
import MyStruct
1171 tfile = TFile(filename,
"RECREATE")
1173 ver = TParameter(int)(
"version",5)
1174 ver.Write(
"version")
1179 mmstruct = MyMetaStruct()
1183 mmstruct.release =
"%s" % (
str(self.
release))
1185 mmstruct.geant =
"%s" % (
str(self.
geant))
1186 mmstruct.phys =
"%s" % (
str(self.
phys))
1187 mmstruct.comment =
"%s" % (
str(self.
comment))
1189 meta.Branch(
"detector",addressof(mmstruct,
"detector"),
"detector/C")
1190 meta.Branch(
"particle",addressof(mmstruct,
"particle"),
"particle/I")
1191 meta.Branch(
"release",addressof(mmstruct,
"release"),
"release/C")
1192 meta.Branch(
"geometry",addressof(mmstruct,
"geometry"),
"geometry/C")
1193 meta.Branch(
"geantVersion",addressof(mmstruct,
"geant"),
"geantVersion/C")
1194 meta.Branch(
"physicsList",addressof(mmstruct,
"phys"),
"physicsList/C")
1195 meta.Branch(
"comment",addressof(mmstruct,
"comment"),
"physicsList/C")
1199 mstruct = MyStruct()
1201 libr.Branch(
"x",addressof(mstruct,
"x"),
"x/F")
1202 libr.Branch(
"y",addressof(mstruct,
"y"),
"y/F")
1203 libr.Branch(
"z",addressof(mstruct,
"z"),
"z/F")
1204 libr.Branch(
"e",addressof(mstruct,
"e"),
"e/F")
1205 libr.Branch(
"time",addressof(mstruct,
"time"),
"time/F")
1211 mstruct.z = self.
step
1218 mstruct.x = len(self.
library[eta])
1225 mstruct.x = len(self.
library[eta][dist])
1231 self.
library[eta][dist].sort(key=
lambda x: x.egen)
1232 for storedShower
in self.
library[eta][dist] :
1233 mstruct.x = len(storedShower.shower)
1234 mstruct.y = storedShower.rsize
1235 mstruct.z = storedShower.zsize
1236 mstruct.e = storedShower.egen
1239 for hit
in storedShower.shower:
1244 mstruct.time = hit.time
1247 libr.Write(
"library")
1250 print (
"VERSION: FCALDistEtaEnergyLib",
"PARTICLE:",self.
particle,
"DETECTOR:",self.
detector)
1254 ebins = [1,2,3,4,5,10,20,50,100,200,500,1000]
1256 print (
"Number of etabins:",
str(len(etas)))
1259 for distbin
in etabin.values():
1260 fstot +=len(distbin)
1261 print (
"Number of showers:",
str(fstot))
1262 print (
"-"*(13+len(ebins)*8))
1263 infostr =
"|dists|ebins|"
1265 infostr += (
"<%d" %ebin).rjust(7)
1268 print (
"-"*(13+len(ebins)*8))
1271 for distlow,disthigh
in zip(dists,(dists[1:] + [4.5])) :
1282 for shower
in self.
library[eta][distlow] :
1283 if (shower.egen <= ebin)
and (shower.egen > prevebin) :
1285 egenshow = shower.egen
1287 for hit
in shower.shower :
1289 erec[ebin] += erecshow
1290 egen[ebin] += egenshow
1291 hits[ebin] += len(shower.shower)
1292 if (count[ebin] > 0) :
1293 hits[ebin] /= count[ebin]
1296 infostr+=
str(eta).rjust(10)
1299 infostr2+=
str(
round(distlow,5)).rjust(7)
1302 infostr3+=
str(
round(disthigh,3)).rjust(8)
1305 infostr+=
str(count[ebin]).rjust(7)
1306 if (egen[ebin] > 0) :
1307 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
1308 infostr3+= (
"%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
1310 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
1311 infostr3+=
"0.0".rjust(7)
1318 print (
"-"*(12+len(ebins)*8))
1320 from ROOT
import TH3F
1321 from math
import sqrt,copysign,log10
1322 hits = TH3F(
"HITS",
"Hits Distrib",50,1,1000,101,-300,300,100,0,500)
1323 containmentZ = TH3F(
"CONTZ",
"ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
1324 containmentR = TH3F(
"CONTR",
"ContR Distrib",50,1,1000,101,-300,300,100,0,500)
1329 for distlow,disthigh
in zip(dists,(dists[1:] + [4.5])) :
1330 for storedShower
in self.
library[eta][distlow] :
1331 containmentR.Fill(log10(storedShower.egen)*333,storedShower.rsize,storedShower.zsize,10)
1332 containmentR.Fill(log10(storedShower.egen)*333,-storedShower.rsize,storedShower.zsize,10)
1333 containmentZ.Fill(log10(storedShower.egen)*333,0,storedShower.zsize,10)
1334 for hit
in storedShower.shower :
1335 hits.Fill(log10(storedShower.egen)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
1337 return hits,containmentZ,containmentR