This commit was generated by cvs2svn to compensate for changes in r23278,
[u/mrichter/AliRoot.git] / CORRFW / AliCFManager.cxx
CommitLineData
563113d0 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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// The class AliCFManager is designed to handle inside the
17// task the basic components for a particle-level correction of single
18// particle analysis
19// The class provides methods to set lists of cuts and to loop over them
20// for several different selection steps to be then used for
21// efficiency calculation.
22// prototype version by S.Arcelli silvia.arcelli@cern.ch
23///////////////////////////////////////////////////////////////////////////
24#include "TBits.h"
25#include "TList.h"
26#include "TH1.h"
27#include "AliLog.h"
28#include "AliCFCutBase.h"
29#include "AliCFManager.h"
30
31ClassImp(AliCFManager)
32
33//_____________________________________________________________________________
34AliCFManager::AliCFManager() :
35 TNamed(),
36 fEvtContainer(0x0),
37 fPartContainer(0x0),
38 fhQABits(0x0)
39
40{
41 //
42 // ctor
43 //
44 for(Int_t i=0;i<kNEvtSel;i++)fEvtCutList[i]=0x0;
45 for(Int_t i=0;i<kNPartSel;i++)fPartCutList[i]=0x0;
46 fhQABits=new TBits(0);
47}
48//_____________________________________________________________________________
49AliCFManager::AliCFManager(Char_t* name, Char_t* title) :
50 TNamed(name,title),
51 fEvtContainer(0x0),
52 fPartContainer(0x0),
53 fhQABits(0x0)
54 {
55 //
56 // ctor
57 //
58 for(Int_t i=0;i<kNEvtSel;i++)fEvtCutList[i]=0x0;
59 for(Int_t i=0;i<kNPartSel;i++)fPartCutList[i]=0x0;
60 fhQABits=new TBits(0);
61}
62//_____________________________________________________________________________
63AliCFManager::AliCFManager(const AliCFManager& c) :
64 TNamed(c),
65 fEvtContainer(c.fEvtContainer),
66 fPartContainer(c.fPartContainer),
67 fhQABits(c.fhQABits)
68 {
69 //
70 //copy ctor
71 //
72 for(Int_t i=0;i<kNEvtSel;i++)fEvtCutList[i]=c.fEvtCutList[i];
73 for(Int_t i=0;i<kNPartSel;i++)fPartCutList[i]=c.fPartCutList[i];
74 }
75//_____________________________________________________________________________
76AliCFManager& AliCFManager::operator=(const AliCFManager& c)
77{
78 //
79 // Assignment operator
80 //
81 if (this != &c) {
82 TNamed::operator=(c) ;
83 }
84
85 this->fEvtContainer=c.fEvtContainer;
86 this->fPartContainer=c.fPartContainer;
87 this->fhQABits=c.fhQABits;
88 for(Int_t i=0;i<kNEvtSel;i++)this->fEvtCutList[i]=c.fEvtCutList[i];
89 for(Int_t i=0;i<kNPartSel;i++)this->fPartCutList[i]=c.fPartCutList[i];
90 return *this ;
91}
92
93//_____________________________________________________________________________
94AliCFManager::~AliCFManager() {
95 //
96 //dtor
97 //
98 if(fhQABits) delete fhQABits;
99}
100
101//_____________________________________________________________________________
102Bool_t AliCFManager::CheckParticleCuts(Int_t isel, TObject *obj, const TString &selcuts) const {
103 //
104 // check whether object obj passes particle-level selection isel
105 //
106
107 if(isel>=kNPartSel){
108 AliWarning(Form("Selection index out of Range! isel=%i, max. number of selections= %i", isel,kNPartSel));
109 return kTRUE;
110 }
111 if(!fPartCutList[isel])return kTRUE;
112 TObjArrayIter iter(fPartCutList[isel]);
113 AliCFCutBase *cut = 0;
114 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
115 TString cutName=cut->GetName();
116 Bool_t checkCut=CompareStrings(cutName,selcuts);
117 if(checkCut && !cut->IsSelected(obj)) return kFALSE;
118 }
119 return kTRUE;
120}
121
122//_____________________________________________________________________________
123Bool_t AliCFManager::CheckEventCuts(Int_t isel, TObject *obj, const TString &selcuts) const{
124 //
125 // check whether object obj passes event-level selection isel
126 //
127
128 if(isel>=kNEvtSel){
129 AliWarning(Form("Selection index out of Range! isel=%i, max. number of selections= %i", isel,kNEvtSel));
130 return kTRUE;
131 }
132 if(!fEvtCutList[isel])return kTRUE;
133 TObjArrayIter iter(fEvtCutList[isel]);
134 AliCFCutBase *cut = 0;
135 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
136 TString cutName=cut->GetName();
137 Bool_t checkCut=CompareStrings(cutName,selcuts);
138 if(checkCut && !cut->IsSelected(obj)) return kFALSE;
139 }
140 return kTRUE;
141}
142
143//_____________________________________________________________________________
144void AliCFManager::FillQABeforeParticleCuts(Int_t isel, TObject *obj) const{
145 //
146 // Fill QA histos before cuts at particle selection level isel are applied
147 //
148
149 if(isel>=kNPartSel){
150 AliWarning(Form("Selection index out of Range! isel=%i, max. number of selections= %i", isel,kNPartSel));
151 return;
152 }
153 if(!fPartCutList[isel])return;
154
155 TObjArrayIter iter(fPartCutList[isel]);
156 AliCFCutBase *cut = 0;
157 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
158 if(cut->IsQAOn())cut->FillHistogramsBeforeCuts(obj);
159 }
160}
161//_____________________________________________________________________________
162void AliCFManager::FillQAAfterParticleCuts(Int_t isel, TObject *obj) const{
163 //
164 // Fill QA histos after cuts at particle selection level isel are applied
165 //
166 if(isel>=kNPartSel){
167 AliWarning(Form("Selection index out of Range! isel=%i, max. number of selections= %i", isel,kNPartSel));
168 return;
169 }
170 if(!fPartCutList[isel])return;
171
172 TObjArrayIter iter(fPartCutList[isel]);
173 AliCFCutBase *cut = 0;
174 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
175 if(cut->IsQAOn())cut->FillHistogramsAfterCuts(obj);
176 }
177}
178
179//_____________________________________________________________________________
180void AliCFManager::FillQABeforeEventCuts(Int_t isel, TObject *obj) const{
181 //
182 // Fill QA histos before cuts at event selection level isel are applied
183 //
184
185 if(isel>=kNEvtSel){
186 AliWarning(Form("Selection index out of Range! isel=%i, max. number of selections= %i", isel,kNEvtSel));
187 return;
188 }
189 if(!fEvtCutList[isel])return;
190
191 TObjArrayIter iter(fEvtCutList[isel]);
192 AliCFCutBase *cut = 0;
193 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
194 if(cut->IsQAOn())cut->FillHistogramsBeforeCuts(obj);
195 }
196}
197
198//_____________________________________________________________________________
199void AliCFManager::FillQAAfterEventCuts(Int_t isel, TObject *obj) const{
200 //
201 // Fill QA histos after cuts at event selection level isel are applied
202 //
203
204 if(isel>=kNEvtSel){
205 AliWarning(Form("Selection index out of Range! isel=%i, max. number of selections= %i", isel,kNEvtSel));
206 return;
207 }
208 if(!fEvtCutList[isel])return;
209
210 TObjArrayIter iter(fEvtCutList[isel]);
211 AliCFCutBase *cut = 0;
212 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
213 if(cut->IsQAOn())cut->FillHistogramsAfterCuts(obj);
214 }
215}
216
217//_____________________________________________________________________________
218void AliCFManager::AddQAHistosToList(TList *list) const {
219 //
220 // Add to list the full list of QA histograms to be written to the output
221 //
222
223 for(Int_t isel=0;isel<kNPartSel; isel++){
224 if(!fPartCutList[isel])continue;
225 TObjArrayIter iter(fPartCutList[isel]);
226 AliCFCutBase *cut = 0;
227 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
228 if(cut->IsQAOn())cut->AddQAHistograms(list);
229 }
230 }
231
232 //Event-level cuts QA
233
234 for(Int_t isel=0;isel<kNEvtSel; isel++){
235 if(!fEvtCutList[isel])continue;
236 TObjArrayIter iter(fEvtCutList[isel]);
237 AliCFCutBase *cut = 0;
238 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
239 if(cut->IsQAOn())cut->AddQAHistograms(list);
240 }
241 }
242}
243//_____________________________________________________________________________
244TBits* AliCFManager::GetQAParticleSelBits(Int_t isel, TObject *obj) {
245 //
246 // Get the full list of QA histograms to be written to the output
247 //
248
249 fhQABits->Clear(); //reset the list
250
251 //Particle-level cuts QA
252
253 if(fPartCutList[isel]){
254 TObjArrayIter iter(fPartCutList[isel]);
255 AliCFCutBase *cut = 0;
256 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
257 if(cut->IsQAOn()){
258 TBits *qalist=new TBits(0);
259 cut->GetBitMap(obj,qalist);
260 for(UInt_t icut=0;icut<qalist->GetNbits();icut++){
261 fhQABits->SetBitNumber(icut,qalist->TestBitNumber(icut));
262 }
263 delete qalist;
264 }
265 }
266 }
267
268 return fhQABits;
269
270}
271
272//_____________________________________________________________________________
273void AliCFManager::SetEventInfo(TObject *obj) const {
274
275 //Particle level cuts
276
277 for(Int_t isel=0;isel<kNPartSel; isel++){
278 if(!fPartCutList[isel])continue;
279 TObjArrayIter iter(fPartCutList[isel]);
280 AliCFCutBase *cut = 0;
281 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
282 cut->SetEvtInfo(obj);
283 }
284 }
285
286 //Event level cuts
287
288 for(Int_t isel=0;isel<kNEvtSel; isel++){
289 if(!fEvtCutList[isel])continue;
290 TObjArrayIter iter(fEvtCutList[isel]);
291 AliCFCutBase *cut = 0;
292 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
293 cut->SetEvtInfo(obj);
294 }
295 }
296}
297//_____________________________________________________________________________
298void AliCFManager::InitQAHistos() const {
299
300 //Particle level cuts
301
302 for(Int_t isel=0;isel<kNPartSel; isel++){
303 if(!fPartCutList[isel])continue;
304 TObjArrayIter iter(fPartCutList[isel]);
305 AliCFCutBase *cut = 0;
306 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
307 if(cut->IsQAOn())cut->Init();
308 }
309 }
310
311 //Event level cuts
312
313 for(Int_t isel=0;isel<kNEvtSel; isel++){
314 if(!fEvtCutList[isel])continue;
315 TObjArrayIter iter(fEvtCutList[isel]);
316 AliCFCutBase *cut = 0;
317 while ( (cut = (AliCFCutBase*)iter.Next()) ) {
318 if(cut->IsQAOn())cut->Init();
319 }
320 }
321}
322
323//_____________________________________________________________________________
324Bool_t AliCFManager::CompareStrings(const TString &cutname,const TString &selcuts) const{
325 //
326 // compare two strings
327 //
328
329 if(selcuts.Contains("all"))return kTRUE;
330 if ( selcuts.CompareTo(cutname) == 0 ||
331 selcuts.BeginsWith(cutname+" ") ||
332 selcuts.EndsWith(" "+cutname) ||
333 selcuts.Contains(" "+cutname+" ")) return kTRUE;
334 return kFALSE;
335}
336
337