ATLAS Offline Software
Loading...
Searching...
No Matches
CaloThinCellsByClusterAlg_test.py
Go to the documentation of this file.
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
3#
4# File: CaloRec/python/CaloThinCellsByClusterAlg_test.py
5# Author: scott snyder
6# Date: Nov, 2019
7# Brief: Test for CaloThinCellsByClusterAlg.
8#
9
10from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
11from AthenaConfiguration.ComponentFactory import CompFactory
12from AthenaPython.PyAthenaComps import Alg, StatusCode
13from math import pi
14import ROOT
15
16
17cell_hashes = set()
18
19
21 ccc = ROOT.CaloCellContainer()
22 for i in range (mgr.element_size()):
23 elt = mgr.get_element (ROOT.IdentifierHash (i))
24 if not elt: break
25 cc = ROOT.CaloCell (elt, 0, 0, 0, 0)
26 ccc.push_back (cc)
27 ROOT.SetOwnership (cc, False)
28 ccc.order()
29 ccc.updateCaloIterators()
30 return ccc
31
32
33def make_clusters (mgr, ccc, hashes, ctx):
34 clc = ROOT.xAOD.CaloClusterContainer()
35 clc_store = ROOT.xAOD.CaloClusterAuxContainer()
36 clc.setStore (clc_store)
37 cellLinks = ROOT.CaloClusterCellLinkContainer()
38 ids = ROOT.vector(ROOT.IdentifierHash)()
39
40 for i in range(2):
41 cl = ROOT.xAOD.CaloCluster()
42 clc.push_back (cl)
43 ROOT.SetOwnership (cl, False)
44 eta = 0.5 - i # 0.5 or -0.5
45 phi = 1
46 cl.setEta (eta)
47 cl.setPhi (phi)
48 cl.setClusterSize (ROOT.xAOD.CaloCluster.SW_37ele)
49 links = ROOT.CaloClusterCellLink (ccc)
50 cl.addCellLink (links)
51 ROOT.SetOwnership (links, False)
52
53 mgr.cellsInZone (eta - 0.05, eta + 0.05, phi - 0.05, phi + 0.05, ids)
54 for hash in ids:
55 elt = mgr.get_element (hash)
56 s = elt.getSampling()
57 if s == 0 or s == 2:
58 idx = ccc.findIndex (hash)
59 if idx < 0:
60 print ("??? Can't find cell with hash ", hash)
61 else:
62 hashes.add (hash.value())
63 cl.addCell (idx, 1)
64 cl.setLink(cellLinks, ctx)
65
66 return (clc, clc_store, cellLinks)
67
68
69class CreateDataAlg (Alg):
70 def execute (self):
71 ctx = self.getContext()
72 mgr = self.condStore['CaloDetDescrManager'].find (ctx.eventID())
73 ccc = make_calo_cells (mgr)
74 self.evtStore.record (ccc, 'AllCalo', False)
75
76 global cell_hashes
77 cell_hashes = set()
78 (clc, clc_store, cellLinks) = make_clusters (mgr, ccc, cell_hashes, ctx)
79 self.evtStore.record (clc, 'Clusters', False)
80 self.evtStore.record (clc_store, 'ClustersAux.', False)
81 self.evtStore.record (cellLinks, 'Clusters_links', False)
82 return StatusCode.Success
83
84
85class CheckThinningAlg (Alg):
86 def isCloseTo (self, elt, eta, phi):
87 # Assuming no phi wrapping.
88 return (abs (elt.eta() - eta) < 3*0.025 and
89 abs (elt.phi() - phi) < 7*2*pi/256)
90
91 def execute (self):
92 ctx = self.getContext()
93 mgr = self.condStore['CaloDetDescrManager'].find (ctx.eventID())
94 dec = self.evtStore['AllCalo_THINNED_StreamAOD.thinAlg']
95
96 for i in range (dec.size()):
97 elt = mgr.get_element (ROOT.IdentifierHash (i))
98 if elt.getSampling() == 3:
99 close = (self.isCloseTo (elt, 0.5, 1) or
100 self.isCloseTo (elt, -0.5, 1))
101 if not dec.thinned(i):
102 assert close
103 else:
104 assert not close
105 else:
106 if not dec.thinned(i):
107 assert i in cell_hashes
108 else:
109 assert i not in cell_hashes
110 return StatusCode.Success
111
112
113def testCfg (flags):
114 result = ComponentAccumulator()
115
116 from LArGeoAlgsNV.LArGMConfig import LArGMCfg
117 from TileGeoModel.TileGMConfig import TileGMCfg
118 result.merge(LArGMCfg(flags))
119 result.merge(TileGMCfg(flags))
120
121 from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
122 result.merge(LArOnOffIdMappingCfg(flags))
123
124 result.addEventAlgo (CreateDataAlg ('CreateDataAlg'))
125
126 CaloThinCellsByClusterAlg=CompFactory.CaloThinCellsByClusterAlg
127 result.addEventAlgo (CaloThinCellsByClusterAlg ('thinAlg',
128 StreamName = 'StreamAOD',
129 Clusters = 'Clusters',
130 SamplingCellsName = ['EMB3']))
131
132 result.addEventAlgo (CheckThinningAlg ('CheckThinningAlg'))
133 return result
134
135
136# Work around issue with cling in root 6.20.06 getting confused
137# by forward declarations.
138ROOT.xAOD.CaloClusterContainer_v1
139
140
141from AthenaConfiguration.AllConfigFlags import initConfigFlags
142from AthenaConfiguration.TestDefaults import defaultTestFiles
143flags = initConfigFlags()
144flags.Input.Files = defaultTestFiles.RDO_RUN2
145flags.Input.TimeStamps = [1000]
146flags.Detector.GeometryLAr = True
147flags.Detector.GeometryTile = True
148flags.needFlagsCategory('Tile')
149flags.needFlagsCategory('LAr')
150
151flags.lock()
152from AthenaConfiguration.MainServicesConfig import MainServicesCfg
153acc = MainServicesCfg(flags)
154
155from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
156acc.merge (McEventSelectorCfg (flags))
157
158acc.merge (testCfg (flags))
159acc.run(1)
STL class.