]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AnalyzeSDDGainAllMod.C
Fix for pre_VTH choice (A. Mastroserio)
[u/mrichter/AliRoot.git] / ITS / AnalyzeSDDGainAllMod.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TH2F.h>
3 #include <TCanvas.h>
4 #include <TStopwatch.h>
5 #include <TStyle.h>
6 #include <TLatex.h>
7 #include <TFile.h>
8 #include <TGrid.h>
9 #include "AliRawReader.h"
10 #include "AliRawReaderDate.h"
11 #include "AliRawReaderRoot.h"
12 #include "AliITSOnlineSDDBase.h"
13 #include "AliITSOnlineSDDCMN.h"
14 #include "AliITSOnlineSDDTP.h"
15 #include "AliITSRawStreamSDD.h"
16 #include "AliITSRawStreamSDDCompressed.h"
17 #endif
18
19 // Macro for the analysis of PULSER runs (equivalent to ITSSDDGAINda.cxx)
20 // Two functions named AnalyzeSDDGainAllModules: 
21 // The first is for analyzing a local raw data file and takes as agrument the file name.
22 // The second is for running on ALIEN
23 // All DDLs are analyzed, the argument nDDL selects the DDL to be plotted
24 // Origin: F. Prino (prino@to.infn.it)
25
26
27 void AnalyzeSDDGainAllMod(Char_t *datafil, 
28                           Int_t adcfreq=20, 
29                           Int_t nDDL=0, 
30                           Int_t firstEv=10, 
31                           Int_t lastEv=16, 
32                           Float_t pascalDAC=100, 
33                           Int_t dataformat=1){
34
35   const Int_t kTotDDL=24;
36   const Int_t kModPerDDL=12;
37   const Int_t kSides=2;
38
39
40   TH2F** histo = new TH2F*[kTotDDL*kModPerDDL*kSides];
41   AliITSOnlineSDDTP **anal=new AliITSOnlineSDDTP*[kTotDDL*kModPerDDL*kSides];
42   Bool_t isFilled[kTotDDL*kModPerDDL*kSides];
43
44   Char_t hisnam[20];
45   for(Int_t iddl=0; iddl<kTotDDL;iddl++){
46     for(Int_t imod=0; imod<kModPerDDL;imod++){
47       for(Int_t isid=0;isid<kSides;isid++){
48         Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
49         anal[index]=new AliITSOnlineSDDTP(iddl,imod,isid,pascalDAC);
50         if(adcfreq==40) anal[index]->SetLastGoodTB(254);
51         else anal[index]->SetLastGoodTB(126);
52         sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid);
53         histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
54         isFilled[index]=0;
55       }
56     }
57   }
58
59   TCanvas* c0 = new TCanvas("c0","Ev Display",900,900);
60   gStyle->SetPalette(1);
61   Char_t text[50];
62
63   Int_t iev=firstEv;
64   AliRawReader *rd; 
65   if(strstr(datafil,".root")!=0){
66     rd=new AliRawReaderRoot(datafil,iev);
67   }else{
68     rd=new AliRawReaderDate(datafil,iev);
69   }
70   TLatex *t0=new TLatex();
71   t0->SetNDC();
72   t0->SetTextSize(0.06);
73   t0->SetTextColor(4);
74
75   do{
76     c0->Clear();
77     c0->Divide(4,6,0.001,0.001);
78     printf("Event # %d\n",iev);
79     rd->Reset();
80     for(Int_t iddl=0; iddl<kTotDDL;iddl++){
81       for(Int_t imod=0; imod<kModPerDDL;imod++){
82         for(Int_t isid=0;isid<kSides;isid++){
83           Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
84           histo[index]->Reset();
85         }
86       }
87     }
88     AliITSRawStream* s;
89     if(dataformat==0){
90       s=new AliITSRawStreamSDD(rd);
91     }else{
92       s=new AliITSRawStreamSDDCompressed(rd);
93       if(dataformat==1) s->SetADCEncoded(kTRUE);
94     }
95     while(s->Next()){
96       Int_t iDDL=rd->GetDDLID();
97       Int_t iCarlos=s->GetCarlosId();
98       if(s->IsCompletedModule()) continue;
99       if(s->IsCompletedDDL()) continue;
100       if(iDDL>=0 && iDDL<kTotDDL){ 
101         Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel(); 
102         histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal());
103         isFilled[index]=1;
104       }
105     }
106     delete s;
107     iev++;
108     for(Int_t iddl=0; iddl<kTotDDL;iddl++){
109       for(Int_t imod=0; imod<kModPerDDL;imod++){
110         for(Int_t isid=0;isid<kSides;isid++){
111           Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
112           anal[index]->AddEvent(histo[index]);
113           if(iddl==nDDL){
114             Int_t index2=kSides*imod+isid;
115             c0->cd(index2+1);
116             histo[index]->DrawCopy("colz");
117             sprintf(text,"DDL %d channel %d Side %d",nDDL,imod,isid);
118             t0->DrawLatex(0.15,0.92,text);
119             c0->Update();
120           }
121         }
122       }
123     }
124     printf(" --- OK\n");
125   }while(rd->NextEvent()&&iev<=lastEv);
126
127   TH1F *htotgain=new TH1F("htotgain","",100,0.2,4.2);
128   TH1F *htotpeakpos=new TH1F("htotpeakpos","",256,-0.5,255.5);
129   TH1F *hstatus=new TH1F("hstatus","",2,-0.5,1.5);
130
131   TFile *outfil=new TFile("SDDgain-results.root","recreate");
132   for(Int_t iddl=0; iddl<kTotDDL;iddl++){
133     for(Int_t imod=0; imod<kModPerDDL;imod++){
134       for(Int_t isid=0;isid<kSides;isid++){
135         Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
136         if(isFilled[index]){
137           anal[index]->ValidateAnodes();
138           anal[index]->WriteToASCII();
139           anal[index]->WriteToROOT(outfil);
140           for(Int_t ian=0; ian<256;ian++){
141             Float_t gain=anal[index]->GetChannelGain(ian);
142             Float_t ppos=anal[index]->GetTimeBinTPPeak(ian);
143             Int_t anstatus=anal[index]->IsAnodeGood(ian);
144             hstatus->Fill(anstatus);
145             htotgain->Fill(gain);
146             htotpeakpos->Fill(ppos);
147           }
148         }
149       }
150     }
151   }
152   outfil->Close();
153
154   // Draw Statistics of baselines and noise
155   TCanvas *call=new TCanvas("call","General stats",700,700);
156   call->Divide(2,2);
157   call->cd(1);
158   htotpeakpos->Draw();
159   htotpeakpos->GetXaxis()->SetTitle("TP peak position (Time Bin)");
160   htotpeakpos->GetXaxis()->SetTitleSize(0.07);
161   htotpeakpos->GetXaxis()->SetTitleOffset(0.6);
162   call->cd(2);
163   htotgain->Draw();
164   htotgain->GetXaxis()->SetTitle("Gain (ADC/DAC)");
165   htotgain->GetXaxis()->SetTitleSize(0.07);
166   htotgain->GetXaxis()->SetTitleOffset(0.6);
167   call->cd(3);
168   hstatus->Draw();
169   hstatus->GetXaxis()->SetTitle("Anode Status (0=bad 1=good)");
170   hstatus->GetXaxis()->SetTitleSize(0.07);
171   hstatus->GetXaxis()->SetTitleOffset(0.6);
172   call->Update();
173   call->SaveAs("GenStatsPulser.gif");
174
175   // Draw baselines and noisegain and TestPulse time bin for all modules
176
177   TH1F** hgain = new TH1F*[kModPerDDL*kSides];
178   TH1F** htptb = new TH1F*[kModPerDDL*kSides];
179
180   TCanvas *c1=new TCanvas("c1","DDL: TP position",900,900);
181   c1->SetBottomMargin(0.14);
182   c1->Divide(4,6,0.001,0.001);
183   TCanvas *c2=new TCanvas("c2","DDL: gain",900,900);
184   c2->SetBottomMargin(0.14);
185   c2->Divide(4,6,0.001,0.001);
186
187   for(Int_t imod=0; imod<kModPerDDL;imod++){
188     for(Int_t isid=0;isid<kSides;isid++){
189       Int_t index1=kSides*(kModPerDDL*nDDL+imod)+isid;
190       Int_t index2=kSides*imod+isid;
191       sprintf(text,"DDL %d channel %d Side %d",nDDL,imod,isid);
192
193       TLatex *t3=new TLatex(0.15,0.92,text);
194       t3->SetNDC();
195       t3->SetTextSize(0.06);
196       t3->SetTextColor(4);
197       sprintf(hisnam,"hgain%ds%d",imod,isid);
198       hgain[index2]=new TH1F(hisnam,"",256,-0.5,255.5);
199       sprintf(hisnam,"htptb%ds%d",imod,isid);
200       htptb[index2]=new TH1F(hisnam,"",256,-0.5,255.5);
201       for(Int_t ian=0;ian<256;ian++){
202         hgain[index2]->SetBinContent(ian+1,anal[index1]->GetChannelGain(ian));
203         htptb[index2]->SetBinContent(ian+1,anal[index1]->GetTimeBinTPPeak(ian));
204       }
205
206       c1->cd(index2+1);
207       htptb[index2]->Draw();
208     //    htptb[imod]->SetMinimum(0);
209     //    htptb[imod]->SetMaximum(75);
210       htptb[index2]->GetXaxis()->SetTitle("Anode");
211       htptb[index2]->GetYaxis()->SetTitle("TP position (Time Bin)");
212       htptb[index2]->GetXaxis()->SetTitleSize(0.07);
213       htptb[index2]->GetYaxis()->SetTitleSize(0.07);
214       htptb[index2]->GetXaxis()->SetTitleOffset(0.6);
215       htptb[index2]->GetYaxis()->SetTitleOffset(0.7);
216       t3->Draw();
217       c1->Update();
218
219
220       c2->cd(index2+1); 
221       hgain[index2]->SetMinimum(0.);
222       hgain[index2]->SetMaximum(4.);
223       hgain[index2]->Draw();
224       hgain[index2]->GetXaxis()->SetTitle("Anode");
225       hgain[index2]->GetYaxis()->SetTitle("Gain");
226       hgain[index2]->GetXaxis()->SetTitleSize(0.07);
227       hgain[index2]->GetYaxis()->SetTitleSize(0.07);
228       hgain[index2]->GetXaxis()->SetTitleOffset(0.6);
229       hgain[index2]->GetYaxis()->SetTitleOffset(0.7);
230       hgain[index2]->SetStats(0);
231       t3->Draw();
232       c2->Update();
233     }
234   }
235
236   c1->SaveAs("TPtimebin.gif");
237   c2->SaveAs("Gain.gif");
238
239 }
240
241 void AnalyzeSDDGainAllMod(Int_t nrun, Int_t n2, Char_t* dir="LHC08d_SDD",
242                           Int_t adcfreq=20, 
243                           Int_t nDDL=0, 
244                           Int_t firstEv=15, 
245                           Int_t lastEv=20, 
246                           Float_t pascalDAC=100, 
247                           Int_t dataformat=1){
248
249   TGrid::Connect("alien:",0,0,"t");
250   Char_t filnam[200];
251   sprintf(filnam,"alien:///alice/data/2008/%s/%09d/raw/08%09d%03d.10.root",dir,nrun,nrun,n2);
252   printf("Open file %s\n",filnam);
253   AnalyzeSDDGainAllMod(filnam,adcfreq,nDDL,firstEv,lastEv,pascalDAC,dataformat);
254 }