]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationSlat.cxx
readers updated (mini header -> data header)
[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 {
36 // Default constructor
37   fChamber = 0;
38   fNDiv = 0;
39   fSlats = 0;
40   fCurrentSlat = 0;
41 }
42
43 AliMUONSegmentationSlat::AliMUONSegmentationSlat(Int_t /*nsec*/) 
44 {
45 // Non default constructor
46     fSlats=0;            
47     fNDiv = new TArrayI(4);
48     fChamber = 0;
49     fCurrentSlat = 0;
50 }
51
52 AliMUONSegmentationSlat::~AliMUONSegmentationSlat(){
53   //PH Delete TObjArrays
54   if (fSlats) {
55     fSlats->Delete();
56     delete fSlats;
57   }
58
59   if (fNDiv) {
60     delete fNDiv;
61   }
62
63 }
64 //-----------------------------------------------------------
65 void AliMUONSegmentationSlat::SetPadSize(Float_t p1, Float_t p2)
66 {
67 //  Sets the pad (strip) size 
68 //  
69     fDpx=p1;
70     fDpy=p2;
71 }
72 //-----------------------------------------------------------
73 Float_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 }
79 //-----------------------------------------------------------
80 void AliMUONSegmentationSlat::GetNParallelAndOffset(Int_t /*iX*/, Int_t /*iY*/, Int_t *Nparallel, Int_t *Offset) 
81 {
82   *Nparallel=1;
83   *Offset=0;
84 }
85 //-----------------------------------------------------------
86 void AliMUONSegmentationSlat::GiveTestPoints(Int_t & /*n*/, Float_t */*x*/, Float_t */*y*/)  const 
87 {;}
88 //-----------------------------------------------------------
89 Float_t AliMUONSegmentationSlat::Distance2AndOffset(Int_t /*iX*/, Int_t /*iY*/, Float_t /*X*/, Float_t /*Y*/, Int_t * /*dummy*/) 
90 {
91   return 0.;
92 }
93 //-----------------------------------------------------------
94 Float_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
106 Float_t AliMUONSegmentationSlat::Dpy(Int_t /*isec*/) const
107 {
108 //
109 // Returns y-pad (strip)  size for given sector isec
110    return fDpy;
111 }
112
113 void 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
125 void 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;
134     Float_t eps = 1.e-4;
135     
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();
140
141 //     zlocal = (x>0) ? zlocal-2.*fDz : zlocal+2.*fDz;
142     zlocal = (x>0) ? zlocal+2.*fDz : zlocal-2.*fDz;      //Change?
143
144 //  Set the signs for the symmetry transformation and transform to first quadrant
145     SetSymmetry(x);
146     Float_t xabs=TMath::Abs(x);
147
148
149 // Find slat number                      
150     for (i=0; i<fNSlats; i+=1) {       //Loop on all slats (longuer but more secure)
151         index=i;
152         if ((y >= fYPosition[i]-eps) && (y <= fYPosition[i]+fSlatY+eps)) break;
153     }
154     
155 //
156 // Transform to local coordinate system
157
158     
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     }
166 }
167
168 void 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 //
174     Int_t iytemp = iy;
175     Int_t index  =  0;
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;
192 }
193
194 void AliMUONSegmentationSlat::
195 LocalToGlobal(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
205     x = (xlocal+fXPosition[islat])*fSym;
206     y=(ylocal+fYPosition[islat]);
207
208     z = (TMath::Even(islat)) ?     fDz : -fDz ; //Change for new referential
209     z = (x>0)                ? z+2.*fDz : z-2.*fDz ; 
210
211     z+=fChamber->Z();
212 }
213
214
215 void 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
227     ix=ixlocal*fSym;
228     iy=iy;
229 }
230
231
232 void AliMUONSegmentationSlat::SetSymmetry(Int_t   ix)
233 {
234 // Set set signs for symmetry transformation
235     fSym=TMath::Sign(1,ix);
236 }
237
238 void AliMUONSegmentationSlat::SetSymmetry(Float_t  x)
239 {
240 // Set set signs for symmetry transformation
241     fSym=Int_t (TMath::Sign((Float_t)1.,x));
242 }
243
244 void AliMUONSegmentationSlat::
245 GetPadI(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
260     ix=ix*Int_t(TMath::Sign((Float_t)1.,x));    
261 }
262
263
264 void AliMUONSegmentationSlat::
265 GetPadC(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
278 // Symmetry transformation of half planes
279     x=x*TMath::Sign(1,ix);
280
281 // z-position
282     z = (TMath::Even(islat)) ?      fDz : -fDz ; //Change for new referential
283     z = (x>0)                ?  z+2.*fDz : z-2.*fDz ; 
284     z += fChamber->Z();
285 }
286
287 Int_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
296 Int_t AliMUONSegmentationSlat::Sector(Int_t ix, Int_t iy)
297 {
298 // Returns sector for pad coordiantes (ix,iy)
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
308 void 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
315     SetSymmetry(ix);
316     
317     GlobalToLocal(ix,iy,islat,ixlocal,iylocal);
318     fSlatIndex=islat;
319     fCurrentSlat=Slat(islat);
320     fCurrentSlat->SetPad(ixlocal, iylocal);
321 }
322
323 void  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
341 void AliMUONSegmentationSlat::
342 FirstPad(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
348     Int_t islat;
349     Float_t xlocal, ylocal;
350     GlobalToLocal(xhit, yhit, zhit, islat, xlocal, ylocal);
351     fSlatIndex=islat;
352     if (islat>-1) {
353       fCurrentSlat=Slat(islat);
354       fCurrentSlat->FirstPad(xlocal, ylocal, dx, dy);
355     }
356
357 }
358
359
360 void AliMUONSegmentationSlat::NextPad()
361 {
362 // Stepper for the iteration over pads
363 //
364     fCurrentSlat->NextPad();
365 }
366
367
368 Int_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
376 void AliMUONSegmentationSlat::
377 IntegrationLimits(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
386 void AliMUONSegmentationSlat::
387 Neighbours(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     
393     SetSymmetry(iX);
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
404 Int_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
420 Int_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
433 Int_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)
444 void  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
457 void AliMUONSegmentationSlat::Init(Int_t chamber)
458 {
459 //    
460 // Initialize slat modules of quadrant +/+    
461 // The other three quadrants are handled through symmetry transformations
462 //
463   //printf("\n Initialise Segmentation Slat \n");
464 //
465
466 // Initialize Slat modules
467     Int_t islat, i;
468     Int_t ndiv[4];
469 // Pad division
470     for (i=0; i<4; i++) ndiv[i]=(*fNDiv)[i];
471 //
472     fDz=0.813;
473 // Slat height    
474     fSlatY=40.;
475     for (i=0; i<15; i++) fSlatX[i]=0.;
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++) {
484         fSlats->AddAt(CreateSlatModule(),islat);
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)
500         fYPosition[islat]= fYPosOrigin+islat*(fSlatY-2.*fShift);
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));
514     fId=chamber;
515 }
516
517
518
519
520
521 void 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
533 void  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
539 AliMUONSegmentationSlatModule*  AliMUONSegmentationSlat::Slat(Int_t index) const
540   //PH { return ((AliMUONSegmentationSlatModule*) (*fSlats)[index]);}
541 { return ((AliMUONSegmentationSlatModule*) fSlats->At(index));}
542
543
544 AliMUONSegmentationSlatModule* AliMUONSegmentationSlat::
545 CreateSlatModule()
546 {
547     // Factory method for slat module
548     return new AliMUONSegmentationSlatModule(4);
549 }
550
551
552 void AliMUONSegmentationSlat::Draw(const char* opt) const
553 {
554 // Draw method for event display
555 // 
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 }
606
607
608