OBJECT ORIENTED PROGRAMMING FOR DATA PROCESSING Canale unico

Docente coordinatore e verbalizzante: FRANCESCO PANNARALE GRECO

Obiettivi formativi

Il principale obiettivo di Object Oriented Programming for Data Processing è quello di fornire un'introduzione ai metodi computazionali più recenti, usati nell'ambito dell’analisi dati nella ricerca attuale.

Il corso mira a familiarizzare gli studenti con le moderne tecniche di programmazione usate nell'analisi dati. Nella prima parte del corso, sarà presentato il C++ e la programmazione object-oriented e saranno risolti problemi di fisica con i Strategy and Composition patterns. Sarà discusso ROOT ed usato per l'analisi dei dati e l'immagazzinamento persistente di dati. Nella seconda parte del corso verrà introdotto il Python ed i package NumPy e SciPy. Il package MatPlotLib verrà usato per la visualizzazione ed animazione dei dati.


OBIETTIVI SPECIFICI:

A - Conoscenza e capacità di comprensione
OF 1) Conoscere programmazione orientata ad oggetti
OF 2) Comprendere il polimorfismo e le sue applicazioni in problemi di fisica
OF 3) Usare librerie di ROOT per analisi dati
OF 4) Conoscere gli ingredienti base per simulazione numerica di processi fisici
OF 5) Comprendere le principali caratteristiche di Python per analisi dati
OF 6) Conoscere le nozioni base di Machine Learning ed applicazioni

B – Capacità applicative
OF 7) Implementare classi polimorfiche per nozioni di fisica
OF 8) Realizzare simulazioni numeriche tramite uso di classi polimorfiche ed oggetti
OF 9) Fare analisi dati con ROOT e usare classi per graficare e interpolazioni di dati in C++
OF 10) Usare Jupyter Notebook e i pacchetti SciPy, Numpy e Matplotlib per simulazioni numeriche ed analisi dati con Python

C - Autonomia di giudizio
OF 11) Essere in grado di applicare le conoscenze acquisite in analisi dati e simulazioni numeriche anche in altri ambiti di fisica ed in contesti commerciali ed industriali
OF 12) Essere in gradi di applicare tecniche di Machine Learning in Python a problemi di fisica

D – Abilità nella comunicazione
OF 13) essere in grado di illustrare il concetto di polimorfismo con esempi applicati in fisica

E - Capacità di apprendere
OF 13) Essere in grado di approfondire aspetti più avanzati di programmazione ad oggetti in autonomia
OF 14) Essere in gradi di realizzare simulazioni numeriche per processi fisici più complessi come quelli trattati nei corsi di Laboratorio di Fisica
OF 15) Essere in grado di fare analisi dati ed interpolazioni numeriche nei corsi di Laboratorio di Fisica

Risultati di apprendimento attesi

Il principale obiettivo di Object Oriented Programming for Data Processing è quello di fornire un'introduzione ai metodi computazionali più recenti, usati nell'ambito della nell'ambito dell’analisi dati nella ricerca attuale.

Il corso mira a familiarizzare gli studenti con le moderne tecniche di programmazione usate nell'analisi dati. Nella prima parte del corso, sarà presentato il C++ e la programmazione object-oriented e saranno risolti problemi di fisica con i Strategy and Composition patterns. Sarà discusso ROOT ed usato per l'analisi dei dati e l'immagazzinamento persistente di dati. Nella seconda parte del corso verrà introdotto il Python ed i package NumPy e SciPy. Il package MatPlotLib verrà usato per la visualizzazione ed animazione dei dati.

OBIETTIVI SPECIFICI:

A - Conoscenza e capacità di comprensione
OF 1) Conoscere programmazione orientata ad oggetti
OF 2) Comprendere il polimorfismo e le sue applicazioni in problemi di fisica
OF 3) Usare librerie di ROOT per analisi dati
OF 4) Conoscere gli ingredienti base per simulazione numerica di processi fisici
OF 5) Comprendere le principali caratteristiche di Python per analisi dati

B – Capacità applicative
OF 6) Implementare classi polimorfiche per nozioni di fisica
OF 7) Realizzare simulazioni numeriche tramite uso di classi polimorfiche ed oggetti
OF 8) Fare analisi dati con ROOT e usare classi per graficare e interpolazioni di dati in C++
OF 9) Usare Jupyter Notebook e i pacchetti SciPy, Numpy e Matplotlib per simulazioni numeriche ed analisi dati con Python

C - Autonomia di giudizio
OF 10) Essere in grado di applicare le conoscenze acquisite in analisi dati e simulazioni numeriche anche in altri ambiti di fisica ed in contesti commerciali ed industriali

D – Abilità nella comunicazione
OF 11) essere in grado di illustrare il concetto di polimorfismo con esempi applicati in fisica

E - Capacità di apprendere
OF 12) Essere in grado di approfondire aspetti più avanzati di programmazione ad oggetti in autonomia
OF 13) Essere in gradi di realizzare simulazioni numeriche per processi fisici più complessi come quelli trattati nei corsi di Laboratorio di Fisica
OF 14) Essere in grado di fare analisi dati ed interpolazioni numeriche nei corsi di Laboratorio di Fisica

Prerequisiti

Le conoscenze di programmazione di base, ovvero iterazioni, condizioni, puntatori, funzioni, array, sono essenziali. È importante avere conoscenze di base di meccanica classica, elettromagnetismo, cinematica relativistica e teoria della misura, offerte dai corsi di laurea in Fisica o in Astronomia e astrofisica. E' utile avere una conoscenza di base della fisica subnucleare, come il concetto di decadimenti e collisioni, massa invariante e conservazione del 4-momento.

Programma dell’insegnamento

The main goal of Computing Methods for Physics is to provide an introduction to the most recent computational methods, used in the context of current research. The course is structured with four channels, with different contents.
The first channel aims at making students familiar with modern techniques of programming used in data analysis. The first part of the course introduces C++ and object-oriented programming; physics problems are solved, and ROOT is discussed and used for data analysis and persistent data storage. The second part of the course focuses on Python and some popular packages, such as NumPy and SciPy. The MatPlotLib package will be used for data visualization and animation.

The detailed content of the course is the following.

Part 1 — C++
* Introduction to C++.
* Data types. Functions. Variable scope. Namespaces.
* References and pointers. Constants.
* Classes and objects in C++. Interface and attributes. Constructors. Private and public mem- bers, helper and utility methods.
* Separating interface and implementation. Header and source files.
* Constant member functions. Default arguments for function parameters.
* Dynamic memory allocation. Destructors.
* Operator overloading. Special this pointer. Friend methods.
* Static data members and methods.
* Enumerators.
* g++ options. Command line arguments. Linking external libraries. File I/O.
* Using std::map, std::pair, and std::vector.
* Object oriented programming: Inheritance. Base and derived class.
* Overview of Polymorphism. Polymorphism with virtual methods.
* Abstract class. Virtual and pure virtual functions. Virtual destructors.
* Strategy Pattern (examples: numerical integration methods, custom Function class).
* ROOT:
- Compiling and linking with ROOT libraries.
- Data storage and I/O (TFile and TTree).
- Random generators (TRandom).
- 1D histograms (TH1F).
- Branches with variable per-event size.
- 2D histograms (TH2F).
- Using TTTree’s created by others. Creating a custom analysis class.
- Relativistic boost (TTLorentzVector).

Part 2 — Python
* Introduction to Python. Differences with C/C++.
* Interactive Python, Python scripts, Python with Jupyter notebooks.
* Basics: semantics, flow control, data types, functions, modules.
* Collections: tuples, lists, dictionaries and sets. Comprehensions.
* File processing: simple text I/O, pickle, json.
* Functions with multiple return values, positional and keyword arguments.
* NumPy: ndarrays and their methods and attributes.
* Matplotlib: plotting functions and histograms, making animated plots.
* SciPy: integrate.trapz, integrate.quad, integrate.odeint, optimize.curve fit.
* Classes in Python: init , del , str , operator overriding, inheritance and polymorphism, double- and single-underscore variable name prefixes, empty class, static methods, multiple inheritance.
* Markov-Chain-Monte-Carlo with emcee.

Testi di riferimento

The student will be provided with detailed slides, notebooks, and code examples throughout the course.

The following is a list of suggested textbooks.
* C++ How to program (5th edition), H. Deitel and P. Deitel, Prentice Hall
* The C++ Programming Language (4th edition), B. Stroustrup, Addison-Wesley Professional
* Effective Modern C++, S. Meyers, O’Reilly Media
* Python for Data Analysis (2nd Edition), W. McKinney, O’Reilly Media

Modalità di svolgimento

Le lezioni sono tenute due volte alla settimana e sono basate su presentazioni e sulla condivisione di esempi di codice con gli studenti. Dopo 3 settimane di lezione, sono previste sessioni di laboratorio una volta alla settimana della durata di 3 ore, per un totale di 4 sessioni di laboratorio.

Frequenza

La frequenza alle lezioni non è obbligatoria ma è fortemente consigliata, così come la partecipazione alle sessioni di laboratorio per C++ e Python.

Modalità di esame

L’esame consiste in una prova pratica di 4 ore da svolgere in presenza o da remoto tramite connessione audio/video. La prova consiste nella implementazione di una simulazione numerica, o di classi per risolvere un problema di fisica, oppure l’analisi di dati forniti o simulati. Al termine della prova viene consegnato il codice insieme con i grafici generati dal programma. Ci sarà poi una discussione orale delle soluzioni adottate.

Nella valutazione si terrà conto di:
- correttezza logica del programma;
- correttezza di sintassi nel codice;
- errori di compilazione e linking;
- chiarezza e rigore nelle scelte fatte;
- correttezza numerica, ordine di grandezza, e unità di misura nei grafici.

Esempi di domande

Your exam material (code files, plots, etc.) must be submitted via google classroom by 13:00 as a single zip file.

C++ evaluation will be based on: correct syntax, proper return types, proper arguments of functions, data members and class interfaces, setters/getters, unnecessary void functions, correct mathematical expression and physical units, comments throughout the code, separation of class implementations and interfaces.

Python evaluation will be based on: correct syntax, avoiding C-style loops, using Python features in general, comments throughout the notebook/scripts, labels, legends and plot styling and clarity in general.

Part 1 – C++
1. A capacitor is characterized by its capacitance C = Q/∆V — measured in Farad [F] — which regulates the ratio between the charge Q > 0 on its positively charged plate and the differential potential ∆V between its two plates. These quantities can be used to determine the energy stored in the capacitor:
U = 1/2 C (∆V)^2 = 1/2 Q ∆V = 1/2 Q^2 C.
Implement a class Capacitor to represent spherical capacitors, for which
C=4πε0εr R1R2/(R2-R1),
where ε0 = 8.854·10−12 F/m is the vacuum permittivity, R1 and R2 are the radii of the inner and the outer spherical plate, respectively, and εr ≥ 1 is the relative permittivity of the material between the plates (εr = 1 for vacuum). The class must provide 3 constructors so that the user can create instances of these capacitors by providing Q, ∆V , or U in addition to R1, R2, and εr.

2. Implement a class CompositeCapacitor which inherits from Capacitor and allows the user to represent spherical capacitors in which the gap between the plates is filled with N layers of different materials (so different εr’s) with the same thickness. The total capacitance of a this object is given by
C = 1/(1/C1 + ... +1/CN)
where Ci is the capacitance of layer i. Also this class must provide the user with 3 constructors, but note that this time ε will not be a single value: instead ε⃗ = {εr1, ..., εrN}.

3. Write an application app.cpp to showcase the methods of your classes.


Part 2 – Python
Use a Python notebook or Python scripts to complete the following tasks.
1. Load the dictionary stored in the file data.pickle.
2. Plot the data content of the dictionary.
3. Set up a Monte Carlo with emcee to fit the data.
4. Display and comment the results of your fit.

  • Anno accademico2026/2027
  • Corso di studio a cui afferisce l’insegnamentoPhysics - Fisica
  • Codice insegnamento10616465
  • CurriculumPhysics of Biological Systems
  • Anno e semestre1º anno - 1º semestre
  • TipologiaAttività formative affini ed integrative
  • AmbitoAttività formative affini o integrative
  • SSDFIS/01
  • Presenza obbligatoriaNo
  • Linguaeng
  • CFU6 CFU
  • Durata complessiva60 ore
  • Distribuzione delle ore24 classroom hours, 36 training hours