Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
30 | f9daq | 1 | #include "stdio.h" |
2 | #include "TROOT.h" |
||
3 | #include "TFile.h" |
||
4 | #include "TNtuple.h" |
||
5 | #include "TH1F.h" |
||
6 | #include "TH2F.h" |
||
7 | #include "TF1.h" |
||
8 | #include "TMath.h" |
||
9 | #include "TStyle.h" |
||
10 | #include "TCanvas.h" |
||
11 | #include "TLine.h" |
||
12 | #include "zlib/zlib.h" |
||
13 | |||
14 | int scan2d(char * fname="test", char *plopt="2d", double value=0){ |
||
15 | |||
16 | char fullname[256]; |
||
17 | |||
18 | //get ROOT file with histograms |
||
19 | char fnameroot[1024]; |
||
20 | TFile * rootfile; |
||
21 | TDirectory *dir; |
||
22 | |||
23 | sprintf(fnameroot, "root/%s.root", fname); |
||
24 | rootfile = (TFile *) gROOT->FindObject(fname); |
||
25 | if(rootfile==NULL) rootfile = new TFile(fnameroot); |
||
26 | if(rootfile==NULL) { |
||
27 | printf("Cannot open root file %s!!!\n",fnameroot); |
||
28 | return 0; |
||
29 | } |
||
30 | dir = (TDirectory*) rootfile; |
||
31 | |||
32 | |||
33 | // set draw style |
||
34 | gStyle->SetOptStat("ne"); |
||
35 | gStyle->SetPalette(1, 0); |
||
36 | |||
37 | gStyle->SetPaperSize(TStyle::kA4); |
||
38 | gStyle->SetStatBorderSize(1); |
||
39 | gStyle->SetFrameBorderMode(0); |
||
40 | gStyle->SetFrameFillColor(0); |
||
41 | gStyle->SetCanvasBorderMode(0); |
||
42 | gStyle->SetPadBorderMode(0); |
||
43 | gStyle->SetPadColor(0); |
||
44 | gStyle->SetCanvasColor(0); |
||
45 | gStyle->SetStatColor(0); |
||
46 | gStyle->SetOptFit(11); |
||
47 | gStyle->SetOptStat(); |
||
48 | gStyle->SetPadRightMargin(0.15); |
||
49 | gStyle->SetPadLeftMargin(0.12); |
||
50 | //gStyle->SetTitleYOffset(1.4); |
||
51 | |||
52 | TCanvas *c; |
||
53 | int cc=-1; |
||
54 | char hname[256]; |
||
55 | TH1F *hp1d; TH2F *hp2d; |
||
56 | |||
57 | c = new TCanvas("2D Scan", fname, 650, 0, 600, 1200); |
||
58 | c ->Divide(2,4); |
||
59 | for (int i=0;i<8;i++){ |
||
60 | TVirtualPad *pad=c->cd(i%4*2+i/4+1); |
||
61 | |||
62 | if( strstr(plopt, "2d") != NULL ) { |
||
63 | pad->SetLogz(); |
||
64 | pad->SetLogy(0); |
||
65 | sprintf(hname, "h2d%d",i); hp2d = (TH2F *) dir->Get(hname); |
||
66 | (hp2d->GetYaxis())->SetLabelOffset(0.01); |
||
67 | hp2d->SetTitle("; X [mm]; Y[mm]"); |
||
68 | hp2d->DrawCopy("COLZ"); |
||
69 | sprintf(fullname, "ps/%s_2d.pdf", fname); |
||
70 | } |
||
71 | if( strstr(plopt, "adc") != NULL ) { |
||
72 | pad->SetLogy(1); |
||
73 | pad->SetLogz(0); |
||
74 | |||
75 | sprintf(hname, "hadc%d",i); hp1d = (TH1F *) dir->Get(hname); |
||
76 | if (value>0) (hp1d->GetXaxis())->SetRangeUser(0,value); |
||
77 | (hp1d->GetYaxis())->SetLabelOffset(0.01); |
||
78 | hp1d->SetTitle("; ADC (a.u.); N"); |
||
79 | hp1d->DrawCopy(); |
||
80 | sprintf(fullname, "ps/%s_adc.pdf", fname); |
||
81 | |||
82 | } |
||
83 | } |
||
84 | |||
85 | c->SaveAs(fullname); |
||
86 | return 0; |
||
87 | } |