// ---------------------------------------------------------------------- // // HepHistoHistProf.cc - implementation of Histo profile histogram // // HepHistoHistProf is the implementation of the Histo profile // histogram. It is derived from HepHistProf (the generic interface) and // HepHistoHist. It is mainly a C++ wrapper around the CERNlib Histo // Fortran histogramming libraries. // // No HepHistoHistProf objects are ever directly // instantiated by the programmer. When creating new HepHist* objects, // the manager is in charge of creating the appropriate HepHisto object. // // To use generate Histo histograms, HepHistoFileManager must be used: // // int lunit = 10; // HepFileManager* m = new HepHistoFileManager("filename.rz", lunit); // : // : // HepHistProf* h(m->histProf("Title", 100, 0.0, 23.0, 0.0, 23.0)); // float x, y, weight; // : // [gather data] // : // h->accumulate(x, y, weight); // // // Note that the constructor can take an ID number which is used by // the Histo implementation of HepHistProf. If omitted, the ID number is // generated automatically (which is recommended). The ID number is // available through the id() method. // // Bob Jacobsen // 30-May-1997 Walter Brown Added cloning functions // 29-May-1997 Jason Luther Added comments // 04-Jun-1997 Jason Luther Rewrote comments // 04-Aug-1998 Philippe Canal Added weight, entries, sum, etc.. // // ---------------------------------------------------------------------- #ifndef HEPTRACE_H #include "HepTuple/HepTrace.h" #endif #ifndef HEPHISTOHISTPROF_H #include "HepTuple/HepHistoHistProf.h" #endif #ifndef HEPFILEMANAGER_H #include "HepTuple/HepFileManager.h" #endif #include "histoscope.h" #include "ZMutility/iostream" #include USING( std::string ) #define HS_MAX_CATEGORY_LENGTH 255 #define HS_MAX_TITLE_LENGTH 80 #define HS_MAX_NAME_LENGTH 80 ZM_BEGIN_NAMESPACE( zmht ) /* namespace zmht { */ // create a profile plot with the given title and binning HepHistoHistProf::HepHistoHistProf( HepHistoFileManager * manager , const string& title , const int nBinsX, const float lowX, const float highX , const float lowY, const float highY , const string& chopt , const int idReq , const int histo_id ) : HepHistProf( manager, title, nBinsX, lowX, highX, lowY, highY, chopt, idReq ), histo_id_(histo_id) { HEP_DEBUG( "HepHistoHistProf::constructor( \"" << title << "\", " << id_ << " )" ); } // HepHistoHistProf::HepHistoHistProf() HepHistoHistProf::HepHistoHistProf( HepHistoFileManager * manager , const string& title , const int nBinsX, const float lowX, const float highX , const float lowY, const float highY , const int idReq , const int histo_id ) : HepHistProf( manager, title, nBinsX, lowX, highX, lowY, highY, idReq ), histo_id_(histo_id) { } // HepHistoHistProf::HepHistoHistProf() HepHistoHistProf::HepHistoHistProf( HepHistProf * original , const string& title , const int idReq ) : HepHistProf( original->manager(), title, original->nBinsX(), original->minX(), original->maxX(), original->minY(), original->maxY(), idReq ) { // make the Histoscope item int oldID = ((HepHistoHistProf*)original)->histo_id_; histo_id_ = hs_copy(oldID, idReq, (char*)title.c_str(), (char*)HepHistoFileManager::category(original->dir()).c_str() ); } // HepHistoHistProf::HepHistoHistProf() // Used for dummy construction ... // the object is then not valid ... HepHistoHistProf::HepHistoHistProf() : HepHistProf() { HEP_DEBUG( "HepHistoHistProf::constructor( )" ); } HepHistoHistProf::~HepHistoHistProf() { HEP_DEBUG( "HepHistoHistProf::destructor( \"" << *title_ << "\", " << id_ << " )" ); } void HepHistoHistProf::accumulate( const float x , const float y , const float weight ) { ZMthrow(ZMxHepNotYet("Profile Histogram")); if ( mayUse() ) { _accumulate( x, y, weight ); // hs_fill_prof_hist( histo_id_, x, y, weight ); } else { ZMthrow(ZMxHepUnmanagedItem("attempt to accumulate() to unmanaged histogram.")); return; } } #define CHECK(name) \ if (! mayUse() ) { \ ZMthrow(ZMxHepUnmanagedItem( \ string("attempt to " #name "() an unmanaged histogram ") \ +title()+string("."))); \ return 0; \ } int HepHistoHistProf::entries() const { // number of entries CHECK(entries); ZMthrow(ZMxHepNotYet("Profile Histogram")); // call histo function return hs_num_entries(histo_id_); } int HepHistoHistProf::entries( const int binNumX) const { // number of entries in X-bin ZMthrow(ZMxHepUnsupported("Histo's Histogram Profoile do not have access to the number of entries by bin")); CHECK(entries); return 0; } float HepHistoHistProf::weight() const { // sum of all weight CHECK(weight); ZMthrow(ZMxHepNotYet("Profile Histogram")); /* This stuff is a copy of the code from HepHBookHist1D.cc We don't quite know what to do for HistoScope just yet. int nx, ny, nwt, loc; float xmi, xma, ymi, yma; float *contents; const int maxTitleLen = 80; char rtitle[maxTitleLen+1]; int kase = 1; float sumw = 0.0; rtitle[maxTitleLen] = '\0'; HGIVE( id_, rtitle, nx, xmi, xma, ny, ymi, yma, nwt, loc ); contents = new float[nx]; PUNPAK( id_, *contents, kase, nx ); for(int i=0; i