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