Project
Loading...
Searching...
No Matches
HitMapBuilder.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
17
18#include <array>
19namespace o2
20{
21namespace mid
22{
23
24HitMapBuilder::HitMapBuilder(const GeometryTransformer& geoTrans) : mMapping(), mHitFinder(geoTrans) {}
25
26void HitMapBuilder::setMaskedChannels(const std::vector<ColumnData>& maskedChannels, bool clear)
27{
28 if (clear) {
29 mMaskedChannels.clear();
30 }
31 std::array<int, 2> nLines{4, 1};
32 for (auto& mask : maskedChannels) {
33 for (int icath = 0; icath < 2; ++icath) {
34 for (int iline = 0; iline < nLines[icath]; ++iline) {
35 auto pat = mask.getPattern(icath, iline);
36 for (int istrip = 0; istrip < detparams::NStripsBP; ++istrip) {
37 if (pat & (1 << istrip)) {
38 auto area = mMapping.stripByLocation(istrip, icath, iline, mask.columnId, mask.deId);
39 mMaskedChannels[mask.deId].emplace_back(area);
40 }
41 }
42 }
43 }
44 }
45}
46
47bool HitMapBuilder::crossCommonElement(const std::vector<int>& fired, const std::vector<int>& nonFired) const
48{
49 // First check that all elements in fired are the same
50 auto refIt = fired.begin();
51 for (auto it = fired.begin() + 1, end = fired.end(); it != end; ++it) {
52 if (*it != *refIt) {
53 return false;
54 }
55 }
56
57 // If there is no element in nonFired, then return true
58 if (nonFired.empty()) {
59 return true;
60 }
61
62 // Check that at least one element in nonFired matches the reference elements
63 for (auto it = nonFired.begin(), end = nonFired.end(); it != end; ++it) {
64 if (*it == *refIt) {
65 return true;
66 }
67 }
68
69 return false;
70}
71
72int HitMapBuilder::getEffFlag(const std::vector<int>& firedFEEIdMT11, const std::vector<int>& nonFiredFEEIdMT11) const
73{
74 std::vector<int> firedRPCLines, nonFiredRPCLines;
75 for (auto& feeId : firedFEEIdMT11) {
76 firedRPCLines.emplace_back(detparams::getDEIdFromFEEId(feeId));
77 }
78 for (auto& feeId : nonFiredFEEIdMT11) {
79 nonFiredRPCLines.emplace_back(detparams::getDEIdFromFEEId(feeId));
80 }
81
82 if (crossCommonElement(firedRPCLines, nonFiredRPCLines)) {
83 if (crossCommonElement(firedFEEIdMT11, nonFiredFEEIdMT11)) {
84 return 3;
85 }
86 return 2;
87 }
88 return 1;
89}
90
91int HitMapBuilder::getFEEIdMT11(double xp, double yp, uint8_t deId) const
92{
93 auto stripIndex = mMapping.stripByPosition(xp, yp, 0, deId, false);
94 if (stripIndex.isValid()) {
96 return detparams::makeUniqueFEEId(deIdMT11, stripIndex.column, stripIndex.line);
97 }
98 return -1;
99}
100
101bool HitMapBuilder::matchesMaskedChannel(const Cluster& cl) const
102{
103 auto found = mMaskedChannels.find(cl.deId);
104 if (found == mMaskedChannels.end()) {
105 return false;
106 }
107
108 double nSigmas = 4.;
109
110 for (auto& area : found->second) {
111 if (std::abs(cl.xCoor - area.getCenterX()) < nSigmas * cl.getEX() + area.getHalfSizeX() &&
112 std::abs(cl.yCoor - area.getCenterY()) < nSigmas * cl.getEY() + area.getHalfSizeY()) {
113 return true;
114 }
115 }
116 return false;
117}
118
119void HitMapBuilder::buildTrackInfo(Track& track, gsl::span<const Cluster> clusters) const
120{
121 std::vector<int> firedFEEIdMT11, nonFiredFEEIdMT11;
122 bool badForEff = false;
123 for (int ich = 0; ich < 4; ++ich) {
124 auto icl = track.getClusterMatchedUnchecked(ich);
125 if (icl >= 0) {
126 auto& cl = clusters[icl];
127 firedFEEIdMT11.emplace_back(getFEEIdMT11(cl.xCoor, cl.yCoor, cl.deId));
128 for (int icath = 0; icath < 2; ++icath) {
129 if (cl.isFired(icath)) {
130 track.setFiredChamber(ich, icath);
131 }
132 }
133 } else {
134 auto impactPts = mHitFinder.getLocalPositions(track, ich, true);
135 for (auto& impactPt : impactPts) {
136 auto feeIdMT11 = getFEEIdMT11(impactPt.xCoor, impactPt.yCoor, impactPt.deId);
137 if (feeIdMT11 >= 0) {
138 nonFiredFEEIdMT11.emplace_back(feeIdMT11);
139 if (matchesMaskedChannel(impactPt)) {
140 badForEff = true;
141 }
142 } else {
143 badForEff = true;
144 }
145 }
146 }
147 }
148 track.setFiredFEEId(firedFEEIdMT11.front());
149 int effFlag = badForEff ? 0 : getEffFlag(firedFEEIdMT11, nonFiredFEEIdMT11);
150 track.setEfficiencyFlag(effFlag);
151}
152
153void HitMapBuilder::process(std::vector<Track>& tracks, gsl::span<const Cluster> clusters) const
154{
155 for (auto& track : tracks) {
156 buildTrackInfo(track, clusters);
157 }
158}
159
160} // namespace mid
161} // namespace o2
Utility to build the MID track hit maps.
HMPID cluster implementation.
Definition Cluster.h:27
std::vector< Cluster > getLocalPositions(const Track &track, int chamber, bool withUncertainties=false) const
void process(std::vector< Track > &tracks, gsl::span< const Cluster > clusters) const
void setMaskedChannels(const std::vector< ColumnData > &maskedChannels, bool clear)
HitMapBuilder(const GeometryTransformer &geoTrans)
void buildTrackInfo(Track &track, gsl::span< const Cluster > clusters) const
MpStripIndex stripByPosition(double xPos, double yPos, int cathode, int deId, bool warn=true) const
Definition Mapping.cxx:592
MpArea stripByLocation(int strip, int cathode, int line, int column, int deId, bool warn=true) const
Definition Mapping.cxx:487
This class defines the MID track.
Definition Track.h:30
int getClusterMatchedUnchecked(int chamber) const
Definition Track.h:98
void setFiredChamber(int chamber, int cathode)
Definition Track.h:132
void setEfficiencyFlag(int effFlag)
Definition Track.h:169
void setFiredFEEId(int uniqueFeeId)
Sets the fired FEE ID.
Definition Track.h:147
GLuint GLuint end
Definition glcorearb.h:469
GLint GLuint mask
Definition glcorearb.h:291
uint16_t makeUniqueFEEId(int deId, int columnId, int lineId)
bool isRightSide(int deId)
int getDEIdFromFEEId(uint16_t uniqueFEEId)
int getDEId(bool isRight, int chamber, int rpc)
constexpr int NStripsBP
Number of strips in the Bending Plane.
simClustering correlation clear()
std::vector< Cluster > clusters
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...