]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALQAChecker.cxx
e455d4124a43d3bd15d1d6ee89a0d7fd9f264860
[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*[fknSM]),
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
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
84 }          
85
86 //__________________________________________________________________
87 AliEMCALQAChecker::~AliEMCALQAChecker() 
88 {
89         /// dtor
90   delete [] fTextSM ;
91   delete fLineCol ;
92   for (Int_t i=0; i<4; ++i) delete fLineRow[i] ;
93   delete fText  ; 
94 }
95
96 //__________________________________________________________________
97 AliEMCALQAChecker::AliEMCALQAChecker(const AliEMCALQAChecker& qac) : 
98 AliQACheckerBase(qac.GetName(), qac.GetTitle()), 
99 fTextSM(new TText*[fknSM]) ,
100 fLineCol(static_cast<TLine*>(qac.fLineCol->Clone())) , 
101 fText(new TPaveText(0.2,0.7,0.8,0.9,"NDC"))
102 {
103    // copy ctor 
104   for (Int_t sm = 0 ; sm < fknSM ; sm++){
105     fTextSM[sm] = static_cast<TText *>(qac.fTextSM[sm]->Clone()) ;
106   }
107         for(Int_t i = 0 ; i < 4 ; i++) {
108
109                 fLineRow[i] = static_cast<TLine*>(qac.fLineRow[i]->Clone()) ; 
110         }
111 }   
112 //__________________________________________________________________
113 AliEMCALQAChecker& AliEMCALQAChecker::operator = (const AliEMCALQAChecker &qac) 
114 {
115   fTextSM  = new TText*[fknSM] ;
116   fLineCol = static_cast<TLine*>(qac.fLineCol->Clone()) ; 
117   fText    = new TPaveText(0.2,0.7,0.8,0.9,"NDC") ;
118   for (Int_t sm = 0 ; sm < fknSM ; sm++){
119     fTextSM[sm] = static_cast<TText *>(qac.fTextSM[sm]->Clone()) ;
120   }
121         for(Int_t i = 0; i < 4; i++) {
122
123                 fLineRow[i] = static_cast<TLine*>(qac.fLineRow[i]->Clone()) ; 
124         }
125   return *this ;
126 }
127
128 //______________________________________________________________________________
129 void AliEMCALQAChecker::Check(Double_t * test, AliQAv1::ALITASK_t index, TObjArray ** list, const AliDetectorRecoParam * /*recoParam*/)
130 {
131         /// Check objects in list
132         
133         if ( index == AliQAv1::kRAW ) 
134         {
135     CheckRaws(test, list);
136                 printf ("checkers for task %d \n", index) ;             
137         }
138         
139         if ( index == AliQAv1::kREC)
140         {
141     CheckRecPoints(test, list);
142         }
143         
144         if ( index == AliQAv1::kESD )
145         {
146     CheckESD(test, list);
147         }
148         AliWarning(Form("Checker for task %d not implement for the moment",index));
149 }
150
151 //______________________________________________________________________________
152 TH1* 
153 AliEMCALQAChecker::GetHisto(TObjArray* list, const char* hname, Int_t specie) const
154 {
155         /// Get a given histo from the list
156         TH1* h = static_cast<TH1*>(list->FindObject(Form("%s_%s",AliRecoParam::GetEventSpecieName(specie),hname)));
157         if (!h)
158         {
159                 AliError(Form("Did not find expected histo %s",hname));
160         }
161         return h;
162 }
163
164 //______________________________________________________________________________
165 Double_t 
166 AliEMCALQAChecker::MarkHisto(TH1& histo, Double_t value) const
167 {
168         /// Mark histo as originator of some QA error/warning
169         
170         if ( value != 1.0 )
171         {
172                 histo.SetBit(AliQAv1::GetQABit());
173         }
174         
175         return value;
176 }
177
178
179 //______________________________________________________________________________
180 void AliEMCALQAChecker::CheckRaws(Double_t * test, TObjArray ** list)
181 {
182   //  Check RAW QA histograms   
183   //  -- Yaxian Mao, CCNU/CERN/LPSC
184   //adding new checking method: 25/04/2010, Yaxian Mao
185   //Comparing the amplitude from current run to the reference run, if the ratio in the range [0.8, .12], count as a good tower.
186   //If more than 90% towers are good, EMCAL works fine, otherwise experts should be contacted. 
187   
188                                 
189   //Float_t kThreshold = 80. ; 
190   Int_t nTowersPerSM = 24*48; // number of towers in a SuperModule; 24x48
191   Double_t nTot = fknSM * nTowersPerSM ;
192   TList *lstF = 0;
193   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) {
194     test[specie] = 0.0 ; 
195     if ( !AliQAv1::Instance()->IsEventSpecieSet(specie)) 
196       continue ; 
197     if (list[specie]->GetEntries() == 0)  
198       test[specie] = 0. ; // nothing to check
199     else {
200       TH2F * hdata  = (TH2F*)list[specie]->At(k2DRatioAmp) ; 
201       TH1F * ratio = (TH1F*)list[specie]->At(kRatioDist) ;
202       if(hdata->GetEntries()==0 || ratio->GetEntries()==0)
203         continue;
204       //adding the lines to distinguish different SMs
205       lstF = hdata->GetListOfFunctions();
206       { // RS: clean list of functions
207         if (lstF) {
208           TObject *stats = lstF->FindObject("stats"); lstF->Remove(stats);
209           TObject *obj;
210           while ((obj = lstF->First())) { while(lstF->Remove(obj)) { } delete obj; }
211           if (stats) lstF->Add(stats);
212         } 
213       }
214       lstF->Add(fLineCol->Clone()); 
215       for(Int_t iLine = 0; iLine < 4; iLine++) {
216         lstF->Add(fLineRow[iLine]->Clone());
217       } 
218       //Now adding the text to for each SM
219       for(Int_t iSM = 0 ; iSM < fknSM ; iSM++){  //number of SMs loop start
220         lstF->Add(fTextSM[iSM]->Clone()); 
221       }
222       //
223       lstF = ratio->GetListOfFunctions();
224       { // RS: clean list of functions
225         if (lstF) {
226           TObject *stats = lstF->FindObject("stats"); lstF->Remove(stats);
227           TObject *obj;
228           while ((obj = lstF->First())) { while(lstF->Remove(obj)) { } delete obj; }
229           if (stats) lstF->Add(stats);
230         } 
231       }
232       lstF->Add(fText->Clone()) ;
233       //
234       //now check the ratio histogram
235       Double_t binContent = 0. ;  
236       Int_t NGoodTower = 0 ;
237       Double_t rv = 0. ;
238       for(Int_t ix = 1; ix <= hdata->GetNbinsX(); ix++) {
239         for(Int_t iy = 1; iy <= hdata->GetNbinsY(); iy++) {
240           binContent = hdata->GetBinContent(ix, iy) ; 
241           if (binContent < 1.2 && binContent > 0.8) 
242             NGoodTower++ ;
243         }
244       }
245       rv = NGoodTower/nTot ; 
246       printf("%2.2f %% towers out of range [0.8, 1.2]\n", (1-rv)*100);
247       if(fText){
248         fText->Clear() ; 
249         
250         fText->AddText(Form("%2.2f %% towers out of range [0.8, 1.2]", (1-rv)*100));     
251         if (rv < 0.9) {
252           test[specie] = 0.9 ;
253           // 2 lines text info for quality         
254           fText->SetFillColor(2) ;
255           fText->AddText(Form("EMCAL = NOK, CALL EXPERTS!!!")); 
256         }
257         else {
258           test[specie] = 0.1 ;
259           fText->SetFillColor(3) ;
260           fText->AddText(Form("EMCAL = OK, ENJOY...")); 
261         }
262         //hdata->Reset("ICE");
263         //ratio->Reset("ICE");
264       }//fText
265     } 
266   } //finish the checking
267 }
268
269 //______________________________________________________________________________
270 void AliEMCALQAChecker::Init(const AliQAv1::DETECTORINDEX_t det) 
271 {
272         /// intialises QA and QA checker settings
273         AliQAv1::Instance(det) ; 
274         Float_t hiValue[AliQAv1::kNBIT] ; 
275         Float_t lowValue[AliQAv1::kNBIT] ;
276         lowValue[AliQAv1::kINFO]      = 0.0   ; 
277         hiValue[AliQAv1::kINFO]       = 0.1 ; 
278         lowValue[AliQAv1::kWARNING]   = 0.1 ; 
279   hiValue[AliQAv1::kWARNING]    = 0.5 ; 
280         lowValue[AliQAv1::kERROR]     = 0.5   ; 
281         hiValue[AliQAv1::kERROR]      = 0.8 ; 
282         lowValue[AliQAv1::kFATAL]     = 0.8   ; 
283         hiValue[AliQAv1::kFATAL]      = 1.0 ; 
284         SetHiLo(&hiValue[0], &lowValue[0]) ; 
285 }
286