]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/FORWARD/analysis2/qa/QAPlotter.C
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / qa / QAPlotter.C
index 1e74780dbdd245d982d9a1921adeae1f0ccd4f27..5cbaa5262cadac83ad687074bce373a78315961b 100644 (file)
@@ -52,10 +52,11 @@ struct QAPlotter : public QABase
     /** 
      * Constuctor
      * 
-     * @param d Detector 
-     * @param r Ring 
+     * @param d      Detector 
+     * @param r      Ring 
+     * @param useVar Use variance for errors (not min/max)
      */
-    Ring(UShort_t d, Char_t r)
+    Ring(UShort_t d, Char_t r, Bool_t useVar=false)
       : QARing(d, r),
         fGChi2(0),
         fGC(0),
@@ -66,7 +67,8 @@ struct QAPlotter : public QABase
         fGSingles(0),
         fGLoss(0),
         fGBeta(0),
-        fGOccupancy(0)
+        fGOccupancy(0),
+       fUseVar(useVar)
     {
       fGChi2           = new TGraphAsymmErrors;
       fGC              = new TGraphAsymmErrors;
@@ -143,6 +145,11 @@ struct QAPlotter : public QABase
       Double_t y  = q.mean;
       Double_t el = y-q.min;
       Double_t eh = q.max-y;
+      if (fUseVar) { 
+       //Info("UpdateGraph", "Setting errors on %s to variance",g->GetName());
+       el = q.var; 
+       eh = q.var; 
+      }
       if (TMath::Abs(y) < 1e-6) return;
       Int_t    i  = g->GetN();
       g->SetPoint(i, runNo, y);
@@ -185,20 +192,58 @@ struct QAPlotter : public QABase
     TGraph*            fGLoss;     // Graph of 'lost' data 
     TGraph*            fGBeta;     // Graph of Poisson vs ELoss correlation
     TGraphAsymmErrors* fGOccupancy;// Graph of mean occupancy              
+    Bool_t             fUseVar;    // Use variance 
   };
+  // =================================================================
+  /** 
+   * Compatiblity constructor 
+   * 
+   * @param prodYear    Year
+   * @param prodLetter  Letter
+   * @param useVar      Use variance 
+   */
+  QAPlotter(Long_t prodYear, Char_t prodLetter, Bool_t useVar) 
+    : QABase("", (prodYear < 2000 ? 2000 : 0) + prodYear, 
+            Form("LHC%02d%c", int(prodYear % 100), prodLetter), "pass0"), 
+      fNAccepted(0),
+      fVz(0), 
+      fUseVar(useVar)
+  {
+    Info("QAPlotter", "Do we use variance? %s", fUseVar ? "yes" : "no");
+    fFMD1i = new Ring(1, 'I', useVar); 
+    fFMD2i = new Ring(2, 'I', useVar); 
+    fFMD2o = new Ring(2, 'O', useVar); 
+    fFMD3i = new Ring(3, 'I', useVar); 
+    fFMD3o = new Ring(3, 'O', useVar); 
+    fNAccepted = new TGraph;
+    fNAccepted->SetName("nAccepted");
+    fNAccepted->SetMarkerStyle(20);
+    fNAccepted->SetLineWidth(2);
+
+    fVz = new TGraphErrors;
+    fVz->SetName("vz");
+    fVz->SetMarkerStyle(20);
+    fVz->SetLineWidth(2);
+  }
   /** 
    * Constructor 
    */
-  QAPlotter(Int_t prodYear=0, Char_t prodLetter='\0') 
-    : QABase(false, prodYear, prodLetter),
+  QAPlotter(const TString& dataType, 
+           Int_t          year, 
+           const TString& period, 
+           const TString& pass, 
+           Bool_t         useVar=true) 
+    : QABase(dataType, year, period, pass),
       fNAccepted(0),
-      fVz(0)
+      fVz(0),
+      fUseVar(useVar)
   {
-    fFMD1i = new Ring(1, 'I'); 
-    fFMD2i = new Ring(2, 'I'); 
-    fFMD2o = new Ring(2, 'O'); 
-    fFMD3i = new Ring(3, 'I'); 
-    fFMD3o = new Ring(3, 'O'); 
+    Info("QAPlotter", "Do we use variance? %s", fUseVar ? "yes" : "no");
+    fFMD1i = new Ring(1, 'I', useVar); 
+    fFMD2i = new Ring(2, 'I', useVar); 
+    fFMD2o = new Ring(2, 'O', useVar); 
+    fFMD3i = new Ring(3, 'I', useVar); 
+    fFMD3o = new Ring(3, 'O', useVar); 
     fNAccepted = new TGraph;
     fNAccepted->SetName("nAccepted");
     fNAccepted->SetMarkerStyle(20);
@@ -218,6 +263,23 @@ struct QAPlotter : public QABase
   {
     fFiles.Add(new TObjString(filename));
   }
+  const char* GetUserInfo(TList* l, const char* name, const char* def) const
+  {
+    if (!l) {
+      Warning("GetUserInfo", "No user information list");
+      return def;
+    }
+    
+    TObject* o = l->FindObject(name);
+    if (!o) {
+      Warning("GetUserInfo", "User information %s not found", name);
+      l->ls();
+      return def;
+    }
+
+    Info("GetUserInfo", "Got user information %s=%s", name, o->GetTitle());
+    return o->GetTitle();
+  }
   /** 
    * Make a tree 
    * 
@@ -228,11 +290,18 @@ struct QAPlotter : public QABase
   Bool_t MakeTree(bool read)
   {
     if (fFiles.GetEntriesFast() <= 0) return QABase::MakeTree(read);
-
+    if (fFiles.GetEntriesFast() == 1 && read) {
+      TFile* file = TFile::Open(fFiles.At(0)->GetName(), "READ");
+      if (file) {
+       fTree       = static_cast<TTree*>(file->Get("T"));
+       return true;
+      }
+    }
     TChain* chain = new TChain("T", "T");
     if (!chain->AddFileInfoList(&fFiles)) return false;
     
     fTree   = chain;
+    
     return true;
   }
 
@@ -247,13 +316,19 @@ struct QAPlotter : public QABase
       Error("Run", "No input tree");
       return;
     }
-      
     fFirst = 0xFFFFFFFF;
     fLast  = 0;
 
     UInt_t nEntries = fTree->GetEntries();
     UInt_t j = 0;
     fRuns.Set(nEntries);
+    Info("Run", "Got %d runs", nEntries);
+    TList* l = fTree->GetUserInfo();
+    fPeriod   = GetUserInfo(l, "period", "?");
+    fPass     = GetUserInfo(l, "pass",   "?");
+    fDataType = GetUserInfo(l, "type",   "?");
+      
+
     for (UInt_t i = 0; i < nEntries; i++) {
       fTree->GetEntry(i);
 
@@ -286,11 +361,11 @@ struct QAPlotter : public QABase
    */
   void Plot()
   {
-    fTeXName = Form("trend_%09d_%09d", fFirst, fLast);
+    // fTeXName = Form("trend_%09d_%09d", fFirst, fLast);
     TString title;
-    if (fYear != 0 && fLetter != '\0'
-      title.Form("QA trends for LHC%d%c runs %d --- %d", 
-                fYear, fLetter, fFirst, fLast);
+    if (!fPeriod.IsNull() && !fPass.IsNull()
+      title.Form("QA trends for %s/%s runs %d --- %d", 
+                fPeriod.Data(), fPass.Data(), fFirst, fLast);
     else
       title.Form("QA trends for runs %d --- %d", fFirst, fLast);
     MakeCanvas(title);
@@ -363,6 +438,11 @@ struct QAPlotter : public QABase
     occ->Write();
     beta->Write();
 
+    std::ofstream doc(".doc");
+    doc << fPeriod << " " << fPass << " ("
+       << fDataType << ")" << std::endl;
+    doc.close();
+
     Close(false); // Do not delete PNGs
   }
   /** 
@@ -496,24 +576,28 @@ struct QAPlotter : public QABase
    * @param h      Frame histogram
    * @param title  Title 
    * @param runs   List of runs, if any
+   * @param areas  Other areas 
    */
   void AddRuns(TH1* h, const char* title, TArrayI* runs=0, 
               TList* areas=0)
   {
     h->GetXaxis()->SetNoExponent();
     // h->GetXaxis()->SetTitleOffset(1);
-    h->SetYTitle(title);
+    TString ytitle(title);
+    if (fUseVar) ytitle.Append(" (errors: variance)");
+    else         ytitle.Append(" (errors: min/max)");
+    h->SetYTitle(ytitle.Data());
     h->SetXTitle("Run #");
-
+    // Info("AddRuns", "%s: %s vs %s", h->GetName(), 
+    //      h->GetXaxis()->GetTitle(), h->GetYaxis()->GetTitle());
+  
     Int_t    r1  = h->GetXaxis()->GetXmin();
     Int_t    r2  = h->GetXaxis()->GetXmax();
     Double_t lx  = 0;
-    Double_t tx  = .045; // (r2 - r1) / 18;
+    Double_t tx  = .025; // (r2 - r1) / 18;
     Double_t wx  = 1 - fCanvas->GetLeftMargin() - fCanvas->GetRightMargin();
     Double_t dy  = .025;
     Double_t y   = fCanvas->GetBottomMargin()+dy;
-    UInt_t   cw  = fCanvas->GetWw();  // In pixels
-    UInt_t   ch  = fCanvas->GetWh(); // In pixels
     for (Int_t i = 0; i < fRuns.GetSize(); i++) {
       Int_t    r = fRuns[i];
       Double_t x = fCanvas->GetLeftMargin() + wx*Double_t(r-r1)/(r2-r1);
@@ -564,7 +648,7 @@ struct QAPlotter : public QABase
       TObjString* area = new TObjString;
       TString&    spec = area->String();
       spec.Form("<span style=\"left: %d%%; bottom: %d%%;\" "
-               "onClick='window.location=\"qa_%09d.html\"' "
+               "onClick='window.location=\"%09d/index.html\"' "
                "onMouseOver='this.style.cursor=\"pointer\"' "
                "alt=\"%d\""
                ">%d</span>",
@@ -589,7 +673,7 @@ struct QAPlotter : public QABase
       << "<div class='runs'>\n"
       << "  Runs:<br> ";
     for (Int_t i = 0; i < fRuns.GetSize(); i++) {
-      o << "<a href='qa_" << Form("%09d", fRuns[i]) << ".html'>"
+      o << "<a href='" << Form("%09d", fRuns[i]) << "/index.html'>"
        << fRuns[i] << "</a> " << std::flush;
     }
     o << "\n"
@@ -621,6 +705,7 @@ struct QAPlotter : public QABase
   UInt_t        fLast;      // Last run
   TArrayI       fRuns;      // Seen runs 
   TObjArray     fFiles;
+  Bool_t        fUseVar;    // Use variance rather than min/max 
 };
  
 //