]>
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; |
0b35b573 | 57 | fBitCut[i]=kFALSE; |
775970eb | 58 | fUpperCut[i]=0x0; |
b2a297fa | 59 | } |
60 | } | |
61 | ||
62 | //________________________________________________________________________ | |
63 | AliDielectronVarCuts::AliDielectronVarCuts(const char* name, const char* title) : | |
64 | AliAnalysisCuts(name,title), | |
a94c2e7e | 65 | fUsedVars(new TBits(AliDielectronVarManager::kNMaxValues)), |
b2a297fa | 66 | fNActiveCuts(0), |
67 | fActiveCutsMask(0), | |
e123f993 | 68 | fSelectedCutsMask(0), |
69 | fCutOnMCtruth(kFALSE), | |
70 | fCutType(kAll) | |
b2a297fa | 71 | { |
72 | // | |
73 | // Named contructor | |
74 | // | |
75 | for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){ | |
76 | fActiveCuts[i]=0; | |
77 | fCutMin[i]=0; | |
78 | fCutMax[i]=0; | |
b9d223bb | 79 | fCutExclude[i]=kFALSE; |
0b35b573 | 80 | fBitCut[i]=kFALSE; |
775970eb | 81 | fUpperCut[i]=0x0; |
b2a297fa | 82 | } |
83 | } | |
84 | ||
85 | //________________________________________________________________________ | |
86 | AliDielectronVarCuts::~AliDielectronVarCuts() | |
87 | { | |
88 | // | |
89 | // Destructor | |
90 | // | |
a94c2e7e | 91 | if (fUsedVars) delete fUsedVars; |
b2a297fa | 92 | } |
93 | ||
94 | //________________________________________________________________________ | |
95 | Bool_t AliDielectronVarCuts::IsSelected(TObject* track) | |
96 | { | |
97 | // | |
98 | // Make cut decision | |
99 | // | |
100 | ||
e123f993 | 101 | //reset |
b2a297fa | 102 | fSelectedCutsMask=0; |
103 | SetSelected(kFALSE); | |
e123f993 | 104 | |
105 | if (!track) return kFALSE; | |
775970eb | 106 | |
e123f993 | 107 | //If MC cut, get MC truth |
108 | if (fCutOnMCtruth){ | |
109 | AliVParticle *part=static_cast<AliVParticle*>(track); | |
110 | track=AliDielectronMC::Instance()->GetMCTrackFromMCEvent(part->GetLabel()); | |
111 | if (!track) return kFALSE; | |
112 | } | |
113 | ||
114 | //Fill values | |
115 | Double_t values[AliDielectronVarManager::kNMaxValues]; | |
a94c2e7e | 116 | AliDielectronVarManager::SetFillMap(fUsedVars); |
e123f993 | 117 | AliDielectronVarManager::Fill(track,values); |
775970eb | 118 | |
b2a297fa | 119 | for (Int_t iCut=0; iCut<fNActiveCuts; ++iCut){ |
120 | Int_t cut=fActiveCuts[iCut]; | |
78091935 | 121 | SETBIT(fSelectedCutsMask,iCut); |
0b35b573 | 122 | |
123 | // apply 'bit cut' | |
124 | if(fBitCut[iCut]) { | |
125 | if ( (TESTBIT((UInt_t)values[cut],(UInt_t)fCutMin[iCut]))^(!fCutExclude[iCut]) ) CLRBIT(fSelectedCutsMask,iCut); | |
126 | } | |
127 | else { | |
128 | // standard var cuts | |
129 | if ( !fUpperCut[iCut] && ((values[cut]<fCutMin[iCut]) || (values[cut]>fCutMax[iCut]))^fCutExclude[iCut] ) { | |
130 | CLRBIT(fSelectedCutsMask,iCut); | |
131 | } | |
132 | else if ( fUpperCut[iCut]) { | |
133 | /// use a THnBase inherited cut object // | |
134 | Double_t *vals = new Double_t[fUpperCut[iCut]->GetNdimensions()];//={-1}; | |
135 | // get array of values for the corresponding dimensions using axis names | |
136 | for(Int_t idim=0; idim<fUpperCut[iCut]->GetNdimensions(); idim++) { | |
137 | vals[idim] = values[AliDielectronVarManager::GetValueType(fUpperCut[iCut]->GetAxis(idim)->GetName())]; | |
138 | // printf(" \t %s %.3f ",fUpperCut[iCut]->GetAxis(idim)->GetName(),vals[idim]); | |
139 | } | |
140 | // find bin for values (w/o creating it in case it is not filled) | |
141 | Long_t bin = fUpperCut[iCut]->GetBin(vals,kFALSE); | |
142 | Double_t cutMax = (bin>0 ? fUpperCut[iCut]->GetBinContent(bin) : -999. ); | |
143 | if ( ((values[cut]<fCutMin[iCut]) || (values[cut]>cutMax))^fCutExclude[iCut] ) CLRBIT(fSelectedCutsMask,iCut); | |
144 | delete [] vals; | |
775970eb | 145 | } |
775970eb | 146 | } |
0b35b573 | 147 | // cut type and decision |
de620662 | 148 | if ( fCutType==kAll && !TESTBIT(fSelectedCutsMask,iCut) ) return kFALSE; // option to (minor) speed improvement |
b2a297fa | 149 | } |
775970eb | 150 | |
b2a297fa | 151 | Bool_t isSelected=(fSelectedCutsMask==fActiveCutsMask); |
e123f993 | 152 | if ( fCutType==kAny ) isSelected=(fSelectedCutsMask>0); |
b2a297fa | 153 | SetSelected(isSelected); |
154 | return isSelected; | |
155 | } | |
78091935 | 156 | |
157 | //________________________________________________________________________ | |
572b0139 | 158 | void AliDielectronVarCuts::AddCut(AliDielectronVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t excludeRange) |
78091935 | 159 | { |
160 | // | |
161 | // Set cut range and activate it | |
162 | // | |
163 | if (min>max){ | |
164 | Double_t tmp=min; | |
165 | min=max; | |
166 | max=tmp; | |
167 | } | |
e123f993 | 168 | fCutMin[fNActiveCuts]=min; |
169 | fCutMax[fNActiveCuts]=max; | |
572b0139 | 170 | fCutExclude[fNActiveCuts]=excludeRange; |
78091935 | 171 | SETBIT(fActiveCutsMask,fNActiveCuts); |
e123f993 | 172 | fActiveCuts[fNActiveCuts]=(UShort_t)type; |
a94c2e7e | 173 | fUsedVars->SetBitNumber(type,kTRUE); |
e123f993 | 174 | ++fNActiveCuts; |
78091935 | 175 | } |
b2a297fa | 176 | |
0b35b573 | 177 | //________________________________________________________________________ |
178 | void AliDielectronVarCuts::AddBitCut(AliDielectronVarManager::ValueTypes type, UInt_t bit, Bool_t excludeRange) | |
179 | { | |
180 | // | |
181 | // Set cut range and activate it | |
182 | // | |
183 | fCutMin[fNActiveCuts]=bit; | |
184 | fCutExclude[fNActiveCuts]=excludeRange; | |
185 | fBitCut[fNActiveCuts]=kTRUE; | |
186 | SETBIT(fActiveCutsMask,fNActiveCuts); | |
187 | fActiveCuts[fNActiveCuts]=(UShort_t)type; | |
188 | fUsedVars->SetBitNumber(type,kTRUE); | |
189 | ++fNActiveCuts; | |
190 | } | |
191 | ||
775970eb | 192 | //________________________________________________________________________ |
af0f2f47 | 193 | void AliDielectronVarCuts::AddCut(AliDielectronVarManager::ValueTypes type, Double_t min, THnBase * const max, Bool_t excludeRange) |
775970eb | 194 | { |
195 | // | |
196 | // Set cut range and activate it | |
197 | // | |
198 | fCutMin[fNActiveCuts]=min; | |
199 | fCutMax[fNActiveCuts]=0.0; | |
200 | fCutExclude[fNActiveCuts]=excludeRange; | |
201 | SETBIT(fActiveCutsMask,fNActiveCuts); | |
202 | fActiveCuts[fNActiveCuts]=(UShort_t)type; | |
203 | fUsedVars->SetBitNumber(type,kTRUE); | |
af0f2f47 | 204 | |
205 | fUpperCut[fNActiveCuts]=max; | |
206 | // fill used variables into map | |
207 | for(Int_t idim=0; idim<fUpperCut[fNActiveCuts]->GetNdimensions(); idim++) { | |
208 | TString var(fUpperCut[fNActiveCuts]->GetAxis(idim)->GetName()); | |
209 | fUsedVars->SetBitNumber(AliDielectronVarManager::GetValueType(var.Data()), kTRUE); | |
775970eb | 210 | } |
775970eb | 211 | ++fNActiveCuts; |
212 | } | |
213 | ||
78091935 | 214 | //________________________________________________________________________ |
215 | void AliDielectronVarCuts::Print(const Option_t* /*option*/) const | |
216 | { | |
217 | // | |
218 | // Print cuts and the range | |
219 | // | |
220 | printf("cut ranges for '%s'\n",GetTitle()); | |
e123f993 | 221 | if (fCutType==kAll){ |
222 | printf("All Cuts have to be fulfilled\n"); | |
223 | } else { | |
224 | printf("Any Cut has to be fulfilled\n"); | |
225 | } | |
78091935 | 226 | for (Int_t iCut=0; iCut<fNActiveCuts; ++iCut){ |
e123f993 | 227 | Int_t cut=(Int_t)fActiveCuts[iCut]; |
572b0139 | 228 | Bool_t inverse=fCutExclude[iCut]; |
0b35b573 | 229 | Bool_t bitcut=fBitCut[iCut]; |
230 | Bool_t objcut=fUpperCut[iCut]; | |
572b0139 | 231 | |
0b35b573 | 232 | if(!bitcut && !objcut) { |
233 | // standard cut | |
234 | if (!inverse){ | |
235 | printf("Cut %02d: %f < %s < %f\n", iCut, | |
236 | fCutMin[iCut], AliDielectronVarManager::GetValueName((Int_t)cut), fCutMax[iCut]); | |
237 | } else { | |
238 | printf("Cut %02d: !(%f < %s < %f)\n", iCut, | |
239 | fCutMin[iCut], AliDielectronVarManager::GetValueName((Int_t)cut), fCutMax[iCut]); | |
240 | } | |
572b0139 | 241 | } |
0b35b573 | 242 | else if(bitcut) { |
243 | // bit cut | |
244 | if (!inverse){ | |
245 | printf("Cut %02d: %s & (1ULL<<%d) \n", iCut, | |
246 | AliDielectronVarManager::GetValueName((Int_t)cut), (UInt_t)fCutMin[iCut]); | |
247 | } else { | |
248 | printf("Cut %02d: !(%s & (1ULL<<%d)) \n", iCut, | |
249 | AliDielectronVarManager::GetValueName((Int_t)cut), (UInt_t)fCutMin[iCut]); | |
250 | } | |
251 | } | |
252 | else if(objcut) { | |
253 | // upper cut limit provided by object depending on 'dep' | |
254 | TString dep=""; | |
255 | for(Int_t idim=0; idim<fUpperCut[iCut]->GetNdimensions(); idim++) | |
256 | dep+=Form("%s%s",(idim?",":""),fUpperCut[iCut]->GetAxis(idim)->GetName()); | |
257 | ||
258 | if (!inverse){ | |
259 | printf("Cut %02d: %f < %s < obj(%s)\n", iCut, | |
260 | fCutMin[iCut], AliDielectronVarManager::GetValueName((Int_t)cut), dep.Data()); | |
261 | } else { | |
262 | printf("Cut %02d: !(%f < %s < obj(%s))\n", iCut, | |
263 | fCutMin[iCut], AliDielectronVarManager::GetValueName((Int_t)cut), dep.Data()); | |
264 | } | |
265 | } | |
266 | } //loop over cuts | |
78091935 | 267 | } |