From e6bf3f4c4b772a0dd564945ed27e026c77688f83 Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 18 Feb 2015 09:18:00 +0100 Subject: [PATCH] rivet with lhe weights --- .../RivetInterface/interface/RivetAnalyzer.h | 3 ++ .../RivetInterface/plugins/RivetAnalyzer.cc | 48 ++++++++++++------- .../python/rivetAnalyzer_cfi.py | 3 ++ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h b/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h index 037ba5c6aa68c..60f9b1d46440d 100644 --- a/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h +++ b/GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h @@ -47,6 +47,9 @@ class RivetAnalyzer : public edm::EDAnalyzer edm::InputTag _hepmcCollection; bool _useExternalWeight; + bool _useLHEweights; + int _LHEweightNumber; + edm::InputTag _LHECollection; edm::InputTag _genEventInfoCollection; Rivet::AnalysisHandler _analysisHandler; bool _isFirstEvent; diff --git a/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc b/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc index b02c7175d3211..56f06d1a2877b 100644 --- a/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc +++ b/GeneratorInterface/RivetInterface/plugins/RivetAnalyzer.cc @@ -6,6 +6,7 @@ #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" #include "DataFormats/Common/interface/Handle.h" #include "Rivet/AnalysisHandler.hh" @@ -40,6 +41,10 @@ _produceDQM(pset.getParameter("ProduceDQMOutput")) throw cms::Exception("RivetAnalyzer") << "when using an external event weight you have to specify the GenEventInfoProduct collection from which the weight has to be taken " ; } _genEventInfoCollection = pset.getParameter("GenEventInfoCollection"); + _LHECollection = pset.getParameter("LHECollection"); + _useLHEweights = pset.getParameter("useLHEweights"); + _LHEweightNumber = pset.getParameter("LHEweightNumber"); + } //get the analyses @@ -55,7 +60,7 @@ _produceDQM(pset.getParameter("ProduceDQMOutput")) xsection = pset.getParameter("CrossSection"); for (iana = ibeg; iana != iend; ++iana){ if ((*iana)->needsCrossSection()) - (*iana)->setCrossSection(xsection); + (*iana)->setCrossSection(xsection); } if (_produceDQM){ // book stuff needed for DQM @@ -92,8 +97,10 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet // get HepMC GenEvent const HepMC::GenEvent *myGenEvent = evt->GetEvent(); - //if you want to use an external weight we have to clene the GenEvent and change the weight + + //if you want to use an external weight we have to clone the GenEvent and change the weight if ( _useExternalWeight ){ + HepMC::GenEvent * tmpGenEvtPtr = new HepMC::GenEvent( *(evt->GetEvent()) ); if (tmpGenEvtPtr->weights().size() == 0) { throw cms::Exception("RivetAnalyzer") << "Original weight container has 0 size "; @@ -101,12 +108,21 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet if (tmpGenEvtPtr->weights().size() > 1) { edm::LogWarning("RivetAnalyzer") << "Original event weight size is " << tmpGenEvtPtr->weights().size() << ". Will change only the first one "; } - edm::Handle genEventInfoProduct; - iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct); - tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight(); - myGenEvent = tmpGenEvtPtr; - } + if(!_useLHEweights){ + edm::Handle genEventInfoProduct; + iEvent.getByLabel(_genEventInfoCollection, genEventInfoProduct); + tmpGenEvtPtr->weights()[0] = genEventInfoProduct->weight(); + }else{ + edm::Handle lheEventHandle; + iEvent.getByLabel(_LHECollection,lheEventHandle); + const LHEEventProduct::WGT& wgt = lheEventHandle->weights().at(_LHEweightNumber); + tmpGenEvtPtr->weights()[0] = wgt.wgt; + } + myGenEvent = tmpGenEvtPtr; + + } + //aaply the beams initialization on the first event if (_isFirstEvent){ @@ -119,13 +135,13 @@ void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSet //if we have cloned the GenEvent, we delete it if ( _useExternalWeight ) - delete myGenEvent; + delete myGenEvent; } void RivetAnalyzer::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){ if (_doFinalize) - _analysisHandler.finalize(); + _analysisHandler.finalize(); else { //if we don't finalize we just want to do the transformation from histograms to DPS ////normalizeTree(_analysisHandler.tree()); @@ -139,11 +155,11 @@ void RivetAnalyzer::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){ - //from Rivet 2.X: Analysis.hh (cls 18Feb2014) - /// List of registered analysis data objects - //const vector& analysisObjects() const { - //return _analysisobjects; - //} +//from Rivet 2.X: Analysis.hh (cls 18Feb2014) +/// List of registered analysis data objects +//const vector& analysisObjects() const { +//return _analysisobjects; +//} @@ -198,7 +214,7 @@ void RivetAnalyzer::normalizeTree() { _analysisHandler.datapointsetFactory().create(path, *tmphisto); } //now convert to root and then ME - //need aida2flat (from Rivet 1.X) & flat2root here + //need aida2flat (from Rivet 1.X) & flat2root here TH1F* h = aida2root(histo, basename); if (_produceDQM) _mes.push_back(dbe->book1D(h->GetName(), h)); @@ -212,7 +228,7 @@ void RivetAnalyzer::normalizeTree() { _analysisHandler.datapointsetFactory().create(path, *tmpprof); } //now convert to root and then ME - //need aida2flat (from Rivet 1.X) & flat2root here + //need aida2flat (from Rivet 1.X) & flat2root here TProfile* p = aida2root(prof, basename); if (_produceDQM) _mes.push_back(dbe->bookProfile(p->GetName(), p)); diff --git a/GeneratorInterface/RivetInterface/python/rivetAnalyzer_cfi.py b/GeneratorInterface/RivetInterface/python/rivetAnalyzer_cfi.py index 86a578b1b73ba..25cad2ff5d222 100644 --- a/GeneratorInterface/RivetInterface/python/rivetAnalyzer_cfi.py +++ b/GeneratorInterface/RivetInterface/python/rivetAnalyzer_cfi.py @@ -5,6 +5,9 @@ HepMCCollection = cms.InputTag('generator'), UseExternalWeight = cms.bool(False), GenEventInfoCollection = cms.InputTag('generator'), + useLHEweights = cms.bool(False), + LHEweightNumber = cms.int32(0), + LHECollection = cms.InputTag('source'), CrossSection = cms.double(1000), DoFinalize = cms.bool(True), ProduceDQMOutput = cms.bool(False),