]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSQASPDChecker.cxx
don't sort clusters after local reco, do this in AliITSUTrackerGlo
[u/mrichter/AliRoot.git] / ITS / AliITSQASPDChecker.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 "TH2F.h"
27 #include "TString.h"
28 #include "TList.h"
29 #include "TCanvas.h"
30 #include "TFrame.h"
31 #include "TStyle.h"
32 #include "TPaletteAxis.h"
33
34 // --- AliRoot header files ---
35 #include"AliQACheckerBase.h"
36 #include "AliITSQASPDChecker.h"
37 #include "AliITSQADataMakerRec.h"
38 #include "AliLog.h"
39
40 ClassImp(AliITSQASPDChecker)
41  //__________________________________________________________________
42  AliITSQASPDChecker::AliITSQASPDChecker() : 
43   TObject(),
44   fSubDetOffset(0), 
45   fStepBitSPD(NULL),
46   fLowSPDValue(NULL),
47   fHighSPDValue(NULL),
48   fImage(NULL) 
49 {
50  // default contructor
51 }
52 //__________________________________________________________________
53 AliITSQASPDChecker& AliITSQASPDChecker::operator = (const AliITSQASPDChecker& qac ) 
54 {
55  // Equal operator.
56  this->~AliITSQASPDChecker();
57  new(this) AliITSQASPDChecker(qac);
58  return *this;
59 }
60 //__________________________________________________________________
61 AliITSQASPDChecker::~AliITSQASPDChecker() {
62  // destructor
63  if(fStepBitSPD) delete[] fStepBitSPD ;
64  if(fLowSPDValue)delete[]fLowSPDValue;
65  if(fHighSPDValue) delete[]fHighSPDValue;
66  if(fImage) delete[]fImage;
67
68
69 //__________________________________________________________________
70 Double_t AliITSQASPDChecker::Check(AliQAv1::ALITASK_t index, TObjArray * list, const AliDetectorRecoParam * /*recoParam*/)
71 {
72  //
73  // General methods for SPD Cheks to be used in RAWS and REC ALITASK_t
74  //
75
76  AliDebug(2, Form("AliITSQASPDChecker called with offset: %d\n", fSubDetOffset));
77
78  Double_t test = 0.0;
79  Int_t count = 0;
80  // Checks for ALITASK_t AliQAv1::kRAW
81  if(index == AliQAv1::kRAW) {
82   return CheckRawData(list);
83  } else {
84   if (list->GetEntries() == 0) {
85    test = 1.; // nothing to check
86   }
87   else {
88    TIter next(list);
89    TH1 * hdata;
90    count = 0;
91    while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
92     if (hdata) {
93      TString histName = hdata->GetName();
94      if (!histName.Contains("_SPD")) continue;
95      Double_t rv = 0.;
96      if (hdata->GetEntries()>0) rv = 1;
97      if (histName.Contains("LayPattern")) {
98       if (hdata->GetBinContent(1)) {
99        Double_t ratio=hdata->GetBinContent(2)/hdata->GetBinContent(1);
100        AliDebug(2, Form("%s: ratio RecPoints lay2 / lay1 = %f", hdata->GetName(), ratio));
101       }
102       else
103        AliDebug(AliQAv1::GetQADebugLevel(), "No RecPoints in lay1");
104      }
105      else if(histName.Contains("ModPattern")) {
106       Int_t ndead=0;
107       for(Int_t ibin=0;ibin<hdata->GetNbinsX();ibin++) {
108        if(histName.Contains("SPD1") && ibin<80 && hdata->GetBinContent(ibin+1)>0) ndead++;
109        if(histName.Contains("SPD2") && ibin>79 && hdata->GetBinContent(ibin+1)>0) ndead++;
110       }
111       AliDebug(2, Form("%s: Entries = %d  number of empty modules = %d", 
112          hdata->GetName(),(Int_t)hdata->GetEntries(),ndead));
113      }
114      else if(histName.Contains("SizeYvsZ")) {
115       Double_t meanz=hdata->GetMean(1);
116       Double_t meany=hdata->GetMean(2);
117       Double_t rmsz=hdata->GetRMS(1);
118       Double_t rmsy=hdata->GetRMS(2);
119       AliDebug(AliQAv1::GetQADebugLevel(), Form("%s: Cluster sizeY mean = %f  rms = %f", hdata->GetName(),meany,rmsy));
120       AliDebug(AliQAv1::GetQADebugLevel(), Form("%s: Cluster sizeZ mean = %f  rms = %f", hdata->GetName(),meanz,rmsz));
121      }
122      else if(histName.Contains("SPDMultiplicity")) {
123       AliDebug(2, Form("%s: Events = %d  mean = %f  rms = %f",
124          hdata->GetName(),(Int_t)hdata->GetEntries(),hdata->GetMean(),hdata->GetRMS()));}
125
126      // else AliDebug(AliQAv1::GetQADebugLevel(), Form("%s -> %f", hdata->GetName(), rv));
127      count++;
128      test += rv;
129     }
130     else {
131      AliError("Data type cannot be processed") ;
132     }
133    }
134
135    if (count != 0) {
136     if (AliITSQADataMakerRec::AreEqual(test,0)) {
137      AliWarning("Histograms are there, but they are all empty: setting flag to kWARNING");
138      test = fHighSPDValue[AliQAv1::kWARNING];  //upper limit value to set kWARNING flag for a task
139     }
140     else {
141      test /= count;
142     }
143    }
144   }
145  }
146  AliDebug(AliQAv1::GetQADebugLevel(), Form("Test Result = %f", test));
147  return test ;
148
149 }
150 //__________________________________________________________________
151 Double_t AliITSQASPDChecker::CheckRawData(const TObjArray * list) {
152  //
153  // Checks on the raw data histograms [ preliminary version ]
154  // The output of this method is the fraction of SPD histograms which are processed by the checker. 
155  // The methods returns fHighSPDValue[AliQAv1::kFATAL] in case of data format errors or MEB errors
156  // 
157  // A. Mastroserio
158
159  Double_t test =0;
160
161  // basic checks on input data
162  if(!list) {
163   AliError("NO histogram list for RAWS");
164   return test;
165  }
166
167  if(list->GetEntries() == 0) {
168   AliWarning("No histograms in RAW list \n");
169   return test;
170  }
171
172  // loop over the raw data histograms
173  TIter next(list);
174  TH1 * hdata;
175  Double_t totalHistos = 0;
176  Double_t goodHistos = 0; // number of histograms which passed the checks
177  Double_t response =0;
178  Bool_t fatalProblem = kFALSE;
179
180  while ( (hdata = dynamic_cast<TH1 *>(next())) ) {
181   if (hdata) {
182    TString histName = hdata->GetName();
183    if(!histName.Contains("SPD")) continue;
184    totalHistos++;
185    // data format error
186    if(histName.Contains("SPDErrorsAll")){
187     if(hdata->GetListOfFunctions()->GetEntries()<1) hdata->GetListOfFunctions()->Add(new TPaveText(0.2,0.23,0.7,0.5,"NDC"));
188
189     for(Int_t i=0; i<hdata->GetListOfFunctions()->GetEntries(); i++){
190      TString funcName = hdata->GetListOfFunctions()->At(i)->ClassName();
191      if(funcName.Contains("TPaveText")){
192       TPaveText *p = (TPaveText*)hdata->GetListOfFunctions()->At(i);
193       p->Clear();
194
195       if(hdata->Integral(0,hdata->GetNbinsX())>0){
196        Bool_t isHighMult = kFALSE;
197        Bool_t isDataCorrupted=kFALSE;
198        for(Int_t ieq=0; ieq<20; ieq++){
199         if(hdata->GetBinContent(ieq+1,17+1)>0 && hdata->GetBinContent(ieq+1,20+1)>0) isHighMult = kTRUE;
200         for(Int_t iErr=1; iErr<20; iErr++){
201          if(iErr==20 || iErr==17) continue;
202          if(hdata->GetBinContent(ieq+1,iErr+1)>0) isDataCorrupted=kTRUE; 
203         }
204        }
205        if(isHighMult && !isDataCorrupted) {
206         p->SetFillColor(kOrange);
207         p->AddText("High occupancy in a chip detected (-> errors type 17,20 and 0 are present). ");
208         p->AddText("ONLY IF OTHER error types are present CALL the expert");
209         response = fHighSPDValue[AliQAv1::kWARNING];
210        } else if(isDataCorrupted) {
211         p->SetFillColor(kRed);
212         p->AddText("Data Format NOT OK. Please call the expert!");
213         response = fHighSPDValue[AliQAv1::kFATAL];
214         fatalProblem=kTRUE;
215        }
216        continue;
217       } // if errors 
218       else {
219        p->Clear();
220        p->SetFillColor(kGreen);
221        p->AddText("OK");
222       }
223      } // TPaveText
224     } // list entries   
225    } // data format error
226
227    // MEB error
228    else if(histName.Contains("MEB")){
229     if(hdata->GetListOfFunctions()->GetEntries()<1) hdata->GetListOfFunctions()->Add(new TPaveText(0.2,0.23,0.7,0.5,"NDC"));
230
231     for(Int_t i=0; i<hdata->GetListOfFunctions()->GetEntries(); i++){
232      TString funcName = hdata->GetListOfFunctions()->At(i)->ClassName();
233      if(funcName.Contains("TPaveText")){
234       TPaveText *p = (TPaveText*)hdata->GetListOfFunctions()->At(i);
235       p->Clear();
236
237       if(hdata->GetEntries()>0){
238        p->SetFillColor(kRed);
239        p->AddText("MEB problem could be present. Please check if SPD is in READY state.");
240        p->AddText("If SPD is in -READY- state, please notify it to the expert."); 
241        response = fHighSPDValue[AliQAv1::kFATAL];
242        fatalProblem=kTRUE;
243        continue;
244
245       } else {
246        p->SetFillColor(kGreen);
247        p->AddText("OK");
248       }   
249
250      } // pave text
251     } // list 
252    }
253    goodHistos++;
254   }
255  }
256  if(!fatalProblem) response = goodHistos/totalHistos;
257  // printf("n histos %f - good ones %f ----> ratio %f , fatal response %i\n",totalHistos,goodHistos,goodHistos/totalHistos,(Int_t)fatalProblem);
258  return response;
259 }
260
261 //__________________________________________________________________
262 void AliITSQASPDChecker::SetTaskOffset(Int_t TaskOffset)
263 {
264  // Offset for SPD within ITS QA
265  fSubDetOffset = TaskOffset;
266 }
267
268 //__________________________________________________________________
269 void AliITSQASPDChecker::SetStepBit(const Double_t *steprange) 
270 {
271  // Step bit for SPD within ITS QA
272  fStepBitSPD = new Double_t[AliQAv1::kNBIT];
273  for(Int_t bit=0;bit<AliQAv1::kNBIT;bit++)
274  {
275   fStepBitSPD[bit]=steprange[bit];
276  }
277 }
278
279
280 //__________________________________________________________________
281 void  AliITSQASPDChecker::SetSPDLimits(const Float_t *lowvalue, const Float_t * highvalue)
282 {
283  // SPD limints for QA bit within general ITS QA
284  fLowSPDValue = new Float_t[AliQAv1::kNBIT];
285  fHighSPDValue= new Float_t[AliQAv1::kNBIT];
286
287  for(Int_t bit=0;bit<AliQAv1::kNBIT;bit++)
288  {
289   fLowSPDValue[bit]=lowvalue[bit];
290   fHighSPDValue[bit]= highvalue[bit];
291  }
292
293 }
294 //__________________________________________________________________
295 Bool_t  AliITSQASPDChecker::MakeSPDImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
296 {
297  //create the image for raws and recpoints. In the other case, the default methodof CheckerBase class will be used
298
299  Bool_t val=kFALSE;
300
301  fImage=(TCanvas**)AliQAChecker::Instance()->GetDetQAChecker(0)->GetImage();
302
303  switch(task)
304  {
305   case AliQAv1::kRAWS:{
306                        val = MakeSPDRawsImage(list, task,mode);
307                       }
308                       break;
309   case AliQAv1::kRECPOINTS:;
310   case AliQAv1::kHITS:; 
311   case AliQAv1::kESDS:; 
312   case AliQAv1::kDIGITS:;
313   case AliQAv1::kDIGITSR:;
314   case AliQAv1::kSDIGITS:;
315   case AliQAv1::kTRACKSEGMENTS:;
316   case AliQAv1::kRECPARTICLES:; 
317   default:
318                               {
319                                //AliQAChecker::Instance()->GetDetQAChecker(0)->MakeImage(list,task,mode);
320                                val = kFALSE;
321                               }
322                               break;
323   case AliQAv1::kNULLTASKINDEX:; case  AliQAv1::kNTASKINDEX: 
324                                {AliWarning(Form("No histograms for these tasks ( %s ) \n", AliQAv1::GetTaskName(task).Data())); val = kFALSE;}
325                                break;
326  }
327  return val; 
328 }
329 //_______________________________________________________________________
330 Bool_t AliITSQASPDChecker::MakeSPDRawsImage(TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode )
331 {
332  //
333  // create layout of the histograms used in the DQM
334  //
335
336  // some style settings
337  gStyle->SetOptStat(10);  
338  for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
339   //printf("-------------------------> %i \n", esIndex);
340   if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0) 
341   {printf ("Nothing for %s \n", AliRecoParam::GetEventSpecieName(esIndex)); continue;}
342   else{
343    const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
344    if ( !fImage[esIndex] ) {
345     fImage[esIndex] = new TCanvas(title, title,6000,3200) ;
346    }
347
348    fImage[esIndex]->Clear() ; 
349    fImage[esIndex]->SetTitle(title) ; 
350    fImage[esIndex]->cd();
351
352    TPaveText someText(0.015, 0.015, 0.98, 0.98);
353    someText.AddText(title);
354    someText.Draw(); 
355    fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
356    fImage[esIndex]->Clear() ; 
357    Int_t nx =3; 
358    Int_t ny =2; 
359
360    fImage[esIndex]->Divide(nx, ny) ; 
361
362    TH1* hist = NULL ;
363    Int_t npad = 1 ; 
364    fImage[esIndex]->cd(npad); 
365    fImage[esIndex]->cd(npad)->SetBorderMode(0) ;
366
367    TIter next(list[esIndex]);
368
369    while ( (hist=static_cast<TH1*>(next())) ) {
370     //gPad=fImage[esIndex]->cd(npad)->GetPad(npad);
371     if(!hist->TestBit(AliQAv1::GetImageBit())) continue;
372     TString name(hist->GetName());
373     if(name.Contains("SPDErrorsAll")) {
374      fImage[esIndex]->cd(1) ; 
375      gPad->SetBorderMode(0) ;  
376      gPad->SetRightMargin(0.05);
377      gPad->SetLeftMargin(0.1);
378      gPad->SetGridx();
379      gPad->SetGridy();
380      hist->SetOption("text") ;
381      hist->DrawCopy();  
382     }     
383     if(name.Contains("MEB")) {
384      fImage[esIndex]->cd(2) ; 
385      gPad->SetBorderMode(0) ;  
386      gPad->SetGridy();
387      gPad->SetGridx();
388      gPad->SetRightMargin(0.05);
389      gPad->SetLeftMargin(0.15);
390      gPad->SetBottomMargin(0.1);
391      hist->SetOption("text") ;
392      hist->DrawCopy();  
393     }     
394     if(name.Contains("SPDFastOrCorrelation")){
395      fImage[esIndex]->cd(3) ; 
396      gPad->SetBorderMode(0) ;  
397      hist->SetOption("") ;
398      hist->DrawCopy();               
399     }
400
401     if(name.Contains("SPDHitMapStaveChipInner")){
402      fImage[esIndex]->cd(4) ; 
403      gPad->SetBorderMode(0) ;  
404      gPad->SetRightMargin(0.25);
405      gPad->SetGridx();
406      gPad->SetGridy();
407      hist->SetObjectStat(0);
408      hist->SetOption("colz") ;
409      hist->DrawCopy();               
410     }
411     if(name.Contains("SPDHitMapStaveChipOuter")){
412      fImage[esIndex]->cd(5) ; 
413      gPad->SetBorderMode(0) ;  
414      gPad->SetRightMargin(0.25);
415      gPad->SetGridx();
416      gPad->SetGridy();
417      hist->SetObjectStat(0);
418      hist->SetOption("colz") ;
419      hist->DrawCopy();               
420     }
421     if(name.Contains("SPDFastOrMapStaveChip")){
422      fImage[esIndex]->cd(6) ; 
423      gPad->SetBorderMode(0) ;  
424      gPad->SetRightMargin(0.1);
425      gPad->SetLeftMargin(0.15);
426      gPad->SetBottomMargin(0.15);
427      gPad->SetTopMargin(-0.2);
428      gPad->SetGridy();
429      gPad->SetGridx();
430      hist->SetObjectStat(0);
431      hist->SetOption("colz") ;
432      hist->DrawCopy("colz");   
433      TH2F *h2 =  (TH2F*)(gPad->GetListOfPrimitives()->At(0)); 
434      for(Int_t i=0; i<h2->GetListOfFunctions()->GetEntries(); i++){
435        TString cname = h2->GetListOfFunctions()->At(i)->ClassName();
436         if(cname.Contains("TPaletteAxis")){
437         TPaletteAxis *palette = (TPaletteAxis*)(h2->GetListOfFunctions()->At(i));
438         if(palette) palette->SetLabelSize(0.02);
439        }
440       }
441      hist->DrawCopy("colz");   
442      //gPad->Update();
443     }
444
445
446    }
447
448    fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
449    //fImage[esIndex]->SaveAs("image.png");
450   }
451  }
452  return kTRUE;
453 }
454
455