Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rest-for-physics/detectorlib
Browse files Browse the repository at this point in the history
  • Loading branch information
jgalan committed Mar 11, 2022
2 parents 448766e + fef4296 commit f296261
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
image: nkx1231/root6-geant4-garfield:0.8
image: ghcr.io/lobis/root-geant4-garfield:cpp17_ROOT-v6-26-00_Geant4-v10.4.3_Garfield-af4a1451
# image: nkx1231/root6-geant4-garfield:0.8

stages:
- pre-build
Expand Down
40 changes: 29 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@ set( LibraryVersion "1.6" )
add_definitions(-DLIBRARY_VERSION="${LibraryVersion}")

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

if (${REST_GARFIELD} MATCHES "ON")
add_definitions(-DUSE_Garfield)
include(FindGarfield)
message(STATUS "GARFIELD " ${Garfield_INCLUDE_DIRS})
set(external_include_dirs ${external_include_dirs} ${Garfield_INCLUDE_DIRS})
set(external_libs "${external_libs} ${Garfield_LIBRARIES}")
set(external_include_dirs ${external_include_dirs} ${Garfield_DIR}/Heed)
message(STATUS "HEED Include " ${Garfield_DIR}/Heed)
message(STATUS "ALL INCLUDES: " ${external_include_dirs})
set(feature_added "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)
set(external_include_dirs ${external_include_dirs} ${GARFIELD_INSTALL}/Include)
set(external_include_dirs ${external_include_dirs} ${GARFIELD_INSTALL}/Heed)
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}")

set(feature_added "Garfield")
set(feature_added ${feature_added} PARENT_SCOPE)
else ()
set(REST_GARFIELD OFF)
Expand Down
22 changes: 13 additions & 9 deletions inc/TRestDetectorGarfieldDriftProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@

#include <TRestDetectorGas.h>

#if defined USE_Garfield
#if defined USE_Garfield_OLD
#include "AvalancheMC.hh"
#include "ComponentBase.hh"
#include "Sensor.hh"
typedef AvalancheMC DRIFT_METHOD;
#elif USE_Garfield
#include "AvalancheMC.hh"
#include "Component.hh"
#include "Sensor.hh"
typedef AvalancheMC DRIFT_METHOD;
// TODO Could we have this as an option given through metadata?
#define DRIFT_METHOD AvalancheMC
#endif

#include <TRandom3.h>

#include <TRestDetectorGeometry.h>
#include <TRestDetectorHitsEvent.h>
#include <TRestDetectorReadout.h>
#include <TRestDetectorSignalEvent.h>

#include "TRestDetectorGeometry.h"
#include "TRestDetectorHitsEvent.h"
#include "TRestDetectorReadout.h"
#include "TRestDetectorSignalEvent.h"
#include "TRestEventProcess.h"

class TRestDetectorGarfieldDriftProcess : public TRestEventProcess {
Expand All @@ -48,8 +52,8 @@ class TRestDetectorGarfieldDriftProcess : public TRestEventProcess {
TRestDetectorGas* fGas; //!
TRestDetectorGeometry* fGeometry; //!

Garfield::Sensor* fGfSensor; //!
Garfield::DRIFT_METHOD* fGfDriftMethod; //!
Garfield::Sensor* fGfSensor; //!
DRIFT_METHOD* fGfDriftMethod; //!

void InitFromConfigFile();

Expand Down
3 changes: 1 addition & 2 deletions inc/TRestDetectorGas.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#ifndef RestCore_TRestDetectorGas
#define RestCore_TRestDetectorGas
#include <TROOT.h>
#include <stdlib.h>

#include <cstdlib>
#include <fstream>
#include <iostream>

Expand All @@ -40,7 +40,6 @@
#include "TSystem.h"
#include "TVector3.h"

//#define USE_Garfield
#if defined USE_Garfield
#include "ComponentConstant.hh"
#include "GeometrySimple.hh"
Expand Down
49 changes: 32 additions & 17 deletions inc/TRestDetectorGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,47 @@
#ifndef RestCore_TRestDetectorGeometry
#define RestCore_TRestDetectorGeometry

#include <TGeoManager.h>
#include <TGeoMaterial.h>
#include <TGeoVolume.h>
#include <TObject.h>

#include <iostream>
#include <vector>

#include "TGeoManager.h"
#include "TGeoMaterial.h"
#include "TGeoVolume.h"
#include "TObject.h"

#include <TRestDetectorGas.h>
#include "TRestDetectorGas.h"

#if defined USE_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<Garfield::ComponentBase*> 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
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

#endif

public:
Expand All @@ -55,6 +69,7 @@ class TRestDetectorGeometry : public TGeoManager {
void InitGfGeometry();

#if defined USE_Garfield

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

Expand All @@ -64,7 +79,7 @@ class TRestDetectorGeometry : public TGeoManager {
}

/// Set Garfield field component
void AddGfComponent(Garfield::ComponentBase* c) {
void AddGfComponent(Component* c) {
c->SetGeometry(fGfGeometry);
vGfComponent.push_back(c);
}
Expand All @@ -89,15 +104,15 @@ class TRestDetectorGeometry : public TGeoManager {
if (i < vReadoutElec.size())
return vReadoutElec[i];
else
return 0;
return nullptr;
}

/// Get i^th Gf component
Garfield::ComponentBase* GetGfComponent(unsigned int i) {
Component* GetGfComponent(unsigned int i) {
if (i < vGfComponent.size())
return vGfComponent[i];
else
return 0;
return nullptr;
}

/// Getnumber of Gf components
Expand All @@ -108,7 +123,7 @@ class TRestDetectorGeometry : public TGeoManager {
if (i < vGfSensor.size())
return vGfSensor[i];
else
return 0;
return nullptr;
}

/// Getnumber of Gf sensors
Expand Down

0 comments on commit f296261

Please sign in to comment.