CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/IOMC/EventVertexGenerators/src/BaseEvtVtxGenerator.cc

Go to the documentation of this file.
00001 
00002 /*
00003 *  $Date: 2009/05/25 12:46:03 $
00004 *  $Revision: 1.14 $
00005 */
00006 
00007 #include "IOMC/EventVertexGenerators/interface/BaseEvtVtxGenerator.h"
00008 
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 
00012 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00013 
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00016 
00017 #include "FWCore/Utilities/interface/Exception.h"
00018 
00019 #include "DataFormats/Provenance/interface/Provenance.h"
00020 #include "FWCore/Utilities/interface/EDMException.h"
00021 
00022 //#include "HepMC/GenEvent.h"
00023 // #include "CLHEP/Vector/ThreeVector.h"
00024 // #include "HepMC/SimpleVector.h"
00025 
00026 using namespace edm;
00027 using namespace std;
00028 using namespace CLHEP;
00029 //using namespace HepMC;
00030 
00031 BaseEvtVtxGenerator::BaseEvtVtxGenerator( const ParameterSet& pset ) 
00032         : fVertex(0), boost_(0), fTimeOffset(0), fEngine(0),
00033           sourceLabel(pset.getParameter<edm::InputTag>("src"))
00034 {
00035    
00036 /* No longer needed...
00037 
00038    // 1st of all, check on module_label - must be VtxSmeared !
00039    if ( pset.getParameter<string>("@module_label") != "VtxSmeared" )
00040    {
00041       throw cms::Exception("Configuration")
00042         << "Module has an invalid module label. "
00043            "The label of this module MUST be VtxSmeared.";
00044    }
00045 */
00046       
00047    Service<RandomNumberGenerator> rng;
00048 
00049    if ( ! rng.isAvailable()) {
00050 
00051      throw cms::Exception("Configuration")
00052        << "The BaseEvtVtxGenerator requires the RandomNumberGeneratorService\n"
00053           "which is not present in the configuration file.  You must add the service\n"
00054           "in the configuration file or remove the modules that require it.";
00055    }
00056 
00057    CLHEP::HepRandomEngine& engine = rng->getEngine();
00058    fEngine = &engine;
00059 
00060       
00061    produces<bool>(); 
00062 }
00063 
00064 BaseEvtVtxGenerator::~BaseEvtVtxGenerator() 
00065 {
00066    delete fVertex ;
00067    if (boost_ != 0 ) delete boost_;
00068    // no need since now it's done in HepMCProduct
00069    // delete fEvt ;
00070 }
00071 
00072 void BaseEvtVtxGenerator::produce( Event& evt, const EventSetup& )
00073 {
00074    
00075    
00076    Handle<HepMCProduct> HepMCEvt ;
00077    
00078    evt.getByLabel( sourceLabel, HepMCEvt ) ;
00079    
00080    // generate new vertex & apply the shift 
00081    //
00082    HepMCEvt->applyVtxGen( newVertex() ) ;
00083 
00084    //HepMCEvt->LorentzBoost( 0., 142.e-6 );
00085    HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
00086    HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
00087    
00088    // OK, create a (pseudo)product and put in into edm::Event
00089    //
00090    auto_ptr<bool> NewProduct(new bool(true)) ;      
00091    evt.put( NewProduct ) ;
00092       
00093    return ;
00094 }
00095 
00096 CLHEP::HepRandomEngine& BaseEvtVtxGenerator::getEngine() 
00097 {
00098    return *fEngine;
00099 }