CMS 3D CMS Logo

BaseEvtVtxGenerator.cc
Go to the documentation of this file.
1 
2 /*
3 */
4 
6 
9 
12 
15 
17 
20 
21 //#include "HepMC/GenEvent.h"
22 // #include "CLHEP/Vector/ThreeVector.h"
23 // #include "HepMC/SimpleVector.h"
24 
25 using namespace edm;
26 using namespace CLHEP;
27 //using namespace HepMC;
28 
29 
31  : fVertex(0), boost_(0), fTimeOffset(0),
32  sourceLabel(pset.getParameter<edm::InputTag>("src"))
33 {
35  if ( ! rng.isAvailable()) {
36  throw cms::Exception("Configuration")
37  << "The BaseEvtVtxGenerator requires the RandomNumberGeneratorService\n"
38  "which is not present in the configuration file. \n"
39  "You must add the service\n"
40  "in the configuration file or remove the modules that require it.";
41  }
42 
43  consumes<edm::HepMCProduct>(sourceLabel);
44  produces<edm::HepMCProduct>();
45 }
46 
48 {
49  delete fVertex ;
50  if (boost_ != nullptr ) delete boost_;
51  // no need since now it's done in HepMCProduct
52  // delete fEvt ;
53 }
54 
56 {
58  CLHEP::HepRandomEngine* engine = &rng->getEngine(evt.streamID());
59 
60  Handle<HepMCProduct> HepUnsmearedMCEvt ;
61 
62  evt.getByLabel( sourceLabel, HepUnsmearedMCEvt ) ;
63 
64  // Copy the HepMC::GenEvent
65  HepMC::GenEvent* genevt = new HepMC::GenEvent(*HepUnsmearedMCEvt->GetEvent());
66  std::unique_ptr<edm::HepMCProduct> HepMCEvt(new edm::HepMCProduct(genevt));
67  // generate new vertex & apply the shift
68  //
69  HepMCEvt->applyVtxGen( newVertex(engine) ) ;
70 
71  //HepMCEvt->LorentzBoost( 0., 142.e-6 );
72  HepMCEvt->boostToLab( GetInvLorentzBoost(), "vertex" );
73  HepMCEvt->boostToLab( GetInvLorentzBoost(), "momentum" );
74 
75  evt.put(std::move(HepMCEvt)) ;
76 
77  return ;
78 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
HepMC::FourVector * fVertex
virtual void produce(edm::Event &, const edm::EventSetup &) override
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
virtual HepMC::FourVector * newVertex(CLHEP::HepRandomEngine *)=0
BaseEvtVtxGenerator(const edm::ParameterSet &)
bool isAvailable() const
Definition: Service.h:46
virtual TMatrixD * GetInvLorentzBoost()=0
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:35
return(e1-e2)*(e1-e2)+dp *dp
HLT enums.
StreamID streamID() const
Definition: Event.h:81
def move(src, dest)
Definition: eostools.py:510