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