MINT2
Chi2BoxSet.cpp
Go to the documentation of this file.
1 #include "Mint/IDalitzEvent.h"
2 #include "Mint/Chi2BoxSet.h"
4 
5 #include "Mint/FitAmpSum.h"
6 
7 using namespace std;
8 using namespace MINT;
9 
12  , _integCalc(0)
13  , _normFactor(1)
14 {
15 }
17  , const counted_ptr<IIntegrationCalculator>& integPtr)
19  , _integCalc(integPtr)
20  , _normFactor(1)
21 {
22  Chi2Box b(pat);
23  add(b);
24 }
26  , const counted_ptr<IIntegrationCalculator>& integPtr)
28  , _integCalc(integPtr)
29  , _normFactor(1)
30 {
31  Chi2Box b(area);
32  add(b);
33 }
35  : MINT::PolymorphVector<Chi2Box>(other)
36  , _integCalc(0)
37  , _normFactor(1)
38 {
39 }
41  : MINT::PolymorphVector<Chi2Box>(other)
42  , _integCalc(0)
43  , _histoData(other._histoData)
44  , _histoMC(other._histoMC)
45  , _normFactor(other._normFactor)
46 {
47  if(0 != other._integCalc){
49  _integCalc = newCP;
50  }
51 }
52 
53 void Chi2BoxSet::add(const Chi2Box& box){
54  this->push_back(box);
55 }
56 
57 void Chi2BoxSet::add(const Chi2BoxSet& boxSet){
58  for(unsigned int i=0; i<boxSet.size(); i++){
59  this->add(boxSet[i]);
60  }
61 }
62 
64  for(unsigned int i=0; i < this->size(); i++){
65  (*this)[i].resetEventCounts();
66  }
67 }
69  for(unsigned int i=0; i < this->size(); i++){
70  if ((*this)[i].addData(evt)){
71  _histoData.addEvent(evt);
72  return true;
73  }
74  }
75  return false;
76 }
78  for(unsigned int i=0; i < this->size(); i++){
79  if ((*this)[i].addData(evt)){
80  _histoData.addEvent(*evt);
81  return true;
82  }
83  }
84  return false;
85 }
86 bool Chi2BoxSet::addMC(IDalitzEvent& evt, double weight){
87  for(unsigned int i=0; i < this->size(); i++){
88  if((*this)[i].addMC(evt, weight)){
89  _histoMC.addEvent(evt, weight);
90  if(0 != _integCalc)_integCalc->addEvent(&evt);
91  return true;
92  }
93  }
94  return false;
95 }
96 bool Chi2BoxSet::addMC(IDalitzEvent* evt, double weight){
97  bool dbThis=false;
98  if(dbThis) {
99  cout << "Chi2BoxSet::addMC for pointers called with evt = "
100  << evt << endl;
101  }
102  for(unsigned int i=0; i < this->size(); i++){
103  if((*this)[i].addMC(evt, weight)){
104  _histoMC.addEvent(*evt, weight);
105  if(0 != _integCalc)_integCalc->addEvent(evt);
106  return true;
107  }
108  }
109  return false;
110 }
111 void Chi2BoxSet::printBoxInfo(std::ostream& os) const{
112  os << "Chi2BoxSet with " << this->size() << " sub-box";
113  if(this->size() > 1) os << "es";
114  os << ": ";
115  for(unsigned int i=0; i < this->size(); i++){
116  os << "\n " << i << ") " << (*this)[i];
117  }
118  if(0 != _integCalc){
121  os << "\n sorted fractions in this box\n"
122  << f << endl;
123  }
124  os << "\n--------------------------------------------------------\n" << endl;
125 
126 }
127 int Chi2BoxSet::nData() const{
128  int sum=0;
129  for(unsigned int i=0; i < this->size(); i++){
130  sum += (*this)[i].nData();
131  }
132  return sum;
133 }
134 int Chi2BoxSet::nMC() const{
135  int sum=0;
136  for(unsigned int i=0; i < this->size(); i++){
137  sum += (*this)[i].nMC();
138  }
139  return sum;
140 }
141 double Chi2BoxSet::weightedMC() const{
142  double sum=0;
143  for(unsigned int i=0; i < this->size(); i++){
144  sum += (*this)[i].weightedMC();
145  }
146  return sum;
147 }
148 double Chi2BoxSet::weightedMC2() const{
149  double sum=0;
150  for(unsigned int i=0; i < this->size(); i++){
151  sum += (*this)[i].weightedMC2();
152  }
153  return sum;
154 }
155 
156 // keep changing my mind which one is right...
157 double Chi2BoxSet::rmsMC(int ) const{
158  return weightedMC2();
159 }
160 
161 /*
162 double Chi2BoxSet::rmsMC(int Ntotal) const{
163  bool dbThis=false;
164  double dN = (double) Ntotal;
165  double msq = weightedMC2() /(dN);
166  double m = weightedMC() /(dN);
167  if(dbThis){
168  cout << "Chi2BoxSet::rmsMC() "
169  << " msq " << msq << " m " << m << " m*m " << m*m
170  << " rms " << msq - m*m
171  << endl;
172  }
173  // this treats events that didn't get into the
174  // box as events with weight 0.
175  // The variance on the weights is
176  // Var(w) = msq - m*m
177  // The variance on the sum of weights
178  // is therefore (msq - m*m) * dN
179  return (msq - m*m) * dN;
180 }
181 */
182 
183 void Chi2BoxSet::setHistoColour(Color_t fcolor){
184  setFillColour(fcolor);
185  setLineColour(fcolor);
186 }
187 void Chi2BoxSet::setFillColour(Color_t fcolor){
188  histoData().setFillColour(fcolor);
189  histoMC().setFillColour(fcolor);
190 }
191 void Chi2BoxSet::setLineColour(Color_t fcolor){
192  histoData().setLineColour(fcolor);
193  histoMC().setLineColour(fcolor);
194 }
195 
197  return _histoData;
198 }
200  return _histoData;
201 }
203  return _histoMC;
204 }
206  return _histoMC;
207 }
208 
209 double Chi2BoxSet::chi2(double normFactorPassed) const{
210  double nf=normFactorPassed;
211  if(nf < 0){
212  nf = normFactor();
213  }
214 
215  int n_data = this->nData();
216  double weight_mc = this->weightedMC() * nf;
217 
218  double var_mc = this->weightedMC2() * nf*nf;
219  double varData_expected = weight_mc;
220 
221  double varData;
222  if(0 != varData_expected) varData = varData_expected;
223  else varData = n_data;
224 
225  double var = varData + var_mc;
226 
227  double delta_N = n_data - weight_mc;
228  double dNSq = delta_N * delta_N;
229  double chi2;
230  if( dNSq < var * 1.e-20) chi2=0; // catches legit. 0-entry cases
231  else chi2 = dNSq / var;
232 
233  return chi2;
234 }
235 
236 std::ostream& operator<<(std::ostream& os, const Chi2BoxSet& c2bs){
237  c2bs.print(os);
238  return os;
239 }
240 //
void add(const Chi2Box &box)
Definition: Chi2BoxSet.cpp:53
void resetEventCounts()
Definition: Chi2BoxSet.cpp:63
MINT::counted_ptr< IIntegrationCalculator > _integCalc
Definition: Chi2BoxSet.h:20
double chi2(double normFactorPassed=-1) const
Definition: Chi2BoxSet.cpp:209
virtual MINT::counted_ptr< IIntegrationCalculator > clone_IIntegrationCalculator() const =0
void push_back(const Chi2Box &c)
int nMC() const
Definition: Chi2BoxSet.cpp:134
bool addMC(IDalitzEvent &evt, double weight)
Definition: Chi2BoxSet.cpp:86
void setFillColour(Color_t fcolor)
void printBoxInfo(std::ostream &os=std::cout) const
Definition: Chi2BoxSet.cpp:111
double weightedMC2() const
Definition: Chi2BoxSet.cpp:148
void setHistoColour(Color_t fcolor)
Definition: Chi2BoxSet.cpp:183
double rmsMC(int Ntotal) const
Definition: Chi2BoxSet.cpp:157
double weightedMC() const
Definition: Chi2BoxSet.cpp:141
virtual FitFractionList getFractions() const =0
void setLineColour(Color_t fcolor)
DalitzHistoSet & histoMC()
Definition: Chi2BoxSet.cpp:202
void setLineColour(Color_t fcolor)
Definition: Chi2BoxSet.cpp:191
void addEvent(const IDalitzEvent &evt, double weight=1)
unsigned int size() const
virtual void addEvent(IDalitzEvent *evtPtr, double weight=1)=0
double normFactor() const
Definition: Chi2BoxSet.h:64
DalitzHistoSet _histoData
Definition: Chi2BoxSet.h:22
void print(std::ostream &os=std::cout) const
Definition: Chi2BoxSet.h:53
int nData() const
Definition: Chi2BoxSet.cpp:127
void sortByMagnitudeDecending()
void setFillColour(Color_t fcolor)
Definition: Chi2BoxSet.cpp:187
DalitzHistoSet & histoData()
Definition: Chi2BoxSet.cpp:196
bool addData(const IDalitzEvent &evt)
Definition: Chi2BoxSet.cpp:68
std::ostream & operator<<(std::ostream &os, const Chi2BoxSet &c2bs)
Definition: Chi2BoxSet.cpp:236
DalitzHistoSet _histoMC
Definition: Chi2BoxSet.h:22