Changes for report #76227: ZDC TDC info in ESD and physics selection (for release...
[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=2010, Int_t firstRun=111000, 
35                    Int_t lastRun=999999999, 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("Calib%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,900,700);
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) haxis1 = gPad->DrawFrame(firstRun-100, 20, lastRun+100, 90);
118    else  haxis1 = gPad->DrawFrame(firstRun-100, 200, lastRun+100, 700);
119    haxis1->GetXaxis()->SetNoExponent();
120    haxis1->SetXTitle("RUN no.");
121    haxis1->SetYTitle("ZNC pedestals");
122    //
123    graph[ic]->SetMarkerStyle(20);
124    graph[ic]->SetMarkerColor(kBlue);
125    graph[ic]->Draw("P, SAME");
126    // *** ZPC pedestals
127    cHadPeds->cd(ic+6);
128    //
129    TH1F *haxis2=0;
130    if(ipedGainChain==0) haxis2= gPad->DrawFrame(firstRun-100, 20, lastRun+100, 90);
131    else  haxis2 = gPad->DrawFrame(firstRun-100, 200, lastRun+100, 700);
132    haxis2->GetXaxis()->SetNoExponent();
133    haxis2->SetXTitle("RUN no.");
134    haxis2->SetYTitle("ZPC pedestals");
135    //
136    graph[ic+5]->SetMarkerStyle(21);
137    graph[ic+5]->SetMarkerColor(kBlue+3);
138    graph[ic+5]->Draw("P, SAME");
139    // *** ZNA pedestals
140    cHadPeds->cd(ic+11);
141    //
142    TH1F *haxis3=0;
143    if(ipedGainChain==0) haxis3 = gPad->DrawFrame(firstRun-100, 20, lastRun+100, 90);
144    else  haxis3 = gPad->DrawFrame(firstRun-100, 200, lastRun+100, 700);
145    haxis3->GetXaxis()->SetNoExponent();
146    haxis3->SetXTitle("RUN no.");
147    haxis3->SetYTitle("ZNA pedestals");
148    //
149    graph[ic+12]->SetMarkerStyle(20);
150    graph[ic+12]->SetMarkerColor(kRed);
151    graph[ic+12]->Draw("P, SAME");
152    // *** ZPA pedestals
153    cHadPeds->cd(ic+16);
154    //
155    TH1F *haxis4=0;
156    if(ipedGainChain==0) haxis4 = gPad->DrawFrame(firstRun-100, 20, lastRun+100, 90);
157    else  haxis4 = gPad->DrawFrame(firstRun-100, 200, lastRun+100, 700);
158    haxis4->GetXaxis()->SetNoExponent();
159    haxis4->SetXTitle("RUN no.");
160    haxis4->SetYTitle("ZPA pedestals");
161    //
162    graph[ic+17]->SetMarkerStyle(21);
163    graph[ic+17]->SetMarkerColor(kRed+1);
164    graph[ic+17]->Draw("P, SAME");
165  }
166  cHadPeds->SaveAs("ZDCPedvsTime1.gif");
167
168  TCanvas *cothPeds = new TCanvas("cothPeds","ZEM + Ref. pedestals",800,0,600,600);
169  cothPeds->Divide(2,2);
170  for(int ic=0; ic<2; ic++){
171     // *** ZEM pedestals
172     cothPeds->cd(ic+1);
173     //
174     TH1F *haxis5=0;
175     if(ipedGainChain==0) haxis5 = gPad->DrawFrame(firstRun-100, 20, lastRun+20, 90);
176     else  haxis5 = gPad->DrawFrame(firstRun-100, 200, lastRun+100, 700);
177     haxis5->GetXaxis()->SetNoExponent();
178     haxis5->SetXTitle("RUN no.");
179     haxis5->SetYTitle("ZEM pedestals");
180     //
181     graph[ic+10]->SetMarkerStyle(22);
182     graph[ic+10]->SetMarkerColor(kGreen+1);
183     graph[ic+10]->Draw("P, SAME");
184     // *** Ref. pedestals
185     cothPeds->cd(ic+3);
186     //
187     TH1F *haxis6=0; 
188     if(ipedGainChain==0) haxis6 = gPad->DrawFrame(firstRun-100, 20, lastRun+100, 90);
189     else  haxis6 = gPad->DrawFrame(firstRun-100, 150, lastRun+100, 700);
190     haxis6->GetXaxis()->SetNoExponent();
191     haxis6->SetXTitle("RUN no.");
192     haxis6->SetYTitle("PMRef. pedestals");
193     //
194     graph[ic+22]->SetMarkerStyle(23);
195     graph[ic+22]->SetMarkerColor(kGreen+4);
196     graph[ic+22]->Draw("P, SAME");
197  }
198  cothPeds->SaveAs("ZDCPedvsTime2.gif");
199  
200 }