Skip to content

Commit 95d7c9b

Browse files
committed
Bugfix: When starting sensor placement around the x-axis you can have a different number of sensor stacks on the positive/negative side of the stave leading to garbage memory access. Fixed now.
1 parent 9a93b25 commit 95d7c9b

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

Detectors/Upgrades/ALICE3/FT3/simulation/src/FT3Module.cxx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ void FT3Module::fill_stave(PosNegPositionTypes& y_positions, double Rin, double
166166
if (!y_positions.first.empty()) { // sensors already placed
167167
double previousStackHeight = Constants::getStackHeight(y_positions.first.back().second);
168168
y_top = y_positions.first.back().first + previousStackHeight + Constants::stackGap;
169-
} else if (y_ranges.first.first < absAllowedYRange.first) {
170-
// given starting y is lower than the minimum allowed y, start at the latter.
171-
y_top = absAllowedYRange.first;
169+
} else if (absAllowedYRange.first > 0) {
170+
// there is a minimum inner value --> start at the max of the two
171+
y_top = std::max(absAllowedYRange.first, y_ranges.first.first);
172172
} else {
173-
// given starting y is acceptable, start there
173+
// No inner minimum value, start at given value
174174
y_top = y_ranges.first.first;
175175
}
176176
// fill positive y sensor positions
@@ -186,15 +186,18 @@ void FT3Module::fill_stave(PosNegPositionTypes& y_positions, double Rin, double
186186
// subtract instead to move further down
187187
double previousStackHeight = Constants::getStackHeight(y_positions.second.back().second);
188188
y_bottom = y_positions.second.back().first - previousStackHeight - Constants::stackGap;
189-
} else if (y_ranges.second.first > -absAllowedYRange.first) {
190-
// given starting y is closer to x-axis than max allowed y, start at the latter.
191-
y_bottom = -absAllowedYRange.first;
189+
} else if (absAllowedYRange.first > 0) {
190+
// there is a minimum inner value --> start at the min of the two
191+
y_bottom = std::min(-absAllowedYRange.first, y_ranges.second.first);
192192
} else {
193-
// given starting y is acceptable, start there
193+
// No inner minimum value, start at given value
194194
y_bottom = y_ranges.second.first;
195195
}
196196
// fill in the sensors on negative y
197197
while ( (y_bottom - sensorStackHeight) >= -max_sensor_y_abs ) {
198+
LOG(info) << "\t\tPlacing " << kSensorStack << " sensors at y = " << y_bottom
199+
<< " to " << (y_bottom - sensorStackHeight)
200+
<< " with x_left = " << x_left;
198201
y_positions.second.emplace_back(y_bottom, kSensorStack);
199202
y_bottom -= sensorAbsStackYShift;
200203
}
@@ -658,6 +661,7 @@ void FT3Module::create_layout_staveGeo(double mZ, int layerNumber, int direction
658661
}
659662
}
660663

664+
// Create volumes for the sensors and the support materials on top of the stave
661665
for (unsigned i_stave = 0; i_stave < Constants::x_midpoints.size(); i_stave++) {
662666
double x_mid = Constants::x_midpoints[i_stave];
663667
int staveID = Constants::staveIdxToID(i_stave);
@@ -686,12 +690,12 @@ void FT3Module::create_layout_staveGeo(double mZ, int layerNumber, int direction
686690
: -Constants::z_offsetStave;
687691
}
688692

689-
for (unsigned i_y_pos = 0; i_y_pos < y_positionsPosNeg[i_stave].first.size(); i_y_pos++) {
690-
for (int y_sign = -1; y_sign < 2; y_sign+=2) {
691-
// place sensors at positive and negative y
692-
const auto& positions = (y_sign == 1) ? y_positionsPosNeg[i_stave].first
693-
: y_positionsPosNeg[i_stave].second;
694-
// define starting midpoint: y = y_start +- distance to middle of sensor
693+
for (int y_sign = -1; y_sign < 2; y_sign+=2) {
694+
// place sensors at positive and negative y
695+
const auto& positions = (y_sign == 1) ? y_positionsPosNeg[i_stave].first
696+
: y_positionsPosNeg[i_stave].second;
697+
// define starting midpoint: y = y_start +- distance to middle of sensor
698+
for (unsigned i_y_pos = 0; i_y_pos < positions.size(); i_y_pos++) {
695699
double y_mid = positions[i_y_pos].first + y_sign * Constants::sensor2x1_height / 2;
696700
for (unsigned i_sens = 0; i_sens < positions[i_y_pos].second; i_sens++) {
697701
TGeoVolume* sensor;

0 commit comments

Comments
 (0)