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