]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/ShowCalibrationSDD.C
Treatment of bad SDD half-modules (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 <TStyle.h>
7 #include <TGrid.h>
8 #include <TLine.h>
9 #include <TCanvas.h>
10 #include <TObjArray.h>
11 #include "AliCDBEntry.h"
12 #include "AliITSCalibrationSDD.h"
13 #include "AliITSgeomTGeo.h"
14 #endif
15
16 // Macro to plot the calibration parameters from the OCDB file 
17 // created from PEDESTAL and PULSER runs (OCDB/ITS/Calib/CalibSDD)
18 // Two methods ShowCalibrationSDD:
19 //  - the first takes the name of the file to be displayed
20 //  - the second builds the alien path+name from run number and file version
21 //
22 // Origin: F. Prino (prino@to.infn.it)
23
24 void ShowCalibrationSDD(Int_t iMod=0, Char_t *filnam="$ALICE_ROOT/ITS/Calib/CalibSDD/Run0_9999999_v0_s0.root"){
25
26
27   TFile *f=TFile::Open(filnam);
28   AliCDBEntry *ent=(AliCDBEntry*)f->Get("AliCDBEntry");
29   TH2I* hlay3=new TH2I("hlay3","Layer 3",12,-0.5,5.5,14,-0.5,13.5);
30   hlay3->GetXaxis()->SetTitle("Detector");
31   hlay3->GetYaxis()->SetTitle("Ladder");
32   hlay3->GetXaxis()->SetTickLength(0);
33   hlay3->GetYaxis()->SetTickLength(0);
34   hlay3->SetStats(0);
35   hlay3->SetMinimum(-1);
36   TH2I* hlay4=new TH2I("hlay4","Layer 4",16,-0.5,7.5,22,-0.5,21.5);
37   hlay4->GetXaxis()->SetTitle("Detector");
38   hlay4->GetYaxis()->SetTitle("Ladder");
39   hlay4->GetXaxis()->SetTickLength(0);
40   hlay4->GetYaxis()->SetTickLength(0);
41   hlay4->GetYaxis()->SetTitle("Ladder");
42   hlay4->SetStats(0);
43   hlay4->SetMinimum(-1);
44
45   TObjArray *calSDD = (TObjArray *)ent->GetObject();
46   printf("Entries in array=%d\n",calSDD->GetEntriesFast());
47   TH1F* hmodstatus=new TH1F("hmodstatus","",260,0.5,260.5);
48   TH1F* hnbadch=new TH1F("hnbadch","",260,0.5,260.5);
49   TH1F* hbase=new TH1F("hbase","",60,0.5,120.5);
50   TH1F* hnoise=new TH1F("hnoise","",100,0.,7.);
51   TH1F* hgain=new TH1F("hgain","",100,0.,4.);
52   TH1F* hchstatus=new TH1F("hchstatus","",2,-0.5,1.5);
53   AliITSCalibrationSDD *cal;
54   Int_t badModCounter3=0;
55   Int_t badModCounter4=0;
56   Int_t badAnodeCounter3=0;
57   Int_t badAnodeCounter4=0;
58   Int_t badAnodeCounterGoodMod3=0;
59   Int_t badAnodeCounterGoodMod4=0;
60   Int_t badAnodeCounterGoodModAndChip3=0;
61   Int_t badAnodeCounterGoodModAndChip4=0;
62   Int_t badChipCounter3=0;
63   Int_t badChipCounter4=0;
64   for(Int_t i=0; i<260; i++){
65     cal=(AliITSCalibrationSDD*)calSDD->At(i);
66     if(cal==0) continue;
67     printf("Module %d (%d)   status = ",i,i+240);
68     Int_t lay,lad,det;
69     AliITSgeomTGeo::GetModuleId(i+240,lay,lad,det);
70     Int_t index=1+(det-1)*2;
71     if(cal->IsBad()){ 
72       printf("BAD\t");
73       if(lay==3){ 
74         badModCounter3++;
75         hlay3->SetBinContent(index,lad,0);
76         hlay3->SetBinContent(index+1,lad,0);
77       }else if(lay==4){ 
78         badModCounter4++;
79         hlay4->SetBinContent(index,lad,0);
80         hlay4->SetBinContent(index+1,lad,0);
81       }
82       hmodstatus->SetBinContent(i+1,0);
83     }else{ 
84       printf("OK\t");
85       hmodstatus->SetBinContent(i+1,1);
86       if(lay==3){ 
87         badAnodeCounterGoodMod3+=cal->GetDeadChannels();
88         if(cal->IsChipBad(0) && cal->IsChipBad(1) && cal->IsChipBad(2) && cal->IsChipBad(3)){
89           hlay3->SetBinContent(index,lad,0);
90         }else{
91           hlay3->SetBinContent(index,lad,1);
92         }
93         if(cal->IsChipBad(4) && cal->IsChipBad(5) && cal->IsChipBad(6) && cal->IsChipBad(7)){
94           hlay3->SetBinContent(index+1,lad,0);
95         }else{
96           hlay3->SetBinContent(index+1,lad,1);
97         }
98       }else{ 
99         badAnodeCounterGoodMod4+=cal->GetDeadChannels();
100         if(cal->IsChipBad(0) && cal->IsChipBad(1) && cal->IsChipBad(2) && cal->IsChipBad(3)){
101           hlay4->SetBinContent(index,lad,0);
102         }else{
103           hlay4->SetBinContent(index,lad,1);
104         }
105         if(cal->IsChipBad(4) && cal->IsChipBad(5) && cal->IsChipBad(6) && cal->IsChipBad(7)){
106           hlay4->SetBinContent(index+1,lad,0);
107         }else{
108           hlay4->SetBinContent(index+1,lad,1);
109         }
110       }
111      }
112     printf("   Chip Status (0=OK, 1=BAD): ");  
113     for(Int_t ic=0; ic<8;ic++){ 
114       printf("%d ",cal->IsChipBad(ic));
115       if(cal->IsChipBad(ic) && !cal->IsBad()){ 
116         if(i<84) badChipCounter3++;
117         else badChipCounter4++;
118       }
119     }
120     if(cal->IsAMAt20MHz()) printf("      20 MHz sampling");
121     else printf("      40 MHz sampling");
122     printf("\n");
123     if(i<84) badAnodeCounter3+=cal->GetDeadChannels();
124     else badAnodeCounter4+=cal->GetDeadChannels();
125     hnbadch->SetBinContent(i+1,cal->GetDeadChannels());
126     for(Int_t iAn=0; iAn<512; iAn++){
127       Int_t ic=cal->GetChip(iAn);
128       if(!cal->IsChipBad(ic) && !cal->IsBad() && cal->IsBadChannel(iAn)){ 
129         if(i<84) badAnodeCounterGoodModAndChip3++;
130         else badAnodeCounterGoodModAndChip4++;
131       }
132       Float_t base=cal->GetBaseline(iAn);
133       Float_t noise=cal->GetNoiseAfterElectronics(iAn);
134       Float_t gain=cal->GetChannelGain(iAn);
135       if(cal->IsBadChannel(iAn)) hchstatus->Fill(0);
136       if(!cal->IsBadChannel(iAn) && !cal->IsChipBad(ic) && !cal->IsBad() ){
137         hbase->Fill(base);
138         hchstatus->Fill(1);
139         hnoise->Fill(noise);
140         hgain->Fill(gain);
141       }
142     }
143   }
144   Int_t totbad3=badModCounter3*512+badChipCounter3*64+badAnodeCounterGoodModAndChip3;
145   Int_t tot3=6*14*512;
146   Float_t fracbad3=(Float_t)totbad3/(Float_t)tot3;
147   Int_t totbad4=badModCounter4*512+badChipCounter4*64+badAnodeCounterGoodModAndChip4;
148   Int_t tot4=8*22*512;
149   Float_t fracbad4=(Float_t)totbad4/(Float_t)tot4;
150   Float_t fractot=(Float_t)(totbad3+totbad4)/(Float_t)(tot3+tot4);
151   printf("----------------------Summary----------------------\n");
152   printf("---- Layer 3 ----\n");
153   printf("# of bad modules                      = %d\n",badModCounter3);
154   printf("# of bad chips in good modules        = %d\n",badChipCounter3);
155   printf("# of bad anodes in good modules+chips = %d\n",badAnodeCounterGoodModAndChip3);
156   printf("Fraction of bads (anodes+chips+mod)   = %f\n",fracbad3);
157   printf("---- Layer 4 ----\n");
158   printf("# of bad modules                      = %d\n",badModCounter4);
159   printf("# of bad chips in good modules        = %d\n",badChipCounter4);
160   printf("# of bad anodes in good modules+chips = %d\n",badAnodeCounterGoodModAndChip4);
161   printf("Fraction of bads (anodes+chips+mod)   = %f\n",fracbad4);
162   printf("---- Total   ----\n");
163   printf("# of bad modules                      = %d\n",badModCounter3+badModCounter4);
164   printf("# of bad chips in good modules        = %d\n",badChipCounter3+badChipCounter4);
165   printf("# of bad anodes in good modules+chips = %d\n",badAnodeCounterGoodModAndChip3+badAnodeCounterGoodModAndChip4);
166   printf("Fraction of bads (anodes+chips+mod)   = %f\n",fractot);
167   printf("---------------------------------------------------\n");
168   
169
170   TCanvas *c0=new TCanvas("c0","Module status",800,800);
171   c0->Divide(1,2);
172   c0->cd(1);
173   hmodstatus->Draw();
174   hmodstatus->GetXaxis()->SetTitle("Module number");
175   hmodstatus->GetYaxis()->SetTitle("Module status (1=OK, 0=BAD)");
176   c0->cd(2);
177   hnbadch->Draw();
178   hnbadch->GetXaxis()->SetTitle("Module number");
179   hnbadch->GetYaxis()->SetTitle("Number of bad anodes");
180
181   TCanvas *c1=new TCanvas("c1","Anode calibration",800,800);
182   c1->Divide(2,2);
183   c1->cd(1);
184   hbase->Draw();
185   hbase->GetXaxis()->SetTitle("Baseline after equalization");
186   hbase->GetXaxis()->CenterTitle();  
187   c1->cd(2);
188   hnoise->Draw(); 
189   hnoise->GetXaxis()->SetTitle("Noise");
190   hnoise->GetXaxis()->CenterTitle();  
191   c1->cd(3);
192   hgain->Draw();
193   hgain->GetXaxis()->SetTitle("Gain");
194   hgain->GetXaxis()->CenterTitle();  
195   c1->cd(4);
196   hchstatus->Draw();
197   hchstatus->GetXaxis()->SetTitle("Anode status (0=bad, 1=OK)");
198   hchstatus->GetXaxis()->CenterTitle();
199   Int_t palette[3]={kGray,2,3};
200   gStyle->SetPalette(3,palette);
201   
202   TLine* lin=new TLine(0,0,0,23);  
203   TCanvas* clay=new TCanvas("clay","Layer status",900,600);
204   clay->Divide(2,1);
205   clay->cd(1);
206   hlay3->Draw("col");
207   for(Int_t i=0;i<6;i++){
208     lin->SetY1(-0.5);
209     lin->SetY2(13.5);
210     lin->SetX1(i+0.5);
211     lin->SetX2(i+0.5);
212     lin->DrawClone();
213   }
214   for(Int_t i=0;i<14;i++){
215     lin->SetX1(-0.5);
216     lin->SetX2(5.5);
217     lin->SetY1(i+0.5);
218     lin->SetY2(i+0.5);
219     lin->DrawClone();
220   }
221   clay->cd(2);
222   hlay4->Draw("col");
223   for(Int_t i=0;i<8;i++){
224     lin->SetY1(-0.5);
225     lin->SetY2(21.5);
226     lin->SetX1(i+0.5);
227     lin->SetX2(i+0.5);
228     lin->DrawClone();
229   }
230   for(Int_t i=0;i<22;i++){
231     lin->SetX1(-0.5);
232     lin->SetX2(7.5);
233     lin->SetY1(i+0.5);
234     lin->SetY2(i+0.5);
235     lin->DrawClone();
236   }
237
238
239
240
241   // Plot quantities for specified module
242
243   cal=(AliITSCalibrationSDD*)calSDD->At(iMod);
244   if(cal==0) return;
245   printf("-----------------------------------\n");
246   printf("Module %d    status = ",iMod);
247   if(cal->IsBad()) printf("BAD\n");
248   else printf("OK\n");
249   printf("   Chip Status (0=OK, 1=BAD): ");  
250   for(Int_t ic=0; ic<8;ic++) printf("%d ",cal->IsChipBad(ic));
251   printf("\n");
252   printf("   Number of bad anodes =%d\n",cal->GetDeadChannels());
253   printf("-----------------------------------\n");
254   Int_t ipt=0;
255   TGraph *gbad=new TGraph(0);
256   gbad->SetTitle("Bad Channels");
257   TGraph *gbase=new TGraph(0);
258   gbase->SetTitle("Baselines");
259   TGraph *gnoi=new TGraph(0);
260   gnoi->SetTitle("Noise");
261   TGraph *ggain=new TGraph(0);
262   ggain->SetTitle("Gain");
263   for(Int_t iAn=0; iAn<512; iAn++){
264     Float_t bad=1;
265     if(cal->IsBadChannel(iAn)) bad=0;
266     Float_t base=cal->GetBaseline(iAn);
267     Float_t noise=cal->GetNoiseAfterElectronics(iAn);
268     Float_t gain=cal->GetChannelGain(iAn);
269     gbad->SetPoint(ipt,(Float_t)iAn,bad);
270     gbase->SetPoint(ipt,(Float_t)iAn,base);
271     ggain->SetPoint(ipt,(Float_t)iAn,gain);
272     gnoi->SetPoint(ipt,(Float_t)iAn,noise);
273     ipt++;
274   }
275   Char_t ctit[100];
276   sprintf(ctit,"Module %d",iMod);
277
278   TCanvas *c2=new TCanvas("c2",ctit,1200,800);
279   c2->Divide(2,2);
280   
281   c2->cd(1);
282   gbase->SetMarkerStyle(7);
283   gbase->Draw("AP");
284   gbase->GetXaxis()->SetTitle("Anode Number");
285   gbase->GetYaxis()->SetTitle("Baseline after equalization");  
286   c2->cd(2);
287   gnoi->SetMarkerStyle(7);
288   gnoi->Draw("AP");
289   gnoi->GetXaxis()->SetTitle("Anode Number");
290   gnoi->GetYaxis()->SetTitle("Noise");  
291   c2->cd(3);
292   ggain->SetMarkerStyle(7);
293   ggain->Draw("AP");
294   ggain->GetXaxis()->SetTitle("Anode Number");
295   ggain->GetYaxis()->SetTitle("Gain");
296   c2->cd(4);
297   gbad->SetMarkerStyle(7);
298   gbad->Draw("AP");
299   gbad->SetMinimum(-0.1);
300   gbad->GetXaxis()->SetTitle("Anode Number");
301   gbad->GetYaxis()->SetTitle("Anode Status (1=OK, 0=bad)");
302 }
303
304 void ShowCalibrationSDD(Int_t nrun, Int_t nv, Int_t year=2009, Int_t nmod=0){
305   TGrid::Connect("alien:",0,0,"t");
306   Char_t filnam[200];
307   sprintf(filnam,"alien:///alice/data/%d/OCDB/ITS/Calib/CalibSDD/Run%d_999999999_v%d_s0.root",year,nrun,nv);
308   printf("Open file: %s\n",filnam);
309   ShowCalibrationSDD(nmod,filnam);
310 }