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