bug fixed
[u/mrichter/AliRoot.git] / T0 / AliT0CalibViewer.C
1 /* $Id$ */
2
3
4 #if !defined(__CINT__)
5 #include "TControlBar.h"
6 #include "TString.h"
7 #include "TRandom.h"
8 #include "TH1F.h"
9 #include "TF1.h"
10 #include "TCanvas.h"
11
12 #include "AliRun.h"
13 #include "AliT0CalibData.h"
14 #include "AliT0AlignData.h"
15 #include "AliCDBMetaData.h"
16 #include "AliCDBId.h"
17 #include "AliCDBEntry.h"
18 #include "AliCDBManager.h"
19 #include "AliCDBStorage.h"
20 #endif
21 TFile *gFile=0;
22
23 void AliT0CalibViewer()
24 {
25   TControlBar *menu = new TControlBar("vertical","T0 CalibViewer");
26   menu->AddButton("Open file","OpenFile()",
27                   "Open file");
28   menu->AddButton("Draw CFD","DrawCFD()",
29                   "Draw all CFD");
30   menu->AddButton("Draw LED","DrawLED()",
31                   "Draw all LED");
32   menu->AddButton("Draw LED-CFD","DrawLEDminCFD()",
33                   "Draw LED-CFD");
34   menu->AddButton("Draw QTC","DrawQTC()",
35                   "Draw all QTC");
36   menu->AddButton("Draw CFDvsQTC","DrawCFDvsQTC()",
37                   "Draw CFD vs QTC");
38   menu->AddButton("Draw CFDvsLED","DrawCFDvsLED()",
39                   "Draw CFD vs LED-CFD");
40   menu->Show();
41 }
42 void OpenFile()
43 {
44
45 const char *ft[]={"T0 raw files","t0tree*.root","All files","*",0,0};
46   TString dir(".");
47   TGFileInfo fi; fi.fFileTypes=ft; fi.fIniDir=StrDup(dir);
48   new TGFileDialog(gClient->GetRoot(), 0x0, kFDOpen, &fi);
49
50   if(!fi.fFilename) return;
51   if(gFile){ gFile->Close(); gFile=0;}
52   
53   gFile=TFile::Open(fi.fFilename); 
54
55 }
56
57 //------------------------------------------------------------------------
58 void DrawCFD()
59 {
60   Int_t npeaks = 20;
61   Int_t sigma=3.;
62   Bool_t down=false;
63   Int_t index[20];
64    
65   TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
66   c1->Divide(4,3);
67   gStyle->SetOptFit(1111);
68   //c1->Divide(2,2);
69   Char_t buf1[10];
70   for (Int_t i=0; i<12; i++)
71     {
72       c1->cd(i+1);
73       sprintf(buf1,"T0_C_%i_CFD",i+1);
74       TH1F *cfd = (TH1F*) gFile->Get(buf1);
75       //     cfd->Draw();
76       TSpectrum *s = new TSpectrum(2*npeaks,1);
77       Int_t nfound = s->Search(cfd,sigma," ",0.05);
78       cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
79       if(nfound!=0){
80         Float_t *xpeak = s->GetPositionX();
81         TMath::Sort(nfound, xpeak, index,down);
82         Float_t xp = xpeak[index[0]];
83         Int_t xbin = cfd->GetXaxis()->FindBin(xp);
84         Float_t yp = cfd->GetBinContent(xbin);
85         cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[1]<<"\typeak = "<<yp<<endl;
86         Float_t hmax = xp+3*sigma;
87         Float_t hmin = xp-3*sigma;
88         cout<<hmin<< " "<<hmax<<endl;
89         cfd->GetXaxis()->SetRange(hmin-20,hmax+20);
90         //      cout<<" cfd range "<<mean<<" rms "<<rms<<" "<<hmin<<" "<<hmax<<endl;
91         TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
92         //      cfd->Fit("g1","R");
93         cfd->Draw();
94       }
95     }
96  
97 }
98 //------------------------------------------------------------------------
99 void DrawLED()
100 {
101   Int_t npeaks = 10;
102   Int_t sigma=10.;
103   Bool_t down=false;
104   Int_t index[20];
105   
106   TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
107   c1->Divide(4,3);
108   
109   Char_t buf1[20];
110   for (Int_t i=0; i<12; i++)
111     {
112       c1->cd(i+1);
113       sprintf(buf1,"T0_C_%i_LED",i+1);
114       TH1F *cfd = (TH1F*) gFile->Get(buf1);
115       cfd->Draw();
116       TSpectrum *s = new TSpectrum(2*npeaks,1);
117       Int_t nfound = s->Search(cfd,sigma," ",0.2);
118       cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
119       if(nfound!=0) {
120         Float_t *xpeak = s->GetPositionX();
121         TMath::Sort(nfound, xpeak, index,down);
122         Float_t xp = xpeak[index[0]];
123         Int_t xbin = cfd->GetXaxis()->FindBin(xp);
124         Float_t yp = cfd->GetBinContent(xbin);
125         cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[index[0]]<<"\typeak = "<<yp<<endl;
126         Float_t hmin=xp-3*sigma;
127         Float_t hmax =xp+3*sigma;
128         cfd->GetXaxis()->SetRange(hmin,hmax);
129         TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
130         cfd->Fit("g1","R");
131         //      cfd->Draw();
132         
133       }
134       
135     }
136 }
137
138 //------------------------------------------------------------------------
139 void DrawQTC()
140 {
141   
142   TCanvas *c1 = new TCanvas("c1", "QTC",0,48,1280,951);
143   // c1->Divide(4,3);
144   c1->Divide(2,3);
145   
146   Char_t buf1[10];
147   for (Int_t i=0; i<12; i++)
148     {
149       c1->cd(i+1);
150       sprintf(buf1,"QTC%i",i+1);
151       TH1F *qtc = (TH1F*) gFile->Get(buf1);
152       Float_t mean = qtc->GetMean();
153       Float_t rms = qtc->GetRMS();
154       Float_t hminR=mean - 0.1*mean;
155       Float_t hmaxR =mean + 0.1*mean;
156       qtc->GetXaxis()->SetRange(hminR,hmaxR);
157       Float_t hmin=mean - 3*rms;
158       Float_t hmax =mean + 3*rms;
159       qtc->GetXaxis()->SetRange(hmin,hmax);
160       // TF1 *g2 = new TF1("g2", "gaus", hmin, hmax);
161        //             qtc->Fit("g2","RQ");
162        qtc->Draw();
163     }
164   
165   
166 }
167
168 //------------------------------------------------------------------------
169 void DrawLEDminCFD()
170 {
171   Int_t npeaks = 10;
172   Int_t sigma=10.;
173   Bool_t down=false;
174   Int_t index[20];
175   
176   TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
177   c1->Divide(4,3);
178   
179   Char_t buf1[20];
180   for (Int_t i=0; i<12; i++)
181     {
182       c1->cd(i+1);
183       sprintf(buf1,"LED-CFD%i",i+1);
184       TH1F *cfd = (TH1F*) gFile->Get(buf1);
185       cfd->Draw();
186       TSpectrum *s = new TSpectrum(2*npeaks,1);
187       Int_t nfound = s->Search(cfd,sigma," ",0.2);
188       cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
189       if(nfound!=0) {
190         Float_t *xpeak = s->GetPositionX();
191         TMath::Sort(nfound, xpeak, index,down);
192         Float_t xp = xpeak[index[0]];
193         Int_t xbin = cfd->GetXaxis()->FindBin(xp);
194         Float_t yp = cfd->GetBinContent(xbin);
195         cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[index[0]]<<"\typeak = "<<yp<<endl;
196         Float_t hmin=xp-3*sigma;
197         Float_t hmax =xp+3*sigma;
198         cfd->GetXaxis()->SetRange(hmin,hmax);
199         TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
200         cfd->Fit("g1","RQ");
201
202         
203       }
204       
205     }
206   /*
207   TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
208   c1->Divide(2,2);
209   Char_t buf1[10];
210   for (Int_t i=0; i<4; i++)
211     {
212       c1->cd(i+1);
213       sprintf(buf1,"LED-CFD%i",i+1);
214       TH1F *cfd = (TH1F*) file->Get(buf1);
215       //  cout<<buf1<<" "<<cfd<<endl;
216       //     cfd->Draw();
217       //   cfd->GetXaxis()->SetRange(0,100);
218       Float_t mean = cfd->GetMean();
219       Float_t rms = cfd->GetRMS();
220       Float_t hmin=mean - 3*rms;
221       Float_t hmax =mean + 3*rms;
222       cfd->GetXaxis()->SetRange(hmin-10,hmax+10);
223       cout<<" cfd range "<<mean<<" rms "<<rms<<" "<<hmin<<" "<<hmax<<endl;
224       //     TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
225       //  cfd->Fit("g1","RQ");
226       cfd->Draw();
227     }
228   */
229
230 }
231 //------------------------------------------------------------------------
232 void DrawCFDvsQTC()
233 {
234   Int_t npeaks = 20;
235   Int_t sigma=3.;
236   Bool_t down=false;
237
238   Int_t index[20];
239   Char_t buf1[10], buf2[10];
240   
241   TCanvas *c1 = new TCanvas("c1", "c1",0,48,1280,951);
242   gStyle->SetOptStat(0);
243   c1->Divide(3,2);
244   
245   for (Int_t i=0; i<5; i++)
246     {
247       c1->cd(i+1);
248       sprintf(buf1,"T0_C_%i_CFD",i+1);
249       sprintf(buf2,"CFDvsQTC%i",i+1);
250       cout<<buf1<<" "<<buf2<<endl;
251       TH2F *qtc_cfd = (TH2F*) gFile->Get(buf2);
252       TH1F *cfd = (TH1F*) gFile->Get(buf1);
253       //       cfd->Draw();
254       TSpectrum *s = new TSpectrum(2*npeaks,1);
255       Int_t nfound = s->Search(cfd,sigma," ",0.05);
256       cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
257       if(nfound!=0){
258         Float_t *xpeak = s->GetPositionX();
259         TMath::Sort(nfound, xpeak, index,down);
260         Float_t xp = xpeak[index[0]];
261         Int_t xbin = cfd->GetXaxis()->FindBin(xp);
262         Float_t yp = cfd->GetBinContent(xbin);
263         cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[1]<<"\typeak = "<<yp<<endl;
264         Float_t hmax = xp+10*sigma;
265         Float_t hmin = xp-10*sigma;
266         cout<<hmin<< " "<<hmax<<endl;
267         //          cfd->GetXaxis()->SetRange(hmin,hmax);
268         //          TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
269         // cfd->Fit("g1","R");
270         Int_t hminbin=  qtc_cfd->GetXaxis()->GetFirst();
271         Int_t hmaxbin=  qtc_cfd->GetXaxis()->GetLast();
272         Int_t nbins= qtc_cfd->GetXaxis()->GetNbins();
273         cout<<"  qtc_cfd "<<hminbin<<" "<<hmaxbin<<" "<<nbins<<endl;
274         //  qtc_cfd->Draw();
275         TProfile *pr_y = qtc_cfd->ProfileX();
276         
277         pr_y->SetMaximum(hmax);
278         pr_y->SetMinimum(hmin);
279         Int_t np=nbins/20;
280         Double_t *xx = new Double_t[np];
281         Double_t *yy = new Double_t[np];
282         Int_t ng=0;
283         Double_t yg=0;
284         for (Int_t ip=1; ip<nbins; ip++)
285           {
286             if(ip%20 != 0 ) {
287               if (pr_y->GetBinContent(ip) !=0)
288                 yg +=pr_y->GetBinContent(ip);
289               //        cout<<ng<<" "<<pr_y->GetBinContent(ip)<<" "<<yg<<endl;
290               ng++;}
291             else {
292               xx[ip/20] = Float_t (ip);
293               yy[ip/20] = yg/ng;
294               yg=0;
295               ng=0;
296               //              cout<<ip<<" "<<ip/20<<" "<< xx[ip/20]<<" "<< yy[ip/20]<<endl;
297             }
298           }
299         TH2F *hr = new TH2F("hr"," ",np,0,nbins, np, hmin, hmax);
300         hr->Draw();
301         TGraph *gr = new TGraph(np,xx,yy);
302         gr->SetMinimum(hmin);
303         gr->SetMaximum(hmax);
304         gr->SetMarkerStyle(20);
305         gr->Draw("P");
306         //      delete [] xx;
307         //      delete [] yy;
308         
309         // pr_y->Rebin(10);
310                    //  pr_y->Draw();
311             
312       }
313       
314     }
315   
316
317 }
318 //------------------------------------------------------------------------
319 void DrawCFDvsLED()
320 {
321   Int_t runNumber=1098;
322   
323   Int_t npeaks = 20;
324   Int_t sigma=2.;
325   Char_t buf1[10], buf2[10];
326   
327   for (Int_t i=0; i<1; i++)
328     {
329       //   c1->cd(i+1);
330       sprintf(buf1,"T0_C_%i_CFD",i+1);
331       sprintf(buf2,"CFD_LED%i",i+1);
332       
333       TH2F *qtc_cfd = (TH2F*) gFile->Get(buf2);
334       TH1F *cfd = (TH1F*) gFile->Get(buf1);
335       //       cfd->Draw();
336       TSpectrum *s = new TSpectrum(2*npeaks,1);
337       Int_t nfound = s->Search(cfd,sigma," ",0.05);
338       cout<<"Found "<<nfound<<" peaks sigma "<<sigma<<endl;;
339       if(nfound!=0){
340         Double_t max=0.0; 
341         Double_t tabmax[2] = {0.0, 0.0};
342         Float_t *xpeak = s->GetPositionX();
343         for(Int_t k=0; k<1 ;k++)
344           {
345             Float_t xp = xpeak[k];
346             Int_t xbin = cfd->GetXaxis()->FindBin(xp);
347             Float_t yp = cfd->GetBinContent(xbin);
348             cout<<"xbin = "<<xbin<<"\txpeak = "<<xpeak[k]<<"\typeak = "<<yp<<endl;
349           }
350         Float_t hmin=xp-10*sigma;
351         Float_t hmax =xp+10*sigma;
352         cout<<hmin<< " "<<hmax<<endl;
353         //          cfd->GetXaxis()->SetRange(hmin,hmax);
354         //          TF1 *g1 = new TF1("g1", "gaus", hmin, hmax);
355         // cfd->Fit("g1","R");
356         Int_t hminbin=  qtc_cfd->GetXaxis()->GetFirst();
357         Int_t hmaxbin=  qtc_cfd->GetXaxis()->GetLast();
358         Int_t nbins= qtc_cfd->GetXaxis()->GetNbins();
359         cout<<"  qtc_cfd "<<hminbin<<" "<<hmaxbin<<" "<<nbins<<endl;
360         //  qtc_cfd->Draw();
361         TProfile *pr_y = qtc_cfd->ProfileX();
362         
363         pr_y->SetMaximum(hmax);
364         pr_y->SetMinimum(hmin);
365         Int_t np=nbins/20;
366         Double_t *xx = new Double_t[np];
367         Double_t *yy = new Double_t[np];
368         Int_t ng=0;
369         Double_t yg=0;
370         for (Int_t ip=1; ip<nbins; ip++)
371           {
372             if(ip%20 != 0 ) {
373               if (pr_y->GetBinContent(ip) !=0)
374                 yg +=pr_y->GetBinContent(ip);
375               //        cout<<ng<<" "<<pr_y->GetBinContent(ip)<<" "<<yg<<endl;
376               ng++;}
377             else {
378               xx[ip/20] = Float_t (ip);
379               yy[ip/20] = yg/ng;
380               yg=0;
381               ng=0;
382               cout<<ip<<" "<<ip/20<<" "<< xx[ip/20]<<" "<< yy[ip/20]<<endl;
383             }
384           }
385         TH2F *hr = new TH2F("hr"," ",np,0,nbins, np, hmin, hmax);
386         hr->Draw();
387         TGraph *gr = new TGraph(np,xx,yy);
388         gr->SetMinimum(hmin);
389         gr->SetMaximum(hmax);
390         gr->Draw("P");
391         delete [] xx;
392         delete [] yy;
393         
394         // pr_y->Rebin(10);
395         //  pr_y->Draw();
396         
397       }
398       
399     }
400   
401
402 }