pploner commited on
Commit
402b3b6
·
verified ·
1 Parent(s): 1fcf66a

Upload COLLIDE2V_example_notebook.ipynb

Browse files
Files changed (1) hide show
  1. COLLIDE2V_example_notebook.ipynb +477 -0
COLLIDE2V_example_notebook.ipynb ADDED
@@ -0,0 +1,477 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "432e48eb",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/afs/cern.ch/user/p/phploner/.local/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
14
+ " from .autonotebook import tqdm as notebook_tqdm\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "import awkward as ak\n",
20
+ "import pyarrow as pa\n",
21
+ "import pyarrow.parquet as pq\n",
22
+ "import os\n",
23
+ "# SPECIFY HERE A VALID CACHE DIRECTORY WITH ENOUGH STORAGE FOR THE DATASETS\n",
24
+ "os.environ[\"HF_HOME\"] = \"/eos/project/f/foundational-model-dataset/samples/philip_production/full_production_1percent/.cache/huggingface\"\n",
25
+ "from datasets import load_dataset\n"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "markdown",
30
+ "id": "2e31fb7f",
31
+ "metadata": {},
32
+ "source": [
33
+ "<small>One can download the whole dataset or parts of it using the `load_dataset` function. \n",
34
+ "Specify the process folder to be inspected using `data_dir` or specify single parquet files using the `data_files` argument.\n",
35
+ "Without these arguments the whole dataset will be accessible. \n",
36
+ "Since the dataset is huge, streaming will be necessary to access it.</small>"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 2,
42
+ "id": "a938312a",
43
+ "metadata": {},
44
+ "outputs": [],
45
+ "source": [
46
+ "# load dataset of one process folder\n",
47
+ "# if one wants to load the entire dataset, skip the data_dir or data_files argument\n",
48
+ "dataset = load_dataset(\"fastmachinelearning/collide-1m\", \n",
49
+ " data_dir=\"WJetsToLNu_13TeV-madgraphMLM-pythia8\",\n",
50
+ " streaming=True)\n",
51
+ "dataset = dataset[\"train\"]"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "markdown",
56
+ "id": "743e1cbb",
57
+ "metadata": {},
58
+ "source": [
59
+ "<small> Here are the different columns that are available in the dataset: </small>"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": 3,
65
+ "id": "14412cb7",
66
+ "metadata": {},
67
+ "outputs": [
68
+ {
69
+ "name": "stdout",
70
+ "output_type": "stream",
71
+ "text": [
72
+ "FullReco_PFCand_PT\n",
73
+ "FullReco_PFCand_Eta\n",
74
+ "FullReco_PFCand_Phi\n",
75
+ "FullReco_PFCand_PID\n",
76
+ "FullReco_PFCand_Charge\n",
77
+ "FullReco_PFCand_Mass\n",
78
+ "FullReco_PFCand_D0\n",
79
+ "FullReco_PFCand_DZ\n",
80
+ "FullReco_PFCand_ErrorD0\n",
81
+ "FullReco_PFCand_ErrorDZ\n",
82
+ "FullReco_PFCand_fUniqueID\n",
83
+ "FullReco_PFCand_PuppiW\n",
84
+ "FullReco_PUPPIPart_PT\n",
85
+ "FullReco_PUPPIPart_Eta\n",
86
+ "FullReco_PUPPIPart_Phi\n",
87
+ "FullReco_PUPPIPart_Charge\n",
88
+ "FullReco_PUPPIPart_Mass\n",
89
+ "FullReco_PUPPIPart_PID\n",
90
+ "FullReco_PUPPIPart_D0\n",
91
+ "FullReco_PUPPIPart_DZ\n",
92
+ "FullReco_PUPPIPart_ErrorD0\n",
93
+ "FullReco_PUPPIPart_ErrorDZ\n",
94
+ "FullReco_PUPPIPart_fUniqueID\n",
95
+ "FullReco_PUPPIPart_PuppiW\n",
96
+ "FullReco_Electron_PT\n",
97
+ "FullReco_Electron_Eta\n",
98
+ "FullReco_Electron_Phi\n",
99
+ "FullReco_Electron_EhadOverEem\n",
100
+ "FullReco_Electron_IsolationVarRhoCorr\n",
101
+ "FullReco_MuonTight_PT\n",
102
+ "FullReco_MuonTight_Eta\n",
103
+ "FullReco_MuonTight_Phi\n",
104
+ "FullReco_MuonTight_IsolationVarRhoCorr\n",
105
+ "FullReco_PhotonTight_PT\n",
106
+ "FullReco_PhotonTight_Eta\n",
107
+ "FullReco_PhotonTight_Phi\n",
108
+ "FullReco_JetAK4_PT\n",
109
+ "FullReco_JetAK4_Eta\n",
110
+ "FullReco_JetAK4_Phi\n",
111
+ "FullReco_JetAK4_Mass\n",
112
+ "FullReco_JetAK4_BTag\n",
113
+ "FullReco_JetAK4_BTagPhys\n",
114
+ "FullReco_JetAK4_Charge\n",
115
+ "FullReco_JetAK4_Constituents\n",
116
+ "FullReco_JetAK8_PT\n",
117
+ "FullReco_JetAK8_Eta\n",
118
+ "FullReco_JetAK8_Phi\n",
119
+ "FullReco_JetAK8_Mass\n",
120
+ "FullReco_JetAK8_BTag\n",
121
+ "FullReco_JetAK8_BTagPhys\n",
122
+ "FullReco_JetAK8_Charge\n",
123
+ "FullReco_JetPuppiAK4_PT\n",
124
+ "FullReco_JetPuppiAK4_Eta\n",
125
+ "FullReco_JetPuppiAK4_Phi\n",
126
+ "FullReco_JetPuppiAK4_Mass\n",
127
+ "FullReco_JetPuppiAK4_BTag\n",
128
+ "FullReco_JetPuppiAK4_BTagPhys\n",
129
+ "FullReco_JetPuppiAK4_Charge\n",
130
+ "FullReco_JetPuppiAK4_Constituents\n",
131
+ "FullReco_JetPuppiAK8_PT\n",
132
+ "FullReco_JetPuppiAK8_Eta\n",
133
+ "FullReco_JetPuppiAK8_Phi\n",
134
+ "FullReco_JetPuppiAK8_Mass\n",
135
+ "FullReco_JetPuppiAK8_BTag\n",
136
+ "FullReco_JetPuppiAK8_BTagPhys\n",
137
+ "FullReco_JetPuppiAK8_Charge\n",
138
+ "FullReco_MET_MET\n",
139
+ "FullReco_MET_Phi\n",
140
+ "FullReco_MET_Eta\n",
141
+ "FullReco_PUPPIMET_MET\n",
142
+ "FullReco_PUPPIMET_Phi\n",
143
+ "FullReco_PUPPIMET_Eta\n",
144
+ "FullReco_GenMissingET_MET\n",
145
+ "FullReco_GenMissingET_Eta\n",
146
+ "FullReco_GenMissingET_Phi\n",
147
+ "FullReco_GenPart_PT\n",
148
+ "FullReco_GenPart_Eta\n",
149
+ "FullReco_GenPart_Phi\n",
150
+ "FullReco_GenPart_PID\n",
151
+ "FullReco_GenPart_M1\n",
152
+ "FullReco_GenPart_M2\n",
153
+ "FullReco_GenPart_D1\n",
154
+ "FullReco_GenPart_D2\n",
155
+ "FullReco_GenPart_Status\n",
156
+ "FullReco_GenPart_IsPU\n",
157
+ "FullReco_GenJetAK4_PT\n",
158
+ "FullReco_GenJetAK4_Eta\n",
159
+ "FullReco_GenJetAK4_Phi\n",
160
+ "FullReco_GenJetAK4_Mass\n",
161
+ "FullReco_GenJetAK8_PT\n",
162
+ "FullReco_GenJetAK8_Eta\n",
163
+ "FullReco_GenJetAK8_Phi\n",
164
+ "FullReco_GenJetAK8_Mass\n",
165
+ "FullReco_PrimaryVertex_X\n",
166
+ "FullReco_PrimaryVertex_Y\n",
167
+ "FullReco_PrimaryVertex_Z\n",
168
+ "FullReco_PrimaryVertex_T\n",
169
+ "FullReco_PrimaryVertex_SumPT2\n",
170
+ "L1T_PFCand_PT\n",
171
+ "L1T_PFCand_Eta\n",
172
+ "L1T_PFCand_Phi\n",
173
+ "L1T_PFCand_PID\n",
174
+ "L1T_PFCand_Charge\n",
175
+ "L1T_PFCand_Mass\n",
176
+ "L1T_PFCand_D0\n",
177
+ "L1T_PFCand_DZ\n",
178
+ "L1T_PFCand_ErrorD0\n",
179
+ "L1T_PFCand_ErrorDZ\n",
180
+ "L1T_PFCand_fUniqueID\n",
181
+ "L1T_PFCand_PuppiW\n",
182
+ "L1T_PUPPIPart_PT\n",
183
+ "L1T_PUPPIPart_Eta\n",
184
+ "L1T_PUPPIPart_Phi\n",
185
+ "L1T_PUPPIPart_Charge\n",
186
+ "L1T_PUPPIPart_Mass\n",
187
+ "L1T_PUPPIPart_PID\n",
188
+ "L1T_PUPPIPart_D0\n",
189
+ "L1T_PUPPIPart_DZ\n",
190
+ "L1T_PUPPIPart_ErrorD0\n",
191
+ "L1T_PUPPIPart_ErrorDZ\n",
192
+ "L1T_PUPPIPart_fUniqueID\n",
193
+ "L1T_PUPPIPart_PuppiW\n",
194
+ "L1T_Electron_PT\n",
195
+ "L1T_Electron_Eta\n",
196
+ "L1T_Electron_Phi\n",
197
+ "L1T_Electron_EhadOverEem\n",
198
+ "L1T_Electron_IsolationVarRhoCorr\n",
199
+ "L1T_MuonTight_PT\n",
200
+ "L1T_MuonTight_Eta\n",
201
+ "L1T_MuonTight_Phi\n",
202
+ "L1T_MuonTight_IsolationVarRhoCorr\n",
203
+ "L1T_PhotonTight_PT\n",
204
+ "L1T_PhotonTight_Eta\n",
205
+ "L1T_PhotonTight_Phi\n",
206
+ "L1T_JetAK4_PT\n",
207
+ "L1T_JetAK4_Eta\n",
208
+ "L1T_JetAK4_Phi\n",
209
+ "L1T_JetAK4_Mass\n",
210
+ "L1T_JetAK4_BTag\n",
211
+ "L1T_JetAK4_BTagPhys\n",
212
+ "L1T_JetAK4_Charge\n",
213
+ "L1T_JetAK4_Constituents\n",
214
+ "L1T_JetAK8_PT\n",
215
+ "L1T_JetAK8_Eta\n",
216
+ "L1T_JetAK8_Phi\n",
217
+ "L1T_JetAK8_Mass\n",
218
+ "L1T_JetAK8_BTag\n",
219
+ "L1T_JetAK8_BTagPhys\n",
220
+ "L1T_JetAK8_Charge\n",
221
+ "L1T_JetPuppiAK4_PT\n",
222
+ "L1T_JetPuppiAK4_Eta\n",
223
+ "L1T_JetPuppiAK4_Phi\n",
224
+ "L1T_JetPuppiAK4_Mass\n",
225
+ "L1T_JetPuppiAK4_BTag\n",
226
+ "L1T_JetPuppiAK4_BTagPhys\n",
227
+ "L1T_JetPuppiAK4_Charge\n",
228
+ "L1T_JetPuppiAK4_Constituents\n",
229
+ "L1T_JetPuppiAK8_PT\n",
230
+ "L1T_JetPuppiAK8_Eta\n",
231
+ "L1T_JetPuppiAK8_Phi\n",
232
+ "L1T_JetPuppiAK8_Mass\n",
233
+ "L1T_JetPuppiAK8_BTag\n",
234
+ "L1T_JetPuppiAK8_BTagPhys\n",
235
+ "L1T_JetPuppiAK8_Charge\n",
236
+ "L1T_MET_MET\n",
237
+ "L1T_MET_Phi\n",
238
+ "L1T_MET_Eta\n",
239
+ "L1T_PUPPIMET_MET\n",
240
+ "L1T_PUPPIMET_Phi\n",
241
+ "L1T_PUPPIMET_Eta\n"
242
+ ]
243
+ }
244
+ ],
245
+ "source": [
246
+ "cols = list(dataset.features.keys())\n",
247
+ "for c in cols:\n",
248
+ " print(c)"
249
+ ]
250
+ },
251
+ {
252
+ "cell_type": "markdown",
253
+ "id": "3f48be1e",
254
+ "metadata": {},
255
+ "source": [
256
+ "<small> The dataset will have one row for each event, one can access the respective next row by calling `row=next(iter(dataset))`. Once a row is loaded, one can easily access the respective features using `row['feature']`, where 'feature' is any of the above listed columns. Loading multiple rows at once might lead to memory issues. </small>"
257
+ ]
258
+ },
259
+ {
260
+ "cell_type": "code",
261
+ "execution_count": 4,
262
+ "id": "adb5ae4d",
263
+ "metadata": {},
264
+ "outputs": [],
265
+ "source": [
266
+ "row1 = next(iter(dataset))"
267
+ ]
268
+ },
269
+ {
270
+ "cell_type": "code",
271
+ "execution_count": 16,
272
+ "id": "869dccac",
273
+ "metadata": {},
274
+ "outputs": [
275
+ {
276
+ "data": {
277
+ "text/html": [
278
+ "<pre>[0.291,\n",
279
+ " 0.226,\n",
280
+ " 0.454,\n",
281
+ " 0.468,\n",
282
+ " 0.412,\n",
283
+ " 0.22,\n",
284
+ " 0.755,\n",
285
+ " 0.963,\n",
286
+ " 0.484,\n",
287
+ " 0.814,\n",
288
+ " ...,\n",
289
+ " 5.42,\n",
290
+ " 0.735,\n",
291
+ " 2.6,\n",
292
+ " 1.99,\n",
293
+ " 2.98,\n",
294
+ " 2.21,\n",
295
+ " 3.04,\n",
296
+ " 1.14,\n",
297
+ " 3.48]\n",
298
+ "--------------------\n",
299
+ "backend: cpu\n",
300
+ "nbytes: 34.5 kB\n",
301
+ "type: 4318 * float64</pre>"
302
+ ],
303
+ "text/plain": [
304
+ "<Array [0.291, 0.226, 0.454, ..., 3.04, 1.14, 3.48] type='4318 * float64'>"
305
+ ]
306
+ },
307
+ "execution_count": 16,
308
+ "metadata": {},
309
+ "output_type": "execute_result"
310
+ }
311
+ ],
312
+ "source": [
313
+ "example_arr = ak.Array(row1['FullReco_PFCand_PT'])\n",
314
+ "example_arr"
315
+ ]
316
+ },
317
+ {
318
+ "cell_type": "code",
319
+ "execution_count": 17,
320
+ "id": "9efa96de",
321
+ "metadata": {},
322
+ "outputs": [
323
+ {
324
+ "data": {
325
+ "text/plain": [
326
+ "ArrayType(NumpyType('float64'), 4318, None)"
327
+ ]
328
+ },
329
+ "execution_count": 17,
330
+ "metadata": {},
331
+ "output_type": "execute_result"
332
+ }
333
+ ],
334
+ "source": [
335
+ "example_arr.type"
336
+ ]
337
+ },
338
+ {
339
+ "cell_type": "markdown",
340
+ "id": "7e6369c9",
341
+ "metadata": {},
342
+ "source": [
343
+ "<small> Once the data is saved in an array in this way, all the usual awkward array operations can be applied. </small>"
344
+ ]
345
+ },
346
+ {
347
+ "cell_type": "markdown",
348
+ "id": "29f6f3d6",
349
+ "metadata": {},
350
+ "source": [
351
+ "<small> To access a specific row, one can use the following `get_row_by_index` function. </small>"
352
+ ]
353
+ },
354
+ {
355
+ "cell_type": "code",
356
+ "execution_count": 18,
357
+ "id": "64a97872",
358
+ "metadata": {},
359
+ "outputs": [],
360
+ "source": [
361
+ "def get_row_by_index(dataset, target_index):\n",
362
+ " for i, row in enumerate(dataset):\n",
363
+ " if i == target_index:\n",
364
+ " return row\n",
365
+ " return None"
366
+ ]
367
+ },
368
+ {
369
+ "cell_type": "code",
370
+ "execution_count": 19,
371
+ "id": "0b5da1cc",
372
+ "metadata": {},
373
+ "outputs": [],
374
+ "source": [
375
+ "row100 = get_row_by_index(dataset, 100)"
376
+ ]
377
+ },
378
+ {
379
+ "cell_type": "code",
380
+ "execution_count": 22,
381
+ "id": "30afc6bc",
382
+ "metadata": {},
383
+ "outputs": [
384
+ {
385
+ "data": {
386
+ "text/html": [
387
+ "<pre>[1.47,\n",
388
+ " 1.01,\n",
389
+ " 1.14,\n",
390
+ " 0.894,\n",
391
+ " 0.905,\n",
392
+ " 0.647,\n",
393
+ " 1.15,\n",
394
+ " 0.616,\n",
395
+ " 0.736,\n",
396
+ " 0.521,\n",
397
+ " ...,\n",
398
+ " 1.26,\n",
399
+ " 2.95,\n",
400
+ " 6.43,\n",
401
+ " 1.82,\n",
402
+ " 1.76,\n",
403
+ " 2.72,\n",
404
+ " 2.86,\n",
405
+ " 1.29,\n",
406
+ " 0.773]\n",
407
+ "--------------------\n",
408
+ "backend: cpu\n",
409
+ "nbytes: 29.7 kB\n",
410
+ "type: 3709 * float64</pre>"
411
+ ],
412
+ "text/plain": [
413
+ "<Array [1.47, 1.01, 1.14, 0.894, ..., 2.86, 1.29, 0.773] type='3709 * float64'>"
414
+ ]
415
+ },
416
+ "execution_count": 22,
417
+ "metadata": {},
418
+ "output_type": "execute_result"
419
+ }
420
+ ],
421
+ "source": [
422
+ "example_arr100 = ak.Array(row100['FullReco_PFCand_PT'])\n",
423
+ "example_arr100"
424
+ ]
425
+ },
426
+ {
427
+ "cell_type": "code",
428
+ "execution_count": 23,
429
+ "id": "8ffdc8ed",
430
+ "metadata": {},
431
+ "outputs": [
432
+ {
433
+ "data": {
434
+ "text/plain": [
435
+ "ArrayType(NumpyType('float64'), 3709, None)"
436
+ ]
437
+ },
438
+ "execution_count": 23,
439
+ "metadata": {},
440
+ "output_type": "execute_result"
441
+ }
442
+ ],
443
+ "source": [
444
+ "example_arr100.type"
445
+ ]
446
+ },
447
+ {
448
+ "cell_type": "markdown",
449
+ "id": "b7002061",
450
+ "metadata": {},
451
+ "source": [
452
+ "<small> We hope you enjoy looking through this preliminary dataset and aim to have the full dataset uploaded soon. If you have any questions or suggestions please let us know at [email protected] or [email protected] .</small>"
453
+ ]
454
+ }
455
+ ],
456
+ "metadata": {
457
+ "kernelspec": {
458
+ "display_name": "Python 3",
459
+ "language": "python",
460
+ "name": "python3"
461
+ },
462
+ "language_info": {
463
+ "codemirror_mode": {
464
+ "name": "ipython",
465
+ "version": 3
466
+ },
467
+ "file_extension": ".py",
468
+ "mimetype": "text/x-python",
469
+ "name": "python",
470
+ "nbconvert_exporter": "python",
471
+ "pygments_lexer": "ipython3",
472
+ "version": "3.9.21"
473
+ }
474
+ },
475
+ "nbformat": 4,
476
+ "nbformat_minor": 5
477
+ }