CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Validation/EventGenerator/src/WeightManager.cc

Go to the documentation of this file.
00001 #include "Validation/EventGenerator/interface/WeightManager.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00007 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
00008 
00009 
00010 using namespace edm;
00011 
00012 WeightManager::WeightManager(const ParameterSet& iConfig):
00013 _useHepMC(iConfig.getParameter<bool>("UseWeightFromHepMC"))
00014 {
00015   if (_useHepMC)
00016     _hepmcCollection = iConfig.getParameter<InputTag>("hepmcCollection");
00017   else  
00018     _genEventInfos = iConfig.getParameter<std::vector<InputTag> >("genEventInfos");
00019 }
00020 
00021 double WeightManager::weight(const Event& iEvent){
00022   if (_useHepMC){
00023     edm::Handle<HepMCProduct> evt;
00024     iEvent.getByLabel(_hepmcCollection, evt);
00025     const HepMC::GenEvent *myGenEvent = evt->GetEvent();
00026 
00027     double weight = 1.;
00028     if (myGenEvent->weights().size() > 0)
00029       weight = myGenEvent->weights()[0];
00030     return weight;
00031   } else {
00032     double weight = 1.;
00033     for (unsigned int i = 0; i < _genEventInfos.size(); ++i){
00034       edm::Handle<GenEventInfoProduct> info;
00035       iEvent.getByLabel(_genEventInfos[i], info);
00036       weight *= info->weight();
00037     }
00038     return weight;
00039   }
00040 }