CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LHEProducer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <memory>
3 
4 #include <boost/shared_ptr.hpp>
5 #include <sigc++/signal.h>
6 
7 #include <HepMC/GenEvent.h>
8 #include <HepMC/SimpleVector.h>
9 
16 
20 
23 
30 
31 using namespace lhef;
32 
33 class LHEProducer : public edm::EDFilter {
34  public:
35  explicit LHEProducer(const edm::ParameterSet &params);
36  virtual ~LHEProducer();
37 
38  protected:
39  virtual void beginJob();
40  virtual void endJob();
41  virtual bool beginRun(edm::Run &run, const edm::EventSetup &es);
42  virtual bool endRun(edm::Run &run, const edm::EventSetup &es);
43  virtual bool filter(edm::Event &event, const edm::EventSetup &es);
44 
45  private:
46  double matching(const HepMC::GenEvent *event, bool shower) const;
47 
48  bool showeredEvent(const boost::shared_ptr<HepMC::GenEvent> &event);
49  void onInit();
50  void onBeforeHadronisation();
51 
52  unsigned int eventsToPrint;
53  std::vector<int> removeResonances;
54  std::auto_ptr<Hadronisation> hadronisation;
55  std::auto_ptr<JetMatching> jetMatching;
56 
57  double extCrossSect;
58  double extFilterEff;
60 
61  boost::shared_ptr<LHEEvent> partonLevel;
62  boost::shared_ptr<LHERunInfo> runInfo;
63  unsigned int index;
65  double weight;
67 };
68 
70  eventsToPrint(params.getUntrackedParameter<unsigned int>("eventsToPrint", 0)),
71  extCrossSect(params.getUntrackedParameter<double>("crossSection", -1.0)),
72  extFilterEff(params.getUntrackedParameter<double>("filterEfficiency", -1.0)),
73  matchSummary(false)
74 {
76  params.getParameter<edm::ParameterSet>("hadronisation"));
77 
78  if (params.exists("removeResonances"))
80  params.getParameter<std::vector<int> >(
81  "removeResonances");
82 
83  std::set<std::string> matchingCapabilities;
84  if (params.exists("jetMatching")) {
85  edm::ParameterSet jetParams =
87  "jetMatching");
88  jetMatching = JetMatching::create(jetParams);
89 
90  matchingCapabilities = jetMatching->capabilities();
91  hadronisation->matchingCapabilities(matchingCapabilities);
92  }
93 
94  produces<edm::HepMCProduct>();
95  produces<GenEventInfoProduct>();
96  produces<GenRunInfoProduct, edm::InRun>();
97 
98  if (jetMatching.get()) {
99  if (params.getUntrackedParameter<bool>(
100  "preferShowerVetoCallback", true))
101  hadronisation->onShoweredEvent().connect(
102  sigc::mem_fun(*this,
104  hadronisation->onInit().connect(
105  sigc::mem_fun(*this, &LHEProducer::onInit));
106  hadronisation->onBeforeHadronisation().connect(
107  sigc::mem_fun(*this,
109 
110  matchSummary = matchingCapabilities.count("matchSummary");
111  if (matchSummary) {
112  produces< std::vector<double> >("matchDeltaR");
113  produces< std::vector<double> >("matchDeltaPRel");
114  }
115  }
116 
117  // force total branching ratio for QCD/QED to 1
118  for(int i = 0; i < 6; i++)
120  for(int i = 9; i < 23; i++)
122 }
123 
125 {
126 }
127 
129 {
130  hadronisation->init();
131 }
132 
134 {
135  hadronisation.reset();
136  jetMatching.reset();
137 }
138 
140 {
142  run.getByLabel("source", product);
143 
144  runInfo.reset(new LHERunInfo(*product));
145  index = 0;
146 
147  return true;
148 }
149 
151 {
152  hadronisation->statistics();
153 
155  if (runInfo) {
156  crossSection = runInfo->xsec();
157  runInfo->statistics();
158  }
159 
160  std::auto_ptr<GenRunInfoProduct> runInfo(new GenRunInfoProduct);
161 
162  runInfo->setInternalXSec(
163  GenRunInfoProduct::XSec(crossSection.value,
164  crossSection.error));
165  runInfo->setExternalXSecLO(extCrossSect);
166  runInfo->setFilterEfficiency(extFilterEff);
167 
168  run.put(runInfo);
169 
170  runInfo.reset();
171 
172  return true;
173 }
174 
176 {
177  std::auto_ptr<edm::HepMCProduct> result(new edm::HepMCProduct);
178 
180  event.getByLabel("source", product);
181 
182  partonLevel.reset(new LHEEvent(runInfo, *product));
183  if (!removeResonances.empty())
184  partonLevel->removeResonances(removeResonances);
185 
186  if (product->pdf())
187  partonLevel->setPDF(
188  std::auto_ptr<LHEEvent::PDF>(
189  new LHEEvent::PDF(*product->pdf())));
190 
191  hadronisation->setEvent(partonLevel);
192 
193  double br = branchingRatios.getFactor(hadronisation.get(),
194  partonLevel);
195 
196  matchingDone = false;
197  weight = 1.0;
198  std::auto_ptr<HepMC::GenEvent> hadronLevel(hadronisation->hadronize());
199 
200  if (!hadronLevel.get()) {
201  if (matchingDone) {
202  if (weight == 0.0)
203  partonLevel->count(LHERunInfo::kSelected, br);
204  else
205  partonLevel->count(LHERunInfo::kKilled,
206  br, weight);
207  } else
208  partonLevel->count(LHERunInfo::kTried, br);
209  }
210 
211  if (!matchingDone && jetMatching.get() && hadronLevel.get())
212  weight = matching(hadronLevel.get(), false);
213 
214  if (weight == 0.0) {
215  edm::LogInfo("Generator|LHEInterface")
216  << "Event got rejected by the "
217  "jet matching." << std::endl;
218 
219  if (hadronLevel.get()) {
220  partonLevel->count(LHERunInfo::kSelected);
221  hadronLevel.reset();
222  }
223  }
224 
225  if (!hadronLevel.get()) {
226  event.put(result);
227  std::auto_ptr<GenEventInfoProduct> info(
228  new GenEventInfoProduct);
229  event.put(info);
230  return false;
231  }
232 
233  partonLevel->count(LHERunInfo::kAccepted, br, weight);
234 
235  hadronLevel->set_event_number(++index);
236 
237  if (eventsToPrint) {
238  eventsToPrint--;
239  hadronLevel->print();
240  }
241 
242  std::auto_ptr<GenEventInfoProduct> info(
243  new GenEventInfoProduct(hadronLevel.get()));
244  result->addHepMCData(hadronLevel.release());
245  event.put(result);
246  event.put(info);
247 
248  if (jetMatching.get() && matchSummary) {
249  std::auto_ptr< std::vector<double> > matchDeltaR(
250  new std::vector<double>);
251  std::auto_ptr< std::vector<double> > matchDeltaPRel(
252  new std::vector<double>);
253 
254  typedef std::vector<JetMatching::JetPartonMatch> Matches;
255  Matches matches = jetMatching->getMatchSummary();
256 
257  for(Matches::const_iterator iter = matches.begin();
258  iter != matches.end(); ++iter) {
259  if (!iter->isMatch())
260  continue;
261 
262  matchDeltaR->push_back(iter->delta);
263  matchDeltaPRel->push_back(iter->jet.rho() /
264  iter->parton.rho() - 1.0);
265  }
266 
267  event.put(matchDeltaR, "matchDeltaR");
268  event.put(matchDeltaPRel, "matchDeltaPRel");
269  }
270 
271  return true;
272 }
273 
274 double LHEProducer::matching(const HepMC::GenEvent *event, bool shower) const
275 {
276  if (!jetMatching.get())
277  return 1.0;
278 
279  return jetMatching->match(partonLevel->asHepMCEvent().get(),
280  event, shower);
281 }
282 
283 bool LHEProducer::showeredEvent(const boost::shared_ptr<HepMC::GenEvent> &event)
284 {
285  weight = matching(event.get(), true);
286  matchingDone = true;
287  return weight == 0.0;
288 }
289 
291 {
292  jetMatching->init(runInfo);
293 }
294 
296 {
297  jetMatching->beforeHadronisation(partonLevel);
298 }
299 
301 
T getParameter(std::string const &) const
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:174
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void set(int pdgId, bool both=true, double value=1.0)
double extFilterEff
Definition: LHEProducer.cc:58
virtual bool filter(edm::Event &event, const edm::EventSetup &es)
Definition: LHEProducer.cc:175
double extCrossSect
Definition: LHEProducer.cc:57
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double getFactor(const Hadronisation *hadronisation, const boost::shared_ptr< LHEEvent > &event) const
virtual void endJob()
Definition: LHEProducer.cc:133
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual ~LHEProducer()
Definition: LHEProducer.cc:124
void beginJob()
Definition: Breakpoints.cc:15
std::vector< int > removeResonances
Definition: LHEProducer.cc:53
double weight
Definition: LHEProducer.cc:65
BranchingRatios branchingRatios
Definition: LHEProducer.cc:66
virtual bool endRun(edm::Run &run, const edm::EventSetup &es)
Definition: LHEProducer.cc:150
void onBeforeHadronisation()
Definition: LHEProducer.cc:295
tuple result
Definition: query.py:137
LHEProducer(const edm::ParameterSet &params)
Definition: LHEProducer.cc:69
double matching(const HepMC::GenEvent *event, bool shower) const
Definition: LHEProducer.cc:274
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool matchingDone
Definition: LHEProducer.cc:64
boost::shared_ptr< LHEEvent > partonLevel
Definition: LHEProducer.cc:61
bool matchSummary
Definition: LHEProducer.cc:59
void onInit()
Definition: LHEProducer.cc:290
#define DEFINE_LHE_JETMATCHING_PLUGIN(T)
Definition: JetMatching.h:79
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
virtual void beginJob()
Definition: LHEProducer.cc:128
std::auto_ptr< JetMatching > jetMatching
Definition: LHEProducer.cc:55
unsigned int index
Definition: LHEProducer.cc:63
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:79
virtual bool beginRun(edm::Run &run, const edm::EventSetup &es)
Definition: LHEProducer.cc:139
boost::shared_ptr< LHERunInfo > runInfo
Definition: LHEProducer.cc:62
unsigned int eventsToPrint
Definition: LHEProducer.cc:52
std::auto_ptr< Hadronisation > hadronisation
Definition: LHEProducer.cc:54
SurfaceDeformation * create(int type, const std::vector< double > &params)
bool showeredEvent(const boost::shared_ptr< HepMC::GenEvent > &event)
Definition: LHEProducer.cc:283
Definition: Run.h:31