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