Changeset 289 in Idarraga


Ignore:
Timestamp:
Apr 27, 2012, 12:02:03 AM (12 years ago)
Author:
idarraga
Message:
 
Location:
mafalda
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • mafalda/BlobsFinder/BlobsFinder.cpp

    r280 r289  
    1212#include "MAFTools/MAFTools.h"
    1313
     14#include "MPXAlgo/Highlighter.h"
    1415
    1516using namespace MSG;
     
    5051        btype = type;
    5152}
    52 */
     53 */
    5354
    5455/**
     
    192193                                if(StartBlob(colItr, rowItr))
    193194                                {
     195                                        // Fill cluster description
     196                                        FillClusterDescription();
     197
    194198                                        // calculate one blob's properties
    195199                                        int retVal = CalculateProperties();
     
    249253        oneBlob.blobContent.clear();
    250254        oneBlob.blobContentSet.clear();
     255        oneBlob.clusterDescription.clear();
    251256
    252257        oneBlob.bP.nPixels = 0;
     
    630635        oneBlob.bP.fitCut = fitCut;
    631636
     637        // A rotation might be unreliable on a highly pixelized object.  Here's a different approach
     638        //  to calculate the circle and elipse areas
     639
     640        // check if the object needs rotation
     641        if(oneBlob.bP.chisquare_OverDof > m_chisquare_OverDof_rotation)
     642        {
     643
     644                // Find the line passing through the extremes of the blob (using the linear regression is not quite right)
     645                vector< pair<Float_t, Float_t> > limitPixels = MAFTools::FindLimitPixels(oneBlob);
     646                double slope = ( limitPixels[1].second - limitPixels[0].second ) / ( limitPixels[1].first - limitPixels[0].first );
     647                double cut = oneBlob.bP.geoCenter_y - slope*oneBlob.bP.geoCenter_x;
     648
     649                // Now calculate the perpendicular distance to this line from all points.
     650                // I will take this as the b of the ellipse
     651                // Then using the perpline I do the same to find a of the ellipse
     652
     653                double maxb = 0.;
     654                double maxa = 0.;
     655                double dist = 0., distcut = 0.;
     656                double perpslope = -1./slope;
     657                double perpcut = oneBlob.bP.geoCenter_y - perpslope*oneBlob.bP.geoCenter_x;
     658                double cutdistance = MAFTools::CalcDistance(limitPixels[0].first, limitPixels[0].second, limitPixels[1].first, limitPixels[1].second) / oneBlob.bP.width_x;
     659                double radiusSquared = 0.;
     660
     661                for (listItr = oneBlob.blobContent.begin() ; listItr != oneBlob.blobContent.end() ; listItr++) {
     662
     663                        // Tricky here ...
     664                        // To determine b, I scan the points between the line at a perpendicular distance <= 1/5 of max pixels from the perp line
     665                        // the opposite for a
     666
     667                        distcut = MAFTools::CalcPerpDistanceToLine(perpslope, perpcut, (*listItr).first );
     668                        if(distcut <= cutdistance) {
     669                                dist = MAFTools::CalcPerpDistanceToLine(slope, cut, (*listItr).first );
     670                                if(dist > maxb) maxb = dist;
     671                        }
     672
     673                        distcut = MAFTools::CalcPerpDistanceToLine(slope, cut, (*listItr).first );
     674                        if(distcut <= cutdistance) {
     675                                dist = MAFTools::CalcPerpDistanceToLine(perpslope, perpcut, (*listItr).first );
     676                                if(dist > maxa) maxa = dist;
     677                        }
     678
     679
     680                        /*
     681                        // Highlighters ... only for visualization
     682                        // limits
     683                        Highlighter * lineA = new Highlighter(limitPixels[0].first, limitPixels[0].second, "arrow", this);
     684                        lineA->SetLineWidth(1);
     685                        PullToStoreGateAccess(lineA, MPXDefs::DO_NOT_SERIALIZE_ME);
     686
     687                        Highlighter * lineB = new Highlighter(limitPixels[1].first, limitPixels[1].second, "arrow", this);
     688                        lineB->SetLineWidth(1);
     689                        PullToStoreGateAccess(lineB, MPXDefs::DO_NOT_SERIALIZE_ME);
     690
     691                        double x1 = oneBlob.bP.geoCenter_x - 5;
     692                        double y1 = slope * x1 + cut;
     693                        double x2 = oneBlob.bP.geoCenter_x + 5;
     694                        double y2 = slope * x2 + cut;
     695
     696                        Highlighter * lineD = new Highlighter(x1, y1, x2, y2, "line", this);
     697                        lineD->SetLineColor(kRed);
     698                        lineD->SetLineWidth(1);
     699                        PullToStoreGateAccess(lineD, MPXDefs::DO_NOT_SERIALIZE_ME);
     700
     701                        x1 = oneBlob.bP.geoCenter_x - 5;
     702                        y1 = perpslope * x1 + perpcut;
     703                        x2 = oneBlob.bP.geoCenter_x + 5;
     704                        y2 = perpslope * x2 + perpcut;
     705
     706                        Highlighter * lineD2 = new Highlighter(x1, y1, x2, y2, "line", this);
     707                        lineD2->SetLineColor(kGreen);
     708                        lineD2->SetLineWidth(1);
     709                        PullToStoreGateAccess(lineD2, MPXDefs::DO_NOT_SERIALIZE_ME);
     710*/
     711
     712                }
     713
     714                oneBlob.bP.ellipseA = maxa;
     715                oneBlob.bP.ellipseB = maxb;
     716
     717                // wx/2 is a, wy/2 is b.  AreaElipse = Pi*a*b
     718                oneBlob.bP.ellipseArea = TMath::Pi()*(maxa*maxb)/4.0;
     719
     720                // fraction --> (sqrt(2)/2)
     721                if(maxa >= maxb)
     722                        radiusSquared = (2.*maxa*maxa) * (0.5/4.);
     723                else
     724                        radiusSquared = (2.*maxb*maxb) * (0.5/4.);
     725
     726                oneBlob.bP.circleArea = TMath::Pi()*radiusSquared;
     727
     728        }
     729        else // no rotation needed
     730        {
     731                Double_t radiusSquared = (wx*wx + wy*wy) * 0.5/4.; // fraction --> (sqrt(2)/2)
     732                oneBlob.bP.circleArea = TMath::Pi()*radiusSquared;
     733                oneBlob.bP.ellipseArea = TMath::Pi()*(wx * wy)/4.0;
     734                oneBlob.bP.ellipseA = wx;
     735                oneBlob.bP.ellipseB = wy;
     736        }
     737
     738        /*
    632739        // check if the object needs rotation
    633740        if(oneBlob.bP.chisquare_OverDof > m_chisquare_OverDof_rotation)
     
    682789                oneBlob.bP.ellipseB = wy;
    683790        }
     791         */
    684792
    685793        // finally type initialized to _NOTYPE_ASSIGNED
     
    10301138}
    10311139
     1140void BlobsFinder::FillClusterDescription(){
     1141
     1142        list< pair < pair<Int_t, Int_t>, Int_t > > bc = oneBlob.GetBlobContent();
     1143        list< pair < pair<Int_t, Int_t>, Int_t > >::iterator i = bc.begin();
     1144
     1145        for ( ; i != bc.end() ; i++) {
     1146                oneBlob.clusterDescription.push_back( pair< pair<Int_t, Int_t>, Int_t > ( (*i).first, GetMatrixElement((*i).first) ) );
     1147        }
     1148
     1149}
     1150
    10321151void BlobsFinder::CalcMinMaxGeoCenter(Float_t geox, Float_t geoy){
    10331152
  • mafalda/BlobsFinder/BlobsFinder.h

    r276 r289  
    144144  set< pair<Int_t, Int_t> > GetContentSet(){return blobContentSet;};
    145145  list< pair < pair<Int_t, Int_t>, Int_t > > GetBlobContent(){return blobContent;};
     146  list< pair < pair<Int_t, Int_t>, Int_t > > GetClusterDescription(){return clusterDescription;};
    146147
    147148  // this will go private ... TODO !!!
     
    151152  //                                               2  3  4
    152153  // A <list> keeps entries in order
     154  // WARNING The second member of the pair is not the TOT(or counts).  Is
     155  //  the ordering in the cluster as defined above
    153156  list< pair < pair<Int_t, Int_t>, Int_t > > blobContent;
    154157  list< pair < pair<Int_t, Int_t>, Int_t > >::iterator blobItr;
     
    156159  //  stdlib does better than me ;)
    157160  set< pair<Int_t, Int_t> > blobContentSet;
     161
     162  // This list really contains the X,Y,C information
     163  list< pair < pair<Int_t, Int_t>, Int_t > > clusterDescription;
    158164
    159165  blobProperties bP;
     
    221227  Float_t GetBalance(Int_t, Int_t, Int_t, Int_t, Float_t *, Float_t *, Int_t *, Int_t *, Float_t *, Float_t *);
    222228  void CalcMinMaxGeoCenter(Float_t, Float_t);
     229  void FillClusterDescription();
    223230
    224231private:
  • mafalda/MPXAlgo/MediPixAlgo.cpp

    r284 r289  
    599599}
    600600
     601TCanvas * MediPixAlgo::DrawInSeparateWindow(vector<TGraph2D *> g){
     602
     603        ///////////////////////////////////////////////////////////////////
     604        TCanvas * c11 = new TCanvas();
     605        int ngraphs2D = (int)g.size();
     606        int xdiv = floor( TMath::Sqrt(ngraphs2D) );
     607        int ydiv = ceil( (double)ngraphs2D/(double)xdiv );
     608        c11->Divide(xdiv, ydiv);
     609
     610        vector<TGraph2D *>::iterator itr = g.begin();
     611        int cntr2 = 0;
     612        for ( ; itr != g.end(); itr++) {
     613                c11->cd(cntr2+1);
     614                (*itr)->Draw("tri1");
     615                cntr2++;
     616        }
     617
     618        return c11;
     619}
     620
    601621#endif
  • mafalda/MPXAlgo/MediPixAlgo.h

    r284 r289  
    1818#include <TString.h>
    1919#include <TVector3.h>
     20#include <TGraph2D.h>
     21#include <TCanvas.h>
    2022
    2123#include "AnalysisCore/MediPixAnalysisCore.h"
     
    193195  void ReadConfiguration();
    194196
     197  // Extra drawing
     198  TCanvas * DrawInSeparateWindow(vector<TGraph2D *>);
     199
    195200  /////////////////////////////
    196201  // Report objects to the TBrowser
Note: See TracChangeset for help on using the changeset viewer.