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