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