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