]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/vertexingHF/AliRDHFCuts.cxx
Now PtBin() returns -1 if pt>maximum of all bins
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliRDHFCuts.cxx
CommitLineData
650b3ced 1/**************************************************************************
2 * Copyright(c) 1998-2010, 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//
18// Base class for cuts on AOD reconstructed heavy-flavour decay
19//
20// Author: A.Dainese, andrea.dainese@pd.infn.it
21/////////////////////////////////////////////////////////////
22#include <Riostream.h>
23
24#include "AliVEvent.h"
25#include "AliESDEvent.h"
26#include "AliAODEvent.h"
27#include "AliVVertex.h"
28#include "AliESDVertex.h"
29#include "AliAODVertex.h"
3cbc09cd 30#include "AliESDtrack.h"
31#include "AliAODTrack.h"
650b3ced 32#include "AliESDtrackCuts.h"
33#include "AliAODRecoDecayHF.h"
34#include "AliRDHFCuts.h"
35
36ClassImp(AliRDHFCuts)
37
38//--------------------------------------------------------------------------
39AliRDHFCuts::AliRDHFCuts(const Char_t* name, const Char_t* title) :
40AliAnalysisCuts(name,title),
41fMinVtxType(3),
42fMinVtxContr(1),
43fMaxVtxRedChi2(1e6),
44fMinSPDMultiplicity(0),
45fTriggerMask(0),
46fTrackCuts(0),
47fnPtBins(1),
48fnPtBinLimits(1),
49fPtBinLimits(0),
50fnVars(1),
51fVarNames(0),
52fnVarsForOpt(0),
53fVarsForOpt(0),
54fGlobalIndex(1),
55fCutsRD(0),
56fIsUpperCut(0)
57{
58 //
59 // Default Constructor
60 //
61}
62//--------------------------------------------------------------------------
63AliRDHFCuts::AliRDHFCuts(const AliRDHFCuts &source) :
64 AliAnalysisCuts(source),
65 fMinVtxType(source.fMinVtxType),
66 fMinVtxContr(source.fMinVtxContr),
67 fMaxVtxRedChi2(source.fMaxVtxRedChi2),
68 fMinSPDMultiplicity(source.fMinSPDMultiplicity),
69 fTriggerMask(source.fTriggerMask),
70 fTrackCuts(0),
71 fnPtBins(source.fnPtBins),
72 fnPtBinLimits(source.fnPtBinLimits),
73 fPtBinLimits(0),
74 fnVars(source.fnVars),
75 fVarNames(0),
76 fnVarsForOpt(source.fnVarsForOpt),
77 fVarsForOpt(0),
78 fGlobalIndex(source.fGlobalIndex),
79 fCutsRD(0),
80 fIsUpperCut(0)
81{
82 //
83 // Copy constructor
84 //
85 cout<<"Copy constructor"<<endl;
86 if(source.GetTrackCuts()) AddTrackCuts(source.GetTrackCuts());
650b3ced 87 if(source.fPtBinLimits) SetPtBins(source.fnPtBinLimits,source.fPtBinLimits);
88 if(source.fVarNames) SetVarNames(source.fnVars,source.fVarNames,source.fIsUpperCut);
89 if(source.fCutsRD) SetCuts(source.fGlobalIndex,source.fCutsRD);
90 if(source.fVarsForOpt) SetVarsForOpt(source.fnVarsForOpt,source.fVarsForOpt);
91 PrintAll();
650b3ced 92
93}
94//--------------------------------------------------------------------------
95AliRDHFCuts &AliRDHFCuts::operator=(const AliRDHFCuts &source)
96{
97 //
98 // assignment operator
99 //
100 if(&source == this) return *this;
101
102 AliAnalysisCuts::operator=(source);
103
104 fMinVtxType=source.fMinVtxType;
105 fMinVtxContr=source.fMinVtxContr;
106 fMaxVtxRedChi2=source.fMaxVtxRedChi2;
107 fMinSPDMultiplicity=source.fMinSPDMultiplicity;
108 fTriggerMask=source.fTriggerMask;
109 fnPtBins=source.fnPtBins;
110 fnVars=source.fnVars;
111 fGlobalIndex=source.fGlobalIndex;
112 fnVarsForOpt=source.fnVarsForOpt;
113
bbbf8c32 114 if(source.GetTrackCuts()) AddTrackCuts(source.GetTrackCuts());
650b3ced 115 if(source.fPtBinLimits) SetPtBins(source.fnPtBinLimits,source.fPtBinLimits);
116 if(source.fVarNames) SetVarNames(source.fnVars,source.fVarNames,source.fIsUpperCut);
117 if(source.fCutsRD) SetCuts(source.fGlobalIndex,source.fCutsRD);
118 if(source.fVarsForOpt) SetVarsForOpt(source.fnVarsForOpt,source.fVarsForOpt);
119 PrintAll();
120
650b3ced 121 return *this;
122}
123//--------------------------------------------------------------------------
124AliRDHFCuts::~AliRDHFCuts() {
125 //
126 // Default Destructor
127 //
128 if(fPtBinLimits) {delete [] fPtBinLimits; fPtBinLimits=0;}
129 if(fVarNames) {delete [] fVarNames; fVarNames=0;}
130 if(fVarsForOpt) {delete [] fVarsForOpt; fVarsForOpt=0;}
131 if(fCutsRD) {
132 delete [] fCutsRD;
133 fCutsRD=0;
134 }
135 if(fIsUpperCut) {delete [] fIsUpperCut; fIsUpperCut=0;}
136
137}
138//---------------------------------------------------------------------------
139Bool_t AliRDHFCuts::IsEventSelected(AliVEvent *event) const {
140 //
141 // Event selection
142 //
3cbc09cd 143 //if(fTriggerMask && event->GetTriggerMask()!=fTriggerMask) return kFALSE;
650b3ced 144
145 // multiplicity cuts no implemented yet
146
147 const AliVVertex *vertex = event->GetPrimaryVertex();
148
149 if(!vertex) return kFALSE;
150
151 TString title=vertex->GetTitle();
152 if(title.Contains("Z") && fMinVtxType>1) return kFALSE;
153 if(title.Contains("3D") && fMinVtxType>2) return kFALSE;
154
155 if(vertex->GetNContributors()<fMinVtxContr) return kFALSE;
156
157 return kTRUE;
158}
159//---------------------------------------------------------------------------
3cbc09cd 160Bool_t AliRDHFCuts::AreDaughtersSelected(AliAODRecoDecayHF *d) const {
161 //
162 // Daughter tracks selection
163 //
85d335a7 164 if(!fTrackCuts) return kTRUE;
165
3cbc09cd 166 Int_t ndaughters = d->GetNDaughters();
167 AliESDtrack* esdTrack=0;
85d335a7 168 AliAODVertex *vAOD = d->GetPrimaryVtx();
169 Double_t pos[3],cov[6];
170 vAOD->GetXYZ(pos);
171 vAOD->GetCovarianceMatrix(cov);
172 const AliESDVertex *vESD = new AliESDVertex(pos,cov,100.,100);
173
174 Bool_t retval=kTRUE;
3cbc09cd 175
176 for(Int_t idg=0; idg<ndaughters; idg++) {
177 AliAODTrack *dgTrack = (AliAODTrack*)d->GetDaughter(idg);
85d335a7 178 if(!dgTrack) retval = kFALSE;
3cbc09cd 179 //printf("charge %d\n",dgTrack->Charge());
180 if(dgTrack->Charge()==0) continue; // it's not a track, but a V0
181 // convert to ESD track here
85d335a7 182 esdTrack=new AliESDtrack(dgTrack);
183 // needed to calculate the impact parameters
184 esdTrack->RelateToVertex(vESD,0.,3.);
185 if(!fTrackCuts->IsSelected(esdTrack)) retval = kFALSE;
3cbc09cd 186 delete esdTrack; esdTrack=0;
187 }
85d335a7 188
189 delete vESD; vESD=0;
190
191 return retval;
3cbc09cd 192}
193//---------------------------------------------------------------------------
650b3ced 194void AliRDHFCuts::SetPtBins(Int_t nPtBinLimits,Float_t *ptBinLimits) {
195 // Set the pt bins
196
197 if(fPtBinLimits) {
198 delete [] fPtBinLimits;
199 fPtBinLimits = NULL;
200 printf("Changing the pt bins\n");
201 }
202
203 if(nPtBinLimits != fnPtBins+1){
204 cout<<"Warning: ptBinLimits dimention "<<nPtBinLimits<<" != nPtBins+1 ("<<fnPtBins+1<<")\nSetting nPtBins to "<<nPtBinLimits-1<<endl;
205 SetNPtBins(nPtBinLimits-1);
206 }
207
208 fnPtBinLimits = nPtBinLimits;
209 SetGlobalIndex();
210 cout<<"Changing also Global Index -> "<<fGlobalIndex<<endl;
211 fPtBinLimits = new Float_t[fnPtBinLimits];
212 for(Int_t ib=0; ib<nPtBinLimits; ib++) fPtBinLimits[ib]=ptBinLimits[ib];
213
214 return;
215}
216//---------------------------------------------------------------------------
217void AliRDHFCuts::SetVarNames(Int_t nVars,TString *varNames,Bool_t *isUpperCut){
218 // Set the variable names
219
220 if(fVarNames) {
221 delete [] fVarNames;
222 fVarNames = NULL;
223 printf("Changing the variable names\n");
224 }
225 if(nVars!=fnVars){
226 printf("Wrong number of variables: it has to be %d\n",fnVars);
227 return;
228 }
229 //fnVars=nVars;
230 fVarNames = new TString[nVars];
231 fIsUpperCut = new Bool_t[nVars];
232 for(Int_t iv=0; iv<nVars; iv++) {
233 fVarNames[iv] = varNames[iv];
234 fIsUpperCut[iv] = isUpperCut[iv];
235 }
236
237 return;
238}
239//---------------------------------------------------------------------------
240void AliRDHFCuts::SetVarsForOpt(Int_t nVars,Bool_t *forOpt) {
241 // Set the variables to be used for cuts optimization
242
243 if(fVarsForOpt) {
244 delete [] fVarsForOpt;
245 fVarsForOpt = NULL;
246 printf("Changing the variables for cut optimization\n");
247 }
248
249 if(nVars==0){//!=fnVars) {
250 printf("%d not accepted as number of variables: it has to be %d\n",nVars,fnVars);
251 return;
252 }
253
254 fnVarsForOpt = 0;
255 fVarsForOpt = new Bool_t[fnVars];
256 for(Int_t iv=0; iv<fnVars; iv++) {
257 fVarsForOpt[iv]=forOpt[iv];
258 if(fVarsForOpt[iv]) fnVarsForOpt++;
259 }
260
261 return;
262}
263//---------------------------------------------------------------------------
264void AliRDHFCuts::SetCuts(Int_t nVars,Int_t nPtBins,Float_t **cutsRD) {
4edfaee0 265 //
266 // store the cuts
267 //
650b3ced 268 if(nVars!=fnVars) {
269 printf("Wrong number of variables: it has to be %d\n",fnVars);
270 return;
271 }
272 if(nPtBins!=fnPtBins) {
273 printf("Wrong number of pt bins: it has to be %d\n",fnPtBins);
274 return;
275 }
276
277 if(!fCutsRD) fCutsRD = new Float_t[fGlobalIndex];
278
4edfaee0 279
650b3ced 280 for(Int_t iv=0; iv<fnVars; iv++) {
281
282 for(Int_t ib=0; ib<fnPtBins; ib++) {
283
650b3ced 284 //check
4edfaee0 285 if(GetGlobalIndex(iv,ib)>=fGlobalIndex) {
650b3ced 286 cout<<"Overflow, exit..."<<endl;
287 return;
288 }
4edfaee0 289
290 fCutsRD[GetGlobalIndex(iv,ib)] = cutsRD[iv][ib];
291
650b3ced 292 }
293 }
650b3ced 294 return;
295}
296//---------------------------------------------------------------------------
297void AliRDHFCuts::SetCuts(Int_t glIndex,Float_t* cutsRDGlob){
4edfaee0 298 //
299 // store the cuts
300 //
650b3ced 301 if(glIndex != fGlobalIndex){
302 cout<<"Wrong array size: it has to be "<<fGlobalIndex<<endl;
303 return;
304 }
305 if(!fCutsRD) fCutsRD = new Float_t[fGlobalIndex];
306
307 for(Int_t iGl=0;iGl<fGlobalIndex;iGl++){
308 fCutsRD[iGl] = cutsRDGlob[iGl];
309 }
650b3ced 310 return;
650b3ced 311}
650b3ced 312//---------------------------------------------------------------------------
4edfaee0 313void AliRDHFCuts::PrintAll() const {
314 //
315 // print all cuts values
316 //
650b3ced 317 if(fVarNames){
318 cout<<"Array of variables"<<endl;
319 for(Int_t iv=0;iv<fnVars;iv++){
320 cout<<fVarNames[iv]<<"\t";
321 }
322 cout<<endl;
323 }
324 if(fVarsForOpt){
325 cout<<"Array of optimization"<<endl;
326 for(Int_t iv=0;iv<fnVars;iv++){
327 cout<<fVarsForOpt[iv]<<"\t";
328 }
329 cout<<endl;
330 }
331 if(fIsUpperCut){
332 cout<<"Array of upper/lower cut"<<endl;
333 for(Int_t iv=0;iv<fnVars;iv++){
334 cout<<fIsUpperCut[iv]<<"\t";
335 }
336 cout<<endl;
337 }
338 if(fPtBinLimits){
339 cout<<"Array of ptbin limits"<<endl;
340 for(Int_t ib=0;ib<fnPtBinLimits;ib++){
341 cout<<fPtBinLimits[ib]<<"\t";
342 }
343 cout<<endl;
344 }
345 if(fCutsRD){
346 cout<<"Matrix of cuts"<<endl;
347 for(Int_t iv=0;iv<fnVars;iv++){
348 for(Int_t ib=0;ib<fnPtBins;ib++){
349 cout<<"fCutsRD["<<iv<<"]["<<ib<<"] = "<<fCutsRD[GetGlobalIndex(iv,ib)]<<"\t";
350 }
351 cout<<endl;
352 }
353 cout<<endl;
354 }
4edfaee0 355 return;
650b3ced 356}
650b3ced 357//---------------------------------------------------------------------------
358void AliRDHFCuts::GetCuts(Float_t**& cutsRD) const{
4edfaee0 359 //
650b3ced 360 // get the cuts
4edfaee0 361 //
650b3ced 362
4edfaee0 363 //cout<<"Give back a "<<fnVars<<"x"<<fnPtBins<<" matrix."<<endl;
650b3ced 364
650b3ced 365
4edfaee0 366 Int_t iv,ib;
650b3ced 367 if(!cutsRD) {
4edfaee0 368 //cout<<"Initialization..."<<endl;
650b3ced 369 cutsRD=new Float_t*[fnVars];
4edfaee0 370 for(iv=0; iv<fnVars; iv++) {
650b3ced 371 cutsRD[iv] = new Float_t[fnPtBins];
372 }
373 }
374
4edfaee0 375 for(Int_t iGlobal=0; iGlobal<fGlobalIndex; iGlobal++) {
376 GetVarPtIndex(iGlobal,iv,ib);
377 cutsRD[iv][ib] = fCutsRD[iGlobal];
650b3ced 378 }
379
4edfaee0 380 return;
650b3ced 381}
382
383//---------------------------------------------------------------------------
384Int_t AliRDHFCuts::GetGlobalIndex(Int_t iVar,Int_t iPtBin) const{
4edfaee0 385 //
3cbc09cd 386 // give the global index from variable and pt bin
4edfaee0 387 //
650b3ced 388 return iPtBin*fnVars+iVar;
389}
390
391//---------------------------------------------------------------------------
392void AliRDHFCuts::GetVarPtIndex(Int_t iGlob, Int_t& iVar, Int_t& iPtBin) const {
4edfaee0 393 //
650b3ced 394 //give the index of the variable and of the pt bin from the global index
4edfaee0 395 //
650b3ced 396 iPtBin=(Int_t)iGlob/fnVars;
397 iVar=iGlob%fnVars;
398
4edfaee0 399 return;
650b3ced 400}
401
402//---------------------------------------------------------------------------
403Int_t AliRDHFCuts::PtBin(Double_t pt) const {
4edfaee0 404 //
650b3ced 405 //give the pt bin where the pt lies.
4edfaee0 406 //
eaa73e44 407 Int_t ptbin=-1;
650b3ced 408 for (Int_t i=0;i<fnPtBins;i++){
409 if(pt<fPtBinLimits[i+1]) {
410 ptbin=i;
411 break;
412 }
413 }
414 return ptbin;
415}
aaf4e30f 416//-------------------------------------------------------------------
417Float_t AliRDHFCuts::GetCutValue(Int_t iVar,Int_t iPtBin) const {
418 //
419 // Give the value of cut set for the variable iVar and the pt bin iPtBin
420 //
421 if(!fCutsRD){
422 cout<<"Cuts not iniziaisez yet"<<endl;
423 return 0;
424 }
425 return fCutsRD[GetGlobalIndex(iVar,iPtBin)];
426}
427