diff --git a/arf/SaeFF_0.0_0.0.arf b/arf/SaeFF_0.0_0.0.arf
index 4c6f3ef1d1bf425613deb54c8ffbea4f2923dd7d..8c6d198412ba0c80cec3424bf48a543c1e2f8853 100644
Binary files a/arf/SaeFF_0.0_0.0.arf and b/arf/SaeFF_0.0_0.0.arf differ
diff --git a/arf/SaeFF_0.0_180.0.arf b/arf/SaeFF_0.0_180.0.arf
index 1a0a668b852e72bf2c571f9646147fd911325ff5..cc1a0c3f0b0bfbb775a5879e6c9fdd16dbb81578 100644
Binary files a/arf/SaeFF_0.0_180.0.arf and b/arf/SaeFF_0.0_180.0.arf differ
diff --git a/arf/SaeFF_0.0_270.0.arf b/arf/SaeFF_0.0_270.0.arf
index 030182a92a7fc6441406b9850c1139a1e10c85ec..878b59c37f6274c186e62f34d654e317fe9d2e71 100644
Binary files a/arf/SaeFF_0.0_270.0.arf and b/arf/SaeFF_0.0_270.0.arf differ
diff --git a/arf/SaeFF_0.0_360.0.arf b/arf/SaeFF_0.0_360.0.arf
index 4c6f3ef1d1bf425613deb54c8ffbea4f2923dd7d..8c6d198412ba0c80cec3424bf48a543c1e2f8853 100644
Binary files a/arf/SaeFF_0.0_360.0.arf and b/arf/SaeFF_0.0_360.0.arf differ
diff --git a/arf/SaeFF_0.0_90.0.arf b/arf/SaeFF_0.0_90.0.arf
index 3e6d9833aef1db59516404e4d20aed01033e2703..dcc2667336495c249dbb4e3bfac2d819c07f5351 100644
Binary files a/arf/SaeFF_0.0_90.0.arf and b/arf/SaeFF_0.0_90.0.arf differ
diff --git a/arf/SaeFF_30.0_0.0.arf b/arf/SaeFF_30.0_0.0.arf
index df8cd1c151e93475a38cb691c2d8b1ae2f222ae7..b6a058c6ed65e89f946a51abbe58e0c3b6233485 100644
Binary files a/arf/SaeFF_30.0_0.0.arf and b/arf/SaeFF_30.0_0.0.arf differ
diff --git a/arf/SaeFF_30.0_180.0.arf b/arf/SaeFF_30.0_180.0.arf
index 86a8a4f690825a9201f0acdad5ff352c97abca6e..520798f7195a35d50ff7236012ae0d548b11bdeb 100644
Binary files a/arf/SaeFF_30.0_180.0.arf and b/arf/SaeFF_30.0_180.0.arf differ
diff --git a/arf/SaeFF_30.0_270.0.arf b/arf/SaeFF_30.0_270.0.arf
index cc4bf5d0897e8f0d9537914906153b36502d418f..9bd51c8fefbe325b881bff64b52bebffd7181693 100644
Binary files a/arf/SaeFF_30.0_270.0.arf and b/arf/SaeFF_30.0_270.0.arf differ
diff --git a/arf/SaeFF_30.0_360.0.arf b/arf/SaeFF_30.0_360.0.arf
index df8cd1c151e93475a38cb691c2d8b1ae2f222ae7..b6a058c6ed65e89f946a51abbe58e0c3b6233485 100644
Binary files a/arf/SaeFF_30.0_360.0.arf and b/arf/SaeFF_30.0_360.0.arf differ
diff --git a/arf/SaeFF_30.0_90.0.arf b/arf/SaeFF_30.0_90.0.arf
index bae1b2d89b7f5651423ed689ef88f586eb0b2624..8eee78ed4ba71fe59bcb07743471ca71303fd1b6 100644
Binary files a/arf/SaeFF_30.0_90.0.arf and b/arf/SaeFF_30.0_90.0.arf differ
diff --git a/arf/SaeFF_60.0_0.0.arf b/arf/SaeFF_60.0_0.0.arf
index 447a31d96b88d261363c66d130538b2e3ba08697..846b1b427b53bddf50825a600c97cf4ee7303469 100644
Binary files a/arf/SaeFF_60.0_0.0.arf and b/arf/SaeFF_60.0_0.0.arf differ
diff --git a/arf/SaeFF_60.0_180.0.arf b/arf/SaeFF_60.0_180.0.arf
index 46486e27aea11cd78c685eb6a03a69696d73e483..bf4a0993f305b27f6b4dd046415373df9b841dc2 100644
Binary files a/arf/SaeFF_60.0_180.0.arf and b/arf/SaeFF_60.0_180.0.arf differ
diff --git a/arf/SaeFF_60.0_270.0.arf b/arf/SaeFF_60.0_270.0.arf
index c5cef21bc7bd27a4bfa5e2a8a042ef1a31db3de5..9238c32e190a6ac23091844ec02481fbd1b0dc4a 100644
Binary files a/arf/SaeFF_60.0_270.0.arf and b/arf/SaeFF_60.0_270.0.arf differ
diff --git a/arf/SaeFF_60.0_360.0.arf b/arf/SaeFF_60.0_360.0.arf
index 447a31d96b88d261363c66d130538b2e3ba08697..846b1b427b53bddf50825a600c97cf4ee7303469 100644
Binary files a/arf/SaeFF_60.0_360.0.arf and b/arf/SaeFF_60.0_360.0.arf differ
diff --git a/arf/SaeFF_60.0_90.0.arf b/arf/SaeFF_60.0_90.0.arf
index 5f4cdf76e1597c33bba573d9b11420df28f4d7c1..e4af0e10a0beb324384f47a4fc9eccb9a8d2c15b 100644
Binary files a/arf/SaeFF_60.0_90.0.arf and b/arf/SaeFF_60.0_90.0.arf differ
diff --git a/arf/SaeFF_90.0_0.0.arf b/arf/SaeFF_90.0_0.0.arf
index 72e47f9d216a75b160b821ab2e6222f4c0db1f6b..d2eea23a5e67f416427f5620844d7b4af1cd8a73 100644
Binary files a/arf/SaeFF_90.0_0.0.arf and b/arf/SaeFF_90.0_0.0.arf differ
diff --git a/arf/SaeFF_90.0_180.0.arf b/arf/SaeFF_90.0_180.0.arf
index b185dec1c310ae2ccbc20ef148bee111a6495042..24823210571ef61b68c26254688ae8d9a4df5b21 100644
Binary files a/arf/SaeFF_90.0_180.0.arf and b/arf/SaeFF_90.0_180.0.arf differ
diff --git a/arf/SaeFF_90.0_270.0.arf b/arf/SaeFF_90.0_270.0.arf
index b7cd14a0a544e88074ccf18ba1b57108701d8d54..99a52ccbac660c89bb3503be3c4a428afaf52d9f 100644
Binary files a/arf/SaeFF_90.0_270.0.arf and b/arf/SaeFF_90.0_270.0.arf differ
diff --git a/arf/SaeFF_90.0_360.0.arf b/arf/SaeFF_90.0_360.0.arf
index 72e47f9d216a75b160b821ab2e6222f4c0db1f6b..d2eea23a5e67f416427f5620844d7b4af1cd8a73 100644
Binary files a/arf/SaeFF_90.0_360.0.arf and b/arf/SaeFF_90.0_360.0.arf differ
diff --git a/arf/SaeFF_90.0_90.0.arf b/arf/SaeFF_90.0_90.0.arf
index 31d8d73f5874f8e850bfac8f5ed6da25050a01a0..45ab258a4dab4daa2a30d2f56ed5f7769858d814 100644
Binary files a/arf/SaeFF_90.0_90.0.arf and b/arf/SaeFF_90.0_90.0.arf differ
diff --git a/arf/XaeFF_0.0_0.0.arf b/arf/XaeFF_0.0_0.0.arf
index 6936827ee66951150c243d772e9b8e8f7e412f55..c111f8347cfd4ff66d24b2b33992a334ebadecf5 100644
Binary files a/arf/XaeFF_0.0_0.0.arf and b/arf/XaeFF_0.0_0.0.arf differ
diff --git a/arf/XaeFF_0.0_180.0.arf b/arf/XaeFF_0.0_180.0.arf
index 60d7d6803a579a1434d3daa0f969a5fafba1375d..88f2a948668f0767e8c698d3196ceb4067bcfffc 100644
Binary files a/arf/XaeFF_0.0_180.0.arf and b/arf/XaeFF_0.0_180.0.arf differ
diff --git a/arf/XaeFF_0.0_270.0.arf b/arf/XaeFF_0.0_270.0.arf
index 2d47ea21e772bbf2dfff1046de72201f3abf31ff..ee8f35f32a78f4d34c02dc25fb3edeedf1ba77fc 100644
Binary files a/arf/XaeFF_0.0_270.0.arf and b/arf/XaeFF_0.0_270.0.arf differ
diff --git a/arf/XaeFF_0.0_360.0.arf b/arf/XaeFF_0.0_360.0.arf
index 6936827ee66951150c243d772e9b8e8f7e412f55..c111f8347cfd4ff66d24b2b33992a334ebadecf5 100644
Binary files a/arf/XaeFF_0.0_360.0.arf and b/arf/XaeFF_0.0_360.0.arf differ
diff --git a/arf/XaeFF_0.0_90.0.arf b/arf/XaeFF_0.0_90.0.arf
index fef0dcfca91873a8b50a4138950f868aa8ed8351..a70a5057c5c127f27ed6de737ca832f208bd2f39 100644
Binary files a/arf/XaeFF_0.0_90.0.arf and b/arf/XaeFF_0.0_90.0.arf differ
diff --git a/arf/XaeFF_30.0_0.0.arf b/arf/XaeFF_30.0_0.0.arf
index 7396a70e5585df172ce4f9aedace1c987b27f8b2..0ed7c2c7c2ab1e8f8b67871055f4a73c07a444fd 100644
Binary files a/arf/XaeFF_30.0_0.0.arf and b/arf/XaeFF_30.0_0.0.arf differ
diff --git a/arf/XaeFF_30.0_180.0.arf b/arf/XaeFF_30.0_180.0.arf
index 55a0d264969077faa37c703e2e366cc601c95efd..c6599baf6c337d6bad1280d07e1d14e127989f7e 100644
Binary files a/arf/XaeFF_30.0_180.0.arf and b/arf/XaeFF_30.0_180.0.arf differ
diff --git a/arf/XaeFF_30.0_270.0.arf b/arf/XaeFF_30.0_270.0.arf
index 9fceff18ba43249867dfa0fa176100bdd096fad8..1608c49a1f604080d7e1fa8a960276247cc9e46a 100644
Binary files a/arf/XaeFF_30.0_270.0.arf and b/arf/XaeFF_30.0_270.0.arf differ
diff --git a/arf/XaeFF_30.0_360.0.arf b/arf/XaeFF_30.0_360.0.arf
index 7396a70e5585df172ce4f9aedace1c987b27f8b2..0ed7c2c7c2ab1e8f8b67871055f4a73c07a444fd 100644
Binary files a/arf/XaeFF_30.0_360.0.arf and b/arf/XaeFF_30.0_360.0.arf differ
diff --git a/arf/XaeFF_30.0_90.0.arf b/arf/XaeFF_30.0_90.0.arf
index 47a824af6fd4fadea51158a8c4772a9420323559..7b2a555418c42da60793c5dd3597ac1b024b1976 100644
Binary files a/arf/XaeFF_30.0_90.0.arf and b/arf/XaeFF_30.0_90.0.arf differ
diff --git a/arf/XaeFF_60.0_0.0.arf b/arf/XaeFF_60.0_0.0.arf
index 76c693b177a477d0c48fc7d49de658975ea77a55..724b1cd1e2ddc12eb61ac217cb6a13bca9cfcc83 100644
Binary files a/arf/XaeFF_60.0_0.0.arf and b/arf/XaeFF_60.0_0.0.arf differ
diff --git a/arf/XaeFF_60.0_180.0.arf b/arf/XaeFF_60.0_180.0.arf
index 997670a3fbccf4e2663852ab9b57c65109a8a934..3fac20baa4e0810ab2d10c267456636ba6dff1ab 100644
Binary files a/arf/XaeFF_60.0_180.0.arf and b/arf/XaeFF_60.0_180.0.arf differ
diff --git a/arf/XaeFF_60.0_270.0.arf b/arf/XaeFF_60.0_270.0.arf
index 11ded8a25d24592a8d60034802aca00741d5991b..02eb8ab97797bdbe680da6ccaa281c4ec38435ea 100644
Binary files a/arf/XaeFF_60.0_270.0.arf and b/arf/XaeFF_60.0_270.0.arf differ
diff --git a/arf/XaeFF_60.0_360.0.arf b/arf/XaeFF_60.0_360.0.arf
index 76c693b177a477d0c48fc7d49de658975ea77a55..724b1cd1e2ddc12eb61ac217cb6a13bca9cfcc83 100644
Binary files a/arf/XaeFF_60.0_360.0.arf and b/arf/XaeFF_60.0_360.0.arf differ
diff --git a/arf/XaeFF_60.0_90.0.arf b/arf/XaeFF_60.0_90.0.arf
index 26b8d6d2c11cb45c0dcd268a9d4ceb12586f4e62..e5f423066ac8258b293c8afbd12fa92cea0541d0 100644
Binary files a/arf/XaeFF_60.0_90.0.arf and b/arf/XaeFF_60.0_90.0.arf differ
diff --git a/arf/XaeFF_90.0_0.0.arf b/arf/XaeFF_90.0_0.0.arf
index 8447185f59cefee94adf552292d772d8652d0128..f2a7f79c725a637ef548311436469dbafcc2a505 100644
Binary files a/arf/XaeFF_90.0_0.0.arf and b/arf/XaeFF_90.0_0.0.arf differ
diff --git a/arf/XaeFF_90.0_180.0.arf b/arf/XaeFF_90.0_180.0.arf
index 3cdd6ef2894d7c66653a101244b042edf204737d..0a05effe1202ddd5e7f00fb3d78edb103a41478f 100644
Binary files a/arf/XaeFF_90.0_180.0.arf and b/arf/XaeFF_90.0_180.0.arf differ
diff --git a/arf/XaeFF_90.0_270.0.arf b/arf/XaeFF_90.0_270.0.arf
index 0ab2424417c8cda7fd3662ccd7ecb7d6c53f9de1..31175037bbb232490c88a9bb4be301f46024c648 100644
Binary files a/arf/XaeFF_90.0_270.0.arf and b/arf/XaeFF_90.0_270.0.arf differ
diff --git a/arf/XaeFF_90.0_360.0.arf b/arf/XaeFF_90.0_360.0.arf
index 8447185f59cefee94adf552292d772d8652d0128..f2a7f79c725a637ef548311436469dbafcc2a505 100644
Binary files a/arf/XaeFF_90.0_360.0.arf and b/arf/XaeFF_90.0_360.0.arf differ
diff --git a/arf/XaeFF_90.0_90.0.arf b/arf/XaeFF_90.0_90.0.arf
index 93000e87b747feb66a717c7d5f4132dc65b57b85..d56635bc853beb716edd8b2c7cd669e71dc68752 100644
Binary files a/arf/XaeFF_90.0_90.0.arf and b/arf/XaeFF_90.0_90.0.arf differ
diff --git a/python/__pycache__/arf.cpython-38.pyc b/python/__pycache__/arf.cpython-38.pyc
index 8e30ad9f8724c2f46fb710b04813c56fe4e634b2..bf5dbd0ecf6b72bf7ac8fc2bdfc245dfcc8b0d2d 100644
Binary files a/python/__pycache__/arf.cpython-38.pyc and b/python/__pycache__/arf.cpython-38.pyc differ
diff --git a/python/__pycache__/data.cpython-38.pyc b/python/__pycache__/data.cpython-38.pyc
index 0cd0ec4d811ebead27d00714daf4eb0ccab7291b..5e7c1d2d6f36d5c110deb8423968d6a6d2584995 100644
Binary files a/python/__pycache__/data.cpython-38.pyc and b/python/__pycache__/data.cpython-38.pyc differ
diff --git a/python/__pycache__/noisy.cpython-38.pyc b/python/__pycache__/noisy.cpython-38.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..27091080e209d0d4822fa1f3a8d5dad2e6f3ebed
Binary files /dev/null and b/python/__pycache__/noisy.cpython-38.pyc differ
diff --git a/python/__pycache__/rmf.cpython-38.pyc b/python/__pycache__/rmf.cpython-38.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..6421dbd07ce8b73b7a50995a34a212d7d9418a4d
Binary files /dev/null and b/python/__pycache__/rmf.cpython-38.pyc differ
diff --git a/python/a.out b/python/a.out
deleted file mode 100755
index 67b98a4d229102453ed94ee2a9591fbce78cb5a2..0000000000000000000000000000000000000000
Binary files a/python/a.out and /dev/null differ
diff --git a/python/aeFF.py b/python/aeFF.py
index 2f800aeaa5ae76f1b003477770f586146d214bb2..c5ea7bbdd01c926f8b947e3a00a08a48d82fe8cc 100644
--- a/python/aeFF.py
+++ b/python/aeFF.py
@@ -12,6 +12,7 @@ def main():
     # 1 Estract data from fits file and give these output file_dat
     file_dat = "areaEfficace.dat"
     data_estraction(file_dat)
+    
     #2 Filter data
     data = np.loadtxt(file_dat, dtype=str)
     
@@ -38,6 +39,7 @@ def main():
         # Maschera booleana per filtrare i dati per la combinazione corrente di theta e phi
         # confronta i dati del file con i dati dell'array creato
         mask = (theta == theta_val) & (phi == phi_val)
+
         energy_filtered = energy[mask]
         ratio_X_filtered = ratio_X[mask]
         ratio_S_filtered = ratio_S[mask]
@@ -49,11 +51,11 @@ def main():
         #plot_data_S.append((energy_filtered, ratio_S_filtered, theta_val, phi_val))
 
         # 3 ARF
-        #arf_file(energy_filtered, ratio_X_filtered, ratio_S_filtered, theta_val, phi_val)
+        arf_file(energy_filtered, ratio_X_filtered, ratio_S_filtered, theta_val, phi_val)
 
         # 4 RMF
-        #rmf_file(energy_filtered, 'X', X_en_dep_file_filtered, theta_val, phi_val)
-        #rmf_file(energy_filtered, 'S', S_en_dep_file_filtered, theta_val, phi_val)
+        rmf_file('X', energy_filtered, X_en_dep_file_filtered, theta_val, phi_val)
+        rmf_file('S', energy_filtered, S_en_dep_file_filtered, theta_val, phi_val)
 
         # approcci diversi per arf e rmf
         # in arf essendo più semplice la chiamo una volta e dentro scrivo due volte le cose che deve fare
diff --git a/python/arf.py b/python/arf.py
index d74d73efe1884723e9548e0728aa6f0c2e808d86..2f4759871c4a685cfa5a2efdf2ade59c94f566f2 100644
--- a/python/arf.py
+++ b/python/arf.py
@@ -16,6 +16,7 @@ def create_header(extension):
     extension.header['ARFVERSN'] = '1992A'
     extension.header['HDUVERS1'] = '1.0.0'
     extension.header['HDUVERS2'] = '1.1.0'
+    extension.header['COMMENT'] = "Alfonso Pisapia"
 
 def arf_file(energy_filt, ratio_X_filt, ratio_S_filt, theta, phi):
     try:
diff --git a/python/convertFits2Ascii.py b/python/convertFits2Ascii.py
index 0d33c62affe30998ecde6bab9c598c5204456005..c871b9f622da101407e933270fc71567829cc0b8 100644
--- a/python/convertFits2Ascii.py
+++ b/python/convertFits2Ascii.py
@@ -1,13 +1,14 @@
-import astropy.io.fits as fits
+import astropy.io.fits as pyfits
 import numpy as np
 
 # ! posso anche lanciare questo script dal bash iniziale e gli do come argomento il nome del file
 
-mask_file_fits = "msk_55_4752313.fits"
+mask_file_fits = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/msk_55_4752313.fits"
+mask_file_ascii = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/mask.dat"
 
 def fits_to_ascii(mask_file_fits, mask_file_ascii):
     
-    with fits.open(mask_file_fits) as hdul:
+    with pyfits.open(mask_file_fits) as hdul:
         data = hdul[0].data
 
         # Estrarre l'HDU primaria (dati e header)
@@ -27,4 +28,4 @@ def fits_to_ascii(mask_file_fits, mask_file_ascii):
             np.savetxt(f, data, fmt="%d", delimiter=" ")
 
 # Esegui la funzione specificando il file FITS di input e il file ASCII di output
-fits_to_ascii('/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/msk_55_4752313.fits', 'mask.dat')
\ No newline at end of file
+fits_to_ascii(mask_file_fits, mask_file_ascii)
\ No newline at end of file
diff --git a/python/convertRoot2Fits.py b/python/convertRoot2Fits.py
index ac5a2ae8ac5d198ae187f7334056d7c36f1a1b6b..aa2e3b001c1ffff80f8e86358c7b98146e471740 100644
--- a/python/convertRoot2Fits.py
+++ b/python/convertRoot2Fits.py
@@ -85,12 +85,11 @@ def generate_fits(energy, theta_deg, phi_deg):
             pyfits.Column(name='Event_time', format='1D', unit='ns', array=t_TI[sorting])
             ])
 
-        tbhdu.header.set('EXTNAME', 'EVENTS', 'Name of this binary table extension')
+        tbhdu.header.set('EXTNAME', 'EVENTS', 'Alfonso Pisapia')
 
         hdulist = pyfits.HDUList([prhdu, tbhdu])
 
         output_dir = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/fits"
-
         if not os.path.exists(output_dir):
             os.makedirs(output_dir)
 
diff --git a/python/data.py b/python/data.py
index 3f0c28217a745c24fc8bf2ba209b0ef05b371710..49c871b9485e68d4a060c0e3abf0064cc6b5de92 100644
--- a/python/data.py
+++ b/python/data.py
@@ -1,11 +1,48 @@
 import os
 import numpy as np
 from multiprocessing import Pool
-import astropy.io.fits as fits
+import astropy.io.fits as pyfits
 
 from noisy import add_noise_X, add_noise_S
 
 
+def write_fits_dep(energy, theta, phi, type, en_dep_noisy, en_dep):
+    
+    # Write FITS file
+    # "Null" primary array
+    prhdu = pyfits.PrimaryHDU()
+    
+    # Extension
+    tbhdu = pyfits.BinTableHDU.from_columns([
+        pyfits.Column(name='En_dep_Noise', format='1D', unit='keV', array = en_dep_noisy),
+        pyfits.Column(name='En_dep', format='1D', unit='keV', array = en_dep)
+        ])
+    
+    tbhdu.header['EXTNAME'] = 'EVENTS'
+    tbhdu.header['TELESCOP'] = 'THESEUS'
+    tbhdu.header['INSTRUME'] = 'XGIS'
+    tbhdu.header['COMMENT'] = "Simulated energy deposits with noise"
+    tbhdu.header['TUNIT1'] = "keV" 
+    tbhdu.header['TYPE'] = type
+    tbhdu.header['ENERGY'] = energy
+    tbhdu.header['THETA'] = theta
+    tbhdu.header['PHI'] = phi
+    tbhdu.header['COMMENT'] = "Alfonso Pisapia"
+    
+    hdulist = pyfits.HDUList([prhdu, tbhdu])
+    
+    fits_dep_dir = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/fits_dep"
+    if not os.path.exists(fits_dep_dir):
+        os.makedirs(fits_dep_dir)
+        
+    file_name = f"{type}_en_dep_{energy:.1f}_{theta}_{phi}.fits"
+    
+    output_file = os.path.join(fits_dep_dir, file_name)
+    hdulist.writeto(output_file, overwrite=True)
+    
+    return file_name
+    
+
 # Funzione che prende in input un singolo file FITS da processare.
 def get_data(files):
     # Estrazione di energia, theta e phi dal nome del file
@@ -17,7 +54,7 @@ def get_data(files):
     phi = float(name_parts[3])
     
     # Apertura del file fits e lettura dei dati
-    with fits.open(files) as hdul:
+    with pyfits.open(files) as hdul:
         data = hdul[1].data
         tot_events = len(data)
         scint_id_col = data['Scint_ID']
@@ -29,42 +66,25 @@ def get_data(files):
         eventi_S = tot_events - eventi_X
         ratio_X = eventi_X/tot_events
         ratio_S = eventi_S/tot_events
-        
-        X_en_dep_noisy = [add_noise_X(X_dep) for X_dep in X_en_dep]
+
+        X_en_dep_noisy = [add_noise_X(X_dep) for X_dep in X_en_dep] # list comprehension di Python, una struttura compatta che consente di applicare una funzione a ciascun elemento di un array o di una lista, creando direttamente un nuovo array con i risultati.
         S_en_dep_noisy = [add_noise_S(S_dep) for S_dep in S_en_dep]
-        
-    return energy, ratio_X, ratio_S, theta, phi, X_en_dep, S_en_dep
+
+    return energy, ratio_X, ratio_S, theta, phi, X_en_dep_noisy, S_en_dep_noisy, X_en_dep, S_en_dep
+
 
 def write_results(file_dat, results):
-    
-    npy_dir = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/npy"
-    npy_noise_dir = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/npy_noise"
-    if not os.path.exists(npy_dir):
-        os.makedirs(npy_dir)
-    if not os.path.exists(npy_noise_dir):
-        os.makedirs(npy_noise_dir)
-    
+
     with open(file_dat, "w") as f:
-        for energy, ratio_X, ratio_S, theta, phi, X_en_dep, S_en_dep in results:
-            # Salva l'array en_dep in un file separato, e salva tutto in una cartella, Smisto i dati tra X ed S
-            X_npy_file = f"X_en_dep_{energy:.1f}_{theta}_{phi}.npy"
-            S_npy_file = f"S_en_dep_{energy:.1f}_{theta}_{phi}.npy"
+        for energy, ratio_X, ratio_S, theta, phi, X_en_dep_noisy, S_en_dep_noisy, X_en_dep, S_en_dep in results:
+                        
+            X_fits = write_fits_dep(energy, theta, phi, 'X', X_en_dep_noisy, X_en_dep)
+            S_fits = write_fits_dep(energy, theta, phi, 'S', S_en_dep_noisy, S_en_dep)
             
-            X_en_dep_file = os.path.join(npy_dir, X_npy_file)
-            S_en_dep_file = os.path.join(npy_dir, S_npy_file)
-            
-            np.save(X_en_dep_file, X_en_dep)
-            np.save(S_en_dep_file, S_en_dep)
-            
-            f.write(f"{energy:.1f}\t{ratio_X:.3f}\t{ratio_S:.3f}\t{theta}\t{phi}\t{X_npy_file}\t{S_npy_file}\n")
+            f.write(f"{energy:.1f}\t{ratio_X:.3f}\t{ratio_S:.3f}\t{theta}\t{phi}\t{X_fits}\t{S_fits}\n")
+
+
 
-    # Add noise to Energy Depoists Files and save in another folder
-    npy_noise_dir = "/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/npy_noise"
-    if not os.path.exists(npy_noise_dir):
-        os.makedirs(npy_noise_dir)
-    
-    add_noise_X()
-    add_noise_S()
 
 # Estrae i dati, processa in parallelo tutti i file .fits presenti nella folder, usa le due funzioni già definite
 def data_estraction(file_dat):
diff --git a/python/noisy.py b/python/noisy.py
index 7e70bfe1f8f96ff870ff52b4dc4f93058445380c..733844ec873c7baec280a9cc9990236ec6d5b0c0 100644
--- a/python/noisy.py
+++ b/python/noisy.py
@@ -2,72 +2,39 @@ import os
 import numpy as np
 import matplotlib.pyplot as plt
 
-
+# ! check riccardo
 def add_noise_X(input):
     
-    
-    
-    w = 3.66 # eV/e-
-    fano_factor = 0.125 # for semiconductor detectors
+    w = 3.66                                    # eV/e-
+    fano_factor = 0.125                         # for semiconductor detectors
     sigma_fano = np.sqrt(fano_factor*input/w)   # keV*(e-)/eV -> e-rms
-    sigma_el = 30.0 # e- rms in termini di devizaioni standard
+    sigma_el = 30.0                             # e-rms in termini di devizaioni standard
     
-    variance = sigma_fano**2 + sigma_el**2  # Varianza della gaussiana
+    variance = sigma_fano**2 + sigma_el**2      # Varianza della gaussiana
     std_row = np.sqrt(variance)
-    std = (std_row*3.66)/1000     # (e-rms)*eV/(e-rms) --> keV
+    std = (std_row*3.66)/1000                   # (e-rms)*eV/(e-rms) --> keV
 
     # Estrai un valore campionato dalla distribuzione gaussiana
     output = np.random.normal(loc=input, scale=std)
-    #print(std)
-    #print("Valore estratto dalla distribuzione gaussiana:", output)
-    
-    
-    os.chdir("/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/npy")
-    array = np.load("X_en_dep_2.0_0.0_0.0.npy")
-    #print(array)
-
-    dep = [add_noise(input) for input in array] # list comprehension di Python, una struttura compatta che consente di applicare una funzione a ciascun elemento di un array o di una lista, creando direttamente un nuovo array con i risultati.
-
-
-
-
-    X_npy_noise_file = "X_en_dep_noy_2.0_0.0_0.0.npy"
-    X_en_dep_noise_file = os.path.join(npy_noise_dir, X_npy_noise_file)
-
-    new = np.save(X_en_dep_noise_file, dep)
-
-    loaded_dep = np.load(X_en_dep_noise_file)
-    print("Contenuto del nuovo file .npy con rumore aggiunto:")
-    print(loaded_dep)
     
-    
-
-
-
+    return output
 
 def add_noise_S(input):
     
-    light_efficiency = 25 # e-/keV
+    light_efficiency = 25                       # e-/keV
     sigma_stat = input*light_efficiency
-    sigma_el = 30.0 # conto due volte perche ho due sdd
+    sigma_el = 30.0                             # conto due volte perche ho due sdd
     
     variance = sigma_stat**2 + 2*sigma_el**2
-    
-    std = np.sqrt(variance)
+    std = np.sqrt(variance)/1000
     
     # Estrai un valore campionato dalla distribuzione gaussiana
     output = np.random.normal(loc=input, scale=std)
-    #print(std)
-    #print("Valore estratto dalla distribuzione gaussiana:", output)
-
-
+    
     return output
     
 
 
-
-
-
     # # PLOT
     # # Genera i valori per la curva gaussiana
     # x = np.linspace(input - 4*std, input + 4*std, 1000)
diff --git a/python/rmf.py b/python/rmf.py
index 810bee27c03d7dda71e8e432fdc5647436f1460e..502770ea06ea085bec1319c7ac96f27e47d712ab 100644
--- a/python/rmf.py
+++ b/python/rmf.py
@@ -26,6 +26,7 @@ def create_matrix_header(extension):
     extension.header['RMFVERSN'] = '1992A'
     extension.header['HDUVERS1'] = '1.0.0'
     extension.header['HDUVERS2'] = '1.3.0'
+    extension.header['COMMENT'] = "Alfonso Pisapia"
     
     
 def create_ebounds_header(extension):
@@ -49,48 +50,51 @@ def create_ebounds_header(extension):
 
 def estract_row(en_dep_file, bins):
     
-    en_dep = np.load(en_dep_file)
-    lenght = en_dep.size
-    
-    counts, bin_edges = np.histogram(en_dep, bins=bins)
-    counts_norm = counts/lenght
-    
-    print(counts)
-    print(counts_norm)
-    
-    n_grp = 0
-    f_chan = []
-    n_chan = []
+    with pyfits.open(en_dep_file) as hdul:
+        data = hdul[1].data
+        en_dep_noise = data['En_dep_Noise']
+        lenght = len(data)
+        
+        counts, bin_edges = np.histogram(en_dep_noise, bins=bins)
+        counts_norm = counts/lenght
+        
+        print(counts)
+        print(counts_norm)
+        
+        n_grp = 0
+        f_chan = []
+        n_chan = []
 
-    # Controlla i gruppi di valori consecutivi non nulli
-    in_group = False  # Stato per controllare se siamo all'interno di un gruppo, booleano
-    group_start = None  # Per memorizzare l'inizio del gruppo, intero, noen= senza valore
+        # Controlla i gruppi di valori consecutivi non nulli
+        in_group = False  # Stato per controllare se siamo all'interno di un gruppo, booleano
+        group_start = None  # Per memorizzare l'inizio del gruppo, intero, noen= senza valore
 
-    # Il ciclo scorre ogni valore dell'array counts_norm e controlla se è maggiore di zero (cioè non nullo).
-    for i in range(len(counts_norm)):
-        if counts_norm[i] > 0:
-            if not in_group:  # se non sono gia in un gruppo svolgi i seguenti # ! questi comandi li esegue solo per i valori iniziali di ogni gruppo
-                in_group = True # apro un nuovo gruppo
-                group_start = i  # Memorizza l'indice di inizio del gruppo
-                f_chan.append(i)  # Aggiungi l'indice di inizio al vettore f_chan
-                n_grp += 1  # Incrementa il numero di gruppi
-        else:
-            if in_group:  # Termina il gruppo corrente # ! qui esegue solo al primo zero che trova, se ne trova uno consecutivo non esegue perche trova in_group falso
-                in_group = False
-                group_length = i - group_start  # Calcola la lunghezza del gruppo
-                n_chan.append(group_length)  # Aggiungi la lunghezza del gruppo a n_chan
+        # Il ciclo scorre ogni valore dell'array counts_norm e controlla se è maggiore di zero (cioè non nullo).
+        for i in range(len(counts_norm)):
+            if counts_norm[i] > 0:
+                if not in_group:  # se non sono gia in un gruppo svolgi i seguenti # ! questi comandi li esegue solo per i valori iniziali di ogni gruppo
+                    in_group = True # apro un nuovo gruppo
+                    group_start = i  # Memorizza l'indice di inizio del gruppo
+                    f_chan.append(i)  # Aggiungi l'indice di inizio al vettore f_chan
+                    n_grp += 1  # Incrementa il numero di gruppi
+            else:
+                if in_group:  # Termina il gruppo corrente # ! qui esegue solo al primo zero che trova, se ne trova uno consecutivo non esegue perche trova in_group falso
+                    in_group = False
+                    group_length = i - group_start  # Calcola la lunghezza del gruppo
+                    n_chan.append(group_length)  # Aggiungi la lunghezza del gruppo a n_chan
 
-    # Controlla se l'ultimo gruppo arriva fino alla fine dell'array
-    if in_group:  # se è true esegue
-        n_chan.append(len(counts_norm) - group_start)
-    
-    return n_grp, f_chan, n_chan, counts_norm       # row_matrix = counts_norm
+        # Controlla se l'ultimo gruppo arriva fino alla fine dell'array
+        if in_group:  # se è true esegue
+            n_chan.append(len(counts_norm) - group_start)
+        
+        return n_grp, f_chan, n_chan, counts_norm       # row_matrix = counts_norm
 
 
-def rmf_file(energy, type, en_dep_file_filt, theta, phi):
+def rmf_file(type, energy, en_dep_file_filt, theta, phi):
+    
+    os.chdir('/home/alfonso/Scrivania/THESEUS/xgis_m7-main/fits_dep')
+    
     try:
-        os.chdir("/home/alfonso/Scrivania/THESEUS/xgis_m7-main/python/npy")
-        
         n_grp_col = []
         f_chan_col = []
         n_chan_col = []
@@ -111,10 +115,10 @@ def rmf_file(energy, type, en_dep_file_filt, theta, phi):
             n_chan_col.append(n_chan)
             row_matrix_col.append(row_matrix)
             
-        print(f"n_grp: {n_grp_col}")
-        print(f"f_chan: {f_chan_col}")
-        print(f"n_chan: {n_chan_col}")
-        print(f"row_matrix: {row_matrix_col}")        
+        # print(f"n_grp: {n_grp_col}")
+        # print(f"f_chan: {f_chan_col}")
+        # print(f"n_chan: {n_chan_col}")
+        # print(f"row_matrix: {row_matrix_col}")        
         
         # ! *************************************************************************************************************
         
diff --git a/python/zero.CANCELLA.py b/python/zero.CANCELLA.py
deleted file mode 100644
index abd69086dae30b04a6a88310c486a1aa0efa50ed..0000000000000000000000000000000000000000
--- a/python/zero.CANCELLA.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# Nome del file da leggere
-file_path = "mask.dat"
-
-# Apri il file in modalità lettura
-with open(file_path, 'r') as file:
-    # Itera su ogni riga del file
-    for line_num, line in enumerate(file, start=1):
-        # Rimuovi eventuali spazi vuoti ai bordi e dividi la riga in elementi
-        elements = line.strip().split()
-        
-        # Conta il numero di '0' nella riga corrente
-        zero_count = elements.count('0')
-        
-        # Stampa il numero di zeri per la riga corrente
-        print(f"Riga {line_num}: {zero_count} zeri")
-
diff --git a/rmf/Xrmf_0.0_0.0.rmf b/rmf/Xrmf_0.0_0.0.rmf
index 870bb5e09b0d4d1fa8bef4ffd825c04f8339f3fa..e5ec9a5c9a3998a2e4bb12d658b95c181b7fc47c 100644
Binary files a/rmf/Xrmf_0.0_0.0.rmf and b/rmf/Xrmf_0.0_0.0.rmf differ
diff --git a/rmf/Xrmf_0.0_180.0.rmf b/rmf/Xrmf_0.0_180.0.rmf
index f8029000e206ecdd1f78f4e91a8a20281d0244e5..d633caa260778d81ef014846cb8460784b4bbee9 100644
Binary files a/rmf/Xrmf_0.0_180.0.rmf and b/rmf/Xrmf_0.0_180.0.rmf differ
diff --git a/rmf/Xrmf_0.0_270.0.rmf b/rmf/Xrmf_0.0_270.0.rmf
index ac69a7aeb08de2fb44c8d0a8070282e2f6eee26a..8a3675f781b1e04c4dc0b47155304a1020d3445c 100644
Binary files a/rmf/Xrmf_0.0_270.0.rmf and b/rmf/Xrmf_0.0_270.0.rmf differ
diff --git a/rmf/Xrmf_0.0_360.0.rmf b/rmf/Xrmf_0.0_360.0.rmf
index 870bb5e09b0d4d1fa8bef4ffd825c04f8339f3fa..304073ae07b63a659ade35ff03340e16cf002bbf 100644
Binary files a/rmf/Xrmf_0.0_360.0.rmf and b/rmf/Xrmf_0.0_360.0.rmf differ
diff --git a/rmf/Xrmf_0.0_90.0.rmf b/rmf/Xrmf_0.0_90.0.rmf
index 901d6c06efd12f419bd8fe03c0c0bed5f8c82af7..4d0f74ae2f455cf76f66a61269afaa123167cd8b 100644
Binary files a/rmf/Xrmf_0.0_90.0.rmf and b/rmf/Xrmf_0.0_90.0.rmf differ
diff --git a/rmf/Xrmf_30.0_0.0.rmf b/rmf/Xrmf_30.0_0.0.rmf
index 5c6f937604b8972eb88f7b0dde64b927bf971f37..a0c453f20fb6b05ba6065d3473574fdc47352944 100644
Binary files a/rmf/Xrmf_30.0_0.0.rmf and b/rmf/Xrmf_30.0_0.0.rmf differ
diff --git a/rmf/Xrmf_30.0_180.0.rmf b/rmf/Xrmf_30.0_180.0.rmf
index 5e20690d68d575beb7ed82977b0819508dbd7b23..5d1edbea1a0a6226e7c670cba055315a7b1f1fd7 100644
Binary files a/rmf/Xrmf_30.0_180.0.rmf and b/rmf/Xrmf_30.0_180.0.rmf differ
diff --git a/rmf/Xrmf_30.0_270.0.rmf b/rmf/Xrmf_30.0_270.0.rmf
index 56157b82d94ecae6ed8c58235400849da785c377..398f5c01c002eb6e31b3105b8f00485e030af155 100644
Binary files a/rmf/Xrmf_30.0_270.0.rmf and b/rmf/Xrmf_30.0_270.0.rmf differ
diff --git a/rmf/Xrmf_30.0_360.0.rmf b/rmf/Xrmf_30.0_360.0.rmf
index 5c6f937604b8972eb88f7b0dde64b927bf971f37..e41d85966b478d644a3e350b6c33ce528d858763 100644
Binary files a/rmf/Xrmf_30.0_360.0.rmf and b/rmf/Xrmf_30.0_360.0.rmf differ
diff --git a/rmf/Xrmf_30.0_90.0.rmf b/rmf/Xrmf_30.0_90.0.rmf
index 4a6f0745e46ddde4b95fb44288cb2013298d96e9..70db773ac3ecb6972a03c9a4fa91cec0b5d1c7ec 100644
Binary files a/rmf/Xrmf_30.0_90.0.rmf and b/rmf/Xrmf_30.0_90.0.rmf differ
diff --git a/rmf/Xrmf_60.0_0.0.rmf b/rmf/Xrmf_60.0_0.0.rmf
index c5a6c1764cc786b859140588a601794027a90ec6..2f946003115f8dd1fdaa906ebb96ef4fca7d8c43 100644
Binary files a/rmf/Xrmf_60.0_0.0.rmf and b/rmf/Xrmf_60.0_0.0.rmf differ
diff --git a/rmf/Xrmf_60.0_180.0.rmf b/rmf/Xrmf_60.0_180.0.rmf
index be69c655c6a48a72471eb16cd6777ec21ae8277d..e453e8d817bf9400aebac245c4fbd8d99d88fe89 100644
Binary files a/rmf/Xrmf_60.0_180.0.rmf and b/rmf/Xrmf_60.0_180.0.rmf differ
diff --git a/rmf/Xrmf_60.0_270.0.rmf b/rmf/Xrmf_60.0_270.0.rmf
index 919dff5e7cf20abeaf41aefb0e57919be7c55cad..6085246e3b9c755955fb2cfcce3384258d8b7bcc 100644
Binary files a/rmf/Xrmf_60.0_270.0.rmf and b/rmf/Xrmf_60.0_270.0.rmf differ
diff --git a/rmf/Xrmf_60.0_360.0.rmf b/rmf/Xrmf_60.0_360.0.rmf
index c5a6c1764cc786b859140588a601794027a90ec6..b2942df5f54ba9ac839aff84d8c9e7ac2a9ef745 100644
Binary files a/rmf/Xrmf_60.0_360.0.rmf and b/rmf/Xrmf_60.0_360.0.rmf differ
diff --git a/rmf/Xrmf_60.0_90.0.rmf b/rmf/Xrmf_60.0_90.0.rmf
index 5f45958bce592495bcc70a658dac13d2da2ab218..90b0f46997468f8d6a5c21896a44137abb20370c 100644
Binary files a/rmf/Xrmf_60.0_90.0.rmf and b/rmf/Xrmf_60.0_90.0.rmf differ
diff --git a/rmf/Xrmf_90.0_0.0.rmf b/rmf/Xrmf_90.0_0.0.rmf
index 9884bf6971dd2e2e50f26542535dfaad88775962..91d8559c6a5fd34dbf314229c973b56121df8473 100644
Binary files a/rmf/Xrmf_90.0_0.0.rmf and b/rmf/Xrmf_90.0_0.0.rmf differ
diff --git a/rmf/Xrmf_90.0_180.0.rmf b/rmf/Xrmf_90.0_180.0.rmf
index d3fe25e6054096106976054b291b21948b168153..f9ae08a34406de4209707e47a59ed952371abe98 100644
Binary files a/rmf/Xrmf_90.0_180.0.rmf and b/rmf/Xrmf_90.0_180.0.rmf differ
diff --git a/rmf/Xrmf_90.0_270.0.rmf b/rmf/Xrmf_90.0_270.0.rmf
index 709775d06274e2a73bed72fad97bddb113b81d67..a6b1a87d9e7d0deb438209929e8b768760e64e5c 100644
Binary files a/rmf/Xrmf_90.0_270.0.rmf and b/rmf/Xrmf_90.0_270.0.rmf differ
diff --git a/rmf/Xrmf_90.0_360.0.rmf b/rmf/Xrmf_90.0_360.0.rmf
index 9884bf6971dd2e2e50f26542535dfaad88775962..91d8559c6a5fd34dbf314229c973b56121df8473 100644
Binary files a/rmf/Xrmf_90.0_360.0.rmf and b/rmf/Xrmf_90.0_360.0.rmf differ
diff --git a/rmf/Xrmf_90.0_90.0.rmf b/rmf/Xrmf_90.0_90.0.rmf
index a4a565f878879b9b1ba838d099f4cf7061095a0b..a86f0ff010d2cb7830a19bbff17a7e35a548648b 100644
Binary files a/rmf/Xrmf_90.0_90.0.rmf and b/rmf/Xrmf_90.0_90.0.rmf differ
diff --git a/xgis_M7 b/xgis_M7
index 7c7706bbcc79ec7141751625e5ddc9cc7d80623c..a9034cd29db548472ca19631b1aa8656344a070a 100755
Binary files a/xgis_M7 and b/xgis_M7 differ