CMS 3D CMS Logo

GaussianZBeamSpotFilter.cc
Go to the documentation of this file.
2 
4 
8 
10 
11 #include "HepMC/GenRanges.h"
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
13 #include "CLHEP/Random/RandomEngine.h"
14 
16  src_(iPSet.getParameter<edm::InputTag>("src")),
17  baseSZ_(iPSet.getParameter<double>("baseSZ")*cm),
18  baseZ0_(iPSet.getParameter<double>("baseZ0")*cm),
19  newSZ_(iPSet.getParameter<double>("newSZ")*cm),
20  newZ0_(iPSet.getParameter<double>("newZ0")*cm)
21 {
23  if ( ! rng.isAvailable()) {
24  throw cms::Exception("Configuration")
25  << "The GaussianZBeamSpotFilter requires the RandomNumberGeneratorService\n"
26  "which is not present in the configuration file. You must add the service\n"
27  "in the configuration file or remove the modules that require it.";
28  }
29 
30  if ( baseZ0_ != newZ0_ ) {
31  edm::LogError("InconsistentZPosition") << "Z0 : old " << baseZ0_ << " and new " << newZ0_ << " are different";
32  }
33 
34  if ( baseSZ_ < newSZ_ ) {
35  edm::LogError("InconsistentZSigma") << "Sigma Z : old " << baseSZ_ << " smaller than new " << newSZ_ ;
36  }
37 
38 }
39 
41 
43 {
44 
45  bool pass = true;
46 
48  CLHEP::HepRandomEngine& engine = rng->getEngine(iEvent.streamID());
49 
51 
52  iEvent.getByLabel( src_, HepMCEvt ) ;
53 
54  // HepMCEvt->GetEvent()->print();
55 
56  HepMC::GenEvent::vertex_const_iterator vitr= HepMCEvt->GetEvent()->vertex_range().begin();
57 
58  if ( vitr != HepMCEvt->GetEvent()->vertex_range().end() ) {
59 
60  double vtxZ = (*vitr)->point3d().z();
61  double gaussRatio = std::exp(-(vtxZ-newZ0_)*(vtxZ-newZ0_)/(2.0*newSZ_*newSZ_)+(vtxZ-baseZ0_)*(vtxZ-baseZ0_)/(2.0*baseSZ_*baseSZ_));
62  if ( engine.flat() > gaussRatio ) { pass = false; }
63  // std::cout << "base sigmaZ = " << baseSZ_ << " new sigmaZ = " << newSZ_ << " vtxZ = " << vtxZ << " gaussian ratio = " << gaussRatio << " pass = " << pass << std::endl;
64 
65  }
66 
67  return pass;
68 
69 }
70 
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
int iEvent
Definition: GenABIO.cc:224
bool isAvailable() const
Definition: Service.h:40
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
bool filter(edm::Event &, const edm::EventSetup &) override
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
GaussianZBeamSpotFilter(const edm::ParameterSet &)
HLT enums.
StreamID streamID() const
Definition: Event.h:95