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