Transfer of the initialisation of the QA Data objects in the framework; clean the...
[u/mrichter/AliRoot.git] / MUON / AliMUONQADataMakerRec.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 // $Id$
17
18 // --- MUON header files ---
19 #include "AliMUONQADataMakerRec.h"
20
21 #include "AliMUON2DMap.h"
22 #include "AliMUONCluster.h"  
23 #include "AliMUONConstants.h"  
24 #include "AliMUONDDLTrigger.h"
25 #include "AliMUONDarcHeader.h"
26 #include "AliMUONDigitMaker.h"
27 #include "AliMUONLocalStruct.h"
28 #include "AliMUONLocalTrigger.h"
29 #include "AliMUONRawStreamTracker.h"
30 #include "AliMUONRawStreamTrigger.h"
31 #include "AliMUONRegHeader.h"
32 #include "AliMUONTrackerDataMaker.h"
33 #include "AliMUONTriggerDisplay.h"
34 #include "AliMUONVCluster.h"
35 #include "AliMUONVClusterStore.h"
36 #include "AliMUONVDigit.h"
37 #include "AliMUONVDigitStore.h"
38 #include "AliMUONVTrackerData.h"
39 #include "AliMUONVTriggerStore.h"
40 #include "AliMUONTrack.h"
41 #include "AliMUONTrackParam.h"
42 #include "AliMUONESDInterface.h"
43 #include "AliMUONCalibrationData.h"
44 #include "AliMpBusPatch.h"
45 #include "AliMpCDB.h"
46 #include "AliMpConstants.h"
47 #include "AliMpDDLStore.h"
48 #include "AliMpDEIterator.h"
49 #include "AliMpDEManager.h"
50 #include "AliMpLocalBoard.h"
51 #include "AliMpStationType.h"
52 #include "AliMpTriggerCrate.h"
53 #include "AliMpDCSNamer.h"
54 #include "AliRawEventHeaderBase.h"
55
56 // --- AliRoot header files ---
57 #include "AliCDBManager.h"
58 #include "AliCDBStorage.h"
59 #include "AliESDEvent.h"
60 #include "AliESDMuonTrack.h"
61 #include "AliESDMuonCluster.h"
62 #include "AliLog.h"
63 #include "AliRawReader.h"
64 #include "AliQAChecker.h"
65 #include "AliCodeTimer.h"
66 #include "AliDCSValue.h"
67 #include "AliMUONVDigit.h"
68
69 // --- ROOT system ---
70 #include <TClonesArray.h>
71 #include <TFile.h> 
72 #include <TH1F.h> 
73 #include <TH1I.h> 
74 #include <TH2F.h>
75 #include <TH3F.h> 
76 #include <Riostream.h>
77
78 //-----------------------------------------------------------------------------
79 /// \class AliMUONQADataMakerRec
80 ///
81 /// MUON base class for quality assurance data (histo) maker
82 ///
83 /// \author C. Finck, D. Stocco, L. Aphecetche
84
85 /// \cond CLASSIMP
86 ClassImp(AliMUONQADataMakerRec)
87 /// \endcond
88            
89 //____________________________________________________________________________ 
90 AliMUONQADataMakerRec::AliMUONQADataMakerRec() : 
91 AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kMUON), "MUON Quality Assurance Data Maker"),
92 fIsInitRaws(kFALSE),
93 fIsInitRecPointsTracker(kFALSE),
94 fIsInitRecPointsTrigger(kFALSE),
95 fIsInitESDs(kFALSE),
96 fDigitStore(0x0),
97 fTriggerStore(0x0),
98 fDigitMaker(0x0),
99 fClusterStore(0x0),
100 fTrackerDataMaker(0x0)
101 {
102     /// ctor
103         
104   AliDebug(AliQAv1::GetQADebugLevel(),"");
105
106         Ctor();
107 }
108
109 //____________________________________________________________________________ 
110 void
111 AliMUONQADataMakerRec::Ctor()
112 {
113         /// Init some members
114         fDigitStore = AliMUONVDigitStore::Create("AliMUONDigitStoreV1");
115         fDigitMaker = new AliMUONDigitMaker(kTRUE);
116 }
117
118 //____________________________________________________________________________ 
119 AliMUONQADataMakerRec::AliMUONQADataMakerRec(const AliMUONQADataMakerRec& qadm) :
120 AliQADataMakerRec(qadm),
121 fIsInitRaws(kFALSE),
122 fIsInitRecPointsTracker(kFALSE),
123 fIsInitRecPointsTrigger(kFALSE),
124 fIsInitESDs(kFALSE),
125 fDigitStore(0x0),
126 fTriggerStore(0x0),
127 fDigitMaker(0x0),
128 fClusterStore(0x0),
129 fTrackerDataMaker(0x0)
130 {
131     ///copy ctor 
132
133   AliDebug(AliQAv1::GetQADebugLevel(),"");
134
135
136     SetName((const char*)qadm.GetName()) ; 
137     SetTitle((const char*)qadm.GetTitle()); 
138
139         // Do not copy the digit store and digit maker, but create its own ones
140         
141         Ctor();
142         
143 }
144
145 //__________________________________________________________________
146 AliMUONQADataMakerRec& AliMUONQADataMakerRec::operator = (const AliMUONQADataMakerRec& qadm )
147 {
148   /// Assignment operator
149
150   AliDebug(AliQAv1::GetQADebugLevel(),"");
151
152   // check assignment to self
153   if (this == &qadm) return *this;
154
155   this->~AliMUONQADataMakerRec();
156   new(this) AliMUONQADataMakerRec(qadm);
157   return *this;
158 }
159
160 //__________________________________________________________________
161 AliMUONQADataMakerRec::~AliMUONQADataMakerRec()
162 {
163     /// dtor
164   
165   AliDebug(AliQAv1::GetQADebugLevel(),"");
166
167   AliCodeTimerAuto("");
168   
169   delete fDigitStore;
170   delete fTriggerStore;
171   delete fDigitMaker;
172   delete fClusterStore;
173   delete fTrackerDataMaker;
174 }
175
176 //____________________________________________________________________________ 
177 void AliMUONQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray** list)
178 {
179   ///Detector specific actions at end of cycle
180   
181   AliCodeTimerAuto("");
182   
183   // Display trigger histos in a more user friendly way
184   DisplayTriggerInfo(task);
185   
186   for (Int_t specie = 0 ; specie < AliRecoParam::kNSpecies ; specie++) 
187   {
188     if (! IsValidEventSpecie(specie, list)  ) 
189       continue ;
190     SetEventSpecie(AliRecoParam::ConvertIndex(specie)) ; 
191     if ( task == AliQAv1::kRAWS && fTrackerDataMaker ) 
192       {
193
194         if ( !GetRawsData(kTrackerBusPatchOccupancy) ) continue;
195         
196         TIter next(list[specie]);
197         TObject* o;
198         Bool_t alreadyThere(kFALSE);
199         while ( ( o = next() ) && !alreadyThere )
200           {
201             TString classname(o->ClassName());
202             if ( classname.Contains("TrackerData") ) alreadyThere = kTRUE;
203           }
204         if (!alreadyThere && fTrackerDataMaker) 
205           {
206           AliDebug(AliQAv1::GetQADebugLevel(), "Adding fTrackerDataMaker to the list of qa objects");
207             list[specie]->AddAt(fTrackerDataMaker->Data(),(Int_t)kTrackerData);
208           }
209           if ( fTrackerDataMaker ) 
210             {
211               TH1* hbp = GetRawsData(kTrackerBusPatchOccupancy);
212               hbp->Reset();
213               TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
214               AliMpBusPatch* bp(0x0);
215               AliMUONVTrackerData* data = fTrackerDataMaker->Data();
216               Int_t occDim = 2;
217       
218               while ( ( bp = static_cast<AliMpBusPatch*>(nextBP())) )
219                 {
220                   Int_t busPatchId = bp->GetId();
221                   Int_t bin = hbp->FindBin(busPatchId);
222                   hbp->SetBinContent(bin,data->BusPatch(busPatchId,occDim));
223                 }
224             }
225       }
226     
227     // Normalize RecPoints histos
228     if ( task == AliQAv1::kRECPOINTS ) {
229       
230       if (!GetRecPointsData(kTrackerClusterChargePerChMean)) continue;
231
232       TH1* hTrackerClusterChargePerChMean = GetRecPointsData(kTrackerClusterChargePerChMean);
233       TH1* hTrackerClusterChargePerChSigma = GetRecPointsData(kTrackerClusterChargePerChSigma);
234       TH1* hTrackerClusterMultiplicityPerChMean = GetRecPointsData(kTrackerClusterMultiplicityPerChMean);
235       TH1* hTrackerClusterMultiplicityPerChSigma = GetRecPointsData(kTrackerClusterMultiplicityPerChSigma);
236       TH1* hTrackerClusterChargePerDEMean = GetRecPointsData(kTrackerClusterChargePerDEMean);
237       TH1* hTrackerClusterMultiplicityPerDEMean = GetRecPointsData(kTrackerClusterMultiplicityPerDEMean);
238       
239       // loop over chambers
240       for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
241         
242         TH1* hTrackerClusterChargePerChamber = GetRecPointsData(kTrackerClusterChargePerChamber+iCh);
243         Double_t sigmaCharge = hTrackerClusterChargePerChamber->GetRMS();
244         hTrackerClusterChargePerChMean->SetBinContent(iCh+1, hTrackerClusterChargePerChamber->GetMean());
245         hTrackerClusterChargePerChMean->SetBinError(iCh+1, hTrackerClusterChargePerChamber->GetMeanError());
246         hTrackerClusterChargePerChSigma->SetBinContent(iCh+1, sigmaCharge);
247         hTrackerClusterChargePerChSigma->SetBinError(iCh+1, hTrackerClusterChargePerChamber->GetRMSError());
248         
249         TH1* hTrackerClusterMultiplicityPerChamber = GetRecPointsData(kTrackerClusterMultiplicityPerChamber+iCh);
250         Double_t sigmaSize = hTrackerClusterMultiplicityPerChamber->GetRMS();
251         hTrackerClusterMultiplicityPerChMean->SetBinContent(iCh+1, hTrackerClusterMultiplicityPerChamber->GetMean());
252         hTrackerClusterMultiplicityPerChMean->SetBinError(iCh+1, hTrackerClusterMultiplicityPerChamber->GetMeanError());
253         hTrackerClusterMultiplicityPerChSigma->SetBinContent(iCh+1, sigmaSize);
254         hTrackerClusterMultiplicityPerChSigma->SetBinError(iCh+1, hTrackerClusterMultiplicityPerChamber->GetRMSError());
255         
256         // loop over DE into chamber iCh
257         AliMpDEIterator it;
258         it.First(iCh);
259         while ( !it.IsDone()) {
260           
261           Int_t iDE = it.CurrentDEId();
262           
263           TH1* hTrackerClusterChargePerDE = GetRecPointsData(kTrackerClusterChargePerDE+iDE);
264           hTrackerClusterChargePerDEMean->SetBinContent(iDE+1, hTrackerClusterChargePerDE->GetMean());
265           Double_t nClusters = hTrackerClusterChargePerDE->GetEntries();
266           if (nClusters > 1) hTrackerClusterChargePerDEMean->SetBinError(iDE+1, sigmaCharge/TMath::Sqrt(nClusters));
267           else hTrackerClusterChargePerDEMean->SetBinError(iDE+1, hTrackerClusterChargePerChamber->GetXaxis()->GetXmax());
268           
269           TH1* hTrackerClusterMultiplicityPerDE = GetRecPointsData(kTrackerClusterMultiplicityPerDE+iDE);
270           hTrackerClusterMultiplicityPerDEMean->SetBinContent(iDE+1, hTrackerClusterMultiplicityPerDE->GetMean());
271           nClusters = hTrackerClusterMultiplicityPerDE->GetEntries();
272           if (nClusters > 1) hTrackerClusterMultiplicityPerDEMean->SetBinError(iDE+1, sigmaSize/TMath::Sqrt(nClusters));
273           else hTrackerClusterMultiplicityPerDEMean->SetBinError(iDE+1, hTrackerClusterMultiplicityPerChamber->GetXaxis()->GetXmax());
274           
275           it.Next();
276         }
277         
278       }
279       
280     }
281     
282     // Normalize ESD histos
283     if ( task == AliQAv1::kESDS ) {
284       
285       if (!GetESDsData(kESDnClustersPerTrack)) continue;
286       
287       Double_t nTracks = GetESDsData(kESDnClustersPerTrack)->GetEntries();
288       if (nTracks <= 0) continue;
289       
290       TH1* hESDnClustersPerCh = GetESDsData(kESDnClustersPerCh);
291       TH1* hESDnClustersPerDE = GetESDsData(kESDnClustersPerDE);
292       TH1* hESDClusterChargePerChMean = GetESDsData(kESDClusterChargePerChMean);
293       TH1* hESDClusterChargePerChSigma = GetESDsData(kESDClusterChargePerChSigma);
294       TH1* hESDClusterSizePerChMean = GetESDsData(kESDClusterSizePerChMean);
295       TH1* hESDClusterSizePerChSigma = GetESDsData(kESDClusterSizePerChSigma);
296       TH1* hESDResidualXPerChMean = GetESDsData(kESDResidualXPerChMean);
297       TH1* hESDResidualXPerChSigma = GetESDsData(kESDResidualXPerChSigma);
298       TH1* hESDResidualYPerChMean = GetESDsData(kESDResidualYPerChMean);
299       TH1* hESDResidualYPerChSigma = GetESDsData(kESDResidualYPerChSigma);
300       TH1* hESDLocalChi2XPerChMean = GetESDsData(kESDLocalChi2XPerChMean);
301       TH1* hESDLocalChi2YPerChMean = GetESDsData(kESDLocalChi2YPerChMean);
302       TH1* hESDLocalChi2PerChMean = GetESDsData(kESDLocalChi2PerChMean);
303       TH1* hESDClusterChargePerDE = GetESDsData(kESDClusterChargePerDE);
304       TH1* hESDClusterSizePerDE = GetESDsData(kESDClusterSizePerDE);
305       TH1* hESDResidualXPerDEMean = GetESDsData(kESDResidualXPerDEMean);
306       TH1* hESDResidualXPerDESigma = GetESDsData(kESDResidualXPerDESigma);
307       TH1* hESDResidualYPerDEMean = GetESDsData(kESDResidualYPerDEMean);
308       TH1* hESDResidualYPerDESigma = GetESDsData(kESDResidualYPerDESigma);
309       TH1* hESDLocalChi2XPerDEMean = GetESDsData(kESDLocalChi2XPerDEMean);
310       TH1* hESDLocalChi2YPerDEMean = GetESDsData(kESDLocalChi2YPerDEMean);
311       TH1* hESDLocalChi2PerDEMean = GetESDsData(kESDLocalChi2PerDEMean);
312       TH1* hESDnTotClustersPerCh = GetESDsData(kESDnTotClustersPerCh);
313       TH1* hESDnTotClustersPerDE = GetESDsData(kESDnTotClustersPerDE);
314       TH1* hESDnTotFullClustersPerDE = GetESDsData(kESDnTotFullClustersPerDE);
315       TH1* hESDSumClusterChargePerDE = GetESDsData(kESDSumClusterChargePerDE);
316       TH1* hESDSumClusterSizePerDE = GetESDsData(kESDSumClusterSizePerDE);
317       TH1* hESDSumResidualXPerDE = GetESDsData(kESDSumResidualXPerDE);
318       TH1* hESDSumResidualYPerDE = GetESDsData(kESDSumResidualYPerDE);
319       TH1* hESDSumResidualX2PerDE = GetESDsData(kESDSumResidualX2PerDE);
320       TH1* hESDSumResidualY2PerDE = GetESDsData(kESDSumResidualY2PerDE);
321       TH1* hESDSumLocalChi2XPerDE = GetESDsData(kESDSumLocalChi2XPerDE);
322       TH1* hESDSumLocalChi2YPerDE = GetESDsData(kESDSumLocalChi2YPerDE);
323       TH1* hESDSumLocalChi2PerDE = GetESDsData(kESDSumLocalChi2PerDE);
324       
325       hESDnClustersPerCh->Reset();
326       hESDnClustersPerDE->Reset();
327       hESDnClustersPerCh->Add(hESDnTotClustersPerCh, 1./nTracks);
328       hESDnClustersPerDE->Add(hESDnTotClustersPerDE, 1./nTracks);
329       
330       // loop over chambers
331       for (Int_t iCh = 0; iCh < AliMUONConstants::NTrackingCh(); iCh++) {
332         
333         TH1* hESDClusterChargeInCh = GetESDsData(kESDClusterChargeInCh+iCh);
334         Double_t sigmaCharge = hESDClusterChargeInCh->GetRMS();
335         hESDClusterChargePerChMean->SetBinContent(iCh+1, hESDClusterChargeInCh->GetMean());
336         hESDClusterChargePerChMean->SetBinError(iCh+1, hESDClusterChargeInCh->GetMeanError());
337         hESDClusterChargePerChSigma->SetBinContent(iCh+1, sigmaCharge);
338         hESDClusterChargePerChSigma->SetBinError(iCh+1, hESDClusterChargeInCh->GetRMSError());
339         
340         TH1* hESDClusterSizeInCh = GetESDsData(kESDClusterSizeInCh+iCh);
341         Double_t sigmaSize = hESDClusterSizeInCh->GetRMS();
342         hESDClusterSizePerChMean->SetBinContent(iCh+1, hESDClusterSizeInCh->GetMean());
343         hESDClusterSizePerChMean->SetBinError(iCh+1, hESDClusterSizeInCh->GetMeanError());
344         hESDClusterSizePerChSigma->SetBinContent(iCh+1, sigmaSize);
345         hESDClusterSizePerChSigma->SetBinError(iCh+1, hESDClusterSizeInCh->GetRMSError());
346         
347         TH1* hESDResidualXInCh = GetESDsData(kESDResidualXInCh+iCh);
348         Double_t sigmaResidualX = hESDResidualXInCh->GetRMS();
349         hESDResidualXPerChMean->SetBinContent(iCh+1, hESDResidualXInCh->GetMean());
350         hESDResidualXPerChMean->SetBinError(iCh+1, hESDResidualXInCh->GetMeanError());
351         hESDResidualXPerChSigma->SetBinContent(iCh+1, sigmaResidualX);
352         hESDResidualXPerChSigma->SetBinError(iCh+1, hESDResidualXInCh->GetRMSError());
353         
354         TH1* hESDResidualYInCh = GetESDsData(kESDResidualYInCh+iCh);
355         Double_t sigmaResidualY = hESDResidualYInCh->GetRMS();
356         hESDResidualYPerChMean->SetBinContent(iCh+1, hESDResidualYInCh->GetMean());
357         hESDResidualYPerChMean->SetBinError(iCh+1, hESDResidualYInCh->GetMeanError());
358         hESDResidualYPerChSigma->SetBinContent(iCh+1, sigmaResidualY);
359         hESDResidualYPerChSigma->SetBinError(iCh+1, hESDResidualYInCh->GetRMSError());
360         
361         TH1* hESDLocalChi2XInCh = GetESDsData(kESDLocalChi2XInCh+iCh);
362         Double_t sigmaLocalChi2X = hESDLocalChi2XInCh->GetRMS();
363         hESDLocalChi2XPerChMean->SetBinContent(iCh+1, hESDLocalChi2XInCh->GetMean());
364         hESDLocalChi2XPerChMean->SetBinError(iCh+1, hESDLocalChi2XInCh->GetMeanError());
365         
366         TH1* hESDLocalChi2YInCh = GetESDsData(kESDLocalChi2YInCh+iCh);
367         Double_t sigmaLocalChi2Y = hESDLocalChi2YInCh->GetRMS();
368         hESDLocalChi2YPerChMean->SetBinContent(iCh+1, hESDLocalChi2YInCh->GetMean());
369         hESDLocalChi2YPerChMean->SetBinError(iCh+1, hESDLocalChi2YInCh->GetMeanError());
370         
371         TH1* hESDLocalChi2InCh = GetESDsData(kESDLocalChi2InCh+iCh);
372         Double_t sigmaLocalChi2 = hESDLocalChi2InCh->GetRMS();
373         hESDLocalChi2PerChMean->SetBinContent(iCh+1, hESDLocalChi2InCh->GetMean());
374         hESDLocalChi2PerChMean->SetBinError(iCh+1, hESDLocalChi2InCh->GetMeanError());
375         
376         // loop over DE into chamber iCh
377         AliMpDEIterator it;
378         it.First(iCh);
379         while ( !it.IsDone()) {
380           
381           Int_t iDE = it.CurrentDEId();
382           
383           Double_t nClusters = hESDnTotClustersPerDE->GetBinContent(iDE+1);
384           if (nClusters > 1) {
385             
386             hESDClusterChargePerDE->SetBinContent(iDE+1, hESDSumClusterChargePerDE->GetBinContent(iDE+1)/nClusters);
387             hESDClusterChargePerDE->SetBinError(iDE+1, sigmaCharge/TMath::Sqrt(nClusters));
388             
389             Double_t meanResX = hESDSumResidualXPerDE->GetBinContent(iDE+1)/nClusters;
390             hESDResidualXPerDEMean->SetBinContent(iDE+1, meanResX);
391             hESDResidualXPerDEMean->SetBinError(iDE+1, sigmaResidualX/TMath::Sqrt(nClusters));
392             hESDResidualXPerDESigma->SetBinContent(iDE+1, TMath::Sqrt(hESDSumResidualX2PerDE->GetBinContent(iDE+1)/nClusters - meanResX*meanResX));
393             hESDResidualXPerDESigma->SetBinError(iDE+1, sigmaResidualX/TMath::Sqrt(2.*nClusters));
394             
395             Double_t meanResY = hESDSumResidualYPerDE->GetBinContent(iDE+1)/nClusters;
396             hESDResidualYPerDEMean->SetBinContent(iDE+1, meanResY);
397             hESDResidualYPerDEMean->SetBinError(iDE+1, sigmaResidualY/TMath::Sqrt(nClusters));
398             hESDResidualYPerDESigma->SetBinContent(iDE+1, TMath::Sqrt(hESDSumResidualY2PerDE->GetBinContent(iDE+1)/nClusters - meanResY*meanResY));
399             hESDResidualYPerDESigma->SetBinError(iDE+1, sigmaResidualY/TMath::Sqrt(2.*nClusters));
400             
401             hESDLocalChi2XPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2XPerDE->GetBinContent(iDE+1)/nClusters);
402             hESDLocalChi2XPerDEMean->SetBinError(iDE+1, sigmaLocalChi2X/TMath::Sqrt(nClusters));
403             
404             hESDLocalChi2YPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2YPerDE->GetBinContent(iDE+1)/nClusters);
405             hESDLocalChi2YPerDEMean->SetBinError(iDE+1, sigmaLocalChi2Y/TMath::Sqrt(nClusters));
406             
407             hESDLocalChi2PerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2PerDE->GetBinContent(iDE+1)/nClusters);
408             hESDLocalChi2PerDEMean->SetBinError(iDE+1, sigmaLocalChi2/TMath::Sqrt(nClusters));
409             
410           } else {
411             
412             hESDClusterChargePerDE->SetBinContent(iDE+1, hESDSumClusterChargePerDE->GetBinContent(iDE+1));
413             hESDClusterChargePerDE->SetBinError(iDE+1, hESDClusterChargeInCh->GetXaxis()->GetXmax());
414             
415             hESDResidualXPerDEMean->SetBinContent(iDE+1, hESDSumResidualXPerDE->GetBinContent(iDE+1));
416             hESDResidualXPerDEMean->SetBinError(iDE+1, hESDResidualXInCh->GetXaxis()->GetXmax());
417             hESDResidualXPerDESigma->SetBinContent(iDE+1, 0.);
418             hESDResidualXPerDESigma->SetBinError(iDE+1, hESDResidualXInCh->GetXaxis()->GetXmax());
419             
420             hESDResidualYPerDEMean->SetBinContent(iDE+1, hESDSumResidualYPerDE->GetBinContent(iDE+1));
421             hESDResidualYPerDEMean->SetBinError(iDE+1, hESDResidualYInCh->GetXaxis()->GetXmax());
422             hESDResidualYPerDESigma->SetBinContent(iDE+1, 0.);
423             hESDResidualYPerDESigma->SetBinError(iDE+1, hESDResidualYInCh->GetXaxis()->GetXmax());
424             
425             hESDLocalChi2XPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2XPerDE->GetBinContent(iDE+1));
426             hESDLocalChi2XPerDEMean->SetBinError(iDE+1, hESDLocalChi2XInCh->GetXaxis()->GetXmax());
427             
428             hESDLocalChi2YPerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2YPerDE->GetBinContent(iDE+1));
429             hESDLocalChi2YPerDEMean->SetBinError(iDE+1, hESDLocalChi2YInCh->GetXaxis()->GetXmax());
430             
431             hESDLocalChi2PerDEMean->SetBinContent(iDE+1, hESDSumLocalChi2PerDE->GetBinContent(iDE+1));
432             hESDLocalChi2PerDEMean->SetBinError(iDE+1, hESDLocalChi2InCh->GetXaxis()->GetXmax());
433             
434           }
435           
436           Double_t nFullClusters = hESDnTotFullClustersPerDE->GetBinContent(iDE+1);
437           if (nFullClusters > 1) {
438             
439             hESDClusterSizePerDE->SetBinContent(iDE+1, hESDSumClusterSizePerDE->GetBinContent(iDE+1)/nFullClusters);
440             hESDClusterSizePerDE->SetBinError(iDE+1, sigmaSize/TMath::Sqrt(nFullClusters));
441             
442           } else {
443             
444             hESDClusterSizePerDE->SetBinContent(iDE+1, hESDSumClusterSizePerDE->GetBinContent(iDE+1));
445             hESDClusterSizePerDE->SetBinError(iDE+1, hESDClusterSizeInCh->GetXaxis()->GetXmax());
446             
447           }
448           
449           it.Next();
450         }
451         
452       }
453       
454     }
455     
456   }
457   
458   // do the QA checking
459   AliQAChecker::Instance()->Run(AliQAv1::kMUON, task, list) ;
460 }
461
462 //____________________________________________________________________________ 
463 void AliMUONQADataMakerRec::InitRaws()
464 {
465     /// create Raws histograms in Raws subdir
466         
467   AliCodeTimerAuto("");
468   
469   const Bool_t expert   = kTRUE ; 
470   const Bool_t saveCorr = kTRUE ; 
471   const Bool_t image    = kTRUE ; 
472   
473         if ( ! AliCDBManager::Instance()->GetDefaultStorage() )
474         {
475                 AliError("CDB default storage not set. Cannot work.");
476                 fIsInitRaws=kFALSE;
477         }
478         
479         TH3F* h3 = new TH3F("hTriggerScalersBendPlane", "Trigger scalers in bending plane",
480                                                                                         4, 10.5, 14.5,
481                                                                                         234, 0.5, 234.5,
482                                                                                         16, -0.5, 15.5);
483         h3->GetXaxis()->SetTitle("Chamber");
484         h3->GetYaxis()->SetTitle("Board");
485         h3->GetZaxis()->SetTitle("Strip");
486         Add2RawsList(h3, kTriggerScalersBP, expert, !image, !saveCorr);
487         
488         TH3F* h4 = new TH3F("hTriggerScalersNonBendPlane", "Trigger scalers in non-bending plane",
489                                                                                         4, 10.5, 14.5,
490                                                                                         234, 0.5, 234.5,
491                                                                                         16, -0.5, 15.5);
492         h4->GetXaxis()->SetTitle("Chamber");
493         h4->GetYaxis()->SetTitle("Board");
494         h4->GetZaxis()->SetTitle("Strip");
495         Add2RawsList(h4, kTriggerScalersNBP, expert, !image, !saveCorr);
496         
497         AliMUONTriggerDisplay triggerDisplay;
498         TString histoName, histoTitle;
499         for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
500                 TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
501                 for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
502                         histoName = Form("hScalers%sChamber%i", cathName.Data(), 11+iChamber);
503                         histoTitle = Form("Chamber %i: Scalers %s", 11+iChamber, cathName.Data());
504                         TH2F* h5 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplayStrips, 
505                                                                               iCath, iChamber, histoTitle);
506                         Add2RawsList(h5, kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, !expert, image, !saveCorr);
507                 }
508         }
509
510         TH2F* h6 = new TH2F("hTriggerRPCI", "Trigger RPC currents",
511                             4, 10.5, 14.5,
512                             18, -0.5, 17.5);
513         h6->GetXaxis()->SetTitle("Chamber");
514         h6->GetYaxis()->SetTitle("RPC");
515         Add2RawsList(h6, kTriggerRPCi, expert, !image, !saveCorr);
516
517         TH2F* h7 = new TH2F("hTriggerRPCHV", "Trigger RPC HV",
518                             4, 10.5, 14.5,
519                             18, -0.5, 17.5);
520         h7->GetXaxis()->SetTitle("Chamber");
521         h7->GetYaxis()->SetTitle("RPC");
522         Add2RawsList(h7, kTriggerRPChv, expert, !image, !saveCorr);
523         
524         for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
525           histoName = Form("hRPCIChamber%i", 11+iChamber);
526           histoTitle = Form("Chamber %i: RPC Currents (#muA)", 11+iChamber);
527           TH2F* h8 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplaySlats, 
528                                                                 0, iChamber, histoTitle);
529           Add2RawsList(h8, kTriggerIDisplay + iChamber, !expert, image, !saveCorr);
530         }
531
532         for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
533           histoName = Form("hRPCHVChamber%i", 11+iChamber);
534           histoTitle = Form("Chamber %i: RPC HV (V)", 11+iChamber);
535           TH2F* h9 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplaySlats, 
536                                                                 0, iChamber, histoTitle);
537           Add2RawsList(h9, kTriggerHVDisplay + iChamber, !expert, image, !saveCorr);
538         }
539
540         TH1F* h10 = new TH1F("hTriggerScalersTime", "Trigger scalers acquisition time", 1, 0.5, 1.5);
541         h10->GetXaxis()->SetBinLabel(1, "One-bin histogram: bin is filled at each scaler event.");
542         h10->GetYaxis()->SetTitle("Cumulated scaler time (s)");
543         Add2RawsList(h10, kTriggerScalersTime, !expert, image, !saveCorr);
544         
545   Int_t nbp(0);
546   TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
547   while (next())
548   {
549     ++nbp;
550   }
551   
552   TH1* hbp = new TH1F("hTrackerBusPatchOccupancy","Occupancy of bus patches",
553                       nbp,-0.5,nbp-0.5);
554   
555   Add2RawsList(hbp,kTrackerBusPatchOccupancy, !expert, image, !saveCorr);
556
557   const Bool_t histogram(kFALSE);
558
559   fTrackerDataMaker = new AliMUONTrackerDataMaker(GetMUONRecoParam(),
560                                                   AliCDBManager::Instance()->GetRun(),
561                                                   0x0,
562                                                   AliCDBManager::Instance()->GetDefaultStorage()->GetURI(),
563                                                   "NOGAIN",
564                                                   histogram,
565                                                   0.0,0.0);
566                 
567   fTrackerDataMaker->Data()->DisableChannelLevel(); // to save up disk space, we only store starting at the manu level
568         
569   fTrackerDataMaker->SetRunning(kTRUE);
570   
571         fIsInitRaws = kTRUE;
572 }
573
574 //__________________________________________________________________
575 void AliMUONQADataMakerRec::InitDigits() 
576 {
577   /// Initialized Digits spectra 
578   const Bool_t expert   = kTRUE ; 
579   const Bool_t image    = kTRUE ; 
580   
581   TH1I* h0 = new TH1I("hDigitsDetElem", "Detection element distribution in Digits;Detection element Id;Counts",  1400, 100, 1500); 
582   Add2DigitsList(h0, 0, !expert, image);
583   
584   TH1I* h1 = new TH1I("hDigitsADC", "ADC distribution in Digits;ACD value;Counts", 4096, 0, 4095); 
585   Add2DigitsList(h1, 1, !expert, image);    
586
587
588 //____________________________________________________________________________ 
589 void AliMUONQADataMakerRec::InitRecPoints()
590 {
591         /// create Reconstructed Points histograms in RecPoints subdir
592   
593   AliCodeTimerAuto("");
594   
595         InitRecPointsTrigger();
596         InitRecPointsTracker();
597 }
598
599 //____________________________________________________________________________ 
600 void AliMUONQADataMakerRec::InitRecPointsTracker()
601 {
602   /// create Reconstructed Points histograms in RecPoints subdir for the
603   /// MUON tracker subsystem.
604   const Bool_t expert   = kTRUE ; 
605   const Bool_t image    = kTRUE ; 
606   
607   AliCodeTimerAuto("");
608   
609   TH1I *h1I;
610   TH1F *h1F;
611   TH2F *h2F;
612   
613   // histograms per chamber
614   Int_t nCh = AliMpConstants::NofTrackingChambers();
615   for ( Int_t i = 0; i < nCh; ++i ) 
616   {
617     h1I = new TH1I(Form("hTrackerClusterMultiplicityForChamber%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads};Counts)",i+1), 100,0,100);
618     Add2RecPointsList(h1I,kTrackerClusterMultiplicityPerChamber+i, expert, !image);
619     
620     h1I = new TH1I(Form("hTrackerClusterChargeForChamber%d",i+1), Form("cluster charge distribution in chamber %d;charge (ADC counts);Counts",i+1), 500,0,5000);
621     Add2RecPointsList(h1I,kTrackerClusterChargePerChamber+i, expert, !image);
622     
623     Float_t rMax = AliMUONConstants::Rmax(i/2);
624     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);
625     Add2RecPointsList(h2F, kTrackerClusterHitMapPerChamber+i, expert, !image);
626   }
627   
628   // summary histograms per chamber
629   h1I = new TH1I("hTrackerNumberOfClustersPerChamber", "Number of clusters per chamber;chamber ID;n_{clusters}", nCh,-0.5,nCh-0.5);
630   Add2RecPointsList(h1I,kTrackerNumberOfClustersPerChamber, !expert, image);
631   
632   h1F = new TH1F("hTrackerClusterMultiplicityPerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh,-0.5,nCh-0.5);
633   h1F->SetOption("P");
634   h1F->SetMarkerStyle(kFullDotMedium);
635   h1F->SetMarkerColor(kRed);
636   Add2RecPointsList(h1F, kTrackerClusterMultiplicityPerChMean, !expert, image);
637   
638   h1F = new TH1F("hTrackerClusterMultiplicityPerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh,-0.5,nCh-0.5);
639   h1F->SetOption("P");
640   h1F->SetMarkerStyle(kFullDotMedium);
641   h1F->SetMarkerColor(kRed);
642   Add2RecPointsList(h1F, kTrackerClusterMultiplicityPerChSigma, !expert, image);
643   
644   h1F = new TH1F("hTrackerClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (ADC counts)", nCh,-0.5,nCh-0.5);
645   h1F->SetOption("P");
646   h1F->SetMarkerStyle(kFullDotMedium);
647   h1F->SetMarkerColor(kRed);
648   Add2RecPointsList(h1F, kTrackerClusterChargePerChMean, !expert, image);
649   
650   h1F = new TH1F("hTrackerClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (ADC counts)", nCh,-0.5,nCh-0.5);
651   h1F->SetOption("P");
652   h1F->SetMarkerStyle(kFullDotMedium);
653   h1F->SetMarkerColor(kRed);
654   Add2RecPointsList(h1F, kTrackerClusterChargePerChSigma, !expert, image);
655   
656   // histograms per DE
657   Int_t ndes(0);
658   AliMpDEIterator it;
659   it.First();
660   while ( !it.IsDone())
661   {
662     Int_t detElemId = it.CurrentDEId();
663     
664     if ( AliMpDEManager::GetStationType(detElemId) != AliMp::kStationTrigger )
665     {
666       ndes = TMath::Max(ndes,detElemId);
667       
668       h1I = new TH1I(Form("hTrackerClusterMultiplicityForDE%04d",detElemId), Form("cluster size distribution in detection element %d;size (n_{pads})",detElemId), 100,0,100);
669       Add2RecPointsList(h1I,kTrackerClusterMultiplicityPerDE+detElemId, expert, !image);
670       
671       h1I = new TH1I(Form("hTrackerClusterChargeForDE%04d",detElemId), Form("cluster charge distribution in detection element %d;charge (ADC counts)",detElemId), 500,0,5000);
672       Add2RecPointsList(h1I,kTrackerClusterChargePerDE+detElemId, expert, !image);
673     }
674     
675     it.Next();
676   }
677   
678   // summary histograms per DE
679   h1I = new TH1I("hTrackerNumberOfClustersPerDE", "Number of clusters per detection element;DetElem ID;n_{clusters}", ndes+1,-0.5,ndes+0.5);
680   Add2RecPointsList(h1I, kTrackerNumberOfClustersPerDE, !expert, image);
681   
682   h1F = new TH1F("hTrackerClusterMultiplicityPerDEMean", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", ndes+1,-0.5,ndes+0.5);
683   h1F->SetOption("P");
684   h1F->SetMarkerStyle(kFullDotMedium);
685   h1F->SetMarkerColor(kRed);
686   Add2RecPointsList(h1F, kTrackerClusterMultiplicityPerDEMean, !expert, image);
687   
688   h1F = new TH1F("hTrackerClusterChargePerDEMean", "cluster mean charge per DE;DetElem ID;<charge> (ADC counts)", ndes+1,-0.5,ndes+0.5);
689   h1F->SetOption("P");
690   h1F->SetMarkerStyle(kFullDotMedium);
691   h1F->SetMarkerColor(kRed);
692   Add2RecPointsList(h1F, kTrackerClusterChargePerDEMean, !expert, image);
693   
694   fIsInitRecPointsTracker=kTRUE;
695 }
696
697 //____________________________________________________________________________ 
698 void AliMUONQADataMakerRec::InitRecPointsTrigger()
699 {
700         /// create Reconstructed Points histograms in RecPoints subdir for the
701         /// MUON Trigger subsystem.
702         
703   const Bool_t expert   = kTRUE ; 
704   const Bool_t image    = kTRUE ; 
705   
706     TH3F* h0 = new TH3F("hTriggerDigitsBendPlane", "Trigger digits in bending plane",
707                         4, 10.5, 14.5,
708                         234, 0.5, 234.5,
709                         16, -0.5, 15.5);
710     h0->GetXaxis()->SetTitle("Chamber");
711     h0->GetYaxis()->SetTitle("Board");
712     h0->GetZaxis()->SetTitle("Strip");
713     Add2RecPointsList(h0, kTriggerDigitsBendPlane, expert, !image);
714
715     TH3F* h1 = new TH3F("hTriggerDigitsNonBendPlane", "Trigger digits in non-bending plane",
716                         4, 10.5, 14.5,
717                         234, 0.5, 234.5,
718                         16, -0.5, 15.5);
719     h1->GetXaxis()->SetTitle("Chamber");
720     h1->GetYaxis()->SetTitle("Board");
721     h1->GetZaxis()->SetTitle("Strip");
722     Add2RecPointsList(h1, kTriggerDigitsNonBendPlane, expert, !image);
723
724     TH1F* h2 = new TH1F("hTriggeredBoards", "Triggered boards", 234, 0.5, 234.5);
725     Add2RecPointsList(h2, kTriggeredBoards, expert, !image);
726
727     AliMUONTriggerDisplay triggerDisplay;
728     TString histoName, histoTitle;
729     for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
730       TString cathName = ( iCath==0 ) ? "BendPlane" : "NonBendPlane";
731       for(Int_t iChamber=0; iChamber<AliMpConstants::NofTriggerChambers(); iChamber++){
732         histoName = Form("hTriggerDigits%sChamber%i", cathName.Data(), 11+iChamber);
733         histoTitle = Form("Chamber %i: Fired pads %s", 11+iChamber, cathName.Data());
734         TH2F* h3 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto(histoName, AliMUONTriggerDisplay::kDisplayStrips, 
735                                                               iCath, iChamber, histoTitle);
736         Add2RecPointsList(h3, kTriggerDigitsDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber, !expert, image);
737       }
738     }
739
740     TH2F* h4 = (TH2F*)triggerDisplay.GetEmptyDisplayHisto("hFiredBoardsDisplay", AliMUONTriggerDisplay::kDisplayBoards,
741                                                           0, 0, "Fired boards");
742     Add2RecPointsList(h4, kTriggerBoardsDisplay, !expert, image);
743         
744         fIsInitRecPointsTrigger = kTRUE;
745 }
746
747
748 //____________________________________________________________________________ 
749 void AliMUONQADataMakerRec::InitESDs()
750 {
751   ///create ESDs histograms in ESDs subdir
752   
753   const Bool_t expert   = kTRUE ; 
754   const Bool_t image    = kTRUE ; 
755   
756   Int_t nCh = AliMUONConstants::NTrackingCh();
757   Int_t nDE = 1100;
758   
759   // track info
760   TH1F* hESDnTracks = new TH1F("hESDnTracks", "number of tracks;n_{tracks}", 20, 0., 20.);
761   Add2ESDsList(hESDnTracks, kESDnTracks, !expert, image);
762
763   TH1F* hESDMatchTrig = new TH1F("hESDMatchTrig", "number of tracks matched with trigger;n_{tracks}", 20, 0., 20.);
764   Add2ESDsList(hESDMatchTrig, kESDMatchTrig, !expert, image);
765   
766   TH1F* hESDMomentum = new TH1F("hESDMomentum", "momentum distribution;p (GeV/c)", 300, 0., 300);
767   Add2ESDsList(hESDMomentum, kESDMomentum, !expert, image);
768
769   TH1F* hESDPt = new TH1F("hESDPt", "transverse momentum distribution;p_{t} (GeV/c)", 200, 0., 50);
770   Add2ESDsList(hESDPt, kESDPt, !expert, image);
771
772   TH1F* hESDRapidity = new TH1F("hESDRapidity", "rapidity distribution;rapidity", 200, -4.5, -2.);
773   Add2ESDsList(hESDRapidity, kESDRapidity, !expert, image);
774
775   TH1F* hESDChi2 = new TH1F("hESDChi2", "normalized #chi^{2} distribution;#chi^{2} / ndf", 500, 0., 50.);
776   Add2ESDsList(hESDChi2, kESDChi2, !expert, image);
777   
778   TH1F* hESDProbChi2 = new TH1F("hESDProbChi2", "distribution of probability of #chi^{2};prob(#chi^{2})", 100, 0., 1.);
779   Add2ESDsList(hESDProbChi2, kESDProbChi2, !expert, image);
780   
781   TH1F* hESDThetaX = new TH1F("hESDThetaX", "#theta_{X} distribution;#theta_{X} (degree)", 360, -180., 180);
782   Add2ESDsList(hESDThetaX, kESDThetaX, !expert, image);
783   
784   TH1F* hESDThetaY = new TH1F("hESDThetaY", "#theta_{Y} distribution;#theta_{Y} (degree)", 360, -180., 180);
785   Add2ESDsList(hESDThetaY, kESDThetaY, !expert, image);
786   
787   // cluster info
788   for (Int_t i = 0; i < nCh; i++) {
789     Float_t rMax = AliMUONConstants::Rmax(i/2);
790     TH2F* hESDClusterHitMap = new TH2F(Form("hESDClusterHitMap%d",i+1), Form("cluster position distribution in chamber %d;X (cm);Y (cm)",i+1),
791                                        100, -rMax, rMax, 100, -rMax, rMax);
792     Add2ESDsList(hESDClusterHitMap, kESDClusterHitMap+i, expert, !image);
793   }
794   
795   TH1F* hESDnClustersPerTrack = new TH1F("hESDnClustersPerTrack", "number of associated clusters per track;n_{clusters}", 20, 0., 20.);
796   Add2ESDsList(hESDnClustersPerTrack, kESDnClustersPerTrack, !expert, image);
797   
798   TH1F* hESDnClustersPerCh = new TH1F("hESDnClustersPerCh", "averaged number of clusters per chamber per track;chamber ID;<n_{clusters}>", nCh, -0.5, nCh-0.5);
799   hESDnClustersPerCh->SetFillColor(kRed);
800   Add2ESDsList(hESDnClustersPerCh, kESDnClustersPerCh, !expert, image);
801   
802   TH1F* hESDnClustersPerDE = new TH1F("hESDnClustersPerDE", "averaged number of clusters per DE per track;DetElem ID;<n_{clusters}>", nDE+1, -0.5, nDE+0.5);
803   hESDnClustersPerDE->SetFillColor(kRed);
804   Add2ESDsList(hESDnClustersPerDE, kESDnClustersPerDE, !expert, image);
805   
806   for (Int_t i = 0; i < nCh; i++) {
807     TH1F* hESDClusterChargeInCh = new TH1F(Form("hESDClusterChargeInCh%d",i+1), Form("cluster charge distribution in chamber %d;charge (ADC counts)",i+1), 500, 0., 5000.);
808     Add2ESDsList(hESDClusterChargeInCh, kESDClusterChargeInCh+i, expert, !image);
809   }
810   
811   TH1F* hESDClusterChargePerChMean = new TH1F("hESDClusterChargePerChMean", "cluster mean charge per chamber;chamber ID;<charge> (ADC counts)", nCh, -0.5, nCh-0.5);
812   hESDClusterChargePerChMean->SetOption("P");
813   hESDClusterChargePerChMean->SetMarkerStyle(kFullDotMedium);
814   hESDClusterChargePerChMean->SetMarkerColor(kRed);
815   Add2ESDsList(hESDClusterChargePerChMean, kESDClusterChargePerChMean, !expert, image);
816   
817   TH1F* hESDClusterChargePerChSigma = new TH1F("hESDClusterChargePerChSigma", "cluster charge dispersion per chamber;chamber ID;#sigma_{charge} (ADC counts)", nCh, -0.5, nCh-0.5);
818   hESDClusterChargePerChSigma->SetOption("P");
819   hESDClusterChargePerChSigma->SetMarkerStyle(kFullDotMedium);
820   hESDClusterChargePerChSigma->SetMarkerColor(kRed);
821   Add2ESDsList(hESDClusterChargePerChSigma, kESDClusterChargePerChSigma, !expert, image);
822   
823   TH1F* hESDClusterChargePerDE = new TH1F("hESDClusterChargePerDE", "cluster mean charge per DE;DetElem ID;<charge> (ADC counts)", nDE+1, -0.5, nDE+0.5);
824   hESDClusterChargePerDE->SetOption("P");
825   hESDClusterChargePerDE->SetMarkerStyle(kFullDotMedium);
826   hESDClusterChargePerDE->SetMarkerColor(kRed);
827   Add2ESDsList(hESDClusterChargePerDE, kESDClusterChargePerDE, !expert, image);
828   
829   for (Int_t i = 0; i < nCh; i++) {
830     TH1F* hESDClusterSizeInCh = new TH1F(Form("hESDClusterSizeInCh%d",i+1), Form("cluster size distribution in chamber %d;size (n_{pads})",i+1), 200, 0., 200.);
831     Add2ESDsList(hESDClusterSizeInCh, kESDClusterSizeInCh+i, expert, !image);
832   }
833   
834   TH1F* hESDClusterSizePerChMean = new TH1F("hESDClusterSizePerChMean", "cluster mean size per chamber;chamber ID;<size> (n_{pads})", nCh, -0.5, nCh-0.5);
835   hESDClusterSizePerChMean->SetOption("P");
836   hESDClusterSizePerChMean->SetMarkerStyle(kFullDotMedium);
837   hESDClusterSizePerChMean->SetMarkerColor(kRed);
838   Add2ESDsList(hESDClusterSizePerChMean, kESDClusterSizePerChMean, !expert, image);
839   
840   TH1F* hESDClusterSizePerChSigma = new TH1F("hESDClusterSizePerChSigma", "cluster size dispersion per chamber;chamber ID;#sigma_{size} (n_{pads})", nCh, -0.5, nCh-0.5);
841   hESDClusterSizePerChSigma->SetOption("P");
842   hESDClusterSizePerChSigma->SetMarkerStyle(kFullDotMedium);
843   hESDClusterSizePerChSigma->SetMarkerColor(kRed);
844   Add2ESDsList(hESDClusterSizePerChSigma, kESDClusterSizePerChSigma, !expert, image);
845   
846   TH1F* hESDClusterSizePerDE = new TH1F("hESDClusterSizePerDE", "cluster mean size per DE;DetElem ID;<size> (n_{pads})", nDE+1, -0.5, nDE+0.5);
847   hESDClusterSizePerDE->SetOption("P");
848   hESDClusterSizePerDE->SetMarkerStyle(kFullDotMedium);
849   hESDClusterSizePerDE->SetMarkerColor(kRed);
850   Add2ESDsList(hESDClusterSizePerDE, kESDClusterSizePerDE, !expert, image);
851   
852   // cluster - track info
853   for (Int_t i = 0; i < nCh; i++) {
854     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.);
855     Add2ESDsList(hESDResidualXInCh, kESDResidualXInCh+i, expert, !image);
856     
857     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.);
858     Add2ESDsList(hESDResidualYInCh, kESDResidualYInCh+i, expert, !image);
859     
860     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);
861     Add2ESDsList(hESDLocalChi2XInCh, kESDLocalChi2XInCh+i, expert, !image);
862     
863     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);
864     Add2ESDsList(hESDLocalChi2YInCh, kESDLocalChi2YInCh+i, expert, !image);
865     
866     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);
867     Add2ESDsList(hESDLocalChi2InCh, kESDLocalChi2InCh+i, expert, !image);
868   }
869   
870   TH1F* hESDResidualXPerChMean = new TH1F("hESDResidualXPerChMean", "cluster-track residual-X per Ch: mean;chamber ID;<#Delta_{X}> (cm)", nCh, -0.5, nCh-0.5);
871   hESDResidualXPerChMean->SetOption("P");
872   hESDResidualXPerChMean->SetMarkerStyle(kFullDotMedium);
873   hESDResidualXPerChMean->SetMarkerColor(kRed);
874   Add2ESDsList(hESDResidualXPerChMean, kESDResidualXPerChMean, !expert, image);
875   
876   TH1F* hESDResidualYPerChMean = new TH1F("hESDResidualYPerChMean", "cluster-track residual-Y per Ch: mean;chamber ID;<#Delta_{Y}> (cm)", nCh, -0.5, nCh-0.5);
877   hESDResidualYPerChMean->SetOption("P");
878   hESDResidualYPerChMean->SetMarkerStyle(kFullDotMedium);
879   hESDResidualYPerChMean->SetMarkerColor(kRed);
880   Add2ESDsList(hESDResidualYPerChMean, kESDResidualYPerChMean, !expert, image);
881   
882   TH1F* hESDResidualXPerChSigma = new TH1F("hESDResidualXPerChSigma", "cluster-track residual-X per Ch: sigma;chamber ID;#sigma_{X} (cm)", nCh, -0.5, nCh-0.5);
883   hESDResidualXPerChSigma->SetOption("P");
884   hESDResidualXPerChSigma->SetMarkerStyle(kFullDotMedium);
885   hESDResidualXPerChSigma->SetMarkerColor(kRed);
886   Add2ESDsList(hESDResidualXPerChSigma, kESDResidualXPerChSigma, !expert, image);
887   
888   TH1F* hESDResidualYPerChSigma = new TH1F("hESDResidualYPerChSigma", "cluster-track residual-Y per Ch: sigma;chamber ID;#sigma_{Y} (cm)", nCh, -0.5, nCh-0.5);
889   hESDResidualYPerChSigma->SetOption("P");
890   hESDResidualYPerChSigma->SetMarkerStyle(kFullDotMedium);
891   hESDResidualYPerChSigma->SetMarkerColor(kRed);
892   Add2ESDsList(hESDResidualYPerChSigma, kESDResidualYPerChSigma, !expert, image);
893   
894   TH1F* hESDLocalChi2XPerChMean = new TH1F("hESDLocalChi2XPerChMean", "local chi2-X per Ch: mean;chamber ID;<local #chi^{2}_{X}>", nCh, -0.5, nCh-0.5);
895   hESDLocalChi2XPerChMean->SetOption("P");
896   hESDLocalChi2XPerChMean->SetMarkerStyle(kFullDotMedium);
897   hESDLocalChi2XPerChMean->SetMarkerColor(kRed);
898   Add2ESDsList(hESDLocalChi2XPerChMean, kESDLocalChi2XPerChMean, !expert, image);
899   
900   TH1F* hESDLocalChi2YPerChMean = new TH1F("hESDLocalChi2YPerChMean", "local chi2-Y per Ch: mean;chamber ID;<local #chi^{2}_{Y}>", nCh, -0.5, nCh-0.5);
901   hESDLocalChi2YPerChMean->SetOption("P");
902   hESDLocalChi2YPerChMean->SetMarkerStyle(kFullDotMedium);
903   hESDLocalChi2YPerChMean->SetMarkerColor(kRed);
904   Add2ESDsList(hESDLocalChi2YPerChMean, kESDLocalChi2YPerChMean, !expert, image);
905   
906   TH1F* hESDLocalChi2PerChMean = new TH1F("hESDLocalChi2PerChMean", "local chi2 (~0.5*(#chi^{2}_{X}+#chi^{2}_{Y})) per Ch: mean;chamber ID;<local #chi^{2}>", nCh, -0.5, nCh-0.5);
907   hESDLocalChi2PerChMean->SetOption("P");
908   hESDLocalChi2PerChMean->SetMarkerStyle(kFullDotMedium);
909   hESDLocalChi2PerChMean->SetMarkerColor(kRed);
910   Add2ESDsList(hESDLocalChi2PerChMean, kESDLocalChi2PerChMean, !expert, image);
911   
912   TH1F* hESDResidualXPerDEMean = new TH1F("hESDResidualXPerDEMean", "cluster-track residual-X per DE: mean;DetElem ID;<#Delta_{X}> (cm)", nDE+1, -0.5, nDE+0.5);
913   hESDResidualXPerDEMean->SetOption("P");
914   hESDResidualXPerDEMean->SetMarkerStyle(kFullDotMedium);
915   hESDResidualXPerDEMean->SetMarkerColor(kRed);
916   Add2ESDsList(hESDResidualXPerDEMean, kESDResidualXPerDEMean, !expert, image);
917   
918   TH1F* hESDResidualYPerDEMean = new TH1F("hESDResidualYPerDEMean", "cluster-track residual-Y per DE: mean;DetElem ID;<#Delta_{Y}> (cm)", nDE+1, -0.5, nDE+0.5);
919   hESDResidualYPerDEMean->SetOption("P");
920   hESDResidualYPerDEMean->SetMarkerStyle(kFullDotMedium);
921   hESDResidualYPerDEMean->SetMarkerColor(kRed);
922   Add2ESDsList(hESDResidualYPerDEMean, kESDResidualYPerDEMean, !expert, image);
923   
924   TH1F* hESDResidualXPerDESigma = new TH1F("hESDResidualXPerDESigma", "cluster-track residual-X per DE: sigma;DetElem ID;#sigma_{X} (cm)", nDE+1, -0.5, nDE+0.5);
925   hESDResidualXPerDESigma->SetOption("P");
926   hESDResidualXPerDESigma->SetMarkerStyle(kFullDotMedium);
927   hESDResidualXPerDESigma->SetMarkerColor(kRed);
928   Add2ESDsList(hESDResidualXPerDESigma, kESDResidualXPerDESigma, !expert, image);
929   
930   TH1F* hESDResidualYPerDESigma = new TH1F("hESDResidualYPerDESigma", "cluster-track residual-Y per DE: sigma;DetElem ID;#sigma_{Y} (cm)", nDE+1, -0.5, nDE+0.5);
931   hESDResidualYPerDESigma->SetOption("P");
932   hESDResidualYPerDESigma->SetMarkerStyle(kFullDotMedium);
933   hESDResidualYPerDESigma->SetMarkerColor(kRed);
934   Add2ESDsList(hESDResidualYPerDESigma, kESDResidualYPerDESigma, !expert, image);
935   
936   TH1F* hESDLocalChi2XPerDEMean = new TH1F("hESDLocalChi2XPerDEMean", "local chi2-X per DE: mean;DetElem ID;<local #chi^{2}_{X}>", nDE+1, -0.5, nDE+0.5);
937   hESDLocalChi2XPerDEMean->SetOption("P");
938   hESDLocalChi2XPerDEMean->SetMarkerStyle(kFullDotMedium);
939   hESDLocalChi2XPerDEMean->SetMarkerColor(kRed);
940   Add2ESDsList(hESDLocalChi2XPerDEMean, kESDLocalChi2XPerDEMean, !expert, image);
941   
942   TH1F* hESDLocalChi2YPerDEMean = new TH1F("hESDLocalChi2YPerDEMean", "local chi2-Y per DE: mean;DetElem ID;<local #chi^{2}_{Y}>", nDE+1, -0.5, nDE+0.5);
943   hESDLocalChi2YPerDEMean->SetOption("P");
944   hESDLocalChi2YPerDEMean->SetMarkerStyle(kFullDotMedium);
945   hESDLocalChi2YPerDEMean->SetMarkerColor(kRed);
946   Add2ESDsList(hESDLocalChi2YPerDEMean, kESDLocalChi2YPerDEMean, !expert, image);
947   
948   TH1F* hESDLocalChi2PerDEMean = new TH1F("hESDLocalChi2PerDEMean", "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);
949   hESDLocalChi2PerDEMean->SetOption("P");
950   hESDLocalChi2PerDEMean->SetMarkerStyle(kFullDotMedium);
951   hESDLocalChi2PerDEMean->SetMarkerColor(kRed);
952   Add2ESDsList(hESDLocalChi2PerDEMean, kESDLocalChi2PerDEMean, !expert, image);
953   
954   // intermediate histograms
955   TH1F* hESDnTotClustersPerCh = new TH1F("hESDnTotClustersPerCh", "total number of associated clusters per chamber;chamber ID;#Sigma(n_{clusters})", nCh, -0.5, nCh-0.5);
956   Add2ESDsList(hESDnTotClustersPerCh, kESDnTotClustersPerCh, expert, !image);
957   TH1F* hESDnTotClustersPerDE = new TH1F("hESDnTotClustersPerDE", "total number of associated clusters per DE;DetElem ID;#Sigma(n_{clusters})", nDE+1, -0.5, nDE+0.5);
958   Add2ESDsList(hESDnTotClustersPerDE, kESDnTotClustersPerDE, expert, !image);
959   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);
960   Add2ESDsList(hESDnTotFullClustersPerDE, kESDnTotFullClustersPerDE, expert, !image);
961   TH1F* hESDSumClusterChargePerDE = new TH1F("hESDSumClusterChargePerDE", "sum of cluster charge per DE;DetElem ID;#Sigma(charge) (ADC counts)", nDE+1, -0.5, nDE+0.5);
962   Add2ESDsList(hESDSumClusterChargePerDE, kESDSumClusterChargePerDE, expert, !image);
963   TH1F* hESDSumClusterSizePerDE = new TH1F("hESDSumClusterSizePerDE", "sum of cluster size per DE;DetElem ID;#Sigma(size) (n_{pads})", nDE+1, -0.5, nDE+0.5);
964   Add2ESDsList(hESDSumClusterSizePerDE, kESDSumClusterSizePerDE, expert, !image);
965   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);
966   Add2ESDsList(hESDSumResidualXPerDE, kESDSumResidualXPerDE, expert, !image);
967   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);
968   Add2ESDsList(hESDSumResidualYPerDE, kESDSumResidualYPerDE, expert, !image);
969   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);
970   Add2ESDsList(hESDSumResidualX2PerDE, kESDSumResidualX2PerDE, expert, !image);
971   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);
972   Add2ESDsList(hESDSumResidualY2PerDE, kESDSumResidualY2PerDE, expert, !image);
973   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);
974   Add2ESDsList(hESDSumLocalChi2XPerDE, kESDSumLocalChi2XPerDE, expert, !image);
975   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);
976   Add2ESDsList(hESDSumLocalChi2YPerDE, kESDSumLocalChi2YPerDE, expert, !image);
977   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);
978   Add2ESDsList(hESDSumLocalChi2PerDE, kESDSumLocalChi2PerDE, expert, !image);
979   
980   fIsInitESDs =  kTRUE;
981 }
982
983 //____________________________________________________________________________
984 void AliMUONQADataMakerRec::MakeRaws(AliRawReader* rawReader)
985 {
986     /// make QA for rawdata
987
988   if ( ! fIsInitRaws ) {
989       AliWarningStream() 
990         << "Skipping function due to a failure in Init" << endl;
991       return;
992     }    
993
994     // Check id histograms already created for this Event Specie
995   
996   if ( rawReader->GetType() == AliRawEventHeaderBase::kPhysicsEvent ) 
997   {
998     rawReader->Reset();
999     MakeRawsTracker(rawReader);
1000   }
1001   
1002   rawReader->Reset();    
1003   MakeRawsTrigger(rawReader);
1004 }
1005
1006 //____________________________________________________________________________
1007 void AliMUONQADataMakerRec::MakeRawsTracker(AliRawReader* rawReader)
1008 {
1009         /// make QA for rawdata tracker
1010         
1011         ((AliMUONTrackerDataMaker*)fTrackerDataMaker)->SetRawReader(rawReader);
1012         
1013         fTrackerDataMaker->ProcessEvent();
1014 }
1015
1016 //____________________________________________________________________________
1017 void AliMUONQADataMakerRec::MakeRawsTrigger(AliRawReader* rawReader)
1018 {
1019         /// make QA for rawdata trigger
1020         
1021     // Get trigger scalers
1022
1023     Int_t loCircuit=0;
1024     AliMpCDB::LoadDDLStore();
1025
1026     AliMUONRawStreamTrigger rawStreamTrig(rawReader);
1027     while (rawStreamTrig.NextDDL()) 
1028     {
1029       // If not a scaler event, do nothing
1030       Bool_t scalerEvent =  rawReader->GetDataHeader()->GetL1TriggerMessage() & 0x1;
1031       if(!scalerEvent) break;
1032
1033       AliMUONDDLTrigger* ddlTrigger = rawStreamTrig.GetDDLTrigger();
1034       AliMUONDarcHeader* darcHeader = ddlTrigger->GetDarcHeader();
1035
1036       if (darcHeader->GetGlobalFlag()){
1037         UInt_t nOfClocks = darcHeader->GetGlobalClock();
1038         Double_t nOfSeconds = ((Double_t) nOfClocks) / 40e6; // 1 clock each 25 ns
1039         ((TH1F*)GetRawsData(kTriggerScalersTime))->Fill(1., nOfSeconds);
1040       }
1041
1042       Int_t nReg = darcHeader->GetRegHeaderEntries();
1043     
1044       for(Int_t iReg = 0; iReg < nReg ;iReg++)
1045       {   //reg loop
1046
1047         // crate info  
1048         AliMpTriggerCrate* crate = AliMpDDLStore::Instance()->
1049           GetTriggerCrate(rawStreamTrig.GetDDL(), iReg);
1050
1051         AliMUONRegHeader* regHeader =  darcHeader->GetRegHeaderEntry(iReg);
1052
1053         // loop over local structures
1054         Int_t nLocal = regHeader->GetLocalEntries();
1055         for(Int_t iLocal = 0; iLocal < nLocal; iLocal++) 
1056         {
1057           AliMUONLocalStruct* localStruct = regHeader->GetLocalEntry(iLocal);
1058         
1059           // if card exist
1060           if (!localStruct) continue;
1061           
1062           loCircuit = crate->GetLocalBoardId(localStruct->GetId());
1063
1064           if ( !loCircuit ) continue; // empty slot
1065
1066           AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(loCircuit, false);
1067
1068           // skip copy cards
1069           if( !localBoard->IsNotified()) 
1070             continue;
1071
1072           Int_t cathode = localStruct->GetComptXY()%2;
1073
1074           ERaw hindex = (cathode==0) ? kTriggerScalersBP : kTriggerScalersNBP;
1075
1076           // loop over strips
1077           for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
1078             if(localStruct->GetXY1(ibitxy) > 0)
1079               ((TH3F*)GetRawsData(hindex))->Fill(11+0, loCircuit, ibitxy, 2*localStruct->GetXY1(ibitxy));
1080             if(localStruct->GetXY2(ibitxy) > 0)
1081               ((TH3F*)GetRawsData(hindex))->Fill(11+1, loCircuit, ibitxy, 2*localStruct->GetXY2(ibitxy));
1082             if(localStruct->GetXY3(ibitxy) > 0)
1083               ((TH3F*)GetRawsData(hindex))->Fill(11+2, loCircuit, ibitxy, 2*localStruct->GetXY3(ibitxy));
1084             if(localStruct->GetXY4(ibitxy) > 0)
1085               ((TH3F*)GetRawsData(hindex))->Fill(11+3, loCircuit, ibitxy, 2*localStruct->GetXY4(ibitxy));
1086           } // loop on strips
1087         } // iLocal
1088       } // iReg
1089     } // NextDDL
1090 }
1091
1092 //__________________________________________________________________
1093 void AliMUONQADataMakerRec::MakeDigits(TTree* digitsTree)         
1094 {
1095   /// makes data from Digits
1096
1097   if (!fDigitStore)
1098     fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
1099   fDigitStore->Connect(*digitsTree, false);
1100   digitsTree->GetEvent(0);
1101   
1102   TIter next(fDigitStore->CreateIterator());
1103   
1104   AliMUONVDigit* dig = 0x0;
1105   
1106   while ( ( dig = static_cast<AliMUONVDigit*>(next()) ) )
1107     {
1108     GetDigitsData(0)->Fill(dig->DetElemId());
1109     GetDigitsData(1)->Fill(dig->ADC());
1110     }
1111 }
1112
1113 //____________________________________________________________________________
1114 void AliMUONQADataMakerRec::MakeRecPoints(TTree* clustersTree)
1115 {
1116         /// Fill histograms from treeR
1117         
1118   if (fIsInitRecPointsTracker) MakeRecPointsTracker(clustersTree);
1119         if (fIsInitRecPointsTrigger) MakeRecPointsTrigger(clustersTree);
1120 }
1121
1122 //____________________________________________________________________________
1123 void AliMUONQADataMakerRec::MakeRecPointsTracker(TTree* clustersTree)
1124 {
1125         /// Fill histograms related to tracker clusters 
1126         
1127         // First things first : do we have clusters in the TreeR ?
1128         // In "normal" production mode, it should be perfectly normal
1129         // *not* to have them.
1130         // But if for some reason we de-activated the combined tracking,
1131         // then we have clusters in TreeR, so let's take that opportunity
1132         // to QA them...
1133         
1134         if (!fClusterStore)
1135         {
1136                 AliCodeTimerAuto("ClusterStore creation");
1137                 fClusterStore = AliMUONVClusterStore::Create(*clustersTree);
1138                 if (!fClusterStore) 
1139                 {
1140                         fIsInitRecPointsTracker = kFALSE;
1141                         return;
1142                 }
1143         }
1144         
1145         AliCodeTimerAuto("");
1146         
1147         fClusterStore->Connect(*clustersTree,kFALSE);
1148         clustersTree->GetEvent(0);
1149
1150         TIter next(fClusterStore->CreateIterator());
1151         AliMUONVCluster* cluster;
1152         
1153         while ( ( cluster = static_cast<AliMUONVCluster*>(next()) ) )
1154         {
1155                 Int_t detElemId = cluster->GetDetElemId();
1156                 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
1157                 
1158                 GetRecPointsData(kTrackerNumberOfClustersPerDE)->Fill(detElemId);
1159                 GetRecPointsData(kTrackerClusterChargePerDE+detElemId)->Fill(cluster->GetCharge());
1160                 GetRecPointsData(kTrackerClusterMultiplicityPerDE+detElemId)->Fill(cluster->GetNDigits());
1161
1162                 GetRecPointsData(kTrackerNumberOfClustersPerChamber)->Fill(chamberId);
1163                 GetRecPointsData(kTrackerClusterChargePerChamber+chamberId)->Fill(cluster->GetCharge());
1164                 GetRecPointsData(kTrackerClusterMultiplicityPerChamber+chamberId)->Fill(cluster->GetNDigits());
1165                 GetRecPointsData(kTrackerClusterHitMapPerChamber+chamberId)->Fill(cluster->GetX(),cluster->GetY());
1166                 
1167         }
1168         
1169         fClusterStore->Clear();
1170 }
1171
1172 //____________________________________________________________________________
1173 void AliMUONQADataMakerRec::MakeRecPointsTrigger(TTree* clustersTree)
1174 {
1175         /// makes data from trigger response
1176       
1177     // Fired pads info
1178     fDigitStore->Clear();
1179
1180     if (!fTriggerStore) fTriggerStore = AliMUONVTriggerStore::Create(*clustersTree);
1181     fTriggerStore->Clear();
1182     fTriggerStore->Connect(*clustersTree, false);
1183     clustersTree->GetEvent(0);
1184
1185     AliMUONLocalTrigger* locTrg;
1186     TIter nextLoc(fTriggerStore->CreateLocalIterator());
1187
1188     while ( ( locTrg = static_cast<AliMUONLocalTrigger*>(nextLoc()) ) ) 
1189     {
1190       if (locTrg->IsNull()) continue;
1191    
1192       TArrayS xyPattern[2];
1193       locTrg->GetXPattern(xyPattern[0]);
1194       locTrg->GetYPattern(xyPattern[1]);
1195
1196       Int_t nBoard = locTrg->LoCircuit();
1197
1198       Bool_t xTrig=locTrg->IsTrigX();
1199       Bool_t yTrig=locTrg->IsTrigY();
1200     
1201       if (xTrig && yTrig)
1202         ((TH1F*)GetRecPointsData(kTriggeredBoards))->Fill(nBoard);
1203
1204       fDigitMaker->TriggerDigits(nBoard, xyPattern, *fDigitStore);
1205     }
1206
1207     TIter nextDigit(fDigitStore->CreateIterator());
1208     AliMUONVDigit* mDigit;
1209     while ( ( mDigit = static_cast<AliMUONVDigit*>(nextDigit()) ) )
1210     {
1211       Int_t detElemId = mDigit->DetElemId();
1212       Int_t ch = detElemId/100;
1213       Int_t localBoard = mDigit->ManuId();
1214       Int_t channel = mDigit->ManuChannel();
1215       Int_t cathode = mDigit->Cathode();
1216       ERecPoints hindex 
1217         = ( cathode == 0 ) ? kTriggerDigitsBendPlane : kTriggerDigitsNonBendPlane;
1218       
1219       ((TH3F*)GetRecPointsData(hindex))->Fill(ch, localBoard, channel);
1220     }
1221 }
1222
1223 //____________________________________________________________________________
1224 void AliMUONQADataMakerRec::MakeESDs(AliESDEvent* esd)
1225 {
1226   /// make QA data from ESDs
1227   
1228   if ( ! fIsInitESDs ) {
1229     AliWarningStream() 
1230     << "Skipping function due to a failure in Init" << endl;
1231     return;
1232   }  
1233   
1234   // load ESD event in the interface
1235   AliMUONESDInterface esdInterface;
1236   if (GetMUONRecoParam()) AliMUONESDInterface::ResetTracker(GetMUONRecoParam());
1237   else AliError("Unable to get recoParam: use default ones for residual calculation");
1238   esdInterface.LoadEvent(*esd);
1239   
1240   GetESDsData(kESDnTracks)->Fill(esdInterface.GetNTracks());
1241   
1242   Int_t nTrackMatchTrig = 0;
1243   
1244   // loop over tracks
1245   Int_t nTracks = (Int_t) esd->GetNumberOfMuonTracks(); 
1246   for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) {
1247     
1248     // get the ESD track and skip "ghosts"
1249     AliESDMuonTrack* esdTrack = esd->GetMuonTrack(iTrack);
1250     if (!esdTrack->ContainTrackerData()) continue;
1251     
1252     // get corresponding MUON track
1253     AliMUONTrack* track = esdInterface.FindTrack(esdTrack->GetUniqueID());
1254     
1255     if (esdTrack->ContainTriggerData()) nTrackMatchTrig++;
1256     
1257     GetESDsData(kESDMomentum)->Fill(esdTrack->P());
1258     GetESDsData(kESDPt)->Fill(esdTrack->Pt());
1259     GetESDsData(kESDRapidity)->Fill(esdTrack->Y());
1260     GetESDsData(kESDChi2)->Fill(track->GetNormalizedChi2());
1261     GetESDsData(kESDProbChi2)->Fill(TMath::Prob(track->GetGlobalChi2(),track->GetNDF()));
1262     GetESDsData(kESDThetaX)->Fill(esdTrack->GetThetaXUncorrected() / TMath::Pi() * 180.);
1263     GetESDsData(kESDThetaY)->Fill(esdTrack->GetThetaYUncorrected() / TMath::Pi() * 180.);
1264     GetESDsData(kESDnClustersPerTrack)->Fill(track->GetNClusters());
1265     
1266     // loop over clusters
1267     AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
1268     while (trackParam) {
1269       
1270       AliMUONVCluster* cluster = trackParam->GetClusterPtr();
1271       Int_t chId = cluster->GetChamberId();
1272       Int_t deID = cluster->GetDetElemId();
1273       Double_t residualX = cluster->GetX() - trackParam->GetNonBendingCoor();
1274       Double_t residualY = cluster->GetY() - trackParam->GetBendingCoor();
1275       Double_t sigmaResidualX2 = cluster->GetErrX2() - trackParam->GetCovariances()(0,0);
1276       Double_t sigmaResidualY2 = cluster->GetErrY2() - trackParam->GetCovariances()(2,2);
1277       Double_t localChi2X = (sigmaResidualX2 > 0.) ? residualX*residualX/sigmaResidualX2 : 0.;
1278       Double_t localChi2Y = (sigmaResidualY2 > 0.) ? residualY*residualY/sigmaResidualY2 : 0.;
1279       Double_t localChi2 = 0.5 * trackParam->GetLocalChi2();
1280       
1281       GetESDsData(kESDClusterHitMap+chId)->Fill(cluster->GetX(), cluster->GetY());
1282       
1283       GetESDsData(kESDnTotClustersPerCh)->Fill(chId);
1284       GetESDsData(kESDnTotClustersPerDE)->Fill(deID);
1285       
1286       GetESDsData(kESDClusterChargeInCh+chId)->Fill(cluster->GetCharge());
1287       GetESDsData(kESDSumClusterChargePerDE)->Fill(deID, cluster->GetCharge());
1288       
1289       if (cluster->GetNDigits() > 0) { // discard clusters with pad not stored in ESD
1290         GetESDsData(kESDnTotFullClustersPerDE)->Fill(deID);
1291         GetESDsData(kESDClusterSizeInCh+chId)->Fill(cluster->GetNDigits());
1292         GetESDsData(kESDSumClusterSizePerDE)->Fill(deID, cluster->GetNDigits());
1293       }
1294       
1295       GetESDsData(kESDResidualXInCh+chId)->Fill(residualX);
1296       GetESDsData(kESDResidualYInCh+chId)->Fill(residualY);
1297       GetESDsData(kESDSumResidualXPerDE)->Fill(deID, residualX);
1298       GetESDsData(kESDSumResidualYPerDE)->Fill(deID, residualY);
1299       GetESDsData(kESDSumResidualX2PerDE)->Fill(deID, residualX*residualX);
1300       GetESDsData(kESDSumResidualY2PerDE)->Fill(deID, residualY*residualY);
1301       
1302       GetESDsData(kESDLocalChi2XInCh+chId)->Fill(localChi2X);
1303       GetESDsData(kESDLocalChi2YInCh+chId)->Fill(localChi2Y);
1304       GetESDsData(kESDLocalChi2InCh+chId)->Fill(localChi2);
1305       GetESDsData(kESDSumLocalChi2XPerDE)->Fill(deID, localChi2X);
1306       GetESDsData(kESDSumLocalChi2YPerDE)->Fill(deID, localChi2Y);
1307       GetESDsData(kESDSumLocalChi2PerDE)->Fill(deID, localChi2);
1308       
1309       trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
1310     }
1311     
1312   }
1313   
1314   GetESDsData(kESDMatchTrig)->Fill(nTrackMatchTrig);
1315   
1316 }
1317
1318 //____________________________________________________________________________ 
1319 void AliMUONQADataMakerRec::StartOfDetectorCycle()
1320 {
1321     /// Detector specific actions at start of cycle
1322   
1323 }
1324
1325 //____________________________________________________________________________ 
1326 void AliMUONQADataMakerRec::DisplayTriggerInfo(AliQAv1::TASKINDEX_t task)
1327 {
1328   //
1329   /// Display trigger information in a user-friendly way:
1330   /// from local board and strip numbers to their position on chambers
1331   //
1332   
1333
1334   if(task!=AliQAv1::kRECPOINTS && task!=AliQAv1::kRAWS) return;
1335
1336   // check we get histograms, otherwise return right now
1337   if ( task == AliQAv1::kRECPOINTS )
1338   {
1339     if ( !GetRecPointsData(kTriggerDigitsBendPlane) ) return;
1340   }
1341   
1342   if ( task == AliQAv1::kRAWS ) 
1343   {
1344     if ( !GetRawsData(kTriggerScalersBP) ) return;
1345   }
1346   
1347   AliMUONTriggerDisplay triggerDisplay;
1348   
1349   TH3F* histoStrips=0x0;
1350   TH2F* histoDisplayStrips=0x0;
1351
1352   for (Int_t iCath = 0; iCath < AliMpConstants::NofCathodes(); iCath++)
1353   {
1354     if(task==AliQAv1::kRECPOINTS){
1355       ERecPoints hindex 
1356         = ( iCath == 0 ) ? kTriggerDigitsBendPlane : kTriggerDigitsNonBendPlane;
1357       histoStrips = (TH3F*)GetRecPointsData(hindex);
1358     }
1359     else if(task==AliQAv1::kRAWS){
1360       ERaw hindex 
1361         = ( iCath == 0 ) ? kTriggerScalersBP : kTriggerScalersNBP;
1362       histoStrips = (TH3F*)GetRawsData(hindex);
1363       if(histoStrips->GetEntries()==0) continue; // No scalers found
1364     }
1365     
1366     for (Int_t iChamber = 0; iChamber < AliMpConstants::NofTriggerChambers(); iChamber++)
1367     {
1368       if(task==AliQAv1::kRECPOINTS){
1369         histoDisplayStrips = (TH2F*)GetRecPointsData(kTriggerDigitsDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
1370       }
1371       else if(task==AliQAv1::kRAWS){
1372         histoDisplayStrips = (TH2F*)GetRawsData(kTriggerScalersDisplay + AliMpConstants::NofTriggerChambers()*iCath + iChamber);
1373       }
1374       Int_t bin = histoStrips->GetXaxis()->FindBin(11+iChamber);
1375       histoStrips->GetXaxis()->SetRange(bin,bin);
1376       TH2F* inputHisto = (TH2F*)histoStrips->Project3D("zy");
1377       triggerDisplay.FillDisplayHistogram(inputHisto, histoDisplayStrips, AliMUONTriggerDisplay::kDisplayStrips, iCath, iChamber);
1378       if(task==AliQAv1::kRAWS) {
1379         Float_t acquisitionTime = ((TH1F*)GetRawsData(kTriggerScalersTime))->GetBinContent(1);
1380         histoDisplayStrips->Scale(1./acquisitionTime);
1381       }
1382     } // iChamber
1383   } // iCath
1384
1385   if(task==AliQAv1::kRAWS){    
1386     TH2F* histoI  = (TH2F*) GetRawsData(kTriggerRPCi);
1387     TH2F* histoHV = (TH2F*) GetRawsData(kTriggerRPChv);
1388     FillTriggerDCSHistos();
1389     for (Int_t iChamber = 0; iChamber < AliMpConstants::NofTriggerChambers(); iChamber++) {
1390       Int_t bin = histoI->GetXaxis()->FindBin(11+iChamber);
1391       TH2F* histoDisplayI = (TH2F*)GetRawsData(kTriggerIDisplay + iChamber);
1392       triggerDisplay.FillDisplayHistogram(histoI->ProjectionY("_px", bin, bin), histoDisplayI, AliMUONTriggerDisplay::kDisplaySlats, 0, iChamber);
1393       TH2F* histoDisplayHV = (TH2F*)GetRawsData(kTriggerHVDisplay + iChamber);
1394       bin = histoHV->GetXaxis()->FindBin(11+iChamber);
1395       triggerDisplay.FillDisplayHistogram(histoHV->ProjectionY("_px", bin, bin), histoDisplayHV, AliMUONTriggerDisplay::kDisplaySlats, 0, iChamber);
1396     }
1397   }
1398
1399   if(task==AliQAv1::kRECPOINTS){
1400     TH1F* histoBoards = (TH1F*)GetRecPointsData(kTriggeredBoards);
1401     TH2F* histoDisplayBoards = (TH2F*)GetRecPointsData(kTriggerBoardsDisplay);
1402     triggerDisplay.FillDisplayHistogram(histoBoards, histoDisplayBoards, AliMUONTriggerDisplay::kDisplayBoards, 0, 0);
1403   }
1404 }
1405
1406
1407 //_____________________________________________________________________________
1408 Bool_t 
1409 AliMUONQADataMakerRec::FillTriggerDCSHistos()
1410 {
1411   /// Get HV and currents values for one trigger chamber
1412   
1413   AliCodeTimerAuto("");
1414
1415   AliMUONCalibrationData calibrationData(AliCDBManager::Instance()->GetRun());
1416
1417   TMap* triggerDcsMap = calibrationData.TriggerDCS();
1418
1419   if ( !triggerDcsMap ) 
1420   {
1421     AliError("Cannot fill DCS histos, as triggerDcsMap is NULL");
1422     return kFALSE;
1423   }
1424
1425   AliMpDEIterator deIt;
1426   
1427   deIt.First();
1428     
1429   AliMpDCSNamer triggerDcsNamer("TRIGGER");
1430
1431   TH2* currHisto = 0x0;
1432
1433   Bool_t error = kFALSE;
1434   
1435   while ( !deIt.IsDone() )
1436   {
1437     Int_t detElemId = deIt.CurrentDEId();
1438     
1439     if ( AliMpDEManager::GetStationType(detElemId) == AliMp::kStationTrigger) {
1440
1441       Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
1442       Int_t slat = detElemId%100;
1443
1444       for(Int_t iMeas=0; iMeas<AliMpDCSNamer::kNDCSMeas; iMeas++){
1445         TString currAlias = triggerDcsNamer.DCSChannelName(detElemId, 0, iMeas);
1446
1447         AliDebug(AliQAv1::GetQADebugLevel(), Form("\nDetElemId %i   dcsAlias %s", detElemId, currAlias.Data()));
1448
1449         TPair* triggerDcsPair = static_cast<TPair*>(triggerDcsMap->FindObject(currAlias.Data()));
1450
1451         if (!triggerDcsPair)
1452         {
1453           AliError(Form("Did not find expected alias (%s) for DE %d",
1454                         currAlias.Data(),detElemId));  
1455           error = kTRUE;
1456         }
1457         else
1458         {
1459           TObjArray* values = static_cast<TObjArray*>(triggerDcsPair->Value());
1460           if (!values)
1461           {
1462             AliError(Form("Could not get values for alias %s",currAlias.Data()));
1463             error = kTRUE;
1464           }
1465           else
1466           {
1467             TIter next(values);
1468             AliDCSValue* val;
1469
1470             while ( ( val = static_cast<AliDCSValue*>(next()) ) )
1471             {
1472               Float_t hvi = val->GetFloat();
1473
1474               AliDebug(AliQAv1::GetQADebugLevel(), Form("Value %f", hvi));
1475
1476               switch(iMeas){
1477               case AliMpDCSNamer::kDCSI:
1478                 currHisto = (TH2F*) GetRawsData(kTriggerRPCi);
1479                 break;
1480               case AliMpDCSNamer::kDCSHV:
1481                 currHisto = (TH2F*) GetRawsData(kTriggerRPChv);
1482                 break;
1483               } 
1484               Int_t binX = currHisto->GetXaxis()->FindBin(iChamber+1);
1485               Int_t binY = currHisto->GetYaxis()->FindBin(slat);
1486               currHisto->SetBinContent(binX, binY, hvi);
1487             } // loop on values
1488           } // if (!values)
1489         } // if (!triggerDcsPair)
1490       } // loop on measured types (HV and currents)
1491     } // if (stationType == kStationTrigger)
1492
1493     deIt.Next();
1494   }
1495   return error;
1496 }
1497
1498 //____________________________________________________________________________ 
1499 AliMUONVTrackerData* AliMUONQADataMakerRec::GetTrackerData() const
1500
1501 /// Return tracker data
1502   
1503   return fTrackerDataMaker->Data(); 
1504   
1505 }