source: trunk/MagicSoft/Mars/mtemp/mifae/macros/plotOptimal.C@ 7136

Last change on this file since 7136 was 4103, checked in by rico, 21 years ago
*** empty log message ***
File size: 3.3 KB
Line 
1////////////////////////////////////////////////////////////////////////////////////
2//
3// _____ Plot Optimized cuts _____
4//
5// Take as input an output from programs/optimizeCuts and plot the results
6// You only need to specify the input file name
7//
8// Jose Flix <jflix@ifae.es>
9// Javier Rico <jrico@ifae.es>
10////////////////////////////////////////////////////////////////////////////////////
11
12
13void plotOptimal(TString fname="optimize.out")
14{
15 gROOT->Reset();
16 gStyle->SetCanvasColor(0);
17 gStyle->SetCanvasBorderMode(0);
18 gStyle->SetPadBorderMode(0);
19 gStyle->SetFrameBorderMode(0);
20 gStyle->SetOptStat(000000);
21 gStyle->SetPalette(1);
22
23 ifstream ifun(fname.Data());
24 Float_t width,length,excess,significance;
25
26 Float_t wmin=9999999;
27 Float_t lmin=9999999;
28 Float_t wmax=-9999999;
29 Float_t lmax=-9999999;
30 Float_t emax=-9999999;
31 Float_t smax=-9999999;
32
33 Float_t dw=-1;
34 Float_t dl=-1;
35 Float_t prevw=-1;
36 Float_t prevl=-1;
37
38 // first loop to get parameters
39 Int_t i=0;
40 while(ifun >> width)
41 {
42 // read data
43 ifun >> length;
44 ifun >> excess;
45 ifun >> significance;
46
47 // keep max/min
48 if(width<wmin) wmin=width;
49 if(length<lmin) lmin=length;
50 if(width>wmax) wmax=width;
51 if(length>lmax) lmax=length;
52 if(significance>smax)
53 {
54 smax=significance;
55 emax=excess;
56 }
57
58 if(width!=prevw) dw=width-prevw;
59 if(length!=prevl) dl=length-prevl;
60
61 prevw=width;
62 prevl=length;
63 i++;
64 }
65 ifun.close();
66
67 cout << "wmin: " << wmin << ", wmax: " << wmax+dw << ", lmin: " << lmin << ", lmax: " << lmax+dl << endl;
68
69 // define histos
70 Int_t nx = TMath::Nint((wmax-wmin)/dw)+1;
71 Int_t ny = TMath::Nint((lmax-lmin)/dl)+1;
72 TH2F *ex = new TH2F("Excess","Excess",nx,wmin,wmax+dw,ny,lmin,lmax+dl);
73 TH2F *sig = new TH2F("Significance","Significance",nx,wmin,wmax+dw,ny,lmin,lmax+dl);
74
75 cout << "nx: " << nx << ", ny: " << ny << endl;
76 cout << "dw: " << dw << ", dl: " << dl << endl;
77
78 ifstream ifun2;
79 ifun2.open(fname.Data());
80
81 // second loop to fill the histograms
82 Float_t wopt,lopt,eopt;
83 while(ifun2 >> width)
84 {
85 // read data
86 ifun2 >> length;
87 ifun2 >> excess;
88 ifun2 >> significance;
89
90 cout << "Width: " << width << '\t' << "Length: " << length << '\t' << "Excess: " << excess << '\t' << "Significance: " << significance;
91 if(significance==smax)
92 {
93 cout << " *****";
94 wopt=width;
95 lopt=length;
96 eopt=excess;
97 }
98
99 cout << endl;
100
101 Int_t binx = TMath::Nint(((width-wmin)/dw));
102 Int_t biny = TMath::Nint(((length-lmin)/dl));
103
104 // cout << "binnx: " << binx+1 << ", biny: " << biny+1 << endl;
105
106 ex->SetBinContent(binx+1,biny+1,excess+.00001);
107 sig->SetBinContent(binx+1,biny+1,significance+.00001);
108 }
109 cout << "Maximal significance: " << smax << " (excess=" << eopt << ") for width="<<wopt<<", length=" << lopt << endl;
110
111 // plot
112 TCanvas *c3 = new TCanvas("c3","c3",0,0,500,750);
113 c3->Divide(1,2);
114
115 c3->cd(1);
116 ex->GetXaxis()->SetTitle("Width (degrees)");
117 ex->GetYaxis()->SetTitle("Length (degrees)");
118 ex->Draw("colz");
119
120 c3->cd(2);
121 sig->GetXaxis()->SetTitle("Width (degrees)");
122 sig->GetYaxis()->SetTitle("Length (degrees)");
123 sig->Draw("colz");
124}
Note: See TracBrowser for help on using the repository browser.