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 "AliMUONCluster.h"
21 #include "AliMUONPad.h"
22 #include "TObjArray.h"
23 #include "Riostream.h"
24 #include "TVirtualPad.h"
25 #include "TVirtualX.h"
27 /// \class AliMUONCluster
29 /// A group of adjacent pads
31 /// Besides holding an internal array of AliMUONPads, this object
32 /// also computes some global characteristics for that pad sets.
34 /// \author Laurent Aphecetche
38 ClassImp(AliMUONCluster)
43 //___________________________________________________________________________
45 ShouldUsePad(const AliMUONPad& pad,
46 Int_t cathode, Int_t statusMask, Bool_t matchMask)
49 // FIXME : we should only use >=0 status, so we can fully
50 // use masking possibility ?
51 if ( pad.Status() < 0 ) return kFALSE;
53 if ( pad.Cathode() == cathode && pad.IsReal() && !pad.IsSaturated() )
55 Bool_t test = ( ( pad.Status() & statusMask ) != 0 );
58 test = ( pad.Status() == 0 );
60 if ( ( test && matchMask ) || ( !test && !matchMask ) )
68 //___________________________________________________________________________
69 Int_t Unique(Int_t n, Double_t* array, Double_t precision)
71 /// Return the number of *different* elements in array
72 /// where different is up to precision
73 /// Note that we assume that n is >= 1
77 Int_t* index = new Int_t[n];
79 TMath::Sort(n,array,index);
81 for ( Int_t i = 1; i < n; ++i )
83 if ( array[index[i]] - array[index[i-1]] < -precision ) ++count;
92 //_____________________________________________________________________________
93 AliMUONCluster::AliMUONCluster()
98 fPositionError(1E9,1E9),
104 fMultiplicity[0]=fMultiplicity[1]=0;
105 fRawCharge[0]=fRawCharge[1]=0;
106 fCharge[0]=fCharge[1]=0;
107 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
110 //_____________________________________________________________________________
111 AliMUONCluster::AliMUONCluster(const AliMUONCluster& src)
114 fHasPosition(kFALSE),
116 fPositionError(1E9,1E9),
125 //_____________________________________________________________________________
127 AliMUONCluster::operator=(const AliMUONCluster& src)
129 /// assignement operator
130 AliMUONCluster c(src);
135 //_____________________________________________________________________________
136 AliMUONCluster::~AliMUONCluster()
138 /// dtor : note that we're owner of our pads
142 //_____________________________________________________________________________
144 AliMUONCluster::AddPad(const AliMUONPad& pad)
146 /// Add a pad to our pad array, and update some internal information
148 /// If pad array was sorted prior to this call, we re-sort it after
153 fPads = new TObjArray(10);
154 fPads->SetOwner(kTRUE);
156 AliMUONPad* p = new AliMUONPad(pad);
158 p->SetClusterId(GetUniqueID());
159 Int_t cathode = p->Cathode();
160 ++(fMultiplicity[cathode]);
161 fRawCharge[cathode] += p->Charge();
162 if ( p->IsSaturated() )
164 fIsSaturated[p->Cathode()]=kTRUE;
166 if ( fIsSorted ) Sort();
169 //_____________________________________________________________________________
171 AliMUONCluster::Area() const
173 /// Return the geometrical area covered by this cluster
175 // Start by finding the (x,y) limits of this cluster
176 TVector2 lowerLeft(1E9,1E9);
177 TVector2 upperRight(-1E9,-1E9);
179 for ( Int_t i = 0; i < Multiplicity(); ++i )
181 AliMUONPad* pad = Pad(i);
182 TVector2 ll = pad->Position() - pad->Dimensions();
183 TVector2 ur = pad->Position() + pad->Dimensions();
184 lowerLeft.Set( TMath::Min(ll.X(),lowerLeft.X()),
185 TMath::Min(ll.Y(),lowerLeft.Y()) );
186 upperRight.Set( TMath::Max(ur.X(),upperRight.X()),
187 TMath::Max(ur.Y(),upperRight.Y()) );
190 // then construct the area from those limits
191 return AliMpArea((lowerLeft+upperRight)/2,
192 (upperRight-lowerLeft)/2);
195 //_____________________________________________________________________________
197 AliMUONCluster::Copy(TObject& obj) const
200 // Copy this cluster to (cluster&)obj
203 AliMUONCluster& dest = static_cast<AliMUONCluster&>(obj);
204 dest.fPads = static_cast<TObjArray*>(fPads->Clone());
205 dest.fHasPosition = fHasPosition;
206 dest.fPosition = fPosition;
207 dest.fPositionError = fPositionError;
208 dest.fHasCharge = fHasCharge;
209 dest.fIsSorted = fIsSorted;
211 for ( Int_t i = 0; i < 2; ++i )
213 dest.fRawCharge[i] = fRawCharge[i];
214 dest.fCharge[i] = fCharge[i];
215 dest.fMultiplicity[i] = fMultiplicity[i];
216 dest.fIsSaturated[i] = fIsSaturated[i];
220 //_____________________________________________________________________________
222 AliMUONCluster::Charge() const
224 /// Return the average charge over both cathodes
225 return (Charge(0)+Charge(1))/2.0;
228 //_____________________________________________________________________________
230 AliMUONCluster::Charge(Int_t cathode) const
232 /// Returns the charge of a given cathode
233 if ( !fHasCharge ) return RawCharge(cathode);
235 if ( cathode == 0 || cathode == 1 )
237 return fCharge[cathode];
242 //_____________________________________________________________________________
244 AliMUONCluster::ChargeAsymmetry() const
246 /// Returns the charge asymmetry
249 return TMath::Abs(Charge(0)-Charge(1))/Charge();
254 //_____________________________________________________________________________
256 AliMUONCluster::MinPadDimensions(Int_t statusMask, Bool_t matchMask) const
258 /// Returns the minimum pad dimensions (half sizes), only considering
259 /// pads matching (or not, depending matchMask) a given mask
261 TVector2 cath0(MinPadDimensions(0,statusMask,matchMask));
262 TVector2 cath1(MinPadDimensions(1,statusMask,matchMask));
264 return TVector2( TMath::Min(cath0.X(),cath1.X()),
265 TMath::Min(cath0.Y(),cath1.Y()) );
268 //_____________________________________________________________________________
270 AliMUONCluster::MinPadDimensions(Int_t cathode,
271 Int_t statusMask, Bool_t matchMask) const
273 /// Returns the minimum pad dimensions (half sizes), only considering
274 /// pads matching (or not, depending matchMask) a given mask, within a
280 for ( Int_t i = 0; i < Multiplicity(); ++i )
282 AliMUONPad* pad = Pad(i);
283 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
285 xmin = TMath::Min(xmin,pad->DX());
286 ymin = TMath::Min(ymin,pad->DY());
289 return TVector2(xmin,ymin);
292 //_____________________________________________________________________________
294 AliMUONCluster::Multiplicity() const
296 /// Returns the total number of pads in this cluster
297 return Multiplicity(0)+Multiplicity(1);
300 //_____________________________________________________________________________
302 AliMUONCluster::Multiplicity(Int_t cathode) const
304 /// Returns the number of pads in this cluster, in the given cathode
305 if ( cathode == 0 || cathode == 1 )
307 return fMultiplicity[cathode];
312 //_____________________________________________________________________________
314 AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
316 /// Number of pads satisfying (or not, depending matchMask) a
321 TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
322 TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
324 AliMpIntPair npad0(NofPads(0,statusMask,matchMask));
325 AliMpIntPair npad1(NofPads(1,statusMask,matchMask));
327 if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
329 nx = TMath::Max( npad0.GetFirst(), npad1.GetFirst() );
333 nx = dim0.X() < dim1.X() ? npad0.GetFirst() : npad1.GetFirst();
336 if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
338 ny = TMath::Max( npad0.GetSecond(), npad1.GetSecond() );
342 ny = dim0.Y() < dim1.Y() ? npad0.GetSecond() : npad1.GetSecond();
345 return AliMpIntPair(nx,ny);
348 //_____________________________________________________________________________
350 AliMUONCluster::NofPads(Int_t cathode,
351 Int_t statusMask, Bool_t matchMask) const
353 /// Number of pads of a given cathode, satisfying (or not,
354 /// depending matchMask) a given mask
356 Int_t n = Multiplicity(cathode);
359 return AliMpIntPair(0,0);
361 Double_t* x = new Double_t[n];
362 Double_t* y = new Double_t[n];
365 for ( Int_t i = 0; i < Multiplicity(); ++i )
367 AliMUONPad* pad = Pad(i);
368 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
376 Int_t cx = Unique(np,x,0.01);
377 Int_t cy = Unique(np,y,0.01);
382 return AliMpIntPair(cx,cy);
385 //_____________________________________________________________________________
387 AliMUONCluster::Pad(Int_t index) const
389 /// Returns the index-th pad
391 if (!fPads) return 0x0;
392 if ( index < fPads->GetLast()+1 )
394 return static_cast<AliMUONPad*>(fPads->At(index));
398 AliError(Form("Requesting index %d out of bounds (%d)",index,fPads->GetLast()));
404 //_____________________________________________________________________________
406 AliMUONCluster::Paint(Option_t*)
408 /// Paint this cluster
409 if (!Multiplicity()) return;
411 AliMpArea area(Area());
413 gPad->Range(area.LeftBorder(),area.DownBorder(),area.RightBorder(),area.UpBorder());
415 gVirtualX->SetFillStyle(0);
417 gVirtualX->SetLineColor(2);
418 gVirtualX->SetLineWidth(4);
419 for ( Int_t i = 0; i < Multiplicity(); ++i)
421 AliMUONPad* pad = Pad(i);
422 if ( pad->Cathode() == 0 ) pad->Paint();
425 gVirtualX->SetLineColor(4);
426 gVirtualX->SetLineWidth(2);
427 for ( Int_t i = 0; i < Multiplicity(); ++i)
429 AliMUONPad* pad = Pad(i);
430 if ( pad->Cathode() == 1 ) pad->Paint();
435 //_____________________________________________________________________________
437 AliMUONCluster::Print(Option_t* opt) const
440 cout << "Cluster Id " << GetUniqueID() << " npads=" << Multiplicity()
441 << "(" << Multiplicity(0) << "," << Multiplicity(1) << ") RawCharge="
442 << RawCharge() << " (" << RawCharge(0) << "," << RawCharge(1)
443 << " Charge=(" << Charge(0) << "," << Charge(1) <<")";
446 cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
447 cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
450 cout << Form(" Area=(%e,%e,%e,%e)",a.LeftBorder(),a.RightBorder(),
451 a.DownBorder(),a.UpBorder());
455 fPads->Print("",opt);
459 //_____________________________________________________________________________
461 AliMUONCluster::Sort()
463 /// Sort the pad array
468 //_____________________________________________________________________________
470 AliMUONCluster::RemovePad(AliMUONPad* pad)
473 /// As a consequence, some internal information must be updated
477 // update cluster's data
478 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
479 fMultiplicity[0]=fMultiplicity[1]=0;
480 fRawCharge[0]=fRawCharge[1]=0;
481 for ( Int_t i = 0; i <= fPads->GetLast(); ++i )
483 AliMUONPad* p = Pad(i);
484 if ( p->IsSaturated() )
486 fIsSaturated[p->Cathode()] = kTRUE;
488 ++fMultiplicity[p->Cathode()];
489 fRawCharge[p->Cathode()] += p->Charge();
491 if (fIsSorted) Sort();
494 //_____________________________________________________________________________
496 AliMUONCluster::RawCharge() const
498 /// Returns the raw average charge
499 return (RawCharge(0)+RawCharge(1))/2.0;
502 //_____________________________________________________________________________
504 AliMUONCluster::RawCharge(Int_t cathode) const
506 /// Returns the average charge of a given cathode
507 if ( cathode == 0 || cathode == 1 )
509 return fRawCharge[cathode];
514 //_____________________________________________________________________________
516 AliMUONCluster::RawChargeAsymmetry() const
518 /// Returns the raw charge asymmetry
519 if ( RawCharge() > 0 )
521 return TMath::Abs(RawCharge(0)-RawCharge(1))/RawCharge();