Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reconstruction_benchmarks
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
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
EIC
benchmarks
reconstruction_benchmarks
Commits
a1b3797c
Commit
a1b3797c
authored
3 years ago
by
Chao Peng
Browse files
Options
Downloads
Patches
Plain Diff
add a script to get layer ids
parent
29e7d3e6
No related branches found
No related tags found
1 merge request
!128
add benchmark for pion0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
benchmarks/imaging_ecal/scripts/get_layerids.py
+72
-0
72 additions, 0 deletions
benchmarks/imaging_ecal/scripts/get_layerids.py
with
72 additions
and
0 deletions
benchmarks/imaging_ecal/scripts/get_layerids.py
0 → 100644
+
72
−
0
View file @
a1b3797c
'''
A simple analysis script to extract some basic info of Monte-Carlo hits
'''
import
os
import
DDG4
import
ROOT
import
pandas
as
pd
import
numpy
as
np
import
argparse
from
matplotlib
import
pyplot
as
plt
import
matplotlib.ticker
as
ticker
# read from RDataFrame and flatten a given collection, return pandas dataframe
def
flatten_collection
(
rdf
,
collection
,
cols
=
None
):
if
not
cols
:
cols
=
[
str
(
c
)
for
c
in
rdf
.
GetColumnNames
()
if
str
(
c
).
startswith
(
'
{}.
'
.
format
(
collection
))]
else
:
cols
=
[
'
{}.{}
'
.
format
(
collection
,
c
)
for
c
in
cols
]
if
not
cols
:
print
(
'
cannot find any branch under collection {}
'
.
format
(
collection
))
return
pd
.
DataFrame
()
data
=
rdf
.
AsNumpy
(
cols
)
# flatten the data, add an event id to identify clusters from different events
evns
=
[]
for
i
,
vec
in
enumerate
(
data
[
cols
[
0
]]):
evns
+=
[
i
]
*
vec
.
size
()
for
n
,
vals
in
data
.
items
():
# make sure ints are not converted to floats
typename
=
vals
[
0
].
__class__
.
__name__
.
lower
()
dtype
=
np
.
int64
if
'
int
'
in
typename
or
'
long
'
in
typename
else
np
.
float64
# type safe creation
data
[
n
]
=
np
.
asarray
([
v
for
vec
in
vals
for
v
in
vec
],
dtype
=
dtype
)
# build data frame
dfp
=
pd
.
DataFrame
({
c
:
pd
.
Series
(
v
)
for
c
,
v
in
data
.
items
()})
dfp
.
loc
[:,
'
event
'
]
=
evns
return
dfp
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'
rec_file
'
,
help
=
'
Path to reconstruction output file.
'
)
parser
.
add_argument
(
'
-o
'
,
dest
=
'
outdir
'
,
default
=
'
.
'
,
help
=
'
Output directory.
'
)
parser
.
add_argument
(
'
-c
'
,
'
--compact
'
,
dest
=
'
compact
'
,
required
=
True
,
help
=
'
Top-level xml file of the detector description
'
)
parser
.
add_argument
(
'
--collection
'
,
dest
=
'
coll
'
,
required
=
True
,
help
=
'
Hits collection name in the reconstruction file
'
)
parser
.
add_argument
(
'
--readout
'
,
dest
=
'
readout
'
,
required
=
True
,
help
=
'
Readout name for the hits collection
'
)
args
=
parser
.
parse_args
()
# get hits
rdf_rec
=
ROOT
.
RDataFrame
(
'
events
'
,
args
.
rec_file
)
df
=
flatten_collection
(
rdf_rec
,
args
.
coll
)
df
.
rename
(
columns
=
{
c
:
c
.
replace
(
args
.
coll
+
'
.
'
,
''
)
for
c
in
df
.
columns
},
inplace
=
True
)
# initialize dd4hep detector
kernel
=
DDG4
.
Kernel
()
description
=
kernel
.
detectorDescription
()
kernel
.
loadGeometry
(
"
file:{}
"
.
format
(
args
.
compact
))
decoder
=
description
.
readout
(
args
.
readout
).
idSpec
().
decoder
()
lindex
=
decoder
.
index
(
'
layer
'
)
get_layer_id
=
np
.
vectorize
(
lambda
cid
:
decoder
.
get
(
cid
,
lindex
))
df
.
loc
[:,
'
layerID
'
]
=
get_layer_id
(
df
[
'
cellID
'
].
astype
(
int
).
values
)
print
(
df
[[
'
cellID
'
,
'
layerID
'
,
'
position.x
'
,
'
position.y
'
,
'
position.z
'
,
'
energy
'
]])
# always terminate dd4hep kernel
kernel
.
terminate
()
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