ATLAS Offline Software
PowhegBB4L.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 // PowhegHooksBB4L.h
5 
6 // Author: Tomas Jezo, Markus Seidel and Ben Nachman based on
7 // PowhegHooks.h by Richard Corke
8 
10 #include "UserSetting.h"
11 
12 namespace Pythia8 {
13 
14 // Create the user hook
15  class PowhegBB4L;
17 
18 //==========================================================================
19 
20 // Use userhooks to veto PYTHIA emissions above the POWHEG scale.
21 
22 class PowhegBB4L : public UserHooks {
23 //class PowhegHooksBB4L : public PowhegHooks {
24 
25 public:
26 
27  // Constructor and destructor.
29  m_onlyDistance1("Powheg:bb4l:onlyDistance1", 0),
30  m_useScaleResonanceInstead("Powheg:bb4l:useScaleResonanceInstead", 0){}
32 //--------------------------------------------------------------------------
33 
34 //--------------------------------------------------------------------------
35 
36  // Calculates the scale of the hardest emission from within the resonance system
37  // translated by Markus Seidel modified by Tomas Jezo
38  inline double findresscale( const int iRes, const Event& event) {
39  double scale = 0.;
40 
41  int nDau = event[iRes].daughterList().size();
42 
43  if (nDau == 0) {
44  // No resonance found, set scale to high value
45  // Pythia will shower any MC generated resonance unrestricted
46  scale = 1e30;
47  }
48  else if (nDau < 3) {
49  // No radiating resonance found
50  scale = 0.8;
51  }
52  else if (std::abs(event[iRes].id()) == 6) {
53  // Find top daughters
54  int idw = -1, idb = -1, idg = -1;
55 
56  for (int i = 0; i < nDau; i++) {
57  int iDau = event[iRes].daughterList()[i];
58  if (std::abs(event[iDau].id()) == 24) idw = iDau;
59  if (std::abs(event[iDau].id()) == 5) idb = iDau;
60  if (std::abs(event[iDau].id()) == 21) idg = iDau;
61  }
62 
63  // Get daughter 4-vectors in resonance frame
64  Vec4 pw(event[idw].p());
65  pw.bstback(event[iRes].p());
66 
67  Vec4 pb(event[idb].p());
68  pb.bstback(event[iRes].p());
69 
70  Vec4 pg(event[idg].p());
71  pg.bstback(event[iRes].p());
72 
73  // Calculate scale
74  scale = std::sqrt(2*pg*pb*pg.e()/pb.e());
75  }
76  else {
77  scale = 1e30;
78  }
79 
80  return scale;
81  }
82 
83 //--------------------------------------------------------------------------
84 
85  // The following routine will match daughters of particle `e[iparticle]` to an expected pattern specified via the list of expected particle PDG ID's `ids`,
86  // id wildcard is specified as 0 if match is obtained, the positions and the momenta of these particles are returned in vectors `positions` and `momenta`
87  // respectively
88  // if exitOnExtraLegs==true, it will exit if the decay has more particles than expected, but not less
89  inline bool match_decay(int iparticle, const Event &e, const std::vector<int> &ids, std::vector<int> &positions, std::vector<Vec4> &momenta, bool exitOnExtraLegs = true){
90  // compare sizes
91  if (e[iparticle].daughterList().size() != ids.size()) {
92  if (exitOnExtraLegs && e[iparticle].daughterList().size() > ids.size()) exit(-1);
93  return false;
94  }
95  // compare content
96  for (size_t i = 0; i < e[iparticle].daughterList().size(); i++) {
97  int di = e[iparticle].daughterList()[i];
98  if (ids[i] != 0 && e[di].id() != ids[i])
99  return false;
100  }
101  // reset the positions and momenta vectors (because they may be reused)
102  positions.clear();
103  momenta.clear();
104  // construct the array of momenta
105  for (size_t i = 0; i < e[iparticle].daughterList().size(); i++) {
106  int di = e[iparticle].daughterList()[i];
107  positions.push_back(di);
108  momenta.push_back(e[di].p());
109  }
110  return true;
111  }
112 
113  inline double qSplittingScale(Vec4 pt, Vec4 p1, Vec4 p2){
114  p1.bstback(pt);
115  p2.bstback(pt);
116  return std::sqrt( 2*p1*p2*p2.e()/p1.e() );
117  }
118 
119  inline double gSplittingScale(Vec4 pt, Vec4 p1, Vec4 p2){
120  p1.bstback(pt);
121  p2.bstback(pt);
122  return std::sqrt( 2*p1*p2*p1.e()*p2.e()/(std::pow(p1.e(),2)+std::pow(p2.e(),2)) );
123  }
124 
125 
126  inline double getdechardness(int topcharge, const Event &e){
127  int tid = 6*topcharge, wid = 24*topcharge, bid = 5*topcharge, gid = 21, wildcard = 0;
128  // find last top in the record
129  int i_top = -1;
130  Vec4 p_top, p_b, p_g, p_g1, p_g2;
131  for (int i = 0; i < e.size(); i++)
132  if (e[i].id() == tid) {
133  i_top = i;
134  p_top = e[i].p();
135  }
136  if (i_top == -1) return -1.0;
137 
138  // summary of cases
139  // 1.) t > W b
140  // a.) b > 3 ... error
141  // b.) b > b g ... h = sqrt(2*p_g*p_b*p_g.e()/p_b.e())
142  // c.) b > other ... h = -1
143  // return h
144  // 2.) t > W b g
145  // a.) b > 3 ... error
146  // b.) b > b g ... h1 = sqrt(2*p_g*p_b*p_g.e()/p_b.e())
147  // c.) b > other ... h1 = -1
148  // i.) g > 3 ... error
149  // ii.) g > 2 ... h2 = sqrt(2*p_g1*p_g2*p_g1.e()*p_g2.e()/(pow(p_g1.e(),2)+pow(p_g2.e(),2))) );
150  // iii.) g > other ... h2 = -1
151  // return max(h1,h2)
152  // 3.) else ... error
153 
154  vector<Vec4> momenta;
155  vector<int> positions;
156 
157  // 1.) t > b W
158  if ( match_decay(i_top, e, std::vector<int> {wid, bid}, positions, momenta, false) ) {
159  double h;
160  int i_b = positions[1];
161  // a.+b.) b > 3 or b > b g
162  if ( match_decay(i_b, e, std::vector<int> {bid, gid}, positions, momenta) )
163  h = qSplittingScale(e[i_top].p(), momenta[0], momenta[1]);
164  // c.) b > other
165  else
166  h = -1;
167  return h;
168  }
169  // 2.) t > b W g
170  else if ( match_decay(i_top, e, std::vector<int> {wid, bid, gid}, positions, momenta, false) ) {
171  double h1, h2;
172  int i_b = positions[1], i_g = positions[2];
173  // a.+b.) b > 3 or b > b g
174  if ( match_decay(i_b, e, std::vector<int> {bid, gid}, positions, momenta) )
175  h1 = qSplittingScale(e[i_top].p(), momenta[0], momenta[1]);
176  // c.) b > other
177  else
178  h1 = -1;
179  // i.+ii.) g > 3 or g > 2
180  if ( match_decay(i_g, e, std::vector<int> {wildcard, wildcard}, positions, momenta) )
181  h2 = gSplittingScale(e[i_top].p(), momenta[0], momenta[1]);
182  // c.) b > other
183  else
184  h2 = -1;
185  return max(h1, h2);
186  }
187  // 3.) else
188  else {
189  exit(-1);
190  }
191  }
192 
193 //--------------------------------------------------------------------------
194 
195  // called after shower -- cannot be used for veto, because the event will get discarded
196  inline bool canVetoPartonLevel() { return true; }
197  inline bool doVetoPartonLevel(const Event &e) {
198  double topdechardness = getdechardness(1, e), atopdechardness = getdechardness(-1, e);
199  if ((topdechardness > m_topresscale) or (atopdechardness > m_atopresscale)) {
200 
201 #if PYTHIA_VERSION_INTEGER >= 8310
202  loggerPtr->ERROR_MSG("Warning in PowhegHooksBB4L::doVetoPartonLevel: passed doVetoFSREmission veto, but wouldn't have passed veto based on the full event listing");
203 #else
204  infoPtr->errorMsg("Warning in PowhegHooksBB4L::doVetoPartonLevel: passed doVetoFSREmission veto, but wouldn't have passed veto based on the full event listing");
205 #endif
206  }
207 // cout << " veto scales: " << fixed << setprecision(17) << setw(30) << topresscale << setw(30) << atopresscale << endl;
208  m_topresscale = -1;
209  m_atopresscale = -1;
210 
211  return false;
212  }
213 
214  // called before each resonance decay shower
215  inline bool canSetResonanceScale() { return true; }
216  inline double scaleResonance(int iRes, const Event &e) {
217  double scale = 0.;
218 
219  if (e[iRes].id() == 6){
220  scale = m_topresscale = findresscale(iRes, e);
221  }else if (e[iRes].id() == -6){
222  scale = m_atopresscale = findresscale(iRes, e);
223  }
224 
225  if (m_useScaleResonanceInstead(settingsPtr)) return scale;
226 
227  return 1e30;
228  }
229 
230 //--------------------------------------------------------------------------
231 
232  // FSR veto
233  inline bool canVetoFSREmission() {
234  if (m_useScaleResonanceInstead(settingsPtr))
235  return false;
236  else
237  return true;
238  }
239 
240 
241 
242  inline bool doVetoFSREmission(int, const Event &e, int, bool inResonance) {
243 
244  if (inResonance) {
245 
246  // get the participants of the splitting: the radiator and the emitted
247  int iEmt = e.size() - 2;
248  int iRadAft = e.size() - 3;
249  int iRadBef = e[iEmt].mother1();
250 
251  // find the top resonance the radiator originates from
252  int iTop = e[iRadBef].mother1();
253  int distance = 1;
254  while (std::abs(e[iTop].id()) != 6 && iTop > 0) {
255  iTop = e[iTop].mother1();
256  distance ++;
257  }
258  if (iTop == 0) {
259 #if PYTHIA_VERSION_INTEGER >= 8310
260  loggerPtr->ERROR_MSG("Warning in PowhegHooksBB4L::doVetoFSREmission: emission in resonance not from top quark, not vetoing");
261 #else
262  infoPtr->errorMsg("Warning in PowhegHooksBB4L::doVetoFSREmission: emission in resonance not from top quark, not vetoing");
263 #endif
264  return false;
265  }
266  int iTopCharge = (e[iTop].id()>0)?1:-1;
267 
268 
269  // calculate the scale of the emission
270  Vec4 pr(e[iRadAft].p()), pe(e[iEmt].p()), pt(e[iTop].p());
271  double scale;
272  // gluon splitting into two partons
273  if (e[iRadBef].id() == 21)
275  // quark emitting a gluon
276  else if (std::abs(e[iRadBef].id()) <= 5)
278  // other stuff (which we should not veto)
279  else {
280  scale = 0;
281  }
282 
283  if (iTopCharge > 0) {
284  if (m_onlyDistance1(settingsPtr))
285  return (distance == 1) && scale > m_topresscale;
286  else
287  return scale > m_topresscale;
288  }
289  else {
290  if (m_onlyDistance1(settingsPtr))
291  return (distance == 1) && scale > m_atopresscale;
292  else
293  return scale > m_atopresscale;
294  }
295  } else {
296  return false;
297  }
298 
299  return false;
300  }
301 
302 //--------------------------------------------------------------------------
303 
304  // Functions to return information
305 
306 // inline int getNFSRveto() { return nFSRveto; }
307 
308 //--------------------------------------------------------------------------
309 
310 private:
311 
316 };
317 
318 //==========================================================================
319 
320 } // end namespace Pythia8
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Pythia8::PowhegBB4L::m_useScaleResonanceInstead
Pythia8_UserHooks::UserSetting< int > m_useScaleResonanceInstead
Definition: PowhegBB4L.cxx:315
keylayer_zslicemap.pb
pb
Definition: keylayer_zslicemap.py:188
Pythia8::PowhegBB4L::canVetoPartonLevel
bool canVetoPartonLevel()
Definition: PowhegBB4L.cxx:196
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
Pythia8::PowhegBB4L::match_decay
bool match_decay(int iparticle, const Event &e, const std::vector< int > &ids, std::vector< int > &positions, std::vector< Vec4 > &momenta, bool exitOnExtraLegs=true)
Definition: PowhegBB4L.cxx:89
Event
Definition: trigbs_orderedMerge.cxx:42
Pythia8::PowhegBB4L::scaleResonance
double scaleResonance(int iRes, const Event &e)
Definition: PowhegBB4L.cxx:216
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
test_pyathena.pt
pt
Definition: test_pyathena.py:11
Pythia8::PowhegBB4L::qSplittingScale
double qSplittingScale(Vec4 pt, Vec4 p1, Vec4 p2)
Definition: PowhegBB4L.cxx:113
Pythia8_UserHooks::UserHooksFactory::Creator
Definition: UserHooksFactory.h:54
Pythia8::PowhegBB4L::canSetResonanceScale
bool canSetResonanceScale()
Definition: PowhegBB4L.cxx:215
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
LArG4AODNtuplePlotter.pe
pe
Definition: LArG4AODNtuplePlotter.py:116
UserHooksFactory.h
Pythia8
Author: James Monk (jmonk@cern.ch)
Definition: IPythia8Custom.h:13
HitType::wildcard
@ wildcard
Pythia8_UserHooks::UserSetting< int >
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Pythia8::PowhegBB4L::m_onlyDistance1
Pythia8_UserHooks::UserSetting< int > m_onlyDistance1
Definition: PowhegBB4L.cxx:314
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Pythia8::PowhegBB4L::gSplittingScale
double gSplittingScale(Vec4 pt, Vec4 p1, Vec4 p2)
Definition: PowhegBB4L.cxx:119
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
Pythia8::PowhegBB4L::getdechardness
double getdechardness(int topcharge, const Event &e)
Definition: PowhegBB4L.cxx:126
lumiFormat.i
int i
Definition: lumiFormat.py:85
Pythia8::PowhegBB4L::~PowhegBB4L
~PowhegBB4L()
Definition: PowhegBB4L.cxx:31
extractSporadic.h
list h
Definition: extractSporadic.py:97
TileDCSDataPlotter.pr
pr
Definition: TileDCSDataPlotter.py:922
UserSetting.h
gid
Acts::GeometryIdentifier gid
Definition: ActsWriteTrackingGeometryTransforms.cxx:27
Pythia8::PowhegBB4L::m_atopresscale
double m_atopresscale
Definition: PowhegBB4L.cxx:313
calibdata.exit
exit
Definition: calibdata.py:236
Pythia8::PowhegBB4L::doVetoPartonLevel
bool doVetoPartonLevel(const Event &e)
Definition: PowhegBB4L.cxx:197
ParticleGun_EoverP_Config.pg
pg
Definition: ParticleGun_EoverP_Config.py:61
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
Pythia8::powhegBB4LCreator
Pythia8_UserHooks::UserHooksFactory::Creator< Pythia8::PowhegBB4L > powhegBB4LCreator("PowhegBB4L")
h
Pythia8::PowhegBB4L::doVetoFSREmission
bool doVetoFSREmission(int, const Event &e, int, bool inResonance)
Definition: PowhegBB4L.cxx:242
Pythia8::PowhegBB4L
Definition: PowhegBB4L.cxx:22
Pythia8::PowhegBB4L::m_topresscale
double m_topresscale
Definition: PowhegBB4L.cxx:312
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
Pythia8::PowhegBB4L::PowhegBB4L
PowhegBB4L()
Definition: PowhegBB4L.cxx:28
Pythia8::PowhegBB4L::canVetoFSREmission
bool canVetoFSREmission()
Definition: PowhegBB4L.cxx:233
Pythia8::PowhegBB4L::findresscale
double findresscale(const int iRes, const Event &event)
Definition: PowhegBB4L.cxx:38
BchCleanup.idb
idb
Definition: BchCleanup.py:152