Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Common/SimConfig/include/SimConfig/SimConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace o2
namespace conf
{

enum SimFieldMode {
kDefault = 0,
kUniform = 1,
kCCDB = 2
};

// configuration struct (which can be passed around)
struct SimConfigData {
std::vector<std::string> mActiveModules; // list of active modules
Expand Down Expand Up @@ -50,7 +56,7 @@ struct SimConfigData {
std::string mCCDBUrl; // the URL where to find CCDB
uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
int mField; // L3 field setting in kGauss: +-2,+-5 and 0
bool mUniformField = false; // uniform magnetic field
SimFieldMode mFieldMode = kDefault; // uniform magnetic field
bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
bool mNoGeant = false; // if Geant transport should be turned off (when one is only interested in the generated events)

Expand Down
24 changes: 20 additions & 4 deletions Common/SimConfig/src/SimConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <thread>
#include <cmath>
#include <chrono>
#include <regex>

using namespace o2::conf;
namespace bpo = boost::program_options;
Expand Down Expand Up @@ -48,10 +49,10 @@ void SimConfig::initOptions(boost::program_options::options_description& options
"chunkSize", bpo::value<unsigned int>()->default_value(500), "max size of primary chunk (subevent) distributed by server")(
"chunkSizeI", bpo::value<int>()->default_value(-1), "internalChunkSize")(
"seed", bpo::value<int>()->default_value(-1), "initial seed (default: -1 random)")(
"field", bpo::value<std::string>()->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-<intKGaus>U for uniform field ")(
"field", bpo::value<std::string>()->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-<intKGaus>U for uniform field; \"ccdb\" for taking it from CCDB ")(
"nworkers,j", bpo::value<int>()->default_value(nsimworkersdefault), "number of parallel simulation workers (only for parallel mode)")(
"noemptyevents", "only writes events with at least one hit")(
"CCDBUrl", bpo::value<std::string>()->default_value("ccdb-test.cern.ch:8080"), "URL for CCDB to be used.")(
"CCDBUrl", bpo::value<std::string>()->default_value("http://alice-ccdb.cern.ch"), "URL for CCDB to be used.")(
"timestamp", bpo::value<uint64_t>(), "global timestamp value in ms (for anchoring) - default is now")(
"asservice", bpo::value<bool>()->default_value(false), "run in service/server mode")(
"noGeant", bpo::bool_switch(), "prohibits any Geant transport/physics (by using tight cuts)");
Expand Down Expand Up @@ -173,8 +174,23 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const&
if (vm.count("noemptyevents")) {
mConfigData.mFilterNoHitEvents = true;
}
mConfigData.mField = std::stoi((vm["field"].as<std::string>()).substr(0, (vm["field"].as<std::string>()).rfind("U")));
mConfigData.mUniformField = (vm["field"].as<std::string>()).find("U") != std::string::npos;

// analyse field options
// either: "ccdb" or +-2[U],+-5[U] and 0[U]; +-<intKGaus>U
auto& fieldstring = vm["field"].as<std::string>();
std::regex re("(ccdb)|([+-]?[250]U?)");
if (!std::regex_match(fieldstring, re)) {
LOG(error) << "Invalid field option";
return false;
}
if (fieldstring == "ccdb") {
mConfigData.mFieldMode = SimFieldMode::kCCDB;
} else if (fieldstring.find("U") != std::string::npos) {
mConfigData.mFieldMode = SimFieldMode::kUniform;
}
if (fieldstring != "ccdb") {
mConfigData.mField = std::stoi((vm["field"].as<std::string>()).substr(0, (vm["field"].as<std::string>()).rfind("U")));
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions Common/SimConfig/src/SimConfigLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::conf::DigiParams> + ;

#pragma link C++ enum o2::conf::EG4Physics;
#pragma link C++ enum o2::conf::SimFieldMode;
#pragma link C++ struct o2::conf::G4Params + ;
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::conf::G4Params> + ;

Expand Down
4 changes: 3 additions & 1 deletion Detectors/Base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ o2_add_library(DetectorsBase
src/BaseDPLDigitizer.cxx
src/CTFCoderBase.cxx
src/Aligner.cxx
src/SimFieldUtils.cxx
PUBLIC_LINK_LIBRARIES FairRoot::Base
O2::CommonUtils
O2::DetectorsCommonDataFormats
Expand Down Expand Up @@ -48,7 +49,8 @@ o2_target_root_dictionary(DetectorsBase
include/DetectorsBase/MatCell.h
include/DetectorsBase/MatLayerCyl.h
include/DetectorsBase/MatLayerCylSet.h
include/DetectorsBase/Aligner.h)
include/DetectorsBase/Aligner.h
include/DetectorsBase/SimFieldUtils.h)

if(BUILD_SIMULATION)
o2_add_test(
Expand Down
38 changes: 38 additions & 0 deletions Detectors/Base/include/DetectorsBase/SimFieldUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 SimFieldUtils.h
/// \brief Methods to create simulation mag field

#ifndef ALICEO2_BASE_SIMFIELDUTILS_H_
#define ALICEO2_BASE_SIMFIELDUTILS_H_

namespace o2
{
namespace field
{
class MagneticField;
}

namespace base
{

class SimFieldUtils
{
public:
// a common entry point to create the mag field for simulation
// based on the simulation configuration in SimConfig
static o2::field::MagneticField* const createMagField();
};

} // namespace base
} // namespace o2
#endif
1 change: 1 addition & 0 deletions Detectors/Base/src/DetectorsBaseLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma link C++ class o2::base::GeometryManager::MatBudgetExt + ;
#pragma link C++ class o2::base::MaterialManager + ;
#pragma link C++ class o2::MaterialManagerParam + ;
#pragma link C++ class o2::base::SimFieldUtils + ;

#pragma link C++ class o2::base::Ray + ;
#pragma link C++ class o2::base::MatCell + ;
Expand Down
38 changes: 38 additions & 0 deletions Detectors/Base/src/SimFieldUtils.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 <DetectorsBase/SimFieldUtils.h>
#include <Field/MagneticField.h>
#include <SimConfig/SimConfig.h>
#include <CCDB/BasicCCDBManager.h>
#include <DataFormatsParameters/GRPMagField.h>

using namespace o2::base;

o2::field::MagneticField* const SimFieldUtils::createMagField()
{
auto& confref = o2::conf::SimConfig::Instance();
// a) take field from CDDB
const auto fieldmode = confref.getConfigData().mFieldMode;
o2::field::MagneticField* field = nullptr;
if (fieldmode == o2::conf::SimFieldMode::kCCDB) {
LOG(info) << "Fetching magnetic field from CCDB";
auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
auto grpmagfield = ccdb.get<o2::parameters::GRPMagField>("GLO/Config/GRPMagField");
// TODO: clarify if we need to pass other params such as beam energy/type etc.
field = o2::field::MagneticField::createFieldMap(grpmagfield->getL3Current(), grpmagfield->getDipoleCurrent(), grpmagfield->getFieldUniformity());
}
// b) using the given values on the command line
else {
field = o2::field::MagneticField::createNominalField(confref.getConfigData().mField, confref.getConfigData().mFieldMode == o2::conf::SimFieldMode::kUniform);
}
return field;
}
4 changes: 2 additions & 2 deletions macro/build_geometry.C
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <FairLogger.h>
#include <algorithm>
#include "DetectorsCommonDataFormats/UpgradesStatus.h"
#include <DetectorsBase/SimFieldUtils.h>
#endif

#ifdef ENABLE_UPGRADES
Expand Down Expand Up @@ -103,8 +104,7 @@ void build_geometry(FairRunSim* run = nullptr)
run->SetMaterials("media.geo"); // Materials

// we need a field to properly init the media
auto field = o2::field::MagneticField::createNominalField(confref.getConfigData().mField, confref.getConfigData().mUniformField);
run->SetField(field);
run->SetField(o2::base::SimFieldUtils::createMagField());

// Create geometry
// we always need the cave
Expand Down
6 changes: 3 additions & 3 deletions run/O2PrimaryServerDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
#include <SimConfig/SimConfig.h>
#include <CommonUtils/ConfigurableParam.h>
#include <CommonUtils/RngHelper.h>
#include "Field/MagneticField.h"
#include <DetectorsBase/SimFieldUtils.h>
#include <Field/MagneticField.h>
#include <TGeoGlobalMagField.h>
#include <typeinfo>
#include <thread>
Expand Down Expand Up @@ -76,8 +77,7 @@ class O2PrimaryServerDevice final : public FairMQDevice

// init magnetic field as it might be needed by the generator
if (TGeoGlobalMagField::Instance()->GetField() == nullptr) {
auto field = o2::field::MagneticField::createNominalField(conf.getConfigData().mField, conf.getConfigData().mUniformField);
TGeoGlobalMagField::Instance()->SetField(field);
TGeoGlobalMagField::Instance()->SetField(o2::base::SimFieldUtils::createMagField());
TGeoGlobalMagField::Instance()->Lock();
}

Expand Down