Skip to content

This project demonstrates an example of a physics analysis by reading data from a CERN ROOT file. The processed data includes properties of muons and jets. The main objective of the project is to calculate the total energy and environmental mass of the jets surrounding the muon in the dataset.

License

Notifications You must be signed in to change notification settings

masanbasa3k/ML-FOR-ENVIRONMENT-MASS-CALCULATIONS-OF-MUONS

Repository files navigation

ML FOR ENVIRONMENT MASS CALCULATIONS OF MUONS (Graduation_Project)

English Explanation

This code demonstrates an example of a physical analysis used in a graduation project, by reading data from a CERN ROOT file. The processed data includes properties of muons and jets. The main objective of the project is to calculate the total energy and environmental mass of jets around muons in the data set.

The code first opens the ROOT file using the uproot library and reads the data using the required branch names. Then, it defines functions to calculate the four-momentum of muons and jets, as well as the environmental mass.

The data set consists of properties such as PT, Eta, Phi for muons, and PT, Eta, Phi, Mass for jets. The data set goes through preprocessing steps and is combined with the functions used to calculate the environmental mass.

In the next step, the data set is split into independent variables (muon properties) and the target variable (environmental mass). Then, the data set is divided into training and test sets.

Next, different machine learning models (Random Forest, Linear Regression, SVR) are defined, and permutation importance evaluation is used to calculate the feature importance rankings of these models. The obtained results are printed based on the feature importance rankings.

Finally, various machine learning models (DummyRegressor, KNeighborsRegressor, LinearRegression, etc.) are defined, and these models are evaluated with different performance metrics (mean absolute error, median absolute error, R-squared score, explained variance score). The metric results obtained are collected in a data frame and printed.

Detailed Explanation

  1. Defines a function calculate_muon_momentum that calculates the momentum and energy components of a muon based on its transverse momentum (PT), pseudorapidity (Eta), and azimuthal angle (Phi).
  2. Defines a function calculate_delta_R that calculates the angular separation (delta R) between two objects given their pseudorapidities and azimuthal angles.
  3. Defines a function calculate_environment_mass that calculates the environmental mass around a muon by considering the momenta of nearby jets and missing energy. It uses the previously defined functions to calculate the muon momentum and delta R.
  4. Defines a list of branches to extract from the ROOT file.
  5. Extracts the data from the ROOT file and converts it into a Pandas DataFrame.
  6. Calls the calculate_environment_mass function to calculate the environmental mass and adds it as a new column in the DataFrame.
  7. Splits the DataFrame into input features (X) and the target variable (y).
  8. Splits the data into training and test sets using train_test_split from scikit-learn.
  9. Defines a list of models to train, including Random Forest, Linear Regression, and Support Vector Regression.
  10. Trains each model using the training data and calculates the feature importances using permutation importance.
  11. Prints the feature importances for each model.
  12. Defines a list of model names and metric names for evaluation.
  13. Creates an empty DataFrame to store the evaluation metrics.
  14. Loops over each model, evaluates it on the test data, and calculates metrics such as mean absolute error, median absolute error, R-squared score, and explained variance score.
  15. Prints the evaluation metrics for each model.

Türkçe Anlatım

Bu kod, CERN ROOT dosyasından veri okuyarak bir bitirme projesinde kullanılan bir fiziksel analiz örneğini göstermektedir. İşlenen veri, muon ve jetlerin özelliklerini içermektedir. Projenin ana hedefi, veri tabanındaki muonun çevresindeki jetlerin toplam enerjisini ve çevresel kütlesini hesaplamaktır.

Kod, öncelikle uproot kütüphanesini kullanarak ROOT dosyasını açar ve gerekli dal adlarını kullanarak verileri okur. Ardından, muon ve jetlerin dört momentumunu hesaplayan ve çevresel kütleyi hesaplayan fonksiyonlar tanımlanır.

Veri seti, muonun özellikleri (PT, Eta, Phi) ve jetlerin özellikleri (PT, Eta, Phi, Kütle) gibi özelliklerden oluşur. Veri seti öncelikle ön işleme adımlarından geçirilir ve çevresel kütleyi hesaplamak için kullanılan fonksiyonlarla birleştirilir.

Sonraki adımda, veri seti bağımsız değişkenler (muon özellikleri) ve hedef değişken (çevresel kütle) olarak ayrılır. Ardından, veri seti eğitim ve test setlerine bölünür.

Daha sonra, farklı makine öğrenimi modelleri (Random Forest, Linear Regression, SVR) tanımlanır ve bu modellerin özellik önem derecelerini hesaplamak için permütasyon önem değerlendirmesi kullanılır. Elde edilen sonuçlar, özellik önem sıralamasına göre yazdırılır.

Son olarak, çeşitli makine öğrenimi modelleri (DummyRegressor, KNeighborsRegressor, LinearRegression, vb.) tanımlanır ve bu modellerin farklı performans metrikleriyle (ortalama mutlak hata, medyan mutlak hata, R-kare skoru, açıklanan varyans skoru) değerlendirilir. Elde edilen metrik sonuçları bir veri çerçevesinde toplanır ve yazdırılır.

Detaylı Anlatım

  1. Bir fonksiyon tanımlayın: calculate_muon_momentum. Bu fonksiyon, bir müonün moment ve enerji bileşenlerini, transvers momentumu (PT), pseudorapidity (Eta) ve azimuthal açısı (Phi) temel alarak hesaplar.
  2. Bir fonksiyon tanımlayın: calculate_delta_R. Bu fonksiyon, pseudorapidity ve azimuthal açılarına dayanarak, iki nesne arasındaki açısal ayrımı (delta R) hesaplar.
  3. Bir fonksiyon tanımlayın: calculate_environment_mass. Bu fonksiyon, yakındaki jetlerin momenta ve eksik enerjiyi dikkate alarak, bir müonun çevresel kütlesini hesaplar. Müon momentumunu ve delta R'yi hesaplamak için önceden tanımlanan fonksiyonları kullanır.
  4. ROOT dosyasından çıkarılacak dalları içeren bir liste tanımlayın.
  5. ROOT dosyasından verileri çıkarın ve bunları bir Pandas DataFrame'e dönüştürün.
  6. calculate_environment_mass fonksiyonunu çağırarak çevresel kütleyi hesaplayın ve DataFrame'e yeni bir sütun olarak ekleyin.
  7. DataFrame'i giriş özellikleri (X) ve hedef değişken (y) olarak ayırın.
  8. scikit-learn'den train_test_split kullanarak veriyi eğitim ve test setlerine ayırın.
  9. Random Forest, Linear Regression ve Support Vector Regression gibi eğitilecek modellerin bir listesini tanımlayın.
  10. Her bir modeli eğiterek, özellik önemini permutasyon önemine göre hesaplayın.
  11. Her bir model için özellik önemlerini yazdırın.
  12. Değerlendirme için model adları ve metrik adlarını içeren bir liste tanımlayın.
  13. Değerlendirme metriklerini saklamak için boş bir DataFrame oluşturun.
  14. Her bir model için döngü oluşturarak, test verisi üzerinde değerlendirin ve ortalama mutlak hata, medyan mutlak hata, R-kare skoru ve açıklanan varyans skoru gibi metrikleri hesaplayın.
  15. Her bir model için değerlendirme metriklerini yazdırın.

About

This project demonstrates an example of a physics analysis by reading data from a CERN ROOT file. The processed data includes properties of muons and jets. The main objective of the project is to calculate the total energy and environmental mass of the jets surrounding the muon in the dataset.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages