CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetMatchingAlpgen.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstring>
3 #include <vector>
4 #include <memory>
5 #include <string>
6 
7 #include <HepMC/GenEvent.h>
8 
11 
15 
16 namespace gen {
17 
18 extern "C" {
19  // Put here all the functions for interfacing Fortran code.
20 
21 // extern void alinit_();
22  extern void alsetp_();
23 // extern void alevnt_();
24  extern void alveto_(int *ipveto);
25 
26  extern void dbpart_();
27  extern void pyupre_();
28 
29  void alshcd_(char csho[3]);
30  void alshen_();
31 } // extern "C"
32 
33 // Constructor
35  JetMatching(params),
36  applyMatching(params.getParameter<bool>("applyMatching")),
37  runInitialized(false)
38 {
39  ahopts_.etclus = params.getParameter<double>("etMin");
40  ahopts_.rclus = params.getParameter<double>("drMin");
41  ahopts_.iexc = params.getParameter<bool>("exclusive");
42 }
43 
44 // Destructor
46 {
47 }
48 
49 std::set<std::string> JetMatchingAlpgen::capabilities() const
50 {
51  std::set<std::string> result;
52  result.insert("psFinalState");
53  result.insert("hepevt");
54  result.insert("pythia6");
55  return result;
56 }
57 
58 // Implements the Alpgen MLM method - use alpg_match.F
59 
61 {
62 
63  // Read Alpgen run card stored in the LHERunInfo object.
64  std::vector<std::string> headerLines = runInfo->findHeader("AlpgenUnwParFile");
65  if (headerLines.empty())
66  throw cms::Exception("Generator|PartonShowerVeto")
67  << "In order to use Alpgen jet matching, "
68  "the input file has to contain the corresponding "
69  "Alpgen headers." << std::endl;
70 
71  // Parse the header using its bultin function.
72  header.parse(headerLines.begin(), headerLines.end());
73 
74  // I don't want to print this right now.
75 // std::cout << "Alpgen header" << std::endl;
76 // std::cout << "========================" << std::endl;
77 // std::cout << "\tihrd = " << header.ihrd << std::endl;
78 // std::cout << "\tmc = " << header.masses[AlpgenHeader::mc]
79 // << ", mb = " << header.masses[AlpgenHeader::mb]
80 // << ", mt = " << header.masses[AlpgenHeader::mt]
81 // << ", mw = " << header.masses[AlpgenHeader::mw]
82 // << ", mz = " << header.masses[AlpgenHeader::mz]
83 // << ", mh = " << header.masses[AlpgenHeader::mh]
84 // << std::endl;
85 // for(std::map<AlpgenHeader::Parameter, double>::const_iterator iter =
86 // header.params.begin(); iter != header.params.end(); ++iter)
87 // std::cout << "\t" << AlpgenHeader::parameterName(iter->first)
88 // << " = " << iter->second << std::endl;
89 // std::cout << "\txsec = " << header.xsec
90 // << " +-" << header.xsecErr << std::endl;
91 // std::cout << "========================" << std::endl;
92 
93  // Here we pass a few header variables to common block and
94  // call Alpgen init routine to do the rest.
95  // The variables passed first are the ones directly that
96  // need to be set up "manually": IHRD and the masses.
97  // (ebeam is set just to mimic the original code)
98  // Afterwards, we pass the full spectrum of Alpgen
99  // parameters directly into the AHPARS structure, to be
100  // treated by AHSPAR which is called inside alsetp_().
101 
105 
106  for(std::map<AlpgenHeader::Parameter, double>::const_iterator iter =
107  header.params.begin(); iter != header.params.end(); ++iter) {
108  if (iter->first <= 0 || iter->first >= (int)AHPARS::nparam - 1)
109  continue;
110  ahpars_.parval[(int)iter->first - 1] = iter->second;
111  }
112 
113  // Run the rest of the setup.
114  alsetp_();
115 
116  // When we reach this point, the run is fully initialized.
117  runInitialized = true;
118 }
119 
121 {
122  // We can't continue if the run has not been initialized.
123  if (!runInitialized)
124  throw cms::Exception("Generator|PartonShowerVeto")
125  << "Run not initialized in JetMatchingAlpgen"
126  << std::endl;
127 
128  // We are called just after LHEInterface has filled in
129  // the Fortran common block (and Pythia6 called UPEVNT).
130 
131  // Possibly not interesting for us.
132  // (except perhaps for debugging?)
133  // pyupre_();
134  // dbpart_();
135  eventInitialized = true;
136 }
137 
138 /*
139 int JetMatchingAlpgen::match(const HepMC::GenEvent *partonLevel,
140  const HepMC::GenEvent *finalState,
141  bool showeredFinalState)
142 */
143 int JetMatchingAlpgen::match( const lhef::LHEEvent* partonLevel, const std::vector<fastjet::PseudoJet>* jetInput )
144 {
145 
146 /*
147  if (!showeredFinalState)
148  throw cms::Exception("Generator|PartonShowerVeto")
149  << "Alpgen matching expected parton shower "
150  "final state." << std::endl;
151 */
152 
153  if (!runInitialized)
154  throw cms::Exception("Generator|PartonShowerVeto")
155  << "Run not initialized in JetMatchingAlpgen"
156  << std::endl;
157 
158  if (!eventInitialized)
159  throw cms::Exception("Generator|PartonShowerVeto")
160  << "Event not initialized in JetMatchingAlpgen"
161  << std::endl;
162 
163  // If matching not required (e.g., icckw = 0), don't run the
164  // FORTRAN veto code.
165  if(!applyMatching) return 0;
166 
167  // Call the Fortran veto code.
168  int veto = 0;
169  alveto_(&veto);
170 
171  eventInitialized = false;
172 
173  // If event was vetoed, the variable veto will contain the number 1.
174  // In this case, we must return 1 - that will be used as the return value from UPVETO.
175  // If event was accepted, the variable veto will contain the number 0.
176  // In this case, we must return 0 - that will be used as the return value from UPVETO.
177  return veto ? 1 : 0;
178 }
179 
180 void alshcd_(char csho[3])
181 {
182  std::strncpy(csho, "PYT", 3); // or "HER"
183 }
184 
185 void alshen_()
186 {
187 }
188 
189 } // end namespace gen
T getParameter(std::string const &) const
struct AHPPARA ahppara_
void alsetp_()
std::map< Parameter, double > params
Definition: AlpgenHeader.h:67
bool parse(const std::vector< std::string >::const_iterator &begin, const std::vector< std::string >::const_iterator &end)
Definition: AlpgenHeader.cc:67
int match(const lhef::LHEEvent *partonLevel, const std::vector< fastjet::PseudoJet > *jetInput)
void alshcd_(char csho[3])
void alshen_()
double masses[6]
struct AHOPTS ahopts_
tuple result
Definition: query.py:137
void beforeHadronisation(const lhef::LHEEvent *event)
std::set< std::string > capabilities() const
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
double rclus
double parval[nparam]
void init(const lhef::LHERunInfo *runInfo)
void pyupre_()
JetMatchingAlpgen(const edm::ParameterSet &params)
static const unsigned int nparam
unsigned int ihrd
Definition: AlpgenHeader.h:68
struct AHPARS ahpars_
std::vector< std::string > findHeader(const std::string &tag) const
Definition: LHERunInfo.cc:390
volatile std::atomic< bool > shutdown_flag false
double etclus
double masses[MASS_MAX]
Definition: AlpgenHeader.h:73
void dbpart_()
void alveto_(int *ipveto)