Subversion Repositories f9daq

Rev

Rev 36 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include "TROOT.h"
  2. #include "TFile.h"
  3. #include "TBenchmark.h"
  4. #include "TH1F.h"
  5. #include "TH2F.h"
  6. #include "TCanvas.h"
  7. #include "TStyle.h"
  8. #include "TPad.h"
  9. #include "TF1.h"
  10. #include "TGraph.h"
  11. #include "TSpectrum.h"
  12. #include "stdio.h"
  13.  
  14. #include "include/RTUtil.h"
  15.  
  16. int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=-16, double rangeRight=16, bool debug = false)
  17. {
  18.   //const int c_nChannels = 64;
  19.   //const double c_xOffset = 2.2; // mm
  20.   //const double c_yOffset = 2.3;
  21.  
  22.   int map[8][8]={{32,34,53,55,40,42,61,63},
  23.                  {48,50,37,39,56,58,45,47},
  24.                  {33,35,52,54,41,43,60,62},
  25.                  {49,51,36,38,57,59,44,46},
  26.                  {17,19,4,6,25,27,12,14},
  27.                  {1,3,20,22,9,11,28,30},
  28.                  {16,18,5,7,24,26,13,15},
  29.                  {0,2,21,23,8,10,29,31}
  30.                 };
  31.  
  32.   char fnameroot[256];
  33.   TFile* rootfile;
  34.         sprintf(fnameroot, "root/%s.root", filename);
  35.         rootfile = (TFile *) gROOT->FindObject(filename);
  36.         if(rootfile==NULL) rootfile = new TFile(fnameroot);
  37.         if(rootfile==NULL) {
  38.           printf("Cannot open root file %s!!!\n",fnameroot);
  39.           return(0);
  40.         }
  41.  
  42.         // set draw style
  43.         gStyle->SetPalette(1, 0);
  44.        
  45.         gStyle->SetPaperSize(TStyle::kA4);
  46.         gStyle->SetStatBorderSize(1);
  47.         gStyle->SetFrameBorderMode(0);
  48.         gStyle->SetFrameFillColor(0);
  49.         gStyle->SetCanvasBorderMode(0);
  50.         gStyle->SetPadBorderMode(0);
  51.         gStyle->SetPadColor(0);
  52.         gStyle->SetCanvasColor(0);
  53.         gStyle->SetStatColor(0);
  54.         gStyle->SetOptFit(11);
  55.         gStyle->SetOptStat(0);
  56.         gStyle->SetPadRightMargin(0.15);
  57.         gStyle->SetPadLeftMargin(0.12);
  58.         //gStyle->SetTitleYOffset(1.4);
  59.          
  60.     TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);
  61.     TH2F* htdc = (TH2F*) rootfile->Get("htdc");
  62.     canvas1->cd();
  63.     htdc->Draw("colz");
  64.    
  65.     TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");
  66.     TCanvas* canvas2 = new TCanvas("canvas2","canvas2",800,800);
  67.     canvas2->cd();
  68.     h_correctedTDC->Draw("colz");
  69.     /*
  70.     canvas2->cd(2);
  71.     int binY = map[chX][chY];
  72.     TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1);
  73.     //channelY->SetStats(0);
  74.    
  75.     char title[256];
  76.     sprintf(title,"Channel %d;t [ns];Events", binY);
  77.     channelY->SetTitle(title);
  78.     channelY->GetYaxis()->SetTitleOffset(1.7);
  79.     //TAxis* xAxis = h_correctedTDC->GetXaxis();
  80.     //int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1);
  81.     //channelY->GetXaxis()->SetRangeUser(-range, range);
  82.     channelY->Draw();
  83.  
  84.     TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight);
  85.     TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8);
  86.     f_gaus1->SetParNames("Linear","Norm","#mu","#sigma");
  87.     f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2");
  88.     Int_t n = channelY->GetMaximum();
  89.     Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin());
  90.    
  91.     f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0);
  92.     channelY->Fit(f_gaus1,"0");
  93.     channelY->Fit(f_gaus1,"r");
  94.     */
  95.     //Fit in range +- 3 sigma
  96.     //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3),
  97.       //                            f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3));
  98.    
  99.  
  100.     //f_gaus2->SetParameters(-1, n, mean-0.1, 0.01,
  101.       //                         n, mean+0.1, 0.1);
  102.     //channelY->Fit(f_gaus2,"0");
  103.     //channelY->Fit(f_gaus2,"rl");
  104.     // set range to +- 3 sigma
  105.     //channelY->Fit(f_gaus,"lr","",f_gaus->GetParameter(2)-3*f_gaus->GetParameter(3),
  106.       //                           f_gaus->GetParameter(2)+3*f_gaus->GetParameter(3));
  107.                              
  108.   return (0);
  109.   }
  110.