Changeset 124 in Idarraga


Ignore:
Timestamp:
Apr 12, 2011, 9:41:47 AM (13 years ago)
Author:
idarraga
Message:
 
Location:
mafalda
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • mafalda/AnalysisCore/MediPixAnalysisCoreLinkDef.h

    r111 r124  
    4646#pragma link C++ class hola;
    4747#pragma link C++ class hola;
     48#pragma link C++ class FEI4;
     49#pragma link C++ class Test1;
     50#pragma link C++ class FEI3Mips;
    4851
    4952#endif
  • mafalda/MAFTools/MAFTools.cpp

    r25 r124  
    1010
    1111#include "MAFTools.h"
     12#include "MPXAlgo/Highlighter.h"
     13#include "MPXAlgo/MediPixAlgo.h"
    1214
    1315#include <set>
    1416#include <iostream>
    15  
     17
    1618#include <TROOT.h>
    1719#include <TF1.h>
     
    2426
    2527
    26   Bool_t LinearRegression(Float_t * slope, Float_t * cut,
    27                           Float_t * chisquare_OverDof,
    28                           Float_t initslope, Float_t initycross,
    29                           set< pair<Int_t, Int_t> > blobContent){
    30    
    31     set< pair<Int_t, Int_t> >::iterator setItr;
    32    
    33     // data -->N points
    34     const Int_t N = (const Int_t) blobContent.size();
    35    
    36     // Fit to ax + b.  N has to be greater or equal to the number of
    37     // linearly indepentend functions, in this case 2.
    38     if(N < 2) {
    39       // fit failed
    40       *slope = 0;
    41       *chisquare_OverDof = 0.;
    42       return false;
    43     }
    44    
    45     Float_t * xd = new Float_t[N];
    46     Float_t * yd = new Float_t[N];
    47     Int_t cntr = 0;
    48    
    49     for(setItr = blobContent.begin() ; setItr != blobContent.end() ; setItr++)
    50       {
    51         xd[cntr] = (Float_t)(*setItr).first;
    52         yd[cntr] = (Float_t)(*setItr).second;
    53         cntr++;
    54       }
    55    
    56     // get the fit done, linear fit
    57     TF1 * f1 = new TF1("f1","[0]*x + [1]",0. , 1.);
    58     // enter the guess for the parameters
    59     f1->SetParameters(initslope, initycross);
    60     TGraph * g1 = new TGraph(N, xd, yd);
    61     g1->Fit(f1,"NQ");
    62    
    63     *chisquare_OverDof = f1->GetChisquare()/(Float_t)f1->GetNDF();
    64     *slope = f1->GetParameter(0);
    65     *cut = f1->GetParameter(1);
    66    
    67     delete f1;
    68     delete g1;
    69     delete [] xd;
    70     delete [] yd;
    71    
    72     return true;
    73   }
     28Bool_t LinearRegression(Float_t * slope, Float_t * cut,
     29                Float_t * chisquare_OverDof,
     30                Float_t initslope, Float_t initycross,
     31                set< pair<Int_t, Int_t> > blobContent){
    7432
    75   Int_t ConvertXYPositionToInteger(pair<Int_t, Int_t> position, Int_t dimX, Int_t dimY){
     33        set< pair<Int_t, Int_t> >::iterator setItr;
    7634
    77     return (position.first)%dimX + (position.second)*dimY;
     35        // data -->N points
     36        const Int_t N = (const Int_t) blobContent.size();
    7837
    79   }
     38        // Fit to ax + b.  N has to be greater or equal to the number of
     39        // linearly indepentend functions, in this case 2.
     40        if(N < 2) {
     41                // fit failed
     42                *slope = 0;
     43                *chisquare_OverDof = 0.;
     44                return false;
     45        }
    8046
    81   Int_t ConvertXYPositionToInteger(Int_t positionX, Int_t positionY, Int_t dimX, Int_t dimY){
     47        Float_t * xd = new Float_t[N];
     48        Float_t * yd = new Float_t[N];
     49        Int_t cntr = 0;
    8250
    83     pair<Int_t, Int_t> coordinates (positionX, positionY);
     51        for(setItr = blobContent.begin() ; setItr != blobContent.end() ; setItr++)
     52        {
     53                xd[cntr] = (Float_t)(*setItr).first;
     54                yd[cntr] = (Float_t)(*setItr).second;
     55                cntr++;
     56        }
    8457
    85     return ConvertXYPositionToInteger(coordinates, dimX, dimY);
     58        // get the fit done, linear fit
     59        TF1 * f1 = new TF1("f1","[0]*x + [1]",0. , 1.);
     60        // enter the guess for the parameters
     61        f1->SetParameters(initslope, initycross);
     62        TGraph * g1 = new TGraph(N, xd, yd);
     63        g1->Fit(f1,"NQ");
    8664
    87   }
    88  
    89   Double_t CalcDistance(Double_t x1, Double_t y1,
    90                         Double_t x2, Double_t y2){
     65        *chisquare_OverDof = f1->GetChisquare()/(Float_t)f1->GetNDF();
     66        *slope = f1->GetParameter(0);
     67        *cut = f1->GetParameter(1);
    9168
    92     return TMath::Sqrt((y2 - y1)*(y2 - y1)
    93                        +
    94                        (x2 - x1)*(x2 - x1));
    95    
    96   }
     69        delete f1;
     70        delete g1;
     71        delete [] xd;
     72        delete [] yd;
    9773
    98   Double_t CalcDistance(std::pair<Double_t, Double_t> p1,
    99                         std::pair<Double_t, Double_t> p2){
    100    
    101     return CalcDistance(p1.first, p1.second,
     74        return true;
     75}
     76
     77Int_t ConvertXYPositionToInteger(pair<Int_t, Int_t> position, Int_t dimX, Int_t dimY){
     78
     79        return (position.first)%dimX + (position.second)*dimY;
     80
     81}
     82
     83Int_t ConvertXYPositionToInteger(Int_t positionX, Int_t positionY, Int_t dimX, Int_t dimY){
     84
     85        pair<Int_t, Int_t> coordinates (positionX, positionY);
     86
     87        return ConvertXYPositionToInteger(coordinates, dimX, dimY);
     88
     89}
     90
     91Double_t CalcDistance(Double_t x1, Double_t y1,
     92                Double_t x2, Double_t y2){
     93
     94        return TMath::Sqrt((y2 - y1)*(y2 - y1)
     95                        +
     96                        (x2 - x1)*(x2 - x1));
     97
     98}
     99
     100Double_t CalcDistance(std::pair<Double_t, Double_t> p1,
     101                std::pair<Double_t, Double_t> p2){
     102
     103        return CalcDistance(p1.first, p1.second,
    102104                        p2.first, p2.second);
    103   }
    104  
     105}
    105106
     107Double_t CalcPerpDistanceToLine(Float_t slope, Float_t cut, pair<Int_t, Int_t> point){
     108        return CalcPerpDistanceToLine(slope, cut, point.first, point.second);
     109}
     110
     111Double_t CalcPerpDistanceToLine(Float_t slope, Float_t cut, Int_t px, Int_t py){
     112
     113        Float_t cutPrim = 0.;
     114        Float_t slopePrim = -1./slope;
     115
     116        // Cut of the perpendicular line
     117        cutPrim  = py;
     118        cutPrim -= slopePrim * px;
     119
     120        // intersection of the two lines
     121        Float_t interx = (cutPrim - cut)/(slope - slopePrim);
     122        Float_t intery = interx * slope + cut;
     123
     124        return CalcDistance(px, py, interx, intery);
     125}
     126
     127void DrawLine(MediPixAlgo * algo, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Int_t wd = 2, Int_t st = 2, EColor color = kBlack) {
     128
     129        Highlighter * lineD = new Highlighter(x1, y1, x2, y2, "line", algo);
     130        lineD->SetLineColor(color);
     131        lineD->SetLineWidth(wd);
     132        lineD->SetLineStyle(st);
     133        algo->PullToStoreGateAccess(lineD, MPXDefs::DO_NOT_SERIALIZE_ME);
     134
     135}
     136
     137std::string DumpWordInBinary(UInt_t word) {
     138
     139        string wordS;
     140
     141        UInt_t oneBit = 0x0;
     142        Int_t sizeOfWord = sizeof(word)*8; // number of bits
     143
     144        for (int i = 0 ; i < sizeOfWord ; i++) { // number of bits
     145
     146                oneBit = word & 0x1;
     147
     148                if(oneBit == 0x1) { wordS.append(1,'1'); }
     149                else { wordS.append(1,'0'); }
     150
     151                word = word >> 1;
     152        }
     153
     154        reverse(wordS.begin(),wordS.end());
     155
     156        return wordS;
     157}
    106158
    107159}
  • mafalda/MAFTools/MAFTools.h

    r25 r124  
    1111#include <set>
    1212#include <iostream>
     13#include <vector>
    1314
    1415#include <TROOT.h>
     16
     17class MediPixAlgo;
     18
     19using namespace std;
    1520
    1621namespace MAFTools {
     
    3035                        Double_t, Double_t);
    3136 
     37  Double_t CalcPerpDistanceToLine(Float_t, Float_t, pair<Int_t, Int_t>);
     38  Double_t CalcPerpDistanceToLine(Float_t, Float_t, Int_t, Int_t);
     39
     40
     41  /* Drawing */
     42  void DrawLine(MediPixAlgo *, Float_t, Float_t, Float_t, Float_t, Int_t, Int_t, EColor);
     43
     44  /* Word handling */
     45  std::string DumpWordInBinary(UInt_t word);
    3246
    3347}
  • mafalda/MPXAlgo/MediPixAlgo.h

    r104 r124  
    125125  /* Other Gets */
    126126  TApplication * GetApplication();
    127   // get the tree corresponding to this algo
     127  // Get the TTree corresponding to this algo
    128128  TTree * getMyTree();
     129  TTree * GetMyTree(){return getMyTree();};
     130  // Get the ROOTFile;
    129131  TFile * getMyROOTFile();
     132  TFile * GetMyROOTFile(){return getMyROOTFile();};
     133  // output
    130134  MSG::Endreq endreq;
    131135
  • mafalda/PPSResidual/PPSResidual.cpp

    r97 r124  
    77#include "MAFTools/MAFTools.h"
    88#include "TVector3.h"
     9#include "TF1.h"
    910
    1011#include <vector>
     
    1718PPSResidual::PPSResidual(){
    1819
     20        TF1 * f1 = new TF1("hola","x",0., 0.);
    1921
    2022}
Note: See TracChangeset for help on using the changeset viewer.