Skip to content
4 changes: 4 additions & 0 deletions ALICE3/Core/ALICE3CoreLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@

#pragma link C++ class std::vector < std::vector < unsigned int>> + ;
#pragma link C++ class std::vector < std::vector < std::uint32_t>> + ;
#pragma link C++ class o2::fastsim::SecondaryLutAxis + ;
#pragma link C++ class o2::fastsim::SecondaryLutEntry + ;
#pragma link C++ class std::vector < o2::fastsim::SecondaryLutEntry> + ;
#pragma link C++ class o2::fastsim::SecondaryLut + ;
4 changes: 4 additions & 0 deletions ALICE3/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ o2physics_add_library(ALICE3Core
FlatLutRootWriter.cxx
FlatTrackSmearer.cxx
GeometryContainer.cxx
SecondaryLut.cxx
SecondaryTrackSmearer.cxx
PUBLIC_LINK_LIBRARIES O2::Framework
O2Physics::AnalysisCore
PRIVATE_LINK_LIBRARIES ROOT::Core
ROOT::RIO
ROOT::Hist
ROOT::Tree)

o2physics_target_root_dictionary(ALICE3Core
HEADERS TrackUtilities.h
FlatLutEntry.h
OTFParticle.h
GeometryContainer.h
SecondaryLut.h
LINKDEF ALICE3CoreLinkDef.h)

o2physics_add_library(FastTracker
Expand Down
5 changes: 4 additions & 1 deletion ALICE3/Core/DetLayer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ DetLayer::DetLayer(const TString& name,
}

DetLayer::DetLayer(const DetLayer& other)
: mName(other.mName), mR(other.mR), mZ(other.mZ), mX0(other.mX0), mXrho(other.mXrho), mResRPhi(other.mResRPhi), mResZ(other.mResZ), mEff(other.mEff), mType(other.mType)
: mName(other.mName), mR(other.mR), mZ(other.mZ), mX0(other.mX0), mXrho(other.mXrho), mResRPhi(other.mResRPhi), mResZ(other.mResZ), mEff(other.mEff), mType(other.mType), mDiskROuter(other.mDiskROuter)
{
}

Expand Down Expand Up @@ -141,6 +141,9 @@ std::string DetLayer::toString() const
case kLayerSilicon:
out.append("Silicon");
break;
case kLayerSiliconDisk:
out.append("SiliconDisk");
break;
case kLayerGas:
out.append("Gas/TPC");
break;
Expand Down
43 changes: 38 additions & 5 deletions ALICE3/Core/DetLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef ALICE3_CORE_DETLAYER_H_
#define ALICE3_CORE_DETLAYER_H_

#include <Framework/Logger.h>

#include <TGraph.h>
#include <TString.h>

Expand Down Expand Up @@ -48,6 +50,12 @@ struct DetLayer {
void setResolutionZ(float resZ) { mResZ = resZ; }
void setEfficiency(float eff) { mEff = eff; }
void setType(int type) { mType = type; }
void setSiliconDiskAcceptance(float innerRadius, float outerRadius, float z)
{
mR = innerRadius;
mZ = z;
mDiskROuter = outerRadius;
}

// Dead areas

Expand All @@ -71,13 +79,35 @@ struct DetLayer {
int getType() const { return mType; }
const TString& getName() const { return mName; }
const TGraph* getDeadPhiRegions() const { return mDeadPhiRegions; }
float getDiskInnerRadius() const
{
if (mType != kLayerSiliconDisk) {
LOG(fatal) << "getDiskInnerRadius() called for layer " << mName << " which is not a silicon disk layer (type: " << mType << ")";
}
return mR;
}
float getDiskOuterRadius() const
{
if (mType != kLayerSiliconDisk) {
LOG(fatal) << "getDiskOuterRadius() called for layer " << mName << " which is not a silicon disk layer (type: " << mType << ")";
}
return mDiskROuter >= 0.f ? mDiskROuter : mR;
}
float getDiskZ() const
{
if (mType != kLayerSiliconDisk) {
LOG(fatal) << "getDiskZ() called for layer " << mName << " which is not a silicon disk layer (type: " << mType << ")";
}
return mZ;
}

// Check layer mType
bool isInert() const { return mType == kLayerInert; }
bool isSilicon() const { return mType == kLayerSilicon; }
bool isGas() const { return mType == kLayerGas; }
bool isTOF() const { return mType == kLayerTOF; }
bool isVertex() const { return mType == kLayerVertex; }
bool isSiliconDisk() const { return mType == kLayerSiliconDisk; }
bool isActive() const { return mType != kLayerInert; } // active layers are not inert

// Utilities
Expand All @@ -97,11 +127,12 @@ struct DetLayer {
return mDeadPhiRegions->Eval(phi) > 1.f;
};

static constexpr int kLayerVertex = -1; // vertex layer type (not used in tracking)
static constexpr int kLayerInert = 0; // inert/undefined layer
static constexpr int kLayerSilicon = 1; // silicon layer
static constexpr int kLayerGas = 2; // gas/tpc layer
static constexpr int kLayerTOF = 3; // TOF layer type (not used in tracking)
static constexpr int kLayerVertex = -1; // vertex layer type (not used in tracking)
static constexpr int kLayerInert = 0; // inert/undefined layer
static constexpr int kLayerSilicon = 1; // silicon layer
static constexpr int kLayerGas = 2; // gas/tpc layer
static constexpr int kLayerTOF = 3; // TOF layer type (not used in tracking)
static constexpr int kLayerSiliconDisk = 4; // silicon disk

private:
// TString for holding name
Expand All @@ -127,6 +158,8 @@ struct DetLayer {

// layer type
int mType{0}; // 0: undefined/inert, 1: silicon, 2: gas/tpc

float mDiskROuter{-1.f}; // outer radius for silicon disks, if applicable
};

} // namespace o2::fastsim
Expand Down
160 changes: 153 additions & 7 deletions ALICE3/Core/FastTracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <Rtypes.h>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
Expand All @@ -52,19 +53,151 @@
namespace o2::fastsim
{

FastTracker::SiliconLayerHits FastTracker::countSiliconLayerHits(const o2::track::TrackParCov& track) const
{
SiliconLayerHits result;
std::array<float, 3> position{};
track.getXYZGlo(position);
const double x = position[0], y = position[1], z = position[2];
const double phi = track.getPhi(), tgl = track.getTgl(), curvature = track.getCurvature(magneticField);
if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z) ||
!std::isfinite(phi) || !std::isfinite(tgl) || !std::isfinite(curvature)) {
LOG(error) << "Cannot count silicon layer hits for non-finite track parameters";
result.count = -1;
return result;
}
const double ux = std::cos(phi), uy = std::sin(phi);
constexpr double MinCurvature = 1.e-8;
constexpr double TwoPi = 6.2831853071795864769;

for (const auto& layer : layers) {
if (!layer.isSilicon() && !layer.isSiliconDisk()) {
continue;
}
if (layer.isSiliconDisk()) {
const double diskZ = layer.getDiskZ();
const double rMin = layer.getDiskInnerRadius();
const double rMax = layer.getDiskOuterRadius();
if (!std::isfinite(diskZ) || !std::isfinite(rMin) || !std::isfinite(rMax) ||
rMin < 0. || rMax < rMin) {
LOG(fatal) << "Invalid silicon disk geometry: " << layer;
continue;
}
if (std::abs(tgl) < 1.e-12) {
continue;
}
const double distance = (diskZ - z) / tgl;
if (distance < 0.) {
continue;
}
if (std::abs(curvature) >= MinCurvature) {
if (distance > TwoPi / std::abs(curvature)) {
continue;
}
}

const double cx = std::abs(curvature) < MinCurvature ? x : x - uy / curvature;
const double cy = std::abs(curvature) < MinCurvature ? y : y + ux / curvature;
const double startTheta = std::atan2(y - cy, x - cx);
const double diskX = std::abs(curvature) < MinCurvature ? x + ux * distance : cx + std::cos(startTheta + curvature * distance) / std::abs(curvature);
const double diskY = std::abs(curvature) < MinCurvature ? y + uy * distance : cy + std::sin(startTheta + curvature * distance) / std::abs(curvature);
const double hitRadius = std::hypot(diskX, diskY);
if (hitRadius >= rMin && hitRadius <= rMax) {
++result.count;
const float rHit = static_cast<float>(hitRadius);
result.innerRadius = result.innerRadius < 0.f ? rHit : std::min(result.innerRadius, rHit);
result.outerRadius = std::max(result.outerRadius, rHit);
}
continue;
}
const double r = layer.getRadius();
const double halfLength = layer.getZ();
if (!std::isfinite(r) || !std::isfinite(halfLength) || r <= 0. || halfLength < 0.) {
LOG(fatal) << "Invalid silicon layer geometry: " << layer;
continue;
}
bool reached = false;
if (std::abs(curvature) < MinCurvature) {
const double projection = x * ux + y * uy;
const double discriminant = projection * projection + r * r - x * x - y * y;
if (discriminant >= 0.) {
const double root = std::sqrt(discriminant);
for (const double distance : {-projection - root, -projection + root}) {
if (distance >= 0. && std::abs(z + distance * tgl) <= halfLength) {
reached = true;
break;
}
}
}
} else {
const double cx = x - uy / curvature, cy = y + ux / curvature;
const double trackRadius = 1. / std::abs(curvature);
const double centerDistance = std::hypot(cx, cy);
if (centerDistance < 1.e-10 && std::abs(trackRadius - r) < 1.e-5) {
const double endZ = z + TwoPi * trackRadius * tgl;
reached = std::min(z, endZ) <= halfLength && std::max(z, endZ) >= -halfLength;
} else if (centerDistance > 0. && centerDistance <= trackRadius + r &&
centerDistance >= std::abs(trackRadius - r)) {
const double along = (r * r + centerDistance * centerDistance - trackRadius * trackRadius) / (2. * centerDistance);
const double perpendicular = std::sqrt(std::max(0., r * r - along * along));
const double nx = cx / centerDistance, ny = cy / centerDistance;
const double startX = x - cx, startY = y - cy;
for (const double sign : {-1., 1.}) {
const double ix = along * nx - sign * perpendicular * ny;
const double iy = along * ny + sign * perpendicular * nx;
const double vx = ix - cx, vy = iy - cy;
double angle = std::atan2(startX * vy - startY * vx, startX * vx + startY * vy);
if (std::hypot(ix - x, iy - y) < 1.e-5) {
angle = 0.;
}
if (curvature < 0.) {
angle = -angle;
}
if (angle < 0.) {
angle += TwoPi;
}
const double distance = angle / std::abs(curvature);
if (std::abs(z + distance * tgl) <= halfLength) {
reached = true;
break;
}
}
}
}
if (reached) {
++result.count;
if (result.innerRadius < 0.f || r < result.innerRadius) {
result.innerRadius = r;
}
result.outerRadius = std::max(result.outerRadius, static_cast<float>(r));
}
}
return result;
}

// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+

DetLayer* FastTracker::addLayer(const TString& name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
{
LOG(debug) << "Adding layer " << name << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type;
DetLayer newLayer(name, r, z, x0, xrho, resRPhi, resZ, eff, type);
if (newLayer.isSiliconDisk()) {
newLayer.setSiliconDiskAcceptance(r, r, z);
}
// Check that efficient layers are not inert layers
if (newLayer.getEfficiency() > 0.0f && newLayer.isInert()) {
LOG(error) << "Layer " << name << " with efficiency > 0.0 should not be inert";
}
// Layers should be ordered by increasing radius, check this
if (!layers.empty() && newLayer.getRadius() < layers.back().getRadius()) {
LOG(fatal) << "Layer " << newLayer << " is not ordered correctly, it should be after layer " << layers.back();
if (!newLayer.isSiliconDisk()) {
const auto previous = std::find_if(layers.rbegin(), layers.rend(),
[](const auto& layer) {
return !layer.isSiliconDisk();
});

if (previous != layers.rend() && newLayer.getRadius() < previous->getRadius()) {
LOG(fatal) << "Layer " << newLayer << " is not ordered correctly, it should be after layer " << previous->getName();
}
}
// Layers should all have different names
for (const auto& layer : layers) {
Expand Down Expand Up @@ -180,6 +313,10 @@ void FastTracker::addGenericDetector(const o2::fastsim::GeometryEntry& configMap

LOG(info) << " Adding layer " << layer << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
DetLayer* addedLayer = addLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
if (type == DetLayer::kLayerSiliconDisk) {
const float rMax = configMap.getFloatValue(layer, "diskOuterRadius");
addedLayer->setSiliconDiskAcceptance(r, rMax, z);
}
if (!deadPhiRegions.empty()) { // Taking it as ccdb path or local file
// Check if it begins with ccdb:
if (deadPhiRegions.starts_with("ccdb:")) {
Expand Down Expand Up @@ -321,15 +458,15 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
const float initialAlpha = inputTrack.getAlpha(); // frame of the input track
const float kTrackingMargin = 0.1;

int firstActiveLayer = -1; // first layer that is not inert
int firstActiveLayer = -1; // first supported layer that is not inert
for (size_t i = 0; i < layers.size(); ++i) {
if (!layers[i].isInert()) {
if (!layers[i].isInert() && !layers[i].isSiliconDisk()) {
firstActiveLayer = i;
break;
}
}
if (firstActiveLayer < 0) {
LOG(fatal) << "No active layers found in FastTracker, check layer setup";
LOG(fatal) << "No active non-disk layers found in FastTracker, check layer setup";
return -2; // no active layers
}
const int xrhosteps = 100;
Expand All @@ -350,8 +487,14 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
// Outward pass to find intercepts
int firstLayerReached = -1;
int lastLayerReached = -1;
int previousLayer = -1;
new (&outputTrack)(o2::track::TrackParCov)(inputTrack);
for (size_t il = 0; il < layers.size(); il++) {
if (layers[il].isSiliconDisk()) {
continue;
}
const int previousNonDiskLayer = previousLayer;
previousLayer = il;
// check if layer is doable
if (layers[il].getRadius() < initialRadius) {
continue; // this layer should not be attempted, but go ahead
Expand Down Expand Up @@ -398,9 +541,9 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
LOGF(debug, "Propagation was %s up to layer %d", ok ? "successful" : "unsuccessful", il);

// was there a problem on this layer?
if (!ok && il > 0) { // may fail to reach target layer due to the eloss
if (!ok && previousNonDiskLayer >= 0) { // may fail to reach target layer due to the eloss
const float rad2 = inputTrack.getX() * inputTrack.getX() + inputTrack.getY() * inputTrack.getY();
const float maxR = layers[il - 1].getRadius() + kTrackingMargin * 2;
const float maxR = layers[previousNonDiskLayer].getRadius() + kTrackingMargin * 2;
const float minRad = (fMinRadTrack > 0 && fMinRadTrack < maxR) ? fMinRadTrack : maxR;
if (rad2 - minRad * minRad < kTrackingMargin * kTrackingMargin) { // check previously reached layer
return -5; // did not reach min requested layer
Expand Down Expand Up @@ -475,6 +618,9 @@ int FastTracker::fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackPa
// Inward pass to calculate covariances
// As in DetectorK::SolveTrack, the track is rotated to the frame of each layer (X axis normal to the layer)
for (int il = lastLayerReached; il >= firstLayerReached; il--) {
if (layers[il].isSiliconDisk()) {
continue;
}

float targetX = 1e+3;
inputTrack.getXatLabR(layers[il].getRadius(), targetX, magneticField);
Expand Down
11 changes: 11 additions & 0 deletions ALICE3/Core/FastTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class FastTracker
*
* Propagates the given input track through the detector layers, applying
* relevant corrections and updates, and stores the result in outputTrack.
* Silicon disks are not included in this tracking calculation.
*
* @param inputTrack The input track parameters and covariance (const, by value).
* @param outputTrack Reference to the output track parameters and covariance, to be filled.
Expand All @@ -101,6 +102,16 @@ class FastTracker
*/
int fastTrack(o2::track::TrackParCov inputTrack, o2::track::TrackParCov& outputTrack, const float nch, const float maxRadius = 100.f);

struct SiliconLayerHits {
int count = 0;
float innerRadius = -1.f;
float outerRadius = -1.f;
};
/// Count distinct silicon cylinders and disks crossed in the first turn of
/// the ideal production helix, including their longitudinal/radial acceptance.
/// Material, dead regions and layer efficiencies are not applied. count is -1 on error.
[[nodiscard]] SiliconLayerHits countSiliconLayerHits(const o2::track::TrackParCov& track) const;

// For efficiency calculation
float dist(float z, float radius);
float oneEventHitDensity(float multiplicity, float radius);
Expand Down
Loading
Loading