Skip to content

Commit a1d96c9

Browse files
committed
Add option to disable MC labels in TRD TRAP sim
1 parent 29534b7 commit a1d96c9

8 files changed

Lines changed: 112 additions & 75 deletions

File tree

Detectors/TRD/workflow/include/TRDWorkflow/TRDDigitReaderSpec.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace trd
2929
class TRDDigitReaderSpec : public o2::framework::Task
3030
{
3131
public:
32-
TRDDigitReaderSpec(int channels) : mChannels(channels){};
32+
TRDDigitReaderSpec(int channels, bool useMC) : mChannels(channels), mUseMC(useMC) {}
3333
~TRDDigitReaderSpec() override = default;
3434
void init(o2::framework::InitContext& ic) override;
3535
void run(o2::framework::ProcessingContext& pc) override;
@@ -39,6 +39,7 @@ class TRDDigitReaderSpec : public o2::framework::Task
3939
int mState = 0;
4040
bool mUseRun2 = false;
4141
int mChannels;
42+
bool mUseMC = false;
4243
std::unique_ptr<TFile> mFile = nullptr;
4344
//std::unique_ptr<TTree> DPLTree;
4445
std::string mInputFileName = "";
@@ -48,7 +49,7 @@ class TRDDigitReaderSpec : public o2::framework::Task
4849
std::string mMCLabelsBranchName = "TRDMCLabels";
4950
};
5051

51-
o2::framework::DataProcessorSpec getTRDDigitReaderSpec(int channels);
52+
o2::framework::DataProcessorSpec getTRDDigitReaderSpec(int channels, bool useMC);
5253

5354
} // end namespace trd
5455
} // end namespace o2

Detectors/TRD/workflow/include/TRDWorkflow/TRDTrackletWriterSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace o2
3131
namespace trd
3232
{
3333

34-
o2::framework::DataProcessorSpec getTRDTrackletWriterSpec();
34+
o2::framework::DataProcessorSpec getTRDTrackletWriterSpec(bool useMC);
3535

3636
} // end namespace trd
3737
} // end namespace o2

Detectors/TRD/workflow/include/TRDWorkflow/TRDTrapSimulatorSpec.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TRDDPLTrapSimulatorTask : public o2::framework::Task
3434
{
3535

3636
public:
37-
TRDDPLTrapSimulatorTask() = default;
37+
TRDDPLTrapSimulatorTask(bool useMC) : mUseMC(useMC) {}
3838

3939
void init(o2::framework::InitContext& ic) override;
4040
void run(o2::framework::ProcessingContext& pc) override;
@@ -46,6 +46,7 @@ class TRDDPLTrapSimulatorTask : public o2::framework::Task
4646
unsigned long mRunNumber = 297595; //run number to anchor simulation to.
4747
int mShowTrackletStats = 1; // show some statistics for each run
4848
bool mEnableOnlineGainCorrection{false};
49+
bool mUseMC{false}; // whether or not to use MC labels
4950
bool mEnableTrapConfigDump{false};
5051
bool mShareDigitsManually{true}; // duplicate digits connected to shared pads if digitizer did not do so
5152
std::string mTrapConfigName; // the name of the config to be used.
@@ -57,10 +58,10 @@ class TRDDPLTrapSimulatorTask : public o2::framework::Task
5758
void loadTrapConfig();
5859
void loadDefaultTrapConfig();
5960
void setOnlineGainTables();
60-
void processTRAPchips(int currDetector, int& nTrackletsInTrigRec, std::vector<Tracklet64>& trapTrackletsAccum, o2::dataformats::MCTruthContainer<o2::MCCompLabel>& trackletMCLabels, const o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>& digitMCLabels);
61+
void processTRAPchips(int currDetector, int& nTrackletsInTrigRec, std::vector<Tracklet64>& trapTrackletsAccum, o2::dataformats::MCTruthContainer<o2::MCCompLabel>& lblTracklets, const o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>* lblDigits);
6162
};
6263

63-
o2::framework::DataProcessorSpec getTRDTrapSimulatorSpec();
64+
o2::framework::DataProcessorSpec getTRDTrapSimulatorSpec(bool useMC);
6465

6566
} // end namespace trd
6667
} // end namespace o2

Detectors/TRD/workflow/src/TRDDigitReaderSpec.cxx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,17 @@ void TRDDigitReaderSpec::run(ProcessingContext& pc)
9797
};
9898
getFromBranch(mDigitBranchName.c_str(), (void**)&digits);
9999
getFromBranch(mTriggerRecordBranchName.c_str(), (void**)&triggerRecords);
100-
getFromBranch(mMCLabelsBranchName.c_str(), (void**)&ioLabels);
100+
if (mUseMC) {
101+
getFromBranch(mMCLabelsBranchName.c_str(), (void**)&ioLabels);
102+
// publish labels in shared memory
103+
auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::trd::MCLabel>>(Output{"TRD", "LABELS", 0, Lifetime::Timeframe});
104+
ioLabels->copyandflatten(sharedlabels);
105+
LOG(info) << "TRDDigitReader labels size (in bytes) = " << sharedlabels.size();
106+
}
101107

102-
// publish labels in shared memory
103-
auto& sharedlabels = pc.outputs().make<o2::dataformats::ConstMCTruthContainer<o2::trd::MCLabel>>(Output{"TRD", "LABELS", 0, Lifetime::Timeframe});
104-
ioLabels->copyandflatten(sharedlabels);
105108
pc.outputs().snapshot(Output{"TRD", "DIGITS", 0, Lifetime::Timeframe}, *digits);
106109
pc.outputs().snapshot(Output{"TRD", "TRGRDIG", 0, Lifetime::Timeframe}, *triggerRecords);
107-
LOG(info) << "TRDDigitReader digits size=" << digits->size() << " triggerrecords size=" << triggerRecords->size() << " mc labels size (in bytes) = " << sharedlabels.size();
110+
LOG(info) << "TRDDigitReader digits size=" << digits->size() << " triggerrecords size=" << triggerRecords->size();
108111
}
109112
//delete DPLTree; // next line will delete the pointer as well.
110113
mFile->Close();
@@ -115,17 +118,18 @@ void TRDDigitReaderSpec::run(ProcessingContext& pc)
115118
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
116119
}
117120

118-
DataProcessorSpec getTRDDigitReaderSpec(int channels)
121+
DataProcessorSpec getTRDDigitReaderSpec(int channels, bool useMC)
119122
{
120-
123+
std::vector<OutputSpec> outputs;
124+
outputs.emplace_back("TRD", "DIGITS", 0, Lifetime::Timeframe);
125+
outputs.emplace_back("TRD", "TRGRDIG", 0, Lifetime::Timeframe);
126+
if (useMC) {
127+
outputs.emplace_back("TRD", "LABELS", 0, Lifetime::Timeframe);
128+
}
121129
return DataProcessorSpec{"TRDDIGITREADER",
122130
Inputs{},
123-
Outputs{
124-
OutputSpec{"TRD", "DIGITS", 0, Lifetime::Timeframe},
125-
OutputSpec{"TRD", "TRGRDIG", 0, Lifetime::Timeframe},
126-
OutputSpec{"TRD", "LABELS", 0, Lifetime::Timeframe}},
127-
// outputs,
128-
AlgorithmSpec{adaptFromTask<TRDDigitReaderSpec>(channels)},
131+
outputs,
132+
AlgorithmSpec{adaptFromTask<TRDDigitReaderSpec>(channels, useMC)},
129133
Options{
130134
{"digitsfile", VariantType::String, "trddigits.root", {"Input data file containing run3 digitizer going into Trap Simulator"}},
131135
{"run2digitsfile", VariantType::String, "run2digits.root", {"Input data file containing run2 digitis going into Trap Simulator"}}}};

Detectors/TRD/workflow/src/TRDTrackletWriterSpec.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace trd
3434
template <typename T>
3535
using BranchDefinition = framework::MakeRootTreeWriterSpec::BranchDefinition<T>;
3636

37-
o2::framework::DataProcessorSpec getTRDTrackletWriterSpec()
37+
o2::framework::DataProcessorSpec getTRDTrackletWriterSpec(bool useMC)
3838
{
3939
// using InputSpec = framework::InputSpec;
4040
using MakeRootTreeWriterSpec = framework::MakeRootTreeWriterSpec;
@@ -52,7 +52,7 @@ o2::framework::DataProcessorSpec getTRDTrackletWriterSpec()
5252
"trdtracklets.root",
5353
"o2sim",
5454
BranchDefinition<std::vector<o2::trd::Tracklet64>>{InputSpec{"tracklets", "TRD", "TRACKLETS"}, "Tracklet"},
55-
BranchDefinition<o2::dataformats::MCTruthContainer<o2::trd::MCLabel>>{InputSpec{"trklabels", "TRD", "TRKLABELS"}, "TRKLabels"},
55+
BranchDefinition<o2::dataformats::MCTruthContainer<o2::trd::MCLabel>>{InputSpec{"trklabels", "TRD", "TRKLABELS"}, "TRKLabels", (useMC ? 1 : 0), "TRKLABELS"},
5656
BranchDefinition<std::vector<o2::trd::TriggerRecord>>{InputSpec{"tracklettrigs", "TRD", "TRKTRGRD"}, "TrackTrg"})();
5757
};
5858

Detectors/TRD/workflow/src/TRDTrapSimulatorSpec.cxx

Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void TRDDPLTrapSimulatorTask::setOnlineGainTables()
142142
}
143143
}
144144

145-
void TRDDPLTrapSimulatorTask::processTRAPchips(int currDetector, int& nTrackletsInTrigRec, std::vector<Tracklet64>& trapTrackletsAccum, o2::dataformats::MCTruthContainer<o2::MCCompLabel>& trackletMCLabels, const o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>& digitMCLabels)
145+
void TRDDPLTrapSimulatorTask::processTRAPchips(int currDetector, int& nTrackletsInTrigRec, std::vector<Tracklet64>& trapTrackletsAccum, o2::dataformats::MCTruthContainer<o2::MCCompLabel>& lblTracklets, const o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>* lblDigits)
146146
{
147147
// Loop over all TRAP chips of detector number currDetector.
148148
// TRAP chips without input data are skipped
@@ -159,36 +159,38 @@ void TRDDPLTrapSimulatorTask::processTRAPchips(int currDetector, int& nTracklets
159159
auto trackletsOut = mTrapSimulator[iTrap].getTrackletArray64();
160160
int nTrackletsOut = trackletsOut.size();
161161
nTrackletsInTrigRec += nTrackletsOut;
162-
auto digitCountOut = mTrapSimulator[iTrap].getTrackletDigitCount(); // number of digits contributing to each tracklet
163-
auto digitIndicesOut = mTrapSimulator[iTrap].getTrackletDigitIndices(); // global indices of the digits composing the tracklets
164-
int currDigitIndex = 0; // count the total number of digits which are associated to tracklets for this TRAP
165-
int trkltIdxStart = trapTrackletsAccum.size();
166-
for (int iTrklt = 0; iTrklt < nTrackletsOut; ++iTrklt) {
167-
// for each tracklet of this TRAP check the MC labels of the digits which contribute to the tracklet
168-
int tmp = currDigitIndex;
169-
for (int iDigitIndex = tmp; iDigitIndex < tmp + digitCountOut[iTrklt]; ++iDigitIndex) {
170-
if (iDigitIndex == tmp) {
171-
// for the first digit composing the tracklet we don't need to check for duplicate labels
172-
trackletMCLabels.addElements(trkltIdxStart + iTrklt, digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]));
173-
} else {
174-
// in case more than one digit composes the tracklet we add only the labels
175-
// from the additional digit(s) which are not already contained in the previous
176-
// digit(s)
177-
auto currentLabels = trackletMCLabels.getLabels(trkltIdxStart + iTrklt);
178-
auto newLabels = digitMCLabels.getLabels(digitIndicesOut[iDigitIndex]);
179-
for (const auto& newLabel : newLabels) {
180-
bool isAlreadyIn = false;
181-
for (const auto& currLabel : currentLabels) {
182-
if (currLabel.compare(newLabel)) {
183-
isAlreadyIn = true;
162+
if (mUseMC) {
163+
auto digitCountOut = mTrapSimulator[iTrap].getTrackletDigitCount(); // number of digits contributing to each tracklet
164+
auto digitIndicesOut = mTrapSimulator[iTrap].getTrackletDigitIndices(); // global indices of the digits composing the tracklets
165+
int currDigitIndex = 0; // count the total number of digits which are associated to tracklets for this TRAP
166+
int trkltIdxStart = trapTrackletsAccum.size();
167+
for (int iTrklt = 0; iTrklt < nTrackletsOut; ++iTrklt) {
168+
// for each tracklet of this TRAP check the MC labels of the digits which contribute to the tracklet
169+
int tmp = currDigitIndex;
170+
for (int iDigitIndex = tmp; iDigitIndex < tmp + digitCountOut[iTrklt]; ++iDigitIndex) {
171+
if (iDigitIndex == tmp) {
172+
// for the first digit composing the tracklet we don't need to check for duplicate labels
173+
lblTracklets.addElements(trkltIdxStart + iTrklt, lblDigits->getLabels(digitIndicesOut[iDigitIndex]));
174+
} else {
175+
// in case more than one digit composes the tracklet we add only the labels
176+
// from the additional digit(s) which are not already contained in the previous
177+
// digit(s)
178+
auto currentLabels = lblTracklets.getLabels(trkltIdxStart + iTrklt);
179+
auto newLabels = lblDigits->getLabels(digitIndicesOut[iDigitIndex]);
180+
for (const auto& newLabel : newLabels) {
181+
bool isAlreadyIn = false;
182+
for (const auto& currLabel : currentLabels) {
183+
if (currLabel.compare(newLabel)) {
184+
isAlreadyIn = true;
185+
}
186+
}
187+
if (!isAlreadyIn) {
188+
lblTracklets.addElement(trkltIdxStart + iTrklt, newLabel);
184189
}
185-
}
186-
if (!isAlreadyIn) {
187-
trackletMCLabels.addElement(trkltIdxStart + iTrklt, newLabel);
188190
}
189191
}
192+
++currDigitIndex;
190193
}
191-
++currDigitIndex;
192194
}
193195
}
194196
trapTrackletsAccum.insert(trapTrackletsAccum.end(), trackletsOut.begin(), trackletsOut.end());
@@ -221,25 +223,30 @@ void TRDDPLTrapSimulatorTask::run(o2::framework::ProcessingContext& pc)
221223

222224
// input
223225
auto inputDigits = pc.inputs().get<gsl::span<o2::trd::Digit>>("digitinput"); // block of TRD digits
224-
auto digitMCLabels = pc.inputs().get<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>("labelinput"); // MC labels associated to the input digits
225226
auto inputTriggerRecords = pc.inputs().get<gsl::span<o2::trd::TriggerRecord>>("triggerrecords"); // time and number of digits for each collision
226227
if (inputDigits.size() == 0 || inputTriggerRecords.size() == 0) {
227228
LOG(warn) << "Did not receive any digits, trigger records, or neither one nor the other. Aborting.";
228229
return;
229230
}
230231
LOG(debug) << "Read in " << inputDigits.size() << " digits";
231-
LOG(debug) << "Labels contain " << digitMCLabels.getNElements() << " elements with and indexed size of " << digitMCLabels.getIndexedSize();
232-
LOG(debug) << "Trigger records are available for " << inputTriggerRecords.size() << " collisions";
233-
if (digitMCLabels.getIndexedSize() != inputDigits.size()) {
234-
LOG(warn) << "Digits and Labels coming into TrapSimulator are of differing sizes, labels will be jibberish. " << digitMCLabels.getIndexedSize() << "!=" << inputDigits.size();
232+
233+
const o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>* lblDigitsPtr = nullptr;
234+
235+
if (mUseMC) {
236+
auto lblDigits = pc.inputs().get<o2::dataformats::ConstMCTruthContainer<o2::MCCompLabel>>("labelinput"); // MC labels associated to the input digits
237+
lblDigitsPtr = &lblDigits;
238+
LOG(debug) << "Labels contain " << lblDigitsPtr->getNElements() << " elements with and indexed size of " << lblDigitsPtr->getIndexedSize();
239+
if (lblDigitsPtr->getIndexedSize() != inputDigits.size()) {
240+
LOG(warn) << "Digits and Labels coming into TrapSimulator are of differing sizes, labels will be jibberish. " << lblDigitsPtr->getIndexedSize() << "!=" << inputDigits.size();
241+
}
235242
}
243+
LOG(debug) << "Trigger records are available for " << inputTriggerRecords.size() << " collisions";
236244

237245
// output
238246
std::vector<Tracklet64> trapTrackletsAccum; // calculated tracklets
239-
o2::dataformats::MCTruthContainer<o2::MCCompLabel> trackletMCLabels; // MC labels for the tracklets, taken from the digits which make up the tracklet (duplicates are removed)
240247
// copy from the input to keep the collision times, but the number of objects in here will refer to tracklets instead of digits
241248
std::vector<o2::trd::TriggerRecord> trackletTriggerRecords(inputTriggerRecords.begin(), inputTriggerRecords.end()); // time and number of tracklets for each collision
242-
trapTrackletsAccum.reserve(inputDigits.size() / 500);
249+
o2::dataformats::MCTruthContainer<o2::MCCompLabel> lblTracklets; // MC labels for the tracklets, taken from the digits which make up the tracklet (duplicates are removed)
243250

244251
// sort digits by chamber ID for each collision and keep track in index vector
245252
auto sortStart = std::chrono::high_resolution_clock::now();
@@ -266,7 +273,7 @@ void TRDDPLTrapSimulatorTask::run(o2::framework::ProcessingContext& pc)
266273
}
267274
if (currDetector != digit->getDetector()) {
268275
// we switch to a new chamber, process all TRAPs of the previous chamber which contain data
269-
processTRAPchips(currDetector, nTrackletsInTrigRec, trapTrackletsAccum, trackletMCLabels, digitMCLabels);
276+
processTRAPchips(currDetector, nTrackletsInTrigRec, trapTrackletsAccum, lblTracklets, lblDigitsPtr);
270277
currDetector = digit->getDetector();
271278
}
272279
// fill the digit data into the corresponding TRAP chip
@@ -302,12 +309,14 @@ void TRDDPLTrapSimulatorTask::run(o2::framework::ProcessingContext& pc)
302309
mTrapSimulator[trapIdx].setData(digit->getChannel(), digit->getADC(), digitIndices[iDigit]);
303310
}
304311
// take care of the TRAPs for the last chamber
305-
processTRAPchips(currDetector, nTrackletsInTrigRec, trapTrackletsAccum, trackletMCLabels, digitMCLabels);
312+
processTRAPchips(currDetector, nTrackletsInTrigRec, trapTrackletsAccum, lblTracklets, lblDigitsPtr);
306313
trackletTriggerRecords[iTrig].setDataRange(trapTrackletsAccum.size() - nTrackletsInTrigRec, nTrackletsInTrigRec);
307314
}
308315

309316
LOG(info) << "Trap simulator found " << trapTrackletsAccum.size() << " tracklets from " << inputDigits.size() << " Digits.";
310-
LOG(info) << "In total " << trackletMCLabels.getNElements() << " MC labels are associated to the tracklets";
317+
if (mUseMC) {
318+
LOG(info) << "In total " << lblTracklets.getNElements() << " MC labels are associated to the tracklets";
319+
}
311320
if (mShowTrackletStats > 0) {
312321
std::chrono::duration<double> digitLoopTime = std::chrono::high_resolution_clock::now() - timeDigitLoopStart;
313322
LOG(info) << "Trap Simulator done ";
@@ -317,21 +326,35 @@ void TRDDPLTrapSimulatorTask::run(o2::framework::ProcessingContext& pc)
317326
}
318327
pc.outputs().snapshot(Output{"TRD", "TRACKLETS", 0, Lifetime::Timeframe}, trapTrackletsAccum);
319328
pc.outputs().snapshot(Output{"TRD", "TRKTRGRD", 0, Lifetime::Timeframe}, trackletTriggerRecords);
320-
pc.outputs().snapshot(Output{"TRD", "TRKLABELS", 0, Lifetime::Timeframe}, trackletMCLabels);
329+
if (mUseMC) {
330+
pc.outputs().snapshot(Output{"TRD", "TRKLABELS", 0, Lifetime::Timeframe}, lblTracklets);
331+
}
321332

322333
LOG(debug) << "TRD Trap Simulator Device exiting";
323334
pc.services().get<ControlService>().endOfStream();
324335
pc.services().get<ControlService>().readyToQuit(QuitRequest::Me);
325336
}
326337

327-
o2::framework::DataProcessorSpec getTRDTrapSimulatorSpec()
338+
o2::framework::DataProcessorSpec getTRDTrapSimulatorSpec(bool useMC)
328339
{
329-
return DataProcessorSpec{"TRAP", Inputs{InputSpec{"digitinput", "TRD", "DIGITS", 0}, InputSpec{"triggerrecords", "TRD", "TRGRDIG", 0}, InputSpec{"labelinput", "TRD", "LABELS", 0}},
340+
std::vector<InputSpec> inputs;
341+
std::vector<OutputSpec> outputs;
342+
343+
inputs.emplace_back("digitinput", "TRD", "DIGITS", 0);
344+
inputs.emplace_back("triggerrecords", "TRD", "TRGRDIG", 0);
345+
346+
outputs.emplace_back("TRD", "TRACKLETS", 0, Lifetime::Timeframe);
347+
outputs.emplace_back("TRD", "TRKTRGRD", 0, Lifetime::Timeframe);
348+
349+
if (useMC) {
350+
inputs.emplace_back("labelinput", "TRD", "LABELS", 0);
351+
outputs.emplace_back("TRD", "TRKLABELS", 0, Lifetime::Timeframe);
352+
}
330353

331-
Outputs{OutputSpec{"TRD", "TRACKLETS", 0, Lifetime::Timeframe}, // this is the 64 tracklet words
332-
OutputSpec{"TRD", "TRKTRGRD", 0, Lifetime::Timeframe},
333-
OutputSpec{"TRD", "TRKLABELS", 0, Lifetime::Timeframe}},
334-
AlgorithmSpec{adaptFromTask<TRDDPLTrapSimulatorTask>()},
354+
return DataProcessorSpec{"TRAP",
355+
inputs,
356+
outputs,
357+
AlgorithmSpec{adaptFromTask<TRDDPLTrapSimulatorTask>(useMC)},
335358
Options{
336359
{"show-trd-trackletstats", VariantType::Int, 1, {"Display the processing time of the tracklet processing in the TRAPs"}},
337360
{"trd-trapconfig", VariantType::String, "cf_pg-fpnp32_zs-s16-deh_tb30_trkl-b5n-fs1e24-ht200-qs0e24s24e23-pidlinear-pt100_ptrg.r5549", {"Name of the trap config from the CCDB default:cf_pg-fpnp32_zs-s16-deh_tb30_trkl-b5n-fs1e24-ht200-qs0e24s24e23-pidlinear-pt100_ptrg.r5549"}},

0 commit comments

Comments
 (0)