diff --git a/.clang-format-ignore b/.clang-format-ignore index a6c57f5fb2ffb..04f780d0b2553 100644 --- a/.clang-format-ignore +++ b/.clang-format-ignore @@ -1 +1,3 @@ *.json +# vendored FairRoot sources: keep upstream formatting +Detectors/3rdparty/FairRootBase/** diff --git a/Common/Field/CMakeLists.txt b/Common/Field/CMakeLists.txt index 719e7bc3a6440..b73687717370b 100644 --- a/Common/Field/CMakeLists.txt +++ b/Common/Field/CMakeLists.txt @@ -10,23 +10,17 @@ # or submit itself to any jurisdiction. o2_add_library(Field - SOURCES src/MagFieldContFact.cxx - src/MagFieldFact.cxx - src/MagFieldFast.cxx - src/MagFieldParam.cxx + SOURCES src/MagFieldFast.cxx src/MagneticField.cxx src/MagneticWrapperChebyshev.cxx src/FieldOriginBiasParam.cxx src/ALICE3MagneticField.cxx - PUBLIC_LINK_LIBRARIES O2::MathUtils FairRoot::Base O2::CommonUtils) + PUBLIC_LINK_LIBRARIES O2::MathUtils O2::FairRootBase O2::CommonUtils) o2_target_root_dictionary(Field HEADERS include/Field/MagneticWrapperChebyshev.h include/Field/MagneticField.h - include/Field/MagFieldParam.h - include/Field/MagFieldContFact.h include/Field/MagFieldFast.h - include/Field/MagFieldFact.h include/Field/FieldOriginBiasParam.h include/Field/ALICE3MagneticField.h) diff --git a/Common/Field/include/Field/MagFieldContFact.h b/Common/Field/include/Field/MagFieldContFact.h deleted file mode 100644 index 7cfdae740e657..0000000000000 --- a/Common/Field/include/Field/MagFieldContFact.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 MagFieldContFact.h -/// \brief Definition of the MagFieldContFact: factory for ALICE mag. field -/// \author ruben.shahoyan@cern.ch - -#ifndef ALICEO2_FIELD_MAGFIELDCONTFACT_ -#define ALICEO2_FIELD_MAGFIELDCONTFACT_ - -#include "FairContFact.h" -#include "Rtypes.h" // for ClassDef - -class FairParSet; - -namespace o2 -{ -namespace field -{ - -class MagFieldParam; - -class MagFieldContFact : public FairContFact -{ - private: - void setAllContainers(); - - public: - MagFieldContFact(); - ~MagFieldContFact() override = default; - FairParSet* createContainer(FairContainer*) override; - - ClassDefOverride(MagFieldContFact, 0); // Factory for Magnetic field parameters containers -}; - -} // namespace field -} // namespace o2 -#endif diff --git a/Common/Field/include/Field/MagFieldFact.h b/Common/Field/include/Field/MagFieldFact.h deleted file mode 100644 index bc0b548c36a85..0000000000000 --- a/Common/Field/include/Field/MagFieldFact.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 MagFieldFact.h -/// \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" - -class FairField; - -namespace o2 -{ -namespace field -{ -class MagFieldParam; - -class MagFieldFact : public FairFieldFactory -{ - public: - MagFieldFact(); - ~MagFieldFact() override; - FairField* createFairField() override; - void SetParm() override; - - private: - MagFieldFact(const MagFieldFact&); - MagFieldFact& operator=(const MagFieldFact&); - - MagFieldParam* mFieldPar; - - ClassDefOverride(MagFieldFact, 2); -}; -} // namespace field -} // namespace o2 - -#endif diff --git a/Common/Field/include/Field/MagFieldParam.h b/Common/Field/include/Field/MagFieldParam.h index 166a8e7296dcc..076200ebfb53b 100644 --- a/Common/Field/include/Field/MagFieldParam.h +++ b/Common/Field/include/Field/MagFieldParam.h @@ -10,27 +10,24 @@ // or submit itself to any jurisdiction. /// \file MagFieldParam.h -/// \brief Definition of the MagFieldParam: container for ALICE mag. field parameters +/// \brief Definition of the MagFieldParam: ALICE mag. field type enumerations /// \author ruben.shahoyan@cern.ch #ifndef ALICEO2_FIELD_MAGFIELDPARAM_H_ #define ALICEO2_FIELD_MAGFIELDPARAM_H_ -#include "FairParGenericSet.h" -#include - -class FairParamList; - namespace o2 { namespace field { -class MagneticField; - -class MagFieldParam : public FairParGenericSet -{ - public: +/// Field map and beam type enumerations. +/// +/// This used to be a FairParGenericSet container written into the FairRoot +/// runtime database. That path was never populated nor read back in production +/// (field settings come from CCDB/SimConfig via SimFieldUtils), so only the +/// enumerations - which are used throughout O2 - are kept. +struct MagFieldParam { enum BMap_t { k2kG, k5kG, @@ -44,35 +41,8 @@ class MagFieldParam : public FairParGenericSet kBeamTypepA, kBeamTypeAp }; - - MagFieldParam(const char* name = "", const char* title = "", const char* context = ""); - - void SetParam(const MagneticField* field); - - BMap_t GetMapType() const { return mMapType; } - BeamType_t GetBeamType() const { return mBeamType; } - Int_t GetDefInt() const { return mDefaultIntegration; } - Double_t GetFactorSol() const { return mFactorSol; } - Double_t GetFactorDip() const { return mFactorDip; } - Double_t GetBeamEnergy() const { return mBeamEnergy; } - Double_t GetMaxField() const { return mMaxField; } - const char* GetMapPath() const { return mMapPath.Data(); } - - void putParams(FairParamList* list) override; - Bool_t getParams(FairParamList* list) override; - - private: - BMap_t mMapType; ///< map type ID - BeamType_t mBeamType; ///< beam type ID - Int_t mDefaultIntegration; ///< field integration type for MC - Double_t mFactorSol; ///< solenoid current factor - Double_t mFactorDip; ///< dipole current factor - Double_t mBeamEnergy; ///< beam energy - Double_t mMaxField; ///< max field for geant - TString mMapPath; ///< path to map file - - ClassDefOverride(MagFieldParam, 1); }; + } // namespace field } // namespace o2 diff --git a/Common/Field/include/Field/MagneticField.h b/Common/Field/include/Field/MagneticField.h index 14a0bff30ae08..0b3ff3a3f0d72 100644 --- a/Common/Field/include/Field/MagneticField.h +++ b/Common/Field/include/Field/MagneticField.h @@ -25,8 +25,6 @@ #include "TNamed.h" // for TNamed #include // for str::unique_ptr -class FairParamList; - namespace o2 { namespace field @@ -63,8 +61,6 @@ class MagneticField : public FairField MagFieldParam::BeamType_t btype = MagFieldParam::kBeamTypepp, Double_t benergy = -1, Int_t integ = 2, Double_t fmax = 15, const std::string path = "$(O2_ROOT)/share/Common/maps/mfchebKGI_sym.root"); - MagneticField(const MagFieldParam& param); - MagneticField& operator=(const MagneticField& src); /// Default destructor @@ -147,9 +143,6 @@ class MagneticField : public FairField /// 3d field query alias for Alias Method to calculate the field at point xyz void GetBxyz(const Double_t p[3], Double_t* b) override { MagneticField::Field(p, b); } - /// Fill Paramater - void FillParContainer() override; - /// Method to calculate the integral_0^z of br,bt,bz void getTPCIntegral(const Double_t* xyz, Double_t* b) const; diff --git a/Common/Field/src/FieldLinkDef.h b/Common/Field/src/FieldLinkDef.h index 3571644096a73..ff5d4a6352f7e 100644 --- a/Common/Field/src/FieldLinkDef.h +++ b/Common/Field/src/FieldLinkDef.h @@ -16,9 +16,6 @@ #pragma link C++ class o2::field::MagneticField + ; #pragma link C++ class o2::field::MagneticWrapperChebyshev + ; -#pragma link C++ class o2::field::MagFieldParam + ; -#pragma link C++ class o2::field::MagFieldContFact + ; -#pragma link C++ class o2::field::MagFieldFact + ; #pragma link C++ class o2::field::MagFieldFast + ; #pragma link C++ class o2::field::ALICE3MagneticField + ; diff --git a/Common/Field/src/MagFieldContFact.cxx b/Common/Field/src/MagFieldContFact.cxx deleted file mode 100644 index 29d953b71796b..0000000000000 --- a/Common/Field/src/MagFieldContFact.cxx +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 MagFieldContFact.cxx -/// \brief Implementation of the MagFieldContFact: factory for ALICE mag. field -/// \author ruben.shahoyan@cern.ch - -#include // for strcmp, NULL -#include // for FairLogger -#include "FairRuntimeDb.h" // for FairRuntimeD -#include "FairParSet.h" -#include "Field/MagFieldParam.h" // for FairConstPar -#include "Field/MagFieldContFact.h" - -using namespace o2::field; - -ClassImp(MagFieldContFact) static MagFieldContFact gMagFieldContFact; - -MagFieldContFact::MagFieldContFact() : FairContFact() -{ - // Constructor (called when the library is loaded) - fName = "MagFieldContFact"; - fTitle = "Factory for MagField parameter container"; - setAllContainers(); - FairRuntimeDb::instance()->addContFactory(this); -} - -void MagFieldContFact::setAllContainers() -{ - // Creates the Container objects and adds it to the list of containers - - auto* p = new FairContainer("MagFieldParam", "Mag. Field Parameters", "Default Field"); - containers->Add(p); -} - -FairParSet* MagFieldContFact::createContainer(FairContainer* c) -{ - // calls the constructor of the corresponding parameter container. - const char* name = c->GetName(); - LOG(info) << "MagFieldContFact::createContainer: Creating mag.field container " << name; - FairParSet* p = nullptr; - if (strcmp(name, "MagFieldParam") == 0) { - p = new MagFieldParam(c->getConcatName().Data(), c->GetTitle(), c->getContext()); - } - return p; -} diff --git a/Common/Field/src/MagFieldFact.cxx b/Common/Field/src/MagFieldFact.cxx deleted file mode 100644 index f71b9cf587d97..0000000000000 --- a/Common/Field/src/MagFieldFact.cxx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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. - -#include "Field/MagFieldFact.h" -#include "FairField.h" -#include -#include "FairRuntimeDb.h" -#include "Field/MagFieldParam.h" -#include "Field/MagneticField.h" - -#include -using std::cerr; -using std::cout; -using std::endl; - -using namespace o2::field; - -ClassImp(MagFieldFact); - -static MagFieldFact gMagFieldFact; - -MagFieldFact::MagFieldFact() : FairFieldFactory(), mFieldPar(nullptr) { fCreator = this; } -MagFieldFact::~MagFieldFact() = default; - -void MagFieldFact::SetParm() -{ - auto RunDB = FairRuntimeDb::instance(); - mFieldPar = (MagFieldParam*)RunDB->getContainer("MagFieldParam"); -} - -FairField* MagFieldFact::createFairField() -{ - 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() - 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); -} diff --git a/Common/Field/src/MagFieldParam.cxx b/Common/Field/src/MagFieldParam.cxx deleted file mode 100644 index 9af35904c38e7..0000000000000 --- a/Common/Field/src/MagFieldParam.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 MagFieldParam.cxx -/// \brief Implementation of the MagFieldParam class -/// \author ruben.shahoyan@cern.ch - -#include "Field/MagFieldParam.h" -#include "Field/MagneticField.h" -#include "FairParamList.h" -#include "FairRun.h" -#include "FairRuntimeDb.h" - -using namespace o2::field; - -//======================================== -ClassImp(MagFieldParam); - -MagFieldParam::MagFieldParam(const char* name, const char* title, const char* context) - : FairParGenericSet(name, title, context), mMapType(k5kG), mBeamType(kNoBeamField), mDefaultIntegration(0), mFactorSol(0.), mFactorDip(0.), mBeamEnergy(0.), mMaxField(0.), mMapPath() -{ - /// create param for alice mag. field -} - -void MagFieldParam::SetParam(const MagneticField* field) -{ - /// fill parameters from the initialized field - // SetName(field->GetName()); ? is this needed - // SetTitle(field->GetTitle()); - mMapType = field->getMapType(); - mBeamType = field->getBeamType(); - mDefaultIntegration = field->Integral(); - mFactorSol = field->getFactorSolenoid(); - mFactorDip = field->getFactorDipole(); - mBeamEnergy = field->getBeamEnergy(); - mMaxField = field->Max(); - mMapPath = field->getDataFileName(); - // -} - -void MagFieldParam::putParams(FairParamList* list) -{ - /// store parameters in the list - if (!list) { - return; - } - list->add("Map Type ID", int(mMapType)); - list->add("Beam Type ID", int(mBeamType)); - list->add("Integral Type", mDefaultIntegration); - list->add("Fact.Solenoid", mFactorSol); - list->add("Fact.Dipole ", mFactorDip); - list->add("Beam Energy ", mBeamEnergy); - list->add("Max. Field ", mMaxField); - list->add("Path to map ", mMapPath.Data()); - // -} - -Bool_t MagFieldParam::getParams(FairParamList* list) -{ - /// retried parameters - int int2enum = 0; - if (!list->fill("Map Type ID", &int2enum)) { - return kFALSE; - } - mMapType = static_cast(int2enum); - if (!list->fill("Beam Type ID", &int2enum)) { - return kFALSE; - } - mBeamType = static_cast(int2enum); - // - if (!list->fill("Integral Type", &mDefaultIntegration)) { - return kFALSE; - } - if (!list->fill("Fact.Solenoid", &mFactorSol)) { - return kFALSE; - } - if (!list->fill("Fact.Dipole ", &mFactorDip)) { - return kFALSE; - } - if (!list->fill("Beam Energy ", &mBeamEnergy)) { - return kFALSE; - } - if (!list->fill("Max. Field ", &mMaxField)) { - return kFALSE; - } - FairParamObj* parpath = list->find("Path to map "); - if (!parpath) { - return kFALSE; - } - int lgt = parpath->getLength(); - // RS: is there a bug in FairParamList::fill(const Text_t* name,Text_t* value,const Int_t length)? - // I think the "if (lfill("Path to map ", cbuff, lgt + 2)) { - return kFALSE; - } - mMapPath = cbuff; - return kTRUE; -} diff --git a/Common/Field/src/MagneticField.cxx b/Common/Field/src/MagneticField.cxx index 603a89d160ba0..0c32db05aff31 100644 --- a/Common/Field/src/MagneticField.cxx +++ b/Common/Field/src/MagneticField.cxx @@ -20,9 +20,6 @@ #include // for TString #include // for TSystem, gSystem #include // for FairLogger -#include "FairParamList.h" -#include "FairRun.h" -#include "FairRuntimeDb.h" using namespace o2::field; @@ -131,39 +128,6 @@ MagneticField::MagneticField(const char* name, const char* title, Double_t facto CreateField(); } -MagneticField::MagneticField(const MagFieldParam& param) - : FairField(param.GetName(), param.GetTitle()), - mMeasuredMap(nullptr), - mFastField(nullptr), - mMapType(param.GetMapType()), - mSolenoid(0), - mBeamType(param.GetBeamType()), - mBeamEnergy(param.GetBeamEnergy()), - mDefaultIntegration(param.GetDefInt()), - mPrecisionInteg(1), - mMultipicativeFactorSolenoid(1.), - mMultipicativeFactorDipole(1.), - mMaxField(param.GetMaxField()), - mDipoleOnOffFlag(param.GetFactorDip() == 0.), - mQuadrupoleGradient(0), - mDipoleField(0), - mCompensatorField2C(0), - mCompensatorField1A(0), - mCompensatorField2A(0), - mParameterNames("", "") -{ - /* - * Constructor for FairParam derived params - */ - setFactorSolenoid(param.GetFactorSol()); - setFactorDipole(param.GetFactorDip()); - setDataFileName(param.GetMapPath()); - if (!gOriginBias) { - checkOriginBias(); - } - CreateField(); -} - MagneticField* MagneticField::createNominalField(int fld, bool uniform) { float fldCoeffL3, fldCoeffDip; @@ -724,16 +688,6 @@ void MagneticField::Print(Option_t* opt) const } } -void MagneticField::FillParContainer() -{ - // fill field parameters - FairRun* fRun = FairRun::Instance(); - FairRuntimeDb* rtdb = fRun->GetRuntimeDb(); - MagFieldParam* par = static_cast(rtdb->getContainer("MagFieldParam")); - par->SetParam(this); - par->setChanged(); -} - //_____________________________________________________________________________ void MagneticField::AllowFastField(bool v) { diff --git a/Common/SimConfig/CMakeLists.txt b/Common/SimConfig/CMakeLists.txt index 5737221789471..91d8826bb1093 100644 --- a/Common/SimConfig/CMakeLists.txt +++ b/Common/SimConfig/CMakeLists.txt @@ -24,7 +24,7 @@ o2_add_library(SimConfig src/G4ScoringMerger.cxx PUBLIC_LINK_LIBRARIES O2::CommonUtils O2::DetectorsCommonDataFormats O2::SimulationDataFormat - FairRoot::Base Boost::program_options) + O2::FairRootBase Boost::program_options) o2_target_root_dictionary(SimConfig diff --git a/DataFormats/Detectors/ZDC/CMakeLists.txt b/DataFormats/Detectors/ZDC/CMakeLists.txt index 2e69c27e74c0a..bd446ded47fd4 100644 --- a/DataFormats/Detectors/ZDC/CMakeLists.txt +++ b/DataFormats/Detectors/ZDC/CMakeLists.txt @@ -14,7 +14,7 @@ o2_add_library(DataFormatsZDC src/OrbitRawData.cxx src/OrbitRecData.cxx src/OrbitData.cxx src/ZDCTDCData.cxx src/ZDCEnergy.cxx src/ZDCWaveform.cxx src/CTF.cxx src/RecEventFlat.cxx PUBLIC_LINK_LIBRARIES O2::CommonConstants O2::CommonDataFormat O2::DetectorsCalibration - O2::ZDCBase ROOT::MathCore FairRoot::Base + O2::ZDCBase ROOT::MathCore O2::FairRootBase O2::SimulationDataFormat O2::MathUtils Microsoft.GSL::GSL) diff --git a/DataFormats/Parameters/CMakeLists.txt b/DataFormats/Parameters/CMakeLists.txt index ed137a42f6565..c52dee20da4f3 100644 --- a/DataFormats/Parameters/CMakeLists.txt +++ b/DataFormats/Parameters/CMakeLists.txt @@ -15,7 +15,7 @@ o2_add_library(DataFormatsParameters src/GRPECSObject.cxx src/GRPMagField.cxx src/AggregatedRunInfo.cxx - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CommonConstants + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::CommonConstants O2::CommonTypes O2::CCDB O2::DetectorsCommonDataFormats) diff --git a/DataFormats/simulation/CMakeLists.txt b/DataFormats/simulation/CMakeLists.txt index f9001272b70df..f8e53d08bf699 100644 --- a/DataFormats/simulation/CMakeLists.txt +++ b/DataFormats/simulation/CMakeLists.txt @@ -22,7 +22,7 @@ o2_add_library(SimulationDataFormat src/InteractionSampler.cxx src/ConstMCTruthContainer.cxx PUBLIC_LINK_LIBRARIES Microsoft.GSL::GSL - FairRoot::Base + O2::FairRootBase O2::DetectorsCommonDataFormats O2::DataFormatsParameters O2::DataFormatsCalibration diff --git a/Detectors/3rdparty/FairRootBase/AUTHORS b/Detectors/3rdparty/FairRootBase/AUTHORS new file mode 100644 index 0000000000000..c16a3b890ee9e --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/AUTHORS @@ -0,0 +1,6 @@ +Al-Turany, Mohammad +Karabowicz, Radoslaw +Klein, Dennis +Kresan, Dmytro +Rybalchenko, Alexey +Uhlig, Florian diff --git a/Detectors/3rdparty/FairRootBase/CMakeLists.txt b/Detectors/3rdparty/FairRootBase/CMakeLists.txt new file mode 100644 index 0000000000000..5081bd5f968a3 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2019-2020 CERN and copyright holders of ALICE O2. +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +# All rights not expressly granted are reserved. +# +# This software is distributed under the terms of the GNU General Public +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". +# +# 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. + +# FairRootBase: the FairRoot simulation classes used by O2. Origin, licence and changes are in README.md. + +# o2_target_root_dictionary requires paths relative to the current source dir +file(GLOB FAIRROOTBASE_SOURCES CONFIGURE_DEPENDS + RELATIVE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/src/*.cxx) +file(GLOB FAIRROOTBASE_HEADERS CONFIGURE_DEPENDS + RELATIVE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/include/*.h) + +o2_add_library(FairRootBase + TARGETVARNAME targetFairRootBase + SOURCES ${FAIRROOTBASE_SOURCES} + PUBLIC_LINK_LIBRARIES FairLogger::FairLogger + MC::VMC + Boost::serialization + ROOT::Core + ROOT::Geom + # TGeoTrack, used by FairTrajFilter + ROOT::GeomPainter + ROOT::EG + ROOT::Physics + ROOT::Tree + ROOT::RIO + ROOT::Gdml) + +# Vendored third-party code: do not fail the O2 build on its warnings. +target_compile_options(${targetFairRootBase} PRIVATE -w) + +o2_target_root_dictionary(FairRootBase + HEADERS ${FAIRROOTBASE_HEADERS} + LINKDEF src/FairRootBaseLinkDef.h) + +# These headers are included by bare name ("FairDetector.h") from O2 public +# headers, exactly as they were when they came from the FairRoot package, so +# they must be installed flat into /include rather than under a +# per-target subdirectory (which is what o2_add_library would do). +install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN "*.h") diff --git a/Detectors/3rdparty/FairRootBase/CONTRIBUTORS b/Detectors/3rdparty/FairRootBase/CONTRIBUTORS new file mode 100644 index 0000000000000..dfa14b2019225 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/CONTRIBUTORS @@ -0,0 +1,39 @@ +Aphecetche, Laurent +Babai, Arya +Berzano, Dario +Bertini, Denis +Binet, Sebastien +Costanza, Susanna +Eulisse, Giulio +Friese, Volker +Gertsenberger, Konstantin +Hřivnáčová, Ivana +Klasen, Roman +Kliemt, Ralf +Klenze, Philipp +Kollegger, Thorsten +Koenig, Ilse +Krzewicki, Mikolaj +Lavezzi, Lia +Lavrik, Evgeny +Lantwin, Oliver +Manafov, Anar +Mayer, Jan +Neskovic, Gvozden +Neubert, Sebastian +Ovcharenko, Egor +Pellegrino,Carmelo +Pierre-Alain, Loizeau +Pflueger, Stefan +Richter, Matthias +Rademakers, Fons +Rohr, David +Shahoyan, Ruben +Stockmanns, Tobias +Tacke, Christian +Ustyuzhanin, Andrey +von Haller, Barthélémy +Wenzel, Sandro +Wielanek, Daniel +Winckler, Nicolas +Zanetti, Lorenzo diff --git a/Detectors/3rdparty/FairRootBase/COPYRIGHT b/Detectors/3rdparty/FairRootBase/COPYRIGHT new file mode 100644 index 0000000000000..7523cea96ec46 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/COPYRIGHT @@ -0,0 +1,9 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: FairRoot +Upstream-Contact: Mohammad Al-Turany +Source: https://github.com/FairRootGroup/FairRoot + +Files: * +Copyright: 2003-2019, GSI Helmholtzzentrum fuer Schwerionenforschung GmbH +Copyright: 2003-2019, [see AUTHORS file] +Copyright: 2003-2019, [see CONTRIBUTORS file] diff --git a/Detectors/3rdparty/FairRootBase/LICENSE b/Detectors/3rdparty/FairRootBase/LICENSE new file mode 100644 index 0000000000000..5b74683895d17 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/LICENSE @@ -0,0 +1,843 @@ +GPL text after LGPL text in this file: + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Detectors/3rdparty/FairRootBase/README.md b/Detectors/3rdparty/FairRootBase/README.md new file mode 100644 index 0000000000000..4494faf842c00 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/README.md @@ -0,0 +1,24 @@ +# FairRootBase + +This directory holds the part of [FairRoot](https://github.com/FairRootGroup/FairRoot) that the O2 +simulation uses: the VMC application, module and detector base classes, the run, sink and root +manager, the generic stack, the event headers and a few helpers around them. The code was taken from +FairRoot `v18.4.9-alice3`, commit `a16083b13989d08de596b4fedbde4df2c3880a35`, which is the version +ALICE has been building against. + +The files keep their original copyright and licence headers. FairRoot is distributed under the GNU +Lesser General Public Licence version 3. The licence text is in [LICENSE](LICENSE) and the copyright +statement in [COPYRIGHT](COPYRIGHT), with [AUTHORS](AUTHORS) and [CONTRIBUTORS](CONTRIBUTORS), all copied verbatim +from FairRoot. Each modified file carries a note below its licence header. + +Changes with respect to the upstream sources, made in 2026: + +- Code paths that O2 does not use were removed. This covers the runtime parameter database and the + geometry parameter containers, among others. The affected files are `FairMCApplication`, + `FairModule`, `FairRun`, `FairRunSim`, `FairSink` and `FairField`. +- `FairModule` stops with a clear message if its geometry import is used, since O2 does not set it up. +- `FairRootBaseLinkDef.h` is new and builds one dictionary for the directory. + +The sources keep their upstream formatting and are excluded from clang-format. + +We are grateful to the FairRoot developers for this code and for many years of collaboration. diff --git a/Detectors/3rdparty/FairRootBase/include/FairAlignmentHandler.h b/Detectors/3rdparty/FairRootBase/include/FairAlignmentHandler.h new file mode 100644 index 0000000000000..1bae25bd78c64 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairAlignmentHandler.h @@ -0,0 +1,23 @@ +#ifndef FAIR_ALIGNMENTHANDLER_H +#define FAIR_ALIGNMENTHANDLER_H + +#include +#include + +class FairAlignmentHandler +{ + friend class FairRun; + std::map fAlignmentMatrices; + + void AlignGeometry() const; + void AlignGeometryByFullPath() const; + void AlignGeometryBySymlink() const; + + void AddAlignmentMatrices(const std::map& alignmentMatrices, bool invertMatrices); + + public: + FairAlignmentHandler(); + virtual ~FairAlignmentHandler(); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairBaseMCGenerator.h b/Detectors/3rdparty/FairRootBase/include/FairBaseMCGenerator.h new file mode 100644 index 0000000000000..7ad7e34074c32 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairBaseMCGenerator.h @@ -0,0 +1,80 @@ +/* + * FairBaseMCGenerator.h + * + * Created on: 16 mar 2020 + * Author: Daniel Wielanek + * E-mail: daniel.wielanek@gmail.com + * Warsaw University of Technology, Faculty of Physics + */ +#ifndef FAIR_BASEMCGENERATOR_H_ +#define FAIR_BASEMCGENERATOR_H_ + +#include "FairGenerator.h" + +/** + * abstract class for generators that use "macro input" to generate partcles + */ +class FairBaseMCGenerator : public FairGenerator +{ + public: + enum eVertexSmear + { + kBox, + kGauss, + kExp + }; + FairBaseMCGenerator(); + /** + * set PDG code of generated particles + * @param pdg + */ + void SetPDGType(Int_t pdg); + /** + * set vertex position and algorithm of vertex generation + * @param vx, vy, vz Vertex coordinates [cm] + * @param evx, evy, evz Vertex dispersion [cm] + * @param sm distribution of vertex, gaussian or box + */ + void SetVertex(Double_t vx, + Double_t vy, + Double_t vz, + Double_t evx = 0, + Double_t evy = 0, + Double_t evz = 0, + eVertexSmear sm = kBox); + /** + * set number of particles per event + * @param mult + */ + void SetMultiplicity(Int_t mult) { fMult = mult; }; + virtual Bool_t Init(); + virtual ~FairBaseMCGenerator(); + + protected: + FairBaseMCGenerator(const FairBaseMCGenerator &other) = default; + FairBaseMCGenerator &operator=(const FairBaseMCGenerator &rhs) = default; + Int_t GetPDGType() const { return fPDGType; }; + Int_t GetMultiplicity() const { return fMult; }; + Double_t GetPDGMass() const { return fPDGMass; }; + /** + * generate event parameters like current event + */ + virtual void GenerateEventParameters(); + Double_t GetVxAv() const { return fVx; }; + Double_t GetVyAv() const { return fVy; }; + Double_t GetVzAv() const { return fVz; }; + Double_t GetVxRms() const { return fVex; } + Double_t GetVyRms() const { return fVey; } + Double_t GetVzRms() const { return fVez; } + Double_t fX, fY, fZ; // current vertex coordinates [cm] + private: + Int_t fPDGType; // Particle type (PDG encoding) + Int_t fMult; // Multiplicity; + eVertexSmear fVertexSmear; + Double_t fPDGMass; + Double_t fVx, fVy, fVz; + Double_t fVex, fVey, fVez; + ClassDef(FairBaseMCGenerator, 1); +}; + +#endif /* FAIR_BASEMCGENERATOR_H_ */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairBoxGenerator.h b/Detectors/3rdparty/FairRootBase/include/FairBoxGenerator.h new file mode 100644 index 0000000000000..90b97c591717c --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairBoxGenerator.h @@ -0,0 +1,157 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairBoxGenerator header file ----- +// ----- Created 09/09/04 by Yu.Kharlov ----- +// ------------------------------------------------------------------------- + +/** FairBoxGenerator.h + *@author Yuri Kharlov + * + * The FairBoxGenerator generates particles within given range + * over pt, phi, eta, y or theta a fixed multiplicity per event. + * Derived from FairGenerator. + **/ + +/* $Id: FairBoxGenerator.h,v 1.3 2006/07/14 11:23:57 kharlov Exp $ */ + +/* History of cvs commits: + * + * $Log: FairBoxGenerator.h,v $ + * Revision 1.3 2006/07/14 11:23:57 kharlov + * Add protection for simultaneously set ranges; split vertex and kinematics ranges + * + * Revision 1.2 2006/03/29 16:25:50 kharlov + * New functionality added + * + */ + +#ifndef FAIR_BOXGENERATOR_H +#define FAIR_BOXGENERATOR_H + +#include "FairBaseMCGenerator.h" +#include "FairGenerator.h" // for FairGenerator + +#include // for Double32_t, Bool_t, kTRUE, etc + +class FairPrimaryGenerator; + +class FairBoxGenerator : public FairBaseMCGenerator +{ + public: + /** Default constructor. **/ + FairBoxGenerator(); + + /** Constructor with PDG-ID, multiplicity + **@param pdgid Particle type (PDG encoding) + **@param mult Multiplicity (default is 1) + **/ + FairBoxGenerator(Int_t pdgid, Int_t mult = 1); + + /** Destructor **/ + virtual ~FairBoxGenerator() {} + + /** Modifiers **/ + + void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10) + { + fPMin = pmin; + fPMax = pmax; + fPRangeIsSet = kTRUE; + } + + void SetPtRange(Double32_t ptmin = 0, Double32_t ptmax = 10) + { + fPtMin = ptmin; + fPtMax = ptmax; + fPtRangeIsSet = kTRUE; + } + + void SetEkinRange(Double32_t kmin = 0, Double32_t kmax = 10) + { + fEkinMin = kmin; + fEkinMax = kmax; + fEkinRangeIsSet = kTRUE; + } + + void SetPhiRange(Double32_t phimin = 0, Double32_t phimax = 360) + { + fPhiMin = phimin; + fPhiMax = phimax; + } + + void SetEtaRange(Double32_t etamin = -5, Double32_t etamax = 7) + { + fEtaMin = etamin; + fEtaMax = etamax; + fEtaRangeIsSet = kTRUE; + } + + void SetYRange(Double32_t ymin = -5, Double32_t ymax = 7) + { + fYMin = ymin; + fYMax = ymax; + fYRangeIsSet = kTRUE; + } + + void SetThetaRange(Double32_t thetamin = 0, Double32_t thetamax = 90) + { + fThetaMin = thetamin; + fThetaMax = thetamax; + fThetaRangeIsSet = kTRUE; + } + + void SetCosTheta() { fCosThetaIsSet = kTRUE; } + + void SetXYZ(Double32_t x = 0, Double32_t y = 0, Double32_t z = 0); + + void SetBoxXYZ(Double32_t x1 = 0, Double32_t y1 = 0, Double32_t x2 = 0, Double32_t y2 = 0, Double32_t z = 0); + + /** + * not used, for backward compatibility, please user FairLogger to set debug mode + * @param + */ + void SetDebug(Bool_t /*debug*/) {} + /** Initializer **/ + Bool_t Init(); + + /** Creates an event with given type and multiplicity. + **@param primGen pointer to the FairPrimaryGenerator + **/ + virtual Bool_t ReadEvent(FairPrimaryGenerator* primGen); + + /** Clone this object (used in MT mode only) */ + virtual FairGenerator* CloneGenerator() const; + + protected: + /** Copy constructor. **/ + FairBoxGenerator(const FairBoxGenerator&) = default; + FairBoxGenerator& operator=(const FairBoxGenerator&) = default; + + private: + Double32_t fPtMin, fPtMax; // Transverse momentum range [GeV] + Double32_t fPhiMin, fPhiMax; // Azimuth angle range [degree] + Double32_t fEtaMin, fEtaMax; // Pseudorapidity range in lab system + Double32_t fYMin, fYMax; // Rapidity range in lab system + Double32_t fPMin, fPMax; // Momentum range in lab system + Double32_t fThetaMin, fThetaMax; // Polar angle range in lab system [degree] + Double32_t fEkinMin, fEkinMax; // Kinetic Energy range in lab system [GeV] + + Bool_t fEtaRangeIsSet; // True if eta range is set + Bool_t fYRangeIsSet; // True if rapidity range is set + Bool_t fThetaRangeIsSet; // True if theta range is set + Bool_t fCosThetaIsSet; // True if uniform distribution in + // cos(theta) is set (default -> not set) + Bool_t fPtRangeIsSet; // True if transverse momentum range is set + Bool_t fPRangeIsSet; // True if abs.momentum range is set + Bool_t fEkinRangeIsSet; // True if kinetic energy range is set + + ClassDef(FairBoxGenerator, 5); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairDetector.h b/Detectors/3rdparty/FairRootBase/include/FairDetector.h new file mode 100644 index 0000000000000..b89fa8ab79ada --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairDetector.h @@ -0,0 +1,115 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRDETECTOR_H +#define FAIRDETECTOR_H + +#include "FairModule.h" // for FairModule + +#include // for Int_t, Bool_t, etc + +class FairLogger; +class FairVolume; +class TClonesArray; + +/** + * Base class for constructing detecors + * @author M. Al-Turany, Denis Bertini + * @version 0.1 + * @since 12.01.04 + */ +class FairDetector : public FairModule +{ + public: + /** + constructor + Name : Detector Name + Active: kTRUE for active detectors (ProcessHits() will be called) + kFALSE for inactive detectors + */ + FairDetector(const char* Name, Bool_t Active, Int_t DetId = 0); + /** + default constructor + */ + FairDetector(); + /** + destructor + */ + virtual ~FairDetector(); + /** + Initialization of the detector is done here + */ + virtual void Initialize(); + /** + this method is called for each step during simulation (see FairMCApplication::Stepping()) + */ + virtual Bool_t ProcessHits(FairVolume* v = 0) = 0; + /** + this is called at the end of an event after the call to tree fill in the FairRootManager + */ + virtual void EndOfEvent() {} + /** + Registers the produced collections in FAIRRootManager. + */ + virtual void Register() = 0; + + /** + Gets the produced collections + */ + virtual TClonesArray* GetCollection(Int_t iColl) const = 0; + /** + has to be called after each event to reset the containers + */ + virtual void Reset() = 0; + + virtual void CopyClones(TClonesArray*, TClonesArray*, Int_t) {} + /** + User actions after finishing of a primary track + */ + virtual void FinishPrimary() {} + /** + Finish MC Run + */ + virtual void FinishRun() {} + /** + User actions at beginning of a primary track + */ + virtual void BeginPrimary() {} + /** + User actions after finishing of each track + */ + virtual void PostTrack() {} + /** + User actions at beginning of each track + */ + virtual void PreTrack() {} + /** + User actions at beginning of event + */ + virtual void BeginEvent() {} + /** + this is called at the end of an event before the call to tree fill in the FairRootManager + */ + virtual void FinishEvent() {} + + void SaveGeoParams(); + Int_t GetDetId() { return fDetId; } + + protected: + /** Copy constructor */ + FairDetector(const FairDetector&); + /** Assignment operator */ + FairDetector& operator=(const FairDetector&); + + void DefineSensitiveVolumes(); + + Int_t fDetId; // Detector Id has to be set from ctr. + FairLogger* fLogger; //! /// FairLogger + + ClassDef(FairDetector, 1); +}; +#endif // FAIRDETECTOR_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairEventHeader.h b/Detectors/3rdparty/FairRootBase/include/FairEventHeader.h new file mode 100644 index 0000000000000..31a08ec2f56c8 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairEventHeader.h @@ -0,0 +1,77 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairEventHeader header file ----- +// ----- Created 08/09/04 D.Bertini ----- +// ------------------------------------------------------------------------- + +#ifndef FAIREVENTHEADER_H +#define FAIREVENTHEADER_H + +#include // for Int_t, Double_t, UInt_t, ClassDef, etc +#include // for TNamed + +/** + * Event Header Class + **@author D.Bertini + **@author M.Al-Turany + */ +class FairEventHeader : public TNamed +{ + public: + /** Default constructor */ + FairEventHeader(); + + /** Get the run ID for this run*/ + UInt_t GetRunId() { return fRunId; } + + /** Get the MC time for this event*/ + Double_t GetEventTime() { return fEventTime; } + + /** Get the MC input file Id for this event*/ + Int_t GetInputFileId() { return fInputFileId; } + + /**The entry number in the original MC chain */ + Int_t GetMCEntryNumber() { return fMCEntryNo; } + + /** Set the run ID for this run + * @param runid : unique run id + */ + void SetRunId(UInt_t runid) { fRunId = runid; } + + /** Set the MC time for this event + * @param time : time in ns + */ + void SetEventTime(Double_t time) { fEventTime = time; } + + /** Set the Signal file Id for this event*/ + void SetInputFileId(Int_t id) { fInputFileId = id; } + + /**The entry number in the original MC chain */ + void SetMCEntryNumber(Int_t id) { fMCEntryNo = id; } + + /** + * Destructor + */ + virtual ~FairEventHeader(); + virtual void Register(Bool_t Persistance = kTRUE); + + protected: + /** Run Id */ + UInt_t fRunId; + /** Event Time **/ + Double_t fEventTime; + /** Input file identifier, the file description is in the File header*/ + Int_t fInputFileId; + /**MC entry number from input chain*/ + Int_t fMCEntryNo; + + ClassDef(FairEventHeader, 3); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairField.h b/Detectors/3rdparty/FairRootBase/include/FairField.h new file mode 100644 index 0000000000000..2e0e5fac708a5 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairField.h @@ -0,0 +1,120 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +// ------------------------------------------------------------------------- +// ----- FairField header file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- +// ----- Redesign 13/02/06 by V. Friese ----- +// ----- Redesign 04/08/06 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +/** FairField.h + ** @author M.Al-Turany + ** @author V.Friese + ** @since 06.01.2004 + ** @version1.0 + ** + ** Abstract base class for magnetic fields in FAIR + ** Concrete field should implement the pure virtual methods + ** GetBx, GetBy and GetBz and/or GetBxyz + ** + ** Note: Field values should be returned in kG (thanks to Geant3) + **/ + +#ifndef FAIRFIELD_H +#define FAIRFIELD_H 1 + +#include "FairLogger.h" + +#include // for Double_t, Bool_t, etc +#include + +class FairField : public TVirtualMagField +{ + public: + /** Default constructor **/ + FairField(); + + /** Constructor with name and title **/ + FairField(const char* name, const char* title = "FAIR Magnetic Field"); + + FairField& operator=(const FairField&) { return *this; } + + /** Destructor **/ + virtual ~FairField(); + + /** Intialisation. E.g. read in the field map. If needed, to be + ** implemented in the concrete class. + **/ + virtual void Init(){}; + + /** Test whether field type is Constant **/ + Bool_t IsConst(); + + /** Test whether field typ is Map **/ + Bool_t IsMap(); + + /** Field type ( 0=constant, 1=map, 2=map sym2, 3 = map sym3 ) **/ + Int_t GetType() const { return fType; } + + /** Get x component of magnetic field [kG] + ** @param x,y,z Position [cm] + **/ + virtual Double_t GetBx(Double_t, Double_t, Double_t) + { + LOG(warn) << "FairField::GetBx Should be implemented in User class"; + return 0; + } + + /** Get y component of magnetic field [kG] + ** @param x,y,z Position [cm] + **/ + virtual Double_t GetBy(Double_t, Double_t, Double_t) + { + LOG(warn) << "FairField::GetBy Should be implemented in User class"; + return 0; + } + + /** Get z component of magnetic field [kG] + ** @param x,y,z Position [cm] + **/ + virtual Double_t GetBz(Double_t, Double_t, Double_t) + { + LOG(warn) << "FairField::GetBz Should be implemented in User class"; + return 0; + } + + /** Get magnetic field. For use of Geant3 + ** @param point Coordinates [cm] + ** @param bField (return) Field components [kG] + **/ + virtual void GetFieldValue(const Double_t point[3], Double_t* bField); + + void Field(const Double_t point[3], Double_t* B) { GetFieldValue(point, B); } + + /** Screen output. To be implemented in the concrete class. **/ + virtual void Print(Option_t*) const { ; } + virtual void GetBxyz(const Double_t[3], Double_t*) + { + LOG(warn) << "FairField::GetBxyz Should be implemented in User class"; + } + + + protected: + /** Field type. 1 = constant field, 2 = field map. **/ + Int_t fType; + + private: + FairField(const FairField&); + // FairField& operator=(const FairField&); + // TODO: Check why the htrack needs this + + ClassDef(FairField, 4); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairFileHeader.h b/Detectors/3rdparty/FairRootBase/include/FairFileHeader.h new file mode 100644 index 0000000000000..b71edf491e632 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairFileHeader.h @@ -0,0 +1,74 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairFileHeader source file ----- +// ----- Created 20/04/11 M.Al-Turany ----- +// ------------------------------------------------------------------------- + +#ifndef FAIRFILEHEADER_H +#define FAIRFILEHEADER_H + +#include // for UInt_t, etc +#include // for TNamed +#include // for TString + +class FairFileInfo; +class TFile; +class TList; + +/** + * File Header Class + **@author M.Al-Turany + */ +class FairFileHeader : public TNamed +{ + public: + /** Default constructor */ + FairFileHeader(); + + /**Add a class name of a task*/ + void AddTaskClassName(TString taskname); + + /** Set the run ID for this run + * @param runid : unique run id + */ + void SetRunId(UInt_t runid) { fRunId = runid; } + + /** Get the run ID for this run*/ + UInt_t GetRunId() { return fRunId; } + + /** Return the list of tasks class names */ + TList* GetListOfTasks() { return fTaskList; } + + void AddInputFile(TFile* f, UInt_t id, UInt_t ChId); + + /** + * Destructor + */ + virtual ~FairFileHeader(); + + FairFileInfo* GetFileInfo(UInt_t id, UInt_t ChId); + + protected: + /** Run Id */ + UInt_t fRunId; + + /**list of TObjStrings presenting the class names of tasks used to produce this file */ + TList* fTaskList; + + /**list of TObjStrings presenting the input files used to produce this file*/ + TList* fFileList; + + private: + FairFileHeader(const FairFileHeader&); + FairFileHeader& operator=(const FairFileHeader&); + + ClassDef(FairFileHeader, 2); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairFileInfo.h b/Detectors/3rdparty/FairRootBase/include/FairFileInfo.h new file mode 100644 index 0000000000000..19913322665c6 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairFileInfo.h @@ -0,0 +1,56 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// FairFileInfo.h +// Created by Mohammad Al-Turany on 6/21/11. +// +#ifndef FAIRFILEINFO_H +#define FAIRFILEINFO_H + +#include // for UInt_t, FairFileInfo::Class, etc +#include // for TNamed +#include // for TString + +class TFile; + +class FairFileInfo : public TNamed +{ + public: + FairFileInfo(); + FairFileInfo(TFile* file, UInt_t id, UInt_t ChId); + virtual ~FairFileInfo(); + + TString GetPath() { return fPath; } + UInt_t GetSize() { return fSize; } + UInt_t GetIdentifier() { return fIdentifier; } + UInt_t GetOrderInChain() { return fInChainId; } + + void Print(Option_t* option = "") const; + + void SetPath(TString path) { fPath = path; } + void SetSize(UInt_t size) { fSize = size; } + void SetIdentifier(UInt_t id) { fIdentifier = id; } + void SetOrderInChain(UInt_t id) { fInChainId = id; } + + protected: + /** Full path of file*/ + TString fPath; + /** size of file in bytes*/ + UInt_t fSize; + /** Signal file identifier used*/ + UInt_t fIdentifier; + /** file order in the chain*/ + UInt_t fInChainId; + + private: + FairFileInfo(const FairFileInfo&); + FairFileInfo& operator=(const FairFileInfo&); + + ClassDef(FairFileInfo, 1); +}; + +#endif // FAIRFILEINFO_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairGenerator.h b/Detectors/3rdparty/FairRootBase/include/FairGenerator.h new file mode 100644 index 0000000000000..ba824ed1dfc77 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGenerator.h @@ -0,0 +1,67 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairGenerator header file ----- +// ----- Created 09/06/04 by D. Bertini / V. Friese ----- +// ------------------------------------------------------------------------- + +/** FairGenerator.h + *@author D.Bertini + *@author V.Friese + * +The FairGenerator is the abtract base class for the generators used to +generate input for the transport simulation.Each concrete generator class +derived from this one must implement the abtract method ReadEvent, +which has to use the method FairPrimaryGenerator::AddTrack. +**/ + +#ifndef FAIRGENERATOR_H +#define FAIRGENERATOR_H + +#include // for Bool_t, etc +#include // for TNamed + +class FairPrimaryGenerator; + +class FairGenerator : public TNamed +{ + public: + /** Default constructor. **/ + FairGenerator(); + + /** Constructor with name and title **/ + FairGenerator(const char* name, const char* title = "FAIR Generator"); + + /** Destructor. **/ + virtual ~FairGenerator(); + + /** Abstract method ReadEvent must be implemented by any derived class. + It has to handle the generation of input tracks (reading from input + file) and the handing of the tracks to the FairPrimaryGenerator. I + t is called from FairMCApplication. + *@param pStack The stack + *@return kTRUE if successful, kFALSE if not + **/ + virtual Bool_t ReadEvent(FairPrimaryGenerator* primGen) = 0; + + /**Initialize the generator if needed */ + virtual Bool_t Init() { return kTRUE; } + + /** Clone this object (used in MT mode only) */ + virtual FairGenerator* CloneGenerator() const; + + protected: + /** Copy constructor */ + FairGenerator(const FairGenerator&); + /** Assignment operator */ + FairGenerator& operator=(const FairGenerator&); + + ClassDef(FairGenerator, 1); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairGenericStack.h b/Detectors/3rdparty/FairRootBase/include/FairGenericStack.h new file mode 100644 index 0000000000000..1d71d7d358222 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGenericStack.h @@ -0,0 +1,204 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairGenericStack header file ----- +// ----- Created 10/08/04 by D. Bertini ----- +// ------------------------------------------------------------------------- + +/** FairGenericStack.h + *@author D.Bertini + * Generic MC stack class + **/ + +#ifndef FAIRGENERICSTACK_H +#define FAIRGENERICSTACK_H + +#include // for Double_t, Int_t, etc +#include +#include // for TMCProcess +#include // for TVirtualMCStack +#include +#include + +class FairLogger; +class TParticle; +class TRefArray; +class TIterator; + +class FairGenericStack : public TVirtualMCStack +{ + public: + /** Default constructor **/ + FairGenericStack(); + + /** Destructor with estimated array size **/ + FairGenericStack(Int_t size); + + /** Destructor **/ + virtual ~FairGenericStack(); + + /** Virtual method PushTrack. + ** Add a TParticle to the stack. + ** This function has an extra argument wrt to the function defined in the base class. + *@param toBeDone Flag for tracking + *@param parentID Index of mother particle + *@param pdgCode Particle type (PDG encoding) + *@param px,py,pz Momentum components at start vertex [GeV] + *@param e Total energy at start vertex [GeV] + *@param vx,vy,vz Coordinates of start vertex [cm] + *@param time Start time of track [s] + *@param polx,poly,polz Polarisation vector + *@param proc Production mechanism (VMC encoding) + *@param ntr Track number (filled by the stack) + *@param weight Particle weight + *@param is Generation status code (whatever that means) + *@param secondparentID used fot the index of mother of primery in the list + **/ + virtual void PushTrack(Int_t toBeDone, + Int_t parentID, + Int_t pdgCode, + Double_t px, + Double_t py, + Double_t pz, + Double_t e, + Double_t vx, + Double_t vy, + Double_t vz, + Double_t time, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Int_t& ntr, + Double_t weight, + Int_t is, + Int_t secondparentID) = 0; + + /** Fill the MCTrack output array, applying filter criteria **/ + virtual void FillTrackArray() {} + + /** Update the track index in the MCTracks and MCPoints **/ + virtual void UpdateTrackIndex(TRefArray* /* detArray=0 */) {} + + /** Set the list of detectors to be used for filltering the stack*/ + void SetDetArrayList(TRefArray* detArray); + + /** Allow a stack to perform a clean-up after a primary particle is finished **/ + virtual void FinishPrimary() {} + + /** Resets arrays and stack and deletes particles and tracks **/ + virtual void Reset() {} + + /** Register the MCTrack array to the Root Manager **/ + virtual void Register() {} + + virtual TClonesArray* GetListOfParticles() { return 0; } + virtual void SetParticleArray(__attribute__((unused)) TClonesArray* partArray) {} + virtual void SetParticleArray(__attribute__((unused)) TClonesArray* partArray, + __attribute__((unused)) Int_t partFrom, + __attribute__((unused)) Int_t partTo) + {} + + /** Clone this object (used in MT mode only) */ + virtual FairGenericStack* CloneStack() const; + + /** Fast simulation function to move particle to different position. + In Geant3 it stops the current trajectory, and starts it again in the position given by the user. + In Geant4 the FastSimulationModel with take over. + Later, the points are reindexed and the thus created tracks are not stored in the output. + *@param xx,yy,zz new position of the particle + *@param tt new proper time of the particle + *@param px,py,pz new momentum of the particle + *@param en new energy of the particle + **/ + virtual void FastSimMoveParticleTo(Double_t xx, + Double_t yy, + Double_t zz, + Double_t tt, + Double_t px, + Double_t py, + Double_t pz, + Double_t en); + /** Fast simulation function to stop original particle. **/ + virtual void FastSimStopParticle(); + /** Fast simulation function to generate secondaries. + *@param xx,yy,zz position of the particle + *@param tt proper time of the particle + *@param px,py,pz momentum of the particle + *@param en energy of the particle + **/ + virtual void FastSimPushSecondary(Int_t parentID, + Int_t pdgCode, + Double_t xx, + Double_t yy, + Double_t zz, + Double_t tt, + Double_t px, + Double_t py, + Double_t pz, + Double_t en, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Double_t weight, + Int_t is); + /** Allow FairFastSim the retrieval of moved particle position, p1 and p2 to get secondaries **/ + virtual std::tuple FastSimGetMovedIndex() + { + return std::make_tuple(fFSMovedIndex, fFSFirstSecondary, fFSNofSecondaries); + } + virtual void FastSimClearMovedIndex() + { + fFSMovedIndex = -2; + fFSFirstSecondary = -2; + fFSNofSecondaries = 0; + } + + template + void FastSimUpdateTrackIndex(T* point, Int_t& iTrack); + + protected: + /** Copy constructor */ + FairGenericStack(const FairGenericStack&); + /** Assignment operator */ + FairGenericStack& operator=(const FairGenericStack&); + + /** Fair Logger */ + FairLogger* fLogger; //! + + /** List of detectors registering hits in the simulation */ + TRefArray* fDetList; //! + + /** Iterator for the detector list*/ + TIterator* fDetIter; + + /**Verbosity level*/ + Int_t fVerbose; + + /** FastSimulation: STL map from new track index to original track index **/ + std::map fFSTrackMap; //! + std::map::iterator fFSTrackIter; //! + Int_t fFSMovedIndex; //! + Int_t fFSFirstSecondary; //! + Int_t fFSNofSecondaries; //! + + ClassDef(FairGenericStack, 1); +}; + +template +void FairGenericStack::FastSimUpdateTrackIndex(T* point, Int_t& iTrack) +{ + fFSTrackIter = fFSTrackMap.find(iTrack); // check if point created by FastSimulation + if (fFSTrackIter != fFSTrackMap.end()) { // indeed the point has been created by the FastSimulation mechanism + iTrack = fFSTrackIter->second; + point->SetTrackID(iTrack); // set proper TrackID + } +} + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairGenericVMCConfig.h b/Detectors/3rdparty/FairRootBase/include/FairGenericVMCConfig.h new file mode 100644 index 0000000000000..861c90dc6890e --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGenericVMCConfig.h @@ -0,0 +1,25 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairGenericVMCConfig header file ----- +// ----- Created 2019.02.19 by R. Karabowicz ----- +// ------------------------------------------------------------------------- + +#ifndef FAIR_GENERIC_VMC_CONFIG_H +#define FAIR_GENERIC_VMC_CONFIG_H + +class FairGenericVMCConfig +{ + public: + FairGenericVMCConfig(); + virtual ~FairGenericVMCConfig(); + + virtual void Setup(const char* mcEngine); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoAsciiIo.h b/Detectors/3rdparty/FairRootBase/include/FairGeoAsciiIo.h new file mode 100644 index 0000000000000..fce204578cc83 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoAsciiIo.h @@ -0,0 +1,58 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOASCIIIO_H +#define FAIRGEOASCIIIO_H + +#include "FairGeoIo.h" // for FairGeoIo + +#include // for Bool_t, etc +#include // for TString +#include // for fstream + +class FairGeoSet; +class FairGeoMedia; +class FairGeoInterface; + +/** + * Class for geometry I/O from ASCII file + * @author Ilse Koenig + */ +class FairGeoAsciiIo : public FairGeoIo +{ + TString filename; + TString filedir; + Bool_t writable; + std::fstream* file; + + public: + FairGeoAsciiIo(); + virtual ~FairGeoAsciiIo(); + void setDirectory(const char* fDir) { filedir = fDir; } + const char* getDirectory() { return filedir.Data(); } + const char* getFilename() { return filename.Data(); } + Bool_t open(const char*, const Text_t* status = "in"); + Bool_t isOpen(); + Bool_t isWritable(); + void close(); + void print(); + Bool_t read(FairGeoMedia*); + Bool_t read(FairGeoSet*, FairGeoMedia*); + Bool_t write(FairGeoMedia*); + Bool_t write(FairGeoSet* set); + Bool_t readGeomConfig(FairGeoInterface*); + Bool_t readDetectorSetup(FairGeoInterface*); + Bool_t setSimulRefRun(const char*) { return kTRUE; } + Bool_t setHistoryDate(const char*) { return kTRUE; } + + private: + FairGeoAsciiIo(const FairGeoAsciiIo&); + FairGeoAsciiIo& operator=(const FairGeoAsciiIo&); + ClassDef(FairGeoAsciiIo, 0); // Class for geometry I/O from ASCII file +}; + +#endif /* !FAIRGEOASCIIIO_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoAssembly.h b/Detectors/3rdparty/FairRootBase/include/FairGeoAssembly.h new file mode 100644 index 0000000000000..0c9cb29b0c2e0 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoAssembly.h @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOASSEMBLY_H +#define FAIRGEOASSEMBLY_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoAssembly::Class, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoAssembly : public FairGeoBasicShape +{ + public: + FairGeoAssembly(); + ~FairGeoAssembly(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream* pFile, FairGeoVolume* volu); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + + ClassDef(FairGeoAssembly, 0); // class for geometry shape ASSEMBLY +}; + +#endif /* !FAIRGEOASSEMBLY_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoBasicShape.h b/Detectors/3rdparty/FairRootBase/include/FairGeoBasicShape.h new file mode 100644 index 0000000000000..d6d8745bcfeca --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoBasicShape.h @@ -0,0 +1,54 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOBASICSHAPE_H +#define FAIRGEOBASICSHAPE_H + +#include // for Int_t, etc +#include // for TNamed +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; +/** + * base class for all shapes + * @author Ilse koenig + */ +class FairGeoBasicShape : public TNamed +{ + protected: + Int_t nPoints; // number of points describing the shape + Int_t nParam; // number of parameters needed to create the ROOT shape + TArrayD* param; // parameters needed to create the ROOT shape + FairGeoTransform* center; // position of the volume center in the technical KS + FairGeoTransform* position; // position of the ROOT volume in its ROOT mother + public: + FairGeoBasicShape(); + virtual ~FairGeoBasicShape(); + Int_t getNumPoints() { return nPoints; } + Int_t getNumParam() { return nParam; } + TArrayD* getParam() { return param; } + FairGeoTransform* getCenterPosition() { return center; } + FairGeoTransform* getVoluPosition() { return position; } + virtual Int_t readPoints(std::fstream*, FairGeoVolume*); + virtual Bool_t writePoints(std::fstream*, FairGeoVolume*); + virtual void printPoints(FairGeoVolume* volu); + virtual TArrayD* calcVoluParam(FairGeoVolume*) { return 0; } + virtual void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&); + virtual void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&) { return; } + void printParam(); + + protected: + void posInMother(const FairGeoTransform&, const FairGeoTransform&); + ClassDef(FairGeoBasicShape, 0); // base class for all shapes + private: + FairGeoBasicShape(const FairGeoBasicShape&); + FairGeoBasicShape& operator=(const FairGeoBasicShape&); +}; + +#endif /* !FAIRGEOBASICSHAPE_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoBrik.h b/Detectors/3rdparty/FairRootBase/include/FairGeoBrik.h new file mode 100644 index 0000000000000..82d3ce4d19ad1 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoBrik.h @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOBRIK_H +#define FAIRGEOBRIK_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoBrik::Class, etc + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoBrik : public FairGeoBasicShape +{ + public: + FairGeoBrik(); + ~FairGeoBrik(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + ClassDef(FairGeoBrik, 0); // class for geometry shape BOX or BRIK +}; + +#endif /* !FAIRGEOBRIK_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoBuilder.h b/Detectors/3rdparty/FairRootBase/include/FairGeoBuilder.h new file mode 100644 index 0000000000000..38b77c165dbbb --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoBuilder.h @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOBUILDER_H +#define FAIRGEOBUILDER_H + +#include // for Int_t, etc +#include // for TNamed + +class FairGeoNode; +class FairGeoMedium; + +/** + * abstract base class for geometry builders + * @author ilse koenig + */ +class FairGeoBuilder : public TNamed +{ + protected: + Int_t nRot; // number of defined rotations + Int_t nMed; // number of defined media + + FairGeoBuilder(); + FairGeoBuilder(const char* name, const char* title); + + public: + virtual ~FairGeoBuilder() {} + virtual Bool_t createNode(FairGeoNode*, Int_t hadFormat = 0) = 0; + virtual Int_t createMedium(FairGeoMedium*) = 0; + virtual void finalize() {} + inline const Int_t& GetNMedia() const { return nMed; } + inline void SetNMedia(const Int_t& nmed) { nMed = nmed; } + ClassDef(FairGeoBuilder, 0); +}; + +#endif /* !FAIRGEOBUILDER_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoCone.h b/Detectors/3rdparty/FairRootBase/include/FairGeoCone.h new file mode 100644 index 0000000000000..4846edf0b0050 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoCone.h @@ -0,0 +1,36 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOCONE_H +#define FAIRGEOCONE_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoCone::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; +/** + * class for geometry shape CONE + * @author ilse koenig + */ +class FairGeoCone : public FairGeoBasicShape +{ + public: + FairGeoCone(); + ~FairGeoCone(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoCone, 0); +}; + +#endif /* !FAIRGEOCONE_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoCons.h b/Detectors/3rdparty/FairRootBase/include/FairGeoCons.h new file mode 100644 index 0000000000000..6f727e64cf7b9 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoCons.h @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOCONS_H +#define FAIRGEOCONS_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoCons::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; +/** + * class for geometry shape CONS + * @author ilse koenig + */ +class FairGeoCons : public FairGeoBasicShape +{ + public: + FairGeoCons(); + ~FairGeoCons(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + + ClassDef(FairGeoCons, 0); +}; + +#endif /* !FAIRGEOCONS_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoEltu.h b/Detectors/3rdparty/FairRootBase/include/FairGeoEltu.h new file mode 100644 index 0000000000000..1d7fc697edff5 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoEltu.h @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOELTU_H +#define FAIRGEOELTU_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoEltu::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +/** + * class for geometry shape ELTU + * @author Ilse koenig + */ +class FairGeoEltu : public FairGeoBasicShape +{ + public: + FairGeoEltu(); + ~FairGeoEltu(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoEltu, 0); +}; + +#endif /* !FAIRGEOELTU_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoInterface.h b/Detectors/3rdparty/FairRootBase/include/FairGeoInterface.h new file mode 100644 index 0000000000000..189bce4def7c5 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoInterface.h @@ -0,0 +1,99 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOINTERFACE_H +#define FAIRGEOINTERFACE_H + +#include // for Bool_t, kFALSE, Int_t, etc +#include // for TObject +#include // for TString + +class FairGeoIo; +class FairGeoSet; +class FairGeoMedia; +class FairGeoShapes; +class FairGeoBuilder; +class TObjArray; +class TList; + +enum EHGeoDetPart +{ + kFairGeoCave = 0, + kFairGeoPipe = 1, + kFairGeoTarget = 2, + kFairGeoMagnet = 3, + kFairGeoRich = 4, + kFairGeoSts = 5, + kFairGeoTrd = 6, + kFairGeoTof = 7, + kFairGeoEcal = 8 +}; + +/** + * Class to manage geometry for simulations + * @author Ilse koenig + * @author M. Al-Turany + */ +class FairGeoInterface : public TObject +{ + FairGeoIo* fileInput; /** ASCII file I/O */ + FairGeoIo* oraInput; /** Oracle input */ + FairGeoIo* output; /** Oracle output */ + Int_t nSets; /** number of geometry sets (detector parts) */ + Int_t nActualSets; /** number of set in actual geometry */ + TObjArray* sets; /** array of geometry sets */ + FairGeoMedia* media; /** list of media */ + FairGeoShapes* shapes; /** list of shapes */ + TList* masterNodes; /** list of mother nodes used by several sets */ + TString setupFile; /** file with detector setups (subsets) */ + FairGeoBuilder* geoBuilder; /** actually used geometry builder */ + + public: + FairGeoInterface(); + ~FairGeoInterface(); + void setOracleInput(FairGeoIo* p) { oraInput = p; } + void setOutput(FairGeoIo* p) { output = p; } + void setGeomBuilder(FairGeoBuilder* p) { geoBuilder = p; } + FairGeoIo* getFileInput() { return fileInput; } + FairGeoIo* getOraInput() { return oraInput; } + FairGeoIo* getOutput() { return output; } + FairGeoShapes* getShapes() { return shapes; } + FairGeoMedia* getMedia() { return media; } + TList* getMasterNodes() { return masterNodes; } + void addInputFile(const char*); + void addGeoModule(FairGeoSet*); + void setMediaFile(const char* file); + FairGeoSet* findSet(const char*); + Bool_t readSet(FairGeoSet*); + Bool_t writeSet(FairGeoSet*); + Bool_t writeSet(FairGeoSet*, const char*); + Bool_t createSet(FairGeoSet*); + void deleteSet(FairGeoSet* pSet); + Bool_t readMedia(); + Bool_t writeMedia(); + Bool_t writeMedia(const char*); + Bool_t readAll(); + Bool_t writeAll(); + Bool_t createAll(Bool_t withCleanup = kFALSE); + Bool_t createGeometry(Bool_t withCleanup = kFALSE); + Bool_t readGeomConfig(const char*); + void addSetupFile(const char* f) { setupFile = f; } + Bool_t readSetupFile(); + void print(); + void SetNoOfSets(Int_t n) { nSets = n; } + + private: + FairGeoInterface(const FairGeoInterface&); + FairGeoInterface& operator=(const FairGeoInterface&); + + FairGeoIo* connectInput(const char*); + Bool_t connectOutput(const char*); + + ClassDef(FairGeoInterface, 0); +}; + +#endif /* !FAIRGEOINTERFACE_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoIo.h b/Detectors/3rdparty/FairRootBase/include/FairGeoIo.h new file mode 100644 index 0000000000000..4aeb9dadcf0c2 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoIo.h @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOIO_H +#define FAIRGEOIO_H + +#include // for Bool_t, FairGeoIo::Class, etc +#include // for TObject + +class FairGeoMedia; +class FairGeoSet; +class FairGeoInterface; + +/** + * Abstract base class for geometry I/O + * @author Ilse Koenig + */ +class FairGeoIo : public TObject +{ + public: + virtual Bool_t open(const char*, const Text_t* status = "in") = 0; + virtual void close() = 0; + virtual void print() = 0; + virtual Bool_t isOpen() = 0; + virtual Bool_t isWritable() = 0; + virtual Bool_t read(FairGeoMedia*) = 0; + virtual Bool_t read(FairGeoSet*, FairGeoMedia*) = 0; + virtual Bool_t write(FairGeoMedia*) = 0; + virtual Bool_t write(FairGeoSet*) = 0; + virtual Bool_t readGeomConfig(FairGeoInterface*) = 0; + virtual Bool_t setSimulRefRun(const char*) = 0; + virtual Bool_t setHistoryDate(const char*) = 0; + + private: + ClassDef(FairGeoIo, 0); +}; + +#endif /* !FAIRGEOIO_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoLoader.h b/Detectors/3rdparty/FairRootBase/include/FairGeoLoader.h new file mode 100644 index 0000000000000..e23ad327e62ee --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoLoader.h @@ -0,0 +1,49 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/*************************************************************************** + FairGeoLoader.h - description + ------------------- + begin : Thu Jun 17 2004 + copyright : (C) 2004 by turany + email : m.al-turany@gsi.de + ***************************************************************************/ + +#ifndef FairGeoLOADER_H +#define FairGeoLOADER_H + +#include // for FairGeoLoader::Class, etc +#include // for TNamed + +class FairGeoInterface; +class FairGeoBuilder; +/**New Geometry Loader, this loader handel the Hades geometry description + * @author Ilse koenig + * @author M. Al-Turany*/ + +class FairGeoLoader : public TNamed +{ + public: + FairGeoLoader(const char* Name, const char* title); + FairGeoLoader(); + virtual ~FairGeoLoader(); + FairGeoInterface* getGeoInterface() { return fInterface; } + FairGeoBuilder* getGeoBuilder() { return fGeoBuilder; } + /** static access method*/ + static FairGeoLoader* Instance(); + + private: + FairGeoLoader(const FairGeoLoader&); + FairGeoLoader& operator=(const FairGeoLoader&); + static FairGeoLoader* fgInstance; //! /**Singleton instance*/ + FairGeoInterface* fInterface; //! /** Hades Geometry Interface*/ + FairGeoBuilder* fGeoBuilder; //! /**Geometry builder*/ + + ClassDef(FairGeoLoader, 1); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoMedia.h b/Detectors/3rdparty/FairRootBase/include/FairGeoMedia.h new file mode 100644 index 0000000000000..c057c899ed848 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoMedia.h @@ -0,0 +1,54 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOMEDIA_H +#define FAIRGEOMEDIA_H + +#include // for FairGeoMedia::Class, etc +#include // for TNamed +#include // for TString +#include // for fstream + +class FairGeoMedium; +class TList; + +/** + * Class for materials and media + * @author Ilse koenig + */ +class FairGeoMedia : public TNamed +{ + private: + TList* media; /** list of media */ + TString inputFile; /** name of input file or Oracle */ + TString author; /** author of the media version */ + TString description; /** description of the version */ + public: + FairGeoMedia(); + ~FairGeoMedia(); + void setInputFile(const char* file) { inputFile = file; } + const char* getInputFile() { return inputFile; } + void addMedium(FairGeoMedium* m); + FairGeoMedium* getMedium(const char*); + TList* getListOfMedia() { return media; } + void read(std::fstream&); + void print(); + void list(); + void write(std::fstream&); + void setAuthor(TString& s) { author = s; } + void setDescription(TString& s) { description = s; } + TString& getAuthor() { return author; } + TString& getDescription() { return description; } + + private: + FairGeoMedia(const FairGeoMedia&); + FairGeoMedia& operator=(const FairGeoMedia&); + + ClassDef(FairGeoMedia, 0); +}; + +#endif /* !FAIRGEOMEDIA_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoMedium.h b/Detectors/3rdparty/FairRootBase/include/FairGeoMedium.h new file mode 100644 index 0000000000000..fcf52484508a2 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoMedium.h @@ -0,0 +1,101 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOMEDIUM_H +#define FAIRGEOMEDIUM_H + +#include // for Double_t, Int_t, Bool_t, etc +#include // for TNamed +#include // for fstream + +/** + * Class for tracking medium + * @author ilse koenig + */ +class FairGeoMedium : public TNamed +{ + private: + Int_t medId; /** Unique number for the material and the medium */ + Int_t autoflag; /** Flag for default values of madfld .. minstep*/ + Int_t nComponents; /** Number of material components */ + Int_t weightFac; /** Factor for weights (1: relative w., -1: w. by number of atoms)*/ + Double_t* ca; //[nComponents] /** Atomic weights for the components*/ + Double_t* cz; //[nComponents] /** Atomic numbers for the components*/ + Double_t* cw; //[nComponents] /** Weights of the components in a mixture*/ + Double_t density; /** Density in g cm(**-3)*/ + Double_t radLen; /** Radiation lenght*/ + Int_t sensFlag; /** Sensitivity flag*/ + Int_t fldFlag; /** Field flag*/ + Double_t fld; /** Maximum field value in kilogauss*/ + Double_t epsil; /** Boundary crossing precision*/ + Double_t madfld; /** Maximum angular deviation due to field*/ + Double_t maxstep; /** Maximum step permitted*/ + Double_t maxde; /** Maximum fractional energy loss*/ + Double_t minstep; /** Minimum value for step*/ + Int_t npckov; /** Number of optical parameters for Cerenkov*/ + Double_t* ppckov; //[npckov] /** Photon momentum*/ + Double_t* absco; //[npckov] /** Absoption length*/ + Double_t* effic; //[npckov] /** Detection efficiency*/ + Double_t* rindex; //[npckov] /** Refraction index*/ + public: + FairGeoMedium(const char* name = ""); + FairGeoMedium& operator=(const FairGeoMedium&) { return *this; } + ~FairGeoMedium(); + void setMediumIndex(Int_t i) { medId = i; } + Int_t getMediumIndex() { return medId; } + void setAutoFlag(Int_t i) { autoflag = i; } + Int_t getAutoFlag() { return autoflag; } + void setNComponents(Int_t); + Int_t getNComponents() { return nComponents; } + Bool_t setComponent(Int_t, Double_t, Double_t, Double_t w = 1.); + void getComponent(Int_t, Double_t*); + Int_t getWeightFac() { return weightFac; } + void setDensity(Double_t d) { density = d; } + Double_t getDensity() { return density; } + void setRadiationLength(Double_t l) { radLen = l; } + Double_t getRadiationLength() { return radLen; } + void setNpckov(Int_t); + Int_t getNpckov() { return npckov; } + Bool_t setCerenkovPar(Int_t, Double_t, Double_t, Double_t, Double_t); + void getCerenkovPar(Int_t, Double_t*); + void setMediumPar(Int_t, + Int_t, + Double_t, + Double_t, + Double_t maxDeviation = -1., + Double_t maxStep = -1., + Double_t maxDE = -1., + Double_t minStepDouble_t = -1.); + void getMediumPar(Double_t*); + inline Bool_t isSensitive(); + Int_t getSensitivityFlag() { return sensFlag; } + Int_t getFieldFlag() { return fldFlag; } + Double_t getField() { return fld; } + Double_t getEpsil() { return epsil; } + void read(std::fstream&, Int_t autoflag); + void print(); + void write(std::fstream&); + Bool_t calcRadiationLength(); + + private: + FairGeoMedium(const FairGeoMedium&); + // TODO: correct copy constructor for FairGeoMedium + // FairGeoMedium& operator=(const FairGeoMedium&); + + ClassDef(FairGeoMedium, 1); // +}; + +inline Bool_t FairGeoMedium::isSensitive() +{ + if (sensFlag) { + return kTRUE; + } else { + return kFALSE; + } +} + +#endif /* !FAIRGEOMEDIUM_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoNode.h b/Detectors/3rdparty/FairRootBase/include/FairGeoNode.h new file mode 100644 index 0000000000000..f3f1e9e3320fb --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoNode.h @@ -0,0 +1,155 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEONODE_H +#define FAIRGEONODE_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape +#include "FairGeoMedium.h" // for FairGeoMedium +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for Bool_t, FairGeoNode::Class, etc +#include // for TObjArray +#include // for TString +#include // for fstream + +class FairGeoVector; +class TArrayD; +class TGeoVolume; +class TList; + +enum EFairGeoNodeType +{ + kFairGeoElement = 0, + kFairGeoKeepin = 1, + kFairGeoModule = 2, + kFairGeoTopNode = 3, + kFairGeoRefNode = 4 +}; + +/** + * basic geometry parameters of a volume + * @author Ilse koenig + */ +class FairGeoNode : public FairGeoVolume +{ + private: + FairGeoNode(const FairGeoNode&); + FairGeoNode& operator=(const FairGeoNode&); + + protected: + Bool_t active; /** in/out flag for creation */ + FairGeoTransform center; /** position of the GEANT/ROOT center */ + EFairGeoNodeType volumeType; /** type of volume */ + Bool_t created; /** Flag set kTRUE after creation of volume */ + FairGeoNode* copyNode; /** pointer to the reference volume for a copy */ + TGeoVolume* rootVolume; /** pointer to the ROOT node */ + FairGeoBasicShape* pShape; /** pointer to the shape */ + FairGeoNode* pMother; //! /** pointer to the mother volume */ + FairGeoMedium* medium; /** pointer to medium */ + FairGeoTransform* labTransform; /** Transformation to the LAB system */ + TObjArray* fDaughterList; /** List of daughter Nodes */ + // const char* fTruncName; // + TString fTruncName; + + public: + FairGeoNode(); + FairGeoNode(FairGeoNode&); + virtual ~FairGeoNode(); + void AddDaughter(FairGeoNode* fNode) { fDaughterList->AddLast(fNode); } + TObjArray* GetListOfDaughters() { return fDaughterList; } + EFairGeoNodeType getVolumeType() { return volumeType; } + Bool_t isTopNode() { return static_cast((volumeType == kFairGeoTopNode)); } + Bool_t isRefNode() { return static_cast((volumeType == kFairGeoRefNode)); } + Bool_t isKeepin() { return static_cast((volumeType == kFairGeoKeepin)); } + Bool_t isModule() { return static_cast((volumeType == kFairGeoModule)); } + Int_t getCopyNo(); + FairGeoBasicShape* getShapePointer() { return pShape; } + FairGeoNode* getMotherNode() { return pMother; } + FairGeoMedium* getMedium() { return medium; } + Bool_t isActive() { return active; } + FairGeoTransform& getCenterPosition() { return center; } + TArrayD* getParameters(); + FairGeoTransform* getPosition(); + FairGeoTransform* getLabTransform(); + FairGeoNode* getCopyNode() { return copyNode; } + TGeoVolume* getRootVolume() { return rootVolume; } + TList* getTree(); + Bool_t isSensitive(); + Bool_t isCreated() { return created; } + void setCreated() { created = kTRUE; } + void setName(const Text_t* s); + void setVolumeType(EFairGeoNodeType t) { volumeType = t; } + void setVolumePar(FairGeoNode&); + void setShape(FairGeoBasicShape* s); + void setMother(FairGeoNode* s); + void setMedium(FairGeoMedium* med) { medium = med; } + void setActive(Bool_t a = kTRUE) { active = a; } + void setCenterPosition(const FairGeoTransform& t) { center = t; } + void setCopyNode(FairGeoNode* p) { copyNode = p; } + void setRootVolume(TGeoVolume* p) { rootVolume = p; } + FairGeoTransform* calcLabTransform(); + void setLabTransform(FairGeoTransform&); + Bool_t calcModuleTransform(FairGeoTransform&); + Bool_t calcRefPos(FairGeoVector&); + void clear(); + void print(); + Bool_t write(std::fstream&); + Int_t compare(FairGeoNode&); + + void setTruncName(const char* aName) { fTruncName = aName; } + const char* getTruncName() + { + if (fTruncName.Length() > 0) { + return fTruncName.Data(); + } else { + return GetName(); + } + } + + ClassDef(FairGeoNode, 1); // +}; + +// -------------------- inlines -------------------------- + +inline void FairGeoNode::setName(const Text_t* s) +{ + // Sets the name of the volume + fName = s; + fName.ToUpper(); +} + +inline void FairGeoNode::setShape(FairGeoBasicShape* s) +{ + // Sets the shape of the volume + if (s) { + pShape = s; + shape = pShape->GetName(); + } +} + +inline void FairGeoNode::setMother(FairGeoNode* moth) +{ + // Sets the mother of the volume + if (moth) { + pMother = moth; + mother = pMother->GetName(); + pMother->AddDaughter(this); + } +} + +inline Bool_t FairGeoNode::isSensitive() +{ + if (medium) { + return medium->isSensitive(); + } else { + return kFALSE; + } +} + +#endif /* !FAIRGEONODE_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoPcon.h b/Detectors/3rdparty/FairRootBase/include/FairGeoPcon.h new file mode 100644 index 0000000000000..a411e154cdae6 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoPcon.h @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOPCON_H +#define FAIRGEOPCON_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoPcon::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +/** + * class for geometry shape PCON + * @author Ilse koenig + */ +class FairGeoPcon : public FairGeoBasicShape +{ + public: + FairGeoPcon(); + ~FairGeoPcon(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoPcon, 0); // +}; + +#endif /* !FAIRGEOPCON_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoPgon.h b/Detectors/3rdparty/FairRootBase/include/FairGeoPgon.h new file mode 100644 index 0000000000000..8197d49aa3290 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoPgon.h @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOPGON_H +#define FAIRGEOPGON_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoPcon::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +/** + * class for geometry shape PGON + * @author Ilse koenig + */ +class FairGeoPgon : public FairGeoBasicShape +{ + public: + FairGeoPgon(); + ~FairGeoPgon(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoPgon, 0); // +}; + +#endif /* !FAIRGEOPGON_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoRootBuilder.h b/Detectors/3rdparty/FairRootBase/include/FairGeoRootBuilder.h new file mode 100644 index 0000000000000..ef92d2c41117c --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoRootBuilder.h @@ -0,0 +1,44 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOROOTBUILDER_H +#define FAIRGEOROOTBUILDER_H + +#include "FairGeoBuilder.h" // for FairGeoBuilder + +#include // for FairGeoRootBuilder::Class, etc + +class FairGeoMedium; +class FairGeoNode; +class TGeoManager; + +/** + * class to create geometry in ROOT + * @author M. Al-Turany + */ +class FairGeoRootBuilder : public FairGeoBuilder +{ + private: + FairGeoRootBuilder(const FairGeoRootBuilder&); + FairGeoRootBuilder& operator=(const FairGeoRootBuilder&); + + protected: + TGeoManager* geoManager; // ROOT geometry manager + + public: + FairGeoRootBuilder(); + FairGeoRootBuilder(const char*, const char*); + ~FairGeoRootBuilder() {} + void setGeoManager(TGeoManager* me) { geoManager = me; } + Bool_t createNode(FairGeoNode*, Int_t hadFormat = 0); + Int_t createMedium(FairGeoMedium*); + void finalize(); + void checkOverlaps(Double_t ovlp = 0.0001); + ClassDef(FairGeoRootBuilder, 0); // +}; + +#endif /* !FAIRGEOROOTBUILDER_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoRotation.h b/Detectors/3rdparty/FairRootBase/include/FairGeoRotation.h new file mode 100644 index 0000000000000..9a8c3af906e32 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoRotation.h @@ -0,0 +1,225 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOROTATION_H +#define FAIRGEOROTATION_H + +#include "FairGeoVector.h" // for FairGeoVector + +#include // for Double_t, Int_t, Bool_t, etc +#include // for TObject +#include // for operator<<, cout, ostream, etc + +class TRotMatrix; + +/** + * rotation matrix + * @author Ilse koenig + */ +class FairGeoRotation : public TObject +{ + protected: + Double_t rot[9]; + + public: + inline FairGeoRotation(); + inline FairGeoRotation(const FairGeoRotation&); + inline FairGeoRotation(const Double_t*); + FairGeoRotation(const Double_t, const Double_t, const Double_t); + ~FairGeoRotation() {} + inline void setMatrix(const Double_t*); + inline void setMatrix(const Float_t*); + void setEulerAngles(const Double_t, const Double_t, const Double_t); + inline void setElement(const Double_t, const Int_t); + inline Double_t operator()(Int_t) const; + inline FairGeoRotation& operator=(const FairGeoRotation&); + inline Bool_t operator==(const FairGeoRotation&); + inline Bool_t operator!=(const FairGeoRotation&); + inline FairGeoVector operator*(const FairGeoVector&)const; + inline FairGeoRotation operator*(const FairGeoRotation&)const; + inline FairGeoRotation& operator*=(const FairGeoRotation&); + inline FairGeoRotation& transform(const FairGeoRotation&); + inline Bool_t isUnitMatrix(); + inline FairGeoRotation inverse() const; + inline FairGeoRotation& invert(); + inline Double_t determinant() const; + Double_t diff2(const FairGeoRotation&) const; + inline Double_t getElement(Int_t i, Int_t j) const; + inline void setUnitMatrix(); + inline void setZero(); + inline void print() const; + TRotMatrix* createTRotMatrix(const Text_t* name = "", const Text_t* title = ""); + + ClassDef(FairGeoRotation, 1); // +}; + +// -------------------- inlines --------------------------- + +inline FairGeoRotation::FairGeoRotation() + : TObject() +{ + rot[0] = rot[4] = rot[8] = 1.; + rot[1] = rot[2] = rot[3] = rot[5] = rot[6] = rot[7] = 0.; +} + +inline Double_t FairGeoRotation::operator()(Int_t i) const +{ + if (i >= 0 && i < 9) { + return rot[i]; + } + Error("operator()", "bad index"); + return 0; +} + +inline FairGeoRotation::FairGeoRotation(const FairGeoRotation& r) + : TObject(r) +{ + for (Int_t i = 0; i < 9; i++) { + rot[i] = r(i); + } +} + +inline FairGeoRotation::FairGeoRotation(const Double_t* a) + : TObject() +{ + for (Int_t i = 0; i < 9; i++) { + rot[i] = a[i]; + } +} + +inline void FairGeoRotation::setMatrix(const Double_t* a) +{ + for (Int_t i = 0; i < 9; i++) { + rot[i] = a[i]; + } +} + +inline void FairGeoRotation::setMatrix(const Float_t* a) +{ + for (Int_t i = 0; i < 9; i++) { + rot[i] = a[i]; + } +} + +inline void FairGeoRotation::setElement(const Double_t a, const Int_t i) +{ + if (i < 9) { + rot[i] = a; + } +} + +inline Double_t FairGeoRotation::getElement(Int_t i, Int_t j) const { return rot[i * 3 + j]; } + +inline FairGeoRotation& FairGeoRotation::operator=(const FairGeoRotation& r) +{ + for (Int_t i = 0; i < 9; i++) { + rot[i] = r(i); + } + return *this; +} + +inline Bool_t FairGeoRotation::operator==(const FairGeoRotation& r) +{ + Int_t i = 0; + while (i < 9) { + if (rot[i] != r(i)) { + return kFALSE; + } + i++; + } + return kTRUE; +} + +inline Bool_t FairGeoRotation::operator!=(const FairGeoRotation& r) +{ + Int_t i = 0; + while (i < 9) { + if (rot[i] != r(i)) { + return kTRUE; + } + i++; + } + return kFALSE; +} + +inline FairGeoVector FairGeoRotation::operator*(const FairGeoVector& v) const +{ + return FairGeoVector(rot[0] * v(0) + rot[1] * v(1) + rot[2] * v(2), + rot[3] * v(0) + rot[4] * v(1) + rot[5] * v(2), + rot[6] * v(0) + rot[7] * v(1) + rot[8] * v(2)); +} + +inline FairGeoRotation FairGeoRotation::operator*(const FairGeoRotation& r) const +{ + Double_t a[9]; + for (Int_t kk = 0; kk < 9; kk++) { + a[kk] = 0; + } + for (Int_t i = 0; i < 3; i++) { + for (Int_t j = 0; j < 3; j++) { + Int_t n = 3 * i + j; + for (Int_t k = 0; k < 3; k++) { + a[n] += rot[3 * i + k] * r(3 * k + j); + } + } + } + return FairGeoRotation(&a[0]); +} + +inline FairGeoRotation& FairGeoRotation::operator*=(const FairGeoRotation& r) { return *this = operator*(r); } + +inline FairGeoRotation& FairGeoRotation::transform(const FairGeoRotation& r) { return *this = r * (*this); } + +inline Bool_t FairGeoRotation::isUnitMatrix() +{ + return (rot[0] == 1. && rot[1] == 0. && rot[2] == 0. && rot[3] == 0. && rot[4] == 1. && rot[5] == 0. && rot[6] == 0. + && rot[7] == 0. && rot[8] == 1.) + ? kTRUE + : kFALSE; +} + +inline FairGeoRotation FairGeoRotation::inverse() const +{ + Double_t a[9]; + for (Int_t i = 0; i < 3; i++) { + for (Int_t j = 0; j < 3; j++) { + a[j + 3 * i] = rot[i + 3 * j]; + } + } + return FairGeoRotation(a); +} + +inline FairGeoRotation& FairGeoRotation::invert() { return *this = inverse(); } + +inline Double_t FairGeoRotation::determinant() const +{ + return rot[0] * (rot[4] * rot[8] - rot[7] * rot[5]) - rot[3] * (rot[1] * rot[8] - rot[7] * rot[2]) + + rot[6] * (rot[1] * rot[5] - rot[4] * rot[2]); +} + +inline void FairGeoRotation::setUnitMatrix() +{ + rot[0] = rot[4] = rot[8] = 1.; + rot[1] = rot[2] = rot[3] = rot[5] = rot[6] = rot[7] = 0.; +} + +inline void FairGeoRotation::setZero() +{ + for (Int_t i = 0; i < 9; i++) { + rot[i] = 0.; + } +} + +inline void FairGeoRotation::print() const +{ + for (Int_t i = 0; i < 9; i++) { + std::cout << rot[i] << " "; + } + std::cout << '\n'; +} + +#endif /* !FAIRGEOROTATION_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoSet.h b/Detectors/3rdparty/FairRootBase/include/FairGeoSet.h new file mode 100644 index 0000000000000..cd36eda767e25 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoSet.h @@ -0,0 +1,109 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOSET_H +#define FAIRGEOSET_H + +#include "FairGeoNode.h" + +#include // for Int_t, Bool_t, etc +#include // for TList +#include // for TNamed +#include // for TString +#include // for fstream + +// class FairGeoNode; +class FairGeoShapes; +class FairGeoMedia; +class FairGeoBuilder; +class FairGeoTransform; +class TArrayI; + +/** + * Base class for geometry of detector parts + * @author Ilse koenig + */ +class FairGeoSet : public TNamed +{ + protected: + Int_t hadesGeo; + + class FairGeoCopyNode : public TNamed + { + public: + FairGeoNode* pNode; + FairGeoCopyNode(const char* name, FairGeoNode* node) + : TNamed(name, "") + , pNode(node) + {} + // SetName(name); + // + // } + ~FairGeoCopyNode() {} + + private: + FairGeoCopyNode(const FairGeoCopyNode&); + FairGeoCopyNode& operator=(const FairGeoCopyNode&); + }; + + TList* volumes; /** list of volumes */ + TList* masterNodes; /** pointer to list of mother volumes from other detector parts*/ + Int_t maxSectors; /** maximum number of sectors (-1 for detectors outside any sector)*/ + Int_t maxKeepinVolumes; /** maximum number of keepin volumes per sector*/ + Int_t maxModules; /** maximum number of modules per sector*/ + TArrayI* modules; /** Module's array.*/ + FairGeoShapes* pShapes; /** pointer to the class FairGeoShapes*/ + TString geoFile; /** name of geometry input file or Oracle*/ + TString author; /** author of the media version*/ + TString description; /** description of the version*/ + + FairGeoSet(); + void readInout(std::fstream&); + void readTransform(std::fstream&, FairGeoTransform&); + Bool_t readVolumeParams(std::fstream&, FairGeoMedia*, FairGeoNode*, TList* l = 0); + Bool_t readKeepIn(std::fstream&, FairGeoMedia*, TString&); + Bool_t readModule(std::fstream&, FairGeoMedia*, TString&, TString&, Bool_t a = kFALSE); + + public: + virtual ~FairGeoSet(); + void setShapes(FairGeoShapes* s) { pShapes = s; } + void setMasterNodes(TList* m) { masterNodes = m; } + void setGeomFile(const char* filename) { geoFile = filename; } + const char* getGeomFile() { return geoFile.Data(); } + Int_t getMaxSectors(void) { return maxSectors; } + Int_t getMaxModules(void) { return maxModules; } + Int_t getMaxKeepinVolumes(void) { return maxKeepinVolumes; } + void setModules(Int_t, Int_t*); + Int_t* getModules(void); + Int_t getModule(Int_t, Int_t); + FairGeoNode* getVolume(const char* name) { return dynamic_cast(volumes->FindObject(name)); } + FairGeoNode* getMasterNode(const char* name) { return dynamic_cast(masterNodes->FindObject(name)); } + TList* getListOfVolumes() { return volumes; } + FairGeoShapes* getShapes() { return pShapes; } + void setAuthor(TString& s) { author = s; } + void setDescription(TString& s) { description = s; } + TString& getAuthor() { return author; } + TString& getDescription() { return description; } + virtual const char* getKeepinName(Int_t, Int_t) { return 0; } + virtual const char* getModuleName(Int_t) { return 0; } + virtual const char* getEleName(Int_t) { return 0; } + virtual Int_t getSecNumInMod(const TString&) { return -1; } + virtual Int_t getModNumInMod(const TString&) { return 0; } + virtual Bool_t read(std::fstream&, FairGeoMedia*); + virtual void addRefNodes() {} + virtual void write(std::fstream&); + virtual void print(); + virtual Bool_t create(FairGeoBuilder*); + void compare(FairGeoSet&); + ClassDef(FairGeoSet, 0); // + + private: + FairGeoSet(const FairGeoSet&); + FairGeoSet& operator=(const FairGeoSet&); +}; + +#endif /* !FAIRGEOSET_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoShapes.h b/Detectors/3rdparty/FairRootBase/include/FairGeoShapes.h new file mode 100644 index 0000000000000..51625efb7af00 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoShapes.h @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOSHAPES_H +#define FAIRGEOSHAPES_H + +#include // for FairGeoShapes::Class, etc +#include // for TObject +#include // for TString +#include // for fstream + +class FairGeoVolume; +class FairGeoBasicShape; +class TList; +/** + * manager class for geometry shapes + * @author Ilse koenig + */ +class FairGeoShapes : public TObject +{ + private: + FairGeoShapes(const FairGeoShapes&); + FairGeoShapes& operator=(const FairGeoShapes&); + + protected: + TList* shapes; // list of already created shape classes + + public: + FairGeoShapes(); + ~FairGeoShapes(); + FairGeoBasicShape* selectShape(FairGeoVolume*); + FairGeoBasicShape* selectShape(const TString&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoShapes, 0); // +}; + +#endif /* !FAIRGEOSHAPES_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoSphe.h b/Detectors/3rdparty/FairRootBase/include/FairGeoSphe.h new file mode 100644 index 0000000000000..f91a87d5185f5 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoSphe.h @@ -0,0 +1,37 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOSPHE_H +#define FAIRGEOSPHE_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoPcon::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +/** + * class for geometry shape SPHE + * @author Ilse koenig + */ +class FairGeoSphe : public FairGeoBasicShape +{ + public: + FairGeoSphe(); + ~FairGeoSphe(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoSphe, 0); // +}; + +#endif /* !FAIRGEOSPHE_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoTorus.h b/Detectors/3rdparty/FairRootBase/include/FairGeoTorus.h new file mode 100644 index 0000000000000..42f78e0b57fb0 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoTorus.h @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOTORUS_H +#define FAIRGEOTORUS_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoPcon::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoTorus : public FairGeoBasicShape +{ + public: + FairGeoTorus(); + ~FairGeoTorus(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream* pFile, FairGeoVolume* volu); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + + ClassDef(FairGeoTorus, 0); // class for geometry shape TORUS +}; + +#endif /* !FAIRGEOTORUS_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoTransform.h b/Detectors/3rdparty/FairRootBase/include/FairGeoTransform.h new file mode 100644 index 0000000000000..609317e0dbbb1 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoTransform.h @@ -0,0 +1,73 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOTRANSFORM_H +#define FAIRGEOTRANSFORM_H + +#include "FairGeoRotation.h" // for FairGeoRotation +#include "FairGeoVector.h" // for FairGeoVector + +#include // for Double_t, etc +#include // for TObject + +/** + * basic geometry transformation class + * @author Ilse koenig*/ +class FairGeoTransform : public TObject +{ + protected: + FairGeoRotation rot; /** rotation matrix, describing the orientation*/ + FairGeoVector trans; /** translation vector, describing the position*/ + FairGeoVector trans_cm; /** translation vector, describing the position in cm*/ + + public: + FairGeoTransform(); + inline FairGeoTransform(const FairGeoTransform& t); + ~FairGeoTransform() {} + FairGeoTransform& operator=(const FairGeoTransform& t); + const FairGeoRotation& getRotMatrix() const { return rot; } + const FairGeoVector& getTransVector() const { return trans; } + void setRotMatrix(const FairGeoRotation& r) { rot = r; } + void setRotMatrix(const Double_t* a) { rot.setMatrix(a); } + void setRotMatrix(const Float_t* a) { rot.setMatrix(a); } + void setTransVector(const FairGeoVector& t) { trans = t; } + void setTransVector(const Double_t* a) { trans.setVector(a); } + void setTransVector(const Float_t* a) { trans.setVector(a); } + FairGeoVector transFrom(const FairGeoVector& p) const; + FairGeoVector transTo(const FairGeoVector& p) const; + void transFrom(const FairGeoTransform&); + void transTo(const FairGeoTransform&); + void invert(void); + void clear(); + void print(); + const FairGeoVector& getTranslation() + { + const double fac = 10.; + trans_cm = trans; + return (trans_cm /= fac); + } + + const FairGeoRotation& getRotation() const { return rot; } + + inline void setTransform(const FairGeoTransform& t); + ClassDef(FairGeoTransform, 1); // +}; + +inline FairGeoTransform::FairGeoTransform(const FairGeoTransform& t) + : TObject(t) + , rot(t.getRotMatrix()) + , trans(t.getTransVector()) + , trans_cm(FairGeoVector(0, 0, 0)) +{} + +inline void FairGeoTransform::setTransform(const FairGeoTransform& t) +{ + rot = t.getRotMatrix(); + trans = t.getTransVector(); +} + +#endif /* !FAIRGEOTRANSFORM_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoTrap.h b/Detectors/3rdparty/FairRootBase/include/FairGeoTrap.h new file mode 100644 index 0000000000000..85d893e171bf8 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoTrap.h @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOTRAP_H +#define FAIRGEOTRAP_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape +#include "FairGeoRotation.h" // for FairGeoRotation + +#include // for FairGeoPcon::Class, Bool_t, etc + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoTrap : public FairGeoBasicShape +{ + private: + FairGeoRotation intrinsicRot; + + public: + FairGeoTrap(); + ~FairGeoTrap(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + ClassDef(FairGeoTrap, 0); // class for geometry shape TRAP +}; + +#endif /* !FAIRGEOTRAP_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoTrd1.h b/Detectors/3rdparty/FairRootBase/include/FairGeoTrd1.h new file mode 100644 index 0000000000000..edc77254b922b --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoTrd1.h @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOTRD1_H +#define FAIRGEOTRD1_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape +#include "FairGeoRotation.h" // for FairGeoRotation + +#include // for FairGeoPcon::Class, Bool_t, etc + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoTrd1 : public FairGeoBasicShape +{ + private: + FairGeoRotation intrinsicRot; + + public: + FairGeoTrd1(); + ~FairGeoTrd1(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + + ClassDef(FairGeoTrd1, 0); // class for geometry shape TRD1 +}; + +#endif /* !FAIRGEOTRD1_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoTube.h b/Detectors/3rdparty/FairRootBase/include/FairGeoTube.h new file mode 100644 index 0000000000000..1d8501275cf1e --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoTube.h @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOTUBE_H +#define FAIRGEOTUBE_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoPcon::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoTube : public FairGeoBasicShape +{ + public: + FairGeoTube(); + ~FairGeoTube(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoTube, 0); // class for geometry shape TUBE +}; + +#endif /* !FAIRGEOTUBE_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoTubs.h b/Detectors/3rdparty/FairRootBase/include/FairGeoTubs.h new file mode 100644 index 0000000000000..b26615f87a28f --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoTubs.h @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOTUBS_H +#define FAIRGEOTUBS_H + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape + +#include // for FairGeoPcon::Class, Bool_t, etc +#include // for fstream + +class FairGeoTransform; +class FairGeoVolume; +class TArrayD; + +class FairGeoTubs : public FairGeoBasicShape +{ + public: + FairGeoTubs(); + ~FairGeoTubs(); + TArrayD* calcVoluParam(FairGeoVolume*); + void calcVoluPosition(FairGeoVolume*, const FairGeoTransform&, const FairGeoTransform&); + Int_t readPoints(std::fstream*, FairGeoVolume*); + Bool_t writePoints(std::fstream*, FairGeoVolume*); + void printPoints(FairGeoVolume* volu); + ClassDef(FairGeoTubs, 0); // class for geometry shape TUBS +}; + +#endif /* !FAIRGEOTUBS_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoVector.h b/Detectors/3rdparty/FairRootBase/include/FairGeoVector.h new file mode 100644 index 0000000000000..49eba5e89cc3f --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoVector.h @@ -0,0 +1,278 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOVECTOR_H +#define FAIRGEOVECTOR_H + +#include // for Double_t, Bool_t, Int_t, etc +#include // for pow, floor, sqrt +#include // for Abs +#include // for TObject +#include +#include // for operator<<, ostream, etc +#include // for printf + +class FairGeoVector : public TObject +{ + protected: + Double_t x; + Double_t y; + Double_t z; + inline void round(Double_t d, Int_t n); + + public: + FairGeoVector(Double_t dx = 0, Double_t dy = 0, Double_t dz = 0) + : TObject() + , x(dx) + , y(dy) + , z(dz) + {} + FairGeoVector(const FairGeoVector& v) + : TObject(v) + , x(v.getX()) + , y(v.getY()) + , z(v.getZ()) + {} + ~FairGeoVector() {} + Double_t& X() { return x; } + Double_t& Y() { return y; } + Double_t& Z() { return z; } + Double_t getX() const { return x; } + Double_t getY() const { return y; } + Double_t getZ() const { return z; } + + Double_t getValues(Int_t i) + { + if (i < 0 || i > 2) { + std::cout << " -E- Vector index is 0 1 2 only ! " << std::endl; + } + if (i == 0) { + return x; + } + if (i == 1) { + return y; + } + if (i == 2) { + return z; + } + return -1; + } + + void setXYZ(const Double_t xx, const Double_t yy, const Double_t zz) + { + x = xx; + y = yy; + z = zz; + } + void setX(const Double_t a) { x = a; } + void setY(const Double_t a) { y = a; } + void setZ(const Double_t a) { z = a; } + inline void setVector(const Double_t* a); + inline void setVector(const Float_t* a); + inline Double_t operator()(const Int_t i) const; + inline FairGeoVector operator-() const; + inline FairGeoVector& operator=(const FairGeoVector& v); + inline Bool_t operator==(const FairGeoVector& v) const; + inline Bool_t operator!=(const FairGeoVector& v) const; + inline Bool_t operator<(const Double_t a); + inline Bool_t operator<=(const Double_t a); + inline Bool_t operator>(const Double_t a); + inline Bool_t operator>=(const Double_t a); + inline FairGeoVector& operator+=(const Double_t a); + inline FairGeoVector& operator-=(const Double_t a); + inline FairGeoVector& operator*=(const Double_t a); + inline FairGeoVector& operator/=(const Double_t a); + inline FairGeoVector& operator+=(const FairGeoVector& v); + inline FairGeoVector& operator-=(const FairGeoVector& v); + inline FairGeoVector operator+(const FairGeoVector& v) const; + inline FairGeoVector operator-(const FairGeoVector& v) const; + inline FairGeoVector& abs(); + inline Double_t scalarProduct(const FairGeoVector& v) const; + inline FairGeoVector vectorProduct(const FairGeoVector& v) const; + Double_t length() const { return sqrt(x * x + y * y + z * z); } + void clear() { x = y = z = 0.; } + void print() const { printf("%10.3f%10.3f%10.3f\n", x, y, z); } + inline void round(Int_t n); + inline friend std::ostream& operator<<(std::ostream& put, const FairGeoVector& v); + inline friend std::istream& operator>>(std::istream& get, FairGeoVector& v); + ClassDef(FairGeoVector, 1); // vector with 3 components +}; + +// -------------------- inlines --------------------------- + +inline void FairGeoVector::setVector(const Double_t* a) +{ + x = a[0]; + y = a[1]; + z = a[2]; +} + +inline void FairGeoVector::setVector(const Float_t* a) +{ + x = a[0]; + y = a[1]; + z = a[2]; +} + +inline Double_t FairGeoVector::operator()(const Int_t i) const +{ + switch (i) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + Error("operator()", "bad index"); + } + return 0; +} + +inline FairGeoVector FairGeoVector::operator-() const +{ + FairGeoVector p(-x, -y, -z); + return p; +} + +inline FairGeoVector& FairGeoVector::operator=(const FairGeoVector& v) +{ + x = v.getX(); + y = v.getY(); + z = v.getZ(); + return *this; +} + +inline Bool_t FairGeoVector::operator==(const FairGeoVector& v) const +{ + return ((v.getX() != x || v.getY() != y || v.getZ() != z) ? kFALSE : kTRUE); +} + +inline Bool_t FairGeoVector::operator!=(const FairGeoVector& v) const +{ + return (v.getX() != x || v.getY() != y || v.getZ() != z) ? kTRUE : kFALSE; +} +/// check with ilse +inline Bool_t FairGeoVector::operator<(const Double_t a) { return (x >= a || y >= a || z >= a) ? kFALSE : kTRUE; } + +inline Bool_t FairGeoVector::operator<=(const Double_t a) { return (x > a || y > a || z > a) ? kFALSE : kTRUE; } + +inline Bool_t FairGeoVector::operator>(const Double_t a) { return (x <= a || y <= a || z <= a) ? kFALSE : kTRUE; } + +inline Bool_t FairGeoVector::operator>=(const Double_t a) { return (x < a || y < a || z < a) ? kFALSE : kTRUE; } + +inline FairGeoVector& FairGeoVector::operator+=(const Double_t a) +{ + x += a; + y += a; + z += a; + return *this; +} + +inline FairGeoVector& FairGeoVector::operator-=(const Double_t a) +{ + x -= a; + y -= a; + z -= a; + return *this; +} + +inline FairGeoVector& FairGeoVector::operator*=(const Double_t a) +{ + x *= a; + y *= a; + z *= a; + return *this; +} + +inline FairGeoVector& FairGeoVector::operator/=(const Double_t a) +{ + x /= a; + y /= a; + z /= a; + return *this; +} + +inline FairGeoVector& FairGeoVector::operator+=(const FairGeoVector& v) +{ + x += v.getX(); + y += v.getY(); + z += v.getZ(); + return *this; +} + +inline FairGeoVector& FairGeoVector::operator-=(const FairGeoVector& v) +{ + x -= v.getX(); + y -= v.getY(); + z -= v.getZ(); + return *this; +} + +inline FairGeoVector FairGeoVector::operator+(const FairGeoVector& v) const +{ + FairGeoVector p(*this); + return p += v; +} + +inline FairGeoVector FairGeoVector::operator-(const FairGeoVector& v) const +{ + FairGeoVector p(*this); + return p -= v; +} + +inline FairGeoVector& FairGeoVector::abs() +{ + x = TMath::Abs(x); + y = TMath::Abs(y); + z = TMath::Abs(z); + return *this; +} + +inline Double_t FairGeoVector::scalarProduct(const FairGeoVector& v) const +{ + return (x * v.getX() + y * v.getY() + z * v.getZ()); +} + +inline FairGeoVector FairGeoVector::vectorProduct(const FairGeoVector& v) const +{ + FairGeoVector p(y * v.getZ() - z * v.getY(), z * v.getX() - x * v.getZ(), x * v.getY() - y * v.getX()); + return p; +} + +inline void FairGeoVector::round(Double_t d, Int_t n) +{ + // rounds d to a precision with n digits + if (d > 0) { + d = floor(d * pow(10., n) + 0.5) / pow(10., n); + } else { + d = -floor((-d) * pow(10., n) + 0.5) / pow(10., n); + } +} + +inline void FairGeoVector::round(Int_t n) +{ + // rounds every component to a precision with n digits + round(x, n); + round(y, n); + round(z, n); +} + +inline std::ostream& operator<<(std::ostream& put, const FairGeoVector& v) +{ + return put << v(0) << " " << v(1) << " " << v(2) << '\n'; +} + +inline std::istream& operator>>(std::istream& get, FairGeoVector& v) +{ + Double_t x[3]; + get >> x[0] >> x[1] >> x[2]; + v.setVector(x); + return get; +} + +#endif /* !FAIRGEOVECTOR_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairGeoVolume.h b/Detectors/3rdparty/FairRootBase/include/FairGeoVolume.h new file mode 100644 index 0000000000000..696e9528c8eb2 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairGeoVolume.h @@ -0,0 +1,112 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRGEOVOLUME_H +#define FAIRGEOVOLUME_H + +#include "FairGeoMedium.h" // for FairGeoMedium +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector + +#include // for Int_t, Text_t, Double_t, etc +#include // for TNamed +#include // for TObjArray +#include // for TString +#include // for NULL + +/** + * basic geometry parameters of a volume + * @author Ilse koenig + */ +class FairGeoVolume : public TNamed +{ + private: + FairGeoVolume& operator=(const FairGeoVolume&); + + protected: + TString shape; /**eant shape of the volume*/ + TString mother; /** Name of the mother volume*/ + TObjArray* points; /** array of points (type FairGeoVector)*/ + FairGeoTransform transform; /** transformation relative to the mother system */ + FairGeoTransform fLabTransform; /** transformation to the LAB system; */ + FairGeoMedium fMedium; /** medium properties */ + Int_t nPoints; /** number of points */ + Int_t fHadFormat; // + Int_t fgMCid; /** Volume Id given by MC*/ + + public: + inline FairGeoVolume(); + FairGeoVolume(FairGeoVolume&); + virtual ~FairGeoVolume(); + const TString& getName() const { return fName; } + const TString& getShape() const { return shape; } + const TString& getMother() const { return mother; } + FairGeoTransform& getTransform() { return transform; } + FairGeoTransform& getLabTransform() { return fLabTransform; } + FairGeoMedium& getMedium() { return fMedium; } + Int_t getNumPoints() { return nPoints; } + inline FairGeoVector* getPoint(const Int_t n); + inline void setName(const Text_t* s); + void setVolumePar(FairGeoVolume&); + inline void setShape(const Text_t* s); + inline void setMother(const Text_t* s); + void createPoints(const Int_t); + void setPoint(const Int_t, const Double_t, const Double_t, const Double_t); + void setPoint(const Int_t, const FairGeoVector&); + virtual void clear(); + virtual void print(); + virtual void setHadFormat(Int_t i) { fHadFormat = i; } + Double_t getVolParameter(Int_t nPoint, Int_t pos); + Int_t getMCid() { return fgMCid; } + void setMCid(Int_t MCid) { fgMCid = MCid; } + + ClassDef(FairGeoVolume, 1); // +}; + +// -------------------- inlines -------------------------- + +inline FairGeoVolume::FairGeoVolume() + : TNamed() + , shape("") + , mother("") + , points(NULL) + , transform(FairGeoTransform()) + , fLabTransform(FairGeoTransform()) + , fMedium(0) + , nPoints(0) + , fHadFormat(0) + , fgMCid(0) +{} + +inline FairGeoVector* FairGeoVolume::getPoint(const Int_t n) +{ + if (points && n < nPoints) { + return static_cast(points->At(n)); + } else { + return 0; + } +} + +inline void FairGeoVolume::setName(const Text_t* s) +{ + fName = s; + fName.ToUpper(); +} + +inline void FairGeoVolume::setShape(const Text_t* s) +{ + shape = s; + shape.ToUpper(); +} + +inline void FairGeoVolume::setMother(const Text_t* s) +{ + mother = s; + mother.ToUpper(); +} + +#endif /* !FAIRGEOVOLUME_H */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairIon.h b/Detectors/3rdparty/FairRootBase/include/FairIon.h new file mode 100644 index 0000000000000..6981d26bbc569 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairIon.h @@ -0,0 +1,109 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairIon header file ----- +// ----- Created 27/08/04 by V. Friese / D.Bertini ----- +// ------------------------------------------------------------------------- + +/** FairIon.h + *@author V.Friese + *@author D.Bertini + ** + ** A class for the user definition of an ion. It will be instantiated + ** from the constructor of the FairIonGenerator. + **/ + +#ifndef FAIRION_H +#define FAIRION_H + +#include // for Int_t, Double_t, etc +#include // for TNamed + +class FairLogger; + +class FairIon : public TNamed +{ + public: + /** Default constructor **/ + FairIon(); + + /** Standard constructor + *@param name name + *@param z atomic number + *@param a atomic mass + *@param q electric charge + *@param e excitation energy + *@param m mass [GeV] + ** If mass is not given, it will be set to a times the proton mass. + **/ + + FairIon(const char* name, Int_t z, Int_t a, Int_t q, Double_t e = 0., Double_t m = 0.); + void SetParams(const char* name, Int_t z, Int_t a, Int_t q, Double_t e = 0., Double_t m = 0.) + { + SetName(name); + fZ = z; + fA = a; + fQ = q; + fExcEnergy = e; + fMass = m; + } + /** Destructor **/ + virtual ~FairIon(); + + /** Accessors **/ + /** + * Return the atomic number + */ + Int_t GetZ() const { return fZ; } + /** + * Return the atomic mass + */ + Int_t GetA() const { return fA; } + /** + * Return the charge + */ + Int_t GetQ() const { return fQ; } + /** + * Return the excitation energy + */ + Double_t GetExcEnergy() const { return fExcEnergy; } + /** + * Return the mass in GeV + */ + Double_t GetMass() const { return fMass; } + + /** Modifiers **/ + /** + * Set the excitation energy + */ + void SetExcEnergy(Double_t eExc) { fExcEnergy = eExc; } + /** + * Set the atomic mass, use SetMass to set the mass of the ion + */ + void SetA(Int_t a) { fA = a; } + /** + * Set the mass in GeV + */ + void SetMass(Double_t mass) { fMass = mass; } + + private: + static Int_t fgNIon; //! /// Number of ions instantiated. One per generator. + Int_t fZ; /// Atomic number + Int_t fA; /// Atomic mass + Int_t fQ; /// Electric charge + Double_t fExcEnergy; /// Excitation energy [GeV] + Double_t fMass; /// Mass [GeV] + FairLogger* fLogger; //! /// FairLogger + + FairIon(const FairIon&); + FairIon& operator=(const FairIon&); + + ClassDef(FairIon, 2); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairLink.h b/Detectors/3rdparty/FairRootBase/include/FairLink.h new file mode 100644 index 0000000000000..78ad91fe912c8 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairLink.h @@ -0,0 +1,189 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairLink.h + * + * Created on: Dec 23, 2009 + * Author: stockman + * "Pointer" to any data structure inside a root file with a tree structure + * Contains four information: + * File : in which file is the data written (-1 : actual number; 254 : maximum number) + * Entry: entry number in branch of a tree (-1 : actual entry) + * Type : branch inside the tree (-1 : FairLink not set; 65534 : maximum number) + * Index: position inside a container stored in the given branch and entry + * Weight: weighting factor to describe probabilities of a MC truth match + * + */ + +#ifndef FAIRLINK_H_ +#define FAIRLINK_H_ + +#include // for Int_t, Float_t, etc, ClassDefNV +#include // for ostream, cout + +class FairLink +{ + public: + FairLink(); + FairLink(Int_t type, Int_t index, Float_t weight = 1.); + FairLink(TString branchName, Int_t index, Float_t weight = 1.); + FairLink(Int_t file, Int_t entry, Int_t type, Int_t index, Float_t weight = 1.); + FairLink(Int_t file, Int_t entry, TString branchName, Int_t index, Float_t weight = 1.); + ~FairLink(){}; + + void SetLink(Int_t file, Int_t entry, Int_t type, Int_t index, Float_t weight = 1.) + { + SetFile(file); + SetEntry(entry); + SetType(type); + SetIndex(index); + SetWeight(weight); + }; + void SetLink(Int_t type, Int_t index, Float_t weight = 1.) + { + SetFile(-1); + SetEntry(-1); + SetType(type); + SetIndex(index); + SetWeight(weight); + }; + int GetFile() const; + int GetEntry() const { return fEntry; } + int GetType() const; + int GetIndex() const { return fIndex; } + float GetWeight() const { return fWeight; } + + void SetFile(int file); + void SetEntry(int entry) { fEntry = entry; }; + void SetType(int type); + void SetIndex(int index) { fIndex = index; }; + + void SetWeight(Float_t weight) { fWeight = weight; } + void AddWeight(Float_t weight) { fWeight += weight; } + + void PrintLinkInfo(std::ostream& out = std::cout) const; + + bool operator==(const FairLink& link) const + { + if ((GetFile() == link.GetFile() || link.GetFile() == -1) + && (GetEntry() == link.GetEntry() || link.GetEntry() == -1) && GetType() == link.GetType() + && GetIndex() == link.GetIndex()) { + return true; + } else { + return false; + } + } + + bool operator<(const FairLink& link) const + { + if (GetFile() != -1 && link.GetFile() != -1) { + if (GetFile() < link.GetFile()) + return true; + else if (link.GetFile() < GetFile()) + return false; + } + if (GetEntry() != -1 && link.GetEntry() != -1) { + if (GetEntry() < link.GetEntry()) + return true; + else if (link.GetEntry() < GetEntry()) + return false; + } + if (GetType() < link.GetType()) + return true; + else if (link.GetType() < GetType()) + return false; + if (GetIndex() < link.GetIndex()) + return true; + else if (link.GetIndex() < GetIndex()) + return false; + + return false; + } + + friend std::ostream& operator<<(std::ostream& out, const FairLink& link) + { + link.PrintLinkInfo(out); + return out; + } + + ClassDefNV(FairLink, 5); + + template + void serialize(Archive& ar, const unsigned int) + { + ar& fFile; + ar& fType; + ar& fEntry; + ar& fIndex; + ar& fWeight; + } + + private: + unsigned char fFile; + unsigned short fType; + int fEntry; + int fIndex; + float fWeight; +}; + +inline FairLink::FairLink() + : fFile(0) + , fType(0) + , fEntry(-1) + , fIndex(-1) + , fWeight(1.0) +{} + +inline FairLink::FairLink(Int_t type, Int_t index, Float_t weight) + : fFile(0) + , fType(0) + , fEntry(-1) + , fIndex(index) + , fWeight(weight) +{ + SetType(type); +} + +inline FairLink::FairLink(Int_t file, Int_t entry, Int_t type, Int_t index, Float_t weight) + : fFile(0) + , fType(0) + , fEntry(entry) + , fIndex(index) + , fWeight(weight) +{ + SetFile(file); + SetType(type); +} + +inline void FairLink::SetType(int type) +{ + if (type < -1) + return; + fType = type + 1; +} + +inline int FairLink::GetType() const +{ + int type = fType; + return type - 1; +} + +inline void FairLink::SetFile(int file) +{ + if (file < -1) + return; + fFile = file + 1; +} + +inline int FairLink::GetFile() const +{ + int file = fFile; + return file - 1; +} + +#endif /* FAIRLINK_H_ */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairLinkManager.h b/Detectors/3rdparty/FairRootBase/include/FairLinkManager.h new file mode 100644 index 0000000000000..1727453881422 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairLinkManager.h @@ -0,0 +1,48 @@ +#ifndef FAIR_LINK_MANAGER_H +#define FAIR_LINK_MANAGER_H + +#include // for Bool_t, Int_t, UInt_t, etc +#include // for multi-threading +#include // for TObject +#include // for set of branch types to ignore + +class FairLogger; + +class FairLinkManager : public TObject +{ + public: + /**ctor*/ + FairLinkManager(); + /**dtor*/ + virtual ~FairLinkManager(); + + /** static access method */ + static FairLinkManager* Instance(); + virtual void AddIgnoreType(Int_t type); ///< Adds a BranchId (Type) to which links are not included in the link + ///< list. Either ignore types or include types can be given. + virtual Bool_t IsIgnoreType(Int_t type) const; + + virtual void AddIncludeType(Int_t type); ///< Adds a BranchId (Type) to which links are included in the link list. + ///< Either ignore types or include types can be given (XOR). + + std::set GetIgnoreTypes() const { return fIgnoreTypes; } + + private: + /**private methods*/ + FairLinkManager(const FairLinkManager&); + FairLinkManager& operator=(const FairLinkManager&); + /** Set the branch address for a given branch name and return + a TObject pointer, the user have to cast this pointer to the right type.*/ + + std::set fIgnoreTypes; //! + Bool_t fIgnoreSetting; + + /**Singleton instance*/ + static TMCThreadLocal FairLinkManager* fgInstance; + + FairLogger* fLogger; //! + + ClassDef(FairLinkManager, 1); +}; + +#endif // FAIR_ROOT_MANAGER_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairLogger.h b/Detectors/3rdparty/FairRootBase/include/FairLogger.h new file mode 100644 index 0000000000000..bccd4f749bc9d --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairLogger.h @@ -0,0 +1,158 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairLogger.h + * + * Created on: Mar 03, 2011 + * Author: f.uhlig + */ + +#ifndef BASE_FAIRLOGGER_H_ +#define BASE_FAIRLOGGER_H_ + +#include // for bool, FairLogger::Class, etc +#include +#include // for va_list +#include // for operator<< +#include // for vector + +#define MESSAGE_ORIGIN __FILE__, CONVERTTOSTRING(__LINE__), __FUNCTION__ + +// backwards-compatibility with older FairLogger calls, TODO: delete me as soon as possible +enum FairLogLevel +{ + FATAL, + ERROR, + WARNING, + INFO, + DEBUG, + DEBUG1, + DEBUG2, + DEBUG3, + DEBUG4 +}; + +// backwards-compatibility with older FairLogger calls, TODO: delete me as soon as possible +static const char* const LogLevelString[] = + {"FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4"}; + +class FairLogger +{ + public: + static FairLogger* GetLogger(); + + void SetLogToScreen(bool enabled) + { + if (enabled) { + fair::Logger::SetConsoleSeverity(fConsoleSeverity); + } else { + fair::Logger::SetConsoleSeverity(fair::Severity::fatal); + } + } + + void SetLogScreenLevel(const char* severity) + { + fConsoleSeverity = severity; + fair::Logger::SetConsoleSeverity(fConsoleSeverity); + } + + void SetLogToFile(bool enabled) + { + if (enabled) { + fair::Logger::SetFileSeverity(fLogFileSeverity); + } else { + fair::Logger::SetFileSeverity(fair::Severity::fatal); + } + } + + void SetLogFileLevel(const char* severity) + { + fLogFileSeverity = severity; + fair::Logger::SetFileSeverity(fLogFileSeverity); + } + + void SetLogFileName(const std::string& name) + { + fLogFileName = name; + OpenLogFile(); + } + + void SetColoredLog(bool enabled) { fair::Logger::SetConsoleColor(enabled); } + + void SetLogVerbosityLevel(const char* verbosity) { fair::Logger::SetVerbosity(verbosity); } + + bool IsLogNeeded(fair::Severity severity); + bool IsLogNeeded(FairLogLevel level) __attribute__(( + deprecated("Use 'IsLogNeeded(fair::Severity severity)' or 'fair::Logger::Logging(const fair::Severity " + "severity)' or 'fair::Logger::Logging(const std::string& severityStr)'"))); + + void Fatal(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(fatal) << content;' macro interface instead."))); + void Error(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(error) << content;' macro interface instead."))); + void Warning(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(warn) << content;' macro interface instead."))); + void Info(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(info) << content;' macro interface instead."))); + void Debug(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(debug) << content;' macro interface instead."))); + void Debug1(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(debug1) << content;' macro interface instead."))); + void Debug2(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(debug2) << content;' macro interface instead."))); + void Debug3(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(debug3) << content;' macro interface instead."))); + void Debug4(const char* file, const char* line, const char* func, const char* format, ...) + __attribute__((deprecated("Use 'LOG(debug4) << content;' macro interface instead."))); + + static char const endl __attribute__(( + deprecated("Line break is now added automatically by the LOG macro, this variable only adds empty space."))); + static char const flush __attribute__(( + deprecated("Data is now flushed automatically by the LOG macro, this variable only adds empty space."))); + + void SetScreenStreamToCerr(bool /* useCerr */) {} + + private: + static FairLogger* instance; + + FairLogger(); + FairLogger(const FairLogger&); + FairLogger operator=(const FairLogger&); + + ~FairLogger() {} + + void Log(fair::Severity level, + const char* file, + const char* line, + const char*, + const char* format, + va_list arglist); + + const char* ConvertLogLevelToString(FairLogLevel level) const { return LogLevelString[level]; } + + static void LogFatalMessage(); + + void OpenLogFile() { fair::Logger::InitFileSink(fLogFileSeverity, fLogFileName, false); } + + void CloseLogFile() { fair::Logger::RemoveFileSink(); } + + std::string fLogFileName; + std::string fLogFileSeverity; + std::string fConsoleSeverity; + + int fBufferSize; + int fBufferSizeNeeded; + std::vector fDynamicBuffer; + char* fBufferPointer; + + ClassDef(FairLogger, 4); +}; + +#define gLogger (FairLogger::GetLogger()) + +#endif // BASE_FAIRLOGGER_H_ diff --git a/Detectors/3rdparty/FairRootBase/include/FairMCApplication.h b/Detectors/3rdparty/FairRootBase/include/FairMCApplication.h new file mode 100644 index 0000000000000..6ee3dd0488f15 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMCApplication.h @@ -0,0 +1,326 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairMCApplication header file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +#ifndef FAIR_MC_APPLICATION_H +#define FAIR_MC_APPLICATION_H + +#include "FairRunInfo.h" // for FairRunInfo + +#include // for Int_t, Bool_t, Double_t, etc +#include // for TLorentzVector +#include // for TString +#include // for TVirtualMCApplication +#include // for list +#include // for map, multimap, etc + +class FairDetector; +class FairEventHeader; +class FairField; +class FairGenericStack; +class FairMCEventHeader; +class FairPrimaryGenerator; +class FairRadGridManager; +class FairRadLenManager; +class FairRadMapManager; +class FairRootManager; +class FairTask; +class FairTrajFilter; +class FairVolume; +class FairRunSim; +class TChain; +class TIterator; +class TObjArray; +class TRefArray; +class TTask; +class TVirtualMC; + +enum class FairMCApplicationState +{ + kUnknownState, + kConstructGeometry, + kInitGeometry +}; + +/** + * The Main Application ( Interface to MonteCarlo application ) + * @author M. Al-Turany, D. Bertini + * @version 0.1 + * @since 12.01.04 + */ + +class FairMCApplication : public TVirtualMCApplication +{ + public: + /** Standard constructor + *@param name name + *@param title title + *@param ModList a TObjArray containing all detectors and modules used in this simulation + *@param MatName material file name + */ + FairMCApplication(const char* name, const char* title, TObjArray* ModList, const char* MatName); + /** default constructor + */ + FairMCApplication(); + /** default destructor + */ + virtual ~FairMCApplication(); + /** Singelton instance + */ + static FairMCApplication* Instance(); + virtual void AddDecayModes(); + /** Add user defined particles (optional) */ + virtual void AddParticles(); // MC Application + /** Add user defined ions (optional) */ + virtual void AddIons(); // MC Application + /** + *Add user defined Tasks to be executed after each event (optional) + * @param fTask: Task that has to be excuted during simulation + */ + void AddTask(TTask* fTask); + /** Define actions at the beginning of the event */ + virtual void BeginEvent(); // MC Application + /** Define actions at the beginning of primary track */ + virtual void BeginPrimary(); // MC Application + /** Construct user geometry */ + virtual void ConstructGeometry(); // MC Application + /** Align or misalign geometry before actual run */ + virtual Bool_t MisalignGeometry(); + /** Define parameters for optical processes (optional) */ + virtual void ConstructOpGeometry(); // MC Application + /** Define actions at the end of event */ + virtual void FinishEvent(); // MC Application + /** Define actions at the end of primary track */ + virtual void FinishPrimary(); // MC Application + /** Define actions at the end of run */ + void FinishRun(); + /** Generate primary particles */ + virtual void GeneratePrimaries(); // MC Application + /** Return detector by name */ + FairDetector* GetDetector(const char* DetName); + /** Return Field used in simulation*/ + FairField* GetField() { return fxField; } + /**Return primary generator*/ + FairPrimaryGenerator* GetGenerator(); + /**Return list of tasks*/ + TTask* GetListOfTasks(); + FairGenericStack* GetStack(); + TChain* GetChain(); + /** Initialize geometry */ + virtual void InitGeometry(); // MC Application + /** Initialize MC engine */ + void InitMC(const char* setup, const char* cuts); + /** Initialize Tasks if any*/ + void InitTasks(); + /**Define actions at the end of each track */ + virtual void PostTrack(); // MC Application + /** Define actions at the beginning of each track*/ + virtual void PreTrack(); // MC Application + + /** Clone for worker (used in MT mode only) */ + virtual TVirtualMCApplication* CloneForWorker() const; + + /** Init application on worker (used in MT mode only) */ + virtual void InitOnWorker(); + + /** Finish run on worker (used in MT mode only) */ + virtual void FinishRunOnWorker(); + + /** Run the MC engine + * @param nofEvents : number of events to simulate + */ + void RunMC(Int_t nofEvents); + /** + * Set the magnetic field for simulation + * @param field: magnetic field + */ + void SetField(FairField* field); + /** + * Set the event generator for simulation + * @param fxGenerator: Event generator(s) + */ + void SetGenerator(FairPrimaryGenerator* fxGenerator); + /** + * Set the parameter containers needed by Tasks(if any) + */ + void SetParTask(); + /** + * Switch for using Pythia as external decayer + * @param decayer: if TRUE pythia will decay particles specifid in the Decay Config macro (see + * SetPythiaDecayerConfig) + */ + void SetPythiaDecayer(Bool_t decayer) { fPythiaDecayer = decayer; } + /** + * set the decay configuration macro to be used by Pythia + */ + void SetPythiaDecayerConfig(const TString decayerConf) { fPythiaDecayerConfig = decayerConf; } + /** + * Switch for using the radiation length manager + */ + void SetRadiationLengthReg(Bool_t RadLen); + /** + * Switch for using the radiation map manager + */ + void SetRadiationMapReg(Bool_t RadMap); + /** + * Switch for debuging the tracking + */ + void SetTrackingDebugMode(Bool_t set) { fDebug = set; } + /** + * Switch for using 2 or 3 body phase-space decay + * @param decay: if TRUE 2/3 body phase space decay will be used for particle specified in the User Decay Config + * macro (see SetUserDecayConfig) + */ + void SetUserDecay(Bool_t decay) { fUserDecay = decay; } + /** + * set the decay configuration macro to be used by user decay + */ + void SetUserDecayConfig(const TString decayerConf) { fUserDecayConfig = decayerConf; } + /** Define action at each step, dispatch the action to the corresponding detectors */ + virtual void Stepping(); // MC Application + /** Stop the run*/ + virtual void StopRun(); + /** Stop the run*/ + virtual void StopMCRun(); + /**Define maximum radius for tracking (optional) */ + virtual Double_t TrackingRmax() const; // MC Application + /** Define maximum z for tracking (optional) */ + virtual Double_t TrackingZmax() const; // MC Application + + void AddMeshList(TObjArray* meshList); + + /** + * Set if the current event should be written to the output file. + * The default value which is set back after each event is to store + * the event. + */ + void SetSaveCurrentEvent(Bool_t set) { fSaveCurrentEvent = set; } + + /** + * Get the current application state. + */ + FairMCApplicationState GetState() const { return fState; } + + private: + // methods + Int_t GetIonPdg(Int_t z, Int_t a) const; + + void UndoGeometryModifications(); + + protected: + // data members + /**List of active detector */ + TRefArray* fActiveDetectors; + /**List of FairTask*/ + FairTask* fFairTaskList; //! + /**detector list (Passive and Active)*/ + TRefArray* fDetectors; + /**Map used for dispatcher*/ + TRefArray* fDetMap; + /**Iterator for Module list*/ + TIterator* fModIter; //! + /**Module list in simulation*/ + TObjArray* fModules; + /**Number of sensetive volumes in simulation session*/ + Int_t fNoSenVolumes; //! + /**flag for using Pythia as external decayer */ + Bool_t fPythiaDecayer; + /** Pythia decay config macro*/ + TString fPythiaDecayerConfig; //! + /** Simulation Stack */ + FairGenericStack* fStack; //! + /**Pointer to thr I/O Manager */ + FairRootManager* fRootManager; //! + /**List of sensetive volumes in all detectors*/ + TRefArray* fSenVolumes; //! + /**Magnetic Field Pointer*/ + FairField* fxField; // + /**Primary generator*/ + FairPrimaryGenerator* fEvGen; // + /**MC Engine 1= Geant3, 2 = Geant4*/ + Int_t fMcVersion; // mc Version + /** Track visualization manager */ + FairTrajFilter* fTrajFilter; //! + /**Flag for accepted tracks for visualization*/ + Bool_t fTrajAccepted; //! + /**Flag for using user decay*/ + Bool_t fUserDecay; + /**User decay config macro*/ + TString fUserDecayConfig; //! + /** Debug flag*/ + Bool_t fDebug; //! + /**dispatcher internal use */ + FairVolume* fDisVol; + /**dispatcher internal use */ + FairDetector* fDisDet; + /**dispatcher internal use */ + std::multimap fVolMap; //! + /**dispatcher internal use */ + std::multimap::iterator fVolIter; //! + /** Track position*/ + /**dispatcher internal use RadLeng*/ + std::map fModVolMap; //! + /**dispatcher internal use RadLen*/ + std::map::iterator fModVolIter; //! + TLorentzVector fTrkPos; //! + /** Flag for Radiation length register mode */ + Bool_t fRadLength; //! + + /**Radiation length Manager*/ + FairRadLenManager* fRadLenMan; //! + /** Flag for Radiation map register mode */ + Bool_t fRadMap; //! + /**Radiation Map Manager*/ + FairRadMapManager* fRadMapMan; //! + /**Radiation map Grid Manager*/ + FairRadGridManager* fRadGridMan; //! + + FairEventHeader* fEventHeader; //! + + FairMCEventHeader* fMCEventHeader; //! + /** list of senstive detectors used in the simuation session*/ + std::list listActiveDetectors; //! + /** list of all detectors used in the simuation session*/ + std::list listDetectors; //! + /** Pointer to the current MC engine //! + */ + TVirtualMC* fMC; + /** Pointer to FairRunSim //! */ + FairRunSim* fRun; + + /** Flag if the current event should be saved */ + Bool_t fSaveCurrentEvent; + + /** Current state */ + FairMCApplicationState fState; //! + + ClassDef(FairMCApplication, 4); + + private: + /** Protected copy constructor */ + FairMCApplication(const FairMCApplication&); + /** Protected assignment operator */ + FairMCApplication& operator=(const FairMCApplication&); + + FairRunInfo fRunInfo; //! + Bool_t fGeometryIsInitialized; + + static FairMCApplication* fgMasterInstance; +}; + +// inline functions + +inline FairMCApplication* FairMCApplication::Instance() +{ + return static_cast(TVirtualMCApplication::Instance()); +} + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairMCEventHeader.h b/Detectors/3rdparty/FairRootBase/include/FairMCEventHeader.h new file mode 100644 index 0000000000000..3b071a755c140 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMCEventHeader.h @@ -0,0 +1,109 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** FairMCEventHeader.h + *@author V.Friese + ** Data class (level MC) containing information about the input event. + ** 15.05.2008 change the event time to ns (M. Al-Turany) + **/ + +#ifndef FAIRMCEVENTHEADER_H +#define FAIRMCEVENTHEADER_H 1 + +#include // for Double_t, UInt_t, etc +#include // for TNamed +#include // for TVector3 + +class FairMCEventHeader : public TNamed +{ + public: + /** Default constructor **/ + FairMCEventHeader(); + + /** Constructor with all members + ** + *@param iEvent event identifier + *@param x,y,z vertex oordinates [cm] + *@param t event time [ns] + *@param b impact parameter [fm] (if relevant) + *@param nPrim number of input tracks + **/ + FairMCEventHeader(Int_t iEvent, Double_t x, Double_t y, Double_t z, Double_t t, Double_t b, Int_t nPrim); + + /** Standard constructor with run identifier **/ + FairMCEventHeader(UInt_t runId); + + /** Destructor **/ + virtual ~FairMCEventHeader(); + + /** Accessors **/ + UInt_t GetRunID() const { return fRunId; } /// run identifier + UInt_t GetEventID() const { return fEventId; } /// event identifier + Double_t GetX() const { return fX; } /// vertex x [cm] + Double_t GetY() const { return fY; } /// vertex y [cm] + Double_t GetZ() const { return fZ; } /// vertex z [cm] + Double_t GetT() const { return fT; } /// event time [ns] + Double_t GetB() const { return fB; } /// impact parameter [fm] + Int_t GetNPrim() const { return fNPrim; } /// number of input tracks + Bool_t IsSet() const { return fIsSet; } /// Flag + Double_t GetRotX() const { return fRotX; } /// rot. around x-axis [rad] + Double_t GetRotY() const { return fRotY; } /// rot. around y-axis [rad] + Double_t GetRotZ() const { return fRotZ; } /// rot. around z-axis [rad] + + void GetVertex(TVector3& vertex) { vertex.SetXYZ(fX, fY, fZ); } + + /** Modifiers **/ + void SetEventID(UInt_t eventId) { fEventId = eventId; } + void SetRunID(UInt_t runId) { fRunId = runId; } + void SetTime(Double_t t) { fT = t; } + void SetB(Double_t b) { fB = b; } + void SetNPrim(Int_t nPrim) { fNPrim = nPrim; } + void MarkSet(Bool_t isSet) { fIsSet = isSet; } + void SetVertex(Double_t x, Double_t y, Double_t z); + void SetVertex(const TVector3& vertex); + void SetRotX(Double_t rotx) { fRotX = rotx; } + void SetRotY(Double_t roty) { fRotY = roty; } + void SetRotZ(Double_t rotz) { fRotZ = rotz; } + + /** Reset all members **/ + void Reset(); + + /** Register the class as data branch to the output */ + virtual void Register(); + + protected: + UInt_t fRunId; /// Run identifier + UInt_t fEventId; /// Event identifier + Double32_t fX; /// Primary vertex x [cm] + Double32_t fY; /// Primary vertex y [cm] + Double32_t fZ; /// Primary vertex z [cm] + Double32_t fT; /// Event time [s] + Double32_t fB; /// Impact parameter [fm] (if relevant) + Int_t fNPrim; /// Number of input tracks + Bool_t fIsSet; /// Flag whether variables are filled + Double32_t fRotX; /// Rotation around x-axis (beam tilt) [rad] + Double32_t fRotY; /// Rotation around y-axis (beam tilt) [rad] + Double32_t fRotZ; /// Rotation around z-axis (event plane) [rad] + + ClassDef(FairMCEventHeader, 2); +}; + +inline void FairMCEventHeader::SetVertex(Double_t x, Double_t y, Double_t z) +{ + fX = x; + fY = y; + fZ = z; +} + +inline void FairMCEventHeader::SetVertex(const TVector3& vertex) +{ + fX = vertex.X(); + fY = vertex.Y(); + fZ = vertex.Z(); +} + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairMCPoint.h b/Detectors/3rdparty/FairRootBase/include/FairMCPoint.h new file mode 100644 index 0000000000000..da4fb205af46e --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMCPoint.h @@ -0,0 +1,143 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** FairMCPoint.h + * This is the base class for all MC Points generated by the transport of + * tracks through active detectors. + **/ + +#ifndef FAIRMCPOINT_H +#define FAIRMCPOINT_H + +#include "FairMultiLinkedData_Interface.h" // for FairMultiLinkedData + +#include // for Double_t, Double32_t, Int_t, etc +#include // for TVector3 + +namespace boost { +namespace serialization { +class access; +} +} // namespace boost +#include + +class FairMCPoint : public FairMultiLinkedData_Interface +{ + public: + /** Default constructor **/ + FairMCPoint(); + + /** Constructor with arguments + *@param trackID Index of MCTrack + *@param detID Detector ID + *@param pos Point coordinates [cm] + *@param mom Momentum of track at MCPoint [GeV] + *@param tof Time since event start [ns] + *@param length Track length since creation [cm] + *@param eLoss Energy deposit [GeV] + *@param EventId MC event id + **/ + FairMCPoint(Int_t trackID, + Int_t detID, + TVector3 pos, + TVector3 mom, + Double_t tof, + Double_t length, + Double_t eLoss, + UInt_t EventId = 0); + + /** Destructor **/ + virtual ~FairMCPoint(); + + /** Accessors */ + UInt_t GetEventID() const { return fEventId; } /// event identifier + Int_t GetTrackID() const { return fTrackID; } + Double_t GetPx() const { return fPx; } + Double_t GetPy() const { return fPy; } + Double_t GetPz() const { return fPz; } + Double_t GetTime() const { return fTime; } + Double_t GetLength() const { return fLength; } + Double_t GetEnergyLoss() const { return fELoss; } + void Momentum(TVector3& mom) const { mom.SetXYZ(fPx, fPy, fPz); } + Int_t GetDetectorID() const { return fDetectorID; }; + Double_t GetX() const { return fX; }; + Double_t GetY() const { return fY; }; + Double_t GetZ() const { return fZ; }; + void Position(TVector3& pos) const { pos.SetXYZ(fX, fY, fZ); } + + /** Modifiers **/ + void SetEventID(UInt_t eventId) { fEventId = eventId; } + virtual void SetTrackID(Int_t id) { fTrackID = id; } + void SetTime(Double_t time) { fTime = time; } + void SetLength(Double_t length) { fLength = length; } + void SetEnergyLoss(Double_t eLoss) { fELoss = eLoss; } + void SetMomentum(const TVector3& mom); + void SetDetectorID(Int_t detID) { fDetectorID = detID; } + void SetX(Double_t x) { fX = x; } + void SetY(Double_t y) { fY = y; } + void SetZ(Double_t z) { fZ = z; } + void SetXYZ(Double_t x, Double_t y, Double_t z); + void SetPosition(const TVector3& pos); + + /** Output to screen **/ + virtual void Print(const Option_t* opt = 0) const; + + template + void serialize(Archive& ar, const unsigned int) + { + // ar & boost::serialization::base_object(*this); + ar& fTrackID; + ar& fEventId; + ar& fDetectorID; + ar& fX; + ar& fY; + ar& fZ; + ar& fPx; + ar& fPy; + ar& fPz; + ar& fTime; + ar& fLength; + ar& fELoss; + } + + protected: + friend class boost::serialization::access; + + Int_t fTrackID; ///< Track index + UInt_t fEventId; ///< MC Event id + Double32_t fPx, fPy, fPz; ///< Momentum components [GeV] + Double32_t fTime; ///< Time since event start [ns] + Double32_t fLength; ///< Track length since creation [cm] + Double32_t fELoss; ///< Energy loss at this point [GeV] + Int_t fDetectorID; ///< Detector unique identifier + Double32_t fX, fY, fZ; ///< Position of hit [cm] + + ClassDef(FairMCPoint, 5); +}; + +inline void FairMCPoint::SetMomentum(const TVector3& mom) +{ + fPx = mom.Px(); + fPy = mom.Py(); + fPz = mom.Pz(); +} + +inline void FairMCPoint::SetXYZ(Double_t x, Double_t y, Double_t z) +{ + fX = x; + fY = y; + fZ = z; +} + +inline void FairMCPoint::SetPosition(const TVector3& pos) +{ + fX = pos.X(); + fY = pos.Y(); + fZ = pos.Z(); +} + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairMesh.h b/Detectors/3rdparty/FairRootBase/include/FairMesh.h new file mode 100644 index 0000000000000..21b33cc1477b6 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMesh.h @@ -0,0 +1,106 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairMesh header file ----- +// ----- original author D.Bertini ----- +// ----- adapted april 2010 O.Hartmann ----- +// ------------------------------------------------------------------------- + +#ifndef FAIRMESH_H +#define FAIRMESH_H + +#include // for Double_t, Int_t, etc +#include // for TH2D +#include // for TObject +#include // for TString + +/** + * Abstract base class for Mesh Objects. + **@author D.Bertini + */ +class FairMesh : public TObject +{ + public: + /** Default constructor **/ + FairMesh(); + FairMesh(const char*); + + /** Destructor **/ + virtual ~FairMesh(); + + /** Accessors **/ + Double_t GetXmin() const { return fXmin; }; + Double_t GetYmin() const { return fYmin; }; + Double_t GetZmin() const { return fZmin; }; + + Double_t GetXmax() const { return fXmax; }; + Double_t GetYmax() const { return fYmax; }; + Double_t GetZmax() const { return fZmax; }; + + /** Modifiers **/ + void SetX(Double_t xmin, Double_t xmax, Int_t nbin) + { + fXmin = xmin; + fXmax = xmax; + NXbin = nbin; + } + void SetY(Double_t ymin, Double_t ymax, Int_t nbin) + { + fYmin = ymin; + fYmax = ymax; + NYbin = nbin; + } + void SetZ(Double_t zmin, Double_t zmax, Int_t nbin) + { + fZmin = zmin; + fZmax = zmax; + NZbin = nbin; + } + + TH2D* GetMeshTid() { return fMeshTid; } + TH2D* GetMeshFlu() { return fMeshFlu; } + TH2D* GetMeshSEU() { return fMeshSEU; } + /*** Output to screen */ + // virtual void Print(const Option_t* opt = 0) const {;} + + Double_t GetDiag() { return fDiag; } + Double_t GetBinVolume() { return fBinVolume; } + + void fillTID(Double_t x, Double_t y, Double_t we) { fMeshTid->Fill(x, y, we); } + void fillFluence(Double_t x, Double_t y, Double_t we) { fMeshFlu->Fill(x, y, we); } + void fillSEU(Double_t x, Double_t y, Double_t we) { fMeshSEU->Fill(x, y, we); } + void Scale(Double_t fac) + { + fMeshTid->Scale(fac); + fMeshFlu->Scale(fac); + fMeshSEU->Scale(fac); + } + + void calculate(); + + void print(); + + protected: + Double_t fXmin, fYmin, fZmin; + Double_t fXmax, fYmax, fZmax; + Int_t NXbin, NYbin, NZbin; + Double_t fBinVolume; + Double_t fDiag; + TH2D* fMeshTid; // !mesh + TH2D* fMeshFlu; // !mesh + TH2D* fMeshSEU; // !mesh + TString fhname; // !mesh + + private: + FairMesh(const FairMesh&); + FairMesh& operator=(const FairMesh&); + + ClassDef(FairMesh, 1); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairModule.h b/Detectors/3rdparty/FairRootBase/include/FairModule.h new file mode 100644 index 0000000000000..fdf8eae1267bd --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairModule.h @@ -0,0 +1,169 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +#ifndef FAIRMODULE_H +#define FAIRMODULE_H + +#include "FairGeoInterface.h" // for FairGeoInterface +#include "FairGeoLoader.h" // for FairGeoLoader +#include "FairGeoNode.h" // for FairGeoNode +#include "FairGeoVolume.h" // for FairGeoVolume +#include "FairLogger.h" +#include "FairRun.h" // for FairRun + +#include // for Bool_t, Int_t, etc +#include // for TList (ptr only), TListIter +#include // for TNamed +#include // for TObjArray +#include // for TString, operator!= +#include // for string + +class FairVolumeList; +class FairVolume; +class TArrayI; +class TGeoMatrix; +class TGeoNode; +class TGeoVolume; +class TRefArray; +class TVirtualMC; + +/** + * Base class for constructing all detecors and passive volumes + * @author M. Al-Turany, Denis Bertini + * @version 1.0 + * @since 01.04.08 M.Al-Turany + * Add methods to construct geometry via ROOT files + * Add some documentation + * + * Changelog: 29.02.2012 [O.Merle] Fixed missing material assignment for top volume. + * ... and please - add some documentation to your code. + */ +class FairModule : public TNamed +{ + public: + /**default ctor*/ + FairModule(); + /**Standard ctor*/ + FairModule(const char* Name, const char* title, Bool_t Active = kFALSE); + /**default dtor*/ + virtual ~FairModule(); + /**Print method should be implemented in detector or module*/ + virtual void Print(Option_t*) const { ; } + /**Set the geometry file name o be used*/ + virtual void SetGeometryFileName(TString fname, TString geoVer = "0"); + /**Get the Geometry file name*/ + virtual TString GetGeometryFileName() { return fgeoName; } + /**Get the geometry file version if used*/ + virtual TString GetGeometryFileVer() { return fgeoVer; } + /**method called from the MC application to construct the geometry, has to be implimented by user*/ + virtual void ConstructGeometry(); + /**method called from the MC application to set optical geometry properties*/ + virtual void ConstructOpGeometry(); + /**construct geometry from root files (TGeo)*/ + virtual void ConstructRootGeometry(TGeoMatrix* shiftM = nullptr); + /**construct geometry from standard ASSCII files (Hades Format)*/ + virtual void ConstructASCIIGeometry(); + /** Modify the geometry for the simulation run using methods of the Root geometry package */ + virtual void ModifyGeometry() + __attribute__((deprecated("Use FairAlignmentHandler instead, see Tutorial4 for examples"))) + { + LOG(warn) << "This function is deprecated. Use FairAlignmentHandler instead, see Tutorial4 for examples."; + } + virtual void RegisterAlignmentMatrices() { ; } + + /**construct geometry from GDML files*/ + virtual void ConstructGDMLGeometry(__attribute__((unused)) TGeoMatrix* posrot); + /** custom settings of processes and cuts for media to be forwarded to the + ** detector simulation */ + virtual void SetSpecialPhysicsCuts() { ; } + /** Clone this object (used in MT mode only)*/ + virtual FairModule* CloneModule() const; + /** Init worker run (used in MT mode only) */ + virtual void BeginWorkerRun() const { ; } + /** Finish worker run (used in MT mode only) */ + virtual void FinishWorkerRun() const { ; } + + + /**Set the sensitivity flag for volumes, called from ConstructASCIIRootGeometry(), and has to be implimented for + * detectors which use ConstructASCIIRootGeometry() to build the geometry */ + virtual Bool_t IsSensitive(const std::string& name); + /**The function below is depracated, please change to the new method above */ + virtual Bool_t CheckIfSensitive(__attribute__((unused)) std::string name) __attribute__(( + deprecated("The method CheckIfSensitive is deprecated. Implement IsSensitive in the detector classes."))) + { + return kFALSE; + } + /**called from ConstructRootGeometry()*/ + virtual void ExpandNode(TGeoNode* Node); + /**called from ConstructGDMLGeometry()*/ + virtual void ExpandNodeForGDML(__attribute__((unused)) TGeoNode* curNode); + /**return the MC id of a volume named vname*/ + virtual Int_t getVolId(const TString&) const { return 0; } + /**return the detector/Module id (which was set in the sim macro for the detector)*/ + Int_t GetModId() { return fModId; } + /**Set the verbose level in this detector*/ + void SetVerboseLevel(Int_t level) { fVerboseLevel = level; } + /**return the detector status */ + Bool_t IsActive() { return fActive; } + /**set the detector/module id*/ + void SetModId(Int_t id) { fModId = id; } + /** Set the name of the mother volume to which a new geometry is added. + ** This function is needed for geometries which are defined as ROOT geometry manager. + **/ + void SetMotherVolume(TString volName) { fMotherVolumeName = volName; } + /**called from ConstuctASCIIGeometry*/ + /**Set the parameter containers*/ + virtual void SetParContainers() { ; } + /** Initialize everything which has to be done before the construction and modification + ** of the geometry. Mostly this is needed to read data from the parameter containers.*/ + virtual void InitParContainers() { ; } + /**return the geo parameter of this detector/module*/ + TList* GetListOfGeoPar() { return flGeoPar; } + + /**list of volumes in a simulation session*/ + static thread_local FairVolumeList* vList; //! + /**total number of volumes in a simulaion session*/ + static thread_local Int_t fNbOfVolumes; //! + /**list of all sensitive volumes in a simulaion session*/ + static thread_local TRefArray* svList; //! + + static thread_local TArrayI* volNumber; //! + TString fMotherVolumeName; //! + FairVolume* getFairVolume(FairGeoNode* fNode); + void AddSensitiveVolume(TGeoVolume* v); + + private: + /** Re-implimented from ROOT: TGeoMatrix::SetDefaultName() */ + void SetDefaultMatrixName(TGeoMatrix* matrix); + void AssignMediumAtImport(TGeoVolume* v); // O.Merle, 29.02.2012 - see impl. + + /**called from ConstructGDMLGeometry. Changes default ID created by TGDMLParse*/ + void ReAssignMediaId(); + void swap(FairModule& other) throw(); + + protected: + FairModule(const FairModule&); + FairModule& operator=(const FairModule&); + TString fgeoVer; + TString fgeoName; + Int_t fModId; + Bool_t fActive; + Int_t fNbOfSensitiveVol; //! + Int_t fVerboseLevel; + TList* flGeoPar; //! list of Detector Geometry parameters + Bool_t fGeoSaved; //! flag for initialisation + TVirtualMC* fMC; //! cahed pointer to MC (available only after initialization) + + ClassDef(FairModule, 4); +}; + +// The container-based ConstructASCIIGeometry template was removed with the +// FairRuntimeDb: it stored imported ASCII geometry into a parameter container. + + +#endif // FAIRMODULE_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairMonitor.h b/Detectors/3rdparty/FairRootBase/include/FairMonitor.h new file mode 100644 index 0000000000000..498be19164368 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMonitor.h @@ -0,0 +1,121 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +/* + * FairMonitor.h + * + * Created on: Aug 01, 2015 + * Author: r.karabowicz + */ + +#ifndef BASE_FAIRMONITOR_H_ +#define BASE_FAIRMONITOR_H_ + +#include +#include +#include +#include + +class TCanvas; +class TFile; +class TList; +class TTask; + +class FairMonitor : public TNamed +{ + public: + static FairMonitor* GetMonitor(); + + void EnableMonitor(Bool_t tempBool = kTRUE, TString fileName = "") + { + fRunMonitor = tempBool; + fOutputFileName = fileName; + } + void EnableDrawing(Bool_t tempBool = kTRUE) { fDrawCanvas = tempBool; } + Bool_t IsRunning() { return fRunMonitor; } + + void StartMonitoring(const TTask* tTask, const char* identStr) + { + StartTimer(tTask, identStr); + StartMemoryMonitor(tTask, identStr); + } + void StopMonitoring(const TTask* tTask, const char* identStr) + { + StopTimer(tTask, identStr); + StopMemoryMonitor(tTask, identStr); + } + + void StartTimer(const TTask* tTask, const char* identStr); + void StopTimer(const TTask* tTask, const char* identStr); + + void StartMemoryMonitor(const TTask* tTask, const char* identStr); + void StopMemoryMonitor(const TTask* tTask, const char* identStr); + + void RecordInfo(const TTask* tTask, const char* identStr, Double_t value); + + void RecordRegister(const char* name, const char* folderName, Bool_t toFile); + void RecordGetting(const char* name); + + void SetCurrentTask(TTask* tTask) { fCurrentTask = tTask; } + + virtual void Print(Option_t* option = "") const; + virtual void Draw(Option_t* option = ""); + + void PrintTask(TString specString) const; + void PrintTask(TTask* tempTask, Int_t taskLevel = 0) const; + void DrawHist(TString specString); + + TList* GetHistList() { return fHistList; } + + void StoreHistograms(TFile* sinkFile); + + private: + static FairMonitor* instance; + FairMonitor(); + ~FairMonitor(); + FairMonitor(const FairMonitor&); + FairMonitor& operator=(const FairMonitor&); + + Bool_t fRunMonitor; + Bool_t fDrawCanvas; + + Double_t fRunTime; + Double_t fRunMem; + + std::map fTimerMap; + std::map fMemoryMap; + + TList* fHistList; + TCanvas* fCanvas; + + Int_t fNoTaskRequired; + Int_t fNoTaskCreated; + + TTask* fCurrentTask; + + TString fOutputFileName; // output file name, if empty then try to use FairSink to store histograms + + std::multimap fTaskRequired; + std::multimap fTaskCreated; + std::multimap fTaskCreatedTemp; + + std::map fObjectMap; + std::map fTaskMap; + + std::map> fObjectPos; + std::map> fTaskPos; + + void GetTaskMap(TTask* tempTask); + void AnalyzeObjectMap(TTask* tempTask); + + ClassDef(FairMonitor, 0); +}; + +extern FairMonitor* gMonitor; + +#endif // BASE_FAIRMONITOR_H_ diff --git a/Detectors/3rdparty/FairRootBase/include/FairMultiLinkedData.h b/Detectors/3rdparty/FairRootBase/include/FairMultiLinkedData.h new file mode 100644 index 0000000000000..7735abfdb0c38 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMultiLinkedData.h @@ -0,0 +1,169 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * FairMultiLinkedData.h + * + * \date Dec 7, 2009 + * \author T.Stockmanns + */ + +#ifndef FAIRMULTILINKEDDATA_H_ +#define FAIRMULTILINKEDDATA_H_ + +#include "FairLink.h" // for FairLink + +#include // for Int_t, Bool_t, kFALSE, etc +#include // for TObject +#include // for TString +#include // for ostream +#include // for operator<<, ostream, cout +#include // for set +#include // for vector + +class FairMultiLinkedData : public TObject +{ + public: + FairMultiLinkedData(); ///< Default constructor + FairMultiLinkedData(const std::set& links, Bool_t persistanceCheck = kTRUE); ///< Constructor + FairMultiLinkedData(TString dataType, + const std::vector& links, + Int_t fileId = -1, + Int_t evtId = -1, + Bool_t persistanceCheck = kTRUE, + Bool_t bypass = kFALSE, + Float_t mult = 1.0); ///< Constructor + FairMultiLinkedData(Int_t dataType, + const std::vector& links, + Int_t fileId = -1, + Int_t evtId = -1, + Bool_t persistanceCheck = kTRUE, + Bool_t bypass = kFALSE, + Float_t mult = 1.0); ///< Constructor + + virtual ~FairMultiLinkedData(){}; + + virtual std::set GetLinks() const { return fLinks; } ///< returns stored links as FairLinks + virtual FairLink GetEntryNr() const { return fEntryNr; } ///< gives back the entryNr + virtual Int_t GetNLinks() const { return fLinks.size(); } ///< returns the number of stored links + virtual FairLink GetLink(Int_t pos) const; ///< returns the FairLink at the given position + virtual FairMultiLinkedData GetLinksWithType( + Int_t type) const; ///< Gives you a list of links which contain the given type + virtual std::vector + GetSortedMCTracks(); ///< Gives you a list of all FairLinks pointing to a "MCTrack" sorted by their weight + TObject* GetData(FairLink& myLink); ///< Get the TObject the Link is pointing to + virtual Int_t GetDefaultType() { return fDefaultType; } + Bool_t GetPersistanceCheck() { return fPersistanceCheck; } ///< Returns the value of PersistanceCheck + Int_t GetVerbose() { return fVerbose; } ///< Returns the verbosity level + virtual void SetDefaultType(Int_t type) { fDefaultType = type; } + virtual void SetPersistanceCheck(Bool_t check) + { + fPersistanceCheck = check; + } ///< Controls if a persistance check of a link is done or not + virtual void SetVerbose(Int_t level) { fVerbose = level; } ///< Sets the verbosity level + virtual void SetInsertHistory(Bool_t val) + { + fInsertHistory = val; + } ///< Toggles if history of a link is inserted or not + Bool_t GetInsertHistory() const { return fInsertHistory; } + + virtual void SetEntryNr(FairLink entry) { fEntryNr = entry; } + virtual void SetLinks(FairMultiLinkedData links, Float_t mult = 1.0); ///< Sets the links as vector of FairLink + virtual void SetLink(FairLink link, + Bool_t bypass = kFALSE, + Float_t mult = 1.0); ///< Sets the Links with a single FairLink + + virtual void AddLinks(FairMultiLinkedData links, + Float_t mult = 1.0); ///< Adds a List of FairLinks (FairMultiLinkedData) to fLinks + virtual void AddLink(FairLink link, + Bool_t bypass = kFALSE, + Float_t mult = 1.0); ///< Adds a FairLink link at the end of fLinks. If multi is kTRUE a link + ///< is allowed more than once otherwise it is stored only once + + virtual void InsertLink(FairLink link); ///< Inserts a link into the list of links without persistance checking + virtual void InsertHistory( + FairLink link); ///< Adds the FairLinks of the inserted link to the set of links of this object + + virtual void AddAllWeights(Double_t weight); ///< Adds weight to all Links + virtual void SetAllWeights(Double_t weight); ///< Sets a common weight for Links + virtual void MultiplyAllWeights(Double_t weight); ///< Multiplies all Links with weight + + virtual Bool_t IsLinkInList(FairLink link) + { + return IsLinkInList(link.GetType(), link.GetIndex()); + } ///< Test if a given link is in fLinks + virtual Bool_t IsLinkInList( + Int_t type, + Int_t index); ///< Same as IsLinkInList(FairLink) just with type and index given separately + virtual Int_t LinkPosInList(FairLink link) + { + return LinkPosInList(link.GetType(), link.GetIndex()); + } ///< returns position of link in fLinks. If it is not in the list -1 is returned + virtual Int_t LinkPosInList(Int_t type, Int_t index); ///< Same as LinkPosInList(FairLink) + + virtual void DeleteLink(FairLink link) + { + DeleteLink(link.GetType(), link.GetIndex()); + } ///< Deletes a link ouf of fLinks + virtual void DeleteLink(Int_t type, Int_t index); ///< Deletes a link ouf of fLinks + + virtual void Reset() { ResetLinks(); } + virtual void ResetLinks() { fLinks.clear(); } ///< Clears fLinks + + std::ostream& PrintLinkInfo(std::ostream& out = std::cout) const + { + out << GetEntryNr() << " -> ["; + for (Int_t i = 0; i < GetNLinks(); i++) { + GetLink(i).PrintLinkInfo(out); + out << " "; + } + out << "]"; + return out; + } ///< Output + + friend std::ostream& operator<<(std::ostream& out, const FairMultiLinkedData& data) + { + data.PrintLinkInfo(out); + return out; + } ///< Output + + protected: + std::set fLinks; + FairLink fEntryNr; + Bool_t fPersistanceCheck; //! + Bool_t fInsertHistory; //! + Int_t fVerbose; //! + + virtual void SimpleAddLinks(Int_t fileId, + Int_t evtId, + Int_t dataType, + const std::vector& links, + Bool_t, + Float_t) + { + for (UInt_t i = 0; i < links.size(); i++) { + fLinks.insert(FairLink(fileId, evtId, dataType, links[i])); + } + } + Int_t fDefaultType; + + ClassDef(FairMultiLinkedData, 4); +}; + +/**\fn virtual void FairMultiLinkedData::SetLinks(Int_t type, std::vector links) + * \param type as Int_t gives one type of source data for all indices + * \param links as vector gives the vector of indices at which position in the TClonesArray the source data is + * stored + */ + +/**\fn virtual void FairMultiLinkedData::SetLinks(std::vector type, std::vector links) + * \param type as vector gives the type of source data (TClonesArray) + * \param links as vector gives the vector of indices at which position in the TClonesArray the source data is + * stored + */ + +#endif /* FAIRMULTILinkedData_H_ */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairMultiLinkedData_Interface.h b/Detectors/3rdparty/FairRootBase/include/FairMultiLinkedData_Interface.h new file mode 100644 index 0000000000000..68781006976bb --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairMultiLinkedData_Interface.h @@ -0,0 +1,104 @@ +/** + * FairMultiLinkedData_Interface.h + * + * \date Dec 7, 2009 + * \author T.Stockmanns + */ + +#ifndef FairMultiLinkedData_Interface_H_ +#define FairMultiLinkedData_Interface_H_ + +#include "FairLink.h" // for FairLink +#include "FairMultiLinkedData.h" + +#include // for Int_t, Bool_t, kFALSE, etc +#include // for TObject +#include // for TString +#include // for operator<<, ostream, cout +#include // for std::unique_ptr +#include // for set +#include // for vector + +class FairMultiLinkedData_Interface : public TObject +{ + public: + FairMultiLinkedData_Interface() = default; ///< Default constructor + FairMultiLinkedData_Interface(FairMultiLinkedData& links, Bool_t persistanceCheck = kTRUE); ///< Constructor + FairMultiLinkedData_Interface(TString dataType, + std::vector links, + Int_t fileId = -1, + Int_t evtId = -1, + Bool_t persistanceCheck = kTRUE, + Bool_t bypass = kFALSE, + Float_t mult = 1.0); ///< Constructor + FairMultiLinkedData_Interface(Int_t dataType, + std::vector links, + Int_t fileId = -1, + Int_t evtId = -1, + Bool_t persistanceCheck = kTRUE, + Bool_t bypass = kFALSE, + Float_t mult = 1.0); ///< Constructor + FairMultiLinkedData_Interface(const FairMultiLinkedData_Interface& toCopy); + + ~FairMultiLinkedData_Interface() = default; + + FairMultiLinkedData_Interface& operator=(const FairMultiLinkedData_Interface& rhs); + + std::set GetLinks() const; ///< returns stored links as FairLinks + Int_t GetNLinks() const; ///< returns the number of stored links + FairLink GetLink(Int_t pos) const; ///< returns the FairLink at the given position + FairMultiLinkedData GetLinksWithType(Int_t type) const; ///< returns all FairLinks with the corresponding type + FairLink GetEntryNr() const; + FairMultiLinkedData* GetPointerToLinks() const { return fLink.get(); } ///< returns non-owning pointer + + std::vector GetSortedMCTracks(); + + void SetLinks(FairMultiLinkedData links); ///< Sets the links as vector of FairLink + void SetLink(FairLink link); ///< Sets the Links with a single FairLink + void SetInsertHistory(Bool_t val); + void SetEntryNr(FairLink val); + ///< @param[in] links transfers ownership + void SetPointerToLinks(FairMultiLinkedData* links) { fLink.reset(links); } + void SetPointerToLinks(std::unique_ptr links) { fLink = std::move(links); } + + void AddLinks(FairMultiLinkedData links, + Float_t mult = 1.0); ///< Adds a List of FairLinks (FairMultiLinkedData_Interface) to fLinks + void AddLink(FairLink link); ///< Adds a FairLink link at the end of fLinks. If multi is kTRUE a link is allowed + ///< more than once otherwise + void AddInterfaceData(FairMultiLinkedData_Interface* data); + + void ResetLinks(); + + std::ostream& PrintLinkInfo(std::ostream& out = std::cout) const + { + if (GetPointerToLinks() != 0) + GetPointerToLinks()->PrintLinkInfo(out); + return out; + } ///< Output + + friend std::ostream& operator<<(std::ostream& out, const FairMultiLinkedData_Interface& data) + { + data.PrintLinkInfo(out); + return out; + } ///< Output + + protected: + std::unique_ptr fLink; + FairMultiLinkedData* CreateFairMultiLinkedData(); ///< returns non-owning pointer + + ClassDef(FairMultiLinkedData_Interface, 6); +}; + +/**\fn virtual void FairMultiLinkedData_Interface::SetLinks(Int_t type, std::vector links) + * \param type as Int_t gives one type of source data for all indices + * \param links as vector gives the vector of indices at which position in the TClonesArray the source data is + * stored + */ + +/**\fn virtual void FairMultiLinkedData_Interface::SetLinks(std::vector type, std::vector links) + * \param type as vector gives the type of source data (TClonesArray) + * \param links as vector gives the vector of indices at which position in the TClonesArray the source data is + * stored + */ + +#endif /* FairMultiLinkedData_Interface_H_ */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairParticle.h b/Detectors/3rdparty/FairRootBase/include/FairParticle.h new file mode 100644 index 0000000000000..b2b1dd627d6e8 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairParticle.h @@ -0,0 +1,119 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/// Class FAIRParticle +/// ------------------ +/// Extended TParticle with persistent pointers to mother and daughters +/// particles (Ivana Hrivnacova, 5.4.2002) +/// Used to define particles which will be added to Geant3/4 (M. Al-Turany) + +#ifndef FAIR_PARTICLE_H +#define FAIR_PARTICLE_H + +#include // for Int_t, Double_t, Bool_t, etc +#include // for TMCParticleType +#include // for TObject +#include // for TRef +#include // for TRefArray +#include // for TString + +class TParticle; + +class FairParticle : public TObject +{ + public: + FairParticle(Int_t id, TParticle* particle); + FairParticle(Int_t id, TParticle* particle, FairParticle* mother); + FairParticle(const char* name, + Int_t z, + Int_t a, + Int_t s, + Double_t mass, + Int_t q, + Bool_t stable, + Double_t decaytime); + FairParticle(const char* name, Int_t z, Int_t a, Double_t mass, Int_t q, Bool_t stable, Double_t decaytime); + FairParticle(Int_t pdg, + const TString name, + TMCParticleType mcType, + Double_t mass, + Double_t charge, + Double_t lifetime, + const TString pType = "Ion", + Double_t width = 0, + Int_t iSpin = 0, + Int_t iParity = 0, + Int_t iConjugation = 0, + Int_t iIsospin = 0, + Int_t iIsospinZ = 0, + Int_t gParity = 0, + Int_t lepton = 0, + Int_t baryon = 0, + Bool_t stable = kFALSE); + + FairParticle(); + + virtual ~FairParticle(); + + // methods + void SetMother(FairParticle* particle); + void AddDaughter(FairParticle* particle); + virtual void Print(Option_t* option = "") const; + void PrintDaughters() const; + + // get methods + Int_t GetPDG() const; + TParticle* GetParticle() const; + FairParticle* GetMother() const; + Int_t GetNofDaughters() const; + FairParticle* GetDaughter(Int_t i) const; + virtual const char* GetName() const { return fname.Data(); } + TMCParticleType GetMCType() { return fmcType; } + Double_t GetMass() { return fmass; } + Double_t GetCharge() { return fcharge; } + Double_t GetDecayTime() { return fDecayTime; } + const TString& GetPType() { return fpType; } + Double_t GetWidth() { return fwidth; } + Int_t GetSpin() { return fiSpin; } + Int_t GetiParity() { return fiParity; } + Int_t GetConjugation() { return fiConjugation; } + Int_t GetIsospin() { return fiIsospin; } + Int_t GetIsospinZ() { return fiIsospinZ; } + Int_t GetgParity() { return fgParity; } + Int_t GetLepton() { return flepton; } + Int_t GetBaryon() { return fbaryon; } + Bool_t IsStable() { return fstable; } + + private: + FairParticle(const FairParticle& P); + FairParticle& operator=(const FairParticle&) { return *this; } + // data members + Int_t fpdg; + TParticle* fParticle; + TRef fMother; + TRefArray fDaughters; + const TString fname; + TMCParticleType fmcType; + Double_t fmass; + Double_t fcharge; + Double_t fDecayTime; + const TString fpType; + Double_t fwidth; + Int_t fiSpin; + Int_t fiParity; + Int_t fiConjugation; + Int_t fiIsospin; + Int_t fiIsospinZ; + Int_t fgParity; + Int_t flepton; + Int_t fbaryon; + Bool_t fstable; + + ClassDef(FairParticle, 3); +}; + +#endif // FAIR_PARTICLE_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairPrimaryGenerator.h b/Detectors/3rdparty/FairRootBase/include/FairPrimaryGenerator.h new file mode 100644 index 0000000000000..662560fc8b384 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairPrimaryGenerator.h @@ -0,0 +1,273 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +/** FairPrimaryGenerator.h + *@author V.Friese + * +The FairPrimaryGenerator is responsible for the handling of the MC input. +Several input generators can be registered to it; these have to be +derived from the FairGenerator class. The FairPrimaryGenerator defines +position and (optionally) smearing of the primary vertex. +This class should be instantised only once. + +Modified 05.06.07: add a method DoTracking(Bool_t) to be able to switch on/off +the tracking from the macro (M. Al-Turany) + +**/ + +#ifndef FAIRPRIMARYGENERATOR_H +#define FAIRPRIMARYGENERATOR_H + +#include "FairGenerator.h" // for FairGenerator + +#include // for Double_t, Bool_t, Int_t, etc +#include +#include // for TNamed +#include // for TObjArray +#include // for TVector3 +#include // for cout + +class FairGenericStack; +class FairMCEventHeader; +class TIterator; + +class FairPrimaryGenerator : public TNamed +{ + + public: + /** Default constructor. **/ + FairPrimaryGenerator(); + + /** Constructor with name and title **/ + FairPrimaryGenerator(const char *name, const char *title = "FAIR Generator"); + + /** Destructor. **/ + virtual ~FairPrimaryGenerator(); + + /** Initialize the generater (if needed!)*/ + virtual Bool_t Init(); + + /** Register a generator derived from FairGenerator. **/ + void AddGenerator(FairGenerator *generator) + { + if (!fGenList) { + std::cout << "Empty fGenList pointer ! " << std::endl; + return; + } + fGenList->Add(generator); + } + + void SetEventNr(Int_t evtNr) { fEventNr = evtNr; } + + /** Public method GenerateEvent + To be called at the beginning of each event from FairMCApplication. + Generates an event vertex and calls the ReadEvent methods from the + registered generators. + *@param pStack The particle stack + *@return kTRUE if successful, kFALSE if not + **/ + virtual Bool_t GenerateEvent(FairGenericStack *pStack); + + /** Public method AddTrack + Adding a track to the MC stack. To be called within the ReadEvent + methods of the registered generators. + *@param pdgid Particle ID (PDG code) + *@param px,py,pz Momentum coordinates [GeV] + *@param vx,vy,vz Track origin relative to event vertex + **/ + virtual void AddTrack(Int_t pdgid, + Double_t px, + Double_t py, + Double_t pz, + Double_t vx, + Double_t vy, + Double_t vz, + Int_t parent = -1, + Bool_t wanttracking = true, + Double_t e = -9e9, + Double_t tof = 0., + Double_t weight = 0., + TMCProcess proc = kPPrimary); + + /** Clone this object (used in MT mode only) */ + virtual FairPrimaryGenerator *ClonePrimaryGenerator() const; + + /** Set beam position and widths. + *@param beamX0 mean x position of beam at target + *@param beamY0 mean y position of beam at target + *@param beamSigmaX Gaussian beam width in x + *@param beamSigmaY Gaussian beam width in y + **/ + void SetBeam(Double_t beamX0, Double_t beamY0, Double_t beamSigmaX, Double_t beamSigmaY); + + /** Set nominal beam angle and angle widths. + *@param beamAngleX0 mean x angle of beam at target + *@param beamAngleY0 mean y angle of beam at target + *@param beamAngleSigmaX Gaussian beam angle width in x + *@param beamAngleSigmaY Gaussian beam angle width in y + **/ + void SetBeamAngle(Double_t beamAngleX0, Double_t beamAngleY0, Double_t beamAngleSigmaX, Double_t beamAngleSigmaY); + + /** Public method SetEventPlane + **@param phiMin Lower limit for event plane angle [rad] + **@param phiMax Upper limit for event plane angle [rad] + **If set, an event plane angle will be generated with flat + **distrtibution between phiMin and phiMax. + **/ + void SetEventPlane(Double_t phiMin, Double_t phiMax); + + /** Set target position and thickness. + *@param targetZ z position of target center + *@param targetDz full target thickness + **/ + void SetTarget(Double_t targetZ, Double_t targetDz); + + /** Set target position for multiple tagets. The thickness + * is the same for all targets. + *@param nroftargets number of targets + *@param *targetZ z positions of target center + *@param targetDz full target thickness + **/ + void SetMultTarget(Int_t nroftargets, Double_t *targetZ, Double_t targetDz); + + /** Enable vertex smearing in z and/or xy direction **/ + void SmearVertexZ(Bool_t flag); + void SmearGausVertexZ(Bool_t flag); + void SmearVertexXY(Bool_t flag); + void SmearGausVertexXY(Bool_t flag); + + TObjArray *GetListOfGenerators() { return fGenList; } + + /** Set the pointer to the MCEvent **/ + void SetEvent(FairMCEventHeader *event) { fEvent = event; }; + + /** Accessor to the MCEvent **/ + FairMCEventHeader *GetEvent() { return fEvent; }; + + /** Swich on/off the tracking of a particle*/ + + void DoTracking(Bool_t doTracking = kTRUE) { fdoTracking = doTracking; } + + Int_t GetTotPrimary() { return fTotPrim; } + + protected: + /** Copy constructor */ + FairPrimaryGenerator(const FairPrimaryGenerator &); + /** Assignment operator */ + FairPrimaryGenerator &operator=(const FairPrimaryGenerator &); + + /** Nominal beam position at target in x [cm] */ + Double_t fBeamX0; + /** Nominal beam position at target in y [cm]*/ + Double_t fBeamY0; + /** Beam width (Gaussian) in x [cm]*/ + Double_t fBeamSigmaX; + /** Beam width (Gaussian) in y [cm]*/ + Double_t fBeamSigmaY; + + /** Nominal beam angle at target in x [rad] */ + Double_t fBeamAngleX0; + /** Nominal beam angle at target in y [rad] */ + Double_t fBeamAngleY0; + /** Actual beam angle at target in x [rad] */ + Double_t fBeamAngleX; + /** Actual beam angle at target in y [rad] */ + Double_t fBeamAngleY; + /** Beam angle width (Gaussian) in x [rad]*/ + Double_t fBeamAngleSigmaX; + /** Beam angle width (Gaussian) in y [rad]*/ + Double_t fBeamAngleSigmaY; + /** Actual beam direction at the vertex */ + TVector3 fBeamDirection; + + /** Lower limit for the event plane rotation angle [rad] */ + Double_t fPhiMin; + /** Upper limit for the event plane rotation angle [rad] */ + Double_t fPhiMax; + /** Actual event plane rotation angle [rad] */ + Double_t fPhi; + + /** Nominal z position of center of targets [cm]*/ + Double_t *fTargetZ; //! + /** Number of targets;*/ + Int_t fNrTargets; + /** Full target thickness [cm]*/ + Double_t fTargetDz; + + /** Vertex position of current event [cm]*/ + TVector3 fVertex; + + /** Number of primary tracks in current event*/ + Int_t fNTracks; + + /** Flag for uniform vertex smearing in z*/ + Bool_t fSmearVertexZ; + /** Flag for gaus vertex smearing in z*/ + Bool_t fSmearGausVertexZ; + /** Flag for vertex smearing in xy*/ + Bool_t fSmearVertexXY; + /** Flag for gaus vertex smearing in xy*/ + Bool_t fSmearGausVertexXY; + /** Flag for beam gradient calculation*/ + Bool_t fBeamAngle; + /** Flag for event plane rotation*/ + Bool_t fEventPlane; + + /** Pointer to MC stack*/ + FairGenericStack *fStack; //! + /** List of registered generators */ + TObjArray *fGenList; + /** Iterator over generator list */ + TIterator *fListIter; //! + /** Pointer to MCEventHeader */ + FairMCEventHeader *fEvent; //! + /** go to tracking */ + Bool_t fdoTracking; //! + /** Number of MC tracks before a Generator is called, needed for MC index + * update */ + Int_t fMCIndexOffset; //! + /** Number of all primaries of this run*/ + static Int_t fTotPrim; //! + /** Event number (Set by the primary generator if not set already by one of + the specific generators + **/ + Int_t fEventNr; + + /** Private method MakeVertex. If vertex smearing in xy is switched on, + the event vertex is smeared Gaussianlike in x and y direction + according to the mean beam positions and widths set by the + SetBeam method. If vertex smearing in z is switched on, the z + coordinate of the event vertex is flatly distributed over the + extension of the target. + To be called at the beginning of the event from the + GenerateEvent method. + **/ + virtual void MakeVertex(); + + /** Private method MakeBeamAngle. If beam angle smearing in xy + is switched on, all tracks in an event are rotated by a Gaussianlike + angle distribution around the x and y axis according to the mean + beam angle and angle widths set by the SetBeamAngle method. + To be called at the beginning of the event from the GenerateEvent + method. + **/ + virtual void MakeBeamAngle(); + + /** Private method MakeEventPlane. If the rotation of the event around the + z-axis by a random angle is switched on, the complete event is rotated + by the chosen angle. This function is called at the beginning of the + event from the GenerateEvent method. The function pick a random + rotation angle between fPhiMin and fPhiMax which are set using the + function SetEventPlane. + **/ + void MakeEventPlane(); + + ClassDef(FairPrimaryGenerator, 5); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRadGridManager.h b/Detectors/3rdparty/FairRootBase/include/FairRadGridManager.h new file mode 100644 index 0000000000000..885e8c6616d83 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRadGridManager.h @@ -0,0 +1,121 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadGridManager source file ----- +// ----- original author D.Bertini ----- +// ----- adapted april 2010 O.Hartmann ----- +// ------------------------------------------------------------------------- +#ifndef FAIRRADGRIDMANAGER_H +#define FAIRRADGRIDMANAGER_H 1 + +#include // for Float_t, Double_t, Int_t, etc +#include // for TLorentzVector +#include // for TObjArray +#include // for TString +#include // for basic_ostream::operator<<, etc + +class FairMesh; +class TClonesArray; + +/** + * @class FairRadGridManager + */ + +class FairRadGridManager +{ + public: + /** + * Default constructor. + * Creates the singleton object of FairRadGridManager class. + * The pointer to this object can be reached via FairRadGridManager::Instance(). + */ + FairRadGridManager(); + /** + * Destructor. + */ + virtual ~FairRadGridManager(); + + /** + * Class definition. + */ + ClassDef(FairRadGridManager, 1); + + private: + FairRadGridManager(const FairRadGridManager&); + FairRadGridManager& operator=(const FairRadGridManager&); + + static FairRadGridManager* fgInstance; + + /** + * collection of point + */ + TClonesArray* fPointCollection; + /**track index */ + Int_t fTrackID; //! + /**volume id */ + Int_t fVolumeID; //! + /** entry position in global frame*/ + TLorentzVector fPosIn; //! + /** exit position in global frame*/ + TLorentzVector fPosOut; //! + /** momentum in*/ + TLorentzVector fMomIn; //! + /** momentum out*/ + TLorentzVector fMomOut; //! + /**track time */ + Double_t fTime; //! + /**track length */ + Double_t fLength; //! + /** energy loss */ + Double_t fELoss; //! + /** mass umber*/ + Float_t fA; + /** atomic number*/ + Float_t fZmat; + /** density */ + Float_t fDensity; + /**radition length */ + Float_t fRadl; + /**absorption length */ + Float_t fAbsl; + /**estimator*/ + Int_t fEstimator; + /** the mesh */ + TObjArray* fMeshList; + /** output file name */ + TString fOutputFileName; + + static Double_t fLtmp; + + public: + TObjArray* GetMeshList() { return fMeshList; } + void AddMeshList(TObjArray* list) + { + std::cout << " grid manag " << list->GetEntriesFast() << std::endl; + fMeshList = list; + } + Bool_t IsTrackInside(TLorentzVector& vec, FairMesh* aMesh); + Bool_t IsTrackEntering(TLorentzVector& vec1, TLorentzVector& vec2); + /** fill the 2D mesh */ + void FillMeshList(); + /**initialize the manager*/ + void Init(); + /**reset*/ + void Reset(); + /**set output file name*/ + void SetOutputFileName(TString tempString) { fOutputFileName = tempString; } + TString GetOutputFileName() { return fOutputFileName; } + /** + * This function is used to access the methods of the class. + * @return Pointer to the singleton FairRadGridManager object, created + * with FairRadGridManager::FairRadGridManager(). + */ + static FairRadGridManager* Instance(); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRadLenManager.h b/Detectors/3rdparty/FairRootBase/include/FairRadLenManager.h new file mode 100644 index 0000000000000..13573a2fca39a --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRadLenManager.h @@ -0,0 +1,98 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadLenManager source file ----- +// ----- Created 14/01/08 by M. Al-Turany ----- +// ------------------------------------------------------------------------- +#ifndef FAIRRADLENMANAGER_H +#define FAIRRADLENMANAGER_H 1 + +#include // for Float_t, Double_t, Int_t, etc +#include // for TLorentzVector + +class TClonesArray; + +/** + * @class FairRadLenManager + */ + +class FairRadLenManager +{ + public: + /** + * Default constructor. + * Creates the singleton object of FairRadLenManager class. + * The pointer to this object can be reached via FairRadLenManager::Instance(). + */ + FairRadLenManager(); + + /** + * Destructor. + */ + virtual ~FairRadLenManager(); + + /** + * Class definition. + */ + ClassDef(FairRadLenManager, 1); + + private: + FairRadLenManager(const FairRadLenManager&); + FairRadLenManager& operator=(const FairRadLenManager&); + + static FairRadLenManager* fgInstance; + + /** + * collection of point + */ + TClonesArray* fPointCollection; + /**track index */ + Int_t fTrackID; //! + /**volume id */ + Int_t fVolumeID; //! + /** entry position in global frame*/ + TLorentzVector fPosIn; //! + /** exit position in global frame*/ + TLorentzVector fPosOut; //! + /** momentum in*/ + TLorentzVector fMomIn; //! + /** momentum out*/ + TLorentzVector fMomOut; //! + /**track time */ + Double_t fTime; //! + /**track length */ + Double_t fLength; //! + /** energy loss */ + Double_t fELoss; //! + /** mass umber*/ + Float_t fA; + /** atomic number*/ + Float_t fZmat; + /** density */ + Float_t fDensity; + /**radition length */ + Float_t fRadl; + /**absorption length */ + Float_t fAbsl; + + public: + /**Add point to collection*/ + void AddPoint(Int_t& ModuleId); + /**initialize the manager*/ + void Init(); + /**reset*/ + void Reset(); + /** + * This function is used to access the methods of the class. + * @return Pointer to the singleton FairRadLenManager object, created + * with FairRadLenManager::FairRadLenManager(). + */ + static FairRadLenManager* Instance(); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRadLenPoint.h b/Detectors/3rdparty/FairRootBase/include/FairRadLenPoint.h new file mode 100644 index 0000000000000..8213c74de38e9 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRadLenPoint.h @@ -0,0 +1,90 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadLenPoint header file ----- +// ----- Created 14/01/08 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +/** FairRadLenPoint.h + *@author M. Al-Turany + * + */ + +#ifndef FAIRRADLENPOINT_H +#define FAIRRADLENPOINT_H + +#include "FairMCPoint.h" // for FairMCPoint + +#include // for Double_t, Float_t, etc +#include // for TVector3 + +class FairRadLenPoint : public FairMCPoint +{ + public: + /** Default constructor **/ + FairRadLenPoint(); + + FairRadLenPoint(Int_t trackID, + Int_t detID, + TVector3 pos, + TVector3 mom, + Double_t tof, + Double_t length, + Double_t eLoss, + TVector3 posOut, + TVector3 momOut, + Float_t fA, + Float_t fZ, + Float_t fDensity, + Float_t fRadLen); + + /** Destructor **/ + virtual ~FairRadLenPoint(); + + /** Accessors **/ + Float_t GetA() { return fA; } + Float_t GetZm() { return fZmat; } + Float_t GetRadLength() { return fRadLen; } + Float_t GetDensity() { return fDensity; } + + /** Modifiers **/ + void SetA(Double_t A) { fA = A; } + void SetZm(Double_t Z) { fZmat = Z; } + void SetRadLength(Double_t length) { fRadLen = length; } + void SetDensity(Double_t Density) { fDensity = Density; } + + /** Output to screen **/ + virtual void Print(const Option_t* opt) const; + + Double_t GetXOut() const { return fXOut; }; + Double_t GetYOut() const { return fYOut; }; + Double_t GetZOut() const { return fZOut; }; + + Double_t GetPxOut() const { return fPxOut; } + Double_t GetPyOut() const { return fPyOut; } + Double_t GetPzOut() const { return fPzOut; } + + TVector3 GetPosition() const { return TVector3(fX, fY, fZ); } + TVector3 GetPositionOut() const { return TVector3(fXOut, fYOut, fZOut); } + + void PositionOut(TVector3& pos) const { pos.SetXYZ(fXOut, fYOut, fZOut); }; + void MomentumOut(TVector3& mom) const { mom.SetXYZ(fPxOut, fPyOut, fPzOut); } + + protected: + Float_t fA; // A of material + Float_t fZmat; // Z of material + Float_t fDensity; // density of material + Float_t fRadLen; // radiation length + + Double_t fXOut, fYOut, fZOut; + Double_t fPxOut, fPyOut, fPzOut; + + ClassDef(FairRadLenPoint, 1); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRadMapManager.h b/Detectors/3rdparty/FairRootBase/include/FairRadMapManager.h new file mode 100644 index 0000000000000..766af76ff8adf --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRadMapManager.h @@ -0,0 +1,111 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadMapManager source file ----- +// ------------------------------------------------------------------------- +#ifndef FAIRRADMAPMANAGER_H +#define FAIRRADMAPMANAGER_H 1 + +#include // for Double_t, Float_t, Int_t, etc +#include // for TLorentzVector + +class TClonesArray; +class TMap; + +/** + * @class FairRadMapManager + */ + +class FairRadMapManager +{ + public: + /** + * Default constructor. + * Creates the singleton object of FairRadMapManager class. + * The pointer to this object can be reached via FairRadMapManager::Instance(). + */ + FairRadMapManager(); + + /** + * Destructor. + */ + virtual ~FairRadMapManager(); + + /** + * Class definition. + */ + ClassDef(FairRadMapManager, 1); + + private: + FairRadMapManager(const FairRadMapManager&); + FairRadMapManager& operator=(const FairRadMapManager&); + + static FairRadMapManager* fgInstance; + + /** + * collection of point + */ + TClonesArray* fPointCollection; + /**track index */ + Int_t fTrackID; //! + /**volume id */ + Int_t fVolumeID; //! + /** pid */ + Int_t fPdg; //! + /** entry position in global frame*/ + TLorentzVector fPosIn; //! + /** exit position in global frame*/ + TLorentzVector fPosOut; //! + /** momentum in*/ + TLorentzVector fMomIn; //! + /** momentum out*/ + TLorentzVector fMomOut; //! + /**track time */ + Double_t fTime; //! + /**track length */ + Double_t fLength; //! + /**track setp */ + Double_t fStep; + /** energy loss */ + Double_t fELoss; //! + /**dose */ + Double_t fDose; + Double_t fDoseSL; + /** mass umber*/ + Float_t fA; + /** atomic number*/ + Float_t fZmat; + /** radiation length*/ + Float_t fRadl; + /** density */ + Float_t fDensity; + /**absorption length */ + Float_t fAbsl; + //**volume, mass */ + Double_t fActVol; + Double_t fActMass; + + TMap* fMassMap; + + public: + /**Add point to collection*/ + void AddPoint(Int_t& ModuleId); + /**initialize the manager*/ + void Init(); + /**reset*/ + void Reset(); + /** + * This function is used to access the methods of the class. + * @return Pointer to the singleton FairRadMapManager object, created + * with FairRadMapManager::FairRadMapManager(). + */ + static FairRadMapManager* Instance(); + // void GetGeoManager(); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRadMapPoint.h b/Detectors/3rdparty/FairRootBase/include/FairRadMapPoint.h new file mode 100644 index 0000000000000..07f40560fcaf8 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRadMapPoint.h @@ -0,0 +1,101 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadMapPoint header file ----- +// ------------------------------------------------------------------------- + +/** FairRadMapPoint.h + *@author O.N. Hartmann + * + */ + +#ifndef FAIRRADMAPPOINT_H +#define FAIRRADMAPPOINT_H + +#include "FairMCPoint.h" // for FairMCPoint + +#include // for Double_t, Float_t, Int_t, etc +#include // for TVector3 + +class FairRadMapPoint : public FairMCPoint +{ + public: + /** Default constructor **/ + FairRadMapPoint(); + + FairRadMapPoint(Int_t trackID, + Int_t detID, + TVector3 pos, + TVector3 mom, + Double_t tof, + Double_t length, + Double_t eLoss, + TVector3 posOut, + TVector3 momOut, + Float_t fA, + Float_t fZ, + Float_t fDensity, + Double_t fVolMass, + Double_t fStep, + Double_t fDose, + Double_t fDoseSL, + Int_t fPdg); + + /** Destructor **/ + virtual ~FairRadMapPoint(); + + /** Accessors **/ + Float_t GetA() { return fA; } + Float_t GetZm() { return fZmat; } + Float_t GetMass() { return fVolMass; } + Float_t GetDensity() { return fDensity; } + + /** Modifiers **/ + void SetA(Double_t A) { fA = A; } + void SetZm(Double_t Z) { fZmat = Z; } + void SetMass(Double_t vmass) { fVolMass = vmass; } + void SetDensity(Double_t Density) { fDensity = Density; } + + /** Output to screen **/ + virtual void Print(const Option_t* opt) const; + + Int_t GetPdg() const { return fPdg; }; + + Double_t GetXOut() const { return fXOut; } + Double_t GetYOut() const { return fYOut; } + Double_t GetZOut() const { return fZOut; } + + Double_t GetPxOut() const { return fPxOut; } + Double_t GetPyOut() const { return fPyOut; } + Double_t GetPzOut() const { return fPzOut; } + + Double_t GetDose() const { return fDose; } + Double_t GetDoseSL() const { return fDoseSL; } + + TVector3 GetPosition() const { return TVector3(fX, fY, fZ); } + TVector3 GetPositionOut() const { return TVector3(fXOut, fYOut, fZOut); } + + void PositionOut(TVector3& pos) const { pos.SetXYZ(fXOut, fYOut, fZOut); }; + void MomentumOut(TVector3& mom) const { mom.SetXYZ(fPxOut, fPyOut, fPzOut); } + + protected: + // Int_t detID; // detector ID or volume ID + Int_t fPdg; // track PID + Float_t fA; // A of material + Float_t fZmat; // Z of material + Float_t fDensity; // density of material + Double_t fVolMass; // radiation length + + Double_t fStep, fDose, fDoseSL; + Double_t fXOut, fYOut, fZOut; + Double_t fPxOut, fPyOut, fPzOut; + + ClassDef(FairRadMapPoint, 3); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRootFileSink.h b/Detectors/3rdparty/FairRootBase/include/FairRootFileSink.h new file mode 100644 index 0000000000000..726ae1af62bab --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRootFileSink.h @@ -0,0 +1,99 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairRootFileSink ----- +// ----- Created 22.12.2017 by R. Karabowicz ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#ifndef __FAIRROOT__FairRootFileSink__ +#define __FAIRROOT__FairRootFileSink__ + +#include "FairSink.h" + +#include +#include +#include +#include + +class FairEventHeader; +class FairFileHeader; +class TBranch; +class TObjArray; +class TObject; +class TTree; +class TFolder; + +class FairRootFileSink : public FairSink +{ + public: + FairRootFileSink(TFile* f, const char* Title = "OutputRootFile"); + FairRootFileSink(const TString* RootFileName, const char* Title = "OutputRootFile"); + FairRootFileSink(const TString RootFileName, const char* Title = "OutputRootFile"); + // FairRootFileSink(const FairRootFileSink& file); + virtual ~FairRootFileSink(); + + virtual Bool_t InitSink(); + virtual void Close(); + virtual void Reset(); + + virtual Sink_Type GetSinkType() { return kFILESINK; } + + virtual void FillEventHeader(FairEventHeader* feh); + + virtual TFile* OpenRootFile(TString fileName = ""); + TFile* GetRootFile() { return fRootFile; } + virtual TString GetFileName() { return (fRootFile ? fRootFile->GetName() : ""); } + + virtual void SetOutTree(TTree* fTree) { fOutTree = fTree; } + TTree* GetOutTree() { return fOutTree; } + + virtual void Fill(); + + virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0); + + virtual void RegisterImpl(const char*, const char*, void*); + virtual void RegisterAny(const char* brname, const std::type_info& oi, const std::type_info& pi, void* obj); + + virtual void WriteFolder(); + virtual bool CreatePersistentBranchesAny(); + + virtual void WriteObject(TObject* f, const char*, Int_t option = 0); + virtual void WriteGeometry(); + + virtual FairSink* CloneSink(); + + private: + /** Title of input sink, could be input, background or signal*/ + TString fOutputTitle; + /** ROOT file */ + TFile* fRootFile; + /** Output Tree */ + TTree* fOutTree; + /** list of folders from all input (and friends) files */ + TObjArray* fListFolder; //! + /** folder structure of output */ + TFolder* fCbmout; + /** Initialization flag, true if initialized */ + Bool_t fIsInitialized; + + FairRootFileSink(const FairRootFileSink&); + FairRootFileSink operator=(const FairRootFileSink&); + + void TruncateBranchNames(); + void TruncateBranchNames(TBranch* b, TString ffn); + // bool CreatePersistentBranchesAny(); + + /**File Header*/ + FairFileHeader* fFileHeader; //! + + ClassDef(FairRootFileSink, 1); +}; + +#endif /* defined(__FAIRROOT__FairRootFileSink__) */ diff --git a/Detectors/3rdparty/FairRootBase/include/FairRootManager.h b/Detectors/3rdparty/FairRootBase/include/FairRootManager.h new file mode 100644 index 0000000000000..11eede224b0f2 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRootManager.h @@ -0,0 +1,532 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIR_ROOT_MANAGER_H +#define FAIR_ROOT_MANAGER_H + +#include "FairLogger.h" +#include "FairSink.h" +#include "FairSource.h" + +#include // for Bool_t, Int_t, UInt_t, etc +#include // for TChain +#include // for multi-threading +#include // for TObject +#include // for TString, operator< +#include // for map, multimap, etc +#include +#include +#include // is_pointer, remove_pointer, is_const, remove... +#include +#include + +class BinaryFunctor; +class FairEventHeader; +class FairFileHeader; +class FairLink; +class FairTSBufferFunctional; +class FairWriteoutBuffer; +class TBranch; +class TClonesArray; +class TObjArray; +class TCollection; +class TFile; +class TFolder; +class TIterator; +class TList; +class TNamed; +class TRefArray; +class TTree; + +/** + * I/O Manager class + * @author M. Al-Turany, Denis Bertini + * @version 0.1 + * @since 12.01.04 + */ + +class FairRootManager : public TObject +{ + public: + /**dtor*/ + virtual ~FairRootManager(); + Bool_t AllDataProcessed(); + /** Add a branch name to the Branchlist and give it an id*/ + Int_t AddBranchToList(const char* name); + /** + Check if Branch persistence or not (Memory branch) + return value: + 1 : Branch is Persistance + 2 : Memory Branch + 0 : Branch does not exist */ + Int_t CheckBranch(const char* BrName); + + void CloseSink() + { + if (fSink) { + fSink->Close(); + } + } + /**Create a new file and save the current TGeoManager object to it*/ + void CreateGeometryFile(const char* geofile); + void Fill(); + void LastFill(); + TClonesArray* GetEmptyTClonesArray(TString branchName); + TClonesArray* GetTClonesArray(TString branchName); + /**Update the list of Memory branches from the source used*/ + void UpdateBranches(); + + /**Return branch name by Id*/ + TString GetBranchName(Int_t id); + /**Return Id of a branch named */ + Int_t GetBranchId(TString const& BrName); + + /**The MCTrack branch stands out since it is required by the framework algorithms**/ + Int_t GetMCTrackBranchId() const { return fMCTrackBranchId; } + + /**Return a TList of TObjString of branch names available in this session*/ + TList* GetBranchNameList() { return fBranchNameList; } + /**Return the vector of branch names that were requested by tasks as input*/ + const std::vector& GetReqBranchNames() const { return fReqBrNames; } + + /** Get the Object (container) for the given branch name, + this method can be used to access the data of + a branch that was created from a different + analysis task, and not written in the tree yet. + the user have to cast this pointer to the right type. + Return a pointer to the object (collection) saved in the fInChain branch named BrName*/ + TObject* GetObject(const char* BrName); + + /// Initializes and returns a default object for a branch or looks it up when it exists already. + /// Returns nullptr when the branch does not exist or looking up with wrong type. + /// The name Init indicates that this functions should be called only in Init sections of FairTasks. + /// The returned default object will be filled with data by the framework. + template + T InitObjectAs(const char* BrName); + + /** Return a pointer to the object (collection) saved in the fInTree branch named BrName*/ + Double_t GetEventTime(); + /** Returns a clone of the data object the link is pointing to. The clone has to be deleted in the calling code! */ + TObject* GetCloneOfLinkData(const FairLink link); + /** Get the data of the given branch name, + * this method runs over multiple entries + * of the tree and selects the data according + * to the function and the parameter given. + */ + + TClonesArray* GetCloneOfTClonesArray(const FairLink link); + + void InitTSBuffer(TString branchName, BinaryFunctor* function); + TClonesArray* GetData(TString branchName, BinaryFunctor* function, Double_t parameter); + TClonesArray* GetData(TString branchName, + BinaryFunctor* startFunction, + Double_t startParameter, + BinaryFunctor* stopFunction, + Double_t stopParameter); + void RegisterTSBuffer(TString branchName, FairTSBufferFunctional* functionalBuffer) + { + fTSBufferMap[branchName] = functionalBuffer; + } + void TerminateTSBuffer(TString branchName); + void TerminateAllTSBuffer(); + FairTSBufferFunctional* GetTSBuffer(TString branchName) { return fTSBufferMap[branchName]; } + + /** static access method */ + static FairRootManager* Instance(); + + /**Read a single entry from background chain*/ + Int_t ReadEvent(Int_t i = 0); + /** Read a single entry from each branch that is not read via TSBuffers*/ + Int_t ReadNonTimeBasedEventFromBranches(Int_t i = 0); + /**Read the tree entry on one branch**/ + void ReadBranchEvent(const char* BrName); + /**Read the tree entry on one branch for a specific entry**/ + void ReadBranchEvent(const char* BrName, Int_t entry); + + /**Read all entries from input tree(s) with time stamp from current time to dt (time in ns)*/ + + Int_t GetRunId(); + + Bool_t ReadNextEvent(Double_t dt); + /**create a new branch in the output tree + *@param name Name of the branch to create + *@param Foldername Folder name containing this branch (e.g Detector name) + *@param obj Pointer of type TNamed (e.g. MCStack object) + *@param toFile if kTRUE, branch will be saved to the tree*/ + void Register(const char* name, const char* Foldername, TNamed* obj, Bool_t toFile); + /**create a new branch in the output tree + *@param name Name of the branch to create + *@param Foldername Folder name containing this branch (e.g Detector name) + *@param obj Pointer of type TCollection (e.g. TClonesArray of hits, points) + *@param toFile if kTRUE, branch will be saved to the tree*/ + void Register(const char* name, const char* Foldername, TCollection* obj, Bool_t toFile); + + /** create a new branch based on an arbitrary type T (for which a dictionary must exist) **/ + template + void RegisterAny(const char* name, T*& obj, Bool_t toFile); + /// for branches which are not managed by folders, we need a special function + /// to trigger persistent branch creation + /// return true if successful; false if problem + bool CreatePersistentBranchesAny(); + + void RegisterInputObject(const char* name, TObject* obj); + + TClonesArray* Register(TString branchName, TString className, TString folderName, Bool_t toFile); + /** Register a new FairWriteoutBuffer to the map. If a Buffer with the same map key already exists the given buffer + * will be deleted and the old will be returned!*/ + FairWriteoutBuffer* RegisterWriteoutBuffer(TString branchName, FairWriteoutBuffer* buffer); + /**Update the list of time based branches in the output file*/ + void UpdateListOfTimebasedBranches(); + /**Use time stamps to read data and not tree entries*/ + void RunWithTimeStamps() { fTimeStamps = kTRUE; } + + /**Set the branch name list*/ + void SetBranchNameList(TList* list); + /** Replace the time based branch name list*/ + void SetTimeBasedBranchNameList(TList* list); + + void FillEventHeader(FairEventHeader* feh) + { + if (fSource) + fSource->FillEventHeader(feh); + } + + /**Enables a last Fill command after all events are processed to store any data which is still in Buffers*/ + void SetLastFill(Bool_t val = kTRUE) { fFillLastData = val; } + /**When creating TTree from TFolder the fullpath of the objects is used as branch names + * this method truncate the full path from the branch names + */ + + Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0); + /** Write the current TGeoManager to file*/ + void WriteGeometry(); + /**Write the file header object to the output file*/ + void WriteFileHeader(FairFileHeader* f); + /**Write the folder structure used to create the tree to the output file */ + void WriteFolder(); + + /**Check the maximum event number we can run to*/ + Int_t CheckMaxEventNo(Int_t EvtEnd = 0); + + void StoreWriteoutBufferData(Double_t eventTime); + void StoreAllWriteoutBufferData(); + void DeleteOldWriteoutBufferData(); + + Int_t GetEntryNr() { return fEntryNr; } + void SetEntryNr(Int_t val) { fEntryNr = val; } + + void SetUseFairLinks(Bool_t val) { fUseFairLinks = val; }; + Bool_t GetUseFairLinks() const { return fUseFairLinks; }; + + /** + * @param Status : if true all inputs are mixed, i.e: each read event will take one entry from each input and put + * them in one big event and send it to the next step + */ + /* void SetMixAllInputs(Bool_t Status) { */ + /* fMixAllInputs=kTRUE; */ + /* } */ + + /** These methods have been moved to the FairFileSource */ + void SetSource(FairSource* tempSource) { fSource = tempSource; } + FairSource* GetSource() { return fSource; } + Bool_t InitSource(); + + void SetSink(FairSink* tempSink) { fSink = tempSink; } + FairSink* GetSink() { return fSink; } + Bool_t InitSink(); + + void SetListOfFolders(TObjArray* ta) { fListFolder = ta; } + TChain* GetInChain() { return fSourceChain; } + TChain* GetSignalChainNo(UInt_t i) { return fSignalChainList[i]; } + TTree* GetInTree() + { + if (fSourceChain) + return fSourceChain->GetTree(); + return 0; + } + const TFile* GetRootFile() + { + if (fSourceChain) + return fSourceChain->GetFile(); + return 0; + } + TFile* GetInFile() + { + if (fSourceChain) + return fSourceChain->GetFile(); + return 0; + } + void SetInChain(TChain* tempChain, Int_t ident = -1); + /* /\**Set the input tree when running on PROOF worker*\/ */ + + void SetFinishRun(Bool_t val = kTRUE) { fFinishRun = val; } + Bool_t FinishRun() { return fFinishRun; } + + static void SetTreeName(const std::string& tname) { fTreeName = tname; } + static void SetFolderName(const std::string& tname) { fFolderName = tname; } + + const static char* GetTreeName(); + const static char* GetFolderName(); + + /**public Members for multi-threading */ + Int_t GetInstanceId() const { return fId; } + void UpdateFileName(TString& fileName); + + // vvvvvvvvvv depracted functions, replaced by FairSink vvvvvvvvvv + /** Return a pointer to the output File of type TFile */ + TFile* GetOutFile(); + /** Return a pointer to the output tree of type TTree */ + TTree* GetOutTree(); + // ^^^^^^^^^^ depracted functions, replaced by FairSink ^^^^^^^^^^ + + /**Read one event from source to find out which RunId to use*/ + Bool_t SpecifyRunId(); + + private: + // helper struct since std::pair has problems with type_info + struct TypeAddressPair + { + TypeAddressPair(const std::type_info& oi, const std::type_info& pi, void* a) + : origtypeinfo(oi) + , persistenttypeinfo(pi) + , ptraddr(a) + {} + const std::type_info& origtypeinfo; // type_info of type addr points to + const std::type_info& persistenttypeinfo; // type_info of ROOT persistent branch (drops pointers) + void* ptraddr; // address of a pointer (pointing to origtypeinfo); + }; + + /**private methods*/ + /**ctor*/ + FairRootManager(); + FairRootManager(const FairRootManager&); + FairRootManager& operator=(const FairRootManager&); + /** Set the branch address for a given branch name and return + a TObject pointer, the user have to cast this pointer to the right type.*/ + TObject* ActivateBranch(const char* BrName); + void AddFriends(); + /**Add a branch to memory, it will not be written to the output files*/ + void AddMemoryBranch(const char*, TObject*); + + template + void AddMemoryBranchAny(const char* name, T** obj); + template + T GetMemoryBranchAny(const char* name) const; + + template + void RegisterImpl(const char* name, const char* Foldername, T* obj, Bool_t toFile); + + /** Internal Check if Branch persistence or not (Memory branch) + return value: + 1 : Branch is Persistance + 2 : Memory Branch + 0 : Branch does not exist + */ + Int_t CheckBranchSt(const char* BrName); + /**Create the Map for the branch persistency status */ + void CreatePerMap(); + TObject* GetMemoryBranch(const char*); + // void GetRunIdInfo(TString fileName, TString inputLevel); + + FairWriteoutBuffer* GetWriteoutBuffer(TString branchName); + + // private helper function to emit a warning + void EmitMemoryBranchWrongTypeWarning(const char* brname, const char* typen1, const char* typen2) const; + + /**private Members*/ + Int_t fOldEntryNr; + /**folder structure of output*/ + TFolder* fOutFolder; + /**folder structure of input*/ + TFolder* fRootFolder; + /** current time in ns*/ + Double_t fCurrentTime; + TObject** fObj2; //! + /** Counter for the number of branches activiated */ + Int_t fNObj; //! + /** A list which hold the pointer to the branch + * and the name of the branch in memory, it contains all branches (TClonesArrays) + * persistance and Memory only branches + */ + std::map fMap; //! + + /**folder name variable*/ + static std::string fFolderName; //! + /**tree name variable*/ + static std::string fTreeName; //! + static std::string GetNameFromFile(const char* namekind); + + /// A map of branchnames to typeinformation + memory address; + /// used for branches registered with RegisterAny; use of ptr here + /// since type_info cannot be copied + std::map> fAnyBranchMap; //! + /// keeps track of branches which are supposed to be persistified + std::vector fPersistentBranchesAny; + + /**Branch id for this run */ + Int_t fBranchSeqId; + /**List of branch names as TObjString*/ + TList* fBranchNameList; //! + /**Vector of (not necessarily unique) branch names requested per GetObject / InitObjectAs */ + std::vector fReqBrNames; //! + + /**The branch ID for the special (required) MCTrack branch**/ + Int_t fMCTrackBranchId; //! + + /**List of Time based branchs names as TObjString*/ + TList* fTimeBasedBranchNameList; //! + /** Internally used to compress empty slots in data buffer*/ + std::map fActiveContainer; + /** Internally used to read time ordered data from branches*/ + std::map fTSBufferMap; //! + std::map fWriteoutBufferMap; //! + std::map fInputBranchMap; //! //Map of input branch ID with TBranch pointer + /**if kTRUE Read data according to time and not entries*/ + Bool_t fTimeStamps; + /**Flag for creation of Map for branch persistency list */ + Bool_t fBranchPerMap; + /** Map for branch persistency list */ + std::map fBrPerMap; //! + /**Iterator for the fBrPerMap Map*/ + std::map::iterator fBrPerMapIter; + + /** for internal use, to return the same event time for the same entry*/ + UInt_t fCurrentEntryNo; //! + /** for internal use, to return the same event time for the same entry*/ + UInt_t fTimeforEntryNo; //! + Bool_t fFillLastData; //! + Int_t fEntryNr; //! + + TObjArray* fListFolder; //! + + FairSource* fSource; + + TChain* fSourceChain = nullptr; + std::map fSignalChainList; //! + + FairEventHeader* fEventHeader; + + FairSink* fSink; + + Bool_t fUseFairLinks; //! + Bool_t fFinishRun; //! + /** List of branches from input Chain or Tree*/ + TObjArray* fListOfBranchesFromInput; //! + /** Iterator for the list of branches from input Chain or Tree */ + TIterator* fListOfBranchesFromInputIter; //! + /** List of branches used with no-time stamp in time-based session */ + TRefArray* fListOfNonTimebasedBranches; //! + /** Iterator for the list of branches used with no-time stamp in time-based session */ + TIterator* fListOfNonTimebasedBranchesIter; //! + + /**private Members for multi-threading */ + // global static data members + static Int_t fgCounter; // The counter of instances + // data members + Int_t fId; // This manager ID + + ClassDef(FairRootManager, 12); +}; + +// FIXME: move to source since we can make it non-template dependent +template +void FairRootManager::AddMemoryBranchAny(const char* brname, T** obj) +{ + if (fAnyBranchMap.find(brname) == fAnyBranchMap.end()) { + auto& ot = typeid(T*); + auto& pt = typeid(T); + fAnyBranchMap[brname] = std::unique_ptr(new TypeAddressPair(ot, pt, (void*)obj)); + } +} + +// try to retrieve an object address from the registered branches/names +template +T FairRootManager::GetMemoryBranchAny(const char* brname) const +{ + static_assert(std::is_pointer::value, "Return type of GetMemoryBranchAny has to be a pointer"); + using P = typename std::remove_pointer::type; + auto iter = fAnyBranchMap.find(brname); + if (iter != fAnyBranchMap.end()) { + // verify type consistency + if (typeid(P).hash_code() != iter->second->origtypeinfo.hash_code()) { + EmitMemoryBranchWrongTypeWarning(brname, typeid(P).name(), iter->second->origtypeinfo.name()); + return nullptr; + } + return static_cast(iter->second->ptraddr); + } + return nullptr; +} + +template +void FairRootManager::RegisterAny(const char* brname, T*& obj, bool persistence) +{ + AddBranchToList(brname); + // we are taking the address of the passed pointer + AddMemoryBranchAny(brname, &obj); + if (persistence) { + auto& ot = typeid(T*); + auto& pt = typeid(T); + if (fSink) + fSink->RegisterAny(brname, ot, pt, &obj); + else + LOG(fatal) << "The sink does not exist to store persistent branches."; + } +} + +// this function serves as a factory (or lookup) for memory managed +// instances associated to branches +// it returns a pointer to unmodifiable instance of T +template +TPtr FairRootManager::InitObjectAs(const char* brname) +{ + static_assert(std::is_pointer::value, "Return type of GetObjectAs has to be a pointer"); + using X = typename std::remove_pointer::type; + static_assert(std::is_const::value, "Return type of GetObjectAs has to be pointer to const class"); + using T = typename std::remove_const::type; + + // is there already an object associated to the branch in memory?? + // then just return + T** obj = GetMemoryBranchAny(brname); + // obj is some address/instance holding TPtr instances + if (obj != nullptr) + return *obj; + + if (!fSource) { + return nullptr; + } + + // it does not seem to be the case, let us create the pointer which will be initialized + // with the data (pointer to T) + T** addr = new T*; + // init the pointee to a default obj which we can return + (*addr) = new T; + // try to find and activate in the source + auto succeeded = fSource->ActivateObjectAny((void**)addr, typeid(T), brname); + + if (!succeeded) { + delete (*addr); + delete addr; + return nullptr; + } + // add into branch list + AddMemoryBranchAny(brname, addr); + // register as a **requested** branch + // (duplications are explicitely allowed) + fReqBrNames.emplace_back(brname); + + // NOTE: ideally we would do proper resource management for addr and *addr + // since the FairRootManager becomes owner of these pointers/instances; Unfortunately this + // is quite a difficult task since we would have to store something like std::unique_ptr in a member + // container which we cannot know a priori; Some solutions we could think of in the future are + // a) use the Destructor mechanism of ROOT::TClass since we still have the type info. + // b) investigate if boost::any could be of help here + // In any case, this problem is not very critical in the sense that FairRootManager is a singleton and hence + // cannot really leak memory (Assuming that the destructors of T are not doing something non-trivial). + return *addr; +} + +#endif // FAIR_ROOT_MANAGER_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairRun.h b/Detectors/3rdparty/FairRootBase/include/FairRun.h new file mode 100644 index 0000000000000..630342d82b062 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRun.h @@ -0,0 +1,219 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +#ifndef FAIRRUN_H +#define FAIRRUN_H + +#include "FairAlignmentHandler.h" +#include "FairRootManager.h" + +#include // for Int_t, Bool_t, etc +#include // for multi-threading +#include // for TNamed +#include +#include +#include + +class FairEventHeader; +class FairFileHeader; +class FairSink; +class FairTask; +class TFile; +class FairField; +class TGeoHMatrix; + +/** + * Configure the Simuation or Analysis + * @author M. Al-Turany D. Bertini + * @version 0.1 + * @since 12.01.04 + */ + +class FairRun : public TNamed +{ + friend class FairMCApplication; + + public: + /** + * default ctor + */ + FairRun(Bool_t isMaster = kTRUE); + /** + * default dtor + */ + virtual ~FairRun(); + /** + * static instance + */ + static FairRun* Instance(); + /** + * Add a FAIRTask to the simulation or analysis + */ + virtual void AddTask(FairTask* t); + virtual void StoreTaskNames(const FairTask* t); + virtual void SetTask(FairTask* t); + /** + * Initialize the Simulation or analysis + */ + virtual void Init() = 0; + /* + * Get the magnetic field * + */ + virtual FairField* GetField() = 0; + /** + * run the analysis or simulation + */ + virtual void Run(Int_t NStart = 0, Int_t NStop = 0) = 0; + /** + * Set the experiment dependent run header + * for each run + */ + void SetEventHeader(FairEventHeader* EvHeader) { fEvtHeader = EvHeader; } + /** + * return a pointer to the RuntimeDB + */ + /** + * Set the sink + */ + void SetSink(FairSink* tempSink) + { + fSink = tempSink; + fRootManager->SetSink(tempSink); + fUserOutputFileName = fSink->GetFileName(); + } + /** + * return a pointer to the sink + */ + FairSink* GetSink() { return fSink; } + /** + * return the run ID for the actul run + */ + Int_t GetRunId() { return (static_cast(fRunId)); } + + /** + * Set the Run ID + */ + void SetRunId(UInt_t runId) { fRunId = runId; } + + /**Get the detector specific run header*/ + FairEventHeader* GetEventHeader(); + /** + * return true for Anaylsis session + */ + Bool_t IsAna() { return fAna; } + /** + *Get task by name + */ + + FairTask* GetTask(const char* taskName); + /** + *Get Main Task + */ + FairTask* GetMainTask() { return fTask; } + /** + * Return the number of Tasks added to this Run + */ + Int_t GetNTasks() { return fNTasks; } + + /**Create a new file and save the TGeoManager to it*/ + void CreateGeometryFile(const char* geofile); + + //** Set if RunInfo file should be written */ + void SetWriteRunInfoFile(Bool_t write); + + //** Set if RunInfo should be generated */ + void SetGenerateRunInfo(Bool_t write) { fGenerateRunInfo = write; } + + //** Get info if RunInfo file is written */ + Bool_t GetWriteRunInfoFile(); + + //** Get info if RunInfo file is written */ + Bool_t IsRunInfoGenerated() { return fGenerateRunInfo; } + + //** Switches the use of FairLinks */ + void SetUseFairLinks(Bool_t val); + + //** Get info if run on master */ + Bool_t GetIsMaster() const { return fIsMaster; } + + //** Mark/Unmark event to be filled into output. Default is TRUE. */ + void MarkFill(Bool_t flag) { fMarkFill = flag; } + + //** Get option string */ + TString GetOptions() { return fOptions; }; + + //** Set option string */ + void SetOptions(const TString& s) { fOptions = s; }; + + // vvvvvvvvvv depracted functions, replaced by FairSink vvvvvvvvvv + /** + * Set the output file name for analysis or simulation + */ + virtual void SetOutputFile(const char* fname); + /** + * Set the output file for analysis or simulation + */ + virtual void SetOutputFile(TFile* f); + /** + * Set the output file name without creating the file + */ + void SetOutputFileName(const TString& name); + TFile* GetOutputFile(); + // ^^^^^^^^^^ depracted functions, replaced by FairSink ^^^^^^^^^^ + + /** + * New functions which allow to postpone creating a new Sink in MT + * to be kept after clean-up of deprecated functions above + */ + void SetUserOutputFileName(const TString& name); + TString GetUserOutputFileName() const; + + void AddAlignmentMatrices(const std::map& alignmentMatrices, bool invertMatrices = false); + + private: + FairRun(const FairRun& M); + FairRun& operator=(const FairRun&) { return *this; } + /** Number of Tasks added*/ + Int_t fNTasks; + + protected: + /** static pointer to this run*/ + static TMCThreadLocal FairRun* fRunInstance; + /** RuntimeDb*/ + /** Tasks used*/ + FairTask* fTask; + /**IO manager */ + FairRootManager* fRootManager; + /**Output sink*/ + FairSink* fSink; + /**Output file name set by user*/ + TString fUserOutputFileName; + /**Options for derived classes, to be set & parsed by user*/ + TString fOptions; + /**Run Id*/ + UInt_t fRunId; //! + /** true for Anaylsis session*/ + Bool_t fAna; //! + /** MC Event Header */ + FairEventHeader* fEvtHeader; //! + /** File Header */ + FairFileHeader* fFileHeader; + /** true if RunInfo file should be written*/ + Bool_t fGenerateRunInfo; //! + /** true if on master*/ + Bool_t fIsMaster; //! + + Bool_t fMarkFill; //! + + FairAlignmentHandler fAlignmentHandler; + + void AlignGeometry() const; + + ClassDef(FairRun, 5); +}; +#endif // FAIRRUN_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairRunIdGenerator.h b/Detectors/3rdparty/FairRootBase/include/FairRunIdGenerator.h new file mode 100644 index 0000000000000..a282952ed8bb0 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRunIdGenerator.h @@ -0,0 +1,55 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRRUNIDGENERATOR_H +#define FAIRRUNIDGENERATOR_H + +#include // IWYU pragma: keep for timespec +// IWYU pragma: no_include + +typedef unsigned char uint8_t; +typedef unsigned short int uint16_t; +typedef unsigned int uint32_t; +typedef unsigned char uuid_t[16]; + +class FairRunIdGenerator +{ + struct uuid + { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint16_t clock_seq; + uint8_t node[6]; + }; + + struct timespec fTimeSpec; + + int get_random_fd(void); + void get_random_bytes(void*, int); + int get_node_id(unsigned char*); + int get_clock(uint32_t*, uint32_t*, uint16_t*); + void uuid_generate_time(uuid_t); + void uuid_generate_random(uuid_t); + void uuid_generate(uuid_t); + void uuid_pack(const struct uuid*, uuid_t); + void uuid_unpack(const uuid_t, struct uuid*); + + public: + struct timespec getTimeSpec() { return fTimeSpec; } + struct timespec getTimeSpecFromTID(unsigned int ms); + unsigned int getTID(); + + public: + FairRunIdGenerator() + : fTimeSpec() + {} + ~FairRunIdGenerator() {} + unsigned int generateId(void); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRunInfo.h b/Detectors/3rdparty/FairRootBase/include/FairRunInfo.h new file mode 100644 index 0000000000000..f4776b4a1f3db --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRunInfo.h @@ -0,0 +1,51 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRRUNINFO_H +#define FAIRRUNINFO_H + +#include // for Double_t, Long_t, etc +#include // for TObject +#include // for CpuInfo_t, MemInfo_t, etc +#include // for TTimeStamp +#include // for vector + +class TList; + +class FairRunInfo : public TObject +{ + public: + FairRunInfo(); + ~FairRunInfo(); + + void StoreInfo(); + void WriteInfo(); + void Reset(); + + private: + TTimeStamp fTimeStamp; //! + CpuInfo_t fCpuInfo; //! + MemInfo_t fMemInfo; //! + ProcInfo_t fProcInfo; //! + std::vector fTimeDiff; //! + std::vector fTime; //! + std::vector fResidentMemory; //! + std::vector fVirtualMemory; //! + + void CalculateTimeDifference(); + void PrintInfo(); + void GetInfo(); + void CreateAndFillHistograms(TList* histoList); + void WriteHistosToFile(TList* histoList); + + FairRunInfo(const FairRunInfo&); + FairRunInfo& operator=(const FairRunInfo&); + + ClassDef(FairRunInfo, 2); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairRunSim.h b/Detectors/3rdparty/FairRootBase/include/FairRunSim.h new file mode 100644 index 0000000000000..f69962902cc6c --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairRunSim.h @@ -0,0 +1,229 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +#ifndef FAIRRUNSIM_H +#define FAIRRUNSIM_H + +#include "FairIon.h" // for FairIon +#include "FairMCApplication.h" // for FairMCApplication +#include "FairParticle.h" // for FairParticle +#include "FairRun.h" // for FairRun + +#include // for Bool_t, Double_t, Int_t, etc +#include // for multi-threading +#include // for TObjArray +#include // for TString +#include + +class FairField; +class FairMCEventHeader; +class FairMesh; +class FairModule; +class FairPrimaryGenerator; +class FairGenericVMCConfig; + +/** + * Configure the Simulation session + * @author M. Al-Turany D. Bertini + * @version 0.1 + * @since 12.01.04 + */ +class FairRunSim : public FairRun +{ + public: + /** default ctor*/ + FairRunSim(Bool_t isMaster = kTRUE); + /** default dtor*/ + virtual ~FairRunSim(); + /** Singelton instance*/ + static FairRunSim* Instance(); + /** + * Add a module to the simulation (e.g. PIPE, Magnet, ..etc) + */ + void AddModule(FairModule* Mod); + /** + * Add a user defined ion to the simulation + */ + void AddNewIon(FairIon* ion) { fIons->Add(ion); } + /** + * Add a user defined ion to the simulation + */ + void AddNewParticle(FairParticle* Particle) { fParticles->Add(Particle); } + /** + * this method is used by the FAIRMCApplication + */ + TObjArray* GetUserDefIons(); + /** + * this method is used by the FAIRMCApplication + */ + TObjArray* GetUserDefParticles(); + + /** + * Initialize the Simulation + */ + virtual void Init(); + /** + * run the simulation + */ + virtual void Run(Int_t NEvents = 0, Int_t NotUsed = 0); + /** + * Set the magnetic that has to be used for simulation field + */ + void SetField(FairField* field); + /** + * Set the event generator that has to be used for simulation field + */ + void SetGenerator(FairPrimaryGenerator* Gen); + + /** + * Set the experiment dependent event header + * for each Monte Carlo Event + */ + void SetMCEventHeader(FairMCEventHeader* McHeader) { fMCEvHead = McHeader; } + + /** Set the material file name to be used */ + void SetMaterials(const char* MatFileName); + + /**switch On/Off the track visualisation */ + void SetStoreTraj(Bool_t storeTraj = kTRUE) { fStoreTraj = storeTraj; } + + /**Return the switch for the track visualisation */ + Bool_t GetStoreTraj() const { return fStoreTraj; } + + /**switch On/Off the debug mode */ + void SetTrackingDebugMode(Bool_t set) + { + if (fApp) { + fApp->SetTrackingDebugMode(set); + } + } + + /**Set geometry builder*/ + void SetGeoModel(char* name); + + /**return the geometry loader used in this session*/ + TString* GetGeoModel() { return fLoaderName; } + + /**Get the field used in simulation*/ + FairField* GetField() { return fField; } + + /**Get the detector specific event header*/ + FairMCEventHeader* GetMCEventHeader(); + + /**return the full list of modules used in simulation*/ + TObjArray* GetListOfModules() { return ListOfModules; } + + /**Get the used primary generator*/ + FairPrimaryGenerator* GetPrimaryGenerator() { return fGen; } + + /**switch On/Off external decayer (Pythia) */ + void SetPythiaDecayer(Bool_t decayer) { fPythiaDecayer = decayer; } + + /**switch On external decayer (Pythia). Config macro will be used */ + void SetPythiaDecayer(const TString& Config); + + /**switch On user defined decay, Config macro will be called */ + void SetUserDecay(const TString& Config); + + /**switch On/Off user defined decay if true gconfig/UserDecay.C macro will be called */ + void SetUserDecay(Bool_t decay) { fUserDecay = decay; } + + /**Flag for external decayer*/ + Bool_t IsExtDecayer() { return fPythiaDecayer; } + + /**Flag for User decay*/ + Bool_t IsUserDecay() { return fUserDecay; } + + /**Switch on/off Radiation length register */ + void SetRadLenRegister(Bool_t value) { fRadLength = value; } + + void SetRadMapRegister(Bool_t value) { fRadMap = value; } + + void SetRadGridRegister(Bool_t value) { fRadGrid = value; } + + void AddMesh(FairMesh* Mesh); + + void SetUserConfig(const TString& Config) { fUserConfig = Config; } + TString GetUserConfig() { return fUserConfig; } + + void SetUserCuts(const TString& Cuts) { fUserCuts = Cuts; } + TString GetUserCuts() { return fUserCuts; } + + /** Set Beam energy in GeV/c */ + void SetBeamMom(Double_t BeamMom) + { + fBeamMom = BeamMom; + fUseBeamMom = kTRUE; + } + + /** Get the Beam energy */ + Double_t GetBeamMom() { return fBeamMom; } + + /**Get beam energy flag */ + Bool_t UseBeamMom() { return fUseBeamMom; } + + void SetSimSetup(std::function f) + { + fSimSetup = f; + fUseSimSetupFunction = true; + } + + void SetSimulationConfig(FairGenericVMCConfig* tconf) { fSimulationConfig = tconf; } + FairGenericVMCConfig* GetSimulationConfig() { return fSimulationConfig; } + + void SetIsMT(Bool_t isMT) { fIsMT = isMT; } + Bool_t IsMT() const { return fIsMT; } + + void SetImportTGeoToVMC(Bool_t v) { fImportTGeoToVMC = v; } + Bool_t IsImportTGeoToVMC() const { return fImportTGeoToVMC; } + + void StopMCRun() { fApp->StopMCRun(); } + + private: + FairRunSim(const FairRunSim& M); + FairRunSim& operator=(const FairRunSim&) { return *this; } + void SetMCConfig(); + void CheckFlukaExec(); + + protected: + Int_t count; //! /** Internal counter*/ + FairMCApplication* fApp; //! /** Main VMC application */ + Double_t fBeamMom; //! /** Beam Energy in GeV/c */ + Bool_t fUseBeamMom; //! /** flag for use Beam Energy */ + FairPrimaryGenerator* fGen; //! /** Primary Event Generator */ + FairMCEventHeader* fMCEvHead; //! /** MC Event Header */ + static TMCThreadLocal FairRunSim* fginstance; //! /** Singleton Instance */ + FairField* fField; /** Magnetic Field */ + const char* fMapName; //! /** Input file name map*/ + TObjArray* fIons; //! /** Array of user defined ions */ + TObjArray* fParticles; //! /** Array of user defined particles*/ + TObjArray* ListOfModules; //! /** Array of used modules */ + TString MatFname; //! /** Material file name */ + Bool_t fStoreTraj; //! /** Trajectory store flags */ + TString* fLoaderName; //! /** Geometry Model (TGeo or G3)*/ + Bool_t fPythiaDecayer; //! /** flag for using Pythia decayer*/ + TString fPythiaDecayerConfig; //! /** Macro for Pythia decay configuration*/ + Bool_t fUserDecay; /** flag for setting user decay */ + TString fUserDecayConfig; //! /** Macro for decay configuration*/ + Bool_t fRadLength; //! /** flag for registring radiation length*/ + Bool_t fRadMap; //! /** flag for RadiationMapManager + Bool_t fRadGrid; //! + TObjArray* fMeshList; //! /** radiation grid scoring + TString fUserConfig; //! /** Macro for geant configuration*/ + TString fUserCuts; //! /** Macro for geant cuts*/ + Bool_t fIsMT; //! /** MT mode option (Geant4 only)*/ + Bool_t fImportTGeoToVMC; //! /** Allow importing TGeometry to VMC */ + std::function fSimSetup; //! /** A user provided function to do sim setup / + //! instead of using macros **/ + bool fUseSimSetupFunction = false; + FairGenericVMCConfig* fSimulationConfig; //! /** Simulation configuration */ + + ClassDef(FairRunSim, 2); +}; + +#endif // FAIRRUNSIM_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairSink.h b/Detectors/3rdparty/FairRootBase/include/FairSink.h new file mode 100644 index 0000000000000..2df7ebff5cbbc --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairSink.h @@ -0,0 +1,98 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairSink ----- +// ----- Created 22.12.2017 by R. Karabowicz ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#ifndef FAIRSINK_H +#define FAIRSINK_H + +#include +#include +#include // map +#include // unique_ptr +#include // string +#include // type_info + +#include // rootcling needs the complete type for the dictionary + // (it used to arrive via the now-deleted FairFileSource) + +class TObject; +class TTree; + +enum Sink_Type +{ + kONLINESINK, + kFILESINK +}; + +class FairSink +{ + public: + FairSink(); + FairSink(const FairSink& sink); + virtual ~FairSink(); + + virtual Bool_t InitSink() = 0; + virtual void Close() = 0; + virtual void Reset() = 0; + + virtual Sink_Type GetSinkType() = 0; + virtual TString GetFileName() { return ""; } + + void SetRunId(Int_t runId) { fRunId = runId; } + Int_t GetRunId() const { return fRunId; } + + virtual void SetOutTree(TTree* fTree) = 0; + + virtual void Fill() = 0; + + virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) = 0; + + virtual void RegisterImpl(const char*, const char*, void*) = 0; + virtual void RegisterAny(const char* brname, const std::type_info& oi, const std::type_info& pi, void* obj) = 0; + + virtual void WriteFolder() = 0; + virtual bool CreatePersistentBranchesAny() = 0; + + virtual void WriteObject(TObject* f, const char*, Int_t option = 0) = 0; + virtual void WriteGeometry() = 0; + + virtual FairSink* CloneSink() = 0; + + protected: + struct TypeAddressPair + { + TypeAddressPair(const std::type_info& oi, const std::type_info& pi, void* a) + : origtypeinfo(oi) + , persistenttypeinfo(pi) + , ptraddr(a) + {} + const std::type_info& origtypeinfo; // type_info of type addr points to + const std::type_info& persistenttypeinfo; // type_info of ROOT persistent branch (drops pointers) + void* ptraddr; // address of a pointer (pointing to origtypeinfo); + }; + + Int_t fRunId; + + /**folder structure of output*/ + TFolder* fOutFolder; + /// A map of branchnames to typeinformation + memory address; + /// used for branches registered to bes stored; use of ptr here + /// since type_info cannot be copied + std::map> fPersistentBranchesMap; //! + + public: + ClassDef(FairSink, 1); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairSource.h b/Detectors/3rdparty/FairRootBase/include/FairSource.h new file mode 100644 index 0000000000000..fd50b08ba8592 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairSource.h @@ -0,0 +1,100 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairSource ----- +// ----- Created 01.11.2013 by F. Uhlig ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#ifndef FAIRSOURCE_H +#define FAIRSOURCE_H + +#include "FairLogger.h" +#include "TClass.h" + +#include +#include + +class FairEventHeader; + +enum Source_Type +{ + kONLINE, + kFILE +}; + +class FairSource : public TObject +{ + public: + FairSource(); + FairSource(const FairSource& source); + virtual ~FairSource(); + virtual Bool_t Init() = 0; + virtual Int_t ReadEvent(UInt_t = 0) = 0; + virtual Bool_t SpecifyRunId() = 0; + virtual void Close() = 0; + virtual void Reset() = 0; + virtual Bool_t ActivateObject(TObject**, const char*) { return kFALSE; } + virtual Bool_t ActivateObjectAny(void**, const std::type_info&, const char*) { return kFALSE; } + virtual Source_Type GetSourceType() = 0; + virtual void SetParUnpackers() = 0; + virtual Bool_t InitUnpackers() = 0; + virtual Bool_t ReInitUnpackers() = 0; + /**Check the maximum event number we can run to*/ + virtual Int_t CheckMaxEventNo(Int_t = 0) { return -1; } + /**Read the tree entry on one branch**/ + virtual void ReadBranchEvent(const char*) { return; } + virtual void ReadBranchEvent(const char*, Int_t) { return; } + virtual void FillEventHeader(FairEventHeader* feh); + void SetRunId(Int_t runId) { fRunId = runId; } + Int_t GetRunId() const { return fRunId; } + + protected: + Int_t fRunId; + + public: + ClassDef(FairSource, 2); +}; + +namespace { + +template +bool ActivateObjectAnyImpl(S* source, void** obj, const std::type_info& info, const char* brname) +{ + // we check if the types match at all + auto br = source->GetBranch(brname); + if (!br) { + // branch not found in source + return false; + } + + // look up the TClass and resulting typeid stored in this branch + auto cl = TClass::GetClass(br->GetClassName()); + if (!cl) { + // class not found + return false; + } + + auto storedtype = cl->GetTypeInfo(); + + // check consistency of types + if (info.hash_code() != storedtype->hash_code()) { + LOG(info) << "Trying to read from branch " << brname << " with wrong type " << info.name() + << " (expected: " << storedtype->name() << ")\n"; + return false; + } + source->SetBranchStatus(brname, 1); + // force to use the (void*) interface which is non-checking + source->SetBranchAddress(brname, (void*)obj); + return true; +} + +} // namespace + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairSystemInfo.h b/Detectors/3rdparty/FairRootBase/include/FairSystemInfo.h new file mode 100644 index 0000000000000..f0c590238a409 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairSystemInfo.h @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +/* + * FairSystemInfo.h + * + * Created on: Mai 18, 2015 + * Author: f.uhlig + */ + +#ifndef BASE_FAIRSYSTEMINFO_H_ +#define BASE_FAIRSYSTEMINFO_H_ + +#include +#include + +class FairSystemInfo +{ + public: + FairSystemInfo() {} + virtual ~FairSystemInfo() {} + + Float_t GetMaxMemory(); + size_t GetCurrentMemory(); + + ClassDef(FairSystemInfo, 1); +}; + +#endif // BASE_FAIRSYSTEMINFO_H_ diff --git a/Detectors/3rdparty/FairRootBase/include/FairTSBufferFunctional.h b/Detectors/3rdparty/FairRootBase/include/FairTSBufferFunctional.h new file mode 100644 index 0000000000000..e3e0327c98212 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairTSBufferFunctional.h @@ -0,0 +1,221 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FairTSBufferFunctionalFunctional_H_ +#define FairTSBufferFunctionalFunctional_H_ + +#include "FairTimeStamp.h" // for FairTimeStamp + +#include // for Int_t, Bool_t, Double_t, etc +#include // for TObject +#include // for TString +#include // for binary_function +#include // for operator<<, basic_ostream, etc + +class TBranch; +class TClonesArray; +class TTree; + +/** + * \class BinaryFunctor + * \brief Base class for all functors which are used in the FairTSBufferFunctional + * \see FairTSBufferFunctional + * + * The class is a base class to control which data is extracted by the FairTSBufferFunctional class for processing. + * The important method to overwrite is Call. It gets the actual data which is read in from the tree and a parameter. + * If the actual data is not anymore part of the data you want to have Call returns true to stop the reading of data. + * Otherwise it should return false. + * The method TimeOut is used to break the processing if for example always the same data is requested. + */ + +class BinaryFunctor +{ + public: + virtual bool operator()(FairTimeStamp* a, double b) { return Call(a, b); }; + virtual bool Call(FairTimeStamp* a, double b) = 0; + virtual bool TimeOut() { return false; } + virtual void ResetTimeOut(){}; + + virtual ~BinaryFunctor(){}; +}; + +/** + * \class StopTime + * Gives you all the data which is older than the given parameter StopTime. + * It does not return the data requested before. + */ + +class StopTime : public BinaryFunctor +{ + public: + StopTime() + : fRequestTime(-1) + , fOldTime(-1) + , fSameTimeRequestCounter(0){}; + + /** + * \parameter b: StopTime: All data older than StopTime is returned + */ + bool Call(FairTimeStamp* a, double b) + { + fRequestTime = b; + // std::cout << "StopTime: " << a->GetTimeStamp() << " > " << b << std::endl; + return a->GetTimeStamp() > b; + }; + + bool TimeOut() + { + if (fRequestTime != fOldTime) { + fOldTime = fRequestTime; + fSameTimeRequestCounter = 0; + // std::cout << "RequestedTime: " << fRequestTime << std::endl; + return false; + } else if (fRequestTime == fOldTime) { + std::cout << "-I- FairTSBufferFunctional StopTime has requested the same data as before: " << fRequestTime + << std::endl; + fSameTimeRequestCounter++; + } else { + std::cout << "-E- FairTSBufferFunctional StopTime Functor has requested time " << fRequestTime + << " smaller than old time " << fOldTime << std::endl; + return true; + } + if (fSameTimeRequestCounter > 9) { + return true; + } else { + return false; + } + } + + void ResetTimeOut() { fSameTimeRequestCounter = 0; } + + private: + double fRequestTime; + double fOldTime; + int fSameTimeRequestCounter; +}; + +/** + * \class TimeGap + * Returns you all the data between two time gaps of a given length. + */ + +class TimeGap : public BinaryFunctor +{ + public: + TimeGap() + : fOldTime(-1.){}; + + /** + * \parameter b : TimeGap: All data between two time gaps which are larger than TimeGap are returned + */ + bool Call(FairTimeStamp* a, double b) + { + double aTime = a->GetTimeStamp(); + + if (fOldTime < 0) { + fOldTime = aTime; + return false; + } + if (aTime - fOldTime > b) { + fOldTime = aTime; + return true; + } else { + fOldTime = aTime; + return false; + } + }; + + private: + double fOldTime; +}; + +/** + * \class FairTSBufferFunctional + * \brief A class to access time ordered data in a root branch + * + * In the constructor of the class one has to give the branch name of the data, the tree the data is stored in + * and a BinaryFunctor which contains the method how the data should be extracted. Several example functors already + * exists. To extract the data one has to call GetData with a parameter which fits to the selected functor. GetData + * returns a TClonesArray which contains the data. + * + * + * Be careful! The buffer runs through the time ordered data in one time direction only. This means that you cannot + * request data which is older than the data you have requested before. + * + * Addition: This is not true anymore. GetData(Double_t, Double_t) is able to get also data which is older but this only + * works if you request a fixed time via StopTime functor. For other functors the behavior is unpredictable. + * + * Created on: Feb 18, 201 + * Author: stockman + */ + +class FairTSBufferFunctional : public TObject +{ + public: + FairTSBufferFunctional(TString branchName, + TTree* sourceTree, + BinaryFunctor* stopFunction, + BinaryFunctor* startFunction = 0); + + virtual ~FairTSBufferFunctional(){}; + TClonesArray* GetData(Double_t stopParameter); + TClonesArray* GetData(Double_t startParameter, Double_t stopParameter); + Int_t GetBranchIndex() { return fBranchIndex; } + + void SetBranchIndex(const Int_t val) { fBranchIndex = val; } + void SetStartFunction(BinaryFunctor* function) { fStartFunction = function; } + void SetStopFunction(BinaryFunctor* function) { fStopFunction = function; } + Bool_t AllDataProcessed(); + void Terminate() { fTerminate = kTRUE; } + + Bool_t TimeOut() + { + Bool_t stopTimeOut = fStopFunction->TimeOut(); + Bool_t startTimeOut = kTRUE; + if (fStartFunction != 0) { + startTimeOut = fStartFunction->TimeOut(); + // if (startTimeOut == kTRUE && stopTimeOut == kFALSE){ + // fStartFunction->ResetTimeOut(); + // } + // else if (startTimeOut == kFALSE && stopTimeOut == kTRUE){ + // fStopFunction->ResetTimeOut(); + // } + } + return (stopTimeOut && startTimeOut); + } + + Int_t FindStartIndex(Double_t startParameter); + + private: + void ReadInNextFilledEntry(); + Int_t ReadInPreviousFilledEntry(Int_t startEntry); + void ReadInNextEntry(); //** used only if no function is given and input data is directly passed through to the + // OutputArray + void ReadInEntry(Int_t number); + void AbsorbDataBufferArray(); //< Absorbs the complete data from fInputArray to fBufferArray + + TClonesArray* fOutputArray; + TClonesArray* fBufferArray; + TClonesArray* fInputArray; + + BinaryFunctor* fStartFunction; + BinaryFunctor* fStopFunction; + + TBranch* fBranch; + Int_t fBranchIndex; + + Bool_t fTerminate; + + Int_t fVerbose; + + FairTSBufferFunctional(const FairTSBufferFunctional&); + FairTSBufferFunctional& operator=(const FairTSBufferFunctional&); + + ClassDef(FairTSBufferFunctional, 0); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairTask.h b/Detectors/3rdparty/FairRootBase/include/FairTask.h new file mode 100644 index 0000000000000..445affe3494bb --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairTask.h @@ -0,0 +1,151 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairTask header file ----- +// ----- Created 12/01/04 by M. Al-Turany / D. Bertini ----- +// ------------------------------------------------------------------------- + +/** FairTask + * @author M. Al-Turany, Denis Bertini + * @since 12.01.04 + ** + ** Base class for tasks in the cbmroot framework. + ** Derived classes should implement the Exec method. + **/ + +#ifndef FAIRTASK_H +#define FAIRTASK_H + +#include "FairRootManager.h" // for FairRootManager + +#include // for Int_t, FairTask::Class, etc +#include // for TString +#include // for TTask +#include + +class FairLogger; + +enum InitStatus +{ + kSUCCESS, + kERROR, + kFATAL +}; + +class FairTask : public TTask +{ + public: + /** Default constructor **/ + FairTask(); + + /** Standard constructor + *@param name Name of task + *@param iVerbose Verbosity level + **/ + FairTask(const char* name, Int_t iVerbose = 1); + + /** Destructor **/ + virtual ~FairTask(); + + /** Initialisation at begin of run. For this task and all of the subtasks. + Method used internally in FairRoot. **/ + void InitTask(); + + /** Reinitialisation. For this task and all of the subtasks. + Method used internally in FairRoot. **/ + void ReInitTask(); + + /** Set parameters. For this task and all of the subtasks. + Method used internally in FairRoot. **/ + void SetParTask(); + + /** Action at end of run. For this task and all of the subtasks. + Method used internally in FairRoot. **/ + virtual void FinishTask(); + + /** Action at end of event. For this task and all of the subtasks. **/ + virtual void FinishEvent(); + + /** Set verbosity level. For this task and all of the subtasks. **/ + void SetVerbose(Int_t iVerbose); + + void SetInputPersistance(Bool_t val) { fInputPersistance = val; } + + void CheckInputPersistance(TString branchName) + { + FairRootManager* ioman = FairRootManager::Instance(); + fInputPersistance = ioman->CheckBranch(branchName); + } + + virtual void ExecuteTask(Option_t* option = "0"); // *MENU* + + /** Set persistency of branch with given name true or false + * In case is is set to false the branch will not be written to the output. + **/ + void SetOutputBranchPersistent(TString, Bool_t); + + /** Check if the branch with the given name is persistent. + * If the branch is not in the map, the default return value is true. + **/ + Bool_t IsOutputBranchPersistent(TString); + + void SetStreamProcessing(Bool_t val = kTRUE) { fStreamProcessing = val; } + + protected: + Int_t fVerbose; // Verbosity level + Int_t fInputPersistance; ///< Indicates if input branch is persistant + FairLogger* fLogger; //! + Bool_t fStreamProcessing; + + /** Intialisation at begin of run. To be implemented in the derived class. + *@value Success If not kSUCCESS, task will be set inactive. + **/ + virtual InitStatus Init() { return kSUCCESS; }; + + /** Reinitialisation. To be implemented in the derived class. + *@value Success If not kSUCCESS, task will be set inactive. + **/ + virtual InitStatus ReInit() { return kSUCCESS; }; + + /** Intialise parameter containers. + To be implemented in the derived class. + **/ + virtual void SetParContainers(){}; + + /** Action at end of run. For this task and all of the subtasks. + To be implemented in the derived class. + **/ + virtual void Finish(){}; + + /** Recursive intialisation of subtasks at begin of run **/ + void InitTasks(); + + /** Recursive reinitialisation of subtasks **/ + void ReInitTasks(); + + virtual void ExecuteTasks(Option_t* option); + + /** Recursive parameter initialisation for subtasks **/ + void SetParTasks(); + + /** Recursive finish of subtasks **/ + void FinishTasks(); + + /** Recursive FinishEvent of subtasks **/ + void FinishEvents(); + + private: + std::map fOutputPersistance; + + FairTask(const FairTask&); + FairTask& operator=(const FairTask&); + + ClassDef(FairTask, 4); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairTimeStamp.h b/Detectors/3rdparty/FairRootBase/include/FairTimeStamp.h new file mode 100644 index 0000000000000..257d5ce5eae49 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairTimeStamp.h @@ -0,0 +1,127 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIRTIMESTAMP_H +#define FAIRTIMESTAMP_H + +#include "FairMultiLinkedData_Interface.h" // for FairMultiLinkedData + +#include // for Double_t, etc +#include // for ostream +#include // for ostream, cout + +namespace boost { +namespace serialization { +class access; +} +} // namespace boost +#include + +class TObject; + +/** + * Base class for Time stamp information + ** Aug. 2010 + **@author M.Al-Turany + */ +class FairTimeStamp : public FairMultiLinkedData_Interface +{ + public: + /** Default constructor **/ + FairTimeStamp(); + /** Constructor with time **/ + FairTimeStamp(Double_t time); + /** Constructor with time and time error **/ + FairTimeStamp(Double_t time, Double_t timeerror); + + /** Destructor **/ + virtual ~FairTimeStamp(){}; + /** Accessors **/ + Double_t GetTimeStamp() const { return fTimeStamp; } + Double_t GetTimeStampError() const { return fTimeStampError; } + /** Modifiers **/ + void SetTimeStamp(Double_t t) { fTimeStamp = t; } + void SetTimeStampError(Double_t t) { fTimeStampError = t; } + virtual Int_t Compare(const TObject* obj) const + { + if (this == obj) { + return 0; + } + FairTimeStamp* tsobj = static_cast(const_cast(obj)); + Double_t ts = tsobj->GetTimeStamp(); + Double_t tserror = tsobj->GetTimeStampError(); + if (fTimeStamp < ts) { + return -1; + } else if (fTimeStamp == ts && fTimeStampError < tserror) { + return -1; + } else if (fTimeStamp == ts && fTimeStampError == tserror) { + return 0; + } else { + return 1; + } + } + + virtual std::ostream& PrintTimeInfo(std::ostream& out = std::cout) const; + virtual Bool_t IsSortable() const { return kTRUE; }; + + virtual bool equal(FairTimeStamp* data) + { + return (fTimeStamp == data->GetTimeStamp() && fTimeStampError == data->GetTimeStampError()); + } + + friend std::ostream& operator<<(std::ostream& out, const FairTimeStamp& link) + { + link.PrintTimeInfo(out); + return out; + } + + virtual bool operator<(const FairTimeStamp* rValue) const + { + if (GetTimeStamp() < rValue->GetTimeStamp()) + return true; + else + return false; + } + + template + void serialize(Archive& ar, const unsigned int) + { + // ar & boost::serialization::base_object(*this); + ar& fTimeStamp; + ar& fTimeStampError; + } + + protected: + friend class boost::serialization::access; + + Double_t fTimeStamp; /** Time of digit or Hit [ns] */ + Double_t fTimeStampError; /** Error on time stamp */ + + ClassDef(FairTimeStamp, 4); +}; + +// ----- Default constructor ------------------------------------------- +inline FairTimeStamp::FairTimeStamp() + : FairMultiLinkedData_Interface() + , fTimeStamp(-1) + , fTimeStampError(-1) +{} + +// ----- Standard constructor ------------------------------------------ +inline FairTimeStamp::FairTimeStamp(Double_t time) + : FairMultiLinkedData_Interface() + , fTimeStamp(time) + , fTimeStampError(-1) +{} + +inline FairTimeStamp::FairTimeStamp(Double_t time, Double_t timeerror) + : FairMultiLinkedData_Interface() + , fTimeStamp(time) + , fTimeStampError(timeerror) +{} + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairTrajFilter.h b/Detectors/3rdparty/FairRootBase/include/FairTrajFilter.h new file mode 100644 index 0000000000000..ff158ca0dc54a --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairTrajFilter.h @@ -0,0 +1,282 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ********************************************* // +// *** D. Kresan 2004-Sep-14 *** // +// *** D.Kresan@gsi.de *** // +// ********************************************* // + +#ifndef FAIR_TRAJ_FILTER_H +#define FAIR_TRAJ_FILTER_H 1 + +#include // for Double_t, Bool_t, Int_t, etc +#include // IWYU pragma: keep needed by cint // TODO: is this still relevant for CINT? +#include // for multi-threading +#include // for Pi, TwoPi +#include // for TString + +class TClonesArray; +class TParticle; + +/** + * @class FairTrajFilter + * The filter for storing of the trajectories. + * This singleton class controls storing of trajectories + * in the gGeoManager list during the simulation. + * It is created, if FairRun::SetStoreTraj(kTRUE) was called + * in the run macro + * before the initialisation. The cuts should be applied + * after initialisation and before run via + * FairTrajFilter::Instance()->Set...Cut(...) methods. + * Three modes of momentum cut (phase space, polar and decart reference systems), + * are self-excluded. The last that was set, is applied in the simulation. + * All other cuts are combined together. + * @author D. Kresan + * @version 0.1 + * @since 2004-Sep-15 + */ + +class FairTrajFilter +{ + public: + /** + * Default constructor. + * Creates the singleton object of FairTrajFilter class. + * The pointer to this object can be reached via FairTrajFilter::Instance(). + */ + FairTrajFilter(); + + /** + * Destructor. + */ + virtual ~FairTrajFilter(); + + /** + * Class definition. + */ + ClassDef(FairTrajFilter, 1); + + private: + FairTrajFilter(const FairTrajFilter&); + FairTrajFilter& operator=(const FairTrajFilter&); + + static TMCThreadLocal FairTrajFilter* fgInstance; + + Double_t fVxMin; + Double_t fVxMax; + Double_t fVyMin; + Double_t fVyMax; + Double_t fVzMin; + Double_t fVzMax; + + Double_t fPMin; + Double_t fPMax; + Double_t fThetaMin; + Double_t fThetaMax; + Double_t fPhiMin; + Double_t fPhiMax; + + Double_t fPxMin; + Double_t fPxMax; + Double_t fPyMin; + Double_t fPyMax; + Double_t fPzMin; + Double_t fPzMax; + + Double_t fPtMin; + Double_t fPtMax; + Double_t fRapidityMin; + Double_t fRapidityMax; + + Int_t fKinCutType; + + Double_t fEtotMin; + Double_t fEtotMax; + + Bool_t fStorePrim; + Bool_t fStoreSec; + + Double_t fStepSizeMin; + + /** + * collection of tracks + */ + TClonesArray* fTrackCollection; + + TGeoTrack* fCurrentTrk; + + public: + TGeoTrack* AddTrack(Int_t trackId, Int_t pdgCode); + TGeoTrack* AddTrack(TParticle* p); + TGeoTrack* CheckAddTrack(Int_t trackId, TParticle* p); + TGeoTrack* GetCurrentTrk() { return fCurrentTrk; } + + void Init(TString brName = "GeoTracks", TString folderName = "MCGeoTrack"); + void Reset(); + /** + * This function is used to access the methods of the class. + * @return Pointer to the singleton FairTrajFilter object, created + * with FairTrajFilter::FairTrajFilter(). + */ + static FairTrajFilter* Instance(); + + /** + * This function applies all availible cuts on different variables. + * @param p - pointer to the TParticle object. + * @return kTRUE - if particle survives the cuts. Otherwise - kFALSE. + */ + Bool_t IsAccepted(const TParticle* p) const; + + /** + * This function enables the vertex cut. + * Three modes of momentum cut (phase space, polar and decart reference systems), + * are self-excluded. The last that was set, is applied in the simulation. + * @param Box in coordinate space. Only trajectories, created inside this box + * will be stored. Default values - the cave dimensions. + */ + void SetVertexCut(Double_t vxMin = -2000., + Double_t vyMin = -2000., + Double_t vzMin = -2000., + Double_t vxMax = 2000., + Double_t vyMax = 2000., + Double_t vzMax = 2000.); + + /** + * This function enables the momentum cut (polar reference system). + * Three modes of momentum cut (phase space, polar and decart reference systems), + * are self-excluded. The last that was set, is applied in the simulation. + * @param The region in momentum space (polar reference system). Only particles + * inside this region will be stored. + * Default values - whole momentum range. + */ + void SetMomentumCutP(Double_t pMin = 0., + Double_t thetaMin = 0., + Double_t phiMin = 0., + Double_t pMax = 1e10, + Double_t thetaMax = TMath::Pi(), + Double_t phiMax = TMath::TwoPi()); + + /** + * This function enables the momentum cut (decart reference system). + * Three modes of momentum cut (phase space, polar and decart reference systems), + * are self-excluded. The last that was set, is applied in the simulation. + * @param The region in momentum space (decart reference system). Only particles + * inside this region will be stored. + * Default values - whole momentum range. + */ + void SetMomentumCutD(Double_t pxMin = -1e10, + Double_t pyMin = -1e10, + Double_t pzMin = -1e10, + Double_t pxMax = 1e10, + Double_t pyMax = 1e10, + Double_t pzMax = 1e10); + + /** + * This function enables the cut in phase space (pt-rapidity). + * @param The region in phase space (pt-rapidity). Only particles + * inside this region will be stored. + * Default values - whole pt-rapidity range. + */ + void SetPtRapidityCut(Double_t ptMin = 0., + Double_t ptMax = 1e10, + Double_t rapidityMin = -1e10, + Double_t rapidityMax = 1e10); + + /** + * This function enables the cut on total energy. + * @param Total energy range. Only particles with total energy value + * inside this range will be stored. Deafult values - whole energy range. + */ + void SetEnergyCut(Double_t etotMin = 0., Double_t etotMax = 1e10); + + /** + * This function controls the storing of primaries. + * @param storePrim - boolean flag to control the storing of primaries. + */ + inline void SetStorePrimaries(Bool_t storePrim = kTRUE) { fStorePrim = storePrim; }; + + /** + * This function controls the storing of secondaries. + * @param storeSec - boolean flag to control the storing of secondaries. + */ + inline void SetStoreSecondaries(Bool_t storeSec = kTRUE) { fStoreSec = storeSec; }; + + /** + * This function controls the process of adding the points to the trajectory. + * @param stepSizeMin - minimum value of step size, wich will be added to + * the trajectory. + */ + void SetStepSizeCut(Double_t stepSizeMin = 0.); + + /** + * This is the getter for the vertex cut. + * @param References to the variables where return values should be stored. + */ + void GetVertexCut(Double_t& vxMin, + Double_t& vyMin, + Double_t& vzMin, + Double_t& vxMax, + Double_t& vyMax, + Double_t& vzMax) const; + + /** + * This is the getter for the momentum cut (polar reference system). + * @param References to the variables where return values should be stored. + */ + void GetMomentumCutP(Double_t& pMin, + Double_t& thetaMin, + Double_t& phiMin, + Double_t& pMax, + Double_t& thetaMax, + Double_t& phiMax) const; + + /** + * This is the getter for the momentum cut (decart reference system). + * @param References to the variables where return values should be stored. + */ + void GetMomentumCutD(Double_t& pxMin, + Double_t& pyMin, + Double_t& pzMin, + Double_t& pxMax, + Double_t& pyMax, + Double_t& pzMax) const; + + /** + * This is the getter for the space phase cut. + * @param References to the variables where return values should be stored. + */ + void GetPtRapidityCut(Double_t& ptMin, Double_t& ptMax, Double_t& rapidityMin, Double_t& rapidityMax) const; + + /** + * This is the getter for the total energy cut. + * @param References to the variables where return values should be stored. + */ + void GetEnergyCut(Double_t& etotMin, Double_t& etotMax) const; + + /** + * This is the getter for flag of storing of primaries. + * @return kTRUE if primaries should be stored. + */ + inline Bool_t IsPrimariesStored() const { return fStorePrim; }; + + /** + * This is the getter for flag of storing of secondaries. + * @return kTRUE if secondaries should be stored. + */ + inline Bool_t IsSecondariesStored() const { return fStoreSec; }; + + /** + * This is the getter for the step size cut. + * @return The minimum value of the step size wich still should be + * added to the trajectory. + */ + inline Double_t GetStepSizeCut() const { return fStepSizeMin; }; + + TGeoTrack* GetTrack(Int_t trackId); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairVolume.h b/Detectors/3rdparty/FairRootBase/include/FairVolume.h new file mode 100644 index 0000000000000..0dab826c62478 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairVolume.h @@ -0,0 +1,83 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIR_VOLUME_H +#define FAIR_VOLUME_H + +#include "FairDetector.h" +#include "FairModule.h" + +#include // for Int_t, FairVolume::Class, etc +#include // for TNamed +#include // for TString +class FairGeoNode; + +/** + * This Object is only used for internal book keeping! + * @author M. Al-Turany, D. Bertini + * @version 0.1 + * @since 12.01.04 + */ + +class FairVolume : public TNamed +{ + public: + FairVolume(); + FairVolume(TString name, Int_t id = 0, Int_t detid = 0, FairModule* fMod = 0); + virtual ~FairVolume(); + + // const char* GetName() { return fName.Data();} + // TString getName() { return fName;} + + void setRealName(TString name) { fRealName = name; } + const char* getRealName() { return fRealName.Data(); } + Int_t getVolumeId() { return fVolumeId; } + Int_t getModId() { return fModId; } + void setModId(Int_t id) { fModId = id; } + void setCopyNo(Int_t id) { fCopyNo = id; } + void setVolumeId(Int_t id) { fVolumeId = id; } + void setGeoNode(FairGeoNode* d) { fNode = d; } + void setMotherId(Int_t fM) { fMotherId = fM; } + void setMotherCopyNo(Int_t CopyNo) { fMotherCopyNo = CopyNo; } + + FairModule* GetModule() { return fModule; } + FairDetector* GetDetector() { return fDetector; } + void SetModule(FairModule* mod) + { + fModule = mod; + if (mod->InheritsFrom("FairDetector")) { + fDetector = dynamic_cast(mod); + } + } + + Int_t getMCid() { return fMCid; } + Int_t getCopyNo() { return fCopyNo; } + void setMCid(Int_t id) { fMCid = id; } + FairGeoNode* getGeoNode() { return fNode; } + Int_t getMotherId() { return fMotherId; } + Int_t getMotherCopyNo() { return fMotherCopyNo; } + + private: + FairVolume(const FairVolume&); + FairVolume& operator=(const FairVolume&); + + // TString fName; /**Volume Name in MC*/ + TString fRealName; /**Volume Name in ASCII file*/ + Int_t fVolumeId; /**Volume Id in GeoManager*/ + Int_t fModId; /**Module Id in which this volume exist*/ + Int_t fMCid; /**Volume Id in MC*/ + Int_t fCopyNo; /**Volume Copy No*/ + Int_t fMotherId; /**Mother Volume Id*/ + Int_t fMotherCopyNo; /**Mother Volume Copy No*/ + FairDetector* fDetector; /** The Detector which will proccess the hits for this volume*/ + FairModule* fModule; /**The Module in which the volume is */ + FairGeoNode* fNode; /**Node corresponding to this volume*/ + + ClassDef(FairVolume, 2); +}; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/include/FairVolumeList.h b/Detectors/3rdparty/FairRootBase/include/FairVolumeList.h new file mode 100644 index 0000000000000..342c04865b631 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairVolumeList.h @@ -0,0 +1,50 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#ifndef FAIR_VOLUMELIST_H +#define FAIR_VOLUMELIST_H + +#include "FairVolume.h" + +#include // for Int_t, etc +#include // for TObjArray +#include // for TObject +#include // for TString + +// class FairVolume; + +/** + * This Object is only used for internal book keeping! + * @author M. Al-Turany, D. Bertini + * @version 0.1 + * @since 12.01.04 + */ + +class FairVolumeList : public TObject +{ + private: + TObjArray* fData; + FairVolumeList(const FairVolumeList&); + FairVolumeList& operator=(const FairVolumeList&); + + public: + FairVolumeList(); + virtual ~FairVolumeList(); + + FairVolume* getVolume(TString* name); + Int_t getVolumeId(TString* name); + + FairVolume* findObject(TString name); + void addVolume(FairVolume* elem); + + Int_t getEntries() { return fData->GetEntries(); } + FairVolume* At(Int_t pos) { return (dynamic_cast(fData->At(pos))); } + + ClassDef(FairVolumeList, 1); +}; + +#endif // FAIR_VOLUMELIST_H diff --git a/Detectors/3rdparty/FairRootBase/include/FairWriteoutBuffer.h b/Detectors/3rdparty/FairRootBase/include/FairWriteoutBuffer.h new file mode 100644 index 0000000000000..bdb74ff018cfa --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/include/FairWriteoutBuffer.h @@ -0,0 +1,149 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/** + * @class FairWriteoutBuffer + * + * @author Tobias Stockmanns + * @brief A container class to store digi data during events + * + * The FairWriteoutBuffer class provides a container which handles the storage of data between + * events. The data has to be given with an active time, the absolute time the data is active in the + * detector and can influence the output of the data. + * FillNewData is used to put new data into the container. + * WriteOutData with a given actual time stores the data which has an active time older than the given time + * in the corresponding TClonesArray of the FairRootManager. + * At the end of the task WriteOutAllData has to be called to store the data which is still in the buffer. + * If one adds data via FillNewData into the buffer which is already present in the buffer, Modify is called. + * The standard behavior of Modify is that the new data is ignored to simulate pile-up. If a different behavior + * is wanted one has to overwrite Modify in a derived class. + * + * The data which should be stored in the buffer has to be derived from FairTimeStamp. + * It needs an operator< and a method equal if the same detector element is hit. + * + * To use this buffer one has to derive his own buffer class from FairWriteoutBuffer and overwrite the pure virtual + * functions. + */ + +#ifndef FairWriteoutBuffer_H_ +#define FairWriteoutBuffer_H_ + +#include "FairLogger.h" // for FairLogger +#include "FairRootManager.h" // for FairRootManager +#include "FairTimeStamp.h" // for FairTimeStamp + +#include // for Bool_t, Int_t, etc +#include // for TClonesArray +#include // for TObject +#include // for TString +#include // for cout, ostream +#include // for multimap +#include // for pair +#include // for vector + +class FairWriteoutBuffer : public TObject +{ + public: + FairWriteoutBuffer() + : TObject() + , fStartTime_map() + , fDeadTime_map() + , fBranchName() + , fClassName() + , fTreeSave(false) + , fActivateBuffering(kFALSE) + , fVerbose(0) + , fLogger(FairLogger::GetLogger()){}; + FairWriteoutBuffer(TString branchName, TString className, TString folderName, Bool_t persistance); + virtual ~FairWriteoutBuffer(){}; + + virtual void SaveDataToTree(Bool_t val = kTRUE) + { + fTreeSave = val; ///< If SaveDataToTree is set the data is stored at the end of the buffering into the given + ///< TClonesArray. + } + virtual void ActivateBuffering(Bool_t val = kTRUE) + { + fActivateBuffering = val; ///< fActivateBuffering has to be set to kTRUE to use the buffering. Otherwise the + ///< data is directly stored in the given TClonesArray. + } + + Bool_t IsBufferingActivated() { return fActivateBuffering; } + + /// Fills a pointer to a data object into the buffer. StartTime gives the time when the data can influence later + /// data, activeTime gives the time how long the data can influence later data. Both time data has to be given as an + /// absolute time! + virtual void FillNewData(FairTimeStamp* data, double startTime, double activeTime); + + virtual Int_t GetNData() { return fDeadTime_map.size(); } + virtual std::vector GetRemoveOldData(double time); + virtual std::vector GetAllData(); + + virtual void SetVerbose(Int_t val) { fVerbose = val; } + + virtual void DeleteOldData() + { + if (fBranchName.Length() > 0) { + TClonesArray* myArray = FairRootManager::Instance()->GetTClonesArray(fBranchName); + myArray->Delete(); + } + } + + virtual void WriteOutData(double time); + virtual void WriteOutAllData(); + + protected: + virtual void AddNewDataToTClonesArray( + FairTimeStamp* data) = 0; ///< store the data from the FairTimeStamp pointer in a TClonesArray (you have to + ///< cast it to your type of data) + virtual double FindTimeForData( + FairTimeStamp* data) = 0; ///< if the same data object (like a pad or a pixel) is already present in the + ///< buffer, the time of this object has to be returned otherwise -1 + virtual void FillDataMap(FairTimeStamp* data, double activeTime) = 0; ///< add a new element in the search buffer + virtual void EraseDataFromDataMap( + FairTimeStamp* data) = 0; ///< delete the element from the search buffer (see PndSdsDigiPixelWriteoutBuffer) + + /// Modify defines the behavior of the buffer if data should be stored which is already in the buffer. Parameters + /// are the old data with the active time, the new data with an active time. Modify returns than a vector with the + /// new data which should be stored. + virtual std::vector> Modify(std::pair oldData, + std::pair) + { + std::vector> result; + result.push_back(oldData); + return result; + } + + virtual void WriteOutDataDeadTimeMap(double time); + virtual void MoveDataFromStartTimeMapToDeadTimeMap(double time); + virtual void FillDataToDeadTimeMap(FairTimeStamp* data, double activeTime, double startTime); + + virtual void PrintData(FairTimeStamp* data) + { + std::cout << data->GetTimeStamp(); + }; ///< Method should be overwritten in derived classes to print the data of an object stored in the buffer + virtual void PrintDeadTimeMap(); + virtual void PrintStartTimeMap(); + + std::multimap> fStartTime_map; + std::multimap fDeadTime_map; + + TString fBranchName; + TString fClassName; + Bool_t fTreeSave; + Bool_t fActivateBuffering; + Int_t fVerbose; + FairLogger* fLogger; //! /// FairLogger + + private: + FairWriteoutBuffer(const FairWriteoutBuffer&); + FairWriteoutBuffer& operator=(const FairWriteoutBuffer&); + + ClassDef(FairWriteoutBuffer, 1); +}; + +#endif /* FairWriteoutBuffer_H_ */ diff --git a/Detectors/3rdparty/FairRootBase/src/FairAlignmentHandler.cxx b/Detectors/3rdparty/FairRootBase/src/FairAlignmentHandler.cxx new file mode 100644 index 0000000000000..5e8bf25403561 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairAlignmentHandler.cxx @@ -0,0 +1,95 @@ +#include "FairAlignmentHandler.h" + +#include "FairLogger.h" + +#include +#include + +FairAlignmentHandler::FairAlignmentHandler() {} + +FairAlignmentHandler::~FairAlignmentHandler() {} + +void FairAlignmentHandler::AlignGeometry() const +{ + if (fAlignmentMatrices.size() > 0) { + LOG(info) << "aligning the geometry..."; + + LOG(info) << "aligning in total " << fAlignmentMatrices.size() << " volumes."; + if (gGeoManager->GetNAlignable() > 0) { + AlignGeometryBySymlink(); + } else { + AlignGeometryByFullPath(); + } + + LOG(info) << "alignment finished!"; + } +} + +void FairAlignmentHandler::AlignGeometryByFullPath() const +{ + TString volume_path; + + LOG(info) << "aligning using full path."; + for (auto const& alignment_entry : fAlignmentMatrices) { + volume_path = alignment_entry.first; + + gGeoManager->cd(volume_path); + + TGeoNode* volume_node = gGeoManager->GetCurrentNode(); + TGeoMatrix* volume_matrix = volume_node->GetMatrix(); + // Need to do this as since ROOT 6.14 TGeoMatrix has no multiplication operator anymore + // it is implimnted now in TGeoHMatrix + + TGeoHMatrix local_volume_matrix = TGeoHMatrix(*volume_matrix); + + TGeoHMatrix* new_volume_matrix = new TGeoHMatrix(local_volume_matrix * alignment_entry.second); + // new matrix, representing real position (from new local mis RS to the global one) + + TGeoPhysicalNode* pn = gGeoManager->MakePhysicalNode(volume_path); + + pn->Align(new_volume_matrix); + } + LOG(info) << "alignments applied!"; +} + +void FairAlignmentHandler::AlignGeometryBySymlink() const +{ + TString volume_path; + + LOG(info) << "aligning using symlinks"; + for (auto const& alignment_entry : fAlignmentMatrices) { + volume_path = alignment_entry.first; + + TGeoPhysicalNode* node = NULL; + TGeoPNEntry* entry = gGeoManager->GetAlignableEntry(volume_path); + if (entry) { + node = gGeoManager->MakeAlignablePN(entry); + } + + TGeoMatrix* volume_matrix = NULL; + if (node) { + volume_matrix = node->GetMatrix(); + } else { + continue; + } + // Need to do this as since ROOT 6.14 TGeoMatrix has no multiplication operator anymore + // it is implimnted now in TGeoHMatrix + TGeoHMatrix local_volume_matrix = TGeoHMatrix(*volume_matrix); + + TGeoHMatrix* new_volume_matrix = new TGeoHMatrix(local_volume_matrix * alignment_entry.second); + // new matrix, representing real position (from new local mis RS to the global one) + node->Align(new_volume_matrix); + } +} + +void FairAlignmentHandler::AddAlignmentMatrices(const std::map& alignmentMatrices, + bool invertMatrices) +{ + LOG(info) << "adding inverting matrices..."; + for (auto const& m : alignmentMatrices) { + if (invertMatrices) + fAlignmentMatrices[m.first] *= m.second.Inverse(); + else + fAlignmentMatrices[m.first] *= m.second; + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairBaseMCGenerator.cxx b/Detectors/3rdparty/FairRootBase/src/FairBaseMCGenerator.cxx new file mode 100644 index 0000000000000..af120aae202de --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairBaseMCGenerator.cxx @@ -0,0 +1,104 @@ +/* + * FairSimpleMCGenerator.cxx + * + * Created on: 16 mar 2020 + * Author: Daniel Wielanek + * E-mail: daniel.wielanek@gmail.com + * Warsaw University of Technology, Faculty of Physics + */ +#include "FairBaseMCGenerator.h" + +#include "FairLogger.h" + +#include +#include +#include + +FairBaseMCGenerator::FairBaseMCGenerator() + : FairGenerator() + , fX(0) + , fY(0) + , fZ(0) + , fPDGType(0) + , fMult(0) + , fVertexSmear(kBox) + , fPDGMass(0.0) + , fVx(0.0) + , fVy(0.0) + , fVz(0.0) + , fVex(0.0) + , fVey(0.0) + , fVez(0.0) +{} + +void FairBaseMCGenerator::SetVertex(Double_t vx, + Double_t vy, + Double_t vz, + Double_t evx, + Double_t evy, + Double_t evz, + eVertexSmear VertexSmear) +{ + fX = fVx = vx; + fY = fVy = vy; + fZ = fVz = vz; + fVex = evx; + fVey = evy; + fVez = evz; + fVertexSmear = VertexSmear; +} + +FairBaseMCGenerator::~FairBaseMCGenerator() +{ + // TODO Auto-generated destructor stub +} + +Bool_t FairBaseMCGenerator::Init() +{ + if (fMult <= 0) + return kFALSE; + TDatabasePDG *pid = TDatabasePDG::Instance(); + TParticlePDG *p = pid->GetParticle(fPDGType); + if (p != nullptr) { + LOG(info) << this->ClassName() << ": particle with PDG =" << GetPDGType() << " Found"; + fPDGMass = p->Mass(); + } + return kTRUE; +} + +void FairBaseMCGenerator::SetPDGType(Int_t pdg) { fPDGType = pdg; } + +void FairBaseMCGenerator::GenerateEventParameters() +{ + switch (fVertexSmear) { + case kGauss: { + fX = gRandom->Gaus(fVx, fVex); + fY = gRandom->Gaus(fVy, fVey); + fZ = gRandom->Gaus(fVz, fVez); + } break; + case kBox: { + fX = gRandom->Uniform(fVx - fVex, fVx + fVex); + fY = gRandom->Uniform(fVy - fVey, fVy + fVey); + fZ = gRandom->Uniform(fVz - fVez, fVz + fVez); + } break; + case kExp: { + if (gRandom->Uniform() < 0.5) { + fX = fVx + gRandom->Exp(fVex); + } else { + fX = fVx - gRandom->Exp(fVex); + } + if (gRandom->Uniform() < 0.5) { + fY = fVy + gRandom->Exp(fVey); + } else { + fY = fVy - gRandom->Exp(fVey); + } + if (gRandom->Uniform() < 0.5) { + fZ = fVz + gRandom->Exp(fVez); + } else { + fZ = fVz - gRandom->Exp(fVez); + } + } break; + } + LOG(info) << this->ClassName() << ": Event, vertex = (" << fX << "," << fY << "," << fZ << ") cm, multiplicity " + << fMult; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairBoxGenerator.cxx b/Detectors/3rdparty/FairRootBase/src/FairBoxGenerator.cxx new file mode 100644 index 0000000000000..25d4f6b452557 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairBoxGenerator.cxx @@ -0,0 +1,214 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairBoxGenerator source file ----- +// ----- Created 09/09/04 by Yu.Kharlov +// ------------------------------------------------------------------------- + +/* $Id: FairBoxGenerator.cxx,v 1.4 2006/07/18 09:28:06 prokudin Exp $ */ + +/* History of cvs commits: + * + * $Log: FairBoxGenerator.cxx,v $ + * Revision 1.4 2006/07/18 09:28:06 prokudin + * Should be * instead / + * + * Revision 1.3 2006/07/14 11:23:57 kharlov + * Add protection for simultaneously set ranges; split vertex and kinematics ranges + * + * Revision 1.2 2006/03/29 16:25:50 kharlov + * New functionality added + * + */ + +#include "FairBoxGenerator.h" + +#include "FairLogger.h" +#include "FairPrimaryGenerator.h" + +#include +#include +#include +#include +#include +#include // for cos, acos +#include // for printf + +FairBoxGenerator::FairBoxGenerator() + : FairBaseMCGenerator() + , fPtMin(0) + , fPtMax(0) + , fPhiMin(0) + , fPhiMax(0) + , fEtaMin(0) + , fEtaMax(0) + , fYMin(0) + , fYMax(0) + , fPMin(0) + , fPMax(0) + , fThetaMin(0) + , fThetaMax(0) + , fEkinMin(0) + , fEkinMax(0) + , fEtaRangeIsSet(0) + , fYRangeIsSet(0) + , fThetaRangeIsSet(0) + , fCosThetaIsSet(0) + , fPtRangeIsSet(0) + , fPRangeIsSet(0) + , fEkinRangeIsSet(0) +{ + // Default constructor +} + +FairBoxGenerator::FairBoxGenerator(Int_t pdgid, Int_t mult) + : FairBaseMCGenerator() + , fPtMin(0) + , fPtMax(0) + , fPhiMin(0) + , fPhiMax(0) + , fEtaMin(0) + , fEtaMax(0) + , fYMin(0) + , fYMax(0) + , fPMin(0) + , fPMax(0) + , fThetaMin(0) + , fThetaMax(0) + , fEkinMin(0) + , fEkinMax(0) + , fEtaRangeIsSet(0) + , fYRangeIsSet(0) + , fThetaRangeIsSet(0) + , fCosThetaIsSet(0) + , fPtRangeIsSet(0) + , fPRangeIsSet(0) + , fEkinRangeIsSet(0) +{ + // Constructor. Set default kinematics limits + SetPDGType(pdgid); + SetMultiplicity(mult); + SetPhiRange(); +} + +void FairBoxGenerator::SetXYZ(Double32_t x, Double32_t y, Double32_t z) { SetVertex(x, y, z, 0, 0, 0, kBox); } + +void FairBoxGenerator::SetBoxXYZ(Double32_t x1, Double32_t y1, Double32_t x2, Double32_t y2, Double32_t z) +{ + Double_t X1 = TMath::Min(x1, x2); + Double_t X2 = TMath::Max(x1, x2); + Double_t Y1 = TMath::Min(y1, y2); + Double_t Y2 = TMath::Max(y1, y2); + Double_t dX = 0.5 * (X2 - X1); + Double_t dY = 0.5 * (Y2 - Y1); + Double_t x = 0.5 * (X1 + X2); + Double_t y = 0.5 * (Y1 + Y2); + SetVertex(x, y, z, dX, dY, 0, kBox); +} + +Bool_t FairBoxGenerator::Init() +{ + // Initialize parent generator + if (FairBaseMCGenerator::Init() == kFALSE) + return kFALSE; + // Check for particle type + TDatabasePDG* pdgBase = TDatabasePDG::Instance(); + TParticlePDG* particle = pdgBase->GetParticle(GetPDGType()); + + if (!particle) { + LOG(fatal) << "FairBoxGenerator: PDG " << GetPDGType() << " not defined"; + } + + if (fPhiMax - fPhiMin > 360) { + LOG(fatal) << "FairBoxGenerator:Init(): phi range is too wide: " << fPhiMin << "Uniform(fPhiMin, fPhiMax) * TMath::DegToRad(); + + if (fPRangeIsSet) { + pabs = gRandom->Uniform(fPMin, fPMax); + } else if (fPtRangeIsSet) { + pt = gRandom->Uniform(fPtMin, fPtMax); + } + + if (fThetaRangeIsSet) { + if (fCosThetaIsSet) + theta = acos(gRandom->Uniform(cos(fThetaMin * TMath::DegToRad()), cos(fThetaMax * TMath::DegToRad()))); + else { + theta = gRandom->Uniform(fThetaMin, fThetaMax) * TMath::DegToRad(); + } + } else if (fEtaRangeIsSet) { + eta = gRandom->Uniform(fEtaMin, fEtaMax); + theta = 2 * TMath::ATan(TMath::Exp(-eta)); + } else if (fYRangeIsSet) { + y = gRandom->Uniform(fYMin, fYMax); + mt = TMath::Sqrt(GetPDGMass() * GetPDGMass() + pt * pt); + pz = mt * TMath::SinH(y); + } + + if (fThetaRangeIsSet || fEtaRangeIsSet) { + if (fPRangeIsSet) { + pz = pabs * TMath::Cos(theta); + pt = pabs * TMath::Sin(theta); + } else if (fPtRangeIsSet) { + pz = pt / TMath::Tan(theta); + } + } + + px = pt * TMath::Cos(phi); + py = pt * TMath::Sin(phi); + + LOG(debug) << "FairBoxGen: " << Form("PDG %i p=(%.2f, %.2f, %.2f) GeV,", GetPDGType(), px, py, pz); + primGen->AddTrack(GetPDGType(), px, py, pz, fX, fY, fZ); + } + return kTRUE; +} + +FairGenerator* FairBoxGenerator::CloneGenerator() const +{ + // Clone for worker (used in MT mode only) + + return new FairBoxGenerator(*this); +} + +ClassImp(FairBoxGenerator); diff --git a/Detectors/3rdparty/FairRootBase/src/FairDetector.cxx b/Detectors/3rdparty/FairRootBase/src/FairDetector.cxx new file mode 100644 index 0000000000000..71542f29ace5e --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairDetector.cxx @@ -0,0 +1,144 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairDetector source file ----- +// ----- Created 06/01/04 by M. Al-Turany/ D. Bertini ----- +// ------------------------------------------------------------------------- + +#include "FairDetector.h" + +#include "FairGeoNode.h" // for FairGeoNode +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairModule.h" // for FairModule::svList, etc +#include "FairRootManager.h" +#include "FairVolume.h" // for FairVolume + +#include // for TFolder +#include // for gGeoManager +#include // for TList +#include // for TObject +#include // for TROOT, gROOT +#include // for TRefArray +#include // for TString +#include // for TVirtualMC + +FairDetector::FairDetector(const char* Name, Bool_t Active, Int_t DetId) + : FairModule(Name, "FAIR Detector", Active) + , fDetId(DetId) + , fLogger(FairLogger::GetLogger()) +{ + flGeoPar = new TList(); + TString lname(GetName()); + lname += "GeoPar"; + flGeoPar->SetName(lname.Data()); + fGeoSaved = kFALSE; +} + +FairDetector::FairDetector(const FairDetector& rhs) + : FairModule(rhs) + , fDetId(rhs.fDetId) + , fLogger(rhs.fLogger) +{} + +FairDetector::~FairDetector() { delete flGeoPar; } + +FairDetector& FairDetector::operator=(const FairDetector& rhs) +{ + // check assignment to self + if (this == &rhs) + return *this; + + // base class assignment + FairModule::operator=(rhs); + + // assignment operator + fDetId = rhs.fDetId; + fLogger = rhs.fLogger; + + return *this; +} + +FairDetector::FairDetector() + : fDetId(0) + , fLogger(FairLogger::GetLogger()) +{} + +// ------------------------------------------------------------------------- + +void FairDetector::DefineSensitiveVolumes() +{ + LOG(info) << "FairDetector::DefineSensitiveVolumes"; + TObjArray* volumes = gGeoManager->GetListOfVolumes(); + TIter next(volumes); + TGeoVolume* volume; + while ((volume = static_cast(next()))) { + if (IsSensitive(volume->GetName())) { + LOG(debug) << "Sensitive Volume " << volume->GetName(); + AddSensitiveVolume(volume); + } + } +} + +// ------------------------------------------------------------------------- + +void FairDetector::Initialize() +{ + // Registers hits collection in Root manager; + // sets sensitive volumes. + // --- + + // Define sensitive volumes if in MT + if (gMC->IsMT()) { + std::cout << "Define sensitive volume " << std::endl; + DefineSensitiveVolumes(); + } + + Int_t NoOfEntries = svList->GetEntries(); + Int_t fMCid; + FairGeoNode* fN; + TString cutName; + TString copysign = "#"; + for (Int_t i = 0; i < NoOfEntries; i++) { + FairVolume* aVol = static_cast(svList->At(i)); + cutName = aVol->GetName(); + Ssiz_t pos = cutName.Index(copysign, 1); + if (pos > 1) { + cutName.Resize(pos); + } + if (aVol->getModId() == GetModId()) { + fMCid = TVirtualMC::GetMC()->VolId(cutName.Data()); + aVol->setMCid(fMCid); + fN = aVol->getGeoNode(); + if (fN) { + fN->setMCid(fMCid); + } + } + } + + // Initialize cached pointer to MC (on master in sequential mode) + fMC = TVirtualMC::GetMC(); +} + +void FairDetector::SaveGeoParams() +{ + if (!fGeoSaved) { + LOG(info) << "Detector: " << GetName() << " Geometry parameters saved ... "; + TFolder* mf = dynamic_cast(gROOT->FindObjectAny(FairRootManager::GetFolderName())); + TFolder* stsf = nullptr; + if (mf) { + stsf = dynamic_cast(mf->FindObjectAny(GetName())); + } + if (stsf) { + TFolder* newf = stsf->AddFolder("Parameters", "Detector parameters", nullptr); + newf->Add(flGeoPar); + } + fGeoSaved = kTRUE; + } +} + +ClassImp(FairDetector); diff --git a/Detectors/3rdparty/FairRootBase/src/FairEventHeader.cxx b/Detectors/3rdparty/FairRootBase/src/FairEventHeader.cxx new file mode 100644 index 0000000000000..8692197eac223 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairEventHeader.cxx @@ -0,0 +1,31 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairEventHeader source file ----- +// ----- Created 08/09/04 D. Bertini ----- +// ------------------------------------------------------------------------- + +#include "FairEventHeader.h" + +#include "FairRootManager.h" + +FairEventHeader::FairEventHeader() + : fRunId(0) + , fEventTime(-1.) + , fInputFileId(0) + , fMCEntryNo(0) +{} + +FairEventHeader::~FairEventHeader() {} + +void FairEventHeader::Register(Bool_t Persistence) +{ + FairRootManager::Instance()->Register("EventHeader.", "EvtHeader", this, Persistence); +} + +ClassImp(FairEventHeader); diff --git a/Detectors/3rdparty/FairRootBase/src/FairField.cxx b/Detectors/3rdparty/FairRootBase/src/FairField.cxx new file mode 100644 index 0000000000000..97a05250f51a9 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairField.cxx @@ -0,0 +1,51 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairField source file ----- +// ----- Created 06/01/04 by M. Al/Turany ----- +// ----- Redesign 13/02/06 by V. Friese ----- +// ------------------------------------------------------------------------- + +#include "FairField.h" + +FairField::FairField() + : TVirtualMagField("FAIR Magnetic Field") + , fType(0) +{} + +FairField::FairField(const char* name, const char*) + : TVirtualMagField(name) + , fType(0) +{} + +FairField::~FairField() {} + +Bool_t FairField::IsConst() +{ + if (fType == 1) { + return kTRUE; + } + return kFALSE; +} + +Bool_t FairField::IsMap() +{ + if (fType == 2) { + return kTRUE; + } + return kFALSE; +} + +void FairField::GetFieldValue(const Double_t point[3], Double_t* bField) +{ + bField[0] = GetBx(point[0], point[1], point[2]); + bField[1] = GetBy(point[0], point[1], point[2]); + bField[2] = GetBz(point[0], point[1], point[2]); +} + +ClassImp(FairField); diff --git a/Detectors/3rdparty/FairRootBase/src/FairFileHeader.cxx b/Detectors/3rdparty/FairRootBase/src/FairFileHeader.cxx new file mode 100644 index 0000000000000..8f5a88a47fede --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairFileHeader.cxx @@ -0,0 +1,55 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairFileHeader source file ----- +// ----- Created 20/04/11 M.Al-Turany ----- +// ------------------------------------------------------------------------- + +#include "FairFileHeader.h" + +#include "FairFileInfo.h" // for FairFileInfo + +#include // for TIterator +#include // for TList +#include // for TObjString +#include // for TObject +class TFile; + +FairFileHeader::FairFileHeader() + : TNamed() + , fRunId(0) + , fTaskList(new TList()) + , fFileList(new TList()) +{} + +void FairFileHeader::AddTaskClassName(TString taskname) { fTaskList->AddLast(new TObjString(taskname)); } + +void FairFileHeader::AddInputFile(TFile* f, UInt_t id, UInt_t ChId) +{ + fFileList->AddLast(new FairFileInfo(f, id, ChId)); +} + +FairFileInfo* FairFileHeader::GetFileInfo(UInt_t id, UInt_t ChId) +{ + TIterator* Iter = fFileList->MakeIterator(); + Iter->Reset(); + TObject* obj = 0; + FairFileInfo* info = 0; + while ((obj = Iter->Next())) { + info = dynamic_cast(obj); + if (info && info->GetIdentifier() == id && info->GetOrderInChain() == ChId) { + return info; + } + } + delete Iter; + return 0; +} + +FairFileHeader::~FairFileHeader() {} + +ClassImp(FairFileHeader); diff --git a/Detectors/3rdparty/FairRootBase/src/FairFileInfo.cxx b/Detectors/3rdparty/FairRootBase/src/FairFileInfo.cxx new file mode 100644 index 0000000000000..ed1e0605da45c --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairFileInfo.cxx @@ -0,0 +1,48 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// FairFileInfo.cxx +// Created by Mohammad Al-Turany on 6/21/11. +// +#include "FairFileInfo.h" + +#include // for TFile +#include // for TSystem, gSystem +#include // for printf + +//__________________________________________________________________________ +FairFileInfo::FairFileInfo() + : TNamed() + , fPath("") + , fSize(0) + , fIdentifier(0) + , fInChainId(0) +{} +//__________________________________________________________________________ +FairFileInfo::FairFileInfo(TFile* file, UInt_t id, UInt_t ChId) + : TNamed(file->GetName(), "Inputfile") + , fPath("") + , fSize(file->GetSize()) + , fIdentifier(id) + , fInChainId(ChId) +{ + fPath += gSystem->WorkingDirectory(); + fPath += fName; +} +//__________________________________________________________________________ +FairFileInfo::~FairFileInfo() {} +//__________________________________________________________________________ +void FairFileInfo::Print(Option_t*) const +{ + printf("Printing FairFileInfo for : %s \n", fName.Data()); + printf("File full path : %s \n", fPath.Data()); + printf("File Size in Byte : %i \n", fSize); + printf("File Identifier : %i \n", fIdentifier); + printf("File order in input chain : %i \n", fInChainId); +} +//__________________________________________________________________________ +ClassImp(FairFileInfo); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGenerator.cxx b/Detectors/3rdparty/FairRootBase/src/FairGenerator.cxx new file mode 100644 index 0000000000000..046fdf97f33fa --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGenerator.cxx @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairGenerator source file ----- +// ------------------------------------------------------------------------- + +#include "FairGenerator.h" + +FairGenerator::FairGenerator() + : TNamed() +{} + +FairGenerator::FairGenerator(const char* name, const char* title) + : TNamed(name, title) +{} + +FairGenerator::FairGenerator(const FairGenerator& rhs) + : TNamed(rhs) +{} + +FairGenerator::~FairGenerator() {} + +FairGenerator& FairGenerator::operator=(const FairGenerator& rhs) +{ + // check assignment to self + if (this == &rhs) + return *this; + + // base class assignment + TNamed::operator=(rhs); + + return *this; +} + +FairGenerator* FairGenerator::CloneGenerator() const +{ + Fatal("CloneGenerator", "Has to be overriden in multi-threading applications."); + return 0; +} + +ClassImp(FairGenerator); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGenericStack.cxx b/Detectors/3rdparty/FairRootBase/src/FairGenericStack.cxx new file mode 100644 index 0000000000000..3015d8bef25eb --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGenericStack.cxx @@ -0,0 +1,176 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairGenericStack source file ----- +// ----- Created 10/08/04 by D. Bertini ----- +// ------------------------------------------------------------------------- +#include "FairGenericStack.h" + +#include "FairLogger.h" // for FairLogger + +#include +#include +#include +#include +#include +#include +#include // strcmp + +FairGenericStack::FairGenericStack() + : TVirtualMCStack() + , fLogger(FairLogger::GetLogger()) + , fDetList(0) + , fDetIter(0) + , fVerbose(1) + , fFSTrackMap() + , fFSTrackIter() + , fFSMovedIndex(-2) + , fFSFirstSecondary(-2) + , fFSNofSecondaries(0) +{} + +// ----- Constructor with estimated array dimension -------------------- +FairGenericStack::FairGenericStack(Int_t) + : TVirtualMCStack() + , fLogger(FairLogger::GetLogger()) + , fDetList(0) + , fDetIter(0) + , fVerbose(1) + , fFSTrackMap() + , fFSTrackIter() + , fFSMovedIndex(-2) + , fFSFirstSecondary(-2) + , fFSNofSecondaries(0) +{} + +FairGenericStack::~FairGenericStack() { delete fDetIter; } + +FairGenericStack::FairGenericStack(const FairGenericStack& rhs) + : TVirtualMCStack(rhs) + , fLogger(FairLogger::GetLogger()) + , fDetList(rhs.fDetList) + , fDetIter(0) + , fVerbose(rhs.fVerbose) +{} + +FairGenericStack& FairGenericStack::operator=(const FairGenericStack& rhs) +{ + // check assignment to self + if (this == &rhs) + return *this; + + // base class assignment + TVirtualMCStack::operator=(rhs); + + // assignment oiperator + fLogger = 0; + fDetList = 0; + fDetIter = 0; + fVerbose = rhs.fVerbose; + + return *this; +} + +void FairGenericStack::SetDetArrayList(TRefArray* detArray) +{ + fDetList = detArray; + if (fDetList != 0) { + fDetIter = fDetList->MakeIterator(); + } +} + +FairGenericStack* FairGenericStack::CloneStack() const +{ + Fatal("CloneStack", "Has to be overriden in multi-threading applications."); + return 0; +} + +void FairGenericStack::FastSimMoveParticleTo(Double_t xx, + Double_t yy, + Double_t zz, + Double_t tt, + Double_t px, + Double_t py, + Double_t pz, + Double_t en) +{ + TLorentzVector curPos; + TVirtualMC::GetMC()->TrackPosition(curPos); + LOG(debug) << "track is in " << curPos.X() << "," << curPos.Y() << "," << curPos.Z() << ", moving to " << xx << "," + << yy << "," << zz; + TString curVolName(TVirtualMC::GetMC()->CurrentVolName()); + TString targetVolName(gGeoManager->FindNode(xx, yy, zz)->GetVolume()->GetName()); + if (curVolName.EqualTo(targetVolName)) { + LOG(fatal) << "FairStack::FastSimMoveParticleTo(" << xx << "," << yy << "," << zz << ": " << curVolName << " = " + << targetVolName << ") crashes the simulation."; + } else { + LOG(debug) << "gMC says track is in \"" << curVolName << "\" moving particle to \"" << targetVolName << "\"."; + } + + Int_t tobedone = 1; + Int_t parent = 0; // do not store it as mother + Int_t pdg = TVirtualMC::GetMC()->TrackPid(); + Double_t polx = 0.; + Double_t poly = 0.; + Double_t polz = 0.; + TMCProcess proc = kPPrimary; // not important, the track will not be saved + Int_t ntr = 0; // Track number; to be filled by the stack + Int_t status = 0; // not important, the track will not be saved + Double_t weight = 0.; + + PushTrack(tobedone, parent, pdg, px, py, pz, en, xx, yy, zz, tt, polx, poly, polz, proc, ntr, weight, status, -1); + fFSMovedIndex = GetListOfParticles()->GetEntries() - 1; + Int_t trackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); + fFSTrackIter = fFSTrackMap.find(trackID); // check if this track is not already created by FastSimulation + if (fFSTrackIter != fFSTrackMap.end()) // indeed the track has been created by the FastSimulation mechanism + trackID = fFSTrackIter->second; // use the ID of the original track + fFSTrackMap[ntr] = trackID; + + LOG(debug) << "FairStack::FastSimMoveParticleTo() created track number " << ntr << " to replace track number " + << trackID; + + if (strcmp(TVirtualMC::GetMC()->GetName(), "TGeant3TGeo") == 0) { + TVirtualMC::GetMC()->StopTrack(); + } +} + +void FairGenericStack::FastSimStopParticle() +{ + if (TVirtualMC::GetMC()->IsTrackStop()) + LOG(fatal) << "FairStack::FastSimStopParticle() tries to stop particle that was probably moved!"; + fFSMovedIndex = -1; + TVirtualMC::GetMC()->StopTrack(); +} + +void FairGenericStack::FastSimPushSecondary(Int_t parentID, + Int_t pdgCode, + Double_t xx, + Double_t yy, + Double_t zz, + Double_t tt, + Double_t px, + Double_t py, + Double_t pz, + Double_t en, + Double_t polx, + Double_t poly, + Double_t polz, + TMCProcess proc, + Double_t weight, + Int_t is) +{ + Int_t tobedone = 1; + + Int_t ntr = 0; // Track number; to be filled by the stack + PushTrack(tobedone, parentID, pdgCode, px, py, pz, en, xx, yy, zz, tt, polx, poly, polz, proc, ntr, weight, is, -1); + if (fFSNofSecondaries == 0) + fFSFirstSecondary = GetListOfParticles()->GetEntries() - 1; + fFSNofSecondaries++; +} + +ClassImp(FairGenericStack); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGenericVMCConfig.cxx b/Detectors/3rdparty/FairRootBase/src/FairGenericVMCConfig.cxx new file mode 100644 index 0000000000000..335ab45412c05 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGenericVMCConfig.cxx @@ -0,0 +1,169 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairGenericVMCConfigurce file ----- +// ----- Created 2019.02.19 by R. Karabowicz ----- +// ------------------------------------------------------------------------- +#include "FairGenericVMCConfig.h" + +#include "FairLogger.h" +#include "FairRunSim.h" + +#include + +FairGenericVMCConfig::FairGenericVMCConfig() {} + +FairGenericVMCConfig::~FairGenericVMCConfig() {} + +void FairGenericVMCConfig::Setup(const char* mcEngine) +{ + LOG(warning) << "FairGenericVMCConfig::Setup() Using gConfig.C macro DEPRACATED."; + LOG(warning) << "Check FairRoot/examples/common/gconfig/ for current YAML implementation."; + + TString lUserCuts = FairRunSim::Instance()->GetUserCuts(); + TString lUserConfig = FairRunSim::Instance()->GetUserConfig(); + + TString work = getenv("VMCWORKDIR"); + TString work_config = work + "/gconfig/"; + work_config.ReplaceAll("//", "/"); + + TString Lib_config = getenv("GEANT4VMC_MACRO_DIR"); + Lib_config.ReplaceAll("//", "/"); + if (!Lib_config.EndsWith("/") && !Lib_config.IsNull()) { + Lib_config += "/"; + } + + TString config_dir = getenv("CONFIG_DIR"); + config_dir.ReplaceAll("//", "/"); + + Bool_t AbsPath = kFALSE; + + TString LibMacro; + TString LibFunction; + TString ConfigMacro; + TString cuts = lUserCuts; + //----------------------------------------------Geant4 Config----------------------------------------- + if (strcmp(mcEngine, "TGeant4") == 0) { + TString g4LibMacro = "g4libs.C"; + TString g4Macro; + if (lUserConfig.IsNull()) { + g4Macro = "g4Config.C"; + lUserConfig = g4Macro; + } else { + if (lUserConfig.Contains("/")) { + AbsPath = kTRUE; + } + g4Macro = lUserConfig; + LOG(info) << "---------------User config is used: " << g4Macro.Data(); + } + if (TString(gSystem->FindFile(config_dir.Data(), g4LibMacro)) + != TString("")) { // be carfull after this call the string g4LibMacro is empty if not found!!!! + LOG(info) << "---User path for Configuration (g4libs.C) is used: " << config_dir.Data(); + LibMacro = g4LibMacro; + } else if (gSystem->AccessPathName((Lib_config + "g4libs.C").Data()) == false) { + // Note: file is existing if AccessPathName return false + LOG(info) << "---G4VMC macro path for Configuration (g4libs.C) is used: " << Lib_config.Data(); + LibMacro = Lib_config + "g4libs.C"; + } + LibFunction = "g4libs()"; + if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), g4Macro)) != TString("")) { + LOG(info) << "---User path for Configuration (g4Config.C) is used: " << config_dir.Data(); + ConfigMacro = g4Macro; + } else { + if (AbsPath) { + ConfigMacro = lUserConfig; + } else { + ConfigMacro = work_config + lUserConfig; + } + } + //----------------------------------------------Geant3 Config----------------------------------------- + } else if (strcmp(mcEngine, "TGeant3") == 0) { + TString g3LibMacro = "g3libs.C"; + TString g3Macro = "g3Config.C"; + if (lUserConfig.IsNull()) { + g3Macro = "g3Config.C"; + lUserConfig = g3Macro; + LOG(info) << "-------------- Standard Config is called ------------------------------------"; + } else { + if (lUserConfig.Contains("/")) { + AbsPath = kTRUE; + } + g3Macro = lUserConfig; + LOG(info) << "---------------User config is used: " << g3Macro.Data(); + } + if (TString(gSystem->FindFile(config_dir.Data(), g3LibMacro)) != TString("")) { + LOG(info) << "---User path for Configuration (g3libs.C) is used: " << config_dir.Data(); + LibMacro = g3LibMacro; + } else if (gSystem->AccessPathName((work_config + "g3libs.C").Data()) == false) { + // Note: file is existing if AccessPathName return false + LOG(info) << "---VMCWORKDIR path for Configuration (g3libs.C) is used: " << work_config.Data(); + LibMacro = work_config + "g3libs.C"; + } + LibFunction = "g3libs()"; + if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), g3Macro)) != TString("")) { + LOG(info) << "---User path for Configuration (g3Config.C) is used: " << config_dir.Data(); + ConfigMacro = g3Macro; + } else { + if (AbsPath) { + ConfigMacro = lUserConfig; + } else { + ConfigMacro = work_config + lUserConfig; + } + } + //----------------------------------------------Fluka Config----------------------------------------- + } else if (strcmp(mcEngine, "TFluka") == 0) { + TString flLibMacro = "fllibs.C"; + TString flMacro = "flConfig.C"; + if (lUserConfig.IsNull()) { + flMacro = "flConfig.C"; + lUserConfig = flMacro; + } else { + if (lUserConfig.Contains("/")) { + AbsPath = kTRUE; + } + flMacro = lUserConfig; + LOG(info) << "---------------User config is used: " << flMacro.Data(); + } + if (TString(gSystem->FindFile(config_dir.Data(), flLibMacro)) != TString("")) { + LOG(info) << "---User path for Configuration (fllibs.C) is used: " << config_dir.Data(); + } else { + flLibMacro = work_config + "fllibs.C"; + } + LibMacro = flLibMacro; + LibFunction = "fllibs()"; + if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), flMacro)) != TString("")) { + LOG(info) << "---User path for Configuration (flConfig.C) is used: " << config_dir.Data(); + ConfigMacro = flMacro; + } else { + if (AbsPath) { + ConfigMacro = lUserConfig; + } else { + ConfigMacro = work_config + lUserConfig; + } + } + } + //----------------------------------------------SetCuts------------------------------------------------ + if (TString(gSystem->FindFile(config_dir.Data(), cuts)) != TString("")) { + LOG(info) << "---User path for Cuts and Processes (SetCuts.C) is used: " << config_dir.Data(); + } else { + cuts = work_config + lUserCuts; + } + //--------------------------------------Now load the Config and Cuts------------------------------------ + if (!LibMacro.IsNull()) { + gROOT->LoadMacro(LibMacro.Data()); + gROOT->ProcessLine(LibFunction.Data()); + } + + gROOT->LoadMacro(ConfigMacro.Data()); + gROOT->ProcessLine("Config()"); + + gROOT->LoadMacro(cuts); + gROOT->ProcessLine("SetCuts()"); +} + +ClassImp(FairGenericVMCConfig); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoAsciiIo.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoAsciiIo.cxx new file mode 100644 index 0000000000000..c2beca1fa3584 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoAsciiIo.cxx @@ -0,0 +1,280 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 10/11/2003 + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoAsciiIo +// +// Class for geometry I/O from ASCII file +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoAsciiIo.h" + +#include "FairGeoInterface.h" // for FairGeoInterface +#include "FairGeoIo.h" // for FairGeoIo +#include "FairGeoMedia.h" // for FairGeoMedia +#include "FairGeoSet.h" // for FairGeoSet + +#include // for fstream +#include // for cout +#include // for sscanf +#include // for strcmp, strlen, strtok, etc + +using std::cout; +using std::endl; +using std::ios; + +ClassImp(FairGeoAsciiIo); + +FairGeoAsciiIo::FairGeoAsciiIo() + : FairGeoIo() + , filename("") + , filedir("") + , writable(kFALSE) + , file(nullptr) +{ + // Constructor +} + +FairGeoAsciiIo::~FairGeoAsciiIo() +{ + // Destructor + close(); + delete file; + file = 0; +} + +Bool_t FairGeoAsciiIo::open(const char* fname, const Text_t* status) +{ + // Opens the file fname + close(); + if (!file) { + file = new std::fstream(); + } else { + (file->clear()); + } + if (!filedir.IsNull()) { + filename = filedir + "/" + fname; + } else { + filename = fname; + } + filename = filename.Strip(); + if (strcmp(status, "in") == 0) { + file->open(filename, ios::in); + writable = kFALSE; + } else { + if (strcmp(status, "out") == 0) { + file->open(filename, ios::in); + if (!isOpen()) { + file->close(); + file->clear(); + file->open(filename, ios::out); + writable = kTRUE; + } else { + file->close(); + Error("open", "Output file %s exists already and will not be recreated.", filename.Data()); + return kFALSE; + } + } else { + Error("open", "Invalid file option!"); + } + } + if (file->rdbuf()->is_open() == 0) { + Fatal("open", "Failed to open file %s", filename.Data()); + return kFALSE; + } + return kTRUE; +} + +Bool_t FairGeoAsciiIo::isOpen() +{ + // Returns kTRUE, if the file is open + if (file && file->rdbuf()->is_open() == 1) { + return kTRUE; + } + return kFALSE; +} + +Bool_t FairGeoAsciiIo::isWritable() +{ + // Returns kTRUE, if the file is open and writable + if (isOpen() && writable) { + return kTRUE; + } + return kFALSE; +} + +void FairGeoAsciiIo::close() +{ + // Closes the file + if (isOpen()) { + file->close(); + filename = ""; + } +} + +void FairGeoAsciiIo::print() +{ + // Prints file information + if (isOpen()) { + if (writable) { + cout << "Open output file: " << filename << endl; + } else { + cout << "Open input file: " << filename << endl; + } + } else { + cout << "No file open." << endl; + } +} + +Bool_t FairGeoAsciiIo::read(FairGeoMedia* media) +{ + // Reads the media from file + if (!isOpen() || writable || media == 0) { + return kFALSE; + } + media->read(*file); + return kTRUE; +} + +Bool_t FairGeoAsciiIo::read(FairGeoSet* set, FairGeoMedia* media) +{ + // Reads the geometry set from file + if (!isOpen() || writable || set == 0) { + return kFALSE; + } + set->read(*file, media); + return kTRUE; +} + +Bool_t FairGeoAsciiIo::write(FairGeoMedia* media) +{ + // Writes the media to file + if (!isOpen() || !writable || media == 0) { + return kFALSE; + } + media->write(*file); + return kTRUE; +} + +Bool_t FairGeoAsciiIo::write(FairGeoSet* set) +{ + // Writes the geometry set to file + if (!isOpen() || !writable || set == 0) { + return kFALSE; + } + set->write(*file); + return kTRUE; +} + +Bool_t FairGeoAsciiIo::readGeomConfig(FairGeoInterface* interface) +{ + // Reads the GEANT configuration file + if (!isOpen() || writable || interface == 0) { + return kFALSE; + } + TString buf(256); + TString simRefRun, historyDate; + Int_t k = -1; + while (!(*file).eof()) { + buf.ReadLine(*file); + buf = buf.Strip(buf.kBoth); + if (!buf.IsNull() && buf(0, 2) != "//" && buf(0, 1) != "*") { + if (buf.Contains(".geo") || buf.Contains("_gdb")) { + interface->addInputFile(buf.Data()); + } else { + if (buf.Contains(".setup")) { + interface->addSetupFile(buf.Data()); + } else { + if (buf.Contains("SimulRefRunDb:")) { + k = buf.Last(' ') + 1; + if (k) { + simRefRun = buf(k, buf.Length() - k); + } + } else { + if (buf.Contains("HistoryDateDb:")) { + k = buf.First(' ') + 1; + if (buf.Length() > k) { + historyDate = buf(k, buf.Length() - k); + historyDate = historyDate.Strip(historyDate.kBoth); + } + } + } + } + } + } + } + Bool_t rc = kTRUE; + FairGeoIo* oraIo = interface->getOraInput(); + if (oraIo) { + if (historyDate.Length() > 0) { + rc = oraIo->setHistoryDate(historyDate.Data()); + } + if (rc && simRefRun.Length() > 0) { + rc = oraIo->setSimulRefRun(simRefRun.Data()); + } + } + return rc; +} + +Bool_t FairGeoAsciiIo::readDetectorSetup(FairGeoInterface* interface) +{ + // Reads the detector setups, needed for create only subsets + if (!isOpen() || writable || interface == 0) { + return kFALSE; + } + const Int_t maxbuf = 256; + char buf[maxbuf]; + TString s, det; + FairGeoSet* set = 0; + Int_t maxModules = 0, secNo = -1; + Int_t* mod = 0; + const char d[] = " "; + while (!(*file).eof()) { + (*file).getline(buf, maxbuf); + if (strlen(buf) >= 3 && buf[1] != '/') { + if (buf[0] == '[') { + set = 0; + delete[] mod; + mod = 0; + s = buf; + Ssiz_t n = s.First(']'); + det = s(1, n - 1); + det.ToLower(); + set = interface->findSet(det); + if (!set) { + Error("readDetectorSetup", "Detector %s not found", det.Data()); + delete[] mod; + return kFALSE; + } + maxModules = set->getMaxModules(); + mod = new Int_t[maxModules]; + } else { + if (set && mod) { + char* ss = strtok(buf, d); + if (ss && strlen(ss) > 3) { + secNo = static_cast(ss[3] - '0') - 1; + for (Int_t i = 0; i < maxModules && mod; i++) { + ss = strtok(nullptr, d); + if (ss) { + sscanf(ss, "%i", &mod[i]); + } + } + set->setModules(secNo, mod); + } + } else { + delete[] mod; + return kFALSE; + } + } + } + } + delete[] mod; + return kTRUE; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoAssembly.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoAssembly.cxx new file mode 100644 index 0000000000000..c60402f9027ca --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoAssembly.cxx @@ -0,0 +1,103 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : M. Al-Turany 21/04/2009 + +///////////////////////////////////////////////////////////// +// +// FairGeoAssmebly +// +// class for the shape Assembly +///////////////////////////////////////////////////////////// +#include "FairGeoAssembly.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for TString +#include +#include // for fstream, etc +#include // for printf, sprintf +#include // for strlen + +ClassImp(FairGeoAssembly); + +FairGeoAssembly::FairGeoAssembly() + : FairGeoBasicShape() +{ + // constructor + fName = "ASSEMBLY"; + nPoints = 0; + nParam = 0; + param = new TArrayD(nParam); +} + +FairGeoAssembly::~FairGeoAssembly() +{ + // destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +Int_t FairGeoAssembly::readPoints(std::fstream*, FairGeoVolume*) +{ + + // Assemblies has no parameters so just return 1; + return 1; +} + +TArrayD* FairGeoAssembly::calcVoluParam(FairGeoVolume*) +{ + // nothing to calculate + + return param; +} + +Bool_t FairGeoAssembly::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 4 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + sprintf(buf, "%9.3f\n", v(0)); + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoAssembly::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + printf("%9.3f\n", v(0)); + } +} + +void FairGeoAssembly::calcVoluPosition(FairGeoVolume*, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoBasicShape.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoBasicShape.cxx new file mode 100644 index 0000000000000..d467c261f156b --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoBasicShape.cxx @@ -0,0 +1,145 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 29/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoBasicShape +// +// Base class of the all shapes +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoBasicShape.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for fstream +#include // for cout +#include // for printf, sprintf, sscanf +#include // for strlen + +using std::cout; + +ClassImp(FairGeoBasicShape); + +FairGeoBasicShape::FairGeoBasicShape() + : TNamed() + , nPoints(0) + , nParam(0) + , param(0) + , center(new FairGeoTransform()) + , position(new FairGeoTransform()) +{ + // default constructor +} + +FairGeoBasicShape::~FairGeoBasicShape() +{ + // destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +Int_t FairGeoBasicShape::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads nPoints with 3 components from Ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + } + return nPoints; +} + +Bool_t FairGeoBasicShape::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes nPoints with 3 components to Ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < volu->getNumPoints(); i++) { + FairGeoVector& v = *(volu->getPoint(i)); + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoBasicShape::printPoints(FairGeoVolume* volu) +{ + // prints nPoints with 3 components to screen + for (Int_t i = 0; i < volu->getNumPoints(); i++) { + FairGeoVector& v = *(volu->getPoint(i)); + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } +} + +void FairGeoBasicShape::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& mTR) +{ + // calculates the relevant information to position the corresponding volume + // in its mother and to position later other components inside this volume. + // The transformation mTR describes the position and orientation of the + // mother volume (center) relative to the physical coordinate system of + // the volume from which it was created. + FairGeoTransform& dTC = volu->getTransform(); + calcVoluPosition(volu, dTC, mTR); +} + +void FairGeoBasicShape::posInMother(const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calculates the position of the volume inside its mother + // dTC is the coordinate system of the ROOT volume relative to its physical + // coordinate system + // mTR is the coordinate system of the mother volume relative to its + // physical coordinate system + position->setRotMatrix(center->getRotMatrix()); + position->setTransVector(center->getTransVector()); + position->transFrom(dTC); + position->transTo(mTR); + FairGeoVector t(position->getTransVector()); + position->setTransVector(t *= 0.1); +} + +void FairGeoBasicShape::printParam() +{ + // prints the parameters of the ROOT shape + if (param) { + for (Int_t i = 0; i < nParam; i++) { + cout << param->At(i) << " "; + } + cout << '\n'; + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoBrik.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoBrik.cxx new file mode 100644 index 0000000000000..063b8c36d148a --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoBrik.cxx @@ -0,0 +1,85 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 14/05/99 by Ilse Koenig + +///////////////////////////////////////////////////////////// +// +// FairGeoBrik +// +// class for the GEANT shape BOX +// +// The intrisic coordinate system of a BOX in GEANT/ROOT has the +// same orientation as the volume described by its 8 points +// in the technical coordinate system +// +///////////////////////////////////////////////////////////// +#include "FairGeoBrik.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for TString + +ClassImp(FairGeoBrik); + +FairGeoBrik::FairGeoBrik() + : FairGeoBasicShape() +{ + // constructor + fName = "BOX "; + nPoints = 8; + nParam = 3; + param = new TArrayD(nParam); +} + +FairGeoBrik::~FairGeoBrik() +{ + // destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +TArrayD* FairGeoBrik::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape + if (!volu) { + return 0; + } + FairGeoVector v = *(volu->getPoint(5)) - *(volu->getPoint(3)); + v.abs(); + v *= (1 / 20.); + for (Int_t i = 0; i < nParam; i++) { + param->AddAt(v(i), i); + } + return param; +} + +void FairGeoBrik::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + FairGeoVector trans = *(volu->getPoint(5)) + *(volu->getPoint(3)); + trans *= 0.5; + center->clear(); + center->setTransVector(trans); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoBuilder.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoBuilder.cxx new file mode 100644 index 0000000000000..28ddcc599414c --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoBuilder.cxx @@ -0,0 +1,36 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 11/11/03 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoBuilder +// +// Base class for GEANT and ROOT builder classes to create the geometry +// +/////////////////////////////////////////////////////////////////////////////// + +#include "FairGeoBuilder.h" + +ClassImp(FairGeoBuilder); + +FairGeoBuilder::FairGeoBuilder() + : TNamed() + , nRot(0) + , nMed(0) +{ + // Default constructor +} + +FairGeoBuilder::FairGeoBuilder(const char* name, const char* title) + : TNamed(name, title) + , nRot(0) + , nMed(0) +{ + // Constructor +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoCone.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoCone.cxx new file mode 100644 index 0000000000000..b5ab571f4f958 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoCone.cxx @@ -0,0 +1,163 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 28/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoCone +// +// class for the GEANT shape CONE +// +// The size of a CONE is defined by 4 'points'. +// point 0: origin of starting circle of the cone; +// point 1: inner radius of starting circle, +// outer radius of starting circle; +// (z-component not used) +// point 2: origin of ending circle of the cone; +// point 3: inner radius of ending circle, +// outer radius of ending circle; +// (z-component not used) +// Warning: The x- and y-values of point 0 and 2 have to be the same!!!! +// A rotation has to be desribed via the rotation matrix. +// +// The intrinsic coordinate system of a CONE, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoCone.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for Abs +#include // for TString +#include +#include // for fstream, etc +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoCone); + +FairGeoCone::FairGeoCone() + : FairGeoBasicShape() +{ + // constructor + fName = "CONE"; + nPoints = 4; + nParam = 5; + param = new TArrayD(nParam); +} + +FairGeoCone::~FairGeoCone() +{ + // default destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +Int_t FairGeoCone::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 4 'points' decribed above from ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + i++; + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + return nPoints; +} + +Bool_t FairGeoCone::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 4 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i == 0 || i == 2) { + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoCone::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i == 0 || i == 2) { + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + printf("%9.3f%10.3f\n", v(0), v(1)); + } + } +} + +TArrayD* FairGeoCone::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape CONE + Double_t fac = 10.; + FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0)); + param->AddAt(TMath::Abs(v(2)) / fac / 2., 0); + FairGeoVector& v1 = *(volu->getPoint(1)); + param->AddAt(v1(0) / fac, 1); + param->AddAt(v1(1) / fac, 2); + FairGeoVector& v3 = *(volu->getPoint(3)); + param->AddAt(v3(0) / fac, 3); + param->AddAt(v3(1) / fac, 4); + return param; +} + +void FairGeoCone::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calculates the position of the center of the volume in the intrinsic + // coordinate system and stores it in the data element 'center' + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0)); + t[2] = v(2) / 2.; + center->clear(); + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoCons.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoCons.cxx new file mode 100644 index 0000000000000..44fd49010872e --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoCons.cxx @@ -0,0 +1,170 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 28/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoCons +// +// class for the GEANT shape CONS +// +// The size of a CONS is defined by 5 'points'. +// point 0: origin of starting circle of the cons; +// point 1: inner radius of starting circle, +// outer radius of starting circle; +// (z-component not used) +// point 2: origin of ending circle of the cons; +// point 3: inner radius of ending circle, +// outer radius of ending circle; +// (z-component not used) +// point 4: starting angle of the segment, +// ending angle of the segment; +// (z-component not used) +// Warning: The x- and y-values of point 0 and 2 have to be the same!!!! +// A rotation has to be desribed via the rotation matrix. +// +// The intrinsic coordinate system of a CONS, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoCons.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for Abs +#include // for TString +#include +#include // for fstream, etc +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoCons); + +FairGeoCons::FairGeoCons() + : FairGeoBasicShape() +{ + // constructor + fName = "CONS"; + nPoints = 5; + nParam = 7; + param = new TArrayD(nParam); +} + +FairGeoCons::~FairGeoCons() +{ + // default destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +Int_t FairGeoCons::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 5 'points' decribed above from ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + if (i == 0 || i == 2) { + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + } else { + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + } + return nPoints; +} + +Bool_t FairGeoCons::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 5 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i == 0 || i == 2) { + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoCons::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i == 0 || i == 2) { + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + printf("%9.3f%10.3f\n", v(0), v(1)); + } + } +} + +TArrayD* FairGeoCons::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape CONS + Double_t fac = 10.; + FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0)); + param->AddAt(TMath::Abs(v(2)) / fac / 2., 0); + FairGeoVector& v1 = *(volu->getPoint(1)); + param->AddAt(v1(0) / fac, 1); + param->AddAt(v1(1) / fac, 2); + FairGeoVector& v3 = *(volu->getPoint(3)); + param->AddAt(v3(0) / fac, 3); + param->AddAt(v3(1) / fac, 4); + FairGeoVector& v4 = *(volu->getPoint(4)); + param->AddAt(v4(0), 5); + param->AddAt(v4(1), 6); + return param; +} + +void FairGeoCons::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calculates the position of the center of the volume in the intrinsic + // coordinate system and stores it in the data element 'center' + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0)); + t[2] = v(2) / 2.; + center->clear(); + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoEltu.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoEltu.cxx new file mode 100644 index 0000000000000..a37be52ef73b4 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoEltu.cxx @@ -0,0 +1,158 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 28/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoEltu +// +// class for the GEANT shape ELTU +// +// The size of a ELTU is defined by 3 'points'. +// point 0: origin of starting ellipse of the eltu; +// point 1: semi-axis of the ellipse along x, +// semi-axis of the ellipse along y; +// (z-component not used) +// point 2: origin of ending ellipse of the eltu; +// Warning: The x- and y-values of point 0 and 2 have to be the same!!!! +// A rotation has to be desribed via the rotation matrix. +// +// The intrinsic coordinate system of a ELTU, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoEltu.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for Abs +#include // for TString +#include +#include // for fstream, etc +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoEltu); + +FairGeoEltu::FairGeoEltu() + : FairGeoBasicShape() +{ + // constructor + fName = "ELTU"; + nPoints = 3; + nParam = 3; + param = new TArrayD(nParam); +} + +FairGeoEltu::~FairGeoEltu() +{ + // default destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +Int_t FairGeoEltu::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 3 'points' decribed above from ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + if (i != 1) { + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + } else { + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + } + return nPoints; +} + +Bool_t FairGeoEltu::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 3 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i != 1) { + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoEltu::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i != 1) { + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + printf("%9.3f%10.3f\n", v(0), v(1)); + } + } +} + +TArrayD* FairGeoEltu::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape ELTU + Double_t fac = 10.; + FairGeoVector& v1 = *(volu->getPoint(1)); + param->AddAt(v1(0) / fac, 0); + param->AddAt(v1(1) / fac, 1); + FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0)); + param->AddAt(TMath::Abs(v(2)) / fac / 2., 2); + return param; +} + +void FairGeoEltu::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calculates the position of the center of the volume in the intrinsic + // coordinate system and stores it in the data element 'center' + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0)); + t[2] = v(2) / 2.; + center->clear(); + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoInterface.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoInterface.cxx new file mode 100644 index 0000000000000..81f76734474fc --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoInterface.cxx @@ -0,0 +1,538 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 10/11/03 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoInterface +// +// Manager class for geometry used by simulation + +// *--15.12.04 M. Al-Turany +// 1-addInputFile(const char* name) is not used anymore +// 2-addGeoModule(FairGeoSet*pSet) is added +// 3-setMediaFile(const char *file) is added +// 3-findSet(const char* name) has been changed, no hard coding of name +// 4-nSets is now set by a method SetNoOfSets(Int_t) (see header file) + +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoInterface.h" + +#include "FairGeoAsciiIo.h" // for FairGeoAsciiIo +#include "FairGeoBuilder.h" // for FairGeoBuilder +#include "FairGeoIo.h" // for FairGeoIo +#include "FairGeoMedia.h" // for FairGeoMedia +#include "FairGeoSet.h" // for FairGeoSet +#include "FairGeoShapes.h" // for FairGeoShapes + +#include // for TClass +#include // for TList +#include // for TObjArray +#include // for operator<<, basic_ostream, etc +#include // for sprintf +#include // for strcmp +#include // for time_t +#include // for tm, localtime, time + +using std::cout; +using std::endl; + +ClassImp(FairGeoInterface); + +FairGeoInterface::FairGeoInterface() + : TObject() + , fileInput(nullptr) + , oraInput(nullptr) + , output(nullptr) + , nSets(0) + , nActualSets(0) + , sets(new TObjArray()) + , media(new FairGeoMedia()) + , shapes(new FairGeoShapes()) + , masterNodes(new TList()) + , setupFile("") + , geoBuilder(nullptr) +{ + // Constructor +} + +FairGeoInterface::~FairGeoInterface() +{ + // Destructor + delete fileInput; + fileInput = 0; + delete oraInput; + oraInput = 0; + delete output; + output = 0; + + // if (geoBuilder) { + // delete geoBuilder; + // geoBuilder=0; + // } + if (masterNodes) { + masterNodes->Delete(); + delete masterNodes; + masterNodes = 0; + } + if (sets) { + sets->Delete(); + delete sets; + sets = 0; + } + if (media) { + delete media; + media = 0; + } + if (shapes) { + delete shapes; + shapes = 0; + } +} + +void FairGeoInterface::addGeoModule(FairGeoSet* pSet) +{ + sets->AddLast(pSet); + pSet->setShapes(shapes); + pSet->setMasterNodes(masterNodes); + nActualSets++; +} +void FairGeoInterface::setMediaFile(const char* file) { media->setInputFile(file); } + +void FairGeoInterface::addInputFile(const char* file) +{ + + Error("This Methode is not used any more ", "Use addGeoModule to add detectors: %s", file); + /* + // Adds the input file and creates the corresponding detector object + FairGeoSet* pSet=0; + TString setName(file); + setName.ToLower(); + Int_t l=setName.Last('/')+1; + setName=setName(l,setName.Length()-l); + if (setName.Contains("media")) { + media->setInputFile(file); + } else { + if (setName.Contains("cave")) { + pSet=static_cast(sets->At(kFairGeoCave)); + if (!pSet) { + pSet=new FairGeoCave; + sets->AddAt(pSet,kFairGeoCave); + } + } else if (setName.Contains("pipe")) { + pSet=static_cast(sets->At(kFairGeoPipe)); + if (!pSet) { + pSet=new FairGeoPipe; + sets->AddAt(pSet,kFairGeoPipe); + } + } else if (setName.Contains("target")) { + pSet=static_cast(sets->At(kFairGeoTarget)); + if (!pSet) { + pSet=new FairGeoTarget; + sets->AddAt(pSet,kFairGeoTarget); + } + } else if (setName.Contains("magnet")) { + pSet=static_cast(sets->At(kFairGeoMagnet)); + if (!pSet) { + pSet=new FairGeoMagnet; + sets->AddAt(pSet,kFairGeoMagnet); + } + } else if (setName.Contains("rich")) { + pSet=static_cast(sets->At(kFairGeoRich)); + if (!pSet) { + pSet=new FairGeoRich; + sets->AddAt(pSet,kFairGeoRich); + } + } else if (setName.Contains("sts")) { + pSet=static_cast(sets->At(kFairGeoSts)); + if (!pSet) { + pSet=new FairGeoSts; + sets->AddAt(pSet,kFairGeoSts); + } + } else if (setName.Contains("trd")) { + pSet=static_cast(sets->At(kFairGeoTrd)); + if (!pSet) { + pSet=new FairGeoTrd; + sets->AddAt(pSet,kFairGeoTrd); + } + } else if (setName.Contains("tof")) { + pSet=static_cast(sets->At(kFairGeoTof)); + if (!pSet) { + pSet=new FairGeoTof; + sets->AddAt(pSet,kFairGeoTof); + } + } else Error("addInputFile","Unknown detector set: %s",file); + if (pSet) { + pSet->setShapes(shapes); + pSet->setMasterNodes(masterNodes); + pSet->setGeomFile(file); + nActualSets++; + } + } + */ +} + +FairGeoSet* FairGeoInterface::findSet(const char* name) +{ + // Find the detector set in the actual setup + FairGeoSet* pSet = 0; + TString setName(name); + TString PSetName; + setName.ToLower(); + Int_t l = setName.Last('/') + 1; + setName = setName(l, setName.Length() - l); + /* if (setName.Contains("cave")) pSet=static_cast(sets->At(kFairGeoCave)); + else if (setName.Contains("pipe")) pSet=static_cast(sets->At(kFairGeoPipe)); + else if (setName.Contains("target")) pSet=static_cast(sets->At(kFairGeoTarget)); + else if (setName.Contains("magnet")) pSet=static_cast(sets->At(kFairGeoMagnet)); + else if (setName.Contains("rich")) pSet=static_cast(sets->At(kFairGeoRich)); + else if (setName.Contains("sts")) pSet=static_cast(sets->At(kFairGeoSts)); + else if (setName.Contains("trd")) pSet=static_cast(sets->At(kFairGeoTrd)); + else if (setName.Contains("tof")) pSet=static_cast(sets->At(kFairGeoTof)); + else if (setName.Contains("ecal")) pSet=static_cast(sets->At(kFairGeoEcal)); + return pSet; + */ + for (Int_t i = 0; i < nSets; i++) { + PSetName = sets->At(i)->GetName(); + if (PSetName.Contains(setName.Data())) { + pSet = static_cast(sets->At(i)); + cout << "FairGeoInterface::findSet" << pSet->GetName() << endl; + break; + } + } + return pSet; +} + +Bool_t FairGeoInterface::readSet(FairGeoSet* pSet) +{ + // Reads the geometry for the detector part + Bool_t rc = kFALSE; + FairGeoIo* input = 0; + if (pSet) { + input = connectInput(pSet->getGeomFile()); + if (input) { + rc = input->read(pSet, media); + } + } + return rc; +} + +Bool_t FairGeoInterface::writeSet(FairGeoSet* pSet) +{ + // Writes the geometry for the detector part to output + if (pSet && connectOutput(pSet->GetName())) { + return output->write(pSet); + } + return kFALSE; +} + +Bool_t FairGeoInterface::writeSet(FairGeoSet* pSet, const char* filename) +{ + // Writes the geometry for the detector part to file + if (pSet && output) { + output->open(filename, "out"); + if (output->isOpen()) { + return output->write(pSet); + } + } + return kFALSE; +} + +void FairGeoInterface::deleteSet(FairGeoSet* pSet) +{ + // Deletes the set + if (pSet) { + sets->Remove(pSet); + delete pSet; + pSet = 0; + } +} + +Bool_t FairGeoInterface::readMedia() +{ + // Reads the media + Bool_t rc = kFALSE; + FairGeoIo* input = connectInput(media->getInputFile()); + if (input) { + rc = input->read(media); + } + return rc; +} + +Bool_t FairGeoInterface::writeMedia() +{ + // Writes the media to output + if (connectOutput("media")) { + return output->write(media); + } + return kFALSE; +} + +Bool_t FairGeoInterface::writeMedia(const char* filename) +{ + // Writes the media to file + if (output) { + output->open(filename, "out"); + if (output->isOpen()) { + return output->write(media); + } + } + return kFALSE; +} + +Bool_t FairGeoInterface::readAll() +{ + // Reads the media and the whole geometry + Bool_t rc = kTRUE; + if (nActualSets == 0 && oraInput) { + rc = oraInput->readGeomConfig(this); + // if (rc) addInputFile("media_gdb"); + if (rc) { + addInputFile("media_gdb"); + } + } + if (rc) { + rc = readSetupFile(); + } + if (rc) { + rc = readMedia(); + } + FairGeoSet* pSet = 0; + for (Int_t i = 0; i < nSets && rc; i++) { + pSet = static_cast(sets->At(i)); + if (pSet) { + cout << "Read " << pSet->GetName() << endl; + rc = readSet(pSet); + } + } + return rc; +} + +Bool_t FairGeoInterface::writeAll() +{ + // Reads the media and the whole geometry to output + Bool_t rc = kTRUE; + FairGeoSet* pSet = 0; + rc = writeMedia(); + for (Int_t i = 0; i < nSets && rc; i++) { + pSet = static_cast(sets->At(i)); + if (pSet) { + rc = writeSet(pSet); + } + } + return rc; +} + +Bool_t FairGeoInterface::createAll(Bool_t withCleanup) +{ + // Creates the whole geometry + // (if withCleanup==kTRUE, the geometry input is deleted afterwards) + Bool_t rc = kTRUE; + Int_t n = 0; + if (geoBuilder) { + FairGeoSet* pSet = 0; + for (Int_t i = 0; i < nSets && rc; i++) { + pSet = static_cast(sets->At(i)); + if (pSet) { + cout << "Create " << pSet->GetName() << endl; + rc = pSet->create(geoBuilder); + n++; + if (withCleanup) { + sets->RemoveAt(i); + delete pSet; + } + } + } + if (rc && n > 0) { + geoBuilder->finalize(); + } + } else { + Error("createAll()", "No Builder"); + } + return rc; +} + +Bool_t FairGeoInterface::createGeometry(Bool_t withCleanup) +{ + // Reads and creates the whole geometry + // (if withCleanup==kTRUE, the geometry input is deleted after creation) + Bool_t rc = kTRUE; + Int_t n = 0; + if (geoBuilder) { + if (nActualSets == 0 && oraInput) { + rc = oraInput->readGeomConfig(this); + if (rc) { + addInputFile("media_gdb"); + } + } + if (rc) { + rc = readSetupFile(); + } + if (rc) { + rc = readMedia(); + } + FairGeoSet* pSet = 0; + for (Int_t i = 0; i < nSets && rc; i++) { + pSet = static_cast(sets->At(i)); + if (pSet) { + cout << "Read and create " << pSet->GetName() << endl; + rc = readSet(pSet); + if (rc) { + rc = pSet->create(geoBuilder); + n++; + } + if (withCleanup) { + sets->RemoveAt(i); + delete pSet; + } + } + } + if (rc && n > 0) { + geoBuilder->finalize(); + } + } else { + Error("createAll()", "No Builder"); + } + return rc; +} + +FairGeoIo* FairGeoInterface::connectInput(const char* filename) +{ + // Connects the input (ASCII or Oracle) + FairGeoIo* currentIo = 0; + if (filename) { + TString s(filename); + s = s.Strip(); + if (s.EndsWith(".dat") || s.EndsWith(".geo") || s.EndsWith(".setup")) { + if (!fileInput) { + fileInput = new FairGeoAsciiIo(); + } + fileInput->open(filename); + currentIo = fileInput; + } else if (s.EndsWith("_gdb")) { + currentIo = oraInput; + } + } + if (currentIo && currentIo->isOpen()) { + return currentIo; + } + return 0; +} + +Bool_t FairGeoInterface::connectOutput(const char* name) +{ + // Connects the output (ASCII or Oracle) + if (output) { + if (strcmp(output->IsA()->GetName(), "FairGeoAsciiIo") == 0) { + TString fName(name); + char buf[80]; + struct tm* newtime; + time_t t; + time(&t); + newtime = localtime(&t); + if (newtime->tm_mday < 10) { + sprintf(buf, "_0%i", newtime->tm_mday); + } else { + sprintf(buf, "_%i", newtime->tm_mday); + } + fName = fName + buf; + if (newtime->tm_mon < 9) { + sprintf(buf, "0%i", newtime->tm_mon + 1); + } else { + sprintf(buf, "%i", newtime->tm_mon + 1); + } + fName = fName + buf; + Int_t y = newtime->tm_year - 100; + if (y < 10) { + sprintf(buf, "0%i", y); + } else { + sprintf(buf, "%i", y); + } + fName = fName + buf; + if (newtime->tm_hour < 10) { + sprintf(buf, "0%i", newtime->tm_hour); + } else { + sprintf(buf, "%i", newtime->tm_hour); + } + fName = fName + buf; + if (newtime->tm_min < 10) { + sprintf(buf, "0%i", newtime->tm_min); + } else { + sprintf(buf, "%i", newtime->tm_min); + } + fName = fName + buf; + if (newtime->tm_sec < 10) { + sprintf(buf, "0%i", newtime->tm_sec); + } else { + sprintf(buf, "%i", newtime->tm_sec); + } + fName = fName + buf + ".geo"; + output->open(fName, "out"); + cout << "Output file for " << name << ": " << (static_cast(output))->getFilename() + << endl; + } + if (output->isOpen() && output->isWritable()) { + return kTRUE; + } + } else { + Error("connectOutput", "No output open"); + } + return kFALSE; +} + +Bool_t FairGeoInterface::createSet(FairGeoSet* pSet) +{ + // Creates the geometry of detector part + if (!geoBuilder) { + return kFALSE; + } + return pSet->create(geoBuilder); +} + +void FairGeoInterface::print() +{ + // Prints the media and the list of detector parts + media->list(); + cout << "********************************************************************\n"; + cout << "List of detector parts:\n"; + FairGeoSet* pSet = 0; + for (Int_t i = 0; i < nSets; i++) { + pSet = static_cast(sets->At(i)); + if (pSet) { + cout << " " << pSet->GetName() << ":\t" << pSet->getGeomFile() << '\n'; + } + } + cout << "********************************************************************\n"; +} + +Bool_t FairGeoInterface::readGeomConfig(const char* configFile) +{ + // Reads the GEANT configuration file + Bool_t rc = kFALSE; + FairGeoIo* input = 0; + if (configFile) { + input = connectInput(configFile); + if (input) { + rc = input->readGeomConfig(this); + } + } + return rc; +} + +Bool_t FairGeoInterface::readSetupFile() +{ + // Reads the detector setups, needed for create only subsets + Bool_t rc = kTRUE; + if (setupFile.Length() > 0) { + FairGeoAsciiIo* input = static_cast(connectInput(setupFile)); + if (input) { + rc = input->readDetectorSetup(this); + } + } + return rc; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoIo.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoIo.cxx new file mode 100644 index 0000000000000..91ad83b9d74aa --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoIo.cxx @@ -0,0 +1,20 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 10/11/2003 + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoIo +// +// Base class for geometry I/O from ASCII file and Oracle +// +/////////////////////////////////////////////////////////////////////////////// + +#include "FairGeoIo.h" + +ClassImp(FairGeoIo); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoLoader.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoLoader.cxx new file mode 100644 index 0000000000000..6a135e1c28e11 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoLoader.cxx @@ -0,0 +1,67 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/*************************************************************************** + FairGeoLoader.cxx - description + ------------------- + begin : Thu Jun 17 2004 + copyright : (C) 2004 by ilse koenig , M. Al-turany + email : m.al-turany@gsi.de + ***************************************************************************/ +#include "FairGeoLoader.h" + +#include "FairGeoInterface.h" // for FairGeoInterface +#include "FairGeoRootBuilder.h" // for FairGeoRootBuilder + +#include // for TGeoManager +#include // for NULL, exit +#include // for cout, endl, operator<<, etc +#include // for strncmp + +using std::cout; +using std::endl; + +FairGeoLoader* FairGeoLoader::fgInstance = 0; + +FairGeoLoader* FairGeoLoader::Instance() { return fgInstance; } + +FairGeoLoader::FairGeoLoader() + : TNamed() + , fInterface(NULL) + , fGeoBuilder(NULL) +{ + fgInstance = this; +} + +FairGeoLoader::FairGeoLoader(const char* Name, const char* title) + : TNamed(Name, title) + , fInterface(NULL) + , fGeoBuilder(NULL) +{ + if (fgInstance) { + Fatal("FairGeoLoader", "Singleton instance already exists."); + return; + } + fgInstance = this; + fInterface = new FairGeoInterface; + if (strncmp(Name, "TGeo", 4) == 0) { + TGeoManager* geom = new TGeoManager("FAIRGeom", "FAIR geometry"); + fGeoBuilder = new FairGeoRootBuilder("TGeo builder", "geometry builder"); + (static_cast(fGeoBuilder))->setGeoManager(geom); + } else if (strncmp(Name, "G3Native", 8) == 0) { + cout << "-I- FairGeoLoader() : Native G3 Geometry is used: This option is not supported any more!" << endl; + exit(0); + // gGeoManager = NULL; + // fGeoBuilder=new FairGeoG3Builder("G3 builder","geometry builder"); + } + + fInterface->setGeomBuilder(fGeoBuilder); +} + +FairGeoLoader::~FairGeoLoader() { delete fInterface; } + +ClassImp(FairGeoLoader); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoMedia.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoMedia.cxx new file mode 100644 index 0000000000000..bb1e912942909 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoMedia.cxx @@ -0,0 +1,163 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Last modified : 10/11/03 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoMedia +// +// Class for materials and media +// +/////////////////////////////////////////////////////////////////////////////// + +#include "FairGeoMedia.h" + +#include "FairGeoMedium.h" +#include "FairLogger.h" + +#include +#include + +using std::cout; +using std::endl; + +ClassImp(FairGeoMedia); + +FairGeoMedia::FairGeoMedia() + : TNamed() + , media(new TList()) + , inputFile("") + , author("") + , description("") +{ + // Constructor +} + +FairGeoMedia::~FairGeoMedia() +{ + // Destructor + if (media) { + media->Delete(); + delete media; + media = 0; + } +} + +FairGeoMedium* FairGeoMedia::getMedium(const char* mediumName) +{ + // Returns the medium with name mediumName + return static_cast(media->FindObject(mediumName)); +} + +void FairGeoMedia::addMedium(FairGeoMedium* m) +{ + // Adds a medium to the list of media + media->Add(m); +} + +void FairGeoMedia::list() +{ + // Lists all media + cout << "********************************************************************\n"; + cout << "List of media:\n"; + TListIter iter(media); + FairGeoMedium* medium; + while ((medium = static_cast(iter.Next()))) { + cout << " " << medium->GetName() << "\n"; + } +} + +void FairGeoMedia::print() +{ + // Prints the media + if (!author.IsNull()) { + cout << "//Author: " << author << '\n'; + } + if (!description.IsNull()) { + cout << "//Description: " << description << '\n'; + } + cout << "//----------------------------------------------------------\n"; + TListIter iter(media); + FairGeoMedium* medium; + Int_t i = 0; + while ((medium = static_cast(iter.Next()))) { + if (medium->getAutoFlag() != 0) { + medium->print(); + i++; + } + } + if (i != media->GetSize()) { + iter.Reset(); + cout << "//----------------------------------------------\n"; + cout << "AUTONULL\n"; + cout << "//----------------------------------------------\n"; + while ((medium = static_cast(iter.Next()))) { + if (medium->getAutoFlag() == 0) { + medium->print(); + } + } + } +} + +void FairGeoMedia::read(std::fstream& fin) +{ + // Reads the media from file + LOG(info) << "FairGeoMedia: Read media "; + const Int_t maxBuf = 256; + char buf[maxBuf]; + Int_t autoflag = 1; + while (!fin.eof()) { + fin >> buf; + if (buf[0] == '\0' || buf[0] == '/') { + fin.getline(buf, maxBuf); + } else if (fin.eof()) { + break; + } else { + TString eleName(buf); + if (eleName.CompareTo("AUTONULL") != 0) { + FairGeoMedium* medium = new FairGeoMedium(eleName); + medium->read(fin, autoflag); + media->Add(medium); + } else { + autoflag = 0; + } + } + } +} + +void FairGeoMedia::write(std::fstream& fout) +{ + // Writes the media to file + if (!author.IsNull()) { + fout << "//Author: " << author << '\n'; + } + if (!description.IsNull()) { + fout << "//Description: " << description << '\n'; + } + fout << "//----------------------------------------------------------\n"; + TListIter iter(media); + FairGeoMedium* medium; + Int_t i = 0; + while ((medium = static_cast(iter.Next()))) { + if (medium->getAutoFlag() != 0) { + medium->write(fout); + i++; + } + } + if (i != media->GetSize()) { + iter.Reset(); + fout << "//----------------------------------------------\n"; + fout << "AUTONULL\n"; + fout << "//----------------------------------------------\n"; + while ((medium = static_cast(iter.Next()))) { + if (medium->getAutoFlag() == 0) { + medium->write(fout); + } + } + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoMedium.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoMedium.cxx new file mode 100644 index 0000000000000..2f51ff30a0f38 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoMedium.cxx @@ -0,0 +1,362 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- ö : Ilse Koenig +//*-- Modified : 10/11/2003 by Ilse Koenig + +//////////////////////////////////////////////////////////////////////////////// +// +// Class for tracking medium ( includes also material ) +// +//////////////////////////////////////////////////////////////////////////////// +#include "FairGeoMedium.h" + +#include // for TString +#include // for pow, log +// IWYU pragma: no_include +#include // for INT_MAX +#include // for fstream +#include // for cout +#include // for abs + +using std::cout; +using std::log; +using std::pow; + +ClassImp(FairGeoMedium); + +FairGeoMedium::FairGeoMedium(const char* name) + : TNamed(name, "") + , medId(0) + , autoflag(1) + , nComponents(0) + , weightFac(0) + , ca(nullptr) + , cz(nullptr) + , cw(nullptr) + , density(0) + , radLen(0) + , sensFlag(0) + , fldFlag(0) + , fld(0) + , epsil(0) + , madfld(-1) + , maxstep(-1) + , maxde(-1) + , minstep(-1) + , npckov(0) + , ppckov(nullptr) + , absco(nullptr) + , effic(nullptr) + , rindex(nullptr){ + // Constructor for a medium with name and index id + // SetName(name); + }; + +FairGeoMedium::~FairGeoMedium() +{ + // Destructor + if (nComponents > 0) { + delete[] ca; + ca = 0; + delete[] cz; + cz = 0; + delete[] cw; + cw = 0; + nComponents = 0; + } + if (npckov > 0) { + delete[] ppckov; + ppckov = 0; + delete[] absco; + absco = 0; + delete[] effic; + effic = 0; + delete[] rindex; + rindex = 0; + npckov = 0; + } +} + +void FairGeoMedium::setNComponents(Int_t n) +{ + // Sets the number of components in the material + if (n == 0) { + return; + } + Int_t k = abs(n); + if (nComponents != 0 && k != nComponents) { + delete[] ca; + delete[] cz; + delete[] cw; + nComponents = 0; + } + if (nComponents == 0) { + nComponents = k; + ca = new Double_t[k]; + cz = new Double_t[k]; + cw = new Double_t[k]; + } + weightFac = static_cast(n / nComponents); +} + +Bool_t FairGeoMedium::setComponent(Int_t i, Double_t a, Double_t z, Double_t weight) +{ + // Defines the ith material component + if (i < 0 || i >= nComponents) { + Error("setNComponents", "Wrong index"); + return kFALSE; + } + ca[i] = a; + cz[i] = z; + cw[i] = weight; + return kTRUE; +} + +void FairGeoMedium::getComponent(Int_t i, Double_t* p) +{ + // Returns the ith material component + if (i >= 0 && i < nComponents) { + p[0] = ca[i]; + p[1] = cz[i]; + p[2] = cw[i]; + // cout << " -I p: " << p[0] << p[1] << p[2] << endl; + } else { + p[0] = p[1] = p[2] = 0.; + } +} + +void FairGeoMedium::setNpckov(Int_t n) +{ + // Sets the number of optical parameters for the tracking of Cerenkov light + if (n != npckov && npckov > 0) { + delete[] ppckov; + delete[] absco; + delete[] effic; + delete[] rindex; + } + npckov = n; + if (n > 0) { + ppckov = new Double_t[npckov]; + absco = new Double_t[npckov]; + effic = new Double_t[npckov]; + rindex = new Double_t[npckov]; + } +} + +Bool_t FairGeoMedium::setCerenkovPar(Int_t i, Double_t p, Double_t a, Double_t e, Double_t r) +{ + // Defines the ith parameter set of the optical parameters + if (i < 0 || i >= npckov) { + Error("setNpckov", "Wrong index"); + return kFALSE; + } + ppckov[i] = p; + absco[i] = a; + effic[i] = e; + rindex[i] = r; + return kTRUE; +} + +void FairGeoMedium::getCerenkovPar(Int_t i, Double_t* p) +{ + // returns the ith parameter set of the optical parameters + if (i >= 0 && i < npckov) { + p[0] = ppckov[i]; + p[1] = absco[i]; + p[2] = effic[i]; + p[3] = rindex[i]; + } else { + p[0] = p[1] = p[2] = p[3] = 0.; + } +} + +void FairGeoMedium::setMediumPar(Int_t sensitivityFlag, + Int_t fieldFlag, + Double_t maxField, + Double_t precision, + Double_t maxDeviation, + Double_t maxStep, + Double_t maxDE, + Double_t minStep) +{ + // Sets the medium parameters + sensFlag = sensitivityFlag; + fldFlag = fieldFlag; + fld = maxField; + epsil = precision; + madfld = maxDeviation; + maxstep = maxStep; + maxde = maxDE; + minstep = minStep; +} + +void FairGeoMedium::getMediumPar(Double_t* params) +{ + // Returns the medium parameters + params[0] = sensFlag; + params[1] = fldFlag; + params[2] = fld; + params[3] = madfld; + params[4] = maxstep; + params[5] = maxde; + params[6] = epsil; + params[7] = minstep; + params[8] = 0.; + params[9] = 0.; +} + +void FairGeoMedium::read(std::fstream& fin, Int_t aflag) +{ + // Reads the parameters from file + autoflag = aflag; + Int_t n; + fin >> n; + setNComponents(n); + for (Int_t ik = 0; ik < nComponents; ik++) { + fin >> ca[ik]; + } + for (Int_t i = 0; i < nComponents; i++) { + fin >> cz[i]; + } + fin >> density; + if (nComponents == 1) { + cw[0] = 1.; + calcRadiationLength(); + } else { + for (Int_t i = 0; i < nComponents; i++) { + fin >> cw[i]; + } + } + fin >> sensFlag >> fldFlag >> fld >> epsil; + if (autoflag < 1) { + fin >> madfld >> maxstep >> maxde >> minstep; + } else { + // to use this feature one has to set TGeant3::SetAUTO(0), thus if the media does not + // defined these values one can force Geant3 to calculate them by given them a value + // of -1 + madfld = -1; + maxstep = -1; + maxde = -1; + minstep = -1; + } + fin >> n; + if (n > 0 && n < (INT_MAX - 1)) { + setNpckov(n); + // if (n>0) { + for (Int_t i = 0; i < n; i++) { + fin >> ppckov[i] >> absco[i] >> effic[i] >> rindex[i]; + } + } +} + +void FairGeoMedium::print() +{ + // Prints the medium definition + const char* bl = " "; + cout << GetName() << '\n' << nComponents * weightFac << bl; + for (Int_t ii = 0; ii < nComponents; ii++) { + cout << ca[ii] << bl; + } + for (Int_t j = 0; j < nComponents; j++) { + cout << cz[j] << bl; + } + cout << density << bl; + if (nComponents < 2) { + cout << radLen; + } else + for (Int_t iik = 0; iik < nComponents; iik++) { + cout << cw[iik] << bl; + } + cout << '\n' << sensFlag << bl << fldFlag << bl << fld << bl << epsil << '\n'; + if (autoflag < 1) { + cout << madfld << bl << maxstep << bl << maxde << bl << minstep << '\n'; + } + cout << npckov << '\n'; + if (npckov > 0) { + for (Int_t i = 0; i < npckov; i++) { + cout << ppckov[i] << bl << absco[i] << bl << effic[i] << bl << rindex[i] << '\n'; + } + } + cout << '\n'; +} + +void FairGeoMedium::write(std::fstream& fout) +{ + // Writes the medium definition into stream + const char* bl = " "; + fout << GetName() << '\n' << nComponents * weightFac << bl; + for (Int_t i = 0; i < nComponents; i++) { + fout << ca[i] << bl; + } + for (Int_t j = 0; j < nComponents; j++) { + fout << cz[j] << bl; + } + fout << density << bl; + if (nComponents < 2) { + fout << radLen; + } else + for (Int_t i = 0; i < nComponents; i++) { + fout << cw[i] << bl; + } + fout << '\n' << sensFlag << bl << fldFlag << bl << fld << bl << epsil << '\n'; + if (autoflag < 1) { + fout << madfld << bl << maxstep << bl << maxde << bl << minstep << '\n'; + } + fout << npckov << '\n'; + if (npckov > 0) { + for (Int_t i = 0; i < npckov; i++) { + fout << ppckov[i] << bl << absco[i] << bl << effic[i] << bl << rindex[i] << '\n'; + } + } + fout << '\n'; +} + +Bool_t FairGeoMedium::calcRadiationLength() +{ + // calculates radiation length + // formula in GEANT manual CONS110 + if (cz[0] < 1.e-6) { // VAKUUM$ + radLen = 1.e+16; + return kTRUE; + } + Double_t alpha = 1 / 137.; // fine structure constant + Double_t fac = .1912821; // 4*((electron radius)**2)*(avogadro's number) + Double_t z, a, w, az2, fc, y, xi, x0i, amol = 0., x0itot = 0.; + if (weightFac > 0) { + amol = 1.; + } else { + for (int i = 0; i < nComponents; i++) { + amol += cw[i] * ca[i]; + if (amol == 0.) { + Error("calcRadiationLength()", "amol==0 for medium %s", fName.Data()); + return kFALSE; + } + } + } + for (int i = 0; i < nComponents; i++) { + z = cz[i]; + a = ca[i]; + if (weightFac > 0) { + w = cw[i] / amol; + } else { + w = a * cw[i] / amol; + } + az2 = alpha * alpha * z * z; + fc = az2 * (1. / (1. + az2) + 0.20206 - 0.0369 * az2 + 0.0083 * az2 * az2 - .002F * az2 * az2 * az2); + y = log(183. / pow(z, 1. / 3.)) - fc; + xi = static_cast(log(1440. / pow(z, 2. / 3.)) / y); + x0i = fac * alpha / a * z * (z + xi) * y; + x0itot += (x0i * w); + } + if (x0itot == 0. || density == 0.) { + Error("calcRadiationLength()", "x0itot=0 or density=0 for medium %s", fName.Data()); + return kFALSE; + } + radLen = 1 / density / x0itot; + return kTRUE; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoNode.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoNode.cxx new file mode 100644 index 0000000000000..bec67893c6282 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoNode.cxx @@ -0,0 +1,432 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 10/11/2003 +//*---Modified: 21/06/2005 D.Bertini + +//////////////////////////////////////////////////////////////// +// FairGeoNode +// +// Class to hold the basic geometry properties of a GEANT volume +// +//////////////////////////////////////////////////////////////// +#include "FairGeoNode.h" + +#include "FairGeoRotation.h" // for FairGeoRotation +#include "FairGeoVector.h" // for FairGeoVector + +#include // for TList +#include // IWYU pragma: keep for abs +// IWYU pragma: no_include +#include // for sscanf +#include +#include // for operator<<, basic_ostream, etc + +using std::cout; +using std::endl; + +ClassImp(FairGeoNode); + +FairGeoNode::FairGeoNode() + : FairGeoVolume() + , active(kFALSE) + , center(FairGeoTransform()) + , volumeType(kFairGeoElement) + , created(kFALSE) + , copyNode(nullptr) + , rootVolume(nullptr) + , pShape(0) + , pMother(nullptr) + , medium(nullptr) + , labTransform(nullptr) + , fDaughterList(new TObjArray(5)) + , fTruncName("") +{ + // Constructor + clear(); +} + +FairGeoNode::FairGeoNode(FairGeoNode& r) + : FairGeoVolume(r) + , active(kFALSE) + , center(r.getCenterPosition()) + , volumeType(r.getVolumeType()) + , created(kFALSE) + , copyNode(r.getCopyNode()) + , rootVolume(r.getRootVolume()) + , pShape(nullptr) + , pMother(nullptr) + , medium(nullptr) + , labTransform(new FairGeoTransform(*(r.getLabTransform()))) + , fDaughterList(new TObjArray(*(r.GetListOfDaughters()))) + , fTruncName(r.getTruncName()) +{ + // Copy constructor + points = 0; + nPoints = 0; + fName = r.GetName(); + setVolumePar(r); + if (r.isActive()) { + active = kTRUE; + } + if (r.isCreated()) { + created = kTRUE; + } +} + +FairGeoNode::~FairGeoNode() +{ + // Destructor + if (points) { + for (Int_t i = 0; i < nPoints; i++) { + points->RemoveAt(i); + } + delete points; + points = 0; + } + if (labTransform) { + delete labTransform; + labTransform = 0; + } + if (fDaughterList) { + fDaughterList->Delete(); + delete fDaughterList; + } +} + +void FairGeoNode::setVolumePar(FairGeoNode& r) +{ + // Copies all volume parameters except the name + setMother(r.getMotherNode()); + medium = r.getMedium(); + setShape(r.getShapePointer()); + Int_t n = r.getNumPoints(); + createPoints(n); + for (Int_t i = 0; i < nPoints; i++) { + setPoint(i, *(r.getPoint(i))); + } + transform = r.getTransform(); +} + +void FairGeoNode::clear() +{ + // Clears the volume and deletes the points + /* pMother=0; + medium=0; + pShape=0; + volumeType=kFairGeoElement; + active=kFALSE; + created=kFALSE; + copyNode=0; + rootVolume=0; + */ + if (labTransform) { + delete labTransform; + labTransform = 0; + } + FairGeoVolume::clear(); +} + +Int_t FairGeoNode::getCopyNo() +{ + // Returns the copy number + Int_t n = 0; + if (fHadFormat == 1) { + Int_t l = fName.Length(); + if (l > 4) { + TString s(fName); + s.Remove(0, 4); + sscanf(s.Data(), "%i", &n); + } + } else { + + Ssiz_t l = fName.Last('#'); + if (l > 0) { + TString s(fName); + s.Remove(0, l + 1); + sscanf(s.Data(), "%i", &n); + } + } + + return n; +} + +TArrayD* FairGeoNode::getParameters() +{ + // Returns the parameters to create a GEANT/ROOT volume + if (pShape) { + return pShape->calcVoluParam(this); + } + return 0; +} + +FairGeoTransform* FairGeoNode::getPosition() +{ + // Returns the transformation to position a volume in GEANT/ROOT + if (pShape && pMother) { + pShape->calcVoluPosition(this, pMother->getCenterPosition()); + center.setTransform(*(pShape->getCenterPosition())); + return pShape->getVoluPosition(); + } + return 0; +} + +void FairGeoNode::print() +{ + // Prints all parameters of a volume + cout << "//----------------------------------------------------------\n"; + FairGeoVolume::print(); + cout << "//----------------------------------------------------------\n"; + return; + + /* + cout<<((const char*)fName)<<'\n'; + if (pMother) { cout<<((const char*)mother)<<'\n'; } + else { cout<<"-- unknown mother --\n"; } + if (!copyNode) { + if (pShape) { cout<<((const char*)shape)<<'\n'; } + else { cout<<"-- unknown shape --\n"; } + if (medium) { cout<GetName()<<'\n'; } + else { cout<<"-- unknown medium --\n"; } + if (points && pShape) { pShape->printPoints(this); } + else { cout<<"-- no points --\n"; } + } + transform.getTransVector().print(); + transform.getRotMatrix().print(); + cout<<"//----------------------------------------------------------\n"; + */ +} + +Bool_t FairGeoNode::write(std::fstream& fout) +{ + // Writes all parameters of a volume to file + fout << fName.Data() << '\n'; + if (pMother) { + fout << (const_cast(mother.Data())) << '\n'; + } else { + Error("write", "Unknown mother for %s\n", fName.Data()); + return kFALSE; + } + if (!copyNode) { + if (pShape) { + fout << (const_cast(shape.Data())) << '\n'; + } else { + Error("write", "Unknown shape for %s\n", fName.Data()); + return kFALSE; + } + if (medium) { + fout << medium->GetName() << '\n'; + } else { + Error("write", "Unknown medium for %s\n", fName.Data()); + return kFALSE; + } + if (points && pShape) { + pShape->writePoints(&fout, this); + } else { + Error("write", "No points for %s\n", fName.Data()); + return kFALSE; + } + } + const FairGeoRotation& r = transform.getRotMatrix(); + const FairGeoVector& v = transform.getTransVector(); + fout.precision(3); + fout << v(0) << " " << v(1) << " " << v(2) << '\n'; + fout.precision(7); + for (Int_t i = 0; i < 9; i++) { + fout << r(i) << " "; + } + fout << '\n'; + fout << "//----------------------------------------------------------\n"; + return kTRUE; +} + +TList* FairGeoNode::getTree() +{ + // Returns the tree of the mother volumes + TList* tree = new TList(); + FairGeoNode* v = this; + FairGeoNode* lmother; + do { + lmother = v->getMotherNode(); + if (lmother) { + tree->Add(lmother); + } + v = lmother; + } while (v && !v->isTopNode()); + return tree; +} + +FairGeoTransform* FairGeoNode::getLabTransform() +{ + // Returns the lab transformation + if (labTransform) { + return labTransform; + } else { + return calcLabTransform(); + } +} + +FairGeoTransform* FairGeoNode::calcLabTransform() +{ + // Calculates the lab transformation + + labTransform = new FairGeoTransform(transform); + + if (!isTopNode()) { + if (!pMother) { + Error("calcLabTransform()", "Mother volume of %s not found!", GetName()); + delete labTransform; + return 0; + } + FairGeoTransform* tm = pMother->getLabTransform(); + if (!tm) { + ; + Error("calcLabTransform()", "Lab Transformation of mother volume of %s not found!", GetName()); + delete labTransform; + return 0; + } + labTransform->transFrom(*tm); + } + + fLabTransform = *labTransform; + fMedium = *medium; + return labTransform; +} + +void FairGeoNode::setLabTransform(FairGeoTransform& t) +{ + // Sets the lab transformation + if (!isTopNode()) { + if (labTransform) { + labTransform->setTransform(t); + } else { + labTransform = new FairGeoTransform(t); + } + if (!pMother) { + Error("calcLabTransform()", "Mother volume of %s not found!", GetName()); + delete labTransform; + return; + } + FairGeoTransform* tm = pMother->getLabTransform(); + if (!tm) { + ; + Error("calcLabTransform()", "Lab Transformation of mother volume of %s not found!", GetName()); + delete labTransform; + return; + } + transform = t; + transform.transTo(*tm); + } +} + +Bool_t FairGeoNode::calcModuleTransform(FairGeoTransform& modTransform) +{ + // Calculates the transformation relative to the detectors coordinate system + FairGeoNode* node = this; + modTransform = transform; + while (node && !node->isModule()) { + FairGeoNode* pm = node->getMotherNode(); + if (!pm) { + Error("calcModuleTransform", "Mother volume of %s not found!", node->GetName()); + return kFALSE; + } + modTransform.transFrom(pm->getTransform()); + node = pm; + } + if (isTopNode()) { + return kFALSE; + } else { + return kTRUE; + } +} + +Bool_t FairGeoNode::calcRefPos(FairGeoVector& refPos) +{ + // Calculates the position in the detectors coordinate system + FairGeoNode* node = this; + refPos = center.getTransVector(); + do { + refPos = node->getTransform().transFrom(refPos); + node = node->getMotherNode(); + if (!node) { + Error("calcModuleTransform", "Mother of volume %s not found!", GetName()); + return kFALSE; + } + } while (node && !node->isModule()); + if (isTopNode()) { + return kFALSE; + } else { + return kTRUE; + } +} + +Int_t FairGeoNode::compare(FairGeoNode& rn) +{ + // Compares the volume with the volume rn and prints the diagnose + // Returns kTRUE if the volume parameters are the same + Int_t diff[] = {0, 0, 0, 0, 0, 0}; + Int_t n = 0; + cout << fName << '\t'; + if (mother.CompareTo(rn.getMother()) != 0) { + diff[0] = 1; + n++; + } + if (medium && rn.getMedium()) { + TString med = medium->GetName(); + if (med.CompareTo(rn.getMedium()->GetName()) != 0) { + diff[1] = 1; + n++; + } + } else { + diff[1] = 1; + n++; + } + if (shape.CompareTo(rn.getShape()) != 0) { + diff[2] = 1; + n++; + } + Int_t np = rn.getNumPoints(); + if (points && nPoints == np) { + for (Int_t i = 0; i < np; i++) { + FairGeoVector v1 = *(getPoint(i)); + FairGeoVector v2 = *(rn.getPoint(i)); + if (fabs(v1(0) - v2(0)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001) { + diff[3] = 1; + n++; + break; + } + } + } else { + diff[3] = 1; + n++; + } + FairGeoVector v1 = transform.getTransVector(); + FairGeoVector v2 = rn.getTransform().getTransVector(); + if (fabs(v1(0) - v2(0)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001 || fabs(v1(1) - v2(1)) >= 0.001) { + diff[4] = 1; + n++; + } + FairGeoRotation r1 = transform.getRotMatrix(); + FairGeoRotation r2 = rn.getTransform().getRotMatrix(); + for (Int_t i = 0; i < 9; i++) { + if (fabs(r1(i) - r2(i)) >= 1.e-7) { + diff[5] = 1; + n++; + break; + } + } + if (n > 0) { + for (Int_t i = 0; i < 6; i++) { + cout << " " << diff[i] << " "; + } + cout << '\n'; + } else { + cout << " same\n"; + } + return n; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoPcon.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoPcon.cxx new file mode 100644 index 0000000000000..842b650829893 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoPcon.cxx @@ -0,0 +1,177 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 26/11/2001 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoPcon +// +// class for the GEANT shape PCON +// +// The size of a PCON is defined by a variable number of 'points'. +// point 0: number of planes perpendicular to the z axis where the +// dimension of the section is given; +// point 1: azimutal angle phi at which the volume begins, +// opening angle dphi of the volume, +// (z-component not used) +// point 2ff: z coordinate of the section, +// inner radius at position z, +// outer radius at position z; +// +// The intrinsic coordinate system of a PCON, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoPcon.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for TString +#include +#include // for fstream, etc +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoPcon); + +FairGeoPcon::FairGeoPcon() + : FairGeoBasicShape() +{ + // constructor + fName = "PCON"; + nPoints = 0; + nParam = 0; +} + +FairGeoPcon::~FairGeoPcon() +{ + // default destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +Int_t FairGeoPcon::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 'points' decribed above from ascii file and stores them in the + // array 'points' of the volume + // returns the number of points + if (!pFile) { + return 0; + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + pFile->getline(buf, maxbuf); + Int_t n; + sscanf(buf, "%i", &n); + if (n <= 0) { + return 0; + } + nPoints = n + 2; + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + volu->setPoint(0, static_cast(n), 0.0, 0.0); + for (Int_t i = 1; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + if (i != 1) { + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + } else { + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + } + return nPoints; +} + +Bool_t FairGeoPcon::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < volu->getNumPoints(); i++) { + FairGeoVector& v = *(volu->getPoint(i)); + switch (i) { + case 0: + sprintf(buf, "%3i\n", static_cast(v(0))); + break; + case 1: + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + break; + default: + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoPcon::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < volu->getNumPoints(); i++) { + FairGeoVector& v = *(volu->getPoint(i)); + switch (i) { + case 0: + printf("%3i\n", static_cast(v(0))); + break; + case 1: + printf("%9.3f%10.3f\n", v(0), v(1)); + break; + default: + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } + } +} + +TArrayD* FairGeoPcon::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape PCON + Double_t fac = 10.; + nPoints = volu->getNumPoints(); + nParam = (nPoints - 1) * 3; + if (param && param->GetSize() != nParam) { + delete param; + param = 0; + } + if (!param) { + param = new TArrayD(nParam); + } + FairGeoVector& v1 = *(volu->getPoint(1)); + Int_t k = 0; + param->AddAt(v1(0), k++); + param->AddAt(v1(1), k++); + param->AddAt((nPoints - 2), k++); + for (Int_t i = 2; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + param->AddAt(v(0) / fac, k++); + param->AddAt(v(1) / fac, k++); + param->AddAt(v(2) / fac, k++); + } + return param; +} + +void FairGeoPcon::calcVoluPosition(FairGeoVolume*, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + center->clear(); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoPgon.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoPgon.cxx new file mode 100644 index 0000000000000..567eb325e7be0 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoPgon.cxx @@ -0,0 +1,163 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 26/11/2001 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoPgon +// +// class for the GEANT shape PGON +// +// The size of a PGON is defined by a variable number of 'points'. +// point 0: number of planes perpendicular to the z axis where the +// dimension of the section is given; +// point 1: azimutal angle phi at which the volume begins, +// opening angle dphi of the volume, +// number of sides of the cross section between the phi-limits; +// point 2ff: z coordinate of the section, +// inner radius at position z, +// outer radius at position z; +// +// The intrinsic coordinate system of a PGON, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoPgon.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for TString +#include +#include // for basic_ostream::write +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoPgon); + +FairGeoPgon::FairGeoPgon() + : FairGeoBasicShape() +{ + // constructor + fName = "PGON"; + nPoints = 0; + nParam = 0; +} + +FairGeoPgon::~FairGeoPgon() +{ + // default destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +Int_t FairGeoPgon::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 'points' decribed above from ascii file and stores them in the + // array 'points' of the volume + // returns the number of points + if (!pFile) { + return 0; + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + pFile->getline(buf, maxbuf); + Int_t n; + sscanf(buf, "%i", &n); + if (n <= 0) { + return 0; + } + nPoints = n + 2; + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + volu->setPoint(0, static_cast(n), 0.0, 0.0); + for (Int_t i = 1; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + } + return nPoints; +} + +Bool_t FairGeoPgon::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < volu->getNumPoints(); i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i != 0) { + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + sprintf(buf, "%3i\n", static_cast(v(0))); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoPgon::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < volu->getNumPoints(); i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i != 0) { + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + printf("%3i\n", static_cast(v(0))); + } + } +} + +TArrayD* FairGeoPgon::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape PGON + Double_t fac = 10.; + nPoints = volu->getNumPoints(); + nParam = nPoints * 3 - 2; + if (param && param->GetSize() != nParam) { + delete param; + param = 0; + } + if (!param) { + param = new TArrayD(nParam); + } + FairGeoVector& v1 = *(volu->getPoint(1)); + Int_t k = 0; + param->AddAt(v1(0), k++); + param->AddAt(v1(1), k++); + param->AddAt(v1(2), k++); + param->AddAt((nPoints - 2), k++); + for (Int_t i = 2; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + param->AddAt(v(0) / fac, k++); + param->AddAt(v(1) / fac, k++); + param->AddAt(v(2) / fac, k++); + } + return param; +} + +void FairGeoPgon::calcVoluPosition(FairGeoVolume*, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + center->clear(); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoRootBuilder.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoRootBuilder.cxx new file mode 100644 index 0000000000000..7fef0ac41ac98 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoRootBuilder.cxx @@ -0,0 +1,210 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 10/11/03 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoRootBuilder +// +// Class to create the geometry in ROOT +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoRootBuilder.h" + +#include "FairGeoMedium.h" // for FairGeoMedium +#include "FairGeoNode.h" // for FairGeoNode +#include "FairGeoRotation.h" // for FairGeoRotation +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector + +#include // for TArrayD +#include // for TGeoManager +#include // for TGeoMixture, TGeoMaterial +#include // for TGeoCombiTrans, etc +#include // for TGeoMedium +#include // for TGeoVolume, etc +#include // for TString +#include // for sprintf +#include + +ClassImp(FairGeoRootBuilder); + +FairGeoRootBuilder::FairGeoRootBuilder() + : FairGeoBuilder() + , geoManager(nullptr) +{ + // Default constructor +} + +FairGeoRootBuilder::FairGeoRootBuilder(const char* name, const char* title) + : FairGeoBuilder(name, title) + , geoManager(nullptr) +{ + // Constructor +} + +Bool_t FairGeoRootBuilder::createNode(FairGeoNode* volu, Int_t hadFormat) +{ + // Creates the volume + if (!geoManager || !volu) { + return kFALSE; + } + // volu->print(); + + TString nodeName = volu->GetName(); + if (hadFormat == 1) { + volu->setHadFormat(hadFormat); + nodeName = nodeName(0, 4); + } else { + nodeName = (volu->GetName()); + Ssiz_t l = nodeName.Last('#'); + if (l > 0) { + nodeName = nodeName(0, l); + } + } + + FairGeoNode* mother = volu->getMotherNode(); + if (!mother && !volu->isTopNode()) { + Error("createNode", "Mother volume of %s not found\n", volu->GetName()); + return kFALSE; + } + + TGeoVolume* rv = 0; + FairGeoNode* cv = volu->getCopyNode(); + // if (cv) cout<<"Copy of "<GetName()<getRootVolume(); + } + if (!rv) { + FairGeoMedium* lmedium = volu->getMedium(); + Int_t lnMed = lmedium->getMediumIndex(); + if (lnMed <= 0) { + lnMed = createMedium(lmedium); + } + if (lnMed <= 0) { + return kFALSE; + } + TArrayD* par = volu->getParameters(); + // for (Int_t k=0;kGetSize();k++) cout<At(k)<<" "; + // cout<getShape() << endl; + if (volu->getShape().Contains("TORUS")) { // Torus is missing in the TGeoManager::Volume + // this should solve the problem tell it is implimented in root + TGeoMedium* medium = geoManager->GetMedium(lnMed); + rv = geoManager->MakeTorus( + nodeName.Data(), medium, par->At(0), par->At(1), par->At(2), par->At(3), par->At(4)); + // cout << "Create Torus" << nodeName.Data() << endl; + } else if (volu->getShape().Contains("ASSEMBLY")) { + rv = geoManager->MakeVolumeAssembly(nodeName.Data()); + + } else { + rv = geoManager->Volume(nodeName.Data(), volu->getShape().Data(), lnMed, par->GetArray(), par->GetSize()); + } + volu->setCreated(); + if (volu->isModule() && cv) { + cv->setCreated(); + cv->setRootVolume(rv); + cv->getPosition(); + } + } + if (!rv) { + return kFALSE; + } + volu->setRootVolume(rv); + if (volu->isTopNode()) { + geoManager->SetTopVolume(rv); + } else { + FairGeoTransform* trans = volu->getPosition(); + const FairGeoRotation& rot = trans->getRotMatrix(); + const FairGeoVector& pos = trans->getTransVector(); + TGeoMatrix* tr = 0; + if ((const_cast(rot)).isUnitMatrix()) { + tr = new TGeoTranslation(pos.getX(), pos.getY(), pos.getZ()); + } else { + nRot++; + char b[13]; + snprintf(b, sizeof(b), "R%i", nRot); + TGeoRotation* r = new TGeoRotation(b); + Double_t a[9]; + for (Int_t i = 0; i < 9; i++) { + a[i] = rot(i); + } + r->SetMatrix(a); + tr = new TGeoCombiTrans(pos.getX(), pos.getY(), pos.getZ(), r); + } + TGeoVolume* mo = mother->getRootVolume(); + if (!mo) { + return kFALSE; + } + mo->AddNode(rv, volu->getCopyNo(), tr); + } + return kTRUE; +} + +Int_t FairGeoRootBuilder::createMedium(FairGeoMedium* med) +{ + // Creates the medium + if (!geoManager && !med) { + return 0; + } + Int_t nComp = med->getNComponents(); + Int_t weightFac = med->getWeightFac(); + TGeoMaterial* material = 0; + Double_t p[3]; + if (nComp == 1) { + med->getComponent(0, p); + material = new TGeoMaterial(med->GetName(), p[0], p[1], med->getDensity(), med->getRadiationLength()); + // Interaction length not defined!!!!!! + } else { + material = new TGeoMixture(med->GetName(), nComp, med->getDensity()); + Double_t sumWeights = 0.; + if (weightFac < 0) { + for (Int_t i = 0; i < nComp; i++) { + med->getComponent(i, p); + sumWeights += p[0] * p[2]; + } + } + for (Int_t i = 0; i < nComp; i++) { + med->getComponent(i, p); + if (weightFac > 0) { + (static_cast(material))->DefineElement(i, p[0], p[1], p[2]); + } else { + (static_cast(material))->DefineElement(i, p[0], p[1], p[0] * p[2] / sumWeights); + } + } + } + nMed++; + med->setMediumIndex(nMed); + Double_t mp[10]; + med->getMediumPar(mp); + TGeoMedium* medium = new TGeoMedium(med->GetName(), nMed, material, mp); + if (medium) { + return nMed; + } else { + return 0; + } +} + +void FairGeoRootBuilder::finalize() +{ + // Closes the geometry input in ROOT and draws the cave + if (geoManager) { + geoManager->CloseGeometry(); + geoManager->SetVisLevel(5); + geoManager->GetTopVolume()->Draw(); + } +} + +void FairGeoRootBuilder::checkOverlaps(Double_t ovlp) +{ + // Checks the geometry for overlaps and extrusions wit a default precision of 1 micron + if (geoManager) { + geoManager->CheckOverlaps(ovlp, "SAME"); + geoManager->PrintOverlaps(); + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoRotation.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoRotation.cxx new file mode 100644 index 0000000000000..48821b0c61ecf --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoRotation.cxx @@ -0,0 +1,137 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 16/06/99 + +/////////////////////////////////////////////////////////////////////////////// +// FairGeoRotation +// +// This class defines a 3x3 rotation matrix. +// The data are stored in a linear array with 9 Double_t +// components. +// +// Inline functions: +// +// Constructors: +// FairGeoRotation() +// FairGeoRotation(const FairGeoRotation& r) +// FairGeoRotation(const Double_t* a) +// +// Access to components: +// Double_t operator () (Int_t) const +// void setElement(const Double_t,const Int_t) +// +// Check for equality/inequality +// Bool_t operator == (const FairGeoRotation&) +// Bool_t operator != (const FairGeoRotation&) +// +// FairGeoRotation& operator = (const FairGeoRotation&); +// assignment +// +// void setUnitMatrix() +// sets identity matrix +// +// void setZero() +// sets all components to 0.0 +// +// Bool_t isUnitMatrix() +// checks unity +// +// FairGeoRotation& invert() +// inverts the matrix +// +// FairGeoRotation inverse() +// copies the matrix and returns the inverse of the copy +// +// Double_t determinant() const; +// returns determinate +// +// FairGeoRotation& operator *= (const FairGeoRotation&); +// multiplies with the given rotation matrix from the right +// +// FairGeoRotation& transform(const FairGeoRotation&); +// multiplies with the given rotation matrix from the left +// +// FairGeoVector operator * (const FairGeoVector&) const; +// rotates a vector +// +// FairGeoRotation operator * (const FairGeoRotation&) const; +// rotates the given rotation +// +// void print() +// shows the matrix +// +// +// Euler Angles: +// 1. angle: rotation around z-axis --> x1, y1, z1=z +// 2. angle: rotation around y1-axis --> x2, y2=y1, z2 +// 3. angle: rotation around z2-axis --> x3, y3, z3=z2 +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoRotation.h" + +#include // for Cos, Sin +#include // for TRotMatrix + +ClassImp(FairGeoRotation); + +FairGeoRotation::FairGeoRotation(const Double_t a, const Double_t b, const Double_t c) + : TObject() +{ + // constructor taking three Euler angles + setEulerAngles(a, b, c); +} + +void FairGeoRotation::setEulerAngles(const Double_t a, const Double_t b, const Double_t c) +{ + // sets the matrix calculating the values from the given Euler angles + const double deg2rad = 0.01745329252; + Double_t s0 = TMath::Sin(a * deg2rad); + Double_t c0 = TMath::Cos(a * deg2rad); + Double_t s1 = TMath::Sin(b * deg2rad); + Double_t c1 = TMath::Cos(b * deg2rad); + Double_t s2 = TMath::Sin(c * deg2rad); + Double_t c2 = TMath::Cos(c * deg2rad); + rot[0] = c0 * c1 * c2 - s0 * s2; + rot[1] = -c0 * c1 * s2 - s0 * c2; + rot[2] = c0 * s1; + rot[3] = s0 * c1 * c2 + c0 * s2; + rot[4] = c0 * c2 - s0 * c1 * s2; + rot[5] = s0 * s1; + rot[6] = -s1 * c2; + rot[7] = s1 * s2; + rot[8] = c1; +} + +Double_t FairGeoRotation::diff2(const FairGeoRotation& r) const +{ + // calculates the square of the difference between 2 matrices + Double_t s = 0; + for (Int_t i = 0; i < 9; i++) { + Double_t d = rot[i] - r(i); + s += d * d; + } + return s; +} + +TRotMatrix* FairGeoRotation::createTRotMatrix(const Text_t* name, const Text_t* title) +{ + // creates a TRotMatrix + // (uses a new() operator and the user has to take care to free the memory) + TRotMatrix* t = 0; + if (isUnitMatrix() == kTRUE) { + return t; + } + Double_t a[9]; + for (Int_t i = 0; i < 3; i++) { + for (Int_t j = 0; j < 3; j++) { + a[j + 3 * i] = rot[i + 3 * j]; + } + } + t = new TRotMatrix(name, title, a); + return t; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoSet.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoSet.cxx new file mode 100644 index 0000000000000..8429589ad8f16 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoSet.cxx @@ -0,0 +1,523 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Created : 10/11/2003 + +///////////////////////////////////////////////////////////// +// FairGeoSet +// +// Base class for geometry of detector parts +// +///////////////////////////////////////////////////////////// +#include "FairGeoSet.h" + +#include "FairGeoBasicShape.h" // for FairGeoBasicShape +#include "FairGeoBuilder.h" // for FairGeoBuilder +#include "FairGeoMedia.h" // for FairGeoMedia +#include "FairGeoNode.h" // for FairGeoNode, etc +#include "FairGeoShapes.h" // for FairGeoShapes +#include "FairGeoTransform.h" // for FairGeoTransform + +#include // for TArrayI +#include // for TString, operator<< +#include // for isalpha +#include // for fstream +#include // for cout +#include // for strcmp + +class FairGeoMedium; + +using std::cout; +using std::endl; +using std::ios; + +ClassImp(FairGeoSet); + +FairGeoSet::FairGeoSet() + : TNamed() + , hadesGeo(0) + , volumes(new TList()) + , masterNodes(nullptr) + , maxSectors(0) + , maxKeepinVolumes(0) + , maxModules(0) + , modules(nullptr) + , pShapes(nullptr) + , geoFile("") + , author("") + , description("") +{ + // Constructor +} + +FairGeoSet::~FairGeoSet() +{ + // Destructor + delete volumes; + volumes = 0; + delete modules; + modules = 0; +} + +void FairGeoSet::setModules(Int_t s, Int_t* m) +{ + // Stores the modules given in 'm' as active modules in sector 's' + // May be called with s=-1 for detectors not belonging to a sector + if (!modules) { + if (maxSectors == 0 && maxModules > 0) { + modules = new TArrayI(maxModules); + } + if (maxSectors > 0 && maxModules > 0) { + modules = new TArrayI(maxSectors * maxModules); + } + } + Int_t sec = 0; + if (s > 0) { + sec = s; + } + for (Int_t i = 0; i < maxModules; i++) { + if (modules) { + modules->AddAt(m[i], (sec * maxModules + i)); + } + } +} + +Int_t* FairGeoSet::getModules() +{ + // Returns a linear array of all modules + if (modules) { + return modules->GetArray(); + } + return 0; +} + +Int_t FairGeoSet::getModule(Int_t s, Int_t m) +{ + // Returns 1, if the module is not explicitly set inactive + // (in this case it returns 0) + // May be called with s=-1 for detectors not belonging to a sector + if (!modules) { + return 1; + } + if (m < maxModules && s < 0) { + return (*modules)[m]; + } + if (m < maxModules && s < maxSectors) { + return (*modules)[(s * maxModules + m)]; + } + return 0; +} + +Bool_t FairGeoSet::read(std::fstream& fin, FairGeoMedia* media) +{ + // Reads the geometry from file + Int_t s1 = -1, s2 = 0; + if (maxSectors > 0) { + s1 = 0; + s2 = maxSectors; + } + Bool_t rc = kTRUE; + for (Int_t s = s1; s < s2 && rc; s++) { + for (Int_t k = 0; k < maxKeepinVolumes && rc; k++) { + TString keepinName = getKeepinName(s, k); + rc = readKeepIn(fin, media, keepinName); + } + } + for (Int_t m = 0; m < maxModules && rc; m++) { + Bool_t containsActiveModule = kFALSE; + for (Int_t s = s1; s < s2; s++) { + if (getModule(s, m)) { + containsActiveModule = kTRUE; + } + } + TString modName = getModuleName(m); + TString eleName = getEleName(m); + rc = readModule(fin, media, modName, eleName, containsActiveModule); + } + return rc; +} + +void FairGeoSet::readInout(std::fstream& fin) +{ + // Reads the inout flag (in old files) + char c = ' '; + do { + fin.get(c); + } while (c == ' ' || c == '\n'); + if (c != '0' && c != '1') { + fin.putback(c); + } else + do { + fin.get(c); + } while (c != '\n'); + return; +} + +void FairGeoSet::readTransform(std::fstream& fin, FairGeoTransform& tf) +{ + // Reads the transformation from file + Double_t r[9], t[3]; + fin >> t[0] >> t[1] >> t[2]; + for (Int_t i = 0; i < 9; i++) { + fin >> r[i]; + } + tf.setRotMatrix(r); + tf.setTransVector(t); +} + +Bool_t FairGeoSet::readVolumeParams(std::fstream& fin, FairGeoMedia* media, FairGeoNode* volu, TList* refVolumes) +{ + // Reads the volume definition from file + // Int_t hadgeo = 1; + if (volu == 0 || media == 0 || refVolumes == 0) { + return kFALSE; + } + const Int_t maxbuf = 256; + char buf[maxbuf]; + TString name(volu->GetName()); + Int_t nameLength = name.Length(); + Bool_t isCopy = kFALSE; + fin >> buf; + FairGeoNode* mother = 0; + FairGeoCopyNode* refNode = 0; + TString refName; + + if (volu->isKeepin()) { + mother = getMasterNode(buf); + } else if (volu->isModule()) { + mother = getMasterNode(buf); + if (!mother) { + mother = getVolume(buf); + } + if (volu->isActive() && mother) { + mother->setActive(); + } + } else { + mother = getVolume(buf); + if (!mother) { + mother = getMasterNode(buf); + } + } + + volu->setMother(mother); + if (!mother) { + Warning("readVolumeParams", "Mother volume %s not found!", buf); + } + + if (hadesGeo == 1) { + // cout << " read copies in Hades format " << endl; + + if (nameLength > 4) { + char c = ' '; + do { + fin.get(c); + } while (c == ' ' || c == '\n'); + Int_t i = static_cast(c); + fin.putback(c); + + if (!isalpha(i)) { + isCopy = kTRUE; + } + refName = name(0, 4); + refNode = static_cast(refVolumes->FindObject(refName)); + if (!refNode) { + if (isCopy) { + return kFALSE; + } + refVolumes->Add(new FairGeoCopyNode(refName.Data(), volu)); + } else { + FairGeoNode* cn = refNode->pNode; + volu->setCopyNode(cn); + volu->setMedium(cn->getMedium()); + volu->setShape(cn->getShapePointer()); + Int_t n = cn->getNumPoints(); + volu->createPoints(n); + for (Int_t k = 0; k < n; k++) { + volu->setPoint(k, *(cn->getPoint(k))); + } + } + } + + } else { + // cbm format + Ssiz_t l = name.Last('#'); + if (l > 0) { + char c; + do { + fin.get(c); + } while (c == ' ' || c == '\n'); + Int_t i = static_cast(c); + fin.putback(c); + if (!isalpha(i)) { + isCopy = kTRUE; + } + refName = name(0, l); + refNode = static_cast(refVolumes->FindObject(refName)); + if (!refNode) { + if (isCopy) { + return kFALSE; + } + refVolumes->Add(new FairGeoCopyNode(refName.Data(), volu)); + } else { + FairGeoNode* cn = refNode->pNode; + volu->setCopyNode(cn); + volu->setMedium(cn->getMedium()); + volu->setShape(cn->getShapePointer()); + Int_t n = cn->getNumPoints(); + volu->createPoints(n); + for (Int_t k = 0; k < n; k++) { + volu->setPoint(k, *(cn->getPoint(k))); + } + } + } + } + + if (!isCopy) { + fin >> buf; + FairGeoBasicShape* sh = pShapes->selectShape(buf); + if (sh) { + volu->setShape(sh); + } else { + return kFALSE; + } + fin >> buf; + FairGeoMedium* medium = media->getMedium(buf); + if (!medium) { + Error("readVolumeParams", "Medium %s not found in list of media", buf); + return kFALSE; + } + volu->setMedium(medium); + Int_t n = 0; + fin.getline(buf, maxbuf); // to read the end of line + if (sh) { + n = sh->readPoints(&fin, volu); + } + if (n <= 0) { + return kFALSE; + } + } + readTransform(fin, volu->getTransform()); + return kTRUE; +} + +Bool_t FairGeoSet::readKeepIn(std::fstream& fin, FairGeoMedia* media, TString& name) +{ + // Reads the keepin volume from file + fin.clear(); + fin.seekg(0, ios::beg); + FairGeoNode* volu = 0; + Bool_t rc = kTRUE; + TList refVolumes; + const Int_t maxbuf = 256; + char buf[maxbuf]; + while (rc && !volu && !fin.eof()) { + fin >> buf; + if (buf[0] == '/') { + fin.getline(buf, maxbuf); + } else if (!fin.eof()) { + if (strcmp(buf, name) == 0) { + volu = new FairGeoNode; + volu->SetName(buf); + volu->setVolumeType(kFairGeoKeepin); + readInout(fin); + rc = readVolumeParams(fin, media, volu, &refVolumes); + } else { + do { + fin.getline(buf, maxbuf); + } while (!fin.eof() && buf[0] != '/'); + } + } + } + if (rc) { + volumes->Add(volu); + } else { + delete volu; + volu = 0; + } + refVolumes.Delete(); + return rc; +} + +Bool_t FairGeoSet::readModule(std::fstream& fin, + FairGeoMedia* media, + TString& modName, + TString& eleName, + Bool_t containsActiveMod) +{ + // Reads the whole geometry of a module from file + const Int_t maxbuf = 256; + Text_t buf[maxbuf]; + fin.clear(); + fin.seekg(0, ios::beg); + FairGeoNode* volu = 0; + Bool_t rc = kTRUE; + TList refVolumes; + TString name; + while (rc && !fin.eof()) { + fin >> buf; + if (buf[0] == '/') { + fin.getline(buf, maxbuf); + } else if (!fin.eof()) { + // TString name(buf); + name = buf; + if (name.BeginsWith(modName)) { + volu = new FairGeoNode; + volu->SetName(buf); + volu->setVolumeType(kFairGeoModule); + Int_t a = getModule(getSecNumInMod(buf), getModNumInMod(buf)); + if (a > 0) { + volu->setActive(kTRUE); + } else { + volu->setActive(kFALSE); + } + readInout(fin); + rc = readVolumeParams(fin, media, volu, &refVolumes); + if (rc) { + volumes->Add(volu); + } else { + Error("readModule", "Failed for module %s\n", volu->GetName()); + delete volu; + volu = 0; + } + } else if (!eleName.IsNull() && name.BeginsWith(eleName)) { + volu = new FairGeoNode; + volu->SetName(buf); + volu->setVolumeType(kFairGeoElement); + volu->setActive(containsActiveMod); + rc = readVolumeParams(fin, media, volu, &refVolumes); + if (rc) { + volumes->Add(volu); + } else { + Error("readModule", "Failed for %s\n", volu->GetName()); + delete volu; + volu = 0; + } + } else { + do { + fin.getline(buf, maxbuf); + } while (!fin.eof() && buf[0] != '/'); + } + } + } + refVolumes.Delete(); + return rc; +} + +void FairGeoSet::print() +{ + // Prints the geometry + if (!author.IsNull()) { + cout << "//Author: " << author << '\n'; + } + if (!description.IsNull()) { + cout << "//Description: " << description << '\n'; + } + if (!description.IsNull()) { + cout << "//----------------------------------------------------------\n"; + } + std::ios_base::fmtflags tmp = cout.setf(ios::fixed, ios::floatfield); + TListIter iter(volumes); + FairGeoNode* volu; + while ((volu = static_cast(iter.Next()))) { + volu->print(); + } + cout.setf(tmp); +} + +void FairGeoSet::write(std::fstream& fout) +{ + // Writes the volumes to file + if (!author.IsNull()) { + fout << "//Author: " << author << '\n'; + } + if (!description.IsNull()) { + fout << "//Description: " << description << '\n'; + } + fout << "//----------------------------------------------------------\n"; + std::ios_base::fmtflags tmp = fout.setf(ios::fixed, ios::floatfield); + TListIter iter(volumes); + FairGeoNode* volu; + Bool_t rc = kTRUE; + while ((volu = static_cast(iter.Next())) && rc) { + rc = volu->write(fout); + } + fout.setf(tmp); +} + +Bool_t FairGeoSet::create(FairGeoBuilder* builder) +{ + // Creates the geometry + if (!builder) { + return kFALSE; + } + TListIter iter(volumes); + FairGeoNode* volu; + Bool_t rc = kTRUE; + while ((volu = static_cast(iter.Next())) && rc) { + if (volu->isActive()) { + + if (hadesGeo == 1) { + rc = builder->createNode(volu, hadesGeo); + } else { + rc = builder->createNode(volu); + } + if (rc) { + if (volu->isTopNode() || volu->isRefNode()) { + FairGeoNode* n = getMasterNode(volu->GetName()); + if (n) { + n->setCenterPosition(volu->getCenterPosition()); + n->setRootVolume(volu->getRootVolume()); + } + } + } else { + Error("create", "Creation of %s failed!", volu->GetName()); + } + } + } + return rc; +} + +void FairGeoSet::compare(FairGeoSet& rset) +{ + // Compares the geometry parameters and print a diagnose + if (fName.CompareTo(rset.GetName()) != 0) { + Error("compare", "Sets have different type"); + return; + } + TListIter iter(volumes); + FairGeoNode* volu; + Int_t n = 0, nnf = 0, nDiff = 0; + cout << "name\t mother medium shape points pos rot\n"; + cout << "------------------------------------------------\n"; + while ((volu = static_cast(iter.Next()))) { + n++; + FairGeoNode* rNode = rset.getVolume(volu->GetName()); + if (!rNode) { + nnf++; + } else if (volu->compare(*rNode) > 0) { + nDiff++; + } + } + cout << "Number of volumes in first list: " << n << '\n'; + cout << "Number of different volumes: " << nDiff << endl; + cout << "Number of volumes not found in second list: " << nnf << '\n'; + TList* rlist = rset.getListOfVolumes(); + if (rlist->GetSize() != (n - nnf)) { + nnf = 0; + TListIter riter(rlist); + while ((volu = static_cast(riter.Next()))) { + FairGeoNode* rNode = getVolume(volu->GetName()); + if (!rNode) { + nnf++; + } + } + } else { + nnf = 0; + } + cout << "Number of additional volumes in second list: " << nnf << '\n'; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoShapes.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoShapes.cxx new file mode 100644 index 0000000000000..d7157d43b11c3 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoShapes.cxx @@ -0,0 +1,199 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 22/06/2003 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoShapes +// +// Class to manage the GEANT/ROOT geometry shapes +// +// The 3D geometry in ROOT uses the ROOT library geom. +// +// This class holds a list of shape classes (type FairGeoBasicShape). They are +// used by all detectors when reading or writing geometry parameter containers +// to ascii files or to create an event display. This class is instantiated in +// the class HSpectrometer inside the function createDetGeomPar(Text_t* name). +// Every geometry parameter container gets a pointer to it. +// +// The individual shape classes are accessible with the selectShape(...) +// functions. The functions readPoints(...) and writePoints(...) use it +// internally. +// +// In the current version the following shapes are implemented: +// BOX TRAP TRD1 PGON PCON TUBE TUBS CONE CONS SPHE ELTU +// TORUS is added 06.11.06 m.al-turany +// +/////////////////////////////////////////////////////////////////////////////// + +#include "FairGeoShapes.h" + +#include "FairGeoAssembly.h" +#include "FairGeoBasicShape.h" +#include "FairGeoBrik.h" +#include "FairGeoCone.h" +#include "FairGeoCons.h" +#include "FairGeoEltu.h" +#include "FairGeoPcon.h" +#include "FairGeoPgon.h" +#include "FairGeoSphe.h" +#include "FairGeoTorus.h" +#include "FairGeoTrap.h" +#include "FairGeoTrd1.h" +#include "FairGeoTube.h" +#include "FairGeoTubs.h" +#include "FairGeoVolume.h" + +#include +#include // for fstream + +ClassImp(FairGeoShapes); + +FairGeoShapes::FairGeoShapes() + : TObject() + , shapes(new TList()) +{ + // constructor creates empty list of shapes +} + +FairGeoShapes::~FairGeoShapes() +{ + // destructor deletes all shapes + shapes->Delete(); + delete shapes; +} + +FairGeoBasicShape* FairGeoShapes::selectShape(FairGeoVolume* volu) +{ + // returns a pointer to the shape used in the given volume + // calls internally selectShape(TString&) with the name of the shape + // returns NULL if the corresponding shape class is not implemented + const TString& name(volu->getShape()); + return selectShape(name); +} + +FairGeoBasicShape* FairGeoShapes::selectShape(const TString& name) +{ + // returns a pointer to the shape given by name + // creates a shape object and adds it to the list of shapes if + // not existing + // returns NULL if the corresponding shape class is not implemented + TString allShapes[13] = { + "BOX ", "TRAP", "TRD1", "PGON", "PCON", "TUBE", "TUBS", "CONE", "CONS", "SPHE", "ELTU", "TORUS", "ASSEMBLY"}; + TString sName(name); + if (sName.Length() == 3) { + sName += " "; + } + FairGeoBasicShape* s = static_cast(shapes->FindObject(sName)); + if (s) { + return s; + } + Int_t no = -1; + for (Int_t i = 0; i < 13; i++) { + if (sName.CompareTo(allShapes[i]) == 0) { + no = i; + } + } + switch (no) { + case 0: { + s = new FairGeoBrik(); + break; + } + case 1: { + s = new FairGeoTrap(); + break; + } + case 2: { + s = new FairGeoTrd1(); + break; + } + case 3: { + s = new FairGeoPgon(); + break; + } + case 4: { + s = new FairGeoPcon(); + break; + } + case 5: { + s = new FairGeoTube(); + break; + } + case 6: { + s = new FairGeoTubs(); + break; + } + case 7: { + s = new FairGeoCone(); + break; + } + case 8: { + s = new FairGeoCons(); + break; + } + case 9: { + s = new FairGeoSphe(); + break; + } + case 10: { + s = new FairGeoEltu(); + break; + } + case 11: { + s = new FairGeoTorus(); + break; + } + case 12: { + s = new FairGeoAssembly(); + break; + } + default: { + Error("selectShape", "shape %s not implemented", name.Data()); + } + } + if (s) { + shapes->Add(s); + } + return s; +} + +Int_t FairGeoShapes::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the points of the given volume from the Ascii file + // returns the number of points read + // returns 0 if if the corresponding shape class is not implemented + FairGeoBasicShape* s = selectShape(volu); + if (s) { + return s->readPoints(pFile, volu); + } else { + return 0; + } +} + +Bool_t FairGeoShapes::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the points of the given volume to the Ascii file + // return kFALSE if the corresponding shape class is not implemented + FairGeoBasicShape* s = selectShape(volu); + if (s) { + return s->writePoints(pFile, volu); + } else { + return kFALSE; + } +} + +void FairGeoShapes::printPoints(FairGeoVolume* volu) +{ + // writes the points of the given volume to the Ascii file + // return kFALSE if the corresponding shape class is not implemented + FairGeoBasicShape* s = selectShape(volu); + if (s) { + return s->printPoints(volu); + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoSphe.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoSphe.cxx new file mode 100644 index 0000000000000..e58d32d3c08e1 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoSphe.cxx @@ -0,0 +1,136 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 29/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoSphe +// +// class for the GEANT shape SPHE +// +// The size of a SPHE is defined by 3 'points' (The z-components are not used) +// point 0: inner radius of the shell +// outer radius of the shell; +// point 1: starting polar angle of the shell, +// ending polar angle of the shell; +// point 2: starting azimuthal angle of the shell, +// ending azimuthal angle of the shell; ) +// +// The intrinsic coordinate system of a SPHE, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoSphe.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for TString +#include +#include // for basic_ostream::write +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoSphe); + +FairGeoSphe::FairGeoSphe() + : FairGeoBasicShape() +{ + // constructor + fName = "SPHE"; + nPoints = 3; + nParam = 6; + param = new TArrayD(nParam); +} + +FairGeoSphe::~FairGeoSphe() +{ + // default destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +Int_t FairGeoSphe::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 3 'points' decribed above from ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + return nPoints; +} + +Bool_t FairGeoSphe::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 3 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } else { + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + pFile->write(buf, strlen(buf)); + } + return kTRUE; + } +} + +void FairGeoSphe::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + printf("%9.3f%10.3f\n", v(0), v(1)); + } +} + +TArrayD* FairGeoSphe::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape SPHE + Double_t fac = 10.; + FairGeoVector& v0 = *(volu->getPoint(0)); + FairGeoVector& v1 = *(volu->getPoint(1)); + FairGeoVector& v2 = *(volu->getPoint(2)); + param->AddAt(v0(0) / fac, 0); + param->AddAt(v0(1) / fac, 1); + param->AddAt(v1(0), 2); + param->AddAt(v1(1), 3); + param->AddAt(v2(0), 4); + param->AddAt(v2(1), 5); + return param; +} + +void FairGeoSphe::calcVoluPosition(FairGeoVolume*, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + center->clear(); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoTorus.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoTorus.cxx new file mode 100644 index 0000000000000..8b22e20f3d168 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoTorus.cxx @@ -0,0 +1,136 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : M. Al-Turany 06/11/2006 + +///////////////////////////////////////////////////////////// +// +// FairGeoTorus +// +// class for the shape Torus +// A torus has 5 parameters : +// R - axial radius +// Rmin - inner radius +// Rmax - outer radius +// Phi1 - starting phi +// Dphi - phi extent +///////////////////////////////////////////////////////////// +#include "FairGeoTorus.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for TString +#include +#include // for basic_ostream::write +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoTorus); + +FairGeoTorus::FairGeoTorus() + : FairGeoBasicShape() +{ + // constructor + fName = "TORUS"; + nPoints = 5; + nParam = 5; + param = new TArrayD(nParam); +} + +FairGeoTorus::~FairGeoTorus() +{ + // destructor + if (param) { + delete param; + param = 0; + } + if (center) { + delete center; + center = 0; + } + if (position) { + delete position; + position = 0; + } +} + +Int_t FairGeoTorus::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads nPoints with 3 components from Ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf", &x); + volu->setPoint(i, x, 0, 0); + } + return nPoints; +} + +TArrayD* FairGeoTorus::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape + + for (Int_t i = 0; i < 3; i++) { + FairGeoVector v = *(volu->getPoint(i)); + v *= (1 / 10.); + param->AddAt(v(0), i); + } + FairGeoVector v = *(volu->getPoint(3)); + param->AddAt(v(0), 3); + + v = *(volu->getPoint(4)); + param->AddAt(v(0), 4); + + return param; +} + +Bool_t FairGeoTorus::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 4 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + sprintf(buf, "%9.3f\n", v(0)); + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoTorus::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + printf("%9.3f\n", v(0)); + } +} + +void FairGeoTorus::calcVoluPosition(FairGeoVolume*, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoTransform.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoTransform.cxx new file mode 100644 index 0000000000000..2e366c612fc7b --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoTransform.cxx @@ -0,0 +1,143 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 16/06/1999 +//*-- Modified : 21/06/2005 D.Bertini + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoTransform +// +// Class to hold the orientation (rotation matrix) and the position +// (translation vector) of a coordinate system (system 2) relative to a +// reference coordinate system (system 1) +// It provides member functions to transform a vector or a point and an other +// coordinate system from its own coordinate system into the reference +// coordinate system and vice versa. +// Instances of this class can e.g. hold the lab or detector transformation of +// a geometry volume (see class FairGeoVolume) +// +// Inline functions: +// +// FairGeoTransform() +// The default constructor creates an identity transformation +// FairGeoTransform(FairGeoTransform& t) +// copy constructor +// void setTransform(const FairGeoTransform& t) +// copies the given transformation +// void setRotMatrix(const FairGeoRotation& r) +// copies the given rotation matrix +// void setRotMatrix(const Double_t* a) +// creates a rotation matrix taking an Double_t array with 9 components +// void setTransVector(const FairGeoVector& t) +// copies the given translation vector +// void setTransVector(const Double_t* a) +// creates a translation vector taking an Double_t array with 6 components +// const FairGeoRotation& getRotMatrix() const +// returns the rotation matrix +// const FairGeoVector& getTransVector() const +// returns the translation vector +// +/////////////////////////////////////////////////////////////////////////////// + +#include "FairGeoTransform.h" + +//#include +//#include +//#include "math.h" + +ClassImp(FairGeoTransform); + +FairGeoTransform::FairGeoTransform() + : TObject() + , rot(FairGeoRotation(0, 0, 0)) + , trans(FairGeoVector(0, 0, 0)) + , trans_cm(FairGeoVector(0, 0, 0)) +{} + +FairGeoTransform& FairGeoTransform::operator=(const FairGeoTransform& t) +{ + rot = t.getRotMatrix(); + trans = t.getTransVector(); + + return *this; +} + +FairGeoVector FairGeoTransform::transFrom(const FairGeoVector& p) const +{ + // Transforms a vector (point) given in its own coordinate + // system (2) into the reference coordinate system (1) + // e.g. v2 is a vector (point) in the detector coordinate system; + // it can be transformed to a vector v2 the lab system with + // FairGeoVector v2=mo.transFrom(v1) + // where mo is the coordinate system of the mother + return rot * p + trans; +} + +FairGeoVector FairGeoTransform::transTo(const FairGeoVector& p) const +{ + // Transforms a vector (point) given in the reference system (1) + // into the local coordinate system (2) + // e.g. v1 is a vector (point) in the lab system; it can be transformed to + // a vector v2 the detector coordinate system with + // FairGeoVector v2=mo.transTo(v1) + // where mo is the coordinate system of the mother + return rot.inverse() * (p - trans); +} + +void FairGeoTransform::transTo(const FairGeoTransform& s) +{ + // Transforms the coordinate system into the coordinate system + // described by s. Both transformations must have the same reference + // system e.g. the lab system + // This function is e.g. used to transform a daughter coordinate system + // with a transformation relative to the lab into the detector coordinate + // system. + const FairGeoRotation& rm = s.getRotMatrix(); + FairGeoRotation rt(rm.inverse()); + if (rm.diff2(rot) < 0.000001) { + rot.setUnitMatrix(); + } else { + rot.transform(rt); + } + trans -= s.getTransVector(); + trans = rt * trans; + // trans.round(3); // rounds to 3 digits (precision 1 micrometer) +} + +void FairGeoTransform::transFrom(const FairGeoTransform& s) +{ + // Transforms the coordinate system described by s into the local + // coordinate system + // This function is e.g. used to transform a daughter coordinate system + // with a transformation relative to its mother into the lab system. + // e.g. daughterDetTransform.transFrom(motherLabTransform) + const FairGeoRotation& r = s.getRotMatrix(); + rot.transform(r); + trans = r * trans; + trans += s.getTransVector(); +} + +void FairGeoTransform::clear() +{ + trans.clear(); + rot.setUnitMatrix(); +} + +void FairGeoTransform::print() +{ + rot.print(); + trans.print(); +} + +void FairGeoTransform::invert(void) +{ + rot.invert(); + trans = rot * trans; + trans *= -1.; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoTrap.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoTrap.cxx new file mode 100644 index 0000000000000..cff559e8d8063 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoTrap.cxx @@ -0,0 +1,167 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 16/05/99 by Ilse Koenig + +///////////////////////////////////////////////////////////// +// +// FairGeoTrap +// +// class for the GEANT shape TRAP +// +// The technical coordinate system of a TRAP, which sits in +// CAVE and is not rotated, is the laboratory system. +// The y-axis points from the smaller side to the larger one. +// That's the same definitition as for a TRAP and different from +// the Geant or ROOT definition for a TRAP. +// Therefore a transformation is needed: +// x-technical = - (x-Geant) +// y-technical = - (y-Geant) +// z-technical = z-Geant +// This is stored in the data element intrinsicRot which is +// created in the function calcVoluPosition(...) +// +///////////////////////////////////////////////////////////// +#include "FairGeoTrap.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for ATan, Pi, Sqrt, atan +#include // for Abs +#include // for TString +#include // for operator<<, cout, etc + +using std::cout; + +ClassImp(FairGeoTrap); + +FairGeoTrap::FairGeoTrap() + : FairGeoBasicShape() + , intrinsicRot(FairGeoRotation()) +{ + // constructor + fName = "TRAP"; + nPoints = 8; + nParam = 11; + param = new TArrayD(nParam); + intrinsicRot.setElement(-1., 0); + intrinsicRot.setElement(-1., 4); +} + +FairGeoTrap::~FairGeoTrap() +{ + // destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +TArrayD* FairGeoTrap::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape + const Double_t fac = 20.; + const Double_t raddeg = 180. / TMath::Pi(); + Double_t alpha, beta; + FairGeoVector cb, ct, dc; + for (Int_t i = 0; i < 4; i++) { + cb += *(volu->getPoint(i)); + } // bottom plane + for (Int_t j = 4; j < 8; j++) { + ct += *(volu->getPoint(j)); + } // top plane + dc = (ct - cb); + // cout << dc <<" "<< ct <<" "<< cb <<" "<< endl; + dc *= 0.25; // vector from bottom to top plane + dc.setX(-dc(0)); // GEANT coordinate system + dc.setY(-dc(1)); + param->AddAt(TMath::Abs(dc(2)) / fac, 0); + alpha = TMath::ATan(TMath::Sqrt(dc(0) * dc(0) + dc(1) * dc(1)) / dc(2)) * raddeg; + if (TMath::Abs(alpha) < 0.0001) { + alpha = 0.0; + beta = 0.0; + } else { + if (TMath::Abs(dc(0)) < 0.0001) { + if (dc(1) > 0) { + beta = 90.0; + } else { + beta = 270.0; + } + } else { + beta = atan(dc(1) / dc(0)) * raddeg; + if (dc(0) < 0) { + beta = 180.0 + beta; + } + if (beta < 0) { + beta = 360.0 + beta; + } + } + } + param->AddAt(alpha, 1); + param->AddAt(beta, 2); + param->AddAt(((*(volu->getPoint(1)))(1) - (*(volu->getPoint(0)))(1)) / fac, 3); + param->AddAt(((*(volu->getPoint(1)))(0) - (*(volu->getPoint(2)))(0)) / fac, 4); + param->AddAt(((*(volu->getPoint(0)))(0) - (*(volu->getPoint(3)))(0)) / fac, 5); + + Double_t a = TMath::ATan(((*(volu->getPoint(1)))(0) - (*(volu->getPoint(0)))(0) + (*(volu->getPoint(2)))(0) + - (*(volu->getPoint(3)))(0)) + / 40. / param->At(3)) + * raddeg; + if (TMath::Abs(a) <= 0.0001) { + param->AddAt(0., 6); + } else { + param->AddAt(a, 6); + } + param->AddAt(((*(volu->getPoint(5)))(1) - (*(volu->getPoint(4)))(1)) / fac, 7); + param->AddAt(((*(volu->getPoint(5)))(0) - (*(volu->getPoint(6)))(0)) / fac, 8); + param->AddAt(((*(volu->getPoint(4)))(0) - (*(volu->getPoint(7)))(0)) / fac, 9); + a = TMath::ATan(((*(volu->getPoint(5)))(0) - (*(volu->getPoint(4)))(0) + (*(volu->getPoint(6)))(0) + - (*(volu->getPoint(7)))(0)) + / 40. / param->At(7)) + * raddeg; + if (TMath::Abs(a) <= 0.0001) { + param->AddAt(0., 10); + } else { + param->AddAt(a, 10); + } + // check if coplanar + Double_t dx = (param->At(4) - param->At(5)) / param->At(3) * param->At(7) - (param->At(8) - param->At(9)); + if (TMath::Abs(dx) >= 0.001) { + cout << "top and bottom plane are not coplanar for shape TRAP\n"; + cout << "lenght in x-direction of top plane is changed\n"; + cout << "old values: " << param->At(8) << " " << param->At(9) << "\n"; + param->AddAt(param->At(8) + dx / 2., 8); + param->AddAt(param->At(9) - dx / 2., 9); + cout << "new values: " << param->At(8) << " " << param->At(9) << "\n"; + } + return param; +} + +void FairGeoTrap::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + for (Int_t i = 0; i < 8; i++) { + t[0] += (*(volu->getPoint(i)))(0); + } + t[0] /= 8.; + t[1] = + ((*(volu->getPoint(1)))(1) + (*(volu->getPoint(0)))(1) + (*(volu->getPoint(5)))(1) + (*(volu->getPoint(4)))(1)) + / 4.; + t[2] = ((*(volu->getPoint(4)))(2) + (*(volu->getPoint(0)))(2)) / 2.; + center->setTransVector(t); + center->setRotMatrix(intrinsicRot); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoTrd1.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoTrd1.cxx new file mode 100644 index 0000000000000..4dc63e764776d --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoTrd1.cxx @@ -0,0 +1,102 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 16/05/99 by Ilse Koenig + +///////////////////////////////////////////////////////////// +// +// FairGeoTrd1 +// +// class for the GEANT shape TRD1 +// +// The technical coordinate system of a TRD1, which sits in +// CAVE and is not rotated, is the laboratory system. +// The y-axis points from the smaller side to the larger one. +// That's the same definitition as for a TRAP and different from +// the Geant or ROOT definition for a TRD1. +// Therefore a transformation is needed: +// x-technical = - (x-Geant) +// y-technical = z-Geant +// z-technical = y-Geant +// This is stored in the data element intrinsicRot which is +// created in the function calcVoluPosition(...) +// +///////////////////////////////////////////////////////////// +#include "FairGeoTrd1.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for Abs +#include // for TString + +ClassImp(FairGeoTrd1); + +FairGeoTrd1::FairGeoTrd1() + : FairGeoBasicShape() + , intrinsicRot(FairGeoRotation()) +{ + // constructor + fName = "TRD1"; + nPoints = 8; + nParam = 4; + param = new TArrayD(nParam); + intrinsicRot.setZero(); + intrinsicRot.setElement(-1., 0); + intrinsicRot.setElement(1., 5); + intrinsicRot.setElement(1., 7); +} + +FairGeoTrd1::~FairGeoTrd1() +{ + // destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +TArrayD* FairGeoTrd1::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape + Double_t fac = 20.; + FairGeoVector& v0 = *(volu->getPoint(0)); + FairGeoVector& v1 = *(volu->getPoint(1)); + FairGeoVector& v2 = *(volu->getPoint(2)); + FairGeoVector& v3 = *(volu->getPoint(3)); + FairGeoVector& v4 = *(volu->getPoint(4)); + param->AddAt(TMath::Abs((v0(0) - v3(0)) / fac), 0); + param->AddAt((v1(0) - v2(0)) / fac, 1); + param->AddAt((v4(2) - v0(2)) / fac, 2); + param->AddAt((v1(1) - v0(1)) / fac, 3); + return param; +} + +void FairGeoTrd1::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + for (Int_t i = 0; i < 4; i++) { + t[0] += (*(volu->getPoint(i)))(0); + } + t[0] /= 4.; + FairGeoVector& v0 = *(volu->getPoint(0)); + FairGeoVector& v1 = *(volu->getPoint(1)); + FairGeoVector& v4 = *(volu->getPoint(4)); + t[1] = (v1(1) + v0(1)) / 2.; + t[2] = (v4(2) + v0(2)) / 2.; + center->setTransVector(t); + center->setRotMatrix(intrinsicRot); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoTube.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoTube.cxx new file mode 100644 index 0000000000000..8744b6e3a744d --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoTube.cxx @@ -0,0 +1,152 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 28/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoTube +// +// class for the GEANT shape TUBE +// +// The size of a TUBE is defined by 3 'points'. +// point 0: origin of starting circle of the tube; +// point 1: inner radius of starting circle, +// outer radius of starting circle; +// (z-component not used) +// point 2: origin of ending circle of the tube; +// Warning: The x- and y-values of point 0 and 2 have to be the same!!!! +// A rotation has to be desribed via the rotation matrix. +// +// The intrinsic coordinate system of a TUBE, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoTube.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for Abs +#include // for TString +#include +#include // for basic_ostream::write +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoTube); + +FairGeoTube::FairGeoTube() + : FairGeoBasicShape() +{ + // constructor + fName = "TUBE"; + nPoints = 3; + nParam = 3; + param = new TArrayD(nParam); +} + +FairGeoTube::~FairGeoTube() +{ + // default destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +Int_t FairGeoTube::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 3 'points' decribed above from ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + if (i != 1) { + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + } else { + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + } + return nPoints; +} + +Bool_t FairGeoTube::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 3 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i != 1) { + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoTube::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i != 1) { + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + printf("%9.3f%10.3f\n", v(0), v(1)); + } + } +} + +TArrayD* FairGeoTube::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape TUBE + Double_t fac = 10.; + FairGeoVector& v1 = *(volu->getPoint(1)); + param->AddAt(v1(0) / fac, 0); + param->AddAt(v1(1) / fac, 1); + FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0)); + param->AddAt(TMath::Abs(v(2)) / fac / 2., 2); + return param; +} + +void FairGeoTube::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calculates the position of the center of the ROOT volume in the intrinsic + // coordinate system and stores it in the data element 'center' + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0)); + t[2] = v(2) / 2.; + center->clear(); + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoTubs.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoTubs.cxx new file mode 100644 index 0000000000000..553f7a00a6659 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoTubs.cxx @@ -0,0 +1,157 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 11/11/2003 by Ilse Koenig +//*-- Modified : 28/06/99 by Ilse Koenig + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoTubs +// +// class for the GEANT shape TUBS +// +// The size of a TUBS is defined by 4 'points'. +// point 0: origin of starting circle of the tubs; +// point 1: inner radius of starting circle, +// outer radius of starting circle; +// (z-component not used) +// point 2: origin of ending circle of the tubs; +// point 3: starting angle of the segment, +// ending angle of the segment; +// (z-component not used) +// Warning: The x- and y-values of point 0 and 2 have to be the same!!!! +// A rotation has to be desribed via the rotation matrix. +// +// The intrinsic coordinate system of a TUBS, which sits in the CAVE and is +// not rotated, is identical with the laboratory system. +// +/////////////////////////////////////////////////////////////////////////////// +#include "FairGeoTubs.h" + +#include "FairGeoTransform.h" // for FairGeoTransform +#include "FairGeoVector.h" // for FairGeoVector +#include "FairGeoVolume.h" // for FairGeoVolume + +#include // for TArrayD +#include // for Abs +#include // for TString +#include +#include // for basic_ostream::write +#include // for printf, sprintf, sscanf +#include // for strlen + +ClassImp(FairGeoTubs); + +FairGeoTubs::FairGeoTubs() + : FairGeoBasicShape() +{ + // constructor + fName = "TUBS"; + nPoints = 4; + nParam = 5; + param = new TArrayD(nParam); +} + +FairGeoTubs::~FairGeoTubs() +{ + // default destructor + delete param; + param = 0; + delete center; + center = 0; + delete position; + position = 0; +} + +Int_t FairGeoTubs::readPoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // reads the 4 'points' decribed above from ascii file + // if the array of points is not existing in the volume it is created and + // the values are stored inside + // returns the number of points + if (!pFile) { + return 0; + } + if (volu->getNumPoints() != nPoints) { + volu->createPoints(nPoints); + } + Double_t x, y, z; + const Int_t maxbuf = 155; + Text_t buf[maxbuf]; + for (Int_t i = 0; i < nPoints; i++) { + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf%lf", &x, &y, &z); + volu->setPoint(i, x, y, z); + i++; + pFile->getline(buf, maxbuf); + sscanf(buf, "%lf%lf", &x, &y); + volu->setPoint(i, x, y, 0.0); + } + return nPoints; +} + +Bool_t FairGeoTubs::writePoints(std::fstream* pFile, FairGeoVolume* volu) +{ + // writes the 4 'points' decribed above to ascii file + if (!pFile) { + return kFALSE; + } + Text_t buf[155]; + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i == 0 || i == 2) { + sprintf(buf, "%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + sprintf(buf, "%9.3f%10.3f\n", v(0), v(1)); + } + pFile->write(buf, strlen(buf)); + } + return kTRUE; +} + +void FairGeoTubs::printPoints(FairGeoVolume* volu) +{ + // prints volume points to screen + for (Int_t i = 0; i < nPoints; i++) { + FairGeoVector& v = *(volu->getPoint(i)); + if (i == 0 || i == 2) { + printf("%9.3f%10.3f%10.3f\n", v(0), v(1), v(2)); + } else { + printf("%9.3f%10.3f\n", v(0), v(1)); + } + } +} + +TArrayD* FairGeoTubs::calcVoluParam(FairGeoVolume* volu) +{ + // calculates the parameters needed to create the shape TUBS + Double_t fac = 10.; + FairGeoVector& v1 = *(volu->getPoint(1)); + param->AddAt(v1(0) / fac, 0); + param->AddAt(v1(1) / fac, 1); + FairGeoVector v = *(volu->getPoint(2)) - *(volu->getPoint(0)); + param->AddAt(TMath::Abs(v(2)) / fac / 2., 2); + FairGeoVector& v3 = *(volu->getPoint(3)); + param->AddAt(v3(0), 3); + param->AddAt(v3(1), 4); + return param; +} + +void FairGeoTubs::calcVoluPosition(FairGeoVolume* volu, const FairGeoTransform& dTC, const FairGeoTransform& mTR) +{ + // calculates the position of the center of the volume in the intrinsic + // coordinate system and stores it in the data element 'center' + // calls the function posInMother(...) to calculate the position of the + // volume in its mother + Double_t t[3] = {0., 0., 0.}; + FairGeoVector v = *(volu->getPoint(2)) + *(volu->getPoint(0)); + t[2] = v(2) / 2.; + center->clear(); + center->setTransVector(t); + posInMother(dTC, mTR); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoVector.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoVector.cxx new file mode 100644 index 0000000000000..f0ae32517b61b --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoVector.cxx @@ -0,0 +1,95 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 16/06/99 + +/////////////////////////////////////////////////////////////////////////////// +// +// FairGeoVector +// +// This class defines a vector with 3 Double_t components. +// Instantiations of this class are e.g geometry points and +// translation vectors in the geometry transformations. +// +// All functions and operators are defined inline. +// +// Constructors: +// FairGeoVector(Double_t dx=0,Double_t dy=0,Double_t dz=0) +// FairGeoVector(const FairGeoVector& v) +// +// Access to the components: +// void setVector(const Double_t* a); +// void setX(const Double_t a) +// void setY(const Double_t a) +// void setZ(const Double_t a) +// Double_t getX() const +// Double_t getY() const +// Double_t getZ() const +// Double_t operator() (const Int_t i) const; +// +// Check for the size of all components: +// Bool_t operator < (const Double_t a) +// Bool_t operator <= (const Double_t a) +// Bool_t operator > (const Double_t a) +// Bool_t operator >= (const Double_t a) +// +// Check for equality/inequality; +// Bool_t operator == (const FairGeoVector& v) const +// Bool_t operator != (const FairGeoVector& v) const +// +// Addition/Substraction of a vector; +// FairGeoVector& operator += (const Double_t a) +// FairGeoVector& operator -= (const Double_t a) +// +// Addition/Substraction of two vectors; +// FairGeoVector operator + (const FairGeoVector& v) const +// FairGeoVector operator - (const FairGeoVector& v) const +// +// Multiplication/Division of each components with/by a factor +// FairGeoVector& operator *= (const Double_t a) +// FairGeoVector& operator /= (const Double_t a) +// +// +// FairGeoVector operator - () const +// changes the sign of all components +// +// FairGeoVector& operator = (const FairGeoVector& v) +// assignment +// +// FairGeoVector& abs() +// builds absolute value of each components +// +// Double_t scalarProduct(const FairGeoVector& v) const; +// returns the scalar product +// +// FairGeoVector vectorProduct(const FairGeoVector& v) const; +// returns the vector product +// +// Double_t length() const {return sqrt(x*x+y*y+z*z);} +// returns the length +// +// void clear() +// sets all components to 0.0 +// +// void print() +// prints the components +// +// void round(Int_t n) +// rounds all components to a precision with n digits +// +// friend ostream& operator << (ostream& put,const FairGeoVector& v); +// output to stream +// +// friend istream& operator >> (istream& get,FairGeoVector& v); +// input from stream +// +/////////////////////////////////////////////////////////////////////////////// + +#include "FairGeoVector.h" + +ClassImp(FairGeoVector); diff --git a/Detectors/3rdparty/FairRootBase/src/FairGeoVolume.cxx b/Detectors/3rdparty/FairRootBase/src/FairGeoVolume.cxx new file mode 100644 index 0000000000000..85b57fad81b17 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairGeoVolume.cxx @@ -0,0 +1,164 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +//*-- AUTHOR : Ilse Koenig +//*-- Modified : 27/05/99 + +///////////////////////////////////////////////////////////// +// FairGeoVolume +// +// Class to hold the basic geometry properties of a volume +// Each volume has a name, a pointer to a reference volume and +// a lab transformation. +// The reference volume defines the shape, the mother, the size +// and the transformation relative to the mother volume which +// is either the cave (for modules) or the detector (for the +// inner parts). +// As an example: +// The Mdc modules built at GSI (plane 1 type) are all identical +// independent where the sit in the cave. This module type has a +// fixed coordinate system. The first layers in all these modules +// are identical and they have the same position in the module +// coordinate system. +// +///////////////////////////////////////////////////////////// +#include "FairGeoVolume.h" + +#include // for operator<<, basic_ostream, etc + +using std::cout; +using std::endl; + +ClassImp(FairGeoVolume); + +FairGeoVolume::FairGeoVolume(FairGeoVolume& r) + : TNamed(r) + , shape("") + , mother("") + , points(NULL) + , transform(FairGeoTransform()) + , fLabTransform(FairGeoTransform()) + , fMedium(0) + , nPoints(0) + , fHadFormat(0) + , fgMCid(0) +{ + // copy constructor + // fName=r.GetName(); + setVolumePar(r); +} + +void FairGeoVolume::setVolumePar(FairGeoVolume& r) +{ + // copies all volume parameters except the name + shape = r.getShape(); + mother = r.getMother(); + Int_t n = r.getNumPoints(); + createPoints(n); + for (Int_t i = 0; i < nPoints; i++) { + setPoint(i, *(r.getPoint(i))); + } + transform = r.getTransform(); +} + +void FairGeoVolume::createPoints(const Int_t n) +{ + // Creates n Points (objects of class FairGeoVector). + // If the array exists already and the size is different from n it is + // deleted and recreated with the new size n. + // If n==0 the points are deleted. + if (n != nPoints) { + nPoints = n; + if (n > 0) { + if (points != 0) { + points->Delete(); + delete points; + } + points = new TObjArray(n); + for (Int_t i = 0; i < n; i++) { + points->AddAt(new FairGeoVector(), i); + } + } else { + if (points) { + points->Delete(); + } + delete points; + points = 0; + } + } +} + +void FairGeoVolume::setPoint(const Int_t n, const Double_t x, const Double_t y, const Double_t z) +{ + // set the 3 values of the point with index n + if (points && n < nPoints) { + FairGeoVector* v = static_cast(points->At(n)); + v->setX(x); + v->setY(y); + v->setZ(z); + } +} + +void FairGeoVolume::setPoint(const Int_t n, const FairGeoVector& p) +{ + // sets point with index n by copying the 3 components of point p + if (points && n < nPoints) { + FairGeoVector& v = *(static_cast(points->At(n))); + v = p; + } +} + +void FairGeoVolume::clear() +{ + // clears the volume + // deletes the points + shape = ""; + mother = ""; + if (points) { + points->Delete(); + } + delete points; + points = 0; + nPoints = 0; + transform.clear(); +} + +void FairGeoVolume::print() +{ + // prints all parameters of a volume + cout << "Volume: " << (const_cast(fName.Data())) + << " Shape: " << (const_cast(shape.Data())) + << " Mother: " << (const_cast(mother.Data())) << '\n'; + cout << "Points definition " << endl; + if (points) { + for (Int_t i = 0; i < nPoints; i++) { + cout << (*(static_cast(points->At(i)))); + } + } + cout << "Lab Transform " << endl; + fLabTransform.print(); + cout << '\n'; +} + +Double_t FairGeoVolume::getVolParameter(Int_t nPoint, Int_t pos) +{ + FairGeoVector* vec = static_cast(points->At(nPoint)); + if (vec) { + return vec->getValues(pos); + } else { + return -1; + } +} + +FairGeoVolume::~FairGeoVolume() +{ + if (points) { + points->Delete(); + delete points; + points = 0; + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairIon.cxx b/Detectors/3rdparty/FairRootBase/src/FairIon.cxx new file mode 100644 index 0000000000000..525289be6aee3 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairIon.cxx @@ -0,0 +1,51 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairIon source file ----- +// ------------------------------------------------------------------------- +#include "FairIon.h" + +#include "FairLogger.h" + +#include +#include + +FairIon::FairIon() + : TNamed() + , fZ(0) + , fA(0) + , fQ(0) + , fExcEnergy(0) + , fMass(0) + , fLogger(FairLogger::GetLogger()) +{} + +FairIon::FairIon(const char* name, Int_t z, Int_t a, Int_t q, Double_t e, Double_t mass) + : TNamed(name, "User defined ion") + , fZ(z) + , fA(a) + , fQ(q) + , fExcEnergy(e) + , fMass(0) + , fLogger(FairLogger::GetLogger()) +{ + TDatabasePDG* pdgDB = TDatabasePDG::Instance(); + TParticlePDG* kProton = pdgDB->GetParticle(2212); + Double_t kProtonMass = kProton->Mass(); + + if (mass == 0.) { + fMass = kProtonMass * Double_t(a); + } else { + fMass = mass; + } + LOG(info) << "New Ion " << name << " Z=" << z << " A=" << a << " Charge=" << q << " Mass=" << fMass << " GeV "; +} + +FairIon::~FairIon(){}; + +ClassImp(FairIon); diff --git a/Detectors/3rdparty/FairRootBase/src/FairLink.cxx b/Detectors/3rdparty/FairRootBase/src/FairLink.cxx new file mode 100644 index 0000000000000..364026880c6b8 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairLink.cxx @@ -0,0 +1,46 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairLink.cpp + * + * Created on: Dec 23, 2009 + * Author: stockman + */ + +#include "FairLink.h" + +#include "FairRootManager.h" + +ClassImp(FairLink); + +FairLink::FairLink(TString branchName, Int_t index, Float_t weight) + : fFile(0) + , fType(0) + , fEntry(-1) + , fIndex(index) + , fWeight(weight) +{ + SetType(FairRootManager::Instance()->GetBranchId(branchName)); +} + +FairLink::FairLink(Int_t file, Int_t entry, TString branchName, Int_t index, Float_t weight) + : fFile(0) + , fType(0) + , fEntry(entry) + , fIndex(index) + , fWeight(weight) +{ + SetFile(file); + SetType(FairRootManager::Instance()->GetBranchId(branchName)); +} + +void FairLink::PrintLinkInfo(std::ostream& out) const +{ + out << "(" << GetFile() << "/" << GetEntry() << "/"; + out << GetType() << "/" << GetIndex() << "/" << GetWeight() << ")"; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairLinkManager.cxx b/Detectors/3rdparty/FairRootBase/src/FairLinkManager.cxx new file mode 100644 index 0000000000000..17c940340f44c --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairLinkManager.cxx @@ -0,0 +1,74 @@ +// ------------------------------------------------------------------------- +// ----- FairLinkManager source file ----- +// ----- Created 05/06/14 by T.Stockmanns ----- +// ------------------------------------------------------------------------- + +#include "FairLinkManager.h" + +#include "FairLogger.h" +#include "FairRun.h" + +TMCThreadLocal FairLinkManager* FairLinkManager::fgInstance = 0; + +FairLinkManager* FairLinkManager::Instance() +{ + // Returns singleton instance. + // --- + return fgInstance; +} + +FairLinkManager::FairLinkManager() + : TObject() + , fIgnoreTypes() + , fIgnoreSetting(kTRUE) + , fLogger(0) +{ + if (fgInstance) { + Fatal("FairLinkManager", "Singleton instance already exists."); + return; + } + // std::cout << "-I- FairLinkManager::FairLinkManager created!" << std::endl; + fgInstance = this; + + // Logger only on master - TO DO + if (FairRun::Instance()->GetIsMaster()) { + fLogger = FairLogger::GetLogger(); + } +} + +FairLinkManager::~FairLinkManager() +{ + LOG(debug) << "Enter Destructor of FairLinkManager"; + fgInstance = 0; + LOG(debug) << "Leave Destructor of FairLinkManager"; +} + +void FairLinkManager::AddIgnoreType(Int_t type) +{ + if (fIgnoreSetting == kFALSE) { + LOG(debug) << "AddIgnoreType ignored because of IncludeType setting"; + return; + } + LOG(debug) << "AddIgnoreType"; + fIgnoreTypes.insert(type); +} + +void FairLinkManager::AddIncludeType(Int_t type) +{ + LOG(debug) << "AddIgnoreType"; + if (fIgnoreSetting == kTRUE) { + fIgnoreSetting = kFALSE; + fIgnoreTypes.clear(); + } + fIgnoreTypes.insert(type); +} + +Bool_t FairLinkManager::IsIgnoreType(Int_t type) const +{ + if (fIgnoreSetting) + return fIgnoreTypes.count(type); + else + return !fIgnoreTypes.count(type); +} + +ClassImp(FairLinkManager); diff --git a/Detectors/3rdparty/FairRootBase/src/FairLogger.cxx b/Detectors/3rdparty/FairRootBase/src/FairLogger.cxx new file mode 100644 index 0000000000000..28210ce18ea27 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairLogger.cxx @@ -0,0 +1,203 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairLogger.cxx + * + * Created on: Mar 03, 2011 + * Author: f.uhlig + */ + +#include "FairLogger.h" + +#include // for TString, operator==, etc +#include // for gSystem, TSystem +#include // for cout, cerr +#include // for fclose, freopen, remove, etc + +FairLogger* FairLogger::instance = nullptr; + +const char FairLogger::endl = ' '; +const char FairLogger::flush = ' '; + +FairLogger::FairLogger() + : fLogFileName() + , fLogFileSeverity("info") + , fConsoleSeverity("info") + , fBufferSize(1024) + , fBufferSizeNeeded(-1) + , fDynamicBuffer(fBufferSize) + , fBufferPointer(&fDynamicBuffer[0]) +{ + fair::Logger::OnFatal(LogFatalMessage); +} + +FairLogger* FairLogger::GetLogger() +{ + if (!instance) { + instance = new FairLogger(); + } + + return instance; +} + +void FairLogger::Fatal(const char* file, const char* line, const char* func, const char* format, ...) +{ + va_list ap; + va_start(ap, format); + Log(fair::Severity::fatal, file, line, func, format, ap); + va_end(ap); +} + +void FairLogger::Error(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::error)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::error, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Warning(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::warning)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::warning, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Info(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::info)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::info, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Debug(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::debug)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::debug, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Debug1(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::debug1)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::debug1, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Debug2(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::debug2)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::debug2, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Debug3(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::debug3)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::debug3, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Debug4(const char* file, const char* line, const char* func, const char* format, ...) +{ + if (IsLogNeeded(fair::Severity::debug4)) { + va_list ap; + va_start(ap, format); + Log(fair::Severity::debug4, file, line, func, format, ap); + va_end(ap); + } +} + +void FairLogger::Log(fair::Severity severity, + const char* file, + const char* line, + const char* func, + const char* format, + va_list arglist) +{ + // If the format string together with the argument list was used once it can't + // be used another time. Don't know why but if we do so the arguments are not + // correct any longer and the program may crash (On Mac OSX). Even if it does + // not crash it does not work as expected. + // To vercome the problem the output is written to a buffer which then can be + // used several times. + + while (true) { + fBufferSizeNeeded = vsnprintf(fBufferPointer, fBufferSize, format, arglist); + + // Try to vsnprintf into our buffer. + // int needed = vsnprintf (buf, size, fmt, ap); + // NB. C99 (which modern Linux and OS X follow) says vsnprintf + // failure returns the length it would have needed. But older + // glibc and current Windows return -1 for failure, i.e., not + // telling us how much was needed. + + if (fBufferSizeNeeded <= static_cast(fBufferSize) && fBufferSizeNeeded >= 0) { + // It fits fine so we're done. + LOGD(severity, file, line, func) << std::string(fBufferPointer, static_cast(fBufferSizeNeeded)); + break; + } + + // vsnprintf reported that it wanted to write more characters + // than we allotted. So try again using a dynamic buffer. This + // doesn't happen very often if we chose our initial size well. + fBufferSize = (fBufferSizeNeeded > 0) ? (fBufferSizeNeeded + 1) : (fBufferSize * 2); + fDynamicBuffer.resize(fBufferSize); + } +} + +bool FairLogger::IsLogNeeded(fair::Severity severity) { return fair::Logger::Logging(severity); } + +bool FairLogger::IsLogNeeded(FairLogLevel level) { return fair::Logger::Logging(ConvertLogLevelToString(level)); } + +void FairLogger::LogFatalMessage() +{ + // Since Fatal indicates a fatal error it is maybe usefull to have + // system information from the incident. Since the output on the screen + // does not help the noraml user, the stderr is redirected into a special + // core dump file for later usage. + // Fatal also indicates a problem which is so severe that the process should + // not go on, so the process is aborted. + + if (gSystem) { + TString corefile = "core_dump_"; + int pid = gSystem->GetPid(); + corefile += pid; + + std::cerr << "For later analysis we write a core dump to " << corefile << std::endl; + + if (freopen(corefile, "w", stderr)) { + gSystem->StackTrace(); + fclose(stderr); + } + } + + throw fair::FatalException("Fatal error occured. Exiting..."); +} + +ClassImp(FairLogger); diff --git a/Detectors/3rdparty/FairRootBase/src/FairMCApplication.cxx b/Detectors/3rdparty/FairRootBase/src/FairMCApplication.cxx new file mode 100644 index 0000000000000..b84f5c9b278c5 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMCApplication.cxx @@ -0,0 +1,1452 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +// ------------------------------------------------------------------------- +// ----- FairMCApplication source file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- +#include "FairMCApplication.h" + +#include "FairDetector.h" // for FairDetector +#include "FairField.h" // for FairField +#include "FairGenericStack.h" // for FairGenericStack +#include "FairGeoInterface.h" // for FairGeoInterface +#include "FairGeoLoader.h" // for FairGeoLoader +#include "FairGeoMedia.h" // for FairGeoMedia +#include "FairGeoMedium.h" // for FairGeoMedium +#include "FairIon.h" // for FairIon +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairMCEventHeader.h" // for FairMCEventHeader +#include "FairMesh.h" // for FairMesh +#include "FairModule.h" // for FairModule, etc +#include "FairParticle.h" // for FairParticle +#include "FairPrimaryGenerator.h" // for FairPrimaryGenerator +#include "FairRadGridManager.h" // for FairRadGridManager +#include "FairRadLenManager.h" // for FairRadLenManager +#include "FairRadMapManager.h" // for FairRadMapManager +#include "FairRootFileSink.h" // for CloneForWorker (in MT mode only) +#include "FairRootManager.h" // for FairRootManager +#include "FairRun.h" // for FairRun +#include "FairRunInfo.h" // for FairRunInfo +#include "FairRunSim.h" // for FairRunSim +#include "FairTask.h" // for FairTask +#include "FairTrajFilter.h" // for FairTrajFilter +#include "FairVolume.h" // for FairVolume + +#include // for TDatabasePDG +#include // for TFile +#include // for gGeoManager, TGeoManager +#include // for TGeoMedium +#include // for TGeoNode +#include // for TGeoPhysicalNode +#include // for TGeoTrack +#include // for TGeoVolume +#include // for TH2D +#include // for THashList +#include // for TInterpreter, gInterpreter +#include // for TIterator +#include // for TList, TListIter +#include // for TObjArray +#include // for TObject +#include // for TParticlePDG +#include // for TROOT, gROOT +#include // for TRefArray +#include // for TSystem, gSystem +#include // for TVirtualMC +#include // for TVirtualMCStack +class TParticle; + +#include // for DBL_MAX +#include // std::mutex +#include // for getenv, exit +#include // for pair +std::mutex mtx; // mutex for critical section + +using std::pair; + +FairMCApplication* FairMCApplication::fgMasterInstance = 0; + +//_____________________________________________________________________________ +FairMCApplication::FairMCApplication(const char* name, const char* title, TObjArray* ModList, const char*) + : TVirtualMCApplication(name, title) + , fActiveDetectors(nullptr) + , fFairTaskList(nullptr) + , fDetectors(nullptr) + , fDetMap(nullptr) + , fModIter(nullptr) + , fModules(nullptr) + , fNoSenVolumes(0) + , fPythiaDecayer(kFALSE) + , fPythiaDecayerConfig("") + , fStack(nullptr) + , fRootManager(nullptr) + , fSenVolumes(nullptr) + , fxField(nullptr) + , fEvGen(nullptr) + , fMcVersion(-1) + , fTrajFilter(nullptr) + , fTrajAccepted(kFALSE) + , fUserDecay(kFALSE) + , fUserDecayConfig("") + , fDebug(kFALSE) + , fDisVol(nullptr) + , fDisDet(nullptr) + , fVolMap() + , fVolIter() + , fModVolMap() + , fModVolIter() + , fTrkPos(TLorentzVector(0, 0, 0, 0)) + , fRadLength(kFALSE) + , fRadLenMan(nullptr) + , fRadMap(kFALSE) + , fRadMapMan(nullptr) + , fRadGridMan(nullptr) + , fEventHeader(nullptr) + , fMCEventHeader(nullptr) + , listActiveDetectors() + , listDetectors() + , fMC(nullptr) + , fRun(nullptr) + , fSaveCurrentEvent(kTRUE) + , fState(FairMCApplicationState::kUnknownState) + , fRunInfo() + , fGeometryIsInitialized(kFALSE) +{ + // Standard Simulation constructor + + // Create an ObjArray of Modules and its iterator + + LOG(debug) << "FairMCApplication-ctor " << this; + + fRun = FairRunSim::Instance(); + fModules = ModList; + fModIter = fModules->MakeIterator(); + // Create and fill a list of active detectors + fDetectors = new TRefArray; + fActiveDetectors = new TRefArray(); + fModIter->Reset(); + FairDetector* detector; + TObject* obj; + + while ((obj = fModIter->Next())) { + detector = dynamic_cast(obj); + if (detector) { + fDetectors->Add(detector); + listDetectors.push_back(detector); + if (detector->IsActive()) { + fActiveDetectors->Add(detector); + listActiveDetectors.push_back(detector); + } + } else if (!dynamic_cast(obj)) { + LOG(error) << "Dynamic cast fails. Object neither FairDetector nor FairModule in module list"; + } + } + + // Create a Task list + fFairTaskList = new FairTask("Task List", 1); + gROOT->GetListOfBrowsables()->Add(fFairTaskList); + fMcVersion = -1; + // Initialise fTrajFilter pointer + fTrajFilter = nullptr; + fDetMap = new TRefArray(1000); + fDisVol = 0; + fDisDet = 0; + + // This ctor is used to construct the application on master + fgMasterInstance = this; +} + +//_____________________________________________________________________________ +FairMCApplication::FairMCApplication(const FairMCApplication& rhs) + : TVirtualMCApplication(rhs.GetName(), rhs.GetTitle()) + , fActiveDetectors(nullptr) + , fFairTaskList(nullptr) + , fDetectors(nullptr) + , fDetMap(nullptr) + , fModIter(nullptr) + , fModules(nullptr) + , fNoSenVolumes(0) + , fPythiaDecayer(kFALSE) + , fPythiaDecayerConfig(rhs.fPythiaDecayerConfig) + , fStack(nullptr) + , fRootManager(nullptr) + , fSenVolumes(nullptr) + , fxField(rhs.fxField) + , fEvGen(nullptr) + , fMcVersion(rhs.fMcVersion) + , fTrajFilter(nullptr) + , fTrajAccepted(kFALSE) + , fUserDecay(kFALSE) + , fUserDecayConfig(rhs.fUserDecayConfig) + , fDebug(rhs.fDebug) + , fDisVol(nullptr) + , fDisDet(nullptr) + , fVolMap() + , fVolIter() + , fModVolMap() + , fModVolIter() + , fTrkPos(rhs.fTrkPos) + , fRadLength(kFALSE) + , fRadLenMan(nullptr) + , fRadMap(kFALSE) + , fRadMapMan(nullptr) + , fRadGridMan(nullptr) + , fEventHeader(nullptr) + , fMCEventHeader(nullptr) + , listActiveDetectors() + , listDetectors() + , fMC(nullptr) + , fRun(nullptr) + , fSaveCurrentEvent(kTRUE) + , fState(FairMCApplicationState::kUnknownState) + , fRunInfo() + , fGeometryIsInitialized(kFALSE) +{ + // Copy constructor + // Do not create Root manager + + LOG(debug) << "FairMCApplication-copy-ctor " << this; + + // Create an ObjArray of Modules and its iterator + fModules = new TObjArray(); + fModIter = fModules->MakeIterator(); + // Clone modules + TObject* obj; + rhs.fModIter->Reset(); + while ((obj = rhs.fModIter->Next())) { + LOG(debug) << "cloning " << (static_cast(obj))->GetName(); + fModules->Add(static_cast(obj)->CloneModule()); + } + + // Create and fill a list of active detectors + fDetectors = new TRefArray; + fActiveDetectors = new TRefArray(); + fModIter->Reset(); + FairDetector* detector; + while ((obj = fModIter->Next())) { + if (obj->InheritsFrom("FairDetector")) { + detector = dynamic_cast(obj); + if (detector) { + fDetectors->Add(detector); + listDetectors.push_back(detector); + if (detector->IsActive()) { + fActiveDetectors->Add(detector); + listActiveDetectors.push_back(detector); + } + } else { + LOG(error) << "Dynamic cast fails."; + } + } + } + + // Clone stack + fStack = rhs.fStack->CloneStack(); + + // Create a Task list + // Let's try without it + // fFairTaskList= new FairTask("Task List", 1); + // gROOT->GetListOfBrowsables()->Add(fFairTaskList); + + fDetMap = new TRefArray(1000); +} +//_____________________________________________________________________________ +FairMCApplication::FairMCApplication() + : TVirtualMCApplication() + , fActiveDetectors(0) + , fFairTaskList(0) + , fDetectors(0) + , fDetMap(0) + , fModIter(0) + , fModules(0) + , fNoSenVolumes(0) + , fPythiaDecayer(kFALSE) + , fPythiaDecayerConfig("") + , fStack(0) + , fRootManager(0) + , fSenVolumes(0) + , fxField(0) + , fEvGen(0) + , fMcVersion(-1) + , fTrajFilter(nullptr) + , fTrajAccepted(kFALSE) + , fUserDecay(kFALSE) + , fUserDecayConfig("") + , fDebug(kFALSE) + , fDisVol(0) + , fDisDet(0) + , fVolMap() + , fVolIter() + , fModVolMap() + , fModVolIter() + , fTrkPos(TLorentzVector(0, 0, 0, 0)) + , fRadLength(kFALSE) + , fRadLenMan(nullptr) + , fRadMap(kFALSE) + , fRadMapMan(nullptr) + , fRadGridMan(nullptr) + , fEventHeader(nullptr) + , fMCEventHeader(nullptr) + , listActiveDetectors() + , listDetectors() + , fMC(nullptr) + , fRun(nullptr) + , fSaveCurrentEvent(kTRUE) + , fState(FairMCApplicationState::kUnknownState) + , fRunInfo() + , fGeometryIsInitialized(kFALSE) +{ + // Default constructor +} +//_____________________________________________________________________________ +FairMCApplication::~FairMCApplication() +{ + // Destructor + // LOG(debug3) << "Enter Destructor of FairMCApplication"; + delete fStack; + delete fActiveDetectors; // don't do fActiveDetectors->Delete() here + // the modules are already deleted in FairRunSim + delete fDetectors; + delete fModIter; + // LOG(debug3) << "Leave Destructor of FairMCApplication"; + delete fMC; +} + +//_____________________________________________________________________________ +FairMCApplication& FairMCApplication::operator=(const FairMCApplication& rhs) +{ + // Assignment operator + + // check assignment to self + if (this != &rhs) { + + // base class assignment + TVirtualMCApplication::operator=(rhs); + + fActiveDetectors = nullptr; + fFairTaskList = nullptr; + fDetectors = nullptr; + fDetMap = nullptr; + fModIter = nullptr; + fModules = nullptr; + fNoSenVolumes = 0; + fPythiaDecayer = kFALSE; + fPythiaDecayerConfig = rhs.fPythiaDecayerConfig; + fStack = nullptr; + fRootManager = nullptr; + fSenVolumes = nullptr; + fxField = rhs.fxField; + fEvGen = nullptr; + fMcVersion = rhs.fMcVersion; + fTrajFilter = nullptr; + fTrajAccepted = kFALSE; + fUserDecay = kFALSE; + fUserDecayConfig = rhs.fUserDecayConfig; + fDebug = rhs.fDebug; + fDisVol = nullptr; + fDisDet = nullptr; + fTrkPos = rhs.fTrkPos; + fRadLength = kFALSE; + fRadLenMan = nullptr; + fRadMap = kFALSE; + fRadMapMan = nullptr; + fRadGridMan = nullptr; + fEventHeader = nullptr; + fMCEventHeader = nullptr; + fGeometryIsInitialized = kFALSE; + + // Do not create Root manager + + // Create an ObjArray of Modules and its iterator + fModules = new TObjArray(); + fModIter = fModules->MakeIterator(); + // Clone modules + TObject* obj; + while ((obj = rhs.fModIter->Next())) { + fModules->Add(static_cast(obj)->CloneModule()); + } + + // Create and fill a list of active detectors + fDetectors = new TRefArray; + fActiveDetectors = new TRefArray(); + fModIter->Reset(); + FairDetector* detector; + while ((obj = fModIter->Next())) { + if (obj->InheritsFrom("FairDetector")) { + detector = dynamic_cast(obj); + if (detector) { + fDetectors->Add(detector); + listDetectors.push_back(detector); + if (detector->IsActive()) { + fActiveDetectors->Add(detector); + listActiveDetectors.push_back(detector); + } + } else { + LOG(error) << "Dynamic cast fails."; + } + } + } + + // Clone stack + fStack = rhs.fStack->CloneStack(); + + // Create a Task list + // Let's try without it + // fFairTaskList= new FairTask("Task List", 1); + // gROOT->GetListOfBrowsables()->Add(fFairTaskList); + + fDetMap = new TRefArray(1000); + + fState = rhs.fState; + } + + return *this; +} + +//_____________________________________________________________________________ +void FairMCApplication::InitMC(const char*, const char*) +{ + // Initialize MC. + // --- + // This methode is called from FairRunSim::SetMCConfig which excucute first the gconfig + // macro that creates the MC instance (G3 or G4) + + fMC = TVirtualMC::GetMC(); + + if (fMC == 0) { + LOG(fatal) << "No MC engine defined"; + } + + fStack = dynamic_cast(fMC->GetStack()); + if (fStack == nullptr) { + LOG(fatal) << "No Stack defined."; + } + fMC->SetMagField(fxField); + + fRootManager = FairRootManager::Instance(); + // fRootManager->SetDebug(true); + + fMC->Init(); + fMC->BuildPhysics(); + TString MCName = fMC->GetName(); + if (MCName == "TGeant3" || MCName == "TGeant3TGeo") { + fMcVersion = 0; + } else if (MCName == "TGeant4") { + fMcVersion = 1; + } else if (MCName == "TFluka") { + fMcVersion = 2; + } else { + fMcVersion = 3; // Geane + } + fTrajFilter = FairTrajFilter::Instance(); + + LOG(info) << "Monte Carlo Engine Initialisation with: " << MCName.Data(); +} + +//_____________________________________________________________________________ +void FairMCApplication::RunMC(Int_t nofEvents) +{ + // Reset the time for FairRunInfo. Otherwise the time of the + // first event will include the time needed for initilization. + fRunInfo.Reset(); + + /** Set the list of active detectors to the stack*/ + fStack->SetDetArrayList(fActiveDetectors); + + // MC run. + fMC->ProcessRun(nofEvents); + // finish run + FinishRun(); +} + +//____________________________________________________________________________ +void FairMCApplication::FinishRun() +{ + // Finish MC run. + // --- + + LOG(debug) << "FairMCMCApplication::FinishRun() start"; + + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->FinishRun(); + } + + // TO DO: clone this in MT mode ? + if (fFairTaskList) { + fFairTaskList->FinishTask(); + } + // fRootManager->Fill(); + + FairPrimaryGenerator* gen = FairRunSim::Instance()->GetPrimaryGenerator(); + // FairMCEventHeader* header = gen->GetEvent(); + Int_t nprimary = gen->GetTotPrimary(); + TObjArray* meshlist = nullptr; + + // Only in sequential mode + if (fRadGridMan) { + + meshlist = fRadGridMan->GetMeshList(); + + TH2D* tid = nullptr; + TH2D* flu = nullptr; + TH2D* seu = nullptr; + + LOG(info) << "======================================================="; + LOG(info) << " Dosimetry histos saving in \"" << fRadGridMan->GetOutputFileName() << "\""; + LOG(info) << "======================================================="; + + TFile* radGridFile = TFile::Open(fRadGridMan->GetOutputFileName(), "recreate"); + radGridFile->mkdir("Dosimetry"); + radGridFile->cd("Dosimetry"); + + for (Int_t i = 0; i < meshlist->GetEntriesFast(); i++) { + FairMesh* aMesh = dynamic_cast(meshlist->At(i)); + if (aMesh) { + aMesh->Scale(1. / nprimary); + tid = aMesh->GetMeshTid(); + flu = aMesh->GetMeshFlu(); + seu = aMesh->GetMeshSEU(); + tid->Write(); + flu->Write(); + seu->Write(); + } + } + radGridFile->Write(); + radGridFile->Close(); + delete radGridFile; + } + + // Save histograms with memory and runtime information in the output file + if (FairRunSim::Instance()->IsRunInfoGenerated()) { + fRunInfo.WriteInfo(); + } + + if (!fRadGridMan && fRootManager) { + fRootManager->Write(); + fRootManager->CloseSink(); + } + + if (!fMC->IsMT()) { + UndoGeometryModifications(); + } + + LOG(debug) << "Done FairMCMCApplication::FinishRun()"; +} + +//_____________________________________________________________________________ +void FairMCApplication::BeginEvent() +{ + // User actions at beginning of event + // --- + + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->BeginEvent(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::BeginPrimary() +{ + // User actions at beginning of a primary track + // --- + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->BeginPrimary(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::PreTrack() +{ + // User actions at beginning of each track + // --- + + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->PreTrack(); + } + + fTrajAccepted = kFALSE; + if (nullptr != fTrajFilter) { + // Get the pointer to current track + TParticle* particle = fStack->GetCurrentTrack(); + // LOG(debug) << " FairMCApplication::PreTrack(): " << particle; + // Apply cuts + fTrajAccepted = fTrajFilter->IsAccepted(particle); + if (fTrajAccepted) { + // Add trajectory to geo manager + // Int_t trackId = fStack->GetCurrentTrackNumber(); + TGeoTrack* fTrack = fTrajFilter->CheckAddTrack(fMC->GetStack()->GetCurrentTrackNumber(), particle); + // TLorentzVector pos; + fMC->TrackPosition(fTrkPos); + fTrack->AddPoint(fTrkPos.X(), fTrkPos.Y(), fTrkPos.Z(), fTrkPos.T()); + } + } +} + +//_____________________________________________________________________________ +TVirtualMCApplication* FairMCApplication::CloneForWorker() const +{ + mtx.lock(); + LOG(info) << "FairMCApplication::CloneForWorker "; + + // Create new FairRunSim object on worker + // and pass some data from master FairRunSim object + FairRunSim* workerRun = new FairRunSim(kFALSE); + workerRun->SetName(fRun->GetName()); // Transport engine + workerRun->SetSink(fRun->GetSink()->CloneSink()); + + // Trajectories filter is created explicitly as we do not call + // FairRunSim::Init on workers + if (fRun->GetStoreTraj()) { + new FairTrajFilter(); + } + + // Create new FairMCApplication object on worker + FairMCApplication* workerApplication = new FairMCApplication(*this); + workerApplication->SetGenerator(fEvGen->ClonePrimaryGenerator()); + + mtx.unlock(); + + return workerApplication; +} + +//_____________________________________________________________________________ +void FairMCApplication::InitOnWorker() +{ + // Create Root manager + fRootManager = FairRootManager::Instance(); + + LOG(info) << "FairMCApplication::InitForWorker " << fRootManager->GetInstanceId() << " " << this; + + // Set FairRunSim worker(just for consistency, not needed on worker) + fRun = FairRunSim::Instance(); + + // Generate per-thread file name + // and create a new sink on worker + // moved to CloneForWorker and specific sink->CloneSink(); + + fRootManager->InitSink(); + + // Cache thread-local gMC + fMC = gMC; + + // Set data to MC + fMC->SetStack(fStack); + fMC->SetMagField(fxField); + + LOG(info) << "Monte Carlo Engine Worker Initialisation with: " << fMC->GetName(); +} + +//_____________________________________________________________________________ +void FairMCApplication::FinishRunOnWorker() +{ + LOG(debug) << "FairMCApplication::FinishRunOnWorker: "; + + FinishRun(); +} + +//_____________________________________________________________________________ +void FairMCApplication::Stepping() +{ + // User actions at each step + // --- + + // Work around for Fluka VMC, which does not call + // MCApplication::PreTrack() + static Int_t TrackId = 0; + if (fMcVersion == 2 && fMC->GetStack()->GetCurrentTrackNumber() != TrackId) { + PreTrack(); + TrackId = fMC->GetStack()->GetCurrentTrackNumber(); + } + + // Check if the volume with id is in the volume multimap. + // If it is not in the map the volume is not a sensitive volume + // and we do not call nay of our ProcessHits functions. + + // If the volume is in the multimap, check in second step if the current + // copy is alredy inside the multimap. + // If the volume is not in the multimap add the copy of the volume to the + // multimap. + // In any case call the ProcessHits function for this specific detector. + Int_t copyNo; + Int_t id = fMC->CurrentVolID(copyNo); + Bool_t InMap = kFALSE; + fDisVol = 0; + fDisDet = 0; + Int_t fCopyNo = 0; + fVolIter = fVolMap.find(id); + + if (fVolIter != fVolMap.end()) { + + // Call Process hits for FairVolume with this id, copyNo + do { + fDisVol = fVolIter->second; + fCopyNo = fDisVol->getCopyNo(); + if (copyNo == fCopyNo) { + fDisDet = fDisVol->GetDetector(); + if (fDisDet) { + fDisDet->ProcessHits(fDisVol); + } + InMap = kTRUE; + break; + } + ++fVolIter; + } while (fVolIter != fVolMap.upper_bound(id)); + + // if (fDisVol && !InMap) { // fDisVolume is set previously, no check needed + + // Create new FairVolume with this id, copyNo. + // Use the FairVolume with the same id found in the map to get + // the link to the detector. + // Seems that this never happens (?) + if (!InMap) { + // cout << "Volume not in map; fDisVol ? " << fDisVol << endl + FairVolume* fNewV = new FairVolume(fMC->CurrentVolName(), id); + fNewV->setMCid(id); + fNewV->setModId(fDisVol->getModId()); + fNewV->SetModule(fDisVol->GetModule()); + fNewV->setCopyNo(copyNo); + fVolMap.insert(pair(id, fNewV)); + fDisDet = fDisVol->GetDetector(); + + // LOG(info) << "FairMCApplication::Stepping: new fair volume" + // << id << " " << copyNo << " " << fDisDet; + if (fDisDet) { + fDisDet->ProcessHits(fNewV); + } + } + } + + // If information about the tracks should be stored the information as to be + // stored for any step. + // Information about each single step has also to be stored for the other + // special run modes of the simulation which are used to store information + // about + // 1.) Radiation length in each volume + // 2.) Energy deposition in each volume + // 3.) Fluence of particles through a defined plane which can be anywhere + // in the geometry. This plane has not to be correlated with any real + // volume + if (fTrajAccepted) { + if (fMC->TrackStep() > fTrajFilter->GetStepSizeCut()) { + fMC->TrackPosition(fTrkPos); + fTrajFilter->GetCurrentTrk()->AddPoint(fTrkPos.X(), fTrkPos.Y(), fTrkPos.Z(), fTrkPos.T()); + } + } + if (fRadLenMan) { + id = fMC->CurrentVolID(copyNo); + fModVolIter = fgMasterInstance->fModVolMap.find(id); + fRadLenMan->AddPoint(fModVolIter->second); + } + if (fRadMapMan) { + id = fMC->CurrentVolID(copyNo); + fModVolIter = fgMasterInstance->fModVolMap.find(id); + fRadMapMan->AddPoint(fModVolIter->second); + } + if (fRadGridMan) { + fRadGridMan->FillMeshList(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::PostTrack() +{ + // User actions after finishing of each track + // --- + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->PostTrack(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::FinishPrimary() +{ + // User actions after finishing of a primary track + // --- + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->FinishPrimary(); + } + + fStack->FinishPrimary(); +} + +//_____________________________________________________________________________ +void FairMCApplication::StopRun() +{ + FinishEvent(); + FinishRun(); + if (fRootManager) { + fRootManager->Write(); + fRootManager->CloseSink(); + } + LOG(warn) << "StopRun() exiting not safetly oopps !!!@@@!!!"; + exit(0); +} + +//_____________________________________________________________________________ +void FairMCApplication::StopMCRun() +{ + if (fMC) + fMC->StopRun(); +} + +//_____________________________________________________________________________ +void FairMCApplication::FinishEvent() +{ + // User actions after finishing of an event + // --- + LOG(debug) << "[" << fRootManager->GetInstanceId() + << " FairMCMCApplication::FinishEvent: " << fMCEventHeader->GetEventID() << " (MC " + << gMC->CurrentEvent() << ")"; + if (gMC->IsMT() + && fRun->GetSink()->GetSinkType() == kONLINESINK) { // fix the rare case when running G4 multithreaded on MQ + fMCEventHeader->SetEventID(gMC->CurrentEvent() + 1); + } + + // --> Fill the stack output array + fStack->FillTrackArray(); + // --> Update track indizes in MCTracks and MCPoints + fStack->UpdateTrackIndex(fActiveDetectors); + // --> Screen output of stack + // fStack->Print(); + + if (fFairTaskList) { + fFairTaskList->ExecuteTask(""); + fFairTaskList->FinishEvent(); + } + + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->FinishEvent(); + } + + if (fRootManager && fSaveCurrentEvent) { + fRootManager->Fill(); + } else { + fSaveCurrentEvent = kTRUE; + } + + for (auto detectorPtr : listActiveDetectors) { + detectorPtr->EndOfEvent(); + } + + fStack->Reset(); + if (nullptr != fTrajFilter) { + fTrajFilter->Reset(); + // TObjArray* fListOfTracks=gGeoManager->GetListOfTracks(); + // fListOfTracks->Delete(); + gGeoManager->GetListOfTracks()->Delete(); + } + if (nullptr != fRadLenMan) { + fRadLenMan->Reset(); + } + if (nullptr != fRadMapMan) { + fRadMapMan->Reset(); + } + + // Store information about runtime for one event and memory consuption + // for later usage. + if ((FairRunSim::Instance()->IsRunInfoGenerated()) && !gMC->IsMT()) { + fRunInfo.StoreInfo(); + } +} +//_____________________________________________________________________________ +Double_t FairMCApplication::TrackingRmax() const +{ + // No limit + // --- + return DBL_MAX; +} +//_____________________________________________________________________________ +Double_t FairMCApplication::TrackingZmax() const +{ + // No limit + // --- + return DBL_MAX; +} +//_____________________________________________________________________________ +void FairMCApplication::SetField(FairField* field) { fxField = field; } +//_____________________________________________________________________________ +void FairMCApplication::ConstructOpGeometry() +{ + // The optical properties of ASCII-defined media used to be pushed into the + // MC here (TVirtualMC::SetCerenkov) by walking FairGeoLoader's media list. + // ALICE never loads an ASCII media file, so that list was always empty and + // the loop was a no-op - but it dereferenced FairGeoLoader::Instance() + // unconditionally, which meant the singleton had to be constructed even + // though it did nothing. Detectors that need optical media (HMPID) define + // them in their own ConstructOpGeometry() override, dispatched below. + fModIter->Reset(); + FairModule* Mod = nullptr; + while ((Mod = dynamic_cast(fModIter->Next()))) { + Mod->ConstructOpGeometry(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::ConstructGeometry() +{ + // Construct geometry and also fill following member data: + // - fModVolMap: (volId,moduleId) + // - fSenVolumes: list of sensitive volumes + if (!gGeoManager) { + LOG(fatal) << "gGeoManager not initialized at FairMCApplication::ConstructGeometry\n"; + } + + fState = FairMCApplicationState::kConstructGeometry; + + fModIter->Reset(); + FairModule* Mod = nullptr; + Int_t NoOfVolumes = 0; + Int_t NoOfVolumesBefore = 0; + Int_t ModId = 0; + + TObjArray* tgeovolumelist = gGeoManager->GetListOfVolumes(); + + while ((Mod = dynamic_cast(fModIter->Next()))) { + NoOfVolumesBefore = tgeovolumelist->GetEntriesFast(); + Mod->ConstructGeometry(); + ModId = Mod->GetModId(); + NoOfVolumes = tgeovolumelist->GetEntriesFast(); + for (Int_t n = NoOfVolumesBefore; n < NoOfVolumes; n++) { + TGeoVolume* v = (TGeoVolume*)tgeovolumelist->At(n); + fModVolMap.insert(pair(v->GetNumber(), ModId)); + } + } + + // LOG(debug) << "FairMCApplication::ConstructGeometry() : Now closing the geometry"; + int NoOfVolumesBeforeClose = tgeovolumelist->GetEntries(); + gGeoManager->CloseGeometry(); // close geometry + int NoOfVolumesAfterClose = tgeovolumelist->GetEntries(); + + // Check if CloseGeometry has modified the volume list which might happen for + // runtime shapes (parametrizations,etc). If this is the case, our lookup structures + // built above are likely out of date. Issue at least a warning here. + if (NoOfVolumesBeforeClose != NoOfVolumesAfterClose) { + LOG(error) << "TGeoManager::CloseGeometry() modified the volume list from " << NoOfVolumesBeforeClose << " to " + << NoOfVolumesAfterClose << "\n" + << "This almost certainly means inconsistent lookup structures used in simulation/stepping.\n"; + } + + if (fRun->IsImportTGeoToVMC()) { + TVirtualMC::GetMC()->SetRootGeometry(); // notify VMC about Root geometry + LOG(info) << "TGeometry will be imported to VMC" + << "\n"; + } else { + LOG(info) << "TGeometry will not be imported to VMC" + << "\n"; + } + Int_t Counter = 0; + TDatabasePDG* pdgDatabase = TDatabasePDG::Instance(); + const THashList* list = pdgDatabase->ParticleList(); + if (list == 0) + pdgDatabase->ReadPDGTable(); + list = pdgDatabase->ParticleList(); + if (list != 0) { + TIterator* particleIter = list->MakeIterator(); + TParticlePDG* Particle = 0; + while ((Particle = dynamic_cast(particleIter->Next())) && (Counter <= 256)) { + TString Name = gGeoManager->GetPdgName(Particle->PdgCode()); + // LOG(info) << Counter <<" : Particle name: "<< Name.Data() << " PDG " << Particle->PdgCode(); + if (Name == "XXX") + gGeoManager->SetPdgName(Particle->PdgCode(), Particle->GetName()); + Counter++; + } + delete particleIter; + } + fModIter->Reset(); + while ((Mod = dynamic_cast(fModIter->Next()))) { + Mod->RegisterAlignmentMatrices(); + } + + // dont use this here anymore, use FairMCApplication::MisalignGeometry + // fRun->AlignGeometry() + + gGeoManager->RefreshPhysicalNodes(kFALSE); + + fState = FairMCApplicationState::kUnknownState; +} + +// ____________________________________________________________________________ +Bool_t FairMCApplication::MisalignGeometry() +{ + // call this only here + fRun->AlignGeometry(); + return true; +} + +//_____________________________________________________________________________ +void FairMCApplication::InitGeometry() +{ + fState = FairMCApplicationState::kInitGeometry; + + LOG(info) << "FairMCApplication::InitGeometry: " << fRootManager->GetInstanceId(); + + // ToBeDone + // Recently the InitGeometry is called twice from the G4VMC, This is a work around tell the problem get fixed in + // G4VMC + if (fGeometryIsInitialized) + return; + + /// Initialize geometry + + /** Register stack and detector collections*/ + FairVolume* fv = 0; + Int_t id = 0; + fModIter->Reset(); + + // Register stack + if (fEvGen && fStack && fRootManager) { + fStack->Register(); + } else { + LOG(warn) << "Stack is not registered "; + } + + /** SetSpecialPhysicsCuts for FairDetector objects and all passive modules inheriting from FairModule */ + // initialize and register FairDetector objects in addition + // Note: listActiveDetectors or fActiveDetectors not used to include passive modules in the same loop. + FairModule* module; + FairDetector* detector; + TObject* obj; + fModIter->Reset(); + while ((obj = fModIter->Next())) { + detector = dynamic_cast(obj); + module = dynamic_cast(obj); + if (module) { + module->SetSpecialPhysicsCuts(); + } + if (detector) { + // check whether detector is active + if (detector->IsActive()) { + detector->Initialize(); + detector->Register(); + } + } + } + fModIter->Reset(); + + /**Tasks has to be initialized here, they have access to the detector branches and still can create objects in the + * tree*/ + /// There is always a Main Task ! + /// so .. always a InitTasks() is called + if (fFairTaskList) { + InitTasks(); + } + + // store the EventHeader Info + // Get and register EventHeader + UInt_t runId = FairRunSim::Instance()->GetRunId(); + + LOG(info) << "Simulation RunID: " << runId; + + // Get and register the MCEventHeader + fMCEventHeader = FairRunSim::Instance()->GetMCEventHeader(); + fMCEventHeader->SetRunID(runId); + if (fRootManager) { + fMCEventHeader->Register(); + } + + if (fEvGen) { + fEvGen->SetEvent(fMCEventHeader); + } + fTrajFilter = FairTrajFilter::Instance(); + if (nullptr != fTrajFilter) { + fTrajFilter->Init(); + } + if (nullptr != fRadLenMan) { + fRadLenMan->Init(); + } + if (nullptr != fRadMapMan) { + fRadMapMan->Init(); + } + if (nullptr != fRadGridMan) { + fRadGridMan->Init(); + } + + /// save Geo Params in Output file + if (fRootManager) { + fRootManager->WriteFolder(); + } + + // Get static thread local svList + fSenVolumes = FairModule::svList; + if (fSenVolumes) { + fNoSenVolumes = fSenVolumes->GetEntries(); + } + + // Fill sensitive volumes in fVolMap + for (Int_t i = 0; i < fNoSenVolumes; i++) { + + fv = dynamic_cast(fSenVolumes->At(i)); + if (!fv) { + LOG(error) << "No FairVolume in fSenVolumes at position " << i; + continue; + } + id = fv->getMCid(); + if (fv->getGeoNode() == 0) { + TGeoNode* fN = 0; + TGeoVolume* v = gGeoManager->GetVolume(fv->GetName()); + TObjArray* fNs = 0; + if (v) { + fNs = v->GetNodes(); + } + if (fNs) { + for (Int_t k = 0; k < fNs->GetEntriesFast(); k++) { + fN = dynamic_cast(fNs->At(k)); + if (!fN) { + LOG(error) << "No TGeoNode in fNs at position " << k; + continue; + } + FairVolume* fNewV = new FairVolume(fv->GetName(), id); + fNewV->setModId(fv->getModId()); + fNewV->SetModule(fv->GetModule()); + fNewV->setCopyNo(fN->GetNumber()); + fNewV->setMCid(id); + fVolMap.insert(pair(id, fNewV)); + } + } else { + FairVolume* fNewV = new FairVolume(fv->GetName(), id); + fNewV->setModId(fv->getModId()); + fNewV->SetModule(fv->GetModule()); + fNewV->setCopyNo(1); + fNewV->setMCid(id); + fVolMap.insert(pair(id, fNewV)); + } + } else { + fVolMap.insert(pair(id, fv)); + } + } // end off loop Fill sensitive volumes + + fGeometryIsInitialized = kTRUE; + + fState = FairMCApplicationState::kUnknownState; +} + +//_____________________________________________________________________________ +void FairMCApplication::GeneratePrimaries() +{ + // Fill the user stack (derived from TVirtualMCStack) with primary particles. + // --- + LOG(debug) << "FairMCApplication::GeneratePrimaries: " << fEvGen; + + if (fEvGen) { + // LOG(debug) << "FairMCApplication::GeneratePrimaries()"; + if (!fEvGen->GenerateEvent(fStack)) { + StopRun(); + } + } +} +//_____________________________________________________________________________ +FairDetector* FairMCApplication::GetDetector(const char* DetName) +{ + return dynamic_cast(fModules->FindObject(DetName)); +} +//_____________________________________________________________________________ +void FairMCApplication::AddIons() +{ + TDatabasePDG* pdgDatabase = TDatabasePDG::Instance(); + TObjArray* NewIons = fRun->GetUserDefIons(); + TIterator* Iter = NewIons->MakeIterator(); + Iter->Reset(); + TObject* obj = 0; + FairIon* ion = 0; + while ((obj = Iter->Next())) { + ion = dynamic_cast(obj); + if (ion) { + // Check if an ion with the calculated pdg code already exists in the + // TDatabasePDG. + // If the ion already exist don't create a new one because this fails for + // Geant4. Instead modify the FairIon to use the already existing ion + // from the TDatabasePDG. + // The problem occured for example for Alphas which exist already. + Int_t ionPdg = GetIonPdg(ion->GetZ(), ion->GetA()); + if (!pdgDatabase->GetParticle(ionPdg)) { + fMC->DefineIon( + ion->GetName(), ion->GetZ(), ion->GetA(), ion->GetQ(), ion->GetExcEnergy(), ion->GetMass()); + + } else { + ion->SetName(pdgDatabase->GetParticle(ionPdg)->GetName()); + } + // Add Ion to gGeoManager visualization + if (gGeoManager) { + gGeoManager->SetPdgName(pdgDatabase->GetParticle(ion->GetName())->PdgCode(), ion->GetName()); + } + LOG(info) << "Add Ion: " << ion->GetName() << " with PDG " + << pdgDatabase->GetParticle(ion->GetName())->PdgCode(); + } + } + delete Iter; + /** Initialize the event generator */ + if (fEvGen) { + fEvGen->Init(); + } +} +//_____________________________________________________________________________ +void FairMCApplication::AddParticles() +{ + TObjArray* NewPart = fRun->GetUserDefParticles(); + TIterator* parIter = NewPart->MakeIterator(); + parIter->Reset(); + + // check MC engine is not null (fMC is 0x00 at this line in case of Geant4) + TVirtualMC* curMC = TVirtualMC::GetMC(); + if (!curMC) + LOG(fatal) << "No MC engine was defined before AddParticles()"; + + TObject* obj = 0; + FairParticle* particle = 0; + while ((obj = parIter->Next())) { + particle = dynamic_cast(obj); + if (particle) { // (Int_t pdg, const char* name, TMCParticleType type, Double_t mass, Double_t charge, + // Double_t lifetime); + LOG(info) << "Add Particle: " << particle->GetName() << " with PDG " << particle->GetPDG() << "\n" + << particle->GetName() << " // const TString& name \n" + << particle->GetMCType() << " // TMCParticleType mcType \n" + << particle->GetMass() << " // Double_t mass \n" + << particle->GetCharge() << " // Double_t charge \n" + << particle->GetDecayTime() << " // Double_t lifetime \n" + << particle->GetPType() << " // const TString& pType, \n" + << particle->GetWidth() << " // Double_t width \n" + << particle->GetSpin() << " // Int_t iSpin \n" + << particle->GetiParity() << " // Int_t iParity \n" + << particle->GetConjugation() << " // Int_t iConjugation \n" + << particle->GetIsospin() << " // Int_t iIsospin \n" + << particle->GetIsospinZ() << " // Int_t iIsospinZ \n" + << particle->GetgParity() << " // Int_t gParity \n" + << particle->GetLepton() << " // Int_t lepton \n" + << particle->GetBaryon() << " // Int_t baryon \n" + << particle->IsStable() << " // Bool_t stable \n"; + + curMC->DefineParticle(particle->GetPDG(), // Int_t pdg + particle->GetName(), // const TString& name + particle->GetMCType(), // TMCParticleType mcType + particle->GetMass(), // Double_t mass + particle->GetCharge(), // Double_t charge + particle->GetDecayTime(), // Double_t lifetime + particle->GetPType(), // const TString& pType, + particle->GetWidth(), // Double_t width + particle->GetSpin(), // Int_t iSpin + particle->GetiParity(), // Int_t iParity + particle->GetConjugation(), // Int_t iConjugation + particle->GetIsospin(), // Int_t iIsospin + particle->GetIsospinZ(), // Int_t iIsospinZ + particle->GetgParity(), // Int_t gParity + particle->GetLepton(), // Int_t lepton + particle->GetBaryon(), // Int_t baryon + particle->IsStable() // Bool_t stable + ); + + // Add Particle to gGeoManager visualization + if (gGeoManager) + gGeoManager->SetPdgName(particle->GetPDG(), particle->GetName()); + } + } + + delete parIter; + AddDecayModes(); +} + +//_____________________________________________________________________________ +void FairMCApplication::AddDecayModes() +{ + TString work = getenv("VMCWORKDIR"); + TString work_config = work + "/gconfig/"; + work_config.ReplaceAll("//", "/"); + + TString config_dir = getenv("CONFIG_DIR"); + config_dir.ReplaceAll("//", "/"); + + Bool_t AbsPath = kFALSE; + + if (!config_dir.EndsWith("/")) { + config_dir += "/"; + } + // set Pythia as external decayer + + if (fPythiaDecayer) { + TString decayConfig; + if (fPythiaDecayerConfig.IsNull()) { + decayConfig = "DecayConfig.C"; + fPythiaDecayerConfig = decayConfig; + } else { + if (fPythiaDecayerConfig.Contains("/")) { + AbsPath = kTRUE; + } + decayConfig = fPythiaDecayerConfig; + } + + if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), decayConfig)) != TString("")) { + LOG(info) << "---User path for Configuration (DecayConfig.C) is used : " << config_dir.Data(); + } else { + if (AbsPath) { + decayConfig = fPythiaDecayerConfig; + } else { + decayConfig = work_config + fPythiaDecayerConfig; + } + } + // Add decay modes using an external configuration script + LOG(info) << "External Decay Modes with script \n " << decayConfig.Data(); + // Load configuration script and execute it + Int_t pyt = gROOT->LoadMacro(decayConfig.Data()); + if (pyt == 0) { + gInterpreter->ProcessLine("DecayConfig()"); + } + } + // set user defined phase space decay for particles (ions) + AbsPath = kFALSE; + if (fUserDecay) { + TString Userdecay; + if (fUserDecayConfig.IsNull()) { + Userdecay = "UserDecay.C"; + fUserDecayConfig = Userdecay; + } else { + if (fUserDecayConfig.Contains("/")) { + AbsPath = kTRUE; + } + Userdecay = fUserDecayConfig; + } + + if (!AbsPath && TString(gSystem->FindFile(config_dir.Data(), Userdecay)) != TString("")) { + LOG(info) << "---User path for Configuration (UserDecay.C) is used : " << config_dir.Data(); + } else { + if (AbsPath) { + Userdecay = fUserDecayConfig; + } else { + Userdecay = work_config + fUserDecayConfig; + } + } + LOG(info) << "User Decay Modes with script \n " << Userdecay.Data(); + Int_t dec = gROOT->LoadMacro(Userdecay.Data()); + if (dec == 0) { + gInterpreter->ProcessLine("UserDecayConfig()"); + } + } +} + +//_____________________________________________________________________________ +FairPrimaryGenerator* FairMCApplication::GetGenerator() { return fEvGen; } + +//_____________________________________________________________________________ +void FairMCApplication::SetGenerator(FairPrimaryGenerator* pGen) { fEvGen = pGen; } + +//_____________________________________________________________________________ +void FairMCApplication::AddTask(TTask* fTask) +{ + if (!fFairTaskList) { + fFairTaskList = new FairTask("Task List", 1); + gROOT->GetListOfBrowsables()->Add(fFairTaskList); + } + fFairTaskList->Add(fTask); + SetParTask(); +} + +//_____________________________________________________________________________ +FairGenericStack* FairMCApplication::GetStack() { return fStack; } + +//_____________________________________________________________________________ +TTask* FairMCApplication::GetListOfTasks() { return fFairTaskList; } + +//_____________________________________________________________________________ +void FairMCApplication::SetParTask() +{ + // Only RTDB init when more than Main Task list + if (FairRun::Instance()->GetNTasks() >= 1) { + fFairTaskList->SetParTask(); + } + // The FairRuntimeDb parameter database has been removed: every module's + // SetParContainers() was empty and no container was ever requested. +} +//_____________________________________________________________________________ +void FairMCApplication::InitTasks() +{ + + // Only RTDB init when more than Main Task list + if (FairRun::Instance()->GetNTasks() >= 1) { + LOG(info) << "Initialize Tasks--------------------------"; + fFairTaskList->InitTask(); + } +} + +//_____________________________________________________________________________ +TChain* FairMCApplication::GetChain() +{ + if (fRootManager) { + return fRootManager->GetInChain(); + } else { + LOG(warn) << "The function is not available in MT mode"; + return 0; + } +} + +//_____________________________________________________________________________ +void FairMCApplication::SetRadiationLengthReg(Bool_t RadLen) +{ + fRadLength = RadLen; + if (fRadLength) { + fRadLenMan = new FairRadLenManager(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::SetRadiationMapReg(Bool_t RadMap) +{ + fRadMap = RadMap; + if (fRadMap) { + fRadMapMan = new FairRadMapManager(); + } +} + +//_____________________________________________________________________________ +void FairMCApplication::AddMeshList(TObjArray* meshList) +{ + if (!fRadGridMan) { + fRadGridMan = new FairRadGridManager(); + } + fRadGridMan->AddMeshList(meshList); +} + +//_____________________________________________________________________________ +Int_t FairMCApplication::GetIonPdg(Int_t z, Int_t a) const +{ + // Acording to + // http://pdg.lbl.gov/2012/reviews/rpp2012-rev-monte-carlo-numbering.pdf + + return 1000000000 + 10 * 1000 * z + 10 * a; +} + +//_____________________________________________________________________________ +void FairMCApplication::UndoGeometryModifications() +{ + // Undo all misalignment done in the MisalignGeometry methods of the + // several FairModuls. + // In the output (parameter container and separate geometry file) + // only the ideal geometry is stored. + // I don't know any better way than to loop over all physical nodes + // and to set the matrix back to the original one. + // TODO: Check if it is more easy to write the ideal geometry before + // the geometry is misaligned. In this case one does not have + // to revert the misalignment. + + TObjArray* physNodes = gGeoManager->GetListOfPhysicalNodes(); + Int_t numPhysNodes = physNodes->GetEntriesFast(); + + if (0 == numPhysNodes) + return; + + // fRootManager->CreateGeometryFile("misaligned_geometry.root"); + LOG(info) << "Undo all misalignment"; + + TGeoPhysicalNode* node = nullptr; + TGeoHMatrix* ng3 = nullptr; + for (Int_t k = 0; k < numPhysNodes; k++) { + node = static_cast(physNodes->At(k)); + ng3 = node->GetOriginalMatrix(); //"real" global matrix, what survey sees + node->Align(ng3); + } + + gGeoManager->ClearPhysicalNodes(kFALSE); +} + +ClassImp(FairMCApplication); diff --git a/Detectors/3rdparty/FairRootBase/src/FairMCEventHeader.cxx b/Detectors/3rdparty/FairRootBase/src/FairMCEventHeader.cxx new file mode 100644 index 0000000000000..3709c98aa14ec --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMCEventHeader.cxx @@ -0,0 +1,90 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +// ------------------------------------------------------------------------ +// ----- FairMCEventHeader source file ----- +// ----- ----- +// ----- Created 08/12/05 V. Friese ----- +// ------------------------------------------------------------------------ + +#include "FairMCEventHeader.h" + +#include "FairRootManager.h" + +FairMCEventHeader::FairMCEventHeader() + : TNamed("MCEvent", "MC") + , fRunId(0) + , fEventId(-1) + , fX(0.) + , fY(0.) + , fZ(0.) + , fT(0.) + , fB(0.) + , fNPrim(0) + , fIsSet(kFALSE) + , fRotX(0.) + , fRotY(0.) + , fRotZ(0.) +{} + +FairMCEventHeader::FairMCEventHeader(UInt_t runId) + : TNamed("MCEvent", "MC") + , fRunId(runId) + , fEventId(-1) + , fX(0.) + , fY(0.) + , fZ(0.) + , fT(0.) + , fB(0.) + , fNPrim(0) + , fIsSet(kFALSE) + , fRotX(0.) + , fRotY(0.) + , fRotZ(0.) +{} + +FairMCEventHeader::FairMCEventHeader(Int_t iEvent, + Double_t x, + Double_t y, + Double_t z, + Double_t t, + Double_t b, + Int_t nPrim) + : TNamed("MCEvent", "MC") + , fRunId(0) + , fEventId(iEvent) + , fX(x) + , fY(y) + , fZ(z) + , fT(t) + , fB(b) + , fNPrim(nPrim) + , fIsSet(kFALSE) + , fRotX(0.) + , fRotY(0.) + , fRotZ(0.) +{} + +FairMCEventHeader::~FairMCEventHeader() {} + +void FairMCEventHeader::Reset() +{ + fEventId = -1; + fNPrim = 0; + fX = fY = fZ = fT = fB = 0.; + fIsSet = kFALSE; + fRotX = fRotY = fRotZ = 0.; +} + +void FairMCEventHeader::Register() +{ + // Dot at the end of the name is needed for splitting!! + FairRootManager::Instance()->Register("MCEventHeader.", "Event", this, kTRUE); +} + +ClassImp(FairMCEventHeader); diff --git a/Detectors/3rdparty/FairRootBase/src/FairMCPoint.cxx b/Detectors/3rdparty/FairRootBase/src/FairMCPoint.cxx new file mode 100644 index 0000000000000..77b086b615848 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMCPoint.cxx @@ -0,0 +1,62 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#include "FairMCPoint.h" + +#include "FairLogger.h" + +FairMCPoint::FairMCPoint() + : FairMultiLinkedData_Interface() + , fTrackID(-1) + , fEventId(0) + , fPx(0.) + , fPy(0.) + , fPz(0.) + , fTime(0.) + , fLength(0.) + , fELoss(0.) + , fDetectorID(-1) + , fX(0) + , fY(0) + , fZ(0) +{} + +FairMCPoint::FairMCPoint(Int_t trackID, + Int_t detID, + TVector3 pos, + TVector3 mom, + Double_t tof, + Double_t length, + Double_t eLoss, + UInt_t EventId) + : FairMultiLinkedData_Interface() + , fTrackID(trackID) + , fEventId(EventId) + , fPx(mom.Px()) + , fPy(mom.Py()) + , fPz(mom.Pz()) + , fTime(tof) + , fLength(length) + , fELoss(eLoss) + , fDetectorID(detID) + , fX(pos.X()) + , fY(pos.Y()) + , fZ(pos.Z()) +{} + +FairMCPoint::~FairMCPoint() {} + +void FairMCPoint::Print(const Option_t*) const +{ + LOG(debug) << "FairMC point for track " << fTrackID << " in detector " << fDetectorID; + LOG(debug) << "Position (" << fX << ", " << fY << ", " << fZ << ") cm"; + LOG(debug) << " Momentum (" << fPx << ", " << fPy << ", " << fPz << ") GeV"; + LOG(debug) << " Time " << fTime << " ns, Length " << fLength << " cm, Energy loss " << fELoss * 1.0e06 + << " keV"; +} + +ClassImp(FairMCPoint); diff --git a/Detectors/3rdparty/FairRootBase/src/FairMesh.cxx b/Detectors/3rdparty/FairRootBase/src/FairMesh.cxx new file mode 100644 index 0000000000000..1218e48163316 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMesh.cxx @@ -0,0 +1,100 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairMesh source file ----- +// ----- original author D.Bertini ----- +// ----- adapted april 2010 O.Hartmann ----- +// ------------------------------------------------------------------------- + +#include "FairMesh.h" + +#include // for Sqrt +#include // for TString, operator+ +#include // for operator<<, basic_ostream, etc + +using namespace std; + +FairMesh::FairMesh() + : TObject() + , fXmin(0.0) + , fYmin(0.) + , fZmin(0.) + , fXmax(0.) + , fYmax(0.) + , fZmax(0.) + , NXbin(0) + , NYbin(0) + , NZbin(0) + , fBinVolume(0.) + , fDiag(0.) + , fMeshTid(nullptr) + , fMeshFlu(nullptr) + , fMeshSEU(nullptr) + , fhname("") +{} + +FairMesh::FairMesh(const char* fname) + : TObject() + , fXmin(0.0) + , fYmin(0.) + , fZmin(0.) + , fXmax(0.) + , fYmax(0.) + , fZmax(0.) + , NXbin(0) + , NYbin(0) + , NZbin(0) + , fBinVolume(0.) + , fDiag(0.) + , fMeshTid(nullptr) + , fMeshFlu(nullptr) + , fMeshSEU(nullptr) + , fhname(fname) +{ + // fhname = fname; +} + +void FairMesh::calculate() +{ + // compute numbers + + TString tid = fhname + "TID"; + fMeshTid = new TH2D(tid.Data(), "TID", NXbin, fXmin, fXmax, NYbin, fYmin, fYmax); + fMeshTid->Sumw2(); + + TString flu = fhname + "FLU"; + fMeshFlu = new TH2D(flu.Data(), "Fluence", NXbin, fXmin, fXmax, NYbin, fYmin, fYmax); + fMeshFlu->Sumw2(); + + TString seu = fhname + "SEU"; + fMeshSEU = new TH2D(seu.Data(), "SEU", NXbin, fXmin, fXmax, NYbin, fYmin, fYmax); + fMeshSEU->Sumw2(); + + // reseting + fMeshTid->Reset(); + fMeshFlu->Reset(); + fMeshSEU->Reset(); + + fBinVolume = ((fXmax - fXmin) / NXbin) * ((fYmax - fYmin) / NYbin) * ((fZmax - fZmin) / NZbin); + + fDiag = TMath::Sqrt(((fXmax - fXmin) / NXbin) * ((fXmax - fXmin) / NXbin) + + ((fYmax - fYmin) / NYbin) * ((fYmax - fYmin) / NYbin) + + ((fZmax - fZmin) / NZbin) * ((fZmax - fZmin) / NZbin)); +} + +FairMesh::~FairMesh() {} + +void FairMesh::print() +{ + cout << " Xmin " << fXmin << " Xmax " << fXmax << endl; + cout << " Ymin " << fYmin << " Ymax " << fYmax << endl; + cout << " Zmin " << fZmin << " Zmax " << fZmax << endl; + cout << " NX " << NXbin << " NY " << NXbin << endl; +} + +ClassImp(FairMesh); diff --git a/Detectors/3rdparty/FairRootBase/src/FairModule.cxx b/Detectors/3rdparty/FairRootBase/src/FairModule.cxx new file mode 100644 index 0000000000000..0e2c11d3bf690 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairModule.cxx @@ -0,0 +1,675 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +// ------------------------------------------------------------------------- +// ----- FairModule source file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- +/* Generated by Together */ +#include "FairModule.h" + +#include "FairGeoBuilder.h" // for FairGeoBuilder +#include "FairGeoInterface.h" // for FairGeoInterface +#include "FairGeoLoader.h" // for FairGeoLoader +#include "FairGeoMedia.h" // for FairGeoMedia +#include "FairGeoNode.h" // for FairGeoNode +#include "FairMCApplication.h" +#include "FairRun.h" // for FairRun +#include "FairVolume.h" // for FairVolume +#include "FairVolumeList.h" // for FairVolumeList + +#include // for TBuffer, operator<<, etc +#include // for TIter +#include // for TFile +#include // for TGeoManager, gGeoManager +#include // for TGeoMaterial +#include // for TGeoMatrix, TGeoHMatrix +#include // for TGeoMedium +#include // for TGeoNode +#include // for TGeoVolume +#include // for TGeoVoxelFinder +#include // for TKey +#include // for TList, TListIter +#include // for TObjArray +#include // for TObject +#include // for TRefArray +#include // for TSystem, gSystem +#include + +#ifdef ROOT_HAS_GDML +#include +#endif + +#include +#include // for getenv +#include // for strcmp, strlen + +class FairGeoMedium; + +thread_local TArrayI* FairModule::volNumber = 0; +thread_local Int_t FairModule::fNbOfVolumes = 0; +thread_local FairVolumeList* FairModule::vList = 0; +thread_local TRefArray* FairModule::svList = 0; + +void FairModule::ConstructGeometry() +{ + LOG(warn) + << "The method ConstructGeometry has to be implemented in the detector class which inherits from FairModule"; +} + +void FairModule::ConstructOpGeometry() +{ + LOG(debug2) + << "The method ConstructOpGeometry has to be implemented in the detector class which inherits from FairModule"; +} + +FairModule::~FairModule() {} + +FairModule::FairModule(const char* Name, const char* title, Bool_t Active) + : TNamed(Name, title) + , fMotherVolumeName("") + , fgeoVer("Not defined") + , fgeoName("Not defined") + , fModId(-1) + , fActive(Active) + , fNbOfSensitiveVol(0) + , fVerboseLevel(0) + , flGeoPar(nullptr) + , fGeoSaved(kFALSE) + , fMC(nullptr) +{ + if (!svList) { + svList = new TRefArray(); + } + if (!vList) { + vList = new FairVolumeList(); + } +} + +FairModule::FairModule(const FairModule& rhs) + : TNamed(rhs) + , fMotherVolumeName(rhs.fMotherVolumeName) + , fgeoVer(rhs.fgeoVer) + , fgeoName(rhs.fgeoName) + , fModId(rhs.fModId) + , fActive(rhs.fActive) + , fNbOfSensitiveVol(rhs.fNbOfSensitiveVol) + , fVerboseLevel(rhs.fVerboseLevel) + , flGeoPar(nullptr) + , fGeoSaved(rhs.fGeoSaved) + , fMC(nullptr) +{ + if (!svList) { + svList = new TRefArray(); + for (Int_t i = 0; i < rhs.svList->GetEntries(); i++) { + svList->Add(rhs.svList->At(i)); + } + } + + if (!vList) { + vList = new FairVolumeList(); + for (Int_t i = 0; i < rhs.vList->getEntries(); i++) { + vList->addVolume(rhs.vList->At(i)); + } + } + + // Initialize cached pointer to MC (on worker) + fMC = TVirtualMC::GetMC(); + + // TO DO - add when we know what type is the elements of flGeoPar + // flGeoPar=new TObjArray(); + // TIter it = rhs.flGeoPar->MakeIterator(); + // Copy parameters + // TObject* obj; + // while((obj=it->Next())) { + // flGeoPar->Add(...); + //} +} + +FairModule::FairModule() + : TNamed() + , fMotherVolumeName("") + , fgeoVer("Not defined") + , fgeoName("Not defined") + , fModId(-1) + , fActive(kFALSE) + , fNbOfSensitiveVol(0) + , fVerboseLevel(0) + , flGeoPar(nullptr) + , fGeoSaved(kFALSE) + , fMC(nullptr) +{} + +FairModule& FairModule::operator=(const FairModule& rhs) +{ + // check assignment to self + if (this == &rhs) + return *this; + + // base class assignment + TNamed::operator=(rhs); + + // assignment operator + fMotherVolumeName = rhs.fMotherVolumeName; + fgeoVer = rhs.fgeoVer; + fgeoName = rhs.fgeoName; + fModId = rhs.fModId; + fActive = rhs.fActive; + fNbOfSensitiveVol = rhs.fNbOfSensitiveVol; + fVerboseLevel = rhs.fVerboseLevel; + flGeoPar = nullptr; + fGeoSaved = rhs.fGeoSaved; + fMC = TVirtualMC::GetMC(); + + // TO DO - add when we know what type is the elements of flGeoPar + // flGeoPar=new TObjArray(); + // TIter it = rhs.flGeoPar->MakeIterator(); + // copy parameters + // TObject* obj; + // while((obj=it->Next())) { + // flGeoPar->Add(...); + //} + + return *this; +} + +void FairModule::Streamer(TBuffer& b) +{ + TNamed::Streamer(b); + + if (b.IsReading()) { + fgeoVer.Streamer(b); + fgeoName.Streamer(b); + b >> fActive; + b >> fModId; + } else { + fgeoVer.Streamer(b); + fgeoName.Streamer(b); + b << fActive; + b << fModId; + } +} + +void FairModule::SetGeometryFileName(TString fname, TString) +{ + + // If absolute path is given as argument, try to find it there. + // If the file don't exist break. Don't look anywhere else. + if (fname.BeginsWith("/")) { + if (gSystem->AccessPathName(fname.Data())) { + LOG(fatal) << fName << ": geometry file " << fname << " not found in absolut path!"; + fgeoName = ""; + } // file not found + fgeoName = fname; + LOG(debug) << fName << ": using geometry file " << fgeoName; + return; + } + + // If GEOMPATH is set, try to find the file there. + // If there is no such file go on to look in the default location. + TString userPath = getenv("GEOMPATH"); + userPath.ReplaceAll("//", "/"); + if (!userPath.IsNull()) { + if (!userPath.EndsWith("/")) { + userPath += "/"; + } + fgeoName = userPath + fname; + if (!gSystem->AccessPathName(fgeoName.Data())) { + LOG(debug) << fName << ": using geometry file " << fgeoName; + return; + } + LOG(debug) << fName << ": geometry file " << fname << " not found in GEOMPATH " << userPath; + } + + // Look in the standard path + fgeoName = getenv("VMCWORKDIR"); + fgeoName += "/geometry/" + fname; + if (!gSystem->AccessPathName(fgeoName.Data())) { + LOG(debug) << fName << ": using geometry file " << fgeoName; + return; + } + + // File not found + LOG(fatal) << fName << ": geometry file " << fname << " not found in standard path "; + fgeoName = ""; + return; +} + +// FairModule::ProcessNodes() removed: it imported ASCII-geometry nodes into the +// FairRuntimeDb 'FairGeoParSet' container. O2 builds geometry natively with TGeo +// and the runtime database is gone. +void FairModule::AddSensitiveVolume(TGeoVolume* v) +{ + + LOG(debug2) << "AddSensitiveVolume " << v->GetName(); + + // Only register volumes which are not already registered + // Otherwise the stepping will be slowed down + if (!vList->findObject(v->GetName())) { + FairVolume* volume = nullptr; + volume = new FairVolume(v->GetName(), fNbOfVolumes++); + vList->addVolume(volume); + volume->setModId(fModId); + volume->SetModule(this); + svList->Add(volume); + fNbOfSensitiveVol++; + } +} + +FairVolume* FairModule::getFairVolume(FairGeoNode* fN) +{ + FairVolume* fv; + FairVolume* fvol = 0; + for (Int_t i = 0; i < vList->getEntries(); i++) { + fv = vList->At(i); + if ((fv->getGeoNode()) == fN) { + fvol = fv; + return fvol; + break; + } + } + return fvol; +} + +void FairModule::ConstructRootGeometry(TGeoMatrix* shiftM) +{ + /** Construct the detector geometry from ROOT files, possible inputs are: + * 1. A TGeoVolume as a mother (master) volume containing the detector geometry + * 2. A TGeoManager with the detector geometry + * 3. A TGeoVolume as a mother or Master volume which is the output of the CAD2ROOT geometry, in this case + * the materials are not proprely defined and had to be reset + * In all cases we have to check that the material properties are the same or is the materials defined in + * the current simulation session + */ + TGeoManager* OldGeo = gGeoManager; + TGeoManager* NewGeo = 0; + TGeoVolume* volume = 0; + ; + TFile* f = TFile::Open(GetGeometryFileName().Data()); + TList* l = f->GetListOfKeys(); + TKey* key; + TIter next(l); + TGeoNode* n = 0; + TGeoVolume* v1 = 0; + while ((key = static_cast(next()))) { + /**loop inside the delivered root file and try to fine a TGeoManager object + * the first TGeoManager found will be read + */ + if (strcmp(key->GetClassName(), "TGeoManager") != 0) { + continue; + } + gGeoManager = 0; + NewGeo = static_cast(key->ReadObj()); + break; + } + if (NewGeo != 0) { + /** in case a TGeoManager was found get the top most volume and the node + */ + + NewGeo->cd(); + volume = static_cast(NewGeo->GetNode(0)->GetDaughter(0)->GetVolume()); + v1 = volume->MakeCopyVolume(volume->GetShape()); + // n=NewGeo->GetTopNode(); + n = v1->GetNode(0); + // NewGeo=0; + // delete NewGeo; //move it to the end of the method + + } else { + /** The file does not contain any TGeoManager, so we assume to have a file with a TGeoVolume + * try to look for a TGeoVolume inside the file + */ + + key = static_cast(l->At(0)); // Get the first key in the list + volume = dynamic_cast(key->ReadObj()); + if (volume != 0) { + n = volume->GetNode(0); + } + if (n != 0) { + v1 = n->GetVolume(); + } + } + + if (v1 == 0) { + LOG(fatal) << "Could not find any geometry in file " << GetGeometryFileName().Data(); + } else { + gGeoManager = OldGeo; + gGeoManager->cd(); + // If AddToVolume is empty add the volume to the top volume Cave + // If it is defined check i´f the volume exists and if it exists add the volume from the root file + // to the already existing volume + TGeoVolume* Cave = nullptr; + if (0 == fMotherVolumeName.Length()) { + Cave = gGeoManager->GetTopVolume(); + } else { + Cave = gGeoManager->GetVolume(fMotherVolumeName); + } + if (Cave != nullptr) { + /** Everything is OK, we have a TGeoVolume and now we add it to the simulation TGeoManager */ + gGeoManager->AddVolume(v1); + /** Force rebuilding of voxels */ + TGeoVoxelFinder* voxels = v1->GetVoxels(); + if (voxels) { + voxels->SetNeedRebuild(); + } + + // else { fLogger->Fatal(MESSAGE_ORIGIN, "\033[5m\033[31mFairModule::ConstructRootGeometry(): could not find + // voxels \033[0m"); } + + /**To avoid having different names of the default matrices + * because we could have get the volume from another + * TGeoManager, we reset the default matrix name + */ + TGeoMatrix* M = n->GetMatrix(); + + // very nasty! + TGeoHMatrix* M2 = new TGeoHMatrix(*M); + + // For debugging + // M2->Dump(); + // const Double_t* transl1 = M2->GetTranslation(); + // std::cout << transl1[0] << "\t" << transl1[1] << "\t" << transl1[2] << std::endl; + // if (shiftM) { + // shiftM->Dump(); + // const Double_t* transl2 = shiftM->GetTranslation(); + // std::cout << transl2[0] << "\t" << transl2[1] << "\t" << transl2[2] << std::endl; + //} + + if (shiftM) { + M2->Multiply(shiftM); // HACK! + } + + SetDefaultMatrixName(M2); + + // TODO + // I don't really understand this juggling with the matices, + // so, please, take care of how it works with my changes. + // Egor. + + /** Now we can remove the matrix so that the new geomanager will rebuild it properly*/ + gGeoManager->GetListOfMatrices()->Remove(M2); + TGeoHMatrix* global = gGeoManager->GetHMatrix(); + gGeoManager->GetListOfMatrices()->Remove(global); // Remove the Identity matrix + /** Now we can add the node to the existing cave */ + + Cave->AddNode(v1, 0, M2); + /** correction from O. Merle: in case of a TGeoVolume (v1) set the material properly */ + + AssignMediumAtImport(v1); + /** now go through the herachy and set the materials properly, this is important becase the CAD converter + * produce TGeoVolumes with materials that have only names and no properties + */ + ExpandNode(n); + delete NewGeo; + delete f; + } else { + LOG(fatal) << "Could not find the given mother volume " << fMotherVolumeName.Data() + << " where the geomanger should be added."; + } + } +} + +#ifdef ROOT_HAS_GDML + +void FairModule::ConstructGDMLGeometry(__attribute__((unused)) TGeoMatrix* posrot) +{ + // Parse the GDML file + TFile* old = gFile; + TGDMLParse parser; + TGeoVolume* gdmlTop; + gdmlTop = parser.GDMLReadFile(GetGeometryFileName()); + + // Change ID of media. TGDMLParse starts allways from 0. Need to shift. + ReAssignMediaId(); + + // Add volume to the cave and go through it recursively + gGeoManager->GetTopVolume()->AddNode(gdmlTop, 1, posrot); + ExpandNodeForGDML(gGeoManager->GetTopVolume()->GetNode(gGeoManager->GetTopVolume()->GetNdaughters() - 1)); + gFile = old; +} + +void FairModule::ExpandNodeForGDML(TGeoNode* curNode) +{ + // Get pointer to volume and assign medium + TGeoVolume* curVol = curNode->GetVolume(); + AssignMediumAtImport(curVol); + + // Check if the volume is sensitive + if ((this->InheritsFrom("FairDetector")) && IsSensitive(curVol->GetName())) { + LOG(debug2) << "Sensitive Volume " << curVol->GetName(); + AddSensitiveVolume(curVol); + } + + //! Recursevly go down the tree of nodes + if (curVol->GetNdaughters() != 0) { + TObjArray* NodeChildList = curVol->GetNodes(); + TGeoNode* curNodeChild; + for (Int_t j = 0; j < NodeChildList->GetEntriesFast(); j++) { + curNodeChild = static_cast(NodeChildList->At(j)); + ExpandNodeForGDML(curNodeChild); + } + } +} + +#else + +void FairModule::ConstructGDMLGeometry(__attribute__((unused)) TGeoMatrix* posrot) +{ + LOG(error) << "Could not construct magnet geometry from gdml file."; + LOG(error) << "The used ROOT version does not support gdml."; + LOG(error) << "Please recompile ROOT with gdml support."; + LOG(fatal) << "Stop execution at this point."; +} + +void FairModule::ExpandNodeForGDML(__attribute__((unused)) TGeoNode* curNode) {} + +#endif + +void FairModule::ReAssignMediaId() +{ + if (!FairGeoLoader::Instance()) { + LOG(fatal) << "FairModule: no FairGeoLoader, the ASCII/ROOT geometry import of FairRoot is not set up in O2"; + } + // Initialise pointer to GeoBuilder + FairGeoBuilder* geoBuilder = FairGeoLoader::Instance()->getGeoBuilder(); + // Get list of TGeo media + TList* media = gGeoManager->GetListOfMedia(); + // Loop over new media which are not in GeoBase and shift the ID + TGeoMedium* med; + // TGeoMedium* med2; + for (Int_t i = geoBuilder->GetNMedia(); i < media->GetEntries(); i++) { + med = static_cast(media->At(i)); + med->SetId(i + 1); + } + // Change GeoBase medium index + geoBuilder->SetNMedia(media->GetEntries()); + + // Revove dublicated materials + TList* materials = gGeoManager->GetListOfMaterials(); + TIter next1(materials); + // map for existing materials + std::map mapMatName; + TGeoMaterial* mat; + while ((mat = static_cast(next1()))) { + // If material exist - delete dublicated. If not - set the flag + if (mapMatName[mat->GetName()]) { + materials->Remove(mat); + } else { + mapMatName[mat->GetName()] = kTRUE; + } + } +} + +void FairModule::ConstructASCIIGeometry() +{ + LOG(warn) << "The method ConstructASCIIGeometry has to be implemented in the detector class which inherits from " + "FairModule"; +} + +//__________________________________________________________________________ +Bool_t FairModule::IsSensitive(const std::string& name) +{ + // LOG(warn) << "Implement IsSensitive in the detector class which inherits from FairModule"; + // LOG(warn) << "For now calling the obsolete function CheckIfSensitive"; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + return CheckIfSensitive(name); +#pragma GCC diagnostic pop +} + +void FairModule::ExpandNode(TGeoNode* fN) +{ + // FairGeoLoader* geoLoad = FairGeoLoader::Instance(); + // FairGeoInterface* geoFace = geoLoad->getGeoInterface(); + // FairGeoMedia* Media = geoFace->getMedia(); + // FairGeoBuilder* geobuild=geoLoad->getGeoBuilder(); + TGeoMatrix* Matrix = fN->GetMatrix(); + if (gGeoManager->GetListOfMatrices()->FindObject(Matrix)) { + gGeoManager->GetListOfMatrices()->Remove(Matrix); + } + TGeoVolume* v1 = fN->GetVolume(); + TObjArray* NodeList = v1->GetNodes(); + for (Int_t Nod = 0; Nod < NodeList->GetEntriesFast(); Nod++) { + TGeoNode* fNode = static_cast(NodeList->At(Nod)); + TGeoMatrix* M = fNode->GetMatrix(); + // M->SetDefaultName(); + SetDefaultMatrixName(M); + if (fNode->GetNdaughters() > 0) { + ExpandNode(fNode); + } + TGeoVolume* v = fNode->GetVolume(); + AssignMediumAtImport(v); + if (!gGeoManager->FindVolumeFast(v->GetName())) { + LOG(debug2) << "Register Volume " << v->GetName(); + v->RegisterYourself(); + } + if ((this->InheritsFrom("FairDetector")) && IsSensitive(v->GetName())) { + LOG(debug2) << "Sensitive Volume " << v->GetName(); + AddSensitiveVolume(v); + } + v->GetShape()->AfterStreamer(); + } +} + +void FairModule::SetDefaultMatrixName(TGeoMatrix* matrix) +{ + // Copied from root TGeoMatrix::SetDefaultName() and modified (memory leak) + // If no name was supplied in the ctor, the type of transformation is checked. + // A letter will be prepended to the name : + // t - translation + // r - rotation + // s - scale + // c - combi (translation + rotation) + // g - general (tr+rot+scale) + // The index of the transformation in gGeoManager list of transformations will + // be appended. + if (!gGeoManager) { + return; + } + if (strlen(matrix->GetName())) { + return; + } + char type = 'n'; + if (matrix->IsTranslation()) { + type = 't'; + } + if (matrix->IsRotation()) { + type = 'r'; + } + if (matrix->IsScale()) { + type = 's'; + } + if (matrix->IsCombi()) { + type = 'c'; + } + if (matrix->IsGeneral()) { + type = 'g'; + } + TObjArray* matrices = gGeoManager->GetListOfMatrices(); + Int_t index = 0; + if (matrices) { + index = matrices->GetEntriesFast() - 1; + } + matrix->SetName(Form("%c%i", type, index)); +} + +void FairModule::AssignMediumAtImport(TGeoVolume* v) +{ + + /** + * Assign medium to the the volume v, this has to be done in all cases: + * case 1: For CAD converted volumes they have no mediums (only names) + * case 2: TGeoVolumes, we need to be sure that the material is defined in this session + */ + if (!FairGeoLoader::Instance()) { + LOG(fatal) << "FairModule: no FairGeoLoader, the ASCII/ROOT geometry import of FairRoot is not set up in O2"; + } + FairGeoMedia* Media = FairGeoLoader::Instance()->getGeoInterface()->getMedia(); + FairGeoBuilder* geobuild = FairGeoLoader::Instance()->getGeoBuilder(); + + TGeoMedium* med1 = v->GetMedium(); + + if (med1) { + // In newer ROOT version also a TGeoVolumeAssembly has a material and medium. + // This medium is called dummy and is automatically set when the geometry is constructed. + // Since this material and medium is neither in the TGeoManager (at this point) nor in our + // ASCII file we have to create it the same way it is done in TGeoVolume::CreateDummyMedium() + // In the end the new medium and material has to be added to the TGeomanager, because this is + // not done automatically when using the default constructor. For all other constructors the + // newly created medium or material is added to the TGeomanger. + // Create the medium and material only the first time. + TString medName = static_cast(med1->GetName()); + if (medName.EqualTo("dummy") && nullptr == gGeoManager->GetMedium(medName)) { + + TGeoMaterial* dummyMaterial = new TGeoMaterial(); + dummyMaterial->SetName("dummy"); + + TGeoMedium* dummyMedium = new TGeoMedium(); + dummyMedium->SetName("dummy"); + dummyMedium->SetMaterial(dummyMaterial); + + gGeoManager->GetListOfMedia()->Add(dummyMedium); + gGeoManager->AddMaterial(dummyMaterial); + } + + TGeoMaterial* mat1 = v->GetMaterial(); + TGeoMaterial* newMat = gGeoManager->GetMaterial(mat1->GetName()); + if (newMat == 0) { + /**The Material is not defined in the TGeoManager, we try to create one if we have enough information about + * it*/ + FairGeoMedium* FairMedium = Media->getMedium(mat1->GetName()); + if (!FairMedium) { + LOG(fatal) << "Material " << mat1->GetName() << "is not defined in ASCII file nor in Root file."; + // FairMedium=new FairGeoMedium(mat1->GetName()); + // Media->addMedium(FairMedium); + } else { + + Int_t nmed = geobuild->createMedium(FairMedium); + v->SetMedium(gGeoManager->GetMedium(nmed)); + gGeoManager->SetAllIndex(); + } + } else { + /**Material is already available in the TGeoManager and we can set it */ + TGeoMedium* med2 = gGeoManager->GetMedium(mat1->GetName()); + v->SetMedium(med2); + } + } else { + if (strcmp(v->ClassName(), "TGeoVolumeAssembly") != 0) { + //[R.K.-3.3.08] // When there is NO material defined, set it to avoid conflicts in Geant + LOG(fatal) << "The volume " << v->GetName() + << "has no medium information and not an Assembly so we have to quit"; + } + } +} + +FairModule* FairModule::CloneModule() const +{ + Fatal("CloneModule", "Has to be overriden in multi-threading applications."); + return 0; +} + +ClassImp(FairModule); diff --git a/Detectors/3rdparty/FairRootBase/src/FairMonitor.cxx b/Detectors/3rdparty/FairRootBase/src/FairMonitor.cxx new file mode 100644 index 0000000000000..e72d4373a508a --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMonitor.cxx @@ -0,0 +1,744 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairMonitor.cxx + * + * Created on: Aug 01, 2015 + * Author: r.karabowicz + */ + +#include "FairMonitor.h" + +#include "FairLogger.h" +#include "FairSystemInfo.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +FairMonitor* FairMonitor::instance = nullptr; + +FairMonitor::FairMonitor() + : TNamed("FairMonitor", "Monitor for FairRoot") + , fRunMonitor(kFALSE) + , fDrawCanvas(kFALSE) + , fRunTime(0.) + , fRunMem(0.) + , fTimerMap() + , fMemoryMap() + , fHistList(new TList()) + , fCanvas() + , fNoTaskRequired(0) + , fNoTaskCreated(0) + , fCurrentTask(0) + , fTaskRequired() + , fTaskCreated() + , fTaskCreatedTemp() + , fObjectMap() + , fTaskMap() + , fObjectPos() + , fTaskPos() +{} + +FairMonitor::~FairMonitor() {} + +FairMonitor* FairMonitor::GetMonitor() +{ + if (!instance) { + instance = new FairMonitor(); + } + return instance; +} + +void FairMonitor::StartTimer(const TTask* tTask, const char* identStr) +{ + if (!fRunMonitor) + return; + + TString tempString = Form("timer_%p_%s_%s", tTask, tTask->GetName(), identStr); + + auto itt = fTimerMap.find(tempString); + if (itt == fTimerMap.end()) { + fTimerMap.insert(std::pair(tempString, TStopwatch())); + itt = fTimerMap.find(tempString); + } + fTimerMap[tempString].Start(); +} + +void FairMonitor::StopTimer(const TTask* tTask, const char* identStr) +{ + if (!fRunMonitor) + return; + + TString tempString = Form("timer_%p_%s_%s", tTask, tTask->GetName(), identStr); + + auto itt = fTimerMap.find(tempString); + if (itt == fTimerMap.end()) { + LOG(info) << "FairMonitor::StopTimer() called without matching StartTimer()"; + return; + } + // itt->second + fTimerMap[tempString].Stop(); + + Double_t time = fTimerMap[tempString].RealTime(); + RecordInfo(tTask, Form("%s_TIM", identStr), time); + + if (tempString.EndsWith("_EXEC")) + fRunTime += time; +} + +void FairMonitor::StartMemoryMonitor(const TTask* tTask, const char* identStr) +{ + if (!fRunMonitor) + return; + FairSystemInfo sysInfo; + Int_t memoryAtStart = static_cast(sysInfo.GetCurrentMemory()); + + TString memMon = Form("mem_%p_%s_%s", tTask, tTask->GetName(), identStr); + + auto iti = fMemoryMap.find(memMon); + if (iti == fMemoryMap.end()) + fMemoryMap.insert(std::pair(memMon, memoryAtStart)); + else + iti->second = memoryAtStart; +} + +void FairMonitor::StopMemoryMonitor(const TTask* tTask, const char* identStr) +{ + if (!fRunMonitor) + return; + FairSystemInfo sysInfo; + Int_t memoryAtEnd = static_cast(sysInfo.GetCurrentMemory()); + + TString memMon = Form("mem_%p_%s_%s", tTask, tTask->GetName(), identStr); + + auto iti = fMemoryMap.find(memMon); + if (iti == fMemoryMap.end()) + LOG(warn) << "FairMonitor::StopMemoryMonitor() Could not find corresponding entry for \"" << memMon.Data() + << "\"."; + else { + RecordInfo(tTask, Form("%s_MEM", identStr), memoryAtEnd - iti->second); + + if (memMon.EndsWith("_EXEC")) + fRunMem += memoryAtEnd - iti->second; + } +} + +void FairMonitor::RecordInfo(const TTask* tTask, const char* identStr, Double_t value) +{ + if (!fRunMonitor) + return; + + TString tempString = Form("hist_%p_%s_%s", tTask, tTask->GetName(), identStr); + + Int_t nofHists = fHistList->GetEntries(); + Int_t ihist = 0; + for (ihist = 0; ihist < nofHists; ++ihist) { + if (!tempString.CompareTo(fHistList->At(ihist)->GetName())) { + break; + } + } + if (ihist == nofHists) { + TString titleString = Form("Histogram %s for %s", identStr, tTask->GetName()); + fHistList->Add(new TH1F(tempString, titleString, 1000, 0, 1000)); + } + TH1F* tempHist = (static_cast((fHistList->At(ihist)))); + Int_t nofEntries = tempHist->GetEntries(); + if (nofEntries > tempHist->GetNbinsX()) + tempHist->SetBins(tempHist->GetNbinsX() * 10, 0, tempHist->GetXaxis()->GetXmax() * 10); + + tempHist->SetBinContent(nofEntries + 1, value); +} + +void FairMonitor::RecordRegister(const char* name, const char* folderName, Bool_t toFile) +{ + if (!fRunMonitor) + return; + + LOG(debug) << "*** FM::RecordRegister(" << name << ", " << folderName << (toFile ? ", kTRUE)" : ", kFALSE") + << " for task >>" << fCurrentTask << "<< (" << (fCurrentTask ? fCurrentTask->GetName() : "") << ")"; + if (fCurrentTask == 0) { + fNoTaskCreated++; + LOG(info) << "*** FM::RecordRegister(" << name << ", " << folderName << (toFile ? ", kTRUE)" : ", kFALSE") + << " WITHOUT TASK"; + return; + } + TString tempString = Form("%p_%s", fCurrentTask, fCurrentTask->GetName()); + if (toFile) { + fTaskCreated.insert(std::pair(tempString, TString(name))); + } else { + fTaskCreatedTemp.insert(std::pair(tempString, TString(name))); + } +} + +void FairMonitor::RecordGetting(const char* name) +{ + if (!fRunMonitor) + return; + + LOG(debug) << "*** FM::RecordGetting(" << name << ") for task >>" << fCurrentTask << "<< (" + << (fCurrentTask ? fCurrentTask->GetName() : "") << ")"; + + if (fCurrentTask == 0) { + fNoTaskRequired++; + return; + } + TString tempString = Form("%p_%s", fCurrentTask, fCurrentTask->GetName()); + fTaskRequired.insert(std::pair(tempString, TString(name))); +} + +void FairMonitor::PrintTask(TTask* tempTask, Int_t taskLevel) const +{ + if (!fRunMonitor) + return; + + Int_t nofHists = fHistList->GetEntries(); + TString tempString = ""; + + Double_t timInt = -1.; + Double_t timEnt = 0.; + Int_t memInt = -1.; + + char byteChar[4] = {'B', 'k', 'M', 'G'}; + + for (Int_t ihist = 0; ihist < nofHists; ihist++) { + tempString = Form("%s", fHistList->At(ihist)->GetName()); + if (tempString.Contains(Form("%p", tempTask))) { + if (tempString.Contains("EXEC_TIM")) { + timInt = (static_cast(fHistList->At(ihist))->Integral()); + timEnt = (static_cast(fHistList->At(ihist))->GetEntries()); + } + if (tempString.Contains("EXEC_MEM")) { + memInt = (static_cast(fHistList->At(ihist))->Integral()); + } + } + } + if (timInt < 0) { + LOG(warn) << "FairMonitor::PrintTask(), task \"" << tempTask->GetName() << "\" not found!"; + } else { + // LOG(info) << "\"" << tempTask->GetName() << "\" --> TIME integral = " << timInt << " -- MEMORY integral = + // " << memInt; + TString printString = Form("%f", timInt / timEnt); + for (Int_t itemp = printString.Length(); itemp < 10; itemp++) + printString.Insert(0, ' '); + if (printString.Length() > 10) + printString.Remove(11, 100); + printString += " s/ev |"; + Double_t timePerc = 100. * timInt / fRunTime; + if (timePerc < 100.) + printString += ' '; + if (timePerc < 10.) + printString += ' '; + tempString = Form("%f", timePerc); + for (Int_t itemp = tempString.Length(); itemp < 8; itemp++) + printString += ' '; + printString += tempString; + printString.Remove(27, 100); + Int_t byteIdent = 0; + while (memInt > 1024) { + memInt = memInt / 1024; + byteIdent++; + } + tempString = Form("%4d", memInt); + printString += " % ] "; + if (memInt < 0) + printString += "- - -"; + else { + printString += tempString; + printString += byteChar[byteIdent]; + } + printString += " \""; + for (Int_t ilev = 0; ilev < taskLevel; ilev++) + printString += " "; + printString += tempTask->GetName(); + if (printString.Length() > 80) + printString.Remove(80, 100); + printString += "\""; + Int_t timeFrac = static_cast((timePerc / 100. * 30.)); + + printString.Insert(37, "\033[0m"); + switch (byteIdent) { + case 0: + printString.Insert(32, "\033[42m"); + break; + case 1: + printString.Insert(32, "\033[43m"); + break; + default: + printString.Insert(32, "\033[41m"); + break; + } + printString.Insert(timeFrac, "\033[0m"); + if (timePerc < 30) + printString.Insert(0, "[\033[42m"); + else if (timePerc < 90) + printString.Insert(0, "[\033[43m"); + else + printString.Insert(0, "[\033[41m"); + LOG(info) << printString.Data(); + } + + TList* subTaskList = tempTask->GetListOfTasks(); + if (!subTaskList) + return; + for (Int_t itask = 0; itask < subTaskList->GetEntries(); itask++) { + TTask* subTask = static_cast(subTaskList->At(itask)); + if (subTask) + PrintTask(subTask, taskLevel + 1); + } +} + +void FairMonitor::Print(Option_t*) const +{ + if (!fRunMonitor) { + LOG(warn) << "FairMonitor was disabled. Nothing to print!"; + return; + } + + LOG(info) << "- Total Run Time: " << fRunTime << " s ---------------------------------------------------------"; + TTask* mainFairTask = static_cast((gROOT->GetListOfBrowsables()->FindObject("FairTaskList"))); + if (mainFairTask) + PrintTask(mainFairTask, 0); + LOG(info) << "-------------------------------------------------------------------------------------"; +} + +void FairMonitor::PrintTask(TString specString) const +{ + if (!fRunMonitor) { + LOG(warn) << "FairMonitor was disabled. Nothing to print!"; + return; + } + + TString unitString = ""; + + Int_t nofHists = fHistList->GetEntries(); + for (Int_t ihist = 0; ihist < nofHists; ihist++) { + TString histString = Form("%s", fHistList->At(ihist)->GetName()); + if (histString.Contains(specString)) { + histString.Replace(0, histString.First('_') + 1, ""); + histString.Replace(0, histString.First('_') + 1, ""); + Double_t integral = (static_cast((fHistList->At(ihist)))->Integral()); + Double_t entries = (static_cast((fHistList->At(ihist)))->GetEntries()); + // Double_t valPent = integral/entries; + if (histString.EndsWith("_TIM")) + unitString = " s"; + if (histString.EndsWith("_MEM")) + unitString = " B"; + LOG(info) << histString.Data() << " >>>>> " << integral << unitString.Data() << " / " << entries + << " ent = " << integral / entries << unitString.Data() << " / ent"; + } + } +} + +void FairMonitor::Draw(Option_t*) +{ + if (!fRunMonitor) { + LOG(warn) << "FairMonitor was disabled. Nothing to print!"; + return; + } + + typedef std::map::iterator tiMapIter; + tiMapIter iti; + + TTask* mainFairTask = static_cast((gROOT->GetListOfBrowsables()->FindObject("FairTaskList"))); + if (!mainFairTask) + return; + + GetTaskMap(mainFairTask); + + for (auto itb = fTaskRequired.begin(); itb != fTaskRequired.end(); ++itb) { + iti = fTaskMap.find(itb->first); + if (iti == fTaskMap.end()) + fTaskMap.insert(std::pair(itb->first, 0)); + iti = fObjectMap.find(itb->second); + if (iti == fObjectMap.end()) + fObjectMap.insert(std::pair(itb->second, 0)); + } + for (auto itb = fTaskCreated.begin(); itb != fTaskCreated.end(); ++itb) { + iti = fTaskMap.find(itb->first); + if (iti == fTaskMap.end()) + fTaskMap.insert(std::pair(itb->first, 0)); + iti = fObjectMap.find(itb->second); + if (iti == fObjectMap.end()) + fObjectMap.insert(std::pair(itb->second, 0)); + } + for (auto itb = fTaskCreatedTemp.begin(); itb != fTaskCreatedTemp.end(); ++itb) { + iti = fTaskMap.find(itb->first); + if (iti == fTaskMap.end()) + fTaskMap.insert(std::pair(itb->first, 0)); + iti = fObjectMap.find(itb->second); + if (iti == fObjectMap.end()) + fObjectMap.insert(std::pair(itb->second, 0)); + } + + AnalyzeObjectMap(mainFairTask); + + Int_t maxHierarchyNumber = 0; + for (iti = fObjectMap.begin(); iti != fObjectMap.end(); ++iti) { + if (maxHierarchyNumber < iti->second) + maxHierarchyNumber = iti->second; + } + + LOG(debug) << "Max hierarchy number is " << maxHierarchyNumber; + + fCanvas = new TCanvas("MonitorCanvas", "Fair Monitor", 10, 10, 960, 600); + fCanvas->cd(); + + fCanvas->SetFillStyle(4000); + fCanvas->Range(0, 0, 960, 800); + fCanvas->SetFillColor(0); + fCanvas->SetBorderSize(0); + fCanvas->SetBorderMode(0); + fCanvas->SetFrameFillColor(0); + + for (Int_t ihier = 0; ihier < maxHierarchyNumber + 1; ++ihier) { + Int_t nofHier = 0; + for (iti = fTaskMap.begin(); iti != fTaskMap.end(); ++iti) { + if (iti->second == ihier) { + nofHier++; + } + } + LOG(debug) << "There are " << nofHier << " tasks on level " << ihier << "."; + + if (ihier == 0) { + Double_t iObj = 0.; + for (iti = fTaskMap.begin(); iti != fTaskMap.end(); ++iti) { + if (iti->second == ihier) { + std::pair tempPos(50, 600 - iObj * 40); + fTaskPos.insert(std::pair>(iti->first, tempPos)); + iObj += 1.; + } + } + } else { + Int_t iObj = 0; + Int_t secLine = 0; + Int_t secLineEven = 0; + if (nofHier > 9) { + secLine = 1; + if (nofHier % 2 == 0) + secLineEven = 1; + } + Int_t startingPosition = 575 - nofHier / (1 + secLine) * 45 - secLine * (1 - secLineEven) * 45; + + Double_t topEdge = + 800. + - 800. * (2. * static_cast(ihier) - 0.5) / (static_cast(2 * maxHierarchyNumber + 1)) + + secLine * 15; + LOG(debug) << "for level " << ihier << " will put top edge at " << topEdge << ". " + << (secLineEven ? "Two lines" : "One line") << (secLineEven ? " with offset" : ""); + for (iti = fTaskMap.begin(); iti != fTaskMap.end(); ++iti) { + if (iti->second == ihier) { + std::pair tempPos(startingPosition + iObj * 90 / (1 + secLine) + - secLineEven * (iObj % 2) * 45, + topEdge - 15 - secLine * (iObj % 2) * 35); + fTaskPos.insert(std::pair>(iti->first, tempPos)); + iObj += 1; + } + } + } + + nofHier = 0; + for (iti = fObjectMap.begin(); iti != fObjectMap.end(); ++iti) { + if (TMath::Abs(iti->second) == ihier) { + nofHier++; + } + } + LOG(debug) << "There are " << nofHier << " objects on level " << ihier << "."; + + Int_t iObj = 0; + Int_t secLine = 0; + Int_t secLineEven = 0; + if (nofHier > 9) { + secLine = 1; + if (nofHier % 2 == 0) + secLineEven = 1; + } + Int_t startingPosition = 575 - nofHier / (1 + secLine) * 45 - secLine * (1 - secLineEven) * 45; + + Double_t topEdge = + 800. + - 800. * (2. * static_cast(ihier) + 0.5) / (static_cast(2 * maxHierarchyNumber + 1)) + + secLine * 15; + LOG(debug) << "for level " << ihier << " will put top edge at " << topEdge << ". " + << (secLineEven ? "Two lines" : "One line") << (secLineEven ? " with offset" : ""); + for (iti = fObjectMap.begin(); iti != fObjectMap.end(); ++iti) { + if (TMath::Abs(iti->second) == ihier) { + std::pair tempPos(startingPosition + iObj * 90 / (1 + secLine) + - secLineEven * (iObj % 2) * 45, + topEdge - 15 - secLine * (iObj % 2) * 35); + fObjectPos.insert(std::pair>(iti->first, tempPos)); + iObj += 1; + } + } + } + + typedef std::map>::iterator tddMapIter; + tddMapIter itt; + tddMapIter ito; + + for (auto itb = fTaskRequired.begin(); itb != fTaskRequired.end(); ++itb) { + itt = fTaskPos.find(itb->first); + ito = fObjectPos.find(itb->second); + if (itt != fTaskPos.end() && ito != fObjectPos.end()) { + std::pair taskPos = itt->second; + std::pair objectPos = ito->second; + TArrow* tempArrow = + new TArrow(objectPos.first, objectPos.second - 15, taskPos.first, taskPos.second + 15, 0.01, "|>"); + tempArrow->Draw(); + } + } + for (auto itb = fTaskCreated.begin(); itb != fTaskCreated.end(); ++itb) { + itt = fTaskPos.find(itb->first); + ito = fObjectPos.find(itb->second); + if (itt != fTaskPos.end() && ito != fObjectPos.end()) { + std::pair taskPos = itt->second; + std::pair objectPos = ito->second; + TArrow* tempArrow = + new TArrow(taskPos.first, taskPos.second - 15, objectPos.first, objectPos.second + 15, 0.01, "|>"); + tempArrow->Draw(); + } + } + for (auto itb = fTaskCreatedTemp.begin(); itb != fTaskCreatedTemp.end(); ++itb) { + itt = fTaskPos.find(itb->first); + ito = fObjectPos.find(itb->second); + if (itt != fTaskPos.end() && ito != fObjectPos.end()) { + std::pair taskPos = itt->second; + std::pair objectPos = ito->second; + TArrow* tempArrow = + new TArrow(taskPos.first, taskPos.second - 15, objectPos.first, objectPos.second + 15, 0.01, "|>"); + tempArrow->Draw(); + } + } + + for (itt = fTaskPos.begin(); itt != fTaskPos.end(); ++itt) { + std::pair taskPos = itt->second; + TBox* bkgBox = new TBox(taskPos.first - 40, taskPos.second - 15, taskPos.first + 40, taskPos.second + 15); + bkgBox->SetFillColor(kGreen - 9); + bkgBox->Draw(); + + TString tempString = Form("hist_%s_%s", itt->first.Data(), "EXEC_TIM"); + Int_t nofHists = fHistList->GetEntries(); + for (Int_t ihist = 0; ihist < nofHists; ++ihist) { + if (!tempString.CompareTo(fHistList->At(ihist)->GetName())) { + Double_t timeInt = (static_cast(fHistList->At(ihist))->Integral()); + Double_t timeFrac = 80. * timeInt / fRunTime; + TBox* barBox = new TBox( + taskPos.first - 40, taskPos.second - 15, taskPos.first - 40 + timeFrac, taskPos.second + 15); + barBox->SetFillColor(kRed); + barBox->Draw(); + } + } + + tempString = itt->first; + tempString.Replace(0, tempString.First('_') + 1, ""); + if (tempString.Length() > 16) + tempString.Replace(16, tempString.Length(), ""); + TLatex* taskText = new TLatex(taskPos.first, taskPos.second, tempString.Data()); + taskText->SetTextAlign(22); + taskText->SetTextSize(0.015); + taskText->Draw(); + } + + for (ito = fObjectPos.begin(); ito != fObjectPos.end(); ++ito) { + std::pair objectPos = ito->second; + iti = fObjectMap.find(ito->first); + TPaveText* paveText = new TPaveText( + objectPos.first - 40, objectPos.second - 15, objectPos.first + 40, objectPos.second + 15, "nb"); + paveText->SetFillColor(kMagenta - 9); + if (iti != fObjectMap.end()) + if (iti->second < 0) + paveText->SetFillColor(kGray); + paveText->SetShadowColor(0); + paveText->SetTextSize(0.015); + TString tempString = ito->first; + if (tempString.Length() > 16) + tempString.Replace(16, tempString.Length(), ""); + paveText->AddText(tempString); + paveText->Draw(); + } +} + +void FairMonitor::DrawHist(TString specString) +{ + if (!fRunMonitor) { + LOG(warn) << "FairMonitor was disabled. Nothing to draw!"; + return; + } + + Int_t nofHists = fHistList->GetEntries(); + Int_t nofDraws = 0; + TString drawStr = "P"; + + TLegend* tempLeg = new TLegend(0.0, 0.5, 0.5, 0.9); + + Double_t histMax = 0.; + for (Int_t ihist = 0; ihist < nofHists; ihist++) { + TString histString = Form("%s", fHistList->At(ihist)->GetName()); + if (histString.Contains(specString)) { + TH1F* tempHist = (static_cast((fHistList->At(ihist)))); + if (histMax < tempHist->GetMaximum()) + histMax = tempHist->GetMaximum(); + } + } + + for (Int_t ihist = 0; ihist < nofHists; ihist++) { + TString histString = Form("%s", fHistList->At(ihist)->GetName()); + if (histString.Contains(specString)) { + TH1F* tempHist = (static_cast((fHistList->At(ihist)))); + if (tempHist->GetXaxis()->GetXmax() > tempHist->GetEntries()) + tempHist->SetBins(tempHist->GetEntries(), 0, tempHist->GetEntries()); + tempHist->SetMarkerColor(nofDraws % 6 + 2); + tempHist->SetMarkerStyle(nofDraws % 4 + 20); + tempHist->SetAxisRange(0., histMax * 1.1, "Y"); + tempHist->Draw(drawStr); + TString tempName = tempHist->GetName(); + tempName.Remove(0, tempName.First('_') + 1); + tempName.Remove(0, tempName.First('_') + 1); + tempLeg->AddEntry(tempHist, tempName, "p"); + nofDraws++; + drawStr = "Psame"; + } + } + if (nofDraws > 1) + tempLeg->Draw(); +} + +void FairMonitor::StoreHistograms(TFile* sinkFile) +{ + if (!fRunMonitor) { + return; + } + Bool_t wasBatch = gROOT->IsBatch(); + if (!fDrawCanvas && !wasBatch) // default: switching to batch mode if draw canvas disabled + gROOT->SetBatch(kTRUE); + this->Draw(); + if (!fDrawCanvas && !wasBatch) // default: switching to batch mode if draw canvas disabled + gROOT->SetBatch(kFALSE); + + TFile* histoFile = sinkFile; + if (fOutputFileName.Length() > 1 && fOutputFileName != sinkFile->GetName()) { + histoFile = TFile::Open(fOutputFileName, "recreate"); + } + + histoFile->mkdir("MonitorResults"); + histoFile->cd("MonitorResults"); + TIter next(fHistList); + while (TH1* thist = (static_cast(next()))) { + thist->SetBins(thist->GetEntries(), 0, thist->GetEntries()); + thist->Write(); + } + if (fCanvas) { + fCanvas->Write(); + } + + if (histoFile != sinkFile) { + histoFile->Close(); + delete histoFile; + } +} + +// Private function to fill the map of the tasks +void FairMonitor::GetTaskMap(TTask* tempTask) +{ + TString tempString = Form("%p_%s", tempTask, tempTask->GetName()); + fTaskMap.insert(std::pair(tempString, 0)); + + TList* subTaskList = tempTask->GetListOfTasks(); + if (!subTaskList) + return; + for (Int_t itask = 0; itask < subTaskList->GetEntries(); itask++) { + TTask* subTask = static_cast(subTaskList->At(itask)); + if (subTask) + GetTaskMap(subTask); + } +} + +// Private function to analyze the object list: +// assign to each of the tasks and objects (TClonesArray, pressumably) +// one number that places them in a hierarchy +// objects number 0 are the ones in the input array +// tasks get number from the abs(highest number object they read) increased by one +// tasks number i create objects number i (if they go to output file) or +// tasks number i create objects number -i (if they are not persistent) +void FairMonitor::AnalyzeObjectMap(TTask* tempTask) +{ + TString tempString = Form("%p_%s", tempTask, tempTask->GetName()); + + Int_t hierarchyNumber = 0; + + typedef std::map::iterator tiMapIter; + tiMapIter iti; + + LOG(debug) << "TASK \"" << tempTask->GetName() << "\" NEEDS:"; + for (auto itb = fTaskRequired.begin(); itb != fTaskRequired.end(); ++itb) { + if (itb->first != tempString) + continue; + LOG(debug) << " \"" << itb->second.Data() << "\""; + iti = fObjectMap.find(itb->second); + if (iti == fObjectMap.end()) + continue; + if (hierarchyNumber <= TMath::Abs(iti->second)) + hierarchyNumber = TMath::Abs(iti->second) + 1; + } + + // hierarchyNumber++; + + LOG(debug) << "WILL GET hierarchyNumber = " << hierarchyNumber; + + iti = fTaskMap.find(tempString); + if (iti != fTaskMap.end()) + iti->second = hierarchyNumber; + + LOG(debug) << " \"" << tempTask->GetName() << "\" CREATES:"; + for (auto itb = fTaskCreated.begin(); itb != fTaskCreated.end(); ++itb) { + if (itb->first != tempString) + continue; + LOG(debug) << " + \"" << itb->second.Data() << "\""; + iti = fObjectMap.find(itb->second); + if (iti == fObjectMap.end()) + continue; + iti->second = hierarchyNumber; + } + + for (auto itb = fTaskCreatedTemp.begin(); itb != fTaskCreatedTemp.end(); ++itb) { + if (itb->first != tempString) + continue; + LOG(debug) << " - \"" << itb->second.Data() << "\""; + iti = fObjectMap.find(itb->second); + if (iti == fObjectMap.end()) + continue; + iti->second = -hierarchyNumber; + } + + TList* subTaskList = tempTask->GetListOfTasks(); + if (!subTaskList) + return; + for (Int_t itask = 0; itask < subTaskList->GetEntries(); itask++) { + TTask* subTask = static_cast(subTaskList->At(itask)); + if (subTask) + AnalyzeObjectMap(subTask); + } +} + +ClassImp(FairMonitor); diff --git a/Detectors/3rdparty/FairRootBase/src/FairMultiLinkedData.cxx b/Detectors/3rdparty/FairRootBase/src/FairMultiLinkedData.cxx new file mode 100644 index 0000000000000..4212f3f3bb018 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMultiLinkedData.cxx @@ -0,0 +1,356 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairMultiLinkedData.cxx + * + * Created on: Dec 7, 2009 + * Author: stockman + */ + +#include "FairMultiLinkedData.h" + +#include "FairLinkManager.h" // for FairLinkManager +#include "FairMultiLinkedData_Interface.h" +#include "FairRootManager.h" // for FairRootManager + +#include // for TClonesArray +#include // for find +#include // for distance + +ClassImp(FairMultiLinkedData); + +FairMultiLinkedData::FairMultiLinkedData() + : TObject() + , fLinks() + , fEntryNr() + , fPersistanceCheck(kTRUE) + , fInsertHistory(kTRUE) + , fVerbose(0) + , fDefaultType(0) +{} + +FairMultiLinkedData::FairMultiLinkedData(const std::set& links, Bool_t persistanceCheck) + : TObject() + , fLinks(links) + , fEntryNr() + , fPersistanceCheck(persistanceCheck) + , fInsertHistory(kTRUE) + , fVerbose(0) + , fDefaultType(0) +{} + +FairMultiLinkedData::FairMultiLinkedData(TString dataType, + const std::vector& links, + Int_t fileId, + Int_t evtId, + Bool_t persistanceCheck, + Bool_t bypass, + Float_t mult) + : TObject() + , fLinks() + , fEntryNr() + , fPersistanceCheck(persistanceCheck) + , fInsertHistory(kTRUE) + , fVerbose(0) + , fDefaultType(0) +{ + SimpleAddLinks(fileId, evtId, FairRootManager::Instance()->GetBranchId(dataType), links, bypass, mult); + // FairMultiLinkedData(ioman->GetBranchId(dataType), links, persistanceCheck, bypass, addup, mult); +} + +FairMultiLinkedData::FairMultiLinkedData(Int_t dataType, + const std::vector& links, + Int_t fileId, + Int_t evtId, + Bool_t persistanceCheck, + Bool_t bypass, + Float_t mult) + : TObject() + , fLinks() + , fEntryNr() + , fPersistanceCheck(persistanceCheck) + , fInsertHistory(kTRUE) + , fVerbose(0) + , fDefaultType(0) +{ + SimpleAddLinks(fileId, evtId, dataType, links, bypass, mult); +} + +FairLink FairMultiLinkedData::GetLink(Int_t pos) const +{ + if (pos < static_cast(fLinks.size())) { + // return value at iterator+pos + return *(std::next(fLinks.begin(), pos)); + } else { + std::cout << "-E- FairMultiLinkedData:GetLink(pos) pos " << pos << " outside range " << fLinks.size() + << std::endl; + return FairLink(); + } +} + +void FairMultiLinkedData::SetLinks(FairMultiLinkedData links, Float_t mult) +{ + fLinks.clear(); + AddLinks(links, mult); +} + +void FairMultiLinkedData::SetLink(FairLink link, Bool_t bypass, Float_t mult) +{ + fLinks.clear(); + Float_t weight = link.GetWeight() * mult; + link.SetWeight(weight); + AddLink(link, bypass); +} + +void FairMultiLinkedData::AddLinks(FairMultiLinkedData links, Float_t mult) +{ + std::set myLinks = links.GetLinks(); + for (auto link : myLinks) { + link.SetWeight(link.GetWeight() * mult); + AddLink(link); + } +} + +void FairMultiLinkedData::AddLink(FairLink link, Bool_t bypass, Float_t mult) +{ + Float_t weight = link.GetWeight() * mult; + link.SetWeight(weight); + // std::cout << fVerbose << std::endl; + + FairRootManager* ioman = FairRootManager::Instance(); + + if (ioman == 0) { + std::cout << "-W- no IOManager present!" << std::endl; + fPersistanceCheck = kFALSE; + } + if (fVerbose > 1) { + std::cout << "Add FairLink: " << link << std::endl; + } + + if (fPersistanceCheck == kFALSE || link.GetIndex() < 0 + || (link.GetType() != ioman->GetMCTrackBranchId() + && ioman->CheckBranch(ioman->GetBranchName(link.GetType())) == 0)) { + InsertLink(link); + if (fInsertHistory == kTRUE) + InsertHistory(link); + return; + } + + if (bypass == kFALSE) { + if (fVerbose > 1) { + std::cout << "BranchName " << ioman->GetBranchName(link.GetType()) + << " checkStatus: " << ioman->CheckBranch(ioman->GetBranchName(link.GetType())) << std::endl; + } + if (link.GetType() > ioman->GetMCTrackBranchId() + && ioman->CheckBranch(ioman->GetBranchName(link.GetType())) != 1) { + if (fVerbose > 1) { + std::cout << "BYPASS!" << std::endl; + } + // bypass = kTRUE; + } + } + + if (bypass == kTRUE) { + // FairRootManager* ioman = FairRootManager::Instance(); + if (link.GetType() > ioman->GetMCTrackBranchId()) { + TClonesArray* array = static_cast(ioman->GetObject(ioman->GetBranchName(link.GetType()))); + if (fVerbose > 1) { + std::cout << "Entries in " << ioman->GetBranchName(link.GetType()) << " Array: " << array->GetEntries() + << std::endl; + } + FairMultiLinkedData* links = static_cast(array->At(link.GetIndex())); + if (fVerbose > 1) { + std::cout << "FairMultiLinkedData has " << links->GetNLinks() << " Entries: " << std::endl; + std::cout << *links << std::endl; + } + AddLinks(*links, mult); + return; + } else { + InsertLink(link); + if (fInsertHistory == kTRUE) + InsertHistory(link); + } + } else { + InsertLink(link); + if (fInsertHistory == kTRUE) + InsertHistory(link); + } +} + +void FairMultiLinkedData::InsertLink(FairLink link) +{ + if (FairLinkManager::Instance()->IsIgnoreType(link.GetType())) { + return; + } + + std::set::iterator it = fLinks.find(link); + if (it != fLinks.end()) { + FairLink myTempLink = *it; + myTempLink.AddWeight(link.GetWeight()); + fLinks.erase(it); + fLinks.insert(myTempLink); + } else { + fLinks.insert(link); + } + return; +} + +void FairMultiLinkedData::InsertHistory(FairLink link) +{ + FairRootManager* ioman = FairRootManager::Instance(); + FairMultiLinkedData* pointerToLinks = 0; + + if (fVerbose > 1) { + std::cout << "FairMultiLinkedData::InsertHistory for Link " << link + << " Type: " << ioman->GetBranchName(link.GetType()) << std::endl; + } + + if (link.GetType() < 0) + return; + if (link.GetType() == ioman->GetMCTrackBranchId()) + return; + if (ioman->GetBranchName(link.GetType()).Contains(".")) + return; + if (link.GetEntry() != -1 && link.GetEntry() != ioman->GetEntryNr()) + return; + + if (link.GetIndex() < 0) { // if index is -1 then this is not a TClonesArray so only the Object is returned + TObject* myObject = ioman->GetObject(ioman->GetBranchName(link.GetType())); + if (myObject->InheritsFrom("FairMultiLinkedData_Interface")) { + FairMultiLinkedData_Interface* interface = static_cast(myObject); + pointerToLinks = interface->GetPointerToLinks(); + } else { + std::cout << "FairMultiLinkedData::InsertHistory Link to wrong Class: " + << ioman->GetBranchName(link.GetType()) << std::endl; + return; + } + } else { + TClonesArray* dataArray = static_cast(ioman->GetObject(ioman->GetBranchName(link.GetType()))); + if (dataArray != 0 && link.GetIndex() < dataArray->GetEntriesFast()) { + TObject* myObject = dataArray->At(link.GetIndex()); + if (myObject->InheritsFrom("FairMultiLinkedData_Interface")) { + FairMultiLinkedData_Interface* interface = static_cast(myObject); + pointerToLinks = interface->GetPointerToLinks(); + } else { + std::cout << "FairMultiLinkedData::InsertHistory Link to wrong Class: " + << ioman->GetBranchName(link.GetType()) << std::endl; + return; + } + } + } + if (pointerToLinks != 0) { + std::set linkSet = pointerToLinks->GetLinks(); + for (auto tlink : linkSet) { + if (fVerbose > 1) + std::cout << "FairMultiLinkedData::InsertHistory inserting " << tlink << std::endl; + InsertLink(tlink); + } + } +} + +Bool_t FairMultiLinkedData::IsLinkInList(Int_t type, Int_t index) +{ + if (LinkPosInList(type, index) > -1) { + return kTRUE; + } + return kFALSE; +} + +Int_t FairMultiLinkedData::LinkPosInList(Int_t type, Int_t index) +{ + std::set::iterator it = std::find(fLinks.begin(), fLinks.end(), FairLink(type, index)); + if (it != fLinks.end()) { + return std::distance(fLinks.begin(), it); + } + return -1; +} + +void FairMultiLinkedData::DeleteLink(Int_t /*type*/, Int_t /*index*/) +{ + /* Int_t pos = LinkPosInList(type, index); + if (pos < 0) return; + else{ + fLinks.erase(fLinks.begin()+pos); + }*/ +} + +FairMultiLinkedData FairMultiLinkedData::GetLinksWithType(Int_t type) const +{ + FairMultiLinkedData result; + for (auto link : fLinks) { + if (link.GetType() == type) { + result.InsertLink(link); + } + } + return result; +} + +bool LargerWeight(FairLink val1, FairLink val2) { return val1.GetWeight() > val2.GetWeight(); } + +std::vector FairMultiLinkedData::GetSortedMCTracks() +{ + FairMultiLinkedData mcLinks = GetLinksWithType(FairRootManager::Instance()->GetMCTrackBranchId()); + std::set mcSet = mcLinks.GetLinks(); + std::vector mcVector(mcSet.begin(), mcSet.end()); + // std::sort(begin(mcVector), end(mcVector), [](FairLink& val1, FairLink& val2){ return val1.GetWeight() > + // val2.GetWeight();}); + std::sort(begin(mcVector), end(mcVector), LargerWeight); + return mcVector; +} + +TObject* FairMultiLinkedData::GetData(FairLink& myLink) +{ + FairRootManager* ioman = FairRootManager::Instance(); + TString branchName = ioman->GetBranchName(myLink.GetType()); + if (ioman->CheckBranch(branchName) > 0) { + TClonesArray* myArray = static_cast(ioman->GetObject(branchName)); + if (myArray != 0) { + if (myArray->GetEntries() > myLink.GetIndex()) { + return myArray->At(myLink.GetIndex()); + } else { + std::cout << "-E- FairMultiLinkedData::GetData index out of bounds" << std::endl; + } + } else { + std::cout << "-E- FairMultiLinkedData::GetData no TClonesArray" << std::endl; + } + } else { + std::cout << "-E- FairMultiLinkedData::GetData Branch does not exist in Memory" << std::endl; + } + + return 0; +} + +void FairMultiLinkedData::SetAllWeights(Double_t weight) +{ + std::set tempLinks; + for (auto link : fLinks) { + link.SetWeight(weight); + tempLinks.insert(link); + } + fLinks = tempLinks; +} + +void FairMultiLinkedData::AddAllWeights(Double_t weight) +{ + std::set tempLinks; + for (auto link : fLinks) { + link.SetWeight(weight + link.GetWeight()); + tempLinks.insert(link); + } + fLinks = tempLinks; +} + +void FairMultiLinkedData::MultiplyAllWeights(Double_t weight) +{ + std::set tempLinks; + for (auto link : fLinks) { + link.SetWeight(weight * link.GetWeight()); + tempLinks.insert(link); + } + fLinks = tempLinks; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairMultiLinkedData_Interface.cxx b/Detectors/3rdparty/FairRootBase/src/FairMultiLinkedData_Interface.cxx new file mode 100644 index 0000000000000..cf4295f913591 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairMultiLinkedData_Interface.cxx @@ -0,0 +1,206 @@ +/* + * FairMultiLinkedData_Interface.cxx + * + * Created on: Dec 7, 2009 + * Author: stockman + */ + +#include "FairMultiLinkedData_Interface.h" + +#include "FairRootManager.h" // for FairRootManager + +ClassImp(FairMultiLinkedData_Interface); + +FairMultiLinkedData_Interface::FairMultiLinkedData_Interface(FairMultiLinkedData& links, Bool_t) +{ + SetLinks(links); +} + +FairMultiLinkedData_Interface::FairMultiLinkedData_Interface(TString dataType, + std::vector links, + Int_t fileId, + Int_t evtId, + Bool_t persistanceCheck, + Bool_t bypass, + Float_t mult) +{ + FairMultiLinkedData data(dataType, links, fileId, evtId, persistanceCheck, bypass, mult); + SetLinks(data); +} + +FairMultiLinkedData_Interface::FairMultiLinkedData_Interface(Int_t dataType, + std::vector links, + Int_t fileId, + Int_t evtId, + Bool_t persistanceCheck, + Bool_t bypass, + Float_t mult) +{ + FairMultiLinkedData data(dataType, links, fileId, evtId, persistanceCheck, bypass, mult); + SetLinks(data); +} + +FairMultiLinkedData_Interface::FairMultiLinkedData_Interface(const FairMultiLinkedData_Interface& toCopy) + : TObject(toCopy) +{ + if (toCopy.GetPointerToLinks() != 0) { + SetInsertHistory(kFALSE); + SetLinks(*(toCopy.GetPointerToLinks())); + SetEntryNr(toCopy.GetEntryNr()); + // copy history flag information + SetInsertHistory(toCopy.GetPointerToLinks()->GetInsertHistory()); + } +} + +FairMultiLinkedData_Interface& FairMultiLinkedData_Interface::operator=(const FairMultiLinkedData_Interface& rhs) +{ + if (rhs.GetPointerToLinks() != 0) { + SetInsertHistory(kFALSE); + SetLinks(*(rhs.GetPointerToLinks())); + SetEntryNr(rhs.GetEntryNr()); + SetInsertHistory(kTRUE); + } + return *this; +} + +FairMultiLinkedData* FairMultiLinkedData_Interface::CreateFairMultiLinkedData() +{ + if (FairRootManager::Instance() != nullptr) { + if (FairRootManager::Instance()->GetUseFairLinks()) { + if (fLink == nullptr) { + fLink.reset(new FairMultiLinkedData()); + } + return fLink.get(); + } + } + return 0; +} + +std::set FairMultiLinkedData_Interface::GetLinks() const +{ + if (GetPointerToLinks() != 0) { + return GetPointerToLinks()->GetLinks(); + } else { + std::set emptySet; + return emptySet; + } +} + +Int_t FairMultiLinkedData_Interface::GetNLinks() const +{ + if (GetPointerToLinks() != 0) { + return GetPointerToLinks()->GetNLinks(); + } else { + return 0; + } +} + +FairLink FairMultiLinkedData_Interface::GetLink(Int_t pos) const +{ + if (GetPointerToLinks() != 0) { + return GetPointerToLinks()->GetLink(pos); + } else { + FairLink emptyLink; + return emptyLink; + } +} + +FairLink FairMultiLinkedData_Interface::GetEntryNr() const +{ + if (GetPointerToLinks() != 0) { + return GetPointerToLinks()->GetEntryNr(); + } else { + FairLink emptyLink; + return emptyLink; + } +} + +FairMultiLinkedData FairMultiLinkedData_Interface::GetLinksWithType(Int_t type) const +{ + if (GetPointerToLinks() != 0) { + return GetPointerToLinks()->GetLinksWithType(type); + } else { + FairMultiLinkedData emptyLinks; + return emptyLinks; + } +} + +std::vector FairMultiLinkedData_Interface::GetSortedMCTracks() +{ + if (GetPointerToLinks() != 0) { + return GetPointerToLinks()->GetSortedMCTracks(); + } else { + std::vector empty; + return empty; + } +} + +void FairMultiLinkedData_Interface::SetLinks(FairMultiLinkedData links) +{ + CreateFairMultiLinkedData(); + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->SetLinks(links); + } +} + +void FairMultiLinkedData_Interface::SetLink(FairLink link) +{ + CreateFairMultiLinkedData(); + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->SetLink(link); + } +} + +void FairMultiLinkedData_Interface::SetEntryNr(FairLink val) +{ + CreateFairMultiLinkedData(); + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->SetEntryNr(val); + } +} + +void FairMultiLinkedData_Interface::AddLinks(FairMultiLinkedData links, Float_t mult) +{ + CreateFairMultiLinkedData(); + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->AddLinks(links, mult); + } +} + +void FairMultiLinkedData_Interface::AddLink(FairLink link) +{ + CreateFairMultiLinkedData(); + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->AddLink(link); + } +} + +void FairMultiLinkedData_Interface::AddInterfaceData(FairMultiLinkedData_Interface* data) +{ + SetInsertHistory(kFALSE); // todo add previous history value + if (data->GetEntryNr().GetType() != -1) + AddLink(data->GetEntryNr()); + else + std::cout << "-E- FairMultiLinkedData_Interface::AddInterfaceData EntryNr == " << data->GetEntryNr() + << std::endl; + + if (data->GetPointerToLinks() != 0) { + AddLinks(*data->GetPointerToLinks()); + } + SetInsertHistory(GetPointerToLinks()->GetInsertHistory()); +} + +void FairMultiLinkedData_Interface::SetInsertHistory(Bool_t val) +{ + CreateFairMultiLinkedData(); + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->SetInsertHistory(val); + } +} + +void FairMultiLinkedData_Interface::ResetLinks() +{ + if (GetPointerToLinks() != 0) { + GetPointerToLinks()->ResetLinks(); + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairParticle.cxx b/Detectors/3rdparty/FairRootBase/src/FairParticle.cxx new file mode 100644 index 0000000000000..9df85a22b07c0 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairParticle.cxx @@ -0,0 +1,366 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairParticle source file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +// Extended TParticle with pointers to mother and daughters particles + +#include "FairParticle.h" + +#include // for TDatabasePDG +#include // for TMCParticleType::kPTIon, etc +#include // for TParticle +#include // for TParticlePDG +#include // for operator<<, basic_ostream, etc + +using std::cout; +using std::endl; + +ClassImp(FairParticle); + +FairParticle::FairParticle(Int_t id, TParticle* particle) + : TObject() + , fpdg(id) + , fParticle(particle) + , fMother(0) + , fDaughters(0) + , fname(particle->GetName()) + , fmcType(kPTIon) + , fmass(particle->GetMass()) + , fcharge(particle->GetPDG()->Charge()) + , fDecayTime(particle->GetPDG()->Lifetime()) + , fpType("Ion") + , fwidth(particle->GetPDG()->Width()) + , fiSpin(static_cast(particle->GetPDG()->Spin())) + , fiParity(particle->GetPDG()->Parity()) + , fiConjugation(0) + , fiIsospin(static_cast(particle->GetPDG()->Isospin())) + , fiIsospinZ(0) + , fgParity(0) + , flepton(0) + , fbaryon(0) + , fstable(particle->GetPDG()->Stable()) +{} + +FairParticle::FairParticle(const char* name, + Int_t z, + Int_t a, + Int_t s, + Double_t mass, + Int_t q, + Bool_t stable, + Double_t decaytime) + : TObject() + , fpdg(1000000000 + 10000000 * s + 10000 * z + 10 * a) + , fParticle(0) + , fMother(0) + , fDaughters(0) + , fname(name) + , fmcType(kPTIon) + , fmass(0) + , fcharge(0) + , fDecayTime(decaytime) + , fpType("Ion") + , fwidth(0) + , fiSpin(0) + , fiParity(0) + , fiConjugation(0) + , fiIsospin(0) + , fiIsospinZ(0) + , fgParity(0) + , flepton(0) + , fbaryon(0) + , fstable(stable) +{ + + TDatabasePDG* pdgDB = TDatabasePDG::Instance(); + if (!pdgDB->GetParticle(fpdg)) { + if (mass == 0) { + TParticlePDG* kProton = pdgDB->GetParticle(2212); + Double_t kProtonMass = kProton->Mass(); + mass = a * kProtonMass; + } + pdgDB->AddParticle(name, name, mass, stable, 0, q, "kPTHadron", fpdg); + } + + fParticle = new TParticle(); + fParticle->SetPdgCode(fpdg); + + fmcType = kPTHadron; + fmass = mass; + fcharge = fParticle->GetPDG()->Charge(); + fDecayTime = decaytime; + fwidth = fParticle->GetPDG()->Width(); + fiSpin = static_cast(fParticle->GetPDG()->Spin()); + fiParity = fParticle->GetPDG()->Parity(); + fiConjugation = 0; + fiIsospin = static_cast(fParticle->GetPDG()->Isospin()); + fiIsospinZ = 0; + fgParity = 0; + flepton = 0; + fbaryon = 0; + fstable = fParticle->GetPDG()->Stable(); +} + +FairParticle::FairParticle(const char* name, + Int_t z, + Int_t a, + Double_t mass, + Int_t q, + Bool_t stable, + Double_t decaytime) + : TObject() + , fpdg(10000000 + 10000 * z + 10 * a) + , fParticle(0) + , fMother(0) + , fDaughters(0) + , fname(name) + , fmcType(kPTIon) + , fmass(0) + , fcharge(0) + , fDecayTime(decaytime) + , fpType("Ion") + , fwidth(0) + , fiSpin(0) + , fiParity(0) + , fiConjugation(0) + , fiIsospin(0) + , fiIsospinZ(0) + , fgParity(0) + , flepton(0) + , fbaryon(0) + , fstable(stable) +{ + // fpdg= 10000000+10000* z +10 * a; + + // fDecayTime= decaytime; + TDatabasePDG* pdgDB = TDatabasePDG::Instance(); + + if (!pdgDB->GetParticle(fpdg)) { + if (mass == 0) { + TParticlePDG* kProton = pdgDB->GetParticle(2212); + Double_t kProtonMass = kProton->Mass(); + mass = a * kProtonMass; + } + pdgDB->AddParticle(name, name, mass, stable, 0, q, "kPTHadron", fpdg); + } + + fParticle = new TParticle(); + fParticle->SetPdgCode(fpdg); + + fmcType = kPTHadron; + fmass = mass; + fcharge = fParticle->GetPDG()->Charge(); + fDecayTime = decaytime; + fwidth = fParticle->GetPDG()->Width(); + fiSpin = static_cast(fParticle->GetPDG()->Spin()); + fiParity = fParticle->GetPDG()->Parity(); + fiConjugation = 0; + fiIsospin = static_cast(fParticle->GetPDG()->Isospin()); + fiIsospinZ = 0; + fgParity = 0; + flepton = 0; + fbaryon = 0; + fstable = fParticle->GetPDG()->Stable(); +} + +FairParticle::FairParticle(Int_t id, TParticle* particle, FairParticle* mother) + : TObject() + , fpdg(id) + , fParticle(particle) + , fMother(mother) + , fDaughters() + , fname(particle->GetName()) + , fmcType(kPTIon) + , fmass(0) + , fcharge(0) + , fDecayTime(0) + , fpType("Ion") + , fwidth(0) + , fiSpin(0) + , fiParity(0) + , fiConjugation(0) + , fiIsospin(0) + , fiIsospinZ(0) + , fgParity(0) + , flepton(0) + , fbaryon(0) + , fstable(kTRUE) + +{} + +FairParticle::FairParticle(Int_t pdg, + const TString name, + TMCParticleType mcType, + Double_t mass, + Double_t charge, + Double_t lifetime, + const TString pType, + Double_t width, + Int_t iSpin, + Int_t iParity, + Int_t iConjugation, + Int_t iIsospin, + Int_t iIsospinZ, + Int_t gParity, + Int_t lepton, + Int_t baryon, + Bool_t stable) + : TObject() + , fpdg(pdg) + , fParticle(new TParticle()) + , fMother(0) + , fDaughters(0) + , fname(name) + , fmcType(mcType) + , fmass(mass) + , fcharge(charge) + , fDecayTime(lifetime) + , fpType(pType) + , fwidth(width) + , fiSpin(iSpin) + , fiParity(iParity) + , fiConjugation(iConjugation) + , fiIsospin(iIsospin) + , fiIsospinZ(iIsospinZ) + , fgParity(gParity) + , flepton(lepton) + , fbaryon(baryon) + , fstable(stable) +{ + + if (!TDatabasePDG::Instance()->GetParticle(fpdg)) { + TDatabasePDG::Instance()->AddParticle(fname, fname, fmass, fstable, fwidth, fcharge, pType, fpdg); + } + + fParticle->SetPdgCode(fpdg); +} + +FairParticle::FairParticle() + : TObject() + , fpdg(0) + , fParticle(0) + , fMother(0) + , fDaughters() + , fname("ion") + , fmcType(kPTIon) + , fmass(0) + , fcharge(0) + , fDecayTime(0) + , fpType("Ion") + , fwidth(0) + , fiSpin(0) + , fiParity(0) + , fiConjugation(0) + , fiIsospin(0) + , fiIsospinZ(0) + , fgParity(0) + , flepton(0) + , fbaryon(0) + , fstable(kTRUE) +{} + +FairParticle::~FairParticle() { delete fParticle; } + +// +// public methods +// + +void FairParticle::SetMother(FairParticle* particle) +{ + // Adds particles daughter + // --- + + fMother.SetObject(particle); +} + +void FairParticle::AddDaughter(FairParticle* particle) +{ + // Adds particles daughter + // --- + + fDaughters.Add(particle); +} + +void FairParticle::Print(Option_t*) const +{ + // Prints particle properties. + // --- + // return; + + cout << "Particle: " << fParticle->GetName() << " with ID: " << fpdg << endl; + + // fParticle->Print(); + + if (GetMother()) { + cout << "Mother: " << GetMother()->GetParticle()->GetName() << " with ID: " << GetMother()->GetPDG() + << endl; + } else { + cout << "Primary " << endl; + } + + cout << "Number of daughters: " << GetNofDaughters() << endl; + cout << endl; +} + +void FairParticle::PrintDaughters() const +{ + // Prints particles daughters. + // --- + + for (Int_t i = 0; i < GetNofDaughters(); i++) { + cout << i << "th daughter: " << endl; + GetDaughter(i)->Print(); + } +} + +Int_t FairParticle::GetPDG() const +{ + // Returs particle ID. + // --- + + return fpdg; +} + +TParticle* FairParticle::GetParticle() const +{ + // Returns particle definition (TParticle). + // --- + + return fParticle; +} + +FairParticle* FairParticle::GetMother() const +{ + // Returns particle definition (TParticle). + // --- + + return static_cast(fMother.GetObject()); +} + +Int_t FairParticle::GetNofDaughters() const +{ + // Returns number of daughters. + // --- + + return fDaughters.GetEntriesFast(); +} + +FairParticle* FairParticle::GetDaughter(Int_t i) const +{ + // Returns i-th daughter. + // --- + + if (i < 0 || i >= GetNofDaughters()) { + Fatal("GetDaughter", "Index out of range"); + } + + return static_cast(fDaughters.At(i)); +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairPrimaryGenerator.cxx b/Detectors/3rdparty/FairRootBase/src/FairPrimaryGenerator.cxx new file mode 100644 index 0000000000000..55aa1770dcc3d --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairPrimaryGenerator.cxx @@ -0,0 +1,544 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ + +#include "FairPrimaryGenerator.h" + +#include "FairGenerator.h" // for FairGenerator +#include "FairGenericStack.h" // for FairGenericStack +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairMCEventHeader.h" // for FairMCEventHeader + +#include // for TDatabasePDG +#include // for TIterator +#include // for Sqrt +#include // for TObject +#include // for TParticlePDG +#include // for TRandom, gRandom +#include // for operator<<, basic_ostream, etc + +using std::cerr; +using std::cout; +using std::endl; + +Int_t FairPrimaryGenerator::fTotPrim = 0; + +FairPrimaryGenerator::FairPrimaryGenerator() + : TNamed() + , fBeamX0(0.) + , fBeamY0(0.) + , fBeamSigmaX(0.) + , fBeamSigmaY(0.) + , fBeamAngleX0(0.) + , fBeamAngleY0(0.) + , fBeamAngleX(0.) + , fBeamAngleY(0.) + , fBeamAngleSigmaX(0.) + , fBeamAngleSigmaY(0.) + , fBeamDirection(TVector3(0., 0., 1.)) + , fPhiMin(0.) + , fPhiMax(0.) + , fPhi(0.) + , fTargetZ(new Double_t[1]) + , fNrTargets(1) + , fTargetDz(0) + , fVertex(TVector3(0., 0., 0.)) + , fNTracks(0) + , fSmearVertexZ(kFALSE) + , fSmearGausVertexZ(kFALSE) + , fSmearVertexXY(kFALSE) + , fSmearGausVertexXY(kFALSE) + , fBeamAngle(kFALSE) + , fEventPlane(kFALSE) + , fStack(nullptr) + , fGenList(new TObjArray()) + , fListIter(fGenList->MakeIterator()) + , fEvent(nullptr) + , fdoTracking(kTRUE) + , fMCIndexOffset(0) + , fEventNr(0) +{ + fTargetZ[0] = 0.; +} + +FairPrimaryGenerator::FairPrimaryGenerator(const char *name, const char *title) + : TNamed(name, title) + , fBeamX0(0) + , fBeamY0(0) + , fBeamSigmaX(0) + , fBeamSigmaY(0) + , fBeamAngleX0(0) + , fBeamAngleY0(0) + , fBeamAngleX(0) + , fBeamAngleY(0) + , fBeamAngleSigmaX(0) + , fBeamAngleSigmaY(0) + , fBeamDirection(TVector3(0., 0., 1.)) + , fPhiMin(0.) + , fPhiMax(0.) + , fPhi(0.) + , fTargetZ(new Double_t[1]) + , fNrTargets(1) + , fTargetDz(0) + , fVertex(TVector3(0., 0., 0.)) + , fNTracks(0) + , fSmearVertexZ(kFALSE) + , fSmearGausVertexZ(kFALSE) + , fSmearVertexXY(kFALSE) + , fSmearGausVertexXY(kFALSE) + , fBeamAngle(kFALSE) + , fEventPlane(kFALSE) + , fStack(nullptr) + , fGenList(new TObjArray()) + , fListIter(fGenList->MakeIterator()) + , fEvent(nullptr) + , fdoTracking(kTRUE) + , fMCIndexOffset(0) + , fEventNr(0) +{ + fTargetZ[0] = 0.; +} + +FairPrimaryGenerator::FairPrimaryGenerator(const FairPrimaryGenerator &rhs) + : TNamed(rhs) + , fBeamX0(rhs.fBeamX0) + , fBeamY0(rhs.fBeamY0) + , fBeamSigmaX(rhs.fBeamSigmaX) + , fBeamSigmaY(rhs.fBeamSigmaY) + , fBeamAngleX0(rhs.fBeamAngleX0) + , fBeamAngleY0(rhs.fBeamAngleY0) + , fBeamAngleX(rhs.fBeamAngleX) + , fBeamAngleY(rhs.fBeamAngleY) + , fBeamAngleSigmaX(rhs.fBeamAngleSigmaX) + , fBeamAngleSigmaY(rhs.fBeamAngleSigmaY) + , fBeamDirection(rhs.fBeamDirection) + , fPhiMin(rhs.fPhiMin) + , fPhiMax(rhs.fPhiMax) + , fPhi(rhs.fPhi) + , fTargetZ(new Double_t[1]) + , fNrTargets(rhs.fNrTargets) + , fTargetDz(rhs.fTargetDz) + , fVertex(rhs.fVertex) + , fNTracks(rhs.fNTracks) + , fSmearVertexZ(rhs.fSmearVertexZ) + , fSmearGausVertexZ(rhs.fSmearGausVertexZ) + , fSmearVertexXY(rhs.fSmearVertexXY) + , fSmearGausVertexXY(rhs.fSmearGausVertexXY) + , fBeamAngle(rhs.fBeamAngle) + , fEventPlane(rhs.fEventPlane) + , fStack(nullptr) + , fGenList(new TObjArray()) + , fListIter(fGenList->MakeIterator()) + , fEvent(nullptr) + , fdoTracking(rhs.fdoTracking) + , fMCIndexOffset(rhs.fMCIndexOffset) + , fEventNr(rhs.fEventNr) +{ + fTargetZ[0] = rhs.fTargetZ[0]; +} + +Bool_t FairPrimaryGenerator::Init() +{ + /** Initialize list of generators*/ + for (Int_t i = 0; i < fGenList->GetEntries(); i++) { + FairGenerator *gen = static_cast(fGenList->At(i)); + if (gen) { + gen->Init(); + } + } + return kTRUE; +} + +FairPrimaryGenerator::~FairPrimaryGenerator() +{ + + delete[] fTargetZ; + fGenList->Delete(); + delete fGenList; + delete fListIter; +} + +FairPrimaryGenerator &FairPrimaryGenerator::operator=(const FairPrimaryGenerator &rhs) +{ + // check assignment to self + if (this != &rhs) { + + // base class assignment + TNamed::operator=(rhs); + + // assignment operator + fBeamX0 = rhs.fBeamX0; + fBeamY0 = rhs.fBeamY0; + fBeamSigmaX = rhs.fBeamSigmaX; + fBeamSigmaY = rhs.fBeamSigmaY; + fBeamAngleX0 = rhs.fBeamAngleX0; + fBeamAngleY0 = rhs.fBeamAngleY0; + fBeamAngleX = rhs.fBeamAngleX; + fBeamAngleY = rhs.fBeamAngleY; + fBeamAngleSigmaX = rhs.fBeamAngleSigmaX; + fBeamAngleSigmaY = rhs.fBeamAngleSigmaY; + fBeamDirection = rhs.fBeamDirection; + fPhiMin = rhs.fPhiMin; + fPhiMax = rhs.fPhiMax; + fPhi = rhs.fPhi; + fTargetZ = new Double_t[1]; + fNrTargets = rhs.fNrTargets; + fTargetDz = rhs.fTargetDz; + fVertex = rhs.fVertex; + fNTracks = rhs.fNTracks; + fSmearVertexZ = rhs.fSmearVertexZ; + fSmearGausVertexZ = rhs.fSmearGausVertexZ; + fSmearVertexXY = rhs.fSmearVertexXY; + fSmearGausVertexXY = rhs.fSmearGausVertexXY; + fBeamAngle = rhs.fBeamAngle; + fEventPlane = rhs.fEventPlane; + fStack = nullptr; + fGenList = new TObjArray(); + fListIter = fGenList->MakeIterator(); + fEvent = nullptr; + fdoTracking = rhs.fdoTracking; + fMCIndexOffset = rhs.fMCIndexOffset; + fEventNr = rhs.fEventNr; + fTargetZ[0] = rhs.fTargetZ[0]; + } + + return *this; +} + +Bool_t FairPrimaryGenerator::GenerateEvent(FairGenericStack *pStack) +{ + // Check for MCEventHeader + if (!fEvent) { + LOG(fatal) << "No MCEventHeader branch!"; + return kFALSE; + } else { + // Initialise + fStack = pStack; + fNTracks = 0; + fEvent->Reset(); + + // Create beam angle + // Here we only randomly generate two angles (anglex, angley) + // for the event and later on (in AddTrack()) + // all our particles will be rotated accordingly. + if (fBeamAngle) { + MakeBeamAngle(); + } + + // Create event vertex + MakeVertex(); + fEvent->SetVertex(fVertex); + + // Create event plane + // Randomly generate an angle by which each track added (in AddTrack()) + // to the event is rotated around the z-axis + if (fEventPlane) { + MakeEventPlane(); + } + + // Call the ReadEvent methods from all registered generators + fListIter->Reset(); + TObject *obj = 0; + FairGenerator *gen = 0; + while ((obj = fListIter->Next())) { + gen = dynamic_cast(obj); + if (!gen) { + return kFALSE; + } + const char *genName = gen->GetName(); + fMCIndexOffset = fNTracks; // number tracks before generator is called + Bool_t test = gen->ReadEvent(this); + if (!test) { + LOG(error) << "ReadEvent failed for generator " << genName; + return kFALSE; + } + } + + fTotPrim += fNTracks; + // Screen output + + // Set the event number if not set already by one of the dedicated generators + if (-1 == fEvent->GetEventID()) { + fEventNr++; + fEvent->SetEventID(fEventNr); + } + LOG(debug) << "(Event " << fEvent->GetEventID() << ") " << fNTracks << " primary tracks from vertex (" + << fVertex.X() << ", " << fVertex.Y() << ", " << fVertex.Z() << ") with beam angle (" << fBeamAngleX + << ", " << fBeamAngleY << ") "; + + fEvent->SetNPrim(fNTracks); + + return kTRUE; + } +} + +void FairPrimaryGenerator::AddTrack(Int_t pdgid, + Double_t px_raw, + Double_t py_raw, + Double_t pz_raw, + Double_t vx, + Double_t vy, + Double_t vz, + Int_t parent, + Bool_t wanttracking, + Double_t e, + Double_t tof, + Double_t weight, + TMCProcess proc) +{ + // ---> Add event vertex to track vertex + vx += fVertex.X(); + vy += fVertex.Y(); + vz += fVertex.Z(); + + // cout << "FairPrimaryGenerator::AddTrack +Z" << fVertex.Z() << " pdgid " << + // pdgid << "?"<< wanttracking << endl; + + TVector3 mom(px_raw, py_raw, pz_raw); + + if (fEventPlane) { + // Rotate the track (event) by the randomly generated angle which is fixed + // for the complete event. + // The coordinate system is not changed by this rotation. + mom.RotateZ(fPhi); + } + + if (fBeamAngle) { + // Rotate the track (event) from the rotated beam direction system into + // the fixed global experiment coordinate system + mom.RotateUz(fBeamDirection.Unit()); + } + + // ---> Convert K0 and AntiK0 into K0s and K0L + if (pdgid == 311 || pdgid == -311) { + Double_t test = gRandom->Uniform(0., 1.); + if (test >= 0.5) { + pdgid = 310; + } // K0S + else { + pdgid = 130; + } // K0L + } + + // ---> Check whether particle type is in PDG Database + TDatabasePDG *pdgBase = TDatabasePDG::Instance(); + if (!pdgBase) { + Fatal("FairPrimaryGenerator", "No TDatabasePDG instantiated"); + } else { + TParticlePDG *pdgPart = pdgBase->GetParticle(pdgid); + if (!pdgPart) { + if (e < 0) { + cerr << "\033[5m\033[31m -E FairPrimaryGenerator: PDG code " << pdgid + << " not found in database.\033[0m " << endl; + cerr << "\033[5m\033[31m -E FairPrimaryGenerator: Discarding particle " + "\033[0m " + << endl; + cerr << "\033[5m\033[31m -E FairPrimaryGenerator: now MC Index is " + "corrupted \033[0m " + << endl; + return; + } else { + cout << "\033[5m\033[31m -W FairPrimaryGenerator: PDG code " << pdgid + << " not found in database. This warning can be savely " + "ignored.\033[0m " + << endl; + } + } + } + // ---> Get mass and calculate energy of particle + if (e < 0) { + Double_t mass = pdgBase->GetParticle(pdgid)->Mass(); + e = TMath::Sqrt(mom.Mag2() + mass * mass); + } // else, use the value of e given to the function + + // ---> Set all other parameters required by PushTrack + Int_t doTracking = 0; // Go to tracking + if (fdoTracking && wanttracking) { + doTracking = 1; + } + Int_t dummyparent = -1; // Primary particle (now the value is -1 by default) + Double_t polx = 0.; // Polarisation + Double_t poly = 0.; + Double_t polz = 0.; + Int_t ntr = 0; // Track number; to be filled by the stack + Int_t status = 0; // Generation status + + if (parent != -1) { + parent += fMCIndexOffset; + } // correct for tracks which are in list before generator is called + // Add track to stack + fStack->PushTrack(doTracking, + dummyparent, + pdgid, + mom.X(), + mom.Y(), + mom.Z(), + e, + vx, + vy, + vz, + tof, + polx, + poly, + polz, + proc, + ntr, + weight, + status, + parent); + fNTracks++; +} + +FairPrimaryGenerator *FairPrimaryGenerator::ClonePrimaryGenerator() const +{ + FairPrimaryGenerator *newPrimaryGenerator = new FairPrimaryGenerator(*this); + + /** Clone generators in the list*/ + for (Int_t i = 0; i < fGenList->GetEntries(); i++) { + FairGenerator *gen = static_cast(fGenList->At(i)); + if (gen) { + newPrimaryGenerator->AddGenerator(gen->CloneGenerator()); + } + } + + return newPrimaryGenerator; +} + +void FairPrimaryGenerator::SetBeam(Double_t x0, Double_t y0, Double_t sigmaX, Double_t sigmaY) +{ + fBeamX0 = x0; + fBeamY0 = y0; + fBeamSigmaX = sigmaX; + fBeamSigmaY = sigmaY; +} + +void FairPrimaryGenerator::SetBeamAngle(Double_t beamAngleX0, + Double_t beamAngleY0, + Double_t beamAngleSigmaX, + Double_t beamAngleSigmaY) +{ + fBeamAngleX0 = beamAngleX0; + fBeamAngleY0 = beamAngleY0; + fBeamAngleSigmaX = beamAngleSigmaX; + fBeamAngleSigmaY = beamAngleSigmaY; + fBeamAngle = kTRUE; +} + +void FairPrimaryGenerator::SetEventPlane(Double_t phiMin, Double_t phiMax) +{ + fPhiMin = phiMin; + fPhiMax = phiMax; + fEventPlane = kTRUE; +} + +void FairPrimaryGenerator::SetTarget(Double_t z, Double_t dz) +{ + + fTargetZ[0] = z; + fTargetDz = dz; +} + +void FairPrimaryGenerator::SetMultTarget(Int_t nroftargets, Double_t *targetpos, Double_t dz) +{ + + delete[] fTargetZ; + + fNrTargets = nroftargets; + + fTargetZ = new Double_t[nroftargets]; + for (Int_t i = 0; i < nroftargets; i++) { + fTargetZ[i] = targetpos[i]; + } + fTargetDz = dz; +} + +void FairPrimaryGenerator::MakeVertex() +{ + Double_t vx = fBeamX0; + Double_t vy = fBeamY0; + Double_t vz; + if (1 == fNrTargets) { + vz = fTargetZ[0]; + } else { + Int_t Target = static_cast(gRandom->Uniform(fNrTargets)); + vz = fTargetZ[Target]; + } + + if (fSmearVertexZ) + vz = gRandom->Uniform(vz - fTargetDz / 2., vz + fTargetDz / 2.); + + if (fSmearGausVertexZ) { + vz = gRandom->Gaus(vz, fTargetDz); + } + + if (fSmearGausVertexXY) { + if (fBeamSigmaX != 0.) { + vx = gRandom->Gaus(fBeamX0, fBeamSigmaX); + } + if (fBeamSigmaY != 0.) { + vy = gRandom->Gaus(fBeamY0, fBeamSigmaY); + } + } + + if (fSmearVertexXY) { + if (fBeamSigmaX != 0.) { + vx = gRandom->Uniform(vx - fBeamSigmaX / 2., vx + fBeamSigmaX / 2.); + } + if (fBeamSigmaY != 0.) { + vy = gRandom->Uniform(vy - fBeamSigmaY / 2., vy + fBeamSigmaY / 2.); + } + } + + fVertex = TVector3(vx, vy, vz); +} + +void FairPrimaryGenerator::MakeBeamAngle() +{ + fBeamAngleX = gRandom->Gaus(fBeamAngleX0, fBeamAngleSigmaX); + fBeamAngleY = gRandom->Gaus(fBeamAngleY0, fBeamAngleSigmaY); + fBeamDirection.SetXYZ(TMath::Tan(fBeamAngleX), TMath::Tan(fBeamAngleY), 1.); + fEvent->SetRotX(fBeamAngleX); + fEvent->SetRotY(fBeamAngleY); +} + +void FairPrimaryGenerator::MakeEventPlane() +{ + fPhi = gRandom->Uniform(fPhiMin, fPhiMax); + fEvent->SetRotZ(fPhi); +} + +void FairPrimaryGenerator::SmearVertexZ(Bool_t flag) +{ + fSmearVertexZ = flag; + if (fSmearVertexZ && fSmearGausVertexZ) { + fSmearGausVertexZ = kFALSE; + } +} + +void FairPrimaryGenerator::SmearGausVertexZ(Bool_t flag) +{ + fSmearGausVertexZ = flag; + if (fSmearGausVertexZ && fSmearVertexZ) { + fSmearVertexZ = kFALSE; + } +} +void FairPrimaryGenerator::SmearVertexXY(Bool_t flag) +{ + fSmearVertexXY = flag; + if (fSmearVertexXY && fSmearGausVertexXY) { + fSmearGausVertexXY = kFALSE; + } +} +void FairPrimaryGenerator::SmearGausVertexXY(Bool_t flag) +{ + fSmearGausVertexXY = flag; + if (fSmearGausVertexXY && fSmearVertexXY) { + fSmearVertexXY = kFALSE; + } +} + +ClassImp(FairPrimaryGenerator); diff --git a/Detectors/3rdparty/FairRootBase/src/FairRadGridManager.cxx b/Detectors/3rdparty/FairRootBase/src/FairRadGridManager.cxx new file mode 100644 index 0000000000000..6856bebf3cfe6 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRadGridManager.cxx @@ -0,0 +1,162 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadLenManager source file ----- +// ----- original author D.Bertini ----- +// ----- adapted april 2010 O.Hartmann ----- +// ------------------------------------------------------------------------- + +#include "FairRadGridManager.h" + +#include "FairMesh.h" +#include "FairRootManager.h" + +#include +#include + +ClassImp(FairRadGridManager); + +FairRadGridManager* FairRadGridManager::fgInstance = nullptr; + +Double_t FairRadGridManager::fLtmp = 0.0; + +FairRadGridManager* FairRadGridManager::Instance() +{ + /**singelton instance*/ + return fgInstance; +} + +FairRadGridManager::FairRadGridManager() + : fPointCollection(nullptr) + , fTrackID(0) + , fVolumeID(0) + , fPosIn(TLorentzVector(0, 0, 0, 0)) + , fPosOut(TLorentzVector(0, 0, 0, 0)) + , fMomIn(TLorentzVector(0, 0, 0, 0)) + , fMomOut(TLorentzVector(0, 0, 0, 0)) + , fTime(0) + , fLength(0) + , fELoss(0) + , fA(0) + , fZmat(0) + , fDensity(0) + , fRadl(0) + , fAbsl(0) + , fEstimator(0) + , fMeshList(nullptr) + , fOutputFileName("radGridManager.root") +{ + /** radiation length default ctor */ + if (nullptr == fgInstance) { + fgInstance = this; + } + fLtmp = 0; +} + +FairRadGridManager::~FairRadGridManager() +{ + /** radiation length default dtor */ + fgInstance = nullptr; +} + +void FairRadGridManager::Init() +{ + // fMeshList = new TObjArray(); +} + +void FairRadGridManager::Reset() +{ + // No free of memory ? + // fMesh->Reset(); +} + +void FairRadGridManager::FillMeshList() +{ + + /**Add a point to the collection*/ + TParticle* part = TVirtualMC::GetMC()->GetStack()->GetCurrentTrack(); + fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); + TVirtualMC::GetMC()->TrackPosition(fPosIn); + TVirtualMC::GetMC()->TrackMomentum(fMomIn); + fELoss = 0.; + // Int_t MatId= TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl); + + /** Sum energy loss for all steps in the mesh*/ + for (Int_t i = 0; i < fMeshList->GetEntriesFast(); i++) { + FairMesh* aMesh = static_cast(fMeshList->At(i)); + Double_t fBinVolume = aMesh->GetBinVolume(); + Double_t fDiag = aMesh->GetDiag(); + + // Geometry bound test + if (IsTrackInside(fPosIn, aMesh)) { + fELoss = TVirtualMC::GetMC()->Edep(); + // cout << "-I- track (" << fTrackID << ") is inside " << endl; + // cout << " E deposited is " << fELoss << endl; + TVirtualMC::GetMC()->TrackPosition(fPosOut); + TVirtualMC::GetMC()->TrackMomentum(fMomOut); + + // Now cumulate fEloss (Gev/cm3) + // and normalize it to the mesh volume + + // 1 estimator Edep + fELoss = fELoss / fBinVolume; + // 2 estimator TrackLengh + fLength = TVirtualMC::GetMC()->TrackStep(); + // fill TID + + aMesh->fillTID(fPosOut.X(), fPosOut.Y(), fELoss); + // fill total Fluence + if (fLength < 5 * fDiag) { + + fLength = fLength / fBinVolume; + aMesh->fillFluence(fPosOut.X(), fPosOut.Y(), fLength); + + // fill SEU + if (part->P() > 0.02) { + aMesh->fillSEU(fPosOut.X(), fPosOut.Y(), fLength); + } + } + } + } +} + +Bool_t FairRadGridManager::IsTrackEntering(TLorentzVector&, TLorentzVector&) +{ + // assume for the moment vertical scoring planes + // cout << " is entering diagnosis " << endl; + // cout << " Z pos " << pos.Z() << endl; + // cout << " Zmin " << fZmin << endl; + // cout << " diff " << pos.Z()-fZmin << endl; + + // if ( (( TMath::Abs(pos.Z() - fZmin) ) < 1.0e-06 ) + // && + // ( mom.Z() > 0 ) + // ) return kTRUE; + // else + // return kFALSE; + + return kFALSE; +} + +Bool_t FairRadGridManager::IsTrackInside(TLorentzVector& pos, FairMesh* aMesh) +{ + // check if inside volume + if ((pos.X() >= aMesh->GetXmin()) && (pos.X() <= aMesh->GetXmax()) && (pos.Y() >= aMesh->GetYmin()) + && (pos.Y() <= aMesh->GetYmax()) && (pos.Z() >= aMesh->GetZmin()) && (pos.Z() <= aMesh->GetZmax())) { + /* cout << " inside Xpos: " << pos.X() << " Xmin: " << aMesh->GetXmin() + << " Xmax: " << aMesh->GetXmax() << endl; + cout << " inside Ypos: " << pos.Y() << " Ymin: " << aMesh->GetYmin() + << " Ymax: " << aMesh->GetYmax() << endl; + cout << " inside Zpos: " << pos.Z() << " Zmin: " + << aMesh->GetZmin() << " Zmax: " << aMesh->GetZmax() << endl; + */ + return kTRUE; + } else { + return kFALSE; + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairRadLenManager.cxx b/Detectors/3rdparty/FairRootBase/src/FairRadLenManager.cxx new file mode 100644 index 0000000000000..31a4d8e03e337 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRadLenManager.cxx @@ -0,0 +1,119 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadLenManager source file ----- +// ----- Created 14/01/08 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +#include "FairRadLenManager.h" + +#include "FairRadLenPoint.h" // for FairRadLenPoint +#include "FairRootManager.h" // for FairRootManager + +#include // for TClonesArray +#include // for TVector3 +#include // for TVirtualMC +#include // for TVirtualMCStack + +using namespace std; + +ClassImp(FairRadLenManager); + +FairRadLenManager* FairRadLenManager::fgInstance = nullptr; + +FairRadLenManager* FairRadLenManager::Instance() +{ + /**singelton instance*/ + return fgInstance; +} + +FairRadLenManager::FairRadLenManager() + : fPointCollection(new TClonesArray("FairRadLenPoint")) + , fTrackID(0) + , fVolumeID(0) + , fPosIn(TLorentzVector(0, 0, 0, 0)) + , fPosOut(TLorentzVector(0, 0, 0, 0)) + , fMomIn(TLorentzVector(0, 0, 0, 0)) + , fMomOut(TLorentzVector(0, 0, 0, 0)) + , fTime(0) + , fLength(0) + , fELoss(0) + , fA(0) + , fZmat(0) + , fDensity(0) + , fRadl(0) + , fAbsl(0) +{ + /** radiation length default ctor */ + if (nullptr == fgInstance) { + fgInstance = this; + // fPointCollection=new TClonesArray("FairRadLenPoint"); + } +} + +FairRadLenManager::~FairRadLenManager() +{ + /** radiation length default dtor */ + fgInstance = nullptr; + fPointCollection->Delete(); + delete fPointCollection; +} + +void FairRadLenManager::Init() +{ + /**create the branch for output */ + FairRootManager::Instance()->Register("RadLen", "RadLenPoint", fPointCollection, kTRUE); +} + +void FairRadLenManager::Reset() +{ + /**We have to free the momeory, Clear() is faster but not enough! */ + fPointCollection->Delete(); +} + +void FairRadLenManager::AddPoint(Int_t& ModuleId) +{ + /**Add a point to the collection*/ + if (TVirtualMC::GetMC()->IsTrackEntering()) { + fELoss = 0.; + Int_t copyNo; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); + fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09; + fLength = TVirtualMC::GetMC()->TrackLength(); + TVirtualMC::GetMC()->TrackPosition(fPosIn); + TVirtualMC::GetMC()->TrackMomentum(fMomIn); + // Int_t MatId= TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl); + TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl); + } + /** Sum energy loss for all steps in the active volume */ + fELoss += TVirtualMC::GetMC()->Edep(); + /** Create a point at exit of the volume */ + if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() + || TVirtualMC::GetMC()->IsTrackDisappeared()) { + // FairRadLenPoint* p=0; + fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); + TVirtualMC::GetMC()->TrackPosition(fPosOut); + TVirtualMC::GetMC()->TrackMomentum(fMomOut); + TClonesArray& clref = *fPointCollection; + Int_t tsize = clref.GetEntriesFast(); + // p=new(clref[tsize]) FairRadLenPoint(fTrackID, ModuleId, + new (clref[tsize]) FairRadLenPoint(fTrackID, + ModuleId, + TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()), + TVector3(fMomIn.X(), fMomIn.Y(), fMomIn.Z()), + fTime, + fLength, + fELoss, + TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), + TVector3(fMomOut.X(), fMomOut.Y(), fMomOut.Z()), + fA, + fZmat, + fDensity, + fRadl); + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairRadLenPoint.cxx b/Detectors/3rdparty/FairRootBase/src/FairRadLenPoint.cxx new file mode 100644 index 0000000000000..30878697fed24 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRadLenPoint.cxx @@ -0,0 +1,63 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadLenPoint source file ----- +// ----- Created 14/01/08 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +#include "FairRadLenPoint.h" + +FairRadLenPoint::FairRadLenPoint() + : FairMCPoint() + , fA(0) + , fZmat(0) + , fDensity(0) + , fRadLen(0) + , fXOut(0) + , fYOut(0) + , fZOut(0) + , fPxOut(0) + , fPyOut(0) + , fPzOut(0) +{ + /**default ctor*/ +} + +FairRadLenPoint::FairRadLenPoint(Int_t trackID, + Int_t detID, + TVector3 pos, + TVector3 mom, + Double_t tof, + Double_t length, + Double_t eLoss, + TVector3 posOut, + TVector3 momOut, + Float_t A, + Float_t Z, + Float_t Density, + Float_t RadLen) + : FairMCPoint(trackID, detID, pos, mom, tof, length, eLoss) + , fA(A) + , fZmat(Z) + , fDensity(Density) + , fRadLen(RadLen) + , fXOut(posOut.X()) + , fYOut(posOut.Y()) + , fZOut(posOut.Z()) + , fPxOut(momOut.Px()) + , fPyOut(momOut.Py()) + , fPzOut(momOut.Pz()) +{} + +FairRadLenPoint::~FairRadLenPoint() {} + +void FairRadLenPoint::Print(const Option_t*) const +{ /**to be implimented*/ +} + +ClassImp(FairRadLenPoint); diff --git a/Detectors/3rdparty/FairRootBase/src/FairRadMapManager.cxx b/Detectors/3rdparty/FairRootBase/src/FairRadMapManager.cxx new file mode 100644 index 0000000000000..4109e9fabc38a --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRadMapManager.cxx @@ -0,0 +1,210 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadMapManager source file ----- +// ------------------------------------------------------------------------- + +#include "FairRadMapManager.h" + +#include "FairRadMapPoint.h" // for FairRadMapPoint +#include "FairRootManager.h" // for FairRootManager + +#include // for TClonesArray +#include // for TGeoManager, gGeoManager +#include // for TGeoVolume +#include // for TMap +#include // for TObjArray +#include // for TObject +#include // for TVector3 +#include // for TVectorD +#include // for TVectorT +#include // for TVirtualMC +#include // for TVirtualMCStack +#include // for operator<<, basic_ostream, etc + +using namespace std; + +ClassImp(FairRadMapManager); + +FairRadMapManager* FairRadMapManager::fgInstance = nullptr; + +FairRadMapManager* FairRadMapManager::Instance() +{ + /**singelton instance*/ + return fgInstance; +} + +FairRadMapManager::FairRadMapManager() + : fPointCollection(new TClonesArray("FairRadMapPoint")) + , fTrackID(0) + , fVolumeID(0) + , fPdg(0) + , fPosIn(TLorentzVector(0, 0, 0, 0)) + , fPosOut(TLorentzVector(0, 0, 0, 0)) + , fMomIn(TLorentzVector(0, 0, 0, 0)) + , fMomOut(TLorentzVector(0, 0, 0, 0)) + , fTime(0) + , fLength(0) + , fStep(0) + , fELoss(0) + , fDose(0) + , fDoseSL(0) + , fA(0) + , fZmat(0) + , fRadl(0) + , fDensity(0) + , fAbsl(0) + , fActVol(0) + , fActMass(0) + , fMassMap(nullptr) +{ + /** radiation length default ctor */ + if (nullptr == fgInstance) { + fgInstance = this; + // fPointCollection=new TClonesArray("FairRadMapPoint"); + } +} + +FairRadMapManager::~FairRadMapManager() +{ + /** radiation length default dtor */ + fgInstance = nullptr; + fPointCollection->Delete(); + delete fPointCollection; + delete fMassMap; +} + +void FairRadMapManager::Init() +{ + /**create the branch for output */ + FairRootManager::Instance()->Register("RadMap", "RadMapPoint", fPointCollection, kTRUE); + cout << "RadMapMan initialized" << endl; + + // compute once the masses of the volumes in this simulation and store them in a TMap object + + Int_t volumeiterator = 0, lastvolume = 0; + Double_t vmass; + TObjArray* volumelist; + TGeoVolume* myvolume; + const char* volumename; + fMassMap = new TMap(lastvolume + 1, 0); + + volumelist = gGeoManager->GetListOfVolumes(); + + lastvolume = volumelist->GetLast(); + + volumeiterator = 0; + + cout << "RadMapMan: calculating the masses for " << lastvolume << " volumes in this simulation" << endl; + + while (volumeiterator <= lastvolume) { + volumename = volumelist->At(volumeiterator)->GetName(); + myvolume = gGeoManager->GetVolume(volumename); + vmass = myvolume->WeightA(); // calculate weight analytically + TVectorD* vomass = new TVectorD(1, 1, vmass, "END"); // 1-dim vector + + fMassMap->Add(myvolume, vomass); + + cout << myvolume->GetName() << " has " << vmass << " kg" << endl; + + volumeiterator++; + } +} + +void FairRadMapManager::Reset() +{ + /**We have to free the momeory, Clear() is faster but not enough! */ + fPointCollection->Delete(); + cout << " FairRadMapManager::Reset() ------------------------------------------------\n" << endl; +} + +void FairRadMapManager::AddPoint(Int_t&) +{ + /**Add a point to the collection*/ + if (TVirtualMC::GetMC()->IsTrackEntering()) { + fELoss = 0.; + fStep = 0.; + fDose = 0.; + fDoseSL = 0.; + fPdg = 0; + fActVol = 0.; + fActMass = 0.; + Int_t copyNo; + fVolumeID = TVirtualMC::GetMC()->CurrentVolID(copyNo); + fTime = TVirtualMC::GetMC()->TrackTime() * 1.0e09; + fLength = TVirtualMC::GetMC()->TrackLength(); + TVirtualMC::GetMC()->TrackPosition(fPosIn); + TVirtualMC::GetMC()->TrackMomentum(fMomIn); + // Int_t MatId= TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl); + TVirtualMC::GetMC()->CurrentMaterial(fA, fZmat, fDensity, fRadl, fAbsl); + + // if (!gGeoManager) { GetGeoManager(); } + // TGeoVolume* actVolume = gGeoManager->GetCurrentVolume(); + TGeoVolume* actVolume = gGeoManager->GetVolume(fVolumeID); + + TVectorD* ActMass = static_cast(fMassMap->GetValue(actVolume)); + + fActMass = ActMass->Min(); // read from TVectorD + + // cout << actVolume->GetName() << " has " << fActMass << " kg" << endl; + } + /** Sum energy loss for all steps in the active volume */ + fELoss += TVirtualMC::GetMC()->Edep(); + fStep += TVirtualMC::GetMC()->TrackStep(); + + fPdg = TVirtualMC::GetMC()->TrackPid(); + + // calculate the energy dose + // exclude fragments with PDG code >= 10000 + + if (fPdg < 10000 && fStep > 0 && fActMass > 0) { + // fDose = fELoss*1.602e-10/(fDensity*actvol*0.001); // per mass/kg + fDose = fELoss * 1.602e-10 / (fActMass); // per mass/kg + } else { + fDose = -.00001; + } + + // exclude very high, probably wrong, energy doses + if (fDose > 0.02) { + fDose = -.00001; + } + + /** Create a point at exit of the volume */ + if (TVirtualMC::GetMC()->IsTrackExiting() || TVirtualMC::GetMC()->IsTrackStop() + || TVirtualMC::GetMC()->IsTrackDisappeared()) { + + // FairRadMapPoint* p=0; + fTrackID = TVirtualMC::GetMC()->GetStack()->GetCurrentTrackNumber(); + Int_t copyNo; + Int_t fVolID = TVirtualMC::GetMC()->CurrentVolID(copyNo); // CAVEAT: fVolID is NOT an unique identifier!! + TVirtualMC::GetMC()->TrackPosition(fPosOut); + TVirtualMC::GetMC()->TrackMomentum(fMomOut); + + TClonesArray& clref = *fPointCollection; + Int_t tsize = clref.GetEntriesFast(); + + // p=new(clref[tsize]) FairRadMapPoint(fTrackID, fVolID, + new (clref[tsize]) FairRadMapPoint(fTrackID, + fVolID, + TVector3(fPosIn.X(), fPosIn.Y(), fPosIn.Z()), + TVector3(fMomIn.X(), fMomIn.Y(), fMomIn.Z()), + fTime, + fLength, + fELoss, + TVector3(fPosOut.X(), fPosOut.Y(), fPosOut.Z()), + TVector3(fMomOut.X(), fMomOut.Y(), fMomOut.Z()), + fA, + fZmat, + fDensity, + fActMass, + fStep, + fDose, + fDoseSL, + fPdg); + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairRadMapPoint.cxx b/Detectors/3rdparty/FairRootBase/src/FairRadMapPoint.cxx new file mode 100644 index 0000000000000..0bdc6eafde2e6 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRadMapPoint.cxx @@ -0,0 +1,73 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRadMapPoint source file ----- +// ------------------------------------------------------------------------- + +#include "FairRadMapPoint.h" + +FairRadMapPoint::FairRadMapPoint() + : FairMCPoint() + , fPdg(0) + , fA(0) + , fZmat(0) + , fDensity(0) + , fVolMass(0) + , fStep(0) + , fDose(0) + , fDoseSL(0) + , fXOut(0) + , fYOut(0) + , fZOut(0) + , fPxOut(0) + , fPyOut(0) + , fPzOut(0) +{} + +FairRadMapPoint::FairRadMapPoint(Int_t trackID, + Int_t detID, + TVector3 pos, + TVector3 mom, + Double_t tof, + Double_t length, + Double_t eLoss, + TVector3 posOut, + TVector3 momOut, + Float_t A, + Float_t Z, + Float_t Density, + Double_t VolMass, + Double_t Step, + Double_t Dose, + Double_t DoseSL, + Int_t Pdg) + : FairMCPoint(trackID, detID, pos, mom, tof, length, eLoss) + , fPdg(Pdg) + , fA(A) + , fZmat(Z) + , fDensity(Density) + , fVolMass(VolMass) + , fStep(Step) + , fDose(Dose) + , fDoseSL(DoseSL) + , fXOut(posOut.X()) + , fYOut(posOut.Y()) + , fZOut(posOut.Z()) + , fPxOut(momOut.Px()) + , fPyOut(momOut.Py()) + , fPzOut(momOut.Pz()) + +{} + +FairRadMapPoint::~FairRadMapPoint() {} + +void FairRadMapPoint::Print(const Option_t*) const +{ /**to be implimented*/ +} + +ClassImp(FairRadMapPoint); diff --git a/Detectors/3rdparty/FairRootBase/src/FairRootBaseLinkDef.h b/Detectors/3rdparty/FairRootBase/src/FairRootBaseLinkDef.h new file mode 100644 index 0000000000000..82a5ad2c52d20 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRootBaseLinkDef.h @@ -0,0 +1,82 @@ +// Dictionary for the FairRoot classes used by O2. The streamer flags follow FairRoot's own +// LinkDef files, so the on-disk format of persisted classes is unchanged. + +#ifdef __CLING__ +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class FairBaseMCGenerator+; +#pragma link C++ class FairBoxGenerator+; +#pragma link C++ class FairDetector+; +#pragma link C++ class FairEventHeader; +#pragma link C++ class FairField+; +#pragma link C++ class FairFileHeader+; +#pragma link C++ class FairFileInfo+; +#pragma link C++ class FairGenerator+; +#pragma link C++ class FairGenericStack+; +#pragma link C++ class FairGeoAsciiIo; +#pragma link C++ class FairGeoAssembly; +#pragma link C++ class FairGeoBasicShape; +#pragma link C++ class FairGeoBrik; +#pragma link C++ class FairGeoBuilder; +#pragma link C++ class FairGeoCone; +#pragma link C++ class FairGeoCons; +#pragma link C++ class FairGeoEltu; +#pragma link C++ class FairGeoInterface; +#pragma link C++ class FairGeoIo; +#pragma link C++ class FairGeoLoader; +#pragma link C++ class FairGeoMedia; +#pragma link C++ class FairGeoMedium; +#pragma link C++ class FairGeoNode+; +#pragma link C++ class FairGeoPcon; +#pragma link C++ class FairGeoPgon; +#pragma link C++ class FairGeoRootBuilder; +#pragma link C++ class FairGeoRotation; +#pragma link C++ class FairGeoSet; +#pragma link C++ class FairGeoShapes; +#pragma link C++ class FairGeoSphe; +#pragma link C++ class FairGeoTorus; +#pragma link C++ class FairGeoTransform; +#pragma link C++ class FairGeoTrap; +#pragma link C++ class FairGeoTrd1; +#pragma link C++ class FairGeoTube; +#pragma link C++ class FairGeoTubs; +#pragma link C++ class FairGeoVector; +#pragma link C++ class FairGeoVolume+; +#pragma link C++ class FairIon+; +#pragma link C++ class FairLink+; +#pragma link C++ class FairLinkManager+; +#pragma link C++ class FairLogger+; +#pragma link C++ class FairMCApplication+; +#pragma link C++ class FairMCEventHeader+; +#pragma link C++ class FairMCPoint+; +#pragma link C++ class FairMesh+; +#pragma link C++ class FairModule-; +#pragma link C++ class FairMonitor+; +#pragma link C++ class FairMultiLinkedData+; +#pragma link C++ class FairMultiLinkedData_Interface+; +#pragma link C++ class FairParticle+; +#pragma link C++ class FairPrimaryGenerator+; +#pragma link C++ class FairRadGridManager+; +#pragma link C++ class FairRadLenManager+; +#pragma link C++ class FairRadLenPoint+; +#pragma link C++ class FairRadMapManager+; +#pragma link C++ class FairRadMapPoint+; +#pragma link C++ class FairRootFileSink; +#pragma link C++ class FairRootManager+; +#pragma link C++ class FairRun+; +#pragma link C++ class FairRunInfo+; +#pragma link C++ class FairRunSim; +#pragma link C++ class FairSink; +#pragma link C++ class FairSource; +#pragma link C++ class FairSystemInfo; +#pragma link C++ class FairTSBufferFunctional+; +#pragma link C++ class FairTask+; +#pragma link C++ class FairTimeStamp+; +#pragma link C++ class FairTrajFilter; +#pragma link C++ class FairVolume+; +#pragma link C++ class FairVolumeList+; +#pragma link C++ class FairWriteoutBuffer; + +#endif diff --git a/Detectors/3rdparty/FairRootBase/src/FairRootFileSink.cxx b/Detectors/3rdparty/FairRootBase/src/FairRootFileSink.cxx new file mode 100644 index 0000000000000..757762ac74c04 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRootFileSink.cxx @@ -0,0 +1,368 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairRootFileSink ----- +// ----- Created 22.12.2017 by R. Karabowicz ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#include "FairRootFileSink.h" + +#include "FairEventHeader.h" +#include "FairLogger.h" +#include "FairMonitor.h" // to store histograms at the end +#include "FairRootManager.h" // to GetTreeName() + +#include +#include +#include +#include +#include // for TGeoManager, gGeoManager +#include +#include +#include +#include +#include +#include +#include +#include // free +#include // __cxa_demangle +#include // unique_ptr +#include // string + +FairRootFileSink::FairRootFileSink(TFile* f, const char* Title) + : FairSink() + , fOutputTitle(Title) + , fRootFile(f) + , fOutTree(0) + , fListFolder(new TObjArray(16)) + , fCbmout(0) + , fIsInitialized(kFALSE) + , fFileHeader(0) +{ + if (fRootFile->IsZombie()) { + LOG(fatal) << "Error opening the Input file"; + } + LOG(debug) << "FairRootFileSink created------------"; +} + +FairRootFileSink::FairRootFileSink(const TString* RootFileName, const char* Title) + : FairSink() + , fOutputTitle(Title) + , fRootFile(0) + , fOutTree(0) + , fListFolder(new TObjArray(16)) + , fCbmout(0) + , fIsInitialized(kFALSE) + , fFileHeader(0) +{ + fRootFile = TFile::Open(RootFileName->Data(), "recreate"); + if (fRootFile->IsZombie()) { + LOG(fatal) << "Error opening the Output file"; + } + LOG(debug) << "FairRootFileSink created------------"; +} + +FairRootFileSink::FairRootFileSink(const TString RootFileName, const char* Title) + : FairSink() + , fOutputTitle(Title) + , fRootFile(0) + , fOutTree(0) + , fListFolder(new TObjArray(16)) + , fCbmout(0) + , fIsInitialized(kFALSE) + , fFileHeader(0) +{ + fRootFile = TFile::Open(RootFileName.Data(), "recreate"); + if (fRootFile->IsZombie()) { + LOG(fatal) << "Error opening the Input file"; + } + LOG(debug) << "FairRootFileSink created------------"; +} + +FairRootFileSink::~FairRootFileSink() {} + +TFile* FairRootFileSink::OpenRootFile(TString fileName) +{ + if (fileName.Length() <= 5) + return nullptr; + return TFile::Open(fileName.Data(), "recreate"); +} + +Bool_t FairRootFileSink::InitSink() +{ + if (fIsInitialized) { + LOG(info) << "FairRootFileSink already initialized"; + return kTRUE; + } + fIsInitialized = kTRUE; + + fRootFile->cd(); + + // FairRun* fRun = FairRun::Instance(); + /**Check if a simulation run!*/ + fOutFolder = gROOT->GetRootFolder()->AddFolder( + Form("%s_%d", FairRootManager::GetFolderName(), FairRootManager::Instance()->GetInstanceId()), "Main Folder"); + gROOT->GetListOfBrowsables()->Add(fOutFolder); + + LOG(info) << "FairRootFileSink initialized."; + LOG(info) << " - " << fOutFolder->GetName(); + LOG(info) << " - " << fRootFile->GetName(); + + return kTRUE; +} + +void FairRootFileSink::TruncateBranchNames() +{ + /** If a object is created in a folder the corresponding branch + * in the tree is crated with a wrong name. + * The name of the branch is created as follows + * mainFolder.subFolder.nameOfStoredObject + * e.g. cbmroot.Event.ExampleClass. + * The name which is wanted is only nameOfStoredObject + * e.g. ExampleClass. + * This is corrected in this function + * If the folder does not exist don't do anything + */ + TCollection* lf = fOutFolder->GetListOfFolders(); + TIterator* iter = lf->MakeIterator(); + TObjArray* Br = fOutTree->GetListOfBranches(); + TIterator* BrIter = Br->MakeIterator(); + TObject* obj; + TObject* BrObj; + + /** correct branch names in all folders below the main output folder*/ + while ((obj = iter->Next())) { + /** Create TString with the part of the branch name which should be + * removed. This is mainFolderName.folderName. e.g. cbmroot.Event. + * This part of the branch name is obsolete, so it is removed from + * the branch name. + */ + TString ffn = (fOutFolder->GetName()); + ffn = ffn + "."; + ffn = ffn + obj->GetName(); + ffn = ffn + "."; + + /** Correct name of all branches and leaves which correspond to + * the subfolder. To do so loop over all branches and check + * if the branch corresponds with the folder. If it corresponds + * correct the branch names of all sub branches. + * Only correct branch names for up to now uncorrected branches. + */ + BrIter->Reset(); + + while ((BrObj = BrIter->Next())) { + TBranch* b = static_cast(BrObj); + TruncateBranchNames(b, ffn); + } + } + + // Remove all occurence of FairMCEventHeader and from + // all branches containing that string. + // This is not the correct way to do it, but up tonow we don't understand + // why this part comes in when storing a derrived class from + // FairMCEventHeader or FairEventHeader. + + iter->Reset(); + while ((obj = iter->Next())) { + TString ffn = ".FairMCEventHeader"; + BrIter->Reset(); + + while ((BrObj = BrIter->Next())) { + TBranch* b = static_cast(BrObj); + TruncateBranchNames(b, ffn); + } + } + + iter->Reset(); + while ((obj = iter->Next())) { + TString ffn = ".FairEventHeader"; + BrIter->Reset(); + + while ((BrObj = BrIter->Next())) { + TBranch* b = static_cast(BrObj); + TruncateBranchNames(b, ffn); + } + } + + delete iter; + delete BrIter; +} + +void FairRootFileSink::TruncateBranchNames(TBranch* b, TString ffn) +{ + /** Get the branch name from the branch object, remove common + * and wrong part of the name and and set branch name to + * the new corrected name. This has to be done recursivly for + * all subbranches/leaves + * Remove wrong part of branch name + */ + TObject* BrObj; + TString nn = b->GetName(); + LOG(debug) << "nn.Data before: " << nn.Data(); + nn.ReplaceAll(ffn.Data(), ""); + LOG(debug) << "nn.Data after: " << nn.Data(); + LOG(debug) << "##################"; + b->SetName(nn.Data()); + TObjArray* Br = b->GetListOfBranches(); + TIterator* BrIter = Br->MakeIterator(); + BrIter->Reset(); + + while ((BrObj = BrIter->Next())) { + TBranch* bb = static_cast(BrObj); + TruncateBranchNames(bb, ffn); + } + delete BrIter; +} + +void FairRootFileSink::Close() +{ + if (fRootFile) { + fRootFile->Close(); + } +} + +void FairRootFileSink::Reset() {} + +void FairRootFileSink::FillEventHeader(FairEventHeader* /* feh */) { return; } + +void FairRootFileSink::RegisterImpl(const char* /* name */, const char* folderName, void* obj) +{ + TFolder* folder = 0; + TFolder* f = 0; + f = static_cast(fOutFolder->FindObjectAny(folderName)); + if (f == 0) { + folder = fOutFolder->AddFolder(folderName, folderName); + } else { + folder = f; + } + // ((TNamed*)obj)->SetName(name); + folder->Add((TNamed*)obj); +} + +void FairRootFileSink::RegisterAny(const char* brname, const std::type_info& oi, const std::type_info& pi, void* obj) +{ + fPersistentBranchesMap[brname] = std::unique_ptr(new TypeAddressPair(oi, pi, obj)); +} + +void FairRootFileSink::WriteFolder() +{ + fRootFile->cd(); + if (fOutFolder != 0) { + fOutFolder->Write(FairRootManager::GetFolderName()); + + // FairRun* fRun = FairRun::Instance(); + fOutTree = + new TTree(FairRootManager::GetTreeName(), + Form("/%s_%d", FairRootManager::GetFolderName(), FairRootManager::Instance()->GetInstanceId()), + 99); + TruncateBranchNames(); + CreatePersistentBranchesAny(); + } +} + +namespace impl { +// a helper function to demangle a type_name +inline std::string demangle(const char* name) +{ + int status = -4; // some arbitrary value to eliminate the compiler warning + std::unique_ptr res{abi::__cxa_demangle(name, nullptr, nullptr, &status), std::free}; + return (status == 0) ? res.get() : name; +} +} // namespace impl + +bool FairRootFileSink::CreatePersistentBranchesAny() +{ + for (auto& iter : fPersistentBranchesMap) { + LOG(info) << "CREATING BRANCH " << iter.first; + auto& tinfo = iter.second->persistenttypeinfo; + auto tname = impl::demangle(tinfo.name()); + + // for the branch creation we need a TClass describing the object + // get it from ROOT via the type name + auto cl = TClass::GetClass(tinfo); + if (!cl) { + LOG(fatal) << "No TClass found for " << tname << "\n"; + return false; + } + + if (!cl->HasDictionary()) { + LOG(fatal) << "No dictionary found for " << tname << "\n"; + return false; + } + + // create the branch + auto obj = iter.second->ptraddr; + + LOG(info) << "Creating branch for " << iter.first.c_str() << " with address " << obj; + fOutTree->Branch(iter.first.c_str(), tname.c_str(), obj); + } + return true; +} + +void FairRootFileSink::WriteObject(TObject* f, const char* name, Int_t option) +{ + fRootFile->cd(); + f->Write(name, option); +} + +void FairRootFileSink::WriteGeometry() +{ + fRootFile->cd(); + gGeoManager->Write(); +} + +void FairRootFileSink::Fill() +{ + if (fOutTree != 0) { + fOutTree->Fill(); + } else { + LOG(info) << " No Output Tree"; + } +} + +Int_t FairRootFileSink::Write(const char*, Int_t, Int_t) +{ + /** Writes the tree in the file.*/ + if (fOutTree != 0) { + /** Get the file handle to the current output file from the tree. + * If ROOT splits the file (due to the size of the file) the file + * handle fOutFile is lost and the program crash while writing the + * last part of the last file. + */ + + // fOutTree->Print(); + + fRootFile = fOutTree->GetCurrentFile(); + FairMonitor::GetMonitor()->StoreHistograms(fRootFile); + LOG(debug) << "FairRootFileSink::Write to file: " << fRootFile->GetName(); + fRootFile->cd(); + fOutTree->Write(); + } else { + LOG(info) << "No Output Tree"; + } + return 0; +} +//_____________________________________________________________________________ + +//_____________________________________________________________________________ +FairSink* FairRootFileSink::CloneSink() +{ + FairRootManager* tempMan = FairRootManager::Instance(); + + TString workerFileName = fRootFile->GetName(); + tempMan->UpdateFileName(workerFileName); + FairRootFileSink* newSink = new FairRootFileSink(workerFileName); + + LOG(info) << "FairRootFileSink::CloneSink(). manager " << tempMan->GetInstanceId(); + return newSink; +} +//_____________________________________________________________________________ + +ClassImp(FairRootFileSink); diff --git a/Detectors/3rdparty/FairRootBase/src/FairRootManager.cxx b/Detectors/3rdparty/FairRootBase/src/FairRootManager.cxx new file mode 100644 index 0000000000000..c37581917459d --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRootManager.cxx @@ -0,0 +1,1077 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairRootManager source file ----- +// ----- Created 06/01/04 by M. Al-Turany/D. Bertini ----- +// ------------------------------------------------------------------------- + +// Class FairRootManager +// ------------------ +// Class that takes care of Root IO. +#include "FairRootManager.h" + +#include "FairEventHeader.h" // for FairEventHeader +#include "FairFileHeader.h" // for FairFileHeader +#include "FairLink.h" // for FairLink +#include "FairLinkManager.h" // for FairLinkManager +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairMonitor.h" // for FairMonitor +#include "FairRootFileSink.h" // to enable GetOutFile() +#include "FairRun.h" // for FairRun +#include "FairTSBufferFunctional.h" // for FairTSBufferFunctional, etc +#include "FairWriteoutBuffer.h" // for FairWriteoutBuffer + +#include // for TBranch +#include // for TClonesArray +#include // for TCollection, TIter +#include // for TFile +#include // for TFolder +#include // for TGeoManager, gGeoManager +#include // for TIterator +#include // for TList +#include +#include // for TNamed +#include // for TObjArray +#include // for TObjString +#include // for TRefArray +#include // for TTree +#include // for find +#include +#include +#include // for strcmp +#include // for operator<<, basic_ostream, etc +#include // for _List_iterator, list, etc +#include // for map, _Rb_tree_iterator, etc +#include // for set, set<>::iterator +#include // for exit +#include // for pair +#include // for vector + +using std::list; +using std::map; +using std::pair; +using std::set; + +namespace { +// Define mutexes per operation which modify shared data +TMCMutex createMutex = TMCMUTEX_INITIALIZER; +TMCMutex deleteMutex = TMCMUTEX_INITIALIZER; +} // namespace + +Int_t FairRootManager::fgCounter = 0; +std::string FairRootManager::fFolderName = ""; +std::string FairRootManager::fTreeName = ""; + +FairRootManager* FairRootManager::Instance() +{ + // Returns singleton instance. + // --- + static thread_local FairRootManager instance; + return &instance; +} + +FairRootManager::FairRootManager() + : TObject() + , fOldEntryNr(-1) + , fOutFolder(0) + , fRootFolder(0) + , fCurrentTime(0) + , fObj2(new TObject*[1000]) + , fNObj(-1) + , fMap() + , fBranchSeqId(0) + , fBranchNameList(new TList()) + , fMCTrackBranchId(-1) + , fTimeBasedBranchNameList(new TList()) + , fActiveContainer() + , fTSBufferMap() + , fWriteoutBufferMap() + , fInputBranchMap() + , fTimeStamps(kFALSE) + , fBranchPerMap(kFALSE) + , fBrPerMap() + , fBrPerMapIter() + , fCurrentEntryNo(0) + , fTimeforEntryNo(0) + , fFillLastData(kFALSE) + , fEntryNr(0) + , fListFolder(0) + , fSource(0) + , fSignalChainList() + , fEventHeader(new FairEventHeader()) + , fSink(nullptr) + , fUseFairLinks(kFALSE) + , fFinishRun(kFALSE) + , fListOfBranchesFromInput(0) + , fListOfBranchesFromInputIter(0) + , fListOfNonTimebasedBranches(new TRefArray()) + , fListOfNonTimebasedBranchesIter(0) + , fId(0) +{ + LOG(debug) << "FairRootManager::FairRootManager: going to lock " << this; + + TMCAutoLock lk(&createMutex); + + // Set Id + fId = fgCounter; + + // Increment counter + ++fgCounter; + + lk.unlock(); + + LOG(debug) << "Released lock and done FairRootManager::FairRootManager in " << fId << " " << this; +} + +FairRootManager::~FairRootManager() +{ + // + LOG(debug) << "Enter Destructor of FairRootManager"; + + delete[] fObj2; + fBranchNameList->Delete(); + delete fBranchNameList; + LOG(debug) << "Leave Destructor of FairRootManager"; + delete fEventHeader; + delete fSourceChain; + if (fSink) + delete fSink; + if (fSource) + delete fSource; + + // Global cleanup + TMCAutoLock lk(&deleteMutex); + + LOG(debug) << "FairRootManager::~FairRootManager: going to lock " << fId << " " << this; + + --fgCounter; + + // + lk.unlock(); + + LOG(debug) << "Released lock and done FairRootManager::~FairRootManager in " << fId << " " << this; +} + +Bool_t FairRootManager::InitSource() +{ + // creating fSourceChain now, to give the user chance to change the tree and folder name + fSourceChain = new TChain(GetTreeName(), Form("/%s", GetFolderName())); + + LOG(debug) << "Call the initialiazer for the FairSource in FairRootManager "; + if (fSource) { + Bool_t sourceInitBool = fSource->Init(); + fListOfBranchesFromInput = fSourceChain->GetListOfBranches(); + TObject* obj; + if (fListOfBranchesFromInput) { + fListOfBranchesFromInputIter = fListOfBranchesFromInput->MakeIterator(); + while ((obj = fListOfBranchesFromInputIter->Next())) { + if ((fTimeBasedBranchNameList->FindObject(obj->GetName())) == 0) + fListOfNonTimebasedBranches->Add(obj); + } + } + LOG(debug) << "Source is intialized and the list of branches is created in FairRootManager "; + fListOfNonTimebasedBranchesIter = fListOfNonTimebasedBranches->MakeIterator(); + return sourceInitBool; + } + return kFALSE; +} + +Bool_t FairRootManager::InitSink() +{ + if (fSink) { + fSink->InitSink(); + } + return kTRUE; +} + +template +void FairRootManager::RegisterImpl(const char* name, const char* folderName, T* obj, Bool_t toFile) +{ + /// a common implementation for Register + FairMonitor::GetMonitor()->RecordRegister(name, folderName, toFile); + + // Security check. If the the name is equal the folder name there are problems with reading + // back the data. Instead of the object inside the folder the RootManger will return a pointer + // to the folder. To avoid such problems we check here if both strings are equal and stop the + // execution with some error message if this is the case. + if (strcmp(name, folderName) == 0) { + LOG(fatal) << "The names for the object name " << name << " and the folder name " << folderName + << " are equal. This isn't allowed. So we stop the execution at this point. Pleae change either the " + "name or the folder name."; + } + + if (toFile) { /**Write the Object to the Tree*/ + obj->SetName(name); + if (fSink) { + fSink->RegisterImpl(name, folderName, obj); + } else { + LOG(fatal) << "The sink does not exist to store persistent branches."; + } + } + AddMemoryBranch(name, obj); + AddBranchToList(name); + + if (toFile == kFALSE) { + FairLinkManager::Instance()->AddIgnoreType(GetBranchId(name)); + } +} + +void FairRootManager::Register(const char* name, const char* folderName, TNamed* obj, Bool_t toFile) +{ + RegisterImpl(name, folderName, obj, toFile); +} + +Int_t FairRootManager::AddBranchToList(const char* name) +{ + if (fBranchNameList->FindObject(name) == 0) { + fBranchNameList->AddLast(new TObjString(name)); + // check if we are setting the MCTrack Branch + if (strcmp(name, "MCTrack") == 0) { + fMCTrackBranchId = fBranchSeqId; + } + fBranchSeqId++; + } + return fBranchSeqId; +} + +void FairRootManager::Register(const char* name, const char* foldername, TCollection* obj, Bool_t toFile) +{ + RegisterImpl(name, foldername, obj, toFile); +} + +void FairRootManager::RegisterInputObject(const char* name, TObject* obj) +{ + AddMemoryBranch(name, obj); + AddBranchToList(name); +} + +TClonesArray* FairRootManager::Register(TString branchName, TString className, TString folderName, Bool_t toFile) +{ + FairMonitor::GetMonitor()->RecordRegister(branchName, folderName, toFile); + + TClonesArray* outputArray; + if (fActiveContainer.find(branchName) == fActiveContainer.end()) { + fActiveContainer[branchName] = new TClonesArray(className); + outputArray = fActiveContainer[branchName]; + Register(branchName, folderName, outputArray, toFile); + } + + return fActiveContainer[branchName]; +} + +TClonesArray* FairRootManager::GetEmptyTClonesArray(TString branchName) +{ + if (fActiveContainer.find(branchName) + != fActiveContainer.end()) { // if a TClonesArray is registered in the active container + if (fActiveContainer[branchName] == 0) { // the address of the TClonesArray is still valid + std::cout << "-E- FairRootManager::GetEmptyTClonesArray: Container deleted outside FairRootManager!" + << std::endl; + } else { + fActiveContainer[branchName]->Delete(); + } + return fActiveContainer[branchName]; // return the container + } else { + std::cout << "-E- Branch: " << branchName << " not registered!" + << std::endl; // error if the branch is not registered + } + return 0; +} + +TClonesArray* FairRootManager::GetTClonesArray(TString branchName) +{ + if (fActiveContainer.find(branchName) != fActiveContainer.end()) { + return fActiveContainer[branchName]; // return the container + } else { + LOG(info) << "Branch: " << branchName.Data() << " not registered!"; + } + // error if the branch is not registered + return 0; +} + +TString FairRootManager::GetBranchName(Int_t id) +{ + /**Return the branch name from the id*/ + if (id < fBranchSeqId) { + TObjString* ObjStr = static_cast(fBranchNameList->At(id)); + return ObjStr->GetString(); + } else { + TString NotFound("Branch not found"); + return NotFound; + } +} + +Int_t FairRootManager::GetBranchId(TString const& BrName) +{ + /**Return the branch id from the name*/ + TObjString* ObjStr; + Int_t Id = -1; + for (Int_t t = 0; t < fBranchNameList->GetEntries(); t++) { + ObjStr = static_cast(fBranchNameList->TList::At(t)); + if (BrName == ObjStr->GetString()) { + Id = t; + break; + } + } + return Id; +} + +void FairRootManager::InitTSBuffer(TString branchName, BinaryFunctor* function) +{ + fTSBufferMap[branchName] = new FairTSBufferFunctional(branchName, GetInTree(), function); +} + +TClonesArray* FairRootManager::GetData(TString branchName, BinaryFunctor* function, Double_t parameter) +{ + if (fTSBufferMap[branchName] == 0) { + fTSBufferMap[branchName] = new FairTSBufferFunctional(branchName, GetInTree(), function); + } + fTSBufferMap[branchName]->SetStopFunction(function); + return fTSBufferMap[branchName]->GetData(parameter); +} + +TClonesArray* FairRootManager::GetData(TString branchName, + BinaryFunctor* startFunction, + Double_t startParameter, + BinaryFunctor* stopFunction, + Double_t stopParameter) +{ + if (fTSBufferMap[branchName] == 0) { + fTSBufferMap[branchName] = new FairTSBufferFunctional(branchName, GetInTree(), stopFunction, startFunction); + } + fTSBufferMap[branchName]->SetStopFunction(stopFunction); + fTSBufferMap[branchName]->SetStartFunction(startFunction); + return fTSBufferMap[branchName]->GetData(startParameter, stopParameter); +} + +void FairRootManager::TerminateTSBuffer(TString branchName) +{ + if (fTSBufferMap.count(branchName) > 0) { + fTSBufferMap[branchName]->Terminate(); + } +} + +void FairRootManager::TerminateAllTSBuffer() +{ + for (auto& mi : fTSBufferMap) { + mi.second->Terminate(); + } +} + +Bool_t FairRootManager::AllDataProcessed() +{ + for (auto& mi : fTSBufferMap) { + if (mi.second->AllDataProcessed() == kFALSE && mi.second->TimeOut() == kFALSE) { + return kFALSE; + } + } + return kTRUE; +} + +void FairRootManager::Fill() +{ + if (fSink) + fSink->Fill(); +} + +void FairRootManager::LastFill() +{ + // FairMonitor::GetMonitor()->StoreHistograms(); MOVED TO FairRootFileSink + if (fFillLastData) { + if (fSink) + fSink->Fill(); + } +} + +Int_t FairRootManager::Write(const char*, Int_t, Int_t) +{ + /** Writes the tree in the file.*/ + + LOG(debug) << "FairRootManager::Write " << this; + + if (fSink) + return (fSink->Write()); + + return 0; +} + +void FairRootManager::WriteGeometry() +{ + /** Writes the geometry in the current output file.*/ + if (fSink) + fSink->WriteGeometry(); +} + +void FairRootManager::CreateGeometryFile(const char* geofile) +{ + /** Writes the geometry in a separate file. + * This is only to have a file which can be read without the + * framework. The geomanager used by the framework is still + * stored in the parameter file or database + */ + TFile* oldfile = gFile; + TFile* file = TFile::Open(geofile, "RECREATE"); + file->cd(); + gGeoManager->Write(); + file->Close(); + file->Delete(); + gFile = oldfile; +} + +void FairRootManager::WriteFolder() +{ + if (fSink) { + fSink->WriteFolder(); + fSink->WriteObject(fBranchNameList, "BranchList", TObject::kSingleKey); + fSink->WriteObject(fTimeBasedBranchNameList, "TimeBasedBranchList", TObject::kSingleKey); + } +} +Bool_t FairRootManager::SpecifyRunId() +{ + if (!fSource) { + LOG(fatal) << "No Source available"; + return false; + } + Bool_t Result = fSource->SpecifyRunId(); + fSource->FillEventHeader(fEventHeader); + LOG(info) << "---FairRootManager::SpecifyRunId --- "; + return Result; +} +Int_t FairRootManager::ReadEvent(Int_t i) +{ + if (!fSource) + return 0; + + fSource->Reset(); + + SetEntryNr(i); + + if (!fSource) { + LOG(fatal) << "No Source available"; + return -1; + } + + fCurrentEntryNo = i; + + Int_t readEventResult = fSource->ReadEvent(i); + + fSource->FillEventHeader(fEventHeader); + fCurrentTime = fEventHeader->GetEventTime(); + + LOG(debug) << "--Event number --- " << fCurrentEntryNo << " with time ---- " << fCurrentTime; + + return readEventResult; +} + +void FairRootManager::ReadBranchEvent(const char* BrName, Int_t entry) +{ + if (!fSource) + return; + fSource->Reset(); + SetEntryNr(entry); + + fSource->ReadBranchEvent(BrName, entry); + fSource->FillEventHeader(fEventHeader); + fCurrentTime = fEventHeader->GetEventTime(); +} + +Int_t FairRootManager::GetRunId() +{ + if (fSource) { + fSource->FillEventHeader(fEventHeader); + return fEventHeader->GetRunId(); + } + return -1; +} + +void FairRootManager::ReadBranchEvent(const char* BrName) +{ + if (fSource) { + fSource->ReadBranchEvent(BrName); + fSource->FillEventHeader(fEventHeader); + fCurrentTime = fEventHeader->GetEventTime(); + } +} + +Int_t FairRootManager::ReadNonTimeBasedEventFromBranches(Int_t Entry) +{ + if (fSource) { + TObject* Obj; + fListOfNonTimebasedBranchesIter->Reset(); + while ((Obj = fListOfNonTimebasedBranchesIter->Next())) { + fSource->ReadBranchEvent(Obj->GetName(), Entry); + fSource->FillEventHeader(fEventHeader); + fCurrentTime = fEventHeader->GetEventTime(); + } + } else { + return 0; + } + return 1; +} + +Bool_t FairRootManager::ReadNextEvent(Double_t) +{ + Bool_t readentry = kFALSE; + /// TODO + return readentry; +} + +TObject* FairRootManager::GetObject(const char* BrName) +{ + fReqBrNames.emplace_back(BrName); + /**Get Data object by name*/ + TObject* Obj = nullptr; + LOG(debug2) << " Try to find if the object " << BrName << " is already activated by another task or call"; + /**Try to find the object in the folder structure, object already activated by other task or call*/ + if (fOutFolder) { + Obj = fOutFolder->FindObjectAny(BrName); + if (Obj) { + LOG(debug2) << "Object " << BrName << " was already activated by another task"; + } + } + /**if the object does not exist then it could be a memory branch */ + if (!Obj) { + LOG(debug2) << "Try to find if the object " << BrName << " is a memory branch"; + Obj = GetMemoryBranch(BrName); + if (Obj) { + LOG(debug2) << "Object " << BrName << " is a memory branch"; + } + } + /**if the object does not exist then look in the input tree */ + if (fRootFolder && !Obj) { + /** there is an input tree and the object was not in memory */ + LOG(debug2) << "Object " << BrName + << " is not a memory branch and not yet activated, try the Input Tree (Chain)"; + Obj = fRootFolder->FindObjectAny(BrName); + Obj = ActivateBranch(BrName); + } + if (!Obj) { + Obj = ActivateBranch(BrName); + } + if (Obj != nullptr) + FairMonitor::GetMonitor()->RecordGetting(BrName); + return Obj; +} + +TObject* FairRootManager::GetCloneOfLinkData(const FairLink link) +{ + TObject* result = 0; + + // std::cout << "GetCloneOfLinkData: Link " << link << std::endl; + Int_t fileId = link.GetFile(); + Int_t entryNr = link.GetEntry(); + Int_t type = link.GetType(); + Int_t index = link.GetIndex(); + + Int_t oldEntryNr = GetEntryNr(); + + // std::cout << "OldEntryNr: " << GetEntryNr(); + + // std::cout << "GetLinkData: " << link << std::endl; + + TTree* dataTree; // get the correct Tree + if (fileId < 0) { + dataTree = GetInTree(); + } else if (fileId == 0) { + dataTree = GetInChain(); + } else { + dataTree = GetSignalChainNo(fileId); + } + + if (dataTree == 0) { + dataTree = GetInTree(); + } + + if (type < 0) { + return 0; + } + + TBranch* dataBranch = 0; + + // std::cout << "DataType: " << GetBranchName(type) << std::endl; + + if (fileId < 0 && fInputBranchMap[type] != 0) { + dataBranch = fInputBranchMap[type]; + } else if (fileId < 0) { + fInputBranchMap[type] = dataTree->GetBranch(GetBranchName(type)); + dataBranch = fInputBranchMap[type]; + } else { + dataBranch = dataTree->GetBranch(GetBranchName(type)); + } + + if (dataBranch == 0) { + return 0; + } + + if (entryNr > -1) { // get the right entry (if entryNr < 0 then the current entry is taken + if (entryNr < dataBranch->GetEntries()) { + dataBranch->GetEntry(entryNr); + } else { + return 0; + } + } else { // the link entry nr is negative --> take the actual one + + // std::cout << "EntryNr: " << GetEntryNr() << std::endl; + // dataBranch->GetEntry(GetEntryNr()); + } + + if (index < 0) { // if index is -1 then this is not a TClonesArray so only the Object is returned + result = GetObject(GetBranchName(type))->Clone(); + } else { + TClonesArray* dataArray = static_cast(GetObject(GetBranchName(type))); + + // std::cout << "FairRootManager::GetCloneOfLinkData() dataArray size: " << dataArray->GetEntriesFast() + // << std::endl; + if (index < dataArray->GetEntriesFast()) { + // std::cout << "DataArray at index " << index << " has Link: " << + // ((FairMultiLinkedData*)dataArray->At(index))->GetNLinks() << std::cout; + result = dataArray->At(index)->Clone(); + // std::cout << "Result: " << *((FairMultiLinkedData*)result) << std::endl; + } + } + if (entryNr > -1) { + dataBranch->GetEntry(oldEntryNr); // reset the dataBranch to the original entry + } + return result; +} + +TClonesArray* FairRootManager::GetCloneOfTClonesArray(const FairLink link) +{ + TClonesArray* result = 0; + + // std::cout << "GetCloneOfLinkData: Link " << link << std::endl; + Int_t fileId = link.GetFile(); + Int_t entryNr = link.GetEntry(); + Int_t type = link.GetType(); + Int_t index = link.GetIndex(); + + Int_t oldEntryNr = GetEntryNr(); + + // std::cout << "OldEntryNr: " << GetEntryNr(); + + // std::cout << "GetLinkData: " << link << std::endl; + + TTree* dataTree; // get the correct Tree + if (fileId < 0) { + dataTree = GetInTree(); + } else if (fileId == 0) { + dataTree = GetInChain(); + } else { + dataTree = GetSignalChainNo(fileId); + } + + if (dataTree == 0) { + dataTree = GetInTree(); + } + + if (type < 0) { + return 0; + } + + TBranch* dataBranch = 0; + + // std::cout << "DataType: " << GetBranchName(type) << std::endl; + + if (fileId < 0 && fInputBranchMap[type] != 0) { + dataBranch = fInputBranchMap[type]; + } else if (fileId < 0) { + fInputBranchMap[type] = dataTree->GetBranch(GetBranchName(type)); + dataBranch = fInputBranchMap[type]; + } else { + dataBranch = dataTree->GetBranch(GetBranchName(type)); + } + + if (dataBranch == 0) { + return 0; + } + + if (entryNr > -1) { // get the right entry (if entryNr < 0 then the current entry is taken + if (entryNr < dataBranch->GetEntries()) { + dataBranch->GetEntry(entryNr); + } else { + return 0; + } + } else { // the link entry nr is negative --> take the actual one + + // std::cout << "EntryNr: " << GetEntryNr() << std::endl; + // dataBranch->GetEntry(GetEntryNr()); + } + + if (index < 0) { // if index is -1 then this is not a TClonesArray so only the Object is returned + result = 0; + } else { + result = static_cast(GetObject(GetBranchName(type))->Clone()); + } + if (entryNr > -1) { + dataBranch->GetEntry(oldEntryNr); // reset the dataBranch to the original entry + } + return result; +} + +Int_t FairRootManager::CheckBranch(const char* BrName) +{ + /**The first time this method is called the map is generated and then used*/ + if (!fBranchPerMap) { + CreatePerMap(); + return CheckBranchSt(BrName); + } else { + fBrPerMapIter = fBrPerMap.find(BrName); + if (fBrPerMapIter != fBrPerMap.end()) { + return fBrPerMapIter->second; + } else { + return 0; + } + } +} + +void FairRootManager::SetBranchNameList(TList* list) +{ + if (list == nullptr) + return; + // otherwise clear existing and add via the standard interface + fBranchNameList->Clear(); + fMCTrackBranchId = -1; + for (Int_t t = 0; t < list->GetEntries(); t++) { + AddBranchToList(static_cast(list->At(t))->GetString().Data()); + } +} + +void FairRootManager::SetInChain(TChain* tempChain, Int_t ident) +{ + if (ident <= 0) + fSourceChain = tempChain; + else + fSignalChainList[ident] = tempChain; +} + +Double_t FairRootManager::GetEventTime() { return fCurrentTime; } + +void FairRootManager::UpdateBranches() +{ + for (Int_t iobj = 0; iobj <= fNObj; iobj++) { + if (fObj2[iobj]) { + LOG(info) << "FairRootManager::UpdateBranches \"" << fObj2[iobj]->GetName() << "\" (\"" + << fObj2[iobj]->GetTitle() << "\")"; + TString tempBranchName = fObj2[iobj]->GetName(); + fSource->ActivateObject(&fObj2[fNObj], tempBranchName.Data()); + } + } +} + +/** Private functions*/ + +TObject* FairRootManager::ActivateBranch(const char* BrName) +{ + /** Set the branch address for a given branch name and return a TObject pointer, + the user have to cast this pointer to the right type. + The function has been revisited ! Now it test if in the task init() mutilple + calls to activate branch is done , and then just forward the pointer. + + **/ + fNObj++; + fObj2[fNObj] = GetMemoryBranch(BrName); + if (fObj2[fNObj]) { + return fObj2[fNObj]; + } + /**try to find the object decribing the branch in the folder structure in file*/ + LOG(debug) << "Try to find an object " << BrName << " describing the branch in the folder structure in file"; + if (fListFolder) { + for (Int_t i = 0; i < fListFolder->GetEntriesFast(); i++) { + TFolder* fold = static_cast(fListFolder->At(i)); + fObj2[fNObj] = fold->FindObjectAny(BrName); + if (fObj2[fNObj]) { + LOG(info) << "Object " << BrName << " describing the branch in the folder structure was found"; + break; + } + } + } + + if (!fObj2[fNObj]) { + /** if we do not find an object corresponding to the branch in the folder structure + * then we have no idea about what type of object is this and we cannot set the branch address + */ + LOG(info) << " Branch: " << BrName << " not found in Tree."; + // Fatal(" No Branch in the tree", BrName ); + return 0; + } else { + if (fSource) + fSource->ActivateObject(&fObj2[fNObj], BrName); + } + + AddMemoryBranch(BrName, fObj2[fNObj]); + return fObj2[fNObj]; +} + +void FairRootManager::AddMemoryBranch(const char* fName, TObject* pObj) +{ + /**branch will be available ionly in Memory, will not be written to disk */ + map::iterator p; + TString BrName = fName; + p = fMap.find(BrName); + if (p != fMap.end()) { + } else { + fMap.insert(pair(BrName, pObj)); + } +} + +Int_t FairRootManager::CheckBranchSt(const char* BrName) +{ + // cout <<"FairRootManager::CheckBranchSt : " << BrName << endl; + Int_t returnvalue = 0; + TObject* Obj1 = nullptr; + + if (fListFolder == 0) { + fListFolder = new TObjArray(16); + } + + // cout <<"FairRootManager::CheckBranchSt : " <Add(fRootFolder); + Obj1 = fRootFolder->FindObjectAny(BrName); + } + if (fOutFolder && !Obj1) { + fListFolder->Add(fOutFolder); + Obj1 = fOutFolder->FindObjectAny(BrName); // Branch in output folder + } + if (!Obj1) { + for (Int_t i = 0; i < fListFolder->GetEntriesFast(); i++) { + // cout << "Search in Folder: " << i << " " << fListFolder->At(i) << endl; + TFolder* fold = dynamic_cast(fListFolder->At(i)); + if (fold != 0) { + Obj1 = fold->FindObjectAny(BrName); + } + if (Obj1) { + break; + } + } + } + TObject* Obj2 = nullptr; + Obj2 = GetMemoryBranch(BrName); // Branch in Memory + if (Obj1 != 0) { + returnvalue = 1; + } else if (Obj2 != 0) { + returnvalue = 2; + } else { + returnvalue = 0; + } + + /** 1 : Branch is Persistance + 2 : Memory Branch + 0 : Branch does not exist + */ + return returnvalue; +} + +void FairRootManager::CreatePerMap() +{ + // cout << " FairRootManager::CreatePerMap() " << endl; + fBranchPerMap = kTRUE; + for (Int_t i = 0; i < fBranchSeqId; i++) { + TObjString* name = static_cast(fBranchNameList->At(i)); + // cout << " FairRootManager::CreatePerMap() Obj At " << i << " is " << name->GetString() << endl; + TString BrName = name->GetString(); + fBrPerMap.insert(pair(BrName, CheckBranchSt(BrName.Data()))); + } +} + +TObject* FairRootManager::GetMemoryBranch(const char* fName) +{ + + // return fMap[BrName]; + TString BrName = fName; + map::iterator p; + p = fMap.find(BrName); + + if (p != fMap.end()) { + return p->second; + } else { + return 0; + } +} + +void FairRootManager::WriteFileHeader(FairFileHeader* f) +{ + if (fSink) + fSink->WriteObject(f, "FileHeader", TObject::kSingleKey); +} + +Int_t FairRootManager::CheckMaxEventNo(Int_t EvtEnd) +{ + if (fSource) + return fSource->CheckMaxEventNo(EvtEnd); + return 0; +} + +FairWriteoutBuffer* FairRootManager::RegisterWriteoutBuffer(TString branchName, FairWriteoutBuffer* buffer) +{ + if (fWriteoutBufferMap[branchName] == 0) { + fWriteoutBufferMap[branchName] = buffer; + } else { + LOG(warn) << "Branch " << branchName.Data() << " is already registered in WriteoutBufferMap"; + delete buffer; + } + + return fWriteoutBufferMap[branchName]; +} + +void FairRootManager::UpdateListOfTimebasedBranches() +{ + /** + * Add branches that are time based to the proper list + */ + + for (auto& mi : fWriteoutBufferMap) { + if (mi.second->IsBufferingActivated()) + fTimeBasedBranchNameList->AddLast(new TObjString(mi.first.Data())); + } +} + +void FairRootManager::SetTimeBasedBranchNameList(TList* list) +{ + /** + * Replace the list + */ + + if (list != 0) { + fTimeBasedBranchNameList->Delete(); + delete fTimeBasedBranchNameList; + fTimeBasedBranchNameList = list; + } +} + +FairWriteoutBuffer* FairRootManager::GetWriteoutBuffer(TString branchName) +{ + if (fWriteoutBufferMap.count(branchName) > 0) { + return fWriteoutBufferMap[branchName]; + } else { + return 0; + } +} + +void FairRootManager::StoreWriteoutBufferData(Double_t eventTime) +{ + for (auto& mi : fWriteoutBufferMap) { + mi.second->WriteOutData(eventTime); + } +} + +void FairRootManager::StoreAllWriteoutBufferData() +{ + Bool_t dataInBuffer = kFALSE; + for (auto& mi : fWriteoutBufferMap) { + if (mi.second->GetNData() > 0) { + dataInBuffer = kTRUE; + } + mi.second->WriteOutAllData(); + } + fFillLastData = dataInBuffer; +} + +void FairRootManager::DeleteOldWriteoutBufferData() +{ + for (auto& mi : fWriteoutBufferMap) { + mi.second->DeleteOldData(); + } +} + +std::string FairRootManager::GetNameFromFile(const char* namekind) +{ + std::string default_name = ""; + + if (strcmp(namekind, "treename=") && strcmp(namekind, "foldername=")) { + LOG(fatal) << "FairRootManager, requested " << namekind << ", while only treename= and foldername= available."; + return default_name; + } + + char* workdir = getenv("VMCWORKDIR"); + if (nullptr == workdir) { + return default_name; + } + + // Open file with output tree name + std::ifstream file(Form("%s/config/rootmanager.dat", workdir)); + // If file does not exist -> default + if (!file.is_open()) { + return default_name; + } + + std::string line; + while (std::getline(file, line)) { + if (line.rfind(namekind, 0) == 0) { + line.replace(0, strlen(namekind), ""); + file.close(); + return line; + } + } + + file.close(); + return default_name; +} + +const char* FairRootManager::GetTreeName() +{ + if (fTreeName.length() > 0) { + return Form("%s", fTreeName.c_str()); + } + + std::string nameFromFile = GetNameFromFile("treename="); + if (nameFromFile.length() > 0) { + return Form("%s", nameFromFile.c_str()); + } + + return "cbmsim"; +} + +const char* FairRootManager::GetFolderName() +{ + if (fFolderName.length() > 0) { + return Form("%s", fFolderName.c_str()); + } + + std::string nameFromFile = GetNameFromFile("foldername="); + if (nameFromFile.length() > 0) { + return Form("%s", nameFromFile.c_str()); + } + + if (!FairRun::Instance()->IsAna()) { + return "cbmroot"; + } + return "cbmout"; +} + +void FairRootManager::EmitMemoryBranchWrongTypeWarning(const char* brname, const char* type1, const char* type2) const +{ + LOG(warn) << "Trying to read from memory branch " << brname << " with wrong type " << type1 + << " (expexted: " << type2 << " )"; +} + +void FairRootManager::UpdateFileName(TString& fileName) +{ + TString tid = "_t"; + tid += GetInstanceId(); + fileName.Insert(fileName.Index(".root"), tid); +} + +TFile* FairRootManager::GetOutFile() +{ + LOG(warning) << "FairRootManager::GetOutFile() deprecated. Use separate file to store additional data."; + auto sink = GetSink(); + assert(sink->GetSinkType() == kFILESINK); + auto rootFileSink = static_cast(sink); + return rootFileSink->GetRootFile(); +} + +TTree* FairRootManager::GetOutTree() +{ + LOG(warning) << "FairRootManager::GetOutTree() deprecated. Use separate file to store additional data."; + auto sink = GetSink(); + assert(sink->GetSinkType() == kFILESINK); + auto rootFileSink = static_cast(sink); + return rootFileSink->GetOutTree(); +} + +ClassImp(FairRootManager); diff --git a/Detectors/3rdparty/FairRootBase/src/FairRun.cxx b/Detectors/3rdparty/FairRootBase/src/FairRun.cxx new file mode 100644 index 0000000000000..546953e9314e4 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRun.cxx @@ -0,0 +1,186 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). +// ------------------------------------------------------------------------- +// ----- FairRun source file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +#include "FairRun.h" + +#include "FairEventHeader.h" // for FairEventHeader +#include "FairFileHeader.h" // for FairFileHeader +#include "FairLinkManager.h" // for FairLinkManager +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairRootFileSink.h" // only temporary, should be removed after the move to FairSink is finished +#include "FairRootManager.h" // for FairRootManager +#include "FairTask.h" // for FairTask + +#include // for TFile +#include // for TList +#include // for TObject +#include // for... well, assert + +TMCThreadLocal FairRun* FairRun::fRunInstance = 0; + +FairRun* FairRun::Instance() { return fRunInstance; } + +FairRun::FairRun(Bool_t isMaster) + : TNamed() + , fNTasks(0) + , fTask(new FairTask("FairTaskList")) + , fRootManager(0) + , fSink(0) + , fUserOutputFileName() + , fRunId(0) + , fAna(kFALSE) + , fEvtHeader(nullptr) + , fFileHeader(new FairFileHeader()) + , fGenerateRunInfo(kFALSE) + , fIsMaster(isMaster) + , fMarkFill(kTRUE) +{ + if (fRunInstance) { + Fatal("FairRun", "Singleton instance already exists."); + return; + } + fRunInstance = this; + + fRootManager = FairRootManager::Instance(); + + new FairLinkManager(); +} + +FairRun::~FairRun() +{ + LOG(debug) << "Enter Destructor of FairRun"; + delete fTask; // There is another tasklist in MCApplication, + // but this should be independent + delete fEvtHeader; + LOG(debug) << "Leave Destructor of FairRun"; +} + +void FairRun::AddTask(FairTask* task) +{ + fTask->Add(task); + StoreTaskNames(task); +} + +void FairRun::StoreTaskNames(const FairTask* task) +{ + if (task) { + fFileHeader->AddTaskClassName(task->ClassName()); + fNTasks++; + + const TList* subtasks = task->GetListOfTasks(); + if (subtasks) { + for (const auto subtask : *subtasks) { + StoreTaskNames(static_cast(subtask)); + } + } + } +} + +void FairRun::SetTask(FairTask* task) +{ + delete fTask; + fTask = task; + fNTasks = 0; + TList* tasklist = fFileHeader->GetListOfTasks(); + if (tasklist) { + tasklist->Clear(); + StoreTaskNames(task); + } +} + +void FairRun::CreateGeometryFile(const char* geofile) { fRootManager->CreateGeometryFile(geofile); } + +FairTask* FairRun::GetTask(const char* taskName) +{ + TList* taskList = fTask->GetListOfTasks(); + TObject* task = taskList->FindObject(taskName); + return dynamic_cast(task); +} + +FairEventHeader* FairRun::GetEventHeader() +{ + if (nullptr == fEvtHeader) { + fEvtHeader = new FairEventHeader(); + } + return fEvtHeader; +} + +void FairRun::SetUseFairLinks(Bool_t val) { fRootManager->SetUseFairLinks(val); } + +void FairRun::SetWriteRunInfoFile(Bool_t write) +{ + LOG(warn) << "Function FairRun::SetWriteRunInfoFile(Bool_t) is depcrecated and will vanish in future versions of " + "FairRoot.\n"; + LOG(warn) << "Please use FairRun::SetGenerateRunInfo(Bool_t) instead."; + + fGenerateRunInfo = write; +} + +Bool_t FairRun::GetWriteRunInfoFile() +{ + LOG(warn) + << "Function FairRun::GetWriteRunInfoFile() is depcrecated and will vanish in future versions of FairRoot.\n"; + LOG(warn) << "Please use FairRun::IsRunInfoGenerated() instead."; + + return fGenerateRunInfo; +} + +void FairRun::SetOutputFile(const char* fname) +{ + LOG(warning) << "FairRun::SetOutputFile() deprecated. Use FairRootFileSink."; + fSink = new FairRootFileSink(fname); + if (fRootManager) + fRootManager->SetSink(fSink); + fUserOutputFileName = fname; +} + +void FairRun::SetOutputFile(TFile* f) +{ + LOG(warning) << "FairRun::SetOutputFile() deprecated. Use FairRootFileSink."; + fSink = new FairRootFileSink(f); + if (fRootManager) + fRootManager->SetSink(fSink); + if (f) + fUserOutputFileName = f->GetName(); +} + +void FairRun::SetOutputFileName(const TString& name) +{ + LOG(warning) << "FairRun::SetOutputFileName() deprecated. Use FairRootFileSink."; + fSink = new FairRootFileSink(name); + if (fRootManager) + fRootManager->SetSink(fSink); + fUserOutputFileName = name; +} + +TFile* FairRun::GetOutputFile() +{ + LOG(warning) << "FairRun::GetOutputFile() deprecated. Use separate file to store additional data."; + auto sink = GetSink(); + assert(sink->GetSinkType() == kFILESINK); + auto rootFileSink = static_cast(sink); + return rootFileSink->GetRootFile(); +} + +void FairRun::SetUserOutputFileName(const TString& name) { fUserOutputFileName = name; } + +TString FairRun::GetUserOutputFileName() const { return fUserOutputFileName; } + +void FairRun::AlignGeometry() const { fAlignmentHandler.AlignGeometry(); } + +void FairRun::AddAlignmentMatrices(const std::map& alignmentMatrices, bool invertMatrices) +{ + fAlignmentHandler.AddAlignmentMatrices(alignmentMatrices, invertMatrices); +} + +ClassImp(FairRun); diff --git a/Detectors/3rdparty/FairRootBase/src/FairRunIdGenerator.cxx b/Detectors/3rdparty/FairRootBase/src/FairRunIdGenerator.cxx new file mode 100644 index 0000000000000..67114c4760dd7 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRunIdGenerator.cxx @@ -0,0 +1,404 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * gen_uuid.c --- generate a DCE-compatible uuid + * + * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU + * Library General Public License. + * %End-Header% + */ + +/* + * Force inclusion of SVID stuff since we need it if we're compiling in + * gcc-wall wall mode + */ +#define _SVID_SOURCE +#define _DEFAULT_SOURCE + +#include "FairRunIdGenerator.h" + +#include // for rand, srand +#include // for memcpy +#include // for errno, EAGAIN, EINTR +#include // for open, O_RDONLY, O_NONBLOCK +#include // for gettimeofday +#include // for getpid, getuid, read + +#define srand(x) srandom(x) +#define rand() random() + +// using namespace std; + +//#include "genid32.h" replaced by hrunidgenerator.h + +/* + * uuid.h -- private header file for uuids + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU + * Library General Public License. + * %End-Header% + */ + +/* + * Offset between 15-Oct-1582 and 1-Jan-70 + */ +#define TIME_OFFSET_HIGH 0x01B21DD2 +#define TIME_OFFSET_LOW 0x13814000 + +int FairRunIdGenerator::get_random_fd(void) +{ + struct timeval tv; + static int fd = -2; + int i; + + if (fd == -2) { + gettimeofday(&tv, 0); + fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + fd = open("/dev/random", O_RDONLY | O_NONBLOCK); + } + srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec); + } + /* Crank the random number generator a few times */ + gettimeofday(&tv, 0); + for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--) { + rand(); + } + return fd; +} + +/* + * Generate a series of random bytes. Use /dev/urandom if possible, + * and if not, use srandom/random. + */ +void FairRunIdGenerator::get_random_bytes(void* buf, int nbytes) +{ + int i, fd = get_random_fd(); + int lose_counter = 0; + char* cp = static_cast(buf); + + if (fd >= 0) { + while (nbytes > 0) { + i = read(fd, cp, nbytes); + if ((i < 0) && ((errno == EINTR) || (errno == EAGAIN))) { + continue; + } + if (i <= 0) { + if (lose_counter++ == 8) { + break; + } + continue; + } + nbytes -= i; + cp += i; + lose_counter = 0; + } + } + /* XXX put something better here if no /dev/random! */ + for (i = 0; i < nbytes; i++) { + *cp++ = rand() & 0xFF; + } + return; +} + +/* + * Get the ethernet hardware address, if we can find it... + */ +int FairRunIdGenerator::get_node_id(unsigned char* /*node_id*/) +{ +#ifdef HAVE_NET_IF_H + int sd; + struct ifreq ifr, *ifrp; + struct ifconf ifc; + char buf[1024]; + int n, i; + unsigned char* a; + + /* + * BSD 4.4 defines the size of an ifreq to be + * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len + * However, under earlier systems, sa_len isn't present, so the size is + * just sizeof(struct ifreq) + */ +#ifdef HAVE_SA_LEN +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif +#define ifreq_size(i) max(sizeof(struct ifreq), sizeof((i).ifr_name) + (i).ifr_addr.sa_len) +#else +#define ifreq_size(i) sizeof(struct ifreq) +#endif /* HAVE_SA_LEN*/ + + sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); + if (sd < 0) { + return -1; + } + memset(buf, 0, sizeof(buf)); + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = buf; + if (ioctl(sd, SIOCGIFCONF, (char*)&ifc) < 0) { + close(sd); + return -1; + } + n = ifc.ifc_len; + for (i = 0; i < n; i += ifreq_size(*ifr)) { + ifrp = (struct ifreq*)((char*)ifc.ifc_buf + i); + strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ); +#ifdef SIOCGIFHWADDR + if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0) { + continue; + } + a = (unsigned char*)&ifr.ifr_hwaddr.sa_data; +#else +#ifdef SIOCGENADDR + if (ioctl(sd, SIOCGENADDR, &ifr) < 0) { + continue; + } + a = (unsigned char*)ifr.ifr_enaddr; +#else + /* + * XXX we don't have a way of getting the hardware + * address + */ + close(sd); + return 0; +#endif /* SIOCGENADDR */ +#endif /* SIOCGIFHWADDR */ + if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5]) { + continue; + } + if (node_id) { + memcpy(node_id, a, 6); + close(sd); + return 1; + } + } + close(sd); +#endif + return 0; +} + +/* Assume that the gettimeofday() has microsecond granularity */ +#define MAX_ADJUSTMENT 10 + +int FairRunIdGenerator::get_clock(uint32_t* clock_high, uint32_t* clock_low, uint16_t* ret_clock_seq) +{ + static int adjustment = 0; + static struct timeval last = {0, 0}; + static uint16_t clock_seq; + struct timeval tv; + unsigned long long clock_reg; + +try_again: + gettimeofday(&tv, 0); + if ((last.tv_sec == 0) && (last.tv_usec == 0)) { + get_random_bytes(&clock_seq, sizeof(clock_seq)); + clock_seq &= 0x1FFF; + last = tv; + last.tv_sec--; + } + if ((tv.tv_sec < last.tv_sec) || ((tv.tv_sec == last.tv_sec) && (tv.tv_usec < last.tv_usec))) { + clock_seq = (clock_seq + 1) & 0x1FFF; + adjustment = 0; + last = tv; + } else if ((tv.tv_sec == last.tv_sec) && (tv.tv_usec == last.tv_usec)) { + if (adjustment >= MAX_ADJUSTMENT) { + goto try_again; + } + adjustment++; + } else { + adjustment = 0; + last = tv; + } + + clock_reg = tv.tv_usec * 10 + adjustment; + clock_reg += (static_cast(tv.tv_sec)) * 10000000; + clock_reg += ((static_cast(0x01B21DD2)) << 32) + 0x13814000; + + *clock_high = clock_reg >> 32; + *clock_low = clock_reg; + *ret_clock_seq = clock_seq; + + fTimeSpec.tv_sec = last.tv_sec; + // fTimeSpec.tv_nsec = last.tv_usec*1000.; + fTimeSpec.tv_nsec = 0.; + + return 0; +} + +void FairRunIdGenerator::uuid_generate_time(uuid_t out) +{ + static unsigned char node_id[6]; + static int has_init = 0; + struct uuid uu; + uint32_t clock_mid; + + if (!has_init) { + if (get_node_id(node_id) <= 0) { + get_random_bytes(node_id, 6); + /* + * Set multicast bit, to prevent conflicts + * with IEEE 802 addresses obtained from + * network cards + */ + node_id[0] |= 0x80; + } + has_init = 1; + } + get_clock(&clock_mid, &uu.time_low, &uu.clock_seq); + uu.clock_seq |= 0x8000; + uu.time_mid = static_cast(clock_mid); + uu.time_hi_and_version = (clock_mid >> 16) | 0x1000; + memcpy(uu.node, node_id, 6); + uuid_pack(&uu, out); +} + +void FairRunIdGenerator::uuid_generate_random(uuid_t out) +{ + uuid_t buf; + struct uuid uu; + + get_random_bytes(buf, sizeof(buf)); + uuid_unpack(buf, &uu); + + uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000; + uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; + uuid_pack(&uu, out); +} + +/* + * This is the generic front-end to uuid_generate_random and + * uuid_generate_time. It uses uuid_generate_random only if + * /dev/urandom is available, since otherwise we won't have + * high-quality randomness. + */ +void FairRunIdGenerator::uuid_generate(uuid_t out) +{ + /* + if (get_random_fd() >= 0) { + uuid_generate_random(out); + } else { + uuid_generate_time(out); + } + */ + uuid_generate_time(out); +} + +/* + * Internal routine for packing UUID's + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU + * Library General Public License. + * %End-Header% + */ + +void FairRunIdGenerator::uuid_pack(const struct uuid* uu, uuid_t ptr) +{ + uint32_t tmp; + unsigned char* out = ptr; + + tmp = uu->time_low; + out[3] = static_cast(tmp); + tmp >>= 8; + out[2] = static_cast(tmp); + tmp >>= 8; + out[1] = static_cast(tmp); + tmp >>= 8; + out[0] = static_cast(tmp); + + tmp = uu->time_mid; + out[5] = static_cast(tmp); + tmp >>= 8; + out[4] = static_cast(tmp); + + tmp = uu->time_hi_and_version; + out[7] = static_cast(tmp); + tmp >>= 8; + out[6] = static_cast(tmp); + + tmp = uu->clock_seq; + out[9] = static_cast(tmp); + tmp >>= 8; + out[8] = static_cast(tmp); + + memcpy(out + 10, uu->node, 6); +} + +/* + * Internal routine for unpacking UUID + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU + * Library General Public License. + * %End-Header% + */ + +void FairRunIdGenerator::uuid_unpack(const uuid_t in, struct uuid* uu) +{ + const uint8_t* ptr = in; + uint32_t tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_low = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_mid = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_hi_and_version = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->clock_seq = tmp; + + memcpy(uu->node, ptr, 6); +} + +unsigned int FairRunIdGenerator::generateId(void) +{ + uuid_t uu; + // unsigned int v; + // struct timeval ret_tv; + uuid_generate(uu); + + /* + v = ((uu[0] ^ uu[4] ^ uu[8] ^ uu[12]) << 0) + | ((uu[1] ^ uu[5] ^ uu[9] ^ uu[13]) << 8) + | ((uu[2] ^ uu[6] ^ uu[10] ^ uu[14]) << 16) + | ((uu[3] ^ uu[7] ^ uu[11] ^ uu[15]) << 24); +*/ + + // return v & 0x7fffffff; + return getTID(); +} + +unsigned int FairRunIdGenerator::getTID() { return (fTimeSpec.tv_sec); } + +struct timespec FairRunIdGenerator::getTimeSpecFromTID(unsigned int ms) +{ + struct timespec ret_tv; + ret_tv.tv_sec = ms; + ret_tv.tv_nsec = 0.; // truncate the ns resolution + return ret_tv; +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairRunInfo.cxx b/Detectors/3rdparty/FairRootBase/src/FairRunInfo.cxx new file mode 100644 index 0000000000000..2c85e27747767 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRunInfo.cxx @@ -0,0 +1,199 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#include "FairRunInfo.h" + +#include "FairLogger.h" // for FairLogger + +#include // for TFile, gFile +#include // for TH1F +#include // for TIterator +#include // for TList +#include // for TString +#include // for ProcInfo_t, TSystem, etc +#include // for sort + +ClassImp(FairRunInfo); + +FairRunInfo::FairRunInfo() + : TObject() + , fTimeStamp() + , fCpuInfo() + , fMemInfo() + , fProcInfo() + , fTimeDiff() + , fTime() + , fResidentMemory() + , fVirtualMemory() +{} + +FairRunInfo::~FairRunInfo() {} + +void FairRunInfo::StoreInfo() +{ + // Extract the Information about the used memory from the system. + // Stores this info together with the timedifference between now + // and the last call in container arrays for later usage. + // gSystem->GetCpuInfo(&cpuInfo, 10); + // gSystem->GetMemInfo(&memInfo); + + GetInfo(); + + CalculateTimeDifference(); + + PrintInfo(); +} + +void FairRunInfo::GetInfo() +{ + // Set the TimeStamp to the actual time and store it + fTimeStamp.Set(); + // fTime.push_back(fTimeStamp.GetSec()); + fTime.push_back(fTimeStamp.AsDouble()); + + gSystem->GetProcInfo(&fProcInfo); + fResidentMemory.push_back(fProcInfo.fMemResident / 1024); + fVirtualMemory.push_back(fProcInfo.fMemVirtual / 1024); +} + +void FairRunInfo::CalculateTimeDifference() +{ + // Calculates the time difference between now and the last call + + Int_t lastElement = fTime.size() - 1; + fTimeDiff.push_back(fTime.at(lastElement) - fTime.at(lastElement - 1)); +} + +void FairRunInfo::PrintInfo() +{ + + LOG(debug) << "Time to execute 1 event: " << fTimeDiff.back() << "s"; + LOG(debug) << "Used resident memory: " << fResidentMemory.back() << " MB"; + LOG(debug) << "Used virtual memory: " << fVirtualMemory.back() << " MB"; +} + +void FairRunInfo::WriteInfo() +{ + TList* histoList = new TList(); + CreateAndFillHistograms(histoList); + // CreateAndFillHistograms(histoList); + WriteHistosToFile(histoList); +} + +void FairRunInfo::CreateAndFillHistograms(TList* histoList) +{ + Int_t entries = fTime.size(); + Double_t timePeriod = fTime.back() - fTime.front(); + Int_t timeBins = static_cast(timePeriod * 10); + if (0 == timeBins) + timeBins = 1; + + TH1F* ResidentMemoryVsEvent = new TH1F( + "ResidentMemoryVsEvent", "Resident Memory as function of Eventnumber;Event;Memory [MB]", entries, 0, entries); + TH1F* VirtualMemoryVsEvent = new TH1F( + "VirtualMemoryVsEvent", "Virtual Memory as function of Eventnumber;Event;Memory [MB]", entries, 0, entries); + TH1F* ResidentMemoryVsTime = new TH1F( + "ResidentMemoryVsTime", "Resident memory as function of Runtime;Time [s];Memory [MB]", timeBins, 0, timeBins); + TH1F* VirtualMemoryVsTime = new TH1F( + "VirtualMemoryVsTime", "Virtual memory as function of Runtime;Time [s];Memory [MB]", timeBins, 0, timeBins); + TH1F* EventtimeVsEvent = new TH1F( + "EventtimeVsEvent", "Runtime per Event as function of Event number;Event;Time [s]", entries - 1, 1, entries); + + std::vector timeDiffSorted(fTimeDiff); + std::vector::iterator it; + std::sort(timeDiffSorted.begin(), timeDiffSorted.end()); + + Double_t minTime = timeDiffSorted.front(); + Double_t maxTime = timeDiffSorted.back(); + timePeriod = maxTime - minTime; + + TH1F* TimePerEvent = new TH1F("TimePerEvent", + "Runtime;Time [s];Events", + static_cast((timePeriod + 20) * 10), + static_cast(minTime - 10), + static_cast(maxTime + 10)); + + Int_t counter = 0; + std::vector::iterator lit; + Double_t timeOffset = fTime.front() + 1.; + for (lit = fResidentMemory.begin(); lit < fResidentMemory.end(); ++lit) { + ResidentMemoryVsEvent->Fill(counter, *lit); + ResidentMemoryVsTime->Fill(fTime.at(counter) - timeOffset, *lit); + counter++; + } + histoList->AddLast(ResidentMemoryVsEvent); + histoList->AddLast(ResidentMemoryVsTime); + + counter = 0; + for (lit = fVirtualMemory.begin(); lit < fVirtualMemory.end(); ++lit) { + VirtualMemoryVsEvent->Fill(counter, *lit); + VirtualMemoryVsTime->Fill(fTime.at(counter) - timeOffset, *lit); + counter++; + } + histoList->AddLast(VirtualMemoryVsEvent); + histoList->AddLast(VirtualMemoryVsTime); + + counter = 1; + for (it = fTimeDiff.begin(); it < fTimeDiff.end(); ++it) { + TimePerEvent->Fill(*it); + EventtimeVsEvent->Fill(counter, *it); + counter++; + } + histoList->AddLast(TimePerEvent); + histoList->AddLast(EventtimeVsEvent); +} + +void FairRunInfo::WriteHistosToFile(TList* histoList) +{ + // If the file size is larger then approx. 2GB then the histos + // can't be read any longer. Because of this problem the histos + // are written to a separate file instead + + TFile* oldfile = gFile; + + TString directory = gFile->GetName(); + LOG(debug) << "Name: " << gFile->GetName(); + Ssiz_t posLastSlash = directory.Last('/'); + directory.Remove(posLastSlash + 1, directory.Length() - posLastSlash - 1); + TString filename = ""; + if (directory.EndsWith("/")) { + filename += directory; + } + + directory = gFile->GetName(); + LOG(debug) << "Name: " << directory.Data(); + posLastSlash = directory.Last('/'); + directory.Remove(0, posLastSlash + 1); + directory.ReplaceAll(".root", ""); + LOG(debug) << "Name: " << directory.Data(); + + // Int_t pid = gSystem->GetPid(); + filename += "FairRunInfo_"; + filename += directory; + filename += ".root"; + LOG(debug) << "Filename: " << filename.Data(); + + TFile* f1 = TFile::Open(filename, "recreate"); + f1->cd(); + + TIterator* listIter = histoList->MakeIterator(); + listIter->Reset(); + TObject* obj = nullptr; + while ((obj = listIter->Next())) { + obj->Write(); + } + + delete listIter; + histoList->Delete(); + delete histoList; + + f1->Close(); + f1->Delete(); + gFile = oldfile; +} + +void FairRunInfo::Reset() { GetInfo(); } diff --git a/Detectors/3rdparty/FairRootBase/src/FairRunSim.cxx b/Detectors/3rdparty/FairRootBase/src/FairRunSim.cxx new file mode 100644 index 0000000000000..bf8ff912f1b7b --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairRunSim.cxx @@ -0,0 +1,317 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// Modified for ALICE O2 in 2026: parts not used by O2 were removed (see README.md in this directory). + +// ----- FairRunSim source file ----- +// ----- Created 06/01/04 by M. Al-Turany ----- + +#include "FairRunSim.h" + +#include "FairField.h" // for FairField +#include "FairFileHeader.h" // for FairFileHeader +#include "FairGenericVMCConfig.h" // for FairGenericVMCConfig +#include "FairGeoInterface.h" // for FairGeoInterface +#include "FairGeoLoader.h" // for FairGeoLoader +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairMCEventHeader.h" // for FairMCEventHeader +#include "FairMesh.h" // for FairMesh +#include "FairModule.h" // for FairModule +#include "FairPrimaryGenerator.h" // for FairPrimaryGenerator +#include "FairRootManager.h" // for FairRootManager +#include "FairRunIdGenerator.h" // for FairRunIdGenerator +#include "FairTask.h" // for FairTask +#include "FairTrajFilter.h" // for FairTrajFilter + +#include // for TIter +#include // for gGeoManager +#include // for TList +#include // for TObjString +#include // for TObject +#include // for gRandom +#include // for TSystem, gSystem +#include // for cout, endl, ostream +#include // for getenv, nullptr +#include // for strcmp, strncmp + +using std::cout; +using std::endl; + +ClassImp(FairRunSim); + +FairRunSim::FairRunSim(Bool_t isMaster) + : FairRun(isMaster) + , count(0) + , fApp(nullptr) + , fBeamMom(0) + , fUseBeamMom(kFALSE) + , fGen(nullptr) + , fMCEvHead(nullptr) + , fField(nullptr) + , fMapName("") + , fIons(new TObjArray()) + , fParticles(new TObjArray()) + , ListOfModules(new TObjArray()) + , MatFname("") + , fStoreTraj(kFALSE) + , fLoaderName(new TString("TGeo")) + , fPythiaDecayer(kFALSE) + , fPythiaDecayerConfig("") + , fUserDecay(kFALSE) + , fUserDecayConfig("") + , fRadLength(kFALSE) + , fRadMap(kFALSE) + , fRadGrid(kFALSE) + , fMeshList(new TObjArray()) + , fUserConfig("") + , fUserCuts("SetCuts.C") + , fIsMT(kFALSE) + , fImportTGeoToVMC(kTRUE) + , fSimulationConfig(nullptr) + +{ + if (fginstance) { + Fatal("FairRun", "Singleton instance already exists."); + return; + } + fginstance = this; + fRunId = 0; + fAna = kFALSE; +} + +FairRunSim::~FairRunSim() +{ + LOG(debug) << "Enter Destructor of FairRunSim "; + + // delete fApp; + + /** List of Modules is filled via AddModule from the macro, but it + is the responsibility of FairRunSim to call the destructors of + the modules- + */ + LOG(debug) << "Start deleting all registered modules"; + ListOfModules->Delete(); + delete ListOfModules; + LOG(debug) << "Finish deleting all registered modules"; + + fIons->Delete(); + delete fIons; + fParticles->Delete(); + delete fParticles; + + delete fApp; + // delete fField; + // Not owner of the field + delete fGen; + delete fMCEvHead; +} + +FairRunSim* FairRunSim::Instance() { return fginstance; } + +void FairRunSim::AddModule(FairModule* Mod) +{ + ListOfModules->Add(Mod); + Mod->SetModId(count++); +} + +void FairRunSim::AddMesh(FairMesh* Mesh) +{ + Mesh->print(); + Mesh->calculate(); + fMeshList->Add(Mesh); +} + +TObjArray* FairRunSim::GetUserDefIons() +{ + /** return the array of user defined ions*/ + return fIons; +} + +TObjArray* FairRunSim::GetUserDefParticles() +{ + /** return the array of user defined particles*/ + return fParticles; +} + +void FairRunSim::Init() +{ + /**Initialize the simulation session*/ + fRootManager->InitSink(); + + CheckFlukaExec(); + + // fOutFile=fRootManager->OpenOutFile(fOutname); + LOG(info) << "============== FairRunSim: Initialising simulation run =============="; + + FairGeoLoader* loader = new FairGeoLoader(fLoaderName->Data(), "Geo Loader"); + FairGeoInterface* GeoInterFace = loader->getGeoInterface(); + GeoInterFace->SetNoOfSets(ListOfModules->GetEntries()); + GeoInterFace->setMediaFile(MatFname.Data()); + GeoInterFace->readMedia(); + + // gSystem->cd(flout.Data()); + + fApp = new FairMCApplication("Fair", "The Fair VMC App", ListOfModules, MatFname); + fApp->SetGenerator(fGen); + + // Add a Generated run ID to the FairRunTimeDb + if (fRunId == 0) { + FairRunIdGenerator genid; + fRunId = genid.generateId(); + } + fFileHeader->SetRunId(fRunId); + /** Add Tasks to simulation if any*/ + fApp->AddTask(fTask); + // The FairBaseParSet / FairGeoParSet runtime-database containers were filled + // here but never written out nor read back; the database has been removed. + + // Set global Parameter Info + + if (fPythiaDecayer) { + fApp->SetPythiaDecayer(fPythiaDecayer); + if (fPythiaDecayerConfig) { + fApp->SetPythiaDecayerConfig(fPythiaDecayerConfig); + } + } + if (fUserDecay) { + fApp->SetUserDecay(fUserDecay); + if (fUserDecayConfig) { + fApp->SetUserDecayConfig(fUserDecayConfig); + } + } + // on/off visualisation + if (fStoreTraj) { + LOG(info) << "Create visualisation manager "; + new FairTrajFilter(); + } + if (fRadLength) { + fApp->SetRadiationLengthReg(fRadLength); + } + if (fRadMap) { + fApp->SetRadiationMapReg(fRadMap); + } + if (fRadGrid) { + fApp->AddMeshList(fMeshList); + } + + if (fField) { + fField->Init(); + } + fApp->SetField(fField); + + /**Set the configuration for MC engine*/ + SetMCConfig(); + fRootManager->WriteFileHeader(fFileHeader); +} + + +void FairRunSim::CheckFlukaExec() +{ + /** Private method for setting FLUKA simulation*/ + TString work = getenv("VMCWORKDIR"); + TString work_config = work + "/gconfig/"; + work_config.ReplaceAll("//", "/"); + + TString config_dir = getenv("CONFIG_DIR"); + config_dir.ReplaceAll("//", "/"); + if (!config_dir.EndsWith("/")) { + config_dir += "/"; + } + + TString flout; + if (strcmp(GetName(), "TFluka") == 0) { + TString flexec = "run_fluka.sh"; + if (TString(gSystem->FindFile(config_dir.Data(), flexec)) != TString("")) { + LOG(info) << "---User path for Configuration is used: " << config_dir.Data(); + } else { + flexec = work_config + "run_fluka.sh"; + } + gSystem->Exec(flexec.Data()); + // More generic for different macro + // dir layout + TString macrodir = getenv("PWD"); + // cout << macrodir << endl; + flout = macrodir + "/fluka_out"; + flout.ReplaceAll("//", "/"); + gSystem->cd(flout.Data()); + } +} + +void FairRunSim::SetMCConfig() +{ + // Either setup the simulation with the provided user hook + if (fUseSimSetupFunction) { + fSimSetup(); + } else { + if (fSimulationConfig == nullptr) // RKRKRK COMMENT + fSimulationConfig = new FairGenericVMCConfig(); + fSimulationConfig->Setup(GetName()); + } + + fApp->InitMC("foo", "bar"); +} + +void FairRunSim::Run(Int_t NEvents, Int_t) { fApp->RunMC(NEvents); } + +void FairRunSim::SetField(FairField* field) { fField = field; } + +void FairRunSim::SetGenerator(FairPrimaryGenerator* Gen) { fGen = Gen; } + +void FairRunSim::SetMaterials(const char* MatFileName) +{ + TString Mat = ""; + TString work = getenv("GEOMPATH"); + work.ReplaceAll("//", "/"); + if (work.IsNull()) { + work = getenv("VMCWORKDIR"); + Mat = work + "/geometry/"; + Mat.ReplaceAll("//", "/"); + } else { + Mat = work; + if (!Mat.EndsWith("/")) { + Mat += "/"; + } + } + MatFname = Mat + MatFileName; + LOG(info) << "Media file used: " << MatFname.Data(); +} + +void FairRunSim::SetGeoModel(char* name) +{ + if (strncmp(fName, "TGeant3", 7) == 0) { + delete fLoaderName; + fLoaderName = new TString(name); + LOG(info) << "FairRun::SetGeoModel(): G3 native geometry model used "; + } else { + LOG(info) << "FairRun::SetGeoModel(): Geant3 MC engine only !"; + LOG(info) << "FairRun::SetGeoModel(): Method skipped ... "; + } +} + +void FairRunSim::SetPythiaDecayer(const TString& Config) +{ + /**switch On external decayer (Pythia). Config macro will be used */ + fPythiaDecayerConfig = Config; + fPythiaDecayer = kTRUE; +} + +void FairRunSim::SetUserDecay(const TString& Config) +{ + /**switch On user defined decay, Config macro will be called */ + fUserDecayConfig = Config; + fUserDecay = kTRUE; +} + +FairMCEventHeader* FairRunSim::GetMCEventHeader() +{ + if (nullptr == fMCEvHead) { + fMCEvHead = new FairMCEventHeader(); + } + return fMCEvHead; +} + +TMCThreadLocal FairRunSim* FairRunSim::fginstance = 0; diff --git a/Detectors/3rdparty/FairRootBase/src/FairSink.cxx b/Detectors/3rdparty/FairRootBase/src/FairSink.cxx new file mode 100644 index 0000000000000..5e36b08bab634 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairSink.cxx @@ -0,0 +1,32 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence version 3 (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairSink ----- +// ----- Created 22.12.2017 by R. Karabowicz ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#include "FairSink.h" + +#include +#include + +FairSink::FairSink() + : fRunId(0) + , fOutFolder(0) +{} + +FairSink::FairSink(const FairSink& sink) + : fRunId(sink.fRunId) + , fOutFolder(0) +{} + +FairSink::~FairSink() {} + +ClassImp(FairSink); diff --git a/Detectors/3rdparty/FairRootBase/src/FairSource.cxx b/Detectors/3rdparty/FairRootBase/src/FairSource.cxx new file mode 100644 index 0000000000000..bbcf93eab3d62 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairSource.cxx @@ -0,0 +1,38 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----------------------------------------------------------------------------- +// ----- ----- +// ----- FairSource ----- +// ----- Created 01.11.2013 by F. Uhlig ----- +// ----- ----- +// ----------------------------------------------------------------------------- + +#include "FairSource.h" + +#include "FairEventHeader.h" + +FairSource::FairSource() + : TObject() + , fRunId(0) +{} + +FairSource::FairSource(const FairSource& source) + : TObject(source) + , fRunId(source.fRunId) +{} + +FairSource::~FairSource() {} + +void FairSource::FillEventHeader(FairEventHeader* eh) +{ + if (eh) { + eh->SetRunId(fRunId); + } +} + +ClassImp(FairSource); diff --git a/Detectors/3rdparty/FairRootBase/src/FairSystemInfo.cxx b/Detectors/3rdparty/FairRootBase/src/FairSystemInfo.cxx new file mode 100644 index 0000000000000..1f7180d6172bd --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairSystemInfo.cxx @@ -0,0 +1,83 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairSystemInfo.cxx + * + * Created on: Mar 18, 2015 + * Author: f.uhlig + */ + +#include "FairSystemInfo.h" + +#include +#include + +#if defined(__APPLE__) && defined(__MACH__) +#include + +#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) +#include +#include + +#else +#error "Unknown OS." +#endif + +Float_t FairSystemInfo::GetMaxMemory() +{ + // Returns the maximal used memory in MB + + struct rusage rusage; + getrusage(RUSAGE_SELF, &rusage); + +#if defined(__APPLE__) && defined(__MACH__) + return static_cast(rusage.ru_maxrss) / (1024 * 1024); +#else + return static_cast(rusage.ru_maxrss) / 1024; +#endif +} + +/** + * Returns the current resident set size (physical memory use) measured + * in bytes, or zero if the value cannot be determined on this OS. + */ +size_t FairSystemInfo::GetCurrentMemory() +{ +#if defined(__APPLE__) && defined(__MACH__) + /* OSX ------------------------------------------------------ */ + struct mach_task_basic_info info; + mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; + if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, reinterpret_cast(&info), &infoCount) + != KERN_SUCCESS) + // (task_info_t)&info, &infoCount ) != KERN_SUCCESS ) + return static_cast(0L); /* Can't access? */ + return static_cast(info.resident_size); + +#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) + /* Linux ---------------------------------------------------- */ + long rss = 0L; + long pagesize = sysconf(_SC_PAGESIZE); + FILE* fp = NULL; + if ((fp = fopen("/proc/self/statm", "r")) == NULL) + return (size_t)0L; /* Can't open? */ + if (fscanf(fp, "%*s%ld", &rss) != 1) { + fclose(fp); + return (size_t)0L; /* Can't read? */ + } + fclose(fp); + if (rss > 0 && rss < std::numeric_limits::max() / pagesize) { + return (size_t)rss * (size_t)sysconf(_SC_PAGESIZE); + } else { + return (size_t)0L; + } + +#else + /* AIX, BSD, Solaris, and Unknown OS ------------------------ */ + return (size_t)0L; /* Unsupported. */ +#endif +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairTSBufferFunctional.cxx b/Detectors/3rdparty/FairRootBase/src/FairTSBufferFunctional.cxx new file mode 100644 index 0000000000000..22c2463b2ce9a --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairTSBufferFunctional.cxx @@ -0,0 +1,294 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#include "FairTSBufferFunctional.h" + +#include "FairLink.h" // for FairLink +#include "FairRootManager.h" // for FairRootManager +#include "FairTimeStamp.h" // for FairTimeStamp + +#include // for TBranch +#include // for TClass +#include // for TClonesArray +#include // for TTree + +ClassImp(FairTSBufferFunctional); + +FairTSBufferFunctional::FairTSBufferFunctional(TString branchName, + TTree* sourceTree, + BinaryFunctor* stopFunction, + BinaryFunctor* startFunction) + : TObject() + , fOutputArray(nullptr) + , fBufferArray(nullptr) + , fInputArray(nullptr) + , fStartFunction(startFunction) + , fStopFunction(stopFunction) + , fBranch(nullptr) + , fBranchIndex(-1) + , fTerminate(kFALSE) + , fVerbose(0) +{ + fBranch = sourceTree->GetBranch(branchName.Data()); + if (fBranch == 0) { + std::cout << "-E- FairTSBufferFunctional::FairTSBufferFunctional Branch " << branchName << " does not exist!" + << std::endl; + } + FairRootManager* ioman = FairRootManager::Instance(); + fInputArray = static_cast(ioman->GetObject(branchName.Data())); + fBufferArray = new TClonesArray(fInputArray->GetClass()->GetName()); + fOutputArray = new TClonesArray(fInputArray->GetClass()->GetName()); +} + +TClonesArray* FairTSBufferFunctional::GetData(Double_t stopParameter) +{ + Double_t actualTime = 0.; + int posBuffer = 0; + + if (fStopFunction == 0) { // no function is given ==> read in data in traditional way event by event + ReadInNextEntry(); + fOutputArray->AbsorbObjects(static_cast(fInputArray), 0, fInputArray->GetEntriesFast() - 1); + return fOutputArray; + } + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData for stopParameter: " << stopParameter << std::endl; + } + + // if the BufferArray is empty fill it + if (fBufferArray->GetEntriesFast() == 0) { + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData fBufferArray is empty: Read in Data" << std::endl; + } + ReadInNextFilledEntry(); + AbsorbDataBufferArray(); + } + + // if the BufferArray is still empty you have reached the end of your data set + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData fBufferArray->GetEntriesFast(): " + << fBufferArray->GetEntriesFast() << std::endl; + } + FairTimeStamp* dataPoint = static_cast(fBufferArray->Last()); + if (dataPoint == 0) { + if (fVerbose > 0) { + std::cout << "-I- FairTSBufferFunctional::GetData dataPoint is empty ==> All Data read in" << std::endl; + } + return fOutputArray; + } + + dataPoint = static_cast(fBufferArray->First()); + + while (!(*fStopFunction)(dataPoint, stopParameter)) { // check if you have reached end of requested data + posBuffer++; + // if you have reached the end of the BufferArray fill it with new data from tree + if (posBuffer == fBufferArray->GetEntriesFast()) { + ReadInNextFilledEntry(); + AbsorbDataBufferArray(); + } + // if you are still at the end of the BufferArray than break (no new data in tree) + if (posBuffer == fBufferArray->GetEntriesFast()) { + break; + } + dataPoint = static_cast(fBufferArray->At(posBuffer)); + if (fVerbose > 1) { + std::cout << posBuffer << " TimeStampData: " << dataPoint->GetTimeStamp() << std::endl; + } + } + + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData Index for Absorb: " << posBuffer + << " BufferArray size: " << fBufferArray->GetEntriesFast() << std::endl; + } + if (posBuffer < fBufferArray->GetEntriesFast() && posBuffer > 0) { + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData absorb BufferArray up to posBuffer " << posBuffer + << " into fOutputArray" << std::endl; + } + fOutputArray->AbsorbObjects(fBufferArray, 0, posBuffer - 1); + posBuffer = 0; + return fOutputArray; + } + if (fVerbose > 1) { + std::cout << "Index: " << posBuffer << " BranchIndex: " << fBranchIndex << " NBranch " << fBranch->GetEntries() + << std::endl; + } + + if (posBuffer >= fBufferArray->GetEntriesFast() && posBuffer != 0 && fBranchIndex + 1 >= fBranch->GetEntries()) { + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData end of data reached. Send the rest to the OutputArray!" + << std::endl; + } + fOutputArray->AbsorbObjects(fBufferArray, 0, fBufferArray->GetEntries() - 1); + } + + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::GetData: Read in up to entry: " << fBranchIndex << " with actualTime " + << actualTime << " and requested stopParameter " << stopParameter << std::endl; + } + + return fOutputArray; +} + +TClonesArray* FairTSBufferFunctional::GetData(Double_t startParameter, Double_t stopParameter) +{ + if (fStartFunction != 0) { + fBufferArray->Delete(); + fOutputArray->Delete(); + Int_t startIndex = FindStartIndex(startParameter); + // std::cout << "StartParameter : " << startParameter << " StartIndex: " << startIndex << "/" << + // GetBranchIndex() << " size BufferArray " << fBufferArray->GetEntries() < -1) { + ReadInEntry(fBranchIndex); + fBufferArray->AbsorbObjects(fInputArray, startIndex, fInputArray->GetEntries() - 1); + } + } + return GetData(stopParameter); +} + +Int_t FairTSBufferFunctional::FindStartIndex(Double_t startParameter) +{ + FairTimeStamp* dataPoint; + Int_t tempIndex = fBranchIndex; + // Bool_t runBackwards = kTRUE; + Int_t previousIndex = -1; + Int_t previousBranchIndex = -1; + + ReadInEntry(tempIndex); //< Get Data out of Tree + + while (fInputArray->GetEntries() == 0 && tempIndex > 0) { //< If the entry of the tree was empty read in previous + // entries until you find one which is filled + tempIndex--; + ReadInEntry(tempIndex); + } + + if (fInputArray->GetEntries() + == 0) { // If the previous entries in the tree are also empty run in the forward direction + ReadInNextFilledEntry(); + // runBackwards = kFALSE; + } + + if (fInputArray->GetEntries() == 0) { // If there is still no data the branch is empty! + std::cout << "-I- FairTSBufferFunctional::FindStartIndex: All entries are empty!" << std::endl; + return -1; + } + fBranchIndex = tempIndex; + // Now we have data or FindStartIndex already returned -1 + + dataPoint = static_cast(fInputArray->Last()); + // std::cout << "DataPoint: " << *dataPoint << std::endl; + while (!(*fStartFunction)(dataPoint, startParameter)) { + // std::cout << "DataPoint Search Entry: " << fBranchIndex << ": " << *dataPoint << std::endl; + ReadInNextFilledEntry(); + if (fInputArray->GetEntries() != 0) { + dataPoint = static_cast(fInputArray->Last()); + } else { + return -1; + } + } + + // Now you have data where the last element in the array does not fit to your request + Int_t startPos = fInputArray->GetEntries() - 1; + while ((*fStartFunction)(dataPoint, startParameter)) { + // std::cout << "DataPoint Search in Entry: " << fBranchIndex << ": " << *dataPoint << std::endl; + previousIndex = startPos; + previousBranchIndex = fBranchIndex; + startPos--; + if (startPos == -1) { + fBranchIndex = ReadInPreviousFilledEntry(fBranchIndex); + startPos = fInputArray->GetEntries() - 1; + if (startPos < 0) { + if (fBranchIndex == 0) { + return 0; + } + return -1; + } + } + dataPoint = static_cast(fInputArray->At(startPos)); + } + fBranchIndex = previousBranchIndex; + return previousIndex; +} + +void FairTSBufferFunctional::ReadInNextFilledEntry() +{ + fInputArray->Delete(); + + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::ReadInNextFilledEntry: Entries in InputArray " + << fInputArray->GetEntriesFast() << " Branch Entries: " << fBranch->GetEntries() << std::endl; + } + while (fInputArray->GetEntriesFast() == 0 && fBranchIndex + 1 < fBranch->GetEntries()) { + fBranchIndex++; + ReadInEntry(fBranchIndex); + } +} + +Int_t FairTSBufferFunctional::ReadInPreviousFilledEntry(Int_t startEntry) +{ + Int_t tempIndex = startEntry; + + fInputArray->Delete(); + while (fInputArray->GetEntriesFast() == 0 && tempIndex > 0) { + tempIndex--; + ReadInEntry(tempIndex); + } + return tempIndex; +} + +void FairTSBufferFunctional::AbsorbDataBufferArray() +{ + if (fInputArray->GetEntriesFast() > 0) { + if (fVerbose > 1) { + std::cout << "-I- FairTSBufferFunctional::ReadInNextFilledEntry: Absorb InputArray into Buffer" + << std::endl; + } + fBufferArray->AbsorbObjects(fInputArray, 0, fInputArray->GetEntries() - 1); + } +} + +void FairTSBufferFunctional::ReadInNextEntry() +{ + if (fBranchIndex + 1 < fBranch->GetEntries()) { + fBranchIndex++; + ReadInEntry(fBranchIndex); + } +} + +void FairTSBufferFunctional::ReadInEntry(Int_t number) +{ + fInputArray->Delete(); + if (number < fBranch->GetEntries()) { + fBranch->GetEntry(number); + for (int i = 0; i < fInputArray->GetEntriesFast(); i++) { + (static_cast(fInputArray->At(i))) + ->SetEntryNr(FairLink(0, number, FairRootManager::Instance()->GetBranchId(fBranch->GetName()), i, 1)); + } + if (fVerbose > 1) + std::cout << "-I- FairTSBufferFunctional::ReadInEntry BranchIndex: " << number + << " Entries: " << fInputArray->GetEntriesFast() << std::endl; + } +} + +Bool_t FairTSBufferFunctional::AllDataProcessed() +{ + if (fTerminate == kTRUE) { + return kTRUE; + } + if (fBranchIndex + 1 >= fBranch->GetEntries()) { + if (fBufferArray->GetEntriesFast() == 0) { + if (fOutputArray->GetEntriesFast() == 0) { + return kTRUE; + } else { + return kFALSE; + } + } else { + return kFALSE; + } + } else { + return kFALSE; + } +} diff --git a/Detectors/3rdparty/FairRootBase/src/FairTask.cxx b/Detectors/3rdparty/FairRootBase/src/FairTask.cxx new file mode 100644 index 0000000000000..accb54c048c57 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairTask.cxx @@ -0,0 +1,251 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ----- FairTask source file ----- +// ----- Created 12/01/04 by M. Al-Turany / D. Bertini ----- + +#include "FairTask.h" + +#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN +#include "FairMonitor.h" // for FairMonitor + +#include // for TIter +#include // for TList +#include // for TObject +#include // printf +#include // pair + +FairTask::FairTask() + : TTask() + , fVerbose(0) + , fInputPersistance(-1) + , fLogger(FairLogger::GetLogger()) + , fStreamProcessing(kFALSE) + , fOutputPersistance() +{} + +FairTask::FairTask(const char* name, Int_t iVerbose) + : TTask(name, "FairTask") + , fVerbose(iVerbose) + , fInputPersistance(-1) + , fLogger(FairLogger::GetLogger()) + , fOutputPersistance() +{} + +FairTask::~FairTask() {} + +void FairTask::InitTask() +{ + FairMonitor::GetMonitor()->SetCurrentTask(this); + if (!fActive) { + return; + } + InitStatus tStat = Init(); + if (tStat == kFATAL) { + LOG(fatal) << "Initialization of Task " << fName.Data() << " failed fatally"; + } + if (tStat == kERROR) { + fActive = kFALSE; + } + FairMonitor::GetMonitor()->SetCurrentTask(0); + InitTasks(); +} + +void FairTask::ReInitTask() +{ + if (!fActive) { + return; + } + InitStatus tStat = ReInit(); + if (tStat == kFATAL) { + LOG(fatal) << "Reinitialization of Task " << fName.Data() << " failed fatally"; + } + if (tStat == kERROR) { + fActive = kFALSE; + } + ReInitTasks(); +} + +void FairTask::SetParTask() +{ + if (!fActive) { + return; + } + SetParContainers(); + SetParTasks(); +} + +void FairTask::FinishEvent() +{ + if (!fActive) { + return; + } + FinishEvents(); +} + +void FairTask::FinishTask() +{ + if (!fActive) { + return; + } + Finish(); + FinishTasks(); +} + +void FairTask::SetVerbose(Int_t iVerbose) +{ + fVerbose = iVerbose; + TIter next(GetListOfTasks()); + FairTask* task; + while ((task = dynamic_cast(next()))) { + task->SetVerbose(iVerbose); + } +} + +void FairTask::InitTasks() +{ + TIter next(GetListOfTasks()); + FairTask* task; + while ((task = dynamic_cast(next()))) { + task->InitTask(); + } +} + +void FairTask::ExecuteTask(Option_t* option) +{ + // Execute main task and its subtasks. + // When calling this function, the Exec function of the corresponding class + // is invoked, then the list of its subtasks is executed calling recursively + // all the subtasks, etc. + // + // The option parameter may be used to select different execution steps + // within a task. This parameter is passed also to all the subtasks. + + if (fgBeginTask) { + Error("ExecuteTask", "Cannot execute task:%s, already running task: %s", GetName(), fgBeginTask->GetName()); + return; + } + if (!IsActive()) + return; + + fOption = option; + fgBeginTask = this; + fgBreakPoint = 0; + + if (fBreakin) + return; + if (gDebug > 1) { + LOG(info) << "Execute task:" << GetName() << " : " << GetTitle(); + } + FairMonitor::GetMonitor()->StartMonitoring(this, "EXEC"); + Exec(option); + FairMonitor::GetMonitor()->StopMonitoring(this, "EXEC"); + + fHasExecuted = kTRUE; + ExecuteTasks(option); + + if (fBreakout) + return; + + if (!fgBreakPoint) { + fgBeginTask->CleanTasks(); + fgBeginTask = 0; + } +} + +void FairTask::ExecuteTasks(Option_t* option) +{ + // Execute all the subtasks of a task. + + TIter next(fTasks); + FairTask* task; + while ((task = static_cast(next()))) { + if (fgBreakPoint) + return; + if (!task->IsActive()) + continue; + if (task->fHasExecuted) { + task->ExecuteTasks(option); + continue; + } + if (task->fBreakin == 1) { + printf("Break at entry of task: %s\n", task->GetName()); + fgBreakPoint = this; + task->fBreakin++; + return; + } + + if (gDebug > 1) { + LOG(info) << "Execute task:" << task->GetName() << " : " << task->GetTitle(); + } + FairMonitor::GetMonitor()->StartMonitoring(task, "EXEC"); + task->Exec(option); + FairMonitor::GetMonitor()->StopMonitoring(task, "EXEC"); + + task->fHasExecuted = kTRUE; + task->ExecuteTasks(option); + if (task->fBreakout == 1) { + printf("Break at exit of task: %s\n", task->GetName()); + fgBreakPoint = this; + task->fBreakout++; + return; + } + } +} + +void FairTask::ReInitTasks() +{ + TIter next(GetListOfTasks()); + FairTask* task; + while ((task = dynamic_cast(next()))) { + task->ReInitTask(); + } +} + +void FairTask::SetParTasks() +{ + TIter next(GetListOfTasks()); + FairTask* task; + while ((task = dynamic_cast(next()))) { + task->SetParTask(); + } +} + +void FairTask::FinishTasks() +{ + TIter next(GetListOfTasks()); + FairTask* task; + while ((task = dynamic_cast(next()))) { + task->FinishTask(); + } +} + +void FairTask::FinishEvents() +{ + TIter next(GetListOfTasks()); + FairTask* task; + while ((task = dynamic_cast(next()))) { + task->FinishEvent(); + } +} + +void FairTask::SetOutputBranchPersistent(TString branchName, Bool_t persistence) +{ + fOutputPersistance.insert(std::pair(branchName, persistence)); +} + +Bool_t FairTask::IsOutputBranchPersistent(TString branchName) +{ + std::map::iterator it = fOutputPersistance.find(branchName); + if (it != fOutputPersistance.end()) { + return it->second; + } else { + return kTRUE; + } +} + +ClassImp(FairTask); diff --git a/Detectors/3rdparty/FairRootBase/src/FairTimeStamp.cxx b/Detectors/3rdparty/FairRootBase/src/FairTimeStamp.cxx new file mode 100644 index 0000000000000..784da78984e79 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairTimeStamp.cxx @@ -0,0 +1,17 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +#include "FairTimeStamp.h" + +std::ostream& FairTimeStamp::PrintTimeInfo(std::ostream& out) const +{ + out << " TimeStamp: " << GetTimeStamp() << " +/- " << GetTimeStampError() << std::endl; + FairMultiLinkedData_Interface::PrintLinkInfo(out); + return out; +} + +ClassImp(FairTimeStamp); diff --git a/Detectors/3rdparty/FairRootBase/src/FairTrajFilter.cxx b/Detectors/3rdparty/FairRootBase/src/FairTrajFilter.cxx new file mode 100644 index 0000000000000..bb15b005fce5d --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairTrajFilter.cxx @@ -0,0 +1,337 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ********************************************* // +// *** D. Kresan 2004-Sep-14 *** // +// *** D.Kresan@gsi.de *** // +// ********************************************* // + +#include "FairTrajFilter.h" + +#include "FairRootManager.h" // for FairRootManager + +#include // for TClonesArray +#include // for Fatal +#include +#include +#include +#include // for Pi, TwoPi, Log +#include // for Abs +#include // for TParticle +#include // for operator<<, basic_ostream, etc + +using namespace std; + +ClassImp(FairTrajFilter); + +TMCThreadLocal FairTrajFilter* FairTrajFilter::fgInstance = nullptr; + +FairTrajFilter* FairTrajFilter::Instance() { return fgInstance; } + +FairTrajFilter::FairTrajFilter() + : fVxMin(-2000.) + , fVxMax(2000.) + , fVyMin(-2000.) + , fVyMax(2000.) + , fVzMin(-2000.) + , fVzMax(2000.) + , fPMin(0.) + , fPMax(1e10) + , fThetaMin(0.) + , fThetaMax(TMath::Pi()) + , fPhiMin(0.) + , fPhiMax(TMath::TwoPi()) + , fPxMin(-1e10) + , fPxMax(1e10) + , fPyMin(-1e10) + , fPyMax(1e10) + , fPzMin(-1e10) + , fPzMax(1e10) + , fPtMin(0.) + , fPtMax(1e10) + , fRapidityMin(-1e10) + , fRapidityMax(1e10) + , fKinCutType(0) + , // polar system by default + fEtotMin(0.) + , fEtotMax(1e10) + , fStorePrim(kTRUE) + , fStoreSec(kTRUE) + , fStepSizeMin(0.1) + , // 1mm by default + fTrackCollection(new TClonesArray("TGeoTrack")) + , fCurrentTrk(nullptr) +{ + if (nullptr != fgInstance) { + Fatal("FairTrajFilter", "Singleton class already exists."); + return; + } + + fgInstance = this; +} + +FairTrajFilter::~FairTrajFilter() { fgInstance = nullptr; } + +void FairTrajFilter::Init(TString brName, TString folderName) +{ + FairRootManager::Instance()->Register(brName.Data(), folderName.Data(), fTrackCollection, kTRUE); +} + +void FairTrajFilter::Reset() { fTrackCollection->Delete(); } + +Bool_t FairTrajFilter::IsAccepted(const TParticle* p) const +{ + if (nullptr == p) { + return kFALSE; + } + + // Apply vertex cut + if ((p->Vx() < fVxMin) || (p->Vx() > fVxMax) || (p->Vy() < fVyMin) || (p->Vy() > fVyMax) || (p->Vz() < fVzMin) + || (p->Vz() > fVzMax)) { + return kFALSE; + } + + // Apply cut on kinematics + if (0 == fKinCutType) { + if ((p->P() < fPMin) || (p->P() > fPMax) || (p->Theta() < fThetaMin) || (p->Theta() > fThetaMax) + || (p->Phi() < fPhiMin) || (p->Phi() > fPhiMax)) { + return kFALSE; + } + } else if (1 == fKinCutType) { + if ((p->Px() < fPxMin) || (p->Px() > fPxMax) || (p->Py() < fPyMin) || (p->Py() > fPyMax) || (p->Pz() < fPzMin) + || (p->Pz() > fPzMax)) { + return kFALSE; + } + } else { + Double_t rapidity = 0.5 * TMath::Log((p->Energy() + p->Pz()) / (p->Energy() - p->Pz())); + if ((p->Pt() < fPtMin) || (p->Pt() > fPtMax) || (rapidity < fRapidityMin) || (rapidity > fRapidityMax)) { + return kFALSE; + } + } + + // Apply energy cut + if ((p->Energy() < fEtotMin) || (p->Energy() > fEtotMax)) { + return kFALSE; + } + + // Apply generation cut + if (-1 == p->GetFirstMother()) { + if (kFALSE == fStorePrim) { + return kFALSE; + } + } else { + if (kFALSE == fStoreSec) { + return kFALSE; + } + } + + return kTRUE; +} + +void FairTrajFilter::SetVertexCut(Double_t vxMin, + Double_t vyMin, + Double_t vzMin, + Double_t vxMax, + Double_t vyMax, + Double_t vzMax) +{ + TGeoBBox* cave = static_cast(gGeoManager->GetTopVolume()->GetShape()); + cave->ComputeBBox(); + Double_t caveX = 2. * cave->GetDX(); + Double_t caveY = 2. * cave->GetDY(); + Double_t caveZ = 2. * cave->GetDZ(); + if ((vxMax < vxMin) || (vyMax < vyMin) || (vzMax < vzMin) || (TMath::Abs(vxMin) > caveX) + || (TMath::Abs(vxMax) > caveX) || (TMath::Abs(vyMin) > caveY) || (TMath::Abs(vyMax) > caveY) + || (TMath::Abs(vzMin) > caveZ) || (TMath::Abs(vzMax) > caveZ)) { + cout << "-E- FairTrajFilter::SetVertexCut() : invalid region, ignoring." << endl; + return; + } + fVxMin = vxMin; + fVxMax = vxMax; + fVyMin = vyMin; + fVyMax = vyMax; + fVzMin = vzMin; + fVzMax = vzMax; +} + +void FairTrajFilter::SetMomentumCutP(Double_t pMin, + Double_t thetaMin, + Double_t phiMin, + Double_t pMax, + Double_t thetaMax, + Double_t phiMax) +{ + if ((pMax < pMin) || (thetaMax < thetaMin) || (phiMax < phiMin) || (pMin < 0.) || (pMax < 0.) || (thetaMin < 0.) + || (thetaMax > TMath::Pi()) || (phiMin < 0.) || (phiMax > TMath::TwoPi())) { + cout << "-E- FairTrajFilter::SetMomentumCutP() : invalid region, ignoring." << endl; + return; + } + fPMin = pMin; + fPMax = pMax; + fThetaMin = thetaMin; + fThetaMax = thetaMax; + fPhiMin = phiMin; + fPhiMax = phiMax; + fKinCutType = 0; +} + +void FairTrajFilter::SetMomentumCutD(Double_t pxMin, + Double_t pyMin, + Double_t pzMin, + Double_t pxMax, + Double_t pyMax, + Double_t pzMax) +{ + if ((pxMax < pxMin) || (pyMax < pyMin) || (pzMax < pzMin)) { + cout << "-E- FairTrajFilter::SetMomentumCutD() : invalid region, ignoring." << endl; + return; + } + fPxMin = pxMin; + fPxMax = pxMax; + fPyMin = pyMin; + fPyMax = pyMax; + fPzMin = pzMin; + fPzMax = pzMax; + fKinCutType = 1; +} + +void FairTrajFilter::SetPtRapidityCut(Double_t ptMin, Double_t ptMax, Double_t rapidityMin, Double_t rapidityMax) +{ + if ((ptMax < ptMin) || (rapidityMax < rapidityMin) || (ptMin < 0.) || (ptMax < 0.)) { + cout << "-E- FairTrajFilter::SetPtRapidityCut() : invalid region, ignoring." << endl; + return; + } + fPtMin = ptMin; + fPtMax = ptMax; + fRapidityMin = rapidityMin; + fRapidityMax = rapidityMax; + fKinCutType = 2; +} + +void FairTrajFilter::SetEnergyCut(Double_t etotMin, Double_t etotMax) +{ + if ((etotMax < etotMin) || (etotMin < 0.) || (etotMax < 0.)) { + cout << "-E- FairTrajFilter::SetEnergyCut() : invalid region, ignoring." << endl; + return; + } + fEtotMin = etotMin; + fEtotMax = etotMax; +} + +void FairTrajFilter::SetStepSizeCut(Double_t stepSizeMin) +{ + if (stepSizeMin < 0.) { + cout << "-E- FairTrajFilter::SetStepSizeCut() : invalid value, ignoring." << endl; + return; + } + fStepSizeMin = stepSizeMin; +} + +void FairTrajFilter::GetVertexCut(Double_t& vxMin, + Double_t& vyMin, + Double_t& vzMin, + Double_t& vxMax, + Double_t& vyMax, + Double_t& vzMax) const +{ + vxMin = fVxMin; + vxMax = fVxMax; + vyMin = fVyMin; + vyMax = fVyMax; + vzMin = fVzMin; + vzMax = fVzMax; +} + +void FairTrajFilter::GetMomentumCutP(Double_t& pMin, + Double_t& thetaMin, + Double_t& phiMin, + Double_t& pMax, + Double_t& thetaMax, + Double_t& phiMax) const +{ + pMin = fPMin; + pMax = fPMax; + thetaMin = fThetaMin; + thetaMax = fThetaMax; + phiMin = fPhiMin; + phiMax = fPhiMax; +} + +void FairTrajFilter::GetMomentumCutD(Double_t& pxMin, + Double_t& pyMin, + Double_t& pzMin, + Double_t& pxMax, + Double_t& pyMax, + Double_t& pzMax) const +{ + pxMin = fPxMin; + pxMax = fPxMax; + pyMin = fPyMin; + pyMax = fPyMax; + pzMin = fPzMin; + pzMax = fPzMax; +} + +void FairTrajFilter::GetPtRapidityCut(Double_t& ptMin, + Double_t& ptMax, + Double_t& rapidityMin, + Double_t& rapidityMax) const +{ + ptMin = fPtMin; + ptMax = fPtMax; + rapidityMin = fRapidityMin; + rapidityMax = fRapidityMax; +} + +void FairTrajFilter::GetEnergyCut(Double_t& etotMin, Double_t& etotMax) const +{ + etotMin = fEtotMin; + etotMax = fEtotMax; +} + +TGeoTrack* FairTrajFilter::AddTrack(Int_t trackId, Int_t pdgCode) +{ + + // cout << "FairTrajFilter::AddTrack" << endl; + TClonesArray& clref = *fTrackCollection; + Int_t tsize = clref.GetEntriesFast(); + fCurrentTrk = new (clref[tsize]) TGeoTrack(trackId, pdgCode); + return fCurrentTrk; +} + +TGeoTrack* FairTrajFilter::AddTrack(TParticle* p) +{ + Int_t trackId = 0; + // cout << "FairTrajFilter::AddTrack" << endl; + if (fCurrentTrk) { + trackId = fCurrentTrk->GetId(); + } + Int_t pdgCode = p->GetPdgCode(); + TClonesArray& clref = *fTrackCollection; + Int_t tsize = clref.GetEntriesFast(); + fCurrentTrk = new (clref[tsize]) TGeoTrack(++trackId, pdgCode, 0, p); + return fCurrentTrk; +} + +TGeoTrack* FairTrajFilter::CheckAddTrack(Int_t trackId, TParticle* p) +{ + TClonesArray& clref = *fTrackCollection; + Int_t tsize = clref.GetEntriesFast(); + for (Int_t itr = tsize - 1; itr >= 0; --itr) { + TGeoTrack* tempTrack = dynamic_cast(clref.At(itr)); + if (tempTrack->GetId() == trackId) { + fCurrentTrk = tempTrack; + return fCurrentTrk; + } + } + // track with given trackId not found, creating new one + Int_t pdgCode = p->GetPdgCode(); + fCurrentTrk = new (clref[tsize]) TGeoTrack(trackId, pdgCode, 0, p); + return fCurrentTrk; +} + +TGeoTrack* FairTrajFilter::GetTrack(Int_t trackId) { return static_cast(fTrackCollection->At(trackId)); } diff --git a/Detectors/3rdparty/FairRootBase/src/FairVolume.cxx b/Detectors/3rdparty/FairRootBase/src/FairVolume.cxx new file mode 100644 index 0000000000000..8e56b02ac4321 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairVolume.cxx @@ -0,0 +1,69 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairVolume source file ----- +// ----- Created 12/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +#include "FairVolume.h" + +FairVolume::FairVolume() + : TNamed() + , + // fName(""), /**Volume Name in MC*/ + fRealName("") + , /**Volume Name in ASCII file*/ + fVolumeId(-1) + , /**Volume Id in GeoManager*/ + fModId(-1) + , /**Module Id in which this volume exist*/ + fMCid(-1) + , /**Volume Id in MC*/ + fCopyNo(-1) + , /**Volume Copy No*/ + fMotherId(-1) + , /**Mother Volume Id*/ + fMotherCopyNo(-1) + , /**Mother Volume Copy No*/ + fDetector(0) + , fModule(nullptr) + , /**The Module (detector) which will proccess the hits for this volume*/ + fNode(nullptr) /**Node corre*/ +{} + +FairVolume::FairVolume(TString name, Int_t id, Int_t ModId, FairModule* fMod) + : TNamed(name, name) + , + // fName(name), + fRealName("") + , /**Volume Name in ASCII file*/ + fVolumeId(id) + , /**Volume Id in GeoManager*/ + fModId(ModId) + , /**Module Id in which this volume exist*/ + fMCid(-1) + , /**Volume Id in MC*/ + fCopyNo(-1) + , /**Volume Copy No*/ + fMotherId(0) + , /**Mother Volume Id*/ + fMotherCopyNo(0) + , /**Mother Volume Copy No*/ + fDetector(0) + , fModule(fMod) + , /**The Module (detector) which will proccess the hits for this volume*/ + fNode(nullptr) /**Node corre*/ +{ + if (fModule && fModule->InheritsFrom("FairDetector")) { + fDetector = dynamic_cast(fModule); + } +} + +FairVolume::~FairVolume() {} + +ClassImp(FairVolume); diff --git a/Detectors/3rdparty/FairRootBase/src/FairVolumeList.cxx b/Detectors/3rdparty/FairRootBase/src/FairVolumeList.cxx new file mode 100644 index 0000000000000..3a481331d2a08 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairVolumeList.cxx @@ -0,0 +1,81 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +// ------------------------------------------------------------------------- +// ----- FairVolumeList source file ----- +// ----- Created 12/01/04 by M. Al-Turany ----- +// ------------------------------------------------------------------------- + +#include "FairVolumeList.h" + +#include "FairLogger.h" // for logging +#include "FairVolume.h" // for FairVolume + +FairVolumeList::FairVolumeList() + : TObject() + , fData(new TObjArray()) +{} + +FairVolumeList::~FairVolumeList() +{ + if (fData) { + fData->Delete(); + delete fData; + } +} + +FairVolume* FairVolumeList::getVolume(TString* name) +{ + + TObject* obj = findObject(*name); + if (obj) { + LOG(info) << "FairVolume getVolume " << name->Data() << "found"; + } + + return static_cast(obj); +} + +Int_t FairVolumeList::getVolumeId(TString* name) +{ + FairVolume* vol = getVolume(name); + + if (vol) { + return vol->getVolumeId(); + } else { + return -111; + } +} + +FairVolume* FairVolumeList::findObject(TString name) +{ + FairVolume* obj = nullptr; + + for (int i = 0; i < fData->GetEntriesFast(); i++) { + obj = static_cast(fData->At(i)); + if (obj) { + if (obj->GetName() == name) { + return static_cast(obj); + } + } + } + + return nullptr; +} + +void FairVolumeList::addVolume(FairVolume* elem) +{ + FairVolume* v = static_cast(findObject(elem->GetName())); + + if (v) { + LOG(error) << "FairVolumeList element: " << elem->GetName() << " VolId : " << elem->getVolumeId() + << " already defined " << v->getVolumeId(); + } else { + fData->Add(elem); + } +} + +ClassImp(FairVolumeList); diff --git a/Detectors/3rdparty/FairRootBase/src/FairWriteoutBuffer.cxx b/Detectors/3rdparty/FairRootBase/src/FairWriteoutBuffer.cxx new file mode 100644 index 0000000000000..2037ae7b08e18 --- /dev/null +++ b/Detectors/3rdparty/FairRootBase/src/FairWriteoutBuffer.cxx @@ -0,0 +1,282 @@ +/******************************************************************************** + * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * * + * This software is distributed under the terms of the * + * GNU Lesser General Public Licence (LGPL) version 3, * + * copied verbatim in the file "LICENSE" * + ********************************************************************************/ +/* + * FairWriteoutBuffer.cpp + * + * Created on: Jul 30, 2010 + * Author: stockman + */ + +#include "FairWriteoutBuffer.h" + +#include "FairLogger.h" // for FairLogger +#include "FairRootManager.h" // for FairRootManager + +#include // for operator<<, ostream, cout, etc +#include // for reverse_iterator + +FairWriteoutBuffer::FairWriteoutBuffer(TString branchName, TString className, TString folderName, Bool_t persistance) + : TObject() + , fStartTime_map() + , fDeadTime_map() + , fBranchName(branchName) + , fClassName(className) + , fTreeSave(true) + , fActivateBuffering(kTRUE) + , fVerbose(0) + , fLogger(FairLogger::GetLogger()) +{ + FairRootManager::Instance()->Register(branchName, className, folderName, persistance); + if (fBranchName == "" || fClassName == "") { + fTreeSave = false; + } else { + fTreeSave = true; + } +} + +void FairWriteoutBuffer::WriteOutData(double time) +{ + if (fActivateBuffering) { + if (fVerbose > 0) { + std::cout << "Before removing: "; + PrintStartTimeMap(); + PrintDeadTimeMap(); + } + + MoveDataFromStartTimeMapToDeadTimeMap(time); + + if (fVerbose > 0) { + std::cout << "After removing: "; + PrintStartTimeMap(); + PrintDeadTimeMap(); + } + + WriteOutDataDeadTimeMap(time); + + if (fVerbose > 0) { + std::cout << "DeadTime map after readout time: " << time << std::endl; + PrintDeadTimeMap(); + } + + } else { + FairRootManager::Instance()->GetTClonesArray(fBranchName); + } +} + +void FairWriteoutBuffer::WriteOutDataDeadTimeMap(double time) +{ + FairRootManager* ioman = FairRootManager::Instance(); + std::vector data; + if (fActivateBuffering) { + if (fVerbose > 0) { + std::cout << "-I- FairWriteoutBuffer::WriteOutData for time: " << time << std::endl; + } + data = GetRemoveOldData(time); + if (fTreeSave && data.size() > 0) { + TClonesArray* myArray = ioman->GetTClonesArray(fBranchName); + if (!myArray) { + std::cout << "-E- FairWriteoutBuffer::WriteOutData " << fBranchName << " array is not available!" + << std::endl; + } + if (fVerbose > 0) { + std::cout << "-I- FairWriteoutBuffer::WriteOutData size: " << data.size() << std::endl; + } + for (unsigned int i = 0; i < data.size(); i++) { + AddNewDataToTClonesArray(data[i]); + if (fVerbose > 1) { + std::cout << i << " : "; + data[i]->Print(); + std::cout << std::endl; + } + delete data[i]; + } + } + } else { + ioman->GetTClonesArray(fBranchName); + } +} + +void FairWriteoutBuffer::WriteOutAllData() +{ + double ultimateTime = 0; + + if (fStartTime_map.size() > 0) { + ultimateTime = fStartTime_map.rbegin()->first + 1; + MoveDataFromStartTimeMapToDeadTimeMap(ultimateTime); + } + + if (fDeadTime_map.size() > 0) { + if (fDeadTime_map.rbegin()->first > ultimateTime) { + ultimateTime = fDeadTime_map.rbegin()->first + 1; + } + } + + if (ultimateTime > 0) { + WriteOutData(ultimateTime); + } +} + +std::vector FairWriteoutBuffer::GetRemoveOldData(double time) +{ + typedef std::multimap::iterator DTMapIter; + std::vector result; + for (DTMapIter it = fDeadTime_map.begin(); it != fDeadTime_map.lower_bound(time); ++it) { + if (fVerbose > 1) { + std::cout << "-I- GetRemoveOldData: DeadTime: " << it->first << " Data: " << it->second << std::endl; + } + result.push_back(it->second); + EraseDataFromDataMap(it->second); + } + fDeadTime_map.erase(fDeadTime_map.begin(), fDeadTime_map.lower_bound(time)); + return result; +} + +std::vector FairWriteoutBuffer::GetAllData() +{ + return GetRemoveOldData(fDeadTime_map.rbegin()->first + 1); +} + +void FairWriteoutBuffer::FillNewData(FairTimeStamp* data, double startTime, double activeTime) +{ + FairTimeStamp* dataClone = static_cast(data->Clone()); + + if (fActivateBuffering) { + if (fVerbose > 0) { + std::cout << "StartTime: " << startTime << std::endl; + } + std::pair timeData(activeTime, dataClone); + fStartTime_map.insert(std::pair>(startTime, timeData)); + } else { + AddNewDataToTClonesArray(dataClone); + delete dataClone; + } +} + +void FairWriteoutBuffer::FillDataToDeadTimeMap(FairTimeStamp* data, double activeTime, double startTime) +{ + if (fActivateBuffering) { + typedef std::multimap::iterator DTMapIter; + // typedef std::map::iterator DataMapIter; + if (activeTime < 0) + activeTime = 0; // to avoid errors due to wrong (negative) returnvalues of overwritten modify function by + // subdetector groups. A negative (-1) aktiveTime already indicate empty data maps! + double timeOfOldData = FindTimeForData(data); + // PrintDeadTimeMap(); + if (timeOfOldData > -1) { // if an older active data object is already present + if (fVerbose > 1) { + std::cout << " OldData found! " << timeOfOldData << std::endl; + } + if (fVerbose > 1) { + std::cout << "New Data: " << activeTime << " : " << data << std::endl; + } + double currentdeadtime = timeOfOldData; + FairTimeStamp* oldData; + bool dataFound = false; + + // PrintDeadTimeMap(); + for (DTMapIter it = fDeadTime_map.lower_bound(currentdeadtime); + it != fDeadTime_map.upper_bound(currentdeadtime); + ++it) { + oldData = it->second; + if (fVerbose > 1) { + std::cout << "Check Data: " << it->first << " : " << oldData << std::endl; + } + if (oldData->equal(data)) { + if (fVerbose > 1) { + std::cout << " oldData == data " << std::endl; + } + if (fVerbose > 1) { + std::cout << it->first << " : " << it->second << std::endl; + } + fDeadTime_map.erase(it); + EraseDataFromDataMap(oldData); + dataFound = true; + break; + } + } + + if (dataFound == true) { + if (timeOfOldData + > startTime) { // if older active data can interference with the new data call modify function + std::vector> modifiedData = + Modify(std::pair(currentdeadtime, oldData), + std::pair(activeTime, data)); + for (unsigned int i = 0; i < modifiedData.size(); i++) { + FillDataToDeadTimeMap(modifiedData[i].second, + modifiedData[i].first, + 0); // startTime = 0 since the Maps are already empty and the startTime + // therefore doesn't matter anymore + if (fVerbose > 1) { + std::cout << i << " :Modified Data: " << modifiedData[i].first << " : " + << modifiedData[i].second << std::endl; + } + } + } else { // no interference can happen between old hit and new hit + AddNewDataToTClonesArray(oldData); // therefore the old hit is written out + fDeadTime_map.insert( + std::pair(activeTime, data)); // and the new hit is stored + FillDataMap(data, activeTime); + } + } else { + std::cout << "-E- FairWriteoutBuffer::FillDataToDeadTimeMap: old data present in dataMap but not in " + "deadTimeMap!" + << std::endl; + } + + } else { + if (fVerbose > 1) { + std::cout << "-I- FairWriteoutBuffer::FillDataToDeadTimeMap Data Inserted: " << activeTime << " : "; + data->Print(); + std::cout << std::endl; + } + fDeadTime_map.insert(std::pair(activeTime, data)); + FillDataMap(data, activeTime); + } + } else { + AddNewDataToTClonesArray(data); + delete data; + } +} + +void FairWriteoutBuffer::MoveDataFromStartTimeMapToDeadTimeMap(double time) +{ + typedef std::multimap>::iterator startTimeMapIter; + + startTimeMapIter stopTime = fStartTime_map.lower_bound(time); + for (startTimeMapIter iter = fStartTime_map.begin(); iter != stopTime; ++iter) { + std::pair data = iter->second; + double startTime = iter->first; + FillDataToDeadTimeMap(data.second, data.first, startTime); + } + fStartTime_map.erase(fStartTime_map.begin(), stopTime); +} + +void FairWriteoutBuffer::PrintStartTimeMap() +{ + typedef std::multimap>::iterator startTimeMapIter; + std::cout << "StartTimeMap: " << std::endl; + for (startTimeMapIter iter = fStartTime_map.begin(); iter != fStartTime_map.end(); ++iter) { + FairTimeStamp* data = iter->second.second; + std::cout << " | " << iter->first << "/" << data->GetTimeStamp(); + } + std::cout << " |" << std::endl; +} + +void FairWriteoutBuffer::PrintDeadTimeMap() +{ + typedef std::multimap::iterator DTMapIter; + std::cout << "DeadTimeMap: " << std::endl; + for (DTMapIter it = fDeadTime_map.begin(); it != fDeadTime_map.end(); ++it) { + std::cout << it->first << " / "; + PrintData(it->second); + std::cout << std::endl; + } + std::cout << std::endl; +} + +ClassImp(FairWriteoutBuffer); diff --git a/Detectors/Base/CMakeLists.txt b/Detectors/Base/CMakeLists.txt index 76e4ed9f741fd..d4fe4fd11a26c 100644 --- a/Detectors/Base/CMakeLists.txt +++ b/Detectors/Base/CMakeLists.txt @@ -37,7 +37,7 @@ o2_add_library(DetectorsBase src/GlobalParams.cxx src/O2Tessellated.cxx src/TGeoGeometryUtils.cxx - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::CommonUtils O2::DetectorsCommonDataFormats O2::DataFormatsCTP diff --git a/Detectors/Base/src/Propagator.cxx b/Detectors/Base/src/Propagator.cxx index a465bbc312c77..cdb3a0ee9db32 100644 --- a/Detectors/Base/src/Propagator.cxx +++ b/Detectors/Base/src/Propagator.cxx @@ -30,7 +30,6 @@ using namespace o2::gpu; #include "DataFormatsParameters/GRPObject.h" #include "DataFormatsParameters/GRPMagField.h" #include "DetectorsBase/GeometryManager.h" -#include // eventually will get rid of it #include template @@ -49,10 +48,9 @@ void PropagatorImpl::updateField() { if (!mField) { mField = static_cast(TGeoGlobalMagField::Instance()->GetField()); - if (!mField) { - LOG(warning) << "No Magnetic Field in TGeoGlobalMagField, checking legacy FairRunAna"; - mField = dynamic_cast(FairRunAna::Instance()->GetField()); - } + // The legacy FairRunAna fallback was removed with the FairRoot analysis-run + // class: O2 never instantiates one, so FairRunAna::Instance() was null here + // and the call was undefined behaviour; the fatal below is the real outcome. if (!mField) { LOG(fatal) << "Magnetic field is not initialized!"; } diff --git a/Detectors/CMakeLists.txt b/Detectors/CMakeLists.txt index 9094bca1a2d2e..699747e3131e9 100644 --- a/Detectors/CMakeLists.txt +++ b/Detectors/CMakeLists.txt @@ -9,6 +9,10 @@ # granted to it by virtue of its status as an Intergovernmental Organization # or submit itself to any jurisdiction. +# vendored FairRoot simulation base classes; must come first as +# DetectorsBase and most simulation libraries link against it +add_subdirectory(3rdparty/FairRootBase) + add_subdirectory(Base) add_subdirectory(CADSupport) add_subdirectory(Raw) diff --git a/Detectors/CPV/simulation/src/Detector.cxx b/Detectors/CPV/simulation/src/Detector.cxx index 1203aad5526f9..4191fbc574f95 100644 --- a/Detectors/CPV/simulation/src/Detector.cxx +++ b/Detectors/CPV/simulation/src/Detector.cxx @@ -18,7 +18,6 @@ #include "TVirtualMC.h" #include "TGeoPhysicalNode.h" -#include "FairGeoNode.h" #include "FairRootManager.h" #include "FairVolume.h" diff --git a/Detectors/CPV/testsimulation/CMakeLists.txt b/Detectors/CPV/testsimulation/CMakeLists.txt index 33a15099f64ca..38fe1b69ef50d 100644 --- a/Detectors/CPV/testsimulation/CMakeLists.txt +++ b/Detectors/CPV/testsimulation/CMakeLists.txt @@ -14,16 +14,3 @@ o2_add_test_root_macro(drawCPVgeometry.C O2::DetectorsPassive O2::PHOSSimulation LABELS cpv) - -o2_add_test_root_macro(plot_hit_cpv.C - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CPVSimulation - LABELS cpv COMPILE_ONLY) - -o2_add_test_root_macro(plot_dig_cpv.C - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CPVSimulation - LABELS cpv) - -o2_add_test_root_macro(plot_clu_cpv.C - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::CPVSimulation - LABELS cpv) - diff --git a/Detectors/CPV/testsimulation/plot_clu_cpv.C b/Detectors/CPV/testsimulation/plot_clu_cpv.C deleted file mode 100644 index e17f81156eb39..0000000000000 --- a/Detectors/CPV/testsimulation/plot_clu_cpv.C +++ /dev/null @@ -1,118 +0,0 @@ -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include -#include - -#include "TROOT.h" -#include -#include "TCanvas.h" -#include "TH2.h" -//#include "DataFormatsParameters/GRPObject.h" -#include "FairFileSource.h" -#include -#include "FairRunAna.h" -//#include "FairRuntimeDb.h" -#include "FairParRootFileIo.h" -#include "FairSystemInfo.h" -#include "SimulationDataFormat/MCCompLabel.h" - -#include "DataFormatsCPV/Cluster.h" -#include "CPVBase/Geometry.h" -#endif - -void plot_clu_cpv(std::string inputfile = "cpvclusters.root", int ifirst = 0, int ilast = -1) -{ - // macros to plot CPV clusters - - // Clusters - TFile* file0 = TFile::Open(inputfile.data()); - std::cout << " Open clusters file " << inputfile << std::endl; - TTree* cluTree = (TTree*)gFile->Get("o2sim"); - std::vector* mClustersArray = nullptr; - cluTree->SetBranchAddress("CPVCluster", &mClustersArray); - - if (!mClustersArray) { - std::cout << "CPV clusters not found in the file. Exiting ..." << std::endl; - return; - } - - TH1F* hClusterTotEnergy[5]; - TH1F* hClusterMaxEnergy[5]; - TH1F* hClusterSize[5]; - TH1F* hClusterSizeX[5]; - TH1F* hClusterSizeZ[5]; - - TH2D* vMod[5][1000] = {0}; - int primLabels[5][1000]; - for (int mod = 2; mod < 5; mod++) { - hClusterTotEnergy[mod] = new TH1F(Form("hClusterTotEnergy%d", mod), - Form("Cluster Total Energy mod %d", mod), 10000, 0, 10000); - hClusterMaxEnergy[mod] = new TH1F(Form("hClusterMaxEnergy%d", mod), - Form("Cluster Max Energy mod %d", mod), 10000, 0, 10000); - hClusterSize[mod] = new TH1F(Form("hClusterSize%d", mod), - Form("Cluster Size mod %d", mod), 100, 0, 100); - hClusterSizeX[mod] = new TH1F(Form("hClusterSizeX%d", mod), - Form("Cluster SizeX mod %d", mod), 100, 0, 100); - hClusterSizeZ[mod] = new TH1F(Form("hClusterSizeZ%d", mod), - Form("Cluster SizeZ mod %d", mod), 100, 0, 100); - - for (int j = 0; j < 100; j++) - primLabels[mod][j] = -1; - } - - int nEntries = cluTree->GetEntriesFast(); - if (ilast < 0) - ilast = nEntries; - if (ilast > nEntries) - ilast = nEntries; - - for (int ievent = ifirst; ievent < ilast; ievent++) { - cluTree->GetEvent(ievent); - - std::vector::const_iterator it; - std::cout << "I start cluster cycling (record #" << ievent << " in o2sim tree)" << std::endl; - - for (it = mClustersArray->begin(); it != mClustersArray->end(); it++) { - float en = (*it).getEnergy(); - float posX, posZ; - (*it).getLocalPosition(posX, posZ); - int cluSize = (*it).getMultiplicity(); - int mod = (*it).getModule(); - if (!vMod[mod][0]) { - gROOT->cd(); - vMod[mod][0] = - new TH2D(Form("hMod%d_prim%d", mod, 0), Form("hMod%d_prim%d", mod, 0), - 100, -100., 100., 100, -100., 100.); - } - vMod[mod][0]->Fill(posX, posZ, en); - hClusterTotEnergy[mod]->Fill(en); - hClusterSize[mod]->Fill(cluSize); - } - - std::cout << "I finish cycling clusters" << std::endl; - } - TCanvas* c[5]; - TH2D* box = new TH2D("box", "CPV module", 100, -100., 100., 100, -100., 100.); - TCanvas* cTotEn = new TCanvas(); - cTotEn->Divide(3, 1); - TCanvas* cSize = new TCanvas(); - cSize->Divide(3, 1); - - for (int mod = 2; mod < 5; mod++) { - c[mod] = - new TCanvas(Form("ClusterInMod%d", mod), Form("CPV clusters in module %d", mod), 10 * mod, 0, 600 + 10 * mod, 400); - box->Draw(); - int j = 0; - while (vMod[mod][j]) { - vMod[mod][j]->SetLineColor(j + 1); - if (j == 0) - vMod[mod][j]->Draw("box"); - else - vMod[mod][j]->Draw("boxsame"); - j++; - } - cTotEn->cd(mod - 1); - hClusterTotEnergy[mod]->Draw(); - cSize->cd(mod - 1); - hClusterSize[mod]->Draw(); - } -} diff --git a/Detectors/CPV/testsimulation/plot_dig_cpv.C b/Detectors/CPV/testsimulation/plot_dig_cpv.C deleted file mode 100644 index c6116f09e6bb0..0000000000000 --- a/Detectors/CPV/testsimulation/plot_dig_cpv.C +++ /dev/null @@ -1,106 +0,0 @@ -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include -#include - -#include "TROOT.h" -#include -#include "TCanvas.h" -#include "TH2.h" -#include "TH1.h" -//#include "DataFormatsParameters/GRPObject.h" -#include "FairFileSource.h" -#include -#include "FairRunAna.h" -//#include "FairRuntimeDb.h" -#include "FairParRootFileIo.h" -#include "FairSystemInfo.h" -#include "SimulationDataFormat/MCCompLabel.h" - -#include "DataFormatsCPV/Digit.h" -#include "CPVBase/Geometry.h" -#endif - -void plot_dig_cpv(int ievent = 0, std::string inputfile = "o2dig.root") -{ - // macros to plot CPV digits - - // Digits - TFile* file0 = TFile::Open(inputfile.data()); - std::cout << " Open digits file " << inputfile << std::endl; - TTree* hitTree = (TTree*)gFile->Get("o2sim"); - std::vector* mDigitsArray = nullptr; - hitTree->SetBranchAddress("CPVDigit", &mDigitsArray); - - if (!mDigitsArray) { - std::cout << "CPV digits not found in the file. Exiting ..." << std::endl; - return; - } - hitTree->GetEvent(ievent); - - TH1F* hDigitAmplitude[5]; - TH2D* vMod[5][1000] = {0}; - int primLabels[5][1000]; - for (int mod = 1; mod < 5; mod++) { - hDigitAmplitude[mod] = new TH1F(Form("hDigitAmplitude_mod%d", mod), - Form("Digit amplitudes in module %d", mod), - 4096, 0., 4096.); - for (int j = 0; j < 100; j++) - primLabels[mod][j] = -1; - } - - std::vector::const_iterator it; - short relId[3]; - std::cout << "I start digit cycling" << std::endl; - - for (it = mDigitsArray->begin(); it != mDigitsArray->end(); it++) { - short absId = (*it).getAbsId(); - float en = (*it).getAmplitude(); - int lab = (*it).getLabel(); //TODO - //std::cout << "label = " << lab << std::endl; - o2::cpv::Geometry::absToRelNumbering(absId, relId); - hDigitAmplitude[relId[0]]->Fill(en); - // check, if this label already exist - int j = 0; - bool found = false; - //no labels for the time being - // while (primLabels[relId[0]][j] >= -2) { - // if (primLabels[relId[0]][j] == lab) { - // found = true; - // break; - // } else { - // j++; - // } - // } - if (!found) { - primLabels[relId[0]][j] = lab; - } - if (!vMod[relId[0]][j]) { - gROOT->cd(); - vMod[relId[0]][j] = - new TH2D(Form("hMod%d_prim%d", relId[0], j), Form("hMod%d_prim%d", relId[0], j), 128, 0., 128., 60, 0., 60.); - } - vMod[relId[0]][j]->Fill(relId[1] - 0.5, relId[2] - 0.5, en); - } - - std::cout << "I finish cycling digits" << std::endl; - - TCanvas *c[5], *c_ampl[5]; - TH2D* box = new TH2D("box", "CPV module", 128, 0., 128., 60, 0., 60.); - for (int mod = 2; mod < 5; mod++) { - c[mod] = - new TCanvas(Form("DigitInMod%d", mod), Form("CPV digits in module %d", mod), 10 * mod, 0, 600 + 10 * mod, 400); - box->Draw(); - int j = 0; - while (vMod[mod][j]) { - vMod[mod][j]->SetLineColor(j + 1); - if (j == 0) - vMod[mod][j]->Draw("box"); - else - vMod[mod][j]->Draw("boxsame"); - j++; - } - c_ampl[mod] = new TCanvas(Form("DigitAmplitudes_%d", mod), Form("DigitAmplitudes_%d", mod), - 10 * mod + 800, 0, 600 + 10 * mod + 200, 400); - hDigitAmplitude[mod]->Draw(); - } -} diff --git a/Detectors/CPV/testsimulation/plot_hit_cpv.C b/Detectors/CPV/testsimulation/plot_hit_cpv.C deleted file mode 100644 index 7605b7be8c1fd..0000000000000 --- a/Detectors/CPV/testsimulation/plot_hit_cpv.C +++ /dev/null @@ -1,94 +0,0 @@ -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include - -#include "TROOT.h" -#include -#include "TCanvas.h" -#include "TH2.h" -//#include "DataFormatsParameters/GRPObject.h" -#include "FairFileSource.h" -#include -#include "FairRunAna.h" -#include "FairParRootFileIo.h" -#include "FairSystemInfo.h" -#include "SimulationDataFormat/MCCompLabel.h" -#include "CPVBase/Geometry.h" -#include "DataFormatsCPV/Hit.h" -#include "DetectorsCommonDataFormats/DetectorNameConf.h" -#include "DetectorsCommonDataFormats/DetID.h" -#endif - -using namespace o2::detectors; - -void plot_hit_cpv(int ievent = 0, std::string inputprefix = "o2sim") -{ - // macros to plot CPV hits - - // Hits - std::string inputfile(o2::base::DetectorNameConf::getHitsFileName(DetID::CPV, inputprefix)); - TFile* file0 = TFile::Open(inputfile.c_str()); - std::cout << " Open hits file " << inputfile << std::endl; - TTree* hitTree = (TTree*)gFile->Get("o2sim"); - std::vector* mHitsArray = nullptr; - hitTree->SetBranchAddress("CPVHit", &mHitsArray); - - if (!mHitsArray) { - std::cout << "CPV hits not registered in the FairRootManager. Exiting ..." << std::endl; - return; - } - hitTree->GetEvent(ievent); - - TH2D* vMod[5][100] = {0}; - int primLabels[5][100]; - for (int mod = 1; mod < 5; mod++) - for (int j = 0; j < 100; j++) - primLabels[mod][j] = -1; - - std::vector::iterator it; - short relId[3]; - - // for(it=mHitsArray->begin(); it!=mHitsArray->end(); it++){ - - for (auto& it : *mHitsArray) { - short absId = it.GetDetectorID(); - float en = it.GetEnergyLoss(); - int lab = it.GetTrackID(); - o2::cpv::Geometry::absToRelNumbering(absId, relId); - printf("reldId=(%d,%d,%d) \n", relId[0], relId[1], relId[2]); - // check, if this label already exist - int j = 0; - bool found = false; - while (primLabels[relId[0]][j] >= 0) { - if (primLabels[relId[0]][j] == lab) { - found = true; - break; - } else { - j++; - } - } - if (!found) { - primLabels[relId[0]][j] = lab; - } - if (!vMod[relId[0]][j]) { - gROOT->cd(); - vMod[relId[0]][j] = - new TH2D(Form("hMod%d_prim%d", relId[0], j), Form("hMod%d_prim%d", relId[0], j), 128, 0., 128., 60, 0., 60.); - } - vMod[relId[0]][j]->Fill(relId[1] - 0.5, relId[2] - 0.5, en); - } - - TCanvas* c[5]; - for (int mod = 1; mod < 5; mod++) { - c[mod] = - new TCanvas(Form("HitInMod%d", mod), Form("CPV hits in module %d", mod), 10 * mod, 0, 600 + 10 * mod, 400); - int j = 0; - while (vMod[mod][j]) { - vMod[mod][j]->SetLineColor(j + 1); - if (j == 0) - vMod[mod][j]->Draw("box"); - else - vMod[mod][j]->Draw("boxsame"); - j++; - } - } -} diff --git a/Detectors/EMCAL/simulation/src/Detector.cxx b/Detectors/EMCAL/simulation/src/Detector.cxx index 6dc4aded8a68d..4e6c7ced5c3e8 100644 --- a/Detectors/EMCAL/simulation/src/Detector.cxx +++ b/Detectors/EMCAL/simulation/src/Detector.cxx @@ -20,7 +20,6 @@ #include "TVector2.h" #include "TVector3.h" -#include "FairGeoNode.h" #include "FairRootManager.h" #include "FairVolume.h" diff --git a/Detectors/EMCAL/testsimulation/CMakeLists.txt b/Detectors/EMCAL/testsimulation/CMakeLists.txt index 6d6496e456281..75b84c3cdef7c 100644 --- a/Detectors/EMCAL/testsimulation/CMakeLists.txt +++ b/Detectors/EMCAL/testsimulation/CMakeLists.txt @@ -19,22 +19,17 @@ foreach(genmacro ${genmacros}) MESSAGE(STATUS "Adding test for macro ${genmacro}") o2_add_test_root_macro(${genmacro} COMPILE_ONLY - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase LABELS emcal) o2_data_file(COPY ${genmacro} DESTINATION Detectors/EMC/testsimulation) endforeach() o2_add_test_root_macro(PutEmcalInTop.C PUBLIC_LINK_LIBRARIES O2::EMCALSimulation - O2::DetectorsPassive FairRoot::Base + O2::DetectorsPassive O2::FairRootBase LABELS emcal) o2_add_test_root_macro(drawEMCALgeometry.C PUBLIC_LINK_LIBRARIES O2::EMCALSimulation - O2::DetectorsPassive FairRoot::Base - LABELS emcal) - -o2_add_test_root_macro(run_sim_emcal.C - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::EMCALSimulation - O2::DetectorsPassive O2::Generators + O2::DetectorsPassive O2::FairRootBase LABELS emcal) diff --git a/Detectors/EMCAL/testsimulation/run_sim_emcal.C b/Detectors/EMCAL/testsimulation/run_sim_emcal.C deleted file mode 100644 index 22ea9bdd2ad2e..0000000000000 --- a/Detectors/EMCAL/testsimulation/run_sim_emcal.C +++ /dev/null @@ -1,136 +0,0 @@ -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include - -#include "Rtypes.h" -#include "TSystem.h" -#include "TMath.h" -#include "TString.h" -#include "TStopwatch.h" -#include "TGeoManager.h" - -#include "FairRunSim.h" -#include -#include "FairRuntimeDb.h" -#include "FairPrimaryGenerator.h" -#include "FairBoxGenerator.h" -#include "FairParRootFileIo.h" -#include "FairSystemInfo.h" - -#include "TGeoGlobalMagField.h" -#include "Field/MagneticField.h" - -#include "DetectorsPassive/Cave.h" -#include "Generators/GeneratorFromFile.h" -#include "EMCALSimulation/Detector.h" -#endif - -#define BOX_GENERATOR 1 - -void run_sim_emcal(Int_t nEvents = 10, TString mcEngine = "TGeant3") -{ - FairLogger::GetLogger()->SetLogScreenLevel("DEBUG"); - TString dir = getenv("VMCWORKDIR"); - TString geom_dir = dir + "/Detectors/Geometry/"; - gSystem->Setenv("GEOMPATH", geom_dir.Data()); - - TString tut_configdir = dir + "/Detectors/gconfig"; - gSystem->Setenv("CONFIG_DIR", tut_configdir.Data()); - - // Output file name - char fileout[100]; - sprintf(fileout, "AliceO2_%s.emcal.mc_%i_event.root", mcEngine.Data(), nEvents); - TString outFile = fileout; - - // Parameter file name - char filepar[100]; - sprintf(filepar, "AliceO2_%s.emcal.params_%i.root", mcEngine.Data(), nEvents); - TString parFile = filepar; - - // In general, the following parts need not be touched - - // Debug option - gDebug = 0; - - // Timer - TStopwatch timer; - timer.Start(); - - // Create simulation run - FairRunSim* run = new FairRunSim(); - - run->SetName(mcEngine); // Transport engine - run->SetSink(new FairRootFileSink(outFile.Data())); // Output file - FairRuntimeDb* rtdb = run->GetRuntimeDb(); - - // Create media - run->SetMaterials("media.geo"); // Materials - - // Create geometry - o2::passive::Cave* cave = new o2::passive::Cave("CAVE"); - cave->SetGeometryFileName("cave.geo"); - run->AddModule(cave); - - o2::field::MagneticField* magField = new o2::field::MagneticField("Maps", "Maps", -1., -1., o2::field::MagFieldParam::k5kG); - run->SetField(magField); - - // ===| Add EMCAL |============================================================ - o2::emcal::Detector* emcal = new o2::emcal::Detector(kTRUE); - run->AddModule(emcal); - - // Create PrimaryGenerator - FairPrimaryGenerator* primGen = new FairPrimaryGenerator(); -#ifdef BOX_GENERATOR - FairBoxGenerator* boxGen = new FairBoxGenerator(211, 10); /*protons*/ - - //boxGen->SetThetaRange(0.0, 90.0); - boxGen->SetEtaRange(-0.9, 0.9); - boxGen->SetPRange(0.1, 5); - boxGen->SetPhiRange(0., 360.); - boxGen->SetDebug(kTRUE); - - primGen->AddGenerator(boxGen); -#else - // reading the events from a kinematics file (produced by AliRoot) - auto extGen = new o2::eventgen::GeneratorFromFile("Kinematics.root"); - extGen->SetStartEvent(2); - primGen->AddGenerator(extGen); -#endif - - run->SetGenerator(primGen); - - // store track trajectories - // run->SetStoreTraj(kTRUE); - - // Initialize simulation run - run->Init(); - - // Runtime database - Bool_t kParameterMerged = kTRUE; - FairParRootFileIo* parOut = new FairParRootFileIo(kParameterMerged); - parOut->open(parFile.Data()); - rtdb->setOutput(parOut); - rtdb->saveOutput(); - rtdb->print(); - - // Start run - run->Run(nEvents); - delete run; - // run->CreateGeometryFile("geofile_full.root"); - - // Finish - timer.Stop(); - Double_t rtime = timer.RealTime(); - Double_t ctime = timer.CpuTime(); - - // extract max memory usage - FairSystemInfo sysinfo; - - std::cout << std::endl - << std::endl; - std::cout << "Macro finished succesfully." << std::endl; - std::cout << "Output file is " << outFile << std::endl; - std::cout << "Parameter file is " << parFile << std::endl; - std::cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << std::endl - << std::endl; - std::cout << "Memory used " << sysinfo.GetMaxMemory() << "\n"; -} diff --git a/Detectors/FIT/FDD/base/CMakeLists.txt b/Detectors/FIT/FDD/base/CMakeLists.txt index 18a13fb34f2a2..8b01f8c839e99 100644 --- a/Detectors/FIT/FDD/base/CMakeLists.txt +++ b/Detectors/FIT/FDD/base/CMakeLists.txt @@ -11,8 +11,8 @@ o2_add_library(FDDBase SOURCES src/Geometry.cxx - PUBLIC_LINK_LIBRARIES O2::CommonConstants ROOT::Geom FairRoot::Base O2::FrameworkLogger) + PUBLIC_LINK_LIBRARIES O2::CommonConstants ROOT::Geom O2::FairRootBase O2::FrameworkLogger) -o2_target_root_dictionary(FDDBase +o2_target_root_dictionary(FDDBase HEADERS include/FDDBase/Geometry.h include/FDDBase/Constants.h) diff --git a/Detectors/FIT/FT0/base/CMakeLists.txt b/Detectors/FIT/FT0/base/CMakeLists.txt index e5fc77160ec7d..a9f3910090370 100644 --- a/Detectors/FIT/FT0/base/CMakeLists.txt +++ b/Detectors/FIT/FT0/base/CMakeLists.txt @@ -11,7 +11,7 @@ o2_add_library(FT0Base SOURCES src/Geometry.cxx - PUBLIC_LINK_LIBRARIES ROOT::Physics FairRoot::Base O2::DetectorsBase O2::DetectorsCommonDataFormats O2::FrameworkLogger) + PUBLIC_LINK_LIBRARIES ROOT::Physics O2::FairRootBase O2::DetectorsBase O2::DetectorsCommonDataFormats O2::FrameworkLogger) o2_target_root_dictionary(FT0Base HEADERS include/FT0Base/Geometry.h include/FT0Base/Constants.h diff --git a/Detectors/FIT/FV0/base/CMakeLists.txt b/Detectors/FIT/FV0/base/CMakeLists.txt index b8faf38fb070c..bc07622ca3c53 100644 --- a/Detectors/FIT/FV0/base/CMakeLists.txt +++ b/Detectors/FIT/FV0/base/CMakeLists.txt @@ -12,7 +12,7 @@ o2_add_library(FV0Base SOURCES src/Geometry.cxx PUBLIC_LINK_LIBRARIES ROOT::Geom - FairRoot::Base + O2::FairRootBase O2::FrameworkLogger O2::DetectorsBase O2::DetectorsCommonDataFormats) diff --git a/Detectors/ITSMFT/ITS/base/CMakeLists.txt b/Detectors/ITSMFT/ITS/base/CMakeLists.txt index 25f0f120b35cb..9918bda9715cb 100644 --- a/Detectors/ITSMFT/ITS/base/CMakeLists.txt +++ b/Detectors/ITSMFT/ITS/base/CMakeLists.txt @@ -10,14 +10,11 @@ # or submit itself to any jurisdiction. o2_add_library(ITSBase - SOURCES src/GeometryTGeo.cxx src/ContainerFactory.cxx - src/MisalignmentParameter.cxx + SOURCES src/GeometryTGeo.cxx src/DescriptorInnerBarrel.cxx src/ITSBaseParam.cxx PUBLIC_LINK_LIBRARIES O2::DetectorsBase O2::ITSMFTBase $<$:O2::ITS3Base>) o2_target_root_dictionary(ITSBase HEADERS include/ITSBase/GeometryTGeo.h - include/ITSBase/ContainerFactory.h - include/ITSBase/MisalignmentParameter.h include/ITSBase/DescriptorInnerBarrel.h include/ITSBase/ITSBaseParam.h) diff --git a/Detectors/ITSMFT/ITS/base/include/ITSBase/ContainerFactory.h b/Detectors/ITSMFT/ITS/base/include/ITSBase/ContainerFactory.h deleted file mode 100644 index baf2f3b94d243..0000000000000 --- a/Detectors/ITSMFT/ITS/base/include/ITSBase/ContainerFactory.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 ContainerFactory.h -/// \brief Definition of the ContainerFactory class - -#ifndef ALICEO2_ITS_CONTAINERFACTORY_H_ -#define ALICEO2_ITS_CONTAINERFACTORY_H_ - -#include "FairContFact.h" // for FairContFact, FairContainer (ptr only) -#include "Rtypes.h" // for ContainerFactory::Class, ClassDef, etc - -class FairParSet; - -class FairContainer; - -namespace o2 -{ -namespace its -{ -class ContainerFactory : public FairContFact -{ - private: - /// Creates the Container objects with all accepted - /// contexts and adds them to - /// the list of containers for the O2its library. - void mSetAllContainers(); - - public: - /// Default constructor - ContainerFactory(); - - /// Default destructor - ~ContainerFactory() override = default; - /// Calls the constructor of the corresponding parameter container. - /// For an actual context, which is not an empty string and not - /// the default context - /// of this container, the name is concatinated with the context. - FairParSet* createContainer(FairContainer*) override; - - ClassDefOverride(ContainerFactory, 0); // Factory for all AliceO2 ITS parameter containers -}; -} // namespace its -} // namespace o2 - -#endif diff --git a/Detectors/ITSMFT/ITS/base/include/ITSBase/MisalignmentParameter.h b/Detectors/ITSMFT/ITS/base/include/ITSBase/MisalignmentParameter.h deleted file mode 100644 index 0e663f23b2514..0000000000000 --- a/Detectors/ITSMFT/ITS/base/include/ITSBase/MisalignmentParameter.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 MisalignmentParameter.h -/// \brief Definition of the MisalignmentParameter class - -#ifndef ALICEO2_ITS_MISALIGNMENTPARAMETER_H_ -#define ALICEO2_ITS_MISALIGNMENTPARAMETER_H_ - -#include "FairParGenericSet.h" // for FairParGenericSet - -#include "Rtypes.h" // for ClassDef - -#include "TArrayD.h" // for TArrayD - -class FairParamList; - -namespace o2 -{ -namespace its -{ -class MisalignmentParameter : public FairParGenericSet -{ - public: - MisalignmentParameter(const char* name = "MisalignmentParameter", - const char* title = "Misalignment parameter for AliceO2ITSHitProducerIdealMisallign Parameters", - const char* context = "TestDefaultContext"); - - ~MisalignmentParameter() override; - - void Clear(); - - void putParams(FairParamList*) override; - - Bool_t getParams(FairParamList*) override; - - TArrayD getShiftX() { return mShiftX; } - TArrayD getShiftY() { return mShiftY; } - TArrayD getShiftZ() { return mShiftZ; } - TArrayD getRotX() { return mRotX; } - TArrayD getRotY() { return mRotY; } - TArrayD getRotZ() { return mRotZ; } - Int_t getNumberOfDetectors() { return mNumberOfDetectors; } - - private: - TArrayD mShiftX; ///< Array to hold the misalignment in x-direction - TArrayD mShiftY; ///< Array to hold the misalignment in y-direction - TArrayD mShiftZ; ///< Array to hold the misalignment in z-direction - TArrayD mRotX; ///< Array to hold the rotation in x-direction - TArrayD mRotY; ///< Array to hold the rotation in y-direction - TArrayD mRotZ; ///< Array to hold the rotation in z-direction - Int_t mNumberOfDetectors; ///< Total number of detectors - - MisalignmentParameter(const MisalignmentParameter&); - - MisalignmentParameter& operator=(const MisalignmentParameter&); - - ClassDefOverride(MisalignmentParameter, 1); -}; -} // namespace its -} // namespace o2 - -#endif diff --git a/Detectors/ITSMFT/ITS/base/src/ContainerFactory.cxx b/Detectors/ITSMFT/ITS/base/src/ContainerFactory.cxx deleted file mode 100644 index 43e67ff9fabac..0000000000000 --- a/Detectors/ITSMFT/ITS/base/src/ContainerFactory.cxx +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 ContainerFactory.cxx -/// \brief Implementation of the ContainerFactory class - -#include "ITSBase/ContainerFactory.h" -#include "FairRuntimeDb.h" // for FairRuntimeDb -#include "TString.h" // for TString - -class FairParSet; - -using namespace o2::its; - -ClassImp(o2::its::ContainerFactory); - -static ContainerFactory gO2itsContFact; - -ContainerFactory::ContainerFactory() : FairContFact() -{ - fName = "ContainerFactory"; - fTitle = "Factory for parameter containers in libO2its"; - mSetAllContainers(); - FairRuntimeDb::instance()->addContFactory(this); -} - -void ContainerFactory::mSetAllContainers() -{ - // FairContainer* p= new FairContainer("O2itsGeoPar", - // "O2its Geometry Parameters", - // "TestDefaultContext"); - // p->addContext("TestNonDefaultContext"); - // - // containers->Add(p); -} - -FairParSet* ContainerFactory::createContainer(FairContainer* c) -{ - // const char* name=c->GetName(); - // FairParSet* p=NULL; - // if (strcmp(name,"O2itsGeoPar")==0) { - // p=new O2itsGeoPar(c->getConcatName().Data(), - // c->GetTitle(),c->getContext()); - //} - // return p; - return nullptr; -} diff --git a/Detectors/ITSMFT/ITS/base/src/DescriptorInnerBarrel.cxx b/Detectors/ITSMFT/ITS/base/src/DescriptorInnerBarrel.cxx index aa7d1abd54e5e..a71e31e9467a9 100644 --- a/Detectors/ITSMFT/ITS/base/src/DescriptorInnerBarrel.cxx +++ b/Detectors/ITSMFT/ITS/base/src/DescriptorInnerBarrel.cxx @@ -13,7 +13,6 @@ #include // for LOG, LOG_IF #include "FairRootManager.h" // for FairRootManager #include "FairRun.h" // for FairRun -#include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairVolume.h" // for FairVolume #include "FairRootManager.h" diff --git a/Detectors/ITSMFT/ITS/base/src/ITSBaseLinkDef.h b/Detectors/ITSMFT/ITS/base/src/ITSBaseLinkDef.h index a3355e80f9a67..3bb19dbda0f76 100644 --- a/Detectors/ITSMFT/ITS/base/src/ITSBaseLinkDef.h +++ b/Detectors/ITSMFT/ITS/base/src/ITSBaseLinkDef.h @@ -16,8 +16,6 @@ #pragma link off all functions; #pragma link C++ class o2::its::GeometryTGeo; -#pragma link C++ class o2::its::ContainerFactory; -#pragma link C++ class o2::its::MisalignmentParameter + ; #pragma link C++ class o2::its::DescriptorInnerBarrel + ; #pragma link C++ class o2::its::ITSBaseParam + ; #pragma link C++ class o2::conf::ConfigurableParamHelper < o2::its::ITSBaseParam> + ; diff --git a/Detectors/ITSMFT/ITS/base/src/MisalignmentParameter.cxx b/Detectors/ITSMFT/ITS/base/src/MisalignmentParameter.cxx deleted file mode 100644 index 98e8518e4ee61..0000000000000 --- a/Detectors/ITSMFT/ITS/base/src/MisalignmentParameter.cxx +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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 MisalignmentParameter.cxx -/// \brief Implementation of the MisalignmentParameter class - -#include "ITSBase/MisalignmentParameter.h" - -#include "FairParamList.h" - -using namespace o2::its; - -ClassImp(o2::its::MisalignmentParameter); - -MisalignmentParameter::MisalignmentParameter(const char* name, const char* title, const char* context) - : FairParGenericSet(name, title, context), - mShiftX(), - mShiftY(), - mShiftZ(), - mRotX(), - mRotY(), - mRotZ(), - mNumberOfDetectors(0) -{ -} - -MisalignmentParameter::~MisalignmentParameter() = default; -void MisalignmentParameter::Clear() {} -void MisalignmentParameter::putParams(FairParamList* list) -{ - if (!list) { - return; - } - - list->add("NumberOfDetectors", mNumberOfDetectors); - list->add("ShiftX", mShiftX); - list->add("ShiftY", mShiftY); - list->add("ShiftZ", mShiftZ); - list->add("RotationX", mRotX); - list->add("RotationY", mRotY); - list->add("RotationZ", mRotZ); -} - -Bool_t MisalignmentParameter::getParams(FairParamList* list) -{ - if (!list) { - return kFALSE; - } - - if (!list->fill("NumberOfDetectors", &mNumberOfDetectors)) { - return kFALSE; - } - - mShiftX.Set(mNumberOfDetectors); - if (!list->fill("ShiftX", &mShiftX)) { - return kFALSE; - } - - mShiftY.Set(mNumberOfDetectors); - if (!list->fill("ShiftY", &mShiftY)) { - return kFALSE; - } - - mShiftZ.Set(mNumberOfDetectors); - if (!list->fill("ShiftZ", &mShiftZ)) { - return kFALSE; - } - - mRotX.Set(mNumberOfDetectors); - if (!list->fill("RotationX", &mRotX)) { - return kFALSE; - } - - mRotY.Set(mNumberOfDetectors); - if (!list->fill("RotationY", &mRotY)) { - return kFALSE; - } - - mRotZ.Set(mNumberOfDetectors); - if (!list->fill("RotationZ", &mRotZ)) { - return kFALSE; - } - - return kTRUE; -} diff --git a/Detectors/ITSMFT/ITS/simulation/src/DescriptorInnerBarrelITS2.cxx b/Detectors/ITSMFT/ITS/simulation/src/DescriptorInnerBarrelITS2.cxx index 09c1d9f448340..fd5b7a755ed76 100644 --- a/Detectors/ITSMFT/ITS/simulation/src/DescriptorInnerBarrelITS2.cxx +++ b/Detectors/ITSMFT/ITS/simulation/src/DescriptorInnerBarrelITS2.cxx @@ -13,7 +13,6 @@ #include // for LOG, LOG_IF #include "FairRootManager.h" // for FairRootManager #include "FairRun.h" // for FairRun -#include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairVolume.h" // for FairVolume #include "FairRootManager.h" diff --git a/Detectors/ITSMFT/ITS/simulation/src/Detector.cxx b/Detectors/ITSMFT/ITS/simulation/src/Detector.cxx index 6f4f1fa5fe028..e2fcf9b5aa014 100644 --- a/Detectors/ITSMFT/ITS/simulation/src/Detector.cxx +++ b/Detectors/ITSMFT/ITS/simulation/src/Detector.cxx @@ -32,7 +32,6 @@ #include "FairDetector.h" // for FairDetector #include "FairRootManager.h" // for FairRootManager #include "FairRun.h" // for FairRun -#include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairVolume.h" // for FairVolume #include "FairRootManager.h" @@ -313,8 +312,6 @@ void Detector::InitializeO2Detector() } mGeometryTGeo = GeometryTGeo::Instance(); - // FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb(); - // O2itsGeoPar* par=(O2itsGeoPar*)(rtdb->getContainer("O2itsGeoPar")); } Bool_t Detector::ProcessHits(FairVolume* vol) diff --git a/Detectors/ITSMFT/test/HitAnalysis/CMakeLists.txt b/Detectors/ITSMFT/test/HitAnalysis/CMakeLists.txt index 4155023626774..a706537e8d61d 100644 --- a/Detectors/ITSMFT/test/HitAnalysis/CMakeLists.txt +++ b/Detectors/ITSMFT/test/HitAnalysis/CMakeLists.txt @@ -11,6 +11,6 @@ o2_add_library(HitAnalysis SOURCES src/HitAnalysis.cxx - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::ITSMFTSimulation + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::ITSMFTSimulation O2::ITSBase) o2_target_root_dictionary(HitAnalysis HEADERS include/HitAnalysis/HitAnalysis.h) diff --git a/Detectors/MUON/MID/Simulation/CMakeLists.txt b/Detectors/MUON/MID/Simulation/CMakeLists.txt index a2c36800a1046..6709488b89761 100644 --- a/Detectors/MUON/MID/Simulation/CMakeLists.txt +++ b/Detectors/MUON/MID/Simulation/CMakeLists.txt @@ -1,13 +1,13 @@ -# Copyright 2019-2020 CERN and copyright holders of ALICE O2. See -# https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +# Copyright 2019-2020 CERN and copyright holders of ALICE O2. +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. # All rights not expressly granted are reserved. # -# This software is distributed under the terms of the GNU General Public License -# v3 (GPL Version 3), copied verbatim in the file "COPYING". +# This software is distributed under the terms of the GNU General Public +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". # # 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. +# granted to it by virtue of its status as an Intergovernmental Organization +# or submit itself to any jurisdiction. o2_add_library( MIDSimulation @@ -47,6 +47,6 @@ if(BUILD_TESTING) o2_add_test_root_macro( macros/drawMIDGeometry.C - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::DetectorsPassive O2::MIDSimulation + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::DetectorsPassive O2::MIDSimulation LABELS "muon;mid") endif() diff --git a/Detectors/PHOS/simulation/src/Detector.cxx b/Detectors/PHOS/simulation/src/Detector.cxx index 4bb1269133273..5b537db1f2c0e 100644 --- a/Detectors/PHOS/simulation/src/Detector.cxx +++ b/Detectors/PHOS/simulation/src/Detector.cxx @@ -18,7 +18,6 @@ #include "TVirtualMC.h" #include "TGeoPhysicalNode.h" -#include "FairGeoNode.h" #include "FairRootManager.h" #include "FairVolume.h" diff --git a/Detectors/PHOS/testsimulation/CMakeLists.txt b/Detectors/PHOS/testsimulation/CMakeLists.txt index bfeca6123b55d..b9891c692c7f7 100644 --- a/Detectors/PHOS/testsimulation/CMakeLists.txt +++ b/Detectors/PHOS/testsimulation/CMakeLists.txt @@ -10,23 +10,23 @@ # or submit itself to any jurisdiction. o2_add_test_root_macro(PutPhosInTop.C - PUBLIC_LINK_LIBRARIES O2::DetectorsPassive FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::DetectorsPassive O2::FairRootBase O2::PHOSSimulation LABELS phos) o2_add_test_root_macro(drawPHOSgeometry.C - PUBLIC_LINK_LIBRARIES O2::DetectorsPassive FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::DetectorsPassive O2::FairRootBase O2::PHOSSimulation LABELS phos) o2_add_test_root_macro(plot_dig_phos.C - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::SimulationDataFormat O2::PHOSSimulation O2::PHOSBase LABELS phos) o2_add_test_root_macro(plot_hit_phos.C - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::SimulationDataFormat O2::PHOSSimulation LABELS phos) diff --git a/Detectors/Passive/CMakeLists.txt b/Detectors/Passive/CMakeLists.txt index a4b2ac5b97eae..b191191594135 100644 --- a/Detectors/Passive/CMakeLists.txt +++ b/Detectors/Passive/CMakeLists.txt @@ -17,7 +17,6 @@ o2_add_library(DetectorsPassive src/Pipe.cxx src/PipeRun4.cxx src/Magnet.cxx - src/PassiveContFact.cxx src/FrameStructure.cxx src/Shil.cxx src/Hall.cxx @@ -34,7 +33,6 @@ o2_target_root_dictionary(DetectorsPassive include/DetectorsPassive/Dipole.h include/DetectorsPassive/Compensator.h include/DetectorsPassive/Magnet.h - include/DetectorsPassive/PassiveContFact.h include/DetectorsPassive/Pipe.h include/DetectorsPassive/PipeRun4.h include/DetectorsPassive/FrameStructure.h @@ -48,6 +46,6 @@ o2_target_root_dictionary(DetectorsPassive # FIXME: if PutFrameInTop really depends on TRD, then the following can not work # as TRD is built afterwards. So we have a dependency problem here potentially. # o2_add_test_root_macro(FILENAME "macro/PutFrameInTop.C" PUBLIC_LINK_LIBRARIES -# DetectorsPassive FairRoot::Base TRDSimulation) +# DetectorsPassive O2::FairRootBase TRDSimulation) o2_data_file(COPY data DESTINATION Detectors/Passive/simulation) diff --git a/Detectors/Passive/include/DetectorsPassive/PassiveContFact.h b/Detectors/Passive/include/DetectorsPassive/PassiveContFact.h deleted file mode 100644 index a68f2b8090dfe..0000000000000 --- a/Detectors/Passive/include/DetectorsPassive/PassiveContFact.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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. - -/******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * - * * - * This software is distributed under the terms of the * - * GNU Lesser General Public Licence version 3 (LGPL) version 3, * - * copied verbatim in the file "LICENSE" * - ********************************************************************************/ - -// ------------------------------------------------------------------------- -// ----- AliPassiveContFact file ----- -// ----- Created 26/03/14 by M. Al-Turany ----- -// ------------------------------------------------------------------------- - -#ifndef ALICEO2_PASSIVE_CONTFACT_H -#define ALICEO2_PASSIVE_CONTFACT_H - -#include "FairContFact.h" // for FairContFact, etc -#include "Rtypes.h" // for AliPassiveContFact::Class, etc - -class FairParSet; - -namespace o2 -{ -namespace passive -{ - -class PassiveContFact : public FairContFact -{ - private: - void setAllContainers(); - - public: - PassiveContFact(); - ~PassiveContFact() override { ; } - FairParSet* createContainer(FairContainer*) override; - ClassDefOverride(o2::passive::PassiveContFact, 0); // Factory for all Passive parameter containers -}; -} // namespace passive -} // namespace o2 -#endif /* !PNDPASSIVECONTFACT_H */ diff --git a/Detectors/Passive/src/PassiveContFact.cxx b/Detectors/Passive/src/PassiveContFact.cxx deleted file mode 100644 index 1fce6d48536a0..0000000000000 --- a/Detectors/Passive/src/PassiveContFact.cxx +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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. - -/******************************************************************************** - * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * - * * - * This software is distributed under the terms of the * - * GNU Lesser General Public Licence version 3 (LGPL) version 3, * - * copied verbatim in the file "LICENSE" * - ********************************************************************************/ - -// ------------------------------------------------------------------------- -// ----- PassiveContFact file ----- -// ----- Created 26/03/14 by M. Al-Turany ----- -// ------------------------------------------------------------------------- - -//*-- AUTHOR : Denis Bertini -//*-- Created : 21/06/2005 - -///////////////////////////////////////////////////////////// -// -// PassiveContFact -// -// Factory for the parameter containers in libPassive -// -///////////////////////////////////////////////////////////// -#include "DetectorsPassive/PassiveContFact.h" -#include "FairRuntimeDb.h" // for FairRuntimeDb -#include "TList.h" // for TList -#include "TString.h" // for TString -#include // for strcmp, NULL - -using namespace std; -using namespace o2::passive; - -ClassImp(o2::passive::PassiveContFact); - -static PassiveContFact gPassiveContFact; - -PassiveContFact::PassiveContFact() - : FairContFact() -{ - // Constructor (called when the library is loaded) - fName = "PassiveContFact"; - fTitle = "Factory for parameter containers in libPassive"; - setAllContainers(); - FairRuntimeDb::instance()->addContFactory(this); -} - -void PassiveContFact::setAllContainers() -{ - /** Creates the Container objects with all accepted contexts and adds them to - * the list of containers for the STS library.*/ - - auto* p = new FairContainer("FairGeoPassivePar", - "Passive Geometry Parameters", - "TestDefaultContext"); - p->addContext("TestNonDefaultContext"); - - containers->Add(p); -} - -FairParSet* PassiveContFact::createContainer(FairContainer* c) -{ - /** Calls the constructor of the corresponding parameter container. - * For an actual context, which is not an empty string and not the default context - * of this container, the name is concatinated with the context. */ - /* const char* name=c->GetName(); - FairParSet* p=NULL; - if (strcmp(name,"FairGeoPassivePar")==0) { - p=new FairGeoPassivePar(c->getConcatName().Data(),c->GetTitle(),c->getContext()); - } - return p; -*/ - return nullptr; -} diff --git a/Detectors/Passive/src/PassiveLinkDef.h b/Detectors/Passive/src/PassiveLinkDef.h index b1d674519bf2e..cc73eb6918968 100644 --- a/Detectors/Passive/src/PassiveLinkDef.h +++ b/Detectors/Passive/src/PassiveLinkDef.h @@ -33,7 +33,6 @@ #pragma link C++ class o2::passive::Compensator + ; #pragma link C++ class o2::passive::Magnet + ; #pragma link C++ class o2::passive::Cave + ; -#pragma link C++ class o2::passive::PassiveContFact + ; #pragma link C++ class o2::passive::Pipe + ; #pragma link C++ class o2::passive::PipeRun4 + ; #pragma link C++ class o2::passive::FrameStructure + ; diff --git a/Detectors/Raw/CMakeLists.txt b/Detectors/Raw/CMakeLists.txt index 510506a6eb291..12e799d5e1ddc 100644 --- a/Detectors/Raw/CMakeLists.txt +++ b/Detectors/Raw/CMakeLists.txt @@ -19,7 +19,7 @@ o2_add_library(DetectorsRaw src/DistSTFSenderSpec.cxx src/RawDumpSpec.cxx PUBLIC_LINK_LIBRARIES AliceO2::Common - FairRoot::Base + O2::FairRootBase O2::Headers O2::CommonDataFormat O2::DetectorsCommonDataFormats diff --git a/Detectors/Raw/TFReaderDD/CMakeLists.txt b/Detectors/Raw/TFReaderDD/CMakeLists.txt index 7d113f5bbad92..a9a5d9a027401 100644 --- a/Detectors/Raw/TFReaderDD/CMakeLists.txt +++ b/Detectors/Raw/TFReaderDD/CMakeLists.txt @@ -13,7 +13,7 @@ o2_add_library(TFReaderDD SOURCES src/SubTimeFrameFile.cxx src/BinFileOp.cxx src/SubTimeFrameFileReader.cxx - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::Headers O2::Framework O2::DetectorsRaw diff --git a/Detectors/TOF/base/CMakeLists.txt b/Detectors/TOF/base/CMakeLists.txt index 0e63bea6bdd79..91e84fe2f9a52 100644 --- a/Detectors/TOF/base/CMakeLists.txt +++ b/Detectors/TOF/base/CMakeLists.txt @@ -19,7 +19,7 @@ o2_add_library(TOFBase src/EventTimeMaker.cxx src/Utils.cxx src/CalibTOFapi.cxx - PUBLIC_LINK_LIBRARIES Boost::serialization FairRoot::Base Microsoft.GSL::GSL + PUBLIC_LINK_LIBRARIES Boost::serialization O2::FairRootBase Microsoft.GSL::GSL O2::DetectorsBase O2::CommonDataFormat O2::DetectorsRaw O2::DataFormatsTOF) diff --git a/Detectors/TPC/base/CMakeLists.txt b/Detectors/TPC/base/CMakeLists.txt index 6456207e50530..af67040b960dc 100644 --- a/Detectors/TPC/base/CMakeLists.txt +++ b/Detectors/TPC/base/CMakeLists.txt @@ -12,7 +12,6 @@ o2_add_library(TPCBase SOURCES src/CalArray.cxx src/CalDet.cxx - src/ContainerFactory.cxx src/CRU.cxx src/DigitPos.cxx src/ModelGEM.cxx @@ -37,12 +36,11 @@ o2_add_library(TPCBase src/FEEConfig.cxx src/CommonModeCorrection.cxx PUBLIC_LINK_LIBRARIES Vc::Vc Boost::boost O2::DataFormatsTPC - O2::DetectorsRaw O2::CCDB FairRoot::Base) + O2::DetectorsRaw O2::CCDB O2::FairRootBase) o2_target_root_dictionary(TPCBase HEADERS include/TPCBase/CalArray.h include/TPCBase/CalDet.h - include/TPCBase/ContainerFactory.h include/TPCBase/CRU.h include/TPCBase/DigitPos.h include/TPCBase/ModelGEM.h diff --git a/Detectors/TPC/base/include/TPCBase/ContainerFactory.h b/Detectors/TPC/base/include/TPCBase/ContainerFactory.h deleted file mode 100644 index fc03683117af2..0000000000000 --- a/Detectors/TPC/base/include/TPCBase/ContainerFactory.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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. - -#ifndef ALICEO2_TPC_CONTAINERFACTORY_H_ -#define ALICEO2_TPC_CONTAINERFACTORY_H_ - -#include "FairContFact.h" // for FairContFact, FairContainer (ptr only) -#include "Rtypes.h" // for ContainerFactory::Class, ClassDef, etc -class FairParSet; - -class FairContainer; - -namespace o2 -{ -namespace tpc -{ - -class ContainerFactory : public FairContFact -{ - private: - void setAllContainers(); - - public: - ContainerFactory(); - ~ContainerFactory() override = default; - FairParSet* createContainer(FairContainer*) override; - ClassDefOverride(o2::tpc::ContainerFactory, 0); // Factory for all tpc parameter containers -}; -} // namespace tpc -} // namespace o2 -#endif diff --git a/Detectors/TPC/base/src/ContainerFactory.cxx b/Detectors/TPC/base/src/ContainerFactory.cxx deleted file mode 100644 index 47555bd72be51..0000000000000 --- a/Detectors/TPC/base/src/ContainerFactory.cxx +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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. - -#include "TPCBase/ContainerFactory.h" -#include "FairRuntimeDb.h" // for FairRuntimeDb - -class FairParSet; -using namespace o2::tpc; - -ClassImp(ContainerFactory); - -static ContainerFactory gTpcContainerFactory; - -ContainerFactory::ContainerFactory() - : FairContFact() -{ - /** Constructor (called when the library is loaded) */ - fName = "ContainerFactory"; - fTitle = "Factory for parameter containers in libO2tpc"; - setAllContainers(); - FairRuntimeDb::instance()->addContFactory(this); -} - -void ContainerFactory::setAllContainers() -{ - /** Creates the Container objects with all accepted - contexts and adds them to - the list of containers for the O2tpc library. - */ - - /* FairContainer* p= new FairContainer("O2tpcGeoPar", - "O2tpc Geometry Parameters", - "TestDefaultContext"); - p->addContext("TestNonDefaultContext"); - - containers->Add(p); -*/ -} - -FairParSet* ContainerFactory::createContainer(FairContainer* c) -{ - /** Calls the constructor of the corresponding parameter container. - For an actual context, which is not an empty string and not - the default context - of this container, the name is concatinated with the context. - */ - /* - const char* name=c->GetName(); - FairParSet* p=NULL; - if (strcmp(name,"O2tpcGeoPar")==0) { - p=new O2tpcGeoPar(c->getConcatName().Data(), - c->GetTitle(),c->getContext()); - } - return p; - */ - return nullptr; -} diff --git a/Detectors/TPC/base/src/TPCBaseLinkDef.h b/Detectors/TPC/base/src/TPCBaseLinkDef.h index 3d91f62dd979b..528f10928852e 100644 --- a/Detectors/TPC/base/src/TPCBaseLinkDef.h +++ b/Detectors/TPC/base/src/TPCBaseLinkDef.h @@ -30,7 +30,6 @@ #pragma link C++ class std::vector < o2::tpc::CalDet < float>> + ; #pragma link C++ class std::vector < o2::tpc::CalDet < float>*> + ; #pragma link C++ class std::unordered_map < std::string, o2::tpc::CalDet < float>> + ; -#pragma link C++ class o2::tpc::ContainerFactory; #pragma link C++ class o2::tpc::CRU; #pragma link C++ class o2::tpc::DigitPos; #pragma link C++ class o2::tpc::ModelGEM; diff --git a/Detectors/TPC/reconstruction/CMakeLists.txt b/Detectors/TPC/reconstruction/CMakeLists.txt index 085e14708c13b..b3743fbfdf9d6 100644 --- a/Detectors/TPC/reconstruction/CMakeLists.txt +++ b/Detectors/TPC/reconstruction/CMakeLists.txt @@ -31,7 +31,7 @@ o2_add_library(TPCReconstruction src/CTFCoder.cxx src/RawProcessingHelpers.cxx src/IonTailCorrection.cxx - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::SimulationDataFormat O2::TPCBase O2::GPUO2Interface diff --git a/Detectors/TPC/simulation/CMakeLists.txt b/Detectors/TPC/simulation/CMakeLists.txt index bff9045a1456f..7b89784e6799f 100644 --- a/Detectors/TPC/simulation/CMakeLists.txt +++ b/Detectors/TPC/simulation/CMakeLists.txt @@ -53,7 +53,7 @@ if(BUILD_TESTING) LABELS tpc) o2_add_test_root_macro(macro/laserTrackGenerator.C - PUBLIC_LINK_LIBRARIES FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::DataFormatsTPC LABELS tpc) diff --git a/Detectors/TPC/simulation/src/Detector.cxx b/Detectors/TPC/simulation/src/Detector.cxx index 28e8eff25cfc0..544f093ee8199 100644 --- a/Detectors/TPC/simulation/src/Detector.cxx +++ b/Detectors/TPC/simulation/src/Detector.cxx @@ -26,12 +26,7 @@ #include // for NULL -#include "FairGeoVolume.h" -#include "FairGeoNode.h" -#include "FairGeoLoader.h" -#include "FairGeoInterface.h" #include "FairRun.h" -#include "FairRuntimeDb.h" #include #include "FairRootManager.h" diff --git a/Detectors/Upgrades/ALICE3/FCT/simulation/src/Detector.cxx b/Detectors/Upgrades/ALICE3/FCT/simulation/src/Detector.cxx index 458df289d0bb2..410bd00607980 100644 --- a/Detectors/Upgrades/ALICE3/FCT/simulation/src/Detector.cxx +++ b/Detectors/Upgrades/ALICE3/FCT/simulation/src/Detector.cxx @@ -27,7 +27,6 @@ #include "FairModule.h" // for FairModule #include "FairRootManager.h" // for FairRootManager #include "FairRun.h" // for FairRun -#include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairVolume.h" // for FairVolume #include "FairRootManager.h" diff --git a/Detectors/Upgrades/ALICE3/FD3/simulation/src/Detector.cxx b/Detectors/Upgrades/ALICE3/FD3/simulation/src/Detector.cxx index bd79b1deaad80..f5966ca424531 100644 --- a/Detectors/Upgrades/ALICE3/FD3/simulation/src/Detector.cxx +++ b/Detectors/Upgrades/ALICE3/FD3/simulation/src/Detector.cxx @@ -27,7 +27,6 @@ #include #include "FairRootManager.h" #include "FairRun.h" -#include "FairRuntimeDb.h" #include "FairVolume.h" #include "FairRootManager.h" diff --git a/Detectors/Upgrades/ALICE3/TRKFT3/FT3/simulation/src/Detector.cxx b/Detectors/Upgrades/ALICE3/TRKFT3/FT3/simulation/src/Detector.cxx index 6b07ae3ecd842..8407482dbd4ec 100644 --- a/Detectors/Upgrades/ALICE3/TRKFT3/FT3/simulation/src/Detector.cxx +++ b/Detectors/Upgrades/ALICE3/TRKFT3/FT3/simulation/src/Detector.cxx @@ -27,7 +27,6 @@ #include "FairRootManager.h" // for FairRootManager #include "FairRootManager.h" #include "FairRun.h" // for FairRun -#include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairVolume.h" // for FairVolume #include "TGeoManager.h" // for TGeoManager, gGeoManager diff --git a/Detectors/ZDC/base/CMakeLists.txt b/Detectors/ZDC/base/CMakeLists.txt index b55ec73aa1b73..b0daed8064533 100644 --- a/Detectors/ZDC/base/CMakeLists.txt +++ b/Detectors/ZDC/base/CMakeLists.txt @@ -11,7 +11,7 @@ o2_add_library(ZDCBase SOURCES src/Geometry.cxx src/ModuleConfig.cxx src/FragmentParam.cxx src/Helpers.cxx - PUBLIC_LINK_LIBRARIES O2::CommonConstants ROOT::MathCore FairRoot::Base O2::FrameworkLogger) + PUBLIC_LINK_LIBRARIES O2::CommonConstants ROOT::MathCore O2::FairRootBase O2::FrameworkLogger) o2_target_root_dictionary(ZDCBase HEADERS include/ZDCBase/Geometry.h include/ZDCBase/Constants.h include/ZDCBase/ModuleConfig.h include/ZDCBase/FragmentParam.h) diff --git a/Detectors/gconfig/CMakeLists.txt b/Detectors/gconfig/CMakeLists.txt index a4d207d2e3543..d35bbed3deb36 100644 --- a/Detectors/gconfig/CMakeLists.txt +++ b/Detectors/gconfig/CMakeLists.txt @@ -11,7 +11,7 @@ o2_add_library(G3Setup SOURCES src/G3Config.cxx - PUBLIC_LINK_LIBRARIES MC::Geant3 FairRoot::Base O2::SimulationDataFormat O2::Generators O2::SimSetup + PUBLIC_LINK_LIBRARIES MC::Geant3 O2::FairRootBase O2::SimulationDataFormat O2::Generators O2::SimSetup ) # Optional VecGeom navigation for Geant4 (G4.navmode=kVecGeom). It needs TGeo2VecGeom and a VecGeom @@ -38,7 +38,7 @@ endif() o2_add_library(G4Setup TARGETVARNAME targetG4Setup SOURCES ${G4SETUP_SOURCES} - PUBLIC_LINK_LIBRARIES MC::Geant4VMC MC::Geant4 FairRoot::Base O2::SimulationDataFormat O2::Generators O2::SimSetup O2::FastSim O2::DetectorsBase + PUBLIC_LINK_LIBRARIES MC::Geant4VMC MC::Geant4 O2::FairRootBase O2::SimulationDataFormat O2::Generators O2::SimSetup O2::FastSim O2::DetectorsBase ) if(G4SETUP_WITH_VECGEOM) @@ -50,17 +50,17 @@ endif() o2_add_library(FLUKASetup SOURCES src/FlukaConfig.cxx - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::SimulationDataFormat O2::Generators O2::SimSetup + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::SimulationDataFormat O2::Generators O2::SimSetup ) o2_add_library(MCReplaySetup SOURCES src/MCReplayConfig.cxx - PUBLIC_LINK_LIBRARIES MC::MCReplay FairRoot::Base O2::SimulationDataFormat O2::Generators O2::SimSetup + PUBLIC_LINK_LIBRARIES MC::MCReplay O2::FairRootBase O2::SimulationDataFormat O2::Generators O2::SimSetup ) o2_add_library(O2TrivialMCEngineSetup SOURCES src/O2TrivialMCConfig.cxx - PUBLIC_LINK_LIBRARIES O2::O2TrivialMC FairRoot::Base O2::SimulationDataFormat O2::Generators O2::SimSetup + PUBLIC_LINK_LIBRARIES O2::O2TrivialMC O2::FairRootBase O2::SimulationDataFormat O2::Generators O2::SimSetup ) o2_add_library(SimSetup diff --git a/Generators/CMakeLists.txt b/Generators/CMakeLists.txt index cf8afe3235712..aee822933d657 100644 --- a/Generators/CMakeLists.txt +++ b/Generators/CMakeLists.txt @@ -54,9 +54,8 @@ o2_add_library(Generators $<$:src/AODToHepMC.cxx> $<$,$>:src/GeneratorHybrid.cxx> $<$,$>:src/GeneratorHybridParam.cxx> - PUBLIC_LINK_LIBRARIES FairRoot::Base O2::SimConfig O2::CommonUtils O2::DetectorsBase O2::ZDCBase O2::DetectorsRaw + PUBLIC_LINK_LIBRARIES O2::FairRootBase O2::SimConfig O2::CommonUtils O2::DetectorsBase O2::ZDCBase O2::DetectorsRaw O2::SimulationDataFormat ${pythiaTarget} ${hepmcTarget} - FairRoot::Gen onnxruntime::onnxruntime TARGETVARNAME targetName) @@ -122,7 +121,7 @@ endif() o2_target_root_dictionary(Generators HEADERS ${headers}) o2_add_test_root_macro(share/external/extgen.C - PUBLIC_LINK_LIBRARIES O2::Generators FairRoot::Base + PUBLIC_LINK_LIBRARIES O2::Generators O2::FairRootBase LABELS generators COMPILE_ONLY) if(doBuildSimulation) diff --git a/Steer/include/Steer/O2RunSim.h b/Steer/include/Steer/O2RunSim.h index a3b970377314c..f8593a462401d 100644 --- a/Steer/include/Steer/O2RunSim.h +++ b/Steer/include/Steer/O2RunSim.h @@ -17,27 +17,18 @@ #include "FairRunSim.h" // for FairRunSim #include "Rtypes.h" // for Bool_t, Double_t, UInt_t, etc +#include #include -#include "FairBaseParSet.h" // for FairBaseParSet -#include "FairGeoParSet.h" // for FairGeoParSet #include "FairField.h" // for FairField #include "FairFileHeader.h" // for FairFileHeader -#include "FairGeoInterface.h" // for FairGeoInterface -#include "FairGeoLoader.h" // for FairGeoLoader #include // for FairLogger, MESSAGE_ORIGIN #include "FairMCEventHeader.h" // for FairMCEventHeader -#include "FairMesh.h" // for FairMesh #include "FairModule.h" // for FairModule -#include "FairParSet.h" // for FairParSet #include "FairPrimaryGenerator.h" // for FairPrimaryGenerator #include "FairRootManager.h" // for FairRootManager #include "FairRunIdGenerator.h" // for FairRunIdGenerator -#include "FairRuntimeDb.h" // for FairRuntimeDb #include "FairTask.h" // for FairTask -#include "FairTrajFilter.h" // for FairTrajFilter -#include "TRandom.h" -#include #include #include @@ -59,12 +50,8 @@ class O2RunSim : public FairRunSim fRootManager->InitSink(); - // original FairRunSim follows - FairGeoLoader* loader = new FairGeoLoader(fLoaderName->Data(), "Geo Loader"); - FairGeoInterface* GeoInterFace = loader->getGeoInterface(); - GeoInterFace->SetNoOfSets(ListOfModules->GetEntries()); - GeoInterFace->setMediaFile(MatFname.Data()); - GeoInterFace->readMedia(); + // the geometry manager that FairGeoLoader used to create here (its ASCII media part is not used by ALICE) + new TGeoManager("FAIRGeom", "FAIR geometry"); if (mDeviceMode) { fApp = new O2MCApplication("Fair", "The Fair VMC App", ListOfModules, MatFname); @@ -78,26 +65,10 @@ class O2RunSim : public FairRunSim fApp->SetGenerator(fGen); - // Add a Generated run ID to the FairRunTimeDb FairRunIdGenerator genid; - // FairRuntimeDb *rtdb= GetRuntimeDb(); fRunId = genid.generateId(); - fRtdb->addRun(fRunId); fFileHeader->SetRunId(fRunId); - /** This call will create the container if it does not exist*/ - FairBaseParSet* par = dynamic_cast(fRtdb->getContainer("FairBaseParSet")); - if (par) { - par->SetDetList(GetListOfModules()); - par->SetGen(GetPrimaryGenerator()); - par->SetBeamMom(fBeamMom); - } - - /** This call will create the container if it does not exist*/ - FairGeoParSet* geopar = dynamic_cast(fRtdb->getContainer("FairGeoParSet")); - if (geopar) { - geopar->SetGeometry(gGeoManager); - } // Set global Parameter Info if (fPythiaDecayer) { @@ -117,25 +88,6 @@ class O2RunSim : public FairRunSim fField->Init(); } fApp->SetField(fField); - SetFieldContainer(); - - TList* containerList = fRtdb->getListOfContainers(); - TIter next(containerList); - FairParSet* cont; - TObjArray* ContList = new TObjArray(); - while ((cont = dynamic_cast(next()))) { - ContList->Add(new TObjString(cont->GetName())); - } - if (par) { - par->SetContListStr(ContList); - par->SetRndSeed(gRandom->GetSeed()); - par->setChanged(); - par->setInputVersion(fRunId, 1); - } - if (geopar) { - geopar->setChanged(); - geopar->setInputVersion(fRunId, 1); - } fSimSetup(); fApp->InitMC("foo", "bar"); diff --git a/dependencies/FindFairRoot.cmake b/dependencies/FindFairRoot.cmake deleted file mode 100644 index b48d2cad67c4b..0000000000000 --- a/dependencies/FindFairRoot.cmake +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2019-2020 CERN and copyright holders of ALICE O2. -# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -# All rights not expressly granted are reserved. -# -# This software is distributed under the terms of the GNU General Public -# License v3 (GPL Version 3), copied verbatim in the file "COPYING". -# -# 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. - -# TODO: remove this file once FairRoot correctly exports its cmake config - -find_path(FairRoot_INC FairDetector.h - PATH_SUFFIXES FairRoot/include - PATHS ${FAIRROOTPATH}/include - ${FAIRROOT_ROOT}/include - $ENV{FAIRROOT_ROOT}/include) - -get_filename_component(FairRoot_TOPDIR "${FairRoot_INC}/.." ABSOLUTE) - -set(OLD_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}) -set(CMAKE_PREFIX_PATH ${FairRoot_TOPDIR}) - -find_library(FairRoot_Tools FairTools) -find_library(FairRoot_ParBase ParBase) -find_library(FairRoot_GeoBase GeoBase) -find_library(FairRoot_Base Base) -find_library(FairRoot_Gen Gen) - -set(CMAKE_PREFIX_PATH ${OLD_CMAKE_PREFIX_PATH}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(FairRoot - DEFAULT_MSG FairRoot_Base - FairRoot_Tools - FairRoot_ParBase - FairRoot_GeoBase - FairRoot_Gen - FairRoot_INC) - -if(NOT TARGET FairRoot::Tools) - add_library(FairRoot::Tools IMPORTED INTERFACE) - set_target_properties(FairRoot::Tools - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${FairRoot_INC} - INTERFACE_LINK_LIBRARIES ${FairRoot_Tools}) - target_link_libraries(FairRoot::Tools INTERFACE FairLogger::FairLogger) -endif() - -if(NOT TARGET FairRoot::ParBase) - add_library(FairRoot::ParBase IMPORTED INTERFACE) - set_target_properties(FairRoot::ParBase - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${FairRoot_INC} - INTERFACE_LINK_LIBRARIES ${FairRoot_ParBase}) - target_link_libraries(FairRoot::ParBase INTERFACE FairRoot::Tools) -endif() - -if(NOT TARGET FairRoot::GeoBase) - add_library(FairRoot::GeoBase IMPORTED INTERFACE) - set_target_properties(FairRoot::GeoBase - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${FairRoot_INC} - INTERFACE_LINK_LIBRARIES ${FairRoot_GeoBase}) -endif() - -if(NOT TARGET FairRoot::Base) - add_library(FairRoot::Base IMPORTED INTERFACE) - get_filename_component(libdir ${FairRoot_Base} DIRECTORY) - set_target_properties(FairRoot::Base - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${FairRoot_INC} - INTERFACE_LINK_LIBRARIES ${FairRoot_Base} - INTERFACE_LINK_DIRECTORIES ${libdir}) - target_link_libraries(FairRoot::Base - INTERFACE FairRoot::Tools FairRoot::ParBase FairRoot::GeoBase MC::VMC) -endif() - -if(NOT TARGET FairRoot::Gen) - add_library(FairRoot::Gen IMPORTED INTERFACE) - set_target_properties(FairRoot::Gen - PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${FairRoot_INC} - INTERFACE_LINK_LIBRARIES ${FairRoot_Gen}) - target_link_libraries(FairRoot::Gen - INTERFACE FairRoot::ParBase FairRoot::Base - FairRoot::ParBase) -endif() diff --git a/dependencies/O2Dependencies.cmake b/dependencies/O2Dependencies.cmake index 8a0283ccb645f..a75f10d035f34 100644 --- a/dependencies/O2Dependencies.cmake +++ b/dependencies/O2Dependencies.cmake @@ -17,8 +17,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_MODULE_PATH}) # Required packages # -# Order is not completely irrelevant. For instance arrow must come before -# FairRoot (see FindFairRoot.cmake) +# Order is not completely irrelevant. # # Generally speaking we should prefer the CONFIG variant of the find_package. We # explicitely don't use the CONFIG variant (i.e. we do use the MODULE variant) @@ -168,9 +167,6 @@ set_package_properties(Boost PROPERTIES TYPE REQUIRED) find_package(FairLogger CONFIG) set_package_properties(FairLogger PROPERTIES TYPE REQUIRED) -find_package(FairRoot MODULE) -set_package_properties(FairRoot PROPERTIES TYPE REQUIRED) - find_package(Microsoft.GSL CONFIG) set_package_properties(Microsoft.GSL PROPERTIES diff --git a/doc/CMakeMigration.md b/doc/CMakeMigration.md index 14b4ed93ca85e..bbff7e582b7f3 100644 --- a/doc/CMakeMigration.md +++ b/doc/CMakeMigration.md @@ -83,7 +83,6 @@ Third-party dependencies are found in [dependencies/CMakeLists.txt](../dependenc `find_package` calls are of the `CONFIG` variety unless there's a compelling reason to use the `MODULE` version. In particular : -- [FindFairRoot](../dependencies/FindFairRoot.cmake) is creating imported targets so we can use `FairRoot::XXX` targets even if those are not (yet) created by FairRoot itself. That file will disappear when FairRoot completes its own CMake migration. - [FindGeant3](../dependencies/FindGeant3.cmake), [FindGeant4](../dependencies/FindGeant4.cmake), [Geant4VMC](../dependencies/FindGeant4VMC.cmake) : while those MC projects have Config.cmake files and thus define targets, they do not include the proper include paths for those targets. So those Find modules are just light ones that add the missing include paths to the imported targets defined in those projects. - [Findpythia](../dependencies/Findpythia.cmake) (for Pythia8) and [Findpythia6](../dependencies/Findpythia6.cmake) define imported targets for those libraries - [Findms_gsl](../dependencies/Findms_gsl.cmake) defines a `ms_gsl` target corresponding to the header only library diff --git a/macro/CMakeLists.txt b/macro/CMakeLists.txt index 91a15af31c3b0..c3319b9e6d7f6 100644 --- a/macro/CMakeLists.txt +++ b/macro/CMakeLists.txt @@ -35,8 +35,6 @@ install(FILES CheckDigits_mft.C runTPCRefit.C run_CRUDataSkimming_its.C run_calib_tof.C - run_clus_tof.C - run_clus_tpc.C run_clus_emcal.C run_collect_calib_tof.C run_digi2raw_its.C @@ -244,17 +242,6 @@ o2_add_test_root_macro(run_calib_tof.C O2::DetectorsBase O2::GlobalTracking) -# FIXME: move to subsystem dir -o2_add_test_root_macro(run_clus_tof.C - PUBLIC_LINK_LIBRARIES O2::TOFReconstruction O2::Framework O2::TOFBase - O2::SimulationDataFormat O2::TOFCalibration O2::DataFormatsTOF - LABELS tof) - -# FIXME: move to subsystem dir -o2_add_test_root_macro(run_clus_tpc.C - PUBLIC_LINK_LIBRARIES O2::TPCReconstruction - LABELS tpc) - # FIXME: move to subsystem dir o2_add_test_root_macro(run_clus_emcal.C PUBLIC_LINK_LIBRARIES O2::EMCALReconstruction diff --git a/macro/o2sim.C b/macro/o2sim.C index 3e2891a32f437..007955666d822 100644 --- a/macro/o2sim.C +++ b/macro/o2sim.C @@ -27,7 +27,6 @@ #include "DataFormatsParameters/GRPECSObject.h" #include "DataFormatsParameters/GRPMagField.h" #include "DataFormatsParameters/GRPLHCIFData.h" -#include "FairParRootFileIo.h" #include "FairSystemInfo.h" #include #include @@ -114,6 +113,15 @@ FairRunSim* o2sim_init(bool asservice, bool evalmat = false) run->SetSimSetup([confref]() { o2::SimSetup::setup(confref.getMCEngine().c_str()); }); run->SetRunId(timestamp); + // NOTE: in device ("as a service") mode the transport workers persist nothing + // through this sink - hits go to the hit merger, which writes the real files + // via NameConf - so the file it produces is an empty, PID-named + // o2sim_.root holding only FairRoot bookkeeping. It cannot simply be + // left unset, though: FairRootManager::RegisterImpl() calls LOG(fatal) with + // "The sink does not exist to store persistent branches" for any Register() + // with toFile=true, which every detector does. Dropping it needs a no-op sink + // implementation (FairSink::kONLINESINK has no class behind it here), not just + // skipping SetSink(). auto pid = getpid(); std::stringstream s; s << confref.getOutPrefix(); diff --git a/macro/run_clus_tof.C b/macro/run_clus_tof.C deleted file mode 100644 index 674e987556ae7..0000000000000 --- a/macro/run_clus_tof.C +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2019-2020 CERN and copyright holders of ALICE O2. -// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. -// All rights not expressly granted are reserved. -// -// This software is distributed under the terms of the GNU General Public -// License v3 (GPL Version 3), copied verbatim in the file "COPYING". -// -// 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. - -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include - -#include - -#include -#include "FairRunAna.h" -#include "FairFileSource.h" -#include "FairRuntimeDb.h" -#include "FairParRootFileIo.h" -#include "FairSystemInfo.h" -#include "TFile.h" -#include "TTree.h" -#include "TBranch.h" - -#include "TOFBase/Digit.h" -#include "SimulationDataFormat/MCCompLabel.h" -#include "SimulationDataFormat/MCTruthContainer.h" -#include "TOFReconstruction/ClustererTask.h" -#include "DataFormatsTOF/CalibLHCphaseTOF.h" -#include "DataFormatsTOF/CalibTimeSlewingParamTOF.h" -#include "TOFBase/CalibTOFapi.h" -#include "TOFReconstruction/Clusterer.h" -#include "TOFReconstruction/DataReader.h" -#endif - -void run_clus_tof(std::string outputfile = "tofclusters.root", std::string inputfile = "tofdigits.root", bool isMC = true) -{ - // Initialize logger - FairLogger* logger = FairLogger::GetLogger(); - // logger->SetLogVerbosityLevel("LOW"); - // logger->SetLogScreenLevel("DEBUG"); - - // Setup timer - TStopwatch timer; - timer.Start(); - - std::vector mDigits, *mPdigits = &mDigits; - std::vector mRow, *mProw = &mRow; - std::vector> mLabels, *mPlabels = &mLabels; - o2::tof::DigitDataReader reader; ///< Digit reader - - // Load digits - TFile* file = new TFile(inputfile.c_str(), "OLD"); - std::unique_ptr treeDig((TTree*)file->Get("o2sim")); - if (treeDig) { - treeDig->SetBranchAddress("TOFDigit", &mPdigits); - treeDig->SetBranchAddress("TOFReadoutWindow", &mProw); - - if (isMC) { - treeDig->SetBranchAddress("TOFDigitMCTruth", &mPlabels); - } - - treeDig->GetEntry(0); - } - - o2::dataformats::CalibLHCphaseTOF lhcPhaseObj; - o2::dataformats::CalibTimeSlewingParamTOF channelCalibObj; - // calibration objects set to zero - lhcPhaseObj.addLHCphase(0, 0); - lhcPhaseObj.addLHCphase(2000000000, 0); - - for (int ich = 0; ich < o2::dataformats::CalibTimeSlewingParamTOF::NCHANNELS; ich++) { - channelCalibObj.addTimeSlewingInfo(ich, 0, 0); - int sector = ich / o2::dataformats::CalibTimeSlewingParamTOF::NCHANNELXSECTOR; - int channelInSector = ich % o2::dataformats::CalibTimeSlewingParamTOF::NCHANNELXSECTOR; - channelCalibObj.setFractionUnderPeak(sector, channelInSector, 1); - } - o2::tof::CalibTOFapi calibapi(long(0), &lhcPhaseObj, &channelCalibObj); - - o2::tof::Clusterer clusterer; - std::vector clustersArray, *pClustersArray = &clustersArray; - o2::dataformats::MCTruthContainer clsLabels, *pClsLabels = &clsLabels; - clusterer.setCalibApi(&calibapi); - if (isMC) - clusterer.setMCTruthContainer(pClsLabels); - - for (int i = 0; i < mRow.size(); i++) { - printf("# TOF readout window for clusterization = %d/%d (N digits = %d)\n", i, int(mRow.size()), int(mRow.at(i).size())); - auto digitsRO = mRow.at(i).getBunchChannelData(mDigits); - - reader.setDigitArray(&digitsRO); - - if (isMC) { - clusterer.process(reader, clustersArray, &(mPlabels->at(i))); - } else - clusterer.process(reader, clustersArray, nullptr); - } - - LOG(info) << "TOF CLUSTERER : TRANSFORMED " << mDigits.size() - << " DIGITS TO " << clustersArray.size() << " CLUSTERS"; - - TFile* fout = new TFile(outputfile.c_str(), "RECREATE"); - TTree* tout = new TTree("o2sim", "o2sim"); - tout->Branch("TOFCluster", &pClustersArray); - if (isMC) - tout->Branch("TOFClusterMCTruth", &pClsLabels); - tout->Fill(); - tout->Write(); - fout->Close(); - timer.Stop(); - timer.Print(); -} diff --git a/macro/run_clus_tpc.C b/macro/run_clus_tpc.C deleted file mode 100644 index 950eb45f68851..0000000000000 --- a/macro/run_clus_tpc.C +++ /dev/null @@ -1,103 +0,0 @@ -#if !defined(__CLING__) || defined(__ROOTCLING__) -#include - -#include "Rtypes.h" -#include "TString.h" -#include "TStopwatch.h" -#include "TGeoManager.h" - -#include -#include "FairRunAna.h" -#include "FairFileSource.h" -#include "FairSystemInfo.h" -#include "FairRuntimeDb.h" -#include "FairParRootFileIo.h" -#include - -#endif -#include "TPCReconstruction/ClustererTask.h" - -void run_clus_tpc(std::string outputfile = "o2clus_tpc.root", std::string inputfile = "o2dig.root", - std::string paramfile = "o2sim_par.root", bool isContinuous = true, unsigned threads = 0); - -void run_clus_tpc(Int_t nEvents, TString mcEngine = "TGeant3", bool isContinuous = true, unsigned threads = 0) -{ - // Input and output file name - std::stringstream inputfile, outputfile, paramfile; - inputfile << "AliceO2_" << mcEngine << ".tpc.digi_" << nEvents << "_event.root"; - paramfile << "AliceO2_" << mcEngine << ".tpc.params_" << nEvents << ".root"; - outputfile << "AliceO2_" << mcEngine << ".tpc.clusters_" << nEvents << "_event.root"; - run_clus_tpc(outputfile.str(), inputfile.str(), paramfile.str(), isContinuous, threads); -} - -void run_clus_tpc(std::string outputfile, std::string inputfile, std::string paramfile, bool isContinuous, - unsigned threads) -{ - // Initialize logger - FairLogger* logger = FairLogger::GetLogger(); - logger->SetLogVerbosityLevel("HIGH"); - logger->SetLogScreenLevel("DEBUG"); - - // Setup timer - TStopwatch timer; - - // Setup FairRoot analysis manager - FairRunAna* run = new FairRunAna(); - FairFileSource* fFileSource = new FairFileSource(inputfile.data()); - run->SetSource(fFileSource); - run->SetSink(new FairRootFileSink(outputfile.c_str())); - - // Setup Runtime DB - FairRuntimeDb* rtdb = run->GetRuntimeDb(); - FairParRootFileIo* parInput1 = new FairParRootFileIo(); - parInput1->open(paramfile.data()); - rtdb->setFirstInput(parInput1); - - TGeoManager::Import("geofile_full.root"); - - // Setup clusterer - o2::tpc::ClustererTask* clustTPC = new o2::tpc::ClustererTask(0); - clustTPC->setContinuousReadout(isContinuous); - - run->AddTask(clustTPC); - - // Initialize everything - run->Init(); - - // Start simulation - timer.Start(); - run->Run(); - - run->TerminateRun(); - // we are done, cleanup - delete clustTPC; - - std::cout << std::endl - << std::endl; - - // Extract the maximal used memory an add is as Dart measurement - // This line is filtered by CTest and the value send to CDash - FairSystemInfo sysInfo; - Float_t maxMemory = sysInfo.GetMaxMemory(); - std::cout << R"()"; - std::cout << maxMemory; - std::cout << "" << std::endl; - - timer.Stop(); - Double_t rtime = timer.RealTime(); - Double_t ctime = timer.CpuTime(); - - Float_t cpuUsage = ctime / rtime; - std::cout << R"()"; - std::cout << cpuUsage; - std::cout << "" << std::endl; - - std::cout << std::endl - << std::endl; - std::cout << "Output file is " << outputfile.data() << std::endl; - // std::cout << "Parameter file is " << parFile << std::endl; - std::cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << std::endl - << std::endl; - std::cout << "Macro finished succesfully." << std::endl; - return; -}