|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 1, |
| 5 | + "execution_count": 2, |
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
|
57 | 57 | } |
58 | 58 | ], |
59 | 59 | "source": [ |
60 | | - "N = 10000\n", |
61 | | - "df = pd.read_csv('data_000637.txt', nrows = N)\n", |
62 | | - "print(df.head())\n", |
63 | | - "#df.describe() mi da anche info tipo media, st dev etc" |
| 60 | + "df = pd.read_csv('data_000637.txt')\n", |
| 61 | + "print(df.head())" |
64 | 62 | ] |
65 | 63 | }, |
66 | 64 | { |
|
84 | 82 | } |
85 | 83 | ], |
86 | 84 | "source": [ |
87 | | - "max_bx_counter = df['BX_COUNTER'].max() #prendo df e cerco il max nella colonna \"BX_COUNTER\".\n", |
88 | | - "num_bx_in_orbit = max_bx_counter + 1 #il max sarà max + 1\n", |
89 | | - "print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}') #l'f all'inizio mi fa stampare una stringa" |
| 85 | + "num_bx_in_orbit = df['BX_COUNTER'].max() + 1 \n", |
| 86 | + "print(f'The number of BX in an ORBIT is: {num_bx_in_orbit}') " |
90 | 87 | ] |
91 | 88 | }, |
92 | 89 | { |
|
110 | 107 | } |
111 | 108 | ], |
112 | 109 | "source": [ |
113 | | - "df_full = pd.read_csv('data_000637.txt')\n", |
114 | | - "max_orbit = df_full['ORBIT_CNT'].max() #valore max dell'orbit_cnt\n", |
115 | | - "min_orbit = df_full['ORBIT_CNT'].min() #valore min\n", |
116 | | - "duration_orbits = max_orbit - min_orbit + 1 #durata in orbits\n", |
117 | | - "duration_bx = duration_orbits * num_bx_in_orbit #calcolo la durata in bx\n", |
118 | | - "duration_ns = duration_bx * 25 #converto in ns dato che un bx sono 25 nanosecondi\n", |
| 110 | + "max_orbit = df['ORBIT_CNT'].max() \n", |
| 111 | + "min_orbit = df['ORBIT_CNT'].min() \n", |
| 112 | + "duration_orbits = max_orbit - min_orbit + 1 \n", |
| 113 | + "duration_bx = duration_orbits * num_bx_in_orbit \n", |
| 114 | + "duration_ns = duration_bx * 25 \n", |
119 | 115 | "duration_seconds = duration_ns / 1e9\n", |
120 | 116 | "print(f'Data taking lasted: {duration_seconds} seconds')" |
121 | 117 | ] |
|
146 | 142 | } |
147 | 143 | ], |
148 | 144 | "source": [ |
149 | | - "df['ABS_T'] = (df['TDC_MEAS']*25/30)+(df['BX_COUNTER']*25)+(df['ORBIT_CNT']*num_bx_in_orbit*25) \n", |
150 | | - "#per aggiungere una colonna alla fine creo con df[]. poi in questo caso faccio la somma delle 3\n", |
151 | | - "#colonne ricordando di convertire in nanosecondi\n", |
| 145 | + "df['ABS_T'] = (df['TDC_MEAS']*25/30) + (df['BX_COUNTER']*25) + (df['ORBIT_CNT']*num_bx_in_orbit*25) \n", |
152 | 146 | "#df = df.drop(columns=['absolute_time_ns']) in caso volessi cancellare una colonna\n", |
153 | 147 | "print(df.head())" |
154 | 148 | ] |
|
171 | 165 | "text": [ |
172 | 166 | " HEAD FPGA TDC_CHANNEL ORBIT_CNT BX_COUNTER TDC_MEAS ABS_T\n", |
173 | 167 | "0 0 0 123 3869200167 2374 26 3.447457e+14\n", |
174 | | - "1 0 0 124 3869200167 2374 27 3.447457e+14\n", |
| 168 | + "1 1 0 124 3869200167 2374 27 3.447457e+14\n", |
175 | 169 | "2 0 0 63 3869200167 2553 28 3.447457e+14\n", |
176 | | - "3 1 0 64 3869200167 2558 19 3.447457e+14\n", |
| 170 | + "3 0 0 64 3869200167 2558 19 3.447457e+14\n", |
177 | 171 | "4 1 0 64 3869200167 2760 25 3.447457e+14\n" |
178 | 172 | ] |
179 | 173 | } |
180 | 174 | ], |
181 | 175 | "source": [ |
182 | | - "df['HEAD'] = np.random.choice([0,1], size = len(df)) #np.random.choice([valori ammessi], numero di\n", |
183 | | - "#righe da modificare)\n", |
| 176 | + "df['HEAD'] = np.random.choice([0,1], size = len(df))\n", |
184 | 177 | "print(df.head())" |
185 | 178 | ] |
186 | 179 | }, |
|
200 | 193 | "name": "stdout", |
201 | 194 | "output_type": "stream", |
202 | 195 | "text": [ |
203 | | - " HEAD FPGA TDC_CHANNEL ORBIT_CNT BX_COUNTER TDC_MEAS ABS_T\n", |
204 | | - "3 1 0 64 3869200167 2558 19 3.447457e+14\n", |
205 | | - "4 1 0 64 3869200167 2760 25 3.447457e+14\n", |
206 | | - "7 1 0 139 3869200167 2776 0 3.447457e+14\n", |
207 | | - "9 1 0 60 3869200167 2788 7 3.447457e+14\n", |
208 | | - "11 1 0 64 3869200167 2786 19 3.447457e+14\n" |
| 196 | + " HEAD FPGA TDC_CHANNEL ORBIT_CNT BX_COUNTER TDC_MEAS ABS_T\n", |
| 197 | + "1 1 0 124 3869200167 2374 27 3.447457e+14\n", |
| 198 | + "4 1 0 64 3869200167 2760 25 3.447457e+14\n", |
| 199 | + "5 1 0 63 3869200167 2762 4 3.447457e+14\n", |
| 200 | + "7 1 0 139 3869200167 2776 0 3.447457e+14\n", |
| 201 | + "8 1 0 62 3869200167 2774 21 3.447457e+14\n" |
209 | 202 | ] |
210 | 203 | } |
211 | 204 | ], |
212 | 205 | "source": [ |
213 | | - "df_head_1 = df[df['HEAD'] == 1] #creo un df nuovo che copia il df precedente prendendo però solo\n", |
214 | | - "#le righe dove df['HEAD'] == 1\n", |
| 206 | + "df_head_1 = df[df['HEAD'] == 1]\n", |
215 | 207 | "print(df_head_1.head())" |
216 | 208 | ] |
217 | 209 | }, |
|
224 | 216 | }, |
225 | 217 | { |
226 | 218 | "cell_type": "code", |
227 | | - "execution_count": 21, |
| 219 | + "execution_count": 9, |
228 | 220 | "metadata": {}, |
229 | 221 | "outputs": [ |
230 | 222 | { |
|
239 | 231 | } |
240 | 232 | ], |
241 | 233 | "source": [ |
242 | | - "# ho due valori di FPGA (0 e 1)\n", |
243 | | - "df_fpga0 = df[df['FPGA']==0] #creo un df con FPGA == 0\n", |
244 | | - "df_fpga1 = df[df['FPGA']==1] #creo un df con FPGA == 1\n", |
245 | | - "grouped_0 = df_fpga0.groupby('TDC_CHANNEL', dropna=False) #raggruppo con TDC_CHANNEL \n", |
246 | | - "grouped_1 = df_fpga1.groupby('TDC_CHANNEL', dropna=False) #e non escludo i valori NaN\n", |
247 | | - "counts_0 = grouped_0.count() #conta quanti valori ci sono\n", |
248 | | - "#print(counts_0)\n", |
| 234 | + "df_fpga0 = df[df['FPGA']==0] \n", |
| 235 | + "df_fpga1 = df[df['FPGA']==1]\n", |
| 236 | + "grouped_0 = df_fpga0.groupby('TDC_CHANNEL', dropna=False)\n", |
| 237 | + "grouped_1 = df_fpga1.groupby('TDC_CHANNEL', dropna=False) \n", |
| 238 | + "counts_0 = grouped_0.count()\n", |
249 | 239 | "counts_1 = grouped_1.count()\n", |
250 | | - "#print(counts_1)\n", |
251 | 240 | "\n", |
252 | | - "figure, axis = plt.subplots(1, 2) #una figura con 2 \"axis\", ovvero due figure in una\n", |
253 | | - "figure.set_figwidth(12) #larghezza \n", |
254 | | - "figure.set_figheight(6) #altezza \n", |
255 | | - "#setto la prima delle due figure\n", |
| 241 | + "figure, axis = plt.subplots(1, 2)\n", |
| 242 | + "figure.set_figwidth(12)\n", |
| 243 | + "figure.set_figheight(6)\n", |
| 244 | + "\n", |
256 | 245 | "axis[0].plot(counts_0.axes[0], counts_0['FPGA']) \n", |
257 | 246 | "axis[0].set_title(\"FPGA 0\") \n", |
258 | 247 | "axis[0].set_xlabel(\"TDC Channel\")\n", |
259 | 248 | "axis[0].set_ylabel(\"Counts\")\n", |
260 | | - "#ora la seconda figura\n", |
| 249 | + "\n", |
261 | 250 | "axis[1].plot(counts_1.axes[0], counts_1['FPGA'])\n", |
262 | 251 | "axis[1].set_title(\"FPGA 1\") \n", |
263 | 252 | "axis[1].set_xlabel(\"TDC Channel\")\n", |
264 | 253 | "axis[1].set_ylabel(\"Counts\")\n", |
265 | | - "figure.tight_layout(pad=5.0) #le metto attaccate" |
| 254 | + "figure.tight_layout(pad=5.0)" |
266 | 255 | ] |
267 | 256 | }, |
268 | 257 | { |
|
274 | 263 | }, |
275 | 264 | { |
276 | 265 | "cell_type": "code", |
277 | | - "execution_count": 25, |
| 266 | + "execution_count": 10, |
278 | 267 | "metadata": {}, |
279 | 268 | "outputs": [ |
280 | 269 | { |
|
316 | 305 | }, |
317 | 306 | { |
318 | 307 | "cell_type": "code", |
319 | | - "execution_count": 29, |
| 308 | + "execution_count": 11, |
320 | 309 | "metadata": {}, |
321 | 310 | "outputs": [ |
322 | 311 | { |
|
329 | 318 | } |
330 | 319 | ], |
331 | 320 | "source": [ |
332 | | - "n_of_unique_orbits = df_full['ORBIT_CNT'].nunique() #unici in tutto il dataset\n", |
| 321 | + "n_of_unique_orbits = df['ORBIT_CNT'].nunique() #unici in tutto il dataset\n", |
333 | 322 | "print(f\"Number of unique orbits: {n_of_unique_orbits}\")\n", |
334 | 323 | "\n", |
335 | | - "n_uniq_139 = df_full[df_full['TDC_CHANNEL'] == 139]['ORBIT_CNT'].nunique()\n", |
| 324 | + "n_uniq_139 = df[df['TDC_CHANNEL'] == 139]['ORBIT_CNT'].nunique()\n", |
336 | 325 | "print(f\"Number of unique orbits with at least one meas from TDC_CHANNEL=139: {n_uniq_139}\")" |
337 | 326 | ] |
338 | 327 | } |
|
0 commit comments