-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathframeanal.py
executable file
·525 lines (444 loc) · 22 KB
/
frameanal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#!/usr/bin/python
"""
@run:
./frameanal.py Test.seq
@brief:
The code reads the root file produced for a IR camera temperature image, find
the cooling pipe temperature profile which is used to detect the potential flaws
on the stave.
@functions (class FrameAnalysis):
__init__ (roo_name, cfg_name = "config_frame", fig_outdir = "plot") :
Constructor providing the input root file name, roo_name;
config file name, cfg_name and output figure folder name, fig_outdir.
In the config file, set the parameters:
- Set the stave starting (X0, Y0) and ending (X1, Y1) pixel indexes, and
similarly for pipe region.
- Set the CM per pixel value, which depends on the IR camera and its lens.
- Set StaveSideL = 0 or 1 to indicate if the initial stave is on L (1) or
J (0) side. In the case of L side, it is flipped to look like J side.
- Set LiquidTLow = 0 or 1 to indicate if the liquid passing the cooling
pipe is below (1) or above (0) room temperature.
- Set the minimum and maximum temperature for plotting the raw frame,
stave region and pipe region.
draw_frames():
Draw the 2D temperature profile for the raw image, stave region and pipe region
fit_hist(h1):
Fit a gaussian to the input 1D histogram, h1. The X axis of h1 is the pixel number
from Y axis of the pipe region 2D image at a each X axis point. The Y axis of h1
is the temperature values at the point.
The fit returns a tuple: (temperature, mean position, width, chi2, ndf)
The returned temperature is the measurement of the cooling pipe temperature at that
point.
find_pipes():
Find the cooling pipes on the pipe region image. Make plots of the temperature
distribution along the cooling pipe, together with the fitted result of the mean
position, peak width, chi2 and NDF.
@notes:
This code assumes using python 2.7.10
It doesn't work for python 3.x, because ROOT support is not guaranteed.
@reference:
TTree in python:
https://www-zeuthen.desy.de/~middell/public/pyroot/pyroot.html
https://root.cern.ch/how/how-write-ttree-python
@email: [email protected]
"""
import sys # system
import os # operating system
import numpy # number in python
import math # math
import ROOT # ROOT from CERN
import configFinder as cf
class FrameAnalysis:
"""
To find out the possible flaws on a stave, one needs to check the non-uniformity on the cooling pipe temperature
profile.
A stave recorded by IR camera is characterized with its frame diameter from bottom left corner to top right corner.
It should look like:
A raw "J" side IR camera 'photo'
| -----------------------------------|
| |
| Stave |
| ---- .............. (X1, Y1) |
| | | |
| | --------------- Pipe |
| |-----------------| (X1, Y1) |
| Pipe| | |
| (X0,|-----------------| |
| Y0)------------------- |
| Stave |
| (X0, Y0) |
| |
| -----------------------------------|
A raw "L" side image is flipped to look like "J" side above.
A stave contains the whole stave including the end of stave card, indicated as Stave (X0, Y0) --> (X1, Y0)
A pipe part of the stave contains the pipe region, indicated as Pipe (X0, Y0) --> (X1, Y0)
The cooling pipe temperature is extracted from the Pipe frame.
"""
_parameters = {
"StavePixelX0": 0, # stave position in pixel index
"StavePixelY0": 0,
"StavePixelX1": 0,
"StavePixelY1": 0,
"PipePixelX0": 0, # pipe position in pixel index
"PipePixelY0": 0,
"PipePixelX1": 0,
"PipePixelY1": 0,
"CMperPixel": 0, # cm per pixel, specific for camera
"StaveSideL": 0, # 0: "J", 1: "L". Sides "J" or "L" based on the rotation of the end of stave card
"LiquidTLow": 0, # 0: higher than room temperature, 1: lower than room temperature
"FrameTmax": -999., # for plotting, set the maximum and minimum Temperature
"FrameTmin": 999., # use arbitrary value if these parameters are not set
"StaveTmax": -999., # Frame = raw frame, Stave = stave region, Pipe = pipe region
"StaveTmin": 999.,
"PipeTmax": -999.,
"PipeTmin": 999.,
}
def __init__ (self, roo_name, cfg_name = "config_frame", fig_outdir = "plot", bolFindConfig = True, bol14ModCore = False) :
#
# better run root on batch mode
#
ROOT.gROOT.SetBatch()
#
# create the output folders if not exist yet
#
self._fig_outdir = fig_outdir
if not os.path.isdir( fig_outdir ):
os.mkdir( fig_outdir )
self._hist_outdir = self._fig_outdir + "/hist"
if not os.path.isdir( self._hist_outdir ):
os.mkdir( self._hist_outdir )
self._fit_outdir = self._fig_outdir + "/fit"
if not os.path.isdir( self._fit_outdir ):
os.mkdir( self._fit_outdir )
if bolFindConfig == True:
print ("Usage: Finding frame configuration...")
cf.FindPoints( roo_name, cfg_name, fig_outdir, bol14ModCore)
if not os.path.isfile( cfg_name ):
print ("ERROR:<FRAMEANALYSIS::__INIT__> config file " + cfg_name + " not found.")
raise Exception(" Config file error! ")
if bolFindConfig == True:
os.system('cp '+cfg_name+' '+fig_outdir+'/'+cfg_name)
frame_name = roo_name.split('/')[-1]
os.system('cp '+roo_name+' '+fig_outdir+'/'+frame_name)
_f_cfg = open( cfg_name, 'r')
for line in _f_cfg:
#
# skip empty line or started with '#'
#
if ( len(line) <= 0 ) or line.startswith( '#' ) :
continue
item_val = line.split()
if ( len(item_val) != 2 ):
print ("ERROR:<FRAMEANALYSIS::__INIT__> config items expected to be: Item Value. Not the correct style: " + line + ".")
raise Exception(" Config file style error! ")
item = item_val[0]
value = float( item_val[1] )
print ("TEST, "+item+", value " + str(value) )
self._parameters[ item ] = value
print ("INFO:<FRAMEANALYSIS::__INIT__> the list of the parameters below: ")
if (self._parameters[ "CMperPixel" ] <= 0) or (self._parameters[ "StavePixelX1" ] <= 0) or (self._parameters[ "PipePixelX1" ] <= 0):
raise Exception(" Config parameter error! ")
if (self._parameters[ "StavePixelX0" ] > self._parameters[ "PipePixelX0" ] > 0) or (self._parameters[ "StavePixelX1" ] < self._parameters[ "PipePixelX1" ] > 0):
raise Exception(" Stave and pipe pixel not matched error! ")
self._nxpixel_stave = int(self._parameters[ "StavePixelX1" ]) - int(self._parameters[ "StavePixelX0" ]) + 1
self._nypixel_stave = int(self._parameters[ "StavePixelY1" ]) - int(self._parameters[ "StavePixelY0" ]) + 1
self._nxpixel_pipe = int(self._parameters[ "PipePixelX1" ] ) - int(self._parameters[ "PipePixelX0" ] ) + 1
self._nypixel_pipe = int(self._parameters[ "PipePixelY1" ] ) - int(self._parameters[ "PipePixelY0" ] ) + 1
#
# conversion from pixel to CM, pipe should use the same diameter as in Stave's coordinates
#
self._X0_pipe = self._parameters[ "CMperPixel" ] * ( self._parameters[ "PipePixelX0" ] - self._parameters[ "StavePixelX0" ] )
self._Y0_pipe = self._parameters[ "CMperPixel" ] * ( self._parameters[ "PipePixelY0" ] - self._parameters[ "StavePixelY0" ] )
self._X1_pipe = self._parameters[ "CMperPixel" ] * self._nxpixel_pipe + self._X0_pipe
self._Y1_pipe = self._parameters[ "CMperPixel" ] * self._nypixel_pipe + self._Y0_pipe
#
# loop over the parameter keys
#
for par in self._parameters:
val = self._parameters[ par ]
print ("INFO:<FRAMEANALYSIS::__INIT__> " + par + " = " + str( val ) )
#
# read the input root file
#
if not os.path.isfile( roo_name ):
print ("ERROR:<FRAMEANALYSIS::__INIT__> root input file " + roo_name + " not found.")
raise Exception(" Root input file error! ")
_f_roo = ROOT.TFile( roo_name, "read" );
_btree = _f_roo.Get("btree");
_nxpixel = numpy.zeros(1, dtype=int)
_nypixel = numpy.zeros(1, dtype=int)
_btree.SetBranchAddress( "nxpixel", _nxpixel )
_btree.SetBranchAddress( "nypixel", _nypixel )
_btree.GetEntry( 0 )
if (_nxpixel[0] <=0) or (_nypixel[0] <=0):
print ("ERROR:<FRAMEANALYSIS::__INIT__> number of pixels in X and/or Y not obtained.")
raise Exception(" Number of pixels not set!")
if ( self._parameters[ "StavePixelX1" ] >= _nxpixel[0] ) or ( self._parameters[ "StavePixelY1" ] >= _nypixel[0] ):
raise Exception(" Stave pixel index overflowed error! ")
self._nxpixel_raw = _nxpixel[0]
self._nypixel_raw = _nypixel[0]
#
# Temperature in 2D for the whole raw figure T[y][x] initialized with -999 C.
#
self.stave_temperature_2d = [[ -999. for x in range( _nxpixel[0] )] for y in range( _nypixel[0] )]
_atree = _f_roo.Get("atree");
_xpos = numpy.zeros(1, dtype=int)
_ypos = numpy.zeros(1, dtype=int)
_temperature = numpy.zeros(1, dtype=float)
_atree.SetBranchAddress( "xpos", _xpos )
_atree.SetBranchAddress( "ypos", _ypos )
_atree.SetBranchAddress( "temperature", _temperature )
_n_entries = _atree.GetEntries()
for ientry in range( _n_entries ):
_atree.GetEntry( ientry )
if ( self._parameters[ "StaveSideL" ] ):
#
# for L side, use a mirror image for Y axis to present the stave as J side
#
_ypos_mr = _nypixel[0] - _ypos[0] - 1
self.stave_temperature_2d[ _ypos_mr ][ _xpos[0] ] = _temperature[0]
else:
self.stave_temperature_2d[ _ypos[0] ][ _xpos[0] ] = _temperature[0]
_f_roo.Close()
def draw_frames(self):
"""
@brief: draw 2D Temperature frames
raw frame: including all pixels
stave frame: only the stave area
pipe frame: only the pipe area
"""
_Xcm_frame = self._parameters[ "CMperPixel" ] * self._nxpixel_raw
_Ycm_frame = self._parameters[ "CMperPixel" ] * self._nypixel_raw
_h2_frame = ROOT.TH2F( "frame", ";X in cm; Y in cm; Temperature (#circC)", self._nxpixel_raw, 0., _Xcm_frame, self._nypixel_raw, 0., _Ycm_frame )
_Xcm_stave = self._parameters[ "CMperPixel" ] * self._nxpixel_stave
_Ycm_stave = self._parameters[ "CMperPixel" ] * self._nypixel_stave
_h2_stave = ROOT.TH2F( "stave", ";X in cm; Y in cm; Temperature (#circC)", self._nxpixel_stave, 0., _Xcm_stave, self._nypixel_stave, 0., _Ycm_stave )
_h2_pipe = ROOT.TH2F( "pipe", ";X in cm; Y in cm; Temperature (#circC)", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe, self._nypixel_pipe, self._Y0_pipe, self._Y1_pipe )
if ( self._parameters[ "FrameTmax" ] > -998. ):
_h2_frame.SetMaximum( self._parameters[ "FrameTmax" ] )
if ( self._parameters[ "FrameTmin" ] < 998. ):
_h2_frame.SetMinimum( self._parameters[ "FrameTmin" ] )
if ( self._parameters[ "StaveTmax" ] > -998. ):
_h2_stave.SetMaximum( self._parameters[ "StaveTmax" ] )
if ( self._parameters[ "StaveTmin" ] < 998. ):
_h2_stave.SetMinimum( self._parameters[ "StaveTmin" ] )
if ( self._parameters[ "PipeTmax" ] > -998. ):
_h2_pipe.SetMaximum( self._parameters[ "PipeTmax" ] )
if ( self._parameters[ "PipeTmin" ] < 998. ):
_h2_pipe.SetMinimum( self._parameters[ "PipeTmin" ] )
for ix in range ( self._nxpixel_raw ) :
for iy in range ( self._nypixel_raw ) :
T = self.stave_temperature_2d[ iy ][ ix ]
_h2_frame.SetBinContent( ix + 1, iy + 1, T);
if ( ix >= self._parameters[ "StavePixelX0" ] ) and ( iy >= self._parameters[ "StavePixelY0" ] ) and \
( ix <= self._parameters[ "StavePixelX1" ] ) and ( iy <= self._parameters[ "StavePixelY1" ] ):
ix_stave = int( ix - self._parameters[ "StavePixelX0" ] + 1 )
iy_stave = int( iy - self._parameters[ "StavePixelY0" ] + 1 )
_h2_stave.SetBinContent( ix_stave, iy_stave, T)
if ( ix >= self._parameters[ "PipePixelX0" ] ) and ( iy >= self._parameters[ "PipePixelY0" ] ) and \
( ix <= self._parameters[ "PipePixelX1" ] ) and ( iy <= self._parameters[ "PipePixelY1" ] ):
ix_pipe = int( ix - self._parameters[ "PipePixelX0" ] + 1 )
iy_pipe = int( iy - self._parameters[ "PipePixelY0" ] + 1 )
_h2_pipe.SetBinContent( ix_pipe, iy_pipe, T)
ROOT.gStyle.SetOptStat(0)
c1 = ROOT.TCanvas( 'c1', '', 800, 600 )
# margin: Float_t left, Float_t right, Float_t bottom, Float_t top
c1.SetMargin( 0.08, 0.15, 0.1, 0.05)
_h2_frame.Draw("colz")
c1.Print( self._fig_outdir + "/frame.png" )
c1.Print( self._fig_outdir + "/frame.pdf" )
c2 = ROOT.TCanvas( 'c2', '', 700, 400 )
c2.SetMargin( 0.0675, 0.12, 0.12, 0.05)
_h2_stave.GetXaxis().SetTitleSize( 1.3 * _h2_stave.GetXaxis().GetTitleSize() );
_h2_stave.GetYaxis().SetTitleSize( 1.3 * _h2_stave.GetYaxis().GetTitleSize() );
_h2_stave.GetYaxis().SetTitleOffset( 0.65 * _h2_stave.GetYaxis().GetTitleOffset() );
_h2_stave.Draw("colz")
c2.Print( self._fig_outdir + "/stave.png" )
c2.Print( self._fig_outdir + "/stave.pdf" )
#c3 = ROOT.TCanvas( 'c3', '', 700, 400 )
#c3.SetMargin( 0.0675, 0.12, 0.12, 0.05)
_h2_pipe.GetXaxis().SetTitleSize( 1.3 * _h2_pipe.GetXaxis().GetTitleSize() );
_h2_pipe.GetYaxis().SetTitleSize( 1.3 * _h2_pipe.GetYaxis().GetTitleSize() );
_h2_pipe.GetYaxis().SetTitleOffset( 0.65 * _h2_pipe.GetYaxis().GetTitleOffset() );
_h2_pipe.Draw("colz")
c2.Print( self._fig_outdir + "/pipe.png" )
c2.Print( self._fig_outdir + "/pipe.pdf" )
def fit_hist(self, h1):
"""
read a 1D histogram, fit to gaussian function, return (mean, mean position, width)
expecting h1 in range [0., n] with n the number of bins
"""
ROOT.gStyle.SetOptStat(0)
cf1 = ROOT.TCanvas( 'cf1', '', 600, 600 )
# margin: Float_t left, Float_t right, Float_t bottom, Float_t top
cf1.SetMargin( 0.1, 0.05, 0.12, 0.05)
h1.GetXaxis().SetTitle( "Y axis in pixels" )
h1.GetYaxis().SetTitle( "Temperature (#circC)")
h1.Draw()
nbins = h1.GetNbinsX()
f1 = ROOT.TF1( "FitGaus", "gaus",0.0, float(nbins) )
if ( self._parameters[ "LiquidTLow" ] > 0 ):
f1.SetParLimits(0, -100., 10.)
else:
f1.SetParLimits(0, 0.00001, 100.);
#constraints on sigma
f1.SetParameter(2, nbins/3. );
f1.SetParLimits(2, nbins/5., nbins * 3 / 4.);
#constraints on peak position
f1.SetParameter(1, nbins/2.);
f1.SetParLimits(1, nbins/4., nbins * 3 / 4.);
h1.Fit(f1,"Q") # Fit(f1,"0") meaning no draw on the canvas
# 3 parameters: temperature, mean, sigma
_pars = numpy.zeros(3, dtype=float)
f1.GetParameters( _pars );
_temp = _pars[0]
_mean = _pars[1]
_width= _pars[2]
_chi2 = f1.GetChisquare()
_ndf = f1.GetNDF()
Tl = ROOT.TLatex()
Tl.SetTextSize(20)
Tl.SetTextFont(43)
Tl.SetNDC()
ss = "#color[4]{Left: #chi^{2}/NDF = %.1f / %d}" % (_chi2, _ndf)
Tl.DrawLatex(0.18, 0.88, ss)
Tl.DrawLatex(0.18, 0.84, ("#color[4]{mean: %5.3f}" % _mean))
Tl.DrawLatex(0.18, 0.80, ("#color[4]{width: %5.3f}" % _width))
Tl.DrawLatex(0.18, 0.76, ("#color[4]{T: %3.1f #circ C}" % _temp))
cf1.Update()
_name = self._fit_outdir + "/h_" + str( h1.GetTitle() ) + ".png"
cf1.Print( _name )
return (_temp, _mean, _width, _chi2, _ndf)
def find_pipes(self):
"""
Find the temperature profile of the cooling pipe. At each point along the cooling pipe, find the minimum ( or maximum depending on the operating
temperature ) along Y axis.
Cooling pipe looks like:
Y -----------
-----------
X ->
where, only the top and bottom pipes are kept. The short pipe turn along the Y axis at right is NOT analyzed so far.
Obtain the cooling pipe temperature as a function of X axis for top and bottom lines. Use the top 40% of the pixels to get the top cooling pipe,
and the bottom 40% of the pixels for the bottom pipe curve.
"""
_roo_out = ROOT.TFile(self._fig_outdir+"/result.root", "recreate")
h1s = [ ROOT.TH1F("top_pipe_temperature", ";X in cm; Temperature (#circC)", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("top_pipe_mean", ";X in cm; Pipe position Y in cm", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("top_pipe_width", ";X in cm; Pipe width Y in cm", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("top_pipe_chi2", ";X in cm; Pipe fit chi2", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("top_pipe_ndf", ";X in cm; Pipe fit ndf", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("bot_pipe_temperature", ";X in cm; Temperature (#circC)", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("bot_pipe_mean", ";X in cm; Pipe position Y in cm", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("bot_pipe_width", ";X in cm; Pipe width Y in cm", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("bot_pipe_chi2", ";X in cm; Pipe fit chi2", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
ROOT.TH1F("bot_pipe_ndf", ";X in cm; Pipe fit ndf", self._nxpixel_pipe, self._X0_pipe, self._X1_pipe),
]
for ix in range ( self._nxpixel_pipe ) :
ix_raw = int ( ix + self._parameters[ "PipePixelX0" ] )
ny_1pipe = int ( 0.4 * self._nypixel_pipe )
#
# pipe using the top and bottom 40% of the pixels
# top: high Y
# bottom: low Y
#
ht1 = ROOT.TH1F( "t"+str(ix), "t"+str(ix), ny_1pipe, 0., float( ny_1pipe ) )
hb1 = ROOT.TH1F( "b"+str(ix), "b"+str(ix), ny_1pipe, 0., float( ny_1pipe ) )
for iy in range ( self._nypixel_pipe ) :
iy_raw = int ( iy + self._parameters[ "PipePixelY0" ] )
if ( iy < ny_1pipe ):
#
# low Y pixel number for bottom curve
#
hb1.SetBinContent( iy + 1, self.stave_temperature_2d[ iy_raw ][ ix_raw ])
hb1.SetBinError( iy + 1, 0.02 * self.stave_temperature_2d[ iy_raw ][ ix_raw ]) # set 2% error
elif ( iy >= int(self._nypixel_pipe - ny_1pipe) ):
#
# high Y pixel number for top curve
#
iy_reset = int(iy - (self._nypixel_pipe - ny_1pipe) + 1 )
ht1.SetBinContent( iy_reset, self.stave_temperature_2d[ iy_raw ][ ix_raw ])
ht1.SetBinError( iy_reset, 0.02 * self.stave_temperature_2d[ iy_raw ][ ix_raw ]) # set 2% error
# returned tuple: (temp, mean, width, chi2, ndf)
_t_data = self.fit_hist( ht1 )
_b_data = self.fit_hist( hb1 )
for idx,val in enumerate(_t_data):
h1s[ idx ].SetBinContent( ix+1, val )
for idx,val in enumerate(_b_data):
jdx = int( idx + 5 )
h1s[ jdx ].SetBinContent( ix+1, val )
c0 = ROOT.TCanvas( 'c0', '', 2000, 600 )
# margin: Float_t left, Float_t right, Float_t bottom, Float_t top
c0.SetMargin( 0.065, 0.03, 0.15, 0.05)
for h1 in h1s:
h1.SetLineWidth(3)
h1.GetXaxis().SetTitleSize( 1.3 * h1.GetXaxis().GetTitleSize() );
h1.GetYaxis().SetTitleSize( 1.3 * h1.GetYaxis().GetTitleSize() );
h1.GetYaxis().SetTitleOffset( 0.65 * h1.GetYaxis().GetTitleOffset() );
h1.Draw()
c0.Print( self._hist_outdir + "/" + h1.GetName() + ".png" )
c0.Print( self._hist_outdir + "/" + h1.GetName() + ".pdf" )
h1.Write()
_roo_out.Close()
def print_usage( s_function):
print ("Usage: " + s_function + " INPUT_ROOT_FILE [CONFIG = config_frame] [OUTDIR = plot]")
print (" -mc : uses the config_frame file in the local directory of the inputroot file")
print (" -14M: searches for a 14 module stave core instead of a 13 module")
def main():
if sys.version_info[0] >= 3:
print ("ERROR:<FRAMEANALYSIS::MAIN> PyROOT only works with Python 2.x. Code Tested with 2.7.10. Current version " + str(sys.version_info[0]) + ".x")
raise Exception(" Python Version too high. Use 2.x. ")
strInputCmds = sys.argv[1:]
if ("-h" in strInputCmds) or ("--help" in strInputCmds):
print_usage( str(sys.argv[0]))
return
bolFindConfig = True
if ("-mc" in strInputCmds) or ("--manualconfig" in strInputCmds):
print ("Usage: Manual configuration override. Will use config settings from config_frame in same dir as inputfile")
bolFindConfig = False
while ("-mc" in strInputCmds):
strInputCmds.remove("-mc")
while ("--manualconfig" in strInputCmds):
strInputCmds.remove("--manualconfig")
bol14ModCore = False
if ("-14M" in strInputCmds) or ("--14modulecore" in strInputCmds):
print("Usage: Assuming 14 module stave core")
bol14ModCore = True
while ("-14M" in strInputCmds):
strInputCmds.remove("-14M")
while ("--14modulecore" in strInputCmds):
strInputCmds.remove("--14modulecore")
else:
print("Usage: Assuming 13 module stave core")
if len(strInputCmds) <= 0:
print ("ERROR:<FRAMEANALYSIS> Please provide: input root file. Missing! Return.")
print_usage( str(sys.argv[0]))
return
elif len(strInputCmds) == 1:
str_inroo = strInputCmds[0]
str_cfg = "config_frame"
str_outdir = "plot"
elif len(strInputCmds) == 2:
str_inroo = strInputCmds[0]
str_cfg = strInputCmds[1]
str_outdir = "plot"
elif len(strInputCmds) == 3:
str_inroo = strInputCmds[0]
str_cfg = strInputCmds[1]
str_outdir = strInputCmds[2]
else:
print ("ERROR:<FRAMEANALYSIS> Too many inputs! Return.")
print_usage( str(sys.argv[0]))
return
if bolFindConfig == False: #Looks for config_frame in same directory as root file and makes all output go into this folder
#get the directory
strInFile = str_inroo.split("/")[-1]
strInDir = str_inroo.replace("/"+strInFile,"")
str_cfg = strInDir + "/" + str_cfg
if str_outdir == 'plot':
str_outdir = strInDir
ist_frmana = FrameAnalysis( str_inroo, str_cfg, str_outdir, bolFindConfig, bol14ModCore )
ist_frmana.draw_frames()
ist_frmana.find_pipes()
print (' Make plots. Done!')
if __name__ == "__main__":
main()