Standarized naming schema for cuts
[u/mrichter/AliRoot.git] / ANALYSIS / AliAODParticleCut.cxx
CommitLineData
a5556ea5 1#include "AliAODParticleCut.h"
2//__________________________________________________________________________
3////////////////////////////////////////////////////////////////////////////
4// //
5// class AliAODParticleCut //
6// //
7// Classes for single particle cuts //
8// User should use only AliAODParticleCut, eventually //
9// EmptyCut which passes all particles //
10// There is all interface for setting cuts on all particle properties //
11// The main method is Pass - which returns //
12// True to reject particle //
13// False in case it meets all the criteria of the given cut //
14// //
15// User should create (and also destroy) cuts himself //
16// and then pass them to the Analysis And Function by a proper method //
17// //
18// //
19// more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html //
78d7c6d3 20// responsible: Piotr Skowronski@cern.ch //
a5556ea5 21// //
22////////////////////////////////////////////////////////////////////////////
23
24#include <Riostream.h>
25
26
27ClassImp(AliAODParticleCut)
28const Int_t AliAODParticleCut::fgkMaxCuts = 50;
29/******************************************************************/
30
31AliAODParticleCut::AliAODParticleCut():
b4fb427e 32 fCuts(new AliAODParticleBaseCut* [fgkMaxCuts]),//last property in the property enum => defines number of properties
a5556ea5 33 fNCuts(0),
34 fPID(0)
35{
36 //default ctor
37}
38/******************************************************************/
39
40AliAODParticleCut::AliAODParticleCut(const AliAODParticleCut& in):
41 TObject(in)
42{
43 //cpy ctor
b4fb427e 44 fCuts = new AliAODParticleBaseCut* [fgkMaxCuts];//last property in the property
a5556ea5 45 //property enum => defines number of properties
46 fNCuts = in.fNCuts;
47 fPID = in.fPID;
48 for (Int_t i = 0;i<fNCuts;i++)
49 {
b4fb427e 50 fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
a5556ea5 51 }
52}
53/******************************************************************/
54AliAODParticleCut& AliAODParticleCut::operator=(const AliAODParticleCut& in)
55{
56 //assigment operator
57 Info("operator=","operator=operator=operator=operator=\noperator=operator=operator=operator=");
58 for (Int_t i = 0;i<fNCuts;i++)
59 {
60 delete fCuts[i];
61 }
62
63 fNCuts = in.fNCuts;
64 fPID = in.fPID;
65 for (Int_t i = 0;i<fNCuts;i++)
66 {
b4fb427e 67 fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
a5556ea5 68 }
69 return *this;
70}
71
72/******************************************************************/
73AliAODParticleCut::~AliAODParticleCut()
74{
75 //dtor
76 for (Int_t i = 0;i<fNCuts;i++)
77 {
78 delete fCuts[i];
79 }
80 delete []fCuts;
81}
82/******************************************************************/
83
afa8b37b 84Bool_t AliAODParticleCut::Pass(AliVAODParticle* p) const
a5556ea5 85{
86//method checks all the cuts that are set (in the list)
87//If any of the baseCuts rejects particle False(rejection) is returned
88
89 if(!p)
90 {
91 Warning("Pass()","No Pasaran! We never accept NULL pointers");
92 return kTRUE;
93 }
94 if( (p->GetPdgCode() != fPID) && ( fPID != 0)) return kTRUE;
95
96 for (Int_t i = 0;i<fNCuts;i++)
97 {
98 if ( (fCuts[i]->Pass(p)) )
99 {
100// fCuts[i]->Print();
101 return kTRUE; //if one of the cuts rejects, then reject
102 }
103 }
104 return kFALSE;
105}
106/******************************************************************/
107
b4fb427e 108void AliAODParticleCut::AddBasePartCut(AliAODParticleBaseCut* basecut)
a5556ea5 109{
110 //adds the base pair cut (cut on one value)
111
112 if (!basecut) return;
113 if( fNCuts == (fgkMaxCuts-1) )
114 {
115 Warning("AddBasePartCut","Not enough place for another cut");
116 return;
117 }
118 fCuts[fNCuts++]=basecut;
119
120}
121
122/******************************************************************/
b4fb427e 123AliAODParticleBaseCut* AliAODParticleCut::FindCut(AliAODCutProperty property)
a5556ea5 124{
125 //returns pointer to the cut checking the given property
126 for (Int_t i = 0;i<fNCuts;i++)
127 {
128 if (fCuts[i]->GetProperty() == property)
129 return fCuts[i]; //we found the cut we were searching for
130 }
131
132 return 0x0; //we did not found this cut
133
134}
135/******************************************************************/
136
137void AliAODParticleCut::SetMomentumRange(Double_t min, Double_t max)
138{
139 //Sets momentum range
140 AliAODMomentumCut* cut= (AliAODMomentumCut*)FindCut(kAODP);
141 if(cut) cut->SetRange(min,max);
142 else fCuts[fNCuts++] = new AliAODMomentumCut(min,max);
143}
144/******************************************************************/
145
146
147void AliAODParticleCut::SetPtRange(Double_t min, Double_t max)
148{
149 //name self descriptive
150 AliAODPtCut* cut= (AliAODPtCut*)FindCut(kAODPt);
151 if(cut) cut->SetRange(min,max);
152 else fCuts[fNCuts++] = new AliAODPtCut(min,max);
153
154}
155/******************************************************************/
156
157void AliAODParticleCut::SetEnergyRange(Double_t min, Double_t max)
158{
159 //name self descriptive
160 AliAODEnergyCut* cut= (AliAODEnergyCut*)FindCut(kAODE);
161 if(cut) cut->SetRange(min,max);
162 else fCuts[fNCuts++] = new AliAODEnergyCut(min,max);
163
164}
165/******************************************************************/
166
167void AliAODParticleCut::SetRapidityRange(Double_t min, Double_t max)
168{
169 //name self descriptive
b4fb427e 170 AliAODParticleBaseCut* cut = FindCut(kAODRapidity);
a5556ea5 171 if(cut) cut->SetRange(min,max);
172 else fCuts[fNCuts++] = new AliAODRapidityCut(min,max);
173
174}
175/******************************************************************/
176
177void AliAODParticleCut::SetPseudoRapidityRange(Double_t min, Double_t max)
178{
179 //name self descriptive
b4fb427e 180 AliAODParticleBaseCut* cut = FindCut(kAODPseudoRapidity);
a5556ea5 181 if(cut) cut->SetRange(min,max);
182 else fCuts[fNCuts++] = new AliAODPseudoRapidityCut(min,max);
183
184}
185/******************************************************************/
186
187void AliAODParticleCut::SetPxRange(Double_t min, Double_t max)
188{
189 //name self descriptive
b4fb427e 190 AliAODParticleBaseCut* cut = FindCut(kAODPx);
a5556ea5 191 if(cut) cut->SetRange(min,max);
192 else fCuts[fNCuts++] = new AliAODPxCut(min,max);
193}
194/******************************************************************/
195
196void AliAODParticleCut::SetPyRange(Double_t min, Double_t max)
197{
198 //name self descriptive
b4fb427e 199 AliAODParticleBaseCut* cut = FindCut(kAODPy);
a5556ea5 200 if(cut) cut->SetRange(min,max);
201 else fCuts[fNCuts++] = new AliAODPyCut(min,max);
202}
203/******************************************************************/
204
205void AliAODParticleCut::SetPzRange(Double_t min, Double_t max)
206{
207 //name self descriptive
b4fb427e 208 AliAODParticleBaseCut* cut = FindCut(kAODPz);
a5556ea5 209 if(cut) cut->SetRange(min,max);
210 else fCuts[fNCuts++] = new AliAODPzCut(min,max);
211}
212/******************************************************************/
213
214void AliAODParticleCut::SetPhiRange(Double_t min, Double_t max)
215{
216 //name self descriptive
b4fb427e 217 AliAODParticleBaseCut* cut = FindCut(kAODPhi);
a5556ea5 218 if(cut) cut->SetRange(min,max);
219 else fCuts[fNCuts++] = new AliAODPhiCut(min,max);
220}
221/******************************************************************/
222
223void AliAODParticleCut::SetThetaRange(Double_t min, Double_t max)
224{
225 //name self descriptive
b4fb427e 226 AliAODParticleBaseCut* cut = FindCut(kAODTheta);
a5556ea5 227 if(cut) cut->SetRange(min,max);
228 else fCuts[fNCuts++] = new AliAODThetaCut(min,max);
229}
230/******************************************************************/
231
232void AliAODParticleCut::SetVxRange(Double_t min, Double_t max)
233{
234 //name self descriptive
b4fb427e 235 AliAODParticleBaseCut* cut = FindCut(kAODVx);
a5556ea5 236 if(cut) cut->SetRange(min,max);
237 else fCuts[fNCuts++] = new AliAODVxCut(min,max);
238}
239/******************************************************************/
240
241void AliAODParticleCut::SetVyRange(Double_t min, Double_t max)
242{
243 //name self descriptive
b4fb427e 244 AliAODParticleBaseCut* cut = FindCut(kAODVy);
a5556ea5 245 if(cut) cut->SetRange(min,max);
246 else fCuts[fNCuts++] = new AliAODVyCut(min,max);
247}
248/******************************************************************/
249
250void AliAODParticleCut::SetVzRange(Double_t min, Double_t max)
251{
252 //name self descriptive
b4fb427e 253 AliAODParticleBaseCut* cut = FindCut(kAODVz);
a5556ea5 254 if(cut) cut->SetRange(min,max);
255 else fCuts[fNCuts++] = new AliAODVzCut(min,max);
256}
257
258/******************************************************************/
259void AliAODParticleCut::Streamer(TBuffer &b)
260{
261 // Stream all objects in the array to or from the I/O buffer.
262
263 UInt_t R__s, R__c;
264 if (b.IsReading())
265 {
266 Int_t i;
267 for (i = 0;i<fNCuts;i++) delete fCuts[i];
268 b.ReadVersion(&R__s, &R__c);
269 TObject::Streamer(b);
270 b >> fPID;
271 b >> fNCuts;
272 for (i = 0;i<fNCuts;i++)
273 {
274 b >> fCuts[i];
275 }
276 b.CheckByteCount(R__s, R__c,AliAODParticleCut::IsA());
277 }
278 else
279 {
280 R__c = b.WriteVersion(AliAODParticleCut::IsA(), kTRUE);
281 TObject::Streamer(b);
282 b << fPID;
283 b << fNCuts;
284 for (Int_t i = 0;i<fNCuts;i++)
285 {
286 b << fCuts[i];
287 }
288 b.SetByteCount(R__c, kTRUE);
289 }
290}
291/******************************************************************/
292
293void AliAODParticleCut::Print(void) const
294{
295 //prints all information about the cut to stdout
296 cout<<"Printing AliAODParticleCut, this = "<<this<<endl;
297 cout<<"fPID "<<fPID<<endl;
298 cout<<"fNCuts "<<fNCuts <<endl;
299 for (Int_t i = 0;i<fNCuts;i++)
300 {
301 cout<<" fCuts["<<i<<"] "<<fCuts[i]<<endl<<" ";
302 fCuts[i]->Print();
303 }
304}
305
306/******************************************************************/
307/******************************************************************/
308
b4fb427e 309ClassImp(AliAODParticleEmptyCut)
310void AliAODParticleEmptyCut::Streamer(TBuffer &b)
a5556ea5 311 {
312 //stramer
313 AliAODParticleCut::Streamer(b);
314 }
315/******************************************************************/
316/******************************************************************/
317/******************************************************************/
318
319/******************************************************************/
320/******************************************************************/
321/******************************************************************/
322
b4fb427e 323ClassImp(AliAODParticleBaseCut)
324void AliAODParticleBaseCut::Print(void) const
a5556ea5 325{
326 // prints the information anout the base cut to stdout
327 cout<<"fMin="<<fMin <<", fMax=" <<fMax<<" ";
328 PrintProperty();
329}
330/******************************************************************/
331
b4fb427e 332void AliAODParticleBaseCut::PrintProperty(void) const
a5556ea5 333{
334 //prints the property name
335 switch (fProperty)
336 {
337 case kAODP:
338 cout<<"kAODP"; break;
339 case kAODPt:
340 cout<<"kAODPt"; break;
341 case kAODE:
342 cout<<"kAODE"; break;
343 case kAODRapidity:
344 cout<<"kAODRapidity"; break;
345 case kAODPseudoRapidity:
346 cout<<"kAODPseudoRapidity"; break;
347 case kAODPx:
348 cout<<"kAODPx"; break;
349 case kAODPy:
350 cout<<"kAODPy"; break;
351 case kAODPz:
352 cout<<"kAODPz"; break;
353 case kAODPhi:
354 cout<<"kAODPhi"; break;
355 case kAODTheta:
356 cout<<"kAODTheta"; break;
357 case kAODVx:
358 cout<<"kAODVx"; break;
359 case kAODVy:
360 cout<<"kAODVy"; break;
361 case kAODVz:
362 cout<<"kAODVz"; break;
363 case kAODPid:
364 cout<<"kAODPid"; break;
365 case kAODNone:
366 cout<<"kAODNone"; break;
367 default:
368 cout<<"Property Not Found";
369 }
370 cout<<endl;
371}
372ClassImp( AliAODMomentumCut )
373
374ClassImp( AliAODPtCut )
375ClassImp( AliAODEnergyCut )
376ClassImp( AliAODRapidityCut )
377ClassImp( AliAODPseudoRapidityCut )
378ClassImp( AliAODPxCut )
379ClassImp( AliAODPyCut )
380ClassImp( AliAODPzCut )
381ClassImp( AliAODPhiCut )
382ClassImp( AliAODThetaCut )
383ClassImp( AliAODVxCut )
384ClassImp( AliAODVyCut )
385ClassImp( AliAODVzCut )
386
387ClassImp( AliAODPIDCut )
388
389void AliAODPIDCut::Print(void) const
390{
391 cout<<"PID "<<fPID<<" ";
b4fb427e 392 AliAODParticleBaseCut::Print();
a5556ea5 393}
394
395ClassImp( AliAODLogicalOperCut )
396
397AliAODLogicalOperCut::AliAODLogicalOperCut():
b4fb427e 398 AliAODParticleBaseCut(-10e10,10e10,kAODNone),
a5556ea5 399 fFirst(new AliAODDummyBaseCut),
400 fSecond(new AliAODDummyBaseCut)
401{
402 //ctor
403}
404/******************************************************************/
405
b4fb427e 406AliAODLogicalOperCut::AliAODLogicalOperCut(AliAODParticleBaseCut* first, AliAODParticleBaseCut* second):
407 AliAODParticleBaseCut(-10e10,10e10,kAODNone),
408 fFirst((first)?(AliAODParticleBaseCut*)first->Clone():0x0),
409 fSecond((second)?(AliAODParticleBaseCut*)second->Clone():0x0)
a5556ea5 410{
411 //ctor
412 if ( (fFirst && fSecond) == kFALSE)
413 {
414 Fatal("AliAODLogicalOperCut","One of parameters is NULL!");
415 }
416}
417/******************************************************************/
418
419AliAODLogicalOperCut::~AliAODLogicalOperCut()
420{
421 //destructor
422 delete fFirst;
423 delete fSecond;
424}
425/******************************************************************/
426
afa8b37b 427Bool_t AliAODLogicalOperCut::AliAODDummyBaseCut::Pass(AliVAODParticle* /*part*/) const
a5556ea5 428{
429 //checks if particles passes properties defined by this cut
430 Warning("Pass","You are using dummy base cut! Probobly some logical cut is not set up properly");
431 return kFALSE;//accept
432}
433/******************************************************************/
434
435void AliAODLogicalOperCut::Streamer(TBuffer &b)
436{
437 // Stream all objects in the array to or from the I/O buffer.
438 UInt_t R__s, R__c;
439 if (b.IsReading())
440 {
441 delete fFirst;
442 delete fSecond;
443 fFirst = 0x0;
444 fSecond = 0x0;
445
446 b.ReadVersion(&R__s, &R__c);
447 TObject::Streamer(b);
448 b >> fFirst;
449 b >> fSecond;
450 b.CheckByteCount(R__s, R__c,AliAODLogicalOperCut::IsA());
451 }
452 else
453 {
454 R__c = b.WriteVersion(AliAODLogicalOperCut::IsA(), kTRUE);
455 TObject::Streamer(b);
456 b << fFirst;
457 b << fSecond;
458 b.SetByteCount(R__c, kTRUE);
459 }
460}
461
462/******************************************************************/
463ClassImp(AliAODOrCut)
464
afa8b37b 465Bool_t AliAODOrCut::Pass(AliVAODParticle * p) const
a5556ea5 466{
467 //returns true when rejected
468 //AND operation is a little bit misleading but is correct
469 //User wants to build logical cuts with natural (positive) logic
470 //while AODAN use inernally reverse (returns true when rejected)
471 if (fFirst->Pass(p) && fSecond->Pass(p)) return kTRUE;//rejected (both rejected, returned kTRUE)
472 return kFALSE;//accepted, at least one accepted (returned kFALSE)
473}
474/******************************************************************/
475
476ClassImp(AliAODAndCut)
477
afa8b37b 478Bool_t AliAODAndCut::Pass(AliVAODParticle * p) const
a5556ea5 479{
480 //returns true when rejected
481 //OR operation is a little bit misleading but is correct
482 //User wants to build logical cuts with natural (positive) logic
483 //while AODAN use inernally reverse (returns true when rejected)
484 if (fFirst->Pass(p) || fSecond->Pass(p)) return kTRUE;//rejected (any of two rejected(returned kTRUE) )
485 return kFALSE;//accepted (both accepted (returned kFALSE))
486}
487/******************************************************************/