MINT2
DalitzHistogram.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:58 GMT
3 #include "Mint/DalitzHistogram.h"
4 #include "Mint/NamedParameter.h"
5 
7 #include "Mint/IDalitzEvent.h"
8 #include "Mint/Utils.h"
9 
10 #include <string>
11 #include <algorithm>
12 #include <iostream>
13 #include <fstream>
14 #include <cstdio>
15 #include <sstream>
16 
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 
20 #include "TCanvas.h"
21 #include "TFile.h"
22 #include "TTree.h"
23 #include "TBranch.h"
24 #include "TObjArray.h"
25 #include "TH1D.h"
26 #include "TH2D.h"
27 
28 #include "TROOT.h"
29 #include "TRint.h"
30 
31 using namespace std;
32 using namespace MINT;
33 
35  : _units(GeV*GeV), _h(0), _c(), _pat()
36  , _name("noName"), _tree(0), _patForTree()
37 {
38 }
39 
41  , const DalitzEventPattern& pat
42  , int bins
43  , double units
44  )
45  : _units(units), _nbins(bins), _h(0), _c(), _pat()
46  , _name("noName"), _tree(0), _patForTree()
47 {
48  init(c, pat);
49 }
50 
51 /*
52 DalitzHistogram::DalitzHistogram(TTree* t)
53  : _units(GeV*GeV), _h(0), _c(), _pat()
54  , _name("noName"), _tree(0), _patForTree()
55 {
56  double *u = 0;
57  int *n = 0;
58  TH1 *h = 0;
59  std::vector<int> *c=0, *p=0;
60 
61  cout << "show event" << endl;
62  t->Show(0);
63  cout << "done that, setting addresses" << endl;
64  t->SetBranchAddress("units", &u);
65  t->SetBranchAddress("nbins", &n);
66  // t->SetBranchAddress("h", &h);
67  t->SetBranchAddress("c", &c);
68  t->SetBranchAddress("pat", &p);
69 
70  cout << "got to set addresses" << endl;
71 
72  _units = *u;
73  _nbins = *n;
74  counted_ptr<TH1> hptr((TH1*) h->Clone());
75  _h = hptr;
76  _c = *c;
77  _pat = *p;
78  // t->SetBranchAddress("name", &_name);
79 
80  cout << "units before Get " << _units << endl;
81  t->Show(0);
82  cout << "units after Get " << _units << endl;
83 
84  DalitzCoordinate co(*c);
85  _c = co;
86  DalitzEventPattern pa(*p);
87  _pat = pa;
88 
89  makeName();
90 }
91 */
92 
94  : _units(other._units)
95  , _nbins(other._nbins)
96  , _h(0)
97  , _c(other._c)
98  , _pat(other._pat)
99  , _name(other._name)
100  , _tree(0)
101  , _patForTree(other._patForTree)
102 {
103  bool dbThis=false;
104  if(0 != other._h){
105  _h = counted_ptr<TH1>((TH1*) other._h->Clone());
106  if(0 == _h){
107  cout << "Error in DalitzHistogram copy constructor"
108  << endl;
109  throw "oh man!";
110  }
111  _h->SetDirectory(0);
112  }
113  if(dbThis){
114  cout << "DalitzHistogram copy ctor" << endl;
115  cout << "pat before: " << other._pat
116  << ", and after " << _pat << endl;
117  }
118 }
119 
121 
122 }
124  if(0 != other.histo()){
125  _h = counted_ptr<TH1>((TH1*) other.histo()->Clone());
126  if(0 == _h){
127  cout << "Error in DalitzHistogram = operator"
128  << endl;
129  throw "oh man!";
130  }
131  _h->SetDirectory(0);
132  }else{
133  _h = counted_ptr<TH1>(0);
134  }
135  _nbins = other._nbins;
136  _c = other._c;
137  _pat = other._pat;
138  _name = other._name;
139  _tree = 0;
140  _patForTree = other._patForTree;
141  return *this;
142 }
143 std::string convertInt(int number)
144 {
145  stringstream ss;//create a stringstream
146  ss << number;//add number to the stream
147  return ss.str();//return a string with the contents of the stream
148 }
150  , const DalitzEventPattern& pat_in)
151 {
152 // pat_in
153  TString c_out = c_in.name();
154  for (unsigned int i = 1; i< pat_in.size(); i++)
155  {
156  std::string sij = convertInt(i);
157  c_out.ReplaceAll(sij,pat_in[i].name());
158  }
159  c_out.ReplaceAll("sij","m^{2}");
160  c_out.ReplaceAll("K+","K^{+}");
161  c_out.ReplaceAll("pi+","#pi^{+}");
162  c_out.ReplaceAll("pi-","#pi^{-}");
163  c_out.ReplaceAll("Jpsi0","J/#psi");
164  c_out.ReplaceAll("psi0","#psi");
165  c_out.ReplaceAll("gamma0","#gamma");
166 
167  c_out.ReplaceAll(","," ");
168  _smartTitle = c_out;
169 }
170 
171 const std::string DalitzHistogram::smartTitle() const
172 {
173  return _smartTitle;
174 }
176  , const DalitzEventPattern& pat_in
177  , int bins
178  , double units
179  ){
180 
181  // this needs to change!
182  _c = c_in;
183  _pat = pat_in;
184  _nbins = bins;
185  _units = units;
187 
188  smartTitle(c_in,pat_in);
189 
190 
191  double mi=0, ma=0;
192  for(std::map<DalitzCoordKey, DalitzCoordinate>::iterator it = _c.begin();
193  it != _c.end(); it++){
194  double eps = 0.1;
195 
196  mi = _pat.sijMin(it->second)/_units;
197  ma = _pat.sijMax(it->second)/_units;
198 
199  mi -= (ma-mi)*eps;
200  ma += (ma-mi)*eps;
201 
202  it->second.setMin(mi);
203  it->second.setMax(ma);
204  }
205 
206  makeName();
207 
208  counted_ptr<TH1D> local_h(new TH1D(name().c_str(), name().c_str()
209  , _nbins, mi, ma));
210  if(0 == local_h){
211  cout << "Error in DalitzHistogram::init: local_h = " << local_h << endl;
212  throw "annoying";
213  }
214  local_h->SetDirectory(0);
215  local_h->SetNameTitle(hname().c_str(), "");// smartTitle().c_str());
216  local_h->Sumw2();
217  local_h->SetLineWidth(2);
218 
219  std::string unitsName;
220  if (_units == TeV*TeV) unitsName = "TeV^{2}";
221  else if(_units == GeV*GeV) unitsName = "GeV^{2}";
222  else if(_units == MeV*MeV) unitsName = "MeV^{2}";
223  else if(_units == keV*keV) unitsName = "keV^{2}";
224  else if(_units == eV* eV) unitsName = "eV^{2}";
225  else{
226  unitsName = anythingToString((int) (_units/(GeV*GeV))) + " GeV^{2}";
227  }
228 
229  std::string XLabel = (string)smartTitle().c_str()+ " [" + (string)unitsName + "]";
230  local_h->GetXaxis()->SetTitle(XLabel.c_str());
231  local_h->GetXaxis()->SetTitleSize();
232 
233  double bw = (ma - mi)/((double)_nbins);
234  char s[100]={'\0'};
235  sprintf(s, "%f", bw);
236  std::string st(s);
237  std::string YLabel = "Yield / " + st + " " + unitsName;
238 
239  local_h->GetYaxis()->SetTitle(YLabel.c_str());
240 
241  _h = local_h;
242 
243  return;
244 }
245 
246 
247 void DalitzHistogram::add(const DalitzHistogram& addMeToYou, double weight){
248  bool dbThis=false;
249 
250  if(0 == addMeToYou.histo()){
251  cout << "WARNING in DalitzHistogram::add(const DalitzHistogram&): "
252  << " Trying to add a DalitzHistogram w/o histogram to me"
253  << " I'll treat it as a zero (i.e. I'll do nothing)."
254  << endl;
255  return;
256  }
257  if(0 == histo()){
258  if(dbThis){
259  cout << "WARNING in DalitzHistogram::add(const DalitzHistogram&): "
260  << " Trying to add a DalitzHistogram to me although I have"
261  << " no histogram myself - treating myself as zero."
262  << endl;
263  }
264  (*this) = addMeToYou;
265  makeName();
266  _h->SetNameTitle(hname().c_str(), htitle().c_str());
267  // same as before, but repeated for robustness - in case
268  // the other histogram had a funny name.
269  return;
270  }
271  if(_c != addMeToYou._c){
272  cout << "WARNING in DalitzHistogram::add(const DalitzHistogram&): "
273  << " adding histograms for different co-ordinates!"
274  << "\n\t" << _c << " != " << addMeToYou._c
275  << "\n\t I'll go ahead with it, but it might not be what you want."
276  << endl;
277  }
278  _h->Add((addMeToYou.histo().get()), weight);
279  return;
280 }
281 void DalitzHistogram::multiply(const DalitzHistogram& multiplyWith){
282  bool dbThis=false;
283 
284  if(0 == multiplyWith.histo()){
285  cout << "WARNING in DalitzHistogram::multiply(const DalitzHistogram&): "
286  << " Trying to mulitply a DalitzHistogram w/o histogram to me"
287  << " I'll treat it as a zero (i.e. I'll clear myself of entries)."
288  << endl;
289  this->clearHisto();
290  return;
291  }
292  if(0 == histo()){
293  if(dbThis){
294  cout << "WARNING in DalitzHistogram::multiply(const DalitzHistogram&): "
295  << " Trying to multiply a DalitzHistogram to me although I have"
296  << " no histogram myself - treating myself as zero."
297  << endl;
298  }
299  _h = counted_ptr<TH1>((TH1*) multiplyWith.histo()->Clone());
300  if(0 == _h){
301  cout << "Error DalitzHistogram::multiply: _h = " << _h << endl;
302  throw "should not happen";
303  }
304  _h->SetDirectory(0);
305  _c = multiplyWith._c;
306  makeName();
307  _h->SetNameTitle(hname().c_str(), htitle().c_str());
308  _h->Clear();
309  return;
310  }
311  if(_c != multiplyWith._c){
312  cout << "WARNING in DalitzHistogram::multiply(const DalitzHistogram&): "
313  << " multiplying histograms for different co-ordinates!"
314  << "\n\t" << _c << " != " << multiplyWith._c
315  << "\n\t I'll go ahead with it, but it might not be what you want."
316  << endl;
317  }
318  _h->Multiply((multiplyWith.histo().get()));
319  return;
320 }
322  bool dbThis=false;
323 
324  if(0 == divideBy.histo()){
325  cout << "WARNING in DalitzHistogram::divide(const DalitzHistogram&): "
326  << " Trying to divide a DalitzHistogram w/o histogram to me"
327  << " I guess I should crash, but I'll do nothing."
328  << endl;
329  // this->clearHisto();
330  return;
331  }
332  if(0 == histo()){
333  if(dbThis){
334  cout << "WARNING in DalitzHistogram::divide(const DalitzHistogram&): "
335  << " Trying to divide a DalitzHistogram to me although I have"
336  << " no histogram myself - treating myself as zero."
337  << endl;
338  }
339  _h = counted_ptr<TH1>((TH1*) divideBy.histo()->Clone());
340  if(0 == _h){
341  cout << "Error in DalitzHistogram::divide: _h = " << _h << endl;
342  throw "mistake";
343  }
344  _h->SetDirectory(0);
345  _c = divideBy._c;
346  makeName();
347  _h->SetNameTitle(hname().c_str(), htitle().c_str());
348  _h->Clear();
349  return;
350  }
351  if(_c != divideBy._c){
352  cout << "WARNING in DalitzHistogram::divide(const DalitzHistogram&): "
353  << " divideing histograms for different co-ordinates!"
354  << "\n\t" << _c << " != " << divideBy._c
355  << "\n\t I'll go ahead with it, but it might not be what you want."
356  << endl;
357  }
358  _h->Divide((divideBy.histo().get()));
359  return;
360 }
361 void DalitzHistogram::addEvent(const IDalitzEvent& evt, double weight){
362  if(0 == _h){
363  cout << "Error in DalitzHistogram::addEvent: trying to fill empty histogram"
364  << endl;
365  return;
366  }
367  _h->Fill(evt.sij(_c.begin()->second)/_units, weight);
368 }
369 
370 void DalitzHistogram::scale(double sf){
371  if(0 == _h) return;
372  _h->Scale(sf);
373 }
374 void DalitzHistogram::setTitle(const std::string& title){
375  if(0 != _h) _h->SetTitle(title.c_str());
376 }
378  if(0 == _h) return;
379  _h->Clear();
380  //_h->Scale(0.0);
381 }
382 
383 bool DalitzHistogram::draw(const std::string& baseName // =""
384  , const std::string& drawOpt// =""
385  , const std::string& format// = "eps"
386  ) const{
387  if(0 == _h) return false;
388  string fname = baseName + _c.nameFileSave() + "." + format;
389  TCanvas can;
390  _h->Draw(drawOpt.c_str());
391  can.Print(fname.c_str());
392  return true;
393 }
394 
396  _name = _c.name();
397 }
398 
399 /*
400 TTree* DalitzHistogram::makeTree() const{
401  _tree = new TTree((name()).c_str(), (name()).c_str());
402  _tree->Branch("units", const_cast<double*> (&_units));
403  _tree->Branch("nbins", const_cast<int*>(&_nbins));
404  cout << "TH1 pointer: " << (TH1*) const_cast<TH1*>( (TH1*) (_h.get()))
405  << endl;
406  _tree->Branch("h", (TH1*) const_cast<TH1*>( (TH1*) (_h.get())));
407  _tree->Branch("c", const_cast<std::vector<int>*>((std::vector<int>*)&_c));
408  _tree->Branch("pat", const_cast<std::vector<int>*>(&_patForTree));
409  return _tree;
410 }
411 TTree* DalitzHistogram::ttree() const{
412  // if(0 == _tree) makeTree();
413  return _tree;
414 }
415 
416 bool DalitzHistogram::writeTree() const{
417  makeTree();
418  ttree()->Fill();
419 
420  ttree()->Write();
421  cout << "showin tree just written" << endl;
422  ttree()->Show();
423  //_h->Write();
424  return true;
425 }
426 */
427 bool DalitzHistogram::makeDirectory(const std::string& asSubdirOf)const{
428  /*
429  A mode is created from or'd permission bit masks defined
430  in <sys/stat.h>:
431  #define S_IRWXU 0000700 RWX mask for owner
432  #define S_IRUSR 0000400 R for owner
433  #define S_IWUSR 0000200 W for owner
434  #define S_IXUSR 0000100 X for owner
435 
436  #define S_IRWXG 0000070 RWX mask for group
437  #define S_IRGRP 0000040 R for group
438  #define S_IWGRP 0000020 W for group
439  #define S_IXGRP 0000010 X for group
440 
441  #define S_IRWXO 0000007 RWX mask for other
442  #define S_IROTH 0000004 R for other
443  #define S_IWOTH 0000002 W for other
444  #define S_IXOTH 0000001 X for other
445 
446  #define S_ISUID 0004000 set user id on execution
447  #define S_ISGID 0002000 set group id on execution
448  #define S_ISVTX 0001000 save swapped text even after use
449  */
450 
451  mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO
452  | S_ISUID | S_ISGID;
453  // see above for meaning. I want everybody to be allowed to read/write/exec.
454  // Not sure about the last two bits.
455 
456  int zeroForSuccess = 0;
457  zeroForSuccess |= mkdir( (asSubdirOf ).c_str(), mode );
458  zeroForSuccess |= mkdir( (asSubdirOf + "/" + dirName() ).c_str(), mode );
459  return (0 == zeroForSuccess);
460 }
461 
462 bool DalitzHistogram::saveAsDir(const std::string& asSubdirOf) const{
463  makeDirectory(asSubdirOf); // ignore error codes from mkdir, they could
464  saveValues(asSubdirOf);
465  saveHisto(asSubdirOf);
466  return true;
467 }
468 bool DalitzHistogram::retrieveFromDir(const std::string& asSubdirOf
469  , const char* theName){
470  bool success = true;
471  if(0 != theName) _name = theName;
472  success |= retrieveValues(asSubdirOf, theName);
473 
474  success |= retrieveHisto(asSubdirOf, theName);
475  return success;
476 }
477 const std::string& DalitzHistogram::dirName() const{
478  return name();
479 }
480 const std::string DalitzHistogram::hname() const{
481  std::string s;
482  for(std::string::const_iterator it = name().begin();
483  it != name().end(); it++){
484  if('(' == *it || ')'== *it) s += "_";
485  else if(',' == *it) s += "_";
486  else s+= *it;
487  }
488  return s;
489 }
490 const std::string& DalitzHistogram::htitle() const{
491  return name();
492 }
493 std::string DalitzHistogram::valueFileName(const std::string& asSubdirOf
494  , const char* theName)const{
495  std::string dir;
496  if(0 == theName){
497  dir=dirName();
498  }else{
499  dir=theName;
500  }
501  return asSubdirOf + "/" + dir + "/value.txt";
502 }
503 std::string DalitzHistogram::histoFileName(const std::string& asSubdirOf
504  , const char* theName)const{
505  std::string dir;
506  if(0 == theName){
507  dir=dirName();
508  }else{
509  dir=theName;
510  }
511  return asSubdirOf + "/" + dir + "/histo.root";
512 }
513 
514 bool DalitzHistogram::saveValues(const std::string& inDir) const{
515 
516  NamedParameter<double> n_units("units"
517  , NamedParameterBase::QUIET);
518  NamedParameter<int> n_nbins("nbins"
519  ,NamedParameterBase::QUIET);
520  NamedParameter<int> n_c("c"
521  , NamedParameterBase::QUIET);
522  NamedParameter<int> n_pat("pat"
523  , NamedParameterBase::QUIET);
524  NamedParameter<std::string> n_name("name"
525  , NamedParameterBase::QUIET);
526 
527  n_units = _units;
528  n_nbins = _nbins;
529  n_c = (std::vector<int>) _c.begin()->first; // needs to change
530  // cout << "pat = " << _pat << endl;
531  n_pat = _pat.getVectorOfInts();
532  // cout << "n_pat = " << n_pat << endl;
533  n_name = _name;
534 
535  std::string fname = valueFileName(inDir);
536  ofstream os(fname.c_str());
537  if(os.bad()){
538  cout << "ERROR in DalitzHistogram::saveValues of \n\t" << name()
539  << "\n\t unable to create file: "
540  << "\n\t" << fname << endl;
541  return false;
542  }
543  os << name()
544  << '\n' << n_units
545  << '\n' << n_nbins
546  << '\n' << n_c
547  << '\n' << n_pat
548  << '\n' << n_name
549  << endl;
550  os.close();
551  return true;
552 }
553 bool DalitzHistogram::retrieveValues(const std::string& fromDirectory
554  , const char* theName){
555  bool dbThis=false;
556  std::string fname = valueFileName(fromDirectory, theName);
557  if(dbThis)cout << "trying fname = " << fname << endl;
558  NamedParameter<double> n_units("units"
559  , fname.c_str()
560  //, NamedParameterBase::QUIET
561  );
562  n_units.reloadFile(fname.c_str());
563  NamedParameter<int> n_nbins("nbins"
564  ,fname.c_str()
565  //, NamedParameterBase::QUIET
566  );
567  NamedParameter<int> n_c("c"
568  , fname.c_str()
569  //, NamedParameterBase::QUIET
570  );
571  NamedParameter<int> n_pat("pat"
572  , fname.c_str()
573  //, NamedParameterBase::QUIET
574  );
575  NamedParameter<std::string> n_name("name"
576  , fname.c_str()
577  //, NamedParameterBase::QUIET
578  );
579 
580  _units = n_units;
581  _nbins = n_nbins;
582  DalitzCoordinate co(n_c.getVector());
583  _c = (DalitzCoordSet) co;
584  DalitzEventPattern pa(n_pat.getVector());
585  _pat = pa;
586  //cout << "after reading in, the pattern is " << _pat << endl;
587  _name = n_name;
588 
589  return true;
590 }
591 
592 bool DalitzHistogram::saveHisto(const std::string& inDir) const{
593  bool dbThis=false;
594  if(false && dbThis){
595  cout << "DalitzHistogram::saveHisto( " << inDir << " ) got called"
596  << endl;
597  }
598 
599  std::string fn = histoFileName(inDir);
600 
601  if(0 == _h) return false;
602 
603  //_h->SaveAs(fn.c_str());
604  //return true;
605 
606  if(dbThis){
607  cout << "DalitzHistogram::saveHisto: tryring to save " << fn
608  << endl;
609  }
610  TFile* f = TFile::Open(fn.c_str(), "RECREATE");
611  if(0 == f){
612  cout << "DalitzHistogram::saveHisto(const std::string& inDir)"
613  << " failed to open file " << fn << endl;
614  return false;
615  }
616  if(dbThis){
617  cout << "file isOpen " << f->IsOpen() << endl;
618  cout << "file isWritable " << f->IsWritable() << endl;
619  }
620  if(! f->IsWritable()){
621  cout << "File " << fn << " not writeable" << endl;
622  throw "damn";
623  }
624  f->cd();
625  if(dbThis){
626  cout << "cd'ed to file" << endl;
627  cout << "number of entries in _h " << _h->GetEntries() << endl;
628  cout << "now about to write " << endl;
629  }
630  _h->Write();
631  if(dbThis) cout << "done writing. now closing" << endl;
632  f->Close();
633  //h->SetDirectory(0);
634  if(dbThis) cout << "closed it. Now returning true" << endl;
635  //delete f;
636  return true;
637 
638 }
639 
640 bool DalitzHistogram::retrieveHisto(const std::string& fromDir
641  , const char* theName){
642  bool dbThis=false;
643  std::string fn = histoFileName(fromDir, theName);
644  // _name = theName();
645  TFile* f = TFile::Open(fn.c_str(), "READ");
646  if(0 == f){
647  cout << "ERROR in DalitzHistogram::retrieveHisto: cannot open file "
648  << fn << endl;
649  throw "bugger";
650  }
651  TH1* th = (TH1*) f->Get(hname().c_str());
652  if(0 == th){
653  cout << "ERROR in DalitzHistogram::retrieveHisto"
654  << "\n\t can't find histogram " << hname()
655  << "\n\t in file " << fn << endl;
656  throw "errorRetrievingHisto";
657  }
658  th->SetDirectory(0);
659  counted_ptr<TH1> cth((TH1*) th->Clone());
660  cth->SetDirectory(0);
661  _h = cth;
662  f->Close();
663  if(dbThis){
664  cout << "DalitzHistogram::retrieveHisto"
665  << "\n\t retrieved histogram " << hname()
666  << "\n\t in file " << fn << endl;
667  cout << "\t the ptr " << _h.get() << endl;
668  cout << "\t the name " << _h->GetTitle() << endl;
669  }
670  return true;
671 }
672 
674  , const std::string& baseName // =""
675  , const std::string& format
676  , const std::string& fitDrawOpt
677  ) const{
678  if(0 == _h) return false;
679  string fname = baseName + _c.nameFileSave() + "." + format;
680  TCanvas can;
681 
682  counted_ptr<TH1> h_c( (TH1*) histo()->Clone());
683  if(0 == h_c){
684  cout << "Error in DalitzHistogram::drawWithFit, failed to clone histo h_c"
685  << endl;
686  throw "rubbish";
687  }
688  h_c->SetDirectory(0);
689  counted_ptr<TH1> fit_c( (TH1*) fit.histo()->Clone());
690  if(0 == fit_c){
691  cout << "Error in DalitzHistogram::drawWithFit, failed to clone histo fit_c"
692  << endl;
693  throw "rubbish";
694  }
695  fit_c->SetDirectory(0);
696  fit_c->Scale(h_c->Integral()/fit_c->Integral());
697 
698  double maxiThis = h_c->GetMaximum();//Stored();
699  double maxiThat = fit_c->GetMaximum();//Stored();
700 
701  if(maxiThat > maxiThis) h_c->SetMaximum(maxiThat*1.05);
702  // else h_c->SetMaximum(maxiThis);
703 
704  h_c->Draw("E1");
705 
706  fit_c->SetLineWidth(3);
707  fit_c->SetLineColor(2);
708  fit_c->SetMarkerColor(2);
709 
710  fit_c->Draw(fitDrawOpt.c_str());
711  can.Print(fname.c_str());
712  return true;
713 }
714 
716  , const DalitzHistogram& fit
717  , const std::string& baseName // =""
718  , const std::string& format
719  , const std::string& fitDrawOpt
720  ) const{
721  if(0 == _h) return false;
722  string fname = baseName + _c.nameFileSave() + "." + format;
723 
724  counted_ptr<TH1> h_c( (TH1*) histo()->Clone());
725  if(0 == h_c){
726  cout << "Error in DalitzHistogram::drawWithFit 2"
727  << ", failed to clone histo h_c"
728  << endl;
729  throw "rubbish";
730  }
731  h_c->SetDirectory(0);
732 
733  counted_ptr<TH1> fit_c( (TH1*) fit.histo()->Clone());
734  if(0 == fit_c){
735  cout << "Error in DalitzHistogram::drawWithFit 2"
736  << ", failed to clone histo fit_c"
737  << endl;
738  throw "rubbish";
739  }
740  fit_c->SetDirectory(0);
741  fit_c->Scale(h_c->Integral()/fit_c->Integral());
742 
743  double maxiThis = h_c->GetMaximum();//Stored();
744  double maxiThat = fit_c->GetMaximum();//Stored();
745 
746  if(maxiThat > maxiThis) h_c->SetMaximum(maxiThat*1.05);
747  // else h_c->SetMaximum(maxiThis);
748 
749  h_c->Draw("E1");
750 
751  fit_c->SetLineWidth(3);
752  fit_c->SetLineColor(2);
753  fit_c->SetMarkerColor(2);
754 
755  fit_c->Draw(fitDrawOpt.c_str());
756  can.Print(fname.c_str());
757  return true;
758 }
760  return _h;
761 }
762 
763 bool DalitzHistogram::drawEachAmp( TCanvas& // can
764  , const std::string& baseName // =""
765  , const std::string& drawOpt// =""
766  , const std::string& format// = "eps"
767  ) const{
768  if(0 == _h) return false;
769  string fname = baseName + _c.nameFileSave() + "." + format;
770  _h->Draw(drawOpt.c_str());
771 // can.Print(fname.c_str());
772  return true;
773 }
774 
775 
777  if(0 == _h) return 0;
778  return _h->Integral();
779 }
780 
781 void DalitzCoordSet::print(std::ostream& os) const{
782  os << this->name();
783 }
784 
785 
786 // ----
787 
788 std::ostream& operator<<(std::ostream& os, const DalitzCoordSet& dcs){
789  dcs.print(os);
790  return os;
791 }
792 
793 // =====
bool retrieveHisto(const std::string &fromDir, const char *theName=0)
static const double keV
std::string valueFileName(const std::string &asSubdirOf=".", const char *theName=0) const
bool saveAsDir(const std::string &asSubdirOf=".") const
std::string nameFileSave() const
double sijMax(const MINT::PolymorphVector< int > &indices) const
DalitzHistogram & operator=(const DalitzHistogram &other)
void print(std::ostream &os) const
std::string histoFileName(const std::string &asSubdirOf=".", const char *theName=0) const
const std::string smartTitle() const
const std::string & dirName() const
bool saveHisto(const std::string &inDir=".") const
MINT::counted_ptr< TH1 > _h
std::vector< int > _patForTree
MINT::const_counted_ptr< TH1 > histo() const
MINT::counted_ptr< TH1 > getHisto()
static const double s
const std::string & name() const
bool retrieveValues(const std::string &fromDirectory, const char *theName=0)
void setTitle(const std::string &title)
virtual double sij(const MINT::PolymorphVector< int > &indices) const =0
void init(const DalitzCoordSet &c, const DalitzEventPattern &p, int bins=100, double units=GeV *GeV)
bool draw(const std::string &baseName="", const std::string &drawOpt="", const std::string &format="eps") const
std::map< Key, Val >::iterator end()
Definition: PolymorphMap.h:29
std::ostream & operator<<(std::ostream &os, const DalitzCoordSet &dcs)
void addEvent(const IDalitzEvent &evt, double weight=1)
void divide(const DalitzHistogram &divideBy)
static const double MeV
bool drawWithFit(const DalitzHistogram &fit, const std::string &baseName="", const std::string &format="eps", const std::string &fitDrawOpt="HIST C SAME") const
const std::string hname() const
std::vector< int > getVectorOfInts() const
bool retrieveFromDir(const std::string &asSubdirOf=".", const char *theName=0)
double sijMin(const MINT::PolymorphVector< int > &indices) const
bool saveValues(const std::string &inDir=".") const
bool makeDirectory(const std::string &asSubdirOf=".") const
DalitzCoordSet _c
std::string convertInt(int number)
static const double GeV
std::string name() const
bool reloadFile(const std::string &id)
unsigned int size() const
std::map< Key, Val >::iterator begin()
Definition: PolymorphMap.h:26
std::string anythingToString(const T &anything)
Definition: Utils.h:62
const std::string & htitle() const
double integral() const
std::string _name
bool drawEachAmp(TCanvas &can, const std::string &baseName="", const std::string &drawOpt="SAME", const std::string &format="eps") const
virtual ~DalitzHistogram()
void add(const DalitzHistogram &addMeToYou, double weight=1)
static const double TeV
static const double eV
std::string _smartTitle
void scale(double sf)
X * get() const
Definition: counted_ptr.h:123
void multiply(const DalitzHistogram &multiplyWith)
DalitzEventPattern _pat