Changeset 285 in Idarraga
- Timestamp:
- Apr 20, 2012, 5:11:44 PM (12 years ago)
- Location:
- mafalda/MAFTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mafalda/MAFTools/MAFTools.cpp
r251 r285 17 17 #include <set> 18 18 #include <iostream> 19 #include <fstream> 20 #include <stdlib.h> 19 21 20 22 #include <TROOT.h> … … 349 351 350 352 //cout << "next: " << nextNeighbor.first << " , " << nextNeighbor.second << " ---> " 351 353 //<< totmap[ nextNeighbor.second * maxx + nextNeighbor.first ] << endl; 352 354 353 355 // check the Set see if it existed … … 390 392 else 391 393 return (2*tolerancePixels + 2)*4 + 392 GetLengthOfSpiral(--tolerancePixels);394 GetLengthOfSpiral(--tolerancePixels); 393 395 394 396 } … … 437 439 spiral->yCntr = 1; 438 440 spiral->dir = 1; 441 442 } 443 444 void FillValuesForDisplay(Highlighter * hl, blob bl){ 445 446 hl->UploadDisplayValue("Number of Pixels ", bl.bP.nPixels); 447 hl->UploadDisplayValue("Inner Pixels ", bl.bP.nInnerPixels); 448 hl->UploadDisplayValue("Total charge ", bl.bP.totalCharge); 449 hl->UploadDisplayValue("Width x ", bl.bP.width_x); 450 hl->UploadDisplayValue("Width y ", bl.bP.width_y); 451 hl->UploadDisplayValue("Geo center x ", bl.bP.geoCenter_x); 452 hl->UploadDisplayValue("Geo center y ", bl.bP.geoCenter_y); 453 hl->UploadDisplayValue("Weighted center x ", bl.bP.weightedCenter_x); 454 hl->UploadDisplayValue("Weighted center y ", bl.bP.weightedCenter_y); 455 hl->UploadDisplayValue("Box area ", bl.bP.boxArea); 456 hl->UploadDisplayValue("Circle area ", bl.bP.circleArea); 457 hl->UploadDisplayValue("Ellipse area ", bl.bP.ellipseArea); 458 hl->UploadDisplayValue(" circle/elipse ", bl.bP.circleArea/bl.bP.ellipseArea); 459 hl->UploadDisplayValue("Elipse A ", bl.bP.ellipseA); 460 hl->UploadDisplayValue("Elipse B ", bl.bP.ellipseB); 461 hl->UploadDisplayValue("Rotation angle [deg] ", bl.bP.rotAngle * 180 / TMath::Pi()); 462 hl->UploadDisplayValue("Chisquare/dof ", bl.bP.chisquare_OverDof); 463 hl->UploadDisplayValue("Fit slope ", bl.bP.fitSlope); 464 hl->UploadDisplayValue("Fit cut ", bl.bP.fitCut); 465 hl->UploadDisplayValue("Balance to minimum ", bl.bP.balanceToMin); 466 hl->UploadDisplayValue("Balance to maximum ", bl.bP.balanceToMin); 467 hl->UploadDisplayValue("Min dist to center ", bl.bP.minToGeoCenter); 468 hl->UploadDisplayValue("Max dist to center ", bl.bP.maxToGeoCenter); 439 469 440 470 } … … 507 537 } 508 538 509 } 510 511 539 540 TimePixCalibration::TimePixCalibration(const char * af, 541 const char * bf, 542 const char * cf, 543 const char * tf, 544 int width, int height){ 545 546 m_width = width; 547 m_height = height; 548 549 ifstream afs(af, fstream::in); 550 ifstream bfs(bf, fstream::in); 551 ifstream cfs(cf, fstream::in); 552 ifstream tfs(tf, fstream::in); 553 554 //////////////////////////////////// 555 // a 556 m_a = new double[m_width*m_height]; 557 double temp = 0.; 558 int i = 0; 559 while ( afs.good() ) { 560 afs >> temp; 561 if(afs.eof()) break; 562 m_a[i++] = temp; 563 } 564 afs.close(); 565 if(i != m_width*m_height){ 566 cout << "Calibration does not seem to be complete for paremeter a." << endl; 567 cout << "Got " << i << " items. " << m_width << "*" << m_height 568 << " were requested. Giving up." << endl; 569 exit(1); 570 } 571 572 //////////////////////////////////// 573 // b 574 m_b = new double[m_width*m_height]; 575 i = 0; 576 while ( bfs.good() ) { 577 bfs >> temp; 578 if(bfs.eof()) break; 579 m_b[i++] = temp; 580 } 581 bfs.close(); 582 if(i != m_width*m_height){ 583 cout << "Calibration does not seem to be complete for paremeter b." << endl; 584 cout << "Got " << i << " items. " << m_width << "*" << m_height 585 << " were requested. Giving up." << endl; 586 exit(1); 587 } 588 589 //////////////////////////////////// 590 // c 591 m_c = new double[m_width*m_height]; 592 i = 0; 593 while ( cfs.good() ) { 594 cfs >> temp; 595 if(cfs.eof()) break; 596 m_c[i++] = temp; 597 } 598 cfs.close(); 599 if(i != m_width*m_height){ 600 cout << "Calibration does not seem to be complete for paremeter c." << endl; 601 cout << "Got " << i << " items. " << m_width << "*" << m_height 602 << " were requested. Giving up." << endl; 603 exit(1); 604 } 605 606 //////////////////////////////////// 607 // t 608 m_t = new double[m_width*m_height]; 609 i = 0; 610 while ( tfs.good() ) { 611 tfs >> temp; 612 if(tfs.eof()) break; 613 m_t[i++] = temp; 614 } 615 tfs.close(); 616 if(i != m_width*m_height){ 617 cout << "Calibration does not seem to be complete for paremeter t." << endl; 618 cout << "Got " << i << " items. " << m_width << "*" << m_height 619 << " were requested. Giving up." << endl; 620 exit(1); 621 } 622 623 } 624 625 TimePixCalibration::~TimePixCalibration(){ 626 } 627 628 double TimePixCalibration::GetE(pair<int,int> pix, int tot){ 629 630 //TF1 * surr = GetSurrogateTF1(pix); 631 632 int index = MAFTools::XYtoC(pix, m_width); 633 double par[] = { m_a[index], m_b[index], m_c[index], m_t[index] }; 634 635 /* 636 if(pix.first == 111 && pix.second == 70) { 637 std::cout << "a = " << par[0] << std::endl; 638 std::cout << "b = " << par[1] << std::endl; 639 std::cout << "c = " << par[2] << std::endl; 640 std::cout << "t = " << par[3] << std::endl; 641 }*/ 642 643 644 double evalTOT = 0.; 645 double prev_e = 0.; 646 double dist = 0.; 647 double prev_dist = 10000; 648 649 // search 650 for(double e = 3.0; e <= 10000. ; e+=0.05) { // steps of 0.05 keV, start search 651 652 //evalTOT = surr->Eval(e); 653 evalTOT = SurrogateCalibFunction(e, par); 654 if(evalTOT < 0) continue; // don't consider those values. Not physical. 655 dist = TMath::Abs(evalTOT - tot); 656 //if(pix.first == 111 && pix.second == 70) cout << "dist = " << dist << " | e = " << e << " | evalTOT = " << evalTOT << " | tot = " << tot << endl; 657 if( dist > prev_dist ) break; // if I am going far, break. 658 659 prev_dist = dist; 660 prev_e = e; // keep the last energy 661 } 662 663 return prev_e; 664 } 665 666 int TimePixCalibration::GetTOT (pair<int, int> pix, double E) { 667 668 int index = MAFTools::XYtoC(pix, m_width); 669 double par[] = { m_a[index], m_b[index], m_c[index], m_t[index] }; 670 671 return SurrogateCalibFunction(E, par); 672 //return GetSurrogateTF1(pix)->Eval(E); 673 } 674 675 double TimePixCalibration::SurrogateCalibFunction(double x, double * par){ 676 return par[0]*x + par[1] - (par[2]/(x-par[3])); 677 } 678 679 // Only if needed one can fetch a few functions as TF1 objects 680 TF1 * TimePixCalibration::GetSurrogateTF1(pair<int, int> pix){ 681 682 // check first if the function has been defined. Use the Set. 683 m_surrogateItr = m_surrogateSet.find(pix); 684 685 // If surrogate TF1 does not exist yet, build the function first 686 if( m_surrogateItr == m_surrogateSet.end() ) { 687 TString ftitle = "surrogate_"; 688 ftitle += pix.first; ftitle += "_"; ftitle += pix.second; 689 // Usually the parameters come given in keV !!! WARNING !!! 690 m_surrogateMap[pix] = new TF1(ftitle,"[0]*x + [1] - ([2]/(x-[3]))",0,1000); // 1 MeV 691 // Populate parameters. Look for right index first 692 int index = MAFTools::XYtoC(pix, m_width); 693 m_surrogateMap[pix]->SetParameters(m_a[index], m_b[index], m_c[index], m_t[index]); 694 } 695 696 return m_surrogateMap[pix]; 697 } 698 699 } 512 700 #endif -
mafalda/MAFTools/MAFTools.h
r251 r285 7 7 8 8 #include <set> 9 #include <map> 9 10 #include <iostream> 10 11 #include <vector> … … 16 17 //class blob; 17 18 class MediPixAlgo; 19 class Highlighter; 18 20 //class AllBlobsContainer; 19 21 //typedef struct steerSpiral; … … 22 24 23 25 namespace MAFTools { 24 25 Bool_t LinearRegression(Float_t * slope, Float_t * cut,26 Float_t * chisquare_OverDof, Float_t * chisquare, Float_t * ndf,27 Float_t initslope, Float_t initycross,28 std::set< std::pair<Int_t, Int_t> > blobContent);29 26 30 Int_t XYtoC(pair<Int_t, Int_t>, Int_t); 31 Int_t XYtoC(Int_t, Int_t, Int_t); 27 Bool_t LinearRegression(Float_t * slope, Float_t * cut, 28 Float_t * chisquare_OverDof, Float_t * chisquare, Float_t * ndf, 29 Float_t initslope, Float_t initycross, 30 std::set< std::pair<Int_t, Int_t> > blobContent); 32 31 33 Int_t ConvertXYPositionToInteger(std::pair<Int_t, Int_t> position, Int_t dimX, Int_t dimY); 32 Int_t XYtoC(pair<Int_t, Int_t>, Int_t); 33 Int_t XYtoC(Int_t, Int_t, Int_t); 34 34 35 Int_t ConvertXYPositionToInteger(Int_t positionX, Int_t positionY, Int_t dimX, Int_t dimY); 36 37 Double_t CalcDistance(std::pair<Double_t, Double_t>, 38 std::pair<Double_t, Double_t>); 39 Double_t CalcDistance(Double_t, Double_t, 40 Double_t, Double_t); 41 42 Double_t CalcPerpDistanceToLine(Float_t, Float_t, pair<Int_t, Int_t>); 43 Double_t CalcPerpDistanceToLine(Float_t, Float_t, Int_t, Int_t); 35 Int_t ConvertXYPositionToInteger(std::pair<Int_t, Int_t> position, Int_t dimX, Int_t dimY); 36 37 Int_t ConvertXYPositionToInteger(Int_t positionX, Int_t positionY, Int_t dimX, Int_t dimY); 38 39 Double_t CalcDistance(std::pair<Double_t, Double_t>, 40 std::pair<Double_t, Double_t>); 41 Double_t CalcDistance(Double_t, Double_t, 42 Double_t, Double_t); 43 44 Double_t CalcPerpDistanceToLine(Float_t, Float_t, pair<Int_t, Int_t>); 45 Double_t CalcPerpDistanceToLine(Float_t, Float_t, Int_t, Int_t); 44 46 45 47 46 /* Drawing */ 47 void DrawLine(MediPixAlgo *, Float_t, Float_t, Float_t, Float_t, Int_t, Int_t, EColor); 48 /* Drawing */ 49 void FillValuesForDisplay(Highlighter * hl, blob bl); 50 void DrawLine(MediPixAlgo *, Float_t, Float_t, Float_t, Float_t, Int_t, Int_t, EColor); 48 51 49 50 52 /* Word handling */ 53 std::string DumpWordInBinary(UInt_t word); 51 54 52 53 55 // Blobs handling 56 vector<pair<Float_t, Float_t> > FindLimitPixels(blob); 54 57 55 56 57 58 59 60 61 62 63 58 /* 59 * Check if a blob appears within a certain distance from the edges 60 * Parameters: 61 * - blob 62 * - vector containing farthest pixels in the blob (see FindLimitPixels(blob)) 63 * - Width of sensor in units of pixels 64 * - Height of sensor in units of pixels 65 */ 66 Bool_t BlobAtADistanceFromEdges(blob, vector<pair<Float_t, Float_t> >, Int_t, Int_t, Int_t, Int_t); 64 67 65 66 67 68 69 70 71 72 73 74 75 68 /** 69 * Clustering stuff 70 */ 71 int DigitalBlobReclustering(int, AllBlobsContainer *, blob, int, int, std::map<int,int>); 72 bool StartBlob(int, int, int, AllBlobsContainer *, blob *, int, int, std::map<int,int>); 73 bool FollowBlob(blob *, steerSpiral *, int, int, int, std::map<int,int>); 74 void RewindSpiral(steerSpiral *); 75 Int_t GetLengthOfSpiral(Int_t); 76 pair<Int_t, Int_t> GetNextPosition(pair<Int_t, Int_t>, steerSpiral *); 77 bool IsUnsafePosition(pair<Int_t, Int_t>, int, int); 78 void ClearOneBlobData(blob *); 76 79 77 78 80 /* Dump contents of a blob */ 81 void DumpBlobContents(blob); 79 82 80 int FindDiscontinuity(blob); 83 int FindDiscontinuity(blob); 84 85 86 /////////////////////////////////////////////// 87 // TimePix specific 88 89 class TimePixCalibration { 90 91 public: 92 // Provide the 4 calibration files, a,b,c,t 93 TimePixCalibration(){}; 94 TimePixCalibration(const char *, const char *, const char *, const char *, int, int); 95 ~TimePixCalibration(); 96 97 double SurrogateCalibFunction(double x, double *); 98 int GetTOT(pair<int, int>, double); 99 double GetE(pair<int, int>, int); 100 101 TF1 * GetSurrogateTF1(pair<int, int>); 102 103 private: 104 105 double * m_a; 106 double * m_b; 107 double * m_c; 108 double * m_t; 109 110 int m_width; 111 int m_height; 112 113 map<pair<int, int>, TF1* > m_surrogateMap; 114 set< pair<int, int> > m_surrogateSet; // verify content 115 set< pair<int, int> >::iterator m_surrogateItr; 116 117 }; 118 81 119 } 82 120
Note: See TracChangeset
for help on using the changeset viewer.