ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArExample
LArCalibProcessing
share
LArCellNtuple.py
Go to the documentation of this file.
1
#!/bin/env python
2
# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
4
9
import
os,sys,getopt
10
11
# dumping class
12
13
import
cppyy
14
from
array
import
array
15
16
import
ROOT
17
from
ROOT
import
HWIdentifier, Identifier, IdentifierHash, TFile
18
from
AthenaPython
import
PyAthena
19
20
class
CellE
(
PyAthena.Alg
):
21
def
__init__
(self,ofile,isSC):
22
super(CellE,self).
__init__
()
23
self.
fout
= ROOT.TFile(ofile,
"RECREATE"
)
24
self.
isSC
= isSC
25
26
def
initialize
(self):
27
self.
msg
.
debug
(
"Doing CellE init"
)
28
self.
sg
= PyAthena.py_svc(
'StoreGateSvc'
)
29
self.
has_offID
=
False
30
self.
is_init
=
False
31
return
1
32
33
def
execute
(self):
34
if
self.
detStore
is
None
:
35
self.
detStore
= PyAthena.py_svc(
'DetectorStore'
)
36
if
self.
detStore
is
None
:
37
print
(
"Failed to get DetectorStore"
)
38
return
0
39
if
not
self.
has_offID
:
40
if
not
self.
isSC
:
41
self.
offlineID
= self.
detStore
[
'CaloCell_ID'
]
42
else
:
43
self.
offlineID
= self.
detStore
[
'CaloCell_SuperCell_ID'
]
44
if
self.
offlineID
is
None
:
45
print
(
"Failed to get CaloCell_ID"
)
46
return
0
47
EI = self.
sg
[
'EventInfo'
]
48
if
EI
is
None
:
49
self.
msg
.warning(
"Failed to get EventInfo"
)
50
self.
evtid
=0
51
self.
bcid
=0
52
else
:
53
self.
evtid
=EI.eventNumber()
54
self.
bcid
=EI.bcid()
55
56
if
not
self.
is_init
:
57
self.
msg
.
debug
(
"Doing CellE Ttree init"
)
58
self.
maxcells
=self.
offlineID
.calo_cell_hash_max()
59
self.
amaxcells
=
array
(
'i'
,[self.
maxcells
])
60
self.
aevtid
=
array
(
'L'
,[self.
evtid
])
61
self.
abcid
=
array
(
'I'
,[self.
bcid
])
62
self.
idvec
=
array
(
'i'
,self.
maxcells
*[0])
# storing the identifiers
63
self.
calosamp
=
array
(
'i'
,self.
maxcells
*[0])
# storing the calo sample
64
self.
posneg
=
array
(
'i'
,self.
maxcells
*[0])
# storing the side
65
self.
region
=
array
(
'i'
,self.
maxcells
*[0])
# storing the region
66
self.
etaidx
=
array
(
'i'
,self.
maxcells
*[0])
# storing the eta bin
67
self.
phiidx
=
array
(
'i'
,self.
maxcells
*[0])
# storing the phi bin
68
self.
encell
=
array
(
'd'
,self.
maxcells
*[0.])
# energies
69
self.
timecell
=
array
(
'd'
,self.
maxcells
*[0.])
# timing
70
self.
provcell
=
array
(
'H'
,self.
maxcells
*[0])
# provenance
71
self.
qcell
=
array
(
'H'
,self.
maxcells
*[0])
# quality
72
self.
fout
.cd()
73
self.
nt
= ROOT.TTree(
"mytree"
,
"mytree"
)
74
self.
nt
.SetDirectory(self.
fout
)
75
self.
nt
.Branch(
"ncell"
,self.
amaxcells
,
"ncell/I"
)
76
self.
nt
.Branch(
"Event"
,self.
aevtid
,
"Event/l"
)
77
self.
nt
.Branch(
"BCID"
,self.
abcid
,
"BCID/I"
)
78
self.
nt
.Branch(
"OffID"
,self.
idvec
,
"OffID[ncell]/i"
)
79
self.
nt
.Branch(
"calosamp"
,self.
calosamp
,
"calosamp[ncell]/I"
)
80
self.
nt
.Branch(
"pos_neg"
,self.
posneg
,
"pos_neg[ncell]/I"
)
81
self.
nt
.Branch(
"region"
,self.
region
,
"region[ncell]/I"
)
82
self.
nt
.Branch(
"eta"
,self.
etaidx
,
"eta[ncell]/I"
)
83
self.
nt
.Branch(
"phi"
,self.
phiidx
,
"phi[ncell]/I"
)
84
self.
nt
.Branch(
"energy"
,self.
encell
,
"energy[ncell]/D"
)
85
self.
nt
.Branch(
"time"
,self.
timecell
,
"time[ncell]/D"
)
86
self.
nt
.Branch(
"prov"
,self.
provcell
,
"prov[ncell]/s"
)
87
self.
nt
.Branch(
"qual"
,self.
qcell
,
"qual[ncell]/s"
)
88
self.
is_init
=
True
89
self.
msg
.
debug
(
"CellE Ttree init done"
)
90
91
if
not
self.
isSC
:
92
Cells = self.
sg
[
'AllCalo'
]
93
else
:
94
Cells = self.
sg
[
'SCell'
]
95
nc = Cells.size()
96
cellitr=0;
97
for
j
in
range(nc):
98
c=Cells[j]
99
id=c.ID()
100
if
self.
offlineID
.is_tile(id):
continue
101
if
cellitr >= self.
maxcells
:
continue
102
self.
idvec
[cellitr]=id.get_identifier32().get_compact()
103
self.
calosamp
[cellitr]=self.
offlineID
.calo_sample(id)
104
self.
region
[cellitr]=self.
offlineID
.
region
(id)
105
self.
etaidx
[cellitr]=self.
offlineID
.
eta
(id)
106
self.
posneg
[cellitr]=self.
offlineID
.pos_neg(id)
107
self.
phiidx
[cellitr]=self.
offlineID
.
phi
(id)
108
self.
encell
[cellitr]=c.energy()
109
self.
timecell
[cellitr]=c.time()
110
self.
provcell
[cellitr]=c.provenance()
111
self.
qcell
[cellitr]=c.quality()
112
cellitr += 1
113
self.
aevtid
[0]=self.
evtid
114
self.
abcid
[0]=self.
bcid
115
self.
amaxcells
[0]=cellitr
116
if
self.
amaxcells
[0] > 0:
117
self.
nt
.Fill()
118
return
1
119
120
def
finalize
(self):
121
self.
fout
.cd()
122
self.
nt
.Write()
123
self.
fout
.Close()
124
return
1
125
126
127
def
usage
():
128
print
(sys.argv[0]+
": Dump cells from pool file to ntuple"
)
129
print
(
"Options:"
)
130
print
(
"-i input file (default ESD.pool.root)"
)
131
print
(
"-o output file (default cells.root)"
)
132
print
(
"-n number of events to dump (default -1)"
)
133
print
(
"-m MC pool file (default false)"
)
134
print
(
"-s is SC (default false)"
)
135
print
(
"--detdescr <DetDescrVersion>"
)
136
print
(
"-h Print this help text and exit"
)
137
138
try
:
139
opts,args=getopt.getopt(sys.argv[1:],
"i:o:n:msh"
,[
"help"
,
"detdescr="
])
140
except
Exception
as
e:
141
usage
()
142
print
(e)
143
sys.exit(-1)
144
145
146
ifile=
'ESD.pool.root'
147
ofile=
"cells.root"
148
nev=-1
149
mc=
False
150
sc=
False
151
from
AthenaConfiguration.TestDefaults
import
defaultGeometryTags
152
detdescrtag=defaultGeometryTags.RUN2
153
154
for
o,a
in
opts:
155
if
(o==
"-i"
): ifile=a
156
if
(o==
"-o"
): ofile=a
157
if
(o==
"-n"
): nev=int(a)
158
if
(o==
"-m"
): mc=
True
159
if
(o==
"-s"
): sc=
True
160
if
(o==
"-h"
or
o==
"--help"
):
161
usage
()
162
sys.exit(0)
163
if
(o==
"--detdescr"
):
164
detdescrtag=a
165
166
#Don't let PyRoot open X-connections
167
sys.argv = sys.argv[:1] + [
'-b'
]
168
169
from
AthenaConfiguration.AllConfigFlags
import
initConfigFlags
170
flags=initConfigFlags()
171
flags.Input.Files = ifile.split(
","
)
172
flags.Input.isMC=mc
173
flags.IOVDb.DatabaseInstance=
"CONDBR2"
174
flags.GeoModel.AtlasVersion = detdescrtag
175
flags.LAr.doAlign=
False
176
177
from
AthenaConfiguration.DetectorConfigFlags
import
disableDetectors, allDetectors
178
disableDetectors(flags, allDetectors, toggle_geometry =
True
)
179
flags.Detector.EnableLAr =
True
180
flags.Detector.EnableTile =
True
181
flags.Detector.EnableCalo =
True
182
183
from
AthenaCommon.Constants
import
INFO
184
flags.Exec.OutputLevel=INFO
185
flags.lock()
186
flags.dump()
187
188
from
RootUtils
import
PyROOTFixes
# noqa F401
189
from
AthenaConfiguration.MainServicesConfig
import
MainServicesCfg
190
cfg=MainServicesCfg(flags)
191
192
from
AthenaPoolCnvSvc.PoolReadConfig
import
PoolReadCfg
193
cfg.merge(PoolReadCfg(flags))
194
195
from
TileGeoModel.TileGMConfig
import
TileGMCfg
196
cfg.merge( TileGMCfg(flags) )
197
from
LArGeoAlgsNV.LArGMConfig
import
LArGMCfg
198
cfg.merge(LArGMCfg(flags))
199
if
sc:
200
from
AthenaConfiguration.ComponentFactory
import
CompFactory
201
cfg.addCondAlgo(CompFactory.CaloSuperCellAlignCondAlg())
202
203
cfg.addEventAlgo(
CellE
(ofile,sc))
204
205
cfg.run(nev)
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
debug
const bool debug
Definition
MakeUncertaintyPlots.cxx:53
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
AthCommonMsg< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
LArCellNtuple.CellE
Definition
LArCellNtuple.py:20
LArCellNtuple.CellE.abcid
abcid
Definition
LArCellNtuple.py:61
LArCellNtuple.CellE.bcid
int bcid
Definition
LArCellNtuple.py:51
LArCellNtuple.CellE.timecell
timecell
Definition
LArCellNtuple.py:69
LArCellNtuple.CellE.qcell
qcell
Definition
LArCellNtuple.py:71
LArCellNtuple.CellE.etaidx
etaidx
Definition
LArCellNtuple.py:66
LArCellNtuple.CellE.maxcells
maxcells
Definition
LArCellNtuple.py:58
LArCellNtuple.CellE.__init__
__init__(self, ofile, isSC)
Definition
LArCellNtuple.py:21
LArCellNtuple.CellE.calosamp
calosamp
Definition
LArCellNtuple.py:63
LArCellNtuple.CellE.offlineID
offlineID
Definition
LArCellNtuple.py:41
LArCellNtuple.CellE.region
region
Definition
LArCellNtuple.py:65
LArCellNtuple.CellE.execute
execute(self)
Definition
LArCellNtuple.py:33
LArCellNtuple.CellE.phiidx
phiidx
Definition
LArCellNtuple.py:67
LArCellNtuple.CellE.nt
nt
Definition
LArCellNtuple.py:73
LArCellNtuple.CellE.posneg
posneg
Definition
LArCellNtuple.py:64
LArCellNtuple.CellE.aevtid
aevtid
Definition
LArCellNtuple.py:60
LArCellNtuple.CellE.is_init
bool is_init
Definition
LArCellNtuple.py:30
LArCellNtuple.CellE.fout
fout
Definition
LArCellNtuple.py:23
LArCellNtuple.CellE.sg
sg
Definition
LArCellNtuple.py:28
LArCellNtuple.CellE.provcell
provcell
Definition
LArCellNtuple.py:70
LArCellNtuple.CellE.idvec
idvec
Definition
LArCellNtuple.py:62
LArCellNtuple.CellE.evtid
int evtid
Definition
LArCellNtuple.py:50
LArCellNtuple.CellE.isSC
isSC
Definition
LArCellNtuple.py:24
LArCellNtuple.CellE.encell
encell
Definition
LArCellNtuple.py:68
LArCellNtuple.CellE.has_offID
bool has_offID
Definition
LArCellNtuple.py:29
LArCellNtuple.CellE.amaxcells
amaxcells
Definition
LArCellNtuple.py:59
PyAthena::Alg
Definition
PyAthenaAlg.h:33
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition
PyAthenaAlg.cxx:86
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition
PyAthenaAlg.cxx:60
Constants
LArCellNtuple.usage
usage()
Definition
LArCellNtuple.py:127
array
Generated on
for ATLAS Offline Software by
1.17.0