]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
files for central QA
authoralla <Alla.Maevskaya@cern.ch>
Sat, 8 Mar 2014 17:03:49 +0000 (21:03 +0400)
committeralla <Alla.Maevskaya@cern.ch>
Sat, 8 Mar 2014 17:07:40 +0000 (21:07 +0400)
PWGPP/QA/detectorQAscripts/T0.sh [new file with mode: 0755]
T0/MakeTrendT0.C [new file with mode: 0644]
T0/drawPerformanceT0QATrends.C [new file with mode: 0644]

diff --git a/PWGPP/QA/detectorQAscripts/T0.sh b/PWGPP/QA/detectorQAscripts/T0.sh
new file mode 100755 (executable)
index 0000000..c78d16e
--- /dev/null
@@ -0,0 +1,22 @@
+#available variables:
+#  $dataType     e.g. data or sim
+#  $year         e.g. 2011
+#  $period       e.g. LHC13g
+#  $runNumber     e.g. 169123
+#  $pass         e.g. cpass1,pass1,passMC
+
+runLevelQA()
+{
+  qaFile=$1
+
+  cp $ALICE_ROOT/T0/MakeTrendT0.C .
+  aliroot -b -q -l "MakeTrendT0.C(\"$qaFile\",${runNumber})" 
+}
+
+periodLevelQA()
+{
+  trendingFile=$1
+
+  cp $ALICE_ROOT/T0/drawPerformanceT0QATrends.C .
+  aliroot -b -q -l "drawPerformanceT0QATrends.C(\"$trendingFile\")"
+}
diff --git a/T0/MakeTrendT0.C b/T0/MakeTrendT0.C
new file mode 100644 (file)
index 0000000..8ac95ab
--- /dev/null
@@ -0,0 +1,263 @@
+#include "TChain.h"
+#include "TTree.h"
+#include "TH1F.h"
+#include "TF1.h"
+#include "TH2F.h"
+#include "TCanvas.h"
+#include "TObjArray.h"
+#include "/home/alla/alice/AliRoot/AliRoot/STEER/STEERBase/TTreeStream.h"
+
+#define NPMTs 24
+
+int MakeTrendT0( char *infile, int run) {
+
+  char *outfile = "trending.root";
+  if(!infile) return -1;
+  if(!outfile) return -1;
+
+  TFile *f = TFile::Open(infile,"read");
+  if (!f) {
+    printf("File %s not available\n", infile);
+    return -1;
+  }
+
+  //            LOAD HISTOGRAMS FROM QAresults.root   
+  TObjArray   *fTzeroObject = (TObjArray*) f->Get("T0_Performance/QAT0chists"); 
+
+  TH1F* fTzeroORAplusORC =(TH1F*) ((TH1F*) fTzeroObject->FindObject("fTzeroORAplusORC"))->Clone("A"); 
+  TH1F* fResolution      =(TH1F*) ((TH1F*) fTzeroObject->FindObject("fResolution"))->Clone("B");
+  TH1F* fTzeroORA        =(TH1F*) ((TH1F*) fTzeroObject->FindObject("fTzeroORA"))->Clone("C");
+  TH1F* fTzeroORC        =(TH1F*) ((TH1F*) fTzeroObject->FindObject("fTzeroORC"))->Clone("D");
+
+  TH2F *fTimeVSAmplitude[NPMTs];//counting PMTs from 0
+  TH1D *fAmplitude[NPMTs];
+  TH1D *fTime[NPMTs];
+  //-----> add new histogram here  
+
+
+
+  // sigma fit of resolution, mean T0A, T0C and T0C&A,  mean amplitude for each PMT
+  double resolutionSigma = -9999; //dummy init
+  double tzeroOrAPlusOrC = -9999; //dummy init
+  double tzeroOrA        = -9999; //dummy init
+  double tzeroOrC        = -9999; //dummy init
+  double meanAmplitude[NPMTs]; //dummy init
+  double meanTime[NPMTs]; //dummy init
+  double timeDelayOCDB[NPMTs]; //dummy init
+  //.................................................................................
+
+  for(int ipmt=1; ipmt<=NPMTs; ipmt++){ //loop over all PMTs
+    fTimeVSAmplitude[ipmt-1] =(TH2F*) ((TH2F*) fTzeroObject->FindObject(Form("fTimeVSAmplitude%d",ipmt)))->Clone(Form("E%d",ipmt));
+    int nbinsX = fTimeVSAmplitude[ipmt-1]->GetNbinsX();
+    int nbinsY = fTimeVSAmplitude[ipmt-1]->GetNbinsY();
+    //Amplitude
+    fAmplitude[ipmt-1] = (TH1D*) fTimeVSAmplitude[ipmt-1]->ProjectionX(Form("fAmplitude%d",ipmt), 1, nbinsY); 
+    meanAmplitude[ipmt-1] = -9999; //dummy init 
+    if(fAmplitude[ipmt-1]->GetEntries()>0){
+      meanAmplitude[ipmt-1] = fAmplitude[ipmt-1]->GetMean();
+    }
+
+    //Time
+    fTime[ipmt-1] = (TH1D*) fTimeVSAmplitude[ipmt-1]->ProjectionY(Form("fTime%d",ipmt), 1, nbinsX); 
+    meanTime[ipmt-1] = -9999; //dummy init 
+    if(fTime[ipmt-1]->GetEntries()>0){
+      if(fTime[ipmt-1]->GetEntries()>20){
+        meanTime[ipmt-1] = GetParameterGaus((TH1F*) fTime[ipmt-1], 1); // Mean Time
+      }else if(fTime[ipmt-1]->GetEntries()>0){
+        meanTime[ipmt-1] = fTime[ipmt-1]->GetMean();
+      } 
+    }
+  }
+
+
+
+  if(fResolution->GetEntries()>20){
+    resolutionSigma = GetParameterGaus(fResolution, 2); //gaussian sigma 
+  }else if(fResolution->GetEntries()>0){
+    resolutionSigma = fResolution->GetRMS(); //gaussian sigma 
+  }
+
+  if(fTzeroORAplusORC->GetEntries()>20){
+    tzeroOrAPlusOrC = GetParameterGaus(fTzeroORAplusORC, 1); //gaussian mean 
+  }else if(fTzeroORAplusORC->GetEntries()>0){
+    tzeroOrAPlusOrC = fTzeroORAplusORC->GetMean();
+  }
+
+  if(fTzeroORA->GetEntries()>20){ 
+    tzeroOrA = GetParameterGaus(fTzeroORA, 1); //gaussian mean
+  }else if(fTzeroORA->GetEntries()>0){
+    tzeroOrA = fTzeroORA->GetMean();
+  }
+
+  if(fTzeroORC->GetEntries()>20){
+    tzeroOrC = GetParameterGaus(fTzeroORC, 1); //gaussian mean 
+  }else if(fTzeroORC->GetEntries()>0){
+    tzeroOrC = fTzeroORC->GetMean(); //gaussian mean 
+  }
+
+  //-----> analyze the new histogram here and set mean/sigma
+
+
+  f->Close();
+
+  //-------------------- READ OCDB TIME DELAYS ---------------------------
+  // Arguments:
+  AliCDBManager* man = AliCDBManager::Instance();
+  man->SetDefaultStorage("raw://");
+  man->SetRun(run);
+  AliCDBEntry *entry = AliCDBManager::Instance()->Get("T0/Calib/TimeDelay");
+  AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entry->GetObject(); 
+  for (Int_t i=0; i<NPMTs; i++){
+    timeDelayOCDB[i] = 0;
+    if(clb)
+      timeDelayOCDB[i] = clb->GetCFDvalue(i,0);
+  }
+
+
+  //--------------- write walues to the output ------------ 
+  TTreeSRedirector* pcstream = NULL;
+  pcstream = new TTreeSRedirector(outfile);
+  if (!pcstream) return;
+
+
+  TFile *x =  pcstream->GetFile();
+  x->cd();
+
+  TObjString runType;
+  Int_t startTimeGRP=0;
+  Int_t stopTimeGRP=0;
+  Int_t time=0;
+  Int_t duration=0;
+
+  time     = (startTimeGRP+stopTimeGRP)/2;
+  duration = (stopTimeGRP-startTimeGRP);
+
+  (*pcstream)<<"t0QA"<<
+                  "run="<<run;//<<
+                 //"time="<<time<<
+            // "startTimeGRP="<<startTimeGRP<<
+            //  "stopTimeGRP="<<stopTimeGRP<<
+              ///    "duration="<<duration<<
+               //   "runType.="<<&runType;
+               
+
+ (*pcstream)<<"t0QA"<<
+             "resolution="<< resolutionSigma<<
+             "tzeroOrAPlusOrC="<< tzeroOrAPlusOrC<<
+             "tzeroOrA="<< tzeroOrA<<
+             "tzeroOrC="<< tzeroOrC<<
+             "amplPMT1="<<meanAmplitude[0]<<
+             "amplPMT2="<<meanAmplitude[1]<<
+             "amplPMT3="<<meanAmplitude[2]<<
+             "amplPMT4="<<meanAmplitude[3]<<
+             "amplPMT5="<<meanAmplitude[4]<<
+             "amplPMT6="<<meanAmplitude[5]<<
+             "amplPMT7="<<meanAmplitude[6]<<
+             "amplPMT8="<<meanAmplitude[7]<<
+             "amplPMT9="<<meanAmplitude[8]<<
+             "amplPMT10="<<meanAmplitude[9]<<
+             "amplPMT11="<<meanAmplitude[10]<<
+             "amplPMT12="<<meanAmplitude[11]<<
+             "amplPMT13="<<meanAmplitude[12]<<
+             "amplPMT14="<<meanAmplitude[13]<<
+             "amplPMT15="<<meanAmplitude[14]<<
+             "amplPMT16="<<meanAmplitude[15]<<
+             "amplPMT17="<<meanAmplitude[16]<<
+             "amplPMT18="<<meanAmplitude[17]<<
+             "amplPMT19="<<meanAmplitude[18]<<
+             "amplPMT20="<<meanAmplitude[19]<<
+             "amplPMT21="<<meanAmplitude[20]<<
+             "amplPMT22="<<meanAmplitude[21]<<
+             "amplPMT23="<<meanAmplitude[22]<<
+             "amplPMT24="<<meanAmplitude[23]<<
+             "timePMT1="<<meanTime[0]<<
+             "timePMT2="<<meanTime[1]<<
+             "timePMT3="<<meanTime[2]<<
+             "timePMT4="<<meanTime[3]<<
+             "timePMT5="<<meanTime[4]<<
+             "timePMT6="<<meanTime[5]<<
+             "timePMT7="<<meanTime[6]<<
+             "timePMT8="<<meanTime[7]<<
+             "timePMT9="<<meanTime[8]<<
+             "timePMT10="<<meanTime[9]<<
+             "timePMT11="<<meanTime[10]<<
+             "timePMT12="<<meanTime[11]<<
+             "timePMT13="<<meanTime[12]<<
+             "timePMT14="<<meanTime[13]<<
+             "timePMT15="<<meanTime[14]<<
+             "timePMT16="<<meanTime[15]<<
+             "timePMT17="<<meanTime[16]<<
+             "timePMT18="<<meanTime[17]<<
+             "timePMT19="<<meanTime[18]<<
+             "timePMT20="<<meanTime[19]<<
+             "timePMT21="<<meanTime[20]<<
+             "timePMT22="<<meanTime[21]<<
+             "timePMT23="<<meanTime[22]<<
+             "timePMT24="<<meanTime[23];
+(*pcstream)<<"t0QA"<<
+             "timeDelayPMT1="<<timeDelayOCDB[0]<<
+             "timeDelayPMT2="<<timeDelayOCDB[1]<<
+             "timeDelayPMT3="<<timeDelayOCDB[2]<<
+             "timeDelayPMT4="<<timeDelayOCDB[3]<<
+             "timeDelayPMT5="<<timeDelayOCDB[4]<<
+             "timeDelayPMT6="<<timeDelayOCDB[5]<<
+             "timeDelayPMT7="<<timeDelayOCDB[6]<<
+             "timeDelayPMT8="<<timeDelayOCDB[7]<<
+             "timeDelayPMT9="<<timeDelayOCDB[8]<<
+             "timeDelayPMT10="<<timeDelayOCDB[9]<<
+             "timeDelayPMT11="<<timeDelayOCDB[10]<<
+             "timeDelayPMT12="<<timeDelayOCDB[11]<<
+             "timeDelayPMT13="<<timeDelayOCDB[12]<<
+             "timeDelayPMT14="<<timeDelayOCDB[13]<<
+             "timeDelayPMT15="<<timeDelayOCDB[14]<<
+             "timeDelayPMT16="<<timeDelayOCDB[15]<<
+             "timeDelayPMT17="<<timeDelayOCDB[16]<<
+             "timeDelayPMT18="<<timeDelayOCDB[17]<<
+             "timeDelayPMT19="<<timeDelayOCDB[18]<<
+             "timeDelayPMT20="<<timeDelayOCDB[19]<<
+             "timeDelayPMT21="<<timeDelayOCDB[20]<<
+             "timeDelayPMT22="<<timeDelayOCDB[21]<<
+             "timeDelayPMT23="<<timeDelayOCDB[22]<<
+             "timeDelayPMT24="<<timeDelayOCDB[23];
+
+            //-----> add the mean/sigma of the new histogram here      
+ (*pcstream)<<"t0QA"<<"\n";
+  
+  pcstream->Close(); 
+  delete pcstream; 
+
+  return;
+
+}
+
+//_____________________________________________________________________________
+double GetParameterGaus(TH1F *histo, int whichParameter){
+
+   int    maxBin   =  histo->GetMaximumBin(); 
+   double max      =  (histo->GetBinContent(maxBin-1) + histo->GetBinContent(maxBin) + histo->GetBinContent(maxBin+1))/3;
+   double mean     =  histo->GetBinCenter(maxBin); //mean
+   double lowfwhm  =  histo->GetBinCenter(histo->FindFirstBinAbove(max/2));
+   double highfwhm =  histo->GetBinCenter(histo->FindLastBinAbove(max/2));
+   double sigma    = (highfwhm - lowfwhm)/2.35482; //estimate fwhm  FWHM = 2.35482*sigma
+
+   TF1 *gaussfit   = new TF1("gaussfit","gaus", mean - 4*sigma, mean + 4*sigma); // fit in +- 4 sigma window
+   gaussfit->SetParameters(max, mean, sigma); 
+
+   if(whichParameter==2)
+     histo->Fit(gaussfit,"RQNI");
+   else
+     histo->Fit(gaussfit,"RQN");
+
+   double parValue = gaussfit->GetParameter(whichParameter); 
+
+   delete gaussfit; 
+   return parValue;
+}
+
+
diff --git a/T0/drawPerformanceT0QATrends.C b/T0/drawPerformanceT0QATrends.C
new file mode 100644 (file)
index 0000000..b3f9ef4
--- /dev/null
@@ -0,0 +1,302 @@
+
+TGraphErrors * MakeGraphSparse(TTree * tree, const Char_t * expr="mean-fdelta:run", const Char_t * cut="isTPC&&ptype==0&&theta>0"){
+  // Format of expr: Var:Error:Run
+  //
+  // Make a sparse draw of the variables
+  //  Format of expr : Var:Error:Run
+  //
+
+  const Int_t entries =  tree->Draw(expr,cut,"goff");
+  
+  Double_t *graphX, *graphY, *graphError;
+
+  //check whether error argument exists in expr
+  if(!tree->GetV3()){
+      graphX = tree->GetV2();
+      graphY = tree->GetV1();
+  }
+  else{
+      graphX = tree->GetV3();
+      graphY = tree->GetV1();
+      graphError = tree->GetV2();
+  }
+
+  // sort according to run number
+  Int_t *index = new Int_t[entries];
+  TMath::Sort(entries,graphX,index,false);
+
+  // define arrays for the new graph
+  Double_t *tempArray = new Double_t[entries];
+  Double_t *xError = new Double_t[entries];
+  Double_t *yError = new Double_t[entries];
+  Int_t *vrun = new Int_t[entries]; 
+  Double_t count = 0.5;
+
+  // evaluate arrays for the new graph accroding to the run-number
+  Int_t icount=0;
+  tempArray[index[0]] = count;
+  xError[0] = 0;
+  yError[0] = 0;
+  if(tree->GetV3())
+      yError[index[0]] = graphError[index[0]];
+  vrun[0] = graphX[index[0]];
+
+  // loop the rest entries
+  for(Int_t i=1;i<entries;i++){
+      xError[i] = 0;
+      yError[i] = 0;
+
+      if(tree->GetV3())
+         yError[i] = graphError[index[i]];
+
+
+      if(graphX[index[i]]==graphX[index[i-1]])
+         tempArray[index[i]] = count; 
+      else if((graphX[index[i]]!=graphX[index[i-1]])){
+             count++;
+             icount++;
+             tempArray[index[i]] = count;
+             vrun[icount]=graphX[index[i]];
+      }
+  }
+
+  // count the number of xbins (run-wise) for the new graph
+  const Int_t newNbins = int(count+0.5);
+  Double_t *newBins = new Double_t[newNbins+1];
+  for(Int_t i=0; i<=count+1;i++){
+    newBins[i] = i;
+  }
+  
+  // define and fill the new graph
+  TGraphErrors *graphNew = new TGraphErrors(entries,tempArray,graphY,xError,yError);
+  graphNew->GetXaxis()->Set(newNbins,newBins);
+  
+  // set the bins for the x-axis
+  Char_t xName[50];
+  for(Int_t i=0;i<count;i++){
+    sprintf(xName,"%d",Int_t(vrun[i]));
+    graphNew->GetXaxis()->SetBinLabel(i+1,xName);
+  }
+  graphNew->GetHistogram()->SetTitle("");
+  
+  // memory clearing
+  delete [] xError; 
+  delete [] yError; 
+  delete [] tempArray;
+  delete [] index;
+  delete [] newBins;
+  delete [] vrun;
+  return graphNew;
+
+}
+//------------------------------------------------------------------------------------------------
+drawPerformanceT0QATrends(const char* inFile = "trending.root", const char* runType="pp") {
+  //
+  //
+  gROOT->Reset();
+  gROOT->SetStyle("Plain");
+  gStyle->SetPalette(1);
+  gStyle->SetLabelSize(0.04,"x");
+
+  // open input file
+  //
+  TFile *file = TFile::Open(inFile);
+  if(!file) return;
+  file->cd();
+  
+  TTree *tree = (TTree*)file->Get("t0QA");
+  if(!tree) return;
+  int const entries = tree->GetEntries();
+  cout<<"number of entries   "<<entries<<endl; 
+  TH1F *frame = new TH1F();
+
+  //const float norm_runs = 8.0; 
+  if(entries<8)
+    const float norm_runs =10.0;
+  else if(entries>=8&&entries<16)
+    const float norm_runs =20.0;
+ else
+   const float norm_runs =50.0;
+  int const canvas_width = int(((entries*1.0)/norm_runs)*2000.0);
+  if(entries>50){
+    gStyle->SetTickLength(0.03*norm_runs/(entries*1.0),"Y");
+    gStyle->SetTitleYOffset((norm_runs/(entries*1.0))*0.8);
+    gStyle->SetPadLeftMargin(0.1*norm_runs/(entries*1.0));
+    gStyle->SetPadRightMargin(0.1*norm_runs/(entries*1.0));
+  }
+
+  //Define ranges of you trending plots
+  double resolutionMin = 10,   resolutionMax = 50;    // OR A - OR C
+  double oraplusorcMin = -100, oraplusorcMax = 100;   // OR A + OR CA
+  double oraMin        = -100, oraMax        = 100;   // OR A  
+  double orcMin        = -100, orcMax        = 100;   // OR C
+  double amplMin       =0,    amplMax    =3   ;     // amplitude in each PMT
+  double timeMin       ,   timeMax       ;     // amplitude in each PMT
+  //-----> add ranges of your new trending plot
+
+
+  TCanvas *c1  = new  TCanvas("can","can",canvas_width,500);
+  c1->SetGridy(1);
+  c1->SetGridx(1);
+  c1->SetBottomMargin(0.17);
+  
+  /****** T0 ORA+ORC ******/
+  TGraphErrors *grSum = MakeGraphSparse(tree,"tzeroOrAPlusOrC:run","");
+  grSum->SetMarkerStyle(20);
+  grSum->SetMarkerSize(1.0);
+  grSum->SetMarkerColor(2);
+  TGraphErrors *grORA = MakeGraphSparse(tree,"tzeroOrA:run","");
+  grORA->SetMarkerStyle(28);
+  grORA->SetMarkerSize(1.0);
+  grORA->SetMarkerColor(4);
+  TGraphErrors *grORC = MakeGraphSparse(tree,"tzeroOrC:run","");
+  grORC->SetMarkerStyle(25);
+  grORC->SetMarkerSize(1.0);
+  grORC->SetMarkerColor(1);
+  grSum->GetHistogram()->SetYTitle("mean [ps]");
+  grSum->GetHistogram()->SetTitle("T0 ORA, ORC and (ORA+ORC)/2");
+  grSum->GetHistogram()->SetMinimum(oraplusorcMin);
+  grSum->GetHistogram()->SetMaximum(oraplusorcMax);
+  grSum->Draw("AP");
+  grORA->Draw("psame");
+  grORC->Draw("psame");
+  TLegend *leg = new TLegend(0.1,0.85,0.3,0.95," ","brNDC");
+  leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextSize(0.05);leg->SetNColumns(3);leg->SetColumnSeparation(1);
+  leg->AddEntry(grORA,"ORA","p"); 
+  leg->AddEntry(grORC,"ORC","p"); 
+  leg->AddEntry(grSum,"(ORA+ORC)/2","p"); 
+  leg->Draw(); 
+  grSum->GetXaxis()->LabelsOption("v");
+  c1->SaveAs("meanT0OrAPlusOrC_vs_run.gif");
+  /****** T0 Resolution ******/
+  TGraphErrors *gr = MakeGraphSparse(tree,"resolution:run","");
+  gr->SetMarkerStyle(20);
+  gr->SetMarkerSize(1.0);
+  gr->SetMarkerColor(2);
+  gr->GetHistogram()->SetMinimum(resolutionMin);
+  gr->GetHistogram()->SetMaximum(resolutionMax);
+  gr->Draw("AP");
+  gr->GetXaxis()->LabelsOption("v");
+  gr->GetHistogram()->SetYTitle("sigma [ps]");
+  gr->GetHistogram()->SetTitle("T0 resolution (ORA -ORC)/2");
+  c1->SaveAs("sigmaResolutionT0_vs_run.gif");
+
+   /****** Mean T0 OR A ******/
+ /* TGraphErrors *gr = MakeGraphSparse(tree,"tzeroOrA:run","");
+  gr->SetMarkerStyle(20);
+  gr->SetMarkerSize(1.0);
+  gr->SetMarkerColor(2);
+  gr->GetHistogram()->SetYTitle("mean [ps]");
+  gr->GetHistogram()->SetTitle("T0 OR A");
+  gr->GetHistogram()->SetMinimum(oraMin);
+  gr->GetHistogram()->SetMaximum(oraMax);
+  gr->Draw("AP");
+  gr->GetXaxis()->LabelsOption("v");
+  c1->SaveAs("meanT0OrA_vs_run.gif");
+*/
+
+  /****** Mean T0 OR C ******/
+ /* TGraphErrors *gr = MakeGraphSparse(tree,"tzeroOrC:run","");
+  gr->SetMarkerStyle(20);
+  gr->SetMarkerSize(1.0);
+  gr->SetMarkerColor(2);
+  gr->GetHistogram()->SetYTitle("mean [ps]");
+  gr->GetHistogram()->SetTitle("T0 OR C");
+  gr->GetHistogram()->SetMinimum(orcMin);
+  gr->GetHistogram()->SetMaximum(orcMax);
+  gr->Draw("AP");
+  gr->GetXaxis()->LabelsOption("v");
+  c1->SaveAs("meanT0OrC_vs_run.gif");
+*/
+
+  /****** Mean Amplitude in PMT ******/
+  const int kNPMTs = 24;
+  char name[200];
+
+  for(int ipmt=1;ipmt<=kNPMTs; ipmt++){
+    sprintf(name,"amplPMT%d:run",ipmt);
+    gr = MakeGraphSparse(tree,name,"");
+    gr->SetMarkerStyle(20);
+    gr->SetMarkerSize(1.0);
+    gr->SetMarkerColor(6);
+    gr->GetHistogram()->SetYTitle("mean");
+    gr->GetHistogram()->SetTitle(Form("Amplitude PMT%d",ipmt));
+
+    int nRuns = gr->GetN();
+    double *y =  gr->GetY();
+       double min = y[0];
+       double max = y[0];
+    for(int irun =1; irun<nRuns;irun++){
+      if(min > y[irun] & y[irun]>0) min = y[irun];
+      if(max < y[irun]) max = y[irun];
+    }
+    //  amplMin = min - 2; 
+    //  amplMax = max + 2; 
+
+    gr->GetHistogram()->SetMinimum(amplMin);
+    gr->GetHistogram()->SetMaximum(amplMax);
+    gr->Draw("AP");
+    gr->GetXaxis()->LabelsOption("v");
+    c1->SaveAs(Form("meanAmplPMT%d_vs_run.gif",ipmt));
+  }
+  /****** Mean Time in PMT ******/
+  for(int ipmt=1;ipmt<=kNPMTs; ipmt++){
+    sprintf(name,"timePMT%d:run",ipmt);
+    gr = MakeGraphSparse(tree,name,"");
+
+
+    sprintf(name,"timeDelayPMT%d:run",ipmt);
+    TGraphErrors *grDelay = MakeGraphSparse(tree,name,"");
+    //regular run
+    int nRuns = gr->GetN();
+    double *y =  gr->GetY();
+       double min = y[0];
+       double max = y[0];
+    for(int irun =1; irun<nRuns;irun++){
+      if(min > y[irun] && y[irun]>0) min = y[irun];
+      if(max < y[irun]) max = y[irun];
+    }
+    //Delay
+    //   double *yDelay =  grDelay->GetY();
+    //  nRuns = grDelay->GetN();
+    //   for(int irun =0; irun<nRuns;irun++){
+    //      if(min > yDelay[irun] && yDelay[irun]>0) min = yDelay[irun];
+    //    if(max < yDelay[irun]) max = yDelay[irun];
+    //  }
+    
+    timeMin = min - 2; 
+    timeMax = max + 2; 
+
+    gr->SetMarkerStyle(20);
+    gr->SetMarkerSize(1.0);
+    gr->SetMarkerColor(2);
+    grDelay->SetMarkerStyle(24);
+    grDelay->SetMarkerSize(1.0);
+    grDelay->SetMarkerColor(1);
+
+    gr->GetHistogram()->SetYTitle("mean [channels]");
+    gr->GetHistogram()->SetTitle(Form("Time PMT%d",ipmt));
+    gr->GetHistogram()->SetMinimum(timeMin);
+    gr->GetHistogram()->SetMaximum(timeMax);
+    gr->GetXaxis()->LabelsOption("v");
+    gr->Draw("AP");
+    grDelay->Draw("Psame");
+
+    TLegend *leg = new TLegend(0.1,0.85,0.3,0.95," ","brNDC");
+    leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextSize(0.05);leg->SetNColumns(3);
+    leg->AddEntry(gr,"mean time","p"); 
+    //leg->AddEntry(grDelay,"Time Delay OCDB","p"); 
+    leg->Draw(); 
+    c1->SaveAs(Form("meanTimePMT%d_vs_run.gif",ipmt));
+  }
+
+
+  //-----> draw your new trending plot here
+}
+