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