Skip to content

Commit 1cf2d68

Browse files
authored
Merge b5b3522 into sapling-pr-archive-ktf
2 parents 6108293 + b5b3522 commit 1cf2d68

File tree

13 files changed

+360
-54
lines changed

13 files changed

+360
-54
lines changed

Detectors/CTP/simulation/src/Digitizer.cxx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ std::vector<CTPDigit> Digitizer::process(const gsl::span<o2::ctp::CTPInputDigit>
4343
std::vector<CTPDigit> digits;
4444
for (auto const& hits : predigits) {
4545
std::bitset<CTP_NINPUTS> inpmaskcoll = 0;
46+
auto currentIR = hits.first;
4647
for (auto const inp : hits.second) {
4748
switch (inp->detector) {
4849
case o2::detectors::DetID::FT0: {
@@ -81,17 +82,17 @@ std::vector<CTPDigit> Digitizer::process(const gsl::span<o2::ctp::CTPInputDigit>
8182
std::bitset<CTP_NINPUTS> emcMBaccept;
8283
emcMBaccept.set(CTP_NINPUTS - 1, 1);
8384
inpmaskcoll |= emcMBaccept;
84-
} else {
85+
} // else { // needs to be done always, remove else
8586
for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::EMC]) {
8687
uint64_t mask = inpmaskdebug & detInputName2Mask[ctpinp.name];
8788
// uint64_t mask = (inp->inputsMask).to_ullong() & detInputName2Mask[ctpinp.name];
8889
if (mask) {
8990
inpmaskcoll |= std::bitset<CTP_NINPUTS>(ctpinp.inputMask);
9091
}
9192
}
92-
}
93-
LOG(info) << "EMC input mask:" << inpmaskcoll;
94-
break;
93+
// }
94+
// LOG(info) << "EMC input mask:" << inpmaskcoll << " with IR = " << currentIR.bc << ", orbit = " << currentIR.orbit;
95+
break;
9596
}
9697
case o2::detectors::DetID::PHS: {
9798
for (auto const& ctpinp : det2ctpinp[o2::detectors::DetID::PHS]) {
@@ -132,7 +133,8 @@ std::vector<CTPDigit> Digitizer::process(const gsl::span<o2::ctp::CTPInputDigit>
132133
data.CTPInputMask = inpmaskcoll;
133134
data.CTPClassMask = classmask;
134135
digits.emplace_back(data);
135-
LOG(info) << "Trigger-Event " << data.intRecord.bc << " " << data.intRecord.orbit << " Input mask:" << inpmaskcoll;
136+
LOG(info) << "Trigger-Event " << data.intRecord.bc << " " << data.intRecord.orbit << " Input mask:" << inpmaskcoll << " with IR = " << data.intRecord.bc << ", orbit = " << data.intRecord.orbit;
137+
// LOG(info) << "Trigger-Event " << data.intRecord.bc << " " << data.intRecord.orbit << " Class mask:" << data.CTPClassMask << " with IR = " << data.intRecord.bc << ", orbit = " << data.intRecord.orbit;
136138
}
137139
}
138140
return std::move(digits);
@@ -160,12 +162,12 @@ void Digitizer::calculateClassMask(const std::bitset<CTP_NINPUTS> ctpinpmask, st
160162
classmask |= tcl.classMask;
161163
LOG(info) << "adding MBA:" << tcl.name;
162164
}
163-
} else {
165+
} // else {
164166
// EMCAL rare triggers - physical trigger input
165167
// class identification can be handled like in the case of the other
166168
// classes as EMCAL trigger input is required
167169
classmask |= tcl.classMask;
168-
}
170+
// }
169171
}
170172
} else {
171173
if ((ctpinpmask.to_ullong() & tcl.descriptor->getInputsMask()) == tcl.descriptor->getInputsMask()) {

Detectors/EMCAL/simulation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ o2_add_library(EMCALSimulation
1313
SOURCES src/Detector.cxx src/Digitizer.cxx src/DigitizerTRU.cxx src/SDigitizer.cxx
1414
src/DigitsWriteoutBuffer.cxx src/DigitsWriteoutBufferTRU.cxx src/LZEROElectronics.cxx src/TRUElectronics.cxx src/DigitsVectorStream.cxx src/SpaceFrame.cxx src/SimParam.cxx
1515
src/LabeledDigit.cxx src/RawWriter.cxx
16-
PUBLIC_LINK_LIBRARIES ROOT::TreePlayer O2::EMCALBase O2::DetectorsBase O2::SimConfig O2::SimulationDataFormat O2::Headers O2::DetectorsRaw O2::EMCALReconstruction O2::DataFormatsCTP)
16+
PUBLIC_LINK_LIBRARIES ROOT::TreePlayer O2::EMCALBase O2::DetectorsBase O2::SimConfig O2::SimulationDataFormat O2::Headers O2::DetectorsRaw O2::EMCALReconstruction O2::EMCALCalib O2::DataFormatsCTP)
1717

1818
o2_target_root_dictionary(EMCALSimulation
1919
HEADERS include/EMCALSimulation/Detector.h

Detectors/EMCAL/simulation/include/EMCALSimulation/DigitizerTRU.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "SimulationDataFormat/MCTruthContainer.h"
3232
#include "DataFormatsEMCAL/TriggerRecord.h"
3333
#include "CommonUtils/TreeStreamRedirector.h"
34+
#include "EMCALCalib/FeeDCS.h"
3435

3536
namespace o2
3637
{
@@ -40,6 +41,7 @@ class TreeStreamRedirector;
4041
}
4142
namespace emcal
4243
{
44+
class FeeDCS;
4345

4446
/// \class DigitizerTRU
4547
/// \brief EMCAL DigitizerTRU, digitizes with the help of a temporary description based upon a pol9*Heavyside
@@ -79,6 +81,13 @@ class DigitizerTRU
7981
/// Sets geometry for trigger mapping
8082
void setGeometry(o2::emcal::Geometry* gm) { mGeometry = gm; }
8183

84+
/// Sets FEE DCS for the masking of the fastOrs
85+
void setFEE(o2::emcal::FeeDCS* fees) { mFeeDCS = fees; }
86+
87+
/// Sets the masked fastOrs from the CCDB in the LZERO
88+
void setMaskedFastOrsInLZERO();
89+
void printMaskedFastOrsInLZERO();
90+
8291
void setWindowStartTime(int time) { mTimeWindowStart = time; }
8392
void setDebugStreaming(bool doStreaming) { mEnableDebugStreaming = doStreaming; }
8493

@@ -101,12 +110,20 @@ class DigitizerTRU
101110
/// Getter for debug mode
102111
bool isDebugMode() { return mEnableDebugStreaming; }
103112

113+
/// Getter for triggers
114+
const std::vector<EMCALTriggerInputs>& getTriggerInputs() { return LZERO.getTriggerInputs(); }
115+
104116
/// Getter for patches
105117
std::vector<TRUElectronics> getPatchesVector() { return patchesFromAllTRUs; }
106118

107119
/// raw pointers used here to allow interface with TF1
108120
static double rawResponseFunction(double* x, double* par);
109121

122+
/// Utility functions obtained from QC for EMC
123+
int GetTRUIndexFromSTUIndex(Int_t id, Int_t detector);
124+
int GetChannelForMaskRun2(int mask, int bitnumber, bool onethirdsm);
125+
std::vector<int> GetAbsFastORIndexFromMask();
126+
110127
private:
111128
short mEventTimeOffset = 0; ///< event time difference from trigger time (in number of bins)
112129
bool mSmearEnergy = true; ///< do time and energy smearing
@@ -134,6 +151,7 @@ class DigitizerTRU
134151
std::unique_ptr<o2::utils::TreeStreamRedirector> mDebugStream = nullptr;
135152
// std::unique_ptr<o2::utils::TreeStreamRedirector> mDebugStreamPatch = nullptr;
136153
bool mEnableDebugStreaming = false;
154+
o2::emcal::FeeDCS* mFeeDCS; ///< EMCAL FEE DCS
137155

138156
ClassDefNV(DigitizerTRU, 1);
139157
};

Detectors/EMCAL/simulation/include/EMCALSimulation/LZEROElectronics.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace emcal
3939
/// \param mLastTimesumAllFastOrs Vector of tuples with TRU ID, FastOrID with STU indexing, and their last Timesums
4040
struct EMCALTriggerInputs {
4141
o2::InteractionRecord mInterRecord; ///< Last known interaction record
42+
int mTriggeredTRU; ///< Trigger TRU
43+
std::vector<int> mTriggeredPatches; ///< Trigger patches, in local STU indexing
4244
std::vector<std::tuple<int, int, double>> mLastTimesumAllFastOrs; ///< TRU ID, FastOrID with STU indexing, and its last Timesum
4345
};
4446

@@ -76,6 +78,10 @@ class LZEROElectronics
7678
/// Sets geometry for trigger mapping
7779
void setGeometry(o2::emcal::Geometry* gm) { mGeometry = gm; }
7880

81+
/// Sets the masked fastOrs from the CCDB in the LZERO
82+
void setMaskedFastOrs(std::vector<int> const& maskedfastors) { mMaskedFastOrs = maskedfastors; }
83+
void printMaskedFastOrs();
84+
7985
/// Set Threshold for LZERO algorithm
8086
/// \param threshold LZERO algorithm threshold
8187
void setThreshold(double threshold) { mThreshold = threshold; }
@@ -104,7 +110,7 @@ class LZEROElectronics
104110

105111
/// Getter for the pattern of peaks found by the LZERO algorithm
106112
/// \param p TRUElectronics object
107-
const std::vector<int>& getFiredPatches(TRUElectronics& p) const
113+
const std::vector<int>& getFiredPatches(TRUElectronics const& p) const
108114
{
109115
return p.mFiredPatches;
110116
}
@@ -131,6 +137,7 @@ class LZEROElectronics
131137
// const SimParam* mSimParam = nullptr; ///< SimParam object
132138
std::vector<EMCALTriggerInputs> mTriggers; ///< Triggers to be sent out
133139
std::vector<EMCALTriggerInputsPatch> mTriggersPatch; ///< Triggers to be sent out
140+
std::vector<int> mMaskedFastOrs; ///< Masked fastOrs from CCDB
134141
bool mSimulateNoiseDigits = true; ///< simulate noise digits
135142
// TriggerMappingV2* mTriggerMap = nullptr; ///< Trigger map to properly assign an absolute FastOr to TRU FastOr
136143
Geometry* mGeometry = nullptr; ///< EMCAL geometry

Detectors/EMCAL/simulation/src/DigitizerTRU.cxx

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "EMCALSimulation/DigitizerTRU.h"
1313
#include "EMCALSimulation/SimParam.h"
1414
#include "EMCALSimulation/DigitsWriteoutBuffer.h"
15+
#include "EMCALCalib/FeeDCS.h"
1516
#include "DataFormatsEMCAL/Digit.h"
1617
#include "EMCALBase/Hit.h"
1718
#include "MathUtils/Cartesian.h"
@@ -436,4 +437,78 @@ void DigitizerTRU::finish()
436437
if (isDebugMode() == true) {
437438
endDebugStream();
438439
}
439-
}
440+
}
441+
//______________________________________________________________________
442+
int DigitizerTRU::GetTRUIndexFromSTUIndex(Int_t id, Int_t detector)
443+
{
444+
Int_t kEMCAL = 0;
445+
Int_t kDCAL = 1;
446+
447+
if ((id > 31 && detector == kEMCAL) || (id > 13 && detector == kDCAL) || id < 0) {
448+
return -1; // Error Condition
449+
}
450+
451+
if (detector == kEMCAL) {
452+
return id;
453+
} else if (detector == kDCAL) {
454+
return 32 + ((int)(id / 4) * 6) + ((id % 4 < 2) ? (id % 4) : (id % 4 + 2));
455+
}
456+
return -1;
457+
}
458+
//______________________________________________________________________
459+
int DigitizerTRU::GetChannelForMaskRun2(int mask, int bitnumber, bool onethirdsm)
460+
{
461+
if (onethirdsm) {
462+
return mask * 16 + bitnumber;
463+
}
464+
const int kChannelMap[6][16] = {{8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47}, // Channels in mask0
465+
{56, 57, 58, 59, 68, 69, 70, 71, 80, 81, 82, 83, 92, 93, 94, 95}, // Channels in mask1
466+
{4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43}, // Channels in mask2
467+
{52, 53, 54, 55, 64, 65, 66, 67, 76, 77, 78, 79, 88, 89, 90, 91}, // Channels in mask3
468+
{0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39}, // Channels in mask4
469+
{48, 49, 50, 51, 60, 61, 62, 63, 72, 73, 74, 75, 84, 85, 86, 87}}; // Channels in mask5
470+
return kChannelMap[mask][bitnumber];
471+
}
472+
//______________________________________________________________________
473+
std::vector<int> DigitizerTRU::GetAbsFastORIndexFromMask()
474+
{
475+
TriggerMappingV2 mTriggerMap(mGeometry);
476+
std::vector<int> maskedfastors;
477+
int itru = 0;
478+
for (Int_t i = 0; i < 46; i++) {
479+
int localtru = itru % 32, detector = itru >= 32 ? 1 : 0,
480+
globaltru = GetTRUIndexFromSTUIndex(localtru, detector);
481+
bool onethirdsm = ((globaltru >= 30 && globaltru < 32) || (globaltru >= 50 && globaltru < 52));
482+
for (int ipos = 0; ipos < 6; ipos++) {
483+
auto regmask = mFeeDCS->getTRUDCS(i).getMaskReg(ipos);
484+
std::bitset<16> bitsregmask(regmask);
485+
for (int ibit = 0; ibit < 16; ibit++) {
486+
if (bitsregmask.test(ibit)) {
487+
auto channel = GetChannelForMaskRun2(ipos, ibit, onethirdsm);
488+
int absfastor = mTriggerMap.getAbsFastORIndexFromIndexInTRU(globaltru, channel);
489+
maskedfastors.push_back(absfastor);
490+
}
491+
}
492+
}
493+
itru++;
494+
}
495+
return maskedfastors;
496+
}
497+
//______________________________________________________________________
498+
void DigitizerTRU::setMaskedFastOrsInLZERO()
499+
{
500+
auto maskedFastOrs = GetAbsFastORIndexFromMask();
501+
LOG(info) << "======================================";
502+
LOG(info) << "== PRINT MASK COMPUTED IN DIGITIZER ==";
503+
int counter = 0;
504+
for (auto fastOr : maskedFastOrs) {
505+
LOG(info) << "fastOr masked (number, ID) = (" << counter << ", " << fastOr;
506+
counter += 1;
507+
}
508+
LZERO.setMaskedFastOrs(maskedFastOrs);
509+
}
510+
//______________________________________________________________________
511+
void DigitizerTRU::printMaskedFastOrsInLZERO()
512+
{
513+
LZERO.printMaskedFastOrs();
514+
}

Detectors/EMCAL/simulation/src/DigitsWriteoutBufferTRU.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void DigitsWriteoutBufferTRU::fillOutputContainer(bool isEndOfTimeFrame, Interac
5656
// LZERO.updatePatchesADC(patches);
5757
// LZERO.peakFinderOnAllPatches(patches);
5858
// }
59+
LOG(debug) << "DIG TRU fillOutputContainer in DigitsWriteoutBufferTRU: LOW IR";
5960

6061
mCurrentInteractionRecord = nextInteractionRecord;
6162
clear();
@@ -94,6 +95,8 @@ void DigitsWriteoutBufferTRU::fillOutputContainer(bool isEndOfTimeFrame, Interac
9495
}
9596
}
9697
reserve(15);
98+
99+
LOG(debug) << "DIG TRU fillOutputContainer in DigitsWriteoutBufferTRU: HIGH IR";
97100
}
98101
}
99102
//________________________________________________________

Detectors/EMCAL/simulation/src/LZEROElectronics.cxx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,11 @@ void LZEROElectronics::fill(const std::deque<o2::emcal::DigitTimebinTRU>& digitl
113113
// At the end of the loop run the peak finder
114114
// Ship to LONEElectronics in case a peak is found
115115
// Entire logic limited to timebin by timebin -> effectively implementing time scan
116-
117116
counterDigitTimeBin++;
118117

119118
for (auto& [fastor, digitsList] : *digitsTimeBin.mDigitMap) {
120119
// Digit loop
121120
// The peak finding algorithm is run after getting out of the loop!
122-
123121
if (digitsList.size() == 0) {
124122
continue;
125123
}
@@ -154,7 +152,10 @@ void LZEROElectronics::fill(const std::deque<o2::emcal::DigitTimebinTRU>& digitl
154152
auto whichFastOr = std::get<1>(mTriggerMap.convertFastORIndexTRUtoSTU(whichTRU, whichFastOrTRU));
155153
auto& patchTRU = patchesFromAllTRUs[whichTRU];
156154
auto& fastOrPatchTRU = patchTRU.mFastOrs[whichFastOr];
157-
fastOrPatchTRU.updateADC(summedDigit.getAmplitudeADC());
155+
// fastOrPatchTRU.updateADC(summedDigit.getAmplitudeADC());
156+
if (std::find(mMaskedFastOrs.begin(), mMaskedFastOrs.end(), fastor) != mMaskedFastOrs.end()) {
157+
fastOrPatchTRU.updateADC(summedDigit.getAmplitudeADC());
158+
}
158159

159160
digIndex++;
160161
}
@@ -172,13 +173,21 @@ void LZEROElectronics::fill(const std::deque<o2::emcal::DigitTimebinTRU>& digitl
172173
// It accounts for the difference in times between L0a, L0b, and then there will be a L1 and L1b delay
173174
// There is 1BC uncertainty on the trigger readout due to steps in the interaction between CTP and detector simulations
174175
bool foundPeak = false;
176+
int counterWhichTRU = 0;
177+
int triggeredTRU = -1;
178+
std::vector<int> triggeredPatches;
175179
for (auto& patches : patchesFromAllTRUs) {
176180
updatePatchesADC(patches);
177181
bool foundPeakCurrentTRU = peakFinderOnAllPatches(patches);
178182
auto firedPatches = getFiredPatches(patches);
183+
if (foundPeakCurrentTRU == true && foundPeak == false) {
184+
triggeredTRU = counterWhichTRU;
185+
triggeredPatches = firedPatches;
186+
}
179187
if (foundPeakCurrentTRU) {
180188
foundPeak = true;
181189
}
190+
counterWhichTRU += 1;
182191
}
183192

184193
if (foundPeak == true) {
@@ -187,6 +196,8 @@ void LZEROElectronics::fill(const std::deque<o2::emcal::DigitTimebinTRU>& digitl
187196
EMCALTriggerInputs TriggerInputsForL1;
188197
if (foundPeak) {
189198
TriggerInputsForL1.mInterRecord = record;
199+
TriggerInputsForL1.mTriggeredTRU = triggeredTRU;
200+
TriggerInputsForL1.mTriggeredPatches = triggeredPatches;
190201
int whichTRU = 0;
191202
for (auto& patches : patchesFromAllTRUs) {
192203
int whichFastOr = 0;
@@ -228,3 +239,14 @@ void LZEROElectronics::fill(const std::deque<o2::emcal::DigitTimebinTRU>& digitl
228239
}
229240
}
230241
}
242+
//________________________________________________________
243+
void LZEROElectronics::printMaskedFastOrs()
244+
{
245+
LOG(info) << "===============================";
246+
LOG(info) << "== PRINT MASK SAVED IN LZERO ==";
247+
int counter = 0;
248+
for (auto fastOr : mMaskedFastOrs) {
249+
LOG(info) << "fastOr masked (number, ID) = (" << counter << ", " << fastOr;
250+
counter += 1;
251+
}
252+
}

Detectors/EMCAL/workflow/include/EMCALWorkflow/EMCALDigitizerSpec.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "EMCALSimulation/SDigitizer.h"
2424
#include "SimulationDataFormat/MCTruthContainer.h"
2525
#include <DetectorsBase/BaseDPLDigitizer.h>
26+
#include "EMCALSimulation/DigitizerTRU.h"
2627

2728
class TChain;
2829

@@ -90,6 +91,10 @@ class DigitizerSpec final : public o2::base::BaseDPLDigitizer, public o2::framew
9091
std::vector<TChain*> mSimChains;
9192
o2::ctp::CTPConfiguration* mCTPConfig; ///< CTP configuration
9293
o2::steer::MCKinematicsReader* mcReader; ///< reader to access MC collision information
94+
95+
DigitizerTRU mDigitizerTRU; ///< Digitizer object TRU
96+
o2::emcal::SDigitizer mSumDigitizerTRU; ///< Summed digitizer TRU
97+
bool mRunDigitizerTRU = true; ///< Run Digitizer TRU?
9398
};
9499

95100
/// \brief Create new digitizer spec

0 commit comments

Comments
 (0)