11 __version__ =
'$Revision: 711210 $'
12 __author__ =
'Radist Morse radist.morse@gmail.com'
13 __doc__ =
'Script for merging FS libs'
17 from optparse
import OptionParser
18 from LArG4GenShowerLib.LArG4ShowerLibFunctions
import \
19 EtaEnergyShowerLib, TestShowerLib, FCALDistShowerLib, FCALDistEtaShowerLib
21 usage =
"usage: %prog [options] lib1 [lib2 ...]"
23 parser = OptionParser(usage=usage, version=
"%prog v0.0.1 $Id: LArG4ShowerLibProcessing.py 711210 2015-11-27 15:56:00Z jchapman $")
26 parser.add_option(
"-i",
"--info",dest=
"info", action=
"store_true", help=
"Print info about the lib(s)")
27 parser.add_option(
"-a",
"--add",dest=
"add", action=
"store_true", help=
"Add input libs together")
28 parser.add_option(
"-o",
"--output",dest=
"output", help=
"Name of output file")
29 parser.add_option(
"-s",
"--scale",dest=
"scale", type = float, help=
"Scale library by energy")
30 parser.add_option(
"-d",
"--moveDist",dest=
"moveD", action=
"append", help=
"move dist bin")
31 parser.add_option(
"-e",
"--moveEta",dest=
"moveE", action=
"append", help=
"move eta bin")
32 parser.add_option(
"--removeDist",dest=
"removeD", action=
"append", help=
"remove dist bin")
33 parser.add_option(
"--removeEta",dest=
"removeE", action=
"append", help=
"remove eta bin")
34 parser.add_option(
"-t",
"--truncate",dest=
"truncate", type = int, help=
"truncate lib")
35 parser.add_option(
"-p",
"--paint",dest=
"draw", action=
"store_true", help=
"paint hits distribution histogram")
36 parser.add_option(
'--log', dest=
"loglevel", help=
'Logging level. Use \"--log debug\" to debug the library content step-by-step' )
38 parser.set_defaults(info =
False, add =
False, output =
"", scale = 0.0, moveD = [], moveE = [], removeD = [], removeE = [], draw =
False, truncate = 0, loglevel=
"info")
40 (options, args) = parser.parse_args()
42 logging.basicConfig(stream=sys.stdout,level=options.loglevel.upper() )
43 log=logging.getLogger(
"LArG4ShowerLibProcessing.py")
46 log.error(
"No input specified")
52 log.info(
"Reading file %s",filename)
53 tmplib = EtaEnergyShowerLib()
54 if tmplib.readFromFile(filename) :
56 tmplib = TestShowerLib()
57 if tmplib.readFromFile(filename) :
59 tmplib = FCALDistShowerLib()
60 if tmplib.readFromFile(filename) :
62 tmplib = FCALDistEtaShowerLib()
63 if tmplib.readFromFile(filename) :
66 if (options.truncate > 0) :
68 lib.truncate(options.truncate)
71 for arg,lib
in zip(args,libs) :
75 if (options.add
and len(libs) > 1) :
76 print (
"INFO: Adding libs")
77 outlib = libs[0].__class__()
78 if not outlib.fromLibs(libs) :
85 if (options.scale > 0) :
86 print (
"Scaling to",options.scale)
87 libs[0].scaleEnergy(options.scale)
89 if (len(options.moveD) > 0) :
90 for move
in options.moveD :
91 print (
"Moving bin:",move)
92 movl = map(float,move.split(
":"))
93 if not libs[0].moveDist(*movl) :
94 print (
"WARNING: no",movl[0],
"in lib")
96 if (len(options.moveE) > 0) :
97 for move
in options.moveE :
98 print (
"Moving bin:",move)
99 movl = map(float,move.split(
":"))
100 if not libs[0].moveEta(*movl) :
101 print (
"WARNING: no",movl[0],
"in lib")
103 if (len(options.removeD) > 0) :
104 for move
in options.removeD :
105 print (
"Removing bin:",move)
107 if not libs[0].removeDist(movl) :
108 print (
"WARNING: no",movl,
"in lib")
110 if (len(options.removeE) > 0) :
111 for move
in options.removeE :
112 print (
"Removing bin:",move)
114 if not libs[0].removeEta(movl) :
115 print (
"WARNING: no",movl,
"in lib")
117 if (len(options.output) > 0) :
118 print (
"INFO: Saving file",options.output)
122 print (
"INFO: Drawing lib",options.output)
123 from ROOT
import TCanvas
124 from ROOT
import gROOT, gStyle,gPad
126 gROOT.SetStyle(
"Plain")
129 gStyle.SetNumberContours(50)
131 c1 = TCanvas(
'c1',
"Library Viewer")
135 hits,containmentZ,containmentR = libs[0].drawHits()
138 containmentZ.SetMarkerColor(2)
139 containmentZ.Draw(
"SAME")
140 containmentR.SetMarkerColor(4)
141 containmentR.Draw(
"SAME")
143 from time
import sleep