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