]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muon/AliAnalysisMuMuCutRegistry.cxx
expand particle map when needed
[u/mrichter/AliRoot.git] / PWG / muon / AliAnalysisMuMuCutRegistry.cxx
CommitLineData
5376e016
CP
1#include "AliAnalysisMuMuCutRegistry.h"
2
3/**
4 *
5 * \ingroup pwg-muon-mumu
6 *
7 * \class AliAnalysisMuMuCutRegistry
8 * The cut elements and cut combinations are stored per type, i.e. there's a set for
9 * event cuts/combinations, a set for track cuts/combinations, and a set for track pair cuts/combinations.
10 *
11 * To define a new cut use the AddEventCut, AddTrackCut, AndTrackPairCut and AddTriggerClassCut methods.
12 *
13 * To add an existing cut see AddCutElement.
14 *
15 * To define the negation of a cut, use the Not method.
16 *
17 * To add a new combination use one of the AddCutCombination methods, depending on the number
18 * of cut element(s) the combination is made of.
19 *
20 * Note that what the sub-analysis are really concerned with are cut combinations (i.e. if
21 * you fail to define any combination, nothing will be cut, whatever the number of cut elements
22 * you've defined).
23 *
24 * This class also defines a few default control cut elements aptly named AlwaysTrue.
25 *
26 */
27
28#include <utility>
29#include "AliLog.h"
30#include "TMethodCall.h"
31#include "AliVEvent.h"
32#include <set>
33#include "AliAnalysisMuMuCutElement.h"
34#include "AliAnalysisMuMuCutCombination.h"
35#include "TObjArray.h"
36#include "Riostream.h"
37#include "TList.h"
38
39ClassImp(AliAnalysisMuMuCutRegistry)
40
41//_____________________________________________________________________________
42AliAnalysisMuMuCutRegistry::AliAnalysisMuMuCutRegistry()
43: TObject(),
44fCutElements(0x0),
45fCutCombinations(0x0)
46{
47 /// ctor
48}
49
50//_____________________________________________________________________________
51AliAnalysisMuMuCutRegistry::~AliAnalysisMuMuCutRegistry()
52{
53 /// dtor
54
55 delete fCutElements;
56 delete fCutCombinations;
57}
58
59//_____________________________________________________________________________
60Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(const TObjArray& cutElements)
61{
62 /// Add a cut combination composed of the cuts in the cutElements array.
63 ///
64 /// \return 1 in case of success, 0 if already there, -1 failure
65
66 if ( cutElements.IsEmpty() ) return -1;
67
68 AliAnalysisMuMuCutCombination* cutCombination = new AliAnalysisMuMuCutCombination;
69
70 TIter next(&cutElements);
71 AliAnalysisMuMuCutElement* ce;
72
73 while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(next()) ) )
74 {
75 cutCombination->Add(ce);
76 }
77
78 if ( GetCutCombinations(AliAnalysisMuMuCutElement::kAny)->FindObject(cutCombination) )
79 {
80 delete cutCombination;
81 return 0;
82 }
83
84 GetCutCombinations(AliAnalysisMuMuCutElement::kAny)->Add(cutCombination);
85
86 if ( cutCombination->IsEventCutter() || cutCombination->IsEventHandlerCutter() )
87 {
88 GetCutCombinations(AliAnalysisMuMuCutElement::kEvent)->Add(cutCombination);
89 }
90
91 if ( cutCombination->IsTrackCutter() )
92 {
93 GetCutCombinations(AliAnalysisMuMuCutElement::kTrack)->Add(cutCombination);
94 }
95
96 if ( cutCombination->IsTrackPairCutter() )
97 {
98 GetCutCombinations(AliAnalysisMuMuCutElement::kTrackPair)->Add(cutCombination);
99 }
100
101 if ( cutCombination->IsTriggerClassCutter() )
102 {
103 GetCutCombinations(AliAnalysisMuMuCutElement::kTriggerClass)->Add(cutCombination);
104 }
105
106 return 1;
107}
108
109//_____________________________________________________________________________
110Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(AliAnalysisMuMuCutElement* ce1)
111{
112 /// Convenience method to create a cut combination made of a single cut
113 TObjArray cutElements;
114 if ( ce1 ) cutElements.Add(ce1);
115 return AddCutCombination(cutElements);
116}
117
118//_____________________________________________________________________________
119Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(AliAnalysisMuMuCutElement* ce1,
120 AliAnalysisMuMuCutElement* ce2)
121{
122 /// Convenience method to create a cut combination made of 2 cuts
123 TObjArray cutElements;
124 if ( ce1 ) cutElements.Add(ce1);
125 if ( ce2 ) cutElements.Add(ce2);
126 return AddCutCombination(cutElements);
127}
128
129//_____________________________________________________________________________
130Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(AliAnalysisMuMuCutElement* ce1,
131 AliAnalysisMuMuCutElement* ce2,
132 AliAnalysisMuMuCutElement* ce3)
133{
134 /// Convenience method to create a cut combination made of 3 cuts
135 TObjArray cutElements;
136 if ( ce1 ) cutElements.Add(ce1);
137 if ( ce2 ) cutElements.Add(ce2);
138 if ( ce3 ) cutElements.Add(ce3);
139 return AddCutCombination(cutElements);
140}
141
142//_____________________________________________________________________________
143Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(AliAnalysisMuMuCutElement* ce1, AliAnalysisMuMuCutElement* ce2, AliAnalysisMuMuCutElement* ce3,
144 AliAnalysisMuMuCutElement* ce4)
145{
146 /// Convenience method to create a cut combination made of 4 cuts
147 TObjArray cutElements;
148 if ( ce1 ) cutElements.Add(ce1);
149 if ( ce2 ) cutElements.Add(ce2);
150 if ( ce3 ) cutElements.Add(ce3);
151 if ( ce4 ) cutElements.Add(ce4);
152 return AddCutCombination(cutElements);
153}
154//_____________________________________________________________________________
155Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(AliAnalysisMuMuCutElement* ce1, AliAnalysisMuMuCutElement* ce2, AliAnalysisMuMuCutElement* ce3,
156 AliAnalysisMuMuCutElement* ce4, AliAnalysisMuMuCutElement* ce5)
157{
158 /// Convenience method to create a cut combination made of 5 cuts
159
160 TObjArray cutElements;
161 if ( ce1 ) cutElements.Add(ce1);
162 if ( ce2 ) cutElements.Add(ce2);
163 if ( ce3 ) cutElements.Add(ce3);
164 if ( ce4 ) cutElements.Add(ce4);
165 if ( ce5 ) cutElements.Add(ce5);
166 return AddCutCombination(cutElements);
167}
168
169//_____________________________________________________________________________
170Int_t AliAnalysisMuMuCutRegistry::AddCutCombination(AliAnalysisMuMuCutElement* ce1, AliAnalysisMuMuCutElement* ce2, AliAnalysisMuMuCutElement* ce3,
171 AliAnalysisMuMuCutElement* ce4, AliAnalysisMuMuCutElement* ce5, AliAnalysisMuMuCutElement* ce6)
172{
173 /// Convenience method to create a cut combination made of 6 cuts
174
175 TObjArray cutElements;
176 if ( ce1 ) cutElements.Add(ce1);
177 if ( ce2 ) cutElements.Add(ce2);
178 if ( ce3 ) cutElements.Add(ce3);
179 if ( ce4 ) cutElements.Add(ce4);
180 if ( ce5 ) cutElements.Add(ce5);
181 if ( ce6 ) cutElements.Add(ce6);
182 return AddCutCombination(cutElements);
183}
184
185//_____________________________________________________________________________
186AliAnalysisMuMuCutElement*
187AliAnalysisMuMuCutRegistry::CreateCutElement(AliAnalysisMuMuCutElement::ECutType type,
188 TObject& cutClass,
189 const char* cutMethodName,
190 const char* cutMethodPrototype,
191 const char* defaultParameters)
192{
193 /** Create a cut element. See the ctor of AliAnalysisMuMuCutElement for the meaning
194 * of the parameters.
195 */
196
197 AliAnalysisMuMuCutElement* ce = new AliAnalysisMuMuCutElement(type,cutClass,cutMethodName,cutMethodPrototype,defaultParameters);
198
199 AliAnalysisMuMuCutElement* added = AddCutElement(ce);
200
201 if (!added)
202 {
203 delete ce;
204 }
205
206 return added;
207}
208
209//_____________________________________________________________________________
210AliAnalysisMuMuCutElement*
211AliAnalysisMuMuCutRegistry::AddCutElement(AliAnalysisMuMuCutElement* ce)
212{
213 /// Add an existing cut element to the registry if it is valid
214
215 if ( ce && ce->IsValid() )
216 {
217 if (!GetCutElements(AliAnalysisMuMuCutElement::kAny)->FindObject(ce))
218 {
219 GetCutElements(AliAnalysisMuMuCutElement::kAny)->Add(ce);
220 if ( ce->IsEventCutter() || ce->IsEventHandlerCutter() )
221 {
222 GetCutElements(AliAnalysisMuMuCutElement::kEvent)->Add(ce);
223 }
224 else if ( ce->IsTrackCutter() )
225 {
226 GetCutElements(AliAnalysisMuMuCutElement::kTrack)->Add(ce);
227 }
228 else if ( ce->IsTrackPairCutter() )
229 {
230 GetCutElements(AliAnalysisMuMuCutElement::kTrackPair)->Add(ce);
231 }
232 else if ( ce->IsTriggerClassCutter() )
233 {
234 GetCutElements(AliAnalysisMuMuCutElement::kTriggerClass)->Add(ce);
235 }
236 }
237 return ce;
238 }
239 return 0x0;
240}
241
242//_____________________________________________________________________________
243AliAnalysisMuMuCutElement* AliAnalysisMuMuCutRegistry::AddEventCut(TObject& cutClass,
244 const char* cutMethodName,
245 const char* cutMethodPrototype,
246 const char* defaultParameters)
247{
248 /// Shortcut method to create a cut element of type kEvent
249 return CreateCutElement(AliAnalysisMuMuCutElement::kEvent,cutClass,cutMethodName,
250 cutMethodPrototype,defaultParameters);
251}
252
253//_____________________________________________________________________________
254AliAnalysisMuMuCutElement* AliAnalysisMuMuCutRegistry::AddTrackCut(TObject& cutClass,
255 const char* cutMethodName,
256 const char* cutMethodPrototype,
257 const char* defaultParameters)
258{
259 /// Shortcut method to create a cut element of type kTrack
260 return CreateCutElement(AliAnalysisMuMuCutElement::kTrack,cutClass,cutMethodName,
261 cutMethodPrototype,defaultParameters);
262}
263
264//_____________________________________________________________________________
265AliAnalysisMuMuCutElement* AliAnalysisMuMuCutRegistry::AddTrackPairCut(TObject& cutClass,
266 const char* cutMethodName,
267 const char* cutMethodPrototype,
268 const char* defaultParameters)
269{
270 /// Shortcut method to create a cut element of type kTrackPair
271 return CreateCutElement(AliAnalysisMuMuCutElement::kTrackPair,cutClass,cutMethodName,
272 cutMethodPrototype,defaultParameters);
273}
274
275//_____________________________________________________________________________
276AliAnalysisMuMuCutElement* AliAnalysisMuMuCutRegistry::AddTriggerClassCut(TObject& cutClass,
277 const char* cutMethodName,
278 const char* cutMethodPrototype,
279 const char* defaultParameters)
280{
281 /// Shortcut method to create a cut element of type kTriggerClass
282 return CreateCutElement(AliAnalysisMuMuCutElement::kTriggerClass,cutClass,cutMethodName,
283 cutMethodPrototype,defaultParameters);
284}
285
286//_____________________________________________________________________________
287const TObjArray* AliAnalysisMuMuCutRegistry::GetCutCombinations(AliAnalysisMuMuCutElement::ECutType type) const
288{
289 /// Get (and create if not already done) the array of cut combinations of the given type
290
291 if (!fCutCombinations) return 0x0;
292
293 return static_cast<TObjArray*>(fCutCombinations->At(type));
294}
295
296//_____________________________________________________________________________
297TObjArray* AliAnalysisMuMuCutRegistry::GetCutCombinations(AliAnalysisMuMuCutElement::ECutType type)
298{
299 /// Get (and create if not already done) the array of cut combinations of the given type
300
301 if (!fCutCombinations)
302 {
303 // the fCutCombinations array will be the owner of all the cut combinations
304
305 Int_t N = AliAnalysisMuMuCutElement::kAny + 1;
306
307 fCutCombinations = new TObjArray(N);
308 fCutCombinations->SetOwner(kTRUE);
309
310 for ( Int_t i = 0; i < N; ++i )
311 {
312 TObjArray* array = new TObjArray;
313 array->SetOwner(kFALSE);
314 if (i==AliAnalysisMuMuCutElement::kAny)
315 {
316 // only the first array, containing all the combinations
317 // is the owner of the combinations
318 // the other arrays are just pointing to those
319 array->SetOwner(kTRUE);
320 }
321 fCutCombinations->AddAt(array,i);
322 }
323 }
324 return static_cast<TObjArray*>(fCutCombinations->At(type));
325}
326
327//_____________________________________________________________________________
328const TObjArray* AliAnalysisMuMuCutRegistry::GetCutElements(AliAnalysisMuMuCutElement::ECutType type) const
329{
330 /// Get the array of cut elements of the given type. Return 0x0 if the array does not exist yet
331
332 if (!fCutElements) return 0x0;
333
334 return static_cast<TObjArray*>(fCutElements->At(type));
335}
336
337//_____________________________________________________________________________
338TObjArray* AliAnalysisMuMuCutRegistry::GetCutElements(AliAnalysisMuMuCutElement::ECutType type)
339{
340 /// Get (and create if not already done) the array of cut elements of the given type
341
342 if (!fCutElements)
343 {
344 // owner of all the cut elements
345 Int_t N = AliAnalysisMuMuCutElement::kAny + 1;
346 fCutElements = new TObjArray(N);
347 fCutElements->SetOwner(kTRUE);
348
349 for ( Int_t i = 0; i < N; ++i )
350 {
351 TObjArray* array = new TObjArray;
352 array->SetOwner(kFALSE);
353 if (i == AliAnalysisMuMuCutElement::kAny )
354 {
355 // only the first array is the owner of the cuts
356 // the other ones are just pointing to this one
357 array->SetOwner(kTRUE);
358 }
359 fCutElements->AddAt(array,i);
360 }
361 }
362 return static_cast<TObjArray*>(fCutElements->At(type));
363}
364
365//_____________________________________________________________________________
366AliAnalysisMuMuCutElement* AliAnalysisMuMuCutRegistry::Not(const AliAnalysisMuMuCutElement& cutElement)
367{
368 /// Create a cut which is the opposite of cutElement, and adds it.
369
370 AliAnalysisMuMuCutElementBar* bar = new AliAnalysisMuMuCutElementBar(cutElement);
371
372 AliAnalysisMuMuCutElement* added = AddCutElement(bar);
373
374 if (!added)
375 {
376 delete bar;
377 }
378
379 return added;
380}
381
382//_____________________________________________________________________________
383void AliAnalysisMuMuCutRegistry::Print(Option_t* opt) const
384{
385 /// Printout
386
387 TString sopt(opt);
388 sopt.ToUpper();
389
390 std::cout << "++++ Cut combinations defined : " << std::endl;
391
392 AliAnalysisMuMuCutElement::ECutType cutTypes[] = { AliAnalysisMuMuCutElement::kEvent, AliAnalysisMuMuCutElement::kTrack,
393 AliAnalysisMuMuCutElement::kTrackPair, AliAnalysisMuMuCutElement::kTriggerClass };
394
395 Int_t i(1);
396
397 for ( Int_t iCutType = 0; iCutType < 4; ++iCutType )
398 {
399 if (GetCutElements(cutTypes[iCutType])->IsEmpty()) continue;
400 std::cout << " Cutting on " << AliAnalysisMuMuCutElement::CutTypeName(cutTypes[iCutType]) << std::endl;
401 TIter next(GetCutCombinations(cutTypes[iCutType]));
402 AliAnalysisMuMuCutCombination* cutCombination;
403
404 while ( ( cutCombination = static_cast<AliAnalysisMuMuCutCombination*>(next())) )
405 {
406 std::cout << Form(" %4d ",i);
407 cutCombination->Print(" ");
408 ++i;
409 }
410 }
411
412 if ( sopt.Contains("FULL") || sopt.Contains("ALL") )
413 {
414 std::cout << "++++ Individual cuts defined : " << std::endl;
415
416 for ( Int_t iCutType = 0; iCutType < 4; ++iCutType )
417 {
418 if (GetCutElements(cutTypes[iCutType])->IsEmpty()) continue;
419 std::cout << " Cutting on " << AliAnalysisMuMuCutElement::CutTypeName(cutTypes[iCutType]) << std::endl;
420 TIter nextCutRef(GetCutElements(cutTypes[iCutType]));
421 AliAnalysisMuMuCutElement* ce;
422 i = 1;
423 while ( ( ce = static_cast<AliAnalysisMuMuCutElement*>(nextCutRef()) ) )
424 {
425 std::cout << Form("%4d ",i);
426 ce->Print();
427 ++i;
428 }
429 }
430 }
431}