1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include <Riostream.h>
20 #include <TObjArray.h>
21 #include <TVirtualPad.h>
22 #include <TVirtualX.h>
24 #include "AliMUONCluster.h"
27 #include "AliMUONPad.h"
29 /// \class AliMUONCluster
31 /// A group of adjacent pads
33 /// Besides holding an internal array of AliMUONPads, this object
34 /// also computes some global characteristics for that pad sets.
36 /// \author Laurent Aphecetche
40 ClassImp(AliMUONCluster)
45 //___________________________________________________________________________
47 ShouldUsePad(const AliMUONPad& pad,
48 Int_t cathode, Int_t statusMask, Bool_t matchMask)
51 // FIXME : we should only use >=0 status, so we can fully
52 // use masking possibility ?
53 if ( pad.Status() < 0 ) return kFALSE;
55 if ( pad.Cathode() == cathode && pad.IsReal() && !pad.IsSaturated() )
57 Bool_t test = ( ( pad.Status() & statusMask ) != 0 );
60 test = ( pad.Status() == 0 );
62 if ( ( test && matchMask ) || ( !test && !matchMask ) )
70 //___________________________________________________________________________
71 Int_t Unique(Int_t n, Double_t* array, Double_t precision)
73 /// Return the number of *different* elements in array
74 /// where different is up to precision
75 /// Note that we assume that n is >= 1
79 Int_t* index = new Int_t[n];
81 TMath::Sort(n,array,index);
83 for ( Int_t i = 1; i < n; ++i )
85 if ( array[index[i]] - array[index[i-1]] < -precision ) ++count;
94 //_____________________________________________________________________________
95 AliMUONCluster::AliMUONCluster()
100 fPositionError(1E9,1E9),
106 fMultiplicity[0]=fMultiplicity[1]=0;
107 fRawCharge[0]=fRawCharge[1]=0;
108 fCharge[0]=fCharge[1]=0;
109 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
112 //_____________________________________________________________________________
113 AliMUONCluster::AliMUONCluster(const AliMUONCluster& src)
116 fHasPosition(kFALSE),
118 fPositionError(1E9,1E9),
127 //_____________________________________________________________________________
129 AliMUONCluster::operator=(const AliMUONCluster& src)
131 /// assignement operator
132 AliMUONCluster c(src);
137 //_____________________________________________________________________________
138 AliMUONCluster::~AliMUONCluster()
140 /// dtor : note that we're owner of our pads
144 //_____________________________________________________________________________
146 AliMUONCluster::AddPad(const AliMUONPad& pad)
148 /// Add a pad to our pad array, and update some internal information
150 /// If pad array was sorted prior to this call, we re-sort it after
155 fPads = new TObjArray(10);
156 fPads->SetOwner(kTRUE);
158 AliMUONPad* p = new AliMUONPad(pad);
160 p->SetClusterId(GetUniqueID());
161 Int_t cathode = p->Cathode();
162 ++(fMultiplicity[cathode]);
163 fRawCharge[cathode] += p->Charge();
164 if ( p->IsSaturated() )
166 fIsSaturated[p->Cathode()]=kTRUE;
168 if ( fIsSorted ) Sort();
171 //_____________________________________________________________________________
173 AliMUONCluster::Area() const
175 /// Return the geometrical area covered by this cluster
177 // Start by finding the (x,y) limits of this cluster
178 TVector2 lowerLeft(1E9,1E9);
179 TVector2 upperRight(-1E9,-1E9);
181 for ( Int_t i = 0; i < Multiplicity(); ++i )
183 AliMUONPad* pad = Pad(i);
184 TVector2 ll = pad->Position() - pad->Dimensions();
185 TVector2 ur = pad->Position() + pad->Dimensions();
186 lowerLeft.Set( TMath::Min(ll.X(),lowerLeft.X()),
187 TMath::Min(ll.Y(),lowerLeft.Y()) );
188 upperRight.Set( TMath::Max(ur.X(),upperRight.X()),
189 TMath::Max(ur.Y(),upperRight.Y()) );
192 // then construct the area from those limits
193 return AliMpArea((lowerLeft+upperRight)/2,
194 (upperRight-lowerLeft)/2);
197 //_____________________________________________________________________________
199 AliMUONCluster::Copy(TObject& obj) const
202 /// Copy this cluster to (cluster&)obj
205 AliMUONCluster& dest = static_cast<AliMUONCluster&>(obj);
206 dest.fPads = static_cast<TObjArray*>(fPads->Clone());
207 dest.fHasPosition = fHasPosition;
208 dest.fPosition = fPosition;
209 dest.fPositionError = fPositionError;
210 dest.fHasCharge = fHasCharge;
211 dest.fIsSorted = fIsSorted;
213 for ( Int_t i = 0; i < 2; ++i )
215 dest.fRawCharge[i] = fRawCharge[i];
216 dest.fCharge[i] = fCharge[i];
217 dest.fMultiplicity[i] = fMultiplicity[i];
218 dest.fIsSaturated[i] = fIsSaturated[i];
222 //_____________________________________________________________________________
224 AliMUONCluster::Charge() const
226 /// Return the average charge over both cathodes
227 return (Charge(0)+Charge(1))/2.0;
230 //_____________________________________________________________________________
232 AliMUONCluster::Charge(Int_t cathode) const
234 /// Returns the charge of a given cathode
235 if ( !fHasCharge ) return RawCharge(cathode);
237 if ( cathode == 0 || cathode == 1 )
239 return fCharge[cathode];
244 //_____________________________________________________________________________
246 AliMUONCluster::ChargeAsymmetry() const
248 /// Returns the charge asymmetry
251 return TMath::Abs(Charge(0)-Charge(1))/Charge();
256 //_____________________________________________________________________________
258 AliMUONCluster::MinPadDimensions(Int_t statusMask, Bool_t matchMask) const
260 /// Returns the minimum pad dimensions (half sizes), only considering
261 /// pads matching (or not, depending matchMask) a given mask
263 TVector2 cath0(MinPadDimensions(0,statusMask,matchMask));
264 TVector2 cath1(MinPadDimensions(1,statusMask,matchMask));
266 return TVector2( TMath::Min(cath0.X(),cath1.X()),
267 TMath::Min(cath0.Y(),cath1.Y()) );
270 //_____________________________________________________________________________
272 AliMUONCluster::MinPadDimensions(Int_t cathode,
273 Int_t statusMask, Bool_t matchMask) const
275 /// Returns the minimum pad dimensions (half sizes), only considering
276 /// pads matching (or not, depending matchMask) a given mask, within a
282 for ( Int_t i = 0; i < Multiplicity(); ++i )
284 AliMUONPad* pad = Pad(i);
285 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
287 xmin = TMath::Min(xmin,pad->DX());
288 ymin = TMath::Min(ymin,pad->DY());
291 return TVector2(xmin,ymin);
294 //_____________________________________________________________________________
296 AliMUONCluster::Multiplicity() const
298 /// Returns the total number of pads in this cluster
299 return Multiplicity(0)+Multiplicity(1);
302 //_____________________________________________________________________________
304 AliMUONCluster::Multiplicity(Int_t cathode) const
306 /// Returns the number of pads in this cluster, in the given cathode
307 if ( cathode == 0 || cathode == 1 )
309 return fMultiplicity[cathode];
314 //_____________________________________________________________________________
316 AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
318 /// Number of pads satisfying (or not, depending matchMask) a
323 TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
324 TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
326 AliMpIntPair npad0(NofPads(0,statusMask,matchMask));
327 AliMpIntPair npad1(NofPads(1,statusMask,matchMask));
329 if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
331 nx = TMath::Max( npad0.GetFirst(), npad1.GetFirst() );
335 nx = dim0.X() < dim1.X() ? npad0.GetFirst() : npad1.GetFirst();
338 if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
340 ny = TMath::Max( npad0.GetSecond(), npad1.GetSecond() );
344 ny = dim0.Y() < dim1.Y() ? npad0.GetSecond() : npad1.GetSecond();
347 return AliMpIntPair(nx,ny);
350 //_____________________________________________________________________________
352 AliMUONCluster::NofPads(Int_t cathode,
353 Int_t statusMask, Bool_t matchMask) const
355 /// Number of pads of a given cathode, satisfying (or not,
356 /// depending matchMask) a given mask
358 Int_t n = Multiplicity(cathode);
361 return AliMpIntPair(0,0);
363 Double_t* x = new Double_t[n];
364 Double_t* y = new Double_t[n];
367 for ( Int_t i = 0; i < Multiplicity(); ++i )
369 AliMUONPad* pad = Pad(i);
370 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
378 Int_t cx = Unique(np,x,0.01);
379 Int_t cy = Unique(np,y,0.01);
384 return AliMpIntPair(cx,cy);
387 //_____________________________________________________________________________
389 AliMUONCluster::Pad(Int_t index) const
391 /// Returns the index-th pad
393 if (!fPads) return 0x0;
394 if ( index < fPads->GetLast()+1 )
396 return static_cast<AliMUONPad*>(fPads->At(index));
400 AliError(Form("Requesting index %d out of bounds (%d)",index,fPads->GetLast()));
406 //_____________________________________________________________________________
408 AliMUONCluster::Paint(Option_t*)
410 /// Paint this cluster
411 if (!Multiplicity()) return;
413 AliMpArea area(Area());
415 gPad->Range(area.LeftBorder(),area.DownBorder(),area.RightBorder(),area.UpBorder());
417 gVirtualX->SetFillStyle(0);
419 gVirtualX->SetLineColor(2);
420 gVirtualX->SetLineWidth(4);
421 for ( Int_t i = 0; i < Multiplicity(); ++i)
423 AliMUONPad* pad = Pad(i);
424 if ( pad->Cathode() == 0 ) pad->Paint();
427 gVirtualX->SetLineColor(4);
428 gVirtualX->SetLineWidth(2);
429 for ( Int_t i = 0; i < Multiplicity(); ++i)
431 AliMUONPad* pad = Pad(i);
432 if ( pad->Cathode() == 1 ) pad->Paint();
437 //_____________________________________________________________________________
439 AliMUONCluster::Print(Option_t* opt) const
442 cout << "Cluster Id " << GetUniqueID() << " npads=" << Multiplicity()
443 << "(" << Multiplicity(0) << "," << Multiplicity(1) << ") RawCharge="
444 << RawCharge() << " (" << RawCharge(0) << "," << RawCharge(1)
445 << ") Charge=(" << Charge(0) << "," << Charge(1) <<")";
448 cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
449 cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
451 cout << " " << Area() << endl;
454 fPads->Print("",opt);
458 //_____________________________________________________________________________
460 AliMUONCluster::Sort()
462 /// Sort the pad array
467 //_____________________________________________________________________________
469 AliMUONCluster::RemovePad(AliMUONPad* pad)
472 /// As a consequence, some internal information must be updated
476 // update cluster's data
477 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
478 fMultiplicity[0]=fMultiplicity[1]=0;
479 fRawCharge[0]=fRawCharge[1]=0;
480 for ( Int_t i = 0; i <= fPads->GetLast(); ++i )
482 AliMUONPad* p = Pad(i);
483 if ( p->IsSaturated() )
485 fIsSaturated[p->Cathode()] = kTRUE;
487 ++fMultiplicity[p->Cathode()];
488 fRawCharge[p->Cathode()] += p->Charge();
490 if (fIsSorted) Sort();
493 //_____________________________________________________________________________
495 AliMUONCluster::RawCharge() const
497 /// Returns the raw average charge
498 return (RawCharge(0)+RawCharge(1))/2.0;
501 //_____________________________________________________________________________
503 AliMUONCluster::RawCharge(Int_t cathode) const
505 /// Returns the average charge of a given cathode
506 if ( cathode == 0 || cathode == 1 )
508 return fRawCharge[cathode];
513 //_____________________________________________________________________________
515 AliMUONCluster::RawChargeAsymmetry() const
517 /// Returns the raw charge asymmetry
518 if ( RawCharge() > 0 )
520 return TMath::Abs(RawCharge(0)-RawCharge(1))/RawCharge();