ATLAS Offline Software
LArNewCalib_PedestalAutoCorr.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 if __name__=='__main__':
7 
8  import os,sys
9  import argparse
10  import subprocess
11  from AthenaCommon import Logging
12  log = Logging.logging.getLogger( 'LArPedestalAutoCorr' )
13 
14  MinSample = -1
15  MaxSample = -1
16 
17  # now process the CL options and assign defaults
18  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19  #parser.add_argument('-r','--runlist', dest='runlist', default=RunNumberList, nargs='+', help='Run numbers string list', type=str)
20  parser.add_argument('-r','--run', dest='run', default='00408913', help='Run number string as in input filename', type=str)
21  parser.add_argument('-g','--gain', dest='gain', default="MEDIUM", help='Gain string', type=str)
22  parser.add_argument('-p','--partition', dest='partition', default="All", help='Partition string', type=str)
23  parser.add_argument('-f','--fileprefix', dest='fprefix', default="data25_calib", help='File prefix string', type=str)
24  parser.add_argument('-i','--indirprefix', dest='dprefix', default="/eos/atlas/atlastier0/rucio/", help='Input directory prefix string', type=str)
25  parser.add_argument('-d','--indir', dest='indir', default="", help='Full input dir string', type=str)
26  parser.add_argument('-t','--trigger', dest='trig', default='calibration_', help='Trigger string in filename', type=str)
27  parser.add_argument('-o','--outrprefix', dest='outrprefix', default="LArPedAutoCorr", help='Prefix of output root filename', type=str)
28  parser.add_argument('-l','--outpprefix', dest='outpprefix', default="LArPedAutoCorr", help='Prefix of output pool filename', type=str)
29  parser.add_argument('-e','--outrdir', dest='outrdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/ntuples", help='Output root file directory', type=str)
30  parser.add_argument('-k','--outpdir', dest='outpdir', default="/eos/atlas/atlascerngroupdisk/det-larg/Temp/Weekly/poolFiles", help='Output pool file directory', type=str)
31  parser.add_argument('-n','--outsqlite', dest='outsql', default="mysql.db", help='Output sqlite file, in pool output dir.', type=str)
32  parser.add_argument('-m','--subdet', dest='subdet', default="EMB", help='Subdetector, EMB, EMEC, HEC or FCAL', type=str)
33  parser.add_argument('-s','--side', dest='side', default="C", help='Detector side empty (means both), C or A', type=str)
34  parser.add_argument('-c','--isSC', dest='supercells', default=False, action="store_true", help='is SC data ?')
35  parser.add_argument('-a','--isRawdata', dest='rawdata', default=False, action="store_true", help='is raw data ?')
36  parser.add_argument('-b','--badchansqlite', dest='badsql', default="SnapshotBadChannel.db", help='Input sqlite file with bad chans.', type=str)
37  parser.add_argument('--FW6', dest='fw6', default=False, help='Is it for fw v. 6', action='store_true')
38  parser.add_argument('--EMF', dest='emf', default=False, help='Is it for EMF', action='store_true')
39  parser.add_argument('--nsamples', dest='nsamp', default="32", help='number of samples taken (default 32', type=str)
40 
41  args = parser.parse_args()
42  if help in args and args.help is not None and args.help:
43  parser.print_help()
44  sys.exit(0)
45 
46  for _, value in args._get_kwargs():
47  if value is not None:
48  log.debug(value)
49 
50  if len(args.run) < 8:
51  args.run = args.run.zfill(8)
52 
53  # now set flags according parsed options
54  if args.indir != "":
55  InputDir = args.indir
56  else:
57  gain=args.gain.lower().capitalize()
58 
59 
60  if not args.supercells:
61  partstr = args.partition
62  else:
63  partstr = args.partition+"-DT"
64  if args.rawdata:
65  partstr += "-RawData"
66  InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Pedestal-"+args.nsamp+"s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Pedestal-"+args.nsamp+"s-"+gain+"-"+partstr+".daq.RAW/"
67 
68  #Import the configution-method we want to use (here: Pedestal and AutoCorr)
69  from LArCalibProcessing.LArCalib_PedestalAutoCorrConfig import LArPedestalAutoCorrCfg
70 
71  #Import the MainServices (boilerplate)
72  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
73 
74  #Import the flag-container that is the arguemnt to the configuration methods
75  from AthenaConfiguration.AllConfigFlags import initConfigFlags
76  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
77  flags=initConfigFlags()
78  #first needs to define, if we are with SC or not
79  addLArCalibFlags(flags, args.supercells)
80 
81  #Now we set the flags as required for this particular job:
82  #The following flags help finding the input bytestream files:
83  flags.LArCalib.Input.Dir = InputDir
84  flags.LArCalib.Input.Type = args.trig
85  flags.LArCalib.Input.RunNumbers = [int(args.run),]
86  flags.LArCalib.Input.isRawData = args.rawdata
87 
88  from AthenaConfiguration.TestDefaults import defaultGeometryTags
89  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
90 
91  # Input files
92  flags.Input.Files=flags.LArCalib.Input.Files
93  #Print the input files we found
94  log.info("Input files to be processed:")
95  for f in flags.Input.Files:
96  log.info(f)
97 
98  if len(flags.Input.Files) == 0 :
99  print("Unable to find any input files. Please check the input directory:",InputDir)
100  sys.exit(0)
101 
102 
103  #Some configs depend on the sub-calo in question
104  #(sets also the preselection of LArRawCalibDataReadingAlg)
105  if not flags.LArCalib.isSC:
106  if args.subdet == 'EMB' or args.subdet == 'EMEC':
107  flags.LArCalib.Input.SubDet="EM"
108  else:
109  flags.LArCalib.Input.SubDet=args.subdet
110 
111  if args.side !="":
112  if args.side == "C":
113  flags.LArCalib.Preselection.Side = [0]
114  elif args.side == "A":
115  flags.LArCalib.Preselection.Side = [1]
116  else:
117  log.warning("Bad side argument: %s using both!!", args.side)
118 
119  if args.subdet == 'EMB':
120  flags.LArCalib.Preselection.BEC = [0]
121  else:
122  flags.LArCalib.Preselection.BEC = [1]
123 
124  if args.subdet == 'FCAL':
125  flags.LArCalib.Preselection.FT = [6]
126  elif args.subdet == 'HEC':
127  flags.LArCalib.Preselection.FT = [3,10,16,22]
128 
129  #Output of this job:
130  OutputPedAutoCorrRootFileName = args.outrprefix + "_" + args.run
131  OutputPedAutoCorrPoolFileName = args.outpprefix + "_" + args.run
132 
133  if args.subdet != "" and not flags.LArCalib.isSC:
134  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + "_"+args.subdet
135  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + "_"+args.subdet
136  if flags.LArCalib.Input.SubDet=="EM":
137  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + args.side
138  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + args.side
139  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + ".root"
140  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + ".pool.root"
141 
142  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputPedAutoCorrRootFileName
143  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputPedAutoCorrPoolFileName
144  if args.outsql.startswith("/"):
145  flags.IOVDb.DBConnection="sqlite://;schema=" + args.outsql +";dbname=CONDBR2"
146  else:
147  flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
148 
149  #The global tag we are working with
150  flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
151 
152  #BadChannels sqlite file to be created
153  if not args.emf:
154  if args.badsql.startswith("/"):
155  flags.LArCalib.BadChannelDB = args.badsql
156  else:
157  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
158 
159  #Other potentially useful flags-settings:
160 
161  #Define the global output Level:
162  from AthenaCommon.Constants import INFO
163  flags.Exec.OutputLevel = INFO
164 
165  # testing Acorr patching
166  flags.LArCalib.CorrectBadChannels=True
167 
168  from AthenaConfiguration.Enums import LHCPeriod
169  flags.GeoModel.Run = LHCPeriod.Run3
170 
171  if args.emf:
172  # additions for EMF
173  flags.IOVDb.SqliteInput="/afs/cern.ch/user/p/pavol/public/EMF_otherCond.db"
174  flags.IOVDb.SqliteFolders = ("/LAR/BadChannelsOfl/BadChannelsSC","/LAR/BadChannels/BadChannelsSC","/LAR/Identifier/OnOffIdMap","/LAR/BadChannelsOfl/MissingFEBs","/LAR/BadChannelsOfl/KnownMNBFEBs", "/LAR/BadChannelsOfl/KnownBADFEBs")
175  flags.LArCalib.doValidation = False
176 
177  flags.lock()
178  flags.dump(evaluate=True)
179 
180  # create bad chan sqlite file
181  cmdlinerm = (['/bin/rm', '-f', flags.LArCalib.BadChannelDB])
182  if not flags.LArCalib.isSC:
183  cmdline = (['AtlCoolCopy', 'COOLOFL_LAR/CONDBR2', 'sqlite://;schema='+flags.LArCalib.BadChannelDB+';dbname=CONDBR2', '-f', '/LAR/BadChannelsOfl/BadChannels', '-f', '/LAR/BadChannelsOfl/MissingFEBs', '-t', flags.IOVDb.GlobalTag, '-c', '-a', '-hitag'])
184  else:
185  cmdline = (['AtlCoolCopy', 'COOLOFL_LAR/CONDBR2', 'sqlite://;schema='+flags.LArCalib.BadChannelDB+';dbname=CONDBR2', '-f', '/LAR/BadChannelsOfl/BadChannelsSC', '-t', 'LARBadChannelsOflBadChannelsSC'+flags.LArCalib.BadChannelTagSC, '-c', '-a', '-hitag', '-ch', '0'])
186 
187  try:
188  cp = subprocess.run(cmdlinerm, check=True, capture_output=True )
189  except Exception as e:
190  print((" ").join(cmdlinerm))
191  log.info('not existing BadChan sqlite file, fine')
192  sys.exit(-1)
193  print((" ").join(cmdlinerm))
194  print(cp.stdout)
195  try:
196  cp = subprocess.run(cmdline, check=True, capture_output=True )
197  except Exception as e:
198  print(e)
199  print((" ").join(cmdline))
200  log.error('Could not create BadChan sqlite file !!!!')
201  sys.exit(-1)
202  print((" ").join(cmdline))
203  print(cp.stdout)
204 
205 
206  cfg=MainServicesCfg(flags)
207 
208  cfg.merge(LArPedestalAutoCorrCfg(flags))
209 
210  if flags.LArCalib.isSC:
211  fwversion=5
212  # autoconfig
213  from LArConditionsCommon.LArRunFormat import getLArDTInfoForRun
214  try:
215  runinfo=getLArDTInfoForRun(flags.Input.RunNumbers[0], connstring="COOLONL_LAR/CONDBR2")
216  log.info("Got DT run info !")
217  except Exception:
218  log.warning("Could not get DT run info, using defaults !")
219  else:
220  fwversion=runinfo.FWversion()
221  if args.fw6 or fwversion==6:
222  #FIXME: for some reason addOverride is not working, CA merger is then complaining
223  #from IOVDbSvc.IOVDbSvcConfig import addOverride
224  #cfg.merge(addOverride(flags,"/LAR/Identifier/LatomeMapping","LARIdentifierLatomeMapping-fw6"))
225  fldrs=cfg.getService("IOVDbSvc").Folders
226  for i in range(0, len(fldrs)):
227  if 'LatomeMapping' in fldrs[i]: fldrs[i] += '<tag>LARIdentifierLatomeMapping-fw6</tag>'
228 
229  if args.emf:
230  fldrs=cfg.getService("IOVDbSvc").Folders
231  for i in range(0, len(fldrs)):
232  if 'Align' in fldrs[i]: fldrs[i] += '<forceRunNumber>9999999</forceRunNumber>'
233  if 'LatomeMapping' in fldrs[i]: fldrs[i] += '<tag>LARIdentifierLatomeMapping-EMF</tag>'
234 
235 
236  #run the application
237  cfg.run()
238 
239  #build tag hierarchy in output sqlite file
240  if args.outsql.startswith("/"):
241  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py', args.outsql , flags.IOVDb.GlobalTag])
242  else:
243  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
244  log.debug(cmdline)
245  try:
246  subprocess.run(cmdline, check=True)
247  except Exception as e:
248  log.error('Could not create tag hierarchy in output sqlite file !!!!')
249  sys.exit(-1)
250 
python.LArRunFormat.getLArDTInfoForRun
def getLArDTInfoForRun(run, quiet=False, connstring="COOLONL_LAR/CONDBR2")
Definition: LArRunFormat.py:152
LArRunFormat
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:312
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
Constants
some useful constants -------------------------------------------------—
python.LArCalib_PedestalAutoCorrConfig.LArPedestalAutoCorrCfg
def LArPedestalAutoCorrCfg(flags)
Definition: LArCalib_PedestalAutoCorrConfig.py:32
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3