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 "AliMUONPad.h"
21 #include "AliMpArea.h"
23 #include "Riostream.h"
24 #include "TVirtualPad.h"
25 #include "TVirtualX.h"
31 /// Object gathering information about a hit pad.
33 /// Can be seen as a combination of a Digit (which brings the charge)
34 /// and an MpPad (which brings location and position)
36 /// Also provided are some static functions to compute overlap and
37 /// get neighboring information.
39 /// \author Laurent Aphecetche
48 Intersect(const AliMpArea& a, const AliMpArea& b)
51 // Returns the common part of a and b.
53 Double_t xmin = TMath::Max(a.LeftBorder(),b.LeftBorder());
54 Double_t xmax = TMath::Min(a.RightBorder(),b.RightBorder());
55 Double_t ymin = TMath::Max(a.DownBorder(),b.DownBorder());
56 Double_t ymax = TMath::Min(a.UpBorder(),b.UpBorder());
57 AliMpArea c( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
58 TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
64 //_____________________________________________________________________________
65 AliMUONPad::AliMUONPad()
83 Init(-1,-1,-1,-1,TVector2(0,0),TVector2(0,0),0);
86 //_____________________________________________________________________________
87 AliMUONPad::AliMUONPad(Int_t detElemId, Int_t cathode,
88 Int_t ix, Int_t iy, Double_t x, Double_t y,
89 Double_t dx, Double_t dy, Double_t charge)
107 /// Normal ctor, using full information
108 Init(detElemId,cathode,ix,iy,TVector2(x,y),TVector2(dx,dy),charge);
111 //_____________________________________________________________________________
112 AliMUONPad::AliMUONPad(Double_t x, Double_t y,
113 Double_t dx, Double_t dy, Double_t charge)
115 fIsSaturated(kFALSE),
129 /// Truncated constructor (w/o DE, cath, ix, iy)
130 Init(-1,-1,-1,-1,TVector2(x,y),TVector2(dx,dy),charge);
133 //_____________________________________________________________________________
134 AliMUONPad::AliMUONPad(const TVector2& position, const TVector2& dimensions,
137 fIsSaturated(kFALSE),
152 Init(-1,-1,-1,-1,position,dimensions,charge);
155 //_____________________________________________________________________________
156 AliMUONPad::~AliMUONPad()
161 //_____________________________________________________________________________
163 AliMUONPad::AreNeighbours(const AliMUONPad& d1, const AliMUONPad& d2)
165 /// Whether 2 pads are neighbours or not
166 if ( d1.DetElemId() != d2.DetElemId() ||
167 d1.Cathode() != d2.Cathode() )
173 static Double_t precision = 1E-4; // cm
174 static TVector2 precisionAdjustment(-precision,-precision);
175 return AreOverlapping(d1,d2,precisionAdjustment);
179 //_____________________________________________________________________________
181 AliMUONPad::AreOverlapping(const AliMUONPad& d1, const AliMUONPad& d2,
182 const TVector2& precision)
184 /// Checks the overlap between 2 pads.
185 /// The actual overlap is computed not on d1 and d2, but on d1 and d2
186 /// "re-scaled" using the precision vector (conceptually equivalent to
187 /// d.Dimensions() += precision)
189 /// So, if the elements (x,y) of precision are :
191 /// - positive, the overlap is "computed" from smaller d1 and d2
192 /// which is, modulo the precision, what you would think as a normal
193 /// overlap calculation
194 /// - negative, overlap is from "bigger" d1 and d2, which is usefull to "tweek"
195 /// what we call an overlap, e.g. to consider 2 pads touching only by their
196 /// corners to be overlapping.
198 AliMpArea a1(d1.Position(),d1.Dimensions());
199 AliMpArea a2(d2.Position(),d2.Dimensions());
201 if ( a1.LeftBorder() > a2.RightBorder() - precision.X() ||
202 a1.RightBorder() < a2.LeftBorder() + precision.X() )
207 if ( a1.DownBorder() > a2.UpBorder() - precision.Y() ||
208 a1.UpBorder() < a2.DownBorder() + precision.Y() )
215 //_____________________________________________________________________________
217 AliMUONPad::AreOverlapping(const AliMUONPad& d1, const AliMUONPad& d2,
218 const TVector2& precision,
219 AliMpArea& overlapRegion)
221 /// Checks the overlap between 2 pads, and returns the overlap area
223 /// See comments on the other AreOverlapping method, too : in this
224 /// method, the overlapRegion does *not* depend on the precision parameter,
225 /// which is only used to decide whether the pads are overlapping, while
226 /// the actual overlap region is computed w/o reference to precision.
228 if ( AreOverlapping(d1,d2,precision) )
230 overlapRegion = Overlap(d1,d2);
231 if ( !overlapRegion.IsValid() )
233 cerr << "Something is wrong : the 2 pads below are flagged as overlapping"
234 << ", but the overlapRegion is not valid"
244 //_____________________________________________________________________________
246 AliMUONPad::Compare(const TObject* obj) const
249 /// Ordering is as complete as possible.
251 const AliMUONPad* pad = static_cast<const AliMUONPad*>(obj);
253 if (DetElemId() < 0) {
254 // AZ - For "pixels" from MLEM cluster finder
255 if (Charge() == pad->Charge()) return 0;
256 return ( Charge() < pad->Charge() ) ? 1:-1;
259 if ( DetElemId() > pad->DetElemId() )
263 else if ( DetElemId() > pad->DetElemId() )
270 if ( Cathode() > pad->Cathode() )
274 else if ( Cathode() < pad->Cathode() )
281 if ( Ix() > pad->Ix() )
285 else if ( Ix() < pad->Ix() )
292 if ( Iy() > pad->Iy() )
296 else if ( Iy() < pad->Iy() )
303 if ( X() > pad->X() )
307 else if ( X() < pad->X() )
314 if ( Y() > pad->Y() )
318 else if ( Y() < pad->Y() )
325 return ( Charge() < pad->Charge() ) ? -1:1;
334 //_____________________________________________________________________________
336 AliMUONPad::Coord(Int_t ixy) const
338 /// To be friendly and backward compatible with AZ code, which
339 /// used that kind of coordinate accessing.
349 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
353 //_____________________________________________________________________________
355 AliMUONPad::Init(Int_t detElemId, Int_t cathode,
357 const TVector2& position,
358 const TVector2& dimensions,
361 /// Called by all the ctors
362 fIsSaturated = kFALSE;
364 fDetElemId = detElemId;
368 fPosition = position;
369 fDimensions = dimensions;
371 fChargeBackup = fCharge;
379 //_____________________________________________________________________________
381 AliMUONPad::Overlap(const AliMUONPad& d1, const AliMUONPad& d2)
383 /// Return the overlap region between two pads
384 AliMpArea a1(d1.Position(),d1.Dimensions());
385 AliMpArea a2(d2.Position(),d2.Dimensions());
386 return Intersect(a1,a2);
390 //_____________________________________________________________________________
392 AliMUONPad::Paint(Option_t*)
394 /// Paint pad on screen
395 TVector2 ll = Position() - Dimensions();
396 TVector2 ur = Position() + Dimensions();
398 gPad->PaintBox(ll.X(),ll.Y(),ur.X(),ur.Y());
401 //_____________________________________________________________________________
403 AliMUONPad::Print(Option_t* opt) const
409 ios_base::fmtflags oldflags = cout.flags();
410 if ( Cathode() >= 0 )
412 cout << "DetEle " << setw(5) << DetElemId()
413 << " Cath " << setw(2) << Cathode()
414 << " (Ix,Iy)=(" << setw(3) << Ix() << "," << setw(3) << Iy() << ") ";
416 cout.setf(ios::fixed);
418 cout << " (x,y)=(" << setw(9) << X() << "," << setw(9) << Y() << ") "
419 << " (dx,dy)=(" << setw(9) << DX() << "," << setw(9) << DY() << ") "
422 cout << setw(7) << Charge();
423 if ( sopt.Contains("full") )
426 << " Used=" << (IsUsed()?Form("YES (ClusterId %d)",fClusterId):"NO")
427 << (IsSaturated()?"(S)":" ")
428 << (IsReal()?" ":"(V)")
429 << " Status=" << setw(4) << Status()
430 << " ChargeBackup=" << ChargeBackup();
432 if ( sopt.Contains("corners") )
434 cout << Form(" (xmin,xmax)=(%e,%e) (ymin,ymax)=(%e,%e)",
436 Y()-DY(),Y()+DY()) << endl;
439 cout.precision(6); // reset to default precision
440 cout.flags(oldflags);
443 //_____________________________________________________________________________
445 AliMUONPad::SetCoord(Int_t ixy, Double_t coord)
447 /// Set the pad coordinate (ixy=0 means x, ixy=1 means y)
450 fPosition.Set(coord,Y());
454 fPosition.Set(X(),coord);
458 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
462 //_____________________________________________________________________________
464 AliMUONPad::SetSize(Int_t ixy, Double_t size)
466 /// Set the pad half size (ixy=0 means x half size, ixy=1 means y half size)
469 fDimensions.Set(size,DY());
473 fDimensions.Set(DX(),size);
477 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
481 //_____________________________________________________________________________
483 AliMUONPad::Shift(Int_t ixy, Double_t shift)
485 /// Shift the position by "shift"
486 SetCoord(ixy,Coord(ixy)+shift);
489 //_____________________________________________________________________________
491 AliMUONPad::Size(Int_t ixy) const
493 /// Returns the half size along a direction, given by ixy
494 /// (see SetSize for ixy meaning)
504 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));