laura is hosted by Hepforge, IPPP Durham
Laura++  v3r2
A maximum likelihood fitting package for performing Dalitz-plot analysis.
Lau2DAbsHistDP.cc
Go to the documentation of this file.
1 
2 // Copyright University of Warwick 2004 - 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Authors:
7 // Thomas Latham
8 // John Back
9 // Paul Harrison
10 
15 #include <iostream>
16 
17 #include "TAxis.h"
18 #include "TH2.h"
19 #include "TRandom.h"
20 #include "TSystem.h"
21 
22 #include "Lau2DAbsHistDP.hh"
23 #include "LauBifurcatedGaussPdf.hh"
24 #include "LauDaughters.hh"
25 #include "LauKinematics.hh"
26 #include "LauRandom.hh"
27 
29 
30 
31 Lau2DAbsHistDP::Lau2DAbsHistDP(const LauDaughters* daughters, Bool_t useUpperHalfOnly, Bool_t squareDP) :
32  kinematics_( (daughters!=0) ? daughters->getKinematics() : 0 ),
33  upperHalf_(useUpperHalfOnly),
34  squareDP_(squareDP)
35 {
36  if ( squareDP && ! daughters->squareDP() ) {
37  // The histogram provided is defined in the square DP but the
38  // kinematics object has calculation of the square DP
39  // co-ordinates disabled, so need to enable it,
40  // which requires a bit of a unpleasant const_cast
41  std::cerr << "WARNING in Lau2DAbsHistDP constructor : forcing kinematics to calculate the required square DP co-ordinates" << std::endl;
42  LauKinematics* kine = const_cast<LauKinematics*>( kinematics_ );
43  kine->squareDP(kTRUE);
44  }
45 }
46 
48 {
49 }
50 
52 {
53  TRandom* random = LauRandom::randomFun();
54 
55  Int_t nBinsX = static_cast<Int_t>(hist->GetNbinsX());
56  Int_t nBinsY = static_cast<Int_t>(hist->GetNbinsY());
57 
58  for (Int_t i(0); i<nBinsX; ++i) {
59  for (Int_t j(0); j<nBinsY; ++j) {
60  Double_t currentContent = hist->GetBinContent(i+1,j+1);
61  Double_t currentError = hist->GetBinError(i+1,j+1);
62  Double_t newContent = random->Gaus(currentContent,currentError);
63  if (newContent<0.0) {
64  hist->SetBinContent(i+1,j+1,0.0);
65  } else {
66  hist->SetBinContent(i+1,j+1,newContent);
67  }
68  }
69  }
70 }
71 
72 void Lau2DAbsHistDP::doBinFluctuation(TH2* hist, const TH2* errorHi, const TH2* errorLo)
73 {
74  LauParameter* mean = new LauParameter("mean", 0.5, 0.0, 1.0, kFALSE);
75  LauParameter* sigL = new LauParameter("sigmaL", 0.5, 0.0, 1.0, kFALSE);
76  LauParameter* sigR = new LauParameter("sigmaR", 0.5, 0.0, 1.0, kFALSE);
77 
78  std::vector<LauAbsRValue*> pars(3);
79  pars[0] = mean;
80  pars[1] = sigL;
81  pars[2] = sigR;
82 
83  const TString varName("tmp");
84 
85  Int_t nBinsX = static_cast<Int_t>(hist->GetNbinsX());
86  Int_t nBinsY = static_cast<Int_t>(hist->GetNbinsY());
87 
88  LauFitData genData;
89 
90  for (Int_t i(0); i<nBinsX; ++i) {
91  for (Int_t j(0); j<nBinsY; ++j) {
92  const Double_t currentContent = hist->GetBinContent(i+1,j+1);
93  const Double_t currentErrorLo = errorLo->GetBinContent(i+1,j+1);
94  const Double_t currentErrorHi = errorHi->GetBinContent(i+1,j+1);
95 
96  mean->value( currentContent );
97  sigL->value( currentErrorLo );
98  sigR->value( currentErrorHi );
99 
100  const Double_t minVal = TMath::Max( 0.0, currentContent-5.0*currentErrorLo );
101  const Double_t maxVal = TMath::Min( 1.0, currentContent+5.0*currentErrorHi );
102 
103  LauBifurcatedGaussPdf bfgaus(varName, pars, minVal, maxVal);
104  bfgaus.heightUpToDate(kFALSE);
105  genData = bfgaus.generate(0);
106 
107  const Double_t newContent = genData[varName];
108 
109  hist->SetBinContent(i+1,j+1,newContent);
110  }
111  }
112 
113  delete pars[0];
114  delete pars[1];
115  delete pars[2];
116  pars.clear();
117 }
118 
119 void Lau2DAbsHistDP::raiseOrLowerBins(TH2* hist, const Double_t avEff, const Double_t avEffError)
120 {
121  TRandom* random = LauRandom::randomFun();
122 
123  Double_t curAvg = this->computeAverageContents(hist);
124  Double_t newAvg = random->Gaus(avEff,avEffError);
125 
126  hist->Scale( newAvg / curAvg );
127 }
128 
129 Double_t Lau2DAbsHistDP::computeAverageContents(const TH2* hist) const
130 {
131  Double_t totalContent(0.0);
132  Int_t binsWithinDPBoundary(0);
133 
134  Int_t nBinsX = static_cast<Int_t>(hist->GetNbinsX());
135  Int_t nBinsY = static_cast<Int_t>(hist->GetNbinsY());
136 
137  // Loop through the bins and include any that have their centre or any
138  // of the four corners within the kinematic boundary
139  for ( Int_t i(0); i<nBinsX; ++i ) {
140  Double_t binXCentre = hist->GetXaxis()->GetBinCenter(i+1);
141  Double_t binXLowerEdge = hist->GetXaxis()->GetBinLowEdge(i+1);
142  Double_t binXUpperEdge = hist->GetXaxis()->GetBinUpEdge(i+1);
143 
144  for ( Int_t j(0); j<nBinsY; ++j ) {
145  Double_t binYCentre = hist->GetYaxis()->GetBinCenter(i+1);
146  Double_t binYLowerEdge = hist->GetYaxis()->GetBinLowEdge(i+1);
147  Double_t binYUpperEdge = hist->GetYaxis()->GetBinUpEdge(i+1);
148 
149  if ( this->withinDPBoundaries( binXCentre, binYCentre ) ||
150  this->withinDPBoundaries( binXLowerEdge, binYLowerEdge ) ||
151  this->withinDPBoundaries( binXUpperEdge, binYUpperEdge ) ||
152  this->withinDPBoundaries( binXLowerEdge, binYUpperEdge ) ||
153  this->withinDPBoundaries( binXUpperEdge, binYLowerEdge ) ) {
154 
155  totalContent += hist->GetBinContent(i+1, j+1);
156  ++binsWithinDPBoundary;
157  }
158  }
159  }
160 
161  return totalContent/binsWithinDPBoundary;
162 }
163 
164 Bool_t Lau2DAbsHistDP::withinDPBoundaries(Double_t x, Double_t y) const
165 {
167 }
168 
169 void Lau2DAbsHistDP::getUpperHalf(Double_t& x, Double_t& y) const
170 {
171  if ( upperHalf_ == kTRUE ) {
172  if ( squareDP_ == kFALSE && x > y ) {
173  Double_t temp = y;
174  y = x;
175  x = temp;
176  } else if ( squareDP_ == kTRUE && y > 0.5 ) {
177  y = 1.0 - y;
178  }
179  }
180 }
181 
Bool_t withinDPLimits(const Double_t m13Sq, const Double_t m23Sq) const
Check whether a given (m13Sq,m23Sq) point is within the kinematic limits of the Dalitz plot...
TRandom * randomFun()
Access the singleton random number generator with a particular seed.
Definition: LauRandom.cc:20
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:264
ClassImp(LauAbsCoeffSet)
void raiseOrLowerBins(TH2 *hist, const Double_t avEff, const Double_t avEffError)
Rescale the histogram bin contents based on the desired average efficiency and its uncertainty...
void doBinFluctuation(TH2 *hist)
Fluctuate the contents of each histogram bin independently, in accordance with their errors...
void squareDP(const Bool_t calcSquareDPCoords)
Enable/disable the calculation of square Dalitz plot co-ordinates.
LauParameter()
Default constructor.
Definition: LauParameter.cc:30
Class that defines the particular 3-body decay under study.
Definition: LauDaughters.hh:33
File containing declaration of LauDaughters class.
virtual LauFitData generate(const LauKinematics *kinematics)
Generate an event from the PDF.
Definition: LauAbsPdf.cc:298
std::map< TString, Double_t > LauFitData
Type for holding event data.
File containing declaration of LauKinematics class.
File containing declaration of LauBifurcatedGaussPdf class.
Abstract base class for defining a variation across a 2D DP based on a histogram. ...
Bool_t withinDPBoundaries(Double_t x, Double_t y) const
Check whether the given co-ordinates are within the kinematic boundary.
virtual ~Lau2DAbsHistDP()
Copy constructor.
Class for defining the fit parameter objects.
Definition: LauParameter.hh:35
File containing LauRandom namespace.
Class for defining a bifurcated Gaussian PDF.
Bool_t squareDP_
Boolean for using square DP variables.
const LauKinematics * kinematics_
Kinematics used to check events are within DP boundary.
File containing declaration of Lau2DAbsHistDP class.
Bool_t upperHalf_
Boolean for using the upper half of DP.
void getUpperHalf(Double_t &x, Double_t &y) const
If only using the upper half of the (symmetric) DP then transform into the correct half...
Class for calculating 3-body kinematic quantities.
Double_t computeAverageContents(const TH2 *hist) const
Compute the average bin content for bins within the kinematic boundary.
Double_t value() const
The value of the parameter.
Bool_t withinSqDPLimits(const Double_t mPrime, const Double_t thetaPrime) const
Check whether a given (m&#39;,theta&#39;) point is within the kinematic limits of the Dalitz plot...