]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCQAChecker.cxx
Task for tower inter-calibration (A. De Falco)
[u/mrichter/AliRoot.git] / ZDC / AliZDCQAChecker.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 // --- ROOT system ---
18 #include <TH1F.h> 
19 #include <TIterator.h> 
20 #include <TString.h> 
21 #include <TPaveText.h> 
22 #include <TObjArray.h>
23 #include "TList.h"
24
25 // --- Standard library ---
26
27 // --- AliRoot header files ---
28 #include "AliLog.h"
29 #include "AliZDCQAChecker.h"
30
31 ClassImp(AliZDCQAChecker)
32
33 //____________________________________________________________________________
34 void AliZDCQAChecker::Check(Double_t *  test, AliQAv1::ALITASK_t index, TObjArray ** list,
35       const AliDetectorRecoParam * /*recoParam*/) 
36 {
37   // Checks the QA histograms on the input list: 
38   //
39   const char* taskName = AliQAv1::GetAliTaskName(index);
40   //printf("\n\tAliZDCQAChecker -> checking QA histos for task %s\n",taskName);
41   //
42   Int_t ihitHisto=0, idigHisto=0;
43   Int_t irecHisto=0, irawHisto=0, esdInd=0;
44
45   TObjArray messages;
46   messages.SetOwner(kTRUE);
47
48   for(Int_t specie = 0; specie<AliRecoParam::kNSpecies; specie++){
49     Int_t count = 0; 
50     if(!AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie))) 
51       continue ;
52     //printf("\tAliZDCQAChecker -> specie %d, AliRecoParam::ConvertIndex(specie) %d, AliRecoParam::kLowMult %d, IsEventSpecieSet(specie) %d\n",
53     //  specie, AliRecoParam::ConvertIndex(specie) ,AliRecoParam::kLowMult,
54     //  AliQAv1::Instance(AliQAv1::GetDetIndex(GetName()))->IsEventSpecieSet(AliRecoParam::ConvertIndex(specie)));
55     
56     // ====================================================================
57     //  Checks for p-p events
58     // ====================================================================
59     if(AliRecoParam::ConvertIndex(specie) == AliRecoParam::kLowMult){
60       if(list[specie]->GetEntries()==0){  
61         AliWarning("\t The list to be checked is empty!"); // nothing to check
62         return;
63       }
64       //AliDebug(AliQAv1::GetQADebugLevel(), Form("\n\tAliZDCQAChecker-> checking QA histograms for task %s\n\n",taskName));
65       TIter next(list[specie]); 
66       count = 0; 
67       TH1 * hdata;        
68       
69       Float_t res=0., percentageDiff=0.30;
70       Float_t meanZNA=0., meanZNC=0., meanZPA=0., meanZPC=0.;
71       Float_t pmCZNA=0., pmCZNC=0., pmCZPA=0., pmCZPC=0.;
72       Float_t pmQZNA=0., pmQZNC=0., pmQZPA=0., pmQZPC=0.;
73       Float_t sumADCZNA=0., sumADCZNC=0., sumADCZPA=0., sumADCZPC=0.;
74       Float_t adcCZNA=0., adcCZNC=0., adcCZPA=0., adcCZPC=0.;
75       Float_t adcQZNA=0., adcQZNC=0., adcQZPA=0., adcQZPC=0.;
76       
77       while((hdata = dynamic_cast<TH1 *>(next()))){
78         if(hdata){ 
79           // -------------------------------------------------------------------
80           if(index == AliQAv1::kSIM){
81             //AliDebug(AliQAv1::GetQADebugLevel(), Form("\tAliZDCQAChecker-> checking histo %s",hdata->GetName()));
82             // Check HITS histos
83             //
84             if(!(strncmp(hdata->GetName(),"hHits",5))){
85               if(hdata->GetEntries()>0){
86                 if(ihitHisto==0)      meanZNC = hdata->GetMean();
87                 else if(ihitHisto==1) meanZNA = hdata->GetMean();
88                 else if(ihitHisto==2) meanZPC = hdata->GetMean();
89                 else if(ihitHisto==3) meanZPA = hdata->GetMean();
90                 else if(ihitHisto==4) pmQZNC = hdata->GetMean();
91                 else if(ihitHisto==5) pmQZNA = hdata->GetMean();
92                 else if(ihitHisto==6) pmQZPC = hdata->GetMean();
93                 else if(ihitHisto==7) pmQZPA = hdata->GetMean();
94                 else if(ihitHisto==8)  pmCZNC = hdata->GetMean();
95                 else if(ihitHisto==9)  pmCZNA = hdata->GetMean();
96                 else if(ihitHisto==10) pmCZPC = hdata->GetMean();
97                 else if(ihitHisto==11) pmCZPA = hdata->GetMean();
98               }
99               //
100               // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
101               if(ihitHisto==11){
102                 if(TMath::Abs(meanZNC)>1.e-10){
103                   if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
104                     res=1.;
105                   else 
106                     res=.5;
107                   test[specie] += res;
108                   count++;
109                 }
110                 if(TMath::Abs(meanZNA)>1.e-10){
111                   if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
112                     res=1.;
113                   else percentageDiff=
114                     res=.5;
115                   test[specie] += res;
116                   count++;
117                 }
118                 if(TMath::Abs(meanZPC)>1.e-10){
119                   if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
120                     res=1.;
121                   else 
122                     res=.5;
123                   test[specie] += res;
124                   count++;
125                 }
126                 if(TMath::Abs(meanZPA)>1.e-10){
127                   if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
128                     res=1.;
129                   else 
130                     res=.5;
131                   test[specie] += res;
132                   count++;
133                 }
134               }
135               ihitHisto++;
136             }
137             // Check DIGIT HIGH GAIN CHAIN histos
138             else if(!(strncmp(hdata->GetName(),"hDig",4))){ 
139               if(hdata->GetEntries()>0){
140                 if(idigHisto==0)      sumADCZNC = hdata->GetMean();
141                 else if(idigHisto==1) sumADCZNA = hdata->GetMean();
142                 else if(idigHisto==2) sumADCZPC = hdata->GetMean();
143                 else if(idigHisto==3) sumADCZPA = hdata->GetMean();
144                 else if(idigHisto==4) pmQZNC = hdata->GetMean();
145                 else if(idigHisto==5) pmQZNA = hdata->GetMean();
146                 else if(idigHisto==6) pmQZPC = hdata->GetMean();
147                 else if(idigHisto==7) pmQZPA = hdata->GetMean();
148                 else if(idigHisto==8)  pmCZNC = hdata->GetMean();
149                 else if(idigHisto==9)  pmCZNA = hdata->GetMean();
150                 else if(idigHisto==10) pmCZPC = hdata->GetMean();
151                 else if(idigHisto==11) pmCZPA = hdata->GetMean();
152               }
153               //
154               // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
155               if(idigHisto==11){
156                 if(TMath::Abs(sumADCZNC)>1.e-10){
157                   if((TMath::Abs(adcQZNC-adcCZNC)/adcCZNC)<percentageDiff) 
158                     res=1.;
159                   else 
160                     res=.5;
161                   test[specie] += res;
162                   count++;
163                 }
164                 if(TMath::Abs(sumADCZNA)>1.e-10){
165                   if((TMath::Abs(adcQZNA-adcCZNA)/adcCZNA)<percentageDiff) 
166                     res=1.;
167                   else 
168                     res=.5;
169                   test[specie] += res;
170                   count++;
171                 }
172                 if(TMath::Abs(sumADCZPC)>1.e-10){
173                   if((TMath::Abs(adcQZPC-adcCZPC)/adcCZPC)<percentageDiff) 
174                     res=1.;
175                   else 
176                     res=.5;
177                   test[specie] += res;
178                   count++;
179                 }
180                 if(TMath::Abs(sumADCZPA)>1.e-10){
181                   if((TMath::Abs(adcQZPA-adcCZPA)/adcCZPA)<percentageDiff) 
182                     res=1.;
183                   else 
184                     res=.5;
185                   test[specie] += res;
186                   count++;
187                 }
188               }
189               idigHisto++;            
190             }
191           } 
192           // -------------------------------------------------------------------
193           else if(index == AliQAv1::kRAW) {
194             //
195             // Check RAW HIGH GAIN CHAIN histos
196             
197             messages.Clear();
198             
199             Bool_t iDetPM = kTRUE;
200             // --- Checks
201             if(irawHisto==22){ 
202               Float_t resADC=0.;
203               for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
204                  if((hdata->GetBinContent(ibin))>10.){
205                    res=1.;
206                  }
207                  else if((hdata->GetBinContent(ibin))<10.){
208                    res=0.5;
209                    if(ibin==1 || ibin==6 || ibin==11 || ibin==12 || ibin==13 || ibin==18){
210                      iDetPM = kFALSE;
211                    }
212                  }
213                  //
214                  resADC += res;
215                  test[specie] += res;
216                  count++;
217               }
218               Float_t rv=1.;
219               if(hdata->GetNbinsX() != 0) rv = resADC/hdata->GetNbinsX();
220               if(rv == 1.) messages.Add(new TObjString("ADCs are OK!")); 
221               else if(iDetPM==kFALSE){
222                 messages.Add(new TObjString("Problem with ADCs!"));
223                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL"));
224                 messages.Add(new TObjString("OR A STANDALONE_PEDESTAL RUN"));
225               }
226               else if(iDetPM==kTRUE) messages.Add(new TObjString("Minor problem with ADCs"));
227               SetupHisto(messages, *hdata, rv);
228             }
229             else if(irawHisto==23){
230               Double_t refTDCs = -319.5;
231               Float_t resTDC=0.;
232               for(int ibin=5; ibin<=6; ibin++){
233                  if(TMath::Abs((hdata->GetBinContent(ibin))-refTDCs)<2.){
234                    res=1.;
235                  }
236                  else if((TMath::Abs((hdata->GetBinContent(ibin))-refTDCs)>=2.) &&
237                          (TMath::Abs((hdata->GetBinContent(ibin))-refTDCs)<=3.)){
238                    res=0.9;
239                  }
240                  else{
241                    res=0.5;
242                  }
243                  //
244                  resTDC += res;
245                  test[specie] += res;
246                  count++;
247               }
248               Float_t rv=1.;
249               if(hdata->GetNbinsX() != 0) rv = resTDC/2;
250               if(rv == 1.) messages.Add(new TObjString("TDCs are OK!")); 
251               else if(rv<1 && rv>=0.9) messages.Add(new TObjString("Minor problem with TDCs"));
252               else{
253                 messages.Add(new TObjString("Serious problem in ZDC timing"));
254                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
255                 messages.Add(new TObjString("OR A STANDALONE_PEDESTAL RUN"));
256               }
257               SetupHisto(messages, *hdata, rv);
258             }
259             irawHisto++;
260             
261           } 
262           // -------------------------------------------------------------------
263           else if(index == AliQAv1::kREC) {
264             //
265             // Check REC HIGH GAIN CHAIN histos
266             if(hdata->GetEntries()>0){
267               if(irecHisto==0)       meanZNC = hdata->GetMean();
268               else if(irecHisto==1)  meanZNA = hdata->GetMean();
269               else if(irecHisto==2)  meanZPC = hdata->GetMean();
270               else if(irecHisto==3)  meanZPA = hdata->GetMean();
271               else if(irecHisto==4)  pmQZNC = hdata->GetMean();
272               else if(irecHisto==5)  pmQZNA = hdata->GetMean();
273               else if(irecHisto==6)  pmQZPC = hdata->GetMean();
274               else if(irecHisto==7)  pmQZPA = hdata->GetMean();
275               else if(irecHisto==8)  pmCZNC = hdata->GetMean();
276               else if(irecHisto==9)  pmCZNA = hdata->GetMean();
277               else if(irecHisto==10) pmCZPC = hdata->GetMean();
278               else if(irecHisto==11) pmCZPA = hdata->GetMean();
279             }
280             //
281             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
282             if(irecHisto==11){
283               if(TMath::Abs(meanZNC)>1.e-10){
284                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
285                   res=1.;
286                 else 
287                   res=.5;
288                 test[specie] += res;
289                 count++;
290               }
291               if(TMath::Abs(meanZNA)>1.e-10){
292                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
293                   res=1.;
294                 else 
295                   res=.5;
296                 test[specie] += res;
297                 count++;
298               }
299               if(TMath::Abs(meanZPC)>1.e-10){
300                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
301                   res=1.;
302                 else 
303                   res=.5;
304                 test[specie] += res;
305                 count++;
306               }
307               if(TMath::Abs(meanZPA)>1.e-10){
308                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
309                   res=1.;
310                 else 
311                   res=.5;
312                 test[specie] += res;
313                 count++;
314               }
315             }
316             irecHisto++;            
317           } 
318           // -------------------------------------------------------------------
319           else if(index == AliQAv1::kESD) {
320             //
321             // Check ESD HIGH GAIN CHAIN histos
322             if(hdata->GetEntries()>0){
323               if(esdInd==2)      sumADCZNC = hdata->GetMean();
324               else if(esdInd==3) sumADCZNA = hdata->GetMean();
325               else if(esdInd==4) sumADCZPC = hdata->GetMean();
326               else if(esdInd==5) sumADCZPA = hdata->GetMean();
327               else if(esdInd==8)  pmQZNC = hdata->GetMean();
328               else if(esdInd==9)  pmQZNA = hdata->GetMean();
329               else if(esdInd==10) pmQZPC = hdata->GetMean();
330               else if(esdInd==11) pmQZPA = hdata->GetMean();
331               else if(esdInd==12) pmCZNC = hdata->GetMean();
332               else if(esdInd==13) pmCZNA = hdata->GetMean();
333               else if(esdInd==14) pmCZPC = hdata->GetMean();
334               else if(esdInd==15) pmCZPA = hdata->GetMean();
335             }
336             //
337             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
338             if(esdInd==15){
339               if(TMath::Abs(sumADCZNC)>1.e-10){
340                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
341                   res=1.;
342                 else 
343                   res=.5;
344                 test[specie] += res;
345                 count++;
346               }
347               if(TMath::Abs(sumADCZNA)>1.e-10){
348                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
349                   res=1.;
350                 else 
351                   res=.5;
352                 test[specie] += res;
353                 count++;
354               }
355               if(TMath::Abs(sumADCZPC)>1.e-10){
356                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
357                   res=1.;
358                 else 
359                   res=.5;
360                 test[specie] += res;
361                 count++;
362               }
363               if(TMath::Abs(sumADCZPA)>1.e-10){
364                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
365                   res=1.;
366                 else 
367                   res=.5;
368                 test[specie] += res;
369                 count++;
370               }
371             }
372             esdInd++;
373          }  
374          else {
375            AliWarning(Form("\n\t No ZDC QA for %s task\n",taskName)); 
376            return ;
377          }
378         }//if(hdata) 
379         else AliError("AliZDCQAChecker-> No histos!!!\n");
380       }
381     } // LowMult (p-p)
382     // ====================================================================
383     //  Checks for A-A events
384     // ====================================================================
385     else if (AliRecoParam::ConvertIndex(specie) == AliRecoParam::kHighMult) {
386       if(list[specie]->GetEntries()==0){  
387         AliWarning("\t The list to be checked is empty!");
388         return ;
389       }
390       //AliDebug(AliQAv1::GetQADebugLevel(), Form("\n\tAliZDCQAChecker-> checking QA histograms for task %s\n\n",taskName));
391       //
392       TIter next(list[specie]); 
393       count = 0; 
394       TH1 * hdata;        
395       
396       Float_t res=0., percentageDiff=0.10;
397       Float_t meanZNA=0., meanZNC=0., meanZPA=0., meanZPC=0.;
398       Float_t pmCZNA=0., pmCZNC=0., pmCZPA=0., pmCZPC=0.;
399       Float_t pmQZNA=0., pmQZNC=0., pmQZPA=0., pmQZPC=0.;
400       Float_t sumADCZNA=0., sumADCZNC=0., sumADCZPA=0., sumADCZPC=0.;
401       Float_t adcCZNA=0., adcCZNC=0., adcCZPA=0., adcCZPC=0.;
402       Float_t adcQZNA=0., adcQZNC=0., adcQZPA=0., adcQZPC=0.;
403       
404       while((hdata = dynamic_cast<TH1 *>(next()))){
405         if(hdata){ 
406           //AliDebug(AliQAv1::GetQADebugLevel(), Form("\tAliZDCQAChecker-> checking histo %s",hdata->GetName()));
407           // -------------------------------------------------------------------
408           if(index == AliQAv1::kSIM){
409             // Check HITS histos
410             if (!(strncmp(hdata->GetName(),"hHits",5))){
411               if(hdata->GetEntries()>0){
412                 if(ihitHisto==0)      meanZNC = hdata->GetMean();
413                 else if(ihitHisto==1) meanZNA = hdata->GetMean();
414                 else if(ihitHisto==2) meanZPC = hdata->GetMean();
415                 else if(ihitHisto==3) meanZPA = hdata->GetMean();
416                 else if(ihitHisto==4) pmQZNC = hdata->GetMean();
417                 else if(ihitHisto==5) pmQZNA = hdata->GetMean();
418                 else if(ihitHisto==6) pmQZPC = hdata->GetMean();
419                 else if(ihitHisto==7) pmQZPA = hdata->GetMean();
420                 else if(ihitHisto==8)  pmCZNC = hdata->GetMean();
421                 else if(ihitHisto==9)  pmCZNA = hdata->GetMean();
422                 else if(ihitHisto==10) pmCZPC = hdata->GetMean();
423                 else if(ihitHisto==11) pmCZPA = hdata->GetMean();
424               }
425               //
426               // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
427               // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
428               if(ihitHisto==3){
429                 if(TMath::Abs(meanZNC)>1.e-10 && TMath::Abs(meanZNA)>1.e-10){
430                   if((2*TMath::Abs(meanZNC-meanZNA)/(meanZNA+meanZNC))<percentageDiff) 
431                     res=1.;
432                   else 
433                     res=.5;
434                   test[specie] += res;
435                   count++;
436                 }
437                 if(TMath::Abs(meanZPC)>1.e-10 && TMath::Abs(meanZPA)>1.e-10){
438                   if((TMath::Abs(meanZPC-meanZPA)/(meanZPA+meanZPC))<percentageDiff) 
439                     res=1.;
440                   else 
441                     res=.5;
442                   test[specie] += res;
443                   count++;
444                 }
445               }
446               // --- Check whether (mean PMQi - PMC)/PMC < percentageDiff
447               if(ihitHisto==11){
448                 if(TMath::Abs(meanZNC)>1.e-10){
449                   if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
450                     res=1.;
451                   else 
452                     res=.5;
453                   test[specie] += res;
454                   count++;
455                 }
456                 if(TMath::Abs(meanZNA)>1.e-10){
457                   if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
458                     res=1.;
459                   else 
460                     res=.5;
461                   test[specie] += res;
462                   count++;
463                 }
464                 if(TMath::Abs(meanZPC)>1.e-10){
465                   if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
466                     res=1.;
467                   else 
468                     res=.5;
469                   test[specie] += res;
470                   count++;
471                 }
472                 if(TMath::Abs(meanZPA)>1.e-10){
473                   if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
474                     res=1.;
475                   else 
476                     res=.5;
477                   test[specie] += res;
478                   count++;
479                 }
480               }
481               ihitHisto++;
482             }
483             // Check DIGITS histos
484             else if (!(strncmp(hdata->GetName(),"hDig",4))){
485               if(hdata->GetEntries()>0){
486                 if(idigHisto==0)      sumADCZNC = hdata->GetMean();
487                 else if(idigHisto==1) sumADCZNA = hdata->GetMean();
488                 else if(idigHisto==2) sumADCZPC = hdata->GetMean();
489                 else if(idigHisto==3) sumADCZPA = hdata->GetMean();
490                 else if(idigHisto==4) adcQZNC = hdata->GetMean();
491                 else if(idigHisto==5) adcQZNA = hdata->GetMean();
492                 else if(idigHisto==6) adcQZPC = hdata->GetMean();
493                 else if(idigHisto==7) adcQZPA = hdata->GetMean();
494                 else if(idigHisto==8)  adcCZNC = hdata->GetMean();
495                 else if(idigHisto==9)  adcCZNA = hdata->GetMean();
496                 else if(idigHisto==10) adcCZPC = hdata->GetMean();
497                 else if(idigHisto==11) adcCZPA = hdata->GetMean();
498               }
499               //
500               // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
501               // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
502               if(idigHisto==3){
503                 if(TMath::Abs(sumADCZNC)>1.e-10 && TMath::Abs(sumADCZNA)>1.e-10){
504                   if((2*TMath::Abs(sumADCZNC-sumADCZNA)/(sumADCZNA+sumADCZNC))<percentageDiff) 
505                     res=1.;
506                   else 
507                     res=.5;
508                   test[specie] += res;
509                   count++;
510                 }
511                 if(TMath::Abs(sumADCZPC)>1.e-10 && TMath::Abs(sumADCZPA)>1.e-10){
512                   if((TMath::Abs(sumADCZPC-sumADCZPA)/(sumADCZPA+sumADCZPC))<percentageDiff) 
513                     res=1.;
514                   else 
515                     res=.5;
516                   test[specie] += res;
517                   count++;
518                 }
519               }
520               // --- Check whether (sumADC PMQi - PMC)/PMC < percentageDiff
521               if(idigHisto==11){
522                 if(TMath::Abs(sumADCZNC)>1.e-10){
523                   if((TMath::Abs(adcQZNC-adcCZNC)/adcCZNC)<percentageDiff) 
524                     res=1.;
525                   else 
526                     res=.5;
527                   test[specie] += res;
528                   count++;
529                 }
530                 if(TMath::Abs(sumADCZNA)>1.e-10){
531                   if((TMath::Abs(adcQZNA-adcCZNA)/adcCZNA)<percentageDiff) 
532                     res=1.;
533                   else 
534                     res=.5;
535                   test[specie] += res;
536                   count++;
537                 }
538                 if(TMath::Abs(sumADCZPC)>1.e-10){
539                   if((TMath::Abs(adcQZPC-adcCZPC)/adcCZPC)<percentageDiff) 
540                     res=1.;
541                   else 
542                     res=.5;
543                   test[specie] += res;
544                   count++;
545                 }
546                 if(TMath::Abs(sumADCZPA)>1.e-10){
547                   if((TMath::Abs(adcQZPA-adcCZPA)/adcCZPA)<percentageDiff) 
548                     res=1.;
549                   else 
550                     res=.5;
551                   test[specie] += res;
552                   count++;
553                 }
554               }
555               idigHisto++;
556             }
557           }
558           // -------------------------------------------------------------------
559           else if(index == AliQAv1::kRAW){
560             //
561             // Check RAW HIGH GAIN CHAIN histos
562             
563             messages.Clear();
564             
565             Bool_t iDetPM = kTRUE;
566             // --- Checks
567             if(irawHisto==22){ 
568               Float_t resADC=0.;
569               for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
570                  if((hdata->GetBinContent(ibin))>10.){
571                    res=1.;
572                  }
573                  else if((hdata->GetBinContent(ibin))<10. && 
574                    (ibin==1 || ibin==6 || ibin==11 || ibin==12 || ibin==13 || ibin==18)){
575                    res=0.5;
576                    iDetPM = kFALSE;
577                  }
578                  //
579                  resADC += res;
580                  test[specie] += res;
581                  count++;
582               }
583               Float_t rv=1.;
584               if(hdata->GetNbinsX() != 0) rv = resADC/hdata->GetNbinsX();
585               if(rv == 1.) messages.Add(new TObjString("ADCs are OK!")); 
586               else if(iDetPM==kFALSE){
587                 messages.Add(new TObjString("Problem with ADCs!"));
588                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
589               }
590               else if(iDetPM==kTRUE) messages.Add(new TObjString("Minor problem with ADCs"));
591               SetupHisto(messages, *hdata, rv);
592             }
593             else if(irawHisto==23){
594               Double_t refTDCs[6] = {-83.0,-78.1,-80.2,-79.3,-81.0,-80.9};
595               Float_t resTDC=0.;
596               for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
597                  if(TMath::Abs((hdata->GetBinContent(ibin))-refTDCs[ibin-1])<4.){
598                    res=1.;
599                  }
600                  else{
601                    res=0.5;
602                  }
603                  //
604                  resTDC += res;
605                  test[specie] += res;
606                  count++;
607               }
608               Float_t rv=1.;
609               if(hdata->GetNbinsX() != 0) rv = resTDC/hdata->GetNbinsX();
610               if(rv == 1.) messages.Add(new TObjString("TDCs are OK!")); 
611               else if(rv<1 && rv>0.9) messages.Add(new TObjString("Minor problem with TDCs"));
612               else{
613                 messages.Add(new TObjString("Serious problem in ZDC timing"));
614                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
615               }
616               SetupHisto(messages, *hdata, rv);
617             }
618             else if(irawHisto==26){
619               Double_t yZNC=hdata->GetBinContent(2);
620               Double_t yZNA=hdata->GetBinContent(4);
621               if(TMath::Abs(yZNC)<0.4 && TMath::Abs(yZNA)<0.4) res=1.;
622               else res=0.5;
623               test[specie] += res;
624               count++;
625               //
626               printf(" yZNC = %1.2f yZNA = %1.2f -> res %1.2f\n",yZNC, yZNA,res);
627               if(res == 1.) messages.Add(new TObjString("ZN positions are OK!")); 
628               else{
629                 messages.Add(new TObjString("Problem in ZN positions!")); 
630                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
631               }
632               SetupHisto(messages, *hdata, res);
633             }
634             irawHisto++;
635             
636           }   
637           // -------------------------------------------------------------------
638           else if(index == AliQAv1::kREC){
639             //
640             // Check RAW HIGH GAIN CHAIN histos
641             if(hdata->GetEntries()>0){
642               if(irecHisto==0)       meanZNC = hdata->GetMean();
643               else if(irecHisto==1)  meanZNA = hdata->GetMean();
644               else if(irecHisto==2)  meanZPC = hdata->GetMean();
645               else if(irecHisto==3)  meanZPA = hdata->GetMean();
646               else if(irecHisto==4)  pmQZNC = hdata->GetMean();
647               else if(irecHisto==5)  pmQZNA = hdata->GetMean();
648               else if(irecHisto==6)  pmQZPC = hdata->GetMean();
649               else if(irecHisto==7)  pmQZPA = hdata->GetMean();
650               else if(irecHisto==8)  pmCZNC = hdata->GetMean();
651               else if(irecHisto==9)  pmCZNA = hdata->GetMean();
652               else if(irecHisto==10) pmCZPC = hdata->GetMean();
653               else if(irecHisto==11) pmCZPA = hdata->GetMean();
654             }
655             //
656             // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
657             // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
658             if(irecHisto==3){
659               if(TMath::Abs(meanZNC)>1.e-10 && TMath::Abs(meanZNA)>1.e-10){
660                 if((2*TMath::Abs(meanZNC-meanZNA)/(meanZNA+meanZNC))<percentageDiff) 
661                   res=1.;
662                 else 
663                   res=.5;
664                 test[specie] += res;
665                 count++;
666               }
667               if(TMath::Abs(meanZPC)>1.e-10 && TMath::Abs(meanZPA)>1.e-10){
668                 if((TMath::Abs(meanZPC-meanZPA)/(meanZPA+meanZPC))<percentageDiff) 
669                   res=1.;
670                 else 
671                   res=.5;
672                 test[specie] += res;
673                 count++;
674               }
675             }
676             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
677             if(irecHisto==11){
678               if(TMath::Abs(meanZNC)>1.e-10){
679                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
680                   res=1.;
681                 else 
682                   res=.5;
683                 test[specie] += res;
684                 count++;
685               }
686               if(TMath::Abs(meanZNA)>1.e-10){
687                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
688                   res=1.;
689                 else 
690                   res=.5;
691                 test[specie] += res;
692                 count++;
693               }
694               if(TMath::Abs(meanZPC)>1.e-10){
695                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
696                   res=1.;
697                 else 
698                   res=.5;
699                 test[specie] += res;
700                 count++;
701               }
702               if(TMath::Abs(meanZPA)>1.e-10){
703                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
704                   res=1.;
705                 else 
706                   res=.5;
707                 test[specie] += res;
708                 count++;
709               }
710             }
711             irecHisto++;         
712           }   
713           // -------------------------------------------------------------------
714           else if(index == AliQAv1::kESD){
715             //
716             // Check ESD HIGH GAIN CHAIN histos
717             if(hdata->GetEntries()>0){
718               if(esdInd==2)      sumADCZNC = hdata->GetMean();
719               else if(esdInd==3) sumADCZNA = hdata->GetMean();
720               else if(esdInd==4) sumADCZPC = hdata->GetMean();
721               else if(esdInd==5) sumADCZPA = hdata->GetMean();
722               else if(esdInd==8) pmQZNC = hdata->GetMean();
723               else if(esdInd==9) pmQZNA = hdata->GetMean();
724               else if(esdInd==10) pmQZPC = hdata->GetMean();
725               else if(esdInd==11) pmQZPA = hdata->GetMean();
726               else if(esdInd==12) pmCZNC = hdata->GetMean();
727               else if(esdInd==13) pmCZNA = hdata->GetMean();
728               else if(esdInd==14) pmCZPC = hdata->GetMean();
729               else if(esdInd==15) pmCZPA = hdata->GetMean();
730             }
731             //
732             // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
733             // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
734             if(esdInd==5){
735               if(TMath::Abs(sumADCZNC)>1.e-10 && TMath::Abs(sumADCZNA)>1.e-10){
736                 if((2*TMath::Abs(sumADCZNC-sumADCZNA)/(sumADCZNA+sumADCZNC))<percentageDiff) 
737                   res=1.;
738                 else 
739                   res=.5;
740                 test[specie] += res;
741                 count++;
742               }
743               if(TMath::Abs(sumADCZPC)>1.e-10 && TMath::Abs(sumADCZPA)>1.e-10){
744                 if((TMath::Abs(sumADCZPC-sumADCZPA)/(sumADCZPA+sumADCZPC))<percentageDiff) 
745                   res=1.;
746                 else 
747                   res=.5;
748                 test[specie] += res;
749                 count++;
750               }
751             }
752             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
753             if(esdInd==15){
754               if(TMath::Abs(sumADCZNC)>1.e-10){
755                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
756                   res=1.;
757                 else 
758                   res=.5;
759                 test[specie] += res;
760                 count++;
761               }
762               if(TMath::Abs(sumADCZNA)>1.e-10){
763                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
764                   res=1.;
765                 else 
766                   res=.5;
767                 test[specie] += res;
768                 count++;
769               }
770 /*            if(TMath::Abs(sumADCZPC)>1.e-10){
771                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
772                   res=1.;
773                 else 
774                   res=.5;
775                 test[specie] += res;
776                 count++;
777               }
778               if(TMath::Abs(sumADCZPA)>1.e-10){
779                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
780                   res=1.;
781                 else 
782                   res=.5;
783                 test[specie] += res;
784                 count++;
785               }
786 */
787             }
788             esdInd++;
789           }  
790           else {
791             AliWarning(Form("\n\t No ZDC QA for %s task\n",taskName)); 
792             return ;
793           } 
794         }//if(hdata) 
795         else AliError("\t  No histos found for ZDC!!!\n");
796       }
797     } // HighMult (Pb-Pb) 
798     // ====================================================================
799     //  Checks for Calibration events
800     // ====================================================================
801     else if (AliRecoParam::ConvertIndex(specie) == AliRecoParam::kCalib) {
802       AliWarning(Form("\n\t No check implemented in ZDC QA for %s task\n",taskName)); 
803       return ;
804     } // Calibration
805     // ====================================================================
806     //  Checks for cosmic events
807     // ====================================================================
808     else if (AliRecoParam::ConvertIndex(specie) == AliRecoParam::kCosmic) {
809       AliWarning(Form("\n\t No check implemented in ZDC QA for %s task\n",taskName)); 
810       return ; 
811     } // Cosmic
812     if(TMath::Abs(count)>1.e-10) test[specie] = test[specie]/count;
813     AliDebug(AliQAv1::GetQADebugLevel(), Form("\n\t ZDC QA check result = %1.2f\n",test[specie]));
814   } // Loop on species
815 }  
816
817 //___________________________________________________________________ 
818 void AliZDCQAChecker::SetupHisto(const TObjArray& messages, TH1& histo, Float_t& code)
819 {
820   //
821   /// Add text to histos
822   //
823
824   TPaveText* text = new TPaveText(0.70,0.70,0.99,0.99,"NDC");
825     
826   TIter next(&messages);
827   TObjString* str;
828     
829   while ( ( str = static_cast<TObjString*>(next()) ) ){
830     text->AddText(str->String());
831   }
832
833   TString defaultText = "";
834
835   Int_t color = 0;
836   if(code==1.){
837     color = kGreen;
838     defaultText = "Everything is fine!";
839   }  
840   else if(code<1. && code>=0.9){  
841     color = kYellow;
842     defaultText = "To be monitored in next runs";
843   }
844   else if(code<0.9 && code>=0.6){
845     color = kOrange;
846     defaultText = "notify the expert DURING THE DAY!";
847   }
848   else if(code<0.6){
849     color = kRed;
850     defaultText = "CALL THE EXPERT!!!!";
851   }
852
853
854   text->AddText(defaultText.Data());
855   text->SetFillColor(color);
856                       
857   //histo.SetFillStyle(1001);
858   //histo.SetFillColor(color);
859
860   histo.SetStats(kFALSE);
861     
862   histo.GetListOfFunctions()->Add(text);
863 }