]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSegmentationV01.cxx
Transition to NewIO
[u/mrichter/AliRoot.git] / MUON / AliMUONSegmentationV01.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 /////////////////////////////////////////////////////
19 //  Segmentation and Response classes version 01   //
20 /////////////////////////////////////////////////////
21
22 #include <TBox.h> 
23 #include <TTUBE.h>
24 #include <TBRIK.h>
25 #include <TNode.h>  
26 #include <TGeometry.h>  
27 #include <TF1.h> 
28 #include <TObjArray.h>
29 #include <Riostream.h>
30
31 #include "AliMUONSegmentationV01.h"
32 #include "AliMUON.h"
33 #include "AliMUONChamber.h"
34 #include "AliRun.h"
35
36
37
38 //___________________________________________
39 ClassImp(AliMUONSegmentationV01)
40
41 AliMUONSegmentationV01::AliMUONSegmentationV01(const AliMUONSegmentationV01& segmentation)
42 {
43 // Dummy copy constructor
44 }
45
46 AliMUONSegmentationV01::AliMUONSegmentationV01() 
47 {
48 // Default constructor
49     fRSec = 0;
50     fNDiv = 0;      
51     fDpxD = 0;
52     fCorrA = 0;
53 }
54
55 AliMUONSegmentationV01::AliMUONSegmentationV01(Int_t nsec) 
56 {
57 //  Non default constructor
58
59     fNsec = nsec;
60     fRSec = new TArrayF(fNsec);
61     fNDiv = new TArrayI(fNsec);      
62     fDpxD = new TArrayF(fNsec);      
63
64
65     (*fRSec)[0]=(*fRSec)[1]=(*fRSec)[2]=(*fRSec)[3]=0;     
66     (*fNDiv)[0]=(*fNDiv)[1]=(*fNDiv)[2]=(*fNDiv)[3]=0;     
67     (*fDpxD)[0]=(*fDpxD)[1]=(*fDpxD)[2]=(*fDpxD)[3]=0;     
68     fCorrA = new TObjArray(3);
69     fCorrA->AddAt(0,0);
70     fCorrA->AddAt(0,1);
71     fCorrA->AddAt(0,2);
72     fOffsetY=0;
73
74
75 AliMUONSegmentationV01::~AliMUONSegmentationV01() 
76 {
77 // Destructor
78     if (fRSec) delete fRSec;
79     if (fNDiv) delete fNDiv;
80     if (fDpxD) delete fDpxD;
81     if (fCorrA) {
82         fCorrA->Delete();
83         delete fCorrA;
84     }
85
86
87
88 Float_t AliMUONSegmentationV01::Dpx(Int_t isec) const
89 {
90 //
91 // Returns x-pad size for given sector isec
92    Float_t dpx = (*fDpxD)[isec];
93    return dpx;
94 }
95
96 Float_t AliMUONSegmentationV01::Dpy(Int_t isec) const
97 {
98 //
99 // Returns y-pad size for given sector isec
100    return fDpy;
101 }
102     
103 void   AliMUONSegmentationV01::SetSegRadii(Float_t  r[4])
104 {
105 //
106 // Set the radii of the segmentation zones 
107     for (Int_t i=0; i<4; i++) {
108         (*fRSec)[i]=r[i];
109     }
110 }
111
112
113 void AliMUONSegmentationV01::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     ndiv[0]=ndiv[1];
124 }
125
126
127 void AliMUONSegmentationV01::Init(Int_t chamber)
128 {
129 //
130 //  Fill the arrays fCx (x-contour) and fNpxS (ix-contour) for each sector
131 //  These arrays help in converting from real to pad co-ordinates and
132 //  vice versa.
133 //  This version approximates concentric segmentation zones
134 //
135     Int_t isec;
136     //printf("\n Initialise Segmentation V01\n");
137
138
139     fNpy=Int_t((*fRSec)[fNsec-1]/fDpy)+1;
140
141     (*fDpxD)[fNsec-1]=fDpx;
142     if (fNsec > 1) {
143         for (Int_t i=fNsec-2; i>=0; i--){
144             (*fDpxD)[i]=(*fDpxD)[fNsec-1]/(*fNDiv)[i];
145         }
146     }
147 //
148 // fill the arrays defining the pad segmentation boundaries
149     Float_t ry;
150     Int_t   dnx;
151     Int_t   add;
152 //
153 //  loop over sections
154     for(isec=0; isec<fNsec; isec++) {
155 //  
156 //  loop over pads along the aode wires
157         for (Int_t iy=1; iy<=fNpy; iy++) {
158 //
159             Float_t x=iy*fDpy-fDpy/2;
160             if (x > (*fRSec)[isec]) {
161                 fNpxS[isec][iy]=0;
162                 fCx[isec][iy]=0;
163             } else {
164                 ry=TMath::Sqrt((*fRSec)[isec]*(*fRSec)[isec]-x*x);
165                 if (isec > 1) {
166                     dnx= Int_t((ry-fCx[isec-1][iy])/(*fDpxD)[isec]);
167                     if (isec < fNsec-1) {
168                         if (TMath::Odd((Long_t)dnx)) dnx++;             
169                     }
170                     fNpxS[isec][iy]=fNpxS[isec-1][iy]+dnx;
171                     fCx[isec][iy]=fCx[isec-1][iy]+dnx*(*fDpxD)[isec];
172                 } else if (isec == 1) {
173                     dnx= Int_t((ry-fCx[isec-1][iy])/(*fDpxD)[isec]);
174                     fNpxS[isec][iy]=fNpxS[isec-1][iy]+dnx;
175                     add=4 - (fNpxS[isec][iy])%4;
176                     if (add < 4) fNpxS[isec][iy]+=add; 
177                     dnx=fNpxS[isec][iy]-fNpxS[isec-1][iy];
178                     fCx[isec][iy]=fCx[isec-1][iy]+dnx*(*fDpxD)[isec];
179                 } else {
180                     dnx=Int_t(ry/(*fDpxD)[isec]);
181                     fNpxS[isec][iy]=dnx;
182                     fCx[isec][iy]=dnx*(*fDpxD)[isec];
183                 }
184             }
185         } // y-pad loop
186     } // sector loop
187 // reference to chamber
188     AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
189     fChamber=&(pMUON->Chamber(chamber));
190     fZ = fChamber->Z();
191     fId=chamber;
192 }
193
194 Int_t AliMUONSegmentationV01::Sector(Int_t ix, Int_t iy)
195 {
196 // Returns sector number for given pad position
197 //
198     Int_t absix=TMath::Abs(ix);
199     Int_t absiy=TMath::Abs(iy);
200     Int_t isec=0;
201     for (Int_t i=0; i<fNsec; i++) {
202         if (absix<=fNpxS[i][absiy]){
203             isec=i;
204             break;
205         }
206     }
207     return isec;
208 }
209
210 void AliMUONSegmentationV01::
211 GetPadI(Float_t x, Float_t y, Int_t &ix, Int_t &iy)
212 {
213 //  Returns pad coordinates (ix,iy) for given real coordinates (x,y)
214 //
215     iy = (y-fOffsetY >0)? 
216       Int_t((y-fOffsetY)/fDpy)+1 
217       : 
218       Int_t((y-fOffsetY)/fDpy)-1;
219   
220     if (iy >  fNpy) iy= fNpy;
221     if (iy < -fNpy) iy=-fNpy;
222 //
223 //  Find sector isec
224     Int_t isec=-1;
225     Float_t absx=TMath::Abs(x);
226     Int_t absiy=TMath::Abs(iy);
227     for (Int_t i=0; i < fNsec; i++) {
228         if (absx <= fCx[i][absiy]) {
229             isec=i;
230             break;
231         }
232     }
233     if (isec>0) {
234         ix= Int_t((absx-fCx[isec-1][absiy])/(*fDpxD)[isec])
235             +fNpxS[isec-1][absiy]+1;
236     } else if (isec == 0) {
237         ix= Int_t(absx/(*fDpxD)[isec])+1;
238     } else {
239         ix=fNpxS[fNsec-1][absiy]+1;     
240     }
241     ix = (x>0) ? ix:-ix;
242 }
243
244 void AliMUONSegmentationV01::
245 GetPadC(Int_t ix, Int_t iy, Float_t &x, Float_t &y)
246 {
247 //  Returns real coordinates (x,y) for given pad coordinates (ix,iy)
248 //
249     y = (iy>0) ?
250       Float_t(iy*fDpy)-fDpy/2.+fOffsetY
251       :
252       Float_t(iy*fDpy)+fDpy/2.+fOffsetY; 
253
254 //
255 //  Find sector isec
256     Int_t isec=AliMUONSegmentationV01::Sector(ix,iy);
257 //
258     Int_t absix=TMath::Abs(ix);
259     Int_t absiy=TMath::Abs(iy);
260     if (isec) {
261         x=fCx[isec-1][absiy]+(absix-fNpxS[isec-1][absiy])*(*fDpxD)[isec];
262         x=(ix>0) ?  x-(*fDpxD)[isec]/2 : -x+(*fDpxD)[isec]/2;
263     } else {
264         x=y=0;
265     }
266 }
267
268 void AliMUONSegmentationV01::
269 SetPad(Int_t ix, Int_t iy)
270 {
271     //
272     // Sets virtual pad coordinates, needed for evaluating pad response 
273     // outside the tracking program 
274     GetPadC(ix,iy,fX,fY);
275     fSector=Sector(ix,iy);
276 }
277
278
279 void AliMUONSegmentationV01::
280 FirstPad(Float_t xhit, Float_t yhit, Float_t dx, Float_t dy)
281 {
282 // Initialises iteration over pads for charge distribution algorithm
283 //
284     //
285     // Find the wire position (center of charge distribution)
286     Float_t x0a=GetAnod(xhit);
287     fXhit=x0a;
288     fYhit=yhit;
289     
290     //
291     // and take fNsigma*sigma around this center
292     Float_t x01=x0a  - dx;
293     Float_t x02=x0a  + dx;
294     Float_t y01=yhit - dy;
295     Float_t y02=yhit + dy;
296     //
297     // find the pads over which the charge distributes
298
299     GetPadI(x01,y01,fIxmin,fIymin);
300     GetPadI(x02,y02,fIxmax,fIymax);
301     fXmin=x01;
302     fXmax=x02;
303     fYmin=y01;
304     fYmax=y02;
305     
306     // 
307     // Set current pad to lower left corner
308     if (fIxmax < fIxmin) fIxmax=fIxmin;
309     if (fIymax < fIymin) fIymax=fIymin;    
310     fIx=fIxmin;
311     fIy=fIymin;
312     GetPadC(fIx,fIy,fX,fY);
313 }
314
315
316 void AliMUONSegmentationV01::NextPad()
317 {
318 // Stepper for the iteration over pads
319 //
320 // Step to next pad in the integration region
321   // 
322   // Step to next pad in integration region
323     Float_t xc,yc;
324     Int_t   iyc;
325     
326 //  step from left to right    
327
328     if (fX < fXmax && fX != 0) {
329         if (fIx==-1) fIx++;
330         fIx++;
331 //  step up 
332     } else if (fIy != fIymax) {
333         if (fIy==-1) fIy++;
334         fIy++;
335 //      get y-position of next row (yc), xc not used here       
336         GetPadC(fIx,fIy,xc,yc);
337 //      get x-pad coordiante for first pad in row (fIx)
338         GetPadI(fXmin,yc,fIx,iyc);
339     } else {
340         fIx=-1;
341         fIy=-1;
342     }
343     GetPadC(fIx,fIy,fX,fY);
344     fSector=Sector(fIx,fIy);
345     if (MorePads() && 
346         (fSector ==-1 || fSector==0)) 
347         NextPad();
348 }
349
350 Int_t AliMUONSegmentationV01::MorePads()
351
352 {
353 // Stopping condition for the iterator over pads
354 //
355 // Are there more pads in the integration region
356     return  (fIx != -1  || fIy != -1);
357 /*
358     if ((fX >= fXmax  && fIy >= fIymax) || fY==0) {
359         return 0;
360     } else {
361         return 1;
362     }
363 */
364 }
365
366 void AliMUONSegmentationV01::
367 IntegrationLimits(Float_t& x1,Float_t& x2,Float_t& y1, Float_t& y2)
368 {
369 //  Returns integration limits for current pad
370 //
371     x1=fXhit-fX-Dpx(fSector)/2.;
372     x2=x1+Dpx(fSector);
373     y1=fYhit-fY-Dpy(fSector)/2.;
374     y2=y1+Dpy(fSector);    
375 }
376
377 void AliMUONSegmentationV01::
378 Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, Int_t Xlist[10], Int_t Ylist[10])
379 {
380 // Returns list of next neighbours for given Pad (iX, iY)
381 //
382     const Float_t kEpsilon=fDpy/1000;
383     
384     Float_t x,y;
385     Int_t   ixx, iyy, isec1;
386 //
387     Int_t   isec0=AliMUONSegmentationV01::Sector(iX,iY);
388     Int_t i=0;
389 //    
390 //  step right
391     Xlist[i]=iX+1;
392     if (Xlist[i]==0) Xlist[i]++;
393     Ylist[i++]=iY;
394 //
395 //  step left    
396     Xlist[i]=iX-1;
397     if (Xlist[i]==0) Xlist[i]--;
398     Ylist[i++]=iY;
399 //
400 //  step up 
401     AliMUONSegmentationV01::GetPadC(iX,iY,x,y);
402     AliMUONSegmentationV01::GetPadI(x+kEpsilon,y+fDpy,ixx,iyy);
403     Xlist[i]=ixx;
404     Ylist[i++]=iyy;
405     isec1=AliMUONSegmentationV01::Sector(ixx,iyy);
406     if (isec1==isec0) {
407 //
408 //  no sector boundary crossing
409 //      Xlist[i]=ixx+1;
410 //      Ylist[i++]=iY+1;
411         
412 //      Xlist[i]=ixx-1;
413 //      Ylist[i++]=iY+1;
414     } else if (isec1 < isec0) {
415 // finer segmentation
416 //      Xlist[i]=ixx+1;
417 //      Ylist[i++]=iY+1;
418         
419         Xlist[i]=ixx-1;
420         Ylist[i++]=iyy;
421         
422 //      Xlist[i]=ixx-2;
423 //      Ylist[i++]=iY+1;
424     } else {
425 // coarser segmenation  
426 /*
427         if (TMath::Odd(iX-fNpxS[isec1-1][iY+1])) {
428             Xlist[i]=ixx-1;
429             Ylist[i++]=iY+1;
430         } else {
431             Xlist[i]=ixx+1;
432             Ylist[i++]=iY+1;
433         }
434 */
435     }
436
437 //
438 // step down 
439     AliMUONSegmentationV01::GetPadC(iX,iY,x,y);
440     AliMUONSegmentationV01::GetPadI(x+kEpsilon,y-fDpy,ixx,iyy);
441     Xlist[i]=ixx;
442     Ylist[i++]=iyy;
443     isec1=AliMUONSegmentationV01::Sector(ixx,iyy);
444     if (isec1==isec0) {
445 //
446 //  no sector boundary crossing
447 /*
448     Xlist[i]=ixx+1;
449     Ylist[i++]=iY-1;
450         
451     Xlist[i]=ixx-1;
452     Ylist[i++]=iY-1;
453 */
454     } else if (isec1 < isec0) {
455 // finer segmentation
456 //      Xlist[i]=ixx+1;
457 //      Ylist[i++]=iY-1;
458         
459         Xlist[i]=ixx-1;
460         Ylist[i++]=iyy;
461         
462 //      Xlist[i]=ixx-2;
463 //      Ylist[i++]=iY-1;
464     } else {
465 // coarser segmentation 
466 /*
467         if (TMath::Odd(iX-fNpxS[isec1-1][iY-1])) {
468             Xlist[i]=ixx-1;
469             Ylist[i++]=iY-1;
470         } else {
471             Xlist[i]=ixx+1;
472             Ylist[i++]=iY-1;
473         }
474 */
475     }
476     *Nlist=i;
477 }
478
479 void AliMUONSegmentationV01::GiveTestPoints(Int_t &n, Float_t *x, Float_t *y) const
480 {
481 // Returns test point on the pad plane.
482 // Used during determination of the segmoid correction of the COG-method
483
484     n=3;
485     x[0]=((*fRSec)[0]+(*fRSec)[1])/2/TMath::Sqrt(2.);
486     y[0]=x[0];
487     x[1]=((*fRSec)[1]+(*fRSec)[2])/2/TMath::Sqrt(2.);
488     y[1]=x[1];
489     x[2]=((*fRSec)[2]+(*fRSec)[3])/2/TMath::Sqrt(2.);
490     y[2]=x[2];
491 }
492
493 void AliMUONSegmentationV01::Draw(const char* opt) const
494 {
495  
496 // Draws the segmentation zones
497 //
498   if (!strcmp(opt,"eventdisplay")) { 
499     const int kColorMUON  = kBlue;
500
501     TRotMatrix* rot000 = new TRotMatrix("Rot000"," ", 90,  0, 90, 90, 0, 0);
502     TRotMatrix* rot090 = new TRotMatrix("Rot090"," ", 90, 90, 90,180, 0, 0);
503     TRotMatrix* rot180 = new TRotMatrix("Rot180"," ", 90,180, 90,270, 0, 0);
504     TRotMatrix* rot270 = new TRotMatrix("Rot270"," ", 90,270, 90,  0, 0, 0);
505
506     char nameChamber[9], nameSense[9], nameFrame[9], nameNode[9];
507     char nameSense1[9], nameSense2[9];    
508     TNode *node, *nodeF;
509  
510     sprintf(nameChamber,"C_MUON%d",fId+1);
511     sprintf(nameSense,"S_MUON%d",fId+1);
512     sprintf(nameSense1,"S1_MUON%d",fId+1);
513     sprintf(nameSense2,"S2_MUON%d",fId+1);
514     sprintf(nameFrame,"F_MUON%d",fId+1);        
515
516     TNode* top=gAlice->GetGeometry()->GetNode("alice");
517
518     Float_t rmin = (*fRSec)[0]-3;
519     Float_t rmax = (*fRSec)[3]+3;
520     new TTUBE(nameChamber,"Mother","void",rmin,rmax,0.25,1.);
521     rmin = (*fRSec)[0];
522     rmax = (*fRSec)[3];
523     new TTUBE(nameSense,"Sens. region","void",rmin,rmax,0.25, 1.);
524     Float_t dx=(rmax-rmin)/2;
525     Float_t dy=3.;
526     Float_t dz=0.25;
527     TBRIK* frMUON = new TBRIK(nameFrame,"Frame","void",dx,dy,dz);
528     top->cd();
529     sprintf(nameNode,"MUON%d",100+fId+1);
530     node = new TNode(nameNode,"ChamberNode",nameChamber,0,0,fChamber->Z(),"");
531     node->SetLineColor(kColorMUON);
532     AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
533     (pMUON->Nodes())->Add(node);
534     node->cd();
535     sprintf(nameNode,"MUON%d",200+fId+1);
536     node = new TNode(nameNode,"Sens. Region Node",nameSense,0,0,0,"");
537     node->SetLineColor(kColorMUON);
538     node->cd();
539     Float_t dr=dx+rmin;
540     sprintf(nameNode,"MUON%d",300+fId+1);
541     nodeF = new TNode(nameNode,"Frame0",frMUON,dr, 0, 0,rot000,"");
542     nodeF->SetLineColor(kColorMUON);
543     node->cd();
544     sprintf(nameNode,"MUON%d",400+fId+1);
545     nodeF = new TNode(nameNode,"Frame1",frMUON,0 ,dr,0,rot090,"");
546     nodeF->SetLineColor(kColorMUON);
547     node->cd();
548     sprintf(nameNode,"MUON%d",500+fId+1);
549     nodeF = new TNode(nameNode,"Frame2",frMUON,-dr,0,0,rot180,"");
550     nodeF->SetLineColor(kColorMUON);
551     node  ->cd();
552     sprintf(nameNode,"MUON%d",600+fId+1);   
553     nodeF = new TNode(nameNode,"Frame3",frMUON,0,-dr,0,rot270,"");
554     nodeF->SetLineColor(kColorMUON);   
555   } else {
556     TBox *box;
557     
558     Float_t dx=0.95/fCx[3][1]/2;
559     Float_t dy=0.95/(Float_t(Npy()))/2;
560     Float_t x0,y0,x1,y1;
561     Float_t xc=0.5;
562     Float_t yc=0.5;
563     
564     for (Int_t iy=1; iy<Npy(); iy++) {
565       for (Int_t isec=0; isec<4; isec++) {
566         if (isec==0) {
567           x0=0;
568           x1=fCx[isec][iy]*dx;
569         } else {
570           x0=fCx[isec-1][iy]*dx;
571           x1=fCx[isec][iy]*dx;
572         }
573         y0=Float_t(iy-1)*dy;
574         y1=y0+dy;
575         box=new TBox(x0+xc,y0+yc,x1+xc,y1+yc);
576         box->SetFillColor(isec+1);
577         box->Draw();
578         
579         box=new TBox(-x1+xc,y0+yc,-x0+xc,y1+yc);
580         box->SetFillColor(isec+1);
581         box->Draw();
582         
583         box=new TBox(x0+xc,-y1+yc,x1+xc,-y0+yc);
584         box->SetFillColor(isec+1);
585         box->Draw();
586         
587         box=new TBox(-x1+xc,-y1+yc,-x0+xc,-y0+yc);
588         box->SetFillColor(isec+1);
589         box->Draw();
590       }
591     }
592   }
593 }
594 void AliMUONSegmentationV01::SetCorrFunc(Int_t isec, TF1* func)
595 {
596 // Set the correction function
597     fCorrA->AddAt(func,isec);
598 }
599
600 TF1* AliMUONSegmentationV01::CorrFunc(Int_t isec) const
601
602 // Get correction function
603   //PH    return (TF1*) (*fCorrA)[isec];
604     return (TF1*) fCorrA->At(isec);
605 }
606
607 AliMUONSegmentationV01& AliMUONSegmentationV01::operator 
608 =(const AliMUONSegmentationV01 & rhs)
609 {
610 // Dummy assignment operator
611     return *this;
612 }
613