]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerQADataMakerRec.cxx
Corrected comments for Doxygen
[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 "TString.h"
38 #include "AliRecoParam.h"
39 #include "AliMUONDigitStoreV2R.h"
40 #include "AliMUONTriggerStoreV1.h"
41 #include "AliMpCDB.h"
42 #include "AliMUONRawStreamTriggerHP.h"
43 #include "AliMpDDLStore.h"
44 #include "AliMpTriggerCrate.h"
45 #include "AliMpLocalBoard.h"
46 #include "AliQAv1.h"
47 #include "AliRawReader.h"
48 #include "AliMUONDigitMaker.h"
49 #include "AliMUONLocalTrigger.h"
50 #include "AliMUONRecoParam.h"
51 #include "AliMUONTriggerElectronics.h"
52 #include "AliMUONCalibrationData.h"
53 #include "AliDCSValue.h"
54 #include "AliMpDCSNamer.h"
55 #include "AliMpDEManager.h"
56 #include "AliMpDEIterator.h"
57 #include "AliCDBManager.h"
58 #include "TTree.h"
59 #include "AliMUONGlobalTriggerBoard.h"
60 #include "AliMUONGlobalTrigger.h"
61 #include "AliMUONGlobalCrateConfig.h"
62
63 //____________________________________________________________________________ 
64 AliMUONTriggerQADataMakerRec::AliMUONTriggerQADataMakerRec(AliQADataMakerRec* master) : 
65 AliMUONVQADataMakerRec(master),
66 fDigitMaker(new AliMUONDigitMaker(kFALSE)),
67 fCalibrationData(new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun())),
68 fTriggerProcessor(new AliMUONTriggerElectronics(fCalibrationData)),
69 fDigitStore(0x0)
70 {
71     /// ctor
72 }
73
74
75 //__________________________________________________________________
76 AliMUONTriggerQADataMakerRec::~AliMUONTriggerQADataMakerRec()
77 {
78     /// dtor
79   delete fDigitMaker;
80   delete fDigitStore;
81   delete fTriggerProcessor;
82   delete fCalibrationData;
83 }
84
85 //____________________________________________________________________________ 
86 void AliMUONTriggerQADataMakerRec::EndOfDetectorCycleESDs(Int_t /*specie*/, TObjArray** /*list*/)
87 {
88   /// Normalize ESD histograms
89 }
90   
91 //____________________________________________________________________________ 
92 void AliMUONTriggerQADataMakerRec::EndOfDetectorCycleRecPoints(Int_t /*specie*/, TObjArray** /*list*/)
93 {
94   /// Normalize RecPoints histograms
95   
96 }
97
98
99 //____________________________________________________________________________ 
100 void AliMUONTriggerQADataMakerRec::EndOfDetectorCycleRaws(Int_t /*specie*/, TObjArray** /*list*/)
101 {
102   /// create Raws histograms in Raws subdir
103
104   DisplayTriggerInfo();
105
106   // Normalize RawData histos
107   Float_t nbevent = GetRawsData(kRawNAnalyzedEvents)->GetBinContent(1);
108   Int_t histoRawsIndex[] = {
109     kTriggerErrorSummary,
110     kTriggerCalibSummary,
111     kTriggerReadOutErrors,
112     kTriggerGlobalOutput
113   };
114   Int_t histoRawsScaledIndex[] = {
115     kTriggerErrorSummaryNorm,
116     kTriggerCalibSummaryNorm,
117     kTriggerReadOutErrorsNorm,
118     kTriggerGlobalOutputNorm
119   };
120   const Int_t kNrawsHistos = sizeof(histoRawsIndex)/sizeof(histoRawsIndex[0]);
121   Float_t scaleFactor[kNrawsHistos] = {100., 100., 100., 1.};
122   for(Int_t ihisto=0; ihisto<kNrawsHistos; ihisto++){
123     TH1* inputHisto = GetRawsData(histoRawsIndex[ihisto]);
124     TH1* scaledHisto = GetRawsData(histoRawsScaledIndex[ihisto]);
125     if ( scaledHisto && inputHisto &&  nbevent > 0 ) {
126       scaledHisto->Reset();
127       scaledHisto->Add(inputHisto);
128       scaledHisto->Scale(scaleFactor[ihisto]/nbevent);
129     }
130   } // loop on histos
131
132   TH1* hYCopy = GetRawsData(kTriggerErrorLocalYCopy); //number of YCopy error per board
133   TH1* hYCopyTests = GetRawsData(kTriggerErrorLocalYCopyTest); //contains the number of YCopy test per board
134   TH1* hYCopyNorm = GetRawsData(kTriggerErrorLocalYCopyNorm); 
135   hYCopyNorm->Reset();
136   hYCopyNorm->Divide(hYCopy, hYCopyTests, 100., 1.);
137      
138   Float_t mean = hYCopyNorm->Integral();
139       
140   TH1* hSummary = GetRawsData(kTriggerErrorSummary);
141   hSummary->SetBinContent(kAlgoLocalYCopy+1,mean/192.); //put the mean of the % of YCopy error in the kTriggerError's corresponding bin
142 }
143
144 //____________________________________________________________________________ 
145 void AliMUONTriggerQADataMakerRec::InitRaws()
146 {
147     /// create Raws histograms in Raws subdir
148         
149   AliCodeTimerAuto("",0);
150   
151   const Bool_t expert   = kTRUE ; 
152   const Bool_t saveCorr = kTRUE ; 
153   const Bool_t image    = kTRUE ; 
154  
155   TString boardName = "Local board Id";
156
157   Int_t nbLocalBoard = AliMUONConstants::NTriggerCircuit();
158
159   TH1F* histo1D = 0x0;
160   TH2F* histo2D = 0x0;
161
162   AliMUONTriggerDisplay triggerDisplay;
163
164   TString histoName, histoTitle;
165   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) {
166     histo1D = new TH1F("hTriggerScalersTime", "Acquisition time from trigger scalers", 1, 0.5, 1.5);
167     histo1D->GetXaxis()->SetBinLabel(1, "One-bin histogram: bin is filled at each scaler event.");
168     histo1D->GetYaxis()->SetTitle("Cumulated scaler time (s)");
169     Add2RawsList(histo1D, kTriggerScalersTime, expert, !image, !saveCorr);
170
171     for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
172       TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
173       for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
174         histoName = Form("hTriggerScalers%sChamber%i", cathName.Data(), 11+iChamber);
175         histoTitle = Form("Chamber %i - %s: trigger scaler counts", 11+iChamber, cathName.Data());
176         histo2D = new TH2F(histoName.Data(), histoTitle.Data(),
177                            nbLocalBoard, 0.5, (Float_t)nbLocalBoard + 0.5,
178                            16, -0.5, 15.5);
179         histo2D->GetXaxis()->SetTitle(boardName.Data());
180         histo2D->GetYaxis()->SetTitle("Strip"); 
181         histo2D->SetOption("COLZ");     
182         Add2RawsList(histo2D, kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber, expert, !image, !saveCorr);
183       } // loop on chambers
184     } // loop on cathodes
185         
186     for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
187       TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
188       for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
189         histoName = Form("hTriggerScalersDisplay%sChamber%i", cathName.Data(), 11+iChamber);
190         histoTitle = Form("Chamber %i - %s: Hit rate from scalers (Hz/cm^{2})", 11+iChamber, cathName.Data());
191         histo2D = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplayStrips, 
192                                                              iCath, iChamber, histoTitle);
193         histo2D->SetOption("COLZ");
194         Add2RawsList(histo2D, kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, expert, !image, !saveCorr);
195       } // loop on chambers
196     } // loop on cathodes    
197
198     TString axisLabel[kNtrigCalibSummaryBins] = {"#splitline{Dead}{Channels}", "#splitline{Dead}{Local Boards}", "#splitline{Dead}{Regional Boards}", "#splitline{Dead}{Global Board}", "#splitline{Noisy}{Strips}"};
199
200     TH1F* histoCalib = new TH1F("hTriggerCalibSummaryAll", "MTR calibration summary counts", kNtrigCalibSummaryBins, -0.5, (Float_t)kNtrigCalibSummaryBins - 0.5);
201     for (Int_t ibin=1; ibin<=kNtrigCalibSummaryBins; ibin++){
202       histoCalib->GetXaxis()->SetBinLabel(ibin, axisLabel[ibin-1].Data());
203     }
204     histoCalib->SetFillColor(kBlue);
205     histoCalib->GetYaxis()->SetTitle("Counts");
206     // Copy of previous histo for scaling purposes
207     TH1F* histoCalibNorm = (TH1F*)histoCalib->Clone("hTriggerCalibSummary");
208     histoCalibNorm->SetTitle("MTR calibration summary");
209     histoCalibNorm->SetOption("bar2");
210     histoCalibNorm->GetYaxis()->SetTitle("Percentage per event (%)");
211     // Adding both histos after cloning to avoid problems with the expert bit
212     Add2RawsList(histoCalib,     kTriggerCalibSummary,      expert, !image, !saveCorr);
213     Add2RawsList(histoCalibNorm, kTriggerCalibSummaryNorm, !expert,  image, !saveCorr);
214   } // Calibration reco param
215         
216   Char_t *globalXaxisName[6] = {"US HPt", "US LPt", "LS HPt", "LS LPt", "SGL HPt", "SGL LPt"};
217   Char_t *allLevelXaxisName[kNtrigAlgoErrorBins] = {"Local algo X", "Local algo Y", "Local LUT","Local Y Copy" , "Local2Regional", "Regional", "Regional2Global", "GlobalFromInGlobal", "GlobalFromInLocal", "GlobalFromOutLocal"};
218   Char_t *readoutErrNames[kNtrigStructErrorBins]={"Local","Regional","Global","DARC"};
219
220   TString errorAxisTitle = "Number of errors";
221
222   histo1D = new TH1F("ErrorLocalXPos", "ErrorLocalXPos",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
223   histo1D->GetXaxis()->SetTitle(boardName.Data());
224   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
225   Add2RawsList(histo1D, kTriggerErrorLocalXPos, expert, !image, !saveCorr);
226
227   histo1D = new TH1F("ErrorLocalYPos", "ErrorLocalYPos",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
228   histo1D->GetXaxis()->SetTitle(boardName.Data());
229   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
230   Add2RawsList(histo1D, kTriggerErrorLocalYPos, expert, !image, !saveCorr);
231
232   histo1D = new TH1F("ErrorLocalDev", "ErrorLocalDev",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
233   histo1D->GetXaxis()->SetTitle(boardName.Data());
234   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
235   Add2RawsList(histo1D, kTriggerErrorLocalDev, expert, !image, !saveCorr);
236
237   histo1D = new TH1F("ErrorLocalTriggerDec", "ErrorLocalTriggerDec",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
238   histo1D->GetXaxis()->SetTitle(boardName.Data());
239   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
240   Add2RawsList(histo1D, kTriggerErrorLocalTriggerDec, expert, !image, !saveCorr);
241
242   histo1D = new TH1F("ErrorLocalLPtLSB", "ErrorLocalLPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
243   histo1D->GetXaxis()->SetTitle(boardName.Data());
244   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
245   Add2RawsList(histo1D, kTriggerErrorLocalLPtLSB, expert, !image, !saveCorr);
246
247   histo1D = new TH1F("ErrorLocalLPtMSB", "ErrorLocalLPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
248   histo1D->GetXaxis()->SetTitle(boardName.Data());
249   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
250   Add2RawsList(histo1D, kTriggerErrorLocalLPtMSB, expert, !image, !saveCorr);
251
252   histo1D = new TH1F("ErrorLocalHPtLSB", "ErrorLocalHPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
253   histo1D->GetXaxis()->SetTitle(boardName.Data());
254   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
255   Add2RawsList(histo1D, kTriggerErrorLocalHPtLSB, expert, !image, !saveCorr);
256
257   histo1D = new TH1F("ErrorLocalHPtMSB", "ErrorLocalHPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
258   histo1D->GetXaxis()->SetTitle(boardName.Data());
259   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
260   Add2RawsList(histo1D, kTriggerErrorLocalHPtMSB, expert, !image, !saveCorr);
261
262   histo1D = new TH1F("ErrorLocalTrigY", "ErrorLocalTrigY",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
263   histo1D->GetXaxis()->SetTitle(boardName.Data());
264   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
265   Add2RawsList(histo1D, kTriggerErrorLocalTrigY, expert, !image, !saveCorr);
266
267   histo1D = new TH1F("ErrorLocal2RegionalLPtLSB", "ErrorLocal2RegionalLPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
268   histo1D->GetXaxis()->SetTitle(boardName.Data());
269   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
270   Add2RawsList(histo1D, kTriggerErrorLocal2RegionalLPtLSB, expert, !image, !saveCorr);
271
272   histo1D = new TH1F("ErrorLocal2RegionalLPtMSB", "ErrorLocal2RegionalLPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
273   histo1D->GetXaxis()->SetTitle(boardName.Data());
274   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
275   Add2RawsList(histo1D, kTriggerErrorLocal2RegionalLPtMSB, expert, !image, !saveCorr);
276
277   histo1D = new TH1F("ErrorLocal2RegionalHPtLSB", "ErrorLocal2RegionalHPtLSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
278   histo1D->GetXaxis()->SetTitle(boardName.Data());
279   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
280   Add2RawsList(histo1D, kTriggerErrorLocal2RegionalHPtLSB, expert, !image, !saveCorr);
281
282   histo1D = new TH1F("ErrorLocal2RegionalHPtMSB", "ErrorLocal2RegionalHPtMSB",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
283   histo1D->GetXaxis()->SetTitle(boardName.Data());
284   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
285   Add2RawsList(histo1D, kTriggerErrorLocal2RegionalHPtMSB, expert, !image, !saveCorr);
286
287   histo1D = new TH1F("ErrorOutGlobalFromInGlobal", "ErrorOutGlobalFromInGlobal",6,-0.5,6-0.5);
288   histo1D->GetYaxis()->SetTitle(errorAxisTitle.Data());
289   for (int ibin=0;ibin<6;ibin++){
290     histo1D->GetXaxis()->SetBinLabel(ibin+1,globalXaxisName[ibin]);
291   }
292   Add2RawsList(histo1D, kTriggerErrorOutGlobalFromInGlobal, expert, !image, !saveCorr);
293
294   TH1F* histoAlgoErr = new TH1F("hTriggerAlgoNumOfErrors", "Trigger Algorithm total errors",kNtrigAlgoErrorBins,-0.5,(Float_t)kNtrigAlgoErrorBins-0.5);
295   histoAlgoErr->GetYaxis()->SetTitle("Number of events with errors");
296   for (int ibin=0;ibin<kNtrigAlgoErrorBins;ibin++){
297     histoAlgoErr->GetXaxis()->SetBinLabel(ibin+1,allLevelXaxisName[ibin]);
298   }
299   histoAlgoErr->SetFillColor(kBlue);
300   // Copy of previous histo for scaling purposes
301   TH1F* histoAlgoErrNorm = (TH1F*)histoAlgoErr->Clone("hTriggerAlgoErrors");
302   histoAlgoErrNorm->SetOption("bar2");
303   histoAlgoErrNorm->SetTitle("Trigger algorithm errors");
304   histoAlgoErrNorm->GetYaxis()->SetTitle("% of events with errors");
305   // Adding both histos after cloning to avoid problems with the expert bit
306   Add2RawsList(histoAlgoErr,     kTriggerErrorSummary,      expert, !image, !saveCorr);
307   Add2RawsList(histoAlgoErrNorm, kTriggerErrorSummaryNorm, !expert,  image, !saveCorr);  
308
309   histo1D = new TH1F("hTriggeredBoards", "Triggered boards", nbLocalBoard, 0.5, (Float_t)nbLocalBoard + 0.5);
310   Add2RawsList(histo1D, kTriggeredBoards, expert, !image, !saveCorr);
311
312   histo2D = (TH2F*)triggerDisplay.GetEmptyDisplayHisto("hFiredBoardsDisplay", AliMUONTriggerDisplay::kDisplayBoards,
313                                                        0, 0, "Local board triggers / event");
314   histo2D->SetOption("COLZ");
315   Add2RawsList(histo2D, kTriggerBoardsDisplay, expert, !image, !saveCorr);
316
317   TH1F* histoYCopyErr = new TH1F("ErrorLocalYCopy", "Number of YCopy errors",nbLocalBoard,0.5,(Float_t)nbLocalBoard+0.5);
318   histoYCopyErr->GetXaxis()->SetTitle(boardName.Data());
319   histoYCopyErr->GetYaxis()->SetTitle(errorAxisTitle.Data());
320   // Copy of previous histo for scaling purposes
321   TH1F* histoYCopyErrTest = (TH1F*)histoYCopyErr->Clone("ErrorLocalYCopyTest");
322   histoYCopyErrTest->SetTitle("Number of YCopy tested");
323   // Copy of previous histo for scaling purposes
324   TH1F* histoYCopyErrNorm = (TH1F*)histoYCopyErr->Clone("ErrorLocalYCopyNorm");
325   histoYCopyErrNorm->SetTitle("% of YCopy errors");
326   // Adding both histos after cloning to avoid problems with the expert bit
327   Add2RawsList(histoYCopyErr,     kTriggerErrorLocalYCopy,     expert, !image, !saveCorr);
328   Add2RawsList(histoYCopyErrTest, kTriggerErrorLocalYCopyTest, expert, !image, !saveCorr);
329   Add2RawsList(histoYCopyErrNorm, kTriggerErrorLocalYCopyNorm, expert, !image, !saveCorr);
330
331   TH1F* histoROerr = new TH1F("hTriggerReadoutNumOfErrors","Trigger Read-Out total errors", kNtrigStructErrorBins, -0.5, (Float_t)kNtrigStructErrorBins-0.5);
332   histoROerr->GetYaxis()->SetTitle("Fraction of errors");
333   histoROerr->SetFillColor(kBlue);
334   for (int ibin=0;ibin<kNtrigStructErrorBins;ibin++){
335     histoROerr->GetXaxis()->SetBinLabel(ibin+1,readoutErrNames[ibin]);
336   }
337   // Copy of previous histo for scaling purposes
338   TH1F* histoROerrNorm = (TH1F*)histoROerr->Clone("hTriggerReadoutErrors");
339   histoROerrNorm->SetTitle("Trigger Read-Out errors");
340   histoROerrNorm->SetOption("bar2");
341   histoROerrNorm->GetYaxis()->SetTitle("% of errors per event");
342   // Adding both histos after cloning to avoid problems with the expert bit
343   Add2RawsList(histoROerr,     kTriggerReadOutErrors,      expert, !image, !saveCorr);
344   Add2RawsList(histoROerrNorm, kTriggerReadOutErrorsNorm, !expert,  image, !saveCorr);
345
346   TH1F* histoGlobalMult = new TH1F("hTriggerGlobalOutMultiplicity","Trigger global outputs multiplicity", 6, -0.5, 6.-0.5);
347   histoGlobalMult->GetYaxis()->SetTitle("Number of triggers"); 
348   histoGlobalMult->GetXaxis()->SetTitle("Global output");
349   for (int ibin=0;ibin<6;ibin++){
350     histoGlobalMult->GetXaxis()->SetBinLabel(ibin+1,globalXaxisName[ibin]);
351   }        
352   histoGlobalMult->SetFillColor(kBlue);
353   // Copy of previous histo for scaling purposes
354   TH1F* histoGlobalMultNorm = (TH1F*)histoGlobalMult->Clone("hTriggerGlobalOutMultiplicityPerEvt");
355   histoGlobalMultNorm->SetTitle("Trigger global outputs multiplicity per event");
356   histoGlobalMultNorm->SetOption("bar2");
357   histoGlobalMultNorm->SetBarWidth(0.5);
358   histoGlobalMultNorm->SetBarOffset(0.25);
359   histoGlobalMultNorm->GetYaxis()->SetTitle("Triggers per event");
360   // Adding both histos after cloning to avoid problems with the expert bit
361   Add2RawsList(histoGlobalMult,     kTriggerGlobalOutput,     expert, !image, !saveCorr);
362   Add2RawsList(histoGlobalMultNorm, kTriggerGlobalOutputNorm, expert, !image, !saveCorr);
363
364   histo1D = new TH1F("hRawNAnalyzedEvents", "Number of analyzed events per specie", 1, 0.5, 1.5);
365   Int_t esindex = AliRecoParam::AConvert(CurrentEventSpecie());
366   histo1D->GetXaxis()->SetBinLabel(1, AliRecoParam::GetEventSpecieName(esindex));
367   histo1D->GetYaxis()->SetTitle("Number of analyzed events");
368   Add2RawsList(histo1D, kRawNAnalyzedEvents, expert, !image, !saveCorr);
369 }
370
371 //__________________________________________________________________
372 void AliMUONTriggerQADataMakerRec::InitDigits() 
373 {
374   /// Initialized Digits spectra 
375   const Bool_t expert   = kTRUE ; 
376   const Bool_t image    = kTRUE ; 
377   
378   TH1I* h0 = new TH1I("hDigitsDetElem", "Detection element distribution in Digits;Detection element Id;Counts",  400, 1100, 1500); 
379   Add2DigitsList(h0, 0, !expert, image);
380
381
382 //____________________________________________________________________________ 
383 void AliMUONTriggerQADataMakerRec::InitRecPoints()
384 {
385         /// create Reconstructed Points histograms in RecPoints subdir for the
386         /// MUON Trigger subsystem.
387
388   const Bool_t expert   = kTRUE ; 
389   const Bool_t image    = kTRUE ; 
390
391   TH1F* histo1D = 0x0;
392
393   histo1D = new TH1F("hNAnalyzedEvents", "Number of analyzed events per specie", 1, 0.5, 1.5);
394   Int_t esindex = AliRecoParam::AConvert(CurrentEventSpecie());
395   histo1D->GetXaxis()->SetBinLabel(1, AliRecoParam::GetEventSpecieName(esindex));
396   histo1D->GetYaxis()->SetTitle("Number of analyzed events");
397   Add2RecPointsList(histo1D, kNAnalyzedEvents, expert, !image);
398
399   histo1D = new TH1F("hTriggerTrippedChambers", "Trigger RPCs in trip", 418, 1100-0.5, 1417+0.5);
400   histo1D->GetXaxis()->SetTitle("DetElemId");
401   histo1D->GetYaxis()->SetTitle("# of trips");
402   histo1D->SetFillColor(kRed);
403   histo1D->SetLineColor(kRed);
404   Add2RecPointsList(histo1D, kTriggerRPCtrips, !expert, image);
405
406   FillTriggerDCSHistos();       
407 }
408
409
410 //____________________________________________________________________________ 
411 void AliMUONTriggerQADataMakerRec::InitESDs()
412 {
413   /// Empty implementation
414 }
415
416 //____________________________________________________________________________
417 void AliMUONTriggerQADataMakerRec::MakeRaws(AliRawReader* rawReader)
418 {
419         /// make QA for rawdata trigger
420
421     AliCodeTimerAuto("",0);
422         
423     GetRawsData(kRawNAnalyzedEvents)->Fill(1.);
424
425     // Init Local/Regional/Global decision with fake values
426
427     UInt_t globalInput[4];
428     for (Int_t bit=0; bit<4; bit++){
429         globalInput[bit]=0;
430     }
431
432     //for (Int_t reg=0;reg<16;reg++){
433     //fTriggerOutputRegionalData[reg]=0;
434     //for (Int_t bit=0;bit<4;bit++){
435     //fTriggerInputGlobalDataLPt[reg][bit]=0;
436     //fTriggerInputGlobalDataHPt[reg][bit]=0;
437     //}
438     //}
439
440     AliMUONDigitStoreV2R digitStore;
441     digitStore.Create();
442     digitStore.Clear();
443
444     AliMUONDigitStoreV2R digitStoreAll;
445     digitStoreAll.Create();
446     digitStoreAll.Clear();
447     TArrayS xyPatternAll[2];
448     for(Int_t icath=0; icath<AliMpConstants::NofCathodes(); icath++){
449       xyPatternAll[icath].Set(AliMpConstants::NofTriggerChambers());
450       xyPatternAll[icath].Reset(1);
451     }
452     
453     AliMUONTriggerStoreV1 recoTriggerStore;
454     recoTriggerStore.Create();
455     recoTriggerStore.Clear();
456
457     AliMUONTriggerStoreV1 inputTriggerStore;
458     inputTriggerStore.Create();
459     inputTriggerStore.Clear();
460
461     AliMUONGlobalTrigger inputGlobalTrigger;
462
463     UShort_t maxNcounts = 0xFFFF;
464     
465     // Get trigger Local, Regional, Global in/outputs and scalers
466
467     Int_t loCircuit=0;
468     AliMpCDB::LoadDDLStore();
469
470     const AliMUONRawStreamTriggerHP::AliHeader*          darcHeader  = 0x0;
471     const AliMUONRawStreamTriggerHP::AliRegionalHeader*  regHeader   = 0x0;
472     const AliMUONRawStreamTriggerHP::AliLocalStruct*     localStruct = 0x0;
473
474     Int_t nDeadLocal = 0, nDeadRegional = 0, nDeadGlobal = 0, nNoisyStrips = 0;
475
476     // When a crate is not present, the loop on boards is not performed
477     // This should allow to correctly count the local boards
478     Int_t countNotifiedBoards = 0, countAllBoards = 0;
479
480     AliMUONRawStreamTriggerHP rawStreamTrig(rawReader);
481     while (rawStreamTrig.NextDDL()) 
482     {
483       Bool_t scalerEvent =  rawReader->GetDataHeader()->GetL1TriggerMessage() & 0x1;
484
485       Bool_t fillScalerHistos = ( scalerEvent && 
486                                   ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) );
487
488       if ( scalerEvent != fillScalerHistos ) {
489         Int_t esindex = AliRecoParam::AConvert(CurrentEventSpecie());
490         AliWarning(Form("Scaler event found but event specie is %s. Scaler histos will not be filled", AliRecoParam::GetEventSpecieName(esindex)));
491       }
492
493       darcHeader = rawStreamTrig.GetHeaders();
494
495       if (darcHeader->GetGlobalFlag()){
496         if ( fillScalerHistos ) {
497           UInt_t nOfClocks = darcHeader->GetGlobalClock();
498           Double_t nOfSeconds = ((Double_t) nOfClocks) / 40e6; // 1 clock each 25 ns
499           ((TH1F*)GetRawsData(kTriggerScalersTime))->Fill(1., nOfSeconds);
500         }
501
502         //Get Global datas
503         inputGlobalTrigger.SetFromGlobalResponse(darcHeader->GetGlobalOutput());
504         Bool_t resp[6] = {inputGlobalTrigger.PairUnlikeHpt(), inputGlobalTrigger.PairUnlikeLpt(),
505                           inputGlobalTrigger.PairLikeHpt(), inputGlobalTrigger.PairLikeLpt(),
506                           inputGlobalTrigger.SingleHpt(), inputGlobalTrigger.SingleHpt()}; 
507         for (Int_t bit=0; bit<6; bit++){
508           if ( ! resp[bit] ){
509             if ( fillScalerHistos )
510               nDeadGlobal++;
511           }
512           else
513             ((TH1F*)GetRawsData(kTriggerGlobalOutput))->Fill(bit);
514         }
515
516         //for (Int_t Bit=0; Bit<32; Bit++){
517         //fTriggerInputGlobalDataLPt[Bit/4][Bit%4]=((darcHeader->GetGlobalInput(0)>>Bit)&1);
518         //fTriggerInputGlobalDataLPt[Bit/4+8][Bit%4]=((darcHeader->GetGlobalInput(1)>>Bit)&1);
519         //fTriggerInputGlobalDataHPt[Bit/4][Bit%4]=((darcHeader->GetGlobalInput(2)>>Bit)&1);
520         //fTriggerInputGlobalDataHPt[Bit/4+8][Bit%4]=((darcHeader->GetGlobalInput(3)>>Bit)&1);
521         //}
522
523         for (Int_t i=0; i<4; i++){
524           globalInput[i]=darcHeader->GetGlobalInput(i);
525         }
526       }
527
528       Int_t nReg = rawStreamTrig.GetRegionalHeaderCount();
529
530       for(Int_t iReg = 0; iReg < nReg ;iReg++)
531       {   //reg loop
532
533         //Int_t regId=rawStreamTrig.GetDDL()*8+iReg;
534
535         // crate info  
536           AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->GetTriggerCrate(rawStreamTrig.GetDDL(), iReg);
537
538           regHeader =  rawStreamTrig.GetRegionalHeader(iReg);
539
540           //Get regional outputs -> not checked, hardware read-out doesn't work
541           //fTriggerOutputRegionalData[regId]=Int_t(regHeader->GetOutput());
542           // if ( ! fTriggerOutputRegionalData[regId] )
543           // nDeadRegional++;
544         Int_t nBoardsInReg = 0; // Not necessary when regional output will work
545
546         // loop over local structures
547         Int_t nLocal = regHeader->GetLocalStructCount();
548
549         for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
550         {
551             
552             localStruct = regHeader->GetLocalStruct(iLocal);
553
554           // if card exist
555           if (!localStruct) continue;
556           
557           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
558
559           if ( !loCircuit ) continue; // empty slot
560
561           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
562
563           nBoardsInReg++; // Not necessary when regional output will work
564           countAllBoards++;
565
566           // skip copy cards
567           if( !localBoard->IsNotified()) 
568             continue;
569
570           AliMUONLocalTrigger inputLocalTrigger;
571           inputLocalTrigger.SetLocalStruct(loCircuit, *localStruct);
572           inputTriggerStore.Add(inputLocalTrigger);
573
574           countNotifiedBoards++;  
575
576           TArrayS xyPattern[2];   
577           localStruct->GetXPattern(xyPattern[0]);
578           localStruct->GetYPattern(xyPattern[1]);
579           fDigitMaker->TriggerDigits(loCircuit, xyPattern, digitStore);
580           if ( fillScalerHistos ) // Compute total number of strips
581             fDigitMaker->TriggerDigits(loCircuit, xyPatternAll, digitStoreAll);
582
583           //Get electronic Decisions from data
584
585           //Get regional inputs -> not checked, hardware read-out doesn't work
586           //fTriggerInputRegionalDataLPt[0][loCircuit]=Int_t(((regHeader->GetInput(0))>>(2*iLocal))&1);
587           //fTriggerInputRegionalDataLPt[1][loCircuit]=Int_t(((regHeader->GetInput(1))>>((2*iLocal)+1))&1);
588
589           //Get local in/outputs
590           if (Int_t(localStruct->GetDec())!=0){
591               ((TH1F*)GetRawsData(kTriggeredBoards))->Fill(loCircuit);
592           }
593           else if ( fillScalerHistos ){
594             nDeadLocal++;
595           }
596
597           // loop over strips
598           if ( fillScalerHistos ) {
599             Int_t cathode = localStruct->GetComptXY()%2;
600             for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
601               if (ibitxy==0){
602                 AliDebug(AliQAv1::GetQADebugLevel(),"Filling trigger scalers");
603               }
604
605               UShort_t scalerVal[4] = {
606                 localStruct->GetXY1(ibitxy),
607                 localStruct->GetXY2(ibitxy),
608                 localStruct->GetXY3(ibitxy),
609                 localStruct->GetXY4(ibitxy)
610               };
611
612               for(Int_t ich=0; ich<AliMpConstants::NofTriggerChambers(); ich++){
613                 if ( scalerVal[ich] > 0 )
614                   ((TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*cathode + ich))
615                     ->Fill(loCircuit, ibitxy, 2*(Float_t)scalerVal[ich]);
616
617                 if ( scalerVal[ich] >= maxNcounts )
618                   nNoisyStrips++;
619               } // loop on chamber
620             } // loop on strips
621           } // scaler event
622         } // iLocal
623         if ( nBoardsInReg == 0 )
624           nDeadRegional++; // Not necessary when regional output will work
625       } // iReg
626
627       Float_t readoutErrors[kNtrigStructErrorBins] = {
628         ((Float_t)rawStreamTrig.GetLocalEoWErrors())/((Float_t)countAllBoards),
629         ((Float_t)rawStreamTrig.GetRegEoWErrors())/16.,
630         ((Float_t)rawStreamTrig.GetGlobalEoWErrors())/6.,
631         ((Float_t)rawStreamTrig.GetDarcEoWErrors())/2.
632       };
633     
634       for (Int_t ibin=0; ibin<kNtrigStructErrorBins; ibin++){
635         if ( readoutErrors[ibin] > 0 )
636           ((TH1F*)GetRawsData(kTriggerReadOutErrors))->Fill(ibin, readoutErrors[ibin]);
637       }
638     } // NextDDL
639
640     nDeadLocal += AliMUONConstants::NTriggerCircuit() - countNotifiedBoards;
641     Int_t nStripsTot = digitStoreAll.GetSize();
642     if ( nStripsTot > 0 ) { // The value is != 0 only for scaler events
643       Float_t fraction[kNtrigCalibSummaryBins] = {
644         ((Float_t)(nStripsTot - digitStore.GetSize())) / ((Float_t)nStripsTot),
645         //(Float_t)nDeadLocal / ((Float_t)countNotifiedBoards),
646         (Float_t)nDeadLocal / ((Float_t)AliMUONConstants::NTriggerCircuit()),
647         (Float_t)nDeadRegional / 16.,
648         (Float_t)nDeadGlobal / 6., // Number of bits of global response
649         (Float_t)nNoisyStrips / ((Float_t)nStripsTot),
650       };
651
652       for(Int_t ibin = 0; ibin < kNtrigCalibSummaryBins; ibin++){
653         if ( fraction[ibin] > 0. )
654           ((TH1F*)GetRawsData(kTriggerCalibSummary))->Fill(ibin, fraction[ibin]);
655       }
656     }
657
658   fTriggerProcessor->Digits2Trigger(digitStore,recoTriggerStore);
659
660   //Reconstruct Global decision from Global inputs
661   UChar_t recoResp = RawTriggerInGlobal2OutGlobal(globalInput);
662   AliMUONGlobalTrigger recoGlobalTrigger;
663   recoGlobalTrigger.SetFromGlobalResponse(recoResp);
664
665   // Compare data and reconstructed decisions and fill histos
666   RawTriggerMatchOutLocal(inputTriggerStore, recoTriggerStore);
667   //RawTriggerMatchOutLocalInRegional(); // Not tested, hardware read-out doesn't work
668   RawTriggerMatchOutGlobalFromInGlobal(inputGlobalTrigger, recoGlobalTrigger);
669 }
670
671 //__________________________________________________________________
672 void AliMUONTriggerQADataMakerRec::MakeDigits(TTree* digitsTree)         
673 {
674   /// makes data from Digits
675
676   // Do nothing in case of calibration event
677   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
678
679   if (!fDigitStore)
680     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
681
682   fDigitStore->Clear();
683   fDigitStore->Connect(*digitsTree, false);
684   digitsTree->GetEvent(0);
685   
686   TIter next(fDigitStore->CreateIterator());
687   
688   AliMUONVDigit* dig = 0x0;
689   
690   while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) )
691     {
692     GetDigitsData(0)->Fill(dig->DetElemId());
693     GetDigitsData(1)->Fill(dig->ADC());
694     }
695 }
696
697 //____________________________________________________________________________
698 void AliMUONTriggerQADataMakerRec::MakeRecPoints(TTree* /*clustersTree*/)
699 {
700   // Do nothing in case of calibration event
701   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
702         
703   GetRecPointsData(kNAnalyzedEvents)->Fill(1.);
704 }
705
706 //____________________________________________________________________________
707 void AliMUONTriggerQADataMakerRec::MakeESDs(AliESDEvent* /*esd*/)
708 {  
709   /// Empty implementation
710 }
711
712
713 //____________________________________________________________________________ 
714 void AliMUONTriggerQADataMakerRec::DisplayTriggerInfo()
715 {
716   //
717   /// Display trigger information in a user-friendly way:
718   /// from local board and strip numbers to their position on chambers
719   //
720
721   AliMUONTriggerDisplay triggerDisplay;
722   
723   TH2F* histoStrips=0x0;
724   TH2F* histoDisplayStrips=0x0;
725   if ( GetRawsData(kTriggerScalers) ) {
726     AliMUONTriggerDisplay::EDisplayOption displayOption = AliMUONTriggerDisplay::kNormalizeToArea;
727     for (Int_t iCath = 0; iCath < AliMpConstants::NofCathodes(); iCath++)
728       {    
729         for (Int_t iChamber = 0; iChamber < AliMpConstants::NofTriggerChambers(); iChamber++)
730           {
731             histoStrips = (TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
732
733             if(histoStrips->GetEntries()==0) continue; // No events found => No need to display
734
735             histoDisplayStrips = (TH2F*)GetRawsData(kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
736
737             triggerDisplay.FillDisplayHistogram(histoStrips, histoDisplayStrips,
738                                                 AliMUONTriggerDisplay::kDisplayStrips, iCath, iChamber, displayOption);
739
740             Float_t scaleValue = ((TH1F*)GetRawsData(kTriggerScalersTime))->GetBinContent(1);
741             if(scaleValue>0.) histoDisplayStrips->Scale(1./scaleValue);
742           } // iChamber
743       } // iCath
744   }
745
746   if ( GetRawsData(kTriggeredBoards) ){
747     TH1F* histoBoards = (TH1F*)GetRawsData(kTriggeredBoards);
748     TH2F* histoDisplayBoards = (TH2F*)GetRawsData(kTriggerBoardsDisplay);
749     triggerDisplay.FillDisplayHistogram(histoBoards, histoDisplayBoards, AliMUONTriggerDisplay::kDisplayBoards, 0, 0);
750     Float_t scaleValue = GetRawsData(kRawNAnalyzedEvents)->GetBinContent(1);
751     if(scaleValue>0.) histoDisplayBoards->Scale(1./scaleValue);
752   }
753 }
754
755
756 //_____________________________________________________________________________
757 Bool_t 
758 AliMUONTriggerQADataMakerRec::FillTriggerDCSHistos()
759 {
760   /// Get HV and currents values for one trigger chamber
761   
762   AliCodeTimerAuto("",0);
763
764   TMap* triggerDcsMap = fCalibrationData->TriggerDCS();
765
766   if ( !triggerDcsMap ) 
767   {
768     AliError("Cannot fill DCS histos, as triggerDcsMap is NULL");
769     return kFALSE;
770   }
771
772   const Double_t kMaxDelay = 3.;
773   const Double_t kMaxVariation = 25.; // Volts
774   const Int_t kDefaultNpoints = 200;
775   Double_t scaleFactor = 1./1000.;
776
777   Bool_t error = kFALSE;
778   Bool_t expert   = kTRUE;
779   Bool_t image    = kTRUE;
780
781   AliMpDEIterator deIt;
782   
783   AliMpDCSNamer triggerDcsNamer("TRIGGER");
784
785   TH2F* currHisto = 0x0;
786   Int_t histoIndex = 0;
787   TString histoName, histoTitle;
788
789   TArrayD axisSlat(18+1);
790   for(Int_t islat=0; islat<=18; islat++){
791     axisSlat[islat] = -0.5 + (Float_t)islat;
792   }
793
794   TArrayD axisTimeAux[4], axisTime[4], axisTimeDE(kDefaultNpoints);
795   TArrayI index[4], npoints(4);
796
797   // Build axis of times
798   npoints.Reset();
799   for(Int_t ich=0; ich<4; ich++){
800     axisTimeAux[ich].Set(kDefaultNpoints);
801     axisTimeAux[ich].Reset(-1.);
802   }
803
804   deIt.First();
805   while ( !deIt.IsDone() )
806   {
807     Int_t detElemId = deIt.CurrentDEId();
808     TObjArray* values = GetDCSValues(AliMpDCSNamer::kDCSHV, detElemId, triggerDcsMap, triggerDcsNamer);
809
810     if ( values ) {
811
812       AliDebug(AliQAv1::GetQADebugLevel(), Form("DetElemId %i", detElemId));
813
814       axisTimeDE.Reset(-1.);
815
816       TIter next(values);
817       AliDCSValue* val = 0x0;
818       Double_t previousVal = -999.;
819       Int_t npointsde = 0;
820       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
821       {
822         if ( npointsde + 1 > kDefaultNpoints ) {
823           axisTimeDE.Set(npointsde + 1);
824         }
825
826         Double_t currVal = val->GetFloat();
827         Double_t currTime = (Double_t)val->GetTimeStamp();
828         if (npointsde > 0 ){
829           if ( TMath::Abs( currVal - previousVal ) < kMaxVariation && 
830                TMath::Abs( currTime - axisTimeDE[npointsde-1] ) < 40 ) continue;
831         }
832
833         axisTimeDE[npointsde] = currTime;
834         previousVal = currVal;
835         npointsde++;
836       } // loop on values
837
838       //      AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding DE point %2i  (%2i)  %.2f  (%i)\n", previousBin, npointsde, axisTimeDE[previousBin], nTimesPerBin));
839
840       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
841       Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
842
843       for(Int_t ipde=0; ipde<npointsde; ipde++){
844
845         if ( npoints[ich] + 1 > kDefaultNpoints ) {
846           axisTimeAux[ich].Set(npoints[ich] + 1);
847         }
848
849         for(Int_t ipoint = 0; ipoint < axisTimeAux[ich].GetSize(); ipoint++){
850           if (axisTimeAux[ich][ipoint] < 0.) {
851             axisTimeAux[ich][ipoint] = axisTimeDE[ipde];
852             npoints[ich]++;
853             AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding point %2i  %.0f\n", ipoint, axisTimeAux[ich][ipoint]));
854             break;
855           }
856           if ( TMath::Abs( axisTimeDE[ipde] - axisTimeAux[ich][ipoint]) < kMaxDelay ) {
857             axisTimeAux[ich][ipoint] = TMath::Min(axisTimeAux[ich][ipoint], axisTimeDE[ipde]);
858             break;
859           }
860         } // loop on points
861       } // loop on reorganized values
862
863     } // if ( values ) 
864     deIt.Next();
865   } // loop on DetElemId
866
867   for(Int_t ich=0; ich<4; ich++){
868     axisTimeAux[ich].Set(npoints[ich]);
869     index[ich].Set(npoints[ich]);
870     TMath::Sort(npoints[ich], axisTimeAux[ich].GetArray(), index[ich].GetArray(), kFALSE);
871
872     axisTime[ich].Set(npoints[ich]+1);
873     for(Int_t ipoint = 0; ipoint < axisTimeAux[ich].GetSize(); ipoint++){
874       axisTime[ich][ipoint] = axisTimeAux[ich][index[ich][ipoint]];
875     }
876     Double_t minStartEndWidth = 0.1 * (axisTime[ich][npoints[ich]-1] - axisTime[ich][0]);
877     axisTime[ich][npoints[ich]] = axisTime[ich][npoints[ich]-1] + minStartEndWidth;
878     if ( npoints[ich] >= 1)
879       if ( axisTime[ich][1] - axisTime[ich][0] < minStartEndWidth )
880         axisTime[ich][0] = axisTime[ich][1] - minStartEndWidth;
881   }
882
883
884   // Loop again on detection elements: create and fill histos
885   deIt.First();
886   while ( !deIt.IsDone() )
887   {
888     Int_t detElemId = deIt.CurrentDEId();
889     TObjArray* values = GetDCSValues(AliMpDCSNamer::kDCSHV, detElemId, triggerDcsMap, triggerDcsNamer);
890
891     if ( values ) {
892       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
893       Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
894
895       histoIndex = kTriggerRPChv + ich;
896       histoName = Form("hRPCHVChamber%i", 11+ich);
897       histoTitle = Form("Chamber %i: RPC HV (kV)", 11+ich);
898
899       currHisto = (TH2F*)GetRecPointsData(histoIndex);
900
901       if(!currHisto){
902         currHisto  = new TH2F(histoName.Data(), histoTitle.Data(),
903                               npoints[ich], axisTime[ich].GetArray(),
904                               18, axisSlat.GetArray());
905         currHisto->GetXaxis()->SetTitle("Time");
906         currHisto->GetXaxis()->SetTimeDisplay(1);
907         //currHisto->GetXaxis()->SetTimeFormat("%d%b%y %H:%M:%S");
908         currHisto->GetXaxis()->SetLabelSize(0.03);
909         currHisto->GetYaxis()->SetTitle("RPC");
910         currHisto->SetOption("TEXT45COLZ");
911         Add2RecPointsList(currHisto, histoIndex, expert, !image);
912       }
913
914       Int_t slat = detElemId%100;
915       Int_t slatBin = currHisto->GetYaxis()->FindBin(slat);
916
917       TIter next(values);
918       AliDCSValue* val = 0x0;
919       Double_t sumValuesPerBin = 0.;
920       Int_t nValuesPerBin = 0;
921       Int_t previousBin = -1;
922       Double_t previousTime = -1., previousVal = -999., sumVal = 0., sumTime = 0.;
923       Bool_t isTrip = kFALSE;
924       Int_t nPointsForSlope = 0;
925       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
926       {
927         Double_t currTime = (Double_t)val->GetTimeStamp();
928         Int_t currentBin = currHisto->GetXaxis()->FindBin(currTime+0.5);
929         Double_t currVal = val->GetFloat();
930         Double_t deltaVal = currVal - previousVal;
931         Bool_t isRepeated = kFALSE;
932         if ( previousTime > 0 ){
933           isRepeated = ( TMath::Abs( currVal - previousVal ) < kMaxVariation && 
934                          TMath::Abs( currTime - previousTime ) < 40 );
935
936           // Check for trips
937           sumTime += currTime - previousTime;
938           sumVal += deltaVal;
939           nPointsForSlope++;
940
941           if ( sumTime > 0. && nPointsForSlope >= 3 ){
942             Double_t slope = sumVal / sumTime;
943             if ( slope < -10. ) // going down of more than 10V/s
944               isTrip = kTRUE;
945           }
946
947           if ( deltaVal * sumVal < 0. ) {
948             sumTime = 0.;
949             sumVal = 0.;
950             nPointsForSlope = 0;
951           }
952         }
953
954         if ( ! isRepeated ) {
955           if ( currentBin != previousBin ) {
956             if ( previousBin >= 0 ) {
957               currHisto->SetBinContent(previousBin, slatBin, scaleFactor*sumValuesPerBin/((Double_t)nValuesPerBin));
958               sumValuesPerBin = 0.;
959               nValuesPerBin = 0;
960             }
961             previousBin = currentBin;
962           }
963         }
964           
965         sumValuesPerBin += currVal;
966         nValuesPerBin++;
967         previousTime = currTime;
968         previousVal = currVal;
969       } // loop on values
970       currHisto->SetBinContent(previousBin, slatBin, scaleFactor*sumValuesPerBin/((Double_t)nValuesPerBin)); // Fill last value
971       if ( isTrip ) ((TH1F*)GetRecPointsData(kTriggerRPCtrips))->Fill(detElemId);
972     } // if ( values ) 
973     deIt.Next();
974   } // loop on detElem
975   return error;
976 }
977
978
979 //____________________________________________________________________________ 
980 TObjArray* 
981 AliMUONTriggerQADataMakerRec::GetDCSValues(Int_t iMeas, Int_t detElemId,
982                                            TMap* triggerDcsMap, AliMpDCSNamer& triggerDcsNamer)
983 {
984   if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger) return 0x0;
985
986   TString currAlias = triggerDcsNamer.DCSChannelName(detElemId, 0, iMeas);
987
988   TPair* triggerDcsPair = static_cast<TPair*>(triggerDcsMap->FindObject(currAlias.Data()));
989
990   if (!triggerDcsPair)
991   {
992     printf(Form("Did not find expected alias (%s) for DE %d\n",
993                 currAlias.Data(),detElemId));
994     return 0x0;
995   }
996
997   TObjArray* values = static_cast<TObjArray*>(triggerDcsPair->Value());
998   if (!values)
999   {
1000     printf(Form("Could not get values for alias %s\n",currAlias.Data()));
1001     return 0x0;
1002   }
1003
1004   return values;
1005 }
1006
1007
1008 //____________________________________________________________________________ 
1009 UChar_t AliMUONTriggerQADataMakerRec::RawTriggerInGlobal2OutGlobal(UInt_t globalInput[4])
1010 {
1011   //
1012   /// Reconstruct Global Trigger decision using Global Inputs
1013   //
1014
1015     AliCodeTimerAuto("",0);
1016
1017     AliMUONGlobalCrateConfig* globalConfig = fCalibrationData->GlobalTriggerCrateConfig();
1018
1019     AliMUONGlobalTriggerBoard globalTriggerBoard;
1020     globalTriggerBoard.Reset();
1021     for (Int_t i = 0; i < 4; i++) {
1022         globalTriggerBoard.Mask(i,globalConfig->GetGlobalMask(i));
1023     }
1024
1025     globalTriggerBoard.RecomputeRegional(globalInput);
1026     globalTriggerBoard.Response();
1027     return globalTriggerBoard.GetResponse();
1028
1029 }
1030
1031 //____________________________________________________________________________ 
1032 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutLocal(AliMUONVTriggerStore& inputTriggerStore,
1033                                                            AliMUONVTriggerStore& recoTriggerStore)
1034 {
1035   //
1036   /// Match data and reconstructed Local Trigger decision
1037   //
1038
1039   AliCodeTimerAuto("",0);
1040
1041   Bool_t skipBoard[234];
1042   memset(skipBoard,0,AliMUONConstants::NTriggerCircuit()*sizeof(Bool_t));
1043
1044   Bool_t errorInYCopy = kFALSE;
1045
1046   // First search for YCopy errors.
1047   Int_t loCircuit = -1;
1048   TIter next(recoTriggerStore.CreateLocalIterator());
1049   AliMUONLocalTrigger* recoLocalTrigger, *inputLocalTrigger;
1050   while ( ( recoLocalTrigger = static_cast<AliMUONLocalTrigger*>(next()) ) )
1051   {  
1052     loCircuit = recoLocalTrigger->LoCircuit();
1053     Int_t iboard = loCircuit - 1;
1054
1055     ((TH1F*)GetRawsData(kTriggerErrorLocalYCopyTest))->Fill(loCircuit);
1056   
1057     inputLocalTrigger = inputTriggerStore.FindLocal(loCircuit);
1058
1059     Int_t recoTrigPattern[4]  = {recoLocalTrigger->GetY1Pattern(), recoLocalTrigger->GetY2Pattern(), recoLocalTrigger->GetY3Pattern(), recoLocalTrigger->GetY4Pattern()};
1060     Int_t inputTrigPattern[4] = {inputLocalTrigger->GetY1Pattern(), inputLocalTrigger->GetY2Pattern(), inputLocalTrigger->GetY3Pattern(), inputLocalTrigger->GetY4Pattern()};
1061
1062     AliMpLocalBoard* localBoardMp = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit); // get local board object for switch value
1063
1064     Bool_t errorInCopyBoard = kFALSE;
1065     for(Int_t ich=0; ich<4; ich++){
1066       if ( recoTrigPattern[ich] != inputTrigPattern[ich] ){
1067         skipBoard[iboard] = kTRUE;
1068         if ( ich >=2 ){
1069           if ( localBoardMp->GetSwitch(AliMpLocalBoard::kOR0) )
1070             skipBoard[iboard+1] = kTRUE;
1071           if ( localBoardMp->GetSwitch(AliMpLocalBoard::kOR1) )
1072             skipBoard[iboard-1] = kTRUE;
1073         }
1074         errorInCopyBoard = kTRUE;
1075         errorInYCopy = kTRUE;
1076       }
1077     } // loop on chambers
1078     if ( errorInCopyBoard )
1079       ((TH1F*)GetRawsData(kTriggerErrorLocalYCopy))->Fill(loCircuit);    
1080   } // loop on local boards
1081
1082   if (errorInYCopy)
1083     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalYCopy);
1084   
1085   Bool_t errorInXPosDev = kFALSE;
1086   Bool_t errorInYPosTrigY = kFALSE;
1087   Bool_t errorInLUT = kFALSE;
1088
1089   next.Reset();
1090   while ( ( recoLocalTrigger = static_cast<AliMUONLocalTrigger*>(next()) ) )
1091   {  
1092     loCircuit = recoLocalTrigger->LoCircuit();
1093     Int_t iboard = loCircuit - 1;
1094   
1095     inputLocalTrigger = inputTriggerStore.FindLocal(loCircuit);
1096
1097     if ( recoLocalTrigger->LoStripX() != inputLocalTrigger->LoStripX() ) {
1098       ((TH1F*)GetRawsData(kTriggerErrorLocalXPos))->Fill(loCircuit);
1099       errorInXPosDev = kTRUE;
1100     }
1101
1102     if ( recoLocalTrigger->GetDeviation() != inputLocalTrigger->GetDeviation() ) {
1103       ((TH1F*)GetRawsData(kTriggerErrorLocalDev))->Fill(loCircuit);
1104       errorInXPosDev = kTRUE;
1105     }
1106
1107     // Skip following checks in case we previously found YCopy errors 
1108     if ( skipBoard[iboard] ) continue;
1109
1110     if ( recoLocalTrigger->GetLoDecision() != inputLocalTrigger->GetLoDecision() ) {
1111       ((TH1F*)GetRawsData(kTriggerErrorLocalTriggerDec))->Fill(loCircuit);
1112     }
1113
1114     // Test Hpt and LPT
1115     Int_t recoLut[2]  = { recoLocalTrigger->LoLpt(),  recoLocalTrigger->LoHpt() };
1116     Int_t inputLut[2] = {inputLocalTrigger->LoLpt(), inputLocalTrigger->LoHpt() };
1117     Int_t currIndex[2][2] = {{kTriggerErrorLocalLPtLSB, kTriggerErrorLocalLPtMSB},
1118                              {kTriggerErrorLocalHPtMSB, kTriggerErrorLocalHPtMSB}};
1119     for (Int_t ilut=0; ilut<2; ilut++){
1120       Int_t bitDiff = recoLut[ilut]^inputLut[ilut];
1121       if ( bitDiff == 0 ) continue;
1122       for (Int_t ibit=0; ibit<2; ibit++){
1123         Bool_t isBitDifferent = (bitDiff>>ibit)&1;
1124         if ( isBitDifferent ){
1125           ((TH1F*)GetRawsData(currIndex[ilut][ibit]))->Fill(loCircuit);
1126           errorInLUT = kTRUE;
1127         }
1128       }
1129     }
1130
1131     if ( recoLocalTrigger->LoStripY() != inputLocalTrigger->LoStripY() ) {
1132       ((TH1F*)GetRawsData(kTriggerErrorLocalYPos))->Fill(loCircuit);
1133       errorInYPosTrigY = kTRUE;
1134     }
1135
1136     if ( recoLocalTrigger->LoTrigY() != inputLocalTrigger->LoTrigY()  ) {
1137       ((TH1F*)GetRawsData(kTriggerErrorLocalTrigY))->Fill(loCircuit);   
1138       errorInYPosTrigY = kTRUE;
1139     }
1140   } // loop on local boards
1141
1142   if (errorInXPosDev)
1143     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalX);
1144
1145   if (errorInLUT)
1146     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalLUT);
1147
1148   if (errorInYPosTrigY)
1149     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalY);
1150
1151 }
1152 /*
1153 //____________________________________________________________________________ 
1154 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutLocalInRegional()
1155 {
1156   //
1157   /// Match Local outputs and Regional inputs
1158   /// Not tested, hardware read-out doesn't work
1159   //
1160
1161     for (int localId=1;localId<235;localId++){
1162         if(fTriggerOutputLocalDataLPtDec[0][localId]!=fTriggerInputRegionalDataLPt[0][localId]){
1163             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalLPtLSB))->Fill(localId);
1164         }
1165         if(fTriggerOutputLocalDataLPtDec[1][localId]!=fTriggerInputRegionalDataLPt[1][localId]){
1166             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalLPtMSB))->Fill(localId);
1167         }
1168         if(fTriggerOutputLocalDataHPtDec[0][localId]!=fTriggerInputRegionalDataHPt[0][localId]){
1169             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalHPtLSB))->Fill(localId);
1170         }
1171         if(fTriggerOutputLocalDataHPtDec[1][localId]!=fTriggerInputRegionalDataHPt[1][localId]){
1172             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalHPtMSB))->Fill(localId);
1173         }
1174     }
1175 }
1176 */
1177
1178
1179 //____________________________________________________________________________ 
1180 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutGlobalFromInGlobal(AliMUONGlobalTrigger& inputGlobalTrigger, 
1181                                                                         AliMUONGlobalTrigger& recoGlobalTrigger)
1182 {
1183   //
1184   /// Match data and reconstructed Global Trigger decision for a reconstruction from Global inputs
1185   //
1186
1187   if ( recoGlobalTrigger.GetGlobalResponse() == inputGlobalTrigger.GetGlobalResponse() )
1188     return;
1189
1190   ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoGlobalFromGlobal);
1191
1192   Bool_t inputResp[6] = {inputGlobalTrigger.PairUnlikeHpt(), inputGlobalTrigger.PairUnlikeLpt(),
1193                          inputGlobalTrigger.PairLikeHpt(), inputGlobalTrigger.PairLikeLpt(),
1194                          inputGlobalTrigger.SingleHpt(), inputGlobalTrigger.SingleHpt()};
1195
1196   Bool_t recoResp[6] = {recoGlobalTrigger.PairUnlikeHpt(), recoGlobalTrigger.PairUnlikeLpt(),
1197                         recoGlobalTrigger.PairLikeHpt(), recoGlobalTrigger.PairLikeLpt(),
1198                         recoGlobalTrigger.SingleHpt(), recoGlobalTrigger.SingleHpt()};
1199
1200   for (int bit=0;bit<6;bit++){
1201     if ( recoResp[bit] != inputResp[bit] )
1202       ((TH1F*)GetRawsData(kTriggerErrorOutGlobalFromInGlobal))->Fill(bit);
1203   }
1204 }