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