]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/HplotDA.C
Adding AliTPCcalibV0 to the Makefile (Marian)
[u/mrichter/AliRoot.git] / HMPID / HplotDA.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2
3 #include <Riostream.h>     
4
5 #include <TSystem.h>
6 #include <TCanvas.h>
7 #include <TStyle.h>
8 #include <TH2F.h>
9 #include <TH1F.h>
10 #include <TH1I.h>
11
12 #include "AliHMPIDDigit.h"
13 #include "AliHMPIDRawStream.h"
14
15 #endif
16
17
18
19 TH2F hgPedMapMean[14][6]; 
20 TH2F hgPedMapSigma[14][6];
21 TH1F hgPedMapMean1D[14][6]; 
22 TH1F hgPedMapSigma1D[14][6]; 
23 TH1F hgPedMapSigma1Db[14][6]; 
24
25
26 TH1I hgDdlErr[14];
27 TH1I *hgtmp,*hgtmp2;
28
29
30 Int_t fgRunNum;
31 TFile *fgin[14];
32 TFile *fgout=0x0;
33
34 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++      
35 void Convert(Int_t ddl,Int_t r,Int_t d,Int_t a,Int_t &ch, Int_t &pc, Int_t &px, Int_t &py)
36 {
37  
38   
39   Int_t a2y[6]={3,2,4,1,5,0};//pady for a given address (for single DILOGIC chip)
40   
41   Int_t ch=ddl/2;
42   Int_t tmp=(24-r)/8;              Int_t pc=(ddl%2)? 5-2*tmp:2*tmp; 
43                                   Int_t px=(d-1)*8+a/6;
44         tmp=(ddl%2)?r-1:(24-r);   Int_t py=6*(tmp%8)+a2y[a%6];
45 }
46 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
47 void PlotPedHisto(Char_t *tag,Int_t runNum, Int_t ddl=0,Int_t row=1,Int_t dil=1,Int_t pad=0)
48 {
49  
50   if( 0<=ddl && ddl<=13 && 1<=dil && dil<=10 && 1<=row && row<=24 && 0<=pad && pad<=47) 
51   { 
52  
53   fgin[ddl]->cd();
54   
55   hgtmp=(TH1I*)(fgin[ddl]->Get(Form("hDDL_%d_Row_%d_Dil_%d_Pad_%d",ddl,row,dil,pad)))->Clone();
56   hgtmp2=(TH1I*)(fgin[ddl]->Get(Form("hDDL_%d_Row_%d_Dil_%d_Pad_%d",ddl,row,dil,pad)))->Clone();
57   
58   TCanvas *c1=new TCanvas(Form("hDDL%s_%d_Row_%d_Dil_%d_Pad_%d",tag,ddl,row,dil,pad),Form("hDDL%s_%d_Row_%d_Dil_%d_Pad_%d",tag,ddl,row,dil,pad));
59   
60   hgtmp->SetXTitle("ADC");
61   hgtmp->SetYTitle("Entries");
62   hgtmp->Draw();
63   hgtmp->SetAxisRange(0,350);
64   hgtmp->Draw("hist same");
65   hgtmp2->SetFillColor(5);
66   hgtmp2->Draw("hist same");
67   hgtmp->Draw("same");
68   
69   c1->SaveAs(Form("hDDL%s_%d_Row_%d_Dil_%d_Pad_%d.eps",tag,ddl,row,dil,pad));
70   c1->SaveAs(Form("hDDL%s_%d_Row_%d_Dil_%d_Pad_%d.gif",tag,ddl,row,dil,pad));
71   
72   if(fgout!=0x0) 
73   {
74     fgout->cd();
75     hgtmp2->Write();  
76   }
77   
78   hgtmp->Reset();
79   hgtmp2->Reset();
80   
81   }
82   else 
83   {
84    if( ddl < 0 || ddl > 13) {Printf("Not a valid DDL, exiting %d ...",ddl); } 
85    if( dil < 1 || dil > 10) {Printf("Not a valid DIL, exiting %d ...",dil); } 
86    if( row < 1 || row > 24) {Printf("Not a valid ROW, exiting %d ...",row); } 
87    if( pad < 0 || pad > 48) {Printf("Not a valid PAD, exiting %d ...",pad); } 
88   }   
89 }
90 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
91 void PlotHisto1D(TH1& hin,Char_t* name)
92 {
93   TCanvas *c1=new TCanvas("c1","c1");
94   hin.Draw();
95   c1->SaveAs(Form("%s.eps",name));
96   c1->SaveAs(Form("%s.gif",name));  
97 }
98 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99 void PlotHisto2D(TH2 &hin,Char_t* name,Char_t* opt)
100 {
101  TCanvas *c1=new TCanvas("c1","c1");
102  hin.Draw(opt);
103  c1->SaveAs(Form("%s.eps",name));
104  c1->SaveAs(Form("%s.gif",name));  
105 }
106 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 void ProcPed(Int_t nDDL,Int_t mode)
108 {
109
110     if(gSystem->IsFileInIncludePath(Form("./HmpidPedDdl%02i.txt",nDDL)))
111           ifstream infile(Form("./HmpidPedDdl%02i.txt",nDDL));
112     else return;
113     if(mode==1) {
114     for(Int_t ni=0;ni<6;ni++)
115       {
116         hgPedMapMean[nDDL][ni]  = new TH2F(Form("hPedMapMean_DDL%d_PC_%d" ,nDDL,ni),         Form("Pedestal: Mean, DDL(0-13): %d PC(0-5): %d;padx;pady" ,nDDL,ni),80,0,80,48,0,48);
117         hgPedMapSigma[nDDL][ni] = new TH2F(Form("hPedMapSigma_DDL%d_PC_%d",nDDL,ni),         Form("Pedestal: Sigma, DDL(0-13): %d PC(0-5): %d;padx;pady",nDDL,ni),80,0,80,48,0,48);
118         hgPedMapMean1D[nDDL][ni]  = new TH1F(Form("hPedMapMean1D_DDL%d_PC_%d" ,nDDL,ni),     Form("Pedestal: Mean, DDL(0-13): %d PC(0-5): %d;pad;Mean" ,nDDL,ni),3841,-0.5,3840.5);
119         hgPedMapSigma1D[nDDL][ni]  = new TH1F(Form("hPedMapSigma1D_DDL%d_PC_%d" ,nDDL,ni),   Form("Pedestal: Sigma, DDL(0-13): %d PC(0-5): %d;pad;Sigma" ,nDDL,ni),3841,-0.5,3840.5);
120         hgPedMapSigma1Db[nDDL][ni]  = new TH1F(Form("hPedMapSigma1Db_DDL%d_PC_%d" ,nDDL,ni), Form("Pedestal: Sigma, DDL(0-13): %d PC(0-5): %d;pad;Sigma" ,nDDL,ni),3841,-0.5,3840.5);
121         hgPedMapSigma1Db[nDDL][ni]->SetMaximum(2.5);
122         }
123       }
124     Int_t nSigCut,r,d,a,hard;  Float_t mean,sigma;
125     Int_t ch=0,pc=0,px=0,py=0;
126     Int_t cnt=0;
127     Int_t runNumber=-99999;
128     Char_t tName[10];
129     Int_t  ldcId;
130     Int_t  timeStamp;
131     Int_t  nEv,nDdlEv;
132     Int_t nBadEv;Float_t nBadEvPer;
133     Printf("Start reading DDL: %d ...",nDDL);  
134     infile>>tName>>runNumber;fgRunNum=runNumber;
135     infile>>tName>>ldcId;
136     infile>>tName>>timeStamp;
137     infile>>tName>>nEv;  
138     infile>>tName>>nDdlEv;  
139     infile>>tName>>nBadEv;
140     infile>>tName>>nBadEvPer;
141     infile>>tName>>nSigCut;
142     
143     Printf("RunNumber: %d, LdcId: %d TimeStamp: %d nEv: %d",fgRunNum,ldcId,timeStamp,nEv);
144     
145     while(!infile.eof()){
146       infile>>dec>>r>>d>>a>>mean>>sigma>>hex>>hard;
147       switch(mode)
148       {
149       case 1:
150         Convert(nDDL,r,d,a,ch,pc,px,py); 
151         hgPedMapMean[nDDL][pc].Fill(px,py,mean);  
152         hgPedMapSigma[nDDL][pc].Fill(px,py,sigma);
153         hgPedMapMean1D[nDDL][pc].Fill(cnt%3840,mean);
154         hgPedMapSigma1D[nDDL][pc].Fill(cnt%3840,sigma);
155         hgPedMapSigma1Db[nDDL][pc].Fill(cnt%3840,sigma);
156       break;
157       case 2:
158         if(sigma>3 && sigma!=1000)  PlotPedHisto("Sigma",runNumber,nDDL,r,d,a);    
159       break;
160       case 3:
161         if(sigma==1000)  PlotPedHisto("NoEntry",runNumber,nDDL,r,d,a);    
162       break;
163       
164       }
165         
166       cnt++;      
167     }
168   infile.close();
169   Printf("Stop reading DDL: %d ...",nDDL);
170   
171   /* fill the overall histos */
172   
173   if(mode==1) 
174   {
175     for(Int_t npc=0;npc<6;npc++) 
176       {
177           /* plot pedestal mean values */
178          if(hgPedMapMean[nDDL][npc].GetEntries()!=0) {
179            hgPedMapMean[nDDL][npc].SetStats(0);
180            PlotHisto2D(hgPedMapMean[nDDL][npc],Form("Run%d_PedMeanA_DDL%d_PC%d",fgRunNum,nDDL,npc),"colz");
181            PlotHisto2D(hgPedMapMean[nDDL][npc],Form("Run%d_PedMeanB_DDL%d_PC%d",fgRunNum,nDDL,npc),"surf1");
182          }
183          /* plot pedestal sigma values */
184          if(hgPedMapSigma[nDDL][npc].GetEntries()!=0) {
185            hgPedMapSigma[nDDL][npc].SetStats(0);
186            PlotHisto2D(hgPedMapSigma[nDDL][npc],Form("Run%d_PedSigmaA_DDL%d_PC%d",fgRunNum,nDDL,npc),"colz");
187            PlotHisto2D(hgPedMapSigma[nDDL][npc],Form("Run%d_PedSigmaB_DDL%d_PC%d",fgRunNum,nDDL,npc),"surf1");
188          }
189          /* plot pedestal sigma values */
190          if(hgPedMapSigma[nDDL][npc].GetEntries()!=0) {
191            hgPedMapSigma[nDDL][npc].SetStats(0);
192            hgPedMapSigma[nDDL][npc].SetMaximum(2.5);
193            PlotHisto2D(hgPedMapSigma[nDDL][npc],Form("Run%d_PedSigmaC_DDL%d_PC%d",fgRunNum,nDDL,npc),"colz");
194            PlotHisto2D(hgPedMapSigma[nDDL][npc],Form("Run%d_PedSigmaD_DDL%d_PC%d",fgRunNum,nDDL,npc),"surf1");
195          }
196          /* plot pedestal mean values */
197          if(hgPedMapMean1D[nDDL][npc].GetEntries()!=0) {
198             hgPedMapMean1D[nDDL][npc].SetStats(0);
199            PlotHisto1D(hgPedMapMean1D[nDDL][npc],Form("Run%d_PedMean1DA_DDL%d_PC%d",fgRunNum,nDDL,npc));
200          }
201          /* plot pedestal sigma values */
202          if(hgPedMapSigma1D[nDDL][npc].GetEntries()!=0) {
203            hgPedMapSigma1D[nDDL][npc].SetStats(0);
204            PlotHisto1D(hgPedMapSigma1D[nDDL][npc],Form("Run%d_PedSigma1DA_DDL%d_PC%d",fgRunNum,nDDL,npc));
205          }
206          /* plot pedestal sigma values */
207          if(hgPedMapSigma1Db[nDDL][npc].GetEntries()!=0) {
208            hgPedMapSigma1Db[nDDL][npc].SetStats(0);
209            PlotHisto1D(hgPedMapSigma1D[nDDL][npc],Form("Run%d_PedSigma1DA_DDL%d_PC%d",fgRunNum,nDDL,npc));
210          }       
211       }  
212   }
213   
214        
215 }//ProcPed()
216 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++      
217 void ProcErr(Int_t nDDL,Int_t mode)
218 {
219   if(gSystem->IsFileInIncludePath(Form("./HmpidErrorsDdl%02i.txt",nDDL)))
220           ifstream infile(Form("./HmpidErrorsDdl%02i.txt",nDDL));
221     else return;
222     if(mode==1)
223     {
224     hgDdlErr[nDDL] = new TH1I(Form("hPedErr_DDL%d",nDDL),Form("DDL(%d) Decoding Errors",nDDL),AliHMPIDRawStream::kSumErr+1,-0.5,AliHMPIDRawStream::kSumErr+0.5);
225      for(Int_t ilabel=0; ilabel< AliHMPIDRawStream::kSumErr; ilabel++) {
226       hgDdlErr[nDDL].SetStats(0);
227       hgDdlErr[nDDL].GetXaxis()->CenterLabels(kTRUE);
228       hgDdlErr[nDDL].GetXaxis()->SetBinLabel((ilabel+1),Form("%i  %s",ilabel+1,AliHMPIDRawStream::GetErrName(ilabel)));
229       hgDdlErr[nDDL].SetYTitle("Error #");
230      }
231     hgDdlErr[nDDL].SetFillColor(5);
232   }  
233     
234     Int_t runNumber=-99999;
235     Char_t tName[10];
236     Int_t  ldcId;
237     Int_t  timeStamp;
238     Int_t  nEv,nDdlEv;
239     Int_t rerr;Int_t nBadEv;Float_t nBadEvPer;
240     Int_t row,dil,pad,nzero;
241     Int_t ch,pc,px,py;
242     Printf("Start reading Error File DDL: %d ...",nDDL);  
243     infile>>tName>>runNumber;fgRunNum=runNumber;
244     infile>>tName>>ldcId;
245     infile>>tName>>timeStamp;
246     infile>>tName>>nEv;
247     infile>>tName>>nDdlEv;
248     infile>>tName>>nBadEv;
249     infile>>tName>>nBadEvPer;
250     Printf("RunNumber: %d, LdcId: %d TimeStamp: %d nEv: %d",runNumber,ldcId,timeStamp,nEv);
251     for(Int_t ierr=0;ierr<AliHMPIDRawStream::kSumErr;ierr++)
252     {
253        infile>>rerr;hgDdlErr[nDDL].SetBinContent(ierr+1,rerr);
254      }
255     
256     switch(mode)
257     {
258       case 1:          
259           TCanvas *cerr = new TCanvas("cped","cped");
260           cerr.cd();
261           hgDdlErr[nDDL]->Draw();
262           cerr->SaveAs(Form("PedError_DDL%d.eps",nDDL)); 
263           cerr->SaveAs(Form("PedError_DDL%d.gif",nDDL)); 
264     
265         break;
266         
267       case 2:
268         while(!infile.eof()){
269         infile>>dec>>row>>dil>>pad>>nzero; 
270         if( 0<=nDDL && nDDL<=13 && 1<=dil && dil<=10 && 1<=row && row<=24 && 0<=pad && pad<=47) 
271           { 
272            PlotPedHisto("ZeroQ",runNumber,nDDL,row,dil,pad);
273          }
274        } 
275         
276     break;
277       
278     default:
279         break;  
280     }
281    infile.close();     
282 }
283 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++      
284 void HplotDA(Int_t runNumber)
285 {
286   gStyle->SetPalette(1);
287   fgRunNum=runNumber;
288   
289   Printf("********************************************************************");
290   Printf("********************** HplotDA *************************************");
291   Printf("***                                                              ***");
292   Printf("*** Choose from the following options:                           ***");
293   Printf("***                                                              ***");
294   Printf("*** 1.) Draw errors for all DDL                                  ***");
295   Printf("*** 2.) Draw pedestals for all DDL                               ***");
296   Printf("*** 3.) Draw ADC histo for pads with sigma > 3                   ***");
297   Printf("*** 4.) Draw ADC histo for pads with zero charge                 ***");
298   Printf("*** 5.) Draw ADC histo for pads with no valid charge             ***");
299   Printf("*** 6.) Run all                                                  ***");
300   Printf("***                                                              ***");
301   Printf("********************************************************************");
302   Printf("*** Please select: ");
303   
304   Int_t set=0;
305   cin>>set;
306   
307   
308  for(Int_t i=0;i<14;i++) 
309     {
310     switch(set){
311   
312     case 1:  
313      ProcErr(i,1);
314      break;
315      case 2:
316       ProcPed(i,1);  
317      break;
318      case 3:
319        fgin[i]=new TFile(Form("Run%d_DDL%d.root",runNumber,i),"read");
320        ProcPed(i,2);  
321        fgin[i]->Close();
322        break;
323      case 4:
324        fgin[i]=new TFile(Form("Run%d_DDL%d.root",runNumber,i),"read");
325        ProcErr(i,2);
326        fgin[i]->Close();
327      break;  
328      case 5:
329        fgin[i]=new TFile(Form("Run%d_DDL%d.root",runNumber,i),"read");
330        ProcPed(i,3);  
331        fgin[i]->Close();
332      break; 
333      case 6:
334       if(i==0) fgout=new TFile(Form("SummaryOfRun%d.root",fgRunNum),"recreate");
335   
336       ProcErr(i,1);
337       ProcPed(i,1);
338       fgin[i]=new TFile(Form("Run%d_DDL%d.root",runNumber,i),"read");
339       ProcPed(i,2);  
340       ProcErr(i,2);
341       ProcPed(i,3);  
342       fgin[i]->Close(); 
343        
344       if(i==13) {
345         
346         for(Int_t ipc=0;ipc<6;ipc++) 
347         {
348           hgPedMapMean[i][ipc].Write(); 
349           hgPedMapSigma[i][ipc].Write(); 
350           hgPedMapMean1D[i][ipc].Write(); 
351           hgPedMapSigma1D[i][ipc].Write(); 
352           hgPedMapSigma1Db[i][ipc].Write(); 
353         }
354         hgDdlErr[i].Write();
355       }
356      break;
357      default:
358          Printf("Not a valid selection bye-bye....");
359      break;
360     }
361   }
362  
363   if(fgout!=0x0)fgout->Close();    
364   
365 }
366 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++