Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Detectors/TRD/base/include/TRDBase/Digit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <vector>
#include <array>
#include <unordered_map>
#include <numeric>
#include "Rtypes.h" // for ClassDef

#include "CommonDataFormat/TimeStamp.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ class Digit : public TimeStamp
int getRow() const { return mRow; }
int getPad() const { return mPad; }
ArrayADC const& getADC() const { return mADC; }
ADC_t getADCsum() const { return std::accumulate(mADC.begin(), mADC.end(), (ADC_t)0); }

private:
std::uint16_t mDetector{0}; // TRD detector number, 0-539
Expand Down
13 changes: 6 additions & 7 deletions Detectors/TRD/simulation/include/TRDSimulation/Digitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Digitizer

void process(std::vector<HitType> const&, DigitContainer&, o2::dataformats::MCTruthContainer<MCLabel>&);
void flush(DigitContainer&, o2::dataformats::MCTruthContainer<MCLabel>&);
void pileup();
void setEventTime(double timeNS) { mTime = timeNS; }
void setEventID(int entryID) { mEventID = entryID; }
void setSrcID(int sourceID) { mSrcID = sourceID; }
Expand All @@ -67,6 +68,11 @@ class Digitizer
int getEventID() const { return mEventID; }
int getSrcID() const { return mSrcID; }

// Trigger parameters
static constexpr double READOUT_TIME = 3000; // the time the readout takes, as 30 TB = 3 micro-s.
static constexpr double DEAD_TIME = 200; // trigger deadtime, 2 micro-s
static constexpr double BUSY_TIME = READOUT_TIME + DEAD_TIME; // the time for which no new trigger can be received in nanoseconds

private:
TRDGeometry* mGeo = nullptr; // access to TRDGeometry
PadResponse* mPRF = nullptr; // access to PadResponse
Expand Down Expand Up @@ -96,12 +102,6 @@ class Digitizer
kEmbeddingEvent
};

// Trigger parameters
bool mTriggeredEvent = false;
static constexpr double READOUT_TIME = 3000; // the time the readout takes, as 30 TB = 3 micro-s.
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.

Why a double? and more importantly given the discussion about 30 and 60 timebins on friday, this is going to tie it down. Similarly for the next 2 fields, or do we never simulate for Kr ?

static constexpr double DEAD_TIME = 200; // trigger deadtime, 2 micro-s
static constexpr double BUSY_TIME = READOUT_TIME + DEAD_TIME; // the time for which no new trigger can be received in nanoseconds

// Digitization parameters
static constexpr float AmWidth = TRDGeometry::amThick(); // Width of the amplification region
static constexpr float DrWidth = TRDGeometry::drThick(); // Width of the drift retion
Expand All @@ -125,7 +125,6 @@ class Digitizer

// Digitization chain methods
int triggerEventProcessing(DigitContainer&, o2::dataformats::MCTruthContainer<MCLabel>&);
void pileup();
SignalContainer addSignalsFromPileup();
void clearContainers();
bool convertHits(const int, const std::vector<HitType>&, SignalContainer&, int thread = 0); // True if hit-to-signal conversion is successful
Expand Down
1 change: 1 addition & 0 deletions Detectors/TRD/simulation/src/Detector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bool Detector::ProcessHits(FairVolume* v)
if ((!fMC->TrackCharge()) || fMC->IsTrackDisappeared()) {
return false;
}
fMC->SetMaxStep(0.1); // Should we optimize this value?

// Inside sensitive volume ?
bool drRegion = false;
Expand Down
29 changes: 0 additions & 29 deletions Detectors/TRD/simulation/src/Digitizer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -188,42 +188,13 @@ void Digitizer::clearContainers()
}
}

int Digitizer::triggerEventProcessing(DigitContainer& digits, o2::dataformats::MCTruthContainer<MCLabel>& labels)
{
if (mCurrentTriggerTime < 0 && mLastTime < 0) {
// very first event
mCurrentTriggerTime = mTime;
mLastTime = mTime;
return EventType::kFirstEvent;
}
if (mTime > mLastTime) {
if ((mTime - mCurrentTriggerTime) < BUSY_TIME) {
// send the signal containers to the pileup container, and do not change the current trigger time.
pileup();
mLastTime = mTime;
return EventType::kPileupEvent;
} else {
// flush the digits: signals from the pileup container are converted to adcs
// digits and labels are produced, and the current trigger time is changed after the flush is completed
flush(digits, labels);
mCurrentTriggerTime = mTime;
mLastTime = mTime;
return EventType::kTriggerFired;
}
} else {
return EventType::kEmbeddingEvent;
}
}

void Digitizer::process(std::vector<HitType> const& hits, DigitContainer& digits,
o2::dataformats::MCTruthContainer<MCLabel>& labels)
{
if (!mCalib) {
LOG(FATAL) << "TRD Calibration database not available";
}

int status = triggerEventProcessing(digits, labels);

// Get the a hit container for all the hits in a given detector then call convertHits for a given detector (0 - 539)
std::array<std::vector<HitType>, MAXCHAMBER> hitsPerDetector;
getHitContainerPerDetector(hits, hitsPerDetector);
Expand Down
59 changes: 38 additions & 21 deletions Detectors/TRD/workflow/src/TRDDigitizerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,44 +79,61 @@ class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
std::vector<o2::trd::Digit> digits; // digits which get filled
o2::dataformats::MCTruthContainer<o2::trd::MCLabel> labels; // labels which get filled

o2::InteractionTimeRecord currentTime; // the current time
o2::InteractionTimeRecord triggerTime; // the time at which the TRD start reading out a signal
bool firstEvent = true; // Flag for the first event processed

TStopwatch timer;
timer.Start();

// loop over all composite collisions given from context
// (aka loop over all the interaction records)
for (int collID = 0; collID < irecords.size(); ++collID) {
mDigitizer.setEventTime(irecords[collID].getTimeNS());
currentTime = irecords[collID];
// Trigger logic implemented here
if (firstEvent) {
triggerTime = currentTime;
firstEvent = false;
} else {
double dT = currentTime.getTimeNS() - triggerTime.getTimeNS();
if (dT < o2::trd::Digitizer::BUSY_TIME) {
// BUSY_TIME = READOUT_TIME + DEAD_TIME, if less than that, pile up the signals and update the last time
mDigitizer.pileup();
} else {
// A new signal can be received, and the detector read it out:
// flush previous stored digits, labels and keep a trigger record
// then update the trigger time to the new one
mDigitizer.flush(digits, labels);
assert(digits.size() == labels.getIndexedSize());
// Add trigger record, and send digits to the accumulator
triggers.emplace_back(triggerTime, digitsAccum.size(), digits.size());
std::copy(digits.begin(), digits.end(), std::back_inserter(digitsAccum));
if (mctruth) {
labelsAccum.mergeAtBack(labels);
}
triggerTime = currentTime;
digits.clear();
labels.clear();
}
}

mDigitizer.setEventTime(triggerTime.getTimeNS()); // do we need this?

// for each collision, loop over the constituents event and source IDs
// (background signal merging is basically taking place here)
for (auto& part : eventParts[collID]) {
mDigitizer.setEventID(part.entryID);
mDigitizer.setSrcID(part.sourceID);

// get the hits for this event and this source
// get the hits for this event and this source and process them
std::vector<o2::trd::HitType> hits;
context->retrieveHits(mSimChains, "TRDHit", part.sourceID, part.entryID, &hits);
LOG(INFO) << "For collision " << collID << " eventID " << part.entryID << " found TRD " << hits.size() << " hits ";

mDigitizer.process(hits, digits, labels);
assert(digits.size() == labels.getIndexedSize());

// Add trigger record
triggers.emplace_back(irecords[collID], digitsAccum.size(), digits.size());

std::copy(digits.begin(), digits.end(), std::back_inserter(digitsAccum));
if (mctruth) {
labelsAccum.mergeAtBack(labels);
}
digits.clear();
labels.clear();
}
}

// Force flush of the digits that remain in the digitizer cache
mDigitizer.flush(digits, labels);
assert(digits.size() == labels.getIndexedSize());

triggers.emplace_back(irecords[irecords.size() - 1], digitsAccum.size(), digits.size());
triggers.emplace_back(triggerTime, digitsAccum.size(), digits.size());
std::copy(digits.begin(), digits.end(), std::back_inserter(digitsAccum));
if (mctruth) {
labelsAccum.mergeAtBack(labels);
Expand Down Expand Up @@ -146,7 +163,7 @@ class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
std::vector<TChain*> mSimChains;
// RS: at the moment using hardcoded flag for continuos readout
o2::parameters::GRPObject::ROMode mROMode = o2::parameters::GRPObject::PRESENT; // readout mode
};
}; // namespace trd

o2::framework::DataProcessorSpec getTRDDigitizerSpec(int channel, bool mctruth)
{
Expand All @@ -173,5 +190,5 @@ o2::framework::DataProcessorSpec getTRDDigitizerSpec(int channel, bool mctruth)
Options{}};
}

} // end namespace trd
} // namespace trd
} // end namespace o2
10 changes: 6 additions & 4 deletions macro/analyzeDigitLabels.C
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ void analyse(TTree* tr, const char* brname, Accumulator& prop)
return;
}
auto entries = br->GetEntries();
o2::dataformats::MCTruthContainer<LabelType>* labels = nullptr;
br->SetAddress(&labels);
o2::dataformats::IOMCTruthContainerView* io2 = nullptr;
br->SetAddress(&io2);

for (int i = 0; i < entries; ++i) {
br->GetEntry(i);
o2::dataformats::ConstMCTruthContainer<LabelType> labels;
io2->copyandflatten(labels);

for (int i = 0; i < (int)labels->getIndexedSize(); ++i) {
prop.addLabels(labels->getLabels(i));
for (int i = 0; i < (int)labels.getIndexedSize(); ++i) {
prop.addLabels(labels.getLabels(i));
}
}
};
Expand Down