- Disentangle masks effect from trigger chamber efficiency estimation.
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerQADataMakerRec.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: AliMUONTrackerQADataMakerRec.cxx 35760 2009-10-21 21:45:42Z ivana $
17
18 // --- MUON header files ---
19 #include "AliMUONTrackerQADataMakerRec.h"
20
21 #include "AliCDBManager.h"
22 #include "AliCodeTimer.h"
23 #include "AliDAQ.h"
24 #include "AliESDEvent.h"
25 #include "AliESDMuonTrack.h"
26 #include "AliLog.h"
27 #include "AliMUON2DMap.h"
28 #include "AliMUONCalibParamND.h"
29 #include "AliMUONCalibrationData.h"
30 #include "AliMUONConstants.h"  
31 #include "AliMUONDigitMaker.h"
32 #include "AliMUONESDInterface.h"
33 #include "AliMUONLogger.h"
34 #include "AliMUONQADataMakerRec.h"
35 #include "AliMUONQAIndices.h"
36 #include "AliMUONQAMappingCheck.h"
37 #include "AliMUONTrack.h"
38 #include "AliMUONTrackParam.h"
39 #include "AliMUONTrackerData.h"
40 #include "AliMUONTrackerDataMaker.h"
41 #include "AliMUONVCluster.h"
42 #include "AliMUONVClusterStore.h"
43 #include "AliMUONVDigit.h"
44 #include "AliMUONVDigit.h"
45 #include "AliMUONVDigitStore.h"
46 #include "AliMpBusPatch.h"
47 #include "AliMpConstants.h"
48 #include "AliMpDDL.h"
49 #include "AliMpDDLStore.h"
50 #include "AliMpDEIterator.h"
51 #include "AliMpDEManager.h"
52 #include "AliMpDetElement.h"
53 #include "AliMpManuIterator.h"
54 #include "AliQAv1.h"
55 #include "AliRawReader.h"
56 #include "AliRawEventHeaderBase.h"
57 #include <Riostream.h>
58 #include <TH1F.h> 
59 #include <TH1I.h> 
60 #include <TH2F.h>
61 #include <TMath.h>
62 #include <TObjArray.h>
63 #include <TPaveText.h>
64
65 //-----------------------------------------------------------------------------
66 /// \class AliMUONTrackerQADataMakerRec
67 ///
68 /// Quality assurance data (histo) maker for MUON tracker
69 ///
70 ///
71 /// Note that all the methods of this class shoud not be called when eventSpecie is AliRecoParam::kCalib !
72 ///
73 /// \author C. Finck, D. Stocco, L. Aphecetche
74
75 /// \cond CLASSIMP
76 ClassImp(AliMUONTrackerQADataMakerRec)
77 /// \endcond
78            
79 namespace
80 {
81   Double_t ProtectedSqrt(Double_t x)
82   {
83     return ( x > 0.0 ? TMath::Sqrt(x) : 0.0 );
84   }
85   
86 }
87
88 //____________________________________________________________________________ 
89 AliMUONTrackerQADataMakerRec::AliMUONTrackerQADataMakerRec(AliQADataMakerRec* master) : 
90 AliMUONVQADataMakerRec(master),
91 fDigitStore(0x0),
92 fDigitMaker(new AliMUONDigitMaker(kTRUE)),
93 fClusterStore(0x0),
94 fCalibrationData(new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun())),
95 fLogger(0x0),
96 fBusPatchConfig(0x0),
97 fBPxmin(0),
98 fBPxmax(0),
99 fBPnbins(0),
100 fTrackerDataMakerArray(0x0),
101 fTrackerCalDataArray(0x0),
102 fTrackerRecDataArray(0x0),
103 fMappingCheckRecPointsArray(0x0)
104 {
105   /// ctor
106 }
107
108 //__________________________________________________________________
109 AliMUONTrackerQADataMakerRec::~AliMUONTrackerQADataMakerRec()
110 {
111   /// dtor
112   delete fDigitStore;
113   delete fDigitMaker;
114   delete fClusterStore;
115   delete fCalibrationData;
116   delete fMappingCheckRecPointsArray;
117   if (fLogger)
118   {
119     if ( fLogger->NumberOfEntries() != 0 ) 
120     {
121       AliError("Some unprocessed logged errors are still there... Please check");
122     }
123     delete fLogger;    
124   }
125   delete fTrackerDataMakerArray;
126   delete fTrackerCalDataArray;
127   delete fTrackerRecDataArray;
128   delete fBusPatchConfig;  
129 }
130
131 //____________________________________________________________________________ 
132 void AliMUONTrackerQADataMakerRec::InsertTrackerData(Int_t specie, 
133                                                      TObjArray** list,
134                                                      TObject* object, 
135                                                      Int_t indexNumber,
136                                                      Bool_t replace)
137 {
138   /// Insert an object to a given list
139   
140   TIter next(list[specie]);
141   TObject* o;
142   TObject* old(0x0);
143   Bool_t alreadyThere(kFALSE);
144   
145   while ( ( o = next() ) && !alreadyThere )
146   {
147     TString classname(o->ClassName());
148     if ( classname.Contains("TrackerData") ) 
149     {
150       if ( !strcmp(object->GetName(),o->GetName()) ) 
151       {
152         alreadyThere = kTRUE;
153         old = o;
154       }
155     }
156   }
157   if ( (!alreadyThere && object) || (alreadyThere && replace) )
158   {
159     delete old;
160     AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s to the list of qa objects",object->GetName()));
161     TNamed* named = static_cast<TNamed*>(object);
162     named->SetName(Form("%s_%s",AliRecoParam::GetEventSpecieName(specie),object->GetName()));
163     object->SetBit(AliQAv1::GetExpertBit());
164     list[specie]->AddAt(object,indexNumber);
165   }
166 }
167
168 //____________________________________________________________________________ 
169 void AliMUONTrackerQADataMakerRec::EndOfDetectorCycleESDs(Int_t, TObjArray**)
170 {
171   /// Normalize ESD histograms
172   //
173   Bool_t firstFill = kTRUE;
174   //
175   for (int itc=-1;itc<Master()->GetNTrigClasses();itc++) { // RS: loop over eventual clones per trigger class
176     //
177     TH1* hESDnClustersPerTr = Master()->GetESDsData(AliMUONQAIndices::kESDnClustersPerTrack, itc);
178     if (! hESDnClustersPerTr) continue;
179     Double_t nTracks = hESDnClustersPerTr->GetEntries();
180     if (nTracks <= 0) continue;
181     //
182     if (firstFill) { AliCodeTimerAuto("",0); firstFill = kFALSE;}
183   
184     TH1* hESDnClustersPerCh = Master()->GetESDsData(AliMUONQAIndices::kESDnClustersPerCh,itc);
185     TH1* hESDnClustersPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDnClustersPerDE,itc);
186     TH1* hESDClusterChargePerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDClusterChargePerChMean,itc);
187     TH1* hESDClusterChargePerChSigma = Master()->GetESDsData(AliMUONQAIndices::kESDClusterChargePerChSigma,itc);
188     TH1* hESDClusterSizePerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDClusterSizePerChMean,itc);
189     TH1* hESDClusterSizePerChSigma = Master()->GetESDsData(AliMUONQAIndices::kESDClusterSizePerChSigma,itc);
190     TH1* hESDResidualXPerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDResidualXPerChMean,itc);
191     TH1* hESDResidualXPerChSigma = Master()->GetESDsData(AliMUONQAIndices::kESDResidualXPerChSigma,itc);
192     TH1* hESDResidualYPerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDResidualYPerChMean,itc);
193     TH1* hESDResidualYPerChSigma = Master()->GetESDsData(AliMUONQAIndices::kESDResidualYPerChSigma,itc);
194     TH1* hESDLocalChi2XPerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2XPerChMean,itc);
195     TH1* hESDLocalChi2YPerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2YPerChMean,itc);
196     TH1* hESDLocalChi2PerChMean = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2PerChMean,itc);
197     TH1* hESDClusterChargePerDE = Master()->GetESDsData(AliMUONQAIndices::kESDClusterChargePerDE,itc);
198     TH1* hESDClusterSizePerDE = Master()->GetESDsData(AliMUONQAIndices::kESDClusterSizePerDE,itc);
199     TH1* hESDResidualXPerDEMean = Master()->GetESDsData(AliMUONQAIndices::kESDResidualXPerDEMean,itc);
200     TH1* hESDResidualXPerDESigma = Master()->GetESDsData(AliMUONQAIndices::kESDResidualXPerDESigma,itc);
201     TH1* hESDResidualYPerDEMean = Master()->GetESDsData(AliMUONQAIndices::kESDResidualYPerDEMean,itc);
202     TH1* hESDResidualYPerDESigma = Master()->GetESDsData(AliMUONQAIndices::kESDResidualYPerDESigma,itc);
203     TH1* hESDLocalChi2XPerDEMean = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2XPerDEMean,itc);
204     TH1* hESDLocalChi2YPerDEMean = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2YPerDEMean,itc);
205     TH1* hESDLocalChi2PerDEMean = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2PerDEMean,itc);
206     TH1* hESDnTotClustersPerCh = Master()->GetESDsData(AliMUONQAIndices::kESDnTotClustersPerCh,itc);
207     TH1* hESDnTotClustersPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDnTotClustersPerDE,itc);
208     TH1* hESDnTotFullClustersPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDnTotFullClustersPerDE,itc);
209     TH1* hESDSumClusterChargePerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumClusterChargePerDE,itc);
210     TH1* hESDSumClusterSizePerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumClusterSizePerDE,itc);
211     TH1* hESDSumResidualXPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumResidualXPerDE,itc);
212     TH1* hESDSumResidualYPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumResidualYPerDE,itc);
213     TH1* hESDSumResidualX2PerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumResidualX2PerDE,itc);
214     TH1* hESDSumResidualY2PerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumResidualY2PerDE,itc);
215     TH1* hESDSumLocalChi2XPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumLocalChi2XPerDE,itc);
216     TH1* hESDSumLocalChi2YPerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumLocalChi2YPerDE,itc);
217     TH1* hESDSumLocalChi2PerDE = Master()->GetESDsData(AliMUONQAIndices::kESDSumLocalChi2PerDE,itc);
218     //  
219     if (hESDnClustersPerCh && hESDnTotClustersPerCh) {
220       hESDnClustersPerCh->Reset(); 
221       hESDnClustersPerCh->Add(hESDnTotClustersPerCh, 1./nTracks);
222     }
223     if (hESDnClustersPerDE && hESDnTotClustersPerDE) {
224       hESDnClustersPerDE->Reset();      
225       hESDnClustersPerDE->Add(hESDnTotClustersPerDE, 1./nTracks);
226     }
227     //
228     // loop over chambers
229     for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
230       //
231       double sigmaCharge=0,sigmaSize=0,sigmaResidualX=0,sigmaResidualY=0,sigmaLocalChi2X=0,sigmaLocalChi2Y=0,sigmaLocalChi2=0;
232       //
233       TH1* hESDClusterChargeInCh = Master()->GetESDsData(AliMUONQAIndices::kESDClusterChargeInCh+iCh,itc);
234       if (hESDClusterChargeInCh) {
235         sigmaCharge = hESDClusterChargeInCh->GetRMS();
236         if (hESDClusterChargePerChMean) { 
237           hESDClusterChargePerChMean->SetBinContent(iCh+1, hESDClusterChargeInCh->GetMean());
238           hESDClusterChargePerChMean->SetBinError(iCh+1, hESDClusterChargeInCh->GetMeanError());
239         }
240         if (hESDClusterChargePerChSigma) {
241           hESDClusterChargePerChSigma->SetBinContent(iCh+1, sigmaCharge);
242           hESDClusterChargePerChSigma->SetBinError(iCh+1, hESDClusterChargeInCh->GetRMSError());
243         }    
244       }
245       //
246       TH1* hESDClusterSizeInCh = Master()->GetESDsData(AliMUONQAIndices::kESDClusterSizeInCh+iCh,itc);
247       if (hESDClusterSizeInCh) {
248         sigmaSize = hESDClusterSizeInCh->GetRMS();
249         if (hESDClusterSizePerChMean) {
250           hESDClusterSizePerChMean->SetBinContent(iCh+1, hESDClusterSizeInCh->GetMean());
251           hESDClusterSizePerChMean->SetBinError(iCh+1, hESDClusterSizeInCh->GetMeanError());
252         }
253         if (hESDClusterSizePerChSigma) {
254           hESDClusterSizePerChSigma->SetBinContent(iCh+1, sigmaSize);
255           hESDClusterSizePerChSigma->SetBinError(iCh+1, hESDClusterSizeInCh->GetRMSError());
256         }
257       }    
258       //
259       TH1* hESDResidualXInCh = Master()->GetESDsData(AliMUONQAIndices::kESDResidualXInCh+iCh,itc);
260       if (hESDResidualXInCh) {
261         sigmaResidualX = hESDResidualXInCh->GetRMS();
262         if (hESDResidualXPerChMean) {
263           hESDResidualXPerChMean->SetBinContent(iCh+1, hESDResidualXInCh->GetMean());
264           hESDResidualXPerChMean->SetBinError(iCh+1, hESDResidualXInCh->GetMeanError());
265         }
266         if (hESDResidualXPerChSigma) {
267           hESDResidualXPerChSigma->SetBinContent(iCh+1, sigmaResidualX);
268           hESDResidualXPerChSigma->SetBinError(iCh+1, hESDResidualXInCh->GetRMSError());
269         }
270       }
271       //
272       TH1* hESDResidualYInCh = Master()->GetESDsData(AliMUONQAIndices::kESDResidualYInCh+iCh,itc);
273       if (hESDResidualYInCh) {
274         sigmaResidualY = hESDResidualYInCh->GetRMS();
275         if (hESDResidualYPerChMean) {
276           hESDResidualYPerChMean->SetBinContent(iCh+1, hESDResidualYInCh->GetMean());
277           hESDResidualYPerChMean->SetBinError(iCh+1, hESDResidualYInCh->GetMeanError());
278         }
279         if (hESDResidualYPerChSigma) {
280           hESDResidualYPerChSigma->SetBinContent(iCh+1, sigmaResidualY);
281           hESDResidualYPerChSigma->SetBinError(iCh+1, hESDResidualYInCh->GetRMSError());
282         }
283       }
284       //      
285       TH1* hESDLocalChi2XInCh = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2XInCh+iCh,itc);
286       if (hESDLocalChi2XInCh) {
287         sigmaLocalChi2X = hESDLocalChi2XInCh->GetRMS();
288         if (hESDLocalChi2XPerChMean) {
289           hESDLocalChi2XPerChMean->SetBinContent(iCh+1, hESDLocalChi2XInCh->GetMean());
290           hESDLocalChi2XPerChMean->SetBinError(iCh+1, hESDLocalChi2XInCh->GetMeanError());
291         }
292       }
293       //
294       TH1* hESDLocalChi2YInCh = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2YInCh+iCh,itc);
295       if (hESDLocalChi2YInCh) {
296         sigmaLocalChi2Y = hESDLocalChi2YInCh->GetRMS();
297         if (hESDLocalChi2YPerChMean) {
298           hESDLocalChi2YPerChMean->SetBinContent(iCh+1, hESDLocalChi2YInCh->GetMean());
299           hESDLocalChi2YPerChMean->SetBinError(iCh+1, hESDLocalChi2YInCh->GetMeanError());
300         }    
301       }
302       //
303       TH1* hESDLocalChi2InCh = Master()->GetESDsData(AliMUONQAIndices::kESDLocalChi2InCh+iCh,itc);
304       if (hESDLocalChi2InCh) {
305         sigmaLocalChi2 = hESDLocalChi2InCh->GetRMS();
306         if (hESDLocalChi2PerChMean) {
307           hESDLocalChi2PerChMean->SetBinContent(iCh+1, hESDLocalChi2InCh->GetMean());
308           hESDLocalChi2PerChMean->SetBinError(iCh+1, hESDLocalChi2InCh->GetMeanError());
309         }
310       }
311       //
312       // loop over DE into chamber iCh
313       AliMpDEIterator it;
314       it.First(iCh);
315       while ( !it.IsDone()) {
316         
317         Int_t iDE = it.CurrentDEId();
318         
319         Double_t nClusters = hESDnTotClustersPerDE ? hESDnTotClustersPerDE->GetBinContent(iDE+1) : 0;
320         if (nClusters > 1) {
321           
322           if (hESDClusterChargePerDE && hESDSumClusterChargePerDE) {
323             hESDClusterChargePerDE->SetBinContent(iDE+1, hESDSumClusterChargePerDE->GetBinContent(iDE+1)/nClusters);
324             hESDClusterChargePerDE->SetBinError(iDE+1, sigmaCharge/TMath::Sqrt(nClusters));
325           }
326         
327           if (hESDResidualXPerDEMean && hESDResidualXPerDESigma && hESDSumResidualXPerDE) {
328             Double_t meanResX = hESDSumResidualXPerDE->GetBinContent(iDE+1)/nClusters;
329             hESDResidualXPerDEMean->SetBinContent(iDE+1, meanResX);
330             hESDResidualXPerDEMean->SetBinError(iDE+1, sigmaResidualX/TMath::Sqrt(nClusters));
331             //
332             hESDResidualXPerDESigma->SetBinContent(iDE+1, ProtectedSqrt(hESDSumResidualX2PerDE->GetBinContent(iDE+1)/nClusters - meanResX*meanResX));
333             hESDResidualXPerDESigma->SetBinError(iDE+1, sigmaResidualX/TMath::Sqrt(2.*nClusters));
334           }
335           //        
336           if (hESDResidualYPerDEMean && hESDResidualYPerDESigma && hESDSumResidualYPerDE) {
337             Double_t meanResY = hESDSumResidualYPerDE->GetBinContent(iDE+1)/nClusters;
338             hESDResidualYPerDEMean->SetBinContent(iDE+1, meanResY);
339             hESDResidualYPerDEMean->SetBinError(iDE+1, sigmaResidualY/TMath::Sqrt(nClusters));
340             hESDResidualYPerDESigma->SetBinContent(iDE+1, ProtectedSqrt(hESDSumResidualY2PerDE->GetBinContent(iDE+1)/nClusters - meanResY*meanResY));
341             hESDResidualYPerDESigma->SetBinError(iDE+1, sigmaResidualY/TMath::Sqrt(2.*nClusters));
342           }
343           //
344           if (hESDLocalChi2XPerDEMean && hESDSumLocalChi2XPerDE) {
345             hESDLocalChi2XPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2XPerDE->GetBinContent(iDE+1)/nClusters);
346             hESDLocalChi2XPerDEMean->SetBinError(iDE+1, sigmaLocalChi2X/TMath::Sqrt(nClusters));
347           }
348           //
349           if (hESDLocalChi2YPerDEMean && hESDSumLocalChi2YPerDE) {
350             hESDLocalChi2YPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2YPerDE->GetBinContent(iDE+1)/nClusters);
351             hESDLocalChi2YPerDEMean->SetBinError(iDE+1, sigmaLocalChi2Y/TMath::Sqrt(nClusters));
352           }
353           //
354           if (hESDLocalChi2PerDEMean && hESDSumLocalChi2PerDE) {
355             hESDLocalChi2PerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2PerDE->GetBinContent(iDE+1)/nClusters);
356             hESDLocalChi2PerDEMean->SetBinError(iDE+1, sigmaLocalChi2/TMath::Sqrt(nClusters));
357           }
358         } 
359         else {
360           if (hESDClusterChargePerDE && hESDClusterChargeInCh && hESDSumClusterChargePerDE) {
361             hESDClusterChargePerDE->SetBinContent(iDE+1, hESDSumClusterChargePerDE->GetBinContent(iDE+1));
362             hESDClusterChargePerDE->SetBinError(iDE+1, hESDClusterChargeInCh->GetXaxis()->GetXmax());
363           }
364           //
365           if (hESDResidualXPerDEMean && hESDResidualXPerDESigma && hESDSumResidualXPerDE && hESDResidualXInCh) {
366             hESDResidualXPerDEMean->SetBinContent(iDE+1, hESDSumResidualXPerDE->GetBinContent(iDE+1));
367             hESDResidualXPerDEMean->SetBinError(iDE+1, hESDResidualXInCh->GetXaxis()->GetXmax());
368             hESDResidualXPerDESigma->SetBinContent(iDE+1, 0.);
369             hESDResidualXPerDESigma->SetBinError(iDE+1, hESDResidualXInCh->GetXaxis()->GetXmax());
370           }
371           //
372           if (hESDResidualYPerDEMean && hESDResidualYPerDESigma && hESDSumResidualYPerDE && hESDResidualYInCh) {
373             hESDResidualYPerDEMean->SetBinContent(iDE+1, hESDSumResidualYPerDE->GetBinContent(iDE+1));
374             hESDResidualYPerDEMean->SetBinError(iDE+1, hESDResidualYInCh->GetXaxis()->GetXmax());
375             hESDResidualYPerDESigma->SetBinContent(iDE+1, 0.);
376             hESDResidualYPerDESigma->SetBinError(iDE+1, hESDResidualYInCh->GetXaxis()->GetXmax());
377           }
378           //
379           if (hESDLocalChi2XPerDEMean && hESDSumLocalChi2XPerDE && hESDLocalChi2XInCh) {        
380             hESDLocalChi2XPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2XPerDE->GetBinContent(iDE+1));
381             hESDLocalChi2XPerDEMean->SetBinError(iDE+1, hESDLocalChi2XInCh->GetXaxis()->GetXmax());
382           }
383           //
384           if (hESDLocalChi2YPerDEMean && hESDSumLocalChi2YPerDE && hESDLocalChi2YInCh) {
385             hESDLocalChi2YPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2YPerDE->GetBinContent(iDE+1));
386             hESDLocalChi2YPerDEMean->SetBinError(iDE+1, hESDLocalChi2YInCh->GetXaxis()->GetXmax());
387           }
388           //
389           if (hESDLocalChi2PerDEMean && hESDSumLocalChi2PerDE && hESDLocalChi2InCh) {
390             hESDLocalChi2PerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2PerDE->GetBinContent(iDE+1));
391             hESDLocalChi2PerDEMean->SetBinError(iDE+1, hESDLocalChi2InCh->GetXaxis()->GetXmax());
392           }
393         }
394       
395         Double_t nFullClusters = hESDnTotFullClustersPerDE ? hESDnTotFullClustersPerDE->GetBinContent(iDE+1) : 0;
396         if (nFullClusters > 1) {
397           if (hESDClusterSizePerDE && hESDSumClusterSizePerDE) {        
398             hESDClusterSizePerDE->SetBinContent(iDE+1, hESDSumClusterSizePerDE->GetBinContent(iDE+1)/nFullClusters);
399             hESDClusterSizePerDE->SetBinError(iDE+1, sigmaSize/TMath::Sqrt(nFullClusters));
400           }
401         }
402         else {
403           if (hESDClusterSizePerDE && hESDSumClusterSizePerDE) {
404             hESDClusterSizePerDE->SetBinContent(iDE+1, hESDSumClusterSizePerDE->GetBinContent(iDE+1));
405             hESDClusterSizePerDE->SetBinError(iDE+1, hESDClusterSizeInCh->GetXaxis()->GetXmax());
406           }
407         }
408         
409         it.Next();
410       } // while
411       
412     } // iCh loop
413
414   } // trigger classes loop
415
416 }
417   
418 //____________________________________________________________________________ 
419 void AliMUONTrackerQADataMakerRec::EndOfDetectorCycleRecPoints(Int_t specie, TObjArray** list)
420 {
421   /// Normalize RecPoints histograms
422   //
423   Bool_t firstFill=kTRUE, needIns0=kTRUE, needIns1=kTRUE;
424   //
425   for (int itc=-1;itc<Master()->GetNTrigClasses();itc++) { // RS: loop over eventual clones per trigger class 
426
427     TH1* hTrackerClusterChargePerChMean = GetRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerChMean,itc);
428     if (!hTrackerClusterChargePerChMean) continue;
429     //
430     if (firstFill) { AliCodeTimerAuto("",0); firstFill = kFALSE;}
431
432     TH1* hTrackerClusterChargePerChSigma = GetRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerChSigma,itc);
433     TH1* hTrackerClusterMultiplicityPerChMean = GetRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerChMean,itc);
434     TH1* hTrackerClusterMultiplicityPerChSigma = GetRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerChSigma,itc);
435     TH1* hTrackerClusterChargePerDEMean = GetRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerDEMean,itc);
436     TH1* hTrackerClusterMultiplicityPerDEMean = GetRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerDEMean,itc);
437   
438     // loop over chambers
439     for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
440     
441       TH1* hTrackerClusterChargePerChamber = GetRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerChamber+iCh,itc);
442       Double_t sigmaCharge = 0;
443       if (hTrackerClusterChargePerChamber) {
444         sigmaCharge = hTrackerClusterChargePerChamber->GetRMS();
445         hTrackerClusterChargePerChMean->SetBinContent(iCh+1, hTrackerClusterChargePerChamber->GetMean());
446         hTrackerClusterChargePerChMean->SetBinError(iCh+1,   hTrackerClusterChargePerChamber->GetMeanError());
447         //
448         if (hTrackerClusterChargePerChSigma) {
449           hTrackerClusterChargePerChSigma->SetBinContent(iCh+1, sigmaCharge);
450           hTrackerClusterChargePerChSigma->SetBinError(iCh+1, hTrackerClusterChargePerChamber->GetRMSError());
451         }
452       }
453       //
454       TH1* hTrackerClusterMultiplicityPerChamber = GetRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerChamber+iCh,itc);
455       Double_t sigmaSize = 0;
456       if (hTrackerClusterMultiplicityPerChamber) {
457         sigmaSize = hTrackerClusterMultiplicityPerChamber->GetRMS();
458         if (hTrackerClusterMultiplicityPerChMean) {
459           hTrackerClusterMultiplicityPerChMean->SetBinContent(iCh+1, hTrackerClusterMultiplicityPerChamber->GetMean());
460           hTrackerClusterMultiplicityPerChMean->SetBinError(iCh+1, hTrackerClusterMultiplicityPerChamber->GetMeanError());
461         }
462         if (hTrackerClusterMultiplicityPerChSigma) {
463           hTrackerClusterMultiplicityPerChSigma->SetBinContent(iCh+1, sigmaSize);
464           hTrackerClusterMultiplicityPerChSigma->SetBinError(iCh+1, hTrackerClusterMultiplicityPerChamber->GetRMSError());
465         }
466       }
467       //
468       // loop over DE into chamber iCh
469       AliMpDEIterator it;
470       it.First(iCh);
471       while ( !it.IsDone()) {
472       
473         Int_t iDE = it.CurrentDEId();
474       
475         TH1* hTrackerClusterChargePerDE = GetRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerDE+iDE,itc);
476         if (hTrackerClusterChargePerDEMean && hTrackerClusterChargePerDE) {
477           hTrackerClusterChargePerDEMean->SetBinContent(iDE+1, hTrackerClusterChargePerDE->GetMean());
478           Double_t nClusters = hTrackerClusterChargePerDE->GetEntries();
479           if (nClusters > 1) hTrackerClusterChargePerDEMean->SetBinError(iDE+1, sigmaCharge/TMath::Sqrt(nClusters));
480           else hTrackerClusterChargePerDEMean->SetBinError(iDE+1, hTrackerClusterChargePerChamber ? 
481                                                            hTrackerClusterChargePerChamber->GetXaxis()->GetXmax() : 0);
482         }
483         TH1* hTrackerClusterMultiplicityPerDE = GetRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerDE+iDE,itc);
484         if (hTrackerClusterMultiplicityPerDEMean && hTrackerClusterMultiplicityPerDE) {
485           hTrackerClusterMultiplicityPerDEMean->SetBinContent(iDE+1, hTrackerClusterMultiplicityPerDE->GetMean());
486           Double_t nClusters = hTrackerClusterMultiplicityPerDE->GetEntries();
487           if (nClusters > 1) hTrackerClusterMultiplicityPerDEMean->SetBinError(iDE+1, sigmaSize/TMath::Sqrt(nClusters));
488           else hTrackerClusterMultiplicityPerDEMean->SetBinError(iDE+1, hTrackerClusterMultiplicityPerChamber ? 
489                                                                  hTrackerClusterMultiplicityPerChamber->GetXaxis()->GetXmax() : 0);
490         }
491         it.Next();
492       }
493     }
494   
495     if (needIns0 && MappingCheckRecPoints(specie) ) { // RS: I guess this should not be in the itc loop, do this only once
496       InsertTrackerData(specie,list,MappingCheckRecPoints(specie)->CreateData("RecPoints"),AliMUONQAIndices::kTrackerRecPoints,kTRUE);    
497       needIns0 = kFALSE;
498     }
499     
500     if ( TrackerRecData(specie) ) {
501       /// put the trackerdata in the pipeline
502       if (needIns1) { // RS: I guess this should not be in the itc loop, do this only once
503         InsertTrackerData(specie,list,TrackerRecData(specie),AliMUONQAIndices::kTrackerData);
504         needIns1 = kFALSE;
505       }
506       TH1* hbp = GetRecPointsData(AliMUONQAIndices::kTrackerBusPatchOccupancy,itc);
507       TH1* hnevents = GetRecPointsData(AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed,itc);
508       TH1* hddl = GetRecPointsData(AliMUONQAIndices::kTrackerDDLOccupancy,itc);
509       TH1* hddlevents = GetRecPointsData(AliMUONQAIndices::kTrackerDDLNofEventsUsed,itc);
510     
511       if (itc==-1 && (!hbp || !hnevents || !hddl || !hddlevents)) { //RS: produce error only for trigger-blind class
512         AliError(Form("Missing some histograms : cannot work : hbp=%p hnevents=%p hddl=%p hddlevents=%p",hbp,hnevents,hddl,hddlevents));
513         continue; // return; // RS: the histos might be booked for some trigger class only
514       }
515       //
516       ProjectTrackerData(TrackerRecData(specie),*hbp,*hnevents,*hddl,*hddlevents);    
517     }
518     else {
519       AliError(Form("TrackerRecData is null for specie %s",AliRecoParam::GetEventSpecieName(specie)));
520     }
521   } //  RS: loop over eventual clones per trigger class
522 }
523
524 //____________________________________________________________________________ 
525 void AliMUONTrackerQADataMakerRec::EndOfDetectorCycleDigits(Int_t specie, TObjArray** list)
526 {
527   /// create digits histograms in digits subdir
528   
529   if ( TrackerCalData(specie) )
530   {
531     AliCodeTimerAuto("",0);
532     
533     /// put the trackerdata in the pipeline
534     InsertTrackerData(specie,list,TrackerCalData(specie),AliMUONQAIndices::kTrackerData);
535     //
536     for (int itc=-1;itc<Master()->GetNTrigClasses();itc++) { // RS: loop over eventual clones per trigger class 
537       //    
538       TH1* hbp = GetDigitsData(AliMUONQAIndices::kTrackerBusPatchOccupancy, itc);
539       TH1* hnevents = GetDigitsData(AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed, itc);
540       TH1* hddl = GetDigitsData(AliMUONQAIndices::kTrackerDDLOccupancy, itc);
541       TH1* hddlevents = GetDigitsData(AliMUONQAIndices::kTrackerDDLNofEventsUsed, itc);
542     
543       if ( (!hbp || !hnevents || !hddl || !hddlevents) ) 
544       { 
545         if (itc==-1)
546         {
547           // report error only for trigger-blind class
548           AliError(Form("Missing some histograms : cannot work : hbp=%p hnevents=%p hddl=%p hddlevents=%p",hbp,hnevents,hddl,hddlevents));
549           continue; //return; // RS
550         }
551         else
552         {
553           continue;
554         }
555       }
556       //    
557       ProjectTrackerData(TrackerCalData(specie), *hbp,*hnevents,*hddl,*hddlevents);    
558     } //  RS: loop over eventual clones per trigger class 
559   }
560 }
561
562 //____________________________________________________________________________ 
563 AliMUONQADataMakerRec* AliMUONTrackerQADataMakerRec::Master() const
564 {
565   /// Get our master
566   return static_cast<AliMUONQADataMakerRec*>(fMaster); 
567 }
568
569 //____________________________________________________________________________ 
570 void AliMUONTrackerQADataMakerRec::ProjectTrackerData(AliMUONVTrackerData* data, 
571                                                       TH1& hbp,
572                                                       TH1& hnevents,
573                                                       TH1& hddl,
574                                                       TH1& hddlevents)
575 {
576   /// Project tracker data into shifter-friendly histograms
577   
578   AliCodeTimerAuto(Form("%s",data->Name()),0);
579   
580   /// project the tracerdata into buspatch occupancies (for the experts)
581   hbp.Reset();
582   hbp.SetStats(kFALSE);
583   
584   TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
585   AliMpBusPatch* bp(0x0);
586   Int_t occDim = 2;
587   
588   while ( ( bp = static_cast<AliMpBusPatch*>(nextBP())) )
589   {
590     Int_t busPatchId = bp->GetId();
591     Int_t bin = hbp.FindBin(busPatchId);
592     if ( data->HasBusPatch(busPatchId) )
593     {
594       hbp.SetBinContent(bin,data->BusPatch(busPatchId,occDim)*100.0); // occupancy, in percent
595     }
596   }
597   
598   /// log the readout errors (for the shifter)
599   hnevents.Reset();
600   hnevents.SetStats(kFALSE);
601   hnevents.SetBinContent(1,data->NumberOfEvents(-1));
602   
603   /// project tracker data into DDL occupancies (for the shifter)
604   hddl.Reset();
605   hddl.SetStats(kFALSE);
606   hddlevents.Reset();
607   hddlevents.SetStats(kFALSE);
608   
609   const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
610   const Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
611   
612   for ( Int_t iddl = 0; iddl < nddls; ++iddl )
613   {
614     AliMpDDL* ddl = AliMpDDLStore::Instance()->GetDDL(iddl);
615     
616     Int_t ddlId = offset + ddl->GetId();
617     Int_t npads = 0;
618     
619     Int_t nevents = data->NumberOfEvents(iddl);
620     
621     hddlevents.Fill(ddlId,nevents);
622     
623     Double_t occ(0.0);
624     
625     if ( nevents > 0 )
626     {
627       for ( Int_t ide = 0; ide < ddl->GetNofDEs(); ++ide )
628       {
629         Int_t de = ddl->GetDEId(ide);
630         
631         npads += TMath::Nint(data->DetectionElement(de,3));
632         
633         occ +=  data->DetectionElement(de,4);
634       }
635       
636       if ( npads > 0 )
637       {
638         occ = occ/npads/nevents;
639       }
640       else 
641       {
642         occ = 0.0;
643       }
644     }
645     
646     hddl.Fill(ddlId,100.0*occ); // occ in percent
647   }
648   
649   TPaveText* text = new TPaveText(0.50,0.8,0.9,0.9,"NDC");
650   
651   text->AddText(Form("MCH RUN %d - %d events",AliCDBManager::Instance()->GetRun(),data->NumberOfEvents(-1)));
652
653   hddl.GetListOfFunctions()->Add(text);
654 }
655
656 //____________________________________________________________________________ 
657 void AliMUONTrackerQADataMakerRec::EndOfDetectorCycleRaws(Int_t specie, TObjArray** list)
658 {
659   /// create Raws histograms in Raws subdir
660   
661   if ( TrackerDataMaker(specie) && TrackerDataMaker(specie)->Data() ) 
662   {
663     AliCodeTimerAuto("",0);
664     
665     /// put the trackerdata in the pipeline
666     InsertTrackerData(specie,list,TrackerDataMaker(specie)->Data(),AliMUONQAIndices::kTrackerData);
667     TrackerDataMaker(specie)->SetOwnerOfData(kFALSE); // now that it's attached to list, list will take care of the deletion
668     //    
669     for (int itc=-1;itc<Master()->GetNTrigClasses();itc++) { // RS: loop over eventual clones per trigger class
670
671       TH1* hbp = GetRawsData(AliMUONQAIndices::kTrackerBusPatchOccupancy, itc);
672       TH1* hnevents = GetRawsData(AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed, itc);
673       TH1* hddl = GetRawsData(AliMUONQAIndices::kTrackerDDLOccupancy, itc);
674       TH1* hddlevents = GetRawsData(AliMUONQAIndices::kTrackerDDLNofEventsUsed, itc);
675       //
676       if (!hbp || !hnevents || !hddl || !hddlevents) {
677         if (itc==-1) AliError(Form("Missing some histograms : cannot work : hbp=%p hnevents=%p hddl=%p hddlevents=%p",hbp,hnevents,hddl,hddlevents));
678         continue; // return; // RS
679       }
680       //
681       ProjectTrackerData(TrackerDataMaker(specie)->Data(), *hbp,*hnevents,*hddl,*hddlevents);
682       //
683       FillReadoutStatus(*fLogger,TrackerDataMaker(specie)->Data(), itc);      
684     } // RS: loop over eventual clones per trigger class
685     //
686   }    
687 }
688
689 //____________________________________________________________________________ 
690 void AliMUONTrackerQADataMakerRec::FillReadoutStatus(AliMUONLogger& log, AliMUONVTrackerData* data, Int_t trigCl)
691 {
692   // RS: I am not sure if this part is valid for looping over trigger classes (loggers are not cloned)
693   if (trigCl!=-1) return; // For the moment only trigCl==-1 will be processed (i.e. trigger-blind histos)
694
695   log.ResetItr();
696
697   TString msg;
698   Int_t occurence;
699   
700   TH1* hparity = GetRawsData(AliMUONQAIndices::kTrackerBusPatchParityErrors, trigCl);
701
702   TH1* htoken = GetRawsData(AliMUONQAIndices::kTrackerBusPatchTokenLostErrors, trigCl);
703
704   TH1* hpadding = GetRawsData(AliMUONQAIndices::kTrackerBusPatchPaddingErrors, trigCl);
705   
706   TH1* hrostatus = GetRawsData(AliMUONQAIndices::kTrackerReadoutStatus, trigCl);
707     
708   TH1* hnevents = GetRawsData(AliMUONQAIndices::kTrackerNofPhysicsEventsSeen, trigCl);
709
710   //
711   if (!hparity || !htoken || !hpadding || !hrostatus || !hnevents) return;
712   
713   Int_t nevents = TMath::Nint(hnevents->GetBinContent(1));
714   
715   if ( !nevents ) 
716   {
717     TPaveText* text = new TPaveText(0,0,0.99,0.99,"NDC");
718     text->AddText("FATAL : 0 event seen ? That's NOT normal...");
719     text->SetFillColor(2); // red = FATAL
720     hrostatus->GetListOfFunctions()->Delete();
721     hrostatus->GetListOfFunctions()->Add(text);
722     return;
723   }
724   
725   /////////////////////////////////////////////////////////////////
726   /// Start by counting the number of errors
727   /////////////////////////////////////////////////////////////////
728   
729   while ( log.Next(msg,occurence) )
730   {
731     AliDebug(1,Form("msg=%s occurence=%d",msg.Data(),occurence));
732              
733     if ( msg.Contains("token") )
734     {
735       Int_t dsp(-1),iddl(-1),ecode(-1);
736       
737       sscanf(msg.Data(),"Lost token error detected with address 0x%10X of DDL %10d and code %10d.",
738              &dsp,&iddl,&ecode);
739       Int_t localBP = ((dsp >> 16)- 4)*5 + 1;
740       Int_t buspatch = localBP + iddl*100;
741       
742       // Let's try to get all the suspected bus patches (i.e. one full FRT, as currently
743       // we don't have more precise information to locate the faulty bus patch(es)).
744       
745       AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(buspatch,kFALSE);
746       if (bp)
747       {
748         Int_t frt = bp->GetFrtId();
749         AliMpDDL* ddl = AliMpDDLStore::Instance()->GetDDL(bp->GetDdlId());
750         Int_t* b = new Int_t[ddl->GetMaxDsp()];
751         ddl->GetBusPerDsp(b);
752         Int_t nbus(0);
753         for ( Int_t i = 0; i < ddl->GetNofFrts() && !nbus; ++i ) 
754         {
755           if ( ddl->GetFrtId(i) == frt ) 
756           {
757             nbus = b[i];
758           }
759         }
760         if (nbus<=0) 
761         {
762           AliError("GOT NBUS<=0 ! THAT IS BAD ! CHECK !");
763           nbus=1;
764         }
765         delete[] b;
766       
767         while (nbus) {
768           htoken->Fill(buspatch+nbus-1,occurence);
769           --nbus;
770         }
771       }
772       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofTokenLostErrors,occurence);
773     }
774     
775     if ( msg.Contains("Parity") )
776     {
777       Int_t buspatch;
778       sscanf(msg.Data(),"Parity error in buspatch %d (0x%X).",&buspatch,&buspatch);
779       hparity->Fill(buspatch,occurence);      
780       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofParityErrors,occurence);
781     }
782     
783     if ( msg.Contains("Glitch") ) 
784     {
785       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofGlitchErrors,occurence);      
786     }
787     
788     if ( msg.Contains("Padding") )
789     {
790       Int_t block, dsp, buspatch;      
791       sscanf(msg.Data(),"Padding word error for iBlock %d, iDsp %d, iBus %d.",&block,&dsp,&buspatch);
792       hpadding->Fill(buspatch,occurence);
793       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofPaddingErrors,occurence);      
794     }
795   }
796   
797   /////////////////////////////////////////////////////////////////
798   ///
799   /// Then make the status about number of missing bus patches
800   ///
801   /////////////////////////////////////////////////////////////////
802
803   Int_t nofBusPatchesNotInConfig(0);
804     
805   for ( int i = 1; i <= fBusPatchConfig->GetNbinsX(); ++i )
806   {
807     Double_t buspatchId = fBusPatchConfig->GetBinCenter(i);
808     if ( TMath::Nint(buspatchId) != i ) 
809     {
810       AliError(Form("buspathId=%e i=%d",buspatchId,i));
811     }
812     Double_t content = fBusPatchConfig->GetBinContent(i);
813     
814     if ( content <= 0. /* no content */
815         && 
816         AliMpDDLStore::Instance()->GetBusPatch(i,kFALSE) /* but a valid bus patch */ )
817     {
818       ++nofBusPatchesNotInConfig;
819     }    
820   }
821   
822   Double_t nbuspatches = fBusPatchConfig->GetEntries();
823   
824   Int_t bin = hrostatus->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromConfig);
825   hrostatus->SetBinContent(bin,nofBusPatchesNotInConfig*nevents/nbuspatches);
826   
827   Double_t nofBusPatchesNotInData(0);
828   
829   TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
830   AliMpBusPatch* bp;
831   
832   while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
833   {
834     if ( !data->HasBusPatch(bp->GetId()) ) ++nofBusPatchesNotInData;
835   }
836   
837   bin = hrostatus->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromDataStream);
838   hrostatus->SetBinContent(bin,nofBusPatchesNotInData*nevents/nbuspatches);
839 }
840
841 //____________________________________________________________________________ 
842 void AliMUONTrackerQADataMakerRec::FillEventSize(AliRawReader* rawReader)
843 {
844   /// Fill event size histogram(s)
845   // RS: substituted explicit histo filling by QA framework filling accounting for cloned histos
846   
847   FillRawsData(AliMUONQAIndices::kTrackerNofPhysicsEventsSeen,0.0);
848   
849   Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
850   
851   for ( int i = 0; i < AliDAQ::NumberOfDdls("MUONTRK"); ++i )
852   {
853     rawReader->Reset();
854     rawReader->Select("MUONTRK",i,i);
855     if (rawReader->ReadHeader() )
856     {
857       UInt_t ddlsize = rawReader->GetEquipmentSize();
858       FillRawsData(AliMUONQAIndices::kTrackerDDLEventSize,i+offset,ddlsize);
859       FillRawsData(AliMUONQAIndices::kTrackerDDLNofEventsSeen,i+offset);
860     }      
861   }
862   rawReader->Reset();
863 }
864
865 //____________________________________________________________________________ 
866 void AliMUONTrackerQADataMakerRec::InitCommon()
867 {  
868   if (!fBusPatchConfig)
869   {
870     Int_t bpmin(999999);
871     Int_t bpmax(0);
872     
873     TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
874     AliMpBusPatch* bp(0x0);
875     while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
876     {
877       bpmin = TMath::Min(bpmin,bp->GetId());
878       bpmax = TMath::Max(bpmax,bp->GetId());
879     }
880     
881     fBPxmin = bpmin-0.5;
882     fBPxmax = bpmax+0.5;
883     fBPnbins = TMath::Nint(fBPxmax-fBPxmin);
884         
885     AliMUONVStore* config = fCalibrationData->Config();
886     
887     if (config)
888     {
889       fBusPatchConfig = new TH1F("hTrackerBusPatchConfig","Configuration of bus patches",fBPnbins,fBPxmin,fBPxmax);
890       fBusPatchConfig->SetDirectory(0);
891     }
892     else
893     {
894       AliWarning("Tracker configuration not found. Will not be able to cut on low occupancies");
895     }
896     
897     next.Reset();
898     while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
899     {
900       if ( config ) 
901       {
902         Int_t nofManusInConfig(0);
903       
904         for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
905         {
906           Int_t manuId = bp->GetManuId(imanu);
907           if ( config->FindObject(bp->GetDEId(),manuId)) ++nofManusInConfig;
908         }
909         
910         if ( nofManusInConfig > 0 )
911         {
912           fBusPatchConfig->Fill(bp->GetId(),1.0);
913         }
914         else
915         {
916           fBusPatchConfig->Fill(bp->GetId(),0.0);          
917         }
918       }      
919       else // no config, we assume all is there...
920       {
921         fBusPatchConfig->Fill(bp->GetId());
922       }
923     }
924   }
925 }
926
927 //____________________________________________________________________________ 
928 void AliMUONTrackerQADataMakerRec::BookHistograms(AliQAv1::TASKINDEX_t task)
929 {
930   AliCodeTimerAuto("",0);
931
932   InitCommon();
933   
934   const Bool_t expert   = kTRUE ; 
935   const Bool_t saveCorr = kTRUE ; 
936   const Bool_t image    = kTRUE ; 
937   
938   TH1* hbp = new TH1F("hTrackerBusPatchOccupancy","Occupancy of bus patches",fBPnbins,fBPxmin,fBPxmax);
939   
940   Master()->Add2List(hbp,AliMUONQAIndices::kTrackerBusPatchOccupancy, task, expert, !image, !saveCorr);
941   
942   TH1* h = new TH1F("hTrackerBusPatchParityErrors","Number of parity errors per bus patch",fBPnbins,fBPxmin,fBPxmax);
943   
944   Master()->Add2List(h,AliMUONQAIndices::kTrackerBusPatchParityErrors,task,expert,!image,!saveCorr);
945   
946   h = new TH1F("hTrackerBusPatchTokenLostErrors","Number of token lost errors per bus patch",fBPnbins,fBPxmin,fBPxmax);
947   Master()->Add2List(h,AliMUONQAIndices::kTrackerBusPatchTokenLostErrors,task,expert,!image,!saveCorr);
948   
949   h = new TH1F("hTrackerBusPatchPaddingErrors","Number of padding errors per bus patch",fBPnbins,fBPxmin,fBPxmax);
950   
951   Master()->Add2List(h,AliMUONQAIndices::kTrackerBusPatchPaddingErrors,task,expert,!image,!saveCorr);
952   
953   
954   TH1* hnevents(0x0);
955   
956   if ( task == AliQAv1::kRAWS )
957   {
958     // for raw data, we differentiate events seen from events used to be able to detect
959     // severe decoder errors that lead to no event decoded (i.e. zero event used) even if
960     // events are there (i.e non-zero event seen).
961     hnevents = new TH1F("hTrackerNofPhysicsEventsSeen","Number of physics events seen",1,-0.5,0.5);
962     // this one will count the number of physics event the rawdatamaker is *seeing*
963     TAxis* a = hnevents->GetXaxis();
964     a->SetBinLabel(1,"NPhysicsEvents");
965     hnevents->SetStats(kFALSE);
966     Master()->Add2List(hnevents,AliMUONQAIndices::kTrackerNofPhysicsEventsSeen,task,expert,!image,!saveCorr);
967   }
968   
969   hnevents = new TH1F("hTrackerNofGoodPhysicsEventsUsed","Number of good physics events used",1,-0.5,0.5);
970   // this one will get its content from the TrackerData, i.e. it will count the number of *good* physics events *used*
971   // (i.e. not empty and with no fatal readout error)
972   TAxis* a = hnevents->GetXaxis();
973   a->SetBinLabel(1,"NGoodPhysicsEvents");
974   hnevents->SetStats(kFALSE);  
975
976   Master()->Add2List(hnevents,AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed,task,expert,!image,!saveCorr);
977
978   Master()->Add2List(static_cast<TH1*>(fBusPatchConfig->Clone()),AliMUONQAIndices::kTrackerBusPatchConfig, task,expert, !image, !saveCorr);
979
980   Int_t nbins = AliDAQ::NumberOfDdls("MUONTRK");
981   const Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
982   
983   Double_t xmin = offset - 0.5;
984   Double_t xmax  = offset + nbins - 0.5;
985   
986   TString what(AliQAv1::GetTaskName(task));
987   
988   h = new TH1F(Form("hTrackerDDL%sOccupancy",what.Data()),Form(";DDLId;DDL Occupancy in %% (from %s)",what.Data()),nbins,xmin,xmax);
989   
990   Master()->Add2List(h,AliMUONQAIndices::kTrackerDDLOccupancy,task,expert,!image,!saveCorr);
991
992   if ( task == AliQAv1::kRAWS )
993   {
994     // see above the comment about why we have event seen vs used for raw data.
995     h = new TH1F("hTrackerDDLNofEventsSeen","Number of events seen by DDL;DDLId",nbins,xmin,xmax);
996     Master()->Add2List(h,AliMUONQAIndices::kTrackerDDLNofEventsSeen,task,expert,!image,!saveCorr);
997   }
998   
999   h = new TH1F("hTrackerDDLNofEventsUsed","Number of events used by DDL;DDLId",nbins,xmin,xmax);
1000   Master()->Add2List(h,AliMUONQAIndices::kTrackerDDLNofEventsUsed,task,expert,!image,!saveCorr);
1001   
1002 }
1003
1004 //____________________________________________________________________________ 
1005 void AliMUONTrackerQADataMakerRec::InitRaws()
1006 {
1007   /// create monitor objects for RAWS
1008         
1009   TrackerDataMaker(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1010   
1011   /// Book histograms that are common to Raws and Digits
1012   BookHistograms(AliQAv1::kRAWS);
1013   
1014   /// Now the Raws specific parts
1015   TH1* h = new TH1F("hTrackerReadoutStatus","Readout status (x events)",7,-0.5,6.5);
1016   h->SetStats(kFALSE);
1017   
1018   TAxis* a = h->GetXaxis();
1019   
1020   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofGlitchErrors),"Glitch errors");
1021   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofTokenLostErrors),"Token lost errors");
1022   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofParityErrors),"Parity errors");
1023   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofPaddingErrors),"Padding errors");
1024   
1025   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofEmptyEvents),"Empty events");
1026   
1027   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromConfig),"Not readout bus patches");
1028   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromDataStream),"Missing bus patches");
1029
1030   TH1* h1 = static_cast<TH1*>(h->Clone("hTrackerReadoutStatusPerEvent"));
1031   h1->SetTitle("Readout status per event");
1032   h1->GetYaxis()->SetTitle("Percentage");
1033   
1034   // The QA shifter will only see the summary plot below
1035
1036   Add2RawsList(h,AliMUONQAIndices::kTrackerReadoutStatus,kTRUE,kFALSE,kFALSE);    
1037   Add2RawsList(h1,AliMUONQAIndices::kTrackerReadoutStatusPerEvent,kFALSE,kTRUE,kFALSE);  
1038
1039   // Lastly the event size histograms
1040   
1041   Int_t nbins = AliDAQ::NumberOfDdls("MUONTRK");
1042   const Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
1043   
1044   Double_t xmin = offset - 0.5;
1045   Double_t xmax  = offset + nbins - 0.5;
1046   
1047   h = new TH1F("hTrackerDDLEventSize","DDL event size (bytes);DDL Id;Data size (bytes)",nbins,xmin,xmax);  
1048   h->SetStats(kFALSE);
1049   Add2RawsList(h,AliMUONQAIndices::kTrackerDDLEventSize,kTRUE,kFALSE,kFALSE);
1050
1051   h = new TH1F("hTrackerDDLMeanEventSize","DDL mean event size (KB) per event;DDL Id;Mean Event size (KB)",nbins,xmin,xmax);  
1052   h->SetStats(kFALSE);
1053   Add2RawsList(h,AliMUONQAIndices::kTrackerDDLEventSizePerEvent,kFALSE,kTRUE,kFALSE);
1054     
1055   Add2RawsList(new TH1F("hTrackerIsThere","tracker is there",1,0,1),AliMUONQAIndices::kTrackerIsThere,kTRUE,kFALSE,kFALSE);
1056   //
1057   //ClonePerTrigClass(AliQAv1::kRAWS); // this should be the last line  DONE at parent level
1058 }
1059
1060 //__________________________________________________________________
1061 void AliMUONTrackerQADataMakerRec::InitDigits() 
1062 {
1063   /// create monitor objects for DIGITS
1064   
1065   AliCodeTimerAuto("",0);
1066
1067   if ( GetRecoParam()->TryRecover() )
1068   {
1069     fDigitMaker->SetTryRecover(kTRUE);
1070   }
1071   else
1072   {
1073     fDigitMaker->SetTryRecover(kFALSE);    
1074   }
1075   
1076   TrackerCalData(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1077   
1078   /// Book histograms that are common to Raws and Digits
1079   BookHistograms(AliQAv1::kDIGITSR);
1080   //
1081   //ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line  DONE at parent level
1082
1083
1084 //____________________________________________________________________________ 
1085 void AliMUONTrackerQADataMakerRec::InitRecPoints()
1086 {
1087   /// create Reconstructed Points histograms in RecPoints subdir for the
1088   /// MUON tracker subsystem.
1089   const Bool_t expert   = kTRUE ; 
1090   const Bool_t image    = kTRUE ; 
1091   
1092   AliCodeTimerAuto("",0);
1093
1094   TrackerRecData(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1095   
1096   BookHistograms(AliQAv1::kRECPOINTS);
1097   
1098   TH1I *h1I;
1099   TH1F *h1F;
1100   TH2F *h2F;
1101   
1102   // histograms per chamber
1103   Int_t nCh = AliMpConstants::NofTrackingChambers();
1104   for ( Int_t i = 0; i < nCh; ++i ) 
1105   {
1106     h1I = new TH1I(Form("hTrackerClusterMultiplicityForChamber%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads};Counts)",i+1), 100,0,100);
1107     Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterMultiplicityPerChamber+i, expert, !image);
1108     
1109     h1I = new TH1I(Form("hTrackerClusterChargeForChamber%d",i+1), Form("cluster charge distribution in chamber %d;charge (fC);Counts",i+1), 100,0,1000);
1110     Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterChargePerChamber+i, expert, !image);
1111     
1112     Float_t rMax = AliMUONConstants::Rmax(i/2);
1113     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);
1114     Add2RecPointsList(h2F, AliMUONQAIndices::kTrackerClusterHitMapPerChamber+i, expert, !image);
1115   }
1116   
1117   // summary histograms per chamber
1118   h1I = new TH1I("hTrackerNumberOfClustersPerChamber", "Number of clusters per chamber;chamber ID;n_{clusters}", nCh,-0.5,nCh-0.5);
1119   Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerNumberOfClustersPerChamber, !expert, image);
1120   
1121   h1F = new TH1F("hTrackerClusterMultiplicityPerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh,-0.5,nCh-0.5);
1122   h1F->SetOption("P");
1123   h1F->SetMarkerStyle(kFullDotMedium);
1124   h1F->SetMarkerColor(kRed);
1125   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterMultiplicityPerChMean, !expert, image);
1126   
1127   h1F = new TH1F("hTrackerClusterMultiplicityPerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh,-0.5,nCh-0.5);
1128   h1F->SetOption("P");
1129   h1F->SetMarkerStyle(kFullDotMedium);
1130   h1F->SetMarkerColor(kRed);
1131   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterMultiplicityPerChSigma, !expert, image);
1132   
1133   h1F = new TH1F("hTrackerClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (fC)", nCh,-0.5,nCh-0.5);
1134   h1F->SetOption("P");
1135   h1F->SetMarkerStyle(kFullDotMedium);
1136   h1F->SetMarkerColor(kRed);
1137   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterChargePerChMean, !expert, image);
1138   
1139   h1F = new TH1F("hTrackerClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (fC)", nCh,-0.5,nCh-0.5);
1140   h1F->SetOption("P");
1141   h1F->SetMarkerStyle(kFullDotMedium);
1142   h1F->SetMarkerColor(kRed);
1143   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterChargePerChSigma, !expert, image);
1144   
1145   // histograms per DE
1146   Int_t ndes(0);
1147   AliMpDEIterator it;
1148   it.First();
1149   while ( !it.IsDone())
1150   {
1151     Int_t detElemId = it.CurrentDEId();
1152     
1153     if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger )
1154     {
1155       ndes = TMath::Max(ndes,detElemId);
1156       
1157       h1I = new TH1I(Form("hTrackerClusterMultiplicityForDE%04d",detElemId), Form("cluster size distribution in detection element %d;size (n_{pads})",detElemId), 100,0,100);
1158       Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterMultiplicityPerDE+detElemId, expert, !image);
1159       
1160       h1I = new TH1I(Form("hTrackerClusterChargeForDE%04d",detElemId), Form("cluster charge distribution in detection element %d;charge (fC)",detElemId), 100,0,1000);
1161       Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterChargePerDE+detElemId, expert, !image);
1162     }
1163     
1164     it.Next();
1165   }
1166   
1167   // summary histograms per DE
1168   h1I = new TH1I("hTrackerNumberOfClustersPerDE", "Number of clusters per detection element;DetElem ID;n_{clusters}", ndes+1,-0.5,ndes+0.5);
1169   Add2RecPointsList(h1I, AliMUONQAIndices::kTrackerNumberOfClustersPerDE, !expert, image);
1170   
1171   h1F = new TH1F("hTrackerClusterMultiplicityPerDEMean", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", ndes+1,-0.5,ndes+0.5);
1172   h1F->SetOption("P");
1173   h1F->SetMarkerStyle(kFullDotMedium);
1174   h1F->SetMarkerColor(kRed);
1175   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterMultiplicityPerDEMean, !expert, image);
1176   
1177   h1F = new TH1F("hTrackerClusterChargePerDEMean", "cluster mean charge per DE;DetElem ID;<charge> (fC)", ndes+1,-0.5,ndes+0.5);
1178   h1F->SetOption("P");
1179   h1F->SetMarkerStyle(kFullDotMedium);
1180   h1F->SetMarkerColor(kRed);
1181   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterChargePerDEMean, !expert, image);
1182   
1183   MappingCheckRecPoints(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1184   //
1185   //ClonePerTrigClass(AliQAv1::kRECPOINTS); // this should be the last line  DONE at parent level
1186 }
1187
1188 //____________________________________________________________________________ 
1189 void AliMUONTrackerQADataMakerRec::InitESDs()
1190 {
1191   ///create ESDs histograms in ESDs subdir
1192   
1193   const Bool_t expert   = kTRUE ; 
1194   const Bool_t image    = kTRUE ; 
1195   
1196   Int_t nCh = AliMUONConstants::NTrackingCh();
1197   Int_t nDE = 1100;
1198   
1199   // track info
1200   TH1F* hESDnTracks = new TH1F("hESDnTracks", "number of tracks;n_{tracks}", 20, 0., 20.);
1201   Add2ESDsList(hESDnTracks, AliMUONQAIndices::kESDnTracks, !expert, image);
1202
1203   TH1F* hESDMatchTrig = new TH1F("hESDMatchTrig", "number of tracks matched with trigger;n_{tracks}", 20, 0., 20.);
1204   Add2ESDsList(hESDMatchTrig, AliMUONQAIndices::kESDMatchTrig, !expert, image);
1205   
1206   TH1F* hESDMomentum = new TH1F("hESDMomentum", "momentum distribution;p (GeV/c)", 300, 0., 300);
1207   Add2ESDsList(hESDMomentum, AliMUONQAIndices::kESDMomentum, !expert, image);
1208
1209   TH1F* hESDPt = new TH1F("hESDPt", "transverse momentum distribution;p_{t} (GeV/c)", 200, 0., 50);
1210   Add2ESDsList(hESDPt, AliMUONQAIndices::kESDPt, !expert, image);
1211
1212   TH1F* hESDRapidity = new TH1F("hESDRapidity", "rapidity distribution;rapidity", 200, -4.5, -2.);
1213   Add2ESDsList(hESDRapidity, AliMUONQAIndices::kESDRapidity, !expert, image);
1214
1215   TH1F* hESDChi2 = new TH1F("hESDChi2", "normalized #chi^{2} distribution;#chi^{2} / ndf", 500, 0., 50.);
1216   Add2ESDsList(hESDChi2, AliMUONQAIndices::kESDChi2, !expert, image);
1217   
1218   TH1F* hESDProbChi2 = new TH1F("hESDProbChi2", "distribution of probability of #chi^{2};prob(#chi^{2})", 100, 0., 1.);
1219   Add2ESDsList(hESDProbChi2, AliMUONQAIndices::kESDProbChi2, !expert, image);
1220   
1221   TH1F* hESDThetaX = new TH1F("hESDThetaX", "#theta_{X} distribution;#theta_{X} (degree)", 360, -180., 180);
1222   Add2ESDsList(hESDThetaX, AliMUONQAIndices::kESDThetaX, !expert, image);
1223   
1224   TH1F* hESDThetaY = new TH1F("hESDThetaY", "#theta_{Y} distribution;#theta_{Y} (degree)", 360, -180., 180);
1225   Add2ESDsList(hESDThetaY, AliMUONQAIndices::kESDThetaY, !expert, image);
1226   
1227   // cluster info
1228   for (Int_t i = 0; i < nCh; i++) {
1229     Float_t rMax = AliMUONConstants::Rmax(i/2);
1230     TH2F* hESDClusterHitMap = new TH2F(Form("hESDClusterHitMap%d",i+1), Form("cluster position distribution in chamber %d;X (cm);Y (cm)",i+1),
1231                                        100, -rMax, rMax, 100, -rMax, rMax);
1232     Add2ESDsList(hESDClusterHitMap, AliMUONQAIndices::kESDClusterHitMap+i, expert, !image);
1233   }
1234   
1235   TH1F* hESDnClustersPerTrack = new TH1F("hESDnClustersPerTrack", "number of associated clusters per track;n_{clusters}", 20, 0., 20.);
1236   Add2ESDsList(hESDnClustersPerTrack, AliMUONQAIndices::kESDnClustersPerTrack, !expert, image);
1237   
1238   TH1F* hESDnClustersPerCh = new TH1F("hESDnClustersPerCh", "averaged number of clusters per chamber per track;chamber ID;<n_{clusters}>", nCh, -0.5, nCh-0.5);
1239   hESDnClustersPerCh->SetFillColor(kRed);
1240   Add2ESDsList(hESDnClustersPerCh, AliMUONQAIndices::kESDnClustersPerCh, !expert, image);
1241   
1242   TH1F* hESDnClustersPerDE = new TH1F("hESDnClustersPerDE", "averaged number of clusters per DE per track;DetElem ID;<n_{clusters}>", nDE+1, -0.5, nDE+0.5);
1243   hESDnClustersPerDE->SetFillColor(kRed);
1244   Add2ESDsList(hESDnClustersPerDE, AliMUONQAIndices::kESDnClustersPerDE, !expert, image);
1245   
1246   for (Int_t i = 0; i < nCh; i++) {
1247     TH1F* hESDClusterChargeInCh = new TH1F(Form("hESDClusterChargeInCh%d",i+1), Form("cluster charge distribution in chamber %d;charge (fC)",i+1), 100, 0., 1000.);
1248     Add2ESDsList(hESDClusterChargeInCh, AliMUONQAIndices::kESDClusterChargeInCh+i, expert, !image);
1249   }
1250   
1251   TH1F* hESDClusterChargePerChMean = new TH1F("hESDClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (fC)", nCh, -0.5, nCh-0.5);
1252   hESDClusterChargePerChMean->SetOption("P");
1253   hESDClusterChargePerChMean->SetMarkerStyle(kFullDotMedium);
1254   hESDClusterChargePerChMean->SetMarkerColor(kRed);
1255   Add2ESDsList(hESDClusterChargePerChMean, AliMUONQAIndices::kESDClusterChargePerChMean, !expert, image);
1256   
1257   TH1F* hESDClusterChargePerChSigma = new TH1F("hESDClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (fC)", nCh, -0.5, nCh-0.5);
1258   hESDClusterChargePerChSigma->SetOption("P");
1259   hESDClusterChargePerChSigma->SetMarkerStyle(kFullDotMedium);
1260   hESDClusterChargePerChSigma->SetMarkerColor(kRed);
1261   Add2ESDsList(hESDClusterChargePerChSigma, AliMUONQAIndices::kESDClusterChargePerChSigma, !expert, image);
1262   
1263   TH1F* hESDClusterChargePerDE = new TH1F("hESDClusterChargePerDE", "cluster mean charge per DE;DetElem ID;<charge> (fC)", nDE+1, -0.5, nDE+0.5);
1264   hESDClusterChargePerDE->SetOption("P");
1265   hESDClusterChargePerDE->SetMarkerStyle(kFullDotMedium);
1266   hESDClusterChargePerDE->SetMarkerColor(kRed);
1267   Add2ESDsList(hESDClusterChargePerDE, AliMUONQAIndices::kESDClusterChargePerDE, !expert, image);
1268   
1269   for (Int_t i = 0; i < nCh; i++) {
1270     TH1F* hESDClusterSizeInCh = new TH1F(Form("hESDClusterSizeInCh%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads})",i+1), 200, 0., 200.);
1271     Add2ESDsList(hESDClusterSizeInCh, AliMUONQAIndices::kESDClusterSizeInCh+i, expert, !image);
1272   }
1273   
1274   TH1F* hESDClusterSizePerChMean = new TH1F("hESDClusterSizePerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh, -0.5, nCh-0.5);
1275   hESDClusterSizePerChMean->SetOption("P");
1276   hESDClusterSizePerChMean->SetMarkerStyle(kFullDotMedium);
1277   hESDClusterSizePerChMean->SetMarkerColor(kRed);
1278   Add2ESDsList(hESDClusterSizePerChMean, AliMUONQAIndices::kESDClusterSizePerChMean, !expert, image);
1279   
1280   TH1F* hESDClusterSizePerChSigma = new TH1F("hESDClusterSizePerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh, -0.5, nCh-0.5);
1281   hESDClusterSizePerChSigma->SetOption("P");
1282   hESDClusterSizePerChSigma->SetMarkerStyle(kFullDotMedium);
1283   hESDClusterSizePerChSigma->SetMarkerColor(kRed);
1284   Add2ESDsList(hESDClusterSizePerChSigma, AliMUONQAIndices::kESDClusterSizePerChSigma, !expert, image);
1285   
1286   TH1F* hESDClusterSizePerDE = new TH1F("hESDClusterSizePerDE", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", nDE+1, -0.5, nDE+0.5);
1287   hESDClusterSizePerDE->SetOption("P");
1288   hESDClusterSizePerDE->SetMarkerStyle(kFullDotMedium);
1289   hESDClusterSizePerDE->SetMarkerColor(kRed);
1290   Add2ESDsList(hESDClusterSizePerDE, AliMUONQAIndices::kESDClusterSizePerDE, !expert, image);
1291   
1292   // cluster - track info
1293   for (Int_t i = 0; i < nCh; i++) {
1294     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.);
1295     Add2ESDsList(hESDResidualXInCh, AliMUONQAIndices::kESDResidualXInCh+i, expert, !image);
1296     
1297     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.);
1298     Add2ESDsList(hESDResidualYInCh, AliMUONQAIndices::kESDResidualYInCh+i, expert, !image);
1299     
1300     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);
1301     Add2ESDsList(hESDLocalChi2XInCh, AliMUONQAIndices::kESDLocalChi2XInCh+i, expert, !image);
1302     
1303     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);
1304     Add2ESDsList(hESDLocalChi2YInCh, AliMUONQAIndices::kESDLocalChi2YInCh+i, expert, !image);
1305     
1306     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);
1307     Add2ESDsList(hESDLocalChi2InCh, AliMUONQAIndices::kESDLocalChi2InCh+i, expert, !image);
1308   }
1309   
1310   TH1F* hESDResidualXPerChMean = new TH1F("hESDResidualXPerChMean", "cluster-track residual-X per Ch: mean;chamber ID;<#Delta_{X}> (cm)", nCh, -0.5, nCh-0.5);
1311   hESDResidualXPerChMean->SetOption("P");
1312   hESDResidualXPerChMean->SetMarkerStyle(kFullDotMedium);
1313   hESDResidualXPerChMean->SetMarkerColor(kRed);
1314   Add2ESDsList(hESDResidualXPerChMean, AliMUONQAIndices::kESDResidualXPerChMean, !expert, image);
1315   
1316   TH1F* hESDResidualYPerChMean = new TH1F("hESDResidualYPerChMean", "cluster-track residual-Y per Ch: mean;chamber ID;<#Delta_{Y}> (cm)", nCh, -0.5, nCh-0.5);
1317   hESDResidualYPerChMean->SetOption("P");
1318   hESDResidualYPerChMean->SetMarkerStyle(kFullDotMedium);
1319   hESDResidualYPerChMean->SetMarkerColor(kRed);
1320   Add2ESDsList(hESDResidualYPerChMean, AliMUONQAIndices::kESDResidualYPerChMean, !expert, image);
1321   
1322   TH1F* hESDResidualXPerChSigma = new TH1F("hESDResidualXPerChSigma", "cluster-track residual-X per Ch: sigma;chamber ID;#sigma_{X} (cm)", nCh, -0.5, nCh-0.5);
1323   hESDResidualXPerChSigma->SetOption("P");
1324   hESDResidualXPerChSigma->SetMarkerStyle(kFullDotMedium);
1325   hESDResidualXPerChSigma->SetMarkerColor(kRed);
1326   Add2ESDsList(hESDResidualXPerChSigma, AliMUONQAIndices::kESDResidualXPerChSigma, !expert, image);
1327   
1328   TH1F* hESDResidualYPerChSigma = new TH1F("hESDResidualYPerChSigma", "cluster-track residual-Y per Ch: sigma;chamber ID;#sigma_{Y} (cm)", nCh, -0.5, nCh-0.5);
1329   hESDResidualYPerChSigma->SetOption("P");
1330   hESDResidualYPerChSigma->SetMarkerStyle(kFullDotMedium);
1331   hESDResidualYPerChSigma->SetMarkerColor(kRed);
1332   Add2ESDsList(hESDResidualYPerChSigma, AliMUONQAIndices::kESDResidualYPerChSigma, !expert, image);
1333   
1334   TH1F* hESDLocalChi2XPerChMean = new TH1F("hESDLocalChi2XPerCh", "local chi2-X per Ch: mean;chamber ID;<local #chi^{2}_{X}>", nCh, -0.5, nCh-0.5);
1335   hESDLocalChi2XPerChMean->SetOption("P");
1336   hESDLocalChi2XPerChMean->SetMarkerStyle(kFullDotMedium);
1337   hESDLocalChi2XPerChMean->SetMarkerColor(kRed);
1338   Add2ESDsList(hESDLocalChi2XPerChMean, AliMUONQAIndices::kESDLocalChi2XPerChMean, !expert, image);
1339   
1340   TH1F* hESDLocalChi2YPerChMean = new TH1F("hESDLocalChi2YPerCh", "local chi2-Y per Ch: mean;chamber ID;<local #chi^{2}_{Y}>", nCh, -0.5, nCh-0.5);
1341   hESDLocalChi2YPerChMean->SetOption("P");
1342   hESDLocalChi2YPerChMean->SetMarkerStyle(kFullDotMedium);
1343   hESDLocalChi2YPerChMean->SetMarkerColor(kRed);
1344   Add2ESDsList(hESDLocalChi2YPerChMean, AliMUONQAIndices::kESDLocalChi2YPerChMean, !expert, image);
1345   
1346   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);
1347   hESDLocalChi2PerChMean->SetOption("P");
1348   hESDLocalChi2PerChMean->SetMarkerStyle(kFullDotMedium);
1349   hESDLocalChi2PerChMean->SetMarkerColor(kRed);
1350   Add2ESDsList(hESDLocalChi2PerChMean, AliMUONQAIndices::kESDLocalChi2PerChMean, !expert, image);
1351   
1352   TH1F* hESDResidualXPerDEMean = new TH1F("hESDResidualXPerDEMean", "cluster-track residual-X per DE: mean;DetElem ID;<#Delta_{X}> (cm)", nDE+1, -0.5, nDE+0.5);
1353   hESDResidualXPerDEMean->SetOption("P");
1354   hESDResidualXPerDEMean->SetMarkerStyle(kFullDotMedium);
1355   hESDResidualXPerDEMean->SetMarkerColor(kRed);
1356   Add2ESDsList(hESDResidualXPerDEMean, AliMUONQAIndices::kESDResidualXPerDEMean, !expert, image);
1357   
1358   TH1F* hESDResidualYPerDEMean = new TH1F("hESDResidualYPerDEMean", "cluster-track residual-Y per DE: mean;DetElem ID;<#Delta_{Y}> (cm)", nDE+1, -0.5, nDE+0.5);
1359   hESDResidualYPerDEMean->SetOption("P");
1360   hESDResidualYPerDEMean->SetMarkerStyle(kFullDotMedium);
1361   hESDResidualYPerDEMean->SetMarkerColor(kRed);
1362   Add2ESDsList(hESDResidualYPerDEMean, AliMUONQAIndices::kESDResidualYPerDEMean, !expert, image);
1363   
1364   TH1F* hESDResidualXPerDESigma = new TH1F("hESDResidualXPerDESigma", "cluster-track residual-X per DE: sigma;DetElem ID;#sigma_{X} (cm)", nDE+1, -0.5, nDE+0.5);
1365   hESDResidualXPerDESigma->SetOption("P");
1366   hESDResidualXPerDESigma->SetMarkerStyle(kFullDotMedium);
1367   hESDResidualXPerDESigma->SetMarkerColor(kRed);
1368   Add2ESDsList(hESDResidualXPerDESigma, AliMUONQAIndices::kESDResidualXPerDESigma, !expert, image);
1369   
1370   TH1F* hESDResidualYPerDESigma = new TH1F("hESDResidualYPerDESigma", "cluster-track residual-Y per DE: sigma;DetElem ID;#sigma_{Y} (cm)", nDE+1, -0.5, nDE+0.5);
1371   hESDResidualYPerDESigma->SetOption("P");
1372   hESDResidualYPerDESigma->SetMarkerStyle(kFullDotMedium);
1373   hESDResidualYPerDESigma->SetMarkerColor(kRed);
1374   Add2ESDsList(hESDResidualYPerDESigma, AliMUONQAIndices::kESDResidualYPerDESigma, !expert, image);
1375   
1376   TH1F* hESDLocalChi2XPerDEMean = new TH1F("hESDLocalChi2XPerDE", "local chi2-X per DE: mean;DetElem ID;<local #chi^{2}_{X}>", nDE+1, -0.5, nDE+0.5);
1377   hESDLocalChi2XPerDEMean->SetOption("P");
1378   hESDLocalChi2XPerDEMean->SetMarkerStyle(kFullDotMedium);
1379   hESDLocalChi2XPerDEMean->SetMarkerColor(kRed);
1380   Add2ESDsList(hESDLocalChi2XPerDEMean, AliMUONQAIndices::kESDLocalChi2XPerDEMean, !expert, image);
1381   
1382   TH1F* hESDLocalChi2YPerDEMean = new TH1F("hESDLocalChi2YPerDE", "local chi2-Y per DE: mean;DetElem ID;<local #chi^{2}_{Y}>", nDE+1, -0.5, nDE+0.5);
1383   hESDLocalChi2YPerDEMean->SetOption("P");
1384   hESDLocalChi2YPerDEMean->SetMarkerStyle(kFullDotMedium);
1385   hESDLocalChi2YPerDEMean->SetMarkerColor(kRed);
1386   Add2ESDsList(hESDLocalChi2YPerDEMean, AliMUONQAIndices::kESDLocalChi2YPerDEMean, !expert, image);
1387   
1388   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);
1389   hESDLocalChi2PerDEMean->SetOption("P");
1390   hESDLocalChi2PerDEMean->SetMarkerStyle(kFullDotMedium);
1391   hESDLocalChi2PerDEMean->SetMarkerColor(kRed);
1392   Add2ESDsList(hESDLocalChi2PerDEMean, AliMUONQAIndices::kESDLocalChi2PerDEMean, !expert, image);
1393   
1394   // intermediate histograms
1395   TH1F* hESDnTotClustersPerCh = new TH1F("hESDnTotClustersPerCh", "total number of associated clusters per chamber;chamber ID;#Sigma(n_{clusters})", nCh, -0.5, nCh-0.5);
1396   Add2ESDsList(hESDnTotClustersPerCh, AliMUONQAIndices::kESDnTotClustersPerCh, expert, !image);
1397   TH1F* hESDnTotClustersPerDE = new TH1F("hESDnTotClustersPerDE", "total number of associated clusters per DE;DetElem ID;#Sigma(n_{clusters})", nDE+1, -0.5, nDE+0.5);
1398   Add2ESDsList(hESDnTotClustersPerDE, AliMUONQAIndices::kESDnTotClustersPerDE, expert, !image);
1399   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);
1400   Add2ESDsList(hESDnTotFullClustersPerDE, AliMUONQAIndices::kESDnTotFullClustersPerDE, expert, !image);
1401   TH1F* hESDSumClusterChargePerDE = new TH1F("hESDSumClusterChargePerDE", "sum of cluster charge per DE;DetElem ID;#Sigma(charge) (fC)", nDE+1, -0.5, nDE+0.5);
1402   Add2ESDsList(hESDSumClusterChargePerDE, AliMUONQAIndices::kESDSumClusterChargePerDE, expert, !image);
1403   TH1F* hESDSumClusterSizePerDE = new TH1F("hESDSumClusterSizePerDE", "sum of cluster size per DE;DetElem ID;#Sigma(size) (n_{pads})", nDE+1, -0.5, nDE+0.5);
1404   Add2ESDsList(hESDSumClusterSizePerDE, AliMUONQAIndices::kESDSumClusterSizePerDE, expert, !image);
1405   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);
1406   Add2ESDsList(hESDSumResidualXPerDE, AliMUONQAIndices::kESDSumResidualXPerDE, expert, !image);
1407   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);
1408   Add2ESDsList(hESDSumResidualYPerDE, AliMUONQAIndices::kESDSumResidualYPerDE, expert, !image);
1409   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);
1410   Add2ESDsList(hESDSumResidualX2PerDE, AliMUONQAIndices::kESDSumResidualX2PerDE, expert, !image);
1411   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);
1412   Add2ESDsList(hESDSumResidualY2PerDE, AliMUONQAIndices::kESDSumResidualY2PerDE, expert, !image);
1413   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);
1414   Add2ESDsList(hESDSumLocalChi2XPerDE, AliMUONQAIndices::kESDSumLocalChi2XPerDE, expert, !image);
1415   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);
1416   Add2ESDsList(hESDSumLocalChi2YPerDE, AliMUONQAIndices::kESDSumLocalChi2YPerDE, expert, !image);
1417   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);
1418   Add2ESDsList(hESDSumLocalChi2PerDE, AliMUONQAIndices::kESDSumLocalChi2PerDE, expert, !image);
1419   //
1420   //ClonePerTrigClass(AliQAv1::kESDS); // this should be the last line  DONE at parent level
1421 }
1422
1423 //____________________________________________________________________________
1424 void AliMUONTrackerQADataMakerRec::MakeRaws(AliRawReader* rawReader)
1425 {
1426         /// make QA for rawdata tracker
1427         
1428   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1429
1430   /// forces init
1431   GetRawsData(AliMUONQAIndices::kTrackerBusPatchOccupancy);
1432   
1433   AliMUONTrackerDataMaker* dm = static_cast<AliMUONTrackerDataMaker*>(TrackerDataMaker(AliRecoParam::AConvert(Master()->GetEventSpecie())));
1434
1435   dm->SetRawReader(rawReader);
1436         
1437   Int_t eventType = rawReader->GetType();
1438   
1439   if (eventType == AliRawEventHeaderBase::kPhysicsEvent ) 
1440   {
1441     dm->ProcessEvent();
1442     
1443     FillEventSize(rawReader);
1444         
1445     if ( dm->LastEventWasEmpty() )
1446     {
1447       FillRawsData(AliMUONQAIndices::kTrackerReadoutStatus,1.0*AliMUONQAIndices::kTrackerRawNofEmptyEvents);
1448     }    
1449   }
1450   //
1451 }
1452
1453 //__________________________________________________________________
1454 void AliMUONTrackerQADataMakerRec::MakeDigits(TTree* digitsTree)         
1455 {
1456   /// makes data from Digits
1457   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1458   
1459   /// forces init
1460
1461   GetDigitsData(AliMUONQAIndices::kTrackerBusPatchOccupancy);
1462
1463   if (!fDigitStore)
1464     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
1465   fDigitStore->Connect(*digitsTree, false);
1466   digitsTree->GetEvent(0);
1467   
1468   TIter next(fDigitStore->CreateIterator());
1469   
1470   AliMUONVDigit* dig = 0x0;
1471   
1472   AliMUON2DMap oneEventData(true);
1473   
1474   while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) )
1475   {
1476     if ( dig->IsTracker() )
1477     {
1478       if ( dig->Charge() > 0.0 )
1479       {
1480         
1481         Int_t detElemId = dig->DetElemId();
1482         Int_t manuId = dig->ManuId();
1483         
1484         AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(detElemId,manuId));
1485         if (!param)
1486         {
1487           param = new AliMUONCalibParamND(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,
1488                                           AliMUONVCalibParam::InvalidFloatValue());
1489           oneEventData.Add(param);
1490         }
1491         param->SetValueAsDouble(dig->ManuChannel(),0,dig->Charge());
1492       }
1493     }
1494   }
1495   TrackerCalData(AliRecoParam::AConvert(Master()->GetEventSpecie()))->Add(oneEventData);
1496   //
1497 }
1498
1499 //____________________________________________________________________________
1500 void AliMUONTrackerQADataMakerRec::MakeRecPoints(TTree* clustersTree)
1501 {
1502         /// Fill histograms related to tracker clusters 
1503         
1504         // First things first : do we have clusters in the TreeR ?
1505         // In "normal" production mode, it should be perfectly normal
1506         // *not* to have them.
1507         // But if for some reason we de-activated the combined tracking,
1508         // then we have clusters in TreeR, so let's take that opportunity
1509         // to QA them...
1510         
1511   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1512   // Forces init by requesting an histogram
1513   GetRecPointsData(AliMUONQAIndices::kTrackerBusPatchOccupancy); 
1514
1515         if (!fClusterStore)
1516         {
1517           AliCodeTimerAuto("ClusterStore creation",1);
1518                 fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
1519                 if (!fClusterStore) 
1520                 {
1521                         return;
1522                 }
1523         }
1524         
1525         fClusterStore->Connect(*clustersTree,kFALSE);
1526         clustersTree->GetEvent(0);
1527
1528         TIter next(fClusterStore->CreateIterator());
1529         AliMUONVCluster* cluster;
1530         
1531   AliMUONQAMappingCheck* mcr = MappingCheckRecPoints(AliRecoParam::AConvert(Master()->GetEventSpecie()));
1532   
1533   if ( mcr ) mcr->NewEvent();
1534   
1535   AliMUON2DMap oneEventData(true);
1536   
1537         while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) )
1538         {
1539                 Int_t detElemId = cluster->GetDetElemId();
1540                 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
1541                 
1542                 FillRecPointsData(AliMUONQAIndices::kTrackerNumberOfClustersPerDE,detElemId);
1543                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerDE+detElemId,cluster->GetCharge());
1544                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerDE+detElemId,cluster->GetNDigits());
1545
1546                 FillRecPointsData(AliMUONQAIndices::kTrackerNumberOfClustersPerChamber,chamberId);
1547                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerChamber+chamberId,cluster->GetCharge());
1548                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerChamber+chamberId,cluster->GetNDigits());
1549                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterHitMapPerChamber+chamberId,cluster->GetX(),cluster->GetY());
1550                 
1551     if ( mcr ) mcr->Store(*cluster);
1552     
1553     for ( int i = 0; i < cluster->GetNDigits(); ++i ) 
1554     {
1555       UInt_t digitId = cluster->GetDigitId(i);
1556       
1557       Int_t manuId = AliMUONVDigit::ManuId(digitId);
1558       Int_t manuChannel = AliMUONVDigit::ManuChannel(digitId);
1559       
1560       AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(detElemId,manuId));
1561       if (!param)
1562       {
1563         param = new AliMUONCalibParamND(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
1564         oneEventData.Add(param);
1565       }
1566       param->SetValueAsDouble(manuChannel,0,1.0);
1567     }
1568         }
1569         
1570   TrackerRecData(AliRecoParam::AConvert(Master()->GetEventSpecie()))->Add(oneEventData);    
1571
1572   fClusterStore->Clear();
1573   //
1574 }
1575
1576 //____________________________________________________________________________
1577 void AliMUONTrackerQADataMakerRec::MakeESDs(AliESDEvent* esd)
1578 {
1579   /// make QA data from ESDs
1580
1581   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1582    
1583   // load ESD event in the interface
1584   AliMUONESDInterface esdInterface;
1585   if (GetRecoParam()) AliMUONESDInterface::ResetTracker(GetRecoParam(), kFALSE);
1586   else AliError("Unable to get recoParam: use default ones for residual calculation");
1587   esdInterface.LoadEvent(*esd);
1588   
1589   FillESDsData(AliMUONQAIndices::kESDnTracks,esdInterface.GetNTracks());
1590   
1591   Int_t nTrackMatchTrig = 0;
1592   
1593   // loop over tracks
1594   Int_t nTracks = (Int_t) esd->GetNumberOfMuonTracks(); 
1595   for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) {
1596     
1597     // get the ESD track and skip "ghosts"
1598     AliESDMuonTrack* esdTrack = esd->GetMuonTrack(iTrack);
1599     if (!esdTrack->ContainTrackerData()) continue;
1600     
1601     // get corresponding MUON track
1602     AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
1603     
1604     if (esdTrack->ContainTriggerData()) nTrackMatchTrig++;
1605     
1606     FillESDsData(AliMUONQAIndices::kESDMomentum,esdTrack->P());
1607     FillESDsData(AliMUONQAIndices::kESDPt,esdTrack->Pt());
1608     FillESDsData(AliMUONQAIndices::kESDRapidity,esdTrack->Y());
1609     FillESDsData(AliMUONQAIndices::kESDChi2,track->GetNormalizedChi2());
1610     FillESDsData(AliMUONQAIndices::kESDProbChi2,TMath::Prob(track->GetGlobalChi2(),track->GetNDF()));
1611     FillESDsData(AliMUONQAIndices::kESDThetaX,esdTrack->GetThetaXUncorrected() / TMath::Pi() * 180.);
1612     FillESDsData(AliMUONQAIndices::kESDThetaY,esdTrack->GetThetaYUncorrected() / TMath::Pi() * 180.);
1613     FillESDsData(AliMUONQAIndices::kESDnClustersPerTrack,track->GetNClusters());
1614     
1615     // loop over clusters
1616     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
1617     while (trackParam) {
1618       
1619       AliMUONVCluster* cluster = trackParam->GetClusterPtr();
1620       Int_t chId = cluster->GetChamberId();
1621       Int_t deID = cluster->GetDetElemId();
1622       Double_t residualX = cluster->GetX() - trackParam->GetNonBendingCoor();
1623       Double_t residualY = cluster->GetY() - trackParam->GetBendingCoor();
1624       Double_t sigmaResidualX2 = cluster->GetErrX2() - trackParam->GetCovariances()(0,0);
1625       Double_t sigmaResidualY2 = cluster->GetErrY2() - trackParam->GetCovariances()(2,2);
1626       Double_t localChi2X = (sigmaResidualX2 > 0.) ? residualX*residualX/sigmaResidualX2 : 0.;
1627       Double_t localChi2Y = (sigmaResidualY2 > 0.) ? residualY*residualY/sigmaResidualY2 : 0.;
1628       Double_t localChi2 = 0.5 * trackParam->GetLocalChi2();
1629       
1630       FillESDsData(AliMUONQAIndices::kESDClusterHitMap+chId,cluster->GetX(), cluster->GetY());
1631       
1632       FillESDsData(AliMUONQAIndices::kESDnTotClustersPerCh,chId);
1633       FillESDsData(AliMUONQAIndices::kESDnTotClustersPerDE,deID);
1634       
1635       FillESDsData(AliMUONQAIndices::kESDClusterChargeInCh+chId,cluster->GetCharge());
1636       FillESDsData(AliMUONQAIndices::kESDSumClusterChargePerDE,deID, cluster->GetCharge());
1637       
1638       if (cluster->GetNDigits() > 0) { // discard clusters with pad not stored in ESD
1639         FillESDsData(AliMUONQAIndices::kESDnTotFullClustersPerDE,deID);
1640         FillESDsData(AliMUONQAIndices::kESDClusterSizeInCh+chId,cluster->GetNDigits());
1641         FillESDsData(AliMUONQAIndices::kESDSumClusterSizePerDE,deID, cluster->GetNDigits());
1642       }
1643       
1644       FillESDsData(AliMUONQAIndices::kESDResidualXInCh+chId,residualX);
1645       FillESDsData(AliMUONQAIndices::kESDResidualYInCh+chId,residualY);
1646       FillESDsData(AliMUONQAIndices::kESDSumResidualXPerDE,deID, residualX);
1647       FillESDsData(AliMUONQAIndices::kESDSumResidualYPerDE,deID, residualY);
1648       FillESDsData(AliMUONQAIndices::kESDSumResidualX2PerDE,deID, residualX*residualX);
1649       FillESDsData(AliMUONQAIndices::kESDSumResidualY2PerDE,deID, residualY*residualY);
1650       
1651       FillESDsData(AliMUONQAIndices::kESDLocalChi2XInCh+chId,localChi2X);
1652       FillESDsData(AliMUONQAIndices::kESDLocalChi2YInCh+chId,localChi2Y);
1653       FillESDsData(AliMUONQAIndices::kESDLocalChi2InCh+chId,localChi2);
1654       FillESDsData(AliMUONQAIndices::kESDSumLocalChi2XPerDE,deID, localChi2X);
1655       FillESDsData(AliMUONQAIndices::kESDSumLocalChi2YPerDE,deID, localChi2Y);
1656       FillESDsData(AliMUONQAIndices::kESDSumLocalChi2PerDE,deID, localChi2);
1657       
1658       trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
1659       
1660     }
1661     
1662   }
1663
1664   FillESDsData(AliMUONQAIndices::kESDMatchTrig,nTrackMatchTrig);
1665   //
1666 }
1667
1668 //____________________________________________________________________________ 
1669 AliMUONVTrackerData* AliMUONTrackerQADataMakerRec::GetTrackerData() const
1670
1671   /// Return tracker data
1672   
1673   return TrackerDataMaker(AliRecoParam::AConvert(Master()->GetEventSpecie()))->Data(); 
1674 }
1675
1676 //____________________________________________________________________________ 
1677 void
1678 AliMUONTrackerQADataMakerRec::ResetDetectorRaws(TObjArray* list)
1679 {
1680   /// Reset those histograms that must be reset (and only those), plus
1681   /// the trackerdata itself.
1682   
1683   TIter next(list);
1684   TObject* o;
1685   while ( ( o = next() ) )
1686   {
1687     TH1* h = dynamic_cast<TH1*>(o);
1688     if (h)
1689     {
1690       TString hn(h->GetName());
1691       
1692       if ( !hn.Contains("TrackerBusPatchConfig") )
1693       {
1694         AliDebug(1,Form("Resetting %s",hn.Data()));
1695
1696         h->Reset();
1697       }
1698       else
1699       {
1700         AliDebug(1,Form("Will not reset histogram %s",hn.Data()));          
1701       }
1702       continue;
1703     }
1704     // RS account for the case when this histos were cloned per trigger class
1705     TObjArray* harr = dynamic_cast<TObjArray*>(o);
1706     if (harr) {
1707       TString hn(harr->GetName());
1708       if ( !hn.Contains("TrackerBusPatchConfig") ) {
1709
1710         AliDebug(1,Form("Resetting clones of %s",hn.Data()));
1711
1712         TIter nextCl(harr);
1713         TH1* hc = 0;
1714         while ( (hc=dynamic_cast<TH1*>(nextCl())) ) hc->Reset();
1715       }
1716       else {
1717         AliDebug(1,Form("Will not reset clones of histogram %s",hn.Data()));  
1718       }
1719       continue;
1720     }
1721     //
1722     AliMUONVTrackerData* d = dynamic_cast<AliMUONVTrackerData*>(o);
1723     if (d) {
1724       AliDebug(1,Form("Resetting %s",d->GetName()));
1725       d->Clear();
1726     }
1727     else {
1728       AliError(Form("Found an object of class %s. Do not know how to reset.",o->ClassName()));
1729     }
1730   }
1731
1732   fLogger->Clear();
1733 }
1734
1735 //____________________________________________________________________________ 
1736 TObjArray* AliMUONTrackerQADataMakerRec::GetArray(TObjArray*& array, Bool_t create)
1737 {
1738   /// Get (or create) the array
1739
1740   if ( ! array ) 
1741   {
1742     if ( create ) 
1743     {
1744       array = new TObjArray(AliRecoParam::kNSpecies);
1745     }
1746   }
1747   
1748   return array;
1749 }
1750
1751 //____________________________________________________________________________ 
1752 AliMUONVTrackerDataMaker* 
1753 AliMUONTrackerQADataMakerRec::TrackerDataMaker(Int_t specieIndex)  const
1754 {
1755   /// const version of the getter
1756   if ( fTrackerDataMakerArray )
1757   {
1758     return static_cast<AliMUONVTrackerDataMaker*>(fTrackerDataMakerArray->At(specieIndex));
1759   }
1760   return 0x0;
1761 }
1762
1763 //____________________________________________________________________________ 
1764 AliMUONVTrackerDataMaker* 
1765 AliMUONTrackerQADataMakerRec::TrackerDataMaker(Int_t specieIndex, Bool_t create)
1766 {
1767   /// Get (or create) TrackerDataMaker object for a given specie
1768   
1769   TObjArray* array = GetArray(fTrackerDataMakerArray,create);
1770   TObject* o(0x0);
1771   
1772   if ( array ) 
1773   {
1774     array->SetOwner(kTRUE);
1775     o = array->At(specieIndex);
1776     if (!o && create)
1777     {
1778       
1779       AliMUONTrackerDataMaker* dm = new AliMUONTrackerDataMaker(0x0,
1780                                                                 AliCDBManager::Instance()->GetRun(),
1781                                                                 0x0,
1782                                                                 "",
1783                                                                 "",
1784                                                                 kFALSE,
1785                                                                 0.0,0.0);
1786       
1787       if (!fLogger) fLogger = new AliMUONLogger(-1); // note that we share the logger between species... should not be a big deal though
1788       dm->EnableErrorLogger(fLogger);
1789       dm->Data()->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level    
1790       dm->Data()->SetName("RawCharges");
1791       dm->SetRunning(kTRUE);
1792
1793       o = dm;
1794       array->AddAt(o,specieIndex);      
1795     }
1796   }
1797   return static_cast<AliMUONVTrackerDataMaker*>(o);
1798 }
1799
1800 //____________________________________________________________________________ 
1801 AliMUONVTrackerData* 
1802 AliMUONTrackerQADataMakerRec::TrackerCalData(Int_t specieIndex, Bool_t create)
1803 {
1804   TObjArray* array = GetArray(fTrackerCalDataArray,create);
1805   TObject* o(0x0);
1806   
1807   if (array)
1808   {
1809     o = array->At(specieIndex);
1810     if (!o && create)
1811     {
1812       AliMUONTrackerData* data = new AliMUONTrackerData("CalCharges",Form("Calibrated charges (fC) %s",GetRecoParam()->GetCalibrationMode()),1);
1813       data->SetDimensionName(0,"charge");
1814       data->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level
1815       o=data;
1816       array->AddAt(o,specieIndex);
1817     }
1818   }
1819   return static_cast<AliMUONVTrackerData*>(o);
1820 }
1821
1822 //____________________________________________________________________________ 
1823 AliMUONVTrackerData* 
1824 AliMUONTrackerQADataMakerRec::TrackerRecData(Int_t specieIndex, Bool_t create)
1825 {
1826   TObjArray* array = GetArray(fTrackerRecDataArray,create);
1827   TObject* o(0x0);
1828   
1829   if (array)
1830   {
1831     o = array->At(specieIndex);
1832     if (!o && create)
1833     {
1834       AliMUONTrackerData* data = new AliMUONTrackerData("RecCharges",Form("Calibrated charges (fC) %s for digits belonging to a reconstructed cluster",GetRecoParam()->GetCalibrationMode()),1);
1835       data->SetDimensionName(0,"one");
1836       data->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level
1837       o=data;
1838       array->AddAt(o,specieIndex);
1839     }
1840   }
1841   return static_cast<AliMUONVTrackerData*>(o);
1842 }
1843
1844 //____________________________________________________________________________ 
1845 AliMUONQAMappingCheck* 
1846 AliMUONTrackerQADataMakerRec::MappingCheckRecPoints(Int_t specieIndex, Bool_t create)
1847 {
1848   TObjArray* array = GetArray(fMappingCheckRecPointsArray,create);
1849   TObject* o(0x0);
1850   
1851   if (array)
1852   {
1853     o = array->At(specieIndex);
1854     array->SetOwner(kTRUE);
1855     if (!o && create)
1856     {
1857       AliMUONQAMappingCheck* mcheck = new AliMUONQAMappingCheck(RunNumber()); 
1858       o=mcheck;
1859       array->AddAt(o,specieIndex);
1860     }
1861   }
1862   return static_cast<AliMUONQAMappingCheck*>(o);
1863 }