]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTPairCut.cxx
Bug correction
[u/mrichter/AliRoot.git] / HBTAN / AliHBTPairCut.cxx
1 /* $Id$ */
2 //____________________________________
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Class AliHBTPairCut:
6 //
7 // implements cut on the pair of particles
8 // more info: http://alisoft.cern.ch/people/skowron/analyzer/index.html
9 // Author: Piotr.Skowronski@cern.ch
10 //-------------------------------------------------------------------
11
12 #include "AliHBTPairCut.h"
13 #include "AliHBTPair.h"
14 #include "AliHBTParticleCut.h"
15 #include "AliHBTTrackPoints.h"
16 #include "AliHBTClusterMap.h"
17
18 ClassImp(AliHBTPairCut)
19 const Int_t AliHBTPairCut::fgkMaxCuts = 50;
20 /**********************************************************/
21
22 AliHBTPairCut::AliHBTPairCut():
23   fNCuts(0)
24 {
25   //constructor
26   fFirstPartCut = new AliHBTEmptyParticleCut(); //empty cuts
27   fSecondPartCut= new AliHBTEmptyParticleCut(); //empty cuts
28     
29   fCuts = new AliHbtBasePairCut*[fgkMaxCuts];
30 }
31 /**********************************************************/
32
33 AliHBTPairCut::AliHBTPairCut(const AliHBTPairCut& in):
34  TNamed(in)
35 {
36   //copy constructor
37   fCuts = new AliHbtBasePairCut*[fgkMaxCuts];
38   fNCuts = in.fNCuts;
39
40   fFirstPartCut = (AliHBTParticleCut*)in.fFirstPartCut->Clone();
41   fSecondPartCut = (AliHBTParticleCut*)in.fSecondPartCut->Clone();
42  
43   for (Int_t i = 0;i<fNCuts;i++)
44     {
45       fCuts[i] = (AliHbtBasePairCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
46     }
47 }
48 /**********************************************************/
49
50 AliHBTPairCut&  AliHBTPairCut::operator=(const AliHBTPairCut& in)
51 {
52   //assignment operator
53   fCuts = new AliHbtBasePairCut*[fgkMaxCuts];
54   fNCuts = in.fNCuts;
55
56   fFirstPartCut = (AliHBTParticleCut*)in.fFirstPartCut->Clone();
57   fSecondPartCut = (AliHBTParticleCut*)in.fSecondPartCut->Clone();
58  
59   for (Int_t i = 0;i<fNCuts;i++)
60     {
61       fCuts[i] = (AliHbtBasePairCut*)in.fCuts[i]->Clone();//create new object (clone) and rember pointer to it
62     }
63   return * this;
64 }
65 /**********************************************************/
66
67 AliHBTPairCut::~AliHBTPairCut()
68 {
69   //destructor
70   if (fFirstPartCut != fSecondPartCut)
71     {
72       delete fSecondPartCut;
73     }
74   delete fFirstPartCut;
75   for (Int_t i = 0;i<fNCuts;i++)
76     {
77       delete fCuts[i];
78     }
79   delete []fCuts;
80
81 /**********************************************************/
82
83 /**********************************************************/
84
85 void AliHBTPairCut::AddBasePairCut(AliHbtBasePairCut* basecut)
86 {
87   //adds the base pair cut (cut on one value)
88   
89   if (!basecut) return;
90   if( fNCuts == (fgkMaxCuts-1) )
91     {
92       Warning("AddBasePairCut","Not enough place for another cut");
93       return;
94     }
95   fCuts[fNCuts++]=basecut;
96 }
97 /**********************************************************/
98
99 Bool_t AliHBTPairCut::Pass(AliHBTPair* pair) const
100 {
101   //methods which checks if given pair meets all criteria of the cut
102   //if it meets returns FALSE
103   //if NOT   returns    TRUE
104   if(!pair) 
105     {
106       Warning("Pass","No Pasaran! We never accept NULL pointers");
107       return kTRUE;
108     }
109   
110   //check particle's cuts
111   if( ( fFirstPartCut->Pass( pair->Particle1()) ) || 
112       ( fSecondPartCut->Pass(pair->Particle2()) )   )
113     {  
114       return kTRUE;
115     }
116   return PassPairProp(pair);
117 }
118 /**********************************************************/
119
120 Bool_t AliHBTPairCut::PassPairProp(AliHBTPair* pair) const
121 {
122   //methods which checks if given pair meets all criteria of the cut
123   //if it meets returns FALSE
124   //if NOT   returns    TRUE
125   //examine all base pair cuts
126   for (Int_t i = 0;i<fNCuts;i++)
127     {
128       if ( (fCuts[i]->Pass(pair)) ) return kTRUE; //if one of the cuts reject, then reject
129     }
130   return kFALSE;
131 }
132 /**********************************************************/
133
134 void AliHBTPairCut::SetFirstPartCut(AliHBTParticleCut* cut)
135 {
136   // set cut for the first particle
137   if(!cut) 
138     {
139       Error("SetFirstPartCut","argument is NULL");
140       return;
141     }
142   delete fFirstPartCut;
143   fFirstPartCut = (AliHBTParticleCut*)cut->Clone();
144   
145 }
146 /**********************************************************/
147
148 void AliHBTPairCut::SetSecondPartCut(AliHBTParticleCut* cut)
149 {
150   // set cut for the second particle
151   if(!cut) 
152     {
153       Error("SetSecondPartCut","argument is NULL");
154       return;
155     }
156   delete fSecondPartCut;
157   fSecondPartCut = (AliHBTParticleCut*)cut->Clone();
158 }
159 /**********************************************************/
160
161 void AliHBTPairCut::SetPartCut(AliHBTParticleCut* cut)
162 {
163   //sets the the same cut on both particles
164   if(!cut) 
165     {
166       Error("SetFirstPartCut","argument is NULL");
167       return;
168     }
169   if (fFirstPartCut == fSecondPartCut) fSecondPartCut = 0x0;
170   
171   delete fFirstPartCut;
172   fFirstPartCut = (AliHBTParticleCut*)cut->Clone();
173   
174   delete fSecondPartCut; //even if null should not be harmful
175   fSecondPartCut = fFirstPartCut;
176 }
177 /**********************************************************/
178
179 void AliHBTPairCut::SetQInvRange(Double_t min, Double_t max)
180 {
181   // set range of accepted invariant masses
182   AliHBTQInvCut* cut= (AliHBTQInvCut*)FindCut(kHbtPairCutPropQInv);
183   if(cut) cut->SetRange(min,max);
184   else fCuts[fNCuts++] = new AliHBTQInvCut(min,max);
185 }
186 /**********************************************************/
187 void AliHBTPairCut::SetQOutCMSLRange(Double_t min, Double_t max)
188 {
189   // set range of accepted QOut in CMS
190   AliHBTQOutCMSLCCut* cut= (AliHBTQOutCMSLCCut*)FindCut(kHbtPairCutPropQOutCMSLC);
191   if(cut) cut->SetRange(min,max);
192   else fCuts[fNCuts++] = new AliHBTQOutCMSLCCut(min,max);
193 }
194
195 /**********************************************************/
196 void AliHBTPairCut::SetQSideCMSLRange(Double_t min, Double_t max)
197 {
198   // set range of accepted QSide in CMS
199   AliHBTQSideCMSLCCut* cut= (AliHBTQSideCMSLCCut*)FindCut(kHbtPairCutPropQSideCMSLC);
200   if(cut) cut->SetRange(min,max);
201   else fCuts[fNCuts++] = new AliHBTQSideCMSLCCut(min,max);
202 }
203
204 /**********************************************************/
205 void AliHBTPairCut::SetQLongCMSLRange(Double_t min, Double_t max)
206 {
207   // set range of accepted QLong in CMS
208   AliHBTQLongCMSLCCut* cut= (AliHBTQLongCMSLCCut*)FindCut(kHbtPairCutPropQLongCMSLC);
209   if(cut) cut->SetRange(min,max);
210   else fCuts[fNCuts++] = new AliHBTQLongCMSLCCut(min,max);
211 }
212
213 /**********************************************************/
214
215 void AliHBTPairCut::SetKtRange(Double_t min, Double_t max)
216 {
217   // set range of accepted Kt (?)
218   AliHBTKtCut* cut= (AliHBTKtCut*)FindCut(kHbtPairCutPropKt);
219   if(cut) cut->SetRange(min,max);
220   else fCuts[fNCuts++] = new AliHBTKtCut(min,max);
221 }
222 /**********************************************************/
223
224 void AliHBTPairCut::SetKStarRange(Double_t min, Double_t max)
225 {
226   // set range of accepted KStar (?)
227   AliHBTKStarCut* cut= (AliHBTKStarCut*)FindCut(kHbtPairCutPropKStar);
228   if(cut) cut->SetRange(min,max);
229   else fCuts[fNCuts++] = new AliHBTKStarCut(min,max);
230 }
231 /**********************************************************/
232 void AliHBTPairCut::SetAvSeparationRange(Double_t min, Double_t max)
233 {
234   //sets avarage separation cut ->Anti-Merging cut
235   AliHbtBasePairCut* cut= FindCut(kHbtPairCutPropAvSepar);
236   if(cut) cut->SetRange(min,max);
237   else fCuts[fNCuts++] = new AliHBTAvSeparationCut(min,max);
238 }
239 /**********************************************************/
240
241 void AliHBTPairCut::SetClusterOverlapRange(Double_t min,Double_t max)
242 {
243   //sets cluster overlap factor cut ->Anti-Splitting cut
244   //cluster overlap factor ranges between 
245   // -0.5 (in all padrows both tracks have cluters) 
246   // and 1 (in all padrows one track has cluter and second has not)
247   // When Overlap Factor is 1 this pair of tracks in highly probable to be
248   // splitted track: one particle that is recontructed twise
249   // STAR uses range from -0.5 to 0.6 
250   
251   AliHbtBasePairCut* cut= FindCut(kHbtPairCutPropClOverlap);
252   if(cut) cut->SetRange(min,max);
253   else fCuts[fNCuts++] = new AliHBTCluterOverlapCut(min,max);
254 }
255 /**********************************************************/
256
257 AliHbtBasePairCut* AliHBTPairCut::FindCut(AliHBTPairCutProperty property)
258 {
259   // Find the cut corresponding to "property"
260   for (Int_t i = 0;i<fNCuts;i++)
261     {
262       if (fCuts[i]->GetProperty() == property) 
263         return fCuts[i]; //we found the cut we were searching for
264     }
265   
266   return 0x0; //we did not found this cut
267   
268 }
269 /**********************************************************/
270
271 void AliHBTPairCut::Streamer(TBuffer &b)
272 {
273   // Stream all objects in the array to or from the I/O buffer.
274   
275   UInt_t R__s, R__c;
276   if (b.IsReading()) 
277     {
278       Version_t v = b.ReadVersion(&R__s, &R__c);
279       if (v > -1)
280        {
281           delete fFirstPartCut;
282           delete fSecondPartCut;
283           fFirstPartCut = 0x0;
284           fSecondPartCut = 0x0;
285           TObject::Streamer(b);
286           b >> fFirstPartCut;
287           b >> fSecondPartCut;
288           b >> fNCuts;
289           for (Int_t i = 0;i<fNCuts;i++)
290            {
291              b >> fCuts[i];
292            }
293         }
294       b.CheckByteCount(R__s, R__c,AliHBTPairCut::IsA());
295     } 
296   else 
297     {
298       R__c = b.WriteVersion(AliHBTPairCut::IsA(), kTRUE);
299       TObject::Streamer(b);
300       
301 //      printf("Streamer Cut 1 %#x Cut 2 %#x\n",fFirstPartCut,fSecondPartCut);
302 //      this->Dump();
303 //      fFirstPartCut->Dump();
304       
305       b << fFirstPartCut;
306       b << fSecondPartCut;
307       b << fNCuts;
308       for (Int_t i = 0;i<fNCuts;i++)
309         {
310           b << fCuts[i];
311         }
312       b.SetByteCount(R__c, kTRUE);
313     }
314 }
315 /******************************************************************/
316
317 ClassImp(AliHBTEmptyPairCut)
318   
319 void AliHBTEmptyPairCut::Streamer(TBuffer &b)
320 {
321 //streamer for empty pair cut
322   AliHBTPairCut::Streamer(b);
323 }
324 /******************************************************************/
325
326 ClassImp(AliHbtBasePairCut)
327 ClassImp(AliHBTQInvCut)
328 ClassImp(AliHBTKtCut)
329 ClassImp(AliHBTQSideCMSLCCut)
330 ClassImp(AliHBTQOutCMSLCCut)
331 ClassImp(AliHBTQLongCMSLCCut)
332
333 /******************************************************************/
334 ClassImp(AliHBTAvSeparationCut)
335     
336 Double_t AliHBTAvSeparationCut::GetValue(AliHBTPair* pair) const 
337 {
338   //chacks if avarage distance of two tracks is in given range
339   AliHBTTrackPoints* tpts1 = pair->Particle1()->GetTrackPoints();
340   if ( tpts1 == 0x0)
341    {//it could be simulated pair
342 //     Warning("GetValue","Track 1 does not have Track Points. Pair NOT Passed.");
343      return -1.0;
344    }
345
346   AliHBTTrackPoints* tpts2 = pair->Particle2()->GetTrackPoints();
347   if ( tpts2 == 0x0)
348    {
349 //     Warning("GetValue","Track 2 does not have Track Points. Pair NOT Passed.");
350      return -1.0;
351    }
352    
353   return tpts1->AvarageDistance(*tpts2);
354 }
355 /******************************************************************/
356
357 ClassImp(AliHBTCluterOverlapCut)
358
359 Double_t  AliHBTCluterOverlapCut::GetValue(AliHBTPair* pair) const
360 {
361   //Returns Cluter Overlap Factor
362   //It ranges between -0.5 (in all padrows both tracks have cluters) 
363   // and 1 (in all padrows one track has cluter and second has not)
364   // When Overlap Factor is 1 this pair of tracks in highly probable to be
365   // splitted track: one particle that is recontructed twise
366
367   AliHBTClusterMap* cm1 = pair->Particle1()->GetClusterMap();
368   if ( cm1 == 0x0)
369    {
370      Warning("GetValue","Track 1 does not have Cluster Map. Returning -0.5.");
371      return -.5;
372    }
373
374   AliHBTClusterMap* cm2 = pair->Particle2()->GetClusterMap();
375   if ( cm2 == 0x0)
376    {
377      Warning("GetValue","Track 2 does not have Cluster Map. Returning -0.5.");
378      return -.5;
379    }
380   return cm1->GetOverlapFactor(*cm2);
381 }
382 /******************************************************************/
383 ClassImp(AliHBTOutSideSameSignCut)
384
385 Bool_t AliHBTOutSideSameSignCut::Pass(AliHBTPair *p) const
386 {
387   //returns kTRUE if pair DO NOT meet cut criteria
388   
389   if ( p->GetQOutCMSLC()*p->GetQSideCMSLC() > 0 ) 
390    {
391      return kFALSE;//accpeted
392    }
393
394   return kTRUE ;//rejected
395 }
396 /******************************************************************/
397 ClassImp(AliHBTOutSideDiffSignCut)
398
399 Bool_t AliHBTOutSideDiffSignCut::Pass(AliHBTPair *p) const
400 {
401   //returns kTRUE if pair DO NOT meet cut criteria
402   
403   if ( p->GetQOutCMSLC()*p->GetQSideCMSLC() > 0 ) 
404    {
405      return kTRUE;//rejected
406    }
407   
408   return kFALSE;//accepted
409 }
410 /******************************************************************/
411 ClassImp( AliHBTLogicalOperPairCut )
412
413 AliHBTLogicalOperPairCut::AliHBTLogicalOperPairCut():
414  AliHbtBasePairCut(-10e10,10e10,kHbtPairCutPropNone),
415  fFirst(new AliHBTDummyBasePairCut),
416  fSecond(new AliHBTDummyBasePairCut)
417 {
418  //ctor
419 }
420 /******************************************************************/
421
422 AliHBTLogicalOperPairCut::AliHBTLogicalOperPairCut(AliHbtBasePairCut* first, AliHbtBasePairCut* second):
423  AliHbtBasePairCut(-10e10,10e10,kHbtPairCutPropNone),
424  fFirst((first)?(AliHbtBasePairCut*)first->Clone():0x0),
425  fSecond((second)?(AliHbtBasePairCut*)second->Clone():0x0)
426 {
427   //ctor
428   //note that base cuts are copied, not just pointers assigned
429   if ( (fFirst && fSecond) == kFALSE) 
430    {
431      Fatal("AliHBTLogicalOperPairCut","One of parameters is NULL!");
432    }
433 }
434 /******************************************************************/
435
436 AliHBTLogicalOperPairCut::~AliHBTLogicalOperPairCut()
437 {
438   //destructor
439   delete fFirst;
440   delete fSecond;
441 }
442 /******************************************************************/
443
444 Bool_t AliHBTLogicalOperPairCut::AliHBTDummyBasePairCut::Pass(AliHBTPair* /*pair*/)  const
445 {
446   //checks if particles passes properties defined by this cut
447   Warning("Pass","You are using dummy base cut! Probobly some logical cut is not set up properly");
448   return kFALSE;//accept
449 }
450 /******************************************************************/
451
452 void AliHBTLogicalOperPairCut::Streamer(TBuffer &b)
453 {
454   // Stream all objects in the array to or from the I/O buffer.
455   UInt_t R__s, R__c;
456   if (b.IsReading()) 
457    {
458      delete fFirst;
459      delete fSecond;
460      fFirst  = 0x0;
461      fSecond = 0x0;
462
463      b.ReadVersion(&R__s, &R__c);
464      TObject::Streamer(b);
465      b >> fFirst;
466      b >> fSecond;
467      b.CheckByteCount(R__s, R__c,AliHBTLogicalOperPairCut::IsA());
468    } 
469   else 
470    {
471      R__c = b.WriteVersion(AliHBTLogicalOperPairCut::IsA(), kTRUE);
472      TObject::Streamer(b);
473      b << fFirst;
474      b << fSecond;
475      b.SetByteCount(R__c, kTRUE);
476   }
477 }
478
479 /******************************************************************/
480 ClassImp(AliHBTOrPairCut)
481
482 Bool_t AliHBTOrPairCut::Pass(AliHBTPair * p) const
483 {
484   //returns true when rejected 
485   //AND operation is a little bit misleading but is correct
486   //User wants to build logical cuts with natural (positive) logic
487   //while HBTAN use inernally reverse (returns true when rejected)
488   if (fFirst->Pass(p) && fSecond->Pass(p) ) return kTRUE;//rejected (both rejected, returned kTRUE)
489   return kFALSE;//accepted, at least one accepted (returned kFALSE)
490 }
491 /******************************************************************/
492
493 ClassImp(AliHBTAndPairCut)
494
495 Bool_t AliHBTAndPairCut::Pass(AliHBTPair * p)  const
496 {
497   //returns true when rejected 
498   //OR operation is a little bit misleading but is correct
499   //User wants to build logical cuts with natural (positive) logic
500   //while HBTAN use inernally reverse (returns true when rejected)
501   if (fFirst->Pass(p) || fSecond->Pass(p)) return kTRUE;//rejected (any of two rejected(returned kTRUE) )
502   return kFALSE;//accepted (both accepted (returned kFALSE))
503 }
504 /******************************************************************/