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