Project
Loading...
Searching...
No Matches
Digitizer.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
18namespace o2
19{
20namespace mid
21{
22//______________________________________________________________________________
23Digitizer::Digitizer(const ChamberResponse& chamberResponse, const ChamberEfficiencyResponse& efficiencyResponse, const GeometryTransformer& transformer) : mGenerator(std::default_random_engine()), mRandom(), mResponse(chamberResponse), mEfficiencyResponse(efficiencyResponse), mMapping(), mTransformer(transformer), mDigits()
24{
26}
27
28//______________________________________________________________________________
29void Digitizer::addStrip(const Mapping::MpStripIndex& stripIndex, int cathode, int deId)
30{
32 for (auto& col : mDigits) {
33 if (col.deId == deId && col.columnId == stripIndex.column) {
34 col.addStrip(stripIndex.strip, cathode, stripIndex.line);
35 return;
36 }
37 }
38
39 mDigits.emplace_back(ColumnData{(uint8_t)deId, (uint8_t)stripIndex.column});
40 mDigits.back().addStrip(stripIndex.strip, cathode, stripIndex.line);
41}
42
43//______________________________________________________________________________
44bool Digitizer::addBPStrips(double xPos, double yPos, int deId, double prob, double xOffset)
45{
47
48 // The offset is used to check the strips in the bending plane
49 // placed in the board close to the fired one
50 // If the response says that the strip is too far away, there is no need to check further
51 if (!mResponse.isFired(prob, std::abs(xOffset), 0, deId)) {
52 return false;
53 }
54
55 Mapping::MpStripIndex stripIndex = mMapping.stripByPosition(xPos + 1.01 * xOffset, yPos, 0, deId, false);
56 // Check if the point is still inside the RPC
57 if (!stripIndex.isValid()) {
58 return false;
59 }
60 addStrip(stripIndex, 0, deId);
61 MpArea area = mMapping.stripByLocation(stripIndex.strip, 0, stripIndex.line, stripIndex.column, deId);
62 std::array<double, 2> dist = {area.getYmax() - yPos, yPos - area.getYmin()};
63 addNeighbours(stripIndex, 0, deId, prob, dist, xOffset);
64 return true;
65}
66
67//______________________________________________________________________________
68bool Digitizer::addNeighbours(const Mapping::MpStripIndex& stripIndex, int cathode, int deId, double prob,
69 const std::array<double, 2>& initialDist, double xOffset)
70{
72
73 double xOffset2 = xOffset * xOffset;
74 for (int idir = 0; idir < 2; ++idir) {
75 // Search for neighbours in the two directions
76 // up and down for the BP, right and left for the NBP
77 double dist = initialDist[idir];
78 Mapping::MpStripIndex neigh = mMapping.nextStrip(stripIndex, cathode, deId, idir);
79 while (neigh.isValid() && mResponse.isFired(prob, std::sqrt(dist * dist + xOffset2), cathode, deId)) {
80 addStrip(neigh, cathode, deId);
81 dist += mMapping.getStripSize(neigh.strip, cathode, neigh.column, deId);
82 neigh = mMapping.nextStrip(neigh, cathode, deId, idir);
83 }
84 }
85 return true;
86}
87
88//______________________________________________________________________________
89bool Digitizer::hitToDigits(const Hit& hit)
90{
92
93 // Clear
94 mDigits.clear();
95
96 // Convert point from global to local coordinates
97 auto midPt = hit.middlePoint();
98 int deId = hit.GetDetectorID();
99 math_utils::Point3D<double> localPoint = mTransformer.globalToLocal(deId, (double)midPt.x(), (double)midPt.y(), (double)midPt.z());
100
101 // First get the touched BP strip
102 Mapping::MpStripIndex stripIndex = mMapping.stripByPosition(localPoint.x(), localPoint.y(), 0, deId);
103
104 // Check if the chamber was efficient
105 bool isEfficientBP, isEfficientNBP;
106 if (!mEfficiencyResponse.isEfficient(deId, stripIndex.column, stripIndex.line, isEfficientBP, isEfficientNBP)) {
107 return false;
108 }
109
110 // Digitize if the RPC was efficient
111 double prob = mRandom(mGenerator);
112
113 if (isEfficientBP) {
114 addStrip(stripIndex, 0, deId);
115 MpArea area = mMapping.stripByLocation(stripIndex.strip, 0, stripIndex.line, stripIndex.column, deId);
116 // This is the distance between the hit point and the edges of the strip along y
117 std::array<double, 2> dist = {area.getYmax() - localPoint.y(), localPoint.y() - area.getYmin()};
118 addNeighbours(stripIndex, 0, deId, prob, dist);
119 // Search for neighbours in the close column toward inside
120 addBPStrips(localPoint.x(), localPoint.y(), deId, prob, area.getXmin() - localPoint.x());
121 // Search for neighbours in the close column toward outside
122 addBPStrips(localPoint.x(), localPoint.y(), deId, prob, area.getXmax() - localPoint.x());
123 }
124
125 // Then check the touched NBP strip
126 if (isEfficientNBP) {
127 stripIndex = mMapping.stripByPosition(localPoint.x(), localPoint.y(), 1, deId);
128 addStrip(stripIndex, 1, deId);
129 MpArea area = mMapping.stripByLocation(stripIndex.strip, 1, stripIndex.line, stripIndex.column, deId);
130 // This is the distance between the hit point and the edges of the strip along x
131 std::array<double, 2> dist = {area.getXmax() - localPoint.x(), localPoint.x() - area.getXmin()};
132 addNeighbours(stripIndex, 1, deId, prob, dist);
133 }
134
135 return true;
136}
137
138//______________________________________________________________________________
139void Digitizer::process(const std::vector<Hit>& hits, std::vector<ColumnData>& digitStore, o2::dataformats::MCTruthContainer<MCLabel>& mcContainer)
140{
142 digitStore.clear();
143 mcContainer.clear();
144 int firstStrip = 0, lastStrip = 0;
145
146 for (auto& hit : hits) {
147 hitToDigits(hit);
148
149 for (auto& digit : mDigits) {
150 digitStore.emplace_back(digit);
151 for (int icathode = 0; icathode < 2; ++icathode) {
152 if (getLabelLimits(icathode, digit, firstStrip, lastStrip)) {
153 MCLabel label(hit.GetTrackID(), mEventID, mSrcID, digit.deId, digit.columnId, icathode, firstStrip, lastStrip);
154 mcContainer.addElement(digitStore.size() - 1, label);
155 }
156 }
157 }
158 }
159}
160
161//______________________________________________________________________________
162bool Digitizer::getLabelLimits(int cathode, const ColumnData& col, int& firstStrip, int& lastStrip) const
163{
165 int nLines = (cathode == 0) ? 4 : 1;
166 int invalid = 9999;
167 firstStrip = invalid, lastStrip = invalid;
168 for (int iline = 0; iline < nLines; ++iline) {
169 for (int istrip = 0; istrip < 16; ++istrip) {
170 if (col.isStripFired(istrip, cathode, iline)) {
171 lastStrip = MCLabel::getStrip(istrip, iline);
172 if (firstStrip == invalid) {
173 firstStrip = lastStrip;
174 }
175 } else if (firstStrip != invalid) {
176 return true;
177 }
178 }
179 }
180 return (firstStrip != invalid);
181}
182
183//______________________________________________________________________________
188
189} // namespace mid
190} // namespace o2
Digitizer for MID.
uint32_t col
Definition RawData.h:4
A container to hold and manage MC truth information/labels.
void addElement(uint32_t dataindex, TruthElement const &element, bool noElement=false)
bool isEfficient(int deId, int columnId, int line, bool &isEfficientBP, bool &isEfficientNBP)
bool isFired(double prob, double distance, int cathode, int deId, double theta=0.) const
Checks if the strip at a certain distance from the impact point is fired given a probability prob.
void process(const std::vector< Hit > &hits, std::vector< ColumnData > &digitStore, o2::dataformats::MCTruthContainer< MCLabel > &mcContainer)
Digitizer(const ChamberResponse &chamberResponse, const ChamberEfficiencyResponse &efficiencyResponse, const GeometryTransformer &transformer)
Definition Digitizer.cxx:23
math_utils::Point3D< T > globalToLocal(int deId, const math_utils::Point3D< T > &position) const
static int getStrip(int strip, int line)
Gets the strip.
Definition MCLabel.h:81
MpStripIndex stripByPosition(double xPos, double yPos, int cathode, int deId, bool warn=true) const
Definition Mapping.cxx:592
double getStripSize(int strip, int cathode, int column, int deId) const
Definition Mapping.cxx:140
MpArea stripByLocation(int strip, int cathode, int line, int column, int deId, bool warn=true) const
Definition Mapping.cxx:487
MpStripIndex nextStrip(const MpStripIndex &stripIndex, int cathode, int deId, bool descending=false) const
Definition Mapping.cxx:323
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
Digitizer createDefaultDigitizer()
ChamberEfficiencyResponse createDefaultChamberEfficiencyResponse()
GeometryTransformer createDefaultTransformer()
ChamberResponse createDefaultChamberResponse()
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
Column data structure for MID.
Definition ColumnData.h:29
Indexes required to define a strip in the detection element.
Definition Mapping.h:34
int strip
Line of the local board in the column.
Definition Mapping.h:39
int line
Column in the DE.
Definition Mapping.h:38