]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSQASDDChecker.cxx
Script to draw occupancies
[u/mrichter/AliRoot.git] / ITS / AliITSQASDDChecker.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 <TH1D.h>
27 #include <TH2.h>
28 #include "TCanvas.h"
29 #include "TPaveText.h"
30 #include "TPad.h"
31 //#include "TPaletteAxis.h"
32 // --- AliRoot header files ---
33 #include "AliITSQADataMakerRec.h"
34 #include "AliITSQASDDChecker.h"
35 #include "AliLog.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
38 #include "AliITSCalibrationSDD.h"
39 #include "AliITSgeomTGeo.h"
40 #include "AliQAManager.h"
41 #include "AliQAv1.h"
42 #include "AliQAChecker.h"
43 #include "AliQACheckerBase.h"
44
45
46 ClassImp(AliITSQASDDChecker)
47 //__________________________________________________________________
48 AliITSQASDDChecker& AliITSQASDDChecker::operator = (const AliITSQASDDChecker& qac ) 
49 {
50   // Equal operator.
51   this->~AliITSQASDDChecker();
52   new(this) AliITSQASDDChecker(qac);
53   return *this;
54 }
55
56 AliITSQASDDChecker::~AliITSQASDDChecker() 
57 {
58
59   //destructor
60   if(fStepBitSDD) 
61     {
62       delete[] fStepBitSDD ;
63       fStepBitSDD = NULL;
64     }
65   if(fLowSDDValue)
66     {
67       delete[]fLowSDDValue;
68       fLowSDDValue=NULL;
69     }
70   if(fHighSDDValue)
71     { 
72       delete[]fHighSDDValue;
73       fHighSDDValue=NULL;
74     }
75   if(fCalibration)
76     {
77       delete fCalibration;
78       fCalibration=NULL;
79     }
80   if(fImage)
81     {
82       delete []fImage; 
83       fImage=NULL;
84     }
85 } // dtor
86
87 //__________________________________________________________________
88 Double_t AliITSQASDDChecker::Check(AliQAv1::ALITASK_t index, const TObjArray * list, const AliDetectorRecoParam * /*recoparam*/) 
89 {
90   //check histograms of the different lists  
91   AliInfo(Form("AliITSQASDDChecker called with offset: %d\n", fSubDetOffset) );
92
93   AliDebug(1,Form("AliITSQASDDChecker called with offset: %d\n", fSubDetOffset));
94
95   Double_t sddQACheckerValue = 0.;
96   TH1 *hdata=NULL;
97   Double_t entries=0.;
98   Double_t entries2[2];
99   for(Int_t i=0;i<2;i++)entries2[i]=0.;
100
101   if(!fCalibration){
102     AliCDBEntry *calibSDD = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
103     Bool_t cacheStatus = AliCDBManager::Instance()->GetCacheFlag();
104     if(!calibSDD)
105       {
106         AliError("Calibration object retrieval failed! SDD will not be processed");
107         fCalibration = NULL;
108         sddQACheckerValue= fHighSDDValue[AliQAv1::kWARNING];
109       }
110     else{
111       fCalibration = (TObjArray *)calibSDD->GetObject();
112       
113       if(!cacheStatus)calibSDD->SetObject(NULL);
114       calibSDD->SetOwner(kTRUE);
115       if(!cacheStatus)
116         {
117           delete calibSDD;
118         }
119     }//end calibsdd 
120   }//end f calibration
121
122   AliInfo("Calib SDD Created\n ");
123
124   TIter next(list);
125   TString results1;
126   TString results2;
127   Int_t color=1;
128
129   switch(index) {
130     case AliQAv1::kRAW:{
131       AliInfo(Form("Check on %s\n",AliQAv1::GetAliTaskName(index)));
132 //       if(fRawModulePattern) { delete fRawModulePattern; fRawModulePattern = 0; }
133 //       if(fRawL3Pattern) { delete fRawL3Pattern; fRawL3Pattern = 0; }
134 //       if(fRawL4Pattern) { delete fRawL4Pattern; fRawL4Pattern = 0; }
135       if (list->GetEntries() == 0){AliError("Raw List for SDD is empty \n");sddQACheckerValue += fHighSDDValue[AliQAv1::kFATAL];        break;}
136       TH1 *hmodule=NULL;
137       TH2 *hlayer[2]; 
138       hdata=NULL;
139       for(Int_t i=0;i<2;i++)hlayer[i]=NULL;
140
141       //check counters
142       Int_t emptymodules[2], filledmodules[2],emptyladders[2],filledladders[2],emptydriftregion[2], filleddriftregion[2], excludedmoduleperlayer[2], excludeddrperlayer[2], activemoduleperlayer[2],activedrperlayer[2],exactivemoduleperlayer[2],exactivedrperlayer[2];
143       Int_t excluded=0;            //excluded modules  
144       Int_t excludeddriftregion=0; //excluded single drift region
145       Int_t active=0;              //active modules  
146       Int_t activedriftregion=0;   //active single drift region
147       Int_t exactive=0;            //excluded modules but taking data
148       Int_t exactivedriftregion=0; //excluded single drift region but taking data   
149       Int_t empty=0;
150       Int_t filled=0;
151       Int_t emptydr=0;
152       Int_t filleddr=0;
153       //Int_t emptyactivemodule=0;
154       Int_t emptyactivemoduleperlayer[2];
155       //Int_t emptydractivemodule=0;
156       Int_t emptyactivedrperlayer[2];
157       Int_t emptysum=0;
158       Int_t emptydiff=0;
159       Int_t emptydrsum=0;
160       Int_t emptydrdiff=0;
161
162     for(Int_t i=0;i<2;i++)
163       {
164         emptymodules[i]=0; 
165         filledmodules[i]=0; 
166         emptyladders[i]=0; 
167         filledladders[i]=0; 
168         emptydriftregion[i]=0;
169         filleddriftregion[i]=0; 
170         excludedmoduleperlayer[i]=0;
171         excludeddrperlayer[i]=0;
172         activemoduleperlayer[i]=0;
173         activedrperlayer[i]=0;
174         exactivemoduleperlayer[i]=0;
175         exactivedrperlayer[i]=0;
176         emptyactivemoduleperlayer[i]=0;
177         emptyactivedrperlayer[i]=0;
178       }  
179
180     Int_t neventsraw=0;
181
182     //take the number of events
183
184       while( (hdata = dynamic_cast<TH1* >(next())) ){
185         if (hdata){
186           TString hname=hdata->GetName();
187
188           if(hname.Contains("SDDRawDataCheck"))
189             { 
190               neventsraw=(Int_t)hdata->GetBinContent(1); 
191               //break;
192             }
193           else continue;
194         }//end if hdata
195       }//end while
196
197       next.Begin();
198       while( (hdata = dynamic_cast<TH1* >(next())) ){
199         if (hdata){TString hname=hdata->GetName();
200           if(hname.Contains("SDDchargeMap"))continue;
201           if(hname.Contains("SDDDDLPattern"))continue;
202           if(hname.Contains("SDDEventSize"))continue;
203           if(hname.Contains("_RelativeOccupancy"))continue;
204           if(hname.Contains("SDDModPattern")){
205             if(hname.Contains("NORM")) continue;
206             hmodule=(TH1*)hdata->Clone();
207             entries= hdata->GetEntries();
208             if(AliITSQADataMakerRec::AreEqual(entries,0.)){AliWarning(Form("===================>>>>>> No entries in  %s \n",hname.Data()));sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];}//endif entries
209             else{
210               int modmax=hdata->GetNbinsX();
211               Double_t content=0;
212               Int_t llay=0;
213               for(Int_t i=1;i<=modmax;i++)
214                 {
215                   if(i<85)llay=0;
216                   else llay=1;
217                   content=hdata->GetBinContent(i);
218                   if(AliITSQADataMakerRec::AreEqual(content,0.))
219                     {
220                     empty++;
221                     emptymodules[llay]++;
222                     } 
223                   else 
224                     {
225                       filled++;
226                       filledmodules[llay]++;
227                     }
228                 }//end for
229               //output of the check at the level of the modules. Drift region in the following checks
230
231               AliInfo(Form(" %s : empty modules %i \t filled modules %i",hname.Data(), empty, filled));
232               AliInfo(Form(" %s : Layer 3 empty modules %i \t filled modules %i",hname.Data(), emptymodules[0], filledmodules[0]));
233               AliInfo(Form(" %s : Layer 4 empty modules %i \t filled modules %i",hname.Data(), emptymodules[1], filledmodules[1]));
234             }//end else pattern entries !=0
235           } //modpattern (1d histogram)                 
236           if(hname.Contains("_RelativeOccupancy")) {
237             //fRawModulePattern = (TH1F *) hdata;
238             Float_t threshold = hdata->GetMean() + 4*hdata->GetRMS();
239             if(hname.Contains("L3")) AliInfo(Form("SDD check number 1: L3 mean: %f, rms: ,%f",hdata->GetMean(),hdata->GetRMS()));
240             if(hname.Contains("L4")) AliInfo(Form("SDD check number 2: L4 mean: %f, rms: ,%f",hdata->GetMean(),hdata->GetRMS()));
241             Int_t aboveThreshold = 0;
242             for(Int_t k=0; k<= hdata->GetNbinsX(); k++) {if(hdata->GetBinLowEdge(k) > threshold) aboveThreshold += (int)(hdata->GetBinContent(k));}
243             Float_t fractionAboveThreshold=0.;
244             if(hdata->GetEntries()>0.)fractionAboveThreshold=((Float_t) aboveThreshold)/hdata->GetEntries();
245             if(hname.Contains("L3")) AliInfo(Form("SDD check number 1, L3: Raw fractionAboveThreshold: %f",fractionAboveThreshold));
246             if(hname.Contains("L4")) AliInfo(Form("SDD check number 2, L4: Raw fractionAboveThreshold: %f",fractionAboveThreshold));
247             if(fractionAboveThreshold > fThresholdForRelativeOccupancy) {sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
248               if(hname.Contains("L3")) AliInfo(Form("SDD check number 1: Set Warning (L3 Raw)"));
249               if(hname.Contains("L4")) AliInfo(Form("SDD check number 2: Set Warning (L4 Raw)")); } }//relativeoccupancy
250
251           if(hname.Contains("SDDphizL3") || hname.Contains("SDDphizL4")){if(hname.Contains("NORM"))continue;
252             Int_t layer=0;
253             if(hname.Contains("3"))layer=0;
254             else  if(hname.Contains("4"))layer=1;
255             entries2[layer]=hdata->GetEntries();
256             if(entries2[layer]==0){AliWarning(Form("===================>>>>>> No entries in  %s \n",hname.Data()));
257               sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];}//end if getentries
258             else{
259               Int_t layer1=0;
260               if(hname.Contains("3"))layer1=0;
261               else  if(hname.Contains("4"))layer1=1;
262               TH2* htemp=dynamic_cast<TH2*>(hdata);
263               if(htemp){
264                 hlayer[layer1]=(TH2*)htemp->Clone();
265                 hlayer[layer1]->SetName(Form("%s_copy",hname.Data()));
266                 //hlayer[layer1]->RebinX(2);
267                 int modmay=hlayer[layer1]->GetNbinsY();
268                 TH1D* hproj= hlayer[layer1]->ProjectionY();
269                 Double_t ladcontent=0;
270                 for(Int_t i=1;i<=modmay;i++) {//loop on the ladders
271                   ladcontent=hproj->GetBinContent(i);
272                   if(AliITSQADataMakerRec::AreEqual(ladcontent,0.)) emptyladders[layer1]++;
273                   else filledladders[layer1]++;}//end for
274                 AliInfo(Form(" %s : empty ladders %i \t filled ladders %i\n",hname.Data(), emptyladders[layer1], filledladders[layer1]));//end else layer 3
275                 delete hproj;
276                 hproj=NULL;
277               }//end if htemp
278             }//end else entries !=0
279           }//end check on phiz        
280         }//end if hdata 
281       }//end while
282       for(Int_t ii=0;ii<2;ii++)
283         {
284           filledmodules[ii]=0;
285           emptymodules[ii]=0;
286         }
287       filled=0;
288       empty=0;
289       if(AliITSQADataMakerRec::AreEqual(entries,0.)&& AliITSQADataMakerRec::AreEqual(entries2[0],0.)&& AliITSQADataMakerRec::AreEqual(entries2[1],0.)) break;
290       //else{
291       if(hmodule || (hlayer[0] && hlayer[1])){
292         for(Int_t imod=0;imod<fgknSDDmodules;imod++){
293           Int_t lay=0;
294           Int_t lad=0;
295           Int_t det=0;
296           Int_t module=0;
297           module=imod+fgkmodoffset;
298           AliITSCalibrationSDD * cal=(AliITSCalibrationSDD*)fCalibration->At(imod);
299           if(cal==0) { continue;}
300           AliITSgeomTGeo::GetModuleId(module,lay,lad,det);
301           if (cal->IsBad()){
302             excluded++;
303             excludedmoduleperlayer[lay-3]++;
304             Double_t content=0.;
305             Double_t contentlayer[2];
306             for(Int_t i=0;i<2;i++)contentlayer[i]=0.;
307             if(hmodule)content=hmodule->GetBinContent(imod+1);//if expert bit is active the histogram will be stored in the QA file otherwise the histogram will not be written on the logbook
308             //      if(hlayer[lay-3]) contentlayer[lay-3]=hlayer[lay-3]->GetBinContent(det,lad);
309             if(AliITSQADataMakerRec::AreEqual(content,0.)== kFALSE) {
310               filledmodules[lay-3]++;
311               filled++;
312               AliError(Form("The module %d (layer %i, ladder %i det %i ) excluded from the acquisition, took data \n ",module,lay,lad,det));
313               exactive++;
314               exactivemoduleperlayer[lay-3]++;
315             } else if(AliITSQADataMakerRec::AreEqual(content,0.)) 
316               {
317                 emptymodules[lay-3]++; //it has to be empty
318                 empty++;
319               }
320           } else {
321             Int_t totside=0;
322             Int_t totactiveside=0;
323             //Int_t totbadside=0;
324             Double_t contentgood=0.;
325
326             for(Int_t i=0;i<2;i++){
327               if(hlayer[lay-3]) contentgood=hlayer[lay-3]->GetBinContent(2*det+i-1,lad);
328               if(cal->IsWingBad(i))
329                 { 
330                   excludeddriftregion++; 
331                   excludeddrperlayer[lay-3]++; 
332                   if(AliITSQADataMakerRec::AreEqual(contentgood,0.)==kFALSE){
333                     AliError(Form("The side %d of the module %d (layer %i, ladder %i det %i ) excluded from the acquisition, took data \n ",i,module,lay,lad,det));
334                     exactivedriftregion++; 
335                     exactivedrperlayer[lay-3]++;
336                     filleddr++;
337                     filleddriftregion[lay-3]++;
338                   }
339                 }//end wingbad
340               else{
341                 if(AliITSQADataMakerRec::AreEqual(contentgood,0.)==kTRUE)
342                   {
343                     AliWarning(Form("The side %d of the module %d (layer %i, ladder %i det %i ) is in acquisition, but it didn't take data\n ",i,module, lay, lad, det));
344                   }
345                 else 
346                   {
347                     totside++;
348                   }
349                 totactiveside++;
350               }
351             }//end for
352             if(totside==0){
353             AliWarning(Form("The  module %d (layer %i, ladder %i det %i ) is in acquisition, but it didn't take data\n ",module, lay, lad, det));
354               emptymodules[lay-3]++;
355               empty++;
356
357             }
358               else 
359                 if(totside==2){
360                 filledmodules[lay-3]++;
361                 filled++;
362                 }
363                 else
364                   if(totside==1)
365                     {
366                       //                      emptydr++;
367                       //emptydriftregion[lay-3]++; //it has to be empty
368                       emptydriftregion[lay-3]++; 
369                       emptydr++;
370                       filleddr++;
371                       filleddriftregion[lay-3]++;
372                     }
373             if(totactiveside==1)
374               {
375                 activedriftregion++;
376                 activedrperlayer[lay-3]++;
377               }else if(totactiveside==2)
378               {
379                 active++;
380                 activemoduleperlayer[lay-3]++;
381               }
382
383           }
384         }//end for
385         AliInfo(Form("In total %d modules and %d single drift regions took data.\n ",filled, filleddr));
386         AliInfo(Form("In total %d modules and %d single drift regions were empty\n",empty, emptydr));
387         for(Int_t i=0;i<2;i++)
388           {
389             AliInfo(Form("Layer %i   \tempty modules %i             \t filled modules %i\n", i+3,emptymodules[i], filledmodules[i]));
390             AliInfo(Form("Layer %i   \tempty single drift regions %i \t filled single drift regions %i\n",i+3,emptydriftregion[i], filleddriftregion[i]));
391           }//end else layers
392         emptysum=emptymodules[0]+emptymodules[1];
393         emptydiff=emptysum-excluded;
394         emptyactivemoduleperlayer[0]=emptymodules[0]- excludedmoduleperlayer[0];
395         emptyactivemoduleperlayer[1]=emptymodules[1]- excludedmoduleperlayer[1];
396
397         emptydrsum=emptydriftregion[0]+emptydriftregion[1];
398         emptydrdiff=emptydrsum-excludeddriftregion;
399         emptyactivedrperlayer[0]=emptydriftregion[0]- excludeddrperlayer[0];
400         emptyactivedrperlayer[1]=emptydriftregion[1]- excludeddrperlayer[1];
401
402         Int_t numlimit=1000;
403
404         if(emptysum>excluded||emptydrsum>excludeddriftregion){
405           AliWarning(Form(" %i good module(s) and %i good single drift regions didn't take data! \n",emptydiff,emptydrdiff));
406           AliWarning(Form(" Layer 3: %i good module(s) and %i good single drift regions didn't take data! \n",emptyactivemoduleperlayer[0] ,emptyactivedrperlayer[0] ));
407           AliWarning(Form(" Layer 4: %i good module(s) and %i good single drift regions didn't take data! \n",emptyactivemoduleperlayer[1] ,emptyactivedrperlayer[1] ));
408           //printf("========================= %d",AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::kCosmic));
409           if((AliQAv1::Instance(AliQAv1::GetDetIndex("ITS")))->IsEventSpecieSet(AliRecoParam::kCosmic)==kFALSE){     
410             
411             results1.Form("%i good module(s) and %i good drift regions didn't take data!",emptydiff,emptydrdiff);
412             if(neventsraw<numlimit)
413               {
414                 results2.Form(" Events %d .Too few events.DO NOT CALL the Expert ",neventsraw);
415                 color=5;
416                 sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
417               }
418             else
419               {
420                 results2.Form(" Events %d .Follow the TWiki instruction and call the Expert ",neventsraw);
421                 color=2;
422                 sddQACheckerValue=fHighSDDValue[AliQAv1::kERROR];
423               }
424           }
425           else
426             if((AliQAv1::Instance(AliQAv1::GetDetIndex("ITS")))->IsEventSpecieSet(AliRecoParam::kCosmic)==kTRUE)
427               {
428                 numlimit=10000;
429                 if(neventsraw<numlimit)
430                   {
431                     AliWarning(Form("This is a cosmic run. Some module and drift region are empty but all is OK. "));
432                     results1.Form("OK. Thi is a cosmic run. you need a lot of events");
433                     results2.Form("%i good module(s) and %i good drift are empty! DO NOT CALL THE EXPERT",emptydiff,emptydrdiff);
434                     color=5;
435                     sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
436                   }
437                 else
438                   {
439                     results1.Form("%i good module(s) and %i good drift region(s) have not recpoints!",emptydiff,emptydrdiff);
440                     results2.Form(" Events %d .Follow the TWiki instruction and call the Expert ",neventsraw);
441                     color=2;
442                     sddQACheckerValue=fHighSDDValue[AliQAv1::kERROR];
443                   }
444               }
445         }
446         
447         if(exactive==0 && emptydiff==0 && exactivedriftregion==0 && emptydrdiff==0){
448           AliInfo(Form("All the active modules (%i) and single drift regions (%i) are in acquisition. The number of excluded modules are %i and the excluded single drift regions are %i\n",active,activedriftregion,excluded,excludeddriftregion));
449           results1.Form("OK.");
450           results2.Form(" All active modules and drift regions in acquisition");
451           color=3;
452           sddQACheckerValue=fHighSDDValue[AliQAv1::kINFO];
453         }
454         if(exactive!=0||exactivedriftregion!=0){
455           AliError(Form("%i modules and %i single  drift regions excluded from the acquisition took data. Active modules%i single drift region %i \n ",exactive,exactivedriftregion,active,activedriftregion));
456           AliError(Form("Layer 3: %i modules and %i single  drift regions excluded from the acquisition took data. Active modules%i single drift region %i \n ",exactivemoduleperlayer[0],exactivedrperlayer[0],activemoduleperlayer[0],activedrperlayer[0]));
457           AliError(Form("Layer 3: %i modules and %i single  drift regions excluded from the acquisition took data. Active modules%i single drift region %i \n ",exactivemoduleperlayer[1],exactivedrperlayer[1],activemoduleperlayer[1],activedrperlayer[1]));
458           results1.Form("%i modules and %i drift region excluded from the acquisition took data",exactive,exactivedriftregion);
459           results2.Form("Follow the TWiki instructions and Call the SDD expert ");
460           color=2;      
461           sddQACheckerValue=fHighSDDValue[AliQAv1::kERROR];
462         }
463         if(excluded==exactive||excludeddriftregion==exactivedriftregion){
464           AliError(Form("All the modules (%d) or single drift regions (%d) excluded from the acquisition  took data!\n  Active modules %i \t Active drfift regions %i\n",excluded,excludeddriftregion,active,activedriftregion));
465           results1.Form("All the modules (%d) or drift regions (%d) excluded from the acquisition took data!",excluded,excludeddriftregion );
466           results2.Form("Follow the TWiki instructions and Call the SDD expert ");
467           color=6;
468           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
469         }
470         if(active==0||activedriftregion==0){
471           AliError(Form("No modules or single drift regions took data: excluded %i \t excluded active %i \n\t\t excluded single drift regions %i \t excluded active drift regions %i \n", excluded, exactive, excludeddriftregion, exactivedriftregion)); 
472           results1.Form("No modules or drift region took data: excluded modules %i  excluded drift regions %i ", excluded, excludeddriftregion );
473           results2.Form("Follow the TWiki instructions and Call the SDD expert ");
474           color=6;
475           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
476         }
477
478         TPaveText *pave[2];
479         next.Begin();
480
481         while( (hdata=dynamic_cast<TH1* >(next())) )
482           {
483             if (hdata){
484               TString hname=hdata->GetName();
485               if(hname.Contains("SDDphizL3") || hname.Contains("SDDphizL4")){
486                 if(hname.Contains("NORM"))continue;
487                 //AliInfo("========================================Found histo 11\n");
488                 Int_t lay=0;
489                 if(hname.Contains("3"))lay=0;
490                 else if(hname.Contains("4"))lay=1;
491                 pave[lay]=new TPaveText(0.3,0.88,0.9,0.99,"NDC");
492                 pave[lay]->AddText(results1.Data());
493                 pave[lay]->AddText(results2.Data());
494                 pave[lay]->SetFillColor(color);
495                 pave[lay]->SetBorderSize(1);
496                 pave[lay]->SetLineWidth(1);
497                 hdata->GetListOfFunctions()->Add(pave[lay]);
498               }
499               else
500                 if(hname.Contains("SDDRawDataCheck"))
501                   {
502                     
503                     //AliInfo("========================================Found histo\n");
504                     ((TH1F*)hdata)->SetBinContent(5,active);
505                     ((TH1F*)hdata)->SetBinContent(6,filled);
506                     ((TH1F*)hdata)->SetBinContent(7,activedriftregion);
507                     ((TH1F*)hdata)->SetBinContent(8,filleddr);
508                     ((TH1F*)hdata)->SetBinContent(9,excluded);
509                     ((TH1F*)hdata)->SetBinContent(10,empty);
510                     ((TH1F*)hdata)->SetBinContent(11,excludeddriftregion);
511                     ((TH1F*)hdata)->SetBinContent(12,emptydr);
512                     ((TH1F*)hdata)->SetBinContent(13,exactive);
513                     ((TH1F*)hdata)->SetBinContent(14,emptydiff);
514                     ((TH1F*)hdata)->SetBinContent(15,exactivedriftregion);
515                     ((TH1F*)hdata)->SetBinContent(16,emptydr);
516                     
517                     //layer 3
518                     ((TH1F*)hdata)->SetBinContent(19,activemoduleperlayer[0]);
519                     ((TH1F*)hdata)->SetBinContent(20,filledmodules[0]);
520                     ((TH1F*)hdata)->SetBinContent(21,activedrperlayer[0]);
521                     ((TH1F*)hdata)->SetBinContent(22,filleddriftregion[0]);
522                     ((TH1F*)hdata)->SetBinContent(23,excludedmoduleperlayer[0]);
523                     ((TH1F*)hdata)->SetBinContent(24,emptymodules[0]);
524                     ((TH1F*)hdata)->SetBinContent(25,excludeddrperlayer[0]);
525                     ((TH1F*)hdata)->SetBinContent(26,emptydriftregion[0]);
526                     ((TH1F*)hdata)->SetBinContent(27,exactivemoduleperlayer[0]);
527                     ((TH1F*)hdata)->SetBinContent(28,emptyactivemoduleperlayer[0]);
528                     ((TH1F*)hdata)->SetBinContent(29,activedrperlayer[0]);
529                     ((TH1F*)hdata)->SetBinContent(30,emptyactivedrperlayer[0]);
530                     
531                     //layer 4
532                     ((TH1F*)hdata)->SetBinContent(33,activemoduleperlayer[1]);
533                     ((TH1F*)hdata)->SetBinContent(34,filledmodules[1]);
534                     ((TH1F*)hdata)->SetBinContent(35,activedrperlayer[1]);
535                     ((TH1F*)hdata)->SetBinContent(36,filleddriftregion[1]);
536                     ((TH1F*)hdata)->SetBinContent(37,excludedmoduleperlayer[1]);
537                     ((TH1F*)hdata)->SetBinContent(38,emptymodules[1]);
538                     ((TH1F*)hdata)->SetBinContent(39,excludeddrperlayer[1]);
539                     ((TH1F*)hdata)->SetBinContent(40,emptydriftregion[1]);
540                     ((TH1F*)hdata)->SetBinContent(41,exactivemoduleperlayer[1]);
541                     ((TH1F*)hdata)->SetBinContent(42,emptyactivemoduleperlayer[1]);
542                     ((TH1F*)hdata)->SetBinContent(43,activedrperlayer[1]);
543                     ((TH1F*)hdata)->SetBinContent(44,emptyactivedrperlayer[1]);
544                     //break; 
545                   }
546             }//if hdata
547             
548           }//end while 
549         
550       }//end else 
551       delete hmodule;
552       hmodule=NULL;
553       for(Int_t i=0;i<2;i++) {
554         delete hlayer[i];
555         hlayer[i]=NULL;
556       }//end for
557
558     }//end raw
559       
560       break;
561       
562   case AliQAv1::kNULLTASK:{
563     AliInfo(Form("No Check on %s\n",AliQAv1::GetAliTaskName(index))); 
564     sddQACheckerValue=1.;
565   }
566     break;
567     
568   case AliQAv1::kREC:
569     {
570       Int_t uidrec=list->GetUniqueID();
571       AliInfo(Form("Check on %s\n",AliQAv1::GetAliTaskName(index))); 
572       if(uidrec==20){
573         //recpoints
574         if (list->GetEntries() == 0){ //check if the list is empty
575           //printf("sddQACheckerValue = %f \t value %f\n",sddQACheckerValue,fHighSDDValue[AliQAv1::kFATAL]);
576           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL]; 
577           //break;                      
578         }//end if getentries
579       
580
581       TH1 *hmodule=NULL;
582       TH2 *hlayer[2]; 
583       hdata=NULL;
584       for(Int_t i=0;i<2;i++)hlayer[i]=NULL;
585
586       //check counters
587       Int_t emptymodules[2], filledmodules[2],emptyladders[2],filledladders[2],emptydriftregion[2], filleddriftregion[2], excludedmoduleperlayer[2], excludeddrperlayer[2], activemoduleperlayer[2],activedrperlayer[2],exactivemoduleperlayer[2],exactivedrperlayer[2];
588       Int_t excluded=0;            //excluded modules  
589       Int_t excludeddriftregion=0; //excluded single drift region
590       Int_t active=0;              //active modules  
591       Int_t activedriftregion=0;   //active single drift region
592       Int_t exactive=0;            //excluded modules but taking data
593       Int_t exactivedriftregion=0; //excluded single drift region but taking data   
594       Int_t empty=0;
595       Int_t filled=0;
596       Int_t emptydr=0;
597       Int_t filleddr=0;
598       //Int_t emptyactivemodule=0;
599       Int_t emptyactivemoduleperlayer[2];
600       //Int_t emptydractivemodule=0;
601       Int_t emptyactivedrperlayer[2];
602       Int_t emptysum=0;
603       Int_t emptydiff=0;
604       Int_t emptydrsum=0;
605       Int_t emptydrdiff=0;
606
607     for(Int_t i=0;i<2;i++)
608       {
609         emptymodules[i]=0; 
610         filledmodules[i]=0; 
611         emptyladders[i]=0; 
612         filledladders[i]=0; 
613         emptydriftregion[i]=0;
614         filleddriftregion[i]=0; 
615         excludedmoduleperlayer[i]=0;
616         excludeddrperlayer[i]=0;
617         activemoduleperlayer[i]=0;
618         activedrperlayer[i]=0;
619         exactivemoduleperlayer[i]=0;
620         exactivedrperlayer[i]=0;
621         emptyactivemoduleperlayer[i]=0;
622         emptyactivedrperlayer[i]=0;
623       }  
624
625     Int_t neventsrecpoints=0;
626
627       while( (hdata = dynamic_cast<TH1* >(next())) ){
628         if (hdata){
629           TString hname=hdata->GetName();
630
631           if(hname.Contains("SDDRecPointCheck"))
632             { 
633               neventsrecpoints=(Int_t)hdata->GetBinContent(1); 
634               //break;
635             }
636           else{continue;}
637         }//end if hdata
638       }//end while
639
640       next.Begin();
641
642         while((hdata=dynamic_cast<TH1* >(next()))){
643           if (hdata){
644             TString hname=hdata->GetName();
645             if(hname.Contains("_RelativeOccupancy")) {
646               Float_t threshold = hdata->GetMean() + 4*hdata->GetRMS();
647               if(hname.Contains("L3")) AliInfo(Form("SDD check number 3: L3 mean: %f, rms: ,%f",hdata->GetMean(),hdata->GetRMS()));
648               if(hname.Contains("L4")) AliInfo(Form("SDD check number 4: L4 mean: %f, rms: ,%f",hdata->GetMean(),hdata->GetRMS()));
649               Int_t aboveThreshold = 0;
650               for(Int_t k=0; k<= ((Int_t)hdata->GetNbinsX()); k++) {
651                 if(hdata->GetBinLowEdge(k) > threshold) aboveThreshold += (Int_t)(hdata->GetBinContent(k));
652               }
653               Float_t fractionAboveThreshold=0.;
654               if(hdata->GetEntries()>0.) fractionAboveThreshold = ((Float_t) aboveThreshold)/hdata->GetEntries();
655               if(hname.Contains("L3")) AliInfo(Form("SDD check number 3, L3: RecPoints fractionAboveThreshold: %f",fractionAboveThreshold));
656               if(hname.Contains("L4")) AliInfo(Form("SDD check number 4, L4: RecPoints fractionAboveThreshold: %f",fractionAboveThreshold));
657               if(fractionAboveThreshold > fThresholdForRelativeOccupancy) { 
658                 sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
659                 if(hname.Contains("L3")) AliInfo(Form("SDD check number 3: Set Warning (L3 RecPoints)"));
660                 if(hname.Contains("L4")) AliInfo(Form("SDD check number 4: Set Warning (L4 RecPoints)"));
661               }
662             }
663             if(hname.Contains("Rec2Raw") && !hname.Contains("2D")) {
664               //Float_t threshold = 0.;
665               if(hname.Contains("L3")) AliInfo(Form("SDD check number 5: L3 R2R mean: %f, rms: ,%f",((TH1F *) hdata)->GetMean(),((TH1F *) hdata)->GetRMS()));
666               if(hname.Contains("L4")) AliInfo(Form("SDD check number 6: L4 R2R mean: %f, rms: ,%f",((TH1F *) hdata)->GetMean(),((TH1F *) hdata)->GetRMS()));
667               Int_t belowThreshold = 0;
668               for(Int_t k=0; k<=((TH1F *)hdata)->GetNbinsX(); k++) {
669                 if(((TH1F *) hdata)->GetBinLowEdge(k) < fThresholdForRecToRawRatio) belowThreshold += ((Int_t)((TH1F *) hdata)->GetBinContent(k));
670               }
671               Double_t fractionBelowThreshold =0.;
672               Double_t entries3=((TH1F *)hdata)->GetEntries();
673               if(entries3>0.001)fractionBelowThreshold = ((Double_t)(belowThreshold))/entries3;
674               else{ AliWarning(Form("No entries on %s. The check will retuns zero.\n",hdata->GetName() )); }
675               if(hname.Contains("L3")) AliInfo(Form("SDD check number 5, L3: RecPoints2Raws fractionBelowThreshold: %f",fractionBelowThreshold));
676               if(hname.Contains("L4")) AliInfo(Form("SDD check number 6, L4: RecPoints2Raws fractionBelowThreshold: %f",fractionBelowThreshold));
677               if(fractionBelowThreshold > fThresholdForRelativeOccupancy) { 
678                 sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
679                 if(hname.Contains("L3")) AliInfo(Form("SDD check number 5: Set Warning (L3 RecPoints2Raws)"));
680                 if(hname.Contains("L4")) AliInfo(Form("SDD check number 6: Set Warning (L4 RecPoints2Raws)"));
681               }
682             }
683             if(hname.Contains("dedx")) {
684               if(hname.Contains("L3")) AliInfo(Form("SDD check number 7: L3 average charge: %f, rms: ,%f",hdata->GetMean(),hdata->GetRMS()));
685               if(hname.Contains("L4")) AliInfo(Form("SDD check number 8: L4 average charge: %f, rms: ,%f",hdata->GetMean(),hdata->GetRMS()));
686             }//end if dedx
687           if(hname.Contains("SDDModPatternRP")){
688             if(hname.Contains("NORM")) continue;
689             hmodule=(TH1*)hdata->Clone();
690             entries= hdata->GetEntries();
691             if(AliITSQADataMakerRec::AreEqual(entries,0.)){AliWarning(Form("===================>>>>>> No entries in  %s \n",hname.Data()));sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];}//endif entries
692             else{
693               int modmax=hdata->GetNbinsX();
694               Double_t content=0;
695               Int_t llay=0;
696               for(Int_t i=1;i<=modmax;i++)
697                 {
698                   if(i<85)llay=0;
699                   else llay=1;
700                   content=hdata->GetBinContent(i);
701                   if(AliITSQADataMakerRec::AreEqual(content,0.))
702                     {
703                     empty++;
704                     emptymodules[llay]++;
705                     } 
706                   else 
707                     {
708                       filled++;
709                       filledmodules[llay]++;
710                     }
711                 }//end for
712               //output of the check at the level of the modules. Drift region in the following checks
713
714               AliInfo(Form(" %s : empty modules %i \t filled modules %i",hname.Data(), empty, filled));
715               AliInfo(Form(" %s : Layer 3 empty modules %i \t filled modules %i",hname.Data(), emptymodules[0], filledmodules[0]));
716               AliInfo(Form(" %s : Layer 4 empty modules %i \t filled modules %i",hname.Data(), emptymodules[1], filledmodules[1]));
717             }//end else pattern entries !=0
718           } //modpattern (1d histogram)                 
719
720           if(hname.Contains("SDDModPatternL3RP") || hname.Contains("SDDModPatternL4RP")){if(hname.Contains("NORM"))continue;
721             Int_t layer=0;
722             if(hname.Contains("3"))layer=0;
723             else  if(hname.Contains("4"))layer=1;
724             entries2[layer]=hdata->GetEntries();
725             if(entries2[layer]==0){AliWarning(Form("===================>>>>>> No entries in  %s \n",hname.Data()));
726               sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];}//end if getentries
727             else{
728               Int_t layer1=0;
729               if(hname.Contains("3"))layer1=0;
730               else  if(hname.Contains("4"))layer1=1;
731               TH2* htemp=dynamic_cast<TH2*>(hdata);
732               if(htemp){
733                 hlayer[layer1]=(TH2*)htemp->Clone();
734                 hlayer[layer1]->SetName(Form("%s_copy",hname.Data()));
735                 //hlayer[layer1]->RebinX(2);
736                 int modmay=hlayer[layer1]->GetNbinsY();
737                 TH1D* hproj= hlayer[layer1]->ProjectionY();
738                 Double_t ladcontent=0;
739                 for(Int_t i=1;i<=modmay;i++) {//loop on the ladders
740                   ladcontent=hproj->GetBinContent(i);
741                   if(AliITSQADataMakerRec::AreEqual(ladcontent,0.)) emptyladders[layer1]++;
742                   else filledladders[layer1]++;}//end for
743                 AliInfo(Form(" %s : empty ladders %i \t filled ladders %i\n",hname.Data(), emptyladders[layer1], filledladders[layer1]));//end else layer 3
744                 delete hproj;
745                 hproj=NULL;
746               }//end if htemp
747             }//end else entries !=0
748           }//end check on phiz
749           }//end if hdata
750         }//end while                            
751       for(Int_t ii=0;ii<2;ii++)
752         {
753           filledmodules[ii]=0;
754           emptymodules[ii]=0;
755         }
756       filled=0;
757       empty=0;
758       if(AliITSQADataMakerRec::AreEqual(entries,0.)&& AliITSQADataMakerRec::AreEqual(entries2[0],0.)&& AliITSQADataMakerRec::AreEqual(entries2[1],0.)) break;
759       //else{
760       if(hmodule || (hlayer[0] && hlayer[1])){
761         for(Int_t imod=0;imod<fgknSDDmodules;imod++){
762           Int_t lay=0;
763           Int_t lad=0;
764           Int_t det=0;
765           Int_t module=0;
766           module=imod+fgkmodoffset;
767           AliITSCalibrationSDD * cal=(AliITSCalibrationSDD*)fCalibration->At(imod);
768           if(cal==0) { continue;}
769           AliITSgeomTGeo::GetModuleId(module,lay,lad,det);
770           if (cal->IsBad()){
771             excluded++;
772             excludedmoduleperlayer[lay-3]++;
773             Double_t content=0.;
774             Double_t contentlayer[2];
775             for(Int_t i=0;i<2;i++)contentlayer[i]=0.;
776             if(hmodule)content=hmodule->GetBinContent(imod+1);//if expert bit is active the histogram will be stored in the QA file otherwise the histogram will not be written on the logbook
777             //      if(hlayer[lay-3]) contentlayer[lay-3]=hlayer[lay-3]->GetBinContent(det,lad);
778             if(AliITSQADataMakerRec::AreEqual(content,0.)== kFALSE) {
779               filledmodules[lay-3]++;
780               filled++;
781               AliError(Form("The module %d (layer %i, ladder %i det %i ) excluded from the acquisition,has recpoints \n ",module,lay,lad,det));
782               exactive++;
783               exactivemoduleperlayer[lay-3]++;
784             } else if(AliITSQADataMakerRec::AreEqual(content,0.)) 
785               {
786                 emptymodules[lay-3]++; //it has to be empty
787                 empty++;
788               }
789           } else {
790             Int_t totside=0;
791             Int_t totactiveside=0;
792             //Int_t totbadside=0;
793             Double_t contentgood=0.;
794
795             for(Int_t i=0;i<2;i++){
796               if(hlayer[lay-3]) contentgood=hlayer[lay-3]->GetBinContent(2*det+i-1,lad);
797               if(cal->IsWingBad(i))
798                 { 
799                   excludeddriftregion++; 
800                   excludeddrperlayer[lay-3]++; 
801                   if(AliITSQADataMakerRec::AreEqual(contentgood,0.)==kFALSE){
802                     AliError(Form("The side %d of the module %d (layer %i, ladder %i det %i ) excluded from the acquisition, has recpoints \n ",i,module,lay,lad,det));
803                     exactivedriftregion++; 
804                     exactivedrperlayer[lay-3]++;
805                     filleddr++;
806                     filleddriftregion[lay-3]++;
807                   }
808                 }//end wingbad
809               else{
810                 if(AliITSQADataMakerRec::AreEqual(contentgood,0.)==kTRUE)
811                   {
812                     AliWarning(Form("The side %d of the module %d (layer %i, ladder %i det %i ) is in acquisition, but no recpoints are present\n ",i,module, lay, lad, det));
813                   }
814                 else 
815                   {
816                     totside++;
817                   }
818                 totactiveside++;
819               }
820             }//end for
821             if(totside==0){
822             AliWarning(Form("The  module %d (layer %i, ladder %i det %i ) is in acquisition, but no recpoints are present \n ",module, lay, lad, det));
823               emptymodules[lay-3]++;
824               empty++;
825
826             }
827               else 
828                 if(totside==2){
829                 filledmodules[lay-3]++;
830                 filled++;
831                 }
832                 else
833                   if(totside==1)
834                     {
835                       //                      emptydr++;
836                       //emptydriftregion[lay-3]++; //it has to be empty
837                       emptydriftregion[lay-3]++; 
838                       emptydr++;
839                       filleddr++;
840                       filleddriftregion[lay-3]++;
841                     }
842             if(totactiveside==1)
843               {
844                 activedriftregion++;
845                 activedrperlayer[lay-3]++;
846               }else if(totactiveside==2)
847               {
848                 active++;
849                 activemoduleperlayer[lay-3]++;
850               }
851
852           }
853         }//end for
854         AliInfo(Form("In total %d modules and %d single drift regions have recpoints.\n ",filled, filleddr));
855         AliInfo(Form("In total %d modules and %d single drift regions are empty\n",empty, emptydr));
856         for(Int_t i=0;i<2;i++)
857           {
858             AliInfo(Form("Layer %i   \tempty modules %i             \t filled modules %i\n", i+3,emptymodules[i], filledmodules[i]));
859             AliInfo(Form("Layer %i   \tempty single drift regions %i \t filled single drift regions %i\n",i+3,emptydriftregion[i], filleddriftregion[i]));
860           }//end else layers
861         emptysum=emptymodules[0]+emptymodules[1];
862         emptydiff=emptysum-excluded;
863         emptyactivemoduleperlayer[0]=emptymodules[0]- excludedmoduleperlayer[0];
864         emptyactivemoduleperlayer[1]=emptymodules[1]- excludedmoduleperlayer[1];
865
866         emptydrsum=emptydriftregion[0]+emptydriftregion[1];
867         emptydrdiff=emptydrsum-excludeddriftregion;
868         emptyactivedrperlayer[0]=emptydriftregion[0]- excludeddrperlayer[0];
869         emptyactivedrperlayer[1]=emptydriftregion[1]- excludeddrperlayer[1];
870
871         Int_t numlimit=1000;
872         if(emptysum>excluded||emptydrsum>excludeddriftregion){ 
873           AliWarning(Form(" %i good module(s) and %i good single drift regions have not recpoints! \n",emptydiff,emptydrdiff));
874           AliWarning(Form(" Layer 3: %i good module(s) and %i good single drift regions have not recpoints! \n",emptyactivemoduleperlayer[0] ,emptyactivedrperlayer[0] ));
875           AliWarning(Form(" Layer 4: %i good module(s) and %i good single drift regions have not recpoints! \n",emptyactivemoduleperlayer[1] ,emptyactivedrperlayer[1] ));
876           
877           //sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
878           Int_t numlimits=1000;   
879
880           results1.Form("%i good module(s) and %i good drift region(s) have not recpoints!",emptydiff,emptydrdiff);
881           if((AliQAv1::Instance(AliQAv1::GetDetIndex("ITS")))->IsEventSpecieSet(AliRecoParam::kCosmic)==kFALSE)
882             {
883               if(neventsrecpoints<numlimits)
884                 {
885                   results2.Form(" Events %d .Too few events.DO NOT CALL the Expert ",neventsrecpoints);
886                   color=5;
887                   sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
888                 }
889               else
890                 {
891                   results2.Form(" Events %d .Follow the TWiki instruction and call the Expert ",neventsrecpoints);
892                   color=2;
893                   sddQACheckerValue=fHighSDDValue[AliQAv1::kERROR];
894                 }
895             }
896           else
897             if((AliQAv1::Instance(AliQAv1::GetDetIndex("ITS")))->IsEventSpecieSet(AliRecoParam::kCosmic)==kTRUE)
898               {
899                 numlimit=10000;
900                 if(neventsrecpoints<numlimit)
901                   {
902                     AliWarning(Form("This is a cosmic run. Some module and drift region are empty but all is OK. "));
903                     results1.Form("OK. Thi is a cosmic run. You need a lot of events");
904                     results2.Form("%i good module(s) and %i good drift are empty! DO NOT CALL THE EXPERT",emptydiff,emptydrdiff);
905                     color=5;
906                     sddQACheckerValue=fHighSDDValue[AliQAv1::kWARNING];
907                   }
908                 else
909                   {
910                     results1.Form("%i good module(s) and %i good drift region(s) have not recpoints!",emptydiff,emptydrdiff);
911                     results2.Form(" Events %d .Follow the TWiki instruction and call the Expert ",neventsrecpoints);
912                     color=2;
913                     sddQACheckerValue=fHighSDDValue[AliQAv1::kERROR];
914                   }
915               }
916         }
917         
918       
919
920         if(exactive==0 && emptydiff==0 && exactivedriftregion==0 && emptydrdiff==0){
921           AliInfo(Form("All the active modules (%i) and single drift regions (%i) are in acquisition. The number of excluded modules are %i and the excluded single drift regions are %i\n",active,activedriftregion,excluded,excludeddriftregion));
922           results1.Form("OK.");
923           results2.Form(" All active modules have recpoints");
924           color=3;
925           sddQACheckerValue=fHighSDDValue[AliQAv1::kINFO];
926         }
927         if(exactive!=0||exactivedriftregion!=0){
928           AliError(Form("%i modules and %i single  drift regions excluded from the acquisition have recpoints. Active modules %i single drift region %i \n ",exactive,exactivedriftregion,active,activedriftregion));
929           AliError(Form("Layer 3: %i modules and %i single  drift regions excluded from the acquisition have recpoints. Active modules %i single drift region %i \n ",exactivemoduleperlayer[0],exactivedrperlayer[0],activemoduleperlayer[0],activedrperlayer[0]));
930           AliError(Form("Layer 3: %i modules and %i single  drift regions excluded from the acquisition have recpoints. Active modules %i single drift region %i \n ",exactivemoduleperlayer[1],exactivedrperlayer[1],activemoduleperlayer[1],activedrperlayer[1]));
931           results1.Form("%i modules and %i drift region excluded from the acquisition have recpoints",exactive,exactivedriftregion);
932           results2.Form("Follow the TWiki instructions and Call the SDD expert ");
933           color=2;      
934           sddQACheckerValue=fHighSDDValue[AliQAv1::kERROR];
935         }
936         if(excluded==exactive||excludeddriftregion==exactivedriftregion){
937           AliError(Form("All the modules (%d) or single drift regions (%d) excluded from the acquisition have recpoints!\n  Active modules %i \t Active drfift regions %i\n",excluded,excludeddriftregion,active,activedriftregion));
938           results1.Form("All the modules (%d) or drift regions (%d) excluded from the acquisition have recpoints!",excluded,excludeddriftregion );
939           results2.Form("Follow the TWiki instructions and Call the SDD expert ");
940           color=6;
941           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
942         }
943         if(active==0||activedriftregion==0){
944           AliError(Form("No modules or single drift regions have recpoints: excluded %i \t excluded active %i \n\t\t excluded single drift regions %i \t excluded active drift regions %i \n", excluded, exactive, excludeddriftregion, exactivedriftregion)); 
945           results1.Form("No modules or drift region have recpoints: excluded modules %i  excluded drift regions %i ", excluded, excludeddriftregion );
946           results2.Form("Follow the TWiki instructions and Call the SDD expert ");
947           color=6;
948           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
949         }
950
951         TPaveText *pave[2];
952         next.Begin();
953
954         while( (hdata=dynamic_cast<TH1* >(next())) )
955           {
956             if (hdata){
957               TString hname=hdata->GetName();
958               if(hname.Contains("SDDModPatternL3RP") || hname.Contains("SDDModPatternL4RP")){
959                 if(hname.Contains("NORM"))continue;
960                 //AliInfo("========================================Found histo 11\n");
961                 Int_t lay=0;
962                 if(hname.Contains("3"))lay=0;
963                 else if(hname.Contains("4"))lay=1;
964                 pave[lay]=new TPaveText(0.3,0.88,0.9,0.99,"NDC");
965                 pave[lay]->AddText(results1.Data());
966                 pave[lay]->AddText(results2.Data());
967                 pave[lay]->SetFillColor(color);
968                 pave[lay]->SetBorderSize(1);
969                 pave[lay]->SetLineWidth(1);
970                 hdata->GetListOfFunctions()->Add(pave[lay]);
971               }
972               else
973                 if(hname.Contains("SDDRecPointCheck"))
974                   {
975                     
976                     //AliInfo("========================================Found histo\n");
977                     ((TH1F*)hdata)->SetBinContent(5,active);
978                     ((TH1F*)hdata)->SetBinContent(6,filled);
979                     ((TH1F*)hdata)->SetBinContent(7,activedriftregion);
980                     ((TH1F*)hdata)->SetBinContent(8,filleddr);
981                     ((TH1F*)hdata)->SetBinContent(9,excluded);
982                     ((TH1F*)hdata)->SetBinContent(10,empty);
983                     ((TH1F*)hdata)->SetBinContent(11,excludeddriftregion);
984                     ((TH1F*)hdata)->SetBinContent(12,emptydr);
985                     ((TH1F*)hdata)->SetBinContent(13,exactive);
986                     ((TH1F*)hdata)->SetBinContent(14,emptydiff);
987                     ((TH1F*)hdata)->SetBinContent(15,exactivedriftregion);
988                     ((TH1F*)hdata)->SetBinContent(16,emptydr);
989                     
990                     //layer 3
991                     ((TH1F*)hdata)->SetBinContent(19,activemoduleperlayer[0]);
992                     ((TH1F*)hdata)->SetBinContent(20,filledmodules[0]);
993                     ((TH1F*)hdata)->SetBinContent(21,activedrperlayer[0]);
994                     ((TH1F*)hdata)->SetBinContent(22,filleddriftregion[0]);
995                     ((TH1F*)hdata)->SetBinContent(23,excludedmoduleperlayer[0]);
996                     ((TH1F*)hdata)->SetBinContent(24,emptymodules[0]);
997                     ((TH1F*)hdata)->SetBinContent(25,excludeddrperlayer[0]);
998                     ((TH1F*)hdata)->SetBinContent(26,emptydriftregion[0]);
999                     ((TH1F*)hdata)->SetBinContent(27,exactivemoduleperlayer[0]);
1000                     ((TH1F*)hdata)->SetBinContent(28,emptyactivemoduleperlayer[0]);
1001                     ((TH1F*)hdata)->SetBinContent(29,activedrperlayer[0]);
1002                     ((TH1F*)hdata)->SetBinContent(30,emptyactivedrperlayer[0]);
1003                     
1004                     //layer 4
1005                     ((TH1F*)hdata)->SetBinContent(35,activemoduleperlayer[1]);
1006                     ((TH1F*)hdata)->SetBinContent(36,filledmodules[1]);
1007                     ((TH1F*)hdata)->SetBinContent(37,activedrperlayer[1]);
1008                     ((TH1F*)hdata)->SetBinContent(38,filleddriftregion[1]);
1009                     ((TH1F*)hdata)->SetBinContent(39,excludedmoduleperlayer[1]);
1010                     ((TH1F*)hdata)->SetBinContent(40,emptymodules[1]);
1011                     ((TH1F*)hdata)->SetBinContent(41,excludeddrperlayer[1]);
1012                     ((TH1F*)hdata)->SetBinContent(42,emptydriftregion[1]);
1013                     ((TH1F*)hdata)->SetBinContent(43,exactivemoduleperlayer[1]);
1014                     ((TH1F*)hdata)->SetBinContent(44,emptyactivemoduleperlayer[1]);
1015                     ((TH1F*)hdata)->SetBinContent(45,activedrperlayer[1]);
1016                     ((TH1F*)hdata)->SetBinContent(46,emptyactivedrperlayer[1]);
1017                     
1018                   }
1019             }//if hadata
1020             
1021           }//end while 
1022         
1023       }//end else 
1024       delete hmodule;
1025       hmodule=NULL;
1026       for(Int_t i=0;i<2;i++) {
1027         delete hlayer[i];
1028         hlayer[i]=NULL;
1029       }//end for      
1030
1031
1032       //sddQACheckerValue=1.;
1033       }//end recpoint list uid = 20
1034       else if(uidrec==40)
1035         {
1036           //digitsr
1037           if (list->GetEntries() == 0){ 
1038             sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
1039             break;
1040           } else{
1041         
1042             while( (hdata = dynamic_cast<TH1* >(next())) ){
1043               if (hdata){
1044                 if(hdata->GetEntries()==0)sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];
1045                 else {
1046                   TString hname=hdata->GetName();
1047                   if(hname.Contains("SDD DIGITS Module Pattern")) {
1048                     //see raws
1049                 
1050                     sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1051                   } else if(hname.Contains("SDD Anode Distribution")) {
1052                     sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1053                   } else if(hname.Contains("SDD Tbin Distribution")) {
1054                     //to do as rp
1055                     sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1056                   } else if(hname.Contains("SDD ADC Counts Distribution")) {
1057                     sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1058                   }//end adc counts
1059               
1060                 }//end entries !=0
1061               }//end hdata
1062             }//end while
1063           }//end else
1064           sddQACheckerValue=1.;
1065         }
1066
1067     }
1068     break;
1069   case AliQAv1::kANA:
1070     {
1071       AliInfo(Form("===================> No Check on %s\n",AliQAv1::GetAliTaskName(index)));
1072       sddQACheckerValue=1.; 
1073     }
1074     break;
1075   case AliQAv1::kESD:
1076     {
1077       AliInfo(Form("==================>  No Check on %s\n",AliQAv1::GetAliTaskName(index)));
1078       sddQACheckerValue=1.;
1079     } 
1080     break;
1081   case AliQAv1::kNTASK:{
1082     AliInfo(Form("==================>  No Check on %s\n",AliQAv1::GetAliTaskName(index))); 
1083     sddQACheckerValue=1.;
1084   }
1085     break;
1086   case AliQAv1::kSIM:{
1087     AliInfo(Form("Check on %s\n",AliQAv1::GetAliTaskName(index))); 
1088     Int_t uid=list->GetUniqueID();
1089     if(uid==60) {
1090       //digits
1091       if (list->GetEntries() == 0){ 
1092         sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
1093         break;
1094       } else{
1095         
1096         while( (hdata = dynamic_cast<TH1* >(next())) ){
1097           if (hdata){
1098             if(hdata->GetEntries()==0)sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];
1099             else {
1100               TString hname=hdata->GetName();
1101               if(hname.Contains("SDDDIGITSModulePattern")) {
1102                 //see raws
1103                 
1104                 sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1105               } else if(hname.Contains("SDDAnodeDistribution")) {
1106                 sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1107               } else if(hname.Contains("SDDTbinDistribution")) {
1108                 //to do as rp
1109                 sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1110               } else if(hname.Contains("SDDADCCountsDistribution")) {
1111                 sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1112               }//end adc counts
1113               
1114             }//end entries !=0
1115           }//end hdata
1116         }//end while
1117       }//end else
1118     } else if(uid==50) 
1119       {
1120         //hits
1121         if (list->GetEntries() == 0){ 
1122           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
1123           break;
1124         } 
1125         else{
1126           
1127           while( (hdata = dynamic_cast<TH1* >(next())) ){
1128             if (hdata){
1129               if(hdata->GetEntries()==0)sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];
1130               else {
1131                 TString hname=hdata->GetName();
1132                 if(hname.Contains("SDDHITSModulePattern")) {
1133                   //to do as raws
1134                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1135                 } else if(hname.Contains("SDDHITlenghtalonglocalYCoord")) {
1136                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1137                 } else if(hname.Contains("SDDHITlenghtalonglocalYCoordZoom")) {
1138                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1139                 } else if(hname.Contains("SDDDepositedEnergyDistribution")) {
1140                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1141                 }//end deposited energy
1142                 
1143               }//end entries !=0
1144             }//end hdata
1145           }//end while
1146         }//end else
1147       } else if(uid==70) 
1148       {
1149         //sdigits
1150         if (list->GetEntries() == 0){ 
1151           sddQACheckerValue=fHighSDDValue[AliQAv1::kFATAL];
1152           break;
1153         } else{
1154           
1155           while( (hdata = dynamic_cast<TH1* >(next())) ){
1156             if (hdata){
1157               if(hdata->GetEntries()==0)sddQACheckerValue += fStepBitSDD[AliQAv1::kFATAL];
1158               else {
1159                 TString hname=hdata->GetName();
1160                 if(hname.Contains("SDDSDIGITSModulePattern")) {
1161                   //to do as raws
1162                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1163                 } else if(hname.Contains("SDDAnodeDistribution")) {
1164                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1165                 } else if(hname.Contains("SDDTbinDistribution")) {
1166                   //to do as rp
1167                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1168                 } else if(hname.Contains("SDDADCCountsDistribution")) {
1169                   sddQACheckerValue += fStepBitSDD[AliQAv1::kINFO];    
1170                 }//end adc counts bindistribution
1171               }//end entries !=0
1172             }//end hdata
1173           }//end while
1174         }//end else
1175       }//end sdigits
1176     sddQACheckerValue=1.;
1177   }
1178     break;
1179     
1180   }//end switch
1181   
1182   fCalibration=NULL;
1183   if(hdata) delete hdata;
1184
1185
1186   return sddQACheckerValue;     
1187 }
1188
1189 //__________________________________________________________________
1190 void AliITSQASDDChecker::SetTaskOffset(Int_t taskoffset)
1191 {
1192   //set the number of the histograms already present in the list before the SDD histograms
1193   fSubDetOffset = taskoffset;
1194 }
1195
1196
1197 //__________________________________________________________________
1198 void AliITSQASDDChecker::SetStepBit(const Double_t *steprange)
1199 {
1200   //set the values of the step bit for each QA bit range calculated in the AliITSQAChecker class
1201   fStepBitSDD = new Double_t[AliQAv1::kNBIT];
1202   for(Int_t bit=0;bit<AliQAv1::kNBIT;bit++)
1203     {
1204       fStepBitSDD[bit]=steprange[bit];
1205     }
1206 }
1207
1208 //__________________________________________________________________
1209 void  AliITSQASDDChecker::SetSDDLimits(const Float_t *lowvalue, const Float_t * highvalue)
1210 {
1211   //set the low and high values in for each QA bit range calculated in the AliITSQAChecker class
1212   fLowSDDValue = new Float_t[AliQAv1::kNBIT];
1213   fHighSDDValue= new Float_t[AliQAv1::kNBIT];
1214
1215   for(Int_t bit=0;bit<AliQAv1::kNBIT;bit++)
1216     {
1217       fLowSDDValue[bit]=lowvalue[bit];
1218       fHighSDDValue[bit]= highvalue[bit];
1219     }
1220
1221 }
1222 //__________________________________________________________________
1223 Bool_t  AliITSQASDDChecker::MakeSDDImage( TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode)
1224 {
1225   //create the image for raws and recpoints. In the other case, the default methodof CheckerBase class will be used
1226   //
1227   Bool_t rval=kFALSE;
1228   fImage=(TCanvas**)AliQAChecker::Instance()->GetDetQAChecker(0)->GetImage();
1229
1230   switch(task)
1231     {
1232     case AliQAv1::kRAWS:{
1233       rval=MakeSDDRawsImage(list, task,mode);
1234     }
1235       break;
1236     case AliQAv1::kRECPOINTS:{ rval=MakeSDDRecPointsImage(list, task,mode); }
1237       break;
1238     case AliQAv1::kHITS:; case AliQAv1::kESDS:; case AliQAv1::kDIGITS:;case AliQAv1::kDIGITSR:;case AliQAv1::kSDIGITS:;case AliQAv1::kTRACKSEGMENTS:;case AliQAv1::kRECPARTICLES:; default:
1239     {
1240        rval=kFALSE;
1241        //AliQAChecker::Instance()->GetDetQAChecker(0)->MakeImage(list,task,mode);
1242     }
1243     break;
1244     case AliQAv1::kNULLTASKINDEX:; case  AliQAv1::kNTASKINDEX: 
1245       {AliWarning(Form("No histograms for this task ( %s ) \n", AliQAv1::GetTaskName(task).Data())); rval=kFALSE;}
1246       break;
1247     }
1248 return rval;  
1249 }
1250
1251
1252 //_______________________________________________________________________
1253 Bool_t AliITSQASDDChecker::MakeSDDRawsImage(TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode )
1254 {
1255   // MakeSDDRawsImage: raw data QA plots
1256
1257     for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
1258       //printf("-------------------------> %i \n", esIndex);
1259       if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0) 
1260           {//printf ("Nothing for %s \n", AliRecoParam::GetEventSpecieName(esIndex));
1261          continue;
1262         }
1263       else{
1264         const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
1265         if ( !fImage[esIndex] ) {
1266           fImage[esIndex] = new TCanvas(title, title,1280,980) ;
1267         }
1268         
1269         fImage[esIndex]->Clear() ; 
1270         fImage[esIndex]->SetTitle(title) ; 
1271         fImage[esIndex]->cd();
1272  
1273         TPaveText someText(0.015, 0.015, 0.98, 0.98);
1274         someText.AddText(title);
1275         someText.Draw(); 
1276         fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
1277         fImage[esIndex]->Clear() ; 
1278         Int_t nx =2; //TMath::Nint(TMath::Sqrt(nImages));
1279         Int_t ny =2; // nx  ; 
1280         //if (nx < TMath::Sqrt(nImages))
1281         //ny++ ;  
1282         fImage[esIndex]->Divide(nx, ny) ; 
1283         TIter nexthist(list[esIndex]) ; 
1284         TH1* hist = NULL ;
1285         Int_t npad = 1 ; 
1286         fImage[esIndex]->cd(npad); 
1287         fImage[esIndex]->cd(npad)->SetBorderMode(0) ;
1288         while ( (hist=static_cast<TH1*>(nexthist())) ) {
1289           //gPad=fImage[esIndex]->cd(npad)->GetPad(npad);
1290           TString cln(hist->ClassName()) ; 
1291           if ( ! cln.Contains("TH") )
1292             continue ;
1293           
1294           if(hist->TestBit(AliQAv1::GetImageBit())) {
1295             hist->GetXaxis()->SetTitleSize(0.02);
1296             hist->GetYaxis()->SetTitleSize(0.02);
1297             hist->GetXaxis()->SetLabelSize(0.02);
1298             hist->GetYaxis()->SetLabelSize(0.02);
1299             if(cln.Contains("TH2"))
1300               {
1301                 gPad->SetRightMargin(0.15);
1302                 gPad->SetLeftMargin(0.05);
1303                 hist->SetStats(0);
1304                 hist->SetOption("colz") ;
1305                 //hist->GetListOfFunctions()->FindObject("palette")->SetLabelSize(0.025);
1306                 //gPad->Update();
1307               }
1308             hist->DrawCopy() ; 
1309             fImage[esIndex]->cd(++npad) ; 
1310             fImage[esIndex]->cd(npad)->SetBorderMode(0) ; 
1311           }
1312         }
1313         fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
1314       }
1315     }
1316    return kTRUE;
1317 }
1318
1319
1320
1321
1322 //_______________________________________________________________________
1323 Bool_t AliITSQASDDChecker::MakeSDDRecPointsImage(TObjArray ** list, AliQAv1::TASKINDEX_t task, AliQAv1::MODE_t mode )
1324 {
1325   // MakeSDDRecPointsImage: rec point QA plots
1326
1327     for (Int_t esIndex = 0 ; esIndex < AliRecoParam::kNSpecies ; esIndex++) {
1328       if (! AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(esIndex)) || list[esIndex]->GetEntries() == 0) 
1329         {
1330         //printf ("Nothing for %s \n", AliQAv1::GetTaskName(task).Data()); 
1331         continue;
1332         }
1333       const Char_t * title = Form("QA_%s_%s_%s", GetName(), AliQAv1::GetTaskName(task).Data(), AliRecoParam::GetEventSpecieName(esIndex)) ; 
1334       if ( !fImage[esIndex] ) {
1335         fImage[esIndex] = new TCanvas(title, title,1280,980) ;
1336       }
1337       fImage[esIndex]->Clear() ; 
1338       fImage[esIndex]->SetTitle(title) ; 
1339       fImage[esIndex]->cd();
1340       fImage[esIndex]->SetBorderMode(0) ;  
1341       TPaveText someText(0.015, 0.015, 0.98, 0.98);
1342       someText.AddText(title);
1343       someText.Draw(); 
1344       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
1345       fImage[esIndex]->Clear() ; 
1346       Int_t nx =2; //TMath::Nint(TMath::Sqrt(nImages));
1347       Int_t ny =4; // nx  ; 
1348       //if (nx < TMath::Sqrt(nImages))
1349       //ny++ ;  
1350       fImage[esIndex]->Divide(nx, ny) ; 
1351       TIter nexthist(list[esIndex]) ; 
1352       TH1* hist = NULL ;
1353       Int_t npad = 1 ; 
1354       fImage[esIndex]->cd(npad) ; 
1355       fImage[esIndex]->cd(npad)->SetBorderMode(0) ; 
1356       while ( (hist=static_cast<TH1*>(nexthist())) ) {
1357         //gPad=fImage[esIndex]->cd(npad)->GetPad(npad);
1358         TString cln(hist->ClassName()) ;
1359         //printf("=====================> Class name %s \n",cln.Data()); 
1360         if ( ! cln.Contains("TH") )
1361           continue ;
1362         if(hist->TestBit(AliQAv1::GetImageBit())) {
1363             hist->GetXaxis()->SetTitleSize(0.02);
1364             hist->GetYaxis()->SetTitleSize(0.02);
1365             hist->GetXaxis()->SetLabelSize(0.02);
1366             hist->GetYaxis()->SetLabelSize(0.02);
1367           if(cln.Contains("TH1"))
1368             {
1369               hist->SetFillColor(kOrange+7);
1370               //SetFrameFillColor(kAzure-9);
1371               //hist->DrawCopy() ; 
1372             }
1373           if(cln.Contains("TH2"))
1374             {
1375               gPad->SetRightMargin(0.15);
1376               gPad->SetLeftMargin(0.05);
1377               hist->SetStats(0);
1378               hist->SetOption("colz") ;
1379               //              TPaletteAxis *paletta =(TPaletteAxis*)hist->GetListOfFunctions()->FindObject("palette");
1380               //paletta->SetLabelSize(0.025);
1381               //gPad->Update(); 
1382             }
1383           hist->DrawCopy();
1384           fImage[esIndex]->cd(++npad) ; 
1385           fImage[esIndex]->cd(npad)->SetBorderMode(0) ; 
1386         }
1387       }
1388       fImage[esIndex]->Print(Form("%s%s%d.%s", AliQAv1::GetImageFileName(), AliQAv1::GetModeName(mode), AliQAChecker::Instance()->GetRunNumber(), AliQAv1::GetImageFileFormat()), "ps") ; 
1389     }
1390     // }  
1391    return kTRUE;
1392 }