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