CMS 3D CMS Logo

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

Classes

struct  SmearingParameters
 

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 hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 

Private Member Functions

void addSmearedGenParticle (const reco::GenParticle &gp, const SmearingParameters &sp, HepMC::GenEvent *genEvt)
 
void applySmearingHepMC (const SmearingParameters &sp, HepMC::GenEvent *genEvt)
 

Static Private Member Functions

template<typename T >
static HepMC::FourVector smearMomentum (const T &mom, const SmearingParameters &sp)
 

Private Attributes

std::vector< edm::EDGetTokenT< reco::GenParticleCollection > > genParticleTokens_
 
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 27 of file BeamDivergenceVtxGenerator.cc.

Constructor & Destructor Documentation

◆ BeamDivergenceVtxGenerator()

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

Definition at line 58 of file BeamDivergenceVtxGenerator.cc.

60  : simulateVertex_(iConfig.getParameter<bool>("simulateVertex")),
61  simulateBeamDivergence_(iConfig.getParameter<bool>("simulateBeamDivergence")) {
62  const edm::InputTag tagSrcHepMC = iConfig.getParameter<edm::InputTag>("src");
63  if (!tagSrcHepMC.label().empty())
64  sourceToken_ = consumes<edm::HepMCProduct>(tagSrcHepMC);
65 
66  for (const auto &it : iConfig.getParameter<std::vector<edm::InputTag>>("srcGenParticle"))
67  genParticleTokens_.push_back(consumes<reco::GenParticleCollection>(it));
68 
70  if (!rng.isAvailable())
71  throw cms::Exception("Configuration")
72  << "The BeamDivergenceVtxGenerator requires the RandomNumberGeneratorService\n"
73  "which is not present in the configuration file. \n"
74  "You must add the service\n"
75  "in the configuration file or remove the modules that require it.";
76 
77  produces<edm::HepMCProduct>();

References genParticleTokens_, edm::ParameterSet::getParameter(), edm::Service< T >::isAvailable(), edm::InputTag::label(), and sourceToken_.

◆ ~BeamDivergenceVtxGenerator()

BeamDivergenceVtxGenerator::~BeamDivergenceVtxGenerator ( )
overridedefault

Member Function Documentation

◆ addSmearedGenParticle()

void BeamDivergenceVtxGenerator::addSmearedGenParticle ( const reco::GenParticle gp,
const SmearingParameters sp,
HepMC::GenEvent genEvt 
)
private

Definition at line 200 of file BeamDivergenceVtxGenerator.cc.

203  {
204  // add vertex of the particle
205  HepMC::GenVertex *vtx = new HepMC::GenVertex(HepMC::FourVector((gp.vx() + sp.vtx_x) * 1E1, // conversion: cm to mm
206  (gp.vy() + sp.vtx_y) * 1E1,
207  (gp.vz() + sp.vtx_z) * 1E1,
208  0.));
209  genEvt->add_vertex(vtx);
210 
211  // add the particle itself
212  HepMC::GenParticle *particle = new HepMC::GenParticle(smearMomentum(gp.p4(), sp), gp.pdgId(), gp.status());
213  vtx->add_particle_out(particle);

References TtGenEvtProducer_cfi::genEvt, GenParticle::GenParticle, runTauDisplay::gp, smearMomentum(), badGlobalMuonTaggersAOD_cff::vtx, BeamDivergenceVtxGenerator::SmearingParameters::vtx_x, BeamDivergenceVtxGenerator::SmearingParameters::vtx_y, and BeamDivergenceVtxGenerator::SmearingParameters::vtx_z.

Referenced by produce().

◆ applySmearingHepMC()

void BeamDivergenceVtxGenerator::applySmearingHepMC ( const SmearingParameters sp,
HepMC::GenEvent genEvt 
)
private

Definition at line 181 of file BeamDivergenceVtxGenerator.cc.

182  {
183  if (simulateVertex_) {
184  for (HepMC::GenEvent::vertex_iterator vit = genEvt->vertices_begin(); vit != genEvt->vertices_end(); ++vit) {
185  const auto &pos = (*vit)->position();
186  (*vit)->set_position(HepMC::FourVector(pos.x() + sp.vtx_x * 1E1, // conversion: cm to mm
187  pos.y() + sp.vtx_y * 1E1,
188  pos.z() + sp.vtx_z * 1E1,
189  pos.t()));
190  }
191  }
192 
194  for (HepMC::GenEvent::particle_iterator part = genEvt->particles_begin(); part != genEvt->particles_end(); ++part)
195  (*part)->set_momentum(smearMomentum((*part)->momentum(), sp));
196  }

References TtGenEvtProducer_cfi::genEvt, simulateBeamDivergence_, simulateVertex_, smearMomentum(), BeamDivergenceVtxGenerator::SmearingParameters::vtx_x, BeamDivergenceVtxGenerator::SmearingParameters::vtx_y, and BeamDivergenceVtxGenerator::SmearingParameters::vtx_z.

Referenced by produce().

◆ fillDescriptions()

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

Definition at line 81 of file BeamDivergenceVtxGenerator.cc.

82  {
84 
85  desc.add<edm::InputTag>("src", edm::InputTag("generator", "unsmeared"))
86  ->setComment("input collection in HepMC format");
87 
88  desc.add<std::vector<edm::InputTag>>("srcGenParticle", std::vector<edm::InputTag>())
89  ->setComment("input collections in GenParticle format");
90 
91  desc.add<bool>("simulateBeamDivergence", true)->setComment("account for the beam angular divergence?");
92  desc.add<bool>("simulateVertex", true)->setComment("account for the vertex transverse smearing?");
93 
94  descriptions.add("beamDivergenceVtxGenerator", desc);

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), and HLT_2018_cff::InputTag.

◆ produce()

void BeamDivergenceVtxGenerator::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 98 of file BeamDivergenceVtxGenerator.cc.

99  {
100  // get random engine
102  CLHEP::HepRandomEngine *rnd = &(rng->getEngine(iEvent.streamID()));
103 
104  // get conditions
105  edm::ESHandle<CTPPSBeamParameters> hBeamParameters;
106  iSetup.get<CTPPSBeamParametersRcd>().get(hBeamParameters);
107 
108  // get HepMC input (if given)
111  genEvt = new HepMC::GenEvent();
112  } else {
113  edm::Handle<edm::HepMCProduct> hepUnsmearedMCEvt;
114  iEvent.getByToken(sourceToken_, hepUnsmearedMCEvt);
115 
116  genEvt = new HepMC::GenEvent(*hepUnsmearedMCEvt->GetEvent());
117  }
118 
119  // prepare output
120  std::unique_ptr<edm::HepMCProduct> output(new edm::HepMCProduct(genEvt));
121 
122  // generate smearing parameters
123  SmearingParameters sp;
124 
125  if (simulateVertex_) {
126  // NB: the separtion between effective offsets in LHC sectors 45 and 56 cannot be applied, thus the values for 45 are used
127  sp.vtx_x = hBeamParameters->getVtxOffsetX45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevX();
128  sp.vtx_y = hBeamParameters->getVtxOffsetY45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevY();
129  sp.vtx_z = hBeamParameters->getVtxOffsetZ45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevZ();
130  }
131 
133  sp.bd_x_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX45();
134  sp.bd_x_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX56();
135  sp.bd_y_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY45();
136  sp.bd_y_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY56();
137  }
138 
139  // apply smearing
141 
142  for (const auto &token : genParticleTokens_) {
144  iEvent.getByToken(token, hGPCollection);
145 
146  for (const auto &gp : *hGPCollection)
148  }
149 
150  // save output
151  iEvent.put(std::move(output));

References addSmearedGenParticle(), applySmearingHepMC(), BeamDivergenceVtxGenerator::SmearingParameters::bd_x_45, BeamDivergenceVtxGenerator::SmearingParameters::bd_x_56, BeamDivergenceVtxGenerator::SmearingParameters::bd_y_45, BeamDivergenceVtxGenerator::SmearingParameters::bd_y_56, TtGenEvtProducer_cfi::genEvt, genParticleTokens_, edm::EventSetup::get(), get, CTPPSBeamParameters::getBeamDivergenceX45(), CTPPSBeamParameters::getBeamDivergenceX56(), CTPPSBeamParameters::getBeamDivergenceY45(), CTPPSBeamParameters::getBeamDivergenceY56(), edm::RandomNumberGenerator::getEngine(), edm::HepMCProduct::GetEvent(), CTPPSBeamParameters::getVtxOffsetX45(), CTPPSBeamParameters::getVtxOffsetY45(), CTPPSBeamParameters::getVtxOffsetZ45(), CTPPSBeamParameters::getVtxStddevX(), CTPPSBeamParameters::getVtxStddevY(), CTPPSBeamParameters::getVtxStddevZ(), runTauDisplay::gp, iEvent, edm::EDGetTokenT< T >::isUninitialized(), eostools::move(), convertSQLitetoXML_cfg::output, simulateBeamDivergence_, simulateVertex_, sourceToken_, unpackBuffers-CaloStage2::token, BeamDivergenceVtxGenerator::SmearingParameters::vtx_x, BeamDivergenceVtxGenerator::SmearingParameters::vtx_y, and BeamDivergenceVtxGenerator::SmearingParameters::vtx_z.

◆ smearMomentum()

template<typename T >
HepMC::FourVector BeamDivergenceVtxGenerator::smearMomentum ( const T mom,
const SmearingParameters sp 
)
staticprivate

Definition at line 156 of file BeamDivergenceVtxGenerator.cc.

157  {
158  // TODO: this is an oversimplified implemetation
159  // the TOTEM smearing module should be taken as reference
160 
161  double th_x = mom.x() / mom.z();
162  double th_y = mom.y() / mom.z();
163 
164  if (mom.z() > 0.) {
165  th_x += sp.bd_x_45;
166  th_y += sp.bd_y_45;
167  } else {
168  th_x += sp.bd_x_56;
169  th_y += sp.bd_y_56;
170  }
171 
172  // calculate consistent p_z component
173  const double sign = (mom.z() > 0.) ? 1. : -1.;
174  const double p = sqrt(mom.x() * mom.x() + mom.y() * mom.y() + mom.z() * mom.z());
175  const double p_z = sign * p / sqrt(1. + th_x * th_x + th_y * th_y);
176 
177  return HepMC::FourVector(p_z * th_x, p_z * th_y, p_z, mom.e());

References BeamDivergenceVtxGenerator::SmearingParameters::bd_x_45, BeamDivergenceVtxGenerator::SmearingParameters::bd_x_56, BeamDivergenceVtxGenerator::SmearingParameters::bd_y_45, BeamDivergenceVtxGenerator::SmearingParameters::bd_y_56, AlCaHLTBitMon_ParallelJobs::p, Validation_hcalonly_cfi::sign, and mathSSE::sqrt().

Referenced by addSmearedGenParticle(), and applySmearingHepMC().

Member Data Documentation

◆ genParticleTokens_

std::vector<edm::EDGetTokenT<reco::GenParticleCollection> > BeamDivergenceVtxGenerator::genParticleTokens_
private

Definition at line 40 of file BeamDivergenceVtxGenerator.cc.

Referenced by BeamDivergenceVtxGenerator(), and produce().

◆ simulateBeamDivergence_

bool BeamDivergenceVtxGenerator::simulateBeamDivergence_
private

Definition at line 43 of file BeamDivergenceVtxGenerator.cc.

Referenced by applySmearingHepMC(), and produce().

◆ simulateVertex_

bool BeamDivergenceVtxGenerator::simulateVertex_
private

Definition at line 42 of file BeamDivergenceVtxGenerator.cc.

Referenced by applySmearingHepMC(), and produce().

◆ sourceToken_

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

Definition at line 39 of file BeamDivergenceVtxGenerator.cc.

Referenced by BeamDivergenceVtxGenerator(), and produce().

CTPPSBeamParameters::getVtxStddevY
double getVtxStddevY() const
Definition: CTPPSBeamParameters.cc:78
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
pos
Definition: PixelAliasList.h:18
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
edm::Handle< edm::HepMCProduct >
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
CTPPSBeamParameters::getBeamDivergenceY45
double getBeamDivergenceY45() const
Definition: CTPPSBeamParameters.cc:61
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
CTPPSBeamParameters::getVtxOffsetZ45
double getVtxOffsetZ45() const
Definition: CTPPSBeamParameters.cc:72
part
part
Definition: HCALResponse.h:20
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
CTPPSBeamParameters::getBeamDivergenceY56
double getBeamDivergenceY56() const
Definition: CTPPSBeamParameters.cc:63
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CTPPSBeamParameters::getBeamDivergenceX45
double getBeamDivergenceX45() const
Definition: CTPPSBeamParameters.cc:60
edm::EDGetTokenT::isUninitialized
bool isUninitialized() const
Definition: EDGetToken.h:70
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
BeamDivergenceVtxGenerator::smearMomentum
static HepMC::FourVector smearMomentum(const T &mom, const SmearingParameters &sp)
Definition: BeamDivergenceVtxGenerator.cc:156
edm::ESHandle< CTPPSBeamParameters >
BeamDivergenceVtxGenerator::sourceToken_
edm::EDGetTokenT< edm::HepMCProduct > sourceToken_
Definition: BeamDivergenceVtxGenerator.cc:39
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
CTPPSBeamParameters::getBeamDivergenceX56
double getBeamDivergenceX56() const
Definition: CTPPSBeamParameters.cc:62
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
CTPPSBeamParameters::getVtxOffsetY45
double getVtxOffsetY45() const
Definition: CTPPSBeamParameters.cc:71
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
BeamDivergenceVtxGenerator::addSmearedGenParticle
void addSmearedGenParticle(const reco::GenParticle &gp, const SmearingParameters &sp, HepMC::GenEvent *genEvt)
Definition: BeamDivergenceVtxGenerator.cc:200
edm::Service< edm::RandomNumberGenerator >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
get
#define get
BeamDivergenceVtxGenerator::applySmearingHepMC
void applySmearingHepMC(const SmearingParameters &sp, HepMC::GenEvent *genEvt)
Definition: BeamDivergenceVtxGenerator.cc:181
CTPPSBeamParameters::getVtxOffsetX45
double getVtxOffsetX45() const
Definition: CTPPSBeamParameters.cc:70
CTPPSBeamParametersRcd
Definition: CTPPSBeamParametersRcd.h:14
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
CTPPSBeamParameters::getVtxStddevZ
double getVtxStddevZ() const
Definition: CTPPSBeamParameters.cc:79
cms::Exception
Definition: Exception.h:70
BeamDivergenceVtxGenerator::genParticleTokens_
std::vector< edm::EDGetTokenT< reco::GenParticleCollection > > genParticleTokens_
Definition: BeamDivergenceVtxGenerator.cc:40
edm::HepMCProduct
Definition: HepMCProduct.h:18
CTPPSBeamParameters::getVtxStddevX
double getVtxStddevX() const
Definition: CTPPSBeamParameters.cc:77
BeamDivergenceVtxGenerator::simulateVertex_
bool simulateVertex_
Definition: BeamDivergenceVtxGenerator.cc:42
edm::InputTag
Definition: InputTag.h:15
BeamDivergenceVtxGenerator::simulateBeamDivergence_
bool simulateBeamDivergence_
Definition: BeamDivergenceVtxGenerator.cc:43
TtGenEvtProducer_cfi.genEvt
genEvt
Definition: TtGenEvtProducer_cfi.py:7
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
reco::vertex_iterator
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Definition: VertexFwd.h:19