]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTPairCut.cxx
c0486a62858b6caeddc0bc42c5845e474abf07a8
[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 AliHbtBasePairCut* AliHBTPairCut::FindCut(AliHBTPairCutProperty property)
257 {
258   // Find the cut corresponding to "property"
259   for (Int_t i = 0;i<fNCuts;i++)
260     {
261       if (fCuts[i]->GetProperty() == property) 
262         return fCuts[i]; //we found the cut we were searching for
263     }
264   
265   return 0x0; //we did not found this cut
266   
267 }
268 /**********************************************************/
269
270 void AliHBTPairCut::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       Version_t v = b.ReadVersion(&R__s, &R__c);
278       if (v > -1)
279        {
280           delete fFirstPartCut;
281           delete fSecondPartCut;
282           fFirstPartCut = 0x0;
283           fSecondPartCut = 0x0;
284           TObject::Streamer(b);
285           b >> fFirstPartCut;
286           b >> fSecondPartCut;
287           b >> fNCuts;
288           for (Int_t i = 0;i<fNCuts;i++)
289            {
290              b >> fCuts[i];
291            }
292         }
293       b.CheckByteCount(R__s, R__c,AliHBTPairCut::IsA());
294     } 
295   else 
296     {
297       R__c = b.WriteVersion(AliHBTPairCut::IsA(), kTRUE);
298       TObject::Streamer(b);
299       
300 //      printf("Streamer Cut 1 %#x Cut 2 %#x\n",fFirstPartCut,fSecondPartCut);
301 //      this->Dump();
302 //      fFirstPartCut->Dump();
303       
304       b << fFirstPartCut;
305       b << fSecondPartCut;
306       b << fNCuts;
307       for (Int_t i = 0;i<fNCuts;i++)
308         {
309           b << fCuts[i];
310         }
311       b.SetByteCount(R__c, kTRUE);
312     }
313 }
314 /******************************************************************/
315
316 ClassImp(AliHBTEmptyPairCut)
317   
318 void AliHBTEmptyPairCut::Streamer(TBuffer &b)
319 {
320 //streamer for empty pair cut
321   AliHBTPairCut::Streamer(b);
322 }
323 /******************************************************************/
324
325 ClassImp(AliHbtBasePairCut)
326 ClassImp(AliHBTQInvCut)
327 ClassImp(AliHBTKtCut)
328 ClassImp(AliHBTQSideCMSLCCut)
329 ClassImp(AliHBTQOutCMSLCCut)
330 ClassImp(AliHBTQLongCMSLCCut)
331
332 /******************************************************************/
333 ClassImp(AliHBTAvSeparationCut)
334     
335 Double_t AliHBTAvSeparationCut::GetValue(AliHBTPair* pair) const 
336 {
337   //chacks if avarage distance of two tracks is in given range
338   AliHBTTrackPoints* tpts1 = pair->Particle1()->GetTrackPoints();
339   if ( tpts1 == 0x0)
340    {//it could be simulated pair
341 //     Warning("GetValue","Track 1 does not have Track Points. Pair NOT Passed.");
342      return -1.0;
343    }
344
345   AliHBTTrackPoints* tpts2 = pair->Particle2()->GetTrackPoints();
346   if ( tpts2 == 0x0)
347    {
348 //     Warning("GetValue","Track 2 does not have Track Points. Pair NOT Passed.");
349      return -1.0;
350    }
351    
352   return tpts1->AvarageDistance(*tpts2);
353 }
354 /******************************************************************/
355
356 ClassImp(AliHBTCluterOverlapCut)
357
358 Double_t  AliHBTCluterOverlapCut::GetValue(AliHBTPair* pair) const
359 {
360   //Returns Cluter Overlap Factor
361   //It ranges between -0.5 (in all padrows both tracks have cluters) 
362   // and 1 (in all padrows one track has cluter and second has not)
363   // When Overlap Factor is 1 this pair of tracks in highly probable to be
364   // splitted track: one particle that is recontructed twise
365
366   AliHBTClusterMap* cm1 = pair->Particle1()->GetClusterMap();
367   if ( cm1 == 0x0)
368    {
369      Warning("GetValue","Track 1 does not have Cluster Map. Returning -0.5.");
370      return -.5;
371    }
372
373   AliHBTClusterMap* cm2 = pair->Particle2()->GetClusterMap();
374   if ( cm2 == 0x0)
375    {
376      Warning("GetValue","Track 2 does not have Cluster Map. Returning -0.5.");
377      return -.5;
378    }
379   return cm1->GetOverlapFactor(*cm2);
380 }
381 /******************************************************************/
382
383 ClassImp( AliHBTLogicalOperPairCut )
384
385 AliHBTLogicalOperPairCut::AliHBTLogicalOperPairCut():
386  AliHbtBasePairCut(-10e10,10e10,kHbtPairCutPropNone),
387  fFirst(new AliHBTDummyBasePairCut),
388  fSecond(new AliHBTDummyBasePairCut)
389 {
390  //ctor
391 }
392 /******************************************************************/
393
394 AliHBTLogicalOperPairCut::AliHBTLogicalOperPairCut(AliHbtBasePairCut* first, AliHbtBasePairCut* second):
395  AliHbtBasePairCut(-10e10,10e10,kHbtPairCutPropNone),
396  fFirst((first)?(AliHbtBasePairCut*)first->Clone():0x0),
397  fSecond((second)?(AliHbtBasePairCut*)second->Clone():0x0)
398 {
399   //ctor
400   //note that base cuts are copied, not just pointers assigned
401   if ( (fFirst && fSecond) == kFALSE) 
402    {
403      Fatal("AliHBTLogicalOperPairCut","One of parameters is NULL!");
404    }
405 }
406 /******************************************************************/
407
408 AliHBTLogicalOperPairCut::~AliHBTLogicalOperPairCut()
409 {
410   //destructor
411   delete fFirst;
412   delete fSecond;
413 }
414 /******************************************************************/
415
416 Bool_t AliHBTLogicalOperPairCut::AliHBTDummyBasePairCut::Pass(AliHBTPair* /*pair*/)  const
417 {
418   //checks if particles passes properties defined by this cut
419   Warning("Pass","You are using dummy base cut! Probobly some logical cut is not set up properly");
420   return kFALSE;//accept
421 }
422 /******************************************************************/
423
424 void AliHBTLogicalOperPairCut::Streamer(TBuffer &b)
425 {
426   // Stream all objects in the array to or from the I/O buffer.
427   UInt_t R__s, R__c;
428   if (b.IsReading()) 
429    {
430      delete fFirst;
431      delete fSecond;
432      fFirst  = 0x0;
433      fSecond = 0x0;
434
435      b.ReadVersion(&R__s, &R__c);
436      TObject::Streamer(b);
437      b >> fFirst;
438      b >> fSecond;
439      b.CheckByteCount(R__s, R__c,AliHBTLogicalOperPairCut::IsA());
440    } 
441   else 
442    {
443      R__c = b.WriteVersion(AliHBTLogicalOperPairCut::IsA(), kTRUE);
444      TObject::Streamer(b);
445      b << fFirst;
446      b << fSecond;
447      b.SetByteCount(R__c, kTRUE);
448   }
449 }
450
451 /******************************************************************/
452 ClassImp(AliHBTOrPairCut)
453
454 Bool_t AliHBTOrPairCut::Pass(AliHBTPair * p) const
455 {
456   //returns true when rejected 
457   //AND operation is a little bit misleading but is correct
458   //User wants to build logical cuts with natural (positive) logic
459   //while HBTAN use inernally reverse (returns true when rejected)
460   if (fFirst->Pass(p) && fSecond->Pass(p) ) return kTRUE;//rejected (both rejected, returned kTRUE)
461   return kFALSE;//accepted, at least one accepted (returned kFALSE)
462 }
463 /******************************************************************/
464
465 ClassImp(AliHBTAndPairCut)
466
467 Bool_t AliHBTAndPairCut::Pass(AliHBTPair * p)  const
468 {
469   //returns true when rejected 
470   //OR operation is a little bit misleading but is correct
471   //User wants to build logical cuts with natural (positive) logic
472   //while HBTAN use inernally reverse (returns true when rejected)
473   if (fFirst->Pass(p) || fSecond->Pass(p)) return kTRUE;//rejected (any of two rejected(returned kTRUE) )
474   return kFALSE;//accepted (both accepted (returned kFALSE))
475 }
476 /******************************************************************/