CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

CompHist Class Reference

#include <CompHist.h>

Inheritance diagram for CompHist:
FitHist TopInspect ManipHist TopInspectFit CalibClosureTest TopInspectRatio TopInspectSum

List of all members.

Public Types

enum  HistFilter { kBeginsWith, kEndsWith, kContains }
enum  RootOutput { kFirstOnly, kLastOnly, kAll }

Public Member Functions

 CompHist ()
 CompHist (bool verbose)
void draw (TCanvas &, TLegend &, int &, int &)
void drawEps ()
void drawPs ()
bool histFilter (TString &, std::vector< std::string > &)
bool histFilter (TString &, std::vector< std::string > &, CompHist::HistFilter)
void loadHistograms (std::vector< std::string > &, std::vector< TObjArray > &)
void loadHistograms ()
virtual void readConfig (std::string)=0
void setVerbose (bool val)
bool verbose ()
std::string writeAs ()
void writeOutput (CompHist::RootOutput)
void writeOutput ()
virtual ~CompHist ()

Protected Member Functions

void configBlockHist (ConfigFile &)
void configBlockIO (ConfigFile &)
double findMaximum (int)
bool isOutputRequested ()
std::string legend (int)
void readHistogramList ()
void readLabels (std::string, std::vector< std::string > &)
void setAxesStyle (TH1 &, const char *, const char *)
void setCanvasStyle (TCanvas &)
void setCanvGrid (TCanvas &, int)
void setCanvLog (TCanvas &, int)
void setFillColor (TH1F &, int)
void setFillStyle (TH1F &, int)
void setHistLabels (TH1F &, int)
void setHistMax (TH1F &, int)
void setHistMin (TH1F &, int)
void setHistScale (TH1F &, int)
void setHistStyles (TH1F &, int, int)
void setLegendStyle (TLegend &)
void setLineColor (TH1F &, int)
void setLineStyle (TH1F &, int)
void setLineWidth (TH1F &, int)
void setMarkerColor (TH1F &, int)
void setMarkerSize (TH1F &, int)
void setMarkerStyle (TH1F &, int)

Protected Attributes

std::vector< short int > commonStyle_
std::vector< short int > commonWidth_
std::vector< std::string > dirNameList_
std::vector< short int > errors_
std::vector< TFile * > fileList_
std::vector< std::string > fileNameList_
std::string filterOpt_
std::vector< short int > gridX_
std::vector< short int > gridY_
std::vector< short int > histColor_
std::string histFile_
std::vector< std::string > histFilterList_
std::vector< std::string > histList_
std::vector< short int > histStyle_
std::vector< std::string > legendEntries_
double legXLeft_
double legXRight_
double legYLower_
double legYUpper_
std::vector< short int > logX_
std::vector< short int > logY_
std::vector< double > markerSize_
std::vector< short int > markerStyle_
std::vector< double > max_
std::vector< double > min_
std::string output_
std::vector< std::string > outputLabelList_
std::vector< std::string > plotFilterList_
std::string rootOutDir_
std::vector< TObjArray > sampleList_
std::vector< double > scale_
bool verbose_
std::string writeAs_
std::string writeTo_
std::vector< std::string > xAxes_
std::vector< std::string > yAxes_

Detailed Description

Definition at line 35 of file CompHist.h.


Member Enumeration Documentation

Enumerator:
kBeginsWith 
kEndsWith 
kContains 

Definition at line 40 of file CompHist.h.

Enumerator:
kFirstOnly 
kLastOnly 
kAll 

Definition at line 39 of file CompHist.h.


Constructor & Destructor Documentation

CompHist::CompHist ( ) [inline]

Definition at line 44 of file CompHist.h.

:verbose_(false){};
CompHist::CompHist ( bool  verbose) [inline]

Definition at line 45 of file CompHist.h.

virtual CompHist::~CompHist ( ) [inline, virtual]

Definition at line 47 of file CompHist.h.

{};

Member Function Documentation

void CompHist::configBlockHist ( ConfigFile cfg) [protected]

Definition at line 72 of file CompHist.cc.

References ExpressReco_HICollisions_FallBack::cerr, cmsRelvalreport::exit, ConfigFile::read(), and readVector().

{
  //-----------------------------------------------
  // read all configurables defined in CompHisto-
  // grams from config file. Throw human readable 
  // exception when misspellings occure
  //-----------------------------------------------
  try{
    //-----------------------------------------------
    // canvas steering
    //-----------------------------------------------
    readVector( cfg.read<std::string>( "xLog" ), logX_ );
    readVector( cfg.read<std::string>( "yLog" ), logY_ );
    readVector( cfg.read<std::string>( "xGrid" ), gridX_);
    readVector( cfg.read<std::string>( "yGrid" ), gridY_);

    //-----------------------------------------------
    // histogram steering
    //-----------------------------------------------
    readVector( cfg.read<std::string>( "histErrors" ), errors_);
    readVector( cfg.read<std::string>( "histScale" ), scale_ );
    readVector( cfg.read<std::string>( "histMinimum"), min_ );
    readVector( cfg.read<std::string>( "histMaximum"), max_ );
    readVector( cfg.read<std::string>( "histType" ), histStyle_ );
    readVector( cfg.read<std::string>( "histStyle" ), commonStyle_ );
    readVector( cfg.read<std::string>( "histColor" ), histColor_ );
    readVector( cfg.read<std::string>( "lineWidth" ), commonWidth_ );
    readVector( cfg.read<std::string>( "markerStyle" ), markerStyle_ );
    readVector( cfg.read<std::string>( "markerSize" ), markerSize_ );
    readLabels( cfg.read<std::string>( "xAxes" ), xAxes_ );
    readLabels( cfg.read<std::string>( "yAxes" ), yAxes_ );

    //-----------------------------------------------
    // legend steering
    //-----------------------------------------------
    readLabels( cfg.read<std::string>( "legEntries"), legendEntries_);
    legXLeft_ = cfg.read<double>( "legXLeft" );
    legXRight_= cfg.read<double>( "legXRight" );
    legYLower_= cfg.read<double>( "legYLower" );
    legYUpper_= cfg.read<double>( "legYUpper" );
  }
  catch(...){
    std::cerr << "ERROR during reading of config file"   << std::endl;
    std::cerr << "      misspelled variables in cfg ?"   << std::endl;
    std::cerr << "      [--called in configBlockHist--]" << std::endl;
    std::exit(1);
  }
}
void CompHist::configBlockIO ( ConfigFile cfg) [protected]

Definition at line 40 of file CompHist.cc.

References ExpressReco_HICollisions_FallBack::cerr, cmsRelvalreport::exit, ConfigFile::read(), and readVector().

{
  //-----------------------------------------------
  // read all configurables defined in CompHisto-
  // grams from config file. Throw human readable 
  // exception when misspellings occure
  //-----------------------------------------------
  try{
    //-----------------------------------------------
    // input/output files
    //-----------------------------------------------
    histFile_  = cfg.read<std::string>( "histInput" );
    readVector ( cfg.read<std::string>( "rootInput" ), fileNameList_ );
    readVector ( cfg.read<std::string>( "inputDirs" ), dirNameList_  );
    filterOpt_ = cfg.read<std::string>( "filterOption" );
    readVector ( cfg.read<std::string>( "histFilter" ), histFilterList_ );
    readVector ( cfg.read<std::string>( "plotFilter" ), plotFilterList_ );
    writeTo_   = cfg.read<std::string>( "writePlotsTo" );
    writeAs_   = cfg.read<std::string>( "writePlotsAs" );
    rootOutDir_= cfg.read<std::string>( "outputDir" );
    output_    = cfg.read<std::string>( "rootOutput" );
    readVector ( cfg.read<std::string>( "outputLabels" ), outputLabelList_ );
  }
  catch(...){
    std::cerr << "ERROR during reading of config file" << std::endl;
    std::cerr << "      misspelled variables in cfg ?" << std::endl;
    std::cerr << "      [--called in configBlockIO--]" << std::endl;
    std::exit(1);
  }
}
void CompHist::draw ( TCanvas &  canv,
TLegend &  leg,
int &  idx,
int &  jdx 
)

Definition at line 294 of file CompHist.cc.

References HistStyle::Filled, estimatePileup::hist, HistStyle::Line, and HistStyle::Marker.

{  
  //-----------------------------------------------
  // loop all samples via the list sampleList_, which 
  // containas the histograms of each sample as 
  // TObjects in TObjectArrays
  //-----------------------------------------------
  TH1F hfirst; //draw first histogram on top of others
               //after all histograms have been drawn
  std::vector<TObjArray>::const_iterator hist = sampleList_.begin();
  for(int kdx=0; hist!=sampleList_.end(); ++hist, ++kdx){
    TH1F& hcmp = *((TH1F*)(*hist)[idx]); //recieve histogram
    setCanvLog( canv, jdx );
    setCanvGrid( canv, jdx );
    setHistStyles( hcmp, jdx, kdx );
    // for the first histogram just draw
    // for the following ones draw same
    if(kdx==0){
      hfirst = hcmp; // buffer first histogram to redraw it after all
      if(errors_[kdx]) 
        hcmp.Draw("e");
      else 
        hcmp.Draw(   );
    }
    else{
      if(errors_[kdx]) 
        hcmp.Draw("samee");
      else 
        hcmp.Draw("same" );
    }
    // add legend entry in appropriate format
    switch( histStyle_[kdx]){
    case HistStyle::Line:
      leg.AddEntry( &hcmp, legend(kdx).c_str(), "L"  );
      break;
      
    case HistStyle::Marker:
      leg.AddEntry( &hcmp, legend(kdx).c_str(), "PL" );
      break;
      
    case HistStyle::Filled:
      leg.AddEntry( &hcmp, legend(kdx).c_str(), "FL" );
      break;
    }
  }
  if(errors_[0]){
    hfirst.Draw("esame");
  }
  else{
    hfirst.Draw( "same"); 
  }
  leg.Draw( "same" );
  canv.RedrawAxis( );
  canv.Update( );
}
void CompHist::drawEps ( )

Definition at line 404 of file CompHist.cc.

References gather_cfg::cout, and convertSQLitetoXML_cfg::output.

Referenced by main().

{
  //-----------------------------------------------
  // define canvas
  //-----------------------------------------------
  TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
  setCanvasStyle( *canv  );

  //-----------------------------------------------
  // loop histograms via the list of histogram
  // names stored in histList_, open a new page 
  // for each histogram & plot each sample in 
  // the same canvas
  //-----------------------------------------------  
  for(int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
    //-----------------------------------------------
    // prepare compare string for plot filtering
    //-----------------------------------------------
    TString cmp( histList_[idx] );
    if( !histFilter(cmp, plotFilterList_) ){
      if(verbose_){
        cout << " event is filtered out according to"
             << " settings in cfg file; filterOpt:  "
             << filterOpt_ 
             << " hist: " << cmp << std::endl;
      }
      continue;
    }
    //-----------------------------------------------
    // open output files
    //-----------------------------------------------
    TString output( writeTo_.c_str() );
    output += "/";
    output += histList_[ idx ];
    output += ".";
    output += writeAs_;

    TPostScript psFile( output, 113);
    psFile.NewPage();
    //-----------------------------------------------
    // on each page the legend needs to be redeclared
    //-----------------------------------------------   
    TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
    setLegendStyle( *leg ); 
    draw(*canv, *leg, idx, jdx);
    psFile.Close();
    ++jdx; delete leg;
  }
  canv->Close();
  delete canv;
}
void CompHist::drawPs ( )

Definition at line 351 of file CompHist.cc.

References gather_cfg::cout, and convertSQLitetoXML_cfg::output.

Referenced by main().

{
  //-----------------------------------------------
  // define canvas
  //-----------------------------------------------
  TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
  setCanvasStyle( *canv  );

  //-----------------------------------------------
  // open output file
  //-----------------------------------------------
  TString output( writeTo_.c_str() );
  output += "/";
  output += "inspect";
  output += ".";
  output += writeAs_;
  TPostScript psFile( output, 111); //112 for portrait

  //-----------------------------------------------
  // loop histograms via the list of histogram
  // names stored in histList_, open a new page 
  // for each histogram & plot each sample in 
  // the same canvas
  //-----------------------------------------------
  for(int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
    // prepare compare string for plot filtering
    TString cmp( histList_[idx] );
    if( !histFilter(cmp, plotFilterList_) ){
      if(verbose_){
        cout << " event is filtered out according to"
             << " settings in cfg file; filterOpt:  "
             << filterOpt_ 
             << " hist: " << cmp << std::endl;
      }
      continue;
    }
    psFile.NewPage();
    //-----------------------------------------------
    // on each page the legend needs to be redeclared
    //-----------------------------------------------   
    TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
    setLegendStyle( *leg );  
    draw(*canv, *leg, idx, jdx);
    if(idx == (int)histList_.size()-1){
      psFile.Close();
    }
    ++jdx; delete leg;
  }
  canv->Close();
  delete canv;
}
double CompHist::findMaximum ( int  idx) [protected]

Definition at line 468 of file CompHist.cc.

References estimatePileup::hist, and max().

{
  double max=-1.;
  for(std::vector<TObjArray>::const_iterator hist = sampleList_.begin(); 
      hist!=sampleList_.end(); ++hist){
    TH1F& hcmp = *((TH1F*)(*hist)[idx]); //recieve histogram
    if( max<0 || hcmp.GetMaximum()>max ) max=hcmp.GetMaximum();
  }
  return max;
}
bool CompHist::histFilter ( TString &  cmp,
std::vector< std::string > &  ref 
)

Definition at line 244 of file CompHist.cc.

References ExpressReco_HICollisions_FallBack::cerr.

{
  bool contained=true;
  if(!filterOpt_.empty()){
    contained=false;
    if(!filterOpt_.compare("begins")){
      contained = histFilter(cmp, ref, kBeginsWith);
    }
    else if(!filterOpt_.compare("ends")){
      contained = histFilter(cmp, ref, kEndsWith);
    }
    else if(!filterOpt_.compare("contains")){
      contained = histFilter(cmp, ref, kContains);
    }
    else{
      std::cerr << "ERROR during histogram filtering   " << std::endl;
      std::cerr << "      filter option is not properly" << std::endl;
      std::cerr << "      specified : " << filterOpt_ << std::endl;
    }
  }
  return contained;
}
bool CompHist::histFilter ( TString &  cmp,
std::vector< std::string > &  ref,
CompHist::HistFilter  option 
)

Definition at line 268 of file CompHist.cc.

{
  bool contained=true;
  if(ref.size()>0){
    contained=false;
    for(unsigned int idx=0; idx<ref.size(); ++idx){
      TString buffer(ref[idx]);
      if( !option==kContains ) buffer+="_";
      if( option==kBeginsWith && cmp.BeginsWith(buffer) ){ 
        contained=true;
        break;
      }
      if( option==kEndsWith && cmp.EndsWith(buffer) ){
        contained=true;
        break;
      }
      if( option==kContains && cmp.Contains(buffer) ){
        contained=true;
        break;
      }
    }
  }
  return contained;
}
bool CompHist::isOutputRequested ( ) [inline, protected]

Definition at line 69 of file CompHist.h.

References rootOutDir_.

{return rootOutDir_.size()>1;};
std::string CompHist::legend ( int  idx) [protected]

Definition at line 457 of file CompHist.cc.

{
  char buffer[100];
  sprintf(buffer, "undefined sample %i", idx);
  if( legendEntries_.size()>=sampleList_.size() ){
    return legendEntries_[idx];
  }
  return buffer;
}
void CompHist::loadHistograms ( )

Definition at line 216 of file CompHist.cc.

References gather_cfg::cout.

{
  //-----------------------------------------------
  // fill histograms listed in histList_ into a
  // TObjectArray for each sample given in the 
  // list fileNameList_ and its directories; Each 
  // TObjectArray is then pushed into the vector 
  // sampleList_ which keeps all TObjectArrays of 
  // histograms for each sample 
  //-----------------------------------------------

  //fill histogram list
  if( !histFile_.empty() )
    readHistogramList();
  else{
    if( histFilterList_.size()>0 ){
      if( !filterOpt_.compare("contains") )
        cout << "WARNING: missing hist file in cfg file; will use list of histogram" << std::endl
             << "         names given in histFilter instead, requires filterOption " << std::endl
             << "         'optains'; will move filterOption to 'optain' to go on..." << std::endl;
      filterOpt_="contains";
      histList_ =histFilterList_;
    }
  }
  loadHistograms(histList_, sampleList_);
}
void CompHist::loadHistograms ( std::vector< std::string > &  histList,
std::vector< TObjArray > &  sampleList 
)

Definition at line 159 of file CompHist.cc.

References ExpressReco_HICollisions_FallBack::cerr, gather_cfg::cout, createBeamHaloJobs::directory, dbtoweb::file, estimatePileup::hist, and AlCaRecoCosmics_cfg::name.

Referenced by main().

{
  //fill vector of root files if not already done
  if( fileList_.empty() ){
    std::vector<std::string>::const_iterator name;
    for(name = fileNameList_.begin(); name!=fileNameList_.end(); ++name){
      fileList_.push_back( new TFile( name->c_str() ) );
    }
  }
  //fill vector of histogram arrays
  std::vector<TFile*>::const_iterator file = fileList_.begin();
  for(int jdx=0 ; file!=fileList_.end(); ++file, ++jdx){
    std::vector<std::string>::const_iterator rootDir;
    for(rootDir = dirNameList_.begin(); rootDir!=dirNameList_.end(); ++rootDir){
      TH1F *dummy;
      TObjArray hist;
      for( int idx=0; idx<(int)histList.size(); ++idx ){
        TString directory( *rootDir );
        directory+="/";
        directory+=histList[idx];
        
        if(verbose_){
          std::cout << "load from: " << (*file)->GetName() << " " 
               << "directory: " << directory << std::endl;
        }
        dummy = (TH1F*)(*file)->Get( directory );
        if( !dummy ){
          std::cerr << "WARNING:" 
               << " Didn't find indicated hist"
               << " [" << directory << "]" 
               << " in file" 
               << " [" << (*file)->GetName() << "]" 
               << std::endl;
          return;
        }

        // prepare unambiguous histogram name
        TString outname( fileNameList_[jdx] );
        outname.Remove(outname.Last('.'), outname.Length());
        outname += ":";
        outname += *rootDir;
        outname +="/";
        outname +=dummy->GetName();
        dummy->SetName( outname );

        // add histogram to list
        hist.Add( dummy );
        if(verbose_){
          std::cout << "added to list as: " << dummy->GetName() << std::endl;
        }
      } // end of histogram name list 
      sampleList.push_back( hist );
    } // end of root directory list
  } // end of root file list
}
virtual void CompHist::readConfig ( std::string  ) [pure virtual]
void CompHist::readHistogramList ( ) [protected]

Definition at line 122 of file CompHist.cc.

References ExpressReco_HICollisions_FallBack::cerr, prof2calltree::count, gather_cfg::cout, and estimatePileup::histFile.

{
  //-----------------------------------------------
  // fill the list histList_ with all requested
  // histogram names; the names are recieved from 
  // a .hist file; jump out if the reading takes 
  // too long 
  //-----------------------------------------------
  ifstream histFile( histFile_.c_str() );

  int count=0;
  while( !histFile.eof() ){
    std::string buffer;
    histFile >> buffer;
    if( buffer.size()>0 ){
      TString cmp(buffer);
      if( histFilter(cmp, histFilterList_) )
        histList_.push_back(buffer);
      else{
        if(verbose_){
          std::cout << " histogram is filtered out according"
               << " to settings in cfg file; filterOpt:  "
               << filterOpt_ << std::endl;
        }
      }
    }
    if( count>999 ){
      std::cerr << "ERROR caught in slope for histogram" << std::endl;
      std::cerr << "      names. Misspelled file name ?" << std::endl;
      std::cerr << histFile_.c_str() << std::endl;
      break;
    }
    ++count;
  }
}
void CompHist::readLabels ( std::string  s,
std::vector< std::string > &  vec 
) [protected]

Definition at line 9 of file CompHist.cc.

References label.

{
  //-----------------------------------------------
  // fill vector of std::string's from a single
  // std::string s; the process starts as soon as 
  // leading " are found and starts a new substr
  // as soon as a "; is encountered
  //-----------------------------------------------
  std::stringstream stream( s );
  std::string buffer, label;
  while (!stream.eof()) {
    stream >> buffer;
    if(buffer.find("\"", 0)==0){
      //start new label if leading " are found
      label=buffer;
    }
    else{
      //concatenate buffer to label else
      label+=" ";
      label+=buffer;
    }

    //push_back label if it starts with " and ends with ";
    if(buffer.find("\"", buffer.size()-2)==buffer.size()-2 &&
       buffer.find(";",  buffer.size()-2)==buffer.size()-1){
      vec.push_back( label.substr(1, label.size()-3) );
    }
  }
}
void CompHist::setAxesStyle ( TH1 &  hist,
const char *  titleX,
const char *  titleY 
) [protected]

Definition at line 532 of file CompHist.cc.

{
  hist.SetTitle( "" );

  hist.GetXaxis()->SetTitle( titleX );
  hist.GetXaxis()->SetTitleSize  ( 0.06 );
  hist.GetXaxis()->SetTitleColor (    1 );
  hist.GetXaxis()->SetTitleOffset(  1.0 );
  hist.GetXaxis()->SetTitleFont  (   62 );
  hist.GetXaxis()->SetLabelSize  ( 0.05 );
  hist.GetXaxis()->SetLabelFont  (   62 );
  hist.GetXaxis()->CenterTitle   (      );
  hist.GetXaxis()->SetNdivisions (  505 );
  
  hist.GetYaxis()->SetTitle( titleY );
  hist.GetYaxis()->SetTitleSize  ( 0.07 );
  hist.GetYaxis()->SetTitleColor (    1 );
  hist.GetYaxis()->SetTitleOffset(  1.3 );
  hist.GetYaxis()->SetTitleFont  (   62 );
  hist.GetYaxis()->SetLabelSize  ( 0.05 );
  hist.GetYaxis()->SetLabelFont  (   62 );
}
void CompHist::setCanvasStyle ( TCanvas &  canv) [protected]

Definition at line 488 of file CompHist.cc.

{
  canv.SetFillStyle   ( 4000 );
  canv.SetLeftMargin  ( 0.20 );
  canv.SetRightMargin ( 0.05 );
  canv.SetBottomMargin( 0.15 );
  canv.SetTopMargin   ( 0.05 );
}
void CompHist::setCanvGrid ( TCanvas &  canv,
int  idx 
) [protected]

Definition at line 515 of file CompHist.cc.

{
  if( idx<((int)gridX_.size()-1) && idx<((int)gridY_.size()-1) ){
    canv.SetGridx ( gridX_[idx]  );
    canv.SetGridy ( gridY_[idx]  );
  }
  else if( idx<((int)gridY_.size()-1) ){
    canv.SetGridx ( 0 );
    canv.SetGridy ( gridY_[idx]  );
  }
  else{
    canv.SetGridx ( 0 );
    canv.SetGridy ( 0 );
  }
}
void CompHist::setCanvLog ( TCanvas &  canv,
int  idx 
) [protected]

Definition at line 498 of file CompHist.cc.

{
  if( idx<((int)logX_.size()-1) && idx<((int)logY_.size()-1) ){
    canv.SetLogx ( logX_[idx]  );
    canv.SetLogy ( logY_[idx]  );
  }
  else if( idx<((int)logY_.size()-1) ){
    canv.SetLogx ( 0 );
    canv.SetLogy ( logY_[idx]  );
  }
  else{
    canv.SetLogx ( 0 );
    canv.SetLogy ( 0 );
  }
}
void CompHist::setFillColor ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 689 of file CompHist.cc.

{
  hist.SetFillColor( 1 );
  if( jdx<((int)histColor_.size()) ){
    hist.SetFillColor(histColor_[jdx]);
  }
}
void CompHist::setFillStyle ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 680 of file CompHist.cc.

{
  hist.SetFillStyle( 3005 );
  if( jdx<((int)commonStyle_.size()) ){
    hist.SetFillStyle(commonStyle_[jdx]);
  }
}
void CompHist::setHistLabels ( TH1F &  hist,
int  idx 
) [protected]

Definition at line 604 of file CompHist.cc.

{
  if( idx<((int)xAxes_.size()) && idx<((int)yAxes_.size()) ){
    setAxesStyle( hist, xAxes_[idx].c_str(), yAxes_[idx].c_str() );
  }
  else if( idx<((int)xAxes_.size()) ){
    setAxesStyle( hist, xAxes_[idx].c_str(), "events" );
  }
  else{
    if( strcmp(hist.GetTitle(),"") == 0 ){
      setAxesStyle( hist, hist.GetXaxis()->GetTitle(), "events" );  
    }
    else{
      setAxesStyle( hist, hist.GetTitle(), "events" );            
    }           
  }
}
void CompHist::setHistMax ( TH1F &  hist,
int  idx 
) [protected]

Definition at line 631 of file CompHist.cc.

{
  if( ((int)max_.size()>0) && (idx<(int)max_.size()) ){
    hist.SetMaximum(max_[idx]);
  }
  else{
    hist.SetMaximum(1.5*findMaximum(idx));
  }
}
void CompHist::setHistMin ( TH1F &  hist,
int  idx 
) [protected]

Definition at line 642 of file CompHist.cc.

{
  if( ((int)min_.size()>0) && (idx<(int)min_.size()) ){
    hist.SetMinimum(min_[idx]);
  }
  else{
    hist.SetMinimum(0.);    
  }
}
void CompHist::setHistScale ( TH1F &  hist,
int  idx 
) [protected]

Definition at line 623 of file CompHist.cc.

{
  if( idx<((int)scale_.size()) ){
    if( scale_[idx]>0 ) hist.Scale(scale_[idx]/hist.Integral());
  }
}
void CompHist::setHistStyles ( TH1F &  hist,
int  idx,
int  jdx 
) [protected]

Definition at line 556 of file CompHist.cc.

References HistStyle::Filled, HistStyle::Line, and HistStyle::Marker.

{
  //-----------------------------------------------
  // check hist style; throw exception if style 
  // is not competible with specifications; set 
  // default line[0] if vector is too short
  //-----------------------------------------------
  int histType=0;
  if( jdx<((int)histStyle_.size()) ){
    if(HistStyle::Line<=histStyle_[jdx] && histStyle_[jdx]<=HistStyle::Filled){
      histType=histStyle_[jdx];
    }
    else{
      throw "Histogram Type cannot be specified ";
    }
  }
  
  //define histogram styles
  setHistLabels( hist, idx );
  setHistScale ( hist, idx );
  setHistMax   ( hist, idx );
  setHistMin   ( hist, idx );

  switch( histType ){
  case HistStyle::Line: 
    setLineWidth( hist, jdx );
    setLineColor( hist, jdx );
    setLineStyle( hist, jdx );
    break;

  case HistStyle::Marker:
    setLineWidth  ( hist, jdx );
    setLineColor  ( hist, jdx );
    setMarkerColor( hist, jdx );
    setMarkerStyle( hist, jdx ); 
    setMarkerSize ( hist, jdx );    
    break;

  case HistStyle::Filled:
    setLineWidth( hist, jdx );
    setLineColor( hist, jdx );
    setFillColor( hist, jdx );
    setFillStyle( hist, jdx );    
    break;
  }
}
void CompHist::setLegendStyle ( TLegend &  leg) [protected]

Definition at line 480 of file CompHist.cc.

{
  leg.SetFillStyle ( 0 );
  leg.SetFillColor ( 0 );
  leg.SetBorderSize( 0 ); 
}
void CompHist::setLineColor ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 671 of file CompHist.cc.

{
  hist.SetLineColor( 1 );
  if( jdx<((int)histColor_.size()) ){
    hist.SetLineColor(histColor_[jdx]);
  }
}
void CompHist::setLineStyle ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 662 of file CompHist.cc.

{
  hist.SetLineStyle( 1 );
  if( jdx<((int)commonStyle_.size()) ){
    hist.SetLineStyle(commonStyle_[jdx]);
  }
}
void CompHist::setLineWidth ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 653 of file CompHist.cc.

{
  hist.SetLineWidth( 5 );
  if( jdx<((int)commonWidth_.size()) ){
    hist.SetLineWidth(commonWidth_[jdx]);
  }
}
void CompHist::setMarkerColor ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 707 of file CompHist.cc.

{
  hist.SetMarkerColor( 1 );
  if( jdx<((int)histColor_.size()) ){
    hist.SetMarkerColor(histColor_[jdx]);
  }
}
void CompHist::setMarkerSize ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 716 of file CompHist.cc.

{
  hist.SetMarkerSize( 2.3 );
  if( jdx<((int)markerSize_.size()) ){
    hist.SetMarkerSize(markerSize_[jdx]);
  }
}
void CompHist::setMarkerStyle ( TH1F &  hist,
int  jdx 
) [protected]

Definition at line 698 of file CompHist.cc.

{
  hist.SetMarkerStyle( 23 );
  if( jdx<((int)markerStyle_.size()) ){
    hist.SetMarkerStyle(markerStyle_[jdx]);
  }
}
void CompHist::setVerbose ( bool  val) [inline]

Definition at line 51 of file CompHist.h.

References verbose_.

{verbose_=val; return;}
bool CompHist::verbose ( ) [inline]

Definition at line 52 of file CompHist.h.

References verbose_.

{return verbose_;}
std::string CompHist::writeAs ( ) [inline]

Definition at line 50 of file CompHist.h.

References writeAs_.

Referenced by main().

{return writeAs_;}
void CompHist::writeOutput ( ) [inline]

Reimplemented in TopInspectRatio, and TopInspectSum.

Definition at line 61 of file CompHist.h.

References kAll, and writeOutput().

Referenced by writeOutput(), TopInspectRatio::writeOutput(), and TopInspectSum::writeOutput().

void CompHist::writeOutput ( CompHist::RootOutput  option)

Definition at line 725 of file CompHist.cc.

References ExpressReco_HICollisions_FallBack::cerr, dbtoweb::file, estimatePileup::hist, estimatePileup::histFile, AlCaRecoCosmics_cfg::name, and dbtoconf::out.

{
  //---------------------------------------------
  // write filled target histogram to output file
  // if specified
  //---------------------------------------------
  if( isOutputRequested() ){
    //-----------------------------------------------
    // open hist file for book keeping of hist names
    //-----------------------------------------------
    TString name( output_ );
    name.Remove(name.Last('.'), name.Length()); 
    name+=".hist"; //replace .root by .hist
    ofstream histFile(name, std::ios::out);

    //-----------------------------------------------
    // open root output file and create directory
    // if necessary
    //-----------------------------------------------
    TFile file( output_.c_str(), "update" );
    if( !file.GetDirectory(rootOutDir_.c_str()) ) 
      // create new directory if it does not yet exist
      file.mkdir( rootOutDir_.c_str(), rootOutDir_.c_str() );
    else 
      // clean-up directory if it was existing already 
      (file.GetDirectory(rootOutDir_.c_str()))->Delete("*;*");
    file.cd(rootOutDir_.c_str());
    
    //-----------------------------------------------
    // loop and write out histograms
    //-----------------------------------------------
    if( option==kAll ){
      std::vector<TObjArray>::const_iterator hist = sampleList_.begin();
      for( ;hist!=sampleList_.end(); ++hist){
        for(unsigned int idx=0; idx<histList_.size(); ++idx){  
          histFile << ((TH1F*)(*hist)[idx])->GetName() << "\n";
          ((TH1F*)(*hist)[idx])->Write();
        }
      }
    }
    else{
      for(unsigned int idx=0; idx<histList_.size(); ++idx){ 
        // write first/last histograms in the sample list only
        histFile << (TH1F*)((sampleList_.back())[idx])->GetName() << "\n";
        switch( option ){
        case kFirstOnly:
          ((TH1F*)((*sampleList_.begin())[idx]))->Write();
          break;
        case kLastOnly:
          ((TH1F*)((sampleList_.back())[idx]))->Write();
          break;
        default:
          std::cerr << "WARNING:" 
               << " Wrong option indicated for writeOutput" << " [" << option 
               << "]" << " while only " << kFirstOnly << " up to " << kAll 
               << " are available" << std::endl;
          break;          
        }
      }
    }
    file.Close();
  }
}

Member Data Documentation

std::vector<short int> CompHist::commonStyle_ [protected]

Definition at line 119 of file CompHist.h.

std::vector<short int> CompHist::commonWidth_ [protected]

Definition at line 120 of file CompHist.h.

std::vector<std::string> CompHist::dirNameList_ [protected]

Definition at line 105 of file CompHist.h.

std::vector<short int> CompHist::errors_ [protected]

Definition at line 126 of file CompHist.h.

std::vector<TFile*> CompHist::fileList_ [protected]

Definition at line 137 of file CompHist.h.

std::vector<std::string> CompHist::fileNameList_ [protected]

Definition at line 106 of file CompHist.h.

std::string CompHist::filterOpt_ [protected]

Definition at line 103 of file CompHist.h.

std::vector<short int> CompHist::gridX_ [protected]

Definition at line 115 of file CompHist.h.

std::vector<short int> CompHist::gridY_ [protected]

Definition at line 115 of file CompHist.h.

std::vector<short int> CompHist::histColor_ [protected]

Definition at line 118 of file CompHist.h.

std::string CompHist::histFile_ [protected]

Definition at line 104 of file CompHist.h.

std::vector<std::string> CompHist::histFilterList_ [protected]

Definition at line 108 of file CompHist.h.

std::vector<std::string> CompHist::histList_ [protected]

Definition at line 139 of file CompHist.h.

std::vector<short int> CompHist::histStyle_ [protected]

Definition at line 117 of file CompHist.h.

std::vector<std::string> CompHist::legendEntries_ [protected]

Definition at line 131 of file CompHist.h.

double CompHist::legXLeft_ [protected]

Definition at line 129 of file CompHist.h.

double CompHist::legXRight_ [protected]

Definition at line 129 of file CompHist.h.

double CompHist::legYLower_ [protected]

Definition at line 130 of file CompHist.h.

double CompHist::legYUpper_ [protected]

Definition at line 130 of file CompHist.h.

std::vector<short int> CompHist::logX_ [protected]

Definition at line 116 of file CompHist.h.

std::vector<short int> CompHist::logY_ [protected]

Definition at line 116 of file CompHist.h.

std::vector<double> CompHist::markerSize_ [protected]

Definition at line 122 of file CompHist.h.

std::vector<short int> CompHist::markerStyle_ [protected]

Definition at line 121 of file CompHist.h.

std::vector<double> CompHist::max_ [protected]

Definition at line 124 of file CompHist.h.

std::vector<double> CompHist::min_ [protected]

Definition at line 124 of file CompHist.h.

std::string CompHist::output_ [protected]

Definition at line 109 of file CompHist.h.

std::vector<std::string> CompHist::outputLabelList_ [protected]

Definition at line 112 of file CompHist.h.

std::vector<std::string> CompHist::plotFilterList_ [protected]

Definition at line 107 of file CompHist.h.

std::string CompHist::rootOutDir_ [protected]

Definition at line 110 of file CompHist.h.

Referenced by isOutputRequested().

std::vector<TObjArray> CompHist::sampleList_ [protected]

Definition at line 138 of file CompHist.h.

std::vector<double> CompHist::scale_ [protected]

Definition at line 125 of file CompHist.h.

bool CompHist::verbose_ [protected]

Definition at line 136 of file CompHist.h.

Referenced by setVerbose(), and verbose().

std::string CompHist::writeAs_ [protected]

Definition at line 111 of file CompHist.h.

Referenced by writeAs().

std::string CompHist::writeTo_ [protected]

Definition at line 111 of file CompHist.h.

std::vector<std::string> CompHist::xAxes_ [protected]

Definition at line 123 of file CompHist.h.

std::vector<std::string> CompHist::yAxes_ [protected]

Definition at line 123 of file CompHist.h.