]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationSlat.cxx
Use only x-symmetry in global to local transformations and delegation.
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentationSlat.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 /*
17 $Log$
18 Revision 1.3  2000/10/18 11:42:06  morsch
19 - AliMUONRawCluster contains z-position.
20 - Some clean-up of useless print statements during initialisations.
21
22 Revision 1.2  2000/10/09 14:06:18  morsch
23 Some type cast problems of type  (TMath::Sign((Float_t)1.,x)) corrected (P.H.)
24
25 Revision 1.1  2000/10/06 09:00:47  morsch
26 Segmentation class for chambers built out of slats.
27
28 */
29
30 #include "AliMUONSegmentationSlat.h"
31 #include "AliMUONSegmentationSlatModule.h"
32 #include "AliMUON.h"
33 #include "AliMUONChamber.h"
34 #include "TArrayI.h"
35 #include "TObjArray.h"
36 #include "AliRun.h"
37 #include <TMath.h>
38 #include <iostream.h>
39
40 //___________________________________________
41 ClassImp(AliMUONSegmentationSlat)
42
43 AliMUONSegmentationSlat::AliMUONSegmentationSlat() 
44 {
45 // Default constructor
46     fSlats=0;            
47     fNDiv = new TArrayI(4);   
48 }
49
50 void AliMUONSegmentationSlat::SetPadSize(Float_t p1, Float_t p2)
51 {
52 //  Sets the pad (strip) size 
53 //  
54     fDpx=p1;
55     fDpy=p2;
56 }
57
58 Float_t AliMUONSegmentationSlat::GetAnod(Float_t xhit) const
59 {
60 // Returns for a hit position xhit the position of the nearest anode wire    
61     Float_t wire= (xhit>0)? Int_t(xhit/fWireD)+0.5:Int_t(xhit/fWireD)-0.5;
62     return fWireD*wire;
63 }
64
65 Float_t AliMUONSegmentationSlat::Dpx(Int_t isec) const
66 {
67 //
68 // Returns x-pad size for given sector isec
69 // isec = 100*islat+iregion
70 //
71     Int_t islat, iregion;
72     islat    = isec/100;
73     iregion  = isec%100;
74     return Slat(islat)->Dpx(iregion);
75 }
76
77 Float_t AliMUONSegmentationSlat::Dpy(Int_t isec) const
78 {
79 //
80 // Returns y-pad (strip)  size for given sector isec
81    return fDpy;
82 }
83
84 void AliMUONSegmentationSlat::SetPadDivision(Int_t ndiv[4])
85 {
86 //
87 // Defines the pad size perp. to the anode wire (y) for different sectors. 
88 // Pad sizes are defined as integral fractions ndiv of a basis pad size
89 // fDpx
90 // 
91     for (Int_t i=0; i<4; i++) {
92         (*fNDiv)[i]=ndiv[i];
93     }
94 }
95
96 void AliMUONSegmentationSlat::GlobalToLocal(
97     Float_t x, Float_t y, Float_t z, Int_t &islat, Float_t &xlocal, Float_t &ylocal)
98 {
99 //
100 // Perform local to global transformation for space coordinates
101 //
102     Float_t zlocal;
103     Int_t i;
104     Int_t index=-1;
105 // Transform According to slat plane z-position: negative side is shifted down 
106 //                                                 positive side is shifted up
107 // by half the overlap
108     zlocal = z-fChamber->Z();
109 //  Set the signs for the symmetry transformation and transform to first quadrant
110     SetSymmetry(x);
111     Float_t xabs=TMath::Abs(x);
112
113     Int_t ifirst = (zlocal < Float_t(0))? 0:1;
114 //
115 // Find slat number                      
116     for (i=ifirst; i<fNSlats; i+=2) {
117         index=i;
118         if ((y >= fYPosition[i]) && (y < fYPosition[i]+fSlatY)) break;
119     }
120     
121 //
122 // Transform to local coordinate system
123
124     
125     ylocal = y   -fYPosition[index];
126     xlocal = xabs-fXPosition[index];
127     islat  = index;
128     if (i >= fNSlats) {islat = -1; x=-1; y = -1;}
129 }
130
131 void AliMUONSegmentationSlat::GlobalToLocal(
132     Int_t ix, Int_t iy, Int_t &islat, Int_t &ixlocal, Int_t &iylocal)
133 {
134 //
135 // Perform global to local transformation for pad coordinates
136 //
137     Int_t iytemp = iy;
138     Int_t index  =  0;
139     
140     iylocal = iytemp;
141
142 //
143 // Find slat number (index) and iylocal  
144     for (Int_t i=0; i<fNSlats; i++) {
145         iytemp-=Slat(i)->Npy();
146         
147         
148         if (iytemp <= 0) break;
149         iylocal = iytemp;
150         index=i+1;
151     }
152
153     ixlocal=TMath::Abs(ix);
154     islat=index;
155 }
156
157 void AliMUONSegmentationSlat::
158 LocalToGlobal(Int_t islat, Float_t  xlocal, Float_t  ylocal, Float_t  &x, Float_t  &y, Float_t &z)
159 {
160 // Transform from local to global space coordinates
161 //
162 // upper plane (y>0) even slat number is shifted down
163 // upper plane (y>0)  odd slat number is shifted up 
164 // lower plane (y<0) even slat number is shifted up
165 // lower plane (y<0)  odd slat number is shifted down
166 //
167
168     x = (xlocal+fXPosition[islat])*fSym;
169     y=(ylocal+fYPosition[islat]);
170
171     z = (TMath::Even(islat)) ? -fDz : fDz ; 
172     z+=fChamber->Z();
173 }
174
175
176 void AliMUONSegmentationSlat::LocalToGlobal(
177     Int_t islat, Int_t ixlocal, Int_t iylocal, Int_t &ix, Int_t &iy)
178 {
179 // Transform from local to global pad coordinates
180 //
181     Int_t i;
182     iy=iylocal;
183     
184 //
185 // Find slat number (index) and iylocal  
186     for (i=0; i<islat; i++) iy+=Slat(islat)->Npy();
187
188     ix=ixlocal*fSym;
189     iy=iy;
190 }
191
192
193 void AliMUONSegmentationSlat::SetSymmetry(Int_t   ix)
194 {
195 // Set set signs for symmetry transformation
196     fSym=TMath::Sign(1,ix);
197 }
198
199 void AliMUONSegmentationSlat::SetSymmetry(Float_t  x)
200 {
201 // Set set signs for symmetry transformation
202     fSym=Int_t (TMath::Sign((Float_t)1.,x));
203 }
204
205 void AliMUONSegmentationSlat::
206 GetPadI(Float_t x, Float_t y, Float_t z, Int_t &ix, Int_t &iy)
207 {
208 // Returns pad coordinates for given set of space coordinates
209
210     Int_t islat, i;
211     Float_t xlocal, ylocal;
212     
213     GlobalToLocal(x,y,z,islat,xlocal,ylocal);
214     if (islat == -1) {
215         ix=0; iy=0; return;
216     }
217     
218     Slat(islat)->GetPadI(xlocal, ylocal, ix, iy);
219     for (i=0; i<islat; i++) iy+=Slat(islat)->Npy();
220
221     ix=ix*Int_t(TMath::Sign((Float_t)1.,x));    
222 }
223
224
225 void AliMUONSegmentationSlat::
226 GetPadC(Int_t ix, Int_t iy, Float_t &x, Float_t &y, Float_t &z)
227 {
228 //  Returns real coordinates (x,y) for given pad coordinates (ix,iy)
229 //
230     Int_t islat, ixlocal, iylocal;
231 //
232 // Delegation of transforamtion to slat
233     GlobalToLocal(ix,iy,islat,ixlocal,iylocal);
234     Slat(islat)->GetPadC(ixlocal, iylocal, x, y);
235 // Slat offset
236     x+=fXPosition[islat];
237     y+=fYPosition[islat];    
238
239 // Symmetry transformation of half planes
240     x=x*TMath::Sign(1,ix);
241
242 // z-position
243     z = (TMath::Even(islat)) ? -fDz : fDz ; 
244     z += fChamber->Z();
245 }
246
247 Int_t AliMUONSegmentationSlat::ISector()
248 {
249 // Returns current sector during tracking
250     Int_t iregion;
251     
252     iregion =  fCurrentSlat->ISector();
253     return 100*fSlatIndex+iregion;
254 }
255
256 Int_t AliMUONSegmentationSlat::Sector(Int_t ix, Int_t iy)
257 {
258     Int_t ixlocal, iylocal, iregion, islat;
259
260     GlobalToLocal(ix,iy,islat,ixlocal,iylocal);
261     
262     iregion =  Slat(islat)->Sector(ixlocal, iylocal);
263     return 100*islat+iregion;
264 }
265
266
267 void AliMUONSegmentationSlat::SetPad(Int_t ix, Int_t iy)
268 {
269     //
270     // Sets virtual pad coordinates, needed for evaluating pad response 
271     // outside the tracking program
272     Int_t islat, ixlocal, iylocal;
273
274     SetSymmetry(ix);
275     
276     GlobalToLocal(ix,iy,islat,ixlocal,iylocal);
277     fSlatIndex=islat;
278     fCurrentSlat=Slat(islat);
279     fCurrentSlat->SetPad(ixlocal, iylocal);
280 }
281
282 void  AliMUONSegmentationSlat::SetHit(Float_t xhit, Float_t yhit, Float_t zhit)
283 {   //
284     // Sets current hit coordinates
285
286     Float_t xlocal, ylocal;
287     Int_t islat;
288
289     
290
291     GlobalToLocal(xhit,yhit,zhit,islat,xlocal,ylocal);
292     fSlatIndex=islat;
293     if (islat < 0) printf("\n SetHit: %d", islat);
294     
295     fCurrentSlat=Slat(islat);
296     fCurrentSlat->SetHit(xlocal, ylocal);
297 }
298
299
300 void AliMUONSegmentationSlat::
301 FirstPad(Float_t xhit, Float_t yhit, Float_t zhit, Float_t dx, Float_t dy)
302 {
303 // Initialises iteration over pads for charge distribution algorithm
304 //
305
306
307
308     Int_t islat;
309     Float_t xlocal, ylocal;
310     GlobalToLocal(xhit, yhit, zhit, islat, xlocal, ylocal);
311     fSlatIndex=islat;
312     fCurrentSlat=Slat(islat);
313     fCurrentSlat->FirstPad(xlocal, ylocal, dx, dy);
314
315 }
316
317
318 void AliMUONSegmentationSlat::NextPad()
319 {
320 // Stepper for the iteration over pads
321 //
322     fCurrentSlat->NextPad();
323 }
324
325
326 Int_t AliMUONSegmentationSlat::MorePads()
327 // Stopping condition for the iterator over pads
328 //
329 // Are there more pads in the integration region
330
331     return fCurrentSlat->MorePads();
332 }
333
334 void AliMUONSegmentationSlat::
335 IntegrationLimits(Float_t& x1,Float_t& x2,Float_t& y1, Float_t& y2)
336 {
337 //  Returns integration limits for current pad
338 //
339     
340     fCurrentSlat->IntegrationLimits(x1, x2, y1, y2);
341
342 }
343
344 void AliMUONSegmentationSlat::
345 Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, Int_t Xlist[10], Int_t Ylist[10])
346 {
347 // Returns list of neighbours of pad with coordinates iX, iY
348
349     Int_t i, xListLocal[10], yListLocal[10], iXlocal, iYlocal, islat;
350     
351     SetSymmetry(iX);
352
353     GlobalToLocal(iX, iY, islat, iXlocal, iYlocal);
354  
355     Slat(islat)->Neighbours(iXlocal, iYlocal, Nlist, xListLocal, yListLocal);
356     
357     for (i=0; i<*Nlist; i++) LocalToGlobal(islat, xListLocal[i], yListLocal[i], Xlist[i], Ylist[i]);
358
359 }
360
361
362 Int_t  AliMUONSegmentationSlat::Ix()
363 {
364 // Return current pad coordinate ix during stepping
365     Int_t ixl,iyl,ix,iy;
366     ixl=fCurrentSlat->Ix();
367     iyl=fCurrentSlat->Iy();
368     
369     LocalToGlobal(fSlatIndex, ixl, iyl, ix, iy);
370     Int_t ixc, iyc, isc;
371     Float_t xc, yc;
372     GlobalToLocal(ix, iy, isc, ixc, iyc);
373     Slat(isc)->GetPadC(ixc,iyc,xc,yc);
374     return ix;
375 }
376
377
378 Int_t  AliMUONSegmentationSlat::Iy()
379 {
380 // Return current pad coordinate iy during stepping
381     Int_t ixl,iyl,ix,iy;
382     ixl=fCurrentSlat->Ix();
383     iyl=fCurrentSlat->Iy();
384     LocalToGlobal(fSlatIndex, ixl, iyl, ix, iy);
385     return iy;
386 }
387
388
389
390    // Signal Generation Condition during Stepping
391 Int_t AliMUONSegmentationSlat::SigGenCond(Float_t x, Float_t y, Float_t z)
392
393 //
394 //  True if signal generation condition fullfilled
395     Float_t xlocal, ylocal;
396     Int_t islat;
397     GlobalToLocal(x, y, z, islat, xlocal, ylocal);
398     return Slat(islat)->SigGenCond(xlocal, ylocal, z);
399 }
400
401 // Initialise signal generation at coord (x,y,z)
402 void  AliMUONSegmentationSlat::SigGenInit(Float_t x, Float_t y, Float_t z)
403 {
404 // Initialize the signal generation condition
405 //
406     Float_t xlocal, ylocal;
407     Int_t islat;
408
409     GlobalToLocal(x, y, z, islat, xlocal, ylocal);
410     Slat(islat)->SigGenInit(xlocal, ylocal, z);
411 }
412
413
414
415 void AliMUONSegmentationSlat::Init(Int_t chamber)
416 {
417 //    
418 // Initialize slat modules of quadrant +/+    
419 // The other three quadrants are handled through symmetry transformations
420 //
421     printf("\n Initialise Segmentation Slat \n");
422 //
423
424 //    Initialize Slat modules
425     Int_t islat, i;
426     Int_t ndiv[4];
427 // Pad division
428     for (i=0; i<4; i++) ndiv[i]=(*fNDiv)[i];
429 // Half distance between slat planes
430     fDz=1.76;
431 // Slat height    
432     fSlatY=40.;
433     for (i=0; i<15; i++) fSlatX[i]=0.;
434     
435 // Initialize array of slats 
436     fSlats  = new TObjArray(fNSlats);
437 // Maximum number of strips (pads) in x and y
438     fNpy=0;   
439     fNpx=0;
440 // for each slat in the quadrant (+,+)    
441     for (islat=0; islat<fNSlats; islat++) {
442         (*fSlats)[islat] = CreateSlatModule();
443
444         AliMUONSegmentationSlatModule *slat =  Slat(islat);
445         // Configure Slat
446         slat->SetId(islat);
447         
448 // Foward pad size
449         slat->SetPadSize(fDpx, fDpy);
450 // Forward wire pitch
451         slat->SetDAnod(fWireD);
452 // Foward segmentation 
453         slat->SetPadDivision(ndiv);
454         slat->SetPcbBoards(fPcb[islat]);
455 // Initialize slat module
456         slat->Init(chamber);
457 // y-position of slat module relative to the first (closest to the beam)
458         fYPosition[islat]= fYPosOrigin+islat*(fSlatY-2.*fShift);
459 //
460         fNpy+=slat->Npy();
461         if (slat->Npx() > fNpx) fNpx=slat->Npx();
462         Int_t isec;
463         for (isec=0; isec< 4; isec++)
464         {
465             fSlatX[islat]+=40.*fPcb[islat][isec];
466         }
467         
468     }
469 // Set parent chamber number
470     AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
471     fChamber=&(pMUON->Chamber(chamber));
472 }
473
474
475
476
477
478 void AliMUONSegmentationSlat::SetNPCBperSector(Int_t *npcb)
479
480     //  PCB distribution for station 4 (6 rows with 1+3 segmentation regions)
481     for (Int_t islat=0; islat<fNSlats; islat++){ 
482         fPcb[islat][0] = *(npcb + 4 * islat);
483         fPcb[islat][1] = *(npcb + 4 * islat + 1);
484         fPcb[islat][2] = *(npcb + 4 * islat + 2);
485         fPcb[islat][3] = *(npcb + 4 * islat + 3);
486     }
487 }
488
489
490 void  AliMUONSegmentationSlat::SetSlatXPositions(Float_t *xpos)
491 {
492 // Set x-positions of Slats
493     for (Int_t islat=0; islat<fNSlats; islat++) fXPosition[islat]=xpos[islat];
494 }
495
496 AliMUONSegmentationSlatModule*  AliMUONSegmentationSlat::Slat(Int_t index) const
497 { return ((AliMUONSegmentationSlatModule*) (*fSlats)[index]);}
498
499
500 AliMUONSegmentationSlatModule* AliMUONSegmentationSlat::
501 CreateSlatModule()
502 {
503     // Factory method for slat module
504     return new AliMUONSegmentationSlatModule();
505 }
506
507
508
509
510