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