CbmRoot
PairAnalysisCutCombi.cxx
Go to the documentation of this file.
1 // //
3 // Authors:
4 // Julian Book <Julian.Book@cern.ch>
5 /*
6 
7  Advanced cut class.
8 
9  Add cuts that are applied only for certain types of e.g. tracks or under
10  some defined condition: AddCut(AnalysisCuts *cuts, AnalysisCuts *range)
11 
12  Example - apply TRD PID only for track with 3-4 reconstructed hits
13 
14  // TRD reconstruction cuts
15  PairAnalysisVarCuts *recTRD = new PairAnalysisVarCuts("recTRD","recTRD");
16  recTRD->AddCut(PairAnalysisVarManager::kTRDHits, 3., 4.);
17 
18  // TRD Pid - 1-dimensional
19  PairAnalysisVarCuts *pidTRD = new PairAnalysisVarCuts("pidTRD","pidTRD");
20  pidTRD->AddCut(PairAnalysisVarManager::kTRDPidANN, 0.5, 1.5);
21 
22  // build PID cut depending on track quality
23  PairAnalysisCutCombi *pidTRDavai = new PairAnalysisCutCombi("TRDPidAvai","TRDPidAvai");
24  pidTRDavai->AddCut(pidTRD, recTRD);
25 
26 
27 */
28 // //
30 
31 #include "PairAnalysisVarManager.h"
32 
33 #include "PairAnalysisCutCombi.h"
34 
36 
38  : AnalysisCuts()
39  , fNActiveCuts(0)
40  , fActiveCutsMask(0)
41  , fSelectedCutsMask(0)
42  , fCutType(kAll) {
43  //
44  // Default Constructor
45  //
46  for (Int_t i = 0; i < kNmaxCuts; ++i) {
47  fRangeCuts[i] = 0x0;
48  fCuts[i] = 0x0;
49  }
50 }
51 
52 //______________________________________________
53 PairAnalysisCutCombi::PairAnalysisCutCombi(const char* name, const char* title)
54  : AnalysisCuts(name, title)
55  , fNActiveCuts(0)
56  , fActiveCutsMask(0)
57  , fSelectedCutsMask(0)
58  , fCutType(kAll) {
59  //
60  // Named Constructor
61  //
62  for (Int_t i = 0; i < kNmaxCuts; ++i) {
63  fRangeCuts[i] = 0x0;
64  fCuts[i] = 0x0;
65  }
66 }
67 
68 //______________________________________________
70  //
71  // Default Destructor
72  //
73  for (Int_t i = 0; i < kNmaxCuts; ++i) {
74  if (fRangeCuts[i]) delete fRangeCuts[i];
75  if (fCuts[i]) delete fCuts[i];
76  }
77 }
78 
79 //______________________________________________
81  //
82  // add CutCombi cuts
83  //
84  if (fNActiveCuts == kNmaxCuts) {
85  Warning("AddCut", "Too many cuts added!");
86  return;
87  }
88 
90  fRangeCuts[fNActiveCuts] = range;
91  fCuts[fNActiveCuts] = cuts;
92  ++fNActiveCuts;
93 }
94 
95 
96 //______________________________________________
97 Bool_t PairAnalysisCutCombi::IsSelected(TObject* track) {
98  //
99  // make cut decision
100  //
101 
102  if (!track) return kFALSE;
103 
104  //Fill values
105  Double_t* values = PairAnalysisVarManager::GetData();
106  PairAnalysisVarManager::Fill(track, values);
107 
109  return (IsSelected(values));
110 }
111 
112 //________________________________________________________________________
113 Bool_t PairAnalysisCutCombi::IsSelected(Double_t* const values) {
114  //
115  // Make cut decision
116  //
117 
118  //reset
119  fSelectedCutsMask = 0;
120  SetSelected(kFALSE);
121 
122  // loop overe all cuts
123  for (Int_t iCut = 0; iCut < fNActiveCuts; ++iCut) {
124  SETBIT(fSelectedCutsMask, iCut);
125 
126  if (!fRangeCuts[iCut] || !fCuts[iCut]) continue;
127 
128  // check the range(s) where cuts should be applied
129  if (!fRangeCuts[iCut]->IsSelected(values)) continue;
130 
131  // check decision
132  if (!fCuts[iCut]->IsSelected(values)) CLRBIT(fSelectedCutsMask, iCut);
133 
134  // cut type and intermediate decision
135  if (fCutType == kAll && !TESTBIT(fSelectedCutsMask, iCut)) return kFALSE;
136  }
137 
138  // cut type and final decision
139  Bool_t isSelected = (fSelectedCutsMask == fActiveCutsMask);
140  if (fCutType == kAny) isSelected = (fSelectedCutsMask > 0);
141  SetSelected(isSelected);
142  return isSelected;
143 }
144 
145 //________________________________________________________________________
146 void PairAnalysisCutCombi::Print(const Option_t* /*option*/) const {
147  //
148  // Print cuts and the range
149  //
150  printf("-----------------------------------------------------------------\n");
151  printf("cut ranges for '%s'\n", GetTitle());
152  if (fCutType == kAll) {
153  printf("All Cuts have to be fulfilled\n");
154  } else {
155  printf("Any Cut has to be fulfilled\n");
156  }
157 
158  for (Int_t iCut = 0; iCut < fNActiveCuts; ++iCut) {
159  fCuts[iCut]->Print();
160  printf("For the following conditions:\n");
161  fRangeCuts[iCut]->Print();
162  }
163  printf("-----------------------------------------------------------------\n");
164 }
PairAnalysisCutCombi::kNmaxCuts
@ kNmaxCuts
Definition: PairAnalysisCutCombi.h:53
PairAnalysisMixingHandler::kAll
@ kAll
Definition: PairAnalysisMixingHandler.h:29
PairAnalysisCutCombi::~PairAnalysisCutCombi
virtual ~PairAnalysisCutCombi()
Definition: PairAnalysisCutCombi.cxx:69
PairAnalysisCutCombi::kAll
@ kAll
Definition: PairAnalysisCutCombi.h:23
PairAnalysisCutCombi::IsSelected
virtual Bool_t IsSelected(Double_t *const values)
Definition: PairAnalysisCutCombi.cxx:113
PairAnalysisCutCombi::fActiveCutsMask
UInt_t fActiveCutsMask
Definition: PairAnalysisCutCombi.h:56
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
PairAnalysisCutCombi::PairAnalysisCutCombi
PairAnalysisCutCombi()
PairAnalysisVarManager::Fill
static void Fill(const TObject *particle, Double_t *const values)
Definition: PairAnalysisVarManager.h:474
PairAnalysisCutCombi::fNActiveCuts
UShort_t fNActiveCuts
Definition: PairAnalysisCutCombi.h:55
ClassImp
ClassImp(PairAnalysisCutCombi) PairAnalysisCutCombi
Definition: PairAnalysisCutCombi.cxx:35
PairAnalysisVarManager.h
AnalysisCuts::SetSelected
virtual void SetSelected(Bool_t dec)
Definition: AnalysisCuts.h:25
PairAnalysisCutCombi::fCutType
CutType fCutType
Definition: PairAnalysisCutCombi.h:60
PairAnalysisCutCombi::fCuts
AnalysisCuts * fCuts[kNmaxCuts]
Definition: PairAnalysisCutCombi.h:63
PairAnalysisCutCombi
Definition: PairAnalysisCutCombi.h:20
PairAnalysisCutCombi::AddCut
void AddCut(AnalysisCuts *cuts, AnalysisCuts *range)
Definition: PairAnalysisCutCombi.cxx:80
PairAnalysisCutCombi::fRangeCuts
AnalysisCuts * fRangeCuts[kNmaxCuts]
Definition: PairAnalysisCutCombi.h:62
PairAnalysisVarManager::GetData
static Double_t * GetData()
Definition: PairAnalysisVarManager.h:386
PairAnalysisCutCombi.h
PairAnalysisCutCombi::Print
virtual void Print(const Option_t *option="") const
Definition: PairAnalysisCutCombi.cxx:146
PairAnalysisCutCombi::kAny
@ kAny
Definition: PairAnalysisCutCombi.h:23
PairAnalysisCutCombi::fSelectedCutsMask
UInt_t fSelectedCutsMask
Definition: PairAnalysisCutCombi.h:59
AnalysisCuts
Definition: AnalysisCuts.h:12