]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDQAChecker.cxx
Task updated to estimate efficiency/contamination and to use the new CAF
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDQAChecker.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 //  Checks the quality assurance. 
21 //  By comparing with reference data
22 //  Skeleton for HMPID
23 //...
24
25 // --- ROOT system ---
26 #include <TClass.h>
27 #include <TH1F.h> 
28 #include <TH1I.h> 
29 #include <TF1.h> 
30 #include <TIterator.h> 
31 #include <TKey.h> 
32 #include <TFile.h> 
33
34 // --- Standard library ---
35
36 // --- AliRoot header files ---
37 #include "AliLog.h"
38 #include "AliQAv1.h"
39 #include "AliQAChecker.h"
40 #include "AliHMPIDQAChecker.h"
41 #include "AliCDBEntry.h"
42 #include "AliQAManager.h"
43
44 ClassImp(AliHMPIDQAChecker)
45  //_________________________________________________________________
46 AliHMPIDQAChecker::AliHMPIDQAChecker() : 
47 AliQACheckerBase("HMPID","HMPID Quality Assurance Data Checker"), 
48 fNoReference(kTRUE), 
49 fQARefRec(NULL)
50 {
51     //ctor, fetches the reference data from OCDB 
52   char * detOCDBDir = Form("HMPID/%s/%s", AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName()) ; 
53   AliCDBEntry * QARefRec = AliQAManager::QAManager()->Get(detOCDBDir);
54   if(QARefRec) {
55     fQARefRec = dynamic_cast<TObjArray*> (QARefRec->GetObject()) ; 
56     if (fQARefRec)
57       if (fQARefRec->GetEntries()) 
58         fNoReference = kFALSE ;            
59     if (fNoReference) 
60       AliInfo("QA reference data NOT retrieved for Reconstruction check. No HMPIDChecker!");
61   }
62 }
63
64 //_________________________________________________________________
65 AliHMPIDQAChecker::AliHMPIDQAChecker(const AliHMPIDQAChecker& qac) : 
66 AliQACheckerBase(qac.GetName(), qac.GetTitle()), 
67 fNoReference(qac.fNoReference), 
68 fQARefRec(NULL)
69 {
70   fNoReference = qac.fNoReference ; 
71   if (qac.fQARefRec) {
72     fQARefRec = new TObjArray(qac.fQARefRec->GetEntries()) ; 
73     for (Int_t index=0; index < qac.fQARefRec->GetEntries(); index++) 
74       fQARefRec->Add(qac.fQARefRec->At(index)) ; 
75   }
76 }
77
78 //_________________________________________________________________
79 AliHMPIDQAChecker::~AliHMPIDQAChecker() 
80 {
81   fQARefRec->Delete() ; 
82   delete fQARefRec ; 
83 }
84 //_________________________________________________________________
85 void AliHMPIDQAChecker::Check(Double_t *  check, AliQAv1::ALITASK_t index, TObjArray ** list, const AliDetectorRecoParam * /*recoParam*/) 
86 {
87 //
88 // Main check function: Depending on the TASK, different checks are applied
89 // At the moment:       check for empty histograms and checks for RecPoints
90
91   if(fNoReference)  
92
93   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
94     check[specie] = 1.0;
95     if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
96       continue ; 
97     // checking for empy histograms
98     if(CheckEntries(list[specie]) == 0)  {
99       AliWarning("histograms are empty");
100       check[specie] = 0.4;//-> Corresponds to kWARNING see AliQACheckerBase::Run
101     }
102   
103     //check sim
104     if(index == AliQAv1::kSIM) check[specie] = CheckSim(list[specie], fQARefRec);
105
106     // checking rec points
107     if(index == AliQAv1::kREC) check[specie] = CheckRec(list[specie], fQARefRec);
108    
109     //default check response. It will be changed when reasonable checks will be considered
110     else check[specie] = 0.7 ; // /-> Corresponds to kINFO see AliQACheckerBase::Run 
111   } // species loop
112 }
113 //_________________________________________________________________
114 Double_t AliHMPIDQAChecker::CheckEntries(TObjArray * list) const
115 {
116   //
117   //  check on the QA histograms on the input list: 
118   // 
119
120   Double_t test = 0.0  ;
121   Int_t count = 0 ; 
122   
123   if (list->GetEntries() == 0){  
124     test = 1. ; // nothing to check
125   }
126   else {
127     TIter next(list) ; 
128     TH1 * hdata ;
129     count = 0 ; 
130     while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
131       if (hdata) { 
132         Double_t rv = 0.;
133         //Printf("hitogram %s     has entries: %f ",hdata->GetName(),hdata->GetEntries());
134         if(hdata->GetEntries()>0)rv=1; 
135         count++ ; 
136         test += rv ; 
137       }
138       else{
139         AliError("Data type cannot be processed") ;
140       }
141       
142     }
143     if (count != 0) { 
144       if (test==0) {
145         AliWarning("Histograms are booked for THIS specific Task, but they are all empty: setting flag to kWARNING");
146         test = 0.;  //upper limit value to set kWARNING flag for a task
147       }
148       else test = 1 ;
149     }
150   }
151
152   return test ; 
153 }  
154 //_________________________________________________________________
155 Double_t AliHMPIDQAChecker::CheckSim(TObjArray *listsim, TObjArray *listref) const
156 {
157   //
158   //  check on the HMPID RecPoints by using expo fit and Kolmogorov Test:
159   //
160
161    Float_t checkresponse = 0;
162
163    Float_t counter = 0 ;
164    TIter next(listsim) ;
165    TH1* histo;
166    while ( (histo = dynamic_cast<TH1 *>(next())) ) {
167      //PH The histogram should have at least 10 bins with at least 5 entries
168      Int_t nbinsabove = 0;
169      for (Int_t ibin=histo->FindBin(1); ibin<=histo->FindBin(50); ibin++) { 
170        if (histo->GetBinContent(ibin)>5) nbinsabove++;
171      }
172
173    if( nbinsabove < 10 ) counter++;
174    else {
175     TString h = histo->GetTitle();
176     if(h.Contains("Zoom")){
177     histo->Fit("expo","LQ0","",5,50);
178     if(histo->GetFunction("expo")->GetParameter(1) !=0 ) if(TMath::Abs((-1./(histo->GetFunction("expo"))->GetParameter(1)) - 35 ) > 5) counter++;
179     }
180     if(h.Contains("size  MIP"))   if(TMath::Abs(histo->GetMean()-5) > 2) counter++;
181     if(h.Contains("size  Phots")) if(TMath::Abs(histo->GetMean()-2) > 2) counter++;
182     if(h.Contains("distribution")) if(histo->KolmogorovTest((TH1F *)listref->At(0))<0.8) counter++;
183     AliDebug(AliQAv1::GetQADebugLevel(),Form(" Kolm. test : %f ",histo->KolmogorovTest((TH1F *)listref->At(0))));  
184    }
185   }
186  Float_t response = counter/(7.+7.+42.+42.); // 7.+7.+42 +42 = N checked histograms (-> To be replaced by listsim->GetEntries())
187  
188  if(response < 0.1) checkresponse = 0.7;      // <10% of the check histograms show a failing check -> Corresponds to kINFO see AliQACheckerBase::Run
189  else if(response < 0.5) checkresponse = 0.4; //  50%  of the check histograms show a failing check -> Corresponds to kWARNING see AliQACheckerBase::Run
190  else checkresponse = 0.001;                  // > 50% of the check histograms show a failing check -> Corresponds to kERROR see AliQACheckerBase::Run
191  return checkresponse;
192 }
193
194 //___________________________________________________________________________________________________
195 Double_t AliHMPIDQAChecker::CheckRec(TObjArray *listrec, TObjArray *listref) const
196 {
197   //
198   //  check on the HMPID RecPoints by using expo fit and Kolmogorov Test:
199   //
200
201    Float_t checkresponse = 0;
202
203    Float_t counter = 0 ;
204    TIter next(listrec) ;
205    TH1* histo;
206    while ( (histo = dynamic_cast<TH1 *>(next())) ) {
207      //PH The histogram should have at least 10 bins with at least 5 entries
208      Int_t nbinsabove = 0;
209      for (Int_t ibin=histo->FindBin(1); ibin<=histo->FindBin(50); ibin++) { 
210        if (histo->GetBinContent(ibin)>5) nbinsabove++;
211      }
212
213    if( nbinsabove < 10 ) counter++;
214    else {
215     TString h = histo->GetTitle();
216     if(h.Contains("Zoom")){
217     histo->Fit("expo","LQ0","",5,50);
218     if(histo->GetFunction("expo")->GetParameter(1) !=0 ) if(TMath::Abs((-1./(histo->GetFunction("expo"))->GetParameter(1)) - 35 ) > 5) counter++;
219     }
220     if(h.Contains("size  MIP"))   if(TMath::Abs(histo->GetMean()-5) > 2) counter++;
221     if(h.Contains("size  Phots")) if(TMath::Abs(histo->GetMean()-2) > 2) counter++;
222     if(h.Contains("distribution")) if(histo->KolmogorovTest((TH1F *)listref->At(0))<0.8) counter++;
223     AliDebug(AliQAv1::GetQADebugLevel(),Form(" Kolm. test : %f ",histo->KolmogorovTest((TH1F *)listref->At(0))));  
224    }
225   }
226  Float_t response = counter/(7.+7.+42.+42.); // 7.+7.+42 +42 = N checked histograms (-> To be replaced by listrec->GetEntries())
227  
228  if(response < 0.1) checkresponse = 0.7;      // <10% of the check histograms show a failing check -> Corresponds to kINFO see AliQACheckerBase::Run
229  else if(response < 0.5) checkresponse = 0.4; //  50%  of the check histograms show a failing check -> Corresponds to kWARNING see AliQACheckerBase::Run
230  else checkresponse = 0.001;                  // > 50% of the check histograms show a failing check -> Corresponds to kERROR see AliQACheckerBase::Run
231  return checkresponse;
232 }
233