laura is hosted by Hepforge, IPPP Durham
Laura++  v3r4
A maximum likelihood fitting package for performing Dalitz-plot analysis.
Lau2DAbsHistDP.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2013 University of Warwick
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */
17 
18 /*
19 Laura++ package authors:
20 John Back
21 Paul Harrison
22 Thomas Latham
23 */
24 
29 #include <iostream>
30 
31 #include "TAxis.h"
32 #include "TH2.h"
33 #include "TRandom.h"
34 #include "TSystem.h"
35 
36 #include "Lau2DAbsHistDP.hh"
37 #include "LauBifurcatedGaussPdf.hh"
38 #include "LauDaughters.hh"
39 #include "LauKinematics.hh"
40 #include "LauRandom.hh"
41 
43 
44 
45 Lau2DAbsHistDP::Lau2DAbsHistDP(const LauDaughters* daughters, Bool_t useUpperHalfOnly, Bool_t squareDP) :
46  kinematics_( (daughters!=0) ? daughters->getKinematics() : 0 ),
47  upperHalf_(useUpperHalfOnly),
48  squareDP_(squareDP)
49 {
50  if ( squareDP && ! daughters->squareDP() ) {
51  // The histogram provided is defined in the square DP but the
52  // kinematics object has calculation of the square DP
53  // co-ordinates disabled, so need to enable it,
54  // which requires a bit of a unpleasant const_cast
55  std::cerr << "WARNING in Lau2DAbsHistDP constructor : forcing kinematics to calculate the required square DP co-ordinates" << std::endl;
56  LauKinematics* kine = const_cast<LauKinematics*>( kinematics_ );
57  kine->squareDP(kTRUE);
58  }
59 }
60 
62 {
63 }
64 
66 {
67  TRandom* random = LauRandom::randomFun();
68 
69  Int_t nBinsX = static_cast<Int_t>(hist->GetNbinsX());
70  Int_t nBinsY = static_cast<Int_t>(hist->GetNbinsY());
71 
72  for (Int_t i(0); i<nBinsX; ++i) {
73  for (Int_t j(0); j<nBinsY; ++j) {
74  Double_t currentContent = hist->GetBinContent(i+1,j+1);
75  Double_t currentError = hist->GetBinError(i+1,j+1);
76  Double_t newContent = random->Gaus(currentContent,currentError);
77  if (newContent<0.0) {
78  hist->SetBinContent(i+1,j+1,0.0);
79  } else {
80  hist->SetBinContent(i+1,j+1,newContent);
81  }
82  }
83  }
84 }
85 
86 void Lau2DAbsHistDP::doBinFluctuation(TH2* hist, const TH2* errorHi, const TH2* errorLo)
87 {
88  LauParameter* mean = new LauParameter("mean", 0.5, 0.0, 1.0, kFALSE);
89  LauParameter* sigL = new LauParameter("sigmaL", 0.5, 0.0, 1.0, kFALSE);
90  LauParameter* sigR = new LauParameter("sigmaR", 0.5, 0.0, 1.0, kFALSE);
91 
92  std::vector<LauAbsRValue*> pars(3);
93  pars[0] = mean;
94  pars[1] = sigL;
95  pars[2] = sigR;
96 
97  const TString varName("tmp");
98 
99  Int_t nBinsX = static_cast<Int_t>(hist->GetNbinsX());
100  Int_t nBinsY = static_cast<Int_t>(hist->GetNbinsY());
101 
102  LauFitData genData;
103 
104  for (Int_t i(0); i<nBinsX; ++i) {
105  for (Int_t j(0); j<nBinsY; ++j) {
106  const Double_t currentContent = hist->GetBinContent(i+1,j+1);
107  const Double_t currentErrorLo = errorLo->GetBinContent(i+1,j+1);
108  const Double_t currentErrorHi = errorHi->GetBinContent(i+1,j+1);
109 
110  mean->value( currentContent );
111  sigL->value( currentErrorLo );
112  sigR->value( currentErrorHi );
113 
114  const Double_t minVal = TMath::Max( 0.0, currentContent-5.0*currentErrorLo );
115  const Double_t maxVal = TMath::Min( 1.0, currentContent+5.0*currentErrorHi );
116 
117  LauBifurcatedGaussPdf bfgaus(varName, pars, minVal, maxVal);
118  bfgaus.heightUpToDate(kFALSE);
119  genData = bfgaus.generate(0);
120 
121  const Double_t newContent = genData[varName];
122 
123  hist->SetBinContent(i+1,j+1,newContent);
124  }
125  }
126 
127  delete pars[0];
128  delete pars[1];
129  delete pars[2];
130  pars.clear();
131 }
132 
133 void Lau2DAbsHistDP::raiseOrLowerBins(TH2* hist, const Double_t avEff, const Double_t avEffError)
134 {
135  TRandom* random = LauRandom::randomFun();
136 
137  Double_t curAvg = this->computeAverageContents(hist);
138  Double_t newAvg = random->Gaus(avEff,avEffError);
139 
140  hist->Scale( newAvg / curAvg );
141 }
142 
143 Double_t Lau2DAbsHistDP::computeAverageContents(const TH2* hist) const
144 {
145  Double_t totalContent(0.0);
146  Int_t binsWithinDPBoundary(0);
147 
148  Int_t nBinsX = static_cast<Int_t>(hist->GetNbinsX());
149  Int_t nBinsY = static_cast<Int_t>(hist->GetNbinsY());
150 
151  // Loop through the bins and include any that have their centre or any
152  // of the four corners within the kinematic boundary
153  for ( Int_t i(0); i<nBinsX; ++i ) {
154  Double_t binXCentre = hist->GetXaxis()->GetBinCenter(i+1);
155  Double_t binXLowerEdge = hist->GetXaxis()->GetBinLowEdge(i+1);
156  Double_t binXUpperEdge = hist->GetXaxis()->GetBinUpEdge(i+1);
157 
158  for ( Int_t j(0); j<nBinsY; ++j ) {
159  Double_t binYCentre = hist->GetYaxis()->GetBinCenter(i+1);
160  Double_t binYLowerEdge = hist->GetYaxis()->GetBinLowEdge(i+1);
161  Double_t binYUpperEdge = hist->GetYaxis()->GetBinUpEdge(i+1);
162 
163  if ( this->withinDPBoundaries( binXCentre, binYCentre ) ||
164  this->withinDPBoundaries( binXLowerEdge, binYLowerEdge ) ||
165  this->withinDPBoundaries( binXUpperEdge, binYUpperEdge ) ||
166  this->withinDPBoundaries( binXLowerEdge, binYUpperEdge ) ||
167  this->withinDPBoundaries( binXUpperEdge, binYLowerEdge ) ) {
168 
169  totalContent += hist->GetBinContent(i+1, j+1);
170  ++binsWithinDPBoundary;
171  }
172  }
173  }
174 
175  return totalContent/binsWithinDPBoundary;
176 }
177 
178 Bool_t Lau2DAbsHistDP::withinDPBoundaries(Double_t x, Double_t y) const
179 {
181 }
182 
183 void Lau2DAbsHistDP::getUpperHalf(Double_t& x, Double_t& y) const
184 {
185  if ( upperHalf_ == kTRUE ) {
186  if ( squareDP_ == kFALSE && x > y ) {
187  Double_t temp = y;
188  y = x;
189  x = temp;
190  } else if ( squareDP_ == kTRUE && y > 0.5 ) {
191  y = 1.0 - y;
192  }
193  }
194 }
195 
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:34
virtual Bool_t heightUpToDate() const
Check if the maximum height of the PDF is up to date.
Definition: LauAbsPdf.hh:278
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:44
Class that defines the particular 3-body decay under study.
Definition: LauDaughters.hh:47
File containing declaration of LauDaughters class.
virtual LauFitData generate(const LauKinematics *kinematics)
Generate an event from the PDF.
Definition: LauAbsPdf.cc:312
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:49
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...