]>
Commit | Line | Data |
---|---|---|
b2a297fa | 1 | /************************************************************************* |
2 | * Copyright(c) 1998-2009, 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 class providing cuts to all infomation // | |
18 | // available for the AliVParticle interface // // | |
19 | // // | |
20 | // Authors: // | |
21 | // Jens Wiechula <Jens.Wiechula@cern.ch> // | |
af0f2f47 | 22 | // Julian Book <Julian.Book@cern.ch> // |
b2a297fa | 23 | /* |
24 | ||
25 | ||
26 | ||
27 | */ | |
28 | // // | |
29 | /////////////////////////////////////////////////////////////////////////// | |
30 | ||
31 | ||
af0f2f47 | 32 | #include <THnBase.h> |
775970eb | 33 | |
b2a297fa | 34 | #include "AliDielectronVarCuts.h" |
e123f993 | 35 | #include "AliDielectronMC.h" |
b2a297fa | 36 | |
37 | ClassImp(AliDielectronVarCuts) | |
38 | ||
39 | ||
40 | AliDielectronVarCuts::AliDielectronVarCuts() : | |
41 | AliAnalysisCuts(), | |
a94c2e7e | 42 | fUsedVars(new TBits(AliDielectronVarManager::kNMaxValues)), |
b2a297fa | 43 | fNActiveCuts(0), |
44 | fActiveCutsMask(0), | |
e123f993 | 45 | fSelectedCutsMask(0), |
46 | fCutOnMCtruth(kFALSE), | |
47 | fCutType(kAll) | |
b2a297fa | 48 | { |
49 | // | |
50 | // Default costructor | |
51 | // | |
52 | for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){ | |
53 | fActiveCuts[i]=0; | |
54 | fCutMin[i]=0; | |
55 | fCutMax[i]=0; | |
572b0139 | 56 | fCutExclude[i]=kFALSE; |
775970eb | 57 | fUpperCut[i]=0x0; |
b2a297fa | 58 | } |
59 | } | |
60 | ||
61 | //________________________________________________________________________ | |
62 | AliDielectronVarCuts::AliDielectronVarCuts(const char* name, const char* title) : | |
63 | AliAnalysisCuts(name,title), | |
a94c2e7e | 64 | fUsedVars(new TBits(AliDielectronVarManager::kNMaxValues)), |
b2a297fa | 65 | fNActiveCuts(0), |
66 | fActiveCutsMask(0), | |
e123f993 | 67 | fSelectedCutsMask(0), |
68 | fCutOnMCtruth(kFALSE), | |
69 | fCutType(kAll) | |
b2a297fa | 70 | { |
71 | // | |
72 | // Named contructor | |
73 | // | |
74 | for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){ | |
75 | fActiveCuts[i]=0; | |
76 | fCutMin[i]=0; | |
77 | fCutMax[i]=0; | |
b9d223bb | 78 | fCutExclude[i]=kFALSE; |
775970eb | 79 | fUpperCut[i]=0x0; |
b2a297fa | 80 | } |
81 | } | |
82 | ||
83 | //________________________________________________________________________ | |
84 | AliDielectronVarCuts::~AliDielectronVarCuts() | |
85 | { | |
86 | // | |
87 | // Destructor | |
88 | // | |
a94c2e7e | 89 | if (fUsedVars) delete fUsedVars; |
b2a297fa | 90 | } |
91 | ||
92 | //________________________________________________________________________ | |
93 | Bool_t AliDielectronVarCuts::IsSelected(TObject* track) | |
94 | { | |
95 | // | |
96 | // Make cut decision | |
97 | // | |
98 | ||
e123f993 | 99 | //reset |
b2a297fa | 100 | fSelectedCutsMask=0; |
101 | SetSelected(kFALSE); | |
e123f993 | 102 | |
103 | if (!track) return kFALSE; | |
775970eb | 104 | |
e123f993 | 105 | //If MC cut, get MC truth |
106 | if (fCutOnMCtruth){ | |
107 | AliVParticle *part=static_cast<AliVParticle*>(track); | |
108 | track=AliDielectronMC::Instance()->GetMCTrackFromMCEvent(part->GetLabel()); | |
109 | if (!track) return kFALSE; | |
110 | } | |
111 | ||
112 | //Fill values | |
113 | Double_t values[AliDielectronVarManager::kNMaxValues]; | |
a94c2e7e | 114 | AliDielectronVarManager::SetFillMap(fUsedVars); |
e123f993 | 115 | AliDielectronVarManager::Fill(track,values); |
775970eb | 116 | |
b2a297fa | 117 | for (Int_t iCut=0; iCut<fNActiveCuts; ++iCut){ |
118 | Int_t cut=fActiveCuts[iCut]; | |
78091935 | 119 | SETBIT(fSelectedCutsMask,iCut); |
775970eb | 120 | if ( !fUpperCut[iCut] && ((values[cut]<fCutMin[iCut]) || (values[cut]>fCutMax[iCut]))^fCutExclude[iCut] ) CLRBIT(fSelectedCutsMask,iCut); |
121 | else if ( fUpperCut[iCut]) { | |
af0f2f47 | 122 | // use a THnBase inherited cut object |
123 | Double_t *vals = new Double_t[fUpperCut[iCut]->GetNdimensions()];//={-1}; | |
124 | // get array of values for the corresponding dimensions using axis names | |
125 | for(Int_t idim=0; idim<fUpperCut[iCut]->GetNdimensions(); idim++) { | |
126 | vals[idim] = values[AliDielectronVarManager::GetValueType(fUpperCut[iCut]->GetAxis(idim)->GetName())]; | |
127 | // printf(" \t %s %.3f ",fUpperCut[iCut]->GetAxis(idim)->GetName(),vals[idim]); | |
775970eb | 128 | } |
af0f2f47 | 129 | // find bin for values (w/o creating it in case it is not filled) |
130 | Long_t bin = fUpperCut[iCut]->GetBin(vals,kFALSE); | |
131 | Double_t cutMax = (bin>0 ? fUpperCut[iCut]->GetBinContent(bin) : -999. ); | |
132 | if ( ((values[cut]<fCutMin[iCut]) || (values[cut]>cutMax))^fCutExclude[iCut] ) CLRBIT(fSelectedCutsMask,iCut); | |
133 | delete [] vals; | |
775970eb | 134 | } |
de620662 | 135 | if ( fCutType==kAll && !TESTBIT(fSelectedCutsMask,iCut) ) return kFALSE; // option to (minor) speed improvement |
b2a297fa | 136 | } |
775970eb | 137 | |
b2a297fa | 138 | Bool_t isSelected=(fSelectedCutsMask==fActiveCutsMask); |
e123f993 | 139 | if ( fCutType==kAny ) isSelected=(fSelectedCutsMask>0); |
b2a297fa | 140 | SetSelected(isSelected); |
141 | return isSelected; | |
142 | } | |
78091935 | 143 | |
144 | //________________________________________________________________________ | |
572b0139 | 145 | void AliDielectronVarCuts::AddCut(AliDielectronVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t excludeRange) |
78091935 | 146 | { |
147 | // | |
148 | // Set cut range and activate it | |
149 | // | |
150 | if (min>max){ | |
151 | Double_t tmp=min; | |
152 | min=max; | |
153 | max=tmp; | |
154 | } | |
e123f993 | 155 | fCutMin[fNActiveCuts]=min; |
156 | fCutMax[fNActiveCuts]=max; | |
572b0139 | 157 | fCutExclude[fNActiveCuts]=excludeRange; |
78091935 | 158 | SETBIT(fActiveCutsMask,fNActiveCuts); |
e123f993 | 159 | fActiveCuts[fNActiveCuts]=(UShort_t)type; |
a94c2e7e | 160 | fUsedVars->SetBitNumber(type,kTRUE); |
e123f993 | 161 | ++fNActiveCuts; |
78091935 | 162 | } |
b2a297fa | 163 | |
775970eb | 164 | //________________________________________________________________________ |
af0f2f47 | 165 | void AliDielectronVarCuts::AddCut(AliDielectronVarManager::ValueTypes type, Double_t min, THnBase * const max, Bool_t excludeRange) |
775970eb | 166 | { |
167 | // | |
168 | // Set cut range and activate it | |
169 | // | |
170 | fCutMin[fNActiveCuts]=min; | |
171 | fCutMax[fNActiveCuts]=0.0; | |
172 | fCutExclude[fNActiveCuts]=excludeRange; | |
173 | SETBIT(fActiveCutsMask,fNActiveCuts); | |
174 | fActiveCuts[fNActiveCuts]=(UShort_t)type; | |
175 | fUsedVars->SetBitNumber(type,kTRUE); | |
af0f2f47 | 176 | |
177 | fUpperCut[fNActiveCuts]=max; | |
178 | // fill used variables into map | |
179 | for(Int_t idim=0; idim<fUpperCut[fNActiveCuts]->GetNdimensions(); idim++) { | |
180 | TString var(fUpperCut[fNActiveCuts]->GetAxis(idim)->GetName()); | |
181 | fUsedVars->SetBitNumber(AliDielectronVarManager::GetValueType(var.Data()), kTRUE); | |
775970eb | 182 | } |
775970eb | 183 | ++fNActiveCuts; |
184 | } | |
185 | ||
78091935 | 186 | //________________________________________________________________________ |
187 | void AliDielectronVarCuts::Print(const Option_t* /*option*/) const | |
188 | { | |
189 | // | |
190 | // Print cuts and the range | |
191 | // | |
192 | printf("cut ranges for '%s'\n",GetTitle()); | |
e123f993 | 193 | if (fCutType==kAll){ |
194 | printf("All Cuts have to be fulfilled\n"); | |
195 | } else { | |
196 | printf("Any Cut has to be fulfilled\n"); | |
197 | } | |
78091935 | 198 | for (Int_t iCut=0; iCut<fNActiveCuts; ++iCut){ |
e123f993 | 199 | Int_t cut=(Int_t)fActiveCuts[iCut]; |
572b0139 | 200 | Bool_t inverse=fCutExclude[iCut]; |
201 | ||
202 | if (!inverse){ | |
203 | printf("Cut %02d: %f < %s < %f\n", iCut, | |
204 | fCutMin[iCut], AliDielectronVarManager::GetValueName((Int_t)cut), fCutMax[iCut]); | |
205 | } else { | |
206 | printf("Cut %02d: !(%f < %s < %f)\n", iCut, | |
207 | fCutMin[iCut], AliDielectronVarManager::GetValueName((Int_t)cut), fCutMax[iCut]); | |
208 | } | |
78091935 | 209 | } |
210 | } |