CbmRoot
AnalysisFilter.cxx
Go to the documentation of this file.
1 //
3 // Manager class for filter decisions based on cuts
4 // The filter contains a list of sets of cuts and controll histograms (optional).
5 // A bit field is filled in order to store the decision of each cut-set.
6 //
7 // Authors:
8 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
9 // Julian Book <Julian.Book@cern.ch>
10 //
11 // Add cut object to list via AddCuts(AnalysisCuts* cuts)
12 // Add control histograms via AddHistos(PairAnalysisHistos* histos)
13 //
15 
16 #include "AnalysisFilter.h"
17 #include "AnalysisCuts.h"
18 #include "PairAnalysisHistos.h"
19 #include <THashList.h>
20 #include <TList.h>
21 #include <TObject.h>
22 
23 #include "PairAnalysisVarManager.h"
24 
26 
27 
29  : TNamed(), fCuts(0), fHistos() {
30  // Default constructor
31  fHistos.SetOwner(kTRUE);
32  fHistos.SetName("PairAnalysis_FilterHistos");
33 }
34 
35 AnalysisFilter::AnalysisFilter(const char* name, const char* title)
36  : TNamed(name, title)
37  , fCuts(new TList())
38  , fHistos()
39 // fHistos(new TList())
40 {
41  // Constructor
42  fHistos.SetOwner(kTRUE);
43  fHistos.SetName(name);
44 }
45 
47  : TNamed(obj), fCuts(0), fHistos() {
48  // Copy constructor
49  fCuts = obj.fCuts;
50  // fHistos = obj.fHistos;
51 }
52 
54  // Destructor
55  if (fCuts) fCuts->Delete("slow");
56  //if (fHistos) fHistos->Delete("slow");
57  fHistos.Clear();
58  delete fCuts;
59 }
60 
62  // Assignment
63  if (&other != this) {
64  TNamed::operator=(other);
65  fCuts = other.fCuts;
66  // fHistos = other.fHistos;
67  }
68  return *this;
69 }
70 
71 UInt_t AnalysisFilter::IsSelected(TObject* obj) {
72  //
73  // Loop over all set of cuts
74  // and store the decision
75  UInt_t result = 0;
76  UInt_t filterMask;
77 
78  TIter next(fCuts);
79  AnalysisCuts* cuts;
80  Int_t iCutB = 1;
81 
82 
83  //Fill values - fill only once the variables
84  // TODO: check carefully the case of pairlegcuts,
85  // before switching to IsSelected(values)
86  // Double_t values[PairAnalysisVarManager::kNMaxValuesMC];
87  // PairAnalysisVarManager::Fill(obj,values);
88 
89  while ((cuts = (AnalysisCuts*) next())) {
90  //Bool_t acc = cuts->IsSelected(values);
91  Bool_t acc = cuts->IsSelected(obj);
92  if ((filterMask = cuts->GetFilterMask()) > 0) {
93  acc = (acc && (filterMask == result));
94  }
95  cuts->SetSelected(acc);
96  if (acc) { result |= iCutB & 0x00ffffff; }
97  iCutB *= 2;
98  }
99 
100  return result;
101 }
102 
103 UInt_t AnalysisFilter::IsSelected(Double_t* const values) {
104  //
105  // Loop over all set of cuts
106  // and store the decision
107  UInt_t result = 0;
108  UInt_t filterMask;
109 
110  TIter next(fCuts);
111  AnalysisCuts* cuts;
112  Int_t iCutB = 1;
113 
114  while ((cuts = (AnalysisCuts*) next())) {
115  Bool_t acc = cuts->IsSelected(values);
116  if ((filterMask = cuts->GetFilterMask()) > 0) {
117  acc = (acc && (filterMask == result));
118  }
119  cuts->SetSelected(acc);
120  if (acc) { result |= iCutB & 0x00ffffff; }
121  iCutB *= 2;
122  }
123 
124  return result;
125 }
126 
127 UInt_t AnalysisFilter::IsSelected(TList* list) {
128  //
129  // Loop over all set of cuts
130  // and store the decision
131  UInt_t result = 0;
132  UInt_t filterMask;
133 
134  TIter next(fCuts);
135  AnalysisCuts* cuts;
136  Int_t iCutB = 1;
137 
138  while ((cuts = (AnalysisCuts*) next())) {
139  Bool_t acc = cuts->IsSelected(list);
140  if ((filterMask = cuts->GetFilterMask()) > 0) {
141  acc = (acc && (filterMask & result));
142  }
143  cuts->SetSelected(acc);
144  if (acc) { result |= iCutB & 0x00ffffff; }
145  iCutB *= 2;
146  }
147 
148  return result;
149 }
150 
152  //
153  // Loop over all set of cuts and call Init
154  TIter next(fCuts);
155  AnalysisCuts* cuts;
156  while ((cuts = (AnalysisCuts*) next()))
157  cuts->Init();
158 }
159 
161  // Add a set of cuts
162  fCuts->Add(cuts);
163 }
164 
165 void AnalysisFilter::AddHistos(PairAnalysisHistos* histos) {
166  //
167  // add histos for each cut
168  //
169  fHistos.Clear();
170  TIter next(fCuts);
171  AnalysisCuts* cuts;
172  Int_t iCut = 0;
173  while ((cuts = (AnalysisCuts*) next())) {
174  fHistos.AddAt(
175  (PairAnalysisHistos*) histos->GetHistogramList()->Clone(cuts->GetName()),
176  iCut++);
177  // printf("AnalysisFilter::AddHistos add histos for %s at %d \n",cuts->GetName(),iCut);
178  }
179 }
180 
181 Bool_t AnalysisFilter::IsSelected(char* name) {
182  //
183  // Returns current result for cut with name
184  AnalysisCuts* cut = (AnalysisCuts*) (fCuts->FindObject(name));
185  if (cut) {
186  return (cut->Selected());
187  } else {
188  return 0;
189  }
190 }
AnalysisFilter::fHistos
THashList fHistos
Definition: AnalysisFilter.h:37
AnalysisFilter.h
AnalysisFilter::AnalysisFilter
AnalysisFilter()
PairAnalysisVarManager.h
AnalysisFilter::fCuts
TList * fCuts
Definition: AnalysisFilter.h:36
AnalysisFilter::~AnalysisFilter
virtual ~AnalysisFilter()
Definition: AnalysisFilter.cxx:53
AnalysisCuts::SetSelected
virtual void SetSelected(Bool_t dec)
Definition: AnalysisCuts.h:25
AnalysisCuts::Init
virtual void Init()
Definition: AnalysisCuts.h:22
ClassImp
ClassImp(AnalysisFilter) AnalysisFilter
Definition: AnalysisFilter.cxx:25
AnalysisFilter::Init
virtual void Init()
Definition: AnalysisFilter.cxx:151
AnalysisCuts::GetFilterMask
virtual UInt_t GetFilterMask() const
Definition: AnalysisCuts.h:24
AnalysisFilter::IsSelected
virtual UInt_t IsSelected(Double_t *const values)
Definition: AnalysisFilter.cxx:103
AnalysisCuts::IsSelected
virtual Bool_t IsSelected(Double_t *const)
Definition: AnalysisCuts.h:19
AnalysisFilter::AddHistos
void AddHistos(PairAnalysisHistos *histos)
Definition: AnalysisFilter.cxx:165
AnalysisCuts::Selected
virtual UInt_t Selected() const
Definition: AnalysisCuts.h:26
AnalysisFilter
Definition: AnalysisFilter.h:15
AnalysisFilter::operator=
AnalysisFilter & operator=(const AnalysisFilter &other)
Definition: AnalysisFilter.cxx:61
PairAnalysisHistos.h
AnalysisFilter::AddCuts
virtual void AddCuts(AnalysisCuts *cuts)
Definition: AnalysisFilter.cxx:160
AnalysisCuts
Definition: AnalysisCuts.h:12
AnalysisCuts.h