Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for old Garfield versions #41

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
57 changes: 20 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,29 @@
set( LibraryVersion "1.6" )
set(LibraryVersion "1.6")
add_definitions(-DLIBRARY_VERSION="${LibraryVersion}")

#find garfield libs and includes
IF (NOT DEFINED REST_GARFIELD)
if (NOT DEFINED REST_GARFIELD OR NOT REST_GARFIELD)
set(REST_GARFIELD OFF)
ENDIF ()

if (${REST_GARFIELD} MATCHES "ON")
add_definitions(-DUSE_Garfield)

if (DEFINED ENV{GARFIELD_INSTALL})
# Tested for Garfield af4a14516489babbd6e6df780edd58fedf7fa12b
message(STATUS "Using new Garfield CMake")
set(GARFIELD_INSTALL $ENV{GARFIELD_INSTALL})
find_package(Garfield REQUIRED)
set(external_include_dirs ${external_include_dirs} ${GARFIELD_INSTALL}/include/Garfield)
set(external_libs ${external_libs} Garfield::Garfield)
# recommended CMake way does not work, we need to delete the "FindGarfield.cmake" script
elseif (DEFINED ENV{GARFIELD_HOME})
# Old way, for backwards compatibility
message(STATUS "Using old Garfield CMake")
set(GARFIELD_INSTALL $ENV{GARFIELD_HOME})
include(FindGarfieldOld)
message(STATUS Garfield_INCLUDE_DIRS ${Garfield_INCLUDE_DIRS})
message(STATUS Garfield_INCLUDE_DIRS ${Garfield_INCLUDE_Heed_DIRS})
message(STATUS Garfield_LIBRARIES ${Garfield_LIBRARIES})
set(external_include_dirs ${external_include_dirs} ${Garfield_INCLUDE_DIRS})
set(external_include_dirs ${external_include_dirs} ${Garfield_INCLUDE_Heed_DIRS})
set(external_libs ${external_libs} ${Garfield_LIBRARIES})
add_definitions(-DUSE_Garfield_OLD)
else ()
message(FATAL_ERROR "Garfield not found")
endif ()

#set(GARFIELD_INSTALL $ENV{GARFIELD_INSTALL})
message(STATUS "GARFIELD INSTALLATION: ${GARFIELD_INSTALL}")
message(STATUS "Garfield DISABLED")
endif ()

if (REST_GARFIELD)
message(STATUS "Garfield ENABLED")

add_compile_definitions(REST_GARFIELD)

# Tested for Garfield af4a14516489babbd6e6df780edd58fedf7fa12b
find_package(Garfield REQUIRED)

set(GARFIELD_INSTALL $ENV{GARFIELD_INSTALL})
set(external_include_dirs ${external_include_dirs} ${GARFIELD_INSTALL}/include/Garfield)
set(external_libs ${external_libs} Garfield::Garfield)

message(STATUS "GARFIELD installation found at ${GARFIELD_INSTALL}")

set(feature_added "Garfield")
set(feature_added ${feature_added} PARENT_SCOPE)
else ()
set(REST_GARFIELD OFF)
endif (${REST_GARFIELD} MATCHES "ON")

endif ()

if (NOT ${REST_EVE} MATCHES "ON")
set(excludes ${excludes} TRestDetectorHitsEventViewer)
Expand Down
12 changes: 5 additions & 7 deletions inc/TRestDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
#include "TRestStringOutput.h"
#include "TRestTools.h"

using namespace std;

//! An metadata class to store basic detector information
class TRestDetector : public TRestMetadata {
public:
/// The detector name
string fDetectorName = "REST Detector";
std::string fDetectorName = "REST Detector";

/// The detector drift voltage in V
Double_t fDriftVoltage = -1;
Expand Down Expand Up @@ -84,19 +82,19 @@ class TRestDetector : public TRestMetadata {
Double_t fElectronicsThreshold = -1;

/// The electronics gain in raw configuration format (hexadecimal)
string fElectronicsGain = "-1";
std::string fElectronicsGain = "-1";
/// The electronics clock (sampling) in raw configuration format (hexadecimal)
string fElectronicsClock = "-1";
std::string fElectronicsClock = "-1";
/// The electronics shaping in raw configuration format (hexadecimal)
string fElectronicsShaping = "-1";
std::string fElectronicsShaping = "-1";

void InitFromConfigFile() { ReadAllParameters(); }

void PrintMetadata();

void UpdateMetadataMembers();

// Constructors
// Constructor
TRestDetector() {}
// Destructor
~TRestDetector() {}
Expand Down
20 changes: 6 additions & 14 deletions inc/TRestDetectorGarfieldDriftProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@

#include <TRestDetectorGas.h>

#if defined USE_Garfield_OLD
#include "AvalancheMC.hh"
#include "ComponentBase.hh"
#include "Sensor.hh"
typedef AvalancheMC DRIFT_METHOD;
#elif USE_Garfield
#if defined REST_GARFIELD
lobis marked this conversation as resolved.
Show resolved Hide resolved
#include "AvalancheMC.hh"
#include "Component.hh"
#include "Sensor.hh"
typedef AvalancheMC DRIFT_METHOD;
// TODO Could we have this as an option given through metadata?
#endif

#include <TRandom3.h>
Expand All @@ -47,7 +41,7 @@ class TRestDetectorGarfieldDriftProcess : public TRestEventProcess {
TRestDetectorHitsEvent* fInputHitsEvent; //!
TRestDetectorHitsEvent* fOutputHitsEvent; //!

#if defined USE_Garfield
#if defined REST_GARFIELD
Copy link
Member

@jgalan jgalan Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we keep USE_Garfield? It is done like that for other libraries.

We use REST_LIBRARY inside cmake, USE_LIBRARY inside the c++ codes. E.g. USE_SQL, USE_MPFR

TRestDetectorReadout* fReadout; //!
TRestDetectorGas* fGas; //!
TRestDetectorGeometry* fGeometry; //!
Expand All @@ -61,9 +55,8 @@ class TRestDetectorGarfieldDriftProcess : public TRestEventProcess {

Int_t FindModule(Int_t readoutPlane, Double_t x, Double_t y);
Int_t FindChannel(Int_t module, Double_t x, Double_t y);
#endif

protected:
#if defined USE_Garfield
Double_t fGasPressure; // atm
// Double_t fElectricField; // V/cm
Double_t fDriftPotential; // V
Expand All @@ -79,7 +72,7 @@ class TRestDetectorGarfieldDriftProcess : public TRestEventProcess {

TRestEvent* ProcessEvent(TRestEvent* eventInput);

#if defined USE_Garfield
#if defined REST_GARFIELD
void InitProcess();
void EndProcess();

Expand Down Expand Up @@ -110,8 +103,7 @@ class TRestDetectorGarfieldDriftProcess : public TRestEventProcess {
// Destructor
~TRestDetectorGarfieldDriftProcess();
#endif
ClassDef(TRestDetectorGarfieldDriftProcess,
1); // Template for a REST "event process" class inherited from
// TRestEventProcess
ClassDef(TRestDetectorGarfieldDriftProcess, 1);
};

#endif
20 changes: 10 additions & 10 deletions inc/TRestDetectorGas.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#ifndef RestCore_TRestDetectorGas
#define RestCore_TRestDetectorGas

#include <TROOT.h>

#include <cstdlib>
Expand All @@ -40,14 +41,13 @@
#include "TSystem.h"
#include "TVector3.h"

#if defined USE_Garfield
#if defined REST_GARFIELD
#include "ComponentConstant.hh"
#include "GeometrySimple.hh"
#include "MediumMagboltz.hh"
#include "Sensor.hh"
#include "SolidBox.hh"
#include "TrackHeed.hh"
using namespace Garfield;
#else
class MediumMagboltz;
#endif
Expand Down Expand Up @@ -110,13 +110,13 @@ class TRestDetectorGas : public TRestDetectorDriftVolume {
Bool_t fTest = false; //!

void InitFromConfigFile();
string ConstructFilename();
std::string ConstructFilename();

void AddGasComponent(std::string gasName, Double_t fraction);

void GenerateGasFile();

void UploadGasToServer(string gasFilename);
void UploadGasToServer(std::string gasFilename);

Double_t GetDriftVelocity(Double_t E);
Double_t GetLongitudinalDiffusion(Double_t E);
Expand All @@ -126,7 +126,7 @@ class TRestDetectorGas : public TRestDetectorDriftVolume {

public:
TRestDetectorGas();
TRestDetectorGas(const char* cfgFileName, string name = "", bool gasGeneration = false,
TRestDetectorGas(const char* cfgFileName, std::string name = "", bool gasGeneration = false,
bool test = false);
~TRestDetectorGas();

Expand All @@ -144,7 +144,7 @@ class TRestDetectorGas : public TRestDetectorDriftVolume {

void LoadGasFile();

string FindGasFile(string name);
std::string FindGasFile(std::string name);

void CalcGarField(double Emin, double Emax, int n);

Expand All @@ -162,8 +162,8 @@ class TRestDetectorGas : public TRestDetectorDriftVolume {
/// Returns the gas component *n*.
TString GetGasComponentName(Int_t n) {
if (n >= GetNofGases()) {
cout << "REST WARNING. Gas name component n=" << n << " requested. But only " << GetNofGases()
<< " component(s) in the mixture." << endl;
std::cout << "REST WARNING. Gas name component n=" << n << " requested. But only "
<< GetNofGases() << " component(s) in the mixture." << std::endl;
return "";
}
return fGasComponentName[n];
Expand Down Expand Up @@ -250,12 +250,12 @@ class TRestDetectorGas : public TRestDetectorDriftVolume {
void PlotTransversalDiffusion(Double_t eMin, Double_t eMax, Int_t nSteps);
void PlotTownsendCoefficient(Double_t eMin, Double_t eMax, Int_t nSteps);
void PrintGasInfo();
void PrintGasFileContent() { cout << fGasFileContent << endl; };
void PrintGasFileContent() { std::cout << fGasFileContent << std::endl; };

/// Prints the metadata information from the gas
void PrintMetadata() { PrintGasInfo(); }

ClassDef(TRestDetectorGas, 3); // Gas Parameters
ClassDef(TRestDetectorGas, 3);
};

#endif
38 changes: 11 additions & 27 deletions inc/TRestDetectorGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,34 @@

#include "TRestDetectorGas.h"

#if defined USE_Garfield
#if defined REST_GARFIELD

#if defined USE_Garfield_OLD
#include "ComponentBase.hh"
#else
#include "Component.hh"
#endif

#include "GeometryRoot.hh"
#include "Sensor.hh"

#if defined USE_Garfield_OLD
typedef Garfield::ComponentBase Component;
#else
typedef Garfield::Component Component;
#endif

#endif

using namespace std;

class TRestDetectorGeometry : public TGeoManager {
protected:
#if defined USE_Garfield
Garfield::GeometryRoot* fGfGeometry; //!///< Pointer to Garfield::GeometryRoot object of the
//! geometry
vector<Component*> vGfComponent; //!///< Vector of pointers to Garfield Component object
vector<Garfield::Sensor*> vGfSensor; //!///< Vector of pointers to Garfield Sensor object
TGeoNode* fDriftElec; //!///< pointer to drift electrode
vector<TGeoNode*> vReadoutElec; //!///< vector of pointers to readout planes

#if defined REST_GARFIELD
Garfield::GeometryRoot* fGfGeometry; //!///< Pointer to Garfield::GeometryRoot object of the geometry
vector<Garfield::Component*> vGfComponent; //!///< Vector of pointers to Garfield Component object
vector<Garfield::Sensor*> vGfSensor; //!///< Vector of pointers to Garfield Sensor object
TGeoNode* fDriftElec; //!///< pointer to drift electrode
vector<TGeoNode*> vReadoutElec; //!///< vector of pointers to readout planes
lobis marked this conversation as resolved.
Show resolved Hide resolved
#endif

public:
// Construtor
// Constructor
TRestDetectorGeometry();
// Destructor
virtual ~TRestDetectorGeometry();

/// initialize Garfield::GeometryRoot geometry object
void InitGfGeometry();

#if defined USE_Garfield

#if defined REST_GARFIELD
/// Return pointer to Garfield::GeometryRoot geometry object
Garfield::GeometryRoot* GetGfGeometry() { return fGfGeometry; }

Expand Down Expand Up @@ -108,7 +92,7 @@ class TRestDetectorGeometry : public TGeoManager {
}

/// Get i^th Gf component
Component* GetGfComponent(unsigned int i) {
Garfield::Component* GetGfComponent(unsigned int i) {
if (i < vGfComponent.size())
return vGfComponent[i];
else
Expand Down Expand Up @@ -138,7 +122,7 @@ class TRestDetectorGeometry : public TGeoManager {

void PrintGeometry();

ClassDef(TRestDetectorGeometry, 1); // REST event superclass
ClassDef(TRestDetectorGeometry, 1);
};

#endif
11 changes: 3 additions & 8 deletions src/TRestDetectorElectronDiffusionProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ void TRestDetectorElectronDiffusionProcess::LoadDefaultConfig() {
fGasPressure = 1;
}

//______________________________________________________________________________
void TRestDetectorElectronDiffusionProcess::Initialize() {
SetSectionName(this->ClassName());
SetLibraryVersion(LIBRARY_VERSION);
Expand All @@ -65,7 +64,6 @@ void TRestDetectorElectronDiffusionProcess::LoadConfig(string cfgFilename, strin
if (LoadConfigFromFile(cfgFilename, name)) LoadDefaultConfig();
}

//______________________________________________________________________________
void TRestDetectorElectronDiffusionProcess::InitProcess() {
fRandom = new TRandom3(fSeed);

Expand All @@ -86,7 +84,7 @@ void TRestDetectorElectronDiffusionProcess::InitProcess() {
exit(-1);
}
} else {
#ifndef USE_Garfield
#ifndef REST_GARFIELD
ferr << "A TRestDetectorGas definition was found but REST was not linked to Garfield libraries."
<< endl;
ferr << "Please, remove the TRestDetectorGas definition, and add gas parameters inside the process "
Expand Down Expand Up @@ -114,7 +112,6 @@ void TRestDetectorElectronDiffusionProcess::InitProcess() {
}
}

//______________________________________________________________________________
TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* evInput) {
fInputHitsEvent = (TRestDetectorHitsEvent*)evInput;
fOutputHitsEvent->SetEventInfo(fInputHitsEvent);
Expand Down Expand Up @@ -222,7 +219,6 @@ TRestEvent* TRestDetectorElectronDiffusionProcess::ProcessEvent(TRestEvent* evIn
return fOutputHitsEvent;
}

//______________________________________________________________________________
void TRestDetectorElectronDiffusionProcess::EndProcess() {
// Function to be executed once at the end of the process
// (after all events have been processed)
Expand All @@ -232,7 +228,6 @@ void TRestDetectorElectronDiffusionProcess::EndProcess() {
// TRestEventProcess::EndProcess();
}

//______________________________________________________________________________
void TRestDetectorElectronDiffusionProcess::InitFromConfigFile() {
fGasPressure = GetDblParameterWithUnits("gasPressure", -1.);
fElectricField = GetDblParameterWithUnits("electricField", -1.);
Expand All @@ -242,15 +237,15 @@ void TRestDetectorElectronDiffusionProcess::InitFromConfigFile() {
if (fLonglDiffCoeff == -1)
fLonglDiffCoeff = StringToDouble(GetParameter("longDiff", "-1"));
else {
warning << "longitudinalDiffusionCoeffient is now OBSOLETE! It will soon dissapear." << endl;
warning << "longitudinalDiffusionCoefficient is now OBSOLETE! It will soon disappear." << endl;
warning << " Please use the shorter form of this parameter : longDiff" << endl;
}

fTransDiffCoeff = StringToDouble(GetParameter("transversalDiffusionCoefficient", "-1"));
if (fTransDiffCoeff == -1)
fTransDiffCoeff = StringToDouble(GetParameter("transDiff", "-1"));
else {
warning << "transversalDiffusionCoeffient is now OBSOLETE! It will soon dissapear." << endl;
warning << "transversalDiffusionCoefficient is now OBSOLETE! It will soon disappear." << endl;
warning << " Please use the shorter form of this parameter : transDiff" << endl;
}
fMaxHits = StringToInteger(GetParameter("maxHits", "1000"));
Expand Down
Loading