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
43 changes: 43 additions & 0 deletions Common/Constants/include/CommonConstants/MathConstants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file MathConstants.h
/// \brief useful math constants
/// \author ruben.shahoyan@cern.ch

#ifndef ALICEO2_COMMON_MATH_CONSTANTS_
#define ALICEO2_COMMON_MATH_CONSTANTS_

namespace o2
{
namespace constants
{
namespace math
{
constexpr float Almost0 = 1.17549e-38;
constexpr float Almost1 = 1.f - Almost0;
constexpr float VeryBig = 1.f / Almost0;

constexpr float PI = 3.14159274101257324e+00f;
constexpr float TwoPI = 2.f * PI;
constexpr float PIHalf = 0.5f * PI;
constexpr float Rad2Deg = 180.f / PI;
constexpr float Deg2Rad = PI / 180.f;

constexpr int NSectors = 18;
constexpr float SectorSpanDeg = 360. / NSectors;
constexpr float SectorSpanRad = SectorSpanDeg * Deg2Rad;

// conversion from B(kGaus) to curvature for 1GeV pt
constexpr float B2C = -0.299792458e-3;
}
}
}
#endif
19 changes: 8 additions & 11 deletions Common/Field/include/Field/MagFieldFact.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,36 @@
/// \brief Definition of the MagFieldFact: factory for ALIDE mag. field from MagFieldParam
/// \author ruben.shahoyan@cern.ch


#ifndef ALICEO2_FIELD_MAGFIELDFACT_H
#define ALICEO2_FIELD_MAGFIELDFACT_H

#include "FairFieldFactory.h"
#include "Field/MagneticField.h"
#include <memory>

class FairField;

namespace o2 {
namespace field {

namespace o2
{
namespace field
{
class MagFieldParam;

class MagFieldFact : public FairFieldFactory
class MagFieldFact : public FairFieldFactory
{

public:
MagFieldFact();
~MagFieldFact() override;
FairField* createFairField() override;
void SetParm() override;

private:
MagFieldFact(const MagFieldFact&);
MagFieldFact& operator=(const MagFieldFact&);

MagFieldParam* mFieldPar;
std::unique_ptr<MagneticField> mField; // the resource-owning handle to a field

ClassDefOverride(MagFieldFact,2)
ClassDefOverride(MagFieldFact, 2)
};

}
}

Expand Down
36 changes: 13 additions & 23 deletions Common/Field/src/MagFieldFact.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
// or submit itself to any jurisdiction.

#include "Field/MagFieldFact.h"
#include "FairField.h"
#include "FairLogger.h"
#include "FairRuntimeDb.h"
#include "Field/MagFieldParam.h"
#include "Field/MagneticField.h"
#include "FairRuntimeDb.h"
#include "FairField.h"

#include <iostream>
using std::cout;
Expand All @@ -21,39 +22,28 @@ using std::endl;

using namespace o2::field;


ClassImp(MagFieldFact)

static MagFieldFact gMagFieldFact;

static MagFieldFact gMagFieldFact;

MagFieldFact::MagFieldFact()
:FairFieldFactory(),
mFieldPar(nullptr),
mField()
{
fCreator=this;
}

MagFieldFact::~MagFieldFact()
= default;
MagFieldFact::MagFieldFact() : FairFieldFactory(), mFieldPar(nullptr) { fCreator = this; }
MagFieldFact::~MagFieldFact() = default;

void MagFieldFact::SetParm()
{
auto RunDB = FairRuntimeDb::instance();
mFieldPar = (MagFieldParam*) RunDB->getContainer("MagFieldParam");
mFieldPar = (MagFieldParam*)RunDB->getContainer("MagFieldParam");
}

FairField* MagFieldFact::createFairField()
{
if ( !mFieldPar ) {
{
if (!mFieldPar) {
LOG(ERROR) << "MagFieldFact::createFairField: No field parameters available";
return nullptr;
}
// since we have just 1 field class, we don't need to consider fFieldPar->GetType()
mField = std::make_unique<MagneticField>(*mFieldPar);
std::cerr << "creating the field\n";
return mField.get();
std::cerr << "creating the field as unmanaged pointer\n";
// we have to use naked "new" here since the FairRootAna or TGeoGlobalMagField expect
// bare pointer on the field which they eventually destroy
return new MagneticField(*mFieldPar);
}


1 change: 1 addition & 0 deletions Common/MathUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(SRCS
)

set(HEADERS
include/${MODULE_NAME}/Utils.h
include/${MODULE_NAME}/Chebyshev3D.h
include/${MODULE_NAME}/Chebyshev3DCalc.h
include/${MODULE_NAME}/MathBase.h
Expand Down
68 changes: 31 additions & 37 deletions Common/MathUtils/include/MathUtils/Cartesian3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
#ifndef ALICEO2_CARTESIAN3D_H
#define ALICEO2_CARTESIAN3D_H

#include <Math/GenVector/DisplacementVector3D.h>
#include <Math/GenVector/PositionVector3D.h>
#include <Math/GenVector/Rotation3D.h>
#include <Math/GenVector/Transform3D.h>
#include <Math/GenVector/Translation3D.h>
#include <Rtypes.h>
#include <TGeoMatrix.h>
#include <Math/GenVector/DisplacementVector3D.h>
#include <Math/GenVector/PositionVector3D.h>
#include "MathUtils/Cartesian2D.h"
#include <iostream>

#include "MathUtils/Cartesian2D.h"

template <typename T>
using Point3D = ROOT::Math::PositionVector3D<ROOT::Math::Cartesian3D<T>, ROOT::Math::DefaultCoordinateSystemTag>;
Expand All @@ -34,27 +33,22 @@ using Vector3D = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<T>, RO

namespace o2
{
namespace Base
{

/// predefined transformations: Tracking->Local, Tracking->Global, Local->Global etc
/// predefined transformations: Tracking->Local, Tracking->Global, Local->Global etc
/// The IDs must be < 32

struct TransformType {
static constexpr int L2G = 0;
static constexpr int T2L = 1;
static constexpr int T2G = 2;
static constexpr int T2GRot = 3;
}; /// transformation types

static constexpr int T2GRot = 3;
}; /// transformation types

class Rotation2D
{
//
// class to perform rotation of 3D (around Z) and 2D points

public:

Rotation2D() = default;
Rotation2D(float cs, float sn) : mCos(cs), mSin(sn) {}
Rotation2D(float phiZ) : mCos(cos(phiZ)), mSin(sin(phiZ)) {}
Expand All @@ -74,68 +68,67 @@ class Rotation2D
mSin = sn;
}

void getComponents(float& cs, float &sn) const
void getComponents(float& cs, float& sn) const
{
cs = mCos;
sn = mSin;
}

template <typename T>
Point3D<T> operator()(const Point3D<T>& v) const
{ // local->master
return Point3D<T>( v.X()*mCos - v.Y()*mSin, v.X()*mSin + v.Y()*mCos, v.Z() );
return Point3D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos, v.Z());
}

template <typename T>
Point3D<T> operator^(const Point3D<T>& v) const
{ // master->local
return Point3D<T>( v.X()*mCos + v.Y()*mSin, -v.X()*mSin + v.Y()*mCos, v.Z() );
return Point3D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos, v.Z());
}

template <typename T>
Vector3D<T> operator()(const Vector3D<T>& v) const
{ // local->master
return Vector3D<T>( v.X()*mCos - v.Y()*mSin, v.X()*mSin + v.Y()*mCos, v.Z() );
return Vector3D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos, v.Z());
}

template <typename T>
Vector3D<T> operator^(const Vector3D<T>& v) const
{ // master->local
return Vector3D<T>( v.X()*mCos + v.Y()*mSin, -v.X()*mSin + v.Y()*mCos, v.Z() );
return Vector3D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos, v.Z());
}

template <typename T>
Point2D<T> operator()(const Point2D<T>& v) const
{ // local->master
return Point2D<T>( v.X()*mCos - v.Y()*mSin, v.X()*mSin + v.Y()*mCos );
return Point2D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos);
}

template <typename T>
Point2D<T> operator^(const Point2D<T>& v) const
{ // master->local
return Point2D<T>( v.X()*mCos + v.Y()*mSin, -v.X()*mSin + v.Y()*mCos );
return Point2D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos);
}

template <typename T>
Vector2D<T> operator()(const Vector2D<T>& v) const
{ // local->master
return Vector2D<T>( v.X()*mCos - v.Y()*mSin, v.X()*mSin + v.Y()*mCos );
return Vector2D<T>(v.X() * mCos - v.Y() * mSin, v.X() * mSin + v.Y() * mCos);
}

template <typename T>
Vector2D<T> operator^(const Vector2D<T>& v) const
{ // master->local
return Vector2D<T>( v.X()*mCos + v.Y()*mSin, -v.X()*mSin + v.Y()*mCos );
return Vector2D<T>(v.X() * mCos + v.Y() * mSin, -v.X() * mSin + v.Y() * mCos);
}

private:

float mCos = 1.f; ///< cos of rotation angle
float mSin = 0.f; ///< sin of rotation angle
float mCos = 1.f; ///< cos of rotation angle
float mSin = 0.f; ///< sin of rotation angle

ClassDefNV(Rotation2D,1);
ClassDefNV(Rotation2D, 1);
};

class Transform3D : public ROOT::Math::Transform3D
{
//
Expand All @@ -154,25 +147,28 @@ class Transform3D : public ROOT::Math::Transform3D

// inherit assignment operators of the base class
using ROOT::Math::Transform3D::operator=;

// to avoid conflict between the base Transform3D(const ForeignMatrix & m) and
// Transform3D(const TGeoMatrix &m) constructors we cannot inherit base c-tors,
// therefore we redefine them here
Transform3D(const ROOT::Math::Rotation3D& r, const Vector& v) : ROOT::Math::Transform3D(r, v) {}
Transform3D(const ROOT::Math::Rotation3D& r, const ROOT::Math::Translation3D& t) : ROOT::Math::Transform3D(r, t) {}
template <class IT>
Transform3D(IT begin, IT end) : ROOT::Math::Transform3D(begin, end) {}
Transform3D(IT begin, IT end) : ROOT::Math::Transform3D(begin, end)
{
}

// conversion operator to TGeoHMatrix
operator TGeoHMatrix&() const {
operator TGeoHMatrix&() const
{
static TGeoHMatrix tmp;
double rot[9],tra[3];
GetComponents(rot[0],rot[1],rot[2],tra[0],rot[3],rot[4],rot[5],tra[1],rot[6],rot[7],rot[8],tra[2]);
double rot[9], tra[3];
GetComponents(rot[0], rot[1], rot[2], tra[0], rot[3], rot[4], rot[5], tra[1], rot[6], rot[7], rot[8], tra[2]);
tmp.SetRotation(rot);
tmp.SetTranslation(tra);
return tmp;
}

void set(const TGeoMatrix& m); // set parameters from TGeoMatrix

using ROOT::Math::Transform3D::operator();
Expand Down Expand Up @@ -227,9 +223,7 @@ class Transform3D : public ROOT::Math::Transform3D
ClassDefNV(Transform3D, 1)
};
}
}

std::ostream &operator<<(std::ostream &os, const o2::Base::Rotation2D &t);

std::ostream& operator<<(std::ostream& os, const o2::Rotation2D& t);

#endif
Loading