Changeset 8756 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
10/13/07 19:56:29 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r8755 r8756  
    1818
    1919                                                 -*-*- END OF LINE -*-*-
     20
     21 2007/10/13 Thomas Bretz
     22
     23   * mgeom/MGeomCam.[h,cc]:
     24     - added new member functions GetDirections and GetNeighbor
     25
     26   * mgeom/MGeomCamDwarf.cc:
     27     - fixed counting of pixels
     28
     29   * mgeom/MGeomPix.[h,cc]:
     30     - added enumfor direction
     31     - added new member function GetDirection
     32
     33   * mhist/MHCamera.cc:
     34     - make sure that fGeomCam is correctly duplicated. The standard
     35       clone fails if the MGeomCam clone has been overwritten
     36     - added "text" option to Draw
     37
     38   * mtools/MagicReversi.[h,cc]:
     39     - moved GetDirection and GetNeighbor to MGeomCam
     40
     41
    2042
    2143 2007/10/10 Thomas Bretz
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.cc

    r8399 r8756  
    473473    GetNeighbors(arr, pix, r);
    474474}
     475
     476// --------------------------------------------------------------------------
     477//
     478// Return direction of p2 w.r.t. p1. For more details
     479// see MGeomPix::GetDirection
     480//
     481Int_t MGeomCam::GetDirection(UInt_t p1, UInt_t p2) const
     482{
     483    if (p1>fNumPixels || p2>fNumPixels)
     484        return -1;
     485
     486    return operator[](p1).GetDirection(operator[](p2));
     487}
     488
     489// --------------------------------------------------------------------------
     490//
     491// Get index of neighbor of pixel idx in direction dir, if existing.
     492//
     493Int_t MGeomCam::GetNeighbor(UInt_t idx, Int_t dir) const
     494{
     495    if (idx>fNumPixels)
     496        return -1;
     497
     498    const MGeomPix &pix=operator[](idx);
     499
     500    //
     501    // search for the neighbor in the given direction
     502    //
     503    int i;
     504    for (i=0; i<pix.GetNumNeighbors(); i++)
     505        if (GetDirection(idx, pix.GetNeighbor(i))==dir)
     506            return pix.GetNeighbor(i);
     507
     508    return -1;
     509}
  • trunk/MagicSoft/Mars/mgeom/MGeomCam.h

    r8399 r8756  
    102102    void GetNeighbors(TList &arr,   const MGeomPix &pix, Float_t r) const;
    103103
     104    Int_t GetDirection(UInt_t p1, UInt_t p2) const;
     105    Int_t GetNeighbor(UInt_t idx, Int_t dir) const;
     106
    104107    virtual void Print(Option_t *opt=NULL)   const;
    105108
  • trunk/MagicSoft/Mars/mgeom/MGeomCamDwarf.cc

    r8388 r8756  
    183183// distance to (0,0) is retruned.
    184184//
     185// Due to possible rounding errors we need to use exactly the same
     186// algorithm as for creating the pixels!
     187//
    185188Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)
    186189{
     
    198201        // starting number to the ending number
    199202        //
    200         for (int i=0; i<ring; i++)
    201         {
    202             Double_t x, y;
    203             if (CalcXY(kDirN, ring, i, x, y)<rad)
    204                 n++;
     203        for (Int_t dir=kDirNE; dir<=kDirSE; dir++)
     204        {
     205            for (int i=0; i<ring; i++)
     206            {
     207                Double_t x, y;
     208                if (CalcXY(dir, ring, i, x, y)<rad)
     209                    n++;
     210            }
    205211        }
    206212
     
    209215
    210216        ring++;
    211         cnt += 6*n; // Because of symmetry only one direction is enough
     217        cnt += n;
    212218    }
    213219
     
    276282
    277283        if (n==0)
     284        {
     285            cout << cnt << " pixels created of " << GetNumPixels() << endl;
    278286            return;
     287        }
    279288
    280289        ring++;
  • trunk/MagicSoft/Mars/mgeom/MGeomPix.cc

    r7346 r8756  
    173173    return kTRUE;
    174174}
     175
     176// ------------------------------------------------------------------------
     177//
     178// Return the direction of the pixel pix w.r.t. this pixel.
     179// Remark: This function assumes a simple geometry.
     180//
     181Int_t MGeomPix::GetDirection(const MGeomPix &pix) const
     182{
     183    const Double_t x1 = GetX();
     184    const Double_t y1 = GetY();
     185
     186    const Double_t x2 = pix.GetX();
     187    const Double_t y2 = pix.GetY();
     188
     189    if (x1>=x2 && y1>y2) return kRightTop;
     190    if (x1>=x2 && y1<y2) return kRightBottom;
     191    if (x1<=x2 && y1>y2) return kLeftTop;
     192    if (x1<=x2 && y1<y2) return kLeftBottom;
     193    if (x1>x2)           return kRight;
     194    if (x1<x2)           return kLeft;
     195
     196    return -1;
     197}
  • trunk/MagicSoft/Mars/mgeom/MGeomPix.h

    r8385 r8756  
    1313    static const Float_t gsTan60; // tan(60/kRad2Deg);
    1414    static const Float_t gsTan30; // tan(30/kRad2Deg);
     15
     16    enum {
     17        kRightTop,
     18        kRight,
     19        kRightBottom,
     20        kLeftBottom,
     21        kLeft,
     22        kLeftTop
     23    };
    1524
    1625private:
     
    6877    Float_t GetAngle(const MGeomPix &pix) const { return TMath::ATan2(fX - pix.GetX(), fY - pix.GetY()); }
    6978
    70 
    7179    Float_t GetA() const    { return fA; /*fD*fD*gsTan60/2;*/ }
    7280    Int_t   GetAidx() const { return fAidx; }
     
    7987
    8088    Bool_t IsInside(Float_t px, Float_t py) const;
     89    Int_t  GetDirection(const MGeomPix &pix) const;
    8190
    8291    /*
  • trunk/MagicSoft/Mars/mhist/MHCamera.cc

    r8754 r8756  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.105 2007-10-08 15:45:24 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.106 2007-10-13 18:56:27 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    162162TObject *MHCamera::Clone(const char *newname) const
    163163{
    164     TH1 *rc = static_cast<TH1*>(TH1D::Clone(newname));
     164    MHCamera *rc = static_cast<MHCamera*>(TH1D::Clone(newname));
    165165    rc->SetDirectory(NULL);
     166
     167    if (rc->fGeomCam && fGeomCam)
     168    {
     169        delete rc->fGeomCam;
     170        rc->fGeomCam = static_cast<MGeomCam*>(fGeomCam->Clone());
     171    }
     172
    166173    return rc;
    167174}
     
    571578//   'content'     Display the relative content aligned to GetMaximum() and
    572579//                 GeMinimum() ((val-min)/(max-min))
     580//   'text'        Draw GetBinContent as char
    573581//   'proj'        Display the y-projection of the histogram
    574582//   'pal0'        Use Pretty palette
     
    11761184        return;
    11771185    }
     1186    if (opt.Contains("text"))
     1187    {
     1188        PaintIndices(5);
     1189        return;
     1190    }
    11781191}
    11791192
     
    13011314//  1: sector number
    13021315//  2: content
     1316//  5: Assume GetBinContent is a char
    13031317//
    13041318void MHCamera::PaintIndices(Int_t type)
     
    13141328
    13151329    TText txt;
    1316     txt.SetTextFont(122);
     1330    if (type!=5)
     1331        txt.SetTextFont(122);
    13171332    txt.SetTextAlign(22);   // centered/centered
    13181333
     
    13291344        case 3: num += TMath::Nint(fArray[i+1]); break;
    13301345        case 4: num += fBinEntries[i+1]; break;
     1346        case 5: num = (char)TMath::Nint(GetBinContent(i+1)); break;
    13311347        }
    13321348
  • trunk/MagicSoft/Mars/mtools/MagicReversi.cc

    r8755 r8756  
    481481}
    482482
    483 Int_t MagicReversi::GetDirection(Int_t src, Int_t dst) const
    484 {
    485     const MGeomPix &pix1=(*fGeomCam)[dst];
    486     const MGeomPix &pix2=(*fGeomCam)[src];
    487 
    488     const Double_t x1 = pix1.GetX();
    489     const Double_t y1 = pix1.GetY();
    490 
    491     const Double_t x2 = pix2.GetX();
    492     const Double_t y2 = pix2.GetY();
    493 
    494     if (x1>=x2 && y1>y2) return kRightTop;
    495     if (x1>=x2 && y1<y2) return kRightBottom;
    496     if (x1<=x2 && y1>y2) return kLeftTop;
    497     if (x1<=x2 && y1<y2) return kLeftBottom;
    498     if (x1>x2)           return kRight;
    499     if (x1<x2)           return kLeft;
    500 
    501     return -1;
    502 }
    503 
    504 Int_t MagicReversi::GetNeighbor(Int_t idx, Int_t dir) const
    505 {
    506     MGeomPix &pix=(*fGeomCam)[idx];
    507 
    508     //
    509     // search for the neighbor in the given direction
    510     //
    511     int i;
    512     for (i=0; i<pix.GetNumNeighbors(); i++)
    513         if (GetDirection(idx, pix.GetNeighbor(i))==dir)
    514             return pix.GetNeighbor(i);
    515 
    516     return -1;
    517 }
    518 
    519483Bool_t MagicReversi::Flip(Int_t origidx, Bool_t flip)
    520484{
     
    523487    int test[6] = {0,0,0,0,0,0};
    524488
    525     for (int dir=kRightTop; dir<=kLeftTop; dir++)
     489    for (int dir=MGeomPix::kRightTop; dir<=MGeomPix::kLeftTop; dir++)
    526490    {
    527491        Int_t idx = origidx;
     
    530494        while (1)
    531495        {
    532             idx = GetNeighbor(idx, dir);
     496            idx = fGeomCam->GetNeighbor(idx, dir);
    533497            if (idx<0 || (*this)[idx].GetFillColor()==kEmpty)
    534498                break;
     
    547511    int cnt = 0;
    548512
    549     for (int dir=kRightTop; dir<=kLeftTop; dir++)
     513    for (int dir=MGeomPix::kRightTop; dir<=MGeomPix::kLeftTop; dir++)
    550514    {
    551515        Int_t idx = origidx;
     
    557521            for (int i=0; i<test[dir]; i++)
    558522            {
    559                 idx = GetNeighbor(idx, dir);
     523                idx = fGeomCam->GetNeighbor(idx, dir);
    560524
    561525                fUsrPts[(*this)[idx].GetFillColor()-kRed]--;
  • trunk/MagicSoft/Mars/mtools/MagicReversi.h

    r8755 r8756  
    1919{
    2020private:
    21     enum {
    22         kRightTop,
    23         kRight,
    24         kRightBottom,
    25         kLeftBottom,
    26         kLeft,
    27         kLeftTop
    28     };
    29 //    static const Int_t fColorBombs[7]; // colors for the hexagons
    30 
    3121    MGeomCam      *fGeomCam;       // pointer to camera geometry
    3222
     
    7363
    7464    Bool_t Flip(Int_t idx, Bool_t flip);
    75     Int_t  GetDirection(Int_t src, Int_t dst) const;
    76     Int_t  GetNeighbor(Int_t idx, Int_t dir) const;
    7765    Bool_t CheckMoves();
    7866
Note: See TracChangeset for help on using the changeset viewer.