LHAPDF veraion 5.9.1
[u/mrichter/AliRoot.git] / ZDC / PlotPedestalsvsTime.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <Riostream.h>
3 #include <TSystem.h>
4 #include <TRandom.h>
5 #include <TROOT.h>
6 #include <TStyle.h>
7 #include <TCanvas.h>
8 #include <TGraphErrors.h>
9 #include <TGrid.h>
10 #include <TFile.h>
11 #include "AliCDBEntry.h"
12 #include "AliCDBGrid.h"
13 #include "AliCDBId.h"
14 #include "AliCDBLocal.h"
15 #include "AliCDBManager.h"
16 #include "AliCDBMetaData.h"
17 #include "AliCDBPath.h"
18 #include "AliCDBRunRange.h"
19 #include "AliCDBStorage.h"
20 #include "AliDCSValue.h"
21 #include "AliZDC.h"
22 #include "AliZDCv3.h"
23 #include "AliZDCPedestals.h"
24 #include "AliZDCEnCalib.h"
25 #include "AliZDCTowerCalib.h"
26 #include "AliZDCChMap.h"
27 #include "AliZDCLaserCalib.h"
28 #include "AliZDCMBCalib.h"
29 #include "AliZDCDataDCS.h"
30
31 #endif
32
33
34 void PlotPedestalsvsTime(Int_t year=2011, Int_t firstRun=141820, 
35                    Int_t lastRun=146900, Int_t ipedGainChain=0)
36 {
37
38
39   TGrid::Connect("alien:",0,0,"t");
40   gSystem->Exec(Form("gbbox find \"/alice/data/%d/OCDB/ZDC/Calib/Pedestals/\" \"Run*.root\" > calibAlienFiles.txt",year));
41   FILE* listruns=fopen("calibAlienFiles.txt","r");
42   
43   const int kNchannels=24;
44   TGraphErrors* graph[24];
45   for(Int_t i=0; i<kNchannels; i++){
46      graph[i] = new TGraphErrors(0);
47      char name[50], title[50];
48      sprintf(name,"graph%d",i); sprintf(title,"Pedestal ch.%d vs. run#",i);
49      graph[i]->SetName("graph");  graph[i]->SetTitle("title");
50   }
51
52   Char_t filnam[200], filnamalien[200];
53   Int_t iPoint=0;
54   Int_t nrun, nrun2, nv, ns;
55
56   while(!feof(listruns)){
57     int st = fscanf(listruns,"%s\n",filnam);    
58     Char_t directory[100];
59     sprintf(directory,"/alice/data/%d",year);
60     if(!strstr(filnam,directory)) continue;
61     sscanf(filnam,"/alice/data/%d/OCDB/ZDC/Calib/Pedestals/Run%d_%d_v%d_s%d.root",&year,&nrun,&nrun2,&nv,&ns);
62     if(nrun<firstRun) continue;
63     if(nrun>lastRun) continue;
64     sprintf(filnamalien,"alien://%s",filnam);
65     printf("Opening file: %s\n",filnam);
66     TFile *f = TFile::Open(filnamalien);  
67     AliCDBEntry *entry = (AliCDBEntry*)f->Get("AliCDBEntry");
68     AliZDCPedestals *calibdata = dynamic_cast<AliZDCPedestals*>  (entry->GetObject());
69     
70     for(int i=0; i<kNchannels; i++){
71       if(ipedGainChain==0){
72         graph[i]->SetPoint(iPoint, (Double_t)nrun, calibdata->GetMeanPed(i));
73         graph[i]->SetPointError(iPoint, 0., calibdata->GetMeanPedWidth(i));
74       }
75       else{
76         graph[i]->SetPoint(iPoint, (Double_t)nrun, calibdata->GetMeanPed(i+kNchannels));
77         graph[i]->SetPointError(iPoint, 0., calibdata->GetMeanPedWidth(i+kNchannels));
78       }
79     }
80     iPoint++;
81     f->Close();
82  }
83
84  TFile *outfile=new TFile(Form("PedCalib%dVsTime.root",year),"recreate");
85  outfile->cd();
86  for(int i=0; i<kNchannels; i++) graph[i]->Write();
87  outfile->Close();
88
89  //***********************************************************
90  // #### ROOT initialization
91  gROOT->Reset();
92  gStyle->SetCanvasColor(10);
93  gStyle->SetFrameFillColor(10);
94  gStyle->SetOptTitle(0);
95  gStyle->SetOptStat(1111);
96  gStyle->SetOptFit(0);
97  gStyle->SetTitleTextColor(4);
98  gStyle->SetStatTextColor(4);
99  gStyle->SetStatX(0.92);
100  gStyle->SetStatY(0.92);
101  gStyle->SetLineColor(1);
102  gStyle->SetPalette(1);
103  gStyle->SetPadTopMargin(0.05);
104  gStyle->SetPadRightMargin(0.05);
105  gStyle->SetPadBottomMargin(0.09);
106  gStyle->SetPadLeftMargin(0.09); 
107  gStyle->SetTitleOffset(1.1,"Y");  
108  // *************************************************************
109
110  TCanvas *cHadPeds = new TCanvas("cHadPeds","Hadronic ZDC pedestals",0,0,1000,800);
111  cHadPeds->Divide(5,4);
112  for(int ic=0; ic<5; ic++){
113    // *** ZNC pedestals
114    cHadPeds->cd(ic+1);
115    //
116    TH1F *haxis1=0;
117    if(ipedGainChain==0){
118      if(ic==0) haxis1 = gPad->DrawFrame(firstRun-100, 80, lastRun+100, 100);
119      else  haxis1 = gPad->DrawFrame(firstRun-100, 50, lastRun+100, 70);
120    }
121    else{
122      if(ic==0) haxis1 = gPad->DrawFrame(firstRun-100, 500, lastRun+100, 800);
123      else  haxis1 = gPad->DrawFrame(firstRun-100, 300, lastRun+100, 600);
124    }
125    haxis1->GetXaxis()->SetNoExponent();
126    haxis1->SetXTitle("RUN no.");
127    haxis1->SetYTitle("ZNC pedestals");
128    //
129    graph[ic]->SetMarkerStyle(20);
130    graph[ic]->SetMarkerColor(kBlue);
131    graph[ic]->Draw("P, SAME");
132    // *** ZPC pedestals
133    cHadPeds->cd(ic+6);
134    //
135    TH1F *haxis2=0;
136    if(ipedGainChain==0) haxis2= gPad->DrawFrame(firstRun-100, 55, lastRun+100, 85);
137    else  haxis2 = gPad->DrawFrame(firstRun-100, 400, lastRun+100, 700);
138    haxis2->GetXaxis()->SetNoExponent();
139    haxis2->SetXTitle("RUN no.");
140    haxis2->SetYTitle("ZPC pedestals");
141    //
142    graph[ic+5]->SetMarkerStyle(21);
143    graph[ic+5]->SetMarkerColor(kBlue+3);
144    graph[ic+5]->Draw("P, SAME");
145    // *** ZNA pedestals
146    cHadPeds->cd(ic+11);
147    //
148    TH1F *haxis3=0;
149    if(ipedGainChain==0) haxis3 = gPad->DrawFrame(firstRun-100, 35, lastRun+100, 85);
150    else  haxis3 = gPad->DrawFrame(firstRun-100, 300, lastRun+100, 700);
151    haxis3->GetXaxis()->SetNoExponent();
152    haxis3->SetXTitle("RUN no.");
153    haxis3->SetYTitle("ZNA pedestals");
154    //
155    graph[ic+12]->SetMarkerStyle(20);
156    graph[ic+12]->SetMarkerColor(kRed);
157    graph[ic+12]->Draw("P, SAME");
158    // *** ZPA pedestals
159    cHadPeds->cd(ic+16);
160    //
161    TH1F *haxis4=0;
162    if(ipedGainChain==0) haxis4 = gPad->DrawFrame(firstRun-100, 40, lastRun+100, 80);
163    else  haxis4 = gPad->DrawFrame(firstRun-100, 300, lastRun+100, 600);
164    haxis4->GetXaxis()->SetNoExponent();
165    haxis4->SetXTitle("RUN no.");
166    haxis4->SetYTitle("ZPA pedestals");
167    //
168    graph[ic+17]->SetMarkerStyle(21);
169    graph[ic+17]->SetMarkerColor(kRed+1);
170    graph[ic+17]->Draw("P, SAME");
171  }
172  cHadPeds->SaveAs("ZDCPedvsTime1.gif");
173  cHadPeds->SaveAs("ZDCPedvsTime1.C");
174
175  TCanvas *cothPeds = new TCanvas("cothPeds","ZEM + Ref. pedestals",800,0,600,600);
176  cothPeds->Divide(2,2);
177  for(int ic=0; ic<2; ic++){
178     // *** ZEM pedestals
179     cothPeds->cd(ic+1);
180     //
181     TH1F *haxis5=0;
182     if(ipedGainChain==0) haxis5 = gPad->DrawFrame(firstRun-100, 30, lastRun+20, 70);
183     else  haxis5 = gPad->DrawFrame(firstRun-100, 250, lastRun+100, 550);
184     haxis5->GetXaxis()->SetNoExponent();
185     haxis5->SetXTitle("RUN no.");
186     haxis5->SetYTitle("ZEM pedestals");
187     //
188     graph[ic+10]->SetMarkerStyle(22);
189     graph[ic+10]->SetMarkerColor(kGreen+1);
190     graph[ic+10]->Draw("P, SAME");
191     // *** Ref. pedestals
192     cothPeds->cd(ic+3);
193     //
194     TH1F *haxis6=0; 
195     if(ipedGainChain==0) haxis6 = gPad->DrawFrame(firstRun-100, 50, lastRun+100, 90);
196     else  haxis6 = gPad->DrawFrame(firstRun-100, 400, lastRun+100, 700);
197     haxis6->GetXaxis()->SetNoExponent();
198     haxis6->SetXTitle("RUN no.");
199     haxis6->SetYTitle("PMRef. pedestals");
200     //
201     graph[ic+22]->SetMarkerStyle(23);
202     graph[ic+22]->SetMarkerColor(kGreen+4);
203     graph[ic+22]->Draw("P, SAME");
204  }
205  cothPeds->SaveAs("ZDCPedvsTime2.gif");
206  cothPeds->SaveAs("ZDCPedvsTime2.C");
207  
208 }