ATLAS Offline Software
CaloComputeNoiseConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2025 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 LArCalibUtils.LArHVScaleConfig import LArHVScaleCfg
8 from AthenaCommon.Logging import logging
9 
10 def CaloComputeNoiseCfg(flagsIn,mu=60,nsamp=4,dt=25,output='cellnoise_data.root'):
11 
12  if (dt!=25):
13  raise RuntimeError("At this point (early run 3), only a dt of 25ns is supported")
14 
15  #Clone flags-container and modify it, since this is not a standard reco job
16  flags=flagsIn.clone()
17  flags.Calo.Noise.fixedLumiForNoise=mu
18  flags.LAr.doHVCorr = False #Avoid double-rescaling
19  flags.LAr.ROD.NumberOfCollisions = mu # for OFC computation
20  flags.LAr.ROD.nSamples = nsamp # number of samples to use
21  flags.lock()
22 
23  msg = logging.getLogger("CaloComputeNoiseCfg")
24  #pick noise-tag depending on mu and dt
25 
26  #FIXME: make this configurable
27  minbiastag="LARElecCalibMCMinBias-mc16-Epos-A3-s3687"
28  fsampltag="LARElecCalibMCfSampl-G4101-20371-FTFP_BERT_BIRK_v2"
29  shapetag="LARElecCalibMCShapeLArPileupShape-RUN2-2018"
30  hvcorrtag="LARElecCalibMCHVScaleCorr-IOVDEP-02"
31 
32  msg.info("Noise computing for mu=%i and dt=%i" , mu,dt)
33 
34  result=ComponentAccumulator()
35 
36  from LArGeoAlgsNV.LArGMConfig import LArGMCfg
37  result.merge(LArGMCfg(flags))
38  from TileGeoModel.TileGMConfig import TileGMCfg
39  result.merge(TileGMCfg(flags))
40 
41  from LArRecUtils.LArADC2MeVCondAlgConfig import LArADC2MeVCondAlgCfg
42  from LArRecUtils.LArRecUtilsConfig import LArOFCCondAlgCfg
43  result.merge(LArADC2MeVCondAlgCfg(flags))
44  result.merge(LArOFCCondAlgCfg(flags))
45  result.merge(LArHVScaleCfg(flags))
46 
47  #make proper overrides
48  from IOVDbSvc.IOVDbSvcConfig import addOverride
49  result.merge(addOverride(flags,"/LAR/ElecCalibMC/MinBias", minbiastag))
50  result.merge(addOverride(flags,"/LAR/ElecCalibMC/fSampl", fsampltag))
51  result.merge(addOverride(flags,"/LAR/ElecCalibMC/Shape", shapetag))
52  result.merge(addOverride(flags,"/LAR/ElecCalibMC/HVScaleCorr", hvcorrtag))
53  result.merge(addOverride(flags,"/LAR/NoiseOfl/CellNoise", "LARNoiseOflCellNoise-empty"))
54  result.merge(addOverride(flags,"/TILE/OFL02/NOISE/CELL", "TileOfl02NoiseCell-OF2-05-25ns-R2-single-IOV"))
55  result.merge(addOverride(flags,"/CALO/Ofl/Noise/CellNoise", "CaloOflNoiseCellnoise-empty"))
56 
57  #we need a pedestal folder from data
58  #first remove the MC folder
59  iovdbsvc=result.getService("IOVDbSvc")
60  # check existing list of folders and remove it if found
61  folder="/LAR/ElecCalibMC/Pedestal"
62  for i in range(0,len(iovdbsvc.Folders)):
63  if (iovdbsvc.Folders[i].find(folder)>=0):
64  del iovdbsvc.Folders[i]
65  break
66  condInputLoader=result.getCondAlgo("CondInputLoader")
67  for cil_Loadval in condInputLoader.Load:
68  if folder in cil_Loadval:
69  condInputLoader.Load.remove(cil_Loadval)
70  break
71 
72  #and now configure data one
73  dfolder="/LAR/ElecCalibFlat/Pedestal"
74  iovdbsvc.Folders.append(dfolder+"<db>COOLONL_LAR/CONDBR2</db>")
75  condInputLoader.Load.add(("CondAttrListCollection",dfolder))
76  result.addCondAlgo(CompFactory.getComp("LArFlatConditionsAlg<LArPedestalFlat>")(ReadKey=dfolder,WriteKey="LArPedestal"))
77 
78  result.addEventAlgo(CompFactory.CaloNoiseCompCondAlg(NMinBias=flags.Calo.Noise.fixedLumiForNoise))
79 
80  result.addEventAlgo(CompFactory.CaloRescaleNoise(absScaling=True,
81  ElecNoiseKey="elecNoise",PileupNoiseKey="pileupNoise"))
82 
83  import os
84  if os.path.exists(output):
85  os.remove(output)
86  result.addService(CompFactory.THistSvc(Output = ["file1 DATAFILE='"+output+"' OPT='RECREATE'"]))
87  result.setAppProperty("HistogramPersistency","ROOT")
88 
89  return result
90 
91 
92 if __name__=="__main__":
93  import argparse
94  parser= argparse.ArgumentParser(description="(Compute noise")
95 
96  parser.add_argument('-r', '--run', type=int, default=358013, help="Which run number to use ")
97  parser.add_argument('-t', '--globaltag', type=str, default="OFLCOND-MC21-SDR-RUN3-12",help="Global conditions tag ")
98  parser.add_argument('-o', '--output',type=str,default="cellnoise_data.root",help="name stub for root and sqlite output files")
99  parser.add_argument('-m', '--mu', type=int, default=60, help="Which mu to use ")
100  parser.add_argument('-n', '--nsamples', type=int, default=4, help="Number of samples for OFC/Autocorr ")
101  parser.add_argument('--olevel', type=int, default=3, help="Output level to use ")
102 
103  args = parser.parse_args()
104  print(args)
105 
106 
107  from AthenaConfiguration.AllConfigFlags import initConfigFlags
108  flags = initConfigFlags()
109  flags.Input.RunNumbers=[args.run]
110  print("set the runnumber: ",flags.Input.RunNumbers)
111  flags.Input.Files=[]
112  flags.IOVDb.DatabaseInstance="OFLP200"
113  flags.Input.isMC=True
114  from Campaigns.Utils import Campaign
115  flags.Input.MCCampaign=Campaign.Unknown
116  from AthenaConfiguration.TestDefaults import defaultGeometryTags
117  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
118 
119  flags.LAr.ROD.UseHighestGainAutoCorr = True
120 
121  if args.globaltag:
122  flags.IOVDb.GlobalTag=args.globaltag
123 
124  flags.lock()
126  from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
127  cfg.merge(McEventSelectorCfg(flags,
128  FirstLB = 0,
129  EventsPerRun = 1,
130  FirstEvent = 1,
131  InitialTimeStamp = 0,
132  TimeStampInterval = 1))
133 
134  cfg.merge(CaloComputeNoiseCfg(flags,output=args.output,mu=args.mu,nsamp=args.nsamples))
135 
136  # could not put into algo config
137  cfg.getCondAlgo("LArADC2MeVCondAlg").LArHVScaleCorrKey=""
138 
139  cfg.getService("DetectorStore").Dump=True
140  cfg.getService("ConditionStore").Dump=True
141 
142  cfg.getService("MessageSvc").OutputLevel=args.olevel
143  if args.olevel < 3:
144  cfg.getCondAlgo("LArAutoCorrTotalCondAlg").OutputLevel=3
145  cfg.getCondAlgo("LArOFCCondAlg").OutputLevel=3
146  cfg.getService("MessageSvc").defaultLimit=999999999
147 
148  cfg.printConfig(withDetails=True)
149 
150  print("Start running...")
151  cfg.run(1)
python.CaloComputeNoiseConfig.CaloComputeNoiseCfg
def CaloComputeNoiseCfg(flagsIn, mu=60, nsamp=4, dt=25, output='cellnoise_data.root')
Definition: CaloComputeNoiseConfig.py:10
python.LArRecUtilsConfig.LArOFCCondAlgCfg
def LArOFCCondAlgCfg(flags, name='LArOFCCondAlg', **kwargs)
Definition: LArRecUtilsConfig.py:33
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
python.LArADC2MeVCondAlgConfig.LArADC2MeVCondAlgCfg
def LArADC2MeVCondAlgCfg(flags)
Definition: LArADC2MeVCondAlgConfig.py:6
python.MainServicesConfig.MainEvgenServicesCfg
def MainEvgenServicesCfg(flags, LoopMgr="AthenaEventLoopMgr", withSequences=True)
Definition: MainServicesConfig.py:409
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
python.McEventSelectorConfig.McEventSelectorCfg
def McEventSelectorCfg(flags, **kwargs)
Definition: McEventSelectorConfig.py:5
LArGMConfig.LArGMCfg
def LArGMCfg(flags)
Definition: LArGMConfig.py:8
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:26
python.IOVDbSvcConfig.addOverride
def addOverride(flags, folder, tag, tagType="tag", db=None)
Definition: IOVDbSvcConfig.py:238
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArHVScaleConfig.LArHVScaleCfg
def LArHVScaleCfg(configFlags)
Definition: LArHVScaleConfig.py:8
TileGMConfig.TileGMCfg
def TileGMCfg(flags)
Definition: TileGMConfig.py:7