]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliAODParticleCut.cxx
Few basic event cuts developed, coding conventions corrected
[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 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   //
20 // responsible: Piotr Skowronski@cern.ch                                   //
21 //                                                                        //
22 ////////////////////////////////////////////////////////////////////////////
23
24 #include <Riostream.h>
25
26
27 ClassImp(AliAODParticleCut)
28 const Int_t AliAODParticleCut::fgkMaxCuts = 50;
29 /******************************************************************/
30
31 AliAODParticleCut::AliAODParticleCut():
32  fCuts(new AliAODParticleBaseCut* [fgkMaxCuts]),//last property in the property enum => defines number of properties
33  fNCuts(0),
34  fPID(0)
35 {
36   //default ctor
37 }
38 /******************************************************************/
39
40 AliAODParticleCut::AliAODParticleCut(const AliAODParticleCut& in):
41  TObject(in)
42 {
43   //cpy ctor
44   fCuts = new AliAODParticleBaseCut* [fgkMaxCuts];//last property in the property
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    {
50      fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
51    }
52 }
53 /******************************************************************/
54 AliAODParticleCut& 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    {
67      fCuts[i] = (AliAODParticleBaseCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
68    }
69   return *this;
70 }    
71
72 /******************************************************************/
73 AliAODParticleCut::~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
84 Bool_t AliAODParticleCut::Pass(AliVAODParticle* p) const
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
108 void AliAODParticleCut::AddBasePartCut(AliAODParticleBaseCut* basecut)
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 /******************************************************************/
123 AliAODParticleBaseCut* AliAODParticleCut::FindCut(EAODCutProperty property)
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
137 void 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
147 void 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
157 void 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
167 void AliAODParticleCut::SetRapidityRange(Double_t min, Double_t max)
168 {
169   //name self descriptive
170   AliAODParticleBaseCut* cut = FindCut(kAODRapidity);
171   if(cut) cut->SetRange(min,max);
172   else fCuts[fNCuts++] = new AliAODRapidityCut(min,max);
173
174 }
175 /******************************************************************/
176
177 void AliAODParticleCut::SetPseudoRapidityRange(Double_t min, Double_t max)
178 {
179   //name self descriptive
180   AliAODParticleBaseCut* cut = FindCut(kAODPseudoRapidity);
181   if(cut) cut->SetRange(min,max);
182   else fCuts[fNCuts++] = new AliAODPseudoRapidityCut(min,max);
183  
184 }
185 /******************************************************************/
186
187 void AliAODParticleCut::SetPxRange(Double_t min, Double_t max)
188 {
189   //name self descriptive
190   AliAODParticleBaseCut* cut = FindCut(kAODPx);
191   if(cut) cut->SetRange(min,max);
192   else fCuts[fNCuts++] = new AliAODPxCut(min,max);
193 }
194 /******************************************************************/
195
196 void AliAODParticleCut::SetPyRange(Double_t min, Double_t max)
197 {  
198   //name self descriptive
199   AliAODParticleBaseCut* cut = FindCut(kAODPy);
200   if(cut) cut->SetRange(min,max);
201   else fCuts[fNCuts++] = new AliAODPyCut(min,max);
202 }
203 /******************************************************************/
204
205 void AliAODParticleCut::SetPzRange(Double_t min, Double_t max)
206 {
207   //name self descriptive
208   AliAODParticleBaseCut* cut = FindCut(kAODPz);
209   if(cut) cut->SetRange(min,max);
210   else fCuts[fNCuts++] = new AliAODPzCut(min,max);
211 }
212 /******************************************************************/
213
214 void AliAODParticleCut::SetPhiRange(Double_t min, Double_t max)
215 {
216   //name self descriptive
217   AliAODParticleBaseCut* cut = FindCut(kAODPhi);
218   if(cut) cut->SetRange(min,max);
219   else fCuts[fNCuts++] = new AliAODPhiCut(min,max);
220 }
221 /******************************************************************/
222
223 void AliAODParticleCut::SetThetaRange(Double_t min, Double_t max)
224 {
225   //name self descriptive
226   AliAODParticleBaseCut* cut = FindCut(kAODTheta);
227   if(cut) cut->SetRange(min,max);
228   else fCuts[fNCuts++] = new AliAODThetaCut(min,max);
229 }
230 /******************************************************************/
231
232 void AliAODParticleCut::SetVxRange(Double_t min, Double_t max)
233 {
234   //name self descriptive
235   AliAODParticleBaseCut* cut = FindCut(kAODVx);
236   if(cut) cut->SetRange(min,max);
237   else fCuts[fNCuts++] = new AliAODVxCut(min,max);
238 }
239 /******************************************************************/
240
241 void AliAODParticleCut::SetVyRange(Double_t min, Double_t max)
242 {
243   //name self descriptive
244   AliAODParticleBaseCut* cut = FindCut(kAODVy);
245   if(cut) cut->SetRange(min,max);
246   else fCuts[fNCuts++] = new AliAODVyCut(min,max);
247 }
248 /******************************************************************/
249
250 void AliAODParticleCut::SetVzRange(Double_t min, Double_t max)
251 {
252   //name self descriptive
253   AliAODParticleBaseCut* cut = FindCut(kAODVz);
254   if(cut) cut->SetRange(min,max);
255   else fCuts[fNCuts++] = new AliAODVzCut(min,max);
256 }
257
258 /******************************************************************/
259 void 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
293 void 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
309 ClassImp(AliAODParticleEmptyCut)
310 void AliAODParticleEmptyCut::Streamer(TBuffer &b)
311  {
312   //stramer
313   AliAODParticleCut::Streamer(b);
314  }
315 /******************************************************************/
316 /******************************************************************/
317 /******************************************************************/
318
319 /******************************************************************/
320 /******************************************************************/
321 /******************************************************************/
322
323 ClassImp(AliAODParticleBaseCut)
324 void AliAODParticleBaseCut::Print(void) const
325 {
326   // prints the information anout the base cut to stdout
327   cout<<"fMin="<<fMin <<", fMax=" <<fMax<<"    ";
328   PrintProperty();
329 }
330 /******************************************************************/
331
332 void AliAODParticleBaseCut::PrintProperty(void) const
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 }
372 ClassImp( AliAODMomentumCut )
373
374 ClassImp( AliAODPtCut )
375 ClassImp( AliAODEnergyCut )
376 ClassImp( AliAODRapidityCut )
377 ClassImp( AliAODPseudoRapidityCut )
378 ClassImp( AliAODPxCut )
379 ClassImp( AliAODPyCut )
380 ClassImp( AliAODPzCut )
381 ClassImp( AliAODPhiCut )
382 ClassImp( AliAODThetaCut )
383 ClassImp( AliAODVxCut )
384 ClassImp( AliAODVyCut )
385 ClassImp( AliAODVzCut )
386
387 ClassImp( AliAODPIDCut )
388
389 void AliAODPIDCut::Print(void) const
390 {
391   cout<<"PID "<<fPID<<" ";
392   AliAODParticleBaseCut::Print();
393 }
394
395 ClassImp( AliAODLogicalOperCut )
396
397 AliAODLogicalOperCut::AliAODLogicalOperCut():
398  AliAODParticleBaseCut(-10e10,10e10,kAODNone),
399  fFirst(new AliAODDummyBaseCut),
400  fSecond(new AliAODDummyBaseCut)
401 {
402  //ctor
403 }
404 /******************************************************************/
405
406 AliAODLogicalOperCut::AliAODLogicalOperCut(AliAODParticleBaseCut* first, AliAODParticleBaseCut* second):
407  AliAODParticleBaseCut(-10e10,10e10,kAODNone),
408  fFirst((first)?(AliAODParticleBaseCut*)first->Clone():0x0),
409  fSecond((second)?(AliAODParticleBaseCut*)second->Clone():0x0)
410 {
411   //ctor
412   if ( (fFirst && fSecond) == kFALSE) 
413    {
414      Fatal("AliAODLogicalOperCut","One of parameters is NULL!");
415    }
416 }
417 /******************************************************************/
418
419 AliAODLogicalOperCut::~AliAODLogicalOperCut()
420 {
421   //destructor
422   delete fFirst;
423   delete fSecond;
424 }
425 /******************************************************************/
426
427 Bool_t AliAODLogicalOperCut::AliAODDummyBaseCut::Pass(AliVAODParticle* /*part*/)  const
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
435 void 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 /******************************************************************/
463 ClassImp(AliAODOrCut)
464
465 Bool_t AliAODOrCut::Pass(AliVAODParticle * p) const
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
476 ClassImp(AliAODAndCut)
477
478 Bool_t AliAODAndCut::Pass(AliVAODParticle * p)  const
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 /******************************************************************/