194 {
195
199 << " Aborting ... ");
200 return;
201 }
203
207 << " Aborting ... " );
208 return;
209 }
211
215 << " Aborting ... ");
216 return;
217 }
219
223 << " Aborting ... ");
224 return;
225 }
227
230
231 writeLHE.headerBlock() << readH.headerBlock;
232 writeLHE.initComments() << readH.initComments;
233 writeLHE.heprup = readH.heprup;
234 writeLHE.init();
235
236 long neve = 0;
238
239
240
241
242
243
244 while( readH.readEvent() ){
245
246 int ID_l[4] = {-999, -999, -999, -999};
247 int decayModeType = 4.0 *
m_rand.Rndm();
248
249 if (decayModeType == 0){
250
251 read4f = &read4e;
253 }
254 else if (decayModeType == 1 || decayModeType == 2){
255
256 read4f = &read2e2mu;
258 for(
int i = 2;
i < 4;
i++) ID_l[i] =
m_muonID;
259 }
260 else {
261
262 read4f = &read4mu;
263 for(
int i = 0;
i < 4;
i++) ID_l[i] =
m_muonID;
264 }
265
266 if( !read4f->readEvent() ){
267 ANA_MSG_INFO(
"Still Powheg events but no more Prophecy4f ");
268 ANA_MSG_INFO(
"events! Writing out LHE file ... Events processed so far " << neve );
269 break;
270 }
271
272 ++neve;
273 if(neve%1000==0){
274 print(
"Events processed so far ", neve);
275 }
276 if( readH.outsideBlock.length() )
278
279 int nup_org=readH.hepeup.NUP;
280
281 for(int nup=0; nup<nup_org; nup++){
283 readH.hepeup.ISTUP[nup]=2;
284 }
285 writeLHE.hepeup = readH.hepeup;
286
287 double P4_Z[5][2]{};
288 double P4_l[5][5]{};
289
290 double Pph[5] = {-999., -999., -999., -999., -999.};
291 double daughter2[5][5]{};
292
293 for(
int i=0;
i<nup_org;
i++){
295 TLorentzVector higgs( readH.hepeup.PUP[i][0],
296 readH.hepeup.PUP[i][1],
297 readH.hepeup.PUP[i][2],
298 readH.hepeup.PUP[i][3] );
299
300 TVector3 boostvec = higgs.BoostVector();
301 TLorentzRotation boost(-boostvec);
302 TLorentzRotation backboost(boostvec);
303
304
305 TLorentzVector r_higgs(higgs);
306 r_higgs*=boost;
307
308
309
310 writeLHE.hepeup.resize(nup_org+read4f->hepeup.NUP);
311
312 TLorentzVector sum_daughter;
313 TLorentzVector sum_daughter_rest;
314 TLorentzVector sum_daughter_rest_init;
315
316 for(
int k=0;
k<read4f->hepeup.NUP;
k++){
317 TLorentzVector daughter(read4f->hepeup.PUP[k][0],
318 read4f->hepeup.PUP[k][1],
319 read4f->hepeup.PUP[k][2],
320 read4f->hepeup.PUP[k][3]);
321 sum_daughter_rest_init+=daughter;
322 }
323
324 for(
int j=0;
j<read4f->hepeup.NUP;
j++){
325 TLorentzVector daughter(read4f->hepeup.PUP[j][0],
326 read4f->hepeup.PUP[j][1],
327 read4f->hepeup.PUP[j][2],
328 read4f->hepeup.PUP[j][3]);
329 sum_daughter_rest+=daughter;
330
331 daughter *= backboost;
332 daughter *= higgs.M()/sum_daughter_rest_init.M();
333
334
337 break;
338 }
339
340 sum_daughter+=daughter;
341
343 std::abs(read4f->hepeup.IDUP[j])==
m_muonID ){
344
345
346 P4_l[0][
j] = daughter.Px();
347 P4_l[1][
j] = daughter.Py();
348 P4_l[2][
j] = daughter.Pz();
349 P4_l[3][
j] = daughter.E();
350
351 }
352 else if( std::abs(read4f->hepeup.IDUP[j])==
m_photonID ){
353 Pph[0] = daughter.Px();
354 Pph[1] = daughter.Py();
355 Pph[2] = daughter.Pz();
356 Pph[3] = daughter.E();
357 Pph[4] =0.0;
358 }
359 }
360
361 for(
int n=0;
n<4;
n++){
364
365
366 P4_Z[
n][0] = P4_l[
n][0] + P4_l[
n][1];
367 P4_Z[
n][1] = P4_l[
n][2] + P4_l[
n][3];
368 }
369 }
370
371 double mass1, mass2;
372 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]);
373 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]);
376
377 double p1[5],
p2[5], pZ1[5],
p3[5], p4[5], pZ2[5];
378 for(
int u=0;
u<5;
u++){
379
386
387 }
388
392 p4[4] = 0.0;
393
394
395
396 rescms(pZ1, p1, p2, mass1, mass1);
397 rescms(pZ2, p3, p4, mass2, mass2);
398
399 for(
int d =0;
d<5;
d++){
400 daughter2[0][
d] =
p1[
d];
401 daughter2[1][
d] =
p2[
d];
402 daughter2[2][
d] =
p3[
d];
403 daughter2[3][
d] = p4[
d];
404 daughter2[4][
d] = Pph[
d];
405 }
406
407
408 bool doDebug = false;
409 doDebug = true;
410 if (doDebug) {
411
414 ANA_MSG_DEBUG(
"Higgs " << higgs.M() <<
", " << higgs.Pt() <<
"," << higgs.Eta() <<
"," << higgs.Phi());
415
416
417 TLorentzVector higgsFromChildren;
418 for(
int d =0;
d < read4f->hepeup.NUP;
d++){
419 TLorentzVector child;
420 child.SetXYZM( daughter2[d][0],
421 daughter2[d][1],
422 daughter2[d][2],
423 daughter2[d][4] );
424
425 ANA_MSG_DEBUG(
"child " << d <<
" " << child.M() <<
", " << child.Pt() <<
", " << child.Eta() <<
", " << child.Phi());
426 higgsFromChildren += child;
427 }
428 ANA_MSG_DEBUG(
"Higgs mass " << higgs.M() <<
", from children " << higgsFromChildren.M() <<
", diff " << higgs.M() - higgsFromChildren.M());
429 }
430 break;
431 }
432 }
433
434
436 writeLHE.hepeup = readH.hepeup;
437 }
438 else{
439
440 for(int jp=0; jp<read4f->hepeup.NUP; jp++){
441 if (jp < 4){
442 writeLHE.hepeup.IDUP[nup_org+jp] = (jp % 2 == 0)? ID_l[jp] : -ID_l[jp];
443
444 }
445 else{
446 writeLHE.hepeup.IDUP[nup_org+jp] = read4f->hepeup.IDUP[jp];
447 }
448
449 writeLHE.hepeup.ISTUP[nup_org+jp]=read4f->hepeup.ISTUP[jp];
450 if( read4f->hepeup.ICOLUP[jp].first==0 &&
451 read4f->hepeup.ICOLUP[jp].second==0 ) {
452 writeLHE.hepeup.ICOLUP[nup_org+jp].first=0;
453 writeLHE.hepeup.ICOLUP[nup_org+jp].second=0;
454 }
455 else {
456 writeLHE.hepeup.ICOLUP[nup_org+jp].first=read4f->hepeup.ICOLUP[jp].first+100;
457 writeLHE.hepeup.ICOLUP[nup_org+jp].second=read4f->hepeup.ICOLUP[jp].second+100;
458 }
459 writeLHE.hepeup.MOTHUP[nup_org+jp].first=3;
460 writeLHE.hepeup.MOTHUP[nup_org+jp].second=3;
461
462 if (jp>=5) throw std::runtime_error("Prophecy4fMerger::merge: jp index out of range for array 'daughter2'.");
463 writeLHE.hepeup.PUP[nup_org+jp][0]=daughter2[jp][0];
464 writeLHE.hepeup.PUP[nup_org+jp][1]=daughter2[jp][1];
465 writeLHE.hepeup.PUP[nup_org+jp][2]=daughter2[jp][2];
466 writeLHE.hepeup.PUP[nup_org+jp][3]=daughter2[jp][3];
467 writeLHE.hepeup.PUP[nup_org+jp][4]=daughter2[jp][4];
468 writeLHE.hepeup.VTIMUP[nup_org+jp]=read4f->hepeup.VTIMUP[jp];
469 writeLHE.hepeup.SPINUP[nup_org+jp]=read4f->hepeup.SPINUP[jp];
470 }
471 }
472
473
474
475
476 writeLHE.hepeup.XWGTUP *= read4f->hepeup.XWGTUP;
477 double prophecyWeight = read4f->hepeup.XWGTUP;
478 if ( writeLHE.hepeup.weights_compressed.size() > 0 ) {
479 for ( int i = 1, N = writeLHE.hepeup.weights_compressed.size(); i < N; ++i ) {
480 writeLHE.hepeup.weights_compressed[
i] *= prophecyWeight;
481
482 }
483 }
484
485 writeLHE.eventComments() << readH.eventComments;
486 writeLHE.writeEvent();
487 }
488}
bool fileExists(const std::string &filename)
static const long m_higgsID
std::string m_inProphecy4mu
std::string m_inProphecy2e2mu
std::string m_inProphecy4e
static const long m_muonID
bool isPHevent(const TLorentzVector &higgs, const TLorentzVector &sum_daugh_rest_init)
int rescms(double *p, double *p1, double *p2, double m1, double m2)
void print(const std::string &field)
static const long m_photonID
static const long m_electronID
double setParticleMass(int id) const
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
@ u
Enums for curvilinear frames.