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