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="data24_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 
38  args = parser.parse_args()
39  if help in args and args.help is not None and args.help:
40  parser.print_help()
41  sys.exit(0)
42 
43  for _, value in args._get_kwargs():
44  if value is not None:
45  log.debug(value)
46 
47  if len(args.run) < 8:
48  args.run = args.run.zfill(8)
49 
50  # now set flags according parsed options
51  if args.indir != "":
52  InputDir = args.indir
53  else:
54  gain=args.gain.lower().capitalize()
55 
56 
57  if not args.supercells:
58  partstr = args.partition
59  else:
60  partstr = args.partition+"-DT"
61  if args.rawdata:
62  partstr += "-RawData"
63  # here - add optional nsamples
64  InputDir = args.dprefix+args.fprefix+"/calibration_LArElec-Pedestal-32s-"+gain+"-"+partstr+"/"+args.run+"/"+args.fprefix+"."+args.run+".calibration_LArElec-Pedestal-32s-"+gain+"-"+partstr+".daq.RAW/"
65 
66  #Import the configution-method we want to use (here: Pedestal and AutoCorr)
67  from LArCalibProcessing.LArCalib_PedestalAutoCorrConfig import LArPedestalAutoCorrCfg
68 
69  #Import the MainServices (boilerplate)
70  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
71 
72  #Import the flag-container that is the arguemnt to the configuration methods
73  from AthenaConfiguration.AllConfigFlags import initConfigFlags
74  from LArCalibProcessing.LArCalibConfigFlags import addLArCalibFlags
75  flags=initConfigFlags()
76  #first needs to define, if we are with SC or not
77  addLArCalibFlags(flags, args.supercells)
78 
79  #Now we set the flags as required for this particular job:
80  #The following flags help finding the input bytestream files:
81  flags.LArCalib.Input.Dir = InputDir
82  flags.LArCalib.Input.Type = args.trig
83  flags.LArCalib.Input.RunNumbers = [int(args.run),]
84  flags.LArCalib.Input.isRawData = args.rawdata
85 
86  from AthenaConfiguration.TestDefaults import defaultGeometryTags
87  flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
88 
89  # Input files
90  flags.Input.Files=flags.LArCalib.Input.Files
91  #Print the input files we found
92  log.info("Input files to be processed:")
93  for f in flags.Input.Files:
94  log.info(f)
95 
96  if len(flags.Input.Files) == 0 :
97  print("Unable to find any input files. Please check the input directory:",InputDir)
98  sys.exit(0)
99 
100 
101  #Some configs depend on the sub-calo in question
102  #(sets also the preselection of LArRawCalibDataReadingAlg)
103  if not flags.LArCalib.isSC:
104  if args.subdet == 'EMB' or args.subdet == 'EMEC':
105  flags.LArCalib.Input.SubDet="EM"
106  else:
107  flags.LArCalib.Input.SubDet=args.subdet
108 
109  if args.side !="":
110  if args.side == "C":
111  flags.LArCalib.Preselection.Side = [0]
112  elif args.side == "A":
113  flags.LArCalib.Preselection.Side = [1]
114  else:
115  log.warning("Bad side argument: ",args.side," using both!!")
116 
117  if args.subdet == 'EMB':
118  flags.LArCalib.Preselection.BEC = [0]
119  else:
120  flags.LArCalib.Preselection.BEC = [1]
121 
122  if args.subdet == 'FCAL':
123  flags.LArCalib.Preselection.FT = [6]
124  elif args.subdet == 'HEC':
125  flags.LArCalib.Preselection.FT = [3,10,16,22]
126 
127  #Output of this job:
128  OutputPedAutoCorrRootFileName = args.outrprefix + "_" + args.run
129  OutputPedAutoCorrPoolFileName = args.outpprefix + "_" + args.run
130 
131  if args.subdet != "" and not flags.LArCalib.isSC:
132  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + "_"+args.subdet
133  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + "_"+args.subdet
134  if flags.LArCalib.Input.SubDet=="EM":
135  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + args.side
136  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + args.side
137  OutputPedAutoCorrRootFileName = OutputPedAutoCorrRootFileName + ".root"
138  OutputPedAutoCorrPoolFileName = OutputPedAutoCorrPoolFileName + ".pool.root"
139 
140  flags.LArCalib.Output.ROOTFile = args.outrdir + "/" + OutputPedAutoCorrRootFileName
141  flags.LArCalib.Output.POOLFile = args.outpdir + "/" + OutputPedAutoCorrPoolFileName
142  if args.outsql.startswith("/"):
143  flags.IOVDb.DBConnection="sqlite://;schema=" + args.outsql +";dbname=CONDBR2"
144  else:
145  flags.IOVDb.DBConnection="sqlite://;schema="+args.outpdir + "/" + args.outsql +";dbname=CONDBR2"
146 
147  #The global tag we are working with
148  flags.IOVDb.GlobalTag = "LARCALIB-RUN2-00"
149 
150  #BadChannels sqlite file to be created
151  if args.badsql.startswith("/"):
152  flags.LArCalib.BadChannelDB = args.badsql
153  else:
154  flags.LArCalib.BadChannelDB = args.outpdir + "/" + args.badsql
155 
156  #Other potentially useful flags-settings:
157 
158  #Define the global output Level:
159  from AthenaCommon.Constants import INFO
160  flags.Exec.OutputLevel = INFO
161 
162  from AthenaConfiguration.Enums import LHCPeriod
163  flags.GeoModel.Run = LHCPeriod.Run3
164 
165  flags.lock()
166 
167  # create bad chan sqlite file
168  cmdlinerm = (['/bin/rm', '-f', flags.LArCalib.BadChannelDB])
169  if not flags.LArCalib.isSC:
170  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'])
171  else:
172  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'])
173 
174  try:
175  cp = subprocess.run(cmdlinerm, check=True, capture_output=True )
176  except Exception as e:
177  print((" ").join(cmdlinerm))
178  log.info('not existing BadChan sqlite file, fine')
179  sys.exit(-1)
180  print((" ").join(cmdlinerm))
181  print(cp.stdout)
182  try:
183  cp = subprocess.run(cmdline, check=True, capture_output=True )
184  except Exception as e:
185  print(e)
186  print((" ").join(cmdline))
187  log.error('Could not create BadChan sqlite file !!!!')
188  sys.exit(-1)
189  print((" ").join(cmdline))
190  print(cp.stdout)
191 
192  cfg=MainServicesCfg(flags)
193 
194  cfg.merge(LArPedestalAutoCorrCfg(flags))
195 
196  #run the application
197  cfg.run()
198 
199  #build tag hierarchy in output sqlite file
200  if args.outsql.startswith("/"):
201  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py', args.outsql , flags.IOVDb.GlobalTag])
202  else:
203  cmdline = (['/afs/cern.ch/user/l/larcalib/LArDBTools/python/BuildTagHierarchy.py',args.outpdir + "/" + args.outsql , flags.IOVDb.GlobalTag])
204  log.debug(cmdline)
205  try:
206  subprocess.run(cmdline, check=True)
207  except Exception as e:
208  log.error('Could not create tag hierarchy in output sqlite file !!!!')
209  sys.exit(-1)
210 
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:252
Constants
some useful constants -------------------------------------------------—
python.LArCalib_PedestalAutoCorrConfig.LArPedestalAutoCorrCfg
def LArPedestalAutoCorrCfg(flags)
Definition: LArCalib_PedestalAutoCorrConfig.py:5
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
python.LArCalibConfigFlags.addLArCalibFlags
def addLArCalibFlags(flags, isSC=False)
Definition: LArCalibConfigFlags.py:3