CbmRoot
Loading...
Searching...
No Matches
PairAnalysisVarCuts.cxx
Go to the documentation of this file.
1
2//
3//
4// Authors:
5// * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
6// Julian Book <Julian.Book@cern.ch>
7/*
8
9 This class provides cuts for all variables and formulas managed by PairAnalysisVarManager.
10 Many cuts can be added to the same object and are processed consecutively according to
11 the cut logic/type SetCutType(CutType type). Further the arguments of AddCut allow to
12 include or exclude a certain selection in the analysis.
13
14 It is recommmended to give the cut object a unique and meaning full name(+title), since
15 they are used e.g. in PairAnalysisCutQa and PairAnalysis::GetCutStepHistogramList()
16 to monitor the cut impact.
17
18 Many objects can be combined in a PairAnalysisCutGroup with additional cut logics.
19
20
21*/
22// //
24
25
26#include "PairAnalysisVarCuts.h"
27
28#include <TAxis.h>
29#include <TFormula.h>
30
31#include "PairAnalysisHelper.h"
32
34
35
37 : AnalysisCuts()
38 , fUsedVars(new TBits(PairAnalysisVarManager::kNMaxValuesMC))
39 , fNActiveCuts(0)
40 , fActiveCutsMask(0)
41 , fSelectedCutsMask(0)
42 , fCutType(ECutType::kAll)
43{
44 //
45 // Default costructor
46 //
47 for (Int_t i = 0; i < PairAnalysisVarManager::kNMaxValuesMC; ++i) {
48 fActiveCuts[i] = 0;
49 fCutMin[i] = 0;
50 fCutMax[i] = 0;
51 fCutExclude[i] = kFALSE;
52 fBitCut[i] = kFALSE;
53 fCutVar[i] = 0x0;
54 }
56}
57
58//________________________________________________________________________
59PairAnalysisVarCuts::PairAnalysisVarCuts(const char* name, const char* title)
60 : AnalysisCuts(name, title)
61 , fUsedVars(new TBits(PairAnalysisVarManager::kNMaxValuesMC))
62 , fNActiveCuts(0)
63 , fActiveCutsMask(0)
64 , fSelectedCutsMask(0)
65 , fCutType(ECutType::kAll)
66{
67 //
68 // Named contructor
69 //
70 for (Int_t i = 0; i < PairAnalysisVarManager::kNMaxValuesMC; ++i) {
71 fActiveCuts[i] = 0;
72 fCutMin[i] = 0;
73 fCutMax[i] = 0;
74 fCutExclude[i] = kFALSE;
75 fBitCut[i] = kFALSE;
76 fCutVar[i] = 0x0;
77 }
79}
80
81//________________________________________________________________________
83{
84 //
85 // Destructor
86 //
87 if (fUsedVars) delete fUsedVars;
88 for (Int_t i = 0; i < PairAnalysisVarManager::kNMaxValuesMC; ++i) {
89 if (fCutVar[i]) delete fCutVar[i];
90 }
91}
92
93//________________________________________________________________________
94Bool_t PairAnalysisVarCuts::IsSelected(Double_t* const values)
95{
96 //
97 // Make cut decision
98 //
99
100 //reset
102 SetSelected(kFALSE);
103
104 for (Int_t iCut = 0; iCut < fNActiveCuts; ++iCut) {
105 Int_t cut = fActiveCuts[iCut];
107
108 // apply 'bit cut'
109 if (fBitCut[iCut]) {
110 if ((TESTBIT((UInt_t) values[cut], (UInt_t) fCutMin[iCut])) ^ (!fCutExclude[iCut]))
112 }
113 else {
114 // standard var cuts
115 if (!fCutVar[iCut] && ((values[cut] < fCutMin[iCut]) || (values[cut] > fCutMax[iCut])) ^ fCutExclude[iCut]) {
117 }
118 else if (fCutVar[iCut] && fCutVar[iCut]->IsA() == TFormula::Class()) {
120 TFormula* form = static_cast<TFormula*>(fCutVar[iCut]);
121 Double_t val = PairAnalysisHelper::EvalFormula(form, values);
122 if (((val < fCutMin[iCut]) || (val > fCutMax[iCut])) ^ fCutExclude[iCut]) { CLRBIT(fSelectedCutsMask, iCut); }
123 }
124 }
125 // cut type and decision
127 return kFALSE; // option to (minor) speed improvement
128 }
129
130 Bool_t isSelected = (fSelectedCutsMask == fActiveCutsMask);
131 if (fCutType == ECutType::kAny) isSelected = (fSelectedCutsMask > 0);
132 SetSelected(isSelected);
133 return isSelected;
134}
135
136//________________________________________________________________________
138{
139 //
140 // Make cut decision
141 //
142
143 //reset
145 SetSelected(kFALSE);
146
147 if (!track) return kFALSE;
148
149 //Fill values
150 Double_t* values = PairAnalysisVarManager::GetData();
152 PairAnalysisVarManager::Fill(track, values);
153
155 return (IsSelected(values));
156}
157
158//________________________________________________________________________
160 Bool_t excludeRange)
161{
162 //
163 // Set cut range and activate it
164 //
165 if (min > max) {
166 Double_t tmp = min;
167 min = max;
168 max = tmp;
169 }
172 fCutExclude[fNActiveCuts] = excludeRange;
174 fActiveCuts[fNActiveCuts] = (UShort_t) type;
175 fUsedVars->SetBitNumber(type, kTRUE);
176 ++fNActiveCuts;
177}
178
179//________________________________________________________________________
180void PairAnalysisVarCuts::AddCut(const char* formula, Double_t min, Double_t max, Bool_t excludeRange)
181{
182 //
183 // Set cut range and activate it
184 //
185 if (min > max) {
186 Double_t tmp = min;
187 min = max;
188 max = tmp;
189 }
192 fCutExclude[fNActiveCuts] = excludeRange;
195
196 // construct a TFormula
197 TFormula* form = new TFormula("varFormula", formula);
198 // compile function
199 if (form->Compile()) return;
200 //set parameter identifier and activate variables in the fill map
201 for (Int_t i = 0; i < form->GetNpar(); i++) {
202 form->SetParName(i, PairAnalysisVarManager::GetValueName(form->GetParameter(i)));
203 fUsedVars->SetBitNumber((Int_t) form->GetParameter(i), kTRUE);
204 }
205
206 fCutVar[fNActiveCuts] = form;
207 ++fNActiveCuts;
208}
209
210//________________________________________________________________________
212{
213 //
214 // Set cut range and activate it
215 //
216 fCutMin[fNActiveCuts] = bit;
217 fCutExclude[fNActiveCuts] = excludeRange;
218 fBitCut[fNActiveCuts] = kTRUE;
220 fActiveCuts[fNActiveCuts] = (UShort_t) type;
221 fUsedVars->SetBitNumber(type, kTRUE);
222 ++fNActiveCuts;
223}
224
225//________________________________________________________________________
226void PairAnalysisVarCuts::Print(const Option_t* /*option*/) const
227{
228 //
229 // Print cuts and the range
230 //
231 printf("------------------------------------------\n");
232 printf("cut ranges for '%s'\n", GetTitle());
233 if (fCutType == ECutType::kAll) { printf("All Cuts have to be fulfilled\n"); }
234 else {
235 printf("Any Cut has to be fulfilled\n");
236 }
237 for (Int_t iCut = 0; iCut < fNActiveCuts; ++iCut) {
238 Int_t cut = (Int_t) fActiveCuts[iCut];
239 Bool_t inverse = fCutExclude[iCut];
240 Bool_t bitcut = fBitCut[iCut];
241 Bool_t fcut = (fCutVar[iCut] && fCutVar[iCut]->IsA() == TFormula::Class());
242
243 if (!bitcut && !fcut) {
244 // standard cut
245 if (!inverse) {
246 printf("Cut %02d: %f < %s < %f\n", iCut, fCutMin[iCut], PairAnalysisVarManager::GetValueName((Int_t) cut),
247 fCutMax[iCut]);
248 }
249 else {
250 printf("Cut %02d: !(%f < %s < %f)\n", iCut, fCutMin[iCut], PairAnalysisVarManager::GetValueName((Int_t) cut),
251 fCutMax[iCut]);
252 }
253 }
254 else if (bitcut) {
255 // bit cut
256 if (!inverse) {
257 printf("Cut %02d: %s & (1ULL<<%d) \n", iCut, PairAnalysisVarManager::GetValueName((Int_t) cut),
258 (UInt_t) fCutMin[iCut]);
259 }
260 else {
261 printf("Cut %02d: !(%s & (1ULL<<%d)) \n", iCut, PairAnalysisVarManager::GetValueName((Int_t) cut),
262 (UInt_t) fCutMin[iCut]);
263 }
264 }
265 else if (fcut) {
266 // variable defined by a formula
267 TFormula* form = static_cast<TFormula*>(fCutVar[iCut]);
268 TString tit(form->GetExpFormula());
269 // replace parameter variables with names labels
270 for (Int_t j = 0; j < form->GetNpar(); j++)
271 tit.ReplaceAll(Form("[%d]", j), form->GetParName(j));
272 if (!inverse) printf("Cut %02d: %f < %s < %f\n", iCut, fCutMin[iCut], tit.Data(), fCutMax[iCut]);
273 else
274 printf("Cut %02d: !(%f < %s < %f)\n", iCut, fCutMin[iCut], tit.Data(), fCutMax[iCut]);
275 }
276 else
277 printf("cut class not found\n");
278 } //loop over cuts
279 printf("------------------------------------------\n");
280}
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
ClassImp(PairAnalysisVarCuts) PairAnalysisVarCuts
#define SETBIT(n, i)
Definition RTypes.h:15
#define TESTBIT(n, i)
Definition RTypes.h:17
#define CLRBIT(n, i)
Definition RTypes.h:16
virtual void SetSelected(Bool_t dec)
void AddBitCut(PairAnalysisVarManager::ValueTypes type, UInt_t bit, Bool_t excludeRange=kFALSE)
UShort_t fActiveCuts[PairAnalysisVarManager::kNMaxValuesMC]
virtual Bool_t IsSelected(Double_t *const values)
Double_t fCutMin[PairAnalysisVarManager::kNMaxValuesMC]
Bool_t fBitCut[PairAnalysisVarManager::kNMaxValuesMC]
Double_t fCutMax[PairAnalysisVarManager::kNMaxValuesMC]
void AddCut(PairAnalysisVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t excludeRange=kFALSE)
virtual void Print(const Option_t *option="") const
Bool_t fCutExclude[PairAnalysisVarManager::kNMaxValuesMC]
TObject * fCutVar[PairAnalysisVarManager::kNMaxValuesMC]
static void SetFillMap(TBits *map)
static const char * GetValueName(Int_t i)
static void Fill(const TObject *particle, Double_t *const values)
Double_t EvalFormula(TFormula *form, const Double_t *values)