Skip to content

Commit ca98185

Browse files
authored
TRD: Fix trigger records (digitizer), and MC step size (hits) (#4680)
* Fix TRD trigger records * Add getADCsum method to the Digit class * Fix analyze digit labels macro for new labels IO * Drop unnecessary conditional
1 parent 7ff2d30 commit ca98185

File tree

6 files changed

+53
-61
lines changed

6 files changed

+53
-61
lines changed

Detectors/TRD/base/include/TRDBase/Digit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <vector>
1616
#include <array>
1717
#include <unordered_map>
18+
#include <numeric>
1819
#include "Rtypes.h" // for ClassDef
1920

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

5658
private:
5759
std::uint16_t mDetector{0}; // TRD detector number, 0-539

Detectors/TRD/simulation/include/TRDSimulation/Digitizer.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Digitizer
5959

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

71+
// Trigger parameters
72+
static constexpr double READOUT_TIME = 3000; // the time the readout takes, as 30 TB = 3 micro-s.
73+
static constexpr double DEAD_TIME = 200; // trigger deadtime, 2 micro-s
74+
static constexpr double BUSY_TIME = READOUT_TIME + DEAD_TIME; // the time for which no new trigger can be received in nanoseconds
75+
7076
private:
7177
TRDGeometry* mGeo = nullptr; // access to TRDGeometry
7278
PadResponse* mPRF = nullptr; // access to PadResponse
@@ -96,12 +102,6 @@ class Digitizer
96102
kEmbeddingEvent
97103
};
98104

99-
// Trigger parameters
100-
bool mTriggeredEvent = false;
101-
static constexpr double READOUT_TIME = 3000; // the time the readout takes, as 30 TB = 3 micro-s.
102-
static constexpr double DEAD_TIME = 200; // trigger deadtime, 2 micro-s
103-
static constexpr double BUSY_TIME = READOUT_TIME + DEAD_TIME; // the time for which no new trigger can be received in nanoseconds
104-
105105
// Digitization parameters
106106
static constexpr float AmWidth = TRDGeometry::amThick(); // Width of the amplification region
107107
static constexpr float DrWidth = TRDGeometry::drThick(); // Width of the drift retion
@@ -125,7 +125,6 @@ class Digitizer
125125

126126
// Digitization chain methods
127127
int triggerEventProcessing(DigitContainer&, o2::dataformats::MCTruthContainer<MCLabel>&);
128-
void pileup();
129128
SignalContainer addSignalsFromPileup();
130129
void clearContainers();
131130
bool convertHits(const int, const std::vector<HitType>&, SignalContainer&, int thread = 0); // True if hit-to-signal conversion is successful

Detectors/TRD/simulation/src/Detector.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ bool Detector::ProcessHits(FairVolume* v)
9292
if ((!fMC->TrackCharge()) || fMC->IsTrackDisappeared()) {
9393
return false;
9494
}
95+
fMC->SetMaxStep(0.1); // Should we optimize this value?
9596

9697
// Inside sensitive volume ?
9798
bool drRegion = false;

Detectors/TRD/simulation/src/Digitizer.cxx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -188,42 +188,13 @@ void Digitizer::clearContainers()
188188
}
189189
}
190190

191-
int Digitizer::triggerEventProcessing(DigitContainer& digits, o2::dataformats::MCTruthContainer<MCLabel>& labels)
192-
{
193-
if (mCurrentTriggerTime < 0 && mLastTime < 0) {
194-
// very first event
195-
mCurrentTriggerTime = mTime;
196-
mLastTime = mTime;
197-
return EventType::kFirstEvent;
198-
}
199-
if (mTime > mLastTime) {
200-
if ((mTime - mCurrentTriggerTime) < BUSY_TIME) {
201-
// send the signal containers to the pileup container, and do not change the current trigger time.
202-
pileup();
203-
mLastTime = mTime;
204-
return EventType::kPileupEvent;
205-
} else {
206-
// flush the digits: signals from the pileup container are converted to adcs
207-
// digits and labels are produced, and the current trigger time is changed after the flush is completed
208-
flush(digits, labels);
209-
mCurrentTriggerTime = mTime;
210-
mLastTime = mTime;
211-
return EventType::kTriggerFired;
212-
}
213-
} else {
214-
return EventType::kEmbeddingEvent;
215-
}
216-
}
217-
218191
void Digitizer::process(std::vector<HitType> const& hits, DigitContainer& digits,
219192
o2::dataformats::MCTruthContainer<MCLabel>& labels)
220193
{
221194
if (!mCalib) {
222195
LOG(FATAL) << "TRD Calibration database not available";
223196
}
224197

225-
int status = triggerEventProcessing(digits, labels);
226-
227198
// Get the a hit container for all the hits in a given detector then call convertHits for a given detector (0 - 539)
228199
std::array<std::vector<HitType>, MAXCHAMBER> hitsPerDetector;
229200
getHitContainerPerDetector(hits, hitsPerDetector);

Detectors/TRD/workflow/src/TRDDigitizerSpec.cxx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,61 @@ class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
7979
std::vector<o2::trd::Digit> digits; // digits which get filled
8080
o2::dataformats::MCTruthContainer<o2::trd::MCLabel> labels; // labels which get filled
8181

82+
o2::InteractionTimeRecord currentTime; // the current time
83+
o2::InteractionTimeRecord triggerTime; // the time at which the TRD start reading out a signal
84+
bool firstEvent = true; // Flag for the first event processed
85+
8286
TStopwatch timer;
8387
timer.Start();
84-
8588
// loop over all composite collisions given from context
8689
// (aka loop over all the interaction records)
8790
for (int collID = 0; collID < irecords.size(); ++collID) {
88-
mDigitizer.setEventTime(irecords[collID].getTimeNS());
91+
currentTime = irecords[collID];
92+
// Trigger logic implemented here
93+
if (firstEvent) {
94+
triggerTime = currentTime;
95+
firstEvent = false;
96+
} else {
97+
double dT = currentTime.getTimeNS() - triggerTime.getTimeNS();
98+
if (dT < o2::trd::Digitizer::BUSY_TIME) {
99+
// BUSY_TIME = READOUT_TIME + DEAD_TIME, if less than that, pile up the signals and update the last time
100+
mDigitizer.pileup();
101+
} else {
102+
// A new signal can be received, and the detector read it out:
103+
// flush previous stored digits, labels and keep a trigger record
104+
// then update the trigger time to the new one
105+
mDigitizer.flush(digits, labels);
106+
assert(digits.size() == labels.getIndexedSize());
107+
// Add trigger record, and send digits to the accumulator
108+
triggers.emplace_back(triggerTime, digitsAccum.size(), digits.size());
109+
std::copy(digits.begin(), digits.end(), std::back_inserter(digitsAccum));
110+
if (mctruth) {
111+
labelsAccum.mergeAtBack(labels);
112+
}
113+
triggerTime = currentTime;
114+
digits.clear();
115+
labels.clear();
116+
}
117+
}
118+
119+
mDigitizer.setEventTime(triggerTime.getTimeNS()); // do we need this?
89120

90121
// for each collision, loop over the constituents event and source IDs
91122
// (background signal merging is basically taking place here)
92123
for (auto& part : eventParts[collID]) {
93124
mDigitizer.setEventID(part.entryID);
94125
mDigitizer.setSrcID(part.sourceID);
95-
96-
// get the hits for this event and this source
126+
// get the hits for this event and this source and process them
97127
std::vector<o2::trd::HitType> hits;
98128
context->retrieveHits(mSimChains, "TRDHit", part.sourceID, part.entryID, &hits);
99-
LOG(INFO) << "For collision " << collID << " eventID " << part.entryID << " found TRD " << hits.size() << " hits ";
100-
101129
mDigitizer.process(hits, digits, labels);
102-
assert(digits.size() == labels.getIndexedSize());
103-
104-
// Add trigger record
105-
triggers.emplace_back(irecords[collID], digitsAccum.size(), digits.size());
106-
107-
std::copy(digits.begin(), digits.end(), std::back_inserter(digitsAccum));
108-
if (mctruth) {
109-
labelsAccum.mergeAtBack(labels);
110-
}
111-
digits.clear();
112-
labels.clear();
113130
}
114131
}
132+
115133
// Force flush of the digits that remain in the digitizer cache
116134
mDigitizer.flush(digits, labels);
117135
assert(digits.size() == labels.getIndexedSize());
118-
119-
triggers.emplace_back(irecords[irecords.size() - 1], digitsAccum.size(), digits.size());
136+
triggers.emplace_back(triggerTime, digitsAccum.size(), digits.size());
120137
std::copy(digits.begin(), digits.end(), std::back_inserter(digitsAccum));
121138
if (mctruth) {
122139
labelsAccum.mergeAtBack(labels);
@@ -146,7 +163,7 @@ class TRDDPLDigitizerTask : public o2::base::BaseDPLDigitizer
146163
std::vector<TChain*> mSimChains;
147164
// RS: at the moment using hardcoded flag for continuos readout
148165
o2::parameters::GRPObject::ROMode mROMode = o2::parameters::GRPObject::PRESENT; // readout mode
149-
};
166+
}; // namespace trd
150167

151168
o2::framework::DataProcessorSpec getTRDDigitizerSpec(int channel, bool mctruth)
152169
{
@@ -173,5 +190,5 @@ o2::framework::DataProcessorSpec getTRDDigitizerSpec(int channel, bool mctruth)
173190
Options{}};
174191
}
175192

176-
} // end namespace trd
193+
} // namespace trd
177194
} // end namespace o2

macro/analyzeDigitLabels.C

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,16 @@ void analyse(TTree* tr, const char* brname, Accumulator& prop)
7979
return;
8080
}
8181
auto entries = br->GetEntries();
82-
o2::dataformats::MCTruthContainer<LabelType>* labels = nullptr;
83-
br->SetAddress(&labels);
82+
o2::dataformats::IOMCTruthContainerView* io2 = nullptr;
83+
br->SetAddress(&io2);
8484

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

88-
for (int i = 0; i < (int)labels->getIndexedSize(); ++i) {
89-
prop.addLabels(labels->getLabels(i));
90+
for (int i = 0; i < (int)labels.getIndexedSize(); ++i) {
91+
prop.addLabels(labels.getLabels(i));
9092
}
9193
}
9294
};

0 commit comments

Comments
 (0)