00001
00013 #include "Validation/RecoB/interface/BTagValidator.h"
00014
00015
00016 #include "TClass.h"
00017 #include "TDirectory.h"
00018 #include "TH1.h"
00019 #include "TH2.h"
00020 #include "TH3.h"
00021 #include "TString.h"
00022
00023 #include "FWCore/Utilities/interface/Exception.h"
00024 #include "FWCore/Version/interface/GetReleaseVersion.h"
00025
00026 #include "Validation/RecoB/interface/HistoCompare.h"
00027 #include "DQMServices/Core/interface/DQMStore.h"
00028 #include "DQMServices/Core/interface/MonitorElement.h"
00029
00030
00031
00032
00033 BTagValidator::BTagValidator(const edm::ParameterSet& iConfig) {
00034
00035
00036 algorithm_ = iConfig.getParameter<std::string>( "algorithm" );
00037 rootFile_ = iConfig.getParameter<std::string>( "rootfile" );
00038 DQMFile_ = iConfig.getParameter<std::string>( "DQMFile" );
00039 TString tversion(edm::getReleaseVersion());
00040 tversion = tversion.Remove(0,1);
00041 tversion = tversion.Remove(tversion.Length()-1,tversion.Length());
00042 DQMFile_ = std::string(tversion)+"_"+DQMFile_;
00043 histogramList_ = iConfig.getParameter<vstring>( "histogramList" );
00044 referenceFilename_ = iConfig.getParameter<std::string>( "referenceFilename" );
00045 doCompare_ = iConfig.getParameter<bool>( "compareHistograms");
00046 }
00047
00048
00049 BTagValidator::~BTagValidator() {
00050
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 void
00060 BTagValidator::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00061 { }
00062
00063
00064 void
00065 BTagValidator::endJob()
00066 {
00067
00068 TObject * tObject ;
00069
00070
00071 MonitorElement* monElement ;
00072 MonitorElement* monElementRes;
00073
00074 TFile * file = new TFile ( TString ( rootFile_ ) ) ;
00075
00076
00077 HistoCompare hcompare;
00078
00079 if (doCompare_) hcompare.SetReferenceFilename(TString(referenceFilename_) );
00080
00081 file->cd();
00082
00083
00084 DQMStore * dbe = edm::Service<DQMStore>().operator->();
00085
00086 dbe->setCurrentFolder( "RecoBV/"+algorithm_ );
00087
00088 for (std::size_t i=0; i<histogramList_.size(); ++i) {
00089
00090 tObject = gDirectory->Get( TString( histogramList_[i] ) ) ;
00091
00092 if ( tObject == 0 )
00093 throw cms::Exception("BTagValidator") << "Histogram " << histogramList_[i] << " was not produced in the analysis. ";
00094
00095 if ( tObject->IsA()->InheritsFrom( "TH1" ) ) {
00096
00097 TH1 * histogram = (TH1*) tObject ;
00098
00099 TH1* hresiduals = 0;
00100
00101 if (doCompare_)
00102 hresiduals = hcompare.Compare(histogram, "/DQMData/"+TString(algorithm_)+"/"+TString(histogram->GetName()) );
00103
00104 file->cd();
00105
00106 monElement = dbe->book1D (
00107 std::string( histogram->GetName() ),
00108 std::string( histogram->GetTitle() ),
00109 histogram->GetXaxis()->GetNbins(),
00110 histogram->GetXaxis()->GetXmin(),
00111 histogram->GetXaxis()->GetXmax()
00112 );
00113
00114 monElement->setAxisTitle( std::string ( histogram->GetXaxis()->GetTitle()) , 1);
00115 monElement->setAxisTitle( std::string ( histogram->GetYaxis()->GetTitle()) , 2);
00116
00117
00118 for(Int_t x=0; x<histogram->GetXaxis()->GetNbins(); x++) {
00119 monElement->setBinContent ( x, histogram->GetBinContent( x ) ) ;
00120 monElement->setBinError ( x, histogram->GetBinError( x ) ) ;
00121 }
00122
00123 if (doCompare_ && hresiduals!= 0 ) {
00124 monElementRes = dbe->book1D (
00125 std::string( hresiduals->GetName() ),
00126 std::string( hresiduals->GetTitle() ),
00127 hresiduals->GetXaxis()->GetNbins(),
00128 hresiduals->GetXaxis()->GetXmin(),
00129 hresiduals->GetXaxis()->GetXmax()
00130 );
00131
00132
00133 for(Int_t x=0; x<hresiduals->GetXaxis()->GetNbins(); x++) {
00134 monElementRes->setBinContent ( x, hresiduals->GetBinContent( x ) ) ;
00135 monElementRes->setBinError ( x, hresiduals->GetBinError( x ) ) ;
00136 }
00137 }
00138 }
00139 else if ( tObject->IsA()->InheritsFrom( "TH2" ) ) {
00140
00141 TH2 * histogram = (TH2*) tObject ;
00142
00143 monElement = dbe->book2D (
00144 std::string( histogram->GetName() ),
00145 std::string( histogram->GetTitle() ),
00146 histogram->GetXaxis()->GetNbins(),
00147 histogram->GetXaxis()->GetXmin(),
00148 histogram->GetXaxis()->GetXmax(),
00149 histogram->GetYaxis()->GetNbins(),
00150 histogram->GetYaxis()->GetXmin(),
00151 histogram->GetYaxis()->GetXmax()
00152 );
00153
00154 monElement->setAxisTitle( std::string ( histogram->GetXaxis()->GetTitle()) , 1);
00155 monElement->setAxisTitle( std::string ( histogram->GetYaxis()->GetTitle()) , 2);
00156
00157 for(Int_t x=0; x<histogram->GetXaxis()->GetNbins(); x++)
00158 for(Int_t y=0; y<histogram->GetYaxis()->GetNbins(); y++) {
00159 monElement->setBinContent ( x, y, histogram->GetBinContent( x, y ) ) ;
00160 monElement->setBinError ( x, y, histogram->GetBinError( x, y ) ) ;
00161 }
00162 }
00163 else if ( tObject->IsA()->InheritsFrom( "TH3" ) ) {
00164
00165 TH3 * histogram = (TH3*) tObject ;
00166
00167 monElement = dbe->book3D (
00168 std::string( histogram->GetName() ),
00169 std::string( histogram->GetTitle() ),
00170 histogram->GetXaxis()->GetNbins(),
00171 histogram->GetXaxis()->GetXmin(),
00172 histogram->GetXaxis()->GetXmax(),
00173 histogram->GetYaxis()->GetNbins(),
00174 histogram->GetYaxis()->GetXmin(),
00175 histogram->GetYaxis()->GetXmax(),
00176 histogram->GetZaxis()->GetNbins(),
00177 histogram->GetZaxis()->GetXmin(),
00178 histogram->GetZaxis()->GetXmax()
00179 );
00180
00181 monElement->setAxisTitle( std::string ( histogram->GetXaxis()->GetTitle()) , 1);
00182 monElement->setAxisTitle( std::string ( histogram->GetYaxis()->GetTitle()) , 2);
00183
00184 for(Int_t x=0; x<histogram->GetXaxis()->GetNbins(); x++)
00185 for(Int_t y=0; y<histogram->GetYaxis()->GetNbins(); y++)
00186 for(Int_t z=0; z<histogram->GetZaxis()->GetNbins(); z++) {
00187 monElement->setBinContent ( x, y, z, histogram->GetBinContent( x, y, z ) ) ;
00188 monElement->setBinError ( x, y, z, histogram->GetBinError( x, y, z ) ) ;
00189 }
00190 }
00191 }
00192
00193 dbe->showDirStructure() ;
00194 dbe->save(DQMFile_) ;
00195 file->Close() ;
00196
00197 }
00198
00199
00200 DEFINE_FWK_MODULE(BTagValidator);