PandaRoot
GFFieldManager.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 /* Copyright 2008-2010, Technische Universitaet Muenchen,
14  Authors: Christian Hoeppner & Sebastian Neubert
15 
16  This file is part of GENFIT.
17 
18  GENFIT is free software: you can redistribute it and/or modify
19  it under the terms of the GNU Lesser General Public License as published
20  by the Free Software Foundation, either version 3 of the License, or
21  (at your option) any later version.
22 
23  GENFIT is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  GNU Lesser General Public License for more details.
27 
28  You should have received a copy of the GNU Lesser General Public License
29  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
30 */
35 #ifndef GFFIELDMANAGER_H
36 #define GFFIELDMANAGER_H
37 
38 #include "GFAbsBField.h"
39 #include <iostream>
40 
49  private:
50  GFFieldManager() {}
51  static GFFieldManager *fInstance;
52  static GFAbsBField *fField;
53 
54  public:
56  {
57  if (fField == nullptr) {
58  std::cerr << "Appareantly GFFieldManager hasnt been initialized with a correct GFAbsBField pointer -> abort" << std::endl;
59  throw;
60  }
61  return fField;
62  }
63 
64  static TVector3 getFieldVal(const TVector3 &x)
65  {
66  if (fInstance == nullptr) {
67  std::cerr << "Appareantly GFFieldManager hasnt been instantiated yet, call getInstance() and init() before getFieldVal() -> abort" << std::endl;
68  throw;
69  }
70  if (fField == nullptr) {
71  std::cerr << "Appareantly GFFieldManager hasnt been initialized with a correct GFAbsBField pointer -> abort" << std::endl;
72  throw;
73  }
74  return fField->get(x);
75  }
76 
78  void init(GFAbsBField *b) { fField = b; }
79 
81  {
82  if (fInstance == nullptr) {
83  fInstance = new GFFieldManager();
84  }
85  return fInstance;
86  }
87 };
88 
90 #endif
GFAbsBField * getField()
static TVector3 getFieldVal(const TVector3 &x)
virtual TVector3 get(const TVector3 &) const =0
override this is you concrete implementation
Generic Interface to magnetic fields in GENFIT.
Definition: GFAbsBField.h:46
void init(GFAbsBField *b)
set the magntic field here. Magnetic field classes must be derived from GFAbsBField ...
static GFFieldManager * getInstance()
Singleton which provides access to magnetic field for track representations.