Subversion Repositories f9daq

Rev

Rev 47 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
35 f9daq 1
#include "TROOT.h"
2
#include "TFile.h"
3
#include "TBenchmark.h"
91 f9daq 4
#include "TH1.h"
35 f9daq 5
#include "TH1F.h"
6
#include "TH2F.h"
37 f9daq 7
#include "TH3F.h"
35 f9daq 8
#include "TCanvas.h"
9
#include "TStyle.h"
10
#include "TPad.h"
11
#include "TF1.h"
12
#include "TGraph.h"
13
#include "TSpectrum.h"
91 f9daq 14
#include "TAttFill.h"
35 f9daq 15
#include "stdio.h"
16
 
91 f9daq 17
#include "include/RTUtil.h"
18
 
37 f9daq 19
//#include "include/RTUtil.h"
35 f9daq 20
 
91 f9daq 21
int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=87, double rangeRight=107, bool debug = false)
35 f9daq 22
{
23
 
24
  int map[8][8]={{32,34,53,55,40,42,61,63},
25
                 {48,50,37,39,56,58,45,47},
26
                 {33,35,52,54,41,43,60,62},
27
                 {49,51,36,38,57,59,44,46},
28
                 {17,19,4,6,25,27,12,14},
29
                 {1,3,20,22,9,11,28,30},
30
                 {16,18,5,7,24,26,13,15},
31
                 {0,2,21,23,8,10,29,31}
32
                };
33
 
34
  char fnameroot[256];
35
  TFile* rootfile;
36
	sprintf(fnameroot, "root/%s.root", filename);
37
	rootfile = (TFile *) gROOT->FindObject(filename);
38
	if(rootfile==NULL) rootfile = new TFile(fnameroot);
39
	if(rootfile==NULL) {
40
	  printf("Cannot open root file %s!!!\n",fnameroot);
41
	  return(0);
42
	}
43
 
44
	// set draw style
91 f9daq 45
	/*
35 f9daq 46
	gStyle->SetPalette(1, 0);
47
 
48
	gStyle->SetPaperSize(TStyle::kA4);
49
	gStyle->SetStatBorderSize(1);
50
	gStyle->SetFrameBorderMode(0);
51
	gStyle->SetFrameFillColor(0);
52
	gStyle->SetCanvasBorderMode(0);
53
	gStyle->SetPadBorderMode(0);
54
	gStyle->SetPadColor(0);
55
	gStyle->SetCanvasColor(0);
56
	gStyle->SetStatColor(0);
91 f9daq 57
	gStyle->SetOptFit(1111);
37 f9daq 58
	gStyle->SetOptStat("ne");
59
	gStyle->SetPadTopMargin(0.15);
60
	gStyle->SetPadBottomMargin(0.15);
35 f9daq 61
	gStyle->SetPadRightMargin(0.15);
37 f9daq 62
	gStyle->SetPadLeftMargin(0.15);
91 f9daq 63
	//gStyle->SetTitleYOffset(1.4);*/
64
	RTSetStyle(gStyle);
35 f9daq 65
 
66
    TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);
91 f9daq 67
    TH2F* h_tdc = (TH2F*) rootfile->Get("htdc");
35 f9daq 68
    canvas1->cd();
91 f9daq 69
    h_tdc->Draw("colz");
35 f9daq 70
 
47 f9daq 71
    //TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC");
72
    TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");
91 f9daq 73
    TCanvas* canvas2 = new TCanvas("canvas2","canvas2",1000,1000);
35 f9daq 74
    canvas2->cd();
47 f9daq 75
    h_correctedTDC->Draw("colz");
36 f9daq 76
 
91 f9daq 77
 
78
    //TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz");
79
    //h_correctedTDC->SetTitle("; t [ns]; Channel");
80
    //h_correctedTDC->Draw("colz");
81
    TCanvas* canvas3 = new TCanvas("canvas3","canvas3",1600,1600);
82
    canvas3->cd();
83
    //TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64);
84
    //h_allTDCbins->Draw();
85
 
86
 
35 f9daq 87
    int binY = map[chX][chY];
91 f9daq 88
    if (debug) printf("%d\n", binY);
89
    //TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1);
90
    TH1D* channelY = h_tdc->ProjectionX("",binY+1,binY+1);
91
    channelY->SetStats(1);
35 f9daq 92
 
93
    char title[256];
91 f9daq 94
    sprintf(title,";Time [ns];Events");
35 f9daq 95
    channelY->SetTitle(title);
91 f9daq 96
    //channelY->GetYaxis()->SetTitleOffset(1.7);
97
    //TAxis* xAxis = h_correctedTDC->GetXaxis();
98
    //int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1);
99
    //channelY->GetXaxis()->SetRangeUser(-range, range);
100
    //gStyle->SetOptStat("nemr");
101
    //gStyle->SetOptFit(111);
102
    channelY->GetXaxis()->SetRangeUser(rangeLeft,rangeRight);
35 f9daq 103
    channelY->Draw();
104
 
91 f9daq 105
    // Fit function: linear for background c + k*x
106
    // Signal: norm*gaussian(mu,sigma)
107
    TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)", rangeLeft, rangeRight);
108
    //TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)");
109
    f_gaus1->SetParNames("Const","Linear","Norm","#mu","#sigma");
110
    //f_gaus1->SetLineColor(kAzure+1);
111
    f_gaus1->SetLineColor(kBlack);
112
    f_gaus1->SetLineWidth(4);
113
 
114
    f_gaus1->SetParameter(0, channelY->GetMinimum());
115
    f_gaus1->SetParameter(1, 0.0);
116
    f_gaus1->SetParameter(2, channelY->GetMaximum() - channelY->GetMinimum());
117
    f_gaus1->SetParameter(3, channelY->GetBinCenter(channelY->GetMaximumBin()));
118
    f_gaus1->SetParameter(4, 1.0);
119
    //channelY->Fit(f_gaus1,"qr");
120
    //channelY->Fit(f_gaus1,"r");
121
 
35 f9daq 122
    //Fit in range +- 3 sigma
91 f9daq 123
    //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(3)-3*f_gaus1->GetParameter(4),
124
    channelY->Fit(f_gaus1,"","");
125
                                  //f_gaus1->GetParameter(3)+3*f_gaus1->GetParameter(4));
126
 
127
    double N = channelY->GetEntries();
128
    double Nbkg = (rangeRight - rangeLeft)*f_gaus1->GetParameter(0);
129
    double Nsig = N - Nbkg;
130
    printf("\nN = %f, Nsig = %f, Nbkg = %f, SN = %f***\n\n", N, Nsig, Nbkg, Nsig/Nbkg);
131
   /*
132
    //to draw a shaded area above and below an histogram range, we create
133
   //a TGraph object (here we shade bins 60 to 80).
134
   Int_t i;
135
   Int_t n = 2*(80-60);
136
   TGraph *gr = new TGraph(2*n);
137
   for (i=0;i<20;i++) {
138
      Float_t xlow = h1->GetBinLowEdge(60+i);
139
      Float_t xup  = h1->GetBinLowEdge(60+i+1);
140
      Float_t y    = h1->GetBinContent(60+i);
141
      Float_t yup  = 1.1*y;
142
      Float_t ydown= 0.9*y;
143
      gr->SetPoint(2*i,  xlow,yup);
144
      gr->SetPoint(2*i+1,xup, yup);
145
      gr->SetPoint(2*n-2*i-1,xlow, ydown);
146
      gr->SetPoint(2*n-2*i-2,xup, ydown);
147
   }
148
   gr->SetFillColor(2);
149
   gr->Draw("lf");*/
150
 
151
   TH1D* timeWindow = (TH1D*) channelY->Clone();
152
    timeWindow->GetXaxis()->SetRangeUser(92,102);
153
    //timeWindow->SetFillColor(kAzure-1);
154
    timeWindow->SetFillColor(kBlack);
155
    timeWindow->SetFillStyle(3004);
156
    timeWindow->Draw("same");
35 f9daq 157
 
91 f9daq 158
 
159
  char drawing[128];
160
  sprintf(drawing, "ps/%sTDC.pdf", filename);
161
  canvas3->SaveAs(drawing);
162
 
163
  gPad->Update();
35 f9daq 164
  return (0);
165
  }