MINT2
IntegCalculator.cpp
Go to the documentation of this file.
1 
2 #include "Mint/IntegCalculator.h"
3 #include "Mint/FitAmpPairList.h"
4 #include "Mint/Minimiser.h"
6 
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 
10 #include <iostream>
11 #include <sstream>
12 
13 
14 using namespace MINT;
15 using namespace std;
16 
17 //static
19  return "With_EfficiencyEffects";
20 }
22  return "Without_EfficiencyEffects";
23 }
24 
26  return _withEff;
27 }
29  return _noEff;
30 }
31 
32 
33 // constructors
35  : _withEff(), _noEff(), _onlyOneFitAmpPairList(false)
36 {
37 }
39  : _withEff(wEff), _noEff(wEff)
40 {
41  if(! wEff.haveEfficiency()){
43  }else{
44  _onlyOneFitAmpPairList = false;
46  }
47 }
48 
51  , _withEff(other._withEff)
52  , _noEff(other._noEff)
53  , _onlyOneFitAmpPairList(other._onlyOneFitAmpPairList)
54 {
55 }
59  return ptr;
60 }
61 
62 
63 // the rest
65  withEff().setEfficiency(eff);
66  _onlyOneFitAmpPairList = false;
67 }
71 }
72 
74  withEff().addAmps(a1, a2);
75  if(! _onlyOneFitAmpPairList) noEff().addAmps(a1, a2);
76 }
77 void IntegCalculator::addEvent(IDalitzEvent* evtPtr, double weight){
78  if(0 == evtPtr) return;
79  addEvent(*evtPtr, weight);
80 }
81 void IntegCalculator::addEvent(IDalitzEvent& evt, double weight){
82  withEff().addEvent(evt, weight);
83  if(! _onlyOneFitAmpPairList) noEff().addEvent(evt, weight);
84 }
86  , double weight){
87  if(0 == evtPtr) return;
88  addEvent(*evtPtr, weight);
89 }
90 void IntegCalculator::reAddEvent(IDalitzEvent* evtPtr, double weight){
91  if(0 == evtPtr) return;
92  reAddEvent(*evtPtr, weight);
93 }
94 void IntegCalculator::reAddEvent(IDalitzEvent& evt, double weight){
95  withEff().reAddEvent(evt, weight);
96  if(! _onlyOneFitAmpPairList) noEff().reAddEvent(evt, weight);
97 }
99  , double weight){
100  if(0 == evtPtr) return;
101  reAddEvent(*evtPtr, weight);
102 }
103 
105  bool sc=true;
106  sc |= withEff().add(other.withEff());
107  sc |= noEff().add(other.noEff());
108  return sc;
109 }
111  if(0 != other) return add(*other);
112  return true;
113 }
115  if(0 != other) return add(*other);
116  return true;
117 }
118 
120  bool sc=true;
121  sc |= withEff().append(other.withEff());
122  sc |= noEff().append(other.noEff());
123  return sc;
124 }
126  if(0 != other) return append(*other);
127  return true;
128 }
130  if(0 != other) return append(*other);
131  return true;
132 }
133 
135  int Nw = withEff().numEvents();
137  int Nn = noEff().numEvents();
138  if(Nw != Nn){
139  cout << "WARNING in IntegCalculator::numEvents()!"
140  << " number of events in FitAmpPairList with efficiency"
141  << " is not the same as without: "
142  << Nw << " != " << Nn << endl;
143  cout << "I'll return the one with efficiency, Nw = " << Nw << endl;
144  }
145  }
146  return Nw;
147 }
149  return withEff().integral();
150 }
152  return withEff().variance();
153 }
154 
155 std::complex<double> IntegCalculator::ComplexSum()const{
156  return withEff().ComplexSum();
157 }
158 
160  bool dbThis=false;
161  if(dbThis){
162  cout << "Fractions WITH efficiency (for debug only)" << endl;
163  withEff().makeAndStoreFractions("wrongFractions_WithEff","fitFractions_wrong_WithEff.root",mini);
164  cout << "\n and now Fractions WITHOUT efficiency"
165  << " (i.e. what you really want):" << endl;
166  }
168  else return noEff().makeAndStoreFractions(mini);
169 }
171  return noEff().getFractionChi2();
172 }
173 
175  return withEff().histoSet();
176 }
179 }
182 }
183 void IntegCalculator::saveEachAmpsHistograms(const std::string& prefix) const{
185  else return noEff().saveEachAmpsHistograms(prefix);
186 }
187 
188 std::vector<DalitzHistoSet> IntegCalculator::GetEachAmpsHistograms(){
190  else return noEff().GetEachAmpsHistograms();
191 }
192 
194  return withEff().interferenceHistoSet();
195 }
196 void IntegCalculator::saveInterferenceHistograms(const std::string& prefix) const{
198  else return noEff().saveInterferenceHistograms(prefix);
199 }
200 
201 std::vector<DalitzHistoSet> IntegCalculator::GetInterferenceHistograms(){
203  else return noEff().GetInterferenceHistograms();
204 }
205 
207  bool dbThis=false;
208  if(dbThis) cout << "IntegCalculator::doFinalStats called" << endl;
209  makeAndStoreFractions(mini);
210 }
211 
212 bool IntegCalculator::makeDirectories(const std::string& asSubdirOf)const{
213  /*
214  A mode is created from or'd permission bit masks defined
215  in <sys/stat.h>:
216  #define S_IRWXU 0000700 RWX mask for owner
217  #define S_IRUSR 0000400 R for owner
218  #define S_IWUSR 0000200 W for owner
219  #define S_IXUSR 0000100 X for owner
220 
221  #define S_IRWXG 0000070 RWX mask for group
222  #define S_IRGRP 0000040 R for group
223  #define S_IWGRP 0000020 W for group
224  #define S_IXGRP 0000010 X for group
225 
226  #define S_IRWXO 0000007 RWX mask for other
227  #define S_IROTH 0000004 R for other
228  #define S_IWOTH 0000002 W for other
229  #define S_IXOTH 0000001 X for other
230 
231  #define S_ISUID 0004000 set user id on execution
232  #define S_ISGID 0002000 set group id on execution
233  #define S_ISVTX 0001000 save swapped text even after use
234  */
235 
236  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO
237  | S_ISUID | S_ISGID;
238  // see above for meaning. I want everybody to be allowed to read/write/exec.
239  // Not sure about the last two bits.
240 
241  int zeroForSuccess = 0;
242  zeroForSuccess |= mkdir( (asSubdirOf ).c_str(), mode );
243  zeroForSuccess |= mkdir( (asSubdirOf+"/"+dirNameWithEff() ).c_str(), mode );
244  zeroForSuccess |= mkdir( (asSubdirOf+"/"+dirNameNoEff() ).c_str(), mode );
245  return (0 == zeroForSuccess);
246 }
247 
248 
249 bool IntegCalculator::save(const std::string& dirname) const{
250  bool sc=true;
251  makeDirectories(dirname);
252  sc &= withEff().save(dirname + "/" + dirNameWithEff());
254  sc &= withEff().save(dirname + "/" + dirNameNoEff());
255  }else{
256  sc &= noEff().save(dirname + "/" + dirNameNoEff());
257  }
258  return sc;
259 }
260 bool IntegCalculator::retrieve(const std::string& commaSeparatedList){
261  bool dbThis=false;
262  bool sc=true;
263  std::stringstream is(commaSeparatedList);
264  std::string dirname;
265  int counter=0;
266  while(getline(is, dirname, ',')){
267  dirname = ParsedParameterLine::removeLeadingAndTrailingBlanks(dirname);
268  if("" == dirname) continue;
269  if(dbThis){
270  cout << "IntegCalculator::retrieve: reading file: "
271  << dirname
272  << endl;
273  }
274  if(0 == counter){
275  this->retrieveSingle(dirname);
276  }else{
277  IntegCalculator n(*this);
278  sc &= n.retrieveSingle(dirname);
279  this->add(n);
280  }
281  counter++;
282  }
283  return sc;
284 }
285 bool IntegCalculator::retrieveSingle(const std::string& dirname){
286  bool sc=true;
287  sc &= withEff().retrieve(dirname + "/" + dirNameWithEff());
288  sc &= noEff().retrieve(dirname + "/" + dirNameNoEff());
289  return true;
290 }
291 
293  return withEff().getFractions();
294 }
295 
296 void IntegCalculator::print(ostream& os) const{
297  os << "IntegCalculator"
298  << "my FitAmpPairList with eff:\n" << withEff()
299  << "\n the integral: " << integral();
300 }
301 
303  bool needTo = withEff().needToReIntegrate();
304  if(! _onlyOneFitAmpPairList) needTo |= noEff().needToReIntegrate();
305  return needTo;
306 }
310 }
314 }
318 }
319 //
virtual bool append(const IntegCalculator &other)
virtual double getFractionChi2() const
virtual bool retrieve(const std::string &commaSeparatedList)
virtual bool append(const FitAmpPairList &otherListPtr)
virtual DalitzHistoSet interferenceHistoSet() const
virtual void saveInterferenceHistograms(const std::string &prefix) const
virtual DalitzHistoSet histoSet() const
virtual double integral() const
virtual bool save(const std::string &dirname) const
virtual void addAmps(FitAmplitude *a1, FitAmplitude *a2)
virtual FitFractionList getFractions() const
virtual void reAddEvent(IDalitzEvent &evt, double weight=1)
std::vector< DalitzHistoSet > GetEachAmpsHistograms()
virtual DalitzHistoSet un_normalised_histoSetRe() const
virtual void print(std::ostream &os=std::cout) const
void saveEachAmpsHistograms(const std::string &prefix) const
virtual DalitzHistoSet un_normalised_histoSetIm() const
virtual std::vector< DalitzHistoSet > GetInterferenceHistograms()
virtual double variance() const
std::vector< DalitzHistoSet > GetInterferenceHistograms()
static std::string dirNameWithEff()
FitAmpPairList & noEff()
virtual std::vector< DalitzHistoSet > GetEachAmpsHistograms()
virtual bool add(const FitAmpPairList &otherList)
virtual bool add(const IntegCalculator &other)
void setEfficiency(MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > eff)
bool needToReIntegrate() const
virtual double integral() const
virtual void addAmps(FitAmplitude *a1, FitAmplitude *a2)
virtual bool makeAndStoreFractions(MINT::Minimiser *mini=0)
virtual std::complex< double > ComplexSum() const
virtual int numEvents() const
virtual MINT::counted_ptr< IIntegrationCalculator > clone_IIntegrationCalculator() const
virtual bool makeAndStoreFractions(MINT::Minimiser *mini=0)
virtual double variance() const
virtual bool save(const std::string &asSubdirOf=".") const
virtual void doFinalStats(MINT::Minimiser *mini=0)
virtual void addEvent(IDalitzEvent *evtPtr, double weight=1)
virtual bool retrieveSingle(const std::string &dirname)
bool makeDirectories(const std::string &asSubdirOf=".") const
virtual void saveEachAmpsHistograms(const std::string &prefix) const
static std::string dirNameNoEff()
virtual DalitzHistoSet un_normalised_histoSetIm() const
virtual std::complex< double > ComplexSum() const
virtual double getFractionChi2() const
FitFractionList getFractions() const
void saveInterferenceHistograms(const std::string &prefix) const
bool haveEfficiency() const
DalitzHistoSet interferenceHistoSet() const
virtual int numEvents() const
virtual void addEvent(IDalitzEvent *evtPtr, double weight=1)
bool needToReIntegrate() const
void setEfficiency(MINT::counted_ptr< MINT::IReturnRealForEvent< IDalitzEvent > > eff)
virtual DalitzHistoSet histoSet() const
virtual DalitzHistoSet un_normalised_histoSetRe() const
FitAmpPairList _noEff
virtual bool retrieve(const std::string &asSubdirOf=".")
FitAmpPairList & withEff()
virtual void reAddEvent(IDalitzEvent *evtPtr, double weight=1)