]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALQAChecker.cxx
Add possbility to read also the RecPoints
[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
23 For the moment we only implement the checking of raw data QA
24 by looking at the average at the each tower.
25 We count the times of the response for each tower, the propability for all towers should be the same (given value)
26 depending on that value, the resulting QA flag is info, warning, error or fatal.
27 Also we check the percentage of towers inside the average for each SM
28
29
30 -- Yaxian Mao, CCNU/CERN/LPSC
31 */
32
94594e5d 33
34// --- ROOT system ---
35#include <TClass.h>
9e47432c 36#include <TH1.h>
37#include <TF1.h>
94594e5d 38#include <TH1I.h>
39#include <TIterator.h>
40#include <TKey.h>
41#include <TFile.h>
9e47432c 42#include <TLine.h>
43#include <TPaveText.h>
44#include <TMath.h>
94594e5d 45
46// --- Standard library ---
47
48// --- AliRoot header files ---
49#include "AliLog.h"
4e25ac79 50#include "AliQAv1.h"
94594e5d 51#include "AliQAChecker.h"
52#include "AliEMCALQAChecker.h"
9e47432c 53#include "AliEMCALQADataMakerRec.h"
94594e5d 54
55ClassImp(AliEMCALQAChecker)
56
9e47432c 57//__________________________________________________________________
58AliEMCALQAChecker::AliEMCALQAChecker() :
59AliQACheckerBase("EMCAL","EMCAL Quality Assurance Data Maker"),
60fLine(new TLine*[fknSM]),
61fHref(new TLine*[fknSM]),
62fText(NULL)
63{
64 /// ctor
65 for (Int_t sm = 0 ; sm < fknSM ; sm++){
66 fLine[sm] = NULL ;
67 fHref[sm] = NULL ;
68 }
69}
70
71//__________________________________________________________________
72AliEMCALQAChecker::~AliEMCALQAChecker()
73{
74 /// dtor
75 delete [] fLine ;
76 delete [] fHref ;
77 if (fText)
78 delete fText ;
79}
80
81//__________________________________________________________________
82AliEMCALQAChecker::AliEMCALQAChecker(const AliEMCALQAChecker& qac) :
83AliQACheckerBase(qac.GetName(), qac.GetTitle()),
84fLine(new TLine*[fknSM]),
85fHref(new TLine*[fknSM]),
86fText(qac.fText)
87{
88 /// copy ctor
89 for (Int_t sm = 0 ; sm < fknSM ; sm++){
90 fLine[sm] = qac.fLine[sm] ;
91 fHref[sm] = qac.fHref[sm] ;
92 }
93}
94//__________________________________________________________________
95AliEMCALQAChecker& AliEMCALQAChecker::operator = (const AliEMCALQAChecker &qac)
96{
97 fText = qac.fText;
98
99 for (Int_t sm = 0 ; sm < fknSM ; sm++){
100 fLine[sm] = qac.fLine[sm] ;
101 fHref[sm] = qac.fHref[sm] ;
102 }
103 return *this ;
104}
105
106//______________________________________________________________________________
107Double_t *
108AliEMCALQAChecker::Check(AliQAv1::ALITASK_t index, TObjArray ** list, AliDetectorRecoParam * /*recoParam*/)
109{
110 /// Check objects in list
111
112 if ( index == AliQAv1::kRAW )
113 {
114 return CheckRaws(list);
115 printf ("checkers for task %d \n", index) ;
116 }
117
118 if ( index == AliQAv1::kREC)
119 {
120 return CheckRecPoints(list);
121 }
122
123 if ( index == AliQAv1::kESD )
124 {
125 return CheckESD(list);
126 }
127 AliWarning(Form("Checker for task %d not implement for the moment",index));
128 return NULL;
129}
130
131//______________________________________________________________________________
132TH1*
133AliEMCALQAChecker::GetHisto(TObjArray* list, const char* hname, Int_t specie) const
134{
135 /// Get a given histo from the list
136 TH1* h = static_cast<TH1*>(list->FindObject(Form("%s_%s",AliRecoParam::GetEventSpecieName(specie),hname)));
137 if (!h)
138 {
139 AliError(Form("Did not find expected histo %s",hname));
140 }
141 return h;
142}
143
144//______________________________________________________________________________
145Double_t
146AliEMCALQAChecker::MarkHisto(TH1& histo, Double_t value) const
147{
148 /// Mark histo as originator of some QA error/warning
149
150 if ( value != 1.0 )
151 {
152 histo.SetBit(AliQAv1::GetQABit());
153 }
154
155 return value;
156}
157
158
159//______________________________________________________________________________
160Double_t *
161AliEMCALQAChecker::CheckRaws(TObjArray ** list)
162{
163 /// Check raws
164
165 Float_t kThreshold = 80. ;
166
167 Double_t * test = new Double_t[AliRecoParam::kNSpecies] ;
168 for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
169 test[specie] = 1.0 ;
170 if ( !AliQAv1::Instance()->IsEventSpecieSet(specie))
171 continue ;
172 if (list[specie]->GetEntries() == 0)
173 test[specie] = 0. ; // nothing to check
174 else {
175 TH1 * hdata = (TH1*)list[specie]->At(kTowerHG) ;
176 if(hdata->GetEntries()==0)
177 continue;
178 Int_t nbin = hdata->GetNbinsX() ;
179 Int_t nTower = nbin/4 ;
180 if(fText) {
181 fText->DeleteText() ;
182 fText->Clear() ;
183 }
184 else {
185 fText = new TPaveText(0.3,0.6,0.7,0.9,"NDC") ;
186 }
187 fText->AddText(Form("OK if more than %2.2f %% inside aver-sigma < HG counts < aver+sigma", kThreshold));
188 //TPaveText * fText[fknSM] = {0};
189 Double_t rv = 0. ;
190 for(Int_t iSM = 0 ; iSM < fknSM ; iSM++){
191 TString projname = Form("proj_%d",iSM);
192 Double_t aver = 0. ;
193 Double_t recal = 0 ;
194 Double_t init = 0. ;
195 Double_t mean = 0. ;
196 Double_t width = 0. ;
197 Int_t flag = 0 ;
198 Double_t ratio = 0. ;
199 TH1F * proj = NULL ;
200 for(Int_t iTower = iSM*nTower ; iTower<(iSM+1)*nTower ; iTower++){
201 aver += hdata->GetBinContent(iTower);
202 //printf("Tower: %d has counts = %f\n",iTower, hdata->GetBinContent(iTower));
203 }
204 aver /=nTower;
205 AliInfo(Form("SM: %d has average = %f\n",iSM, aver));
206 Double_t ymin = hdata->GetBinContent(hdata->GetMinimumBin());
207 Double_t ymax = hdata->GetBinContent(hdata->GetMaximumBin());
208 proj = new TH1F(projname,projname,nbin,-aver,aver);
209
210 fLine[iSM] = dynamic_cast<TLine*>(hdata->GetListOfFunctions()->FindObject(fLine[iSM]));
211 if (!fLine[iSM]) {
212 fLine[iSM] = new TLine((iSM+1)*nTower,ymin,(iSM+1)*nTower,ymax);
213 fLine[iSM]->SetLineColor(1);
214 fLine[iSM]->SetLineWidth(2);
215 hdata->GetListOfFunctions()->Add(fLine[iSM]);
216 list[specie]->AddAt(hdata, kTowerHG) ;
217 }
218 else {
219 fLine[iSM]->SetX1((iSM+1)*nTower) ;
220 fLine[iSM]->SetY1(ymin) ;
221 fLine[iSM]->SetX2((iSM+1)*nTower) ;
222 fLine[iSM]->SetY2(ymax) ;
223 }
224
225 //Double_t size = 0.24 ;
226 //fText[iSM] = new TPaveText(0.1+size*iSM,0.7,size*(iSM+1),0.9,"NDC");
227 for(Int_t iTower = iSM*nTower ; iTower<(iSM+1)*nTower ; iTower++){
228 proj->Fill(hdata->GetBinContent(iTower)-aver);
229 }
230 proj->Fit("gaus","","QNO");
231 mean=proj->GetFunction("gaus")->GetParameter(1);
232 width=proj->GetFunction("gaus")->GetParameter(2);
233 AliInfo(Form("aver = %f, mean = %f, sigma =%f\n",aver,mean, width));
234 //if mean or sigma is too huge from the fitting, fitting failed
235 if(aver < 0 || width/aver >2.) flag = -1 ;
236 else { //recalculate the average if the fitting didn't give the initial average
237 aver+=mean;
238 init=TMath::Abs(mean/aver);
239 while(init>0.01){
240 if(flag) flag = 0 ;
241 for(Int_t iTower = iSM*nTower ; iTower < (iSM+1)*nTower ; iTower++){
242 if(hdata->GetBinContent(iTower)>(aver-width) && hdata->GetBinContent(iTower)<(aver+width)){
243 flag++ ;
244 recal += hdata->GetBinContent(iTower);
245 }
246 }
247 recal/=flag;
248 aver =(aver+recal)/2 ;
249 init=(aver-recal)/(aver+recal) ;
250 } //recalculate the average
251 if(flag)ratio=100.0*flag/nTower ; //counting how many towers used for average recalculation
252 rv+=TMath::Abs((aver-recal)/(aver+recal)) ;
253 AliInfo(Form("SM %d has %2.2f %% chanhel works \n", iSM, ratio));
254 }
255 fHref[iSM] = dynamic_cast<TLine*>(hdata->GetListOfFunctions()->FindObject(fHref[iSM]));
256 if(!fHref[iSM]) {
257 fHref[iSM] = new TLine(iSM*nTower,aver,(iSM+1)*nTower,aver);
258 hdata->GetListOfFunctions()->Add(fHref[iSM]);
259 list[specie]->AddAt(hdata, kTowerHG) ;
260 }
261 else {
262 fHref[iSM]->Clear() ;
263 fHref[iSM]->SetX1(iSM*nTower) ;
264 fHref[iSM]->SetY1(aver) ;
265 fHref[iSM]->SetX2((iSM+1)*nTower) ;
266 fHref[iSM]->SetY2(aver) ;
267 }
268 hdata->Paint() ;
269 if(ratio<= kThreshold && flag >0){ //if towers used for average recalculation smaller than 10%, then the problem on this SM
270 //fText->SetFillColor(2);
271 fHref[iSM]->SetLineColor(2);
272 fHref[iSM]->SetLineWidth(2);
273 fText->SetFillColor(2);
274 fText->AddText(Form("SM %d: NOK = %2.0f %% channels OK!!!",iSM,ratio));
275 //fText[iSM]->AddText(Form("SM %d NOT OK, only %5.2f %% works!!!",iSM,flag/nTower));
276 }
277 else if (flag == -1 || flag == 0 || ratio == 0.) {
278 fText->SetFillColor(2);
279 fHref[iSM]->SetLineColor(2);
280 fHref[iSM]->SetLineWidth(2);
281 fText->SetFillColor(2);
282 fText->AddText(Form("SM %d: NOK Fitting failed",iSM,ratio));
283 //fText[iSM]->AddText(Form("SM %d has %5.2f %% towers wok normally",iSM,flag/nTower));
284 } else {
285 fText->SetFillColor(3);
286 fHref[iSM]->SetLineColor(3);
287 fHref[iSM]->SetLineWidth(2);
288 fText->AddText(Form("SM %d: OK = %2.0f %% channels OK",iSM,ratio));
289 //fText[iSM]->AddText(Form("SM %d has %5.2f %% towers wok normally",iSM,flag/nTower));
290 }
291 hdata->Paint() ;
292 //hdata->GetListOfFunctions()->Add(fText[iSM]);
293 delete proj ;
294 }
295 rv/=fknSM;
296 hdata->GetListOfFunctions()->Add(fText);
297 hdata->Paint() ;
298 if ( rv <=0.1 )
299 {
300 AliInfo(Form("Got a small deviation rv = %f from average, SM works fine",rv));
301 test[specie] = 0.05;
302 }
303
304 if ( rv <=0.5 && rv >0.1 )
305 {
306 AliWarning(Form("Got a deviation rv = %f from average, be careful!",rv));
307 test[specie] = 0.3;
308 }
309
310 if ( rv <=0.5 && rv >0.8 )
311 {
312 AliError(Form("Got a large deviation of %f from average for SMs!!!",rv));
313 test[specie] = 0.7;
314 }
315 if ( rv >0.8 )
316 {
317 AliError(Form("Got too large deviation of %f from average !!!???",rv));
318 test[specie] = 0.9;
319 }
320 }
321
322 }
323 return test ;
324}
325
326//______________________________________________________________________________
327void AliEMCALQAChecker::Init(const AliQAv1::DETECTORINDEX_t det)
328{
329 /// intialises QA and QA checker settings
330 AliQAv1::Instance(det) ;
331 Float_t hiValue[AliQAv1::kNBIT] ;
332 Float_t lowValue[AliQAv1::kNBIT] ;
333 lowValue[AliQAv1::kINFO] = 0.0 ;
334 hiValue[AliQAv1::kINFO] = 0.1 ;
335 hiValue[AliQAv1::kWARNING] = 0.5;
336 lowValue[AliQAv1::kWARNING] = 0.1 ;
337 lowValue[AliQAv1::kERROR] = 0.5 ;
338 hiValue[AliQAv1::kERROR] = 0.8 ;
339 lowValue[AliQAv1::kFATAL] = 0.8 ;
340 hiValue[AliQAv1::kFATAL] = 1.0 ;
341 SetHiLo(&hiValue[0], &lowValue[0]) ;
342}
94594e5d 343