<!-- doxy
\page refDetectorsBase Detectors base support
/doxy -->

# Geometry

## Loading geometry

The `o2sim_geometry.root` file is generated by the `o2-sim` (only for the modules which are asked for the simulation). Currently it has to be loaded from the local file, in future its uploading from the CCDB will be implemented.

The standard way to load the geometry is via static method
```cpp
o2::base::GeometryManager::loadGeometry(std::string_view geomFilePath = "", bool applyMisalignment = true);
```

An empty `geomFilePath` is interpreted as a request to load `o2sim_geometry.root` from the current directory.
Otherwise, the following attempts will be done: (i) if it is a valid file name, load as is,
(ii) if it is a valid directory path, load from it `o2sim_geometry.root` file, (iii) otherwise, interpret it as a prefix
to compose a file name `geomFilePath_geometry.root`. Note that if the `ConfigurableParam`-type `NameConf.mDirGeom` string is not empty or equal to `none`, then its value will be prepended
in front of the `geomFilePath` as a top directory.

The argument `applyMisalignment` will trigger an attempt to apply the misalignment from the CCDB (see below).

## Applying geometry (mis)alignment

The `TGeoManager` object stored in the file (or CCDB) corresponds to closed but unlocked `ideal` geometry, whose volumes declared as `alignable` can be modified applying the relevant `TGeoHMatrix`.
This matrix is generated on the fly from the `o2::detectors::AlignParam` objects, which are stored in the vector per detector in the `<DET>/Aling` path on the CCDB.

The volume aligned by given `AlignParam` object is identified by the its `mSymName` data member (which must be the same as assigned when declaring the volume alignable via
`gGeoManager->SetAlignableEntry(...)` in the detector geometry builder) and (for sensitive volumes only) by the `mAlignableID` data member, also provided for the sensors as an argument of
`SetAlignableEntry(...)` (for the non-sensor volumes `mAlignableID` must be -1).

The value of the `mAlignableID` must be composed by the static method
`o2::base::GeometryManager::getSensID(DetID detId, int sensID)`, where `sensID` is the sequential number of the sensor for given detector `detId`.

Some details about the transformations applied by the `o2::detectors::AlignParam` (similar to the Aliroot AliAlignObjParams) can be found in the [The delta-transformation](https://alice-offline.web.cern.ch/Activities/Alignment/deltatr.html) page.

Currently the test CCDB server [http://ccdb-test.cern.ch:8080](http://ccdb-test.cern.ch:8080) is populated with empty vectors (generated by the `O2/macros/UploadDummyAlignment.C` macro) which do not modify the geometry
(except for the ITS whose misalignment is generated by the sample macro `O2/Detectors/ITSMFT/ITS/macros/test/ITSMisaligner.C`.

On the low level the (mis)alignment is applied to the geometry by the static method `o2::base::GeometryManager::applyAlignment(const std::vector<o2::detectors::AlignParam>& algPars)`.
When loading the geometry via `o2::base::GeometryManager::loadGeometry(..)` method the alignment will be applied if the argument `applyMisalignment` is `true`, using the
`o2::base::Aligner` helper. This latter inherits from the `ConfigurableParam`, so it can be configured from the command line by passing `--configKeyValues "align-geom.<key>=<value>"` string (provided the workflow invokes `o2::conf::ConfigurableParam::updateFromString(configcontext.options().get<std::string>("configKeyValues"))`).
It allows to set the following parameters:

*   `align-geom.mCCDB       : URL of the CCDB server, default: "http://ccdb-test.cern.ch:8080"`

*   `align-geom.mDetectors  : Comma separated list of detectors, "all"(default) or "none"`

*   `align-geom.mTimeStamp  : the time-stamp for CCDB query. If it is 0 (default) then the time-stamp = `now()` in milliseconds will be used.

`TODO`: once the framework will provide CCDB service, the helper will be adapted to retrieve the alignment objects via query to DPL.

