Ignore:
Timestamp:
04/06/04 13:41:56 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mgeom
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.cc

    r3547 r3666  
    5353
    5454#include <TClass.h>     // IsA()->New()
     55#include <TVector2.h>   // TVector2
    5556
    5657#include "MLog.h"
     
    9293
    9394    for (UInt_t i=0; i<npix; i++)
    94       fPixels[i] = new MGeomPix;
     95        fPixels[i] = new MGeomPix;
    9596
    9697    SetReadyToSave();
     
    195196void MGeomCam::CalcMaxRadius()
    196197{
    197 
    198   fMaxRadius.Set(fNumAreas+1);
    199   fMinRadius.Set(fNumAreas+1); 
    200 
    201   for (Int_t i=0; i<fNumAreas+1; i++)
    202     {
    203       fMaxRadius[i] = 0.;
    204       fMinRadius[i] = FLT_MAX;
    205     }
    206  
    207   for (UInt_t i=0; i<fNumPixels; i++)
    208     {
    209 
    210       const MGeomPix &pix = (*this)[i];
    211 
    212       const UInt_t  s = pix.GetAidx();     
    213       const Float_t x = pix.GetX();
    214       const Float_t y = pix.GetY();
    215       const Float_t d = pix.GetD();
    216 
    217       const Float_t r = TMath::Hypot(x, y);
    218 
    219       const Float_t maxr = r + d;
    220       const Float_t minr = r>d ? r-d : 0;
    221      
    222       if (maxr>fMaxRadius[s+1])
    223         fMaxRadius[s+1] = maxr;
    224 
    225       if (minr<fMinRadius[s+1])
    226         fMinRadius[s+1] = minr;
    227 
    228       if (minr<fMinRadius[0])
    229         fMinRadius[0] = minr;
    230 
    231       if (maxr>fMaxRadius[0])
    232         fMaxRadius[0] = maxr;
    233 
    234     }
    235 }
    236 
     198    fMaxRadius.Set(fNumAreas+1);
     199    fMinRadius.Set(fNumAreas+1);
     200
     201    for (Int_t i=0; i<fNumAreas+1; i++)
     202    {
     203        fMaxRadius[i] = 0.;
     204        fMinRadius[i] = FLT_MAX;
     205    }
     206
     207    for (UInt_t i=0; i<fNumPixels; i++)
     208    {
     209        const MGeomPix &pix = (*this)[i];
     210
     211        const UInt_t  s = pix.GetAidx();
     212        const Float_t x = pix.GetX();
     213        const Float_t y = pix.GetY();
     214        const Float_t d = pix.GetD();
     215
     216        const Float_t r = TMath::Hypot(x, y);
     217
     218        const Float_t maxr = r + d;
     219        const Float_t minr = r>d ? r-d : 0;
     220
     221        if (maxr>fMaxRadius[s+1])
     222            fMaxRadius[s+1] = maxr;
     223
     224        if (minr<fMinRadius[s+1])
     225            fMinRadius[s+1] = minr;
     226
     227        if (minr<fMinRadius[0])
     228            fMinRadius[0] = minr;
     229
     230        if (maxr>fMaxRadius[0])
     231            fMaxRadius[0] = maxr;
     232    }
     233}
     234
     235// --------------------------------------------------------------------------
    237236//
    238237// Have to call the radii of the subcameras starting to count from 1
     
    240239Float_t MGeomCam::GetMaxRadius(const Int_t i) const
    241240{
    242   if (i==-1) return fMaxRadius[0];
    243   return i>fNumAreas ? -1 : fMaxRadius[i+1];
    244 }
    245 
     241    return i<-1 || i>fNumAreas ? -1 : fMaxRadius[i+1];
     242}
     243
     244// --------------------------------------------------------------------------
    246245//
    247246// Have to call the radii of the subcameras starting to count from 1
     
    249248Float_t MGeomCam::GetMinRadius(const Int_t i) const
    250249{
    251   if (i==-1) return fMinRadius[0];
    252   return i>fNumAreas ? -1 : fMinRadius[i+1];
     250    return i<-1 || i>fNumAreas ? -1 : fMinRadius[i+1];
    253251}
    254252
     
    302300    return (TObject*)IsA()->New();
    303301}
     302
     303// --------------------------------------------------------------------------
     304//
     305//  Return the pixel index corresponding to the coordinates given in x, y.
     306//  The coordinates are given in pixel units (millimeters)
     307//  If no pixel exists return -1;
     308//
     309Int_t MGeomCam::GetPixelIdxXY(Float_t x, Float_t y) const
     310{
     311    for (unsigned int i=0; i<fNumPixels; i++)
     312        if ((*this)[i].IsInside(x, y))
     313            return i;
     314
     315    return -1;
     316}
     317
     318Int_t MGeomCam::GetPixelIdx(const TVector2 &v) const
     319{
     320    return GetPixelIdxXY(v.X(), v.Y());
     321}
     322
     323Int_t MGeomCam::GetPixelIdxDeg(const TVector2 &v) const
     324{
     325    return GetPixelIdxXYdeg(v.X(), v.Y());
     326}
     327
    304328/*
    305329void MGeomCam::Streamer(TBuffer &R__b)
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.h

    r3547 r3666  
    1212#endif
    1313
     14class TVector2;
    1415class MGeomPix;
    1516
     
    7374
    7475    MGeomPix &operator[](Int_t i);
    75     MGeomPix &operator[](Int_t i)          const;
     76    MGeomPix &operator[](Int_t i) const;
     77
     78    Int_t GetPixelIdx(const TVector2 &v) const;
     79    Int_t GetPixelIdxDeg(const TVector2 &v) const;
     80    Int_t GetPixelIdxXY(Float_t x, Float_t y) const;
     81    Int_t GetPixelIdxXYdeg(Float_t x, Float_t y) const
     82    {
     83        return GetPixelIdxXY(x/fConvMm2Deg, y/fConvMm2Deg);
     84    }
    7685
    7786    virtual void Print(Option_t *opt=NULL)   const;
  • trunk/MagicSoft/Mars/mgeom/MGeomPix.cc

    r3392 r3666  
    133133    *fLog << "d= " << fD << "mm  A= " << fA << "mm²" << endl;
    134134}
     135
     136// ------------------------------------------------------------------------
     137//
     138// compute the distance of a point (px,py) to the Hexagon center in
     139// MGeomPix coordinates. Return kTRUE if inside.
     140//
     141Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
     142{
     143    //
     144    //  compute the distance of the Point to the center of the Hexagon
     145    //
     146    const Double_t dx = px-fX;
     147
     148    //
     149    // Now check if point is outside of hexagon; just check x coordinate
     150    // in three coordinate systems: the default one, in which two sides of
     151    // the hexagon are paralel to the y axis (see camera displays) and two
     152    // more, rotated with respect to that one by +- 60 degrees.
     153    //
     154    if (TMath::Abs(dx)*2>fD)
     155        return kFALSE;
     156
     157    const Double_t dy = py-fY;
     158
     159    const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
     160    const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
     161
     162    const Double_t dx2 = dx*cos60 + dy*sin60;
     163    if  (TMath::Abs(dx2)*2>fD)
     164        return kFALSE;
     165
     166    const Double_t dx3 = dx*cos60 - dy*sin60;
     167    if (TMath::Abs(dx3)*2>fD)
     168        return kFALSE;
     169
     170    return kTRUE;
     171}
  • trunk/MagicSoft/Mars/mgeom/MGeomPix.h

    r3392 r3666  
    5656    Bool_t IsInOuterRing() const     { return TestBit(kIsInOuterRing); }
    5757
     58    Bool_t IsInside(Float_t px, Float_t py) const;
     59
    5860    /*
    5961     //
Note: See TracChangeset for help on using the changeset viewer.