CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeneratorFilter.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 
5 // class template GeneratorFilter<HAD> provides an EDFilter which uses
6 // the hadronizer type HAD to generate partons, hadronize them, and
7 // decay the resulting particles, in the CMS framework.
8 
9 #ifndef gen_GeneratorFilter_h
10 #define gen_GeneratorFilter_h
11 
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
27 
28 // #include "GeneratorInterface/ExternalDecays/interface/ExternalDecayDriver.h"
29 
30 //#include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
35 
36 namespace edm
37 {
38  template <class HAD, class DEC> class GeneratorFilter : public one::EDFilter<EndRunProducer,
39  EndLuminosityBlockProducer,
40  one::WatchLuminosityBlocks,
41  one::SharedResources>
42  {
43  public:
44  typedef HAD Hadronizer;
45  typedef DEC Decayer;
46 
47  // The given ParameterSet will be passed to the contained
48  // Hadronizer object.
49  explicit GeneratorFilter(ParameterSet const& ps);
50 
51  virtual ~GeneratorFilter();
52 
53  virtual bool filter(Event& e, EventSetup const& es) override;
54  virtual void endRunProduce(Run &, EventSetup const&) override;
55  virtual void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
56  virtual void endLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
57  virtual void endLuminosityBlockProduce(LuminosityBlock &, EventSetup const&) override;
58 
59  private:
61  //gen::ExternalDecayDriver* decayer_;
63  unsigned int nEventsInLumiBlock_;
64  };
65 
66  //------------------------------------------------------------------------
67  //
68  // Implementation
69 
70  template <class HAD, class DEC>
72  EDFilter(),
73  hadronizer_(ps),
74  decayer_(0),
75  nEventsInLumiBlock_(0)
76  {
77  // TODO:
78  // Put the list of types produced by the filters here.
79  // The current design calls for:
80  // * GenRunInfoProduct
81  // * HepMCProduct
82  //
83  // other maybe added as needs be
84  //
85 
86  std::vector<std::string> const& sharedResources = hadronizer_.sharedResources();
87  for(auto const& resource : sharedResources) {
88  usesResource(resource);
89  }
90 
91  if ( ps.exists("ExternalDecays") )
92  {
93  //decayer_ = new gen::ExternalDecayDriver(ps.getParameter<ParameterSet>("ExternalDecays"));
94  ParameterSet ps1 = ps.getParameter<ParameterSet>("ExternalDecays");
95  decayer_ = new Decayer(ps1);
96 
97  std::vector<std::string> const& sharedResourcesDec = decayer_->sharedResources();
98  for(auto const& resource : sharedResourcesDec) {
99  usesResource(resource);
100  }
101  }
102  // This handles the case where there are no shared resources, because you
103  // have to declare something when the SharedResources template parameter was used.
104  if(sharedResources.empty() && (!decayer_ || decayer_->sharedResources().empty())) {
105  usesResource(edm::uniqueSharedResourceName());
106  }
107 
108  produces<edm::HepMCProduct>("unsmeared");
109  produces<GenEventInfoProduct>();
110  produces<GenLumiInfoProduct, edm::InLumi>();
111  produces<GenRunInfoProduct, edm::InRun>();
112 
113  }
114 
115  template <class HAD, class DEC>
117  { if ( decayer_ ) delete decayer_;}
118 
119  template <class HAD, class DEC>
120  bool
122  {
123  RandomEngineSentry<HAD> randomEngineSentry(&hadronizer_, ev.streamID());
124  RandomEngineSentry<DEC> randomEngineSentryDecay(decayer_, ev.streamID());
125 
126  //added for selecting/filtering gen events, in the case of hadronizer+externalDecayer
127 
128  bool passEvtGenSelector = false;
129  std::auto_ptr<HepMC::GenEvent> event(0);
130 
131  while(!passEvtGenSelector)
132  {
133  event.reset();
134  hadronizer_.setEDMEvent(ev);
135 
136  if ( !hadronizer_.generatePartonsAndHadronize() ) return false;
137 
138  // this is "fake" stuff
139  // in principle, decays are done as part of full event generation,
140  // except for particles that are marked as to be kept stable
141  // but we currently keep in it the design, because we might want
142  // to use such feature for other applications
143  //
144  if ( !hadronizer_.decay() ) return false;
145 
146  event = std::auto_ptr<HepMC::GenEvent>(hadronizer_.getGenEvent());
147  if ( !event.get() ) return false;
148 
149  // The external decay driver is being added to the system,
150  // it should be called here
151  //
152  if ( decayer_ )
153  {
154  event.reset( decayer_->decay( event.get() ) );
155  }
156  if ( !event.get() ) return false;
157 
158  passEvtGenSelector = hadronizer_.select( event.get() );
159 
160  }
161  // check and perform if there're any unstable particles after
162  // running external decay packages
163  //
164  // fisrt of all, put back modified event tree (after external decay)
165  //
166  hadronizer_.resetEvent( event.release() );
167 
168  //
169  // now run residual decays
170  //
171  if ( !hadronizer_.residualDecay() ) return false;
172 
173  hadronizer_.finalizeEvent();
174 
175  event.reset( hadronizer_.getGenEvent() );
176  if ( !event.get() ) return false;
177 
178  event->set_event_number( ev.id().event() );
179 
180  //
181  // tutto bene - finally, form up EDM products !
182  //
183  std::auto_ptr<GenEventInfoProduct> genEventInfo(hadronizer_.getGenEventInfo());
184  if (!genEventInfo.get())
185  {
186  // create GenEventInfoProduct from HepMC event in case hadronizer didn't provide one
187  genEventInfo.reset(new GenEventInfoProduct(event.get()));
188  }
189  ev.put(genEventInfo);
190 
191  std::auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
192  bare_product->addHepMCData( event.release() );
193  ev.put(bare_product, "unsmeared");
194  nEventsInLumiBlock_ ++;
195  return true;
196  }
197 
198  template <class HAD, class DEC>
199  void
201  {
202  // If relevant, record the integrated luminosity for this run
203  // here. To do so, we would need a standard function to invoke on
204  // the contained hadronizer that would report the integrated
205  // luminosity.
206 
207  hadronizer_.statistics();
208 
209  if ( decayer_ ) decayer_->statistics();
210 
211  std::auto_ptr<GenRunInfoProduct> griproduct(new GenRunInfoProduct(hadronizer_.getGenRunInfo()));
212  r.put(griproduct);
213  }
214 
215  template <class HAD, class DEC>
216  void
218  {
219  nEventsInLumiBlock_ = 0;
220  RandomEngineSentry<HAD> randomEngineSentry(&hadronizer_, lumi.index());
221  RandomEngineSentry<DEC> randomEngineSentryDecay(decayer_, lumi.index());
222 
223  if ( !hadronizer_.readSettings(0) )
225  << "Failed to read settings for the hadronizer "
226  << hadronizer_.classname() << " \n";
227 
228  if ( decayer_ )
229  {
230  decayer_->init(es);
231  if ( !hadronizer_.declareStableParticles( decayer_->operatesOnParticles() ) )
233  << "Failed to declare stable particles in hadronizer "
234  << hadronizer_.classname()
235  << "\n";
236  if ( !hadronizer_.declareSpecialSettings( decayer_->specialSettings() ) )
238  << "Failed to declare special settings in hadronizer "
239  << hadronizer_.classname()
240  << "\n";
241  }
242 
243  if ( !hadronizer_.initializeForInternalPartons() )
245  << "Failed to initialize hadronizer "
246  << hadronizer_.classname()
247  << " for internal parton generation\n";
248  }
249 
250  template <class HAD, class DEC>
251  void
253  {}
254 
255  template <class HAD, class DEC>
256  void
258  {
259  hadronizer_.statistics();
260  if ( decayer_ ) decayer_->statistics();
261 
262  GenRunInfoProduct genRunInfo = GenRunInfoProduct(hadronizer_.getGenRunInfo());
263  std::vector<GenLumiInfoProduct::ProcessInfo> GenLumiProcess;
264  GenRunInfoProduct::XSec xsec = genRunInfo.internalXSec();
266  temp.setProcess(0);
267  temp.setLheXSec(xsec.value(), xsec.error()); // Pythia gives error of -1
268  temp.setNPassPos(nEventsInLumiBlock_);
269  temp.setNPassNeg(0);
270  temp.setNTotalPos(nEventsInLumiBlock_);
271  temp.setNTotalNeg(0);
272  temp.setTried(nEventsInLumiBlock_, nEventsInLumiBlock_, nEventsInLumiBlock_);
273  temp.setSelected(nEventsInLumiBlock_, nEventsInLumiBlock_, nEventsInLumiBlock_);
274  temp.setKilled(nEventsInLumiBlock_, nEventsInLumiBlock_, nEventsInLumiBlock_);
275  temp.setAccepted(0,-1,-1);
276  temp.setAcceptedBr(0,-1,-1);
277  GenLumiProcess.push_back(temp);
278 
279  std::auto_ptr<GenLumiInfoProduct> genLumiInfo(new GenLumiInfoProduct());
280  genLumiInfo->setHEPIDWTUP(-1);
281  genLumiInfo->setProcessInfo( GenLumiProcess );
282  lumi.put(genLumiInfo);
283 
284  nEventsInLumiBlock_ = 0;
285 
286  }
287 }
288 
289 #endif // gen_GeneratorFilter_h
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
void setTried(unsigned int n, double sum, double sum2)
virtual void endLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
void setSelected(unsigned int n, double sum, double sum2)
virtual bool filter(Event &e, EventSetup const &es) override
LuminosityBlockIndex index() const
tuple lumi
Definition: fjr2json.py:35
void setKilled(unsigned int n, double sum, double sum2)
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool ev
GeneratorFilter(ParameterSet const &ps)
void setAccepted(unsigned int n, double sum, double sum2)
void setAcceptedBr(unsigned int n, double sum, double sum2)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
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
unsigned int nEventsInLumiBlock_
virtual void beginLuminosityBlock(LuminosityBlock const &, EventSetup const &) override
virtual void endRunProduce(Run &, EventSetup const &) override
void setLheXSec(double value, double err)
const XSec & internalXSec() const
edm::EventID id() const
Definition: EventBase.h:60
StreamID streamID() const
Definition: Event.h:79
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:112
virtual void endLuminosityBlockProduce(LuminosityBlock &, EventSetup const &) override
std::string uniqueSharedResourceName()
Definition: Run.h:43
void put(std::auto_ptr< PROD > product)
Put a new product.