]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSt345SlatSegmentation.cxx
New versions of GDC and CDH raw data headers. Some CDH getters are added
[u/mrichter/AliRoot.git] / MUON / AliMUONSt345SlatSegmentation.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 /// \class AliMUONSt345SlatSegmentation
19 /// \brief Segmentation classes for slat modules          
20 ///
21 /// This class works with local coordinates
22 /// of the slats via the class AliMUONGeometrySegmentation
23 /// This class contains the size of the slats and the
24 /// and the differents PCB densities. 
25 /// (from old AliMUONSegmentationSlatModule)
26 ///
27 /// Add electronics mapping - Christian, Subatech, Mai 05
28 ///
29 /// \author Gines Martinez, Subatech, Nov04
30
31 #include <TArrayI.h>
32 #include <TArrayF.h>
33 #include "AliMUONSt345SlatSegmentation.h"
34 #include "AliLog.h"
35
36 /// \cond CLASSIMP
37 ClassImp(AliMUONSt345SlatSegmentation)
38 /// \endcond
39
40 AliMUONSt345SlatSegmentation::AliMUONSt345SlatSegmentation() 
41   :     AliMUONVGeometryDESegmentation(),
42         fBending(0),
43         fId(0),
44         fNsec(0),
45         fNDiv(0),
46         fDpxD(0),
47         fDpyD(0),
48         fDpx(0),
49         fDpy(0),
50         fNpx(999999),
51         fNpy(999999),
52         fWireD(0.0),
53         fXhit(0.),
54         fYhit(0.),
55         fIx(0),
56         fIy(0),
57         fX(0.),
58         fY(0.),
59         fIxmin(0),
60         fIxmax(0),
61         fIymin(0),
62         fIymax(0),
63         fInitDone(kFALSE)
64 {
65 /// Default constructor
66         AliDebug(1,Form("this=%p default (empty) ctor",this));
67 }
68
69 //___________________________________________
70 AliMUONSt345SlatSegmentation::AliMUONSt345SlatSegmentation(Bool_t bending) 
71   :     AliMUONVGeometryDESegmentation(),
72         fBending(bending),
73         fId(0),
74         fNsec(0),
75         fNDiv(0),
76         fDpxD(0),
77         fDpyD(0),
78         fDpx(0),
79         fDpy(0),
80         fNpx(999999),
81         fNpy(999999),
82         fWireD(0.25),
83         fXhit(0.),
84         fYhit(0.),
85         fIx(0),
86         fIy(0),
87         fX(0.),
88         fY(0.),
89         fIxmin(0),
90         fIxmax(0),
91         fIymin(0),
92         fIymax(0),
93         fInitDone(kFALSE)
94
95 {
96 /// Standard constructor
97
98   fNsec = 4;  // 4 sector densities at most per slat 
99   fNDiv = new TArrayI(fNsec);      
100   fDpxD = new TArrayF(fNsec);      
101   fDpyD = new TArrayF(fNsec);      
102   (*fNDiv)[0]=(*fNDiv)[1]=(*fNDiv)[2]=(*fNDiv)[3]=0;     
103   (*fDpxD)[0]=(*fDpxD)[1]=(*fDpxD)[2]=(*fDpxD)[3]=0;       
104   (*fDpyD)[0]=(*fDpyD)[1]=(*fDpyD)[2]=(*fDpyD)[3]=0;   
105   AliDebug(1,Form("this=%p ctor for bending=%d",this,fBending)); 
106
107 }
108 //----------------------------------------------------------------------
109 AliMUONSt345SlatSegmentation::~AliMUONSt345SlatSegmentation() 
110 {
111 /// Destructor
112
113   AliDebug(1, Form("dtor this = %p", this));
114
115   delete fNDiv;
116   delete fDpxD;
117   delete fDpyD;
118 }
119
120 //------------------------------------------------------------------------
121 Float_t AliMUONSt345SlatSegmentation::Distance2AndOffset(Int_t iX, Int_t iY, Float_t X, Float_t Y, Int_t * /*dummy*/)
122 {
123 /// Returns the square of the distance between 1 pad
124 /// labelled by its Channel numbers and a coordinate
125
126   Float_t x,y;
127   GetPadC(iX,iY,x,y);
128   return (x-X)*(x-X) + (y-Y)*(y-Y);
129 }
130 //____________________________________________________________________________
131 Float_t AliMUONSt345SlatSegmentation::Dpx(Int_t isec) const
132 {
133 /// Return x-strip width
134
135   return (*fDpxD)[isec];
136
137
138 //____________________________________________________________________________
139 Float_t AliMUONSt345SlatSegmentation::Dpy(Int_t  isec) const
140 {
141 /// Return y-strip width
142
143   return (*fDpyD)[isec];
144 }
145 //_____________________________________________________________________________
146 Float_t AliMUONSt345SlatSegmentation::GetAnod(Float_t xhit) const
147 {
148 /// Returns for a hit position xhit the position of the nearest anode wire    
149
150   Float_t wire= (xhit>0)? Int_t(xhit/fWireD)+0.5:Int_t(xhit/fWireD)-0.5;
151   return fWireD*wire;
152 }
153
154 //_____________________________________________________________________________
155 Bool_t AliMUONSt345SlatSegmentation::HasPad(Int_t ix, Int_t iy)
156 {
157 /// Return true if pas with given indices exists
158
159         if ( ix < 1 || ix > Npx() || iy < 1 || iy > Npy() )
160         {
161                 return kFALSE;
162         }
163         Int_t isec = Sector(ix,iy);
164         if ( isec == -1 )
165         {
166                 return kFALSE;
167         }
168         if ( iy > fNpyS[isec] )
169         {
170                 return kFALSE;
171         }
172         return kTRUE;
173 }
174
175 //--------------------------------------------------------------------------------
176 void AliMUONSt345SlatSegmentation::GetPadC(Int_t ix, Int_t iy, Float_t &x, Float_t &y) 
177 {
178 /// Returns real coordinates (x,y) for given pad coordinates (ix,iy)
179
180   if (ix < 1 || ix > Npx() || iy < 1 || iy > Npy() ){
181     AliWarning(Form("ix %d or iy %d out of boundaries: Npx=%d and Npy=%d",ix, iy, Npx(), Npy()));
182     x = y= 0.;
183
184   } else { 
185
186     //  Find sector isec
187     Int_t isec = Sector(ix,iy);
188     if (isec == -1) AliWarning(Form("isector = %d  with ix %d, iy %d", isec, ix, iy));
189     if (iy > fNpyS[isec]) {
190       x = y = 0.;
191       return;
192     }
193     if (isec>0) {
194       x = fCx[isec-1]+(ix-fNpxS[isec-1])*(*fDpxD)[isec];
195       x = x-(*fDpxD)[isec]/2;
196       y = Float_t(iy*(*fDpyD)[isec])-(*fDpyD)[isec]/2.- fCy;  // !!!  
197     } else {
198       x = y = 0;
199     }
200   }
201 }
202
203
204 //_____________________________________________________________________________
205 void AliMUONSt345SlatSegmentation::GetPadI(Float_t x, Float_t y, Int_t &ix, Int_t &iy) 
206 {
207 ///  Returns pad coordinates (ix,iy) for given real coordinates (x,y)
208
209   //  Find sector isec    
210   Int_t isec=-1;
211   for (Int_t i=fNsec-1; i > 0; i--) {
212     if (x >= fCx[i-1]) {
213       isec=i;
214       if (TMath::Abs(fCx[isec] - fCx[isec-1]) <0.1  && isec > 1) isec--;
215       break;
216     }
217   }
218   if (isec == -1) AliWarning(Form("isector equal to %d  with xl %f, yl %f", isec, x, y));
219   if (isec>0) {
220     ix= Int_t((x-fCx[isec-1])/(*fDpxD)[isec])
221       +fNpxS[isec-1]+1;
222     iy= Int_t((y+fCy)/(*fDpyD)[isec])+1;
223   } else if (isec == 0) {
224     ix= Int_t(x/(*fDpxD)[isec])+1;
225     iy= Int_t((y+fCy)/(*fDpyD)[isec])+1;
226   } else {
227     ix=0;
228     iy=0;
229   }
230 }
231 //-------------------------------------------------------------------------
232 void AliMUONSt345SlatSegmentation::GetPadI(Float_t x, Float_t y , Float_t /*z*/, Int_t &ix, Int_t &iy)
233 {
234 /// Returns pad coordinates (ix,iy) for given real coordinates (x,y)
235
236   GetPadI(x, y, ix, iy);
237 }
238
239
240 //_______________________________________________________________
241 void AliMUONSt345SlatSegmentation::SetPadDivision(Int_t ndiv[4])
242 {
243 /// Defines the pad size perp. to the anode wire (y) for different sectors. 
244 /// Pad sizes are defined as integral fractions ndiv of a basis pad size
245 /// fDpx
246  
247   for (Int_t i=0; i<4; i++) {
248     (*fNDiv)[i]=ndiv[i];
249   }
250   ndiv[0]=ndiv[1];
251 }
252 //____________________________________________________________________________
253 void AliMUONSt345SlatSegmentation::SetPadSize(Float_t p1, Float_t p2)
254 {
255 /// Sets the padsize 
256
257   fDpx=p1;
258   fDpy=p2;
259 }
260 //_______________________________________________________________          
261 void AliMUONSt345SlatSegmentation::SetPcbBoards(Int_t n[4])
262 {
263 /// Set PcbBoard segmentation zones for each density
264 /// n[0] slat type parameter
265 /// n[1] PcbBoards for highest density sector fNDiv[1] etc ...
266
267   fRtype = n[0];
268   n[0] = 0;
269   for (Int_t i=0; i<4; i++) fPcbBoards[i]=n[i];
270
271 }
272 //-------------------------------------------------------------------------
273 void AliMUONSt345SlatSegmentation::SetPad(Int_t ix, Int_t iy)
274 {
275 /// Sets virtual pad coordinates, needed for evaluating pad response 
276 /// outside the tracking program 
277
278   GetPadC(ix,iy,fX,fY);
279   fSector=Sector(ix,iy);
280 }
281 //---------------------------------------------------------------------------
282 void AliMUONSt345SlatSegmentation::SetHit(Float_t x, Float_t y)
283 {
284 /// Set current hit 
285
286   fXhit = x;
287   fYhit = y;
288     
289   if (x <  fCx[0])    fXhit = fCx[0];
290   if (y < -fDyPCB/2.) fYhit = -fDyPCB/2.;
291     
292   if (x > fCx[fNsec-1]) fXhit = fCx[fNsec-1];
293   if (y > fDyPCB/2.)    fYhit = fDyPCB/2.;
294     
295 }
296 //----------------------------------------------------------------------------
297 void AliMUONSt345SlatSegmentation::SetHit(Float_t xhit, Float_t yhit, Float_t /*zhit*/)
298 {
299 /// Set current hit 
300
301   SetHit(xhit, yhit);
302 }
303
304 //----------------------------------------------------------
305 void AliMUONSt345SlatSegmentation::FirstPad(Float_t xhit, Float_t yhit, Float_t dx, Float_t dy)
306 {
307 /// Initialises iteration over pads for charge distribution algorithm
308
309     //
310     // Find the wire position (center of charge distribution)
311     Float_t x0a = GetAnod(xhit);
312     fXhit = x0a;
313     fYhit = yhit;
314     //
315     // and take fNsigma*sigma around this center
316     Float_t x01 = x0a  - dx ;
317     Float_t x02 = x0a  + dx;
318     Float_t y01 = yhit - dy;
319     Float_t y02 = yhit + dy;
320
321     // check the limits after adding (fNsigma*sigma)
322     if (x01 <  fCx[0])   x01 =  fCx[0];
323     if (y01 < -fDyPCB/2) y01 = -fDyPCB/2;
324
325     if (x02 >= fCx[fNsec-1]) x02 = fCx[fNsec-1]; // still ok ? (CF)
326     if (y02 >= fDyPCB/2.) y02 = fDyPCB/2.;
327
328    
329     Int_t isec=-1;
330     for (Int_t i=fNsec-1; i > 0; i--) {
331       if (x02 >= fCx[i-1]) {
332         isec=i;
333         if (TMath::Abs(fCx[isec] - fCx[isec-1]) < 0.1 && isec > 1) isec--;
334         break;
335       }
336     }
337
338     //    y02 += Dpy(isec);// why ? (CF)
339    
340     //
341     // find the pads over which the charge distributes
342     GetPadI(x01,y01,fIxmin,fIymin);
343     GetPadI(x02,y02,fIxmax,fIymax);
344     
345     if (fIxmax > fNpx) fIxmax=fNpx;
346     if (fIymax > fNpyS[isec]) fIymax = fNpyS[isec];    
347     if (fIxmin < 1) fIxmin = 1;    // patch for the moment (Ch. Finck)
348     if (fIymin < 1) fIymin = 1;    
349
350     fXmin = x01;
351     fXmax = x02;    
352     fYmin = y01;
353     fYmax = y02;    
354   
355     // 
356     // Set current pad to lower left corner
357     if (fIxmax < fIxmin) fIxmax = fIxmin;
358     if (fIymax < fIymin) fIymax = fIymin;    
359     fIx = fIxmin;
360     fIy = fIymin;
361     
362     GetPadC(fIx,fIy,fX,fY);
363     fSector = Sector(fIx,fIy);
364  
365     AliDebug(4,Form("xhit,yhit,dx,dy=%e,%e,%e,%e ix,iy=%3d,%3d",
366                     xhit,yhit,dx,dy,fIx,fIy));
367 }
368
369 //----------------------------------------------------------------------
370 void AliMUONSt345SlatSegmentation::FirstPad(Float_t xhit, Float_t yhit, Float_t /*zhit*/, Float_t dx, Float_t dy)
371 {
372 /// Initialises iteration over pads for charge distribution algorithm
373
374   FirstPad(xhit, yhit, dx, dy);
375 }
376 //----------------------------------------------------------------------
377 void AliMUONSt345SlatSegmentation::NextPad()
378 {
379 /// Stepper for the iteration over pads
380
381   // Step to next pad in the integration region
382   //  step from left to right    
383   if (fIx != fIxmax) {
384     fIx++;
385     GetPadC(fIx,fIy,fX,fY);
386     fSector=Sector(fIx,fIy);
387     //  step up 
388   } else if (fIy != fIymax) {
389     fIx=fIxmin;
390     fIy++;
391     GetPadC(fIx,fIy,fX,fY);
392     fSector=Sector(fIx,fIy);
393   } else {
394     fIx=-999;
395     fIy=-999;
396   }
397 }
398 //-------------------------------------------------------------------------
399 Int_t AliMUONSt345SlatSegmentation::MorePads()
400 {
401 /// Stopping condition for the iterator over pads
402
403   // Are there more pads in the integration region
404     
405   return  (fIx != -999  || fIy != -999);
406 }
407 //--------------------------------------------------------------------------
408 Int_t AliMUONSt345SlatSegmentation::Sector(Int_t ix, Int_t iy) 
409 {
410 /// Determine segmentation zone from pad coordinates
411
412   Int_t isec = -1;
413   for (Int_t i = 0; i < fNsec; i++) {
414     if (ix <= fNpxS[i]) {
415       isec = i;
416       break;
417     }
418   }
419   if (isec == -1) AliWarning(Form("Sector = %d  with ix %d and iy %d, Npx %d",
420                                   isec, ix, iy, fNpx));
421
422   return isec;
423
424 }
425 //-----------------------------------------------------------------------------
426 void AliMUONSt345SlatSegmentation::
427 IntegrationLimits(Float_t& x1,Float_t& x2,Float_t& y1, Float_t& y2) 
428 {
429 ///  Returns integration limits for current pad
430
431   x1=fXhit-fX-Dpx(fSector)/2.;
432   x2=x1+Dpx(fSector);
433   y1=fYhit-fY-Dpy(fSector)/2.;
434   y2=y1+Dpy(fSector);    
435
436   AliDebug(4,Form("xhit,yhit=%e,%e x,y=%e,%e, x1,x2,y1,y2=%e,%e,%e,%e",fXhit,fYhit,fX,fY,x1,x2,y1,y2));
437
438 }
439 //-----------------------------------------------------------------------------
440 void AliMUONSt345SlatSegmentation::
441 Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, Int_t Xlist[10], Int_t Ylist[10]) 
442 {
443 /// Returns list of next neighbours for given Pad (iX, iY)
444
445   Int_t i=0;
446   //  step right
447   if (iX+1 <= fNpx) {
448     Xlist[i]=iX+1;
449     Ylist[i++]=iY;
450   }
451   //  step left    
452   if (iX-1 > 0) {
453     Xlist[i]=iX-1;
454     Ylist[i++]=iY;
455   } 
456   Int_t sector = Sector(iX,iY);
457   //  step up
458   if (iY+1 <= fNpyS[sector]) {
459     Xlist[i]=iX;
460     Ylist[i++]=iY+1;
461   }
462   //  step down    
463   if (iY-1 > 0) {
464     Xlist[i]=iX;
465     Ylist[i++]=iY-1;
466   }
467   *Nlist=i;
468 }
469
470 //--------------------------------------------------------------------------
471 void AliMUONSt345SlatSegmentation::Init(Int_t detectionElementId)
472 {
473 ///  Fill the arrays fCx (x-contour) and fNpxS (ix-contour) for each sector
474 ///  These arrays help in converting from real to pad co-ordinates and
475 ///  vice versa
476 ///   
477 ///  Segmentation is defined by rectangular modules approximating
478 ///  concentric circles as shown below
479
480   //  PCB module size in cm
481   //  printf("\n Initialise Segmentation SlatModule \n");
482
483   
484   //  printf(" fBending: %d \n",fBending);
485
486   if (fInitDone) return; // security if init is already done in AliMUONFactory
487   fDxPCB=40;
488   fDyPCB=40;
489
490   //  Calculate padsize along x
491   (*fDpxD)[fNsec-1]=fDpx;
492   (*fDpyD)[fNsec-1]=fDpy;
493   if (fNsec > 1) {
494     for (Int_t i=fNsec-1; i>=0; i--){ // fNsec-2
495       if (!fBending) {
496         (*fDpxD)[i]=fDpx;
497         (*fDpyD)[i]=(*fDpyD)[fNsec-1]/(*fNDiv)[i];
498       } else {
499         (*fDpxD)[i]=(*fDpxD)[fNsec-1]/(*fNDiv)[i];
500         (*fDpyD)[i]=fDpy;
501       }
502     }
503   }
504   //
505   // fill the arrays defining the pad segmentation boundaries
506   //
507   //  
508   //  Loop over sectors (isec=0 for secto close to the beam pipe)
509   Float_t totalLength = 0;
510   for (Int_t isec=0; isec<4; isec++) totalLength += fPcbBoards[isec]*fDxPCB;  // !!!!
511
512   fNpy = 0;   // maximum number of pads in y
513   for (Int_t isec=0; isec<4; isec++) {
514     if (isec==0) {
515       fNpxS[0] = 0;
516       fNpyS[0] = 0;
517       fCx[0]   = -totalLength/2;
518     } else {
519       fNpxS[isec] = fNpxS[isec-1] + fPcbBoards[isec]*Int_t(fDxPCB/(*fDpxD)[isec]+0.5); 
520       fNpyS[isec] = Int_t(fDyPCB/(*fDpyD)[isec]+0.5);
521       if (fNpyS[isec] >= fNpy) fNpy = fNpyS[isec]; 
522       fCx[isec]= fCx[isec-1] + fPcbBoards[isec]*fDxPCB;
523     }
524   } // sectors
525
526   fNpx = fNpxS[3];  // maximum number of pads in x
527   fCy = fDyPCB/2.;
528   //
529   fId = detectionElementId;
530
531   fInitDone = kTRUE;
532 }