Since it contains fixes of coding rule violations, all classes are involved. Further...
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEcuts.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  *                                                                      *
17  * Cut menagement class implemented by the                              *
18  * ALICE Heavy Flavour Electron Group                                   *
19  *                                                                      *
20  * Authors:                                                             *
21  *   Raphaelle Bailhache <R.Bailhache@gsi.de>                           *
22  *   Markus Fasel <M.Fasel@gsi.de>                                      *
23  *   Markus Heide <mheide@uni-muenster.de>                              *
24  *   Matus Kalisky <m.kalisky@uni-muenster.de>                          *
25  *                                                                      *
26  ************************************************************************/
27 #include <TClass.h>
28 #include <TList.h>
29 #include <TObjArray.h>
30 #include <TString.h>
31
32 #include "AliCFAcceptanceCuts.h"
33 #include "AliCFCutBase.h"
34 #include "AliCFManager.h"
35 #include "AliCFParticleGenCuts.h"
36 #include "AliCFTrackIsPrimaryCuts.h"
37 #include "AliCFTrackKineCuts.h"
38 #include "AliCFTrackQualityCuts.h"
39 #include "AliESDtrack.h"
40 #include "AliMCParticle.h"
41
42 #include "AliHFEcuts.h"
43
44 ClassImp(AliHFEcuts)
45
46 //__________________________________________________________________
47 AliHFEcuts::AliHFEcuts():
48   fRequirements(0),
49   fMinClustersTPC(0),
50   fMinTrackletsTRD(0),
51   fCutITSPixel(0),
52   fMaxChi2clusterTPC(0.),
53   fMinClusterRatioTPC(0.),
54   fSigmaToVtx(0.),
55   fHistQA(0x0),
56   fCutList(0x0),
57   fDebugLevel(0)
58 {
59   //
60   // Default Constructor
61   //
62   memset(fProdVtx, 0, sizeof(Double_t) * 4);
63   memset(fDCAtoVtx, 0, sizeof(Double_t) * 2);
64   memset(fPtRange, 0, sizeof(Double_t) * 2);
65   fCutList = new TObjArray();
66   fCutList->SetOwner();
67 }
68
69 //__________________________________________________________________
70 AliHFEcuts::AliHFEcuts(const AliHFEcuts &c):
71   TObject(c),
72   fRequirements(c.fRequirements),
73   fMinClustersTPC(c.fMinClustersTPC),
74   fMinTrackletsTRD(c.fMinTrackletsTRD),
75   fCutITSPixel(c.fCutITSPixel),
76   fMaxChi2clusterTPC(c.fMaxChi2clusterTPC),
77   fMinClusterRatioTPC(c.fMinClusterRatioTPC),
78   fSigmaToVtx(c.fSigmaToVtx),
79   fHistQA(0x0),
80   fCutList(0x0),
81   fDebugLevel(0)
82 {
83   //
84   // Copy Constructor
85   //
86   memcpy(fProdVtx, c.fProdVtx, sizeof(Double_t) * 4);
87   memcpy(fDCAtoVtx, c.fDCAtoVtx, sizeof(Double_t) * 4);
88   memcpy(fPtRange, c.fPtRange, sizeof(Double_t) *2);
89   fCutList = dynamic_cast<TObjArray *>(c.fCutList->Clone());
90   fCutList->SetOwner();
91 }
92
93 //__________________________________________________________________
94 AliHFEcuts::~AliHFEcuts(){
95   //
96   // Destruktor
97   //
98   if(fCutList){
99     fCutList->Delete();
100     delete fCutList;
101   }
102   fCutList = 0x0;
103   if(fHistQA) fHistQA->Clear();
104   delete fHistQA;
105 }
106
107 //__________________________________________________________________
108 void AliHFEcuts::Initialize(AliCFManager *cfm){
109
110   // Call all the setters for the cuts
111   SetParticleGenCutList();
112   SetAcceptanceCutList();
113   SetRecKineTPCCutList();
114   SetRecKineITSCutList();
115   SetRecPrimaryCutList();
116   SetHFElectronITSCuts();
117   SetHFElectronTPCCuts();
118   SetHFElectronTRDCuts();
119
120   
121   // Connect the cuts
122   cfm->SetParticleCutsList(kStepMCGenerated, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartGenCuts")));
123   cfm->SetParticleCutsList(kStepMCInAcceptance, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartAccCuts")));
124   cfm->SetParticleCutsList(kStepRecKineTPC, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartRecKineTPCCuts")));
125   cfm->SetParticleCutsList(kStepRecKineITS, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartRecKineITSCuts")));
126   cfm->SetParticleCutsList(kStepRecPrim, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartPrimCuts")));
127   cfm->SetParticleCutsList(kStepHFEcutsITS, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartHFECutsITS")));
128   cfm->SetParticleCutsList(kStepHFEcutsTPC, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartHFECutsTPC")));
129   cfm->SetParticleCutsList(kStepHFEcutsTRD, dynamic_cast<TObjArray *>(fCutList->FindObject("fPartHFECutsTRD")));
130
131 }
132
133 //__________________________________________________________________
134 void AliHFEcuts::Initialize(){
135   // Call all the setters for the cuts
136   SetParticleGenCutList();
137   SetAcceptanceCutList();
138   SetRecKineTPCCutList();
139   SetRecKineITSCutList();
140   SetRecPrimaryCutList();
141   SetHFElectronITSCuts();
142   SetHFElectronTPCCuts();
143   SetHFElectronTRDCuts();
144
145 }
146
147 //__________________________________________________________________
148 void AliHFEcuts::SetParticleGenCutList(){
149   //
150   // Initialize Particle Cuts for Monte Carlo Tracks
151   // Production Vertex: < 1cm (Beampipe)
152   // Particle Species: Electrons
153   // Eta: < 0.9 (TRD-TOF acceptance)
154   //
155   AliCFParticleGenCuts *genCuts = new AliCFParticleGenCuts("fCutsGenMC", "Particle Generation Cuts");
156   genCuts->SetRequireIsCharged();
157   if(IsRequirePrimary()) genCuts->SetRequireIsPrimary();
158   if(IsRequireProdVertex()){
159     genCuts->SetProdVtxRangeX(fProdVtx[0], fProdVtx[1]);
160     genCuts->SetProdVtxRangeY(fProdVtx[2], fProdVtx[3]);
161   }
162   genCuts->SetRequirePdgCode(11/*, kTRUE*/);
163   
164   AliCFTrackKineCuts *kineMCcuts = new AliCFTrackKineCuts("fCutsKineMC","MC Kine Cuts");
165   kineMCcuts->SetPtRange(fPtRange[0], fPtRange[1]);
166   kineMCcuts->SetEtaRange(-0.9, 0.9);
167
168   if(IsInDebugMode()){
169     genCuts->SetQAOn(fHistQA);
170     kineMCcuts->SetQAOn(fHistQA);
171   }
172
173   TObjArray *mcCuts = new TObjArray;
174   mcCuts->SetName("fPartGenCuts");
175   mcCuts->AddLast(genCuts);
176   mcCuts->AddLast(kineMCcuts);
177   fCutList->AddLast(mcCuts);
178 }
179
180 //__________________________________________________________________
181 void AliHFEcuts::SetAcceptanceCutList(){
182   //
183   // Initialize Particle (Monte Carlo) acceptance cuts
184   // Min. Required Hist for Detectors:
185   //          ITS [3]
186   //          TPC [2]
187   //          TRD [12]
188   //          TOF [0]
189   //
190   AliCFAcceptanceCuts *accCuts = new AliCFAcceptanceCuts("fCutsAccMC", "MC Acceptance Cuts");
191   accCuts->SetMinNHitITS(3);
192   accCuts->SetMinNHitTPC(2);
193   accCuts->SetMinNHitTRD(12);
194   if(IsInDebugMode()) accCuts->SetQAOn(fHistQA);
195   
196   TObjArray *partAccCuts = new TObjArray();
197   partAccCuts->SetName("fPartAccCuts");
198   partAccCuts->AddLast(accCuts);
199   fCutList->AddLast(partAccCuts);
200 }
201
202 //__________________________________________________________________
203 void AliHFEcuts::SetRecKineTPCCutList(){
204   //
205   // Track Kinematics and Quality cuts (Based on the Standard cuts from PWG0)
206   //
207   // Variances:
208   //  y: 2
209   //  z: 2
210   //  sin(phi): 0.5
211   //  tan(theta): 0.5
212   //  1/pt: 2
213   // Min. Number of Clusters:
214   //  TPC: 50
215   // RefitRequired:
216   //  TPC
217   // Chi2 per TPC cluster: 3.5
218   //
219   // Kinematics:
220   //  Momentum Range: 100MeV - 20GeV
221   //  Eta: < 0.9 (TRD-TOF acceptance)
222   //
223   AliCFTrackQualityCuts *trackQuality = new AliCFTrackQualityCuts("fCutsQualityRec","REC Track Quality Cuts");
224   trackQuality->SetMinNClusterTPC(fMinClustersTPC);
225   trackQuality->SetMaxChi2PerClusterTPC(fMaxChi2clusterTPC);
226   trackQuality->SetStatus(AliESDtrack::kTPCrefit);
227   trackQuality->SetMaxCovDiagonalElements(2., 2., 0.5, 0.5, 2); 
228
229   AliCFTrackKineCuts *kineCuts = new AliCFTrackKineCuts("fCutsKineRec", "REC Kine Cuts");
230   kineCuts->SetPtRange(fPtRange[0], fPtRange[1]);
231   kineCuts->SetEtaRange(-0.9, 0.9);
232   
233   if(IsInDebugMode()){
234     trackQuality->SetQAOn(fHistQA);
235     kineCuts->SetQAOn(fHistQA);
236   }
237   
238   TObjArray *recCuts = new TObjArray;
239   recCuts->SetName("fPartRecKineTPCCuts");
240   recCuts->AddLast(trackQuality);
241   recCuts->AddLast(kineCuts);
242   fCutList->AddLast(recCuts);
243 }
244
245 //__________________________________________________________________
246 void AliHFEcuts::SetRecKineITSCutList(){
247   //
248   // Track Kinematics and Quality cuts (Based on the Standard cuts from PWG0)
249   //
250   // RefitRequired:
251   //  ITS
252   //
253   AliCFTrackQualityCuts *trackQuality = new AliCFTrackQualityCuts("fCutsQualityRec","REC Track Quality Cuts");
254   trackQuality->SetStatus(AliESDtrack::kITSrefit);
255   
256   if(IsInDebugMode()){
257     trackQuality->SetQAOn(fHistQA);
258   }
259   
260   TObjArray *recCuts = new TObjArray;
261   recCuts->SetName("fPartRecKineITSCuts");
262   recCuts->AddLast(trackQuality);
263   fCutList->AddLast(recCuts);
264 }
265
266 //__________________________________________________________________
267 void AliHFEcuts::SetRecPrimaryCutList(){
268   //
269   // Primary cuts (based on standard cuts from PWG0):
270   //  DCA to Vertex: 
271   //    XY: 3. cm
272   //    Z:  10. cm
273   //  No Kink daughters
274   //
275   AliCFTrackIsPrimaryCuts *primaryCut = new AliCFTrackIsPrimaryCuts("fCutsPrimaryCuts", "REC Primary Cuts");
276   if(IsRequireDCAToVertex()){
277     primaryCut->SetDCAToVertex2D(kTRUE);
278     primaryCut->SetMaxDCAToVertexXY(fDCAtoVtx[0]);
279     primaryCut->SetMaxDCAToVertexZ(fDCAtoVtx[1]);
280   }
281   if(IsRequireSigmaToVertex()){
282     primaryCut->SetRequireSigmaToVertex(kTRUE);
283     primaryCut->SetMaxNSigmaToVertex(fSigmaToVtx);
284   }
285   primaryCut->SetAcceptKinkDaughters(kFALSE);
286   if(IsInDebugMode()) primaryCut->SetQAOn(fHistQA);
287   
288   TObjArray *primCuts = new TObjArray;
289   primCuts->SetName("fPartPrimCuts");
290   primCuts->AddLast(primaryCut);
291   fCutList->AddLast(primCuts);
292 }
293
294 //__________________________________________________________________
295 void AliHFEcuts::SetHFElectronITSCuts(){
296   //
297   // Special Cuts introduced by the HFElectron Group: ITS
298   //
299   AliHFEextraCuts *hfecuts = new AliHFEextraCuts("fCutsHFElectronGroupPixels","Extra cuts from the HFE group");
300   if(IsRequireITSpixel()){
301     hfecuts->SetRequireITSpixel(AliHFEextraCuts::ITSPixel_t(fCutITSPixel));
302   }
303   if(IsRequireDCAToVertex()){
304     hfecuts->SetMaxImpactParamR(fDCAtoVtx[0]);
305     hfecuts->SetMaxImpactParamZ(fDCAtoVtx[1]);
306   }
307   
308   if(IsInDebugMode()) hfecuts->SetQAOn(fHistQA);
309   
310   TObjArray *hfeCuts = new TObjArray;
311   hfeCuts->SetName("fPartHFECutsITS");
312   hfeCuts->AddLast(hfecuts);
313   fCutList->AddLast(hfeCuts);
314 }
315
316 //__________________________________________________________________
317 void AliHFEcuts::SetHFElectronTPCCuts(){
318   //
319   // Special Cuts introduced by the HFElectron Group: TPC
320   //
321   AliHFEextraCuts *hfecuts = new AliHFEextraCuts("fCutsHFElectronGroupTPC","Extra cuts from the HFE group");
322   if(fMinClusterRatioTPC > 0.) hfecuts->SetClusterRatioTPC(fMinClusterRatioTPC);
323   if(IsInDebugMode()) hfecuts->SetQAOn(fHistQA);
324   
325   TObjArray *hfeCuts = new TObjArray;
326   hfeCuts->SetName("fPartHFECutsTPC");
327   hfeCuts->AddLast(hfecuts);
328   fCutList->AddLast(hfeCuts);
329 }
330
331 //__________________________________________________________________
332 void AliHFEcuts::SetHFElectronTRDCuts(){
333   //
334   // Special Cuts introduced by the HFElectron Group: TRD
335   //
336   AliHFEextraCuts *hfecuts = new AliHFEextraCuts("fCutsHFElectronGroupTRD","Extra cuts from the HFE group");
337   if(fMinTrackletsTRD > 0.) hfecuts->SetMinTrackletsTRD(fMinTrackletsTRD);
338   if(IsInDebugMode()) hfecuts->SetQAOn(fHistQA);
339   
340   TObjArray *hfeCuts = new TObjArray;
341   hfeCuts->SetName("fPartHFECutsTRD");
342   hfeCuts->AddLast(hfecuts);
343   fCutList->AddLast(hfeCuts);
344 }
345
346 //__________________________________________________________________
347 void AliHFEcuts::SetDebugMode(){ 
348   //
349   // Switch on QA
350   //
351   SetBit(kDebugMode, kTRUE); 
352   fHistQA = new TList;
353   fHistQA->SetName("CutQAhistograms");
354   fHistQA->SetOwner(kFALSE);
355 }
356
357 //__________________________________________________________________
358 Bool_t AliHFEcuts::CheckParticleCuts(CutStep_t step, TObject *o){
359   //
360   // Checks the cuts without using the correction framework manager
361   // 
362   TString stepnames[kNcutSteps] = {"fPartGenCuts", "fPartAccCuts", "fPartRecCuts", "fPartPrimCuts", "fPartHFECuts"};
363   TObjArray *cuts = dynamic_cast<TObjArray *>(fCutList->FindObject(stepnames[step].Data()));
364   if(!cuts) return kTRUE;
365   TIterator *it = cuts->MakeIterator();
366   AliCFCutBase *mycut;
367   Bool_t status = kTRUE;
368   while((mycut = dynamic_cast<AliCFCutBase *>(it->Next()))){
369     status &= mycut->IsSelected(o);
370   }
371   delete it;
372   return status;
373 }