]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HMPID/AliHMPIDQAChecker.cxx
2486562946df0d4606c58d89a452535a4dd0c4ae
[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::operator=(const AliHMPIDQAChecker& qac) 
80 {
81   //
82   // Assignment operator
83   //
84   if (this!=&qac) {
85     AliQACheckerBase::operator=(qac) ;
86     fNoReference = qac.fNoReference  ;
87     fQARefRec    = qac.fQARefRec     ;    
88   }
89   return *this;
90 }   
91 //_______________________________________________________________________________________________
92 AliHMPIDQAChecker::~AliHMPIDQAChecker() 
93 {
94   fQARefRec->Delete() ; 
95   delete fQARefRec ; 
96 }
97 //_________________________________________________________________
98 Double_t * AliHMPIDQAChecker::Check(AliQAv1::ALITASK_t index, TObjArray ** list, const AliDetectorRecoParam * /*recoParam*/) 
99 {
100 //
101 // Main check function: Depending on the TASK, different checks are applied
102 // At the moment:       check for empty histograms and checks for RecPoints
103
104   Double_t * check = new Double_t[AliRecoParam::kNSpecies] ; 
105   if(fNoReference)  
106   return check;
107
108   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
109     check[specie] = 1.0;
110     if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) 
111       continue ; 
112     // checking for empy histograms
113     if(CheckEntries(list[specie]) == 0)  {
114       AliWarning("histograms are empty");
115       check[specie] = 0.4;//-> Corresponds to kWARNING see AliQACheckerBase::Run
116     }
117   
118     //check sim
119     if(index == AliQAv1::kSIM) check[specie] = CheckSim(list[specie], fQARefRec);
120
121     // checking rec points
122     if(index == AliQAv1::kREC) check[specie] = CheckRec(list[specie], fQARefRec);
123    
124     //default check response. It will be changed when reasonable checks will be considered
125     else check[specie] = 0.7 ; // /-> Corresponds to kINFO see AliQACheckerBase::Run 
126   } // species loop
127
128   return check;
129 }
130 //_________________________________________________________________
131 Double_t AliHMPIDQAChecker::CheckEntries(TObjArray * list) const
132 {
133   //
134   //  check on the QA histograms on the input list: 
135   // 
136
137   Double_t test = 0.0  ;
138   Int_t count = 0 ; 
139   
140   if (list->GetEntries() == 0){  
141     test = 1. ; // nothing to check
142   }
143   else {
144     TIter next(list) ; 
145     TH1 * hdata ;
146     count = 0 ; 
147     while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
148       if (hdata) { 
149         Double_t rv = 0.;
150         //Printf("hitogram %s     has entries: %f ",hdata->GetName(),hdata->GetEntries());
151         if(hdata->GetEntries()>0)rv=1; 
152         count++ ; 
153         test += rv ; 
154       }
155       else{
156         AliError("Data type cannot be processed") ;
157       }
158       
159     }
160     if (count != 0) { 
161       if (test==0) {
162         AliWarning("Histograms are booked for THIS specific Task, but they are all empty: setting flag to kWARNING");
163         test = 0.;  //upper limit value to set kWARNING flag for a task
164       }
165       else test = 1 ;
166     }
167   }
168
169   return test ; 
170 }  
171 //_________________________________________________________________
172 Double_t AliHMPIDQAChecker::CheckSim(TObjArray *listsim, TObjArray *listref) const
173 {
174   //
175   //  check on the HMPID RecPoints by using expo fit and Kolmogorov Test:
176   //
177
178    Float_t checkresponse = 0;
179
180    Float_t counter = 0 ;
181    TIter next(listsim) ;
182    TH1* histo;
183    while ( (histo = dynamic_cast<TH1 *>(next())) ) {
184      //PH The histogram should have at least 10 bins with at least 5 entries
185      Int_t nbinsabove = 0;
186      for (Int_t ibin=histo->FindBin(1); ibin<=histo->FindBin(50); ibin++) { 
187        if (histo->GetBinContent(ibin)>5) nbinsabove++;
188      }
189
190    if( nbinsabove < 10 ) counter++;
191    else {
192     TString h = histo->GetTitle();
193     if(h.Contains("Zoom")){
194     histo->Fit("expo","LQ0","",5,50);
195     if(histo->GetFunction("expo")->GetParameter(1) !=0 ) if(TMath::Abs((-1./(histo->GetFunction("expo"))->GetParameter(1)) - 35 ) > 5) counter++;
196     }
197     if(h.Contains("size  MIP"))   if(TMath::Abs(histo->GetMean()-5) > 2) counter++;
198     if(h.Contains("size  Phots")) if(TMath::Abs(histo->GetMean()-2) > 2) counter++;
199     if(h.Contains("distribution")) if(histo->KolmogorovTest((TH1F *)listref->At(0))<0.8) counter++;
200     AliDebug(AliQAv1::GetQADebugLevel(),Form(" Kolm. test : %f ",histo->KolmogorovTest((TH1F *)listref->At(0))));  
201    }
202   }
203  Float_t response = counter/(7.+7.+42.+42.); // 7.+7.+42 +42 = N checked histograms (-> To be replaced by listsim->GetEntries())
204  
205  if(response < 0.1) checkresponse = 0.7;      // <10% of the check histograms show a failing check -> Corresponds to kINFO see AliQACheckerBase::Run
206  else if(response < 0.5) checkresponse = 0.4; //  50%  of the check histograms show a failing check -> Corresponds to kWARNING see AliQACheckerBase::Run
207  else checkresponse = 0.001;                  // > 50% of the check histograms show a failing check -> Corresponds to kERROR see AliQACheckerBase::Run
208  return checkresponse;
209 }
210
211 //___________________________________________________________________________________________________
212 Double_t AliHMPIDQAChecker::CheckRec(TObjArray *listrec, TObjArray *listref) const
213 {
214   //
215   //  check on the HMPID RecPoints by using expo fit and Kolmogorov Test:
216   //
217
218    Float_t checkresponse = 0;
219
220    Float_t counter = 0 ;
221    TIter next(listrec) ;
222    TH1* histo;
223    while ( (histo = dynamic_cast<TH1 *>(next())) ) {
224      //PH The histogram should have at least 10 bins with at least 5 entries
225      Int_t nbinsabove = 0;
226      for (Int_t ibin=histo->FindBin(1); ibin<=histo->FindBin(50); ibin++) { 
227        if (histo->GetBinContent(ibin)>5) nbinsabove++;
228      }
229
230    if( nbinsabove < 10 ) counter++;
231    else {
232     TString h = histo->GetTitle();
233     if(h.Contains("Zoom")){
234     histo->Fit("expo","LQ0","",5,50);
235     if(histo->GetFunction("expo")->GetParameter(1) !=0 ) if(TMath::Abs((-1./(histo->GetFunction("expo"))->GetParameter(1)) - 35 ) > 5) counter++;
236     }
237     if(h.Contains("size  MIP"))   if(TMath::Abs(histo->GetMean()-5) > 2) counter++;
238     if(h.Contains("size  Phots")) if(TMath::Abs(histo->GetMean()-2) > 2) counter++;
239     if(h.Contains("distribution")) if(histo->KolmogorovTest((TH1F *)listref->At(0))<0.8) counter++;
240     AliDebug(AliQAv1::GetQADebugLevel(),Form(" Kolm. test : %f ",histo->KolmogorovTest((TH1F *)listref->At(0))));  
241    }
242   }
243  Float_t response = counter/(7.+7.+42.+42.); // 7.+7.+42 +42 = N checked histograms (-> To be replaced by listrec->GetEntries())
244  
245  if(response < 0.1) checkresponse = 0.7;      // <10% of the check histograms show a failing check -> Corresponds to kINFO see AliQACheckerBase::Run
246  else if(response < 0.5) checkresponse = 0.4; //  50%  of the check histograms show a failing check -> Corresponds to kWARNING see AliQACheckerBase::Run
247  else checkresponse = 0.001;                  // > 50% of the check histograms show a failing check -> Corresponds to kERROR see AliQACheckerBase::Run
248  return checkresponse;
249 }
250