00001 #ifndef PSHIST_HMANAGER_H 00002 #define PSHIST_HMANAGER_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: HManager.h 2056 2011-06-29 21:44:29Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class HManager. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 #include <vector> 00017 #include <string> 00018 #include <boost/utility.hpp> 00019 00020 //---------------------- 00021 // Base Class Headers -- 00022 //---------------------- 00023 00024 //------------------------------- 00025 // Collaborating Class Headers -- 00026 //------------------------------- 00027 #include "PSHist/Axis.h" 00028 #include "PSHist/H1.h" 00029 #include "PSHist/H2.h" 00030 #include "PSHist/Profile.h" 00031 00032 //------------------------------------ 00033 // Collaborating Class Declarations -- 00034 //------------------------------------ 00035 00036 00037 // --------------------- 00038 // -- Class Interface -- 00039 // --------------------- 00040 00041 namespace PSHist { 00042 00043 /** 00044 * @defgroup PSHist PSHist package 00045 * 00046 * @brief Package defining interfaces for histogramming services. 00047 * 00048 * This package contains interfaces (abstract classes) for 00049 * histogramming services used by psana framework. 00050 */ 00051 00052 00053 /** 00054 * @ingroup PSHist 00055 * 00056 * @brief Interface for histogram/tuple manager class. 00057 * 00058 * HManager is an empty base class which holds information about ntuples/histograms. 00059 * The main reason is to be able to create and hold new histograms or/and ntuples 00060 * without knowing without knowing what the underlying system is. For example, 00061 * it might be root, hbook, hyppo etc. 00062 * 00063 * Usage: 00064 * @code 00065 * #include "RootHist/RootHManager.h" 00066 * #include "PSHist/HManager.h" 00067 * #include "PSHist/Axis.h" 00068 * #include "PSHist/H1.h" 00069 * #include "PSHist/H2.h" 00070 * #include "PSHist/Profile.h" 00071 * @endcode 00072 * 00073 * 1. Create a HManager with specific constructor (root for example): 00074 * 00075 * @code 00076 * PSHist::HManager *hMan = new RootHist::RootHManager("my-output-file.root", "RECREATE"); 00077 * @endcode 00078 * 00079 * 2. Create histograms 00080 * 00081 * @code 00082 * PSHist::H1 *pHis1f = hMan->hist1f("His1 float title",100,0.,1.); 00083 * PSHist::H2 *pHis2d = hMan->hist2d("His2 double title",100,0.,1.,100,0.,1.); 00084 * @endcode 00085 * 00086 * 00087 * 3. Fill histograms 00088 * 00089 * @code 00090 * pHis1f->fill(x,[weight]); // once per event 00091 * pHis2d->fill(x,y,[weight]); 00092 * @endcode 00093 * 00094 * 00095 * 4. Write the data into a file: 00096 * 00097 * @code 00098 * hMan->write(); // at the end of job 00099 * delete hMan; 00100 * @endcode 00101 * 00102 * This software was developed for the LCLS project. If you use all or 00103 * part of it, please give an appropriate acknowledgment. 00104 * 00105 * @see H1 00106 * @see H2 00107 * @see Profile 00108 * 00109 * @version $Id: HManager.h 2056 2011-06-29 21:44:29Z salnikov@SLAC.STANFORD.EDU $ 00110 * 00111 * @author Mikhail S. Dubrovin 00112 */ 00113 00114 class HManager : boost::noncopyable { 00115 public: 00116 00117 // Destructor 00118 virtual ~HManager () {} 00119 00120 // 1-d histograms 00121 00122 /** 00123 * @brief Create new 1-dimensional histogram and return pointer to it. 00124 * 00125 * This method creates new 1-dimensional histogram with same-width bins. 00126 * Internal storage of the created histogram will consists of 32-bit 00127 * integer per histogram bin. 00128 * The name of the histogram must be unique, otherwise exception is thrown. 00129 * 00130 * <b>Returned pointer should never be deleted by client code.</b> 00131 * 00132 * @param[in] name Histogram name, unique string. 00133 * @param[in] title Title of the histogram, arbitrary string. 00134 * @param[in] nbins Number of bins. 00135 * @param[in] xlow Low edge of the first bin. 00136 * @param[in] xhigh High edge of the last bin. 00137 * @return Pointer to a newly created histogram, do not delete. 00138 * 00139 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00140 * identical name exists already 00141 */ 00142 virtual H1* hist1i(const std::string& name, const std::string& title, 00143 int nbins, double xlow, double xhigh) = 0; 00144 00145 /** 00146 * @brief Create new 1-dimensional histogram and return pointer to it. 00147 * 00148 * This method creates new 1-dimensional histogram with same-width bins. 00149 * Internal storage of the created histogram will consists of 32-bit 00150 * floating number per histogram bin. 00151 * The name of the histogram must be unique, otherwise exception is thrown. 00152 * 00153 * <b>Returned pointer should never be deleted by client code.</b> 00154 * 00155 * @param[in] name Histogram name, unique string. 00156 * @param[in] title Title of the histogram, arbitrary string. 00157 * @param[in] nbins Number of bins. 00158 * @param[in] xlow Low edge of the first bin. 00159 * @param[in] xhigh High edge of the last bin. 00160 * @return Pointer to a newly created histogram, do not delete. 00161 * 00162 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00163 * identical name exists already 00164 */ 00165 virtual H1* hist1f(const std::string& name, const std::string& title, 00166 int nbins, double xlow, double xhigh) = 0; 00167 00168 /** 00169 * @brief Create new 1-dimensional histogram and return pointer to it. 00170 * 00171 * This method creates new 1-dimensional histogram with same-width bins. 00172 * Internal storage of the created histogram will consists of 64-bit 00173 * floating number per histogram bin. 00174 * The name of the histogram must be unique, otherwise exception is thrown. 00175 * 00176 * <b>Returned pointer should never be deleted by client code.</b> 00177 * 00178 * @param[in] name Histogram name, unique string. 00179 * @param[in] title Title of the histogram, arbitrary string. 00180 * @param[in] nbins Number of bins. 00181 * @param[in] xlow Low edge of the first bin. 00182 * @param[in] xhigh High edge of the last bin. 00183 * @return Pointer to a newly created histogram, do not delete. 00184 * 00185 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00186 * identical name exists already 00187 */ 00188 virtual H1* hist1d(const std::string& name, const std::string& title, 00189 int nbins, double xlow, double xhigh) = 0; 00190 00191 /** 00192 * @brief Create new 1-dimensional histogram and return pointer to it. 00193 * 00194 * This method creates new 1-dimensional histogram with variable-width bins. 00195 * Internal storage of the created histogram will consists of 32-bit 00196 * integer per histogram bin. 00197 * The name of the histogram must be unique, otherwise exception is thrown. 00198 * 00199 * <b>Returned pointer should never be deleted by client code.</b> 00200 * 00201 * @param[in] name Histogram name, unique string. 00202 * @param[in] title Title of the histogram, arbitrary string. 00203 * @param[in] nbins Number of bins. 00204 * @param[in] xbinedges Array of the histogram edges, size of the array 00205 * is @c nbins+1, it should contain ordered values for 00206 * low edges of all bins plus high edge of last bin. 00207 * @return Pointer to a newly created histogram, do not delete. 00208 * 00209 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00210 * identical name exists already 00211 */ 00212 virtual H1* hist1i(const std::string& name, const std::string& title, 00213 int nbins, const double *xbinedges) = 0; 00214 00215 /** 00216 * @brief Create new 1-dimensional histogram and return pointer to it. 00217 * 00218 * This method creates new 1-dimensional histogram with variable-width bins. 00219 * Internal storage of the created histogram will consists of 32-bit 00220 * floating number per histogram bin. 00221 * The name of the histogram must be unique, otherwise exception is thrown. 00222 * 00223 * <b>Returned pointer should never be deleted by client code.</b> 00224 * 00225 * @param[in] name Histogram name, unique string. 00226 * @param[in] title Title of the histogram, arbitrary string. 00227 * @param[in] nbins Number of bins. 00228 * @param[in] xbinedges Array of the histogram edges, size of the array 00229 * is @c nbins+1, it should contain ordered values for 00230 * low edges of all bins plus high edge of last bin. 00231 * @return Pointer to a newly created histogram, do not delete. 00232 * 00233 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00234 * identical name exists already 00235 */ 00236 virtual H1* hist1f(const std::string& name, const std::string& title, 00237 int nbins, const double *xbinedges) = 0; 00238 00239 /** 00240 * @brief Create new 1-dimensional histogram and return pointer to it. 00241 * 00242 * This method creates new 1-dimensional histogram with variable-width bins. 00243 * Internal storage of the created histogram will consists of 64-bit 00244 * floating number per histogram bin. 00245 * The name of the histogram must be unique, otherwise exception is thrown. 00246 * 00247 * <b>Returned pointer should never be deleted by client code.</b> 00248 * 00249 * @param[in] name Histogram name, unique string. 00250 * @param[in] title Title of the histogram, arbitrary string. 00251 * @param[in] nbins Number of bins. 00252 * @param[in] xbinedges Array of the histogram edges, size of the array 00253 * is @c nbins+1, it should contain ordered values for 00254 * low edges of all bins plus high edge of last bin. 00255 * @return Pointer to a newly created histogram, do not delete. 00256 * 00257 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00258 * identical name exists already 00259 */ 00260 virtual H1* hist1d(const std::string& name, const std::string& title, 00261 int nbins, const double *xbinedges) = 0; 00262 00263 /** 00264 * @brief Create new 1-dimensional histogram and return pointer to it. 00265 * 00266 * This method creates new 1-dimensional histogram, number of bins and 00267 * their edges are determined by separate object (Axis class). 00268 * Internal storage of the created histogram will consists of 32-bit 00269 * integer per histogram bin. 00270 * The name of the histogram must be unique, otherwise exception is thrown. 00271 * 00272 * <b>Returned pointer should never be deleted by client code.</b> 00273 * 00274 * @param[in] name Histogram name, unique string. 00275 * @param[in] title Title of the histogram, arbitrary string. 00276 * @param[in] axis Axis definition. 00277 * @return Pointer to a newly created histogram, do not delete. 00278 * 00279 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00280 * identical name exists already 00281 */ 00282 virtual H1* hist1i(const std::string& name, const std::string& title, 00283 const PSHist::Axis& axis) = 0; 00284 00285 /** 00286 * @brief Create new 1-dimensional histogram and return pointer to it. 00287 * 00288 * This method creates new 1-dimensional histogram, number of bins and 00289 * their edges are determined by separate object (Axis class). 00290 * Internal storage of the created histogram will consists of 32-bit 00291 * floating number per histogram bin. 00292 * The name of the histogram must be unique, otherwise exception is thrown. 00293 * 00294 * <b>Returned pointer should never be deleted by client code.</b> 00295 * 00296 * @param[in] name Histogram name, unique string. 00297 * @param[in] title Title of the histogram, arbitrary string. 00298 * @param[in] axis Axis definition. 00299 * @return Pointer to a newly created histogram, do not delete. 00300 * 00301 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00302 * identical name exists already 00303 */ 00304 virtual H1* hist1f(const std::string& name, const std::string& title, 00305 const PSHist::Axis& axis) = 0; 00306 00307 /** 00308 * @brief Create new 1-dimensional histogram and return pointer to it. 00309 * 00310 * This method creates new 1-dimensional histogram, number of bins and 00311 * their edges are determined by separate object (Axis class). 00312 * Internal storage of the created histogram will consists of 64-bit 00313 * floating number per histogram bin. 00314 * The name of the histogram must be unique, otherwise exception is thrown. 00315 * 00316 * <b>Returned pointer should never be deleted by client code.</b> 00317 * 00318 * @param[in] name Histogram name, unique string. 00319 * @param[in] title Title of the histogram, arbitrary string. 00320 * @param[in] axis Axis definition. 00321 * @return Pointer to a newly created histogram, do not delete. 00322 * 00323 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00324 * identical name exists already 00325 */ 00326 virtual H1* hist1d(const std::string& name, const std::string& title, 00327 const PSHist::Axis& axis) = 0; 00328 00329 // 2-d histograms 00330 00331 /** 00332 * @brief Create new 2-dimensional histogram and return pointer to it. 00333 * 00334 * This method creates new 2-dimensional histogram, number of bins and 00335 * their edges are determined by separate objects (Axis class). 00336 * Internal storage of the created histogram will consists of 32-bit 00337 * integer per histogram bin. 00338 * The name of the histogram must be unique, otherwise exception is thrown. 00339 * 00340 * <b>Returned pointer should never be deleted by client code.</b> 00341 * 00342 * @param[in] name Histogram name, unique string. 00343 * @param[in] title Title of the histogram, arbitrary string. 00344 * @param[in] xaxis X axis definition. 00345 * @param[in] yaxis Y axis definition. 00346 * @return Pointer to a newly created histogram, do not delete. 00347 * 00348 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00349 * identical name exists already 00350 */ 00351 virtual H2* hist2i(const std::string& name, const std::string& title, 00352 const PSHist::Axis& xaxis, const PSHist::Axis& yaxis ) = 0; 00353 00354 /** 00355 * @brief Create new 2-dimensional histogram and return pointer to it. 00356 * 00357 * This method creates new 2-dimensional histogram, number of bins and 00358 * their edges are determined by separate objects (Axis class). 00359 * Internal storage of the created histogram will consists of 32-bit 00360 * floating number per histogram bin. 00361 * The name of the histogram must be unique, otherwise exception is thrown. 00362 * 00363 * <b>Returned pointer should never be deleted by client code.</b> 00364 * 00365 * @param[in] name Histogram name, unique string. 00366 * @param[in] title Title of the histogram, arbitrary string. 00367 * @param[in] xaxis X axis definition. 00368 * @param[in] yaxis Y axis definition. 00369 * @return Pointer to a newly created histogram, do not delete. 00370 * 00371 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00372 * identical name exists already 00373 */ 00374 virtual H2* hist2f(const std::string& name, const std::string& title, 00375 const PSHist::Axis& xaxis, const PSHist::Axis& yaxis ) = 0; 00376 00377 /** 00378 * @brief Create new 2-dimensional histogram and return pointer to it. 00379 * 00380 * This method creates new 2-dimensional histogram, number of bins and 00381 * their edges are determined by separate objects (Axis class). 00382 * Internal storage of the created histogram will consists of 64-bit 00383 * floating number per histogram bin. 00384 * The name of the histogram must be unique, otherwise exception is thrown. 00385 * 00386 * <b>Returned pointer should never be deleted by client code.</b> 00387 * 00388 * @param[in] name Histogram name, unique string. 00389 * @param[in] title Title of the histogram, arbitrary string. 00390 * @param[in] xaxis X axis definition. 00391 * @param[in] yaxis Y axis definition. 00392 * @return Pointer to a newly created histogram, do not delete. 00393 * 00394 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00395 * identical name exists already 00396 */ 00397 virtual H2* hist2d(const std::string& name, const std::string& title, 00398 const PSHist::Axis& xaxis, const PSHist::Axis& yaxis ) = 0; 00399 00400 // 1-d profile histograms 00401 00402 /** 00403 * @brief Create new 1-dimensional profile histogram and return pointer to it. 00404 * 00405 * This method creates new 1-dimensional profile histogram with same-width bins. 00406 * The name of the histogram must be unique, otherwise exception is thrown. 00407 * Option string determines what value is returned for the bin error, 00408 * possible values are "" (default) for error-of-mean and "s" 00409 * for standard deviation. 00410 * 00411 * <b>Returned pointer should never be deleted by client code.</b> 00412 * 00413 * @param[in] name Histogram name, unique string. 00414 * @param[in] title Title of the histogram, arbitrary string. 00415 * @param[in] nbinsx Number of bins. 00416 * @param[in] xlow Low edge of the first bin. 00417 * @param[in] xhigh High edge of the last bin. 00418 * @param[in] option Option string. 00419 * @return Pointer to a newly created histogram, do not delete. 00420 * 00421 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00422 * identical name exists already 00423 */ 00424 virtual Profile* prof1(const std::string& name, const std::string& title, 00425 int nbinsx, double xlow, double xhigh, const std::string& option="") = 0; 00426 00427 /** 00428 * @brief Create new 1-dimensional profile histogram and return pointer to it. 00429 * 00430 * This method creates new 1-dimensional profile histogram with variable-width bins. 00431 * The name of the histogram must be unique, otherwise exception is thrown. 00432 * Option string determines what value is returned for the bin error, 00433 * possible values are "" (default) for error-of-mean and "s" 00434 * for standard deviation. 00435 * 00436 * <b>Returned pointer should never be deleted by client code.</b> 00437 * 00438 * @param[in] name Histogram name, unique string. 00439 * @param[in] title Title of the histogram, arbitrary string. 00440 * @param[in] nbins Number of bins. 00441 * @param[in] xbinedges Array of the histogram edges, size of the array 00442 * is @c nbins+1, it should contain ordered values for 00443 * low edges of all bins plus high edge of last bin. 00444 * @param[in] option Option string. 00445 * @return Pointer to a newly created histogram, do not delete. 00446 * 00447 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00448 * identical name exists already 00449 */ 00450 virtual Profile* prof1(const std::string& name, const std::string& title, 00451 int nbins, const double *xbinedges, const std::string& option="") = 0; 00452 00453 /** 00454 * @brief Create new 1-dimensional profile histogram and return pointer to it. 00455 * 00456 * This method creates new 1-dimensional profile histogram, number of bins and 00457 * their edges are determined by separate object (Axis class). 00458 * The name of the histogram must be unique, otherwise exception is thrown. 00459 * Option string determines what value is returned for the bin error, 00460 * possible values are "" (default) for error-of-mean and "s" 00461 * for standard deviation. 00462 * 00463 * <b>Returned pointer should never be deleted by client code.</b> 00464 * 00465 * @param[in] name Histogram name, unique string. 00466 * @param[in] title Title of the histogram, arbitrary string. 00467 * @param[in] axis X axis definition. 00468 * @param[in] option Option string. 00469 * @return Pointer to a newly created histogram, do not delete. 00470 * 00471 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00472 * identical name exists already 00473 */ 00474 virtual Profile* prof1(const std::string& name, const std::string& title, 00475 const PSHist::Axis& axis, const std::string& option="") = 0; 00476 00477 /** 00478 * @brief Create new 1-dimensional profile histogram and return pointer to it. 00479 * 00480 * This method creates new 1-dimensional profile histogram with same-width bins. 00481 * The name of the histogram must be unique, otherwise exception is thrown. 00482 * Option string determines what value is returned for the bin error, 00483 * possible values are "" (default) for error-of-mean and "s" 00484 * for standard deviation. 00485 * Values of y ouside of range (ylow-yhigh) will be ignored. 00486 * 00487 * <b>Returned pointer should never be deleted by client code.</b> 00488 * 00489 * @param[in] name Histogram name, unique string. 00490 * @param[in] title Title of the histogram, arbitrary string. 00491 * @param[in] nbinsx Number of bins. 00492 * @param[in] xlow Low edge of the first bin. 00493 * @param[in] xhigh High edge of the last bin. 00494 * @param[in] ylow Lowest possible value for Y values. 00495 * @param[in] yhigh Highest possible value for Y values. 00496 * @param[in] option Option string. 00497 * @return Pointer to a newly created histogram, do not delete. 00498 * 00499 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00500 * identical name exists already 00501 */ 00502 virtual Profile* prof1(const std::string& name, const std::string& title, 00503 int nbinsx, double xlow, double xhigh, double ylow, double yhigh, 00504 const std::string& option="") = 0; 00505 00506 /** 00507 * @brief Create new 1-dimensional profile histogram and return pointer to it. 00508 * 00509 * This method creates new 1-dimensional profile histogram with variable-width bins. 00510 * The name of the histogram must be unique, otherwise exception is thrown. 00511 * Option string determines what value is returned for the bin error, 00512 * possible values are "" (default) for error-of-mean and "s" 00513 * for standard deviation. 00514 * Values of y ouside of range (ylow-yhigh) will be ignored. 00515 * 00516 * <b>Returned pointer should never be deleted by client code.</b> 00517 * 00518 * @param[in] name Histogram name, unique string. 00519 * @param[in] title Title of the histogram, arbitrary string. 00520 * @param[in] nbins Number of bins. 00521 * @param[in] xbinedges Array of the histogram edges, size of the array 00522 * is @c nbins+1, it should contain ordered values for 00523 * low edges of all bins plus high edge of last bin. 00524 * @param[in] ylow Lowest possible value for Y values. 00525 * @param[in] yhigh Highest possible value for Y values. 00526 * @param[in] option Option string. 00527 * @return Pointer to a newly created histogram, do not delete. 00528 * 00529 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00530 * identical name exists already 00531 */ 00532 virtual Profile* prof1(const std::string& name, const std::string& title, 00533 int nbins, const double *xbinedges, double ylow, double yhigh, 00534 const std::string& option="") = 0; 00535 00536 /** 00537 * @brief Create new 1-dimensional profile histogram and return pointer to it. 00538 * 00539 * This method creates new 1-dimensional profile histogram, number of bins and 00540 * their edges are determined by separate object (Axis class). 00541 * The name of the histogram must be unique, otherwise exception is thrown. 00542 * Option string determines what value is returned for the bin error, 00543 * possible values are "" (default) for error-of-mean and "s" 00544 * for standard deviation. 00545 * Values of y ouside of range (ylow-yhigh) will be ignored. 00546 * 00547 * <b>Returned pointer should never be deleted by client code.</b> 00548 * 00549 * @param[in] name Histogram name, unique string. 00550 * @param[in] title Title of the histogram, arbitrary string. 00551 * @param[in] axis X axis definition. 00552 * @param[in] ylow Lowest possible value for Y values. 00553 * @param[in] yhigh Highest possible value for Y values. 00554 * @param[in] option Option string. 00555 * @return Pointer to a newly created histogram, do not delete. 00556 * 00557 * @throw ExceptionDuplicateName thrown if histogram or tuple with 00558 * identical name exists already 00559 */ 00560 virtual Profile* prof1(const std::string& name, const std::string& title, 00561 const PSHist::Axis& axis, double ylow, double yhigh, 00562 const std::string& option="") = 0; 00563 00564 /** 00565 * @brief Store all booked histograms and tuples to a permanent storage. 00566 * 00567 * This method should be called once before deleting manager object. 00568 * 00569 * @throw ExceptionStore thrown if write operation fails. 00570 */ 00571 virtual void write() = 0; 00572 00573 }; 00574 00575 } // namespace PSHist 00576 00577 #endif // PSHIST_HMANAGER_H