ATLAS Offline Software
HECNoiseD3PDMaker.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2 
3 #
4 # D3PDMaker
5 #
6 # Author: Sven Menke
7 #
8 # this python alg creates a D3PD and fills it
9 #
10 from __future__ import print_function
11 import AthenaPython.PyAthena as PyAthena
12 import ROOT
13 from array import array
14 
16  def __init__ ( self, name, **kw ) :
17  PyAthena.Alg.__init__(self,name)
18  self.name = name
19  self.det = None
20  self.cond = None
21 
22 
23  self.MinDigitADC = kw.get('MinDigitADC', 20)
24  self.MaxDeltaT = kw.get('MaxDeltaT', 5)
25  self.NtupleFileName = kw.get('NtupleFileName', 'HECNoiseD3PD.root')
26  self.RequireTrigger = kw.get('RequireTrigger', False)
27  self.TriggerLines = kw.get('TriggerLines', ['HLT_noalg_L1EM20A',
28  'HLT_noalg_L1EM20C',
29  'L1_J12',
30  'L1_J30',
31  'L1_TAU5',
32  'L1_TAU8',
33  'L1_J5_EMPTY',
34  'L1_J10_EMPTY',
35  'L1_J12_EMPTY',
36  'L1_J30_EMPTY',
37  'L1_TAU5_EMPTY',
38  'L1_TAU8_EMPTY',
39  'L1_J5_FIRSTEMPTY',
40  'L1_J10_FIRSTEMPTY',
41  'L1_J12_FIRSTEMPTY',
42  'L1_J30_FIRSTEMPTY',
43  'L1_TAU5_FIRSTEMPTY',
44  'L1_TAU8_FIRSTEMPTY'])
45 
46  def initialize(self):
47  print ("==> initializing ", self.name)
48  print ("MinDigitADC: ", self.MinDigitADC)
49  print ("MaxDeltaT: ", self.MaxDeltaT)
50  print ("NtupleFileName: ", self.NtupleFileName)
51  print ("RequireTrigger: ", self.RequireTrigger)
52  print ("TriggerLines: ", self.TriggerLines)
53  #
54  self.sg = PyAthena.py_svc("StoreGateSvc")
55  self.cond = PyAthena.py_svc('StoreGateSvc/ConditionStore')
56  self.det = PyAthena.py_svc("StoreGateSve/DetectorStore")
57  self.LArOID = self.det.retrieve("LArOnlineID","LArOnlineID")
58  self.cid = self.det.retrieve("CaloCell_ID","CaloCell_ID")
59  self.tdt = PyAthena.py_tool('Trig::TrigDecisionTool/TrigDecisionTool')
60  self.ntfile = ROOT.TFile(self.NtupleFileName,"RECREATE")
61  self.hectree = ROOT.TTree("HECNoise","HECNoise")
62  self.iRun = array('i',[0])
63  self.iEvent = array('L',[0])
64  self.iEventCount = array('i',[0])
65  self.fPrescale = {}
66  self.iTrigger = {}
67  for tl in self.TriggerLines:
68  self.fPrescale[tl] = array('f',[0.0])
69  self.iTrigger[tl] = array('i',[0])
70  pass
71  self.iTime = array('i',[0])
72  self.iLB = array('i',[0])
73  self.iBCID = array('i',[0])
74  self.avgMu = array('f',[0.0])
75  self.actMu = array('f',[0.0])
76  self.iGain = array('i',[0])
77  self.iOID = array('L',[0])
78  self.iSide = array('i',[0])
79  self.iSamp = array('i',[0])
80  self.iReg = array('i',[0])
81  self.iEta = array('i',[0])
82  self.iPhi = array('i',[0])
83  self.iQuality = array('i',[0])
84  self.e = array('f',[0.0])
85  self.t = array('f',[0.0])
86  self.eta = array('f',[0.0])
87  self.phi = array('f',[0.0])
88  self.z = array('f',[0.0])
89  self.r = array('f',[0.0])
90  self.Ped = array('f',[0.0])
91  self.PedRMS = array('f',[0.0])
92  self.iDigi = array('i',32*[0])
93  self.iMax = array('i',[0])
94  self.iMin = array('i',[0])
95  #
96  self.hectree.Branch("iRun",self.iRun,"iRun/I")
97  self.hectree.Branch("iEvent",self.iEvent,"iEvent/I")
98  self.hectree.Branch("iEventCount",self.iEventCount,"iEventCount/I")
99 
100  for tl in self.TriggerLines:
101  self.hectree.Branch(tl+"_Prescale",self.fPrescale[tl],tl+"_Prescale/F")
102  self.hectree.Branch(tl+"_Trigger",self.iTrigger[tl],tl+"_Trigger/I")
103  pass
104  self.hectree.Branch("iTime",self.iTime,"iTime/I")
105  self.hectree.Branch("iLB",self.iLB,"iLB/I")
106  self.hectree.Branch("iBCID",self.iBCID,"iBCID/I")
107  self.hectree.Branch("avgMu",self.avgMu,"avgMu/F")
108  self.hectree.Branch("actMu",self.actMu,"actMu/F")
109  self.hectree.Branch("iGain",self.iGain,"iGain/I")
110  self.hectree.Branch("iOID",self.iOID,"iOID/l")
111  self.hectree.Branch("iSide",self.iSide,"iSide/I")
112  self.hectree.Branch("iSamp",self.iSamp,"iSamp/I")
113  self.hectree.Branch("iReg",self.iReg,"iReg/I")
114  self.hectree.Branch("iEta",self.iEta,"iEta/I")
115  self.hectree.Branch("iPhi",self.iPhi,"iPhi/I")
116  self.hectree.Branch("iQuality",self.iQuality,"iQuality/I")
117  self.hectree.Branch("e",self.e,"e/F")
118  self.hectree.Branch("t",self.t,"t/F")
119  self.hectree.Branch("eta",self.eta,"eta/F")
120  self.hectree.Branch("phi",self.phi,"phi/F")
121  self.hectree.Branch("z",self.z,"z/F")
122  self.hectree.Branch("r",self.r,"r/F")
123  self.hectree.Branch("Ped",self.Ped,"Ped/F")
124  self.hectree.Branch("PedRMS",self.PedRMS,"PedRMS/F")
125  self.hectree.Branch("iDigi",self.iDigi,"iDigi[32]/I")
126  self.hectree.Branch("iMax",self.iMax,"iMax/I")
127  self.hectree.Branch("iMin",self.iMin,"iMin/I")
128  #
129  return True
130 
131  def execute(self):
132  eid=ROOT.Gaudi.Hive.currentContext().eventID()
133  lcsCont = self.cond.retrieve("CondCont<LArOnOffIdMapping>","LArOnOffIdMap")
134  lcs=lcsCont.find(eid)
135  pedCont = self.cond.retrieve("CondCont<ILArPedestal>","LArPedestal")
136  ped=pedCont.find(eid)
137  cddCont = self.cond.retrieve("CondCont<CaloDetDescrManager>","CaloDetDescrManager")
138  cdd=cddCont.find(eid)
139  # filter low gain cells
140  passedTrigger = False
141  foundLowCell = False
142  for tl in self.TriggerLines:
143  self.fPrescale[tl][0] = self.tdt.getPrescale(tl)
144  if self.tdt.isPassed(tl):
145  passedTrigger = True
146  self.iTrigger[tl][0] = 1
147  pass
148  else:
149  self.iTrigger[tl][0] = 0
150  pass
151  pass
152  if passedTrigger or not self.RequireTrigger: # take only triggered events or all if RequireTrigger is False (default)
153  self.iEventCount[0] = 0
154  ldc = self.sg.retrieve("LArDigitContainer","LArDigitContainer_Thinned")
155  for ld in ldc:
156  hid = ld.hardwareID()
157  if self.LArOID.isHECchannel(hid):# and ld.gain() == 2:
158  sigmax=0
159  sigmin=0
160  imax=0
161  imin=0
162  isamp=0
163  samp0= ld.samples()[0]
164  for samp in ld.samples():
165  if isamp < 32:
166  self.iDigi[isamp] = samp
167  pass
168  if samp-samp0 > sigmax:
169  sigmax = samp-samp0
170  imax=isamp
171  pass
172  if samp-samp0 < sigmin:
173  sigmin = samp-samp0
174  imin=isamp
175  pass
176  isamp = isamp+1
177  pass
178  if sigmax > self.MinDigitADC and sigmin < -self.MinDigitADC and ( (imin-imax) < self.MaxDeltaT or imin < imax):
179  foundLowCell = True
180  ei = self.sg.retrieve("xAOD::EventInfo","EventInfo")
181  cc = self.sg.retrieve("CaloCellContainer","AllCalo")
182  self.iRun[0] = ei.runNumber()
183  self.iEvent[0] = ei.eventNumber()
184  self.iEventCount[0] = self.iEventCount[0]+1
185  self.iTime[0] = ei.timeStamp()
186  self.iLB[0] = ei.lumiBlock()
187  self.iBCID[0] = ei.bcid()
188  self.avgMu[0] = ei.averageInteractionsPerCrossing()
189  self.actMu[0] = ei.actualInteractionsPerCrossing()
190  self.iGain[0] = ld.gain()
191  oid = lcs.cnvToIdentifier(hid)
192  self.iOID[0] = ld.channelID().get_compact()
193  self.Ped[0] = ped.pedestal(ld.channelID(),ld.gain())
194  self.PedRMS[0] = ped.pedestalRMS(ld.channelID(),ld.gain())
195  self.iSide[0] = self.cid.pos_neg(oid)
196  self.iSamp[0] = self.cid.sampling(oid)
197  self.iReg[0] = self.cid.region(oid)
198  self.iEta[0] = self.cid.eta(oid)
199  self.iPhi[0] = self.cid.phi(oid)
200  self.iMax[0] = imax
201  self.iMin[0] = imin
202  ihash = self.cid.calo_cell_hash(oid)
203  rcell = cc.findCell(ihash)
204  self.e[0] = 0.0
205  self.t[0] = 0.0
206  self.iQuality[0] = 0
207  if rcell.ID() != oid:
208  print ("Cell iHash does not match ...")
209  pass
210  else:
211  self.e[0] = rcell.e()
212  self.t[0] = rcell.time()
213  self.iQuality[0] = rcell.quality()
214  pass
215  cdde = cdd.get_element(oid)
216  self.eta[0] = cdde.eta()
217  self.phi[0] = cdde.phi()
218  self.z[0] = cdde.z()
219  self.r[0] = cdde.r()
220  self.hectree.Fill()
221  self.setFilterPassed(True)
222  pass
223  pass
224  pass
225  if foundLowCell:
226  print ('Event passed HECNoise Filter')
227  return True
228  pass
229  print ('Event failed HECNoise Filter')
230  self.setFilterPassed(False)
231  return True
232 
233  def finalize(self):
234  self.ntfile.Write()
235  self.ntfile.Close()
236  return True
237 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iMax
iMax
Definition: HECNoiseD3PDMaker.py:93
HECNoiseD3PDMaker.HECNoiseD3PDMaker.PedRMS
PedRMS
Definition: HECNoiseD3PDMaker.py:91
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iRun
iRun
Definition: HECNoiseD3PDMaker.py:62
HECNoiseD3PDMaker.HECNoiseD3PDMaker.Ped
Ped
Definition: HECNoiseD3PDMaker.py:90
PyAthena::Alg::initialize
virtual StatusCode initialize() override
Definition: PyAthenaAlg.cxx:60
PyAthena::Alg::execute
virtual StatusCode execute() override
Definition: PyAthenaAlg.cxx:93
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iQuality
iQuality
Definition: HECNoiseD3PDMaker.py:83
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iEventCount
iEventCount
Definition: HECNoiseD3PDMaker.py:64
HECNoiseD3PDMaker.HECNoiseD3PDMaker.z
z
Definition: HECNoiseD3PDMaker.py:88
HECNoiseD3PDMaker.HECNoiseD3PDMaker.name
name
Definition: HECNoiseD3PDMaker.py:18
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iEta
iEta
Definition: HECNoiseD3PDMaker.py:81
HECNoiseD3PDMaker.HECNoiseD3PDMaker.r
r
Definition: HECNoiseD3PDMaker.py:89
HECNoiseD3PDMaker.HECNoiseD3PDMaker
Definition: HECNoiseD3PDMaker.py:15
PyAthena::Alg::finalize
virtual StatusCode finalize() override
Definition: PyAthenaAlg.cxx:86
HECNoiseD3PDMaker.HECNoiseD3PDMaker.det
det
Definition: HECNoiseD3PDMaker.py:19
HECNoiseD3PDMaker.HECNoiseD3PDMaker.LArOID
LArOID
Definition: HECNoiseD3PDMaker.py:57
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iPhi
iPhi
Definition: HECNoiseD3PDMaker.py:82
HECNoiseD3PDMaker.HECNoiseD3PDMaker.phi
phi
Definition: HECNoiseD3PDMaker.py:87
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iTime
iTime
Definition: HECNoiseD3PDMaker.py:71
HECNoiseD3PDMaker.HECNoiseD3PDMaker.t
t
Definition: HECNoiseD3PDMaker.py:85
HECNoiseD3PDMaker.HECNoiseD3PDMaker.hectree
hectree
Definition: HECNoiseD3PDMaker.py:61
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iSide
iSide
Definition: HECNoiseD3PDMaker.py:78
HECNoiseD3PDMaker.HECNoiseD3PDMaker.RequireTrigger
RequireTrigger
Definition: HECNoiseD3PDMaker.py:26
HECNoiseD3PDMaker.HECNoiseD3PDMaker.sg
sg
Definition: HECNoiseD3PDMaker.py:54
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iDigi
iDigi
Definition: HECNoiseD3PDMaker.py:92
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iOID
iOID
Definition: HECNoiseD3PDMaker.py:77
HECNoiseD3PDMaker.HECNoiseD3PDMaker.MaxDeltaT
MaxDeltaT
Definition: HECNoiseD3PDMaker.py:24
HECNoiseD3PDMaker.HECNoiseD3PDMaker.actMu
actMu
Definition: HECNoiseD3PDMaker.py:75
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iReg
iReg
Definition: HECNoiseD3PDMaker.py:80
HECNoiseD3PDMaker.HECNoiseD3PDMaker.e
e
Definition: HECNoiseD3PDMaker.py:84
HECNoiseD3PDMaker.HECNoiseD3PDMaker.fPrescale
fPrescale
Definition: HECNoiseD3PDMaker.py:65
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iMin
iMin
Definition: HECNoiseD3PDMaker.py:94
array
HECNoiseD3PDMaker.HECNoiseD3PDMaker.MinDigitADC
MinDigitADC
cell cuts
Definition: HECNoiseD3PDMaker.py:23
HECNoiseD3PDMaker.HECNoiseD3PDMaker.TriggerLines
TriggerLines
Definition: HECNoiseD3PDMaker.py:27
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iEvent
iEvent
Definition: HECNoiseD3PDMaker.py:63
HECNoiseD3PDMaker.HECNoiseD3PDMaker.cond
cond
Definition: HECNoiseD3PDMaker.py:20
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iSamp
iSamp
Definition: HECNoiseD3PDMaker.py:79
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iGain
iGain
Definition: HECNoiseD3PDMaker.py:76
HECNoiseD3PDMaker.HECNoiseD3PDMaker.tdt
tdt
Definition: HECNoiseD3PDMaker.py:59
HECNoiseD3PDMaker.HECNoiseD3PDMaker.ntfile
ntfile
Definition: HECNoiseD3PDMaker.py:60
HECNoiseD3PDMaker.HECNoiseD3PDMaker.avgMu
avgMu
Definition: HECNoiseD3PDMaker.py:74
HECNoiseD3PDMaker.HECNoiseD3PDMaker.cid
cid
Definition: HECNoiseD3PDMaker.py:58
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iTrigger
iTrigger
Definition: HECNoiseD3PDMaker.py:66
PyAthena::Alg
Definition: PyAthenaAlg.h:33
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iBCID
iBCID
Definition: HECNoiseD3PDMaker.py:73
HECNoiseD3PDMaker.HECNoiseD3PDMaker.iLB
iLB
Definition: HECNoiseD3PDMaker.py:72
HECNoiseD3PDMaker.HECNoiseD3PDMaker.__init__
def __init__(self, name, **kw)
Definition: HECNoiseD3PDMaker.py:16
HECNoiseD3PDMaker.HECNoiseD3PDMaker.eta
eta
Definition: HECNoiseD3PDMaker.py:86
HECNoiseD3PDMaker.HECNoiseD3PDMaker.NtupleFileName
NtupleFileName
Definition: HECNoiseD3PDMaker.py:25