Ignore:
Timestamp:
03/01/09 21:54:27 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mgeom
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mgeom/GeomLinkDef.h

    r8920 r9369  
    55#pragma link off all functions;
    66
     7#pragma link C++ class MGeom+;
    78#pragma link C++ class MGeomPix+;
     9#pragma link C++ class MGeomRectangle+;
    810#pragma link C++ class MGeomCam-;
    911#pragma link C++ class MGeomPMT+;
     
    1618#pragma link C++ class MGeomCamDwarf+;
    1719#pragma link C++ class MGeomCamMagic+;
     20#pragma link C++ class MGeomCamSquare+;
    1821//#pragma link C++ class MGeomCamMagicHG+;
    1922//#pragma link C++ class MGeomCamMagic919+;
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.cc

    r9259 r9369  
    8585//
    8686MGeomCam::MGeomCam(UInt_t npix, Float_t dist, const char *name, const char *title)
    87     : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)),
    88     fPixels(npix), fMaxRadius(1), fMinRadius(1), fPixRatio(npix), fPixRatioSqrt(npix)
     87    : fNumPixels(npix), fCamDist(dist), fConvMm2Deg(kRad2Deg/(dist*1000)), fPixels(npix),
     88    fMaxRadius(1), fMinRadius(1), fPixRatio(npix), fPixRatioSqrt(npix)
    8989{
    9090    fName  = name  ? name  : "MGeomCam";
     
    9595    //
    9696    fPixels.SetOwner();
    97 
    98     // For root versions <5.18 AddAt is mandatory, for newer
    99     // root-version the []-operator can be used safely
    100     for (UInt_t i=0; i<npix; i++)
    101         fPixels.AddAt(new MGeomPix, i);
    10297}
    10398
     
    126121    Int_t m = c.fPixels.GetEntriesFast();
    127122
     123    c.fPixels.Delete();
    128124    c.fPixels.Expand(n);
    129125
    130126    for (int i=m; i<n; i++)
    131         c.fPixels.AddAt(new MGeomPix, i);
    132 
    133     for (int i=0; i<n; i++)
    134         fPixels[i]->Copy(c[i]);
     127        c.fPixels.AddAt(fPixels[i]->Clone(), i);
    135128}
    136129
     
    141134// entries may crash the program!
    142135//
    143 MGeomPix &MGeomCam::operator[](Int_t i)
    144 {
    145     return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
     136MGeom &MGeomCam::operator[](Int_t i)
     137{
     138    return *static_cast<MGeom*>(fPixels.UncheckedAt(i));
    146139}
    147140
     
    152145// entries may crash the program!
    153146//
    154 MGeomPix &MGeomCam::operator[](Int_t i) const
    155 {
    156     return *static_cast<MGeomPix*>(fPixels.UncheckedAt(i));
     147MGeom &MGeomCam::operator[](Int_t i) const
     148{
     149    return *static_cast<MGeom*>(fPixels.UncheckedAt(i));
    157150}
    158151
     
    240233    for (UInt_t i=0; i<fNumPixels; i++)
    241234    {
    242         const MGeomPix &pix = (*this)[i];
     235        const MGeom &pix = (*this)[i];
    243236
    244237        const UInt_t  s = pix.GetAidx();
     
    289282    for (unsigned int i=0; i<fNumPixels; i++)
    290283    {
    291         MGeomPix &gpix = (*this)[i];
     284        MGeom &gpix = (*this)[i];
    292285
    293286        Double_t phi[6];
     
    462455// The center pixel is also returned.
    463456//
    464 void MGeomCam::GetNeighbors(TArrayI &arr, const MGeomPix &pix, Float_t r) const
     457void MGeomCam::GetNeighbors(TArrayI &arr, const MGeom &pix, Float_t r) const
    465458{
    466459    arr.Set(GetNumPixels());
     
    490483    }
    491484
    492     const MGeomPix &pix = (*this)[idx];
     485    const MGeom &pix = (*this)[idx];
    493486    GetNeighbors(arr, pix, r);
    494487}
     
    499492// The center pixel is also returned.
    500493//
    501 void MGeomCam::GetNeighbors(TList &arr, const MGeomPix &pix, Float_t r) const
     494void MGeomCam::GetNeighbors(TList &arr, const MGeom &pix, Float_t r) const
    502495{
    503496    for (unsigned int i=0; i<GetNumPixels(); i++)
     
    518511        return;
    519512
    520     const MGeomPix &pix = (*this)[idx];
     513    const MGeom &pix = (*this)[idx];
    521514    GetNeighbors(arr, pix, r);
    522515}
     
    544537        return -1;
    545538
    546     const MGeomPix &pix=operator[](idx);
     539    const MGeom &pix=operator[](idx);
    547540
    548541    //
     
    598591        MGeomCam::Class()->WriteBuffer(b, this);
    599592}
     593
     594void MGeomCam::SetAt(UInt_t i, const MGeom &pix)
     595{
     596    if (i>=fNumPixels)
     597        return;
     598
     599    if (fPixels[i])
     600        delete fPixels.RemoveAt(i);
     601
     602    // For root versions <5.18 AddAt is mandatory, for newer
     603    // root-version the []-operator can be used safely
     604    fPixels.AddAt(pix.Clone(), i);
     605}
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.h

    r9259 r9369  
    2020class TVector2;
    2121class TArrayI;
    22 class MGeomPix;
     22class MGeom;
    2323
    2424class MGeomCam : public MParContainer
     
    4343//    Int_t     fNumAreas;        // Number of different pixel sizes
    4444
    45 protected:
    4645    void CalcMaxRadius();
    4746    void CalcNumSectors();
     
    5251public:
    5352    MGeomCam(UInt_t npix=0, Float_t dist=1, const char *name=NULL, const char *title=NULL);
     53    MGeomCam(const MGeomCam &cam) { cam.Copy(*this); }
    5454
    5555    void Copy(TObject &o) const;
     
    9595    UShort_t GetNumPixWithAidx(UInt_t i) const { return (UShort_t)fNumPixWithAidx[i]; }
    9696
    97     MGeomPix &operator[](Int_t i);
    98     MGeomPix &operator[](Int_t i) const;
     97    MGeom &operator[](Int_t i);
     98    MGeom &operator[](Int_t i) const;
    9999
    100100    Int_t GetPixelIdx(const TVector2 &v) const;
     
    108108    void GetNeighbors(TArrayI &arr, UInt_t idx,          Float_t r) const;
    109109    void GetNeighbors(TList &arr,   UInt_t idx,          Float_t r) const;
    110     void GetNeighbors(TArrayI &arr, const MGeomPix &pix, Float_t r) const;
    111     void GetNeighbors(TList &arr,   const MGeomPix &pix, Float_t r) const;
     110    void GetNeighbors(TArrayI &arr, const MGeom &pix, Float_t r) const;
     111    void GetNeighbors(TList &arr,   const MGeom &pix, Float_t r) const;
    112112
    113113    Int_t GetDirection(UInt_t p1, UInt_t p2) const;
     
    119119    void Print(Option_t *opt=NULL) const;
    120120
     121    void SetAt(UInt_t i, const MGeom &pix);
     122
    121123    ClassDef(MGeomCam, 5)  // Geometry base class for the camera
    122124};
  • trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc

    r2521 r9369  
    222222    //  add the first pixel to the list
    223223    //
    224     Int_t pixnum = 0;
    225 
    226     (*this)[pixnum++].Set(0, 0, diameter);
     224    Int_t pixnum = 1;
     225
     226    SetAt(0, MGeomPix(0, 0, diameter));
    227227
    228228    for (Int_t ring=1; ring<7; ring++)
     
    233233        //
    234234        for (int i=0; i<ring; i++)
    235             (*this)[pixnum++].Set((ring-i*0.5)*diameter,
    236                                   i*kS32*diameter,
    237                                   diameter);
    238 
    239         for (int i=0; i<ring; i++)
    240             (*this)[pixnum++].Set((ring*0.5-i)*diameter,
    241                                   ring*kS32 * diameter,
    242                                   diameter);
    243 
    244         for (int i=0; i<ring; i++)
    245             (*this)[pixnum++].Set(-(ring+i)*0.5*diameter,
    246                                   (ring-i)*kS32*diameter,
    247                                   diameter);
    248 
    249         for (int i=0; i<ring; i++)
    250             (*this)[pixnum++].Set((0.5*i-ring)*diameter,
    251                                   -i*kS32*diameter,
    252                                   diameter);
    253 
    254         for (int i=0; i<ring; i++)
    255             (*this)[pixnum++].Set((i-ring*0.5)*diameter,
    256                                   -ring*kS32 * diameter,
    257                                   diameter);
    258 
    259         for (int i=0; i<ring; i++)
    260             (*this)[pixnum++].Set((ring+i)*0.5*diameter,
    261                                   (-ring+i)*kS32*diameter,
    262                                   diameter);
     235            SetAt(pixnum++, MGeomPix((ring-i*0.5)*diameter,
     236                                     i*kS32*diameter, diameter));
     237
     238        for (int i=0; i<ring; i++)
     239            SetAt(pixnum++, MGeomPix((ring*0.5-i)*diameter,
     240                                     ring*kS32 * diameter, diameter));
     241
     242        for (int i=0; i<ring; i++)
     243            SetAt(pixnum++, MGeomPix(-(ring+i)*0.5*diameter,
     244                                     (ring-i)*kS32*diameter, diameter));
     245
     246        for (int i=0; i<ring; i++)
     247            SetAt(pixnum++, MGeomPix((0.5*i-ring)*diameter,
     248                                     -i*kS32*diameter, diameter));
     249
     250        for (int i=0; i<ring; i++)
     251            SetAt(pixnum++, MGeomPix((i-ring*0.5)*diameter,
     252                                     -ring*kS32 * diameter, diameter));
     253
     254        for (int i=0; i<ring; i++)
     255            SetAt(pixnum++, MGeomPix((ring+i)*0.5*diameter,
     256                                     (-ring+i)*kS32*diameter, diameter));
    263257    }
    264258}
  • trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc

    r9259 r9369  
    102102TObject *MGeomCamDwarf::Clone(const char *newname) const
    103103{
    104     MGeomCam *cam = new MGeomCam(GetNumPixels(), GetCameraDist());
    105     for (UInt_t i=0; i<GetNumPixels(); i++)
    106         (*this)[i].Copy((*cam)[i]);
    107 
     104    MGeomCam *cam = new MGeomCam(*this);
    108105    cam->InitGeometry();
    109106    return cam;
     
    256253    //  add the first pixel to the list
    257254    //
    258     (*this)[0].Set(0, 0, diameter);
     255    SetAt(0, MGeomPix(0, 0, diameter));
    259256
    260257    Int_t cnt  = 1;
     
    268265                Double_t x, y;
    269266                CalcXY(dir, ring, i, x, y);
    270                 (*this)[cnt++].Set(x*diameter, y*diameter, diameter);
     267                SetAt(cnt++, MGeomPix(x*diameter, y*diameter, diameter));
    271268            }
    272269        }
     
    285282    //  add the first pixel to the list
    286283    //
    287     (*this)[0].Set(0, 0, diameter);
     284    SetAt(0, MGeomPix(0, 0, diameter));
    288285
    289286    Int_t cnt  = 1;
     
    300297                Double_t x, y;
    301298                if (CalcXY(dir, ring, i, x, y)<rad)
    302                     (*this)[cnt+n++].Set(x*diameter, y*diameter, diameter);
     299                    SetAt(cnt+n++, MGeomPix(x*diameter, y*diameter, diameter));
    303300            }
    304301        }
     
    323320    for (UInt_t i=0; i<GetNumPixels(); i++)
    324321    {
    325         MGeomPix &pix = (*this)[i];
     322        MGeomPix &pix = static_cast<MGeomPix&>((*this)[i]);
    326323
    327324        Int_t k = 0;
  • trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc

    r9356 r9369  
    361361    //
    362362    for (UInt_t i=0; i<GetNumPixels(); i++)
    363         (*this)[i].Set(xtemp[i], ytemp[i], i>396?60:30, sector[i], i>396?1:0);
     363        SetAt(i, MGeomPix(xtemp[i], ytemp[i], i>396?60:30, sector[i], i>396?1:0));
    364364    // (*this)[i].Set(xtemp[i], ytemp[i], i>396?60:30, i>396?sector[i]+6:sector[i]);
    365365}
  • trunk/MagicSoft/Mars/mgeom/MGeomPix.cc

    r9259 r9369  
    22!
    33! *
    4 ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
     4! * This file is part of CheObs, the Modular Analysis and Reconstruction
    55! * Software. It is distributed to you in the hope that it can be a useful
    66! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
     
    99! * Permission to use, copy, modify and distribute this software and its
    1010! * documentation for any purpose is hereby granted without fee,
    11 ! * provided that the above copyright notice appear in all copies and
     11! * provided that the above copyright notice appears in all copies and
    1212! * that both that copyright notice and this permission notice appear
    1313! * in supporting documentation. It is provided "as is" without express
     
    1717!
    1818!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !   Author(s): Harald Kornmayer 1/2001
    20 !
    21 !   Copyright: MAGIC Software Development, 2000-2008
     19!
     20!   Copyright: MAGIC Software Development, 2000-2009
    2221!
    2322!
     
    4847//  - added fUserBits
    4948//
    50 //
    51 // FIXME: According to an agreement we have to change the name 'Id' to 'idx'
     49// Version 5:
     50// ----------
     51//  - now derives from MGeom to which some data members have been moved
    5252//
    5353////////////////////////////////////////////////////////////////////////////
     
    5656#include <TMath.h>
    5757#include <TVector2.h>
     58#include <TVirtualPad.h>
    5859
    5960#include "MLog.h"
     
    6162
    6263#include "MGeomCam.h"
     64#include "MHexagon.h"
    6365
    6466ClassImp(MGeomPix);
    6567
    66 using namespace std;
    67 
    68 const Float_t MGeomPix::gsTan30 = TMath::Tan(30/kRad2Deg); // sqrt(3)/3
    69 const Float_t MGeomPix::gsTan60 = TMath::Tan(60/kRad2Deg); // sqrt(3)
     68const Float_t MGeomPix::gsTan30 = TMath::Sqrt(3)/3;  //TMath::Tan(TMath::DegToRad()*30);
     69const Float_t MGeomPix::gsTan60 = TMath::Sqrt(3);    //TMath::Tan(TMath::DegToRad()*60);
     70
     71const Float_t MGeomPix::gsCos60 = 0.5;               //TMath::Cos(TMath::DegToRad()*60);
     72const Float_t MGeomPix::gsSin60 = TMath::Sqrt(3)/2;  //TMath::Sin(TMath::DegToRad()*60);
    7073
    7174// --------------------------------------------------------------------------
     
    7376// Initializes one pixel
    7477//
    75 MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a) : fUserBits(0)
    76 {
    77     //  default constructor
    78     Set(x, y, r, s, a);
     78MGeomPix::MGeomPix(Float_t x, Float_t y, Float_t r, UInt_t s, UInt_t a) : MGeom(x, y, s, a)
     79{
     80    SetD(r);
    7981    SetNeighbors();
    8082}
     
    8284// --------------------------------------------------------------------------
    8385//
    84 // Return position as TVector2(fX, fY)
    85 //
    86 TVector2 MGeomPix::GetP() const
    87 {
    88     return TVector2(fX, fY);
    89 }
    90 
    91 // --------------------------------------------------------------------------
    92 //
    93 // Initializes Next Neighbors.
    94 //
    95 // WARNING: This function is public, but it is not meant for user access.
    96 // It should only be used from geometry classes (like MGeomCam)
    97 //
    98 void MGeomPix::SetNeighbors(Short_t i0, Short_t i1, Short_t i2,
    99                             Short_t i3, Short_t i4, Short_t i5)
    100 {
    101     fNeighbors[0] = i0;
    102     fNeighbors[1] = i1;
    103     fNeighbors[2] = i2;
    104     fNeighbors[3] = i3;
    105     fNeighbors[4] = i4;
    106     fNeighbors[5] = i5;
    107 
    108     int i;
    109     for (i=0; i<6; i++)
    110         if (fNeighbors[i]<0)
    111             break;
    112 
    113     fNumNeighbors = i;
    114 
    115     fNumNeighbors<5 ? SETBIT(fUserBits, kIsInOutermostRing) : CLRBIT(fUserBits, kIsInOutermostRing);
    116 }
    117 
    118 // --------------------------------------------------------------------------
    119 //
    120 //  Set the kIsOuterRing flag if this pixel has a outermost pixel
    121 //  as Next Neighbor and don't have the kIsOutermostRing flag itself.
    122 //
    123 void MGeomPix::CheckOuterRing(const MGeomCam &cam)
    124 {
    125     if (IsInOutermostRing())
    126         return;
    127 
    128     CLRBIT(fUserBits, kIsInOuterRing);
    129 
    130     for (int i=0; i<fNumNeighbors; i++)
    131         if (cam[fNeighbors[i]].IsInOutermostRing())
    132         {
    133             SETBIT(fUserBits, kIsInOuterRing);
    134             return;
    135         }
    136 }
    137 
    138 // --------------------------------------------------------------------------
    139 //
    14086// Print the geometry information of one pixel.
    14187//
    14288void MGeomPix::Print(Option_t *opt) const
    143 {
    144     //   information about a pixel
    145     *fLog << all << "MPixGeom:  x/y=" << fX << "/" << fY << "mm ";
    146     *fLog << "d= " << fD << "mm  A= " << fA << "mm² (";
    147     for (int i=0; i<fNumNeighbors; i++)
    148         *fLog << fNeighbors[i] << (i<fNumNeighbors-1?",":"");
    149     *fLog << ")" << endl;
    150 }
    151 
    152 // ------------------------------------------------------------------------
    153 //
    154 // Return distance of center to coordinate origin: hypot(fX,fY)
    155 //
    156 Float_t MGeomPix::GetDist() const
    157 {
    158     return TMath::Hypot(fX, fY);
    159 }
    160 
    161 // ------------------------------------------------------------------------
    162 //
    163 // Return distance of center to center of pix: hypot(fX-pix.fX,fY-pix.fY)
    164 //
    165 Float_t MGeomPix::GetDist(const MGeomPix &pix) const
    166 {
    167     return TMath::Hypot(fX-pix.fX, fY-pix.fY);
    168 }
    169 
    170 // ------------------------------------------------------------------------
    171 //
    172 // Return angle defined by the center and the center of pix:
    173 //  atan2(fX-pix.fX,fY-pix.fY)
    174 //
    175 Float_t MGeomPix::GetAngle(const MGeomPix &pix) const
    176 {
    177     return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY());
    178 }
    179 
    180 // ------------------------------------------------------------------------
    181 //
    182 // compute the distance of a point (px,py) to the Hexagon center in
    183 // MGeomPix coordinates. Return kTRUE if inside.
    184 //
    185 Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
    186 {
     89{
     90    MGeom::Print(opt);
     91    gLog << " d=" << fD << "mm" << endl;
     92}
     93
     94// ------------------------------------------------------------------------
     95//
     96// compute the distance of a point (px,py) to the Hexagon center in world
     97// coordinates. Return -1 if inside.
     98//
     99Float_t MGeomPix::DistanceToPrimitive(Float_t px, Float_t py) const
     100{
     101    //FIXME: Rotation phi missing!
     102
    187103    //
    188104    //  compute the distance of the Point to the center of the Hexagon
    189105    //
    190     const Double_t dx = px-fX;
     106    //const Double_t dx = px-fX;
     107    //const Double_t dy = py-fY;
     108
     109    TVector2 v(px-fX, py-fY);
     110    // FIXME: fPhi or -fPhi?
     111    // v = v.Rotate(-fPhi);             // FIXME: Replace with a precalculates sin/cos vector
     112
     113    const Double_t dx = v.X();
     114    const Double_t dy = v.Y();
     115
     116    const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
    191117
    192118    //
     
    196122    // more, rotated with respect to that one by +- 60 degrees.
    197123    //
    198     if (TMath::Abs(dx)>fD/2)
    199         return kFALSE;
    200 
    201     const Double_t dy = py-fY;
    202 
    203     const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
    204     const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
    205 
    206     const Double_t dxc = dx*cos60;
    207     const Double_t dys = dy*sin60;
    208 
    209     if  (TMath::Abs(dxc + dys)>fD/2)
    210         return kFALSE;
    211 
    212     if (TMath::Abs(dxc - dys)>fD/2)
    213         return kFALSE;
    214 
    215     return kTRUE;
    216 }
    217 
    218 // ------------------------------------------------------------------------
    219 //
    220 // Return the direction of the pixel pix w.r.t. this pixel.
    221 // Remark: This function assumes a simple geometry.
    222 //
    223 Int_t MGeomPix::GetDirection(const MGeomPix &pix) const
    224 {
    225     const Double_t x1 = GetX();
    226     const Double_t y1 = GetY();
    227 
    228     const Double_t x2 = pix.GetX();
    229     const Double_t y2 = pix.GetY();
    230 
    231     if (x1<=x2 && y1<y2) return kRightTop;
    232     if (x1<=x2 && y1>y2) return kRightBottom;
    233     if (x1>=x2 && y1<y2) return kLeftTop;
    234     if (x1>=x2 && y1>y2) return kLeftBottom;
    235     if (x1<x2)           return kRight;
    236     if (x1>x2)           return kLeft;
    237 
    238     cout << -1 << endl;
     124
     125    if (TMath::Abs(dx) > fD/2)
     126      return disthex;
     127
     128    const Double_t dx2 = dx*gsCos60 + dy*gsSin60;
     129
     130    if  (TMath::Abs(dx2) > fD/2)
     131      return disthex;
     132
     133    const Double_t dx3 = dx*gsCos60 - dy*gsSin60;
     134
     135    if  (TMath::Abs(dx3) > fD/2)
     136      return disthex;
    239137
    240138    return -1;
     
    243141// ------------------------------------------------------------------------
    244142//
    245 // compute the distance of a point (px,py) to the Hexagon center in world
    246 // coordinates. Return -1 if inside.
    247 //
    248 Float_t MGeomPix::DistanceToPrimitive(Float_t px, Float_t py) const
    249 {
    250     //FIXME: Rotation phi missing!
    251 
    252     static Double_t fgCos60 = 0.5;               //TMath::Cos(TMath::DegToRad()*60);
    253     static Double_t fgSin60 = TMath::Sqrt(3.)/2; //TMath::Sin(TMath::DegToRad()*60);
    254 
     143// Implementation of PaintPrimitive drwaing a hexagonal pixel
     144//
     145void MGeomPix::PaintPrimitive(const TAttLine &fill, const TAttFill &line, Double_t scalexy, Double_t scaled) const
     146{
     147    MHexagon hex;
     148
     149    fill.Copy(hex);
     150    line.Copy(hex);
     151
     152    hex.PaintHexagon(fX*scalexy, fY*scalexy, fD*scaled);
     153}
     154
     155
     156// ------------------------------------------------------------------------
     157//
     158// compute the distance of a point (px,py) to the Hexagon center in
     159// MGeomPix coordinates. Return kTRUE if inside.
     160//
     161Bool_t MGeomPix::IsInside(Float_t px, Float_t py) const
     162{
    255163    //
    256164    //  compute the distance of the Point to the center of the Hexagon
    257165    //
    258     //const Double_t dx = px-fX;
    259     //const Double_t dy = py-fY;
    260 
    261     TVector2 v(px-fX, py-fY);
    262     // FIXME: fPhi or -fPhi?
    263     // v = v.Rotate(-fPhi);             // FIXME: Replace with a precalculates sin/cos vector
    264 
    265     const Double_t dx = v.X();
    266     const Double_t dy = v.Y();
    267 
    268     const Double_t disthex = TMath::Sqrt(dx*dx + dy*dy);
     166    const Double_t dx = px-fX;
    269167
    270168    //
     
    274172    // more, rotated with respect to that one by +- 60 degrees.
    275173    //
    276 
    277     if (TMath::Abs(dx) > fD/2.)
    278       return disthex;
    279 
    280     const Double_t dx2 = dx*fgCos60 + dy*fgSin60;
    281 
    282     if  (TMath::Abs(dx2) > fD/2.)
    283       return disthex;
    284 
    285     const Double_t dx3 = dx*fgCos60 - dy*fgSin60;
    286 
    287     if  (TMath::Abs(dx3) > fD/2.)
    288       return disthex;
    289 
    290     return -1;
     174    if (TMath::Abs(dx)>fD/2)
     175        return kFALSE;
     176
     177    const Double_t dy = py-fY;
     178
     179    const static Double_t cos60 = TMath::Cos(60/kRad2Deg);
     180    const static Double_t sin60 = TMath::Sin(60/kRad2Deg);
     181
     182    const Double_t dxc = dx*cos60;
     183    const Double_t dys = dy*sin60;
     184
     185    if  (TMath::Abs(dxc + dys)>fD/2)
     186        return kFALSE;
     187
     188    if (TMath::Abs(dxc - dys)>fD/2)
     189        return kFALSE;
     190
     191    return kTRUE;
    291192}
    292193
     
    460361}
    461362*/
    462 
  • trunk/MagicSoft/Mars/mgeom/MGeomPix.h

    r9259 r9369  
    22#define MARS_MGeomPix
    33
    4 #ifndef MARS_MParContainer
    5 #include "MParContainer.h"
     4#ifndef MARS_MGeom
     5#include "MGeom.h"
    66#endif
    77
    8 class MGeomCam;
    9 class TVector2;
    10 class TOrdCollection;
    11 
    12 
    13 class MGeomPix : public MParContainer
     8class MGeomPix : public MGeom
    149{
    1510public:
     
    1712    static const Float_t gsTan30; // tan(30/kRad2Deg);
    1813
    19     enum {
    20         kRightTop,
    21         kRight,
    22         kRightBottom,
    23         kLeftBottom,
    24         kLeft,
    25         kLeftTop
    26     };
     14    static const Float_t gsCos60; // cos(60/kRad2Deg);
     15    static const Float_t gsSin60; // sin(30/kRad2Deg);
    2716
    2817private:
    29     enum {
    30         kIsInOutermostRing = 0,
    31         kIsInOuterRing     = 1,
    32     };
    33 
    34     Float_t fX;            // [mm]   the x coordinate of the center
    35     Float_t fY;            // [mm]   the y coordinate of the center
    3618    Float_t fD;            // [mm]   the d coordinate of the pixel (dist between two parallel sides)
    37     Float_t fA;            // [mm^2] Area of the pixel
    38 
    39     Byte_t  fNumNeighbors; // number of valid neighbors
    40     Short_t fNeighbors[6]; // the IDs of the pixel next to it (we are assuming an hexagonal geometry)
    41 
    42     UInt_t fSector;        // Number of sector the pixels corresponds to
    43     UInt_t fAidx;          // Area index of the pixel
    44 
    45     Byte_t fUserBits;
    4619
    4720public:
     
    5124    {
    5225        MGeomPix &pix = (MGeomPix&)obj;
    53         pix.fX = fX;
    54         pix.fY = fY;
     26
    5527        pix.fD = fD;
    56         pix.fA = fA;
    57         pix.fNumNeighbors = fNumNeighbors;
    58         pix.fSector = fSector;
    59         pix.fAidx = fAidx;
    60         pix.fUserBits = fUserBits;
    61         for (int i=0; i<6; i++)
    62             pix.fNeighbors[i] = fNeighbors[i];
    6328
     29        MGeom::Copy(obj);
    6430        TObject::Copy(obj);
    6531    }
    6632
     33    void SetD(Float_t d=1) { fD=d; fA=d*d*gsTan60/2; }
     34
     35    Float_t GetD() const  { return fD; }         // Distance between two parallel sides
     36    Float_t GetL() const  { return fD*gsTan30; } // Length of one of the parallel sides
     37    Float_t GetT() const  { return fD/gsTan60; } // Distance between two opposite edges (traverse)
     38
     39    Bool_t  IsInside(Float_t px, Float_t py) const;
     40    Float_t DistanceToPrimitive(Float_t px, Float_t py) const;
     41    void    PaintPrimitive(const TAttLine &line, const TAttFill &fill, Double_t scalexy=1, Double_t scaled=1) const;
     42
    6743    void Print(Option_t *opt=NULL) const;
    6844
    69     void Set(Float_t x, Float_t y, Float_t d=1, UInt_t s=0, UInt_t aidx=0) { fX=x; fY=y; fD=d; fA=d*d*gsTan60/2; fSector=s; fAidx=aidx; }
    70 
    71     void SetNeighbors(Short_t i0=-1, Short_t i1=-1, Short_t i2=-1,
    72                       Short_t i3=-1, Short_t i4=-1, Short_t i5=-1);
    73 
    74     void CheckOuterRing(const MGeomCam &cam);
    75 
    76     Float_t GetX() const  { return fX; }
    77     Float_t GetY() const  { return fY; }
    78     Float_t GetD() const  { return fD; }         // Distance between two parellel sides
    79     Float_t GetL() const  { return fD*gsTan30; } // Length of one of the parallel sides
    80     Float_t GetT() const  { return fD/gsTan60; } // Distance between two opposite edges (traverse)
    81     UInt_t  GetSector() const { return fSector; }
    82 
    83     TVector2 GetP() const;
    84 
    85     Float_t GetDist() const;
    86     Float_t GetDist(const MGeomPix &pix) const;
    87     Float_t GetAngle(const MGeomPix &pix) const;
    88 
    89     Float_t GetA() const    { return fA; /*fD*fD*gsTan60/2;*/ }
    90     Int_t   GetAidx() const { return fAidx; }
    91 
    92     Byte_t  GetNumNeighbors() const { return fNumNeighbors; }
    93     Short_t GetNeighbor(Byte_t i) const { return fNeighbors[i]; }
    94 
    95     Bool_t IsInOutermostRing() const { return TESTBIT(fUserBits, kIsInOutermostRing); }
    96     Bool_t IsInOuterRing() const     { return TESTBIT(fUserBits, kIsInOuterRing); }
    97 
    98     Bool_t IsInside(Float_t px, Float_t py) const;
    99     Int_t  GetDirection(const MGeomPix &pix) const;
    100 
    101     virtual Float_t DistanceToPrimitive(Float_t px, Float_t py) const;
    102     //void GetIntersectionBorder(TOrdCollection &col, const MGeomPix &hex) const;
    103     //Double_t CalcOverlapArea(const MGeomPix &cam) const;
    104 
    105     //TObject *GetGraphics() { return new MHexagon(*this); }
    106 
    107     ClassDef(MGeomPix, 4) // Geometry class describing the geometry of one pixel
     45    ClassDef(MGeomPix, 5) // Geometry class describing the geometry of one pixel
    10846};
    10947
  • trunk/MagicSoft/Mars/mgeom/Makefile

    r8386 r9369  
    1919#  connect the include files defined in the config.mk file
    2020#
    21 INCLUDES = -I. -I../mbase -I../MBase
     21INCLUDES = -I. -I../mbase -I../mgui -I../MBase
    2222
    23 SRCFILES = MGeomPix.cc \
     23SRCFILES = MGeom.cc \
     24           MGeomPix.cc \
     25           MGeomRectangle.cc \
    2426           MGeomCam.cc \
    2527           MGeomCamCT1.cc \
    2628           MGeomCamDwarf.cc \
    2729           MGeomCamMagic.cc \
     30           MGeomCamSquare.cc \
    2831           MGeomCorsikaCT.cc \
    2932           MGeomMirror.cc \
Note: See TracChangeset for help on using the changeset viewer.