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