CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Validation/RecoJets/bin/CalibClosureTest.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <string>
00003 #include <fstream>
00004 #include <iostream>
00005 
00006 #include "Validation/RecoJets/interface/RootSystem.h"
00007 #include "Validation/RecoJets/interface/RootHistograms.h"
00008 #include "Validation/RecoJets/interface/RootPostScript.h"
00009 #include "Validation/RecoJets/interface/ManipHist.h"
00010 #include "Validation/RecoJets/bin/NiceStyle.cc"
00011 
00012 using namespace std;
00013 
00014 class CalibClosureTest : public ManipHist {
00015  public:
00016   CalibClosureTest(){};
00017   ~CalibClosureTest(){};
00018   virtual void readConfig( std::string );
00019   void configBlockSpecific(ConfigFile&);
00020 
00021   //extra members
00022   void drawEff();
00023   void drawCorrel();
00024   TString output(const char*, std::string&, const char*);
00025   TString output(const char*, std::string&, std::string&, const char*);
00026 
00027  private:
00028 
00029   // extra memebers
00030   std::vector<std::string> corrHistNameList_;
00031   std::vector<std::string> corrAxesLabelList_;
00032   std::vector<std::string> cmpObjLabelList_;
00033   std::vector<std::string> effHistNameList_;
00034   std::vector<std::string> effAxesLabelList_;
00035 };
00036 
00037 
00038 void CalibClosureTest::readConfig( std::string name )
00039 {
00040   ConfigFile cfg( name, "=", "$" ); 
00041   configBlockIO  ( cfg );
00042   configBlockHist( cfg );
00043   configBlockFit ( cfg );
00044   configBlockSpecific( cfg );
00045 }
00046 
00047 void 
00048 CalibClosureTest::configBlockSpecific(ConfigFile& cfg)
00049 {
00050   //-----------------------------------------------
00051   // read all configurables defined in CompHisto-
00052   // grams from config file. Throw human readable 
00053   // exception when misspellings occure
00054   //-----------------------------------------------
00055   try{
00056     //-----------------------------------------------
00057     // input/output files
00058     //-----------------------------------------------
00059     readVector ( cfg.read<std::string>( "corrHistNames" ), corrHistNameList_ );
00060     readLabels ( cfg.read<std::string>( "corrAxesLabels"), corrAxesLabelList_);
00061     readVector ( cfg.read<std::string>( "effHistNames"  ), effHistNameList_  );
00062     readLabels ( cfg.read<std::string>( "effAxesLabels" ), effAxesLabelList_ );
00063     readVector ( cfg.read<std::string>( "cmpObjectLabels"), cmpObjLabelList_ );
00064   }
00065   catch(...){
00066     std::cerr << "ERROR during reading of config file" << std::endl;
00067     std::cerr << "      misspelled variables in cfg ?" << std::endl;
00068     std::cerr << "      [--called in configBlockSpecific--]" << std::endl;
00069     std::exit(1);
00070   }
00071 }
00072 
00073 TString 
00074 CalibClosureTest::output(const char* pre, std::string& name, std::string& label, const char* post)
00075 {
00076   TString buffer( output(pre, name, post) );
00077   buffer.Remove(buffer.Last('.'), buffer.Length());
00078   buffer+="_";
00079   buffer+=label;
00080   buffer+=".";
00081   buffer+=post;
00082   return buffer;
00083 }
00084 
00085 TString 
00086 CalibClosureTest::output(const char* pre, std::string& name, const char* post)
00087 {
00088   // prepare name of the output file
00089   TString buffer( name );
00090   if( ((TString)buffer(buffer.Last('_')+1, buffer.Length())).IsDigit() )
00091     buffer.Remove(buffer.Last('_'), buffer.Length()); // chop off everything before the 
00092   buffer.Remove(0, buffer.Last ('_')+1);              // second to last and last '_'
00093   TString output( writeTo_.c_str() );
00094   output+=pre;
00095   output+=buffer;
00096   output+= ".";
00097   output+=post;  
00098   return output;
00099 }
00100 
00101 void CalibClosureTest::drawEff()
00102 {
00103   std::vector<TObjArray> effSampleList;
00104   loadHistograms(effHistNameList_, effSampleList);
00105 
00106   TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
00107   setCanvasStyle( *canv  );
00108   canv->SetGridx( 1 );
00109   canv->SetGridy( 1 );
00110 
00111   //---------------------------------------------
00112   // loop histograms via the list of histogram 
00113   // names stored in effHistNameList_, open a 
00114   // new page for each histogram; histograms are
00115   // expected in order ref(0)/sample(1),... 
00116   //---------------------------------------------
00117   for(unsigned int jdx=0; jdx<effHistNameList_.size()/2; ++jdx){
00118     TPostScript psFile(output("/inspectMatch_", effHistNameList_[2*jdx], "eps"), 113);
00119     psFile.NewPage();
00120 
00121     TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
00122     setLegendStyle( *leg ); 
00123     //-----------------------------------------------
00124     // loop each sample, draw all sample for a given 
00125     // histogram name in one plot 
00126     //-----------------------------------------------
00127     std::vector<TObjArray>::const_iterator hist = effSampleList.begin();
00128     for(unsigned int idx=0; hist!=effSampleList.end(); ++hist, ++idx){  
00129       TH1F& href = *((TH1F*)(*hist)[2*jdx]); //recieve histograms
00130       TH1F& hcmp = *((TH1F*)(*hist)[2*jdx+1]);
00131       setHistStyles( hcmp, jdx, idx );
00132 
00133       if(idx==0){
00134         // prepare axes labels
00135         char xstring[100], ystring[100];
00136         if( idx<effAxesLabelList_.size() )
00137           sprintf(xstring, effAxesLabelList_[jdx].c_str(),  cmpObjLabelList_[1].c_str());
00138         sprintf(ystring, "match^{%s}/match^{%s}", cmpObjLabelList_[0].c_str(), cmpObjLabelList_[1].c_str());
00139         hcmp.GetXaxis()->SetTitle( xstring );
00140         hcmp.GetYaxis()->SetTitle( ystring );
00141         hcmp.SetMinimum(0.85*hcmp.GetMinimum());
00142         hcmp.SetMaximum(1.25*hcmp.GetMaximum());
00143         divideHistograms(hcmp, href, 1);
00144         hcmp.Draw();
00145       }
00146       else{
00147         divideHistograms(hcmp, href, 1);
00148         hcmp.Draw("same");
00149       }
00150       leg->AddEntry( &hcmp, legend( idx ).c_str(), "PL" );
00151     }
00152     leg->Draw( "same" );
00153     canv->RedrawAxis( );
00154     canv->Update( );
00155     psFile.Close();
00156     delete leg;
00157   }
00158   canv->Close();
00159   delete canv;
00160 }
00161 
00162 void CalibClosureTest::drawCorrel()
00163 {
00164   std::vector<TObjArray> corrSampleList;
00165   loadHistograms(corrHistNameList_, corrSampleList);
00166 
00167   TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
00168   setCanvasStyle( *canv  );
00169   canv->SetGridx( 1 );
00170   canv->SetGridy( 1 );
00171 
00172   //---------------------------------------------
00173   // loop histograms via the list of histogram 
00174   // names stored in corrHistNameList_, open a 
00175   // new file for each histogram and each sample
00176   //---------------------------------------------
00177   for(unsigned int jdx=0; jdx<corrHistNameList_.size(); ++jdx){  
00178     //---------------------------------------------
00179     // loop all available samples, open a new file
00180     // for each sample
00181     //---------------------------------------------
00182     std::vector<TObjArray>::const_iterator hist = corrSampleList.begin();
00183     for(unsigned int idx=0; hist!=corrSampleList.end(); ++hist, ++idx){  
00184       TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
00185       setLegendStyle( *leg ); 
00186       
00187       TPostScript psFile(output("/inspectCorrel_", corrHistNameList_[jdx], outputLabelList_[idx], "eps"), 113);
00188       psFile.NewPage();
00189       
00190       TH2F& hcmp = *((TH2F*)(*hist)[jdx]);
00191       hcmp.SetLineColor  ( histColor_[idx] );
00192       hcmp.SetFillColor  ( histColor_[idx] );
00193       hcmp.SetMarkerColor( histColor_[idx] );
00194       char xstring[100], ystring[100];
00195       if( jdx<corrAxesLabelList_.size() ){
00196         sprintf(xstring, corrAxesLabelList_[jdx].c_str(), cmpObjLabelList_[0].c_str() );
00197         sprintf(ystring, corrAxesLabelList_[jdx].c_str(), cmpObjLabelList_[1].c_str() );
00198       }
00199       setAxesStyle( hcmp, xstring, ystring );
00200       leg->AddEntry( &hcmp, legend( idx ).c_str(), "FL" );
00201       hcmp.Draw("box");
00202       leg->Draw( "same" );
00203       canv->RedrawAxis( );
00204       canv->Update( );
00205       psFile.Close();
00206       delete leg;
00207     }
00208   }
00209   canv->Close();
00210   delete canv;
00211 }
00212 
00213 int main(int argc, char* argv[])
00214 {
00215   setNiceStyle();
00216   gStyle->SetOptStat( 0 );
00217   gStyle->SetOptFit ( 0 );
00218 
00219   gStyle->SetStatColor(0);
00220   gStyle->SetStatBorderSize(0);
00221   gStyle->SetStatX(0.93);
00222   gStyle->SetStatY(0.93);
00223   gStyle->SetStatW(0.18);
00224   gStyle->SetStatH(0.18);
00225 
00226   if( argc<2 ){
00227     std::cerr << "ERROR:" 
00228          << " Missing argument" << std::endl;
00229     return 1;
00230   }
00231 
00232   CalibClosureTest plots;
00233   //plots.setVerbose(true);
00234   plots.readConfig( argv[1] );
00235   plots.loadHistograms();
00236   if( !strcmp(plots.writeAs().c_str(), "ps") ){
00237     plots.fitAndDrawPs();
00238     plots.fillTargetHistograms();
00239     plots.drawPs();
00240   } else if( !strcmp(plots.writeAs().c_str(), "eps") ){
00241     plots.fitAndDrawEps();
00242     plots.fillTargetHistograms();
00243     plots.drawEps();
00244   } else{
00245     std::cerr << "ERROR:"
00246          << " Unknown file format requested: "
00247          << plots.writeAs() << std::endl; 
00248     return -1;
00249   } 
00250   plots.drawEff();
00251   plots.drawCorrel();
00252 
00253   std::cout << "works " << "thanx and GoodBye " << std::endl; 
00254   return 0;
00255 }