]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerSegmentation.cxx
Optimization of code (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerSegmentation.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //**********************************************************************
19 // Segmentation classe for trigger chambers.
20 // In the present version the method use global strip coordinates except
21 // HasPad. The conversion is made via GetPadLoc2Glo.
22 // To be improved in the future.
23 //**********************************************************************
24
25 #include "AliMUONTriggerSegmentation.h"
26 #include "AliLog.h"
27
28 //___________________________________________
29 ClassImp(AliMUONTriggerSegmentation)
30
31 AliMUONTriggerSegmentation::AliMUONTriggerSegmentation() 
32   : AliMUONVGeometryDESegmentation(),
33     fBending(0),
34     fId(0),
35     fNsec(7),
36     fNpx(999999),
37     fNpy(999999),
38     fXhit(0.),
39     fYhit(0.),
40     fIx(0),
41     fIy(0),
42     fX(0.),
43     fY(0.),
44 // add to St345SlatSegmentation
45     fLineNumber(0),
46     fRpcHalfXsize(0),
47     fRpcHalfYsize(0)
48 {
49 // add to St345SlatSegmentation
50   for (Int_t i=0; i<7; i++) {
51       fNstrip[i]=0;
52       fStripYsize[i]=0.;   
53       fStripXsize[i]=0.;  
54       fModuleXmin[i]=0.;
55       fModuleXmax[i]=0.;  
56       fModuleYmin[i]=0.;  
57   }
58 }
59
60
61 //___________________________________________
62 AliMUONTriggerSegmentation::AliMUONTriggerSegmentation(Bool_t bending) 
63   : AliMUONVGeometryDESegmentation(),
64     fBending(bending),
65     fId(0),
66     fNpx(999999),
67     fNpy(999999),
68     fXhit(0.),
69     fYhit(0.),
70     fIx(0),
71     fIy(0),
72     fX(0.),
73     fY(0.),
74 // add to St345SlatSegmentation
75     fLineNumber(0),
76     fRpcHalfXsize(0),
77     fRpcHalfYsize(0)
78 {
79   // Non default constructor
80   fNsec = 7;  
81 // add to St345SlatSegmentation
82   for (Int_t i=0; i<7; i++) {
83       fNstrip[i]=0;
84       fStripYsize[i]=0.;   
85       fStripXsize[i]=0.;  
86       fModuleXmin[i]=0.;
87       fModuleXmax[i]=0.;  
88       fModuleYmin[i]=0.;  
89   }
90 }
91
92 //----------------------------------------------------------------------
93 AliMUONTriggerSegmentation::AliMUONTriggerSegmentation(const AliMUONTriggerSegmentation& rhs) : AliMUONVGeometryDESegmentation(rhs)
94 {
95   AliFatal("Not implemented.");
96 }
97 //----------------------------------------------------------------------
98 AliMUONTriggerSegmentation::~AliMUONTriggerSegmentation() 
99 {
100   // Destructor
101     ;    
102 }
103 //----------------------------------------------------------------------
104 AliMUONTriggerSegmentation& AliMUONTriggerSegmentation::operator=(const AliMUONTriggerSegmentation& rhs)
105 {
106 // Protected assignement operator
107   if (this == &rhs) return *this;
108   AliFatal("Not implemented.");
109   return *this;  
110 }
111 //----------------------------------------------------------------------
112 Int_t AliMUONTriggerSegmentation::ModuleColNum(Int_t ix)
113 {
114 // returns column number (from 0 to 6) in which the (global) module 
115 // ix is sitting (could return 7 if ix=isec)
116     return TMath::Abs(ix)-Int_t(TMath::Abs(ix)/10)*10-1;
117 }
118 //----------------------------------------------------------------------
119 Bool_t AliMUONTriggerSegmentation::HasPad(Int_t ix, Int_t iy)
120 {
121 // check if steping outside the limits (iy=1,2... iy=0,1...)
122     Bool_t hasPad = true;    
123     Int_t ixGlo = 0;
124     Int_t iyGlo = 0; 
125     GetPadLoc2Glo(ix, iy, ixGlo, iyGlo);
126     if (iyGlo>=fNstrip[ModuleColNum(ixGlo)]) hasPad = false;
127     return hasPad;    
128 }
129 //____________________________________________________________________________
130 Float_t AliMUONTriggerSegmentation::Dpx(Int_t isec) const
131 {
132 // return x-strip width in sector isec
133     Float_t size = (isec<8) ? fStripXsize[isec-1] : fStripXsize[isec-2]/2.;
134     return size;
135 }
136 //____________________________________________________________________________
137 Float_t AliMUONTriggerSegmentation::Dpy(Int_t  isec) const
138 {
139 // return y-strip width in sector isec
140     Float_t size = (isec<8) ? fStripYsize[isec-1] : fStripYsize[isec-2];
141     return size;
142 }
143 //----------------------------------------------------------------------------
144 void AliMUONTriggerSegmentation::GetPadLoc2Glo(Int_t ixLoc, Int_t iyLoc, 
145                                                Int_t &ixGlo, Int_t &iyGlo)
146 {    
147 // converts ixLoc & iyLoc into ixGlo & iyGLo (module,strip number)
148     ixGlo = 0; // see AliMUONTriggerConstants::fgkModuleI
149     iyGlo = 0; // from 0 to (fNtrip-1) in module   
150     if (fBending) { 
151         ixGlo = 10*fLineNumber + ixLoc;
152         iyGlo = iyLoc - 1;
153     } else if (!fBending) {     
154         Int_t iCountStrip = 0;  
155         for (Int_t iModule=0; iModule<fNsec; iModule++) {               
156             for (Int_t iStrip=0; iStrip<fNstrip[iModule]; iStrip++) {
157                 if ((ixLoc-1)==iCountStrip) {
158                     ixGlo = 10*fLineNumber + iModule + 1;
159                     iyGlo = iStrip;
160                 }
161                 iCountStrip++;
162             }
163         }
164     }
165 //    printf(" in GetPadLoc2Glo fbending ixLoc iyLoc ixGlo iyGlo %i %i %i %i \n",fBending,ixLoc,iyLoc,ixGlo,iyGlo);
166 }
167
168 //----------------------------------------------------------------------------
169 void AliMUONTriggerSegmentation::GetPadGlo2Loc(Int_t ixGlo, Int_t iyGlo, 
170                                                Int_t &ixLoc, Int_t &iyLoc)
171 {    
172 // converts ixGlo & iyGlo into ixLoc & iyLoc 
173     ixLoc = 0; 
174     iyLoc = 0; 
175     if (fBending) { 
176         ixLoc = ModuleColNum(ixGlo) + 1;
177         iyLoc = iyGlo + 1;
178     } else if (!fBending) {     
179         Int_t iCountStrip = 1;  
180         for (Int_t iModule=0; iModule<fNsec; iModule++) {               
181             for (Int_t iStrip=0; iStrip<fNstrip[iModule]; iStrip++) {
182                 if ((iModule==ModuleColNum(ixGlo))&&(iStrip==iyGlo)) {
183                     ixLoc = 1;              
184                     iyLoc = iCountStrip;
185                 }               
186                 iCountStrip++;
187             }
188         }
189     }    
190 //    printf(" in GetPadGlo2Loc fBending ixGlo iyGlo ixLoc iyLoc %i %i %i %i %i \n",fBending,ixGlo,iyGlo,ixLoc,iyLoc);
191 }
192
193 //----------------------------------------------------------------------------
194 void AliMUONTriggerSegmentation::GetPadC(Int_t ix, Int_t iy, Float_t &x, Float_t &y) 
195 {
196 // Returns local real coordinates (x,y) for local pad coordinates (ix,iy)
197
198     x = 0.;
199     y = 0.;
200     Int_t iModule = ModuleColNum(ix); // find column number (0-6)
201     if (fBending) {
202         if (iModule==0) {
203             x =  fStripXsize[iModule]/ 2.;
204         } else {        
205         x = fModuleXmax[iModule-1] + fStripXsize[iModule]/2.;
206         }
207         y =  fModuleYmin[iModule] + 
208             iy*fStripYsize[iModule] + fStripYsize[iModule]/2.;
209     } else if (!fBending) {
210         if (ModuleColNum(ix)==6 && iy>7) {
211             x = fModuleXmin[iModule] + 8*fStripXsize[iModule] +
212                 (iy-8)*fStripXsize[iModule]/2. + fStripXsize[iModule]/4.;
213         } else {            
214             x = fModuleXmin[iModule] + 
215                 iy*fStripXsize[iModule] + fStripXsize[iModule]/2.;
216         }
217         y =  fModuleYmin[iModule] + fStripYsize[iModule] / 2.;
218     }    
219     x = x - fRpcHalfXsize;
220     y = y - fRpcHalfYsize;
221
222 //    printf(" in GetPadC fBending ix iy x y %i %i %i %f %f \n",fBending,ix,iy,x,y);
223 }
224
225 //_____________________________________________________________________________
226 void AliMUONTriggerSegmentation::GetPadI(Float_t x, Float_t y, Int_t &ix, Int_t &iy) 
227 {
228 //  Returns global pad coordinates (ix,iy) for local real coordinates (x,y)
229     x = x + fRpcHalfXsize;
230     y = y + fRpcHalfYsize;
231 // find module number    
232     Int_t modNum=0;    
233     for (Int_t iModule=0; iModule<fNsec; iModule++) { // modules
234         if ( x > fModuleXmin[iModule] && x < fModuleXmax[iModule] ) {
235             ix = 10*fLineNumber + iModule + 1;
236             modNum = iModule;       
237         }
238     }
239
240 // find strip number 
241     Float_t yMin = 0.;    
242     Float_t yMax = fModuleYmin[modNum];
243     Float_t xMin = 0.;
244     Float_t xMax = fModuleXmin[modNum];
245     if (ix!=0) {
246         for (Int_t iStrip=0; iStrip<fNstrip[modNum]; iStrip++) {
247             if (fBending) {
248                 yMin = yMax;
249                 yMax = yMin + fStripYsize[modNum];
250                 if (y > yMin && y < yMax) iy = iStrip;
251             } else if (!fBending) {
252                 xMin = xMax;
253                 if (modNum==6 && iStrip>7) {
254                     xMax = xMin + fStripXsize[modNum]/2.;
255                 } else {                    
256                     xMax = xMin + fStripXsize[modNum];
257                 }               
258                 if (x > xMin && x < xMax) iy = iStrip;
259             } //
260         } // loop on strips
261     } // if ix!=0
262 //    printf("in GetPadI fBending x y ix iy %i %f %f %i %i \n",fBending,x,y,ix,iy);
263 }
264 //-------------------------------------------------------------------------
265 void AliMUONTriggerSegmentation::GetPadI(Float_t x, Float_t y , Float_t /*z*/, Int_t &ix, Int_t &iy)
266 {
267   GetPadI(x, y, ix, iy);
268 }
269
270 //-------------------------------------------------------------------------
271 void AliMUONTriggerSegmentation::SetLineNumber(Int_t iLineNumber){
272     fLineNumber = iLineNumber;    
273 }
274 //-------------------------------------------------------------------------
275 void AliMUONTriggerSegmentation::SetPad(Int_t ix, Int_t iy)
276 {
277   // Sets virtual pad coordinates, needed for evaluating pad response 
278   // outside the tracking program 
279   GetPadC(ix,iy,fX,fY);
280   fIx = ix; // used in IntegrationLimits
281   fIy = iy;    
282   fSector=Sector(ix,iy);
283 }
284 //---------------------------------------------------------------------------
285 void AliMUONTriggerSegmentation::SetHit(Float_t x, Float_t y)
286 {
287   // Set current hit 
288   fXhit = x;
289   fYhit = y;
290 }
291 //----------------------------------------------------------------------------
292 void AliMUONTriggerSegmentation::SetHit(Float_t xhit, Float_t yhit, Float_t /*zhit*/)
293 {
294   SetHit(xhit, yhit);
295 }
296
297 //--------------------------------------------------------------------------
298 Int_t AliMUONTriggerSegmentation::Sector(Int_t ix, Int_t iy) 
299 {
300 // determine segmentation zone from pad coordinates (from 1 to 8)
301     if (!fBending && ModuleColNum(ix)==6 && iy>7) {
302         return 8; // sector 8: diff. strip width within same module
303     } else {
304         return ModuleColNum(ix)+1;
305     }
306 }
307
308 //-----------------------------------------------------------------------------
309 void AliMUONTriggerSegmentation::
310 IntegrationLimits(Float_t& x1,Float_t& x2,Float_t& x3, Float_t& x4) 
311 {
312 // need to return (only) x4 = dist. betwwen the hit and the closest border of
313 // the current strip
314
315     Int_t ix,iy;
316     Float_t xstrip,ystrip;
317     GetPadI(fXhit,fYhit,ix,iy);
318     GetPadC(ix,iy,xstrip,ystrip);
319     x1= (fBending) ? fYhit : fXhit;  // hit y (bending) / x (!bending) position
320     x2= (fBending) ? ystrip : xstrip; // y or x coord. of the main strip
321     x3= (fBending) ? fY : fX;          // current strip real y or x coord.
322     Int_t modNum = ModuleColNum(fIx);
323
324     // find the position of the 2 borders of the current strip
325     Float_t min = 0.;
326     Float_t max = 0.;    
327     if (fBending) {
328         min = x3 - fStripYsize[modNum]/2.;
329         max = x3 + fStripYsize[modNum]/2.;      
330     } else {
331         if (modNum==6 && fIy>7) { // equivalent to fSector == 8
332             min = x3 - fStripXsize[modNum]/4.;
333             max = x3 + fStripXsize[modNum]/4.;  
334         } else 
335             min = x3 - fStripXsize[modNum]/2.;
336             max = x3 + fStripXsize[modNum]/2.;          
337     }    
338     // dist. between the hit and the closest border of the current strip
339     x4 = (TMath::Abs(max-x1) > TMath::Abs(min-x1)) ? 
340         TMath::Abs(min-x1):TMath::Abs(max-x1);
341 //    printf("fBending x1 x3 min max x4 %i %f %f %f %f %f\n",fBending,x1,x3,min,max,x4);
342 }
343
344
345 //-----------------------------------------------------------------------------
346 void AliMUONTriggerSegmentation::
347 Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, Int_t Xlist[10], Int_t Ylist[10]) 
348 {
349 //-----------------BENDING-----------------------------------------
350 // Returns list of 10 next neighbours for given X strip (ix, iy)  
351 // neighbour number 4 in the list -                     
352 // neighbour number 3 in the list  |                    
353 // neighbour number 2 in the list  |_ Upper part             
354 // neighbour number 1 in the list  |            
355 // neighbour number 0 in the list -           
356 //      X strip (ix, iy) 
357 // neighbour number 5 in the list -       
358 // neighbour number 6 in the list  | _ Lower part
359 // neighbour number 7 in the list  |
360 // neighbour number 8 in the list  | 
361 // neighbour number 9 in the list -
362
363 //-----------------NON-BENDING-------------------------------------
364 // Returns list of 10 next neighbours for given Y strip (ix, iy)  
365 // neighbour number 9 8 7 6 5 (Y strip (ix, iy)) 0 1 2 3 4 in the list
366 //                  \_______/                    \_______/
367 //                    left                         right
368
369     Int_t absiX = TMath::Abs(iX); 
370     Int_t modNum = ModuleColNum(absiX); // from 0 to 6
371     Int_t nStrip = fNstrip[modNum];    
372     
373     if (fBending) {
374         Int_t iCandidateUp, iCandidateDo;
375         Int_t j;
376         
377         *Nlist = 10;
378         for (Int_t i=0; i<10; i++) Xlist[i]=Ylist[i]=0;
379         
380         if (iY < nStrip) {          
381             for (Int_t i=0; i<5; i++) {
382                 j = i + 5;
383                 iCandidateUp = iY + (i + 1);
384                 iCandidateDo = iY - (i + 1);
385                 if (iCandidateUp < nStrip) { 
386                     Xlist[i] = iX;
387                     Ylist[i] = iCandidateUp;  
388                 }
389                 if (iCandidateDo >= 0) { 
390                     Xlist[j] = iX;
391                     Ylist[j] = iCandidateDo;  
392                 }
393             }       
394         } // iY < nStrip        
395
396     } else { // non-bending
397          
398       Int_t iCandidateLeft, iCandidateRight;
399       Int_t iNewCandidateRight=0; 
400       Int_t iNewCandidateLeft=0;
401 // first strip number on the right of the left module  
402       if ( modNum!=0 && absiX!=52 ) 
403           iNewCandidateLeft = fNstrip[modNum-1]-1;
404       Int_t j;
405       
406       *Nlist = 10;
407       for (Int_t i=0; i<10; i++) Xlist[i]=Ylist[i]=0;
408       
409       if (iY < nStrip) {
410           
411           for (Int_t i=0; i<5; i++) {
412               j = i + 5;
413               iCandidateRight = iY + (i + 1);
414               iCandidateLeft  = iY - (i + 1);
415               if (iCandidateRight < nStrip) { // strip in same module  
416                   Xlist[i] = absiX;
417                   Ylist[i] = iCandidateRight;  
418               } else if (modNum!=6) {   // need to scan the module on the right
419                   Xlist[i] = absiX+1;
420                   Ylist[i] = iNewCandidateRight;  
421                   iNewCandidateRight++;
422               }
423               
424               if (iCandidateLeft >=0 ) { // strip in same module
425                   Xlist[j] = absiX;
426                   Ylist[j] = iCandidateLeft;  
427               } else if ( iNewCandidateLeft !=0) {
428                   Xlist[j] = absiX-1;
429                   Ylist[j] = iNewCandidateLeft;  
430                   iNewCandidateLeft--;
431               }
432           }
433           
434           if (iX<0) {                                  // left side of chamber 
435               for (Int_t i=0; i<10; i++) { 
436                   if (Xlist[i]!=0) Xlist[i]=-Xlist[i]; 
437               }
438           }
439           
440       } // iY < nStrip
441     } // non-bending
442
443 //    for (Int_t i=0; i<10; i++) {
444 //      printf("AliMUONTriggerSegmentation LOC fBending i ix iy = %i %i %i %i \n",fBending,i,Xlist[i],Ylist[i]);
445 //   }
446 }
447
448 //--------------------------------------------------------------------------
449 void AliMUONTriggerSegmentation::Init(Int_t detectionElementId,
450                                       Int_t nStrip[7],
451                                       Float_t stripYsize[7],
452                                       Float_t stripXsize[7],
453                                       Float_t offset)
454 {
455 //    printf(" fBending: %d \n",fBending);
456     
457     Int_t nStripMax = 0;
458     if (fBending) nStripMax = nStrip[0];
459     
460     for (Int_t i=0; i<7; i++) {
461         fNstrip[i]=nStrip[i];
462         fStripYsize[i]=stripYsize[i];
463         fStripXsize[i]=stripXsize[i];
464         fModuleYmin[0]=0.;
465     }
466 // take care of offset in Y in chamber 5, first module
467     fModuleYmin[0] = offset;
468     
469     Float_t tmp = 0.;  
470     Int_t npad = 0;  // number of pad in x and y
471     for (Int_t iModule=0; iModule<fNsec; iModule++) { // modules        
472         fModuleXmin[iModule] = tmp;      
473         npad = npad + fNstrip[iModule];
474         if (fBending) {
475             fModuleXmax[iModule] = 
476                 fModuleXmin[iModule] + fStripXsize[iModule];
477         } else if (!fBending) {
478             if (iModule<6) {
479                 fModuleXmax[iModule] = 
480                     fModuleXmin[iModule] + 
481                     fStripXsize[iModule]*fNstrip[iModule];
482             } else if (iModule==6) { 
483                 fModuleXmax[iModule] = 
484                     fModuleXmin[iModule] + 
485                     (fStripXsize[iModule]*fNstrip[iModule]/2) +
486                     (fStripXsize[iModule]/2.*fNstrip[iModule]/2);
487             }     
488         }
489         tmp = fModuleXmax[iModule];      
490         
491 // calculate nStripMax in x & y
492         if (fBending) {
493             if (fNstrip[iModule] > nStripMax) nStripMax = fNstrip[iModule];
494         } else if (!fBending) {
495             for (Int_t iStrip=0; iStrip<fNstrip[iModule]; iStrip++) nStripMax++;
496         }
497     } // loop on modules
498
499 // associate nStripMax
500 //   fNpx = (fBending) ? fNsec : nStripMax;
501 //   fNpy = (fBending) ? nStripMax : 1;
502     fNpx = 124; // tot num of modules (like with old segmentation)
503     fNpy = 64; // max number of y strips within one module
504
505 // calculate half size in x & y (to shift local coordinate ref. system)
506   fRpcHalfXsize = 0;
507   fRpcHalfYsize = 0;  
508   if (fBending) {
509       for (Int_t iModule=0; iModule<fNsec; iModule++)  
510           fRpcHalfXsize = fRpcHalfXsize + fStripXsize[iModule];      
511       fRpcHalfYsize = fNstrip[1] * fStripYsize[1];
512   } else if (!fBending) {
513       fRpcHalfXsize = fModuleXmax[6];
514       fRpcHalfYsize = fStripYsize[1];
515   }
516   fRpcHalfXsize = fRpcHalfXsize / 2.;
517   fRpcHalfYsize = fRpcHalfYsize / 2.;  
518
519 /*
520   printf(" fNpx fNpy fRpcHalfXsize fRpcHalfYsize = %i %i %f %f \n",
521          fNpx,fNpy,fRpcHalfXsize,fRpcHalfYsize);
522
523   for (Int_t iModule=0; iModule<fNsec; iModule++) {
524       printf(" iModule fModuleXmin fModuleXmax fModuleYmin fStripXsize fStripYsize %i %f %f %f %f %f\n",
525              iModule,fModuleXmin[iModule],fModuleXmax[iModule],
526              fModuleYmin[iModule],
527              fStripXsize[iModule],fStripYsize[iModule]);
528              }
529
530   for (Int_t iModule=0; iModule<fNsec; iModule++) {
531       printf(" iModule fNstrip fStripXsize fStripYsize %i %i %f %f \n",
532              iModule,fNstrip[iModule],
533              fStripXsize[iModule],fStripYsize[iModule]);
534   }
535 */
536
537   fId = detectionElementId;
538 }
539
540
541
542
543
544
545