]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCluster.cxx
Added the possibility to do diagnostics histograms.
[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
18#include "AliMUONCluster.h"
19
20#include "AliLog.h"
21#include "AliMUONPad.h"
22#include "TObjArray.h"
23#include "Riostream.h"
24#include "TVirtualPad.h"
25#include "TVirtualX.h"
26
27/// \class AliMUONCluster
28///
29/// A group of adjacent pads
30///
31/// Besides holding an internal array of AliMUONPads, this object
32/// also computes some global characteristics for that pad sets.
33///
34/// \author Laurent Aphecetche
35///
36
37/// \cond CLASSIMP
38ClassImp(AliMUONCluster)
39/// \endcond
40
41namespace
42{
43 //___________________________________________________________________________
44 Bool_t
45 ShouldUsePad(const AliMUONPad& pad,
46 Int_t cathode, Int_t statusMask, Bool_t matchMask)
47 {
48
49 // FIXME : we should only use >=0 status, so we can fully
50 // use masking possibility ?
51 if ( pad.Status() < 0 ) return kFALSE;
52
53 if ( pad.Cathode() == cathode && pad.IsReal() && !pad.IsSaturated() )
54 {
55 Bool_t test = ( ( pad.Status() & statusMask ) != 0 );
56 if ( !statusMask )
57 {
58 test = ( pad.Status() == 0 );
59 }
60 if ( ( test && matchMask ) || ( !test && !matchMask ) )
61 {
62 return kTRUE;
63 }
64 }
65 return kFALSE;
66 }
67
68 //___________________________________________________________________________
69 Int_t Unique(Int_t n, Double_t* array, Double_t precision)
70 {
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
74
75 Int_t count(1);
76
77 Int_t* index = new Int_t[n];
78
79 TMath::Sort(n,array,index);
80
81 for ( Int_t i = 1; i < n; ++i )
82 {
83 if ( array[index[i]] - array[index[i-1]] < -precision ) ++count;
84 }
85
86 delete[] index;
87
88 return count;
89 }
90}
91
92//_____________________________________________________________________________
93AliMUONCluster::AliMUONCluster()
94: TObject(),
95fPads(0x0),
96fHasPosition(kFALSE),
97fPosition(1E9,1E9),
98fPositionError(1E9,1E9),
99fHasCharge(kFALSE),
100fChi2(0),
101fIsSorted(kFALSE)
102{
103 /// ctor
104 fMultiplicity[0]=fMultiplicity[1]=0;
105 fRawCharge[0]=fRawCharge[1]=0;
106 fCharge[0]=fCharge[1]=0;
107 fIsSaturated[0]=fIsSaturated[1]=kFALSE;
108}
109
110//_____________________________________________________________________________
111AliMUONCluster::AliMUONCluster(const AliMUONCluster& src)
112: TObject(src),
113fPads(0x0),
114fHasPosition(kFALSE),
115fPosition(1E9,1E9),
116fPositionError(1E9,1E9),
117fHasCharge(kFALSE),
118fChi2(0),
119fIsSorted(kFALSE)
120{
121 /// copy ctor
122 src.Copy(*this);
123}
124
125//_____________________________________________________________________________
126AliMUONCluster&
127AliMUONCluster::operator=(const AliMUONCluster& src)
128{
129 /// assignement operator
130 AliMUONCluster c(src);
131 c.Copy(*this);
132 return *this;
133}
134
135//_____________________________________________________________________________
136AliMUONCluster::~AliMUONCluster()
137{
138 /// dtor : note that we're owner of our pads
139 delete fPads;
140}
141
142//_____________________________________________________________________________
143void
144AliMUONCluster::AddPad(const AliMUONPad& pad)
145{
146 /// Add a pad to our pad array, and update some internal information
147 /// accordingly.
148 /// If pad array was sorted prior to this call, we re-sort it after
149 /// actual addition.
150
151 if (!fPads)
152 {
153 fPads = new TObjArray(10);
154 fPads->SetOwner(kTRUE);
155 }
156 AliMUONPad* p = new AliMUONPad(pad);
157 fPads->AddLast(p);
158 p->SetClusterId(GetUniqueID());
159 Int_t cathode = p->Cathode();
160 ++(fMultiplicity[cathode]);
161 fRawCharge[cathode] += p->Charge();
162 if ( p->IsSaturated() )
163 {
164 fIsSaturated[p->Cathode()]=kTRUE;
165 }
166 if ( fIsSorted ) Sort();
167}
168
169//_____________________________________________________________________________
170AliMpArea
171AliMUONCluster::Area() const
172{
173 /// Return the geometrical area covered by this cluster
174
175 // Start by finding the (x,y) limits of this cluster
176 TVector2 lowerLeft(1E9,1E9);
177 TVector2 upperRight(-1E9,-1E9);
178
179 for ( Int_t i = 0; i < Multiplicity(); ++i )
180 {
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()) );
188 }
189
190 // then construct the area from those limits
191 return AliMpArea((lowerLeft+upperRight)/2,
192 (upperRight-lowerLeft)/2);
193}
194
195//_____________________________________________________________________________
196void
197AliMUONCluster::Copy(TObject& obj) const
198{
199 //
200 // Copy this cluster to (cluster&)obj
201 //
202 TObject::Copy(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;
210 dest.fChi2 = fChi2;
211 for ( Int_t i = 0; i < 2; ++i )
212 {
213 dest.fRawCharge[i] = fRawCharge[i];
214 dest.fCharge[i] = fCharge[i];
215 dest.fMultiplicity[i] = fMultiplicity[i];
216 dest.fIsSaturated[i] = fIsSaturated[i];
217 }
218}
219
220//_____________________________________________________________________________
221Float_t
222AliMUONCluster::Charge() const
223{
224 /// Return the average charge over both cathodes
225 return (Charge(0)+Charge(1))/2.0;
226}
227
228//_____________________________________________________________________________
229Float_t
230AliMUONCluster::Charge(Int_t cathode) const
231{
232 /// Returns the charge of a given cathode
233 if ( !fHasCharge ) return RawCharge(cathode);
234
235 if ( cathode == 0 || cathode == 1 )
236 {
237 return fCharge[cathode];
238 }
239 return 0;
240}
241
242//_____________________________________________________________________________
243Float_t
244AliMUONCluster::ChargeAsymmetry() const
245{
246 /// Returns the charge asymmetry
247 if ( Charge() > 0 )
248 {
249 return TMath::Abs(Charge(0)-Charge(1))/Charge();
250 }
251 return 0;
252}
253
254//_____________________________________________________________________________
255TVector2
256AliMUONCluster::MinPadDimensions(Int_t statusMask, Bool_t matchMask) const
257{
258 /// Returns the minimum pad dimensions (half sizes), only considering
259 /// pads matching (or not, depending matchMask) a given mask
260
261 TVector2 cath0(MinPadDimensions(0,statusMask,matchMask));
262 TVector2 cath1(MinPadDimensions(1,statusMask,matchMask));
263
264 return TVector2( TMath::Min(cath0.X(),cath1.X()),
265 TMath::Min(cath0.Y(),cath1.Y()) );
266}
267
268//_____________________________________________________________________________
269TVector2
270AliMUONCluster::MinPadDimensions(Int_t cathode,
271 Int_t statusMask, Bool_t matchMask) const
272{
273 /// Returns the minimum pad dimensions (half sizes), only considering
274 /// pads matching (or not, depending matchMask) a given mask, within a
275 /// given cathode
276
277 Double_t xmin(1E9);
278 Double_t ymin(1E9);
279
280 for ( Int_t i = 0; i < Multiplicity(); ++i )
281 {
282 AliMUONPad* pad = Pad(i);
283 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
284 {
285 xmin = TMath::Min(xmin,pad->DX());
286 ymin = TMath::Min(ymin,pad->DY());
287 }
288 }
289 return TVector2(xmin,ymin);
290}
291
292//_____________________________________________________________________________
293Int_t
294AliMUONCluster::Multiplicity() const
295{
296 /// Returns the total number of pads in this cluster
297 return Multiplicity(0)+Multiplicity(1);
298}
299
300//_____________________________________________________________________________
301Int_t
302AliMUONCluster::Multiplicity(Int_t cathode) const
303{
304 /// Returns the number of pads in this cluster, in the given cathode
305 if ( cathode == 0 || cathode == 1 )
306 {
307 return fMultiplicity[cathode];
308 }
309 return 0;
310}
311
312//_____________________________________________________________________________
313AliMpIntPair
314AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
315{
316 /// Number of pads satisfying (or not, depending matchMask) a
317 /// given mask
318
319 Int_t nx, ny;
320
321 TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
322 TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
323
324 AliMpIntPair npad0(NofPads(0,statusMask,matchMask));
325 AliMpIntPair npad1(NofPads(1,statusMask,matchMask));
326
327 if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
328 {
329 nx = TMath::Max( npad0.GetFirst(), npad1.GetFirst() );
330 }
331 else
332 {
333 nx = dim0.X() < dim1.X() ? npad0.GetFirst() : npad1.GetFirst();
334 }
335
336 if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
337 {
338 ny = TMath::Max( npad0.GetSecond(), npad1.GetSecond() );
339 }
340 else
341 {
342 ny = dim0.Y() < dim1.Y() ? npad0.GetSecond() : npad1.GetSecond();
343 }
344
345 return AliMpIntPair(nx,ny);
346}
347
348//_____________________________________________________________________________
349AliMpIntPair
350AliMUONCluster::NofPads(Int_t cathode,
351 Int_t statusMask, Bool_t matchMask) const
352{
353 /// Number of pads of a given cathode, satisfying (or not,
354 /// depending matchMask) a given mask
355
356 Int_t n = Multiplicity(cathode);
357 if (!n)
358 {
359 return AliMpIntPair(0,0);
360 }
361 Double_t* x = new Double_t[n];
362 Double_t* y = new Double_t[n];
363 Int_t np(0);
364
365 for ( Int_t i = 0; i < Multiplicity(); ++i )
366 {
367 AliMUONPad* pad = Pad(i);
368 if ( ShouldUsePad(*pad,cathode,statusMask,matchMask) )
369 {
370 x[np] = pad->X();
371 y[np] = pad->Y();
372 ++np;
373 }
374 }
375
376 Int_t cx = Unique(np,x,0.01);
377 Int_t cy = Unique(np,y,0.01);
378
379 delete[] x;
380 delete[] y;
381
382 return AliMpIntPair(cx,cy);
383}
384
385//_____________________________________________________________________________
386AliMUONPad*
387AliMUONCluster::Pad(Int_t index) const
388{
389 /// Returns the index-th pad
390
391 if (!fPads) return 0x0;
392 if ( index < fPads->GetLast()+1 )
393 {
394 return static_cast<AliMUONPad*>(fPads->At(index));
395 }
396 else
397 {
398 AliError(Form("Requesting index %d out of bounds (%d)",index,fPads->GetLast()));
399 }
400 return 0x0;
401}
402
403
404//_____________________________________________________________________________
405void
406AliMUONCluster::Paint(Option_t*)
407{
408 /// Paint this cluster
409 if (!Multiplicity()) return;
410
411 AliMpArea area(Area());
412
413 gPad->Range(area.LeftBorder(),area.DownBorder(),area.RightBorder(),area.UpBorder());
414
415 gVirtualX->SetFillStyle(0);
416
417 gVirtualX->SetLineColor(2);
418 gVirtualX->SetLineWidth(4);
419 for ( Int_t i = 0; i < Multiplicity(); ++i)
420 {
421 AliMUONPad* pad = Pad(i);
422 if ( pad->Cathode() == 0 ) pad->Paint();
423 }
424
425 gVirtualX->SetLineColor(4);
426 gVirtualX->SetLineWidth(2);
427 for ( Int_t i = 0; i < Multiplicity(); ++i)
428 {
429 AliMUONPad* pad = Pad(i);
430 if ( pad->Cathode() == 1 ) pad->Paint();
431 }
432
433}
434
435//_____________________________________________________________________________
436void
437AliMUONCluster::Print(Option_t* opt) const
438{
439 /// printout
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) <<")";
444 if ( HasPosition() )
445 {
446 cout << " (x,y)=(" << Position().X() << "," << Position().Y() << ")";
447 cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
448 }
449 AliMpArea a(Area());
450 cout << Form(" Area=(%e,%e,%e,%e)",a.LeftBorder(),a.RightBorder(),
451 a.DownBorder(),a.UpBorder());
452 cout << endl;
453 if (fPads)
454 {
455 fPads->Print("",opt);
456 }
457}
458
459//_____________________________________________________________________________
460void
461AliMUONCluster::Sort()
462{
463 /// Sort the pad array
464 fPads->Sort();
465 fIsSorted = kTRUE;
466}
467
468//_____________________________________________________________________________
469void
470AliMUONCluster::RemovePad(AliMUONPad* pad)
471{
472 /// Remove a pad.
473 /// As a consequence, some internal information must be updated
474
475 fPads->Remove(pad);
476 fPads->Compress();
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 )
482 {
483 AliMUONPad* p = Pad(i);
484 if ( p->IsSaturated() )
485 {
486 fIsSaturated[p->Cathode()] = kTRUE;
487 }
488 ++fMultiplicity[p->Cathode()];
489 fRawCharge[p->Cathode()] += p->Charge();
490 }
491 if (fIsSorted) Sort();
492}
493
494//_____________________________________________________________________________
495Float_t
496AliMUONCluster::RawCharge() const
497{
498 /// Returns the raw average charge
499 return (RawCharge(0)+RawCharge(1))/2.0;
500}
501
502//_____________________________________________________________________________
503Float_t
504AliMUONCluster::RawCharge(Int_t cathode) const
505{
506 /// Returns the average charge of a given cathode
507 if ( cathode == 0 || cathode == 1 )
508 {
509 return fRawCharge[cathode];
510 }
511 return 0;
512}
513
514//_____________________________________________________________________________
515Float_t
516AliMUONCluster::RawChargeAsymmetry() const
517{
518 /// Returns the raw charge asymmetry
519 if ( RawCharge() > 0 )
520 {
521 return TMath::Abs(RawCharge(0)-RawCharge(1))/RawCharge();
522 }
523 return 0;
524}