]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTFunction.cxx
d7af8240672e72405fb5612dda3702d2980bb16e
[u/mrichter/AliRoot.git] / HBTAN / AliHBTFunction.cxx
1 #include "AliHBTFunction.h"
2
3 /* $Id: */
4
5 //--------------------------------------------------------------------
6 //AliHBTFunction
7 //Author: Piotr Krzysztof Skowronski
8 //Piotr.Skowronski@cern.ch
9 //Base classes for HBT functions
10 /*
11  OnePairFctn       Function                  TwoPairFctn
12    | \    \        /  |   \                      /|\   
13    |  \    \      /   |    \                    / | \    
14    |   \    \   1D   2D    3D                  /  |  \    
15    |    \    \  / \   |\   | \________________/__ |   \             
16    |     \    \/   \  | \__|_____________    /   \|    \             
17    |      \    \    \_|____|__           \  /     |     \            
18    |       \ /  \___  |    |  \           \/      |\     \              
19    |        /       \ |    |   \          /\      | \     \             
20    |       / \       \|    |    \        /  \     |  \     \              
21    |      /   \      /\    |     \      /    \    |   \     |              
22    |     /     \    /  \   |      \    /      \   |    \    |               
23    |    /       \  /    \  |       \  /        \  |     \   |
24    |   /         \/      \ |        \/          \ |      \  |               
25  OnePair1D   OnePair2D  OnePair3D  TwoPair1D  TwoPair2D TwoPair3D
26
27
28  four particle functions are intendent to be resolution functions:
29  it is mecessary to have simulated particle pair corresponding to given
30  recontructed track pair in order to calculate function simualted value 
31  and recontructed value, to be further histogrammed
32 */
33 //--------------------------------------------------------------------- 
34
35 #include <TH2.h>
36 #include <TH3.h>
37
38 /******************************************************************/
39 /******************************************************************/
40
41 ClassImp( AliHBTFunction )
42
43 AliHBTFunction::AliHBTFunction():
44  fPairCut(new AliHBTEmptyPairCut()), //dummy cut  
45  fWriteNumAndDen(kFALSE)
46 {
47 //Default constructor
48 }
49 /******************************************************************/
50
51 AliHBTFunction::AliHBTFunction(const char* name,const char* title):
52  TNamed(name,title),
53  fPairCut(new AliHBTEmptyPairCut()), //dummy cut  
54  fWriteNumAndDen(kFALSE)
55 {
56 //Constructor  
57 }
58 /******************************************************************/
59
60 AliHBTFunction::AliHBTFunction(const AliHBTFunction & source):
61  TNamed(source),
62  fPairCut((AliHBTPairCut*)source.fPairCut->Clone()),
63  fWriteNumAndDen(source.fWriteNumAndDen)
64 {
65 // Copy constructor needed by the coding conventions
66 }
67 /******************************************************************/
68
69 AliHBTFunction::~AliHBTFunction()
70 {
71 //destructor  
72   delete fPairCut;
73 }
74 /******************************************************************/
75 AliHBTFunction & AliHBTFunction::operator= (const AliHBTFunction & source)
76 {
77  // Assignment needed by the coding conventions
78   delete fPairCut;
79   fPairCut = (AliHBTPairCut*)source.fPairCut->Clone();
80   return * this;
81 }
82
83 void AliHBTFunction::WriteFunction()
84 {
85 //writes result of the function to file
86    if (fWriteNumAndDen)
87     { 
88      if (GetNumerator()) GetNumerator()->Write();
89      if (GetDenominator()) GetDenominator()->Write();
90     } 
91    TH1* res = GetResult();
92    if (res) res->Write();
93 }
94 /******************************************************************/
95
96 TH1* AliHBTFunction::GetRatio(Double_t normfactor)
97  {
98  //returns ratio of numerator and denominator
99  //
100    if (AliHBTParticle::GetDebug()>0) Info("GetRatio","Norm. Factor is %f for %s",normfactor,GetName());
101    
102    if (normfactor == 0.0)
103     {
104       Error("GetRatio","Scaling Factor is 0. Null poiner returned");
105       return 0x0;
106     }
107    TString str = fName + " ratio";
108    TH1 *result = (TH1*)GetNumerator()->Clone(str.Data());
109    
110    result->SetTitle(str.Data());
111    
112    result->Divide(GetNumerator(),GetDenominator(),normfactor);
113    
114    return result;
115    
116  }
117 /******************************************************************/
118 void AliHBTFunction::SetPairCut(AliHBTPairCut* cut)
119 {
120 //Sets new Pair Cut. Old one is deleted
121 //Note that it is created new object instead of simple pointer set
122 //I do not want to have pointer 
123 //to object created somewhere else
124 //because in that case I could not believe that 
125 //it would always exist (sb could delete it)
126 //so we have always own copy
127
128  if(!cut) 
129    {
130      Error("AliHBTFunction::SetPairCut","argument is NULL");
131      return;
132    }
133  delete fPairCut;
134  fPairCut = (AliHBTPairCut*)cut->Clone();
135  
136 }
137
138 /******************************************************************/
139
140 void AliHBTFunction::Rename(const Char_t * name)
141  {
142  //renames the function and histograms
143   SetName(name);
144   SetTitle(name);
145   
146   TString numstr = fName + " Numerator";  //title and name of the 
147                                            //numerator histogram
148   TString denstr = fName + " Denominator";//title and name of the 
149                                            //denominator histogram
150  
151   GetNumerator()->SetName(numstr.Data());
152   GetNumerator()->SetTitle(numstr.Data());
153   
154   GetDenominator()->SetName(denstr.Data());
155   GetDenominator()->SetTitle(denstr.Data());
156   
157  }
158
159 void AliHBTFunction::Rename(const Char_t * name, const Char_t * title)
160  {
161  //renames and retitle the function and histograms
162  
163   SetName(name);
164   SetTitle(title);
165   
166   TString numstrn = fName + " Numerator";  //name of the 
167                                            //numerator histogram
168
169   TString numstrt = fTitle + " Numerator";  //title of the 
170                                            //numerator histogram
171                    
172   TString denstrn = fName + " Denominator";//name of the 
173                                            //denominator histogram
174
175   TString denstrt = fTitle + " Denominator";//title of the 
176                                            //denominator histogram
177                    
178  
179   GetNumerator()->SetName(numstrn.Data());
180   GetNumerator()->SetTitle(numstrt.Data());
181   
182   GetDenominator()->SetName(denstrn.Data());
183   GetDenominator()->SetTitle(denstrt.Data());
184
185
186  }
187 /******************************************************************/
188
189 void AliHBTFunction::InitFunction()
190 {
191 //Iniotializes fctn.: Resets histograms
192 //In case histograms are not created in ctor, builds with default parameters
193   if ( !(GetNumerator()&&GetDenominator()) ) BuildHistos();
194   GetNumerator()->Reset();
195   GetDenominator()->Reset();
196 }
197
198 /******************************************************************/
199 /******************************************************************/
200 /******************************************************************/
201
202 ClassImp( AliHBTOnePairFctn )
203
204 /******************************************************************/
205 /******************************************************************/
206 /******************************************************************/
207
208 ClassImp( AliHBTTwoPairFctn)
209
210 /******************************************************************/
211 /******************************************************************/
212 /******************************************************************/
213
214 ClassImp( AliHBTFunction1D )
215
216 const Int_t AliHBTFunction1D::fgkDefaultNBins = 100;
217 const Float_t AliHBTFunction1D::fgkDefaultMin = 0.0;
218 const Float_t AliHBTFunction1D::fgkDefaultMax = 0.15;
219 const UInt_t AliHBTFunction1D::fgkDefaultNBinsToScale = 30;
220
221
222 AliHBTFunction1D::AliHBTFunction1D():
223  fNumerator(0x0),
224  fDenominator(0x0),
225  fNBinsToScale(fgkDefaultNBinsToScale)
226 {//default constructor
227 }
228 /******************************************************************/
229
230 AliHBTFunction1D::AliHBTFunction1D(Int_t nbins, Float_t maxXval, Float_t minXval):
231  fNumerator(0x0),
232  fDenominator(0x0),
233  fNBinsToScale(fgkDefaultNBinsToScale)
234 {
235  //Constructor of Two Part One Dimentional Function 
236  // nbins: number of bins in histograms - default 100
237  // maxXval and minXval: range of histgram(s) default 0 - 0.15 (GeV)
238  BuildHistos(nbins,maxXval,minXval);
239 }
240 /******************************************************************/
241 AliHBTFunction1D::AliHBTFunction1D(const Char_t *name, const Char_t *title):
242  AliHBTFunction(name,title),
243  fNumerator(0x0),
244  fDenominator(0x0),
245  fNBinsToScale(fgkDefaultNBinsToScale)
246 {//constructor
247 }
248 /******************************************************************/
249 AliHBTFunction1D::AliHBTFunction1D(const Char_t *name, const Char_t *title,
250                                    Int_t nbins, Float_t maxXval, Float_t minXval):
251  AliHBTFunction(name,title),
252  fNumerator(0x0),
253  fDenominator(0x0),
254  fNBinsToScale(fgkDefaultNBinsToScale)
255 {
256 //constructor
257   BuildHistos(nbins,maxXval,minXval);
258 }
259 /******************************************************************/
260
261 AliHBTFunction1D::AliHBTFunction1D(const AliHBTFunction1D& source):
262  AliHBTFunction(source)
263 {
264 // Copy constructor needed by the coding conventions byt not used
265   Fatal("AliHBTFunction1D(const AliHBTFunction1D&)","Cpy ctor not usable.");
266 }
267 /******************************************************************/
268
269 AliHBTFunction1D& AliHBTFunction1D::operator= (const AliHBTFunction1D & /*source*/) 
270 {
271 // Assignment needed by the coding conventions byt not used
272   Fatal("Assignment operator","not implemented");
273   return * this;
274  }
275 /******************************************************************/
276
277 AliHBTFunction1D::~AliHBTFunction1D()
278 {
279 //destructor
280   delete fNumerator;
281   delete fDenominator;
282 }
283 /******************************************************************/
284 void AliHBTFunction1D::BuildHistos()
285 {
286 //builds histograms with default settings
287  BuildHistos(fgkDefaultNBins,fgkDefaultMax,fgkDefaultMin);
288 }
289
290 /******************************************************************/
291
292 void AliHBTFunction1D::BuildHistos(Int_t nbins, Float_t max, Float_t min)
293 {
294 //builds numarator and denominator hitograms
295   TString numstr = fName + " Numerator";  //title and name of the 
296                                           //numerator histogram
297   TString denstr = fName + " Denominator";//title and name of the 
298                                           //denominator histogram
299   fNumerator   = new TH1D(numstr.Data(),numstr.Data(),nbins,min,max);
300   fDenominator = new TH1D(denstr.Data(),denstr.Data(),nbins,min,max);
301    
302   fNumerator->Sumw2();
303   fDenominator->Sumw2();
304 }
305 /******************************************************************/
306
307 Double_t AliHBTFunction1D::Scale()
308 {
309  //Calculates the factor that should be used to scale 
310  //quatience of fNumerator and fDenominator to 1 at tail
311  return Scale(fNumerator,fDenominator);
312 }
313 /******************************************************************/
314
315 Double_t AliHBTFunction1D::Scale(TH1D* num,TH1D* den)
316 {
317  //Calculates the factor that should be used to scale 
318  //quatience of num and den to 1 at tail
319  
320   if (AliHBTParticle::GetDebug()>0) Info("Scale","Enetered Scale()");
321   if(!num) 
322    {
323      Error("Scale","No numerator");
324      return 0.0;
325    }
326   if(!den) 
327    {
328      Error("Scale","No denominator");
329      return 0.0;
330    }
331   
332   if(fNBinsToScale < 1) 
333    {
334     Error("Scale","Number of bins for scaling is smaller thnan 1");
335     return 0.0;
336    }
337   UInt_t nbins = num->GetNbinsX();
338   if (fNBinsToScale > nbins) 
339    {
340     Error("Scale","Number of bins for scaling is bigger thnan number of bins in histograms");
341     return 0.0;
342    }
343   if (AliHBTParticle::GetDebug()>0) Info("Scale","No errors detected");
344
345   Double_t ratio;
346   Double_t sum = 0;
347   Int_t n = 0;
348   
349   Int_t offset = nbins - fNBinsToScale - 1; 
350
351   for (UInt_t i = offset; i< nbins; i++)
352    {
353     if ( num->GetBinContent(i) > 0.0 )
354      {
355        ratio = den->GetBinContent(i)/num->GetBinContent(i);
356        sum += ratio;
357        n++;
358      }
359    }
360   
361   if(AliHBTParticle::GetDebug() > 0) Info("Scale","sum=%f fNBinsToScale=%d n=%d",sum,fNBinsToScale,n);
362   
363   if (n == 0) return 0.0;
364   Double_t ret = sum/((Double_t)n);
365
366   if(AliHBTParticle::GetDebug() > 0) Info("Scale","returning %f",ret);
367   return ret;
368
369
370 /******************************************************************/
371 /******************************************************************/
372 /******************************************************************/
373
374 //____________________
375 ///////////////////////////////////////////////////////
376 //                                                   //
377 // AliHBTFunction2D                                  //
378 //                                                   //
379 // Base Calss for 2-dimensinal Functions             //
380 //                                                   //
381 // Piotr.Skowronski@cern.ch                          //
382 // http://alisoft.cern.ch/people/skowron/analyzer    //
383 //                                                   //
384 ///////////////////////////////////////////////////////
385
386 ClassImp( AliHBTFunction2D )
387
388 const Int_t AliHBTFunction2D::fgkDefaultNBinsX = 200;//default number of Bins in X axis in histograms
389 const Float_t AliHBTFunction2D::fgkDefaultMinX = 0.0;//Default min value of X axis in histograms
390 const Float_t AliHBTFunction2D::fgkDefaultMaxX = 1.5;//Default max value of X axis inhistograms
391
392 const Int_t AliHBTFunction2D::fgkDefaultNBinsY = 200;//default number of Bins in histograms
393 const Float_t AliHBTFunction2D::fgkDefaultMinY = -0.15;//Default min value of histograms
394 const Float_t AliHBTFunction2D::fgkDefaultMaxY =  0.15;//Default max value of histograms
395
396 const UInt_t AliHBTFunction2D::fgkDefaultNBinsToScaleX = 30;//Default number of X bins used for scaling to tale
397 const UInt_t AliHBTFunction2D::fgkDefaultNBinsToScaleY = 30;//Default number of bins used for scaling to tale
398
399 /******************************************************************/
400 AliHBTFunction2D::AliHBTFunction2D():
401  fNumerator(0x0),
402  fDenominator(0x0),
403  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
404  fNBinsToScaleY(fgkDefaultNBinsToScaleY)
405 {//default constructor
406 }
407 /******************************************************************/
408 AliHBTFunction2D::AliHBTFunction2D(const Char_t *name, const Char_t *title):
409  AliHBTFunction(name,title),
410  fNumerator(0x0),
411  fDenominator(0x0),
412  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
413  fNBinsToScaleY(fgkDefaultNBinsToScaleY)
414 {//constructor
415 }
416 /******************************************************************/
417
418 AliHBTFunction2D::AliHBTFunction2D(Int_t nXbins, Double_t maxXval, Double_t minXval,
419                                    Int_t nYbins, Double_t maxYval, Double_t minYval):
420  fNumerator(0x0),
421  fDenominator(0x0),
422  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
423  fNBinsToScaleY(fgkDefaultNBinsToScaleY)
424 {
425   BuildHistos(nXbins,maxXval,minXval,nYbins,maxYval,minYval);
426 }         
427 /******************************************************************/
428
429 AliHBTFunction2D::AliHBTFunction2D(const Char_t *name, const Char_t *title,
430                                    Int_t nXbins, Double_t maxXval, Double_t minXval,
431                                    Int_t nYbins, Double_t maxYval, Double_t minYval):
432  AliHBTFunction(name,title),
433  fNumerator(0x0),
434  fDenominator(0x0),
435  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
436  fNBinsToScaleY(fgkDefaultNBinsToScaleY)
437 {
438   BuildHistos(nXbins,maxXval,minXval,nYbins,maxYval,minYval);
439 }         
440 /******************************************************************/
441 AliHBTFunction2D::AliHBTFunction2D(const AliHBTFunction2D & source):
442  AliHBTFunction(source)
443 {
444 // Copy constructor needed by the coding conventions byt not used
445   Fatal("AliHBTFunction2D(const AliHBTFunction2D&)","Cpy ctor not usable.");
446 }
447 /******************************************************************/
448
449 AliHBTFunction2D& AliHBTFunction2D::operator= (const AliHBTFunction2D& /*source*/) {
450 // Assignment needed by the coding conventions byt not used
451   Fatal("Assignment operator","not implemented");
452   return * this;
453 }
454 /******************************************************************/
455
456 AliHBTFunction2D::~AliHBTFunction2D()
457 {
458 //dtor
459   delete fNumerator;
460   delete fDenominator;
461 }
462 /******************************************************************/
463
464 void AliHBTFunction2D::BuildHistos()
465 {
466 //Creates default histograms
467   BuildHistos(fgkDefaultNBinsX,fgkDefaultMaxX,fgkDefaultMinX,
468               fgkDefaultNBinsY,fgkDefaultMaxY,fgkDefaultMinY);
469 }
470 /******************************************************************/
471
472 void AliHBTFunction2D::BuildHistos(Int_t nxbins, Float_t xmax, Float_t xmin,
473                                    Int_t nybins, Float_t ymax, Float_t ymin)
474 {
475 //Builds numerator and denominator histograms (2d-case)
476  TString numstr = fName + " Numerator";  //title and name of the 
477                                            //numerator histogram
478  TString denstr = fName + " Denominator";//title and name of the 
479                                            //denominator histogram
480          
481  fNumerator   = new TH2D(numstr.Data(),numstr.Data(),
482                          nxbins,xmin,xmax,nybins,ymin,ymax);
483                
484  fDenominator = new TH2D(denstr.Data(),denstr.Data(),
485                          nxbins,xmin,xmax,nybins,ymin,ymax);
486  
487  fNumerator->Sumw2();
488  fDenominator->Sumw2();
489 }
490 /******************************************************************/
491
492 void AliHBTFunction2D::SetNumberOfBinsToScale(UInt_t xn, UInt_t yn)
493 {
494 //defines area used for scaling factor calculation
495   fNBinsToScaleX = xn;
496   fNBinsToScaleY = yn;
497 }
498 /******************************************************************/
499
500 Double_t AliHBTFunction2D::Scale()
501 {
502 // Calculates the factor that should be used to scale 
503 // quatience of fNumerator and fDenominator to 1 at 
504 // given region
505   if (AliHBTParticle::GetDebug()>0) Info("Scale","Enetered Scale()");
506   if(!fNumerator) 
507    {
508      Error("Scale","No numerator");
509      return 0.0;
510    }
511   if(!fDenominator) 
512    {
513      Error("Scale","No denominator");
514      return 0.0;
515    }
516   
517   if( (fNBinsToScaleX < 1) || (fNBinsToScaleY < 1) ) 
518    {
519     Error("Scale","Number of bins for scaling is smaller thnan 1");
520     return 0.0;
521    }
522   UInt_t nbinsX = fNumerator->GetNbinsX();
523   if (fNBinsToScaleX > nbinsX) 
524    {
525     Error("Scale","Number of X bins for scaling is bigger thnan number of bins in histograms");
526     return 0.0;
527    }
528    
529   UInt_t nbinsY = fNumerator->GetNbinsX();
530   if (fNBinsToScaleY > nbinsY) 
531    {
532     Error("Scale","Number of Y bins for scaling is bigger thnan number of bins in histograms");
533     return 0.0;
534    }
535
536   if (AliHBTParticle::GetDebug()>0) Info("Scale","No errors detected");
537
538   Int_t offsetX = nbinsX - fNBinsToScaleX - 1; //bin that we start loop over bins in axis X
539   Int_t offsetY = nbinsY - fNBinsToScaleY - 1; //bin that we start loop over bins in axis X
540
541   Double_t ratio;
542   Double_t sum = 0;
543   Int_t n = 0;
544   
545   for (UInt_t j = offsetY; j< nbinsY; j++)
546     for (UInt_t i = offsetX; i< nbinsX; i++)
547      {
548       if ( fNumerator->GetBinContent(i,j) > 0.0 )
549        {
550          ratio = fDenominator->GetBinContent(i,j)/fNumerator->GetBinContent(i,j);
551          sum += ratio;
552          n++;
553        }
554      }
555   
556   if(AliHBTParticle::GetDebug() > 0) Info("Scale","sum=%f fNBinsToScaleX=%d fNBinsToScaleY=%d n=%d",sum,fNBinsToScaleX,fNBinsToScaleY,n);
557   
558   if (n == 0) return 0.0;
559   Double_t ret = sum/((Double_t)n);
560
561   if(AliHBTParticle::GetDebug() > 0) Info("Scale","returning %f",ret);
562   return ret;
563
564
565 /******************************************************************/
566 /******************************************************************/
567 /******************************************************************/
568
569 //____________________
570 ///////////////////////////////////////////////////////
571 //                                                   //
572 // AliHBTFunction3D                                  //
573 //                                                   //
574 // Base Calss for 3-dimensinal Functions             //
575 //                                                   //
576 // Piotr.Skowronski@cern.ch                          //
577 // http://alisoft.cern.ch/people/skowron/analyzer    //
578 //                                                   //
579 ///////////////////////////////////////////////////////
580
581 ClassImp( AliHBTFunction3D)
582
583 const Int_t AliHBTFunction3D::fgkDefaultNBinsX = 200;//default number of Bins in X axis in histograms
584 const Float_t AliHBTFunction3D::fgkDefaultMinX = 0.0;//Default min value of X axis in histograms
585 const Float_t AliHBTFunction3D::fgkDefaultMaxX = 1.5;//Default max value of X axis inhistograms
586
587 const Int_t AliHBTFunction3D::fgkDefaultNBinsY = 200;//default number of Bins in histograms
588 const Float_t AliHBTFunction3D::fgkDefaultMinY = -0.15;//Default min value of histograms
589 const Float_t AliHBTFunction3D::fgkDefaultMaxY =  0.15;//Default max value of histograms
590
591 const Int_t AliHBTFunction3D::fgkDefaultNBinsZ = 200;//default number of Bins in histograms
592 const Float_t AliHBTFunction3D::fgkDefaultMinZ = -0.15;//Default min value of histograms
593 const Float_t AliHBTFunction3D::fgkDefaultMaxZ =  0.15;//Default max value of histograms
594
595 const UInt_t AliHBTFunction3D::fgkDefaultNBinsToScaleX = 30;//Default number of X bins used for scaling to tale
596 const UInt_t AliHBTFunction3D::fgkDefaultNBinsToScaleY = 30;//Default number of bins used for scaling to tale
597 const UInt_t AliHBTFunction3D::fgkDefaultNBinsToScaleZ = 30;//Default number of bins used for scaling to tale
598
599 AliHBTFunction3D::AliHBTFunction3D():
600  fNumerator(0x0),
601  fDenominator(0x0),
602  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
603  fNBinsToScaleY(fgkDefaultNBinsToScaleY),
604  fNBinsToScaleZ(fgkDefaultNBinsToScaleZ)
605 {
606  //constructor
607 }
608 /******************************************************************/
609
610 AliHBTFunction3D::AliHBTFunction3D(const Char_t *name, const Char_t *title):
611  AliHBTFunction(name,title),
612  fNumerator(0x0),
613  fDenominator(0x0),
614  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
615  fNBinsToScaleY(fgkDefaultNBinsToScaleY),
616  fNBinsToScaleZ(fgkDefaultNBinsToScaleZ)
617 {
618  //constructor
619 }  
620 /******************************************************************/
621
622 AliHBTFunction3D::AliHBTFunction3D(Int_t nXbins, Double_t maxXval, Double_t minXval, 
623                   Int_t nYbins, Double_t maxYval, Double_t minYval, 
624                   Int_t nZbins, Double_t maxZval, Double_t minZval):
625  fNumerator(0x0),
626  fDenominator(0x0),
627  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
628  fNBinsToScaleY(fgkDefaultNBinsToScaleY),
629  fNBinsToScaleZ(fgkDefaultNBinsToScaleZ)
630 {
631  //constructor
632  BuildHistos( nXbins,maxXval,minXval,nYbins,maxYval,minYval,nZbins,maxZval,minZval);
633 }         
634 /******************************************************************/
635
636 AliHBTFunction3D::AliHBTFunction3D(const Char_t *name, const Char_t *title,
637                  Int_t nXbins, Double_t maxXval, Double_t minXval, 
638                  Int_t nYbins, Double_t maxYval, Double_t minYval, 
639                  Int_t nZbins, Double_t maxZval, Double_t minZval):
640  AliHBTFunction(name,title),
641  fNumerator(0x0),
642  fDenominator(0x0),
643  fNBinsToScaleX(fgkDefaultNBinsToScaleX), 
644  fNBinsToScaleY(fgkDefaultNBinsToScaleY),
645  fNBinsToScaleZ(fgkDefaultNBinsToScaleZ)
646 {
647  //constructor
648  BuildHistos( nXbins,maxXval,minXval,nYbins,maxYval,minYval,nZbins,maxZval,minZval);
649 }         
650 /******************************************************************/
651
652 AliHBTFunction3D::AliHBTFunction3D(const AliHBTFunction3D& source):
653  AliHBTFunction(source)
654 {
655 // Copy constructor needed by the coding conventions byt not used
656   Fatal("AliHBTFunction3D(const AliHBTFunction3D&)","Cpy ctor not usable.");
657 }
658 /******************************************************************/
659
660 AliHBTFunction3D& AliHBTFunction3D::operator= (const AliHBTFunction3D & /*source*/) 
661 {
662 // Assignment needed by the coding conventions byt not used
663   Fatal("Assignment operator","not implemented");
664   return * this;
665  }
666 /******************************************************************/
667
668
669 AliHBTFunction3D::~AliHBTFunction3D()
670 {
671   delete fNumerator;
672   delete fDenominator;
673 }
674 /******************************************************************/
675
676 void AliHBTFunction3D::BuildHistos()
677 {
678 //Creates default histograms
679   BuildHistos(fgkDefaultNBinsX,fgkDefaultMaxX,fgkDefaultMinX,
680               fgkDefaultNBinsY,fgkDefaultMaxY,fgkDefaultMinY,
681               fgkDefaultNBinsZ,fgkDefaultMaxZ,fgkDefaultMinZ);
682 }
683 /******************************************************************/
684
685 void AliHBTFunction3D::BuildHistos(Int_t nxbins, Float_t xmax, Float_t xmin,
686                                    Int_t nybins, Float_t ymax, Float_t ymin,
687                        Int_t nzbins, Float_t zmax, Float_t zmin)
688 {
689   //Builds numerator and denominator histograms (3d-case)
690    TString numstr = fName + " Numerator";  //title and name of the 
691                                            //numerator histogram
692    TString denstr = fName + " Denominator";//title and name of the 
693                                            //denominator histogram
694          
695    fNumerator   = new TH3D(numstr.Data(),numstr.Data(),
696                            nxbins,xmin,xmax,nybins,ymin,ymax,nzbins,zmin,zmax);
697                
698    fDenominator = new TH3D(denstr.Data(),denstr.Data(),
699                            nxbins,xmin,xmax,nybins,ymin,ymax,nzbins,zmin,zmax);
700    
701    fNumerator->Sumw2();
702    fDenominator->Sumw2();
703 }
704
705 /******************************************************************/
706
707 Double_t AliHBTFunction3D::Scale()
708 {
709   // Calculates the factor that should be used to scale 
710   // quatience of fNumerator and fDenominator to 1 at 
711   // given volume
712   if (AliHBTParticle::GetDebug()>0) Info("Scale","Enetered Scale()");
713   if(!fNumerator) 
714    {
715      Error("Scale","No numerator");
716      return 0.0;
717    }
718   if(!fDenominator) 
719    {
720      Error("Scale","No denominator");
721      return 0.0;
722    }
723   
724   if( (fNBinsToScaleX < 1) || (fNBinsToScaleY < 1) || (fNBinsToScaleZ < 1)) 
725    {
726     Error("Scale","Number of bins for scaling is smaller thnan 1");
727     return 0.0;
728    }
729   UInt_t nbinsX = fNumerator->GetNbinsX();
730   if (fNBinsToScaleX > nbinsX) 
731    {
732     Error("Scale","Number of X bins for scaling is bigger thnan number of bins in histograms");
733     return 0.0;
734    }
735    
736   UInt_t nbinsY = fNumerator->GetNbinsX();
737   if (fNBinsToScaleY > nbinsY) 
738    {
739     Error("Scale","Number of Y bins for scaling is bigger thnan number of bins in histograms");
740     return 0.0;
741    }
742
743   UInt_t nbinsZ = fNumerator->GetNbinsZ();
744   if (fNBinsToScaleZ > nbinsZ) 
745    {
746     Error("Scale","Number of Z bins for scaling is bigger thnan number of bins in histograms");
747     return 0.0;
748    }
749
750   if (AliHBTParticle::GetDebug()>0) Info("Scale","No errors detected");
751
752   Int_t offsetX = nbinsX - fNBinsToScaleX - 1; //bin that we start loop over bins in axis X
753   Int_t offsetY = nbinsY - fNBinsToScaleY - 1; //bin that we start loop over bins in axis Y
754   Int_t offsetZ = nbinsZ - fNBinsToScaleZ - 1; //bin that we start loop over bins in axis Z
755
756   Double_t ratio;
757   Double_t sum = 0;
758   Int_t n = 0;
759   
760   for (UInt_t k = offsetZ; k<nbinsZ; k++)
761     for (UInt_t j = offsetY; j<nbinsY; j++)
762       for (UInt_t i = offsetX; i<nbinsX; i++)
763        {
764         if ( fNumerator->GetBinContent(i,j,k) > 0.0 )
765          {
766            ratio = fDenominator->GetBinContent(i,j,k)/fNumerator->GetBinContent(i,j,k);
767            sum += ratio;
768            n++;
769          }
770        }
771   
772   if(AliHBTParticle::GetDebug() > 0) 
773     Info("Scale","sum=%f fNBinsToScaleX=%d fNBinsToScaleY=%d fNBinsToScaleZ=%d n=%d",
774           sum,fNBinsToScaleX,fNBinsToScaleY,fNBinsToScaleZ,n);
775   
776   if (n == 0) return 0.0;
777   Double_t ret = sum/((Double_t)n);
778
779   if(AliHBTParticle::GetDebug() > 0) Info("Scale","returning %f",ret);
780   return ret;
781
782 /******************************************************************/
783
784 void AliHBTFunction3D::SetNumberOfBinsToScale(UInt_t xn, UInt_t yn,UInt_t zn)
785 {
786 //sets up the volume to be used for scaling to tail
787  fNBinsToScaleX = xn;
788  fNBinsToScaleY = yn;
789  fNBinsToScaleZ = zn;
790 }
791
792 /******************************************************************/
793 /******************************************************************/
794 /******************************************************************/
795 /******************************************************************/
796 /******************************************************************/
797 /******************************************************************/
798 /******************************************************************/
799 /******************************************************************/
800 /******************************************************************/
801
802 //____________________
803 ///////////////////////////////////////////////////////
804 //                                                   //
805 // AliHBTOnePairFctn1D                               //
806 //                                                   //
807 // Base Calss for 1-dimensinal Functions that need   //
808 // one pair to fill function                         //
809 //                                                   //
810 // Piotr.Skowronski@cern.ch                          //
811 // http://alisoft.cern.ch/people/skowron/analyzer    //
812 //                                                   //
813 ///////////////////////////////////////////////////////
814
815 ClassImp( AliHBTOnePairFctn1D )
816 /******************************************************************/
817
818 AliHBTOnePairFctn1D::AliHBTOnePairFctn1D(Int_t nbins, Float_t maxXval, Float_t minXval):
819  AliHBTFunction1D(nbins,maxXval,minXval)
820 {
821   //constructor
822 }
823 /******************************************************************/
824
825 AliHBTOnePairFctn1D::AliHBTOnePairFctn1D(const Char_t *name, const Char_t *title):
826  AliHBTFunction1D(name,title)
827 {
828
829 }
830 /******************************************************************/
831
832 AliHBTOnePairFctn1D::AliHBTOnePairFctn1D(const Char_t *name, const Char_t *title,
833                                          Int_t nbins, Float_t maxXval, Float_t minXval):
834  AliHBTFunction1D(name,title,nbins,maxXval,minXval)
835 {
836   //constructor
837 }
838 /******************************************************************/
839
840 void AliHBTOnePairFctn1D::ProcessSameEventParticles(AliHBTPair* pair)
841 {
842  //Fills the numerator using pair from the same event
843    pair = CheckPair(pair);
844    if(pair) fNumerator->Fill(GetValue(pair));
845 }
846 /******************************************************************/
847 void AliHBTOnePairFctn1D::ProcessDiffEventParticles(AliHBTPair* pair)
848  {
849   //Fills the denumerator using mixed pairs
850    pair = CheckPair(pair);
851    if(pair) fDenominator->Fill(GetValue(pair));
852   }
853
854 /******************************************************************/
855 /******************************************************************/
856 /******************************************************************/
857
858 //____________________
859 ///////////////////////////////////////////////////////
860 //                                                   //
861 // AliHBTOnePairFctn2D                               //
862 //                                                   //
863 // Base Calss for 2-dimensinal Functions that need   //
864 // one pair to fill function                         //
865 //                                                   //
866 // Piotr.Skowronski@cern.ch                          //
867 // http://alisoft.cern.ch/people/skowron/analyzer    //
868 //                                                   //
869 ///////////////////////////////////////////////////////
870
871 ClassImp( AliHBTOnePairFctn2D )
872 /******************************************************************/
873
874 AliHBTOnePairFctn2D::AliHBTOnePairFctn2D(const Char_t *name, const Char_t *title):
875  AliHBTFunction2D(name,title)
876 {
877   //constructor
878 }
879 /******************************************************************/
880
881 AliHBTOnePairFctn2D::AliHBTOnePairFctn2D(Int_t nXbins, Double_t maxXval, Double_t minXval, 
882                       Int_t nYbins, Double_t maxYval, Double_t minYval):
883  AliHBTFunction2D(nXbins, maxXval, minXval, nYbins, maxYval, minYval)
884 {
885   //constructor
886 }
887 /******************************************************************/
888
889 AliHBTOnePairFctn2D::AliHBTOnePairFctn2D(const Char_t *name, const Char_t *title,
890                       Int_t nXbins, Double_t maxXval, Double_t minXval, 
891                       Int_t nYbins, Double_t maxYval, Double_t minYval):
892  AliHBTFunction2D(name,title, nXbins, maxXval, minXval, nYbins, maxYval, minYval)
893 {
894   //constructor
895 }
896 /******************************************************************/
897
898 void AliHBTOnePairFctn2D::ProcessSameEventParticles(AliHBTPair* pair)
899 {
900   // Fills the numerator using pairs from the same event
901   pair = CheckPair(pair);
902   if(pair) 
903    { 
904      Double_t x,y;
905      GetValues(pair,x,y);
906      fNumerator->Fill(x,y);
907    }
908 }
909 /******************************************************************/
910
911 void AliHBTOnePairFctn2D::ProcessDiffEventParticles(AliHBTPair* pair)
912 {
913   // Fills the denumerator using mixed pairs
914   pair = CheckPair(pair);
915   if(pair) 
916    { 
917      Double_t x,y;
918      GetValues(pair,x,y);
919      fDenominator->Fill(x,y);
920    }
921 }
922 /******************************************************************/
923 /******************************************************************/
924 /******************************************************************/
925 /******************************************************************/
926 //____________________
927 ///////////////////////////////////////////////////////
928 //                                                   //
929 // AliHBTOnePairFctn3D                               //
930 //                                                   //
931 // Base Calss for 3-dimensinal Functions that need   //
932 // one pair to fill function                         //
933 //                                                   //
934 // Piotr.Skowronski@cern.ch                          //
935 // http://alisoft.cern.ch/people/skowron/analyzer    //
936 //                                                   //
937 ///////////////////////////////////////////////////////
938 ClassImp( AliHBTOnePairFctn3D)
939
940 /******************************************************************/
941
942 AliHBTOnePairFctn3D::AliHBTOnePairFctn3D(const Char_t *name, const Char_t *title):
943  AliHBTFunction3D(name,title)
944 {
945   //constructor
946 }
947 /******************************************************************/
948
949 AliHBTOnePairFctn3D::AliHBTOnePairFctn3D(Int_t nXbins, Double_t maxXval, Double_t minXval, 
950                       Int_t nYbins, Double_t maxYval, Double_t minYval, 
951                       Int_t nZbins, Double_t maxZval, Double_t minZval):
952  AliHBTFunction3D(nXbins, maxXval, minXval, nYbins, maxYval, minYval, nZbins, maxZval, minZval)
953 {
954   //constructor
955 }
956 /******************************************************************/
957
958 AliHBTOnePairFctn3D::AliHBTOnePairFctn3D(const Char_t *name, const Char_t *title,
959                       Int_t nXbins, Double_t maxXval, Double_t minXval, 
960                       Int_t nYbins, Double_t maxYval, Double_t minYval, 
961                       Int_t nZbins, Double_t maxZval, Double_t minZval):
962  AliHBTFunction3D(name,title,nXbins, maxXval, minXval, nYbins, maxYval, minYval, nZbins, maxZval, minZval)
963 {
964   //constructor
965 }
966 /******************************************************************/
967
968 void AliHBTOnePairFctn3D::ProcessSameEventParticles(AliHBTPair* pair)
969 {
970 //Reacts on pair coming from same event (real pairs)
971 //and fills numerator histogram
972   pair  = CheckPair(pair);
973   if( pair ) 
974    { 
975      Double_t x,y,z;
976      GetValues(pair,x,y,z);
977      fNumerator->Fill(x,y,z);
978    }
979 }
980 /******************************************************************/
981
982 void AliHBTOnePairFctn3D::ProcessDiffEventParticles(AliHBTPair* pair)
983 {
984 //Reacts on pair coming from different events (mixed pairs)
985 //and fills denominator histogram
986   pair  = CheckPair(pair);
987   if( pair ) 
988    { 
989      Double_t x,y,z;
990      GetValues(pair,x,y,z);
991      fDenominator->Fill(x,y,z);
992    }
993 }
994
995 /******************************************************************/
996 /******************************************************************/
997 /******************************************************************/
998
999 //____________________
1000 ///////////////////////////////////////////////////////
1001 //                                                   //
1002 // AliHBTTwoPairFctn1D                               //
1003 //                                                   //
1004 // Base Calss for 1-dimensinal Functions that need   //
1005 // two pair (simulated and reconstructed)            //
1006 // to fill function                                  //
1007 //                                                   //
1008 // Piotr.Skowronski@cern.ch                          //
1009 // http://alisoft.cern.ch/people/skowron/analyzer    //
1010 //                                                   //
1011 ///////////////////////////////////////////////////////
1012 ClassImp(AliHBTTwoPairFctn1D)
1013 /******************************************************************/
1014
1015 AliHBTTwoPairFctn1D::AliHBTTwoPairFctn1D(Int_t nbins, Float_t maxXval, Float_t minXval):
1016  AliHBTFunction1D(nbins,maxXval,minXval)
1017 {
1018   //constructor
1019 }
1020 /******************************************************************/
1021
1022 AliHBTTwoPairFctn1D::AliHBTTwoPairFctn1D(const Char_t *name, const Char_t *title):
1023  AliHBTFunction1D(name,title)
1024 {
1025   //constructor
1026 }
1027 /******************************************************************/
1028
1029 AliHBTTwoPairFctn1D::AliHBTTwoPairFctn1D(const Char_t *name, const Char_t *title,
1030                                          Int_t nbins, Float_t maxXval, Float_t minXval):
1031  AliHBTFunction1D(name,title,nbins,maxXval,minXval)
1032 {
1033   //constructor
1034 }
1035 /******************************************************************/
1036
1037 void AliHBTTwoPairFctn1D::ProcessSameEventParticles(AliHBTPair* trackpair, AliHBTPair* partpair)
1038 {
1039   // Fills the numerator using pairs from the same event
1040   partpair  = CheckPair(partpair);
1041   if (partpair->GetSwapedPair() == 0x0)//it means that Check pair returned swapped pair
1042     trackpair = trackpair->GetSwapedPair();//so the track pair must be swapped as well
1043   if( partpair ) 
1044    { 
1045      Double_t x = GetValue(trackpair,partpair);
1046      fNumerator->Fill(x);
1047    }
1048 }
1049 /******************************************************************/
1050
1051 void AliHBTTwoPairFctn1D::ProcessDiffEventParticles(AliHBTPair* trackpair, AliHBTPair* partpair)
1052 {
1053   // Fills the denumerator usin mixed pairs
1054   partpair  = CheckPair(partpair);
1055   if (partpair->GetSwapedPair() == 0x0)//it means that Check pair returned swapped pair
1056     trackpair = trackpair->GetSwapedPair();//so the track pair must be swapped as well
1057   if( partpair )
1058    { 
1059      Double_t x = GetValue(trackpair,partpair);
1060      fDenominator->Fill(x);
1061    }
1062 }
1063 /******************************************************************/
1064 /******************************************************************/
1065 /******************************************************************/
1066
1067 //____________________
1068 ///////////////////////////////////////////////////////
1069 //                                                   //
1070 // AliHBTTwoPairFctn2D                               //
1071 //                                                   //
1072 // Base Calss for 2-dimensinal Functions that need   //
1073 // two pair (simulated and reconstructed)            //
1074 // to fill function                                  //
1075 //                                                   //
1076 // Piotr.Skowronski@cern.ch                          //
1077 // http://alisoft.cern.ch/people/skowron/analyzer    //
1078 //                                                   //
1079 ///////////////////////////////////////////////////////
1080
1081 ClassImp(AliHBTTwoPairFctn2D)
1082
1083 /******************************************************************/
1084
1085 AliHBTTwoPairFctn2D::AliHBTTwoPairFctn2D(const Char_t *name, const Char_t *title):
1086  AliHBTFunction2D(name,title)
1087 {
1088   //constructor
1089 }
1090 /******************************************************************/
1091
1092 AliHBTTwoPairFctn2D::AliHBTTwoPairFctn2D(Int_t nXbins, Double_t maxXval, Double_t minXval, 
1093                       Int_t nYbins, Double_t maxYval, Double_t minYval):
1094  AliHBTFunction2D(nXbins, maxXval, minXval, nYbins, maxYval, minYval)
1095 {
1096   //constructor
1097 }
1098 /******************************************************************/
1099
1100 AliHBTTwoPairFctn2D::AliHBTTwoPairFctn2D(const Char_t *name, const Char_t *title,
1101                       Int_t nXbins, Double_t maxXval, Double_t minXval, 
1102                       Int_t nYbins, Double_t maxYval, Double_t minYval):
1103  AliHBTFunction2D(name,title,nXbins, maxXval, minXval, nYbins, maxYval, minYval)
1104 {
1105   //constructor
1106 }
1107 /******************************************************************/
1108
1109 void AliHBTTwoPairFctn2D::ProcessSameEventParticles(AliHBTPair* trackpair, AliHBTPair* partpair)
1110 {
1111 //processes pair of particles coming from a same events (real pair)
1112   partpair  = CheckPair(partpair);  //check cuts
1113   if (partpair->GetSwapedPair() == 0x0)//it means that Check pair returned swapped pair
1114     trackpair = trackpair->GetSwapedPair();//so the track pair must be swapped as well
1115   if( partpair ) 
1116    { 
1117      Double_t x,y;
1118      GetValues(trackpair,partpair,x,y);
1119      fNumerator->Fill(x,y);
1120    }
1121 }
1122 /******************************************************************/
1123
1124 void AliHBTTwoPairFctn2D::ProcessDiffEventParticles(AliHBTPair* trackpair, AliHBTPair* partpair)
1125 {
1126 //processes pair of particles coming from a different events (mixed pair)
1127   partpair  = CheckPair(partpair);
1128   if (partpair->GetSwapedPair() == 0x0)//it means that Check pair returned swapped pair
1129     trackpair = trackpair->GetSwapedPair();//so the track pair must be swapped as well
1130   if( partpair ) 
1131    { 
1132      Double_t x,y;
1133      GetValues(trackpair,partpair,x,y);
1134      fDenominator->Fill(x,y);
1135    }
1136 }
1137
1138 /******************************************************************/
1139 /******************************************************************/
1140 /******************************************************************/
1141
1142 //____________________
1143 ///////////////////////////////////////////////////////
1144 //                                                   //
1145 // AliHBTTwoPairFctn3D                               //
1146 //                                                   //
1147 // Base Calss for 3-dimensinal Functions that need   //
1148 // two pair (simulated and reconstructed)            //
1149 // to fill function                                  //
1150 //                                                   //
1151 // Piotr.Skowronski@cern.ch                          //
1152 // http://alisoft.cern.ch/people/skowron/analyzer    //
1153 //                                                   //
1154 ///////////////////////////////////////////////////////
1155
1156 ClassImp(AliHBTTwoPairFctn3D)
1157
1158 /******************************************************************/
1159
1160 AliHBTTwoPairFctn3D::AliHBTTwoPairFctn3D(const Char_t *name, const Char_t *title):
1161  AliHBTFunction3D(name,title)
1162 {
1163   //constructor
1164 }
1165 /******************************************************************/
1166
1167 AliHBTTwoPairFctn3D::AliHBTTwoPairFctn3D(Int_t nXbins, Double_t maxXval, Double_t minXval, 
1168                       Int_t nYbins, Double_t maxYval, Double_t minYval, 
1169                       Int_t nZbins, Double_t maxZval, Double_t minZval):
1170  AliHBTFunction3D(nXbins, maxXval, minXval, nYbins, maxYval, minYval, nZbins, maxZval, minZval)
1171 {
1172   //constructor
1173 }
1174 /******************************************************************/
1175
1176 AliHBTTwoPairFctn3D::AliHBTTwoPairFctn3D(const Char_t *name, const Char_t *title,
1177                       Int_t nXbins, Double_t maxXval, Double_t minXval, 
1178                       Int_t nYbins, Double_t maxYval, Double_t minYval, 
1179                       Int_t nZbins, Double_t maxZval, Double_t minZval):
1180  AliHBTFunction3D(name,title,nXbins, maxXval, minXval, nYbins, maxYval, minYval, nZbins, maxZval, minZval)
1181 {
1182   //constructor
1183 }
1184 /******************************************************************/
1185
1186 void AliHBTTwoPairFctn3D::ProcessSameEventParticles(AliHBTPair* trackpair, AliHBTPair* partpair)
1187 {
1188   // Fills th numerator using pairs from the same event
1189   partpair  = CheckPair(partpair);
1190   if (partpair->GetSwapedPair() == 0x0)//it means that CheckPair returned swapped pair
1191     trackpair = trackpair->GetSwapedPair();//so the track pair must be swapped as well
1192   if( partpair ) 
1193    { 
1194      Double_t x,y,z;
1195      GetValues(trackpair,partpair,x,y,z);
1196      fNumerator->Fill(x,y,z);
1197    }
1198 }
1199 /******************************************************************/
1200
1201 void AliHBTTwoPairFctn3D::ProcessDiffEventParticles(AliHBTPair* trackpair, AliHBTPair* partpair)
1202 {
1203   // Fills the denumerator using mixed pairs
1204   partpair  = CheckPair(partpair);
1205   if (partpair->GetSwapedPair() == 0x0)//it means that CheckPair returned swapped pair
1206     trackpair = trackpair->GetSwapedPair();//so the track pair must be swapped as well
1207   if( partpair ) 
1208    { 
1209      Double_t x,y,z;
1210      GetValues(trackpair,partpair,x,y,z);
1211      fDenominator->Fill(x,y,z);
1212    }
1213
1214 }
1215
1216 /******************************************************************/
1217 /******************************************************************/
1218 /******************************************************************/
1219