Add protection for anomalous drift speed values
[u/mrichter/AliRoot.git] / ITS / ShowDriftSpeedSDD.C
CommitLineData
40b3a8c7 1#if !defined(__CINT__) || defined(__MAKECINT__)
2420973e 2#include <TF1.h>
40b3a8c7 3#include <TFile.h>
4#include <TH1F.h>
5#include <TGraph.h>
6#include <TStyle.h>
551eb942 7#include <TSystem.h>
8#include <TString.h>
40b3a8c7 9#include <TGrid.h>
10#include <TCanvas.h>
11#include <TLatex.h>
12#include <TObjArray.h>
13#include "AliCDBEntry.h"
14#include "AliITSDriftSpeedArraySDD.h"
2420973e 15#include "AliITSDriftSpeedSDD.h"
40b3a8c7 16#endif
17
18// Macro to plot the calibration parameters from the OCDB file
19// created from an INJECTOR run (OCDB/ITS/Calib/DriftSpeedSDD)
20// Two methods ShowDriftSpeedSDD:
21// - the first takes the name of the file to be displayed
22// - the second builds the alien path+name from run number and file version
23//
24// Origin: F. Prino (prino@to.infn.it)
25
b70dd7af 26Bool_t kNoDraw = kFALSE; // set to kTRUE to eliminate module dependent plots
27
28void ShowDriftSpeedSDD(Char_t filnam[150]="$ALICE_ROOT/ITS/Calib/DriftSpeedSDD/Run0_9999999_v0_s0.root", Int_t firstmod=0, Int_t lastmod=260,Int_t nrun=0){
40b3a8c7 29 TFile *f= TFile::Open(filnam);
30 AliCDBEntry *ent=(AliCDBEntry*)f->Get("AliCDBEntry");
31 TObjArray *drspSDD = (TObjArray *)ent->GetObject();
32 AliITSDriftSpeedArraySDD *vdriftarr0;
33 AliITSDriftSpeedArraySDD *vdriftarr1;
34 TGraph **gvdr0=new TGraph*[260];
35 TGraph **gvdr1=new TGraph*[260];
b70dd7af 36 TCanvas *c0=NULL;
37 if(!kNoDraw)c0=new TCanvas("c0","Module Drift Speed",1100,500);
40b3a8c7 38
39 TGraph *vvsmod0=new TGraph(0);
40 TGraph *vvsmod1=new TGraph(0);
915c0469 41 TGraph *poldegvsmod0=new TGraph(0);
42 TGraph *poldegvsmod1=new TGraph(0);
43 TGraph *anmaxvsmod0=new TGraph(0);
44 TGraph *anmaxvsmod1=new TGraph(0);
45 TGraph *dvcevsmod0=new TGraph(0);
46 TGraph *dvcevsmod1=new TGraph(0);
47 TGraph *dveevsmod0=new TGraph(0);
48 TGraph *dveevsmod1=new TGraph(0);
49
b70dd7af 50 char tit0[100];
51 sprintf(tit0,"Drift Speed vs. mod. number");
52 if(nrun!=0)sprintf(tit0,"Drift Speed vs. mod. number - Run %d",nrun);
53 vvsmod0->SetTitle(tit0);
54 vvsmod1->SetTitle(tit0);
915c0469 55
56 sprintf(tit0,"Degree of poly fit vs. mod. number");
57 if(nrun!=0)sprintf(tit0,"Degree of poly fit vs. mod. number - Run %d",nrun);
58 poldegvsmod0->SetTitle(tit0);
59 poldegvsmod1->SetTitle(tit0);
60
61 sprintf(tit0,"Anode with max. vdrift vs. mod. number");
62 if(nrun!=0)sprintf(tit0,"Anode with max. vdrift vs. mod. number - Run %d",nrun);
63 anmaxvsmod0->SetTitle(tit0);
64 anmaxvsmod1->SetTitle(tit0);
65
66 sprintf(tit0,"Delta Vdrift 128-0 vs. mod. number");
67 if(nrun!=0)sprintf(tit0,"Delta Vdrift 128-0 vs. mod. number - Run %d",nrun);
68 dvcevsmod0->SetTitle(tit0);
69 dvcevsmod1->SetTitle(tit0);
70
71 sprintf(tit0,"Delta Vdrift 256-0 vs. mod. number");
72 if(nrun!=0)sprintf(tit0,"Delta Vdrift 256-0 vs. mod. number - Run %d",nrun);
73 dveevsmod0->SetTitle(tit0);
74 dveevsmod1->SetTitle(tit0);
75
76 TF1* fPoly=new TF1("fPoly","[0]+[1]*x+[2]*x*x+[3]*x*x*x",0.,256.);
40b3a8c7 77 Char_t tit[100];
915c0469 78 Int_t iGoodInj=0;
79 Int_t iAverSpeed=0;
40b3a8c7 80 for(Int_t i=firstmod; i<lastmod; i++){
266a4b47 81 Int_t iMod=i+240;
b70dd7af 82 if(!kNoDraw){
2420973e 83 c0->Clear();
84 c0->Divide(2,1);
b70dd7af 85 }
40b3a8c7 86 Int_t i0=2*i;
87 Int_t i1=1+2*i;
88 vdriftarr0=(AliITSDriftSpeedArraySDD*)drspSDD->At(i0);
89 vdriftarr1=(AliITSDriftSpeedArraySDD*)drspSDD->At(i1);
915c0469 90 AliITSDriftSpeedSDD* vdrift0=0x0;
91 if(vdriftarr0) vdrift0=vdriftarr0->GetDriftSpeedObject(0);
92 AliITSDriftSpeedSDD* vdrift1=0x0;
93 if(vdriftarr1) vdrift1=vdriftarr1->GetDriftSpeedObject(0);
94
40b3a8c7 95 gvdr0[i]=new TGraph(0);
96 gvdr1[i]=new TGraph(0);
97 gvdr0[i]->SetMarkerStyle(7);
98 gvdr1[i]->SetMarkerStyle(7);
99 gvdr0[i]->SetMinimum(5.);
100 gvdr1[i]->SetMinimum(5.);
101 gvdr0[i]->SetMaximum(9.);
102 gvdr1[i]->SetMaximum(9.);
266a4b47 103 sprintf(tit,"Mod %d\n",iMod);
40b3a8c7 104 gvdr0[i]->SetTitle(tit);
105 gvdr1[i]->SetTitle(tit);
106
107 for(Int_t iAn=0; iAn<256; iAn++){
108 Float_t vel0=0;
915c0469 109 if(vdrift0) vel0=vdrift0->GetDriftSpeedAtAnode(iAn);
40b3a8c7 110 Float_t vel1=0;
915c0469 111 if(vdrift1) vel1=vdrift1->GetDriftSpeedAtAnode(iAn);
40b3a8c7 112 gvdr0[i]->SetPoint(iAn,(Float_t)iAn,vel0);
113 gvdr1[i]->SetPoint(iAn,(Float_t)iAn,vel1);
114 }
915c0469 115 if(vdriftarr0->GetInjectorStatus()>0) iGoodInj++;
116 else iAverSpeed++;
117 if(vdriftarr1->GetInjectorStatus()>0) iGoodInj++;
118 else iAverSpeed++;
119
50d25e98 120 printf(" Mod. %d \tStatusLR=%X %X \t v(an 128l)= %f",iMod,vdriftarr0->GetInjectorStatus(),vdriftarr1->GetInjectorStatus(),vdriftarr0->GetDriftSpeed(0,128));
915c0469 121 printf(" \t v(an 128r)= %f Degree=%d %d\n",vdriftarr1->GetDriftSpeed(0,128),vdrift0->GetDegreeofPoly(),vdrift1->GetDegreeofPoly());
2420973e 122
123 if(!kNoDraw){
124 c0->cd(1);
125 gvdr0[i]->Draw("AP");
126 gvdr0[i]->GetXaxis()->SetTitle("Anode");
127 gvdr0[i]->GetYaxis()->SetTitle("Vdrift (#mum/ns)");
128 c0->cd(2);
129 gvdr1[i]->Draw("AP");
130 gvdr1[i]->GetXaxis()->SetTitle("Anode");
131 gvdr1[i]->GetYaxis()->SetTitle("Vdrift (#mum/ns)");
132 c0->Update();
133 }
134
40b3a8c7 135 Float_t vel0=0;
915c0469 136 Float_t pd0=0;
137 if(vdrift0){
138 vel0=vdrift0->GetDriftSpeedAtAnode(128);
139 pd0=vdrift0->GetDegreeofPoly();
140 }
40b3a8c7 141 Float_t vel1=0;
915c0469 142 Float_t pd1=0;
143 if(vdrift1){
144 vel1=vdrift1->GetDriftSpeedAtAnode(128);
145 pd1=vdrift1->GetDegreeofPoly();
146 }
266a4b47 147 vvsmod0->SetPoint(vvsmod0->GetN(),(Float_t)iMod,vel0);
148 vvsmod1->SetPoint(vvsmod1->GetN(),(Float_t)iMod,vel1);
915c0469 149 poldegvsmod0->SetPoint(poldegvsmod0->GetN(),(Float_t)iMod,pd0);
150 poldegvsmod1->SetPoint(poldegvsmod1->GetN(),(Float_t)iMod,pd1);
151
152 for(Int_t ipar=0; ipar<=vdrift0->GetDegreeofPoly(); ipar++){
153 fPoly->SetParameter(ipar,vdrift0->GetDriftSpeedParameter(ipar));
154 }
155 if(vdrift0->GetDegreeofPoly()<3){
156 for(Int_t ipar=vdrift0->GetDegreeofPoly()+1; ipar<=3; ipar++) fPoly->SetParameter(ipar,0.);
157 }
158
159 anmaxvsmod0->SetPoint(anmaxvsmod0->GetN(),(Float_t)iMod,fPoly->GetMaximumX(0.,256.));
160 dvcevsmod0->SetPoint(dvcevsmod0->GetN(),(Float_t)iMod,fPoly->Eval(128)-fPoly->Eval(0));
161 dveevsmod0->SetPoint(dveevsmod0->GetN(),(Float_t)iMod,fPoly->Eval(256)-fPoly->Eval(0));
40b3a8c7 162
915c0469 163 for(Int_t ipar=0; ipar<=vdrift1->GetDegreeofPoly(); ipar++){
164 fPoly->SetParameter(ipar,vdrift1->GetDriftSpeedParameter(ipar));
165 }
166 if(vdrift1->GetDegreeofPoly()<3){
167 for(Int_t ipar=vdrift1->GetDegreeofPoly()+1; ipar<=3; ipar++) fPoly->SetParameter(ipar,0.);
168 }
169 anmaxvsmod1->SetPoint(anmaxvsmod1->GetN(),(Float_t)iMod,fPoly->GetMaximumX(0.,256.));
170 dvcevsmod1->SetPoint(dvcevsmod1->GetN(),(Float_t)iMod,fPoly->Eval(128)-fPoly->Eval(0));
171 dveevsmod1->SetPoint(dveevsmod1->GetN(),(Float_t)iMod,fPoly->Eval(256)-fPoly->Eval(0));
40b3a8c7 172 // getchar();
173 }
915c0469 174
175 printf("Number of half-modules with drift speed from injectors = %d\n",iGoodInj);
176 printf("Number of half-modules with average drift speed = %d\n",iAverSpeed);
177
40b3a8c7 178 TCanvas* c2;
179 c2=new TCanvas("c2","",1000,700);
180 vvsmod0->SetMarkerStyle(20);
181 vvsmod0->Draw("AP");
182 vvsmod0->GetXaxis()->SetTitle("Module Number");
183 vvsmod0->GetYaxis()->SetTitle("Vdrift (#mum/ns)");
184 vvsmod1->SetMarkerStyle(21);
185 vvsmod1->SetMarkerColor(2);
186 vvsmod1->Draw("SAMEP");
b70dd7af 187 TLatex* tleft=new TLatex(0.2,0.82,"Side 0");
40b3a8c7 188 tleft->SetNDC();
189 tleft->SetTextColor(1);
190 tleft->Draw();
b70dd7af 191 TLatex* tright=new TLatex(0.2,0.75,"Side 1");
40b3a8c7 192 tright->SetNDC();
193 tright->SetTextColor(2);
194 tright->Draw();
195
915c0469 196 TCanvas* c3;
197 c3=new TCanvas("c3","",900,900);
198 c3->Divide(2,2);
199
200 c3->cd(1);
201 gPad->SetLeftMargin(0.14);
202 poldegvsmod0->SetMarkerStyle(20);
203 poldegvsmod0->Draw("AP");
204 poldegvsmod0->GetXaxis()->SetTitle("Module Number");
205 poldegvsmod0->GetYaxis()->SetTitle("Degree of Polynomial fit");
206 poldegvsmod0->GetYaxis()->SetTitleOffset(1.4);
207 poldegvsmod1->SetMarkerStyle(21);
208 poldegvsmod1->SetMarkerColor(2);
209 poldegvsmod1->Draw("SAMEP");
210 tleft->Draw();
211 tright->Draw();
212 c3->cd(2);
213 gPad->SetLeftMargin(0.14);
214 anmaxvsmod0->SetMarkerStyle(20);
215 anmaxvsmod0->Draw("AP");
216 anmaxvsmod0->GetXaxis()->SetTitle("Module Number");
217 anmaxvsmod0->GetYaxis()->SetTitle("Anode with max. drift speed");
218 anmaxvsmod0->GetYaxis()->SetTitleOffset(1.4);
219 anmaxvsmod1->SetMarkerStyle(21);
220 anmaxvsmod1->SetMarkerColor(2);
221 anmaxvsmod1->Draw("SAMEP");
222 tleft->Draw();
223 tright->Draw();
224 c3->cd(3);
225 gPad->SetLeftMargin(0.14);
226 dvcevsmod0->SetMarkerStyle(20);
227 dvcevsmod0->Draw("AP");
228 dvcevsmod0->GetXaxis()->SetTitle("Module Number");
229 dvcevsmod0->GetYaxis()->SetTitle("vdrift(anode128)-vdrift(anode0)");
230 dvcevsmod0->GetYaxis()->SetTitleOffset(1.4);
231 dvcevsmod1->SetMarkerStyle(21);
232 dvcevsmod1->SetMarkerColor(2);
233 dvcevsmod1->Draw("SAMEP");
234 tleft->Draw();
235 tright->Draw();
236 c3->cd(4);
237 gPad->SetLeftMargin(0.14);
238 dveevsmod0->SetMarkerStyle(20);
239 dveevsmod0->Draw("AP");
240 dveevsmod0->GetYaxis()->SetTitleOffset(1.4);
241 dveevsmod0->GetXaxis()->SetTitle("Module Number");
242 dveevsmod0->GetYaxis()->SetTitle("vdrift(anode256)-vdrift(anode0)");
243 dveevsmod1->SetMarkerStyle(21);
244 dveevsmod1->SetMarkerColor(2);
245 dveevsmod1->Draw("SAMEP");
246 tleft->Draw();
247 tright->Draw();
248
249
40b3a8c7 250}
251
252
253
2420973e 254void ShowDriftSpeedSDD(Int_t nrun, Int_t year=2010){
40b3a8c7 255 TGrid::Connect("alien:",0,0,"t");
551eb942 256 TString cmd=Form("gbbox find \"/alice/data/%d/OCDB/ITS/Calib/DriftSpeedSDD\" \"Run%d*.root\" > run.txt",year,nrun);
257 gSystem->Exec(cmd.Data());
258
259 Char_t filnam[200],filnamalien[200];
260 FILE* runtxt=fopen("run.txt","r");
261 fscanf(runtxt,"%s\n",filnam);
262 if(!strstr(filnam,"/alice/data/")){
263 printf("Bad run number\n");
264 gSystem->Exec("rm run.txt");
265 return;
266 }
267 sprintf(filnamalien,"alien://%s",filnam);
268
269 printf("Open file: %s\n",filnamalien);
b70dd7af 270 ShowDriftSpeedSDD(filnamalien,0,260,nrun);
551eb942 271 fclose(runtxt);
272 gSystem->Exec("rm run.txt");
273
40b3a8c7 274}