AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONPad.cxx
Go to the documentation of this file.
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 "AliMUONPad.h"
19 
20 #include "AliLog.h"
21 #include "AliMpArea.h"
22 
23 #include "Riostream.h"
24 #include "TVirtualPad.h"
25 #include "TVirtualX.h"
26 #include "TVector2.h"
27 #include "TMath.h"
28 
29 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
42 
43 using std::setw;
44 using std::cout;
45 using std::endl;
46 using std::ios_base;
47 using std::cerr;
48 using std::ios;
52 
53 namespace
54 {
55  AliMpArea
56  Intersect(const AliMpArea& a, const AliMpArea& b)
57  {
58  //
59  // Returns the common part of a and b.
60  //
61  Double_t xmin = TMath::Max(a.LeftBorder(),b.LeftBorder());
62  Double_t xmax = TMath::Min(a.RightBorder(),b.RightBorder());
63  Double_t ymin = TMath::Max(a.DownBorder(),b.DownBorder());
64  Double_t ymax = TMath::Min(a.UpBorder(),b.UpBorder());
65  AliMpArea c( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ,
66  (xmax-xmin)/2.0, (ymax-ymin)/2.0 );
67 
68  return c;
69  }
70 }
71 
72 //_____________________________________________________________________________
74 :
75 TObject(),
76 fIsSaturated(kFALSE),
77 fIsReal(kFALSE),
78 fClusterId(-1),
79 fCathode(-1),
80 fDetElemId(-1),
81 fIx(-1),
82 fIy(-1),
83 fStatus(0),
84 fDimensions(),
85 fPosition(),
86 fCharge(0.0),
87 fChargeBackup(0.0)
88 {
90  Init(-1,-1,-1,-1,TVector2(0,0),TVector2(0,0),0);
91 }
92 
93 //_____________________________________________________________________________
94 AliMUONPad::AliMUONPad(Int_t detElemId, Int_t cathode,
95  Int_t ix, Int_t iy, Double_t x, Double_t y,
96  Double_t dx, Double_t dy, Double_t charge)
97 :
98 TObject(),
99 fIsSaturated(kFALSE),
100 fIsReal(kFALSE),
101 fClusterId(-1),
102 fCathode(-1),
103 fDetElemId(-1),
104 fIx(-1),
105 fIy(-1),
106 fStatus(0),
107 fDimensions(),
108 fPosition(),
109 fCharge(0.0),
110 fChargeBackup(0.0)
111 
112 {
114  Init(detElemId,cathode,ix,iy,TVector2(x,y),TVector2(dx,dy),charge);
115 }
116 
117 //_____________________________________________________________________________
118 AliMUONPad::AliMUONPad(Double_t x, Double_t y,
119  Double_t dx, Double_t dy, Double_t charge)
120 : TObject(),
121 fIsSaturated(kFALSE),
122 fIsReal(kFALSE),
123 fClusterId(-1),
124 fCathode(-1),
125 fDetElemId(-1),
126 fIx(-1),
127 fIy(-1),
128 fStatus(0),
129 fDimensions(),
130 fPosition(),
131 fCharge(0.0),
132 fChargeBackup(0.0)
133 {
135  Init(-1,-1,-1,-1,TVector2(x,y),TVector2(dx,dy),charge);
136 }
137 
138 //_____________________________________________________________________________
139 AliMUONPad::AliMUONPad(const TVector2& position, const TVector2& dimensions,
140  Double_t charge)
141 : TObject(),
142 fIsSaturated(kFALSE),
143 fIsReal(kFALSE),
144 fClusterId(-1),
145 fCathode(-1),
146 fDetElemId(-1),
147 fIx(-1),
148 fIy(-1),
149 fStatus(0),
150 fDimensions(),
151 fPosition(),
152 fCharge(0.0),
153 fChargeBackup(0.0)
154 {
156  Init(-1,-1,-1,-1,position,dimensions,charge);
157 }
158 
159 //_____________________________________________________________________________
161 {
163 }
164 
165 //_____________________________________________________________________________
166 Bool_t
168 {
170  if ( d1.DetElemId() != d2.DetElemId() ||
171  d1.Cathode() != d2.Cathode() )
172  {
173  return kFALSE;
174  }
175  else
176  {
177  static Double_t precision = 1E-4; // cm
178  static TVector2 precisionAdjustment(-precision,-precision);
179  return AreOverlapping(d1,d2,precisionAdjustment);
180  }
181 }
182 
183 //_____________________________________________________________________________
184 Bool_t
186  const TVector2& precision)
187 {
201 
202  AliMpArea a1(d1.X(),d1.Y(),d1.DX(),d1.DY());
203  AliMpArea a2(d2.X(),d2.Y(),d2.DX(),d2.DY());
204 
205  if ( a1.LeftBorder() > a2.RightBorder() - precision.X() ||
206  a1.RightBorder() < a2.LeftBorder() + precision.X() )
207  {
208  return kFALSE;
209  }
210 
211  if ( a1.DownBorder() > a2.UpBorder() - precision.Y() ||
212  a1.UpBorder() < a2.DownBorder() + precision.Y() )
213  {
214  return kFALSE;
215  }
216  return kTRUE;
217 }
218 
219 //_____________________________________________________________________________
220 Bool_t
222  const TVector2& precision,
223  AliMpArea& overlapRegion)
224 {
232  if ( AreOverlapping(d1,d2,precision) )
233  {
234  overlapRegion = Overlap(d1,d2);
235  if ( !overlapRegion.IsValid() )
236  {
237  cerr << "Something is wrong : the 2 pads below are flagged as overlapping"
238  << ", but the overlapRegion is not valid"
239  << endl;
240  d1.Print("corners");
241  d2.Print("corners");
242  }
243  return kTRUE;
244  }
245  return kFALSE;
246 }
247 
248 //_____________________________________________________________________________
249 Int_t
250 AliMUONPad::Compare(const TObject* obj) const
251 {
254 
255  const AliMUONPad* pad = static_cast<const AliMUONPad*>(obj);
256 
257  if (DetElemId() < 0)
258  {
259  // AZ - For "pixels" from MLEM cluster finder
260  // we only sort on charge
261  if (Charge() == pad->Charge()) return 0;
262  return ( Charge() < pad->Charge() ) ? 1:-1;
263  }
264 
265  if ( DetElemId() > pad->DetElemId() )
266  {
267  return 1;
268  }
269  else if ( DetElemId() < pad->DetElemId() )
270  {
271  return -1;
272  }
273  else
274  {
275  // same DetElemId...
276  if ( Cathode() > pad->Cathode() )
277  {
278  return 1;
279  }
280  else if ( Cathode() < pad->Cathode() )
281  {
282  return -1;
283  }
284  else
285  {
286  // same cathode...
287  if ( Ix() > pad->Ix() )
288  {
289  return 1;
290  }
291  else if ( Ix() < pad->Ix() )
292  {
293  return -1;
294  }
295  else
296  {
297  // same ix....
298  if ( Iy() > pad->Iy() )
299  {
300  return 1;
301  }
302  else if ( Iy() < pad->Iy() )
303  {
304  return -1;
305  }
306  else
307  {
308  // same iy....
309  if ( X() > pad->X() )
310  {
311  return 1;
312  }
313  else if ( X() < pad->X() )
314  {
315  return -1;
316  }
317  else
318  {
319  // same X
320  if ( Y() > pad->Y() )
321  {
322  return 1;
323  }
324  else if ( Y() < pad->Y() )
325  {
326  return -1;
327  }
328  else
329  {
330  // same Y
331  if ( Charge() < pad->Charge() )
332  {
333  return -1;
334  }
335  else if ( Charge() > pad->Charge() )
336  {
337  return 1;
338  }
339  else
340  {
341  return 0;
342  }
343  }
344  }
345  }
346  }
347  }
348  }
349  return 0;
350 }
351 
352 //_____________________________________________________________________________
353 Double_t
354 AliMUONPad::Coord(Int_t ixy) const
355 {
358 
359  if ( ixy == 0 )
360  {
361  return X();
362  }
363  else if ( ixy == 1 )
364  {
365  return Y();
366  }
367  AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
368  return 0;
369 }
370 
371 //_____________________________________________________________________________
372 void
373 AliMUONPad::Init(Int_t detElemId, Int_t cathode,
374  Int_t ix, Int_t iy,
375  const TVector2& position,
376  const TVector2& dimensions,
377  Double_t charge)
378 {
380  fIsSaturated = kFALSE;
381  fIsReal = kTRUE;
382  fDetElemId = detElemId;
383  fCathode = cathode;
384  fIx = ix;
385  fIy = iy;
386  fPosition = position;
387  fDimensions = dimensions;
388  fCharge = charge;
390 
391  fClusterId = -1;
392 
393  fStatus = 0;
394 }
395 
396 //_____________________________________________________________________________
397 AliMpArea
399 {
401  AliMpArea a1(d1.X(),d1.Y(),d1.DX(),d1.DY());
402  AliMpArea a2(d2.X(),d2.Y(),d2.DX(),d2.DY());
403  return Intersect(a1,a2);
404 }
405 
406 
407 //_____________________________________________________________________________
408 void
410 {
412  TVector2 ll = Position() - Dimensions();
413  TVector2 ur = Position() + Dimensions();
414 
415  gPad->PaintBox(ll.X(),ll.Y(),ur.X(),ur.Y());
416 }
417 
418 //_____________________________________________________________________________
419 void
420 AliMUONPad::Print(Option_t* opt) const
421 {
423  TString sopt(opt);
424  sopt.ToLower();
425 
426  ios_base::fmtflags oldflags = cout.flags();
427  if ( Cathode() >= 0 )
428  {
429  cout << "DetEle " << setw(5) << DetElemId()
430  << " Cath " << setw(2) << Cathode()
431  << " (Ix,Iy)=(" << setw(3) << Ix() << "," << setw(3) << Iy() << ") ";
432  }
433  cout.setf(ios::fixed);
434  cout.precision(6);
435  cout << " (x,y)=(" << setw(9) << X() << "," << setw(9) << Y() << ") "
436  << " (dx,dy)=(" << setw(9) << DX() << "," << setw(9) << DY() << ") "
437  << " Charge=";
438  cout.precision(2);
439  cout << setw(7) << Charge();
440  if ( sopt.Contains("full") )
441  {
442  cout
443  << " Used=" << (IsUsed()?Form("YES (ClusterId %d)",fClusterId):"NO")
444  << (IsSaturated()?"(S)":" ")
445  << (IsReal()?" ":"(V)")
446  << " Status=" << setw(4) << Status()
447  << " ChargeBackup=" << ChargeBackup();
448  }
449  if ( sopt.Contains("corners") )
450  {
451  cout << Form(" (xmin,xmax)=(%e,%e) (ymin,ymax)=(%e,%e)",
452  X()-DX(),X()+DX(),
453  Y()-DY(),Y()+DY()) << endl;
454  }
455  cout << endl;
456  cout.precision(6); // reset to default precision
457  cout.flags(oldflags);
458 }
459 
460 //_____________________________________________________________________________
461 void
462 AliMUONPad::SetCoord(Int_t ixy, Double_t coord)
463 {
465  if ( ixy == 0 )
466  {
467  fPosition.Set(coord,Y());
468  }
469  else if ( ixy == 1 )
470  {
471  fPosition.Set(X(),coord);
472  }
473  else
474  {
475  AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
476  }
477 }
478 
479 //_____________________________________________________________________________
480 void
481 AliMUONPad::SetSize(Int_t ixy, Double_t size)
482 {
484  if ( ixy == 0 )
485  {
486  fDimensions.Set(size,DY());
487  }
488  else if ( ixy == 1 )
489  {
490  fDimensions.Set(DX(),size);
491  }
492  else
493  {
494  AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
495  }
496 }
497 
498 //_____________________________________________________________________________
499 void
500 AliMUONPad::Shift(Int_t ixy, Double_t shift)
501 {
503  SetCoord(ixy,Coord(ixy)+shift);
504 }
505 
506 //_____________________________________________________________________________
507 Double_t
508 AliMUONPad::Size(Int_t ixy) const
509 {
512 
513  if ( ixy == 0 )
514  {
515  return DX();
516  }
517  else if ( ixy == 1 )
518  {
519  return DY();
520  }
521  AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
522  return 0;
523 }
static Bool_t AreOverlapping(const AliMUONPad &d1, const AliMUONPad &d2, const TVector2 &precision, AliMpArea &overlapArea)
Definition: AliMUONPad.cxx:221
static AliMpArea Overlap(const AliMUONPad &d1, const AliMUONPad &d2)
Definition: AliMUONPad.cxx:398
Bool_t IsReal() const
Return info whether this is a real pad or a virtual one.
Definition: AliMUONPad.h:64
Bool_t IsSaturated() const
Return info whether this pad is saturated or not.
Definition: AliMUONPad.h:67
Double_t LeftBorder() const
Definition: AliMpArea.cxx:124
Double_t ChargeBackup() const
Return backup charge.
Definition: AliMUONPad.h:50
TVector2 Dimensions() const
Return half dimensions in x and y (cm)
Definition: AliMUONPad.h:56
A rectangle area positioned in plane..
Definition: AliMpArea.h:20
Int_t fIy
y-index
Definition: AliMUONPad.h:156
Bool_t fIsSaturated
whether this pad is saturated or not
Definition: AliMUONPad.h:150
virtual Int_t Compare(const TObject *obj) const
Definition: AliMUONPad.cxx:250
Double_t DY() const
Return half dimensions in y (cm)
Definition: AliMUONPad.h:61
static Bool_t AreNeighbours(const AliMUONPad &d1, const AliMUONPad &d2)
Definition: AliMUONPad.cxx:167
void Shift(Int_t ixy, Double_t shift)
Definition: AliMUONPad.cxx:500
void SetSize(Int_t ixy, Double_t Size)
Definition: AliMUONPad.cxx:481
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Double_t Y() const
Return position in y (cm)
Definition: AliMUONPad.h:128
TVector2 fDimensions
half dimensions in x and y (cm)
Definition: AliMUONPad.h:158
Int_t fIx
x-index
Definition: AliMUONPad.h:155
Bool_t fIsReal
whether this is a real pad or a virtual one
Definition: AliMUONPad.h:151
virtual ~AliMUONPad()
Definition: AliMUONPad.cxx:160
Int_t Iy() const
Return y-index.
Definition: AliMUONPad.h:80
virtual void Paint(Option_t *opt="")
Definition: AliMUONPad.cxx:409
Double_t X() const
Return position in x (cm)
Definition: AliMUONPad.h:126
TVector2 fPosition
positions in x and y (cm)
Definition: AliMUONPad.h:159
Int_t Cathode() const
Return cathode number.
Definition: AliMUONPad.h:43
Double_t UpBorder() const
Definition: AliMpArea.cxx:140
Bool_t IsUsed() const
Return true if is used.
Definition: AliMUONPad.h:75
Double_t Size(Int_t ixy) const
Definition: AliMUONPad.cxx:508
Double_t DownBorder() const
Definition: AliMpArea.cxx:148
TVector2 Position() const
Return positions in x and y (cm)
Definition: AliMUONPad.h:85
Double_t fCharge
pad charge
Definition: AliMUONPad.h:160
Int_t fStatus
status word
Definition: AliMUONPad.h:157
void SetCoord(Int_t ixy, Double_t Coord)
Definition: AliMUONPad.cxx:462
Int_t Ix() const
Return x-index.
Definition: AliMUONPad.h:78
Int_t fDetElemId
detection element id
Definition: AliMUONPad.h:154
Bool_t IsValid() const
Return validity.
Definition: AliMpArea.h:83
void Print(Option_t *opt="") const
Definition: AliMUONPad.cxx:420
Double_t Charge() const
Return pad charge.
Definition: AliMUONPad.h:48
Double_t Coord(Int_t ixy) const
Definition: AliMUONPad.cxx:354
Int_t fClusterId
cluster id this pad belongs to (-1 if not attached to a cluster)
Definition: AliMUONPad.h:152
Int_t DetElemId() const
Return detection element id.
Definition: AliMUONPad.h:53
void Init(Int_t detElemId, Int_t cathode, Int_t ix, Int_t iy, const TVector2 &position, const TVector2 &dimensions, Double_t charge)
Definition: AliMUONPad.cxx:373
Int_t fCathode
cathode number
Definition: AliMUONPad.h:153
Int_t Status() const
Return status word.
Definition: AliMUONPad.h:123
Double_t fChargeBackup
backup charge (usefull if clustering somehow plays with the charge, this one is the "original" one) ...
Definition: AliMUONPad.h:161
Double_t RightBorder() const
Definition: AliMpArea.cxx:132
Combination of digit and mppad informations.
Definition: AliMUONPad.h:25
Double_t DX() const
Return half dimensions in x (cm)
Definition: AliMUONPad.h:59