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