Skip to content

Commit 707a2d8

Browse files
committed
more fixes
1 parent abc1bc4 commit 707a2d8

File tree

11 files changed

+198
-130
lines changed

11 files changed

+198
-130
lines changed

.aux/test_with_lcg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ source /cvmfs/sft.cern.ch/lcg/views/${LCG}/${CMTCONFIG}/setup.sh
55
source build/INSTALL/thisostap.sh
66
cd build
77

8-
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j4 --output-on-failure --test-output-size-failed 5000000
8+
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j4 -R '(tmva|chop)' --output-on-failure --test-output-size-failed 5000000

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ message ( " ********************************************************************
4646
set(OSTAP_VERSION_MAJOR 3)
4747
set(OSTAP_VERSION_MINOR 0)
4848
set(OSTAP_VERSION_PATCH 2)
49-
set(OSTAP_VERSION_TWEAK 12)
49+
set(OSTAP_VERSION_TWEAK 14)
5050

5151
set(OSTAP_VERSION ${OSTAP_VERSION_MAJOR}.${OSTAP_VERSION_MINOR}.${OSTAP_VERSION_PATCH}.${OSTAP_VERSION_TWEAK})
5252

ReleaseNotes/release_notes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
# v3.0.2.12
2+
13
## New features
24

35
1. (Re)add multiple projections to 1D histogram for `DataFrame`
46
1. Add `errors` optional argument for `TH1.vmin/vmax/vminmax` methods
57
1. Add `control_plots_signal` and `control_plots_background` argument for TMVA&Chopping `Trainer` classes
6-
8+
1. Improve treatment of ROC-curves in TMVA. Now multigpraph is saved into ROOT output file
9+
1. Improve treatment of control plots in TMVA. Now control histos are saved into ROOT output file
10+
1. Improve `Canvas` context manager
11+
1. Switch the ownership of Ostap-canvas to python
12+
713
## Backward-incompatible
814

915
## Bug fixes

ReleaseNotes/v3.0.2.12.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

ReleaseNotes/v3.0.2.14.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# v3.0.2.14
2+
3+
## New features
4+
5+
1. (Re)add multiple projections to 1D histogram for `DataFrame`
6+
1. Add `errors` optional argument for `TH1.vmin/vmax/vminmax` methods
7+
1. Add `control_plots_signal` and `control_plots_background` argument for TMVA&Chopping `Trainer` classes
8+
1. Improve treatment of ROC-curves in TMVA. Now multigpraph is saved into ROOT output file
9+
1. Improve treatment of control plots in TMVA. Now control histos are saved into ROOT output file
10+
1. Improve `Canvas` context manager
11+
1. Switch the ownership of Ostap-canvas to python
12+
13+
## Backward-incompatible
14+
15+
## Bug fixes
16+
17+
1. fix a sad typo in `TH1.vmin/vmax/vminmax` methods

ostap/plotting/canvas.py

Lines changed: 85 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
'setWebDisplay' , ## set WebDisplay, see ROOT.TROOT.SetWebDisplay
2727
'use_pad' , ## context manager to modifty TPad
2828
'KeepCanvas' , ## context manager to keep/preserve currect canvas
29-
'keepCanvas' , ## context manager to keep/preserve currect canvas
29+
'InvisibleCanvas' , ## context manager to keep/preserve currect canvas
3030
'Canvas' , ## context manager to create currect canvas
3131
'use_canvas' , ## context manager to create currect canvas
32-
'KeepCanvas' , ## context manager to keep the current ROOT canvas
3332
'keepCanvas' , ## context manager to keep the current ROOT canvas
34-
'InvisibleCanvas' , ## context manager to use the invisible current ROOT canvas
3533
'invisibleCanvas' , ## context manager to use the invisible current ROOT canvas
3634
##
3735
)
@@ -40,12 +38,13 @@
4038
from ostap.utils.cidict import cidict, cidict_fun
4139
from ostap.core.core import rootWarning, Ostap
4240
from ostap.utils.utils import which
41+
from ostap.utils.root_utils import Batch
4342
from ostap.utils.timing import Wait
4443
from ostap.plotting.makestyles import ( canvas_width , canvas_height ,
4544
margin_left , margin_right ,
4645
margin_top , margin_bottom )
46+
from ostap.plotting.style import UseStyle
4747
import ostap.core.core
48-
import ostap.plotting.style
4948
import ROOT, os, tempfile, math
5049
# =============================================================================
5150
# logging
@@ -190,17 +189,17 @@ def old_canvas ( self ) :
190189
def current ( self ) :
191190
"""`current` : get the pointer to the current TCanvas
192191
"""
193-
return Ostap.Utils.get_canvas()
192+
return self.current_canvas
194193

195194
@property
196195
def current_canvas ( self ) :
197-
"""`current_canvas` : get the pointer to the current TCanvas
196+
"""`current_canvas` : get the current TCanvas
198197
"""
199198
return Ostap.Utils.get_canvas()
200199

201200
@property
202201
def current_pad ( self ) :
203-
"""`current_pad` : get the pointer to the current TPad
202+
"""`current_pad` : get the current TPad
204203
"""
205204
return Ostap.Utils.get_pad ()
206205

@@ -210,12 +209,12 @@ def current_pad ( self ) :
210209
# with keepCanvas() :
211210
# ... do something here
212211
# @endcode
213-
def keepCanvas() :
212+
def keepCanvas ( *args , **kwargs ) :
214213
""" Keep the current canvas
215214
>>> with keepCanvas() :
216215
... do something here
217216
"""
218-
return KeepCanvas()
217+
return KeepCanvas( *args , **kwargs )
219218

220219
# =============================================================================
221220
## @class InvisibleCanvas
@@ -1166,27 +1165,36 @@ class UsePad(object) :
11661165
""" Helper context manager for `TAttPad` objects
11671166
- see `TAttPad`
11681167
"""
1169-
11701168
def __init__ ( self , pad = None , **config ) :
11711169

11721170
self.__pad = pad if ( pad and isinstance ( pad , ROOT.TAttPad ) ) else None
11731171
self.__config = config
11741172
self.__changed = {}
1175-
1173+
1174+
## Context manager: ENTER
11761175
def __enter__ ( self ) :
1177-
1176+
""" Context manager: ENTER
1177+
Apply modification to the TPad
1178+
"""
1179+
11781180
if not self.__pad : self.__pad = Ostap.Utils.get_pad()
11791181

11801182
if self.pad :
11811183
self.__changed = set_pad ( self.pad , **self.config )
11821184

11831185
return self
11841186

1187+
## Context manager: EXIT
11851188
def __exit__ ( self , *_ ) :
1186-
1189+
""" Context manager: EXIT
1190+
Restore configuration of TPad
1191+
"""
1192+
11871193
if self.pad and self.changed :
11881194
set_pad ( self.pad , **self.changed )
1189-
1195+
1196+
self.__pad = None
1197+
11901198
@property
11911199
def pad ( self ) :
11921200
"""`pad' : pad to be configured"""
@@ -1220,43 +1228,57 @@ def use_pad ( pad , **config ) :
12201228
# with Canvas ( title = 'Canvas #2' , width = 1000 ) :
12211229
# ...
12221230
# @endcode
1223-
class Canvas(KeepCanvas) :
1231+
class Canvas(KeepCanvas,UseStyle,UsePad,Batch) :
12241232
""" Helper context manager to create and configure a canvas (and pad)
12251233
>>> with Canvas ( title = 'Canvas #2' , width = 1000 ) :
12261234
>>> ...
12271235
"""
1228-
def __init__ ( self ,
1229-
name = '' ,
1230-
title = '' ,
1231-
width = canvas_width , ## canvas width
1232-
height = canvas_height , ## canvas height
1233-
wait = 0 , ## pause before exit
1234-
keep = True , ## keep canvas open ?
1235-
plot = '' , ## produce the plot at __exit__
1236-
**kwargs ) : ## Pad configuration
1236+
def __init__ ( self ,
1237+
name = '' ,
1238+
title = '' ,
1239+
width = canvas_width , ## canvas width
1240+
height = canvas_height , ## canvas height
1241+
wait = 0 , ## pause before exit
1242+
keep = True , ## keep canvas open ?
1243+
plot = '' , ## produce the plot at __exit__
1244+
invisible = False , ## invisible (==batch)?
1245+
style = None , ## use this style
1246+
**kwargs ) : ## Pad configuration
12371247

12381248
self.__name = name
12391249
self.__title = title
12401250
self.__width = width
12411251
self.__height = height
1242-
self.__kwargs = kwargs
12431252
self.__keep = True if keep else False
12441253
self.__cnv = None
12451254

12461255
if plot is True : plot = name if name else 'plot'
12471256

12481257
if plot : plot = plot.strip().replace ( ' ' , '_' )
12491258

1250-
self.__plot = plot
1251-
##
1252-
KeepCanvas.__init__ ( self , wait )
1259+
self.__plot = plot
1260+
##
1261+
self.__invisible = True if invisible else False
1262+
if not self.__invisible :
1263+
groot = ROOT.ROOT.GetROOT()
1264+
if groot : self.__invisible = groot.IsBatch()
1265+
1266+
self.__style = style
12531267

1268+
##
1269+
KeepCanvas.__init__ ( self , wait )
1270+
UseStyle .__init__ ( self , self.__style )
1271+
UsePad .__init__ ( self , **kwargs )
1272+
Batch .__init__ ( self , self.__invisible )
1273+
12541274
## context manager: exit
12551275
def __enter__ ( self ) :
12561276

12571277
## (1) use context manager
12581278
KeepCanvas.__enter__ ( self )
1259-
1279+
UseStyle .__enter__ ( self )
1280+
Batch .__enter__ ( self )
1281+
12601282
if not self.__name :
12611283
groot = ROOT.ROOT.GetROOT()
12621284
cnvlst = groot.GetListOfCanvases()
@@ -1266,7 +1288,7 @@ def __enter__ ( self ) :
12661288
self.__name = 'gl_canvas#%d' % hash ( h )
12671289

12681290
if not self.__title :
1269-
self.__title = self.__name
1291+
self.__title = 'Ostap Canvas %s' % self.__name
12701292

12711293
## (2) create/use new canvas
12721294
self.__cnv = getCanvas ( name = self.__name ,
@@ -1280,13 +1302,12 @@ def __enter__ ( self ) :
12801302
## (3) make it active
12811303
self.__cnv.cd()
12821304

1283-
## (4) apply pad settings
1284-
if self.__kwargs :
1285-
pad = Ostap.Utils.get_pad()
1286-
if pad : set_pad ( pad , **self.__kwargs )
1287-
1305+
## (4) apply the pad modifications : it must be after (3)
1306+
UsePad.__enter__ ( self )
1307+
12881308
## (5) keep it open ?
1289-
if self.__keep : _keep.append ( self.__cnv )
1309+
if self.__keep :
1310+
_keep.append ( self.__cnv )
12901311

12911312
return self.__cnv ## return current canvas
12921313

@@ -1302,8 +1323,15 @@ def __exit__ ( self , *_ ) :
13021323
if self.__plot :
13031324
self.__cnv >> self.__plot
13041325

1305-
## switch to the previous canvas
1306-
KeepCanvas.__exit__ ( self , *_ )
1326+
## swith back to pad configuration
1327+
UsePad .__exit__ ( self , *_ )
1328+
## switch back to batch regine
1329+
Batch .__exit__ ( self , *_ )
1330+
## swith back to old style
1331+
UseStyle.__exit__ ( self , *_ )
1332+
## switch to the previous canvas
1333+
KeepCanvas.__exit__ ( self , *_ )
1334+
##
13071335
self.__cnv = None
13081336

13091337
# =============================================================================
@@ -1312,27 +1340,30 @@ def __exit__ ( self , *_ ) :
13121340
# with use_canvas ( title = 'Canvas #2' , width = 1000 ) :
13131341
# ...
13141342
# @endcode
1315-
def use_canvas ( name = '' ,
1316-
title = '' ,
1317-
width = canvas_width , ## canvas width
1318-
height = canvas_height , ## canvas height
1319-
wait = 0 , ## pause before exit
1320-
keep = True , ## keep canvas open ?
1321-
**kwargs ) : ## Pad configuration
1343+
def use_canvas ( name = '' ,
1344+
title = '' ,
1345+
width = canvas_width , ## canvas width
1346+
height = canvas_height , ## canvas height
1347+
wait = 0 , ## pause before exit
1348+
keep = True , ## keep canvas open ?
1349+
plot = '' , ## print canvas as the exit
1350+
invisible = False , ## invisible (==batch)?
1351+
style = None , ## use this style
1352+
**kwargs ) : ## Pad configuration
13221353
""" Helper context manager to create and configure a canvas (and pad)
13231354
>>> with use_canvas ( title = 'Canvas #2' , width = 1000 ) :
13241355
>>> ...
13251356
"""
1326-
return Canvas ( name = name ,
1327-
title = title ,
1328-
width = width , ## canvas width
1329-
height = height , ## canvas height
1330-
wait = wait , ## pause before exit
1331-
keep = keep , ## keep canvas open?
1332-
**kwargs ) ## Pad configuration
1333-
1357+
return Canvas ( name = name , ## canvas name
1358+
title = title , ## canvas title
1359+
width = width , ## canvas width
1360+
height = height , ## canvas height
1361+
wait = wait , ## pause before exit
1362+
keep = keep , ## keep canvas open?
1363+
invisible = invisible , ## invisble/batch
1364+
style = style , ## use this style
1365+
**kwargs ) ## Pad configuration
13341366

1335-
13361367
# =============================================================================
13371368
_decorated_classes_ = (
13381369
ROOT.TVirtualPad ,

ostap/plotting/makestyles.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -884,28 +884,29 @@ def make_ostap_style ( name ,
884884
conf [ 'TitleFont_Y' ] = get_int ( config , 'TitleFont_Y' , font )
885885
conf [ 'TitleFont_Z' ] = get_int ( config , 'TitleFont_Z' , font )
886886

887-
conf [ 'TitleFontSize' ] = get_int ( config , 'TitleFontSize' , 0.0 * scale )
887+
conf [ 'TitleFontSize' ] = get_int ( config , 'TitleFontSize' , 0.05 * scale )
888888

889-
conf [ 'TitleH' ] = get_float ( config , 'TitleH' , 0.0 )
890889

891890
conf [ 'TitleOffset_X' ] = get_float ( config , 'TitleOffset_X' , 1.0 )
892891
conf [ 'TitleOffset_Y' ] = get_float ( config , 'TitleOffset_Y' , 0.0 ) ## NB!!
893892
conf [ 'TitleOffset_Z' ] = get_float ( config , 'TitleOffset_Z' , 1.0 )
894893

895894
conf [ 'TitlePS' ] = get_str ( config , 'TitlePS' , '' )
896895

897-
conf [ 'TitleSize_X' ] = get_float ( config , 'TitleSize_X' , -1.0 * scale )
896+
conf [ 'TitleSize_X' ] = get_float ( config , 'TitleSize_X' , 0.05 * scale )
898897
conf [ 'TitleSize_Y' ] = get_float ( config , 'TitleSize_Y' , 0.05 * scale )
899898
conf [ 'TitleSize_Z' ] = get_float ( config , 'TitleSize_Z' , 0.05 * scale )
900899

901900
conf [ 'TitleStyle' ] = get_int ( config , 'TitleStyle' , 1001 )
902901
conf [ 'TitleTextColor' ] = get_int ( config , 'TitleTextColor' , 1 )
902+
903+
conf [ 'TitleX' ] = get_float ( config , 'TitleX' , 0.05 )
904+
conf [ 'TitleY' ] = get_float ( config , 'TitleY' , 0.95 )
905+
conf [ 'TitleW' ] = get_float ( config , 'TitleW' , 0.0 )
906+
conf [ 'TitleH' ] = get_float ( config , 'TitleH' , 0.0 )
903907

904-
conf [ 'TitleW' ] = get_float ( config , 'TitleW' , 0.0 )
905-
conf [ 'TitleX' ] = get_float ( config , 'TitleX' , 0.01 )
906908
conf [ 'TitleXOffset' ] = get_float ( config , 'TitleXOffset' , 1.0 )
907-
conf [ 'TitleXSize' ] = get_float ( config , 'TitleXSize' , -1.0 * scale )
908-
conf [ 'TitleY' ] = get_float ( config , 'TitleY' , 0.99 * scale )
909+
conf [ 'TitleXSize' ] = get_float ( config , 'TitleXSize' , 0.05 * scale )
909910
conf [ 'TitleYOffset' ] = get_float ( config , 'TitleYOffset' , 0.0 * scale )
910911
conf [ 'TitleYSize' ] = get_float ( config , 'TitleYSize' , 0.05 * scale )
911912

ostap/tools/tests/test_tools_chopping.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@
169169
background_train_fraction = 0.85 ,
170170
##
171171
control_plots_signal = [
172-
( ROOT.TH1F ( hID() , 'control var1' , 100 , -3 , 3 ) , 'var1' ) ,
173-
( ROOT.TH1F ( hID() , 'control var1' , 100 , -3 , 3 ) , 'var2' ) ,
174-
( ROOT.TH1F ( hID() , 'control var3' , 100 , -3 , 3 ) , 'var3' ) ,
172+
( ROOT.TH1F ( hID() , '' , 100 , -3 , 3 ) , 'var1' ) ,
173+
( ROOT.TH1F ( hID() , '' , 100 , -3 , 3 ) , 'var2' ) ,
174+
( ROOT.TH1F ( hID() , '' , 100 , -3 , 3 ) , 'var3' ) ,
175175
] ,
176176
control_plots_background = [
177-
( ROOT.TH2F ( hID() , 'control var1,var2' , 30 , -3, 3 , 30 , -3, 3 ) , 'var1,var2' )
177+
( ROOT.TH2F ( hID() , '' , 30 , -3, 3 , 30 , -3, 3 ) , 'var1,var2' )
178178
] ,
179179
##
180180
##
@@ -205,7 +205,6 @@
205205
# but it is very flexible and powerful with respect to variable transformations
206206
# =============================================================================
207207

208-
209208
# =============================================================================
210209
## A) Add TMVA/Chopping decision to (input) TTrees
211210
# =============================================================================

0 commit comments

Comments
 (0)