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