Skip to content

Commit

Permalink
Merge fcd8475 into sapling-pr-archive-ktf
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf authored Aug 10, 2024
2 parents 9dcc602 + fcd8475 commit 6b624c8
Show file tree
Hide file tree
Showing 18 changed files with 669 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/datamodel-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
# Send pull request
# We need to use "gh" ourselves because alisw/pull-request gets
# confused when multiple repos are checked out.
GH_TOKEN=${{ secrets.GITHUB_TOKEN }} gh pr create -B \
GH_TOKEN="$GITHUB_TOKEN" gh pr create -B \
AliceO2Group:master -H alibuild:auto-datamodel-doc \
--no-maintainer-edit -t 'Automatic data model update' -b "This update \
to the data model documentation was automatically created from \
Expand Down
17 changes: 12 additions & 5 deletions Common/SimConfig/include/SimConfig/G4Params.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ namespace conf

// enumerating the possible G4 physics settings
enum class EG4Physics {
kFTFP_BERT_optical = 0, /* just ordinary */
kFTFP_BERT_optical_biasing = 1, /* with biasing enabled */
kFTFP_INCLXX_optical = 2, /* special INCL++ version */
kFTFP_BERT_HP_optical = 3 /* enable low energy neutron transport */
kFTFP_BERT_optical = 0, /* just ordinary */
kFTFP_BERT_optical_biasing = 1, /* with biasing enabled */
kFTFP_INCLXX_optical = 2, /* special INCL++ version */
kFTFP_BERT_HP_optical = 3, /* enable low energy neutron transport */
kFTFP_BERT_EMV_optical = 4, /* just ordinary with faster electromagnetic physics */
kFTFP_BERT_EMV_optical_biasing = 5, /* with biasing enabled with faster electromagnetic physics */
kFTFP_INCLXX_EMV_optical = 6, /* special INCL++ version */
kFTFP_BERT_EMV_HP_optical = 7, /* enable low energy neutron transport */
kUSER = 8 /* allows to give own string combination */
};

// parameters to influence the G4 engine
struct G4Params : public o2::conf::ConfigurableParamHelper<G4Params> {
EG4Physics physicsmode = EG4Physics::kFTFP_BERT_optical; // physics mode with which to configure G4
EG4Physics physicsmode = EG4Physics::kFTFP_BERT_EMV_optical; // default physics mode with which to configure G4

std::string configMacroFile = ""; // a user provided g4Config.in file (otherwise standard one fill be taken)
std::string userPhysicsList = ""; // possibility to directly give physics list as string

std::string const& getPhysicsConfigString() const;

O2ParamDef(G4Params, "G4");
Expand Down
11 changes: 10 additions & 1 deletion Common/SimConfig/src/G4Params.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ namespace conf

namespace
{
static const std::string confstrings[4] = {"FTFP_BERT_EMV+optical", "FTFP_BERT_EMV+optical+biasing", "FTFP_INCLXX_EMV+optical",
static const std::string confstrings[8] = {"FTFP_BERT+optical",
"FTFP_BERT+optical+biasing",
"FTFP_INCLXX+optical",
"FTFP_BERT_HP+optical",
"FTFP_BERT_EMV+optical",
"FTFP_BERT_EMV+optical+biasing",
"FTFP_INCLXX_EMV+optical",
"FTFP_BERT_HP_EMV+optical"};
}

std::string const& G4Params::getPhysicsConfigString() const
{
if (physicsmode == o2::conf::EG4Physics::kUSER) {
return userPhysicsList;
}
return confstrings[(int)physicsmode];
}

Expand Down
6 changes: 3 additions & 3 deletions Detectors/CTP/workflowScalers/src/ctpCCDBManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int ctpCCDBManager::saveRunScalersToCCDB(CTPRunScalers& scalers, long timeStart,
if (ret == 0) {
LOG(info) << "CTP scalers saved in ccdb:" << mCCDBHost << " run:" << scalers.getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(FATAL) << "Problem writing to database ret:" << ret;
LOG(fatal) << "Problem writing to database ret:" << ret;
}
return ret;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ int ctpCCDBManager::saveRunScalersToQCDB(CTPRunScalers& scalers, long timeStart,
if (ret == 0) {
LOG(info) << "CTP scalers saved in qcdb:" << mQCDBHost << " run:" << scalers.getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(FATAL) << "CTP scalers Problem writing to database qcdb ret:" << ret;
LOG(fatal) << "CTP scalers Problem writing to database qcdb ret:" << ret;
}
return ret;
}
Expand All @@ -103,7 +103,7 @@ int ctpCCDBManager::saveRunConfigToCCDB(CTPConfiguration* cfg, long timeStart)
if (ret == 0) {
LOG(info) << "CTP config saved in ccdb:" << mCCDBHost << " run:" << cfg->getRunNumber() << " tmin:" << tmin << " tmax:" << tmax;
} else {
LOG(FATAL) << "CTPConfig: Problem writing to database ret:" << ret;
LOG(fatal) << "CTPConfig: Problem writing to database ret:" << ret;
}
return ret;
}
Expand Down
6 changes: 6 additions & 0 deletions Detectors/EMCAL/base/src/Geometry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ void Geometry::DefineSamplingFraction(const std::string_view mcname, const std::
}

Float_t samplingFactorTranportModel = 1.;
// Note: The sampling factors are chosen so that results from the simulation
// engines correspond well with testbeam data

if (contains(mcname, "Geant3")) {
samplingFactorTranportModel = 1.; // 0.988 // Do nothing
} else if (contains(mcname, "Fluka")) {
Expand All @@ -318,6 +321,9 @@ void Geometry::DefineSamplingFraction(const std::string_view mcname, const std::
LOG(info) << "Selected physics list: " << physicslist;
// sampling factors for different Geant4 physics list
// GEANT4 10.7 -> EMCAL-784

// set a default (there may be many physics list strings)
samplingFactorTranportModel = 0.81;
if (physicslist == "FTFP_BERT_EMV+optical") {
samplingFactorTranportModel = 0.821;
} else if (physicslist == "FTFP_BERT_EMV+optical+biasing") {
Expand Down
4 changes: 2 additions & 2 deletions Detectors/TPC/qc/src/PID.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ bool PID::processTrack(const o2::tpc::TrackTPC& track, size_t nTracks)
{
// ===| variables required for cutting and filling |===
const auto& dEdx = track.getdEdx();
const auto magCharge = track.getAbsCharge();
const auto pTPC = track.getP() * magCharge; // charge magnitude is divided getP() via getPtInv therefore magCharge is required to be multiplied [fix for He3]
const auto absCharge = track.getAbsCharge();
const auto pTPC = (absCharge > 0) ? (track.getP() / absCharge) : track.getP(); // charge magnitude is divided getP() via getPtInv for pTPC/Z [fix for He3]
const auto tgl = track.getTgl();
const auto snp = track.getSnp();
const auto phi = track.getPhi();
Expand Down
6 changes: 5 additions & 1 deletion Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class Digitizer
void setMeanLumiDistortions(float meanLumi);
void setMeanLumiDistortionsDerivative(float meanLumi);

/// in case of scaled distortions, the distortions can be recalculated to ensure consistent distortions and corrections
void recalculateDistortions();

private:
DigitContainer mDigitContainer; ///< Container for the Digits
std::unique_ptr<SC> mSpaceCharge; ///< Handler of full distortions (static + IR dependant)
Expand All @@ -151,7 +154,8 @@ class Digitizer
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi
float mLumiScaleFactor = 0; ///< value used to scale the derivative map
ClassDefNV(Digitizer, 2);
bool mUseScaledDistortions = false; ///< whether the distortions are already scaled
ClassDefNV(Digitizer, 3);
};
} // namespace tpc
} // namespace o2
Expand Down
32 changes: 31 additions & 1 deletion Detectors/TPC/simulation/src/Digitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void Digitizer::process(const std::vector<o2::tpc::HitGroup>& hits,
if (mDistortionScaleType == 1) {
mSpaceCharge->distortElectron(posEle);
} else if (mDistortionScaleType == 2) {
mSpaceCharge->distortElectron(posEle, mSpaceChargeDer.get(), mLumiScaleFactor);
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer.get()), mLumiScaleFactor);
}

/// Remove electrons that end up more than three sigma of the hit's average diffusion away from the current sector
Expand Down Expand Up @@ -237,3 +237,33 @@ void Digitizer::setMeanLumiDistortionsDerivative(float meanLumi)
{
mSpaceChargeDer->setMeanLumi(meanLumi);
}

void Digitizer::recalculateDistortions()
{
if (!mSpaceCharge || !mSpaceChargeDer) {
LOGP(info, "Average or derivative distortions not set");
return;
}

// recalculate distortions only in case the inst lumi differs from the avg lumi
if (mSpaceCharge->getMeanLumi() != CorrMapParam::Instance().lumiInst) {
for (int iside = 0; iside < 2; ++iside) {
const o2::tpc::Side side = (iside == 0) ? Side::A : Side::C;
// this needs to be done only once
LOGP(info, "Calculating corrections for average distortions");
mSpaceCharge->calcGlobalCorrWithGlobalDistIterative(side, nullptr, 0);

LOGP(info, "Calculating corrections for derivative distortions");
mSpaceChargeDer->calcGlobalCorrWithGlobalDistIterative(side, nullptr, 0);

LOGP(info, "Calculating scaled distortions with scaling factor {}", mLumiScaleFactor);
mSpaceCharge->calcGlobalDistWithGlobalCorrIterative(side, mSpaceChargeDer.get(), mLumiScaleFactor);
}
// set new lumi of avg map
mSpaceCharge->setMeanLumi(CorrMapParam::Instance().lumiInst);
} else {
LOGP(info, "Inst. lumi {} is same as mean lumi {}. Skip recalculation of distortions", CorrMapParam::Instance().lumiInst, mSpaceCharge->getMeanLumi());
}

mUseScaledDistortions = true;
}
17 changes: 16 additions & 1 deletion Detectors/TPC/spacecharge/include/TPCSpaceCharge/SpaceCharge.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,20 @@ class SpaceCharge
/// \param approachR when the difference between the desired r coordinate and the position of the global correction is deltaR, approach the desired r coordinate by deltaR * \p approachR.
/// \param approachPhi when the difference between the desired phi coordinate and the position of the global correction is deltaPhi, approach the desired phi coordinate by deltaPhi * \p approachPhi.
/// \param diffCorr if the absolute differences from the interpolated values for the global corrections from the last iteration compared to the current iteration is smaller than this value, set converged to true for current global distortion
void calcGlobalDistWithGlobalCorrIterative(const DistCorrInterpolator<DataT>& globCorr, const int maxIter = 100, const DataT approachZ = 0.5, const DataT approachR = 0.5, const DataT approachPhi = 0.5, const DataT diffCorr = 1e-6);
/// \param type whether to calculate distortions or corrections
void calcGlobalDistWithGlobalCorrIterative(const DistCorrInterpolator<DataT>& globCorr, const int maxIter = 100, const DataT approachZ = 1, const DataT approachR = 1, const DataT approachPhi = 1, const DataT diffCorr = 50e-6, const SpaceCharge<DataT>* scSCale = nullptr, float scale = 0);

/// step 5: calculate global distortions using the global corrections (FAST)
/// \param scSCale possible second sc object
/// \param scale scaling for second sc object
void calcGlobalDistWithGlobalCorrIterative(const Side side, const SpaceCharge<DataT>* scSCale = nullptr, float scale = 0, const int maxIter = 100, const DataT approachZ = 1, const DataT approachR = 1, const DataT approachPhi = 1, const DataT diffCorr = 50e-6);
void calcGlobalDistWithGlobalCorrIterative(const SpaceCharge<DataT>* scSCale = nullptr, float scale = 0, const int maxIter = 100, const DataT approachZ = 1, const DataT approachR = 1, const DataT approachPhi = 1, const DataT diffCorr = 50e-6);

/// calculate global corrections from global distortions
/// \param scSCale possible second sc object
/// \param scale scaling for second sc object
void calcGlobalCorrWithGlobalDistIterative(const Side side, const SpaceCharge<DataT>* scSCale = nullptr, float scale = 0, const int maxIter = 100, const DataT approachZ = 1, const DataT approachR = 1, const DataT approachPhi = 1, const DataT diffCorr = 50e-6);
void calcGlobalCorrWithGlobalDistIterative(const SpaceCharge<DataT>* scSCale = nullptr, float scale = 0, const int maxIter = 100, const DataT approachZ = 1, const DataT approachR = 1, const DataT approachPhi = 1, const DataT diffCorr = 50e-6);

/// \return returns number of vertices in z direction
unsigned short getNZVertices() const { return mParamGrid.NZVertices; }
Expand Down Expand Up @@ -1359,6 +1372,8 @@ class SpaceCharge
/// set potentialsdue to ROD misalignment
void initRodAlignmentVoltages(const MisalignmentType misalignmentType, const FCType fcType, const int sector, const Side side, const float deltaPot);

void calcGlobalDistCorrIterative(const DistCorrInterpolator<DataT>& globCorr, const int maxIter, const DataT approachZ, const DataT approachR, const DataT approachPhi, const DataT diffCorr, const SpaceCharge<DataT>* scSCale, float scale, const Type type);

ClassDefNV(SpaceCharge, 6);
};

Expand Down
Loading

0 comments on commit 6b624c8

Please sign in to comment.