technical changes:
[u/mrichter/AliRoot.git] / CORRFW / AliCFTrackQualityCuts.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 // The class AliCFTrackQualityCuts is designed to select reconstructed tracks
17 // of high quality and to provide corresponding QA histograms.
18 // This class inherits from the Analysis' Framework abstract base class
19 // AliAnalysisCuts and is a part of the Correction Framework.
20 // This class acts on single, reconstructed tracks, it is applicable on
21 // ESD and AOD data.
22 // It mainly consists of a IsSelected function that returns a boolean.
23 // This function checks whether the considered track passes a set of cuts:
24 // - number of clusters in the ITS
25 // - number of clusters in the TPC
26 // - number of clusters in the TRD
27 // - ratio of found / finable number of clusters in the TPC
28 // - number of tracklets in the TRD
29 // - number TRD tracklets used for pid
30 // - chi2 / cluster in the ITS
31 // - chi2 / cluster in the TPC
32 // - chi2 / tracklet in the TRD
33 // - successful TPC refit
34 // - successful ITS refit
35 // - covariance matrix diagonal elements
36 //
37 // The cut values for these cuts are set with the corresponding set functions.
38 // All cut classes provided by the correction framework are supposed to be
39 // added in the Analysis Framwork's class AliAnalysisFilter and applied by
40 // the filter via a loop.
41 //
42 // author: I. Kraus (Ingrid.Kraus@cern.ch)
43 // idea taken form
44 // AliESDtrackCuts writte by Jan Fiete Grosse-Oetringhaus and
45 // AliRsnDaughterCut class written by A. Pulvirenti.
46
47
48 #include <TCanvas.h>
49 #include <TDirectory.h>
50 #include <TH2.h>
51 #include <TBits.h>
52
53 #include <AliESDtrack.h>
54 #include <AliLog.h>
55 #include "AliCFTrackQualityCuts.h"
56 #include "AliAODTrack.h"
57
58 ClassImp(AliCFTrackQualityCuts)
59
60 //__________________________________________________________________________________
61 AliCFTrackQualityCuts::AliCFTrackQualityCuts() :
62   AliCFCutBase(),
63   fMinNClusterTPC(0),
64   fMinNClusterITS(0),
65   fMinNClusterTRD(0),
66   fMinFoundClusterTPC(0),
67   fMinNTrackletTRD(0),
68   fMinNTrackletTRDpid(0),
69   fMaxChi2PerClusterTPC(0),
70   fMaxChi2PerClusterITS(0),
71   fMaxChi2PerTrackletTRD(0),
72   fCovariance11Max(0),
73   fCovariance22Max(0),
74   fCovariance33Max(0),
75   fCovariance44Max(0),
76   fCovariance55Max(0),
77   fStatus(0),
78   fhCutStatistics(0),
79   fhCutCorrelation(0),
80   fBitmap(0x0),
81   fhNBinsClusterTPC(0),
82   fhNBinsClusterITS(0),
83   fhNBinsClusterTRD(0),
84   fhNBinsFoundClusterTPC(0),
85   fhNBinsTrackletTRD(0),
86   fhNBinsTrackletTRDpid(0),
87   fhNBinsChi2TPC(0),
88   fhNBinsChi2ITS(0),
89   fhNBinsChi2TRD(0),
90   fhNBinsCovariance11(0),
91   fhNBinsCovariance22(0),
92   fhNBinsCovariance33(0),
93   fhNBinsCovariance44(0),
94   fhNBinsCovariance55(0),
95   fhBinLimClusterTPC(0x0),
96   fhBinLimClusterITS(0x0),
97   fhBinLimClusterTRD(0x0),
98   fhBinLimFoundClusterTPC(0x0),
99   fhBinLimTrackletTRD(0x0),
100   fhBinLimTrackletTRDpid(0x0),
101   fhBinLimChi2TPC(0x0),
102   fhBinLimChi2ITS(0x0),
103   fhBinLimChi2TRD(0x0),
104   fhBinLimCovariance11(0x0),
105   fhBinLimCovariance22(0x0),
106   fhBinLimCovariance33(0x0),
107   fhBinLimCovariance44(0x0),
108   fhBinLimCovariance55(0x0)
109 {
110   //
111   // Default constructor
112   //
113   Initialise();
114 }
115 //__________________________________________________________________________________
116 AliCFTrackQualityCuts::AliCFTrackQualityCuts(Char_t* name, Char_t* title) :
117   AliCFCutBase(name,title),
118   fMinNClusterTPC(0),
119   fMinNClusterITS(0),
120   fMinNClusterTRD(0),
121   fMinFoundClusterTPC(0),
122   fMinNTrackletTRD(0),
123   fMinNTrackletTRDpid(0),
124   fMaxChi2PerClusterTPC(0),
125   fMaxChi2PerClusterITS(0),
126   fMaxChi2PerTrackletTRD(0),
127   fCovariance11Max(0),
128   fCovariance22Max(0),
129   fCovariance33Max(0),
130   fCovariance44Max(0),
131   fCovariance55Max(0),
132   fStatus(0),
133   fhCutStatistics(0),
134   fhCutCorrelation(0),
135   fBitmap(0x0),
136   fhNBinsClusterTPC(0),
137   fhNBinsClusterITS(0),
138   fhNBinsClusterTRD(0),
139   fhNBinsFoundClusterTPC(0),
140   fhNBinsTrackletTRD(0),
141   fhNBinsTrackletTRDpid(0),
142   fhNBinsChi2TPC(0),
143   fhNBinsChi2ITS(0),
144   fhNBinsChi2TRD(0),
145   fhNBinsCovariance11(0),
146   fhNBinsCovariance22(0),
147   fhNBinsCovariance33(0),
148   fhNBinsCovariance44(0),
149   fhNBinsCovariance55(0),
150   fhBinLimClusterTPC(0x0),
151   fhBinLimClusterITS(0x0),
152   fhBinLimClusterTRD(0x0),
153   fhBinLimFoundClusterTPC(0x0),
154   fhBinLimTrackletTRD(0x0),
155   fhBinLimTrackletTRDpid(0x0),
156   fhBinLimChi2TPC(0x0),
157   fhBinLimChi2ITS(0x0),
158   fhBinLimChi2TRD(0x0),
159   fhBinLimCovariance11(0x0),
160   fhBinLimCovariance22(0x0),
161   fhBinLimCovariance33(0x0),
162   fhBinLimCovariance44(0x0),
163   fhBinLimCovariance55(0x0)
164 {
165   //
166   // Constructor
167   //
168   Initialise();
169 }
170 //__________________________________________________________________________________
171 AliCFTrackQualityCuts::AliCFTrackQualityCuts(const AliCFTrackQualityCuts& c) :
172   AliCFCutBase(c),
173   fMinNClusterTPC(c.fMinNClusterTPC),
174   fMinNClusterITS(c.fMinNClusterITS),
175   fMinNClusterTRD(c.fMinNClusterTRD),
176   fMinFoundClusterTPC(c.fMinFoundClusterTPC),
177   fMinNTrackletTRD(c.fMinNTrackletTRD),
178   fMinNTrackletTRDpid(c.fMinNTrackletTRDpid),
179   fMaxChi2PerClusterTPC(c.fMaxChi2PerClusterTPC),
180   fMaxChi2PerClusterITS(c.fMaxChi2PerClusterITS),
181   fMaxChi2PerTrackletTRD(c.fMaxChi2PerTrackletTRD),
182   fCovariance11Max(c.fCovariance11Max),
183   fCovariance22Max(c.fCovariance22Max),
184   fCovariance33Max(c.fCovariance33Max),
185   fCovariance44Max(c.fCovariance44Max),
186   fCovariance55Max(c.fCovariance55Max),
187   fStatus(c.fStatus),
188   fhCutStatistics(c.fhCutStatistics),
189   fhCutCorrelation(c.fhCutCorrelation),
190   fBitmap(c.fBitmap),
191   fhNBinsClusterTPC(c.fhNBinsClusterTPC),
192   fhNBinsClusterITS(c.fhNBinsClusterITS),
193   fhNBinsClusterTRD(c.fhNBinsClusterTRD),
194   fhNBinsFoundClusterTPC(c.fhNBinsFoundClusterTPC),
195   fhNBinsTrackletTRD(c.fhNBinsTrackletTRD),
196   fhNBinsTrackletTRDpid(c.fhNBinsTrackletTRDpid),
197   fhNBinsChi2TPC(c.fhNBinsChi2TPC),
198   fhNBinsChi2ITS(c.fhNBinsChi2ITS),
199   fhNBinsChi2TRD(c.fhNBinsChi2TRD),
200   fhNBinsCovariance11(c.fhNBinsCovariance11),
201   fhNBinsCovariance22(c.fhNBinsCovariance22),
202   fhNBinsCovariance33(c.fhNBinsCovariance33),
203   fhNBinsCovariance44(c.fhNBinsCovariance44),
204   fhNBinsCovariance55(c.fhNBinsCovariance55),
205   fhBinLimClusterTPC(c.fhBinLimClusterTPC),
206   fhBinLimClusterITS(c.fhBinLimClusterITS),
207   fhBinLimClusterTRD(c.fhBinLimClusterTRD),
208   fhBinLimFoundClusterTPC(c.fhBinLimFoundClusterTPC),
209   fhBinLimTrackletTRD(c.fhBinLimTrackletTRD),
210   fhBinLimTrackletTRDpid(c.fhBinLimTrackletTRDpid),
211   fhBinLimChi2TPC(c.fhBinLimChi2TPC),
212   fhBinLimChi2ITS(c.fhBinLimChi2ITS),
213   fhBinLimChi2TRD(c.fhBinLimChi2TRD),
214   fhBinLimCovariance11(c.fhBinLimCovariance11),
215   fhBinLimCovariance22(c.fhBinLimCovariance22),
216   fhBinLimCovariance33(c.fhBinLimCovariance33),
217   fhBinLimCovariance44(c.fhBinLimCovariance44),
218   fhBinLimCovariance55(c.fhBinLimCovariance55)
219 {
220   //
221   // copy constructor
222   //
223   ((AliCFTrackQualityCuts &) c).Copy(*this);
224 }
225 //__________________________________________________________________________________
226 AliCFTrackQualityCuts& AliCFTrackQualityCuts::operator=(const AliCFTrackQualityCuts& c)
227 {
228   //
229   // Assignment operator
230   //
231   if (this != &c) {
232     AliCFCutBase::operator=(c) ;
233     fMinNClusterTPC = c.fMinNClusterTPC ;
234     fMinNClusterITS = c.fMinNClusterITS ;
235     fMinNClusterTRD = c.fMinNClusterTRD ;
236     fMinFoundClusterTPC = c.fMinFoundClusterTPC ;
237     fMinNTrackletTRD = c.fMinNTrackletTRD ;
238     fMinNTrackletTRDpid = c.fMinNTrackletTRDpid ;
239     fMaxChi2PerClusterTPC = c.fMaxChi2PerClusterTPC ;
240     fMaxChi2PerClusterITS = c.fMaxChi2PerClusterITS ;
241     fMaxChi2PerTrackletTRD = c.fMaxChi2PerTrackletTRD ;
242     fCovariance11Max = c.fCovariance11Max ;
243     fCovariance22Max = c.fCovariance22Max ;
244     fCovariance33Max = c.fCovariance33Max ;
245     fCovariance44Max = c.fCovariance44Max ;
246     fCovariance55Max = c.fCovariance55Max ;
247     fStatus = c.fStatus ;
248     fhCutStatistics = c.fhCutStatistics ;
249     fhCutCorrelation = c.fhCutCorrelation ;
250     fBitmap =  c.fBitmap ;
251     fhNBinsClusterTPC = c.fhNBinsClusterTPC ;
252     fhNBinsClusterITS = c.fhNBinsClusterITS ;
253     fhNBinsClusterTRD = c.fhNBinsClusterTRD ;
254     fhNBinsFoundClusterTPC = c.fhNBinsFoundClusterTPC ;
255     fhNBinsTrackletTRD = c.fhNBinsTrackletTRD ;
256     fhNBinsTrackletTRDpid = c.fhNBinsTrackletTRDpid ;
257     fhNBinsChi2TPC = c.fhNBinsChi2TPC ;
258     fhNBinsChi2ITS = c.fhNBinsChi2ITS ;
259     fhNBinsChi2TRD = c.fhNBinsChi2TRD ;
260     fhNBinsCovariance11 = c.fhNBinsCovariance11 ;
261     fhNBinsCovariance22 = c.fhNBinsCovariance22 ;
262     fhNBinsCovariance33 = c.fhNBinsCovariance33 ;
263     fhNBinsCovariance44 = c.fhNBinsCovariance44 ;
264     fhNBinsCovariance55 = c.fhNBinsCovariance55 ;
265     fhBinLimClusterTPC = c.fhBinLimClusterTPC ;
266     fhBinLimClusterITS = c.fhBinLimClusterITS ;
267     fhBinLimClusterTRD = c.fhBinLimClusterTRD ;
268     fhBinLimFoundClusterTPC = c.fhBinLimFoundClusterTPC ;
269     fhBinLimTrackletTRD = c.fhBinLimTrackletTRD ;
270     fhBinLimTrackletTRDpid = c.fhBinLimTrackletTRDpid ;
271     fhBinLimChi2TPC = c.fhBinLimChi2TPC ;
272     fhBinLimChi2ITS = c.fhBinLimChi2ITS ;
273     fhBinLimChi2TRD = c.fhBinLimChi2TRD ;
274     fhBinLimCovariance11 = c.fhBinLimCovariance11 ;
275     fhBinLimCovariance22 = c.fhBinLimCovariance22 ;
276     fhBinLimCovariance33 = c.fhBinLimCovariance33 ;
277     fhBinLimCovariance44 = c.fhBinLimCovariance44 ;
278     fhBinLimCovariance55 = c.fhBinLimCovariance55 ;
279
280     for (Int_t i=0; i<c.kNHist; i++){
281       for (Int_t j=0; j<c.kNStepQA; j++){
282         if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
283       }
284     }
285     ((AliCFTrackQualityCuts &) c).Copy(*this);
286   }
287   return *this;
288 }
289 //__________________________________________________________________________________
290 AliCFTrackQualityCuts::~AliCFTrackQualityCuts()
291 {
292   //
293   // destructor
294   //
295   if (fhCutStatistics)  delete fhCutStatistics;
296   if (fhCutCorrelation) delete fhCutCorrelation;
297
298   for (Int_t i=0; i<kNHist; i++){
299     for (Int_t j=0; j<kNStepQA; j++){
300       if(fhQA[i][j]) delete fhQA[i][j];
301     }
302   }
303   if(fBitmap) delete fBitmap;
304   if(fhBinLimClusterTPC) delete fhBinLimClusterTPC;
305   if(fhBinLimClusterITS) delete fhBinLimClusterITS;
306   if(fhBinLimClusterTRD) delete fhBinLimClusterTRD;
307   if(fhBinLimFoundClusterTPC) delete fhBinLimFoundClusterTPC;
308   if(fhBinLimTrackletTRD) delete fhBinLimTrackletTRD;
309   if(fhBinLimTrackletTRDpid) delete fhBinLimTrackletTRDpid;
310   if(fhBinLimChi2TPC) delete fhBinLimChi2TPC;
311   if(fhBinLimChi2ITS) delete fhBinLimChi2ITS;
312   if(fhBinLimChi2TRD) delete fhBinLimChi2TRD;
313   if(fhBinLimCovariance11) delete fhBinLimCovariance11;
314   if(fhBinLimCovariance22) delete fhBinLimCovariance22;
315   if(fhBinLimCovariance33) delete fhBinLimCovariance33;
316   if(fhBinLimCovariance44) delete fhBinLimCovariance44;
317   if(fhBinLimCovariance55) delete fhBinLimCovariance55;
318 }
319 //__________________________________________________________________________________
320 void AliCFTrackQualityCuts::Initialise()
321 {
322   //
323   // sets everything to zero
324   //
325   fMinNClusterTPC = 0;
326   fMinNClusterITS = 0;
327   fMinNClusterTRD = 0;
328   fMinFoundClusterTPC = 0;
329   fMinNTrackletTRD = 0;
330   fMinNTrackletTRDpid = 0;
331   fMaxChi2PerClusterTPC = 0;
332   fMaxChi2PerClusterITS = 0;
333   fMaxChi2PerTrackletTRD = 0;
334   fCovariance11Max = 0;
335   fCovariance22Max = 0;
336   fCovariance33Max = 0;
337   fCovariance44Max = 0;
338   fCovariance55Max = 0;
339   fStatus = 0;
340
341   SetMinNClusterTPC();
342   SetMinNClusterITS();
343   SetMinNClusterTRD();
344   SetMinFoundClusterTPC();
345   SetMinNTrackletTRD();
346   SetMinNTrackletTRDpid();
347   SetMaxChi2PerClusterTPC();
348   SetMaxChi2PerClusterITS();
349   SetMaxChi2PerTrackletTRD();
350   SetMaxCovDiagonalElements();
351   SetStatus();
352
353   for (Int_t i=0; i<kNHist; i++){
354     for (Int_t j=0; j<kNStepQA; j++)
355       fhQA[i][j] = 0x0;
356   }
357   fhCutStatistics = 0;
358   fhCutCorrelation = 0;
359   fBitmap=new TBits(0);
360
361   //set default bining for QA histograms
362   SetHistogramBins(kCutClusterTPC,165,-0.5,164.5);
363   SetHistogramBins(kCutClusterITS,8,-0.5,7.5);
364   SetHistogramBins(kCutClusterTRD,120,-0.5,119.5);
365   SetHistogramBins(kCutMinFoundClusterTPC,110,-0.05,1.05);
366   SetHistogramBins(kCutTrackletTRD,7,-0.5,6.5);
367   SetHistogramBins(kCutTrackletTRDpid,7,-0.5,6.5);
368   SetHistogramBins(kCutChi2TPC,500,0.,10.);
369   SetHistogramBins(kCutChi2ITS,500,0.,10.);
370   SetHistogramBins(kCutChi2TRD,500,0.,10.);
371   SetHistogramBins(kCutCovElement11,200,0.,20.);
372   SetHistogramBins(kCutCovElement22,200,0.,20.);
373   SetHistogramBins(kCutCovElement33,100,0.,1.);
374   SetHistogramBins(kCutCovElement44,100,0.,5.);
375   SetHistogramBins(kCutCovElement55,100,0.,5.);
376 }
377 //__________________________________________________________________________________
378 void AliCFTrackQualityCuts::Copy(TObject &c) const
379 {
380   //
381   // Copy function
382   //
383   AliCFTrackQualityCuts& target = (AliCFTrackQualityCuts &) c;
384
385   target.Initialise();
386
387   if (fhCutStatistics)  target.fhCutStatistics = (TH1F*) fhCutStatistics->Clone();
388   if (fhCutCorrelation) target.fhCutCorrelation = (TH2F*) fhCutCorrelation->Clone();
389
390   for (Int_t i=0; i<kNHist; i++){
391     for (Int_t j=0; j<kNStepQA; j++){
392       if(fhQA[i][j]) target.fhQA[i][j] = (TH1F*)fhQA[i][j]->Clone();
393     }
394   }
395   TNamed::Copy(c);
396 }
397 //__________________________________________________________________________________
398 void AliCFTrackQualityCuts::SelectionBitMap(TObject* obj)
399 {
400   //
401   // test if the track passes the single cuts
402   // and store the information in a bitmap
403   //
404
405   // bitmap stores the decision of each single cut
406   for(Int_t i=0; i<kNCuts; i++)fBitmap->SetBitNumber(i,kFALSE);
407
408   if (!obj) return;
409   if (!obj->InheritsFrom("AliVParticle")) {
410     AliError("object must derived from AliVParticle !");
411     return;
412   }
413
414   Bool_t isESDTrack = strcmp(obj->ClassName(),"AliESDtrack") == 0 ? kTRUE : kFALSE ;
415   Bool_t isAODTrack = strcmp(obj->ClassName(),"AliAODTrack") == 0 ? kTRUE : kFALSE ;
416
417   AliESDtrack * esdTrack = 0x0 ;
418   AliAODTrack * aodTrack = 0x0 ; 
419   if (isESDTrack) esdTrack = dynamic_cast<AliESDtrack*>(obj);
420   if (isAODTrack) aodTrack = dynamic_cast<AliAODTrack*>(obj);
421
422   // get cut quantities
423   Int_t    nClustersTPC = 0;
424   Int_t    nClustersITS = 0 ;
425   Int_t    nClustersTRD = 0 ;
426   Int_t    nTrackletsTRD = 0 ;
427   Float_t  chi2PerClusterTPC =  0 ;
428   Float_t  chi2PerClusterITS = 0 ;
429   Float_t  chi2PerTrackletTRD = 0 ;
430   Double_t extCov[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
431   Float_t fractionFoundClustersTPC = 0;
432
433   if (isESDTrack) {
434     nClustersTPC = esdTrack->GetTPCclusters(0x0);
435     nClustersITS = esdTrack->GetITSclusters(0x0);
436     nClustersTRD = esdTrack->GetTRDncls();
437     nTrackletsTRD = esdTrack->GetTRDntracklets();
438     if (nClustersTPC != 0) chi2PerClusterTPC = esdTrack->GetTPCchi2() / Float_t(nClustersTPC);
439     if (nClustersITS != 0) chi2PerClusterITS = esdTrack->GetITSchi2() / Float_t(nClustersITS);
440     if (nTrackletsTRD != 0) chi2PerTrackletTRD = esdTrack->GetTRDchi2() / Float_t(nTrackletsTRD);
441     esdTrack->GetExternalCovariance(extCov);
442     if (esdTrack->GetTPCNclsF() != 0) fractionFoundClustersTPC = float(nClustersTPC) / float(esdTrack->GetTPCNclsF());
443   }
444
445   // fill the bitmap
446   Int_t iCutBit = 0;
447
448   if (nClustersTPC >= fMinNClusterTPC)
449     fBitmap->SetBitNumber(iCutBit,kTRUE);
450   iCutBit++;
451   if (nClustersITS >= fMinNClusterITS)
452     fBitmap->SetBitNumber(iCutBit,kTRUE);
453   iCutBit++;
454   if (nClustersTRD >= fMinNClusterTRD)
455     fBitmap->SetBitNumber(iCutBit,kTRUE);
456   iCutBit++;
457   if ((fMinFoundClusterTPC <= 0) || (nClustersTPC > 0 && (fractionFoundClustersTPC >= fMinFoundClusterTPC)))
458     fBitmap->SetBitNumber(iCutBit,kTRUE);
459   iCutBit++;
460   if (nTrackletsTRD >= fMinNTrackletTRD)
461     fBitmap->SetBitNumber(iCutBit,kTRUE);
462   iCutBit++;
463   if (esdTrack->GetTRDntrackletsPID() >= fMinNTrackletTRDpid)
464     fBitmap->SetBitNumber(iCutBit,kTRUE);
465   iCutBit++;
466   if (chi2PerClusterTPC <= fMaxChi2PerClusterTPC)
467     fBitmap->SetBitNumber(iCutBit,kTRUE);
468   iCutBit++;
469   if (chi2PerClusterITS <= fMaxChi2PerClusterITS)
470     fBitmap->SetBitNumber(iCutBit,kTRUE);
471   iCutBit++;
472   if (chi2PerTrackletTRD <= fMaxChi2PerTrackletTRD)
473     fBitmap->SetBitNumber(iCutBit,kTRUE);
474   iCutBit++;
475   if (extCov[0]  <= fCovariance11Max)
476     fBitmap->SetBitNumber(iCutBit,kTRUE);
477   iCutBit++;
478   if (extCov[2]  <= fCovariance22Max)
479     fBitmap->SetBitNumber(iCutBit,kTRUE);
480   iCutBit++;
481   if (extCov[5]  <= fCovariance33Max)
482     fBitmap->SetBitNumber(iCutBit,kTRUE);
483   iCutBit++;
484   if (extCov[9]  <= fCovariance44Max)
485     fBitmap->SetBitNumber(iCutBit,kTRUE);
486   iCutBit++;
487   if (extCov[14] <= fCovariance55Max)
488     fBitmap->SetBitNumber(iCutBit,kTRUE);
489   iCutBit++;
490   
491   if (isESDTrack) {
492     if ( (esdTrack->GetStatus() & fStatus) == fStatus ) fBitmap->SetBitNumber(iCutBit,kTRUE);
493   }
494   else {
495     if ( (aodTrack->GetStatus() & fStatus) == fStatus ) fBitmap->SetBitNumber(iCutBit,kTRUE);
496   }
497
498   return;
499 }
500 //__________________________________________________________________________________
501 Bool_t AliCFTrackQualityCuts::IsSelected(TObject* obj) {
502   //
503   // loops over decisions of single cuts and returns if the track is accepted
504   //
505   SelectionBitMap(obj);
506
507   if (fIsQAOn) FillHistograms(obj,0);
508   Bool_t isSelected = kTRUE;
509
510   for (UInt_t icut=0; icut<fBitmap->GetNbits();icut++) {
511     if(!fBitmap->TestBitNumber(icut)) {
512         isSelected = kFALSE;
513         break;
514     }
515   }
516   if (!isSelected) return kFALSE ;
517   if (fIsQAOn) FillHistograms(obj,1);
518   return kTRUE;
519 }
520 //__________________________________________________________________________________
521 void AliCFTrackQualityCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t *bins)
522 {
523   //
524   // variable bin size
525   //
526   if(!fIsQAOn) return;
527
528   if (index<0 || index>=kNHist) {
529     Error("SetHistogramBins","could not determine histogram from index %d",index);
530     return;
531   }
532
533   switch(index){
534   case kCutClusterTPC:
535     fhNBinsClusterTPC=nbins+1;
536     fhBinLimClusterTPC=new Double_t[nbins+1];
537     for(Int_t i=0;i<nbins+1;i++)fhBinLimClusterTPC[i]=bins[i];
538     break;
539
540   case kCutClusterITS:
541     fhNBinsClusterITS=nbins+1;
542     fhBinLimClusterITS=new Double_t[nbins+1];
543     for(Int_t i=0;i<nbins+1;i++)fhBinLimClusterITS[i]=bins[i];
544     break;
545
546   case kCutClusterTRD:
547     fhNBinsClusterTRD=nbins+1;
548     fhBinLimClusterTRD=new Double_t[nbins+1];
549     for(Int_t i=0;i<nbins+1;i++)fhBinLimClusterTRD[i]=bins[i];
550     break;
551
552   case kCutMinFoundClusterTPC:
553     fhNBinsFoundClusterTPC=nbins+1;
554     fhBinLimFoundClusterTPC=new Double_t[nbins+1];
555     for(Int_t i=0;i<nbins+1;i++)fhBinLimFoundClusterTPC[i]=bins[i];
556     break;
557
558   case kCutTrackletTRD:
559     fhNBinsTrackletTRD=nbins+1;
560     fhBinLimTrackletTRD=new Double_t[nbins+1];
561     for(Int_t i=0;i<nbins+1;i++)fhBinLimTrackletTRD[i]=bins[i];
562     break;
563
564   case kCutTrackletTRDpid:
565     fhNBinsTrackletTRDpid=nbins+1;
566     fhBinLimTrackletTRDpid=new Double_t[nbins+1];
567     for(Int_t i=0;i<nbins+1;i++)fhBinLimTrackletTRDpid[i]=bins[i];
568     break;
569
570   case kCutChi2TPC:
571     fhNBinsChi2TPC=nbins+1;
572     fhBinLimChi2TPC=new Double_t[nbins+1];
573     for(Int_t i=0;i<nbins+1;i++)fhBinLimChi2TPC[i]=bins[i];
574     break;
575
576   case kCutChi2ITS:
577     fhNBinsChi2ITS=nbins+1;
578     fhBinLimChi2ITS=new Double_t[nbins+1];
579     for(Int_t i=0;i<nbins+1;i++)fhBinLimChi2ITS[i]=bins[i];
580     break;
581
582   case kCutChi2TRD:
583     fhNBinsChi2TRD=nbins+1;
584     fhBinLimChi2TRD=new Double_t[nbins+1];
585     for(Int_t i=0;i<nbins+1;i++)fhBinLimChi2TRD[i]=bins[i];
586     break;
587
588   case kCutCovElement11:
589     fhNBinsCovariance11=nbins+1;
590     fhBinLimCovariance11=new Double_t[nbins+1];
591     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance11[i]=bins[i];
592     break;
593
594   case kCutCovElement22:
595     fhNBinsCovariance22=nbins+1;
596     fhBinLimCovariance22=new Double_t[nbins+1];
597     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance22[i]=bins[i];
598     break;
599
600   case kCutCovElement33:
601     fhNBinsCovariance33=nbins+1;
602     fhBinLimCovariance33=new Double_t[nbins+1];
603     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance33[i]=bins[i];
604     break;
605
606   case kCutCovElement44:
607     fhNBinsCovariance44=nbins+1;
608     fhBinLimCovariance44=new Double_t[nbins+1];
609     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance44[i]=bins[i];
610     break;
611
612   case kCutCovElement55:
613     fhNBinsCovariance55=nbins+1;
614     fhBinLimCovariance55=new Double_t[nbins+1];
615     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance55[i]=bins[i];
616     break;
617  }
618 }
619 //__________________________________________________________________________________
620 void AliCFTrackQualityCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t xmin, Double_t xmax)
621 {
622   //
623   // fixed bin size
624   //
625   if (index<0 || index>=kNHist) {
626     Error("SetHistogramBins","could not determine histogram from index %d",index);
627     return;
628   }
629
630   switch(index){
631   case kCutClusterTPC:
632     fhNBinsClusterTPC=nbins+1;
633     fhBinLimClusterTPC=new Double_t[nbins+1];
634     for(Int_t i=0;i<nbins+1;i++)fhBinLimClusterTPC[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
635     break;
636
637   case kCutClusterITS:
638     fhNBinsClusterITS=nbins+1;
639     fhBinLimClusterITS=new Double_t[nbins+1];
640     for(Int_t i=0;i<nbins+1;i++)fhBinLimClusterITS[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
641     break;
642
643   case kCutClusterTRD:
644     fhNBinsClusterTRD=nbins+1;
645     fhBinLimClusterTRD=new Double_t[nbins+1];
646     for(Int_t i=0;i<nbins+1;i++)fhBinLimClusterTRD[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
647     break;
648
649   case kCutMinFoundClusterTPC:
650     fhNBinsFoundClusterTPC=nbins+1;
651     fhBinLimFoundClusterTPC=new Double_t[nbins+1];
652     for(Int_t i=0;i<nbins+1;i++)fhBinLimFoundClusterTPC[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
653     break;
654
655   case kCutTrackletTRD:
656     fhNBinsTrackletTRD=nbins+1;
657     fhBinLimTrackletTRD=new Double_t[nbins+1];
658     for(Int_t i=0;i<nbins+1;i++)fhBinLimTrackletTRD[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
659     break;
660
661   case kCutTrackletTRDpid:
662     fhNBinsTrackletTRDpid=nbins+1;
663     fhBinLimTrackletTRDpid=new Double_t[nbins+1];
664     for(Int_t i=0;i<nbins+1;i++)fhBinLimTrackletTRDpid[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
665     break;
666
667   case kCutChi2TPC:
668     fhNBinsChi2TPC=nbins+1;
669     fhBinLimChi2TPC=new Double_t[nbins+1];
670     for(Int_t i=0;i<nbins+1;i++)fhBinLimChi2TPC[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
671     break;
672
673   case kCutChi2ITS:
674     fhNBinsChi2ITS=nbins+1;
675     fhBinLimChi2ITS=new Double_t[nbins+1];
676     for(Int_t i=0;i<nbins+1;i++)fhBinLimChi2ITS[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
677     break;
678
679   case kCutChi2TRD:
680     fhNBinsChi2TRD=nbins+1;
681     fhBinLimChi2TRD=new Double_t[nbins+1];
682     for(Int_t i=0;i<nbins+1;i++)fhBinLimChi2TRD[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
683     break;
684
685   case kCutCovElement11:
686     fhNBinsCovariance11=nbins+1;
687     fhBinLimCovariance11=new Double_t[nbins+1];
688     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance11[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
689     break;
690
691   case kCutCovElement22:
692     fhNBinsCovariance22=nbins+1;
693     fhBinLimCovariance22=new Double_t[nbins+1];
694     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance22[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
695     break;
696
697   case kCutCovElement33:
698     fhNBinsCovariance33=nbins+1;
699     fhBinLimCovariance33=new Double_t[nbins+1];
700     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance33[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
701     break;
702
703   case kCutCovElement44:
704     fhNBinsCovariance44=nbins+1;
705     fhBinLimCovariance44=new Double_t[nbins+1];
706     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance44[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
707     break;
708
709   case kCutCovElement55:
710     fhNBinsCovariance55=nbins+1;
711     fhBinLimCovariance55=new Double_t[nbins+1];
712     for(Int_t i=0;i<nbins+1;i++)fhBinLimCovariance55[i]=xmin+i*(xmax-xmin)/Double_t(nbins);
713     break;
714  }
715 }
716 //__________________________________________________________________________________
717  void AliCFTrackQualityCuts::DefineHistograms() {
718   //
719   // histograms for cut variables, cut statistics and cut correlations
720   //
721   Int_t color = 2;
722
723   // book cut statistics and cut correlation histograms
724   fhCutStatistics = new TH1F(Form("%s_cut_statistics",GetName()), Form("%s cut statistics",GetName()), kNCuts,0.5,kNCuts+0.5);
725   fhCutStatistics->SetLineWidth(2);
726   fhCutStatistics->GetXaxis()->SetBinLabel(1, "nClustersTPC");
727   fhCutStatistics->GetXaxis()->SetBinLabel(2, "nClustersITS");
728   fhCutStatistics->GetXaxis()->SetBinLabel(3, "nClustersTRD");
729   fhCutStatistics->GetXaxis()->SetBinLabel(4, "fractionClustersTPC");
730   fhCutStatistics->GetXaxis()->SetBinLabel(5, "ntrackletsTRD");
731   fhCutStatistics->GetXaxis()->SetBinLabel(6, "ntrackletsTRDpid");
732   fhCutStatistics->GetXaxis()->SetBinLabel(7, "chi2PerClusterTPC");
733   fhCutStatistics->GetXaxis()->SetBinLabel(8, "chi2PerClusterITS");
734   fhCutStatistics->GetXaxis()->SetBinLabel(9, "chi2PerTrackletTRD");
735   fhCutStatistics->GetXaxis()->SetBinLabel(10, "covElement11");
736   fhCutStatistics->GetXaxis()->SetBinLabel(11, "covElement22");
737   fhCutStatistics->GetXaxis()->SetBinLabel(12, "covElement33");
738   fhCutStatistics->GetXaxis()->SetBinLabel(13, "covElement44");
739   fhCutStatistics->GetXaxis()->SetBinLabel(14, "covElement55");
740   fhCutStatistics->GetXaxis()->SetBinLabel(15, "status");
741
742   fhCutCorrelation = new TH2F(Form("%s_cut_correlation",GetName()), Form("%s cut  correlation",GetName()), kNCuts,0.5,kNCuts+0.5,kNCuts,0.5,kNCuts+0.5);
743   fhCutCorrelation->SetLineWidth(2);
744   fhCutCorrelation->GetXaxis()->SetBinLabel(1, "nClustersTPC");
745   fhCutCorrelation->GetXaxis()->SetBinLabel(2, "nClustersITS");
746   fhCutCorrelation->GetXaxis()->SetBinLabel(3, "nClustersTRD");
747   fhCutCorrelation->GetXaxis()->SetBinLabel(4, "fractionClustersTPC");
748   fhCutCorrelation->GetXaxis()->SetBinLabel(5, "ntrackletsTRD");
749   fhCutCorrelation->GetXaxis()->SetBinLabel(6, "ntrackletsTRDpid");
750   fhCutCorrelation->GetXaxis()->SetBinLabel(7, "chi2PerClusterTPC");
751   fhCutCorrelation->GetXaxis()->SetBinLabel(8, "chi2PerClusterITS");
752   fhCutCorrelation->GetXaxis()->SetBinLabel(9, "chi2PerTrackletTRD");
753   fhCutCorrelation->GetXaxis()->SetBinLabel(10, "covElement11");
754   fhCutCorrelation->GetXaxis()->SetBinLabel(11, "covElement22");
755   fhCutCorrelation->GetXaxis()->SetBinLabel(12, "covElement33");
756   fhCutCorrelation->GetXaxis()->SetBinLabel(13, "covElement44");
757   fhCutCorrelation->GetXaxis()->SetBinLabel(14, "covElement55");
758   fhCutStatistics->GetXaxis()->SetBinLabel(15, "status");
759
760   fhCutCorrelation->GetYaxis()->SetBinLabel(1, "nClustersTPC");
761   fhCutCorrelation->GetYaxis()->SetBinLabel(2, "nClustersITS");
762   fhCutCorrelation->GetYaxis()->SetBinLabel(3, "nClustersTRD");
763   fhCutCorrelation->GetYaxis()->SetBinLabel(4, "fractionClustersTPC");
764   fhCutCorrelation->GetYaxis()->SetBinLabel(5, "ntrackletsTRD");
765   fhCutCorrelation->GetYaxis()->SetBinLabel(6, "ntrackletsTRDpid");
766   fhCutCorrelation->GetYaxis()->SetBinLabel(7, "chi2PerClusterTPC");
767   fhCutCorrelation->GetYaxis()->SetBinLabel(8, "chi2PerClusterITS");
768   fhCutCorrelation->GetYaxis()->SetBinLabel(9, "chi2PerTrackletTRD");
769   fhCutCorrelation->GetYaxis()->SetBinLabel(10, "covElement11");
770   fhCutCorrelation->GetYaxis()->SetBinLabel(11, "covElement22");
771   fhCutCorrelation->GetYaxis()->SetBinLabel(12, "covElement33");
772   fhCutCorrelation->GetYaxis()->SetBinLabel(13, "covElement44");
773   fhCutCorrelation->GetYaxis()->SetBinLabel(14, "covElement55");
774   fhCutCorrelation->GetYaxis()->SetBinLabel(15, "status");
775
776
777   // book QA histograms
778   Char_t str[256];
779   for (Int_t i=0; i<kNStepQA; i++) {
780     if (i==0) sprintf(str," ");
781     else sprintf(str,"_cut");
782
783     fhQA[kCutClusterTPC][i]     = new TH1F(Form("%s_nClustersTPC%s",GetName(),str)     ,"",fhNBinsClusterTPC-1,fhBinLimClusterTPC);
784     fhQA[kCutClusterITS][i]     = new TH1F(Form("%s_nClustersITS%s",GetName(),str)     ,"",fhNBinsClusterITS-1,fhBinLimClusterITS);
785     fhQA[kCutClusterTRD][i]     = new TH1F(Form("%s_nClustersTRD%s",GetName(),str)     ,"",fhNBinsClusterTRD-1,fhBinLimClusterTRD);
786     fhQA[kCutMinFoundClusterTPC][i]     = new TH1F(Form("%s_fractionClustersTPC%s",GetName(),str)     ,"",fhNBinsFoundClusterTPC-1,fhBinLimFoundClusterTPC);
787     fhQA[kCutTrackletTRD][i]    = new TH1F(Form("%s_ntrackletsTRD%s",GetName(),str)     ,"",fhNBinsTrackletTRD-1,fhBinLimTrackletTRD);
788     fhQA[kCutTrackletTRDpid][i] = new TH1F(Form("%s_ntrackletsTRDpid%s",GetName(),str)     ,"",fhNBinsTrackletTRDpid-1,fhBinLimTrackletTRDpid);
789     fhQA[kCutChi2TPC][i]        = new TH1F(Form("%s_chi2PerClusterTPC%s",GetName(),str),"",fhNBinsChi2TPC-1,fhBinLimChi2TPC);
790     fhQA[kCutChi2ITS][i]        = new TH1F(Form("%s_chi2PerClusterITS%s",GetName(),str),"",fhNBinsChi2ITS-1,fhBinLimChi2ITS);
791     fhQA[kCutChi2TRD][i]        = new TH1F(Form("%s_chi2PerTrackletTRD%s",GetName(),str),"",fhNBinsChi2TRD-1,fhBinLimChi2TRD);
792     fhQA[kCutCovElement11][i]   = new TH1F(Form("%s_covMatrixDiagonal11%s",GetName(),str),"",fhNBinsCovariance11-1,fhBinLimCovariance11);
793     fhQA[kCutCovElement22][i]   = new TH1F(Form("%s_covMatrixDiagonal22%s",GetName(),str),"",fhNBinsCovariance22-1,fhBinLimCovariance22);
794     fhQA[kCutCovElement33][i]   = new TH1F(Form("%s_covMatrixDiagonal33%s",GetName(),str),"",fhNBinsCovariance33-1,fhBinLimCovariance33);
795     fhQA[kCutCovElement44][i]   = new TH1F(Form("%s_covMatrixDiagonal44%s",GetName(),str),"",fhNBinsCovariance44-1,fhBinLimCovariance44);
796     fhQA[kCutCovElement55][i]   = new TH1F(Form("%s_covMatrixDiagonal55%s",GetName(),str),"",fhNBinsCovariance55-1,fhBinLimCovariance55);
797
798     fhQA[kCutClusterTPC][i]     ->SetXTitle("n TPC clusters");
799     fhQA[kCutClusterITS][i]     ->SetXTitle("n ITS clusters");
800     fhQA[kCutClusterTRD][i]     ->SetXTitle("n TRD clusters");
801     fhQA[kCutMinFoundClusterTPC][i]->SetXTitle("fraction TPC clusters");
802     fhQA[kCutTrackletTRD][i] ->SetXTitle("n tracklets TRD");
803     fhQA[kCutTrackletTRDpid][i]->SetXTitle("n tracklets TRD pid");
804     fhQA[kCutChi2TPC][i]        ->SetXTitle("#chi^{2} per TPC cluster");
805     fhQA[kCutChi2ITS][i]        ->SetXTitle("#chi^{2} per ITS cluster");
806     fhQA[kCutChi2TRD][i]        ->SetXTitle("#chi^{2} per TRD tracklet");
807     fhQA[kCutCovElement11][i]   ->SetXTitle("cov 11 : #sigma_{y}^{2} (cm^{2})");
808     fhQA[kCutCovElement22][i]   ->SetXTitle("cov 22 : #sigma_{z}^{2} (cm^{2})");
809     fhQA[kCutCovElement33][i]   ->SetXTitle("cov 33 : #sigma_{sin(#phi)}^{2}");
810     fhQA[kCutCovElement44][i]   ->SetXTitle("cov 44 : #sigma_{tan(#theta_{dip})}^{2}");
811     fhQA[kCutCovElement55][i]   ->SetXTitle("cov 55 : #sigma_{1/p_{T}}^{2} ((c/GeV)^{2})");
812   }
813
814   for(Int_t i=0; i<kNHist; i++) fhQA[i][1]->SetLineColor(color);
815 }
816 //__________________________________________________________________________________
817 void AliCFTrackQualityCuts::FillHistograms(TObject* obj, Bool_t b)
818 {
819   //
820   // fill the QA histograms
821   //
822
823   if (!obj) return;
824   if (!obj->InheritsFrom("AliVParticle")) {
825     AliError("object must derived from AliVParticle !");
826     return;
827   }
828
829   Bool_t isESDTrack = strcmp(obj->ClassName(),"AliESDtrack") == 0 ? kTRUE : kFALSE ;
830   Bool_t isAODTrack = strcmp(obj->ClassName(),"AliAODTrack") == 0 ? kTRUE : kFALSE ;
831
832   AliESDtrack * esdTrack = 0x0 ;
833   AliAODTrack * aodTrack = 0x0 ; 
834   if (isESDTrack) esdTrack = dynamic_cast<AliESDtrack*>(obj);
835   if (isAODTrack) aodTrack = dynamic_cast<AliAODTrack*>(obj);
836
837   // b = 0: fill histograms before cuts
838   // b = 1: fill histograms after cuts
839
840   Int_t    nClustersTPC = 0;
841   Int_t    nClustersITS = 0 ;
842   Int_t    nClustersTRD = 0 ;
843   Int_t    nTrackletsTRD = 0 ;
844   Float_t  chi2PerClusterTPC =  0 ;
845   Float_t  chi2PerClusterITS = 0 ;
846   Float_t  chi2PerTrackletTRD = 0 ;
847   Double_t extCov[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
848   Float_t fractionFoundClustersTPC = 0;
849
850   if (isESDTrack) {
851     nClustersTPC = esdTrack->GetTPCclusters(0x0);
852     nClustersITS = esdTrack->GetITSclusters(0x0);
853     nClustersTRD = esdTrack->GetTRDncls();
854     nTrackletsTRD = esdTrack->GetTRDntracklets();
855     if (nClustersTPC != 0) chi2PerClusterTPC = esdTrack->GetTPCchi2() / Float_t(nClustersTPC);
856     if (nClustersITS != 0) chi2PerClusterITS = esdTrack->GetITSchi2() / Float_t(nClustersITS);
857     if (nTrackletsTRD != 0) chi2PerTrackletTRD = esdTrack->GetTRDchi2() / Float_t(nTrackletsTRD);
858     esdTrack->GetExternalCovariance(extCov);
859     if (esdTrack->GetTPCNclsF() != 0) fractionFoundClustersTPC = float(nClustersTPC) / float(esdTrack->GetTPCNclsF());
860  }
861   fhQA[kCutClusterTPC][b]->Fill((float)nClustersTPC);
862   fhQA[kCutChi2TPC][b]->Fill(chi2PerClusterTPC);
863   fhQA[kCutClusterITS][b]->Fill((float)nClustersITS);
864   fhQA[kCutChi2ITS][b]->Fill(chi2PerClusterITS);
865   fhQA[kCutClusterTRD][b]->Fill((float)nClustersTRD);
866   fhQA[kCutChi2TRD][b]->Fill(chi2PerTrackletTRD);
867   if (b==0 || (b==1 && nClustersTPC>0)) fhQA[kCutMinFoundClusterTPC][b]->Fill((float)fractionFoundClustersTPC);
868   fhQA[kCutTrackletTRD][b]->Fill((float)nTrackletsTRD);
869   fhQA[kCutTrackletTRDpid][b]->Fill((float)esdTrack->GetTRDntrackletsPID());
870   fhQA[kCutCovElement11][b]->Fill(extCov[0]);
871   fhQA[kCutCovElement22][b]->Fill(extCov[2]);
872   fhQA[kCutCovElement33][b]->Fill(extCov[5]);
873   fhQA[kCutCovElement44][b]->Fill(extCov[9]);
874   fhQA[kCutCovElement55][b]->Fill(extCov[14]);
875
876   // fill cut statistics and cut correlation histograms with information from the bitmap
877   if (b) return;
878
879   // Get the bitmap of the single cuts
880   if ( !obj ) return;
881   SelectionBitMap(obj);
882
883   // Number of single cuts in this class
884   UInt_t ncuts = fBitmap->GetNbits();
885   for(UInt_t bit=0; bit<ncuts;bit++) {
886     if (!fBitmap->TestBitNumber(bit)) {
887         fhCutStatistics->Fill(bit+1);
888         for (UInt_t bit2=bit; bit2<ncuts;bit2++) {
889           if (!fBitmap->TestBitNumber(bit2)) 
890             fhCutCorrelation->Fill(bit+1,bit2+1);
891         }
892     }
893   }
894 }
895 //__________________________________________________________________________________
896 void AliCFTrackQualityCuts::SaveHistograms(const Char_t* dir) {
897   //
898   // saves the histograms in a directory (dir)
899   //
900   if(!fIsQAOn) return;
901
902   if (!dir)
903     dir = GetName();
904
905   gDirectory->mkdir(dir);
906   gDirectory->cd(dir);
907
908   gDirectory->mkdir("before_cuts");
909   gDirectory->mkdir("after_cuts");
910
911   fhCutStatistics->Write();
912   fhCutCorrelation->Write();
913
914   for (Int_t j=0; j<kNStepQA; j++) {
915     if (j==0)
916       gDirectory->cd("before_cuts");
917     else
918       gDirectory->cd("after_cuts");
919
920     for(Int_t i=0; i<kNHist; i++) fhQA[i][j]->Write();
921
922     gDirectory->cd("../");
923   }
924   gDirectory->cd("../");
925 }
926 //__________________________________________________________________________________
927 void AliCFTrackQualityCuts::DrawHistograms(Bool_t drawLogScale)
928 {
929   //
930   // draws some histograms
931   //
932   if(!fIsQAOn) return;
933
934   // pad margins
935   Float_t right = 0.03;
936   Float_t left = 0.175;
937   Float_t top = 0.03;
938   Float_t bottom = 0.175;
939
940   TCanvas* canvas1 = new TCanvas("Track_QA_Quality_1", "Track QA Quality 1", 800, 500);
941   canvas1->Divide(2, 1);
942
943   canvas1->cd(1);
944   fhCutStatistics->SetStats(kFALSE);
945   fhCutStatistics->LabelsOption("v");
946   gPad->SetLeftMargin(left);
947   gPad->SetBottomMargin(0.25);
948   gPad->SetRightMargin(right);
949   gPad->SetTopMargin(0.1);
950   fhCutStatistics->Draw();
951
952   canvas1->cd(2);
953   fhCutCorrelation->SetStats(kFALSE);
954   fhCutCorrelation->LabelsOption("v");
955   gPad->SetLeftMargin(0.30);
956   gPad->SetRightMargin(bottom);
957   gPad->SetTopMargin(0.1);
958   gPad->SetBottomMargin(0.25);
959   fhCutCorrelation->Draw("COLZ");
960
961   canvas1->SaveAs(Form("%s.eps", canvas1->GetName()));
962   canvas1->SaveAs(Form("%s.ps", canvas1->GetName()));
963
964   // -----
965
966   TCanvas* canvas2 = new TCanvas("Track_QA_Quality_2", "Track QA Quality 2", 1200, 800);
967   canvas2->Divide(2, 2);
968
969   canvas2->cd(1);
970   gPad->SetRightMargin(right);
971   gPad->SetLeftMargin(left);
972   gPad->SetTopMargin(top);
973   gPad->SetBottomMargin(bottom);
974   fhQA[kCutClusterTPC][0]->SetStats(kFALSE);
975   fhQA[kCutClusterTPC][0]->Draw();
976   fhQA[kCutClusterTPC][1]->Draw("same");
977
978   canvas2->cd(2);
979   gPad->SetRightMargin(right);
980   gPad->SetLeftMargin(left);
981   gPad->SetTopMargin(top);
982   gPad->SetBottomMargin(bottom);
983   fhQA[kCutChi2TPC][0]->SetStats(kFALSE);
984   fhQA[kCutChi2TPC][0]->Draw();
985   fhQA[kCutChi2TPC][1]->Draw("same");
986
987   canvas2->cd(3);
988   gPad->SetRightMargin(right);
989   gPad->SetLeftMargin(left);
990   gPad->SetTopMargin(top);
991   gPad->SetBottomMargin(bottom);
992   fhQA[kCutClusterITS][0]->SetStats(kFALSE);
993   fhQA[kCutClusterITS][0]->Draw();
994   fhQA[kCutClusterITS][1]->Draw("same");
995
996   canvas2->cd(4);
997   gPad->SetRightMargin(right);
998   gPad->SetLeftMargin(left);
999   gPad->SetTopMargin(top);
1000   gPad->SetBottomMargin(bottom);
1001   fhQA[kCutChi2ITS][0]->SetStats(kFALSE);
1002   fhQA[kCutChi2ITS][0]->Draw();
1003   fhQA[kCutChi2ITS][1]->Draw("same");
1004
1005   canvas2->SaveAs(Form("%s.eps", canvas2->GetName()));
1006   canvas2->SaveAs(Form("%s.ps", canvas2->GetName()));
1007
1008   // -----
1009
1010   TCanvas* canvas3 = new TCanvas("Track_QA_Quality_3", "Track QA Quality 3", 1200, 800);
1011   canvas3->Divide(3, 2);
1012
1013   canvas3->cd(1);
1014   if(drawLogScale) gPad->SetLogy();
1015   gPad->SetRightMargin(right);
1016   gPad->SetLeftMargin(left);
1017   gPad->SetTopMargin(top);
1018   gPad->SetBottomMargin(bottom);
1019   fhQA[kCutCovElement11][0]->SetStats(kFALSE);
1020   fhQA[kCutCovElement11][0]->Draw();
1021   fhQA[kCutCovElement11][1]->Draw("same");
1022
1023   canvas3->cd(2);
1024   if(drawLogScale) gPad->SetLogy();
1025   gPad->SetRightMargin(right);
1026   gPad->SetLeftMargin(left);
1027   gPad->SetTopMargin(top);
1028   gPad->SetBottomMargin(bottom);
1029   fhQA[kCutCovElement22][0]->SetStats(kFALSE);
1030   fhQA[kCutCovElement22][0]->Draw();
1031   fhQA[kCutCovElement22][1]->Draw("same");
1032
1033   canvas3->cd(3);
1034   if(drawLogScale) gPad->SetLogy();
1035   gPad->SetRightMargin(right);
1036   gPad->SetLeftMargin(left);
1037   gPad->SetTopMargin(top);
1038   gPad->SetBottomMargin(bottom);
1039   fhQA[kCutCovElement33][0]->SetStats(kFALSE);
1040   fhQA[kCutCovElement33][0]->Draw();
1041   fhQA[kCutCovElement33][1]->Draw("same");
1042
1043   canvas3->cd(4);
1044   if(drawLogScale) gPad->SetLogy();
1045   gPad->SetRightMargin(right);
1046   gPad->SetLeftMargin(left);
1047   gPad->SetTopMargin(top);
1048   gPad->SetBottomMargin(bottom);
1049   fhQA[kCutCovElement44][0]->SetStats(kFALSE);
1050   fhQA[kCutCovElement44][0]->Draw();
1051   fhQA[kCutCovElement44][1]->Draw("same");
1052
1053   canvas3->cd(5);
1054   if(drawLogScale) gPad->SetLogy();
1055   gPad->SetRightMargin(right);
1056   gPad->SetLeftMargin(left);
1057   gPad->SetTopMargin(top);
1058   gPad->SetBottomMargin(bottom);
1059   fhQA[kCutCovElement55][0]->SetStats(kFALSE);
1060   fhQA[kCutCovElement55][0]->Draw();
1061   fhQA[kCutCovElement55][1]->Draw("same");
1062
1063   canvas3->SaveAs(Form("%s.eps", canvas3->GetName()));
1064   canvas3->SaveAs(Form("%s.ps", canvas3->GetName()));
1065 }
1066 //__________________________________________________________________________________
1067 void AliCFTrackQualityCuts::AddQAHistograms(TList *qaList) {
1068   //
1069   // saves the histograms in a TList
1070   //
1071   DefineHistograms();
1072
1073   qaList->Add(fhCutStatistics);
1074   qaList->Add(fhCutCorrelation);
1075
1076   for (Int_t j=0; j<kNStepQA; j++) {
1077     for(Int_t i=0; i<kNHist; i++)
1078         qaList->Add(fhQA[i][j]);
1079   }
1080 }