Skip to content

Commit a8520d5

Browse files
authored
[EMCAL-539,EMCAL-696,EMCAL-697] First version of the L0 trigger implementation
Added: - TRU time response - Pileup simulation at trigger level - Peak finder and L0 algorithm Simulation not yet implemented in the EMCALDigitizerSPEC Additional changes: * Suppress DigitizerTRU verbosity, moving forward declaration DigitTimebin<template> * SimParam handles trigger parameters
1 parent 9880dbb commit a8520d5

16 files changed

Lines changed: 1701 additions & 13 deletions

DataFormats/Detectors/EMCAL/src/Digit.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ Int_t Digit::getAmplitudeADC(ChannelType_t ctype) const
8686
case ChannelType_t::TRU: {
8787
int ampADC = std::floor(mAmplitudeGeV / constants::EMCAL_TRU_ADCENERGY);
8888
// truncate energy in case dynamic range is saturated
89-
if (ampADC >= constants::EMCAL_TRU_ADCENERGY) {
90-
return constants::EMCAL_TRU_ADCENERGY;
89+
if (ampADC >= constants::MAX_RANGE_ADC) {
90+
return constants::MAX_RANGE_ADC;
9191
}
9292
return ampADC;
9393
};

Detectors/EMCAL/simulation/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010
# or submit itself to any jurisdiction.
1111

1212
o2_add_library(EMCALSimulation
13-
SOURCES src/Detector.cxx src/Digitizer.cxx src/SDigitizer.cxx
14-
src/DigitsWriteoutBuffer.cxx src/DigitsVectorStream.cxx src/SpaceFrame.cxx src/SimParam.cxx
13+
SOURCES src/Detector.cxx src/Digitizer.cxx src/DigitizerTRU.cxx src/SDigitizer.cxx
14+
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
1616
PUBLIC_LINK_LIBRARIES ROOT::TreePlayer O2::EMCALBase O2::DetectorsBase O2::SimConfig O2::SimulationDataFormat O2::Headers O2::DetectorsRaw O2::EMCALReconstruction O2::DataFormatsCTP)
1717

1818
o2_target_root_dictionary(EMCALSimulation
1919
HEADERS include/EMCALSimulation/Detector.h
2020
include/EMCALSimulation/Digitizer.h
21+
include/EMCALSimulation/DigitizerTRU.h
2122
include/EMCALSimulation/SDigitizer.h
2223
include/EMCALSimulation/DigitsWriteoutBuffer.h
24+
include/EMCALSimulation/DigitsWriteoutBufferTRU.h
25+
include/EMCALSimulation/LZEROElectronics.h
26+
include/EMCALSimulation/TRUElectronics.h
27+
include/EMCALSimulation/DigitTimebin.h
2328
include/EMCALSimulation/DigitsVectorStream.h
2429
include/EMCALSimulation/RawWriter.h
2530
include/EMCALSimulation/SpaceFrame.h
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file DigitTimebin.h
13+
/// \brief EMCAL DigitTimebin for the DigitsWriteoutBuffer and DigitsWriteoutBufferTRU
14+
#ifndef ALICEO2_EMCAL_DIGITTIMEBIN_H
15+
#define ALICEO2_EMCAL_DIGITTIMEBIN_H
16+
17+
#include "DataFormatsEMCAL/Digit.h"
18+
#include "EMCALSimulation/LabeledDigit.h"
19+
#include "CommonDataFormat/InteractionRecord.h"
20+
21+
namespace o2
22+
{
23+
24+
namespace emcal
25+
{
26+
27+
template <class DigitTemplate>
28+
struct DigitTimebinBase;
29+
30+
/// \struct DigitTimebinBase
31+
/// \brief DigitTimebinBase templated, used for the DigitsWriteoutBuffer and DigitsWriteoutBufferTRU
32+
/// \ingroup EMCALsimulation
33+
/// \author Markus Fasel, ORNL
34+
/// \author Hadi Hassan, ORNL
35+
/// \author Simone Ragoni, Creighton U.
36+
/// \date 16/12/2022
37+
///
38+
/// \param mRecordMode record mode
39+
/// \param mEndWindow end window
40+
/// \param mTriggerColl trigger collision
41+
/// \param mInterRecord InteractionRecord
42+
/// \param mDigitMap map of the digits, templated
43+
template <class DigitTemplate>
44+
struct DigitTimebinBase {
45+
bool mRecordMode = false;
46+
bool mEndWindow = false;
47+
bool mTriggerColl = false;
48+
std::optional<o2::InteractionRecord> mInterRecord;
49+
std::shared_ptr<std::unordered_map<int, std::list<DigitTemplate>>> mDigitMap = std::make_shared<std::unordered_map<int, std::list<DigitTemplate>>>();
50+
ClassDefNV(DigitTimebinBase, 1);
51+
};
52+
53+
/// \brief DigitTimebin is DigitTimebinBase<LabeledDigit>
54+
using DigitTimebin = DigitTimebinBase<LabeledDigit>;
55+
using DigitTimebinTRU = DigitTimebinBase<Digit>;
56+
57+
} // namespace emcal
58+
} // namespace o2
59+
#endif /* ALICEO2_EMCAL_DIGITTIMEBIN_H */
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef ALICEO2_EMCAL_TRIGGERDIGITIZER_H
13+
#define ALICEO2_EMCAL_TRIGGERDIGITIZER_H
14+
15+
#include <memory>
16+
#include <unordered_map>
17+
#include <vector>
18+
#include <list>
19+
20+
#include "Rtypes.h" // for DigitizerTRU::Class, Double_t, ClassDef, etc
21+
#include "TObject.h" // for TObject
22+
#include "TRandom3.h"
23+
24+
#include "DataFormatsEMCAL/Digit.h"
25+
#include "EMCALBase/Hit.h"
26+
#include "EMCALBase/TriggerMappingV2.h"
27+
#include "EMCALSimulation/SimParam.h"
28+
#include "EMCALSimulation/LabeledDigit.h"
29+
#include "EMCALSimulation/DigitsWriteoutBufferTRU.h"
30+
#include "EMCALSimulation/LZEROElectronics.h"
31+
#include "SimulationDataFormat/MCTruthContainer.h"
32+
#include "DataFormatsEMCAL/TriggerRecord.h"
33+
#include "CommonUtils/TreeStreamRedirector.h"
34+
35+
namespace o2
36+
{
37+
namespace utils
38+
{
39+
class TreeStreamRedirector;
40+
}
41+
namespace emcal
42+
{
43+
44+
/// \class DigitizerTRU
45+
/// \brief EMCAL DigitizerTRU, digitizes with the help of a temporary description based upon a pol9*Heavyside
46+
/// \ingroup EMCALsimulation
47+
/// \author Anders Knospe, University of Houston
48+
/// \author Hadi Hassan, ORNL
49+
/// \author Simone Ragoni, Creighton
50+
class DigitizerTRU
51+
{
52+
public:
53+
DigitizerTRU() = default;
54+
~DigitizerTRU() = default;
55+
DigitizerTRU(const DigitizerTRU&) = delete;
56+
DigitizerTRU& operator=(const DigitizerTRU&) = delete;
57+
58+
void init();
59+
void clear();
60+
61+
/// \brief Sets patches for the current geometry
62+
void setPatches();
63+
64+
/// clear DigitsVectorStream
65+
void flush() { mDigits.flush(); }
66+
67+
/// This is for the readout window that was interrupted by the end of the run
68+
void finish();
69+
70+
/// Steer conversion of hits to digits
71+
void process(const gsl::span<const Digit> summableDigits);
72+
73+
/// Postprocessing of the digits, gathers by Fastors, not by Tower/Cell
74+
/// \param sdigits results of the SDigitizer
75+
std::vector<std::tuple<int, Digit>> makeAnaloguesFastorSums(const gsl::span<const Digit> sdigits);
76+
77+
void setEventTime(o2::InteractionTimeRecord record);
78+
79+
/// Sets geometry for trigger mapping
80+
void setGeometry(o2::emcal::Geometry* gm) { mGeometry = gm; }
81+
82+
void setWindowStartTime(int time) { mTimeWindowStart = time; }
83+
void setDebugStreaming(bool doStreaming) { mEnableDebugStreaming = doStreaming; }
84+
85+
void fillOutputContainer(std::vector<Digit>& digits, o2::dataformats::MCTruthContainer<o2::emcal::MCLabel>& labels);
86+
87+
bool doSmearEnergy() const { return mSmearEnergy; }
88+
double smearEnergy(double energy);
89+
double smearTime(double time, double energy);
90+
bool doSimulateTimeResponse() const { return mSimulateTimeResponse; }
91+
92+
void sampleSDigit(const Digit& sdigit);
93+
94+
/// Close the TreeStreamer to make the file readable
95+
void endDebugStream()
96+
{
97+
mDebugStream->Close();
98+
// mDebugStreamPatch->Close();
99+
}
100+
101+
/// Getter for debug mode
102+
bool isDebugMode() { return mEnableDebugStreaming; }
103+
104+
/// Getter for patches
105+
std::vector<TRUElectronics> getPatchesVector() { return patchesFromAllTRUs; }
106+
107+
/// raw pointers used here to allow interface with TF1
108+
static double rawResponseFunction(double* x, double* par);
109+
110+
private:
111+
short mEventTimeOffset = 0; ///< event time difference from trigger time (in number of bins)
112+
bool mSmearEnergy = true; ///< do time and energy smearing
113+
bool mSimulateTimeResponse = true; ///< simulate time response
114+
// const SimParam* mSimParam = nullptr; ///< SimParam object
115+
116+
std::vector<Digit> mTempDigitVector; ///< temporary digit storage
117+
// std::unordered_map<Int_t, std::list<LabeledDigit>> mDigits; ///< used to sort digits and labels by tower
118+
o2::emcal::DigitsWriteoutBufferTRU mDigits; ///< used to sort digits by tower
119+
o2::emcal::LZEROElectronics LZERO; ///< to start the trigger
120+
std::vector<TRUElectronics> patchesFromAllTRUs; ///< patches from all TRUs
121+
122+
// TRandom3* mRandomGenerator = nullptr; ///< random number generator
123+
std::array<double, constants::EMCAL_MAXTIMEBINS>
124+
mAmplitudeInTimeBins; ///< template of the sampled time response function: amplitude of signal for each time bin (per phase)
125+
126+
// TriggerMappingV2* mTriggerMap = nullptr; ///< Trigger map for tower to fastor ID
127+
Geometry* mGeometry = nullptr; ///< EMCAL geometry
128+
129+
int mTimeWindowStart = 7; ///< The start of the time window
130+
int mDelay = 7; ///< number of (full) time bins corresponding to the signal time delay
131+
bool mWasTriggerFound = false; ///< To save the data
132+
int mPreviousTriggerSize = 0; ///< To save the data
133+
134+
std::unique_ptr<o2::utils::TreeStreamRedirector> mDebugStream = nullptr;
135+
// std::unique_ptr<o2::utils::TreeStreamRedirector> mDebugStreamPatch = nullptr;
136+
bool mEnableDebugStreaming = false;
137+
138+
ClassDefNV(DigitizerTRU, 1);
139+
};
140+
} // namespace emcal
141+
} // namespace o2
142+
143+
#endif /* ALICEO2_EMCAL_TRIGGERDIGITIZER_H */

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "DataFormatsEMCAL/TriggerRecord.h"
2626
#include "SimulationDataFormat/MCTruthContainer.h"
2727
#include "EMCALSimulation/SimParam.h"
28+
#include "EMCALSimulation/DigitTimebin.h"
2829

2930
namespace o2
3031
{
@@ -38,14 +39,6 @@ namespace emcal
3839
/// \author Markus Fasel, ORNL
3940
/// \date 16/02/2022
4041

41-
struct DigitTimebin {
42-
bool mRecordMode = false;
43-
bool mEndWindow = false;
44-
bool mTriggerColl = false;
45-
std::optional<o2::InteractionRecord> mInterRecord;
46-
std::shared_ptr<std::unordered_map<int, std::list<LabeledDigit>>> mDigitMap = std::make_shared<std::unordered_map<int, std::list<LabeledDigit>>>();
47-
};
48-
4942
class DigitsVectorStream
5043
{
5144

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
//_____________________________________________
13+
// GENERAL IDEA
14+
//
15+
// - Focus on https://github.com/AliceO2Group/AliceO2/blob/dev/Detectors/TPC/simulation/include/TPCSimulation/DigitContainer.h
16+
// - Comform it to the classes used by EMCAL in https://github.com/AliceO2Group/AliceO2/blob/dev/Detectors/EMCAL/simulation/include/EMCALSimulation/DigitsWriteoutBuffer.h
17+
// and in https://github.com/AliceO2Group/AliceO2/blob/dev/Detectors/EMCAL/simulation/include/EMCALSimulation/DigitsVectorStream.h
18+
// - The two concepts are similar
19+
// - EMCAL's was however adapted to triggered mode
20+
// - The principle is to reapply the old TPC format to the continuous readout directly
21+
//
22+
// 1) the idea of dumping the time bins in 15 bins is dumped
23+
// 2) the data are pushed to the output stream whenever possible
24+
// 3) the EndOfRun is implemented to break the push to stream
25+
// it is a flag set to 1 which is read by the filloutputcontainer
26+
// 4) no more check of start or end of trigger
27+
// 5) what about the precollision flags?
28+
// 6) is there any longer a need to set the time of the sampled digits time?
29+
30+
#ifndef ALICEO2_EMCAL_DIGITSWRITEOUTBUFFERTRU_H_
31+
#define ALICEO2_EMCAL_DIGITSWRITEOUTBUFFERTRU_H_
32+
33+
#include <memory>
34+
#include <unordered_map>
35+
#include <vector>
36+
#include <deque>
37+
#include <list>
38+
#include <gsl/span>
39+
#include "DataFormatsEMCAL/Digit.h"
40+
#include "CommonDataFormat/InteractionRecord.h"
41+
#include "EMCALSimulation/LZEROElectronics.h"
42+
#include "EMCALSimulation/DigitTimebin.h"
43+
44+
// using namespace o2::emcal;
45+
46+
namespace o2
47+
{
48+
namespace emcal
49+
{
50+
51+
/// \class DigitsWriteoutBufferTRU
52+
/// \brief Container class for time sampled digits to be sent to TRUs in true continuous readout
53+
/// \ingroup EMCALsimulation
54+
/// \author Hadi Hassan, ORNL
55+
/// \author Markus Fasel, ORNL
56+
/// \author Simone Ragoni, ORNL
57+
/// \date 27/09/2022
58+
59+
class DigitsWriteoutBufferTRU
60+
{
61+
public:
62+
/// Default constructor
63+
DigitsWriteoutBufferTRU(unsigned int nTimeBins = 15);
64+
65+
/// Destructor
66+
~DigitsWriteoutBufferTRU() = default;
67+
68+
/// clear the container
69+
void clear();
70+
71+
/// clear DigitsVectorStream
72+
void flush()
73+
{
74+
// mDigitStream.clear();
75+
}
76+
77+
void init();
78+
79+
/// Reserve space for the future container
80+
/// \param eventTimeBin resize adding at the end
81+
void reserve(int eventTimeBin);
82+
83+
/// This is for the readout window that was interrupted by the end of the run
84+
void finish();
85+
86+
/// Add digit to the container
87+
/// \param towerID Cell ID
88+
/// \param dig Labaled digit to add
89+
void addDigits(unsigned int towerID, std::vector<o2::emcal::Digit>& digList);
90+
91+
/// Fill output streamer
92+
/// \param isEndOfTimeFrame End of Time Frame
93+
/// \param nextInteractionRecord Next interaction record, to compute the amount of TimeBins to be saved
94+
void fillOutputContainer(bool isEndOfTimeFrame, InteractionRecord& nextInteractionRecord, std::vector<TRUElectronics>& patchesFromAllTRUs, LZEROElectronics& LZERO);
95+
96+
/// Setters for the live time, busy time, pre-trigger time
97+
void setLiveTime(unsigned int liveTime) { mLiveTime = liveTime; }
98+
void setBusyTime(unsigned int busyTime) { mBusyTime = busyTime; }
99+
100+
const std::deque<o2::emcal::DigitTimebinTRU>& getTimeBins() const { return mTimeBins; }
101+
102+
private:
103+
unsigned int mBufferSize = 15; ///< The size of the buffer
104+
unsigned int mLiveTime = 1500; ///< EMCal live time (ns)
105+
unsigned int mBusyTime = 35000; ///< EMCal busy time (ns)
106+
// unsigned int mPreTriggerTime = 600; ///< EMCal pre-trigger time (ns)
107+
unsigned long mTriggerTime = 0; ///< Time of the collision that fired the trigger (ns)
108+
unsigned long mLastEventTime = 0; ///< The event time of last collisions in the readout window
109+
unsigned int mPhase = 0; ///< The event L1 phase
110+
bool mFirstEvent = true; ///< Flag to the first event in the run
111+
std::deque<o2::emcal::DigitTimebinTRU> mTimeBins; ///< Container for time sampled digits per tower ID for continuous digits
112+
unsigned int mFirstTimeBin = 0;
113+
bool mEndOfRun = 0;
114+
bool mNoPileupMode = false; ///< pileup mode from SimParam
115+
o2::InteractionRecord mCurrentInteractionRecord; ///< Interaction Record of the current event, to be used to fill the output container
116+
117+
ClassDefNV(DigitsWriteoutBufferTRU, 5);
118+
// ClassDefNV are for objects which do not inherit from tobject
119+
// you do not need classIMP instead
120+
};
121+
122+
} // namespace emcal
123+
124+
} // namespace o2
125+
126+
#endif /* ALICEO2_EMCAL_DIGITSWRITEOUTBUFFERTRU_H_ */

0 commit comments

Comments
 (0)