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