Skip to content

Commit e5f6686

Browse files
authored
Fix invalid access in RecHitProcessor::processLook
1 parent dc30688 commit e5f6686

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

L1Trigger/L1TMuonCPPF/src/RecHitProcessor.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,30 +171,31 @@ void RecHitProcessor::processLook(const edm::Event &iEvent,
171171
// Condition to save the CPPFDigi
172172
if (((*cppf1).rawId == rawId) && ((*cppf1).strip == rechitstrip)) {
173173
int old_strip = (*cppf1).strip;
174-
int before = 0;
175-
int after = 0;
174+
int before = (*cppf1).strip;
175+
int after = (*cppf1).strip;
176176

177-
if (cppf1 != CppfVec1.begin())
177+
if (std::distance(CppfVec1.begin(), cppf1) >= 2)
178178
before = (*(cppf1 - 2)).strip;
179-
else if (cppf1 == CppfVec1.begin())
180-
before = (*cppf1).strip;
181-
if (cppf1 != CppfVec1.end())
179+
180+
if (std::distance(cppf1, CppfVec1.end()) > 2)
182181
after = (*(cppf1 + 2)).strip;
183-
else if (cppf1 == CppfVec1.end())
184-
after = (*cppf1).strip;
182+
185183
cppf = cppf1;
186184

187185
if (clustersize == 2) {
186+
bool can_move_back = cppf1 != CppfVec1.begin();
187+
bool can_move_fwd = std::next(cppf1) != CppfVec1.end();
188+
188189
if (firststrip == 1) {
189-
if (before < after)
190-
cppf = (cppf1 - 1);
191-
else if (before > after)
192-
cppf = (cppf1 + 1);
190+
if (before < after && can_move_back)
191+
cppf = cppf1 - 1;
192+
else if (before > after && can_move_fwd)
193+
cppf = cppf1 + 1;
193194
} else if (firststrip > 1) {
194-
if (before < after)
195-
cppf = (cppf1 + 1);
196-
else if (before > after)
197-
cppf = (cppf1 - 1);
195+
if (before < after && can_move_fwd)
196+
cppf = cppf1 + 1;
197+
else if (before > after && can_move_back)
198+
cppf = cppf1 - 1;
198199
}
199200
}
200201
// Using the RPCGeometry

0 commit comments

Comments
 (0)