]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAODParticleCut.cxx
- Fix for a recently introduced bug
[u/mrichter/AliRoot.git] / ANALYSIS / AliAODParticleCut.cxx
1 #include "AliAODParticleCut.h"
2 //__________________________________________________________________________
3 ////////////////////////////////////////////////////////////////////////////
4 //                                                                        //
5 // class AliAODParticleCut                                                //
6 //                                                                        //
7 // Classes for single particle cuts.                                      //
8 // User should use mainly AliAODParticleCut interface methods,            //
9 // eventually EmptyCut which passes all particles.                        //
10 //                                                                        //
11 // There is all interface for setting cuts on all particle properties     //
12 // The main method is Rejected - which returns                            //
13 //         True to reject particle                                        //
14 //         False in case it meets all the criteria of the given cut       //
15 //                                                                        //
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.           //
25 //                                                                        //
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.                     //
29 //                                                                        //
30 // more info: http://aliweb.cern.ch/people/skowron/analyzer/index.html    //
31 // responsible: Piotr Skowronski@cern.ch                                  //
32 //                                                                        //
33 ////////////////////////////////////////////////////////////////////////////
34
35 #include <Riostream.h>
36
37
38 ClassImp(AliAODParticleCut)
39 const Int_t AliAODParticleCut::fgkMaxCuts = 50;
40 /******************************************************************/
41
42 AliAODParticleCut::AliAODParticleCut():
43  fCuts(new AliAODParticleBaseCut* [fgkMaxCuts]),//last property in the property enum => defines number of properties
44  fNCuts(0),
45  fPID(0)
46 {
47   //default ctor
48 }
49 /******************************************************************/
50
51 AliAODParticleCut::AliAODParticleCut(const AliAODParticleCut& in):
52   TObject(in),
53   fCuts(new AliAODParticleBaseCut* [fgkMaxCuts]),//last property in the property
54                                                  //property enum => defines number of properties
55   fNCuts(in.fNCuts),
56   fPID(in.fPID)
57 {
58   //cpy ctor
59   for (Int_t i = 0;i<fNCuts;i++)
60    {
61      fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
62    }
63 }
64 /******************************************************************/
65 AliAODParticleCut& 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    {
78      fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
79    }
80   return *this;
81 }    
82
83 /******************************************************************/
84 AliAODParticleCut::~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
95 Bool_t AliAODParticleCut::Rejected(AliVAODParticle* p) const
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   {
102     Warning("Rejected()","No Pasaran! We never accept NULL pointers");
103     return kTRUE;
104   }
105  if( (p->GetPdgCode() != fPID) && ( fPID != 0)) return kTRUE;
106  
107  for (Int_t i = 0;i<fNCuts;i++)
108    {
109     if ( (fCuts[i]->Rejected(p)) )
110      {
111 //       fCuts[i]->Print();
112        return kTRUE; //if one of the cuts rejects, then reject
113      }
114    }
115   return kFALSE;
116 }
117 /******************************************************************/
118
119 void AliAODParticleCut::AddBasePartCut(AliAODParticleBaseCut* basecut)
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 /******************************************************************/
134 AliAODParticleBaseCut* AliAODParticleCut::FindCut(AliAODParticleBaseCut::EAODCutProperty property)
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
148 void AliAODParticleCut::SetMomentumRange(Double_t min, Double_t max)
149 {
150   //Sets momentum range
151   AliAODMomentumCut* cut= (AliAODMomentumCut*)FindCut(AliAODParticleBaseCut::kAODP);
152   if(cut) cut->SetRange(min,max);
153   else fCuts[fNCuts++] = new AliAODMomentumCut(min,max);
154 }
155 /******************************************************************/
156
157
158 void AliAODParticleCut::SetPtRange(Double_t min, Double_t max)
159 {
160   //name self descriptive
161   AliAODPtCut* cut= (AliAODPtCut*)FindCut(AliAODParticleBaseCut::kAODPt);
162   if(cut) cut->SetRange(min,max);
163   else fCuts[fNCuts++] = new AliAODPtCut(min,max);
164
165 }
166 /******************************************************************/
167
168 void AliAODParticleCut::SetEnergyRange(Double_t min, Double_t max)
169 {
170   //name self descriptive
171   AliAODEnergyCut* cut= (AliAODEnergyCut*)FindCut(AliAODParticleBaseCut::kAODE);
172   if(cut) cut->SetRange(min,max);
173   else fCuts[fNCuts++] = new AliAODEnergyCut(min,max);
174  
175 }
176 /******************************************************************/
177
178 void AliAODParticleCut::SetRapidityRange(Double_t min, Double_t max)
179 {
180   //name self descriptive
181   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODRapidity);
182   if(cut) cut->SetRange(min,max);
183   else fCuts[fNCuts++] = new AliAODRapidityCut(min,max);
184
185 }
186 /******************************************************************/
187
188 void AliAODParticleCut::SetPseudoRapidityRange(Double_t min, Double_t max)
189 {
190   //name self descriptive
191   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPseudoRapidity);
192   if(cut) cut->SetRange(min,max);
193   else fCuts[fNCuts++] = new AliAODPseudoRapidityCut(min,max);
194  
195 }
196 /******************************************************************/
197
198 void AliAODParticleCut::SetPxRange(Double_t min, Double_t max)
199 {
200   //name self descriptive
201   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPx);
202   if(cut) cut->SetRange(min,max);
203   else fCuts[fNCuts++] = new AliAODPxCut(min,max);
204 }
205 /******************************************************************/
206
207 void AliAODParticleCut::SetPyRange(Double_t min, Double_t max)
208 {  
209   //name self descriptive
210   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPy);
211   if(cut) cut->SetRange(min,max);
212   else fCuts[fNCuts++] = new AliAODPyCut(min,max);
213 }
214 /******************************************************************/
215
216 void AliAODParticleCut::SetPzRange(Double_t min, Double_t max)
217 {
218   //name self descriptive
219   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPz);
220   if(cut) cut->SetRange(min,max);
221   else fCuts[fNCuts++] = new AliAODPzCut(min,max);
222 }
223 /******************************************************************/
224
225 void AliAODParticleCut::SetPhiRange(Double_t min, Double_t max)
226 {
227   //name self descriptive
228   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODPhi);
229   if(cut) cut->SetRange(min,max);
230   else fCuts[fNCuts++] = new AliAODPhiCut(min,max);
231 }
232 /******************************************************************/
233
234 void AliAODParticleCut::SetThetaRange(Double_t min, Double_t max)
235 {
236   //name self descriptive
237   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODTheta);
238   if(cut) cut->SetRange(min,max);
239   else fCuts[fNCuts++] = new AliAODThetaCut(min,max);
240 }
241 /******************************************************************/
242
243 void AliAODParticleCut::SetVxRange(Double_t min, Double_t max)
244 {
245   //name self descriptive
246   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODVx);
247   if(cut) cut->SetRange(min,max);
248   else fCuts[fNCuts++] = new AliAODVxCut(min,max);
249 }
250 /******************************************************************/
251
252 void AliAODParticleCut::SetVyRange(Double_t min, Double_t max)
253 {
254   //name self descriptive
255   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODVy);
256   if(cut) cut->SetRange(min,max);
257   else fCuts[fNCuts++] = new AliAODVyCut(min,max);
258 }
259 /******************************************************************/
260
261 void AliAODParticleCut::SetVzRange(Double_t min, Double_t max)
262 {
263   //name self descriptive
264   AliAODParticleBaseCut* cut = FindCut(AliAODParticleBaseCut::kAODVz);
265   if(cut) cut->SetRange(min,max);
266   else fCuts[fNCuts++] = new AliAODVzCut(min,max);
267 }
268
269 /******************************************************************/
270 void 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
304 void AliAODParticleCut::Print(const Option_t * /*opt*/) const
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 /******************************************************************/
319 ClassImp(AliAODParticleEmptyCut)
320
321 void AliAODParticleEmptyCut::Streamer(TBuffer &b)
322  {
323   //stramer
324   AliAODParticleCut::Streamer(b);
325  }
326 /******************************************************************/
327 /******************************************************************/
328 /******************************************************************/