Create Target authored by Erik Asbjørn Mikkelsen Jensen's avatar Erik Asbjørn Mikkelsen Jensen
What can this do ?
-------------
In AUSAlib there is support for a [Target](https://gitlab.au.dk/ausa/ausalib/blob/master/include/ausa/setup/Target.h) which is a collection of [Layers](https://gitlab.au.dk/ausa/ausalib/blob/master/include/ausa/eloss/Layer.h).
A Layer consists of a [Material](https://gitlab.au.dk/ausa/ausalib/blob/master/include/ausa/eloss/Material.h), a geometrical shape called a [Volume](https://gitlab.au.dk/ausa/ausalib/blob/master/include/ausa/geometry/Volume.h).
With a Target one can ask about which layers the line between points intersect. The signature of this is
```c++
std::vector<Intersection> getIntersections(const TVector3& from, const TVector3& to);
```
where the number of entries in the returned vector corresponds to the number of intersections ordered by distance to the intersection point.
Each intersection contains the following information:
```c+++
struct Intersection {
double distance; // Distance to intersection
double transversed; // Distance particle will transverse in layer.
const Layer* layer; // What layer it hit. You can get the material from this.
size_t index; // Index of that layer, if you have created a number of EnergyLossCalculators
};
```
JSON
-------------
The easiest way to create a Target is to create it from json:
```json
{
"center" : {"x":"5mm", "y":"5mm", "z":"5mm"},
"orientation" : {"x":"0mm", "y":"1mm", "z":"0mm"},
"normal" : {"x":"0mm", "y":"0mm", "z":"-1mm"},
"transverseLength" : "50mm",
"upLength" : "50mm",
"layers" : [
{"material" : "Wolfram", "thickness" : "50nm"},
{"material" : "Compound", "thickness" : "50nm"},
{"material" : "Silicon", "thickness" : "50nm", "active" : true}
],
"materials" : [
{"name":"Compound", "density": "19.25g/cm^2", "Z":[74, 84], "mass" : ["100 g/mol", "200 g/mol"], "stoichio" : [5, 6]},
{"name":"Wolfram", "density": "19.25g/cm^2", "Z":74, "mass" : "183.84 g/mol"}
]
}
```
For details about materials have a look [here](https://gitlab.au.dk/ausa/ausalib/wikis/materials).
The target layers created from this will be boxes with dimensions (upLength, transverseLength, thickness).
Basic usage
-------------------------
This shows how to read in a Target from json and query it for intersections:
```c++
#include <ausa/json/IO.h>
using namespace AUSA;
using namespace std;
int main(int argc, char* argv[]) {
Target target = JSON::readTargetFromJSON("target.json");
/* From */ /* To */
auto intersections = target.getIntersections({5,5,-100}, {5,5,5});
for (auto& i : intersections) {
cout << "Hit layer " << i.layer->getMaterial().getName() << " and moves " << i.transversed << " mm in it" << endl;
}
}
```
Using the above target json file this will output:
```
Hit layer Wolfram and moves 5e-05 mm in it
Hit layer Compound and moves 2.5e-05 mm in it
```
\ No newline at end of file