10 from __future__
import print_function
12 __version__ =
'$Revision: 711210 $'
13 __author__ =
'Radist Morse radist.morse@gmail.com'
14 __doc__ =
'Script for merging FS libs'
18 from optparse
import OptionParser
19 from LArG4GenShowerLib.LArG4ShowerLibFunctions
import \
20 EtaEnergyShowerLib, TestShowerLib, FCALDistShowerLib, FCALDistEtaShowerLib
22 usage =
"usage: %prog [options] lib1 [lib2 ...]"
24 parser = OptionParser(usage=usage, version=
"%prog v0.0.1 $Id: LArG4ShowerLibProcessing.py 711210 2015-11-27 15:56:00Z jchapman $")
27 parser.add_option(
"-i",
"--info",dest=
"info", action=
"store_true", help=
"Print info about the lib(s)")
28 parser.add_option(
"-a",
"--add",dest=
"add", action=
"store_true", help=
"Add input libs together")
29 parser.add_option(
"-o",
"--output",dest=
"output", help=
"Name of output file")
30 parser.add_option(
"-s",
"--scale",dest=
"scale", type = float, help=
"Scale library by energy")
31 parser.add_option(
"-d",
"--moveDist",dest=
"moveD", action=
"append", help=
"move dist bin")
32 parser.add_option(
"-e",
"--moveEta",dest=
"moveE", action=
"append", help=
"move eta bin")
33 parser.add_option(
"--removeDist",dest=
"removeD", action=
"append", help=
"remove dist bin")
34 parser.add_option(
"--removeEta",dest=
"removeE", action=
"append", help=
"remove eta bin")
35 parser.add_option(
"-t",
"--truncate",dest=
"truncate", type = int, help=
"truncate lib")
36 parser.add_option(
"-p",
"--paint",dest=
"draw", action=
"store_true", help=
"paint hits distribution histogram")
37 parser.add_option(
'--log', dest=
"loglevel", help=
'Logging level. Use \"--log debug\" to debug the library content step-by-step' )
39 parser.set_defaults(info =
False, add =
False, output =
"", scale = 0.0, moveD = [], moveE = [], removeD = [], removeE = [], draw =
False, truncate = 0, loglevel=
"info")
41 (options, args) = parser.parse_args()
43 logging.basicConfig(stream=sys.stdout,level=options.loglevel.upper() )
44 log=logging.getLogger(
"LArG4ShowerLibProcessing.py")
47 log.error(
"No input specified")
53 log.info(
"Reading file %s",filename)
54 tmplib = EtaEnergyShowerLib()
55 if tmplib.readFromFile(filename) :
57 tmplib = TestShowerLib()
58 if tmplib.readFromFile(filename) :
60 tmplib = FCALDistShowerLib()
61 if tmplib.readFromFile(filename) :
63 tmplib = FCALDistEtaShowerLib()
64 if tmplib.readFromFile(filename) :
67 if (options.truncate > 0) :
69 lib.truncate(options.truncate)
72 for arg,lib
in zip(args,libs) :
76 if (options.add
and len(libs) > 1) :
77 print (
"INFO: Adding libs")
78 outlib = libs[0].__class__()
79 if not outlib.fromLibs(libs) :
86 if (options.scale > 0) :
87 print (
"Scaling to",options.scale)
88 libs[0].scaleEnergy(options.scale)
90 if (len(options.moveD) > 0) :
91 for move
in options.moveD :
92 print (
"Moving bin:",move)
93 movl = map(float,move.split(
":"))
94 if not libs[0].moveDist(*movl) :
95 print (
"WARNING: no",movl[0],
"in lib")
97 if (len(options.moveE) > 0) :
98 for move
in options.moveE :
99 print (
"Moving bin:",move)
100 movl = map(float,move.split(
":"))
101 if not libs[0].moveEta(*movl) :
102 print (
"WARNING: no",movl[0],
"in lib")
104 if (len(options.removeD) > 0) :
105 for move
in options.removeD :
106 print (
"Removing bin:",move)
108 if not libs[0].removeDist(movl) :
109 print (
"WARNING: no",movl,
"in lib")
111 if (len(options.removeE) > 0) :
112 for move
in options.removeE :
113 print (
"Removing bin:",move)
115 if not libs[0].removeEta(movl) :
116 print (
"WARNING: no",movl,
"in lib")
118 if (len(options.output) > 0) :
119 print (
"INFO: Saving file",options.output)
123 print (
"INFO: Drawing lib",options.output)
124 from ROOT
import TCanvas
125 from ROOT
import gROOT, gStyle,gPad
127 gROOT.SetStyle(
"Plain")
130 gStyle.SetNumberContours(50)
132 c1 = TCanvas(
'c1',
"Library Viewer")
136 hits,containmentZ,containmentR = libs[0].drawHits()
139 containmentZ.SetMarkerColor(2)
140 containmentZ.Draw(
"SAME")
141 containmentR.SetMarkerColor(4)
142 containmentR.Draw(
"SAME")
144 from time
import sleep