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