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