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