]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/AliZDCQAChecker.cxx
bug fix
[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[6] = {-325.,-321.6,-323.4,-321.6,-322.2,-321.7};
231               Float_t resTDC=0.;
232               for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
233                  if(TMath::Abs((hdata->GetBinContent(ibin))-refTDCs[ibin-1])<12.){
234                    res=1.;
235                  }
236                  else{
237                    res=0.5;
238                  }
239                  //
240                  resTDC += res;
241                  test[specie] += res;
242                  count++;
243               }
244               Float_t rv=1.;
245               if(hdata->GetNbinsX() != 0) rv = resTDC/hdata->GetNbinsX();
246               if(rv == 1.) messages.Add(new TObjString("TDCs are OK!")); 
247               else if(rv<1 && rv>0.8) messages.Add(new TObjString("Minor problem with TDCs"));
248               else{
249                 messages.Add(new TObjString("Serious problem in ZDC timing"));
250                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
251               }
252               SetupHisto(messages, *hdata, rv);
253             }
254             irawHisto++;
255             
256           } 
257           // -------------------------------------------------------------------
258           else if(index == AliQAv1::kREC) {
259             //
260             // Check REC HIGH GAIN CHAIN histos
261             if(hdata->GetEntries()>0){
262               if(irecHisto==0)       meanZNC = hdata->GetMean();
263               else if(irecHisto==1)  meanZNA = hdata->GetMean();
264               else if(irecHisto==2)  meanZPC = hdata->GetMean();
265               else if(irecHisto==3)  meanZPA = hdata->GetMean();
266               else if(irecHisto==4)  pmQZNC = hdata->GetMean();
267               else if(irecHisto==5)  pmQZNA = hdata->GetMean();
268               else if(irecHisto==6)  pmQZPC = hdata->GetMean();
269               else if(irecHisto==7)  pmQZPA = hdata->GetMean();
270               else if(irecHisto==8)  pmCZNC = hdata->GetMean();
271               else if(irecHisto==9)  pmCZNA = hdata->GetMean();
272               else if(irecHisto==10) pmCZPC = hdata->GetMean();
273               else if(irecHisto==11) pmCZPA = hdata->GetMean();
274             }
275             //
276             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
277             if(irecHisto==11){
278               if(TMath::Abs(meanZNC)>1.e-10){
279                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
280                   res=1.;
281                 else 
282                   res=.5;
283                 test[specie] += res;
284                 count++;
285               }
286               if(TMath::Abs(meanZNA)>1.e-10){
287                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
288                   res=1.;
289                 else 
290                   res=.5;
291                 test[specie] += res;
292                 count++;
293               }
294               if(TMath::Abs(meanZPC)>1.e-10){
295                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
296                   res=1.;
297                 else 
298                   res=.5;
299                 test[specie] += res;
300                 count++;
301               }
302               if(TMath::Abs(meanZPA)>1.e-10){
303                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
304                   res=1.;
305                 else 
306                   res=.5;
307                 test[specie] += res;
308                 count++;
309               }
310             }
311             irecHisto++;            
312           } 
313           // -------------------------------------------------------------------
314           else if(index == AliQAv1::kESD) {
315             //
316             // Check ESD HIGH GAIN CHAIN histos
317             if(hdata->GetEntries()>0){
318               if(esdInd==2)      sumADCZNC = hdata->GetMean();
319               else if(esdInd==3) sumADCZNA = hdata->GetMean();
320               else if(esdInd==4) sumADCZPC = hdata->GetMean();
321               else if(esdInd==5) sumADCZPA = hdata->GetMean();
322               else if(esdInd==8)  pmQZNC = hdata->GetMean();
323               else if(esdInd==9)  pmQZNA = hdata->GetMean();
324               else if(esdInd==10) pmQZPC = hdata->GetMean();
325               else if(esdInd==11) pmQZPA = hdata->GetMean();
326               else if(esdInd==12) pmCZNC = hdata->GetMean();
327               else if(esdInd==13) pmCZNA = hdata->GetMean();
328               else if(esdInd==14) pmCZPC = hdata->GetMean();
329               else if(esdInd==15) pmCZPA = hdata->GetMean();
330             }
331             //
332             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
333             if(esdInd==15){
334               if(TMath::Abs(sumADCZNC)>1.e-10){
335                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
336                   res=1.;
337                 else 
338                   res=.5;
339                 test[specie] += res;
340                 count++;
341               }
342               if(TMath::Abs(sumADCZNA)>1.e-10){
343                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
344                   res=1.;
345                 else 
346                   res=.5;
347                 test[specie] += res;
348                 count++;
349               }
350               if(TMath::Abs(sumADCZPC)>1.e-10){
351                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
352                   res=1.;
353                 else 
354                   res=.5;
355                 test[specie] += res;
356                 count++;
357               }
358               if(TMath::Abs(sumADCZPA)>1.e-10){
359                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
360                   res=1.;
361                 else 
362                   res=.5;
363                 test[specie] += res;
364                 count++;
365               }
366             }
367             esdInd++;
368          }  
369          else {
370            AliWarning(Form("\n\t No ZDC QA for %s task\n",taskName)); 
371            return ;
372          }
373         }//if(hdata) 
374         else AliError("AliZDCQAChecker-> No histos!!!\n");
375       }
376     } // LowMult (p-p)
377     // ====================================================================
378     //  Checks for A-A events
379     // ====================================================================
380     else if (AliRecoParam::ConvertIndex(specie) == AliRecoParam::kHighMult) {
381       if(list[specie]->GetEntries()==0){  
382         AliWarning("\t The list to be checked is empty!");
383         return ;
384       }
385       //AliDebug(AliQAv1::GetQADebugLevel(), Form("\n\tAliZDCQAChecker-> checking QA histograms for task %s\n\n",taskName));
386       //
387       TIter next(list[specie]); 
388       count = 0; 
389       TH1 * hdata;        
390       
391       Float_t res=0., percentageDiff=0.10;
392       Float_t meanZNA=0., meanZNC=0., meanZPA=0., meanZPC=0.;
393       Float_t pmCZNA=0., pmCZNC=0., pmCZPA=0., pmCZPC=0.;
394       Float_t pmQZNA=0., pmQZNC=0., pmQZPA=0., pmQZPC=0.;
395       Float_t sumADCZNA=0., sumADCZNC=0., sumADCZPA=0., sumADCZPC=0.;
396       Float_t adcCZNA=0., adcCZNC=0., adcCZPA=0., adcCZPC=0.;
397       Float_t adcQZNA=0., adcQZNC=0., adcQZPA=0., adcQZPC=0.;
398       
399       while((hdata = dynamic_cast<TH1 *>(next()))){
400         if(hdata){ 
401           //AliDebug(AliQAv1::GetQADebugLevel(), Form("\tAliZDCQAChecker-> checking histo %s",hdata->GetName()));
402           // -------------------------------------------------------------------
403           if(index == AliQAv1::kSIM){
404             // Check HITS histos
405             if (!(strncmp(hdata->GetName(),"hHits",5))){
406               if(hdata->GetEntries()>0){
407                 if(ihitHisto==0)      meanZNC = hdata->GetMean();
408                 else if(ihitHisto==1) meanZNA = hdata->GetMean();
409                 else if(ihitHisto==2) meanZPC = hdata->GetMean();
410                 else if(ihitHisto==3) meanZPA = hdata->GetMean();
411                 else if(ihitHisto==4) pmQZNC = hdata->GetMean();
412                 else if(ihitHisto==5) pmQZNA = hdata->GetMean();
413                 else if(ihitHisto==6) pmQZPC = hdata->GetMean();
414                 else if(ihitHisto==7) pmQZPA = hdata->GetMean();
415                 else if(ihitHisto==8)  pmCZNC = hdata->GetMean();
416                 else if(ihitHisto==9)  pmCZNA = hdata->GetMean();
417                 else if(ihitHisto==10) pmCZPC = hdata->GetMean();
418                 else if(ihitHisto==11) pmCZPA = hdata->GetMean();
419               }
420               //
421               // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
422               // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
423               if(ihitHisto==3){
424                 if(TMath::Abs(meanZNC)>1.e-10 && TMath::Abs(meanZNA)>1.e-10){
425                   if((2*TMath::Abs(meanZNC-meanZNA)/(meanZNA+meanZNC))<percentageDiff) 
426                     res=1.;
427                   else 
428                     res=.5;
429                   test[specie] += res;
430                   count++;
431                 }
432                 if(TMath::Abs(meanZPC)>1.e-10 && TMath::Abs(meanZPA)>1.e-10){
433                   if((TMath::Abs(meanZPC-meanZPA)/(meanZPA+meanZPC))<percentageDiff) 
434                     res=1.;
435                   else 
436                     res=.5;
437                   test[specie] += res;
438                   count++;
439                 }
440               }
441               // --- Check whether (mean PMQi - PMC)/PMC < percentageDiff
442               if(ihitHisto==11){
443                 if(TMath::Abs(meanZNC)>1.e-10){
444                   if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
445                     res=1.;
446                   else 
447                     res=.5;
448                   test[specie] += res;
449                   count++;
450                 }
451                 if(TMath::Abs(meanZNA)>1.e-10){
452                   if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
453                     res=1.;
454                   else 
455                     res=.5;
456                   test[specie] += res;
457                   count++;
458                 }
459                 if(TMath::Abs(meanZPC)>1.e-10){
460                   if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
461                     res=1.;
462                   else 
463                     res=.5;
464                   test[specie] += res;
465                   count++;
466                 }
467                 if(TMath::Abs(meanZPA)>1.e-10){
468                   if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
469                     res=1.;
470                   else 
471                     res=.5;
472                   test[specie] += res;
473                   count++;
474                 }
475               }
476               ihitHisto++;
477             }
478             // Check DIGITS histos
479             else if (!(strncmp(hdata->GetName(),"hDig",4))){
480               if(hdata->GetEntries()>0){
481                 if(idigHisto==0)      sumADCZNC = hdata->GetMean();
482                 else if(idigHisto==1) sumADCZNA = hdata->GetMean();
483                 else if(idigHisto==2) sumADCZPC = hdata->GetMean();
484                 else if(idigHisto==3) sumADCZPA = hdata->GetMean();
485                 else if(idigHisto==4) adcQZNC = hdata->GetMean();
486                 else if(idigHisto==5) adcQZNA = hdata->GetMean();
487                 else if(idigHisto==6) adcQZPC = hdata->GetMean();
488                 else if(idigHisto==7) adcQZPA = hdata->GetMean();
489                 else if(idigHisto==8)  adcCZNC = hdata->GetMean();
490                 else if(idigHisto==9)  adcCZNA = hdata->GetMean();
491                 else if(idigHisto==10) adcCZPC = hdata->GetMean();
492                 else if(idigHisto==11) adcCZPA = hdata->GetMean();
493               }
494               //
495               // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
496               // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
497               if(idigHisto==3){
498                 if(TMath::Abs(sumADCZNC)>1.e-10 && TMath::Abs(sumADCZNA)>1.e-10){
499                   if((2*TMath::Abs(sumADCZNC-sumADCZNA)/(sumADCZNA+sumADCZNC))<percentageDiff) 
500                     res=1.;
501                   else 
502                     res=.5;
503                   test[specie] += res;
504                   count++;
505                 }
506                 if(TMath::Abs(sumADCZPC)>1.e-10 && TMath::Abs(sumADCZPA)>1.e-10){
507                   if((TMath::Abs(sumADCZPC-sumADCZPA)/(sumADCZPA+sumADCZPC))<percentageDiff) 
508                     res=1.;
509                   else 
510                     res=.5;
511                   test[specie] += res;
512                   count++;
513                 }
514               }
515               // --- Check whether (sumADC PMQi - PMC)/PMC < percentageDiff
516               if(idigHisto==11){
517                 if(TMath::Abs(sumADCZNC)>1.e-10){
518                   if((TMath::Abs(adcQZNC-adcCZNC)/adcCZNC)<percentageDiff) 
519                     res=1.;
520                   else 
521                     res=.5;
522                   test[specie] += res;
523                   count++;
524                 }
525                 if(TMath::Abs(sumADCZNA)>1.e-10){
526                   if((TMath::Abs(adcQZNA-adcCZNA)/adcCZNA)<percentageDiff) 
527                     res=1.;
528                   else 
529                     res=.5;
530                   test[specie] += res;
531                   count++;
532                 }
533                 if(TMath::Abs(sumADCZPC)>1.e-10){
534                   if((TMath::Abs(adcQZPC-adcCZPC)/adcCZPC)<percentageDiff) 
535                     res=1.;
536                   else 
537                     res=.5;
538                   test[specie] += res;
539                   count++;
540                 }
541                 if(TMath::Abs(sumADCZPA)>1.e-10){
542                   if((TMath::Abs(adcQZPA-adcCZPA)/adcCZPA)<percentageDiff) 
543                     res=1.;
544                   else 
545                     res=.5;
546                   test[specie] += res;
547                   count++;
548                 }
549               }
550               idigHisto++;
551             }
552           }
553           // -------------------------------------------------------------------
554           else if(index == AliQAv1::kRAW){
555             //
556             // Check RAW HIGH GAIN CHAIN histos
557             
558             messages.Clear();
559             
560             Bool_t iDetPM = kTRUE;
561             // --- Checks
562             if(irawHisto==22){ 
563               Float_t resADC=0.;
564               for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
565                  if((hdata->GetBinContent(ibin))>10.){
566                    res=1.;
567                  }
568                  else if((hdata->GetBinContent(ibin))<10. && 
569                    (ibin==1 || ibin==6 || ibin==11 || ibin==12 || ibin==13 || ibin==18)){
570                    res=0.5;
571                    iDetPM = kFALSE;
572                  }
573                  //
574                  resADC += res;
575                  test[specie] += res;
576                  count++;
577               }
578               Float_t rv=1.;
579               if(hdata->GetNbinsX() != 0) rv = resADC/hdata->GetNbinsX();
580               if(rv == 1.) messages.Add(new TObjString("ADCs are OK!")); 
581               else if(iDetPM==kFALSE){
582                 messages.Add(new TObjString("Problem with ADCs!"));
583                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
584               }
585               else if(iDetPM==kTRUE) messages.Add(new TObjString("Minor problem with ADCs"));
586               SetupHisto(messages, *hdata, rv);
587             }
588             else if(irawHisto==23){
589               Double_t refTDCs[6] = {-83.0,-78.1,-80.2,-79.3,-81.0,-80.9};
590               Float_t resTDC=0.;
591               for(int ibin=1; ibin<=hdata->GetNbinsX(); ibin++){
592                  if(TMath::Abs((hdata->GetBinContent(ibin))-refTDCs[ibin-1])<4.){
593                    res=1.;
594                  }
595                  else{
596                    res=0.5;
597                  }
598                  //
599                  resTDC += res;
600                  test[specie] += res;
601                  count++;
602               }
603               Float_t rv=1.;
604               if(hdata->GetNbinsX() != 0) rv = resTDC/hdata->GetNbinsX();
605               if(rv == 1.) messages.Add(new TObjString("TDCs are OK!")); 
606               else if(rv<1 && rv>0.9) messages.Add(new TObjString("Minor problem with TDCs"));
607               else{
608                 messages.Add(new TObjString("Serious problem in ZDC timing"));
609                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
610               }
611               SetupHisto(messages, *hdata, rv);
612             }
613             else if(irawHisto==26){
614               Double_t yZNC=hdata->GetBinContent(2);
615               Double_t yZNA=hdata->GetBinContent(4);
616               if(TMath::Abs(yZNC)<0.4 && TMath::Abs(yZNA)<0.4) res=1.;
617               else res=0.5;
618               test[specie] += res;
619               count++;
620               //
621               printf(" yZNC = %1.2f yZNA = %1.2f -> res %1.2f\n",yZNC, yZNA,res);
622               if(res == 1.) messages.Add(new TObjString("ZN positions are OK!")); 
623               else{
624                 messages.Add(new TObjString("Problem in ZN positions!")); 
625                 messages.Add(new TObjString("IF THIS IS NOT A TECHNICAL RUN"));
626               }
627               SetupHisto(messages, *hdata, res);
628             }
629             irawHisto++;
630             
631           }   
632           // -------------------------------------------------------------------
633           else if(index == AliQAv1::kREC){
634             //
635             // Check RAW HIGH GAIN CHAIN histos
636             if(hdata->GetEntries()>0){
637               if(irecHisto==0)       meanZNC = hdata->GetMean();
638               else if(irecHisto==1)  meanZNA = hdata->GetMean();
639               else if(irecHisto==2)  meanZPC = hdata->GetMean();
640               else if(irecHisto==3)  meanZPA = hdata->GetMean();
641               else if(irecHisto==4)  pmQZNC = hdata->GetMean();
642               else if(irecHisto==5)  pmQZNA = hdata->GetMean();
643               else if(irecHisto==6)  pmQZPC = hdata->GetMean();
644               else if(irecHisto==7)  pmQZPA = hdata->GetMean();
645               else if(irecHisto==8)  pmCZNC = hdata->GetMean();
646               else if(irecHisto==9)  pmCZNA = hdata->GetMean();
647               else if(irecHisto==10) pmCZPC = hdata->GetMean();
648               else if(irecHisto==11) pmCZPA = hdata->GetMean();
649             }
650             //
651             // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
652             // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
653             if(irecHisto==3){
654               if(TMath::Abs(meanZNC)>1.e-10 && TMath::Abs(meanZNA)>1.e-10){
655                 if((2*TMath::Abs(meanZNC-meanZNA)/(meanZNA+meanZNC))<percentageDiff) 
656                   res=1.;
657                 else 
658                   res=.5;
659                 test[specie] += res;
660                 count++;
661               }
662               if(TMath::Abs(meanZPC)>1.e-10 && TMath::Abs(meanZPA)>1.e-10){
663                 if((TMath::Abs(meanZPC-meanZPA)/(meanZPA+meanZPC))<percentageDiff) 
664                   res=1.;
665                 else 
666                   res=.5;
667                 test[specie] += res;
668                 count++;
669               }
670             }
671             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
672             if(irecHisto==11){
673               if((TMath::Abs(meanZNC)>1.e-10) && (pmCZNC>1.e-10)){
674                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
675                   res=1.;
676                 else 
677                   res=.5;
678                 test[specie] += res;
679                 count++;
680               }
681               if((TMath::Abs(meanZNA)>1.e-10) && (pmCZNA>1.e-10)){
682                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
683                   res=1.;
684                 else 
685                   res=.5;
686                 test[specie] += res;
687                 count++;
688               }
689               if((TMath::Abs(meanZPC)>1.e-10) && (pmCZPC>1.e-10)){
690                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
691                   res=1.;
692                 else 
693                   res=.5;
694                 test[specie] += res;
695                 count++;
696               }
697               if((TMath::Abs(meanZPA)>1.e-10) && (pmCZPA>1.e-10)){
698                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
699                   res=1.;
700                 else 
701                   res=.5;
702                 test[specie] += res;
703                 count++;
704               }
705             }
706             irecHisto++;         
707           }   
708           // -------------------------------------------------------------------
709           else if(index == AliQAv1::kESD){
710             //
711             // Check ESD HIGH GAIN CHAIN histos
712             if(hdata->GetEntries()>0){
713               if(esdInd==2)      sumADCZNC = hdata->GetMean();
714               else if(esdInd==3) sumADCZNA = hdata->GetMean();
715               else if(esdInd==4) sumADCZPC = hdata->GetMean();
716               else if(esdInd==5) sumADCZPA = hdata->GetMean();
717               else if(esdInd==8) pmQZNC = hdata->GetMean();
718               else if(esdInd==9) pmQZNA = hdata->GetMean();
719               else if(esdInd==10) pmQZPC = hdata->GetMean();
720               else if(esdInd==11) pmQZPA = hdata->GetMean();
721               else if(esdInd==12) pmCZNC = hdata->GetMean();
722               else if(esdInd==13) pmCZNA = hdata->GetMean();
723               else if(esdInd==14) pmCZPC = hdata->GetMean();
724               else if(esdInd==15) pmCZPA = hdata->GetMean();
725             }
726             //
727             // --- Check whether 2*|Mean ZNA - Mean ZNC|/(Mean ZNA + Mean ZNC) < percentageDiff
728             // --- and 2*|Mean ZPA - Mean ZPC|/(Mean ZPA + Mean ZPC) < 2*percentageDiff
729             if(esdInd==5){
730               if(TMath::Abs(sumADCZNC)>1.e-10 && TMath::Abs(sumADCZNA)>1.e-10){
731                 if((2*TMath::Abs(sumADCZNC-sumADCZNA)/(sumADCZNA+sumADCZNC))<percentageDiff) 
732                   res=1.;
733                 else 
734                   res=.5;
735                 test[specie] += res;
736                 count++;
737               }
738               if(TMath::Abs(sumADCZPC)>1.e-10 && TMath::Abs(sumADCZPA)>1.e-10){
739                 if((TMath::Abs(sumADCZPC-sumADCZPA)/(sumADCZPA+sumADCZPC))<percentageDiff) 
740                   res=1.;
741                 else 
742                   res=.5;
743                 test[specie] += res;
744                 count++;
745               }
746             }
747             // --- Check whether (sum PMQi - PMC)/PMC < percentageDiff
748             if(esdInd==15){
749               if(TMath::Abs(sumADCZNC)>1.e-10){
750                 if((TMath::Abs(pmQZNC-pmCZNC)/pmCZNC)<percentageDiff) 
751                   res=1.;
752                 else 
753                   res=.5;
754                 test[specie] += res;
755                 count++;
756               }
757               if(TMath::Abs(sumADCZNA)>1.e-10){
758                 if((TMath::Abs(pmQZNA-pmCZNA)/pmCZNA)<percentageDiff) 
759                   res=1.;
760                 else 
761                   res=.5;
762                 test[specie] += res;
763                 count++;
764               }
765 /*            if(TMath::Abs(sumADCZPC)>1.e-10){
766                 if((TMath::Abs(pmQZPC-pmCZPC)/pmCZPC)<percentageDiff) 
767                   res=1.;
768                 else 
769                   res=.5;
770                 test[specie] += res;
771                 count++;
772               }
773               if(TMath::Abs(sumADCZPA)>1.e-10){
774                 if((TMath::Abs(pmQZPA-pmCZPA)/pmCZPA)<percentageDiff) 
775                   res=1.;
776                 else 
777                   res=.5;
778                 test[specie] += res;
779                 count++;
780               }
781 */
782             }
783             esdInd++;
784           }  
785           else {
786             AliWarning(Form("\n\t No ZDC QA for %s task\n",taskName)); 
787             return ;
788           } 
789         }//if(hdata) 
790         else AliError("\t  No histos found for ZDC!!!\n");
791       }
792     } // HighMult (Pb-Pb) 
793     // ====================================================================
794     //  Checks for Calibration events
795     // ====================================================================
796     else if (AliRecoParam::ConvertIndex(specie) == AliRecoParam::kCalib) {
797       AliWarning(Form("\n\t No check implemented in ZDC QA for %s task\n",taskName)); 
798       return ;
799     } // Calibration
800     // ====================================================================
801     //  Checks for cosmic events
802     // ====================================================================
803     else if (AliRecoParam::ConvertIndex(specie) == AliRecoParam::kCosmic) {
804       AliWarning(Form("\n\t No check implemented in ZDC QA for %s task\n",taskName)); 
805       return ; 
806     } // Cosmic
807     if(TMath::Abs(count)>1.e-10) test[specie] = test[specie]/count;
808     AliDebug(AliQAv1::GetQADebugLevel(), Form("\n\t ZDC QA check result = %1.2f\n",test[specie]));
809   } // Loop on species
810 }  
811
812 //___________________________________________________________________ 
813 void AliZDCQAChecker::SetupHisto(const TObjArray& messages, TH1& histo, Float_t& code)
814 {
815   //
816   /// Add text to histos
817   //
818
819   TPaveText* text = new TPaveText(0.70,0.70,0.99,0.99,"NDC");
820     
821   TIter next(&messages);
822   TObjString* str;
823     
824   while ( ( str = static_cast<TObjString*>(next()) ) ){
825     text->AddText(str->String());
826   }
827
828   TString defaultText = "";
829
830   Int_t color = 0;
831   if(code==1.){
832     color = kGreen;
833     defaultText = "Everything is fine!";
834   }  
835   else if(code<1. && code>=0.9){  
836     color = kYellow;
837     defaultText = "To be monitored in next runs";
838   }
839   else if(code<0.9 && code>=0.6){
840     color = kOrange;
841     defaultText = "notify the expert DURING THE DAY!";
842   }
843   else if(code<0.6){
844     color = kRed;
845     defaultText = "CALL THE EXPERT!!!!";
846   }
847
848
849   text->AddText(defaultText.Data());
850   text->SetFillColor(color);
851                       
852   //histo.SetFillStyle(1001);
853   //histo.SetFillColor(color);
854
855   histo.SetStats(kFALSE);
856     
857   histo.GetListOfFunctions()->Add(text);
858 }