CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
BeamDivergenceVtxGenerator Class Reference
Inheritance diagram for BeamDivergenceVtxGenerator:
edm::stream::EDProducer<>

Public Member Functions

 BeamDivergenceVtxGenerator (const edm::ParameterSet &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~BeamDivergenceVtxGenerator () override=default
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 

Private Attributes

bool simulateBeamDivergence_
 
bool simulateVertex_
 
edm::EDGetTokenT< edm::HepMCProductsourceToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 26 of file BeamDivergenceVtxGenerator.cc.

Constructor & Destructor Documentation

BeamDivergenceVtxGenerator::BeamDivergenceVtxGenerator ( const edm::ParameterSet iConfig)
explicit

Definition at line 45 of file BeamDivergenceVtxGenerator.cc.

References edm::Service< T >::isAvailable().

45  :
46  sourceToken_(consumes<edm::HepMCProduct>( iConfig.getParameter<edm::InputTag>("src"))),
47  simulateVertex_ (iConfig.getParameter<bool>("simulateVertex")),
48  simulateBeamDivergence_(iConfig.getParameter<bool>("simulateBeamDivergence"))
49 {
51  if (!rng.isAvailable())
52  throw cms::Exception("Configuration")
53  << "The BeamDivergenceVtxGenerator requires the RandomNumberGeneratorService\n"
54  "which is not present in the configuration file. \n"
55  "You must add the service\n"
56  "in the configuration file or remove the modules that require it.";
57 
58  produces<edm::HepMCProduct>();
59 }
T getParameter(std::string const &) const
bool isAvailable() const
Definition: Service.h:40
edm::EDGetTokenT< edm::HepMCProduct > sourceToken_
BeamDivergenceVtxGenerator::~BeamDivergenceVtxGenerator ( )
overridedefault

Member Function Documentation

void BeamDivergenceVtxGenerator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 135 of file BeamDivergenceVtxGenerator.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), and DEFINE_FWK_MODULE.

136 {
138  desc.add<edm::InputTag>("src", edm::InputTag("generator", "unsmeared"))
139  ->setComment("input collection where to retrieve outgoing particles kinematics to be smeared");
140  desc.add<bool>("simulateBeamDivergence", true)->setComment("account for the beam angular divergence?");
141  desc.add<bool>("simulateVertex", true)->setComment("account for the vertex transverse smearing?");
142 
143  descriptions.add("beamDivergenceVtxGenerator", desc);
144 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void BeamDivergenceVtxGenerator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 64 of file BeamDivergenceVtxGenerator.cc.

References edm::EventSetup::get(), CTPPSBeamParameters::getBeamDivergenceX45(), CTPPSBeamParameters::getBeamDivergenceX56(), CTPPSBeamParameters::getBeamDivergenceY45(), CTPPSBeamParameters::getBeamDivergenceY56(), edm::Event::getByToken(), edm::RandomNumberGenerator::getEngine(), edm::HepMCProduct::GetEvent(), CTPPSBeamParameters::getVtxOffsetX45(), CTPPSBeamParameters::getVtxOffsetY45(), CTPPSBeamParameters::getVtxOffsetZ45(), CTPPSBeamParameters::getVtxStddevX(), CTPPSBeamParameters::getVtxStddevY(), CTPPSBeamParameters::getVtxStddevZ(), eostools::move(), edm::Event::put(), edm::shift, Validation_hcalonly_cfi::sign, simulateBeamDivergence_, simulateVertex_, sourceToken_, mathSSE::sqrt(), and edm::Event::streamID().

65 {
66  // get random engine
68  CLHEP::HepRandomEngine* rnd = &(rng->getEngine(iEvent.streamID()));
69 
70  // get conditions
71  edm::ESHandle<CTPPSBeamParameters> hBeamParameters;
72  iSetup.get<CTPPSBeamParametersRcd>().get(hBeamParameters);
73 
74  // get input
75  edm::Handle<edm::HepMCProduct> hepUnsmearedMCEvt;
76  iEvent.getByToken(sourceToken_, hepUnsmearedMCEvt);
77 
78  // prepare output
79  HepMC::GenEvent* genevt = new HepMC::GenEvent(*hepUnsmearedMCEvt->GetEvent());
80  std::unique_ptr<edm::HepMCProduct> pEvent(new edm::HepMCProduct(genevt));
81 
82  // apply vertex smearing
83  if (simulateVertex_) {
84  // NB: the separtion between effective offsets in LHC sectors 45 and 56 cannot be applied, thus the values for 45 are used
85  const double vtx_x = hBeamParameters->getVtxOffsetX45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevX();
86  const double vtx_y = hBeamParameters->getVtxOffsetY45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevY();
87  const double vtx_z = hBeamParameters->getVtxOffsetZ45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevZ();
88 
89  HepMC::FourVector shift(vtx_x*1E1, vtx_y*1E1, vtx_z*1E1, 0.); // conversions: cm to mm
90  pEvent->applyVtxGen(&shift);
91  }
92 
93  // apply beam divergence
95  const double bd_x_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX45();
96  const double bd_x_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX56();
97 
98  const double bd_y_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY45();
99  const double bd_y_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY56();
100 
101  for (HepMC::GenEvent::particle_iterator part = genevt->particles_begin(); part != genevt->particles_end(); ++part) {
102  const HepMC::FourVector mom = (*part)->momentum();
103 
104  // TODO: this is an oversimplified implemetation
105  // the TOTEM smearing module should be taken as reference
106 
107  double th_x = mom.x() / mom.z();
108  double th_y = mom.y() / mom.z();
109 
110  if (mom.z() > 0.)
111  {
112  th_x += bd_x_45;
113  th_y += bd_y_45;
114  } else {
115  th_x += bd_x_56;
116  th_y += bd_y_56;
117  }
118 
119  // calculate consistent p_z component
120  const double sign = (mom.z() > 0.) ? 1. : -1.;
121  const double p_z = sign * mom.rho() / sqrt(1. + th_x*th_x + th_y*th_y);
122 
123  // set smeared momentum
124  (*part)->set_momentum(HepMC::FourVector(p_z * th_x, p_z * th_y, p_z, mom.e()));
125  }
126  }
127 
128  // save output
129  iEvent.put(std::move(pEvent));
130 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
double getBeamDivergenceX56() const
double getVtxStddevZ() const
double getVtxOffsetX45() const
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
double getBeamDivergenceX45() const
double getBeamDivergenceY56() const
T sqrt(T t)
Definition: SSEVec.h:18
edm::EDGetTokenT< edm::HepMCProduct > sourceToken_
double getVtxStddevX() const
double getBeamDivergenceY45() const
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
part
Definition: HCALResponse.h:20
double getVtxOffsetZ45() const
double getVtxOffsetY45() const
T get() const
Definition: EventSetup.h:71
StreamID streamID() const
Definition: Event.h:95
static unsigned int const shift
double getVtxStddevY() const
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

bool BeamDivergenceVtxGenerator::simulateBeamDivergence_
private

Definition at line 40 of file BeamDivergenceVtxGenerator.cc.

Referenced by produce().

bool BeamDivergenceVtxGenerator::simulateVertex_
private

Definition at line 39 of file BeamDivergenceVtxGenerator.cc.

Referenced by produce().

edm::EDGetTokenT<edm::HepMCProduct> BeamDivergenceVtxGenerator::sourceToken_
private

Definition at line 37 of file BeamDivergenceVtxGenerator.cc.

Referenced by produce().