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