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 //-----------------------------------------------------------------------------
50 Intersect(const AliMpArea& a, const AliMpArea& b)
53 // Returns the common part of a and b.
55 Double_t xmin = TMath::Max(a.LeftBorder(),b.LeftBorder());
56 Double_t xmax = TMath::Min(a.RightBorder(),b.RightBorder());
57 Double_t ymin = TMath::Max(a.DownBorder(),b.DownBorder());
58 Double_t ymax = TMath::Min(a.UpBorder(),b.UpBorder());
59 AliMpArea c( TVector2( (xmin+xmax)/2.0, (ymin+ymax)/2.0 ),
60 TVector2( (xmax-xmin)/2.0, (ymax-ymin)/2.0 ) );
66 //_____________________________________________________________________________
67 AliMUONPad::AliMUONPad()
85 Init(-1,-1,-1,-1,TVector2(0,0),TVector2(0,0),0);
88 //_____________________________________________________________________________
89 AliMUONPad::AliMUONPad(Int_t detElemId, Int_t cathode,
90 Int_t ix, Int_t iy, Double_t x, Double_t y,
91 Double_t dx, Double_t dy, Double_t charge)
109 /// Normal ctor, using full information
110 Init(detElemId,cathode,ix,iy,TVector2(x,y),TVector2(dx,dy),charge);
113 //_____________________________________________________________________________
114 AliMUONPad::AliMUONPad(Double_t x, Double_t y,
115 Double_t dx, Double_t dy, Double_t charge)
117 fIsSaturated(kFALSE),
131 /// Truncated constructor (w/o DE, cath, ix, iy)
132 Init(-1,-1,-1,-1,TVector2(x,y),TVector2(dx,dy),charge);
135 //_____________________________________________________________________________
136 AliMUONPad::AliMUONPad(const TVector2& position, const TVector2& dimensions,
139 fIsSaturated(kFALSE),
154 Init(-1,-1,-1,-1,position,dimensions,charge);
157 //_____________________________________________________________________________
158 AliMUONPad::~AliMUONPad()
163 //_____________________________________________________________________________
165 AliMUONPad::AreNeighbours(const AliMUONPad& d1, const AliMUONPad& d2)
167 /// Whether 2 pads are neighbours or not
168 if ( d1.DetElemId() != d2.DetElemId() ||
169 d1.Cathode() != d2.Cathode() )
175 static Double_t precision = 1E-4; // cm
176 static TVector2 precisionAdjustment(-precision,-precision);
177 return AreOverlapping(d1,d2,precisionAdjustment);
181 //_____________________________________________________________________________
183 AliMUONPad::AreOverlapping(const AliMUONPad& d1, const AliMUONPad& d2,
184 const TVector2& precision)
186 /// Checks the overlap between 2 pads.
187 /// The actual overlap is computed not on d1 and d2, but on d1 and d2
188 /// "re-scaled" using the precision vector (conceptually equivalent to
189 /// d.Dimensions() += precision)
191 /// So, if the elements (x,y) of precision are :
193 /// - positive, the overlap is "computed" from smaller d1 and d2
194 /// which is, modulo the precision, what you would think as a normal
195 /// overlap calculation
196 /// - negative, overlap is from "bigger" d1 and d2, which is usefull to "tweek"
197 /// what we call an overlap, e.g. to consider 2 pads touching only by their
198 /// corners to be overlapping.
200 AliMpArea a1(d1.Position(),d1.Dimensions());
201 AliMpArea a2(d2.Position(),d2.Dimensions());
203 if ( a1.LeftBorder() > a2.RightBorder() - precision.X() ||
204 a1.RightBorder() < a2.LeftBorder() + precision.X() )
209 if ( a1.DownBorder() > a2.UpBorder() - precision.Y() ||
210 a1.UpBorder() < a2.DownBorder() + precision.Y() )
217 //_____________________________________________________________________________
219 AliMUONPad::AreOverlapping(const AliMUONPad& d1, const AliMUONPad& d2,
220 const TVector2& precision,
221 AliMpArea& overlapRegion)
223 /// Checks the overlap between 2 pads, and returns the overlap area
225 /// See comments on the other AreOverlapping method, too : in this
226 /// method, the overlapRegion does *not* depend on the precision parameter,
227 /// which is only used to decide whether the pads are overlapping, while
228 /// the actual overlap region is computed w/o reference to precision.
230 if ( AreOverlapping(d1,d2,precision) )
232 overlapRegion = Overlap(d1,d2);
233 if ( !overlapRegion.IsValid() )
235 cerr << "Something is wrong : the 2 pads below are flagged as overlapping"
236 << ", but the overlapRegion is not valid"
246 //_____________________________________________________________________________
248 AliMUONPad::Compare(const TObject* obj) const
251 /// Ordering is as complete as possible.
253 const AliMUONPad* pad = static_cast<const AliMUONPad*>(obj);
257 // AZ - For "pixels" from MLEM cluster finder
258 // we only sort on charge
259 if (Charge() == pad->Charge()) return 0;
260 return ( Charge() < pad->Charge() ) ? 1:-1;
263 if ( DetElemId() > pad->DetElemId() )
267 else if ( DetElemId() < pad->DetElemId() )
274 if ( Cathode() > pad->Cathode() )
278 else if ( Cathode() < pad->Cathode() )
285 if ( Ix() > pad->Ix() )
289 else if ( Ix() < pad->Ix() )
296 if ( Iy() > pad->Iy() )
300 else if ( Iy() < pad->Iy() )
307 if ( X() > pad->X() )
311 else if ( X() < pad->X() )
318 if ( Y() > pad->Y() )
322 else if ( Y() < pad->Y() )
329 if ( Charge() < pad->Charge() )
333 else if ( Charge() > pad->Charge() )
350 //_____________________________________________________________________________
352 AliMUONPad::Coord(Int_t ixy) const
354 /// To be friendly and backward compatible with AZ code, which
355 /// used that kind of coordinate accessing.
365 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
369 //_____________________________________________________________________________
371 AliMUONPad::Init(Int_t detElemId, Int_t cathode,
373 const TVector2& position,
374 const TVector2& dimensions,
377 /// Called by all the ctors
378 fIsSaturated = kFALSE;
380 fDetElemId = detElemId;
384 fPosition = position;
385 fDimensions = dimensions;
387 fChargeBackup = fCharge;
395 //_____________________________________________________________________________
397 AliMUONPad::Overlap(const AliMUONPad& d1, const AliMUONPad& d2)
399 /// Return the overlap region between two pads
400 AliMpArea a1(d1.Position(),d1.Dimensions());
401 AliMpArea a2(d2.Position(),d2.Dimensions());
402 return Intersect(a1,a2);
406 //_____________________________________________________________________________
408 AliMUONPad::Paint(Option_t*)
410 /// Paint pad on screen
411 TVector2 ll = Position() - Dimensions();
412 TVector2 ur = Position() + Dimensions();
414 gPad->PaintBox(ll.X(),ll.Y(),ur.X(),ur.Y());
417 //_____________________________________________________________________________
419 AliMUONPad::Print(Option_t* opt) const
425 ios_base::fmtflags oldflags = cout.flags();
426 if ( Cathode() >= 0 )
428 cout << "DetEle " << setw(5) << DetElemId()
429 << " Cath " << setw(2) << Cathode()
430 << " (Ix,Iy)=(" << setw(3) << Ix() << "," << setw(3) << Iy() << ") ";
432 cout.setf(ios::fixed);
434 cout << " (x,y)=(" << setw(9) << X() << "," << setw(9) << Y() << ") "
435 << " (dx,dy)=(" << setw(9) << DX() << "," << setw(9) << DY() << ") "
438 cout << setw(7) << Charge();
439 if ( sopt.Contains("full") )
442 << " Used=" << (IsUsed()?Form("YES (ClusterId %d)",fClusterId):"NO")
443 << (IsSaturated()?"(S)":" ")
444 << (IsReal()?" ":"(V)")
445 << " Status=" << setw(4) << Status()
446 << " ChargeBackup=" << ChargeBackup();
448 if ( sopt.Contains("corners") )
450 cout << Form(" (xmin,xmax)=(%e,%e) (ymin,ymax)=(%e,%e)",
452 Y()-DY(),Y()+DY()) << endl;
455 cout.precision(6); // reset to default precision
456 cout.flags(oldflags);
459 //_____________________________________________________________________________
461 AliMUONPad::SetCoord(Int_t ixy, Double_t coord)
463 /// Set the pad coordinate (ixy=0 means x, ixy=1 means y)
466 fPosition.Set(coord,Y());
470 fPosition.Set(X(),coord);
474 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
478 //_____________________________________________________________________________
480 AliMUONPad::SetSize(Int_t ixy, Double_t size)
482 /// Set the pad half size (ixy=0 means x half size, ixy=1 means y half size)
485 fDimensions.Set(size,DY());
489 fDimensions.Set(DX(),size);
493 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));
497 //_____________________________________________________________________________
499 AliMUONPad::Shift(Int_t ixy, Double_t shift)
501 /// Shift the position by "shift"
502 SetCoord(ixy,Coord(ixy)+shift);
505 //_____________________________________________________________________________
507 AliMUONPad::Size(Int_t ixy) const
509 /// Returns the half size along a direction, given by ixy
510 /// (see SetSize for ixy meaning)
520 AliError(Form("Incorrect coordinates index %d (only 0,1 are valid)",ixy));