Version number ++
[u/mrichter/AliRoot.git] / ANALYSIS / AliAODParticleCut.cxx
CommitLineData
a5556ea5 1#include "AliAODParticleCut.h"
2//__________________________________________________________________________
3////////////////////////////////////////////////////////////////////////////
4// //
5// class AliAODParticleCut //
6// //
f9f11a4b 7// Classes for single particle cuts. //
8// User should use mainly AliAODParticleCut interface methods, //
9// eventually EmptyCut which passes all particles. //
10// //
a5556ea5 11// There is all interface for setting cuts on all particle properties //
f9f11a4b 12// The main method is Rejected - which returns //
a5556ea5 13// True to reject particle //
14// False in case it meets all the criteria of the given cut //
15// //
f9f11a4b 16// This class has the list of base particle cuts that perform check on //
17// single property. Particle is rejected if any of cuts rejects it. //
18// There are implemented logical base cuts that perform logical //
19// operations on results of two other base cuts. Using them user can //
20// create a tree structure of a base cuts that performs sophisticated //
21// cut. //
22// //
23// User can also implement a base cut that performs complicated //
24// calculations, if it is only more convenient and/or efficint. //
a5556ea5 25// //
f9f11a4b 26// User should delete created cuts himself //
27// because when setting a cut, other objects (functions,analyses, //
28// readers, other cuts) make their own copy of a cut. //
a5556ea5 29// //
f9f11a4b 30// more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html //
31// responsible: Piotr Skowronski@cern.ch //
a5556ea5 32// //
33////////////////////////////////////////////////////////////////////////////
34
35#include <Riostream.h>
36
37
38ClassImp(AliAODParticleCut)
39const Int_t AliAODParticleCut::fgkMaxCuts = 50;
40/******************************************************************/
41
42AliAODParticleCut::AliAODParticleCut():
b4fb427e 43 fCuts(new AliAODParticleBaseCut* [fgkMaxCuts]),//last property in the property enum => defines number of properties
a5556ea5 44 fNCuts(0),
45 fPID(0)
46{
47 //default ctor
48}
49/******************************************************************/
50
51AliAODParticleCut::AliAODParticleCut(const AliAODParticleCut& in):
52 TObject(in)
53{
54 //cpy ctor
b4fb427e 55 fCuts = new AliAODParticleBaseCut* [fgkMaxCuts];//last property in the property
a5556ea5 56 //property enum => defines number of properties
57 fNCuts = in.fNCuts;
58 fPID = in.fPID;
59 for (Int_t i = 0;i<fNCuts;i++)
60 {
b4fb427e 61 fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
a5556ea5 62 }
63}
64/******************************************************************/
65AliAODParticleCut& AliAODParticleCut::operator=(const AliAODParticleCut& in)
66{
67 //assigment operator
68 Info("operator=","operator=operator=operator=operator=\noperator=operator=operator=operator=");
69 for (Int_t i = 0;i<fNCuts;i++)
70 {
71 delete fCuts[i];
72 }
73
74 fNCuts = in.fNCuts;
75 fPID = in.fPID;
76 for (Int_t i = 0;i<fNCuts;i++)
77 {
b4fb427e 78 fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
a5556ea5 79 }
80 return *this;
81}
82
83/******************************************************************/
84AliAODParticleCut::~AliAODParticleCut()
85{
86 //dtor
87 for (Int_t i = 0;i<fNCuts;i++)
88 {
89 delete fCuts[i];
90 }
91 delete []fCuts;
92}
93/******************************************************************/
94
cea0a066 95Bool_t AliAODParticleCut::Rejected(AliVAODParticle* p) const
a5556ea5 96{
97//method checks all the cuts that are set (in the list)
98//If any of the baseCuts rejects particle False(rejection) is returned
99
100 if(!p)
101 {
cea0a066 102 Warning("Rejected()","No Pasaran! We never accept NULL pointers");
a5556ea5 103 return kTRUE;
104 }
105 if( (p->GetPdgCode() != fPID) && ( fPID != 0)) return kTRUE;
106
107 for (Int_t i = 0;i<fNCuts;i++)
108 {
cea0a066 109 if ( (fCuts[i]->Rejected(p)) )
a5556ea5 110 {
111// fCuts[i]->Print();
112 return kTRUE; //if one of the cuts rejects, then reject
113 }
114 }
115 return kFALSE;
116}
117/******************************************************************/
118
b4fb427e 119void AliAODParticleCut::AddBasePartCut(AliAODParticleBaseCut* basecut)
a5556ea5 120{
121 //adds the base pair cut (cut on one value)
122
123 if (!basecut) return;
124 if( fNCuts == (fgkMaxCuts-1) )
125 {
126 Warning("AddBasePartCut","Not enough place for another cut");
127 return;
128 }
129 fCuts[fNCuts++]=basecut;
130
131}
132
133/******************************************************************/
f9f11a4b 134AliAODParticleBaseCut* AliAODParticleCut::FindCut(AliAODParticleBaseCut::EAODCutProperty property)
a5556ea5 135{
136 //returns pointer to the cut checking the given property
137 for (Int_t i = 0;i<fNCuts;i++)
138 {
139 if (fCuts[i]->GetProperty() == property)
140 return fCuts[i]; //we found the cut we were searching for
141 }
142
143 return 0x0; //we did not found this cut
144
145}
146/******************************************************************/
147
148void AliAODParticleCut::SetMomentumRange(Double_t min, Double_t max)
149{
150 //Sets momentum range
f9f11a4b 151 AliAODMomentumCut* cut= (AliAODMomentumCut*)FindCut(AliAODParticleBaseCut::kAODP);
a5556ea5 152 if(cut) cut->SetRange(min,max);
153 else fCuts[fNCuts++] = new AliAODMomentumCut(min,max);
154}
155/******************************************************************/
156
157
158void AliAODParticleCut::SetPtRange(Double_t min, Double_t max)
159{
160 //name self descriptive
f9f11a4b 161 AliAODPtCut* cut= (AliAODPtCut*)FindCut(AliAODParticleBaseCut::kAODPt);
a5556ea5 162 if(cut) cut->SetRange(min,max);
163 else fCuts[fNCuts++] = new AliAODPtCut(min,max);
164
165}
166/******************************************************************/
167
168void AliAODParticleCut::SetEnergyRange(Double_t min, Double_t max)
169{
170 //name self descriptive
f9f11a4b 171 AliAODEnergyCut* cut= (AliAODEnergyCut*)FindCut(AliAODParticleBaseCut::kAODE);
a5556ea5 172 if(cut) cut->SetRange(min,max);
173 else fCuts[fNCuts++] = new AliAODEnergyCut(min,max);
174
175}
176/******************************************************************/
177
178void AliAODParticleCut::SetRapidityRange(Double_t min, Double_t max)
179{
180 //name self descriptive
f9f11a4b 181 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODRapidity);
a5556ea5 182 if(cut) cut->SetRange(min,max);
183 else fCuts[fNCuts++] = new AliAODRapidityCut(min,max);
184
185}
186/******************************************************************/
187
188void AliAODParticleCut::SetPseudoRapidityRange(Double_t min, Double_t max)
189{
190 //name self descriptive
f9f11a4b 191 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPseudoRapidity);
a5556ea5 192 if(cut) cut->SetRange(min,max);
193 else fCuts[fNCuts++] = new AliAODPseudoRapidityCut(min,max);
194
195}
196/******************************************************************/
197
198void AliAODParticleCut::SetPxRange(Double_t min, Double_t max)
199{
200 //name self descriptive
f9f11a4b 201 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPx);
a5556ea5 202 if(cut) cut->SetRange(min,max);
203 else fCuts[fNCuts++] = new AliAODPxCut(min,max);
204}
205/******************************************************************/
206
207void AliAODParticleCut::SetPyRange(Double_t min, Double_t max)
208{
209 //name self descriptive
f9f11a4b 210 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPy);
a5556ea5 211 if(cut) cut->SetRange(min,max);
212 else fCuts[fNCuts++] = new AliAODPyCut(min,max);
213}
214/******************************************************************/
215
216void AliAODParticleCut::SetPzRange(Double_t min, Double_t max)
217{
218 //name self descriptive
f9f11a4b 219 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPz);
a5556ea5 220 if(cut) cut->SetRange(min,max);
221 else fCuts[fNCuts++] = new AliAODPzCut(min,max);
222}
223/******************************************************************/
224
225void AliAODParticleCut::SetPhiRange(Double_t min, Double_t max)
226{
227 //name self descriptive
f9f11a4b 228 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPhi);
a5556ea5 229 if(cut) cut->SetRange(min,max);
230 else fCuts[fNCuts++] = new AliAODPhiCut(min,max);
231}
232/******************************************************************/
233
234void AliAODParticleCut::SetThetaRange(Double_t min, Double_t max)
235{
236 //name self descriptive
f9f11a4b 237 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODTheta);
a5556ea5 238 if(cut) cut->SetRange(min,max);
239 else fCuts[fNCuts++] = new AliAODThetaCut(min,max);
240}
241/******************************************************************/
242
243void AliAODParticleCut::SetVxRange(Double_t min, Double_t max)
244{
245 //name self descriptive
f9f11a4b 246 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODVx);
a5556ea5 247 if(cut) cut->SetRange(min,max);
248 else fCuts[fNCuts++] = new AliAODVxCut(min,max);
249}
250/******************************************************************/
251
252void AliAODParticleCut::SetVyRange(Double_t min, Double_t max)
253{
254 //name self descriptive
f9f11a4b 255 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODVy);
a5556ea5 256 if(cut) cut->SetRange(min,max);
257 else fCuts[fNCuts++] = new AliAODVyCut(min,max);
258}
259/******************************************************************/
260
261void AliAODParticleCut::SetVzRange(Double_t min, Double_t max)
262{
263 //name self descriptive
f9f11a4b 264 AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODVz);
a5556ea5 265 if(cut) cut->SetRange(min,max);
266 else fCuts[fNCuts++] = new AliAODVzCut(min,max);
267}
268
269/******************************************************************/
270void AliAODParticleCut::Streamer(TBuffer &b)
271{
272 // Stream all objects in the array to or from the I/O buffer.
273
274 UInt_t R__s, R__c;
275 if (b.IsReading())
276 {
277 Int_t i;
278 for (i = 0;i<fNCuts;i++) delete fCuts[i];
279 b.ReadVersion(&R__s, &R__c);
280 TObject::Streamer(b);
281 b >> fPID;
282 b >> fNCuts;
283 for (i = 0;i<fNCuts;i++)
284 {
285 b >> fCuts[i];
286 }
287 b.CheckByteCount(R__s, R__c,AliAODParticleCut::IsA());
288 }
289 else
290 {
291 R__c = b.WriteVersion(AliAODParticleCut::IsA(), kTRUE);
292 TObject::Streamer(b);
293 b << fPID;
294 b << fNCuts;
295 for (Int_t i = 0;i<fNCuts;i++)
296 {
297 b << fCuts[i];
298 }
299 b.SetByteCount(R__c, kTRUE);
300 }
301}
302/******************************************************************/
303
201c7e13 304void AliAODParticleCut::Print(const Option_t * /*opt*/) const
a5556ea5 305{
306 //prints all information about the cut to stdout
307 cout<<"Printing AliAODParticleCut, this = "<<this<<endl;
308 cout<<"fPID "<<fPID<<endl;
309 cout<<"fNCuts "<<fNCuts <<endl;
310 for (Int_t i = 0;i<fNCuts;i++)
311 {
312 cout<<" fCuts["<<i<<"] "<<fCuts[i]<<endl<<" ";
313 fCuts[i]->Print();
314 }
315}
316
317/******************************************************************/
318/******************************************************************/
b4fb427e 319ClassImp(AliAODParticleEmptyCut)
f9f11a4b 320
b4fb427e 321void AliAODParticleEmptyCut::Streamer(TBuffer &b)
a5556ea5 322 {
323 //stramer
324 AliAODParticleCut::Streamer(b);
325 }
326/******************************************************************/
327/******************************************************************/
328/******************************************************************/