ATLAS Offline Software
CaloScaleNoiseConfig.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.ComponentFactory import CompFactory
4 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
5 from AthenaConfiguration.MainServicesConfig import MainEvgenServicesCfg
6 
7 from CaloTools.CaloNoiseCondAlgConfig import CaloNoiseCondAlgCfg
8 from LArCalibUtils.LArHVScaleConfig import LArHVScaleCfg
9 from IOVDbSvc.IOVDbSvcConfig import addOverride
10 from AthenaCommon.Logging import logging
11 
12 def CaloScaleNoiseCfg(flagsIn,absolute=True,mu=60,dt=25,output='cellnoise_data.root'):
13 
14  #Clone flags-container and modify it, since this is not a standard reco job
15  flags=flagsIn.clone()
16  flags.Calo.Noise.fixedLumiForNoise=1
17  flags.LAr.doHVCorr = False #Avoid double-rescaling
18  flags.lock()
19 
20  msg = logging.getLogger("CaloScaleNoiseCfg")
21  #pick noise-tag depending on mu and dt
22 
23  if not absolute:
24  #relative rescale, use current UPD-online tag
25  noisetag="LARNoiseOflCellNoise-RUN2-UPD1-00"
26  msg.info("Noise rescaling using tag %s", noisetag)
27  else:
28  if (dt!=25):
29  raise RuntimeError("At this point (early run 3), only a dt of 25ns is supported")
30 
31  if mu==0:
32  noisetag="LARNoiseOflCellNoisenoise-mc16-EposA3-ofc25mu0-25ns"
33  elif mu==60:
34  noisetag="LARNoiseOflCellNoisenoise-mc16-EposA3-ofc25mu60-25ns"
35  else:
36  raise RuntimeError("At this point (early run 3), only mu values of 0 and 60 are supported")
37 
38 
39  msg.info("Absolute noise scaling using tag %s for mu=%i and dt=%i" , noisetag,mu,dt)
40 
41  result=ComponentAccumulator()
42 
43  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
44  result.merge(LArGMCfg(flags))
45  from TileGeoModel.TileGMConfig import TileGMCfg
46  result.merge(TileGMCfg(flags))
47 
48 
49  result.merge(CaloNoiseCondAlgCfg(flags,noisetype="totalNoise"))
50  result.merge(CaloNoiseCondAlgCfg(flags,noisetype="electronicNoise"))
51  result.merge(CaloNoiseCondAlgCfg(flags,noisetype="pileupNoise"))
52 
53 
54  if absolute:
55  result.merge(addOverride(flags,"/LAR/NoiseOfl/CellNoise",noisetag))
56  else:
57  result.merge(addOverride(flags,"/LAR/NoiseOfl/CellNoise",noisetag))
58 
59  result.merge(LArHVScaleCfg(flags))
60 
61  result.addEventAlgo(CompFactory.CaloRescaleNoise(absScaling=absolute))
62 
63  import os
64  rootfile="cellnoise_data.root"
65  if os.path.exists(rootfile):
66  os.remove(rootfile)
67  result.addService(CompFactory.THistSvc(Output = ["file1 DATAFILE='"+output+"' OPT='RECREATE'"]))
68  result.setAppProperty("HistogramPersistency","ROOT")
69 
70  return result
71 
72 
73 if __name__=="__main__":
74  import sys, argparse
75  parser= argparse.ArgumentParser(description="(Re-)scale noise based on HV DCS values")
76  parser.add_argument('datestamp',help="time specification like 2007-05-25:14:01:00")
77  parser.add_argument('-a', '--absolute', action="store_true", help="Absolute rescaling based on noise derived from MC")
78  parser.add_argument('-t', '--globaltag', type=str, help="Global conditions tag ")
79  parser.add_argument('-o', '--output',type=str,default="hvcorr",help="name stub for root and sqlite output files")
80  args = parser.parse_args()
81  print(args)
82 
83  from time import strptime
84  from calendar import timegm
85  try:
86  ts=strptime(args.datestamp+'/UTC','%Y-%m-%d:%H:%M:%S/%Z')
87  TimeStamp=int(timegm(ts))
88  TimeStamp_ns=TimeStamp*1000000000
89  except ValueError as e:
90  print("ERROR in time specification, use e.g. 2007-05-25:14:01:00")
91  print(e)
92  sys.exit(-1)
93 
94 
95  from LArCalibProcessing.TimeStampToRunLumi import TimeStampToRunLumi
96  rlb=TimeStampToRunLumi(TimeStamp_ns)
97  if rlb is None:
98  rlb=[0xFFFFFFFF-1,0]
99  print("WARNING: Failed to convert time",TimeStamp_ns,"into a run/lumi number. Using 'infinite' run-number",rlb[0])
100 
101 
102  from AthenaConfiguration.AllConfigFlags import initConfigFlags
103  flags = initConfigFlags()
104  flags.Input.RunNumbers=[rlb[0]]
105  flags.Input.TimeStamps=[TimeStamp]
106  flags.Input.Files=[]
107  flags.IOVDb.DatabaseInstance="CONDBR2"
108  from AthenaConfiguration.TestDefaults import defaultGeometryTags
109  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
110 
111  if args.globaltag:
112  flags.IOVDb.GlobalTag=args.globaltag
113 
114  flags.lock()
116  cfg.merge(CaloScaleNoiseCfg(flags,absolute=args.absolute,output=args.output))
117 
118  print("Start running...")
119  cfg.run(1)
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.CaloScaleNoiseConfig.CaloScaleNoiseCfg
def CaloScaleNoiseCfg(flagsIn, absolute=True, mu=60, dt=25, output='cellnoise_data.root')
Definition: CaloScaleNoiseConfig.py:12
python.MainServicesConfig.MainEvgenServicesCfg
def MainEvgenServicesCfg(flags, LoopMgr="AthenaEventLoopMgr", withSequences=True)
Definition: MainServicesConfig.py:353
python.IOVDbSvcConfig.addOverride
def addOverride(flags, folder, tag, db=None)
Definition: IOVDbSvcConfig.py:224
python.CaloNoiseCondAlgConfig.CaloNoiseCondAlgCfg
def CaloNoiseCondAlgCfg(flags, noisetype="totalNoise")
Definition: CaloNoiseCondAlgConfig.py:11
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArHVScaleConfig.LArHVScaleCfg
def LArHVScaleCfg(configFlags)
Definition: LArHVScaleConfig.py:8
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
python.TimeStampToRunLumi.TimeStampToRunLumi
def TimeStampToRunLumi(tmstmp, guard=1, dbInstance="CONDBR2")
Definition: TimeStampToRunLumi.py:3
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7