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 const YODA::Scatter2D& refData(const string& hname) const; 00337 00338 /// Get reference data for a numbered histo 00339 const YODA::Scatter2D& refData(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const; 00340 00341 /// @todo Provide 3D versions as well? (How to distinguish the signatures? Template magic or explicit name?) 00342 //@} 00343 00344 00345 /// @name 1D histogram booking 00346 //@{ 00347 00348 /// Book a 1D histogram with @a nbins uniformly distributed across the range @a lower - @a upper . 00349 Histo1DPtr bookHisto1D(const std::string& name, 00350 size_t nbins, double lower, double upper, 00351 const std::string& title="", 00352 const std::string& xtitle="", 00353 const std::string& ytitle=""); 00354 00355 /// Book a 1D histogram with non-uniform bins defined by the vector of bin edges @a binedges . 00356 Histo1DPtr bookHisto1D(const std::string& name, 00357 const std::vector<double>& binedges, 00358 const std::string& title="", 00359 const std::string& xtitle="", 00360 const std::string& ytitle=""); 00361 00362 /// Book a 1D histogram with binning from a reference scatter. 00363 Histo1DPtr bookHisto1D(const std::string& name, 00364 const Scatter2D& refscatter, 00365 const std::string& title="", 00366 const std::string& xtitle="", 00367 const std::string& ytitle=""); 00368 00369 /// Book a 1D histogram, using the binnings in the reference data histogram. 00370 Histo1DPtr bookHisto1D(const std::string& name, 00371 const std::string& title="", 00372 const std::string& xtitle="", 00373 const std::string& ytitle=""); 00374 00375 /// Book a 1D histogram, using the binnings in the reference data histogram. 00376 /// 00377 /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00378 Histo1DPtr bookHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00379 const std::string& title="", 00380 const std::string& xtitle="", 00381 const std::string& ytitle=""); 00382 00383 //@} 00384 00385 00386 /// @name 2D histogram booking 00387 //@{ 00388 00389 /// Book a 2D histogram with @a nxbins and @a nybins uniformly 00390 /// distributed across the ranges @a xlower - @a xupper and @a 00391 /// ylower - @a yupper respectively along the x- and y-axis. 00392 Histo2DPtr bookHisto2D(const std::string& name, 00393 size_t nxbins, double xlower, double xupper, 00394 size_t nybins, double ylower, double yupper, 00395 const std::string& title="", 00396 const std::string& xtitle="", 00397 const std::string& ytitle="", 00398 const std::string& ztitle=""); 00399 00400 /// Book a 2D histogram with non-uniform bins defined by the 00401 /// vectorx of bin edges @a xbinedges and @a ybinedges. 00402 Histo2DPtr bookHisto2D(const std::string& name, 00403 const std::vector<double>& xbinedges, 00404 const std::vector<double>& ybinedges, 00405 const std::string& title="", 00406 const std::string& xtitle="", 00407 const std::string& ytitle="", 00408 const std::string& ztitle=""); 00409 00410 // /// Book a 2D histogram with binning from a reference scatter. 00411 // Histo2DPtr bookHisto2D(const std::string& name, 00412 // const Scatter3D& refscatter, 00413 // const std::string& title="", 00414 // const std::string& xtitle="", 00415 // const std::string& ytitle="", 00416 // const std::string& ztitle=""); 00417 00418 // /// Book a 2D histogram, using the binnings in the reference data histogram. 00419 // Histo2DPtr bookHisto2D(const std::string& name, 00420 // const std::string& title="", 00421 // const std::string& xtitle="", 00422 // const std::string& ytitle="", 00423 // const std::string& ztitle=""); 00424 00425 // /// Book a 2D histogram, using the binnings in the reference data histogram. 00426 // /// 00427 // /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00428 // Histo2DPtr bookHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00429 // const std::string& title="", 00430 // const std::string& xtitle="", 00431 // const std::string& ytitle="", 00432 // const std::string& ztitle=""); 00433 00434 //@} 00435 00436 00437 /// @name 1D profile histogram booking 00438 //@{ 00439 00440 /// Book a 1D profile histogram with @a nbins uniformly distributed across the range @a lower - @a upper . 00441 Profile1DPtr bookProfile1D(const std::string& name, 00442 size_t nbins, double lower, double upper, 00443 const std::string& title="", 00444 const std::string& xtitle="", 00445 const std::string& ytitle=""); 00446 00447 /// Book a 1D profile histogram with non-uniform bins defined by the vector of bin edges @a binedges . 00448 Profile1DPtr bookProfile1D(const std::string& name, 00449 const std::vector<double>& binedges, 00450 const std::string& title="", 00451 const std::string& xtitle="", 00452 const std::string& ytitle=""); 00453 00454 /// Book a 1D profile histogram with binning from a reference scatter. 00455 Profile1DPtr bookProfile1D(const std::string& name, 00456 const Scatter2D& refscatter, 00457 const std::string& title="", 00458 const std::string& xtitle="", 00459 const std::string& ytitle=""); 00460 00461 /// Book a 1D profile histogram, using the binnings in the reference data histogram. 00462 Profile1DPtr bookProfile1D(const std::string& name, 00463 const std::string& title="", 00464 const std::string& xtitle="", 00465 const std::string& ytitle=""); 00466 00467 /// Book a 1D profile histogram, using the binnings in the reference data histogram. 00468 /// 00469 /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00470 Profile1DPtr bookProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00471 const std::string& title="", 00472 const std::string& xtitle="", 00473 const std::string& ytitle=""); 00474 00475 //@} 00476 00477 00478 /// @name 2D profile histogram booking 00479 //@{ 00480 00481 /// Book a 2D profile histogram with @a nxbins and @a nybins uniformly 00482 /// distributed across the ranges @a xlower - @a xupper and @a ylower - @a 00483 /// yupper respectively along the x- and y-axis. 00484 Profile2DPtr bookProfile2D(const std::string& name, 00485 size_t nxbins, double xlower, double xupper, 00486 size_t nybins, double ylower, double yupper, 00487 const std::string& title="", 00488 const std::string& xtitle="", 00489 const std::string& ytitle="", 00490 const std::string& ztitle=""); 00491 00492 /// Book a 2D profile histogram with non-uniform bins defined by the vectorx 00493 /// of bin edges @a xbinedges and @a ybinedges. 00494 Profile2DPtr bookProfile2D(const std::string& name, 00495 const std::vector<double>& xbinedges, 00496 const std::vector<double>& ybinedges, 00497 const std::string& title="", 00498 const std::string& xtitle="", 00499 const std::string& ytitle="", 00500 const std::string& ztitle=""); 00501 00502 /// Book a 2D profile histogram with binning from a reference scatter. 00503 // Profile2DPtr bookProfile2D(const std::string& name, 00504 // const Scatter3D& refscatter, 00505 // const std::string& title="", 00506 // const std::string& xtitle="", 00507 // const std::string& ytitle="", 00508 // const std::string& ztitle=""); 00509 00510 // /// Book a 2D profile histogram, using the binnings in the reference data histogram. 00511 // Profile2DPtr bookProfile2D(const std::string& name, 00512 // const std::string& title="", 00513 // const std::string& xtitle="", 00514 // const std::string& ytitle="", 00515 // const std::string& ztitle=""); 00516 00517 // /// Book a 2D profile histogram, using the binnings in the reference data histogram. 00518 // /// 00519 // /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00520 // Profile2DPtr bookProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00521 // const std::string& title="", 00522 // const std::string& xtitle="", 00523 // const std::string& ytitle="", 00524 // const std::string& ztitle=""); 00525 00526 //@} 00527 00528 00529 /// @name 2D scatter booking 00530 //@{ 00531 00532 /// @brief Book a 2-dimensional data point set with the given name. 00533 /// 00534 /// @note Unlike histogram booking, scatter booking by default makes no 00535 /// attempt to use reference data to pre-fill the data object. If you want 00536 /// this, which is sometimes useful e.g. when the x-position is not really 00537 /// meaningful and can't be extracted from the data, then set the @a 00538 /// copy_pts parameter to true. This creates points to match the reference 00539 /// data's x values and errors, but with the y values and errors zeroed... 00540 /// assuming that there is a reference histo with the same name: if there 00541 /// isn't, an exception will be thrown. 00542 Scatter2DPtr bookScatter2D(const std::string& name, 00543 bool copy_pts=false, 00544 const std::string& title="", 00545 const std::string& xtitle="", 00546 const std::string& ytitle=""); 00547 00548 /// @brief Book a 2-dimensional data point set, using the binnings in the reference data histogram. 00549 /// 00550 /// The paper, dataset and x/y-axis IDs will be used to build the histo name in the HepData standard way. 00551 /// 00552 /// @note Unlike histogram booking, scatter booking by default makes no 00553 /// attempt to use reference data to pre-fill the data object. If you want 00554 /// this, which is sometimes useful e.g. when the x-position is not really 00555 /// meaningful and can't be extracted from the data, then set the @a 00556 /// copy_pts parameter to true. This creates points to match the reference 00557 /// data's x values and errors, but with the y values and errors zeroed. 00558 Scatter2DPtr bookScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId, 00559 bool copy_pts=false, 00560 const std::string& title="", 00561 const std::string& xtitle="", 00562 const std::string& ytitle=""); 00563 00564 /// @brief Book a 2-dimensional data point set with equally spaced x-points in a range. 00565 /// 00566 /// The y values and errors will be set to 0. 00567 Scatter2DPtr bookScatter2D(const std::string& name, 00568 size_t npts, double lower, double upper, 00569 const std::string& title="", 00570 const std::string& xtitle="", 00571 const std::string& ytitle=""); 00572 00573 /// @brief Book a 2-dimensional data point set based on provided contiguous "bin edges". 00574 /// 00575 /// The y values and errors will be set to 0. 00576 Scatter2DPtr bookScatter2D(const std::string& hname, 00577 const std::vector<double>& binedges, 00578 const std::string& title, 00579 const std::string& xtitle, 00580 const std::string& ytitle); 00581 00582 //@} 00583 00584 00585 /// @todo What follows should really be protected: only public to keep BinnedHistogram happy for now... 00586 public: 00587 00588 /// @name Histogram manipulation 00589 //@{ 00590 00591 /// Normalize the given histogram, @a histo, to area = @a norm. 00592 /// 00593 /// @note The histogram is no longer invalidated by this procedure. 00594 void normalize(Histo1DPtr histo, double norm=1.0, bool includeoverflows=true); 00595 00596 /// Multiplicatively scale the given histogram, @a histo, by factor @s scale. 00597 /// 00598 /// @note The histogram is no longer invalidated by this procedure. 00599 void scale(Histo1DPtr histo, double scale); 00600 00601 /// Normalize the given histogram, @a histo, to area = @a norm. 00602 /// 00603 /// @note The histogram is no longer invalidated by this procedure. 00604 void normalize(Histo2DPtr histo, double norm=1.0, bool includeoverflows=true); 00605 00606 /// Multiplicatively scale the given histogram, @a histo, by factor @s scale. 00607 /// 00608 /// @note The histogram is no longer invalidated by this procedure. 00609 void scale(Histo2DPtr histo, double scale); 00610 00611 00612 /// Helper for histogram division. 00613 /// 00614 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00615 void divide(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const; 00616 00617 /// Helper for histogram division with raw YODA objects. 00618 /// 00619 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00620 void divide(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const; 00621 00622 00623 /// Helper for profile histogram division. 00624 /// 00625 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00626 void divide(Profile1DPtr p1, Profile1DPtr p2, Scatter2DPtr s) const; 00627 00628 /// Helper for profile histogram division with raw YODA objects. 00629 /// 00630 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00631 void divide(const YODA::Profile1D& p1, const YODA::Profile1D& p2, Scatter2DPtr s) const; 00632 00633 00634 /// Helper for 2D histogram division. 00635 /// 00636 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00637 void divide(Histo2DPtr h1, Histo2DPtr h2, Scatter3DPtr s) const; 00638 00639 /// Helper for 2D histogram division with raw YODA objects. 00640 /// 00641 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00642 void divide(const YODA::Histo2D& h1, const YODA::Histo2D& h2, Scatter3DPtr s) const; 00643 00644 00645 /// Helper for 2D profile histogram division. 00646 /// 00647 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00648 void divide(Profile2DPtr p1, Profile2DPtr p2, Scatter3DPtr s) const; 00649 00650 /// Helper for 2D profile histogram division with raw YODA objects 00651 /// 00652 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00653 void divide(const YODA::Profile2D& p1, const YODA::Profile2D& p2, Scatter3DPtr s) const; 00654 00655 00656 /// Helper for histogram efficiency calculation. 00657 /// 00658 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00659 void efficiency(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const; 00660 00661 /// Helper for histogram efficiency calculation. 00662 /// 00663 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00664 void efficiency(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const; 00665 00666 00667 /// Helper for histogram asymmetry calculation. 00668 /// 00669 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00670 void asymm(Histo1DPtr h1, Histo1DPtr h2, Scatter2DPtr s) const; 00671 00672 /// Helper for histogram asymmetry calculation. 00673 /// 00674 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00675 void asymm(const YODA::Histo1D& h1, const YODA::Histo1D& h2, Scatter2DPtr s) const; 00676 00677 00678 /// Helper for converting a differential histo to an integral one. 00679 /// 00680 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00681 void integrate(Histo1DPtr h, Scatter2DPtr s) const; 00682 00683 /// Helper for converting a differential histo to an integral one. 00684 /// 00685 /// @note Assigns to the (already registered) output scatter, @a s. Preserves the path information of the target. 00686 void integrate(const Histo1D& h, Scatter2DPtr s) const; 00687 00688 //@} 00689 00690 00691 public: 00692 00693 /// List of registered analysis data objects 00694 const vector<AnalysisObjectPtr>& analysisObjects() const { 00695 return _analysisobjects; 00696 } 00697 00698 00699 protected: 00700 00701 /// @name Data object registration, retrieval, and removal 00702 //@{ 00703 00704 /// Register a data object in the histogram system 00705 void addAnalysisObject(AnalysisObjectPtr ao); 00706 00707 /// Get a data object from the histogram system 00708 /// @todo Use this default function template arg in C++11 00709 // template <typename AO=AnalysisObjectPtr> 00710 template <typename AO> 00711 const shared_ptr<AO> getAnalysisObject(const std::string& name) const { 00712 foreach (const AnalysisObjectPtr& ao, analysisObjects()) { 00713 if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao); 00714 } 00715 throw Exception("Data object " + histoPath(name) + " not found"); 00716 } 00717 00718 /// Get a data object from the histogram system (non-const) 00719 /// @todo Use this default function template arg in C++11 00720 // template <typename AO=AnalysisObjectPtr> 00721 template <typename AO> 00722 shared_ptr<AO> getAnalysisObject(const std::string& name) { 00723 foreach (const AnalysisObjectPtr& ao, analysisObjects()) { 00724 if (ao->path() == histoPath(name)) return dynamic_pointer_cast<AO>(ao); 00725 } 00726 throw Exception("Data object " + histoPath(name) + " not found"); 00727 } 00728 00729 /// Unregister a data object from the histogram system (by name) 00730 void removeAnalysisObject(const std::string& path); 00731 00732 /// Unregister a data object from the histogram system (by pointer) 00733 void removeAnalysisObject(AnalysisObjectPtr ao); 00734 00735 00736 /// Get a named Histo1D object from the histogram system 00737 const Histo1DPtr getHisto1D(const std::string& name) const { 00738 return getAnalysisObject<Histo1D>(name); 00739 } 00740 00741 /// Get a named Histo1D object from the histogram system (non-const) 00742 Histo1DPtr getHisto1D(const std::string& name) { 00743 return getAnalysisObject<Histo1D>(name); 00744 } 00745 00746 /// Get a Histo1D object from the histogram system by axis ID codes (non-const) 00747 const Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00748 return getAnalysisObject<Histo1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00749 } 00750 00751 /// Get a Histo1D object from the histogram system by axis ID codes (non-const) 00752 Histo1DPtr getHisto1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00753 return getAnalysisObject<Histo1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00754 } 00755 00756 00757 // /// Get a named Histo2D object from the histogram system 00758 // const Histo2DPtr getHisto2D(const std::string& name) const { 00759 // return getAnalysisObject<Histo2D>(name); 00760 // } 00761 00762 // /// Get a named Histo2D object from the histogram system (non-const) 00763 // Histo2DPtr getHisto2D(const std::string& name) { 00764 // return getAnalysisObject<Histo2D>(name); 00765 // } 00766 00767 // /// Get a Histo2D object from the histogram system by axis ID codes (non-const) 00768 // const Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00769 // return getAnalysisObject<Histo2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00770 // } 00771 00772 // /// Get a Histo2D object from the histogram system by axis ID codes (non-const) 00773 // Histo2DPtr getHisto2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00774 // return getAnalysisObject<Histo2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00775 // } 00776 00777 00778 /// Get a named Profile1D object from the histogram system 00779 const Profile1DPtr getProfile1D(const std::string& name) const { 00780 return getAnalysisObject<Profile1D>(name); 00781 } 00782 00783 /// Get a named Profile1D object from the histogram system (non-const) 00784 Profile1DPtr getProfile1D(const std::string& name) { 00785 return getAnalysisObject<Profile1D>(name); 00786 } 00787 00788 /// Get a Profile1D object from the histogram system by axis ID codes (non-const) 00789 const Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00790 return getAnalysisObject<Profile1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00791 } 00792 00793 /// Get a Profile1D object from the histogram system by axis ID codes (non-const) 00794 Profile1DPtr getProfile1D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00795 return getAnalysisObject<Profile1D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00796 } 00797 00798 00799 // /// Get a named Profile2D object from the histogram system 00800 // const Profile2DPtr getProfile2D(const std::string& name) const { 00801 // return getAnalysisObject<Profile2D>(name); 00802 // } 00803 00804 // /// Get a named Profile2D object from the histogram system (non-const) 00805 // Profile2DPtr getProfile2D(const std::string& name) { 00806 // return getAnalysisObject<Profile2D>(name); 00807 // } 00808 00809 // /// Get a Profile2D object from the histogram system by axis ID codes (non-const) 00810 // const Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00811 // return getAnalysisObject<Profile2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00812 // } 00813 00814 // /// Get a Profile2D object from the histogram system by axis ID codes (non-const) 00815 // Profile2DPtr getProfile2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00816 // return getAnalysisObject<Profile2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00817 // } 00818 00819 00820 /// Get a named Scatter2D object from the histogram system 00821 const Scatter2DPtr getScatter2D(const std::string& name) const { 00822 return getAnalysisObject<Scatter2D>(name); 00823 } 00824 00825 /// Get a named Scatter2D object from the histogram system (non-const) 00826 Scatter2DPtr getScatter2D(const std::string& name) { 00827 return getAnalysisObject<Scatter2D>(name); 00828 } 00829 00830 /// Get a Scatter2D object from the histogram system by axis ID codes (non-const) 00831 const Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) const { 00832 return getAnalysisObject<Scatter2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00833 } 00834 00835 /// Get a Scatter2D object from the histogram system by axis ID codes (non-const) 00836 Scatter2DPtr getScatter2D(unsigned int datasetId, unsigned int xAxisId, unsigned int yAxisId) { 00837 return getAnalysisObject<Scatter2D>(makeAxisCode(datasetId, xAxisId, yAxisId)); 00838 } 00839 00840 //@} 00841 00842 00843 private: 00844 00845 /// Name passed to constructor (used to find .info analysis data file, and as a fallback) 00846 string _defaultname; 00847 00848 /// Pointer to analysis metadata object 00849 shared_ptr<AnalysisInfo> _info; 00850 00851 /// Storage of all plot objects 00852 /// @todo Make this a map for fast lookup by path? 00853 vector<AnalysisObjectPtr> _analysisobjects; 00854 00855 /// @name Cross-section variables 00856 //@{ 00857 double _crossSection; 00858 bool _gotCrossSection; 00859 //@} 00860 00861 /// The controlling AnalysisHandler object. 00862 AnalysisHandler* _analysishandler; 00863 00864 /// Collection of cached refdata to speed up many autobookings: the 00865 /// reference data file should only be read once. 00866 mutable std::map<std::string, Scatter2DPtr> _refdata; 00867 00868 00869 private: 00870 00871 /// @name Utility functions 00872 //@{ 00873 00874 /// Get the reference data for this paper and cache it. 00875 void _cacheRefData() const; 00876 00877 //@} 00878 00879 00880 /// The assignment operator is private and must never be called. 00881 /// In fact, it should not even be implemented. 00882 Analysis& operator=(const Analysis&); 00883 00884 }; 00885 00886 00887 } 00888 00889 00890 // Include definition of analysis plugin system so that analyses automatically see it when including Analysis.hh 00891 #include "Rivet/AnalysisBuilder.hh" 00892 00893 /// @def DECLARE_RIVET_PLUGIN 00894 /// Preprocessor define to prettify the global-object plugin hook mechanism. 00895 #define DECLARE_RIVET_PLUGIN(clsname) Rivet::AnalysisBuilder<clsname> plugin_ ## clsname 00896 00897 /// @def DEFAULT_RIVET_ANA_CONSTRUCTOR 00898 /// Preprocessor define to prettify the manky constructor with name string argument 00899 #define DEFAULT_RIVET_ANA_CONSTRUCTOR(clsname) clsname() : Analysis(# clsname) {} 00900 00901 00902 #endif Generated on Tue Mar 24 2015 17:35:23 for The Rivet MC analysis system by ![]() |