From 3e7c46173e8b3f83b9b1ac94660afcf613effbfc Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 14 Dec 2014 18:28:31 -0800 Subject: [PATCH] added python_cfg_example for Frank --- analysis/python_cfg_example/jamfile.jam | 22 +++++ analysis/python_cfg_example/pset/pset.py | 43 ++++++++++ analysis/python_cfg_example/source/main.cc | 94 ++++++++++++++++++++++ externals/build/cmssw/jamfile.jam | 78 ++++++++++++++++++ jamroot.jam | 3 +- 5 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 analysis/python_cfg_example/jamfile.jam create mode 100644 analysis/python_cfg_example/pset/pset.py create mode 100644 analysis/python_cfg_example/source/main.cc create mode 100644 externals/build/cmssw/jamfile.jam diff --git a/analysis/python_cfg_example/jamfile.jam b/analysis/python_cfg_example/jamfile.jam new file mode 100644 index 0000000..9f964b8 --- /dev/null +++ b/analysis/python_cfg_example/jamfile.jam @@ -0,0 +1,22 @@ +# jamfile for the python_cfg_example +# -------------------------------------------------------------------- # + +exe python_cfg_example + : # sources + ./source/main.cc + # dependent packages + /ROOT + #/CMSSW/shared # if you want all of CMSSW (see PAC/externals/build/cmssw/jamfile.jam) + /CMSSW//libFWCoreParameterSet/shared + /CMSSW//libFWCorePythonParameterSet/shared + : # requirements + ./include + ./source + : # default-build + : # usage-requirements + ; + +# install libs/exes +# -------------------------------------------------------------- # + +default-install python_cfg_example ; diff --git a/analysis/python_cfg_example/pset/pset.py b/analysis/python_cfg_example/pset/pset.py new file mode 100644 index 0000000..78fdf22 --- /dev/null +++ b/analysis/python_cfg_example/pset/pset.py @@ -0,0 +1,43 @@ +import FWCore.ParameterSet.Config as cms +import os +import sys + +## path the analysis (THIS SHOULD NOT CHANGE) +analysis_path = os.getenv("PAC") + "/analysis/python_cfg_example" +sys.path.append(analysis_path + "/pset") + +## process to parse (THIS SHOULD NOT CHANGE) +process = cms.PSet() + +## ------------------------------------------------------------- # +## Parameters for the selection, plot making, and fitting +## ------------------------------------------------------------- # + +process.pset = cms.PSet( + + ## path to the analysis + analysis_path = cms.string(analysis_path), + + ## the sample name (from Sample.h/cc) + sample_name = cms.string("sample"), + + ## integrated luminosity + lumi = cms.double(19.5), + + ## output label to give it a unique name + output_label = cms.string("v0"), + + ## search regions + search_regions = cms.vuint32(0, 1, 2, 3, 4, 5, 6), + + ## select a specific sparm parameter + mass_stop = cms.double(-1), + mass_lsp = cms.double(-1), + + ## max number of events to run on + max_events = cms.int64(-1), + + ## verbosity (for trouble shooting) + verbose = cms.bool(False), +) + diff --git a/analysis/python_cfg_example/source/main.cc b/analysis/python_cfg_example/source/main.cc new file mode 100644 index 0000000..5216d4f --- /dev/null +++ b/analysis/python_cfg_example/source/main.cc @@ -0,0 +1,94 @@ +// C++ includes +#include +#include +#include + +// ROOT includes +#include "TString.h" + +// CMSSW includes +// #include "FWCore/FWLite/interface/AutoLibraryLoader.h" // needed for FWLite if you want to run edm files +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/PythonParameterSet/interface/MakeParameterSets.h" + +// ------------------------------------------------------------------------------------ // +// The main program +// ------------------------------------------------------------------------------------ // + +int main(int argc, char **argv) +try +{ + using namespace std; + + // needed for FWLite if you want to run edm files +// gSystem->Load("libFWCoreFWLite"); +// AutoLibraryLoader::enable(); + + // parse the inputs + // -------------------------------------------------------------------------------------------------// + + // check that the python is passed + if (argc < 2) + { + throw std::invalid_argument(Form("Usage : %s [parameters.py]", argv[0])); + } + + // check that pset contains "process" + const std::string pset_filename = argv[1]; + if (!edm::readPSetsFrom(argv[1])->existsAs("process")) + { + throw std::invalid_argument(Form("[python_cfg_example] Error: ParametersSet 'process' is missing in your configuration file")); + } + + // get the python configuration + const edm::ParameterSet& process = edm::readPSetsFrom(pset_filename)->getParameter("process"); + const edm::ParameterSet& pset = process.getParameter("pset"); + + // get the inputs + const long long max_events = pset.getParameter ("max_events" ) ; + const bool verbose = pset.getParameter ("verbose" ) ; + const std::string analysis_path = pset.getParameter ("analysis_path" ) ; + const std::string output_label = pset.getParameter ("output_label" ) ; + const std::string sample_name = pset.getParameter ("sample_name" ) ; + const double lumi = pset.getParameter ("lumi" ) ; + const double mass_stop = pset.getParameter ("mass_stop" ) ; + const double mass_lsp = pset.getParameter ("mass_lsp" ) ; + const std::vector search_regions = pset.getParameter > ("search_regions") ; + + // print out the parameters + // -------------------------------------------------------------------------------------------------// + + cout << "\n[python_cfg_example] running with the following inputs:" << endl; + printf("%-25s = %lld\n" , "max_events" , max_events ); + printf("%-25s = %1.1f\n" , "lumi" , lumi ); + printf("%-25s = %s\n" , "sample_name" , sample_name.c_str() ); + printf("%-25s = %s\n" , "output_label" , output_label.c_str() ); + printf("%-25s = %d\n" , "verbose" , verbose ); + printf("%-25s = %1.0f\n" , "mass_stop" , mass_stop ); + printf("%-25s = %1.0f\n" , "mass_lsp" , mass_lsp ); + + // print the search regions + printf("%-25s = ", "SR(s)"); + for (size_t i = 0; i != search_regions.size(); i++) + { + if (search_regions.at(i) != search_regions.back()) {cout << search_regions.at(i) << ", ";} + else {cout << search_regions.at(i) << endl;} + } + + // do stuff + // -------------------------------------------------------------------------------------------------// + + //... + + // done + // -------------------------------------------------------------------------------------------------// + + return 0; +} +catch (std::exception& e) +{ + std::cerr << "[stop_interp_plots] Error: failed..." << std::endl; + std::cerr << e.what() << std::endl; + return 1; +} + diff --git a/externals/build/cmssw/jamfile.jam b/externals/build/cmssw/jamfile.jam new file mode 100644 index 0000000..e19987d --- /dev/null +++ b/externals/build/cmssw/jamfile.jam @@ -0,0 +1,78 @@ +# jamfile for CMSSW including FWLite + +# need to import some files +import os ; + +# env variables and other derived paths +# ------------------------------------------------------------------------------------------------- # + +# CMSSW variables (4.2 ish) +local CMS_PATH = [ os.environ CMS_PATH ] ; +local CMSSW_RELEASE_BASE = [ os.environ CMSSW_RELEASE_BASE ] ; +local CMSSW_BASE = [ os.environ CMSSW_BASE ] ; +local CMSSW_VERSION = [ os.environ CMSSW_VERSION ] ; +local CMSSW_SEARCH_PATH = [ os.environ CMSSW_SEARCH_PATH ] ; +local CMSSW_DATA_PATH = [ os.environ CMSSW_DATA_PATH ] ; +local SCRAM_ARCH = [ os.environ SCRAM_ARCH ] ; + +# derived variables paths +# NOT robust -- might need more logic if the release name is more complicated +# (e.g. CMSSW_5_3_14_LHAPDF590) +local CMSSW_EXTERNAL_BASE = $(CMS_PATH)/$(SCRAM_ARCH)/external ; +local CMSSW_RELEASE_NOPATCH_BASE = [ SHELL "echo -ne $CMSSW_RELEASE_BASE | sed 's/-patch//g' | sed 's/_patch4//g'" ] ; +#ECHO "CMSSW_RELEASE_NOPATCH_BASE is set: " $(CMSSW_RELEASE_NOPATCH_BASE) "\n" ; + +# library paths +local LIBS_LOCAL = $(CMSSW_BASE)/lib/$(SCRAM_ARCH) ; +local LIBS_BASE = $(CMSSW_RELEASE_BASE)/lib/$(SCRAM_ARCH) ; +local LIBS_NOPATCH_BASE = $(CMSSW_RELEASE_NOPATCH_BASE)/lib/$(SCRAM_ARCH) ; + +# External to CMSSW +# needed by FWLite and are CMSSW version dependent +# (see env var $CMSSW_FWLITE_INCLUDE_PATH) +local SHERPA = $(CMSSW_EXTERNAL_BASE)/sherpa/1.3.1-cms2 ; +local HEPMC = $(CMSSW_EXTERNAL_BASE)/hepmc/2.06.07 ; +local CLHEP = $(CMSSW_EXTERNAL_BASE)/clhep/2.0.4.6 ; + +# CMSSW search paths +# ------------------------------------------------------------------------------------------------- # +project CMSSW + : usage-requirements + # CMSSW Local + $(CMSSW_SEARCH_PATH) + $(CMSSW_BASE)/src + $(CMSSW_BASE)/external/$(SCRAM_ARCH)/data + # CMSSW Release + $(CMSSW_RELEASE_BASE)/src + $(CMSSW_RELEASE_BASE)/external/$(SCRAM_ARCH)/data + # CMSSW Nopatch Release + $(CMSSW_RELEASE_NOPATCH_BASE)/src + $(CMSSW_RELEASE_NOPATCH_BASE)/external/$(SCRAM_ARCH)/data + # CMSSW Externals + $(SHERPA)/include + $(HEPMC)/include + $(CLHEP)/include + ; + +# CMSSW libs +# ------------------------------------------------------------------------------------------------- # +lib libFWCoreFWLite : : FWCoreFWLite $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +lib libFWCoreFramework : : FWCoreFramework $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +lib libFWCoreParameterSet : : FWCoreParameterSet $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +lib libFWCorePythonParameterSet : : FWCorePythonParameterSet $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; + +# these are out of date -- add as need from LIBS_LOCAL, LIBS_BASE, or LIBS_NOPATCH_BASE +#lib libFWCoreVersion : : FWCoreVersion $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libDQMServicesClientConfig : : DQMServicesClientConfig $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libCommonToolsCandAlgos : : CommonToolsCandAlgos $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libDataFormatsFWLite : : DataFormatsFWLite $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libDataFormatsMath : : DataFormatsMath $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libPhysicsToolsFWLite : : PhysicsToolsFWLite $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libDataFormatsTrackReco : : DataFormatsTrackReco $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libDataFormatsCLHEP : : DataFormatsCLHEP $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libSimDataFormatsTrackingAnalysis : : SimDataFormatsTrackingAnalysis $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libCommonToolsUtilAlgos : : CommonToolsUtilAlgos $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libCalibCalorimetryEcalTPGTools : : CalibCalorimetryEcalTPGTools $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libPhysicsToolsPFCandProducer : : PhysicsToolsPFCandProducer $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; +#lib libRecoEgammaElectronIdentification : : RecoEgammaElectronIdentification $(LIBS_LOCAL) $(LIBS_BASE) $(LIBS_NOPATCH_BASE) shared ; + diff --git a/jamroot.jam b/jamroot.jam index 1810e27..4524fa5 100644 --- a/jamroot.jam +++ b/jamroot.jam @@ -66,8 +66,7 @@ set-install-dir $(install-dir) ; # ----------------------------------------------------------------------# # CMSSW -#path-constant CMSSW_SRC : /usr/local/cmssw/osx107_amd64_gcc462/cms/cmssw/CMSSW_5_3_4/src ; -#use-project /CMSSW : ./externals/build/CMSSW ; +use-project /CMSSW : ./externals/build/cmssw ; # BOOST local boost_current = [ os.environ BOOST_CURRENT ] ;