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
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_ (),
00033 value_ (-999999),
00034 value_ext_ (0),
00035
00036 saveHist_ (saveHist),
00037 saveNtup_ (saveNtup),
00038
00039 verboseLevel_ (0)
00040 {
00041 if (verboseLevel_ > 5)
00042 std::cout << "PhysVarHisto(" << name_ << "):: in constructor." << std::endl;
00043
00044
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
00072
00073
00074 histos_.push_back( h );
00075 }
00076 }
00077
00078
00079
00080
00081
00082
00083 void
00084 PhysVarHisto::
00085 fill( double x, unsigned int imulti, double weight )
00086 {
00087
00088
00089
00090 value_ = x;
00091
00092 valueColl_.push_back( x );
00093
00094 if ( value_ext_ ) {
00095
00096 *( (double*)(value_ext_) ) = value_ ;
00097 }
00098
00099 if (verboseLevel_ > 5) {
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
00114
00115
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
00123 makeTH1();
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