Ignore:
Timestamp:
08/23/04 11:41:30 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/manalysis
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc

    r3734 r4702  
    3131//       risk!
    3232//
     33// Class Version 3:
     34// ----------------
     35//  - added fNumIslands
     36//           
    3337// Class Version 2:
    3438// ----------------
     
    4650#include <fstream>
    4751
     52#include <TArrayD.h>
    4853#include <TCanvas.h>
    4954
     
    5257
    5358#include "MGeomCam.h"
     59#include "MGeomPix.h"
    5460
    5561ClassImp(MCerPhotEvt);
     
    96102void MCerPhotEvt::Reset()
    97103{
    98     fNumPixels =  0;
    99     fMaxIndex  = -1;
     104    fNumPixels  =  0;
     105    fMaxIndex   = -1;
     106    fNumIslands = -1;
    100107    fLut.Set(0);
    101108    // fPixels->Delete();
     
    346353void MCerPhotEvt::RemoveUnusedPixels()
    347354{
     355    // Create iterator
    348356    TIter Next(fPixels);
    349357    MCerPhotPix *pix = NULL;
    350358
     359    fMaxIndex = -1;
     360
     361    // Remove all unused pixels from list, calculate new fMaxIndex
    351362    while ((pix=(MCerPhotPix*)Next()))
     363    {
    352364        if (!pix->IsPixelUsed())
    353365            fPixels->Remove(pix);
    354 
     366        else
     367            fMaxIndex = TMath::Max(fMaxIndex, pix->GetPixId());
     368    }
     369
     370    // Crompress array
    355371    fPixels->Compress();
     372
     373    // Get new number of entries in array
    356374    fNumPixels=fPixels->GetEntriesFast();
     375
     376    // Rebuild lookup table
     377    RebuildLut();
    357378}
    358379
     
    409430// --------------------------------------------------------------------------
    410431//
     432// This function recursively finds all pixels of one island and assigns
     433// the number num as island number to the pixel.
     434//
     435//  1) Check whether a pixel with the index idx exists, is unused
     436//     and has not yet a island number assigned.
     437//  2) Assign the island number num to the pixel
     438//  3) Loop over all its neighbors taken from the geometry geom. For all
     439//     neighbors recursively call this function (CalcIsland)
     440//  4) Sum the size of the pixel and all neighbors newly assigned
     441//     (by CalcIsland) to this island
     442//
     443// Returns the sum of the pixel size.
     444//
     445Double_t MCerPhotEvt::CalcIsland(const MGeomCam &geom, Int_t idx, Int_t num)
     446{
     447    // Try to get the pixel information of a pixel with this index
     448    MCerPhotPix *pix = GetPixById(idx);
     449
     450    // If a pixel with this index is not existing... do nothing.
     451    if (!pix)
     452        return 0;
     453
     454    // If an island number was already assigned to this pixel... do nothing.
     455    if (pix->GetIdxIsland()>=0)
     456        return 0;
     457
     458    // If the pixel is an unused pixel... do nothing.
     459    if (!pix->IsPixelUsed())
     460        return 0;
     461
     462    // Assign the new island number num to this used pixel
     463    pix->SetIdxIsland(num);
     464
     465    // Get the geometry information (neighbors) of this pixel
     466    const MGeomPix &gpix = geom[idx];
     467
     468    // Get the size of this pixel
     469    Double_t size = pix->GetNumPhotons();
     470
     471    // Now do the same with all its neighbors and sum the
     472    // sizes which they correspond to
     473    const Int_t n = gpix.GetNumNeighbors();
     474    for (int i=0; i<n; i++)
     475        size += CalcIsland(geom, gpix.GetNeighbor(i), num);
     476
     477    // return size of this (sub)cluster
     478    return size;
     479}
     480
     481// --------------------------------------------------------------------------
     482//
     483// Each pixel which is maked as used is assigned an island number
     484// (starting from 0). A pixel without an island number assigned
     485// has island number -1.
     486//
     487// The index 0 corresponds to the island with the highest size (sum
     488// of GetNumPhotons() in island). The size is decreasing with
     489// increasing indices.
     490//
     491// The information about pixel neighbory is taken from the geometry
     492// MGeomCam geom;
     493//
     494// You can access this island number of a pixel with a call to
     495// MCerPhotPix->GetIdxIsland. The total number of islands available
     496// can be accessed with MCerPhotEvt->GetNumIslands.
     497//
     498// CalcIslands returns the number of islands found. If an error occurs,
     499// eg the geometry has less pixels than the highest index stored, -1 is
     500// returned.
     501//
     502Int_t MCerPhotEvt::CalcIslands(const MGeomCam &geom)
     503{
     504    if (fMaxIndex<0 || fNumPixels<=0)
     505    {
     506        *fLog << err << "ERROR - MCerPhotEvt doesn't contain pixels!" << endl;
     507        fNumIslands = 0;
     508        return -1;
     509    }
     510
     511    if ((UInt_t)fMaxIndex>=geom.GetNumPixels())
     512    {
     513        *fLog << err << "ERROR - MCerPhotEvt::CalcIslands: Size mismatch - geometry too small!" << endl;
     514        return -1;
     515    }
     516
     517    // Create a list to hold the sizes of the islands (The maximum
     518    // number of islands possible is rougly fNumPixels/4)
     519    TArrayD size(fNumPixels/3);
     520
     521    // Calculate Islands
     522    Int_t n=0;
     523
     524    // We could loop over all indices which looks more straight
     525    // forward but should be a lot slower (assuming zero supression)
     526    MCerPhotPix *pix=0;
     527
     528    TIter Next(*this);
     529    while ((pix=static_cast<MCerPhotPix*>(Next())))
     530    {
     531        // This 'if' is necessary (although it is done in GetIsland, too)
     532        // because otherwise the counter (n) would be wrong.
     533        // So only 'start' a new island for used pixels (selected by
     534        // using the Iterator) which do not yet belong to another island.
     535        if (pix->GetIdxIsland()<0)
     536        {
     537            Double_t sz = CalcIsland(geom, pix->GetPixId(), n);
     538            size[n++] = sz;
     539        }
     540    }
     541
     542    // Create an array holding the indices
     543    TArrayI idx(n);
     544
     545    // Sort the sizes descending
     546    TMath::Sort(n, size.GetArray(), idx.GetArray(), kTRUE);
     547
     548    // Replace island numbers by size indices -- After this
     549    // islands indices are sorted by the island size
     550    Next.Reset();
     551    while ((pix=static_cast<MCerPhotPix*>(Next())))
     552    {
     553        const Short_t i = pix->GetIdxIsland();
     554
     555        // Find new index
     556        Short_t j;
     557        for (j=0; j<n; j++)
     558            if (idx[j]==i)
     559                break;
     560
     561        pix->SetIdxIsland(j==n ? -1 : j);
     562    }
     563
     564    // Now assign number of islands found
     565    fNumIslands = n;
     566
     567    // return number of island
     568    return fNumIslands;
     569}
     570
     571// --------------------------------------------------------------------------
     572//
    411573// Returns, depending on the type flag:
    412574//
     
    416578//  3: Number of Photons
    417579//  4: Error
     580//  5: Island index
    418581//
    419582Bool_t MCerPhotEvt::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
     
    442605        val = pix->GetErrorPhot();
    443606        break;
     607    case 5:
     608        val = pix->GetIdxIsland();
     609        break;
    444610    default:
    445611        val = pix->GetNumPhotons()*ratio;
  • trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h

    r3734 r4702  
    2424private:
    2525    UInt_t        fNumPixels;
     26    Short_t       fNumIslands;
    2627     Int_t        fMaxIndex;
    2728    TArrayI       fLut;        // Lookup tabel to lookup pixel by index
    2829    TClonesArray *fPixels;     //-> FIXME: Change TClonesArray away from a pointer?
     30
     31    void RebuildLut()
     32    {
     33        // Resize Lut
     34        fLut.Set(fMaxIndex+1);
     35
     36        // Reset Lut
     37        fLut.Reset(-1);
     38
     39        // Rebuild Lut
     40        for (UInt_t i=0; i<GetNumPixels(); i++)
     41        {
     42            const MCerPhotPix &pix = (*this)[i];
     43            fLut[pix.GetPixId()] = i;
     44        }
     45    }
     46
     47    Double_t CalcIsland(const MGeomCam &geom, Int_t idx, Int_t num);
    2948
    3049public:
     
    3251    ~MCerPhotEvt() { delete fPixels; }
    3352
    34     UInt_t GetNumPixels() const { return fNumPixels; }
    35     //void   InitSize(UInt_t num) { fPixels->Expand(num); }
     53    // Setter function to fill pixels
     54    MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0);
     55    void FixSize();
    3656
    37     MCerPhotPix *AddPixel(Int_t idx, Float_t nph=0, Float_t er=0);
    38 
    39     void FixSize();
     57    // Getter functions
     58    UInt_t  GetNumPixels() const { return fNumPixels; }
     59    Short_t GetNumIslands() const { return fNumIslands; };
    4060
    4161    Bool_t  IsPixelExisting(Int_t id) const;
     
    5272    Float_t GetErrorPhotMax(const MGeomCam *geom=NULL) const;
    5373
     74    // Getter functions to access single pixels
    5475    MCerPhotPix &operator[](int i)       { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
    5576    MCerPhotPix &operator[](int i) const { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
    5677
     78    MCerPhotPix *GetPixById(Int_t idx) const;
     79
     80    // Functions to change the contained data
    5781    void Scale(Double_t f) { fPixels->ForEach(MCerPhotPix, Scale)(f); }
    5882    void RemoveUnusedPixels();
     83    Int_t CalcIslands(const MGeomCam &geom);
     84    void Sort(Int_t upto = kMaxInt)
     85    {
     86        // Sort pixels by index
     87        fPixels->Sort(upto);
     88        RebuildLut();
     89    } // For convinience: Sort pixels by index
    5990
    60     MCerPhotPix *GetPixById(Int_t idx) const;
    61 
     91    // class MParContainer
    6292    void Reset();
    6393
     94    // class TObject
    6495    void Print(Option_t *opt=NULL) const;
    6596    void Clear(Option_t *opt=NULL) { Reset(); }
     
    69100    void DrawPixelContent(Int_t num) const;
    70101
     102    // To build an iterator for this class
    71103    operator TIterator*() const;
    72104
  • trunk/MagicSoft/Mars/manalysis/MCerPhotPix.cc

    r3751 r4702  
    4545//  - added fIsHGSaturated
    4646//
     47// Version 5:
     48// ----------
     49//  - added fIdxIsland
     50//
    4751////////////////////////////////////////////////////////////////////////////
    4852#include "MCerPhotPix.h"
     
    6064//
    6165MCerPhotPix::MCerPhotPix(Int_t pix, Float_t phot, Float_t errphot) :
    62     fPixId(pix), fRing(1), fIsCore(kFALSE), fPhot(phot), fErrPhot(errphot),
     66    fPixId(pix), fIsCore(kFALSE), fRing(1), fIdxIsland(-1),
     67    fPhot(phot), fErrPhot(errphot),
    6368    fIsSaturated(kFALSE), fIsHGSaturated(kFALSE)
    6469{
    6570}
     71
     72// --------------------------------------------------------------------------
     73//
     74// From TObject:
     75//  Compare abstract method. Must be overridden if a class wants to be able
     76//  to compare itself with other objects. Must return -1 if this is smaller
     77//  than obj, 0 if objects are equal and 1 if this is larger than obj.
     78//
     79// Here:
     80//  Index numbers are compared
     81//
     82Int_t MCerPhotPix::Compare(const TObject *o) const
     83{
     84    const Int_t diff = fPixId - static_cast<const MCerPhotPix*>(o)->fPixId;
     85    return diff==0 ? 0 : TMath::Sign(1, diff);
     86}
    6687
    6788// --------------------------------------------------------------------------
  • trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h

    r3751 r4702  
    1212    Int_t    fPixId;     // the pixel Id
    1313
    14    Short_t fRing;      // NT: number of analyzed rings around the core pixels, fRing>0 means: used, fRing= 0 means: unused, fRing= -1 means: unmapped (no possible to use in the calculation of the image parameters)
    15     Bool_t   fIsCore;    // the pixel is a Core pixel -> kTRUE
     14    Bool_t   fIsCore;     // the pixel is a Core pixel -> kTRUE
     15    Short_t  fRing;       // NT: number of analyzed rings around the core pixels, fRing>0 means: used, fRing= 0 means: unused, fRing= -1 means: unmapped (no possible to use in the calculation of the image parameters)
     16    Short_t  fIdxIsland;  // the pixel is a Core pixel -> kTRUE
    1617
    1718    Float_t  fPhot;      // The number of Cerenkov photons
     
    2627    MCerPhotPix(Int_t pix=-1, Float_t phot=0, Float_t errphot=0);
    2728
    28     Int_t    GetPixId() const            { return fPixId;   }
    29     Float_t  GetNumPhotons() const       { return fPhot;    }
    30     Float_t  GetErrorPhot() const        { return fErrPhot; }
     29    Int_t   GetPixId() const            { return fPixId;   }
     30    Float_t GetNumPhotons() const       { return fPhot;    }
     31    Float_t GetErrorPhot() const        { return fErrPhot; }
    3132   
    32     Bool_t   IsPixelUsed() const         { return fRing>0; }
    33     Bool_t   IsPixelUnmapped() const     { return fRing==-1; }
    34     void     SetPixelUnused()            { fRing=0; }
    35     void     SetPixelUsed()              { fRing=1; }
    36     void     SetPixelUnmapped()          { fRing=-1;}
     33    Bool_t  IsPixelUsed() const         { return fRing>0; }
     34    Bool_t  IsPixelUnmapped() const     { return fRing==-1; }
     35    void    SetPixelUnused()            { fRing=0; }
     36    void    SetPixelUsed()              { fRing=1; }
     37    void    SetPixelUnmapped()          { fRing=-1;}
     38    void    SetIdxIsland(Short_t num)   { fIdxIsland=num; }
     39    Short_t GetIdxIsland() const        { return fIdxIsland; }
    3740
    38     void     SetRing(UShort_t r)         { fRing = r;   }
    39     Short_t  GetRing() const             { return fRing;}
     41    void    SetRing(UShort_t r)         { fRing = r;   }
     42    Short_t GetRing() const             { return fRing;}
    4043
    41     void     SetPixelCore()              { fIsCore = kTRUE; }
    42     Bool_t   IsPixelCore() const         { return fIsCore;  }
     44    void    SetPixelCore()              { fIsCore = kTRUE; }
     45    Bool_t  IsPixelCore() const         { return fIsCore;  }
    4346
    44     void     SetNumPhotons(Float_t f)    { fPhot    = f; }
    45     void     SetErrorPhot(Float_t f)     { fErrPhot = f; }
    46     void     Set(Float_t np, Float_t ep) { fPhot = np; fErrPhot = ep; }
     47    void    SetNumPhotons(Float_t f)    { fPhot    = f; }
     48    void    SetErrorPhot(Float_t f)     { fErrPhot = f; }
     49    void    Set(Float_t np, Float_t ep) { fPhot = np; fErrPhot = ep; }
    4750
    48     void     SetPixelSaturated()         { fIsSaturated = kTRUE; }
    49     Bool_t   IsPixelSaturated() const    { return fIsSaturated; }
     51    void    SetPixelSaturated()         { fIsSaturated = kTRUE; }
     52    Bool_t  IsPixelSaturated() const    { return fIsSaturated; }
    5053
    51     void     SetPixelHGSaturated()         { fIsHGSaturated = kTRUE; }
    52     Bool_t   IsPixelHGSaturated() const    { return fIsHGSaturated; }
     54    void    SetPixelHGSaturated()       { fIsHGSaturated = kTRUE; }
     55    Bool_t  IsPixelHGSaturated() const  { return fIsHGSaturated; }
    5356
    54     void     AddNumPhotons(Float_t f)    { fPhot += f; }
     57    void    AddNumPhotons(Float_t f)    { fPhot += f; }
    5558
    56     void     Scale(Float_t f)            { fPhot/=f; }
     59    void    Scale(Float_t f)            { fPhot/=f; }
    5760
    58     void     Print(Option_t *opt = NULL) const;
     61    void    Print(Option_t *opt = NULL) const;
     62    Int_t   Compare(const TObject *obj) const;
     63    Bool_t  IsSortable() const { return kTRUE; }
    5964
    60     ClassDef(MCerPhotPix, 4)  // class containing information about the Cerenkov Photons in a pixel
     65    ClassDef(MCerPhotPix, 5)  // class containing information about the Cerenkov Photons in a pixel
    6166};
    6267
Note: See TracChangeset for help on using the changeset viewer.