]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCluster.cxx
Update responsibles for MCH, MTR, HMP
[u/mrichter/AliRoot.git] / MUON / AliMUONCluster.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 <Riostream.h>
19 #include <TMath.h>
20 #include <TObjArray.h>
21 #include <TVirtualPad.h>
22 #include <TVirtualX.h>
23
24 #include "AliMUONCluster.h"
25 #include "AliMUONPad.h"
26
27 #include "AliMpEncodePair.h"
28
29 #include "AliLog.h"
30
31 //-----------------------------------------------------------------------------
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 ///
41 //-----------------------------------------------------------------------------
42
43 using std::cout;
44 using std::endl;
45 /// \cond CLASSIMP
46 ClassImp(AliMUONCluster)
47 /// \endcond
48
49 namespace
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 //_____________________________________________________________________________
101 AliMUONCluster::AliMUONCluster() 
102 : TObject(), 
103 fPads(),
104 fHasPosition(kFALSE),
105 fPosition(1E9,1E9),
106 fPositionError(1E9,1E9),
107 fHasCharge(kFALSE),
108 fChi2(0)
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;
115   fPads.SetOwner(kTRUE);
116 }
117
118 //_____________________________________________________________________________
119 AliMUONCluster::AliMUONCluster(const AliMUONCluster& src)
120 : TObject(src),
121 fPads(),
122 fHasPosition(kFALSE),
123 fPosition(1E9,1E9),
124 fPositionError(1E9,1E9),
125 fHasCharge(kFALSE),
126 fChi2(0)
127 {
128   /// copy ctor
129   fPads.SetOwner(kTRUE);
130   src.Copy(*this);
131 }
132
133 //_____________________________________________________________________________
134 AliMUONCluster&
135 AliMUONCluster::operator=(const AliMUONCluster& src)
136 {
137   /// assignement operator
138   if ( this != &src ) 
139   {
140     src.Copy(*this);
141   }
142   return *this;
143 }
144
145 //_____________________________________________________________________________
146 AliMUONCluster::~AliMUONCluster()
147 {
148   /// dtor : note that we're owner of our pads
149 //   fPads.Delete();
150 }
151
152 //_____________________________________________________________________________
153 void
154 AliMUONCluster::Clear(Option_t*)
155 {
156   /// Clear our pad array
157   fPads.Clear();
158 //  fPads.Delete();
159 }
160
161 //_____________________________________________________________________________
162 Bool_t
163 AliMUONCluster::Contains(const AliMUONPad& pad) const
164 {
165   /// Whether this cluster contains the pad
166   if (fPads.IsEmpty()) return kFALSE;
167   
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 //_____________________________________________________________________________
177 void
178 AliMUONCluster::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 //_____________________________________________________________________________
196 AliMUONPad*
197 AliMUONCluster::AddPad(const AliMUONPad& pad)
198 {
199   /// Add a pad to our pad array, and update some internal information
200   /// accordingly.
201
202   AliMUONPad* p = new AliMUONPad(pad);
203   fPads.AddLast(p);
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   }
212   return p;
213 }
214
215 //___________________________________________________________________________
216 TString
217 AliMUONCluster::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 //___________________________________________________________________________
232 Bool_t
233 AliMUONCluster::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;
259 }
260
261 //_____________________________________________________________________________
262 AliMpArea
263 AliMUONCluster::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
283   return AliMpArea((lowerLeft+upperRight).X()/2,(lowerLeft+upperRight).Y()/2, 
284                    (upperRight-lowerLeft).X()/2, (upperRight-lowerLeft).Y()/2);
285 }
286
287 //_____________________________________________________________________________
288 AliMpArea
289 AliMUONCluster::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   
298   for ( Int_t i = 0; i < Multiplicity(); ++i )
299   {
300     AliMUONPad* pad = Pad(i);
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     }
310   }
311   
312   // then construct the area from those limits
313   return AliMpArea((lowerLeft+upperRight).X()/2,(lowerLeft+upperRight).Y()/2,
314                    (upperRight-lowerLeft).X()/2, (upperRight-lowerLeft).Y()/2);
315 }
316
317 //_____________________________________________________________________________
318 Bool_t
319 AliMUONCluster::IsMonoCathode() const
320 {
321   /// Whether we have signals only in one of the two cathodes
322   return (Cathode()<2);
323 }
324
325 //_____________________________________________________________________________
326 Int_t
327 AliMUONCluster::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 //_____________________________________________________________________________
352 void
353 AliMUONCluster::Copy(TObject& obj) const
354 {
355   ///
356   /// Copy this cluster to (cluster&)obj
357   ///
358   TObject::Copy(obj);
359   AliMUONCluster& dest = static_cast<AliMUONCluster&>(obj);
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   }
369   dest.fHasPosition = fHasPosition;
370   dest.fPosition = fPosition;
371   dest.fPositionError = fPositionError;
372   dest.fHasCharge = fHasCharge;
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 //_____________________________________________________________________________
384 Float_t 
385 AliMUONCluster::Charge() const
386 {
387   /// Return the average charge over both cathodes
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;
403 }
404
405 //_____________________________________________________________________________
406 Float_t
407 AliMUONCluster::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 //_____________________________________________________________________________
420 Float_t
421 AliMUONCluster::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 //_____________________________________________________________________________
432 TVector2
433 AliMUONCluster::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 //_____________________________________________________________________________
446 TVector2
447 AliMUONCluster::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 //_____________________________________________________________________________
470 TVector2
471 AliMUONCluster::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 //_____________________________________________________________________________
484 TVector2
485 AliMUONCluster::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 //_____________________________________________________________________________
508 Int_t 
509 AliMUONCluster::Multiplicity() const
510 {
511   /// Returns the total number of pads in this cluster
512   return Multiplicity(0)+Multiplicity(1);
513 }
514
515 //_____________________________________________________________________________
516 Int_t
517 AliMUONCluster::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 //_____________________________________________________________________________
528 Long_t
529 AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
530 {
531   /// Number of pads satisfying (or not, depending matchMask) a
532   /// given mask 
533   
534   Int_t nx, ny;
535   
536   TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
537   TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
538   
539   Long_t npad0(NofPads(0,statusMask,matchMask));
540   Long_t npad1(NofPads(1,statusMask,matchMask));
541   
542   if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
543   {
544     nx = TMath::Max( AliMp::PairFirst(npad0), AliMp::PairFirst(npad1) );
545   }
546   else
547   {
548     nx = dim0.X() < dim1.X() ? AliMp::PairFirst(npad0) : AliMp::PairFirst(npad1);
549   }
550   
551   if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
552   {
553     ny = TMath::Max( AliMp::PairSecond(npad0), AliMp::PairSecond(npad1) );
554   }
555   else
556   {
557     ny = dim0.Y() < dim1.Y() ? AliMp::PairSecond(npad0) : AliMp::PairSecond(npad1);
558   }
559   
560   return AliMp::Pair(nx,ny);
561 }
562
563 //_____________________________________________________________________________
564 Long_t
565 AliMUONCluster::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   {
574     return 0;
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   
597   return AliMp::Pair(cx,cy);
598 }
599
600 //_____________________________________________________________________________
601 AliMUONPad*
602 AliMUONCluster::Pad(Int_t index) const
603 {
604   /// Returns the index-th pad
605   
606   if (fPads.IsEmpty()) return 0x0;
607   if ( index < fPads.GetLast()+1 )
608   {
609     return static_cast<AliMUONPad*>(fPads.At(index));
610   }
611   else
612   {
613     AliError(Form("Requested index %d out of bounds (%d) Mult is %d",index,
614                   fPads.GetLast(),Multiplicity()));
615     DumpMe();
616   }
617   return 0x0;
618 }
619
620
621 //_____________________________________________________________________________
622 void
623 AliMUONCluster::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 //_____________________________________________________________________________
653 void
654 AliMUONCluster::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;
668   for (Int_t i = 0; i < fPads.GetSize(); ++i) 
669   {
670     cout << Form("fPads[%d]=%p",i,fPads.At(i)) << endl;
671     if ( fPads.At(i) ) fPads.At(i)->Print();
672   }
673 }
674
675
676 //_____________________________________________________________________________
677 void
678 AliMUONCluster::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)
684   << ") Charge=(" << Charge(0) << "," << Charge(1) <<")";
685   if ( HasPosition() )
686   {
687     cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
688     cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
689   }
690   cout << " " << Area();
691
692   TObjArray* a = static_cast<TObjArray*>(fPads.Clone());
693   a->Sort();
694   a->Print("",opt);
695   delete a;
696 }
697
698 //_____________________________________________________________________________
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 //_____________________________________________________________________________
714 Int_t 
715 AliMUONCluster::Compare(const TObject* obj) const
716 {
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
724   if ( carea.GetPositionX() > area.GetPositionX() ) 
725   {
726     return 1;
727   }
728   else if ( carea.GetPositionX() < area.GetPositionX() ) 
729   {
730     return -1;
731   }
732   else 
733   {
734     if ( carea.GetPositionY() > area.GetPositionY() ) 
735     {
736       return 1;
737     }
738     else if ( carea.GetPositionY() < area.GetPositionY() ) 
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;
755 }
756
757 //_____________________________________________________________________________
758 void
759 AliMUONCluster::RemovePad(AliMUONPad* pad)
760 {
761   /// Remove a pad. 
762   /// As a consequence, some internal information must be updated
763   
764   fPads.Remove(pad);
765   fPads.Compress();
766   delete pad;
767   // update cluster's data
768   fIsSaturated[0]=fIsSaturated[1]=kFALSE;
769   fMultiplicity[0]=fMultiplicity[1]=0;
770   fRawCharge[0]=fRawCharge[1]=0;
771   for ( Int_t i = 0; i <= fPads.GetLast(); ++i )
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   }
781 }
782
783 //_____________________________________________________________________________
784 Float_t 
785 AliMUONCluster::RawCharge() const
786 {
787   /// Returns the raw average charge
788   return (RawCharge(0)+RawCharge(1))/2.0;
789 }
790
791 //_____________________________________________________________________________
792 Float_t
793 AliMUONCluster::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 //_____________________________________________________________________________
804 Float_t
805 AliMUONCluster::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 }