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