ATLAS Offline Software
Loading...
Searching...
No Matches
LArG4ShowerLibProcessing.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
4#
5# $Id: LArG4ShowerLibProcessing.py 711210 2015-11-27 15:56:00Z jchapman $
6#
7# python script for merging libs
8#
9
10
11__version__ = '$Revision: 711210 $'
12__author__ = 'Radist Morse radist.morse@gmail.com'
13__doc__ = 'Script for merging FS libs'
14
15import sys
16import logging
17from optparse import OptionParser
18from LArG4GenShowerLib.LArG4ShowerLibFunctions import \
19 EtaEnergyShowerLib, TestShowerLib, FCALDistShowerLib, FCALDistEtaShowerLib
20
21usage = "usage: %prog [options] lib1 [lib2 ...]"
22
23parser = OptionParser(usage=usage, version="%prog v0.0.1 $Id: LArG4ShowerLibProcessing.py 711210 2015-11-27 15:56:00Z jchapman $")
24
25#parser.add_option("-o","--output", dest="outfile", help="Name of output file (default: %default)")
26parser.add_option("-i","--info",dest="info", action="store_true", help="Print info about the lib(s)")
27parser.add_option("-a","--add",dest="add", action="store_true", help="Add input libs together")
28parser.add_option("-o","--output",dest="output", help="Name of output file")
29parser.add_option("-s","--scale",dest="scale", type = float, help="Scale library by energy")
30parser.add_option("-d","--moveDist",dest="moveD", action="append", help="move dist bin")
31parser.add_option("-e","--moveEta",dest="moveE", action="append", help="move eta bin")
32parser.add_option("--removeDist",dest="removeD", action="append", help="remove dist bin")
33parser.add_option("--removeEta",dest="removeE", action="append", help="remove eta bin")
34parser.add_option("-t","--truncate",dest="truncate", type = int, help="truncate lib")
35parser.add_option("-p","--paint",dest="draw", action="store_true", help="paint hits distribution histogram")
36parser.add_option('--log', dest="loglevel", help='Logging level. Use \"--log debug\" to debug the library content step-by-step' )
37
38parser.set_defaults(info = False, add = False, output = "", scale = 0.0, moveD = [], moveE = [], removeD = [], removeE = [], draw = False, truncate = 0, loglevel="info")
39
40(options, args) = parser.parse_args()
41
42logging.basicConfig(stream=sys.stdout,level=options.loglevel.upper() )
43log=logging.getLogger("LArG4ShowerLibProcessing.py")
44
45if len(args) == 0:
46 log.error("No input specified")
47 sys.exit(1)
48
49libs = []
50
51for filename in args:
52 log.info("Reading file %s",filename)
53 tmplib = EtaEnergyShowerLib()
54 if tmplib.readFromFile(filename) :
55 libs.append(tmplib)
56 tmplib = TestShowerLib()
57 if tmplib.readFromFile(filename) :
58 libs.append(tmplib)
59 tmplib = FCALDistShowerLib()
60 if tmplib.readFromFile(filename) :
61 libs.append(tmplib)
62 tmplib = FCALDistEtaShowerLib()
63 if tmplib.readFromFile(filename) :
64 libs.append(tmplib)
65
66if (options.truncate > 0) :
67 for lib in libs :
68 lib.truncate(options.truncate)
69
70if (options.info) :
71 for arg,lib in zip(args,libs) :
72 print ("LIB",arg)
73 lib.printInfo()
74
75if (options.add and len(libs) > 1) :
76 print ("INFO: Adding libs")
77 outlib = libs[0].__class__()
78 if not outlib.fromLibs(libs) :
79 print ("ABORTING")
80 sys.exit(1)
81 del libs
82 libs = []
83 libs.append(outlib)
84
85if (options.scale > 0) :
86 print ("Scaling to",options.scale)
87 libs[0].scaleEnergy(options.scale)
88
89if (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")
95
96if (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")
102
103if (len(options.removeD) > 0) :
104 for move in options.removeD :
105 print ("Removing bin:",move)
106 movl = float(move)
107 if not libs[0].removeDist(movl) :
108 print ("WARNING: no",movl,"in lib")
109
110if (len(options.removeE) > 0) :
111 for move in options.removeE :
112 print ("Removing bin:",move)
113 movl = float(move)
114 if not libs[0].removeEta(movl) :
115 print ("WARNING: no",movl,"in lib")
116
117if (len(options.output) > 0) :
118 print ("INFO: Saving file",options.output)
119 libs[0].writeToFile(options.output)
120
121if (options.draw) :
122 print ("INFO: Drawing lib",options.output)
123 from ROOT import TCanvas
124 from ROOT import gROOT, gStyle,gPad
125 gROOT.Reset()
126 gROOT.SetStyle("Plain")
127 gStyle.SetOptStat(0)
128 gStyle.SetPalette(1)
129 gStyle.SetNumberContours(50)
130
131 c1 = TCanvas( 'c1', "Library Viewer")
132 #gStyle.SetOptLogx(1)
133 gPad.SetLogx(1)
134
135 hits,containmentZ,containmentR = libs[0].drawHits()
136
137 hits.Draw()
138 containmentZ.SetMarkerColor(2)
139 containmentZ.Draw("SAME")
140 containmentR.SetMarkerColor(4)
141 containmentR.Draw("SAME")
142 c1.Update()
143 from time import sleep
144 while not not(c1) :
145 sleep(1)
STL class.