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"
29 //-----------------------------------------------------------------------------
32 /// Object gathering information about a hit pad.
34 /// Can be seen as a combination of a Digit (which brings the charge)
35 /// and an MpPad (which brings location and position)
37 /// Also provided are some static functions to compute overlap and
38 /// get neighboring information.
40 /// \author Laurent Aphecetche
41 //-----------------------------------------------------------------------------
56 Intersect(const AliMpArea& a, const AliMpArea& b)
59 // Returns the common part of a and b.
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 );
72 //_____________________________________________________________________________
73 AliMUONPad::AliMUONPad()
90 Init(-1,-1,-1,-1,TVector2(0,0),TVector2(0,0),0);
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)
113 /// Normal ctor, using full information
114 Init(detElemId,cathode,ix,iy,TVector2(x,y),TVector2(dx,dy),charge);
117 //_____________________________________________________________________________
118 AliMUONPad::AliMUONPad(Double_t x, Double_t y,
119 Double_t dx, Double_t dy, Double_t charge)
121 fIsSaturated(kFALSE),
134 /// Truncated constructor (w/o DE, cath, ix, iy)
135 Init(-1,-1,-1,-1,TVector2(x,y),TVector2(dx,dy),charge);
138 //_____________________________________________________________________________
139 AliMUONPad::AliMUONPad(const TVector2& position, const TVector2& dimensions,
142 fIsSaturated(kFALSE),
156 Init(-1,-1,-1,-1,position,dimensions,charge);
159 //_____________________________________________________________________________
160 AliMUONPad::~AliMUONPad()
165 //_____________________________________________________________________________
167 AliMUONPad::AreNeighbours(const AliMUONPad& d1, const AliMUONPad& d2)
169 /// Whether 2 pads are neighbours or not
170 if ( d1.DetElemId() != d2.DetElemId() ||
171 d1.Cathode() != d2.Cathode() )
177 static Double_t precision = 1E-4; // cm
178 static TVector2 precisionAdjustment(-precision,-precision);
179 return AreOverlapping(d1,d2,precisionAdjustment);
183 //_____________________________________________________________________________
185 AliMUONPad::AreOverlapping(const AliMUONPad& d1, const AliMUONPad& d2,
186 const TVector2& precision)
188 /// Checks the overlap between 2 pads.
189 /// The actual overlap is computed not on d1 and d2, but on d1 and d2
190 /// "re-scaled" using the precision vector (conceptually equivalent to
191 /// d.Dimensions() += precision)
193 /// So, if the elements (x,y) of precision are :
195 /// - positive, the overlap is "computed" from smaller d1 and d2
196 /// which is, modulo the precision, what you would think as a normal
197 /// overlap calculation
198 /// - negative, overlap is from "bigger" d1 and d2, which is usefull to "tweek"
199 /// what we call an overlap, e.g. to consider 2 pads touching only by their
200 /// corners to be overlapping.
202 AliMpArea a1(d1.X(),d1.Y(),d1.DX(),d1.DY());
203 AliMpArea a2(d2.X(),d2.Y(),d2.DX(),d2.DY());
205 if ( a1.LeftBorder() > a2.RightBorder() - precision.X() ||
206 a1.RightBorder() < a2.LeftBorder() + precision.X() )
211 if ( a1.DownBorder() > a2.UpBorder() - precision.Y() ||
212 a1.UpBorder() < a2.DownBorder() + precision.Y() )
219 //_____________________________________________________________________________
221 AliMUONPad::AreOverlapping(const AliMUONPad& d1, const AliMUONPad& d2,
222 const TVector2& precision,
223 AliMpArea& overlapRegion)
225 /// Checks the overlap between 2 pads, and returns the overlap area
227 /// See comments on the other AreOverlapping method, too : in this
228 /// method, the overlapRegion does *not* depend on the precision parameter,
229 /// which is only used to decide whether the pads are overlapping, while
230 /// the actual overlap region is computed w/o reference to precision.
232 if ( AreOverlapping(d1,d2,precision) )
234 overlapRegion = Overlap(d1,d2);
235 if ( !overlapRegion.IsValid() )
237 cerr << "Something is wrong : the 2 pads below are flagged as overlapping"
238 << ", but the overlapRegion is not valid"
248 //_____________________________________________________________________________
250 AliMUONPad::Compare(const TObject* obj) const
253 /// Ordering is as complete as possible.
255 const AliMUONPad* pad = static_cast<const AliMUONPad*>(obj);
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;
265 if ( DetElemId() > pad->DetElemId() )
269 else if ( DetElemId() < pad->DetElemId() )
276 if ( Cathode() > pad->Cathode() )
280 else if ( Cathode() < pad->Cathode() )
287 if ( Ix() > pad->Ix() )
291 else if ( Ix() < pad->Ix() )
298 if ( Iy() > pad->Iy() )
302 else if ( Iy() < pad->Iy() )
309 if ( X() > pad->X() )
313 else if ( X() < pad->X() )
320 if ( Y() > pad->Y() )
324 else if ( Y() < pad->Y() )
331 if ( Charge() < pad->Charge() )
335 else if ( Charge() > pad->Charge() )
352 //_____________________________________________________________________________
354 AliMUONPad::Coord(Int_t ixy) const
356 /// To be friendly and backward compatible with AZ code, which
357 /// used that kind of coordinate accessing.
367 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
371 //_____________________________________________________________________________
373 AliMUONPad::Init(Int_t detElemId, Int_t cathode,
375 const TVector2& position,
376 const TVector2& dimensions,
379 /// Called by all the ctors
380 fIsSaturated = kFALSE;
382 fDetElemId = detElemId;
386 fPosition = position;
387 fDimensions = dimensions;
389 fChargeBackup = fCharge;
396 //_____________________________________________________________________________
398 AliMUONPad::Overlap(const AliMUONPad& d1, const AliMUONPad& d2)
400 /// Return the overlap region between two pads
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);
407 //_____________________________________________________________________________
409 AliMUONPad::Paint(Option_t*)
411 /// Paint pad on screen
412 TVector2 ll = Position() - Dimensions();
413 TVector2 ur = Position() + Dimensions();
415 gPad->PaintBox(ll.X(),ll.Y(),ur.X(),ur.Y());
418 //_____________________________________________________________________________
420 AliMUONPad::Print(Option_t* opt) const
426 ios_base::fmtflags oldflags = cout.flags();
427 if ( Cathode() >= 0 )
429 cout << "DetEle " << setw(5) << DetElemId()
430 << " Cath " << setw(2) << Cathode()
431 << " (Ix,Iy)=(" << setw(3) << Ix() << "," << setw(3) << Iy() << ") ";
433 cout.setf(ios::fixed);
435 cout << " (x,y)=(" << setw(9) << X() << "," << setw(9) << Y() << ") "
436 << " (dx,dy)=(" << setw(9) << DX() << "," << setw(9) << DY() << ") "
439 cout << setw(7) << Charge();
440 if ( sopt.Contains("full") )
443 << " Used=" << (IsUsed()?Form("YES (ClusterId %d)",fClusterId):"NO")
444 << (IsSaturated()?"(S)":" ")
445 << (IsReal()?" ":"(V)")
446 << " Status=" << setw(4) << Status()
447 << " ChargeBackup=" << ChargeBackup();
449 if ( sopt.Contains("corners") )
451 cout << Form(" (xmin,xmax)=(%e,%e) (ymin,ymax)=(%e,%e)",
453 Y()-DY(),Y()+DY()) << endl;
456 cout.precision(6); // reset to default precision
457 cout.flags(oldflags);
460 //_____________________________________________________________________________
462 AliMUONPad::SetCoord(Int_t ixy, Double_t coord)
464 /// Set the pad coordinate (ixy=0 means x, ixy=1 means y)
467 fPosition.Set(coord,Y());
471 fPosition.Set(X(),coord);
475 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
479 //_____________________________________________________________________________
481 AliMUONPad::SetSize(Int_t ixy, Double_t size)
483 /// Set the pad half size (ixy=0 means x half size, ixy=1 means y half size)
486 fDimensions.Set(size,DY());
490 fDimensions.Set(DX(),size);
494 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
498 //_____________________________________________________________________________
500 AliMUONPad::Shift(Int_t ixy, Double_t shift)
502 /// Shift the position by "shift"
503 SetCoord(ixy,Coord(ixy)+shift);
506 //_____________________________________________________________________________
508 AliMUONPad::Size(Int_t ixy) const
510 /// Returns the half size along a direction, given by ixy
511 /// (see SetSize for ixy meaning)
521 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));