ATLAS Offline Software
CaloFwdTopoTowerConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 from AthenaCommon.Logging import logging
6 
7 def CaloFwdTopoTowerCfg(flags,**kwargs):
8 
9  mlog = logging.getLogger('MakeFwdTopoTowerCfg')
10 
11  result=ComponentAccumulator()
12 
13  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
14  from TileGeoModel.TileGMConfig import TileGMCfg
15 
16  result.merge(LArGMCfg(flags))
17  result.merge(TileGMCfg(flags))
18 
19 
20  result.addCondAlgo(CompFactory.CaloTowerGeometryCondAlg(TowerEtaBins = 100,
21  TowerEtaMin = -5,
22  TowerEtaMax = 5.,))
23 
24 
25  kwargs.setdefault("PrepareLCW",flags.Calo.FwdTower.prepareLCW)
26  kwargs.setdefault("TopoClusterRange",flags.Calo.FwdTower.clusterRange)
27  kwargs.setdefault("BuildCombinedTopoSignal",True)
28 
29  #This property is for the algorithm, not for tool doing most of the work
30  towerContainerKey=kwargs.pop('towerContainerKey','CaloCalFwdTopoTowers')
31  signalContainerKey=kwargs.pop('signalContainerKey','CaloCalTopoSignals')
32  towerBuilderName=kwargs.pop('TowerBuilderName','CaloTopoTowerFromClusterMaker')
33  towerMergerName=kwargs.pop('TowerMergerName','CaloTopoSignalMaker')
34 
35  #instatiate tool using kwargs
36  towerBuilder=CompFactory.CaloTopoTowerFromClusterMaker(towerBuilderName,**kwargs)
37 
38  #Remember oderedByPt to (possibly) apply later:
39  orderbyPt=towerBuilder.OrderClusterByPt
40 
41  if flags.Calo.FwdTower.prepareLCW:
42 
43  towerBuilder.OrderClusterByPt=False
44 
45  mlog.info('Consistency check')
46  if towerBuilder.PrepareLCW and not towerBuilder.BuildTopoTowers:
47  raise RuntimeError('{0}[inconsistent configuration] applying LCW requires to build topo-towers'.format(towerBuilder.name()))
48  if towerBuilder.BuildCombinedTopoSignal and not towerBuilder.BuildTopoTowers:
49  raise RuntimeError('{0}[inconsistent configuration] building combined topo-cluster/topo-tower signals requires to build topo-towers'.format(towerBuilder.name()))
50  if towerBuilder.ApplyCellEnergyThreshold and towerBuilder.BuildTopoTowers:
51  raise RuntimeError('{0}[inconsistent configuration] applying cell energy thresholds for topo-towers not yet implemented'.format(towerBuilder.name()))
52 
53  ''' Tower converter configuration summary
54  '''
55  if towerBuilder.BuildTopoTowers:
56  if towerBuilder.PrepareLCW:
57  ''' LCW topo-towers
58  '''
59  mlog.info('################################################')
60  mlog.info('## Produce LCW calibrated topo-tower clusters ##')
61  mlog.info('################################################')
62  mlog.info('CaloTopoClusterContainerKey .. {0}'.format(towerBuilder.CaloTopoClusterContainerKey))
63  #mlog.info('CellClusterWeightKey ......... {0}'.format(towerBuilder.CellClusterWeightKey))
64  else:
65  ''' EM topo-towers
66  '''
67  mlog.info('###############################################')
68  mlog.info('## Produce EM calibrated topo-tower clusters ##')
69  mlog.info('###############################################')
70  mlog.info('CaloTopoClusterContainerKey .. {0}'.format(towerBuilder.CaloTopoClusterContainerKey))
71 
72  if towerBuilder.BuildCombinedTopoSignal:
73  mlog.info(' ')
74  mlog.info('Combined topo-cluster/topo-towermode with y_max = {0}'.format(towerBuilder.TopoClusterRange))
75  else:
76  ''' EM towers
77  '''
78  mlog.info('########################################')
79  mlog.info('## Produce EM standard tower clusters ##')
80  mlog.info('########################################')
81 
82  #Configure moments maker (requires noise ...)
83  from CaloTools.CaloNoiseCondAlgConfig import CaloNoiseCondAlgCfg
84  result.merge(CaloNoiseCondAlgCfg(flags, noisetype="totalNoise"))
85 
86  baseName=towerBuilder.name.replace("Builder","").replace("Maker","")
87  from AthenaCommon.SystemOfUnits import deg
88 
89  clusterMoments = CompFactory.CaloClusterMomentsMaker (baseName+'MomentMaker')
90  clusterMoments.MaxAxisAngle = 20*deg
91  clusterMoments.TwoGaussianNoise = flags.Calo.TopoCluster.doTwoGaussianNoise
92  clusterMoments.MinBadLArQuality = 4000
93  clusterMoments.MomentsNames = [
94  # "CENTER_LAMBDA",
95  # "CENTER_MAG",
96  "LONGITUDINAL",
97  # "FIRST_ENG_DENS",
98  # "ENG_FRAC_MAX",
99  "ENG_FRAC_EM",
100  # "PTD",
101  "SIGNIFICANCE",
102  # "ENG_POS",
103  ]
104 
105  if not flags.Common.isOnline:
106  from LArConfiguration.LArElecCalibDBConfig import LArElecCalibDBCfg
107  result.merge(LArElecCalibDBCfg(flags,["HVScaleCorr"]))
108  if flags.Input.isMC:
109  clusterMoments.LArHVFraction=CompFactory.LArHVFraction(HVScaleCorrKey="LArHVScaleCorr")
110  else:
111  clusterMoments.LArHVFraction=CompFactory.LArHVFraction(HVScaleCorrKey="LArHVScaleCorrRecomputed")
112 
113  clusterMoments.MomentsNames += ["ENG_BAD_HV_CELLS","N_BAD_HV_CELLS"]
114 
115  #instantiate Algorithm:
116  towerMaker = CompFactory.CaloTopoTowerMaker(baseName+"Alg")
117  towerMaker.TowersOutputName = towerContainerKey
118  towerMaker.TowerMakerTool = towerBuilder
119 
120  from CaloBadChannelTool.CaloBadChanToolConfig import CaloBadChanToolCfg
121  caloBadChanTool = result.popToolsAndMerge( CaloBadChanToolCfg(flags) )
122  CaloClusterBadChannelList=CompFactory.CaloClusterBadChannelList
123  BadChannelListCorr = CaloClusterBadChannelList(badChannelTool = caloBadChanTool)
124 
125 
126  towerMaker.TowerCorrectionTools += [BadChannelListCorr,clusterMoments]
127 
128  if towerBuilder.PrepareLCW:
129  ''' Configure name for calibration tool
130  '''
131  towerCalName = baseName+'Calibrator'
132  towerCalibrator = CompFactory.CaloTopoTowerFromClusterCalibrator(towerCalName)
133  towerCalibrator.OrderClusterByPt = orderbyPt
134 
135  towerMaker.TowerCalibratorTool = towerCalibrator
136 
137  result.addEventAlgo(towerMaker)
138 
139  #merging
140  if towerBuilder.TopoClusterRange > 0.:
141  caloTowerMerger = CompFactory.CaloTopoClusterTowerMerger(towerMergerName)
142  caloTowerMerger.TopoClusterRange = towerBuilder.TopoClusterRange
143  caloTowerMerger.TopoClusterContainerKey = towerBuilder.CaloTopoClusterContainerKey
144  caloTowerMerger.TopoTowerContainerKey = towerMaker.TowersOutputName
145  caloTowerMerger.TopoSignalContainerKey = signalContainerKey
146 
147  result.addEventAlgo(caloTowerMerger)
148 
149  #Output Config:
150  from OutputStreamAthenaPool.OutputStreamConfig import addToAOD, addToESD
151  toESD=[f"xAOD::CaloClusterContainer#{towerContainerKey}",
152  f"xAOD::CaloClusterAuxContainer#{towerContainerKey}Aux.",
153  f"CaloClusterCellLinkContainer#{towerContainerKey}_links"]
154 
155 
156  AODAuxItems=f"xAOD::CaloClusterAuxContainer#{towerContainerKey}Aux"
157  for mom in ("CENTER_LAMBDA",
158  #"CENTER_MAG",
159  "LONGITUDINAL",
160  #"FIRST_ENG_DENS",
161  #"ENG_FRAC_MAX",
162  "ENG_FRAC_EM",
163  #"PTD",
164  "SIGNIFICANCE",
165  "ENG_POS"):
166  AODAuxItems+="."+mom
167 
168  toAOD=[f"xAOD::CaloClusterContainer#{towerContainerKey}",AODAuxItems]
169 
170  result.merge(addToESD(flags, toESD))
171 
172  if flags.Calo.FwdTower.WriteToAOD:
173  result.merge(addToAOD(flags, toAOD))
174 
175  return result
176 
177 
178 if __name__=="__main__":
179  from AthenaConfiguration.AllConfigFlags import initConfigFlags
180  flags = initConfigFlags()
181  flags.Input.Files = ["/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/RecExRecoTest/mc20e_13TeV/valid1.410000.PowhegPythiaEvtGen_P2012_ttbar_hdamp172p5_nonallhad.ESD.e4993_s3227_r12689/myESD.pool.root"]
182  flags.Output.ESDFileName="esdOut.pool.root"
183 
184  flags.lock()
185 
186  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
187  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
188 
189  cfg=MainServicesCfg(flags)
190  cfg.merge(PoolReadCfg(flags))
191 
192  towerAcc=CaloFwdTopoTowerCfg(flags,towerContainerKey="NewTowers",CaloTopoClusterContainerKey="CaloCalTopoClusters")
193 
194  cfg.merge(towerAcc)
195 
196  cfg.run(10)
python.LArElecCalibDBConfig.LArElecCalibDBCfg
def LArElecCalibDBCfg(flags, condObjs)
Definition: LArElecCalibDBConfig.py:47
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
CaloClusterBadChannelList
Definition: CaloClusterBadChannelList.h:26
SystemOfUnits
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
python.CaloFwdTopoTowerConfig.CaloFwdTopoTowerCfg
def CaloFwdTopoTowerCfg(flags, **kwargs)
Definition: CaloFwdTopoTowerConfig.py:7
python.CaloNoiseCondAlgConfig.CaloNoiseCondAlgCfg
def CaloNoiseCondAlgCfg(flags, noisetype="totalNoise")
Definition: CaloNoiseCondAlgConfig.py:11
CaloBadChanToolConfig.CaloBadChanToolCfg
def CaloBadChanToolCfg(flags, **kwargs)
Definition: CaloBadChanToolConfig.py:8
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
python.OutputStreamConfig.addToESD
def addToESD(flags, itemOrList, **kwargs)
Definition: OutputStreamConfig.py:127
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.OutputStreamConfig.addToAOD
def addToAOD(flags, itemOrList, **kwargs)
Definition: OutputStreamConfig.py:142
python.PoolReadConfig.PoolReadCfg
def PoolReadCfg(flags)
Definition: PoolReadConfig.py:69
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7