]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliQualAssCheckerBase.cxx
Modifications in AliESDMuonTrack:
[u/mrichter/AliRoot.git] / STEER / AliQualAssCheckerBase.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 /* $Id$ */
18
19 /*
20   Base class for detectors quality assurance checkers 
21   Compares Data made by QualAssDataMakers with reference data
22   Y. Schutz CERN August 2007
23 */
24
25 // --- ROOT system ---
26 #include <TClass.h>
27 #include <TH1F.h> 
28 #include <TH1I.h> 
29 #include <TIterator.h> 
30 #include <TKey.h> 
31 #include <TFile.h> 
32
33 // --- Standard library ---
34
35 // --- AliRoot header files ---
36 #include "AliLog.h"
37 #include "AliQualAss.h"
38 #include "AliQualAssChecker.h"
39 #include "AliQualAssCheckerBase.h"
40 #include "AliQualAssDataMaker.h"
41
42 ClassImp(AliQualAssCheckerBase)
43
44            
45 //____________________________________________________________________________ 
46 AliQualAssCheckerBase::AliQualAssCheckerBase(const char * name, const char * title) : 
47   TNamed(name, title), 
48   fDataSubDir(0x0),
49   fRefSubDir(0x0) 
50 {
51   // ctor
52 }
53
54 //____________________________________________________________________________ 
55 AliQualAssCheckerBase::AliQualAssCheckerBase(const AliQualAssCheckerBase& qadm) :
56   TNamed(qadm.GetName(), qadm.GetTitle()),
57   fDataSubDir(qadm.fDataSubDir), 
58   fRefSubDir(qadm.fRefSubDir)
59 {
60   //copy ctor
61     
62 }
63
64 //____________________________________________________________________________
65 AliQualAssCheckerBase& AliQualAssCheckerBase::operator = (const AliQualAssCheckerBase& qadm )
66 {
67   // Equal operator.
68   this->~AliQualAssCheckerBase();
69   new(this) AliQualAssCheckerBase(qadm);
70   return *this;
71 }
72
73 //____________________________________________________________________________
74 const Double_t AliQualAssCheckerBase::Check() 
75 {
76   // Performs a basic checking
77   // Compares all the histograms stored in the directory
78
79    Double_t test = 0.0  ;
80    Int_t count = 0 ; 
81
82    if (!fDataSubDir)  
83      test = 1. ; // nothing to check
84    else 
85      if (!fRefSubDir)
86        test = -1 ; // no reference data
87      else {
88        TList * keyList = fDataSubDir->GetListOfKeys() ; 
89        TIter next(keyList) ; 
90        TKey * key ;
91        count = 0 ; 
92        while ( (key = static_cast<TKey *>(next())) ) {
93          TObject * odata = fRefSubDir->Get(key->GetName()) ; 
94          if ( odata->IsA()->InheritsFrom("TH1") ) {
95            TH1 * hdata = static_cast<TH1*>(odata) ; 
96            TH1 * href  = static_cast<TH1*>(fRefSubDir->Get(key->GetName())) ;
97            if (!href) 
98              test = -1 ; // no reference data ; 
99            else {
100              Double_t rv =  DiffK(hdata, href) ;
101              AliInfo(Form("%s ->Test = %f", hdata->GetName(), rv)) ; 
102              test += rv ; 
103              count++ ; 
104            }
105          }
106          else
107            AliError(Form("%s Is a Classname that cannot be processed", key->GetClassName())) ;
108        }
109
110      }
111    if (count != 0) 
112      test /= count ;
113    
114    return test ; 
115 }  
116
117 //____________________________________________________________________________ 
118 const Double_t AliQualAssCheckerBase::DiffC(const TH1 * href, const TH1 * hin) const
119 {
120   // compares two histograms using the Chi2 test
121   if ( hin->Integral() == 0 ) {
122     AliWarning(Form("Spectrum %s in %s is empty", hin->GetName(), AliQualAss::GetDataName())) ; 
123     return 0. ;
124   }
125     
126   return hin->Chi2Test(href) ;  
127 }
128
129 //____________________________________________________________________________ 
130 const Double_t AliQualAssCheckerBase::DiffK(const TH1 * href, const TH1 * hin) const
131 {
132   // compares two histograms using the Kolmogorov test
133   if ( hin->Integral() == 0 ) {
134     AliWarning(Form("Spectrum %s in %s is empty", hin->GetName(), AliQualAss::GetDataName())) ; 
135     return 0. ;
136   }
137     
138   return hin->KolmogorovTest(href) ;  
139 }
140
141 //____________________________________________________________________________ 
142 void AliQualAssCheckerBase::Init(const AliQualAss::DETECTORINDEX det)
143 {
144   AliQualAss::Instance(det) ; 
145 }
146  
147 //____________________________________________________________________________
148 void AliQualAssCheckerBase::Run(AliQualAss::ALITASK index) 
149
150   AliInfo(Form("Processing %s", AliQualAss::GetAliTaskName(index))) ; 
151
152   AliQualAss * qa = AliQualAss::Instance(index) ; 
153
154   Double_t rv = Check() ;   
155   if ( rv <= 0.) 
156     qa->Set(AliQualAss::kFATAL) ; 
157   else if ( rv > 0 && rv <= 0.2 )
158     qa->Set(AliQualAss::kERROR) ; 
159   else if ( rv > 0.2 && rv <= 0.5 )
160     qa->Set(AliQualAss::kWARNING) ;
161   else if ( rv > 0.5 && rv < 1 ) 
162     qa->Set(AliQualAss::kINFO) ; 
163   AliInfo(Form("Test result of %s", AliQualAss::GetAliTaskName(index))) ;
164   Finish() ; 
165 }
166
167 //____________________________________________________________________________
168 void AliQualAssCheckerBase::Finish() const 
169 {
170   // wrap up and save QA in proper file
171     
172   AliQualAss * qa = AliQualAss::Instance() ; 
173   qa->Show() ;
174   AliQualAssChecker::GetQAResultFile()->cd() ; 
175   qa->Write(qa->GetName(), kWriteDelete) ;   
176   AliQualAssChecker::GetQAResultFile()->Close() ;  
177 }