9 #include "Pythia8/DireWeightContainer.h"
10 #include "Pythia8/DireSpace.h"
11 #include "Pythia8/DireTimes.h"
17 const double DireWeightContainer::LARGEWT = 2e0;
21 void DireWeightContainer::setup() {
25 enhanceFactors.clear();
28 card = settingsPtr->word(
"Dire:MG5card");
29 string mePlugin = settingsPtr->word(
"Dire:MEplugin");
30 if (mePlugin.size() > 0) {
32 matrixElements = ShowerMEsPlugin(
"libpythia8mg5" + mePlugin +
".so");
34 hasMEs = matrixElements.initDire(infoPtr,card);
41 const char* names[] = {
43 "Dire_fsr_qcd_1->1&21",
44 "Dire_fsr_qcd_1->21&1",
45 "Dire_fsr_qcd_21->21&21a",
46 "Dire_fsr_qcd_21->21&21b",
47 "Dire_fsr_qcd_21->1&1a",
48 "Dire_fsr_qcd_21->1&1b",
49 "Dire_fsr_qcd_1->2&1&2",
50 "Dire_fsr_qcd_1->1&1&1",
51 "Dire_fsr_qcd_1->1&21_notPartial",
52 "Dire_fsr_qcd_21->21&21_notPartial",
53 "Dire_fsr_qcd_21->1&1_notPartial",
54 "Dire_fsr_qcd_1->1&21&21",
55 "Dire_fsr_qcd_1->1&d&dbar",
56 "Dire_fsr_qcd_1->1&dbar&d",
57 "Dire_fsr_qcd_1->1&u&ubar",
58 "Dire_fsr_qcd_1->1&ubar&u",
59 "Dire_fsr_qcd_1->1&s&sbar",
60 "Dire_fsr_qcd_1->1&sbar&s",
61 "Dire_fsr_qcd_1->1&c&cbar",
62 "Dire_fsr_qcd_1->1&cbar&c",
63 "Dire_fsr_qcd_1->1&b&bbar",
64 "Dire_fsr_qcd_1->1&bbar&b",
65 "Dire_fsr_qcd_21->21&21&21",
66 "Dire_fsr_qcd_21->21&d&dbar",
67 "Dire_fsr_qcd_21->21&dbar&d",
68 "Dire_fsr_qcd_21->21&u&ubar",
69 "Dire_fsr_qcd_21->21&ubar&u",
70 "Dire_fsr_qcd_21->21&s&sbar",
71 "Dire_fsr_qcd_21->21&sbar&s",
72 "Dire_fsr_qcd_21->21&c&cbar",
73 "Dire_fsr_qcd_21->21&cbar&c",
74 "Dire_fsr_qcd_21->21&b&bbar",
75 "Dire_fsr_qcd_21->21&bbar&b",
77 "Dire_isr_qcd_1->1&21",
78 "Dire_isr_qcd_21->1&1",
79 "Dire_isr_qcd_21->21&21a",
80 "Dire_isr_qcd_21->21&21b",
81 "Dire_isr_qcd_1->21&1",
82 "Dire_isr_qcd_1->2&1&2",
83 "Dire_isr_qcd_1->1&1&1",
85 "Dire_fsr_qed_1->1&22",
86 "Dire_fsr_qed_1->22&1",
87 "Dire_fsr_qed_11->11&22",
88 "Dire_fsr_qed_11->22&11",
89 "Dire_fsr_qed_22->1&1a",
90 "Dire_fsr_qed_22->1&1b",
91 "Dire_fsr_qed_22->2&2a",
92 "Dire_fsr_qed_22->2&2b",
93 "Dire_fsr_qed_22->3&3a",
94 "Dire_fsr_qed_22->3&3b",
95 "Dire_fsr_qed_22->4&4a",
96 "Dire_fsr_qed_22->4&4b",
97 "Dire_fsr_qed_22->5&5a",
98 "Dire_fsr_qed_22->5&5b",
99 "Dire_fsr_qed_22->11&11a",
100 "Dire_fsr_qed_22->11&11b",
101 "Dire_fsr_qed_22->13&13a",
102 "Dire_fsr_qed_22->13&13b",
103 "Dire_fsr_qed_22->15&15a",
104 "Dire_fsr_qed_22->15&15b",
106 "Dire_isr_qed_1->1&22",
107 "Dire_isr_qed_1->22&1",
108 "Dire_isr_qed_22->1&1",
109 "Dire_isr_qed_11->11&22",
110 "Dire_isr_qed_11->22&11",
111 "Dire_isr_qed_22->11&11",
113 "Dire_fsr_ew_1->1&23",
114 "Dire_fsr_ew_1->23&1",
115 "Dire_fsr_ew_23->1&1a",
116 "Dire_fsr_ew_23->1&1b",
117 "Dire_fsr_ew_24->1&1a",
118 "Dire_fsr_ew_24->1&1b",
120 "Dire_fsr_u1new_1->1&22",
121 "Dire_fsr_u1new_1->22&1",
122 "Dire_fsr_u1new_11->11&22",
123 "Dire_fsr_u1new_11->22&11",
124 "Dire_fsr_u1new_22->1&1a",
125 "Dire_fsr_u1new_22->1&1b",
126 "Dire_fsr_u1new_22->2&2a",
127 "Dire_fsr_u1new_22->2&2b",
128 "Dire_fsr_u1new_22->3&3a",
129 "Dire_fsr_u1new_22->3&3b",
130 "Dire_fsr_u1new_22->4&4a",
131 "Dire_fsr_u1new_22->4&4b",
132 "Dire_fsr_u1new_22->5&5a",
133 "Dire_fsr_u1new_22->5&5b",
134 "Dire_fsr_u1new_22->11&11a",
135 "Dire_fsr_u1new_22->11&11b",
136 "Dire_fsr_u1new_22->13&13a",
137 "Dire_fsr_u1new_22->13&13b",
138 "Dire_fsr_u1new_22->15&15a",
139 "Dire_fsr_u1new_22->15&15b",
140 "Dire_fsr_u1new_22->211&211a",
141 "Dire_fsr_u1new_22->211&211b",
143 "Dire_isr_u1new_1->1&22",
144 "Dire_isr_u1new_1->22&1",
145 "Dire_isr_u1new_22->1&1",
146 "Dire_isr_u1new_11->11&22",
147 "Dire_isr_u1new_11->22&11",
148 "Dire_isr_u1new_22->11&11"
151 for (
int i=0; i < sizeNames; ++i) {
152 if (settingsPtr->parm(
"Enhance:"+
string(names[i])) > 1.0) {
153 enhanceFactors.insert(
154 make_pair(
string(names[i]),
155 settingsPtr->parm(
"Enhance:"+
string(names[i]))) );
159 string vkey =
"base";
160 rejectWeight.insert( make_pair(vkey, map<ulong, DirePSWeight>() ));
161 acceptWeight.insert( make_pair(vkey, map<ulong, DirePSWeight>() ));
162 showerWeight.insert( make_pair(vkey, 1.) );
163 weightNames.push_back( vkey );
165 bool doVar = settingsPtr->flag(
"Variations:doVariations");
167 vector<string> group;
169 if (settingsPtr->parm(
"Variations:muRisrDown") != 1.) {
170 bookWeightVar(
"Variations:muRisrDown");
171 group.push_back(
"Variations:muRisrDown");
173 if (settingsPtr->parm(
"Variations:muRfsrDown") != 1.) {
174 bookWeightVar(
"Variations:muRfsrDown");
175 group.push_back(
"Variations:muRfsrDown");
177 if (
int(group.size()) > 0) {
178 weightCombineList.insert ( make_pair(
"scaleDown", group) );
179 weightCombineListNames.push_back (
"scaleDown");
184 if (settingsPtr->parm(
"Variations:muRisrUp") != 1.) {
185 bookWeightVar(
"Variations:muRisrUp");
186 group.push_back(
"Variations:muRisrUp");
188 if (settingsPtr->parm(
"Variations:muRfsrUp") != 1.) {
189 bookWeightVar(
"Variations:muRfsrUp");
190 group.push_back(
"Variations:muRfsrUp");
192 if (
int(group.size()) > 0) {
193 weightCombineList.insert ( make_pair(
"scaleUp", group) );
194 weightCombineListNames.push_back (
"scaleUp");
199 if (settingsPtr->flag(
"Variations:PDFup")) {
200 bookWeightVar(
"Variations:PDFup",
false);
201 group.push_back(
"Variations:PDFup");
202 weightCombineList.insert ( make_pair(
"PDFup", group) );
203 weightCombineListNames.push_back (
"PDFup");
206 if (settingsPtr->flag(
"Variations:PDFdown")) {
207 bookWeightVar(
"Variations:PDFdown",
false);
208 group.push_back(
"Variations:PDFdown");
209 weightCombineList.insert ( make_pair(
"PDFdown", group) );
210 weightCombineListNames.push_back (
"PDFdown");
214 if (settingsPtr->parm(
"Variations:muRmeUp") != 1.)
215 bookWeightVar(
"Variations:muRmeUp");
216 if (settingsPtr->parm(
"Variations:muRmeDown") != 1.)
217 bookWeightVar(
"Variations:muRmeDown");
218 if (settingsPtr->parm(
"Variations:muFmeUp") != 1.)
219 bookWeightVar(
"Variations:muFmeUp");
220 if (settingsPtr->parm(
"Variations:muFmeDown") != 1.)
221 bookWeightVar(
"Variations:muFmeDown");
240 void DireWeightContainer::bookWeightVar(
string vkey,
bool checkSettings) {
241 bool insert = !checkSettings || settingsPtr->parm(vkey) != 1.0;
243 rejectWeight.insert( make_pair(vkey, map<ulong, DirePSWeight>() ));
244 acceptWeight.insert( make_pair(vkey, map<ulong, DirePSWeight>() ));
245 showerWeight.insert( make_pair(vkey, 1.) );
246 weightNames.push_back( vkey );
252 void DireWeightContainer::setWeight(
string varKey,
double value) {
253 unordered_map<string, double>::iterator it = showerWeight.find( varKey );
254 if ( it == showerWeight.end() )
return;
260 void DireWeightContainer::resetAcceptWeight(
double pT2key,
double value,
262 unordered_map<string, map<ulong, DirePSWeight> >::iterator
263 it0 = acceptWeight.find( varKey );
264 if ( it0 == acceptWeight.end() )
return;
265 map<ulong, DirePSWeight>::iterator
266 it = acceptWeight[varKey].find( key(pT2key) );
267 if ( it == acceptWeight[varKey].end() )
return;
268 acceptWeight[varKey].erase(it);
269 acceptWeight[varKey].insert( make_pair( key(pT2key),
270 DirePSWeight(value,1,0,pT2key,
"")));
275 void DireWeightContainer::resetRejectWeight(
double pT2key,
double value,
277 unordered_map<string, map<ulong, DirePSWeight> >::iterator
278 it0 = rejectWeight.find( varKey );
279 if ( it0 == rejectWeight.end() )
return;
280 map<ulong, DirePSWeight>::iterator
281 it = rejectWeight[varKey].find( key(pT2key) );
282 if ( it == rejectWeight[varKey].end() )
return;
283 rejectWeight[varKey].erase(it);
284 rejectWeight[varKey].insert( make_pair( key(pT2key),
285 DirePSWeight(value,1,0,pT2key,
"")));
290 void DireWeightContainer::eraseAcceptWeight(
double pT2key,
string varKey) {
291 unordered_map<string, map<ulong, DirePSWeight> >::iterator
292 it0 = acceptWeight.find( varKey );
293 if ( it0 == acceptWeight.end() )
return;
294 map<ulong, DirePSWeight>::iterator
295 it = acceptWeight[varKey].find( key(pT2key) );
296 if ( it == acceptWeight[varKey].end() )
return;
297 acceptWeight[varKey].erase(it);
302 void DireWeightContainer::eraseRejectWeight(
double pT2key,
string varKey) {
303 unordered_map<string, map<ulong, DirePSWeight> >::iterator it0 =
304 rejectWeight.find( varKey );
305 if ( it0 == rejectWeight.end() )
return;
306 map<ulong, DirePSWeight>::iterator it =
307 rejectWeight[varKey].find( key(pT2key) );
308 if ( it == rejectWeight[varKey].end() )
return;
309 rejectWeight[varKey].erase(it);
314 double DireWeightContainer::getAcceptWeight(
double pT2key,
string varKey) {
315 unordered_map<string, map<ulong, DirePSWeight> >::iterator it0 =
316 acceptWeight.find( varKey );
317 if ( it0 == acceptWeight.end() )
return 0./0.;
318 map<ulong, DirePSWeight>::iterator it =
319 acceptWeight[varKey].find( key(pT2key) );
320 if ( it == acceptWeight[varKey].end() )
return 0./0.;
321 return it->second.weight();
327 double DireWeightContainer::getRejectWeight(
double pT2key,
string varKey) {
328 unordered_map<string, map<ulong, DirePSWeight> >::iterator it0 =
329 rejectWeight.find( varKey );
330 if ( it0 == rejectWeight.end() )
return 0./0.;
331 map<ulong, DirePSWeight>::iterator it =
332 rejectWeight[varKey].find( key(pT2key) );
333 if ( it == rejectWeight[varKey].end() )
return 0./0.;
334 return it->second.weight();
340 void DireWeightContainer::insertWeights( map<double,double> aWeight,
341 multimap<double,double> rWeight,
string varKey ) {
343 unordered_map<string, map<ulong, DirePSWeight> >::iterator itA0 =
344 acceptWeight.find( varKey );
345 if ( itA0 == acceptWeight.end() )
return;
346 unordered_map<string, map<ulong, DirePSWeight> >::iterator itR0 =
347 rejectWeight.find( varKey );
348 if ( itR0 == rejectWeight.end() )
return;
351 for ( map<double,double>::iterator it = aWeight.begin();
352 it != aWeight.end(); ++it ){
353 map<ulong, DirePSWeight>::iterator itLo
354 = acceptWeight[varKey].find( key(it->first) );
355 if (itLo == acceptWeight[varKey].end())
356 acceptWeight[varKey].insert(make_pair( key(it->first),
357 DirePSWeight(it->second,1,0,it->first,
"")));
359 itLo->second *= it->second;
362 for ( multimap<double,double>::iterator it = rWeight.begin();
363 it != rWeight.end(); ++it ){
364 map<ulong, DirePSWeight>::iterator itLo
365 = rejectWeight[varKey].find( key(it->first) );
366 if (itLo == rejectWeight[varKey].end())
367 rejectWeight[varKey].insert
368 (make_pair( key(it->first),
369 DirePSWeight(it->second,-1,0,it->first,
"")));
371 itLo->second *= it->second;
378 void DireWeightContainer::calcWeight(
double pT2,
bool includeAcceptAtPT2,
379 bool includeRejectAtPT2) {
382 for ( unordered_map<
string, map<ulong, DirePSWeight> >::iterator
383 it = rejectWeight.begin(); it != rejectWeight.end(); ++it ) {
385 bool hasAccept = ( acceptWeight[it->first].find(key(pT2))
386 != acceptWeight[it->first].end());
387 double acceptWt = (hasAccept && includeAcceptAtPT2)
388 ? acceptWeight[it->first].find(key(pT2))->second.weight()
392 double rejectWt = 1.;
393 for ( map<ulong, DirePSWeight>::reverse_iterator itR
394 = it->second.rbegin(); itR != it->second.rend(); ++itR ){
395 if ( includeRejectAtPT2 && itR->first == key(pT2) ) {
396 rejectWt *= itR->second.weight(); }
397 if ( itR->first > key(pT2) ) { rejectWt *= itR->second.weight(); }
398 if ( itR->first < key(pT2) || itR->first-key(pT2) == 0)
break;
402 unordered_map<string, double>::iterator itW = showerWeight.find(it->first);
404 if (itW != showerWeight.end()) itW->second *= acceptWt*rejectWt;
413 pair<double,double> DireWeightContainer::getWeight(
double pT2,
string varKey) {
416 bool hasAccept = ( acceptWeight[varKey].find(key(pT2))
417 != acceptWeight[varKey].end());
418 double acceptWt = (hasAccept)
419 ? acceptWeight[varKey].find(key(pT2))->second.weight()
423 double rejectWt = 1.;
424 unordered_map<string, map<ulong, DirePSWeight> >::iterator itRW
425 = rejectWeight.find(varKey);
426 if (itRW != rejectWeight.end()) {
429 for ( map<ulong, DirePSWeight>::reverse_iterator itR
430 = itRW->second.rbegin(); itR != itRW->second.rend();
432 if ( itR->first > key(pT2) ) rejectWt *= itR->second.weight();
433 if ( itR->first < key(pT2) || itR->first-key(pT2) == 0)
break;
439 unordered_map<string, double>::iterator itW = showerWeight.find(varKey);
441 if (itW != showerWeight.end()
442 && abs(itW->second) > LARGEWT) direInfoPtr->message(1) << scientific
443 << setprecision(8) << __FILE__ <<
" " << __func__ <<
" "
444 << __LINE__ <<
" : Found large shower weight=" << itW->second
445 <<
" at pT2=" << pT2 << endl;
447 if (itW != showerWeight.end()) rejectWt *= itW->second;
450 if (abs(acceptWt) > LARGEWT) direInfoPtr->message(1) << scientific
451 << setprecision(8) << __FILE__ <<
" " << __func__ <<
" "
452 << __LINE__ <<
" : Found large accept weight=" << acceptWt
453 <<
" at pT2=" << pT2 << endl;
454 if ( abs(rejectWt) > LARGEWT) {
455 for ( map<ulong, DirePSWeight>::reverse_iterator itR
456 = itRW->second.rbegin(); itR != itRW->second.rend(); ++itR ){
457 if ( itR->first > key(pT2) ) {
458 if ( abs(itR->second.weight()) > LARGEWT) direInfoPtr->message(1)
459 << scientific << setprecision(8) << __FILE__ <<
" " << __func__
460 <<
" " << __LINE__ <<
" : Found large reject weight="
461 << itR->second.weight() <<
" at index=" << itR->first
462 <<
" (pT2 approx. " << dkey(itR->first) <<
")" << endl;
464 if ( itR->first < key(pT2) || itR->first-key(pT2) == 0)
break;
469 return make_pair(acceptWt,rejectWt);
477 double DireWeightContainer::enhanceOverestimate(
string name ) {
478 unordered_map<string, double>::iterator it = enhanceFactors.find(name );
479 if ( it == enhanceFactors.end() )
return 1.;
485 double DireWeightContainer::getTrialEnhancement(
double pT2key ) {
486 map<ulong,double>::iterator it = trialEnhancements.find(key(pT2key));
487 if ( it == trialEnhancements.end() )
return 1.;
493 bool DireWeightContainer::hasME(
const Event& event) {
494 if (hasMEs)
return matrixElements.isAvailableMEDire(event);
498 bool DireWeightContainer::hasME(vector <int> in_pdgs, vector<int> out_pdgs) {
499 if (hasMEs)
return matrixElements.isAvailableMEDire(in_pdgs, out_pdgs);
503 double DireWeightContainer::getME(
const Event& event) {
504 if (hasMEs)
return matrixElements.calcMEDire(event);