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