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