Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 44 additions & 40 deletions mcxtrace-comps/contrib/Attenuating_mask.comp
Original file line number Diff line number Diff line change
Expand Up @@ -52,58 +52,62 @@ SHARE

DECLARE
%{
double rho;
t_Table att_table;
double rho;
t_Table att_table;
%}

INITIALIZE
%{
int status=0;
if((status=Table_Read(&(att_table),att_file,0))==-1){ // load the attenuation crossection
fprintf(stderr,"Error: Could not parse file \"%s\" in COMP %s\n",att_file,NAME_CURRENT_COMP); exit(-1);
}
/* checking the header for retrieving density */
char **header_parsed;
header_parsed = Table_ParseHeader(att_table.header,"rho",NULL);
if(header_parsed[0]){rho = strtod(header_parsed[0],NULL);}
else{fprintf(stderr,"Warning(%s): %s not found in header of %s, set to 1\n",NAME_CURRENT_COMP,"rho",att_file); rho = 1;}
printf("Rho = %1.3f.\n\n",rho);
int status = 0;
if ((status = Table_Read (&(att_table), att_file, 0)) == -1) { // load the attenuation crossection
fprintf (stderr, "Error: Could not parse file \"%s\" in COMP %s\n", att_file, NAME_CURRENT_COMP);
exit (-1);
}
/* checking the header for retrieving density */
char** header_parsed;
header_parsed = Table_ParseHeader (att_table.header, "rho", NULL);
if (header_parsed[0]) {
rho = strtod (header_parsed[0], NULL);
} else {
fprintf (stderr, "Warning(%s): %s not found in header of %s, set to 1\n", NAME_CURRENT_COMP, "rho", att_file);
rho = 1;
}
printf ("Rho = %1.3f.\n\n", rho);
%}

TRACE
%{
int hit_sample = 0;
double d0, d1;

hit_sample = box_intersect(&d0, &d1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth); // check intersection with the component

if(hit_sample){
PROP_DL(d0);
double cosleftx = cos(2*PI*x/blocks_xdist);
double cosrightx = cos(PI*blocks_xwidth/blocks_xdist);
double coslefty = cos(2*PI*y/blocks_ydist);
double cosrighty = cos(PI*blocks_yheight/blocks_ydist);
double k = sqrt(kx*kx+ky*ky+kz*kz);
double E = K2E*k;
if(holed_mask==0){ // mask composed of blocking disks
if((cosleftx>cosrightx || cosleftx==cosrightx) && (coslefty>cosrighty || coslefty==cosrighty)){ //absorbed
double mul = 1e2*(d1-d0)*rho*Table_Value(att_table,E,5);
p*=exp(-mul);
} //else transmitted
}
else{ // mask composed of apertures on a grating
if(cosleftx<cosrightx || coslefty<cosrighty){ //absorbed
double mul = 1e2*(d1-d0)*rho*Table_Value(att_table,E,5);
p*=exp(-mul);
} //else transmitted
}
PROP_DL(d1-d0);
}
int hit_sample = 0;
double d0, d1;

hit_sample = box_intersect (&d0, &d1, x, y, z, kx, ky, kz, xwidth, yheight, zdepth); // check intersection with the component

if (hit_sample) {
PROP_DL (d0);
double cosleftx = cos (2 * PI * x / blocks_xdist);
double cosrightx = cos (PI * blocks_xwidth / blocks_xdist);
double coslefty = cos (2 * PI * y / blocks_ydist);
double cosrighty = cos (PI * blocks_yheight / blocks_ydist);
double k = sqrt (kx * kx + ky * ky + kz * kz);
double E = K2E * k;
if (holed_mask == 0) { // mask composed of blocking disks
if ((cosleftx > cosrightx || cosleftx == cosrightx) && (coslefty > cosrighty || coslefty == cosrighty)) { // absorbed
double mul = 1e2 * (d1 - d0) * rho * Table_Value (att_table, E, 5);
p *= exp (-mul);
} // else transmitted
} else { // mask composed of apertures on a grating
if (cosleftx < cosrightx || coslefty < cosrighty) { // absorbed
double mul = 1e2 * (d1 - d0) * rho * Table_Value (att_table, E, 5);
p *= exp (-mul);
} // else transmitted
}
PROP_DL (d1 - d0);
}
%}

MCDISPLAY
%{
box(0,0,0,xwidth,yheight,zdepth,0, 0, 1, 0);
box (0, 0, 0, xwidth, yheight, zdepth, 0, 0, 1, 0);
%}

END
Loading
Loading