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