Analysis.hh
Go to the documentation of this file.
00001 // -*- C++ -*- 00002 #ifndef RIVET_Analysis_HH 00003 #define RIVET_Analysis_HH 00004 00005 #include "Rivet/Config/RivetCommon.hh" 00006 #include "Rivet/AnalysisInfo.hh" 00007 #include "Rivet/Event.hh" 00008 #include "Rivet/Projection.hh" 00009 #include "Rivet/ProjectionApplier.hh" 00010 #include "Rivet/ProjectionHandler.hh" 00011 #include "Rivet/AnalysisLoader.hh" 00012 #include "Rivet/Tools/RivetYODA.hh" 00013 #include "Rivet/Tools/Logging.hh" 00014 #include "Rivet/Tools/ParticleUtils.hh" 00015 00016 00017 /// @def vetoEvent 00018 /// Preprocessor define for vetoing events, including the log message and return. 00019 #define vetoEvent \ 00020 do { MSG_DEBUG("Vetoing event on line " << __LINE__ << " of " << __FILE__); return; } while(0) 00021 00022 00023 namespace Rivet { 00024 00025 00026 // Forward declaration 00027 class AnalysisHandler; 00028 00029 /// @brief This is the base class of all analysis classes in Rivet. 00030 /// 00031 /// There are 00032 /// three virtual functions which should be implemented in base classes: 00033 /// 00034 /// void init() is called by Rivet before a run is started. Here the 00035 /// analysis class should book necessary histograms. The needed 00036 /// projections should probably rather be constructed in the 00037 /// constructor. 00038 /// 00039 /// void analyze(const Event&) is called once for each event. Here the 00040 /// analysis class should apply the necessary Projections and fill the 00041 /// histograms. 00042 /// 00043 /// void finalize() is called after a run is finished. Here the analysis 00044 /// class should do whatever manipulations are necessary on the 00045 /// histograms. Writing the histograms to a file is, however, done by 00046 /// the Rivet class. 00047 class Analysis : public ProjectionApplier { 00048 00049 /// The AnalysisHandler is a friend. 00050 friend class AnalysisHandler; 00051 00052 00053 public: 00054 00055 /// @name Standard constructors and destructors. 00056 //@{ 00057 00058 // /// The default constructor. 00059 // Analysis(); 00060 00061 /// Constructor 00062 Analysis(const std::string& name); 00063 00064 /// The destructor. 00065 virtual ~Analysis() {} 00066 00067 //@} 00068 00069 00070 public: 00071 00072 /// @name Main analysis methods 00073 //@{ 00074 00075 /// Initialize this analysis object. A concrete class should here 00076 /// book all necessary histograms. An overridden function must make 00077 /// sure it first calls the base class function. 00078 virtual void init() { } 00079 00080 /// Analyze one event. A concrete class should here apply the 00081 /// necessary projections on the \a event and fill the relevant 00082 /// histograms. An overridden function must make sure it first calls 00083 /// the base class function. 00084 virtual void analyze(const Event& event) = 0; 00085 00086 /// Finalize this analysis object. A concrete class should here make 00087 /// all necessary operations on the histograms. Writing the 00088 /// histograms to a file is, however, done by the Rivet class. An 00089 /// overridden function must make sure it first calls the base class 00090 /// function. 00091 virtual void finalize() { } 00092 00093 //@} 00094 00095 00096 public: 00097 00098 /// @name Metadata 00099 /// Metadata is used for querying from the command line and also for 00100 /// building web pages and the analysis pages in the Rivet manual. 00101 //@{ 00102 00103 /// Get the actual AnalysisInfo object in which all this metadata is stored. 00104 const AnalysisInfo& info() const { 00105 assert(_info.get() != 0 && "No AnalysisInfo object :O"); 00106 return *_info; 00107 } 00108 00109 /// @brief Get the name of the analysis. 00110 /// 00111 /// By default this is computed by combining the results of the experiment, 00112 /// year and Spires ID metadata methods and you should only override it if 00113 /// there's a good reason why those won't work. 00114 virtual std::string name() const { 00115 return (info().name().empty()) ? _defaultname : info().name(); 00116 } 00117 00118 /// Get the Inspire ID code for this analysis. 00119 virtual std::string inspireId() const { 00120 return info().inspireId(); 00121 } 00122 00123 /// Get the SPIRES ID code for this analysis (~deprecated). 00124 virtual std::string spiresId() const { 00125 return info().spiresId(); 00126 } 00127 00128 /// @brief Names & emails of paper/analysis authors. 00129 /// 00130 /// Names and email of authors in 'NAME <EMAIL>' format. The first 00131 /// name in the list should be the primary contact person. 00132 virtual std::vector<std::string> authors() const { 00133 return info().authors(); 00134 } 00135 00136 /// @brief Get a short description of the analysis. 00137 /// 00138 /// Short (one sentence) description used as an index entry. 00139 /// Use @a description() to provide full descriptive paragraphs 00140 /// of analysis details. 00141 virtual std::string summary() const { 00142 return info().summary(); 00143 } 00144 00145 /// @brief Get a full description of the analysis. 00146 /// 00147 /// Full textual description of this analysis, what it is useful for, 00148 /// what experimental techniques are applied, etc. Should be treated 00149 /// as a chunk of restructuredText (http://docutils.sourceforge.net/rst.html), 00150 /// with equations to be rendered as LaTeX with amsmath operators. 00151 virtual std::string description() const { 00152 return info().description(); 00153 } 00154 00155 /// @brief Information about the events needed as input for this analysis. 00156 /// 00157 /// Event types, energies, kinematic cuts, particles to be considered 00158 /// stable, etc. etc. Should be treated as a restructuredText bullet list 00159 /// (http://docutils.sourceforge.net/rst.html) 00160 virtual std::string runInfo() const { 00161 return info().runInfo(); 00162 } 00163 00164 /// Experiment which performed and published this analysis. 00165 virtual std::string experiment() const { 00166 return info().experiment(); 00167 } 00168 00169 /// Collider on which the experiment ran. 00170 virtual std::string collider() const { 00171 return info().collider(); 00172 } 00173 00174 /// When the original experimental analysis was published. 00175 virtual std::string year() const { 00176 return info().year(); 00177 } 00178 00179 /// Journal, and preprint references. 00180 virtual std::vector<std::string> references() const { 00181 return info().references(); 00182 } 00183 00184 /// BibTeX citation key for this article. 00185 virtual std::string bibKey() const { 00186 return info().bibKey(); 00187 } 00188 00189 /// BibTeX citation entry for this article. 00190 virtual std::string bibTeX() const { 00191 return info().bibTeX(); 00192 } 00193 00194 /// Whether this analysis is trusted (in any way!) 00195 virtual std::string status() const { 00196 return (info().status().empty()) ? "UNVALIDATED" : info().status(); 00197 } 00198 00199 /// Any work to be done on this analysis. 00200 virtual std::vector<std::string> todos() const { 00201 return info().todos(); 00202 } 00203 00204 00205 /// Return the allowed pairs of incoming beams required by this analysis. 00206 virtual const std::vector<PdgIdPair>& requiredBeams() const { 00207 return info().beams(); 00208 } 00209 /// Declare the allowed pairs of incoming beams required by this analysis. 00210 virtual Analysis& setRequiredBeams(const std::vector<PdgIdPair>& requiredBeams) { 00211 info().setBeams(requiredBeams); 00212 return *this; 00213 } 00214 00215 00216 /// Sets of valid beam energy pairs, in GeV 00217 virtual const std::vector<std::pair<double, double> >& requiredEnergies() const { 00218 return info().energies(); 00219 } 00220 /// Declare the list of valid beam energy pairs, in GeV 00221 virtual Analysis& setRequiredEnergies(const std::vector<std::pair<double, double> >& requiredEnergies) { 00222 info().setEnergies(requiredEnergies); 00223 return *this; 00224 } 00225 00226 00227 /// Return true if this analysis needs to know the process cross-section. 00228 /// @todo Remove this and require HepMC >= 2.06 00229 bool needsCrossSection() const { 00230 return info().needsCrossSection(); 00231 } 00232 /// Declare whether this analysis needs to know the process cross-section from the generator. 00233 /// @todo Remove this and require HepMC >= 2.06 00234 Analysis& setNeedsCrossSection(bool needed=true) { 00235 info().setNeedsCrossSection(needed); 00236 return *this; 00237 } 00238 00239 //@} 00240 00241 00242 /// @name Internal metadata modifying methods 00243 //@{ 00244 00245 /// Get the actual AnalysisInfo object in which all this metadata is stored (non-const). 00246 AnalysisInfo& info() { 00247 assert(_info.get() != 0 && "No AnalysisInfo object :O"); 00248 return *_info; 00249 } 00250 00251 //@} 00252 00253 00254 /// @name Run conditions 00255 //@{ 00256 00257 /// Incoming beams for this run 00258 const ParticlePair& beams() const; 00259 00260 /// Incoming beam IDs for this run 00261 const PdgIdPair beamIds() const; 00262 00263 /// Centre of mass energy for this run 00264 double sqrtS() const; 00265 00266 //@} 00267 00268 00269 /// @name Analysis / beam compatibility testing 00270 //@{ 00271 00272 /// Check if analysis is compatible with the provided beam particle IDs and energies 00273 bool isCompatible(const ParticlePair& beams) const; 00274 00275 /// Check if analysis is compatible with the provided beam particle IDs and energies 00276 bool isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const; 00277 00278 /// Check if analysis is compatible with the provided beam particle IDs and energies 00279 bool isCompatible(const PdgIdPair& beams, const std::pair<double,double>& energies) const; 00280 00281 //@} 00282 00283 00284 /// Set the cross section from the generator 00285 Analysis& setCrossSection(double xs); 00286 00287 /// Access the controlling AnalysisHandler object. 00288 AnalysisHandler& handler() const { return *_analysishandler; } 00289 00290 00291 protected: 00292 00293 /// Get a Log object based on the name() property of the calling analysis object. 00294 Log& getLog() const; 00295 00296 /// Get the process cross-section in pb. Throws if this hasn't been set. 00297 double crossSection() const; 00298 00299 /// Get the process cross-section per generated event in pb. Throws if this 00300 /// hasn't been set. 00301 double crossSectionPerEvent() const; 00302 00303 /// Get the number of events seen (via the analysis handler). Use in the 00304 /// finalize phase only. 00305 size_t numEvents() const; 00306 00307 /// Get the sum of event weights seen (via the analysis handler). Use in the 00308 /// finalize phase only. 00309 double sumOfWeights() const; 00310 00311 00312 protected: 00313 00314 /// @name Histogram paths 00315 //@{ 00316 00317 /// Get the canonical histogram "directory" path for this analysis. 00318 const std::string histoDir() const; 00319 00320 /// Get the canonical histogram path for the named histogram in this analysis. 00321 const std::string histoPath(const std::string& hname) const; 00322 00323 /// Get the canonical histogram path for the numbered histogram in this analysis. 00324 const std::string histoPath(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const; 00325 00326 /// Get the internal histogram name for given d, x and y (cf. HepData) 00327 const std::string makeAxisCode(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const; 00328 00329 //@} 00330 00331 00332 /// @name Histogram reference data 00333 //@{ 00334 00335 /// Get reference data for a named histo 00336 /// @todo Move to the templated version when we have C++11 and can have a default fn template type 00337 const YODA::Scatter2D& refData(const string& hname) const; 00338 00339 /// Get reference data for a numbered histo 00340 /// @todo Move to the templated version when we have C++11 and can have a default fn template type 00341 const YODA::Scatter2D& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const; 00342 00343 /// Get reference data for a named histo 00344 /// @todo Would be nice to just use these and ditch the S2D no-template version, 00345 /// but we need C++11 for default args in function templates 00346 // template <typename T=Scatter2D> 00347 /// @todo SFINAE to ensure that the type inherits from YODA::AnalysisObject? 00348 template <typename T> 00349 const T& refData(const string& hname) const { 00350 _cacheRefData(); 00351 MSG_TRACE("Using histo bin edges for " << name() << ":" << hname); 00352 if (!_refdata[hname]) { 00353 MSG_ERROR("Can't find reference histogram " << hname); 00354 throw Exception("Reference data " + hname + " not found."); 00355 } 00356 return dynamic_cast<T&>(*_refdata[hname]); 00357 } 00358 00359 /// Get reference data for a numbered histo 00360 /// @todo Would be nice to just use these and ditch the S2D no-template version, 00361 /// but we need C++11 for default args in function templates 00362 // template <typename T=Scatter2D> 00363 /// @todo SFINAE to ensure that the type inherits from YODA::AnalysisObject? 00364 template <typename T> 00365 const T& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00366 const string hname = makeAxisCode(datasetId, xAxisId, yAxisId); 00367 return refData(hname); 00368 } 00369 00370 //@} 00371 00372 00373 /// @name 1D histogram booking 00374 //@{ 00375 00376 /// Book a 1D histogram with @a nbins uniformly distributed across the range @a lower - @a upper . 00377 Histo1DPtr bookHisto1D(const std::string& name, 00378 size_t nbins, double lower, double upper, 00379 const std::string& title="", 00380 const std::string& xtitle="", 00381 const std::string& ytitle=""); 00382 00383 /// Book a 1D histogram with non-uniform bins defined by the vector of bin edges @a binedges . 00384 Histo1DPtr bookHisto1D(const std::string& name, 00385 const std::vector<double>& binedges, 00386 const std::string& title="", 00387 const std::string& xtitle="", 00388 const std::string& ytitle=""); 00389 00390 /// Book a 1D histogram with binning from a reference scatter. 00391 Histo1DPtr bookHisto1D(const std::string& name, 00392 const Scatter2D& refscatter, 00393 const std::string& title="", 00394 const std::string& xtitle="", 00395 const std::string& ytitle=""); 00396 00397 /// Book a 1D histogram, using the binnings in the reference data histogram. 00398 Histo1DPtr bookHisto1D(const std::string& name, 00399 const std::string& title="", 00400 const std::string& xtitle="", 00401 const std::string& ytitle=""); 00402 00403 /// Book a 1D histogram, using the binnings in the reference data histogram. 00404 /// 00405 /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00406 Histo1DPtr bookHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00407 const std::string& title="", 00408 const std::string& xtitle="", 00409 const std::string& ytitle=""); 00410 00411 //@} 00412 00413 00414 /// @name 2D histogram booking 00415 //@{ 00416 00417 /// Book a 2D histogram with @a nxbins and @a nybins uniformly 00418 /// distributed across the ranges @a xlower - @a xupper and @a 00419 /// ylower - @a yupper respectively along the x- and y-axis. 00420 Histo2DPtr bookHisto2D(const std::string& name, 00421 size_t nxbins, double xlower, double xupper, 00422 size_t nybins, double ylower, double yupper, 00423 const std::string& title="", 00424 const std::string& xtitle="", 00425 const std::string& ytitle="", 00426 const std::string& ztitle=""); 00427 00428 /// Book a 2D histogram with non-uniform bins defined by the 00429 /// vectorx of bin edges @a xbinedges and @a ybinedges. 00430 Histo2DPtr bookHisto2D(const std::string& name, 00431 const std::vector<double>& xbinedges, 00432 const std::vector<double>& ybinedges, 00433 const std::string& title="", 00434 const std::string& xtitle="", 00435 const std::string& ytitle="", 00436 const std::string& ztitle=""); 00437 00438 // /// Book a 2D histogram with binning from a reference scatter. 00439 // Histo2DPtr bookHisto2D(const std::string& name, 00440 // const Scatter3D& refscatter, 00441 // const std::string& title="", 00442 // const std::string& xtitle="", 00443 // const std::string& ytitle="", 00444 // const std::string& ztitle=""); 00445 00446 // /// Book a 2D histogram, using the binnings in the reference data histogram. 00447 // Histo2DPtr bookHisto2D(const std::string& name, 00448 // const std::string& title="", 00449 // const std::string& xtitle="", 00450 // const std::string& ytitle="", 00451 // const std::string& ztitle=""); 00452 00453 // /// Book a 2D histogram, using the binnings in the reference data histogram. 00454 // /// 00455 // /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00456 // Histo2DPtr bookHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00457 // const std::string& title="", 00458 // const std::string& xtitle="", 00459 // const std::string& ytitle="", 00460 // const std::string& ztitle=""); 00461 00462 //@} 00463 00464 00465 /// @name 1D profile histogram booking 00466 //@{ 00467 00468 /// Book a 1D profile histogram with @a nbins uniformly distributed across the range @a lower - @a upper . 00469 Profile1DPtr bookProfile1D(const std::string& name, 00470 size_t nbins, double lower, double upper, 00471 const std::string& title="", 00472 const std::string& xtitle="", 00473 const std::string& ytitle=""); 00474 00475 /// Book a 1D profile histogram with non-uniform bins defined by the vector of bin edges @a binedges . 00476 Profile1DPtr bookProfile1D(const std::string& name, 00477 const std::vector<double>& binedges, 00478 const std::string& title="", 00479 const std::string& xtitle="", 00480 const std::string& ytitle=""); 00481 00482 /// Book a 1D profile histogram with binning from a reference scatter. 00483 Profile1DPtr bookProfile1D(const std::string& name, 00484 const Scatter2D& refscatter, 00485 const std::string& title="", 00486 const std::string& xtitle="", 00487 const std::string& ytitle=""); 00488 00489 /// Book a 1D profile histogram, using the binnings in the reference data histogram. 00490 Profile1DPtr bookProfile1D(const std::string& name, 00491 const std::string& title="", 00492 const std::string& xtitle="", 00493 const std::string& ytitle=""); 00494 00495 /// Book a 1D profile histogram, using the binnings in the reference data histogram. 00496 /// 00497 /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00498 Profile1DPtr bookProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00499 const std::string& title="", 00500 const std::string& xtitle="", 00501 const std::string& ytitle=""); 00502 00503 //@} 00504 00505 00506 /// @name 2D profile histogram booking 00507 //@{ 00508 00509 /// Book a 2D profile histogram with @a nxbins and @a nybins uniformly 00510 /// distributed across the ranges @a xlower - @a xupper and @a ylower - @a 00511 /// yupper respectively along the x- and y-axis. 00512 Profile2DPtr bookProfile2D(const std::string& name, 00513 size_t nxbins, double xlower, double xupper, 00514 size_t nybins, double ylower, double yupper, 00515 const std::string& title="", 00516 const std::string& xtitle="", 00517 const std::string& ytitle="", 00518 const std::string& ztitle=""); 00519 00520 /// Book a 2D profile histogram with non-uniform bins defined by the vectorx 00521 /// of bin edges @a xbinedges and @a ybinedges. 00522 Profile2DPtr bookProfile2D(const std::string& name, 00523 const std::vector<double>& xbinedges, 00524 const std::vector<double>& ybinedges, 00525 const std::string& title="", 00526 const std::string& xtitle="", 00527 const std::string& ytitle="", 00528 const std::string& ztitle=""); 00529 00530 /// Book a 2D profile histogram with binning from a reference scatter. 00531 // Profile2DPtr bookProfile2D(const std::string& name, 00532 // const Scatter3D& refscatter, 00533 // const std::string& title="", 00534 // const std::string& xtitle="", 00535 // const std::string& ytitle="", 00536 // const std::string& ztitle=""); 00537 00538 // /// Book a 2D profile histogram, using the binnings in the reference data histogram. 00539 // Profile2DPtr bookProfile2D(const std::string& name, 00540 // const std::string& title="", 00541 // const std::string& xtitle="", 00542 // const std::string& ytitle="", 00543 // const std::string& ztitle=""); 00544 00545 // /// Book a 2D profile histogram, using the binnings in the reference data histogram. 00546 // /// 00547 // /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00548 // Profile2DPtr bookProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00549 // const std::string& title="", 00550 // const std::string& xtitle="", 00551 // const std::string& ytitle="", 00552 // const std::string& ztitle=""); 00553 00554 //@} 00555 00556 00557 /// @name 2D scatter booking 00558 //@{ 00559 00560 /// @brief Book a 2-dimensional data point set with the given name. 00561 /// 00562 /// @note Unlike histogram booking, scatter booking by default makes no 00563 /// attempt to use reference data to pre-fill the data object. If you want 00564 /// this, which is sometimes useful e.g. when the x-position is not really 00565 /// meaningful and can't be extracted from the data, then set the @a 00566 /// copy_pts parameter to true. This creates points to match the reference 00567 /// data's x values and errors, but with the y values and errors zeroed... 00568 /// assuming that there is a reference histo with the same name: if there 00569 /// isn't, an exception will be thrown. 00570 Scatter2DPtr bookScatter2D(const std::string& name, 00571 bool copy_pts=false, 00572 const std::string& title="", 00573 const std::string& xtitle="", 00574 const std::string& ytitle=""); 00575 00576 /// @brief Book a 2-dimensional data point set, using the binnings in the reference data histogram. 00577 /// 00578 /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00579 /// 00580 /// @note Unlike histogram booking, scatter booking by default makes no 00581 /// attempt to use reference data to pre-fill the data object. If you want 00582 /// this, which is sometimes useful e.g. when the x-position is not really 00583 /// meaningful and can't be extracted from the data, then set the @a 00584 /// copy_pts parameter to true. This creates points to match the reference 00585 /// data's x values and errors, but with the y values and errors zeroed. 00586 Scatter2DPtr bookScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00587 bool copy_pts=false, 00588 const std::string& title="", 00589 const std::string& xtitle="", 00590 const std::string& ytitle=""); 00591 00592 /// @brief Book a 2-dimensional data point set with equally spaced x-points in a range. 00593 /// 00594 /// The y values and errors will be set to 0. 00595 Scatter2DPtr bookScatter2D(const std::string& name, 00596 size_t npts, double lower, double upper, 00597 const std::string& title="", 00598 const std::string& xtitle="", 00599 const std::string& ytitle=""); 00600 00601 /// @brief Book a 2-dimensional data point set based on provided contiguous "bin edges". 00602 /// 00603 /// The y values and errors will be set to 0. 00604 Scatter2DPtr bookScatter2D(const std::string& hname, 00605 const std::vector<double>& binedges, 00606 const std::string& title, 00607 const std::string& xtitle, 00608 const std::string& ytitle); 00609 00610 //@} 00611 00612 00613 /// @todo What follows should really be protected: only public to keep BinnedHistogram happy for now... 00614 public: 00615 00616 /// @name Histogram manipulation 00617 //@{ 00618 00619 /// Normalize the given histogram, @a histo, to area = @a norm. 00620 /// 00621 /// @note The histogram is no longer invalidated by this procedure. 00622 void normalize(Histo1DPtr histo, double norm=1.0, bool includeoverflows=true); 00623 00624 /// Multiplicatively scale the given histogram, @a histo, by factor @s scale. 00625 /// 00626 /// @note The histogram is no longer invalidated by this procedure. 00627 void scale(Histo1DPtr histo, double scale); 00628 00629 /// Normalize the given histogram, @a histo, to area = @a norm. 00630 /// 00631 /// @note The histogram is no longer invalidated by this procedure. 00632 void normalize(Histo2DPtr histo, double norm=1.0, bool includeoverflows=true); 00633 00634 /// Multiplicatively scale the given histogram, @a histo, by factor @s scale. 00635 /// 00636 /// @note The histogram is no longer invalidated by this procedure. 00637 void scale(Histo2DPtr histo, double scale); 00638 00639 00640 /// Helper for histogram division. 00641 /// 00642 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00643 void divide(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const; 00644 00645 /// Helper for histogram division with raw YODA objects. 00646 /// 00647 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00648 void divide(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const; 00649 00650 00651 /// Helper for profile histogram division. 00652 /// 00653 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00654 void divide(Profile1DPtr p1, Profile1DPtr p2, Scatter2DPtr s) const; 00655 00656 /// Helper for profile histogram division with raw YODA objects. 00657 /// 00658 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00659 void divide(const YODA::Profile1D& p1, const YODA::Profile1D& p2, Scatter2DPtr s) const; 00660 00661 00662 /// Helper for 2D histogram division. 00663 /// 00664 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00665 void divide(Histo2DPtr h1, Histo2DPtr h2, Scatter3DPtr s) const; 00666 00667 /// Helper for 2D histogram division with raw YODA objects. 00668 /// 00669 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00670 void divide(const YODA::Histo2D& h1, const YODA::Histo2D& h2, Scatter3DPtr s) const; 00671 00672 00673 /// Helper for 2D profile histogram division. 00674 /// 00675 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00676 void divide(Profile2DPtr p1, Profile2DPtr p2, Scatter3DPtr s) const; 00677 00678 /// Helper for 2D profile histogram division with raw YODA objects 00679 /// 00680 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00681 void divide(const YODA::Profile2D& p1, const YODA::Profile2D& p2, Scatter3DPtr s) const; 00682 00683 00684 /// Helper for histogram efficiency calculation. 00685 /// 00686 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00687 void efficiency(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const; 00688 00689 /// Helper for histogram efficiency calculation. 00690 /// 00691 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00692 void efficiency(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const; 00693 00694 00695 /// Helper for histogram asymmetry calculation. 00696 /// 00697 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00698 void asymm(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const; 00699 00700 /// Helper for histogram asymmetry calculation. 00701 /// 00702 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00703 void asymm(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const; 00704 00705 00706 /// Helper for converting a differential histo to an integral one. 00707 /// 00708 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00709 void integrate(Histo1DPtr h, Scatter2DPtr s) const; 00710 00711 /// Helper for converting a differential histo to an integral one. 00712 /// 00713 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00714 void integrate(const Histo1D& h, Scatter2DPtr s) const; 00715 00716 //@} 00717 00718 00719 public: 00720 00721 /// List of registered analysis data objects 00722 const vector<AnalysisObjectPtr>& analysisObjects() const { 00723 return _analysisobjects; 00724 } 00725 00726 00727 protected: 00728 00729 /// @name Data object registration, retrieval, and removal 00730 //@{ 00731 00732 /// Register a data object in the histogram system 00733 void addAnalysisObject(AnalysisObjectPtr ao); 00734 00735 /// Get a data object from the histogram system 00736 /// @todo Use this default function template arg in C++11 00737 // template <typename AO=AnalysisObjectPtr> 00738 template <typename AO> 00739 const shared_ptr<AO> getAnalysisObject(const std::string& name) const { 00740 foreach (const AnalysisObjectPtr& ao, analysisObjects()) { 00741 if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao); 00742 } 00743 throw Exception("Data object " + histoPath(name) + " not found"); 00744 } 00745 00746 /// Get a data object from the histogram system (non-const) 00747 /// @todo Use this default function template arg in C++11 00748 // template <typename AO=AnalysisObjectPtr> 00749 template <typename AO> 00750 shared_ptr<AO> getAnalysisObject(const std::string& name) { 00751 foreach (const AnalysisObjectPtr& ao, analysisObjects()) { 00752 if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao); 00753 } 00754 throw Exception("Data object " + histoPath(name) + " not found"); 00755 } 00756 00757 /// Unregister a data object from the histogram system (by name) 00758 void removeAnalysisObject(const std::string& path); 00759 00760 /// Unregister a data object from the histogram system (by pointer) 00761 void removeAnalysisObject(AnalysisObjectPtr ao); 00762 00763 00764 /// Get a named Histo1D object from the histogram system 00765 const Histo1DPtr getHisto1D(const std::string& name) const { 00766 return getAnalysisObject<Histo1D>(name); 00767 } 00768 00769 /// Get a named Histo1D object from the histogram system (non-const) 00770 Histo1DPtr getHisto1D(const std::string& name) { 00771 return getAnalysisObject<Histo1D>(name); 00772 } 00773 00774 /// Get a Histo1D object from the histogram system by axis ID codes (non-const) 00775 const Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00776 return getAnalysisObject<Histo1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00777 } 00778 00779 /// Get a Histo1D object from the histogram system by axis ID codes (non-const) 00780 Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00781 return getAnalysisObject<Histo1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00782 } 00783 00784 00785 // /// Get a named Histo2D object from the histogram system 00786 // const Histo2DPtr getHisto2D(const std::string& name) const { 00787 // return getAnalysisObject<Histo2D>(name); 00788 // } 00789 00790 // /// Get a named Histo2D object from the histogram system (non-const) 00791 // Histo2DPtr getHisto2D(const std::string& name) { 00792 // return getAnalysisObject<Histo2D>(name); 00793 // } 00794 00795 // /// Get a Histo2D object from the histogram system by axis ID codes (non-const) 00796 // const Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00797 // return getAnalysisObject<Histo2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00798 // } 00799 00800 // /// Get a Histo2D object from the histogram system by axis ID codes (non-const) 00801 // Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00802 // return getAnalysisObject<Histo2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00803 // } 00804 00805 00806 /// Get a named Profile1D object from the histogram system 00807 const Profile1DPtr getProfile1D(const std::string& name) const { 00808 return getAnalysisObject<Profile1D>(name); 00809 } 00810 00811 /// Get a named Profile1D object from the histogram system (non-const) 00812 Profile1DPtr getProfile1D(const std::string& name) { 00813 return getAnalysisObject<Profile1D>(name); 00814 } 00815 00816 /// Get a Profile1D object from the histogram system by axis ID codes (non-const) 00817 const Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00818 return getAnalysisObject<Profile1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00819 } 00820 00821 /// Get a Profile1D object from the histogram system by axis ID codes (non-const) 00822 Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00823 return getAnalysisObject<Profile1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00824 } 00825 00826 00827 // /// Get a named Profile2D object from the histogram system 00828 // const Profile2DPtr getProfile2D(const std::string& name) const { 00829 // return getAnalysisObject<Profile2D>(name); 00830 // } 00831 00832 // /// Get a named Profile2D object from the histogram system (non-const) 00833 // Profile2DPtr getProfile2D(const std::string& name) { 00834 // return getAnalysisObject<Profile2D>(name); 00835 // } 00836 00837 // /// Get a Profile2D object from the histogram system by axis ID codes (non-const) 00838 // const Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00839 // return getAnalysisObject<Profile2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00840 // } 00841 00842 // /// Get a Profile2D object from the histogram system by axis ID codes (non-const) 00843 // Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00844 // return getAnalysisObject<Profile2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00845 // } 00846 00847 00848 /// Get a named Scatter2D object from the histogram system 00849 const Scatter2DPtr getScatter2D(const std::string& name) const { 00850 return getAnalysisObject<Scatter2D>(name); 00851 } 00852 00853 /// Get a named Scatter2D object from the histogram system (non-const) 00854 Scatter2DPtr getScatter2D(const std::string& name) { 00855 return getAnalysisObject<Scatter2D>(name); 00856 } 00857 00858 /// Get a Scatter2D object from the histogram system by axis ID codes (non-const) 00859 const Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00860 return getAnalysisObject<Scatter2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00861 } 00862 00863 /// Get a Scatter2D object from the histogram system by axis ID codes (non-const) 00864 Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00865 return getAnalysisObject<Scatter2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00866 } 00867 00868 //@} 00869 00870 00871 private: 00872 00873 /// Name passed to constructor (used to find .info analysis data file, and as a fallback) 00874 string _defaultname; 00875 00876 /// Pointer to analysis metadata object 00877 shared_ptr<AnalysisInfo> _info; 00878 00879 /// Storage of all plot objects 00880 /// @todo Make this a map for fast lookup by path? 00881 vector<AnalysisObjectPtr> _analysisobjects; 00882 00883 /// @name Cross-section variables 00884 //@{ 00885 double _crossSection; 00886 bool _gotCrossSection; 00887 //@} 00888 00889 /// The controlling AnalysisHandler object. 00890 AnalysisHandler* _analysishandler; 00891 00892 /// Collection of cached refdata to speed up many autobookings: the 00893 /// reference data file should only be read once. 00894 mutable std::map<std::string, AnalysisObjectPtr> _refdata; 00895 00896 00897 private: 00898 00899 /// @name Utility functions 00900 //@{ 00901 00902 /// Get the reference data for this paper and cache it. 00903 void _cacheRefData() const; 00904 00905 //@} 00906 00907 00908 /// The assignment operator is private and must never be called. 00909 /// In fact, it should not even be implemented. 00910 Analysis& operator=(const Analysis&); 00911 00912 }; 00913 00914 00915 } 00916 00917 00918 // Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh 00919 #include "Rivet/AnalysisBuilder.hh" 00920 00921 /// @def DECLARE_RIVET_PLUGIN 00922 /// Preprocessor define to prettify the global-object plugin hook mechanism. 00923 #define DECLARE_RIVET_PLUGIN(clsname) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname 00924 00925 /// @def DEFAULT_RIVET_ANA_CONSTRUCTOR 00926 /// Preprocessor define to prettify the manky constructor with name string argument 00927 #define DEFAULT_RIVET_ANA_CONSTRUCTOR(clsname) clsname() : Analysis(# clsname) {} 00928 00929 00930 #endif Generated on Thu Mar 10 2016 08:29:46 for The Rivet MC analysis system by ![]() |