ATLAS Offline Software
Loading...
Searching...
No Matches
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
9import os,sys,getopt
10
11# dumping class
12
13import cppyy
14from array import array
15
16import ROOT
17from ROOT import HWIdentifier, Identifier, IdentifierHash, TFile
18from 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])
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
162def 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
173try:
174 opts,args=getopt.getopt(sys.argv[1:],"i:o:n:mvh",["help","detdescr="])
175except Exception as e:
176 usage()
177 print(e)
178 sys.exit(-1)
179
180
181ifile='ESD.pool.root'
182ofile="NoisyROSum.root"
183nev=-1
184mc=False
185hv=False
186from AthenaConfiguration.TestDefaults import defaultGeometryTags
187detdescrtag=defaultGeometryTags.RUN2
188
189for 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
202sys.argv = sys.argv[:1] + ['-b']
203
204from AthenaConfiguration.AllConfigFlags import initConfigFlags
205flags=initConfigFlags()
206flags.Input.Files = [ifile]
207flags.Input.isMC=mc
208flags.IOVDb.DatabaseInstance="CONDBR2"
209flags.GeoModel.AtlasVersion = detdescrtag
210flags.LAr.doAlign=False
211
212from AthenaConfiguration.DetectorConfigFlags import disableDetectors, allDetectors
213disableDetectors(flags, allDetectors, toggle_geometry = True)
214flags.Detector.EnableLAr = True
215flags.Detector.EnableTile = True
216flags.Detector.EnableCalo = True
217
218from AthenaCommon.Constants import INFO
219flags.Exec.OutputLevel=INFO
220flags.lock()
221flags.dump()
222
223from RootUtils import PyROOTFixes # noqa F401
224from AthenaConfiguration.MainServicesConfig import MainServicesCfg
225cfg=MainServicesCfg(flags)
226
227from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
228cfg.merge(PoolReadCfg(flags))
229
230from TileGeoModel.TileGMConfig import TileGMCfg
231cfg.merge( TileGMCfg(flags) )
232from LArGeoAlgsNV.LArGMConfig import LArGMCfg
233cfg.merge(LArGMCfg(flags))
234
235cfg.addEventAlgo(NoisyRO(ofile,hv))
236
237cfg.run(nev)
const bool debug
void print(char *figname, TCanvas *c1)
MsgStream & msg() const
virtual StatusCode execute() override
virtual StatusCode finalize() override
virtual StatusCode initialize() override
STL class.