CbmRoot
PairAnalysisVarCuts.cxx
Go to the documentation of this file.
1 //
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 <TAxis.h>
27 #include <TFormula.h>
28 
29 #include "PairAnalysisHelper.h"
30 #include "PairAnalysisVarCuts.h"
31 
33 
34 
36  : AnalysisCuts()
37  , fUsedVars(new TBits(PairAnalysisVarManager::kNMaxValuesMC))
38  , fNActiveCuts(0)
39  , fActiveCutsMask(0)
40  , fSelectedCutsMask(0)
41  , fCutType(kAll) {
42  //
43  // Default costructor
44  //
45  for (Int_t i = 0; i < PairAnalysisVarManager::kNMaxValuesMC; ++i) {
46  fActiveCuts[i] = 0;
47  fCutMin[i] = 0;
48  fCutMax[i] = 0;
49  fCutExclude[i] = kFALSE;
50  fBitCut[i] = kFALSE;
51  fCutVar[i] = 0x0;
52  }
54 }
55 
56 //________________________________________________________________________
57 PairAnalysisVarCuts::PairAnalysisVarCuts(const char* name, const char* title)
58  : AnalysisCuts(name, title)
59  , fUsedVars(new TBits(PairAnalysisVarManager::kNMaxValuesMC))
60  , fNActiveCuts(0)
61  , fActiveCutsMask(0)
62  , fSelectedCutsMask(0)
63  , fCutType(kAll) {
64  //
65  // Named contructor
66  //
67  for (Int_t i = 0; i < PairAnalysisVarManager::kNMaxValuesMC; ++i) {
68  fActiveCuts[i] = 0;
69  fCutMin[i] = 0;
70  fCutMax[i] = 0;
71  fCutExclude[i] = kFALSE;
72  fBitCut[i] = kFALSE;
73  fCutVar[i] = 0x0;
74  }
76 }
77 
78 //________________________________________________________________________
80  //
81  // Destructor
82  //
83  if (fUsedVars) delete fUsedVars;
84  for (Int_t i = 0; i < PairAnalysisVarManager::kNMaxValuesMC; ++i) {
85  if (fCutVar[i]) delete fCutVar[i];
86  }
87 }
88 
89 //________________________________________________________________________
90 Bool_t PairAnalysisVarCuts::IsSelected(Double_t* const values) {
91  //
92  // Make cut decision
93  //
94 
95  //reset
97  SetSelected(kFALSE);
98 
99  for (Int_t iCut = 0; iCut < fNActiveCuts; ++iCut) {
100  Int_t cut = fActiveCuts[iCut];
101  SETBIT(fSelectedCutsMask, iCut);
102 
103  // apply 'bit cut'
104  if (fBitCut[iCut]) {
105  if ((TESTBIT((UInt_t) values[cut], (UInt_t) fCutMin[iCut]))
106  ^ (!fCutExclude[iCut]))
107  CLRBIT(fSelectedCutsMask, iCut);
108  } else {
109  // standard var cuts
110  if (!fCutVar[iCut]
111  && ((values[cut] < fCutMin[iCut]) || (values[cut] > fCutMax[iCut]))
112  ^ fCutExclude[iCut]) {
113  CLRBIT(fSelectedCutsMask, iCut);
114  } else if (fCutVar[iCut] && fCutVar[iCut]->IsA() == TFormula::Class()) {
116  TFormula* form = static_cast<TFormula*>(fCutVar[iCut]);
117  Double_t val = PairAnalysisHelper::EvalFormula(form, values);
118  if (((val < fCutMin[iCut]) || (val > fCutMax[iCut]))
119  ^ fCutExclude[iCut]) {
120  CLRBIT(fSelectedCutsMask, iCut);
121  }
122  }
123  }
124  // cut type and decision
125  if (fCutType == kAll && !TESTBIT(fSelectedCutsMask, iCut))
126  return kFALSE; // option to (minor) speed improvement
127  }
128 
129  Bool_t isSelected = (fSelectedCutsMask == fActiveCutsMask);
130  if (fCutType == kAny) isSelected = (fSelectedCutsMask > 0);
131  SetSelected(isSelected);
132  return isSelected;
133 }
134 
135 //________________________________________________________________________
136 Bool_t PairAnalysisVarCuts::IsSelected(TObject* track) {
137  //
138  // Make cut decision
139  //
140 
141  //reset
142  fSelectedCutsMask = 0;
143  SetSelected(kFALSE);
144 
145  if (!track) return kFALSE;
146 
147  //Fill values
148  Double_t* values = PairAnalysisVarManager::GetData();
150  PairAnalysisVarManager::Fill(track, values);
151 
153  return (IsSelected(values));
154 }
155 
156 //________________________________________________________________________
158  Double_t min,
159  Double_t max,
160  Bool_t excludeRange) {
161  //
162  // Set cut range and activate it
163  //
164  if (min > max) {
165  Double_t tmp = min;
166  min = max;
167  max = tmp;
168  }
171  fCutExclude[fNActiveCuts] = excludeRange;
172  SETBIT(fActiveCutsMask, fNActiveCuts);
173  fActiveCuts[fNActiveCuts] = (UShort_t) type;
174  fUsedVars->SetBitNumber(type, kTRUE);
175  ++fNActiveCuts;
176 }
177 
178 //________________________________________________________________________
179 void PairAnalysisVarCuts::AddCut(const char* formula,
180  Double_t min,
181  Double_t max,
182  Bool_t excludeRange) {
183  //
184  // Set cut range and activate it
185  //
186  if (min > max) {
187  Double_t tmp = min;
188  min = max;
189  max = tmp;
190  }
193  fCutExclude[fNActiveCuts] = excludeRange;
194  SETBIT(fActiveCutsMask, fNActiveCuts);
196 
197  // construct a TFormula
198  TFormula* form = new TFormula("varFormula", formula);
199  // compile function
200  if (form->Compile()) return;
201  //set parameter identifier and activate variables in the fill map
202  for (Int_t i = 0; i < form->GetNpar(); i++) {
203  form->SetParName(
204  i, PairAnalysisVarManager::GetValueName(form->GetParameter(i)));
205  fUsedVars->SetBitNumber((Int_t) form->GetParameter(i), kTRUE);
206  }
207 
208  fCutVar[fNActiveCuts] = form;
209  ++fNActiveCuts;
210 }
211 
212 //________________________________________________________________________
214  UInt_t bit,
215  Bool_t excludeRange) {
216  //
217  // Set cut range and activate it
218  //
219  fCutMin[fNActiveCuts] = bit;
220  fCutExclude[fNActiveCuts] = excludeRange;
221  fBitCut[fNActiveCuts] = kTRUE;
222  SETBIT(fActiveCutsMask, fNActiveCuts);
223  fActiveCuts[fNActiveCuts] = (UShort_t) type;
224  fUsedVars->SetBitNumber(type, kTRUE);
225  ++fNActiveCuts;
226 }
227 
228 //________________________________________________________________________
229 void PairAnalysisVarCuts::Print(const Option_t* /*option*/) const {
230  //
231  // Print cuts and the range
232  //
233  printf("------------------------------------------\n");
234  printf("cut ranges for '%s'\n", GetTitle());
235  if (fCutType == kAll) {
236  printf("All Cuts have to be fulfilled\n");
237  } else {
238  printf("Any Cut has to be fulfilled\n");
239  }
240  for (Int_t iCut = 0; iCut < fNActiveCuts; ++iCut) {
241  Int_t cut = (Int_t) fActiveCuts[iCut];
242  Bool_t inverse = fCutExclude[iCut];
243  Bool_t bitcut = fBitCut[iCut];
244  Bool_t fcut = (fCutVar[iCut] && fCutVar[iCut]->IsA() == TFormula::Class());
245 
246  if (!bitcut && !fcut) {
247  // standard cut
248  if (!inverse) {
249  printf("Cut %02d: %f < %s < %f\n",
250  iCut,
251  fCutMin[iCut],
253  fCutMax[iCut]);
254  } else {
255  printf("Cut %02d: !(%f < %s < %f)\n",
256  iCut,
257  fCutMin[iCut],
259  fCutMax[iCut]);
260  }
261  } else if (bitcut) {
262  // bit cut
263  if (!inverse) {
264  printf("Cut %02d: %s & (1ULL<<%d) \n",
265  iCut,
267  (UInt_t) fCutMin[iCut]);
268  } else {
269  printf("Cut %02d: !(%s & (1ULL<<%d)) \n",
270  iCut,
272  (UInt_t) fCutMin[iCut]);
273  }
274  } else if (fcut) {
275  // variable defined by a formula
276  TFormula* form = static_cast<TFormula*>(fCutVar[iCut]);
277  TString tit(form->GetExpFormula());
278  // replace parameter variables with names labels
279  for (Int_t j = 0; j < form->GetNpar(); j++)
280  tit.ReplaceAll(Form("[%d]", j), form->GetParName(j));
281  if (!inverse)
282  printf("Cut %02d: %f < %s < %f\n",
283  iCut,
284  fCutMin[iCut],
285  tit.Data(),
286  fCutMax[iCut]);
287  else
288  printf("Cut %02d: !(%f < %s < %f)\n",
289  iCut,
290  fCutMin[iCut],
291  tit.Data(),
292  fCutMax[iCut]);
293  } else
294  printf("cut class not found\n");
295  } //loop over cuts
296  printf("------------------------------------------\n");
297 }
PairAnalysisVarManager::kNMaxValuesMC
@ kNMaxValuesMC
Definition: PairAnalysisVarManager.h:343
PairAnalysisVarManager::SetFillMap
static void SetFillMap(TBits *map)
Definition: PairAnalysisVarManager.h:368
PairAnalysisVarCuts::AddCut
void AddCut(PairAnalysisVarManager::ValueTypes type, Double_t min, Double_t max, Bool_t excludeRange=kFALSE)
Definition: PairAnalysisVarCuts.cxx:157
PairAnalysisHelper::EvalFormula
Double_t EvalFormula(TFormula *form, const Double_t *values)
Definition: PairAnalysisHelper.cxx:278
PairAnalysisVarCuts::fBitCut
Bool_t fBitCut[PairAnalysisVarManager::kNMaxValuesMC]
Definition: PairAnalysisVarCuts.h:91
PairAnalysisVarCuts::kAll
@ kAll
Definition: PairAnalysisVarCuts.h:26
PairAnalysisHelper.h
PairAnalysisVarCuts::fCutExclude
Bool_t fCutExclude[PairAnalysisVarManager::kNMaxValuesMC]
Definition: PairAnalysisVarCuts.h:90
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
PairAnalysisVarCuts::fCutVar
TObject * fCutVar[PairAnalysisVarManager::kNMaxValuesMC]
Definition: PairAnalysisVarCuts.h:93
PairAnalysisVarManager
Definition: PairAnalysisVarManager.h:68
PairAnalysisVarManager::Fill
static void Fill(const TObject *particle, Double_t *const values)
Definition: PairAnalysisVarManager.h:474
PairAnalysisVarCuts::fActiveCuts
UShort_t fActiveCuts[PairAnalysisVarManager::kNMaxValuesMC]
Definition: PairAnalysisVarCuts.h:77
PairAnalysisVarManager::GetValueName
static const char * GetValueName(Int_t i)
Definition: PairAnalysisVarManager.h:377
PairAnalysisVarCuts::fActiveCutsMask
UInt_t fActiveCutsMask
Definition: PairAnalysisVarCuts.h:79
PairAnalysisVarCuts::fCutMax
Double_t fCutMax[PairAnalysisVarManager::kNMaxValuesMC]
Definition: PairAnalysisVarCuts.h:88
PairAnalysisVarCuts::Print
virtual void Print(const Option_t *option="") const
Definition: PairAnalysisVarCuts.cxx:229
PairAnalysisVarCuts.h
PairAnalysisVarCuts::~PairAnalysisVarCuts
virtual ~PairAnalysisVarCuts()
Definition: PairAnalysisVarCuts.cxx:79
min
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:33
PairAnalysisVarManager::InitFormulas
static void InitFormulas()
Definition: PairAnalysisVarManager.h:1692
ClassImp
ClassImp(PairAnalysisVarCuts) PairAnalysisVarCuts
Definition: PairAnalysisVarCuts.cxx:32
PairAnalysisVarCuts::fCutType
CutType fCutType
Definition: PairAnalysisVarCuts.h:83
PairAnalysisVarCuts::fUsedVars
TBits * fUsedVars
Definition: PairAnalysisVarCuts.h:75
PairAnalysisVarCuts
Definition: PairAnalysisVarCuts.h:23
AnalysisCuts::SetSelected
virtual void SetSelected(Bool_t dec)
Definition: AnalysisCuts.h:25
PairAnalysisVarCuts::AddBitCut
void AddBitCut(PairAnalysisVarManager::ValueTypes type, UInt_t bit, Bool_t excludeRange=kFALSE)
Definition: PairAnalysisVarCuts.cxx:213
PairAnalysisVarCuts::IsSelected
virtual Bool_t IsSelected(Double_t *const values)
Definition: PairAnalysisVarCuts.cxx:90
PairAnalysisVarCuts::fCutMin
Double_t fCutMin[PairAnalysisVarManager::kNMaxValuesMC]
Definition: PairAnalysisVarCuts.h:86
PairAnalysisVarCuts::fNActiveCuts
UShort_t fNActiveCuts
Definition: PairAnalysisVarCuts.h:78
PairAnalysisVarCuts::PairAnalysisVarCuts
PairAnalysisVarCuts()
PairAnalysisVarManager::GetData
static Double_t * GetData()
Definition: PairAnalysisVarManager.h:386
PairAnalysisVarCuts::fSelectedCutsMask
UInt_t fSelectedCutsMask
Definition: PairAnalysisVarCuts.h:82
PairAnalysisVarManager::ValueTypes
ValueTypes
Definition: PairAnalysisVarManager.h:71
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
PairAnalysisVarCuts::kAny
@ kAny
Definition: PairAnalysisVarCuts.h:26
AnalysisCuts
Definition: AnalysisCuts.h:12