Macros to chack SDD online calibrations updated for 2011 run
[u/mrichter/AliRoot.git] / ITS / macrosSDD / ShowResponseSDD.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TFile.h>
3 #include <TH1F.h>
4 #include <TH2I.h>
5 #include <TGraph.h>
6 #include <TExec.h>
7 #include <TStyle.h>
8 #include <TString.h>
9 #include <TSystem.h>
10 #include <TGrid.h>
11 #include <TLatex.h>
12 #include <TCanvas.h>
13 #include <TObjArray.h>
14 #include "AliCDBEntry.h"
15 #include "AliITSresponseSDD.h"
16 #endif
17
18 /*  $Id: ShowResponseSDD.C 44072 2010-10-04 15:48:32Z prino $    */
19
20 // Macro to plot the calibration parameters 
21 // (time zero, ADCtokeV and Vdrift correction)
22 // from the OCDB file created from SDD offline calibration 
23 // (OCDB/ITS/Calib/RespSDD)
24
25 void ShowResponseSDD(TString filename="$ALICE_ROOT/OCDB/ITS/Calib/RespSDD/Run0_999999999_v0_s0.root"){
26   if(filename.Contains("alien")){
27     TGrid::Connect("alien:");
28   }
29   TFile* fr=TFile::Open(filename.Data());
30   AliCDBEntry* e=(AliCDBEntry*)fr->Get("AliCDBEntry");
31   AliITSresponseSDD* r=(AliITSresponseSDD*)e->GetObject();
32   TH1F* hTimeZero=new TH1F("hTimeZero","",260,239.5,499.5);
33   TH1F* hVdriftCorrLeft=new TH1F("hVdriftCorrLeft","",260,239.5,499.5);
34   TH1F* hVdriftCorrRight=new TH1F("hVdriftCorrRight","",260,239.5,499.5);
35   TH1F* hdistVdriftCorrLeft=new TH1F("hdistVdriftCorrLeft","",100,-0.2,0.2);
36   TH1F* hdistVdriftCorrRight=new TH1F("hdistVdriftCorrRight","",100,-0.2,0.2);
37   TH1F* hADCtokeV=new TH1F("hADCtokeV","",260,239.5,499.5);
38   Float_t averTz=0.;
39   Float_t averCv0=0.;
40   Float_t averCv1=0.;
41   Float_t averAk=0.;
42   for(Int_t iMod=240; iMod<500; iMod++){
43     Float_t tz=r->GetTimeZero(iMod);
44     Float_t cv0=r->GetDeltaVDrift(iMod,kFALSE);
45     Float_t cv1=r->GetDeltaVDrift(iMod,kTRUE);
46     Float_t ak=r->GetADCtokeV(iMod);
47     hTimeZero->SetBinContent(iMod-240+1,tz);    
48     hVdriftCorrLeft->SetBinContent(iMod-240+1,cv0);
49     hVdriftCorrRight->SetBinContent(iMod-240+1,cv1);
50     hdistVdriftCorrLeft->Fill(cv0);
51     hdistVdriftCorrRight->Fill(cv1);
52     hADCtokeV->SetBinContent(iMod-240+1,ak);
53     averTz+=tz;
54     averCv0+=cv0;
55     averCv1+=cv1;
56     averAk+=ak;
57   }
58   averTz/=260.;
59   averCv0/=260.;
60   averCv1/=260.;
61   averAk/=260.;
62
63   hTimeZero->SetMarkerStyle(20);
64   hADCtokeV->SetMarkerStyle(20);
65   hVdriftCorrLeft->SetMarkerStyle(22);
66   hVdriftCorrLeft->SetMarkerColor(2);
67   hVdriftCorrRight->SetMarkerStyle(24);
68   hVdriftCorrRight->SetMarkerColor(4);
69   hTimeZero->SetMaximum(hTimeZero->GetMaximum()*1.2);
70   hADCtokeV->SetMaximum(hADCtokeV->GetMaximum()*1.2);
71   Float_t maxV=TMath::Max(hVdriftCorrLeft->GetMaximum(),hVdriftCorrRight->GetMaximum());
72   Float_t minV=TMath::Min(hVdriftCorrLeft->GetMinimum(),hVdriftCorrRight->GetMinimum());
73   Float_t scale=TMath::Max(TMath::Abs(maxV),TMath::Abs(minV));
74   if(scale<0.02){
75     hVdriftCorrLeft->SetMinimum(-0.05);
76     hVdriftCorrLeft->SetMaximum(0.05);
77   }else{
78     hVdriftCorrLeft->SetMaximum(1.2*scale);
79     hVdriftCorrLeft->SetMinimum(-1.2*scale);
80   }
81
82   //  gStyle->SetOptStat(0);
83
84   printf("Charge vs. Time correction factor = %f\n",r->GetChargevsTime());
85
86   TCanvas* c1=new TCanvas("c1","Time Zero");
87   hTimeZero->Draw("P");
88   hTimeZero->GetXaxis()->SetTitle("Module Id");
89   hTimeZero->GetYaxis()->SetTitle("Time Zero (ns)");
90   TLatex* tt=new TLatex(0.2,0.8,Form("Average Tzero = %.2f",averTz));
91   tt->SetNDC();
92   tt->Draw();
93   c1->Modified();
94
95   TCanvas* c2=new TCanvas("c2","Vdrift Corr");
96   hVdriftCorrLeft->Draw("P");
97   hVdriftCorrRight->Draw("PSAME");
98   hVdriftCorrLeft->GetXaxis()->SetTitle("Module Id");
99   hVdriftCorrLeft->GetYaxis()->SetTitle("Vdrift correction (#mum/ns)");
100   TLatex* tc0=new TLatex(0.2,0.8,Form("Average Vdrift corr Left = %.3f",averCv0));
101   tc0->SetNDC();
102   tc0->SetTextColor(2);
103   tc0->Draw();
104   TLatex* tc1=new TLatex(0.2,0.72,Form("Average Vdrift corr Right = %.3f",averCv1));
105   tc1->SetNDC();
106   tc1->SetTextColor(4);
107   tc1->Draw();
108   c2->Modified();
109
110   TCanvas* c2b=new TCanvas("c2b","Vdrift Corr");
111   hdistVdriftCorrLeft->Draw(); 
112   hdistVdriftCorrRight->SetLineColor(2);
113   hdistVdriftCorrRight->Draw("SAMES");
114   hdistVdriftCorrLeft->GetXaxis()->SetTitle("Vdrift correction (#mum/ns)");
115   c2b->Modified();
116
117   TCanvas* c3=new TCanvas("c3","ADC calib");
118   hADCtokeV->Draw("P");
119   hADCtokeV->GetXaxis()->SetTitle("Module Id");
120   hADCtokeV->GetYaxis()->SetTitle("ADC to keV conv. factor");
121   TLatex* ta=new TLatex(0.2,0.8,Form("Average ADCtokeV = %.3f",averAk));
122   ta->SetNDC();
123   ta->Draw(); 
124   TLatex* tb=new TLatex(0.2,0.72,Form("Charge vs. Time correction factor = %f\n",r->GetChargevsTime()));
125   tb->SetNDC();
126   tb->SetTextColor(kGreen+1);
127   tb->Draw();
128   c3->Modified();
129
130 }