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