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