laura is hosted by Hepforge, IPPP Durham
Laura++  v3r5
A maximum likelihood fitting package for performing Dalitz-plot analysis.
LauEmbeddedData.cc
Go to the documentation of this file.
1 
2 /*
3 Copyright 2007 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 #include <vector>
31 using std::cerr;
32 using std::endl;
33 
34 #include "TRandom.h"
35 
36 #include "LauIsobarDynamics.hh"
37 #include "LauEmbeddedData.hh"
38 #include "LauKinematics.hh"
39 #include "LauRandom.hh"
40 
42 
43 
44 LauEmbeddedData::LauEmbeddedData(const TString& fileName, const TString& treeName, Bool_t allowReuseOfEvents) :
45  theDataTree_(new LauFitDataTree(fileName,treeName)),
46  reuseEvents_(allowReuseOfEvents)
47 {
48 }
49 
51 {
52  delete theDataTree_;
53 }
54 
56 {
57  if ( theDataTree_ == 0 ) {
58  cerr<<"ERROR in LauEmbeddedData::findBranches : Invalid pointer to the data tree object."<<endl;
59  return kFALSE;
60  }
61 
62  Bool_t branchesReadOK = theDataTree_->findBranches();
63  if ( ! branchesReadOK ) {
64  cerr<<"ERROR in LauEmbeddedData::findBranches : Problem finding branches."<<endl;
65  return kFALSE;
66  }
67 
69 
70  return kTRUE;
71 }
72 
74 {
75  if (!theDataTree_) {
76  cerr<<"ERROR in LauEmbeddedData::getReweightedEvent : Invalid pointer to the data tree object."<<endl;
77  return kFALSE;
78  }
79 
80  if (!dynamics) {
81  cerr<<"ERROR in LauEmbeddedData::getReweightedEvent : Amplitude model is null."<<endl;
82  return kFALSE;
83  }
84 
85  UInt_t numEvents = this->nEvents();
86  UInt_t iEvt(0);
87 
88  // First select a random event within the embedded data sample
89  if (this->reuseEvents()) {
90  iEvt = LauRandom::randomFun()->Integer(numEvents);
91  } else {
92  if (this->nUsedEvents() == numEvents) {
93  cerr<<"ERROR in LauEmbeddedData::getReweightedEvent : Have already used all events in the tree."<<endl;
94  return kFALSE;
95  }
96  Bool_t ok(kFALSE);
97  while (!ok) {
98  iEvt = LauRandom::randomFun()->Integer(numEvents);
99  ok = usedEvents_.insert(iEvt).second;
100  }
101  }
102 
103  // Retrieve the data for the selected event
104  theData_ = theDataTree_->getData(iEvt);
105 
106  LauKinematics* kinematics = dynamics->getKinematics();
107 
108  if (kinematics != 0) {
109 
110  // Get the true m13Sq, m23Sq variables.
111  Double_t m13Sq_MC = this->getValue("m13Sq_MC");
112  Double_t m23Sq_MC = this->getValue("m23Sq_MC");
113 
114  if (kinematics->withinDPLimits(m13Sq_MC,m23Sq_MC)) {
115 
116  // Update the kinematics with the true m13Sq, m23Sq variables
117  kinematics->updateKinematics(m13Sq_MC, m23Sq_MC);
118 
119  // Use this event or not, according to whether the amplitude model selects it.
120  // The LauIsobarDynamics uses an accept/reject method based on the
121  // ratio of the current to maximum ASq value. Other models may use alternative methods,
122  // but they must provide a yes/no answer if the event is accepted.
123  Bool_t gotReweightedEvent = dynamics->gotReweightedEvent();
124  if (gotReweightedEvent == kTRUE) {
125 
126  // Event is accepted.
127  // Update the kinematics to use the reco variables.
128  Double_t m13Sq = this->getValue("m13Sq");
129  Double_t m23Sq = this->getValue("m23Sq");
130  kinematics->updateKinematics(m13Sq, m23Sq);
131 
132  if (LauIsobarDynamics::GenOK != dynamics->checkToyMC(kFALSE,kFALSE)) {
133  return kFALSE;
134  }
135 
136  } else {
137 
138  // Recursively run this function until we get an accepted event
139  return this->getReweightedEvent(dynamics);
140 
141  }
142 
143  } else {
144 
145  cerr<<"WARNING in LauEmbeddedData::getReweightedEvent : Skipping event "<<iEvt<<", which isn't within the DP boundary."<<endl;
146  return this->getReweightedEvent(dynamics);
147 
148  }
149  }
150 
151  return kTRUE;
152 }
153 
155 {
156  if (!theDataTree_) {
157  cerr<<"ERROR in LauEmbeddedData::getEmbeddedEvent : Invalid pointer to the data tree object."<<endl;
158  return;
159  }
160  UInt_t numEvents = this->nEvents();
161  UInt_t iEvt(0);
162  if (this->reuseEvents()) {
163  iEvt = LauRandom::randomFun()->Integer(numEvents);
164  } else {
165  if (this->nUsedEvents() == numEvents) {
166  cerr<<"ERROR in LauEmbeddedData::getEmbeddedEvent : Have already used all events in the tree."<<endl;
167  return;
168  }
169  Bool_t ok(kFALSE);
170  while (!ok) {
171  iEvt = LauRandom::randomFun()->Integer(numEvents);
172  ok = usedEvents_.insert(iEvt).second;
173  }
174  }
175  theData_ = theDataTree_->getData(iEvt);
176 
177  if (kinematics!=0) {
178  Double_t m13Sq = this->getValue("m13Sq");
179  Double_t m23Sq = this->getValue("m23Sq");
180  if (kinematics->withinDPLimits(m13Sq,m23Sq)) {
181  kinematics->updateKinematics(m13Sq,m23Sq);
182  } else {
183  cerr<<"WARNING in LauEmbeddedData::getEmbeddedEvent : Skipping event that isn't within the DP boundary."<<endl;
184  this->getEmbeddedEvent(kinematics);
185  }
186  }
187 }
188 
189 Double_t LauEmbeddedData::getValue(const TString& name) const
190 {
191  LauFitData::const_iterator iter = theData_.find(name);
192  if (iter == theData_.end()) {
193  cerr<<"ERROR in LauEmbeddedData::getValue : Could not find branch \""<<name<<"\" in embedded event."<<endl;
194  return 0.0;
195  } else {
196  return iter->second;
197  }
198 }
199 
200 LauFitData LauEmbeddedData::getValues(const std::vector<TString>& names) const
201 {
202  LauFitData retVal;
203 
204  for ( std::vector<TString>::const_iterator iter = names.begin(); iter != names.end(); ++iter ) {
205  const TString& name = (*iter);
206  LauFitData::const_iterator data_iter = theData_.find(name);
207  if ( data_iter == theData_.end() ) {
208  cerr<<"WARNING in LauEmbeddedData::getValues : Could not find branch \""<<name<<"\" in embedded event."<<endl;
209  } else {
210  retVal.insert( *data_iter );
211  }
212  }
213 
214  return retVal;
215 }
216 
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...
Bool_t findBranches()
Find all of the branches in the tree.
TRandom * randomFun()
Access the singleton random number generator with a particular seed.
Definition: LauRandom.cc:34
UInt_t nEvents() const
Retrieve the number of events.
ClassImp(LauAbsCoeffSet)
Bool_t getReweightedEvent(LauIsobarDynamics *dynamics)
Retrieve an event from the data sample, applying an accept/reject based on the given DP model...
const TString & name() const
The parameter name.
const LauKinematics * getKinematics() const
Retrieve the Dalitz plot kinematics.
void readAllData()
Read all events from the tree.
Bool_t reuseEvents() const
Boolean determining whether events should be reused.
LauFitDataTree * theDataTree_
The structure containing the data.
std::map< TString, Double_t > LauFitData
Type for holding event data.
std::set< UInt_t > usedEvents_
Used events.
Double_t getValue(const TString &name) const
Get the value of a specified branch.
File containing declaration of LauKinematics class.
File containing declaration of LauEmbeddedData class.
File containing declaration of LauIsobarDynamics class.
LauFitData getValues(const std::vector< TString > &names) const
Get values of specified branches.
Class to store the data for embedding in toy experiments.
void getEmbeddedEvent(LauKinematics *kinematics)
Retrieve an event from the data sample.
void updateKinematics(const Double_t m13Sq, const Double_t m23Sq)
Update all kinematic quantities based on the DP co-ordinates m13Sq and m23Sq.
const LauFitData & getData(UInt_t iEvt) const
Retrieve the data for a given event.
File containing LauRandom namespace.
Bool_t gotReweightedEvent()
Calculates whether an event with the current kinematics should be accepted in order to produce a dist...
UInt_t nUsedEvents() const
Retrieve the number of events that have already been sampled.
virtual ~LauEmbeddedData()
Destructor.
Class for defining signal dynamics using the isobar model.
ToyMCStatus checkToyMC(Bool_t printErrorMessages=kTRUE, Bool_t printInfoMessages=kFALSE)
Check the status of the toy MC generation.
LauFitData theData_
The data for the currently retrieved event.
Class for calculating 3-body kinematic quantities.
Bool_t findBranches()
Find and read the branches in data tree.
Class to store the input fit variables.