17 #include <sys/types.h> 24 #include "TObjArray.h" 35 : _units(
GeV*
GeV), _h(0), _c(), _pat()
36 , _name(
"noName"), _tree(0), _patForTree()
45 : _units(units), _nbins(bins), _h(0), _c(), _pat()
46 , _name(
"noName"), _tree(0), _patForTree()
94 : _units(other._units)
95 , _nbins(other._nbins)
101 , _patForTree(other._patForTree)
107 cout <<
"Error in DalitzHistogram copy constructor" 114 cout <<
"DalitzHistogram copy ctor" << endl;
115 cout <<
"pat before: " << other.
_pat 116 <<
", and after " <<
_pat << endl;
124 if(0 != other.
histo()){
127 cout <<
"Error in DalitzHistogram = operator" 153 TString c_out = c_in.
name();
154 for (
unsigned int i = 1; i< pat_in.
size(); i++)
157 c_out.ReplaceAll(sij,pat_in[i].
name());
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");
167 c_out.ReplaceAll(
",",
" ");
192 for(std::map<DalitzCoordKey, DalitzCoordinate>::iterator it =
_c.
begin();
193 it !=
_c.
end(); it++){
202 it->second.setMin(mi);
203 it->second.setMax(ma);
211 cout <<
"Error in DalitzHistogram::init: local_h = " << local_h << endl;
214 local_h->SetDirectory(0);
215 local_h->SetNameTitle(
hname().c_str(),
"");
217 local_h->SetLineWidth(2);
219 std::string unitsName;
224 else if(
_units ==
eV*
eV) unitsName =
"eV^{2}";
229 std::string XLabel = (string)
smartTitle().c_str()+
" [" + (string)unitsName +
"]";
230 local_h->GetXaxis()->SetTitle(XLabel.c_str());
231 local_h->GetXaxis()->SetTitleSize();
233 double bw = (ma - mi)/((
double)
_nbins);
235 sprintf(
s,
"%f", bw);
237 std::string YLabel =
"Yield / " + st +
" " + unitsName;
239 local_h->GetYaxis()->SetTitle(YLabel.c_str());
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)." 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." 264 (*this) = addMeToYou;
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." 278 _h->Add((addMeToYou.
histo().get()), weight);
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)." 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." 301 cout <<
"Error DalitzHistogram::multiply: _h = " <<
_h << endl;
302 throw "should not happen";
305 _c = multiplyWith.
_c;
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." 318 _h->Multiply((multiplyWith.
histo().get()));
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." 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." 341 cout <<
"Error in DalitzHistogram::divide: _h = " <<
_h << endl;
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." 358 _h->Divide((divideBy.
histo().get()));
363 cout <<
"Error in DalitzHistogram::addEvent: trying to fill empty histogram" 375 if(0 !=
_h)
_h->SetTitle(title.c_str());
384 ,
const std::string& drawOpt
385 ,
const std::string& format
387 if(0 ==
_h)
return false;
390 _h->Draw(drawOpt.c_str());
391 can.Print(fname.c_str());
451 mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO
456 int zeroForSuccess = 0;
457 zeroForSuccess |= mkdir( (asSubdirOf ).c_str(), mode );
458 zeroForSuccess |= mkdir( (asSubdirOf +
"/" +
dirName() ).c_str(), mode );
459 return (0 == zeroForSuccess);
469 ,
const char* theName){
471 if(0 != theName)
_name = theName;
482 for(std::string::const_iterator it =
name().begin();
483 it !=
name().end(); it++){
484 if(
'(' == *it ||
')'== *it)
s +=
"_";
485 else if(
',' == *it)
s +=
"_";
494 ,
const char* theName)
const{
501 return asSubdirOf +
"/" + dir +
"/value.txt";
504 ,
const char* theName)
const{
511 return asSubdirOf +
"/" + dir +
"/histo.root";
517 , NamedParameterBase::QUIET);
519 ,NamedParameterBase::QUIET);
521 , NamedParameterBase::QUIET);
523 , NamedParameterBase::QUIET);
525 , NamedParameterBase::QUIET);
529 n_c = (std::vector<int>)
_c.
begin()->first;
536 ofstream os(fname.c_str());
538 cout <<
"ERROR in DalitzHistogram::saveValues of \n\t" <<
name()
539 <<
"\n\t unable to create file: " 540 <<
"\n\t" << fname << endl;
554 ,
const char* theName){
557 if(dbThis)cout <<
"trying fname = " << fname << endl;
595 cout <<
"DalitzHistogram::saveHisto( " << inDir <<
" ) got called" 601 if(0 ==
_h)
return false;
607 cout <<
"DalitzHistogram::saveHisto: tryring to save " << fn
610 TFile* f = TFile::Open(fn.c_str(),
"RECREATE");
612 cout <<
"DalitzHistogram::saveHisto(const std::string& inDir)" 613 <<
" failed to open file " << fn << endl;
617 cout <<
"file isOpen " << f->IsOpen() << endl;
618 cout <<
"file isWritable " << f->IsWritable() << endl;
620 if(! f->IsWritable()){
621 cout <<
"File " << fn <<
" not writeable" << endl;
626 cout <<
"cd'ed to file" << endl;
627 cout <<
"number of entries in _h " <<
_h->GetEntries() << endl;
628 cout <<
"now about to write " << endl;
631 if(dbThis) cout <<
"done writing. now closing" << endl;
634 if(dbThis) cout <<
"closed it. Now returning true" << endl;
641 ,
const char* theName){
645 TFile* f = TFile::Open(fn.c_str(),
"READ");
647 cout <<
"ERROR in DalitzHistogram::retrieveHisto: cannot open file " 651 TH1* th = (TH1*) f->Get(
hname().c_str());
653 cout <<
"ERROR in DalitzHistogram::retrieveHisto" 654 <<
"\n\t can't find histogram " <<
hname()
655 <<
"\n\t in file " << fn << endl;
656 throw "errorRetrievingHisto";
660 cth->SetDirectory(0);
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;
674 ,
const std::string& baseName
675 ,
const std::string& format
676 ,
const std::string& fitDrawOpt
678 if(0 ==
_h)
return false;
684 cout <<
"Error in DalitzHistogram::drawWithFit, failed to clone histo h_c" 688 h_c->SetDirectory(0);
691 cout <<
"Error in DalitzHistogram::drawWithFit, failed to clone histo fit_c" 695 fit_c->SetDirectory(0);
696 fit_c->Scale(h_c->Integral()/fit_c->Integral());
698 double maxiThis = h_c->GetMaximum();
699 double maxiThat = fit_c->GetMaximum();
701 if(maxiThat > maxiThis) h_c->SetMaximum(maxiThat*1.05);
706 fit_c->SetLineWidth(3);
707 fit_c->SetLineColor(2);
708 fit_c->SetMarkerColor(2);
710 fit_c->Draw(fitDrawOpt.c_str());
711 can.Print(fname.c_str());
717 ,
const std::string& baseName
718 ,
const std::string& format
719 ,
const std::string& fitDrawOpt
721 if(0 ==
_h)
return false;
726 cout <<
"Error in DalitzHistogram::drawWithFit 2" 727 <<
", failed to clone histo h_c" 731 h_c->SetDirectory(0);
735 cout <<
"Error in DalitzHistogram::drawWithFit 2" 736 <<
", failed to clone histo fit_c" 740 fit_c->SetDirectory(0);
741 fit_c->Scale(h_c->Integral()/fit_c->Integral());
743 double maxiThis = h_c->GetMaximum();
744 double maxiThat = fit_c->GetMaximum();
746 if(maxiThat > maxiThis) h_c->SetMaximum(maxiThat*1.05);
751 fit_c->SetLineWidth(3);
752 fit_c->SetLineColor(2);
753 fit_c->SetMarkerColor(2);
755 fit_c->Draw(fitDrawOpt.c_str());
756 can.Print(fname.c_str());
764 ,
const std::string& baseName
765 ,
const std::string& drawOpt
766 ,
const std::string& format
768 if(0 ==
_h)
return false;
770 _h->Draw(drawOpt.c_str());
777 if(0 ==
_h)
return 0;
778 return _h->Integral();
bool retrieveHisto(const std::string &fromDir, const char *theName=0)
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()
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()
std::ostream & operator<<(std::ostream &os, const DalitzCoordSet &dcs)
void addEvent(const IDalitzEvent &evt, double weight=1)
void divide(const DalitzHistogram ÷By)
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
std::string convertInt(int number)
bool reloadFile(const std::string &id)
unsigned int size() const
std::map< Key, Val >::iterator begin()
std::string anythingToString(const T &anything)
const std::string & htitle() const
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)
void multiply(const DalitzHistogram &multiplyWith)