Project
Loading...
Searching...
No Matches
RecoContainer.cxx
Go to the documentation of this file.
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#include <algorithm>
13#include <iostream>
16
17using namespace o2::emcal;
18
19EventContainer::EventContainer(const o2::InteractionRecord& currentIR) : mInteractionRecord(currentIR) { initTRUs(); }
20
21void EventContainer::initTRUs()
22{
23 for (auto index = 0; index < mTRUData.size(); index++) {
24 mTRUData[index].setTRUIndex(index);
25 mTRUData[index].setL0time(INT8_MAX);
26 }
27}
28
29void EventContainer::setCellCommon(int tower, double energy, double time, ChannelType_t celltype, bool isLEDmon, int hwaddress, int ddlID, bool doMergeHGLG)
30{
31 auto updateCell = [energy, time, celltype](Cell& cell) {
32 cell.setEnergy(energy);
33 cell.setTimeStamp(time);
34 cell.setType(celltype);
35 };
36 auto& datacontainer = isLEDmon ? mLEDMons : mCells;
37 if (doMergeHGLG) {
38 auto found = std::find_if(datacontainer.begin(), datacontainer.end(), [&tower](const o2::emcal::RecCellInfo& testcell) -> bool { return testcell.mCellData.getTower() == tower; });
39 if (found != datacontainer.end()) {
40 // Cell already existing, store LG if HG is larger then the overflow cut
41 if (celltype == o2::emcal::ChannelType_t::LOW_GAIN) {
42 found->mHWAddressLG = hwaddress;
43 found->mHGOutOfRange = false; // LG is found so it can replace the HG if the HG is out of range
44 if (found->mCellData.getHighGain()) {
45 if (isCellSaturated(found->mCellData.getEnergy())) {
46 // High gain digit has energy above overflow cut, use low gain instead
47 updateCell(found->mCellData);
48 }
49 found->mIsLGnoHG = false;
50 }
51 } else {
52 // new channel would be HG: use that if it is below overflow cut
53 // as the channel existed before it must have been a LG channel,
54 // which would be used in case the HG is out-of-range
55 found->mIsLGnoHG = false;
56 found->mHGOutOfRange = false;
57 found->mHWAddressHG = hwaddress;
58 if (!isCellSaturated(energy)) {
59 updateCell(found->mCellData);
60 }
61 }
62 } else {
63 // New cell
64 bool lgNoHG = false; // Flag for filter of cells which have only low gain but no high gain
65 bool hgOutOfRange = false; // Flag if only a HG is present which is out-of-range
66 int hwAddressLG = -1, // Hardware address of the LG of the tower (for monitoring)
67 hwAddressHG = -1; // Hardware address of the HG of the tower (for monitoring)
68 if (celltype == o2::emcal::ChannelType_t::LOW_GAIN) {
69 lgNoHG = true;
70 hwAddressLG = hwaddress;
71 } else {
72 // High gain cell: Flag as low gain if above threshold
73 hgOutOfRange = isCellSaturated(energy);
74 hwAddressHG = hwaddress;
75 }
76 datacontainer.push_back({o2::emcal::Cell(tower, energy, time, celltype),
77 lgNoHG,
78 hgOutOfRange,
79 ddlID, hwAddressLG, hwAddressHG});
80 }
81 } else {
82 // No merge of HG/LG cells (usually MC where either
83 // of the two is simulated)
84 int hwAddressLG = celltype == ChannelType_t::LOW_GAIN ? hwaddress : -1,
85 hwAddressHG = celltype == ChannelType_t::HIGH_GAIN ? hwaddress : -1;
86 // New cell
87 datacontainer.push_back({o2::emcal::Cell(tower, energy, time, celltype),
88 false,
89 false,
90 ddlID, hwAddressLG, hwAddressHG});
91 }
92}
93
94void EventContainer::setFastOR(uint16_t fastORAbsID, uint8_t starttime, const gsl::span<const uint16_t> timesamples)
95{
96 auto found = mL0FastORs.find(fastORAbsID);
97 if (found != mL0FastORs.end()) {
98 found->second.setTimeSamples(timesamples, starttime);
99 } else {
100 mL0FastORs[fastORAbsID] = FastORTimeSeries(14, timesamples, starttime);
101 }
102}
103
104void EventContainer::sortCells(bool isLEDmon)
105{
106 auto& dataContainer = isLEDmon ? mLEDMons : mCells;
107 std::sort(dataContainer.begin(), dataContainer.end(), [](const RecCellInfo& lhs, const RecCellInfo& rhs) -> bool { return lhs.mCellData.getTower() < rhs.mCellData.getTower(); });
108}
109
110bool EventContainer::isCellSaturated(double energy) const
111{
112 return energy / o2::emcal::constants::EMCAL_ADCENERGY > o2::emcal::constants::OVERFLOWCUT;
113}
114
116{
117 if (index >= mTRUData.size()) {
119 }
120 return mTRUData[index];
121}
122
124{
125 if (index >= mTRUData.size()) {
127 }
128 return mTRUData[index];
129}
130
132{
133 mMessage = "Invalid TRU index " + std::to_string(index);
134}
135
137{
138 auto found = mEvents.find(currentIR);
139 if (found != mEvents.end()) {
140 return found->second;
141 }
142 // interaction not found, create new container
143 auto res = mEvents.insert({currentIR, EventContainer(currentIR)});
144 return res.first->second;
145}
146
148{
149 auto found = mEvents.find(currentIR);
150 if (found == mEvents.end()) {
151 throw InteractionNotFoundException(currentIR);
152 }
153 return found->second;
154}
155
156std::vector<o2::InteractionRecord> RecoContainer::getOrderedInteractions() const
157{
158 std::vector<o2::InteractionRecord> result;
159 for (auto& entry : mEvents) {
160 result.emplace_back(entry.first);
161 }
162 std::sort(result.begin(), result.end(), std::less<>());
163 return result;
164}
165
166RecoContainerReader::RecoContainerReader(RecoContainer& container) : mDataContainer(container)
167{
168 mOrderedInteractions = mDataContainer.getOrderedInteractions();
169}
170
172{
173 if (!hasNext()) {
175 }
176 int currentID = mCurrentEvent;
177 mCurrentEvent++;
178 try {
179 return mDataContainer.getEventContainer(mOrderedInteractions[currentID]);
182 }
183}
Reconstruction container for EMCAL Cells and LEDMONs.
int16_t time
Definition RawEventData.h:4
uint32_t res
Definition RawData.h:0
EMCAL compressed cell information.
Definition Cell.h:59
Handler for access of TRU data with invalid TRU index.
TRUIndexException(std::size_t index)
Constructor.
Containter of cells for a given event.
void setFastOR(uint16_t fastORAbsID, uint8_t starttime, const gsl::span< const uint16_t > timesamples)
Add bunch of time series to the container.
void sortCells(bool isLEDmon)
Sort Cells / LEDMONs in container according to tower / module ID.
const TRUDataHandler & readTRUData(std::size_t truIndex) const
Read-only access TRU data of a given TRU.
EventContainer()=default
Constructor.
TRUDataHandler & getTRUData(std::size_t truIndex)
Read and write access TRU data of a given TRU.
Container for FastOR time series.
Handling of access to objects beyond container boundary.
RecoContainerReader(RecoContainer &container)
Constructor.
EventContainer & nextEvent()
Get the next event in container.
bool hasNext() const
Check whehter there are more events in the container.
Handling of access to trigger interaction record not present in container.
Handler for cells/LEDMONS/Trigger data in timeframes.
EventContainer & getEventContainer(const o2::InteractionRecord &currentIR)
Get container for trigger.
std::vector< o2::InteractionRecord > getOrderedInteractions() const
Get sorted vector interaction records of triggers in container.
Helper class to handle decoded TRU data during the reconstruction.
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint entry
Definition glcorearb.h:5735
GLuint index
Definition glcorearb.h:781
ChannelType_t
Type of a raw data channel.
Definition Constants.h:33
@ HIGH_GAIN
High gain channel.
Definition Constants.h:35
@ LOW_GAIN
Low gain channel.
Definition Constants.h:34
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
Container class for cell information for merging.