Skip to content

Commit 71f88c2

Browse files
committed
o2-sim: Introduce persistent aligned geometry
We stream out an aligned version of the geometry file, for direct use in digitization and other steps in the MC chain. This prevents a lot of calls to CCDB and uncessary dynamic realignment. Digitization is moved to using the new aligned geometry file. We can thing of doing same for other steps. A couple of minor changes accompagny this commit: - use correct timestamp when aligning in o2-sim
1 parent c985760 commit 71f88c2

9 files changed

Lines changed: 45 additions & 26 deletions

File tree

Common/SimConfig/include/SimConfig/DigiParams.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace conf
2727
// Global parameters for digitization
2828
struct DigiParams : public o2::conf::ConfigurableParamHelper<DigiParams> {
2929

30-
std::string digitizationgeometry = ""; // with with geometry file to digitize -> leave empty as this needs to be filled by the digitizer workflow
30+
std::string digitizationgeometry_prefix = ""; // with which geometry prefix we digitized -> leave empty as this needs to be filled by the digitizer workflow
3131
std::string grpfile = ""; // which GRP file to use --> leave empty as this needs to be filled by the digitizer workflow
3232
bool mctruth = true; // whether to create labels
3333

Common/SimConfig/include/SimConfig/SimConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class SimConfig
115115
int getNSimWorkers() const { return mConfigData.mSimWorkers; }
116116
bool isFilterOutNoHitEvents() const { return mConfigData.mFilterNoHitEvents; }
117117
bool asService() const { return mConfigData.mAsService; }
118+
long getTimestamp() const { return mConfigData.mTimestamp; }
118119

119120
private:
120121
SimConfigData mConfigData; //!

Common/Utils/include/CommonUtils/NameConf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
6969

7070
// Filename to store geometry file
7171
static std::string getGeomFileName(const std::string_view prefix = "");
72+
static std::string getAlignedGeomFileName(const std::string_view prefix = "");
7273

7374
// Filename to store material LUT file
7475
static std::string getMatLUTFileName(const std::string_view prefix = "");
@@ -116,6 +117,7 @@ class NameConf : public o2::conf::ConfigurableParamHelper<NameConf>
116117
static constexpr std::string_view KINE_STRING = "Kine"; // hardcoded
117118
static constexpr std::string_view MCHEADER_STRING = "MCHeader"; // hardcoded
118119
static constexpr std::string_view GEOM_FILE_STRING = "geometry";
120+
static constexpr std::string_view ALIGNEDGEOM_FILE_STRING = "geometry-aligned";
119121
static constexpr std::string_view CUT_FILE_STRING = "proc-cut";
120122
static constexpr std::string_view CONFIG_STRING = "configuration";
121123
static constexpr std::string_view ROOT_EXT_STRING = "root";

Common/Utils/src/NameConf.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ std::string NameConf::getGeomFileName(const std::string_view prefix)
4242
return buildFileName(prefix, "_", STANDARDSIMPREFIX, GEOM_FILE_STRING, ROOT_EXT_STRING, Instance().mDirGeom);
4343
}
4444

45+
// Filename to store geometry file
46+
std::string NameConf::getAlignedGeomFileName(const std::string_view prefix)
47+
{
48+
return buildFileName(prefix, "_", STANDARDSIMPREFIX, ALIGNEDGEOM_FILE_STRING, ROOT_EXT_STRING, Instance().mDirGeom);
49+
}
50+
4551
// Filename to store general run parameters (GRP)
4652
std::string NameConf::getCollisionContextFileName(const std::string_view prefix)
4753
{

Detectors/Base/include/DetectorsBase/GeometryManager.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class GeometryManager : public TObject
4949
{
5050
public:
5151
///< load geometry from file
52-
static void loadGeometry(std::string_view geomFilePath = "", bool applyMisalignment = true);
52+
///< When applyMisalignedment == false --> read from unaligned file
53+
///< When preferAlignedFile == true and applyMisalignment == true : Prefer reading from existing aligned file
54+
static void loadGeometry(std::string_view geomFilePath = "", bool applyMisalignment = true, bool preferAlignedFile = true);
5355
static bool isGeometryLoaded() { return gGeoManager != nullptr; }
5456
static void applyMisalignent(bool applyMisalignment = true);
5557

Detectors/Base/src/BaseDPLDigitizer.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void BaseDPLDigitizer::init(o2::framework::InitContext& ic)
2929
// init basic stuff when this was asked for
3030
if (mNeedGeom) {
3131
LOG(info) << "Initializing geometry service";
32-
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry);
32+
o2::base::GeometryManager::loadGeometry(o2::conf::DigiParams::Instance().digitizationgeometry_prefix, true, true /* read from existing aligned file */);
3333
}
3434

3535
if (mNeedField) {

Detectors/Base/src/GeometryManager.cxx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -497,19 +497,27 @@ void GeometryManager::applyMisalignent(bool applyMisalignment)
497497
}
498498

499499
//_________________________________
500-
void GeometryManager::loadGeometry(std::string_view geomFileName, bool applyMisalignment)
500+
void GeometryManager::loadGeometry(std::string_view simPrefix, bool applyMisalignment, bool preferAlignedFile)
501501
{
502-
///< load geometry from file
503-
std::string fname = o2::base::NameConf::getGeomFileName(geomFileName);
504-
LOG(info) << "Loading geometry from " << fname;
505-
TFile flGeom(fname.data());
506-
if (flGeom.IsZombie()) {
507-
LOG(fatal) << "Failed to open file " << fname;
508-
}
509-
// try under the standard CCDB name
510-
if (!flGeom.Get(std::string(o2::base::NameConf::CCDBOBJECT).c_str()) &&
511-
!flGeom.Get(std::string(o2::base::NameConf::GEOMOBJECTNAME_FAIR).c_str())) {
512-
LOG(fatal) << "Did not find geometry named " << o2::base::NameConf::CCDBOBJECT << " or " << o2::base::NameConf::GEOMOBJECTNAME_FAIR;
513-
}
514-
applyMisalignent(applyMisalignment);
502+
auto loadGeom = [](const std::string_view fname) {
503+
LOG(info) << "Loading geometry from " << fname;
504+
TFile flGeom(fname.data());
505+
if (flGeom.IsZombie()) {
506+
LOG(fatal) << "Failed to open file " << fname;
507+
}
508+
// try under the standard CCDB name
509+
if (!flGeom.Get(std::string(o2::base::NameConf::CCDBOBJECT).c_str()) &&
510+
!flGeom.Get(std::string(o2::base::NameConf::GEOMOBJECTNAME_FAIR).c_str())) {
511+
LOG(fatal) << "Did not find geometry named " << o2::base::NameConf::CCDBOBJECT << " or " << o2::base::NameConf::GEOMOBJECTNAME_FAIR;
512+
}
513+
};
514+
515+
if (preferAlignedFile) {
516+
///< load directly from aligned file and apply alignment on top
517+
loadGeom(o2::base::NameConf::getAlignedGeomFileName(simPrefix));
518+
} else {
519+
///< load geometry from unaligned file and apply alignment on top
520+
loadGeom(o2::base::NameConf::getGeomFileName(simPrefix));
521+
applyMisalignent(applyMisalignment);
522+
}
515523
}

Steer/DigitizerWorkflow/src/SimpleDigitizerWorkflow.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
399399
// update the digitization configuration with the right geometry file
400400
// we take the geometry from the first simPrefix (could actually check if they are
401401
// all compatible)
402-
auto geomfilename = o2::base::NameConf::getGeomFileName(simPrefixes[0]);
403-
ConfigurableParam::setValue("DigiParams.digitizationgeometry", geomfilename);
402+
ConfigurableParam::setValue("DigiParams.digitizationgeometry_prefix", simPrefixes[0]);
404403
ConfigurableParam::setValue("DigiParams.grpfile", grpfile);
405404
LOG(info) << "MC-TRUTH " << !configcontext.options().get<bool>("disable-mc");
406405
bool mctruth = !configcontext.options().get<bool>("disable-mc");

Steer/src/O2MCApplication.cxx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,9 @@ bool O2MCApplicationBase::MisalignGeometry()
143143
}
144144
}
145145

146-
// RS We want to store ideal geometry to be able to apply different alignments on the fly
147-
// auto b = FairMCApplication::MisalignGeometry();
148-
149-
// we use this moment to stream our geometry (before other
150-
// VMC engine dependent modifications are done)
151-
146+
// we stream out both unaligned geometry (to allow for
147+
// dynamic post-alignment) as well as the aligned version
148+
// which can be used by digitization etc. immediately
152149
auto& confref = o2::conf::SimConfig::Instance();
153150
auto geomfile = o2::base::NameConf::getGeomFileName(confref.getOutPrefix());
154151
// since in general the geometry is a CCDB object, it must be exported under the standard name
@@ -157,7 +154,11 @@ bool O2MCApplicationBase::MisalignGeometry()
157154

158155
// apply alignment for included detectors AFTER exporting ideal geometry
159156
auto& aligner = o2::base::Aligner::Instance();
160-
aligner.applyAlignment(0);
157+
aligner.applyAlignment(confref.getTimestamp());
158+
159+
// export aligned geometry into different file
160+
auto alignedgeomfile = o2::base::NameConf::getAlignedGeomFileName(confref.getOutPrefix());
161+
gGeoManager->Export(alignedgeomfile.c_str());
161162

162163
// return original return value of misalignment procedure
163164
return true;

0 commit comments

Comments
 (0)