]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSQASSDChecker.cxx
reset transient cluster usage info in the beginning, no need to UnloadClusters
[u/mrichter/AliRoot.git] / ITS / AliITSQASSDChecker.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, 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 /* $Id$ */
17
18 // *****************************************
19 //  Checks the quality assurance 
20 //  by comparing with reference data
21 //  P. Cerello Apr 2008
22 //  INFN Torino
23
24 // --- ROOT system ---
25 #include "TH1.h"
26 #include "TString.h"
27 #include "TCanvas.h"
28 #include "TStyle.h"
29 #include "TPad.h"
30 //#include "Riostream.h"
31
32 // --- AliRoot header files ---
33 #include "AliITSQASSDChecker.h"
34 #include "AliITSQADataMakerRec.h"
35 #include "AliLog.h"
36
37 ClassImp(AliITSQASSDChecker)
38 //__________________________________________________________________
39 AliITSQASSDChecker& AliITSQASSDChecker::operator = (const AliITSQASSDChecker& qac ) 
40 {
41   // Equal operator.
42   this->~AliITSQASSDChecker();
43   new(this) AliITSQASSDChecker(qac);
44   return *this;
45 }
46
47 void AliITSQASSDChecker::CheckRaws(TH1* histo) {  
48   // checker for RAWS
49   Double_t minSSDDataSize = 0;
50   Double_t maxSSDDataSize = 200;
51   Double_t minDDLDataSize = 0;
52   Double_t maxDDLDataSize = 50;
53   Double_t minLDCDataSize = 0;
54   Double_t maxLDCDataSize = 100;
55   Double_t minMeanDDLDataSize = 0;
56   Double_t maxMeanDDLDataSize = 50;
57   Double_t minMeanLDCDataSize = 0;
58   Double_t maxMeanLDCDataSize = 100;
59   //  Double_t maxOccupancy = 5;
60
61   TString histname = histo->GetName();
62
63   if (histname.EndsWith("SSDEventType")) {
64     if (histo->GetEntries()==0) {
65       AliWarning("Event type histogram is empty");
66     }
67     else if (histo->GetBinContent(histo->FindBin(7))==0) AliWarning("No type 7 (physics) events in EventType");
68   }
69
70   if (histname.EndsWith("SSDDataSize")) {
71     if (histo->GetEntries()==0) AliWarning("SSD data size histogram is empty");
72     if (histo->GetMean()>maxSSDDataSize||histo->GetMean()<minSSDDataSize) AliWarning(Form("SSD mean data size is %-.2g kB", histo->GetMean()));
73   }
74
75   if (histname.EndsWith("SSDDataSizePerDDL")) {
76     if (histo->GetEntries()==0) {
77       AliWarning("Data size per DDL histogram is empty");
78     }
79     else {
80       for(Int_t i = 512; i < 528; i++) {
81         if(histo->GetBinContent(histo->FindBin(i))==0) {
82            AliWarning(Form("Data size / DDL histogram: bin for DDL %i is empty",i));
83         }
84         else if(histo->GetBinContent(histo->FindBin(i))<minDDLDataSize||histo->GetBinContent(histo->FindBin(i))>maxDDLDataSize) AliWarning(Form("Data size DDL %i is %-.2g kB",i,histo->GetBinContent(histo->FindBin(i))));
85      }
86     }
87   }
88
89   if (histname.EndsWith("SSDDataSizePerLDC")) {
90     if (histo->GetEntries()==0) {
91       AliWarning("Data size per LDC histogram is empty");
92     }    
93     else {
94       AliInfo(Form("Data size per LDC histogram has %f entries",histo->GetEntries()));
95       for(Int_t i = 170; i < 178; i++) {
96         if(histo->GetBinContent(histo->FindBin(i))==0) {
97           AliWarning(Form("Data size / LDC histogram: bin for LDC %i is empty",i));
98         }
99         else if(AliITSQADataMakerRec::AreEqual(histo->GetBinContent(histo->FindBin(i)),minLDCDataSize) ||histo->GetBinContent(histo->FindBin(i))>maxLDCDataSize) AliWarning(Form("Data size LDC %i is %-.2g kB",i,histo->GetBinContent(i)));
100       }
101     }
102   }
103
104   if (histname.EndsWith("SSDLDCId")) {
105     if (histo->GetEntries()==0) {
106       AliWarning("LDC ID histogram is empty");
107     }    
108     else {
109       for(Int_t i = 170; i < 177; i++) {
110         if(histo->GetBinContent(histo->FindBin(i))==0) {
111           AliWarning(Form("LDC ID histogram: No entries for LDC %i",i));
112         }
113         else if(histo->GetBinContent(histo->FindBin(i))!=histo->GetBinContent(histo->FindBin(i+1))) {
114           AliWarning("LDC Id distribution is not uniform");
115           i=176;
116         }
117       }
118     }
119   }
120
121   if (histname.EndsWith("SSDDDLId")) {
122     if (histo->GetEntries()==0) {
123       AliWarning("DDL ID histogram is empty");
124     }
125     else {
126       for(Int_t i = 512; i < 527; i++) {
127         if(histo->GetBinContent(histo->FindBin(i))==0) {
128           AliWarning(Form("DDL ID histogram: No entries for DDL %i",i));
129         }
130         else if(histo->GetBinContent(histo->FindBin(i))!=histo->GetBinContent(histo->FindBin(i+1))) {
131           AliWarning("DDL Id distribution is not uniform");
132           i=526;
133         }
134       }
135     }
136   }
137
138   if (histname.Contains("SSDDataSizeLDC")) {
139     if (histo->GetEntries()==0) {
140       AliWarning(Form("LDC %s data size distribution is empty", histname(histname.Length()-3,3).Data()));
141     }
142     else if (histo->GetMean()<minMeanLDCDataSize||histo->GetMean()>maxMeanLDCDataSize) AliWarning(Form("Mean data size of LDC %s is %-.2g kB",histname(histname.Length()-3,3).Data(), histo->GetMean()));
143   }
144
145   if (histname.Contains("SSDDataSizeDDL")) {
146     if (histo->GetEntries()==0) {
147       AliWarning(Form("DDL %s data size distribution is empty", histname(histname.Length()-3,3).Data()));
148     } 
149     else if (histo->GetMean()<minMeanDDLDataSize||histo->GetMean()>maxMeanDDLDataSize) AliWarning(Form("Mean data size of DDL %s is %-.2g kB",histname(histname.Length()-3,3).Data(), histo->GetMean()));
150   }
151
152   /* Lines below commented out because nothing was checked with them since the AliWarning was commented (F. Prino, June 18 2014)
153   if (histname.Contains("SSDAverageOccupancy")) {
154  
155     const char* side = "";
156     int ladder = 0;
157     int layernr = 0;
158
159     if (histname.EndsWith("5")) layernr = 499;
160     if (histname.EndsWith("6")) layernr = 599;
161
162     for (Int_t i = 1; i < histo->GetNbinsY() + 1; i++) { //ladder/side loop
163       if(i==3.*int(i/3.)){
164         ladder=int(i/3.)+layernr;
165         side="P side";
166       }
167       else if(i==3.*int(i+1/3.)){
168         ladder=int((i+1)/3.)+layernr;
169         side="N side";
170       }
171
172       for (Int_t j = 1; j < histo->GetNbinsX() + 1; j++) { //module loop
173         //if(histo->GetBinContent(j,i)>maxOccupancy)
174           // AliWarning(Form("Occupancy ladder %i, module %i, %s is %-.2f %%",ladder,j,side, histo->GetBinContent(j,i)));
175       }//module loop
176     }//ladder loop
177   }
178   */
179 }
180
181
182 //__________________________________________________________________
183 Bool_t  AliITSQASSDChecker::MakeSSDImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode) {
184   //create the image for raws and recpoints. In the other case, the default methodof CheckerBase class will be used  //
185   gStyle->SetPalette(1,0);
186   Bool_t rval=kFALSE;
187   fImage=(TCanvas**)AliQAChecker::Instance()->GetDetQAChecker(0)->GetImage();
188
189   if(task == AliQAv1::kRAWS) 
190     rval = MakeSSDRawsImage(list, task,mode);
191   else rval=kFALSE;
192   
193   return rval;
194 }
195
196 //_______________________________________________________________________
197 Bool_t AliITSQASSDChecker::MakeSSDRawsImage(TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode ) {
198   // MakeSSDRawsImage: raw data QA plots
199   for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
200     //printf("-------------------------> %i \n", esIndex);
201     if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0) continue;
202     else {
203       const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
204       if ( !fImage[esIndex] ) fImage[esIndex] = new TCanvas(title, title,1280,980) ;
205         
206       fImage[esIndex]->Clear() ; 
207       fImage[esIndex]->SetTitle(title) ; 
208       fImage[esIndex]->cd();
209  
210       //TPaveText someText(0.015, 0.015, 0.98, 0.98);
211       //someText.AddText(title);
212       //someText.Draw(); 
213       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
214       fImage[esIndex]->Clear() ; 
215       Int_t nx =2; //TMath::Nint(TMath::Sqrt(nImages));
216       Int_t ny =2; // nx  ; 
217         
218       fImage[esIndex]->Divide(nx, ny) ; 
219       TIter nexthist(list[esIndex]) ; 
220       TH1* hist = NULL ;
221       Int_t npad = 1 ; 
222       fImage[esIndex]->cd(npad); 
223       fImage[esIndex]->cd(npad)->SetBorderMode(0) ;
224       while ( (hist=static_cast<TH1*>(nexthist())) ) {
225         //gPad=fImage[esIndex]->cd(npad)->GetPad(npad);
226         TString cln(hist->ClassName()) ; 
227         if ( ! cln.Contains("TH") ) continue ;
228         
229         if(hist->TestBit(AliQAv1::GetImageBit())) {
230           //Printf("Histo name: %s - Class: %s",hist->GetName(),hist->ClassName());
231           hist->GetXaxis()->SetTitleSize(0.02);
232           hist->GetYaxis()->SetTitleSize(0.02);
233           hist->GetXaxis()->SetLabelSize(0.02);
234           hist->GetYaxis()->SetLabelSize(0.02);
235           if(cln.Contains("TH2")) {
236             gPad->SetRightMargin(0.15);
237             gPad->SetLeftMargin(0.05);
238             hist->SetStats(0);
239             hist->SetOption("colz") ;
240             //hist->GetListOfFunctions()->FindObject("palette")->SetLabelSize(0.025);
241             //gPad->Update();
242           }
243           hist->DrawCopy() ; 
244           fImage[esIndex]->cd(++npad) ; 
245           fImage[esIndex]->cd(npad)->SetBorderMode(0) ; 
246         }
247       }
248       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
249     }
250   }
251   
252   return kTRUE;
253 }
254
255 //__________________________________________________________________
256 Double_t AliITSQASSDChecker::Check(AliQAv1::ALITASK_t /*index*/, const TObjArray * list, const AliDetectorRecoParam * /*recoParam*/) { 
257   // main checker method 
258   AliDebug(AliQAv1::GetQADebugLevel(),Form("AliITSQASSDChecker called with offset: %d\n", fSubDetOffset));
259
260   AliInfo(Form("AliITSQASSDChecker called with offset: %d\n", fSubDetOffset) );
261   //cout<<"(AliITSQASSDChecker::Check): List name "<<list->GetName()<<endl;
262   Double_t test = 0.0  ;
263   Int_t count = 0 ;
264   TString listname = list->GetName();
265
266   if (list->GetEntries() == 0){
267     test = 1. ; // nothing to check
268   }
269   else {
270
271     TIter next(list) ;
272     TH1 * hdata ;
273     count = 0 ;
274     while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
275       if (hdata) {
276         TString histname = hdata->GetName();
277         if(!histname.Contains("fHistSSD")) continue;
278         Double_t rv = 0.;
279         if(hdata->GetEntries()>0) {
280            rv = 1;
281
282            //if(histname.Contains("PerDDL")) cout << "(AliITSQASSDChecker::Check) " << histname << " has " << hdata->GetEntries() << " entries. Mean: " << hdata->GetMean() << endl;
283        
284        //    if(hdata->GetMean()>0&&!histname.Contains("_Ladder")) cout << "(AliITSQASSDChecker::Check) " << histname << " not empty! " << hdata->GetEntries() << " entries. Mean: " << hdata->GetMean() << endl;
285         }
286
287     //    if (listname.Contains("Raws")) CheckRaws(hdata);
288    //     if (listname.Contains("RecPoints")) CheckRecPoints(hdata);
289
290         //AliDebug(AliQAv1::GetQADebugLevel(), Form("%s -> %f", hdata->GetName(), rv)) ;
291         //cout<<hdata->GetName()<<" - "<<rv<<endl;
292         count++ ;
293         test += rv ;
294       }
295       else{
296         AliError("Data type cannot be processed") ;
297       }
298     }
299     if (count != 0) {
300       if (AliITSQADataMakerRec::AreEqual(test,0.)) {
301         AliWarning("Histograms are there, but they are all empty: setting flag to kWARNING");
302         test = 0.5;  //upper limit value to set kWARNING flag for a task
303       }
304       else {
305         test /= count ;
306       }
307     }
308   }
309   
310   //AliDebug(AliQAv1::GetQADebugLevel(), Form("Test Result = %f", test)) ;
311   //cout<<"Test result: "<<test<<endl;
312
313   return test ;
314
315   //return 0.;
316
317
318 }
319
320 //__________________________________________________________________
321 void AliITSQASSDChecker::SetTaskOffset(Int_t TaskOffset){
322   // defines offset for SSD
323   fSubDetOffset = TaskOffset;
324 }
325
326 //__________________________________________________________________
327 void AliITSQASSDChecker::SetStepBit(const Double_t *steprange) {
328   // defines step range
329   fStepBitSSD = new Double_t[AliQAv1::kNBIT];
330   for(Int_t bit=0;bit<AliQAv1::kNBIT;bit++)
331     {
332       fStepBitSSD[bit]=steprange[bit];
333     }
334 }
335
336 //__________________________________________________________________
337 void  AliITSQASSDChecker::SetSSDLimits(const Float_t *lowvalue, const Float_t * highvalue){
338   // defines 
339   fLowSSDValue = new Float_t[AliQAv1::kNBIT];
340   fHighSSDValue= new Float_t[AliQAv1::kNBIT];
341
342   for(Int_t bit=0;bit<AliQAv1::kNBIT;bit++)
343     {
344       fLowSSDValue[bit]=lowvalue[bit];
345       fHighSSDValue[bit]= highvalue[bit];
346     }
347
348 }