Update of AliACORDEQAChecker class
[u/mrichter/AliRoot.git] / ACORDE / AliACORDEQAChecker.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 //  Checks the quality assurance for ACORDE. 
17 //  Default implementation
18 //  Authors:
19 //      Mario Rodriguez Cahuantzi <mrodrigu@mail.cern.ch> (FCFM-BUAP) 
20 //      Luciano Diaz Gonzalez <luciano.diaz@nucleares.unam.mx> (ICN-UNAM)
21 //      Arturo Fernandez <afernan@mail.cern.ch> (FCFM-BUAP)
22 //...
23
24 // --- ROOT system ---
25 #include <TClass.h>
26 #include <TH1F.h> 
27 #include <TH1I.h> 
28 #include <TIterator.h> 
29 #include <TKey.h> 
30 #include <TFile.h> 
31
32 // --- Standard library ---
33
34 // --- AliRoot header files ---
35 #include "AliLog.h"
36 #include "AliQAv1.h"
37 #include "AliQAChecker.h"
38 #include "AliACORDEQAChecker.h"
39 #include "AliCDBEntry.h"
40 #include "AliQAManager.h"
41
42 ClassImp(AliACORDEQAChecker)
43
44 //____________________________________________________________________________
45 Double_t * AliACORDEQAChecker::Check(AliQAv1::ALITASK_t /*index*/)
46 {
47   Double_t * rv = new Double_t[AliRecoParam::kNSpecies] ; 
48   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
49     rv[specie] = 0.0 ; 
50   return rv ;  
51 }
52
53 //__________________________________________________________________
54 Double_t * AliACORDEQAChecker::Check(AliQAv1::ALITASK_t /*index*/, TObjArray ** list)
55 {
56
57         Double_t * test = new Double_t[AliRecoParam::kNSpecies] ; 
58         Int_t * count   = new Int_t[AliRecoParam::kNSpecies] ; 
59         Double_t * acoTest = new Double_t[AliRecoParam::kNSpecies];
60  
61
62         // Look at the QAref data for ACORDE
63
64         char * acoOCDBDir = Form("ACORDE/%s/%s",AliQAv1::GetRefOCDBDirName(),AliQAv1::GetRefDataDirName());
65         AliCDBEntry *acoQARefDir = AliQAManager::QAManager()->Get(acoOCDBDir);
66
67         // Check variables set to 0
68
69         for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
70         {
71                 test[specie] = 0.0 ; 
72                 count[specie] = 0 ; 
73                 acoTest[specie] = 0.0;
74         }
75   
76         for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
77         {
78                 if (list[specie]->GetEntries() == 0)
79                 {  
80                         test[specie] = 1. ; // nothing to check
81                         acoTest[specie] = 1.;
82                 }
83                 else 
84                 {
85                         TIter next(list[specie]) ; 
86                         TH1 * hdata ;
87                         while ( (hdata = dynamic_cast<TH1 *>(next())) ) 
88                         {
89                                 if (hdata) 
90                                 { 
91                                         Double_t rv = 0.0 ; 
92                                         if(hdata->GetEntries()>0) rv=1; 
93                                         AliDebug(AliQAv1::GetQADebugLevel(), Form("%s -> %f", hdata->GetName(), rv)) ; 
94                                         count[specie]++ ; 
95                                         test[specie] += rv ; 
96                                         Double_t acoHitsNorm;
97                                         if (hdata->GetMaximum()==1) acoHitsNorm = 1;
98                                         else acoHitsNorm = (hdata->GetMaximum() - 0.50)/hdata->GetMaximum();
99                                         // here we implement the second version for ACORDEQAChecker
100                                         // by the moment we only compare the Mean between the QA histograms and the Reference data 
101                                         if  (acoQARefDir)
102                                         {
103                                                 //AliWarning("Using the QA Reference data for ACORDE !!!");
104                                                 Double_t acoHistChecked = CheckAcordeRefHits(list[specie],(TObjArray *)acoQARefDir->GetObject());
105                                                 if ( (acoHistChecked>0.75) && (acoHistChecked<=1) ) acoTest[specie] = 0.86;
106                                                 if ( (acoHistChecked>0.0020) && (acoHistChecked<=0.75) ) acoTest[specie] = 0.251;
107                                                 if ( (acoHistChecked>0.0) && (acoHistChecked<=0.0020) ) acoTest[specie] = 0.0010;
108                                                 if ( (acoHistChecked>-1.0) && (acoHistChecked<=0.0) ) acoTest[specie] = -0.5;
109         
110                                         }else
111                                         {
112                                                 //AliWarning("Using the inner ACORDE QA Checker !!!");
113                                                 if ( (acoHitsNorm>0.40) && (acoHitsNorm<=1) ) acoTest[specie] = 0.86;
114                                                 if ( (acoHitsNorm>0.0020) && (acoHitsNorm<=0.40) ) acoTest[specie] = 0.251;
115                                                 if ( (acoHitsNorm>0.0) && (acoHitsNorm<=0.0020) ) acoTest[specie] = 0.0010;
116                                                 if ( (acoHitsNorm>-1.0) && (acoHitsNorm<=0.0) ) acoTest[specie] = -0.5;
117                                         }
118                                 }
119                                 else
120                                 {
121                                         AliError("Data type cannot be processed") ;
122                                 }
123                         }
124                         if (count[specie] != 0) 
125                         { 
126                                 if (test[specie]==0) 
127                                 {
128                                         test[specie] = 0.5;  //upper limit value to set kWARNING flag for a task
129                                 }
130                                 else 
131                                 {
132                                         if (acoQARefDir) test[specie] = acoTest[specie];
133                                         else
134                                         {
135                                                 test[specie] = acoTest[specie];
136                                         }
137                                 }
138                         }
139                 }
140         }
141         return test ; 
142 }
143 Double_t AliACORDEQAChecker::CheckAcordeRefHits(TObjArray *HistAcordeList, TObjArray *AcordeRef) const
144 {
145         Double_t acordeTest = 0;
146         TIter next(AcordeRef);
147         TIter next1(HistAcordeList);
148         TH1 *histoAcordeRef;
149         TH1 *histoAcorde;
150         Float_t acordeHistoQAMaker=0;
151         Float_t meanACOQAReference=0;
152         Float_t meanACOQAMaker=0;
153         Float_t test1ACORDE = 0;
154         while((histoAcordeRef=(TH1*)next()) && (histoAcorde=(TH1*)next1())) 
155         {
156                 for(Int_t i=0;i<60;i++) acordeHistoQAMaker=acordeHistoQAMaker + histoAcorde->GetBinContent(i)/histoAcorde->GetMaximum();
157                 meanACOQAReference = histoAcordeRef->GetMean();
158                 meanACOQAMaker = acordeHistoQAMaker/60;
159                 test1ACORDE = TMath::Abs(meanACOQAReference-meanACOQAMaker);
160                 if (test1ACORDE<0.45) acordeTest = 0.86;
161                 if (test1ACORDE > 0.45) acordeTest = 0.50;
162                 if (test1ACORDE > 0.70) acordeTest = 0.25;
163         }
164         return acordeTest;
165 }