]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/macrosSDD/PlotDriftSpeedSDDVsTime.C
Protection against missing timestamps
[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     if(goodTime){
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
366     printf("Number of half-modules with drift speed from injectors = %d\n",iGoodInj);
367     printf("Number of half-modules with average drift speed        = %d\n",iAverSpeed);
368     printf("Number of half-modules with drift speed from injectors L3     = %d\n",iGoodInjL3);
369     printf("Number of half-modules with drift speed from golden module L3 = %d\n",iRescaledSpeedL3);
370     printf("Number of half-modules with drift speed from injectors L4     = %d\n",iGoodInjL4);
371     printf("Number of half-modules with drift speed from golden module L4 = %d\n",iRescaledSpeedL4);
372
373     f->Close();
374   }
375
376   Char_t filout[100];
377   sprintf(filout,"DriftSpVsTime_%d.root",year);
378   TFile *ofil=new TFile(filout,"recreate");
379   for(Int_t iHyb=0; iHyb<520;iHyb++){
380     gvdrvstime[iHyb]->Write();
381     gvdrvsrun[iHyb]->Write();
382     gstatusinjvstime[iHyb]->Write();
383     gstatusinjvsrun[iHyb]->Write();
384   }
385   gGoodInjVsRun->Write();
386   gGoodInjVsRunL3->Write();
387   gGoodInjVsRunL4->Write();
388   gGoodInjVsTime->Write();
389   gGoodInjVsTimeL3->Write();
390   gGoodInjVsTimeL4->Write();
391   gAverSpeedVsRun->Write();
392   gAverSpeedVsRunL3->Write();
393   gAverSpeedVsRunL4->Write();
394   gAverSpeedVsTime->Write();
395   gAverSpeedVsTimeL3->Write();
396   gAverSpeedVsTimeL4->Write();
397   gRescaledSpeedVsRun->Write();
398   gRescaledSpeedVsRunL3->Write();
399   gRescaledSpeedVsRunL4->Write();
400   gRescaledSpeedVsTime->Write();
401   gRescaledSpeedVsTimeL3->Write();
402   gRescaledSpeedVsTimeL4->Write();
403   ofil->Close();
404
405   //  Int_t mod1=244-240;
406   Int_t mod1 = 275-240;
407   Int_t mod2=318-240;
408   //  Int_t mod2=259-240;
409 //   Int_t mod2=274-240;
410   Int_t mod3=413-240;
411   //  Int_t mod4=453-240;
412   Int_t mod4=480-240;
413    //  Int_t mod4=497-240;
414   Int_t lay1,lad1,det1;
415   Int_t lay2,lad2,det2;
416   Int_t lay3,lad3,det3;
417   Int_t lay4,lad4,det4;
418   AliITSgeomTGeo::GetModuleId(mod1+240,lay1,lad1,det1);
419   AliITSgeomTGeo::GetModuleId(mod2+240,lay2,lad2,det2);
420   AliITSgeomTGeo::GetModuleId(mod3+240,lay3,lad3,det3);
421   AliITSgeomTGeo::GetModuleId(mod4+240,lay4,lad4,det4);
422
423   gStyle->SetOptTitle(0);
424   TCanvas* c0=new TCanvas("c0","Vdrift vs. time");
425   c0->SetGridx();
426   c0->SetGridy();
427   gvdrvstime[2*mod1]->SetMarkerStyle(20);
428   gvdrvstime[2*mod2]->SetMarkerStyle(22);
429   gvdrvstime[2*mod2]->SetMarkerColor(2);
430   gvdrvstime[2*mod2]->SetLineColor(2);
431   gvdrvstime[2*mod3]->SetMarkerStyle(29);
432   gvdrvstime[2*mod3]->SetMarkerColor(3);
433   gvdrvstime[2*mod3]->SetLineColor(3);
434   gvdrvstime[2*mod4]->SetMarkerStyle(27);
435   gvdrvstime[2*mod4]->SetMarkerColor(4);
436   gvdrvstime[2*mod4]->SetLineColor(4);
437   gvdrvstime[2*mod1]->Draw("AP");
438   gvdrvstime[2*mod1]->SetMinimum(6.3);
439   gvdrvstime[2*mod1]->SetMaximum(6.75);
440   Char_t title[100];
441   if(year==2009){
442     sprintf(title,"Time (days since July 16th 2009)");
443   }else{
444     sprintf(title,Form("Time (days since January 1st %d)",year));
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(0.);
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(0.);
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 }