rivet is hosted by Hepforge, IPPP Durham
Analysis.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Config/RivetCommon.hh"
00003 #include "Rivet/Analysis.hh"
00004 #include "Rivet/AnalysisHandler.hh"
00005 #include "Rivet/AnalysisInfo.hh"
00006 #include "Rivet/Tools/BeamConstraint.hh"
00007 
00008 namespace Rivet {
00009 
00010 
00011   Analysis::Analysis(const string& name)
00012     : _crossSection(-1.0),
00013       _gotCrossSection(false),
00014       _analysishandler(NULL)
00015   {
00016     ProjectionApplier::_allowProjReg = false;
00017     _defaultname = name;
00018 
00019     unique_ptr<AnalysisInfo> ai = AnalysisInfo::make(name);
00020     assert(ai);
00021     _info = move(ai);
00022     assert(_info);
00023   }
00024 
00025   double Analysis::sqrtS() const {
00026     return handler().sqrtS();
00027   }
00028 
00029   const ParticlePair& Analysis::beams() const {
00030     return handler().beams();
00031   }
00032 
00033   const PdgIdPair Analysis::beamIds() const {
00034     return handler().beamIds();
00035   }
00036 
00037 
00038   const string Analysis::histoDir() const {
00039     /// @todo Cache in a member variable
00040     string _histoDir;
00041     if (_histoDir.empty()) {
00042       _histoDir = "/" + name();
00043       if (handler().runName().length() > 0) {
00044         _histoDir = "/" + handler().runName() + _histoDir;
00045       }
00046       replace_all(_histoDir, "//", "/"); //< iterates until none
00047     }
00048     return _histoDir;
00049   }
00050 
00051 
00052   const string Analysis::histoPath(const string& hname) const {
00053     const string path = histoDir() + "/" + hname;
00054     return path;
00055   }
00056 
00057 
00058   const string Analysis::histoPath(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
00059     return histoDir() + "/" + makeAxisCode(datasetId, xAxisId, yAxisId);
00060   }
00061 
00062 
00063   const string Analysis::makeAxisCode(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
00064     stringstream axisCode;
00065     axisCode << "d";
00066     if (datasetId < 10) axisCode << 0;
00067     axisCode << datasetId;
00068     axisCode << "-x";
00069     if (xAxisId < 10) axisCode << 0;
00070     axisCode << xAxisId;
00071     axisCode << "-y";
00072     if (yAxisId < 10) axisCode << 0;
00073     axisCode << yAxisId;
00074     return axisCode.str();
00075   }
00076 
00077 
00078   Log& Analysis::getLog() const {
00079     string logname = "Rivet.Analysis." + name();
00080     return Log::getLog(logname);
00081   }
00082 
00083 
00084   size_t Analysis::numEvents() const {
00085     return handler().numEvents();
00086   }
00087 
00088 
00089   double Analysis::sumOfWeights() const {
00090     return handler().sumOfWeights();
00091   }
00092 
00093 
00094   ///////////////////////////////////////////
00095 
00096 
00097   bool Analysis::isCompatible(const ParticlePair& beams) const {
00098     return isCompatible(beams.first.pid(),  beams.second.pid(),
00099                         beams.first.energy(), beams.second.energy());
00100   }
00101 
00102 
00103   bool Analysis::isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const {
00104     PdgIdPair beams(beam1, beam2);
00105     pair<double,double> energies(e1, e2);
00106     return isCompatible(beams, energies);
00107   }
00108 
00109 
00110   bool Analysis::isCompatible(const PdgIdPair& beams, const pair<double,double>& energies) const {
00111     // First check the beam IDs
00112     bool beamIdsOk = false;
00113     foreach (const PdgIdPair& bp, requiredBeams()) {
00114       if (compatible(beams, bp)) {
00115         beamIdsOk =  true;
00116         break;
00117       }
00118     }
00119     if (!beamIdsOk) return false;
00120 
00121     // Next check that the energies are compatible (within 1% or 1 GeV, whichever is larger, for a bit of UI forgiveness)
00122 
00123     /// @todo Use some sort of standard ordering to improve comparisons, esp. when the two beams are different particles
00124     bool beamEnergiesOk = requiredEnergies().size() > 0 ? false : true;
00125     typedef pair<double,double> DoublePair;
00126     foreach (const DoublePair& ep, requiredEnergies()) {
00127       if ((fuzzyEquals(ep.first, energies.first, 0.01) && fuzzyEquals(ep.second, energies.second, 0.01)) ||
00128           (fuzzyEquals(ep.first, energies.second, 0.01) && fuzzyEquals(ep.second, energies.first, 0.01)) ||
00129           (abs(ep.first - energies.first) < 1*GeV && abs(ep.second - energies.second) < 1*GeV) ||
00130           (abs(ep.first - energies.second) < 1*GeV && abs(ep.second - energies.first) < 1*GeV)) {
00131         beamEnergiesOk =  true;
00132         break;
00133       }
00134     }
00135     return beamEnergiesOk;
00136 
00137     /// @todo Need to also check internal consistency of the analysis'
00138     /// beam requirements with those of the projections it uses.
00139   }
00140 
00141 
00142   ///////////////////////////////////////////
00143 
00144 
00145   Analysis& Analysis::setCrossSection(double xs) {
00146     _crossSection = xs;
00147     _gotCrossSection = true;
00148     return *this;
00149   }
00150 
00151   double Analysis::crossSection() const {
00152     if (!_gotCrossSection || std::isnan(_crossSection)) {
00153       string errMsg = "You did not set the cross section for the analysis " + name();
00154       throw Error(errMsg);
00155     }
00156     return _crossSection;
00157   }
00158 
00159   double Analysis::crossSectionPerEvent() const {
00160     const double sumW = sumOfWeights();
00161     assert(sumW != 0.0);
00162     return _crossSection / sumW;
00163   }
00164 
00165 
00166 
00167   ////////////////////////////////////////////////////////////
00168   // Histogramming
00169 
00170 
00171   void Analysis::_cacheRefData() const {
00172     if (_refdata.empty()) {
00173       MSG_TRACE("Getting refdata cache for paper " << name());
00174       _refdata = getRefData(name());
00175     }
00176   }
00177 
00178 
00179   const Scatter2D& Analysis::refData(const string& hname) const {
00180     _cacheRefData();
00181     MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
00182     if (!_refdata[hname]) {
00183       MSG_ERROR("Can't find reference histogram " << hname);
00184       throw Exception("Reference data " + hname + " not found.");
00185     }
00186     return dynamic_cast<Scatter2D&>(*_refdata[hname]);
00187   }
00188 
00189 
00190   const Scatter2D& Analysis::refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const {
00191     const string hname = makeAxisCode(datasetId, xAxisId, yAxisId);
00192     return refData(hname);
00193   }
00194 
00195 
00196   CounterPtr Analysis::bookCounter(const string& cname,
00197                                    const string& title) {
00198                                    // const string& xtitle,
00199                                    // const string& ytitle) {
00200     const string path = histoPath(cname);
00201     CounterPtr ctr = make_shared<Counter>(path, title);
00202     addAnalysisObject(ctr);
00203     MSG_TRACE("Made counter " << cname << " for " << name());
00204     // hist->setAnnotation("XLabel", xtitle);
00205     // hist->setAnnotation("YLabel", ytitle);
00206     return ctr;
00207   }
00208 
00209 
00210   CounterPtr Analysis::bookCounter(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
00211                                    const string& title) {
00212                                    // const string& xtitle,
00213                                    // const string& ytitle) {
00214     const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
00215     return bookCounter(axisCode, title);
00216   }
00217 
00218 
00219   Histo1DPtr Analysis::bookHisto1D(const string& hname,
00220                                    size_t nbins, double lower, double upper,
00221                                    const string& title,
00222                                    const string& xtitle,
00223                                    const string& ytitle) {
00224     const string path = histoPath(hname);
00225     Histo1DPtr hist = make_shared<Histo1D>(nbins, lower, upper, path, title);
00226     addAnalysisObject(hist);
00227     MSG_TRACE("Made histogram " << hname <<  " for " << name());
00228     hist->setAnnotation("XLabel", xtitle);
00229     hist->setAnnotation("YLabel", ytitle);
00230     return hist;
00231   }
00232 
00233 
00234   Histo1DPtr Analysis::bookHisto1D(const string& hname,
00235                                    const vector<double>& binedges,
00236                                    const string& title,
00237                                    const string& xtitle,
00238                                    const string& ytitle) {
00239     const string path = histoPath(hname);
00240     Histo1DPtr hist = make_shared<Histo1D>(binedges, path, title);
00241     addAnalysisObject(hist);
00242     MSG_TRACE("Made histogram " << hname <<  " for " << name());
00243     hist->setAnnotation("XLabel", xtitle);
00244     hist->setAnnotation("YLabel", ytitle);
00245     return hist;
00246   }
00247 
00248 
00249   Histo1DPtr Analysis::bookHisto1D(const string& hname,
00250                                    const Scatter2D& refscatter,
00251                                    const string& title,
00252                                    const string& xtitle,
00253                                    const string& ytitle) {
00254     const string path = histoPath(hname);
00255     Histo1DPtr hist = make_shared<Histo1D>(refscatter, path);
00256     addAnalysisObject(hist);
00257     MSG_TRACE("Made histogram " << hname <<  " for " << name());
00258     hist->setTitle(title);
00259     hist->setAnnotation("XLabel", xtitle);
00260     hist->setAnnotation("YLabel", ytitle);
00261     return hist;
00262   }
00263 
00264 
00265   Histo1DPtr Analysis::bookHisto1D(const string& hname,
00266                                    const string& title,
00267                                    const string& xtitle,
00268                                    const string& ytitle) {
00269     const Scatter2D& refdata = refData(hname);
00270     return bookHisto1D(hname, refdata, title, xtitle, ytitle);
00271   }
00272 
00273 
00274   Histo1DPtr Analysis::bookHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
00275                                    const string& title,
00276                                    const string& xtitle,
00277                                    const string& ytitle) {
00278     const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
00279     return bookHisto1D(axisCode, title, xtitle, ytitle);
00280   }
00281 
00282 
00283   /// @todo Add booking methods which take a path, titles and *a reference Scatter from which to book*
00284 
00285 
00286   /////////////////
00287 
00288 
00289   Histo2DPtr Analysis::bookHisto2D(const string& hname,
00290                                    size_t nxbins, double xlower, double xupper,
00291                                    size_t nybins, double ylower, double yupper,
00292                                    const string& title,
00293                                    const string& xtitle,
00294                                    const string& ytitle,
00295                                    const string& ztitle)
00296   {
00297     const string path = histoPath(hname);
00298     Histo2DPtr hist = make_shared<Histo2D>(nxbins, xlower, xupper, nybins, ylower, yupper, path, title);
00299     addAnalysisObject(hist);
00300     MSG_TRACE("Made 2D histogram " << hname <<  " for " << name());
00301     hist->setAnnotation("XLabel", xtitle);
00302     hist->setAnnotation("YLabel", ytitle);
00303     hist->setAnnotation("ZLabel", ztitle);
00304     return hist;
00305   }
00306 
00307 
00308   Histo2DPtr Analysis::bookHisto2D(const string& hname,
00309                                    const vector<double>& xbinedges,
00310                                    const vector<double>& ybinedges,
00311                                    const string& title,
00312                                    const string& xtitle,
00313                                    const string& ytitle,
00314                                    const string& ztitle)
00315   {
00316     const string path = histoPath(hname);
00317     Histo2DPtr hist = make_shared<Histo2D>(xbinedges, ybinedges, path, title);
00318     addAnalysisObject(hist);
00319     MSG_TRACE("Made 2D histogram " << hname <<  " for " << name());
00320     hist->setAnnotation("XLabel", xtitle);
00321     hist->setAnnotation("YLabel", ytitle);
00322     hist->setAnnotation("ZLabel", ztitle);
00323     return hist;
00324   }
00325 
00326 
00327   // Histo2DPtr Analysis::bookHisto2D(const string& hname,
00328   //                                  const Scatter3D& refscatter,
00329   //                                  const string& title="",
00330   //                                  const string& xtitle="",
00331   //                                  const string& ytitle="",
00332   //                                  const string& ztitle="") {
00333   //   const string path = histoPath(hname);
00334   //   Histo2DPtr hist( new Histo2D(refscatter, path) );
00335   //   addAnalysisObject(hist);
00336   //   MSG_TRACE("Made 2D histogram " << hname <<  " for " << name());
00337   //   hist->setTitle(title);
00338   //   hist->setAnnotation("XLabel", xtitle);
00339   //   hist->setAnnotation("YLabel", ytitle);
00340   //   hist->setAnnotation("ZLabel", ztitle);
00341   //   return hist;
00342   // }
00343 
00344 
00345   // Histo2DPtr Analysis::bookHisto2D(const string& hname,
00346   //                                  const string& title,
00347   //                                  const string& xtitle,
00348   //                                  const string& ytitle,
00349   //                                  const string& ztitle) {
00350   //   const Scatter3D& refdata = refData(hname);
00351   //   return bookHisto2D(hname, refdata, title, xtitle, ytitle, ztitle);
00352   // }
00353 
00354 
00355   // Histo2DPtr Analysis::bookHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
00356   //                                  const string& title,
00357   //                                  const string& xtitle,
00358   //                                  const string& ytitle,
00359   //                                  const string& ztitle) {
00360   //   const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
00361   //   return bookHisto2D(axisCode, title, xtitle, ytitle, ztitle);
00362   // }
00363 
00364 
00365   /////////////////
00366 
00367 
00368   Profile1DPtr Analysis::bookProfile1D(const string& hname,
00369                                        size_t nbins, double lower, double upper,
00370                                        const string& title,
00371                                        const string& xtitle,
00372                                        const string& ytitle) {
00373     const string path = histoPath(hname);
00374     Profile1DPtr prof = make_shared<Profile1D>(nbins, lower, upper, path, title);
00375     addAnalysisObject(prof);
00376     MSG_TRACE("Made profile histogram " << hname <<  " for " << name());
00377     prof->setAnnotation("XLabel", xtitle);
00378     prof->setAnnotation("YLabel", ytitle);
00379     return prof;
00380   }
00381 
00382 
00383   Profile1DPtr Analysis::bookProfile1D(const string& hname,
00384                                        const vector<double>& binedges,
00385                                        const string& title,
00386                                        const string& xtitle,
00387                                        const string& ytitle) {
00388     const string path = histoPath(hname);
00389     Profile1DPtr prof = make_shared<Profile1D>(binedges, path, title);
00390     addAnalysisObject(prof);
00391     MSG_TRACE("Made profile histogram " << hname <<  " for " << name());
00392     prof->setAnnotation("XLabel", xtitle);
00393     prof->setAnnotation("YLabel", ytitle);
00394     return prof;
00395   }
00396 
00397 
00398   Profile1DPtr Analysis::bookProfile1D(const string& hname,
00399                                        const Scatter2D& refscatter,
00400                                        const string& title,
00401                                        const string& xtitle,
00402                                        const string& ytitle) {
00403     const string path = histoPath(hname);
00404     Profile1DPtr prof = make_shared<Profile1D>(refscatter, path);
00405     addAnalysisObject(prof);
00406     MSG_TRACE("Made profile histogram " << hname <<  " for " << name());
00407     prof->setTitle(title);
00408     prof->setAnnotation("XLabel", xtitle);
00409     prof->setAnnotation("YLabel", ytitle);
00410     return prof;
00411   }
00412 
00413 
00414   Profile1DPtr Analysis::bookProfile1D(const string& hname,
00415                                        const string& title,
00416                                        const string& xtitle,
00417                                        const string& ytitle) {
00418     const Scatter2D& refdata = refData(hname);
00419     return bookProfile1D(hname, refdata, title, xtitle, ytitle);
00420   }
00421 
00422 
00423   Profile1DPtr Analysis::bookProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
00424                                        const string& title,
00425                                        const string& xtitle,
00426                                        const string& ytitle) {
00427     const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
00428     return bookProfile1D(axisCode, title, xtitle, ytitle);
00429   }
00430 
00431 
00432   ///////////////////
00433 
00434 
00435 
00436   Profile2DPtr Analysis::bookProfile2D(const string& hname,
00437                                    size_t nxbins, double xlower, double xupper,
00438                                    size_t nybins, double ylower, double yupper,
00439                                    const string& title,
00440                                    const string& xtitle,
00441                                    const string& ytitle,
00442                                    const string& ztitle)
00443   {
00444     const string path = histoPath(hname);
00445     Profile2DPtr prof = make_shared<Profile2D>(nxbins, xlower, xupper, nybins, ylower, yupper, path, title);
00446     addAnalysisObject(prof);
00447     MSG_TRACE("Made 2D profile histogram " << hname <<  " for " << name());
00448     prof->setAnnotation("XLabel", xtitle);
00449     prof->setAnnotation("YLabel", ytitle);
00450     prof->setAnnotation("ZLabel", ztitle);
00451     return prof;
00452   }
00453 
00454 
00455   Profile2DPtr Analysis::bookProfile2D(const string& hname,
00456                                    const vector<double>& xbinedges,
00457                                    const vector<double>& ybinedges,
00458                                    const string& title,
00459                                    const string& xtitle,
00460                                    const string& ytitle,
00461                                    const string& ztitle)
00462   {
00463     const string path = histoPath(hname);
00464     Profile2DPtr prof = make_shared<Profile2D>(xbinedges, ybinedges, path, title);
00465     addAnalysisObject(prof);
00466     MSG_TRACE("Made 2D profile histogram " << hname <<  " for " << name());
00467     prof->setAnnotation("XLabel", xtitle);
00468     prof->setAnnotation("YLabel", ytitle);
00469     prof->setAnnotation("ZLabel", ztitle);
00470     return prof;
00471   }
00472 
00473 
00474   // Profile2DPtr Analysis::bookProfile2D(const string& hname,
00475   //                                  const Scatter3D& refscatter,
00476   //                                  const string& title="",
00477   //                                  const string& xtitle="",
00478   //                                  const string& ytitle="",
00479   //                                  const string& ztitle="") {
00480   //   const string path = histoPath(hname);
00481   //   Profile2DPtr prof( new Profile2D(refscatter, path) );
00482   //   addAnalysisObject(prof);
00483   //   MSG_TRACE("Made 2D profile histogram " << hname <<  " for " << name());
00484   //   prof->setTitle(title);
00485   //   prof->setAnnotation("XLabel", xtitle);
00486   //   prof->setAnnotation("YLabel", ytitle);
00487   //   prof->setAnnotation("ZLabel", ztitle);
00488   //   return prof;
00489   // }
00490 
00491 
00492   // Profile2DPtr Analysis::bookProfile2D(const string& hname,
00493   //                                  const string& title,
00494   //                                  const string& xtitle,
00495   //                                  const string& ytitle,
00496   //                                  const string& ztitle) {
00497   //   const Scatter3D& refdata = refData(hname);
00498   //   return bookProfile2D(hname, refdata, title, xtitle, ytitle, ztitle);
00499   // }
00500 
00501 
00502   // Profile2DPtr Analysis::bookProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
00503   //                                  const string& title,
00504   //                                  const string& xtitle,
00505   //                                  const string& ytitle,
00506   //                                  const string& ztitle) {
00507   //   const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
00508   //   return bookProfile2D(axisCode, title, xtitle, ytitle, ztitle);
00509   // }
00510 
00511 
00512   /////////////////
00513 
00514 
00515   Scatter2DPtr Analysis::bookScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId,
00516                                        bool copy_pts,
00517                                        const string& title,
00518                                        const string& xtitle,
00519                                        const string& ytitle) {
00520     const string axisCode = makeAxisCode(datasetId, xAxisId, yAxisId);
00521     return bookScatter2D(axisCode, copy_pts, title, xtitle, ytitle);
00522   }
00523 
00524 
00525   Scatter2DPtr Analysis::bookScatter2D(const string& hname,
00526                                        bool copy_pts,
00527                                        const string& title,
00528                                        const string& xtitle,
00529                                        const string& ytitle) {
00530     Scatter2DPtr s;
00531     const string path = histoPath(hname);
00532     if (copy_pts) {
00533       const Scatter2D& refdata = refData(hname);
00534       s = make_shared<Scatter2D>(refdata, path);
00535       foreach (Point2D& p, s->points()) p.setY(0, 0);
00536     } else {
00537       s = make_shared<Scatter2D>(path);
00538     }
00539     addAnalysisObject(s);
00540     MSG_TRACE("Made scatter " << hname <<  " for " << name());
00541     s->setTitle(title);
00542     s->setAnnotation("XLabel", xtitle);
00543     s->setAnnotation("YLabel", ytitle);
00544     return s;
00545   }
00546 
00547 
00548   Scatter2DPtr Analysis::bookScatter2D(const string& hname,
00549                                        size_t npts, double lower, double upper,
00550                                        const string& title,
00551                                        const string& xtitle,
00552                                        const string& ytitle) {
00553     const string path = histoPath(hname);
00554     Scatter2DPtr s = make_shared<Scatter2D>(path);
00555     const double binwidth = (upper-lower)/npts;
00556     for (size_t pt = 0; pt < npts; ++pt) {
00557       const double bincentre = lower + (pt + 0.5) * binwidth;
00558       s->addPoint(bincentre, 0, binwidth/2.0, 0);
00559     }
00560     addAnalysisObject(s);
00561     MSG_TRACE("Made scatter " << hname <<  " for " << name());
00562     s->setTitle(title);
00563     s->setAnnotation("XLabel", xtitle);
00564     s->setAnnotation("YLabel", ytitle);
00565     return s;
00566   }
00567 
00568 
00569   Scatter2DPtr Analysis::bookScatter2D(const string& hname,
00570                                        const vector<double>& binedges,
00571                                        const string& title,
00572                                        const string& xtitle,
00573                                        const string& ytitle) {
00574     const string path = histoPath(hname);
00575     Scatter2DPtr s = make_shared<Scatter2D>(path);
00576     for (size_t pt = 0; pt < binedges.size()-1; ++pt) {
00577       const double bincentre = (binedges[pt] + binedges[pt+1]) / 2.0;
00578       const double binwidth = binedges[pt+1] - binedges[pt];
00579       s->addPoint(bincentre, 0, binwidth/2.0, 0);
00580     }
00581     addAnalysisObject(s);
00582     MSG_TRACE("Made scatter " << hname <<  " for " << name());
00583     s->setTitle(title);
00584     s->setAnnotation("XLabel", xtitle);
00585     s->setAnnotation("YLabel", ytitle);
00586     return s;
00587   }
00588 
00589 
00590   /////////////////////
00591 
00592 
00593   void Analysis::divide(CounterPtr c1, CounterPtr c2, Scatter1DPtr s) const {
00594     const string path = s->path();
00595     *s = *c1 / *c2;
00596     s->setPath(path);
00597   }
00598 
00599   void Analysis::divide(const Counter& c1, const Counter& c2, Scatter1DPtr s) const {
00600     const string path = s->path();
00601     *s = c1 / c2;
00602     s->setPath(path);
00603   }
00604 
00605 
00606   void Analysis::divide(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const {
00607     const string path = s->path();
00608     *s = *h1 / *h2;
00609     s->setPath(path);
00610   }
00611 
00612   void Analysis::divide(const Histo1D& h1, const Histo1D& h2, Scatter2DPtr s) const {
00613     const string path = s->path();
00614     *s = h1 / h2;
00615     s->setPath(path);
00616   }
00617 
00618 
00619   void Analysis::divide(Profile1DPtr p1, Profile1DPtr p2, Scatter2DPtr s) const {
00620     const string path = s->path();
00621     *s = *p1 / *p2;
00622     s->setPath(path);
00623   }
00624 
00625   void Analysis::divide(const Profile1D& p1, const Profile1D& p2, Scatter2DPtr s) const {
00626     const string path = s->path();
00627     *s = p1 / p2;
00628     s->setPath(path);
00629   }
00630 
00631 
00632   void Analysis::divide(Histo2DPtr h1, Histo2DPtr h2, Scatter3DPtr s) const {
00633     const string path = s->path();
00634     *s = *h1 / *h2;
00635     s->setPath(path);
00636   }
00637 
00638   void Analysis::divide(const Histo2D& h1, const Histo2D& h2, Scatter3DPtr s) const {
00639     const string path = s->path();
00640     *s = h1 / h2;
00641     s->setPath(path);
00642   }
00643 
00644 
00645   void Analysis::divide(Profile2DPtr p1, Profile2DPtr p2, Scatter3DPtr s) const {
00646     const string path = s->path();
00647     *s = *p1 / *p2;
00648     s->setPath(path);
00649   }
00650 
00651   void Analysis::divide(const Profile2D& p1, const Profile2D& p2, Scatter3DPtr s) const {
00652     const string path = s->path();
00653     *s = p1 / p2;
00654     s->setPath(path);
00655   }
00656 
00657 
00658   /// @todo Counter and Histo2D efficiencies and asymms
00659 
00660 
00661   void Analysis::efficiency(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const {
00662     const string path = s->path();
00663     *s = YODA::efficiency(*h1, *h2);
00664     s->setPath(path);
00665   }
00666 
00667   void Analysis::efficiency(const Histo1D& h1, const Histo1D& h2, Scatter2DPtr s) const {
00668     const string path = s->path();
00669     *s = YODA::efficiency(h1, h2);
00670     s->setPath(path);
00671   }
00672 
00673 
00674   void Analysis::asymm(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const {
00675     const string path = s->path();
00676     *s = YODA::asymm(*h1, *h2);
00677     s->setPath(path);
00678   }
00679 
00680   void Analysis::asymm(const Histo1D& h1, const Histo1D& h2, Scatter2DPtr s) const {
00681     const string path = s->path();
00682     *s = YODA::asymm(h1, h2);
00683     s->setPath(path);
00684   }
00685 
00686 
00687   void Analysis::scale(CounterPtr cnt, double factor) {
00688     if (!cnt) {
00689       MSG_WARNING("Failed to scale counter=NULL in analysis " << name() << " (scale=" << factor << ")");
00690       return;
00691     }
00692     if (std::isnan(factor) || std::isinf(factor)) {
00693       MSG_WARNING("Failed to scale counter=" << cnt->path() << " in analysis: " << name() << " (invalid scale factor = " << factor << ")");
00694       factor = 0;
00695     }
00696     MSG_TRACE("Scaling counter " << cnt->path() << " by factor " << factor);
00697     try {
00698       cnt->scaleW(factor);
00699     } catch (YODA::Exception& we) {
00700       MSG_WARNING("Could not scale counter " << cnt->path());
00701       return;
00702     }
00703   }
00704 
00705 
00706   void Analysis::normalize(Histo1DPtr histo, double norm, bool includeoverflows) {
00707     if (!histo) {
00708       MSG_WARNING("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << norm << ")");
00709       return;
00710     }
00711     MSG_TRACE("Normalizing histo " << histo->path() << " to " << norm);
00712     try {
00713       histo->normalize(norm, includeoverflows);
00714     } catch (YODA::Exception& we) {
00715       MSG_WARNING("Could not normalize histo " << histo->path());
00716       return;
00717     }
00718   }
00719 
00720 
00721   void Analysis::scale(Histo1DPtr histo, double factor) {
00722     if (!histo) {
00723       MSG_WARNING("Failed to scale histo=NULL in analysis " << name() << " (scale=" << factor << ")");
00724       return;
00725     }
00726     if (std::isnan(factor) || std::isinf(factor)) {
00727       MSG_WARNING("Failed to scale histo=" << histo->path() << " in analysis: " << name() << " (invalid scale factor = " << factor << ")");
00728       factor = 0;
00729     }
00730     MSG_TRACE("Scaling histo " << histo->path() << " by factor " << factor);
00731     try {
00732       histo->scaleW(factor);
00733     } catch (YODA::Exception& we) {
00734       MSG_WARNING("Could not scale histo " << histo->path());
00735       return;
00736     }
00737   }
00738 
00739 
00740   void Analysis::normalize(Histo2DPtr histo, double norm, bool includeoverflows) {
00741     if (!histo) {
00742       MSG_ERROR("Failed to normalize histo=NULL in analysis " << name() << " (norm=" << norm << ")");
00743       return;
00744     }
00745     MSG_TRACE("Normalizing histo " << histo->path() << " to " << norm);
00746     try {
00747       histo->normalize(norm, includeoverflows);
00748     } catch (YODA::Exception& we) {
00749       MSG_WARNING("Could not normalize histo " << histo->path());
00750       return;
00751     }
00752   }
00753 
00754 
00755   void Analysis::scale(Histo2DPtr histo, double factor) {
00756     if (!histo) {
00757       MSG_ERROR("Failed to scale histo=NULL in analysis " << name() << " (scale=" << factor << ")");
00758       return;
00759     }
00760     if (std::isnan(factor) || std::isinf(factor)) {
00761       MSG_ERROR("Failed to scale histo=" << histo->path() << " in analysis: " << name() << " (invalid scale factor = " << factor << ")");
00762       factor = 0;
00763     }
00764     MSG_TRACE("Scaling histo " << histo->path() << " by factor " << factor);
00765     try {
00766       histo->scaleW(factor);
00767     } catch (YODA::Exception& we) {
00768       MSG_WARNING("Could not scale histo " << histo->path());
00769       return;
00770     }
00771   }
00772 
00773 
00774   void Analysis::integrate(Histo1DPtr h, Scatter2DPtr s) const {
00775     // preserve the path info
00776     const string path = s->path();
00777     *s = toIntegralHisto(*h);
00778     s->setPath(path);
00779   }
00780 
00781   void Analysis::integrate(const Histo1D& h, Scatter2DPtr s) const {
00782     // preserve the path info
00783     const string path = s->path();
00784     *s = toIntegralHisto(h);
00785     s->setPath(path);
00786   }
00787 
00788 
00789   /// @todo 2D versions of integrate... defined how, exactly?!?
00790 
00791 
00792   //////////////////////////////////
00793 
00794 
00795   void Analysis::addAnalysisObject(AnalysisObjectPtr ao) {
00796     _analysisobjects.push_back(ao);
00797   }
00798 
00799   void Analysis::removeAnalysisObject(const string& path) {
00800     for (vector<AnalysisObjectPtr>::iterator it = _analysisobjects.begin();  it != _analysisobjects.end(); ++it) {
00801       if ((*it)->path() == path) {
00802         _analysisobjects.erase(it);
00803         break;
00804       }
00805     }
00806   }
00807 
00808   void Analysis::removeAnalysisObject(AnalysisObjectPtr ao) {
00809     for (vector<AnalysisObjectPtr>::iterator it = _analysisobjects.begin();  it != _analysisobjects.end(); ++it) {
00810       if (*it == ao) {
00811         _analysisobjects.erase(it);
00812         break;
00813       }
00814     }
00815  }
00816 
00817 
00818 }