Skip to content

Updating DT Calibration workflows for CMSSW_15_0_4 #47869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: CMSSW_15_0_X
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions CalibMuon/DTCalibration/python/PlottingTools/plotResiduals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
from .fitResidual import fitResidual
from .drawHistoAllChambers import drawHisto

def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option="HISTOPE1",draw=True):
# This script is not to be run standalone.
# Use CalibMuon/DTCalibration/scripts/allPlotsResiduals.py instead.

mean_ymin = -0.02
mean_ymax = 0.02
sig_ymin = 0.
sig_ymax = 0.07
def plot(fileName,sl,dir='DTResiduals', run='1',option="HISTOPE1",draw=True):

if run in ['390106','390170']:
# These are cosmic Runs
mean_ymin = -0.15
mean_ymax = 0.15
sig_ymin = 0.
sig_ymax = 0.15
else:
mean_ymin = -0.02
mean_ymax = 0.02
sig_ymin = 0.
sig_ymax = 0.07

slType = sl
slStr = "SL%d" % slType
Expand All @@ -22,24 +32,26 @@ def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option
stations = (1,2,3,4)

# (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
# (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
# (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
nBins = 250
if slType == 2: nBins = 180
histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals",nBins,0,nBins)
histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals",nBins,0,nBins)
histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals for Run=%s at %s"%(run,slStr),nBins,0,nBins)
histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals for Run=%s at %s"%(run,slStr),nBins,0,nBins)
for st in stations:
nSectors = 12
if st == 4: nSectors = 14
if st == 4 and slType == 2: continue
if st == 4 and slType == 2: continue
if verbose: print("Station",st)
for wh in wheels:
if verbose: print("Wheel",wh)
if verbose: print("Wheel",wh)
for sec in range(1,nSectors+1):
if verbose: print("Sector",sec)
# Get histogram
histoName = "%s/Wheel%d/Station%d/Sector%d/hResDist_STEP3_W%d_St%d_Sec%d_%s" % (dir,wh,st,sec,wh,st,sec,slStr)
histoName = "%s/Wheel%d/Station%d/Sector%d/hResDist_STEP3_W%d_St%d_Sec%d_%s" % (dir,wh,st,sec,wh,st,sec,slStr)

print("Accessing",histoName)
histo = file.Get(histoName)
histo.Print()
(histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
fitMean = fitFunc.GetParameter(1)
fitMeanErr = fitFunc.GetParError(1)
Expand All @@ -52,16 +64,16 @@ def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option
histoMean.SetBinError(binHistoNew,fitMeanErr)
histoSigma.SetBinContent(binHistoNew,fitSigma)
histoSigma.SetBinError(binHistoNew,fitSigmaErr)

if sec == 1:
label = "Wheel %d" % wh
if wh == -2: label += " MB%d" % st
histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
if wh == -2: label += " MB%d" % st
histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)

objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",
ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)


return (objectsMean,objectsSigma)
25 changes: 18 additions & 7 deletions CalibMuon/DTCalibration/python/Workflow/CrabHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ def check_crabtask(self):
for n_check in range(self.options.max_checks):
task.update()
if task.state in ( "COMPLETED"):
print("Crab task complete. Getting output locally")
output_path = os.path.join( self.local_path, "unmerged_results" )
self.get_output_files(task, output_path)
print("Crab task is complete. You can run the next step now.")
#output_path = os.path.join( self.local_path, "unmerged_results" )
#self.get_output_files(task, output_path)
#self.get_output_files(task)
#print("Finished with get_output_files()")
return True
if task.state in ("SUBMITFAILED", "FAILED"):
print("Crab task failed")
Expand All @@ -85,6 +87,7 @@ def check_crabtask(self):
sys.stdout.write("\r")
prompt_text = "Check (%d/%d). Task state: %s (%s). Press q and enter to stop checks: " % (n_check,
self.options.max_checks, task.state, jobinfos)
print(prompt_text)
user_input = tools.stdinWait(prompt_text, "", self.options.check_interval)
if user_input in ("q","Q"):
return False
Expand All @@ -93,9 +96,14 @@ def check_crabtask(self):
return False

def voms_proxy_time_left(self):
process = subprocess.Popen(['voms-proxy-info', '-timeleft'],
stdout=subprocess.PIPE)
log.debug("Checking voms_proxy time left")
process = subprocess.Popen('voms-proxy-info -timeleft',
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell=True
)
stdout = process.communicate()[0]

if process.returncode != 0:
return 0
else:
Expand Down Expand Up @@ -201,7 +209,7 @@ def fill_options_from_crab_config(self):
@property
def crab(self):
""" Retuns a CrabController instance from cache or creates new
on on first call """
if it is a first call """
if self._crab is None:
if self.cert_info.voGroup:
self._crab = self.crabFunctions.CrabController(voGroup = self.cert_info.voGroup)
Expand All @@ -212,11 +220,14 @@ def crab(self):
@property
def cert_info(self):
if not self._cert_info:
log.debug("No cert info yet. Will try to get it.")
if not self.voms_proxy_time_left() > 0:
warn_msg = "No valid proxy, a default proxy without a specific"
warn_msg = "VOGroup will be used"
print("Try to create voms_proxy")
self.voms_proxy_create()
log.warning(warn_msg)
print("... voms_proxy is created")
log.warning(warn_msg)
self._cert_info = self.crabFunctions.CertInfo()
return self._cert_info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CrabController():
# @param self: A previously defined logger. Crab log messages will use this logger as their parent logger.
def __init__(self, debug=0, logger = None , workingArea = None, voGroup = None, username = None):

#print("Initializing CrabController()")
setConsoleLogLevel(LOGLEVEL_MUTE)
self.debug = debug
if workingArea is not None:
Expand Down Expand Up @@ -186,10 +187,13 @@ def status(self,name):
# @param crabArgs A list of arguments for crab beginning with the command
def callCrabCommand( self, crabArgs ):
crabCommandProcessArgs = (self.crab_q, crabArgs)
print("Will run the callCrabCommand:", crabArgs)
p = Process(target=crabCommandProcess, args=(crabCommandProcessArgs))
p.start()
#print("The (multi)Process() started")
res = self.crab_q.get()
p.join()
print("The Crab command Process has finished.")
return res

## Call crab getlog
Expand Down Expand Up @@ -340,12 +344,13 @@ def crabCommandProcess(q,crabCommandArgs):

class CertInfo:
def __init__( self ):
# print("Running CertInfo() init")
p = subprocess.Popen("voms-proxy-info --fqan",
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell=True)
stdout, stderr = p.communicate()
print(stdout)
print("Grid Certificate:", stdout)
if p.returncode != 0:
self.vo = ""
self.voGroup = ""
Expand All @@ -364,8 +369,7 @@ def __init__( self ):
except:
self.voRole = ""

## Class for a single CrabRequest
#e

# This class represents one crab3 task/request
class CrabTask:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def has_crab3_env(self):

def setup_crab_env(self):
# following
#http://.com/questions/3503719/emulating-bash-source-in-python
#http://stackoverflow.com/questions/3503719/emulating-bash-source-in-python
command = ['bash', '-c', 'unset module;source /cvmfs/cms.cern.ch/crab3/crab.sh && env']
proc = subprocess.Popen(command, executable = '/bin/bash', stdout = subprocess.PIPE)

Expand Down
22 changes: 12 additions & 10 deletions CalibMuon/DTCalibration/python/Workflow/DTTtrigWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def prepare_residuals_correction(self):
self.process.source.firstRun = cms.untracked.uint32(self.options.run)
self.process.GlobalTag.globaltag = cms.string(str(self.options.globaltag))

tag = self.prepare_common_write()
self.prepare_common_write()
if self.options.inputT0DB:
log.warning("Option inputT0DB not supported for residual corrections")

Expand All @@ -188,8 +188,7 @@ def prepare_residuals_correction(self):
ttrig_ResidCorr_db = os.path.abspath( os.path.join(self.result_path,
self.get_output_db("residuals", "write")))
self.process.PoolDBOutputService.connect = 'sqlite_file:%s' % ttrig_ResidCorr_db
rootfile_path = os.path.abspath( os.path.join(self.result_path, self.output_file))
merged_file = os.path.join(self.result_path, self.output_file)
merged_file = os.path.join(self.result_path, "Run"+str(self.options.run)+"_"+self.output_file)
self.process.dtTTrigResidualCorrection.correctionAlgoConfig.residualsRootFile = merged_file
self.write_pset_file()

Expand Down Expand Up @@ -240,16 +239,19 @@ def prepare_validation_write(self):
self.pset_name = 'dtDQMClient_cfg.py'
self.pset_template = 'CalibMuon.DTCalibration.dtDQMClient_cfg'
self.process = tools.loadCmsProcess(self.pset_template)
self.prepare_common_write(do_hadd = False)
dqm_files = glob.glob(os.path.join( self.local_path,
"unmerged_results",
"DQM_*.root"))
(crab_tag, crab_folder) = self.prepare_common_write(do_hadd = False)
print("Crab Folder:", crab_folder)
print("Crab Tag:", crab_tag, "\t Run number =", self.options.run)
#print("local path:", self.local_path)
dqm_files = glob.glob(os.path.join( crab_folder, 'results', "DQM_*.root"))
dqm_files[:] = ["file://"+txt for txt in dqm_files]

self.process.source.fileNames = dqm_files
self.process.dqmSaver.dirName = os.path.abspath(self.result_path)
self.process.dqmSaver.workflow = str(self.options.datasetpath)
if self.process.DQMStore.collateHistograms == True:
self.process.dqmSaver.forceRunNumber = self.options.run
# This parameter does not matter, but it has to be in the format /A/B/C:
self.process.dqmSaver.workflow = "/DT/Calib/Validation"
#if self.process.DQMStore.collateHistograms == True:
self.process.dqmSaver.forceRunNumber = self.options.run
self.write_pset_file()

def summary(self):
Expand Down
4 changes: 2 additions & 2 deletions CalibMuon/DTCalibration/python/Workflow/DTVdriftWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def prepare_segment_check(self):
def prepare_segment_write(self):
self.pset_name = 'dtVDriftSegmentWriter_cfg.py'
self.pset_template = 'CalibMuon.DTCalibration.dtVDriftSegmentWriter_cfg'
tag = self.prepare_common_write()
(tag, folder) = self.prepare_common_write()
merged_file = os.path.join(self.result_path, self.output_file)
self.process = tools.loadCmsProcess(self.pset_template)

Expand Down Expand Up @@ -150,7 +150,7 @@ def prepare_meantimer_check(self):
def prepare_meantimer_write(self):
self.pset_name = 'dtVDriftMeanTimerWriter_cfg.py'
self.pset_template = 'CalibMuon.DTCalibration.dtVDriftMeanTimerWriter_cfg'
tag = self.prepare_common_write()
(tag, folder) = self.prepare_common_write()
merged_file = os.path.join(self.result_path, self.output_file)
self.process = tools.loadCmsProcess(self.pset_template)

Expand Down
47 changes: 27 additions & 20 deletions CalibMuon/DTCalibration/python/Workflow/DTWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,31 @@ def prepare_common_submit(self):
self.add_preselection()

def prepare_common_write(self, do_hadd=True):
""" Common operations used in most prepare_[workflow_mode]_erite functions"""
""" Common operations used in most prepare_[workflow_mode]_write functions"""
self.load_options_command("submit")
output_path = os.path.join( self.local_path, "unmerged_results" )
merged_file = os.path.join(self.result_path, self.output_file)
crabtask = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
initUpdate = False)
print("crabFolder:", crabtask.crabFolder)
if not (self.options.skip_stageout or self.files_reveived or self.options.no_exec):
output_files = self.get_output_files(crabtask, output_path)
if "xrootd" not in output_files.keys():
raise RuntimeError("Could not get output files. No xrootd key found.")
if len(output_files["xrootd"]) == 0:
raise RuntimeError("Could not get output files. Output file list is empty.")
log.info("Received files from storage element")
log.info("Using hadd to merge output files")
res = self.get_output_files(crabtask)
print(res)
if res['commandStatus'] != "SUCCESS":
raise RuntimeError("Could not get output files.")
#if len(output_files["xrootd"]) == 0:
# raise RuntimeError("Could not get output files. Output file list is empty.")
#log.info("Received files from storage element")
#log.info("Using hadd to merge output files")
if not self.options.no_exec and do_hadd:
returncode = tools.haddLocal(output_files["xrootd"], merged_file)

output_files = glob.glob(os.path.join( crabtask.crabFolder, 'results', "*.root"))

merged_file = os.path.join(self.result_path, "Run"+str(self.options.run)+"_"+self.output_file)
print("\t The Merged result will be at:\n", merged_file)

returncode = tools.haddLocal(output_files, merged_file)
if returncode != 0:
raise RuntimeError("Failed to merge files with hadd")
return crabtask.crabConfig.Data.outputDatasetTag
return (crabtask.crabConfig.Data.outputDatasetTag, crabtask.crabFolder)

def prepare_common_dump(self, db_path):
self.process = tools.loadCmsProcess(self.pset_template)
Expand All @@ -254,12 +260,12 @@ def addPoolDBESSource( process,

calibDB = cms.ESSource("PoolDBESSource",
CondDB,
timetype = cms.string('runnumber'),
#timetype = cms.string('runnumber'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to mention that this will conflict with #47851

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, actually the opposite. The line is commented out not to conflict with that change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean. This change is already made in that PR. That's fine. When there is time to merge, I will resolve the conflicts.

toGet = cms.VPSet(cms.PSet(
record = cms.string(record),
tag = cms.string(tag),
label = cms.untracked.string(label)
)),
label = cms.untracked.string(label))
),
)
calibDB.connect = cms.string( str(connect) )
#if authPath: calibDB.DBParameters.authenticationPath = authPath
Expand All @@ -270,11 +276,12 @@ def addPoolDBESSource( process,
moduleName)
)

def get_output_files(self, crabtask, output_path):
res = self.crab.callCrabCommand( ["getoutput",
"--dump",
"--xrootd",
crabtask.crabFolder ] )
def get_output_files(self, crabtask):
log.info("Running get_output_files()")
#print("crabtask:", crabtask)
print("crabtask.crabFolder:", crabtask.crabFolder)
res = self.crab.callCrabCommand( ("getoutput", crabtask.crabFolder ) )
log.debug(res)

return res

Expand Down
18 changes: 0 additions & 18 deletions CalibMuon/DTCalibration/python/Workflow/addPoolDBESSource.py

This file was deleted.

Loading