]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/ShowCalibrationSDD.C
Added plots in macros for SDD calibration monitoring (F. Prino)
[u/mrichter/AliRoot.git] / ITS / ShowCalibrationSDD.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TFile.h>
3 #include <TH1F.h>
4 #include <TH2I.h>
5 #include <TGraph.h>
6 #include <TExec.h>
7 #include <TStyle.h>
8 #include <TString.h>
9 #include <TSystem.h>
10 #include <TGrid.h>
11 #include <TLine.h>
12 #include <TCanvas.h>
13 #include <TObjArray.h>
14 #include "AliCDBEntry.h"
15 #include "AliITSCalibrationSDD.h"
16 #include "AliITSgeomTGeo.h"
17 #endif
18
19 // Macro to plot the calibration parameters from the OCDB file 
20 // created from PEDESTAL and PULSER runs (OCDB/ITS/Calib/CalibSDD)
21 // Two methods ShowCalibrationSDD:
22 //  - the first takes the name of the file to be displayed
23 //  - the second builds the alien path+name from run number and file version
24 //
25 // Origin: F. Prino (prino@to.infn.it)
26
27 void MakePalette(){
28   Int_t palette[3]={kGray,2,3};  
29   gStyle->SetPalette(3,palette);
30 }
31
32 void ShowCalibrationSDD(Char_t *filnam="$ALICE_ROOT/OCDB/ITS/Calib/CalibSDD/Run0_9999999_v0_s0.root", Int_t iMod=0){
33
34
35   TFile *f=TFile::Open(filnam);
36   AliCDBEntry *ent=(AliCDBEntry*)f->Get("AliCDBEntry");
37   TH2I* hlay3=new TH2I("hlay3","Layer 3",12,-0.5,5.5,14,-0.5,13.5);
38   hlay3->GetXaxis()->SetTitle("Detector");
39   hlay3->GetYaxis()->SetTitle("Ladder");
40   hlay3->GetXaxis()->SetTickLength(0);
41   hlay3->GetYaxis()->SetTickLength(0);
42   hlay3->SetStats(0);
43   hlay3->SetMinimum(-1);
44   TH2I* hlay4=new TH2I("hlay4","Layer 4",16,-0.5,7.5,22,-0.5,21.5);
45   hlay4->GetXaxis()->SetTitle("Detector");
46   hlay4->GetYaxis()->SetTitle("Ladder");
47   hlay4->GetXaxis()->SetTickLength(0);
48   hlay4->GetYaxis()->SetTickLength(0);
49   hlay4->GetYaxis()->SetTitle("Ladder");
50   hlay4->SetStats(0);
51   hlay4->SetMinimum(-1);
52   TH2I* hdeadlay3=new TH2I("hdlay3","Layer 3",6,-0.5,5.5,14,-0.5,13.5);
53   hdeadlay3->GetXaxis()->SetTitle("Detector");
54   hdeadlay3->GetYaxis()->SetTitle("Ladder");
55   hdeadlay3->GetXaxis()->SetTickLength(0);
56   hdeadlay3->GetYaxis()->SetTickLength(0);
57   hdeadlay3->SetStats(0);
58   hdeadlay3->SetMinimum(-1.);
59   TH2I* hdeadlay4=new TH2I("hdlay4","Layer 4",8,-0.5,7.5,22,-0.5,21.5);
60   hdeadlay4->GetXaxis()->SetTitle("Detector");
61   hdeadlay4->GetYaxis()->SetTitle("Ladder");
62   hdeadlay4->GetXaxis()->SetTickLength(0);
63   hdeadlay4->GetYaxis()->SetTickLength(0);
64   hdeadlay4->GetYaxis()->SetTitle("Ladder");
65   hdeadlay4->SetStats(0);
66   hdeadlay4->SetMinimum(-1.);
67
68   TObjArray *calSDD = (TObjArray *)ent->GetObject();
69   printf("Entries in array=%d\n",calSDD->GetEntriesFast());
70   TH1F* hmodstatus=new TH1F("hmodstatus","",260,0.5,260.5);
71   TH1F* hnbadch=new TH1F("hnbadch","",260,0.5,260.5);
72   TH1F* hbase=new TH1F("hbase","",60,0.5,120.5);
73   TH2F* hbasemod=new TH2F("hbasemod","",260,239.5,499.5,50,0.,100.);
74   TH1F* hnoise=new TH1F("hnoise","",100,0.,7.);
75   TH2F* hnoisemod=new TH2F("hnoisemod","",260,239.5,499.5,50,0.,10.);
76   TH1F* hgain=new TH1F("hgain","",100,0.,4.);
77   TH2F* hgainmod=new TH2F("hgainmod","",260,239.5,499.5,50,0.,4.);
78   TH1F* hchstatus=new TH1F("hchstatus","",2,-0.5,1.5);
79
80
81   AliITSCalibrationSDD *cal;
82   Int_t badModCounter3=0;
83   Int_t badModCounter4=0;
84   Int_t badAnodeCounter3=0;
85   Int_t badAnodeCounter4=0;
86   Int_t badAnodeCounterGoodMod3=0;
87   Int_t badAnodeCounterGoodMod4=0;
88   Int_t badAnodeCounterGoodModAndChip3=0;
89   Int_t badAnodeCounterGoodModAndChip4=0;
90   Int_t badChipCounter3=0;
91   Int_t badChipCounter4=0;
92   for(Int_t i=0; i<260; i++){
93     cal=(AliITSCalibrationSDD*)calSDD->At(i);
94     if(cal==0) continue;
95     printf("Module %d (%d)   status = ",i,i+240);
96     Int_t lay,lad,det;
97     AliITSgeomTGeo::GetModuleId(i+240,lay,lad,det);
98     Int_t index=1+(det-1)*2;
99     if(cal->IsBad()){ 
100       printf("BAD\t");
101       if(lay==3){ 
102         badModCounter3++;
103         hlay3->SetBinContent(index,lad,0);
104         hlay3->SetBinContent(index+1,lad,0);
105       }else if(lay==4){ 
106         badModCounter4++;
107         hlay4->SetBinContent(index,lad,0);
108         hlay4->SetBinContent(index+1,lad,0);
109       }
110       hmodstatus->SetBinContent(i+1,0);
111     }else{ 
112       printf("OK\t");
113       hmodstatus->SetBinContent(i+1,1);
114       if(lay==3){ 
115         badAnodeCounterGoodMod3+=cal->GetDeadChannels();
116         if(cal->IsChipBad(0) && cal->IsChipBad(1) && cal->IsChipBad(2) && cal->IsChipBad(3)){
117           hlay3->SetBinContent(index,lad,0);
118         }else{
119           hlay3->SetBinContent(index,lad,1);
120         }
121         if(cal->IsChipBad(4) && cal->IsChipBad(5) && cal->IsChipBad(6) && cal->IsChipBad(7)){
122           hlay3->SetBinContent(index+1,lad,0);
123         }else{
124           hlay3->SetBinContent(index+1,lad,1);
125         }
126       }else{ 
127         badAnodeCounterGoodMod4+=cal->GetDeadChannels();
128         if(cal->IsChipBad(0) && cal->IsChipBad(1) && cal->IsChipBad(2) && cal->IsChipBad(3)){
129           hlay4->SetBinContent(index,lad,0);
130         }else{
131           hlay4->SetBinContent(index,lad,1);
132         }
133         if(cal->IsChipBad(4) && cal->IsChipBad(5) && cal->IsChipBad(6) && cal->IsChipBad(7)){
134           hlay4->SetBinContent(index+1,lad,0);
135         }else{
136           hlay4->SetBinContent(index+1,lad,1);
137         }
138       }
139      }
140     printf("   Chip Status (0=OK, 1=BAD): ");  
141     for(Int_t ic=0; ic<8;ic++){ 
142       printf("%d ",cal->IsChipBad(ic));
143       if(cal->IsChipBad(ic) && !cal->IsBad()){ 
144         if(i<84) badChipCounter3++;
145         else badChipCounter4++;
146       }
147     }
148     printf(" # bad anodes = %d  ",cal->GetDeadChannels());
149     if(cal->IsAMAt20MHz()) printf("      20 MHz sampling");
150     else printf("      40 MHz sampling");
151     printf(" Threshold L %d %d H %d %d\n",cal->GetZSLowThreshold(0),cal->GetZSLowThreshold(1),cal->GetZSHighThreshold(0),cal->GetZSHighThreshold(1));
152     if(i<84) badAnodeCounter3+=cal->GetDeadChannels();
153     else badAnodeCounter4+=cal->GetDeadChannels();
154     hnbadch->SetBinContent(i+1,cal->GetDeadChannels());
155     if(lay==3) hdeadlay3->SetBinContent(det,lad,cal->GetDeadChannels());
156     if(lay==4) hdeadlay4->SetBinContent(det,lad,cal->GetDeadChannels());
157     for(Int_t iAn=0; iAn<512; iAn++){
158       Int_t ic=cal->GetChip(iAn);
159       if(!cal->IsChipBad(ic) && !cal->IsBad() && cal->IsBadChannel(iAn)){ 
160         if(i<84) badAnodeCounterGoodModAndChip3++;
161         else badAnodeCounterGoodModAndChip4++;
162       }
163       Float_t base=cal->GetBaseline(iAn);
164       Float_t noise=cal->GetNoiseAfterElectronics(iAn);
165       Float_t gain=cal->GetChannelGain(iAn);
166       if(cal->IsBadChannel(iAn)) hchstatus->Fill(0);
167       if(!cal->IsBadChannel(iAn) && !cal->IsChipBad(ic) && !cal->IsBad() ){
168         hbase->Fill(base);
169         hbasemod->Fill(i+240,base);
170         hchstatus->Fill(1);
171         hnoise->Fill(noise);
172         hnoisemod->Fill(i+240,noise);
173         hgain->Fill(gain);
174         hgainmod->Fill(i+240,gain);
175       }
176     }
177   }
178   Int_t totbad3=badModCounter3*512+badChipCounter3*64+badAnodeCounterGoodModAndChip3;
179   Int_t tot3=6*14*512;
180   Float_t fracbad3=(Float_t)totbad3/(Float_t)tot3;
181   Float_t fracgm3=(Float_t)(84.-badModCounter3)/84.;
182   Float_t fracgm4=(Float_t)(176.-badModCounter4)/176.;
183   Float_t fraccgm3=1.-(Float_t)(badAnodeCounterGoodModAndChip3+badChipCounter3*64)/(512.*(Float_t)(84.-badModCounter3));
184   Float_t fraccgm4=1.-(Float_t)(badAnodeCounterGoodModAndChip4+badChipCounter4*64)/(512.*(Float_t)(176.-badModCounter4));
185   Int_t totbad4=badModCounter4*512+badChipCounter4*64+badAnodeCounterGoodModAndChip4;
186   Int_t tot4=8*22*512;
187   Float_t fracbad4=(Float_t)totbad4/(Float_t)tot4;
188   Float_t fractot=(Float_t)(totbad3+totbad4)/(Float_t)(tot3+tot4);
189   printf("----------------------Summary----------------------\n");
190   printf("---- Layer 3 ----\n");
191   printf("# of bad modules                      = %d\n",badModCounter3);
192   printf("# of bad chips in good modules        = %d\n",badChipCounter3);
193   printf("# of bad anodes in good modules+chips = %d\n",badAnodeCounterGoodModAndChip3);
194   printf("Fraction of Good modules=%f\n",fracgm3);
195   printf("Fraction of good anodes in good modules+chips = %f\n",fraccgm3);
196   printf("Fraction of bads (anodes+chips+mod)   = %f\n",fracbad3);
197   printf("---- Layer 4 ----\n");
198   printf("# of bad modules                      = %d\n",badModCounter4);
199   printf("# of bad chips in good modules        = %d\n",badChipCounter4);
200   printf("# of bad anodes in good modules+chips = %d\n",badAnodeCounterGoodModAndChip4);
201   printf("Fraction of Good modules=%f\n",fracgm4);
202   printf("Fraction of good anodes in good modules+chips = %f\n",fraccgm4);
203   printf("Fraction of bads (anodes+chips+mod)   = %f\n",fracbad4);
204   printf("---- Total   ----\n");
205   printf("# of bad modules                      = %d\n",badModCounter3+badModCounter4);
206   printf("# of bad chips in good modules        = %d\n",badChipCounter3+badChipCounter4);
207   printf("# of bad anodes in good modules+chips = %d\n",badAnodeCounterGoodModAndChip3+badAnodeCounterGoodModAndChip4);
208   printf("Fraction of bads (anodes+chips+mod)   = %f\n",fractot);
209   printf("---------------------------------------------------\n");
210   
211
212   TLine* lin=new TLine(0,0,0,23);  
213   TExec *ex1 = new TExec("ex1","MakePalette();");
214   TExec *ex2 = new TExec("ex2","gStyle->SetPalette(1);");
215
216   TCanvas* clay=new TCanvas("clay","Layer status",900,600);
217   clay->Divide(2,1);
218   clay->cd(1);
219   hlay3->Draw("col");
220   ex1->Draw();
221   hlay3->DrawCopy("col same");
222   for(Int_t i=0;i<6;i++){
223     lin->SetY1(-0.5);
224     lin->SetY2(13.5);
225     lin->SetX1(i+0.5);
226     lin->SetX2(i+0.5);
227     lin->DrawClone();
228   }
229   for(Int_t i=0;i<14;i++){
230     lin->SetX1(-0.5);
231     lin->SetX2(5.5);
232     lin->SetY1(i+0.5);
233     lin->SetY2(i+0.5);
234     lin->DrawClone();
235   }
236   clay->cd(2);
237   hlay4->DrawCopy("col");
238   for(Int_t i=0;i<8;i++){
239     lin->SetY1(-0.5);
240     lin->SetY2(21.5);
241     lin->SetX1(i+0.5);
242     lin->SetX2(i+0.5);
243     lin->DrawClone();
244   }
245   for(Int_t i=0;i<22;i++){
246     lin->SetX1(-0.5);
247     lin->SetX2(7.5);
248     lin->SetY1(i+0.5);
249     lin->SetY2(i+0.5);
250     lin->DrawClone();
251   }
252
253
254
255
256   TCanvas *c0b=new TCanvas("c0b","Bad Channels",900,600);
257   c0b->Divide(2,1);
258   c0b->cd(1);
259   hdeadlay3->DrawCopy("colz");
260   ex2->Draw();
261   hdeadlay3->DrawCopy("colz same");
262   for(Int_t i=0;i<6;i++){
263     lin->SetY1(-0.5);
264     lin->SetY2(13.5);
265     lin->SetX1(i+0.5);
266     lin->SetX2(i+0.5);
267     lin->DrawClone();
268   }
269   for(Int_t i=0;i<14;i++){
270     lin->SetX1(-0.5);
271     lin->SetX2(5.5);
272     lin->SetY1(i+0.5);
273     lin->SetY2(i+0.5);
274     lin->DrawClone();
275   }
276   c0b->cd(2);
277   hdeadlay4->DrawCopy("colz");
278   ex2->Draw();
279   hdeadlay4->DrawCopy("colz same");
280   for(Int_t i=0;i<8;i++){
281     lin->SetY1(-0.5);
282     lin->SetY2(21.5);
283     lin->SetX1(i+0.5);
284     lin->SetX2(i+0.5);
285     lin->DrawClone();
286   }
287   for(Int_t i=0;i<22;i++){
288     lin->SetX1(-0.5);
289     lin->SetX2(7.5);
290     lin->SetY1(i+0.5);
291     lin->SetY2(i+0.5);
292     lin->DrawClone();
293   }
294
295
296   
297   TCanvas *c1=new TCanvas("c1","Anode calibration",800,800);
298   c1->Divide(2,2);
299   c1->cd(1);
300   hbase->Draw();
301   hbase->GetXaxis()->SetTitle("Baseline after equalization");
302   hbase->GetXaxis()->CenterTitle();  
303   c1->cd(2);
304   hnoise->Draw(); 
305   hnoise->GetXaxis()->SetTitle("Noise");
306   hnoise->GetXaxis()->CenterTitle();  
307   c1->cd(3);
308   hgain->Draw();
309   hgain->GetXaxis()->SetTitle("Gain");
310   hgain->GetXaxis()->CenterTitle();  
311   c1->cd(4);
312   hchstatus->Draw();
313   hchstatus->GetXaxis()->SetTitle("Anode status (0=bad, 1=OK)");
314   hchstatus->GetXaxis()->CenterTitle();
315
316   TCanvas *c1m=new TCanvas("c1m","Calib. vs. mod",1000,800);
317   c1m->Divide(2,2);
318   c1m->cd(1);
319   gPad->SetRightMargin(0.14);
320   hbasemod->SetStats(0);
321   hbasemod->Draw("colz"); 
322   hbasemod->GetXaxis()->SetTitle("Module Number");
323   hbasemod->GetYaxis()->SetTitle("Baseline");
324   c1m->cd(2);
325   gPad->SetRightMargin(0.14);
326   hnoisemod->SetStats(0);
327   hnoisemod->Draw("colz"); 
328   hnoisemod->GetXaxis()->SetTitle("Module Number");
329   hnoisemod->GetYaxis()->SetTitle("Noise");
330   c1m->cd(3);
331   gPad->SetRightMargin(0.14);
332   hgainmod->SetStats(0);
333   hgainmod->Draw("colz");
334   hgainmod->GetXaxis()->SetTitle("Module Number");
335   hgainmod->GetYaxis()->SetTitle("Gain");
336   c1m->cd(4);
337   hnbadch->Scale(1/512.);
338   hnbadch->SetMarkerStyle(20);
339   hnbadch->SetMarkerSize(0.8);
340   hnbadch->SetStats(0);
341   hnbadch->Draw("P");
342   hnbadch->GetXaxis()->SetTitle("Module number");   
343   hnbadch->GetYaxis()->SetTitle("Fraction of bad anodes");
344
345
346
347
348
349
350
351
352   // Plot quantities for specified module
353
354   cal=(AliITSCalibrationSDD*)calSDD->At(iMod);
355   if(cal==0) return;
356   printf("-----------------------------------\n");
357   printf("Module %d    status = ",iMod);
358   if(cal->IsBad()) printf("BAD\n");
359   else printf("OK\n");
360   printf("   Chip Status (0=OK, 1=BAD): ");  
361   for(Int_t ic=0; ic<8;ic++) printf("%d ",cal->IsChipBad(ic));
362   printf("\n");
363   printf("   Number of bad anodes =%d\n",cal->GetDeadChannels());
364   printf("-----------------------------------\n");
365   Int_t ipt=0;
366   TGraph *gbad=new TGraph(0);
367   gbad->SetTitle("Bad Channels");
368   TGraph *gbase=new TGraph(0);
369   gbase->SetTitle("Baselines");
370   TGraph *gnoi=new TGraph(0);
371   gnoi->SetTitle("Noise");
372   TGraph *ggain=new TGraph(0);
373   ggain->SetTitle("Gain");
374   for(Int_t iAn=0; iAn<512; iAn++){
375     Float_t bad=1;
376     if(cal->IsBadChannel(iAn)) bad=0;
377     Float_t base=cal->GetBaseline(iAn);
378     Float_t noise=cal->GetNoiseAfterElectronics(iAn);
379     Float_t gain=cal->GetChannelGain(iAn);
380     gbad->SetPoint(ipt,(Float_t)iAn,bad);
381     gbase->SetPoint(ipt,(Float_t)iAn,base);
382     ggain->SetPoint(ipt,(Float_t)iAn,gain);
383     gnoi->SetPoint(ipt,(Float_t)iAn,noise);
384     ipt++;
385   }
386   Char_t ctit[100];
387   sprintf(ctit,"Module %d",iMod);
388
389   TCanvas *c2=new TCanvas("c2",ctit,1200,800);
390   c2->Divide(2,2);
391   
392   c2->cd(1);
393   gbase->SetMarkerStyle(7);
394   gbase->Draw("AP");
395   gbase->GetXaxis()->SetTitle("Anode Number");
396   gbase->GetYaxis()->SetTitle("Baseline after equalization");  
397   c2->cd(2);
398   gnoi->SetMarkerStyle(7);
399   gnoi->Draw("AP");
400   gnoi->GetXaxis()->SetTitle("Anode Number");
401   gnoi->GetYaxis()->SetTitle("Noise");  
402   c2->cd(3);
403   ggain->SetMarkerStyle(7);
404   ggain->Draw("AP");
405   ggain->GetXaxis()->SetTitle("Anode Number");
406   ggain->GetYaxis()->SetTitle("Gain");
407   c2->cd(4);
408   gbad->SetMarkerStyle(7);
409   gbad->Draw("AP");
410   gbad->SetMinimum(-0.1);
411   gbad->GetXaxis()->SetTitle("Anode Number");
412   gbad->GetYaxis()->SetTitle("Anode Status (1=OK, 0=bad)");
413 }
414
415 void ShowCalibrationSDD(Int_t nrun, Int_t year=2010, Int_t nmod=0){
416   TGrid::Connect("alien:",0,0,"t");
417   TString cmd=Form("gbbox find \"/alice/data/%d/OCDB/ITS/Calib/CalibSDD\" \"Run%d*.root\" > run.txt",year,nrun);
418   gSystem->Exec(cmd.Data());
419   Char_t filnam[200],filnamalien[200];
420   FILE* runtxt=fopen("run.txt","r");
421   fscanf(runtxt,"%s\n",filnam);    
422   if(!strstr(filnam,"/alice/data/")){
423     printf("Bad run number\n");
424     gSystem->Exec("rm run.txt");
425     return;
426   }  
427   sprintf(filnamalien,"alien://%s",filnam);
428   
429   printf("Open file: %s\n",filnamalien);
430   ShowCalibrationSDD(filnamalien,nmod);
431   fclose(runtxt);
432   gSystem->Exec("rm run.txt");
433 }