ATLAS Offline Software
ALFA_HalfReco.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8  AthMessaging("ALFA_HalfReco")
9 {
10  ATH_MSG_DEBUG("begin ALFA_HalfReco::ALFA_HalfReco");
11 
12  m_fOvU = 0.0;
13  m_fOvV = 0.0;
14  m_fOverlapCut = 0.0;
15  m_fRecXPos = -9999.0;
16  m_fRecYPos = -9999.0;
17  m_iHalf = 0;
19 
20 // memset(&m_iNumHitsLayer, 0, sizeof(m_iNumHitsLayer));
21 
22  memset(&m_fhits, 0, sizeof(m_fhits));
23  std::fill_n(m_fhits, sizeof(m_fhits)/sizeof(Int_t), -9999);
24 
25  m_iNumU = 0;
26  m_iNumV = 0;
27  m_iRPot = 0;
28  m_iUVCut = 0;
29 
30  ATH_MSG_DEBUG("end ALFA_HalfReco::ALFA_HalfReco");
31 }
32 
34 {
35 }
36 
37 StatusCode ALFA_HalfReco::Initialize(Float_t faMD[RPOTSCNT][ALFALAYERSCNT*ALFAPLATESCNT][ALFAFIBERSCNT], Float_t fbMD[RPOTSCNT][ALFALAYERSCNT*ALFAPLATESCNT][ALFAFIBERSCNT], Int_t iHalf, Int_t fMultiplicityCut, Int_t iUVCut, Float_t fOverlapCut)
38 {
39  ATH_MSG_DEBUG("begin ALFA_HalfReco::Initialize()");
40 
41  m_iMultiplicityCut = fMultiplicityCut;
42  m_iUVCut = iUVCut;
43  m_fOverlapCut = fOverlapCut;
44  m_iHalf = iHalf;
45 
46  for (Int_t iRPot = 0; iRPot < RPOTSCNT; iRPot++)
47  {
48  for (Int_t iLayer = 0; iLayer < ALFALAYERSCNT*ALFAPLATESCNT; iLayer++)
49  {
50  for (Int_t iFiber = 0; iFiber < ALFAFIBERSCNT; iFiber++)
51  {
52  m_faMD[iRPot][iLayer][iFiber] = faMD[iRPot][iLayer][iFiber];
53  m_fbMD[iRPot][iLayer][iFiber] = fbMD[iRPot][iLayer][iFiber];
54  }
55  }
56  }
57 
58  ATH_MSG_DEBUG("end ALFA_HalfReco::Initialize()");
59 
60  return StatusCode::SUCCESS;
61 }
62 
63 StatusCode ALFA_HalfReco::Execute(Int_t iRPot, const std::list<MDHIT> &ListMDHits)
64 {
65  ATH_MSG_DEBUG("ALFA_HalfReco::Execute()");
66 
67  FIBERS structFibers;
68  Int_t iNumUFiberHits = 0; //u_hits, v_hits (a condition for the UVCut 3)
69  Int_t iNumVFiberHits = 0;
70 
71  m_iRPot = iRPot;
72  m_MapLayers.clear();
73 
74  std::list<MDHIT>::const_iterator iter;
75  for (iter=ListMDHits.begin(); iter!=ListMDHits.end(); ++iter)
76  {
77  if (iRPot == (*iter).iRPot)
78  {
79  if(m_MapLayers.find((*iter).iPlate)==m_MapLayers.end())
80  {
81  structFibers.ListFibers.clear();
82  m_MapLayers.insert(std::pair<int, FIBERS>((*iter).iPlate, structFibers));
83  m_MapLayers[(*iter).iPlate].ListFibers.push_back((*iter).iFiber);
84  }
85  else
86  {
87  m_MapLayers[(*iter).iPlate].ListFibers.push_back((*iter).iFiber);
88  }
89  }
90  }
91 
92  //Checking that the multiplicity cut conditions are satisfied
93  //At least more than UV_cut layers have a multiplicity lower than multi_cut
94 // for (Int_t i=half_ch*10;i<half_ch*10+10;i++)
96  {
97 // if (m_iNumHitsLayer[i] <= m_iMultiplicityCut && m_iNumHitsLayer[i] > 0)
98  if ((Int_t)m_MapLayers[i].ListFibers.size()<=m_iMultiplicityCut && (Int_t)m_MapLayers[i].ListFibers.size()>0)
99  {
100  if (fmod(double(i),double(2)) == 1) iNumUFiberHits++;
101  else iNumVFiberHits++;
102  }
103  }
104 
105 
106  // RECONSTRUCTION
107  m_fRecXPos = -9999.0;
108  m_fRecYPos = -9999.0;
109  m_fOvU = -9999.0;
110  m_fOvV = -9999.0;
111 
112  memset(&m_fhits, 0, sizeof(m_fhits));
113  std::fill_n(m_fhits, sizeof(m_fhits)/sizeof(Int_t), -9999);
114 
115  if (iNumUFiberHits>=m_iUVCut && iNumVFiberHits>=m_iUVCut) OverLap();
116 
117  ATH_MSG_DEBUG("end ALFA_HalfReco::Execute()");
118  return StatusCode::SUCCESS;
119 }
120 
121 StatusCode ALFA_HalfReco::Finalize(Float_t &fRecXPos, Float_t &fRecYPos)
122 {
123  ATH_MSG_DEBUG("begin ALFA_HalfReco::Finalize()");
124 
125  fRecXPos = m_fRecXPos;
126  fRecYPos = m_fRecYPos;
127 
128  ATH_MSG_DEBUG("end ALFA_HalfReco::Execute()");
129  return StatusCode::SUCCESS;
130 }
131 
132 void ALFA_HalfReco::HistFill(Float_t &b_p, Float_t &b_n, Float_t &Ov_p, Float_t &Ov_n, Int_t &NumU, Int_t &NumV, Int_t iFlag)
133 {
134  ATH_MSG_DEBUG("ALFA_HalfReco::HistFill()");
135 
136  Int_t iHit;
137  Float_t fFibCen;
138  Float_t b_ref[2] = {-127.0, -127.0};
139  Float_t fXInter, fYInter;
140  Float_t p_min, p_max;
141  Float_t n_min, n_max;
142  Int_t iMinP_tmp, iMaxP_tmp;
143  Int_t iMinN_tmp, iMaxN_tmp;
144  Int_t iFullWidth;
145  const Int_t NBINTOT = 72000;
146  Int_t Over_p[NBINTOT], Over_n[NBINTOT];
147 
148  if (iFlag==0) //First call, Event not reconstructed for U and V
149  {
150  b_ref[0]=-127.0;
151  b_ref[1]=-127.0;
152  }
153 
154  if (iFlag==1) //Event reconstructed for U but not for V so let's try to refine
155  {
156  b_ref[0]=b_p;
157  b_ref[1]=-127.0;
158 
159  }
160 
161  if (iFlag==2) //Event reconstructed for V but not for U so let's try to refine
162  {
163  b_ref[0]=-127.0;
164  b_ref[1]=b_n;
165  }
166 
167  if (iFlag==3) //Event reconstructed for U and V, ultime refinement
168  {
169  b_ref[0]=b_p;
170  b_ref[1]=b_n;
171  }
172 
173  for (Int_t i=0;i<72000;i++)
174  {
175  Over_p[i]=0;
176  Over_n[i]=0;
177  }
178 
179  std::list<int>::iterator intIter;
180 //for(Int_t i=half_ch*10;i<half_ch*10+10;i++)
181  for (Int_t iLayer = ALFAPLATESCNT*m_iHalf; iLayer < m_iHalf*ALFAPLATESCNT+ALFAPLATESCNT; iLayer++)
182  {
183  for (intIter=m_MapLayers[iLayer].ListFibers.begin(); intIter!=m_MapLayers[iLayer].ListFibers.end(); ++intIter)
184  {
185  iHit = *intIter;
186 
187  if (m_faMD[m_iRPot][iLayer][iHit] >= 0)
188  {
189  fXInter = (b_ref[1]-m_fbMD[m_iRPot][iLayer][iHit])/(1+m_faMD[m_iRPot][iLayer][iHit]);
190  fYInter = (m_faMD[m_iRPot][iLayer][iHit]*b_ref[1]+m_fbMD[m_iRPot][iLayer][iHit])/(1+m_faMD[m_iRPot][iLayer][iHit])-b_ref[1];
191  fFibCen = (fYInter-fXInter)/sqrt(2.0);
192 
193  for (Int_t bin=0;bin<480;bin++)
194  {
195  Over_p[(int)((fFibCen-0.24)*1000)+bin+36000]++;
196  }
197  }
198  else
199  {
200  fXInter = (m_fbMD[m_iRPot][iLayer][iHit]-b_ref[0])/(1-m_faMD[m_iRPot][iLayer][iHit]);
201  fYInter = (m_fbMD[m_iRPot][iLayer][iHit]-m_faMD[m_iRPot][iLayer][iHit]*b_ref[0])/(1-m_faMD[m_iRPot][iLayer][iHit])-b_ref[0];
202  fFibCen = (fYInter+fXInter)/sqrt(2.0);
203 
204  for (Int_t bin=0;bin<480;bin++)
205  {
206  Over_n[(int)((fFibCen-0.24)*1000)+bin+36000]++;
207  }
208  }
209  }
210  }
211 
212  //Determine maximum
213  NumU=0;
214  NumV=0;
215 
216  std::vector<int> *max_p = new std::vector<int>;
217  std::vector<int> *max_n = new std::vector<int>;
218 
219  for (Int_t i=0;i<72000;i++)
220  {
221  if (Over_p[i]>NumU) NumU = Over_p[i];
222  if (Over_n[i]>NumV) NumV = Over_n[i];
223  }
224 
225  if (NumU >= m_iUVCut) // If more than m_iUVCut fibers in the maximum we do the reconstruction
226  {
227  for (Int_t i=0;i<72000;i++)
228  {
229  if (Over_p[i]==NumU)
230  {
231  max_p->push_back(i);
232  }
233  }
234 
235  p_min = -36.0 + double(max_p->front())*1e-3;
236  p_max = -36.0 + double(max_p->back())*1e-3;
237  iMinP_tmp = max_p->front();
238  iMaxP_tmp = max_p->back();
239 
240 // Making sure that the plateau belongs to the same track
241  iFullWidth = max_p->size();
242 
243  for (Int_t i=0; i<iFullWidth; i++)
244  {
245  if (max_p->at(iFullWidth-i-1)-iMinP_tmp < 500)
246  {
247  iMaxP_tmp = max_p->at(iFullWidth-i-1);
248  p_max = -36.0 + double(iMaxP_tmp)*1e-3;
249  break;
250  }
251  }
252 
253  if ((p_max-p_min)<m_fOverlapCut) //Check for multiple tracks
254  {
255  b_p = b_ref[1]+(p_min+p_max)/sqrt(2.);
256  Ov_p = p_max-p_min;
257  }
258  else
259  {
260  b_p = -9999.0;
261  Ov_p = -9999.0;
262  }
263  }
264  else
265  {
266  b_p = -9999.0;
267  Ov_p = -9999.0;
268  }
269 
270  if (NumV >= m_iUVCut) // If more than m_iUVCut fibers in the maximum we do the reconstruction
271  {
272  for (Int_t i=0;i<72000;i++)
273  {
274  if (Over_n[i]==NumV)
275  {
276  max_n->push_back(i);
277  }
278  }
279 
280  n_min = -36.0 + double(max_n->front())*1e-3;
281  n_max = -36.0 + double(max_n->back())*1e-3;
282  iMinN_tmp = max_n->front();
283  iMaxN_tmp = max_n->back();
284 
285 // Making sure that the plateau belongs to the same track
286  iFullWidth = max_n->size();
287 
288  for (Int_t i=0; i<iFullWidth; i++)
289  {
290  if (max_n->at(iFullWidth-i-1)-iMinN_tmp < 500)
291  {
292  iMaxN_tmp = max_n->at(iFullWidth-i-1);
293  n_max = -36.0 + double(iMaxN_tmp)*1e-3;
294  break;
295  }
296  }
297 
298  if ((n_max-n_min)<m_fOverlapCut) //Check for multiple tracks
299  {
300  b_n = b_ref[0]+(n_min+n_max)/sqrt(2.);
301  Ov_n = n_max-n_min;
302  }
303  else
304  {
305  b_n = -9999.0;
306  Ov_n = -9999.0;
307  }
308  }
309  else
310  {
311  b_n = -9999.0;
312  Ov_n = -9999.0;
313  }
314 
315  delete max_p;
316  delete max_n;
317 
318  ATH_MSG_DEBUG("endl ALFA_HalfReco::HistFill()");
319 }
320 
322 {
323  ATH_MSG_DEBUG("ALFA_HalfReco::OverLap()");
324 
325  Float_t b_mean_n=-9999.0;
326  Float_t b_mean_p=-9999.0;
327  Float_t overReg_p;
328  Float_t overReg_n;
329  Int_t NumU, NumV;
330 
331  //First call, projection on middle fiber for U and V
332  HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 0);
333 
334  //If first projection worked, we do the ultimate one
335  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0)
336  {
337  HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 3);
338  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0) HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 3);
339  }
340  else
341  {
342  //If first projection worked for p side but not for n, we try to refine n projection using the information from p side
343  if (b_mean_p!=-9999.0 && b_mean_n==-9999.0)
344  {
345  HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 1);
346 
347  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0)
348  {
349  //if it as worked for both we do the ultimate one
350  HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 3);
351  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0) HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 3);
352  }
353  }
354 
355  //If first projection worked for p side but not for n, we try to refine n projection using the information from p side
356  if (b_mean_p==-9999.0 && b_mean_n!=-9999.0)
357  {
358  HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 2);
359 
360  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0)
361  {
362  //if it as worked for both we do the ultimate one
363  HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 3);
364  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0) HistFill(b_mean_p, b_mean_n, overReg_p, overReg_n, NumU, NumV, 3);
365  }
366  }
367  }
368 
369  Float_t x_tmp, y_tmp;
370  Float_t min_x,min_y;
371  Float_t dist_x,dist_y;
372 // Float_t dist_min_x,dist_min_y;
373  Int_t gFib_x, gFib_y;
374  Int_t iHit;
375 
376  Float_t OL_U, OL_V;
377 
378  std::list<int>::iterator intIter;
379  if (b_mean_p!=-9999.0 && b_mean_n!=-9999.0)
380  {
381  m_fRecXPos = (b_mean_n-b_mean_p)/2.0;
382  m_fRecYPos = (b_mean_n+b_mean_p)/2.0;
383  OL_U = overReg_p;
384  OL_V = overReg_n;
385 
386  //for (Int_t i=half_ch*10;i<half_ch*10+10;i++)
387  for (Int_t iLayer = ALFAPLATESCNT*m_iHalf; iLayer<m_iHalf*ALFAPLATESCNT+ALFAPLATESCNT; iLayer++)
388  {
389  min_x = 0.24/cos(TMath::Pi()/4.);
390  min_y = 0.24/cos(TMath::Pi()/4.);
391 
392  gFib_x = 9999;
393  gFib_y = 9999;
394 
395  for (intIter=m_MapLayers[iLayer].ListFibers.begin(); intIter!=m_MapLayers[iLayer].ListFibers.end(); ++intIter)
396  {
397  iHit = *intIter;
398  x_tmp = (m_fRecYPos-m_fbMD[m_iRPot][iLayer][iHit])/m_faMD[m_iRPot][iLayer][iHit];
399  y_tmp = m_faMD[m_iRPot][iLayer][iHit]*m_fRecXPos+m_fbMD[m_iRPot][iLayer][iHit];
400  dist_x = TMath::Abs(m_fRecXPos-x_tmp);
401  dist_y = TMath::Abs(m_fRecYPos-y_tmp);
402 
403  if (dist_x <= min_x)
404  {
405 // dist_min_x = m_fRecXPos-x_tmp;
406  min_x = dist_x;
407  gFib_x = iHit;
408  }
409 
410  if (dist_y <= min_y)
411  {
412 // dist_min_y = m_fRecYPos-y_tmp;
413  min_y = dist_y;
414  gFib_y = iHit;
415  }
416  }
417 
418  if (gFib_x==gFib_y) m_fhits[iLayer]=gFib_x;
419  }
420  }
421  else
422  {
423  m_fRecXPos = -9999.0;
424  m_fRecYPos = -9999.0;
425  NumU = 0;
426  NumV = 0;
427  OL_U = -9999.0;
428  OL_V = -9999.0;
429  }
430 
431  SetData(NumU, NumV, OL_U, OL_V);
432 
433  ATH_MSG_DEBUG("end ALFA_HalfReco::OverLap()");
434 }
435 
436 void ALFA_HalfReco::SetData(Int_t iNumU, Int_t iNumV, Float_t fOvU, Float_t fOvV)
437 {
438  ATH_MSG_DEBUG("begin ALFA_HalfReco::SetData()");
439 
440  m_iNumU = iNumU;
441  m_iNumV = iNumV;
442  m_fOvU = fOvU;
443  m_fOvV = fOvV;
444 
445  ATH_MSG_DEBUG("end ALFA_HalfReco::SetData()");
446 }
447 
448 void ALFA_HalfReco::GetData(Int_t &iNumU, Int_t &iNumV, Float_t &fOvU, Float_t &fOvV, Int_t (&iFibSel)[ALFALAYERSCNT*ALFAPLATESCNT])
449 {
450  ATH_MSG_DEBUG("begin ALFA_HalfReco::GetData()");
451 
452  iNumU = m_iNumU;
453  iNumV = m_iNumV;
454  fOvU = m_fOvU;
455  fOvV = m_fOvV;
456 
457  for (Int_t iLayer=0; iLayer<ALFALAYERSCNT*ALFAPLATESCNT; iLayer++)
458  {
459  iFibSel[iLayer] = m_fhits[iLayer];
460  }
461 
462  ATH_MSG_DEBUG("end ALFA_HalfReco::GetData()");
463 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ALFA_HalfReco::m_fOvV
double m_fOvV
Definition: ALFA_HalfReco.h:42
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ALFA_HalfReco::Execute
StatusCode Execute(Int_t iRPot, const std::list< MDHIT > &ListMDHits)
Definition: ALFA_HalfReco.cxx:63
ALFA_HalfReco::~ALFA_HalfReco
~ALFA_HalfReco()
Definition: ALFA_HalfReco.cxx:33
ALFA_HalfReco::ALFA_HalfReco
ALFA_HalfReco()
Definition: ALFA_HalfReco.cxx:7
ALFAFIBERSCNT
#define ALFAFIBERSCNT
Definition: ALFA_constants.h:10
ALFA_HalfReco::m_iNumV
Int_t m_iNumV
Definition: ALFA_HalfReco.h:41
_FIBERS
Definition: ALFA_LocRec/ALFA_UserObjects.h:30
bin
Definition: BinsDiffFromStripMedian.h:43
RPOTSCNT
#define RPOTSCNT
Definition: ALFA_CLinkAlg.h:26
ALFA_HalfReco::m_fbMD
Float_t m_fbMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT]
Definition: ALFA_HalfReco.h:39
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ALFA_HalfReco::m_faMD
Float_t m_faMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT]
Definition: ALFA_HalfReco.h:38
ALFA_HalfReco::m_fOvU
double m_fOvU
Definition: ALFA_HalfReco.h:42
ALFA_HalfReco::m_iUVCut
Int_t m_iUVCut
Definition: ALFA_HalfReco.h:30
ALFA_HalfReco::HistFill
void HistFill(Float_t &b_p, Float_t &b_n, Float_t &Ov_p, Float_t &Ov_n, Int_t &NumU, Int_t &NumV, Int_t iFlag)
Definition: ALFA_HalfReco.cxx:132
ALFA_HalfReco::m_iHalf
Int_t m_iHalf
Definition: ALFA_HalfReco.h:31
ALFA_HalfReco::Finalize
StatusCode Finalize(Float_t &fRecXPos, Float_t &fRecYPos)
Definition: ALFA_HalfReco.cxx:121
ALFA_HalfReco::GetData
void GetData(Int_t &iNumU, Int_t &iNumV, Float_t &fOvU, Float_t &fOvV, Int_t(&iFibSel)[ALFALAYERSCNT *ALFAPLATESCNT])
Definition: ALFA_HalfReco.cxx:448
ALFA_HalfReco::m_fRecYPos
Float_t m_fRecYPos
Definition: ALFA_HalfReco.h:37
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ALFA_HalfReco::m_iRPot
Int_t m_iRPot
Definition: ALFA_HalfReco.h:32
ALFA_HalfReco.h
ALFA_HalfReco::m_fOverlapCut
Float_t m_fOverlapCut
Definition: ALFA_HalfReco.h:35
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
_FIBERS::ListFibers
std::list< int > ListFibers
Definition: ALFA_LocRec/ALFA_UserObjects.h:31
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
ALFALAYERSCNT
#define ALFALAYERSCNT
Definition: ALFA_constants.h:8
ALFA_HalfReco::m_fRecXPos
Float_t m_fRecXPos
Definition: ALFA_HalfReco.h:36
ALFA_HalfReco::SetData
void SetData(Int_t iNumU, Int_t iNumV, Float_t fOvU, Float_t fOvV)
Definition: ALFA_HalfReco.cxx:436
ALFA_HalfReco::OverLap
void OverLap()
Definition: ALFA_HalfReco.cxx:321
ALFA_HalfReco::m_fhits
Int_t m_fhits[ALFALAYERSCNT *ALFAPLATESCNT]
Definition: ALFA_HalfReco.h:43
ALFA_HalfReco::m_MapLayers
std::map< int, FIBERS > m_MapLayers
Definition: ALFA_HalfReco.h:47
ALFA_HalfReco::Initialize
StatusCode Initialize(Float_t faMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT], Float_t fbMD[RPOTSCNT][ALFALAYERSCNT *ALFAPLATESCNT][ALFAFIBERSCNT], Int_t iHalf, Int_t fMultiplicityCut, Int_t iUVCut, Float_t fOverlapCut)
Definition: ALFA_HalfReco.cxx:37
ALFA_HalfReco::m_iMultiplicityCut
Int_t m_iMultiplicityCut
Definition: ALFA_HalfReco.h:34
ALFAPLATESCNT
#define ALFAPLATESCNT
Definition: ALFA_constants.h:9
ALFA_HalfReco::m_iNumU
Int_t m_iNumU
Definition: ALFA_HalfReco.h:41