attempt to address new coverity reports for AliCalo stuff and QA checker
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALQAChecker.cxx
CommitLineData
94594e5d 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 Checks the quality assurance.
18 By comparing with reference data
19
20 Based on PHOS code written by
21 Y. Schutz CERN July 2007
9e47432c 22
a2655076 23 For the moment we only implement the checking of raw data QA.
24 The checked for ESD and RecPoints will be implemented later.
9e47432c 25
26
9e47432c 27 */
28
94594e5d 29
30// --- ROOT system ---
31#include <TClass.h>
9e47432c 32#include <TH1.h>
33#include <TF1.h>
94594e5d 34#include <TH1I.h>
38986b78 35#include <TH2F.h>
94594e5d 36#include <TIterator.h>
37#include <TKey.h>
38#include <TFile.h>
9e47432c 39#include <TLine.h>
38986b78 40#include <TText.h>
9e47432c 41#include <TPaveText.h>
42#include <TMath.h>
94594e5d 43
44// --- Standard library ---
45
46// --- AliRoot header files ---
47#include "AliLog.h"
4e25ac79 48#include "AliQAv1.h"
94594e5d 49#include "AliQAChecker.h"
50#include "AliEMCALQAChecker.h"
51
52ClassImp(AliEMCALQAChecker)
53
9e47432c 54//__________________________________________________________________
55AliEMCALQAChecker::AliEMCALQAChecker() :
56AliQACheckerBase("EMCAL","EMCAL Quality Assurance Data Maker"),
38986b78 57fTextSM(new TText*[fknSM]),
8a38cd34 58fLineCol(new TLine(47.5,-0.5,47.5,119.5)),
00957c37 59fText(new TPaveText(0.2,0.7,0.8,0.9,"NDC"))
9e47432c 60{
38986b78 61 // ctor
62 fLineCol->SetLineColor(1);
63 fLineCol->SetLineWidth(2);
38986b78 64
65 fTextSM[0]= new TText(20, 12, "SM A0");
8a38cd34 66 fTextSM[1]= new TText(20, 36, "SM A1");
67 fTextSM[2]= new TText(20, 60, "SM A2");
68 fTextSM[3]= new TText(20, 84, "SM A3");
69 fTextSM[4]= new TText(20, 108,"SM A4");
70
71 fTextSM[5]= new TText(64, 12, "SM C0");
72 fTextSM[6]= new TText(64, 36, "SM C1");
73 fTextSM[7]= new TText(64, 60, "SM C2");
74 fTextSM[8]= new TText(64, 84, "SM C3");
75 fTextSM[9]= new TText(64, 108,"SM C4");
76
77 for(int i = 0; i < 4; i++) {
78 fLineRow[i] = new TLine(-0.5,23.5+(24*i),95.5,23.5+(24*i));
79 fLineRow[i]->SetLineColor(1);
80 fLineRow[i]->SetLineWidth(2);
81 }
82
83
9e47432c 84}
85
86//__________________________________________________________________
87AliEMCALQAChecker::~AliEMCALQAChecker()
88{
89 /// dtor
38986b78 90 delete [] fTextSM ;
a42ceb0e 91 delete fLineCol ;
b08d5260 92 for (Int_t i=0; i<4; ++i) delete fLineRow[i] ;
a42ceb0e 93 delete fText ;
9e47432c 94}
95
96//__________________________________________________________________
97AliEMCALQAChecker::AliEMCALQAChecker(const AliEMCALQAChecker& qac) :
98AliQACheckerBase(qac.GetName(), qac.GetTitle()),
38986b78 99fTextSM(new TText*[fknSM]) ,
100fLineCol(static_cast<TLine*>(qac.fLineCol->Clone())) ,
00957c37 101fText(new TPaveText(0.2,0.7,0.8,0.9,"NDC"))
9e47432c 102{
38986b78 103 // copy ctor
9e47432c 104 for (Int_t sm = 0 ; sm < fknSM ; sm++){
38986b78 105 fTextSM[sm] = static_cast<TText *>(qac.fTextSM[sm]->Clone()) ;
9e47432c 106 }
8a38cd34 107 for(Int_t i = 0 ; i < 4 ; i++) {
a42ceb0e 108
8a38cd34 109 fLineRow[i] = static_cast<TLine*>(qac.fLineRow[i]->Clone()) ;
110 }
9e47432c 111}
112//__________________________________________________________________
38986b78 113AliEMCALQAChecker& AliEMCALQAChecker::operator = (const AliEMCALQAChecker &qac)
9e47432c 114{
9ae19208 115 AliQACheckerBase(qac.GetName(), qac.GetTitle());
38986b78 116 fTextSM = new TText*[fknSM] ;
117 fLineCol = static_cast<TLine*>(qac.fLineCol->Clone()) ;
00957c37 118 fText = new TPaveText(0.2,0.7,0.8,0.9,"NDC") ;
9e47432c 119 for (Int_t sm = 0 ; sm < fknSM ; sm++){
38986b78 120 fTextSM[sm] = static_cast<TText *>(qac.fTextSM[sm]->Clone()) ;
9e47432c 121 }
8a38cd34 122 for(Int_t i = 0; i < 4; i++) {
123
124 fLineRow[i] = static_cast<TLine*>(qac.fLineRow[i]->Clone()) ;
125 }
9e47432c 126 return *this ;
127}
128
129//______________________________________________________________________________
a42ceb0e 130void AliEMCALQAChecker::Check(Double_t * test, AliQAv1::ALITASK_t index, TObjArray ** list, const AliDetectorRecoParam * /*recoParam*/)
9e47432c 131{
132 /// Check objects in list
133
134 if ( index == AliQAv1::kRAW )
135 {
a42ceb0e 136 CheckRaws(test, list);
9e47432c 137 printf ("checkers for task %d \n", index) ;
138 }
139
140 if ( index == AliQAv1::kREC)
141 {
a42ceb0e 142 CheckRecPoints(test, list);
9e47432c 143 }
144
145 if ( index == AliQAv1::kESD )
146 {
a42ceb0e 147 CheckESD(test, list);
9e47432c 148 }
149 AliWarning(Form("Checker for task %d not implement for the moment",index));
9e47432c 150}
151
152//______________________________________________________________________________
153TH1*
154AliEMCALQAChecker::GetHisto(TObjArray* list, const char* hname, Int_t specie) const
155{
156 /// Get a given histo from the list
157 TH1* h = static_cast<TH1*>(list->FindObject(Form("%s_%s",AliRecoParam::GetEventSpecieName(specie),hname)));
158 if (!h)
159 {
160 AliError(Form("Did not find expected histo %s",hname));
161 }
162 return h;
163}
164
165//______________________________________________________________________________
166Double_t
167AliEMCALQAChecker::MarkHisto(TH1& histo, Double_t value) const
168{
169 /// Mark histo as originator of some QA error/warning
170
171 if ( value != 1.0 )
172 {
173 histo.SetBit(AliQAv1::GetQABit());
174 }
175
176 return value;
177}
178
179
180//______________________________________________________________________________
a42ceb0e 181void AliEMCALQAChecker::CheckRaws(Double_t * test, TObjArray ** list)
9e47432c 182{
f05c8877 183 // Check RAW QA histograms
184 // -- Yaxian Mao, CCNU/CERN/LPSC
185 //adding new checking method: 25/04/2010, Yaxian Mao
186 //Comparing the amplitude from current run to the reference run, if the ratio in the range [0.8, .12], count as a good tower.
187 //If more than 90% towers are good, EMCAL works fine, otherwise experts should be contacted.
6a754398 188
38986b78 189
190 //Float_t kThreshold = 80. ;
191 Int_t nTowersPerSM = 24*48; // number of towers in a SuperModule; 24x48
192 Double_t nTot = fknSM * nTowersPerSM ;
180c431b 193 TList *lstF = 0;
a2655076 194 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
a42ceb0e 195 test[specie] = 0.0 ;
a2655076 196 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
197 continue ;
198 if (list[specie]->GetEntries() == 0)
a42ceb0e 199 test[specie] = 0. ; // nothing to check
a2655076 200 else {
38986b78 201 TH2F * hdata = (TH2F*)list[specie]->At(k2DRatioAmp) ;
202 TH1F * ratio = (TH1F*)list[specie]->At(kRatioDist) ;
203 if(hdata->GetEntries()==0 || ratio->GetEntries()==0)
204 continue;
205 //adding the lines to distinguish different SMs
180c431b 206 lstF = hdata->GetListOfFunctions();
207 { // RS: clean list of functions
208 if (lstF) {
209 TObject *stats = lstF->FindObject("stats"); lstF->Remove(stats);
210 TObject *obj;
211 while ((obj = lstF->First())) { while(lstF->Remove(obj)) { } delete obj; }
212 if (stats) lstF->Add(stats);
9ae19208 213 }
214 else {
215 AliWarning(Form("Checker : empty list of data functions; returning"));
216 return;
217 }
f05c8877 218 }
180c431b 219 lstF->Add(fLineCol->Clone());
220 for(Int_t iLine = 0; iLine < 4; iLine++) {
221 lstF->Add(fLineRow[iLine]->Clone());
222 }
223 //Now adding the text to for each SM
224 for(Int_t iSM = 0 ; iSM < fknSM ; iSM++){ //number of SMs loop start
225 lstF->Add(fTextSM[iSM]->Clone());
226 }
227 //
228 lstF = ratio->GetListOfFunctions();
229 { // RS: clean list of functions
230 if (lstF) {
231 TObject *stats = lstF->FindObject("stats"); lstF->Remove(stats);
232 TObject *obj;
233 while ((obj = lstF->First())) { while(lstF->Remove(obj)) { } delete obj; }
234 if (stats) lstF->Add(stats);
9ae19208 235 }
236 else {
237 AliWarning(Form("Checker : empty list of ratio functions; returning"));
238 return;
180c431b 239 }
240 }
241 lstF->Add(fText->Clone()) ;
242 //
38986b78 243 //now check the ratio histogram
244 Double_t binContent = 0. ;
245 Int_t NGoodTower = 0 ;
f05c8877 246 Double_t rv = 0. ;
38986b78 247 for(Int_t ix = 1; ix <= hdata->GetNbinsX(); ix++) {
248 for(Int_t iy = 1; iy <= hdata->GetNbinsY(); iy++) {
249 binContent = hdata->GetBinContent(ix, iy) ;
250 if (binContent < 1.2 && binContent > 0.8)
251 NGoodTower++ ;
6a754398 252 }
6a754398 253 }
38986b78 254 rv = NGoodTower/nTot ;
f05c8877 255 printf("%2.2f %% towers out of range [0.8, 1.2]\n", (1-rv)*100);
256 if(fText){
f05c8877 257 fText->Clear() ;
7e1d9a9b 258
259 fText->AddText(Form("%2.2f %% towers out of range [0.8, 1.2]", (1-rv)*100));
260 if (rv < 0.9) {
261 test[specie] = 0.9 ;
262 // 2 lines text info for quality
263 fText->SetFillColor(2) ;
264 fText->AddText(Form("EMCAL = NOK, CALL EXPERTS!!!"));
265 }
266 else {
267 test[specie] = 0.1 ;
268 fText->SetFillColor(3) ;
269 fText->AddText(Form("EMCAL = OK, ENJOY..."));
270 }
271 //hdata->Reset("ICE");
272 //ratio->Reset("ICE");
273 }//fText
180c431b 274 }
275 } //finish the checking
9e47432c 276}
277
278//______________________________________________________________________________
279void AliEMCALQAChecker::Init(const AliQAv1::DETECTORINDEX_t det)
280{
281 /// intialises QA and QA checker settings
282 AliQAv1::Instance(det) ;
283 Float_t hiValue[AliQAv1::kNBIT] ;
284 Float_t lowValue[AliQAv1::kNBIT] ;
285 lowValue[AliQAv1::kINFO] = 0.0 ;
286 hiValue[AliQAv1::kINFO] = 0.1 ;
9e47432c 287 lowValue[AliQAv1::kWARNING] = 0.1 ;
6a754398 288 hiValue[AliQAv1::kWARNING] = 0.5 ;
9e47432c 289 lowValue[AliQAv1::kERROR] = 0.5 ;
290 hiValue[AliQAv1::kERROR] = 0.8 ;
291 lowValue[AliQAv1::kFATAL] = 0.8 ;
292 hiValue[AliQAv1::kFATAL] = 1.0 ;
293 SetHiLo(&hiValue[0], &lowValue[0]) ;
294}
94594e5d 295