]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerQADataMakerRec.cxx
AliMUONTriggerQADataMakerRec:
[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   /// Fill histogram with total number of analyzed events for normalization purposes
701
702   // Do nothing in case of calibration event
703   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
704         
705   GetRecPointsData(kNAnalyzedEvents)->Fill(1.);
706 }
707
708 //____________________________________________________________________________
709 void AliMUONTriggerQADataMakerRec::MakeESDs(AliESDEvent* /*esd*/)
710 {  
711   /// Empty implementation
712 }
713
714
715 //____________________________________________________________________________ 
716 void AliMUONTriggerQADataMakerRec::DisplayTriggerInfo()
717 {
718   //
719   /// Display trigger information in a user-friendly way:
720   /// from local board and strip numbers to their position on chambers
721   //
722
723   AliMUONTriggerDisplay triggerDisplay;
724   
725   TH2F* histoStrips=0x0;
726   TH2F* histoDisplayStrips=0x0;
727   if ( GetRawsData(kTriggerScalers) ) {
728     AliMUONTriggerDisplay::EDisplayOption displayOption = AliMUONTriggerDisplay::kNormalizeToArea;
729     for (Int_t iCath = 0; iCath < AliMpConstants::NofCathodes(); iCath++)
730       {    
731         for (Int_t iChamber = 0; iChamber < AliMpConstants::NofTriggerChambers(); iChamber++)
732           {
733             histoStrips = (TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
734
735             if(histoStrips->GetEntries()==0) continue; // No events found => No need to display
736
737             histoDisplayStrips = (TH2F*)GetRawsData(kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
738
739             triggerDisplay.FillDisplayHistogram(histoStrips, histoDisplayStrips,
740                                                 AliMUONTriggerDisplay::kDisplayStrips, iCath, iChamber, displayOption);
741
742             Float_t scaleValue = ((TH1F*)GetRawsData(kTriggerScalersTime))->GetBinContent(1);
743             if(scaleValue>0.) histoDisplayStrips->Scale(1./scaleValue);
744           } // iChamber
745       } // iCath
746   }
747
748   if ( GetRawsData(kTriggeredBoards) ){
749     TH1F* histoBoards = (TH1F*)GetRawsData(kTriggeredBoards);
750     TH2F* histoDisplayBoards = (TH2F*)GetRawsData(kTriggerBoardsDisplay);
751     triggerDisplay.FillDisplayHistogram(histoBoards, histoDisplayBoards, AliMUONTriggerDisplay::kDisplayBoards, 0, 0);
752     Float_t scaleValue = GetRawsData(kRawNAnalyzedEvents)->GetBinContent(1);
753     if(scaleValue>0.) histoDisplayBoards->Scale(1./scaleValue);
754   }
755 }
756
757
758 //_____________________________________________________________________________
759 Bool_t 
760 AliMUONTriggerQADataMakerRec::FillTriggerDCSHistos()
761 {
762   /// Get HV and currents values for one trigger chamber
763   
764   AliCodeTimerAuto("",0);
765
766   TMap* triggerDcsMap = fCalibrationData->TriggerDCS();
767
768   if ( !triggerDcsMap ) 
769   {
770     AliError("Cannot fill DCS histos, as triggerDcsMap is NULL");
771     return kFALSE;
772   }
773
774   const Double_t kMaxDelay = 3.;
775   const Double_t kMaxVariation = 25.; // Volts
776   const Int_t kDefaultNpoints = 200;
777   Double_t scaleFactor = 1./1000.;
778
779   Bool_t error = kFALSE;
780   Bool_t expert   = kTRUE;
781   Bool_t image    = kTRUE;
782
783   AliMpDEIterator deIt;
784   
785   AliMpDCSNamer triggerDcsNamer("TRIGGER");
786
787   TH2F* currHisto = 0x0;
788   Int_t histoIndex = 0;
789   TString histoName, histoTitle;
790
791   TArrayD axisSlat(18+1);
792   for(Int_t islat=0; islat<=18; islat++){
793     axisSlat[islat] = -0.5 + (Float_t)islat;
794   }
795
796   TArrayD axisTimeAux[4], axisTime[4], axisTimeDE(kDefaultNpoints);
797   TArrayI index[4], npoints(4);
798
799   // Build axis of times
800   npoints.Reset();
801   for(Int_t ich=0; ich<4; ich++){
802     axisTimeAux[ich].Set(kDefaultNpoints);
803     axisTimeAux[ich].Reset(-1.);
804   }
805
806   deIt.First();
807   while ( !deIt.IsDone() )
808   {
809     Int_t detElemId = deIt.CurrentDEId();
810     TObjArray* values = GetDCSValues(AliMpDCSNamer::kDCSHV, detElemId, triggerDcsMap, triggerDcsNamer);
811
812     if ( values ) {
813
814       AliDebug(AliQAv1::GetQADebugLevel(), Form("DetElemId %i", detElemId));
815
816       axisTimeDE.Reset(-1.);
817
818       TIter next(values);
819       AliDCSValue* val = 0x0;
820       Double_t previousVal = -999.;
821       Int_t npointsde = 0;
822       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
823       {
824         if ( npointsde + 1 > kDefaultNpoints ) {
825           axisTimeDE.Set(npointsde + 1);
826         }
827
828         Double_t currVal = val->GetFloat();
829         Double_t currTime = (Double_t)val->GetTimeStamp();
830         if (npointsde > 0 ){
831           if ( TMath::Abs( currVal - previousVal ) < kMaxVariation && 
832                TMath::Abs( currTime - axisTimeDE[npointsde-1] ) < 40 ) continue;
833         }
834
835         axisTimeDE[npointsde] = currTime;
836         previousVal = currVal;
837         npointsde++;
838       } // loop on values
839
840       //      AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding DE point %2i  (%2i)  %.2f  (%i)\n", previousBin, npointsde, axisTimeDE[previousBin], nTimesPerBin));
841
842       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
843       Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
844
845       for(Int_t ipde=0; ipde<npointsde; ipde++){
846
847         if ( npoints[ich] + 1 > kDefaultNpoints ) {
848           axisTimeAux[ich].Set(npoints[ich] + 1);
849         }
850
851         for(Int_t ipoint = 0; ipoint < axisTimeAux[ich].GetSize(); ipoint++){
852           if (axisTimeAux[ich][ipoint] < 0.) {
853             axisTimeAux[ich][ipoint] = axisTimeDE[ipde];
854             npoints[ich]++;
855             AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding point %2i  %.0f\n", ipoint, axisTimeAux[ich][ipoint]));
856             break;
857           }
858           if ( TMath::Abs( axisTimeDE[ipde] - axisTimeAux[ich][ipoint]) < kMaxDelay ) {
859             axisTimeAux[ich][ipoint] = TMath::Min(axisTimeAux[ich][ipoint], axisTimeDE[ipde]);
860             break;
861           }
862         } // loop on points
863       } // loop on reorganized values
864
865     } // if ( values ) 
866     deIt.Next();
867   } // loop on DetElemId
868
869   for(Int_t ich=0; ich<4; ich++){
870     axisTimeAux[ich].Set(npoints[ich]);
871     index[ich].Set(npoints[ich]);
872     TMath::Sort(npoints[ich], axisTimeAux[ich].GetArray(), index[ich].GetArray(), kFALSE);
873
874     axisTime[ich].Set(npoints[ich]+1);
875     for(Int_t ipoint = 0; ipoint < axisTimeAux[ich].GetSize(); ipoint++){
876       axisTime[ich][ipoint] = axisTimeAux[ich][index[ich][ipoint]];
877     }
878     Double_t minStartEndWidth = 0.1 * (axisTime[ich][npoints[ich]-1] - axisTime[ich][0]);
879     axisTime[ich][npoints[ich]] = axisTime[ich][npoints[ich]-1] + minStartEndWidth;
880     if ( npoints[ich] >= 1)
881       if ( axisTime[ich][1] - axisTime[ich][0] < minStartEndWidth )
882         axisTime[ich][0] = axisTime[ich][1] - minStartEndWidth;
883   }
884
885
886   // Loop again on detection elements: create and fill histos
887   deIt.First();
888   while ( !deIt.IsDone() )
889   {
890     Int_t detElemId = deIt.CurrentDEId();
891     TObjArray* values = GetDCSValues(AliMpDCSNamer::kDCSHV, detElemId, triggerDcsMap, triggerDcsNamer);
892
893     if ( values ) {
894       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
895       Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
896
897       histoIndex = kTriggerRPChv + ich;
898       histoName = Form("hRPCHVChamber%i", 11+ich);
899       histoTitle = Form("Chamber %i: RPC HV (kV)", 11+ich);
900
901       currHisto = (TH2F*)GetRecPointsData(histoIndex);
902
903       if(!currHisto){
904         currHisto  = new TH2F(histoName.Data(), histoTitle.Data(),
905                               npoints[ich], axisTime[ich].GetArray(),
906                               18, axisSlat.GetArray());
907         currHisto->GetXaxis()->SetTitle("Time");
908         currHisto->GetXaxis()->SetTimeDisplay(1);
909         //currHisto->GetXaxis()->SetTimeFormat("%d%b%y %H:%M:%S");
910         currHisto->GetXaxis()->SetLabelSize(0.03);
911         currHisto->GetYaxis()->SetTitle("RPC");
912         currHisto->SetOption("TEXT45COLZ");
913         Add2RecPointsList(currHisto, histoIndex, expert, !image);
914       }
915
916       Int_t slat = detElemId%100;
917       Int_t slatBin = currHisto->GetYaxis()->FindBin(slat);
918
919       TIter next(values);
920       AliDCSValue* val = 0x0;
921       Double_t sumValuesPerBin = 0.;
922       Int_t nValuesPerBin = 0;
923       Int_t previousBin = -1;
924       Double_t previousTime = -1., previousVal = -999., sumVal = 0., sumTime = 0.;
925       Bool_t isTrip = kFALSE;
926       Int_t nPointsForSlope = 0;
927       while ( ( val = static_cast<AliDCSValue*>(next()) ) )
928       {
929         Double_t currTime = (Double_t)val->GetTimeStamp();
930         Int_t currentBin = currHisto->GetXaxis()->FindBin(currTime+0.5);
931         Double_t currVal = val->GetFloat();
932         Double_t deltaVal = currVal - previousVal;
933         Bool_t isRepeated = kFALSE;
934         if ( previousTime > 0 ){
935           isRepeated = ( TMath::Abs( currVal - previousVal ) < kMaxVariation && 
936                          TMath::Abs( currTime - previousTime ) < 40 );
937
938           // Check for trips
939           sumTime += currTime - previousTime;
940           sumVal += deltaVal;
941           nPointsForSlope++;
942
943           if ( sumTime > 0. && nPointsForSlope >= 3 ){
944             Double_t slope = sumVal / sumTime;
945             if ( slope < -10. ) // going down of more than 10V/s
946               isTrip = kTRUE;
947           }
948
949           if ( deltaVal * sumVal < 0. ) {
950             sumTime = 0.;
951             sumVal = 0.;
952             nPointsForSlope = 0;
953           }
954         }
955
956         if ( ! isRepeated ) {
957           if ( currentBin != previousBin ) {
958             if ( previousBin >= 0 ) {
959               currHisto->SetBinContent(previousBin, slatBin, scaleFactor*sumValuesPerBin/((Double_t)nValuesPerBin));
960               sumValuesPerBin = 0.;
961               nValuesPerBin = 0;
962             }
963             previousBin = currentBin;
964           }
965         }
966           
967         sumValuesPerBin += currVal;
968         nValuesPerBin++;
969         previousTime = currTime;
970         previousVal = currVal;
971       } // loop on values
972       currHisto->SetBinContent(previousBin, slatBin, scaleFactor*sumValuesPerBin/((Double_t)nValuesPerBin)); // Fill last value
973       if ( isTrip ) ((TH1F*)GetRecPointsData(kTriggerRPCtrips))->Fill(detElemId);
974     } // if ( values ) 
975     deIt.Next();
976   } // loop on detElem
977   return error;
978 }
979
980
981 //____________________________________________________________________________ 
982 TObjArray* 
983 AliMUONTriggerQADataMakerRec::GetDCSValues(Int_t iMeas, Int_t detElemId,
984                                            TMap* triggerDcsMap, AliMpDCSNamer& triggerDcsNamer)
985 {
986   //
987   /// Get values of DCS data points from the map
988   //
989
990   if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger) return 0x0;
991
992   TString currAlias = triggerDcsNamer.DCSChannelName(detElemId, 0, iMeas);
993
994   TPair* triggerDcsPair = static_cast<TPair*>(triggerDcsMap->FindObject(currAlias.Data()));
995
996   if (!triggerDcsPair)
997   {
998     printf(Form("Did not find expected alias (%s) for DE %d\n",
999                 currAlias.Data(),detElemId));
1000     return 0x0;
1001   }
1002
1003   TObjArray* values = static_cast<TObjArray*>(triggerDcsPair->Value());
1004   if (!values)
1005   {
1006     printf(Form("Could not get values for alias %s\n",currAlias.Data()));
1007     return 0x0;
1008   }
1009
1010   return values;
1011 }
1012
1013
1014 //____________________________________________________________________________ 
1015 UChar_t AliMUONTriggerQADataMakerRec::RawTriggerInGlobal2OutGlobal(UInt_t globalInput[4])
1016 {
1017   //
1018   /// Reconstruct Global Trigger decision using Global Inputs
1019   //
1020
1021     AliCodeTimerAuto("",0);
1022
1023     AliMUONGlobalCrateConfig* globalConfig = fCalibrationData->GlobalTriggerCrateConfig();
1024
1025     AliMUONGlobalTriggerBoard globalTriggerBoard;
1026     globalTriggerBoard.Reset();
1027     for (Int_t i = 0; i < 4; i++) {
1028         globalTriggerBoard.Mask(i,globalConfig->GetGlobalMask(i));
1029     }
1030
1031     globalTriggerBoard.RecomputeRegional(globalInput);
1032     globalTriggerBoard.Response();
1033     return globalTriggerBoard.GetResponse();
1034
1035 }
1036
1037 //____________________________________________________________________________ 
1038 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutLocal(AliMUONVTriggerStore& inputTriggerStore,
1039                                                            AliMUONVTriggerStore& recoTriggerStore)
1040 {
1041   //
1042   /// Match data and reconstructed Local Trigger decision
1043   //
1044
1045   AliCodeTimerAuto("",0);
1046
1047   Bool_t skipBoard[234];
1048   memset(skipBoard,0,AliMUONConstants::NTriggerCircuit()*sizeof(Bool_t));
1049
1050   Bool_t errorInYCopy = kFALSE;
1051
1052   // First search for YCopy errors.
1053   Int_t loCircuit = -1;
1054   TIter next(recoTriggerStore.CreateLocalIterator());
1055   AliMUONLocalTrigger* recoLocalTrigger, *inputLocalTrigger;
1056   while ( ( recoLocalTrigger = static_cast<AliMUONLocalTrigger*>(next()) ) )
1057   {  
1058     loCircuit = recoLocalTrigger->LoCircuit();
1059     Int_t iboard = loCircuit - 1;
1060
1061     ((TH1F*)GetRawsData(kTriggerErrorLocalYCopyTest))->Fill(loCircuit);
1062   
1063     inputLocalTrigger = inputTriggerStore.FindLocal(loCircuit);
1064
1065     Int_t recoTrigPattern[4]  = {recoLocalTrigger->GetY1Pattern(), recoLocalTrigger->GetY2Pattern(), recoLocalTrigger->GetY3Pattern(), recoLocalTrigger->GetY4Pattern()};
1066     Int_t inputTrigPattern[4] = {inputLocalTrigger->GetY1Pattern(), inputLocalTrigger->GetY2Pattern(), inputLocalTrigger->GetY3Pattern(), inputLocalTrigger->GetY4Pattern()};
1067
1068     AliMpLocalBoard* localBoardMp = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit); // get local board object for switch value
1069
1070     Bool_t errorInCopyBoard = kFALSE;
1071     for(Int_t ich=0; ich<4; ich++){
1072       if ( recoTrigPattern[ich] != inputTrigPattern[ich] ){
1073         skipBoard[iboard] = kTRUE;
1074         if ( ich >=2 ){
1075           if ( localBoardMp->GetSwitch(AliMpLocalBoard::kOR0) )
1076             skipBoard[iboard+1] = kTRUE;
1077           if ( localBoardMp->GetSwitch(AliMpLocalBoard::kOR1) )
1078             skipBoard[iboard-1] = kTRUE;
1079         }
1080         errorInCopyBoard = kTRUE;
1081         errorInYCopy = kTRUE;
1082       }
1083     } // loop on chambers
1084     if ( errorInCopyBoard )
1085       ((TH1F*)GetRawsData(kTriggerErrorLocalYCopy))->Fill(loCircuit);    
1086   } // loop on local boards
1087
1088   if (errorInYCopy)
1089     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalYCopy);
1090   
1091   Bool_t errorInXPosDev = kFALSE;
1092   Bool_t errorInYPosTrigY = kFALSE;
1093   Bool_t errorInLUT = kFALSE;
1094
1095   next.Reset();
1096   while ( ( recoLocalTrigger = static_cast<AliMUONLocalTrigger*>(next()) ) )
1097   {  
1098     loCircuit = recoLocalTrigger->LoCircuit();
1099     Int_t iboard = loCircuit - 1;
1100   
1101     inputLocalTrigger = inputTriggerStore.FindLocal(loCircuit);
1102
1103     if ( recoLocalTrigger->LoStripX() != inputLocalTrigger->LoStripX() ) {
1104       ((TH1F*)GetRawsData(kTriggerErrorLocalXPos))->Fill(loCircuit);
1105       errorInXPosDev = kTRUE;
1106     }
1107
1108     if ( recoLocalTrigger->GetDeviation() != inputLocalTrigger->GetDeviation() ) {
1109       ((TH1F*)GetRawsData(kTriggerErrorLocalDev))->Fill(loCircuit);
1110       errorInXPosDev = kTRUE;
1111     }
1112
1113     // Skip following checks in case we previously found YCopy error and YPos or trigY errors
1114     if ( (!skipBoard[iboard]) || ( (recoLocalTrigger->LoStripY() == inputLocalTrigger->LoStripY()) && (recoLocalTrigger->LoTrigY() == inputLocalTrigger->LoTrigY())) ) {
1115         
1116         if ( recoLocalTrigger->GetLoDecision() != inputLocalTrigger->GetLoDecision() ) {
1117             ((TH1F*)GetRawsData(kTriggerErrorLocalTriggerDec))->Fill(loCircuit);
1118         }
1119         
1120         // Test Hpt and LPT
1121         Int_t recoLut[2]  = { recoLocalTrigger->LoLpt(),  recoLocalTrigger->LoHpt() };
1122         Int_t inputLut[2] = {inputLocalTrigger->LoLpt(), inputLocalTrigger->LoHpt() };
1123         Int_t currIndex[2][2] = {{kTriggerErrorLocalLPtLSB, kTriggerErrorLocalLPtMSB},
1124                                  {kTriggerErrorLocalHPtMSB, kTriggerErrorLocalHPtMSB}};
1125         for (Int_t ilut=0; ilut<2; ilut++){
1126             Int_t bitDiff = recoLut[ilut]^inputLut[ilut];
1127             if ( bitDiff == 0 ) continue;
1128             for (Int_t ibit=0; ibit<2; ibit++){
1129                 Bool_t isBitDifferent = (bitDiff>>ibit)&1;
1130                 if ( isBitDifferent ){
1131                     ((TH1F*)GetRawsData(currIndex[ilut][ibit]))->Fill(loCircuit);
1132                     errorInLUT = kTRUE;
1133                 }
1134             }
1135         }
1136     }
1137     
1138  
1139     // Skip following checks in case we previously found YCopy errors
1140     if ( skipBoard[iboard] ) continue;
1141
1142     if ( recoLocalTrigger->LoStripY() != inputLocalTrigger->LoStripY() ) {
1143       ((TH1F*)GetRawsData(kTriggerErrorLocalYPos))->Fill(loCircuit);
1144       errorInYPosTrigY = kTRUE;
1145     }
1146
1147     if ( recoLocalTrigger->LoTrigY() != inputLocalTrigger->LoTrigY()  ) {
1148       ((TH1F*)GetRawsData(kTriggerErrorLocalTrigY))->Fill(loCircuit);   
1149       errorInYPosTrigY = kTRUE;
1150     }
1151   } // loop on local boards
1152
1153   if (errorInXPosDev)
1154     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalX);
1155
1156   if (errorInLUT)
1157     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalLUT);
1158
1159   if (errorInYPosTrigY)
1160     ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoLocalY);
1161
1162 }
1163 /*
1164 //____________________________________________________________________________ 
1165 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutLocalInRegional()
1166 {
1167   //
1168   /// Match Local outputs and Regional inputs
1169   /// Not tested, hardware read-out doesn't work
1170   //
1171
1172     for (int localId=1;localId<235;localId++){
1173         if(fTriggerOutputLocalDataLPtDec[0][localId]!=fTriggerInputRegionalDataLPt[0][localId]){
1174             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalLPtLSB))->Fill(localId);
1175         }
1176         if(fTriggerOutputLocalDataLPtDec[1][localId]!=fTriggerInputRegionalDataLPt[1][localId]){
1177             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalLPtMSB))->Fill(localId);
1178         }
1179         if(fTriggerOutputLocalDataHPtDec[0][localId]!=fTriggerInputRegionalDataHPt[0][localId]){
1180             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalHPtLSB))->Fill(localId);
1181         }
1182         if(fTriggerOutputLocalDataHPtDec[1][localId]!=fTriggerInputRegionalDataHPt[1][localId]){
1183             ((TH1F*)GetRawsData(kTriggerErrorLocal2RegionalHPtMSB))->Fill(localId);
1184         }
1185     }
1186 }
1187 */
1188
1189
1190 //____________________________________________________________________________ 
1191 void AliMUONTriggerQADataMakerRec::RawTriggerMatchOutGlobalFromInGlobal(AliMUONGlobalTrigger& inputGlobalTrigger, 
1192                                                                         AliMUONGlobalTrigger& recoGlobalTrigger)
1193 {
1194   //
1195   /// Match data and reconstructed Global Trigger decision for a reconstruction from Global inputs
1196   //
1197
1198   if ( recoGlobalTrigger.GetGlobalResponse() == inputGlobalTrigger.GetGlobalResponse() )
1199     return;
1200
1201   ((TH1F*)GetRawsData(kTriggerErrorSummary))->Fill(kAlgoGlobalFromGlobal);
1202
1203   Bool_t inputResp[6] = {inputGlobalTrigger.PairUnlikeHpt(), inputGlobalTrigger.PairUnlikeLpt(),
1204                          inputGlobalTrigger.PairLikeHpt(), inputGlobalTrigger.PairLikeLpt(),
1205                          inputGlobalTrigger.SingleHpt(), inputGlobalTrigger.SingleHpt()};
1206
1207   Bool_t recoResp[6] = {recoGlobalTrigger.PairUnlikeHpt(), recoGlobalTrigger.PairUnlikeLpt(),
1208                         recoGlobalTrigger.PairLikeHpt(), recoGlobalTrigger.PairLikeLpt(),
1209                         recoGlobalTrigger.SingleHpt(), recoGlobalTrigger.SingleHpt()};
1210
1211   for (int bit=0;bit<6;bit++){
1212     if ( recoResp[bit] != inputResp[bit] )
1213       ((TH1F*)GetRawsData(kTriggerErrorOutGlobalFromInGlobal))->Fill(bit);
1214   }
1215 }