Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cbmroot
Manage
Activity
Members
Labels
Plan
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computing
cbmroot
Commits
0c78dccb
Commit
0c78dccb
authored
1 year ago
by
Eoin Clerkin
Committed by
Sergey Gorbunov
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Apply clang-format
parent
a1f89303
No related branches found
No related tags found
1 merge request
!1815
Introduce total mass macro.
Pipeline
#29472
passed
1 year ago
Stage: build
Stage: package
Stage: verify
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
macro/geometry/total_mass.C
+154
-153
154 additions, 153 deletions
macro/geometry/total_mass.C
with
154 additions
and
153 deletions
macro/geometry/total_mass.C
+
154
−
153
View file @
0c78dccb
...
@@ -2,12 +2,14 @@
...
@@ -2,12 +2,14 @@
SPDX-License-Identifier: GPL-3.0-only
SPDX-License-Identifier: GPL-3.0-only
Authors: Eoin Clerkin [committer] */
Authors: Eoin Clerkin [committer] */
#include
<time.h>
#include
<stdlib.h>
#include
"TGeoManager.h"
#include
"TGeoManager.h"
#include
"TGeoNavigator.h"
#include
"TGeoNavigator.h"
#include
<time.h>
#include
<regex.h>
#include
<regex.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<string.h>
TGeoManager
*
gman
;
TGeoManager
*
gman
;
...
@@ -20,174 +22,173 @@ double tmp_den;
...
@@ -20,174 +22,173 @@ double tmp_den;
#define SAMPLING 100000000
#define SAMPLING 100000000
typedef
struct
node_list
{
typedef
struct
node_list
{
char
*
NAME
=
(
char
*
)
calloc
(
200
,
sizeof
(
char
));
// zero 200 characters
char
*
NAME
=
(
char
*
)
calloc
(
200
,
sizeof
(
char
));
// zero 200 characters
long
int
COUNT
=
0
;
long
int
COUNT
=
0
;
int
MATERIAL_ID
=
0
;
// Given by the TGeoManager
int
MATERIAL_ID
=
0
;
// Given by the TGeoManager
}
node_list
;
}
node_list
;
// find nodal number or return next free.
// find nodal number or return next free.
int
find_node
(
char
*
strname
,
node_list
*
NODE_COUNT
){
int
find_node
(
char
*
strname
,
node_list
*
NODE_COUNT
)
int
j
=
0
;
{
int
j
=
0
;
while
(
true
){
//printf("%d COMPARE %s to %s is %d\n", j, NODE_COUNT[j].NAME, strname, strcmp(NODE_COUNT[j].NAME,strname));
while
(
true
)
{
if
(
!*
NODE_COUNT
[
j
].
NAME
)
goto
not_allocated
;
//printf("%d COMPARE %s to %s is %d\n", j, NODE_COUNT[j].NAME, strname, strcmp(NODE_COUNT[j].NAME,strname));
if
(
!
strcmp
(
NODE_COUNT
[
j
].
NAME
,
strname
)){
if
(
!*
NODE_COUNT
[
j
].
NAME
)
goto
not_allocated
;
return
j
;
// If not yet allocated.
if
(
!
strcmp
(
NODE_COUNT
[
j
].
NAME
,
strname
))
{
};
return
j
;
// If not yet allocated.
j
++
;
};
if
(
j
==
NODE_MAX
)
fprintf
(
stderr
,
"WARNING: NODE_MAX EXCEEDED
\n
"
);
j
++
;
};
if
(
j
==
NODE_MAX
)
fprintf
(
stderr
,
"WARNING: NODE_MAX EXCEEDED
\n
"
);
};
not_allocated:
not_allocated:
return
j
;
return
j
;
}
}
void
total_mass
(
void
total_mass
(
int
output
=
2
)
int
output
=
2
{
){
// output as output controll variable
// output as output controll variable
// output = 0 debuging
// output = 0 debuging
// output = 1 (default) list out the global materials
// output = 1 (default) list out the global materials
// output = 2 total list of individual nodes
// output = 2 total list of individual nodes
int
NUM
=
SAMPLING
;
int
NUM
=
SAMPLING
;
node_list
NODE_COUNT
[
NODE_MAX
];
node_list
NODE_COUNT
[
NODE_MAX
];
strcpy
(
NODE_COUNT
[
0
].
NAME
,
"/cave_1"
);
strcpy
(
NODE_COUNT
[
0
].
NAME
,
"/cave_1"
);
char
strname
[
200
];
char
strname
[
200
];
char
NODE_PATH
[
200
];
char
NODE_PATH
[
200
];
char
ARRAY_PATH
[
20
][
40
];
char
ARRAY_PATH
[
20
][
40
];
double
TOTAL_MASS
=
0
,
SUM_DENSITY
=
0
;
double
TOTAL_MASS
=
0
,
SUM_DENSITY
=
0
;
TFile
file
(
"test.geo.root"
,
"READ"
);
TFile
file
(
"test.geo.root"
,
"READ"
);
file
.
GetListOfKeys
()
->
Print
();
file
.
GetListOfKeys
()
->
Print
();
gman
=
(
TGeoManager
*
)
file
.
Get
(
"FAIRGeom"
);
gman
=
(
TGeoManager
*
)
file
.
Get
(
"FAIRGeom"
);
if
(
gman
==
nullptr
)
gman
=
gGeoManager
;
if
(
gman
==
nullptr
)
gman
=
gGeoManager
;
TGeoNavigator
*
navig
=
gman
->
AddNavigator
();
TGeoNavigator
*
navig
=
gman
->
AddNavigator
();
int
i
=
0
,
j
=
0
,
k
=
0
;
int
i
=
0
,
j
=
0
,
k
=
0
;
int
NUMBER_OF_MATERIALS
=
gman
->
GetListOfMaterials
()
->
Last
()
->
GetUniqueID
();
int
NUMBER_OF_MATERIALS
=
gman
->
GetListOfMaterials
()
->
Last
()
->
GetUniqueID
();
long
int
MATERIAL_COUNT
[
100
];
long
int
MATERIAL_COUNT
[
100
];
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
MATERIAL_COUNT
[
i
]
=
0
;
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
MATERIAL_COUNT
[
i
]
=
0
;
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
Double_t
x
,
y
,
z
;
Double_t
x
,
y
,
z
;
// Full jpsi volume
// Full jpsi volume
/* double XMIN=-700, XMAX=700;
/* double XMIN=-700, XMAX=700;
double YMIN=-570, YMAX=540;
double YMIN=-570, YMAX=540;
double ZMIN=-100, ZMAX=1882;*/
double ZMIN=-100, ZMAX=1882;*/
//double ZMIN=-150, ZMAX=150;
//double ZMIN=-150, ZMAX=150;
// rich_v22a test
// rich_v22a test
double
XMIN
=-
265
,
XMAX
=
265
;
double
XMIN
=
-
265
,
XMAX
=
265
;
double
YMIN
=-
251
,
YMAX
=
251
;
double
YMIN
=
-
251
,
YMAX
=
251
;
double
ZMIN
=
110
,
ZMAX
=
335
;
double
ZMIN
=
110
,
ZMAX
=
335
;
if
(
output
==
2
)
printf
(
"RANDMAX IS %d
\n
Resolution in X, Y, Z is %e %e %e
\n
"
,
RAND_MAX
,
(
XMAX
-
XMIN
)
/
RAND_MAX
,
(
YMAX
-
YMIN
)
/
RAND_MAX
,
(
ZMAX
-
ZMIN
)
/
RAND_MAX
);
if
(
output
==
2
)
double
TOTAL_VOLUME
=
(
XMAX
-
XMIN
)
*
(
YMAX
-
YMIN
)
*
(
ZMAX
-
ZMIN
);
// in cm3 for m3 times 10^-6
printf
(
"RANDMAX IS %d
\n
Resolution in X, Y, Z is %e %e %e
\n
"
,
RAND_MAX
,
(
XMAX
-
XMIN
)
/
RAND_MAX
,
if
(
output
==
2
)
printf
(
"Total volume is %f m3
\n
"
,
(
double
)
TOTAL_VOLUME
/
1000000
);
(
YMAX
-
YMIN
)
/
RAND_MAX
,
(
ZMAX
-
ZMIN
)
/
RAND_MAX
);
double
TOTAL_VOLUME
=
(
XMAX
-
XMIN
)
*
(
YMAX
-
YMIN
)
*
(
ZMAX
-
ZMIN
);
// in cm3 for m3 times 10^-6
// I prevent rastoring bias when number of points is very large.
if
(
output
==
2
)
printf
(
"Total volume is %f m3
\n
"
,
(
double
)
TOTAL_VOLUME
/
1000000
);
// My range will be modified by the random resolution to avoid fixing the single grid.
XMIN
-=-
1
.
0
*
(
(
rand
()
/
RAND_MAX
)
*
((
XMAX
-
XMIN
)
/
RAND_MAX
)
);
// I prevent rastoring bias when number of points is very large.
XMAX
+=
(
(
rand
()
/
RAND_MAX
)
*
((
XMAX
-
XMIN
)
/
RAND_MAX
)
);
// My range will be modified by the random resolution to avoid fixing the single grid.
XMIN
-=
-
1
.
0
*
((
rand
()
/
RAND_MAX
)
*
((
XMAX
-
XMIN
)
/
RAND_MAX
));
YMIN
-=-
1
.
0
*
(
(
rand
()
/
RAND_MAX
)
*
((
YMAX
-
YMIN
)
/
RAND_MAX
)
);
XMAX
+=
((
rand
()
/
RAND_MAX
)
*
((
XMAX
-
XMIN
)
/
RAND_MAX
));
YMAX
+=
(
(
rand
()
/
RAND_MAX
)
*
((
YMAX
-
YMIN
)
/
RAND_MAX
)
);
YMIN
-=
-
1
.
0
*
((
rand
()
/
RAND_MAX
)
*
((
YMAX
-
YMIN
)
/
RAND_MAX
));
ZMIN
-=-
1
.
0
*
(
(
rand
()
/
RAND_MAX
)
*
((
ZMAX
-
ZMIN
)
/
RAND_MAX
)
);
YMAX
+=
((
rand
()
/
RAND_MAX
)
*
((
YMAX
-
YMIN
)
/
RAND_MAX
));
ZMAX
+=
(
(
rand
()
/
RAND_MAX
)
*
((
ZMAX
-
ZMIN
)
/
RAND_MAX
)
);
ZMIN
-=
-
1
.
0
*
((
rand
()
/
RAND_MAX
)
*
((
ZMAX
-
ZMIN
)
/
RAND_MAX
));
// Position of STS Tz=59.5
ZMAX
+=
((
rand
()
/
RAND_MAX
)
*
((
ZMAX
-
ZMIN
)
/
RAND_MAX
));
// double XMIN=-162, XMAX=162;
// double YMIN=-72, YMAX=72;
// Position of STS Tz=59.5
// double ZMIN=-102+59.5, ZMAX=20+59.5;
// double XMIN=-162, XMAX=162;
// double YMIN=-72, YMAX=72;
TOTAL_VOLUME
=
(
XMAX
-
XMIN
)
*
(
YMAX
-
YMIN
)
*
(
ZMAX
-
ZMIN
);
// in cm3 for m3 times 10^-6
// double ZMIN=-102+59.5, ZMAX=20+59.5;
if
(
output
==
2
)
printf
(
"Modified total volume is %f m3
\n
"
,
(
double
)
TOTAL_VOLUME
/
1000000
);
TOTAL_VOLUME
=
(
XMAX
-
XMIN
)
*
(
YMAX
-
YMIN
)
*
(
ZMAX
-
ZMIN
);
// in cm3 for m3 times 10^-6
for
(
i
=
1
;
i
<=
NUM
;
i
++
){
if
(
output
==
2
)
printf
(
"Modified total volume is %f m3
\n
"
,
(
double
)
TOTAL_VOLUME
/
1000000
);
x
=
(
double
)
rand
()
/
RAND_MAX
*
(
XMAX
-
XMIN
)
+
XMIN
;
for
(
i
=
1
;
i
<=
NUM
;
i
++
)
{
y
=
(
double
)
rand
()
/
RAND_MAX
*
(
YMAX
-
YMIN
)
+
YMIN
;
z
=
(
double
)
rand
()
/
RAND_MAX
*
(
ZMAX
-
ZMIN
)
+
ZMIN
;
x
=
(
double
)
rand
()
/
RAND_MAX
*
(
XMAX
-
XMIN
)
+
XMIN
;
y
=
(
double
)
rand
()
/
RAND_MAX
*
(
YMAX
-
YMIN
)
+
YMIN
;
tmp_node
=
navig
->
FindNode
(
x
,
y
,
z
);
z
=
(
double
)
rand
()
/
RAND_MAX
*
(
ZMAX
-
ZMIN
)
+
ZMIN
;
tmp_med
=
tmp_node
->
GetMedium
();
tmp_mat
=
tmp_med
->
GetMaterial
();
tmp_node
=
navig
->
FindNode
(
x
,
y
,
z
);
tmp_den
=
tmp_mat
->
GetDensity
();
tmp_med
=
tmp_node
->
GetMedium
();
tmp_mat
=
tmp_med
->
GetMaterial
();
SUM_DENSITY
+=
tmp_den
;
tmp_den
=
tmp_mat
->
GetDensity
();
MATERIAL_COUNT
[
gman
->
GetMaterialIndex
(
tmp_mat
->
GetName
())]
++
;
SUM_DENSITY
+=
tmp_den
;
j
=
0
;
MATERIAL_COUNT
[
gman
->
GetMaterialIndex
(
tmp_mat
->
GetName
())]
++
;
while
(
navig
->
GetMother
(
j
)
!=
nullptr
){
strcpy
(
ARRAY_PATH
[
j
],(
navig
->
GetMother
(
j
)
->
GetName
()));
j
=
0
;
j
++
;
while
(
navig
->
GetMother
(
j
)
!=
nullptr
)
{
};
strcpy
(
ARRAY_PATH
[
j
],
(
navig
->
GetMother
(
j
)
->
GetName
()));
j
++
;
strname
[
0
]
=
'\0'
;
};
while
(
j
-->
0
){
strcat
(
strname
,
"/"
);
strname
[
0
]
=
'\0'
;
strcat
(
strname
,
ARRAY_PATH
[
j
]);
while
(
j
--
>
0
)
{
ARRAY_PATH
[
j
][
0
]
=
'\0'
;
// zeroing
strcat
(
strname
,
"/"
);
};
strcat
(
strname
,
ARRAY_PATH
[
j
]);
ARRAY_PATH
[
j
][
0
]
=
'\0'
;
// zeroing
// printf("STRING WROTE: %s \n", strname);
};
j
=
find_node
(
strname
,
NODE_COUNT
);
// printf("STRING WROTE: %s \n", strname);
NODE_COUNT
[
j
].
COUNT
++
;
strcpy
(
NODE_COUNT
[
j
].
NAME
,
strname
);
j
=
find_node
(
strname
,
NODE_COUNT
);
NODE_COUNT
[
j
].
COUNT
++
;
NODE_COUNT
[
j
].
MATERIAL_ID
=
gman
->
GetMaterialIndex
(
tmp_mat
->
GetName
());
strcpy
(
NODE_COUNT
[
j
].
NAME
,
strname
);
j
=
0
;
NODE_COUNT
[
j
].
MATERIAL_ID
=
gman
->
GetMaterialIndex
(
tmp_mat
->
GetName
());
};
j
=
0
;
// Ratio of materials MATERIAL_COUNT/TOTAL_COUNT
};
// VOLUME OF MATERIAL [ABOVE]*TOTAL_VOLUME
// TOTAL MASS OF MATERIAL [ABOVE]*DENSITY_OF_MATERIAL
// Ratio of materials MATERIAL_COUNT/TOTAL_COUNT
// VOLUME OF MATERIAL [ABOVE]*TOTAL_VOLUME
long
int
TOTAL_COUNT
=
NUM
;
// TOTAL MASS OF MATERIAL [ABOVE]*DENSITY_OF_MATERIAL
double
VC_RATIO
=
(
double
)
TOTAL_VOLUME
/
TOTAL_COUNT
;
long
int
TOTAL_COUNT
=
NUM
;
printf
(
"TOTAL COUNT: %ld
\n
"
,
TOTAL_COUNT
);
double
VC_RATIO
=
(
double
)
TOTAL_VOLUME
/
TOTAL_COUNT
;
printf
(
"
\n\n
"
);
printf
(
"
\n
COUNT OF MATERIALS: "
);
printf
(
"TOTAL COUNT: %ld
\n
"
,
TOTAL_COUNT
);
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
printf
(
"%f%% "
,
(
double
)
100
*
MATERIAL_COUNT
[
i
]
/
TOTAL_COUNT
);
printf
(
"
\n\n
"
);
printf
(
"
\n
"
);
printf
(
"
\n
COUNT OF MATERIALS: "
);
printf
(
"
\n\n
"
);
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
printf
(
"VOLUME OF %s IS %f
\n
"
,
printf
(
"%f%% "
,
(
double
)
100
*
MATERIAL_COUNT
[
i
]
/
TOTAL_COUNT
);
gman
->
GetMaterial
(
i
)
->
GetName
(),
printf
(
"
\n
"
);
(
double
)
TOTAL_VOLUME
*
MATERIAL_COUNT
[
i
]
/
TOTAL_COUNT
);
printf
(
"
\n\n
"
);
printf
(
"
\n\n
"
);
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
if
(
output
==
2
)
printf
(
"MASS OF %s IS %f kg
\n
"
,
printf
(
"VOLUME OF %s IS %f
\n
"
,
gman
->
GetMaterial
(
i
)
->
GetName
(),
gman
->
GetMaterial
(
i
)
->
GetName
(),
(
double
)
TOTAL_VOLUME
*
MATERIAL_COUNT
[
i
]
/
TOTAL_COUNT
);
0
.
001
*
(
gman
->
GetMaterial
(
i
)
->
GetDensity
())
*
TOTAL_VOLUME
*
MATERIAL_COUNT
[
i
]
/
TOTAL_COUNT
printf
(
"
\n\n
"
);
);
for
(
i
=
0
;
i
<
NUMBER_OF_MATERIALS
;
i
++
)
if
(
output
==
2
)
printf
(
"MASS OF %s IS %f kg
\n
"
,
gman
->
GetMaterial
(
i
)
->
GetName
(),
printf
(
"NODE
\t
COUNT
\t
VOLUME
\t
MATERIAL
\t
MASS
\n
"
);
0
.
001
*
(
gman
->
GetMaterial
(
i
)
->
GetDensity
())
*
TOTAL_VOLUME
*
MATERIAL_COUNT
[
i
]
/
TOTAL_COUNT
);
printf
(
"----------
\t
----------
\t
----------
\t
----------
\t
----------
\n
"
);
for
(
int
k
=
0
;
k
<
5000
;
k
++
){
printf
(
"NODE
\t
COUNT
\t
VOLUME
\t
MATERIAL
\t
MASS
\n
"
);
if
(
NODE_COUNT
[
k
].
COUNT
==
0
)
break
;
printf
(
"----------
\t
----------
\t
----------
\t
----------
\t
----------
\n
"
);
printf
(
"%s
\t
%ld
\t
%f
\t
%s
\t
%f
\n
"
,
for
(
int
k
=
0
;
k
<
5000
;
k
++
)
{
NODE_COUNT
[
k
].
NAME
,
if
(
NODE_COUNT
[
k
].
COUNT
==
0
)
break
;
NODE_COUNT
[
k
].
COUNT
,
printf
(
"%s
\t
%ld
\t
%f
\t
%s
\t
%f
\n
"
,
NODE_COUNT
[
k
].
NAME
,
NODE_COUNT
[
k
].
COUNT
,
(
float
)
NODE_COUNT
[
k
].
COUNT
*
VC_RATIO
,
(
float
)
NODE_COUNT
[
k
].
COUNT
*
VC_RATIO
,
gman
->
GetMaterial
(
NODE_COUNT
[
k
].
MATERIAL_ID
)
->
GetName
(),
gman
->
GetMaterial
(
NODE_COUNT
[
k
].
MATERIAL_ID
)
->
GetName
(),
(
float
)
NODE_COUNT
[
k
].
COUNT
*
VC_RATIO
*
(
gman
->
GetMaterial
(
NODE_COUNT
[
k
].
MATERIAL_ID
)
->
GetDensity
()));
(
float
)
NODE_COUNT
[
k
].
COUNT
*
VC_RATIO
*
(
gman
->
GetMaterial
(
NODE_COUNT
[
k
].
MATERIAL_ID
)
->
GetDensity
())
}
);
}
return
;
return
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment