ATLAS Offline Software
CaloThinCellsByClusterAlg_test.py
Go to the documentation of this file.
1 #
2 # Copyright (C) 2002-2023 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 
10 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
11 from AthenaConfiguration.ComponentFactory import CompFactory
12 from AthenaPython.PyAthenaComps import Alg, StatusCode
13 from math import pi
14 import ROOT
15 
16 
17 cell_hashes = set()
18 
19 
20 def make_calo_cells (mgr):
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 
33 def 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 
65  cl.setLink(cellLinks,ctx)
66 
67  return (clc, clc_store, cellLinks)
68 
69 
70 class CreateDataAlg (Alg):
71  def execute (self):
72  ctx = self.getContext()
73  mgr = self.condStore['CaloDetDescrManager'].find (ctx.eventID())
74  ccc = make_calo_cells (mgr)
75  self.evtStore.record (ccc, 'AllCalo', False)
76 
77  global cell_hashes
78  cell_hashes = set()
79  (clc, clc_store, cellLinks) = make_clusters (mgr, ccc, cell_hashes, ctx)
80  self.evtStore.record (clc, 'Clusters', False)
81  self.evtStore.record (clc_store, 'ClustersAux.', False)
82  self.evtStore.record (cellLinks, 'Clusters_links', False)
83  return StatusCode.Success
84 
85 
86 class CheckThinningAlg (Alg):
87  def isCloseTo (self, elt, eta, phi):
88  # Assuming no phi wrapping.
89  return (abs (elt.eta() - eta) < 3*0.025 and
90  abs (elt.phi() - phi) < 7*2*pi/256)
91 
92  def execute (self):
93  ctx = self.getContext()
94  mgr = self.condStore['CaloDetDescrManager'].find (ctx.eventID())
95  dec = self.evtStore['AllCalo_THINNED_StreamAOD.thinAlg']
96 
97  global cell_hashes
98  for i in range (dec.size()):
99  elt = mgr.get_element (ROOT.IdentifierHash (i))
100  if elt.getSampling() == 3:
101  close = (self.isCloseTo (elt, 0.5, 1) or
102  self.isCloseTo (elt, -0.5, 1))
103  if not dec.thinned(i):
104  assert close
105  else:
106  assert not close
107  else:
108  if not dec.thinned(i):
109  assert i in cell_hashes
110  else:
111  assert i not in cell_hashes
112  return StatusCode.Success
113 
114 
115 def testCfg (flags):
116  result = ComponentAccumulator()
117 
118  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
119  from TileGeoModel.TileGMConfig import TileGMCfg
120  result.merge(LArGMCfg(flags))
121  result.merge(TileGMCfg(flags))
122 
123  from LArCabling.LArCablingConfig import LArOnOffIdMappingCfg
124  result.merge(LArOnOffIdMappingCfg(flags))
125 
126  result.addEventAlgo (CreateDataAlg ('CreateDataAlg'))
127 
128  CaloThinCellsByClusterAlg=CompFactory.CaloThinCellsByClusterAlg
129  result.addEventAlgo (CaloThinCellsByClusterAlg ('thinAlg',
130  StreamName = 'StreamAOD',
131  Clusters = 'Clusters',
132  SamplingCellsName = ['EMB3']))
133 
134  result.addEventAlgo (CheckThinningAlg ('CheckThinningAlg'))
135  return result
136 
137 
138 # Work around issue with cling in root 6.20.06 getting confused
139 # by forward declarations.
140 ROOT.xAOD.CaloClusterContainer_v1
141 
142 
143 from AthenaConfiguration.AllConfigFlags import initConfigFlags
144 from AthenaConfiguration.TestDefaults import defaultTestFiles
146 flags.Input.Files = defaultTestFiles.RDO_RUN2
147 flags.Input.TimeStamps = [1000]
148 flags.Detector.GeometryLAr = True
149 flags.Detector.GeometryTile = True
150 flags.needFlagsCategory('Tile')
151 flags.needFlagsCategory('LAr')
152 
153 flags.lock()
154 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
155 acc = MainServicesCfg(flags)
156 
157 from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
158 acc.merge (McEventSelectorCfg (flags))
159 
160 acc.merge (testCfg (flags))
161 acc.run(1)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.CaloThinCellsByClusterAlg_test.CheckThinningAlg.isCloseTo
def isCloseTo(self, elt, eta, phi)
Definition: CaloThinCellsByClusterAlg_test.py:87
python.CaloThinCellsByClusterAlg_test.CreateDataAlg
Definition: CaloThinCellsByClusterAlg_test.py:70
python.CaloThinCellsByClusterAlg_test.CheckThinningAlg
Definition: CaloThinCellsByClusterAlg_test.py:86
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.CaloThinCellsByClusterAlg_test.make_calo_cells
def make_calo_cells(mgr)
Definition: CaloThinCellsByClusterAlg_test.py:20
python.CaloThinCellsByClusterAlg_test.make_clusters
def make_clusters(mgr, ccc, hashes, ctx)
Definition: CaloThinCellsByClusterAlg_test.py:33
LArCablingConfig.LArOnOffIdMappingCfg
def LArOnOffIdMappingCfg(configFlags)
Definition: LArCablingConfig.py:62
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
python.CaloThinCellsByClusterAlg_test.testCfg
def testCfg(flags)
Definition: CaloThinCellsByClusterAlg_test.py:115
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.CaloThinCellsByClusterAlg_test.CheckThinningAlg.execute
def execute(self)
Definition: CaloThinCellsByClusterAlg_test.py:92
python.CaloThinCellsByClusterAlg_test.CreateDataAlg.execute
def execute(self)
Definition: CaloThinCellsByClusterAlg_test.py:71
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7