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