00001
00002 #include "Rivet/Rivet.hh"
00003 #include "Rivet/RivetAIDA.hh"
00004 #include "Rivet/AnalysisHandler.hh"
00005 #include "Rivet/Analysis.hh"
00006 #include "Rivet/Tools/Logging.hh"
00007 using namespace AIDA;
00008
00009
00010 namespace Rivet {
00011
00012
00013 IAnalysisFactory& Analysis::analysisFactory() {
00014 return getHandler().analysisFactory();
00015 }
00016
00017
00018 ITree& Analysis::tree() {
00019 return getHandler().tree();
00020 }
00021
00022
00023 IHistogramFactory& Analysis::histogramFactory() {
00024 return getHandler().histogramFactory();
00025 }
00026
00027
00028 IDataPointSetFactory& Analysis::datapointsetFactory() {
00029 return getHandler().datapointsetFactory();
00030 }
00031
00032
00033 Log& Analysis::getLog() {
00034 string logname = "Rivet.Analysis." + getName();
00035 return Log::getLog(logname);
00036 }
00037
00038
00039 IHistogram1D* Analysis::bookHistogram1D(const size_t datasetId, const size_t xAxisId,
00040 const size_t yAxisId, const string& title) {
00041 stringstream axisCode;
00042 axisCode << "ds" << datasetId << "-x" << xAxisId << "-y" << yAxisId;
00043 const map<string, BinEdges> data = getBinEdges(getName());
00044 makeHistoDir();
00045 const string path = getHistoDir() + "/" + axisCode.str();
00046 return histogramFactory().createHistogram1D(path, title, data.find(axisCode.str())->second);
00047 }
00048
00049
00050 IHistogram1D* Analysis::bookHistogram1D(const string& name, const string& title,
00051 const size_t nbins, const double lower, const double upper) {
00052 makeHistoDir();
00053 const string path = getHistoDir() + "/" + name;
00054 return histogramFactory().createHistogram1D(path, title, nbins, lower, upper);
00055 }
00056
00057
00058 IHistogram1D* Analysis::bookHistogram1D(const string& name, const string& title,
00059 const vector<double>& binedges) {
00060 makeHistoDir();
00061 const string path = getHistoDir() + "/" + name;
00062 return histogramFactory().createHistogram1D(path, title, binedges);
00063 }
00064
00065
00066 IDataPointSet* Analysis::bookDataPointSet(const string& name, const string& title) {
00067 makeHistoDir();
00068 const string path = getHistoDir() + "/" + name;
00069 return datapointsetFactory().create(path, title, 2);
00070 }
00071
00072
00073 IDataPointSet* Analysis::bookDataPointSet(const string& name, const string& title,
00074 const size_t npts, const double lower, const double upper) {
00075 IDataPointSet* dps = bookDataPointSet(name, title);
00076 for (size_t pt = 0; pt < npts; ++pt) {
00077 const double binwidth = (upper-lower)/npts;
00078 const double bincentre = lower + (pt + 0.5) * binwidth;
00079 dps->addPoint();
00080 IMeasurement* meas = dps->point(pt)->coordinate(0);
00081 meas->setValue(bincentre);
00082 meas->setErrorPlus(binwidth/2.0);
00083 meas->setErrorMinus(binwidth/2.0);
00084 }
00085 return dps;
00086 }
00087
00088
00089 IDataPointSet* Analysis::bookDataPointSet(const size_t datasetId, const size_t xAxisId,
00090 const size_t yAxisId, const string& title) {
00091
00092 throw runtime_error("Auto-booking of DataPointSets is not yet implemented");
00093 }
00094
00095
00096 inline void Analysis::makeHistoDir() {
00097 if (!_madeHistoDir) {
00098 if (! getName().empty()) tree().mkdir(getHistoDir());
00099 _madeHistoDir = true;
00100 }
00101 }
00102
00103
00104 const Cuts Analysis::getCuts() const {
00105 Cuts totalCuts = _cuts;
00106 for (set<Projection*>::const_iterator p = _projections.begin(); p != _projections.end(); ++p) {
00107 totalCuts.addCuts((*p)->getCuts());
00108 }
00109 return totalCuts;
00110 }
00111
00112
00113 const bool Analysis::checkConsistency() const {
00114
00115 for (set<Projection*>::const_iterator p = _projections.begin(); p != _projections.end(); ++p) {
00116 if (! compatible(getBeams(), (*p)->getBeamPairs()) ) {
00117 throw runtime_error("Analysis " + getName() + " beams are inconsistent with "
00118 + "allowed beams for projection " + (*p)->getName());
00119 }
00120 }
00121
00122 getCuts().checkConsistency();
00123 return true;
00124 }
00125
00126
00127 set<Projection*> Analysis::getProjections() const {
00128 set<Projection*> totalProjections = _projections;
00129 for (set<Projection*>::const_iterator p = _projections.begin(); p != _projections.end(); ++p) {
00130 totalProjections.insert((*p)->getProjections().begin(), (*p)->getProjections().end());
00131 }
00132 return totalProjections;
00133 }
00134
00135
00136 }