CMS 3D CMS Logo

BeamDivergenceVtxGenerator.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
16 
18 
21 
22 #include <CLHEP/Random/RandGauss.h>
23 
24 //----------------------------------------------------------------------------------------------------
25 
27 {
28  public:
30  ~BeamDivergenceVtxGenerator() override = default;
31 
33 
34  void produce(edm::Event&, const edm::EventSetup&) override;
35 
36  private:
38 
41 };
42 
43 //----------------------------------------------------------------------------------------------------
44 
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 }
60 
61 //----------------------------------------------------------------------------------------------------
62 
63 void
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 }
131 
132 //----------------------------------------------------------------------------------------------------
133 
134 void
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 }
145 
146 //----------------------------------------------------------------------------------------------------
147 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
static void fillDescriptions(edm::ConfigurationDescriptions &)
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
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T sqrt(T t)
Definition: SSEVec.h:18
bool isAvailable() const
Definition: Service.h:40
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
BeamDivergenceVtxGenerator(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~BeamDivergenceVtxGenerator() override=default
double getVtxOffsetZ45() const
HLT enums.
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
void produce(edm::Event &, const edm::EventSetup &) override