-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmerge_outputs.sh
executable file
·248 lines (229 loc) · 14.2 KB
/
merge_outputs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
NTUPLETAG=$1
CHANNEL=$2
ERA=$3
if [[ -z "$4" ]]; then
STEP="all"
else
STEP=$4 # filelist, hadd, all
fi
case ${CHANNEL} in
"electron")
scope=ee
sample="Electron"
;;
"muon")
scope=mm
sample="Muon"
;;
*)
echo "[ERROR] Given channel ${CHANNEL} not implemented"
exit 42
;;
esac
basedir=/store/user/${USER}/CROWN/ntuples/${NTUPLETAG}/CROWNRun/${ERA}/
gridpath=root://cmsxrootd-kit-disk.gridka.de:1094/
output_dir=/ceph/${USER}/HiggsToTauTau/scalefactors/${NTUPLETAG}/${ERA}UL
[[ ! -d ${output_dir} ]] && mkdir -p ${output_dir}
if [[ ${STEP} == "all" || ${STEP} == "filelist" ]]; then
# Write out the merge commands for all sample types
if [[ ${ERA} == "2018" ]]; then
# MC
[[ -f merge_DYJetsToLL_files_${ERA}_${scope}.log ]] && rm merge_DYJetsToLL_files_${ERA}_${scope}.log
for ext in "" _ext1; do
xrdfs ${gridpath} ls ${basedir}/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8_RunIISummer20UL${ERA: -2}NanoAODv9-106X${ext}/${scope}/
done >>merge_DYJetsToLL_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_DYJetsToLL_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_DYJetsToLL_files_${ERA}_${scope}.log
# Data
echo "[INFO] Gathering data file list..."
[[ -f merge_Single${sample}_files_${ERA}_${scope}.log ]] && rm merge_Single${sample}_files_${ERA}_${scope}.log
for period in {A..D}; do
xrdfs ${gridpath} ls ${basedir}/Single${sample}_Run${ERA}${period}-UL${ERA}/${scope}/
done >>merge_Single${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Single${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Single${sample}_files_${ERA}_${scope}.log
if [[ ${CHANNEL} == "muon" ]]; then
[[ -f merge_Double${sample}_files_${ERA}_${scope}.log ]] && rm merge_Double${sample}_files_${ERA}_${scope}.log
for period in {A..D}; do
xrdfs ${gridpath} ls ${basedir}/Double${sample}_Run${ERA}${period}-UL${ERA}/${scope}/
done >>merge_Double${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Double${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Double${sample}_files_${ERA}_${scope}.log
fi
# Embedding
echo "[INFO] Gathering embedding file list..."
[[ -f merge_${sample}Embedding_files_${ERA}_${scope}.log ]] && rm merge_${sample}Embedding_files_${ERA}_${scope}.log
for period in {A..D}; do
xrdfs ${gridpath} ls ${basedir}/${sample}Embedding_Run${ERA}${period}-UL${ERA}/${scope}/
done >>merge_${sample}Embedding_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_${sample}Embedding_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_${sample}Embedding_files_${ERA}_${scope}.log
elif [[ ${ERA} == "2017" ]]; then
# MC
[[ -f merge_DYJetsToLL_files_${ERA}_${scope}.log ]] && rm merge_DYJetsToLL_files_${ERA}_${scope}.log
for ext in "" _ext1; do
xrdfs ${gridpath} ls ${basedir}/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8_RunIISummer20UL${ERA: -2}NanoAODv9-106X${ext}/${scope}/
done >>merge_DYJetsToLL_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_DYJetsToLL_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_DYJetsToLL_files_${ERA}_${scope}.log
# Data
echo "[INFO] Gathering data file list..."
[[ -f merge_Single${sample}_files_${ERA}_${scope}.log ]] && rm merge_Single${sample}_files_${ERA}_${scope}.log
for period in {B..F}; do
xrdfs ${gridpath} ls ${basedir}/Single${sample}_Run${ERA}${period}-UL${ERA}/${scope}/
done >>merge_Single${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Single${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Single${sample}_files_${ERA}_${scope}.log
if [[ ${CHANNEL} == "muon" ]]; then
[[ -f merge_Double${sample}_files_${ERA}_${scope}.log ]] && rm merge_Double${sample}_files_${ERA}_${scope}.log
for period in {B..F}; do
xrdfs ${gridpath} ls ${basedir}/Double${sample}_Run${ERA}${period}-UL${ERA}/${scope}/
done >>merge_Double${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Double${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Double${sample}_files_${ERA}_${scope}.log
fi
# Embedding
echo "[INFO] Gathering embedding file list..."
[[ -f merge_${sample}Embedding_files_${ERA}_${scope}.log ]] && rm merge_${sample}Embedding_files_${ERA}_${scope}.log
for period in {B..F}; do
xrdfs ${gridpath} ls ${basedir}/${sample}Embedding_Run${ERA}${period}-UL${ERA}/${scope}/
done >>merge_${sample}Embedding_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_${sample}Embedding_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_${sample}Embedding_files_${ERA}_${scope}.log
elif [[ ${ERA} == "2016postVFP" ]]; then
echo "[INFO] Gathering file list for ${ERA}..."
ERA_SAMPLENAME="2016"
# MC
[[ -f merge_DYJetsToLL_files_${ERA}_${scope}.log ]] && rm merge_DYJetsToLL_files_${ERA}_${scope}.log
for ext in "" _ext1; do
xrdfs ${gridpath} ls ${basedir}/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8_RunIISummer20UL${ERA_SAMPLENAME: -2}NanoAODv9-106X${ext}/${scope}/
done >>merge_DYJetsToLL_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_DYJetsToLL_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_DYJetsToLL_files_${ERA}_${scope}.log
# Data
echo "[INFO] Gathering data file list..."
[[ -f merge_Single${sample}_files_${ERA}_${scope}.log ]] && rm merge_Single${sample}_files_${ERA}_${scope}.log
for period in {F..H}; do
xrdfs ${gridpath} ls ${basedir}/Single${sample}_Run${ERA_SAMPLENAME}${period}-UL${ERA_SAMPLENAME}/${scope}/
done >>merge_Single${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Single${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Single${sample}_files_${ERA}_${scope}.log
if [[ ${CHANNEL} == "muon" ]]; then
[[ -f merge_Double${sample}_files_${ERA}_${scope}.log ]] && rm merge_Double${sample}_files_${ERA}_${scope}.log
for period in {F..H}; do
xrdfs ${gridpath} ls ${basedir}/Double${sample}_Run${ERA_SAMPLENAME}${period}-UL_DZ/${scope}/
done >>merge_Double${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Double${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Double${sample}_files_${ERA}_${scope}.log
# ---
[[ -f merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log ]] && rm merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
for period in {F..H}; do
xrdfs ${gridpath} ls ${basedir}/Double${sample}_Run${ERA_SAMPLENAME}${period}-UL${ERA_SAMPLENAME}/${scope}/
done >>merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
fi
# Embedding
echo "[INFO] Gathering embedding file list..."
[[ -f merge_${sample}Embedding_files_${ERA}_${scope}.log ]] && rm merge_${sample}Embedding_files_${ERA}_${scope}.log
for period in {F..H}; do
xrdfs ${gridpath} ls ${basedir}/${sample}Embedding_Run${ERA_SAMPLENAME}${period}-UL${ERA_SAMPLENAME}/${scope}/
done >>merge_${sample}Embedding_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_${sample}Embedding_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_${sample}Embedding_files_${ERA}_${scope}.log
elif [[ ${ERA} == "2016preVFP" ]]; then
echo "[INFO] Gathering file list for ${ERA}..."
ERA_SAMPLENAME="2016"
declare -a data_period=("B-ver1" "B-ver2" "C-HIPM" "D-HIPM" "E-HIPM" "F-HIPM")
declare -a emb_period=("B_ver1" "B_ver2" "C" "D" "E" "F")
# MC
[[ -f merge_DYJetsToLL_files_${ERA}_${scope}.log ]] && rm merge_DYJetsToLL_files_${ERA}_${scope}.log
xrdfs ${gridpath} ls ${basedir}/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8_RunIISummer20UL16NanoAODAPVv9-106X/${scope}/ >> merge_DYJetsToLL_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_DYJetsToLL_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_DYJetsToLL_files_${ERA}_${scope}.log
# Data
echo "[INFO] Gathering data file list..."
[[ -f merge_Single${sample}_files_${ERA}_${scope}.log ]] && rm merge_Single${sample}_files_${ERA}_${scope}.log
for period in ${data_period[@]}; do
xrdfs ${gridpath} ls ${basedir}/Single${sample}_Run${ERA_SAMPLENAME}${period}/${scope}/
done >>merge_Single${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Single${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Single${sample}_files_${ERA}_${scope}.log
if [[ ${CHANNEL} == "muon" ]]; then
[[ -f merge_Double${sample}_files_${ERA}_${scope}.log ]] && rm merge_Double${sample}_files_${ERA}_${scope}.log
declare -a data_period_with_dz=("B-ver1-HIPM-UL_DZ" "B-ver2-HIPM-UL_DZ" "C-HIPM-UL_DZ" "D-HIPM-UL_DZ" "E-HIPM-UL_DZ" "F-HIPM-UL_DZ")
for period in ${data_period_with_dz[@]}; do
xrdfs ${gridpath} ls ${basedir}/Double${sample}_Run${ERA_SAMPLENAME}${period}/${scope}/
done >>merge_Double${sample}_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Double${sample}_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Double${sample}_files_${ERA}_${scope}.log
# ---
[[ -f merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log ]] && rm merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
for period in ${data_period[@]}; do
xrdfs ${gridpath} ls ${basedir}/Double${sample}_Run${ERA_SAMPLENAME}${period}/${scope}/
done >>merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
# remove lines containing .json files
sed -i '/\.json/d' merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log
fi
# Embedding
echo "[INFO] Gathering embedding file list..."
[[ -f merge_${sample}Embedding_files_${ERA}_${scope}.log ]] && rm merge_${sample}Embedding_files_${ERA}_${scope}.log
for period in ${emb_period[@]}; do
xrdfs ${gridpath} ls ${basedir}/${sample}Embedding_Run${ERA_SAMPLENAME}-HIPM_${period}-UL${ERA_SAMPLENAME}/${scope}/
done >>merge_${sample}Embedding_files_${ERA}_${scope}.log
# Modify the written file by appending the redirector to get the full path
sed -i "s#^#${gridpath}#" merge_${sample}Embedding_files_${ERA}_${scope}.log
# remove lines containing .json files
sed -i '/\.json/d' merge_${sample}Embedding_files_${ERA}_${scope}.log
else
echo "[ERROR] Era ${ERA} Not implemented yet..."
exit 42
fi
fi
if [[ ${STEP} == "all" || ${STEP} == "hadd" ]]; then
hadd -f ${output_dir}/DYJetsToLL_${ERA}UL_${scope}.root $(cat merge_DYJetsToLL_files_${ERA}_${scope}.log | tr '\n' ' ') &
hadd -f ${output_dir}/Single${sample}_${ERA}UL.root $(cat merge_Single${sample}_files_${ERA}_${scope}.log | tr '\n' ' ') &
if [[ ${CHANNEL} == "muon" ]]; then
hadd -f ${output_dir}/Double${sample}_${ERA}UL.root $(cat merge_Double${sample}_files_${ERA}_${scope}.log | tr '\n' ' ') &
if [[ ${ERA} == "2016preVFP" ]] || [[ ${ERA} == "2016postVFP" ]]; then
hadd -f ${output_dir}/Double${sample}_${ERA}UL_wo_DZ.root $(cat merge_Double${sample}_files_${ERA}_${scope}_wo_DZ.log | tr '\n' ' ') &
fi
fi
hadd -f ${output_dir}/${sample}Embedding_${ERA}UL.root $(cat merge_${sample}Embedding_files_${ERA}_${scope}.log | tr '\n' ' ') &
wait
fi