SND@LHC Software
Loading...
Searching...
No Matches
compareGeoFiles.py
Go to the documentation of this file.
1"""Compare two geofiles with or without the calibration constants."""
2
3from argparse import ArgumentParser
4
5import SndlhcGeo
6
7parser = ArgumentParser()
8parser.add_argument(
9 "-g1", "--geofile1", help="first geometry file: geo1", required=True
10)
11parser.add_argument(
12 "-g2", "--geofile2", help="second geometry file: geo2", required=True
13)
14parser.add_argument(
15 "--compare_calibration", help="compare calibration constants", action="store_true"
16)
17options = parser.parse_args()
18
19geo1 = SndlhcGeo.GeoInterface(options.geofile1)
20geo2 = SndlhcGeo.GeoInterface(options.geofile2)
21
22print("===========")
23if options.compare_calibration:
24 print("Run comparing the geo calibration constants")
25else:
26 print("Run WITHOUT comparing the geo calibration constants")
27
28calibration_subkeys = ["Loc", "RotPhi", "RotPsi", "RotTheta", "station", "DSTcor", "Shift"]
29detector_list = ["EmulsionDet", "Scifi", "MuFilter"]
30
31for detector in detector_list:
32 print("Running over", detector)
33 print(" Checking if geo1 elements exist in geo2")
34 for key in geo1.snd_geo[detector].keys():
35 if not options.compare_calibration:
36 if any(subkey in key for subkey in calibration_subkeys) and not detector=='EmulsionDet':
37 continue
38 if key not in geo2.snd_geo[detector].keys():
39 print(" ", key, "is missing from geo2")
40 print(" Checking if geo2 elements exist in geo1")
41 for key in geo2.snd_geo[detector].keys():
42 if not options.compare_calibration:
43 if any(subkey in key for subkey in calibration_subkeys) and not detector=='EmulsionDet':
44 continue
45 if key not in geo1.snd_geo[detector].keys():
46 print(" ", key, "is missing from geo1")
47
48 print(" Checking the values of the elements that exist in both files")
49 for key in geo1.snd_geo[detector].keys():
50 if not options.compare_calibration:
51 if any(subkey in key for subkey in calibration_subkeys) and not detector=='EmulsionDet':
52 continue
53 if (
54 key in geo2.snd_geo[detector].keys()
55 and abs(geo1.snd_geo[detector][key] - geo2.snd_geo[detector][key]) != 0
56 ):
57 print(
58 " ",
59 key,
60 "Different value detected! geo1:",
61 geo1.snd_geo[detector][key],
62 "geo2:",
63 geo2.snd_geo[detector][key],
64 )