Skip to content

Commit b2d66a5

Browse files
katilptiborsimko
authored andcommitted
cms-YYYY-luminosity: update scripts for HI type data taking
1 parent 8d91232 commit b2d66a5

File tree

4 files changed

+142
-55
lines changed

4 files changed

+142
-55
lines changed

.github/workflows/cms-luminosity-tables.yaml

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ name: Build listings and records
22
on:
33
workflow_dispatch
44
env:
5+
RECID: 1058
56
YEAR: 2015
6-
ERAS: Run2015D
7+
ERAS: Run2015E
8+
TYPE: pphiref
9+
# Inputs:
10+
# - 2013 pPb: 1056 2013 HIRun2013 pPb
11+
# - 2013 ppref: 1057 2013 Run2013A pphiref
12+
# - 2015 ppref: 1058 2015 Run2015E pphiref
13+
# - 2015 pp: 1055 2015 Run2015D pp (not used to build the current record, but tested to produce the same files)
14+
# - 2016 pp: 1059 2016 Run2016G Run2016H pp
715
defaults:
816
run:
917
working-directory: cms-YYYY-luminosity
@@ -12,27 +20,35 @@ jobs:
1220
runs-on: ubuntu-latest
1321
name: create lumi tables
1422
steps:
15-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v3
1624
- name: Prepare
1725
run: |
1826
mkdir outputs
1927
echo ls `ls`
2028
echo pwd `pwd`
29+
RECID=${{env.RECID}}
30+
YEAR=${{env.YEAR}}
31+
TYPE=${{env.TYPE}}
2132
# Get the part of the normtag file corresponding to validated runs (muons cert file as it has a wider range)
2233
- name: Normtag file
2334
run: |
24-
echo "Get the normtag file for $YEAR"
25-
curl http://api-server-cms-release-info.app.cern.ch/years/val_json?year=$YEAR > myjs.json
26-
muonurl=$(jq -r '.[0][1].url' myjs.json)
27-
wget $muonurl -O cert.txt
28-
wget https://raw.githubusercontent.com/CMS-LUMI-POG/Normtags/master/normtag_PHYSICS.json -O normtag_PHYSICS.json
29-
source normtag.sh > outputs/normtag_PHYSICS_$YEAR.json
30-
cp outputs/normtag_PHYSICS_$YEAR.json normtag_PHYSICS.json
35+
if (( $YEAR > 2013 ))
36+
then
37+
echo "Get the normtag file for $TYPE of $YEAR"
38+
curl 'http://api-server-cms-release-info.app.cern.ch/years/val_json?year='"$YEAR"'&type='"$TYPE"'' > myjs.json
39+
ls -l myjs.json
40+
muonurl=$(jq -r '.[0][1].url' myjs.json)
41+
echo $muonurl
42+
wget $muonurl -O cert.txt
43+
wget https://raw.githubusercontent.com/CMS-LUMI-POG/Normtags/master/normtag_PHYSICS.json -O normtag_PHYSICS.json
44+
source normtag.sh > outputs/normtag_PHYSICS_$TYPE'_'$YEAR.json
45+
cp outputs/normtag_PHYSICS_$TYPE'_'$YEAR.json normtag_PHYSICS.json
46+
fi
3147
# Get the parameters for lumi listings
3248
- name: Get validated runs file
3349
run: |
34-
echo "Get validated runs for $YEAR"
35-
curl http://api-server-cms-release-info.app.cern.ch/years/val_json?year=$YEAR > myjs.json
50+
echo "Get validated runs for $TYPE of $YEAR"
51+
curl 'http://api-server-cms-release-info.app.cern.ch/years/val_json?year='"$YEAR"'&type='"$TYPE"'' > myjs.json
3652
url=$(jq -r '.[0][0].url' myjs.json)
3753
wget $url -O cert.txt
3854
# run the container with the script in the repository
@@ -41,36 +57,40 @@ jobs:
4157
run: |
4258
# Summary txt table per year
4359
echo "Create summary table for $YEAR"
44-
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt tab summ > outputs/$YEAR'lumi.txt'
60+
# Use normtag file for Run-2 values
61+
# and hfoc (the only available option) for Run-1 HI and pp ref
62+
if (( $YEAR > 2014 )); then option="normtag"; else option="hfoc"; fi;
63+
echo "From workflow, type is $TYPE, value of option is $option"
64+
[ $TYPE == "pp" ] && docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt tab $option summ > outputs/$YEAR'lumi.txt'
4565
# Prescale listing for each run in a single csv file
4666
echo "Get prescale listing for all run numbers"
47-
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt csv summ | grep -v "#" | awk '{ print $1 }' FS=':' > run_numbers.txt
48-
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/prescale.sh > outputs/'prescale'$YEAR'.csv'
67+
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt csv $option summ | grep -v "#" | grep "/" | awk '{ print $1 }' FS=':' > run_numbers.txt
68+
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/prescale.sh > outputs/'prescale_'$TYPE$YEAR'.csv'
4969
# Summary txt table per era, for all listed eras
70+
ERAS=${{env.ERAS}}
5071
echo "Create summary tables for $ERAS"
5172
for era in ${ERAS[*]}
5273
do
5374
echo "doing " $era
54-
curl http://api-server-cms-release-info.app.cern.ch/runeras?run_era=$era > myjs.json
75+
curl 'http://api-server-cms-release-info.app.cern.ch/runeras?run_era='"$era"'' > myjs.json
5576
runmin=$(cat myjs.json | jq -r '.[0].run_min')
5677
runmax=$(cat myjs.json | jq -r '.[0].run_max')
57-
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt tab summ $runmin $runmax > outputs/$era'lumi.txt'
78+
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt tab $option summ $runmin $runmax > outputs/$era'lumi.txt'
5879
done
5980
# Detailed csv per year
6081
echo "Create full csv for $YEAR"
61-
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt csv byls > outputs/$YEAR'lumibyls.csv'
82+
docker run -v $(pwd):/mnt/vol -w /home/brilws gitlab-registry.cern.ch/cms-cloud/brilws-docker /bin/bash /mnt/vol/commands.sh cert.txt csv $option byls > outputs/$TYPE'_'$YEAR'lumibyls.csv'
6283
echo ls -l outputs `ls -l outputs`
6384
echo pwd `pwd`
6485
# Build the luminosity record
6586
- name: Build the luminosity records
6687
id: record
6788
run: |
68-
python code/lumi_records.py > outputs/lumi_records.json
89+
python code/lumi_records.py $RECID $YEAR ${ERAS[0]} $TYPE > outputs/lumi_records.json
6990
#python code/vali_records.py > outputs/vali_records.json
7091
# upload output file NB bug: https://github.com/actions/upload-artifact/issues/294
7192
- name: Upload artifact
72-
uses: actions/upload-artifact@v2
93+
uses: actions/upload-artifact@v3
7394
with:
7495
name: output
75-
path: cms-YYYY-luminosity/outputs/
76-
96+
path: cms-YYYY-luminosity/outputs/

cms-YYYY-luminosity/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ This directory contains helper scripts to prepare CMS luminosity information rec
44

55
- subdirectory `code` contains the script to prepare the luminosity information record
66
- shell scripts `commands.sh` and `prescale.sh` are used in workflow `cms-luminosity-tables.yaml` in `.github/workflows` to build the luminosity information tables to be attached in the luminosity record
7-
- subdirectory `inputs` contains the "normtag" file needed for the luminosity calculation.
7+
- subdirectory `inputs` contains the "normtag" file needed for the luminosity calculation.
8+
9+
The inputs are given as GitHub workflow variables and are
10+
11+
- 2013 pPb: 1056 2013 HIRun2013 pPb
12+
- 2013 ppref: 1057 2013 Run2013A pphiref
13+
- 2015 ppref: 1058 2015 Run2015E pphiref
14+
- 2015 pp: 1055 2015 Run2015D pp (not used to build the current record, but tested to produce the same files)
15+
- 2016 pp: 1059 2016 Run2016G Run2016H pp

cms-YYYY-luminosity/code/lumi_records.py

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,76 @@
99

1010
"""
1111
Create a luminosity record.
12-
"""
13-
14-
RECID_START = 1055
15-
YEAR_RELEASED = 2015
16-
12+
Input arguments
13+
- recid (May 2023, the last used recid was 1055 for 2015 pp)
14+
- year to be released
15+
- run era (for pp, give one of the released eras, it is needed to get the collision energy, stored per era)
16+
- type (pp, pPb, pphiref, PbPb)
17+
18+
Inputs:
19+
- 2013 pPb: 1056 2013 HIRun2013 pPb
20+
- 2013 ppref: 1057 2013 Run2013A pphiref
21+
- 2015 ppref: 1058 2015 Run2015E pphiref
22+
- 2015 pp: 1055 2015 Run2015D pp (not used to build the current record, but tested to produce the same files)
1723
24+
"""
1825

19-
def create_record(recid, year, uncertainty, lumi_ref, val_recid):
26+
def create_record(recid, year, era, runtype, uncertainty, lumi_ref, val_recid):
2027
"""Create record for the given year."""
2128

2229
rec = {}
2330

24-
year = str(year)
2531
year_created = year
2632
year_published = datetime.date.today().strftime("%Y")
33+
runtype = str(runtype)
34+
if "pphiref" in runtype :
35+
display_runtype = 'pp'
36+
else:
37+
display_runtype = runtype
38+
39+
# Get the energy
40+
# Using the run_era, for pp it is needed only here
41+
# Could be done differently but this is good enough
42+
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/?run_era='+era
43+
this_json=json.loads(requests.get(url).text.strip())
44+
energy=this_json[0]["energy"]
45+
2746
# NB the reference needs to be to cds for this to work:
2847
url = lumi_ref+'/?of=tm&ot=245__a'
2948
lumi_ref_title = requests.get(url).text.strip()
3049

50+
pp_text=''
51+
if "pphiref" in runtype:
52+
collision_text = energy+' proton-proton collision data, needed as reference data for heavy-ion data analysis,'
53+
elif "PbPb" in runtype:
54+
collision_text = energy+' PbPb heavy-ion collision data'
55+
elif "pPb" in runtype:
56+
collision_text = energy+' proton-Pb heavy-ion collision data'
57+
elif "pp" in runtype:
58+
collision_text = energy+' proton-proton collision data'
59+
run_range_input = year
60+
pp_text='(The integrated luminosity for validated runs and luminosity sections of all '+year+' p-p data taking is available in '+year+'lumi.txt.)'
61+
else:
62+
print('Runtype unknown!')
63+
64+
# normtag file only after Run-1
65+
normtag_text=''
66+
if int(year) > 2014:
67+
normtag_text='The luminometer giving the best value for each luminosity section is recorded in a <strong>normtag</strong> file <a href=\"/record/'+str(recid)+'/files/normtag_PHYSICS_'+runtype+'_'+year+'.json\">normtag_PHYSICS_'+runtype+'_'+year+'.json</a> that is used in the luminosity calculation.'
68+
3169
rec["abstract"] = {}
3270

33-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&released=yes'
71+
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys&released=yes'
3472
od_runs = json.loads(requests.get(url).text.strip())
3573

74+
# The use of variable in string with two different notations could be fixed in the following...
75+
# NB in the +var+ notation, var needs to be a string
3676
rec["abstract"]["description"] = (
37-
"<p>CMS measures the luminosity using different luminometers (luminosity detectors) and algorithms. The luminometer giving the best value for each luminosity section is recorded in a 'normtag' file <a href=\"/record/%s/files/normtag_PHYSICS_%s.json\">normtag_PHYSICS_%s.json</a> that is used in the luminosity calculation.</p>" % (recid, year, year)
38-
+ "<p>The integrated luminosity for validated runs and luminosity sections of the %s public data (%s) is available in %slumi.txt. (The integrated luminosity for validated runs and luminosity sections of all %s p-p data taking is available in %slumi.txt.)</p>" % (year, ",".join(od_runs), ",".join(od_runs), year, year)
39-
+ "<p> For luminosity calculation, a detailed list of luminosity by lumi section is provided in <a href=\"/record/%s/files/%slumibyls.csv\">%slumibyls.csv</a> for the <a href=\"/record/%s\">list of validated runs</a> and lumi sections.</p>" % (recid, year, year, val_recid)
77+
"<p>CMS measures the luminosity using different luminometers (luminosity detectors) and algorithms. "+normtag_text+"</p>"
78+
"<p>The integrated luminosity for validated runs and luminosity sections of the %s taken in %s (%s) is available in %slumi.txt. %s</p>" % (collision_text, year, ",".join(od_runs), ",".join(od_runs), pp_text)
79+
+ "<p> For luminosity calculation, a detailed list of luminosity by lumi section is provided in <a href=\"/record/%s/files/%s_%slumibyls.csv\">%s_%slumibyls.csv</a> for the <a href=\"/record/%s\">list of validated runs</a> and lumi sections.</p>" % (recid, runtype, year, runtype, year, val_recid)
4080
+ "<p>The uncertainty in the luminosity measurement of %s data should be considered as %s%% (reference <a href=\"%s\">%s</a>).</p>" % (year, uncertainty, lumi_ref, lumi_ref_title)
41-
+ "<p>In your estimate for the integrated luminosity, check for which runs the trigger you have selected is active and sum the values for those runs. If you are using prescaled triggers, you can find the trigger prescale factors as shown in <a href=\"/record/5004\">the trigger examples</a>. The change of prescales (run, lumi section, index of prescales) is recorded in <a href=\"/record/%s/files/prescale%s.csv\">prescale%s.csv</a></p>" % (recid, year, year)
81+
+ "<p>In your estimate for the integrated luminosity, check for which runs the trigger you have selected is active and sum the values for those runs. For prescaled triggers, the change of prescales (run, lumi section, index of prescales referring to the PrescaleService module in the High-Level Trigger configuration files) is recorded in <a href=\"/record/%s/files/prescale_%s%s.csv\">prescale_%s%s.csv</a>.</p>" % (recid, runtype, year, runtype, year)
4282
+ "<p>Additional information on how to extract luminosity values using the <strong>brilcalc tool</strong> can be found in the <a href=\"/docs/cms-guide-luminosity-calculation\"> luminosity calculation guide</a>.</p>"
4383
)
4484

@@ -52,8 +92,8 @@ def create_record(recid, year, uncertainty, lumi_ref, val_recid):
5292
]
5393

5494
rec["collision_information"] = {}
55-
rec["collision_information"]["energy"] = "13TeV"
56-
rec["collision_information"]["type"] = "pp"
95+
rec["collision_information"]["energy"] = energy
96+
rec["collision_information"]["type"] = display_runtype
5797

5898
rec["date_created"] = [
5999
year_created,
@@ -85,13 +125,12 @@ def create_record(recid, year, uncertainty, lumi_ref, val_recid):
85125
}
86126
]
87127

88-
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type=pp-phys'
128+
url = 'http://api-server-cms-release-info.app.cern.ch/runeras/run_era?year='+year+'&type='+runtype+'-phys'
89129
#rec["run_period"] = read_run_periods(year, 'pp-phys')
90130
rec["run_period"] = json.loads(requests.get(url).text.strip())
91131

92132
rec["title"] = (
93-
"CMS luminosity information, for %s CMS open data"
94-
% year
133+
"CMS luminosity information for "+collision_text+" taken in "+year
95134
)
96135

97136
rec["type"] = {}
@@ -107,8 +146,10 @@ def main():
107146
"Do the job."
108147

109148
records = []
110-
recid = RECID_START
111-
year = str(YEAR_RELEASED)
149+
recid = sys.argv[1]
150+
year = sys.argv[2]
151+
era = sys.argv[3]
152+
runtype = sys.argv[4]
112153

113154
# this would read from the local json file
114155
# with open('./inputs/cms_release_info.json') as f:
@@ -118,14 +159,16 @@ def main():
118159
# all_years = json.loads(data)
119160
# this_year = all_years[year]
120161

121-
# this gets json from the api server
122-
url = 'http://api-server-cms-release-info.app.cern.ch/years?year='+year+'&output=plain'
123-
this_year = json.loads(requests.get(url).text.strip())
162+
# this gets json from the api server
163+
url = 'http://api-server-cms-release-info.app.cern.ch/years?year='+year+'&type='+runtype+'&output=plain'
164+
this_year = json.loads(requests.get(url).text.strip())
124165

125166
records.append(
126167
create_record(
127168
recid,
128-
this_year["year"],
169+
year,
170+
era,
171+
runtype,
129172
this_year["lumi_uncertainty"],
130173
this_year["luminosity_reference"],
131174
this_year["val_json"][0]["recid"]) # This requires the json files to be in a specific order, with "golden" first

cms-YYYY-luminosity/commands.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,40 @@
22
# parameters:
33
# $1 certified run json
44
# $2 output style csv or tab
5-
# $3 summary or byls (if not byls, no option taken)
6-
# $4 run range first
7-
# $5 run range last
5+
# $3 use normtag file or pxl
6+
# $4 summary or byls (if not byls, no option taken)
7+
# $5 run range first
8+
# $6 run range last
89
# exit on error
910
set -e
1011

1112
cert=$1
1213
style=$2
13-
if [ "$3" == "byls" ]; then mode="--"$3; fi;
1414

15-
if [ -z "$4" ]
15+
#echo "# cert file:"
16+
#cat /mnt/vol/$cert
17+
if [ "$3" == "normtag" ]
18+
then
19+
option="--normtag /mnt/vol/normtag_PHYSICS.json"
20+
#echo "# normtag file:"
21+
#cat /mnt/vol/normtag_PHYSICS.json
22+
else
23+
option="--type $3"
24+
fi
25+
#echo "#from commands: value of options is $option, value of input is $3"
26+
27+
if [ "$4" == "byls" ]; then mode="--"$4; fi;
28+
29+
if [ -z "$5" ]
1630
then
17-
brilcalc lumi -c web $mode -i /mnt/vol/$cert -u /fb --normtag /mnt/vol/normtag_PHYSICS.json --output-style $style
18-
elif [ -z "$5" ]
31+
echo "#Brilcalc command: brilcalc lumi -c web $mode -i /mnt/vol/$cert -u /fb $option --output-style $style"
32+
brilcalc lumi -c web $mode -i /mnt/vol/$cert -u /fb $option --output-style $style
33+
elif [ -z "$6" ]
1934
then
2035
echo "Give maximum range"
2136
else
22-
runmin=$4
23-
runmax=$5
24-
brilcalc lumi -c web $mode --begin $runmin --end $runmax -i /mnt/vol/$cert -u /fb --normtag /mnt/vol/normtag_PHYSICS.json --output-style $style
37+
runmin=$5
38+
runmax=$6
39+
echo "#Brilcalc command: brilcalc lumi -c web $mode --begin $runmin --end $runmax -i /mnt/vol/$cert -u /fb $option --output-style $style"
40+
brilcalc lumi -c web $mode --begin $runmin --end $runmax -i /mnt/vol/$cert -u /fb $option --output-style $style
2541
fi

0 commit comments

Comments
 (0)