diff --git a/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBInterface.h b/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBInterface.h index 5b2c8e6d48251..0a94d4ad861b3 100644 --- a/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBInterface.h +++ b/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBInterface.h @@ -107,6 +107,13 @@ class CDBInterface /// \return gain map object const CalPad& getGainMap(); + /// Return the gain map object applied in the simulation + /// + /// As getGainMap, but from the CCDB the gain map for MC (TPC/Calib/PadGainFullMC) is used, so that the simulation + /// can apply a different gain map than the one the reconstruction corrects with. + /// \return gain map object + const CalPad& getGainMapMC(); + /// Return the ion tail coupling fraction /// /// \return ion tail fraction diff --git a/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBTypes.h b/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBTypes.h index 1873b247eb777..38c6181f655f1 100644 --- a/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBTypes.h +++ b/Detectors/TPC/baserecsim/include/TPCBaseRecSim/CDBTypes.h @@ -90,6 +90,7 @@ enum class CDBType { /// DistortionMapMC, ///< full distortions (static + IR dependant) for MC used in the digitizer DistortionMapDerivMC, ///< derivative distortions for MC used in the digitizer for scaling + CalPadGainFullMC, ///< Full pad gain map for MC used in the digitizer AltroSyncSignal ///< timing of Altro chip sync. signal }; @@ -163,6 +164,8 @@ const std::unordered_map CDBTypeMap{ // distortion maps {CDBType::DistortionMapMC, "TPC/Calib/DistortionMapMC"}, {CDBType::DistortionMapDerivMC, "TPC/Calib/DistortionMapDerivativeMC"}, + // gain map for MC + {CDBType::CalPadGainFullMC, "TPC/Calib/PadGainFullMC"}, // AltroSyncSignal {CDBType::AltroSyncSignal, "TPC/Config/AltroSyncSignal"}, }; diff --git a/Detectors/TPC/baserecsim/src/CDBInterface.cxx b/Detectors/TPC/baserecsim/src/CDBInterface.cxx index 2aaf9c58cbe2c..011e832d5c79c 100644 --- a/Detectors/TPC/baserecsim/src/CDBInterface.cxx +++ b/Detectors/TPC/baserecsim/src/CDBInterface.cxx @@ -175,6 +175,17 @@ const CalPad& CDBInterface::getGainMap() return *mGainMap; } +//______________________________________________________________________________ +const CalPad& CDBInterface::getGainMapMC() +{ + // a gain map from file or the default one is the same for the simulation and the reconstruction + if (mGainMapFileName.size() || mUseDefaults) { + return getGainMap(); + } + + return getObjectFromCDB(CDBTypeMap.at(CDBType::CalPadGainFullMC)); +} + //______________________________________________________________________________ const CalPad& CDBInterface::getITFraction() { diff --git a/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h b/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h index 63f7de331cc26..049c7ccbf81ac 100644 --- a/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h +++ b/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h @@ -161,6 +161,9 @@ class Digitizer /// Whether flush() also flushes the process-wide debug streamer void setFlushDebugStreamer(bool flush) { mFlushDebugStreamer = flush; } + /// Apply the gain map for MC (TPC/Calib/PadGainFullMC) instead of the one of the reconstruction (TPC/Calib/PadGainFull) + void setUseGainMapMC(bool use) { mUseGainMapMC = use; } + private: /// Fill the random rings of the sector seeding, if not done yet void initSectorSeeding(); @@ -176,6 +179,7 @@ class Digitizer ULong64_t mSeedingTimeframe = 0; //!< Timeframe identifier for sector seeding bool mUseSectorSeeding = false; //!< Whether sector seeding is used bool mFlushDebugStreamer = true; //!< Whether flush() flushes the debug streamer + bool mUseGainMapMC = false; //!< Whether the gain map for MC is applied instead of the one of the reconstruction DigitContainer mDigitContainer; ///< Container for the Digits std::vector mSignalArray; //!< Workspace for the shaped signal of one electron diff --git a/Detectors/TPC/simulation/include/TPCSimulation/GEMAmplification.h b/Detectors/TPC/simulation/include/TPCSimulation/GEMAmplification.h index c30302644a07e..23c3aee045699 100644 --- a/Detectors/TPC/simulation/include/TPCSimulation/GEMAmplification.h +++ b/Detectors/TPC/simulation/include/TPCSimulation/GEMAmplification.h @@ -54,7 +54,8 @@ class GEMAmplification void setRandomRingPositions(TRandom& rng); /// Update the OCDB parameters cached in the class. To be called once per event - void updateParameters(); + /// \param useGainMapMC apply the gain map for MC (TPC/Calib/PadGainFullMC) instead of the one of the reconstruction (TPC/Calib/PadGainFull) + void updateParameters(bool useGainMapMC = false); /// Compute the number of electrons after amplification in a full stack of four GEM foils /// \param nElectrons Number of electrons arriving at the first amplification stage (GEM1) diff --git a/Detectors/TPC/simulation/src/Digitizer.cxx b/Detectors/TPC/simulation/src/Digitizer.cxx index 9c7cd1b3649cb..7ac03a93c1926 100644 --- a/Detectors/TPC/simulation/src/Digitizer.cxx +++ b/Detectors/TPC/simulation/src/Digitizer.cxx @@ -125,7 +125,7 @@ void Digitizer::init() mSAMPAProcessing->setRandomRingPositions(rng); } auto& gemAmplification = this->gemAmplification(); - gemAmplification.updateParameters(); + gemAmplification.updateParameters(mUseGainMapMC); auto& electronTransport = this->electronTransport(); electronTransport.updateParameters(mVDrift); auto& sampaProcessing = this->sampaProcessing(); diff --git a/Detectors/TPC/simulation/src/GEMAmplification.cxx b/Detectors/TPC/simulation/src/GEMAmplification.cxx index 0dadc00ee1f95..56f0740bca82d 100644 --- a/Detectors/TPC/simulation/src/GEMAmplification.cxx +++ b/Detectors/TPC/simulation/src/GEMAmplification.cxx @@ -117,12 +117,12 @@ void GEMAmplification::setRandomRingPositions(TRandom& rng) mGainFullStack.setRandomPosition(rng); } -void GEMAmplification::updateParameters() +void GEMAmplification::updateParameters(bool useGainMapMC) { auto& cdb = CDBInterface::instance(); mGEMParam = &(ParameterGEM::Instance()); mGasParam = &(ParameterGas::Instance()); - mGainMap = &(cdb.getGainMap()); + mGainMap = useGainMapMC ? &(cdb.getGainMapMC()) : &(cdb.getGainMap()); } int GEMAmplification::getStackAmplification(int nElectrons) diff --git a/Steer/DigitizerWorkflow/src/TPCDigitizerMTSpec.cxx b/Steer/DigitizerWorkflow/src/TPCDigitizerMTSpec.cxx index 99075e4e1669b..ab74804e9e448 100644 --- a/Steer/DigitizerWorkflow/src/TPCDigitizerMTSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TPCDigitizerMTSpec.cxx @@ -130,6 +130,7 @@ class TPCDPLDigitizerMTTask : public o2::base::BaseDPLDigitizer worker->id = i; worker->digitizer.setContinuousReadout(!triggeredMode); worker->digitizer.setDistortionScaleType(mDistortionType); + worker->digitizer.setUseGainMapMC(mConditions.useGainMapMC()); worker->digitizer.setUseSectorSeeding(sectorSeed); // the main thread flushes the process-wide debug streamer after the workers worker->digitizer.setFlushDebugStreamer(false); diff --git a/Steer/DigitizerWorkflow/src/TPCDigitizerSpec.cxx b/Steer/DigitizerWorkflow/src/TPCDigitizerSpec.cxx index 9bd499a5955c1..28b3ed03ce29b 100644 --- a/Steer/DigitizerWorkflow/src/TPCDigitizerSpec.cxx +++ b/Steer/DigitizerWorkflow/src/TPCDigitizerSpec.cxx @@ -112,6 +112,7 @@ class TPCDPLDigitizerTask : public BaseDPLDigitizer mDigitizer.setContinuousReadout(!triggeredMode); mDigitizer.setDistortionScaleType(mDistortionType); + mDigitizer.setUseGainMapMC(mConditions.useGainMapMC()); if (ic.options().get("tpc-sector-seeding")) { const auto seed = o2::conf::DigiParams::Instance().seed; diff --git a/Steer/DigitizerWorkflow/src/TPCSectorDigitization.cxx b/Steer/DigitizerWorkflow/src/TPCSectorDigitization.cxx index cd859672f9038..15b1f9b4f6d3b 100644 --- a/Steer/DigitizerWorkflow/src/TPCSectorDigitization.cxx +++ b/Steer/DigitizerWorkflow/src/TPCSectorDigitization.cxx @@ -134,6 +134,7 @@ std::vector TPCDigitizerConditions::options() return { {"TPCtriggered", VariantType::Bool, false, {"Impose triggered RO mode (default: continuous)"}}, {"TPCuseCCDB", VariantType::Bool, false, {"true: load calibrations from CCDB; false: use random calibratoins"}}, + {"TPCuseGainMapMC", VariantType::Bool, false, {"with TPCuseCCDB, true: apply the gain map for MC (TPC/Calib/PadGainFullMC); false: apply TPC/Calib/PadGainFull. A GainMap.root file replaces both"}}, {"meanLumiDistortions", VariantType::Float, -1.f, {"override lumi of distortion object if >=0"}}, {"meanLumiDistortionsDerivative", VariantType::Float, -1.f, {"override lumi of derivative distortion object if >=0"}}, {"do-not-recalculate-distortions", VariantType::Bool, false, {"Do not recalculate the distortions"}}, @@ -162,9 +163,18 @@ void TPCDigitizerConditions::init(framework::InitContext& ic, int distortionType mRecalcDistortions = !(ic.options().get("do-not-recalculate-distortions")); SpaceCharge::setNThreads(ic.options().get("n-threads-distortions")); mUseCalibrationsFromCCDB = ic.options().get("TPCuseCCDB"); + mUseGainMapMC = ic.options().get("TPCuseGainMapMC"); mMeanLumiDistortions = ic.options().get("meanLumiDistortions"); mMeanLumiDistortionsDerivative = ic.options().get("meanLumiDistortionsDerivative"); LOG(info) << "TPC calibrations from CCDB: " << mUseCalibrationsFromCCDB; + + if (!mUseCalibrationsFromCCDB) { + if (mUseGainMapMC) { + LOGP(warning, "TPC: TPCuseGainMapMC has no effect without TPCuseCCDB, the digitizer applies the default gain map"); + } + } else { + LOGP(info, "TPC: gain map from the CCDB applied in the digitizer: {}", CDBTypeMap.at(mUseGainMapMC ? CDBType::CalPadGainFullMC : CDBType::CalPadGainFull)); + } } bool TPCDigitizerConditions::finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj, Digitizer& digitizer) @@ -237,7 +247,7 @@ void TPCDigitizerConditions::update(framework::ProcessingContext& pc, Digitizer& } if (std::filesystem::exists("GainMap.root")) { - LOG(info) << "TPC: Using gain map from 'GainMap.root'"; + LOG(info) << "TPC: Using gain map from 'GainMap.root'" << (mUseGainMapMC ? ", TPCuseGainMapMC has no effect" : ""); cdb.setGainMapFromFile("GainMap.root"); } } diff --git a/Steer/DigitizerWorkflow/src/TPCSectorDigitization.h b/Steer/DigitizerWorkflow/src/TPCSectorDigitization.h index daf417e21ae73..3b09a340eb381 100644 --- a/Steer/DigitizerWorkflow/src/TPCSectorDigitization.h +++ b/Steer/DigitizerWorkflow/src/TPCSectorDigitization.h @@ -65,6 +65,8 @@ class TPCDigitizerConditions static void addInputs(std::vector& inputs, int distortionType); void init(framework::InitContext& ic, int distortionType); + /// whether the digitizer applies the gain map for MC (TPC/Calib/PadGainFullMC) instead of TPC/Calib/PadGainFull + bool useGainMapMC() const { return mUseGainMapMC; } /// pass a CCDB object to the digitizer; true if it was a TPC condition bool finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj, Digitizer& digitizer); /// fetch the conditions of a timeframe and prepare the digitizer, which then holds the distortions @@ -75,6 +77,7 @@ class TPCDigitizerConditions VDriftHelper mVDriftHelper{}; int mDistortionType = 0; bool mUseCalibrationsFromCCDB = false; + bool mUseGainMapMC = false; bool mRecalcDistortions = false; float mMeanLumiDistortions = -1; float mMeanLumiDistortionsDerivative = -1;