Skip to content

Commit

Permalink
add the simulation beam profile in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
vlimant committed Jan 17, 2012
1 parent 47792b3 commit 0c336a3
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CondCore/BeamSpotPlugins/src/plugin.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "CondCore/ESSources/interface/registration_macros.h"
#include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h"
#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h"
#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"

REGISTER_PLUGIN(BeamSpotObjectsRcd,BeamSpotObjects);
REGISTER_PLUGIN(SimBeamSpotObjectsRcd,SimBeamSpotObjects);
6 changes: 3 additions & 3 deletions IOMC/EventVertexGenerators/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<flags EDM_PLUGIN="1"/>
<export>
<lib name="1"/>
</export>
<use name="FWCore/Framework"/>
<use name="FWCore/PluginManager"/>
<use name="FWCore/ParameterSet"/>
Expand All @@ -11,3 +8,6 @@
<use name="boost"/>
<use name="clhep"/>
<use name="hepmc"/>
<use name="CondFormats/DataRecord"/>
<use name="CondFormats/BeamSpotObjects"/>
<use name="CondCore/DBOutputService"/>
7 changes: 4 additions & 3 deletions IOMC/EventVertexGenerators/interface/BaseEvtVtxGenerator.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef IOMC_BaseEvtVtxGenerator_H
#define IOMC_BaseEvtVtxGenerator_H
/*
* $Date: 2008/05/28 16:40:45 $
* $Revision: 1.7 $
* $Date: 2010/02/11 00:12:31 $
* $Revision: 1.8 $
*/

#include "FWCore/Framework/interface/EDProducer.h"
Expand Down Expand Up @@ -34,7 +34,8 @@ class BaseEvtVtxGenerator : public edm::EDProducer
virtual ~BaseEvtVtxGenerator();

virtual void produce( edm::Event&, const edm::EventSetup& );

virtual void beginRun( edm::Run & , const edm::EventSetup&) {};

//virtual CLHEP::Hep3Vector* newVertex() = 0;
virtual HepMC::FourVector* newVertex() = 0 ;
/** This method - and the comment - is a left-over from COBRA-OSCAR time :
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef IOMC_BetafuncEvtVtxGenerator_H
#define IOMC_BetafuncEvtVtxGenerator_H

// $Id: BetafuncEvtVtxGenerator.h,v 1.5 2007/09/14 08:31:56 fabiocos Exp $
// $Id: BetafuncEvtVtxGenerator.h,v 1.6 2008/04/04 21:38:24 yumiceva Exp $
/*
________________________________________________________________________
Expand Down Expand Up @@ -32,6 +32,8 @@ class BetafuncEvtVtxGenerator : public BaseEvtVtxGenerator
BetafuncEvtVtxGenerator(const edm::ParameterSet & p);
virtual ~BetafuncEvtVtxGenerator();

virtual void beginRun( edm::Run & , const edm::EventSetup&);

/// return a new event vertex
//virtual CLHEP::Hep3Vector * newVertex();
virtual HepMC::FourVector* newVertex() ;
Expand Down Expand Up @@ -70,6 +72,8 @@ class BetafuncEvtVtxGenerator : public BaseEvtVtxGenerator

private:

bool readDB_;

double alpha_, phi_;
//TMatrixD boost_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

# common parameters
VtxSmearedCommon = cms.PSet(
src = cms.InputTag("generator")
src = cms.InputTag("generator"),
readDB = cms.bool(False)
)
# Gaussian smearing
GaussVtxSmearingParameters = cms.PSet(
Expand Down
158 changes: 158 additions & 0 deletions IOMC/EventVertexGenerators/src/BeamProfile2DB.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// -*- C++ -*-
//
// Package: BeamProfile2DB
// Class: BeamProfile2DB
//
/**\class BeamProfile2DB BeamProfile2DB.cc IOMC/BeamProfile2DB/src/BeamProfile2DB.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Jean-Roch Vlimant,40 3-A28,+41227671209,
// Created: Fri Jan 6 14:49:42 CET 2012
// $Id$
//
//


// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"


//
// class declaration
//

class BeamProfile2DB : public edm::EDAnalyzer {
public:
explicit BeamProfile2DB(const edm::ParameterSet&);
~BeamProfile2DB();

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);


private:
virtual void beginJob() ;
virtual void analyze(const edm::Event&, const edm::EventSetup&);
virtual void endJob() ;

virtual void beginRun(edm::Run const&, edm::EventSetup const&);
virtual void endRun(edm::Run const&, edm::EventSetup const&);
virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);

// ----------member data ---------------------------
edm::ParameterSet config_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
BeamProfile2DB::BeamProfile2DB(const edm::ParameterSet& iConfig)

{
config_=iConfig;
}


BeamProfile2DB::~BeamProfile2DB()
{

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

}


//
// member functions
//

// ------------ method called for each event ------------
void
BeamProfile2DB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
}


// ------------ method called once each job just before starting event loop ------------
void
BeamProfile2DB::beginJob()
{
}

// ------------ method called once each job just after ending the event loop ------------
void
BeamProfile2DB::endJob()
{
edm::Service<cond::service::PoolDBOutputService> poolDbService;
SimBeamSpotObjects * beam = new SimBeamSpotObjects();

beam->read(config_);

poolDbService->createNewIOV<SimBeamSpotObjects>(beam,
poolDbService->beginOfTime(),poolDbService->endOfTime(),
"SimBeamSpotObjectsRcd" );

}

// ------------ method called when starting to processes a run ------------
void
BeamProfile2DB::beginRun(edm::Run const&, edm::EventSetup const&)
{
}

// ------------ method called when ending the processing of a run ------------
void
BeamProfile2DB::endRun(edm::Run const&, edm::EventSetup const&)
{
}

// ------------ method called when starting to processes a luminosity block ------------
void
BeamProfile2DB::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
{
}

// ------------ method called when ending the processing of a luminosity block ------------
void
BeamProfile2DB::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
{
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void
BeamProfile2DB::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(BeamProfile2DB);
50 changes: 35 additions & 15 deletions IOMC/EventVertexGenerators/src/BetafuncEvtVtxGenerator.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// $Id: BetafuncEvtVtxGenerator.cc,v 1.11 2010/12/06 10:57:25 yumiceva Exp $
// $Id: BetafuncEvtVtxGenerator.cc,v 1.12 2011/03/08 16:09:22 burkett Exp $
/*
________________________________________________________________________
Expand All @@ -22,13 +22,18 @@ ________________________________________________________________________
#include "IOMC/EventVertexGenerators/interface/BetafuncEvtVtxGenerator.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ESHandle.h"

#include "CLHEP/Random/RandGaussQ.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "CLHEP/Units/GlobalPhysicalConstants.h"
//#include "CLHEP/Vector/ThreeVector.h"
#include "HepMC/SimpleVector.h"

#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h"
#include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h"

#include <iostream>


Expand All @@ -39,20 +44,23 @@ BetafuncEvtVtxGenerator::BetafuncEvtVtxGenerator(const edm::ParameterSet & p )

fRandom = new CLHEP::RandGaussQ(getEngine());

fX0 = p.getParameter<double>("X0")*cm;
fY0 = p.getParameter<double>("Y0")*cm;
fZ0 = p.getParameter<double>("Z0")*cm;
fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
alpha_ = p.getParameter<double>("Alpha")*radian;
phi_ = p.getParameter<double>("Phi")*radian;
fbetastar = p.getParameter<double>("BetaStar")*cm;
femittance = p.getParameter<double>("Emittance")*cm; // this is not the normalized emittance
fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light; // HepMC time units are mm

if (fSigmaZ <= 0) {
throw cms::Exception("Configuration")
<< "Error in BetafuncEvtVtxGenerator: "
<< "Illegal resolution in Z (SigmaZ is negative)";
readDB_=p.getParameter<bool>("readDB");
if (!readDB_){
fX0 = p.getParameter<double>("X0")*cm;
fY0 = p.getParameter<double>("Y0")*cm;
fZ0 = p.getParameter<double>("Z0")*cm;
fSigmaZ = p.getParameter<double>("SigmaZ")*cm;
alpha_ = p.getParameter<double>("Alpha")*radian;
phi_ = p.getParameter<double>("Phi")*radian;
fbetastar = p.getParameter<double>("BetaStar")*cm;
femittance = p.getParameter<double>("Emittance")*cm; // this is not the normalized emittance
fTimeOffset = p.getParameter<double>("TimeOffset")*ns*c_light; // HepMC time units are mm

if (fSigmaZ <= 0) {
throw cms::Exception("Configuration")
<< "Error in BetafuncEvtVtxGenerator: "
<< "Illegal resolution in Z (SigmaZ is negative)";
}
}


Expand All @@ -63,6 +71,18 @@ BetafuncEvtVtxGenerator::~BetafuncEvtVtxGenerator()
delete fRandom;
}

void BetafuncEvtVtxGenerator::beginRun( edm::Run & , const edm::EventSetup& iEventSetup){

if (readDB_){
edm::ESHandle< SimBeamSpotObjects > beamhandle;
iEventSetup.get<SimBeamSpotObjectsRcd>().get(beamhandle);
fX0=beamhandle->fX0;

//re-initialize the boost matrix
delete boost_;
boost_=0;
}
}

//Hep3Vector* BetafuncEvtVtxGenerator::newVertex() {
HepMC::FourVector* BetafuncEvtVtxGenerator::newVertex() {
Expand Down

0 comments on commit 0c336a3

Please sign in to comment.