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 hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () 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

edm::ESGetToken< CTPPSBeamParameters, CTPPSBeamParametersRcdbeamParametersToken_
 
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 28 of file BeamDivergenceVtxGenerator.cc.

Constructor & Destructor Documentation

◆ BeamDivergenceVtxGenerator()

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

Definition at line 60 of file BeamDivergenceVtxGenerator.cc.

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

206  {
207  // add vertex of the particle
208  HepMC::GenVertex *vtx = new HepMC::GenVertex(HepMC::FourVector(
209  (gp.vx() + sp.vtx_x) * 1E1, // conversion: cm to mm
210  (gp.vy() + sp.vtx_y) * 1E1,
211  (gp.vz() + sp.vtx_z) * 1E1,
212  (/*gp.vt()*/ +sp.vtx_t) * 1E1)); // TODO: GenParticle doesn't seem to have time component of the vertex
213  genEvt->add_vertex(vtx);
214 
215  // add the particle itself
216  HepMC::GenParticle *particle = new HepMC::GenParticle(smearMomentum(gp.p4(), sp), gp.pdgId(), gp.status());
217  vtx->add_particle_out(particle);

References TtGenEvtProducer_cfi::genEvt, GenParticle::GenParticle, runTauDisplay::gp, smearMomentum(), extraflags_cff::vtx, BeamDivergenceVtxGenerator::SmearingParameters::vtx_t, 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 184 of file BeamDivergenceVtxGenerator.cc.

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

References TtGenEvtProducer_cfi::genEvt, simulateBeamDivergence_, simulateVertex_, smearMomentum(), BeamDivergenceVtxGenerator::SmearingParameters::vtx_t, 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 84 of file BeamDivergenceVtxGenerator.cc.

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

References edm::ConfigurationDescriptions::add(), submitPVResolutionJobs::desc, and HLT_FULL_cff::InputTag.

◆ produce()

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

Definition at line 101 of file BeamDivergenceVtxGenerator.cc.

102  {
103  // get random engine
105  CLHEP::HepRandomEngine *rnd = &(rng->getEngine(iEvent.streamID()));
106 
107  // get conditions
109 
110  // get HepMC input (if given)
113  genEvt = new HepMC::GenEvent();
114  } else {
115  edm::Handle<edm::HepMCProduct> hepUnsmearedMCEvt;
116  iEvent.getByToken(sourceToken_, hepUnsmearedMCEvt);
117 
118  genEvt = new HepMC::GenEvent(*hepUnsmearedMCEvt->GetEvent());
119  }
120 
121  // prepare output
122  std::unique_ptr<edm::HepMCProduct> output(new edm::HepMCProduct(genEvt));
123 
124  // generate smearing parameters
125  SmearingParameters sp;
126 
127  if (simulateVertex_) {
128  // NB: the separtion between effective offsets in LHC sectors 45 and 56 cannot be applied, thus the values for 45 are used
129  sp.vtx_x = hBeamParameters->getVtxOffsetX45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevX();
130  sp.vtx_y = hBeamParameters->getVtxOffsetY45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevY();
131  sp.vtx_z = hBeamParameters->getVtxOffsetZ45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevZ();
132  sp.vtx_t = hBeamParameters->getVtxOffsetT45() + CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getVtxStddevT();
133  }
134 
136  sp.bd_x_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX45();
137  sp.bd_x_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceX56();
138  sp.bd_y_45 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY45();
139  sp.bd_y_56 = CLHEP::RandGauss::shoot(rnd) * hBeamParameters->getBeamDivergenceY56();
140  }
141 
142  // apply smearing
144 
145  for (const auto &token : genParticleTokens_) {
147  iEvent.getByToken(token, hGPCollection);
148 
149  for (const auto &gp : *hGPCollection)
151  }
152 
153  // save output
154  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, beamParametersToken_, TtGenEvtProducer_cfi::genEvt, genParticleTokens_, CTPPSBeamParameters::getBeamDivergenceX45(), CTPPSBeamParameters::getBeamDivergenceX56(), CTPPSBeamParameters::getBeamDivergenceY45(), CTPPSBeamParameters::getBeamDivergenceY56(), edm::RandomNumberGenerator::getEngine(), edm::HepMCProduct::GetEvent(), edm::EventSetup::getHandle(), CTPPSBeamParameters::getVtxOffsetT45(), CTPPSBeamParameters::getVtxOffsetX45(), CTPPSBeamParameters::getVtxOffsetY45(), CTPPSBeamParameters::getVtxOffsetZ45(), CTPPSBeamParameters::getVtxStddevT(), 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_t, 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 159 of file BeamDivergenceVtxGenerator.cc.

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

◆ beamParametersToken_

edm::ESGetToken<CTPPSBeamParameters, CTPPSBeamParametersRcd> BeamDivergenceVtxGenerator::beamParametersToken_
private

Definition at line 41 of file BeamDivergenceVtxGenerator.cc.

Referenced by produce().

◆ genParticleTokens_

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

Definition at line 42 of file BeamDivergenceVtxGenerator.cc.

Referenced by BeamDivergenceVtxGenerator(), and produce().

◆ simulateBeamDivergence_

bool BeamDivergenceVtxGenerator::simulateBeamDivergence_
private

Definition at line 45 of file BeamDivergenceVtxGenerator.cc.

Referenced by applySmearingHepMC(), and produce().

◆ simulateVertex_

bool BeamDivergenceVtxGenerator::simulateVertex_
private

Definition at line 44 of file BeamDivergenceVtxGenerator.cc.

Referenced by applySmearingHepMC(), and produce().

◆ sourceToken_

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

Definition at line 40 of file BeamDivergenceVtxGenerator.cc.

Referenced by BeamDivergenceVtxGenerator(), and produce().

CTPPSBeamParameters::getVtxStddevY
double getVtxStddevY() const
Definition: CTPPSBeamParameters.cc:83
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
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:64
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
CTPPSBeamParameters::getVtxOffsetZ45
double getVtxOffsetZ45() const
Definition: CTPPSBeamParameters.cc:75
part
part
Definition: HCALResponse.h:20
CTPPSBeamParameters::getBeamDivergenceY56
double getBeamDivergenceY56() const
Definition: CTPPSBeamParameters.cc:66
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CTPPSBeamParameters::getBeamDivergenceX45
double getBeamDivergenceX45() const
Definition: CTPPSBeamParameters.cc:63
BeamDivergenceVtxGenerator::beamParametersToken_
edm::ESGetToken< CTPPSBeamParameters, CTPPSBeamParametersRcd > beamParametersToken_
Definition: BeamDivergenceVtxGenerator.cc:41
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:159
edm::ESHandle< CTPPSBeamParameters >
BeamDivergenceVtxGenerator::sourceToken_
edm::EDGetTokenT< edm::HepMCProduct > sourceToken_
Definition: BeamDivergenceVtxGenerator.cc:40
CTPPSBeamParameters::getBeamDivergenceX56
double getBeamDivergenceX56() const
Definition: CTPPSBeamParameters.cc:65
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
CTPPSBeamParameters::getVtxOffsetY45
double getVtxOffsetY45() const
Definition: CTPPSBeamParameters.cc:74
BeamDivergenceVtxGenerator::addSmearedGenParticle
void addSmearedGenParticle(const reco::GenParticle &gp, const SmearingParameters &sp, HepMC::GenEvent *genEvt)
Definition: BeamDivergenceVtxGenerator.cc:203
edm::Service< edm::RandomNumberGenerator >
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:155
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:37
BeamDivergenceVtxGenerator::applySmearingHepMC
void applySmearingHepMC(const SmearingParameters &sp, HepMC::GenEvent *genEvt)
Definition: BeamDivergenceVtxGenerator.cc:184
CTPPSBeamParameters::getVtxOffsetX45
double getVtxOffsetX45() const
Definition: CTPPSBeamParameters.cc:73
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
CTPPSBeamParameters::getVtxStddevZ
double getVtxStddevZ() const
Definition: CTPPSBeamParameters.cc:84
CTPPSBeamParameters::getVtxOffsetT45
double getVtxOffsetT45() const
Definition: CTPPSBeamParameters.cc:76
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
cms::Exception
Definition: Exception.h:70
BeamDivergenceVtxGenerator::genParticleTokens_
std::vector< edm::EDGetTokenT< reco::GenParticleCollection > > genParticleTokens_
Definition: BeamDivergenceVtxGenerator.cc:42
edm::HepMCProduct
Definition: HepMCProduct.h:21
CTPPSBeamParameters::getVtxStddevT
double getVtxStddevT() const
Definition: CTPPSBeamParameters.cc:85
CTPPSBeamParameters::getVtxStddevX
double getVtxStddevX() const
Definition: CTPPSBeamParameters.cc:82
BeamDivergenceVtxGenerator::simulateVertex_
bool simulateVertex_
Definition: BeamDivergenceVtxGenerator.cc:44
edm::InputTag
Definition: InputTag.h:15
BeamDivergenceVtxGenerator::simulateBeamDivergence_
bool simulateBeamDivergence_
Definition: BeamDivergenceVtxGenerator.cc:45
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