22#include <forward_list>
26#include <fairlogger/Logger.h>
50 float tau = mSimParam->getTimeResponseTauTRU();
51 float N = mSimParam->getTimeResponsePowerTRU();
53 mSmearEnergy = mSimParam->doSmearEnergy();
54 mSimulateTimeResponse = mSimParam->doSimulateTimeResponse();
66 if (mSimulateTimeResponse) {
69 RawResponse.SetParameters(1., 0., tau, N, 0.);
70 RawResponse.SetParameter(1, 425. / o2::emcal::constants::EMCAL_TIMESAMPLE);
75 RawResponse.SetParameter(1, mSimParam->getSignalDelay() / constants::EMCAL_TIMESAMPLE);
76 for (
int sample = 0; sample < constants::EMCAL_MAXTIMEBINS; sample++) {
77 mAmplitudeInTimeBins[sample] = RawResponse.Eval(sample);
78 LOG(info) <<
"DIG TRU init in DigitizerTRU: amplitudes[" << sample <<
"] = " << mAmplitudeInTimeBins[sample];
84 auto maxElement = std::max_element(mAmplitudeInTimeBins.begin(), mAmplitudeInTimeBins.end());
85 double rescalingFactor = *(maxElement - 1) + *maxElement + *(maxElement + 1) + *(maxElement + 2);
86 double normalisationTRU = mSimParam->getTimeResponseNormalisationTRU();
87 rescalingFactor /= normalisationTRU;
90 for (
int sample = 0; sample < constants::EMCAL_MAXTIMEBINS; sample++) {
91 mAmplitudeInTimeBins[sample] /= rescalingFactor;
92 LOG(info) <<
"DIG TRU init in DigitizerTRU after RESCALING: amplitudes[" << sample <<
"] = " << mAmplitudeInTimeBins[sample];
97 if (mEnableDebugStreaming) {
98 mDebugStream = std::make_unique<o2::utils::TreeStreamRedirector>(
"emcaldigitsDebugTRU.root",
"RECREATE");
109 double xx = (
x[0] - par[1] + tau) / tau;
116 signal = ped + par[0] * std::pow(xx,
n) * std::exp(
n * (1 - xx));
132 for (
auto vectorelement : processedSDigits) {
134 int& fastorID = std::get<0>(vectorelement);
135 auto& digit = std::get<1>(vectorelement);
137 int tower = digit.getTower();
141 if (mTempDigitVector.size() == 0) {
145 mDigits.
addDigits(fastorID, mTempDigitVector);
152 std::unordered_map<int, Digit> sdigitsFastOR;
153 std::vector<int> fastorIndicesFound;
154 for (
const auto& dig : sdigits) {
159 auto found = sdigitsFastOR.find(fastorIndex);
160 if (found != sdigitsFastOR.end()) {
162 Digit digitToSum((found->second).getTower(), dig.getAmplitude(), (found->second).getTimeStamp());
163 (found->second) += digitToSum;
166 fastorIndicesFound.emplace_back(fastorIndex);
167 sdigitsFastOR.emplace(fastorIndex, dig);
171 std::sort(fastorIndicesFound.begin(), fastorIndicesFound.end(), std::less<>());
173 for (
auto& elem : sdigitsFastOR) {
174 auto dig = elem.second;
175 int fastorIndex = elem.first;
181 for (
auto& elem : sdigitsFastOR) {
182 (elem.second).setTRU();
185 for (
auto& elem : sdigitsFastOR) {
186 auto dig = elem.second;
187 int fastorIndex = elem.first;
192 std::vector<std::tuple<int, Digit>> outputFastorSDigits;
193 std::for_each(fastorIndicesFound.begin(), fastorIndicesFound.end(), [&outputFastorSDigits, &sdigitsFastOR](
int fastorIndex) { outputFastorSDigits.emplace_back(fastorIndex, sdigitsFastOR[fastorIndex]); });
194 return outputFastorSDigits;
200 mTempDigitVector.clear();
208 if (energy < __DBL_EPSILON__) {
212 Double_t energies[15];
213 if (mSimulateTimeResponse) {
214 for (
int sample = 0; sample < mAmplitudeInTimeBins.size(); sample++) {
216 double val = energy * (mAmplitudeInTimeBins[sample]);
217 energies[sample] =
val;
218 double digitTime = mEventTimeOffset * constants::EMCAL_TIMESAMPLE;
221 mTempDigitVector.push_back(digit);
225 Digit digit(tower, energy,
smearTime(sDigit.getTimeStamp(), energy));
227 mTempDigitVector.push_back(digit);
230 if (mEnableDebugStreaming) {
231 double timeStamp = sDigit.getTimeStamp();
232 (*mDebugStream).GetFile()->cd();
233 (*mDebugStream) <<
"DigitsTimeSamples"
235 <<
"Time=" << timeStamp
236 <<
"DigitEnergy=" << energy
237 <<
"Sample0=" << energies[0]
238 <<
"Sample1=" << energies[1]
239 <<
"Sample2=" << energies[2]
240 <<
"Sample3=" << energies[3]
241 <<
"Sample4=" << energies[4]
242 <<
"Sample5=" << energies[5]
243 <<
"Sample6=" << energies[6]
244 <<
"Sample7=" << energies[7]
245 <<
"Sample8=" << energies[8]
246 <<
"Sample9=" << energies[9]
247 <<
"Sample10=" << energies[10]
248 <<
"Sample11=" << energies[11]
249 <<
"Sample12=" << energies[12]
250 <<
"Sample13=" << energies[13]
251 <<
"Sample14=" << energies[14]
260 Double_t fluct = (energy * mSimParam->getMeanPhotonElectron()) / mSimParam->getGainFluctuations();
261 TRandom3 mRandomGenerator(std::chrono::high_resolution_clock::now().time_since_epoch().
count());
262 energy *= mRandomGenerator.Poisson(fluct) / fluct;
269 TRandom3 mRandomGenerator(std::chrono::high_resolution_clock::now().time_since_epoch().
count());
270 return mRandomGenerator.Gaus(
time + mSimParam->getSignalDelay(), mSimParam->getTimeResolution(energy));
284 mEventTimeOffset = 0;
286 if (mEnableDebugStreaming) {
290 std::vector<o2::emcal::EMCALTriggerInputs> TriggerInputs;
291 if (TriggerInputsAll.size() != mPreviousTriggerSize) {
292 mWasTriggerFound =
true;
293 mPreviousTriggerSize = TriggerInputsAll.size();
295 mWasTriggerFound =
false;
297 if (TriggerInputsAll.size() > 0 && mWasTriggerFound ==
true) {
298 TriggerInputs.push_back(TriggerInputsAll.back());
300 std::vector<o2::emcal::EMCALTriggerInputsPatch> TriggerInputsPatches;
301 if (TriggerInputsPatchesAll.size() > 0 && mWasTriggerFound ==
true) {
302 TriggerInputsPatches.push_back(TriggerInputsPatchesAll.back());
304 int nIter = TriggerInputs.size();
307 for (
auto& trigger : TriggerInputs) {
308 auto InteractionRecordData = trigger.mInterRecord;
309 auto bc = InteractionRecordData.bc;
310 auto orbit = InteractionRecordData.orbit;
311 for (
auto& fastor : trigger.mLastTimesumAllFastOrs) {
312 auto WhichTRU = std::get<0>(fastor);
313 auto WhichFastOr = std::get<1>(fastor);
314 auto FastOrAmp = std::get<2>(fastor);
315 (*mDebugStream).GetFile()->cd();
316 (*mDebugStream) <<
"L0Timesums"
319 <<
"WhichTRU=" << WhichTRU
320 <<
"WhichFastOr=" << WhichFastOr
321 <<
"FastOrAmp=" << FastOrAmp
352 patchesFromAllTRUs.clear();
363 for (
int j = 0;
j < 3;
j++) {
364 patchesFromAllTRUs.push_back(FullAside);
366 for (
int j = 0;
j < 3;
j++) {
367 patchesFromAllTRUs.push_back(FullCside);
369 for (
int j = 0;
j < 3;
j++) {
370 patchesFromAllTRUs.push_back(FullAside);
372 for (
int j = 0;
j < 3;
j++) {
373 patchesFromAllTRUs.push_back(FullCside);
375 for (
int j = 0;
j < 3;
j++) {
376 patchesFromAllTRUs.push_back(FullAside);
378 for (
int j = 0;
j < 3;
j++) {
379 patchesFromAllTRUs.push_back(FullCside);
381 for (
int j = 0;
j < 3;
j++) {
382 patchesFromAllTRUs.push_back(FullAside);
384 for (
int j = 0;
j < 3;
j++) {
385 patchesFromAllTRUs.push_back(FullCside);
387 for (
int j = 0;
j < 3;
j++) {
388 patchesFromAllTRUs.push_back(FullAside);
390 for (
int j = 0;
j < 3;
j++) {
391 patchesFromAllTRUs.push_back(FullCside);
393 patchesFromAllTRUs.push_back(ThirdAside);
394 patchesFromAllTRUs.push_back(ThirdCside);
395 for (
int j = 0;
j < 3;
j++) {
396 patchesFromAllTRUs.push_back(FullAside);
398 for (
int j = 0;
j < 3;
j++) {
399 patchesFromAllTRUs.push_back(FullCside);
401 for (
int j = 0;
j < 3;
j++) {
402 patchesFromAllTRUs.push_back(FullAside);
404 for (
int j = 0;
j < 3;
j++) {
405 patchesFromAllTRUs.push_back(FullCside);
407 for (
int j = 0;
j < 3;
j++) {
408 patchesFromAllTRUs.push_back(FullAside);
410 for (
int j = 0;
j < 3;
j++) {
411 patchesFromAllTRUs.push_back(FullCside);
413 patchesFromAllTRUs.push_back(ThirdAside);
414 patchesFromAllTRUs.push_back(ThirdCside);
416 while (patchesFromAllTRUs[30].mPatchIDSeedFastOrIDs.size() > 69) {
417 patchesFromAllTRUs[30].mPatchIDSeedFastOrIDs.pop_back();
418 patchesFromAllTRUs[30].mIndexMapPatch.pop_back();
420 while (patchesFromAllTRUs[31].mPatchIDSeedFastOrIDs.size() > 69) {
421 patchesFromAllTRUs[31].mPatchIDSeedFastOrIDs.pop_back();
422 patchesFromAllTRUs[31].mIndexMapPatch.pop_back();
424 while (patchesFromAllTRUs[50].mPatchIDSeedFastOrIDs.size() > 69) {
425 patchesFromAllTRUs[50].mPatchIDSeedFastOrIDs.pop_back();
426 patchesFromAllTRUs[50].mIndexMapPatch.pop_back();
428 while (patchesFromAllTRUs[51].mPatchIDSeedFastOrIDs.size() > 69) {
429 patchesFromAllTRUs[51].mPatchIDSeedFastOrIDs.pop_back();
430 patchesFromAllTRUs[51].mIndexMapPatch.pop_back();
447 if ((
id > 31 && detector == kEMCAL) || (
id > 13 && detector == kDCAL) ||
id < 0) {
451 if (detector == kEMCAL) {
453 }
else if (detector == kDCAL) {
454 return 32 + ((
int)(
id / 4) * 6) + ((
id % 4 < 2) ? (
id % 4) : (
id % 4 + 2));
462 return mask * 16 + bitnumber;
464 const int kChannelMap[6][16] = {{8, 9, 10, 11, 20, 21, 22, 23, 32, 33, 34, 35, 44, 45, 46, 47},
465 {56, 57, 58, 59, 68, 69, 70, 71, 80, 81, 82, 83, 92, 93, 94, 95},
466 {4, 5, 6, 7, 16, 17, 18, 19, 28, 29, 30, 31, 40, 41, 42, 43},
467 {52, 53, 54, 55, 64, 65, 66, 67, 76, 77, 78, 79, 88, 89, 90, 91},
468 {0, 1, 2, 3, 12, 13, 14, 15, 24, 25, 26, 27, 36, 37, 38, 39},
469 {48, 49, 50, 51, 60, 61, 62, 63, 72, 73, 74, 75, 84, 85, 86, 87}};
470 return kChannelMap[
mask][bitnumber];
476 std::vector<int> maskedfastors;
478 for (Int_t
i = 0;
i < 46;
i++) {
479 int localtru = itru % 32, detector = itru >= 32 ? 1 : 0,
481 bool onethirdsm = ((globaltru >= 30 && globaltru < 32) || (globaltru >= 50 && globaltru < 52));
482 for (
int ipos = 0; ipos < 6; ipos++) {
484 std::bitset<16> bitsregmask(regmask);
485 for (
int ibit = 0; ibit < 16; ibit++) {
486 if (bitsregmask.test(ibit)) {
489 maskedfastors.push_back(absfastor);
495 return maskedfastors;
501 LOG(info) <<
"======================================";
502 LOG(info) <<
"== PRINT MASK COMPUTED IN DIGITIZER ==";
504 for (
auto fastOr : maskedFastOrs) {
505 LOG(info) <<
"fastOr masked (number, ID) = (" <<
counter <<
", " << fastOr;
ClassImp(o2::emcal::DigitizerTRU)
static const SimParam & Instance()
EMCAL digit implementation.
Double_t getAmplitude() const
EMCAL DigitizerTRU, digitizes with the help of a temporary description based upon a pol9*Heavyside.
int GetChannelForMaskRun2(int mask, int bitnumber, bool onethirdsm)
std::vector< int > GetAbsFastORIndexFromMask()
double smearEnergy(double energy)
void setEventTime(o2::InteractionTimeRecord record)
int GetTRUIndexFromSTUIndex(Int_t id, Int_t detector)
Utility functions obtained from QC for EMC.
void finish()
This is for the readout window that was interrupted by the end of the run.
void setMaskedFastOrsInLZERO()
Sets the masked fastOrs from the CCDB in the LZERO.
void sampleSDigit(const Digit &sdigit)
std::vector< std::tuple< int, Digit > > makeAnaloguesFastorSums(const gsl::span< const Digit > sdigits)
static double rawResponseFunction(double *x, double *par)
raw pointers used here to allow interface with TF1
double smearTime(double time, double energy)
void endDebugStream()
Close the TreeStreamer to make the file readable.
void setPatches()
Sets patches for the current geometry.
bool isDebugMode()
Getter for debug mode.
void process(const gsl::span< const Digit > summableDigits)
Steer conversion of hits to digits.
void printMaskedFastOrsInLZERO()
void addDigits(unsigned int towerID, std::vector< o2::emcal::Digit > &digList)
void finish()
This is for the readout window that was interrupted by the end of the run.
void clear()
clear the container
void reserve(int eventTimeBin)
void fillOutputContainer(bool isEndOfTimeFrame, InteractionRecord &nextInteractionRecord, std::vector< TRUElectronics > &patchesFromAllTRUs, LZEROElectronics &LZERO)
o2::emcal::TriggerTRUDCS getTRUDCS(Int_t iTRU) const
EMCAL simulation hit information.
void setMaskedFastOrs(std::vector< int > const &maskedfastors)
Sets the masked fastOrs from the CCDB in the LZERO.
void setGeometry(o2::emcal::Geometry *gm)
Sets geometry for trigger mapping.
void printMaskedFastOrs()
void init()
Initialize the L0 electronics.
const std::vector< EMCALTriggerInputsPatch > & getTriggerInputsPatches() const
Getter for the trigger inputs per patches found by the LZERO algorithm.
const std::vector< EMCALTriggerInputs > & getTriggerInputs() const
Getter for the trigger inputs found by the LZERO algorithm.
Trigger mapping starting from Run2.
IndexFastOR getAbsFastORIndexFromIndexInTRU(IndexTRU truIndex, IndexFastOR fastorIndexTRU) const
Get the absolute index of the FastOr from the index in the TRU.
IndexFastOR getAbsFastORIndexFromCellIndex(IndexCell cellIndex) const
Get the absolute FastOR index of the module containing a given cell.
std::tuple< IndexTRU, IndexFastOR > getTRUFromAbsFastORIndex(IndexFastOR fastOrAbsID) const
Get the TRU index and FastOR index in TRU from the absolute FastOR ID.
uint32_t getMaskReg(int pos) const
TRUElectronics creator, based on the TRUElectronics.
void init()
Initialise internal members.
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"