Removing leftover return
[u/mrichter/AliRoot.git] / MUON / AliMUONCluster.cxx
CommitLineData
99ccb7f7 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
9edefa04 18#include <Riostream.h>
19#include <TMath.h>
20#include <TObjArray.h>
21#include <TVirtualPad.h>
22#include <TVirtualX.h>
23
99ccb7f7 24#include "AliMUONCluster.h"
168e9c4d 25#include "AliMUONPad.h"
26
27#include "AliMpEncodePair.h"
99ccb7f7 28
29#include "AliLog.h"
99ccb7f7 30
3d1463c8 31//-----------------------------------------------------------------------------
99ccb7f7 32/// \class AliMUONCluster
33///
34/// A group of adjacent pads
35///
36/// Besides holding an internal array of AliMUONPads, this object
37/// also computes some global characteristics for that pad sets.
38///
39/// \author Laurent Aphecetche
40///
3d1463c8 41//-----------------------------------------------------------------------------
99ccb7f7 42
b80faac0 43using std::cout;
44using std::endl;
99ccb7f7 45/// \cond CLASSIMP
46ClassImp(AliMUONCluster)
47/// \endcond
48
49namespace
50{
51 //___________________________________________________________________________
52 Bool_t
53 ShouldUsePad(const AliMUONPad& pad,
54 Int_t cathode, Int_t statusMask, Bool_t matchMask)
55 {
56
57 // FIXME : we should only use >=0 status, so we can fully
58 // use masking possibility ?
59 if ( pad.Status() < 0 ) return kFALSE;
60
61 if ( pad.Cathode() == cathode && pad.IsReal() && !pad.IsSaturated() )
62 {
63 Bool_t test = ( ( pad.Status() & statusMask ) != 0 );
64 if ( !statusMask )
65 {
66 test = ( pad.Status() == 0 );
67 }
68 if ( ( test && matchMask ) || ( !test && !matchMask ) )
69 {
70 return kTRUE;
71 }
72 }
73 return kFALSE;
74 }
75
76 //___________________________________________________________________________
77 Int_t Unique(Int_t n, Double_t* array, Double_t precision)
78 {
79 /// Return the number of *different* elements in array
80 /// where different is up to precision
81 /// Note that we assume that n is >= 1
82
83 Int_t count(1);
84
85 Int_t* index = new Int_t[n];
86
87 TMath::Sort(n,array,index);
88
89 for ( Int_t i = 1; i < n; ++i )
90 {
91 if ( array[index[i]] - array[index[i-1]] < -precision ) ++count;
92 }
93
94 delete[] index;
95
96 return count;
97 }
98}
99
100//_____________________________________________________________________________
101AliMUONCluster::AliMUONCluster()
102: TObject(),
e0de1dd9 103fPads(),
99ccb7f7 104fHasPosition(kFALSE),
105fPosition(1E9,1E9),
106fPositionError(1E9,1E9),
107fHasCharge(kFALSE),
00de388f 108fChi2(0)
99ccb7f7 109{
110 /// ctor
111 fMultiplicity[0]=fMultiplicity[1]=0;
112 fRawCharge[0]=fRawCharge[1]=0;
113 fCharge[0]=fCharge[1]=0;
114 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
e0de1dd9 115 fPads.SetOwner(kTRUE);
99ccb7f7 116}
117
118//_____________________________________________________________________________
119AliMUONCluster::AliMUONCluster(const AliMUONCluster& src)
120: TObject(src),
e0de1dd9 121fPads(),
99ccb7f7 122fHasPosition(kFALSE),
123fPosition(1E9,1E9),
124fPositionError(1E9,1E9),
125fHasCharge(kFALSE),
00de388f 126fChi2(0)
99ccb7f7 127{
128 /// copy ctor
e0de1dd9 129 fPads.SetOwner(kTRUE);
99ccb7f7 130 src.Copy(*this);
131}
132
133//_____________________________________________________________________________
134AliMUONCluster&
135AliMUONCluster::operator=(const AliMUONCluster& src)
136{
137 /// assignement operator
0c8556b9 138 if ( this != &src )
139 {
140 src.Copy(*this);
141 }
99ccb7f7 142 return *this;
143}
144
145//_____________________________________________________________________________
146AliMUONCluster::~AliMUONCluster()
147{
148 /// dtor : note that we're owner of our pads
08bd919e 149// fPads.Delete();
99ccb7f7 150}
151
152//_____________________________________________________________________________
153void
00de388f 154AliMUONCluster::Clear(Option_t*)
155{
08bd919e 156 /// Clear our pad array
157 fPads.Clear();
158// fPads.Delete();
00de388f 159}
160
161//_____________________________________________________________________________
162Bool_t
163AliMUONCluster::Contains(const AliMUONPad& pad) const
164{
165 /// Whether this cluster contains the pad
e0de1dd9 166 if (fPads.IsEmpty()) return kFALSE;
167
00de388f 168 for ( Int_t i = 0; i < Multiplicity(); ++i )
169 {
170 AliMUONPad* p = Pad(i);
171 if ( pad.Compare(p) == 0 ) return kTRUE;
172 }
173 return kFALSE;
174}
175
176//_____________________________________________________________________________
177void
178AliMUONCluster::AddCluster(const AliMUONCluster& cluster)
179{
180 /// Add all the pads for cluster to this one
181 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
182 {
183 AliMUONPad* p = cluster.Pad(i);
184 if ( Contains(*p) )
185 {
186 AliError("I already got this pad : ");
187 StdoutToAliError(p->Print(););
188 AliFatal("");
189 }
190 AddPad(*p);
191 }
192
193}
194
195//_____________________________________________________________________________
196AliMUONPad*
99ccb7f7 197AliMUONCluster::AddPad(const AliMUONPad& pad)
198{
199 /// Add a pad to our pad array, and update some internal information
200 /// accordingly.
e0de1dd9 201
99ccb7f7 202 AliMUONPad* p = new AliMUONPad(pad);
e0de1dd9 203 fPads.AddLast(p);
99ccb7f7 204 p->SetClusterId(GetUniqueID());
205 Int_t cathode = p->Cathode();
206 ++(fMultiplicity[cathode]);
207 fRawCharge[cathode] += p->Charge();
208 if ( p->IsSaturated() )
209 {
210 fIsSaturated[p->Cathode()]=kTRUE;
211 }
00de388f 212 return p;
213}
214
215//___________________________________________________________________________
216TString
217AliMUONCluster::AsString() const
218{
219 /// Return a string containing a compact form of the pad list
220 TString s(Form("NPADS(%d,%d)",Multiplicity(0),Multiplicity(1)));
221
222 for (Int_t i = 0; i < Multiplicity(); ++i )
223 {
224 AliMUONPad* p = Pad(i);
225 s += Form(" (%d,%d,%d) ",p->Cathode(),p->Ix(),p->Iy());
226 }
227 return s;
228}
229
230
231//___________________________________________________________________________
232Bool_t
233AliMUONCluster::AreOverlapping(const AliMUONCluster& c1, const AliMUONCluster& c2)
234{
235 /// Whether the two clusters overlap
236
237 static Double_t precision = 1E-4; // cm
238 static TVector2 precisionAdjustment(precision,precision);
239
240 for ( Int_t i1 = 0; i1 < c1.Multiplicity(); ++i1 )
241 {
242 AliMUONPad* p1 = c1.Pad(i1);
243
244 for ( Int_t i2 = 0; i2 < c2.Multiplicity(); ++i2 )
245 {
246 AliMUONPad* p2 = c2.Pad(i2);
247 // Note: we use negative precision numbers, meaning
248 // the area of the pads will be *increased* by these small numbers
249 // prior to check the overlap by the AreOverlapping method,
250 // so pads touching only by the corners will be considered as
251 // overlapping.
252 if ( AliMUONPad::AreOverlapping(*p1,*p2,precisionAdjustment) )
253 {
254 return kTRUE;
255 }
256 }
257 }
258 return kFALSE;
99ccb7f7 259}
260
261//_____________________________________________________________________________
262AliMpArea
263AliMUONCluster::Area() const
264{
265 /// Return the geometrical area covered by this cluster
266
267 // Start by finding the (x,y) limits of this cluster
268 TVector2 lowerLeft(1E9,1E9);
269 TVector2 upperRight(-1E9,-1E9);
270
271 for ( Int_t i = 0; i < Multiplicity(); ++i )
272 {
273 AliMUONPad* pad = Pad(i);
274 TVector2 ll = pad->Position() - pad->Dimensions();
275 TVector2 ur = pad->Position() + pad->Dimensions();
276 lowerLeft.Set( TMath::Min(ll.X(),lowerLeft.X()),
277 TMath::Min(ll.Y(),lowerLeft.Y()) );
278 upperRight.Set( TMath::Max(ur.X(),upperRight.X()),
279 TMath::Max(ur.Y(),upperRight.Y()) );
280 }
281
282 // then construct the area from those limits
6e97fbb8 283 return AliMpArea((lowerLeft+upperRight).X()/2,(lowerLeft+upperRight).Y()/2,
284 (upperRight-lowerLeft).X()/2, (upperRight-lowerLeft).Y()/2);
99ccb7f7 285}
286
287//_____________________________________________________________________________
00de388f 288AliMpArea
289AliMUONCluster::Area(Int_t cathode) const
290{
291 /// Return the geometrical area covered by this cluster's pads on
292 /// a given cathode
293
294 // Start by finding the (x,y) limits of this cluster
295 TVector2 lowerLeft(1E9,1E9);
296 TVector2 upperRight(-1E9,-1E9);
297
cd1f0e79 298 for ( Int_t i = 0; i < Multiplicity(); ++i )
00de388f 299 {
300 AliMUONPad* pad = Pad(i);
cd1f0e79 301 if ( pad->Cathode() == cathode )
302 {
303 TVector2 ll = pad->Position() - pad->Dimensions();
304 TVector2 ur = pad->Position() + pad->Dimensions();
305 lowerLeft.Set( TMath::Min(ll.X(),lowerLeft.X()),
306 TMath::Min(ll.Y(),lowerLeft.Y()) );
307 upperRight.Set( TMath::Max(ur.X(),upperRight.X()),
308 TMath::Max(ur.Y(),upperRight.Y()) );
309 }
00de388f 310 }
311
312 // then construct the area from those limits
6e97fbb8 313 return AliMpArea((lowerLeft+upperRight).X()/2,(lowerLeft+upperRight).Y()/2,
314 (upperRight-lowerLeft).X()/2, (upperRight-lowerLeft).Y()/2);
00de388f 315}
316
317//_____________________________________________________________________________
2103dc37 318Bool_t
319AliMUONCluster::IsMonoCathode() const
320{
321 /// Whether we have signals only in one of the two cathodes
322 return (Cathode()<2);
323}
324
325//_____________________________________________________________________________
00de388f 326Int_t
327AliMUONCluster::Cathode() const
328{
329 /// Return the cathode "number" of this cluster :
330 /// 0 if all its pads are on cathode 0
331 /// 1 if all its pads are on cathode 1
332 /// 2 if some pads on cath 0 and some on cath 1
333
334 Int_t cathode(-1);
335 if (Multiplicity(0)>0 && Multiplicity(1)>0)
336 {
337 cathode=2;
338 }
339 else if (Multiplicity(0)>0)
340 {
341 cathode=0;
342 }
343 else if (Multiplicity(1)>0)
344 {
345 cathode=1;
346 }
347
348 return cathode;
349}
350
351//_____________________________________________________________________________
99ccb7f7 352void
353AliMUONCluster::Copy(TObject& obj) const
354{
71a2d3aa 355 ///
356 /// Copy this cluster to (cluster&)obj
357 ///
99ccb7f7 358 TObject::Copy(obj);
359 AliMUONCluster& dest = static_cast<AliMUONCluster&>(obj);
57f3728e 360
361// dest.fPads.Delete();
362 dest.fPads.Clear();
363
364 for ( Int_t i = 0; i <= fPads.GetLast(); ++i )
365 {
366 AliMUONPad* p = static_cast<AliMUONPad*>(fPads.UncheckedAt(i));
367 dest.fPads.AddLast(new AliMUONPad(*p));
368 }
99ccb7f7 369 dest.fHasPosition = fHasPosition;
370 dest.fPosition = fPosition;
371 dest.fPositionError = fPositionError;
372 dest.fHasCharge = fHasCharge;
99ccb7f7 373 dest.fChi2 = fChi2;
374 for ( Int_t i = 0; i < 2; ++i )
375 {
376 dest.fRawCharge[i] = fRawCharge[i];
377 dest.fCharge[i] = fCharge[i];
378 dest.fMultiplicity[i] = fMultiplicity[i];
379 dest.fIsSaturated[i] = fIsSaturated[i];
380 }
381}
382
383//_____________________________________________________________________________
384Float_t
385AliMUONCluster::Charge() const
386{
387 /// Return the average charge over both cathodes
530acd78 388
389 if ( Multiplicity(0) && Multiplicity(1) )
390 {
391 return (Charge(0)+Charge(1))/2.0;
392 }
393 else if ( Multiplicity(0) )
394 {
395 return Charge(0);
396 }
397 else if ( Multiplicity(1) )
398 {
399 return Charge(1);
400 }
401 AliError("Should not be here ?!");
402 return -1.0;
99ccb7f7 403}
404
405//_____________________________________________________________________________
406Float_t
407AliMUONCluster::Charge(Int_t cathode) const
408{
409 /// Returns the charge of a given cathode
410 if ( !fHasCharge ) return RawCharge(cathode);
411
412 if ( cathode == 0 || cathode == 1 )
413 {
414 return fCharge[cathode];
415 }
416 return 0;
417}
418
419//_____________________________________________________________________________
420Float_t
421AliMUONCluster::ChargeAsymmetry() const
422{
423 /// Returns the charge asymmetry
424 if ( Charge() > 0 )
425 {
426 return TMath::Abs(Charge(0)-Charge(1))/Charge();
427 }
428 return 0;
429}
430
431//_____________________________________________________________________________
432TVector2
00de388f 433AliMUONCluster::MaxPadDimensions(Int_t statusMask, Bool_t matchMask) const
434{
435 /// Returns the maximum pad dimensions (half sizes), only considering
436 /// pads matching (or not, depending matchMask) a given mask
437
438 TVector2 cath0(MaxPadDimensions(0,statusMask,matchMask));
439 TVector2 cath1(MaxPadDimensions(1,statusMask,matchMask));
440
441 return TVector2( TMath::Max(cath0.X(),cath1.X()),
442 TMath::Max(cath0.Y(),cath1.Y()) );
443}
444
445//_____________________________________________________________________________
446TVector2
447AliMUONCluster::MaxPadDimensions(Int_t cathode,
448 Int_t statusMask, Bool_t matchMask) const
449{
450 /// Returns the maximum pad dimensions (half sizes), only considering
451 /// pads matching (or not, depending matchMask) a given mask, within a
452 /// given cathode
453
454 Double_t xmax(0);
455 Double_t ymax(0);
456
457 for ( Int_t i = 0; i < Multiplicity(); ++i )
458 {
459 AliMUONPad* pad = Pad(i);
460 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
461 {
462 xmax = TMath::Max(xmax,pad->DX());
463 ymax = TMath::Max(ymax,pad->DY());
464 }
465 }
466 return TVector2(xmax,ymax);
467}
468
469//_____________________________________________________________________________
470TVector2
99ccb7f7 471AliMUONCluster::MinPadDimensions(Int_t statusMask, Bool_t matchMask) const
472{
473 /// Returns the minimum pad dimensions (half sizes), only considering
474 /// pads matching (or not, depending matchMask) a given mask
475
476 TVector2 cath0(MinPadDimensions(0,statusMask,matchMask));
477 TVector2 cath1(MinPadDimensions(1,statusMask,matchMask));
478
479 return TVector2( TMath::Min(cath0.X(),cath1.X()),
480 TMath::Min(cath0.Y(),cath1.Y()) );
481}
482
483//_____________________________________________________________________________
484TVector2
485AliMUONCluster::MinPadDimensions(Int_t cathode,
486 Int_t statusMask, Bool_t matchMask) const
487{
488 /// Returns the minimum pad dimensions (half sizes), only considering
489 /// pads matching (or not, depending matchMask) a given mask, within a
490 /// given cathode
491
492 Double_t xmin(1E9);
493 Double_t ymin(1E9);
494
495 for ( Int_t i = 0; i < Multiplicity(); ++i )
496 {
497 AliMUONPad* pad = Pad(i);
498 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
499 {
500 xmin = TMath::Min(xmin,pad->DX());
501 ymin = TMath::Min(ymin,pad->DY());
502 }
503 }
504 return TVector2(xmin,ymin);
505}
506
507//_____________________________________________________________________________
508Int_t
509AliMUONCluster::Multiplicity() const
510{
511 /// Returns the total number of pads in this cluster
512 return Multiplicity(0)+Multiplicity(1);
513}
514
515//_____________________________________________________________________________
516Int_t
517AliMUONCluster::Multiplicity(Int_t cathode) const
518{
519 /// Returns the number of pads in this cluster, in the given cathode
520 if ( cathode == 0 || cathode == 1 )
521 {
522 return fMultiplicity[cathode];
523 }
524 return 0;
525}
526
527//_____________________________________________________________________________
168e9c4d 528Long_t
99ccb7f7 529AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
530{
531 /// Number of pads satisfying (or not, depending matchMask) a
168e9c4d 532 /// given mask
99ccb7f7 533
534 Int_t nx, ny;
535
536 TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
537 TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
538
168e9c4d 539 Long_t npad0(NofPads(0,statusMask,matchMask));
540 Long_t npad1(NofPads(1,statusMask,matchMask));
99ccb7f7 541
542 if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
543 {
168e9c4d 544 nx = TMath::Max( AliMp::PairFirst(npad0), AliMp::PairFirst(npad1) );
99ccb7f7 545 }
546 else
547 {
168e9c4d 548 nx = dim0.X() < dim1.X() ? AliMp::PairFirst(npad0) : AliMp::PairFirst(npad1);
99ccb7f7 549 }
550
551 if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
552 {
168e9c4d 553 ny = TMath::Max( AliMp::PairSecond(npad0), AliMp::PairSecond(npad1) );
99ccb7f7 554 }
555 else
556 {
168e9c4d 557 ny = dim0.Y() < dim1.Y() ? AliMp::PairSecond(npad0) : AliMp::PairSecond(npad1);
99ccb7f7 558 }
559
168e9c4d 560 return AliMp::Pair(nx,ny);
99ccb7f7 561}
562
563//_____________________________________________________________________________
168e9c4d 564Long_t
99ccb7f7 565AliMUONCluster::NofPads(Int_t cathode,
566 Int_t statusMask, Bool_t matchMask) const
567{
568 /// Number of pads of a given cathode, satisfying (or not,
569 /// depending matchMask) a given mask
570
571 Int_t n = Multiplicity(cathode);
572 if (!n)
573 {
168e9c4d 574 return 0;
99ccb7f7 575 }
576 Double_t* x = new Double_t[n];
577 Double_t* y = new Double_t[n];
578 Int_t np(0);
579
580 for ( Int_t i = 0; i < Multiplicity(); ++i )
581 {
582 AliMUONPad* pad = Pad(i);
583 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
584 {
585 x[np] = pad->X();
586 y[np] = pad->Y();
587 ++np;
588 }
589 }
590
591 Int_t cx = Unique(np,x,0.01);
592 Int_t cy = Unique(np,y,0.01);
593
594 delete[] x;
595 delete[] y;
596
168e9c4d 597 return AliMp::Pair(cx,cy);
99ccb7f7 598}
599
600//_____________________________________________________________________________
601AliMUONPad*
602AliMUONCluster::Pad(Int_t index) const
603{
604 /// Returns the index-th pad
605
e0de1dd9 606 if (fPads.IsEmpty()) return 0x0;
607 if ( index < fPads.GetLast()+1 )
99ccb7f7 608 {
e0de1dd9 609 return static_cast<AliMUONPad*>(fPads.At(index));
99ccb7f7 610 }
611 else
612 {
00de388f 613 AliError(Form("Requested index %d out of bounds (%d) Mult is %d",index,
e0de1dd9 614 fPads.GetLast(),Multiplicity()));
00de388f 615 DumpMe();
99ccb7f7 616 }
617 return 0x0;
618}
619
620
621//_____________________________________________________________________________
622void
623AliMUONCluster::Paint(Option_t*)
624{
625 /// Paint this cluster
626 if (!Multiplicity()) return;
627
628 AliMpArea area(Area());
629
630 gPad->Range(area.LeftBorder(),area.DownBorder(),area.RightBorder(),area.UpBorder());
631
632 gVirtualX->SetFillStyle(0);
633
634 gVirtualX->SetLineColor(2);
635 gVirtualX->SetLineWidth(4);
636 for ( Int_t i = 0; i < Multiplicity(); ++i)
637 {
638 AliMUONPad* pad = Pad(i);
639 if ( pad->Cathode() == 0 ) pad->Paint();
640 }
641
642 gVirtualX->SetLineColor(4);
643 gVirtualX->SetLineWidth(2);
644 for ( Int_t i = 0; i < Multiplicity(); ++i)
645 {
646 AliMUONPad* pad = Pad(i);
647 if ( pad->Cathode() == 1 ) pad->Paint();
648 }
649
650}
651
652//_____________________________________________________________________________
653void
00de388f 654AliMUONCluster::DumpMe() const
655{
656 /// printout
657 cout << "Cluster Id " << GetUniqueID() << " npads=" << Multiplicity()
658 << "(" << Multiplicity(0) << "," << Multiplicity(1) << ") RawCharge="
659 << RawCharge() << " (" << RawCharge(0) << "," << RawCharge(1)
660 << ") Charge=(" << Charge(0) << "," << Charge(1) <<")";
661 if ( HasPosition() )
662 {
663 cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
664 cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
665 }
666 cout << endl;
667// cout << " " << Area() << endl;
e0de1dd9 668 for (Int_t i = 0; i < fPads.GetSize(); ++i)
00de388f 669 {
1130977f 670 cout << Form("fPads[%d]=%p",i,fPads.At(i)) << endl;
e0de1dd9 671 if ( fPads.At(i) ) fPads.At(i)->Print();
672 }
00de388f 673}
674
675
676//_____________________________________________________________________________
677void
99ccb7f7 678AliMUONCluster::Print(Option_t* opt) const
679{
680 /// printout
681 cout << "Cluster Id " << GetUniqueID() << " npads=" << Multiplicity()
682 << "(" << Multiplicity(0) << "," << Multiplicity(1) << ") RawCharge="
683 << RawCharge() << " (" << RawCharge(0) << "," << RawCharge(1)
97d5019e 684 << ") Charge=(" << Charge(0) << "," << Charge(1) <<")";
99ccb7f7 685 if ( HasPosition() )
686 {
687 cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
688 cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
689 }
00de388f 690 cout << " " << Area();
e0de1dd9 691
692 TObjArray* a = static_cast<TObjArray*>(fPads.Clone());
693 a->Sort();
694 a->Print("",opt);
695 delete a;
99ccb7f7 696}
697
698//_____________________________________________________________________________
00de388f 699//Bool_t
700//AliMUONCluster::IsEqual(const TObject* obj) const
701//{
702// const AliMUONCluster* c = static_cast<const AliMUONCluster*>(obj);
703// if ( c->Multiplicity() != Multiplicity() ) return kFALSE;
704//
705// for ( Int_t i = 0; i < c->Multiplicity(); ++i )
706// {
707// AliMUONPad* p = c->Pad(i);
708// if ( p->Compare(Pad(i)) ) return kFALSE;
709// }
710// return kTRUE;
711//}
712
713//_____________________________________________________________________________
714Int_t
715AliMUONCluster::Compare(const TObject* obj) const
99ccb7f7 716{
00de388f 717 /// Compare two clusters. Comparison is made on position and rawcharge only.
718
719 const AliMUONCluster* cluster = static_cast<const AliMUONCluster*>(obj);
720
721 AliMpArea carea(cluster->Area());
722 AliMpArea area(Area());
723
6e97fbb8 724 if ( carea.GetPositionX() > area.GetPositionX() )
00de388f 725 {
726 return 1;
727 }
6e97fbb8 728 else if ( carea.GetPositionX() < area.GetPositionX() )
00de388f 729 {
730 return -1;
731 }
732 else
733 {
6e97fbb8 734 if ( carea.GetPositionY() > area.GetPositionY() )
00de388f 735 {
736 return 1;
737 }
6e97fbb8 738 else if ( carea.GetPositionY() < area.GetPositionY() )
00de388f 739 {
740 return -1;
741 }
742 else
743 {
744 if ( cluster->RawCharge() > RawCharge() )
745 {
746 return 1;
747 }
748 else if ( cluster->RawCharge() < RawCharge() )
749 {
750 return -1;
751 }
752 }
753 }
754 return 0;
99ccb7f7 755}
756
757//_____________________________________________________________________________
758void
759AliMUONCluster::RemovePad(AliMUONPad* pad)
760{
761 /// Remove a pad.
762 /// As a consequence, some internal information must be updated
763
e0de1dd9 764 fPads.Remove(pad);
765 fPads.Compress();
57f3728e 766 delete pad;
99ccb7f7 767 // update cluster's data
768 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
769 fMultiplicity[0]=fMultiplicity[1]=0;
770 fRawCharge[0]=fRawCharge[1]=0;
e0de1dd9 771 for ( Int_t i = 0; i <= fPads.GetLast(); ++i )
99ccb7f7 772 {
773 AliMUONPad* p = Pad(i);
774 if ( p->IsSaturated() )
775 {
776 fIsSaturated[p->Cathode()] = kTRUE;
777 }
778 ++fMultiplicity[p->Cathode()];
779 fRawCharge[p->Cathode()] += p->Charge();
780 }
99ccb7f7 781}
782
783//_____________________________________________________________________________
784Float_t
785AliMUONCluster::RawCharge() const
786{
787 /// Returns the raw average charge
788 return (RawCharge(0)+RawCharge(1))/2.0;
789}
790
791//_____________________________________________________________________________
792Float_t
793AliMUONCluster::RawCharge(Int_t cathode) const
794{
795 /// Returns the average charge of a given cathode
796 if ( cathode == 0 || cathode == 1 )
797 {
798 return fRawCharge[cathode];
799 }
800 return 0;
801}
802
803//_____________________________________________________________________________
804Float_t
805AliMUONCluster::RawChargeAsymmetry() const
806{
807 /// Returns the raw charge asymmetry
808 if ( RawCharge() > 0 )
809 {
810 return TMath::Abs(RawCharge(0)-RawCharge(1))/RawCharge();
811 }
812 return 0;
813}