CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Validation/RecoJets/src/CompHist.cc

Go to the documentation of this file.
00001 #include "Validation/RecoJets/interface/CompHist.h"
00002 #include "Validation/RecoJets/interface/ConfigFile.h"
00003 #include "Validation/RecoJets/interface/RootPostScript.h"
00004 
00005 
00006 using namespace std;
00007 
00008 void 
00009 CompHist::readLabels(std::string s, std::vector<std::string>& vec)
00010 {
00011   //-----------------------------------------------
00012   // fill vector of std::string's from a single
00013   // std::string s; the process starts as soon as 
00014   // leading " are found and starts a new substr
00015   // as soon as a "; is encountered
00016   //-----------------------------------------------
00017   std::stringstream stream( s );
00018   std::string buffer, label;
00019   while (!stream.eof()) {
00020     stream >> buffer;
00021     if(buffer.find("\"", 0)==0){
00022       //start new label if leading " are found
00023       label=buffer;
00024     }
00025     else{
00026       //concatenate buffer to label else
00027       label+=" ";
00028       label+=buffer;
00029     }
00030 
00031     //push_back label if it starts with " and ends with ";
00032     if(buffer.find("\"", buffer.size()-2)==buffer.size()-2 &&
00033        buffer.find(";",  buffer.size()-2)==buffer.size()-1){
00034       vec.push_back( label.substr(1, label.size()-3) );
00035     }
00036   }
00037 }
00038 
00039 void 
00040 CompHist::configBlockIO(ConfigFile& cfg)
00041 {
00042   //-----------------------------------------------
00043   // read all configurables defined in CompHisto-
00044   // grams from config file. Throw human readable 
00045   // exception when misspellings occure
00046   //-----------------------------------------------
00047   try{
00048     //-----------------------------------------------
00049     // input/output files
00050     //-----------------------------------------------
00051     histFile_  = cfg.read<std::string>( "histInput" );
00052     readVector ( cfg.read<std::string>( "rootInput" ), fileNameList_ );
00053     readVector ( cfg.read<std::string>( "inputDirs" ), dirNameList_  );
00054     filterOpt_ = cfg.read<std::string>( "filterOption" );
00055     readVector ( cfg.read<std::string>( "histFilter" ), histFilterList_ );
00056     readVector ( cfg.read<std::string>( "plotFilter" ), plotFilterList_ );
00057     writeTo_   = cfg.read<std::string>( "writePlotsTo" );
00058     writeAs_   = cfg.read<std::string>( "writePlotsAs" );
00059     rootOutDir_= cfg.read<std::string>( "outputDir" );
00060     output_    = cfg.read<std::string>( "rootOutput" );
00061     readVector ( cfg.read<std::string>( "outputLabels" ), outputLabelList_ );
00062   }
00063   catch(...){
00064     std::cerr << "ERROR during reading of config file" << std::endl;
00065     std::cerr << "      misspelled variables in cfg ?" << std::endl;
00066     std::cerr << "      [--called in configBlockIO--]" << std::endl;
00067     std::exit(1);
00068   }
00069 }
00070 
00071 void
00072 CompHist::configBlockHist(ConfigFile& cfg)
00073 {
00074   //-----------------------------------------------
00075   // read all configurables defined in CompHisto-
00076   // grams from config file. Throw human readable 
00077   // exception when misspellings occure
00078   //-----------------------------------------------
00079   try{
00080     //-----------------------------------------------
00081     // canvas steering
00082     //-----------------------------------------------
00083     readVector( cfg.read<std::string>( "xLog" ), logX_ );
00084     readVector( cfg.read<std::string>( "yLog" ), logY_ );
00085     readVector( cfg.read<std::string>( "xGrid" ), gridX_);
00086     readVector( cfg.read<std::string>( "yGrid" ), gridY_);
00087 
00088     //-----------------------------------------------
00089     // histogram steering
00090     //-----------------------------------------------
00091     readVector( cfg.read<std::string>( "histErrors" ), errors_);
00092     readVector( cfg.read<std::string>( "histScale" ), scale_ );
00093     readVector( cfg.read<std::string>( "histMinimum"), min_ );
00094     readVector( cfg.read<std::string>( "histMaximum"), max_ );
00095     readVector( cfg.read<std::string>( "histType" ), histStyle_ );
00096     readVector( cfg.read<std::string>( "histStyle" ), commonStyle_ );
00097     readVector( cfg.read<std::string>( "histColor" ), histColor_ );
00098     readVector( cfg.read<std::string>( "lineWidth" ), commonWidth_ );
00099     readVector( cfg.read<std::string>( "markerStyle" ), markerStyle_ );
00100     readVector( cfg.read<std::string>( "markerSize" ), markerSize_ );
00101     readLabels( cfg.read<std::string>( "xAxes" ), xAxes_ );
00102     readLabels( cfg.read<std::string>( "yAxes" ), yAxes_ );
00103 
00104     //-----------------------------------------------
00105     // legend steering
00106     //-----------------------------------------------
00107     readLabels( cfg.read<std::string>( "legEntries"), legendEntries_);
00108     legXLeft_ = cfg.read<double>( "legXLeft" );
00109     legXRight_= cfg.read<double>( "legXRight" );
00110     legYLower_= cfg.read<double>( "legYLower" );
00111     legYUpper_= cfg.read<double>( "legYUpper" );
00112   }
00113   catch(...){
00114     std::cerr << "ERROR during reading of config file"   << std::endl;
00115     std::cerr << "      misspelled variables in cfg ?"   << std::endl;
00116     std::cerr << "      [--called in configBlockHist--]" << std::endl;
00117     std::exit(1);
00118   }
00119 }
00120 
00121 void 
00122 CompHist::readHistogramList()
00123 {
00124   //-----------------------------------------------
00125   // fill the list histList_ with all requested
00126   // histogram names; the names are recieved from 
00127   // a .hist file; jump out if the reading takes 
00128   // too long 
00129   //-----------------------------------------------
00130   ifstream histFile( histFile_.c_str() );
00131 
00132   int count=0;
00133   while( !histFile.eof() ){
00134     std::string buffer;
00135     histFile >> buffer;
00136     if( buffer.size()>0 ){
00137       TString cmp(buffer);
00138       if( histFilter(cmp, histFilterList_) )
00139         histList_.push_back(buffer);
00140       else{
00141         if(verbose_){
00142           std::cout << " histogram is filtered out according"
00143                << " to settings in cfg file; filterOpt:  "
00144                << filterOpt_ << std::endl;
00145         }
00146       }
00147     }
00148     if( count>999 ){
00149       std::cerr << "ERROR caught in slope for histogram" << std::endl;
00150       std::cerr << "      names. Misspelled file name ?" << std::endl;
00151       std::cerr << histFile_.c_str() << std::endl;
00152       break;
00153     }
00154     ++count;
00155   }
00156 }
00157 
00158 void
00159 CompHist::loadHistograms(std::vector<std::string>& histList, std::vector<TObjArray>& sampleList)
00160 {
00161   //fill vector of root files if not already done
00162   if( fileList_.empty() ){
00163     std::vector<std::string>::const_iterator name;
00164     for(name = fileNameList_.begin(); name!=fileNameList_.end(); ++name){
00165       fileList_.push_back( new TFile( name->c_str() ) );
00166     }
00167   }
00168   //fill vector of histogram arrays
00169   std::vector<TFile*>::const_iterator file = fileList_.begin();
00170   for(int jdx=0 ; file!=fileList_.end(); ++file, ++jdx){
00171     std::vector<std::string>::const_iterator rootDir;
00172     for(rootDir = dirNameList_.begin(); rootDir!=dirNameList_.end(); ++rootDir){
00173       TH1F *dummy;
00174       TObjArray hist;
00175       for( int idx=0; idx<(int)histList.size(); ++idx ){
00176         TString directory( *rootDir );
00177         directory+="/";
00178         directory+=histList[idx];
00179         
00180         if(verbose_){
00181           std::cout << "load from: " << (*file)->GetName() << " " 
00182                << "directory: " << directory << std::endl;
00183         }
00184         dummy = (TH1F*)(*file)->Get( directory );
00185         if( !dummy ){
00186           std::cerr << "WARNING:" 
00187                << " Didn't find indicated hist"
00188                << " [" << directory << "]" 
00189                << " in file" 
00190                << " [" << (*file)->GetName() << "]" 
00191                << std::endl;
00192           return;
00193         }
00194 
00195         // prepare unambiguous histogram name
00196         TString outname( fileNameList_[jdx] );
00197         outname.Remove(outname.Last('.'), outname.Length());
00198         outname += ":";
00199         outname += *rootDir;
00200         outname +="/";
00201         outname +=dummy->GetName();
00202         dummy->SetName( outname );
00203 
00204         // add histogram to list
00205         hist.Add( dummy );
00206         if(verbose_){
00207           std::cout << "added to list as: " << dummy->GetName() << std::endl;
00208         }
00209       } // end of histogram name list 
00210       sampleList.push_back( hist );
00211     } // end of root directory list
00212   } // end of root file list
00213 }
00214 
00215 void 
00216 CompHist::loadHistograms()
00217 {
00218   //-----------------------------------------------
00219   // fill histograms listed in histList_ into a
00220   // TObjectArray for each sample given in the 
00221   // list fileNameList_ and its directories; Each 
00222   // TObjectArray is then pushed into the vector 
00223   // sampleList_ which keeps all TObjectArrays of 
00224   // histograms for each sample 
00225   //-----------------------------------------------
00226 
00227   //fill histogram list
00228   if( !histFile_.empty() )
00229     readHistogramList();
00230   else{
00231     if( histFilterList_.size()>0 ){
00232       if( !filterOpt_.compare("contains") )
00233         cout << "WARNING: missing hist file in cfg file; will use list of histogram" << std::endl
00234              << "         names given in histFilter instead, requires filterOption " << std::endl
00235              << "         'optains'; will move filterOption to 'optain' to go on..." << std::endl;
00236       filterOpt_="contains";
00237       histList_ =histFilterList_;
00238     }
00239   }
00240   loadHistograms(histList_, sampleList_);
00241 }
00242 
00243 bool
00244 CompHist::histFilter(TString& cmp, std::vector<std::string>& ref)
00245 {
00246   bool contained=true;
00247   if(!filterOpt_.empty()){
00248     contained=false;
00249     if(!filterOpt_.compare("begins")){
00250       contained = histFilter(cmp, ref, kBeginsWith);
00251     }
00252     else if(!filterOpt_.compare("ends")){
00253       contained = histFilter(cmp, ref, kEndsWith);
00254     }
00255     else if(!filterOpt_.compare("contains")){
00256       contained = histFilter(cmp, ref, kContains);
00257     }
00258     else{
00259       std::cerr << "ERROR during histogram filtering   " << std::endl;
00260       std::cerr << "      filter option is not properly" << std::endl;
00261       std::cerr << "      specified : " << filterOpt_ << std::endl;
00262     }
00263   }
00264   return contained;
00265 }
00266 
00267 bool 
00268 CompHist::histFilter(TString& cmp, std::vector<std::string>& ref, CompHist::HistFilter option)
00269 {
00270   bool contained=true;
00271   if(ref.size()>0){
00272     contained=false;
00273     for(unsigned int idx=0; idx<ref.size(); ++idx){
00274       TString buffer(ref[idx]);
00275       if( !option==kContains ) buffer+="_";
00276       if( option==kBeginsWith && cmp.BeginsWith(buffer) ){ 
00277         contained=true;
00278         break;
00279       }
00280       if( option==kEndsWith && cmp.EndsWith(buffer) ){
00281         contained=true;
00282         break;
00283       }
00284       if( option==kContains && cmp.Contains(buffer) ){
00285         contained=true;
00286         break;
00287       }
00288     }
00289   }
00290   return contained;
00291 }
00292 
00293 void
00294 CompHist::draw(TCanvas& canv, TLegend& leg, int& idx, int& jdx)
00295 {  
00296   //-----------------------------------------------
00297   // loop all samples via the list sampleList_, which 
00298   // containas the histograms of each sample as 
00299   // TObjects in TObjectArrays
00300   //-----------------------------------------------
00301   TH1F hfirst; //draw first histogram on top of others
00302                //after all histograms have been drawn
00303   std::vector<TObjArray>::const_iterator hist = sampleList_.begin();
00304   for(int kdx=0; hist!=sampleList_.end(); ++hist, ++kdx){
00305     TH1F& hcmp = *((TH1F*)(*hist)[idx]); //recieve histogram
00306     setCanvLog( canv, jdx );
00307     setCanvGrid( canv, jdx );
00308     setHistStyles( hcmp, jdx, kdx );
00309     // for the first histogram just draw
00310     // for the following ones draw same
00311     if(kdx==0){
00312       hfirst = hcmp; // buffer first histogram to redraw it after all
00313       if(errors_[kdx]) 
00314         hcmp.Draw("e");
00315       else 
00316         hcmp.Draw(   );
00317     }
00318     else{
00319       if(errors_[kdx]) 
00320         hcmp.Draw("samee");
00321       else 
00322         hcmp.Draw("same" );
00323     }
00324     // add legend entry in appropriate format
00325     switch( histStyle_[kdx]){
00326     case HistStyle::Line:
00327       leg.AddEntry( &hcmp, legend(kdx).c_str(), "L"  );
00328       break;
00329       
00330     case HistStyle::Marker:
00331       leg.AddEntry( &hcmp, legend(kdx).c_str(), "PL" );
00332       break;
00333       
00334     case HistStyle::Filled:
00335       leg.AddEntry( &hcmp, legend(kdx).c_str(), "FL" );
00336       break;
00337     }
00338   }
00339   if(errors_[0]){
00340     hfirst.Draw("esame");
00341   }
00342   else{
00343     hfirst.Draw( "same"); 
00344   }
00345   leg.Draw( "same" );
00346   canv.RedrawAxis( );
00347   canv.Update( );
00348 }
00349 
00350 void 
00351 CompHist::drawPs()
00352 {
00353   //-----------------------------------------------
00354   // define canvas
00355   //-----------------------------------------------
00356   TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
00357   setCanvasStyle( *canv  );
00358 
00359   //-----------------------------------------------
00360   // open output file
00361   //-----------------------------------------------
00362   TString output( writeTo_.c_str() );
00363   output += "/";
00364   output += "inspect";
00365   output += ".";
00366   output += writeAs_;
00367   TPostScript psFile( output, 111); //112 for portrait
00368 
00369   //-----------------------------------------------
00370   // loop histograms via the list of histogram
00371   // names stored in histList_, open a new page 
00372   // for each histogram & plot each sample in 
00373   // the same canvas
00374   //-----------------------------------------------
00375   for(int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
00376     // prepare compare string for plot filtering
00377     TString cmp( histList_[idx] );
00378     if( !histFilter(cmp, plotFilterList_) ){
00379       if(verbose_){
00380         cout << " event is filtered out according to"
00381              << " settings in cfg file; filterOpt:  "
00382              << filterOpt_ 
00383              << " hist: " << cmp << std::endl;
00384       }
00385       continue;
00386     }
00387     psFile.NewPage();
00388     //-----------------------------------------------
00389     // on each page the legend needs to be redeclared
00390     //-----------------------------------------------   
00391     TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
00392     setLegendStyle( *leg );  
00393     draw(*canv, *leg, idx, jdx);
00394     if(idx == (int)histList_.size()-1){
00395       psFile.Close();
00396     }
00397     ++jdx; delete leg;
00398   }
00399   canv->Close();
00400   delete canv;
00401 }
00402 
00403 void 
00404 CompHist::drawEps()
00405 {
00406   //-----------------------------------------------
00407   // define canvas
00408   //-----------------------------------------------
00409   TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
00410   setCanvasStyle( *canv  );
00411 
00412   //-----------------------------------------------
00413   // loop histograms via the list of histogram
00414   // names stored in histList_, open a new page 
00415   // for each histogram & plot each sample in 
00416   // the same canvas
00417   //-----------------------------------------------  
00418   for(int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
00419     //-----------------------------------------------
00420     // prepare compare string for plot filtering
00421     //-----------------------------------------------
00422     TString cmp( histList_[idx] );
00423     if( !histFilter(cmp, plotFilterList_) ){
00424       if(verbose_){
00425         cout << " event is filtered out according to"
00426              << " settings in cfg file; filterOpt:  "
00427              << filterOpt_ 
00428              << " hist: " << cmp << std::endl;
00429       }
00430       continue;
00431     }
00432     //-----------------------------------------------
00433     // open output files
00434     //-----------------------------------------------
00435     TString output( writeTo_.c_str() );
00436     output += "/";
00437     output += histList_[ idx ];
00438     output += ".";
00439     output += writeAs_;
00440 
00441     TPostScript psFile( output, 113);
00442     psFile.NewPage();
00443     //-----------------------------------------------
00444     // on each page the legend needs to be redeclared
00445     //-----------------------------------------------   
00446     TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
00447     setLegendStyle( *leg ); 
00448     draw(*canv, *leg, idx, jdx);
00449     psFile.Close();
00450     ++jdx; delete leg;
00451   }
00452   canv->Close();
00453   delete canv;
00454 }
00455 
00456 std::string 
00457 CompHist::legend(int idx)
00458 {
00459   char buffer[100];
00460   sprintf(buffer, "undefined sample %i", idx);
00461   if( legendEntries_.size()>=sampleList_.size() ){
00462     return legendEntries_[idx];
00463   }
00464   return buffer;
00465 }
00466 
00467 double
00468 CompHist::findMaximum(int idx)
00469 {
00470   double max=-1.;
00471   for(std::vector<TObjArray>::const_iterator hist = sampleList_.begin(); 
00472       hist!=sampleList_.end(); ++hist){
00473     TH1F& hcmp = *((TH1F*)(*hist)[idx]); //recieve histogram
00474     if( max<0 || hcmp.GetMaximum()>max ) max=hcmp.GetMaximum();
00475   }
00476   return max;
00477 }
00478 
00479 void 
00480 CompHist::setLegendStyle(TLegend& leg)
00481 {
00482   leg.SetFillStyle ( 0 );
00483   leg.SetFillColor ( 0 );
00484   leg.SetBorderSize( 0 ); 
00485 }
00486 
00487 void 
00488 CompHist::setCanvasStyle(TCanvas& canv)
00489 {
00490   canv.SetFillStyle   ( 4000 );
00491   canv.SetLeftMargin  ( 0.20 );
00492   canv.SetRightMargin ( 0.05 );
00493   canv.SetBottomMargin( 0.15 );
00494   canv.SetTopMargin   ( 0.05 );
00495 }
00496 
00497 void 
00498 CompHist::setCanvLog(TCanvas& canv, int idx)
00499 {
00500   if( idx<((int)logX_.size()-1) && idx<((int)logY_.size()-1) ){
00501     canv.SetLogx ( logX_[idx]  );
00502     canv.SetLogy ( logY_[idx]  );
00503   }
00504   else if( idx<((int)logY_.size()-1) ){
00505     canv.SetLogx ( 0 );
00506     canv.SetLogy ( logY_[idx]  );
00507   }
00508   else{
00509     canv.SetLogx ( 0 );
00510     canv.SetLogy ( 0 );
00511   }
00512 }
00513 
00514 void 
00515 CompHist::setCanvGrid(TCanvas& canv, int idx)
00516 {
00517   if( idx<((int)gridX_.size()-1) && idx<((int)gridY_.size()-1) ){
00518     canv.SetGridx ( gridX_[idx]  );
00519     canv.SetGridy ( gridY_[idx]  );
00520   }
00521   else if( idx<((int)gridY_.size()-1) ){
00522     canv.SetGridx ( 0 );
00523     canv.SetGridy ( gridY_[idx]  );
00524   }
00525   else{
00526     canv.SetGridx ( 0 );
00527     canv.SetGridy ( 0 );
00528   }
00529 }
00530 
00531 void 
00532 CompHist::setAxesStyle( TH1& hist, const char* titleX, const char* titleY )
00533 {
00534   hist.SetTitle( "" );
00535 
00536   hist.GetXaxis()->SetTitle( titleX );
00537   hist.GetXaxis()->SetTitleSize  ( 0.06 );
00538   hist.GetXaxis()->SetTitleColor (    1 );
00539   hist.GetXaxis()->SetTitleOffset(  1.0 );
00540   hist.GetXaxis()->SetTitleFont  (   62 );
00541   hist.GetXaxis()->SetLabelSize  ( 0.05 );
00542   hist.GetXaxis()->SetLabelFont  (   62 );
00543   hist.GetXaxis()->CenterTitle   (      );
00544   hist.GetXaxis()->SetNdivisions (  505 );
00545   
00546   hist.GetYaxis()->SetTitle( titleY );
00547   hist.GetYaxis()->SetTitleSize  ( 0.07 );
00548   hist.GetYaxis()->SetTitleColor (    1 );
00549   hist.GetYaxis()->SetTitleOffset(  1.3 );
00550   hist.GetYaxis()->SetTitleFont  (   62 );
00551   hist.GetYaxis()->SetLabelSize  ( 0.05 );
00552   hist.GetYaxis()->SetLabelFont  (   62 );
00553 }
00554 
00555 void 
00556 CompHist::setHistStyles( TH1F& hist, int idx, int jdx )
00557 {
00558   //-----------------------------------------------
00559   // check hist style; throw exception if style 
00560   // is not competible with specifications; set 
00561   // default line[0] if vector is too short
00562   //-----------------------------------------------
00563   int histType=0;
00564   if( jdx<((int)histStyle_.size()) ){
00565     if(HistStyle::Line<=histStyle_[jdx] && histStyle_[jdx]<=HistStyle::Filled){
00566       histType=histStyle_[jdx];
00567     }
00568     else{
00569       throw "Histogram Type cannot be specified ";
00570     }
00571   }
00572   
00573   //define histogram styles
00574   setHistLabels( hist, idx );
00575   setHistScale ( hist, idx );
00576   setHistMax   ( hist, idx );
00577   setHistMin   ( hist, idx );
00578 
00579   switch( histType ){
00580   case HistStyle::Line: 
00581     setLineWidth( hist, jdx );
00582     setLineColor( hist, jdx );
00583     setLineStyle( hist, jdx );
00584     break;
00585 
00586   case HistStyle::Marker:
00587     setLineWidth  ( hist, jdx );
00588     setLineColor  ( hist, jdx );
00589     setMarkerColor( hist, jdx );
00590     setMarkerStyle( hist, jdx ); 
00591     setMarkerSize ( hist, jdx );    
00592     break;
00593 
00594   case HistStyle::Filled:
00595     setLineWidth( hist, jdx );
00596     setLineColor( hist, jdx );
00597     setFillColor( hist, jdx );
00598     setFillStyle( hist, jdx );    
00599     break;
00600   }
00601 }
00602 
00603 void 
00604 CompHist::setHistLabels(TH1F& hist, int idx)
00605 {
00606   if( idx<((int)xAxes_.size()) && idx<((int)yAxes_.size()) ){
00607     setAxesStyle( hist, xAxes_[idx].c_str(), yAxes_[idx].c_str() );
00608   }
00609   else if( idx<((int)xAxes_.size()) ){
00610     setAxesStyle( hist, xAxes_[idx].c_str(), "events" );
00611   }
00612   else{
00613     if( strcmp(hist.GetTitle(),"") == 0 ){
00614       setAxesStyle( hist, hist.GetXaxis()->GetTitle(), "events" );  
00615     }
00616     else{
00617       setAxesStyle( hist, hist.GetTitle(), "events" );            
00618     }           
00619   }
00620 }
00621 
00622 void 
00623 CompHist::setHistScale(TH1F& hist, int idx)
00624 {
00625   if( idx<((int)scale_.size()) ){
00626     if( scale_[idx]>0 ) hist.Scale(scale_[idx]/hist.Integral());
00627   }
00628 }
00629 
00630 void 
00631 CompHist::setHistMax(TH1F& hist, int idx)
00632 {
00633   if( ((int)max_.size()>0) && (idx<(int)max_.size()) ){
00634     hist.SetMaximum(max_[idx]);
00635   }
00636   else{
00637     hist.SetMaximum(1.5*findMaximum(idx));
00638   }
00639 }
00640 
00641 void 
00642 CompHist::setHistMin(TH1F& hist, int idx)
00643 {
00644   if( ((int)min_.size()>0) && (idx<(int)min_.size()) ){
00645     hist.SetMinimum(min_[idx]);
00646   }
00647   else{
00648     hist.SetMinimum(0.);    
00649   }
00650 }
00651 
00652 void 
00653 CompHist::setLineWidth(TH1F& hist, int jdx)
00654 {
00655   hist.SetLineWidth( 5 );
00656   if( jdx<((int)commonWidth_.size()) ){
00657     hist.SetLineWidth(commonWidth_[jdx]);
00658   }
00659 }
00660 
00661 void 
00662 CompHist::setLineStyle(TH1F& hist, int jdx)
00663 {
00664   hist.SetLineStyle( 1 );
00665   if( jdx<((int)commonStyle_.size()) ){
00666     hist.SetLineStyle(commonStyle_[jdx]);
00667   }
00668 }
00669 
00670 void 
00671 CompHist::setLineColor(TH1F& hist, int jdx)
00672 {
00673   hist.SetLineColor( 1 );
00674   if( jdx<((int)histColor_.size()) ){
00675     hist.SetLineColor(histColor_[jdx]);
00676   }
00677 }
00678 
00679 void 
00680 CompHist::setFillStyle(TH1F& hist, int jdx)
00681 {
00682   hist.SetFillStyle( 3005 );
00683   if( jdx<((int)commonStyle_.size()) ){
00684     hist.SetFillStyle(commonStyle_[jdx]);
00685   }
00686 }
00687 
00688 void 
00689 CompHist::setFillColor(TH1F& hist, int jdx)
00690 {
00691   hist.SetFillColor( 1 );
00692   if( jdx<((int)histColor_.size()) ){
00693     hist.SetFillColor(histColor_[jdx]);
00694   }
00695 }
00696 
00697 void 
00698 CompHist::setMarkerStyle(TH1F& hist, int jdx)
00699 {
00700   hist.SetMarkerStyle( 23 );
00701   if( jdx<((int)markerStyle_.size()) ){
00702     hist.SetMarkerStyle(markerStyle_[jdx]);
00703   }
00704 }
00705 
00706 void 
00707 CompHist::setMarkerColor(TH1F& hist, int jdx)
00708 {
00709   hist.SetMarkerColor( 1 );
00710   if( jdx<((int)histColor_.size()) ){
00711     hist.SetMarkerColor(histColor_[jdx]);
00712   }
00713 }
00714 
00715 void 
00716 CompHist::setMarkerSize(TH1F& hist, int jdx)
00717 {
00718   hist.SetMarkerSize( 2.3 );
00719   if( jdx<((int)markerSize_.size()) ){
00720     hist.SetMarkerSize(markerSize_[jdx]);
00721   }
00722 }
00723 
00724 void 
00725 CompHist::writeOutput(CompHist::RootOutput option)
00726 {
00727   //---------------------------------------------
00728   // write filled target histogram to output file
00729   // if specified
00730   //---------------------------------------------
00731   if( isOutputRequested() ){
00732     //-----------------------------------------------
00733     // open hist file for book keeping of hist names
00734     //-----------------------------------------------
00735     TString name( output_ );
00736     name.Remove(name.Last('.'), name.Length()); 
00737     name+=".hist"; //replace .root by .hist
00738     ofstream histFile(name, std::ios::out);
00739 
00740     //-----------------------------------------------
00741     // open root output file and create directory
00742     // if necessary
00743     //-----------------------------------------------
00744     TFile file( output_.c_str(), "update" );
00745     if( !file.GetDirectory(rootOutDir_.c_str()) ) 
00746       // create new directory if it does not yet exist
00747       file.mkdir( rootOutDir_.c_str(), rootOutDir_.c_str() );
00748     else 
00749       // clean-up directory if it was existing already 
00750       (file.GetDirectory(rootOutDir_.c_str()))->Delete("*;*");
00751     file.cd(rootOutDir_.c_str());
00752     
00753     //-----------------------------------------------
00754     // loop and write out histograms
00755     //-----------------------------------------------
00756     if( option==kAll ){
00757       std::vector<TObjArray>::const_iterator hist = sampleList_.begin();
00758       for( ;hist!=sampleList_.end(); ++hist){
00759         for(unsigned int idx=0; idx<histList_.size(); ++idx){  
00760           histFile << ((TH1F*)(*hist)[idx])->GetName() << "\n";
00761           ((TH1F*)(*hist)[idx])->Write();
00762         }
00763       }
00764     }
00765     else{
00766       for(unsigned int idx=0; idx<histList_.size(); ++idx){ 
00767         // write first/last histograms in the sample list only
00768         histFile << (TH1F*)((sampleList_.back())[idx])->GetName() << "\n";
00769         switch( option ){
00770         case kFirstOnly:
00771           ((TH1F*)((*sampleList_.begin())[idx]))->Write();
00772           break;
00773         case kLastOnly:
00774           ((TH1F*)((sampleList_.back())[idx]))->Write();
00775           break;
00776         default:
00777           std::cerr << "WARNING:" 
00778                << " Wrong option indicated for writeOutput" << " [" << option 
00779                << "]" << " while only " << kFirstOnly << " up to " << kAll 
00780                << " are available" << std::endl;
00781           break;          
00782         }
00783       }
00784     }
00785     file.Close();
00786   }
00787 }