Skip to content

Commit 67c05b0

Browse files
authored
Merge pull request #48149 from andreypz/test-rebase-22May
Update DT calibration workflows to work with newest CMSSW releases
2 parents 8fd34ae + 5b9c7a7 commit 67c05b0

17 files changed

+202
-240
lines changed

CalibMuon/DTCalibration/python/PlottingTools/drawHistoAllChambers.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
import ROOT
22

3-
def drawHisto(histo,title,ymin,ymax,option="HISTOP",draw=True):
3+
def drawHisto(histo,yaxis_title,ymin,ymax,option="HISTOP",draw=True):
4+
ROOT.gStyle.SetPadRightMargin(0.02)
5+
ROOT.gStyle.SetPadLeftMargin(0.07)
6+
47
histo.SetStats(0)
58
histo.SetLineWidth(3)
69
histo.SetMarkerStyle(20)
710
histo.SetMarkerSize(0.9)
811
histo.GetYaxis().SetRangeUser(ymin,ymax)
9-
histo.GetYaxis().SetTitle(title)
12+
histo.GetYaxis().SetTitleOffset(1.)
13+
histo.GetYaxis().SetDecimals(1)
14+
histo.GetYaxis().SetMaxDigits(4)
15+
histo.GetYaxis().SetTitle(yaxis_title)
1016
histo.GetXaxis().SetLabelSize(0.04)
1117
histo.GetXaxis().SetTickLength(0.)
1218
histo.LabelsOption("d","X")
13-
19+
1420
fillColor = 0
1521
canvas = None
1622
if draw:
17-
canvas = ROOT.TCanvas("c_" + histo.GetName())
23+
canvas = ROOT.TCanvas("c_" + histo.GetName(), "Default Canvas", 1000, 500)
1824
canvas.SetGridy()
1925
canvas.SetFillColor(fillColor)
20-
if draw: histo.Draw(option)
26+
histo.Draw(option)
27+
2128

2229
linesWh = {}
2330
linesSt = {}

CalibMuon/DTCalibration/python/PlottingTools/plotResiduals.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
from .fitResidual import fitResidual
33
from .drawHistoAllChambers import drawHisto
44

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

7-
mean_ymin = -0.02
8-
mean_ymax = 0.02
9-
sig_ymin = 0.
10-
sig_ymax = 0.07
8+
def plot(fileName,sl,dir='DTResiduals', run='1',option="HISTOPE1",draw=True):
9+
10+
if run in ['390106','390170']:
11+
# These are cosmic Runs
12+
mean_ymin = -0.15
13+
mean_ymax = 0.15
14+
sig_ymin = 0.
15+
sig_ymax = 0.15
16+
else:
17+
mean_ymin = -0.02
18+
mean_ymax = 0.02
19+
sig_ymin = 0.
20+
sig_ymax = 0.07
1121

1222
slType = sl
1323
slStr = "SL%d" % slType
@@ -22,23 +32,23 @@ def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option
2232
stations = (1,2,3,4)
2333

2434
# (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
25-
# (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
35+
# (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
2636
nBins = 250
2737
if slType == 2: nBins = 180
28-
histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals",nBins,0,nBins)
29-
histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals",nBins,0,nBins)
38+
histoMean = ROOT.TH1F("h_ResMeanAll","Mean of residuals for Run=%s at %s" % (run,slStr),nBins,0,nBins)
39+
histoSigma = ROOT.TH1F("h_ResSigmaAll","Sigma of residuals for Run=%s at %s" % (run,slStr),nBins,0,nBins)
3040
for st in stations:
3141
nSectors = 12
3242
if st == 4: nSectors = 14
33-
if st == 4 and slType == 2: continue
43+
if st == 4 and slType == 2: continue
3444
if verbose: print("Station",st)
3545
for wh in wheels:
36-
if verbose: print("Wheel",wh)
46+
if verbose: print("Wheel",wh)
3747
for sec in range(1,nSectors+1):
3848
if verbose: print("Sector",sec)
3949
# Get histogram
40-
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)
41-
print("Accessing",histoName)
50+
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)
51+
if verbose: print("Accessing",histoName)
4252
histo = file.Get(histoName)
4353
(histo,fitFunc) = fitResidual(histo,nSigmas,verbose)
4454
fitMean = fitFunc.GetParameter(1)
@@ -52,16 +62,16 @@ def plot(fileName,sl,dir='DQMData/Run 1/DT/Run summary/DTCalibValidation',option
5262
histoMean.SetBinError(binHistoNew,fitMeanErr)
5363
histoSigma.SetBinContent(binHistoNew,fitSigma)
5464
histoSigma.SetBinError(binHistoNew,fitSigmaErr)
55-
65+
5666
if sec == 1:
5767
label = "Wheel %d" % wh
58-
if wh == -2: label += " MB%d" % st
59-
histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
68+
if wh == -2: label += " MB%d" % st
69+
histoMean.GetXaxis().SetBinLabel(binHistoNew,label)
6070
histoSigma.GetXaxis().SetBinLabel(binHistoNew,label)
6171

62-
objectsMean = drawHisto(histoMean,title="Mean of residuals (cm)",
72+
objectsMean = drawHisto(histoMean,yaxis_title="Mean of residuals (cm)",
6373
ymin=mean_ymin,ymax=mean_ymax,option=option,draw=draw)
64-
objectsSigma = drawHisto(histoSigma,title="Sigma of residuals (cm)",
65-
ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
74+
objectsSigma = drawHisto(histoSigma,yaxis_title="Sigma of residuals (cm)",ymin=sig_ymin,ymax=sig_ymax,option=option,draw=draw)
75+
6676

6777
return (objectsMean,objectsSigma)

CalibMuon/DTCalibration/python/PlottingTools/plotResidualsCosmics.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

CalibMuon/DTCalibration/python/PlottingTools/plotVDriftFromHistos.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def binNumber(station,sector):
55
start = (station - 1)*12
66
return start + sector
77

8-
def plot(fileName,sl,option="HISTOP",draw=True):
8+
def plot(fileName,sl,run="1",option="HISTOP",draw=True):
99

1010
slType = sl
1111
slStr = "SL%d" % slType
@@ -21,14 +21,14 @@ def plot(fileName,sl,option="HISTOP",draw=True):
2121
histosWheel = {}
2222
for wh in wheels:
2323
histoName = 'Wheel%d_%s_VDrift' % (wh,slStr)
24-
print("Accessing",histoName)
24+
#print("Accessing",histoName)
2525
histosWheel[wh] = file.Get(histoName)
2626

2727
# (Wh-2 MB1 Sec1 ... Wh-2 MB1 Sec12 ... Wh-1 MB1 Sec1 ... Wh-1 MB1 Sec12 ...)
2828
# (Wh-2 MB2 Sec1 ... Wh-2 MB2 Sec12 ... Wh-1 MB2 Sec1 ... Wh-1 MB1 Sec12 ...) ...
2929
nBins = 250
3030
if slType == 2: nBins = 180
31-
histo = ROOT.TH1F("h_VDriftAll","VDrift",nBins,0,nBins)
31+
histo = ROOT.TH1F("h_VDriftAll_SL%s"%slStr,"VDrift for Run=%s at %s" % (run,slStr),nBins,0,nBins)
3232
for st in stations:
3333
nSectors = 12
3434
if st == 4: nSectors = 14
@@ -53,9 +53,9 @@ def plot(fileName,sl,option="HISTOP",draw=True):
5353
if wh == -2: label += " MB%d" % st
5454
histo.GetXaxis().SetBinLabel(binHistoNew,label)
5555

56-
objects = drawHisto(histo,
57-
title="v_{drift} (#mum/ns)",
58-
ymin=53,ymax=57,option=option,draw=draw)
56+
objects = drawHisto(histo,
57+
yaxis_title="v_{drift} (#mum/ns)",
58+
ymin=52,ymax=57,option=option,draw=draw)
5959

6060
return objects
6161

CalibMuon/DTCalibration/python/Workflow/CrabHelper.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ def check_crabtask(self):
5050
print(self.crab_config_filepath)
5151
task = self.crabFunctions.CrabTask(crab_config = self.crab_config_filepath,
5252
initUpdate = False)
53-
53+
5454
if self.options.no_exec:
5555
log.info("Nothing to check in no-exec mode")
5656
return True
5757
for n_check in range(self.options.max_checks):
5858
task.update()
5959
if task.state in ( "COMPLETED"):
60-
print("Crab task complete. Getting output locally")
61-
output_path = os.path.join( self.local_path, "unmerged_results" )
62-
self.get_output_files(task, output_path)
60+
print("Crab task is complete. You can run the next step now.")
61+
#output_path = os.path.join( self.local_path, "unmerged_results" )
62+
#self.get_output_files(task, output_path)
63+
#self.get_output_files(task)
64+
#print("Finished with get_output_files()")
6365
return True
6466
if task.state in ("SUBMITFAILED", "FAILED"):
6567
print("Crab task failed")
@@ -83,19 +85,24 @@ def check_crabtask(self):
8385
sys.stdout.write("\r")
8486
sys.stdout.write("".join([" " for i in range(tools.getTerminalSize()[0])]))
8587
sys.stdout.write("\r")
86-
prompt_text = "Check (%d/%d). Task state: %s (%s). Press q and enter to stop checks: " % (n_check,
87-
self.options.max_checks, task.state, jobinfos)
88+
prompt_text = "Check (%d/%d). Task state: %s (%s). \nPress q and enter to stop checks: " \
89+
% (n_check, self.options.max_checks, task.state, jobinfos)
8890
user_input = tools.stdinWait(prompt_text, "", self.options.check_interval)
89-
if user_input in ("q","Q"):
91+
if user_input in ["q","Q"]:
9092
return False
9193
print("Task not completed after %d checks (%d minutes)" % ( self.options.max_checks,
9294
int( self.options.check_interval / 60. )))
9395
return False
9496

9597
def voms_proxy_time_left(self):
96-
process = subprocess.Popen(['voms-proxy-info', '-timeleft'],
97-
stdout=subprocess.PIPE)
98+
log.debug("Checking voms_proxy time left")
99+
process = subprocess.Popen('voms-proxy-info -timeleft',
100+
stdout = subprocess.PIPE,
101+
stderr = subprocess.PIPE,
102+
shell=True
103+
)
98104
stdout = process.communicate()[0]
105+
99106
if process.returncode != 0:
100107
return 0
101108
else:
@@ -200,8 +207,7 @@ def fill_options_from_crab_config(self):
200207

201208
@property
202209
def crab(self):
203-
""" Retuns a CrabController instance from cache or creates new
204-
on on first call """
210+
""" Retuns a CrabController instance from cache or creates new one if it is a first call """
205211
if self._crab is None:
206212
if self.cert_info.voGroup:
207213
self._crab = self.crabFunctions.CrabController(voGroup = self.cert_info.voGroup)
@@ -212,11 +218,13 @@ def crab(self):
212218
@property
213219
def cert_info(self):
214220
if not self._cert_info:
221+
log.debug("No cert info yet. Will try to get it.")
215222
if not self.voms_proxy_time_left() > 0:
216-
warn_msg = "No valid proxy, a default proxy without a specific"
217-
warn_msg = "VOGroup will be used"
218-
self.voms_proxy_create()
223+
warn_msg = "No valid proxy, a default proxy without a specific VOGroup will be used"
219224
log.warning(warn_msg)
225+
log.debug("Trying to create voms_proxy")
226+
self.voms_proxy_create()
227+
log.debug("... voms_proxy is created")
220228
self._cert_info = self.crabFunctions.CertInfo()
221229
return self._cert_info
222230

CalibMuon/DTCalibration/python/Workflow/Crabtools/crabFunctions.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class CrabController():
3434
# @param self: A previously defined logger. Crab log messages will use this logger as their parent logger.
3535
def __init__(self, debug=0, logger = None , workingArea = None, voGroup = None, username = None):
3636

37+
#print("Initializing CrabController()")
3738
setConsoleLogLevel(LOGLEVEL_MUTE)
3839
self.debug = debug
3940
if workingArea is not None:
@@ -186,10 +187,13 @@ def status(self,name):
186187
# @param crabArgs A list of arguments for crab beginning with the command
187188
def callCrabCommand( self, crabArgs ):
188189
crabCommandProcessArgs = (self.crab_q, crabArgs)
190+
print("Will run the callCrabCommand:", crabArgs)
189191
p = Process(target=crabCommandProcess, args=(crabCommandProcessArgs))
190192
p.start()
193+
#print("The (multi)Process() started")
191194
res = self.crab_q.get()
192195
p.join()
196+
print("The Crab command Process has finished.")
193197
return res
194198

195199
## Call crab getlog
@@ -340,12 +344,13 @@ def crabCommandProcess(q,crabCommandArgs):
340344

341345
class CertInfo:
342346
def __init__( self ):
347+
# print("Running CertInfo() init")
343348
p = subprocess.Popen("voms-proxy-info --fqan",
344349
stdout = subprocess.PIPE,
345350
stderr = subprocess.PIPE,
346351
shell=True)
347352
stdout, stderr = p.communicate()
348-
print(stdout)
353+
# print("Grid Certificate:", stdout)
349354
if p.returncode != 0:
350355
self.vo = ""
351356
self.voGroup = ""
@@ -364,8 +369,7 @@ def __init__( self ):
364369
except:
365370
self.voRole = ""
366371

367-
## Class for a single CrabRequest
368-
#e
372+
369373
# This class represents one crab3 task/request
370374
class CrabTask:
371375

@@ -398,6 +402,7 @@ def __init__(self,
398402
raise IOError("File %s not found" % crab_config )
399403
self.name = crab_config
400404
self.name = self.crabConfig.General.requestName
405+
401406
self.uuid = uuid.uuid4()
402407
#~ self.lock = multiprocessing.Lock()
403408
#setup logging

CalibMuon/DTCalibration/python/Workflow/DTCalibrationWorker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def has_crab3_env(self):
3636
return True
3737

3838
def setup_crab_env(self):
39+
log.info('Setting up crab environment')
3940
# following
40-
#http://.com/questions/3503719/emulating-bash-source-in-python
41+
# http://stackoverflow.com/questions/3503719/emulating-bash-source-in-python
4142
command = ['bash', '-c', 'unset module;source /cvmfs/cms.cern.ch/crab3/crab.sh && env']
4243
proc = subprocess.Popen(command, executable = '/bin/bash', stdout = subprocess.PIPE)
4344

44-
print('setting up crab')
4545
for line in proc.stdout:
4646
(key, _, value) = line.partition(b"=")
4747
os.environ[key.decode()] = value.decode().replace("\n","")

0 commit comments

Comments
 (0)