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