ATLAS Offline Software
LArNoisyROSummNtuple.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 
21  def __init__(self,ofile,hv):
22  super(NoisyRO,self).__init__()
23  self.fout = ROOT.TFile(ofile,"RECREATE")
24  self.addhv=hv
25 
26  def initialize (self):
27  self.msg.debug("Doing NoisyRO 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  self.offlineID = self.detStore['CaloCell_ID']
41  if self.offlineID is None:
42  print("Failed to get CaloCell_ID")
43  return 0
44  EI = self.sg['EventInfo']
45  if EI is None:
46  self.msg.warning("Failed to get EventInfo")
47  self.evtid=0
48  self.bcid=0
49  else:
50  self.evtid=EI.eventNumber()
51  self.bcid=EI.bcid()
52 
53  if not self.is_init:
54  self.msg.debug("Doing NoisyRO Ttree init")
55  self.maxvec=100
56  self.aevtid=array('L',[self.evtid])
57  self.abcid=array('I',[self.bcid])
58  self.badFEBPart=array('H',[0])
59  self.badWFFEBPart=array('H',[0])
60  self.SatMediumPart=array('H',[0])
61  self.SatTightPart=array('H',[0])
62  self.MNBLoosePart=array('H',[0])
63  self.MNBTightPart=array('H',[0])
64  self.MNBTight_PsVetoPart=array('H',[0])
65  self.nbad = array('I',[0])
66  self.idvec = array('i',self.maxvec*[-1])
67  self.nMNBTight = array('I',[0])
68  self.MNBTightvec = array('i',self.maxvec*[-1])
69  self.nMNBLoose = array('I',[0])
70  self.MNBLoosevec = array('i',self.maxvec*[-1])
71  self.nMNBTight_PsVeto = array('I',[0])
72  self.MNBTight_PsVetovec = array('i',self.maxvec*[-1])
73  self.fout.cd()
74  self.nt = ROOT.TTree("mytree","mytree")
75  self.nt.SetDirectory(self.fout)
76  self.nt.Branch("Event",self.aevtid,"Event/l")
77  self.nt.Branch("BCID",self.abcid,"BCID/I")
78  self.nt.Branch("badFEBPart",self.badFEBPart,"badFEBPart/s")
79  self.nt.Branch("badWFFEBPart",self.badWFFEBPart,"badWFFEBPart/s")
80  self.nt.Branch("SatMediumPart",self.SatMediumPart,"SatMediumPart/s")
81  self.nt.Branch("SatTightPart",self.SatTightPart,"SatTightPart/s")
82  self.nt.Branch("MNBLoosePart",self.MNBLoosePart,"MNBLoosePart/s")
83  self.nt.Branch("MNBTightPart",self.MNBTightPart,"MNBTightPart/s")
84  self.nt.Branch("MNBTight_PsVetoPart",self.MNBTight_PsVetoPart,"MNBTight_PsVetoPart/s")
85  self.nt.Branch("nbad",self.nbad,"nbad/i")
86  self.nt.Branch("bad_febs",self.idvec,"bad_febs[nbad]/I")
87  self.nt.Branch("nMNBTight",self.nMNBTight,"nMNBTight/i")
88  self.nt.Branch("MNBTight_febs",self.MNBTightvec,"MNBTight_febs[nbad]/I")
89  self.nt.Branch("nMNBLoose",self.nMNBLoose,"nMNBLoose/i")
90  self.nt.Branch("MNBLoose_febs",self.MNBLoosevec,"MNBLoose_febs[nbad]/I")
91  self.nt.Branch("nMNBTight_PsVeto",self.nMNBTight_PsVeto,"nMNBTight_PsVeto/i")
92  self.nt.Branch("MNBTight_PsVeto_febs",self.MNBTight_PsVetovec,"MNBTight_PsVeto_febs[nbad]/I")
93  if self.addhv:
94  self.hvLinesPart=array('H',[0])
95  self.nhv = array('I',[0])
96  self.hvLinesvec = array('i',self.maxvec*[-1])
97  self.nt.Branch("hvLinesPart",self.hvLinesPart,"hvLinesPart/s")
98  self.nt.Branch("nhv",self.nhv,"nhv/i")
99  self.nt.Branch("hvLines_febs",self.hvLinesvec,"hvLines_febs[nbad]/I")
100 
101  self.is_init=True
102  self.msg.debug(" Ttree init done")
103 
104  Nro = self.sg['LArNoisyROSummary']
105  self.badFEBPart=Nro.BadFEBFlaggedPartitions()
106  print("badFEBPart: ",self.badFEBPart," ",Nro.BadFEBFlaggedPartitions())
107  self.badWFFEBPart[0]=Nro.BadFEB_WFlaggedPartitions()
108  self.SatMediumPart[0]=Nro.SatMediumFlaggedPartitions()
109  self.SatTightPart[0]=Nro.SatTightFlaggedPartitions()
110  self.MNBLoosePart[0]=Nro.MNBLooseFlaggedPartitions()
111  self.MNBTightPart[0]=Nro.MNBTightFlaggedPartitions()
112  self.MNBTight_PsVetoPart[0]=Nro.MNBTight_PsVetoFlaggedPartitions()
113  self.aevtid[0]=self.evtid
114  self.abcid[0]=self.bcid
115  hwvec=Nro.get_noisy_febs()
116  self.nbad[0]=hwvec.size()
117  if self.nbad[0] >= self.maxvec:
118  self.nbad[0]=self.maxvec
119  for i in range(0,self.nbad[0]):
120  self.idvec[i]=hwvec[i].get_identifier32().get_compact()
121 
122  hwvec=Nro.get_MNBTight_febs()
123  self.nMNBTight[0]=hwvec.size()
124  if self.nMNBTight[0] >= self.maxvec:
125  self.nMNBTight[0]=self.maxvec
126  for i in range(0,self.nMNBTight[0]):
127  self.MNBTightvec[i]=hwvec[i].get_identifier32().get_compact()
128 
129  hwvec=Nro.get_MNBLoose_febs()
130  self.nMNBLoose[0]=hwvec.size()
131  if self.nMNBLoose[0] >= self.maxvec:
132  self.nMNBLoose[0]=self.maxvec
133  for i in range(0,self.nMNBLoose[0]):
134  self.MNBLoosevec[i]=hwvec[i].get_identifier32().get_compact()
135 
136  hwvec=Nro.get_MNBTight_PsVeto_febs()
137  self.nMNBTight_PsVeto[0]=hwvec.size()
138  if self.nMNBTight_PsVeto[0] >= self.maxvec:
139  self.nMNBTight_PsVeto[0]=self.maxvec
140  for i in range(0,self.nMNBTight_PsVeto[0]):
141  self.MNBTight_PsVetovec[i]=hwvec[i].get_identifier32().get_compact()
142 
143  if self.addhv:
144  self.hvLinesPart[0]=Nro.HVlineFlaggedPartitions()
145  hwvec=Nro.get_noisy_hvlines()
146  self.nhv[0]=hwvec.size()
147  if self.nhv[0] >= self.maxvec:
148  self.nhv[0]=self.maxvec
149  for i in range(0,self.nhv[0]):
150  self.hvLinesvec[i]=hwvec[i].get_identifier32().get_compact()
151 
152  self.nt.Fill()
153  return 1
154 
155  def finalize (self):
156  self.fout.cd()
157  self.nt.Write()
158  self.fout.Close()
159  return 1
160 
161 
162 def usage():
163  print(sys.argv[0]+": Dump LArNoisyROSummary from pool file to ntuple")
164  print("Options:")
165  print("-i input file (default ESD.pool.root)")
166  print("-o output file (default NoisyROSum.root)")
167  print("-n number of events to dump (default -1)")
168  print("-m MC pool file (default fals)")
169  print("-v add HVline info (default fals)")
170  print("--detdescr <DetDescrVersion>")
171  print("-h Print this help text and exit")
172 
173 try:
174  opts,args=getopt.getopt(sys.argv[1:],"i:o:n:mvh",["help","detdescr="])
175 except Exception as e:
176  usage()
177  print(e)
178  sys.exit(-1)
179 
180 
181 ifile='ESD.pool.root'
182 ofile="NoisyROSum.root"
183 nev=-1
184 mc=False
185 hv=False
186 from AthenaConfiguration.TestDefaults import defaultGeometryTags
187 detdescrtag=defaultGeometryTags.RUN2
188 
189 for o,a in opts:
190  if (o=="-i"): ifile=a
191  if (o=="-o"): ofile=a
192  if (o=="-n"): nev=int(a)
193  if (o=="-m"): mc=True
194  if (o=="-v"): hv=True
195  if (o=="-h" or o=="--help"):
196  usage()
197  sys.exit(0)
198  if (o=="--detdescr"):
199  detdescrtag=a
200 
201 #Don't let PyRoot open X-connections
202 sys.argv = sys.argv[:1] + ['-b']
203 
204 from AthenaConfiguration.AllConfigFlags import initConfigFlags
206 flags.Input.Files = [ifile]
207 flags.Input.isMC=mc
208 flags.IOVDb.DatabaseInstance="CONDBR2"
209 flags.GeoModel.AtlasVersion = detdescrtag
210 flags.LAr.doAlign=False
211 
212 from AthenaConfiguration.DetectorConfigFlags import disableDetectors, allDetectors
213 disableDetectors(flags, allDetectors, toggle_geometry = True)
214 flags.Detector.EnableLAr = True
215 flags.Detector.EnableTile = True
216 flags.Detector.EnableCalo = True
217 
218 from AthenaCommon.Constants import INFO
219 flags.Exec.OutputLevel=INFO
220 flags.lock()
221 flags.dump()
222 
223 from RootUtils import PyROOTFixes # noqa F401
224 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
225 cfg=MainServicesCfg(flags)
226 
227 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
228 cfg.merge(PoolReadCfg(flags))
229 
230 from TileGeoModel.TileGMConfig import TileGMCfg
231 cfg.merge( TileGMCfg(flags) )
232 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
233 cfg.merge(LArGMCfg(flags))
234 
235 cfg.addEventAlgo(NoisyRO(ofile,hv))
236 
237 cfg.run(nev)
LArNoisyROSummNtuple.NoisyRO.SatTightPart
SatTightPart
Definition: LArNoisyROSummNtuple.py:61
LArNoisyROSummNtuple.NoisyRO.MNBTight_PsVetovec
MNBTight_PsVetovec
Definition: LArNoisyROSummNtuple.py:72
LArNoisyROSummNtuple.NoisyRO.maxvec
maxvec
Definition: LArNoisyROSummNtuple.py:55
LArNoisyROSummNtuple.NoisyRO
Definition: LArNoisyROSummNtuple.py:20
LArNoisyROSummNtuple.NoisyRO.addhv
addhv
Definition: LArNoisyROSummNtuple.py:24
LArNoisyROSummNtuple.NoisyRO.detStore
detStore
Definition: LArNoisyROSummNtuple.py:35
LArNoisyROSummNtuple.NoisyRO.badWFFEBPart
badWFFEBPart
Definition: LArNoisyROSummNtuple.py:59
LArNoisyROSummNtuple.NoisyRO.MNBLoosevec
MNBLoosevec
Definition: LArNoisyROSummNtuple.py:70
LArNoisyROSummNtuple.NoisyRO.aevtid
aevtid
Definition: LArNoisyROSummNtuple.py:56
LArNoisyROSummNtuple.NoisyRO.idvec
idvec
Definition: LArNoisyROSummNtuple.py:66
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition: PyAthenaAlg.cxx:60
PyAthena::Alg::execute
virtual StatusCode execute() override
Definition: PyAthenaAlg.cxx:93
LArNoisyROSummNtuple.NoisyRO.badFEBPart
badFEBPart
Definition: LArNoisyROSummNtuple.py:58
LArNoisyROSummNtuple.NoisyRO.abcid
abcid
Definition: LArNoisyROSummNtuple.py:57
LArNoisyROSummNtuple.NoisyRO.nbad
nbad
Definition: LArNoisyROSummNtuple.py:65
LArNoisyROSummNtuple.NoisyRO.evtid
evtid
Definition: LArNoisyROSummNtuple.py:47
LArNoisyROSummNtuple.NoisyRO.nhv
nhv
Definition: LArNoisyROSummNtuple.py:95
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition: PyAthenaAlg.cxx:86
LArNoisyROSummNtuple.NoisyRO.__init__
def __init__(self, ofile, hv)
Definition: LArNoisyROSummNtuple.py:21
LArNoisyROSummNtuple.NoisyRO.SatMediumPart
SatMediumPart
Definition: LArNoisyROSummNtuple.py:60
LArNoisyROSummNtuple.NoisyRO.fout
fout
Definition: LArNoisyROSummNtuple.py:23
LArNoisyROSummNtuple.NoisyRO.nMNBLoose
nMNBLoose
Definition: LArNoisyROSummNtuple.py:69
LArNoisyROSummNtuple.NoisyRO.MNBTightvec
MNBTightvec
Definition: LArNoisyROSummNtuple.py:68
LArNoisyROSummNtuple.NoisyRO.nMNBTight
nMNBTight
Definition: LArNoisyROSummNtuple.py:67
LArNoisyROSummNtuple.NoisyRO.offlineID
offlineID
Definition: LArNoisyROSummNtuple.py:40
LArNoisyROSummNtuple.NoisyRO.hvLinesPart
hvLinesPart
Definition: LArNoisyROSummNtuple.py:94
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:310
python.DetectorConfigFlags.disableDetectors
def disableDetectors(flags, detectors, toggle_geometry=False)
Definition: DetectorConfigFlags.py:429
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
Constants
some useful constants -------------------------------------------------—
LArNoisyROSummNtuple.NoisyRO.MNBLoosePart
MNBLoosePart
Definition: LArNoisyROSummNtuple.py:62
LArNoisyROSummNtuple.NoisyRO.nt
nt
Definition: LArNoisyROSummNtuple.py:74
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
LArNoisyROSummNtuple.usage
def usage()
Definition: LArNoisyROSummNtuple.py:162
LArNoisyROSummNtuple.NoisyRO.sg
sg
Definition: LArNoisyROSummNtuple.py:28
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
array
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
RCU::SetDirectory
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition: RootUtils.cxx:28
LArNoisyROSummNtuple.NoisyRO.MNBTightPart
MNBTightPart
Definition: LArNoisyROSummNtuple.py:63
LArNoisyROSummNtuple.NoisyRO.has_offID
has_offID
Definition: LArNoisyROSummNtuple.py:29
LArNoisyROSummNtuple.NoisyRO.hvLinesvec
hvLinesvec
Definition: LArNoisyROSummNtuple.py:96
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
calibdata.cd
cd
Definition: calibdata.py:50
PyAthena::Alg
Definition: PyAthenaAlg.h:33
LArNoisyROSummNtuple.NoisyRO.nMNBTight_PsVeto
nMNBTight_PsVeto
Definition: LArNoisyROSummNtuple.py:71
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:71
LArNoisyROSummNtuple.NoisyRO.bcid
bcid
Definition: LArNoisyROSummNtuple.py:48
LArNoisyROSummNtuple.NoisyRO.MNBTight_PsVetoPart
MNBTight_PsVetoPart
Definition: LArNoisyROSummNtuple.py:64
LArNoisyROSummNtuple.NoisyRO.is_init
is_init
Definition: LArNoisyROSummNtuple.py:30
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7