Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
greenlablib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
greenlab
greenlablib
Commits
e1579c2d
Commit
e1579c2d
authored
1 year ago
by
Arseny Rybnikov
Browse files
Options
Downloads
Patches
Plain Diff
init with readFile, SetBinContent funcs
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
__init__.py
+0
-0
0 additions, 0 deletions
__init__.py
plot.py
+91
-0
91 additions, 0 deletions
plot.py
with
91 additions
and
0 deletions
__init__.py
0 → 100644
+
0
−
0
View file @
e1579c2d
This diff is collapsed.
Click to expand it.
plot.py
0 → 100644
+
91
−
0
View file @
e1579c2d
# ################################################################
# This module intends to simplify ROOT based routines
# ################################################################
# For greenlablib module import use:
# >>> import sys
# >>> sys.path.append('path/to/directory/where/module/is/located')
# >>> from greenlablib import plot as pl
# ################################################################
# Basic includes
import
numpy
as
np
from
array
import
array
# ROOT includes
from
ROOT
import
gROOT
from
ROOT
import
TCanvas
from
ROOT
import
TGraph
from
ROOT
import
TGraphErrors
from
ROOT
import
TH1F
from
ROOT
import
gStyle
from
ROOT
import
gSystem
from
ROOT
import
TBufferJSON
def
improveStyles
():
'''
Improves default ROOT styles
'''
# Stat box format
gStyle
.
SetStatFormat
(
"
4.3f
"
)
gStyle
.
SetFitFormat
(
"
4.3f
"
)
gStyle
.
SetOptStat
(
"
emri
"
)
gStyle
.
SetOptFit
(
111
)
gStyle
.
SetStatY
(
0.9
)
gStyle
.
SetStatX
(
0.9
)
gStyle
.
SetStatW
(
0.2
)
gStyle
.
SetStatH
(
0.2
)
# Title format
gStyle
.
SetTitleY
(
0.98
)
gStyle
.
SetTitleAlign
(
23
)
print
(
"
Default ROOT styles are applied
"
)
def
readFile
(
name
,
ncolumns
,
delimeter
=
'
,
'
):
# filename , number of column in the data file
'''
Multiple columns reading from file
Usage of readFile function
D is data array of columns of some variables
Example of an array:
D[0] D[1] D[2] ... D[n]
1 98 12 ... An
2 96 25 ... Bn
.. .. .. ... ..
Z0 Z1 Z2 ... Zn
and D[-1] stores lenght of array
'''
data
=
[[]
for
i
in
range
(
ncolumns
)]
with
open
(
name
,
'
r
'
)
as
f
:
for
line
in
f
:
if
line
.
find
(
'
#
'
)
!=
-
1
:
# skip '#' comment symbol
continue
for
i
in
range
(
ncolumns
):
val
=
line
.
split
(
delimeter
)
if
(
len
(
val
)
==
ncolumns
):
data
[
i
].
append
(
val
[
i
])
data
.
append
(
len
(
data
[
0
]))
return
data
def
cd
(
d
):
# input parameters d - list - data of the certain column
'''
Preparation of the data for ROOT style presentation
Convertation: python list type -> C++ double type
'''
data
=
array
(
'
d
'
)
for
i
in
range
(
len
(
d
)):
data
.
append
(
float
(
d
[
i
]))
return
data
def
drawBinContent
(
bin_arr
,
val_arr
,
name
=
'
h
'
,
title
=
'
histo
'
,
nbins
=
100
,
bin_first
=
0
,
bin_last
=
100
):
'''
Implements the SetBinContent ROOT method for TH1F histograms
'''
bin_arr
=
cd
(
bin_arr
)
val_arr
=
cd
(
val_arr
)
h
=
TH1F
(
name
,
title
,
int
(
nbins
),
bin_first
,
bin_last
)
h
.
GetYaxis
().
SetMaxDigits
(
3
);
for
b
,
v
in
zip
(
bin_arr
,
val_arr
):
h
.
SetBinContent
(
int
(
b
),
v
)
h
.
SetLineWidth
(
2
)
h
.
Draw
(
""
)
return
h
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment