source: JEM-EUSO/esaf_cc_at_lal/macros/tools/opticsresponse.C @ 114

Last change on this file since 114 was 114, checked in by moretto, 11 years ago

actual version of ESAF at CCin2p3

File size: 9.2 KB
Line 
1Float_t phi = 0;
2gStyle->SetPalette(51);
3TString dbname = "output/NopticsresponseDB.root";
4//TString dbname = "/tmp/opticsresponseDB.root.save";
5EOpticsResponse* Or = NULL;
6Bool_t IsInitialized = kFALSE;
7
8//______________________________________________________________________________
9void opticsresponse()
10{
11   bar = new TControlBar("vertical", "Optics Response Viewer",10,10);
12   
13   bar->AddButton("How to run        ", "help()","Instructions for running this macro"); 
14   bar->AddButton("Build DB          ", "orbuild()","Build the Optics Response DB"); 
15   bar->AddButton("Eff vs Theta      ", "orread_theta()","Efficacies vs Theta");
16   bar->AddButton("Eff vs Lambda     ", "orread_lambda()","Efficacies vs Lambda");
17   bar->AddButton("Eff vs Phi        ", "orread_phi()","Efficacies vs Phi");
18   bar->AddButton("Eff vs Phi.Anim.  ", "orread_phi_animated()","Efficacies vs Phi Animated");
19   bar->AddButton("Eff vs Lambda. Histo", "orread_histo_lambda()","Efficacies vs Lambda.Histos");
20   bar->AddButton("Eff for Spectrum.", "orread_mixed()","Efficacies for the spectrum. Just a test!");
21   
22   bar->Show();
23   gROOT->SaveContext();
24}
25void help () {}
26//______________________________________________________________________________
27Bool_t init() {
28    if (IsInitialized) return kTRUE;
29    Or = new EOpticsResponse(dbname);
30    IsInitialized = kTRUE;
31    return kTRUE;
32}
33//______________________________________________________________________________
34void orbuild() {
35//    ifs = new KIdealFocalSurface; //LIdealFocalSurface;
36//    os = new ParamOpticalSystem; //LOpticalSystem;
37    ifs = new NIdealFocalSurface; //LIdealFocalSurface;
38    os = new NOpticalSystem; //LOpticalSystem;
39
40
41    OpticsResponseBuilder *orb = new OpticsResponseBuilder;
42    orb->SetOpticalSystem(os);
43    orb->SetIdealFocalSurface(ifs);
44    orb->SetDBName(dbname);
45    orb->SetNrays(1000);
46    orb->SetBins(2,1);
47    orb->BuildEfficacyTables();
48}
49
50//______________________________________________________________________________
51void orread_theta() {
52    init();
53    // display total and trigger efficacies as a function of theta
54    Float_t binsTheta = 100, ThetaMax  = 32, stepTheta = ThetaMax/binsTheta; 
55    TH1F *theta1 = new TH1F("theta1","Global Efficacy vs Theta",binsTheta,0,ThetaMax);
56    TH1F *theta2 = new TH1F("theta2","Triggering Efficacy vs Theta",binsTheta,0,ThetaMax);
57    theta1->SetDirectory(0);
58    theta2->SetDirectory(0);
59    TCanvas *c;
60    if (! (c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_theta"))) {
61        c = new TCanvas("c_eff_theta");
62    }
63    else
64        c->Clear();
65    Float_t theta, lambda_fixed = 3.6e-4;       
66    for (Int_t i(0); i < binsTheta; i++) {
67         theta = (i+0.5)*stepTheta;
68         Or->GetEntry(theta*TMath::DegToRad(), lambda_fixed);
69         Float_t toteff  = Or->GetSample()->GetTotalEfficacy();
70         Float_t trigeff = Or->GetSample()->GetTriggEfficacy();
71         theta1->Fill(theta,toteff);
72         theta2->Fill(theta,trigeff);
73    }
74    theta1->Draw();
75    theta2->Draw("same");
76    theta1->GetXaxis()->SetTitle("Theta, [deg]");
77    theta1->SetLineColor(kRed);
78    theta2->SetLineColor(kBlue);       
79    TLegend *legend=new TLegend(0.1,0.85,0.3,1);
80    legend->SetTextFont(72);
81    legend->SetTextSize(0.02);
82    legend->AddEntry(theta1,"Total Efficacy","lp");
83    legend->AddEntry(theta2,"Triggering Efficacy","l");
84    legend->Draw();
85   
86}
87
88//______________________________________________________________________________
89void orread_lambda() {
90    init();
91    // display total and trigger efficacies as a function of lambda
92    Float_t bins = 100, LambdaMax  = 400, LambdaMin=300, step = (LambdaMax-LambdaMin)/bins; 
93    TH1F *theta1 = new TH1F("theta1","Global Efficacy vs Lambda",bins,LambdaMin,LambdaMax);
94    TH1F *theta2 = new TH1F("theta2","Triggering Efficacy vs Lambda",bins,LambdaMin,LambdaMax);
95    theta1->SetDirectory(0);
96    theta2->SetDirectory(0);
97   
98    TCanvas *c;
99    if (! (c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_lambda"))) {
100        c = new TCanvas("c_eff_lambda");
101    }
102    else
103        c->Clear();
104    Float_t theta_fixed = 15*TMath::DegToRad(), lambda;         
105    for (Int_t i(0); i < bins; i++) {
106         lambda = LambdaMin + (i+0.5)*step;
107         Or->GetEntry(theta_fixed, lambda*1.e-6);
108         Float_t toteff  = Or->GetSample()->GetTotalEfficacy();
109         Float_t trigeff = Or->GetSample()->GetTriggEfficacy();
110         theta1->Fill(lambda,toteff);
111         theta2->Fill(lambda,trigeff);
112    }
113    theta1->SetMinimum(0);
114    theta1->Draw();
115    theta2->Draw("same");
116    theta1->GetXaxis()->SetTitle("Lambda, [nm]");
117    theta1->SetLineColor(kRed);
118    theta2->SetLineColor(kBlue);       
119    TLegend *legend=new TLegend(0.1,0.85,0.3,1);
120    legend->SetTextFont(72);
121    legend->SetTextSize(0.02);
122    legend->AddEntry(theta1,"Total Efficacy","lp");
123    legend->AddEntry(theta2,"Triggering Efficacy","l");
124    legend->Draw();
125   
126}
127
128//______________________________________________________________________________
129void orread_phi() {
130    init();
131    TCanvas *c;
132    if (! (c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_phi"))) {
133        c = new TCanvas("c_eff_phi");
134    }
135    else
136        c->Clear();
137    c->Divide(4,4);
138    Float_t theta_fixed = 0*TMath::DegToRad(), lambda_fixed = 3.5e-4;
139    Or->GetEntry(theta_fixed,lambda_fixed);
140    Clear();
141    TH2F* h[16];
142    for (Int_t i = 0; i<16; i++) {
143         c->cd(i+1);
144         gPad->AddExec("zoom","myzoom()");
145         Float_t phi = 360/16*(i+1);
146         h[i] = Or->GetSample()->MakePsfHistRotated(phi*TMath::DegToRad());
147         h[i]->SetName(Form("hRotated%d",i));
148         h[i]->Draw("col");
149         h[i]->GetXaxis()->SetTitle("mm");
150         h[i]->GetYaxis()->SetTitle("mm");   
151    }
152   
153}
154//______________________________________________________________________________
155void orread_phi_animated() {
156    init();
157    TCanvas *c;
158    if (! (c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_phi_animated"))) {
159        c = new TCanvas("c_eff_phi_animated");
160    }
161    else
162        c->Clear();
163    Float_t theta_fixed = 15*TMath::DegToRad(), lambda_fixed = 3.5e-4;
164    Or->GetEntry(theta_fixed,lambda_fixed);
165    TTimer *timer = new TTimer(20);
166    timer->SetCommand("AnimateRotation()");
167    timer->TurnOn();
168   
169}
170
171//______________________________________________________________________________
172void AnimateRotation() {
173    TCanvas *c;
174    if (!(c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_phi_animated"))) return; 
175    phi += 10; 
176    if (phi >=360) phi -= 360;
177    TH2F* h;
178    Clear();
179    h = Or->GetSample()->MakePsfHistRotated(phi*TMath::DegToRad());
180    h->Draw("col");
181    h->GetXaxis()->SetTitle("mm");
182    h->GetYaxis()->SetTitle("mm");   
183    c->Modified();
184    c->Update();
185   
186}
187 
188//______________________________________________________________________________
189void myzoom() {
190   //this function is executed whenever the mouse is moved in a pad
191   TPad * pad = gPad;
192   TCanvas *big = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("big");
193   if (!big) big = new TCanvas("big","big",600,10,600,600);
194   big->cd();
195   TIter next(pad->GetListOfPrimitives());
196   while (obj=next())) {
197      if (obj->InheritsFrom("TH1")) obj->Draw("colz");
198   }
199   big->Update();
200}         
201         
202//______________________________________________________________________________
203void orread_mixed() {
204    init();
205    TCanvas *c;
206    if (! (c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_mixed"))) {
207        c = new TCanvas("c_eff_mixed");
208    }
209    else
210        c->Clear();
211    c->Divide(1,2);
212    TH1F* spec;
213    if (spec = (TH1F*)gROOT->FindObject("spec")) {
214        delete spec; 
215        spec = NULL;
216    }
217    spec = new TH1F("spec","",100,3.e-4,4.e-4);
218   
219    EsafSpectrum *es = new EsafSpectrum();
220    FluoCalculator *fFluoCalculator = LightSourceFactory::Get()->GetFluoCalculator( "nagano" );
221    Float_t y = fFluoCalculator->GetFluoYield(10,80,es);
222    Int_t stats(0);
223    while (1) {
224       stats++;
225       Float_t lambda = es->GetLambda();
226       spec->Fill(lambda);
227       if (stats>1000) break;
228    }
229    c->cd(1);
230    spec->Draw();
231    spec->GetXaxis()->SetTitle("Lambda, [nm]");
232    c->cd(2);
233    TH2F* h;
234    Clear();
235    h = Or->MakePsfHist(10*TMath::DegToRad(),0*TMath::DegToRad(),spec);
236    h->GetXaxis()->SetTitle("mm");
237    h->GetYaxis()->SetTitle("mm");   
238    h->Draw("colz");
239    delete es;
240}
241
242//______________________________________________________________________________
243void orread_histo_lambda() {
244    init();
245    TCanvas *c;
246    if (! (c = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c_eff_histo_lambda"))) {
247        c = new TCanvas("c_eff_histo_lambda");
248    }
249    else
250        c->Clear();
251    c->Divide(4,4);
252    Float_t theta = 15*TMath::DegToRad();
253    Float_t phi   = 45*TMath::DegToRad(); 
254    Clear();
255    TH2F* histos[16];
256    for (Int_t i = 0; i<16; i++) {
257         c->cd(i+1);
258         gPad->AddExec("zoom","myzoom()");
259         Float_t lambda = 3.e-4 + 1.e-4.*i/16;
260         TH2F* h = Or->MakePsfHist(theta,phi,lambda);
261         histos[i] = (TH2F*)h->Clone();
262         histos[i]->SetName(Form("lambda_%d",i));
263         delete h;
264         histos[i]->Draw("col");
265         histos[i]->GetXaxis()->SetTitle("mm");
266         histos[i]->GetYaxis()->SetTitle("mm");   
267   }
268   delete [] histos;
269}
270
271//______________________________________________________________________________
272void Clear() {
273    TH2F* h;
274    if (h=(TH2F*)gROOT->FindObject("hRotated")) {
275        delete h;
276    } 
277}
278
Note: See TracBrowser for help on using the repository browser.