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