5 #include "TLorentzRotation.h"
6 #include "TLorentzVector.h"
9 #include "Pythia8/LHEF3.h"
18 using namespace asg::msgUserCode;
29 ANA_MSG_INFO(
"Prophecy4fMerger::setRandomSeed: set random seed to " << seed <<
".");
44 const double pf4 = (
pi[0] * ps[0] +
pi[1] * ps[1] +
pi[2] * ps[2] +
pi[3] * ps[3]) / ps[4];
45 const double fn = (pf4 +
pi[3]) / (ps[3] + ps[4]);
46 pf[0] =
pi[0] +
fn * ps[0];
47 pf[1] =
pi[1] +
fn * ps[1];
48 pf[2] =
pi[2] +
fn * ps[2];
67 const double pf4 = (
pi[3] * ps[3] -
pi[2] * ps[2] -
pi[1] * ps[1] -
pi[0] * ps[0]) / ps[4];
68 const double fn = (pf4 +
pi[3]) / (ps[3] + ps[4]);
69 pf[0] =
pi[0] -
fn * ps[0];
70 pf[1] =
pi[1] -
fn * ps[1];
71 pf[2] =
pi[2] -
fn * ps[2];
107 double ems = (em1 + em2);
111 double emd = (em1 - em2);
116 if(em0 < ems || em0 < emd){
119 else if(em0 == ems || em0 == emd){
123 ret_val = sqrt((em0 + emd) * (em0 - emd) * (em0 + ems) * (em0 - ems)) * .5f / em0;
134 double po1[5], po2[5], pcm, pcmo;
136 const double m =
p[4];
137 const double mo1 =
p1[4];
138 const double mo2 =
p2[4];
156 for (
int il = 0;
il < 4;
il++) {
157 po1[
il] = pcm / pcmo * po1[
il];
158 po2[
il] = pcm / pcmo * po2[
il];
162 po1[3] = sqrt(pcm*pcm +
m1*
m1);
163 po2[3] = sqrt(pcm*pcm +
m2*
m2);
176 const std::string& prophecy4e,
177 const std::string& prophecy4mu,
178 const std::string& prophecy2e2mu,
179 const std::string& outlhe,
197 <<
" Aborting ... ");
205 <<
" Aborting ... " );
213 <<
" Aborting ... ");
221 <<
" Aborting ... ");
229 writeLHE.headerBlock() << readH.headerBlock;
230 writeLHE.initComments() << readH.initComments;
231 writeLHE.heprup = readH.heprup;
242 while( readH.readEvent() ){
244 int ID_l[4] = {-999, -999, -999, -999};
245 int decayModeType = 4.0 *
m_rand.Rndm();
247 if (decayModeType == 0){
252 else if (decayModeType == 1 || decayModeType == 2){
264 if( !read4f->readEvent() ){
265 ANA_MSG_INFO(
"Still Powheg events but no more Prophecy4f ");
266 ANA_MSG_INFO(
"events! Writing out LHE file ... Events processed so far " << neve );
272 print(
"Events processed so far ", neve);
274 if( readH.outsideBlock.length() )
277 int nup_org=readH.hepeup.NUP;
279 for(
int nup=0; nup<nup_org; nup++){
281 readH.hepeup.ISTUP[nup]=2;
283 writeLHE.hepeup = readH.hepeup;
285 double P4_Z[5][2] = {{0}};
288 double Pph[5] = {-999., -999., -999., -999., -999.};
289 double daughter2[5][5];
291 for(
int i=0;
i<nup_org;
i++){
293 TLorentzVector higgs( readH.hepeup.PUP[
i][0],
294 readH.hepeup.PUP[
i][1],
295 readH.hepeup.PUP[
i][2],
296 readH.hepeup.PUP[
i][3] );
298 TVector3 boostvec = higgs.BoostVector();
299 TLorentzRotation
boost(-boostvec);
300 TLorentzRotation backboost(boostvec);
303 TLorentzVector r_higgs(higgs);
308 writeLHE.hepeup.resize(nup_org+read4f->hepeup.NUP);
310 TLorentzVector sum_daughter;
311 TLorentzVector sum_daughter_rest;
312 TLorentzVector sum_daughter_rest_init;
314 for(
int k=0;
k<read4f->hepeup.NUP;
k++){
315 TLorentzVector daughter(read4f->hepeup.PUP[
k][0],
316 read4f->hepeup.PUP[
k][1],
317 read4f->hepeup.PUP[
k][2],
318 read4f->hepeup.PUP[
k][3]);
319 sum_daughter_rest_init+=daughter;
322 for(
int j=0; j<read4f->hepeup.NUP; j++){
323 TLorentzVector daughter(read4f->hepeup.PUP[j][0],
324 read4f->hepeup.PUP[j][1],
325 read4f->hepeup.PUP[j][2],
326 read4f->hepeup.PUP[j][3]);
327 sum_daughter_rest+=daughter;
329 daughter *= backboost;
330 daughter *= higgs.M()/sum_daughter_rest_init.M();
338 sum_daughter+=daughter;
341 std::abs(read4f->hepeup.IDUP[j])==
m_muonID ){
344 P4_l[0][j] = daughter.Px();
345 P4_l[1][j] = daughter.Py();
346 P4_l[2][j] = daughter.Pz();
347 P4_l[3][j] = daughter.E();
350 else if( std::abs(read4f->hepeup.IDUP[j])==
m_photonID ){
351 Pph[0] = daughter.Px();
352 Pph[1] = daughter.Py();
353 Pph[2] = daughter.Pz();
354 Pph[3] = daughter.E();
359 for(
int n=0;
n<4;
n++){
364 P4_Z[
n][0] = P4_l[
n][0] + P4_l[
n][1];
365 P4_Z[
n][1] = P4_l[
n][2] + P4_l[
n][3];
370 P4_Z[4][0] = sqrt(P4_Z[3][0] * P4_Z[3][0] - P4_Z[0][0] * P4_Z[0][0] - P4_Z[1][0] * P4_Z[1][0] - P4_Z[2][0] * P4_Z[2][0]);
371 P4_Z[4][1] = sqrt(P4_Z[3][1] * P4_Z[3][1] - P4_Z[0][1] * P4_Z[0][1] - P4_Z[1][1] * P4_Z[1][1] - P4_Z[2][1] * P4_Z[2][1]);
375 double p1[5],
p2[5], pZ1[5],
p3[5], p4[5], pZ2[5];
376 for(
int u=0;
u<5;
u++){
397 for(
int d =0;
d<5;
d++){
398 daughter2[0][
d] =
p1[
d];
399 daughter2[1][
d] =
p2[
d];
400 daughter2[2][
d] =
p3[
d];
401 daughter2[3][
d] = p4[
d];
402 daughter2[4][
d] = Pph[
d];
406 bool doDebug =
false;
412 ANA_MSG_DEBUG(
"Higgs " << higgs.M() <<
", " << higgs.Pt() <<
"," << higgs.Eta() <<
"," << higgs.Phi());
415 TLorentzVector higgsFromChildren;
416 for(
int d =0;
d < read4f->hepeup.NUP;
d++){
417 TLorentzVector child;
418 child.SetXYZM( daughter2[
d][0],
423 ANA_MSG_DEBUG(
"child " <<
d <<
" " << child.M() <<
", " << child.Pt() <<
", " << child.Eta() <<
", " << child.Phi());
424 higgsFromChildren += child;
426 ANA_MSG_DEBUG(
"Higgs mass " << higgs.M() <<
", from children " << higgsFromChildren.M() <<
", diff " << higgs.M() - higgsFromChildren.M());
434 writeLHE.hepeup = readH.hepeup;
438 for(
int jp=0; jp<read4f->hepeup.NUP; jp++){
440 writeLHE.hepeup.IDUP[nup_org+jp] = (jp % 2 == 0)? ID_l[jp] : -ID_l[jp];
444 writeLHE.hepeup.IDUP[nup_org+jp] = read4f->hepeup.IDUP[jp];
447 writeLHE.hepeup.ISTUP[nup_org+jp]=read4f->hepeup.ISTUP[jp];
448 if( read4f->hepeup.ICOLUP[jp].first==0 &&
449 read4f->hepeup.ICOLUP[jp].second==0 ) {
450 writeLHE.hepeup.ICOLUP[nup_org+jp].first=0;
451 writeLHE.hepeup.ICOLUP[nup_org+jp].second=0;
454 writeLHE.hepeup.ICOLUP[nup_org+jp].first=read4f->hepeup.ICOLUP[jp].first+100;
455 writeLHE.hepeup.ICOLUP[nup_org+jp].second=read4f->hepeup.ICOLUP[jp].second+100;
457 writeLHE.hepeup.MOTHUP[nup_org+jp].first=3;
458 writeLHE.hepeup.MOTHUP[nup_org+jp].second=3;
459 writeLHE.hepeup.PUP[nup_org+jp][0]=daughter2[jp][0];
460 writeLHE.hepeup.PUP[nup_org+jp][1]=daughter2[jp][1];
461 writeLHE.hepeup.PUP[nup_org+jp][2]=daughter2[jp][2];
462 writeLHE.hepeup.PUP[nup_org+jp][3]=daughter2[jp][3];
463 writeLHE.hepeup.PUP[nup_org+jp][4]=daughter2[jp][4];
464 writeLHE.hepeup.VTIMUP[nup_org+jp]=read4f->hepeup.VTIMUP[jp];
465 writeLHE.hepeup.SPINUP[nup_org+jp]=read4f->hepeup.SPINUP[jp];
472 writeLHE.hepeup.XWGTUP *= read4f->hepeup.XWGTUP;
473 double prophecyWeight = read4f->hepeup.XWGTUP;
474 if ( writeLHE.hepeup.weights_compressed.size() > 0 ) {
475 for (
int i = 1,
N = writeLHE.hepeup.weights_compressed.size();
i <
N; ++
i ) {
476 writeLHE.hepeup.weights_compressed[
i] *= prophecyWeight;
481 writeLHE.eventComments() << readH.eventComments;
482 writeLHE.writeEvent();
487 const TLorentzVector& sum_daugh_rest_init){
489 if( std::abs(higgs.M()-sum_daugh_rest_init.M())>
m_deltaM ){
490 ANA_MSG_INFO(
"POWHEG event with Higgs off-mass shell: " << higgs.M() <<
" GeV");
510 else if( std::abs(
id) ==
m_muonID ){
513 else if( std::abs(
id) ==
m_tauID ){