/************************************************************************** * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * * * * Author: The ALICE Off-line Project. * * Contributors are mentioned in the code where appropriate. * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * * without fee, provided that the above copyright notice appears in all * * copies and that both the copyright notice and this permission notice * * appear in the supporting documentation. The authors make no claims * * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ /* $Id$ */ // // Base class for detectors quality assurance checkers // Compares Data made by QADataMakers with reference data // Y. Schutz CERN August 2007 // // --- ROOT system --- #include #include #include #include #include #include #include #include // --- Standard library --- // --- AliRoot header files --- #include "AliLog.h" #include "AliQA.h" #include "AliQAChecker.h" #include "AliQACheckerBase.h" #include "AliQADataMaker.h" ClassImp(AliQACheckerBase) //____________________________________________________________________________ AliQACheckerBase::AliQACheckerBase(const char * name, const char * title) : TNamed(name, title), fDataSubDir(0x0), fRefSubDir(0x0), fRefOCDBSubDir(0x0), fLowTestValue(0x0), fUpTestValue(0x0) { // ctor fLowTestValue = new Float_t[AliQA::kNBIT] ; fUpTestValue = new Float_t[AliQA::kNBIT] ; fLowTestValue[AliQA::kINFO] = 0.5 ; fUpTestValue[AliQA::kINFO] = 1.0 ; fLowTestValue[AliQA::kWARNING] = 0.002 ; fUpTestValue[AliQA::kWARNING] = 0.5 ; fLowTestValue[AliQA::kERROR] = 0.0 ; fUpTestValue[AliQA::kERROR] = 0.002 ; fLowTestValue[AliQA::kFATAL] = -1.0 ; fUpTestValue[AliQA::kFATAL] = 0.0 ; AliInfo("Default setting is:") ; printf( " INFO -> %1.5f < value < %1.5f \n", fLowTestValue[AliQA::kINFO], fUpTestValue[AliQA::kINFO]) ; printf( " WARNING -> %1.5f < value <= %1.5f \n", fLowTestValue[AliQA::kWARNING], fUpTestValue[AliQA::kWARNING]) ; printf( " ERROR -> %1.5f < value <= %1.5f \n", fLowTestValue[AliQA::kERROR], fUpTestValue[AliQA::kERROR]) ; printf( " FATAL -> %1.5f <= value < %1.5f \n", fLowTestValue[AliQA::kFATAL], fUpTestValue[AliQA::kFATAL]) ; } //____________________________________________________________________________ AliQACheckerBase::AliQACheckerBase(const AliQACheckerBase& qac) : TNamed(qac.GetName(), qac.GetTitle()), fDataSubDir(qac.fDataSubDir), fRefSubDir(qac.fRefSubDir), fRefOCDBSubDir(qac.fRefOCDBSubDir), fLowTestValue(qac.fLowTestValue), fUpTestValue(qac.fLowTestValue) { //copy ctor for (Int_t index = 0 ; index < AliQA::kNBIT ; index++) { fLowTestValue[index] = qac.fLowTestValue[index] ; fUpTestValue[index] = qac.fUpTestValue[index] ; } } //____________________________________________________________________________ AliQACheckerBase& AliQACheckerBase::operator = (const AliQACheckerBase& qadm ) { // Equal operator. this->~AliQACheckerBase(); new(this) AliQACheckerBase(qadm); return *this; } //____________________________________________________________________________ AliQACheckerBase::~AliQACheckerBase() { delete [] fLowTestValue ; delete [] fUpTestValue ; } //____________________________________________________________________________ Double_t * AliQACheckerBase::Check(AliQA::ALITASK_t /*index*/) { // 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 ; if ( !AliQA::Instance()->IsEventSpecieSet(specie) ) continue ; if (!fDataSubDir) { test[specie] = 0. ; // nothing to check } else if (!fRefSubDir && !fRefOCDBSubDir) { test[specie] = -1 ; // no reference data } else { TList * keyList = fDataSubDir->GetListOfKeys() ; TIter next(keyList) ; TKey * key ; count[specie] = 0 ; while ( (key = static_cast(next())) ) { TObject * odata = fRefSubDir->Get(key->GetName()) ; if ( odata->IsA()->InheritsFrom("TH1") ) { TH1 * hdata = static_cast(odata) ; TH1 * href = NULL ; if (fRefSubDir) href = static_cast(fRefSubDir->Get(key->GetName())) ; else if (fRefOCDBSubDir[specie]) { href = static_cast(fRefOCDBSubDir[specie]->FindObject(key->GetName())) ; } if (!href) test[specie] = -1 ; // no reference data ; else { Double_t rv = DiffK(hdata, href) ; AliInfo(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())) ; } if (count[specie] != 0) test[specie] /= count[specie] ; } } return test ; } //____________________________________________________________________________ Double_t * AliQACheckerBase::Check(AliQA::ALITASK_t /*index*/, TObjArray ** list) { // Performs a basic checking // Compares all the histograms in the list 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 ; if ( !AliQA::Instance()->IsEventSpecieSet(specie) ) continue ; if (list[specie]->GetEntries() == 0) test[specie] = 0. ; // nothing to check else { if (!fRefSubDir && !fRefOCDBSubDir) test[specie] = -1 ; // no reference data else { TIter next(list[specie]) ; TH1 * hdata ; count[specie] = 0 ; while ( (hdata = dynamic_cast(next())) ) { if ( hdata) { if ( hdata->TestBit(AliQA::GetExpertBit()) ) // does not perform the test for expert data continue ; TH1 * href = NULL ; if (fRefSubDir) href = static_cast(fRefSubDir->Get(hdata->GetName())) ; else if (fRefOCDBSubDir[specie]) href = static_cast(fRefOCDBSubDir[specie]->FindObject(hdata->GetName())) ; if (!href) test[specie] = -1 ; // no reference data ; else { Double_t rv = DiffK(hdata, href) ; AliInfo(Form("%s ->Test = %f", hdata->GetName(), rv)) ; test[specie] += rv ; count[specie]++ ; } } else AliError("Data type cannot be processed") ; } if (count[specie] != 0) test[specie] /= count[specie] ; } } } return test ; } //____________________________________________________________________________ Double_t AliQACheckerBase::DiffC(const TH1 * href, const TH1 * hin) const { // compares two histograms using the Chi2 test if ( hin->Integral() == 0 ) { AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; return 0. ; } return hin->Chi2Test(href) ; } //____________________________________________________________________________ Double_t AliQACheckerBase::DiffK(const TH1 * href, const TH1 * hin) const { // compares two histograms using the Kolmogorov test if ( hin->Integral() == 0 ) { AliWarning(Form("Spectrum %s is empty", hin->GetName())) ; return 0. ; } return hin->KolmogorovTest(href) ; } //____________________________________________________________________________ void AliQACheckerBase::Run(AliQA::ALITASK_t index, TObjArray ** list) { AliDebug(1, Form("Processing %s", AliQA::GetAliTaskName(index))) ; Double_t * rv = NULL ; if ( !list) rv = Check(index) ; else rv = Check(index, list) ; SetQA(index, rv) ; AliDebug(1, Form("Test result of %s", AliQA::GetAliTaskName(index))) ; if (rv) delete [] rv ; Finish() ; } //____________________________________________________________________________ void AliQACheckerBase::Finish() const { // wrap up and save QA in proper file AliQA * qa = AliQA::Instance() ; qa->Show() ; AliQA::GetQAResultFile()->cd() ; qa->Write(qa->GetName(), kWriteDelete) ; AliQA::GetQAResultFile()->Close() ; } //____________________________________________________________________________ void AliQACheckerBase::SetHiLo(Float_t * hiValue, Float_t * lowValue) { AliInfo("Previous setting was:") ; printf( " INFO -> %1.5f < value < %1.5f \n", fLowTestValue[AliQA::kINFO], fUpTestValue[AliQA::kINFO]) ; printf( " WARNING -> %1.5f < value <= %1.5f \n", fLowTestValue[AliQA::kWARNING], fUpTestValue[AliQA::kWARNING]) ; printf( " ERROR -> %1.5f < value <= %1.5f \n", fLowTestValue[AliQA::kERROR], fUpTestValue[AliQA::kERROR]) ; printf( " FATAL -> %1.5f <= value < %1.5f \n", fLowTestValue[AliQA::kFATAL], fUpTestValue[AliQA::kFATAL]) ; for (Int_t index = 0 ; index < AliQA::kNBIT ; index++) { fLowTestValue[index] = lowValue[index] ; fUpTestValue[index] = hiValue[index] ; } AliInfo("Current setting is:") ; printf( " INFO -> %1.5f < value < %1.5f \n", fLowTestValue[AliQA::kINFO], fUpTestValue[AliQA::kINFO]) ; printf( " WARNING -> %1.5f < value <= %1.5f \n", fLowTestValue[AliQA::kWARNING], fUpTestValue[AliQA::kWARNING]) ; printf( " ERROR -> %1.5f < value <= %1.5f \n", fLowTestValue[AliQA::kERROR], fUpTestValue[AliQA::kERROR]) ; printf( " FATAL -> %1.5f <= value < %1.5f \n", fLowTestValue[AliQA::kFATAL], fUpTestValue[AliQA::kFATAL]) ; } //____________________________________________________________________________ void AliQACheckerBase::SetQA(AliQA::ALITASK_t index, Double_t * value) const { // sets the QA according the return value of the Check AliQA * qa = AliQA::Instance(index) ; for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) { if ( value == NULL ) { // No checker is implemented, set all QA to Fatal qa->Set(AliQA::kFATAL, specie) ; } else { if ( value[specie] >= fLowTestValue[AliQA::kFATAL] && value[specie] < fUpTestValue[AliQA::kFATAL] ) qa->Set(AliQA::kFATAL, specie) ; else if ( value[specie] > fLowTestValue[AliQA::kERROR] && value[specie] <= fUpTestValue[AliQA::kERROR] ) qa->Set(AliQA::kERROR, specie) ; else if ( value[specie] > fLowTestValue[AliQA::kWARNING] && value[specie] <= fUpTestValue[AliQA::kWARNING] ) qa->Set(AliQA::kWARNING, specie) ; else if ( value[specie] > fLowTestValue[AliQA::kINFO] && value[specie] <= fUpTestValue[AliQA::kINFO] ) qa->Set(AliQA::kINFO, specie) ; } } }