ATLAS Offline Software
Loading...
Searching...
No Matches
ALFA_EdgeMethod.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <algorithm>
7
8using namespace std;
9
14
15ALFA_EdgeMethod::ALFA_EdgeMethod(Bool_t bOpt_Sisters, Bool_t bOpt_UseGaps) :
16 AthMessaging("ALFA_EdgeMethod"),
17 m_bOpt_Sisters (bOpt_Sisters),
18 m_bOpt_UseGaps (bOpt_UseGaps)
19{
20}
21
26
27void ALFA_EdgeMethod::Initialize(Int_t iRPot, Float_t faMD[RPOTSCNT][ALFALAYERSCNT*ALFAPLATESCNT][ALFAFIBERSCNT], Float_t fbMD[RPOTSCNT][ALFALAYERSCNT*ALFAPLATESCNT][ALFAFIBERSCNT], const std::list<MDHIT> &ListMDHits)
28{
29 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::Initialize()");
30
31 for (Int_t iPot = 0; iPot < RPOTSCNT; iPot++)
32 {
33 for (Int_t iLayer = 0; iLayer < ALFALAYERSCNT*ALFAPLATESCNT; iLayer++)
34 {
35 for (Int_t iFiber = 0; iFiber < ALFAFIBERSCNT; iFiber++)
36 {
37 m_faMD[iPot][iLayer][iFiber] = faMD[iPot][iLayer][iFiber];
38 m_fbMD[iPot][iLayer][iFiber] = fbMD[iPot][iLayer][iFiber];
39 }
40 }
41 }
42
43 memset(&m_bFiberHitsMD, 0, sizeof(m_bFiberHitsMD));
44 memset(&m_iMultiMD, 0, sizeof(m_iMultiMD));
45 std::list<MDHIT>::const_iterator iter;
46 for (iter=ListMDHits.begin(); iter!=ListMDHits.end(); ++iter)
47 {
48 if (iRPot == (*iter).iRPot)
49 {
50 m_bFiberHitsMD[iRPot][(*iter).iPlate][(*iter).iFiber] = true;
51 m_iMultiMD[iRPot][(*iter).iPlate]++;
52 }
53 }
54
55
56 ATH_MSG_DEBUG("end ALFA_EdgeMethod::Initialize()");
57}
58
59
60
62 return ( edg1.first.first < edg2.first.first );
63}
64
66 if( corr1.second == corr2.second ) return ( corr1.first.second > corr2.first.second );
67 else return ( corr1.second > corr2.second );
68}
69
71 if( track1.first.second + track1.second.second == track2.first.second + track2.second.second )
72 return track1.first.first.second + track1.second.first.second > track2.first.first.second + track2.second.first.second;
73 else return track1.first.second + track1.second.second > track2.first.second + track2.second.second;
74}
75
76void ALFA_EdgeMethod::findEdges( UInt_t no_Detector, UInt_t no_Orient, std::vector< Edge > &edges)
77{
78 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::findEdges()");
79
80 edges.clear();
81 UInt_t left;
82
83 for(UInt_t nL=no_Orient; nL<20; nL+=2){
84 for(UInt_t nF=0; nF<64; nF++){
85 if(m_bFiberHitsMD[no_Detector][nL][nF]){
86 left = nF;
87 while( nF!=63 && m_bFiberHitsMD[no_Detector][nL][nF+1]){nF++;}
88
89 if( m_iMultiMD[no_Detector][nL] > 3 ){
90 edges.emplace_back( make_pair( m_uv_geo[no_Detector][nL][left] - 0.240, kTRUE), kFALSE);
91 edges.emplace_back( make_pair( m_uv_geo[no_Detector][nL][nF] + 0.240, kFALSE), kFALSE);
92 } else {
93 edges.emplace_back( make_pair( m_uv_geo[no_Detector][nL][left] - 0.240, kTRUE), kTRUE);
94 edges.emplace_back( make_pair( m_uv_geo[no_Detector][nL][nF] + 0.240, kFALSE), kTRUE);
95 }
96 }
97 }
98 }
99}
100
101void ALFA_EdgeMethod::findCorridors(std::vector< Edge > &edges, std::vector< Corridor > &corridors)
102{
103 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::findCorridors()");
104
105 corridors.clear();
106
107 Int_t level = 0;
108 Int_t alive = 0;
109 Bool_t max = kFALSE;
110 Float_t leftEd = 9999.0;
111
112
113 for(UInt_t i = 0; i< (edges.size()-1); i++){
114 if( edges.at(i).first.second ){
115 level++;
116 if( edges.at(i).second ){
117 alive++;
118 }
119 if( edges.at(i+1).first.second ){
120 continue;
121 } else {
122 if( alive < 3 || max ){
123 continue;
124 } else {
125 leftEd = edges.at(i).first.first;
126 max = kTRUE;
127 }
128 }
129 } else {
130 level--;
131 if( edges.at(i).second ){
132 alive--;
133 }
134 if( max ){
135 if( edges.at(i+1).first.second ){
136 if( edges.at(i+2).first.second ){
137 corridors.emplace_back( make_pair( 0.5*(leftEd + edges.at(i).first.first), edges.at(i).first.first - leftEd), level+1 );
138 max = kFALSE;
139 }
140 continue;
141 } else {
142 corridors.emplace_back( make_pair( 0.5*(leftEd + edges.at(i).first.first), edges.at(i).first.first - leftEd), level+1 );
143 max = kFALSE;
144 }
145 }
146 }
147 }
148
149 if (corridors.size() >= 2) {
150 for (std::size_t i = 0; i + 1 < corridors.size(); /* no increment*/) {
151 auto& a = corridors[i];
152 auto& b = corridors[i + 1];
153 if (std::abs(a.first.first - b.first.first) < 0.480) {
154 if (a.second > b.second) {
155 corridors.erase(corridors.begin() + (i + 1)); // drop b
156 } else if (a.second < b.second) {
157 corridors.erase(corridors.begin() + i); // drop a
158 } else {
159 // equal "score": pick a rule; for example drop the later one
160 corridors.erase(corridors.begin() + (i + 1));
161 }
162 // no increment: re-check at same i with the new neighbor
163 } else {
164 ++i; // only advance when we kept both
165 }
166 }
167}
168}
169
170Bool_t ALFA_EdgeMethod::testTrack(/*Corridor corr_U, Corridor corr_V*/)
171{
172 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::testTrack()");
173
174 return kTRUE;
175}
176
177Bool_t ALFA_EdgeMethod::iterOne(UInt_t no_Detector, UInt_t no_Orient, std::vector< Corridor > &corridors )
178{
179 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterOne()");
180
181 std::vector< Edge > edges;
182
183 findEdges( no_Detector, no_Orient, edges);
184 if( edges.empty() ) return kFALSE;
185 sort( edges.begin(), edges.end(), functionSortEdges );
186
187 findCorridors(edges, corridors);
188 if( corridors.empty() )
189 return kFALSE;
190
191 if(m_bOpt_Sisters){
192 // Cut for sisters
193 // Other corridors must have more than half of first corridor hits
194 UInt_t minHits = 0.5*corridors.front().second;
195 UInt_t maxCorr = 1;
196 while( maxCorr < corridors.size() && minHits < corridors.at(maxCorr).second ){
197 maxCorr++;
198 }
199 if( maxCorr != corridors.size() ){
200 corridors.resize( maxCorr );
201 }
202 }
203
204 sort( corridors.begin(), corridors.end(), functionSortCorrsOne );
205 if( corridors.size() > 5 ){
206 corridors.resize(5);
207 }
208 return kTRUE;
209}
210
211
212Bool_t ALFA_EdgeMethod::iterationOne(UInt_t no_Detector, std::vector<Track> &tracks )
213{
214 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterationOne()");
215
216 tracks.clear();
217 readUVONE(no_Detector);
218
219 std::vector< Corridor > corr_U;
220 std::vector< Corridor > corr_V;
221 if( !iterOne(no_Detector, 0, corr_U) || !iterOne(no_Detector, 1, corr_V) ) return kFALSE;
222
223 for(auto & i : corr_U){
224 for(auto & j : corr_V){
225 if( testTrack( /*corr_U.at(i), corr_V.at(j)*/ ) ){
226 tracks.emplace_back( i, j );
227 }
228 }
229 }
230
231 if( tracks.empty() ) return kFALSE;
232 sort( tracks.begin(), tracks.end(), functionSortTracks );
233 if( tracks.size() > 10 ){
234 tracks.resize(10);
235 }
236 return kTRUE;
237}
238
239Bool_t ALFA_EdgeMethod::iterNext(UInt_t no_Detector, UInt_t no_Orient, Float_t pos, Int_t level, Corridor &corr)
240{
241 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterNext()");
242
243 std::vector< Edge > edges;
244 findEdges( no_Detector, no_Orient, edges);
245 sort( edges.begin(), edges.end(), functionSortEdges );
246
247 std::vector< Corridor > corridors;
248 findCorridors(edges, corridors);
249 if( corridors.empty() ) return kFALSE;
250
251 sort( corridors.begin(), corridors.end(), CSortCorrsNext(pos));
252 if( std::abs( pos - corridors.front().first.first ) > 0.480 || std::abs( level - (Int_t)corridors.front().second ) > 1 ) return kFALSE;
253
254 corr = corridors.front();
255 return kTRUE;
256}
257
258Bool_t ALFA_EdgeMethod::iterationNext(UInt_t no_Detector, std::vector<Track> &tracks )
259{
260 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterationNext()");
261
262 Corridor corr_U;
263 Corridor corr_V;
264
265 for (std::size_t i = 0; i < tracks.size(); /* no increment*/) {
266 auto& tr = tracks[i];
267 readUVONE(no_Detector, tr.first.first.first, tr.second.first.first);
268 bool rem =
269 iterNext(no_Detector, 0, tr.first.first.first, tr.first.second, corr_U) &&
270 iterNext(no_Detector, 1, tr.second.first.first, tr.second.second, corr_V);
271 //
272 if (rem && testTrack(/*corr_U, corr_V*/)) {
273 tr = std::make_pair(corr_U, corr_V);
274 ++i; // advance only when we keep the element
275 } else {
276 tracks.erase(tracks.begin() + i); // don’t advance; next element overwrites
277 }
278}
279
280 if( tracks.empty() ) return kFALSE;
281 return kTRUE;
282}
283
284Bool_t ALFA_EdgeMethod::EdgeMethod(UInt_t no_Detector, std::vector<Track> &tracks)
285{
286 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::EdgeMethod()");
287
288 if(!iterationOne(no_Detector, tracks )) return kFALSE;
289 if(!iterationNext(no_Detector, tracks )) return kFALSE;
290 if(!iterationNext(no_Detector, tracks )) return kFALSE;
291
292 for(UInt_t i = 0; i < tracks.size(); i++){
293 for(UInt_t j = i+1; j < tracks.size(); j++){
294 if( std::abs( tracks.at(i).first.first.first - tracks.at(j).first.first.first) < 0.002 && std::abs( tracks.at(i).second.first.first - tracks.at(j).second.first.first ) < 0.002 ){
295 tracks.erase( tracks.begin() + j );
296 j--;
297 }
298 }
299 }
300
301 ATH_MSG_DEBUG("end ALFA_EdgeMethod::EdgeMethod()");
302 return kTRUE;
303}
304
305
306void ALFA_EdgeMethod::selectedFibers(UInt_t no_Detector, Track &track, Int_t * selectedFib)
307{
308 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::selectedFibers()");
309
310 readUVONE(no_Detector, track.first.first.first, track.second.first.first );
311
312 UInt_t nF = 0;
313 for(UInt_t nL = 0; nL < 20; nL+=2){
314 selectedFib[nL] = 9999;
315 while( nF != 63 && (m_uv_geo[no_Detector][nL][nF] + 0.2401) <= (track.first.first.first + 0.5 * track.first.first.second) ){
316 nF++;
317 }
318
319 if( (m_uv_geo[no_Detector][nL][nF]-0.2401) <= track.first.first.first - 0.5 * track.first.first.second ){
320 if( m_bFiberHitsMD[no_Detector][nL][nF] ){
321 selectedFib[nL] = nF;
322 } else {
323 selectedFib[nL] = nF + 9000;
324 }
325 } else {
326 if( nF != 0 && m_bFiberHitsMD[no_Detector][nL][nF] && m_bFiberHitsMD[no_Detector][nL][nF-1] ){
327 selectedFib[nL] = nF + 2999;
328 } else if( (m_uv_geo[no_Detector][nL][nF]-0.2401) <= track.first.first.first + 0.5 * track.first.first.second && m_bFiberHitsMD[no_Detector][nL][nF] ){
329 selectedFib[nL] = nF + 2000;
330 } else if ( nF != 0 && (m_uv_geo[no_Detector][nL][nF-1]+0.2401) <= track.first.first.first - 0.5 * track.first.first.second && m_bFiberHitsMD[no_Detector][nL][nF-1] ){
331 selectedFib[nL] = nF + 999;
332 } else {
333 selectedFib[nL] = nF + 9000;
334 }
335 }
336
337 nF > 4 ? nF -= 5 : nF = 0;
338 }
339
340 nF = 0;
341 for(UInt_t nL = 1; nL < 20; nL+=2){
342 selectedFib[nL] = 9999;
343 while( nF != 63 && (m_uv_geo[no_Detector][nL][nF] + 0.2401) <= track.second.first.first + 0.5 * track.second.first.second ){
344 nF++;
345 }
346
347 if( (m_uv_geo[no_Detector][nL][nF]-0.2401) <= track.second.first.first - 0.5 * track.second.first.second ){
348 if( m_bFiberHitsMD[no_Detector][nL][nF] ){
349 selectedFib[nL] = nF;
350 } else {
351 selectedFib[nL] = nF + 9000;
352 }
353 } else {
354 if( nF != 0 && m_bFiberHitsMD[no_Detector][nL][nF] && m_bFiberHitsMD[no_Detector][nL][nF-1] ){
355 selectedFib[nL] = nF + 2999;
356 } else if( (m_uv_geo[no_Detector][nL][nF]-0.2401) <= track.second.first.first + 0.5 * track.second.first.second && m_bFiberHitsMD[no_Detector][nL][nF] ){
357 selectedFib[nL] = nF + 2000;
358 } else if ( nF != 0 && (m_uv_geo[no_Detector][nL][nF-1]+0.2401) <= track.second.first.first - 0.5 * track.second.first.second && m_bFiberHitsMD[no_Detector][nL][nF-1] ){
359 selectedFib[nL] = nF + 999;
360 } else {
361 selectedFib[nL] = nF + 9000;
362 }
363 }
364
365 nF > 4 ? nF -= 5 : nF = 0;
366 }
367
368 if(m_bOpt_UseGaps){
369 Int_t fLow, fCur;
370 Float_t fLeft, fRight;
371
372 for(UInt_t nL = 0; nL < 16; nL+=2){
373 fLow = selectedFib[nL]%1000;
374// if( fLow > 0 && fLow < 63 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
375 if( fLow > 1 && fLow < 62 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
376 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow] ){
377 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow+1] ){
378 fCur = fLow+1;
379 } else {
380 fCur = fLow;
381 }
382 } else {
383 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow-1] ){
384 fCur = fLow-1;
385 } else {
386 fCur = fLow-2;
387 }
388 }
389 fLeft = m_uv_geo[no_Detector][nL+2][fCur] + 0.2399;
390 fRight = m_uv_geo[no_Detector][nL+2][fCur+1] - 0.2401;
391
392 if( fLeft < fRight ){
393
394 if( fLeft > track.first.first.first - 0.5 * track.first.first.second && fLeft < track.first.first.first + 0.5 * track.first.first.second ){
395 track.first.first.first = 0.5 * ( track.first.first.first + 0.5 * track.first.first.second + fLeft );
396 track.first.first.second = 2 * ( track.first.first.first - fLeft );
397 }
398
399 if( fRight > track.first.first.first - 0.5 * track.first.first.second && fRight < track.first.first.first + 0.5 * track.first.first.second ){
400 track.first.first.first = 0.5 * ( track.first.first.first - 0.5 * track.first.first.second + fRight );
401 track.first.first.second = 2 * ( fRight - track.first.first.first );
402 }
403 }
404 nL += 2;
405 }
406 }
407
408 for(UInt_t nL = 1; nL < 17; nL+=2){
409 fLow = selectedFib[nL]%1000;
410// if( fLow > 0 && fLow < 63 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
411 if( fLow > 1 && fLow < 62 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
412 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow] ){
413 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow+1] ){
414 fCur = fLow+1;
415 } else {
416 fCur = fLow;
417 }
418 } else {
419 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow-1] ){
420 fCur = fLow-1;
421 } else {
422 fCur = fLow-2;
423 }
424 }
425 fLeft = m_uv_geo[no_Detector][nL+2][fCur] + 0.2399;
426 fRight = m_uv_geo[no_Detector][nL+2][fCur+1] - 0.2401;
427 if( fLeft < fRight ){
428
429 if( fLeft > track.second.first.first - 0.5 * track.second.first.second && fLeft < track.second.first.first + 0.5 * track.second.first.second ){
430 track.second.first.first = 0.5 * ( track.second.first.first + 0.5 * track.second.first.second + fLeft );
431 track.second.first.second = 2 * ( track.second.first.first - fLeft );
432 }
433
434 if( fRight > track.second.first.first - 0.5 * track.second.first.second && fRight < track.second.first.first + 0.5 * track.second.first.second ){
435 track.second.first.first = 0.5 * ( track.second.first.first - 0.5 * track.second.first.second + fRight );
436 track.second.first.second = 2 * ( fRight - track.second.first.first );
437 }
438 }
439
440 nL += 2;
441 }
442 }
443 }
444}
445
446
447
448
449//Read fibers positions in u&v for pot no_Detector (usig u_pos and v_pos for correction)
450void ALFA_EdgeMethod::readUVONE(Int_t no_Detector, Double_t u_pos, Double_t v_pos)
451{
452 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::readUVONE()");
453
454 for(Int_t no_Layer=0; no_Layer<20; no_Layer++){
455 if(m_faMD[no_Detector][no_Layer][0]<0){
456 for(Int_t no_Fiber=0; no_Fiber<64; no_Fiber++){
457 m_uv_geo[no_Detector][no_Layer][no_Fiber]=(v_pos*(1+m_faMD[no_Detector][no_Layer][no_Fiber])-1.414213562373095*m_fbMD[no_Detector][no_Layer][no_Fiber])/(1-m_faMD[no_Detector][no_Layer][no_Fiber]);
458 }
459 } else {
460 for(Int_t no_Fiber=0; no_Fiber<64; no_Fiber++){
461 m_uv_geo[no_Detector][no_Layer][no_Fiber]=(u_pos*(1-m_faMD[no_Detector][no_Layer][no_Fiber])+1.414213562373095*m_fbMD[no_Detector][no_Layer][no_Fiber])/(1+m_faMD[no_Detector][no_Layer][no_Fiber]);
462 }
463 }
464 }
465}
466
467
468
470 : m_fPosTr(fPosTr)
471{
472
473}
474
476{
477 return (std::abs( corr1.first.first - m_fPosTr ) < std::abs( corr2.first.first - m_fPosTr ));
478}
#define RPOTSCNT
#define ALFALAYERSCNT
#define ALFAPLATESCNT
#define ALFAFIBERSCNT
#define ATH_MSG_DEBUG(x)
static Double_t a
#define max(a, b)
Definition cfImp.cxx:41
Double_t m_uv_geo[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT]
Bool_t iterationNext(UInt_t no_Detector, std::vector< Track > &tracks)
Int_t m_iMultiMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT]
void readUVONE(Int_t no_Detector, Double_t u_pos=91.0, Double_t v_pos=-91.0)
Bool_t iterNext(UInt_t no_Detector, UInt_t no_Orient, Float_t pos, Int_t level, Corridor &corr)
static Bool_t functionSortCorrsOne(Corridor corr1, Corridor corr2)
void findEdges(UInt_t no_Detector, UInt_t no_Orient, std::vector< Edge > &edges)
static Bool_t functionSortEdges(Edge edg1, Edge edg2)
Float_t m_fbMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT]
Bool_t m_bFiberHitsMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT]
std::pair< std::pair< Float_t, Float_t >, UInt_t > Corridor
void selectedFibers(UInt_t no_Detector, Track &track, Int_t *selectedFib)
void Initialize(Int_t iRPot, Float_t faMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT], Float_t fbMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT], const std::list< MDHIT > &ListMDHits)
std::pair< std::pair< Float_t, Bool_t >, Bool_t > Edge
void findCorridors(std::vector< Edge > &edges, std::vector< Corridor > &corridors)
Bool_t EdgeMethod(UInt_t no_Detector, std::vector< Track > &tracks)
Bool_t iterOne(UInt_t no_Detector, UInt_t no_Orient, std::vector< Corridor > &corridors)
Bool_t iterationOne(UInt_t no_Detector, std::vector< Track > &tracks)
static Bool_t functionSortTracks(Track track1, Track track2)
Float_t m_faMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT]
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
CSortCorrsNext(const Float_t fPosTr)
bool operator()(ALFA_EdgeMethod::Corridor corr1, ALFA_EdgeMethod::Corridor corr2) const
STL namespace.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.