CMS 3D CMS Logo

HiCentralityBiasFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HiCentralityBiasFilter
4 // Class: HiCentralityBiasFilter
5 //
13 //
14 // Original Author: Yetkin Yilmaz
15 // Created: Tue Aug 11 12:42:25 EDT 2009
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
35 
37 
39 
40 #include "CLHEP/Random/RandomEngine.h"
41 #include "HepMC/GenEvent.h"
42 #include "HepMC/HeavyIon.h"
43 #include "TF1.h"
44 
45 using namespace std;
46 
47 //
48 // class declaration
49 //
50 
52  public:
54  ~HiCentralityBiasFilter() override;
55 
56  private:
57  void beginJob() override ;
58  bool filter(edm::Event&, const edm::EventSetup&) override;
59  void endJob() override ;
60 
62 
64 
65  TF1* fBias_;
66  string func_;
67  vector<double> par_;
68 
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83 {
84  //now do what ever initialization is needed
85  hepmcSrc_ = consumes<edm::HepMCProduct>(iConfig.getParameter< edm::InputTag > ("generatorSmeared"));
86  func_ = iConfig.getParameter<string>("function");
87  par_ = iConfig.getParameter<vector<double> >("parameters");
88 }
89 
90 
92 {
93 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }
98 
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called on each new Event ------------
105 bool
107 {
108  using namespace edm;
109 
110 
111 
112  CLHEP::HepRandomEngine& engine = rng_->getEngine(iEvent.streamID());
113 
115  iEvent.getByToken(hepmcSrc_,mc);
116  const HepMC::GenEvent* evt = mc->GetEvent();
117 
118  const HepMC::HeavyIon* hi = evt->heavy_ion();
119  if(!hi) return false;
120 
121  double b = hi->impact_parameter();
122  double bound = fBias_->Eval(b);
123  double rand = engine.flat();
124  if(rand > bound) return false;
125 
126  return true;
127 
128 }
129 
130 // ------------ method called once each job just before starting event loop ------------
131 void
133 {
134 
135  fBias_ = new TF1("fBias",func_.data(),0,20);
136 
137  for(size_t ip = 0; ip < par_.size(); ++ip){
138  fBias_->SetParameter(ip,par_[ip]);
139  }
140 
141  double maxpoint = fBias_->GetMaximum(-0.1,20);
142  if(maxpoint < 0.9) throw cms::Exception("HeavyIonCentralityBias")<<"Input bias function is not optimized. Peak value is "<<maxpoint<<" which is required to be close to 1. Please fix the parameters before production."<<endl;
143 
144 
145 }
146 
147 // ------------ method called once each job just after ending the event loop ------------
148 void
150 }
151 
152 //define this as a plug-in
T getParameter(std::string const &) const
HiCentralityBiasFilter(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void beginJob()
Definition: Breakpoints.cc:14
edm::Service< edm::RandomNumberGenerator > rng_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::HepMCProduct > hepmcSrc_
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
double b
Definition: hdecay.h:120
HLT enums.
StreamID streamID() const
Definition: Event.h:95
Signal rand(Signal arg)
Definition: vlib.cc:442
bool filter(edm::Event &, const edm::EventSetup &) override