Skip to content
Open
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
27 changes: 23 additions & 4 deletions Detectors/TRD/simulation/include/TRDSimulation/Digitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "DataFormatsTRD/Digit.h"
#include "DataFormatsTRD/SignalArray.h"
#include "DataFormatsTRD/Constants.h"
#include "DataFormatsTRD/CalVdriftExB.h"
#include "DataFormatsTRD/CalGain.h"

#include "MathUtils/RandomRing.h"
#include "SimulationDataFormat/MCTruthContainer.h"
Expand Down Expand Up @@ -62,18 +64,35 @@ class Digitizer
void setEventID(int entryID) { mEventID = entryID; }
void setSrcID(int sourceID) { mSrcID = sourceID; }
void setCalibrations(Calibrations* calibrations) { mCalib = calibrations; }
void setCalVdriftExB(const CalVdriftExB* calVdriftExB) { mCalVdriftExB = calVdriftExB; }
void setFedChamberStatus(int det, int value)
{
if (det >= constants::MAXCHAMBER)
return;
Comment on lines +70 to +71

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Statements w/o {} trigger code-checker failure.

mFedChamberStatus[det] = value;
}
void setCalGain(const CalGain* calGain) { mCalGain = calGain; }
void setCreateSharedDigits(bool flag) { mCreateSharedDigits = flag; }
int getEventTime() const { return mTime; }
int getEventID() const { return mEventID; }
int getSrcID() const { return mSrcID; }
bool getCreateSharedDigits() const { return mCreateSharedDigits; }
int getFedChamberStatus(int det)
{
if (det >= constants::MAXCHAMBER)
return -1.;
return mFedChamberStatus[det];
}
std::string dumpFlaggedChambers() const;

private:
Geometry* mGeo = nullptr; // access to Geometry
PadResponse mPRF{}; // access to PadResponse
SimParam mSimParam{}; // simulation parameters
Calibrations* mCalib = nullptr; // access to Calibrations in CCDB
Geometry* mGeo = nullptr; // access to Geometry
PadResponse mPRF{}; // access to PadResponse
SimParam mSimParam{}; // simulation parameters
Calibrations* mCalib = nullptr; // access to Calibrations in CCDB
const CalVdriftExB* mCalVdriftExB = nullptr; // access to time-dependent calibrations CalVdriftExB in CCDB
const CalGain* mCalGain = nullptr; // access to time-dependent calibrations CalGain in CCDB
std::array<int, constants::MAXCHAMBER> mFedChamberStatus{}; // access to time-dependent FED chamber status in CCDB
PileupTool pileupTool;

// number of digitizer threads
Expand Down
3 changes: 3 additions & 0 deletions Detectors/TRD/simulation/include/TRDSimulation/SimParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class SimParam
}

// Getters
float getEffVdriftDefault() const { return mEffVdriftDefault; }
float getGasGain() const { return mGasGain; }
float getNoise() const { return mNoise; }
float getChipGain() const { return mChipGain; }
Expand Down Expand Up @@ -136,6 +137,8 @@ class SimParam
float mInvTRFwid{static_cast<float>(mTRFbin) / (mTRFhi - mTRFlo)}; ///< Inverse of the bin width of the integrated TRF and x-talk
float mGasGain{4000.f}; ///< Gas gain

float mEffVdriftDefault{1.22f}; ///< The CCDB contains an effective drift velocity, and not the true drift velocity, so we anchor only the variations. This default parameter is the one reproducing data the best for run 568191.

ClassDefNV(SimParam, 2); // The TRD simulation parameters
};

Expand Down
25 changes: 16 additions & 9 deletions Detectors/TRD/simulation/src/Digitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ void Digitizer::process(std::vector<Hit> const& hits)
auto& signalsMap = mSignalsMapCollection[det];
// Jump to the next detector if the detector is
// switched off, not installed, etc
if (mCalib->getChamberStatus()->isNoData(det)) {
// In the chamber Fed status, 3 corresponds to good chamber
// if (mCalib->getChamberStatus()->isNoData(det)) {
if (getFedChamberStatus(det) != 3) {
continue;
}
if (!mGeo->chamberInGeometry(det)) {
Expand Down Expand Up @@ -199,7 +201,7 @@ bool Digitizer::convertHits(const int det, const std::vector<Hit>& hits, SignalC

double padSignal[mNpad];

const double calExBDetValue = mCalib->getExB(det); // T * V/cm (check units)
const double calExBDetValue = mCalVdriftExB->getExB(det, true); // T * V/cm (check units)
const PadPlane* padPlane = mGeo->getPadPlane(det);
const int layer = mGeo->getLayer(det);
const float rowEndROC = padPlane->getRowEndROC();
Expand Down Expand Up @@ -253,8 +255,11 @@ bool Digitizer::convertHits(const int det, const std::vector<Hit>& hits, SignalC
absDriftLength /= std::sqrt(1 / (1 + calExBDetValue * calExBDetValue));
}

float driftVelocity = mCalib->getVDrift(det, colE, rowE); // The drift velocity
float t0 = mCalib->getT0(det, colE, rowE); // The T0 velocity
float driftVelocity = constants::VDRIFTDEFAULT; // The default drift velocity
if (TMath::Abs(mCalVdriftExB->getVdrift(det, true) - constants::VDRIFTDEFAULT) > 1e-6) {
driftVelocity = mCalVdriftExB->getVdrift(det, true) * constants::VDRIFTDEFAULT / mSimParam.getEffVdriftDefault(); // If they are available in the CCDB, we anchor the vdrift variations
}
float t0 = mCalib->getT0(det, colE, rowE); // The T0 velocity
Comment on lines +259 to +262

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to access calib objects via standard DPL fetcher instead of locally instantiated BasicCCDBManager, but why not doing this for all objecs and getting rid of the mCalib entirely?


// Loop over all created electrons
const int nElectrons = std::fabs(qTotal);
Expand All @@ -277,7 +282,8 @@ bool Digitizer::convertHits(const int det, const std::vector<Hit>& hits, SignalC

// Apply E x B effects
if (mSimParam.isExBOn()) {
locCd = locCd + calExBDetValue * driftLength;
// minus sign is necessary to be compatible with how Vdrift and ExB are calibrated
locCd = locCd - TMath::Tan(calExBDetValue) * driftLength;
}
// The electron position after diffusion and ExB in pad coordinates.
rowE = padPlane->getPadRowNumberROC(locRd);
Expand All @@ -292,7 +298,7 @@ bool Digitizer::convertHits(const int det, const std::vector<Hit>& hits, SignalC
continue;
}
const double colOffset = padPlane->getPadColOffset(colE, locCd + offsetTilt);
driftVelocity = mCalib->getVDrift(det, colE, rowE); // The drift velocity for the updated col and row
// driftVelocity = mCalib->getVDrift(det, colE, rowE); // The drift velocity for the updated col and row
t0 = mCalib->getT0(det, colE, rowE); // The T0 velocity for the updated col and row
// Convert the position to drift time [mus], using either constant drift velocity or
// time structure of drift cells (non-isochronity, GARFIELD calculation).
Expand All @@ -313,7 +319,8 @@ bool Digitizer::convertHits(const int det, const std::vector<Hit>& hits, SignalC
}

// Apply the gas gain including fluctuations
const double signal = -(mSimParam.getGasGain()) * mLogRandomRings[thread].getNextValue();
double timeDepGainFactor = mCalGain->getMPVdEdx(det, true) / constants::MPVDEDXDEFAULT;
const double signal = -(mSimParam.getGasGain()) * timeDepGainFactor * mLogRandomRings[thread].getNextValue();

// Apply the pad response
if (mSimParam.prfOn()) {
Expand Down Expand Up @@ -424,10 +431,10 @@ bool Digitizer::convertSignalsToADC(SignalContainer& signalMapCont, DigitContain
int halfchamberside = (mcm > 3) ? 1 : 0; // 0=Aside, 1=Bside

// Halfchambers that are switched off, masked by mCalib
if ((halfchamberside == 0 && mCalib->getChamberStatus()->isNoDataSideA(det)) ||
/*if ((halfchamberside == 0 && mCalib->getChamberStatus()->isNoDataSideA(det)) ||
(halfchamberside == 1 && mCalib->getChamberStatus()->isNoDataSideB(det))) {
continue;
}
}*/

// Check whether pad is masked
// Bridged pads are not considered yet!!!
Expand Down
36 changes: 34 additions & 2 deletions Detectors/TRD/workflow/src/TRDDigitizerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Framework/DataProcessorSpec.h"
#include "Framework/DataRefUtils.h"
#include "Framework/Lifetime.h"
#include "Framework/CCDBParamSpec.h"
#include "Headers/DataHeader.h"
#include "TStopwatch.h"
#include "TChain.h"
Expand Down Expand Up @@ -69,6 +70,9 @@ class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation;
simcal.getCCDBObjects(creationTime);
mDigitizer.setCalibrations(&simcal);
pc.inputs().get<o2::trd::CalVdriftExB*>("calvdexb");
pc.inputs().get<o2::trd::CalGain*>("calgain");
pc.inputs().get<std::array<int, constants::MAXCHAMBER>*>("fedchamberstatus");

// read collision context from input
auto context = pc.inputs().get<o2::steer::DigitizationContext*>("collisioncontext");
Expand Down Expand Up @@ -207,6 +211,28 @@ class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
finished = true;
}

void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
if (matcher == ConcreteDataMatcher("TRD", "CALVDRIFTEXB", 0)) {
LOG(info) << "CalVdriftExB object has been updated";
mDigitizer.setCalVdriftExB((const o2::trd::CalVdriftExB*)obj);
return;
}
if (matcher == ConcreteDataMatcher("TRD", "CALGAIN", 0)) {
LOG(info) << "CalGain object has been updated";
mDigitizer.setCalGain((const o2::trd::CalGain*)obj);
return;
}
if (matcher == ConcreteDataMatcher("TRD", "FEDCHAMBERSTATUS", 0)) {
LOG(info) << "Fed chamber status has been updated";
std::array<int, constants::MAXCHAMBER>* fedStatus = (std::array<int, constants::MAXCHAMBER>*)obj;
for (int det = 0; det < constants::MAXCHAMBER; det++) {
mDigitizer.setFedChamberStatus(det, (*fedStatus)[det]);
}
return;
}
}

private:
Digitizer mDigitizer;
std::vector<TChain*> mSimChains;
Expand All @@ -230,10 +256,16 @@ o2::framework::DataProcessorSpec getTRDDigitizerSpec(int channel, bool mctruth)
}
outputs.emplace_back("TRD", "ROMode", 0, Lifetime::Timeframe);

std::vector<InputSpec> inputs;
inputs.emplace_back("collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe);
inputs.emplace_back("calvdexb", "TRD", "CALVDRIFTEXB", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/CalVdriftExB"));
inputs.emplace_back("calgain", "TRD", "CALGAIN", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/CalGain"));
inputs.emplace_back("fedchamberstatus", "TRD", "FEDCHAMBERSTATUS", 0, Lifetime::Condition, ccdbParamSpec("TRD/Calib/DCSDPsFedChamberStatus"));

return DataProcessorSpec{
"TRDDigitizer",
Inputs{InputSpec{"collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe}},

// Inputs{InputSpec{"collisioncontext", "SIM", "COLLISIONCONTEXT", static_cast<SubSpecificationType>(channel), Lifetime::Timeframe}},
inputs,
outputs,

AlgorithmSpec{adaptFromTask<TRDDPLDigitizerTask>()},
Expand Down
Loading