32#include <fairlogger/Logger.h>
47std::mutex& calibrationMutex()
49 static std::mutex mutex;
54ULong64_t mixSeed(ULong64_t
x)
56 x += 0x9e3779b97f4a7c15ULL;
57 x = (
x ^ (
x >> 30)) * 0xbf58476d1ce4e5b9ULL;
58 x = (
x ^ (
x >> 27)) * 0x94d049bb133111ebULL;
63UInt_t toTRandom3Seed(ULong64_t
x)
65 const UInt_t
seed =
static_cast<UInt_t
>(
x ^ (
x >> 32));
87 mUseSectorSeeding =
true;
91void Digitizer::initSectorSeeding()
93 if (mUseSectorSeeding && !mGEMAmplification) {
95 TRandom3 rng(toTRandom3Seed(mixSeed(mSeed)));
96 mGEMAmplification = std::make_unique<GEMAmplification>(&rng);
97 mElectronTransport = std::make_unique<ElectronTransport>(&rng);
98 mSAMPAProcessing = std::make_unique<SAMPAProcessing>(&rng);
105 other.initSectorSeeding();
106 mUseSectorSeeding =
other.mUseSectorSeeding;
108 if (
other.mGEMAmplification) {
109 mGEMAmplification = std::make_unique<GEMAmplification>(*
other.mGEMAmplification);
110 mElectronTransport = std::make_unique<ElectronTransport>(*
other.mElectronTransport);
111 mSAMPAProcessing = std::make_unique<SAMPAProcessing>(*
other.mSAMPAProcessing);
118 std::lock_guard<std::mutex> lock(calibrationMutex());
119 if (mUseSectorSeeding) {
121 const ULong64_t sectorSeed = mixSeed(mSeed ^ mixSeed(
static_cast<ULong64_t
>(mSector) + 1));
122 TRandom3 rng(toTRandom3Seed(mixSeed(sectorSeed ^ mixSeed(mSeedingTimeframe))));
123 mGEMAmplification->setRandomRingPositions(rng);
124 mElectronTransport->setRandomRingPositions(rng);
125 mSAMPAProcessing->setRandomRingPositions(rng);
127 auto& gemAmplification = this->gemAmplification();
129 auto& electronTransport = this->electronTransport();
131 auto& sampaProcessing = this->sampaProcessing();
138 const int eventID,
const int sourceID)
145 auto& gemAmplification = this->gemAmplification();
146 auto& electronTransport = this->electronTransport();
147 auto& sampaProcessing = this->sampaProcessing();
149 const int nShapedPoints = eleParam.NShapedPoints;
150 const auto amplificationMode = gemParam.AmplMode;
151 mSignalArray.resize(nShapedPoints);
157 float maxEleTime = (int(mDigitContainer.
size()) - nShapedPoints) * eleParam.ZbinWidth;
159 for (
auto& hitGroup : hits) {
160 const int MCTrackID = hitGroup.GetTrackID();
161 for (
size_t hitindex = 0; hitindex < hitGroup.getSize(); ++hitindex) {
162 const auto& eh = hitGroup.getHit(hitindex);
167 if (mDistortionScaleType == 1) {
169 }
else if (mDistortionScaleType == 2) {
170 mSpaceCharge->
distortElectron(posEle, (mUseScaledDistortions ?
nullptr : mSpaceChargeDer), mLumiScaleFactor);
180 const int nPrimaryElectrons =
static_cast<int>(eh.GetEnergyLoss());
181 const float hitTime = eh.GetTime() * 0.001;
182 float driftTime = 0.f;
187 for (
int iEle = 0; iEle < nPrimaryElectrons; ++iEle) {
191 const float eleTime = driftTime + hitTime;
192 if (eleTime >= maxEleTime) {
196 const float absoluteTime = eleTime + mTDriftOffset + (mEventTime - mOutputDigitTimeOffset);
200 if (!(absoluteTime >= 0 )) {
210 if (std::abs(posEleDiff.Z()) > detParam.TPClength) {
232 if (nElectronsGEM == 0) {
237 const float ADCsignal = sampaProcessing.
getADCvalue(
static_cast<float>(nElectronsGEM));
239 sampaProcessing.
getShapedSignal(ADCsignal, absoluteTime, mSignalArray);
240 for (
float i = 0;
i < nShapedPoints; ++
i) {
241 const float time = absoluteTime +
i * eleParam.ZbinWidth;
254 std::vector<o2::tpc::CommonMode>& commonModeOutput,
260 if (mFlushDebugStreamer && ((finalFlush && mIsContinuous) || (!mIsContinuous)) && mSpaceCharge) {
261 o2::utils::DebugStreamer::instance()->flush();
267 mUseSCDistortions =
true;
269 mSpaceChargeOwned = std::make_unique<SC>();
270 mSpaceCharge = mSpaceChargeOwned.get();
273 if (hisInitialSCDensity) {
281 mUseSCDistortions =
true;
282 if (spaceCharge != mSpaceChargeOwned.get()) {
283 mSpaceChargeOwned.reset();
285 mSpaceCharge = spaceCharge;
292 mSpaceChargeDer = spaceCharge;
299 mUseSCDistortions =
true;
301 mSpaceChargeOwned = std::make_unique<SC>();
302 mSpaceCharge = mSpaceChargeOwned.get();
320 std::lock_guard<std::mutex> lock(calibrationMutex());
323 const auto timediff =
time - mOutputDigitTimeOffset;
330 mSpaceChargeOwned.reset();
331 mSpaceCharge =
other.mSpaceCharge;
332 mSpaceChargeDer =
other.mSpaceChargeDer;
333 mUseSCDistortions =
other.mUseSCDistortions;
334 mLumiScaleFactor =
other.mLumiScaleFactor;
335 mUseScaledDistortions =
other.mUseScaledDistortions;
341 LOGP(info,
"Setting Lumi scale factor: lumiInst: {} lumi mean: {} lumi mean derivative: {} lumi scale factor: {}",
CorrMapParam::Instance().lumiInst, mSpaceCharge->
getMeanLumi(), mSpaceChargeDer->
getMeanLumi(), mLumiScaleFactor);
356 if (!mSpaceCharge || !mSpaceChargeDer) {
357 LOGP(info,
"Average or derivative distortions not set");
363 for (
int iside = 0; iside < 2; ++iside) {
366 LOGP(info,
"Calculating corrections for average distortions");
369 LOGP(info,
"Calculating corrections for derivative distortions");
372 LOGP(info,
"Calculating scaled distortions with scaling factor {}", mLumiScaleFactor);
381 mUseScaledDistortions =
true;
Simple interface to the CDB manager.
Implementation of the parameter class for the CorrectionMapsLoader options.
Definition of the electron transport.
Definition of the GEM amplification.
std::vector< o2::MCCompLabel > labels
Definition of the parameter class for the detector.
Definition of the parameter class for the detector electronics.
Definition of the parameter class for the GEM stack.
Definition of the parameter class for the detector gas.
Definition of the SAMPA response.
This class contains the algorithms for calculation the distortions and corrections.
Definition of the ALICE TPC digitizer.
ClassImp(o2::tpc::Digitizer)
static const ParameterDetector & Instance()
const Sector sector() const
void updateCalibrations()
void setStartTime(TimeBin time)
void setSAMPAProcessing(SAMPAProcessing *sampaProcessing)
Use this SAMPAProcessing instead of the singleton when filling the output.
size_t size() const
Get the size of the container for one event.
void fillOutputContainer(std::vector< Digit > &output, dataformats::MCTruthContainer< MCCompLabel > &mcTruth, std::vector< CommonMode > &commonModeOutput, const Sector §or, TimeBin eventTimeBin=0, bool isContinuous=true, bool finalFlush=false)
void addDigit(const MCCompLabel &label, const CRU &cru, TimeBin timeBin, GlobalPadNumber globalPad, float signal)
void reserve(TimeBin eventTimeBin)
Reserve space in the container for a given event.
const CRU & getCRU() const
PadPos getGlobalPadPos() const
void setMeanLumiDistortions(float meanLumi)
void setUseSCDistortions(const SCDistortionType &distortionType, const TH3 *hisInitialSCDensity)
void setMeanLumiDistortionsDerivative(float meanLumi)
void flush(std::vector< o2::tpc::Digit > &digits, o2::dataformats::MCTruthContainer< o2::MCCompLabel > &labels, std::vector< o2::tpc::CommonMode > &commonModeOutput, bool finalFlush=false)
void setUseSectorSeeding(ULong64_t seed)
void setSCDistortionsFrom(const Digitizer &other)
Use the distortion maps and scaling of another digitizer, which keeps ownership of the maps.
void setSCDistortionsDerivative(SC *spaceCharge)
void setLumiScaleFactor()
void setStartTime(double time)
void recalculateDistortions()
in case of scaled distortions, the distortions can be recalculated to ensure consistent distortions a...
void process(const std::vector< o2::tpc::HitGroup > &hits, const int eventID, const int sourceID=0)
void setSectorSeedingFrom(Digitizer &other)
Use copies of the sector-seeding random rings of another digitizer, which fills them if needed.
Digitizer()
Default constructor.
bool isElectronAttachment(float driftTime)
void updateParameters(float vdrift=0)
Update the OCDB parameters cached in the class. To be called once per event.
bool isCompletelyOutOfSectorCoarseElectronDrift(GlobalPosition3D posEle, const Sector §or) const
GlobalPosition3D getElectronDrift(GlobalPosition3D posEle, float &driftTime)
static ElectronTransport & instance()
void updateParameters()
Update the OCDB parameters cached in the class. To be called once per event.
int getStackAmplification(int nElectrons=1)
static GEMAmplification & instance()
Default constructor.
GlobalPadNumber globalPadNumber(const PadPos &globalPadPosition) const
const DigitPos findDigitPosFromGlobalPosition(const GlobalPosition3D &pos) const
bool isOutOfSector(GlobalPosition3D posEle, const Sector §or, const float margin=0.f) const
static Mapper & instance(const std::string mappingDir="")
void getShapedSignal(float ADCsignal, float driftTime, std::vector< float > &signalArray) const
T getADCvalue(T nElectrons) const
static SAMPAProcessing & instance()
void updateParameters(float vdrift=0)
Update the OCDB parameters cached in the class. To be called once per event.
TimeBin getTimeBinFromTime(float time) const
bool getUseAnalyticalDistCorr() const
void printMetaData() const
void setAnalyticalCorrectionsDistortionsFromFile(std::string_view inpf)
void setUseInitialSCDensity(const bool useInitialSCDensity)
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 setGlobalDistortionsFromFile(std::string_view file, const Side side)
void initAfterReadingFromFile()
float getMeanLumi() const
static void setSCDistortionType(SCDistortionType distortionType)
void setMeanLumi(float lumi)
void calcGlobalDistWithGlobalCorrIterativeLinearCartesian(const Side side, const SpaceCharge< DataT > *scSCale=nullptr, float scale=0, const int maxIter=100, const DataT approachX=1, const DataT approachY=1, const DataT approachZ=1, const DataT diffCorr=50e-6)
void fillChargeDensityFromHisto(const TH3 &hisSCDensity3D)
void distortElectron(GlobalPosition3D &point, const SpaceCharge< DataT > *scSCale=nullptr, float scale=0) const
GLuint GLsizei const GLchar * label
int const float const TrackSeed< NLayers > & seed
Global TPC definitions and constants.
math_utils::Point3D< float > GlobalPosition3D
unsigned short GlobalPadNumber
global pad number
SCDistortionType
Enumerator for setting the space-charge distortion mode.
VectorOfTObjectPtrs other
std::vector< Digit > digits