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