CMS 3D CMS Logo

PhysVarHisto.cc

Go to the documentation of this file.
00001 
00002 #include "PhysicsTools/StarterKit/interface/PhysVarHisto.h"
00003 
00004 #include <string>
00005 #include <sstream>
00006 #include <iostream>
00007 
00008 using pat::PhysVarHisto;
00009 
00010 // Constructor:
00011 PhysVarHisto::
00012 PhysVarHisto( std::string name,
00013               std::string title,
00014               int         nbins,
00015               double      xlow,
00016               double      xhigh,
00017               TFileDirectory * currDir,
00018               std::string units,
00019               std::string type,
00020               bool        saveHist,
00021               bool        saveNtup )
00022   :
00023   currDir_ (currDir),
00024   name_  (name),
00025   type_  (type),
00026   title_ (title),
00027   nbins_ (nbins),
00028   xlow_  (xlow),
00029   xhigh_ (xhigh),
00030   units_ (units),
00031   //
00032   histos_ (),             // vector of 0 elements
00033   value_ (-999999),
00034   value_ext_ (0),
00035   //
00036   saveHist_ (saveHist),
00037   saveNtup_ (saveNtup),
00038   //
00039   verboseLevel_ (0)      // default = very verbose (&&& hardcoded)
00040 {
00041   if (verboseLevel_ > 5)
00042     std::cout << "PhysVarHisto(" << name_ << "):: in constructor." << std::endl;
00043 
00044   // &&& Not sure what (if anything) will be needed to deal with the ntuple.
00045 }
00046 
00047 
00048 void
00049 PhysVarHisto::
00050 makeTH1()
00051 {
00052   if (verboseLevel_ > 5)
00053     std::cout << "PhysVarHisto(" << name_ << "):: in makeTH1()." << std::endl;
00054 
00055 
00056   if (saveHist_ && currDir_) {
00057     if (verboseLevel_ > 5)
00058       std::cout << "PhysVarHisto(" << name_ << ")::makeTH1:"
00059                 << " making new histo." << std::endl;
00060 
00061     std::string name, title;
00062     std::stringstream partNum;
00063     partNum << histos_.size()+1;
00064 
00065     name  = name_  + "_" + partNum.str();
00066     title = title_ + " #" + partNum.str()+ ";" + units_ ;
00067 
00068 
00069     TH1D * h = currDir_->make<TH1D>( name.c_str(), title.c_str(),
00070                                      nbins_, xlow_, xhigh_ );
00071     // &&& Now decorate: set thickness, bkg color, axis labels, etc.
00072     // &&& lift the axis labels from RooFit which does a nice job on them
00073 
00074     histos_.push_back( h );
00075   }
00076 }
00077 
00078 
00079 // Note: imulti follows Fortran-style indexing,
00080 // so imulti==1 is the 1st element.  Note that the histos_ vector
00081 // wakes up with no elements, so histos_.size() gives 0 in the first
00082 // call to fill().
00083 void
00084 PhysVarHisto::
00085 fill( double x, unsigned int imulti, double weight )
00086 {
00087   // Once this PhysVarHisto was made, then there's no turning back
00088   // when it comes to fill() : we cache the value no matter what.
00089 
00090   value_ = x;  // save in case we need to capture it for the ntuple.
00091 
00092   valueColl_.push_back( x );
00093 
00094   if ( value_ext_ ) {
00095     // Defined, use this one as well
00096     *( (double*)(value_ext_) ) = value_ ;
00097   }
00098 
00099   if (verboseLevel_ > 5) {  // very verbose
00100     std::cout << "PhysVarHisto(" << name_ << ")::fill: "
00101               << "value = " << value_ << ". External storage is ";
00102     if (value_ext_)  std::cout << "defined." << std::endl;
00103     else         std::cout << "not defined." << std::endl;
00104   }
00105 
00106 
00107 
00108   if ( ! saveHist_ ) {
00109     std::cout << "PhysVarHisto(" << name_ << ")::fill: saveHist is not defined" << std::endl;
00110     return;
00111   }
00112 
00113   //--- If the requested histo location in multi-histogram
00114   //--- mode is larger than our current vector of histograms,
00115   //--- then grow it up to the location requested.
00116   //
00117   while ( imulti > histos_.size() ) {
00118     if (verboseLevel_ > 4) {
00119       std::cout << "PhysVarHisto(" << name_ << ")::fill: grow histo list by one."
00120                 << std::endl;
00121     }
00122     //--- Make another TH1 at index == current value of size()
00123     makeTH1();    // histos_ vector grows by one element
00124   }
00125   if ( verboseLevel_ > 4 )
00126     std::cout << "PhysVarHisto(" << name_ << ")::fill: About to fill " << imulti << std::endl;
00127   histos_[ imulti-1 ]->Fill( value_, weight );
00128   if ( verboseLevel_ > 4 )
00129     std::cout << "PhysVarHisto(" << name_ << ")::fill: Done filling " << imulti << std::endl;
00130 }
00131 

Generated on Tue Jun 9 17:41:56 2009 for CMSSW by  doxygen 1.5.4