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 //AZ 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);
209 dest.fPads = static_cast<TObjArray*>(fPads->Clone());
211 dest.fHasPosition = fHasPosition;
212 dest.fPosition = fPosition;
213 dest.fPositionError = fPositionError;
214 dest.fHasCharge = fHasCharge;
215 dest.fIsSorted = fIsSorted;
217 for ( Int_t i = 0; i < 2; ++i )
219 dest.fRawCharge[i] = fRawCharge[i];
220 dest.fCharge[i] = fCharge[i];
221 dest.fMultiplicity[i] = fMultiplicity[i];
222 dest.fIsSaturated[i] = fIsSaturated[i];
226 //_____________________________________________________________________________
228 AliMUONCluster::Charge() const
230 /// Return the average charge over both cathodes
231 return (Charge(0)+Charge(1))/2.0;
234 //_____________________________________________________________________________
236 AliMUONCluster::Charge(Int_t cathode) const
238 /// Returns the charge of a given cathode
239 if ( !fHasCharge ) return RawCharge(cathode);
241 if ( cathode == 0 || cathode == 1 )
243 return fCharge[cathode];
248 //_____________________________________________________________________________
250 AliMUONCluster::ChargeAsymmetry() const
252 /// Returns the charge asymmetry
255 return TMath::Abs(Charge(0)-Charge(1))/Charge();
260 //_____________________________________________________________________________
262 AliMUONCluster::MinPadDimensions(Int_t statusMask, Bool_t matchMask) const
264 /// Returns the minimum pad dimensions (half sizes), only considering
265 /// pads matching (or not, depending matchMask) a given mask
267 TVector2 cath0(MinPadDimensions(0,statusMask,matchMask));
268 TVector2 cath1(MinPadDimensions(1,statusMask,matchMask));
270 return TVector2( TMath::Min(cath0.X(),cath1.X()),
271 TMath::Min(cath0.Y(),cath1.Y()) );
274 //_____________________________________________________________________________
276 AliMUONCluster::MinPadDimensions(Int_t cathode,
277 Int_t statusMask, Bool_t matchMask) const
279 /// Returns the minimum pad dimensions (half sizes), only considering
280 /// pads matching (or not, depending matchMask) a given mask, within a
286 for ( Int_t i = 0; i < Multiplicity(); ++i )
288 AliMUONPad* pad = Pad(i);
289 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
291 xmin = TMath::Min(xmin,pad->DX());
292 ymin = TMath::Min(ymin,pad->DY());
295 return TVector2(xmin,ymin);
298 //_____________________________________________________________________________
300 AliMUONCluster::Multiplicity() const
302 /// Returns the total number of pads in this cluster
303 return Multiplicity(0)+Multiplicity(1);
306 //_____________________________________________________________________________
308 AliMUONCluster::Multiplicity(Int_t cathode) const
310 /// Returns the number of pads in this cluster, in the given cathode
311 if ( cathode == 0 || cathode == 1 )
313 return fMultiplicity[cathode];
318 //_____________________________________________________________________________
320 AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
322 /// Number of pads satisfying (or not, depending matchMask) a
327 TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
328 TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
330 AliMpIntPair npad0(NofPads(0,statusMask,matchMask));
331 AliMpIntPair npad1(NofPads(1,statusMask,matchMask));
333 if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
335 nx = TMath::Max( npad0.GetFirst(), npad1.GetFirst() );
339 nx = dim0.X() < dim1.X() ? npad0.GetFirst() : npad1.GetFirst();
342 if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
344 ny = TMath::Max( npad0.GetSecond(), npad1.GetSecond() );
348 ny = dim0.Y() < dim1.Y() ? npad0.GetSecond() : npad1.GetSecond();
351 return AliMpIntPair(nx,ny);
354 //_____________________________________________________________________________
356 AliMUONCluster::NofPads(Int_t cathode,
357 Int_t statusMask, Bool_t matchMask) const
359 /// Number of pads of a given cathode, satisfying (or not,
360 /// depending matchMask) a given mask
362 Int_t n = Multiplicity(cathode);
365 return AliMpIntPair(0,0);
367 Double_t* x = new Double_t[n];
368 Double_t* y = new Double_t[n];
371 for ( Int_t i = 0; i < Multiplicity(); ++i )
373 AliMUONPad* pad = Pad(i);
374 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
382 Int_t cx = Unique(np,x,0.01);
383 Int_t cy = Unique(np,y,0.01);
388 return AliMpIntPair(cx,cy);
391 //_____________________________________________________________________________
393 AliMUONCluster::Pad(Int_t index) const
395 /// Returns the index-th pad
397 if (!fPads) return 0x0;
398 if ( index < fPads->GetLast()+1 )
400 return static_cast<AliMUONPad*>(fPads->At(index));
404 AliError(Form("Requesting index %d out of bounds (%d)",index,fPads->GetLast()));
410 //_____________________________________________________________________________
412 AliMUONCluster::Paint(Option_t*)
414 /// Paint this cluster
415 if (!Multiplicity()) return;
417 AliMpArea area(Area());
419 gPad->Range(area.LeftBorder(),area.DownBorder(),area.RightBorder(),area.UpBorder());
421 gVirtualX->SetFillStyle(0);
423 gVirtualX->SetLineColor(2);
424 gVirtualX->SetLineWidth(4);
425 for ( Int_t i = 0; i < Multiplicity(); ++i)
427 AliMUONPad* pad = Pad(i);
428 if ( pad->Cathode() == 0 ) pad->Paint();
431 gVirtualX->SetLineColor(4);
432 gVirtualX->SetLineWidth(2);
433 for ( Int_t i = 0; i < Multiplicity(); ++i)
435 AliMUONPad* pad = Pad(i);
436 if ( pad->Cathode() == 1 ) pad->Paint();
441 //_____________________________________________________________________________
443 AliMUONCluster::Print(Option_t* opt) const
446 cout << "Cluster Id " << GetUniqueID() << " npads=" << Multiplicity()
447 << "(" << Multiplicity(0) << "," << Multiplicity(1) << ") RawCharge="
448 << RawCharge() << " (" << RawCharge(0) << "," << RawCharge(1)
449 << ") Charge=(" << Charge(0) << "," << Charge(1) <<")";
452 cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
453 cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
455 cout << " " << Area() << endl;
458 fPads->Print("",opt);
462 //_____________________________________________________________________________
464 AliMUONCluster::Sort()
466 /// Sort the pad array
471 //_____________________________________________________________________________
473 AliMUONCluster::RemovePad(AliMUONPad* pad)
476 /// As a consequence, some internal information must be updated
480 // update cluster's data
481 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
482 fMultiplicity[0]=fMultiplicity[1]=0;
483 fRawCharge[0]=fRawCharge[1]=0;
484 for ( Int_t i = 0; i <= fPads->GetLast(); ++i )
486 AliMUONPad* p = Pad(i);
487 if ( p->IsSaturated() )
489 fIsSaturated[p->Cathode()] = kTRUE;
491 ++fMultiplicity[p->Cathode()];
492 fRawCharge[p->Cathode()] += p->Charge();
494 if (fIsSorted) Sort();
497 //_____________________________________________________________________________
499 AliMUONCluster::RawCharge() const
501 /// Returns the raw average charge
502 return (RawCharge(0)+RawCharge(1))/2.0;
505 //_____________________________________________________________________________
507 AliMUONCluster::RawCharge(Int_t cathode) const
509 /// Returns the average charge of a given cathode
510 if ( cathode == 0 || cathode == 1 )
512 return fRawCharge[cathode];
517 //_____________________________________________________________________________
519 AliMUONCluster::RawChargeAsymmetry() const
521 /// Returns the raw charge asymmetry
522 if ( RawCharge() > 0 )
524 return TMath::Abs(RawCharge(0)-RawCharge(1))/RawCharge();