o add Reset function to CalPad and CalROC o Add functionality to AliTPCdataQA - Reset...
[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 && hESDSumResidualX2PerDE) {
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 && hESDSumResidualY2PerDE) {
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   hparity->Reset();
726   htoken->Reset();
727   hpadding->Reset();
728   hrostatus->Reset();
729   
730   /////////////////////////////////////////////////////////////////
731   /// Start by counting the number of errors
732   /////////////////////////////////////////////////////////////////
733   
734   while ( log.Next(msg,occurence) )
735   {
736     AliDebug(1,Form("msg=%s occurence=%d",msg.Data(),occurence));
737              
738     if ( msg.Contains("token") )
739     {
740       Int_t dsp(-1),iddl(-1),ecode(-1);
741       
742       sscanf(msg.Data(),"Lost token error detected with address 0x%10X of DDL %10d and code %10d.",
743              &dsp,&iddl,&ecode);
744       Int_t localBP = ((dsp >> 16)- 4)*5 + 1;
745       Int_t buspatch = localBP + iddl*100;
746       
747       // Let's try to get all the suspected bus patches (i.e. one full FRT, as currently
748       // we don't have more precise information to locate the faulty bus patch(es)).
749       
750       AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(buspatch,kFALSE);
751       if (bp)
752       {
753         Int_t frt = bp->GetFrtId();
754         AliMpDDL* ddl = AliMpDDLStore::Instance()->GetDDL(bp->GetDdlId());
755         Int_t* b = new Int_t[ddl->GetMaxDsp()];
756         ddl->GetBusPerDsp(b);
757         Int_t nbus(0);
758         for ( Int_t i = 0; i < ddl->GetNofFrts() && !nbus; ++i ) 
759         {
760           if ( ddl->GetFrtId(i) == frt ) 
761           {
762             nbus = b[i];
763           }
764         }
765         if (nbus<=0) 
766         {
767           AliError("GOT NBUS<=0 ! THAT IS BAD ! CHECK !");
768           nbus=1;
769         }
770         delete[] b;
771       
772         while (nbus) {
773           htoken->Fill(buspatch+nbus-1,occurence);
774           --nbus;
775         }
776       }
777       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofTokenLostErrors,occurence);
778     }
779     
780     if ( msg.Contains("Parity") )
781     {
782       Int_t buspatch;
783       sscanf(msg.Data(),"Parity error in buspatch %d (0x%X).",&buspatch,&buspatch);
784       hparity->Fill(buspatch,occurence);      
785       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofParityErrors,occurence);
786     }
787     
788     if ( msg.Contains("Glitch") ) 
789     {
790       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofGlitchErrors,occurence);      
791     }
792     
793     if ( msg.Contains("Padding") )
794     {
795       Int_t block, dsp, buspatch;      
796       sscanf(msg.Data(),"Padding word error for iBlock %d, iDsp %d, iBus %d.",&block,&dsp,&buspatch);
797       hpadding->Fill(buspatch,occurence);
798       hrostatus->Fill(1.0*AliMUONQAIndices::kTrackerRawNofPaddingErrors,occurence);      
799     }
800   }
801   
802   /////////////////////////////////////////////////////////////////
803   ///
804   /// Then make the status about number of missing bus patches
805   ///
806   /////////////////////////////////////////////////////////////////
807
808   Int_t nofBusPatchesNotInConfig(0);
809     
810   for ( int i = 1; i <= fBusPatchConfig->GetNbinsX(); ++i )
811   {
812     Double_t buspatchId = fBusPatchConfig->GetBinCenter(i);
813     if ( TMath::Nint(buspatchId) != i ) 
814     {
815       AliError(Form("buspathId=%e i=%d",buspatchId,i));
816     }
817     Double_t content = fBusPatchConfig->GetBinContent(i);
818     
819     if ( content <= 0. /* no content */
820         && 
821         AliMpDDLStore::Instance()->GetBusPatch(i,kFALSE) /* but a valid bus patch */ )
822     {
823       ++nofBusPatchesNotInConfig;
824     }    
825   }
826   
827   Double_t nbuspatches = fBusPatchConfig->GetEntries();
828   
829   Int_t bin = hrostatus->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromConfig);
830   hrostatus->SetBinContent(bin,nofBusPatchesNotInConfig*nevents/nbuspatches);
831   
832   Double_t nofBusPatchesNotInData(0);
833   
834   TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
835   AliMpBusPatch* bp;
836   
837   while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
838   {
839     if ( !data->HasBusPatch(bp->GetId()) ) ++nofBusPatchesNotInData;
840   }
841   
842   bin = hrostatus->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromDataStream);
843   hrostatus->SetBinContent(bin,nofBusPatchesNotInData*nevents/nbuspatches);
844 }
845
846 //____________________________________________________________________________ 
847 void AliMUONTrackerQADataMakerRec::FillEventSize(AliRawReader* rawReader)
848 {
849   /// Fill event size histogram(s)
850   // RS: substituted explicit histo filling by QA framework filling accounting for cloned histos
851   
852   FillRawsData(AliMUONQAIndices::kTrackerNofPhysicsEventsSeen,0.0);
853   
854   Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
855   
856   for ( int i = 0; i < AliDAQ::NumberOfDdls("MUONTRK"); ++i )
857   {
858     rawReader->Reset();
859     rawReader->Select("MUONTRK",i,i);
860     if (rawReader->ReadHeader() )
861     {
862       UInt_t ddlsize = rawReader->GetEquipmentSize();
863       FillRawsData(AliMUONQAIndices::kTrackerDDLEventSize,i+offset,ddlsize);
864       FillRawsData(AliMUONQAIndices::kTrackerDDLNofEventsSeen,i+offset);
865     }      
866   }
867   rawReader->Reset();
868 }
869
870 //____________________________________________________________________________ 
871 void AliMUONTrackerQADataMakerRec::InitCommon()
872 {  
873   if (!fBusPatchConfig)
874   {
875     Int_t bpmin(999999);
876     Int_t bpmax(0);
877     
878     TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
879     AliMpBusPatch* bp(0x0);
880     while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
881     {
882       bpmin = TMath::Min(bpmin,bp->GetId());
883       bpmax = TMath::Max(bpmax,bp->GetId());
884     }
885     
886     fBPxmin = bpmin-0.5;
887     fBPxmax = bpmax+0.5;
888     fBPnbins = TMath::Nint(fBPxmax-fBPxmin);
889         
890     AliMUONVStore* config = fCalibrationData->Config();
891     
892     if (config)
893     {
894       fBusPatchConfig = new TH1F("hTrackerBusPatchConfig","Configuration of bus patches",fBPnbins,fBPxmin,fBPxmax);
895       fBusPatchConfig->SetDirectory(0);
896     }
897     else
898     {
899       AliWarning("Tracker configuration not found. Will not be able to cut on low occupancies");
900     }
901     
902     next.Reset();
903     while ( ( bp = static_cast<AliMpBusPatch*>(next())) )
904     {
905       if ( config ) 
906       {
907         Int_t nofManusInConfig(0);
908       
909         for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
910         {
911           Int_t manuId = bp->GetManuId(imanu);
912           if ( config->FindObject(bp->GetDEId(),manuId)) ++nofManusInConfig;
913         }
914         
915         if ( nofManusInConfig > 0 )
916         {
917           fBusPatchConfig->Fill(bp->GetId(),1.0);
918         }
919         else
920         {
921           fBusPatchConfig->Fill(bp->GetId(),0.0);          
922         }
923       }      
924       else // no config, we assume all is there...
925       {
926         fBusPatchConfig->Fill(bp->GetId());
927       }
928     }
929   }
930 }
931
932 //____________________________________________________________________________ 
933 void AliMUONTrackerQADataMakerRec::BookHistograms(AliQAv1::TASKINDEX_t task)
934 {
935   AliCodeTimerAuto("",0);
936
937   InitCommon();
938   
939   const Bool_t expert   = kTRUE ; 
940   const Bool_t saveCorr = kTRUE ; 
941   const Bool_t image    = kTRUE ; 
942   
943   TH1* hbp = new TH1F("hTrackerBusPatchOccupancy","Occupancy of bus patches",fBPnbins,fBPxmin,fBPxmax);
944   
945   Master()->Add2List(hbp,AliMUONQAIndices::kTrackerBusPatchOccupancy, task, expert, !image, !saveCorr);
946   
947   TH1* h = new TH1F("hTrackerBusPatchParityErrors","Number of parity errors per bus patch",fBPnbins,fBPxmin,fBPxmax);
948   
949   Master()->Add2List(h,AliMUONQAIndices::kTrackerBusPatchParityErrors,task,expert,!image,!saveCorr);
950   
951   h = new TH1F("hTrackerBusPatchTokenLostErrors","Number of token lost errors per bus patch",fBPnbins,fBPxmin,fBPxmax);
952   Master()->Add2List(h,AliMUONQAIndices::kTrackerBusPatchTokenLostErrors,task,expert,!image,!saveCorr);
953   
954   h = new TH1F("hTrackerBusPatchPaddingErrors","Number of padding errors per bus patch",fBPnbins,fBPxmin,fBPxmax);
955   
956   Master()->Add2List(h,AliMUONQAIndices::kTrackerBusPatchPaddingErrors,task,expert,!image,!saveCorr);
957   
958   
959   TH1* hnevents(0x0);
960   
961   if ( task == AliQAv1::kRAWS )
962   {
963     // for raw data, we differentiate events seen from events used to be able to detect
964     // severe decoder errors that lead to no event decoded (i.e. zero event used) even if
965     // events are there (i.e non-zero event seen).
966     hnevents = new TH1F("hTrackerNofPhysicsEventsSeen","Number of physics events seen",1,-0.5,0.5);
967     // this one will count the number of physics event the rawdatamaker is *seeing*
968     TAxis* a = hnevents->GetXaxis();
969     a->SetBinLabel(1,"NPhysicsEvents");
970     hnevents->SetStats(kFALSE);
971     Master()->Add2List(hnevents,AliMUONQAIndices::kTrackerNofPhysicsEventsSeen,task,expert,!image,!saveCorr);
972   }
973   
974   hnevents = new TH1F("hTrackerNofGoodPhysicsEventsUsed","Number of good physics events used",1,-0.5,0.5);
975   // this one will get its content from the TrackerData, i.e. it will count the number of *good* physics events *used*
976   // (i.e. not empty and with no fatal readout error)
977   TAxis* a = hnevents->GetXaxis();
978   a->SetBinLabel(1,"NGoodPhysicsEvents");
979   hnevents->SetStats(kFALSE);  
980
981   Master()->Add2List(hnevents,AliMUONQAIndices::kTrackerNofGoodPhysicsEventsUsed,task,expert,!image,!saveCorr);
982
983   Master()->Add2List(static_cast<TH1*>(fBusPatchConfig->Clone()),AliMUONQAIndices::kTrackerBusPatchConfig, task,expert, !image, !saveCorr);
984
985   Int_t nbins = AliDAQ::NumberOfDdls("MUONTRK");
986   const Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
987   
988   Double_t xmin = offset - 0.5;
989   Double_t xmax  = offset + nbins - 0.5;
990   
991   TString what(AliQAv1::GetTaskName(task));
992   
993   h = new TH1F(Form("hTrackerDDL%sOccupancy",what.Data()),Form(";DDLId;DDL Occupancy in %% (from %s)",what.Data()),nbins,xmin,xmax);
994   
995   Master()->Add2List(h,AliMUONQAIndices::kTrackerDDLOccupancy,task,expert,!image,!saveCorr);
996
997   if ( task == AliQAv1::kRAWS )
998   {
999     // see above the comment about why we have event seen vs used for raw data.
1000     h = new TH1F("hTrackerDDLNofEventsSeen","Number of events seen by DDL;DDLId",nbins,xmin,xmax);
1001     Master()->Add2List(h,AliMUONQAIndices::kTrackerDDLNofEventsSeen,task,expert,!image,!saveCorr);
1002   }
1003   
1004   h = new TH1F("hTrackerDDLNofEventsUsed","Number of events used by DDL;DDLId",nbins,xmin,xmax);
1005   Master()->Add2List(h,AliMUONQAIndices::kTrackerDDLNofEventsUsed,task,expert,!image,!saveCorr);
1006   
1007 }
1008
1009 //____________________________________________________________________________ 
1010 void AliMUONTrackerQADataMakerRec::InitRaws()
1011 {
1012   /// create monitor objects for RAWS
1013         
1014   TrackerDataMaker(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1015   
1016   /// Book histograms that are common to Raws and Digits
1017   BookHistograms(AliQAv1::kRAWS);
1018   
1019   /// Now the Raws specific parts
1020   TH1* h = new TH1F("hTrackerReadoutStatus","Readout status (x events)",7,-0.5,6.5);
1021   h->SetStats(kFALSE);
1022   
1023   TAxis* a = h->GetXaxis();
1024   
1025   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofGlitchErrors),"Glitch errors");
1026   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofTokenLostErrors),"Token lost errors");
1027   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofParityErrors),"Parity errors");
1028   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofPaddingErrors),"Padding errors");
1029   
1030   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofEmptyEvents),"Empty events");
1031   
1032   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromConfig),"Not readout bus patches");
1033   a->SetBinLabel(h->FindBin(1.0*AliMUONQAIndices::kTrackerRawNofMissingBusPatchesFromDataStream),"Missing bus patches");
1034
1035   TH1* h1 = static_cast<TH1*>(h->Clone("hTrackerReadoutStatusPerEvent"));
1036   h1->SetTitle("Readout status per event");
1037   h1->GetYaxis()->SetTitle("Percentage");
1038   
1039   // The QA shifter will only see the summary plot below
1040
1041   Add2RawsList(h,AliMUONQAIndices::kTrackerReadoutStatus,kTRUE,kFALSE,kFALSE);    
1042   Add2RawsList(h1,AliMUONQAIndices::kTrackerReadoutStatusPerEvent,kFALSE,kTRUE,kFALSE);  
1043
1044   // Lastly the event size histograms
1045   
1046   Int_t nbins = AliDAQ::NumberOfDdls("MUONTRK");
1047   const Int_t offset = AliDAQ::DdlIDOffset("MUONTRK");
1048   
1049   Double_t xmin = offset - 0.5;
1050   Double_t xmax  = offset + nbins - 0.5;
1051   
1052   h = new TH1F("hTrackerDDLEventSize","DDL event size (bytes);DDL Id;Data size (bytes)",nbins,xmin,xmax);  
1053   h->SetStats(kFALSE);
1054   Add2RawsList(h,AliMUONQAIndices::kTrackerDDLEventSize,kTRUE,kFALSE,kFALSE);
1055
1056   h = new TH1F("hTrackerDDLMeanEventSize","DDL mean event size (KB) per event;DDL Id;Mean Event size (KB)",nbins,xmin,xmax);  
1057   h->SetStats(kFALSE);
1058   Add2RawsList(h,AliMUONQAIndices::kTrackerDDLEventSizePerEvent,kFALSE,kTRUE,kFALSE);
1059     
1060   Add2RawsList(new TH1F("hTrackerIsThere","tracker is there",1,0,1),AliMUONQAIndices::kTrackerIsThere,kTRUE,kFALSE,kFALSE);
1061   //
1062   //ClonePerTrigClass(AliQAv1::kRAWS); // this should be the last line  DONE at parent level
1063 }
1064
1065 //__________________________________________________________________
1066 void AliMUONTrackerQADataMakerRec::InitDigits() 
1067 {
1068   /// create monitor objects for DIGITS
1069   
1070   AliCodeTimerAuto("",0);
1071
1072   if ( GetRecoParam()->TryRecover() )
1073   {
1074     fDigitMaker->SetTryRecover(kTRUE);
1075   }
1076   else
1077   {
1078     fDigitMaker->SetTryRecover(kFALSE);    
1079   }
1080   
1081   TrackerCalData(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1082   
1083   /// Book histograms that are common to Raws and Digits
1084   BookHistograms(AliQAv1::kDIGITSR);
1085   //
1086   //ClonePerTrigClass(AliQAv1::kDIGITS); // this should be the last line  DONE at parent level
1087
1088
1089 //____________________________________________________________________________ 
1090 void AliMUONTrackerQADataMakerRec::InitRecPoints()
1091 {
1092   /// create Reconstructed Points histograms in RecPoints subdir for the
1093   /// MUON tracker subsystem.
1094   const Bool_t expert   = kTRUE ; 
1095   const Bool_t image    = kTRUE ; 
1096   
1097   AliCodeTimerAuto("",0);
1098
1099   TrackerRecData(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1100   
1101   BookHistograms(AliQAv1::kRECPOINTS);
1102   
1103   TH1I *h1I;
1104   TH1F *h1F;
1105   TH2F *h2F;
1106   
1107   // histograms per chamber
1108   Int_t nCh = AliMpConstants::NofTrackingChambers();
1109   for ( Int_t i = 0; i < nCh; ++i ) 
1110   {
1111     h1I = new TH1I(Form("hTrackerClusterMultiplicityForChamber%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads};Counts)",i+1), 100,0,100);
1112     Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterMultiplicityPerChamber+i, expert, !image);
1113     
1114     h1I = new TH1I(Form("hTrackerClusterChargeForChamber%d",i+1), Form("cluster charge distribution in chamber %d;charge (fC);Counts",i+1), 100,0,1000);
1115     Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterChargePerChamber+i, expert, !image);
1116     
1117     Float_t rMax = AliMUONConstants::Rmax(i/2);
1118     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);
1119     Add2RecPointsList(h2F, AliMUONQAIndices::kTrackerClusterHitMapPerChamber+i, expert, !image);
1120   }
1121   
1122   // summary histograms per chamber
1123   h1I = new TH1I("hTrackerNumberOfClustersPerChamber", "Number of clusters per chamber;chamber ID;n_{clusters}", nCh,-0.5,nCh-0.5);
1124   Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerNumberOfClustersPerChamber, !expert, image);
1125   
1126   h1F = new TH1F("hTrackerClusterMultiplicityPerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh,-0.5,nCh-0.5);
1127   h1F->SetOption("P");
1128   h1F->SetMarkerStyle(kFullDotMedium);
1129   h1F->SetMarkerColor(kRed);
1130   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterMultiplicityPerChMean, !expert, image);
1131   
1132   h1F = new TH1F("hTrackerClusterMultiplicityPerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh,-0.5,nCh-0.5);
1133   h1F->SetOption("P");
1134   h1F->SetMarkerStyle(kFullDotMedium);
1135   h1F->SetMarkerColor(kRed);
1136   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterMultiplicityPerChSigma, !expert, image);
1137   
1138   h1F = new TH1F("hTrackerClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (fC)", nCh,-0.5,nCh-0.5);
1139   h1F->SetOption("P");
1140   h1F->SetMarkerStyle(kFullDotMedium);
1141   h1F->SetMarkerColor(kRed);
1142   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterChargePerChMean, !expert, image);
1143   
1144   h1F = new TH1F("hTrackerClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (fC)", nCh,-0.5,nCh-0.5);
1145   h1F->SetOption("P");
1146   h1F->SetMarkerStyle(kFullDotMedium);
1147   h1F->SetMarkerColor(kRed);
1148   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterChargePerChSigma, !expert, image);
1149   
1150   // histograms per DE
1151   Int_t ndes(0);
1152   AliMpDEIterator it;
1153   it.First();
1154   while ( !it.IsDone())
1155   {
1156     Int_t detElemId = it.CurrentDEId();
1157     
1158     if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger )
1159     {
1160       ndes = TMath::Max(ndes,detElemId);
1161       
1162       h1I = new TH1I(Form("hTrackerClusterMultiplicityForDE%04d",detElemId), Form("cluster size distribution in detection element %d;size (n_{pads})",detElemId), 100,0,100);
1163       Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterMultiplicityPerDE+detElemId, expert, !image);
1164       
1165       h1I = new TH1I(Form("hTrackerClusterChargeForDE%04d",detElemId), Form("cluster charge distribution in detection element %d;charge (fC)",detElemId), 100,0,1000);
1166       Add2RecPointsList(h1I,AliMUONQAIndices::kTrackerClusterChargePerDE+detElemId, expert, !image);
1167     }
1168     
1169     it.Next();
1170   }
1171   
1172   // summary histograms per DE
1173   h1I = new TH1I("hTrackerNumberOfClustersPerDE", "Number of clusters per detection element;DetElem ID;n_{clusters}", ndes+1,-0.5,ndes+0.5);
1174   Add2RecPointsList(h1I, AliMUONQAIndices::kTrackerNumberOfClustersPerDE, !expert, image);
1175   
1176   h1F = new TH1F("hTrackerClusterMultiplicityPerDEMean", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", ndes+1,-0.5,ndes+0.5);
1177   h1F->SetOption("P");
1178   h1F->SetMarkerStyle(kFullDotMedium);
1179   h1F->SetMarkerColor(kRed);
1180   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterMultiplicityPerDEMean, !expert, image);
1181   
1182   h1F = new TH1F("hTrackerClusterChargePerDEMean", "cluster mean charge per DE;DetElem ID;<charge> (fC)", ndes+1,-0.5,ndes+0.5);
1183   h1F->SetOption("P");
1184   h1F->SetMarkerStyle(kFullDotMedium);
1185   h1F->SetMarkerColor(kRed);
1186   Add2RecPointsList(h1F, AliMUONQAIndices::kTrackerClusterChargePerDEMean, !expert, image);
1187   
1188   MappingCheckRecPoints(AliRecoParam::AConvert(Master()->GetEventSpecie()),kTRUE);
1189   //
1190   //ClonePerTrigClass(AliQAv1::kRECPOINTS); // this should be the last line  DONE at parent level
1191 }
1192
1193 //____________________________________________________________________________ 
1194 void AliMUONTrackerQADataMakerRec::InitESDs()
1195 {
1196   ///create ESDs histograms in ESDs subdir
1197   
1198   const Bool_t expert   = kTRUE ; 
1199   const Bool_t image    = kTRUE ; 
1200   
1201   Int_t nCh = AliMUONConstants::NTrackingCh();
1202   Int_t nDE = 1100;
1203   
1204   // track info
1205   TH1F* hESDnTracks = new TH1F("hESDnTracks", "number of tracks;n_{tracks}", 20, 0., 20.);
1206   Add2ESDsList(hESDnTracks, AliMUONQAIndices::kESDnTracks, !expert, image);
1207
1208   TH1F* hESDMatchTrig = new TH1F("hESDMatchTrig", "number of tracks matched with trigger;n_{tracks}", 20, 0., 20.);
1209   Add2ESDsList(hESDMatchTrig, AliMUONQAIndices::kESDMatchTrig, !expert, image);
1210   
1211   TH1F* hESDMomentum = new TH1F("hESDMomentum", "momentum distribution;p (GeV/c)", 300, 0., 300);
1212   Add2ESDsList(hESDMomentum, AliMUONQAIndices::kESDMomentum, !expert, image);
1213
1214   TH1F* hESDPt = new TH1F("hESDPt", "transverse momentum distribution;p_{t} (GeV/c)", 200, 0., 50);
1215   Add2ESDsList(hESDPt, AliMUONQAIndices::kESDPt, !expert, image);
1216
1217   TH1F* hESDRapidity = new TH1F("hESDRapidity", "rapidity distribution;rapidity", 200, -4.5, -2.);
1218   Add2ESDsList(hESDRapidity, AliMUONQAIndices::kESDRapidity, !expert, image);
1219
1220   TH1F* hESDChi2 = new TH1F("hESDChi2", "normalized #chi^{2} distribution;#chi^{2} / ndf", 500, 0., 50.);
1221   Add2ESDsList(hESDChi2, AliMUONQAIndices::kESDChi2, !expert, image);
1222   
1223   TH1F* hESDProbChi2 = new TH1F("hESDProbChi2", "distribution of probability of #chi^{2};prob(#chi^{2})", 100, 0., 1.);
1224   Add2ESDsList(hESDProbChi2, AliMUONQAIndices::kESDProbChi2, !expert, image);
1225   
1226   TH1F* hESDThetaX = new TH1F("hESDThetaX", "#theta_{X} distribution;#theta_{X} (degree)", 360, -180., 180);
1227   Add2ESDsList(hESDThetaX, AliMUONQAIndices::kESDThetaX, !expert, image);
1228   
1229   TH1F* hESDThetaY = new TH1F("hESDThetaY", "#theta_{Y} distribution;#theta_{Y} (degree)", 360, -180., 180);
1230   Add2ESDsList(hESDThetaY, AliMUONQAIndices::kESDThetaY, !expert, image);
1231   
1232   // cluster info
1233   for (Int_t i = 0; i < nCh; i++) {
1234     Float_t rMax = AliMUONConstants::Rmax(i/2);
1235     TH2F* hESDClusterHitMap = new TH2F(Form("hESDClusterHitMap%d",i+1), Form("cluster position distribution in chamber %d;X (cm);Y (cm)",i+1),
1236                                        100, -rMax, rMax, 100, -rMax, rMax);
1237     Add2ESDsList(hESDClusterHitMap, AliMUONQAIndices::kESDClusterHitMap+i, expert, !image);
1238   }
1239   
1240   TH1F* hESDnClustersPerTrack = new TH1F("hESDnClustersPerTrack", "number of associated clusters per track;n_{clusters}", 20, 0., 20.);
1241   Add2ESDsList(hESDnClustersPerTrack, AliMUONQAIndices::kESDnClustersPerTrack, !expert, image);
1242   
1243   TH1F* hESDnClustersPerCh = new TH1F("hESDnClustersPerCh", "averaged number of clusters per chamber per track;chamber ID;<n_{clusters}>", nCh, -0.5, nCh-0.5);
1244   hESDnClustersPerCh->SetFillColor(kRed);
1245   Add2ESDsList(hESDnClustersPerCh, AliMUONQAIndices::kESDnClustersPerCh, !expert, image);
1246   
1247   TH1F* hESDnClustersPerDE = new TH1F("hESDnClustersPerDE", "averaged number of clusters per DE per track;DetElem ID;<n_{clusters}>", nDE+1, -0.5, nDE+0.5);
1248   hESDnClustersPerDE->SetFillColor(kRed);
1249   Add2ESDsList(hESDnClustersPerDE, AliMUONQAIndices::kESDnClustersPerDE, !expert, image);
1250   
1251   for (Int_t i = 0; i < nCh; i++) {
1252     TH1F* hESDClusterChargeInCh = new TH1F(Form("hESDClusterChargeInCh%d",i+1), Form("cluster charge distribution in chamber %d;charge (fC)",i+1), 100, 0., 1000.);
1253     Add2ESDsList(hESDClusterChargeInCh, AliMUONQAIndices::kESDClusterChargeInCh+i, expert, !image);
1254   }
1255   
1256   TH1F* hESDClusterChargePerChMean = new TH1F("hESDClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (fC)", nCh, -0.5, nCh-0.5);
1257   hESDClusterChargePerChMean->SetOption("P");
1258   hESDClusterChargePerChMean->SetMarkerStyle(kFullDotMedium);
1259   hESDClusterChargePerChMean->SetMarkerColor(kRed);
1260   Add2ESDsList(hESDClusterChargePerChMean, AliMUONQAIndices::kESDClusterChargePerChMean, !expert, image);
1261   
1262   TH1F* hESDClusterChargePerChSigma = new TH1F("hESDClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (fC)", nCh, -0.5, nCh-0.5);
1263   hESDClusterChargePerChSigma->SetOption("P");
1264   hESDClusterChargePerChSigma->SetMarkerStyle(kFullDotMedium);
1265   hESDClusterChargePerChSigma->SetMarkerColor(kRed);
1266   Add2ESDsList(hESDClusterChargePerChSigma, AliMUONQAIndices::kESDClusterChargePerChSigma, !expert, image);
1267   
1268   TH1F* hESDClusterChargePerDE = new TH1F("hESDClusterChargePerDE", "cluster mean charge per DE;DetElem ID;<charge> (fC)", nDE+1, -0.5, nDE+0.5);
1269   hESDClusterChargePerDE->SetOption("P");
1270   hESDClusterChargePerDE->SetMarkerStyle(kFullDotMedium);
1271   hESDClusterChargePerDE->SetMarkerColor(kRed);
1272   Add2ESDsList(hESDClusterChargePerDE, AliMUONQAIndices::kESDClusterChargePerDE, !expert, image);
1273   
1274   for (Int_t i = 0; i < nCh; i++) {
1275     TH1F* hESDClusterSizeInCh = new TH1F(Form("hESDClusterSizeInCh%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads})",i+1), 200, 0., 200.);
1276     Add2ESDsList(hESDClusterSizeInCh, AliMUONQAIndices::kESDClusterSizeInCh+i, expert, !image);
1277   }
1278   
1279   TH1F* hESDClusterSizePerChMean = new TH1F("hESDClusterSizePerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh, -0.5, nCh-0.5);
1280   hESDClusterSizePerChMean->SetOption("P");
1281   hESDClusterSizePerChMean->SetMarkerStyle(kFullDotMedium);
1282   hESDClusterSizePerChMean->SetMarkerColor(kRed);
1283   Add2ESDsList(hESDClusterSizePerChMean, AliMUONQAIndices::kESDClusterSizePerChMean, !expert, image);
1284   
1285   TH1F* hESDClusterSizePerChSigma = new TH1F("hESDClusterSizePerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh, -0.5, nCh-0.5);
1286   hESDClusterSizePerChSigma->SetOption("P");
1287   hESDClusterSizePerChSigma->SetMarkerStyle(kFullDotMedium);
1288   hESDClusterSizePerChSigma->SetMarkerColor(kRed);
1289   Add2ESDsList(hESDClusterSizePerChSigma, AliMUONQAIndices::kESDClusterSizePerChSigma, !expert, image);
1290   
1291   TH1F* hESDClusterSizePerDE = new TH1F("hESDClusterSizePerDE", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", nDE+1, -0.5, nDE+0.5);
1292   hESDClusterSizePerDE->SetOption("P");
1293   hESDClusterSizePerDE->SetMarkerStyle(kFullDotMedium);
1294   hESDClusterSizePerDE->SetMarkerColor(kRed);
1295   Add2ESDsList(hESDClusterSizePerDE, AliMUONQAIndices::kESDClusterSizePerDE, !expert, image);
1296   
1297   // cluster - track info
1298   for (Int_t i = 0; i < nCh; i++) {
1299     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.);
1300     Add2ESDsList(hESDResidualXInCh, AliMUONQAIndices::kESDResidualXInCh+i, expert, !image);
1301     
1302     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.);
1303     Add2ESDsList(hESDResidualYInCh, AliMUONQAIndices::kESDResidualYInCh+i, expert, !image);
1304     
1305     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);
1306     Add2ESDsList(hESDLocalChi2XInCh, AliMUONQAIndices::kESDLocalChi2XInCh+i, expert, !image);
1307     
1308     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);
1309     Add2ESDsList(hESDLocalChi2YInCh, AliMUONQAIndices::kESDLocalChi2YInCh+i, expert, !image);
1310     
1311     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);
1312     Add2ESDsList(hESDLocalChi2InCh, AliMUONQAIndices::kESDLocalChi2InCh+i, expert, !image);
1313   }
1314   
1315   TH1F* hESDResidualXPerChMean = new TH1F("hESDResidualXPerChMean", "cluster-track residual-X per Ch: mean;chamber ID;<#Delta_{X}> (cm)", nCh, -0.5, nCh-0.5);
1316   hESDResidualXPerChMean->SetOption("P");
1317   hESDResidualXPerChMean->SetMarkerStyle(kFullDotMedium);
1318   hESDResidualXPerChMean->SetMarkerColor(kRed);
1319   Add2ESDsList(hESDResidualXPerChMean, AliMUONQAIndices::kESDResidualXPerChMean, !expert, image);
1320   
1321   TH1F* hESDResidualYPerChMean = new TH1F("hESDResidualYPerChMean", "cluster-track residual-Y per Ch: mean;chamber ID;<#Delta_{Y}> (cm)", nCh, -0.5, nCh-0.5);
1322   hESDResidualYPerChMean->SetOption("P");
1323   hESDResidualYPerChMean->SetMarkerStyle(kFullDotMedium);
1324   hESDResidualYPerChMean->SetMarkerColor(kRed);
1325   Add2ESDsList(hESDResidualYPerChMean, AliMUONQAIndices::kESDResidualYPerChMean, !expert, image);
1326   
1327   TH1F* hESDResidualXPerChSigma = new TH1F("hESDResidualXPerChSigma", "cluster-track residual-X per Ch: sigma;chamber ID;#sigma_{X} (cm)", nCh, -0.5, nCh-0.5);
1328   hESDResidualXPerChSigma->SetOption("P");
1329   hESDResidualXPerChSigma->SetMarkerStyle(kFullDotMedium);
1330   hESDResidualXPerChSigma->SetMarkerColor(kRed);
1331   Add2ESDsList(hESDResidualXPerChSigma, AliMUONQAIndices::kESDResidualXPerChSigma, !expert, image);
1332   
1333   TH1F* hESDResidualYPerChSigma = new TH1F("hESDResidualYPerChSigma", "cluster-track residual-Y per Ch: sigma;chamber ID;#sigma_{Y} (cm)", nCh, -0.5, nCh-0.5);
1334   hESDResidualYPerChSigma->SetOption("P");
1335   hESDResidualYPerChSigma->SetMarkerStyle(kFullDotMedium);
1336   hESDResidualYPerChSigma->SetMarkerColor(kRed);
1337   Add2ESDsList(hESDResidualYPerChSigma, AliMUONQAIndices::kESDResidualYPerChSigma, !expert, image);
1338   
1339   TH1F* hESDLocalChi2XPerChMean = new TH1F("hESDLocalChi2XPerCh", "local chi2-X per Ch: mean;chamber ID;<local #chi^{2}_{X}>", nCh, -0.5, nCh-0.5);
1340   hESDLocalChi2XPerChMean->SetOption("P");
1341   hESDLocalChi2XPerChMean->SetMarkerStyle(kFullDotMedium);
1342   hESDLocalChi2XPerChMean->SetMarkerColor(kRed);
1343   Add2ESDsList(hESDLocalChi2XPerChMean, AliMUONQAIndices::kESDLocalChi2XPerChMean, !expert, image);
1344   
1345   TH1F* hESDLocalChi2YPerChMean = new TH1F("hESDLocalChi2YPerCh", "local chi2-Y per Ch: mean;chamber ID;<local #chi^{2}_{Y}>", nCh, -0.5, nCh-0.5);
1346   hESDLocalChi2YPerChMean->SetOption("P");
1347   hESDLocalChi2YPerChMean->SetMarkerStyle(kFullDotMedium);
1348   hESDLocalChi2YPerChMean->SetMarkerColor(kRed);
1349   Add2ESDsList(hESDLocalChi2YPerChMean, AliMUONQAIndices::kESDLocalChi2YPerChMean, !expert, image);
1350   
1351   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);
1352   hESDLocalChi2PerChMean->SetOption("P");
1353   hESDLocalChi2PerChMean->SetMarkerStyle(kFullDotMedium);
1354   hESDLocalChi2PerChMean->SetMarkerColor(kRed);
1355   Add2ESDsList(hESDLocalChi2PerChMean, AliMUONQAIndices::kESDLocalChi2PerChMean, !expert, image);
1356   
1357   TH1F* hESDResidualXPerDEMean = new TH1F("hESDResidualXPerDEMean", "cluster-track residual-X per DE: mean;DetElem ID;<#Delta_{X}> (cm)", nDE+1, -0.5, nDE+0.5);
1358   hESDResidualXPerDEMean->SetOption("P");
1359   hESDResidualXPerDEMean->SetMarkerStyle(kFullDotMedium);
1360   hESDResidualXPerDEMean->SetMarkerColor(kRed);
1361   Add2ESDsList(hESDResidualXPerDEMean, AliMUONQAIndices::kESDResidualXPerDEMean, !expert, image);
1362   
1363   TH1F* hESDResidualYPerDEMean = new TH1F("hESDResidualYPerDEMean", "cluster-track residual-Y per DE: mean;DetElem ID;<#Delta_{Y}> (cm)", nDE+1, -0.5, nDE+0.5);
1364   hESDResidualYPerDEMean->SetOption("P");
1365   hESDResidualYPerDEMean->SetMarkerStyle(kFullDotMedium);
1366   hESDResidualYPerDEMean->SetMarkerColor(kRed);
1367   Add2ESDsList(hESDResidualYPerDEMean, AliMUONQAIndices::kESDResidualYPerDEMean, !expert, image);
1368   
1369   TH1F* hESDResidualXPerDESigma = new TH1F("hESDResidualXPerDESigma", "cluster-track residual-X per DE: sigma;DetElem ID;#sigma_{X} (cm)", nDE+1, -0.5, nDE+0.5);
1370   hESDResidualXPerDESigma->SetOption("P");
1371   hESDResidualXPerDESigma->SetMarkerStyle(kFullDotMedium);
1372   hESDResidualXPerDESigma->SetMarkerColor(kRed);
1373   Add2ESDsList(hESDResidualXPerDESigma, AliMUONQAIndices::kESDResidualXPerDESigma, !expert, image);
1374   
1375   TH1F* hESDResidualYPerDESigma = new TH1F("hESDResidualYPerDESigma", "cluster-track residual-Y per DE: sigma;DetElem ID;#sigma_{Y} (cm)", nDE+1, -0.5, nDE+0.5);
1376   hESDResidualYPerDESigma->SetOption("P");
1377   hESDResidualYPerDESigma->SetMarkerStyle(kFullDotMedium);
1378   hESDResidualYPerDESigma->SetMarkerColor(kRed);
1379   Add2ESDsList(hESDResidualYPerDESigma, AliMUONQAIndices::kESDResidualYPerDESigma, !expert, image);
1380   
1381   TH1F* hESDLocalChi2XPerDEMean = new TH1F("hESDLocalChi2XPerDE", "local chi2-X per DE: mean;DetElem ID;<local #chi^{2}_{X}>", nDE+1, -0.5, nDE+0.5);
1382   hESDLocalChi2XPerDEMean->SetOption("P");
1383   hESDLocalChi2XPerDEMean->SetMarkerStyle(kFullDotMedium);
1384   hESDLocalChi2XPerDEMean->SetMarkerColor(kRed);
1385   Add2ESDsList(hESDLocalChi2XPerDEMean, AliMUONQAIndices::kESDLocalChi2XPerDEMean, !expert, image);
1386   
1387   TH1F* hESDLocalChi2YPerDEMean = new TH1F("hESDLocalChi2YPerDE", "local chi2-Y per DE: mean;DetElem ID;<local #chi^{2}_{Y}>", nDE+1, -0.5, nDE+0.5);
1388   hESDLocalChi2YPerDEMean->SetOption("P");
1389   hESDLocalChi2YPerDEMean->SetMarkerStyle(kFullDotMedium);
1390   hESDLocalChi2YPerDEMean->SetMarkerColor(kRed);
1391   Add2ESDsList(hESDLocalChi2YPerDEMean, AliMUONQAIndices::kESDLocalChi2YPerDEMean, !expert, image);
1392   
1393   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);
1394   hESDLocalChi2PerDEMean->SetOption("P");
1395   hESDLocalChi2PerDEMean->SetMarkerStyle(kFullDotMedium);
1396   hESDLocalChi2PerDEMean->SetMarkerColor(kRed);
1397   Add2ESDsList(hESDLocalChi2PerDEMean, AliMUONQAIndices::kESDLocalChi2PerDEMean, !expert, image);
1398   
1399   // intermediate histograms
1400   TH1F* hESDnTotClustersPerCh = new TH1F("hESDnTotClustersPerCh", "total number of associated clusters per chamber;chamber ID;#Sigma(n_{clusters})", nCh, -0.5, nCh-0.5);
1401   Add2ESDsList(hESDnTotClustersPerCh, AliMUONQAIndices::kESDnTotClustersPerCh, expert, !image);
1402   TH1F* hESDnTotClustersPerDE = new TH1F("hESDnTotClustersPerDE", "total number of associated clusters per DE;DetElem ID;#Sigma(n_{clusters})", nDE+1, -0.5, nDE+0.5);
1403   Add2ESDsList(hESDnTotClustersPerDE, AliMUONQAIndices::kESDnTotClustersPerDE, expert, !image);
1404   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);
1405   Add2ESDsList(hESDnTotFullClustersPerDE, AliMUONQAIndices::kESDnTotFullClustersPerDE, expert, !image);
1406   TH1F* hESDSumClusterChargePerDE = new TH1F("hESDSumClusterChargePerDE", "sum of cluster charge per DE;DetElem ID;#Sigma(charge) (fC)", nDE+1, -0.5, nDE+0.5);
1407   Add2ESDsList(hESDSumClusterChargePerDE, AliMUONQAIndices::kESDSumClusterChargePerDE, expert, !image);
1408   TH1F* hESDSumClusterSizePerDE = new TH1F("hESDSumClusterSizePerDE", "sum of cluster size per DE;DetElem ID;#Sigma(size) (n_{pads})", nDE+1, -0.5, nDE+0.5);
1409   Add2ESDsList(hESDSumClusterSizePerDE, AliMUONQAIndices::kESDSumClusterSizePerDE, expert, !image);
1410   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);
1411   Add2ESDsList(hESDSumResidualXPerDE, AliMUONQAIndices::kESDSumResidualXPerDE, expert, !image);
1412   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);
1413   Add2ESDsList(hESDSumResidualYPerDE, AliMUONQAIndices::kESDSumResidualYPerDE, expert, !image);
1414   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);
1415   Add2ESDsList(hESDSumResidualX2PerDE, AliMUONQAIndices::kESDSumResidualX2PerDE, expert, !image);
1416   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);
1417   Add2ESDsList(hESDSumResidualY2PerDE, AliMUONQAIndices::kESDSumResidualY2PerDE, expert, !image);
1418   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);
1419   Add2ESDsList(hESDSumLocalChi2XPerDE, AliMUONQAIndices::kESDSumLocalChi2XPerDE, expert, !image);
1420   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);
1421   Add2ESDsList(hESDSumLocalChi2YPerDE, AliMUONQAIndices::kESDSumLocalChi2YPerDE, expert, !image);
1422   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);
1423   Add2ESDsList(hESDSumLocalChi2PerDE, AliMUONQAIndices::kESDSumLocalChi2PerDE, expert, !image);
1424   //
1425   //ClonePerTrigClass(AliQAv1::kESDS); // this should be the last line  DONE at parent level
1426 }
1427
1428 //____________________________________________________________________________
1429 void AliMUONTrackerQADataMakerRec::MakeRaws(AliRawReader* rawReader)
1430 {
1431         /// make QA for rawdata tracker
1432         
1433   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1434
1435   /// forces init
1436   GetRawsData(AliMUONQAIndices::kTrackerBusPatchOccupancy);
1437   
1438   AliMUONTrackerDataMaker* dm = static_cast<AliMUONTrackerDataMaker*>(TrackerDataMaker(AliRecoParam::AConvert(Master()->GetEventSpecie())));
1439
1440   dm->SetRawReader(rawReader);
1441         
1442   Int_t eventType = rawReader->GetType();
1443   
1444   if (eventType == AliRawEventHeaderBase::kPhysicsEvent ) 
1445   {
1446     dm->ProcessEvent();
1447     
1448     FillEventSize(rawReader);
1449         
1450     if ( dm->LastEventWasEmpty() )
1451     {
1452       FillRawsData(AliMUONQAIndices::kTrackerReadoutStatus,1.0*AliMUONQAIndices::kTrackerRawNofEmptyEvents);
1453     }    
1454   }
1455   //
1456 }
1457
1458 //__________________________________________________________________
1459 void AliMUONTrackerQADataMakerRec::MakeDigits(TTree* digitsTree)         
1460 {
1461   /// makes data from Digits
1462   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1463   
1464   /// forces init
1465
1466   GetDigitsData(AliMUONQAIndices::kTrackerBusPatchOccupancy);
1467
1468   if (!fDigitStore)
1469     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
1470   fDigitStore->Connect(*digitsTree, false);
1471   digitsTree->GetEvent(0);
1472   
1473   TIter next(fDigitStore->CreateIterator());
1474   
1475   AliMUONVDigit* dig = 0x0;
1476   
1477   AliMUON2DMap oneEventData(true);
1478   
1479   while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) )
1480   {
1481     if ( dig->IsTracker() )
1482     {
1483       if ( dig->Charge() > 0.0 )
1484       {
1485         
1486         Int_t detElemId = dig->DetElemId();
1487         Int_t manuId = dig->ManuId();
1488         
1489         AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(detElemId,manuId));
1490         if (!param)
1491         {
1492           param = new AliMUONCalibParamND(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,
1493                                           AliMUONVCalibParam::InvalidFloatValue());
1494           oneEventData.Add(param);
1495         }
1496         param->SetValueAsDouble(dig->ManuChannel(),0,dig->Charge());
1497       }
1498     }
1499   }
1500   TrackerCalData(AliRecoParam::AConvert(Master()->GetEventSpecie()))->Add(oneEventData);
1501   //
1502 }
1503
1504 //____________________________________________________________________________
1505 void AliMUONTrackerQADataMakerRec::MakeRecPoints(TTree* clustersTree)
1506 {
1507         /// Fill histograms related to tracker clusters 
1508         
1509         // First things first : do we have clusters in the TreeR ?
1510         // In "normal" production mode, it should be perfectly normal
1511         // *not* to have them.
1512         // But if for some reason we de-activated the combined tracking,
1513         // then we have clusters in TreeR, so let's take that opportunity
1514         // to QA them...
1515         
1516   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1517   // Forces init by requesting an histogram
1518   GetRecPointsData(AliMUONQAIndices::kTrackerBusPatchOccupancy); 
1519
1520         if (!fClusterStore)
1521         {
1522           AliCodeTimerAuto("ClusterStore creation",1);
1523                 fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
1524                 if (!fClusterStore) 
1525                 {
1526                         return;
1527                 }
1528         }
1529         
1530         fClusterStore->Connect(*clustersTree,kFALSE);
1531         clustersTree->GetEvent(0);
1532
1533         TIter next(fClusterStore->CreateIterator());
1534         AliMUONVCluster* cluster;
1535         
1536   AliMUONQAMappingCheck* mcr = MappingCheckRecPoints(AliRecoParam::AConvert(Master()->GetEventSpecie()));
1537   
1538   if ( mcr ) mcr->NewEvent();
1539   
1540   AliMUON2DMap oneEventData(true);
1541   
1542         while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) )
1543         {
1544                 Int_t detElemId = cluster->GetDetElemId();
1545                 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
1546                 
1547                 FillRecPointsData(AliMUONQAIndices::kTrackerNumberOfClustersPerDE,detElemId);
1548                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerDE+detElemId,cluster->GetCharge());
1549                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerDE+detElemId,cluster->GetNDigits());
1550
1551                 FillRecPointsData(AliMUONQAIndices::kTrackerNumberOfClustersPerChamber,chamberId);
1552                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterChargePerChamber+chamberId,cluster->GetCharge());
1553                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterMultiplicityPerChamber+chamberId,cluster->GetNDigits());
1554                 FillRecPointsData(AliMUONQAIndices::kTrackerClusterHitMapPerChamber+chamberId,cluster->GetX(),cluster->GetY());
1555                 
1556     if ( mcr ) mcr->Store(*cluster);
1557     
1558     for ( int i = 0; i < cluster->GetNDigits(); ++i ) 
1559     {
1560       UInt_t digitId = cluster->GetDigitId(i);
1561       
1562       Int_t manuId = AliMUONVDigit::ManuId(digitId);
1563       Int_t manuChannel = AliMUONVDigit::ManuChannel(digitId);
1564       
1565       AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(detElemId,manuId));
1566       if (!param)
1567       {
1568         param = new AliMUONCalibParamND(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
1569         oneEventData.Add(param);
1570       }
1571       param->SetValueAsDouble(manuChannel,0,1.0);
1572     }
1573         }
1574         
1575   TrackerRecData(AliRecoParam::AConvert(Master()->GetEventSpecie()))->Add(oneEventData);    
1576
1577   fClusterStore->Clear();
1578   //
1579 }
1580
1581 //____________________________________________________________________________
1582 void AliMUONTrackerQADataMakerRec::MakeESDs(AliESDEvent* esd)
1583 {
1584   /// make QA data from ESDs
1585
1586   AliCodeTimerAuto(Form("%s",AliRecoParam::GetEventSpecieName(AliRecoParam::AConvert(Master()->GetEventSpecie()))),0);
1587    
1588   // load ESD event in the interface
1589   if (!AliMUONESDInterface::GetTracker()) {
1590     if (GetRecoParam()) AliMUONESDInterface::ResetTracker(GetRecoParam(), kFALSE);
1591     else AliError("Unable to get recoParam: use default ones for residual calculation");
1592   }
1593   
1594   
1595   Int_t nTrkTracks = 0, nTrackMatchTrig = 0;
1596   
1597   // loop over tracks
1598   Int_t nTracks = (Int_t) esd->GetNumberOfMuonTracks(); 
1599   for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) {
1600     
1601     // get the ESD track and skip "ghosts"
1602     AliESDMuonTrack* esdTrack = esd->GetMuonTrack(iTrack);
1603     if (!esdTrack->ContainTrackerData()) continue;
1604     nTrkTracks++;
1605     
1606     // get corresponding MUON track
1607     AliMUONTrack track;
1608     AliMUONESDInterface::ESDToMUON(*esdTrack, track);
1609     
1610     if (esdTrack->ContainTriggerData()) nTrackMatchTrig++;
1611     
1612     FillESDsData(AliMUONQAIndices::kESDMomentum,esdTrack->P());
1613     FillESDsData(AliMUONQAIndices::kESDPt,esdTrack->Pt());
1614     FillESDsData(AliMUONQAIndices::kESDRapidity,esdTrack->Y());
1615     FillESDsData(AliMUONQAIndices::kESDChi2,track.GetNormalizedChi2());
1616     FillESDsData(AliMUONQAIndices::kESDProbChi2,TMath::Prob(track.GetGlobalChi2(),track.GetNDF()));
1617     FillESDsData(AliMUONQAIndices::kESDThetaX,esdTrack->GetThetaXUncorrected() / TMath::Pi() * 180.);
1618     FillESDsData(AliMUONQAIndices::kESDThetaY,esdTrack->GetThetaYUncorrected() / TMath::Pi() * 180.);
1619     FillESDsData(AliMUONQAIndices::kESDnClustersPerTrack,track.GetNClusters());
1620     
1621     // loop over clusters
1622     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First());
1623     while (trackParam) {
1624       
1625       AliMUONVCluster* cluster = trackParam->GetClusterPtr();
1626       Int_t chId = cluster->GetChamberId();
1627       Int_t deID = cluster->GetDetElemId();
1628       Double_t residualX = cluster->GetX() - trackParam->GetNonBendingCoor();
1629       Double_t residualY = cluster->GetY() - trackParam->GetBendingCoor();
1630       Double_t sigmaResidualX2 = cluster->GetErrX2() - trackParam->GetCovariances()(0,0);
1631       Double_t sigmaResidualY2 = cluster->GetErrY2() - trackParam->GetCovariances()(2,2);
1632       Double_t localChi2X = (sigmaResidualX2 > 0.) ? residualX*residualX/sigmaResidualX2 : 0.;
1633       Double_t localChi2Y = (sigmaResidualY2 > 0.) ? residualY*residualY/sigmaResidualY2 : 0.;
1634       Double_t localChi2 = 0.5 * trackParam->GetLocalChi2();
1635       
1636       FillESDsData(AliMUONQAIndices::kESDClusterHitMap+chId,cluster->GetX(), cluster->GetY());
1637       
1638       FillESDsData(AliMUONQAIndices::kESDnTotClustersPerCh,chId);
1639       FillESDsData(AliMUONQAIndices::kESDnTotClustersPerDE,deID);
1640       
1641       FillESDsData(AliMUONQAIndices::kESDClusterChargeInCh+chId,cluster->GetCharge());
1642       FillESDsData(AliMUONQAIndices::kESDSumClusterChargePerDE,deID, cluster->GetCharge());
1643       
1644       if (cluster->GetNDigits() > 0) { // discard clusters with pad not stored in ESD
1645         FillESDsData(AliMUONQAIndices::kESDnTotFullClustersPerDE,deID);
1646         FillESDsData(AliMUONQAIndices::kESDClusterSizeInCh+chId,cluster->GetNDigits());
1647         FillESDsData(AliMUONQAIndices::kESDSumClusterSizePerDE,deID, cluster->GetNDigits());
1648       }
1649       
1650       FillESDsData(AliMUONQAIndices::kESDResidualXInCh+chId,residualX);
1651       FillESDsData(AliMUONQAIndices::kESDResidualYInCh+chId,residualY);
1652       FillESDsData(AliMUONQAIndices::kESDSumResidualXPerDE,deID, residualX);
1653       FillESDsData(AliMUONQAIndices::kESDSumResidualYPerDE,deID, residualY);
1654       FillESDsData(AliMUONQAIndices::kESDSumResidualX2PerDE,deID, residualX*residualX);
1655       FillESDsData(AliMUONQAIndices::kESDSumResidualY2PerDE,deID, residualY*residualY);
1656       
1657       FillESDsData(AliMUONQAIndices::kESDLocalChi2XInCh+chId,localChi2X);
1658       FillESDsData(AliMUONQAIndices::kESDLocalChi2YInCh+chId,localChi2Y);
1659       FillESDsData(AliMUONQAIndices::kESDLocalChi2InCh+chId,localChi2);
1660       FillESDsData(AliMUONQAIndices::kESDSumLocalChi2XPerDE,deID, localChi2X);
1661       FillESDsData(AliMUONQAIndices::kESDSumLocalChi2YPerDE,deID, localChi2Y);
1662       FillESDsData(AliMUONQAIndices::kESDSumLocalChi2PerDE,deID, localChi2);
1663       
1664       trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
1665       
1666     }
1667     
1668   }
1669
1670   FillESDsData(AliMUONQAIndices::kESDnTracks,nTrkTracks);
1671   FillESDsData(AliMUONQAIndices::kESDMatchTrig,nTrackMatchTrig);
1672   //
1673 }
1674
1675 //____________________________________________________________________________ 
1676 AliMUONVTrackerData* AliMUONTrackerQADataMakerRec::GetTrackerData() const
1677
1678   /// Return tracker data
1679   
1680   return TrackerDataMaker(AliRecoParam::AConvert(Master()->GetEventSpecie()))->Data(); 
1681 }
1682
1683 //____________________________________________________________________________ 
1684 void
1685 AliMUONTrackerQADataMakerRec::ResetDetectorRaws(TObjArray* list)
1686 {
1687   /// Reset those histograms that must be reset (and only those), plus
1688   /// the trackerdata itself.
1689   
1690   TIter next(list);
1691   TObject* o;
1692   while ( ( o = next() ) )
1693   {
1694     TH1* h = dynamic_cast<TH1*>(o);
1695     if (h)
1696     {
1697       TString hn(h->GetName());
1698       
1699       if ( !hn.Contains("TrackerBusPatchConfig") )
1700       {
1701         AliDebug(1,Form("Resetting %s",hn.Data()));
1702
1703         h->Reset();
1704       }
1705       else
1706       {
1707         AliDebug(1,Form("Will not reset histogram %s",hn.Data()));          
1708       }
1709       continue;
1710     }
1711     // RS account for the case when this histos were cloned per trigger class
1712     TObjArray* harr = dynamic_cast<TObjArray*>(o);
1713     if (harr) {
1714       TString hn(harr->GetName());
1715       if ( !hn.Contains("TrackerBusPatchConfig") ) {
1716
1717         AliDebug(1,Form("Resetting clones of %s",hn.Data()));
1718
1719         TIter nextCl(harr);
1720         TH1* hc = 0;
1721         while ( (hc=dynamic_cast<TH1*>(nextCl())) ) hc->Reset();
1722       }
1723       else {
1724         AliDebug(1,Form("Will not reset clones of histogram %s",hn.Data()));  
1725       }
1726       continue;
1727     }
1728     //
1729     AliMUONVTrackerData* d = dynamic_cast<AliMUONVTrackerData*>(o);
1730     if (d) {
1731       AliDebug(1,Form("Resetting %s",d->GetName()));
1732       d->Clear();
1733     }
1734     else {
1735       AliError(Form("Found an object of class %s. Do not know how to reset.",o->ClassName()));
1736     }
1737   }
1738
1739   fLogger->Clear();
1740 }
1741
1742 //____________________________________________________________________________ 
1743 TObjArray* AliMUONTrackerQADataMakerRec::GetArray(TObjArray*& array, Bool_t create)
1744 {
1745   /// Get (or create) the array
1746
1747   if ( ! array ) 
1748   {
1749     if ( create ) 
1750     {
1751       array = new TObjArray(AliRecoParam::kNSpecies);
1752     }
1753   }
1754   
1755   return array;
1756 }
1757
1758 //____________________________________________________________________________ 
1759 AliMUONVTrackerDataMaker* 
1760 AliMUONTrackerQADataMakerRec::TrackerDataMaker(Int_t specieIndex)  const
1761 {
1762   /// const version of the getter
1763   if ( fTrackerDataMakerArray )
1764   {
1765     return static_cast<AliMUONVTrackerDataMaker*>(fTrackerDataMakerArray->At(specieIndex));
1766   }
1767   return 0x0;
1768 }
1769
1770 //____________________________________________________________________________ 
1771 AliMUONVTrackerDataMaker* 
1772 AliMUONTrackerQADataMakerRec::TrackerDataMaker(Int_t specieIndex, Bool_t create)
1773 {
1774   /// Get (or create) TrackerDataMaker object for a given specie
1775   
1776   TObjArray* array = GetArray(fTrackerDataMakerArray,create);
1777   TObject* o(0x0);
1778   
1779   if ( array ) 
1780   {
1781     array->SetOwner(kTRUE);
1782     o = array->At(specieIndex);
1783     if (!o && create)
1784     {
1785       
1786       AliMUONTrackerDataMaker* dm = new AliMUONTrackerDataMaker(0x0,
1787                                                                 AliCDBManager::Instance()->GetRun(),
1788                                                                 0x0,
1789                                                                 "",
1790                                                                 "",
1791                                                                 kFALSE,
1792                                                                 0.0,0.0);
1793       
1794       if (!fLogger) fLogger = new AliMUONLogger(-1); // note that we share the logger between species... should not be a big deal though
1795       dm->EnableErrorLogger(fLogger);
1796       dm->Data()->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level    
1797       dm->Data()->SetName("RawCharges");
1798       dm->SetRunning(kTRUE);
1799
1800       o = dm;
1801       array->AddAt(o,specieIndex);      
1802     }
1803   }
1804   return static_cast<AliMUONVTrackerDataMaker*>(o);
1805 }
1806
1807 //____________________________________________________________________________ 
1808 AliMUONVTrackerData* 
1809 AliMUONTrackerQADataMakerRec::TrackerCalData(Int_t specieIndex, Bool_t create)
1810 {
1811   TObjArray* array = GetArray(fTrackerCalDataArray,create);
1812   TObject* o(0x0);
1813   
1814   if (array)
1815   {
1816     o = array->At(specieIndex);
1817     if (!o && create)
1818     {
1819       AliMUONTrackerData* data = new AliMUONTrackerData("CalCharges",Form("Calibrated charges (fC) %s",GetRecoParam()->GetCalibrationMode()),1);
1820       data->SetDimensionName(0,"charge");
1821       data->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level
1822       o=data;
1823       array->AddAt(o,specieIndex);
1824     }
1825   }
1826   return static_cast<AliMUONVTrackerData*>(o);
1827 }
1828
1829 //____________________________________________________________________________ 
1830 AliMUONVTrackerData* 
1831 AliMUONTrackerQADataMakerRec::TrackerRecData(Int_t specieIndex, Bool_t create)
1832 {
1833   TObjArray* array = GetArray(fTrackerRecDataArray,create);
1834   TObject* o(0x0);
1835   
1836   if (array)
1837   {
1838     o = array->At(specieIndex);
1839     if (!o && create)
1840     {
1841       AliMUONTrackerData* data = new AliMUONTrackerData("RecCharges",Form("Calibrated charges (fC) %s for digits belonging to a reconstructed cluster",GetRecoParam()->GetCalibrationMode()),1);
1842       data->SetDimensionName(0,"one");
1843       data->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level
1844       o=data;
1845       array->AddAt(o,specieIndex);
1846     }
1847   }
1848   return static_cast<AliMUONVTrackerData*>(o);
1849 }
1850
1851 //____________________________________________________________________________ 
1852 AliMUONQAMappingCheck* 
1853 AliMUONTrackerQADataMakerRec::MappingCheckRecPoints(Int_t specieIndex, Bool_t create)
1854 {
1855   TObjArray* array = GetArray(fMappingCheckRecPointsArray,create);
1856   TObject* o(0x0);
1857   
1858   if (array)
1859   {
1860     o = array->At(specieIndex);
1861     array->SetOwner(kTRUE);
1862     if (!o && create)
1863     {
1864       AliMUONQAMappingCheck* mcheck = new AliMUONQAMappingCheck(RunNumber()); 
1865       o=mcheck;
1866       array->AddAt(o,specieIndex);
1867     }
1868   }
1869   return static_cast<AliMUONQAMappingCheck*>(o);
1870 }