Updated directory names on LDC in SDD calibration plotting macro (Mario Sitta)
[u/mrichter/AliRoot.git] / ITS / macrosSDD / PlotDriftSpeedSDDVsTime.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <Riostream.h>
3 #include <TFile.h>
4 #include <TH1F.h>
5 #include <TH2F.h>
6 #include <TGraph.h>
7 #include <TStyle.h>
8 #include <TLegend.h>
9 #include <TLegendEntry.h>
10 #include <TLine.h>
11 #include <TSystem.h>
12 #include <TGrid.h>
13 #include <TMath.h>
14 #include <TGraphErrors.h>
15 #include <TCanvas.h>
16 #include <TLatex.h>
17 #include <TObjArray.h>
18 #include "AliCDBEntry.h"
19 #include "AliITSDriftSpeedArraySDD.h"
20 #include "AliITSgeomTGeo.h"
21 #endif
22
23 /*  $Id: PlotDriftSpeedSDDVsTime.C 41510 2010-06-01 09:21:24Z prino $    */
24
25
26 // Macro to plot the drift speed vs. time from the OCDB files 
27 // created from INJECTOR runs (OCDB/ITS/Calib/DriftSpeedSDD)
28 // Origin: F. Prino (prino@to.infn.it)
29
30 void FillErrors(Float_t errSpeed[260]);
31
32 void PlotDriftSpeedSDDVsTime(Int_t year=2012, Int_t firstRun=172600, 
33                              Int_t lastRun=999999999,
34                              Int_t anode=128){
35   TGrid::Connect("alien:",0,0,"t");
36   Float_t errSpeed[260];
37   FillErrors(errSpeed);
38   Int_t iAn=anode;
39   if(anode>256) iAn=anode-256;
40
41   TString cmd=Form("gbbox find \"/alice/data/%d/OCDB/ITS/Calib/DriftSpeedSDD\" \"Run*.root\" > runSpeedAlien.txt",year);
42   gSystem->Exec(cmd.Data());
43   FILE* listruns=fopen("runSpeedAlien.txt","r");
44   Char_t filnam[200],filnamalien[200];
45   TGraphErrors** gvdrvstime=new TGraphErrors*[520];
46   TGraphErrors** gvdrvsrun=new TGraphErrors*[520];
47   TGraphErrors** gstatusinjvstime=new TGraphErrors*[520];
48   TGraphErrors** gstatusinjvsrun=new TGraphErrors*[520];
49
50
51   TGraph* gGoodInjVsRun=new TGraph(0);
52   gGoodInjVsRun->SetName("gGoodInjVsRun");
53   TGraph* gRescaledSpeedVsRun=new TGraph(0);
54   gRescaledSpeedVsRun->SetName("gRescaledSpeedVsRun");
55   TGraph* gAverSpeedVsRun=new TGraph(0);
56   gAverSpeedVsRun->SetName("gAverSpeedVsRun");
57   TGraph* gGoodInjVsTime=new TGraph(0);
58   gGoodInjVsTime->SetName("gGoodInjVsTime");
59   TGraph* gRescaledSpeedVsTime=new TGraph(0);
60   gRescaledSpeedVsTime->SetName("gRescaledSpeedVsTime");
61   TGraph* gAverSpeedVsTime=new TGraph(0);
62   gAverSpeedVsTime->SetName("gAverSpeedVsIime");
63
64   TGraph* gGoodInjVsRunL3=new TGraph(0);
65   gGoodInjVsRunL3->SetName("gGoodInjVsRunL3");
66   TGraph* gRescaledSpeedVsRunL3=new TGraph(0);
67   gRescaledSpeedVsRunL3->SetName("gRescaledSpeedVsRunL3");
68   TGraph* gAverSpeedVsRunL3=new TGraph(0);
69   gAverSpeedVsRunL3->SetName("gAverSpeedVsRunL3");
70   TGraph* gGoodInjVsTimeL3=new TGraph(0);
71   gGoodInjVsTimeL3->SetName("gGoodInjVsTimeL3");
72   TGraph* gRescaledSpeedVsTimeL3=new TGraph(0);
73   gRescaledSpeedVsTimeL3->SetName("gRescaledSpeedVsTimeL3");
74   TGraph* gAverSpeedVsTimeL3=new TGraph(0);
75   gAverSpeedVsTimeL3->SetName("gAverSpeedVsIimeL3");
76
77   TGraph* gGoodInjVsRunL4=new TGraph(0);
78   gGoodInjVsRunL4->SetName("gGoodInjVsRunL4");
79   TGraph* gRescaledSpeedVsRunL4=new TGraph(0);
80   gRescaledSpeedVsRunL4->SetName("gRescaledSpeedVsRunL4");
81   TGraph* gAverSpeedVsRunL4=new TGraph(0);
82   gAverSpeedVsRunL4->SetName("gAverSpeedVsRunL4");
83   TGraph* gGoodInjVsTimeL4=new TGraph(0);
84   gGoodInjVsTimeL4->SetName("gGoodInjVsTimeL4");
85   TGraph* gRescaledSpeedVsTimeL4=new TGraph(0);
86   gRescaledSpeedVsTimeL4->SetName("gRescaledSpeedVsTimeL4");
87   TGraph* gAverSpeedVsTimeL4=new TGraph(0);
88   gAverSpeedVsTimeL4->SetName("gAverSpeedVsIimeL4");
89
90   TGraph* gFracGoodInjVsRun=new TGraph(0);
91   gFracGoodInjVsRun->SetName("gFracGoodInjVsRun");
92   TGraph* gFracRescaledSpeedVsRun=new TGraph(0);
93   gFracRescaledSpeedVsRun->SetName("gFracRescaledSpeedVsRun");
94   TGraph* gFracAverSpeedVsRun=new TGraph(0);
95   gFracAverSpeedVsRun->SetName("gFracAverSpeedVsRun");
96   TGraph* gFracGoodInjVsTime=new TGraph(0);
97   gFracGoodInjVsTime->SetName("gFracGoodInjVsTime");
98   TGraph* gFracRescaledSpeedVsTime=new TGraph(0);
99   gFracRescaledSpeedVsTime->SetName("gFracRescaledSpeedVsTime");
100   TGraph* gFracAverSpeedVsTime=new TGraph(0);
101   gFracAverSpeedVsTime->SetName("gAverSpeedVsIime");
102
103   TGraph* gFracGoodInjVsRunL3=new TGraph(0);
104   gFracGoodInjVsRunL3->SetName("gFracGoodInjVsRunL3");
105   TGraph* gFracRescaledSpeedVsRunL3=new TGraph(0);
106   gFracRescaledSpeedVsRunL3->SetName("gFracRescaledSpeedVsRunL3");
107   TGraph* gFracAverSpeedVsRunL3=new TGraph(0);
108   gFracAverSpeedVsRunL3->SetName("gFracAverSpeedVsRunL3");
109   TGraph* gFracGoodInjVsTimeL3=new TGraph(0);
110   gFracGoodInjVsTimeL3->SetName("gFracGoodInjVsTimeL3");
111   TGraph* gFracRescaledSpeedVsTimeL3=new TGraph(0);
112   gFracRescaledSpeedVsTimeL3->SetName("gFracRescaledSpeedVsTimeL3");
113   TGraph* gFracAverSpeedVsTimeL3=new TGraph(0);
114   gFracAverSpeedVsTimeL3->SetName("gFracAverSpeedVsIimeL3");
115
116   TGraph* gFracGoodInjVsRunL4=new TGraph(0);
117   gFracGoodInjVsRunL4->SetName("gFracGoodInjVsRunL4");
118   TGraph* gFracRescaledSpeedVsRunL4=new TGraph(0);
119   gFracRescaledSpeedVsRunL4->SetName("gFracRescaledSpeedVsRunL4");
120   TGraph* gFracAverSpeedVsRunL4=new TGraph(0);
121   gFracAverSpeedVsRunL4->SetName("gFracAverSpeedVsRunL4");
122   TGraph* gFracGoodInjVsTimeL4=new TGraph(0);
123   gFracGoodInjVsTimeL4->SetName("gFracGoodInjVsTimeL4");
124   TGraph* gFracRescaledSpeedVsTimeL4=new TGraph(0);
125   gFracRescaledSpeedVsTimeL4->SetName("gFracRescaledSpeedVsTimeL4");
126   TGraph* gFracAverSpeedVsTimeL4=new TGraph(0);
127   gFracAverSpeedVsTimeL4->SetName("gFracAverSpeedVsIimeL4");
128   
129   for(Int_t iMod=0; iMod<260;iMod++){
130     for(Int_t iSide=0; iSide<2; iSide++){
131       Int_t index=2*iMod+iSide;
132       gvdrvstime[index]=new TGraphErrors(0);    
133       gvdrvstime[index]->SetTitle(Form("Module %d Side %d",iMod+240,iSide));
134       gvdrvstime[index]->SetName(Form("gspmod%ds%dt",iMod+240,iSide));
135       gvdrvsrun[index]=new TGraphErrors(0);    
136       gvdrvsrun[index]->SetTitle(Form("Module %d Side %d",iMod+240,iSide));
137       gvdrvsrun[index]->SetName(Form("gspmod%ds%dr",iMod+240,iSide));
138       gstatusinjvstime[index]=new TGraphErrors(0);    
139       gstatusinjvstime[index]->SetTitle(Form("Module %d Side %d",iMod+240,iSide));
140       gstatusinjvstime[index]->SetName(Form("gstinmod%ds%dt",iMod+240,iSide));
141       gstatusinjvsrun[index]=new TGraphErrors(0);    
142       gstatusinjvsrun[index]->SetTitle(Form("Module %d Side %d",iMod+240,iSide));
143       gstatusinjvsrun[index]->SetName(Form("gstinmod%ds%dr",iMod+240,iSide));
144     }
145   }
146
147   Float_t driftField=(1800-45)/291/0.012;  
148   Int_t nrun,nrun2,nv,ns;
149   UInt_t timeZero;
150   if(year==2009) timeZero=1247762992;
151   else if(year==2010) timeZero=1262300400;
152   else if(year==2011) timeZero=1293836400; // 1/1/2011 at 0:00 CEST
153   else timeZero=1325372400;
154   while(!feof(listruns)){
155     fscanf(listruns,"%s\n",filnam);
156     Char_t directory[100];
157     sprintf(directory,"/alice/data/%d",year);
158     if(!strstr(filnam,directory)) continue;
159        sscanf(filnam,"/alice/data/%d/OCDB/ITS/Calib/DriftSpeedSDD/Run%d_%d_v%d_s%d.root",&year,&nrun,&nrun2,&nv,&ns);
160
161        if(year==2009 && (nrun<85639 && nrun2> 85639)) continue;// protection for files with swapped ladders 4-5 of layer 3 
162        if(year==2009 && (nrun>100000 && nv< 325)) continue; // protection for files with swapped ladder 0-1 of layer 4
163   
164     if(nrun<firstRun) continue;
165     if(nrun>lastRun) continue;
166     sprintf(filnamalien,"alien://%s",filnam);
167     printf("Open file: %s\n",filnam);
168     TFile *f= TFile::Open(filnamalien);
169     if(f==0x0)continue;
170     AliCDBEntry *ent=(AliCDBEntry*)f->Get("AliCDBEntry");
171     TObjArray *drspSDD = (TObjArray *)ent->GetObject();
172     
173     Int_t iGoodInj=0;
174     Int_t iRescaledSpeed=0;
175     Int_t iAverSpeed=0;
176    
177     Int_t iGoodInjL3=0;
178     Int_t iRescaledSpeedL3=0;
179     Int_t iAverSpeedL3=0;
180    
181     Int_t iGoodInjL4=0;
182     Int_t iRescaledSpeedL4=0;
183     Int_t iAverSpeedL4=0;
184
185     Int_t totalgoodinj=520;
186     Int_t totalgoodinjL3=168;
187     Int_t totalgoodinjL4=352;
188
189     Float_t fracGoodInj=0.;
190     Float_t fracGoodInjL3=0.;
191     Float_t fracGoodInjL4=0.;
192
193     Float_t fracRescaledSpeed=0.;
194     Float_t fracRescaledSpeedL3=0.;
195     Float_t fracRescaledSpeedL4=0.;
196
197     Float_t fracAverSpeed=0.;
198     Float_t fracAverSpeedL3=0.;
199     Float_t fracAverSpeedL4=0.;
200     
201     AliITSDriftSpeedArraySDD *vdriftarr;
202     AliITSDriftSpeedArraySDD *vdriftarr0;
203     AliITSDriftSpeedArraySDD *vdriftarr1;
204
205     UInt_t timest=0;
206     Float_t timeday=0;
207     Bool_t goodTime=kFALSE;
208
209     for(Int_t iHyb=0; iHyb<520;iHyb++){
210       if(!goodTime){
211         vdriftarr=(AliITSDriftSpeedArraySDD*)drspSDD->At(iHyb);
212         UInt_t statusInj=vdriftarr->GetInjectorStatus();
213         if(statusInj>0){
214           timest=vdriftarr->GetTimestamp(0);
215           if(timest>0 && timest>timeZero){
216             timeday=float(timest-timeZero)/60./60./24.;
217             goodTime=kTRUE;
218           }
219         }
220       }
221     }
222
223     for(Int_t iMod=0; iMod<260;iMod++){
224
225       Int_t i0=2*iMod;
226       Int_t i1=1+2*iMod;
227       vdriftarr0=(AliITSDriftSpeedArraySDD*)drspSDD->At(i0);
228       vdriftarr1=(AliITSDriftSpeedArraySDD*)drspSDD->At(i1);
229
230
231       UInt_t statusInj0=vdriftarr0->GetInjectorStatus();
232       UInt_t statusInj1=vdriftarr1->GetInjectorStatus();
233       Int_t npt=gstatusinjvsrun[i0]->GetN();
234       gstatusinjvsrun[i0]->SetPoint(npt,(Float_t)nrun,(Float_t)statusInj0);
235       gstatusinjvsrun[i1]->SetPoint(npt,(Float_t)nrun,(Float_t)statusInj1);
236       gstatusinjvsrun[i0]->SetPointError(npt,0,0);
237       gstatusinjvsrun[i1]->SetPointError(npt,0,0);
238       if(goodTime){
239         Int_t npt2=gstatusinjvstime[i0]->GetN();
240         gstatusinjvstime[i0]->SetPoint(npt2,timeday,(Float_t)statusInj0);
241         gstatusinjvstime[i1]->SetPoint(npt2,timeday,(Float_t)statusInj1);
242         gstatusinjvstime[i0]->SetPointError(npt2,0,0);
243         gstatusinjvstime[i1]->SetPointError(npt2,0,0);
244       }
245
246       Float_t vdrift0=vdriftarr0->GetDriftSpeed(0,iAn);
247       Float_t vdrift1=vdriftarr1->GetDriftSpeed(0,iAn);
248       Float_t mob=vdrift0*1.E5/driftField;  
249       Float_t temper=293.15*TMath::Power((mob/1350.),-1/2.4); 
250       if(iMod==497-240) printf("Run %s   Time %d Day %f Speed=%f Temp=%f\n",filnam,timest,timeday,vdrift0,temper);
251
252       if(statusInj0>1){
253         iGoodInj++;
254         if(iMod<84)iGoodInjL3++;
255         else iGoodInjL4++;
256         npt=gvdrvsrun[i0]->GetN();
257         gvdrvsrun[i0]->SetPoint(npt,(Float_t)nrun,vdrift0);
258         gvdrvsrun[i0]->SetPointError(npt,0,errSpeed[iMod]);
259         if(goodTime){
260           Int_t npt2=gvdrvstime[i0]->GetN();
261           gvdrvstime[i0]->SetPoint(npt2,timeday,vdrift0);
262           gvdrvstime[i0]->SetPointError(npt2,0,errSpeed[iMod]);
263         }
264       }else if(statusInj0==1){
265         iRescaledSpeed++;
266         if(iMod<84)iRescaledSpeedL3++;
267         else iRescaledSpeedL4++;
268       }else{ 
269         iAverSpeed++;
270         if(iMod<84)iAverSpeedL3++;
271         else iAverSpeedL4++;
272       }
273       if(statusInj1>1){ 
274         iGoodInj++;
275         if(iMod<84)iGoodInjL3++;
276         else iGoodInjL4++;
277         npt=gvdrvsrun[i1]->GetN();
278         gvdrvsrun[i1]->SetPoint(npt,(Float_t)nrun,vdrift1);
279         gvdrvsrun[i1]->SetPointError(npt,0,errSpeed[iMod]);
280         if(goodTime){
281           Int_t npt2=gvdrvstime[i1]->GetN();
282           gvdrvstime[i1]->SetPoint(npt2,timeday,vdrift1);
283           gvdrvstime[i1]->SetPointError(npt2,0,errSpeed[iMod]);
284         }
285       }else if(statusInj1==1){
286         iRescaledSpeed++;
287         if(iMod<84)iRescaledSpeedL3++;
288         else iRescaledSpeedL4++;
289       }else{
290         iAverSpeed++;
291         if(iMod<84)iAverSpeedL3++;
292         else iAverSpeedL4++;
293       }
294     }
295
296     Int_t npt=gGoodInjVsRun->GetN();
297
298     fracGoodInj=(Float_t)iGoodInj/(Float_t)totalgoodinj;
299     fracGoodInjL3=(Float_t)iGoodInjL3/(Float_t)totalgoodinjL3;
300     fracGoodInjL4=(Float_t)iGoodInjL4/(Float_t)totalgoodinjL4;
301
302     fracRescaledSpeed   = (Float_t)iRescaledSpeed/(Float_t)totalgoodinj;
303     fracRescaledSpeedL3 = (Float_t)iRescaledSpeedL3/(Float_t)totalgoodinjL3;
304     fracRescaledSpeedL4 = (Float_t)iRescaledSpeedL3/(Float_t)totalgoodinjL4;
305
306     fracAverSpeed   = (Float_t)iAverSpeed/(Float_t)totalgoodinj;
307     fracAverSpeedL3 = (Float_t)iAverSpeedL3/(Float_t)totalgoodinjL3;
308     fracAverSpeedL4 = (Float_t)iAverSpeedL4/(Float_t)totalgoodinjL4;
309
310     gGoodInjVsRun->SetPoint(npt,(Float_t)nrun,iGoodInj);
311     gRescaledSpeedVsRun->SetPoint(npt,(Float_t)nrun,iRescaledSpeed);
312     gAverSpeedVsRun->SetPoint(npt,(Float_t)nrun,iAverSpeed);
313         
314     gGoodInjVsRunL3->SetPoint(npt,(Float_t)nrun,iGoodInjL3);
315     gRescaledSpeedVsRunL3->SetPoint(npt,(Float_t)nrun,iRescaledSpeedL3);
316     gAverSpeedVsRunL3->SetPoint(npt,(Float_t)nrun,iAverSpeedL3);
317
318     gGoodInjVsRunL4->SetPoint(npt,(Float_t)nrun,iGoodInjL4);
319     gRescaledSpeedVsRunL4->SetPoint(npt,(Float_t)nrun,iRescaledSpeedL4);
320     gAverSpeedVsRunL4->SetPoint(npt,(Float_t)nrun,iAverSpeedL4);
321
322
323     gFracGoodInjVsRun->SetPoint(npt,(Float_t)nrun,(Double_t)fracGoodInj);
324     gFracRescaledSpeedVsRun->SetPoint(npt,(Float_t)nrun,(Double_t)fracRescaledSpeed);
325     gFracAverSpeedVsRun->SetPoint(npt,(Float_t)nrun,(Double_t)fracAverSpeed);
326         
327     gFracGoodInjVsRunL3->SetPoint(npt,(Float_t)nrun,(Double_t)fracGoodInjL3);
328     gFracRescaledSpeedVsRunL3->SetPoint(npt,(Float_t)nrun,(Double_t)fracRescaledSpeedL3);
329     gFracAverSpeedVsRunL3->SetPoint(npt,(Float_t)nrun,(Double_t)fracAverSpeedL3);
330
331     gFracGoodInjVsRunL4->SetPoint(npt,(Float_t)nrun,(Double_t)fracGoodInjL4);
332     gFracRescaledSpeedVsRunL4->SetPoint(npt,(Float_t)nrun,(Double_t)fracRescaledSpeedL4);
333     gFracAverSpeedVsRunL4->SetPoint(npt,(Float_t)nrun,(Double_t)fracAverSpeedL4);
334
335     npt=gGoodInjVsTime->GetN();
336
337     gGoodInjVsTime->SetPoint(npt,timeday,iGoodInj);
338     gRescaledSpeedVsTime->SetPoint(npt,timeday,iRescaledSpeed);
339     gAverSpeedVsTime->SetPoint(npt,timeday,iAverSpeed);
340
341     gGoodInjVsTimeL3->SetPoint(npt,timeday,iGoodInjL3);
342     gRescaledSpeedVsTimeL3->SetPoint(npt,timeday,iRescaledSpeedL3);
343     gAverSpeedVsTimeL3->SetPoint(npt,timeday,iAverSpeedL3);
344
345     gGoodInjVsTimeL4->SetPoint(npt,timeday,iGoodInjL4);
346     gRescaledSpeedVsTimeL4->SetPoint(npt,timeday,iRescaledSpeedL4);
347     gAverSpeedVsTimeL4->SetPoint(npt,timeday,iAverSpeedL4);
348
349
350     gFracGoodInjVsTime->SetPoint(npt,timeday,(Double_t)fracGoodInj);
351     gFracRescaledSpeedVsTime->SetPoint(npt,timeday,(Double_t)fracRescaledSpeed);
352     gFracAverSpeedVsTime->SetPoint(npt,timeday,(Double_t)fracAverSpeed);
353
354     gFracGoodInjVsTimeL3->SetPoint(npt,timeday,(Double_t)fracGoodInjL3);
355     gFracRescaledSpeedVsTimeL3->SetPoint(npt,timeday,(Double_t)fracRescaledSpeedL3);
356     gFracAverSpeedVsTimeL3->SetPoint(npt,timeday,(Double_t)fracAverSpeedL3);
357
358     gFracGoodInjVsTimeL4->SetPoint(npt,timeday,(Double_t)fracGoodInjL4);
359     gFracRescaledSpeedVsTimeL4->SetPoint(npt,timeday,(Double_t)fracRescaledSpeedL4);
360     gFracAverSpeedVsTimeL4->SetPoint(npt,timeday,(Double_t)fracAverSpeedL4);
361
362     printf("Number of half-modules with drift speed from injectors = %d\n",iGoodInj);
363     printf("Number of half-modules with average drift speed        = %d\n",iAverSpeed);
364     printf("Number of half-modules with drift speed from injectors L3     = %d\n",iGoodInjL3);
365     printf("Number of half-modules with drift speed from golden module L3 = %d\n",iRescaledSpeedL3);
366     printf("Number of half-modules with drift speed from injectors L4     = %d\n",iGoodInjL4);
367     printf("Number of half-modules with drift speed from golden module L4 = %d\n",iRescaledSpeedL4);
368
369     f->Close();
370   }
371
372   Char_t filout[100];
373   sprintf(filout,"DriftSpVsTime_%d.root",year);
374   TFile *ofil=new TFile(filout,"recreate");
375   for(Int_t iHyb=0; iHyb<520;iHyb++){
376     gvdrvstime[iHyb]->Write();
377     gvdrvsrun[iHyb]->Write();
378     gstatusinjvstime[iHyb]->Write();
379     gstatusinjvsrun[iHyb]->Write();
380   }
381   gGoodInjVsRun->Write();
382   gGoodInjVsRunL3->Write();
383   gGoodInjVsRunL4->Write();
384   gGoodInjVsTime->Write();
385   gGoodInjVsTimeL3->Write();
386   gGoodInjVsTimeL4->Write();
387   gAverSpeedVsRun->Write();
388   gAverSpeedVsRunL3->Write();
389   gAverSpeedVsRunL4->Write();
390   gAverSpeedVsTime->Write();
391   gAverSpeedVsTimeL3->Write();
392   gAverSpeedVsTimeL4->Write();
393   gRescaledSpeedVsRun->Write();
394   gRescaledSpeedVsRunL3->Write();
395   gRescaledSpeedVsRunL4->Write();
396   gRescaledSpeedVsTime->Write();
397   gRescaledSpeedVsTimeL3->Write();
398   gRescaledSpeedVsTimeL4->Write();
399   ofil->Close();
400
401   //  Int_t mod1=244-240;
402   Int_t mod1 = 275-240;
403   Int_t mod2=318-240;
404   //  Int_t mod2=259-240;
405 //   Int_t mod2=274-240;
406   Int_t mod3=413-240;
407   //  Int_t mod4=453-240;
408   Int_t mod4=480-240;
409    //  Int_t mod4=497-240;
410   Int_t lay1,lad1,det1;
411   Int_t lay2,lad2,det2;
412   Int_t lay3,lad3,det3;
413   Int_t lay4,lad4,det4;
414   AliITSgeomTGeo::GetModuleId(mod1+240,lay1,lad1,det1);
415   AliITSgeomTGeo::GetModuleId(mod2+240,lay2,lad2,det2);
416   AliITSgeomTGeo::GetModuleId(mod3+240,lay3,lad3,det3);
417   AliITSgeomTGeo::GetModuleId(mod4+240,lay4,lad4,det4);
418
419   gStyle->SetOptTitle(0);
420   TCanvas* c0=new TCanvas("c0","Vdrift vs. time");
421   c0->SetGridx();
422   c0->SetGridy();
423   gvdrvstime[2*mod1]->SetMarkerStyle(20);
424   gvdrvstime[2*mod2]->SetMarkerStyle(22);
425   gvdrvstime[2*mod2]->SetMarkerColor(2);
426   gvdrvstime[2*mod2]->SetLineColor(2);
427   gvdrvstime[2*mod3]->SetMarkerStyle(29);
428   gvdrvstime[2*mod3]->SetMarkerColor(3);
429   gvdrvstime[2*mod3]->SetLineColor(3);
430   gvdrvstime[2*mod4]->SetMarkerStyle(27);
431   gvdrvstime[2*mod4]->SetMarkerColor(4);
432   gvdrvstime[2*mod4]->SetLineColor(4);
433   gvdrvstime[2*mod1]->Draw("AP");
434   gvdrvstime[2*mod1]->SetMinimum(6.3);
435   gvdrvstime[2*mod1]->SetMaximum(6.75);
436   Char_t title[100];
437   if(year==2009){
438     sprintf(title,"Time (days since July 16th 2009)");
439   }else if (year==2010){
440     sprintf(title,"Time (days since January 1st 2010)");
441   }else if (year==2011){
442     sprintf(title,"Time (days since January 1st 2011)");
443   }else{
444     sprintf(title,"Time (days since January 1st 2012)");
445   }
446   gvdrvstime[2*mod1]->GetXaxis()->SetTitle(title);
447   gvdrvstime[2*mod1]->GetYaxis()->SetTitle("Drift speed (#mum/ns)");
448   gvdrvstime[2*mod2]->Draw("PSAME");
449   gvdrvstime[2*mod3]->Draw("PSAME");
450   gvdrvstime[2*mod4]->Draw("PSAME");
451   TLegend* leg=new TLegend(0.6,0.7,0.89,0.89);
452   leg->SetBorderSize(0);
453   leg->SetFillColor(0);
454   leg->SetFillStyle(0);
455   TLegendEntry* lent=leg->AddEntry(gvdrvstime[2*mod1],Form("Lay %d Lad %d Det %d",lay1,lad1,det1),"P");
456   lent=leg->AddEntry(gvdrvstime[2*mod2],Form("Lay %d Lad %d Det %d",lay2,lad2,det2),"P");
457   lent->SetTextColor(2);
458   lent=leg->AddEntry(gvdrvstime[2*mod3],Form("Lay %d Lad %d Det %d",lay3,lad3,det3),"P");
459   lent->SetTextColor(3);
460   lent=leg->AddEntry(gvdrvstime[2*mod4],Form("Lay %d Lad %d Det %d",lay4,lad4,det4),"P");
461   lent->SetTextColor(4);
462   leg->Draw();
463
464   TCanvas* c0b=new TCanvas("c0b","StatusInj vs. time");
465   c0->SetGridx();
466   c0->SetGridy();
467   gstatusinjvstime[2*mod1]->SetMarkerStyle(20);
468   gstatusinjvstime[2*mod2]->SetMarkerStyle(22);
469   gstatusinjvstime[2*mod2]->SetMarkerColor(2);
470   gstatusinjvstime[2*mod2]->SetLineColor(2);
471   gstatusinjvstime[2*mod3]->SetMarkerStyle(29);
472   gstatusinjvstime[2*mod3]->SetMarkerColor(3);
473   gstatusinjvstime[2*mod3]->SetLineColor(3);
474   gstatusinjvstime[2*mod4]->SetMarkerStyle(27);
475   gstatusinjvstime[2*mod4]->SetMarkerColor(4);
476   gstatusinjvstime[2*mod4]->SetLineColor(4);
477   gstatusinjvstime[2*mod1]->Draw("AP");
478   gvdrvstime[2*mod1]->GetXaxis()->SetTitle(title);
479   gvdrvstime[2*mod1]->GetYaxis()->SetTitle("Injector Status");
480   gvdrvstime[2*mod2]->Draw("PSAME");
481   gvdrvstime[2*mod3]->Draw("PSAME");
482   gvdrvstime[2*mod4]->Draw("PSAME");
483   leg->Draw();
484
485
486   TCanvas* c1=new TCanvas("c1","Vdrift vs. run");
487   c1->SetGridx();
488   c1->SetGridy();
489   gvdrvsrun[2*mod1]->SetMarkerStyle(20);
490   gvdrvsrun[2*mod2]->SetMarkerStyle(22);
491   gvdrvsrun[2*mod2]->SetMarkerColor(2);
492   gvdrvsrun[2*mod2]->SetLineColor(2);
493   gvdrvsrun[2*mod3]->SetMarkerStyle(29);
494   gvdrvsrun[2*mod3]->SetMarkerColor(3);
495   gvdrvsrun[2*mod3]->SetLineColor(3);
496   gvdrvsrun[2*mod4]->SetMarkerStyle(27);
497   gvdrvsrun[2*mod4]->SetMarkerColor(4);
498   gvdrvsrun[2*mod4]->SetLineColor(4);
499   gvdrvsrun[2*mod1]->Draw("AP");
500   gvdrvsrun[2*mod1]->SetMinimum(6.3);
501   gvdrvsrun[2*mod1]->SetMaximum(6.75);
502
503   gvdrvsrun[2*mod1]->GetXaxis()->SetTitle("Run number");
504   gvdrvsrun[2*mod1]->GetYaxis()->SetTitle("Drift speed (#mum/ns)");
505   gvdrvsrun[2*mod2]->Draw("PSAME");
506   gvdrvsrun[2*mod3]->Draw("PSAME");
507   gvdrvsrun[2*mod4]->Draw("PSAME");
508   leg->Draw();
509
510
511   TH2F* hlay3=new TH2F("hlay3","Variation of the drift speed (%) Layer 3",6,-0.5,5.5,14,-0.5,13.5);
512   hlay3->GetXaxis()->SetTitle("Detector");
513   hlay3->GetYaxis()->SetTitle("Ladder");
514   hlay3->GetXaxis()->SetTickLength(0);
515   hlay3->GetYaxis()->SetTickLength(0);
516   hlay3->SetStats(0);
517
518   TH2F* hlay4=new TH2F("hlay4","Variation of the drift speed (%) Layer 4",8,-0.5,7.5,22,-0.5,21.5);
519   hlay4->GetXaxis()->SetTitle("Detector");
520   hlay4->GetYaxis()->SetTitle("Ladder");
521   hlay4->GetXaxis()->SetTickLength(0);
522   hlay4->GetYaxis()->SetTickLength(0);
523   hlay4->GetYaxis()->SetTitle("Ladder");
524   hlay4->SetStats(0);
525
526   Double_t run1,run2,vdr1,vdr2;
527   Int_t lay,lad,det;
528   for(Int_t iMod=0; iMod<260; iMod++){
529     Int_t lastPoint=gvdrvsrun[2*iMod]->GetN()-1;
530     gvdrvsrun[2*iMod]->GetPoint(lastPoint,run2,vdr2);
531     gvdrvsrun[2*iMod]->GetPoint(lastPoint-1,run1,vdr1);
532     Float_t diff=0.;
533     if(vdr1>0.) diff=100*(vdr2-vdr1)/vdr1;
534     AliITSgeomTGeo::GetModuleId(iMod+240,lay,lad,det);
535     if(lay==3) hlay3->SetBinContent(det,lad,diff);
536     if(lay==4) hlay4->SetBinContent(det,lad,diff);
537   }
538   TLine* lin=new TLine(0,0,0,23);  
539   gStyle->SetPalette(1);
540
541   TCanvas *c0c=new TCanvas("c0c","Percent difference Last Run - Previous Run",900,600);
542   c0c->Divide(2,1);
543   c0c->cd(1);
544   hlay3->DrawCopy("colz");
545   for(Int_t i=0;i<6;i++){
546     lin->SetY1(-0.5);
547     lin->SetY2(13.5);
548     lin->SetX1(i+0.5);
549     lin->SetX2(i+0.5);
550     lin->DrawClone();
551   }
552   for(Int_t i=0;i<14;i++){
553     lin->SetX1(-0.5);
554     lin->SetX2(5.5);
555     lin->SetY1(i+0.5);
556     lin->SetY2(i+0.5);
557     lin->DrawClone();
558   }
559   c0c->cd(2);
560   hlay4->DrawCopy("colz");
561   for(Int_t i=0;i<8;i++){
562     lin->SetY1(-0.5);
563     lin->SetY2(21.5);
564     lin->SetX1(i+0.5);
565     lin->SetX2(i+0.5);
566     lin->DrawClone();
567   }
568   for(Int_t i=0;i<22;i++){
569     lin->SetX1(-0.5);
570     lin->SetX2(7.5);
571     lin->SetY1(i+0.5);
572     lin->SetY2(i+0.5);
573     lin->DrawClone();
574   }
575
576   TCanvas* c4=new TCanvas("c4","GoodMod vs. run");
577   c4->SetGridx();
578   c4->SetGridy();
579   gGoodInjVsRun->SetMarkerStyle(20);
580   gGoodInjVsRun->SetMinimum(50.);
581   gGoodInjVsRun->SetMaximum(370.);
582   gGoodInjVsRunL3->SetMarkerStyle(22);
583   gGoodInjVsRunL3->SetMarkerColor(2);
584   gGoodInjVsRunL3->SetLineColor(2);
585   gGoodInjVsRunL4->SetMarkerStyle(23);
586   gGoodInjVsRunL4->SetMarkerColor(4);
587   gGoodInjVsRunL4->SetLineColor(4);
588   gGoodInjVsRun->Draw("AP");
589   gGoodInjVsRunL3->Draw("PSAME");
590   gGoodInjVsRunL4->Draw("PSAME");
591   gGoodInjVsRun->GetXaxis()->SetTitle("Run number");
592   gGoodInjVsRun->GetYaxis()->SetTitle("Half-modules with drift speed from injectors");
593   TLegend* leg2=new TLegend(0.6,0.3,0.89,0.5);
594   leg2->SetBorderSize(0);
595   leg2->SetFillColor(0);
596   leg2->SetFillStyle(0);
597   TLegendEntry* lent2=leg2->AddEntry(gGoodInjVsRun,"All","P");
598   lent2->SetTextColor(1);
599   lent2=leg2->AddEntry(gGoodInjVsRunL3,"Layer 3 ","P");
600   lent2->SetTextColor(2);
601   lent2=leg2->AddEntry(gGoodInjVsRunL4,"Layer 4","P");
602   lent2->SetTextColor(4);
603   leg2->Draw();
604
605
606   TCanvas* c4bis=new TCanvas("c4bis"," Frac GoodMod vs. run");
607   c4bis->SetGridx();
608   c4bis->SetGridy();
609   gFracGoodInjVsRun->SetMarkerStyle(20);
610   gFracGoodInjVsRun->SetMinimum(0.);
611   gFracGoodInjVsRun->SetMaximum(0.9);
612   gFracGoodInjVsRunL3->SetMarkerStyle(22);
613   gFracGoodInjVsRunL3->SetMarkerColor(2);
614   gFracGoodInjVsRunL3->SetLineColor(2);
615   gFracGoodInjVsRunL4->SetMarkerStyle(23);
616   gFracGoodInjVsRunL4->SetMarkerColor(4);
617   gFracGoodInjVsRunL4->SetLineColor(4);
618   gFracGoodInjVsRun->Draw("AP");
619   gFracGoodInjVsRunL3->Draw("PSAME");
620   gFracGoodInjVsRunL4->Draw("PSAME");
621   gFracGoodInjVsRun->GetXaxis()->SetTitle("Run number");
622   gFracGoodInjVsRun->GetYaxis()->SetTitle("Fraction of Half-modules with drift speed from injectors");
623   gFracGoodInjVsRun->GetYaxis()->SetTitleSize(0.03);
624   gFracGoodInjVsRun->GetYaxis()->SetTitleOffset(1.5);
625   leg2->Draw();
626   
627   TCanvas* c4ter=new TCanvas("c4ter","RescaledMod vs. run");
628   c4ter->SetGridx();
629   c4ter->SetGridy();
630   gRescaledSpeedVsRun->SetMarkerStyle(20);
631   gRescaledSpeedVsRun->SetMinimum(0.);
632   gRescaledSpeedVsRun->SetMaximum(120.);
633   gRescaledSpeedVsRunL3->SetMarkerStyle(22);
634   gRescaledSpeedVsRunL3->SetMarkerColor(2);
635   gRescaledSpeedVsRunL3->SetLineColor(2);
636   gRescaledSpeedVsRunL4->SetMarkerStyle(23);
637   gRescaledSpeedVsRunL4->SetMarkerColor(4);
638   gRescaledSpeedVsRunL4->SetLineColor(4);
639   gRescaledSpeedVsRun->Draw("AP");
640   gRescaledSpeedVsRunL3->Draw("PSAME");
641   gRescaledSpeedVsRunL4->Draw("PSAME");
642   gRescaledSpeedVsRun->GetXaxis()->SetTitle("Run number");
643   gRescaledSpeedVsRun->GetYaxis()->SetTitle("Half-modules with drift speed from golden module");
644   leg2->Draw();
645
646   TCanvas* c5=new TCanvas("c5","GoodMod vs. time");
647   c5->SetGridx();
648   c5->SetGridy();
649   gGoodInjVsTime->SetMarkerStyle(20);
650   gGoodInjVsTime->SetMinimum(50.);
651   gGoodInjVsTime->SetMaximum(370.);
652   gGoodInjVsTimeL3->SetMarkerStyle(22);
653   gGoodInjVsTimeL3->SetMarkerColor(2);
654   gGoodInjVsTimeL3->SetLineColor(2);
655   gGoodInjVsTimeL4->SetMarkerStyle(23);
656   gGoodInjVsTimeL4->SetMarkerColor(4);
657   gGoodInjVsTimeL4->SetLineColor(4);
658   gGoodInjVsTime->Draw("AP");
659   gGoodInjVsTimeL3->Draw("PSAME");
660   gGoodInjVsTimeL4->Draw("PSAME");
661   gGoodInjVsTime->GetXaxis()->SetTitle(title);
662   gGoodInjVsTime->GetYaxis()->SetTitle("Half-modules with drift speed from injectors");
663   leg2->Draw();
664   
665   TCanvas* c5bis=new TCanvas("c5bis","Frac GoodMod vs. time");
666   c5bis->SetGridx();
667   c5bis->SetGridy();
668   gFracGoodInjVsTime->SetMarkerStyle(20);
669   gFracGoodInjVsTime->SetMinimum(0.);
670   gFracGoodInjVsTime->SetMaximum(0.9);
671   gFracGoodInjVsTimeL3->SetMarkerStyle(22);
672   gFracGoodInjVsTimeL3->SetMarkerColor(2);
673   gFracGoodInjVsTimeL3->SetLineColor(2);
674   gFracGoodInjVsTimeL4->SetMarkerStyle(23);
675   gFracGoodInjVsTimeL4->SetMarkerColor(4);
676   gFracGoodInjVsTimeL4->SetLineColor(4);
677   gFracGoodInjVsTime->Draw("AP");
678   gFracGoodInjVsTimeL3->Draw("PSAME");
679   gFracGoodInjVsTimeL4->Draw("PSAME");
680   gFracGoodInjVsTime->GetXaxis()->SetTitle(title);
681   gFracGoodInjVsTime->GetYaxis()->SetTitleSize(0.03);
682   gFracGoodInjVsTime->GetYaxis()->SetTitleOffset(1.5);
683   gFracGoodInjVsTime->GetYaxis()->SetTitle("Fraction of Half-modules with drift speed from injectors");
684   leg2->Draw();
685
686   TCanvas* c5ter=new TCanvas("c5ter","RescaledMod vs. time");
687   c5ter->SetGridx();
688   c5ter->SetGridy();
689   gRescaledSpeedVsTime->SetMarkerStyle(20);
690   gRescaledSpeedVsTime->SetMinimum(0.);
691   gRescaledSpeedVsTime->SetMaximum(120.);
692   gRescaledSpeedVsTimeL3->SetMarkerStyle(22);
693   gRescaledSpeedVsTimeL3->SetMarkerColor(2);
694   gRescaledSpeedVsTimeL3->SetLineColor(2);
695   gRescaledSpeedVsTimeL4->SetMarkerStyle(23);
696   gRescaledSpeedVsTimeL4->SetMarkerColor(4);
697   gRescaledSpeedVsTimeL4->SetLineColor(4);
698   gRescaledSpeedVsTime->Draw("AP");
699   gRescaledSpeedVsTimeL3->Draw("PSAME");
700   gRescaledSpeedVsTimeL4->Draw("PSAME");
701   gRescaledSpeedVsTime->GetXaxis()->SetTitle(title);
702   gRescaledSpeedVsTime->GetYaxis()->SetTitleSize(0.03);
703   gRescaledSpeedVsTime->GetYaxis()->SetTitleOffset(1.5);
704   gRescaledSpeedVsTime->GetYaxis()->SetTitle("Half-modules with drift speed from golden module");
705   leg2->Draw();
706 }
707
708 void FillErrors(Float_t errSpeed[260]){
709   Float_t err[260]={
710     0.002308,0.005120,0.004632,0.001000,0.001735,
711     0.001000,0.001000,0.002667,0.004237,0.005297,
712     0.001000,0.005460,0.005149,0.003921,0.001000,
713     0.003906,0.001000,0.004871,0.001000,0.001000,
714     0.001000,0.001000,0.002261,0.002986,0.002056,
715     0.002848,0.001000,0.001777,0.002822,0.004651,
716     0.001000,0.003551,0.006466,0.001000,0.002083,
717     0.004531,0.001000,0.002213,0.001000,0.001000,
718     0.001000,0.001000,0.001000,0.003223,0.002800,
719     0.002147,0.001000,0.003364,0.001000,0.001000,
720     0.002515,0.003229,0.002552,0.005765,0.002368,
721     0.003473,0.002363,0.001000,0.003413,0.001000,
722     0.004906,0.001000,0.004346,0.004887,0.007138,
723     0.007242,0.004289,0.003970,0.002914,0.002199,
724     0.001000,0.003483,0.002154,0.002914,0.003097,
725     0.006034,0.003101,0.001000,0.002425,0.002651,
726     0.002771,0.002409,0.002260,0.003109,0.001000,
727     0.003384,0.003374,0.002212,0.004441,0.001000,
728     0.001000,0.001000,0.003578,0.001000,0.001000,
729     0.003517,0.003590,0.001787,0.003329,0.001000,
730     0.002770,0.001000,0.004032,0.003059,0.001000,
731     0.001000,0.001000,0.001000,0.001000,0.001000,
732     0.001000,0.004556,0.001000,0.001000,0.001000,
733     0.001000,0.001000,0.001000,0.004819,0.002100,
734     0.002624,0.003784,0.003772,0.002483,0.002792,
735     0.001000,0.004713,0.003214,0.003180,0.002145,
736     0.002470,0.003078,0.001000,0.007131,0.002770,
737     0.002533,0.001000,0.004362,0.002819,0.001000,
738     0.003630,0.004215,0.002975,0.001000,0.003790,
739     0.002345,0.001000,0.003999,0.004555,0.003989,
740     0.001000,0.001000,0.001000,0.003136,0.002426,
741     0.005144,0.002844,0.002310,0.002467,0.002503,
742     0.003811,0.003440,0.004773,0.003114,0.001000,
743     0.000583,0.001000,0.001000,0.003385,0.001000,
744     0.001000,0.001000,0.001000,0.003108,0.002109,
745     0.005325,0.003750,0.002810,0.003559,0.001000,
746     0.001000,0.003262,0.003903,0.001000,0.003622,
747     0.002533,0.002121,0.003733,0.005353,0.002221,
748     0.004767,0.003267,0.004892,0.002152,0.003398,
749     0.001000,0.003146,0.001000,0.002952,0.003310,
750     0.002644,0.002573,0.001000,0.003989,0.001000,
751     0.005294,0.003095,0.003479,0.002250,0.001000,
752     0.001000,0.005221,0.001000,0.001653,0.004330,
753     0.013188,0.007375,0.003226,0.003875,0.001000,
754     0.003653,0.001000,0.002655,0.001000,0.001000,
755     0.001000,0.001000,0.004718,0.001000,0.001000,
756     0.001000,0.002780,0.003680,0.001000,0.002787,
757     0.001000,0.004617,0.001000,0.001000,0.003231,
758     0.001887,0.002090,0.003326,0.129970,0.004907,
759     0.004334,0.001000,0.001000,0.003489,0.002573,
760     0.002566,0.002982,0.001000,0.001000,0.003436,
761     0.004016,0.003736,0.001784,0.004775,0.008090};
762   for(Int_t i=0;i<260;i++) errSpeed[i]=err[i];
763   
764   
765 }