laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauScfMap.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2006 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 <cstdlib>
30 #include <iostream>
31 #include <vector>
32 #include <map>
33 using std::cout;
34 using std::cerr;
35 using std::flush;
36 using std::endl;
37 
38 #include "TAxis.h"
39 #include "TH2.h"
40 #include "TSystem.h"
41 
42 #include "LauScfMap.hh"
43 
45 
46 
48  nBinsX_(-1),
49  nBinsY_(-1),
50  numberOfBins_(-1)
51 {
52 }
53 
55 {
56  for (std::vector<TH2*>::iterator iter = histos_.begin(); iter != histos_.end(); ++iter) {
57  delete (*iter);
58  }
59 }
60 
61 void LauScfMap::setHistos(const std::vector<const TH2*>& histos)
62 {
63  // Check that we have enough histograms
64  Int_t nBinsX = histos.front()->GetNbinsX();
65  Int_t nBinsY = histos.front()->GetNbinsY();
66  Int_t nHist = histos.size();
67 
68  if (nHist != nBinsX*nBinsY) {
69  cerr<<"ERROR in LauScfMap::setHistos : There should be as many histograms supplied as there are bins in each of them."<<endl;
70  cerr<<" : There are "<<nHist<<" histograms and "<<nBinsX*nBinsY<<" bins."<<endl;
71  return;
72  }
73 
74  // number of (tru, and reco as well) bins in a 2D histogram
75  // Later we will create as many fake points to cache DP amplitudes
76  nBinsX_ = nBinsX;
77  nBinsY_ = nBinsY;
79 
80  // Clear out any old histos we might have lying around
81  for (std::vector<TH2*>::iterator iter = histos_.begin(); iter != histos_.end(); ++iter) {
82  delete (*iter);
83  }
84  histos_.clear();
85 
86  // Make sure we have enough space for the new histograms
87  histos_.reserve(nHist);
88 
89  // Loop through the supplied vector
90  // Clone each histogram and store it
91  for (std::vector<const TH2*>::const_iterator iter = histos.begin(); iter != histos.end(); ++iter) {
92  TH2* histo = dynamic_cast<TH2*>((*iter)->Clone());
93  if ( histo==0 ) {
94  cerr<<"ERROR in LauScfMap::setHistos : Problem cloning one of the histograms."<<endl;
95  gSystem->Exit(EXIT_FAILURE);
96  }
97  histos_.push_back(histo);
98  }
99 
100  if ( histos_.size() != histos.size() ) {
101  cerr<<"ERROR in LauScfMap::setHistos : Problem cloning the histograms."<<endl;
102  gSystem->Exit(EXIT_FAILURE);
103  }
104 
105  // Now we need to setup the map
106 
107  // First clear it
108  contribs_.clear();
109 
110  // Fill in the map that links, to each reco bin, a vector with the numbers of the tru bins
111  // that have non-zero contributions in that reco bin
112  // Loop over each histogram bin
113  for (Int_t j(0); j<nBinsY_; ++j) {
114  for (Int_t i(0); i<nBinsX_; ++i) {
115  Int_t binNo = histos_.front()->GetBin(i+1,j+1);
116  std::vector<Int_t>& truBins = contribs_[binNo];
117  truBins.reserve(nHist);
118  for (Int_t k(0); k<nHist; ++k) {
119  Double_t content = histos_[k]->GetBinContent(binNo);
120  if (content>0.0) {
121  truBins.push_back(k);
122  }
123  }
124  }
125  }
126 }
127 
128 void LauScfMap::listBinCentres( std::vector<Double_t>& xCoords, std::vector<Double_t>& yCoords) const
129 {
130  // Create the list of fake points, located at the centres of the
131  // true bins, that we will add to the data points, so as to cache
132  // the DP amplitudes, scfFractions and jacobians at those points.
133  // that have non-zero contributions in that reco bin
134 
135  const TAxis* xAxis = histos_.front()->GetXaxis();
136  Double_t xMax = xAxis->GetXmax();
137  Double_t xMin = xAxis->GetXmin();
138  Double_t xIncrement = (Double_t)((xMax - xMin)/nBinsX_);
139 
140  const TAxis* yAxis = histos_.front()->GetYaxis();
141  Double_t yMax = yAxis->GetXmax();
142  Double_t yMin = yAxis->GetXmin();
143  Double_t yIncrement = (Double_t)((yMax - yMin)/nBinsY_);
144 
145  // Loop over each histogram bin
146  Double_t yCoord = yMin + yIncrement/2;
147  for (Int_t j(1); j<=nBinsY_; ++j) {
148  Double_t xCoord = xMin + xIncrement/2;
149  for (Int_t i(1); i<=nBinsX_; ++i) {
150  xCoords.push_back(xCoord);
151  yCoords.push_back(yCoord);
152  xCoord += xIncrement;
153  }
154  yCoord += yIncrement;
155  }
156 }
157 
158 Int_t LauScfMap::binNumber(Double_t xCoord, Double_t yCoord) const
159 {
160  const TH2* histo = histos_.front();
161  if (histo != 0) {
162  return histo->FindFixBin(xCoord,yCoord);
163  } else {
164  cerr<<"ERROR in LauScfMap::recoBin : No valid histograms found."<<endl;
165  return -1;
166  }
167 }
168 
169 const std::vector<Int_t>* LauScfMap::trueBins(Int_t recoBin) const
170 {
171  std::map< Int_t, std::vector<Int_t> >::const_iterator iter = contribs_.find(recoBin);
172  if (iter != contribs_.end()) {
173  return &(iter->second);
174  } else {
175  return 0;
176  }
177 }
178 
179 Double_t LauScfMap::prob(Int_t recoBin, Int_t trueBin) const
180 {
181  const TH2* histo = histos_[trueBin];
182  if (histo != 0) {
183  return histo->GetBinContent(recoBin);
184  } else {
185  cerr<<"ERROR in LauScfMap::prob : No histogram found for true bin "<<trueBin<<endl;
186  return 0.0;
187  }
188 }
189 
190 TH2* LauScfMap::trueHist(Int_t trueBin)
191 {
192  // Need to turn the histogram bin number into the vector element
193  Int_t x(0), y(0), z(0);
194  histos_.front()->GetBinXYZ( trueBin, x, y, z );
195 
196  Int_t theBin = nBinsX_*(y-1) + (x-1);
197 
198  if ( theBin < 0 || static_cast<UInt_t>(theBin) >= histos_.size() ) {
199  cerr<<"ERROR in LauScfMap::trueHist : No histogram found for true bin "<<trueBin<<", which corresponds to x="<<x<<", y="<<y<<", or entry "<<theBin<<" in the vector."<<endl;
200  gSystem->Exit(EXIT_FAILURE);
201  }
202 
203  TH2* histo = histos_[theBin];
204  if ( histo == 0 ) {
205  cerr<<"ERROR in LauScfMap::trueHist : Null histogram pointer found for true bin "<<trueBin<<", which corresponds to x="<<x<<", y="<<y<<", or entry "<<theBin<<" in the vector."<<endl;
206  gSystem->Exit(EXIT_FAILURE);
207  }
208 
209  return histo;
210 }
211 
ClassImp(LauAbsCoeffSet)
Int_t numberOfBins_
Number of bins in a 2D histogram (nBinsX_*nBinsY_)
Definition: LauScfMap.hh:130
TH2 * trueHist(Int_t trueBin)
Retrieve the migration histogram for trueBin.
Definition: LauScfMap.cc:190
void listBinCentres(std::vector< Double_t > &xCoords, std::vector< Double_t > &yCoords) const
Create lists of the co-ordinates of the centres of true bins.
Definition: LauScfMap.cc:128
const std::vector< Int_t > * trueBins(Int_t recoBin) const
Find which true bins contribute to the given reco bin.
Definition: LauScfMap.cc:169
File containing declaration of LauScfMap class.
void setHistos(const std::vector< const TH2 * > &histos)
Construct the smearing matrix from the supplied histograms.
Definition: LauScfMap.cc:61
Int_t binNumber(Double_t xCoord, Double_t yCoord) const
Find the global bin number for the given co-ordinates.
Definition: LauScfMap.cc:158
std::vector< TH2 * > histos_
The vector of two-dimensional histograms.
Definition: LauScfMap.hh:120
Int_t nBinsY_
Number of bins in the y-axis.
Definition: LauScfMap.hh:128
Int_t nBinsX_
Number of bins in the x-axis.
Definition: LauScfMap.hh:126
virtual ~LauScfMap()
Destructor.
Definition: LauScfMap.cc:54
Class for representing the 4D smearing matrix for mis-reconstructed signal (self cross feed) ...
Definition: LauScfMap.hh:43
std::map< Int_t, std::vector< Int_t > > contribs_
Map that links each reco global bin number and the vector of true bin indices into LauScfMap::histos_...
Definition: LauScfMap.hh:123
Double_t prob(Int_t recoBin, Int_t trueBin) const
Probability of a true event in the given true bin migrating to the reco bin.
Definition: LauScfMap.cc:179