Project
Loading...
Searching...
No Matches
PileupTool.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
14
15using namespace o2::trd;
16using namespace o2::trd::constants;
17
18SignalContainer PileupTool::addSignals(std::deque<std::array<SignalContainer, constants::MAXCHAMBER>>& pileupSignals, const double& triggerTime)
19{
20 SignalContainer addedSignalsMap;
21 int nSignalsToRemove = 0;
22 for (const auto& collection : pileupSignals) {
23 bool pileupSignalBecomesObsolete = false;
24 for (int det = 0; det < MAXCHAMBER; ++det) {
25 const auto& signalMap = collection[det]; //--> a map with active pads only for this chamber
26 for (const auto& signal : signalMap) { // loop over active pads only, if there is any
27 const int& key = signal.first;
28 const SignalArray& signalArray = signal.second;
29 bool signalContributed = false;
30 // check if the signal is from a previous event
31 if (signalArray.firstTBtime < triggerTime) {
32 pileupSignalBecomesObsolete = true;
33 if ((triggerTime - signalArray.firstTBtime) > TRDSimParams::Instance().readoutTimeNS) { // OS: READOUT_TIME should actually be drift time (we want to ignore signals which don't contribute signal anymore at triggerTime)
34 continue; // ignore the signal if it is too old.
35 }
36 // add only what's leftover from this signal
37 // 0.01 = samplingRate/1000, 1/1000 to go from ns to micro-s, the sampling rate is in 1/micro-s
38 int idx = (int)((triggerTime - signalArray.firstTBtime) * 0.01); // number of bins to skip
39 auto it0 = signalArray.signals.begin() + idx;
40 auto it1 = addedSignalsMap[key].signals.begin();
41 while (it0 < signalArray.signals.end()) {
42 *it1 += *it0;
43 it0++;
44 it1++;
45 signalContributed = true;
46 }
47 } else {
48 // the signal is from a subsequent event
49 int idx = (int)((signalArray.firstTBtime - triggerTime) * 0.01); // time bin offset of the pileup signal wrt trigger time. Number of time bins to be added to the signal is constants::TIMEBINS - idx
50 auto it0 = signalArray.signals.begin();
51 auto it1 = addedSignalsMap[key].signals.begin() + idx;
52 while (it1 < addedSignalsMap[key].signals.end()) {
53 *it1 += *it0;
54 it0++;
55 it1++;
56 signalContributed = true;
57 }
58 }
59 // keep the labels
60 if (signalContributed) {
61 for (const auto& label : signalArray.labels) {
62 (addedSignalsMap[key].labels).push_back(label);
63 }
64 }
65 } // loop over active pads in detector
66 } // loop over detectors
67 if (pileupSignalBecomesObsolete) {
68 ++nSignalsToRemove;
69 }
70 } // loop over pileup container
71 // remove all used added signals, keep those that can pileup to newer events.
72 for (int i = 0; i < nSignalsToRemove; ++i) {
73 pileupSignals.pop_front();
74 }
75 return addedSignalsMap;
76}
int32_t i
StringRef key
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
constexpr int MAXCHAMBER
the maximum number of installed chambers
Definition Constants.h:30
std::unordered_map< int, SignalArray > SignalContainer
Definition Digitizer.h:44
SignalContainer addSignals(std::deque< std::array< SignalContainer, constants::MAXCHAMBER > > &, const double &)
std::array< float, constants::TIMEBINS > signals
Definition SignalArray.h:29
std::vector< o2::MCCompLabel > labels
Definition SignalArray.h:31
float readoutTimeNS
the time the readout takes in ns (default 30 time bins = 3 us)