]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliQACheckerBase.cxx
Obsolete code removed.
[u/mrichter/AliRoot.git] / STEER / AliQACheckerBase.cxx
index f354800889f2abe8edc1351b21a4ca966c508d72..6a9a0e88f6696c26df99f5ec74973d8fd5d810ca 100644 (file)
@@ -23,6 +23,7 @@
 //
 
 // --- ROOT system ---
+#include <TCanvas.h>
 #include <TClass.h>
 #include <TH1F.h> 
 #include <TH1I.h> 
@@ -31,6 +32,7 @@
 #include <TFile.h> 
 #include <TList.h>
 #include <TNtupleD.h>
+#include <TPaveText.h>
 
 // --- Standard library ---
 
@@ -40,6 +42,7 @@
 #include "AliQAChecker.h"
 #include "AliQACheckerBase.h"
 #include "AliQADataMaker.h"
+#include "AliDetectorRecoParam.h"
 
 ClassImp(AliQACheckerBase)
 
@@ -49,9 +52,11 @@ AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
   TNamed(name, title), 
   fDataSubDir(0x0),
   fRefSubDir(0x0), 
-  fRefOCDBSubDir(0x0), 
+  fRefOCDBSubDir(new TObjArray*[AliRecoParam::kNSpecies]), 
   fLowTestValue(0x0),
-  fUpTestValue(0x0)
+  fUpTestValue(0x0),
+  fImage(new TCanvas*[AliRecoParam::kNSpecies]), 
+  fPrintImage(kTRUE)
 {
   // ctor
   fLowTestValue = new Float_t[AliQAv1::kNBIT] ; 
@@ -67,10 +72,17 @@ AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) :
   
   AliDebug(AliQAv1::GetQADebugLevel(), "Default setting is:") ;
   if ( AliDebugLevel()  == AliQAv1::GetQADebugLevel() ) {
-    printf( "                      INFO    -> %1.5f <  value <  %1.5f \n", fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO]) ; 
-    printf( "                      WARNING -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING]) ; 
-    printf( "                      ERROR   -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR]) ; 
-    printf( "                      FATAL   -> %1.5f <= value <  %1.5f \n", fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
+    const Char_t * text= Form(" INFO    -> %1.5f <  value <  %1.5f  WARNING -> %1.5f <  value <= %1.5f \n ERROR   -> %1.5f <  value <= %1.5f \n FATAL   -> %1.5f <= value <  %1.5f \n", 
+                              fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO], 
+                              fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING], 
+                              fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR], 
+                              fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
+    AliInfo(Form("%s", text)) ; 
+  }
+  
+  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
+    fImage[specie] = NULL ; 
+    fRefOCDBSubDir[specie] = NULL ;
   }
 }
 
@@ -81,22 +93,27 @@ AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) :
   fRefSubDir(qac.fRefSubDir), 
   fRefOCDBSubDir(qac.fRefOCDBSubDir), 
   fLowTestValue(qac.fLowTestValue),
-  fUpTestValue(qac.fLowTestValue)
+  fUpTestValue(qac.fLowTestValue), 
+  fImage(NULL),  
+  fPrintImage(kTRUE)
 {
   //copy ctor
   for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
     fLowTestValue[index]  = qac.fLowTestValue[index] ; 
     fUpTestValue[index] = qac.fUpTestValue[index] ; 
   }
-    
+    for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
+      fImage[specie] = qac.fImage[specie] ; 
+      fRefOCDBSubDir[specie] = qac.fRefOCDBSubDir[specie] ; 
+    }
 }
 
 //____________________________________________________________________________
-AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm )
+AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qac )
 {
   // Equal operator.
   this->~AliQACheckerBase();
-  new(this) AliQACheckerBase(qadm);
+  new(this) AliQACheckerBase(qac);
   return *this;
 }
 
@@ -105,61 +122,59 @@ AliQACheckerBase::~AliQACheckerBase()
 {
   delete [] fLowTestValue ; 
   delete [] fUpTestValue ; 
+  for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
+    if ( fImage[esIndex] ) 
+      delete fImage[esIndex] ;
+    if ( fRefOCDBSubDir[esIndex] ) 
+      delete fRefOCDBSubDir[esIndex] ; 
+  }
+  delete[] fImage ; 
+  delete[] fRefOCDBSubDir ; 
 }
 
 //____________________________________________________________________________
-Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/
+Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam
 {
   // Performs a basic checking
   // Compares all the histograms stored in the directory
   // With reference histograms either in a file of in OCDB  
 
-       Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
-       Int_t count[AliRecoParam::kNSpecies]   = { 0 }; 
-
-  for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
-    test[specie] = 1.0 ; 
+  TObjArray ** list = new TObjArray *[AliRecoParam::kNSpecies] ; 
+  Int_t specie ;
+  for (specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
+    list[specie] =  new TObjArray(AliQAv1::GetMaxQAObj()) ; 
     if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
       continue ; 
-    if (!fDataSubDir) {
-      test[specie] = 0. ; // nothing to check
-    } else if (!fRefSubDir && !fRefOCDBSubDir) {
-        test[specie] = -1 ; // no reference data
-    } else {
+    if (fDataSubDir) {
       TList * keyList = fDataSubDir->GetListOfKeys() ; 
       TIter next(keyList) ; 
       TKey * key ;
-      count[specie] = 0 ; 
       while ( (key = static_cast<TKey *>(next())) ) {
-        TObject * odata = fRefSubDir->Get(key->GetName()) ; 
-        if ( odata->IsA()->InheritsFrom("TH1") ) {
-          TH1 * hdata = static_cast<TH1*>(odata) ;
-          TH1 * href = NULL ; 
-          if (fRefSubDir) 
-            href  = static_cast<TH1*>(fRefSubDir->Get(key->GetName())) ;
-          else if (fRefOCDBSubDir[specie]) {  
-            href  = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(key->GetName())) ;
-          }
-          if (!href) 
-            test[specie] = -1 ; // no reference data ; 
-          else {
-            Double_t rv =  DiffK(hdata, href) ;
-            AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
-            test[specie] += rv ; 
-            count[specie]++ ; 
-          }
-        } else
-          AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
+        TDirectory * specieDir = fDataSubDir->GetDirectory(key->GetName()) ; 
+        TList * keykeyList = specieDir->GetListOfKeys() ; 
+        TIter next2(keykeyList) ; 
+        TKey * keykey ;
+        while ( (keykey = static_cast<TKey *>(next2())) ) {
+          TObject * odata = specieDir->Get(keykey->GetName()) ; 
+          if ( odata->IsA()->InheritsFrom("TH1") ) {
+            TH1 * hdata = static_cast<TH1*>(odata) ;
+            list[specie]->Add(hdata) ; 
+          } else if (!odata->IsA()->InheritsFrom("TDirectory")) // skip the expert directory
+            AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
+        }
       }
-      if (count[specie] != 0) 
-        test[specie] /= count[specie] ;
     }
   }
-       return test ;
+  Double_t * test = Check(index, list, recoParam) ;
+  
+  delete[] list ; 
+    
+  return test ;
 }  
 
 //____________________________________________________________________________
-Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list) 
+Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list, AliDetectorRecoParam * /*recoParam*/
 {
   // Performs a basic checking
   // Compares all the histograms in the list
@@ -169,7 +184,7 @@ Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** li
 
   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
     test[specie] = 1.0 ; 
-    if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) 
+    if ( !AliQAv1::Instance()->IsEventSpecieSet(specie)) 
       continue ; 
     if (list[specie]->GetEntries() == 0)  
       test[specie] = 0. ; // nothing to check
@@ -180,8 +195,8 @@ Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** li
         TIter next(list[specie]) ; 
         TH1 * hdata ;
         count[specie] = 0 ; 
-        while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
-          if ( hdata) { 
+        while ( (hdata = static_cast<TH1 *>(next())) ) {
+          if ( hdata->IsA()->InheritsFrom("TH1") ) {
             if ( hdata->TestBit(AliQAv1::GetExpertBit()) )  // does not perform the test for expert data
               continue ; 
             TH1 * href = NULL ; 
@@ -195,18 +210,17 @@ Double_t * AliQACheckerBase::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** li
               Double_t rv =  DiffK(hdata, href) ;
               AliDebug(AliQAv1::GetQADebugLevel(), Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
               test[specie] += rv ; 
-              count[specie]++ ; 
+              count[specie]++ ;
             }
-          } 
-          else
+          } else
             AliError("Data type cannot be processed") ;
+          if (count[specie] != 0) 
+            test[specie] /= count[specie] ;
         }
-        if (count[specie] != 0) 
-          test[specie] /= count[specie] ;
       }
     }
   }
-       return test ;
+  return test ;
 }  
 
 
@@ -226,8 +240,8 @@ Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
 Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
 {
   // compares two histograms using the Kolmogorov test
-  if ( hin->Integral() == 0 ) {
-    AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s is empty", hin->GetName())) ; 
+  if ( hin->Integral() == 0 || href->Integral() == 0) {
+    AliDebug(AliQAv1::GetQADebugLevel(), Form("Spectrum %s or its reference is empty", hin->GetName())) ; 
     return 0. ;
   }
     
@@ -235,15 +249,28 @@ Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
 }
 
 //____________________________________________________________________________
-void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list
+void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, AliDetectorRecoParam * recoParam
 { 
        AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ; 
   
        Double_t * rv = NULL ;
-  if ( !list) 
-    rv = Check(index) ;
-  else 
-    rv = Check(index, list) ;
+  rv = Check(index, recoParam) ;
+       SetQA(index, rv) ;      
+       
+  AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
+       
+  if (rv) 
+    delete [] rv ; 
+  Finish() ; 
+}
+
+//____________________________________________________________________________
+void AliQACheckerBase::Run(AliQAv1::ALITASK_t index, TObjArray ** list, AliDetectorRecoParam * recoParam) 
+{ 
+       AliDebug(AliQAv1::GetQADebugLevel(), Form("Processing %s", AliQAv1::GetAliTaskName(index))) ; 
+  
+       Double_t * rv = NULL ;
+  rv = Check(index, list, recoParam) ;
        SetQA(index, rv) ;      
        
   AliDebug(AliQAv1::GetQADebugLevel(), Form("Test result of %s", AliQAv1::GetAliTaskName(index))) ;
@@ -258,33 +285,98 @@ void AliQACheckerBase::Finish() const
 {
        // wrap up and save QA in proper file
        AliQAv1 * qa = AliQAv1::Instance() ; 
-       qa->Show() ;
+       //qa->Show() ;
        AliQAv1::GetQAResultFile()->cd() ; 
        qa->Write(qa->GetName(), kWriteDelete) ;   
        AliQAv1::GetQAResultFile()->Close() ; 
 }
 
+//____________________________________________________________________________ 
+void AliQACheckerBase::MakeImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode) 
+{
+  // makes the QA image for sim and rec
+  Int_t nImages = 0 ;
+  for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
+    if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) ) 
+      continue ;
+    TIter next(list[esIndex]) ;  
+    TH1 * hdata = NULL ; 
+    while ( (hdata=static_cast<TH1 *>(next())) ) {
+      TString cln(hdata->ClassName()) ; 
+      if ( ! cln.Contains("TH") )
+        continue ; 
+      if ( hdata->TestBit(AliQAv1::GetImageBit()) )
+        nImages++; 
+    }
+    break ; 
+  }
+  if ( nImages == 0 ) {
+    AliDebug(AliQAv1::GetQADebugLevel(), Form("No histogram will be plotted for %s %s\n", GetName(), AliQAv1::GetTaskName(task).Data())) ;  
+  } else {
+    AliDebug(AliQAv1::GetQADebugLevel(), Form("%d histograms will be plotted for %s %s\n", nImages, GetName(), AliQAv1::GetTaskName(task).Data())) ;  
+    for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
+      if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0) 
+        continue ;
+      const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
+      if ( !fImage[esIndex] ) {
+        fImage[esIndex] = new TCanvas(title, title) ;
+      }
+      fImage[esIndex]->Clear() ; 
+      fImage[esIndex]->SetTitle(title) ; 
+      fImage[esIndex]->cd() ; 
+      TPaveText someText(0.015, 0.015, 0.98, 0.98) ;
+      someText.AddText(title) ;
+      someText.Draw() ; 
+      fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ; 
+      fImage[esIndex]->Clear() ; 
+      Int_t nx = TMath::Sqrt(nImages) ; 
+      Int_t ny = nx  ; 
+      while ( nx*ny <= nImages) 
+        ny++ ; 
+      
+      fImage[esIndex]->Divide(nx, ny) ; 
+      TIter nexthist(list[esIndex]) ; 
+      TH1* hist = NULL ;
+      Int_t npad = 1 ; 
+      fImage[esIndex]->cd(npad) ; 
+      while ( (hist=static_cast<TH1*>(nexthist())) ) {
+        TString cln(hist->ClassName()) ; 
+        if ( ! cln.Contains("TH") )
+          continue ; 
+        if(hist->TestBit(AliQAv1::GetImageBit())) {
+          hist->Draw() ; 
+          fImage[esIndex]->cd(++npad) ; 
+        }
+      }
+      fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat())) ; 
+    }
+  }  
+}
+
 //____________________________________________________________________________
 void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue) 
 {
   AliDebug(AliQAv1::GetQADebugLevel(), "Previous setting was:") ;
   if ( AliDebugLevel() == AliQAv1::GetQADebugLevel() ) {
-    printf( "                      INFO    -> %1.5f <  value <  %1.5f \n", fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO]) ; 
-    printf( "                      WARNING -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING]) ; 
-    printf( "                      ERROR   -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR]) ; 
-    printf( "                      FATAL   -> %1.5f <= value <  %1.5f \n", fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
+    const Char_t * text= Form(" INFO    -> %1.5f <  value <  %1.5f  WARNING -> %1.5f <  value <= %1.5f \n ERROR   -> %1.5f <  value <= %1.5f \n FATAL   -> %1.5f <= value <  %1.5f \n", 
+                              fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO], 
+                              fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING], 
+                              fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR], 
+                              fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
+    AliInfo(Form("%s", text)) ; 
   }
   
   for (Int_t index = 0 ; index < AliQAv1::kNBIT ; index++) {
     fLowTestValue[index]  = lowValue[index] ; 
-    fUpTestValue[index] = hiValue[index] ; 
+    fUpTestValue[index]   = hiValue[index] ; 
   }
   AliDebug(AliQAv1::GetQADebugLevel(), "Current setting is:") ;
   if ( AliDebugLevel()  == AliQAv1::GetQADebugLevel() ) {
-    printf( "                      INFO    -> %1.5f <  value <  %1.5f \n", fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO]) ; 
-    printf( "                      WARNING -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING]) ; 
-    printf( "                      ERROR   -> %1.5f <  value <= %1.5f \n", fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR]) ; 
-    printf( "                      FATAL   -> %1.5f <= value <  %1.5f \n", fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ; 
+    const Char_t * text= Form(" INFO    -> %1.5f <  value <  %1.5f  WARNING -> %1.5f <  value <= %1.5f \n ERROR   -> %1.5f <  value <= %1.5f \n FATAL   -> %1.5f <= value <  %1.5f \n", 
+                              fLowTestValue[AliQAv1::kINFO], fUpTestValue[AliQAv1::kINFO], 
+                              fLowTestValue[AliQAv1::kWARNING], fUpTestValue[AliQAv1::kWARNING], 
+                              fLowTestValue[AliQAv1::kERROR], fUpTestValue[AliQAv1::kERROR], 
+                              fLowTestValue[AliQAv1::kFATAL], fUpTestValue[AliQAv1::kFATAL]) ;     AliInfo(Form("%s", text)) ; 
   }
 }
 
@@ -294,18 +386,21 @@ void AliQACheckerBase::SetQA(AliQAv1::ALITASK_t index, Double_t * value) const
        // sets the QA according the return value of the Check
 
   AliQAv1 * qa = AliQAv1::Instance(index) ;
+
   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
+    if (! qa->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)))
+      continue ;
     if (  value == NULL ) { // No checker is implemented, set all QA to Fatal
       qa->Set(AliQAv1::kFATAL, specie) ; 
     } else {
       if ( value[specie] >= fLowTestValue[AliQAv1::kFATAL] && value[specie] < fUpTestValue[AliQAv1::kFATAL] ) 
-        qa->Set(AliQAv1::kFATAL, specie) ; 
+        qa->Set(AliQAv1::kFATAL, AliRecoParam::ConvertIndex(specie)) ; 
       else if ( value[specie] > fLowTestValue[AliQAv1::kERROR] && value[specie] <= fUpTestValue[AliQAv1::kERROR]  )
-        qa->Set(AliQAv1::kERROR, specie) ; 
+        qa->Set(AliQAv1::kERROR, AliRecoParam::ConvertIndex(specie)) ; 
       else if ( value[specie] > fLowTestValue[AliQAv1::kWARNING] && value[specie] <= fUpTestValue[AliQAv1::kWARNING]  )
-        qa->Set(AliQAv1::kWARNING, specie) ;
+        qa->Set(AliQAv1::kWARNING, AliRecoParam::ConvertIndex(specie)) ;
       else if ( value[specie] > fLowTestValue[AliQAv1::kINFO] && value[specie] <= fUpTestValue[AliQAv1::kINFO] ) 
-        qa->Set(AliQAv1::kINFO, specie) ;      
+        qa->Set(AliQAv1::kINFO, AliRecoParam::ConvertIndex(specie)) ;  
     }
   }
 }