Commit 0cb3deda authored by Eoin Clerkin's avatar Eoin Clerkin
Browse files

Static test for media.geo

Semi-automated static check for media.geo file.
Compares atomic number against the atomic mass.
Compares relative amounts for composite materials.
Output human readable names to help spotting of name and component mismatches.

Includes bash script which just runs awk with correct media.geo file and an ASCII table of elements.

Test is added to the pipeline
parent 3c7dbc73
......@@ -79,3 +79,21 @@ FileFormatCheck:
- ci_scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
- git fetch upstream
- ci_scripts/check-file-format.sh upstream
FileMediaCheck:
stage: checkFormat
image: alpine
tags:
- docker
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_PROJECT_PATH == "CbmSoft/cbmroot_geometry" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
script:
# Get the upstream repository manually. I did not find any other way to have it for
# comparison
- apk update && apk add git bash file gawk
- ci_scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
- git fetch upstream
- gawk -f ci_scripts/static_check.awk media.geo
1 Hydrogen H 1.00794
2 Helium He 4.0026
3 Lithium Li 6.941
4 Beryllium Be 9.012182
5 Boron B 10.811
6 Carbon C 12.011
7 Nitrogen N 14.00674
8 Oxygen O 15.9994
9 Fluorine F 18.9984032
10 Neon Ne 20.1797
11 Sodium Na 22.989768
12 Magnesium Mg 24.3050
13 Aluminum Al 26.981539
14 Silicon Si 28.0855
15 Phosphorus P 30.973762
16 Sulfur S 32.066
17 Chlorine Cl 35.4527
18 Argon Ar 39.948
19 Potassium K 39.0983
20 Calcium Ca 40.078
21 Scandium Sc 44.955910
22 Titanium Ti 47.867
23 Vanadium V 50.9415
24 Chromium Cr 51.9961
25 Manganese Mn 54.93805
26 Iron Fe 55.845
27 Cobalt Co 58.93320
28 Nickel Ni 58.6934
29 Copper Cu 63.546
30 Zinc Zn 65.39
31 Gallium Ga 69.723
32 Germanium Ge 72.61
33 Arsenic As 74.92159
34 Selenium Se 78.96
35 Bromine Br 79.904
36 Krypton Kr 83.80
37 Rubidium Rb 85.4678
38 Strontium Sr 87.62
39 Yttrium Y 88.90585
40 Zirconium Zr 91.224
41 Niobium Nb 92.90638
42 Molybdenum Mo 95.94
43 Technetium Tc 97.907215
44 Ruthenium Ru 101.07
45 Rhodium Rh 102.90550
46 Palladium Pd 106.42
47 Silver Ag 107.8682
48 Cadmium Cd 112.41
49 Indium In 114.818
50 Tin Sn 118.710
51 Antimony Sb 121.760
52 Tellurium Te 127.60
53 Iodine I 126.90447
54 Xenon Xe 131.29
55 Cesium Cs 132.90543
56 Barium Ba 137.27
57 Lanthanum La 138.9055
58 Cerium Ce 140.115
59 Praeseodymium Pr 140.90765
60 NeoDymium Nd 144.24
61 Promethium Pm 144.912745
62 Samarium Sm 150.36
63 Europium Eu 151.965
64 Gadolinium Gd 157.25
65 Terbium Tb 158.92534
66 Dysprosium Dy 162.50
67 Holmium Ho 164.93032
68 Erbium Er 167.26
69 Thulium Tm 168.93421
70 Ytterbium Yb 173.04
71 Lutetium Lu 174.967
72 Hafnium Hf 178.49
73 Tantalum Ta 180.9479
74 Tungsten W 183.84
75 Rhenium Re 186.207
76 Osmium Os 190.23
77 Iridium Ir 192.217
78 Platinum Pt 195.08
79 Gold Au 196.96654
80 Mercury Hg 200.59
81 Thallium Tl 204.3833
82 Lead Pb 207.2
83 Bismuth Bi 208.98037
84 Polonium Po 208.982415
85 Astatine At 209.987131
86 Radon Rn 222.017570
87 Francium Fr 223.019731
88 Radium Ra 226.025402
89 Actinium Ac 227.027747
90 Thorium Th 232.0381
91 Protactinium Pa 231.03588
92 Uranium U 238.0289
93 Neptunium Np 237.048166
94 Plutonium Pu 244.064197
95 Americium Am 243.061372
96 Curium Cm 247.070346
97 Berkelium Bk 247.070298
98 Californium Cf 251.079579
99 Einsteinium Es 252.08297
100 Fermium Fm 257.095096
101 Mendelevium Md 258.098427
102 Nobelium No 259.1011
103 Lawrencium Lr 262.1098
104 Rutherfordium Rf 261.1089
105 Hahnium Ha 262.1144
106 Seaborgium Sg 263.1186
107 Nielsborium Ns 262.1231
108 Hassium Hs 265.1306
109 Meitnerium Mt 266.1378
#!/usr/bin/gawk -f
#
# Static test to check the atomic number against the atomic mass for inclusions in the geometry media.geo file. Output may be used to spot typos and other human errors.
#
# Author E.Clerkin
# COPYRIGHT: FAIR GMBH 2020
#
#
# Useage: awk -f static_check.awk media.geo
# Must include LIST_ELEMENTS file in same directory.
function abs(x){return (x>=0) ? x : -x}
BEGIN{
ACCEPTABLE_ERROR=0.01 # 1 % ERROR TOLERANCE FOR STATIC CHECK.
FAIL=0; # Flag for determining success. If any check fails then this value is changed.
while(getline < "ci_scripts/LIST_ELEMENTS"){
ELEMENT_NAME[$1]=$2;
ELEMENT_SYMBOL[$1]=$3;
ELEMENT_MASS[$1]=$4;
# Index $1 is the Atomic Number of the Element
};
};
{
delete datum;
FS="[\t ]*"; # Spaces and tags as field seperators in media.geo
for (i = 1; i<=NF; i++)datum[i]=$i; # Loading in a line from media.geo fle to make it easy to work with.
RELATIVE_SUM=0;
content_by="weight"; # The relative content is by number of each atom or by relative weight of each atom.
if($1!="//" && $1!="0" && $1!="1" && $1!="" ){ # Excluding lines that are not first line in definition of medium
print "############################################################################################################";
getline # Obtaining information from subsequent line for additional flags.
sensflag=$2
fldflag=$3
fld=$4
epsil=$5
declare sensor;
if(sensflag==0) # Is the material active?
{
sensor="PASSIVE";
}
else
{
sensor=" ACTIVE";
}
print datum[1], sensor; # Material and Active status.
if(datum[2]<0){
content_by="number" # Relative number
print "Containts by numer";
};
datum[2] = (datum[2]>0)? datum[2] : -1*datum[2]; # Making the NCOMP parameter always positive.
# NCOMP sign controlls the constitutes ratio definitions and is not needed for these tests.
printf "Number of constitutes: %d\n", datum[2]; # Datum[2] has integer value of number of elements.
for(i=1;i<=datum[2];++i){ # Skips throw each of the components.
printf "Atomic Number: %s\tAtomic Mass: %s\n", datum[2+i+datum[2]], datum[2+i]; # See https://fairroot.gsi.de/?q=node/34 for info regarding format ordering.
printf "AN[%d]=> %s : Mass = %s\n", datum[2+i+datum[2]], ELEMENT_NAME[strtonum(datum[2+i+datum[2]])], ELEMENT_MASS[strtonum(datum[2+i+datum[2]])];
# datum[2] is the number of components
# datum[2 + i] is subsequent component's atomic number
# datum[2 + i + datum[2]] is subsequenct component's atomic weight
# datum[2 + 2*datum[2] + 1] is the overall density of the material
# datum[3 + 2*datum[2] + i] is the subsequent relative amount of each compoment.
# printf "PAUSE: %s %s %s", datum[2+i], ELEMENT_MASS[strtonum(datum[2+i+datum[2]])], ERROR;
printf "1 MASS ENTERED %s \n", datum[2+i];
printf "2 ELEMENT MASS %s \n", ELEMENT_MASS[strtonum(datum[2+i+datum[2]])];
if ( length(datum[2+i])!=0 && length(ELEMENT_MASS[strtonum(datum[2+i+datum[2]])])!=0 ){
ERROR = abs( (datum[2+i] - ELEMENT_MASS[strtonum(datum[2+i+datum[2]])] )/datum[2+i])
};
if(datum[2]>1){ # Checks relatavant for more than one component.
if(content_by~"number"){ # When the elements are per their relative number.
printf "%s", ELEMENT_SYMBOL[strtonum(datum[2+i+datum[2]])];
printf "%s\n", datum[3 + 2*datum[2] + i];
CHEMISTRY[ELEMENT_SYMBOL[strtonum(datum[2+i+datum[2]])]]=datum[3 + 2*datum[2] + i];
};
if(content_by~"weight"){ # When the elements are per weight
printf "RELATIVE AMOUNT: %0.2f%% \n", 100*datum[3 + 2*datum[2] + i];
RELATIVE_SUM+=datum[3 + 2*datum[2] + i];
};
};
printf "ERROR IS %f \t", ERROR;
if (ERROR > ACCEPTABLE_ERROR) {
FAIL=1;
printf "CHECK FAILED\n\n"
} else {
printf "CHECK PASSED\n\n"
};
};
# Check if the amount of material adds up to 100%
if(datum[2]>1 && content_by~"weight"){
printf "TOTAL AMOUNT COUNT RELATIVE SUMS: %0.2f%% \t\t\t", 100*RELATIVE_SUM;
if (RELATIVE_SUM<=1+ACCEPTABLE_ERROR && RELATIVE_SUM>=1-ACCEPTABLE_ERROR ){
printf "CHECK PASSED! %s \n\n", RELATIVE_SUM;
}else{
printf "CHECK FAILED! %s \n\n", RELATIVE_SUM;
FAIL=1;
};
};
# Chemical Formula Attempt. For visual inspection by human.
if(datum[2]>1 && content_by~"number"){
printf "Contents by the number of atoms: \n"
for( ele in CHEMISTRY )printf "%s%s", ele, CHEMISTRY[ele];
# ELEMENT_SYMBOL[strtonum(datum[2+i+datum[2]])]
# CHEMISTRY[]
};
print " " # Spacing
delete CHEMISTRY;
};
}
END{
print "------------------------------------------------------------------------------------------------------------"
printf "STATIC TEST: "
if ( ! FAIL ) { printf "PASSED\n" }
if ( FAIL ) { printf "FAILED\n"; exit 1 }
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment