ATLAS Offline Software
Loading...
Searching...
No Matches
ALFA_EdgeMethod.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 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.empty() ){
150 for(UInt_t i = 0; i < corridors.size()-1; i++){
151 if( std::abs( corridors.at(i).first.first - corridors.at(i+1).first.first ) < 0.480){
152 if( corridors.at(i).second > corridors.at(i+1).second ){
153 corridors.erase(corridors.begin()+i+1);
154 i--;
155 } else if ( corridors.at(i).second < corridors.at(i+1).second ){
156 corridors.erase(corridors.begin()+i);
157 i--;
158 }
159 }
160 }
161 }
162
163}
164
165Bool_t ALFA_EdgeMethod::testTrack(/*Corridor corr_U, Corridor corr_V*/)
166{
167 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::testTrack()");
168
169 return kTRUE;
170}
171
172Bool_t ALFA_EdgeMethod::iterOne(UInt_t no_Detector, UInt_t no_Orient, std::vector< Corridor > &corridors )
173{
174 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterOne()");
175
176 std::vector< Edge > edges;
177
178 findEdges( no_Detector, no_Orient, edges);
179 if( edges.empty() ) return kFALSE;
180 sort( edges.begin(), edges.end(), functionSortEdges );
181
182 findCorridors(edges, corridors);
183 if( corridors.empty() )
184 return kFALSE;
185
186 if(m_bOpt_Sisters){
187 // Cut for sisters
188 // Other corridors must have more than half of first corridor hits
189 UInt_t minHits = 0.5*corridors.front().second;
190 UInt_t maxCorr = 1;
191 while( maxCorr < corridors.size() && minHits < corridors.at(maxCorr).second ){
192 maxCorr++;
193 }
194 if( maxCorr != corridors.size() ){
195 corridors.resize( maxCorr );
196 }
197 }
198
199 sort( corridors.begin(), corridors.end(), functionSortCorrsOne );
200 if( corridors.size() > 5 ){
201 corridors.resize(5);
202 }
203 return kTRUE;
204}
205
206
207Bool_t ALFA_EdgeMethod::iterationOne(UInt_t no_Detector, std::vector<Track> &tracks )
208{
209 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterationOne()");
210
211 tracks.clear();
212 readUVONE(no_Detector);
213
214 std::vector< Corridor > corr_U;
215 std::vector< Corridor > corr_V;
216 if( !iterOne(no_Detector, 0, corr_U) || !iterOne(no_Detector, 1, corr_V) ) return kFALSE;
217
218 for(auto & i : corr_U){
219 for(auto & j : corr_V){
220 if( testTrack( /*corr_U.at(i), corr_V.at(j)*/ ) ){
221 tracks.emplace_back( i, j );
222 }
223 }
224 }
225
226 if( tracks.empty() ) return kFALSE;
227 sort( tracks.begin(), tracks.end(), functionSortTracks );
228 if( tracks.size() > 10 ){
229 tracks.resize(10);
230 }
231 return kTRUE;
232}
233
234Bool_t ALFA_EdgeMethod::iterNext(UInt_t no_Detector, UInt_t no_Orient, Float_t pos, Int_t level, Corridor &corr)
235{
236 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterNext()");
237
238 std::vector< Edge > edges;
239 findEdges( no_Detector, no_Orient, edges);
240 sort( edges.begin(), edges.end(), functionSortEdges );
241
242 std::vector< Corridor > corridors;
243 findCorridors(edges, corridors);
244 if( corridors.empty() ) return kFALSE;
245
246 sort( corridors.begin(), corridors.end(), CSortCorrsNext(pos));
247 if( std::abs( pos - corridors.front().first.first ) > 0.480 || std::abs( level - (Int_t)corridors.front().second ) > 1 ) return kFALSE;
248
249 corr = corridors.front();
250 return kTRUE;
251}
252
253Bool_t ALFA_EdgeMethod::iterationNext(UInt_t no_Detector, std::vector<Track> &tracks )
254{
255 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::iterationNext()");
256
257 Corridor corr_U;
258 Corridor corr_V;
259 Bool_t rem;
260
261 for(UInt_t i = 0; i < tracks.size(); i++){
262 readUVONE(no_Detector, tracks.at(i).first.first.first, tracks.at(i).second.first.first );
263 rem = iterNext(no_Detector, 0, tracks.at(i).first.first.first, tracks.at(i).first.second, corr_U) && iterNext(no_Detector, 1, tracks.at(i).second.first.first, tracks.at(i).second.second, corr_V);
264 if( rem && testTrack(/*corr_U, corr_V*/) ){
265 tracks.at(i) = make_pair( corr_U, corr_V );
266 } else {
267 tracks.erase(tracks.begin()+i);
268 i--;
269 }
270 }
271
272 if( tracks.empty() ) return kFALSE;
273 return kTRUE;
274}
275
276Bool_t ALFA_EdgeMethod::EdgeMethod(UInt_t no_Detector, std::vector<Track> &tracks)
277{
278 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::EdgeMethod()");
279
280 if(!iterationOne(no_Detector, tracks )) return kFALSE;
281 if(!iterationNext(no_Detector, tracks )) return kFALSE;
282 if(!iterationNext(no_Detector, tracks )) return kFALSE;
283
284 for(UInt_t i = 0; i < tracks.size(); i++){
285 for(UInt_t j = i+1; j < tracks.size(); j++){
286 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 ){
287 tracks.erase( tracks.begin() + j );
288 j--;
289 }
290 }
291 }
292
293 ATH_MSG_DEBUG("end ALFA_EdgeMethod::EdgeMethod()");
294 return kTRUE;
295}
296
297
298void ALFA_EdgeMethod::selectedFibers(UInt_t no_Detector, Track &track, Int_t * selectedFib)
299{
300 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::selectedFibers()");
301
302 readUVONE(no_Detector, track.first.first.first, track.second.first.first );
303
304 UInt_t nF = 0;
305 for(UInt_t nL = 0; nL < 20; nL+=2){
306 selectedFib[nL] = 9999;
307 while( nF != 63 && (m_uv_geo[no_Detector][nL][nF] + 0.2401) <= (track.first.first.first + 0.5 * track.first.first.second) ){
308 nF++;
309 }
310
311 if( (m_uv_geo[no_Detector][nL][nF]-0.2401) <= track.first.first.first - 0.5 * track.first.first.second ){
312 if( m_bFiberHitsMD[no_Detector][nL][nF] ){
313 selectedFib[nL] = nF;
314 } else {
315 selectedFib[nL] = nF + 9000;
316 }
317 } else {
318 if( nF != 0 && m_bFiberHitsMD[no_Detector][nL][nF] && m_bFiberHitsMD[no_Detector][nL][nF-1] ){
319 selectedFib[nL] = nF + 2999;
320 } 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] ){
321 selectedFib[nL] = nF + 2000;
322 } 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] ){
323 selectedFib[nL] = nF + 999;
324 } else {
325 selectedFib[nL] = nF + 9000;
326 }
327 }
328
329 nF > 4 ? nF -= 5 : nF = 0;
330 }
331
332 nF = 0;
333 for(UInt_t nL = 1; nL < 20; nL+=2){
334 selectedFib[nL] = 9999;
335 while( nF != 63 && (m_uv_geo[no_Detector][nL][nF] + 0.2401) <= track.second.first.first + 0.5 * track.second.first.second ){
336 nF++;
337 }
338
339 if( (m_uv_geo[no_Detector][nL][nF]-0.2401) <= track.second.first.first - 0.5 * track.second.first.second ){
340 if( m_bFiberHitsMD[no_Detector][nL][nF] ){
341 selectedFib[nL] = nF;
342 } else {
343 selectedFib[nL] = nF + 9000;
344 }
345 } else {
346 if( nF != 0 && m_bFiberHitsMD[no_Detector][nL][nF] && m_bFiberHitsMD[no_Detector][nL][nF-1] ){
347 selectedFib[nL] = nF + 2999;
348 } 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] ){
349 selectedFib[nL] = nF + 2000;
350 } 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] ){
351 selectedFib[nL] = nF + 999;
352 } else {
353 selectedFib[nL] = nF + 9000;
354 }
355 }
356
357 nF > 4 ? nF -= 5 : nF = 0;
358 }
359
360 if(m_bOpt_UseGaps){
361 Int_t fLow, fCur;
362 Float_t fLeft, fRight;
363
364 for(UInt_t nL = 0; nL < 16; nL+=2){
365 fLow = selectedFib[nL]%1000;
366// if( fLow > 0 && fLow < 63 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
367 if( fLow > 1 && fLow < 62 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
368 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow] ){
369 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow+1] ){
370 fCur = fLow+1;
371 } else {
372 fCur = fLow;
373 }
374 } else {
375 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow-1] ){
376 fCur = fLow-1;
377 } else {
378 fCur = fLow-2;
379 }
380 }
381 fLeft = m_uv_geo[no_Detector][nL+2][fCur] + 0.2399;
382 fRight = m_uv_geo[no_Detector][nL+2][fCur+1] - 0.2401;
383
384 if( fLeft < fRight ){
385
386 if( fLeft > track.first.first.first - 0.5 * track.first.first.second && fLeft < track.first.first.first + 0.5 * track.first.first.second ){
387 track.first.first.first = 0.5 * ( track.first.first.first + 0.5 * track.first.first.second + fLeft );
388 track.first.first.second = 2 * ( track.first.first.first - fLeft );
389 }
390
391 if( fRight > track.first.first.first - 0.5 * track.first.first.second && fRight < track.first.first.first + 0.5 * track.first.first.second ){
392 track.first.first.first = 0.5 * ( track.first.first.first - 0.5 * track.first.first.second + fRight );
393 track.first.first.second = 2 * ( fRight - track.first.first.first );
394 }
395 }
396 nL += 2;
397 }
398 }
399
400 for(UInt_t nL = 1; nL < 17; nL+=2){
401 fLow = selectedFib[nL]%1000;
402// if( fLow > 0 && fLow < 63 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
403 if( fLow > 1 && fLow < 62 && selectedFib[nL] < 8000 && selectedFib[nL+2] > 8000 && selectedFib[nL+4] < 8000 ){
404 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow] ){
405 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow+1] ){
406 fCur = fLow+1;
407 } else {
408 fCur = fLow;
409 }
410 } else {
411 if( m_uv_geo[no_Detector][nL][fLow] > m_uv_geo[no_Detector][nL+2][fLow-1] ){
412 fCur = fLow-1;
413 } else {
414 fCur = fLow-2;
415 }
416 }
417 fLeft = m_uv_geo[no_Detector][nL+2][fCur] + 0.2399;
418 fRight = m_uv_geo[no_Detector][nL+2][fCur+1] - 0.2401;
419 if( fLeft < fRight ){
420
421 if( fLeft > track.second.first.first - 0.5 * track.second.first.second && fLeft < track.second.first.first + 0.5 * track.second.first.second ){
422 track.second.first.first = 0.5 * ( track.second.first.first + 0.5 * track.second.first.second + fLeft );
423 track.second.first.second = 2 * ( track.second.first.first - fLeft );
424 }
425
426 if( fRight > track.second.first.first - 0.5 * track.second.first.second && fRight < track.second.first.first + 0.5 * track.second.first.second ){
427 track.second.first.first = 0.5 * ( track.second.first.first - 0.5 * track.second.first.second + fRight );
428 track.second.first.second = 2 * ( fRight - track.second.first.first );
429 }
430 }
431
432 nL += 2;
433 }
434 }
435 }
436}
437
438
439
440
441//Read fibers positions in u&v for pot no_Detector (usig u_pos and v_pos for correction)
442void ALFA_EdgeMethod::readUVONE(Int_t no_Detector, Double_t u_pos, Double_t v_pos)
443{
444 ATH_MSG_DEBUG("begin ALFA_EdgeMethod::readUVONE()");
445
446 for(Int_t no_Layer=0; no_Layer<20; no_Layer++){
447 if(m_faMD[no_Detector][no_Layer][0]<0){
448 for(Int_t no_Fiber=0; no_Fiber<64; no_Fiber++){
449 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]);
450 }
451 } else {
452 for(Int_t no_Fiber=0; no_Fiber<64; no_Fiber++){
453 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]);
454 }
455 }
456 }
457}
458
459
460
462 : m_fPosTr(fPosTr)
463{
464
465}
466
468{
469 return (std::abs( corr1.first.first - m_fPosTr ) < std::abs( corr2.first.first - m_fPosTr ));
470}
#define RPOTSCNT
#define ALFALAYERSCNT
#define ALFAPLATESCNT
#define ALFAFIBERSCNT
#define ATH_MSG_DEBUG(x)
#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.