Project
Loading...
Searching...
No Matches
DigitMerging.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 "DigitMerging.h"
13#include <map>
14#include <algorithm>
15#include <numeric>
16#include <iostream>
17#include <set>
18
19using o2::mch::Digit;
20
21void dumpDigits(const std::vector<Digit>& digits)
22{
23 int i{0};
24 std::cout << "dumpDigits" << std::string(40, '-') << "\n";
25 for (auto& d : digits) {
26 std::cout << "i=" << i << ":[" << d.getPadID() << "," << d.getADC() << " ] ";
27 i++;
28 }
29 std::cout << "\n";
30}
31
32std::vector<Digit> mergeDigits_sortnosizeadjust(const std::vector<Digit>& inputDigits, const std::vector<o2::MCCompLabel>& inputLabels)
33{
34 std::vector<int> indices(inputDigits.size());
35 std::iota(begin(indices), end(indices), 0);
36
37 std::sort(indices.begin(), indices.end(), [&inputDigits](int a, int b) {
38 return inputDigits[a].getPadID() < inputDigits[b].getPadID();
39 });
40
41 auto sortedDigits = [&inputDigits, &indices](int i) {
42 return inputDigits[indices[i]];
43 };
44
45 auto sortedLabels = [&inputLabels, &indices](int i) {
46 return inputLabels[indices[i]];
47 };
48
49 std::vector<Digit> digits;
50
51 std::vector<o2::MCCompLabel> labels;
52
53 int i = 0;
54 while (i < indices.size()) {
55 int j = i + 1;
56 while (j < indices.size() && (sortedDigits(i).getPadID() == sortedDigits(j).getPadID())) {
57 j++;
58 }
59 float adc{0};
60 for (int k = i; k < j; k++) {
61 adc += sortedDigits(k).getADC();
62 }
63 digits.emplace_back(sortedDigits(i).getDetID(), sortedDigits(i).getPadID(), adc, sortedDigits(i).getTime());
64 labels.emplace_back(sortedLabels(i).getTrackID(), sortedLabels(i).getEventID(), sortedLabels(i).getSourceID(), false);
65 i = j;
66 }
67 return digits;
68}
69
70std::vector<Digit> mergeDigits_sortsizeadjust(const std::vector<Digit>& inputDigits, const std::vector<o2::MCCompLabel>& inputLabels)
71{
72 std::vector<int> indices(inputDigits.size());
73 std::iota(begin(indices), end(indices), 0);
74
75 std::sort(indices.begin(), indices.end(), [&inputDigits](int a, int b) {
76 return inputDigits[a].getPadID() < inputDigits[b].getPadID();
77 });
78
79 auto sortedDigits = [&inputDigits, &indices](int i) {
80 return inputDigits[indices[i]];
81 };
82
83 auto sortedLabels = [&inputLabels, &indices](int i) {
84 return inputLabels[indices[i]];
85 };
86
87 std::vector<Digit> digits;
88 digits.reserve(inputDigits.size());
89
90 std::vector<o2::MCCompLabel> labels;
91 labels.reserve(inputLabels.size());
92
93 int i = 0;
94 while (i < indices.size()) {
95 int j = i + 1;
96 while (j < indices.size() && (sortedDigits(i).getPadID() == sortedDigits(j).getPadID())) {
97 j++;
98 }
99 float adc{0};
100 for (int k = i; k < j; k++) {
101 adc += sortedDigits(k).getADC();
102 }
103 digits.emplace_back(sortedDigits(i).getDetID(), sortedDigits(i).getPadID(), adc, sortedDigits(i).getTime());
104 labels.emplace_back(sortedLabels(i).getTrackID(), sortedLabels(i).getEventID(), sortedLabels(i).getSourceID(), false);
105 i = j;
106 }
107 digits.resize(digits.size());
108 labels.resize(labels.size());
109 return digits;
110}
111
112std::vector<Digit> mergeDigits_map(const std::vector<Digit>& inputDigits, const std::vector<o2::MCCompLabel>& inputLabels)
113{
114 int iter = 0;
115 int index = 0;
116 std::map<int, int> padidmap;
117 std::set<int> forRemoval;
118 std::vector<Digit> digits{inputDigits};
119 std::vector<o2::MCCompLabel> labels{inputLabels};
120
121 for (auto& digit : digits) {
122 int count = 0;
123 int padid = digit.getPadID();
124 count = padidmap.count(padid);
125 if (count) {
126 std::pair<std::map<int, int>::iterator, std::map<int, int>::iterator> ret;
127
128 ret = padidmap.equal_range(padid);
129 index = ret.first->second;
130 (digits.at(index)).setADC(digits.at(index).getADC() + digit.getADC());
131 forRemoval.emplace(iter);
132 } else {
133 padidmap.emplace(padid, iter);
134 }
135 ++iter;
136 }
137
138 int rmcounts = 0;
139 for (auto& rmindex : forRemoval) {
140 digits.erase(digits.begin() + rmindex - rmcounts);
141 labels.erase(labels.begin() + rmindex - rmcounts);
142 ++rmcounts;
143 }
144 return digits;
145}
146
147std::vector<MergingFunctionType> mergingFunctions()
148{
149 return std::vector<MergingFunctionType>{mergeDigits_sortnosizeadjust, mergeDigits_sortsizeadjust, mergeDigits_map};
150}
std::vector< MergingFunctionType > mergingFunctions()
std::vector< Digit > mergeDigits_map(const std::vector< Digit > &inputDigits, const std::vector< o2::MCCompLabel > &inputLabels)
std::vector< Digit > mergeDigits_sortnosizeadjust(const std::vector< Digit > &inputDigits, const std::vector< o2::MCCompLabel > &inputLabels)
void dumpDigits(const std::vector< Digit > &digits)
std::vector< Digit > mergeDigits_sortsizeadjust(const std::vector< Digit > &inputDigits, const std::vector< o2::MCCompLabel > &inputLabels)
int32_t i
uint32_t j
Definition RawData.h:0
MCH digit implementation.
Definition Digit.h:31
int getPadID() const
Definition Digit.h:54
GLint GLsizei count
Definition glcorearb.h:399
GLuint GLuint end
Definition glcorearb.h:469
GLuint index
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei GLenum const void * indices
Definition glcorearb.h:400
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
std::vector< Digit > digits
ArrayADC adc