]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONSt345SlatSegmentationV2.cxx
Move to new mapping
[u/mrichter/AliRoot.git] / MUON / AliMUONSt345SlatSegmentationV2.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 "AliMUONSt345SlatSegmentationV2.h"
19 #include "AliMUONConstants.h"
20
21 #include "AliMpArea.h"
22 #include "AliMpSlat.h"
23 #include "AliMpSlatSegmentation.h"
24 #include "AliMpPCB.h" 
25 // FIXME: we should not need access to PCB at this level
26 // if the Dpx, Dpy, Sector interface would not be used.
27 // Investigate instead to direct use of AliMpVSegmentation and AliMpPad
28 // from the clusterFinder ? // :aphecetc:20050722 
29 // or, or ... have the AliMpSlat handles the notion of zone, finally
30 // (where "zone" in mapping is equivalent to "sector" here), and thus
31 // let AliMpSlat offer the interface to get information similar to what
32 // Dpx, Dpy, Sector offer now to the clustering. That indeed should be
33 // handled directly at the level of AliMpVSegmentation...
34 #include "AliMpVPadIterator.h"
35
36 #include "AliLog.h"
37
38 #include "Riostream.h"
39 #include "TClass.h"
40
41 ClassImp(AliMUONSt345SlatSegmentationV2)
42
43 namespace
44 {
45   Int_t fgIntOffset = 1;
46   Float_t FMAX(1E9);
47 }
48
49 //_____________________________________________________________________________
50 AliMUONSt345SlatSegmentationV2::AliMUONSt345SlatSegmentationV2()
51 : AliMUONVGeometryDESegmentation(),
52 fDetElemId(-1),
53 fPlaneType(kBendingPlane),
54 fSlat(0),
55 fSlatSegmentation(0),
56 fPadIterator(0),
57 fXhit(FMAX),
58 fYhit(FMAX)
59 {
60         AliDebug(1,Form("this=%p default (empty) ctor",this));
61 }
62
63 //_____________________________________________________________________________
64 AliMUONSt345SlatSegmentationV2::AliMUONSt345SlatSegmentationV2(
65                                    AliMpVSegmentation* segmentation,
66                                    Int_t detElemId, AliMpPlaneType bendingOrNonBending)
67 : AliMUONVGeometryDESegmentation(),
68 fDetElemId(detElemId),
69 fPlaneType(bendingOrNonBending),
70 fSlat(0),
71 fSlatSegmentation(0),
72 fPadIterator(0),
73 fXhit(FMAX),
74 fYhit(FMAX)
75
76   //
77   // Normal ctor.
78   //
79
80   fSlatSegmentation = dynamic_cast<AliMpSlatSegmentation*>(segmentation);
81   if (fSlatSegmentation)
82     fSlat = fSlatSegmentation->Slat();
83   else 
84     AliFatal("Wrong mapping segmentation type");
85                 
86   AliDebug(1,Form("this=%p detElemId=%3d %s fSlatSegmentation=%p",this,detElemId,
87                                                                         ( (bendingOrNonBending==kBendingPlane)?"Bending":"NonBending" ),
88                                                                         fSlatSegmentation));
89 }
90
91 //_____________________________________________________________________________
92 AliMUONSt345SlatSegmentationV2::~AliMUONSt345SlatSegmentationV2()
93 {
94         AliDebug(1,Form("dtor this=%p",this));
95   delete fPadIterator;
96 }
97
98 //_____________________________________________________________________________
99 TF1*
100 AliMUONSt345SlatSegmentationV2::CorrFunc(Int_t) const
101 {
102   AliFatal("Not Implemented");
103   return 0x0;
104 }
105
106 //_____________________________________________________________________________
107 Float_t 
108 AliMUONSt345SlatSegmentationV2::Distance2AndOffset(Int_t,Int_t,
109                                                                                                                                                                                                          Float_t,Float_t,Int_t*)
110 {
111   AliFatal("Not Implemented");
112   return 0.0;
113 }
114
115 //_____________________________________________________________________________
116 void
117 AliMUONSt345SlatSegmentationV2::Draw(Option_t*)
118 {
119   AliFatal("Not Implemented");
120 }
121
122 //_____________________________________________________________________________
123 Float_t
124 AliMUONSt345SlatSegmentationV2::Dpx() const
125 {
126   AliFatal("Not Implemented");
127   return 0.0;
128 }
129
130 //_____________________________________________________________________________
131 Float_t
132 AliMUONSt345SlatSegmentationV2::Dpy() const
133 {
134   AliFatal("Not Implemented");
135   return 0.0;
136 }
137
138 //_____________________________________________________________________________
139 Float_t
140 AliMUONSt345SlatSegmentationV2::Dpx(int ipcb) const
141 {
142         AliMpPCB* pcb = fSlat->GetPCB(ipcb);
143         if (!pcb) 
144   {
145     AliFatal("pcb is null!");
146   }
147         return pcb->PadSizeX();
148 }
149
150 //_____________________________________________________________________________
151 Float_t
152 AliMUONSt345SlatSegmentationV2::Dpy(int ipcb) const
153 {
154         AliMpPCB* pcb = fSlat->GetPCB(ipcb);
155         if (!pcb) 
156   {
157     AliFatal("pcb is null!");
158   }
159         return pcb->PadSizeY();
160 }
161
162 //_____________________________________________________________________________
163 void
164 AliMUONSt345SlatSegmentationV2::FirstPad(Float_t xhit, Float_t yhit, 
165                                                                                                                                                                  Float_t /*zhit*/, 
166                                                                                                                                                                  Float_t dx, Float_t dy)
167 {
168   // OK. We will do it in 2 steps. First get the area over which to
169   // iterate, based on hit coordinates and (dx,dy). This first step
170   // has nothing to do with segmentation in the first place, but with
171   // how we simulate the fact that at some point the charge is shared
172   // amongst several pads.
173   // The second step is the actual pad iteration and is handled by 
174   // a specific class (which has to do only with iteration...)
175   //
176   // FIXME: this method should not be here in the first place, IMHO.
177   //
178         
179   // Find the wire position (center of charge distribution)
180   Float_t xwire = GetAnod(xhit);
181   fXhit = xwire;
182   fYhit = yhit;
183         
184   Double_t x01 = xwire - dx;
185   Double_t x02 = xwire + dx;
186   Double_t y01 = yhit - dy;
187   Double_t y02 = yhit + dy;
188         
189   Double_t xext = x02 - x01;
190   Double_t yext = y02 - y01;
191         
192   // we do not check area here, as we assume the iterator
193   // will do it, and will possibly truncate it if needed.
194   // Note that we convert the area position to a reference frame
195   // located in the lower-left corner of the slat, instead of its
196   // center.
197 //  AliMpArea area(TVector2((x01+x02)/2.0+fSlat->DX(),
198 //                                                                                                      (y01+y02)/2.0+fSlat->DY()),
199 //                                                               TVector2(xext/2.0,yext/2.0));
200   AliMpArea area(TVector2((x01+x02)/2.0,(y01+y02)/2.0),
201                                                                  TVector2(xext/2.0,yext/2.0));
202         
203   delete fPadIterator;
204         
205   fPadIterator = fSlatSegmentation->CreateIterator(area);
206         
207   fPadIterator->First();
208         
209   fCurrentPad = fPadIterator->CurrentItem();
210         
211   if ( !fCurrentPad.IsValid() ) 
212         {
213                 AliError(Form("Cannot get a valid pad for (xhit,yhit,dx,dy)=(%e,%e,%e,%e)",xhit,yhit,dx,dy));
214         }
215         
216   AliDebug(4,Form("xhit,yhit,dx,dy=%e,%e,%e,%e ix,iy=%3d,%3d slat=%s",
217                                                                         xhit,yhit,dx,dy,
218                                                                         fCurrentPad.GetIndices().GetFirst()+1,
219                                                                         fCurrentPad.GetIndices().GetSecond()+1,fSlat->GetID()));                  
220 }
221
222 //_____________________________________________________________________________
223 Float_t
224 AliMUONSt345SlatSegmentationV2::GetAnod(Float_t xhit) const
225 {
226   // Gets the x-coordinate of the wire which is the closest to xhit.
227         
228   Int_t n = Int_t(xhit/AliMUONConstants::Pitch());
229   Float_t wire = (xhit>0) ? n+0.5 : n-0.5;
230   return AliMUONConstants::Pitch()*wire;
231 }
232
233 //_____________________________________________________________________________
234 AliMUONGeometryDirection
235 AliMUONSt345SlatSegmentationV2::GetDirection()
236 {
237   //AliWarning("Not Implemented");
238   return kDirUndefined;
239 }
240
241 //______________________________________________________________________________
242 const AliMpVSegmentation*  
243 AliMUONSt345SlatSegmentationV2::GetMpSegmentation() const
244 {
245 // Returns the mapping segmentation
246 // (provides access to electronics info)
247
248   return fSlatSegmentation;
249 }  
250
251
252 //_____________________________________________________________________________
253 void 
254 AliMUONSt345SlatSegmentationV2::GetNParallelAndOffset(Int_t,Int_t,Int_t*,Int_t*)
255 {
256   AliFatal("Not Implemented");
257 }
258
259 //_____________________________________________________________________________
260 void
261 AliMUONSt345SlatSegmentationV2::GetPadC(Int_t ix, Int_t iy, 
262                                                                                                                                                                 Float_t& x, Float_t& y, Float_t& z)
263 {
264   z = 0;
265   GetPadC(ix,iy,x,y);
266 }
267
268 //_____________________________________________________________________________
269 void
270 AliMUONSt345SlatSegmentationV2::GetPadC(Int_t ix, Int_t iy, 
271                                                                                                                                                                 Float_t& x, Float_t& y)
272 {
273   AliMpPad pad = 
274   fSlatSegmentation->PadByIndices(AliMpIntPair(ix-fgIntOffset,iy-fgIntOffset),
275                                   kTRUE);
276   x = pad.Position().X();
277   y = pad.Position().Y();
278 }
279
280
281 //_____________________________________________________________________________
282 void
283 AliMUONSt345SlatSegmentationV2::GetPadI(Float_t x, Float_t y, Float_t /*z*/,
284 Int_t& ix, Int_t& iy)
285 {
286   GetPadI(x,y,ix,iy);
287 }
288
289 //_____________________________________________________________________________
290 void
291 AliMUONSt345SlatSegmentationV2::GetPadI(Float_t x, Float_t y,
292                                                                                                                                                                 Int_t& ix, Int_t& iy)
293 {
294 //  Double_t slatx = fSlat->DX();
295 //  Double_t slaty = fSlat->DY();
296   AliMpPad pad = 
297     fSlatSegmentation->PadByPosition(TVector2(x,y), kTRUE);
298 //  fSlatSegmentation->PadByPosition(TVector2(x+slatx,y+slaty), kTRUE);
299         
300   if ( pad != AliMpPad::Invalid() )
301         {
302                 ix = pad.GetIndices().GetFirst() + fgIntOffset;
303                 iy = pad.GetIndices().GetSecond() + fgIntOffset;
304         }
305   else
306         {
307                 ix = iy = -1;
308         }
309 }
310
311 //_____________________________________________________________________________
312 void 
313 AliMUONSt345SlatSegmentationV2::GiveTestPoints(Int_t&,Float_t*,Float_t*) const
314 {
315   AliFatal("Not Implemented");
316 }
317
318 //_____________________________________________________________________________
319 Bool_t
320 AliMUONSt345SlatSegmentationV2::HasPad(Float_t x, Float_t y, Float_t z)
321 {
322   Int_t ix, iy;
323   GetPadI(x,y,z,ix,iy);
324   return HasPad(ix,iy);
325 }
326
327 //_____________________________________________________________________________
328 Bool_t
329 AliMUONSt345SlatSegmentationV2::HasPad(Int_t ix, Int_t iy)
330 {
331   return fSlatSegmentation->HasPad(AliMpIntPair(ix-fgIntOffset,iy-fgIntOffset));
332 }
333
334 //_____________________________________________________________________________
335 void
336 AliMUONSt345SlatSegmentationV2::Init(int)
337 {
338   AliWarning("Not Implemented because not needed ;-)");
339 }
340
341 //_____________________________________________________________________________
342 void  
343 AliMUONSt345SlatSegmentationV2::IntegrationLimits(Float_t& x1, Float_t& x2, 
344                                                                                                                                                                                                         Float_t& y1, Float_t& y2)
345 {
346   //
347   //  Returns integration limits for current pad
348   //
349         
350         //   x1 = fXhit - fX - Dpx(fSector)/2.;
351         //   x2 = x1 + Dpx(fSector);
352         //   y1 = fYhit - fY - Dpy(fSector)/2.;
353         //   y2 = y1 + Dpy(fSector);    
354         
355   Float_t x = fCurrentPad.Position().X();
356   Float_t y = fCurrentPad.Position().Y();
357         
358   Float_t padsizex = fCurrentPad.Dimensions().X() * 2.0;
359   Float_t padsizey = fCurrentPad.Dimensions().Y() * 2.0;
360         
361   x1 = fXhit - x - padsizex/2.0;
362   x2 = x1 + padsizex;
363   y1 = fYhit - y - padsizey/2.0;
364   y2 = y1 + padsizey;
365         
366   AliDebug(4,Form("xhit,yhit=%e,%e x,y=%e,%e, x1,x2,y1,y2=%e,%e,%e,%e",fXhit,fYhit,x,y,x1,x2,y1,y2));
367 }
368
369 //_____________________________________________________________________________
370 Int_t
371 AliMUONSt345SlatSegmentationV2::ISector()
372 {
373   // FIXME: remove the usage of ISector from all the code.
374   return -10;
375 }
376
377 //_____________________________________________________________________________
378 Int_t
379 AliMUONSt345SlatSegmentationV2::Ix()
380 {
381   if ( fPadIterator )
382         {
383                 return fPadIterator->CurrentItem().GetIndices().GetFirst() + fgIntOffset;
384         }
385   else
386         {
387                 return -1;
388         }
389 }
390
391 //_____________________________________________________________________________
392 Int_t
393 AliMUONSt345SlatSegmentationV2::Iy()
394 {
395   if ( fPadIterator ) 
396         {
397                 return fPadIterator->CurrentItem().GetIndices().GetSecond() + fgIntOffset;
398         }
399   else
400         {
401                 return -1;
402         }
403 }
404
405 //_____________________________________________________________________________
406 Int_t
407 AliMUONSt345SlatSegmentationV2::MorePads()
408 {
409   return (fPadIterator && !fPadIterator->IsDone());
410 }
411
412 //_____________________________________________________________________________
413 void 
414 AliMUONSt345SlatSegmentationV2::Neighbours(Int_t iX, Int_t iY, Int_t* Nlist, 
415                                                                                                                                                                          Int_t Xlist[10], Int_t Ylist[10])
416 {
417   // Find pad at (ix,iy) for which we'll search neighbours.
418   AliMpPad pad = 
419         fSlatSegmentation->PadByIndices(AliMpIntPair(iX-fgIntOffset,iY-fgIntOffset),kTRUE);
420         
421   // Define the region to look into : a region slightly bigger
422   // than the pad itself (5% bigger), in order to catch first neighbours.
423
424   AliMpArea area(pad.Position(),pad.Dimensions()*1.05); 
425                 
426   AliMpVPadIterator* it = fSlatSegmentation->CreateIterator(area);
427   it->First();
428   Int_t n = 0;
429   while ( !it->IsDone() && n < 10 )
430         {
431                 AliMpPad p = it->CurrentItem();
432                 if ( p != pad ) // skip self
433                 {
434                         Xlist[n] = p.GetIndices().GetFirst() + fgIntOffset;
435                         Ylist[n] = p.GetIndices().GetSecond() + fgIntOffset;
436                         ++n;
437                 }
438                 it->Next();
439         }
440         delete it;
441   *Nlist = n;
442 }
443
444 //_____________________________________________________________________________
445 void
446 AliMUONSt345SlatSegmentationV2::NextPad()
447 {
448   if ( fPadIterator )
449         {
450                 fPadIterator->Next();
451                 fCurrentPad = fPadIterator->CurrentItem();
452         }
453   else
454         {
455                 AliError("PadIterator not initialized. Please use First() first ;-)");
456         }
457 }
458
459 //_____________________________________________________________________________
460 Int_t
461 AliMUONSt345SlatSegmentationV2::Npx() const
462 {
463   return fSlatSegmentation->MaxPadIndexX()+1;
464 }
465
466 //_____________________________________________________________________________
467 Int_t
468 AliMUONSt345SlatSegmentationV2::Npy() const
469 {
470   return fSlatSegmentation->MaxPadIndexY()+1;
471 }
472
473 //_____________________________________________________________________________
474 void
475 AliMUONSt345SlatSegmentationV2::Print(Option_t*) const
476 {
477   cout << "DetElemId=" << fDetElemId << " PlaneType=" 
478   << fPlaneType << " Npx,Npy=" << Npx() << "," << Npy() << " fSlat=" << fSlat 
479   << " fSlatSegmentation=" << fSlatSegmentation
480   << " fSlatSegmentation->Slat()=" << fSlatSegmentation->Slat() << endl;
481 }
482
483 //_____________________________________________________________________________
484 Int_t
485 AliMUONSt345SlatSegmentationV2::Sector(Int_t ix, Int_t)
486 {
487   return fSlat->FindPCBIndex(ix - fgIntOffset);
488 }
489
490 //_____________________________________________________________________________
491 Int_t
492 AliMUONSt345SlatSegmentationV2::Sector(Float_t x, Float_t y)
493 {
494   return fSlat->FindPCBIndex(x,y);
495 }
496
497 //_____________________________________________________________________________
498 void
499 AliMUONSt345SlatSegmentationV2::SetCorrFunc(Int_t,TF1*)
500 {
501   AliFatal("Not Implemented");
502 }
503
504 //_____________________________________________________________________________
505 void
506 AliMUONSt345SlatSegmentationV2::SetDAnod(float)
507 {
508   AliFatal("Not Implemented");
509 }
510
511 //_____________________________________________________________________________
512 void
513 AliMUONSt345SlatSegmentationV2::SetHit(Float_t x, Float_t y, Float_t)
514 {
515   fXhit = x;
516   fYhit = y;
517         
518   //
519   // insure we're within the slat limits. If not, issue an error and sets
520   // the current hit to slat center.
521   // FIXME: this should probably a) not happen at all b) be a fatal error
522   //
523   if ( fXhit < -fSlat->DX() || fXhit > fSlat->DX() ||
524        fYhit < -fSlat->DY() || fYhit > fSlat->DY() )
525         {
526                 AliError(Form("Hit outside slat %s limits (x,y)hit = (%e,%e)."
527                   " Forcing to (0,0)",fSlat->GetID(),fXhit,fYhit));
528                 fXhit = 0.0;
529                 fYhit = 0.0;
530         }
531   
532 }
533
534 //_____________________________________________________________________________
535 void
536 AliMUONSt345SlatSegmentationV2::SetPad(Int_t ix, Int_t iy)
537 {
538   fCurrentPad = 
539         fSlatSegmentation->PadByIndices(AliMpIntPair(ix-fgIntOffset,iy-fgIntOffset),kTRUE);
540   if ( !fCurrentPad.IsValid() )
541         {
542                 AliError(Form("Setting current pad to invalid ! (ix,iy)=(%4d,%4d)",ix,iy));
543         }
544 }
545
546 //_____________________________________________________________________________
547 void
548 AliMUONSt345SlatSegmentationV2::SetPadSize(float,float)
549 {
550   AliFatal("Not Implemented");
551 }
552
553 //_____________________________________________________________________________
554 Int_t 
555 AliMUONSt345SlatSegmentationV2::SigGenCond(Float_t,Float_t,Float_t)
556 {
557   AliFatal("Not Implemented");
558   return 0;
559 }
560
561 //_____________________________________________________________________________
562 void 
563 AliMUONSt345SlatSegmentationV2::SigGenInit(Float_t,Float_t,Float_t)
564 {
565   AliFatal("Not Implemented");
566 }