ITS QA macros for pp 2012 runs
authormasera <masera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 18 Jun 2012 08:06:23 +0000 (08:06 +0000)
committermasera <masera@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 18 Jun 2012 08:06:23 +0000 (08:06 +0000)
PWGPP/ITS/AliITSQAchecks_pp.C [new file with mode: 0644]
PWGPP/ITS/AliITSQAtrend_pp.C [new file with mode: 0644]

diff --git a/PWGPP/ITS/AliITSQAchecks_pp.C b/PWGPP/ITS/AliITSQAchecks_pp.C
new file mode 100644 (file)
index 0000000..26bd440
--- /dev/null
@@ -0,0 +1,1280 @@
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <TCanvas.h>
+#include <TGrid.h>
+#include <TFile.h>
+#include <TList.h>
+#include <TGridResult.h>
+#include <TPaveStats.h>
+#include <TGraph.h>
+#include <TMath.h>
+#include <TGraphErrors.h>
+#include <TH1.h>
+#include <TF1.h>
+#include <TH2.h>
+#include <TLegend.h>
+#include <TLegendEntry.h>
+#include <TLatex.h>
+#include <TString.h>
+#include <TStyle.h>
+#include <TSystem.h>
+#include <TROOT.h>
+#endif
+
+void PlotGeneral(TFile* fildat, TCanvas**& clist, Int_t& cnum);
+void PlotITSsa(TFile* fildat, TCanvas**& clist, Int_t& cnum);
+void PlotSDD(TFile* fildat, TCanvas**& clist, Int_t& cnum);
+void GetGainModuleLevelSSD(TFile* fildat, TCanvas**& clist, Int_t& cnum);
+void VertexQAMacro(TFile *fildat, TCanvas **&clist, Int_t &cnum);
+void PlotSPD(TFile* fildat, TFile* filMC, TCanvas**& clist, Int_t& cnum);
+Bool_t PlotITSTPCMatchingEff(TFile *f, TCanvas**& clist,Int_t& cnum);
+void SetDrawAtt(Int_t markerstyle,Int_t markercolor,Int_t markersize,Int_t linecolor,Int_t linewidth,TH1 *h1);
+Double_t LangausFun(Double_t *x, Double_t *par);
+void SaveC(TFile &fout, TCanvas**& clist, Int_t cnum);
+TString GetRunNumber();
+
+//  the run number is available to all the functions. Its value is set by AliITSQAchecks
+  Int_t gRunNumber = 0;
+  Int_t gRunNumberMC = 0;
+  TString pdfFileNames="";
+
+
+//_______________________________________________________________________
+void AliITSQAchecks_pp(TString option="alien",
+                         Int_t nRun=179920,
+                         TString period="LHC12c",
+                         TString qaTrain="",
+                   TString filenamedata="QAresults_barrel.root",
+                      //                      TString filenameMC="../rif/QAresults_barrel.root",
+                      TString filenameMC="alien:///alice/data/2012/LHC12c/000179918/cpass1/QAresults_barrel.root",
+                      //TString filenameMC="/Users/beole/alice/QA/macros/macros_protoni/QAresults.root",
+                   Int_t nRunMC=179918){
+  // THIS MACRO SHOULD BE COMPILED. IT DOES NOT WORK WITH THE INTERPRETER
+  // option:  "local" if filenamedata is the name of a local file
+  //          "grid" if on alien
+  // nRun:    run number
+  // period:  LHC period (e.g. LHC11h)
+  // qaTrain: QA train specifier  
+  //          Empty string if QAresults.root is in the ESDs/pass1_HLT directory 
+  // filenamedata: QAresults.root is by default the file name with the results
+  // filenameMC: file name for MC comparison. If the names begins with alien:
+  //             the file is accessed through alien, otherwise is taken as local
+  // nRunMC:  run number for comparison. If filenamMC begings with "alien:" 
+  //          the run number is taken from the path. Otherwise, in case of a 
+  //          local filenameMC, the run number must be specified here
+  // Select here what you want to display
+  // the complete selection string is
+  // "general ITSSA SPD SDD SSD vertex ITSTPC"
+  // Contact:  Stefania Beole': beole@to.infn.it  
+
+/* $Id$ */
+
+  gRunNumber = nRun;
+  TString aux(filenameMC);
+  if(aux.BeginsWith("alien:")){
+    aux=aux.Remove(0,35);
+    // aux=aux.Remove(9,aux.Length());  //compare to pass2
+        aux=aux.Remove(6,aux.Length());   //compare to pass1  
+    gRunNumberMC = atoi(aux.Data());
+  }
+  else {
+    gRunNumberMC = nRunMC;
+  }
+
+  TString selection("general ITSSA SPD SDD SSD vertex ITSTPC"); 
+  //TString selection("general ITSSA SPD SDD vertex ITSTPC"); 
+  // TString selection("vertex"); 
+  gROOT->SetStyle("Plain");
+  gStyle->SetOptStat(1111);
+  TFile *fildat;
+  TString path;
+  Int_t year=2012;
+  if(period.Contains("LHC11")) year=2011;
+  else if(period.Contains("LHC10")) year=2010;
+
+  if(option.Contains("local")){
+    fildat=new TFile(filenamedata.Data());
+    printf("Opened file %s\n",fildat->GetName());
+  }else{
+    TGrid::Connect("alien:");
+    if(qaTrain.Contains("QA")){
+      path=Form("/alice/data/%d/%s/%09d/ESDs/pass2/%s/",year,period.Data(),nRun,qaTrain.Data());
+    } else {
+      path=Form("/alice/data/%d/%s/%09d/cpass1/",year,period.Data(),nRun);
+    }
+    filenamedata = "alien://"+path+"QAresults_barrel.root";
+    fildat=TFile::Open(filenamedata.Data());
+  }
+  if(option.Contains("local") && filenameMC.Contains("alien"))TGrid::Connect("alien:");
+  TFile* filMC=TFile::Open(filenameMC.Data());
+  TCanvas** clist;
+  Int_t cnum;
+  char rn[10];
+  cout<<gRunNumberMC<<endl;
+  sprintf(rn,"%d",gRunNumber);
+  TString strRN(rn);
+  TString founame="Outfil"+strRN+".root";
+  TFile fout(founame,"recreate");
+  if(selection.Contains("general")){
+    PlotGeneral(fildat,clist,cnum); 
+    printf("GENERAL - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+
+  }
+  if(selection.Contains("ITSSA")){
+    PlotITSsa(fildat,clist,cnum); 
+    printf("ITSSA - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+  }
+  if(selection.Contains("SDD")){
+    PlotSDD(fildat,clist,cnum); 
+    printf("SDD - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+  }
+  if(selection.Contains("SSD")){
+    GetGainModuleLevelSSD(fildat,clist,cnum);
+    printf("SSD - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+  }
+  if(selection.Contains("vertex")){
+    VertexQAMacro(fildat,clist,cnum);
+    printf("VERTEX - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+  }
+  if(selection.Contains("SPD")){
+    PlotSPD(fildat,filMC,clist,cnum);
+    printf("SPD - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+  }
+  if(selection.Contains("ITSTPC")){
+    PlotITSTPCMatchingEff(fildat,clist,cnum);
+    printf("ITSTPC - cnum = %d\n",cnum);
+    SaveC(fout,clist,cnum);
+  }
+
+  fout.Close();
+
+  // merge the pdf files
+  TString command("gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged");
+  command=command+strRN+".pdf "+pdfFileNames;
+  gSystem->Exec(command.Data());
+  printf(" Merging the pdf file:  %s \n",command.Data());
+  
+}
+
+//_______________________________________________________________________
+void PlotGeneral(TFile* fildat, TCanvas**& clist, Int_t& cnum){
+  TDirectoryFile* df=(TDirectoryFile*)fildat->Get("SDD_Performance");
+  if(!df){
+    printf("SDD_Performance MISSING -> Exit\n");
+    return;
+  }
+  TList* l=(TList*)df->Get("coutputRP");
+  if(!df){
+    printf("coutputRP TList MISSING -> Exit\n");
+    return;
+  }
+  cnum=1; // number of canvases 
+  clist= new TCanvas* [1];//array of pointers to TCanvases
+  gROOT->SetStyle("Plain");
+  gStyle->SetOptStat(1111);
+  TH1F* hcllay=(TH1F*)l->FindObject("hCluInLay");
+  TH1F* hev=(TH1F*)l->FindObject("hNEvents");
+  Int_t nTotEvents=hev->GetBinContent(2);
+  Int_t nTrigEvents=hev->GetBinContent(3);
+  Int_t nEvents=nTotEvents;
+  printf("---- Statistics ----\n");
+  printf("Number of Events = %d\n",nTotEvents);
+  if(nTrigEvents>0){ 
+    printf("Number of Triggered Events = %d\n",nTrigEvents);
+    nEvents=nTrigEvents;
+  }else{
+    printf("No request on the trigger done when running the task\n");
+  }
+  if(hcllay){
+    Double_t norm=hcllay->GetBinContent(1);
+    if(norm>0.){
+      hcllay->Scale(1./norm);
+      hcllay->SetTitle("");
+      hcllay->GetXaxis()->SetRange(2,7);
+      hcllay->SetMinimum(0.);
+      hcllay->SetMaximum(1.1);
+      hcllay->SetMarkerStyle(23);
+      TString ctitle=GetRunNumber()+"General checks: PointPerLayer";
+      TCanvas* ceffL=new TCanvas("ceffL",ctitle,1000,800);
+      clist[0]=ceffL;
+      // ceffL->Divide(1,2);
+      // ceffL->cd(1);
+      ceffL->SetGridy();
+      hcllay->Draw(); 
+      TLatex* tg=new TLatex(0.15,0.2,"Fraction of tracks with point in ITS layer");
+      tg->SetTextSize(0.04);
+      tg->SetNDC();
+      tg->SetTextColor(1);
+      tg->Draw();
+      TString testo="Run "+GetRunNumber();
+      TLatex* tg2 = new TLatex(0.15,0.85,testo.Data());
+      tg2->SetTextSize(0.04);
+      tg2->SetNDC();
+      tg2->SetTextColor(2);
+      tg2->Draw();
+      hcllay->GetXaxis()->SetTitle("Layer");
+      hcllay->GetYaxis()->SetTitle("Fraction of tracks with point in layer");
+      ceffL->Update();
+      ceffL->SaveAs("track_points_per_layer.pdf");
+      pdfFileNames+=" track_points_per_layer.pdf";
+    }
+  }
+}
+
+
+//_______________________________________________________________________
+//////////////////////////////////////////////////////////////////////
+/// ITSsa ////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
+ void PlotITSsa(TFile* fildat, TCanvas**& clist, Int_t& cnum){
+    TDirectoryFile* df=(TDirectoryFile*)fildat->Get("TracksITSsa");
+    if(!df) df=(TDirectoryFile*)fildat->Get("ITSsaTracks");
+    if(!df){
+      printf("ITSsa_Performance MISSING -> Exit\n");
+      return;
+    }
+    TList* l=(TList*)df->Get("clistITSsaTracks");
+    if(!df){
+      printf("clistITSsaTracks TList MISSING -> Exit\n");
+      return;
+    }
+    cnum=2; // number of canvases 
+    clist= new TCanvas* [2];//array of pointers to TCanvases
+     gROOT->SetStyle("Plain");
+  gStyle->SetOptStat(1111);
+
+
+  TH1F* hPtTPCITS=(TH1F*)l->FindObject("hPtTPCITS");
+  TH1F* hPtITSsa=(TH1F*)l->FindObject("hPtITSsa");
+  TH1F* hPtITSpureSA=(TH1F*)l->FindObject("hPtITSpureSA");
+
+  TH2F* hEtaPhiTPCITS=(TH2F*)l->FindObject("hEtaPhiTPCITS");
+  TH2F* hEtaPhiITSsa=(TH2F*)l->FindObject("hEtaPhiITSsa");
+  TH2F* hEtaPhiITSpureSA=(TH2F*)l->FindObject("hEtaPhiITSpureSA");
+  TH1F* hChi2TPCITS=(TH1F*)l->FindObject("hChi2TPCITS");
+  TH1F* hChi2ITSsa=(TH1F*)l->FindObject("hChi2ITSsa");
+  TH1F* hChi2ITSpureSA=(TH1F*)l->FindObject("hChi2ITSpureSA");
+
+  TH1F* hRatio=(TH1F*)hPtTPCITS->Clone("hRatio");
+  TH1F* hRatio1=(TH1F*)hPtTPCITS->Clone("hRatio1");
+   hRatio->Add(hPtITSsa);
+  hRatio->Divide(hPtITSpureSA);
+  hRatio->SetStats(0);
+  hRatio1->Divide(hPtITSsa);
+  hRatio1->SetStats(0);
+
+  TString ctitle=GetRunNumber()+"ITS standalone: performance vs Pt";
+  TCanvas* cITSsa1=new TCanvas("cITSsa1",ctitle,1200,1200);
+  clist[0]=cITSsa1;
+  cITSsa1->Divide(1,3);
+  cITSsa1->cd(1);
+  hPtITSpureSA->Draw();
+  hPtITSpureSA->GetXaxis()->SetTitle("Pt (GeV/c)");
+  gPad->Update();
+  TPaveStats *st1=(TPaveStats*)hPtITSpureSA->GetListOfFunctions()->FindObject("stats");
+  st1->SetY1NDC(0.71);
+  st1->SetY2NDC(0.9);
+  hPtTPCITS->SetLineColor(2);
+  hPtTPCITS->GetXaxis()->SetTitle("Pt (GeV/c)");
+  hPtTPCITS->Draw("sames");
+  //hPtTPCITS->Draw();
+  gPad->Update();
+  TPaveStats *st2=(TPaveStats*)hPtTPCITS->GetListOfFunctions()->FindObject("stats");
+  st2->SetY1NDC(0.71);
+  st2->SetY2NDC(0.9);
+  st2->SetTextColor(2);
+
+  hPtITSsa->SetLineColor(4);
+  hPtITSsa->Draw("sames");
+  gPad->Update();
+  TPaveStats *st3=(TPaveStats*)hPtITSsa->GetListOfFunctions()->FindObject("stats");
+  st3->SetY1NDC(0.51);
+  st3->SetY2NDC(0.7);
+  st3->SetTextColor(4);
+  TLegend* leg=new TLegend(0.5,0.5,0.69,0.79);
+  leg->SetFillColor(0);
+  TLegendEntry* ent=leg->AddEntry(hPtTPCITS,"TPC+ITS","L");
+  ent->SetTextColor(hPtTPCITS->GetLineColor());
+  ent=leg->AddEntry(hPtITSsa,"ITSsa","L");
+  ent->SetTextColor(hPtITSsa->GetLineColor());
+   // to be used only with pp data (ITS pure SA)  
+  ent=leg->AddEntry(hPtITSpureSA,"ITS pureSA","L");
+  ent->SetTextColor(hPtITSpureSA->GetLineColor());
+  leg->Draw();
+  cITSsa1->cd(2);
+   gPad->SetGridx();
+   gPad->SetGridy();
+   hRatio1->GetXaxis()->SetTitle("Pt (GeV/c)");
+   hRatio->GetXaxis()->SetTitle("Pt (GeV/c)");
+   hRatio1->GetYaxis()->SetTitle("TPCITS/ITSsa");
+   hRatio->GetYaxis()->SetTitle("(TPCITS+ITSsa)/ITSpureSA");
+   //   hRatio1->DrawCopy();
+   hRatio->DrawCopy();
+   //   TLatex* tratio=new TLatex(0.2,0.75,"TPC+ITS/ITSsa vs Pt");
+   TLatex* tratio=new TLatex(0.2,0.75,"TPCITS+ITSsa/ITSpureSA vs Pt");
+   tratio->SetNDC();
+   tratio->SetTextColor(1);
+  tratio->Draw();
+  cITSsa1->cd(3);
+  hChi2ITSpureSA->Scale(1./hChi2ITSpureSA->GetEntries());
+  hChi2ITSsa->Scale(1./hChi2ITSsa->GetEntries());
+  hChi2TPCITS->Scale(1./hChi2TPCITS->GetEntries());
+  hChi2ITSpureSA->SetLineColor(1);
+  hChi2ITSpureSA->Draw("");
+  hChi2TPCITS->SetLineColor(2);
+  hChi2TPCITS->Draw("sames");
+  TLatex* tchi=new TLatex(0.25,0.85,"chi2 vs Pt");
+  tchi->SetNDC();
+  tchi->SetTextColor(1);
+  tchi->Draw();
+  gPad->Update();
+  TPaveStats *stc2=(TPaveStats*)hChi2TPCITS->GetListOfFunctions()->FindObject("stats");
+  stc2->SetY1NDC(0.71);
+  stc2->SetY2NDC(0.9);
+  stc2->SetTextColor(2);
+  //  c2->Update();
+  hChi2ITSsa->SetLineColor(4);
+  hChi2ITSsa->Draw("sames");
+  gPad->Update();
+  TPaveStats *stc3=(TPaveStats*)hChi2ITSsa->GetListOfFunctions()->FindObject("stats");
+  stc3->SetY1NDC(0.51);
+  stc3->SetY2NDC(0.7);
+  stc3->SetTextColor(4);
+  leg->Draw();
+
+  cITSsa1->Update();
+  cITSsa1->SaveAs("ITSsa1.pdf");
+  pdfFileNames+=" ITSsa1.pdf";
+  gStyle->SetPalette(1);
+  hEtaPhiITSpureSA->SetStats(0);
+  hEtaPhiITSpureSA->SetTitle("ITS pureSA");
+  hEtaPhiITSsa->SetStats(0);
+  hEtaPhiITSsa->SetTitle("ITSsa tracks");
+  hEtaPhiTPCITS->SetStats(0);
+  hEtaPhiTPCITS->SetTitle("TPC+ITS tracks");
+  ctitle=GetRunNumber()+"Eta-phi distribution for ITSsa and TPC+ITS tracks";
+  TCanvas* cITSsa2=new TCanvas("cITSsa2",ctitle,1200,800);
+  clist[1]=cITSsa2;
+  cITSsa2->Divide(3,1); //for ITSpuresa
+  //cITSsa2->Divide(2,1); //for no ITSpureSA
+  cITSsa2->cd(1);
+  //TPad* p1=new TPad("p1","Tracking: tracks distribution in EtaPhi",0,0.5,1.,1.);
+  //p1->Divide(3,1);
+  //p1->cd (1);
+  hEtaPhiITSpureSA->Draw("colz");
+  hEtaPhiITSpureSA->GetXaxis()->SetTitle("Eta");
+  hEtaPhiITSpureSA->GetYaxis()->SetTitle("Phi");
+  cITSsa2->cd(2);
+  //p1->cd(2);
+  hEtaPhiITSsa->Draw("colz");
+  hEtaPhiITSsa->GetXaxis()->SetTitle("Eta");
+  hEtaPhiITSsa->GetYaxis()->SetTitle("Phi");
+   cITSsa2->cd(3);
+   //p1->cd(3);
+  hEtaPhiTPCITS->Draw("colz");
+  hEtaPhiTPCITS->GetXaxis()->SetTitle("Eta");
+  hEtaPhiTPCITS->GetYaxis()->SetTitle("Phi");
+  //c4->cd(4);
+  cITSsa2->SaveAs("ITSsa2.pdf");  
+  pdfFileNames+=" ITSsa2.pdf";
+}
+
+//-----------------------------------------------------
+// ///////////  Plot SDD ////////////
+//_______________________________________________________________________
+void SetDrawAtt(Int_t markerstyle,Int_t markercolor,Int_t markersize,Int_t linecolor,Int_t linewidth,TH1 *h1){ 
+
+
+  h1->SetMarkerStyle(markerstyle);
+  h1->SetMarkerColor(markercolor);
+  h1->SetMarkerSize(markersize);
+  h1->SetLineColor(linecolor);
+  h1->SetLineWidth(linewidth);
+}
+
+//_______________________________________________________________________
+Double_t LangausFun(Double_t *x, Double_t *par) {
+
+  //Fit parameters:
+  //par[0]=Width (scale) parameter of Landau density
+  //par[1]=Most Probable (MP, location) parameter of Landau density
+  //par[2]=Total area (integral -inf to inf, normalization constant)
+  //par[3]=Width (sigma) of convoluted Gaussian function
+  //
+  //In the Landau distribution (represented by the CERNLIB approximation), 
+  //the maximum is located at x=-0.22278298 with the location parameter=0.
+  //This shift is corrected within this function, so that the actual
+  //maximum is identical to the MP parameter.
+
+  // Numeric constants
+  Double_t invsq2pi = 0.3989422804014;   // (2 pi)^(-1/2)
+  Double_t mpshift  = -0.22278298;       // Landau maximum location
+
+  // Control constants
+  Double_t np = 100.0;      // number of convolution steps
+  Double_t sc =   5.0;      // convolution extends to +-sc Gaussian sigmas
+
+  // Variables
+  Double_t xx;
+  Double_t mpc;
+  Double_t fland;
+  Double_t sum = 0.0;
+  Double_t xlow,xupp;
+  Double_t step;
+  Double_t i;
+
+
+  // MP shift correction
+  mpc = par[1] - mpshift * par[0]; 
+
+  // Range of convolution integral
+  xlow = x[0] - sc * par[3];
+  xupp = x[0] + sc * par[3];
+
+  step = (xupp-xlow) / np;
+
+  // Convolution integral of Landau and Gaussian by sum
+  for(i=1.0; i<=np/2; i++) {
+    xx = xlow + (i-.5) * step;
+    fland = TMath::Landau(xx,mpc,par[0]) / par[0];
+    sum += fland * TMath::Gaus(x[0],xx,par[3]);
+
+    xx = xupp - (i-.5) * step;
+    fland = TMath::Landau(xx,mpc,par[0]) / par[0];
+    sum += fland * TMath::Gaus(x[0],xx,par[3]);
+  }
+
+  return (par[2] * step * sum * invsq2pi / par[3]);
+
+}
+//_________________________________________________________________________
+void PlotSDD(TFile* fildat, TCanvas**& clist, Int_t& cnum){
+  TDirectoryFile* df=(TDirectoryFile*)fildat->Get("SDD_Performance");
+    if(!df){
+      printf("SDD_Performance MISSING -> Exit\n");
+      return;
+    }
+    TList* l=(TList*)df->Get("coutputRP");
+    if(!df){
+      printf("coutputRP TList MISSING -> Exit\n");
+      return;
+    }
+    cnum=1; // number of canvases 
+    clist= new TCanvas* [cnum];//array of pointers to TCanvases
+  gROOT->SetStyle("Plain");
+  gStyle->SetOptStat(1111);
+  TH1F* htimT=(TH1F*)l->FindObject("hDrTimTPAll");
+  TH1F* htimTe=(TH1F*)l->FindObject("hDrTimTPExtra");
+  TH1F* htimTne=(TH1F*)l->FindObject("hDrTimTPNoExtra");
+  htimT->Rebin(4);
+  htimTe->Rebin(4);
+  htimTne->Rebin(4);
+  htimT->SetLineWidth(2);
+  htimTe->SetLineWidth(2);
+  htimTne->SetLineWidth(2);  
+  // TH1F* hev=(TH1F*)l->FindObject("hNEvents");
+  // Int_t nTotEvents=hev->GetBinContent(2);
+  // Int_t nTrigEvents=hev->GetBinContent(3);
+  // Int_t nEvents=nTotEvents;
+  // printf("---- Statistics ----\n");
+  // printf("Number of Events = %d\n",nTotEvents);
+  // if(nTrigEvents>0){ 
+  //   printf("Number of Triggered Events = %d\n",nTrigEvents);
+  //   nEvents=nTrigEvents;
+  // }else{
+  //   printf("No request on the trigger done when running the task\n");
+  // }
+  // if(hcllay){
+  //   Double_t norm=hcllay->GetBinContent(1);
+  //   if(norm>0.){
+  //     hcllay->Scale(1./norm);
+  //     hcllay->SetTitle("");
+  //     hcllay->GetXaxis()->SetRange(2,7);
+  //     hcllay->SetMinimum(0.);
+  //     hcllay->SetMaximum(1.1);
+  //     hcllay->SetMarkerStyle(23);
+  //     TCanvas* ceffL=new TCanvas("ceffL","General: PointPerLayer",800,1000);
+  //     clist[0]=ceffL;
+  //     ceffL->Divide(1,2);
+  //     ceffL->cd(1);
+  //     ceffL->SetGridy();
+  //     hcllay->Draw();
+  //     hcllay->GetXaxis()->SetTitle("Layer");
+  //     hcllay->GetYaxis()->SetTitle("Fraction of tracks with point in layer");
+  //     ceffL->Update();
+  //   }
+  // }
+  TH1F* hSigTim[8];
+  TGraphErrors* gmpv=new TGraphErrors(0);
+  TGraphErrors* gsigg=new TGraphErrors(0);
+  TGraphErrors* gsigl=new TGraphErrors(0);
+  gmpv->SetTitle("");
+  gsigg->SetTitle("");
+  gsigl->SetTitle("");
+  Int_t iPoint=0;
+  TF1 *lfun = new TF1("LangausFun",LangausFun,50.,300.,4);
+  for(Int_t it=0; it<8; it++){
+    hSigTim[it]=(TH1F*)l->FindObject(Form("hSigTimeInt%d",it));
+    if(hSigTim[it]->GetEntries()>200){
+      lfun->SetLineWidth(2);
+      lfun->SetParameter(0,5.);
+      lfun->SetParameter(1,80.);
+      lfun->SetParameter(2,hSigTim[it]->GetEntries()/10.);
+      lfun->SetParameter(3,10.);
+      lfun->SetParLimits(3,0.,20);
+
+      //      hSigTim[it]->Fit("LangausFun","QLR");
+      hSigTim[it]->Fit("LangausFun","ON");
+      hSigTim[it]->GetXaxis()->SetTitle(Form("dE/dx, time interval %d",it+1));
+      hSigTim[it]->GetYaxis()->SetTitle("Events");
+      Float_t mpv=lfun->GetParameter(1);
+      Float_t empv=lfun->GetParError(1);
+      Float_t sig=lfun->GetParameter(3);
+      Float_t esig=lfun->GetParError(3);
+      Float_t sigl=lfun->GetParameter(0);
+      Float_t esigl=lfun->GetParError(0);
+      gmpv->SetPoint(iPoint,(Float_t)it,mpv);
+      gmpv->SetPointError(iPoint,0.,empv);
+      gsigg->SetPoint(iPoint,(Float_t)it,sig);
+      gsigg->SetPointError(iPoint,0.,esig);
+      gsigl->SetPoint(iPoint,(Float_t)it,sigl);
+      gsigl->SetPointError(iPoint,0.,esigl);
+      ++iPoint;
+      printf("Bin %d - MPV=%.3f  \t SigmaLandau=%.3f  \t SigmaGaus=%.3f\n",it,mpv,sigl,sig);
+    }
+  }
+  TString ctitle=GetRunNumber()+"SDD: DriftTime - dE/dx";
+  TCanvas* ctim=new TCanvas("ctim",ctitle,800,1000);
+  clist[0]=ctim;
+  ctim->Divide(1,2);
+  ctim->cd(1);
+  // htimT->Draw();
+  // htimTe->SetLineColor(2);
+  // htimTe->Draw("same");
+  htimTne->SetLineColor(4);
+  htimTne->Draw("");
+  htimTne->GetXaxis()->SetTitle("Drift Time (ns)");
+  htimTne->GetYaxis()->SetTitle("TrackPoints");
+  htimTne->GetYaxis()->SetTitleOffset(1.2);
+  // TLatex* ta=new TLatex(0.5,0.85,"All Clusters");
+  // ta->SetNDC();
+  // ta->SetTextColor(1);
+  // ta->Draw();
+  // TLatex* te=new TLatex(0.5,0.8,"Extra Clusters");
+  // te->SetNDC();
+  // te->SetTextColor(2);
+  // te->Draw();
+  //  TLatex* tn=new TLatex(0.3,0.3,"Non-Extra Clusters");
+  TLatex* tn=new TLatex(0.3,0.3,"Clusters on SDD modules");
+  tn->SetNDC();
+  tn->SetTextColor(4);
+  tn->Draw();
+  TLine* tlin3=new TLine(450.,0.,450.,htimTne->GetMaximum());
+    tlin3->SetLineColor(2);
+    tlin3->SetLineWidth(2);
+    tlin3->SetLineStyle(7);
+    tlin3->Draw("same");
+  TLine* tlin4=new TLine(620.,0.,620.,htimTne->GetMaximum());
+    tlin4->SetLineColor(2);
+    tlin4->SetLineWidth(2);
+    tlin4->SetLineStyle(7);
+    tlin4->Draw("same");
+  TLatex* tlimit1=new TLatex(0.2,0.5,"Range for t0");
+  tlimit1->SetNDC();
+  tlimit1->SetTextColor(2);
+  tlimit1->Draw();
+  TLine* tlin5=new TLine(6200.,0.,6200.,htimTne->GetMaximum());
+    tlin5->SetLineColor(2);
+    tlin5->SetLineStyle(7);
+    tlin5->SetLineWidth(2);
+    tlin5->Draw("same");
+  TLine* tlin6=new TLine(5150.,0.,5150.,htimTne->GetMaximum());
+    tlin6->SetLineColor(2);
+    tlin6->SetLineWidth(2);
+    tlin6->SetLineStyle(7);
+    tlin6->Draw("same");
+  TLatex* tlimit2=new TLatex(0.6,0.5,"Range for falling edge");
+  tlimit2->SetNDC();
+  tlimit2->SetTextColor(2);
+  tlimit2->Draw();
+
+  //  ctim->Update();
+  //  TCanvas* cpars=new TCanvas("cpars","Params",800,600);
+  ctim->cd(2);
+  gPad->SetLeftMargin(0.14);
+  gPad->SetFrameLineWidth(2);
+  gPad->SetTickx();
+  gPad->SetTicky();
+  gmpv->SetMarkerStyle(20);
+  gmpv->SetMinimum(75);
+  gmpv->SetMaximum(90);
+  gmpv->GetXaxis()->SetLimits(-0.2,6.8);
+  gmpv->Draw("AP");
+  gmpv->GetXaxis()->SetTitle("Drift Time interval number");
+  gmpv->GetYaxis()->SetTitle("Landau MPV (keV)");
+  gmpv->GetXaxis()->SetTitleSize(0.05);
+  gmpv->GetYaxis()->SetTitleSize(0.05);
+  gmpv->GetYaxis()->SetTitleOffset(1.2);
+  TLatex* tex=new TLatex(0.2,0.75,"dE/dx MPV vs Drift time interval");
+  tex->SetNDC();
+  tex->SetTextColor(1);
+  tex->Draw();
+ //  cpars->Update();
+  ctim->Update();
+  ctim->SaveAs("SDD.pdf");
+  pdfFileNames+=" SDD.pdf";
+} 
+
+//_______________________________________________________________________
+//////////////// SSD ///////////////////////
+//_______________________________________________________________________
+void GetGainModuleLevelSSD(TFile* fildat, TCanvas**& clist, Int_t& cnum)
+{
+  gROOT->SetStyle("Plain");
+  gStyle->SetOptStat(1111);
+  gStyle->SetPalette(1,0);
+  cnum=1;
+  clist=new TCanvas*[1]; 
+
+  TDirectoryFile* df=(TDirectoryFile*)fildat->Get("PWGPPdEdxSSDQA");
+  TList* listin=(TList*)df->Get("SSDdEdxQA");
+  if(!listin) return;
+  TH2F* fHistQ=0x0;
+  fHistQ=(TH2F*)listin ->FindObject("QACharge");
+  fHistQ->SetStats(111);
+  fHistQ->SetTitle("SSD Charge vs module number");
+if(!fHistQ) return;
+  TH2F* fHistCR=(TH2F*)listin ->FindObject("QAChargeRatio");
+  fHistCR->SetStats(0);
+  fHistCR->SetTitle("SSD Charge Ratio vs module number");
+
+  if(!fHistCR) return;
+
+  TH1F* fHistMPVs=new TH1F("SSD HistMPVS","HistMPVs;MPV;N",75,70,95);
+       
+  TH1F* fHistCRmean=new TH1F("SSD HistCRmean","HistCRmean;CRmean;N",200,-1,1);
+       
+  TH1F *fMPVGraph = new TH1F("SSD MPV","MPVgraph;Module number;MPV",1698,-0.5,1697.5);
+  fMPVGraph->SetMarkerColor(kRed);
+  fMPVGraph->SetMarkerSize(0.5);
+  fMPVGraph->SetMarkerStyle(22);
+  fMPVGraph->SetStats(111111);
+  
+  TH1F *fCRmeanGraph = new TH1F("SSD CRmeangraph","CRmeangraph;Module number;MPV",1698,-0.5,1697.5);
+  fCRmeanGraph->SetMarkerColor(kBlue);
+  fCRmeanGraph->SetMarkerSize(0.5);
+  fCRmeanGraph->SetMarkerStyle(23);
+  fCRmeanGraph->SetStats(111111);
+
+  Float_t mpv[1698];
+  Int_t ntofit=200;
+  //  ofstream outfiletxtbad;
+  //outfiletxtbad.open("QALHC11eCPass1_bis/badModules.txt");   
+    for (int i =0;i<1698;i++)
+    {
+      //      cout<<i<<endl;
+      TString tmpQ("Q");
+      tmpQ+=i;
+      TString tmpCR("CR");
+      tmpCR+=i;
+      TH1D* fHist1DCR= fHistCR->ProjectionY(tmpCR,i+1,i+1);
+      Double_t mean=fHist1DCR->GetMean();
+      if(!(TMath::Abs(mean)<1.0)||fHist1DCR->GetEntries()<10)
+         continue;
+      fHistCRmean->Fill(mean);
+      fCRmeanGraph->SetBinContent(i+1,mean);
+      fCRmeanGraph->SetBinError(i+1,fHist1DCR->GetRMS());
+      fCRmeanGraph->GetYaxis()->SetTitle("CR");
+      TH1D* fHist1DQ=fHistQ->ProjectionY(tmpQ,i+1,i+1);
+      //check bad modules
+      if(fHist1DQ->GetEntries()<ntofit)
+       {
+         //outfiletxtbad<<"Low statistic \t module= "<<i<<" netries="<<fHist1DQ->GetEntries()<<endl;
+         continue;
+       }
+      else
+       {
+         tmpQ+="fit";
+         Float_t range=fHist1DQ->GetBinCenter(fHist1DQ->GetMaximumBin());
+         TF1 *f1 = new TF1(tmpQ,LangausFun,range*0.45,range*3.0,4);
+         f1->SetParameters(7.0,range,1.0,5.5);
+         Float_t normalization=fHist1DQ->GetEntries()*fHist1DQ->GetXaxis()->GetBinWidth(2)/f1->Integral(range*0.45,range*3.0);
+         f1->SetParameters(7.0,range,normalization,5.5);
+         //f1->SetParameters(7.0,range,fHist1DQ->GetMaximum(),5.5);
+         f1->SetParNames("sigma Landau","MPV","N","sigma Gaus");
+         f1->SetParLimits(0,2.0,100.0);
+         f1->SetParLimits(3,0.0,100.0);
+         if(fHist1DQ->Fit(tmpQ,"BRQON")==0)
+           {
+             mpv[i]=f1->GetParameter(1);
+             fHistMPVs->Fill(mpv[i]);  
+             fMPVGraph->SetBinContent(i+1,f1->GetParameter(1));
+             fMPVGraph->SetBinError(i+1,f1->GetParError(1));
+             if(mpv[i]<75.0)
+               {
+                 //outfiletxtbad<<"MPV lower than 75 \t module="<<i<<endl;
+               }       
+             if(mpv[i]>100.0)
+               {
+                 // outfiletxtbad<<"MPV higher than 100 \t module="<<i<<endl;            
+               }
+             if(f1->GetParError(1)>1.0)
+               {
+                 //outfiletxtbad<<"MPV high error on MPV  \t module="<<i<<endl;                                
+               }
+           }
+         else
+           {
+             mpv[i]=1;
+             //outfiletxtbad<<"BAD FIT \t module="<<i<<endl;
+             continue;
+           }   
+       }       
+    }  
+  
+    TString ctitle=GetRunNumber()+"SSD Calibration 1";
+  TCanvas *c1SSD = new TCanvas("c1SSD",ctitle,1000,1000);
+  clist[0]=c1SSD;
+  c1SSD->Divide(2,3);
+  c1SSD->cd(1);
+  fHistQ->DrawCopy("colz");
+  c1SSD->cd(2);
+  fHistCR->DrawCopy("colz");
+
+  //  TCanvas *c2SSD = new TCanvas("c2SSD","SSD Calibration 2",1000,1000);
+  //clist[1]=c2SSD;
+  //c2SSD->Divide(2,2);
+  c1SSD->cd(3);
+  // scala plot MPV
+  fMPVGraph->SetMinimum(40);
+  fMPVGraph->DrawCopy();  
+     TLine* tlin0=new TLine(0.,78.,1698.,78.);
+    tlin0->SetLineColor(2);
+    tlin0->SetLineWidth(2);
+    tlin0->Draw("same");
+     TLine* tlin01=new TLine(0.,88.,1698.,88.);
+    tlin01->SetLineColor(2);
+    tlin01->SetLineWidth(2);
+    tlin01->Draw("same");
+  c1SSD->cd(4); 
+  fHistMPVs->DrawCopy();
+  c1SSD->cd(5);
+  fCRmeanGraph->DrawCopy();
+    TLine* tlin1=new TLine(0.,0.2,1698.,0.2);
+    tlin1->SetLineColor(2);
+    tlin1->SetLineWidth(2);
+    tlin1->Draw("same");
+    TLine* tlin2=new TLine(0.,-0.2,1698.,-0.2);
+    tlin2->SetLineColor(2);
+    tlin2->SetLineWidth(2);
+    tlin2->Draw("same");
+  TLatex* ta1=new TLatex(0.2,0.8,"SSD Calibration");
+  ta1->SetNDC();
+  ta1->SetTextSize(0.05);
+  ta1->SetTextColor(2);
+  ta1->Draw("same");
+  c1SSD->cd(6);
+  fHistCRmean->DrawCopy();
+  c1SSD->Update();
+  c1SSD->SaveAs("SSD.pdf");
+  pdfFileNames+=" SSD.pdf";
+}
+
+//_______________________________________________________________________
+void VertexQAMacro(TFile *fildat, TCanvas **&clist, Int_t &cnum){
+
+       TDirectoryFile *dir = (TDirectoryFile*)fildat->Get("Vertex_Performance");
+       if(!dir){
+               Printf("Vertex directory not found... check!");
+       }
+       
+       TList *lt = (TList*)dir->Get("cOutputVtxESD");
+       
+       cnum = 1;
+       clist = new TCanvas*[1];
+
+       
+       TH1F *xVtxSPD = (TH1F*)lt->FindObject("fhSPDVertexX");
+       TH1F *yVtxSPD = (TH1F*)lt->FindObject("fhSPDVertexY");
+       TH1F *zVtxSPD = (TH1F*)lt->FindObject("fhSPDVertexZ");
+       
+       TH1F *zVtxSPD_Zonly = (TH1F*)lt->FindObject("fhSPDVertexZonly");
+       
+       if(!zVtxSPD_Zonly){
+               Printf("using SPD 3D histo, Zonly not available");
+           zVtxSPD_Zonly = (TH1F*)lt->FindObject("fhSPDVertexZ");      
+       }
+       
+       TH1F *xVtxTRK = (TH1F*)lt->FindObject("fhTRKVertexX");
+       TH1F *yVtxTRK = (TH1F*)lt->FindObject("fhTRKVertexY");
+       TH1F *zVtxTRK = (TH1F*)lt->FindObject("fhTRKVertexZ");
+       
+       TH2F *hntrksSPDvsSPDcls = (TH2F*)lt->FindObject("fhntrksSPDvsSPDcls");
+    TH2F *hntrksZvsSPDcls = (TH2F*)lt->FindObject("fhntrksZvsSPDcls");
+       
+       Bool_t histoCorelation = kTRUE;
+       
+       if(!hntrksZvsSPDcls){
+               Printf("skipping the second part, no 2D histos available");
+               histoCorelation=kFALSE; 
+       }
+
+       TString ctitle=GetRunNumber()+"TRKandSPD3DxVtx";
+       TCanvas *TRK_SPD3D_Vtx = new TCanvas("TRKandSPD3DVtx",ctitle,1000,1000);
+       TRK_SPD3D_Vtx->Divide(3,2);
+       clist[0]=TRK_SPD3D_Vtx;
+       gStyle->SetOptFit(111);
+
+       TRK_SPD3D_Vtx->cd(1);
+       xVtxSPD->SetMarkerStyle(20);
+       xVtxSPD->SetLineWidth(3);
+       xVtxSPD->SetMarkerColor(kBlue+2);
+       TF1 *fx = new TF1("gaus", "gaus", -1, 1);
+       xVtxTRK->SetMarkerStyle(20);
+       xVtxTRK->SetLineWidth(4);
+       xVtxTRK->SetLineColor(2);
+       xVtxTRK->Draw("PE");
+       xVtxTRK->Fit("gaus", "M");
+       xVtxSPD->Draw("PE SAME");
+       xVtxTRK->GetXaxis()->SetRangeUser(-0.10, 0.25);
+       xVtxSPD->GetXaxis()->SetRangeUser(-0.10, 0.25);
+       
+       TLatex* tVTX1=new TLatex(0.15,0.85,"VertexSPD");
+    tVTX1->SetNDC();
+    tVTX1->SetTextColor(kBlue+2);
+    tVTX1->Draw();
+       TLatex* tVTX2=new TLatex(0.15,0.8,"VertexTRK");
+    tVTX2->SetNDC();
+    tVTX2->SetTextColor(2);
+    tVTX2->Draw();
+       
+       TRK_SPD3D_Vtx->cd(2);
+       yVtxSPD->SetMarkerStyle(20);
+       yVtxSPD->SetLineWidth(3);
+       yVtxSPD->SetMarkerColor(kBlue+2);
+       TF1 *fy = new TF1("gaus", "gaus", -1, 1);
+       yVtxTRK->SetMarkerStyle(20);
+       yVtxTRK->SetLineWidth(3);
+       yVtxTRK->SetLineColor(2);
+       yVtxTRK->Draw("PE");
+       yVtxTRK->Fit("gaus", "M");
+       yVtxSPD->Draw("PE SAME");
+       yVtxTRK->GetXaxis()->SetRangeUser(0.1, 0.5);
+       yVtxSPD->GetXaxis()->SetRangeUser(0.1, 0.5);
+
+       TLatex* tVTX3=new TLatex(0.15,0.85,"VertexSPD");
+  tVTX3->SetNDC();
+  tVTX3->SetTextColor(kBlue+2);
+  tVTX3->Draw();
+       TLatex* tVTX4=new TLatex(0.15,0.8,"VertexTRK");
+  tVTX4->SetNDC();
+  tVTX4->SetTextColor(2);
+  tVTX4->Draw();
+       
+       
+       
+       TRK_SPD3D_Vtx->cd(3);
+       
+       TF1 *fz = new TF1("gaus", "gaus", -20, 20);
+       zVtxTRK->SetMarkerStyle(20);
+       zVtxTRK->SetLineWidth(3);
+       zVtxTRK->SetMarkerColor(2);
+       zVtxTRK->SetLineColor(2);
+       zVtxTRK->Fit("gaus", "M");
+       zVtxSPD->SetMarkerStyle(20);
+       zVtxSPD->SetLineWidth(1);
+       zVtxSPD->SetLineColor(kBlue+2);
+       zVtxSPD->SetMarkerColor(kBlue+2);
+       zVtxSPD->SetMarkerSize(0.8);
+       zVtxSPD->Draw("PE");
+       zVtxTRK->Draw("PE SAME");
+
+       TLatex* tVTX5=new TLatex(0.15,0.85,"VertexSPD");
+  tVTX5->SetNDC();
+  tVTX5->SetTextColor(kBlue+2);
+  tVTX5->Draw();
+       TLatex* tVTX6=new TLatex(0.15,0.8,"VertexTRK");
+  tVTX6->SetNDC();
+  tVTX6->SetTextColor(2);
+  tVTX6->Draw();
+
+       
+       
+       //      TCanvas *corrContrSPDClusters = new TCanvas("corrContrSPDClusters", "corrContrSPDClusters");
+       // corrContrSPDClusters->Divide(3,1);
+       //clist[1]=corrContrSPDClusters;
+               TRK_SPD3D_Vtx->cd(4);
+               //      corrContrSPDClusters->cd(1);
+       zVtxSPD_Zonly->SetLineWidth(3);
+       zVtxSPD_Zonly->SetLineColor(kBlue+2);
+       zVtxSPD_Zonly->Draw();
+       TLatex* tVTX7=new TLatex(0.15,0.8,"Vertex Z only");
+  tVTX7->SetNDC();
+  tVTX7->SetTextColor(2);
+  tVTX7->Draw();
+       
+       if(histoCorelation){
+                       TRK_SPD3D_Vtx->cd(5);
+                       //corrContrSPDClusters->cd(2);
+               hntrksSPDvsSPDcls->SetMarkerStyle(20);
+               hntrksSPDvsSPDcls->GetXaxis()->SetRangeUser(0.,400);
+               hntrksSPDvsSPDcls->GetYaxis()->SetRangeUser(0.,4500.);
+               hntrksSPDvsSPDcls->Draw();
+       
+               TRK_SPD3D_Vtx->cd(6);
+               //              corrContrSPDClusters->cd(3);
+               hntrksZvsSPDcls->SetMarkerStyle(20);
+               hntrksZvsSPDcls->GetXaxis()->SetRangeUser(0.,150.);
+               hntrksZvsSPDcls->GetYaxis()->SetRangeUser(0.,1000.);
+               hntrksZvsSPDcls->Draw();        
+   }   
+       TRK_SPD3D_Vtx->SaveAs("vertex.pdf");
+       pdfFileNames+=" vertex.pdf";
+       delete fx;
+       delete fy;
+       delete fz;
+}
+
+//_______________________________________________________________________
+void PlotSPD(TFile *fildat, TFile *filMC, TCanvas **&clist, Int_t &cnum){
+
+  gROOT->SetStyle("Plain");
+  gStyle->SetPalette(1);
+  gStyle->SetOptStat(0);
+  gStyle->SetOptFit(111);
+  cnum=2; // number of canvases 
+  clist= new TCanvas* [2];//array of pointers to TCanvases
+
+   TDirectoryFile *spddata = (TDirectoryFile*)fildat->Get("SPD_Performance");
+    spddata->cd();
+   TList *fListData = (TList*)spddata->Get("coutput1");
+    
+   TString fTitleData = "Data";
+   TString fTitleMc = "MC";
+
+
+  Double_t nevtsData = ((TH1I*)(fListData->FindObject("hEventsProcessed")))->GetEntries();
+  printf("   #events in %s : %f \n",fTitleData.Data(),nevtsData);
+
+  TDirectoryFile *spdmc = (TDirectoryFile*)filMC->Get("SPD_Performance");
+  spdmc->cd();
+  TList *fListMc = (TList*)spdmc->Get("coutput1");
+  Double_t nevtsMc = ((TH1I*)(fListMc->FindObject("hEventsProcessed")))->GetEntries();
+  printf("   #events in %s : %f \n",fTitleMc.Data(),nevtsMc);
+
+  TH2F *trackData = (TH2F*)fListData->FindObject("hSPDphivsSPDeta");
+  trackData->SetTitle(Form("%s %s",trackData->GetTitle(),fTitleData.Data()));
+  TH1D *trackDataPhi = trackData->ProjectionY();
+  if(!trackDataPhi) printf("NO 1 \n");
+
+  trackDataPhi->SetTitle("Tracklets vs Phi");
+  TH1D *trackDataEta = trackData->ProjectionX();
+  if(!trackDataEta) printf("NO 2 \n");
+  trackDataEta->SetTitle("Tracklets vs eta");
+
+  TH1F etaData, phiData;
+  trackDataEta->Copy(etaData);
+  trackDataPhi->Copy(phiData);
+
+  TH1F etaFrac, phiFrac, mcEta, mcPhi;
+  trackDataEta->Copy(etaFrac);
+  trackDataPhi->Copy(phiFrac);
+
+  TH2F *trackMc = (TH2F*)fListMc->FindObject("hSPDphivsSPDeta");
+    trackMc->SetTitle(Form("%s %s",trackMc->GetTitle(),fTitleMc.Data()));
+
+  TString ctitle = GetRunNumber()+"tracklets";
+  TCanvas *tracklets = new TCanvas("tracklets",ctitle,1200,600);
+  clist[0]=tracklets;
+  tracklets->Divide(2,1);
+  tracklets->cd(1);
+  tracklets->cd(1)->SetRightMargin(0.15);
+  trackData->SetTitle(Form("Run %d",gRunNumber));
+  trackData->DrawCopy("colz");
+  tracklets->cd(2);
+  tracklets->cd(2)->SetRightMargin(0.15);
+  trackMc->SetTitle(Form("REF Run %d",gRunNumberMC));
+  TH1D *h = (TH1D*)trackMc->DrawCopy("colz");
+  tracklets->SaveAs("SPDtracklets.pdf");
+  pdfFileNames+=" SPDtracklets.pdf";
+
+  TH1D *trackMcPhi = trackMc->ProjectionY();
+  trackMcPhi->SetTitle(Form("%s",h->GetTitle()));
+  TH1D *trackMcEta = trackMc->ProjectionX();
+  trackMcEta->SetTitle(Form("%s",h->GetTitle()));
+
+  TH1F etaMc, phiMc;
+  trackMcEta->Copy(etaMc);
+  trackMcPhi->Copy(phiMc);
+
+  trackMcEta->Copy(mcEta);
+  trackMcPhi->Copy(mcPhi);
+
+  etaFrac.Scale(1./etaFrac.GetEntries());
+  mcEta.Scale(1./mcEta.GetEntries());
+  etaFrac.Add(&mcEta,-1);
+  etaFrac.Divide(&mcEta);
+
+  phiFrac.Scale(1./phiFrac.GetEntries());
+  mcPhi.Scale(1./mcPhi.GetEntries());
+  phiFrac.Add(&mcPhi,-1);
+  phiFrac.Divide(&mcPhi);
+
+  ctitle = GetRunNumber()+"tracklets and ratios vs eta and phi";
+  TCanvas *track = new TCanvas("track",ctitle,1200,1200);
+  clist[1]=track;
+  track->Divide(2,2);
+  track->cd(1);
+  phiData.SetLineColor(kRed);
+  phiData.SetLineWidth(2);
+  phiData.Scale(1./phiData.GetEntries());
+  phiData.DrawCopy();
+  phiMc.Scale(1./phiMc.GetEntries());
+  TLatex* tphi=new TLatex(0.15,0.15,Form("Red = %d; Blue (ref) = %d",gRunNumber,gRunNumberMC));
+  tphi->SetNDC();
+  tphi->SetTextSize(0.04);
+   tphi->SetTextColor(1);
+  tphi->Draw();  
+  phiMc.DrawCopy("same");
+  track->cd(2);
+  etaData.SetLineColor(kRed);
+  etaData.SetLineWidth(2);
+  etaData.Scale(1./etaData.GetEntries());
+  etaData.DrawCopy();
+  etaMc.Scale(1./etaMc.GetEntries());
+  tphi->Draw();  
+  etaMc.DrawCopy("same");
+  track->cd(3);
+  phiFrac.SetLineColor(1);
+  TLatex* tratio=new TLatex(0.2,0.85,Form("Run %d / REF Run %d",gRunNumber,gRunNumberMC));
+  tratio->SetNDC();
+  tratio->SetTextColor(1);
+  phiFrac.DrawCopy();
+  tratio->Draw();  
+  track->cd(4);
+  etaFrac.SetLineColor(1);
+  etaFrac.DrawCopy();  
+  tratio->Draw();  
+  track->SaveAs("SPD_eta_phi.pdf");
+  pdfFileNames+=" SPD_eta_phi.pdf";
+}
+
+//_______________________________________________________________________
+Bool_t PlotITSTPCMatchingEff(TFile *f, TCanvas**& clist,Int_t& cnum) {
+
+  cnum=1;
+  clist = new TCanvas*[1];
+
+  //  clist = new TCanvas* [1];
+  TString ctitle = GetRunNumber()+"ITS-TPC match";
+  TCanvas* cITSTPCmatch = new TCanvas("cITSTPCmatch",ctitle,10,10,800,600);
+  clist[0]=cITSTPCmatch;
+  // cITSTPCmatch->Divide(2,1);
+  // cITSTPCmatch->cd(1);
+  gPad->SetGridy();
+  gPad->SetLogx();
+  // cITSTPCmatch->cd(2);
+  // gPad->SetGridy();
+  // gPad->SetLogx();
+
+  //  clist = cITSTPCmatch;
+
+  if(!f) return kFALSE;
+
+  TList *list=0;
+  TList *listSPD=0;
+  TDirectoryFile *dir=0;
+
+  // count active SPD HSs
+  dir=(TDirectoryFile*)f->GetDirectory("SPD_Performance");
+  if(dir) listSPD = (TList*)dir->Get("coutput1");
+  if(!dir) return kFALSE;
+
+  Float_t spdFrac[2]={0.,0.};
+  TH1F *hnHSsSPD=new TH1F("hnHSsSPD","Active HSs in SPD layers 1 and 2; layer; HSs",2,0.5,2.5);
+  if(listSPD) {
+    //listSPD->Print();
+    TH1F *hFiredChip = (TH1F*)listSPD->FindObject("hFiredChip");
+    Int_t nHSsInner=0,nHSsOuter=0;
+    for(Int_t i=0;i<400;i++) if(hFiredChip->GetBinContent(i)>0) nHSsInner++;
+    for(Int_t i=400;i<1200;i++) if(hFiredChip->GetBinContent(i)>0) nHSsOuter++;
+    nHSsInner = (Int_t)(nHSsInner/10);
+    nHSsOuter = (Int_t)(nHSsOuter/10);
+    hnHSsSPD->SetBinContent(1,nHSsInner);
+    hnHSsSPD->SetBinContent(2,nHSsOuter);
+    spdFrac[0]=(Float_t)nHSsInner/40.;
+    spdFrac[1]=(Float_t)nHSsOuter/80.;
+  }
+  TGraph *spdFrac0=new TGraph(1);
+  spdFrac0->SetPoint(0,0.08,spdFrac[0]);
+  spdFrac0->SetMarkerColor(1); spdFrac0->SetMarkerStyle(20);
+  TGraph *spdFrac1=new TGraph(1);
+  spdFrac1->SetPoint(0,0.08,spdFrac[1]);
+  spdFrac1->SetMarkerColor(1); spdFrac1->SetMarkerStyle(24);
+  TLegend *l2=new TLegend(0.1,0.62,0.5,0.93);
+  l2->SetBorderSize(1);
+  l2->AddEntry(spdFrac0,"Frac. active SPD0","p");
+  l2->AddEntry(spdFrac1,"Frac. active SPD1","p");
+
+  //
+  // Efficiencies for CENTRAL
+  //
+  dir=(TDirectoryFile*)f->GetDirectory("ITS_Performance");
+  if(dir) list = (TList*)dir->Get("cOutputITS");
+  if(!list) return kFALSE;
+
+  TH1F *fHistPtTPCInAcc = (TH1F*)list->FindObject("fHistPtTPCInAcc");
+  TH1F *fHistPtITSMI6InAcc = (TH1F*)list->FindObject("fHistPtITSMI6InAcc");
+  TH1F *fHistPtITSMI5InAcc = (TH1F*)list->FindObject("fHistPtITSMI5InAcc");
+  TH1F *fHistPtITSMI4InAcc = (TH1F*)list->FindObject("fHistPtITSMI4InAcc");
+  TH1F *fHistPtITSMI3InAcc = (TH1F*)list->FindObject("fHistPtITSMI3InAcc");
+  TH1F *fHistPtITSMI2InAcc = (TH1F*)list->FindObject("fHistPtITSMI2InAcc");
+  TH1F *fHistPtITSMISPDInAcc = (TH1F*)list->FindObject("fHistPtITSMISPDInAcc");
+  TH1F *fHistPtITSMIoneSPDInAcc = (TH1F*)list->FindObject("fHistPtITSMIoneSPDInAcc");
+  TH1F *fHistPtITSTPCsel = (TH1F*)list->FindObject("fHistPtITSTPCsel");
+  TH1F *fHistPtITSMIge2InAcc = (TH1F*)fHistPtITSMI6InAcc->Clone("fHistPtITSMIge2InAcc");
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI5InAcc);
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI4InAcc);
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI3InAcc);
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI2InAcc);
+
+
+  TLegend *l3=new TLegend(0.5,0.62,0.95,0.93);
+  l3->SetBorderSize(1);
+  // cITSTPCmatch->cd(1);
+  fHistPtITSMIge2InAcc->SetTitle("Fraction of prolonged tracks with N ITS points");
+  fHistPtITSMIge2InAcc->SetYTitle("ITS+TPC / TPC");
+  fHistPtITSMIge2InAcc->Divide(fHistPtITSMIge2InAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMIge2InAcc->SetMaximum(1.6);
+  fHistPtITSMIge2InAcc->SetMinimum(0);
+  fHistPtITSMIge2InAcc->GetXaxis()->SetRangeUser(0.1,30);
+  fHistPtITSMIge2InAcc->Draw();
+  l3->AddEntry(fHistPtITSMIge2InAcc,">=2 cls","l");
+  fHistPtITSMI6InAcc->Divide(fHistPtITSMI6InAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMI6InAcc->SetLineColor(2);
+  l3->AddEntry(fHistPtITSMI6InAcc,"6 cls","l");
+  fHistPtITSMI6InAcc->Draw("same");
+  fHistPtITSMI5InAcc->Divide(fHistPtITSMI5InAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMI5InAcc->SetLineColor(3);
+  l3->AddEntry(fHistPtITSMI5InAcc,"5 cls","l");
+  fHistPtITSMI5InAcc->Draw("same");
+  fHistPtITSMI4InAcc->Divide(fHistPtITSMI4InAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMI4InAcc->SetLineColor(4);
+  l3->AddEntry(fHistPtITSMI4InAcc,"4 cls","l");
+  fHistPtITSMI4InAcc->Draw("same");
+  fHistPtITSMI3InAcc->Divide(fHistPtITSMI3InAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMI3InAcc->SetLineColor(6);
+  l3->AddEntry(fHistPtITSMI3InAcc,"3 cls","l");
+  fHistPtITSMI3InAcc->Draw("same");
+  fHistPtITSMI2InAcc->Divide(fHistPtITSMI2InAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMI2InAcc->SetLineColor(7);
+  l3->AddEntry(fHistPtITSMI2InAcc,"2 cls","l");
+  fHistPtITSMI2InAcc->Draw("same");
+  fHistPtITSMISPDInAcc->Divide(fHistPtITSMISPDInAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMISPDInAcc->SetLineColor(9);
+  l3->AddEntry(fHistPtITSMISPDInAcc,"2SPD + any","l");
+  fHistPtITSMISPDInAcc->Draw("same");
+  fHistPtITSMIoneSPDInAcc->Divide(fHistPtITSMIoneSPDInAcc,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSMIoneSPDInAcc->SetLineColor(15);
+  l3->AddEntry(fHistPtITSMIoneSPDInAcc,">=1SPD + any","l");
+  fHistPtITSMIoneSPDInAcc->Draw("same");
+  fHistPtITSTPCsel->Divide(fHistPtITSTPCsel,fHistPtTPCInAcc,1,1,"B");
+  fHistPtITSTPCsel->SetLineColor(kAzure+1);
+  l3->AddEntry(fHistPtITSTPCsel,">=1SPD + any + d_{0} cut","l");
+  fHistPtITSTPCsel->Draw("same");
+  fHistPtITSMIge2InAcc->Draw("same");
+  l3->Draw();
+  l2->Draw();
+  spdFrac0->Draw("p");
+  spdFrac1->Draw("p");
+
+  //
+  // Efficiencies for PERIPHERAL
+  //
+  dir=(TDirectoryFile*)f->GetDirectory("ITS_Performance");
+  if(dir) list = (TList*)dir->Get("cOutputITS");
+  if(!list) return kFALSE;
+
+  fHistPtTPCInAcc = (TH1F*)list->FindObject("fHistPtTPCInAcc");
+  fHistPtITSMI6InAcc = (TH1F*)list->FindObject("fHistPtITSMI6InAcc");
+  fHistPtITSMI5InAcc = (TH1F*)list->FindObject("fHistPtITSMI5InAcc");
+  fHistPtITSMI4InAcc = (TH1F*)list->FindObject("fHistPtITSMI4InAcc");
+  fHistPtITSMI3InAcc = (TH1F*)list->FindObject("fHistPtITSMI3InAcc");
+  fHistPtITSMI2InAcc = (TH1F*)list->FindObject("fHistPtITSMI2InAcc");
+  fHistPtITSMISPDInAcc = (TH1F*)list->FindObject("fHistPtITSMISPDInAcc");
+  fHistPtITSMIoneSPDInAcc = (TH1F*)list->FindObject("fHistPtITSMIoneSPDInAcc");
+  fHistPtITSTPCsel = (TH1F*)list->FindObject("fHistPtITSTPCsel");
+  fHistPtITSMIge2InAcc = (TH1F*)fHistPtITSMI6InAcc->Clone("fHistPtITSMIge2InAcc");
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI5InAcc);
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI4InAcc);
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI3InAcc);
+  fHistPtITSMIge2InAcc->Add(fHistPtITSMI2InAcc);
+
+
+  // cITSTPCmatch->cd(2);
+  // fHistPtITSMIge2InAcc->SetTitle("Fraction of prolonged tracks with N ITS points: peripheral");
+  // fHistPtITSMIge2InAcc->SetYTitle("ITS+TPC / TPC");
+  // fHistPtITSMIge2InAcc->Divide(fHistPtITSMIge2InAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMIge2InAcc->SetMaximum(1.6);
+  // fHistPtITSMIge2InAcc->SetMinimum(0);
+  // fHistPtITSMIge2InAcc->GetXaxis()->SetRangeUser(0.1,30);
+  // fHistPtITSMIge2InAcc->Draw();
+  // fHistPtITSMI6InAcc->Divide(fHistPtITSMI6InAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMI6InAcc->SetLineColor(2);
+  // fHistPtITSMI6InAcc->Draw("same");
+  // fHistPtITSMI5InAcc->Divide(fHistPtITSMI5InAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMI5InAcc->SetLineColor(3);
+  // fHistPtITSMI5InAcc->Draw("same");
+  // fHistPtITSMI4InAcc->Divide(fHistPtITSMI4InAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMI4InAcc->SetLineColor(4);
+  // fHistPtITSMI4InAcc->Draw("same");
+  // fHistPtITSMI3InAcc->Divide(fHistPtITSMI3InAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMI3InAcc->SetLineColor(6);
+  // fHistPtITSMI3InAcc->Draw("same");
+  // fHistPtITSMI2InAcc->Divide(fHistPtITSMI2InAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMI2InAcc->SetLineColor(7);
+  // fHistPtITSMI2InAcc->Draw("same");
+  // fHistPtITSMISPDInAcc->Divide(fHistPtITSMISPDInAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMISPDInAcc->SetLineColor(9);
+  // fHistPtITSMISPDInAcc->Draw("same");
+  // fHistPtITSMIoneSPDInAcc->Divide(fHistPtITSMIoneSPDInAcc,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSMIoneSPDInAcc->SetLineColor(15);
+  // fHistPtITSMIoneSPDInAcc->Draw("same");
+  // fHistPtITSTPCsel->Divide(fHistPtITSTPCsel,fHistPtTPCInAcc,1,1,"B");
+  // fHistPtITSTPCsel->SetLineColor(kAzure+1);
+  // fHistPtITSTPCsel->Draw("same");
+  // fHistPtITSMIge2InAcc->Draw("same");
+  // l3->Draw();
+  // l2->Draw();
+  // spdFrac0->Draw("p");
+  // spdFrac1->Draw("p");
+  cITSTPCmatch->SaveAs("TPCITSmatching.pdf");
+  pdfFileNames+=" TPCITSmatching.pdf";
+  return kTRUE;
+}
+
+//_______________________________________________________________________
+void SaveC(TFile &fout, TCanvas**& clist, Int_t cnum){
+  TDirectory *current = gDirectory;
+  fout.cd();
+  for(Int_t i=0;i<cnum;i++)clist[i]->Write();
+  delete[] clist;
+  current->cd();
+}
+
+//_______________________________________________________________________
+TString GetRunNumber(){
+  // returns a string with the run number
+  char rn[10];
+  sprintf(rn,"%d  ",gRunNumber);
+  TString str(rn);
+  return str;
+}
diff --git a/PWGPP/ITS/AliITSQAtrend_pp.C b/PWGPP/ITS/AliITSQAtrend_pp.C
new file mode 100644 (file)
index 0000000..85c7e34
--- /dev/null
@@ -0,0 +1,2593 @@
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <TH1F.h>
+#include <TH2F.h>
+#include <TF1.h>
+#include <TPad.h>
+#include <TGraphErrors.h>
+#include <TROOT.h>
+#include <TFile.h>
+#include <TTree.h>
+#include <TGrid.h>
+#include <TGridResult.h>
+#include <TMath.h>
+#include <TSystem.h>
+#include <TNtuple.h>
+#include <TCanvas.h>
+#include <TStyle.h>
+#include <TLatex.h>
+#include <TLegend.h>
+#include <TLegendEntry.h>
+#include <Riostream.h>
+//#include <AliITSgeomTGeo.h>
+#endif
+
+TString pdfFileNames="";
+void MakePlot(Int_t run1=-1,Int_t run2=999999,TString ntupleFileName="TrendingITS.root");
+void PlotITSSA(TFile *fil,Int_t *myIndex,Int_t kRunsToPlot);
+void FillITSSAntuple(TFile* f,TNtuple* nt, Int_t nrun);
+void AliITSQAtrend(TString runListFile="LHC12a.txt",TString ntupleFileName="TrendingITS.root");
+Double_t LangausFun(Double_t *x, Double_t *par);
+Bool_t WriteInputTextFileFromMonalisaListOfRuns(TString outtxtfilename,Int_t* listofrunsfromMonalisa,Int_t nruns,TString pathbeforRunN="alice/data/2012/LHC12a/",TString pathafterRunN="cpass1/QAresults_barrel.root");
+
+////////////////////////////////////////////////////////////////
+//    THIS VERSION OPTIMIZED FOR PP
+//    TO BE MODIFIED WHEN PASSING FROM cpass1 to pass1  
+//
+//   Please, read this comment before using this macro 
+//
+//   INPUT FILE: a text file (by default LHC12a.txt) which contains
+//   a list of the complete path+file name of the QAresults root files 
+//   (without the alien:// prefix).
+//   One file per line. The order is irrelevant.
+//
+//   USAGE:
+//
+//   Function AliITSQAtrend():  
+//   it looks for a local root file named TrendingITS.root,
+//   where the ntuples used to build the trending plots are
+//   stored. This file is used to generate incrementally the ntuple contents:
+//   when you add a new entry in the LHC12a.txt file (see below) and you have a
+//   local copy of the  TrendingITS.root file, only the additional run will
+//   be processed. The whole list is processed only the first time you use the
+//   macro. Please, bear in mind that this macro is RAM-intensive: all the
+//   ntuples are kept in memory. It is better to add few runs to the list at 
+//   each time, according to the RAM of your computer. 
+//   The function AliITSQAtrend does not produce any plot.
+//
+//   The LHC12a.txt file contains the QA input file name, with its path and
+//   the number of the LHC fill.
+//   Example of LHC12a.txt (input file complete path + FILL number):
+/*
+/alice/data/2012/LHC12a/000176661/cpass1/QAresults_barrel.root  2469
+/alice/data/2012/LHC12a/000176701/cpass1/QAresults_barrel.root  2470
+*/
+//
+//   Function MakePlot(run1,run2):
+//   it produces the plots. For each canvas a PDF file is created.
+//   A PDF file with all the canvases merged is also produced
+//   The first two argument define a range for the runs to be displayed
+//   These two arguments are optional: by default, all the runs
+//   found in the ntuples are displayed
+////////////////////////////////////////////////////////////////
+
+/* $Id$ */
+
+void MakePlot(Int_t run1,Int_t run2,TString ntupleFileName){
+  // Check run range
+  if(run1>=run2){
+    printf("******   ERROR: invalid run range %d - %d\n",run1,run2);
+    return;
+  }
+
+  TFile* fil=new TFile(ntupleFileName.Data(),"read");
+  if(!fil){
+    printf("File with ntuple does not exist\n");
+    return;
+  }
+  TNtuple* ntsdd=(TNtuple*)fil->Get("ntsdd");
+
+  Float_t nrun;
+  Float_t meanTrPts3,errmeanTrPts3,meanTrPts4,errmeanTrPts4;
+  Float_t minDrTime,errminDrTime,meanDrTime,errmeanDrTime;
+  Float_t fracTrackWithClu1,fracTrackWithClu2,errfracTrackWithClu1,errfracTrackWithClu2;
+  Float_t fracTrackWithClu3,fracTrackWithClu4,errfracTrackWithClu3,errfracTrackWithClu4;
+  Float_t fracTrackWithClu5,fracTrackWithClu6,errfracTrackWithClu5,errfracTrackWithClu6;
+  Float_t fracExtra,errfracExtra;
+  Float_t meandEdxLay3,errmeandEdxLay3,meandEdxLay4,errmeandEdxLay4;
+  Float_t meandEdxTB0,errmeandEdxTB0,meandEdxTB5,errmeandEdxTB5;
+  Float_t MPVdEdxLay3,errMPVdEdxLay3,MPVdEdxLay4,errMPVdEdxLay4;
+  Float_t MPVdEdxTB0,errMPVdEdxTB0,MPVdEdxTB5,errMPVdEdxTB5;
+  Float_t nMod95,nMod80,nMod60,nModEmpty;
+  
+  ntsdd->SetBranchAddress("nrun",&nrun);
+  ntsdd->SetBranchAddress("fracTrackWithClu1",&fracTrackWithClu1);
+  ntsdd->SetBranchAddress("errfracTrackWithClu1",&errfracTrackWithClu1);
+  ntsdd->SetBranchAddress("fracTrackWithClu2",&fracTrackWithClu2);
+  ntsdd->SetBranchAddress("errfracTrackWithClu2",&errfracTrackWithClu2);
+  ntsdd->SetBranchAddress("fracTrackWithClu3",&fracTrackWithClu3);
+  ntsdd->SetBranchAddress("errfracTrackWithClu3",&errfracTrackWithClu3);
+  ntsdd->SetBranchAddress("fracTrackWithClu4",&fracTrackWithClu4);
+  ntsdd->SetBranchAddress("errfracTrackWithClu4",&errfracTrackWithClu4);
+  ntsdd->SetBranchAddress("fracTrackWithClu5",&fracTrackWithClu5);
+  ntsdd->SetBranchAddress("errfracTrackWithClu5",&errfracTrackWithClu5);
+  ntsdd->SetBranchAddress("fracTrackWithClu6",&fracTrackWithClu6);
+  ntsdd->SetBranchAddress("errfracTrackWithClu6",&errfracTrackWithClu6);
+  ntsdd->SetBranchAddress("nMod95",&nMod95);
+  ntsdd->SetBranchAddress("nMod80",&nMod80);
+  ntsdd->SetBranchAddress("nMod60",&nMod60);
+  ntsdd->SetBranchAddress("nModEmpty",&nModEmpty);
+
+  ntsdd->SetBranchAddress("meanTrPts3",&meanTrPts3);
+  ntsdd->SetBranchAddress("errmeanTrPts3",&errmeanTrPts3);
+  ntsdd->SetBranchAddress("meanTrPts4",&meanTrPts4);
+  ntsdd->SetBranchAddress("errmeanTrPts4",&errmeanTrPts4);
+  ntsdd->SetBranchAddress("minDrTime",&minDrTime);
+  ntsdd->SetBranchAddress("errminDrTime",&errminDrTime);
+  ntsdd->SetBranchAddress("meanDrTime",&meanDrTime);
+  ntsdd->SetBranchAddress("errmeanDrTime",&errmeanDrTime);
+  ntsdd->SetBranchAddress("fracExtra",&fracExtra);
+  ntsdd->SetBranchAddress("errfracExtra",&errfracExtra);
+  ntsdd->SetBranchAddress("meandEdxTB0",&meandEdxTB0);
+  ntsdd->SetBranchAddress("errmeandEdxTB0",&errmeandEdxTB0);
+  ntsdd->SetBranchAddress("meandEdxTB5",&meandEdxTB5);
+  ntsdd->SetBranchAddress("errmeandEdxTB5",&errmeandEdxTB5);
+  ntsdd->SetBranchAddress("meandEdxLay3",&meandEdxLay3);
+  ntsdd->SetBranchAddress("errmeandEdxLay3",&errmeandEdxLay3);
+  ntsdd->SetBranchAddress("meandEdxLay4",&meandEdxLay4);
+  ntsdd->SetBranchAddress("errmeandEdxLay4",&errmeandEdxLay4);
+  ntsdd->SetBranchAddress("MPVdEdxTB0",&MPVdEdxTB0);
+  ntsdd->SetBranchAddress("errMPVdEdxTB0",&errMPVdEdxTB0);
+  ntsdd->SetBranchAddress("MPVdEdxTB5",&MPVdEdxTB5);
+  ntsdd->SetBranchAddress("errMPVdEdxTB5",&errMPVdEdxTB5);
+  ntsdd->SetBranchAddress("MPVdEdxLay3",&MPVdEdxLay3);
+  ntsdd->SetBranchAddress("errMPVdEdxLay3",&errMPVdEdxLay3);
+  ntsdd->SetBranchAddress("MPVdEdxLay4",&MPVdEdxLay4);
+  ntsdd->SetBranchAddress("errMPVdEdxLay4",&errMPVdEdxLay4);
+
+  // Sort entries according to run number in the chosen range
+  // Same order is assumed for all the subsequent ntuples
+  Int_t nr=ntsdd->GetEntries();
+  Int_t *myIndex = new Int_t [nr];
+  Int_t *noRuns = new Int_t [nr];
+  Int_t kRunsToPlot=0;
+  printf("Processing runs from %d up to %d\n",run1,run2);
+  for(Int_t i=0; i<nr;i++){
+    printf("Run %f\n",nrun);
+    ntsdd->GetEvent(i);
+    Int_t intrun = static_cast<Int_t>(nrun+0.01);
+    if(intrun>=run1 && intrun<=run2){
+      printf("Accepting run number %d in position %d\n",intrun,kRunsToPlot);
+      noRuns[i]=intrun;
+      kRunsToPlot++;
+    }
+    else {
+      noRuns[i]=run2+10;  
+      printf("Rejecting run number %d - out of range\n",intrun);
+    }
+  }
+  TMath::Sort(nr,noRuns,myIndex,kFALSE);
+  printf("Total number of runs accepted fot display %d\n",kRunsToPlot);
+  if(kRunsToPlot==0)return;
+  for(Int_t i=0;i<kRunsToPlot;i++)printf("Position %d ) Run: %d\n",i,noRuns[myIndex[i]]);
+
+  TH1F* histotrp3=new TH1F("histotrp3","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histotrp4=new TH1F("histotrp4","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histominTime=new TH1F("histominTime","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histomeanTime=new TH1F("histomeanTime","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histofracExtra=new TH1F("histofracExtra","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histodEdxTB0=new TH1F("histodEdxTB0","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histodEdxTB5=new TH1F("histodEdxTB5","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histodEdxLay3=new TH1F("histodEdxLay3","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histodEdxLay4=new TH1F("histodEdxLay4","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoTrackClu1=new TH1F("histoTrackClu1","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoTrackClu2=new TH1F("histoTrackClu2","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoTrackClu3=new TH1F("histoTrackClu3","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoTrackClu4=new TH1F("histoTrackClu4","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoTrackClu5=new TH1F("histoTrackClu5","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoTrackClu6=new TH1F("histoTrackClu6","",kRunsToPlot,0.,kRunsToPlot);
+
+  TH1F* histoNmodEffBelow95=new TH1F("histoNmodEffBelow95","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoNmodEffBelow80=new TH1F("histoNmodEffBelow80","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoNmodEffBelow60=new TH1F("histoNmodEffBelow60","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoNmodEmpty=new TH1F("histoNmodEmpty","",kRunsToPlot,0.,kRunsToPlot);
+
+  for(Int_t i=0; i<kRunsToPlot;i++){
+    ntsdd->GetEvent(myIndex[i]);
+    histoTrackClu1->SetBinContent(i+1,fracTrackWithClu1);
+    histoTrackClu1->SetBinError(i+1,errfracTrackWithClu1);
+    histoTrackClu1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoTrackClu2->SetBinContent(i+1,fracTrackWithClu2);
+    histoTrackClu2->SetBinError(i+1,errfracTrackWithClu2);
+    histoTrackClu2->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoTrackClu3->SetBinContent(i+1,fracTrackWithClu3);
+    histoTrackClu3->SetBinError(i+1,errfracTrackWithClu3);
+    histoTrackClu3->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoTrackClu4->SetBinContent(i+1,fracTrackWithClu4);
+    histoTrackClu4->SetBinError(i+1,errfracTrackWithClu4);
+    histoTrackClu4->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoTrackClu5->SetBinContent(i+1,fracTrackWithClu5);
+    histoTrackClu5->SetBinError(i+1,errfracTrackWithClu5);
+    histoTrackClu5->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoTrackClu6->SetBinContent(i+1,fracTrackWithClu6);
+    histoTrackClu6->SetBinError(i+1,errfracTrackWithClu6);
+    histoTrackClu6->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histominTime->SetBinContent(i+1,minDrTime);
+    histominTime->SetBinError(i+1,errminDrTime);
+    histominTime->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histomeanTime->SetBinContent(i+1,meanDrTime);
+    histomeanTime->SetBinError(i+1,errmeanDrTime);
+    histomeanTime->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histotrp3->SetBinContent(i+1,meanTrPts3);
+    histotrp3->SetBinError(i+1,errmeanTrPts3);
+    histotrp3->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histotrp4->SetBinContent(i+1,meanTrPts4);
+    histotrp4->SetBinError(i+1,errmeanTrPts3);
+    histotrp4->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histofracExtra->SetBinContent(i+1,fracExtra);
+    histofracExtra->SetBinError(i+1,errfracExtra);
+    histofracExtra->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histodEdxTB0->SetBinContent(i+1,MPVdEdxTB0);
+    histodEdxTB0->SetBinError(i+1,errMPVdEdxTB0);
+    histodEdxTB0->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histodEdxTB5->SetBinContent(i+1,MPVdEdxTB5);
+    histodEdxTB5->SetBinError(i+1,errMPVdEdxTB5);
+    histodEdxTB5->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histodEdxLay3->SetBinContent(i+1,MPVdEdxLay3);
+    histodEdxLay3->SetBinError(i+1,errMPVdEdxLay3);
+    histodEdxLay3->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histodEdxLay4->SetBinContent(i+1,MPVdEdxLay4);
+    histodEdxLay4->SetBinError(i+1,errMPVdEdxLay4);
+    histodEdxLay4->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+
+    histoNmodEffBelow95->SetBinContent(i+1,nMod95);
+    histoNmodEffBelow95->SetBinError(i+1,0.0000001);
+    histoNmodEffBelow95->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoNmodEffBelow80->SetBinContent(i+1,nMod80);
+    histoNmodEffBelow80->SetBinError(i+1,0.0000001);
+    histoNmodEffBelow80->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoNmodEffBelow60->SetBinContent(i+1,nMod60);
+    histoNmodEffBelow60->SetBinError(i+1,0.0000001);
+    histoNmodEffBelow60->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+    histoNmodEmpty->SetBinContent(i+1,nModEmpty);
+    histoNmodEmpty->SetBinError(i+1,0.000001);
+    histoNmodEmpty->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrun));
+  }
+
+
+  //---SSD
+
+  TNtuple* ntssd=(TNtuple*)fil->Get("ntssd");
+
+  Float_t  nrunSSD, meandEdxLay5,errmeandEdxLay5,meandEdxLay6,errmeandEdxLay6;
+  Float_t  MPVdEdxLay5,errMPVdEdxLay5,MPVdEdxLay6,errMPVdEdxLay6;
+  Float_t ChargeRatioL5,errChargeratioL5,ChargeRatioL6, errChargeratioL6, moduleOff;
+
+  ntssd->SetBranchAddress("nrun",&nrunSSD);
+  ntssd->SetBranchAddress("meandEdxLay5",&meandEdxLay5);
+  ntssd->SetBranchAddress("errmeandEdxLay5",&errmeandEdxLay5);
+  ntssd->SetBranchAddress("meandEdxLay6",&meandEdxLay6);
+  ntssd->SetBranchAddress("errmeandEdxLay6",&errmeandEdxLay6);
+  ntssd->SetBranchAddress("MPVdEdxLay5",&MPVdEdxLay5);
+  ntssd->SetBranchAddress("errMPVdEdxLay5",&errMPVdEdxLay5);
+  ntssd->SetBranchAddress("MPVdEdxLay6",&MPVdEdxLay6);
+  ntssd->SetBranchAddress("errMPVdEdxLay6",&errMPVdEdxLay6);
+  ntssd->SetBranchAddress("ChargeRatioL5",&ChargeRatioL5);
+  ntssd->SetBranchAddress("errChargeratioL5",&errChargeratioL5);
+  ntssd->SetBranchAddress("ChargeRatioL6",&ChargeRatioL6);
+  ntssd->SetBranchAddress("errChargeratioL6",&errChargeratioL6);
+  ntssd->SetBranchAddress("moduleOff",&moduleOff);
+
+  TH1F* histodEdxLay5=new TH1F("histodEdxLay5","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histodEdxLay6=new TH1F("histodEdxLay6","",kRunsToPlot,0.,kRunsToPlot);
+
+  TH1F* histoChargeRatioLay5=new TH1F("histoChargeRatioLay5","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoChargeRatioLay6=new TH1F("histoChargeRatioLay6","",kRunsToPlot,0.,kRunsToPlot);
+  TH1F* histoEmpty=new TH1F("histoEmpty","",kRunsToPlot,0.,kRunsToPlot);
+  
+  for(Int_t i=0; i<kRunsToPlot;i++){
+
+    ntssd->GetEvent(myIndex[i]);
+
+    histodEdxLay5->SetBinContent(i+1,MPVdEdxLay5);
+    histodEdxLay5->SetBinError(i+1,errMPVdEdxLay5);
+    histodEdxLay5->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunSSD));
+
+    histodEdxLay6->SetBinContent(i+1,MPVdEdxLay6);
+    histodEdxLay6->SetBinError(i+1,errMPVdEdxLay6);
+    histodEdxLay6->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunSSD));
+
+    histoChargeRatioLay5->SetBinContent(i+1,ChargeRatioL5);
+    histoChargeRatioLay5->SetBinError(i+1,errChargeratioL5);
+    histoChargeRatioLay5->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunSSD));
+    
+    histoChargeRatioLay6->SetBinContent(i+1,ChargeRatioL6);
+    histoChargeRatioLay6->SetBinError(i+1,errChargeratioL6);
+    histoChargeRatioLay6->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunSSD));
+
+    histoEmpty->SetBinContent(i+1,moduleOff);
+    histoEmpty->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunSSD));
+
+  }
+
+  //Matching
+
+  TNtuple* ntmatching=(TNtuple*)fil->Get("ntmatching");
+
+  Float_t nrunMatch;
+  Float_t FracSPD1;
+  Float_t errFracSPD1;
+  Float_t FracSPD2;
+  Float_t errFracSPD2;
+  Float_t Eff6Pt02;
+  Float_t errEff6Pt02;
+  Float_t Eff6Pt1;
+  Float_t errEff6Pt1;
+  Float_t Eff6Pt10;
+  Float_t errEff6Pt10;
+  Float_t Eff5Pt02;
+  Float_t errEff5Pt02;
+  Float_t Eff5Pt1;
+  Float_t errEff5Pt1;
+  Float_t Eff5Pt10;
+  Float_t errEff5Pt10;
+  Float_t Eff4Pt02;
+  Float_t errEff4Pt02;
+  Float_t Eff4Pt1;
+  Float_t errEff4Pt1;
+  Float_t Eff4Pt10;
+  Float_t errEff4Pt10;
+  Float_t Eff3Pt02;
+  Float_t errEff3Pt02;
+  Float_t Eff3Pt1;
+  Float_t errEff3Pt1;
+  Float_t Eff3Pt10;
+  Float_t errEff3Pt10;
+  Float_t Eff2Pt02;
+  Float_t errEff2Pt02;
+  Float_t Eff2Pt1;
+  Float_t errEff2Pt1;
+  Float_t Eff2Pt10;
+  Float_t errEff2Pt10;
+  Float_t EffSPDPt02;
+  Float_t errEffSPDPt02;
+  Float_t EffSPDPt1;
+  Float_t errEffSPDPt1;
+  Float_t EffSPDPt10;
+  Float_t errEffSPDPt10;
+  Float_t EffoneSPDPt02;
+  Float_t errEffoneSPDPt02;
+  Float_t EffoneSPDPt1;
+  Float_t errEffoneSPDPt1;
+  Float_t EffoneSPDPt10;
+  Float_t errEffoneSPDPt10;
+  Float_t EffTOTPt02;
+  Float_t errEffTOTPt02;
+  Float_t EffTOTPt1;
+  Float_t errEffTOTPt1;
+  Float_t EffTOTPt10;
+  Float_t errEffTOTPt10;
+
+  ntmatching->SetBranchAddress("nrun",&nrunMatch);
+  //  ntmatching->SetBranchAddress("nrunMatch",&nrunMatch);
+  ntmatching->SetBranchAddress("FracSPD1",&FracSPD1);
+  ntmatching->SetBranchAddress("errFracSPD1",&errFracSPD1);
+  ntmatching->SetBranchAddress("FracSPD2",&FracSPD2);
+  ntmatching->SetBranchAddress("errFracSPD2",&errFracSPD2);
+  ntmatching->SetBranchAddress("Eff6Pt02",&Eff6Pt02);
+  ntmatching->SetBranchAddress("errEff6Pt02",&errEff6Pt02);
+  ntmatching->SetBranchAddress("Eff6Pt1",&Eff6Pt1);
+  ntmatching->SetBranchAddress("errEff6Pt1",&errEff6Pt1);
+  ntmatching->SetBranchAddress("Eff6Pt10",&Eff6Pt10);
+  ntmatching->SetBranchAddress("errEff6Pt10",&errEff6Pt10);
+  ntmatching->SetBranchAddress("Eff5Pt02",&Eff5Pt02);
+  ntmatching->SetBranchAddress("errEff5Pt02",&errEff5Pt02);
+  ntmatching->SetBranchAddress("Eff5Pt1",&Eff5Pt1);
+  ntmatching->SetBranchAddress("errEff5Pt1",&errEff5Pt1);
+  ntmatching->SetBranchAddress("Eff5Pt10",&Eff5Pt10);
+  ntmatching->SetBranchAddress("errEff5Pt10",&errEff5Pt10);
+  ntmatching->SetBranchAddress("Eff4Pt02",&Eff4Pt02);
+  ntmatching->SetBranchAddress("errEff4Pt02",&errEff4Pt02);
+  ntmatching->SetBranchAddress("Eff4Pt1",&Eff4Pt1);
+  ntmatching->SetBranchAddress("errEff4Pt1",&errEff4Pt1);
+  ntmatching->SetBranchAddress("Eff4Pt10",&Eff4Pt10);
+  ntmatching->SetBranchAddress("errEff4Pt10",&errEff4Pt10);
+  ntmatching->SetBranchAddress("Eff3Pt02",&Eff3Pt02);
+  ntmatching->SetBranchAddress("errEff3Pt02",&errEff3Pt02);
+  ntmatching->SetBranchAddress("Eff3Pt1",&Eff3Pt1);
+  ntmatching->SetBranchAddress("errEff3Pt1",&errEff3Pt1);
+  ntmatching->SetBranchAddress("Eff3Pt10",&Eff3Pt10);
+  ntmatching->SetBranchAddress("errEff3Pt10",&errEff3Pt10);
+  ntmatching->SetBranchAddress("Eff2Pt02",&Eff2Pt02);
+  ntmatching->SetBranchAddress("errEff2Pt02",&errEff2Pt02);
+  ntmatching->SetBranchAddress("Eff2Pt1",&Eff2Pt1);
+  ntmatching->SetBranchAddress("errEff2Pt1",&errEff2Pt1);
+  ntmatching->SetBranchAddress("Eff2Pt10",&Eff2Pt10);
+  ntmatching->SetBranchAddress("errEff2Pt10",&errEff2Pt10);
+  ntmatching->SetBranchAddress("EffSPDPt02",&EffSPDPt02);
+  ntmatching->SetBranchAddress("errEffSPDPt02",&errEffSPDPt02);  
+  ntmatching->SetBranchAddress("EffSPDPt1",&EffSPDPt1);
+  ntmatching->SetBranchAddress("errEffSPDPt1",&errEffSPDPt1);  
+  ntmatching->SetBranchAddress("EffSPDPt10",&EffSPDPt10);
+  ntmatching->SetBranchAddress("errEffSPDPt10",&errEffSPDPt10);  
+  ntmatching->SetBranchAddress("EffoneSPDPt02",&EffoneSPDPt02);
+  ntmatching->SetBranchAddress("errEffoneSPDPt02",&errEffoneSPDPt02);
+  ntmatching->SetBranchAddress("EffoneSPDPt1",&EffoneSPDPt1);
+  ntmatching->SetBranchAddress("errEffoneSPDPt1",&errEffoneSPDPt1);
+  ntmatching->SetBranchAddress("EffoneSPDPt10",&EffoneSPDPt10);
+  ntmatching->SetBranchAddress("errEffoneSPDPt10",&errEffoneSPDPt10);
+  ntmatching->SetBranchAddress("EffTOTPt02",&EffTOTPt02);
+  ntmatching->SetBranchAddress("errEffTOTPt02",&errEffTOTPt02);
+  ntmatching->SetBranchAddress("EffTOTPt1",&EffTOTPt1);
+  ntmatching->SetBranchAddress("errEffTOTPt1",&errEffTOTPt1);
+  ntmatching->SetBranchAddress("EffTOTPt10",&EffTOTPt10);
+  ntmatching->SetBranchAddress("errEffTOTPt10",&errEffTOTPt10);
+
+
+  TH1F *hFracSPD1 = new TH1F("hFracSPD1","SPD inner; run number; Fraction of HSs",kRunsToPlot,0.,kRunsToPlot);
+  hFracSPD1->SetLineColor(kGreen+2);
+  hFracSPD1->SetMarkerColor(kGreen+2);
+  hFracSPD1->SetMarkerStyle(20);
+
+  TH1F *hFracSPD2 = new TH1F("hFracSPD2","SPD outer; run number; Fraction of HSs",kRunsToPlot,0.,kRunsToPlot);
+  hFracSPD2->SetLineColor(kYellow+2);
+  hFracSPD2->SetMarkerColor(kYellow+2);
+  hFracSPD2->SetMarkerStyle(20);
+
+  TH1F *hEffSPDPt02 = new TH1F("hEffSPDPt02","Efficiency - P_{T} = 0.2; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffSPDPt02->SetLineWidth(2);
+  hEffSPDPt02->SetLineColor(kAzure+1);
+  hEffSPDPt02->SetMarkerColor(kAzure+1);
+  hEffSPDPt02->SetMarkerStyle(20);
+
+  TH1F *hEffSPDPt1 = new TH1F("hEffSPDPt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffSPDPt1->SetLineWidth(2);
+  hEffSPDPt1->SetLineColor(kAzure+1);
+  hEffSPDPt1->SetMarkerColor(kAzure+1);
+  hEffSPDPt1->SetMarkerStyle(20);
+
+  TH1F *hEffSPDPt10 = new TH1F("hEffSPDPt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffSPDPt10->SetLineWidth(2);
+  hEffSPDPt10->SetLineColor(kAzure+1);
+  hEffSPDPt10->SetMarkerColor(kAzure+1);
+  hEffSPDPt10->SetMarkerStyle(20);
+
+  TH1F *hEffoneSPDPt02 = new TH1F("hEffoneSPDPt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffoneSPDPt02->SetLineWidth(2);
+  hEffoneSPDPt02->SetLineColor(kGray);
+  hEffoneSPDPt02->SetMarkerColor(kGray);
+  hEffoneSPDPt02->SetMarkerStyle(20);
+  TH1F *hEffoneSPDPt1 = new TH1F("hEffoneSPDPt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffoneSPDPt1->SetLineWidth(2);
+  hEffoneSPDPt1->SetLineColor(kGray);
+  hEffoneSPDPt1->SetMarkerColor(kGray);
+  hEffoneSPDPt1->SetMarkerStyle(20);
+  TH1F *hEffoneSPDPt10 = new TH1F("hEffoneSPDPt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffoneSPDPt10->SetLineWidth(2);
+  hEffoneSPDPt10->SetLineColor(kGray);
+  hEffoneSPDPt10->SetMarkerColor(kGray);
+  hEffoneSPDPt10->SetMarkerStyle(20);
+
+  TH1F *hEff2Pt02 = new TH1F("hEff2Pt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff2Pt02->SetLineWidth(2);
+  hEff2Pt02->SetLineColor(kViolet);
+  hEff2Pt02->SetMarkerColor(kViolet);
+  hEff2Pt02->SetMarkerStyle(20);
+  TH1F *hEff2Pt1 = new TH1F("hEff2Pt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff2Pt1->SetLineWidth(2);
+  hEff2Pt1->SetLineColor(kViolet);
+  hEff2Pt1->SetMarkerColor(kViolet);
+  hEff2Pt1->SetMarkerStyle(20);
+  TH1F *hEff2Pt10 = new TH1F("hEff2Pt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff2Pt10->SetLineWidth(2);
+  hEff2Pt10->SetLineColor(kViolet);
+  hEff2Pt10->SetMarkerColor(kViolet);
+  hEff2Pt10->SetMarkerStyle(20);
+
+  TH1F *hEff3Pt02 = new TH1F("hEff3Pt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff3Pt02->SetLineWidth(2);
+  hEff3Pt02->SetLineColor(6);
+  hEff3Pt02->SetMarkerColor(6);
+  hEff3Pt02->SetMarkerStyle(20);
+  TH1F *hEff3Pt1 = new TH1F("hEff3Pt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff3Pt1->SetLineWidth(2);
+  hEff3Pt1->SetLineColor(6);
+  hEff3Pt1->SetMarkerColor(6);
+  hEff3Pt1->SetMarkerStyle(20);
+  TH1F *hEff3Pt10 = new TH1F("hEff3Pt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff3Pt10->SetLineWidth(2);
+  hEff3Pt10->SetLineColor(6);
+  hEff3Pt10->SetMarkerColor(6);
+  hEff3Pt10->SetMarkerStyle(20);
+
+  TH1F *hEff4Pt02 = new TH1F("hEff4Pt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff4Pt02->SetLineWidth(2);
+  hEff4Pt02->SetLineColor(4);
+  hEff4Pt02->SetMarkerColor(4);
+  hEff4Pt02->SetMarkerStyle(20);
+  TH1F *hEff4Pt1 = new TH1F("hEff4Pt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff4Pt1->SetLineWidth(2);
+  hEff4Pt1->SetLineColor(4);
+  hEff4Pt1->SetMarkerColor(4);
+  hEff4Pt1->SetMarkerStyle(20);
+  TH1F *hEff4Pt10 = new TH1F("hEff4Pt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff4Pt10->SetLineWidth(2);
+  hEff4Pt10->SetLineColor(4);
+  hEff4Pt10->SetMarkerColor(4);
+  hEff4Pt10->SetMarkerStyle(20);
+
+  TH1F *hEff5Pt02 = new TH1F("hEff5Pt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff5Pt02->SetLineWidth(2);
+  hEff5Pt02->SetLineColor(3);
+  hEff5Pt02->SetMarkerColor(3);
+  hEff5Pt02->SetMarkerStyle(20);
+  TH1F *hEff5Pt1 = new TH1F("hEff5Pt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff5Pt1->SetLineWidth(2);
+  hEff5Pt1->SetLineColor(3);
+  hEff5Pt1->SetMarkerColor(3);
+  hEff5Pt1->SetMarkerStyle(20);
+  TH1F *hEff5Pt10 = new TH1F("hEff5Pt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff5Pt10->SetLineWidth(3);
+  hEff5Pt10->SetLineColor(3);
+  hEff5Pt10->SetMarkerColor(3);
+  hEff5Pt10->SetMarkerStyle(20);
+
+  TH1F *hEff6Pt02 = new TH1F("hEff6Pt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff6Pt02->SetLineWidth(2);
+  hEff6Pt02->SetLineColor(2);
+  hEff6Pt02->SetMarkerColor(2);
+  hEff6Pt02->SetMarkerStyle(20);
+  TH1F *hEff6Pt1 = new TH1F("hEff6Pt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff6Pt1->SetLineWidth(2);
+  hEff6Pt1->SetLineColor(2);
+  hEff6Pt1->SetMarkerColor(2);
+  hEff6Pt1->SetMarkerStyle(20);
+  TH1F *hEff6Pt10 = new TH1F("hEff6Pt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEff6Pt10->SetLineWidth(2);
+  hEff6Pt10->SetLineColor(2);
+  hEff6Pt10->SetMarkerColor(2);
+  hEff6Pt10->SetMarkerStyle(20);
+
+
+  TH1F *hEffTOTPt02 = new TH1F("hEffTOTPt02","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffTOTPt02->SetLineWidth(2);
+  hEffTOTPt02->SetLineColor(kBlue+2);
+  hEffTOTPt02->SetMarkerColor(kBlue+2);
+  hEffTOTPt02->SetMarkerStyle(20);
+  TH1F *hEffTOTPt1 = new TH1F("hEffTOTPt1","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffTOTPt1->SetLineWidth(2);
+  hEffTOTPt1->SetLineColor(kBlue+2);
+  hEffTOTPt1->SetMarkerColor(kBlue+2);
+  hEffTOTPt1->SetMarkerStyle(20);
+  TH1F *hEffTOTPt10 = new TH1F("hEffTOTPt10","Efficiency; run number; TPC+ITS / TPC",kRunsToPlot,0.,kRunsToPlot);
+  hEffTOTPt10->SetLineWidth(2);
+  hEffTOTPt10->SetLineColor(kBlue+2);
+  hEffTOTPt10->SetMarkerColor(kBlue+2);
+  hEffTOTPt10->SetMarkerStyle(20);
+
+  //  Int_t nEntriesMatch=ntmatching->GetEntries();
+  
+  for(Int_t i=0;i<kRunsToPlot;i++){
+   
+    ntmatching->GetEvent(myIndex[i]);
+    //    Int_t bin=nrunMatch;
+
+    // fill histos
+    //    cout<<i<<") "<<"Index= "<<myIndex[i]<<" nrun= "<<nrunMatch<<", FracSPD1= "<<FracSPD1<<", FracSPD2"<<FracSPD2<<endl;        
+    hFracSPD1->SetBinContent(i+1,FracSPD1);
+    hFracSPD1->SetBinError(i+1,.01);
+    hFracSPD1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    //    cout<<FracSPD1<<endl;
+
+    hFracSPD2->SetBinContent(i+1,FracSPD2);
+    hFracSPD2->SetBinError(i+1,.01);
+    hFracSPD2->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+    
+    //    cout<<FracSPD2<<endl;
+
+    //-------------------------
+      
+    hEff6Pt02->SetBinContent(i+1,Eff6Pt02);
+    hEff6Pt02->SetBinError(i+1,errEff6Pt02);
+    hEff6Pt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEff6Pt1->SetBinContent(i+1,Eff6Pt1);
+    hEff6Pt1->SetBinError(i+1,errEff6Pt1);
+    hEff6Pt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEff6Pt10->SetBinContent(i+1,Eff6Pt10);
+    hEff6Pt10->SetBinError(i+1,errEff6Pt10);
+    hEff6Pt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    hEff5Pt02->SetBinContent(i+1,Eff5Pt02);
+    hEff5Pt02->SetBinError(i+1,errEff5Pt02);
+    hEff5Pt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+           
+    hEff5Pt1->SetBinContent(i+1,Eff5Pt1);
+    hEff5Pt1->SetBinError(i+1,errEff5Pt1);
+    hEff5Pt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+           
+    hEff5Pt10->SetBinContent(i+1,Eff5Pt10);
+    hEff5Pt10->SetBinError(i+1,errEff5Pt10);
+    hEff5Pt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEff4Pt02->SetBinContent(i+1,Eff4Pt02);
+    hEff4Pt02->SetBinError(i+1,errEff4Pt1);
+    hEff4Pt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    hEff4Pt1->SetBinContent(i+1,Eff4Pt1);
+    hEff4Pt1->SetBinError(i+1,errEff4Pt1);
+    hEff4Pt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    hEff4Pt10->SetBinContent(i+1,Eff4Pt10);
+    hEff4Pt10->SetBinError(i+1,errEff4Pt10);
+    hEff4Pt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEff3Pt02->SetBinContent(i+1,Eff3Pt02);
+    hEff3Pt02->SetBinError(i+1,errEff3Pt02);
+    hEff3Pt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+           
+    hEff3Pt1->SetBinContent(i+1,Eff3Pt1);
+    hEff3Pt1->SetBinError(i+1,errEff3Pt1);
+    hEff3Pt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    hEff3Pt10->SetBinContent(i+1,Eff3Pt10);
+    hEff3Pt10->SetBinError(i+1,errEff3Pt10);
+    hEff3Pt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));      
+      
+    hEff2Pt02->SetBinContent(i+1,Eff2Pt02);
+    hEff2Pt02->SetBinError(i+1,errEff2Pt02);
+    hEff2Pt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));  
+
+    hEff2Pt1->SetBinContent(i+1,Eff2Pt1);
+    hEff2Pt1->SetBinError(i+1,errEff2Pt1);
+    hEff2Pt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));  
+
+    hEff2Pt10->SetBinContent(i+1,Eff2Pt10);
+    hEff2Pt10->SetBinError(i+1,errEff2Pt10);
+    hEff2Pt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));  
+
+
+    hEffSPDPt02->SetBinContent(i+1,EffSPDPt02);
+    hEffSPDPt02->SetBinError(i+1,errEffSPDPt02);
+    hEffSPDPt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));  
+      
+    hEffSPDPt1->SetBinContent(i+1,EffSPDPt1);
+    hEffSPDPt1->SetBinError(i+1,errEffSPDPt1);
+    hEffSPDPt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch)); 
+      
+    hEffSPDPt10->SetBinContent(i+1,EffSPDPt10);
+    hEffSPDPt10->SetBinError(i+1,errEffSPDPt10);
+    hEffSPDPt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch)); 
+      
+    hEffoneSPDPt02->SetBinContent(i+1,EffoneSPDPt02);
+    hEffoneSPDPt02->SetBinError(i+1,errEffoneSPDPt02);
+    hEffoneSPDPt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    hEffoneSPDPt1->SetBinContent(i+1,EffoneSPDPt1);
+    hEffoneSPDPt1->SetBinError(i+1,errEffoneSPDPt1);
+    hEffoneSPDPt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEffoneSPDPt10->SetBinContent(i+1,EffoneSPDPt10);
+    hEffoneSPDPt10->SetBinError(i+1,errEffoneSPDPt10);
+    hEffoneSPDPt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+
+    hEffTOTPt02->SetBinContent(i+1,EffTOTPt02);
+    hEffTOTPt02->SetBinError(i+1,errEffTOTPt02);
+    hEffTOTPt02->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEffTOTPt1->SetBinContent(i+1,EffTOTPt1);
+    hEffTOTPt1->SetBinError(i+1,errEffTOTPt1);
+    hEffTOTPt1->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));
+      
+    hEffTOTPt10->SetBinContent(i+1,EffTOTPt10);
+    hEffTOTPt10->SetBinError(i+1,errEffTOTPt10);
+    hEffTOTPt10->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunMatch));  
+
+  }
+  
+  //-----------------------------------
+
+  //---vertex
+
+  TNtuple* ntvertex=(TNtuple*)fil->Get("ntvertex");
+
+  Float_t nrunVertex,Vx,errVx,sigmaVx,errsigmaVx,Vy,errVy,sigmaVy,errsigmaVy,Vz,errVz,sigmaVz,errsigmaVz,VxSPD,errVxSPD,sigmaVxSPD,errsigmaVxSPD,VySPD,errVySPD,sigmaVySPD,errsigmaVySPD,VzSPD,errVzSPD,sigmaVzSPD,errsigmaVzSPD;
+
+  ntvertex->SetBranchAddress("nrun",&nrunVertex);
+  ntvertex->SetBranchAddress("VxTRK",&Vx);
+  ntvertex->SetBranchAddress("errVxTRK",&errVx);
+  ntvertex->SetBranchAddress("sigmaVxTRK",&sigmaVx);
+  ntvertex->SetBranchAddress("errsigmaVxTRK",&errsigmaVx);
+  ntvertex->SetBranchAddress("VyTRK",&Vy);
+  ntvertex->SetBranchAddress("errVyTRK",&errVy);
+  ntvertex->SetBranchAddress("sigmaVyTRK",&sigmaVy);
+  ntvertex->SetBranchAddress("errsigmaVyTRK",&errsigmaVy);
+  ntvertex->SetBranchAddress("VzTRK",&Vz);
+  ntvertex->SetBranchAddress("errVzTRK",&errVz);
+  ntvertex->SetBranchAddress("sigmaVzTRK",&sigmaVz);
+  ntvertex->SetBranchAddress("errsigmaVzTRK",&errsigmaVz);
+ ntvertex->SetBranchAddress("VxSPD",&VxSPD);
+  ntvertex->SetBranchAddress("errVxSPD",&errVxSPD);
+  ntvertex->SetBranchAddress("sigmaVxSPD",&sigmaVxSPD);
+  ntvertex->SetBranchAddress("errsigmaVxSPD",&errsigmaVxSPD);
+  ntvertex->SetBranchAddress("VySPD",&VySPD);
+  ntvertex->SetBranchAddress("errVySPD",&errVySPD);
+  ntvertex->SetBranchAddress("sigmaVySPD",&sigmaVySPD);
+  ntvertex->SetBranchAddress("errsigmaVySPD",&errsigmaVySPD);
+  ntvertex->SetBranchAddress("VzSPD",&VzSPD);
+  ntvertex->SetBranchAddress("errVzSPD",&errVzSPD);
+  ntvertex->SetBranchAddress("sigmaVzSPD",&sigmaVzSPD);
+  ntvertex->SetBranchAddress("errsigmaVzSPD",&errsigmaVzSPD);
+
+
+  TH1F *hVx = new TH1F("hVx","Track Vertex Vx Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hVx->SetLineWidth(2);
+  hVx->SetLineColor(kBlue+2);
+  hVx->SetMarkerColor(kBlue+2);
+  hVx->SetMarkerStyle(20);
+
+ TH1F *hVy = new TH1F("hVy","Track Vertex Vy Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hVy->SetLineWidth(2);
+  hVy->SetLineColor(kBlue+2);
+  hVy->SetMarkerColor(kBlue+2);
+  hVy->SetMarkerStyle(20);
+
+ TH1F *hVz = new TH1F("hVz","Track Vertex Vz Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hVz->SetLineWidth(2);
+  hVz->SetLineColor(kBlue+2);
+  hVz->SetMarkerColor(kBlue+2);
+  hVz->SetMarkerStyle(20);
+
+  TH1F *hSigmaVx = new TH1F("hSigmaVx","Track Vertex SigmaVx Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hSigmaVx->SetLineWidth(2);
+  hSigmaVx->SetLineColor(kBlue+2);
+  hSigmaVx->SetMarkerColor(kBlue+2);
+  hSigmaVx->SetMarkerStyle(20);
+
+ TH1F *hSigmaVy = new TH1F("hSigmaVy","Track Vertex SigmaVy Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hSigmaVy->SetLineWidth(2);
+  hSigmaVy->SetLineColor(kBlue+2);
+  hSigmaVy->SetMarkerColor(kBlue+2);
+  hSigmaVy->SetMarkerStyle(20);
+
+ TH1F *hSigmaVz = new TH1F("hSigmaVz","Track Vertex SigmaVz Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hSigmaVz->SetLineWidth(2);
+  hSigmaVz->SetLineColor(kBlue+2);
+  hSigmaVz->SetMarkerColor(kBlue+2);
+  hSigmaVz->SetMarkerStyle(20);
+
+ TH1F *hVxSPD = new TH1F("hVxSPD","Track Vertex Vx Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hVxSPD->SetLineWidth(2);
+  hVxSPD->SetLineColor(2);
+  hVxSPD->SetMarkerColor(2);
+  hVxSPD->SetMarkerStyle(20);
+
+ TH1F *hVySPD = new TH1F("hVySPD","Track Vertex Vy Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hVySPD->SetLineWidth(2);
+  hVySPD->SetLineColor(2);
+  hVySPD->SetMarkerColor(2);
+  hVySPD->SetMarkerStyle(20);
+
+ TH1F *hVzSPD = new TH1F("hVzSPD","Track Vertex Vz Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hVzSPD->SetLineWidth(2);
+  hVzSPD->SetLineColor(2);
+  hVzSPD->SetMarkerColor(2);
+  hVzSPD->SetMarkerStyle(20);
+
+  TH1F *hSigmaVxSPD = new TH1F("hSigmaVxSPD","Track Vertex SigmaVx Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hSigmaVxSPD->SetLineWidth(2);
+  hSigmaVxSPD->SetLineColor(2);
+  hSigmaVxSPD->SetMarkerColor(2);
+  hSigmaVxSPD->SetMarkerStyle(20);
+
+ TH1F *hSigmaVySPD = new TH1F("hSigmaVySPD","Track Vertex SigmaVy Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hSigmaVySPD->SetLineWidth(2);
+  hSigmaVySPD->SetLineColor(2);
+  hSigmaVySPD->SetMarkerColor(2);
+  hSigmaVySPD->SetMarkerStyle(20);
+
+ TH1F *hSigmaVzSPD = new TH1F("hSigmaVzSPD","Track Vertex SigmaVz Distribution",kRunsToPlot,0.,kRunsToPlot);
+  hSigmaVzSPD->SetLineWidth(2);
+  hSigmaVzSPD->SetLineColor(2);
+  hSigmaVzSPD->SetMarkerColor(2);
+  hSigmaVzSPD->SetMarkerStyle(20);
+
+
+  //  Int_t nEntriesVertex=ntvertex->GetEntries();
+  
+  for(Int_t i=0;i<kRunsToPlot;i++){
+
+    ntvertex->GetEvent(myIndex[i]);
+    
+    //    cout<<Vx<<endl;
+
+    hVx->SetBinContent(i+1,Vx);
+    hVx->SetBinError(i+1,errVx);
+    hVx->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+  
+    hVy->SetBinContent(i+1,Vy);
+    hVy->SetBinError(i+1,errVy);
+    hVy->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+    
+    hVz->SetBinContent(i+1,Vz);
+    hVz->SetBinError(i+1,errVz);
+    hVz->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+  
+    
+    hSigmaVx->SetBinContent(i+1,sigmaVx);
+    hSigmaVx->SetBinError(i+1,errsigmaVx);
+    hSigmaVx->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+
+    hSigmaVy->SetBinContent(i+1,sigmaVy);
+    hSigmaVy->SetBinError(i+1,errsigmaVy);
+    hSigmaVy->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+
+    hSigmaVz->SetBinContent(i+1,sigmaVz);
+    hSigmaVz->SetBinError(i+1,errsigmaVz);
+    hSigmaVz->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+
+ hVxSPD->SetBinContent(i+1,VxSPD);
+    hVxSPD->SetBinError(i+1,errVxSPD);
+    hVxSPD->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+  
+    hVySPD->SetBinContent(i+1,VySPD);
+    hVySPD->SetBinError(i+1,errVySPD);
+    hVySPD->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+    
+    hVzSPD->SetBinContent(i+1,VzSPD);
+    hVzSPD->SetBinError(i+1,errVzSPD);
+    hVzSPD->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+  
+    
+    hSigmaVxSPD->SetBinContent(i+1,sigmaVxSPD);
+    hSigmaVxSPD->SetBinError(i+1,errsigmaVxSPD);
+    hSigmaVxSPD->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+
+    hSigmaVySPD->SetBinContent(i+1,sigmaVySPD);
+    hSigmaVySPD->SetBinError(i+1,errsigmaVySPD);
+    hSigmaVySPD->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+
+    hSigmaVzSPD->SetBinContent(i+1,sigmaVzSPD);
+    hSigmaVzSPD->SetBinError(i+1,errsigmaVzSPD);
+    hSigmaVzSPD->GetXaxis()->SetBinLabel(i+1,Form("%d",(Int_t)nrunVertex));
+    
+  }
+ //--------  Draw Vertex histograms ---------
+  TCanvas *cVertexDisto=new TCanvas("cVertexDisto","cVertexDisto",1200,800);
+  cVertexDisto->Divide(3,2);
+  cVertexDisto->cd(1);
+ //  hVx->SetMinimum(0.03);
+//   hVx->SetMaximum(0.08);
+  hVx->GetYaxis()->SetTitle("Vertex X coordinate");
+  hVx->Draw();
+  hVxSPD->Draw("same");
+  cVertexDisto->cd(2);
+//   hVy->SetMinimum(0.25);
+//   hVy->SetMaximum(0.30);
+  hVy->GetYaxis()->SetTitle("Vertex Y coordinate");
+  hVy->Draw();
+  hVySPD->Draw("same");
+  cVertexDisto->cd(3);
+//   hVz->SetMinimum(-1.);
+//   hVz->SetMaximum(1.);
+  hVz->GetYaxis()->SetTitle("Vertex Z coordinate");
+  hVz->Draw();
+  hVzSPD->Draw("same");
+  cVertexDisto->cd(4);
+//   hSigmaVx->SetMinimum(0.);
+//   hSigmaVx->SetMaximum(0.01);
+  hSigmaVx->GetYaxis()->SetTitle("sigma on x coordinate");
+  hSigmaVx->Draw();
+  hSigmaVxSPD->Draw("same");
+  cVertexDisto->cd(5);
+//   hSigmaVy->SetMinimum(0.);
+//   hSigmaVy->SetMaximum(0.01);
+  hSigmaVy->GetYaxis()->SetTitle("sigma on y coordinate");
+  hSigmaVy->Draw();
+  hSigmaVySPD->Draw("same");
+  cVertexDisto->cd(6);
+//   hSigmaVz->SetMinimum(6.);
+//   hSigmaVz->SetMaximum(10.);
+  hSigmaVz->GetYaxis()->SetTitle("sigma on z coordinate");
+  hSigmaVz->Draw();
+  hSigmaVzSPD->Draw("same");
+  cVertexDisto->SaveAs("Vertex_trend.pdf");
+  pdfFileNames+=" Vertex_trend.pdf";
+ //-----------------------------------
+
+  gStyle->SetOptStat(0);
+
+  TCanvas* c5=new TCanvas("c5","Track With points in ITS");
+  histoTrackClu3->Draw();
+  histoTrackClu3->SetLineColor(1);
+  histoTrackClu3->SetMarkerStyle(20);
+  histoTrackClu3->Draw();
+  histoTrackClu3->SetMinimum(0.);
+  histoTrackClu3->SetMaximum(1.05);
+  histoTrackClu4->SetLineColor(2);
+  histoTrackClu4->SetMarkerColor(2);
+  histoTrackClu4->SetMarkerStyle(22);
+  histoTrackClu4->Draw("same");
+  histoTrackClu1->SetLineColor(kGray+1);
+  histoTrackClu1->SetMarkerColor(kGray+1);
+  histoTrackClu1->SetMarkerStyle(24);
+  histoTrackClu1->Draw("same");
+  histoTrackClu2->SetLineColor(kGray+2);
+  histoTrackClu2->SetMarkerColor(kGray+2);
+  histoTrackClu2->SetMarkerStyle(26);
+  histoTrackClu2->Draw("same");
+  histoTrackClu5->SetLineColor(4);
+  histoTrackClu5->SetMarkerColor(4);
+  histoTrackClu5->SetMarkerStyle(29);
+  histoTrackClu5->Draw("same");
+  histoTrackClu6->SetLineColor(kBlue+1);
+  histoTrackClu6->SetMarkerColor(kBlue+1);
+  histoTrackClu6->SetMarkerStyle(30);
+  histoTrackClu6->SetTitle("Fraction of tracks with points in ITS");
+  histoTrackClu6->Draw("same");
+  histoTrackClu3->GetYaxis()->SetTitle("Fraction of Tracks with Points in ITS Layers");
+  TLegend* leg3=new TLegend(0.7,0.15,0.88,0.35);
+  TLegendEntry* ent;
+  ent=leg3->AddEntry(histoTrackClu1,"Layer1","PL");
+  ent->SetTextColor(histoTrackClu1->GetMarkerColor());
+  ent=leg3->AddEntry(histoTrackClu2,"Layer2","PL");
+  ent->SetTextColor(histoTrackClu2->GetMarkerColor());
+  ent=leg3->AddEntry(histoTrackClu3,"Layer3","PL");
+  ent->SetTextColor(histoTrackClu3->GetMarkerColor());
+  ent=leg3->AddEntry(histoTrackClu4,"Layer4","PL");
+  ent->SetTextColor(histoTrackClu4->GetMarkerColor());
+  ent=leg3->AddEntry(histoTrackClu5,"Layer5","PL");
+  ent->SetTextColor(histoTrackClu5->GetMarkerColor());
+  ent=leg3->AddEntry(histoTrackClu6,"Layer6","PL");
+  ent->SetTextColor(histoTrackClu6->GetMarkerColor());
+
+  leg3->SetFillStyle(0);
+  leg3->Draw();
+  c5->SaveAs("TrackPoints_trend.pdf");
+    pdfFileNames+=" TrackPoints_trend.pdf";
+  c5->Update();
+
+
+
+  TCanvas* c2=new TCanvas("c2","SDD DriftTime & Charge",1200,800);
+  c2->Divide(2,2);
+  c2->cd(1);
+  histominTime->Draw();
+  histominTime->SetMinimum(450);
+  histominTime->SetMaximum(550);
+  histominTime->GetYaxis()->SetTitle("Minimum Drift Time (ns)");
+  TLatex* td1=new TLatex(0.2,0.85,"SDD minimum drift time (ref=505ns)");
+  td1->SetNDC();
+  td1->SetTextColor(1);
+  td1->Draw();
+  c2->cd(2);
+  histomeanTime->Draw();
+  histomeanTime->SetMinimum(3200);
+  histomeanTime->SetMaximum(3300);
+  histomeanTime->GetYaxis()->SetTitle("Average Drift Time (ns)");
+  TLatex* td2=new TLatex(0.2,0.85,"SDD average drift time");
+  td2->SetNDC();
+  // td2>SetTextColor(1);
+  td2->Draw();
+
+  // TCanvas* c4=new TCanvas("c4","Charge");
+  c2->cd(3);
+  gPad->SetGridy();
+  histodEdxTB0->SetLineColor(1);
+  histodEdxTB0->SetMarkerStyle(20);
+  histodEdxTB0->Draw();
+  histodEdxTB0->SetMinimum(70.);
+  histodEdxTB0->SetMaximum(100.);
+  histodEdxTB5->SetLineColor(4);
+  histodEdxTB5->SetMarkerColor(4);
+  histodEdxTB5->SetMarkerStyle(23);
+  // histodEdxTB5->SetMinimum(90);
+  // histodEdxTB5->SetMaximum(120);
+  histodEdxTB5->Draw("same");
+  histodEdxTB0->GetYaxis()->SetTitle("MPV of dE/dx (keV/300 #mum)");
+  TLegend* leg2=new TLegend(0.6,0.15,0.88,0.35);
+  ent=leg2->AddEntry(histodEdxTB0,"Small drift time","PL");
+  ent=leg2->AddEntry(histodEdxTB5,"Large drift time","PL");
+  ent->SetTextColor(histodEdxTB5->GetMarkerColor());
+  leg2->SetFillStyle(0);
+  leg2->Draw();
+  TLatex* tc1=new TLatex(0.2,0.85,"SDD charge in different drift regions");
+  tc1->SetNDC();
+  tc1->SetTextColor(1);
+  tc1->Draw();
+  // TCanvas* c4b=new TCanvas("c4b","Charge per Layer");
+  c2->cd(4);
+  gPad->SetGridy();
+  histodEdxLay3->SetLineColor(1);
+  histodEdxLay3->SetMarkerStyle(20);
+  histodEdxLay3->Draw();
+  histodEdxLay3->SetMinimum(70.);
+  histodEdxLay3->SetMaximum(100.);
+  histodEdxLay4->SetLineColor(4);
+  histodEdxLay4->SetMarkerColor(4);
+  histodEdxLay4->SetMarkerStyle(23);
+  histodEdxLay4->Draw("same");
+  
+  histodEdxLay5->SetLineColor(6);
+  histodEdxLay5->SetMarkerColor(6);
+  histodEdxLay5->SetMarkerStyle(22);
+  histodEdxLay5->Draw("same");
+  histodEdxLay5->SetMinimum(0.);
+  histodEdxLay6->SetLineColor(7);
+  histodEdxLay6->SetMarkerColor(7);
+  histodEdxLay6->SetMarkerStyle(24);
+  histodEdxLay6->Draw("same");
+    
+  histodEdxLay3->GetYaxis()->SetTitle("MPV of dE/dx (keV/300 #mum)");
+  
+  TLegend* leg2b=new TLegend(0.6,0.15,0.88,0.35);
+  ent=leg2b->AddEntry(histodEdxLay3,"Layer 3","PL");
+  ent=leg2b->AddEntry(histodEdxLay4,"Layer 4","PL");
+  ent=leg2b->AddEntry(histodEdxLay5,"Layer 5","PL");
+  ent=leg2b->AddEntry(histodEdxLay6,"Layer 6","PL");
+  ent->SetTextColor(histodEdxLay4->GetMarkerColor());
+  leg2b->SetFillStyle(0);
+  leg2b->Draw();
+  // c4b->Update();
+  TLatex* tc2=new TLatex(0.2,0.85,"SDD and SSD charge in different layers");
+  tc2->SetNDC();
+  tc2->SetTextColor(1);
+  tc2->Draw();
+  c2->SaveAs("SDD_SSD_drift_charge_trend.pdf");  
+  pdfFileNames+=" SDD_SSD_drift_charge_trend.pdf";
+  c2->Update();
+
+  TCanvas *c7=new TCanvas("c7","Charge ratio");
+  c7->cd();
+  histoChargeRatioLay5->SetLineColor(6);
+  histoChargeRatioLay5->SetMarkerColor(6);
+  histoChargeRatioLay5->SetMarkerStyle(20);
+  histoChargeRatioLay5->SetMinimum(-0.01);
+  histoChargeRatioLay5->SetMaximum(+0.01);
+  histoChargeRatioLay5->Draw();
+  histoChargeRatioLay6->SetLineColor(7);
+  histoChargeRatioLay6->SetMarkerColor(7);
+  histoChargeRatioLay6->SetMarkerStyle(22);
+  histoChargeRatioLay6->GetYaxis()->SetTitle("SSD charge ratio");
+  histoChargeRatioLay6->Draw("same");
+  TLegend* legCR=new TLegend(0.7,0.65,0.88,0.75);
+  ent=legCR->AddEntry(histoChargeRatioLay5,"Layer5","PL");
+  ent->SetTextColor(histoChargeRatioLay5->GetMarkerColor());
+  ent=legCR->AddEntry(histoChargeRatioLay6,"Layer6","PL");
+  ent->SetTextColor(histoChargeRatioLay6->GetMarkerColor());
+  legCR->SetFillStyle(0);
+  legCR->Draw();
+  TLatex* tc3=new TLatex(0.2,0.85,"SSD charge ratio in different layers");
+  tc3->SetNDC();
+  tc3->SetTextColor(1);
+  tc3->Draw();
+  c7->SaveAs("SSD_chargeratio_trend.pdf");
+      pdfFileNames+=" SSD_chargeratio_trend.pdf";
+  // TCanvas *c8=new TCanvas("c8","Masked modules");
+  // c8->cd();
+  // histoEmpty->Draw();
+
+  TCanvas *cpt02=new TCanvas("cpt02","TPC-ITS matching efficiency",1200,1000);
+  cpt02->Divide(2,2);
+  cpt02->cd(1);
+  hEff6Pt02->SetMinimum(0);
+  hEff6Pt02->Draw();
+  hEff5Pt02->Draw("same");
+  hEff4Pt02->Draw("same");
+  hEff3Pt02->Draw("same");
+  hEff2Pt02->Draw("same");
+  hEffSPDPt02->Draw("same");
+  hEffoneSPDPt02->Draw("same");
+  hEffTOTPt02->Draw("same");
+  hEff6Pt02->GetYaxis()->SetRangeUser(0,1);
+  TLegend* lpt02=new TLegend(0.9,0.8,1,1);
+  lpt02->AddEntry(hEff6Pt02,"6 cls","l");
+  lpt02->AddEntry(hEff5Pt02,"5 cls","l");
+  lpt02->AddEntry(hEff4Pt02,"4 cls","l");
+  lpt02->AddEntry(hEff3Pt02,"3 cls","l");
+  lpt02->AddEntry(hEff2Pt02,"2 cls","l");
+  lpt02->AddEntry(hEffSPDPt02,"2SPD + any","l");
+  lpt02->AddEntry(hEffoneSPDPt02,">=1SPD + any","l");
+  lpt02->AddEntry(hEffTOTPt02,">=2","l");
+  lpt02->Draw("same");
+  TLatex* tpc1=new TLatex(0.2,0.85,"TPCITS match eff Pt=0.2");
+  tpc1->SetNDC();
+  tpc1->SetTextColor(1);
+  tpc1->Draw();
+
+  // TCanvas *cpt1=new TCanvas("cpt1","cpt1");
+  // cpt1->cd(1);
+  cpt02->cd(2);
+
+  hEff6Pt1->Draw();
+  hEff5Pt1->Draw("same");
+  hEff4Pt1->Draw("same");
+  hEff3Pt1->Draw("same");
+  hEff2Pt1->Draw("same");
+  hEffSPDPt1->Draw("same");
+  hEffoneSPDPt1->Draw("same");
+  hEffTOTPt1->Draw("same");
+  hEff6Pt1->GetYaxis()->SetRangeUser(0,1);
+
+  TLegend* lpt1=new TLegend(0.9,0.8,1,1);
+  lpt1->AddEntry(hEff6Pt1,"6 cls","l");
+  lpt1->AddEntry(hEff5Pt1,"5 cls","l");
+  lpt1->AddEntry(hEff4Pt1,"4 cls","l");
+  lpt1->AddEntry(hEff3Pt1,"3 cls","l");
+  lpt1->AddEntry(hEff2Pt1,"2 cls","l");
+  lpt1->AddEntry(hEffSPDPt1,"2SPD + any","l");
+  lpt1->AddEntry(hEffoneSPDPt1,">=1SPD + any","l");
+  lpt1->AddEntry(hEffTOTPt02,">=2","l");
+  lpt1->Draw("same");
+  TLatex* tpc2=new TLatex(0.2,0.75,"TPCITS match eff Pt=1");
+  tpc2->SetNDC();
+  tpc2->SetTextColor(1);
+  tpc2->Draw();
+
+
+  // TCanvas *cpt10=new TCanvas("cpt10","cpt10");
+  cpt02->cd(3);
+
+  hEff6Pt10->Draw();
+  hEff5Pt10->Draw("same");
+  hEff4Pt10->Draw("same");
+  hEff3Pt10->Draw("same");
+  hEff2Pt10->Draw("same");
+  hEffSPDPt10->Draw("same");
+  hEffoneSPDPt10->Draw("same");
+  hEffTOTPt10->Draw("same");
+  hEff6Pt10->GetYaxis()->SetRangeUser(0,1);
+
+  TLegend* lpt10=new TLegend(0.9,0.8,1,1);
+  lpt10->AddEntry(hEff6Pt10,"6 cls","l");
+  lpt10->AddEntry(hEff5Pt10,"5 cls","l");
+  lpt10->AddEntry(hEff4Pt10,"4 cls","l");
+  lpt10->AddEntry(hEff3Pt10,"3 cls","l");
+  lpt10->AddEntry(hEff2Pt10,"2 cls","l");
+  lpt10->AddEntry(hEffSPDPt10,"2SPD + any","l");
+  lpt10->AddEntry(hEffoneSPDPt10,">=1SPD + any","l");
+  lpt10->AddEntry(hEffTOTPt02,">=2","l");
+  lpt10->Draw("same");
+
+  TLatex* tpc3=new TLatex(0.2,0.75,"TPCITS match eff Pt=10");
+  tpc3->SetNDC();
+  tpc3->SetTextColor(1);
+  tpc3->Draw();
+  cpt02->cd(4);
+
+
+  //  TCanvas *cSPD = new TCanvas("cSPD","cSPD",0,0,1000,300);
+  // cSPD->SetGridy();
+  hFracSPD1->SetMaximum(1.2);
+  hFracSPD1->SetMinimum(0);
+  hFracSPD1->Draw("p");
+  hFracSPD2->Draw("same,p");
+
+  TLegend* lSPD=new TLegend(0.9,0.8,1,1);
+  lSPD->AddEntry(hFracSPD1,"Frac. SPD1 ON","l");
+  lSPD->AddEntry(hFracSPD2,"Frac. SPD2 ON","l");
+  lSPD->Draw();
+  TLatex* tSPD=new TLatex(0.2,0.85,"Fraction of SPD half staves ON");
+  tSPD->SetNDC();
+  tSPD->SetTextColor(1);
+  tSPD->Draw();
+  cpt02->SaveAs("TPCITS_trend.pdf");
+      pdfFileNames+=" TPCITS_trend.pdf";
+  cpt02->Update();
+
+  //-----------  ITS SA -----------
+  PlotITSSA(fil,myIndex,kRunsToPlot);
+ // merge the pdf files
+  TString command("gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged");
+  command=command+"ITS_trend.pdf "+pdfFileNames;
+  gSystem->Exec(command.Data());
+  printf(" Merging the pdf file:  %s \n",command.Data());
+  delete [] myIndex;
+  delete [] noRuns;
+}
+
+//____________________________________________________________________________
+void PlotITSSA(TFile *fil,Int_t *myIndex,Int_t kRunsToPlot){
+  Double_t Lowbin[3]={0.1,0.5,0.9};
+  Double_t Upbin[3]={0.2,0.6,1};
+  gROOT->SetStyle("Plain");
+  gStyle->SetOptTitle(0);
+  gStyle->SetOptStat(0);
+  gStyle->SetFillColor(0);
+  gStyle->SetTextFont(32);
+  
+  TNtuple* nt = (TNtuple*)fil->Get("ntITSsa");
+  Int_t nruns=nt->GetEntries();
+  printf("Events = %d - Runs to be processed %d\n",nruns,kRunsToPlot);
+  Float_t ITSA[3];
+  Float_t TPIT[3];
+  Float_t RAT[3];
+  Float_t run;
+  nt->SetBranchAddress("run",&run);
+  //  nt->SetBranchAddress("NITSsaPtBin0",&ITSA[0]); //Pb-Pb
+  // nt->SetBranchAddress("NITSsaPtBin1",&ITSA[1]); //Pb-Pb
+  // nt->SetBranchAddress("NITSsaPtBin2",&ITSA[2]); //Pb-Pb
+  nt->SetBranchAddress("NITSpureSAPtBin0",&ITSA[0]);
+  nt->SetBranchAddress("NITSpureSAPtBin1",&ITSA[1]);
+  nt->SetBranchAddress("NITSpureSAPtBin2",&ITSA[2]);
+  nt->SetBranchAddress("NITSTPCPtBin0",&TPIT[0]);
+  nt->SetBranchAddress("NITSTPCPtBin1",&TPIT[1]);
+  nt->SetBranchAddress("NITSTPCPtBin2",&TPIT[2]);
+  nt->SetBranchAddress("ratioPtBin0",&RAT[0]);
+  nt->SetBranchAddress("ratioPtBin1",&RAT[1]);
+  nt->SetBranchAddress("ratioPtBin2",&RAT[2]);
+  TH1F *h0=new TH1F("h0","h0",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h1=new TH1F("h1","h1",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h2=new TH1F("h2","h2",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h3=new TH1F("h3","h4",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h4=new TH1F("h4","h5",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h5=new TH1F("h5","h5",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h6=new TH1F("h6","h6",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h7=new TH1F("h7","h7",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  TH1F *h8=new TH1F("h8","h8",kRunsToPlot,-0.5,kRunsToPlot-0.5);
+  for(Int_t iev=0;iev<kRunsToPlot;iev++){
+    nt->GetEvent(myIndex[iev]);
+    //cout<<"Numeri TPCITS "<<TPIT[0]<<" "<<TPIT[1]<<" "<<TPIT[2]<<endl;
+    h0->Fill(iev,ITSA[0]);
+    h1->Fill(iev,ITSA[1]);
+    h2->Fill(iev,ITSA[2]);
+    h3->Fill(iev,TPIT[0]);
+    h4->Fill(iev,TPIT[1]);
+    h5->Fill(iev,TPIT[2]);
+    h6->Fill(iev,RAT[0]);
+    h7->Fill(iev,RAT[1]);
+    h8->Fill(iev,RAT[2]);
+    h0->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h1->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h2->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h3->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h4->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h5->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h6->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h7->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    h8->GetXaxis()->SetBinLabel(iev+1,Form("%.0f",run));
+    //    Printf("%f   %f   %f",ITSA[0],ITSA[1],ITSA[2]);
+  }
+  h0->Print("all");
+  // h0->GetYaxis()->SetTitle("ITSsa tracks");
+  // h0->GetXaxis()->SetTitle("run");
+  // h1->GetYaxis()->SetTitle("ITSsa tracks");
+  // h1->GetXaxis()->SetTitle("run");
+  // h2->GetYaxis()->SetTitle("ITSsa tracks");
+  // h2->GetXaxis()->SetTitle("run");
+  h0->GetYaxis()->SetTitle("ITSpureSA tracks");
+  h0->GetXaxis()->SetTitle("run");
+  h1->GetYaxis()->SetTitle("ITSpureSA tracks");
+  h1->GetXaxis()->SetTitle("run");
+  h2->GetYaxis()->SetTitle("ITSpureSA tracks");
+  h2->GetXaxis()->SetTitle("run");
+  h3->GetYaxis()->SetTitle("ITS+TPC tracks");
+  h3->GetXaxis()->SetTitle("run");
+  h4->GetYaxis()->SetTitle("ITS+TPC tracks");
+  h4->GetXaxis()->SetTitle("run");
+  h5->GetYaxis()->SetTitle("ITS+TPC tracks");
+  h5->GetXaxis()->SetTitle("run");
+  // h6->GetYaxis()->SetTitle("(TPC+ITS)/ITS");
+  // h6->GetXaxis()->SetTitle("run");
+  // h7->GetYaxis()->SetTitle("(TPC+ITS)/ITS");
+  // h7->GetXaxis()->SetTitle("run");
+  // h8->GetYaxis()->SetTitle("(TPC+ITS)/ITS");
+  // h8->GetXaxis()->SetTitle("run");
+  h6->GetYaxis()->SetTitle("(TPC+ITS)+ITSsa/ITSpureSA");
+  h6->GetXaxis()->SetTitle("run");
+  h7->GetYaxis()->SetTitle("(TPC+ITS)+ITSsa/ITSpureSA");
+  h7->GetXaxis()->SetTitle("run");
+  h8->GetYaxis()->SetTitle("(TPC+ITS)+ITSsa/ITSpureSA");
+  h8->GetXaxis()->SetTitle("run"); 
+  h0->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[0],Upbin[0]));
+  h1->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[1],Upbin[1]));
+  h2->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[2],Upbin[2]));
+  h3->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[0],Upbin[0]));
+  h4->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[1],Upbin[1]));
+  h5->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[2],Upbin[2]));
+  h6->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[0],Upbin[0]));
+  h7->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[1],Upbin[1]));
+  h8->SetTitle(Form("%.1f GeV/c < pt < %.1f GeV/c",Lowbin[2],Upbin[2]));
+  h0->SetMinimum(100);
+//   h0->SetMaximum(2);
+  h1->SetMinimum(100);
+//   h1->SetMaximum(2);
+  h2->SetMinimum(100);
+//   h2->SetMaximum(2);
+  h3->SetMinimum(100);
+  h4->SetMinimum(100);
+  h5->SetMinimum(100);
+
+  h8->SetMinimum(0.);
+  h8->SetMaximum(2.5);
+
+  h0->SetMarkerStyle(22);
+  h1->SetMarkerStyle(23);
+  h2->SetMarkerStyle(24);
+  h0->SetMarkerColor(2);
+  h1->SetMarkerColor(1);
+  h2->SetMarkerColor(4);
+  h0->SetLineColor(2);
+  h1->SetLineColor(1);
+  h2->SetLineColor(4);
+
+  h3->SetMarkerStyle(22);
+  h4->SetMarkerStyle(23);
+  h5->SetMarkerStyle(24);
+  h3->SetMarkerColor(2);
+  h4->SetMarkerColor(1);
+  h5->SetMarkerColor(4);
+  h3->SetLineColor(2);
+  h4->SetLineColor(1);
+  h5->SetLineColor(4);
+
+  h6->SetMarkerStyle(22);
+  h7->SetMarkerStyle(23);
+  h8->SetMarkerStyle(24);
+  h6->SetMarkerColor(2);
+  h7->SetMarkerColor(1);
+  h8->SetMarkerColor(4);
+  h6->SetLineColor(2);
+  h7->SetLineColor(1);
+  h8->SetLineColor(4);
+
+  TCanvas *c=new TCanvas();
+  c->SetLogy();
+  c->SetGridy();
+  h0->Draw("p");
+  h1->Draw("psame");
+  h2->Draw("psame");
+c->BuildLegend(0.11,0.15,0.45,0.30);
+  TLatex* ti1=new TLatex(0.11,0.40,"ITS pure SA tracks (normalized to number of events)");
+  ti1->SetNDC();
+  ti1->SetTextColor(1);
+  ti1->Draw();
+  c->SaveAs("ITSsa_trend.pdf");
+      pdfFileNames+=" ITSsa_trend.pdf";
+  TCanvas *c2=new TCanvas();
+  c2->SetLogy();
+  c2->SetGridy();
+  h3->Draw("p");
+  h4->Draw("psame");
+  h5->Draw("psame");
+ c2->BuildLegend(0.11,0.15,0.45,0.30);
+  TLatex* ti2=new TLatex(0.11,0.40,"ITS+TPC tracks (normalized to number of events)");
+  ti2->SetNDC();
+  ti2->SetTextColor(1);
+  ti2->Draw();
+   c2->SaveAs("ITSTPC_trend.pdf");
+      pdfFileNames+=" ITSTPC_trend.pdf";
+  TCanvas *c3=new TCanvas();
+  c3->SetGridy();
+  h8->Draw("p");
+  h7->Draw("psame");
+  h6->Draw("psame");
+   c3->BuildLegend();
+  TLatex* ti3=new TLatex(0.10,0.8,"(ITSTPC+ITSsa)/ITSpureSA ");
+  ti3->SetNDC();
+  ti3->Draw();
+   c3->SaveAs("tracks_ratio_trend.pdf");
+      pdfFileNames+=" tracks_ratio_trend.pdf";
+
+}
+
+
+
+//____________________________________________________________________________
+void AliITSQAtrend(TString runListFile,TString ntupleFileName){
+
+  TGrid::Connect("alien://");
+  
+
+  
+  //-----------SDD
+  
+  const Int_t nVariables=43;
+  TNtuple* ntsdd=new TNtuple("ntsdd","SDD trending","nrun:fracTrackWithClu1:errfracTrackWithClu1:fracTrackWithClu2:errfracTrackWithClu2:fracTrackWithClu3:errfracTrackWithClu3:fracTrackWithClu4:errfracTrackWithClu4:fracTrackWithClu5:errfracTrackWithClu5:fracTrackWithClu6:errfracTrackWithClu6:meanTrPts3:errmeanTrPts3:meanTrPts4:errmeanTrPts4:minDrTime:errminDrTime:meanDrTime:errmeanDrTime:fracExtra:errfracExtra:meandEdxLay3:errmeandEdxLay3:meandEdxLay4:errmeandEdxLay4:meandEdxTB0:errmeandEdxTB0:meandEdxTB5:errmeandEdxTB5:MPVdEdxLay3:errMPVdEdxLay3:MPVdEdxLay4:errMPVdEdxLay4:MPVdEdxTB0:errMPVdEdxTB0:MPVdEdxTB5:errMPVdEdxTB5:nMod95:nMod80:nMod60:nModEmpty");
+  Float_t xnt[nVariables];
+  
+  //--------------SSD
+    
+  const Int_t nVariablesSSD=14;
+  TNtuple* ntssd=new TNtuple("ntssd","SSD trending","nrun:meandEdxLay5:errmeandEdxLay5:meandEdxLay6:errmeandEdxLay6:MPVdEdxLay5:errMPVdEdxLay5:MPVdEdxLay6:errMPVdEdxLay6:ChargeRatioL5:errChargeratioL5:ChargeRatioL6:errChargeratioL6:moduleOff");
+  Float_t xntSSD[nVariablesSSD];
+  
+  //----Matching
+
+  const Int_t nVariablesMatching=60;
+  TNtuple* ntmatching=new TNtuple("ntmatching","Matching Efficiency","nrun:FracSPD1:errFracSPD1:FracSPD2:errFracSPD2:Eff6Pt02:errEff6Pt02:Eff6Pt1:errEff6Pt1:Eff6Pt10:errEff6Pt10:Eff5Pt02:errEff5Pt02:Eff5Pt1:errEff5Pt1:Eff5Pt10:errEff5Pt10:Eff4Pt02:errEff4Pt02:Eff4Pt1:errEff4Pt1:Eff4Pt10:errEff4Pt10:Eff3Pt02:errEff3Pt02:Eff3Pt1:errEff3Pt1:Eff3Pt10:errEff3Pt10:Eff2Pt02:errEff2Pt02:Eff2Pt1:errEff2Pt1:Eff2Pt10:errEff2Pt10:EffSPDPt02:errEffSPDPt02:EffSPDPt1:errEffSPDPt1:EffSPDPt10:errEffSPDPt10:EffoneSPDPt02:errEffoneSPDPt02:EffoneSPDPt1:errEffoneSPDPt1:EffoneSPDPt10:errEffoneSPDPt10:EffTOTPt02:errEffTOTPt02:EffTOTPt1:errEffTOTPt1:EffTOTPt10:errEffTOTPt10");
+
+  Float_t xntMatching[nVariablesMatching];
+  
+  //--------------------------------
+
+  //----QA Vertex
+
+  const Int_t nVariablesVertex=27;
+  TNtuple* ntvertex=new TNtuple("ntvertex","QA Vertex","nrun:VxTRK:errVxTRK:sigmaVxTRK:errsigmaVxTRK:VyTRK:errVyTRK:sigmaVyTRK:errsigmaVyTRK:VzTRK:errVzTRK:sigmaVzTRK:errsigmaVzTRK:VxSPD:errVxSPD:sigmaVxSPD:errsigmaVxSPD:VySPD:errVySPD:sigmaVySPD:errsigmaVySPD:VzSPD:errVzSPD:sigmaVzSPD:errsigmaVzSPD");
+      
+  Float_t xntVertex[nVariablesVertex];
+  
+  //--------------------------------
+
+  //-----  Tracking ITS SA
+  const Int_t nVariablesSA=13;
+  Float_t xntSA[nVariablesSA];
+  TNtuple *ntSA=new TNtuple("ntITSsa","ntITSsa","run:NITSTPCPtBin0:NITSTPCPtBin1:NITSTPCPtBin2:NITSsaPtBin0:NITSsaPtBin1:NITSsaPtBin2:NITSpureSAPtBin0:NITSpureSAPtBin1:NITSpureSAPtBin2:ratioPtBin0:ratioPtBin1:ratioPtBin2");
+
+  //---------------------------------
+
+
+  
+  TBits* readRun=new TBits(999999);
+  readRun->ResetAllBits();
+  //    if(!useExternalList){
+  if(!gSystem->Exec(Form("ls -l %s > /dev/null 2>&1",ntupleFileName.Data()))){
+    TFile* oldfil=new TFile(ntupleFileName.Data());
+    
+    TNtuple* ntmp=(TNtuple*)oldfil->Get("ntsdd");
+    
+    TNtuple* ntmpSSD=(TNtuple*)oldfil->Get("ntssd");
+
+    TNtuple* ntmpMatching=(TNtuple*)oldfil->Get("ntmatching");
+
+    TNtuple* ntmpVertex=(TNtuple*)oldfil->Get("ntvertex");
+
+    TNtuple* ntmpSA=(TNtuple*)oldfil->Get("ntITSsa");
+
+    
+    //-------SDD
+    
+    Bool_t isOK=kFALSE;
+    if(ntmp){
+      if(ntmp->GetNvar()==ntsdd->GetNvar()){
+       isOK=kTRUE;
+       TObjArray* arr1=(TObjArray*)ntsdd->GetListOfBranches();
+       TObjArray* arr2=(TObjArray*)ntmp->GetListOfBranches();
+       for(Int_t iV=0; iV<ntmp->GetNvar(); iV++){
+         TString vnam1=arr1->At(iV)->GetName();
+         TString vnam2=arr2->At(iV)->GetName();
+         if(vnam1!=vnam2) isOK=kFALSE;
+         ntmp->SetBranchAddress(vnam2.Data(),&xnt[iV]);
+       }
+       if(isOK){
+         for(Int_t nE=0; nE<ntmp->GetEntries(); nE++){
+           ntmp->GetEvent(nE);
+           Int_t theRun=(Int_t)(xnt[0]+0.0001);
+           readRun->SetBitNumber(theRun);
+           ntsdd->Fill(xnt);
+         }
+       }
+      }
+    }
+    if(!isOK){
+      printf("Ntuple in local file not OK -> will be recreated\n");
+    }
+       
+    //----------SSD----------
+       
+    Bool_t isOKSSD=kFALSE;
+    if(ntmpSSD){
+      if(ntmpSSD->GetNvar()==ntssd->GetNvar()){
+       isOKSSD=kTRUE;
+       TObjArray* arr1ssd=(TObjArray*)ntssd->GetListOfBranches();
+       TObjArray* arr2ssd=(TObjArray*)ntmpSSD->GetListOfBranches();
+       for(Int_t iV=0; iV<ntmpSSD->GetNvar(); iV++){
+         TString vnam1=arr1ssd->At(iV)->GetName();
+         TString vnam2=arr2ssd->At(iV)->GetName();
+         if(vnam1!=vnam2) isOKSSD=kFALSE;
+         ntmpSSD->SetBranchAddress(vnam2.Data(),&xntSSD[iV]);
+       }
+       if(isOKSSD){
+         for(Int_t nE=0; nE<ntmpSSD->GetEntries(); nE++){
+           ntmpSSD->GetEvent(nE);
+           Int_t theRun=(Int_t)(xntSSD[0]+0.0001);
+           readRun->SetBitNumber(theRun);
+           ntssd->Fill(xntSSD);
+         }
+       }
+      }
+    }
+    if(!isOKSSD){
+      printf("\n\nNtuple SSD in local file not OK -> will be recreated\n\n");
+    }
+
+    //---------Matching---------
+       
+    Bool_t isOKMatching=kFALSE;
+    if(ntmpMatching){
+      if(ntmpMatching->GetNvar()==ntmatching->GetNvar()){
+       isOKMatching=kTRUE;
+       TObjArray* arr1matching=(TObjArray*)ntmatching->GetListOfBranches();
+       TObjArray* arr2matching=(TObjArray*)ntmpMatching->GetListOfBranches();
+       for(Int_t iV=0; iV<ntmpMatching->GetNvar(); iV++){
+         TString vnam1=arr1matching->At(iV)->GetName();
+         TString vnam2=arr2matching->At(iV)->GetName();
+         if(vnam1!=vnam2) isOKMatching=kFALSE;
+         ntmpMatching->SetBranchAddress(vnam2.Data(),&xntMatching[iV]);
+       }
+       if(isOKMatching){
+         for(Int_t nE=0; nE<ntmpMatching->GetEntries(); nE++){
+           ntmpMatching->GetEvent(nE);
+           Int_t theRun=(Int_t)(xntMatching[0]+0.0001);
+           readRun->SetBitNumber(theRun);
+           ntmatching->Fill(xntMatching);
+         }
+       }
+      }
+    }
+    if(!isOKMatching){
+      printf("\n\nNtuple Matching in local file not OK -> will be recreated\n\n");
+    }
+    //-----------------------
+
+    //---------Vertex QA---------
+       
+    Bool_t isOKVertex=kFALSE;
+    if(ntmpVertex){
+      if(ntmpVertex->GetNvar()==ntvertex->GetNvar()){
+       isOKVertex=kTRUE;
+       TObjArray* arr1vertex=(TObjArray*)ntvertex->GetListOfBranches();
+       TObjArray* arr2vertex=(TObjArray*)ntmpVertex->GetListOfBranches();
+       for(Int_t iV=0; iV<ntmpVertex->GetNvar(); iV++){
+         TString vnam1=arr1vertex->At(iV)->GetName();
+         TString vnam2=arr2vertex->At(iV)->GetName();
+         if(vnam1!=vnam2) isOKVertex=kFALSE;
+         ntmpVertex->SetBranchAddress(vnam2.Data(),&xntVertex[iV]);
+       }
+       if(isOKVertex){
+         for(Int_t nE=0; nE<ntmpVertex->GetEntries(); nE++){
+           ntmpVertex->GetEvent(nE);
+           Int_t theRun=(Int_t)(xntVertex[0]+0.0001);
+           readRun->SetBitNumber(theRun);
+           ntvertex->Fill(xntVertex);
+         }
+       }
+      }
+    }
+    if(!isOKVertex){
+      printf("\n\nNtuple Vertex in local file not OK -> will be recreated\n\n");
+    }
+    //-----------------------
+
+    //-----------Tracking SA ----------------
+    Bool_t isOKSA = kFALSE;
+    if(ntmpSA){
+      if(ntmpSA->GetNvar()==ntSA->GetNvar()){
+       isOKSA = kTRUE;
+       TObjArray* arr1SA=(TObjArray*)ntSA->GetListOfBranches();
+       TObjArray* arr2SA=(TObjArray*)ntmpSA->GetListOfBranches();
+       for(Int_t iV=0; iV<ntmpSA->GetNvar(); iV++){
+         TString vnam1=arr1SA->At(iV)->GetName();
+         TString vnam2=arr2SA->At(iV)->GetName();
+         if(vnam1!=vnam2) isOKSA=kFALSE;
+         ntmpSA->SetBranchAddress(vnam2.Data(),&xntSA[iV]);
+       }
+       if(isOKSA){
+         for(Int_t nE=0; nE<ntmpSA->GetEntries(); nE++){
+           ntmpSA->GetEvent(nE);
+           Int_t theRun=(Int_t)(xntSA[0]+0.0001);
+           readRun->SetBitNumber(theRun);
+           ntSA->Fill(xntSA);
+         }
+       }
+      }
+    }
+
+    oldfil->Close();
+    delete oldfil;
+  }
+
+#define MAX_LINES 200
+#define MAX_LINE_LEN 255
+  
+  char strings[MAX_LINES][MAX_LINE_LEN];
+  ifstream in(runListFile.Data());
+  int j = 0;
+  Int_t nrun=0;
+  Int_t runNumb[MAX_LINES];
+  Int_t fillNumb[MAX_LINES];
+  Bool_t goout = kFALSE;
+  while ( in ) {
+    in.getline(strings[j], MAX_LINE_LEN);
+    TString aux(strings[j]);
+    TString auxrun(strings[j]);
+    TString auxfill(strings[j]);
+    Int_t lentrail=0;
+    Int_t lenfill=0;
+    if(aux.Contains("LHC11h/")){
+      lentrail = 27;
+    }
+    else if(aux.Contains("LHC11h_2/")){
+      lentrail = 29;
+    }
+    else if(aux.Contains("LHC12a17b/")){
+      lentrail = 26;
+    }
+    else if(aux.Contains("LHC12b/")){
+      lentrail = 27;
+      lenfill=30;
+    }
+    else if(aux.Contains("LHC12c/")){
+      lentrail = 27;
+    }
+    else if(aux.Contains("LHC12a/")){
+      lentrail = 27;
+      lenfill=30;
+    }
+  
+    
+    else {
+      if(!aux.IsNull())printf("Unrecognised path name %s \n",aux.Data());
+      goout = kTRUE;
+    }
+    if(goout)break;
+    if(aux.Length()<lentrail)continue;
+    auxrun=aux.Remove(0,lentrail);
+    auxfill=aux.Remove(0,36);
+    // cout<<" auxfill= "<<auxfill<<endl;
+    aux=aux.Remove(6,aux.Length());
+    //    aux=aux.Remove();
+    runNumb[j]=atoi(auxrun.Data());
+    fillNumb[j]=atoi(auxfill.Data());
+    printf("%d ) - fill %d - path %s \n",runNumb[j],fillNumb[j],strings[j]);
+    j++;
+    nrun++;
+  }
+
+  printf("\n *******************   Loop on runs *********** \n");
+  Int_t filenotfound=0;
+  for(Int_t jru=0;jru<nrun;jru++) {
+    printf("jru=%d - run number= %d \n",jru,runNumb[jru]);
+    Int_t iRun=runNumb[jru];
+    if(readRun->TestBitNumber(iRun))printf("Run %d - already processed\n",iRun);
+    if(readRun->TestBitNumber(iRun))continue;
+    //cout << "Value from file is " <<t << endl;
+    
+    //    printf("%s\n",strings[jru]);
+  
+  
+    if(!gGrid||!gGrid->IsConnected()) {
+      printf("gGrid not found! exit macro\n");
+      return;
+    }
+    
+    TFile *f=TFile::Open(Form("alien://%s",strings[jru])); 
+    if(!f) {
+      printf("File not found, continue with next one\n");
+      filenotfound++;
+      continue;
+    }
+    
+    TDirectoryFile* df=(TDirectoryFile*)f->Get("SDD_Performance");
+    if(!df){
+      printf("Run %d SDD_Performance MISSING -> Exit\n",iRun);
+      continue;
+    }
+    
+    TList* l=(TList*)df->Get("coutputRP");
+    if(!df){
+      printf("Run %d coutputRP TList MISSING -> Exit\n",iRun);
+      continue;
+    }  
+    
+    //-------------------
+
+    
+    //------------SDD
+
+    cout<<"SDD - QA"<<endl;
+
+    TH1F* hcllay=(TH1F*)l->FindObject("hCluInLay");
+    
+    if(hcllay->GetEntries()==0){
+
+      printf("Run %d hcllay EMPTY -> Continue\n",iRun);
+      continue;
+      
+    }
+
+    Float_t fracT[6]={0.,0.,0.,0.,0.,0.};
+    Float_t efracT[6]={0.,0.,0.,0.,0.,0.};
+    if(hcllay->GetBinContent(1)>0){
+      for(Int_t iLay=0; iLay<6; iLay++){
+       fracT[iLay]=hcllay->GetBinContent(iLay+2)/hcllay->GetBinContent(1);
+       efracT[iLay]=TMath::Sqrt(fracT[iLay]*(1-fracT[iLay])/hcllay->GetBinContent(1));
+      }
+    }
+    
+    TH1F* hmodT=(TH1F*)l->FindObject("hTPMod");
+    
+    if(hmodT->GetEntries()==0){
+      printf("Run %d hmodT EMPTY -> Continue\n",iRun);
+      continue;
+    }
+    
+    TH1F* hgamod=(TH1F*)l->FindObject("hGAMod");
+    
+    if(hgamod->GetEntries()==0){
+      printf("Run %d hgamod EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    Int_t bestMod=0;
+    for(Int_t iMod=0; iMod<260;iMod++){
+      Int_t gda=(Int_t)hgamod->GetBinContent(iMod+1);
+      if(gda>bestMod) bestMod=gda;
+    }
+    Int_t nChunks=1;
+    if(bestMod>512){
+      nChunks=(Int_t)(bestMod/512.+0.5);
+    }
+    hgamod->Scale(1./nChunks);
+    
+    TH1F* hev=(TH1F*)l->FindObject("hNEvents");
+
+    if(hev->GetEntries()==0){
+      printf("Run %d hev EMPTY -> Continue\n",iRun);
+      continue;
+    }
+    
+    Int_t nTotEvents=hev->GetBinContent(2);
+    Int_t nTrigEvents=hev->GetBinContent(3);
+    Int_t nEvents=nTotEvents;
+    printf("Run %d Number of Events = %d Triggered=%d\n",iRun,nTotEvents,nTrigEvents);
+    if(nTrigEvents>0){ 
+      nEvents=nTrigEvents;
+    }
+    if(nTotEvents==0) continue;
+    Int_t nModGood3=0;
+    Int_t nModGood4=0;
+    Int_t nModBadAn=0;
+    Float_t sumtp3=0;
+    Float_t sumtp4=0;
+    Float_t sumEtp3=0;
+    Float_t sumEtp4=0;
+    for(Int_t iMod=0; iMod<260; iMod++){
+      Float_t tps=hmodT->GetBinContent(iMod+1);
+      Float_t ga=hgamod->GetBinContent(iMod+1);
+      if(ga<500) nModBadAn++;
+      Float_t tpsN=0.;
+      Float_t etpsN=0.;
+      if(ga>0){
+       tpsN=tps/ga/(Float_t)nEvents;
+       etpsN=TMath::Sqrt(tps)/ga/(Float_t)nEvents;
+       if(iMod<84){
+         sumtp3+=tpsN;
+         sumEtp3+=(etpsN*etpsN);
+         nModGood3++;
+       }
+       else{
+         sumtp4+=tpsN;
+         sumEtp4+=(etpsN*etpsN);
+         nModGood4++;
+       }
+      }
+    }
+
+    TH1F* hapmod=(TH1F*)l->FindObject("hAllPmod");
+      
+    if(hapmod->GetEntries()==0){
+      printf("Run %d hapmod EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+
+    TH1F* hgpmod=(TH1F*)l->FindObject("hGoodPmod");
+    if(hgpmod->GetEntries()==0){
+      printf("Run %d hgpmod EMPTY -> Continue\n",iRun);
+      continue;
+    }
+      
+    //     TH1F* hmpmod=(TH1F*)l->FindObject("hMissPmod");
+    TH1F* hbrmod=(TH1F*)l->FindObject("hBadRegmod");
+    if(hbrmod->GetEntries()==0){
+      printf("Run %d hbrmod EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F* hskmod=(TH1F*)l->FindObject("hSkippedmod");
+    TH1F* hoamod=(TH1F*)l->FindObject("hOutAccmod");
+    TH1F* hnrmod=(TH1F*)l->FindObject("hNoRefitmod");
+
+    Int_t nBelow95=0;
+    Int_t nBelow80=0;
+    Int_t nBelow60=0;
+    Int_t nZeroP=0;
+    for(Int_t imod=0; imod<260;imod++){
+      Float_t numer=hgpmod->GetBinContent(imod+1)+hbrmod->GetBinContent(imod+1)+hoamod->GetBinContent(imod+1)+hnrmod->GetBinContent(imod+1)+hskmod->GetBinContent(imod+1);
+      Float_t denom=hapmod->GetBinContent(imod+1);
+      if(denom>0){
+       Float_t eff=numer/denom;
+       if(eff<0.95) nBelow95++;
+       if(eff<0.80) nBelow80++;
+       if(eff<0.60) nBelow60++;
+      }
+      if(hmodT->GetBinContent(imod+1)<1.){
+       nZeroP++;
+      }        
+    }
+
+    TH1F* htimT=(TH1F*)l->FindObject("hDrTimTPAll");
+
+    if(htimT->GetEntries()==0){
+      printf("Run %d htimT EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F* htimTe=(TH1F*)l->FindObject("hDrTimTPExtra");
+      
+    if(htimTe->GetEntries()==0){
+      printf("Run %d htimTe EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    Double_t fracExtra=0.;
+    Double_t errFracExtra=0.;
+    if(htimT->GetEntries()>0){
+      fracExtra=htimTe->GetEntries()/htimT->GetEntries();
+      errFracExtra=TMath::Sqrt(htimTe->GetEntries())/htimT->GetEntries();
+    }
+    Double_t averPoints=0.;
+    Double_t cntBins=0.;
+    for(Int_t iBin=1; iBin<=htimT->GetNbinsX(); iBin++){
+      Float_t tim=htimT->GetBinCenter(iBin);
+      if(tim>2000. && tim<4000.){
+       averPoints+=htimT->GetBinContent(iBin);
+       cntBins+=1;
+      }
+    }
+    Double_t minTime=-999.;
+    Double_t errMinTime=0.;
+    if(cntBins>0){ 
+      averPoints/=cntBins;
+      for(Int_t iBin=1; iBin<=htimT->GetNbinsX(); iBin++){
+       if(htimT->GetBinContent(iBin)>0.5*averPoints){
+         minTime=htimT->GetBinCenter(iBin);
+         errMinTime=0.5*htimT->GetBinWidth(iBin);
+         break;
+       }
+      }
+    }
+
+    TH2F* hdedxmod=(TH2F*)l->FindObject("hdEdxVsMod");
+
+    if(hdedxmod->GetEntries()==0){
+      printf("Run %d hdedxmod EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1D* hdedxLay3=hdedxmod->ProjectionY("hdedxLay3",1,84);
+    TH1D* hdedxLay4=hdedxmod->ProjectionY("hdedxLay4",85,260);
+      
+    TH1F* hSigTim0=(TH1F*)l->FindObject("hSigTimeInt0");
+    if(hSigTim0->GetEntries()==0){
+      printf("Run %d hSigTim0 EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F* hSigTim5=(TH1F*)l->FindObject("hSigTimeInt5");
+    if(hSigTim5->GetEntries()==0){
+      printf("Run %d hSigTim5  EMPTY -> Continue\n",iRun);
+      continue;
+    }
+    //Fitting the same distributions in order to have the MPV
+    TF1 *lfunLay3 = new TF1("LangausFunLay3",LangausFun,50.,300.,4); 
+    lfunLay3->SetParameter(0,5.);
+    lfunLay3->SetParameter(1,80.);
+    lfunLay3->SetParameter(2,hdedxLay3->GetEntries()/10.);
+    lfunLay3->SetParameter(3,10.);
+    lfunLay3->SetParLimits(3,0.,20);
+    hdedxLay3->Fit(lfunLay3,"NQLR");
+    TF1 *lfunLay4 = new TF1("LangausFunLay4",LangausFun,50.,300.,4); 
+    lfunLay4->SetParameter(0,5.);
+    lfunLay4->SetParameter(1,80.);
+    lfunLay4->SetParameter(2,hdedxLay4->GetEntries()/10.);
+    lfunLay4->SetParameter(3,10.);
+    lfunLay4->SetParLimits(3,0.,20);
+    hdedxLay4->Fit(lfunLay4,"NQLR");
+    TF1 *lfunTim0 = new TF1("LangausFunTim0",LangausFun,50.,300.,4); 
+    lfunTim0->SetParameter(0,5.);
+    lfunTim0->SetParameter(1,80.);
+    lfunTim0->SetParameter(2,hSigTim0->GetEntries()/10.);
+    lfunTim0->SetParameter(3,10.);
+    lfunTim0->SetParLimits(3,0.,20);
+    hSigTim0->Fit(lfunTim0,"NQLR");
+    TF1 *lfunTim5 = new TF1("LangausFunTim5",LangausFun,50.,300.,4); 
+    lfunTim5->SetParameter(0,5.);
+    lfunTim5->SetParameter(1,80.);
+    lfunTim5->SetParameter(2,hSigTim5->GetEntries()/10.);
+    lfunTim5->SetParameter(3,10.);
+    lfunTim5->SetParLimits(3,0.,20);
+    hSigTim5->Fit(lfunTim5,"NQLR");
+     
+    Int_t index=0;
+    xnt[index++]=iRun;
+    xnt[index++]=fracT[0];
+    xnt[index++]=efracT[0];
+    xnt[index++]=fracT[1];
+    xnt[index++]=efracT[1];
+    xnt[index++]=fracT[2];
+    xnt[index++]=efracT[2];
+    xnt[index++]=fracT[3];
+    xnt[index++]=efracT[3];
+    xnt[index++]=fracT[4];
+    xnt[index++]=efracT[4];
+    xnt[index++]=fracT[5];
+    xnt[index++]=efracT[5];
+    xnt[index++]=sumtp3/nModGood3;
+    xnt[index++]=TMath::Sqrt(sumEtp3)/nModGood3;
+    xnt[index++]=sumtp4/nModGood4;
+    xnt[index++]=TMath::Sqrt(sumEtp4)/nModGood4;
+    xnt[index++]=minTime;
+    xnt[index++]=errMinTime;
+    xnt[index++]=htimT->GetMean();
+    xnt[index++]=htimT->GetMeanError();
+    xnt[index++]=fracExtra;
+    xnt[index++]=errFracExtra;
+    xnt[index++]=hdedxLay3->GetMean();
+    xnt[index++]=hdedxLay3->GetMeanError();
+    xnt[index++]=hdedxLay4->GetMean();
+    xnt[index++]=hdedxLay4->GetMeanError();
+    xnt[index++]=hSigTim0->GetMean();
+    xnt[index++]=hSigTim0->GetMeanError();
+    xnt[index++]=hSigTim5->GetMean();
+    xnt[index++]=hSigTim5->GetMeanError();
+    xnt[index++]=lfunLay3->GetParameter(1);
+    xnt[index++]=lfunLay3->GetParError(1);
+    xnt[index++]=lfunLay4->GetParameter(1);
+    xnt[index++]=lfunLay4->GetParError(1);
+    xnt[index++]=lfunTim0->GetParameter(1);
+    xnt[index++]=lfunTim0->GetParError(1);
+    xnt[index++]=lfunTim5->GetParameter(1);
+    xnt[index++]=lfunTim5->GetParError(1);
+    xnt[index++]=(Float_t)nBelow95;
+    xnt[index++]=(Float_t)nBelow80;
+    xnt[index++]=(Float_t)nBelow60;
+    xnt[index++]=(Float_t)nZeroP;
+    ntsdd->Fill(xnt);
+
+    //    cout<<"\n\nirun sDD"<<iRun<<endl<<endl;
+
+    //-------SSD
+
+    cout<<"SSD - QA"<<endl;
+
+    //TFile* fSSD=TFile::Open(fileNameLong.Data());  
+    
+    //      TDirectoryFile* dfSSD=(TDirectoryFile*)f->Get("PWG1dEdxSSDQA");
+    TDirectoryFile* dfSSD=(TDirectoryFile*)f->Get("PWGPPdEdxSSDQA");
+    if(!dfSSD){
+      printf("Run %d SSD_Performance MISSING -> Exit\n",iRun);
+      continue;
+    }
+      
+    TList* lSSD=(TList*)dfSSD->Get("SSDdEdxQA");
+    if(!dfSSD){
+      printf("Run %d coutputRP TList MISSING -> Exit\n",iRun);
+      continue;
+    }
+    //
+      
+    TH2F* QAchargeRatio=(TH2F*)lSSD->FindObject("QAChargeRatio");
+      
+    if(QAchargeRatio->GetEntries()==0){
+      printf("Run %d QAchargeRatio EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH2F* QAcharge=(TH2F*)lSSD->FindObject("QACharge");
+      
+    if(QAcharge->GetEntries()==0){
+      printf("Run %d QAcharge EMPTY -> Continue\n",iRun);
+      continue;
+    }
+    Int_t biny = QAcharge->GetXaxis()->FindBin(747);
+    Int_t maxy = QAcharge->GetXaxis()->GetXmax();
+    //     Int_t miny = QAcharge->GetXaxis()->GetXmin();
+    
+    Int_t  contEmpty=0;
+    Int_t  contFull=0;
+    
+    TH1D *hChargeL5=QAcharge->ProjectionY("hChargeL5",0,biny);
+    TH1D *hChargeL6=QAcharge->ProjectionY("hChargeL6",biny,maxy);
+    
+//     cout<<  hChargeL5->GetMean()<< " " <<  hChargeL5->GetRMS()<<endl;
+//     cout<<  hChargeL6->GetMean()<< " " <<  hChargeL6->GetRMS()<<endl;
+    
+    TH1D *hChargeRatioL5=QAchargeRatio->ProjectionY("hChargeRatioL5",0,biny);
+    TH1D *hChargeRatioL6=QAchargeRatio->ProjectionY("hChargeRatioL6",biny,maxy);
+    
+//     cout<<  hChargeRatioL5->GetMean()<< " " <<  hChargeRatioL5->GetRMS()<<endl;
+//     cout<<  hChargeRatioL6->GetMean()<< " " <<  hChargeRatioL6->GetRMS()<<endl;
+    
+    if(QAcharge->GetEntries()< 45000)
+      contEmpty=1;
+      
+    else{
+      for(Int_t i =0;i<1698;i++){
+         
+       TString tmpQ("Q");
+       tmpQ+=i;
+         
+       TH1D* fHist1DQ= QAcharge->ProjectionY(tmpQ,i+1,i+1);
+       Double_t mean=fHist1DQ->GetMean();
+
+       if(TMath::Abs(mean)<1.0 ||fHist1DQ->GetEntries()<10)
+         contEmpty++;
+         
+       else 
+         contFull++;
+         
+      }
+    }
+
+//     cout<<"contFull: " <<contFull<<" contEmpty: "<<contEmpty<<endl;
+//     cout<<hChargeL5->GetMean()<<endl;
+
+    //Fitting dE/dx Distr in order to have the MPV
+    TF1 *lfunLay5 = new TF1("LangausFunLay5",LangausFun,50.,300.,4); 
+    lfunLay5->SetParameter(0,5.);
+    lfunLay5->SetParameter(1,80.);
+    lfunLay5->SetParameter(2,hChargeL5->GetEntries()/10.);
+    lfunLay5->SetParameter(3,10.);
+    lfunLay5->SetParLimits(3,0.,20);
+    hChargeL5->Fit(lfunLay5,"NQLR");
+    TF1 *lfunLay6 = new TF1("LangausFunLay6",LangausFun,50.,300.,4); 
+    lfunLay6->SetParameter(0,5.);
+    lfunLay6->SetParameter(1,80.);
+    lfunLay6->SetParameter(2,hChargeL6->GetEntries()/10.);
+    lfunLay6->SetParameter(3,10.);
+    lfunLay6->SetParLimits(3,0.,20);
+    hChargeL6->Fit(lfunLay6,"NQLR");
+      
+    Int_t indexSSD=0;
+    xntSSD[indexSSD++]=iRun;
+    xntSSD[indexSSD++]=(Float_t)hChargeL5->GetMean();
+    xntSSD[indexSSD++]=(Float_t)hChargeL5->GetMeanError();
+    xntSSD[indexSSD++]=(Float_t)hChargeL6->GetMean();
+    xntSSD[indexSSD++]=(Float_t)hChargeL6->GetMeanError();
+    xntSSD[indexSSD++]=(Float_t)lfunLay5->GetParameter(1);
+    xntSSD[indexSSD++]=(Float_t)lfunLay5->GetParError(1);
+    xntSSD[indexSSD++]=(Float_t)lfunLay6->GetParameter(1);
+    xntSSD[indexSSD++]=(Float_t)lfunLay6->GetParError(1);
+    xntSSD[indexSSD++]=(Float_t)hChargeRatioL5->GetMean();
+    xntSSD[indexSSD++]=(Float_t)hChargeRatioL5->GetMeanError();
+    xntSSD[indexSSD++]=(Float_t)hChargeRatioL6->GetMean();
+    xntSSD[indexSSD++]=(Float_t)hChargeRatioL6->GetMeanError();
+    xntSSD[indexSSD++]=(Float_t)contEmpty;
+    ntssd->Fill(xntSSD);                                               
+
+    //    cout<<xnt<<endl<<endl;
+
+//     cout<<"irun ssd "<<iRun<<endl;
+
+//     cout<< iRun<<" "<<hChargeL5->GetMean()<<" "<< hChargeL5->GetRMS()<<" "<<hChargeL6->GetMean()<<" "<<hChargeRatioL5->GetMean()<<" "<<" "<<hChargeRatioL5->GetRMS()<<" "<<hChargeRatioL6->GetMean()<<" "<<hChargeRatioL6->GetRMS()<<" "<<contEmpty<<endl;
+
+//     cout<<xntSSD[0]<<" "<<xntSSD[1]<<" "<<xntSSD[2]<<" "<<xntSSD[3]<<endl;;
+      
+    //--------------matching
+
+    cout<<"Tracking"<<endl;
+
+    TDirectoryFile *dirMatch=(TDirectoryFile*)f->GetDirectory("ITS_Performance");
+    TList *list=NULL;
+    TList *listSPD=NULL;
+      
+    if(dirMatch) {
+      //       list = (TList*)dirMatch->Get("cOutputITS_3500_10000"); //LHC11h
+      //       if(!list)list = (TList*)dirMatch->Get("cOutputITS"); // LHC11e
+      list = (TList*)dirMatch->Get("cOutputITS"); // LHC12e
+    }
+    dirMatch=(TDirectoryFile*)f->GetDirectory("SPD_Performance");
+    if(dirMatch) listSPD = (TList*)dirMatch->Get("coutput1");
+  
+    // if(!list) return kFALSE;
+      
+    Float_t ioValues[30];
+    Float_t ioErrors[30];
+    for(Int_t jj=0;jj<30;jj++){
+      ioValues[jj]=0.;
+      ioErrors[jj]=0.;
+    }
+      
+    Float_t ptbin=0;
+      
+    TH1F *hFiredChip = (TH1F*)listSPD->FindObject("hFiredChip");
+
+    if(hFiredChip->GetEntries()==0){
+      printf("Run %d hFiredChip EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    Int_t nHSsInner=0,nHSsOuter=0;
+    for(Int_t i=0;i<400;i++) if(hFiredChip->GetBinContent(i)>0) nHSsInner++;
+    for(Int_t i=400;i<1200;i++) if(hFiredChip->GetBinContent(i)>0) nHSsOuter++;
+    nHSsInner = (Int_t)(nHSsInner/10);
+    nHSsOuter = (Int_t)(nHSsOuter/10);
+    // hnHSsSPD->SetBinContent(1,nHSsInner);
+    // hnHSsSPD->SetBinContent(2,nHSsOuter);
+      
+    ioValues[0]=(Float_t)nHSsInner/40.;
+    ioValues[1]=(Float_t)nHSsOuter/80.;
+
+    TH1F *fHistPtTPCInAcc = (TH1F*)list->FindObject("fHistPtTPCInAcc");
+
+    if(fHistPtTPCInAcc->GetEntries()==0){
+      printf("Run %dfHistPtTPCInAcc  EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *fHistPtITSMI6InAcc = (TH1F*)list->FindObject("fHistPtITSMI6InAcc");
+
+    if(fHistPtITSMI6InAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMI6InAcc EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *fHistPtITSMI5InAcc = (TH1F*)list->FindObject("fHistPtITSMI5InAcc");
+    if(fHistPtITSMI5InAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMI5InAcc EMPTY -> Continue\n",iRun);
+      continue;
+    }
+      
+    TH1F *fHistPtITSMI4InAcc = (TH1F*)list->FindObject("fHistPtITSMI4InAcc");
+    if(fHistPtITSMI5InAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMI5InAcc EMPTY -> Continue\n",iRun);
+      continue;
+    }
+      
+    TH1F *fHistPtITSMI3InAcc = (TH1F*)list->FindObject("fHistPtITSMI3InAcc");
+    if(fHistPtITSMI3InAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMI3InAcc EMPTY -> Continue\n",iRun);
+      continue;
+    }
+    TH1F *fHistPtITSMI2InAcc = (TH1F*)list->FindObject("fHistPtITSMI2InAcc");
+      
+    if(fHistPtITSMI2InAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMI2InAcc EMPTY -> Continue\n",iRun);
+      continue;
+    }
+    TH1F *fHistPtITSMISPDInAcc = (TH1F*)list->FindObject("fHistPtITSMISPDInAcc");
+    if(fHistPtITSMISPDInAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMISPDInAcc EMPTY -> Continue\n",iRun);
+      continue;
+    }
+      
+    TH1F *fHistPtITSMIoneSPDInAcc = (TH1F*)list->FindObject("fHistPtITSMIoneSPDInAcc");
+      
+    if(fHistPtITSMIoneSPDInAcc->GetEntries()==0){
+      printf("Run %d fHistPtITSMIoneSPDInAcc  EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *fHistPtITSMIge2InAcc = (TH1F*)fHistPtITSMI6InAcc->Clone("fHistPtITSMIge2InAcc");
+    fHistPtITSMIge2InAcc->Add(fHistPtITSMI5InAcc);
+    fHistPtITSMIge2InAcc->Add(fHistPtITSMI4InAcc);
+    fHistPtITSMIge2InAcc->Add(fHistPtITSMI3InAcc);
+    fHistPtITSMIge2InAcc->Add(fHistPtITSMI2InAcc);
+
+      
+
+    fHistPtITSMI6InAcc->Divide(fHistPtITSMI6InAcc,fHistPtTPCInAcc,1,1,"B");
+    ptbin=fHistPtITSMI6InAcc->FindBin(0.201);
+    ioValues[2]=fHistPtITSMI6InAcc->GetBinContent(ptbin);
+    ioErrors[2]=fHistPtITSMI6InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI6InAcc->FindBin(1.001);
+    ioValues[3]=fHistPtITSMI6InAcc->GetBinContent(ptbin);
+    ioErrors[3]=fHistPtITSMI6InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI6InAcc->FindBin(10.001);
+    ioValues[4]=fHistPtITSMI6InAcc->GetBinContent(ptbin);
+    ioErrors[4]=fHistPtITSMI6InAcc->GetBinError(ptbin);
+
+    fHistPtITSMI5InAcc->Divide(fHistPtITSMI5InAcc,fHistPtTPCInAcc,1,1,"B");
+      
+    ptbin=fHistPtITSMI5InAcc->FindBin(0.201);
+    ioValues[5]=fHistPtITSMI5InAcc->GetBinContent(ptbin);
+    ioErrors[5]=fHistPtITSMI5InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI5InAcc->FindBin(1.001);
+    ioValues[6]=fHistPtITSMI5InAcc->GetBinContent(ptbin);
+    ioErrors[6]=fHistPtITSMI5InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI5InAcc->FindBin(10.001);
+    ioValues[7]=fHistPtITSMI5InAcc->GetBinContent(ptbin);
+    ioErrors[7]=fHistPtITSMI5InAcc->GetBinError(ptbin);
+      
+    fHistPtITSMI4InAcc->Divide(fHistPtITSMI4InAcc,fHistPtTPCInAcc,1,1,"B");
+      
+    ptbin=fHistPtITSMI4InAcc->FindBin(0.201);
+    ioValues[9]=fHistPtITSMI4InAcc->GetBinContent(ptbin);
+    ioErrors[9]=fHistPtITSMI4InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI4InAcc->FindBin(1.001);
+    ioValues[10]=fHistPtITSMI4InAcc->GetBinContent(ptbin);
+    ioErrors[10]=fHistPtITSMI4InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI4InAcc->FindBin(10.001);
+    ioValues[11]=fHistPtITSMI4InAcc->GetBinContent(ptbin);
+    ioErrors[11]=fHistPtITSMI4InAcc->GetBinError(ptbin);
+
+    fHistPtITSMI3InAcc->Divide(fHistPtITSMI3InAcc,fHistPtTPCInAcc,1,1,"B");
+
+    ptbin=fHistPtITSMI3InAcc->FindBin(0.201);
+    ioValues[12]=fHistPtITSMI3InAcc->GetBinContent(ptbin);
+    ioErrors[12]=fHistPtITSMI3InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI3InAcc->FindBin(1.001);
+    ioValues[13]=fHistPtITSMI3InAcc->GetBinContent(ptbin);
+    ioErrors[13]=fHistPtITSMI3InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI3InAcc->FindBin(10.001);
+    ioValues[14]=fHistPtITSMI3InAcc->GetBinContent(ptbin);
+    ioErrors[14]=fHistPtITSMI3InAcc->GetBinError(ptbin);
+
+    fHistPtITSMI2InAcc->Divide(fHistPtITSMI2InAcc,fHistPtTPCInAcc,1,1,"B");
+
+    ptbin=fHistPtITSMI2InAcc->FindBin(0.201);
+    ioValues[15]=fHistPtITSMI2InAcc->GetBinContent(ptbin);
+    ioErrors[15]=fHistPtITSMI2InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI2InAcc->FindBin(1.001);
+    ioValues[16]=fHistPtITSMI2InAcc->GetBinContent(ptbin);
+    ioErrors[16]=fHistPtITSMI2InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMI2InAcc->FindBin(10.001);
+    ioValues[17]=fHistPtITSMI2InAcc->GetBinContent(ptbin);
+    ioErrors[17]=fHistPtITSMI2InAcc->GetBinError(ptbin);
+
+    fHistPtITSMISPDInAcc->Divide(fHistPtITSMISPDInAcc,fHistPtTPCInAcc,1,1,"B");
+    ptbin=fHistPtITSMISPDInAcc->FindBin(0.201);
+    ioValues[18]=fHistPtITSMISPDInAcc->GetBinContent(ptbin);
+    ioErrors[18]=fHistPtITSMISPDInAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMISPDInAcc->FindBin(1.001);
+    ioValues[19]=fHistPtITSMISPDInAcc->GetBinContent(ptbin);
+    ioErrors[19]=fHistPtITSMISPDInAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMISPDInAcc->FindBin(10.001);
+    ioValues[20]=fHistPtITSMISPDInAcc->GetBinContent(ptbin);
+    ioErrors[20]=fHistPtITSMISPDInAcc->GetBinError(ptbin);
+
+    fHistPtITSMIoneSPDInAcc->Divide(fHistPtITSMIoneSPDInAcc,fHistPtTPCInAcc,1,1,"B");
+
+    ptbin=fHistPtITSMIoneSPDInAcc->FindBin(0.201);
+    ioValues[21]=fHistPtITSMIoneSPDInAcc->GetBinContent(ptbin);
+    ioErrors[21]=fHistPtITSMIoneSPDInAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMIoneSPDInAcc->FindBin(1.001);
+    ioValues[22]=fHistPtITSMIoneSPDInAcc->GetBinContent(ptbin);
+    ioErrors[22]=fHistPtITSMIoneSPDInAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMIoneSPDInAcc->FindBin(10.001);
+    ioValues[23]=fHistPtITSMIoneSPDInAcc->GetBinContent(ptbin);
+    ioErrors[23]=fHistPtITSMIoneSPDInAcc->GetBinError(ptbin);
+
+  
+    fHistPtITSMIge2InAcc->Divide(fHistPtITSMIge2InAcc,fHistPtTPCInAcc,1,1,"B");
+    ptbin=fHistPtITSMIge2InAcc->FindBin(0.201);
+    ioValues[24]=fHistPtITSMIge2InAcc->GetBinContent(ptbin);
+    ioErrors[24]=fHistPtITSMIge2InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMIge2InAcc->FindBin(1.001);
+    ioValues[25]=fHistPtITSMIge2InAcc->GetBinContent(ptbin);
+    ioErrors[25]=fHistPtITSMIge2InAcc->GetBinError(ptbin);
+    ptbin=fHistPtITSMIge2InAcc->FindBin(10.001);
+    ioValues[26]=fHistPtITSMIge2InAcc->GetBinContent(ptbin);
+    ioErrors[26]=fHistPtITSMIge2InAcc->GetBinError(ptbin);
+
+    Int_t indexMatching=0;
+    xntMatching[indexMatching++]=iRun;
+    xntMatching[indexMatching++]=ioValues[0];
+    xntMatching[indexMatching++]=ioErrors[0];
+    xntMatching[indexMatching++]=ioValues[1];
+    xntMatching[indexMatching++]=ioErrors[1];
+    xntMatching[indexMatching++]=ioValues[2];
+    xntMatching[indexMatching++]=ioErrors[2];
+    xntMatching[indexMatching++]=ioValues[3];
+    xntMatching[indexMatching++]=ioErrors[3];
+    xntMatching[indexMatching++]=ioValues[4];
+    xntMatching[indexMatching++]=ioErrors[4];
+    xntMatching[indexMatching++]=ioValues[5];
+    xntMatching[indexMatching++]=ioErrors[5];
+    xntMatching[indexMatching++]=ioValues[6];
+    xntMatching[indexMatching++]=ioErrors[6];
+    xntMatching[indexMatching++]=ioValues[7];
+    xntMatching[indexMatching++]=ioErrors[7];
+    xntMatching[indexMatching++]=ioValues[8];
+    xntMatching[indexMatching++]=ioErrors[8];
+    xntMatching[indexMatching++]=ioValues[9];
+    xntMatching[indexMatching++]=ioErrors[9];
+    xntMatching[indexMatching++]=ioValues[10];
+    xntMatching[indexMatching++]=ioErrors[10];
+    xntMatching[indexMatching++]=ioValues[11];
+    xntMatching[indexMatching++]=ioErrors[11];
+    xntMatching[indexMatching++]=ioValues[12];
+    xntMatching[indexMatching++]=ioErrors[12];
+    xntMatching[indexMatching++]=ioValues[13];
+    xntMatching[indexMatching++]=ioErrors[13];
+    xntMatching[indexMatching++]=ioValues[14];
+    xntMatching[indexMatching++]=ioErrors[14];
+    xntMatching[indexMatching++]=ioValues[15];
+    xntMatching[indexMatching++]=ioErrors[15];
+    xntMatching[indexMatching++]=ioValues[16];
+    xntMatching[indexMatching++]=ioErrors[16];
+    xntMatching[indexMatching++]=ioValues[17];
+    xntMatching[indexMatching++]=ioErrors[17];
+    xntMatching[indexMatching++]=ioValues[18];
+    xntMatching[indexMatching++]=ioErrors[18];
+    xntMatching[indexMatching++]=ioValues[19];
+    xntMatching[indexMatching++]=ioErrors[19];
+    xntMatching[indexMatching++]=ioValues[20];
+    xntMatching[indexMatching++]=ioErrors[20];
+    xntMatching[indexMatching++]=ioValues[21];
+    xntMatching[indexMatching++]=ioErrors[21];
+    xntMatching[indexMatching++]=ioValues[22];
+    xntMatching[indexMatching++]=ioErrors[22];
+    xntMatching[indexMatching++]=ioValues[23];
+    xntMatching[indexMatching++]=ioErrors[23];
+    xntMatching[indexMatching++]=ioValues[24];
+    xntMatching[indexMatching++]=ioErrors[24];
+    xntMatching[indexMatching++]=ioValues[25];
+    xntMatching[indexMatching++]=ioErrors[25];
+    xntMatching[indexMatching++]=ioValues[26];
+    xntMatching[indexMatching++]=ioErrors[26];
+  
+    ntmatching->Fill(xntMatching);                                             
+
+    //---------------------------
+
+    cout<<"Primary Vertex"<<endl;
+
+    TDirectoryFile *dirVertex = (TDirectoryFile*)f->Get("Vertex_Performance");
+    if(!dirVertex){
+      Printf("Vertex directory not found... check!");
+    }
+  
+    TList *lt = (TList*)dirVertex->Get("cOutputVtxESD");
+       
+    TH1F *xVtxTRK = (TH1F*)lt->FindObject("fhTRKVertexX");
+
+    if(xVtxTRK->GetEntries()==0){
+      printf("Run %d xVtxTRK EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *yVtxTRK = (TH1F*)lt->FindObject("fhTRKVertexY");
+
+    if(yVtxTRK->GetEntries()==0){
+      printf("Run %d yVtxTRK EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *zVtxTRK = (TH1F*)lt->FindObject("fhTRKVertexZ");
+
+    if(zVtxTRK->GetEntries()==0){
+      printf("Run %d zVtxTRK EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+ TH1F *xVtxSPD = (TH1F*)lt->FindObject("fhSPDVertexX");
+
+    if(xVtxSPD->GetEntries()==0){
+      printf("Run %d xVtxSOD EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *yVtxSPD = (TH1F*)lt->FindObject("fhSPDVertexY");
+
+    if(yVtxSPD->GetEntries()==0){
+      printf("Run %d yVtxSPD EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TH1F *zVtxSPD = (TH1F*)lt->FindObject("fhSPDVertexZ");
+
+    if(zVtxSPD->GetEntries()==0){
+      printf("Run %d zVtxSPD EMPTY -> Continue\n",iRun);
+      continue;
+    }
+
+    TF1 *fxTRK = new TF1("gausx", "gaus", -1, 1);
+    xVtxTRK->Fit("gausx", "NQRL");
+
+    TF1 *fyTRK = new TF1("gausy", "gaus", -1, 1);
+    yVtxTRK->Fit("gausy","NQLR");
+//     cout<<fyTRK->GetParameter(1)<<endl;
+//     cout<<fyTRK->GetParError(1)<<endl;
+//     cout<<fyTRK->GetParameter(2)<<endl;
+//     cout<<fyTRK->GetParError(2)<<endl;
+
+    TF1 *fzTRK = new TF1("gausz", "gaus", -1, 1);
+    zVtxTRK->Fit("gausz","NQRL");
+ TF1 *fxSPD = new TF1("gausxSPD", "gaus", -1, 1);
+    xVtxSPD->Fit("gausxSPD", "NQRL");
+
+    TF1 *fySPD = new TF1("gausySPD", "gaus", -1, 1);
+    yVtxSPD->Fit("gausySPD","NQLR");
+//     cout<<fyTRK->GetParameter(1)<<endl;
+//     cout<<fyTRK->GetParError(1)<<endl;
+//     cout<<fyTRK->GetParameter(2)<<endl;
+//     cout<<fyTRK->GetParError(2)<<endl;
+
+    TF1 *fzSPD = new TF1("gauszSPD", "gaus", -1, 1);
+    zVtxSPD->Fit("gauszSPD","NQRL");
+//     cout<<fzTRK->GetParameter(1)<<endl;
+//     cout<<fzTRK->GetParError(1)<<endl;
+//     cout<<fzTRK->GetParameter(2)<<endl;
+//     cout<<fzTRK->GetParError(2)<<endl;
+
+
+    Int_t indexVertex=0;
+    xntVertex[indexVertex++]=iRun;
+    xntVertex[indexVertex++]=(Float_t)fxTRK->GetParameter(1);
+    xntVertex[indexVertex++]=(Float_t)fxTRK->GetParError(1);
+    xntVertex[indexVertex++]=(Float_t)fxTRK->GetParameter(2);
+    xntVertex[indexVertex++]=(Float_t)fxTRK->GetParError(2);
+    xntVertex[indexVertex++]=(Float_t)fyTRK->GetParameter(1);
+    xntVertex[indexVertex++]=(Float_t)fyTRK->GetParError(1);
+    xntVertex[indexVertex++]=(Float_t)fyTRK->GetParameter(2);
+    xntVertex[indexVertex++]=(Float_t)fyTRK->GetParError(2);
+    xntVertex[indexVertex++]=(Float_t)fzTRK->GetParameter(1);
+    xntVertex[indexVertex++]=(Float_t)fzTRK->GetParError(1);
+    xntVertex[indexVertex++]=(Float_t)fzTRK->GetParameter(2);
+    xntVertex[indexVertex++]=(Float_t)fzTRK->GetParError(2);
+ xntVertex[indexVertex++]=(Float_t)fxSPD->GetParameter(1);
+    xntVertex[indexVertex++]=(Float_t)fxSPD->GetParError(1);
+    xntVertex[indexVertex++]=(Float_t)fxSPD->GetParameter(2);
+    xntVertex[indexVertex++]=(Float_t)fxSPD->GetParError(2);
+    xntVertex[indexVertex++]=(Float_t)fySPD->GetParameter(1);
+    xntVertex[indexVertex++]=(Float_t)fySPD->GetParError(1);
+    xntVertex[indexVertex++]=(Float_t)fySPD->GetParameter(2);
+    xntVertex[indexVertex++]=(Float_t)fySPD->GetParError(2);
+    xntVertex[indexVertex++]=(Float_t)fzSPD->GetParameter(1);
+    xntVertex[indexVertex++]=(Float_t)fzSPD->GetParError(1);
+    xntVertex[indexVertex++]=(Float_t)fzSPD->GetParameter(2);
+    xntVertex[indexVertex++]=(Float_t)fzSPD->GetParError(2);
+    ntvertex->Fill(xntVertex); 
+
+                                       
+  
+    //---------------------------
+
+    //--------------   ITS SA ---------------
+    cout<<"ITS - SA"<<endl;
+    //    cout<<f<<" "<<ntSA<<" "<<iRun<<endl;
+    FillITSSAntuple(f,ntSA,iRun);
+
+  } // loop on runs
+
+  printf("%d runs skipped because QA file not found\n",filenotfound);
+  TFile* outfil=new TFile(ntupleFileName.Data(),"recreate");
+  outfil->cd();
+  ntsdd->Write();
+  ntssd->Write();
+  ntmatching->Write();
+  ntvertex->Write();
+  ntSA->Write();
+  outfil->Close();
+  delete outfil;
+  delete ntsdd;
+  delete ntssd;
+  delete ntmatching;
+  delete ntvertex;
+  delete ntSA;
+
+}
+
+//____________________________________________________________________________
+void FillITSSAntuple(TFile* f,TNtuple* nt, Int_t nrun){
+  static const Int_t nVariables=13;
+  static Float_t xnt[nVariables];
+  TH1F *hPtTPCITS=0x0;
+  TH1F *hPtITSsa=0x0;
+  TH1F *hPtITSpureSA=0x0;
+  Double_t Lowbin[3]={0.1,0.5,0.9};
+  Double_t Upbin[3]={0.2,0.6,1};
+  Double_t NTPCITS[3];
+  Double_t NITSsa[3];
+  Double_t NITSpureSA[3];
+  Double_t Ratio[3];
+  TDirectory *dirFile=(TDirectory*)f->Get("ITSsaTracks");
+  TList *cOutput = (TList*)dirFile->Get("clistITSsaTracks"); 
+  // histogram with number of events: in the first cell there is the number of the events
+  // in the second, the number of events with SPD vertex.
+  // normalization will be done to the second number
+  TH1F *hnev =(TH1F*)cOutput->FindObject("hNEvents");
+  Double_t noEvents = hnev->GetBinContent(1);
+  if(noEvents<1.)noEvents=1.;   // protection to avoid division by zero
+  hPtTPCITS=(TH1F*)cOutput->FindObject("hPtTPCITS");
+  hPtITSsa=(TH1F*)cOutput->FindObject("hPtITSsa");
+  hPtITSpureSA=(TH1F*)cOutput->FindObject("hPtITSpureSA");
+
+  for(Int_t ibin=0;ibin<=2;ibin++){
+    NTPCITS[ibin]=hPtTPCITS->Integral(hPtTPCITS->FindBin(Lowbin[ibin]),hPtTPCITS->FindBin(Upbin[ibin]))/noEvents;
+    NITSsa[ibin]=hPtITSsa->Integral(hPtITSsa->FindBin(Lowbin[ibin]),hPtITSsa->FindBin(Upbin[ibin]))/noEvents;
+    NITSpureSA[ibin]=hPtITSpureSA->Integral(hPtITSpureSA->FindBin(Lowbin[ibin]),hPtITSpureSA->FindBin(Upbin[ibin]))/noEvents;
+    //    if(NTPCITS[ibin]!=0 && NITSsa[ibin]!=0)Ratio[ibin]=NTPCITS[ibin]/NITSsa[ibin];
+    Double_t totaltrks=NTPCITS[ibin]+NITSsa[ibin];
+  if(totaltrks!=0 && NITSpureSA[ibin]!=0 )Ratio[ibin]=totaltrks/NITSpureSA[ibin];
+    else Ratio[ibin]=0;
+  }
+  Int_t index=0;
+  xnt[index++]=(Float_t)nrun;
+  xnt[index++]=NTPCITS[0];
+  xnt[index++]=NTPCITS[1];
+  xnt[index++]=NTPCITS[2];
+  xnt[index++]=NITSsa[0];
+  xnt[index++]=NITSsa[1];
+  xnt[index++]=NITSsa[2];
+  xnt[index++]=NITSpureSA[0];
+  xnt[index++]=NITSpureSA[1];
+  xnt[index++]=NITSpureSA[2];
+  xnt[index++]=Ratio[0];
+  xnt[index++]=Ratio[1];
+  xnt[index++]=Ratio[2];
+  nt->Fill(xnt);
+}
+
+
+Double_t LangausFun(Double_t *x, Double_t *par) {
+  
+  //Fit parameters:
+  //par[0]=Width (scale) parameter of Landau density
+  //par[1]=Most Probable (MP, location) parameter of Landau density
+  //par[2]=Total area (integral -inf to inf, normalization constant)
+  //par[3]=Width (sigma) of convoluted Gaussian function
+  //
+  //In the Landau distribution (represented by the CERNLIB approximation), 
+  //the maximum is located at x=-0.22278298 with the location parameter=0.
+  //This shift is corrected within this function, so that the actual
+  //maximum is identical to the MP parameter.
+  
+  // Numeric constants
+  Double_t invsq2pi = 0.3989422804014;   // (2 pi)^(-1/2)
+  Double_t mpshift  = -0.22278298;       // Landau maximum location
+  
+  // Control constants
+  Double_t np = 100.0;      // number of convolution steps
+  Double_t sc =   5.0;      // convolution extends to +-sc Gaussian sigmas
+  
+  // Variables
+  Double_t xx;
+  Double_t mpc;
+  Double_t fland;
+  Double_t sum = 0.0;
+  Double_t xlow,xupp;
+  Double_t step;
+  Double_t i;
+  
+  
+  // MP shift correction
+  mpc = par[1] - mpshift * par[0]; 
+  
+  // Range of convolution integral
+  xlow = x[0] - sc * par[3];
+  xupp = x[0] + sc * par[3];
+  
+  step = (xupp-xlow) / np;
+  
+  // Convolution integral of Landau and Gaussian by sum
+  for(i=1.0; i<=np/2; i++) {
+    xx = xlow + (i-.5) * step;
+    fland = TMath::Landau(xx,mpc,par[0]) / par[0];
+    sum += fland * TMath::Gaus(x[0],xx,par[3]);
+    
+    xx = xupp - (i-.5) * step;
+    fland = TMath::Landau(xx,mpc,par[0]) / par[0];
+    sum += fland * TMath::Gaus(x[0],xx,par[3]);
+  }
+  
+  return (par[2] * step * sum * invsq2pi / par[3]);
+}
+
+Bool_t WriteInputTextFileFromMonalisaListOfRuns(TString outtxtfilename,Int_t* listofrunsfromMonalisa,Int_t nruns,TString pathbeforRunN,TString pathafterRunN){
+
+  // e.g. Int_t listofrunsfromMonalisa[3]={1111,2222,3333,4444}. Copy&paste the list of run given in Monalisa! http://alimonitor.cern.ch/raw/raw_details.jsp?timesel=0&filter_jobtype=LHC+period+LHC12c+-+CPass1+%28reconstruction%29#
+
+  ofstream outfile;
+  outfile.open(outtxtfilename.Data());
+  cout<<"Writing..."<<endl;
+  for(Int_t i=0;i<nruns;i++){
+    outfile<<pathbeforRunN.Data()<<"000"<<listofrunsfromMonalisa[i]<<"/"<<pathafterRunN.Data()<<endl;
+    cout<<pathbeforRunN.Data()<<"000"<<listofrunsfromMonalisa[i]<<"/"<<pathafterRunN.Data()<<endl;
+  }
+
+  cout<<"Done"<<endl;
+  outfile.close();
+  return kTRUE;
+}
+