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