CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoEgamma/EgammaTools/plugins/GBRWrapperMaker.cc

Go to the documentation of this file.
00001 
00002 // -*- C++ -*-
00003 //
00004 // Package:    GBRWrapperMaker
00005 // Class:      GBRWrapperMaker
00006 // 
00014 //
00015 // Original Author:  Josh Bendavid
00016 //         Created:  Tue Nov  8 22:26:45 CET 2011
00017 // $Id: GBRWrapperMaker.cc,v 1.6 2011/12/14 21:33:00 bendavid Exp $
00018 //
00019 //
00020 
00021 
00022 // system include files
00023 #include <memory>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 #include "TFile.h"
00034 #include "CondFormats/EgammaObjects/interface/GBRForest.h"
00035 #include "FWCore/ServiceRegistry/interface/Service.h"
00036 //#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00037 //#include "CondCore/DBCommon/interface/CoralServiceManager.h"
00038 
00039 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00040 #include "FWCore/Framework/interface/ESHandle.h"
00041 #include "FWCore/Framework/interface/EventSetup.h"
00042 #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h"
00043 
00044 
00045 //
00046 // class declaration
00047 //
00048 
00049 class GBRWrapperMaker : public edm::EDAnalyzer {
00050    public:
00051       explicit GBRWrapperMaker(const edm::ParameterSet&);
00052       ~GBRWrapperMaker();
00053 
00054       static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00055 
00056 
00057    private:
00058       virtual void beginJob() ;
00059       virtual void analyze(const edm::Event&, const edm::EventSetup&);
00060       virtual void endJob() ;
00061 
00062       virtual void beginRun(edm::Run const&, edm::EventSetup const&);
00063       virtual void endRun(edm::Run const&, edm::EventSetup const&);
00064       virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00065       virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
00066 
00067       // ----------member data ---------------------------
00068 };
00069 
00070 //
00071 // constants, enums and typedefs
00072 //
00073 
00074 //
00075 // static data member definitions
00076 //
00077 
00078 //
00079 // constructors and destructor
00080 //
00081 GBRWrapperMaker::GBRWrapperMaker(const edm::ParameterSet& iConfig)
00082 
00083 {
00084    //now do what ever initialization is needed
00085 
00086 }
00087 
00088 
00089 GBRWrapperMaker::~GBRWrapperMaker()
00090 {
00091  
00092    // do anything here that needs to be done at desctruction time
00093    // (e.g. close files, deallocate resources etc.)
00094 
00095 }
00096 
00097 
00098 //
00099 // member functions
00100 //
00101 
00102 // ------------ method called for each event  ------------
00103 void
00104 GBRWrapperMaker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00105 {
00106    using namespace edm;
00107 
00108 
00109 
00110 // #ifdef THIS_IS_AN_EVENT_EXAMPLE
00111 //    Handle<ExampleData> pIn;
00112 //    iEvent.getByLabel("example",pIn);
00113 // #endif
00114 //    
00115 // #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00116 //    ESHandle<SetupData> pSetup;
00117 //    iSetup.get<SetupRecord>().get(pSetup);
00118 // #endif
00119 //from Josh:
00120   TFile *infile = new TFile("/afs/cern.ch/user/b/bendavid/cmspublic/gbrv3ph.root","READ");
00121 
00122   printf("load forest\n");
00123 
00124 
00125   GBRForest *gbreb = (GBRForest*)infile->Get("EBCorrection");
00126   GBRForest *gbrebvar = (GBRForest*)infile->Get("EBUncertainty");
00127   GBRForest *gbree = (GBRForest*)infile->Get("EECorrection");
00128   GBRForest *gbreevar = (GBRForest*)infile->Get("EEUncertainty");
00129 
00130 
00131 
00132 
00133 //from Rishi
00134   
00135   TFile *infile_PFLC = new TFile("/afs/cern.ch/user/r/rpatel/ConvXml/TMVARegression_BDTG_PFClusterCorr.root","READ");
00136   TFile *infile_PFGC = new TFile("/afs/cern.ch/user/r/rpatel/ConvXml/TMVARegression_BDTG_PFGlobalCorr.root","READ");
00137   TFile *infile_PFRes = new TFile("/afs/cern.ch/user/r/rpatel/ConvXml/TMVARegression_BDTG_PFRes.root ","READ");
00138   
00139   GBRForest *gbrLC = (GBRForest*)infile_PFLC->Get("GBRForest");
00140   GBRForest *gbrGC = (GBRForest*)infile_PFGC->Get("GBRForest");
00141   GBRForest *gbrRes = (GBRForest*)infile_PFRes->Get("GBRForest");
00142   
00143   
00144   
00145   
00146   printf("made objects\n");
00147   edm::Service<cond::service::PoolDBOutputService> poolDbService;
00148   if (poolDbService.isAvailable()) {
00149        
00150  poolDbService->writeOne( gbreb, poolDbService->beginOfTime(),
00151                                                 "wgbrph_EBCorrection"  );
00152     poolDbService->writeOne( gbrebvar, poolDbService->beginOfTime(),
00153                                                 "wgbrph_EBUncertainty"  );
00154     poolDbService->writeOne( gbree, poolDbService->beginOfTime(),
00155                                               "wgbrph_EECorrection"  );
00156     poolDbService->writeOne( gbreevar, poolDbService->beginOfTime(),
00157                                                 "wgbrph_EEUncertainty"  );
00158     
00159     poolDbService->writeOne( gbrLC, poolDbService->beginOfTime(),
00160                              "wgbrph_PFLCCorrection"  );
00161     poolDbService->writeOne( gbrGC, poolDbService->beginOfTime(),
00162                              "wgbrph_PFGlobalCorrection"  );
00163     poolDbService->writeOne( gbrRes, poolDbService->beginOfTime(),
00164                              "wgbrph_PFResolution"  );
00165   
00166   }
00167 
00168 
00169 }
00170 
00171 
00172 // ------------ method called once each job just before starting event loop  ------------
00173 void 
00174 GBRWrapperMaker::beginJob()
00175 {
00176 }
00177 
00178 // ------------ method called once each job just after ending the event loop  ------------
00179 void 
00180 GBRWrapperMaker::endJob() 
00181 {
00182 }
00183 
00184 // ------------ method called when starting to processes a run  ------------
00185 void 
00186 GBRWrapperMaker::beginRun(edm::Run const&, edm::EventSetup const&)
00187 {
00188 }
00189 
00190 // ------------ method called when ending the processing of a run  ------------
00191 void 
00192 GBRWrapperMaker::endRun(edm::Run const&, edm::EventSetup const&)
00193 {
00194 }
00195 
00196 // ------------ method called when starting to processes a luminosity block  ------------
00197 void 
00198 GBRWrapperMaker::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00199 {
00200 }
00201 
00202 // ------------ method called when ending the processing of a luminosity block  ------------
00203 void 
00204 GBRWrapperMaker::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
00205 {
00206 }
00207 
00208 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
00209 void
00210 GBRWrapperMaker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00211   //The following says we do not know what parameters are allowed so do no validation
00212   // Please change this to state exactly what you do use, even if it is no parameters
00213   edm::ParameterSetDescription desc;
00214   desc.setUnknown();
00215   descriptions.addDefault(desc);
00216 }
00217 
00218 //define this as a plug-in
00219 DEFINE_FWK_MODULE(GBRWrapperMaker);