Changeset 124 in Idarraga
- Timestamp:
- Apr 12, 2011, 9:41:47 AM (13 years ago)
- Location:
- mafalda
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
mafalda/AnalysisCore/MediPixAnalysisCoreLinkDef.h
r111 r124 46 46 #pragma link C++ class hola; 47 47 #pragma link C++ class hola; 48 #pragma link C++ class FEI4; 49 #pragma link C++ class Test1; 50 #pragma link C++ class FEI3Mips; 48 51 49 52 #endif -
mafalda/MAFTools/MAFTools.cpp
r25 r124 10 10 11 11 #include "MAFTools.h" 12 #include "MPXAlgo/Highlighter.h" 13 #include "MPXAlgo/MediPixAlgo.h" 12 14 13 15 #include <set> 14 16 #include <iostream> 15 17 16 18 #include <TROOT.h> 17 19 #include <TF1.h> … … 24 26 25 27 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 } 28 Bool_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){ 74 32 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; 76 34 77 return (position.first)%dimX + (position.second)*dimY; 35 // data -->N points 36 const Int_t N = (const Int_t) blobContent.size(); 78 37 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 } 80 46 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; 82 50 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 } 84 57 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"); 86 64 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); 91 68 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; 97 73 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 77 Int_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 83 Int_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 91 Double_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 100 Double_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, 102 104 p2.first, p2.second); 103 } 104 105 } 105 106 107 Double_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 111 Double_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 127 void 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 137 std::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 } 106 158 107 159 } -
mafalda/MAFTools/MAFTools.h
r25 r124 11 11 #include <set> 12 12 #include <iostream> 13 #include <vector> 13 14 14 15 #include <TROOT.h> 16 17 class MediPixAlgo; 18 19 using namespace std; 15 20 16 21 namespace MAFTools { … … 30 35 Double_t, Double_t); 31 36 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); 32 46 33 47 } -
mafalda/MPXAlgo/MediPixAlgo.h
r104 r124 125 125 /* Other Gets */ 126 126 TApplication * GetApplication(); 127 // get the tree corresponding to this algo127 // Get the TTree corresponding to this algo 128 128 TTree * getMyTree(); 129 TTree * GetMyTree(){return getMyTree();}; 130 // Get the ROOTFile; 129 131 TFile * getMyROOTFile(); 132 TFile * GetMyROOTFile(){return getMyROOTFile();}; 133 // output 130 134 MSG::Endreq endreq; 131 135 -
mafalda/PPSResidual/PPSResidual.cpp
r97 r124 7 7 #include "MAFTools/MAFTools.h" 8 8 #include "TVector3.h" 9 #include "TF1.h" 9 10 10 11 #include <vector> … … 17 18 PPSResidual::PPSResidual(){ 18 19 20 TF1 * f1 = new TF1("hola","x",0., 0.); 19 21 20 22 }
Note: See TracChangeset
for help on using the changeset viewer.