Bug #92237 fixed as Barth suggested
[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 //  Last update: Nov. 14t 2009 --> MRC <mrodrigu@mail.cern.ch> (FCFM-BUAP) 
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 #include <TPaveText.h>
33 #include <TLine.h>
34 // --- Standard library ---
35
36 // --- AliRoot header files ---
37 #include "AliLog.h"
38 #include "AliQAv1.h"
39 #include "AliQAChecker.h"
40 #include "AliACORDEQAChecker.h"
41 #include "AliCDBEntry.h"
42 #include "AliQAManager.h"
43
44 /*************************************************************************
45    Last update: Oct. 10th 2011 from Mario RC, <mrodrigu@mail.cern.ch>
46         |-> Adding the checker class for raw and esd index
47         |-> Setting the threshold lines and box for DQM shifter
48
49 *************************************************************************/
50
51 ClassImp(AliACORDEQAChecker)
52
53 //____________________________________________________________________________
54
55 AliACORDEQAChecker::AliACORDEQAChecker()  :
56 AliQACheckerBase("ACORDE","ACORDE Quality Assurance Data Maker"),
57 fTextDQMShifterInfo(new TPaveText(2.2,45,2.9,50,"T")),
58 fMax(new TLine(1,30,3,30))
59 {
60         // default constructor
61         fMax->SetLineColor(kGreen);
62         fMax->SetLineWidth(3);
63 }
64 //____________________________________________________________________________
65 AliACORDEQAChecker::~AliACORDEQAChecker()
66 {
67         // destructor
68         delete fTextDQMShifterInfo;
69         delete fMax;
70 }
71 //____________________________________________________________________________
72 AliACORDEQAChecker::AliACORDEQAChecker(const AliACORDEQAChecker& qac) :
73 AliQACheckerBase(qac.GetName(), qac.GetTitle()),
74 fTextDQMShifterInfo(new TPaveText(2.2,45,2.9,50,"T")),
75 fMax(static_cast<TLine*>(qac.fMax->Clone()))
76 {
77         //
78 }
79 //____________________________________________________________________________
80 AliACORDEQAChecker& AliACORDEQAChecker::operator = (const AliACORDEQAChecker &qac)
81 {
82         // use cpy option from constructor
83         if (&qac==this) return *this;
84         new (this) AliACORDEQAChecker(qac);
85         return *this;
86 }
87 //____________________________________________________________________________
88 void AliACORDEQAChecker::Check(Double_t * test, AliQAv1::ALITASK_t /*index*/)
89 {
90   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
91     test[specie] = 0.0 ; 
92 }
93 //____________________________________________________________________________
94 void AliACORDEQAChecker::Check(Double_t * test, AliQAv1::ALITASK_t /*index*/, TObjArray ** list, const AliDetectorRecoParam * /*recoParam*/)
95 {
96 // Close version to the final one for the ACORDE QA Checker
97   
98 // Loop over the run species (for specie!= cosmic by now we set QA to INFO) 
99   
100   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
101   {
102         if ( !AliQAv1::Instance()->IsEventSpecieSet(specie) ) continue ; 
103         if (list[specie]->GetEntries() == 0) test[specie] = 1.; // Nothing to check
104         else 
105         {
106                 TIter next(list[specie]) ; 
107                 TH1 * hdata ; // Data created by the AliACORDEQADataMakerXXX (Sim/Rec)
108                 while ( (hdata = dynamic_cast<TH1 *>(next())) ) 
109                 {
110                         if (hdata) 
111                         { 
112                                 Double_t rv = 0.0 ; 
113                                 if(hdata->GetEntries()>0) rv=1; 
114                                 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s -> %f", hdata->GetName(), rv)) ; 
115                                 TString hdataName = hdata->GetName();
116                                 //if (hdata->GetListOfFunctions()->GetEntries() == 0) continue;  
117                                 if (hdataName.Contains("fhACORDEStatusAMU_DQM")){
118                                         if (!hdata->GetListOfFunctions()->Contains(fTextDQMShifterInfo))
119                                                 hdata->GetListOfFunctions()->Add(fTextDQMShifterInfo);
120                                         if (!hdata->GetListOfFunctions()->Contains(fMax))
121                                                 hdata->GetListOfFunctions()->Add(fMax);
122
123                                 }
124                                 // Here we use the QAref ACORDE data from fRefOCDBSubDir
125                                 
126                                 if ( (fRefOCDBSubDir[specie]) && (hdataName.Contains("ACORDEBitPattern")) ) 
127                                 {
128                                         TH1 * href = NULL;
129                                         if (fRefSubDir) href = static_cast<TH1*>(fRefSubDir->Get(hdata->GetName()));
130                                         else if (fRefOCDBSubDir[specie]) href = static_cast<TH1*>(fRefOCDBSubDir[specie]->FindObject(hdata->GetName()));
131                                         test[specie] = CheckAcordeRefHits(href,hdata);
132                                 }else if (hdataName.Contains("ACORDEBitPattern")||hdataName.Contains("fhACORDEStatusAMU_DQM"))
133                                 // Here we use an inner QA Checher without the QAref data
134                                 {
135                                         Float_t acoDataMax = hdata->GetMaximum();
136                                         Int_t flagAcoQAChecker = 0;
137                                         if (acoDataMax == 0) continue;
138                                         for(Int_t i=0;i<60;i++)
139                                         {
140                                                 if ((hdata->GetBinContent(i)/acoDataMax) < 0.75) flagAcoQAChecker++; 
141                                         //      if (hdataName.Contains("fhACORDEStatusSL0_DQM")||hdataName.Contains("fhACORDEStatusAMU_DQM")){
142                                         //              if (hdata->GetBinContent(i)<0.29) flagAcoQA++;
143                                         //      }
144                                         }
145                                         if (hdataName.Contains("ACORDEBitPattern")){
146                                                 Double_t simpleFlag = 1.-flagAcoQAChecker/60.;
147                                                 if ( (simpleFlag >= 0.90) && (simpleFlag <= 1.0) ) test[specie] = 0.75; // INFO
148                                                 if ( (simpleFlag >= 0.70) && (simpleFlag < 0.90) ) test[specie] = 0.50; // WARNING
149                                                 if ( (simpleFlag >= 0.25) && (simpleFlag < 0.70) ) test[specie] = 0.25; // ERROR
150                                                 if ( (simpleFlag >= 0.0) && (simpleFlag < 0.25) )  test[specie] = -1.0; // FATAL
151                                         }
152                                         /*if (hdataName.Contains("fhACORDEStatusSL0_DQM"))
153                                         {
154                                                 if (hdata->GetBinContent(1) != 0) 
155                                                 {
156                                                         if (hdata->GetBinContent(2) < 31)
157                                                         test[specie] = 0.75;
158                                                         else test[specie] = 0.3;
159                                                 } else continue;
160                                         }*/
161                                         if (hdataName.Contains("fhACORDEStatusAMU_DQM"))
162                                         {
163                                                 if (hdata->GetBinContent(1) != 0) 
164                                                 {
165                                                         if (hdata->GetBinContent(2) < 31)
166                                                         test[specie] = 0.75;
167                                                         else test[specie] = 0.3;
168                                                 } else continue;
169                                         }
170
171                                 }       
172
173                                 // Setting Warning message for possible Empty Events with the ACORDE-Trigger
174                                         
175                                 if (hdataName.Contains("ACORDEMultiplicity") && (hdata->GetBinContent(0)!=0)) AliWarning("Empty event registered with ACORDE Trigger !!!");
176                                         
177                                 
178                         }else AliError("Data type cannot be processed") ;
179                         if (fTextDQMShifterInfo)
180                         {
181                                 fTextDQMShifterInfo->Clear();
182                                 if (test[specie] > 0.3){
183                                         fTextDQMShifterInfo->SetFillColor(kGreen);
184                                         fTextDQMShifterInfo->AddText("ACORDE: O.K.");
185                                 }else{
186                                         fTextDQMShifterInfo->SetFillColor(kRed);
187                                         fTextDQMShifterInfo->AddText("ACORDE: Not, O.K.");
188                                 }
189                         }
190                                 
191                 }
192         }
193     if ( (specie == AliRecoParam::kHighMult) || (specie == AliRecoParam::kLowMult) || (specie == AliRecoParam::kCalib) ) test[specie] = 0.75;
194   }
195 }
196 //____________________________________________________________________________
197 Double_t AliACORDEQAChecker::CheckAcordeRefHits(const TH1 * href, const TH1 * hdata) const
198 {
199         Double_t test = 0.;
200         Int_t flag=0;
201         for (Int_t i=0;i<60;i++)
202         {
203                 if (TMath::Abs(href->GetBinContent(i)-hdata->GetBinContent(i))>10) flag++;
204         }
205         if ((flag>50)&&(flag<=60)) test = -1.;
206         if ((flag>30)&&(flag<=50)) test = 0.25;
207         if ((flag>10)&&(flag<=30)) test = 0.5;
208         if ((flag>0)&&(flag<=10)) test = 0.75;
209         return test;
210 }