Subversion Repositories f9daq

Rev

Rev 37 | Rev 47 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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