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  towerMaker.UseLCWCalibration = towerBuilder.PrepareLCW
120 
121  from CaloBadChannelTool.CaloBadChanToolConfig import CaloBadChanToolCfg
122  caloBadChanTool = result.popToolsAndMerge( CaloBadChanToolCfg(flags) )
123  CaloClusterBadChannelList=CompFactory.CaloClusterBadChannelList
124  BadChannelListCorr = CaloClusterBadChannelList(badChannelTool = caloBadChanTool)
125 
126 
127  towerMaker.TowerCorrectionTools += [BadChannelListCorr,clusterMoments]
128 
129  if towerBuilder.PrepareLCW:
130  ''' Configure name for calibration tool
131  '''
132  towerCalName = baseName+'Calibrator'
133  towerCalibrator = CompFactory.CaloTopoTowerFromClusterCalibrator(towerCalName)
134  towerCalibrator.OrderClusterByPt = orderbyPt
135 
136  towerMaker.TowerCalibratorTool = towerCalibrator
137 
138  result.addEventAlgo(towerMaker)
139 
140  #merging
141  if towerBuilder.TopoClusterRange > 0.:
142  caloTowerMerger = CompFactory.CaloTopoClusterTowerMerger(towerMergerName)
143  caloTowerMerger.TopoClusterRange = towerBuilder.TopoClusterRange
144  caloTowerMerger.TopoClusterContainerKey = towerBuilder.CaloTopoClusterContainerKey
145  caloTowerMerger.TopoTowerContainerKey = towerMaker.TowersOutputName
146  caloTowerMerger.TopoSignalContainerKey = signalContainerKey
147 
148  result.addEventAlgo(caloTowerMerger)
149 
150  #Output Config:
151  from OutputStreamAthenaPool.OutputStreamConfig import addToAOD, addToESD
152  toESD=[f"xAOD::CaloClusterContainer#{towerContainerKey}",
153  f"xAOD::CaloClusterAuxContainer#{towerContainerKey}Aux.",
154  f"CaloClusterCellLinkContainer#{towerContainerKey}_links"]
155 
156 
157  AODAuxItems=f"xAOD::CaloClusterAuxContainer#{towerContainerKey}Aux"
158  for mom in ("CENTER_LAMBDA",
159  #"CENTER_MAG",
160  "LONGITUDINAL",
161  #"FIRST_ENG_DENS",
162  #"ENG_FRAC_MAX",
163  "ENG_FRAC_EM",
164  #"PTD",
165  "SIGNIFICANCE",
166  "ENG_POS"):
167  AODAuxItems+="."+mom
168 
169  toAOD=[f"xAOD::CaloClusterContainer#{towerContainerKey}",AODAuxItems]
170 
171  result.merge(addToESD(flags, toESD))
172 
173  if flags.Calo.FwdTower.WriteToAOD:
174  result.merge(addToAOD(flags, toAOD))
175 
176  return result
177 
178 
179 if __name__=="__main__":
180  from AthenaConfiguration.AllConfigFlags import initConfigFlags
181  flags = initConfigFlags()
182  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"]
183  flags.Output.ESDFileName="esdOut.pool.root"
184 
185  flags.lock()
186 
187  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
188  from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
189 
190  cfg=MainServicesCfg(flags)
191  cfg.merge(PoolReadCfg(flags))
192 
193  towerAcc=CaloFwdTopoTowerCfg(flags,towerContainerKey="NewTowers",CaloTopoClusterContainerKey="CaloCalTopoClusters")
194 
195  cfg.merge(towerAcc)
196 
197  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