]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONQADataMakerRec.cxx
Fix for FPE in the reconstruction QA of simulated raw data (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONQADataMakerRec.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$
17
18 // --- MUON header files ---
19 #include "AliMUONQADataMakerRec.h"
20
21 #include "AliMUON2DMap.h"
22 #include "AliMUONCluster.h"  
23 #include "AliMUONConstants.h"  
24 #include "AliMUONDDLTrigger.h"
25 #include "AliMUONDarcHeader.h"
26 #include "AliMUONDigitMaker.h"
27 #include "AliMUONQAMappingCheck.h"
28 #include "AliMUONLocalStruct.h"
29 #include "AliMUONLocalTrigger.h"
30 #include "AliMUONRawStreamTracker.h"
31 #include "AliMUONRawStreamTrigger.h"
32 #include "AliMUONRegHeader.h"
33 #include "AliMUONTrackerDataMaker.h"
34 #include "AliMUONTriggerDisplay.h"
35 #include "AliMUONVCluster.h"
36 #include "AliMUONVClusterStore.h"
37 #include "AliMUONVDigit.h"
38 #include "AliMUONVDigitStore.h"
39 #include "AliMUONVTrackerData.h"
40 #include "AliMUONVTriggerStore.h"
41 #include "AliMUONTrack.h"
42 #include "AliMUONTrackParam.h"
43 #include "AliMUONESDInterface.h"
44 #include "AliMUONCalibrationData.h"
45 #include "AliMpBusPatch.h"
46 #include "AliMpCDB.h"
47 #include "AliMpConstants.h"
48 #include "AliMpDDLStore.h"
49 #include "AliMpDEIterator.h"
50 #include "AliMpDEManager.h"
51 #include "AliMpDetElement.h"
52 #include "AliMpLocalBoard.h"
53 #include "AliMpStationType.h"
54 #include "AliMpTriggerCrate.h"
55 #include "AliMpDCSNamer.h"
56 #include "AliRawEventHeaderBase.h"
57
58 // --- AliRoot header files ---
59 #include "AliCDBManager.h"
60 #include "AliCDBStorage.h"
61 #include "AliESDEvent.h"
62 #include "AliESDMuonTrack.h"
63 #include "AliESDMuonCluster.h"
64 #include "AliLog.h"
65 #include "AliRawReader.h"
66 #include "AliQAChecker.h"
67 #include "AliCodeTimer.h"
68 #include "AliDCSValue.h"
69 #include "AliMUONVDigit.h"
70
71 // --- ROOT system ---
72 #include <TClonesArray.h>
73 #include <TFile.h> 
74 #include <TH1F.h> 
75 #include <TH1I.h> 
76 #include <TH2F.h>
77 #include <TLine.h>
78 #include <TPaveText.h>
79 #include <Riostream.h>
80 #include <TMath.h>
81
82 //-----------------------------------------------------------------------------
83 /// \class AliMUONQADataMakerRec
84 ///
85 /// MUON base class for quality assurance data (histo) maker
86 ///
87 /// \author C. Finck, D. Stocco, L. Aphecetche
88
89 /// \cond CLASSIMP
90 ClassImp(AliMUONQADataMakerRec)
91 /// \endcond
92            
93
94 namespace {
95   
96   int trim(Int_t n, 
97            Double_t* x,
98            Double_t alpha,
99            Double_t& tmean,
100            Double_t& tvar,
101            Double_t& min,
102            Double_t& max)
103   {
104     //
105     // Calculates the trimmed (tmean) mean
106     // of a sample (x) and estimates the variance (tvar)
107     // of that mean.
108     //
109     
110     // First check input parameters
111     
112     // number of observations
113     if ( n < 2 )
114     {
115       return -1;
116     }
117     
118     if ( alpha < 0 || alpha >= 0.5 )
119       // proportion of observations
120       // to be trimmed at each end of the sorted sample
121     {
122       return -2;
123     }
124     
125     // Input parameters are good. Let's move on.
126     
127     // Insure we use a sample sorted into ascending order.
128     
129     Int_t* indices = new Int_t[n];
130     
131     TMath::Sort(n,x,indices,kFALSE);
132     
133     Double_t* sx = new Double_t[n];
134     
135     for ( Int_t i = 0; i < n; ++i )
136     {
137       sx[i] = x[indices[i]];
138     }
139     delete[] indices;
140     
141   
142     // Number of observations trimmed at each end.
143     
144     Int_t k = static_cast<Int_t>(floorf(alpha * n));
145     
146     double sum = 0.0;
147     
148     for ( Int_t i = k; i < n - k ; ++i )
149     {
150       sum += sx[i];
151     }
152     
153     tmean = sum / ( n - 2 * k );
154   
155     double t2 = 0.0;
156     
157     for ( Int_t i = k; i < n - k; ++i )
158     {
159       t2 += (sx[i] - tmean) * (sx[i] - tmean);
160     }
161     
162     tvar = (
163             t2 +
164             k * (sx[k] - tmean) * (sx[k] - tmean) +
165             k * (sx[n - k - 1] - tmean) * (sx[n - k - 1] - tmean)
166             ) / (n * n);
167     
168     // get the min and max for the non-rejected values
169     min = DBL_MAX;
170     max = 0.0;
171     
172     for ( Int_t i = k; i < n-k; ++i ) 
173     {
174       min = TMath::Min(min,sx[i]);
175       max = TMath::Max(max,sx[i]);
176     }
177     
178     delete[] sx;
179     
180     return 0;
181   }
182 }
183
184 //____________________________________________________________________________ 
185 AliMUONQADataMakerRec::AliMUONQADataMakerRec() : 
186 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kMUON), "MUON Quality Assurance Data Maker"),
187 fDigitStore(0x0),
188 fTriggerStore(0x0),
189 fDigitMaker(0x0),
190 fClusterStore(0x0),
191 fTrackerDataMaker(0x0),
192 fMappingCheckRecPoints(0x0)
193 {
194     /// ctor
195         
196   AliDebug(AliQAv1::GetQADebugLevel(),"");
197
198         Ctor();
199 }
200
201 //____________________________________________________________________________ 
202 void
203 AliMUONQADataMakerRec::Ctor()
204 {
205         /// Init some members
206   AliCodeTimerAuto("");
207         fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
208         fDigitMaker = new AliMUONDigitMaker(kTRUE);
209 }
210
211 //____________________________________________________________________________ 
212 AliMUONQADataMakerRec::AliMUONQADataMakerRec(const AliMUONQADataMakerRec& qadm) :
213 AliQADataMakerRec(qadm),
214 fDigitStore(0x0),
215 fTriggerStore(0x0),
216 fDigitMaker(0x0),
217 fClusterStore(0x0),
218 fTrackerDataMaker(0x0),
219 fMappingCheckRecPoints(0x0)
220 {
221     ///copy ctor 
222
223   AliDebug(AliQAv1::GetQADebugLevel(),"");
224
225
226     SetName((const char*)qadm.GetName()) ; 
227     SetTitle((const char*)qadm.GetTitle()); 
228
229         // Do not copy the digit store and digit maker, but create its own ones
230         
231         Ctor();
232         
233 }
234
235 //__________________________________________________________________
236 AliMUONQADataMakerRec& AliMUONQADataMakerRec::operator = (const AliMUONQADataMakerRec& qadm )
237 {
238   /// Assignment operator
239
240   AliDebug(AliQAv1::GetQADebugLevel(),"");
241
242   // check assignment to self
243   if (this == &qadm) return *this;
244
245   this->~AliMUONQADataMakerRec();
246   new(this) AliMUONQADataMakerRec(qadm);
247   return *this;
248 }
249
250 //__________________________________________________________________
251 AliMUONQADataMakerRec::~AliMUONQADataMakerRec()
252 {
253     /// dtor
254   
255   AliDebug(AliQAv1::GetQADebugLevel(),"");
256
257   AliCodeTimerAuto("");
258   
259   delete fDigitStore;
260   delete fTriggerStore;
261   delete fDigitMaker;
262   delete fClusterStore;
263   delete fTrackerDataMaker;
264   delete fMappingCheckRecPoints;
265 }
266
267 //____________________________________________________________________________ 
268 void AliMUONQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray** list)
269 {
270   /// Detector specific actions at end of cycle
271   
272   AliCodeTimerAuto("");
273   
274   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
275   {
276     if (! IsValidEventSpecie(specie, list)  ) continue;
277     
278     SetEventSpecie(AliRecoParam::ConvertIndex(specie));
279         
280     if ( task == AliQAv1::kRAWS && fTrackerDataMaker ) 
281     {
282       // export trackerdata as is, and also make a summarized version (buspatchoccupancy)
283       EndOfDetectorCycleRaws(specie,list);
284     }
285     
286     if ( task == AliQAv1::kRECPOINTS )
287     {
288       // normalize recpoints histograms
289       EndOfDetectorCycleRecPoints(specie,list);
290     }
291     
292     if ( task == AliQAv1::kESDS ) 
293     {
294       // normalize esds histograms
295       EndOfDetectorCycleESDs();
296     }
297     
298     // Display trigger histos in a more user friendly way
299     DisplayTriggerInfo(task);
300     
301   } // loop on specie
302     
303   // do the QA checking
304   AliQAChecker::Instance()->Run(AliQAv1::kMUON,task,list);
305 }
306
307 //____________________________________________________________________________ 
308 void AliMUONQADataMakerRec::InsertTrackerData(Int_t specie, TObjArray** list,
309                                               TObject* object, Int_t indexNumber,
310                                               Bool_t replace)
311 {
312   /// Insert an object to a given list
313   
314   TIter next(list[specie]);
315   TObject* o;
316   TObject* old(0x0);
317   Bool_t alreadyThere(kFALSE);
318   while ( ( o = next() ) && !alreadyThere )
319   {
320     TString classname(o->ClassName());
321     if ( classname.Contains("TrackerData") ) 
322     {
323       alreadyThere = kTRUE;
324       old = o;
325     }
326   }
327   if ( (!alreadyThere && object) || (alreadyThere && replace) )
328   {
329     delete old;
330     AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s to the list of qa objects",object->GetName()));
331     list[specie]->AddAt(object,indexNumber);
332   }
333 }
334
335 //____________________________________________________________________________ 
336 void AliMUONQADataMakerRec::EndOfDetectorCycleESDs()
337 {
338   /// Normalize ESD histograms
339   
340   if (!GetESDsData(kESDnClustersPerTrack)) return;
341   
342   Double_t nTracks = GetESDsData(kESDnClustersPerTrack)->GetEntries();
343   if (nTracks <= 0) return;
344   
345   TH1* hESDnClustersPerCh = GetESDsData(kESDnClustersPerCh);
346   TH1* hESDnClustersPerDE = GetESDsData(kESDnClustersPerDE);
347   TH1* hESDClusterChargePerChMean = GetESDsData(kESDClusterChargePerChMean);
348   TH1* hESDClusterChargePerChSigma = GetESDsData(kESDClusterChargePerChSigma);
349   TH1* hESDClusterSizePerChMean = GetESDsData(kESDClusterSizePerChMean);
350   TH1* hESDClusterSizePerChSigma = GetESDsData(kESDClusterSizePerChSigma);
351   TH1* hESDResidualXPerChMean = GetESDsData(kESDResidualXPerChMean);
352   TH1* hESDResidualXPerChSigma = GetESDsData(kESDResidualXPerChSigma);
353   TH1* hESDResidualYPerChMean = GetESDsData(kESDResidualYPerChMean);
354   TH1* hESDResidualYPerChSigma = GetESDsData(kESDResidualYPerChSigma);
355   TH1* hESDLocalChi2XPerChMean = GetESDsData(kESDLocalChi2XPerChMean);
356   TH1* hESDLocalChi2YPerChMean = GetESDsData(kESDLocalChi2YPerChMean);
357   TH1* hESDLocalChi2PerChMean = GetESDsData(kESDLocalChi2PerChMean);
358   TH1* hESDClusterChargePerDE = GetESDsData(kESDClusterChargePerDE);
359   TH1* hESDClusterSizePerDE = GetESDsData(kESDClusterSizePerDE);
360   TH1* hESDResidualXPerDEMean = GetESDsData(kESDResidualXPerDEMean);
361   TH1* hESDResidualXPerDESigma = GetESDsData(kESDResidualXPerDESigma);
362   TH1* hESDResidualYPerDEMean = GetESDsData(kESDResidualYPerDEMean);
363   TH1* hESDResidualYPerDESigma = GetESDsData(kESDResidualYPerDESigma);
364   TH1* hESDLocalChi2XPerDEMean = GetESDsData(kESDLocalChi2XPerDEMean);
365   TH1* hESDLocalChi2YPerDEMean = GetESDsData(kESDLocalChi2YPerDEMean);
366   TH1* hESDLocalChi2PerDEMean = GetESDsData(kESDLocalChi2PerDEMean);
367   TH1* hESDnTotClustersPerCh = GetESDsData(kESDnTotClustersPerCh);
368   TH1* hESDnTotClustersPerDE = GetESDsData(kESDnTotClustersPerDE);
369   TH1* hESDnTotFullClustersPerDE = GetESDsData(kESDnTotFullClustersPerDE);
370   TH1* hESDSumClusterChargePerDE = GetESDsData(kESDSumClusterChargePerDE);
371   TH1* hESDSumClusterSizePerDE = GetESDsData(kESDSumClusterSizePerDE);
372   TH1* hESDSumResidualXPerDE = GetESDsData(kESDSumResidualXPerDE);
373   TH1* hESDSumResidualYPerDE = GetESDsData(kESDSumResidualYPerDE);
374   TH1* hESDSumResidualX2PerDE = GetESDsData(kESDSumResidualX2PerDE);
375   TH1* hESDSumResidualY2PerDE = GetESDsData(kESDSumResidualY2PerDE);
376   TH1* hESDSumLocalChi2XPerDE = GetESDsData(kESDSumLocalChi2XPerDE);
377   TH1* hESDSumLocalChi2YPerDE = GetESDsData(kESDSumLocalChi2YPerDE);
378   TH1* hESDSumLocalChi2PerDE = GetESDsData(kESDSumLocalChi2PerDE);
379   
380   hESDnClustersPerCh->Reset();
381   hESDnClustersPerDE->Reset();
382   hESDnClustersPerCh->Add(hESDnTotClustersPerCh, 1./nTracks);
383   hESDnClustersPerDE->Add(hESDnTotClustersPerDE, 1./nTracks);
384   
385   // loop over chambers
386   for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
387     
388     TH1* hESDClusterChargeInCh = GetESDsData(kESDClusterChargeInCh+iCh);
389     Double_t sigmaCharge = hESDClusterChargeInCh->GetRMS();
390     hESDClusterChargePerChMean->SetBinContent(iCh+1, hESDClusterChargeInCh->GetMean());
391     hESDClusterChargePerChMean->SetBinError(iCh+1, hESDClusterChargeInCh->GetMeanError());
392     hESDClusterChargePerChSigma->SetBinContent(iCh+1, sigmaCharge);
393     hESDClusterChargePerChSigma->SetBinError(iCh+1, hESDClusterChargeInCh->GetRMSError());
394     
395     TH1* hESDClusterSizeInCh = GetESDsData(kESDClusterSizeInCh+iCh);
396     Double_t sigmaSize = hESDClusterSizeInCh->GetRMS();
397     hESDClusterSizePerChMean->SetBinContent(iCh+1, hESDClusterSizeInCh->GetMean());
398     hESDClusterSizePerChMean->SetBinError(iCh+1, hESDClusterSizeInCh->GetMeanError());
399     hESDClusterSizePerChSigma->SetBinContent(iCh+1, sigmaSize);
400     hESDClusterSizePerChSigma->SetBinError(iCh+1, hESDClusterSizeInCh->GetRMSError());
401     
402     TH1* hESDResidualXInCh = GetESDsData(kESDResidualXInCh+iCh);
403     Double_t sigmaResidualX = hESDResidualXInCh->GetRMS();
404     hESDResidualXPerChMean->SetBinContent(iCh+1, hESDResidualXInCh->GetMean());
405     hESDResidualXPerChMean->SetBinError(iCh+1, hESDResidualXInCh->GetMeanError());
406     hESDResidualXPerChSigma->SetBinContent(iCh+1, sigmaResidualX);
407     hESDResidualXPerChSigma->SetBinError(iCh+1, hESDResidualXInCh->GetRMSError());
408     
409     TH1* hESDResidualYInCh = GetESDsData(kESDResidualYInCh+iCh);
410     Double_t sigmaResidualY = hESDResidualYInCh->GetRMS();
411     hESDResidualYPerChMean->SetBinContent(iCh+1, hESDResidualYInCh->GetMean());
412     hESDResidualYPerChMean->SetBinError(iCh+1, hESDResidualYInCh->GetMeanError());
413     hESDResidualYPerChSigma->SetBinContent(iCh+1, sigmaResidualY);
414     hESDResidualYPerChSigma->SetBinError(iCh+1, hESDResidualYInCh->GetRMSError());
415     
416     TH1* hESDLocalChi2XInCh = GetESDsData(kESDLocalChi2XInCh+iCh);
417     Double_t sigmaLocalChi2X = hESDLocalChi2XInCh->GetRMS();
418     hESDLocalChi2XPerChMean->SetBinContent(iCh+1, hESDLocalChi2XInCh->GetMean());
419     hESDLocalChi2XPerChMean->SetBinError(iCh+1, hESDLocalChi2XInCh->GetMeanError());
420     
421     TH1* hESDLocalChi2YInCh = GetESDsData(kESDLocalChi2YInCh+iCh);
422     Double_t sigmaLocalChi2Y = hESDLocalChi2YInCh->GetRMS();
423     hESDLocalChi2YPerChMean->SetBinContent(iCh+1, hESDLocalChi2YInCh->GetMean());
424     hESDLocalChi2YPerChMean->SetBinError(iCh+1, hESDLocalChi2YInCh->GetMeanError());
425     
426     TH1* hESDLocalChi2InCh = GetESDsData(kESDLocalChi2InCh+iCh);
427     Double_t sigmaLocalChi2 = hESDLocalChi2InCh->GetRMS();
428     hESDLocalChi2PerChMean->SetBinContent(iCh+1, hESDLocalChi2InCh->GetMean());
429     hESDLocalChi2PerChMean->SetBinError(iCh+1, hESDLocalChi2InCh->GetMeanError());
430     
431     // loop over DE into chamber iCh
432     AliMpDEIterator it;
433     it.First(iCh);
434     while ( !it.IsDone()) {
435       
436       Int_t iDE = it.CurrentDEId();
437       
438       Double_t nClusters = hESDnTotClustersPerDE->GetBinContent(iDE+1);
439       if (nClusters > 1) {
440         
441         hESDClusterChargePerDE->SetBinContent(iDE+1, hESDSumClusterChargePerDE->GetBinContent(iDE+1)/nClusters);
442         hESDClusterChargePerDE->SetBinError(iDE+1, sigmaCharge/TMath::Sqrt(nClusters));
443         
444         Double_t meanResX = hESDSumResidualXPerDE->GetBinContent(iDE+1)/nClusters;
445         hESDResidualXPerDEMean->SetBinContent(iDE+1, meanResX);
446         hESDResidualXPerDEMean->SetBinError(iDE+1, sigmaResidualX/TMath::Sqrt(nClusters));
447         hESDResidualXPerDESigma->SetBinContent(iDE+1, TMath::Sqrt(hESDSumResidualX2PerDE->GetBinContent(iDE+1)/nClusters - meanResX*meanResX));
448         hESDResidualXPerDESigma->SetBinError(iDE+1, sigmaResidualX/TMath::Sqrt(2.*nClusters));
449         
450         Double_t meanResY = hESDSumResidualYPerDE->GetBinContent(iDE+1)/nClusters;
451         hESDResidualYPerDEMean->SetBinContent(iDE+1, meanResY);
452         hESDResidualYPerDEMean->SetBinError(iDE+1, sigmaResidualY/TMath::Sqrt(nClusters));
453         hESDResidualYPerDESigma->SetBinContent(iDE+1, TMath::Sqrt(hESDSumResidualY2PerDE->GetBinContent(iDE+1)/nClusters - meanResY*meanResY));
454         hESDResidualYPerDESigma->SetBinError(iDE+1, sigmaResidualY/TMath::Sqrt(2.*nClusters));
455         
456         hESDLocalChi2XPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2XPerDE->GetBinContent(iDE+1)/nClusters);
457         hESDLocalChi2XPerDEMean->SetBinError(iDE+1, sigmaLocalChi2X/TMath::Sqrt(nClusters));
458         
459         hESDLocalChi2YPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2YPerDE->GetBinContent(iDE+1)/nClusters);
460         hESDLocalChi2YPerDEMean->SetBinError(iDE+1, sigmaLocalChi2Y/TMath::Sqrt(nClusters));
461         
462         hESDLocalChi2PerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2PerDE->GetBinContent(iDE+1)/nClusters);
463         hESDLocalChi2PerDEMean->SetBinError(iDE+1, sigmaLocalChi2/TMath::Sqrt(nClusters));
464         
465       } else {
466         
467         hESDClusterChargePerDE->SetBinContent(iDE+1, hESDSumClusterChargePerDE->GetBinContent(iDE+1));
468         hESDClusterChargePerDE->SetBinError(iDE+1, hESDClusterChargeInCh->GetXaxis()->GetXmax());
469         
470         hESDResidualXPerDEMean->SetBinContent(iDE+1, hESDSumResidualXPerDE->GetBinContent(iDE+1));
471         hESDResidualXPerDEMean->SetBinError(iDE+1, hESDResidualXInCh->GetXaxis()->GetXmax());
472         hESDResidualXPerDESigma->SetBinContent(iDE+1, 0.);
473         hESDResidualXPerDESigma->SetBinError(iDE+1, hESDResidualXInCh->GetXaxis()->GetXmax());
474         
475         hESDResidualYPerDEMean->SetBinContent(iDE+1, hESDSumResidualYPerDE->GetBinContent(iDE+1));
476         hESDResidualYPerDEMean->SetBinError(iDE+1, hESDResidualYInCh->GetXaxis()->GetXmax());
477         hESDResidualYPerDESigma->SetBinContent(iDE+1, 0.);
478         hESDResidualYPerDESigma->SetBinError(iDE+1, hESDResidualYInCh->GetXaxis()->GetXmax());
479         
480         hESDLocalChi2XPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2XPerDE->GetBinContent(iDE+1));
481         hESDLocalChi2XPerDEMean->SetBinError(iDE+1, hESDLocalChi2XInCh->GetXaxis()->GetXmax());
482         
483         hESDLocalChi2YPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2YPerDE->GetBinContent(iDE+1));
484         hESDLocalChi2YPerDEMean->SetBinError(iDE+1, hESDLocalChi2YInCh->GetXaxis()->GetXmax());
485         
486         hESDLocalChi2PerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2PerDE->GetBinContent(iDE+1));
487         hESDLocalChi2PerDEMean->SetBinError(iDE+1, hESDLocalChi2InCh->GetXaxis()->GetXmax());
488         
489       }
490       
491       Double_t nFullClusters = hESDnTotFullClustersPerDE->GetBinContent(iDE+1);
492       if (nFullClusters > 1) {
493         
494         hESDClusterSizePerDE->SetBinContent(iDE+1, hESDSumClusterSizePerDE->GetBinContent(iDE+1)/nFullClusters);
495         hESDClusterSizePerDE->SetBinError(iDE+1, sigmaSize/TMath::Sqrt(nFullClusters));
496         
497       } else {
498         
499         hESDClusterSizePerDE->SetBinContent(iDE+1, hESDSumClusterSizePerDE->GetBinContent(iDE+1));
500         hESDClusterSizePerDE->SetBinError(iDE+1, hESDClusterSizeInCh->GetXaxis()->GetXmax());
501         
502       }
503       
504       it.Next();
505     }
506
507   }
508
509 }
510   
511 //____________________________________________________________________________ 
512 void AliMUONQADataMakerRec::EndOfDetectorCycleRecPoints(Int_t specie, TObjArray** list)
513 {
514   /// Normalize RecPoints histograms
515   
516   if (!GetRecPointsData(kTrackerClusterChargePerChMean)) return;
517   
518   TH1* hTrackerClusterChargePerChMean = GetRecPointsData(kTrackerClusterChargePerChMean);
519   TH1* hTrackerClusterChargePerChSigma = GetRecPointsData(kTrackerClusterChargePerChSigma);
520   TH1* hTrackerClusterMultiplicityPerChMean = GetRecPointsData(kTrackerClusterMultiplicityPerChMean);
521   TH1* hTrackerClusterMultiplicityPerChSigma = GetRecPointsData(kTrackerClusterMultiplicityPerChSigma);
522   TH1* hTrackerClusterChargePerDEMean = GetRecPointsData(kTrackerClusterChargePerDEMean);
523   TH1* hTrackerClusterMultiplicityPerDEMean = GetRecPointsData(kTrackerClusterMultiplicityPerDEMean);
524   
525   // loop over chambers
526   for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
527     
528     TH1* hTrackerClusterChargePerChamber = GetRecPointsData(kTrackerClusterChargePerChamber+iCh);
529     Double_t sigmaCharge = hTrackerClusterChargePerChamber->GetRMS();
530     hTrackerClusterChargePerChMean->SetBinContent(iCh+1, hTrackerClusterChargePerChamber->GetMean());
531     hTrackerClusterChargePerChMean->SetBinError(iCh+1, hTrackerClusterChargePerChamber->GetMeanError());
532     hTrackerClusterChargePerChSigma->SetBinContent(iCh+1, sigmaCharge);
533     hTrackerClusterChargePerChSigma->SetBinError(iCh+1, hTrackerClusterChargePerChamber->GetRMSError());
534     
535     TH1* hTrackerClusterMultiplicityPerChamber = GetRecPointsData(kTrackerClusterMultiplicityPerChamber+iCh);
536     Double_t sigmaSize = hTrackerClusterMultiplicityPerChamber->GetRMS();
537     hTrackerClusterMultiplicityPerChMean->SetBinContent(iCh+1, hTrackerClusterMultiplicityPerChamber->GetMean());
538     hTrackerClusterMultiplicityPerChMean->SetBinError(iCh+1, hTrackerClusterMultiplicityPerChamber->GetMeanError());
539     hTrackerClusterMultiplicityPerChSigma->SetBinContent(iCh+1, sigmaSize);
540     hTrackerClusterMultiplicityPerChSigma->SetBinError(iCh+1, hTrackerClusterMultiplicityPerChamber->GetRMSError());
541     
542     // loop over DE into chamber iCh
543     AliMpDEIterator it;
544     it.First(iCh);
545     while ( !it.IsDone()) {
546       
547       Int_t iDE = it.CurrentDEId();
548       
549       TH1* hTrackerClusterChargePerDE = GetRecPointsData(kTrackerClusterChargePerDE+iDE);
550       hTrackerClusterChargePerDEMean->SetBinContent(iDE+1, hTrackerClusterChargePerDE->GetMean());
551       Double_t nClusters = hTrackerClusterChargePerDE->GetEntries();
552       if (nClusters > 1) hTrackerClusterChargePerDEMean->SetBinError(iDE+1, sigmaCharge/TMath::Sqrt(nClusters));
553       else hTrackerClusterChargePerDEMean->SetBinError(iDE+1, hTrackerClusterChargePerChamber->GetXaxis()->GetXmax());
554       
555       TH1* hTrackerClusterMultiplicityPerDE = GetRecPointsData(kTrackerClusterMultiplicityPerDE+iDE);
556       hTrackerClusterMultiplicityPerDEMean->SetBinContent(iDE+1, hTrackerClusterMultiplicityPerDE->GetMean());
557       nClusters = hTrackerClusterMultiplicityPerDE->GetEntries();
558       if (nClusters > 1) hTrackerClusterMultiplicityPerDEMean->SetBinError(iDE+1, sigmaSize/TMath::Sqrt(nClusters));
559       else hTrackerClusterMultiplicityPerDEMean->SetBinError(iDE+1, hTrackerClusterMultiplicityPerChamber->GetXaxis()->GetXmax());
560       
561       it.Next();
562     }
563   }
564   
565   if ( fMappingCheckRecPoints ) InsertTrackerData(specie,list,fMappingCheckRecPoints->CreateData("RecPoints"),kTrackerRecPoints,kTRUE);
566 }
567
568
569 //____________________________________________________________________________ 
570 void AliMUONQADataMakerRec::EndOfDetectorCycleRaws(Int_t specie, TObjArray** list)
571 {
572   /// create Raws histograms in Raws subdir
573   
574   if ( !GetRawsData(kTrackerBusPatchOccupancy) ) return;
575
576   if ( fTrackerDataMaker ) 
577   {
578     InsertTrackerData(specie,list,fTrackerDataMaker->Data(),kTrackerData);
579
580     TH1* hbp = GetRawsData(kTrackerBusPatchOccupancy);
581     hbp->Reset();
582     TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
583     AliMpBusPatch* bp(0x0);
584     AliMUONVTrackerData* data = fTrackerDataMaker->Data();
585     Int_t occDim = 2;
586     
587     while ( ( bp = static_cast<AliMpBusPatch*>(nextBP())) )
588     {
589       Int_t busPatchId = bp->GetId();
590       Int_t bin = hbp->FindBin(busPatchId);
591       hbp->SetBinContent(bin,data->BusPatch(busPatchId,occDim)*100.0); // occupancy, in percent
592     }
593     
594     BeautifyTrackerBusPatchOccupancy(*hbp);
595   }
596 }
597
598 //____________________________________________________________________________ 
599 void AliMUONQADataMakerRec::InitRaws()
600 {
601     /// create Raws histograms in Raws subdir
602         
603   AliCodeTimerAuto("");
604   
605   const Bool_t expert   = kTRUE ; 
606   const Bool_t saveCorr = kTRUE ; 
607   const Bool_t image    = kTRUE ; 
608  
609   TString boardName = "Local board Id";
610   
611   TString histoName, histoTitle;
612   for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
613     TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
614     for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
615       histoName = Form("hTriggerScalers%sChamber%i", cathName.Data(), 11+iChamber);
616       histoTitle = Form("Chamber %i - %s: trigger scaler counts", 11+iChamber, cathName.Data());
617       TH2F* h3 = new TH2F(histoName.Data(), histoTitle.Data(),
618                           234, 0.5, 234.5,
619                           16, -0.5, 15.5);
620       h3->GetXaxis()->SetTitle(boardName.Data());
621       h3->GetYaxis()->SetTitle("Strip");        
622       Add2RawsList(h3, kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber, expert, !image, !saveCorr);
623     }
624   }
625         
626         AliMUONTriggerDisplay triggerDisplay;
627         for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
628                 TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
629                 for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
630                         histoName = Form("hScalersDisplay%sChamber%i", cathName.Data(), 11+iChamber);
631                         histoTitle = Form("Chamber %i - %s: Hit rate from scalers (Hz/cm^{2})", 11+iChamber, cathName.Data());
632                         TH2F* h5 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplayStrips, 
633                                                                               iCath, iChamber, histoTitle);
634                         Add2RawsList(h5, kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, !expert, image, !saveCorr);
635                 }
636         }
637
638         FillTriggerDCSHistos();
639
640         TH1F* h10 = new TH1F("hTriggerScalersTime", "Acquisition time from trigger scalers", 1, 0.5, 1.5);
641         h10->GetXaxis()->SetBinLabel(1, "One-bin histogram: bin is filled at each scaler event.");
642         h10->GetYaxis()->SetTitle("Cumulated scaler time (s)");
643         Add2RawsList(h10, kTriggerScalersTime, !expert, !image, !saveCorr);
644         
645   Int_t bpmin(999999);
646   Int_t bpmax(0);
647   
648   TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
649   AliMpBusPatch* bp(0x0);
650   while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
651   {
652     bpmin = TMath::Min(bpmin,bp->GetId());
653     bpmax = TMath::Max(bpmax,bp->GetId());
654   }
655   
656   Double_t xmin = bpmin-0.5;
657   Double_t xmax = bpmax+0.5;
658   Int_t nbins = bpmax-bpmin+1;
659   
660   TH1* hbp = new TH1F("hTrackerBusPatchOccupancy","Occupancy of bus patches",nbins,xmin,xmax);
661
662   TH1* hbpnpads = new TH1F("hTrackerBusPatchNofPads","Number of pads per bus patch",nbins,xmin,xmax);
663
664   TH1* hbpnmanus = new TH1F("hTrackerBusPatchNofManus","Number of manus per bus patch",nbins,xmin,xmax);
665
666   Add2RawsList(hbp,kTrackerBusPatchOccupancy, !expert, image, !saveCorr);
667   Add2RawsList(hbpnpads,kTrackerBusPatchNofPads, expert, !image, !saveCorr);
668   Add2RawsList(hbpnmanus,kTrackerBusPatchNofManus, expert, !image, !saveCorr);
669
670   const Bool_t histogram(kFALSE);
671
672   if(!fTrackerDataMaker) 
673   {
674     fTrackerDataMaker = new AliMUONTrackerDataMaker(GetMUONRecoParam(),
675                                                     AliCDBManager::Instance()->GetRun(),
676                                                     0x0,
677                                                     "",
678                                                     "NOGAIN",
679                                                     histogram,
680                                                     0.0,0.0);
681   }
682   
683   fTrackerDataMaker->Data()->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level
684
685   fTrackerDataMaker->SetRunning(kTRUE);
686 }
687
688 //__________________________________________________________________
689 void AliMUONQADataMakerRec::InitDigits() 
690 {
691   /// Initialized Digits spectra 
692   const Bool_t expert   = kTRUE ; 
693   const Bool_t image    = kTRUE ; 
694   
695   TH1I* h0 = new TH1I("hDigitsDetElem", "Detection element distribution in Digits;Detection element Id;Counts",  1400, 100, 1500); 
696   Add2DigitsList(h0, 0, !expert, image);
697   
698   TH1I* h1 = new TH1I("hDigitsADC", "ADC distribution in Digits;ACD value;Counts", 4096, 0, 4095); 
699   Add2DigitsList(h1, 1, !expert, image);    
700
701
702 //____________________________________________________________________________ 
703 void AliMUONQADataMakerRec::InitRecPoints()
704 {
705         /// create Reconstructed Points histograms in RecPoints subdir
706   
707   AliCodeTimerAuto("");
708   
709         InitRecPointsTrigger();
710         InitRecPointsTracker();
711 }
712
713 //____________________________________________________________________________ 
714 void AliMUONQADataMakerRec::InitRecPointsTracker()
715 {
716   /// create Reconstructed Points histograms in RecPoints subdir for the
717   /// MUON tracker subsystem.
718   const Bool_t expert   = kTRUE ; 
719   const Bool_t image    = kTRUE ; 
720   
721   AliCodeTimerAuto("");
722   
723   TH1I *h1I;
724   TH1F *h1F;
725   TH2F *h2F;
726   
727   // histograms per chamber
728   Int_t nCh = AliMpConstants::NofTrackingChambers();
729   for ( Int_t i = 0; i < nCh; ++i ) 
730   {
731     h1I = new TH1I(Form("hTrackerClusterMultiplicityForChamber%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads};Counts)",i+1), 100,0,100);
732     Add2RecPointsList(h1I,kTrackerClusterMultiplicityPerChamber+i, expert, !image);
733     
734     h1I = new TH1I(Form("hTrackerClusterChargeForChamber%d",i+1), Form("cluster charge distribution in chamber %d;charge (fC);Counts",i+1), 100,0,1000);
735     Add2RecPointsList(h1I,kTrackerClusterChargePerChamber+i, expert, !image);
736     
737     Float_t rMax = AliMUONConstants::Rmax(i/2);
738     h2F = new TH2F(Form("hTrackerClusterHitMapForChamber%d",i+1), Form("cluster position distribution in chamber %d;X (cm);Y (cm)",i+1), 100, -rMax, rMax, 100, -rMax, rMax);
739     Add2RecPointsList(h2F, kTrackerClusterHitMapPerChamber+i, expert, !image);
740   }
741   
742   // summary histograms per chamber
743   h1I = new TH1I("hTrackerNumberOfClustersPerChamber", "Number of clusters per chamber;chamber ID;n_{clusters}", nCh,-0.5,nCh-0.5);
744   Add2RecPointsList(h1I,kTrackerNumberOfClustersPerChamber, !expert, image);
745   
746   h1F = new TH1F("hTrackerClusterMultiplicityPerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh,-0.5,nCh-0.5);
747   h1F->SetOption("P");
748   h1F->SetMarkerStyle(kFullDotMedium);
749   h1F->SetMarkerColor(kRed);
750   Add2RecPointsList(h1F, kTrackerClusterMultiplicityPerChMean, !expert, image);
751   
752   h1F = new TH1F("hTrackerClusterMultiplicityPerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh,-0.5,nCh-0.5);
753   h1F->SetOption("P");
754   h1F->SetMarkerStyle(kFullDotMedium);
755   h1F->SetMarkerColor(kRed);
756   Add2RecPointsList(h1F, kTrackerClusterMultiplicityPerChSigma, !expert, image);
757   
758   h1F = new TH1F("hTrackerClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (fC)", nCh,-0.5,nCh-0.5);
759   h1F->SetOption("P");
760   h1F->SetMarkerStyle(kFullDotMedium);
761   h1F->SetMarkerColor(kRed);
762   Add2RecPointsList(h1F, kTrackerClusterChargePerChMean, !expert, image);
763   
764   h1F = new TH1F("hTrackerClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (fC)", nCh,-0.5,nCh-0.5);
765   h1F->SetOption("P");
766   h1F->SetMarkerStyle(kFullDotMedium);
767   h1F->SetMarkerColor(kRed);
768   Add2RecPointsList(h1F, kTrackerClusterChargePerChSigma, !expert, image);
769   
770   // histograms per DE
771   Int_t ndes(0);
772   AliMpDEIterator it;
773   it.First();
774   while ( !it.IsDone())
775   {
776     Int_t detElemId = it.CurrentDEId();
777     
778     if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger )
779     {
780       ndes = TMath::Max(ndes,detElemId);
781       
782       h1I = new TH1I(Form("hTrackerClusterMultiplicityForDE%04d",detElemId), Form("cluster size distribution in detection element %d;size (n_{pads})",detElemId), 100,0,100);
783       Add2RecPointsList(h1I,kTrackerClusterMultiplicityPerDE+detElemId, expert, !image);
784       
785       h1I = new TH1I(Form("hTrackerClusterChargeForDE%04d",detElemId), Form("cluster charge distribution in detection element %d;charge (fC)",detElemId), 100,0,1000);
786       Add2RecPointsList(h1I,kTrackerClusterChargePerDE+detElemId, expert, !image);
787     }
788     
789     it.Next();
790   }
791   
792   // summary histograms per DE
793   h1I = new TH1I("hTrackerNumberOfClustersPerDE", "Number of clusters per detection element;DetElem ID;n_{clusters}", ndes+1,-0.5,ndes+0.5);
794   Add2RecPointsList(h1I, kTrackerNumberOfClustersPerDE, !expert, image);
795   
796   h1F = new TH1F("hTrackerClusterMultiplicityPerDEMean", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", ndes+1,-0.5,ndes+0.5);
797   h1F->SetOption("P");
798   h1F->SetMarkerStyle(kFullDotMedium);
799   h1F->SetMarkerColor(kRed);
800   Add2RecPointsList(h1F, kTrackerClusterMultiplicityPerDEMean, !expert, image);
801   
802   h1F = new TH1F("hTrackerClusterChargePerDEMean", "cluster mean charge per DE;DetElem ID;<charge> (fC)", ndes+1,-0.5,ndes+0.5);
803   h1F->SetOption("P");
804   h1F->SetMarkerStyle(kFullDotMedium);
805   h1F->SetMarkerColor(kRed);
806   Add2RecPointsList(h1F, kTrackerClusterChargePerDEMean, !expert, image);
807   
808   if (!fMappingCheckRecPoints) fMappingCheckRecPoints = new AliMUONQAMappingCheck(fRun);  
809 }
810
811 //____________________________________________________________________________ 
812 void AliMUONQADataMakerRec::InitRecPointsTrigger()
813 {
814         /// create Reconstructed Points histograms in RecPoints subdir for the
815         /// MUON Trigger subsystem.
816         
817   const Bool_t expert   = kTRUE ; 
818   const Bool_t image    = kTRUE ; 
819
820   TString boardName = "Local board Id";
821
822   TString histoName, histoTitle;
823   for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
824     TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
825     for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
826       histoName = Form("hTriggerDigits%sChamber%i", cathName.Data(), 11+iChamber);
827       histoTitle = Form("Chamber %i - %s: counts per strip", 11+iChamber, cathName.Data());
828       TH2F* h0 = new TH2F(histoName.Data(), histoTitle.Data(),
829                           234, 0.5, 234.5,
830                           16, -0.5, 15.5);
831       h0->GetXaxis()->SetTitle(boardName.Data());
832       h0->GetYaxis()->SetTitle("Strip");
833       Add2RecPointsList(h0, kTriggerDigits + AliMpConstants::NofTriggerChambers()*iCath + iChamber, expert, !image);
834     }
835   }
836
837     TH1F* h2 = new TH1F("hTriggeredBoards", "Triggered boards", 234, 0.5, 234.5);
838     Add2RecPointsList(h2, kTriggeredBoards, expert, !image);
839
840     AliMUONTriggerDisplay triggerDisplay;
841     for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
842       TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
843       for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
844         histoName = Form("hTriggerDigitsDisplay%sChamber%i", cathName.Data(), 11+iChamber);
845         histoTitle = Form("Chamber %i - %s: Occupancy per strip (counts/event)", 11+iChamber, cathName.Data());
846         TH2F* h3 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplayStrips, 
847                                                               iCath, iChamber, histoTitle);
848         Add2RecPointsList(h3, kTriggerDigitsDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, !expert, image);
849       }
850     }
851
852     TH2F* h4 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto("hFiredBoardsDisplay", AliMUONTriggerDisplay::kDisplayBoards,
853                                                           0, 0, "Local board triggers / event");
854     Add2RecPointsList(h4, kTriggerBoardsDisplay, !expert, image);
855
856     TH1F* h5 = new TH1F("hNAnalyzedEvents", "Number of analyzed events per specie", 1, 0.5, 1.5);
857     Int_t esindex = AliRecoParam::AConvert(fEventSpecie);
858     h5->GetXaxis()->SetBinLabel(1, AliRecoParam::GetEventSpecieName(esindex));
859     h5->GetYaxis()->SetTitle("Number of analyzed events");
860     Add2RecPointsList(h5, kNAnalyzedEvents, !expert, image);
861 }
862
863
864 //____________________________________________________________________________ 
865 void AliMUONQADataMakerRec::InitESDs()
866 {
867   ///create ESDs histograms in ESDs subdir
868   
869   const Bool_t expert   = kTRUE ; 
870   const Bool_t image    = kTRUE ; 
871   
872   Int_t nCh = AliMUONConstants::NTrackingCh();
873   Int_t nDE = 1100;
874   
875   // track info
876   TH1F* hESDnTracks = new TH1F("hESDnTracks", "number of tracks;n_{tracks}", 20, 0., 20.);
877   Add2ESDsList(hESDnTracks, kESDnTracks, !expert, image);
878
879   TH1F* hESDMatchTrig = new TH1F("hESDMatchTrig", "number of tracks matched with trigger;n_{tracks}", 20, 0., 20.);
880   Add2ESDsList(hESDMatchTrig, kESDMatchTrig, !expert, image);
881   
882   TH1F* hESDMomentum = new TH1F("hESDMomentum", "momentum distribution;p (GeV/c)", 300, 0., 300);
883   Add2ESDsList(hESDMomentum, kESDMomentum, !expert, image);
884
885   TH1F* hESDPt = new TH1F("hESDPt", "transverse momentum distribution;p_{t} (GeV/c)", 200, 0., 50);
886   Add2ESDsList(hESDPt, kESDPt, !expert, image);
887
888   TH1F* hESDRapidity = new TH1F("hESDRapidity", "rapidity distribution;rapidity", 200, -4.5, -2.);
889   Add2ESDsList(hESDRapidity, kESDRapidity, !expert, image);
890
891   TH1F* hESDChi2 = new TH1F("hESDChi2", "normalized #chi^{2} distribution;#chi^{2} / ndf", 500, 0., 50.);
892   Add2ESDsList(hESDChi2, kESDChi2, !expert, image);
893   
894   TH1F* hESDProbChi2 = new TH1F("hESDProbChi2", "distribution of probability of #chi^{2};prob(#chi^{2})", 100, 0., 1.);
895   Add2ESDsList(hESDProbChi2, kESDProbChi2, !expert, image);
896   
897   TH1F* hESDThetaX = new TH1F("hESDThetaX", "#theta_{X} distribution;#theta_{X} (degree)", 360, -180., 180);
898   Add2ESDsList(hESDThetaX, kESDThetaX, !expert, image);
899   
900   TH1F* hESDThetaY = new TH1F("hESDThetaY", "#theta_{Y} distribution;#theta_{Y} (degree)", 360, -180., 180);
901   Add2ESDsList(hESDThetaY, kESDThetaY, !expert, image);
902   
903   // cluster info
904   for (Int_t i = 0; i < nCh; i++) {
905     Float_t rMax = AliMUONConstants::Rmax(i/2);
906     TH2F* hESDClusterHitMap = new TH2F(Form("hESDClusterHitMap%d",i+1), Form("cluster position distribution in chamber %d;X (cm);Y (cm)",i+1),
907                                        100, -rMax, rMax, 100, -rMax, rMax);
908     Add2ESDsList(hESDClusterHitMap, kESDClusterHitMap+i, expert, !image);
909   }
910   
911   TH1F* hESDnClustersPerTrack = new TH1F("hESDnClustersPerTrack", "number of associated clusters per track;n_{clusters}", 20, 0., 20.);
912   Add2ESDsList(hESDnClustersPerTrack, kESDnClustersPerTrack, !expert, image);
913   
914   TH1F* hESDnClustersPerCh = new TH1F("hESDnClustersPerCh", "averaged number of clusters per chamber per track;chamber ID;<n_{clusters}>", nCh, -0.5, nCh-0.5);
915   hESDnClustersPerCh->SetFillColor(kRed);
916   Add2ESDsList(hESDnClustersPerCh, kESDnClustersPerCh, !expert, image);
917   
918   TH1F* hESDnClustersPerDE = new TH1F("hESDnClustersPerDE", "averaged number of clusters per DE per track;DetElem ID;<n_{clusters}>", nDE+1, -0.5, nDE+0.5);
919   hESDnClustersPerDE->SetFillColor(kRed);
920   Add2ESDsList(hESDnClustersPerDE, kESDnClustersPerDE, !expert, image);
921   
922   for (Int_t i = 0; i < nCh; i++) {
923     TH1F* hESDClusterChargeInCh = new TH1F(Form("hESDClusterChargeInCh%d",i+1), Form("cluster charge distribution in chamber %d;charge (fC)",i+1), 100, 0., 1000.);
924     Add2ESDsList(hESDClusterChargeInCh, kESDClusterChargeInCh+i, expert, !image);
925   }
926   
927   TH1F* hESDClusterChargePerChMean = new TH1F("hESDClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (fC)", nCh, -0.5, nCh-0.5);
928   hESDClusterChargePerChMean->SetOption("P");
929   hESDClusterChargePerChMean->SetMarkerStyle(kFullDotMedium);
930   hESDClusterChargePerChMean->SetMarkerColor(kRed);
931   Add2ESDsList(hESDClusterChargePerChMean, kESDClusterChargePerChMean, !expert, image);
932   
933   TH1F* hESDClusterChargePerChSigma = new TH1F("hESDClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (fC)", nCh, -0.5, nCh-0.5);
934   hESDClusterChargePerChSigma->SetOption("P");
935   hESDClusterChargePerChSigma->SetMarkerStyle(kFullDotMedium);
936   hESDClusterChargePerChSigma->SetMarkerColor(kRed);
937   Add2ESDsList(hESDClusterChargePerChSigma, kESDClusterChargePerChSigma, !expert, image);
938   
939   TH1F* hESDClusterChargePerDE = new TH1F("hESDClusterChargePerDE", "cluster mean charge per DE;DetElem ID;<charge> (fC)", nDE+1, -0.5, nDE+0.5);
940   hESDClusterChargePerDE->SetOption("P");
941   hESDClusterChargePerDE->SetMarkerStyle(kFullDotMedium);
942   hESDClusterChargePerDE->SetMarkerColor(kRed);
943   Add2ESDsList(hESDClusterChargePerDE, kESDClusterChargePerDE, !expert, image);
944   
945   for (Int_t i = 0; i < nCh; i++) {
946     TH1F* hESDClusterSizeInCh = new TH1F(Form("hESDClusterSizeInCh%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads})",i+1), 200, 0., 200.);
947     Add2ESDsList(hESDClusterSizeInCh, kESDClusterSizeInCh+i, expert, !image);
948   }
949   
950   TH1F* hESDClusterSizePerChMean = new TH1F("hESDClusterSizePerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh, -0.5, nCh-0.5);
951   hESDClusterSizePerChMean->SetOption("P");
952   hESDClusterSizePerChMean->SetMarkerStyle(kFullDotMedium);
953   hESDClusterSizePerChMean->SetMarkerColor(kRed);
954   Add2ESDsList(hESDClusterSizePerChMean, kESDClusterSizePerChMean, !expert, image);
955   
956   TH1F* hESDClusterSizePerChSigma = new TH1F("hESDClusterSizePerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh, -0.5, nCh-0.5);
957   hESDClusterSizePerChSigma->SetOption("P");
958   hESDClusterSizePerChSigma->SetMarkerStyle(kFullDotMedium);
959   hESDClusterSizePerChSigma->SetMarkerColor(kRed);
960   Add2ESDsList(hESDClusterSizePerChSigma, kESDClusterSizePerChSigma, !expert, image);
961   
962   TH1F* hESDClusterSizePerDE = new TH1F("hESDClusterSizePerDE", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", nDE+1, -0.5, nDE+0.5);
963   hESDClusterSizePerDE->SetOption("P");
964   hESDClusterSizePerDE->SetMarkerStyle(kFullDotMedium);
965   hESDClusterSizePerDE->SetMarkerColor(kRed);
966   Add2ESDsList(hESDClusterSizePerDE, kESDClusterSizePerDE, !expert, image);
967   
968   // cluster - track info
969   for (Int_t i = 0; i < nCh; i++) {
970     TH1F* hESDResidualXInCh = new TH1F(Form("hESDResidualXInCh%d",i+1), Form("cluster-track residual-X distribution in chamber %d;#Delta_{X} (cm)",i+1), 1000, -5., 5.);
971     Add2ESDsList(hESDResidualXInCh, kESDResidualXInCh+i, expert, !image);
972     
973     TH1F* hESDResidualYInCh = new TH1F(Form("hESDResidualYInCh%d",i+1), Form("cluster-track residual-Y distribution in chamber %d;#Delta_{Y} (cm)",i+1), 1000, -1., 1.);
974     Add2ESDsList(hESDResidualYInCh, kESDResidualYInCh+i, expert, !image);
975     
976     TH1F* hESDLocalChi2XInCh = new TH1F(Form("hESDLocalChi2XInCh%d",i+1), Form("local chi2-X distribution in chamber %d;local #chi^{2}_{X}",i+1), 1000, 0., 25);
977     Add2ESDsList(hESDLocalChi2XInCh, kESDLocalChi2XInCh+i, expert, !image);
978     
979     TH1F* hESDLocalChi2YInCh = new TH1F(Form("hESDLocalChi2YInCh%d",i+1), Form("local chi2-Y distribution in chamber %d;local #chi^{2}_{Y}",i+1), 1000, 0., 25);
980     Add2ESDsList(hESDLocalChi2YInCh, kESDLocalChi2YInCh+i, expert, !image);
981     
982     TH1F* hESDLocalChi2InCh = new TH1F(Form("hESDLocalChi2InCh%d",i+1), Form("local chi2 (~0.5*(#chi^{2}_{X}+#chi^{2}_{Y})) distribution in chamber %d;local #chi^{2}",i+1), 1000, 0., 25);
983     Add2ESDsList(hESDLocalChi2InCh, kESDLocalChi2InCh+i, expert, !image);
984   }
985   
986   TH1F* hESDResidualXPerChMean = new TH1F("hESDResidualXPerChMean", "cluster-track residual-X per Ch: mean;chamber ID;<#Delta_{X}> (cm)", nCh, -0.5, nCh-0.5);
987   hESDResidualXPerChMean->SetOption("P");
988   hESDResidualXPerChMean->SetMarkerStyle(kFullDotMedium);
989   hESDResidualXPerChMean->SetMarkerColor(kRed);
990   Add2ESDsList(hESDResidualXPerChMean, kESDResidualXPerChMean, !expert, image);
991   
992   TH1F* hESDResidualYPerChMean = new TH1F("hESDResidualYPerChMean", "cluster-track residual-Y per Ch: mean;chamber ID;<#Delta_{Y}> (cm)", nCh, -0.5, nCh-0.5);
993   hESDResidualYPerChMean->SetOption("P");
994   hESDResidualYPerChMean->SetMarkerStyle(kFullDotMedium);
995   hESDResidualYPerChMean->SetMarkerColor(kRed);
996   Add2ESDsList(hESDResidualYPerChMean, kESDResidualYPerChMean, !expert, image);
997   
998   TH1F* hESDResidualXPerChSigma = new TH1F("hESDResidualXPerChSigma", "cluster-track residual-X per Ch: sigma;chamber ID;#sigma_{X} (cm)", nCh, -0.5, nCh-0.5);
999   hESDResidualXPerChSigma->SetOption("P");
1000   hESDResidualXPerChSigma->SetMarkerStyle(kFullDotMedium);
1001   hESDResidualXPerChSigma->SetMarkerColor(kRed);
1002   Add2ESDsList(hESDResidualXPerChSigma, kESDResidualXPerChSigma, !expert, image);
1003   
1004   TH1F* hESDResidualYPerChSigma = new TH1F("hESDResidualYPerChSigma", "cluster-track residual-Y per Ch: sigma;chamber ID;#sigma_{Y} (cm)", nCh, -0.5, nCh-0.5);
1005   hESDResidualYPerChSigma->SetOption("P");
1006   hESDResidualYPerChSigma->SetMarkerStyle(kFullDotMedium);
1007   hESDResidualYPerChSigma->SetMarkerColor(kRed);
1008   Add2ESDsList(hESDResidualYPerChSigma, kESDResidualYPerChSigma, !expert, image);
1009   
1010   TH1F* hESDLocalChi2XPerChMean = new TH1F("hESDLocalChi2XPerCh", "local chi2-X per Ch: mean;chamber ID;<local #chi^{2}_{X}>", nCh, -0.5, nCh-0.5);
1011   hESDLocalChi2XPerChMean->SetOption("P");
1012   hESDLocalChi2XPerChMean->SetMarkerStyle(kFullDotMedium);
1013   hESDLocalChi2XPerChMean->SetMarkerColor(kRed);
1014   Add2ESDsList(hESDLocalChi2XPerChMean, kESDLocalChi2XPerChMean, !expert, image);
1015   
1016   TH1F* hESDLocalChi2YPerChMean = new TH1F("hESDLocalChi2YPerCh", "local chi2-Y per Ch: mean;chamber ID;<local #chi^{2}_{Y}>", nCh, -0.5, nCh-0.5);
1017   hESDLocalChi2YPerChMean->SetOption("P");
1018   hESDLocalChi2YPerChMean->SetMarkerStyle(kFullDotMedium);
1019   hESDLocalChi2YPerChMean->SetMarkerColor(kRed);
1020   Add2ESDsList(hESDLocalChi2YPerChMean, kESDLocalChi2YPerChMean, !expert, image);
1021   
1022   TH1F* hESDLocalChi2PerChMean = new TH1F("hESDLocalChi2PerCh", "local chi2 (~0.5*(#chi^{2}_{X}+#chi^{2}_{Y})) per Ch: mean;chamber ID;<local #chi^{2}>", nCh, -0.5, nCh-0.5);
1023   hESDLocalChi2PerChMean->SetOption("P");
1024   hESDLocalChi2PerChMean->SetMarkerStyle(kFullDotMedium);
1025   hESDLocalChi2PerChMean->SetMarkerColor(kRed);
1026   Add2ESDsList(hESDLocalChi2PerChMean, kESDLocalChi2PerChMean, !expert, image);
1027   
1028   TH1F* hESDResidualXPerDEMean = new TH1F("hESDResidualXPerDEMean", "cluster-track residual-X per DE: mean;DetElem ID;<#Delta_{X}> (cm)", nDE+1, -0.5, nDE+0.5);
1029   hESDResidualXPerDEMean->SetOption("P");
1030   hESDResidualXPerDEMean->SetMarkerStyle(kFullDotMedium);
1031   hESDResidualXPerDEMean->SetMarkerColor(kRed);
1032   Add2ESDsList(hESDResidualXPerDEMean, kESDResidualXPerDEMean, !expert, image);
1033   
1034   TH1F* hESDResidualYPerDEMean = new TH1F("hESDResidualYPerDEMean", "cluster-track residual-Y per DE: mean;DetElem ID;<#Delta_{Y}> (cm)", nDE+1, -0.5, nDE+0.5);
1035   hESDResidualYPerDEMean->SetOption("P");
1036   hESDResidualYPerDEMean->SetMarkerStyle(kFullDotMedium);
1037   hESDResidualYPerDEMean->SetMarkerColor(kRed);
1038   Add2ESDsList(hESDResidualYPerDEMean, kESDResidualYPerDEMean, !expert, image);
1039   
1040   TH1F* hESDResidualXPerDESigma = new TH1F("hESDResidualXPerDESigma", "cluster-track residual-X per DE: sigma;DetElem ID;#sigma_{X} (cm)", nDE+1, -0.5, nDE+0.5);
1041   hESDResidualXPerDESigma->SetOption("P");
1042   hESDResidualXPerDESigma->SetMarkerStyle(kFullDotMedium);
1043   hESDResidualXPerDESigma->SetMarkerColor(kRed);
1044   Add2ESDsList(hESDResidualXPerDESigma, kESDResidualXPerDESigma, !expert, image);
1045   
1046   TH1F* hESDResidualYPerDESigma = new TH1F("hESDResidualYPerDESigma", "cluster-track residual-Y per DE: sigma;DetElem ID;#sigma_{Y} (cm)", nDE+1, -0.5, nDE+0.5);
1047   hESDResidualYPerDESigma->SetOption("P");
1048   hESDResidualYPerDESigma->SetMarkerStyle(kFullDotMedium);
1049   hESDResidualYPerDESigma->SetMarkerColor(kRed);
1050   Add2ESDsList(hESDResidualYPerDESigma, kESDResidualYPerDESigma, !expert, image);
1051   
1052   TH1F* hESDLocalChi2XPerDEMean = new TH1F("hESDLocalChi2XPerDE", "local chi2-X per DE: mean;DetElem ID;<local #chi^{2}_{X}>", nDE+1, -0.5, nDE+0.5);
1053   hESDLocalChi2XPerDEMean->SetOption("P");
1054   hESDLocalChi2XPerDEMean->SetMarkerStyle(kFullDotMedium);
1055   hESDLocalChi2XPerDEMean->SetMarkerColor(kRed);
1056   Add2ESDsList(hESDLocalChi2XPerDEMean, kESDLocalChi2XPerDEMean, !expert, image);
1057   
1058   TH1F* hESDLocalChi2YPerDEMean = new TH1F("hESDLocalChi2YPerDE", "local chi2-Y per DE: mean;DetElem ID;<local #chi^{2}_{Y}>", nDE+1, -0.5, nDE+0.5);
1059   hESDLocalChi2YPerDEMean->SetOption("P");
1060   hESDLocalChi2YPerDEMean->SetMarkerStyle(kFullDotMedium);
1061   hESDLocalChi2YPerDEMean->SetMarkerColor(kRed);
1062   Add2ESDsList(hESDLocalChi2YPerDEMean, kESDLocalChi2YPerDEMean, !expert, image);
1063   
1064   TH1F* hESDLocalChi2PerDEMean = new TH1F("hESDLocalChi2PerDE", "local chi2 (~0.5*(#chi^{2}_{X}+#chi^{2}_{Y})) per DE: mean;DetElem ID;<local #chi^{2}>", nDE+1, -0.5, nDE+0.5);
1065   hESDLocalChi2PerDEMean->SetOption("P");
1066   hESDLocalChi2PerDEMean->SetMarkerStyle(kFullDotMedium);
1067   hESDLocalChi2PerDEMean->SetMarkerColor(kRed);
1068   Add2ESDsList(hESDLocalChi2PerDEMean, kESDLocalChi2PerDEMean, !expert, image);
1069   
1070   // intermediate histograms
1071   TH1F* hESDnTotClustersPerCh = new TH1F("hESDnTotClustersPerCh", "total number of associated clusters per chamber;chamber ID;#Sigma(n_{clusters})", nCh, -0.5, nCh-0.5);
1072   Add2ESDsList(hESDnTotClustersPerCh, kESDnTotClustersPerCh, expert, !image);
1073   TH1F* hESDnTotClustersPerDE = new TH1F("hESDnTotClustersPerDE", "total number of associated clusters per DE;DetElem ID;#Sigma(n_{clusters})", nDE+1, -0.5, nDE+0.5);
1074   Add2ESDsList(hESDnTotClustersPerDE, kESDnTotClustersPerDE, expert, !image);
1075   TH1F* hESDnTotFullClustersPerDE = new TH1F("hESDnTotFullClustersPerDE", "total number of associated clusters containing pad info per DE;DetElem ID;#Sigma(n_{full clusters})", nDE+1, -0.5, nDE+0.5);
1076   Add2ESDsList(hESDnTotFullClustersPerDE, kESDnTotFullClustersPerDE, expert, !image);
1077   TH1F* hESDSumClusterChargePerDE = new TH1F("hESDSumClusterChargePerDE", "sum of cluster charge per DE;DetElem ID;#Sigma(charge) (fC)", nDE+1, -0.5, nDE+0.5);
1078   Add2ESDsList(hESDSumClusterChargePerDE, kESDSumClusterChargePerDE, expert, !image);
1079   TH1F* hESDSumClusterSizePerDE = new TH1F("hESDSumClusterSizePerDE", "sum of cluster size per DE;DetElem ID;#Sigma(size) (n_{pads})", nDE+1, -0.5, nDE+0.5);
1080   Add2ESDsList(hESDSumClusterSizePerDE, kESDSumClusterSizePerDE, expert, !image);
1081   TH1F* hESDSumResidualXPerDE = new TH1F("hESDSumResidualXPerDE", "sum of cluster-track residual-X per DE;DetElem ID;#Sigma(#Delta_{X}) (cm)", nDE+1, -0.5, nDE+0.5);
1082   Add2ESDsList(hESDSumResidualXPerDE, kESDSumResidualXPerDE, expert, !image);
1083   TH1F* hESDSumResidualYPerDE = new TH1F("hESDSumResidualYPerDE", "sum of cluster-track residual-Y per DE;DetElem ID;#Sigma(#Delta_{Y}) (cm)", nDE+1, -0.5, nDE+0.5);
1084   Add2ESDsList(hESDSumResidualYPerDE, kESDSumResidualYPerDE, expert, !image);
1085   TH1F* hESDSumResidualX2PerDE = new TH1F("hESDSumResidualX2PerDE", "sum of cluster-track residual-X**2 per DE;DetElem ID;#Sigma(#Delta_{X}^{2}) (cm^{2})", nDE+1, -0.5, nDE+0.5);
1086   Add2ESDsList(hESDSumResidualX2PerDE, kESDSumResidualX2PerDE, expert, !image);
1087   TH1F* hESDSumResidualY2PerDE = new TH1F("hESDSumResidualY2PerDE", "sum of cluster-track residual-Y**2 per DE;DetElem ID;#Sigma(#Delta_{Y}^{2}) (cm^{2})", nDE+1, -0.5, nDE+0.5);
1088   Add2ESDsList(hESDSumResidualY2PerDE, kESDSumResidualY2PerDE, expert, !image);
1089   TH1F* hESDSumLocalChi2XPerDE = new TH1F("hESDSumLocalChi2XPerDE", "sum of local chi2-X per DE;DetElem ID;#Sigma(local #chi^{2}_{X})", nDE+1, -0.5, nDE+0.5);
1090   Add2ESDsList(hESDSumLocalChi2XPerDE, kESDSumLocalChi2XPerDE, expert, !image);
1091   TH1F* hESDSumLocalChi2YPerDE = new TH1F("hESDSumLocalChi2YPerDE", "sum of local chi2-Y per DE;DetElem ID;#Sigma(local #chi^{2}_{Y})", nDE+1, -0.5, nDE+0.5);
1092   Add2ESDsList(hESDSumLocalChi2YPerDE, kESDSumLocalChi2YPerDE, expert, !image);
1093   TH1F* hESDSumLocalChi2PerDE = new TH1F("hESDSumLocalChi2PerDE", "sum of local chi2 (~0.5*(#chi^{2}_{X}+#chi^{2}_{Y})) per DE;DetElem ID;#Sigma(local #chi^{2})", nDE+1, -0.5, nDE+0.5);
1094   Add2ESDsList(hESDSumLocalChi2PerDE, kESDSumLocalChi2PerDE, expert, !image);
1095 }
1096
1097 //____________________________________________________________________________
1098 void AliMUONQADataMakerRec::MakeRaws(AliRawReader* rawReader)
1099 {
1100     /// make QA for rawdata
1101
1102     // Check id histograms already created for this Event Specie
1103
1104   AliDebug(AliQAv1::GetQADebugLevel(),
1105            Form("RAW event type %s", AliRawEventHeaderBase::GetTypeName(rawReader->GetType())));
1106   
1107   if ( rawReader->GetType() == AliRawEventHeaderBase::kPhysicsEvent ) 
1108   {
1109     rawReader->Reset();
1110     MakeRawsTracker(rawReader);
1111   }
1112   
1113   if ( rawReader->GetType() == AliRawEventHeaderBase::kPhysicsEvent ||
1114        rawReader->GetType() == AliRawEventHeaderBase::kCalibrationEvent ) 
1115   {
1116     rawReader->Reset();    
1117     MakeRawsTrigger(rawReader);
1118   }
1119 }
1120
1121 //____________________________________________________________________________
1122 void AliMUONQADataMakerRec::MakeRawsTracker(AliRawReader* rawReader)
1123 {
1124         /// make QA for rawdata tracker
1125         
1126   /// forces init
1127   GetRawsData(kTrackerBusPatchOccupancy);
1128   
1129         ((AliMUONTrackerDataMaker*)fTrackerDataMaker)->SetRawReader(rawReader);
1130         
1131         fTrackerDataMaker->ProcessEvent();
1132 }
1133
1134 //____________________________________________________________________________
1135 void AliMUONQADataMakerRec::MakeRawsTrigger(AliRawReader* rawReader)
1136 {
1137         /// make QA for rawdata trigger
1138         
1139     // Get trigger scalers
1140
1141     Int_t loCircuit=0;
1142     AliMpCDB::LoadDDLStore();
1143
1144     AliMUONRawStreamTrigger rawStreamTrig(rawReader);
1145     while (rawStreamTrig.NextDDL()) 
1146     {
1147       // If not a scaler event, do nothing
1148       Bool_t scalerEvent =  rawReader->GetDataHeader()->GetL1TriggerMessage() & 0x1;
1149       if ( !scalerEvent ) continue;
1150
1151       AliDebug(AliQAv1::GetQADebugLevel(),"Filling trigger scalers");
1152
1153       AliMUONDDLTrigger* ddlTrigger = rawStreamTrig.GetDDLTrigger();
1154       AliMUONDarcHeader* darcHeader = ddlTrigger->GetDarcHeader();
1155
1156       if (darcHeader->GetGlobalFlag()){
1157         UInt_t nOfClocks = darcHeader->GetGlobalClock();
1158         Double_t nOfSeconds = ((Double_t) nOfClocks) / 40e6; // 1 clock each 25 ns
1159         ((TH1F*)GetRawsData(kTriggerScalersTime))->Fill(1., nOfSeconds);
1160       }
1161
1162       Int_t nReg = darcHeader->GetRegHeaderEntries();
1163     
1164       for(Int_t iReg = 0; iReg < nReg ;iReg++)
1165       {   //reg loop
1166
1167         // crate info  
1168         AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
1169           GetTriggerCrate(rawStreamTrig.GetDDL(), iReg);
1170
1171         AliMUONRegHeader* regHeader =  darcHeader->GetRegHeaderEntry(iReg);
1172
1173         // loop over local structures
1174         Int_t nLocal = regHeader->GetLocalEntries();
1175         for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
1176         {
1177           AliMUONLocalStruct* localStruct = regHeader->GetLocalEntry(iLocal);
1178         
1179           // if card exist
1180           if (!localStruct) continue;
1181           
1182           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
1183
1184           if ( !loCircuit ) continue; // empty slot
1185
1186           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
1187
1188           // skip copy cards
1189           if( !localBoard->IsNotified()) 
1190             continue;
1191
1192           Int_t cathode = localStruct->GetComptXY()%2;
1193
1194           // loop over strips
1195           for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
1196             if(localStruct->GetXY1(ibitxy) > 0)
1197               ((TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*cathode + 0))
1198                 ->Fill(loCircuit, ibitxy, 2*localStruct->GetXY1(ibitxy));
1199             if(localStruct->GetXY2(ibitxy) > 0)
1200               ((TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*cathode + 1))
1201                 ->Fill(loCircuit, ibitxy, 2*localStruct->GetXY2(ibitxy));
1202             if(localStruct->GetXY3(ibitxy) > 0)
1203               ((TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*cathode + 2))
1204                 ->Fill(loCircuit, ibitxy, 2*localStruct->GetXY3(ibitxy));
1205             if(localStruct->GetXY4(ibitxy) > 0)
1206               ((TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*cathode + 3))
1207                 ->Fill(loCircuit, ibitxy, 2*localStruct->GetXY4(ibitxy));
1208           } // loop on strips
1209         } // iLocal
1210       } // iReg
1211     } // NextDDL
1212 }
1213
1214 //__________________________________________________________________
1215 void AliMUONQADataMakerRec::MakeDigits(TTree* digitsTree)         
1216 {
1217   /// makes data from Digits
1218
1219   // Do nothing in case of calibration event
1220   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
1221
1222   if (!fDigitStore)
1223     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
1224   fDigitStore->Connect(*digitsTree, false);
1225   digitsTree->GetEvent(0);
1226   
1227   TIter next(fDigitStore->CreateIterator());
1228   
1229   AliMUONVDigit* dig = 0x0;
1230   
1231   while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) )
1232     {
1233     GetDigitsData(0)->Fill(dig->DetElemId());
1234     GetDigitsData(1)->Fill(dig->ADC());
1235     }
1236 }
1237
1238 //____________________________________________________________________________
1239 void AliMUONQADataMakerRec::MakeRecPoints(TTree* clustersTree)
1240 {
1241         /// Fill histograms from treeR
1242
1243   // Do nothing in case of calibration event
1244   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
1245         
1246   GetRecPointsData(kNAnalyzedEvents)->Fill(1.);
1247
1248   MakeRecPointsTracker(clustersTree);
1249         MakeRecPointsTrigger(clustersTree);
1250 }
1251
1252
1253
1254 //____________________________________________________________________________
1255 void AliMUONQADataMakerRec::MakeRecPointsTracker(TTree* clustersTree)
1256 {
1257         /// Fill histograms related to tracker clusters 
1258         
1259         // First things first : do we have clusters in the TreeR ?
1260         // In "normal" production mode, it should be perfectly normal
1261         // *not* to have them.
1262         // But if for some reason we de-activated the combined tracking,
1263         // then we have clusters in TreeR, so let's take that opportunity
1264         // to QA them...
1265         
1266   AliCodeTimerAuto("");
1267
1268   // Do nothing in case of calibration event
1269   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
1270
1271         if (!fClusterStore)
1272         {
1273                 AliCodeTimerAuto("ClusterStore creation");
1274                 fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
1275                 if (!fClusterStore) 
1276                 {
1277                         return;
1278                 }
1279         }
1280         
1281         fClusterStore->Connect(*clustersTree,kFALSE);
1282         clustersTree->GetEvent(0);
1283
1284         TIter next(fClusterStore->CreateIterator());
1285         AliMUONVCluster* cluster;
1286         
1287   if ( fMappingCheckRecPoints ) fMappingCheckRecPoints->NewEvent();
1288   
1289         while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) )
1290         {
1291                 Int_t detElemId = cluster->GetDetElemId();
1292                 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
1293                 
1294                 GetRecPointsData(kTrackerNumberOfClustersPerDE)->Fill(detElemId);
1295                 GetRecPointsData(kTrackerClusterChargePerDE+detElemId)->Fill(cluster->GetCharge());
1296                 GetRecPointsData(kTrackerClusterMultiplicityPerDE+detElemId)->Fill(cluster->GetNDigits());
1297
1298                 GetRecPointsData(kTrackerNumberOfClustersPerChamber)->Fill(chamberId);
1299                 GetRecPointsData(kTrackerClusterChargePerChamber+chamberId)->Fill(cluster->GetCharge());
1300                 GetRecPointsData(kTrackerClusterMultiplicityPerChamber+chamberId)->Fill(cluster->GetNDigits());
1301                 GetRecPointsData(kTrackerClusterHitMapPerChamber+chamberId)->Fill(cluster->GetX(),cluster->GetY());
1302                 
1303     if ( fMappingCheckRecPoints ) fMappingCheckRecPoints->Store(*cluster);
1304     
1305         }
1306         
1307         fClusterStore->Clear();
1308 }
1309
1310 //____________________________________________________________________________
1311 void AliMUONQADataMakerRec::MakeRecPointsTrigger(TTree* clustersTree)
1312 {
1313         /// makes data from trigger response
1314
1315   AliCodeTimerAuto("");
1316
1317     // Fired pads info
1318     fDigitStore->Clear();
1319
1320     if (!fTriggerStore) fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
1321     fTriggerStore->Clear();
1322     fTriggerStore->Connect(*clustersTree, false);
1323     clustersTree->GetEvent(0);
1324
1325     AliMUONLocalTrigger* locTrg;
1326     TIter nextLoc(fTriggerStore->CreateLocalIterator());
1327
1328     while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(nextLoc()) ) ) 
1329     {
1330       if (locTrg->IsNull()) continue;
1331    
1332       TArrayS xyPattern[2];
1333       locTrg->GetXPattern(xyPattern[0]);
1334       locTrg->GetYPattern(xyPattern[1]);
1335
1336       Int_t nBoard = locTrg->LoCircuit();
1337
1338       Bool_t xTrig=locTrg->IsTrigX();
1339       Bool_t yTrig=locTrg->IsTrigY();
1340     
1341       if (xTrig && yTrig)
1342         ((TH1F*)GetRecPointsData(kTriggeredBoards))->Fill(nBoard);
1343
1344       fDigitMaker->TriggerDigits(nBoard, xyPattern, *fDigitStore);
1345     }
1346
1347     TIter nextDigit(fDigitStore->CreateIterator());
1348     AliMUONVDigit* mDigit;
1349     while ( ( mDigit = static_cast<AliMUONVDigit*>(nextDigit()) ) )
1350     {
1351       Int_t detElemId = mDigit->DetElemId();
1352       Int_t ch = detElemId/100;
1353       Int_t localBoard = mDigit->ManuId();
1354       Int_t channel = mDigit->ManuChannel();
1355       Int_t cathode = mDigit->Cathode();
1356       Int_t iChamber = ch - 11;
1357       
1358       ((TH2F*)GetRecPointsData(kTriggerDigits + AliMpConstants::NofTriggerChambers()*cathode + iChamber))
1359         ->Fill(localBoard, channel);
1360     }
1361 }
1362
1363 //____________________________________________________________________________
1364 void AliMUONQADataMakerRec::MakeESDs(AliESDEvent* esd)
1365 {
1366   /// make QA data from ESDs
1367
1368   AliCodeTimerAuto("");
1369   
1370   // Do nothing in case of calibration event
1371   if ( GetRecoParam()->GetEventSpecie() == AliRecoParam::kCalib ) return;
1372   
1373   // load ESD event in the interface
1374   AliMUONESDInterface esdInterface;
1375   if (GetMUONRecoParam()) AliMUONESDInterface::ResetTracker(GetMUONRecoParam());
1376   else AliError("Unable to get recoParam: use default ones for residual calculation");
1377   esdInterface.LoadEvent(*esd);
1378   
1379   GetESDsData(kESDnTracks)->Fill(esdInterface.GetNTracks());
1380   
1381   Int_t nTrackMatchTrig = 0;
1382   
1383   // loop over tracks
1384   Int_t nTracks = (Int_t) esd->GetNumberOfMuonTracks(); 
1385   for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) {
1386     
1387     // get the ESD track and skip "ghosts"
1388     AliESDMuonTrack* esdTrack = esd->GetMuonTrack(iTrack);
1389     if (!esdTrack->ContainTrackerData()) continue;
1390     
1391     // get corresponding MUON track
1392     AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
1393     
1394     if (esdTrack->ContainTriggerData()) nTrackMatchTrig++;
1395     
1396     GetESDsData(kESDMomentum)->Fill(esdTrack->P());
1397     GetESDsData(kESDPt)->Fill(esdTrack->Pt());
1398     GetESDsData(kESDRapidity)->Fill(esdTrack->Y());
1399     GetESDsData(kESDChi2)->Fill(track->GetNormalizedChi2());
1400     GetESDsData(kESDProbChi2)->Fill(TMath::Prob(track->GetGlobalChi2(),track->GetNDF()));
1401     GetESDsData(kESDThetaX)->Fill(esdTrack->GetThetaXUncorrected() / TMath::Pi() * 180.);
1402     GetESDsData(kESDThetaY)->Fill(esdTrack->GetThetaYUncorrected() / TMath::Pi() * 180.);
1403     GetESDsData(kESDnClustersPerTrack)->Fill(track->GetNClusters());
1404     
1405     // loop over clusters
1406     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
1407     while (trackParam) {
1408       
1409       AliMUONVCluster* cluster = trackParam->GetClusterPtr();
1410       Int_t chId = cluster->GetChamberId();
1411       Int_t deID = cluster->GetDetElemId();
1412       Double_t residualX = cluster->GetX() - trackParam->GetNonBendingCoor();
1413       Double_t residualY = cluster->GetY() - trackParam->GetBendingCoor();
1414       Double_t sigmaResidualX2 = cluster->GetErrX2() - trackParam->GetCovariances()(0,0);
1415       Double_t sigmaResidualY2 = cluster->GetErrY2() - trackParam->GetCovariances()(2,2);
1416       Double_t localChi2X = (sigmaResidualX2 > 0.) ? residualX*residualX/sigmaResidualX2 : 0.;
1417       Double_t localChi2Y = (sigmaResidualY2 > 0.) ? residualY*residualY/sigmaResidualY2 : 0.;
1418       Double_t localChi2 = 0.5 * trackParam->GetLocalChi2();
1419       
1420       GetESDsData(kESDClusterHitMap+chId)->Fill(cluster->GetX(), cluster->GetY());
1421       
1422       GetESDsData(kESDnTotClustersPerCh)->Fill(chId);
1423       GetESDsData(kESDnTotClustersPerDE)->Fill(deID);
1424       
1425       GetESDsData(kESDClusterChargeInCh+chId)->Fill(cluster->GetCharge());
1426       GetESDsData(kESDSumClusterChargePerDE)->Fill(deID, cluster->GetCharge());
1427       
1428       if (cluster->GetNDigits() > 0) { // discard clusters with pad not stored in ESD
1429         GetESDsData(kESDnTotFullClustersPerDE)->Fill(deID);
1430         GetESDsData(kESDClusterSizeInCh+chId)->Fill(cluster->GetNDigits());
1431         GetESDsData(kESDSumClusterSizePerDE)->Fill(deID, cluster->GetNDigits());
1432       }
1433       
1434       GetESDsData(kESDResidualXInCh+chId)->Fill(residualX);
1435       GetESDsData(kESDResidualYInCh+chId)->Fill(residualY);
1436       GetESDsData(kESDSumResidualXPerDE)->Fill(deID, residualX);
1437       GetESDsData(kESDSumResidualYPerDE)->Fill(deID, residualY);
1438       GetESDsData(kESDSumResidualX2PerDE)->Fill(deID, residualX*residualX);
1439       GetESDsData(kESDSumResidualY2PerDE)->Fill(deID, residualY*residualY);
1440       
1441       GetESDsData(kESDLocalChi2XInCh+chId)->Fill(localChi2X);
1442       GetESDsData(kESDLocalChi2YInCh+chId)->Fill(localChi2Y);
1443       GetESDsData(kESDLocalChi2InCh+chId)->Fill(localChi2);
1444       GetESDsData(kESDSumLocalChi2XPerDE)->Fill(deID, localChi2X);
1445       GetESDsData(kESDSumLocalChi2YPerDE)->Fill(deID, localChi2Y);
1446       GetESDsData(kESDSumLocalChi2PerDE)->Fill(deID, localChi2);
1447       
1448       trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
1449       
1450     }
1451     
1452   }
1453
1454   GetESDsData(kESDMatchTrig)->Fill(nTrackMatchTrig);
1455   
1456 }
1457
1458 //____________________________________________________________________________ 
1459 void AliMUONQADataMakerRec::StartOfDetectorCycle()
1460 {
1461     /// Detector specific actions at start of cycle
1462   
1463 }
1464
1465 //____________________________________________________________________________ 
1466 void AliMUONQADataMakerRec::DisplayTriggerInfo(AliQAv1::TASKINDEX_t task)
1467 {
1468   //
1469   /// Display trigger information in a user-friendly way:
1470   /// from local board and strip numbers to their position on chambers
1471   //
1472   
1473
1474   if(task!=AliQAv1::kRECPOINTS && task!=AliQAv1::kRAWS) return;
1475
1476   // check we get histograms, otherwise return right now
1477   if ( task == AliQAv1::kRECPOINTS )
1478   {
1479     if ( !GetRecPointsData(kTriggerDigits) ) return;
1480   }
1481   
1482   if ( task == AliQAv1::kRAWS ) 
1483   {
1484     if ( !GetRawsData(kTriggerScalers) ) return;
1485   }
1486   
1487   AliMUONTriggerDisplay triggerDisplay;
1488   
1489   TH2F* histoStrips=0x0;
1490   TH2F* histoDisplayStrips=0x0;
1491   AliMUONTriggerDisplay::EDisplayOption displayOption = AliMUONTriggerDisplay::kDefaultDisplay;
1492   if(task == AliQAv1::kRAWS) displayOption = AliMUONTriggerDisplay::kNormalizeToArea;
1493
1494   for (Int_t iCath = 0; iCath < AliMpConstants::NofCathodes(); iCath++)
1495   {    
1496     for (Int_t iChamber = 0; iChamber < AliMpConstants::NofTriggerChambers(); iChamber++)
1497     {
1498       if(task==AliQAv1::kRECPOINTS){
1499         histoStrips = (TH2F*)GetRecPointsData(kTriggerDigits + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
1500       }
1501       else if(task==AliQAv1::kRAWS){
1502         histoStrips = (TH2F*)GetRawsData(kTriggerScalers + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
1503       }
1504
1505       if(histoStrips->GetEntries()==0) continue; // No events found => No need to display
1506
1507       if(task==AliQAv1::kRECPOINTS){
1508         histoDisplayStrips = (TH2F*)GetRecPointsData(kTriggerDigitsDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
1509       }
1510       else if(task==AliQAv1::kRAWS){
1511         histoDisplayStrips = (TH2F*)GetRawsData(kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
1512       }
1513
1514       triggerDisplay.FillDisplayHistogram(histoStrips, histoDisplayStrips,
1515                                           AliMUONTriggerDisplay::kDisplayStrips, iCath, iChamber, displayOption);
1516
1517       Float_t scaleValue = 0.;
1518       if(task==AliQAv1::kRAWS) {
1519         scaleValue = ((TH1F*)GetRawsData(kTriggerScalersTime))->GetBinContent(1);
1520       }
1521       else if ( task == AliQAv1::kRECPOINTS ) {
1522         scaleValue = GetRecPointsData(kNAnalyzedEvents)->GetBinContent(1);
1523       }
1524       if(scaleValue>0.) histoDisplayStrips->Scale(1./scaleValue);
1525     } // iChamber
1526   } // iCath
1527
1528   if(task==AliQAv1::kRECPOINTS){
1529     TH1F* histoBoards = (TH1F*)GetRecPointsData(kTriggeredBoards);
1530     TH2F* histoDisplayBoards = (TH2F*)GetRecPointsData(kTriggerBoardsDisplay);
1531     triggerDisplay.FillDisplayHistogram(histoBoards, histoDisplayBoards, AliMUONTriggerDisplay::kDisplayBoards, 0, 0);
1532     Float_t scaleValue = GetRecPointsData(kNAnalyzedEvents)->GetBinContent(1);
1533     if(scaleValue>0.) histoDisplayBoards->Scale(1./scaleValue);
1534   }
1535 }
1536
1537
1538 //_____________________________________________________________________________
1539 Bool_t 
1540 AliMUONQADataMakerRec::FillTriggerDCSHistos()
1541 {
1542   /// Get HV and currents values for one trigger chamber
1543   
1544   AliCodeTimerAuto("");
1545
1546   AliMUONCalibrationData calibrationData(AliCDBManager::Instance()->GetRun());
1547
1548   TMap* triggerDcsMap = calibrationData.TriggerDCS();
1549
1550   if ( !triggerDcsMap ) 
1551   {
1552     AliError("Cannot fill DCS histos, as triggerDcsMap is NULL");
1553     return kFALSE;
1554   }
1555
1556   AliMpDEIterator deIt;
1557   
1558   deIt.First();
1559     
1560   AliMpDCSNamer triggerDcsNamer("TRIGGER");
1561
1562   TH2* currHisto = 0x0;
1563   Int_t histoIndex = 0;
1564   TString histoName, histoTitle;
1565
1566   Bool_t error = kFALSE;
1567   Bool_t expert   = kTRUE;
1568   Bool_t saveCorr = kTRUE;
1569   Bool_t image    = kTRUE;
1570   
1571   while ( !deIt.IsDone() )
1572   {
1573     Int_t detElemId = deIt.CurrentDEId();
1574     
1575     if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStationTrigger) {
1576
1577       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
1578       Int_t slat = detElemId%100;
1579
1580       for(Int_t iMeas=0; iMeas<AliMpDCSNamer::kNDCSMeas; iMeas++){
1581         TString currAlias = triggerDcsNamer.DCSChannelName(detElemId, 0, iMeas);
1582
1583         AliDebug(AliQAv1::GetQADebugLevel(), Form("\nDetElemId %i   dcsAlias %s", detElemId, currAlias.Data()));
1584
1585         TPair* triggerDcsPair = static_cast<TPair*>(triggerDcsMap->FindObject(currAlias.Data()));
1586
1587         if (!triggerDcsPair)
1588         {
1589           AliError(Form("Did not find expected alias (%s) for DE %d",
1590                         currAlias.Data(),detElemId));  
1591           error = kTRUE;
1592         }
1593         else
1594         {
1595           TObjArray* values = static_cast<TObjArray*>(triggerDcsPair->Value());
1596           if (!values)
1597           {
1598             AliError(Form("Could not get values for alias %s",currAlias.Data()));
1599             error = kTRUE;
1600           }
1601           else
1602           {
1603             TIter next(values);
1604             AliDCSValue* val = 0x0;
1605
1606             Int_t ich = iChamber - AliMpConstants::NofTrackingChambers();
1607
1608             switch(iMeas){
1609             case AliMpDCSNamer::kDCSI:
1610               histoIndex = kTriggerRPCi + ich;
1611               histoName = Form("hRPCIChamber%i", 11+ich);
1612               histoTitle = Form("Chamber %i: RPC Currents (#muA)", 11+ich);
1613               break;
1614             case AliMpDCSNamer::kDCSHV:
1615               histoIndex = kTriggerRPChv + ich;
1616               histoName = Form("hRPCHVChamber%i", 11+ich);
1617               histoTitle = Form("Chamber %i: RPC HV (V)", 11+ich);
1618               break;
1619             }
1620
1621             currHisto = (TH2F*) GetRawsData(histoIndex);
1622
1623             if(!currHisto){
1624               Int_t npoints = values->GetEntries();
1625               TArrayF axisSlat(18+1), axisTime(npoints+1);
1626               for(Int_t islat=0; islat<=18; islat++){
1627                 axisSlat[islat] = -0.5 + (Float_t)islat;
1628               }
1629               for(Int_t ientry=0; ientry<npoints; ientry++){
1630                 val = static_cast<AliDCSValue*>(values->At(ientry));
1631                 axisTime[ientry] = val->GetTimeStamp();
1632               }
1633               axisTime[npoints] = val->GetTimeStamp() + 100;
1634
1635               currHisto  = new TH2F(histoName.Data(), histoTitle.Data(),
1636                                     npoints, axisTime.GetArray(),
1637                                     18, axisSlat.GetArray());
1638               currHisto->GetXaxis()->SetTitle("Time");
1639               currHisto->GetXaxis()->SetTimeDisplay(1);
1640               //currHisto->GetXaxis()->SetTimeFormat("%d%b%y %H:%M:%S");
1641               currHisto->GetYaxis()->SetTitle("RPC");
1642               Add2RawsList(currHisto, histoIndex, !expert, image, !saveCorr);
1643             }
1644
1645             while ( ( val = static_cast<AliDCSValue*>(next()) ) )
1646             {
1647               Float_t hvi = val->GetFloat();
1648
1649               AliDebug(AliQAv1::GetQADebugLevel(), Form("Value %f", hvi));
1650  
1651               currHisto->Fill(1.0001 * val->GetTimeStamp(), slat, hvi);
1652             } // loop on values
1653           } // if (!values)
1654         } // if (!triggerDcsPair)
1655       } // loop on measured types (HV and currents)
1656     } // if (stationType == kStationTrigger)
1657
1658     deIt.Next();
1659   }
1660   return error;
1661 }
1662
1663 //____________________________________________________________________________ 
1664 AliMUONVTrackerData* AliMUONQADataMakerRec::GetTrackerData() const
1665
1666 /// Return tracker data
1667   
1668   return fTrackerDataMaker->Data(); 
1669   
1670 }
1671
1672 //____________________________________________________________________________ 
1673 void
1674 AliMUONQADataMakerRec::BeautifyTrackerBusPatchOccupancy(TH1& hbp)
1675 {
1676   /// Put labels, limits and so on on the TrackerBusPatchOccupancy histogram
1677   
1678   hbp.SetXTitle("Absolute Bus Patch Id");
1679   hbp.SetYTitle("Occupancy (percent)");
1680   hbp.SetStats(kFALSE);
1681   
1682   Double_t xmin = hbp.GetXaxis()->GetXmin();
1683   Double_t xmax = hbp.GetXaxis()->GetXmax();
1684   
1685   Double_t occMax(0.1); // 0.1% y-limit for the plot
1686   Double_t occError(1.0); // 1.0% y-limit to count the "errors"
1687   
1688   TLine* line = new TLine(xmin,occError,xmax,occError);
1689   line->SetLineColor(2);
1690   line->SetLineWidth(3);
1691   
1692   hbp.GetListOfFunctions()->Add(line);
1693   
1694   TH1* hnpads = GetRawsData(kTrackerBusPatchNofPads);
1695   hnpads->SetStats(kFALSE);
1696   TH1* hnmanus = GetRawsData(kTrackerBusPatchNofManus);
1697   hnmanus->SetStats(kFALSE);
1698   
1699   TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1700   AliMpBusPatch* bp(0x0);
1701   while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
1702   {
1703     Int_t n(0);
1704     for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
1705     {
1706       Int_t manuId = bp->GetManuId(imanu);
1707       AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(bp->GetDEId());      
1708       n += de->NofChannelsInManu(manuId);
1709     }
1710     hnpads->Fill(bp->GetId(),n*1.0);
1711     hnmanus->Fill(bp->GetId(),bp->GetNofManus()*1.0);
1712   }
1713   
1714   next.Reset();
1715   
1716   Int_t nMissingPads(0);
1717   Int_t nPads(0);
1718   Int_t nBusPatches(0);
1719   Int_t nMissingBusPatches(0);
1720
1721   while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
1722   {
1723     Int_t bin = hbp.FindBin(bp->GetId());
1724     Int_t n = hnpads->GetBinContent(bin);
1725     
1726     ++nBusPatches;
1727
1728     nPads += n;
1729     
1730     if ( hbp.GetBinContent(bin) <= 0 ) 
1731     {
1732       nMissingPads += n;
1733       ++nMissingBusPatches;
1734     }
1735   }
1736
1737   next.Reset();
1738   
1739   Int_t ok(-1);
1740   Int_t n(0);
1741   Int_t nBusPatchesAboveLimit(0);
1742   Double_t alpha(0.1); // trim 10% of data
1743   Double_t tmean(0.0),tvar(0.0);
1744   Double_t ymin(0.0),ymax(0.0);
1745   
1746   
1747   if ( nBusPatches ) 
1748   {
1749     Double_t* x = new Double_t[nBusPatches];
1750   
1751     while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
1752     {
1753       Int_t bin = hbp.FindBin(bp->GetId());
1754       if ( hbp.GetBinContent(bin) > 0 )
1755       {
1756         x[n] = hbp.GetBinContent(bin);
1757         ++n;
1758       }
1759       if ( hbp.GetBinContent(bin) > occError )
1760       {
1761         ++nBusPatchesAboveLimit;
1762       }
1763     }
1764   
1765     // computed the truncated mean of the occupancy values, in order to get a 
1766     // reasonable y-range for the histogram (without giant peaks to the roof 
1767     // for misbehaving buspatches).
1768     ok = trim(n,x,alpha,tmean,tvar,ymin,ymax);
1769     
1770     delete[] x;
1771   }
1772   
1773   if ( ok < 0 ) 
1774   {
1775     ymax = occMax;
1776   }
1777   else
1778   {
1779     ymax = TMath::Max(ymax,occMax);
1780   }
1781   
1782   hbp.SetMaximum(ymax*1.4);
1783   
1784   TPaveText* text = new TPaveText(0.55,0.85,0.99,0.99,"NDC");
1785   
1786   if (ok < 0 ) 
1787   {
1788     text->AddText("Could not compute truncated mean. Not enough events ?");
1789     text->SetFillColor(2);
1790   }
1791   else if (!nPads || !nBusPatches)
1792   {
1793     text->AddText("Could not get the total number of pads. ERROR !!!");
1794     text->SetFillColor(2);
1795   }
1796   else
1797   {
1798     Float_t missingPadFraction = nMissingPads*100.0/nPads;
1799     Float_t missingBusPatchFraction = nMissingBusPatches*100.0/nBusPatches;
1800     Float_t aboveLimitFraction = nBusPatchesAboveLimit*100.0/nBusPatches;
1801     
1802     text->AddText(Form("%5.2f %% of missing buspatches (%d out of %d)",missingBusPatchFraction,nMissingBusPatches,nBusPatches));
1803     text->AddText(Form("%5.2f %% of missing pads (%d out of %d)",missingPadFraction,nMissingPads,nPads));
1804     text->AddText(Form("%5.2f %% bus patches above the %5.2f %% limit",aboveLimitFraction,occError));
1805     text->AddText(Form("Truncated mean at %2d %% is %7.2f %%",(Int_t)(alpha*100),tmean));
1806     
1807     if ( missingPadFraction > 10.0 || aboveLimitFraction > 5.0 ) 
1808     {
1809       text->SetFillColor(2);
1810     }
1811     else
1812     {
1813       text->SetFillColor(3);
1814     }
1815   }
1816   
1817   hbp.GetListOfFunctions()->Add(text);
1818 }
1819
1820
1821