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