]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerQADataMakerRec.cxx
Coverity fix
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerQADataMakerRec.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 // $Id: AliMUONTriggerQADataMakerRec.cxx 35760 2009-10-21 21:45:42Z ivana $
17
18 // --- MUON header files ---
19 #include "AliMUONTriggerQADataMakerRec.h"
20
21 //-----------------------------------------------------------------------------
22 /// \class AliMUONTriggerQADataMakerRec
23 ///
24 /// MUON class for quality assurance data (histo) maker
25 ///
26 /// \author C. Finck, D. Stocco, L. Aphecetche, A. Blanc
27
28 /// \cond CLASSIMP
29 ClassImp(AliMUONTriggerQADataMakerRec)
30 /// \endcond
31            
32 #include "AliCodeTimer.h"
33 #include "AliMUONConstants.h"
34 #include "AliMpConstants.h"
35 #include "AliMUONTriggerDisplay.h"
36 #include "TH2.h"
37 #include "TH1F.h"
38 #include "TString.h"
39 #include "AliRecoParam.h"
40 #include "AliMUONDigitStoreV2R.h"
41 #include "AliMUONTriggerStoreV1.h"
42 #include "AliMpCDB.h"
43 #include "AliMUONRawStreamTriggerHP.h"
44 #include "AliMpDDLStore.h"
45 #include "AliMpTriggerCrate.h"
46 #include "AliMpLocalBoard.h"
47 #include "AliQAv1.h"
48 #include "AliRawReader.h"
49 #include "AliMUONDigitMaker.h"
50 #include "AliMUONLocalTrigger.h"
51 #include "AliMUONRecoParam.h"
52 #include "AliMUONTriggerElectronics.h"
53 #include "AliMUONCalibrationData.h"
54 #include "AliDCSValue.h"
55 #include "AliMpDCSNamer.h"
56 #include "AliMpDEManager.h"
57 #include "AliMpDEIterator.h"
58 #include "AliCDBManager.h"
59 #include "TTree.h"
60 #include "AliMUONGlobalTriggerBoard.h"
61 #include "AliMUONGlobalTrigger.h"
62 #include "AliMUONGlobalCrateConfig.h"
63 #include "AliMUONQAIndices.h"
64 #include "AliMpPad.h"
65 #include "AliMpVSegmentation.h"
66 #include "AliMpSegmentation.h"
67
68 namespace
69 {
70   Double_t ProtectedSqrt(Double_t x)
71   {
72     return ( x > 0.0 ? TMath::Sqrt(x) : 0.0 );
73   }
74 }
75 //____________________________________________________________________________ 
76 AliMUONTriggerQADataMakerRec::AliMUONTriggerQADataMakerRec(AliQADataMakerRec* master) : 
77 AliMUONVQADataMakerRec(master),
78 fDigitMaker(new AliMUONDigitMaker(kFALSE)),
79 fCalibrationData(0x0),
80 fTriggerProcessor(0x0),
81 fDigitStore(0x0)
82 {
83     /// ctor
84 }
85
86
87 //__________________________________________________________________
88 AliMUONTriggerQADataMakerRec::~AliMUONTriggerQADataMakerRec()
89 {
90     /// dtor
91   delete fDigitMaker;
92   delete fDigitStore;
93   delete fTriggerProcessor;
94   delete fCalibrationData;
95 }
96
97 //____________________________________________________________________________ 
98 void AliMUONTriggerQADataMakerRec::EndOfDetectorCycleESDs(Int_t /*specie*/, TObjArray** /*list*/)
99 {
100   /// Normalize ESD histograms
101 }
102   
103 //____________________________________________________________________________ 
104 void AliMUONTriggerQADataMakerRec::EndOfDetectorCycleRecPoints(Int_t /*specie*/, TObjArray** /*list*/)
105 {
106   /// Normalize RecPoints histograms
107 }
108
109
110 //____________________________________________________________________________ 
111 void AliMUONTriggerQADataMakerRec::EndOfDetectorCycleRaws(Int_t /*specie*/, TObjArray** /*list*/)
112 {
113   /// create Raws histograms in Raws subdir
114   
115   Int_t histoRawsIndex[] = {
116     AliMUONQAIndices::kTriggerErrorSummary,
117     AliMUONQAIndices::kTriggerCalibSummary,
118     AliMUONQAIndices::kTriggerReadOutErrors,
119     AliMUONQAIndices::kTriggerGlobalOutput
120   };
121   Int_t histoRawsScaledIndex[] = {
122     AliMUONQAIndices::kTriggerErrorSummaryNorm,
123     AliMUONQAIndices::kTriggerCalibSummaryNorm,
124     AliMUONQAIndices::kTriggerReadOutErrorsNorm,
125     AliMUONQAIndices::kTriggerGlobalOutputNorm
126   };
127   
128   const Int_t kNrawsHistos = sizeof(histoRawsIndex)/sizeof(histoRawsIndex[0]);
129   Float_t scaleFactor[kNrawsHistos] = {100., 100., 100., 1.};
130
131   for ( Int_t itc=-1; itc<AliQADataMakerRec::GetNTrigClasses(); itc++) { 
132   
133     DisplayTriggerInfo(itc);
134
135     // Normalize RawData histos
136     TH1* histo1D = GetRawsData(AliMUONQAIndices::kTriggerRawNAnalyzedEvents,itc);
137     // This histogram is there for all relevant triggers
138     // if it is not there, it means that the trigger is not taken into account
139     // so we can skip the trigger class for all other histos
140     if ( ! histo1D ) continue;
141     Float_t nbevent = histo1D->GetBinContent(1);
142     for(Int_t ihisto=0; ihisto<kNrawsHistos; ihisto++){
143       TH1* inputHisto = GetRawsData(histoRawsIndex[ihisto],itc);
144       TH1* scaledHisto = GetRawsData(histoRawsScaledIndex[ihisto],itc);
145       // Check here for both since we do not clone Calib-only histograms
146       if ( scaledHisto && inputHisto &&  nbevent > 0 ) {
147         scaledHisto->Reset();
148         scaledHisto->Add(inputHisto);
149         scaledHisto->Scale(scaleFactor[ihisto]/nbevent);
150       }
151     } // loop on histos
152
153     
154     // The following histograms are surely there
155     // if the histogram with analyzed events is there:
156     // test on the existence of each histogram is not necessary
157     TH1* hYCopy = GetRawsData(AliMUONQAIndices::kTriggerErrorLocalYCopy,itc); //number of YCopy error per board
158     TH1* hYCopyTests = GetRawsData(AliMUONQAIndices::kTriggerErrorLocalYCopyTest,itc); //contains the number of YCopy test per board
159     TH1* hYCopyNorm = GetRawsData(AliMUONQAIndices::kTriggerErrorLocalYCopyNorm,itc); 
160     hYCopyNorm->Reset();
161     hYCopyNorm->Divide(hYCopy, hYCopyTests, 100., 1.);
162      
163     Float_t mean = hYCopyNorm->Integral();
164       
165     TH1* hSummary = GetRawsData(AliMUONQAIndices::kTriggerErrorSummaryNorm,itc);
166     hSummary->SetBinContent(AliMUONQAIndices::kAlgoLocalYCopy+1,mean/192.); //put the mean of the % of YCopy error in the kTriggerError's corresponding bin
167
168     TH1F* hTriggerRatio = (TH1F*)GetRawsData(AliMUONQAIndices::kTriggerLocalRatio4434,itc);
169     if ( hTriggerRatio ){
170       hTriggerRatio->Divide(((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerNumberOf44Dec,itc)),((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerNumberOf34Dec,itc)));
171
172       FillRatio4434Histos(1,itc,kTRUE);
173
174       //reset bins temporary used to store informations
175       ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerRatio4434AllEvents,itc))->SetBinContent(0,0); 
176       Int_t nbins =  ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerRatio4434AllEvents,itc))->GetNbinsX();
177       ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerRatio4434AllEvents,itc))->SetBinContent(nbins+1,0);
178
179       ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerLocalRatio4434,itc))->SetMaximum(1.1);
180       ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerRatio4434AllEvents,itc))->SetMaximum(1.1);
181       ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerRatio4434SinceLastUpdate,itc))->SetMaximum(1.1);
182     }
183   
184     if ( GetRawsData(AliMUONQAIndices::kTriggerGlobalScalersNorm,itc) ) {
185       TH1* inputHisto = GetRawsData(AliMUONQAIndices::kTriggerGlobalScalers,itc);
186       TH1* scaledHisto = GetRawsData(AliMUONQAIndices::kTriggerGlobalScalersNorm,itc);
187       scaledHisto->Reset();
188       scaledHisto->Add(inputHisto);
189       Float_t scaleValue = ((TH1F*)GetRawsData(AliMUONQAIndices::kTriggerScalersTime,itc))->GetBinContent(1);
190       if ( scaleValue > 0. ) scaledHisto->Scale(1./scaleValue);
191     }
192   } // loop on trigger classes
193 }
194
195 //____________________________________________________________________________ 
196 void AliMUONTriggerQADataMakerRec::InitRaws()
197 {
198     /// create Raws histograms in Raws subdir
199   
200   // RS: Since there is no sense in cloning trigger scalers per trigger, I am (for the moment) forbidding their cloning
201
202   AliCodeTimerAuto("",0);
203   
204   const Bool_t expert   = kTRUE ; 
205   const Bool_t saveCorr = kTRUE ; 
206   const Bool_t image    = kTRUE ; 
207  
208   TString boardName = "Local board Id";
209
210   Int_t nbLocalBoard = AliMUONConstants::NTriggerCircuit();
211
212   TH1F* histo1D = 0x0;
213   TH2F* histo2D = 0x0;
214
215   AliMUONTriggerDisplay triggerDisplay;
216
217   TString histoName, histoTitle;
218   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
219     histo1D = new TH1F("hTriggerScalersTime", "Acquisition time from trigger scalers", 1, 0.5, 1.5);
220     histo1D->GetXaxis()->SetBinLabel(1, "One-bin histogram: bin is filled at each scaler event.");
221     histo1D->GetYaxis()->SetTitle("Cumulated scaler time (s)");
222     Add2RawsList(histo1D, AliMUONQAIndices::kTriggerScalersTime, expert, !image, !saveCorr);
223     ForbidCloning(histo1D); // RS
224
225     for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
226       TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
227       for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
228         histoName = Form("hTriggerScalers%sChamber%i", cathName.Data(), 11+iChamber);
229         histoTitle = Form("Chamber %i - %s: trigger scaler counts", 11+iChamber, cathName.Data());
230         histo2D = new TH2F(histoName.Data(), histoTitle.Data(),
231                            nbLocalBoard, 0.5, (Float_t)nbLocalBoard + 0.5,
232                            16, -0.5, 15.5);
233         histo2D->GetXaxis()->SetTitle(boardName.Data());
234         histo2D->GetYaxis()->SetTitle("Strip"); 
235         histo2D->SetOption("COLZ");     
236         Add2RawsList(histo2D, AliMUONQAIndices::kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber, expert, !image, !saveCorr);
237         ForbidCloning(histo2D); // RS
238       } // loop on chambers
239     } // loop on cathodes
240         
241     for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
242       TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
243       for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
244         histoName = Form("hTriggerScalersDisplay%sChamber%i", cathName.Data(), 11+iChamber);
245         histoTitle = Form("Chamber %i - %s: Hit rate from scalers (Hz/cm^{2})", 11+iChamber, cathName.Data());
246         histo2D = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplayStrips, 
247                                                              iCath, iChamber, histoTitle);
248         histo2D->SetOption("COLZ");
249         Add2RawsList(histo2D, AliMUONQAIndices::kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, expert, !image, !saveCorr);
250         ForbidCloning(histo2D); // RS
251       } // loop on chambers
252     } // loop on cathodes    
253
254     TString axisLabel[AliMUONQAIndices::kNtrigCalibSummaryBins] = {"#splitline{Dead}{Channels}", "#splitline{Dead}{Local Boards}", "#splitline{Dead}{Regional Boards}", "#splitline{Dead}{Global Board}", "#splitline{Noisy}{Strips}"};
255
256     TH1F* histoCalib = new TH1F("hTriggerCalibSummaryAll", "MTR calibration summary counts", AliMUONQAIndices::kNtrigCalibSummaryBins, -0.5, (Float_t)AliMUONQAIndices::kNtrigCalibSummaryBins - 0.5);
257     for (Int_t ibin=1; ibin<=AliMUONQAIndices::kNtrigCalibSummaryBins; ibin++){
258       histoCalib->GetXaxis()->SetBinLabel(ibin, axisLabel[ibin-1].Data());
259     }
260     histoCalib->SetFillColor(kBlue);
261     histoCalib->GetYaxis()->SetTitle("Counts");
262     // Copy of previous histo for scaling purposes
263     TH1F* histoCalibNorm = (TH1F*)histoCalib->Clone("hTriggerCalibSummary");
264     histoCalibNorm->SetTitle("MTR calibration summary");
265     histoCalibNorm->SetOption("bartext0");
266     histoCalibNorm->GetYaxis()->SetTitle("Percentage per event (%)");
267     // Adding both histos after cloning to avoid problems with the expert bit
268     Add2RawsList(histoCalib,     AliMUONQAIndices::kTriggerCalibSummary,      expert, !image, !saveCorr);
269     ForbidCloning(histoCalib); // RS
270
271     Add2RawsList(histoCalibNorm, AliMUONQAIndices::kTriggerCalibSummaryNorm, !expert,  image, !saveCorr);
272     ForbidCloning(histoCalibNorm); // RS
273
274   } // Calibration reco param
275         
276   const char *globalXaxisName[6] = {"US HPt", "US LPt", "LS HPt", "LS LPt", "SGL HPt", "SGL LPt"};
277   const char *allLevelXaxisName[AliMUONQAIndices::kNtrigAlgoErrorBins] = {"Local algo X", "Local algo Y", "Local LUT","Local Y Copy" , "Local2Regional", "Regional", "Regional2Global", "GlobalFromInGlobal", "GlobalFromInLocal", "GlobalFromOutLocal"};
278   const char *readoutErrNames[AliMUONQAIndices::kNtrigStructErrorBins]={"Local","Regional","Global","DARC"};
279
280   TString errorAxisTitle = "Number of errors";
281
282   histo1D = new TH1F("hTriggerErrorLocalXPos", "ErrorLocalXPos",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
283   histo1D->GetXaxis()->SetTitle(boardName.Data());
284   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
285   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalXPos, expert, !image, !saveCorr);
286
287   histo1D = new TH1F("hTriggerErrorLocalYPos", "ErrorLocalYPos",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
288   histo1D->GetXaxis()->SetTitle(boardName.Data());
289   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
290   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalYPos, expert, !image, !saveCorr);
291
292   histo1D = new TH1F("hTriggerErrorLocalDev", "ErrorLocalDev",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
293   histo1D->GetXaxis()->SetTitle(boardName.Data());
294   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
295   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalDev, expert, !image, !saveCorr);
296
297   histo1D = new TH1F("hTriggerErrorLocalTriggerDec", "ErrorLocalTriggerDec",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
298   histo1D->GetXaxis()->SetTitle(boardName.Data());
299   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
300   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalTriggerDec, expert, !image, !saveCorr);
301
302   histo1D = new TH1F("hTriggerErrorLocalLPtLSB", "ErrorLocalLPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
303   histo1D->GetXaxis()->SetTitle(boardName.Data());
304   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
305   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalLPtLSB, expert, !image, !saveCorr);
306
307   histo1D = new TH1F("hTriggerErrorLocalLPtMSB", "ErrorLocalLPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
308   histo1D->GetXaxis()->SetTitle(boardName.Data());
309   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
310   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalLPtMSB, expert, !image, !saveCorr);
311
312   histo1D = new TH1F("hTriggerErrorLocalHPtLSB", "ErrorLocalHPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
313   histo1D->GetXaxis()->SetTitle(boardName.Data());
314   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
315   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalHPtLSB, expert, !image, !saveCorr);
316
317   histo1D = new TH1F("hTriggerErrorLocalHPtMSB", "ErrorLocalHPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
318   histo1D->GetXaxis()->SetTitle(boardName.Data());
319   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
320   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalHPtMSB, expert, !image, !saveCorr);
321
322   histo1D = new TH1F("hTriggerErrorLocalTrigY", "ErrorLocalTrigY",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
323   histo1D->GetXaxis()->SetTitle(boardName.Data());
324   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
325   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocalTrigY, expert, !image, !saveCorr);
326
327   if ( GetRecoParam()->GetEventSpecie() != AliRecoParam::kCalib ) {
328     histo1D = new TH1F("hTriggerRatio4434Local", "Ratio4434Local",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
329     histo1D->GetXaxis()->SetTitle(boardName.Data());
330     histo1D->GetYaxis()->SetTitle("ratio 44/34");
331     Add2RawsList(histo1D, AliMUONQAIndices::kTriggerLocalRatio4434, expert, !image, !saveCorr);                                               
332     histo1D = new TH1F("hTriggerRatio4434AllEvents", "Ratio4434AllEvents",1,0,1);
333     histo1D->GetXaxis()->SetTitle("Event number");
334     histo1D->GetYaxis()->SetTitle("ratio 44/34");
335     histo1D->SetLineColor(4);                           
336     Add2RawsList(histo1D, AliMUONQAIndices::kTriggerRatio4434AllEvents, expert, !image, !saveCorr);                                               
337     histo1D = new TH1F("hTriggerRatio4434SinceLastUpdate", "Ratio4434SinceLastUpdate",1,0,1);
338     histo1D->GetXaxis()->SetTitle("Event number");
339     histo1D->GetYaxis()->SetTitle("ratio 44/34");                           
340     Add2RawsList(histo1D, AliMUONQAIndices::kTriggerRatio4434SinceLastUpdate, expert, !image, !saveCorr);
341   }
342
343   histo1D = new TH1F("hTriggerErrorLocal2RegionalLPtLSB", "ErrorLocal2RegionalLPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
344   histo1D->GetXaxis()->SetTitle(boardName.Data());
345   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
346   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocal2RegionalLPtLSB, expert, !image, !saveCorr);
347
348   histo1D = new TH1F("hTriggerErrorLocal2RegionalLPtMSB", "ErrorLocal2RegionalLPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
349   histo1D->GetXaxis()->SetTitle(boardName.Data());
350   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
351   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocal2RegionalLPtMSB, expert, !image, !saveCorr);
352
353   histo1D = new TH1F("hTriggerErrorLocal2RegionalHPtLSB", "ErrorLocal2RegionalHPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
354   histo1D->GetXaxis()->SetTitle(boardName.Data());
355   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
356   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocal2RegionalHPtLSB, expert, !image, !saveCorr);
357
358   histo1D = new TH1F("hTriggerErrorLocal2RegionalHPtMSB", "ErrorLocal2RegionalHPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
359   histo1D->GetXaxis()->SetTitle(boardName.Data());
360   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
361   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorLocal2RegionalHPtMSB, expert, !image, !saveCorr);
362
363   histo1D = new TH1F("hTriggerErrorOutGlobalFromInGlobal", "ErrorOutGlobalFromInGlobal",6,-0.5,6-0.5);
364   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
365   for (int ibin=0;ibin<6;ibin++){
366     histo1D->GetXaxis()->SetBinLabel(ibin+1,globalXaxisName[ibin]);
367   }
368   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorOutGlobalFromInGlobal, expert, !image, !saveCorr);
369
370   histo1D = new TH1F("hTriggerErrorOutGlobalFromInLocal", "ErrorOutGlobalFromInLocal",6,-0.5,6-0.5);
371   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
372   for (int ibin=0;ibin<6;ibin++){
373     histo1D->GetXaxis()->SetBinLabel(ibin+1,globalXaxisName[ibin]);
374   }
375   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerErrorOutGlobalFromInLocal, expert, !image, !saveCorr);
376
377   TH1F* histoAlgoErr = new TH1F("hTriggerAlgoNumOfErrors", "Trigger Algorithm total errors",AliMUONQAIndices::kNtrigAlgoErrorBins,-0.5,(Float_t)AliMUONQAIndices::kNtrigAlgoErrorBins-0.5);
378   histoAlgoErr->GetYaxis()->SetTitle("Number of events with errors");
379   for (int ibin=0;ibin<AliMUONQAIndices::kNtrigAlgoErrorBins;ibin++){
380     histoAlgoErr->GetXaxis()->SetBinLabel(ibin+1,allLevelXaxisName[ibin]);
381   }
382   histoAlgoErr->SetFillColor(kBlue);
383   // Copy of previous histo for scaling purposes
384   TH1F* histoAlgoErrNorm = (TH1F*)histoAlgoErr->Clone("hTriggerAlgoErrors");
385   histoAlgoErrNorm->SetOption("bartext0");
386   histoAlgoErrNorm->SetTitle("Trigger algorithm errors");
387   histoAlgoErrNorm->GetYaxis()->SetTitle("% of events with errors");
388   // Adding both histos after cloning to avoid problems with the expert bit
389   Add2RawsList(histoAlgoErr,     AliMUONQAIndices::kTriggerErrorSummary,      expert, !image, !saveCorr);
390   Add2RawsList(histoAlgoErrNorm, AliMUONQAIndices::kTriggerErrorSummaryNorm, !expert,  image, !saveCorr);  
391
392   histo1D = new TH1F("hTriggerTriggeredBoards", "Triggered boards", nbLocalBoard, 0.5, (Float_t)nbLocalBoard + 0.5);
393   Add2RawsList(histo1D, AliMUONQAIndices::kTriggeredBoards, expert, !image, !saveCorr);
394
395   histo2D = (TH2F*)triggerDisplay.GetEmptyDisplayHisto("hTriggerFiredBoardsDisplay", AliMUONTriggerDisplay::kDisplayBoards,
396                                                        0, 0, "Local board triggers / event");
397   histo2D->SetOption("COLZ");
398   Add2RawsList(histo2D, AliMUONQAIndices::kTriggerBoardsDisplay, expert, !image, !saveCorr);
399
400   TH1F* histoYCopyErr = new TH1F("hTriggerErrorLocalYCopy", "Number of YCopy errors",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
401   histoYCopyErr->GetXaxis()->SetTitle(boardName.Data());
402   histoYCopyErr->GetYaxis()->SetTitle(errorAxisTitle.Data());
403   // Copy of previous histo for scaling purposes
404   TH1F* histoYCopyErrTest = (TH1F*)histoYCopyErr->Clone("hTriggerErrorLocalYCopyTest");
405   histoYCopyErrTest->SetTitle("Number of YCopy tested");
406   // Copy of previous histo for scaling purposes
407   TH1F* histoYCopyErrNorm = (TH1F*)histoYCopyErr->Clone("hTriggerErrorLocalYCopyNorm");
408   histoYCopyErrNorm->SetTitle("% of YCopy errors");
409   // Adding both histos after cloning to avoid problems with the expert bit
410   Add2RawsList(histoYCopyErr,     AliMUONQAIndices::kTriggerErrorLocalYCopy,     expert, !image, !saveCorr);
411   Add2RawsList(histoYCopyErrTest, AliMUONQAIndices::kTriggerErrorLocalYCopyTest, expert, !image, !saveCorr);
412   Add2RawsList(histoYCopyErrNorm, AliMUONQAIndices::kTriggerErrorLocalYCopyNorm, expert, !image, !saveCorr);
413
414   TH1F* histoROerr = new TH1F("hTriggerReadoutNumOfErrors","Trigger Read-Out total errors", AliMUONQAIndices::kNtrigStructErrorBins, -0.5, (Float_t)AliMUONQAIndices::kNtrigStructErrorBins-0.5);
415   histoROerr->GetYaxis()->SetTitle("Fraction of errors");
416   histoROerr->SetFillColor(kBlue);
417   for (int ibin=0;ibin<AliMUONQAIndices::kNtrigStructErrorBins;ibin++){
418     histoROerr->GetXaxis()->SetBinLabel(ibin+1,readoutErrNames[ibin]);
419   }
420   // Copy of previous histo for scaling purposes
421   TH1F* histoROerrNorm = (TH1F*)histoROerr->Clone("hTriggerReadoutErrors");
422   histoROerrNorm->SetTitle("Trigger Read-Out errors");
423   histoROerrNorm->SetOption("bartext0");
424   histoROerrNorm->GetYaxis()->SetTitle("% of errors per event");
425   // Adding both histos after cloning to avoid problems with the expert bit
426   Add2RawsList(histoROerr,     AliMUONQAIndices::kTriggerReadOutErrors,      expert, !image, !saveCorr);
427   Add2RawsList(histoROerrNorm, AliMUONQAIndices::kTriggerReadOutErrorsNorm, !expert,  image, !saveCorr);
428
429   TH1F* histoGlobalMult = new TH1F("hTriggerGlobalOutMultiplicity","Trigger global outputs multiplicity", 6, -0.5, 6.-0.5);
430   histoGlobalMult->GetYaxis()->SetTitle("Number of triggers"); 
431   histoGlobalMult->GetXaxis()->SetTitle("Global output");
432   for (int ibin=0;ibin<6;ibin++){
433     histoGlobalMult->GetXaxis()->SetBinLabel(ibin+1,globalXaxisName[ibin]);
434   }        
435   histoGlobalMult->SetFillColor(kBlue);
436   // Copy of previous histo for scaling purposes
437   TH1F* histoGlobalMultNorm = (TH1F*)histoGlobalMult->Clone("hTriggerGlobalOutMultiplicityPerEvt");
438   histoGlobalMultNorm->SetTitle("Trigger global outputs multiplicity per event");
439   histoGlobalMultNorm->SetOption("bartext0");
440   //histoGlobalMultNorm->SetBarWidth(0.5);
441   //histoGlobalMultNorm->SetBarOffset(0.25);
442   histoGlobalMultNorm->GetYaxis()->SetTitle("Triggers per event");
443   // Adding both histos after cloning to avoid problems with the expert bit
444   Add2RawsList(histoGlobalMult,     AliMUONQAIndices::kTriggerGlobalOutput,     expert, !image, !saveCorr);
445   Add2RawsList(histoGlobalMultNorm, AliMUONQAIndices::kTriggerGlobalOutputNorm, expert, !image, !saveCorr);
446
447   histo1D = new TH1F("hTriggerRawNAnalyzedEvents", "Number of analyzed events per specie", 1, 0.5, 1.5);
448   Int_t esindex = AliRecoParam::AConvert(CurrentEventSpecie());
449   histo1D->GetXaxis()->SetBinLabel(1, AliRecoParam::GetEventSpecieName(esindex));
450   histo1D->GetYaxis()->SetTitle("Number of analyzed events");
451   Add2RawsList(histo1D, AliMUONQAIndices::kTriggerRawNAnalyzedEvents, expert, !image, !saveCorr);
452
453   if ( GetRecoParam()->GetEventSpecie() != AliRecoParam::kCalib ) {
454     histo1D = new TH1F("hTriggerNumberOf34Dec", "Number of 3/4",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
455     histo1D->GetXaxis()->SetTitle(boardName.Data());
456     histo1D->GetYaxis()->SetTitle("Number of 3/4");
457     Add2RawsList(histo1D, AliMUONQAIndices::kTriggerNumberOf34Dec, expert, !image, !saveCorr);
458
459     histo1D = new TH1F("hTriggerNumberOf44Dec", "Number of 4/4",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
460     histo1D->GetXaxis()->SetTitle(boardName.Data());
461     histo1D->GetYaxis()->SetTitle("Number of 4/4");
462     Add2RawsList(histo1D, AliMUONQAIndices::kTriggerNumberOf44Dec, expert, !image, !saveCorr);
463   }
464   
465   histo1D = new TH1F("hTriggerIsThere","trigger is there",1,0,1);
466   Add2RawsList(histo1D,AliMUONQAIndices::kTriggerIsThere,kTRUE,kFALSE,kFALSE);
467
468   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
469     TH1F* histoGlobalScalers = new TH1F("hTriggerGlobalScalers","Trigger global scalers", 6, -0.5, 6.-0.5);
470     histoGlobalScalers->GetYaxis()->SetTitle("L0 counts");
471     histoGlobalScalers->GetXaxis()->SetTitle("Global output");
472     for (int ibin=0;ibin<6;ibin++){
473       histoGlobalScalers->GetXaxis()->SetBinLabel(ibin+1,globalXaxisName[ibin]);
474     }        
475     // Copy of previous histo for scaling purposes
476     TH1F* histoGlobalScalersNorm = (TH1F*)histoGlobalScalers->Clone("hTriggerGlobalScalersRate");
477     histoGlobalScalersNorm->SetTitle("Trigger global L0 scalers rate");
478     histoGlobalScalersNorm->SetOption("etext0");
479     histoGlobalScalersNorm->GetYaxis()->SetTitle("L0 scalers rate (Hz)");
480     // Adding both histos after cloning to avoid problems with the expert bit
481     Add2RawsList(histoGlobalScalers,     AliMUONQAIndices::kTriggerGlobalScalers,     expert, !image, !saveCorr);
482     ForbidCloning(histoGlobalScalers); // RS
483     Add2RawsList(histoGlobalScalersNorm, AliMUONQAIndices::kTriggerGlobalScalersNorm, expert, !image, !saveCorr);
484     ForbidCloning(histoGlobalScalersNorm); // RS
485   }
486   //
487   //ClonePerTrigClass(AliQAv1::kRAWS); // RS: this should be the last line  DONE at parent level
488   //
489 }
490
491 //__________________________________________________________________
492 void AliMUONTriggerQADataMakerRec::InitDigits() 
493 {
494   /// Initialized Digits spectra 
495   const Bool_t expert   = kTRUE ; 
496   const Bool_t image    = kTRUE ; 
497   
498   TH1I* h0 = new TH1I("hTriggerDigitsDetElem", "Detection element distribution in Digits;Detection element Id;Counts",  400, 1100, 1500); 
499   Add2DigitsList(h0, 0, !expert, image);
500   ForbidCloning(h0);
501   //
502   //ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line  DONE at parent level
503   //
504
505
506 //____________________________________________________________________________ 
507 void AliMUONTriggerQADataMakerRec::InitRecPoints()
508 {
509         /// create Reconstructed Points histograms in RecPoints subdir for the
510         /// MUON Trigger subsystem.
511
512   const Bool_t expert   = kTRUE ; 
513   const Bool_t image    = kTRUE ; 
514
515   TH1F* histo1D = 0x0;
516
517   histo1D = new TH1F("hTriggerNAnalyzedEvents", "Number of analyzed events per specie", 1, 0.5, 1.5);
518   Int_t esindex = AliRecoParam::AConvert(CurrentEventSpecie());
519   histo1D->GetXaxis()->SetBinLabel(1, AliRecoParam::GetEventSpecieName(esindex));
520   histo1D->GetYaxis()->SetTitle("Number of analyzed events");
521   Add2RecPointsList(histo1D, AliMUONQAIndices::kTriggerNAnalyzedEvents, expert, !image);
522   ForbidCloning(histo1D);
523
524   histo1D = new TH1F("hTriggerTrippedChambers", "Trigger RPCs in trip", 418, 1100-0.5, 1417+0.5);
525   histo1D->GetXaxis()->SetTitle("DetElemId");
526   histo1D->GetYaxis()->SetTitle("# of trips");
527   histo1D->SetFillColor(kRed);
528   histo1D->SetLineColor(kRed);
529   Add2RecPointsList(histo1D, AliMUONQAIndices::kTriggerRPCtrips, !expert, image);
530   ForbidCloning(histo1D);   // RS this histo is not cloned
531   //
532   FillTriggerDCSHistos();
533   //
534   //ClonePerTrigClass(AliQAv1::kRECPOINTS); DONE at parent level
535   //
536 }
537
538
539 //____________________________________________________________________________ 
540 void AliMUONTriggerQADataMakerRec::InitESDs()
541 {
542   /// Empty implementation
543 }
544
545 //____________________________________________________________________________
546 void AliMUONTriggerQADataMakerRec::MakeRaws(AliRawReader* rawReader)
547 {
548         /// make QA for rawdata trigger
549
550     AliCodeTimerAuto("",0);
551         
552     // Init Local/Regional/Global decision with fake values
553     //
554     
555     //
556
557     UInt_t globalInput[4];
558     for (Int_t bit=0; bit<4; bit++){
559         globalInput[bit]=0;
560     }
561
562     //for (Int_t reg=0;reg<16;reg++){
563     //fTriggerOutputRegionalData[reg]=0;
564     //for (Int_t bit=0;bit<4;bit++){
565     //fTriggerInputGlobalDataLPt[reg][bit]=0;
566     //fTriggerInputGlobalDataHPt[reg][bit]=0;
567     //}
568     //}
569
570     AliMUONDigitStoreV2R digitStore;
571     
572     AliMUONTriggerStoreV1 recoTriggerStore;
573
574     AliMUONTriggerStoreV1 inputTriggerStore;
575
576     AliMUONGlobalTrigger inputGlobalTrigger;
577
578     UShort_t maxNcounts = 0xFFFF;
579     
580     // Get trigger Local, Regional, Global in/outputs and scalers
581
582     Int_t loCircuit=0;
583     AliMpCDB::LoadDDLStore();
584
585     const AliMUONRawStreamTriggerHP::AliHeader*          darcHeader  = 0x0;
586     const AliMUONRawStreamTriggerHP::AliRegionalHeader*  regHeader   = 0x0;
587     const AliMUONRawStreamTriggerHP::AliLocalStruct*     localStruct = 0x0;
588
589     Int_t nDeadLocal = 0, nDeadRegional = 0, nDeadGlobal = 0, nNoisyStrips = 0;
590     Int_t nFiredStrips = 0, nStripsTot = 0;
591
592     // When a crate is not present, the loop on boards is not performed
593     // This should allow to correctly count the local boards
594     Int_t countNotifiedBoards = 0, countAllBoards = 0;
595
596     Bool_t containTriggerData = kFALSE;
597     AliMUONRawStreamTriggerHP rawStreamTrig(rawReader);
598     while (rawStreamTrig.NextDDL()) 
599       {
600        containTriggerData = kTRUE;
601
602       Bool_t scalerEvent =  rawReader->GetDataHeader()->GetL1TriggerMessage() & 0x1;
603
604       Bool_t fillScalerHistos = ( scalerEvent && 
605                                   ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) );
606
607       if ( scalerEvent != fillScalerHistos ) {
608         Int_t esindex = AliRecoParam::AConvert(CurrentEventSpecie());
609         AliWarning(Form("Scaler event found but event specie is %s. Scaler histos will not be filled", AliRecoParam::GetEventSpecieName(esindex)));
610       }
611
612       darcHeader = rawStreamTrig.GetHeaders();
613
614       if (darcHeader->GetGlobalFlag()){
615         if ( fillScalerHistos ) {
616           UInt_t nOfClocks = darcHeader->GetGlobalClock();
617           Double_t nOfSeconds = ((Double_t) nOfClocks) / 40e6; // 1 clock each 25 ns
618           FillRawsData(AliMUONQAIndices::kTriggerScalersTime, 1., nOfSeconds);
619           const UInt_t* globScaler = darcHeader->GetGlobalScaler();
620           Int_t bitCorr[6] = {2,0,3,1,4,5};
621           for (Int_t bit=0; bit<6; bit++){
622             FillRawsData(AliMUONQAIndices::kTriggerGlobalScalers, bitCorr[bit],(double)(*(globScaler+bit)));
623           }
624         }
625
626         //Get Global datas
627         inputGlobalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
628         Int_t resp[6] = {inputGlobalTrigger.PairUnlikeHpt(), inputGlobalTrigger.PairUnlikeLpt(),
629           inputGlobalTrigger.PairLikeHpt(), inputGlobalTrigger.PairLikeLpt(),
630           inputGlobalTrigger.SingleHpt(), inputGlobalTrigger.SingleLpt()}; 
631         for (Int_t bit=0; bit<6; bit++){
632           if ( resp[bit] == 0 ){
633             if ( fillScalerHistos )
634               nDeadGlobal++;
635           }
636           else
637             FillRawsData(AliMUONQAIndices::kTriggerGlobalOutput, bit, resp[bit]);
638         } // loop on bits
639
640         //for (Int_t Bit=0; Bit<32; Bit++){
641         //fTriggerInputGlobalDataLPt[Bit/4][Bit%4]=((darcHeader->GetGlobalInput(0)>>Bit)&1);
642         //fTriggerInputGlobalDataLPt[Bit/4+8][Bit%4]=((darcHeader->GetGlobalInput(1)>>Bit)&1);
643         //fTriggerInputGlobalDataHPt[Bit/4][Bit%4]=((darcHeader->GetGlobalInput(2)>>Bit)&1);
644         //fTriggerInputGlobalDataHPt[Bit/4+8][Bit%4]=((darcHeader->GetGlobalInput(3)>>Bit)&1);
645         //}
646
647         for (Int_t i=0; i<4; i++){
648           globalInput[i]=darcHeader->GetGlobalInput(i);
649         }
650       }
651
652       Int_t nReg = rawStreamTrig.GetRegionalHeaderCount();
653
654       for(Int_t iReg = 0; iReg < nReg ;iReg++)
655       {   //reg loop
656
657         //Int_t regId=rawStreamTrig.GetDDL()*8+iReg;
658
659         // crate info  
660           AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(rawStreamTrig.GetDDL(), iReg);
661
662           regHeader =  rawStreamTrig.GetRegionalHeader(iReg);
663
664           //Get regional outputs -> not checked, hardware read-out doesn't work
665           //fTriggerOutputRegionalData[regId]=Int_t(regHeader->GetOutput());
666           // if ( ! fTriggerOutputRegionalData[regId] )
667           // nDeadRegional++;
668         Int_t nBoardsInReg = 0; // Not necessary when regional output will work
669
670         // loop over local structures
671         Int_t nLocal = regHeader->GetLocalStructCount();
672
673         for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
674         {
675             
676             localStruct = regHeader->GetLocalStruct(iLocal);
677
678           // if card exist
679           if (!localStruct) continue;
680           
681           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
682
683           if ( !loCircuit ) continue; // empty slot
684
685           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
686
687           nBoardsInReg++; // Not necessary when regional output will work
688           countAllBoards++;
689
690           // skip copy cards
691           if( !localBoard->IsNotified()) 
692             continue;
693
694           AliMUONLocalTrigger inputLocalTrigger;
695           inputLocalTrigger.SetLocalStruct(loCircuit, *localStruct);
696           inputTriggerStore.Add(inputLocalTrigger);
697
698           countNotifiedBoards++;  
699
700           TArrayS xyPattern[2];   
701           localStruct->GetXPattern(xyPattern[0]);
702           localStruct->GetYPattern(xyPattern[1]);
703           fDigitMaker->TriggerDigits(loCircuit, xyPattern, digitStore);
704
705           //Get electronic Decisions from data
706
707           //Get regional inputs -> not checked, hardware read-out doesn't work
708           //fTriggerInputRegionalDataLPt[0][loCircuit]=Int_t(((regHeader->GetInput(0))>>(2*iLocal))&1);
709           //fTriggerInputRegionalDataLPt[1][loCircuit]=Int_t(((regHeader->GetInput(1))>>((2*iLocal)+1))&1);
710
711           //Get local in/outputs
712           if (Int_t(localStruct->GetDec())!=0){
713             FillRawsData(AliMUONQAIndices::kTriggeredBoards,loCircuit);
714           }
715           else if ( fillScalerHistos ){
716             nDeadLocal++;
717           }
718
719           // loop over strips
720           if ( fillScalerHistos ) {
721             Int_t cathode = localStruct->GetComptXY()%2;
722       
723       Int_t offset = 0;
724       if (cathode && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
725
726             for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
727               if (ibitxy==0){
728                 AliDebug(AliQAv1::GetQADebugLevel(),"Filling trigger scalers");
729               }
730
731               UShort_t scalerVal[4] = {
732                 localStruct->GetXY1(ibitxy),
733                 localStruct->GetXY2(ibitxy),
734                 localStruct->GetXY3(ibitxy),
735                 localStruct->GetXY4(ibitxy)
736               };
737         
738         
739
740         for(Int_t ich=0; ich<AliMpConstants::NofTriggerChambers(); ich++){
741           // getDetElemId
742           Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(loCircuit, ich);
743                                         
744           const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(cathode));
745                                         
746                                         
747           Int_t istrip = ibitxy + offset;
748                                         
749           AliMpPad pad = seg->PadByLocation(loCircuit,istrip,kFALSE);
750           if (!pad.IsValid()) continue;
751           nStripsTot++;
752           
753           // UShort_t pattern = (UShort_t)xyPattern[cathode].At(ich); 
754           // if ((pattern >> ibitxy) & 0x1) nFiredStrips++;
755           
756           if ( scalerVal[ich] > 0 ) {
757             FillRawsData(AliMUONQAIndices::kTriggerScalers + AliMpConstants::NofTriggerChambers()*cathode + ich,
758                          loCircuit, istrip, 2*(Float_t)scalerVal[ich]);
759             nFiredStrips++;
760           }
761
762           if ( scalerVal[ich] >= maxNcounts )
763             nNoisyStrips++;
764         } // loop on chamber
765             } // loop on strips
766           } // scaler event
767         } // iLocal
768         if ( nBoardsInReg == 0 )
769           nDeadRegional++; // Not necessary when regional output will work
770       } // iReg
771
772       Float_t readoutErrors[AliMUONQAIndices::kNtrigStructErrorBins] = {
773         ((Float_t)rawStreamTrig.GetLocalEoWErrors())/((Float_t)countAllBoards),
774         ((Float_t)rawStreamTrig.GetRegEoWErrors())/16.,
775         ((Float_t)rawStreamTrig.GetGlobalEoWErrors())/6.,
776         ((Float_t)rawStreamTrig.GetDarcEoWErrors())/2.
777       };
778     
779       for (Int_t ibin=0; ibin<AliMUONQAIndices::kNtrigStructErrorBins; ibin++){
780         if ( readoutErrors[ibin] > 0 )
781           FillRawsData(AliMUONQAIndices::kTriggerReadOutErrors, ibin, readoutErrors[ibin]);
782       }
783     } // NextDDL
784
785     if ( ! containTriggerData ) return;
786
787     FillRawsData(AliMUONQAIndices::kTriggerRawNAnalyzedEvents,1.);
788
789     nDeadLocal += AliMUONConstants::NTriggerCircuit() - countNotifiedBoards;
790     if ( nStripsTot > 0 ) { // The value is != 0 only for scaler events
791       AliDebug(AliQAv1::GetQADebugLevel(), Form("nStripsFired %i  nStripsTot %i", nFiredStrips, nStripsTot));
792       Float_t fraction[AliMUONQAIndices::kNtrigCalibSummaryBins] = {
793         ((Float_t)(nStripsTot - nFiredStrips)) / ((Float_t)nStripsTot),
794         //(Float_t)nDeadLocal / ((Float_t)countNotifiedBoards),
795         (Float_t)nDeadLocal / ((Float_t)AliMUONConstants::NTriggerCircuit()),
796         (Float_t)nDeadRegional / 16.,
797         (Float_t)nDeadGlobal / 6., // Number of bits of global response
798         (Float_t)nNoisyStrips / ((Float_t)nStripsTot),
799       };
800
801       for(Int_t ibin = 0; ibin < AliMUONQAIndices::kNtrigCalibSummaryBins; ibin++){
802         if ( fraction[ibin] > 0. )
803           FillRawsData(AliMUONQAIndices::kTriggerCalibSummary,ibin, fraction[ibin]);
804       }
805     }
806
807   TriggerElectronics()->Digits2Trigger(digitStore,recoTriggerStore);
808
809   AliMUONGlobalTrigger* recoGlobalTriggerFromLocal;
810   recoGlobalTriggerFromLocal = recoTriggerStore.Global();
811
812   //Reconstruct Global decision from Global inputs
813   UChar_t recoResp = RawTriggerInGlobal2OutGlobal(globalInput);
814   AliMUONGlobalTrigger recoGlobalTriggerFromGlobal;
815   recoGlobalTriggerFromGlobal.SetFromGlobalResponse(recoResp);
816
817   // Compare data and reconstructed decisions and fill histos
818   RawTriggerMatchOutLocal(inputTriggerStore, recoTriggerStore);
819   //Fill ratio 44/34 histos
820   for ( Int_t itc=-1; itc<AliQADataMakerRec::GetNEventTrigClasses(); ++itc ) FillRatio4434Histos(fgkUpdateRatio4434, itc, kFALSE);
821   //RawTriggerMatchOutLocalInRegional(); // Not tested, hardware read-out doesn't work
822   RawTriggerMatchOutGlobal(inputGlobalTrigger, recoGlobalTriggerFromGlobal, 'G');
823   // Global, reconstruction from Local inputs: compare data and reconstructed decisions and fill histos
824   RawTriggerMatchOutGlobal(inputGlobalTrigger, *recoGlobalTriggerFromLocal, 'L');
825   // Global, reconstruction from Global inputs: compare data and reconstructed decisions and fill histos
826   //
827 }
828
829 //__________________________________________________________________
830 void AliMUONTriggerQADataMakerRec::MakeDigits(TTree* digitsTree)         
831 {
832   /// makes data from Digits
833
834   // Do nothing in case of calibration event
835   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
836   
837   if (!fDigitStore)
838     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
839   
840   fDigitStore->Clear();
841   fDigitStore->Connect(*digitsTree, false);
842   digitsTree->GetEvent(0);
843   
844   TIter next(fDigitStore->CreateIterator());
845   
846   AliMUONVDigit* dig = 0x0;
847   
848   while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) )
849     {
850       FillDigitsData(0,dig->DetElemId());
851     }
852 }
853
854 //____________________________________________________________________________
855 void AliMUONTriggerQADataMakerRec::MakeRecPoints(TTree* /*clustersTree*/)
856 {
857   /// Fill histogram with total number of analyzed events for normalization purposes
858
859   // Do nothing in case of calibration event
860   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
861         
862   FillRecPointsData(AliMUONQAIndices::kTriggerNAnalyzedEvents,1.);
863 }
864
865 //____________________________________________________________________________
866 void AliMUONTriggerQADataMakerRec::MakeESDs(AliESDEvent* /*esd*/)
867 {  
868   /// Empty implementation
869 }
870
871
872 //____________________________________________________________________________ 
873 void AliMUONTriggerQADataMakerRec::DisplayTriggerInfo(Int_t itc)
874 {
875   //
876   /// Display trigger information in a user-friendly way:
877   /// from local board and strip numbers to their position on chambers
878   //
879
880   AliMUONTriggerDisplay triggerDisplay;
881   
882   TH2* histoStrips=0x0;
883   TH2* histoDisplayStrips=0x0;
884   if ( GetRawsData(AliMUONQAIndices::kTriggerScalers, itc) ) {
885     AliMUONTriggerDisplay::EDisplayOption displayOption = AliMUONTriggerDisplay::kNormalizeToArea;
886     for (Int_t iCath = 0; iCath < AliMpConstants::NofCathodes(); iCath++)
887       {    
888         for (Int_t iChamber = 0; iChamber < AliMpConstants::NofTriggerChambers(); iChamber++)
889           {
890             histoStrips = (TH2*)GetRawsData(AliMUONQAIndices::kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber, itc);
891
892             if(histoStrips->GetEntries()==0) continue; // No events found => No need to display
893
894             histoDisplayStrips = (TH2*)GetRawsData(AliMUONQAIndices::kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, itc);
895
896             triggerDisplay.FillDisplayHistogram(histoStrips, histoDisplayStrips,
897                                                 AliMUONTriggerDisplay::kDisplayStrips, iCath, iChamber, displayOption);
898
899             Float_t scaleValue = ((TH1*)GetRawsData(AliMUONQAIndices::kTriggerScalersTime, itc))->GetBinContent(1);
900             if(scaleValue>0.) histoDisplayStrips->Scale(1./scaleValue);
901           } // iChamber
902       } // iCath
903   }
904   
905   if ( GetRawsData(AliMUONQAIndices::kTriggeredBoards, itc) ){
906     TH1* histoBoards = (TH1*)GetRawsData(AliMUONQAIndices::kTriggeredBoards, itc);
907     TH2* histoDisplayBoards = (TH2*)GetRawsData(AliMUONQAIndices::kTriggerBoardsDisplay, itc);
908     triggerDisplay.FillDisplayHistogram(histoBoards, histoDisplayBoards, AliMUONTriggerDisplay::kDisplayBoards, 0, 0);
909     Float_t scaleValue = GetRawsData(AliMUONQAIndices::kTriggerRawNAnalyzedEvents, itc)->GetBinContent(1);
910     if(scaleValue>0.) histoDisplayBoards->Scale(1./scaleValue);
911   }
912 }
913
914
915 //_____________________________________________________________________________
916 Bool_t 
917 AliMUONTriggerQADataMakerRec::FillTriggerDCSHistos()
918 {
919   /// Get HV and currents values for one trigger chamber
920   // RS: Note: the histos involved in this routin are forbidden to be cloned, -1 in GetRawsData returns the default histos
921   int itc = -1;
922   //
923   AliCodeTimerAuto("",0);
924   
925   TMap* triggerDcsMap = CalibrationData()->TriggerDCS();
926
927   if ( !triggerDcsMap ) 
928   {
929     AliError("Cannot fill DCS histos, as triggerDcsMap is NULL");
930     return kFALSE;
931   }
932
933   const Double_t kMaxDelay = 3.;
934   const Double_t kMaxVariation = 25.; // Volts
935   const Int_t kDefaultNpoints = 200;
936   Double_t scaleFactor = 1./1000.;
937
938   Bool_t error = kFALSE;
939   Bool_t expert   = kTRUE;
940   Bool_t image    = kTRUE;
941
942   AliMpDEIterator deIt;
943   
944   AliMpDCSNamer triggerDcsNamer("TRIGGER");
945
946   TH2F* currHisto = 0x0;
947   Int_t histoIndex = 0;
948   TString histoName, histoTitle;
949
950   TArrayD axisSlat(18+1);
951   for(Int_t islat=0; islat<=18; islat++){
952     axisSlat[islat] = -0.5 + (Float_t)islat;
953   }
954
955   TArrayD axisTimeAux[4], axisTime[4], axisTimeDE(kDefaultNpoints);
956   TArrayI index[4], npoints(4);
957
958   // Build axis of times
959   npoints.Reset();
960   for(Int_t ich=0; ich<4; ich++){
961     axisTimeAux[ich].Set(kDefaultNpoints);
962     axisTimeAux[ich].Reset(-1.);
963   }
964
965   deIt.First();
966   while ( !deIt.IsDone() )
967   {
968     Int_t detElemId = deIt.CurrentDEId();
969     TObjArray* values = GetDCSValues(AliMpDCSNamer::kDCSHV, detElemId, triggerDcsMap, triggerDcsNamer);
970
971     if ( values ) {
972
973       AliDebug(AliQAv1::GetQADebugLevel(), Form("DetElemId %i", detElemId));
974
975       axisTimeDE.Reset(-1.);
976
977       TIter next(values);
978       AliDCSValue* val = 0x0;
979       Double_t previousVal = -999.;
980       Int_t npointsde = 0;
981       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
982       {
983         if ( npointsde + 1 > kDefaultNpoints ) {
984           axisTimeDE.Set(npointsde + 1);
985         }
986
987         Double_t currVal = val->GetFloat();
988         Double_t currTime = (Double_t)val->GetTimeStamp();
989         if (npointsde > 0 ){
990           if ( TMath::Abs( currVal - previousVal ) < kMaxVariation && 
991                TMath::Abs( currTime - axisTimeDE[npointsde-1] ) < 40 ) continue;
992         }
993
994         axisTimeDE[npointsde] = currTime;
995         previousVal = currVal;
996         npointsde++;
997       } // loop on values
998
999       //      AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding DE point %2i  (%2i)  %.2f  (%i)\n", previousBin, npointsde, axisTimeDE[previousBin], nTimesPerBin));
1000
1001       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
1002       Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
1003
1004       for(Int_t ipde=0; ipde<npointsde; ipde++){
1005
1006         if ( npoints[ich] + 1 > kDefaultNpoints ) {
1007           axisTimeAux[ich].Set(npoints[ich] + 1);
1008         }
1009
1010         for(Int_t ipoint = 0; ipoint < axisTimeAux[ich].GetSize(); ipoint++){
1011           if (axisTimeAux[ich][ipoint] < 0.) {
1012             axisTimeAux[ich][ipoint] = axisTimeDE[ipde];
1013             npoints[ich]++;
1014             AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding point %2i  %.0f\n", ipoint, axisTimeAux[ich][ipoint]));
1015             break;
1016           }
1017           if ( TMath::Abs( axisTimeDE[ipde] - axisTimeAux[ich][ipoint]) < kMaxDelay ) {
1018             axisTimeAux[ich][ipoint] = TMath::Min(axisTimeAux[ich][ipoint], axisTimeDE[ipde]);
1019             break;
1020           }
1021         } // loop on points
1022       } // loop on reorganized values
1023
1024     } // if ( values ) 
1025     deIt.Next();
1026   } // loop on DetElemId
1027
1028   for(Int_t ich=0; ich<4; ich++){
1029     axisTimeAux[ich].Set(npoints[ich]);
1030     index[ich].Set(npoints[ich]);
1031     TMath::Sort(npoints[ich], axisTimeAux[ich].GetArray(), index[ich].GetArray(), kFALSE);
1032
1033     axisTime[ich].Set(npoints[ich]+1);
1034     for(Int_t ipoint = 0; ipoint < axisTimeAux[ich].GetSize(); ipoint++){
1035       axisTime[ich][ipoint] = axisTimeAux[ich][index[ich][ipoint]];
1036     }
1037     Double_t minStartEndWidth = 0.1 * (axisTime[ich][npoints[ich]-1] - axisTime[ich][0]);
1038     axisTime[ich][npoints[ich]] = axisTime[ich][npoints[ich]-1] + minStartEndWidth;
1039     if ( npoints[ich] >= 1)
1040       if ( axisTime[ich][1] - axisTime[ich][0] < minStartEndWidth )
1041         axisTime[ich][0] = axisTime[ich][1] - minStartEndWidth;
1042   }
1043
1044
1045   // Loop again on detection elements: create and fill histos
1046   deIt.First();
1047   while ( !deIt.IsDone() )
1048   {
1049     Int_t detElemId = deIt.CurrentDEId();
1050     TObjArray* values = GetDCSValues(AliMpDCSNamer::kDCSHV, detElemId, triggerDcsMap, triggerDcsNamer);
1051
1052     if ( values ) {
1053       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
1054       Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
1055
1056       histoIndex = AliMUONQAIndices::kTriggerRPChv + ich;
1057       histoName = Form("hTriggerRPCHVChamber%i", 11+ich);
1058       histoTitle = Form("Chamber %i: RPC HV (kV)", 11+ich);
1059
1060       currHisto = (TH2F*)GetRecPointsData(histoIndex,itc); // RS this histo is not cloned
1061
1062       if(!currHisto){
1063         currHisto  = new TH2F(histoName.Data(), histoTitle.Data(),
1064                               npoints[ich], axisTime[ich].GetArray(),
1065                               18, axisSlat.GetArray());
1066         currHisto->GetXaxis()->SetTitle("Time");
1067         currHisto->GetXaxis()->SetTimeDisplay(1);
1068         //currHisto->GetXaxis()->SetTimeFormat("%d%b%y %H:%M:%S");
1069         currHisto->GetXaxis()->SetLabelSize(0.03);
1070         currHisto->GetYaxis()->SetTitle("RPC");
1071         currHisto->SetOption("TEXT45COLZ");
1072         Add2RecPointsList(currHisto, histoIndex, expert, !image);
1073         ForbidCloning(currHisto); // RS
1074       }
1075
1076       Int_t slat = detElemId%100;
1077       Int_t slatBin = currHisto->GetYaxis()->FindBin(slat);
1078
1079       TIter next(values);
1080       AliDCSValue* val = 0x0;
1081       Double_t sumValuesPerBin = 0.;
1082       Int_t nValuesPerBin = 0;
1083       Int_t previousBin = -1;
1084       Double_t previousTime = -1., previousVal = -999., sumVal = 0., sumTime = 0.;
1085       Bool_t isTrip = kFALSE;
1086       Int_t nPointsForSlope = 0;
1087       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
1088       {
1089         Double_t currTime = (Double_t)val->GetTimeStamp();
1090         Int_t currentBin = currHisto->GetXaxis()->FindBin(currTime+0.5);
1091         Double_t currVal = val->GetFloat();
1092         Double_t deltaVal = currVal - previousVal;
1093         Bool_t isRepeated = kFALSE;
1094         if ( previousTime > 0 ){
1095           isRepeated = ( TMath::Abs( currVal - previousVal ) < kMaxVariation && 
1096                          TMath::Abs( currTime - previousTime ) < 40 );
1097
1098           // Check for trips
1099           sumTime += currTime - previousTime;
1100           sumVal += deltaVal;
1101           nPointsForSlope++;
1102
1103           if ( sumTime > 0. && nPointsForSlope >= 3 ){
1104             Double_t slope = sumVal / sumTime;
1105             if ( slope < -10. ) // going down of more than 10V/s
1106               isTrip = kTRUE;
1107           }
1108
1109           if ( deltaVal * sumVal < 0. ) {
1110             sumTime = 0.;
1111             sumVal = 0.;
1112             nPointsForSlope = 0;
1113           }
1114         }
1115
1116         if ( ! isRepeated ) {
1117           if ( currentBin != previousBin ) {
1118             if ( previousBin >= 0 ) {
1119               currHisto->SetBinContent(previousBin, slatBin, scaleFactor*sumValuesPerBin/((Double_t)nValuesPerBin));
1120               sumValuesPerBin = 0.;
1121               nValuesPerBin = 0;
1122             }
1123             previousBin = currentBin;
1124           }
1125         }
1126           
1127         sumValuesPerBin += currVal;
1128         nValuesPerBin++;
1129         previousTime = currTime;
1130         previousVal = currVal;
1131       } // loop on values
1132       currHisto->SetBinContent(previousBin, slatBin, scaleFactor*sumValuesPerBin/((Double_t)nValuesPerBin)); // Fill last value
1133       if ( isTrip ) ((TH1*)GetRecPointsData(AliMUONQAIndices::kTriggerRPCtrips,itc))->Fill(detElemId);
1134     } // if ( values ) 
1135     deIt.Next();
1136   } // loop on detElem
1137   return error;
1138 }
1139
1140
1141 //____________________________________________________________________________ 
1142 TObjArray* 
1143 AliMUONTriggerQADataMakerRec::GetDCSValues(Int_t iMeas, Int_t detElemId,
1144                                            TMap* triggerDcsMap, AliMpDCSNamer& triggerDcsNamer)
1145 {
1146   //
1147   /// Get values of DCS data points from the map
1148   //
1149
1150   if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger) return 0x0;
1151
1152   TString currAlias = triggerDcsNamer.DCSChannelName(detElemId, 0, iMeas);
1153
1154   TPair* triggerDcsPair = static_cast<TPair*>(triggerDcsMap->FindObject(currAlias.Data()));
1155
1156   if (!triggerDcsPair)
1157   {
1158     AliError(Form("Did not find expected alias (%s) for DE %d\n",
1159                   currAlias.Data(),detElemId));
1160     return 0x0;
1161   }
1162
1163   TObjArray* values = static_cast<TObjArray*>(triggerDcsPair->Value());
1164   if (!values)
1165   {
1166     AliError(Form("Could not get values for alias %s\n",currAlias.Data()));
1167     return 0x0;
1168   }
1169
1170   return values;
1171 }
1172
1173
1174 //____________________________________________________________________________ 
1175 UChar_t AliMUONTriggerQADataMakerRec::RawTriggerInGlobal2OutGlobal(UInt_t globalInput[4])
1176 {
1177   //
1178   /// Reconstruct Global Trigger decision using Global Inputs
1179   //
1180
1181     AliCodeTimerAuto("",0);
1182
1183     AliMUONGlobalCrateConfig* globalConfig = CalibrationData()->GlobalTriggerCrateConfig();
1184
1185     AliMUONGlobalTriggerBoard globalTriggerBoard;
1186     globalTriggerBoard.Reset();
1187     for (Int_t i = 0; i < 4; i++) {
1188         globalTriggerBoard.Mask(i,globalConfig->GetGlobalMask(i));
1189     }
1190
1191     globalTriggerBoard.RecomputeRegional(globalInput);
1192     globalTriggerBoard.Response();
1193     return globalTriggerBoard.GetResponse();
1194
1195 }
1196
1197 //____________________________________________________________________________ 
1198 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutLocal(const AliMUONVTriggerStore& inputTriggerStore,
1199                                                            const AliMUONVTriggerStore& recoTriggerStore)
1200 {
1201   //
1202   /// Match data and reconstructed Local Trigger decision
1203
1204   AliCodeTimerAuto("",0);
1205
1206   Bool_t skipBoard[234];
1207   memset(skipBoard,0,AliMUONConstants::NTriggerCircuit()*sizeof(Bool_t));
1208
1209   Bool_t errorInYCopy = kFALSE;
1210
1211   // First search for YCopy errors.
1212   Int_t loCircuit = -1;
1213   TIter next(recoTriggerStore.CreateLocalIterator());
1214   AliMUONLocalTrigger* recoLocalTrigger, *inputLocalTrigger;
1215   while ( ( recoLocalTrigger = static_cast<AliMUONLocalTrigger*>(next()) ) )
1216   {  
1217     loCircuit = recoLocalTrigger->LoCircuit();
1218     Int_t iboard = loCircuit - 1;
1219
1220     FillRawsData(AliMUONQAIndices::kTriggerErrorLocalYCopyTest,loCircuit);
1221   
1222     inputLocalTrigger = inputTriggerStore.FindLocal(loCircuit);
1223
1224     Int_t recoTrigPattern[4]  = {recoLocalTrigger->GetY1Pattern(), recoLocalTrigger->GetY2Pattern(), recoLocalTrigger->GetY3Pattern(), recoLocalTrigger->GetY4Pattern()};
1225     Int_t inputTrigPattern[4] = {inputLocalTrigger->GetY1Pattern(), inputLocalTrigger->GetY2Pattern(), inputLocalTrigger->GetY3Pattern(), inputLocalTrigger->GetY4Pattern()};
1226
1227     AliMpLocalBoard* localBoardMp = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit); // get local board object for switch value
1228
1229     Bool_t errorInCopyBoard = kFALSE;
1230     for(Int_t ich=0; ich<4; ich++){
1231       if ( recoTrigPattern[ich] != inputTrigPattern[ich] ){
1232         skipBoard[iboard] = kTRUE;
1233         if ( ich >=2 ){
1234           if ( localBoardMp->GetSwitch(AliMpLocalBoard::kOR0) )
1235             skipBoard[iboard+1] = kTRUE;
1236           if ( localBoardMp->GetSwitch(AliMpLocalBoard::kOR1) )
1237             skipBoard[iboard-1] = kTRUE;
1238         }
1239         errorInCopyBoard = kTRUE;
1240         errorInYCopy = kTRUE;
1241       }
1242     } // loop on chambers
1243     if ( errorInCopyBoard )
1244       FillRawsData(AliMUONQAIndices::kTriggerErrorLocalYCopy,loCircuit);    
1245   } // loop on local boards
1246
1247   if (errorInYCopy)
1248     FillRawsData(AliMUONQAIndices::kTriggerErrorSummary,AliMUONQAIndices::kAlgoLocalYCopy);
1249   
1250   Bool_t errorInXPosDev = kFALSE;
1251   Bool_t errorInYPosTrigY = kFALSE;
1252   Bool_t errorInLUT = kFALSE;
1253
1254   next.Reset();
1255   Bool_t respBendPlane, respNonBendPlane;
1256   while ( ( recoLocalTrigger = static_cast<AliMUONLocalTrigger*>(next()) ) )
1257   {  
1258     loCircuit = recoLocalTrigger->LoCircuit();
1259     Int_t iboard = loCircuit - 1;
1260   
1261     // Fill ratio 44/34 histos (if not scaler event)
1262     if ( GetRecoParam()->GetEventSpecie() != AliRecoParam::kCalib ) {
1263       Bool_t is34 = ( recoLocalTrigger->GetLoDecision() != 0 );
1264       Bool_t is44 = TriggerElectronics()->ModifiedLocalResponse(loCircuit, respBendPlane, respNonBendPlane, kTRUE);
1265       if ( is34 ) FillRawsData(AliMUONQAIndices::kTriggerNumberOf34Dec,loCircuit);
1266       if ( is44 ) FillRawsData(AliMUONQAIndices::kTriggerNumberOf44Dec,loCircuit);
1267
1268       if ( is44 && ! is34 )
1269         AliWarning("Event satisfies the 4/4 conditions but not the 3/4");
1270     }
1271     
1272     inputLocalTrigger = inputTriggerStore.FindLocal(loCircuit);
1273
1274     if ( recoLocalTrigger->LoStripX() != inputLocalTrigger->LoStripX() ) {
1275       FillRawsData(AliMUONQAIndices::kTriggerErrorLocalXPos,loCircuit);
1276       errorInXPosDev = kTRUE;
1277     }
1278     
1279     if ( recoLocalTrigger->GetDeviation() != inputLocalTrigger->GetDeviation() ) {
1280       FillRawsData(AliMUONQAIndices::kTriggerErrorLocalDev,loCircuit);
1281       errorInXPosDev = kTRUE;
1282     }
1283
1284     // Skip following checks in case we previously found YCopy error and YPos or trigY errors
1285     if ( (!skipBoard[iboard]) || ( (recoLocalTrigger->LoStripY() == inputLocalTrigger->LoStripY()) && (recoLocalTrigger->LoTrigY() == inputLocalTrigger->LoTrigY())) ) {
1286         
1287         if ( recoLocalTrigger->GetLoDecision() != inputLocalTrigger->GetLoDecision() ) {
1288           FillRawsData(AliMUONQAIndices::kTriggerErrorLocalTriggerDec,loCircuit);
1289         }
1290         
1291         // Test Hpt and LPT
1292         Int_t recoLut[2]  = { recoLocalTrigger->LoLpt(),  recoLocalTrigger->LoHpt() };
1293         Int_t inputLut[2] = {inputLocalTrigger->LoLpt(), inputLocalTrigger->LoHpt() };
1294         Int_t currIndex[2][2] = {{AliMUONQAIndices::kTriggerErrorLocalLPtLSB, AliMUONQAIndices::kTriggerErrorLocalLPtMSB},
1295                                  {AliMUONQAIndices::kTriggerErrorLocalHPtMSB, AliMUONQAIndices::kTriggerErrorLocalHPtMSB}};
1296         for (Int_t ilut=0; ilut<2; ilut++){
1297             Int_t bitDiff = recoLut[ilut]^inputLut[ilut];
1298             if ( bitDiff == 0 ) continue;
1299             for (Int_t ibit=0; ibit<2; ibit++){
1300                 Bool_t isBitDifferent = (bitDiff>>ibit)&1;
1301                 if ( isBitDifferent ){
1302                   FillRawsData(currIndex[ilut][ibit],loCircuit);
1303                   errorInLUT = kTRUE;
1304                 }
1305             }
1306         }
1307     }
1308     
1309  
1310     // Skip following checks in case we previously found YCopy errors
1311     if ( skipBoard[iboard] ) continue;
1312
1313     if ( recoLocalTrigger->LoStripY() != inputLocalTrigger->LoStripY() ) {
1314       FillRawsData(AliMUONQAIndices::kTriggerErrorLocalYPos,loCircuit);
1315       errorInYPosTrigY = kTRUE;
1316     }
1317
1318     if ( recoLocalTrigger->LoTrigY() != inputLocalTrigger->LoTrigY()  ) {
1319       FillRawsData(AliMUONQAIndices::kTriggerErrorLocalTrigY,loCircuit);        
1320       errorInYPosTrigY = kTRUE;
1321     }
1322   } // loop on local boards
1323   
1324   if (errorInXPosDev)
1325     FillRawsData(AliMUONQAIndices::kTriggerErrorSummary,AliMUONQAIndices::kAlgoLocalX);
1326
1327   if (errorInLUT)
1328     FillRawsData(AliMUONQAIndices::kTriggerErrorSummary,AliMUONQAIndices::kAlgoLocalLUT);
1329
1330   if (errorInYPosTrigY)
1331     FillRawsData(AliMUONQAIndices::kTriggerErrorSummary,AliMUONQAIndices::kAlgoLocalY);
1332
1333 }
1334 /*
1335 //____________________________________________________________________________ 
1336 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutLocalInRegional()
1337 {
1338   //
1339   /// Match Local outputs and Regional inputs
1340   /// Not tested, hardware read-out doesn't work
1341   //
1342
1343     for (int localId=1;localId<235;localId++){
1344         if(fTriggerOutputLocalDataLPtDec[0][localId]!=fTriggerInputRegionalDataLPt[0][localId]){
1345             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalLPtLSB))->Fill(localId);
1346         }
1347         if(fTriggerOutputLocalDataLPtDec[1][localId]!=fTriggerInputRegionalDataLPt[1][localId]){
1348             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalLPtMSB))->Fill(localId);
1349         }
1350         if(fTriggerOutputLocalDataHPtDec[0][localId]!=fTriggerInputRegionalDataHPt[0][localId]){
1351             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalHPtLSB))->Fill(localId);
1352         }
1353         if(fTriggerOutputLocalDataHPtDec[1][localId]!=fTriggerInputRegionalDataHPt[1][localId]){
1354             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalHPtMSB))->Fill(localId);
1355         }
1356     }
1357 }
1358 */
1359
1360
1361 //____________________________________________________________________________ 
1362 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutGlobal(AliMUONGlobalTrigger& inputGlobalTrigger, 
1363                                                                         AliMUONGlobalTrigger& recoGlobalTrigger, 
1364                                                                         Char_t histo)
1365 {
1366   //
1367   /// Match data and reconstructed Global Trigger decision for a reconstruction from Global inputs.
1368   /// histo='G': fill FromGlobalInput histo='L': fill from Local input;
1369   //
1370
1371   if ( recoGlobalTrigger.GetGlobalResponse() == inputGlobalTrigger.GetGlobalResponse() )
1372     return;
1373   Int_t histoToFill;
1374   Int_t binToFill;
1375   
1376   if (histo=='G'){
1377       histoToFill=AliMUONQAIndices::kTriggerErrorOutGlobalFromInGlobal;
1378       binToFill=AliMUONQAIndices::kAlgoGlobalFromGlobal;
1379   }else{
1380       if (histo=='L'){
1381           histoToFill=AliMUONQAIndices::kTriggerErrorOutGlobalFromInLocal;
1382           binToFill=AliMUONQAIndices::kAlgoGlobalFromLocal;
1383       }else{
1384           AliWarning(Form("Global histos not filled, 3rd argument must be 'G' or 'L'"));
1385           return;
1386       } 
1387   }
1388
1389   FillRawsData(AliMUONQAIndices::kTriggerErrorSummary,binToFill);
1390   
1391   Int_t inputResp[6] = {inputGlobalTrigger.PairUnlikeHpt(), inputGlobalTrigger.PairUnlikeLpt(),
1392                         inputGlobalTrigger.PairLikeHpt(), inputGlobalTrigger.PairLikeLpt(),
1393                         inputGlobalTrigger.SingleHpt(), inputGlobalTrigger.SingleLpt()};
1394   
1395   Int_t recoResp[6] = {recoGlobalTrigger.PairUnlikeHpt(), recoGlobalTrigger.PairUnlikeLpt(),
1396                        recoGlobalTrigger.PairLikeHpt(), recoGlobalTrigger.PairLikeLpt(),
1397                        recoGlobalTrigger.SingleHpt(), recoGlobalTrigger.SingleLpt()};
1398   
1399   for (int bit=0;bit<6;bit++){
1400     if ( recoResp[bit] != inputResp[bit] )
1401       FillRawsData(histoToFill,bit);
1402   }
1403 }
1404
1405 //____________________________________________________________________________ 
1406 void AliMUONTriggerQADataMakerRec::FillRatio4434Histos(Int_t evtInterval, Int_t itc, Bool_t isEndOfCycle)
1407 {
1408   /// Fill ratio 44/34 histos
1409   TH1* histoEvents = ( isEndOfCycle ) ? GetRawsData(AliMUONQAIndices::kTriggerRawNAnalyzedEvents,itc) : GetMatchingRawsHisto(AliMUONQAIndices::kTriggerRawNAnalyzedEvents,itc);
1410   if ( ! histoEvents ) return;
1411   Int_t numEvent = Int_t(histoEvents->GetBinContent(1));
1412
1413   // Fill every fgkUpdateRatio4434 events
1414   if (numEvent % evtInterval != 0)
1415     return;
1416   
1417   TH1* histo44dec = ( isEndOfCycle ) ? GetRawsData(AliMUONQAIndices::kTriggerNumberOf44Dec,itc) : GetMatchingRawsHisto(AliMUONQAIndices::kTriggerNumberOf44Dec,itc);
1418   TH1* histo34dec = ( isEndOfCycle ) ? GetRawsData(AliMUONQAIndices::kTriggerNumberOf34Dec,itc) : GetMatchingRawsHisto(AliMUONQAIndices::kTriggerNumberOf34Dec,itc);
1419   
1420   Float_t totalNumberOf44 = histo44dec->GetSumOfWeights();
1421   Float_t totalNumberOf34 = histo34dec->GetSumOfWeights();
1422
1423   if ( totalNumberOf34 == 0 )
1424     return;
1425
1426   TH1* histoAllEvents = ( isEndOfCycle ) ? GetRawsData(AliMUONQAIndices::kTriggerRatio4434AllEvents,itc) : GetMatchingRawsHisto(AliMUONQAIndices::kTriggerRatio4434AllEvents,itc);
1427   
1428   if ( ! histoAllEvents ) return;
1429   Int_t nbins =  histoAllEvents->GetNbinsX();
1430   Float_t maxBin = histoAllEvents->GetXaxis()->GetBinLowEdge(nbins+1);
1431
1432   if ( numEvent - maxBin < 1) return;
1433
1434   // Use the underflow and overflow to store the number of 34 and 44
1435   // in previous event
1436   Float_t previousNumOf34 = histoAllEvents->GetBinContent(0);
1437   Float_t previousNumOf44 = histoAllEvents->GetBinContent(nbins+1);
1438
1439   Float_t numOf34Update = totalNumberOf34 - previousNumOf34;
1440   Float_t numOf44Update = totalNumberOf44 - previousNumOf44;
1441
1442   // Not enough new tracks since last update
1443   //if ( numOf34Update == 0 && numOf44Update == 0 )
1444   if ( numOf34Update < evtInterval - 1 )
1445     return;
1446
1447   Int_t newNbins = ( (Int_t)maxBin % fgkUpdateRatio4434 ) ? nbins : nbins+1;
1448   TString cloneName;
1449   
1450   TH1* histoRatioSinceLastUpdate = ( isEndOfCycle ) ? GetRawsData(AliMUONQAIndices::kTriggerRatio4434SinceLastUpdate,itc) : GetMatchingRawsHisto(AliMUONQAIndices::kTriggerRatio4434SinceLastUpdate,itc);
1451
1452   TH1* histos[2] = {histoAllEvents, histoRatioSinceLastUpdate};
1453   
1454   for (Int_t ihisto=0; ihisto<2; ihisto++){
1455     TH1* currHisto = histos[ihisto];
1456     cloneName = Form("%sClone", currHisto->GetName());
1457     TArrayD newAxis(newNbins+1);
1458     for (Int_t ibin=0; ibin<newNbins; ibin++){
1459       newAxis[ibin] = currHisto->GetXaxis()->GetBinLowEdge(ibin+1);
1460     }
1461     newAxis[newNbins] = numEvent;
1462     TH1F* copyHisto = (TH1F*)currHisto->Clone(cloneName.Data());
1463     //currHisto->SetBins(newNbins, 0., fgkUpdateRatio4434*newNbins);
1464     currHisto->SetBins(newNbins, newAxis.GetArray());
1465     for (Int_t ibin=1; ibin<newNbins; ibin++){
1466       currHisto->SetBinContent(ibin, copyHisto->GetBinContent(ibin));
1467       currHisto->SetBinError(ibin, copyHisto->GetBinError(ibin));
1468     }
1469     delete copyHisto;
1470   }
1471
1472   Float_t ratio4434 = totalNumberOf44/totalNumberOf34;
1473   Float_t errorRatio4434 = ProtectedSqrt(totalNumberOf44*(1-ratio4434))/totalNumberOf34;
1474     
1475   histoAllEvents->SetBinContent(newNbins,ratio4434);
1476   histoAllEvents->SetBinError(newNbins,errorRatio4434);
1477
1478   Float_t ratio4434Update = 0.;
1479   Float_t errorRatio4434Update = 0.;
1480
1481   if(numOf34Update!=0){
1482     ratio4434Update = numOf44Update/numOf34Update;
1483     if ( numOf44Update > numOf34Update ){
1484       AliWarning(Form("Number of 4/4 (%f) is higher than number of 3/4 (%f)", numOf44Update, numOf34Update));
1485     }
1486     errorRatio4434Update = ProtectedSqrt(numOf44Update*(1-ratio4434Update))/numOf34Update;
1487   }
1488
1489   histoRatioSinceLastUpdate->SetBinContent(newNbins,ratio4434Update);
1490   histoRatioSinceLastUpdate->SetBinError(newNbins,errorRatio4434Update);
1491
1492   histoAllEvents->SetBinContent(0,totalNumberOf34);
1493   histoAllEvents->SetBinContent(newNbins+1,totalNumberOf44);
1494
1495 }
1496
1497
1498 //____________________________________________________________________________ 
1499 AliMUONTriggerElectronics* AliMUONTriggerQADataMakerRec::TriggerElectronics()
1500 {
1501   /// Return trigger electronics
1502   /// (create it if necessary)
1503   if ( ! fTriggerProcessor ) 
1504     fTriggerProcessor = new AliMUONTriggerElectronics(CalibrationData());
1505   return fTriggerProcessor;
1506 }
1507
1508
1509 //____________________________________________________________________________ 
1510 AliMUONCalibrationData* AliMUONTriggerQADataMakerRec::CalibrationData()
1511 {
1512   /// Return calibration data
1513   /// (create it if necessary)
1514   if ( ! fCalibrationData ) fCalibrationData = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1515   return fCalibrationData;
1516 }
1517
1518 //____________________________________________________________________________ 
1519 void AliMUONTriggerQADataMakerRec::ResetDetectorRaws(TObjArray*/* list*/)
1520 {
1521   /// Reset the calibration data
1522   delete fTriggerProcessor;
1523   fTriggerProcessor = 0x0;
1524   delete fCalibrationData;
1525   fCalibrationData = 0x0;
1526 }