3 from __future__
import print_function
7 __author__ =
'Radist Morse radist.morse@gmail.com'
34 return self.
egen == other.egen
48 if not isinstance(lib,self.__class__):
49 print (
"ERROR: Different types of libs")
55 self.
geant = libs[0].geant
56 self.
phys = libs[0].phys
58 if ( self.
detector != lib.detector
or
62 self.
geant != lib.geant
or
63 self.
phys != lib.phys ) :
64 print (
"ERROR: DIFFERENT LIBS!!!")
66 from datetime
import datetime
72 from ROOT
import TFile
73 tfile = TFile(filename)
75 ver =
int(tfile.Get(
"version").GetVal())
77 print (
"Not a TestShowerLib: Broken file")
81 print (
"Not a TestShowerLib")
84 meta = tfile.Get(
"meta")
85 libr = tfile.Get(
"library")
92 self.
phys=
str(event.physicsList)
104 curShower.vertex.x = event.x
105 curShower.vertex.y = event.y
106 curShower.vertex.z = event.z
107 curShower.zsize = event.time
108 hitsInCurShower = event.e
111 curShower.momentum.x = event.x
112 curShower.momentum.y = event.y
113 curShower.momentum.z = event.z
114 curShower.momentum.e = event.e
115 curShower.rsize = event.time
116 if (hitsInCurShower > 0) :
127 hit.time = event.time
128 curShower.shower.append(hit)
130 if (hitsInCurShower == 0) :
135 print (
"FILE CORRUPTED!!")
139 from ROOT
import TFile,TTree,TParameter
140 from ROOT
import gROOT, addressof
142 "struct MyMetaStruct {\
143 Char_t detector[40];\
145 Char_t geometry[40];\
148 Char_t comment[400];\
151 from ROOT
import MyMetaStruct
160 from ROOT
import MyStruct
162 tfile = TFile(filename,
"RECREATE")
164 ver = TParameter(int)(
"version",10)
170 mmstruct = MyMetaStruct()
176 mmstruct.geant =
"%s" % (
str(self.
geant))
177 mmstruct.phys =
"%s" % (
str(self.
phys))
180 meta.Branch(
"detector",addressof(mmstruct,
"detector"),
"detector/C")
181 meta.Branch(
"particle",addressof(mmstruct,
"particle"),
"particle/I")
182 meta.Branch(
"release",addressof(mmstruct,
"release"),
"release/C")
183 meta.Branch(
"geometry",addressof(mmstruct,
"geometry"),
"geometry/C")
184 meta.Branch(
"geantVersion",addressof(mmstruct,
"geant"),
"geantVersion/C")
185 meta.Branch(
"physicsList",addressof(mmstruct,
"phys"),
"physicsList/C")
186 meta.Branch(
"comment",addressof(mmstruct,
"comment"),
"physicsList/C")
192 libr.Branch(
"x",addressof(mstruct,
"x"),
"x/F")
193 libr.Branch(
"y",addressof(mstruct,
"y"),
"y/F")
194 libr.Branch(
"z",addressof(mstruct,
"z"),
"z/F")
195 libr.Branch(
"e",addressof(mstruct,
"e"),
"e/F")
196 libr.Branch(
"time",addressof(mstruct,
"time"),
"time/F")
198 for storedShower
in self.
library :
199 mstruct.x = storedShower.vertex.x
200 mstruct.y = storedShower.vertex.y
201 mstruct.z = storedShower.vertex.z
202 mstruct.time = storedShower.zsize
203 mstruct.e = len(storedShower.shower)
205 mstruct.x = storedShower.momentum.x
206 mstruct.y = storedShower.momentum.y
207 mstruct.z = storedShower.momentum.z
208 mstruct.e = storedShower.momentum.e
209 mstruct.time = storedShower.rsize
211 for hit
in storedShower.shower:
216 mstruct.time = hit.time
219 libr.Write(
"library")
224 from ROOT
import TH3F
225 from math
import sqrt,copysign,log10
226 hits = TH3F(
"HITS",
"Hits Distrib",50,1,1000,101,-300,300,100,0,500)
227 containmentZ = TH3F(
"CONTZ",
"ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
228 containmentR = TH3F(
"CONTR",
"ContR Distrib",50,1,1000,101,-300,300,100,0,500)
229 for storedShower
in self.library :
230 containmentR.Fill(log10(storedShower.momentum.e)*333,storedShower.rsize,storedShower.zsize/2,10)
231 containmentR.Fill(log10(storedShower.momentum.e)*333,-storedShower.rsize,storedShower.zsize/2,10)
232 containmentZ.Fill(log10(storedShower.momentum.e)*333,0,storedShower.zsize,10)
233 for hit
in storedShower.shower :
234 hits.Fill(log10(storedShower.momentum.e)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
235 return hits,containmentZ,containmentR
249 for storedShower
in etabin :
250 for hit
in storedShower.shower :
256 for storedShower
in etabin :
257 showers += [(eta,storedShower)]
258 if len(showers) <= truncate :
259 print (
"WARNING: Size of the library is already less:",truncate,
"<",len(showers))
261 from random
import randint
262 while (len(showers) > truncate) :
263 rand = randint(0,len(showers)-1)
269 if not isinstance(lib,self.__class__):
270 print (
"ERROR: Different types of libs")
276 self.
geant = libs[0].geant
277 self.
phys = libs[0].phys
281 etas =
set(libs[0].library.keys())
283 if ( self.
detector != lib.detector
or
287 self.
geant != lib.geant
or
288 self.
phys != lib.phys
or
289 self.
mineta != lib.mineta
or
290 self.
maxeta != lib.maxeta
or
291 etas !=
set(lib.library.keys()) ) :
292 print (
"ERROR: DIFFERENT LIBS!!!")
295 for k,v
in lib.library.items():
311 from ROOT
import TFile
313 tfile = TFile(filename)
315 ver =
int(tfile.Get(
"version").GetVal())
317 print (
"Not an EtaEnergyLib: Broken file")
322 print (
"Not an EtaEnergyLib")
325 meta = tfile.Get(
"meta")
326 libr = tfile.Get(
"library")
334 self.
phys=
str(event.physicsList)
342 showersInCurEta = event.x
343 curEta =
round(event.y,4)
347 if (showersInCurEta > 0) :
350 hitsInCurShower = event.x
355 if (showersInCurEta == 0) :
358 curShower.egen = genEnergy
359 curShower.rsize = rSize
360 curShower.zsize = zSize
362 if (hitsInCurShower > 0) :
375 hit.time = event.time
376 curShower.shower.append(hit)
378 if (hitsInCurShower == 0) :
387 print (
"FILE CORRUPTED!!")
391 from ROOT
import TFile,TTree,TParameter
392 from ROOT
import gROOT, addressof
394 "struct MyMetaStruct {\
395 Char_t detector[40];\
397 Char_t geometry[40];\
400 Char_t comment[400];\
403 from ROOT
import MyMetaStruct
412 from ROOT
import MyStruct
414 tfile = TFile(filename,
"RECREATE")
416 ver = TParameter(int)(
"version",1)
422 mmstruct = MyMetaStruct()
428 mmstruct.geant =
"%s" % (
str(self.
geant))
429 mmstruct.phys =
"%s" % (
str(self.
phys))
432 meta.Branch(
"detector",addressof(mmstruct,
"detector"),
"detector/C")
433 meta.Branch(
"particle",addressof(mmstruct,
"particle"),
"particle/I")
434 meta.Branch(
"release",addressof(mmstruct,
"release"),
"release/C")
435 meta.Branch(
"geometry",addressof(mmstruct,
"geometry"),
"geometry/C")
436 meta.Branch(
"geantVersion",addressof(mmstruct,
"geant"),
"geantVersion/C")
437 meta.Branch(
"physicsList",addressof(mmstruct,
"phys"),
"physicsList/C")
438 meta.Branch(
"comment",addressof(mmstruct,
"comment"),
"physicsList/C")
444 libr.Branch(
"x",addressof(mstruct,
"x"),
"x/F")
445 libr.Branch(
"y",addressof(mstruct,
"y"),
"y/F")
446 libr.Branch(
"z",addressof(mstruct,
"z"),
"z/F")
447 libr.Branch(
"e",addressof(mstruct,
"e"),
"e/F")
448 libr.Branch(
"time",addressof(mstruct,
"time"),
"time/F")
453 mstruct.x = len(self.
library[eta])
459 self.
library[eta].sort(key=
lambda x: x.egen)
460 for storedShower
in self.
library[eta] :
461 mstruct.x = len(storedShower.shower)
462 mstruct.y = storedShower.rsize
463 mstruct.z = storedShower.zsize
464 mstruct.e = storedShower.egen
467 for hit
in storedShower.shower:
472 mstruct.time = hit.time
475 libr.Write(
"library")
478 print (
"VERSION: EtaEnergyLib",
"PARTICLE:",self.
particle,
"DETECTOR:",self.
detector)
481 ebins = [1,2,5,10,20,50,100,200,500,1000]
483 print (
"Number of etabins:",
str(len(etas)))
488 print (
"Number of showers:",
str(fstot))
489 print (
"-"*(12+len(ebins)*8))
490 infostr =
"|etas|ebins|"
492 infostr += (
"<%d" %ebin).rjust(7)
495 print (
"-"*(12+len(ebins)*8))
496 for etalow,etahigh
in zip(etas,(etas[1:] + [self.
maxeta])) :
507 for shower
in self.
library[etalow] :
508 if (shower.egen <= ebin)
and (shower.egen > prevebin) :
510 egenshow = shower.egen
512 for hit
in shower.shower :
514 erec[ebin] += erecshow
515 egen[ebin] += egenshow
516 hits[ebin] += len(shower.shower)
517 if (count[ebin] > 0) :
518 hits[ebin] /= count[ebin]
521 infostr+=
str(
round(etalow,5)).rjust(9)
524 infostr2+=
str(
round(etahigh,3)).rjust(6)
526 infostr3 =
"|ErecEgen"
527 infostr3+=
" ".rjust(2)
530 infostr+=
str(count[ebin]).rjust(7)
531 if (egen[ebin] > 0) :
532 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
533 infostr3+= (
"%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
535 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
536 infostr3+=
"0.0".rjust(7)
543 print (
"-"*(12+len(ebins)*8))
545 from ROOT
import TH3F
546 from math
import sqrt,copysign,log10
547 hits = TH3F(
"HITS",
"Hits Distrib",50,1,1000,101,-300,300,100,0,500)
548 containmentZ = TH3F(
"CONTZ",
"ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
549 containmentR = TH3F(
"CONTR",
"ContR Distrib",50,1,1000,101,-300,300,100,0,500)
551 for storedShower
in etabin :
552 containmentR.Fill(log10(storedShower.egen)*333,storedShower.rsize,storedShower.zsize,10)
553 containmentR.Fill(log10(storedShower.egen)*333,-storedShower.rsize,storedShower.zsize,10)
554 containmentZ.Fill(log10(storedShower.egen)*333,0,storedShower.zsize,10)
555 for hit
in storedShower.shower :
556 hits.Fill(log10(storedShower.egen)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
557 return hits,containmentZ,containmentR
574 for storedShower
in distbin :
575 for hit
in storedShower.shower :
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))
586 from random
import randint
587 while (len(showers) > truncate) :
588 rand = randint(0,len(showers)-1)
604 if not isinstance(lib,self.__class__):
605 print (
"ERROR: Different types of libs")
611 self.
geant = libs[0].geant
612 self.
phys = libs[0].phys
616 self.
step = libs[0].step
617 dists =
set(libs[0].library.keys())
619 if ( self.
detector != lib.detector
or
623 self.
geant != lib.geant
or
624 self.
phys != lib.phys
or
627 self.
step != lib.step
or
628 dists !=
set(lib.library.keys()) ) :
629 print (
"ERROR: DIFFERENT LIBS!!!")
632 for k,v
in lib.library.items():
638 from ROOT
import TFile
640 tfile = TFile(filename)
642 ver =
int(tfile.Get(
"version").GetVal())
644 print (
"Not an FCALDistEnergyLib: Broken file")
648 print (
"Not an FCALDistEnergyLib")
651 meta = tfile.Get(
"meta")
652 libr = tfile.Get(
"library")
660 self.
phys=
str(event.physicsList)
673 showersInCurDist = event.x
674 curDist =
round(event.y,4)
676 if (showersInCurDist > 0) :
679 hitsInCurShower = event.x
683 showersInCurDist -= 1
684 if (showersInCurDist == 0) :
687 curShower.egen = genEnergy
688 curShower.rsize = rSize
689 curShower.zsize = zSize
691 if (hitsInCurShower > 0) :
704 hit.time = event.time
705 curShower.shower.append(hit)
707 if (hitsInCurShower == 0) :
716 print (
"FILE CORRUPTED!!")
720 from ROOT
import TFile,TTree,TParameter
721 from ROOT
import gROOT, addressof
723 "struct MyMetaStruct {\
724 Char_t detector[40];\
726 Char_t geometry[40];\
729 Char_t comment[400];\
732 from ROOT
import MyMetaStruct
741 from ROOT
import MyStruct
743 tfile = TFile(filename,
"RECREATE")
745 ver = TParameter(int)(
"version",4)
751 mmstruct = MyMetaStruct()
757 mmstruct.geant =
"%s" % (
str(self.
geant))
758 mmstruct.phys =
"%s" % (
str(self.
phys))
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")
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")
781 mstruct.z = self.
step
789 mstruct.x = len(self.
library[dist])
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
803 for hit
in storedShower.shower:
808 mstruct.time = hit.time
811 libr.Write(
"library")
814 print (
"VERSION: FCALDistEnergyLib",
"PARTICLE:",self.
particle,
"DETECTOR:",self.
detector)
818 ebins = [1,2,5,10,20,50,100,200,500,1000]
820 print (
"Number of etabins:",
str(len(dists)))
823 fstot +=len(self.
library[dist])
824 print (
"Number of showers:",
str(fstot))
825 print (
"-"*(13+len(ebins)*8))
826 infostr =
"|dists|ebins|"
828 infostr += (
"<%d" %ebin).rjust(7)
831 print (
"-"*(13+len(ebins)*8))
832 for distlow,disthigh
in zip(dists,(dists[1:] + [4.5])) :
843 for shower
in self.
library[distlow] :
844 if (shower.egen <= ebin)
and (shower.egen > prevebin) :
846 egenshow = shower.egen
848 for hit
in shower.shower :
850 erec[ebin] += erecshow
851 egen[ebin] += egenshow
852 hits[ebin] += len(shower.shower)
853 if (count[ebin] > 0) :
854 hits[ebin] /= count[ebin]
857 infostr+=
str(
round(distlow,5)).rjust(10)
860 infostr2+=
str(
round(disthigh,3)).rjust(7)
862 infostr3 =
"|ErecEgen"
863 infostr3+=
" ".rjust(3)
866 infostr+=
str(count[ebin]).rjust(7)
867 if (egen[ebin] > 0) :
868 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
869 infostr3+= (
"%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
871 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
872 infostr3+=
"0.0".rjust(7)
879 print (
"-"*(12+len(ebins)*8))
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)
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
911 for distbin
in etabin.values():
912 for storedShower
in distbin :
913 for hit
in storedShower.shower :
917 log = logging.getLogger(
"FCALDistEtaShowerLib::truncate()")
920 for dist,distbin
in etabin.items():
921 log.info(
"Number of showers in %s %s is %d",
str(eta),
str(dist),len(distbin))
922 for storedShower
in distbin :
923 showers += [(eta, dist, storedShower)]
924 log.info(
"total number of showers: %d", len(showers))
926 log.info(
"will not remove from eta-dist bins with less then %d showers", nShowersMin)
927 if len(showers) <= truncate :
928 log.warning(
"Size of the library is already less: %d < %d",truncate,len(showers))
930 from random
import randint
931 while (len(showers) > truncate) :
932 rand = randint(0,len(showers)-1)
933 if len(self.
library[showers[rand][0]][showers[rand][1]]) < nShowersMin:
935 self.
library[showers[rand][0]][showers[rand][1]].
remove(showers[rand][2])
941 if (oldDist
in etabin.keys()) :
942 etabin[newDist] = etabin.pop(oldDist)
953 if (dist
in etabin.keys()) :
964 if not isinstance(lib,self.__class__):
965 print (
"ERROR: Different types of libs")
971 self.
geant = libs[0].geant
972 self.
phys = libs[0].phys
976 self.
step = libs[0].step
977 etas =
set(libs[0].library.keys())
979 if ( self.
detector != lib.detector
or
983 self.
geant != lib.geant
or
984 self.
phys != lib.phys
or
987 self.
step != lib.step
or
988 etas !=
set(lib.library.keys()) ) :
989 print (
"ERROR: DIFFERENT LIBS!!!")
991 for eta
in libs[0].library.keys() :
992 if (
set(libs[0].library[eta].
keys()) !=
set(lib.library[eta].
keys())) :
993 print (
"ERROR: DIFFERENT LIBS!!!")
996 for k,v
in lib.library.items():
997 for ki,vi
in v.items():
1000 for ki,vi
in v.items():
1004 log = logging.getLogger(
"FCALDistEtaShowerLib::readFromFile()")
1005 from ROOT
import TFile
1007 tfile = TFile(filename)
1009 ver =
int(tfile.Get(
"version").GetVal())
1011 print (
"Not an FCALDistEtaEnergyLib: Broken file")
1016 print (
"Not an FCALDistEtaEnergyLib")
1019 meta = tfile.Get(
"meta")
1020 libr = tfile.Get(
"library")
1028 self.
phys=
str(event.physicsList)
1035 log.debug(
"dector: %s",
str(event.detector))
1036 log.debug(
"particle: %s",
str(event.particle))
1037 log.debug(
"release: %s",
str(event.release))
1038 log.debug(
"geometry: %s",
str(event.geometry))
1039 log.debug(
"geant ver: %s",
str(event.geantVersion))
1040 log.debug(
"physList: %s",
str(event.physicsList))
1041 log.debug(
"comment: %s",
str(event.comment))
1044 log.debug(
"-------")
1045 log.debug(
"x=%f, y=%f, z=%f, e=%f",event.x,event.y,event.z,event.e)
1046 log.debug(
"beginnnig ev loop. lastShower: %s",
str(lastShower))
1047 log.debug(
"beginnnig ev loop. state: %s",
str(state))
1050 log.debug(
"in state=-1")
1057 log.debug(
"in state=0")
1058 log.debug(
"x=distsInCurEta, y=curEta")
1060 distsInCurEta = event.x
1061 curEta =
round(event.y,4)
1063 if (distsInCurEta > 0) :
1066 log.debug(
"in state=1")
1067 log.debug(
"x=showersInCurDist, y=curDist")
1069 showersInCurDist = event.x
1070 curDist =
round(event.y,4)
1071 self.
library[curEta][curDist] = []
1073 if (distsInCurEta == 0) :
1075 if (showersInCurDist > 0) :
1083 log.debug(
"in state=2")
1084 log.debug(
"x=hitsInCurShower, y=curShower.rSize, z=curShower.zSize, e=curShower.genEnergy")
1086 hitsInCurShower = event.x
1090 showersInCurDist -= 1
1091 if (showersInCurDist == 0) :
1094 curShower.egen = genEnergy
1095 curShower.rsize = rSize
1096 curShower.zsize = zSize
1098 if (hitsInCurShower > 0) :
1101 log.debug(
"Appending shower to lib pos %s %s",curEta,curDist)
1113 log.debug(
"in state=3")
1114 log.debug(
"x=hit.x, y=hit.y, z=hit.z, e=hit.e")
1121 hit.time = event.time
1122 curShower.shower.append(hit)
1123 hitsInCurShower -= 1
1124 if (hitsInCurShower == 0) :
1125 log.debug(
"Appending shower+hit to lib pos %s %s",curEta,curDist)
1138 log.debug(
"ending ev loop. lastShower: %s", lastShower)
1139 log.debug(
"ending ev loop. state %s", state)
1140 if log.root.level == logging.DEBUG:
1141 input(
"Continue? Press Enter.")
1145 print (
"FILE CORRUPTED!!")
1149 from ROOT
import TFile,TTree,TParameter
1150 from ROOT
import gROOT, addressof
1152 "struct MyMetaStruct {\
1153 Char_t detector[40];\
1154 Char_t release[40];\
1155 Char_t geometry[40];\
1158 Char_t comment[400];\
1161 from ROOT
import MyMetaStruct
1170 from ROOT
import MyStruct
1172 tfile = TFile(filename,
"RECREATE")
1174 ver = TParameter(int)(
"version",5)
1175 ver.Write(
"version")
1180 mmstruct = MyMetaStruct()
1184 mmstruct.release =
"%s" % (
str(self.
release))
1186 mmstruct.geant =
"%s" % (
str(self.
geant))
1187 mmstruct.phys =
"%s" % (
str(self.
phys))
1188 mmstruct.comment =
"%s" % (
str(self.
comment))
1190 meta.Branch(
"detector",addressof(mmstruct,
"detector"),
"detector/C")
1191 meta.Branch(
"particle",addressof(mmstruct,
"particle"),
"particle/I")
1192 meta.Branch(
"release",addressof(mmstruct,
"release"),
"release/C")
1193 meta.Branch(
"geometry",addressof(mmstruct,
"geometry"),
"geometry/C")
1194 meta.Branch(
"geantVersion",addressof(mmstruct,
"geant"),
"geantVersion/C")
1195 meta.Branch(
"physicsList",addressof(mmstruct,
"phys"),
"physicsList/C")
1196 meta.Branch(
"comment",addressof(mmstruct,
"comment"),
"physicsList/C")
1200 mstruct = MyStruct()
1202 libr.Branch(
"x",addressof(mstruct,
"x"),
"x/F")
1203 libr.Branch(
"y",addressof(mstruct,
"y"),
"y/F")
1204 libr.Branch(
"z",addressof(mstruct,
"z"),
"z/F")
1205 libr.Branch(
"e",addressof(mstruct,
"e"),
"e/F")
1206 libr.Branch(
"time",addressof(mstruct,
"time"),
"time/F")
1212 mstruct.z = self.
step
1219 mstruct.x = len(self.
library[eta])
1226 mstruct.x = len(self.
library[eta][dist])
1232 self.
library[eta][dist].sort(key=
lambda x: x.egen)
1233 for storedShower
in self.
library[eta][dist] :
1234 mstruct.x = len(storedShower.shower)
1235 mstruct.y = storedShower.rsize
1236 mstruct.z = storedShower.zsize
1237 mstruct.e = storedShower.egen
1240 for hit
in storedShower.shower:
1245 mstruct.time = hit.time
1248 libr.Write(
"library")
1251 print (
"VERSION: FCALDistEtaEnergyLib",
"PARTICLE:",self.
particle,
"DETECTOR:",self.
detector)
1255 ebins = [1,2,3,4,5,10,20,50,100,200,500,1000]
1257 print (
"Number of etabins:",
str(len(etas)))
1260 for distbin
in etabin.values():
1261 fstot +=len(distbin)
1262 print (
"Number of showers:",
str(fstot))
1263 print (
"-"*(13+len(ebins)*8))
1264 infostr =
"|dists|ebins|"
1266 infostr += (
"<%d" %ebin).rjust(7)
1269 print (
"-"*(13+len(ebins)*8))
1272 for distlow,disthigh
in zip(dists,(dists[1:] + [4.5])) :
1283 for shower
in self.
library[eta][distlow] :
1284 if (shower.egen <= ebin)
and (shower.egen > prevebin) :
1286 egenshow = shower.egen
1288 for hit
in shower.shower :
1290 erec[ebin] += erecshow
1291 egen[ebin] += egenshow
1292 hits[ebin] += len(shower.shower)
1293 if (count[ebin] > 0) :
1294 hits[ebin] /= count[ebin]
1297 infostr+=
str(eta).rjust(10)
1300 infostr2+=
str(
round(distlow,5)).rjust(7)
1303 infostr3+=
str(
round(disthigh,3)).rjust(8)
1306 infostr+=
str(count[ebin]).rjust(7)
1307 if (egen[ebin] > 0) :
1308 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
1309 infostr3+= (
"%.5f" %(erec[ebin]/egen[ebin])).rjust(7)
1311 infostr2+= (
"%.2f" %(hits[ebin])).rjust(7)
1312 infostr3+=
"0.0".rjust(7)
1319 print (
"-"*(12+len(ebins)*8))
1321 from ROOT
import TH3F
1322 from math
import sqrt,copysign,log10
1323 hits = TH3F(
"HITS",
"Hits Distrib",50,1,1000,101,-300,300,100,0,500)
1324 containmentZ = TH3F(
"CONTZ",
"ContZ Distrib",50,1,1000,101,-300,300,100,0,500)
1325 containmentR = TH3F(
"CONTR",
"ContR Distrib",50,1,1000,101,-300,300,100,0,500)
1330 for distlow,disthigh
in zip(dists,(dists[1:] + [4.5])) :
1331 for storedShower
in self.
library[eta][distlow] :
1332 containmentR.Fill(log10(storedShower.egen)*333,storedShower.rsize,storedShower.zsize,10)
1333 containmentR.Fill(log10(storedShower.egen)*333,-storedShower.rsize,storedShower.zsize,10)
1334 containmentZ.Fill(log10(storedShower.egen)*333,0,storedShower.zsize,10)
1335 for hit
in storedShower.shower :
1336 hits.Fill(log10(storedShower.egen)*333,copysign(sqrt(hit.x*hit.x + hit.y*hit.y),hit.x),hit.z)
1338 return hits,containmentZ,containmentR