ROOT logo
#if !defined(__CINT__) || defined(__MAKECINT__)
#include <TFile.h>
#include <TH1F.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TStyle.h>
#include <TGrid.h>
#include <TCanvas.h>
#include <TSystem.h>
#include <TLatex.h>
#include <TLegend.h>
#include <TLegendEntry.h>
#include <TObjArray.h>
#include "AliCDBEntry.h"
#include "AliITSCalibrationSDD.h"
#endif

/*  $Id: PlotCalibSDDVsTime.C 41568 2010-06-03 09:08:39Z prino $    */

// Macro to plot the calibration parameters from the OCDB files 
// created from PEDESTAL and PULSER runs vs. Time
// Origin: F. Prino (prino@to.infn.it)

void PlotCalibSDDVsTime(Int_t year=2012, Int_t firstRun=172600, 
			Int_t lastRun=999999999,
			Int_t selectedMod=-1){

  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetPadLeftMargin(0.14);
  gStyle->SetTitleOffset(1.4,"Y");  


  TGrid::Connect("alien:",0,0,"t");
  gSystem->Exec(Form("gbbox find \"/alice/data/%d/OCDB/ITS/Calib/CalibSDD\" \"Run*.root\" > runCalibAlien.txt",year));
  FILE* listruns=fopen("runCalibAlien.txt","r");

  TH1F* hbase=new TH1F("hbase","",60,0.5,120.5);
  TH1F* hnoise=new TH1F("hnoise","",100,0.,7.);
  TH1F* hgain=new TH1F("hgain","",100,0.,4.);
  TH1F* hchstatus=new TH1F("hchstatus","",2,-0.5,1.5);
  TH1F* hchstatus3=new TH1F("hchstatus3","",2,-0.5,1.5);
  TH1F* hchstatus4=new TH1F("hchstatus4","",2,-0.5,1.5);
  TGraphErrors* gbasevstim=new TGraphErrors(0);
  TGraphErrors* gnoisevstim=new TGraphErrors(0);
  TGraphErrors* ggainvstim=new TGraphErrors(0);
  TGraphErrors* gstatvstim=new TGraphErrors(0);
  TGraphErrors* gfracvstim=new TGraphErrors(0);
  TGraphErrors* gfrac3vstim=new TGraphErrors(0);
  TGraphErrors* gfrac4vstim=new TGraphErrors(0);
  gbasevstim->SetName("gbasevstim");
  gnoisevstim->SetName("gnoisevstim");
  ggainvstim->SetName("ggainvstim");
  gstatvstim->SetName("gstatvstim");
  gfracvstim->SetName("gfracvstim");
  gfrac3vstim->SetName("gfrac3vstim");
  gfrac4vstim->SetName("gfrac4vstim");
  gbasevstim->SetTitle("Baseline vs. run");
  gnoisevstim->SetTitle("Noise vs. run");
  ggainvstim->SetTitle("Gain vs. run");
  gstatvstim->SetTitle("Good Anodes vs. run");
  gfracvstim->SetTitle("Fraction of Good Anodes vs. run");
  gfrac3vstim->SetTitle("Fraction of Good Anodes vs. run");
  gfrac4vstim->SetTitle("Fraction of Good Anodes vs. run");


  Char_t filnam[200],filnamalien[200];
  Int_t iPoint=0;
  Int_t nrun,nrun2,nv,ns;

  while(!feof(listruns)){
    hbase->Reset();
    hnoise->Reset();
    hgain->Reset();
    hchstatus->Reset();
    hchstatus3->Reset();
    hchstatus4->Reset();
    fscanf(listruns,"%s\n",filnam);    
    Char_t directory[100];
    sprintf(directory,"/alice/data/%d",year);
    if(!strstr(filnam,directory)) continue;
    sscanf(filnam,"/alice/data/%d/OCDB/ITS/Calib/CalibSDD/Run%d_%d_v%d_s%d.root",&year,&nrun,&nrun2,&nv,&ns);
    if(year==2009 && (nrun<85639 && nrun2> 85639)) continue; // protection for files with swapped ladders 4-5 of layer 3 
    if(year==2009 && (nrun>100000 && nv< 184)) continue; // protection for files with swapped ladder 0-1 of layer 4
    if(year==2010 && (nrun>=114603 && nv< 98)) continue; // protection for files without treatment of masked hybrids 
    if(year==2011 && (nrun>=145349 && nrun<=148978) && nrun2> 148978) continue; // protection for files affected by problem in second DA
    if(year==2011 && nrun==156856) continue;
    if(nrun<firstRun) continue;
    if(nrun>lastRun) continue;
    sprintf(filnamalien,"alien://%s",filnam);
    printf("Open file: %s\n",filnam);
    TFile *f= TFile::Open(filnamalien);  
    AliCDBEntry *ent=(AliCDBEntry*)f->Get("AliCDBEntry");
    TObjArray *calSDD = (TObjArray *)ent->GetObject();
    printf("Run %d Entries in array=%d \n",nrun,calSDD->GetEntriesFast());


    AliITSCalibrationSDD *cal;
    for(Int_t iMod=0; iMod<260;iMod++){
      if(selectedMod>=240 && (iMod+240)!=selectedMod) continue;
      cal=(AliITSCalibrationSDD*)calSDD->At(iMod);
      if(cal==0) continue;
      for(Int_t iAn=0; iAn<512; iAn++){
	Int_t ic=cal->GetChip(iAn);
	Float_t base=cal->GetBaseline(iAn);
	Float_t noise=cal->GetNoiseAfterElectronics(iAn);
	Float_t gain=cal->GetChannelGain(iAn);
	if(cal->IsBadChannel(iAn)){
	  hchstatus->Fill(0);
	  if(iMod<84) hchstatus3->Fill(0);
	  else hchstatus4->Fill(0);
	}
	if(!cal->IsBadChannel(iAn) && !cal->IsChipBad(ic) && !cal->IsBad() ){
	  hbase->Fill(base);
	  hchstatus->Fill(1);
	  if(iMod<84) hchstatus3->Fill(1);
	  else hchstatus4->Fill(1);
	  hnoise->Fill(noise);
	  hgain->Fill(gain);
	}
      } 
    }
    printf("Run %d <Base> = %f <Noise> =%f Entries = %d\n",nrun,hbase->GetMean(),hnoise->GetMean(),(Int_t)hbase->GetEntries());
    if(selectedMod==-1 && (Int_t)hbase->GetEntries()==0) continue;
    gbasevstim->SetPoint(iPoint,(Double_t)nrun,hbase->GetMean());
    gbasevstim->SetPointError(iPoint,0.,hbase->GetRMS());
    gnoisevstim->SetPoint(iPoint,(Double_t)nrun,hnoise->GetMean());
    gnoisevstim->SetPointError(iPoint,0.,hnoise->GetRMS());
    ggainvstim->SetPoint(iPoint,(Double_t)nrun,hgain->GetMean());
    ggainvstim->SetPointError(iPoint,0.,hgain->GetRMS());
    gstatvstim->SetPoint(iPoint,(Double_t)nrun,hchstatus->GetBinContent(2));
    Float_t normMod=260.;
    if(selectedMod!=-1) normMod=1.;
    gfracvstim->SetPoint(iPoint,(Double_t)nrun,hchstatus->GetBinContent(2)/normMod/512.);
    gfrac3vstim->SetPoint(iPoint,(Double_t)nrun,hchstatus3->GetBinContent(2)/84./512.);
    gfrac4vstim->SetPoint(iPoint,(Double_t)nrun,hchstatus4->GetBinContent(2)/176./512.);
    iPoint++;
    f->Close();
  }

  TFile *ofil=new TFile(Form("Calib%dVsTime.root",year),"recreate");
  gbasevstim->Write();
  gnoisevstim->Write();
  ggainvstim->Write();
  gstatvstim->Write();
  ofil->Close();

  TCanvas* cbase=new TCanvas("cbase","Baselines");
  gbasevstim->SetFillColor(kOrange-2);
  gbasevstim->SetMarkerStyle(20);
  gbasevstim->Draw("AP3");
  gbasevstim->Draw("PLXSAME");
  gbasevstim->SetMinimum(0.);
  gbasevstim->SetMaximum(70.);  
  gbasevstim->GetXaxis()->SetTitle("Run number");
  gbasevstim->GetYaxis()->SetTitle("<Baseline> (ADC counts)");
  cbase->SaveAs(Form("BaseRun%d.gif",year));

  TCanvas* cnoise=new TCanvas("cnoise","Noise");
  gnoisevstim->SetFillColor(kOrange-2);
  gnoisevstim->SetMarkerStyle(20);
  gnoisevstim->Draw("AP3");
  gnoisevstim->Draw("PLXSAME");
  gnoisevstim->SetMinimum(0.);
  gnoisevstim->SetMaximum(4.);
  gnoisevstim->GetXaxis()->SetTitle("Run number");
  gnoisevstim->GetYaxis()->SetTitle("<Noise> (ADC counts)");
  cnoise->SaveAs(Form("NoiseRun%d.gif",year));

  TCanvas* cgain=new TCanvas("cgain","Gain");
  ggainvstim->SetFillColor(kOrange-2);
  ggainvstim->SetMarkerStyle(20);
  ggainvstim->Draw("AP3");
  ggainvstim->Draw("PLXSAME");
  ggainvstim->SetMinimum(0.);
  ggainvstim->SetMaximum(4.);
  ggainvstim->GetXaxis()->SetTitle("Run number");
  ggainvstim->GetYaxis()->SetTitle("<Gain> (ADC/DAC)");
  cgain->SaveAs(Form("GainRun%d.gif",year));

  TCanvas* cstatus=new TCanvas("cstatus","Good channels");
  gstatvstim->SetFillColor(kOrange-2);
  gstatvstim->SetMarkerStyle(20);
  gstatvstim->Draw("AP3");
  gstatvstim->Draw("PLXSAME");
  if(selectedMod==-1){
    gstatvstim->SetMinimum(100000.);
    gstatvstim->SetMaximum(133000.);
  }else{
    gstatvstim->SetMinimum(0.);
    gstatvstim->SetMaximum(512.);
  }
  gstatvstim->GetXaxis()->SetTitle("Run number");
  if(selectedMod==-1){
    gstatvstim->GetYaxis()->SetTitle("Number of good anodes in acquisition");
  }else{
    gstatvstim->GetYaxis()->SetTitle(Form("Number of good anodes in od %d",selectedMod));
  }
  cstatus->SaveAs(Form("GoodAnodesRun%d.gif",year));

  TCanvas* cfrac=new TCanvas("cfrac","Fraction of Good");
  gfracvstim->SetMarkerStyle(20);
  gfrac3vstim->SetMarkerStyle(22);
  gfrac3vstim->SetMarkerColor(2);
  gfrac3vstim->SetLineColor(2);
  gfrac4vstim->SetMarkerStyle(23);
  gfrac4vstim->SetMarkerColor(4);
  gfrac4vstim->SetLineColor(4);
  gfracvstim->Draw("APL");
  gfracvstim->SetMinimum(0.7);
  gfracvstim->SetMaximum(1.05);
  gfracvstim->GetXaxis()->SetTitle("Run number");
  if(selectedMod==-1){
    gfracvstim->GetYaxis()->SetTitle("Fraction of good anodes in acquisition");
    gfrac3vstim->Draw("PLSAME");
    gfrac4vstim->Draw("PLSAME");
  
    TLegend* leg=new TLegend(0.2,0.15,0.45,0.35);
    leg->SetFillColor(0);
    TLegendEntry* entr=leg->AddEntry(gfrac3vstim,"Layer 3","P");
    entr->SetTextColor(2);
    entr=leg->AddEntry(gfrac4vstim,"Layer 4","P");
    entr->SetTextColor(4);
    entr=leg->AddEntry(gfracvstim,"All","P");
    entr->SetTextColor(1);
    leg->Draw();
  }else{
    gfracvstim->GetYaxis()->SetTitle(Form("Fraction of good anodes in mod %d",selectedMod));
  }
  cfrac->SaveAs(Form("FractionGoodRun%d.gif",year));

}
 PlotCalibSDDVsTime.C:1
 PlotCalibSDDVsTime.C:2
 PlotCalibSDDVsTime.C:3
 PlotCalibSDDVsTime.C:4
 PlotCalibSDDVsTime.C:5
 PlotCalibSDDVsTime.C:6
 PlotCalibSDDVsTime.C:7
 PlotCalibSDDVsTime.C:8
 PlotCalibSDDVsTime.C:9
 PlotCalibSDDVsTime.C:10
 PlotCalibSDDVsTime.C:11
 PlotCalibSDDVsTime.C:12
 PlotCalibSDDVsTime.C:13
 PlotCalibSDDVsTime.C:14
 PlotCalibSDDVsTime.C:15
 PlotCalibSDDVsTime.C:16
 PlotCalibSDDVsTime.C:17
 PlotCalibSDDVsTime.C:18
 PlotCalibSDDVsTime.C:19
 PlotCalibSDDVsTime.C:20
 PlotCalibSDDVsTime.C:21
 PlotCalibSDDVsTime.C:22
 PlotCalibSDDVsTime.C:23
 PlotCalibSDDVsTime.C:24
 PlotCalibSDDVsTime.C:25
 PlotCalibSDDVsTime.C:26
 PlotCalibSDDVsTime.C:27
 PlotCalibSDDVsTime.C:28
 PlotCalibSDDVsTime.C:29
 PlotCalibSDDVsTime.C:30
 PlotCalibSDDVsTime.C:31
 PlotCalibSDDVsTime.C:32
 PlotCalibSDDVsTime.C:33
 PlotCalibSDDVsTime.C:34
 PlotCalibSDDVsTime.C:35
 PlotCalibSDDVsTime.C:36
 PlotCalibSDDVsTime.C:37
 PlotCalibSDDVsTime.C:38
 PlotCalibSDDVsTime.C:39
 PlotCalibSDDVsTime.C:40
 PlotCalibSDDVsTime.C:41
 PlotCalibSDDVsTime.C:42
 PlotCalibSDDVsTime.C:43
 PlotCalibSDDVsTime.C:44
 PlotCalibSDDVsTime.C:45
 PlotCalibSDDVsTime.C:46
 PlotCalibSDDVsTime.C:47
 PlotCalibSDDVsTime.C:48
 PlotCalibSDDVsTime.C:49
 PlotCalibSDDVsTime.C:50
 PlotCalibSDDVsTime.C:51
 PlotCalibSDDVsTime.C:52
 PlotCalibSDDVsTime.C:53
 PlotCalibSDDVsTime.C:54
 PlotCalibSDDVsTime.C:55
 PlotCalibSDDVsTime.C:56
 PlotCalibSDDVsTime.C:57
 PlotCalibSDDVsTime.C:58
 PlotCalibSDDVsTime.C:59
 PlotCalibSDDVsTime.C:60
 PlotCalibSDDVsTime.C:61
 PlotCalibSDDVsTime.C:62
 PlotCalibSDDVsTime.C:63
 PlotCalibSDDVsTime.C:64
 PlotCalibSDDVsTime.C:65
 PlotCalibSDDVsTime.C:66
 PlotCalibSDDVsTime.C:67
 PlotCalibSDDVsTime.C:68
 PlotCalibSDDVsTime.C:69
 PlotCalibSDDVsTime.C:70
 PlotCalibSDDVsTime.C:71
 PlotCalibSDDVsTime.C:72
 PlotCalibSDDVsTime.C:73
 PlotCalibSDDVsTime.C:74
 PlotCalibSDDVsTime.C:75
 PlotCalibSDDVsTime.C:76
 PlotCalibSDDVsTime.C:77
 PlotCalibSDDVsTime.C:78
 PlotCalibSDDVsTime.C:79
 PlotCalibSDDVsTime.C:80
 PlotCalibSDDVsTime.C:81
 PlotCalibSDDVsTime.C:82
 PlotCalibSDDVsTime.C:83
 PlotCalibSDDVsTime.C:84
 PlotCalibSDDVsTime.C:85
 PlotCalibSDDVsTime.C:86
 PlotCalibSDDVsTime.C:87
 PlotCalibSDDVsTime.C:88
 PlotCalibSDDVsTime.C:89
 PlotCalibSDDVsTime.C:90
 PlotCalibSDDVsTime.C:91
 PlotCalibSDDVsTime.C:92
 PlotCalibSDDVsTime.C:93
 PlotCalibSDDVsTime.C:94
 PlotCalibSDDVsTime.C:95
 PlotCalibSDDVsTime.C:96
 PlotCalibSDDVsTime.C:97
 PlotCalibSDDVsTime.C:98
 PlotCalibSDDVsTime.C:99
 PlotCalibSDDVsTime.C:100
 PlotCalibSDDVsTime.C:101
 PlotCalibSDDVsTime.C:102
 PlotCalibSDDVsTime.C:103
 PlotCalibSDDVsTime.C:104
 PlotCalibSDDVsTime.C:105
 PlotCalibSDDVsTime.C:106
 PlotCalibSDDVsTime.C:107
 PlotCalibSDDVsTime.C:108
 PlotCalibSDDVsTime.C:109
 PlotCalibSDDVsTime.C:110
 PlotCalibSDDVsTime.C:111
 PlotCalibSDDVsTime.C:112
 PlotCalibSDDVsTime.C:113
 PlotCalibSDDVsTime.C:114
 PlotCalibSDDVsTime.C:115
 PlotCalibSDDVsTime.C:116
 PlotCalibSDDVsTime.C:117
 PlotCalibSDDVsTime.C:118
 PlotCalibSDDVsTime.C:119
 PlotCalibSDDVsTime.C:120
 PlotCalibSDDVsTime.C:121
 PlotCalibSDDVsTime.C:122
 PlotCalibSDDVsTime.C:123
 PlotCalibSDDVsTime.C:124
 PlotCalibSDDVsTime.C:125
 PlotCalibSDDVsTime.C:126
 PlotCalibSDDVsTime.C:127
 PlotCalibSDDVsTime.C:128
 PlotCalibSDDVsTime.C:129
 PlotCalibSDDVsTime.C:130
 PlotCalibSDDVsTime.C:131
 PlotCalibSDDVsTime.C:132
 PlotCalibSDDVsTime.C:133
 PlotCalibSDDVsTime.C:134
 PlotCalibSDDVsTime.C:135
 PlotCalibSDDVsTime.C:136
 PlotCalibSDDVsTime.C:137
 PlotCalibSDDVsTime.C:138
 PlotCalibSDDVsTime.C:139
 PlotCalibSDDVsTime.C:140
 PlotCalibSDDVsTime.C:141
 PlotCalibSDDVsTime.C:142
 PlotCalibSDDVsTime.C:143
 PlotCalibSDDVsTime.C:144
 PlotCalibSDDVsTime.C:145
 PlotCalibSDDVsTime.C:146
 PlotCalibSDDVsTime.C:147
 PlotCalibSDDVsTime.C:148
 PlotCalibSDDVsTime.C:149
 PlotCalibSDDVsTime.C:150
 PlotCalibSDDVsTime.C:151
 PlotCalibSDDVsTime.C:152
 PlotCalibSDDVsTime.C:153
 PlotCalibSDDVsTime.C:154
 PlotCalibSDDVsTime.C:155
 PlotCalibSDDVsTime.C:156
 PlotCalibSDDVsTime.C:157
 PlotCalibSDDVsTime.C:158
 PlotCalibSDDVsTime.C:159
 PlotCalibSDDVsTime.C:160
 PlotCalibSDDVsTime.C:161
 PlotCalibSDDVsTime.C:162
 PlotCalibSDDVsTime.C:163
 PlotCalibSDDVsTime.C:164
 PlotCalibSDDVsTime.C:165
 PlotCalibSDDVsTime.C:166
 PlotCalibSDDVsTime.C:167
 PlotCalibSDDVsTime.C:168
 PlotCalibSDDVsTime.C:169
 PlotCalibSDDVsTime.C:170
 PlotCalibSDDVsTime.C:171
 PlotCalibSDDVsTime.C:172
 PlotCalibSDDVsTime.C:173
 PlotCalibSDDVsTime.C:174
 PlotCalibSDDVsTime.C:175
 PlotCalibSDDVsTime.C:176
 PlotCalibSDDVsTime.C:177
 PlotCalibSDDVsTime.C:178
 PlotCalibSDDVsTime.C:179
 PlotCalibSDDVsTime.C:180
 PlotCalibSDDVsTime.C:181
 PlotCalibSDDVsTime.C:182
 PlotCalibSDDVsTime.C:183
 PlotCalibSDDVsTime.C:184
 PlotCalibSDDVsTime.C:185
 PlotCalibSDDVsTime.C:186
 PlotCalibSDDVsTime.C:187
 PlotCalibSDDVsTime.C:188
 PlotCalibSDDVsTime.C:189
 PlotCalibSDDVsTime.C:190
 PlotCalibSDDVsTime.C:191
 PlotCalibSDDVsTime.C:192
 PlotCalibSDDVsTime.C:193
 PlotCalibSDDVsTime.C:194
 PlotCalibSDDVsTime.C:195
 PlotCalibSDDVsTime.C:196
 PlotCalibSDDVsTime.C:197
 PlotCalibSDDVsTime.C:198
 PlotCalibSDDVsTime.C:199
 PlotCalibSDDVsTime.C:200
 PlotCalibSDDVsTime.C:201
 PlotCalibSDDVsTime.C:202
 PlotCalibSDDVsTime.C:203
 PlotCalibSDDVsTime.C:204
 PlotCalibSDDVsTime.C:205
 PlotCalibSDDVsTime.C:206
 PlotCalibSDDVsTime.C:207
 PlotCalibSDDVsTime.C:208
 PlotCalibSDDVsTime.C:209
 PlotCalibSDDVsTime.C:210
 PlotCalibSDDVsTime.C:211
 PlotCalibSDDVsTime.C:212
 PlotCalibSDDVsTime.C:213
 PlotCalibSDDVsTime.C:214
 PlotCalibSDDVsTime.C:215
 PlotCalibSDDVsTime.C:216
 PlotCalibSDDVsTime.C:217
 PlotCalibSDDVsTime.C:218
 PlotCalibSDDVsTime.C:219
 PlotCalibSDDVsTime.C:220
 PlotCalibSDDVsTime.C:221
 PlotCalibSDDVsTime.C:222
 PlotCalibSDDVsTime.C:223
 PlotCalibSDDVsTime.C:224
 PlotCalibSDDVsTime.C:225
 PlotCalibSDDVsTime.C:226
 PlotCalibSDDVsTime.C:227
 PlotCalibSDDVsTime.C:228
 PlotCalibSDDVsTime.C:229
 PlotCalibSDDVsTime.C:230
 PlotCalibSDDVsTime.C:231
 PlotCalibSDDVsTime.C:232
 PlotCalibSDDVsTime.C:233