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