update of QA macros, cleanup and formatting (Hege)
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 2 Nov 2011 10:26:47 +0000 (10:26 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 2 Nov 2011 10:26:47 +0000 (10:26 +0000)
HLT/QA/tasks/macros/drawTHnSparse.C
HLT/QA/tasks/macros/overlayPlots.C

index 8a68f3c..1898b86 100644 (file)
@@ -52,6 +52,7 @@
 #include "TStyle.h"
 #include "TPad.h"
 #include <iostream>
+#include <iomanip>
 #include <cstdlib>
 using std::endl;
 #endif
@@ -67,7 +68,7 @@ void printStats(TH1D *hlt, TH1D *off);
 void defineYaxisMax(TH1D *h1, TH1D *h2);
 void printLegend(TH1D *hlt, TH1D *off);
 void plot2D( THnSparse* h, TText *hText, TString folder, cuts cut );
-void plotEventQuantities(THnSparse* heventHLT, THnSparse* heventOFF, TText* hText, TString folder);
+void plotEventQuantities(THnSparse* heventHLT, THnSparse* heventOFF, TText* hText, TString folder,TString fBeamType);
 TString fix1DTitle(const char* c);
 TString fix2DTitle(const char* c1, const char* c2);
 TString cutsToString( cuts cut );
@@ -76,7 +77,7 @@ void printCuts(cuts cut);
 
 //------------------------------------------------------------------//         
 
-void drawTHnSparse(TString inputFile="HLT-OFFLINE-CentralBarrel-comparison.root"){
+void drawTHnSparse(TString beamType="p-p", TString inputFile="HLT-OFFLINE-CentralBarrel-comparison.root"){
  
   gROOT->SetStyle("Plain");
   gStyle->SetPalette(1);
@@ -124,7 +125,7 @@ void drawTHnSparse(TString inputFile="HLT-OFFLINE-CentralBarrel-comparison.root"
   folder.ReplaceAll(",","_");    
   gSystem->Exec("mkdir "+folder); // create a folder whose name contains run number and date of run
   
-  if(heventHLT->GetEntries()>0 || heventOFF->GetEntries()>0) plotEventQuantities(heventHLT,heventOFF,hText,folder);
+  if(heventHLT->GetEntries()>0 || heventOFF->GetEntries()>0) plotEventQuantities(heventHLT,heventOFF,hText,folder,beamType);
   else {
     if(heventHLT->GetEntries()==0) printf("\nThe HLT event THnSparse contains 0 entries\n");
     if(heventOFF->GetEntries()==0) printf("\nThe OFF event THnSparse contains 0 entries\n");
@@ -133,9 +134,9 @@ void drawTHnSparse(TString inputFile="HLT-OFFLINE-CentralBarrel-comparison.root"
   cuts p[] = {                                                                                                                                                                               
          // eta    pt      DCAr     DCAz    TPCclus  ITSclus  vtxStatus  |vtxZ|   V0cent                                                                                                
        {-1, 1,  0,   10, -10, 10, -10, 10,  0, 200,   0, 10,      2,       10,   0, 100},                                                                                                    
-       {-1, 1,  0.3, 10,  -7,  7,  -7,  7,  0, 200,   0, 10,      2,       10,   0, 100},                                                                                                    
-       {-1, 1,  0.6, 10,  -7,  7,  -7,  7,  0, 200,   0, 10,      2,       10,   0, 100},                                                                                                    
-       {-1, 1,  0.9, 10,  -7,  7,  -7,  7,  0, 200,   0, 10,      2,       10,   0, 100}                                                                                                     
+       {-1, 1,  0.30,10,  -7,  7,  -7,  7,  0, 200,   0, 10,      2,       10,   0, 100},                                                                                                    
+       {-1, 1,  0.60,10,  -7,  7,  -7,  7,  0, 200,   0, 10,      2,       10,   0, 100},                                                                                                    
+       {-1, 1,  0.90,10,  -7,  7,  -7,  7,  0, 200,   0, 10,      2,       10,   0, 100}                                                                                                     
   };                                                                                                                                                                                         
   const int nCutSets = sizeof(p)/sizeof(cuts);
  
@@ -246,7 +247,7 @@ void cutStudies( TString folder, THnSparse* htrackHLT, THnSparse* htrackOFF, TTe
   return;
 }
 
-void plotEventQuantities(THnSparse* heventHLT, THnSparse* heventOFF, TText* hText, TString folder){
+void plotEventQuantities(THnSparse* heventHLT, THnSparse* heventOFF, TText* hText, TString folder, TString fBeamType){
 
   TString tmp = "vertex event properties for ";
   tmp += hText->GetTitle();
@@ -285,6 +286,10 @@ void plotEventQuantities(THnSparse* heventHLT, THnSparse* heventOFF, TText* hTex
   can2->Divide(3,2);
   
   can2->cd(1); // track multiplicity
+  if(fBeamType.Contains("p-p")){
+    heventHLT->GetAxis(7)->SetRangeUser(0,1000);
+    heventOFF->GetAxis(7)->SetRangeUser(0,1000);
+  }
   hlt = heventHLT->Projection(7); 
   off = heventOFF->Projection(7); 
   off->SetLineColor(2); 
@@ -296,6 +301,10 @@ void plotEventQuantities(THnSparse* heventHLT, THnSparse* heventOFF, TText* hTex
   if(hlt->GetEntries()>0 && off->GetEntries()>0) printStats(hlt, off);
 
   can2->cd(2); // number of contributors
+  if(fBeamType.Contains("p-p")){
+    heventHLT->GetAxis(6)->SetRangeUser(0,1000);
+    heventOFF->GetAxis(6)->SetRangeUser(0,1000);
+  }
   hlt = heventHLT->Projection(6); 
   off = heventOFF->Projection(6); 
   off->SetLineColor(2); 
@@ -372,7 +381,7 @@ void plotTrackQuantities( THnSparse* htrackHLT, THnSparse* htrackOFF, TText* hTe
   TString tmp = "";
   tmp += "track properties for ";
   tmp+=hText->GetTitle();     
-  TCanvas *can3 = new TCanvas("can3",tmp,1200,800); 
+  TCanvas *can3 = new TCanvas("can3",tmp,1600,1000); 
   can3->Divide(4,2); 
   // the first 9 track related variables filled in the THnSparse
   //  0            1     2    3     4      5      6     7   
@@ -380,60 +389,64 @@ void plotTrackQuantities( THnSparse* htrackHLT, THnSparse* htrackOFF, TText* hTe
   
   TH1D *hlt = NULL; 
   TH1D *off = NULL;
-      
+
+  TLegend *leg = new TLegend(0.25,0.2,0.85,0.85);
+
   for(int i=0; i<8; i++){  
-     hlt = htrackHLT->Projection(i); if(!hlt){ printf("plotTrackQuantities: empty HLT histogram for projection %d\n",i); continue; }
-     off = htrackOFF->Projection(i); if(!off){ printf("plotTrackQuantities: empty OFF histogram for projection %d\n",i); continue; }     
-     hlt->SetTitle(fix1DTitle(htrackHLT->Projection(i)->GetTitle())); 
-     off->SetTitle(fix1DTitle(htrackOFF->Projection(i)->GetTitle())); // is necessary in cases where only offline data is available
+    hlt = htrackHLT->Projection(i); if(!hlt){ printf("plotTrackQuantities: empty HLT histogram for projection %d\n",i); continue; }
+    off = htrackOFF->Projection(i); if(!off){ printf("plotTrackQuantities: empty OFF histogram for projection %d\n",i); continue; }     
+    hlt->SetTitle(fix1DTitle(htrackHLT->Projection(i)->GetTitle())); 
+    off->SetTitle(fix1DTitle(htrackOFF->Projection(i)->GetTitle())); // is necessary in cases where only offline data is available
   
-     TString s = hlt->GetTitle();      
-     if(s.Contains("p_")){ 
-       s+=" (GeV/c)";
-        hlt->SetXTitle(s);     
-     }
-     else if(s.Contains("phi")){
-       s+=" (rad)"; 
-        hlt->SetXTitle(s);
-     }
-     else if(s.Contains("DCA")){
-       s+=" (cm)";
-        hlt->SetXTitle(s);
-     }
+    TString s = hlt->GetTitle();      
+    if(s.Contains("p_")){ 
+      s+=" (GeV/c)";
+      hlt->SetXTitle(s);     
+    }
+    else if(s.Contains("phi")){
+      s+=" (rad)"; 
+      hlt->SetXTitle(s);
+    }
+    else if(s.Contains("DCA")){
+      s+=" (cm)";
+      hlt->SetXTitle(s);
+    }
        
-     if(off->GetEntries()>0) defineYaxisMax(hlt, off);
-     off->SetLineColor(2);
+    if(off->GetEntries()>0) defineYaxisMax(hlt, off);
+    off->SetLineColor(2);
    
-     can3->cd(i+1);
-     if(hlt->GetEntries()>0) hlt->Draw();
-     if(off->GetEntries()>0) off->Draw("sames");
-     if(hlt->GetEntries()>0 && off->GetEntries()>0) printStats(hlt, off);
-     if(off->GetEntries()>0 && i==0 ) printLegend(hlt,off);
+    can3->cd(i+1);
+    if(hlt->GetEntries()>0) hlt->Draw();
+    if(off->GetEntries()>0) off->Draw("sames");
+    if(hlt->GetEntries()>0 && off->GetEntries()>0) printStats(hlt, off);
+    if(off->GetEntries()>0 && i==0 ) printLegend(hlt,off);
      
-     if(hlt->GetEntries()>0 && i==0){
-       TPaveText *pave = new TPaveText(0.7,1356,6.9,9040);
-       pave->SetFillColor(kWhite);
-       pave->SetLineColor(kWhite);
-        pave->SetShadowColor(kWhite);
-        s=""; s+=cut.minEta; s+="<#eta< "; s+=cut.maxEta; pave->AddText(s);
-        s=""; s+=cut.minPt; s+="<p_{T} (GeV/c)<"; s+=cut.maxPt; pave->AddText(s);
-        s=""; s+=cut.minDCAr; s+="<DCAr (cm)<"; s+=cut.maxDCAr; pave->AddText(s);
-        s=""; s+=cut.minDCAz; s+="<DCAz (cm)<"; s+=cut.maxDCAz; pave->AddText(s);
-        s=""; s+=cut.minTPCclus; s+="<TPC cls/tr<"; s+=cut.maxTPCclus; pave->AddText(s);
-        s=""; s+=cut.minITSclus; s+="<ITS cls/tr<"; s+=cut.maxITSclus; pave->AddText(s);
-        s=""; s+="|vertexZ| (cm)<"; s+=TMath::Abs(cut.vertexZ); pave->AddText(s);
-        if(cut.vertexStatus!=2) { s=""; s+="vertex status "; s+=cut.vertexStatus; pave->AddText(s); }
-        if(htrackHLT->GetNdimensions()==11) { s=""; s+=cut.minV0cent; s+=" < V0 centr < "; s+=cut.maxV0cent; pave->AddText(s);}
-       pave->Draw();
-       can3->Update();
-     }      
+    if(hlt->GetEntries()>0 && i==0){
+      leg->SetFillColor(kWhite);
+      leg->SetLineColor(kWhite);
+      leg->SetShadowColor(kWhite);
+      s=""; s+=cut.minEta; s+="<#eta< "; s+=cut.maxEta;leg->AddEntry((TObject*)0, s, "");  
+      s=""; s+=cut.minPt; s.Resize(4); s+="<p_{T} (GeV/c)<"; s+=cut.maxPt;  leg->AddEntry((TObject*)0, s, ""); 
+      s=""; s+=cut.minDCAr; s+="<DCAr (cm)<"; s+=cut.maxDCAr; leg->AddEntry((TObject*)0, s, "");  
+      s=""; s+=cut.minDCAz; s+="<DCAz (cm)<"; s+=cut.maxDCAz; leg->AddEntry((TObject*)0, s, "");  
+      if(cut.minTPCclus!=0 && cut.maxTPCclus!=200){ s=""; s+=cut.minTPCclus; s+="<TPC cls/tr<"; s+=cut.maxTPCclus; leg->AddEntry((TObject*)0, s, "");}
+      if(cut.minITSclus!=0 && cut.maxITSclus!=10){ s=""; s+=cut.minITSclus; s+="<ITS cls/tr<"; s+=cut.maxITSclus; leg->AddEntry((TObject*)0, s, "");}
+      s=""; s+="|vertexZ| (cm)<"; s+=TMath::Abs(cut.vertexZ); leg->AddEntry((TObject*)0, s, ""); 
+      if(cut.vertexStatus!=2) { s=""; s+="vertex status "; s+=cut.vertexStatus; leg->AddEntry((TObject*)0, s, ""); }
+      if(htrackHLT->GetNdimensions()==11) { s=""; s+=cut.minV0cent; s+=" < V0 centr < "; s+=cut.maxV0cent; leg->AddEntry((TObject*)0, s, "");  }
+      
+      leg->Draw();
+      
+      can3->Update();
+       }      
   } 
   TString strcuts = cutsToString(cut);
   
   can3->SaveAs(folder+"/track_properties_"+strcuts+".root");
   can3->SaveAs(folder+"/track_properties_"+strcuts+".png");
-  //delete can3;
-  
+  delete can3;
+  delete leg;
+
   return;
 }
 
@@ -607,8 +620,5 @@ TString fix2DTitle(const char* c1, const char* c2){
 }
 
 void printCuts(cuts cut){
-  printf("\n %2g<eta<%2g, %2g<pt (GeV/c)<%2g, %2g<DCAr (cm)<%2g, %2g<DCAz (cm)<%2g, %d<TPCclus<%d, %d<ITSclus<%d, vertex status %d, |vertexZ| (cm)<%2g, %d<centr (%)<%d \n\n",
-          cut.minEta, cut.maxEta, cut.minPt, cut.maxPt, cut.minDCAr, cut.maxDCAr, cut.minDCAz, cut.maxDCAz, cut.minTPCclus, cut.maxTPCclus, 
-         cut.minITSclus, cut.maxITSclus, cut.vertexStatus, cut.vertexZ, cut.minV0cent, cut.maxV0cent
-       );
+  printf("\n %2g<eta<%2g, %2g<pt (GeV/c)<%2g, %2g<DCAr (cm)<%2g, %2g<DCAz (cm)<%2g, %d<TPCclus<%d, %d<ITSclus<%d, vertex status %d, |vertexZ| (cm)<%2g, %d<centr (%)<%d \n\n",cut.minEta, cut.maxEta, cut.minPt, cut.maxPt, cut.minDCAr, cut.maxDCAr, cut.minDCAz, cut.maxDCAz, cut.minTPCclus, cut.maxTPCclus, cut.minITSclus, cut.maxITSclus, cut.vertexStatus, cut.vertexZ, cut.minV0cent, cut.maxV0cent );
 }
index 9f55624..5d1a9b1 100644 (file)
@@ -6,7 +6,6 @@
 //  It assumes a txt file where the input is specified in 
 //  the following format:
 //  
-//   number of files
 //   file1 legend1
 //   file2 legend2
 //  //file3 legend3
@@ -14,6 +13,9 @@
 //  ...
 //  So it is possible to "comment out" a file by a // in the beginning of the name. While reading the 
 //  the names of the input files, the macro skips the ones that have the // in front of them.
+//
+//  Run it by:
+//  aliroot overlayPlots.C++ 
 // 
 //  @ingroup alihlt_qa
 //  @author Kalliopi.Kanaki@ift.uib.no 
 #include <iostream>
 #include <cstdlib>
 #include <fstream>
+#include <vector>
 using std::endl;
 #endif
 
 void printStats(TH1D *h1, TH1D *h2);
 void defineYaxisMax(TH1D *h1, TH1D *h2);
 
-void overlayPlots(const char* option="HLT"/* or "OFF" */, Bool_t bAddRunName=kTRUE, Bool_t bDrawNormalized=kTRUE, string fi="files.txt"){
+void overlayPlots(TString plottype="track" /*or event*/,const char* option="HLT"/* or "OFF" */,  Bool_t bAddRunName=kTRUE, Bool_t bDrawNormalized=kTRUE, string fi="files.txt"){
 
 
   printf("test\n"); 
@@ -63,119 +66,140 @@ void overlayPlots(const char* option="HLT"/* or "OFF" */, Bool_t bAddRunName=kTR
     return;
   }
   string c;
-  TString f;
+  string f;
   int nr_textfile = 0;
 
-  infile>>nr_textfile;
-  if(!infile.good()) return;
-  printf("Number of files: %d\n", nr_textfile);
-
-  const int nr_files = nr_textfile;
-  TString file[nr_files];
-  string cutnames[nr_files];
+  vector<string> file;
+  vector<string> cutnames;
   string plotname="";
+  string t("//");
 
-  nr_textfile=0;
-  while(nr_textfile < nr_files){
+  while(1){
     infile >> f >> c;
     if(!infile.good()) break;
-    file[nr_textfile] = f;
-    cutnames[nr_textfile] = c; 
-    if(f.BeginsWith("//")) continue;
-    printf("\nfile %d : %s\n", nr_textfile, f.Data());
+    if (f.compare(0, t.length(), t) == 0) continue;
+    file.push_back(f);
+    cutnames.push_back(c);
     nr_textfile++;
   }
   infile.close();
+  cout << cutnames.size()<< endl;
+
+  printf("Number of files: %d\n", nr_textfile);
   
   TCanvas *ca;
   TFile   *ff; 
   TPad    *pad; 
-  TH1D    *g[nr_files];
+  TH1D    *g[nr_textfile];
   
   TCanvas *d = new TCanvas("d",Form("Compare %s distributions",option),1600,1000);
   d->Divide(4,2);
   //d->Divide(3,2);
-  
-  TLegend *l = new TLegend(0.25,0.2,0.89,0.8);
+  TLegend *l;
+  if(plottype.Contains("event"))
+    l = new TLegend(0,0,0.95,0.95);
+  else
+    l = new TLegend(0.35,0.3,0.89,0.8);
   l->SetFillColor(10);
   l->SetLineColor(10);
   
   char cut[100];  
-   
-  //for(int j=1; j<7; j++){ 
-  for(int j=1; j<9; j++){ 
-     for(int i=0; i<nr_files; i++){ 
-            
-        ff = TFile::Open(file[i].Data());   
-        if(!ff || ff->IsZombie()){
-           printf("Non-existent, corrupted or zombie file %s\n", file[i].Data());
-           return;
-        } 
-        //ca  = (TCanvas*)ff->GetObjectUnchecked("can0");                  
-        ca  = (TCanvas*)ff->GetObjectUnchecked("can3");                    
-       if(!ca){
-          printf("Empty canvas in file %s.\n", file[i].Data());
-          continue;
-       }       
-        //pad = (TPad*)ca->GetListOfPrimitives()->FindObject(Form("can0_%d",j));               
-        pad = (TPad*)ca->GetListOfPrimitives()->FindObject(Form("can3_%d",j));                 
-        if(!pad){
-           printf("Empty pad in canvas %s.\n", ca->GetName());
-           continue;        
-        }
-        //g[i] =(TH1D*)pad->FindObject(Form("fEvent%s_proj_%d",option,j-1));
-        g[i] =(TH1D*)pad->FindObject(Form("fTrack%s_proj_%d",option,j-1));
-       if(!g[i]){
-          printf("Empty histogram for i=%d, file %s.\n", i, file[i].Data());
-          continue;
-       }
+
+  int nr_pads=0;
+  if(plottype.Contains("event"))nr_pads=7;
+  else nr_pads=9;
+
+  for(int j=1; j<nr_pads; j++){ 
+    for(int i=0; i<nr_textfile; i++){ 
+       
+      ff = TFile::Open(file[i].data());   
+      if(!ff || ff->IsZombie()){
+       printf("Non-existent, corrupted or zombie file %s\n", file[i].data());
+       return;
+      } 
+      if(plottype.Contains("event"))
+       ca  = (TCanvas*)ff->GetObjectUnchecked("can1");
+      else                 
+       ca  = (TCanvas*)ff->GetObjectUnchecked("can3");             
+      if(!ca){
+       printf("Empty canvas in file %s.\n", file[i].data());
+       continue;
+      }
+      if(plottype.Contains("event"))
+       pad = (TPad*)ca->GetListOfPrimitives()->FindObject(Form("can1_%d",j));          
+      else
+       pad = (TPad*)ca->GetListOfPrimitives()->FindObject(Form("can3_%d",j));          
+      if(!pad){
+       printf("Empty pad in canvas %s.\n", ca->GetName());
+       continue;            
+      }
+      if(plottype.Contains("event"))
+       g[i] =(TH1D*)pad->FindObject(Form("fEvent%s_proj_%d",option,j-1));
+      else
+       g[i] =(TH1D*)pad->FindObject(Form("fTrack%s_proj_%d",option,j-1));
+      if(!g[i]){
+       printf("Empty histogram for i=%d, file %s.\n", i, file[i].data());
+       continue;
+      }
         
-        d->cd(j);
+      d->cd(j);
                
-        if(i==0){
-         g[i]->SetLineColor(kBlack);
-         if(bDrawNormalized) 
-           g[i]->DrawNormalized();
-         else
-           g[i]->Draw();
-         if(option=="OFF"){
-            TPaveStats *st = (TPaveStats*)g[i]->FindObject("stats");
-            st->SetTextColor(kBlack);
-            d->Update();
-         }
+      if(i==0){
+       g[i]->SetLineColor(kBlack);
+       //        defineYaxisMax(hlt, off);
+       if(bDrawNormalized) 
+         g[i]->DrawNormalized();
+       else
+         g[i]->Draw();
+       if(option=="OFF"){
+         TPaveStats *st = (TPaveStats*)g[i]->FindObject("stats");
+         st->SetTextColor(kBlack);
+         d->Update();
        }
-        else { 
-         if(i<4)
-           g[i]->SetLineColor(i+1);
-         else
-           g[i]->SetLineColor(i+2);
-         defineYaxisMax(g[0], g[i]);
-         if(bDrawNormalized)  g[i]->DrawNormalized("sames");
-         else g[i]->Draw("sames");
-
-       }
-       if(!bDrawNormalized)                                     
-         if(i>0) printStats(g[i-1], g[i]);
+      }
+      else { 
+       if(i<4)
+         g[i]->SetLineColor(i+1);
+       else
+         g[i]->SetLineColor(i+2);
+       defineYaxisMax(g[0], g[i]);
+       if(bDrawNormalized)  g[i]->DrawNormalized("sames");
+       else g[i]->Draw("sames");
+
+      }
+
+      if(!bDrawNormalized)                                      
+       if(i>0) printStats(g[i-1], g[i]);
        
-       ff->Close();
-        sprintf( cut,"%s",cutnames[i].c_str() );
-       if(j==1) {
-         l->AddEntry(g[i],cut,"l");            
-         cutnames[i].resize(6);
-         plotname+="_"+cutnames[i];
-       }
-       else continue;
+      ff->Close();
+      sprintf( cut,"%s",cutnames[i].c_str() );
+      if((j==2&&plottype.Contains("track")) || ((j==6&&plottype.Contains("event")))) {
+
+       l->AddEntry(g[i],cut,"l");              
+       //        cutnames[i].resize(6);
+       plotname+="_"+cutnames[i];
+       //cout << "Adding Run: " << plotname <<endl;
+       cout << "Adding Run: " << cutnames[i] <<endl;
+      }
+      else continue;
+    }
+
+    if(j==2 && plottype.Contains("track") ) l->Draw("same");
+    if(plottype.Contains("event") && j==6) {
+      d->cd(7);
+      l->Draw();
+
     }
-    if(j==1) l->Draw("same");
     d->Update();
   }
 
   d->Update(); 
 
   sprintf(filenames,"%s",plotname.c_str());
+  cout << filenames << endl;
   if( bAddRunName){
-    d->SaveAs(Form("overlay_%s_for%s.root",option,plotname));
-    d->Print(Form("overlay_%s_for%s.png",option,plotname));
+    d->SaveAs(Form("overlay_%s_for%s.root",option,filenames));
+    d->Print(Form("overlay_%s_for%s.png",option,filenames));
   }
   else{
     d->SaveAs(Form("overlay_%s.root",option));