diff --git a/MatrixElement/DrellYanBase.cc b/MatrixElement/DrellYanBase.cc
--- a/MatrixElement/DrellYanBase.cc
+++ b/MatrixElement/DrellYanBase.cc
@@ -1,910 +1,911 @@
 // -*- C++ -*-
 //
 // This is the implementation of the non-inlined, non-templated member
 // functions of the DrellYanBase class.
 //
 
 #include "DrellYanBase.h"
 #include "ThePEG/Repository/EventGenerator.h"
 #include "ThePEG/Interface/ClassDocumentation.h"
 #include "ThePEG/Interface/Parameter.h"
 #include "ThePEG/Interface/Reference.h"
 #include "ThePEG/Persistency/PersistentOStream.h"
 #include "ThePEG/Persistency/PersistentIStream.h"
 #include "ThePEG/PDT/EnumParticles.h"
 #include "Herwig/Shower/QTilde/Base/ShowerProgenitor.h"
 #include "Herwig/Shower/QTilde/Base/ShowerParticle.h"
 #include "Herwig/Shower/QTilde/Base/Branching.h"
 #include "Herwig/Shower/RealEmissionProcess.h"
 
 using namespace Herwig;
 
 DrellYanBase::DrellYanBase() 
   : _channelwgtA(0.12), _channelwgtB(2.00), _nover(0), _maxwgt(0.),
     _power(2.0),_preqqbar(6.5),_preqg(4.0),_pregqbar(4.0),
     _min_pt(2.*GeV) {}
 
 void DrellYanBase::persistentOutput(PersistentOStream & os) const {
   os << _channelwgtA << _channelwgtB << _channelweights << _alpha
      << _power << _preqqbar << _preqg << _pregqbar << ounit( _min_pt, GeV )
      << _prefactor;
 }
 
 void DrellYanBase::persistentInput(PersistentIStream & is, int) {
   is >> _channelwgtA >> _channelwgtB >> _channelweights >> _alpha
      >> _power >> _preqqbar >> _preqg >> _pregqbar >> iunit( _min_pt, GeV )
      >> _prefactor;
 }
 
 AbstractClassDescription<DrellYanBase> DrellYanBase::initDrellYanBase;
 // Definition of the static class description member.
 
 void DrellYanBase::Init() {
 
   static ClassDocumentation<DrellYanBase> documentation
     ("The DrellYanBase class provides a base class for the"
      " corrections to Drell-Yan type processes");
 
   static Parameter<DrellYanBase,double> interfaceQQbarChannelWeight
     ("QQbarChannelWeight",
      "The relative weights of the q qbar abd q g channels for selection."
      " This is a technical parameter for the phase-space generation and "
      "should not affect the results only the efficiency and fraction"
      " of events with weight > 1.",
      &DrellYanBase::_channelwgtA, 0.12, 0.01, 100.,
      false, false, Interface::limited);
 
   static Parameter<DrellYanBase,double> interfaceQGChannelWeight
     ("QGChannelWeight",
      "The relative weights of the qg abd qbar g channels for selection."
      " This is a technical parameter for the phase-space generation and "
      "should not affect the results only the efficiency and fraction",
      &DrellYanBase::_channelwgtB, 2., 0.01, 100.,
      false, false, Interface::limited);
 
   static Reference<DrellYanBase,ShowerAlpha> interfaceCoupling
     ("Coupling",
      "Pointer to the object to calculate the coupling for the correction",
      &DrellYanBase::_alpha, false, false, true, false, false);
 
   static Parameter<DrellYanBase,double> interfacePower
     ("Power",
      "The power for the sampling of the matrix elements",
      &DrellYanBase::_power, 2.0, 1.0, 10.0,
      false, false, Interface::limited);
 
   static Parameter<DrellYanBase,double> interfacePrefactorqqbar
     ("Prefactorqqbar",
      "The prefactor for the sampling of the q qbar channel",
      &DrellYanBase::_preqqbar, 5.0, 0.0, 1000.0,
      false, false, Interface::limited);
 
   static Parameter<DrellYanBase,double> interfacePrefactorqg
     ("Prefactorqg",
      "The prefactor for the sampling of the q g channel",
      &DrellYanBase::_preqg, 3.0, 0.0, 1000.0,
      false, false, Interface::limited);
   
   static Parameter<DrellYanBase,double> interfacePrefactorgqbar
     ("Prefactorgqbar",
      "The prefactor for the sampling of the g qbar channel",
      &DrellYanBase::_pregqbar, 3.0, 0.0, 1000.0,
      false, false, Interface::limited);
 
   static Parameter<DrellYanBase, Energy> interfacePtMin
     ("minPt",
      "The pt cut on hardest emision generation"
      "2*(1-Beta)*exp(-sqr(intrinsicpT/RMS))/sqr(RMS)",
      &DrellYanBase::_min_pt, GeV, 2.*GeV, ZERO, 100000.0*GeV,
      false, false, Interface::limited);
 }
 
 void DrellYanBase::doinit() {
   HwMEBase::doinit();
   _channelweights.push_back(_channelwgtA/(1.+_channelwgtA));
   _channelweights.push_back(_channelweights[0]+1./(1.+_channelwgtA)/(1+_channelwgtB));
   _channelweights.push_back(1.0);
   _prefactor.push_back(_preqqbar);
   _prefactor.push_back(_preqg);
   _prefactor.push_back(_pregqbar);
 }
 
 void DrellYanBase::dofinish() {
   HwMEBase::dofinish();
   if(_nover==0) return;
   generator()->log() << "DrellYanBase when applying the hard correction " 
 		     << _nover << " weights larger than one were generated of which"
 		     << " the largest was " << _maxwgt << "\n";
 }
 
 RealEmissionProcessPtr DrellYanBase::applyHardMatrixElementCorrection(RealEmissionProcessPtr born) {
   // get the quark,antiquark
   ParticleVector incoming;
   vector<tcBeamPtr> beams;
   for(unsigned int ix=0;ix<born->bornIncoming().size();++ix) {
     incoming.push_back(born->bornIncoming()[ix]);
     tPPtr beam = born->hadrons()[ix];
     beams.push_back(dynamic_ptr_cast<tcBeamPtr>(beam->dataPtr()));
   }
   pair<double,double> xnew = born->x();
   // ensure that the quark is first
   if(incoming[0]->id()<incoming[1]->id()) {
     swap(incoming[0],incoming[1]);
     swap(beams[0],beams[1]);
     swap(xnew.first,xnew.second);
   } 
   // and the gauge boson
   Lorentz5Momentum pboson;
   for(unsigned int ix=0;ix<born->bornOutgoing().size();++ix) {
     pboson += born->bornOutgoing()[ix]->momentum();
   }
   pboson.rescaleMass();
   // calculate the momenta
   unsigned int iemit,itype;
   vector<Lorentz5Momentum> pnew;
   LorentzRotation trans;
   // if not accepted return
   if(!applyHard(incoming,beams,pboson,iemit,itype,pnew,trans,xnew)) return RealEmissionProcessPtr();
   // if applying ME correction create the new particles
   // first the final-state particles
   Boost boostv=pboson.findBoostToCM();
   trans *=LorentzRotation(boostv);
   born->transformation(trans);
   for(unsigned int ix=0;ix<born->bornOutgoing().size();++ix) {
     Lorentz5Momentum pnew = trans*(born->bornOutgoing()[ix]->momentum());
     born->outgoing().push_back(born->bornOutgoing()[ix]->dataPtr()->produceParticle(pnew));
   }
   // then emitter, spectator and emitted
   // emission of a final-state gluon
   if(itype==0) {
     // get the momenta of the new particles
     Lorentz5Momentum pquark(pnew[0]),panti(pnew[1]),pgluon(pnew[2]);
     if(iemit==2) swap(pquark,panti);
     // ensure gluon can be put on shell
     Lorentz5Momentum ptest(pgluon);
     if(ptest.boost(-(pquark+panti).boostVector()).e() < 
        getParticleData(ParticleID::g)->constituentMass()) return RealEmissionProcessPtr();
     // outgoing gluon
     born->outgoing().push_back(getParticleData(ParticleID::g)->produceParticle(pgluon));
     // incoming particles
     if(born->bornIncoming()[0]->id()>0) {
       if(iemit==1) {
   	born->emitter(0);
   	born->spectator(1);
       }
       else {
   	born->emitter(1);
   	born->spectator(0);
       }
       born->incoming().push_back(born->bornIncoming()[0]->dataPtr()->produceParticle(pquark));
       born->incoming().push_back(born->bornIncoming()[1]->dataPtr()->produceParticle(panti));
       born->outgoing().back()->incomingColour(born->incoming()[0]);
       born->outgoing().back()->incomingAntiColour(born->incoming()[1]);
     }
     else {
       if(iemit==1) {
   	born->emitter(1);
   	born->spectator(0);
       }
       else {
   	born->emitter(0);
   	born->spectator(1);
       }
       born->incoming().push_back(born->bornIncoming()[0]->dataPtr()->produceParticle(panti));
       born->incoming().push_back(born->bornIncoming()[1]->dataPtr()->produceParticle(pquark));
       born->outgoing().back()->incomingColour(born->incoming()[1]);
       born->outgoing().back()->incomingAntiColour(born->incoming()[0]);
     }
   }
   else if(itype==1) {
     Lorentz5Momentum pin(pnew[0]),pout(pnew[1]),pgluon(pnew[2]);
     if(iemit==2) swap(pin,pout);
     // ensure outgoing quark can be put on-shell
     Lorentz5Momentum ptest(pout);
     if(ptest.boost(-(pin+pgluon).boostVector()).e() < 
        incoming[1]->dataPtr()->constituentMass()) return RealEmissionProcessPtr();
     // create the new gluon
     PPtr newg  = getParticleData(ParticleID::g)->produceParticle(pgluon);
     // create the new outgoing quark
     PPtr newout= incoming[1]->dataPtr()->CC()->produceParticle(pout);
     // create the new incoming quark
     PPtr newin = incoming[0]->dataPtr()->produceParticle(pin);
     // colours
     newout->incomingColour(newg);
     newin->antiColourNeighbour(newg);
     if(born->bornIncoming()[0]->id()>0) {
       born->emitter  (1);
       born->spectator(0);
       born->incoming().push_back(newin);
       born->incoming().push_back(newg );
     }
     else {
       born->emitter  (0);
       born->spectator(1);
       born->incoming().push_back(newg );
       born->incoming().push_back(newin);
     }
     born->outgoing().push_back(newout);
   }
   else if(itype==2) {
     Lorentz5Momentum pin(pnew[0]),pout(pnew[1]),pgluon(pnew[2]);
     if(iemit==2) swap(pin,pout);
     // ensure outgoing antiquark can be put on-shell
      Lorentz5Momentum ptest(pout);
      if(ptest.boost(-(pin+pgluon).boostVector()).e() < 
         incoming[0]->dataPtr()->constituentMass()) return RealEmissionProcessPtr();
      // create the new gluon
      PPtr newg  = getParticleData(ParticleID::g)->produceParticle(pgluon);
      // create the new outgoing antiquark
      PPtr newout= incoming[0]->dataPtr()->CC()->produceParticle(pout);
      // create the new incoming antiquark
      PPtr newin = incoming[1]->dataPtr()->produceParticle(pin);
     // colours
     newout->incomingAntiColour(newg);
     newin->colourNeighbour(newg);
     if(born->bornIncoming()[0]->id()>0) {
       born->emitter  (0);
       born->spectator(1);
       born->incoming().push_back(newg );
       born->incoming().push_back(newin);
     }
     else {
       born->emitter  (1);
       born->spectator(0);
       born->incoming().push_back(newin);
       born->incoming().push_back(newg );
     }
     born->outgoing().push_back(newout);
   }
   else
     assert(false);
   born->emitted(born->outgoing().size()+1);
   if(born->bornIncoming()[0]->id()>0) {
     swap(xnew.first,xnew.second);
   }
   born->x(xnew);
   born->interaction(ShowerInteraction::QCD);
   return born;
 }
 
 bool DrellYanBase::applyHard(ParticleVector & quarks, 
 			     vector<tcBeamPtr> beams, Lorentz5Momentum boson,
 			     unsigned int & iemit,unsigned int & itype,
 			     vector<Lorentz5Momentum> & pnew,
 			     LorentzRotation & trans, 
 			     pair<double,double> & xout) {
   // check that quark along +z and qbar along -z
   bool quarkplus=quarks[0]->momentum().z()>quarks[1]->momentum().z();
   // calculate the limits on s
   Energy mb = sqrt(mb2_);
   Energy2 smin=mb2_;
   Energy2 s=
     (generator()->currentEvent()->incoming().first ->momentum()+
      generator()->currentEvent()->incoming().second->momentum()).m2();
   Energy2 smax(s);
   // calculate the rapidity of the boson
   double yB=0.5*log((boson.e()+boson.z())/
 		    (boson.e()-boson.z()));
   if(!quarkplus) yB=-yB;
   // if no phase-space return
   if(smax<smin) return false;
   // get the evolution scales (this needs improving)
   double kappa[2]={1.,1.};
   // get the momentum fractions for the leading order process
   // and the values of the PDF's
   double x[2]={-99.99e99,-99.99e99}, fx[2]={-99.99e99,-99.99e99};
   tcPDFPtr pdf[2];
   x[0] = xout. first;
   x[1] = xout.second;
   for(unsigned int ix=0;ix<quarks.size();++ix) {
     assert(beams[ix]);
     pdf[ix]=beams[ix]->pdf();
     assert(pdf[ix]);
     fx[ix]=pdf[ix]->xfx(beams[ix],quarks[ix]->dataPtr(),mb2_,x[ix]);
   }
   // select the type of process and generate the kinematics
   double rn(UseRandom::rnd());
   Energy2 shat(ZERO),uhat(ZERO),that(ZERO);
   double weight(0.),xnew[2]={1.,1.};
   // generate the value of s according to 1/s^2
   shat = smax*smin/(smin+UseRandom::rnd()*(smax-smin));
   Energy2 jacobian = sqr(shat)*(1./smin-1./smax);
   double sbar=shat/mb2_;
   // calculate limits on that
   Energy2 tmax=mb2_*kappa[0]*(1.-sbar)/(kappa[0]+sbar);
   Energy2 tmin=shat*(1.-sbar)/(kappa[1]+sbar);
   // calculate the limits on uhat
   Energy2 umax(mb2_-shat-tmin),umin(mb2_-shat-tmax);
   // check inside phase space
   if(tmax<tmin||umax<umin) return false;
   // q qbar -> g V
   if(rn<_channelweights[0]) {
     // generate t and u according to 1/t+1/u
     // generate in 1/t
     if(UseRandom::rndbool(0.5)) {
       that=tmax*pow(tmin/tmax,UseRandom::rnd());
       uhat=mb2_-shat-that;
       jacobian *=log(tmin/tmax);
     }
     // generate in 1/u
     else {
       uhat=umax*pow(umin/umax,UseRandom::rnd());
       that=mb2_-shat-uhat;
       jacobian *=log(umin/umax);
     }
     Energy4 jacobian2 = jacobian * 2.*uhat*that/(shat-mb2_);
     // new scale (this is mt^2=pt^2+mb^2)
     Energy2 scale(uhat*that/shat+mb2_);
     // the PDF's with the emitted gluon
     double fxnew[2];
     xnew[0]=exp(yB)/sqrt(s)*sqrt(shat*(mb2_-uhat)/(mb2_-that));
     xnew[1]=shat/(s*xnew[0]);
     for(unsigned int ix=0;ix<2;++ix)
       {fxnew[ix]=pdf[ix]->xfx(beams[ix],quarks[ix]->dataPtr(),scale,xnew[ix]);}
     // jacobian and me parts of the weight
     weight=jacobian2*(sqr(mb2_-that)+sqr(mb2_-uhat))/(sqr(shat)*that*uhat);
     // pdf part of the weight
     weight *=fxnew[0]*fxnew[1]*x[0]*x[1]/(fx[0]*fx[1]*xnew[0]*xnew[1]);
     // finally coupling, colour factor and different channel pieces
     weight *= 2./3./Constants::pi/_channelweights[0]*_alpha->value(scale);
     // select the emiting particle
     iemit=1;
     if(UseRandom::rnd()<sqr(mb2_-uhat)/(sqr(mb2_-uhat)+sqr(mb2_-that))) iemit=2;
     itype=0;
   }
   // incoming gluon
   else {
     // generate t 
     if(rn>_channelweights[1]) {
       swap(tmax,tmin);
       tmax=mb2_-shat-tmax;
       tmin=mb2_-shat-tmin;
     }
     that=tmax*pow(tmin/tmax,UseRandom::rnd());
     uhat=mb2_-shat-that;
     Energy4 jacobian2 = jacobian * that*log(tmax/tmin);
     // new scale (this is mt^2=pt^2+mb^2)
     Energy2 scale(uhat*that/shat+mb2_);
     // g qbar -> qbar V 
     double fxnew[2];
     if(rn<_channelweights[1]) {
       itype=2;
       xnew[0]=exp(yB)/sqrt(s)*sqrt(shat*(mb2_-uhat)/(mb2_-that));
       xnew[1]=shat/(s*xnew[0]);
       fxnew[0]=pdf[0]->xfx(beams[0],getParticleData(ParticleID::g),scale,xnew[0]);
       fxnew[1]=pdf[1]->xfx(beams[1],quarks[1]->dataPtr(),scale,xnew[1]);
       jacobian2/=(_channelweights[1]-_channelweights[0]);
     }
     // q g -> q V 
     else {
       itype=1;
       xnew[0]=exp(yB)/sqrt(s)*sqrt(shat*(mb2_-that)/(mb2_-uhat));
       xnew[1]=shat/(s*xnew[0]);
       fxnew[0]=pdf[0]->xfx(beams[0],quarks[0]->dataPtr(),scale,xnew[0]);
       fxnew[1]=pdf[1]->xfx(beams[1],getParticleData(ParticleID::g),scale,xnew[1]);
       jacobian2/=(_channelweights[2]-_channelweights[1]);
     }
     // jacobian and me parts of the weight
     weight=-jacobian2*(sqr(mb2_-that)+sqr(mb2_-shat))/(sqr(shat)*shat*that);
     // pdf part of the weight
     weight *=fxnew[0]*fxnew[1]*x[0]*x[1]/(fx[0]*fx[1]*xnew[0]*xnew[1]);
     // finally coupling, colour factor and different channel pieces
     weight *= 0.25/Constants::pi*_alpha->value(scale);
     // select the emiting particle
     iemit=1;
     if(UseRandom::rnd()<sqr(mb2_-that)/(sqr(mb2_-that)+sqr(mb2_-shat))) iemit=2;
   }
   // if me correction should be applied
   if(weight>1.) {
     ++_nover;
     _maxwgt=max(_maxwgt,weight);
     weight=1.;
   }
   if(UseRandom::rnd()>weight) return false;
   // construct the momenta in the rest frame of the boson
   Lorentz5Momentum pb(ZERO,ZERO,ZERO,mb,mb),pspect,pg,pemit;
   double cos3 = 0.0;
   if(itype==0)
     {
       pg     = Lorentz5Momentum(ZERO,ZERO,ZERO,0.5*(shat-mb2_)/mb,ZERO);
       Energy2 tp(that),up(uhat);
       double zsign(-1.);
       if(iemit==2)
 	{
 	  tp=uhat;
 	  up=that;
 	  zsign=1.;
 	}
       pspect = Lorentz5Momentum(ZERO,ZERO,zsign*0.5*(mb2_-tp)/mb,
 				0.5*(mb2_-tp)/mb,ZERO);
       Energy eemit=0.5*(mb2_-up)/mb;
       cos3 = 0.5/pspect.z()/pg.e()*(sqr(pspect.e())+sqr(pg.e())-sqr(eemit));
     }
   else
     {
       pg=Lorentz5Momentum(ZERO,ZERO,ZERO,0.5*(mb2_-uhat)/mb,ZERO);
       double zsign(1.);
       if(iemit==1)
 	{
 	  if(itype==1) zsign=-1.;
 	  pspect=Lorentz5Momentum(ZERO,ZERO,0.5*zsign*(shat-mb2_)/mb,
 				  0.5*(shat-mb2_)/mb);
 	  Energy eemit=0.5*(mb2_-that)/mb;
 	  cos3 = 0.5/pspect.z()/pg.e()*(sqr(pspect.e())+sqr(pg.e())-sqr(eemit));
 	}
       else
 	{
 	  if(itype==2) zsign=-1.;
 	  pspect=Lorentz5Momentum(ZERO,ZERO,0.5*zsign*(mb2_-that)/mb,
 				  0.5*(mb2_-that)/mb);
 	  Energy eemit=0.5*(shat-mb2_)/mb;
 	  cos3 = 0.5/pspect.z()/pg.e()*(-sqr(pspect.e())-sqr(pg.e())+sqr(eemit));
 	}
     }
 
   // rotate the gluon
   double sin3(sqrt(1.-sqr(cos3)));
   double phi(Constants::twopi*UseRandom::rnd());
   pg.setX(pg.e()*sin3*cos(phi));
   pg.setY(pg.e()*sin3*sin(phi));
   pg.setZ(pg.e()*cos3);
   if(itype==0) {
     pemit=pb+pg-pspect;
   }
   else {
     if(iemit==1) pemit=pb+pspect-pg;
     else         pemit=pspect+pg-pb;
   }
   pemit.rescaleMass();
   // find the new CMF
   Lorentz5Momentum pp[2];
   if(itype==0) {
     if(iemit==1) {
       pp[0]=pemit;
       pp[1]=pspect;
     }
     else {
       pp[0]=pspect;
       pp[1]=pemit;
     }
   }
   else if(itype==1) {
     pp[1]=pg;
     if(iemit==1) pp[0]=pemit;
     else         pp[0]=pspect;
   }
   else {
     pp[0]=pg;
     if(iemit==1) pp[1]=pemit;
     else         pp[1]=pspect;
   }
   Lorentz5Momentum pz= quarkplus ? pp[0] : pp[1];
   pp[0]/=xnew[0];
   pp[1]/=xnew[1];
   Lorentz5Momentum plab(pp[0]+pp[1]);
   plab.rescaleMass();
   // construct the boost to rest frame of plab
   trans=LorentzRotation(plab.findBoostToCM());
   pz.transform(trans);
   // rotate so emitting particle along z axis
   // rotate so in x-z plane
   trans.rotateZ(-atan2(pz.y(),pz.x()));
   // rotate so along
   trans.rotateY(-acos(pz.z()/pz.vect().mag()));
   // undo azimuthal rotation
   trans.rotateZ(atan2(pz.y(),pz.x()));
   // perform the transforms
   pb    .transform(trans);
   pspect.transform(trans);
   pg    .transform(trans);
   pemit .transform(trans);
   // momenta to be returned
   pnew.push_back(pemit);
   pnew.push_back(pspect);
   pnew.push_back(pg);
   pnew.push_back(pb);
   xout.first=xnew[0];
   xout.second=xnew[1];
   return true;
 }
 
 bool DrellYanBase::softMatrixElementVeto(ShowerProgenitorPtr initial,
 					 ShowerParticlePtr parent,Branching br) {
   if(parent->isFinalState()) return false;
   // check if me correction should be applied
   long id[2]={initial->id(),parent->id()};
   if(id[0]!=id[1]||id[1]==ParticleID::g) return false;
   // get the pT
   Energy pT=br.kinematics->pT();
   // check if hardest so far
   if(pT<initial->highestpT()) return false;
   // compute the invariants
   double kappa(sqr(br.kinematics->scale())/mb2_),z(br.kinematics->z());
   Energy2 shat(mb2_/z*(1.+(1.-z)*kappa)),that(-(1.-z)*kappa*mb2_),uhat(-(1.-z)*shat);
   // check which type of process
   // g qbar 
   double wgt(1.);
   if(id[0]>0&&br.ids[0]->id()==ParticleID::g)
     wgt=mb2_/(shat+uhat)*(sqr(mb2_-that)+sqr(mb2_-shat))/(sqr(shat+uhat)+sqr(uhat));
   else if(id[0]>0&&br.ids[0]->id()==id[0])
     wgt=mb2_/(shat+uhat)*(sqr(mb2_-uhat)+sqr(mb2_-that))/(sqr(shat)+sqr(shat+uhat));
   else if(id[0]<0&&br.ids[0]->id()==ParticleID::g)
     wgt=mb2_/(shat+uhat)*(sqr(mb2_-that)+sqr(mb2_-shat))/(sqr(shat+uhat)+sqr(uhat));
-  else if(id[0]<0&&br.ids[0]->id()==-id[0])
+  else if(id[0]<0&&br.ids[0]->id()==id[0])
     wgt=mb2_/(shat+uhat)*(sqr(mb2_-uhat)+sqr(mb2_-that))/(sqr(shat)+sqr(shat+uhat));
-  else return false;
+  else 
+    return false;
   if(wgt<.0||wgt>1.) generator()->log() << "Soft ME correction weight too large or "
 					<< "negative in DrellYanBase::"
 					<< "softMatrixElementVeto()soft weight " 
 					<< " sbar = " << shat/mb2_ 
 					<< " tbar = " << that/mb2_ 
 					<< "weight = " << wgt << "\n";
   // if not vetoed
   if(UseRandom::rndbool(wgt)) return false;
   // otherwise
   parent->vetoEmission(br.type,br.kinematics->scale());
   return true;
 }
 
 RealEmissionProcessPtr DrellYanBase::generateHardest(RealEmissionProcessPtr born,
 						      ShowerInteraction::Type inter) {
   if(inter==ShowerInteraction::QED) return RealEmissionProcessPtr();
   useMe();
   // get the particles to be showered
   _beams.clear();
   _partons.clear();
   // find the incoming particles
   ParticleVector incoming;
   _quarkplus = true;
   ParticleVector particlesToShower;
   // progenitor particles are produced in z direction.
   for(unsigned int ix=0;ix<born->bornIncoming().size();++ix) {
     incoming.push_back(born->bornIncoming()[ix]);
     tPPtr beam = born->hadrons()[ix];
     _beams.push_back(dynamic_ptr_cast<tcBeamPtr>(beam->dataPtr()));
     _partons.push_back( born->bornIncoming()[ix]->dataPtr() );
     // check that quark is along +ve z direction
     if(born->bornIncoming()[ix]->id() > 0 &&
        born->bornIncoming()[ix]->momentum().z() < ZERO ) 
       _quarkplus = false;
     particlesToShower.push_back( born->bornIncoming()[ix] );
   }
   Lorentz5Momentum pboson;
   for(unsigned int ix=0;ix<born->bornOutgoing().size();++ix) {
     pboson += born->bornOutgoing()[ix]->momentum();
   }
   pboson.rescaleMass();
   // calculate the rapidity of the boson
   _yb = 0.5 * log((pboson.e()+pboson.z())/(pboson.e()-pboson.z()));
   _yb *= _quarkplus ? 1. : -1.;
   _mass = pboson.mass();
   // we are assuming quark first, swap order to ensure this
   // if antiquark first
   bool order = _partons[0]->id()<_partons[1]->id(); 
   if(order) {
     swap(_partons[0],_partons[1]);
     swap(_beams[0],_beams[1]);
   }
   vector<Lorentz5Momentum> pnew;
   int emission_type(-1);
   // generate the hard emission and return if no emission
   if(!getEvent(pnew,emission_type)) {
     born->pT()[ShowerInteraction::QCD] =  _min_pt;
     return born;
   }
   // construct the HardTree object needed to perform the showers
   ParticleVector newparticles;
   // make the particles for the HardTree
   tcPDPtr gluon=getParticleData(ParticleID::g);
   // create the partons
   int iemit;
   // q qbar -> g V
   ColinePtr newline[2]={new_ptr(ColourLine()),new_ptr(ColourLine())};
   if(emission_type==0) {
     newparticles.push_back(_partons[0]->produceParticle(pnew[0]));
     newparticles.push_back(_partons[1]->produceParticle(pnew[1]));
     newparticles.push_back(gluon      ->produceParticle(pnew[2]));
     newline[1]->addColoured(newparticles[0]);
     newline[1]->addColoured(newparticles[2]);
     newline[0]->addAntiColoured(newparticles[1]);
     newline[0]->addAntiColoured(newparticles[2]);
     iemit = (pnew[0]-pnew[2]).m2()>(pnew[1]-pnew[2]).m2() ? 0 : 1;
   }
   // q g    -> q V
   else if(emission_type==1) {
     iemit =1;
     newparticles.push_back(_partons[0]->produceParticle(pnew[0]));
     newparticles.push_back(gluon      ->produceParticle(pnew[1]));
     newparticles.push_back(_partons[1]->CC()->produceParticle(pnew[2]));
     newline[1]->addColoured(newparticles[0]);
     newline[1]->addAntiColoured(newparticles[1]);
     newline[0]->addColoured(newparticles[1]);
     newline[0]->addColoured(newparticles[2]);
   }
   // g qbar -> qbar V
   else {
     iemit =0;
     newparticles.push_back(gluon      ->produceParticle(pnew[0]));
     newparticles.push_back(_partons[1]->produceParticle(pnew[1]));
     newparticles.push_back(_partons[0]->CC()->produceParticle(pnew[2]));
     newline[0]->addAntiColoured(newparticles[1]);
     newline[0]->addColoured(newparticles[0]);
     newline[1]->addAntiColoured(newparticles[0]);
     newline[1]->addAntiColoured(newparticles[2]);
   }
   int ispect = iemit == 0 ? 1 : 0;
   if(iemit==0) newline[0]->addColoured(newparticles.back());
   else         newline[1]->addAntiColoured(newparticles.back());
   // compute the boost for the bosons
   LorentzRotation boost(pboson.findBoostToCM());
   boost.boost(pnew[3].boostVector());
   born->transformation(boost);
   for(unsigned int ix=0;ix<born->bornOutgoing().size();++ix) {
     born->outgoing().push_back(born->bornOutgoing()[ix]->dataPtr()->
 			       produceParticle(born->bornOutgoing()[ix]->momentum()));
     born->outgoing().back()->transform(boost);
   }
   if(!order) {
     born->incoming().push_back(newparticles[0]);
     born->incoming().push_back(newparticles[1]);
   }
   else {
     born->incoming().push_back(newparticles[1]);
     born->incoming().push_back(newparticles[0]);
     swap(iemit,ispect);
   }
   born->outgoing().push_back(newparticles[2]);
   born->emitter  (iemit );
   born->spectator(ispect);
   born->emitted(born->bornOutgoing().size()+2);
   pair<double,double> xnew;
   for(unsigned int ix=0;ix<2;++ix) {
     double x = born->incoming()[ix]->momentum().rho()/born->hadrons()[ix]->momentum().rho();
     if(ix==0) xnew.first  = x;
     else      xnew.second = x;
   }
   born->x(xnew);
   born->pT()[ShowerInteraction::QCD] = _pt;
   born->interaction(ShowerInteraction::QCD);
   return born;
 }
 
 double DrellYanBase::getResult(int emis_type, Energy pt, double yj) {
   Energy2 s=sqr(generator()->maximumCMEnergy());
   Energy2 m2(sqr(_mass));
   Energy2 scale = m2+sqr(pt);
   Energy  et=sqrt(scale);
   // longitudinal real correction fractions
   double x  = pt*exp( yj)/sqrt(s)+et*exp( _yb)/sqrt(s);
   double y  = pt*exp(-yj)/sqrt(s)+et*exp(-_yb)/sqrt(s);
   // reject if outside region
   if(x<0.||x>1.||y<0.||y>1.||x*y<m2/s) return 0.;
   // longitudinal born fractions
   double x1 = _mass*exp( _yb)/sqrt(s);          
   double y1 = _mass*exp(-_yb)/sqrt(s);
   // mandelstam variables
   Energy2 th = -sqrt(s)*x*pt*exp(-yj);
   Energy2 uh = -sqrt(s)*y*pt*exp( yj);
   Energy2 sh = m2-th-uh;
   double res;
   // pdf part of the cross section
   double pdf[4];
   pdf[0]=_beams[0]->pdf()->xfx(_beams[0],_partons[0],m2,x1);
   pdf[1]=_beams[1]->pdf()->xfx(_beams[1],_partons[1],m2,y1);
   //qqbar2Zg
   using Constants::pi;
   if(emis_type==0) {
     pdf[2]=_beams[0]->pdf()->xfx(_beams[0],_partons[0],scale,x);
     pdf[3]=_beams[1]->pdf()->xfx(_beams[1],_partons[1],scale,y);
     res = 4./3./pi*(sqr(th-m2)+sqr(uh-m2))*pt/(sh*uh*th)*GeV;
   }
   //qg2Zq
   else if(emis_type==1) {
     pdf[2]=_beams[0]->pdf()->xfx(_beams[0],_partons[0],scale,x);
     pdf[3]=_beams[1]->pdf()->xfx(_beams[1],getParticleData(ParticleID::g),scale,y);
     res = -1./2./pi*(sqr(uh-m2)+sqr(sh-m2))*pt/(sh*sh*uh)*GeV;
   }
   //qbarg2Zqbar
   else {
     pdf[2]=_beams[0]->pdf()->xfx(_beams[0],getParticleData(ParticleID::g),scale,x);
     pdf[3]=_beams[1]->pdf()->xfx(_beams[1],_partons[1],scale,y);
     res =- 1./2./pi*(sqr(th-m2)+sqr(sh-m2))*pt/(sh*sh*th)*GeV;
   }  
   //deals with pdf zero issue at large x
   if(pdf[0]<=0.||pdf[1]<=0.||pdf[2]<=0.||pdf[3]<=0.) {
     res=0.;
   }
   else {
     res*=pdf[2]*pdf[3]/pdf[0]/pdf[1]*m2/sh;
   }
   res*=_alpha->ratio(sqr(pt));
   return res;
 } 
 
 bool DrellYanBase::getEvent(vector<Lorentz5Momentum> & pnew, 
 				     int & emis_type){
   // pt cut-off
   // Energy minp = 0.1*GeV;  
   // maximum pt (half of centre-of-mass energy)
   Energy maxp = 0.5*generator()->maximumCMEnergy();
   // set pt of emission to zero
   _pt=ZERO;
   //Working Variables
   Energy pt;
   double yj;
   // limits on the rapidity of the jet
   double minyj = -8.0,maxyj = 8.0;
   bool reject;
   double wgt;
   emis_type=-1;
   for(int j=0;j<3;j++) {
     pt=maxp;
     double a = _alpha->overestimateValue()*_prefactor[j]*(maxyj-minyj)/(_power-1.);
     do {
       // generate next pt
       pt=GeV/pow(pow(GeV/pt,_power-1)-log(UseRandom::rnd())/a,1./(_power-1.));
       // generate rapidity of the jet
       yj=UseRandom::rnd()*(maxyj-minyj)+ minyj;
       // calculate rejection weight
       wgt=getResult(j,pt,yj);
       wgt/= _prefactor[j]*pow(GeV/pt,_power);
       reject = UseRandom::rnd()>wgt;
       //no emission event if p goes past p min - basically set to outside
       //of the histogram bounds (hopefully hist object just ignores it)
       if(pt<_min_pt){
 	pt=ZERO;
 	reject = false;
       }
       if(wgt>1.0) {
 	ostringstream s;
 	s << "DrellYanBase::getEvent weight for channel " << j
 	  << "is " << wgt << " which is greater than 1";
 	generator()->logWarning( Exception(s.str(), Exception::warning) );
       }
     }
     while(reject);
     // set pt of emission etc
     if(pt>_pt){
       emis_type = j;
       _pt=pt;
       _yj=yj;
     }
   }
   //was this an (overall) no emission event?
   if(_pt<_min_pt){ 
     _pt=ZERO;
     emis_type = 3;
   }
   if(emis_type==3) return false;
   // generate the momenta of the particles
   // hadron-hadron cmf
   Energy2 s=sqr(generator()->maximumCMEnergy());
   // transverse energy
   Energy2 m2(sqr(_mass));
   Energy et=sqrt(m2+sqr(_pt));
   // first calculate all the kinematic variables
   // longitudinal real correction fractions
   double x  = _pt*exp( _yj)/sqrt(s)+et*exp( _yb)/sqrt(s);
   double y  = _pt*exp(-_yj)/sqrt(s)+et*exp(-_yb)/sqrt(s);
   // that and uhat
   Energy2 th = -sqrt(s)*x*_pt*exp(-_yj);
   Energy2 uh = -sqrt(s)*y*_pt*exp( _yj);
   Energy2 sh = x*y*s;
   if(emis_type==1) swap(th,uh); 
   // decide which was the emitting particle
   unsigned int iemit=1;
   // from q qbar
   if(emis_type==0) {
     if(UseRandom::rnd()<sqr(m2-uh)/(sqr(m2-uh)+sqr(m2-th))) iemit=2;
   }
   else {
     if(UseRandom::rnd()<sqr(m2-th)/(sqr(m2-th)+sqr(m2-sh))) iemit=2;
   }
   // reconstruct the momenta in the rest frame of the gauge boson
   Lorentz5Momentum pb(ZERO,ZERO,ZERO,_mass,_mass),pspect,pg,pemit;
   double cos3;
   if(emis_type==0) {
     pg=Lorentz5Momentum(ZERO,ZERO,ZERO,0.5*(sh-m2)/_mass,ZERO);
     Energy2 tp(th),up(uh);
     double zsign(-1.);
     if(iemit==2) {
       swap(tp,up);
       zsign=1;
     }
     pspect = Lorentz5Momentum(ZERO,ZERO
 			      ,zsign*0.5*(m2-tp)/_mass,0.5*(m2-tp)/_mass,
 			      ZERO);
     Energy eemit=0.5*(m2-up)/_mass;
     cos3 = 0.5/pspect.z()/pg.e()*(sqr(pspect.e())+sqr(pg.e())-sqr(eemit));
   }
   else {
     pg=Lorentz5Momentum(ZERO,ZERO,ZERO,0.5*(m2-uh)/_mass,ZERO);
     double zsign(1.);
     if(iemit==1) {
       if(emis_type==1) zsign=-1.;
       pspect=Lorentz5Momentum(ZERO,ZERO,0.5*zsign*(sh-m2)/_mass,0.5*(sh-m2)/_mass);
       Energy eemit=0.5*(m2-th)/_mass;
       cos3 = 0.5/pspect.z()/pg.e()*(sqr(pspect.e())+sqr(pg.e())-sqr(eemit));
     }
     else {
       if(emis_type==2) zsign=-1.;
       pspect=Lorentz5Momentum(ZERO,ZERO,0.5*zsign*(m2-th)/_mass,0.5*(m2-th)/_mass);
       Energy eemit=0.5*(sh-m2)/_mass;
       cos3 = 0.5/pspect.z()/pg.e()*(-sqr(pspect.e())-sqr(pg.e())+sqr(eemit));
     }
   }
   // rotate the gluon
   double sin3(sqrt(1.-sqr(cos3))),phi(Constants::twopi*UseRandom::rnd());
   pg.setX(pg.e()*sin3*cos(phi));
   pg.setY(pg.e()*sin3*sin(phi));
   pg.setZ(pg.e()*cos3);
   if(emis_type==0) {
     pemit=pb+pg-pspect;
   }
   else {
     if(iemit==1) pemit=pb+pspect-pg;
     else         pemit=pspect+pg-pb;
   }
   pemit .setMass(ZERO);
   pg    .setMass(ZERO);
   pspect.setMass(ZERO);
   // find the new CMF
   Lorentz5Momentum pp[2];
   if(emis_type==0) {
     pp[0]=pemit;
     pp[1]=pspect;
     if(iemit==2) swap(pp[0],pp[1]);
   }
   else if(emis_type==1) {
     pp[1]=pg;
     if(iemit==1) pp[0]=pemit;
     else         pp[0]=pspect;
   }
   else {
     pp[0]=pg;
     if(iemit==1) pp[1]=pemit;
     else         pp[1]=pspect;
   }
   Lorentz5Momentum pz= _quarkplus ? pp[0] : pp[1];
   pp[0]/=x;
   pp[1]/=y;
   Lorentz5Momentum plab(pp[0]+pp[1]);
   plab.rescaleMass();
   // construct the boost to rest frame of plab
   LorentzRotation trans=LorentzRotation(plab.findBoostToCM());
   pz.transform(trans);
   // rotate so emitting particle along z axis
   // rotate so in x-z plane
   trans.rotateZ(-atan2(pz.y(),pz.x()));
   // rotate so along
   trans.rotateY(-acos(pz.z()/pz.vect().mag()));
   // undo azimuthal rotation
   trans.rotateZ(atan2(pz.y(),pz.x()));
   // perform the transforms
   pb    .transform(trans);
   pspect.transform(trans);
   pg    .transform(trans);
   pemit .transform(trans);
   // copy the momenta for the new particles
   pnew.resize(4);
   if(emis_type==0) {
     pnew[0]=pemit;
     pnew[1]=pspect;
     if(iemit==2) swap(pnew[0],pnew[1]);
     pnew[2]=pg;
   }
   else if(emis_type==1) {
     pnew[0]=pemit;
     pnew[2]=pspect;
     if(iemit==2) swap(pnew[0],pnew[2]);
     pnew[1]=pg;
   }
   else if(emis_type==2) {
     pnew[1]=pspect;
     pnew[2]=pemit;
     if(iemit==1) swap(pnew[1],pnew[2]);
     pnew[0]=pg;
   }
   pnew[3]=pb;
   return true;
 }
diff --git a/Shower/QTilde/Base/PartnerFinder.cc b/Shower/QTilde/Base/PartnerFinder.cc
--- a/Shower/QTilde/Base/PartnerFinder.cc
+++ b/Shower/QTilde/Base/PartnerFinder.cc
@@ -1,536 +1,535 @@
 // -*- C++ -*-
 //
 // PartnerFinder.cc is a part of Herwig - A multi-purpose Monte Carlo event generator
 // Copyright (C) 2002-2011 The Herwig Collaboration
 //
 // Herwig is licenced under version 2 of the GPL, see COPYING for details.
 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
 //
 //
 // This is the implementation of the non-inlined, non-templated member
 // functions of the PartnerFinder class.
 //
 
 #include "PartnerFinder.h"
 #include "ThePEG/Interface/ClassDocumentation.h"
 #include "ThePEG/Interface/Parameter.h"
 #include "ThePEG/Repository/EventGenerator.h"
 #include "ThePEG/Persistency/PersistentOStream.h"
 #include "ThePEG/Persistency/PersistentIStream.h"
 #include "ShowerParticle.h"
 #include "ThePEG/Repository/UseRandom.h" 
 #include "ThePEG/Interface/Switch.h"
 #include "ThePEG/Utilities/Debug.h"
 #include "ThePEG/Utilities/DescribeClass.h"
 
 using namespace Herwig;
 
 DescribeAbstractClass<PartnerFinder,Interfaced>
 describePartnerFinder ("Herwig::PartnerFinder","HwShower.so");
 
 // some useful functions to avoid using #define
 namespace {
 
   // return bool if final-state particle
   inline bool FS(const tShowerParticlePtr a) {
     return a->isFinalState();
   }
 
   // return colour line pointer 
   inline Ptr<ThePEG::ColourLine>::transient_pointer  
   CL(const tShowerParticlePtr a, unsigned int index=0) {
     return a->colourInfo()->colourLines().empty() ? ThePEG::tColinePtr() :
       const_ptr_cast<ThePEG::tColinePtr>(a->colourInfo()->colourLines()[index]);
   }
 
   // return colour line size
   inline unsigned int
   CLSIZE(const tShowerParticlePtr a) {
     return a->colourInfo()->colourLines().size();
   }
   
   inline Ptr<ThePEG::ColourLine>::transient_pointer
   ACL(const tShowerParticlePtr a, unsigned int index=0) {
     return a->colourInfo()->antiColourLines().empty() ?  ThePEG::tColinePtr() :
       const_ptr_cast<ThePEG::tColinePtr>(a->colourInfo()->antiColourLines()[index]);
   }
 
   inline unsigned int
   ACLSIZE(const tShowerParticlePtr a) {
     return a->colourInfo()->antiColourLines().size();
   }
 }
 
 void PartnerFinder::persistentOutput(PersistentOStream & os) const {
   os << partnerMethod_ << QEDPartner_ << scaleChoice_;
 }
 
 void PartnerFinder::persistentInput(PersistentIStream & is, int) {
   is >> partnerMethod_ >> QEDPartner_ >> scaleChoice_;
 }
 
 void PartnerFinder::Init() {
 
   static ClassDocumentation<PartnerFinder> documentation
     ("This class is responsible for finding the partners for each interaction types ",
      "and within the evolution scale range specified by the ShowerVariables ",
      "then to determine the initial evolution scales for each pair of partners.");
 
   static Switch<PartnerFinder,int> interfacePartnerMethod
     ("PartnerMethod",
      "Choice of partner finding method for gluon evolution.",
      &PartnerFinder::partnerMethod_, 0, false, false);
   static SwitchOption interfacePartnerMethodRandom
     (interfacePartnerMethod,
      "Random",
      "Choose partners of a gluon randomly.",
      0);
   static SwitchOption interfacePartnerMethodMaximum
     (interfacePartnerMethod,
      "Maximum",
      "Choose partner of gluon with largest angle.",
      1);
 
   static Switch<PartnerFinder,int> interfaceQEDPartner
     ("QEDPartner",
      "Control of which particles to use as the partner for QED radiation",
      &PartnerFinder::QEDPartner_, 0, false, false);
   static SwitchOption interfaceQEDPartnerAll
     (interfaceQEDPartner,
      "All",
      "Consider all possible choices which give a positive contribution"
      " in the soft limit.",
      0);
   static SwitchOption interfaceQEDPartnerIIandFF
     (interfaceQEDPartner,
      "IIandFF",
      "Only allow initial-initial or final-final combinations",
      1);
   static SwitchOption interfaceQEDPartnerIF
     (interfaceQEDPartner,
      "IF",
      "Only allow initial-final combinations",
      2);
 
   static Switch<PartnerFinder,int> interfaceScaleChoice
     ("ScaleChoice",
      "The choice of the evolution scales",
      &PartnerFinder::scaleChoice_, 0, false, false);
   static SwitchOption interfaceScaleChoicePartner
     (interfaceScaleChoice,
      "Partner",
      "Scale of all interactions is that of the evolution partner",
      0);
   static SwitchOption interfaceScaleChoiceDifferent
     (interfaceScaleChoice,
      "Different",
      "Allow each interaction to have different scales",
      1);
 
 }
 
 void PartnerFinder::setInitialEvolutionScales(const ShowerParticleVector &particles,
 					      const bool isDecayCase,
 					      ShowerInteraction::Type type,
 					      const bool setPartners) {
   // clear the existing partners
   for(ShowerParticleVector::const_iterator cit = particles.begin();
       cit != particles.end(); ++cit) (*cit)->clearPartners();
   // set them
   if(type==ShowerInteraction::QCD) {
     setInitialQCDEvolutionScales(particles,isDecayCase,setPartners);
   }
   else if(type==ShowerInteraction::QED) {
     setInitialQEDEvolutionScales(particles,isDecayCase,setPartners);
   }
   else {
     setInitialQCDEvolutionScales(particles,isDecayCase,setPartners);
     setInitialQEDEvolutionScales(particles,isDecayCase,false);
   }
   // print out for debugging
   if(Debug::level>=10) {
     for(ShowerParticleVector::const_iterator cit = particles.begin();
 	cit != particles.end(); ++cit) {
       generator()->log() << "Particle: " << **cit << "\n";
       if(!(**cit).partner()) continue;
       generator()->log() << "Primary partner: " << *(**cit).partner() << "\n";
       for(vector<ShowerParticle::EvolutionPartner>::const_iterator it= (**cit).partners().begin();
 	  it!=(**cit).partners().end();++it) {
 	generator()->log() << it->type << " " << it->weight << " " 
 			   << it->scale/GeV << " " 
  			   << *(it->partner) 
 			   << "\n";
       }
     }
     generator()->log() << flush;
   }
 }
 
 void PartnerFinder::setInitialQCDEvolutionScales(const ShowerParticleVector &particles,
                                                  const bool isDecayCase,
                                                  const bool setPartners) {
   // set the partners and the scales
   if(setPartners) {
     // Loop over  particles  and consider only coloured particles which don't
     // have already their colour partner fixed and that don't have children
     // (the latter requirement is relaxed in the case isDecayCase is true). 
     // Build a map which has as key one of these particles (i.e. a pointer 
     // to a ShowerParticle object) and as a corresponding value the vector
     // of all its possible *normal* candidate colour partners, defined as follows:
     //  --- have colour, and no children (this is not required in the case 
     //      isDecayCase is true);
     //  --- if both are initial (incoming) state particles, then the (non-null) colourLine() 
     //      of one of them must match the (non-null) antiColourLine() of the other.
     //  --- if one is an initial (incoming) state particle and the other is
     //      a final (outgoing) state particle,  then both must have the
     //      same (non-null) colourLine() or the same (non-null) antiColourLine();
     // Notice that this definition exclude the special case of baryon-violating
     // processes (as in R-parity Susy), which will show up as particles
     // without candidate colour partners, and that we will be treated a part later
     // (this means that no modifications of the following loop is needed!)
     ShowerParticleVector::const_iterator cit, cjt;
     for(cit = particles.begin(); cit != particles.end(); ++cit) {
       // Skip colourless particles
       if(!(*cit)->data().coloured()) continue;
       // find the partners
       vector< pair<ShowerPartnerType::Type, tShowerParticlePtr> > partners = 
 	findQCDPartners(*cit,particles);
       // must have a partner
       if(partners.empty()) {
 	throw Exception() << "`Failed to make colour connections in " 
                           << "PartnerFinder::setQCDInitialEvolutionScales"
                           << (**cit)
                           << Exception::eventerror;
       }
       // Calculate the evolution scales for all possible pairs of of particles
       vector<pair<Energy,Energy> > scales;
       for(unsigned int ix=0;ix< partners.size();++ix) {
 	scales.push_back(calculateInitialEvolutionScales(ShowerPPair(*cit,partners[ix].second),
 							 isDecayCase));
       }
       // In the case of more than one candidate colour partners,
       //	       there are now two approaches to choosing the partner. The
       //	       first method is based on two assumptions:
       //               1) the choice of which is the colour partner is done
       //                  *randomly* between the available candidates.
       //               2) the choice of which is the colour partner is done
       //                  *independently* from each particle: in other words,
       //                  if for a particle "i" its selected colour partner is  
       //                  the particle "j", then the colour partner of "j" 
       //                  does not have to be necessarily "i".
       // 	      The second method always chooses the furthest partner
       //	      for hard gluons and gluinos.
       // store the choice
       int position(-1);
       // random choice
       if( partnerMethod_ == 0 ) {
 	// random choice of partner
 	position = UseRandom::irnd(partners.size());
       }
       // take the one with largest angle
       else if (partnerMethod_ == 1 ) {
 	if ((*cit)->perturbative() == 1 && 
 	    (*cit)->dataPtr()->iColour()==PDT::Colour8 ) {
 	  assert(partners.size()==2);
 	  // Determine largest angle
 	  double maxAngle(0.);
 	  for(unsigned int ix=0;ix<partners.size();++ix) {
 	    double angle = (*cit)->momentum().vect().
 	      angle(partners[ix].second->momentum().vect());
 	    if(angle>maxAngle) {
 	      maxAngle = angle;
 	      position = ix;
 	    }
 	  }
 	}
 	else
 	  position = UseRandom::irnd(partners.size());
       }
       else
 	assert(false);
       // set the evolution partner
       (*cit)->partner(partners[position].second);
       for(unsigned int ix=0;ix<partners.size();++ix) {
 	(**cit).addPartner(ShowerParticle::EvolutionPartner(partners[ix].second,
 							    1.,partners[ix].first,
 							    scales[ix].first));
       }
       // set scales for all interactions to that of the partner, default
       Energy scale = scales[position].first;
       for(unsigned int ix=0;ix<partners.size();++ix) {
 	if(partners[ix].first==ShowerPartnerType::QCDColourLine) {
 	  (**cit).scales().QCD_c = 
 	    (**cit).scales().QCD_c_noAO = 
 	    (scaleChoice_==0 ? scale : scales[ix].first);
 	}
 	else if(partners[ix].first==ShowerPartnerType::QCDAntiColourLine) {
 	  (**cit).scales().QCD_ac = 
 	    (**cit).scales().QCD_ac_noAO =
 	    (scaleChoice_==0 ? scale : scales[ix].first);
 	}
 	else
 	  assert(false);
       }
     }
   }
   // primary partner set, set the others and do the scale
   else {
     for(ShowerParticleVector::const_iterator cit = particles.begin();
         cit != particles.end(); ++cit) {
       // Skip colourless particles
       if(!(*cit)->data().coloured()) continue;
       // find the partners
       vector< pair<ShowerPartnerType::Type, tShowerParticlePtr> > partners = 
 	findQCDPartners(*cit,particles);
       // must have a partner
       if(partners.empty()) {
         throw Exception() << "`Failed to make colour connections in " 
                           << "PartnerFinder::setQCDInitialEvolutionScales"
                           << (**cit)
                           << Exception::eventerror;
       }
       // Calculate the evolution scales for all possible pairs of of particles
       vector<pair<Energy,Energy> > scales;
       int position(-1);
       for(unsigned int ix=0;ix< partners.size();++ix) {
 	if(partners[ix].second) position = ix;
 	scales.push_back(calculateInitialEvolutionScales(ShowerPPair(*cit,partners[ix].second),
 							 isDecayCase));
       }
       assert(position>=0);
       for(unsigned int ix=0;ix<partners.size();++ix) {
 	(**cit).addPartner(ShowerParticle::EvolutionPartner(partners[ix].second,
 							    1.,partners[ix].first,
 							    scales[ix].first));
       }
       // set scales for all interactions to that of the partner, default
       Energy scale = scales[position].first;
       for(unsigned int ix=0;ix<partners.size();++ix) {
 	if(partners[ix].first==ShowerPartnerType::QCDColourLine) {
 	  (**cit).scales().QCD_c = 
 	    (**cit).scales().QCD_c_noAO = 
 	    (scaleChoice_==0 ? scale : scales[ix].first);
 	}
 	else if(partners[ix].first==ShowerPartnerType::QCDAntiColourLine) {
 	  (**cit).scales().QCD_ac = 
 	    (**cit).scales().QCD_ac_noAO =
 	    (scaleChoice_==0 ? scale : scales[ix].first);
 	}
 	else {
 	  assert(false);
 	}
       }
     }
   }
 }
 
 void PartnerFinder::setInitialQEDEvolutionScales(const ShowerParticleVector &particles,
 						 const bool isDecayCase,
 						 const bool setPartners) {
   // loop over all the particles
   for(ShowerParticleVector::const_iterator cit = particles.begin();
       cit != particles.end(); ++cit) {
     // not charged or photon continue
-    if(!(**cit).dataPtr()->charged() &&
-       (**cit).id()!=ParticleID::gamma) continue;
+    if(!(**cit).dataPtr()->charged()) continue;
     // find the potential partners
     vector<pair<double,tShowerParticlePtr> > partners = findQEDPartners(*cit,particles,isDecayCase);
     if(partners.empty()) {
       throw Exception() << "Failed to find partner in " 
 			<< "PartnerFinder::setQEDInitialEvolutionScales"
 			<< (**cit) << Exception::eventerror;
     }
     // calculate the probabilities
     double prob(0.);
     for(unsigned int ix=0;ix<partners.size();++ix) prob += partners[ix].first;
     // normalise
     for(unsigned int ix=0;ix<partners.size();++ix) partners[ix].first /= prob;
     // set the partner if required
     int position(-1);
     // use QCD partner if set
     if(!setPartners&&(*cit)->partner()) {
       for(unsigned int ix=0;ix<partners.size();++ix) {
 	if((*cit)->partner()==partners[ix].second) {
 	  position = ix;
 	  break;
 	}
       }
     }
     // set the partner
     if(setPartners||!(*cit)->partner()||position<0) {
       prob = UseRandom::rnd();
       for(unsigned int ix=0;ix<partners.size();++ix) {
  	if(partners[ix].first>prob) {
 	  position = ix;
 	  break;
 	}
 	prob -= partners[ix].first;
       }
       if(position>=0&&(setPartners||!(*cit)->partner())) {
 	(*cit)->partner(partners[position].second);
       }
     }
     // must have a partner
     if(position<0) throw Exception() << "Failed to find partner in " 
 				 << "PartnerFinder::setQEDInitialEvolutionScales"
 				 << (**cit) << Exception::eventerror; 
     // Calculate the evolution scales for all possible pairs of of particles
     vector<pair<Energy,Energy> > scales;
     for(unsigned int ix=0;ix< partners.size();++ix) {
       scales.push_back(calculateInitialEvolutionScales(ShowerPPair(*cit,partners[ix].second),
 						       isDecayCase));
     }
     // store all the possible partners
     for(unsigned int ix=0;ix<partners.size();++ix) {
       (**cit).addPartner(ShowerParticle::EvolutionPartner(partners[ix].second,
 							  partners[ix].first,
 							  ShowerPartnerType::QED,
 							  scales[ix].first));
     }
     // set scales
     (**cit).scales().QED      = scales[position].first;
     (**cit).scales().QED_noAO = scales[position].first;
   }
 }
 
 pair<Energy,Energy> PartnerFinder::
 calculateInitialEvolutionScales(const ShowerPPair &particlePair,
                                 const bool isDecayCase) {
   bool FS1=FS(particlePair.first),FS2= FS(particlePair.second);
 
   if(FS1 && FS2)
     return calculateFinalFinalScales(particlePair);
   else if(FS1 && !FS2) {
     ShowerPPair a(particlePair.second, particlePair.first);
     pair<Energy,Energy> rval = calculateInitialFinalScales(a,isDecayCase);
     return pair<Energy,Energy>(rval.second,rval.first);
   }
   else if(!FS1 &&FS2)
     return calculateInitialFinalScales(particlePair,isDecayCase);
   else
     return calculateInitialInitialScales(particlePair);
 }
 
 vector< pair<ShowerPartnerType::Type, tShowerParticlePtr> > 
 PartnerFinder::findQCDPartners(tShowerParticlePtr particle,
 			       const ShowerParticleVector &particles) {
   vector< pair<ShowerPartnerType::Type, tShowerParticlePtr> > partners;
   ShowerParticleVector::const_iterator cjt;
   for(cjt = particles.begin(); cjt != particles.end(); ++cjt) {
     if(!(*cjt)->data().coloured() || particle==*cjt) continue;
     // one initial-state and one final-state particle
     if(FS(particle) != FS(*cjt)) {
       // loop over all the colours of both particles
       for(unsigned int ix=0; ix<CLSIZE(particle); ++ix) {
 	for(unsigned int jx=0; jx<CLSIZE(*cjt); ++jx) {
 	  if((CL(particle,ix) && CL(particle,ix)==CL(*cjt,jx))) {
 	    partners.push_back(make_pair(ShowerPartnerType::    QCDColourLine,*cjt));
 	  }
 	}
       }
       //loop over all the anti-colours of both particles
       for(unsigned int ix=0; ix<ACLSIZE(particle); ++ix) {
 	for(unsigned int jx=0; jx<ACLSIZE(*cjt); ++jx) {
 	  if((ACL(particle,ix) && ACL(particle,ix)==ACL(*cjt,jx))) {
 	    partners.push_back(make_pair(ShowerPartnerType::QCDAntiColourLine,*cjt));
 	  }
 	}
       }
     }
     // two initial-state or two final-state particles
     else {
       //loop over the colours of the first particle and the anti-colours of the other
       for(unsigned int ix=0; ix<CLSIZE(particle); ++ix){
 	for(unsigned int jx=0; jx<ACLSIZE(*cjt); ++jx){
 	  if(CL(particle,ix) && CL(particle,ix)==ACL(*cjt,jx)) {
 	    partners.push_back(make_pair(ShowerPartnerType::    QCDColourLine,*cjt));
 	  }
 	}
       }
       //loop over the anti-colours of the first particle and the colours of the other
       for(unsigned int ix=0; ix<ACLSIZE(particle); ++ix){
 	for(unsigned int jx=0; jx<CLSIZE(*cjt); jx++){
 	  if(ACL(particle,ix) && ACL(particle,ix)==CL(*cjt,jx)) {
 	    partners.push_back(make_pair(ShowerPartnerType::QCDAntiColourLine,*cjt));
 	  }
 	}
       }
     }
   }
   // if we haven't found any partners look for RPV
   if (partners.empty()) {
     // special for RPV
     tColinePtr col = CL(particle); 
     if(FS(particle)&&col&&col->sourceNeighbours().first) {
       tColinePair cpair = col->sourceNeighbours();
       for(cjt=particles.begin();cjt!=particles.end();++cjt) {
 	if(( FS(*cjt) && ( CL(*cjt) == cpair.first || CL(*cjt)  == cpair.second))||
 	   (!FS(*cjt) && (ACL(*cjt) == cpair.first || ACL(*cjt) == cpair.second ))) {
 	  partners.push_back(make_pair(ShowerPartnerType::    QCDColourLine,*cjt));
 	}
       }
     }
     else if(col&&col->sinkNeighbours().first) {
       tColinePair cpair = col->sinkNeighbours();
       for(cjt=particles.begin();cjt!=particles.end();++cjt) {
 	if(( FS(*cjt) && (ACL(*cjt) == cpair.first || ACL(*cjt)  == cpair.second))||
 	   (!FS(*cjt) && ( CL(*cjt) == cpair.first ||  CL(*cjt) == cpair.second))) {
 	  partners.push_back(make_pair(ShowerPartnerType::    QCDColourLine,*cjt));    
 	}
       }
     }
     col = ACL(particle);
     if(FS(particle)&&col&&col->sinkNeighbours().first) {
       tColinePair cpair = col->sinkNeighbours();
       for(cjt=particles.begin();cjt!=particles.end();++cjt) {
 	if(( FS(*cjt) && (ACL(*cjt) == cpair.first || ACL(*cjt)  == cpair.second))||
 	   (!FS(*cjt) && ( CL(*cjt) == cpair.first ||  CL(*cjt) == cpair.second ))) {
 	  partners.push_back(make_pair(ShowerPartnerType::QCDAntiColourLine,*cjt));  
 	}
       }
     }
     else if(col&&col->sourceNeighbours().first) {
       tColinePair cpair = col->sourceNeighbours();
       for(cjt=particles.begin();cjt!=particles.end();++cjt) {
 	if(( FS(*cjt) && ( CL(*cjt) == cpair.first || CL(*cjt) == cpair.second))||
 	   (!FS(*cjt) && (ACL(*cjt) == cpair.first ||ACL(*cjt) == cpair.second))) {
 	  partners.push_back(make_pair(ShowerPartnerType::QCDAntiColourLine,*cjt));     
 	}
       }
     }
   }
   // return the partners
   return partners;
 }
 
 vector< pair<double, tShowerParticlePtr> > 
 PartnerFinder::findQEDPartners(tShowerParticlePtr particle,
 			       const ShowerParticleVector &particles,
 			       const bool isDecayCase) {
   vector< pair<double, tShowerParticlePtr> > partners;
   ShowerParticleVector::const_iterator cjt;
   double pcharge = particle->id()==ParticleID::gamma ? 1 : double(particle->data().iCharge());
   vector< pair<double, tShowerParticlePtr> > photons;
   for(cjt = particles.begin(); cjt != particles.end(); ++cjt) {
     if(particle == *cjt) continue;
     if((**cjt).id()==ParticleID::gamma) photons.push_back(make_pair(1.,*cjt));
     if(!(*cjt)->data().charged() ) continue;
     double charge = pcharge*double((*cjt)->data().iCharge());
     if( FS(particle) != FS(*cjt) ) charge *=-1.;
     if( QEDPartner_ != 0 && !isDecayCase ) {
       // only include II and FF as requested
       if( QEDPartner_ == 1 && FS(particle) != FS(*cjt) )
 	continue;
       // only include IF is requested
       else if(QEDPartner_ == 2 && FS(particle) == FS(*cjt) )
 	continue;
     }
     if(particle->id()==ParticleID::gamma) charge = -abs(charge);
     // only keep positive dipoles
     if(charge<0.) partners.push_back(make_pair(-charge,*cjt));
   }
   if(particle->id()==ParticleID::gamma&& partners.empty()) {
     return photons;
   }
   return partners;
 }
diff --git a/Shower/QTilde/QTildeShowerHandler.cc b/Shower/QTilde/QTildeShowerHandler.cc
--- a/Shower/QTilde/QTildeShowerHandler.cc
+++ b/Shower/QTilde/QTildeShowerHandler.cc
@@ -1,3674 +1,3677 @@
 // -*- C++ -*-
 //
 // This is the implementation of the non-inlined, non-templated member
 // functions of the QTildeShowerHandler class.
 //
 
 #include "QTildeShowerHandler.h"
 #include "ThePEG/Interface/ClassDocumentation.h"
 #include "ThePEG/Interface/Switch.h"
 #include "ThePEG/Interface/Reference.h"
 #include "ThePEG/Interface/RefVector.h"
 #include "ThePEG/Interface/Parameter.h"
 #include "ThePEG/EventRecord/Particle.h"
 #include "ThePEG/Repository/UseRandom.h"
 #include "ThePEG/Repository/EventGenerator.h"
 #include "ThePEG/Utilities/DescribeClass.h"
 #include "ThePEG/Persistency/PersistentOStream.h"
 #include "ThePEG/Persistency/PersistentIStream.h"
 #include "ThePEG/Utilities/EnumIO.h"
 #include "Herwig/Shower/QTilde/Base/ShowerParticle.h"
 #include "Herwig/PDF/MPIPDF.h"
 #include "Herwig/PDF/MinBiasPDF.h"
 #include "Herwig/Shower/QTilde/Base/ShowerTree.h"
 #include "Herwig/Shower/QTilde/Base/KinematicsReconstructor.h"
 #include "Herwig/Shower/QTilde/Base/PartnerFinder.h"
 #include "Herwig/PDF/HwRemDecayer.h"
 #include "Herwig/Shower/QTilde/Base/ShowerVertex.h"
 #include "ThePEG/Repository/CurrentGenerator.h"
 #include "Herwig/MatrixElement/Matchbox/Base/SubtractedME.h"
 #include "Herwig/MatrixElement/Matchbox/MatchboxFactory.h"
 #include "ThePEG/PDF/PartonExtractor.h"
 #include "Herwig/Shower/RealEmissionProcess.h"
 
 using namespace Herwig;
 
 namespace {
 
   /**
    *  A struct to order the particles in the same way as in the DecayMode's
    */
   struct ParticleOrdering {
     /**
      *  Operator for the ordering
      * @param p1 The first ParticleData object
      * @param p2 The second ParticleData object
      */
     bool operator() (tcPDPtr p1, tcPDPtr p2) {
       return abs(p1->id()) > abs(p2->id()) ||
 	( abs(p1->id()) == abs(p2->id()) && p1->id() > p2->id() ) ||
 	( p1->id() == p2->id() && p1->fullName() > p2->fullName() );
     }
   };
   typedef multiset<tcPDPtr,ParticleOrdering> OrderedParticles;
 
   /**
    * Cached lookup of decay modes.
    * Generator::findDecayMode() is not efficient.
    */
   tDMPtr findDecayMode(const string & tag) {
     static map<string,DMPtr> cache;
     map<string,DMPtr>::const_iterator pos = cache.find(tag);
 
     if ( pos != cache.end() ) 
     	return pos->second;
 
     tDMPtr dm = CurrentGenerator::current().findDecayMode(tag);
     cache[tag] = dm;
     return dm;
   }
 }
 
 bool QTildeShowerHandler::_hardEmissionWarn = true;
 bool QTildeShowerHandler::_missingTruncWarn = true;
 
 QTildeShowerHandler::QTildeShowerHandler() :
   _maxtry(100), _meCorrMode(1), _reconOpt(0),
   _hardVetoReadOption(false),
   _iptrms(ZERO), _beta(0.), _gamma(ZERO), _iptmax(),
   _limitEmissions(0), _initialenhance(1.), _finalenhance(1.),
   interaction_(ShowerInteraction::Both),
   _trunc_Mode(true), _hardEmission(1),
   _spinOpt(1), _softOpt(2), _hardPOWHEG(false), muPt(ZERO),
   _maxTryFSR(100000), _maxFailFSR(100), _fracFSR(0.001),
   _nFSR(0), _nFailedFSR(0)
 {}
 
 QTildeShowerHandler::~QTildeShowerHandler() {}
 
 IBPtr QTildeShowerHandler::clone() const {
   return new_ptr(*this);
 }
 
 IBPtr QTildeShowerHandler::fullclone() const {
   return new_ptr(*this);
 }
 
 void QTildeShowerHandler::persistentOutput(PersistentOStream & os) const {
   os << _model << _splittingGenerator << _maxtry 
      << _meCorrMode << _hardVetoReadOption
      << _limitEmissions << _spinOpt << _softOpt << _hardPOWHEG
      << ounit(_iptrms,GeV) << _beta << ounit(_gamma,GeV) << ounit(_iptmax,GeV) 
      << _vetoes << _trunc_Mode << _hardEmission << _reconOpt 
      << ounit(muPt,GeV)
      << oenum(interaction_) << _maxTryFSR << _maxFailFSR << _fracFSR;
 }
 
 void QTildeShowerHandler::persistentInput(PersistentIStream & is, int) {
   is >> _model >> _splittingGenerator >> _maxtry 
      >> _meCorrMode >> _hardVetoReadOption
      >> _limitEmissions >> _spinOpt >> _softOpt >> _hardPOWHEG
      >> iunit(_iptrms,GeV) >> _beta >> iunit(_gamma,GeV) >> iunit(_iptmax,GeV)
      >> _vetoes >> _trunc_Mode >> _hardEmission >> _reconOpt
      >> iunit(muPt,GeV)
      >> ienum(interaction_) >> _maxTryFSR >> _maxFailFSR >> _fracFSR;
 }
 
 
 // The following static variable is needed for the type
 // description system in ThePEG. 
 DescribeClass<QTildeShowerHandler,ShowerHandler>
 describeHerwigQTildeShowerHandler("Herwig::QTildeShowerHandler", "HwShower.so");
 
 void QTildeShowerHandler::Init() {
 
   static ClassDocumentation<QTildeShowerHandler> documentation
     ("TheQTildeShowerHandler class is the main class"
      " for the angular-ordered parton shower",
      "The Shower evolution was performed using an algorithm described in "
      "\\cite{Marchesini:1983bm,Marchesini:1987cf,Gieseke:2003rz,Bahr:2008pv}.",
      "%\\cite{Marchesini:1983bm}\n"
      "\\bibitem{Marchesini:1983bm}\n"
      "  G.~Marchesini and B.~R.~Webber,\n"
      "  ``Simulation Of QCD Jets Including Soft Gluon Interference,''\n"
      "  Nucl.\\ Phys.\\  B {\\bf 238}, 1 (1984).\n"
      "  %%CITATION = NUPHA,B238,1;%%\n"
      "%\\cite{Marchesini:1987cf}\n"
      "\\bibitem{Marchesini:1987cf}\n"
      "  G.~Marchesini and B.~R.~Webber,\n"
      "   ``Monte Carlo Simulation of General Hard Processes with Coherent QCD\n"
      "  Radiation,''\n"
      "  Nucl.\\ Phys.\\  B {\\bf 310}, 461 (1988).\n"
      "  %%CITATION = NUPHA,B310,461;%%\n"
      "%\\cite{Gieseke:2003rz}\n"
      "\\bibitem{Gieseke:2003rz}\n"
      "  S.~Gieseke, P.~Stephens and B.~Webber,\n"
      "  ``New formalism for QCD parton showers,''\n"
      "  JHEP {\\bf 0312}, 045 (2003)\n"
      "  [arXiv:hep-ph/0310083].\n"
      "  %%CITATION = JHEPA,0312,045;%%\n"
      );
 
   static Reference<QTildeShowerHandler,SplittingGenerator> 
     interfaceSplitGen("SplittingGenerator", 
 		      "A reference to the SplittingGenerator object", 
 		      &Herwig::QTildeShowerHandler::_splittingGenerator,
 		      false, false, true, false);
 
   static Reference<QTildeShowerHandler,ShowerModel> interfaceShowerModel
     ("ShowerModel",
      "The pointer to the object which defines the shower evolution model.",
      &QTildeShowerHandler::_model, false, false, true, false, false);
 
   static Parameter<QTildeShowerHandler,unsigned int> interfaceMaxTry
     ("MaxTry",
      "The maximum number of attempts to generate the shower from a"
      " particular ShowerTree",
      &QTildeShowerHandler::_maxtry, 100, 1, 1000,
      false, false, Interface::limited);
 
   static Switch<QTildeShowerHandler, unsigned int> ifaceMECorrMode
     ("MECorrMode",
      "Choice of the ME Correction Mode",
      &QTildeShowerHandler::_meCorrMode, 1, false, false);
   static SwitchOption on
     (ifaceMECorrMode,"Yes","hard+soft on", 1);
   static SwitchOption hard
     (ifaceMECorrMode,"Hard","only hard on", 2);
   static SwitchOption soft
     (ifaceMECorrMode,"Soft","only soft on", 3);
 
   static Switch<QTildeShowerHandler, bool> ifaceHardVetoReadOption
     ("HardVetoReadOption",
      "Apply read-in scale veto to all collisions or just the primary one?",
      &QTildeShowerHandler::_hardVetoReadOption, false, false, false);
   static SwitchOption AllCollisions
     (ifaceHardVetoReadOption,
      "AllCollisions",
      "Read-in pT veto applied to primary and secondary collisions.",
      false);
   static SwitchOption PrimaryCollision
     (ifaceHardVetoReadOption,
      "PrimaryCollision",
      "Read-in pT veto applied to primary but not secondary collisions.",
      true);
 
   static Parameter<QTildeShowerHandler, Energy> ifaceiptrms
     ("IntrinsicPtGaussian",
      "RMS of intrinsic pT of Gaussian distribution:\n"
      "2*(1-Beta)*exp(-sqr(intrinsicpT/RMS))/sqr(RMS)",
      &QTildeShowerHandler::_iptrms, GeV, ZERO, ZERO, 1000000.0*GeV,
      false, false, Interface::limited);
 
   static Parameter<QTildeShowerHandler, double> ifacebeta
     ("IntrinsicPtBeta",
      "Proportion of inverse quadratic distribution in generating intrinsic pT.\n"
      "(1-Beta) is the proportion of Gaussian distribution",
      &QTildeShowerHandler::_beta, 0, 0, 1,
      false, false, Interface::limited);
 
   static Parameter<QTildeShowerHandler, Energy> ifacegamma
     ("IntrinsicPtGamma",
      "Parameter for inverse quadratic:\n"
      "2*Beta*Gamma/(sqr(Gamma)+sqr(intrinsicpT))",
      &QTildeShowerHandler::_gamma,GeV, ZERO, ZERO, 100000.0*GeV,
      false, false, Interface::limited);
 
   static Parameter<QTildeShowerHandler, Energy> ifaceiptmax
     ("IntrinsicPtIptmax",
      "Upper bound on intrinsic pT for inverse quadratic",
      &QTildeShowerHandler::_iptmax,GeV, ZERO, ZERO, 100000.0*GeV,
      false, false, Interface::limited);
 
   static RefVector<QTildeShowerHandler,ShowerVeto> ifaceVetoes
     ("Vetoes",
      "The vetoes to be checked during showering",
      &QTildeShowerHandler::_vetoes, -1,
      false,false,true,true,false);
 
   static Switch<QTildeShowerHandler,unsigned int> interfaceLimitEmissions
     ("LimitEmissions",
      "Limit the number and type of emissions for testing",
      &QTildeShowerHandler::_limitEmissions, 0, false, false);
   static SwitchOption interfaceLimitEmissionsNoLimit
     (interfaceLimitEmissions,
      "NoLimit",
      "Allow an arbitrary number of emissions",
      0);
   static SwitchOption interfaceLimitEmissionsOneInitialStateEmission
     (interfaceLimitEmissions,
      "OneInitialStateEmission",
      "Allow one emission in the initial state and none in the final state",
      1);
   static SwitchOption interfaceLimitEmissionsOneFinalStateEmission
     (interfaceLimitEmissions,
      "OneFinalStateEmission",
      "Allow one emission in the final state and none in the initial state",
      2);
   static SwitchOption interfaceLimitEmissionsHardOnly
     (interfaceLimitEmissions,
      "HardOnly",
      "Only allow radiation from the hard ME correction",
      3);
   static SwitchOption interfaceLimitEmissionsOneEmission
     (interfaceLimitEmissions,
      "OneEmission",
      "Allow one emission in either the final state or initial state, but not both",
      4);
 
   static Switch<QTildeShowerHandler,bool> interfaceTruncMode
     ("TruncatedShower", "Include the truncated shower?", 
      &QTildeShowerHandler::_trunc_Mode, 1, false, false);
   static SwitchOption interfaceTruncMode0
     (interfaceTruncMode,"No","Truncated Shower is OFF", 0);
   static SwitchOption interfaceTruncMode1
     (interfaceTruncMode,"Yes","Truncated Shower is ON", 1);
 
   static Switch<QTildeShowerHandler,int> interfaceHardEmission
     ("HardEmission",
      "Whether to use ME corrections or POWHEG for the hardest emission",
      &QTildeShowerHandler::_hardEmission, 0, false, false);
   static SwitchOption interfaceHardEmissionNone
     (interfaceHardEmission,
      "None",
      "No Corrections",
      0);
   static SwitchOption interfaceHardEmissionMECorrection
     (interfaceHardEmission,
      "MECorrection",
      "Old fashioned ME correction",
      1);
   static SwitchOption interfaceHardEmissionPOWHEG
     (interfaceHardEmission,
      "POWHEG",
      "Powheg style hard emission",
      2);
 
   static Switch<QTildeShowerHandler,ShowerInteraction::Type> interfaceInteractions
     ("Interactions",
      "The interactions to be used in the shower",
      &QTildeShowerHandler::interaction_, ShowerInteraction::Both, false, false);
   static SwitchOption interfaceInteractionsQCD
     (interfaceInteractions,
      "QCD",
      "Only QCD radiation",
      ShowerInteraction::QCD);
   static SwitchOption interfaceInteractionsQED
     (interfaceInteractions,
      "QED",
      "Only QEd radiation",
      ShowerInteraction::QED);
   static SwitchOption interfaceInteractionsQCDandQED
     (interfaceInteractions,
      "QCDandQED",
      "Both QED and QCD radiation",
      ShowerInteraction::Both);
 
   static Switch<QTildeShowerHandler,unsigned int> interfaceReconstructionOption
     ("ReconstructionOption",
      "Treatment of the reconstruction of the transverse momentum of "
      "a branching from the evolution scale.",
      &QTildeShowerHandler::_reconOpt, 0, false, false);
   static SwitchOption interfaceReconstructionOptionCutOff
     (interfaceReconstructionOption,
      "CutOff",
      "Use the cut-off masses in the calculation",
      0);
   static SwitchOption interfaceReconstructionOptionOffShell
     (interfaceReconstructionOption,
      "OffShell",
      "Use the off-shell masses in the calculation veto the emission of the parent,"
      " no veto in generation of emissions from children",
      1);
   static SwitchOption interfaceReconstructionOptionOffShell2
     (interfaceReconstructionOption,
      "OffShell2",
      "Use the off-shell masses in the calculation veto the emissions from the children."
      " no veto in generation of emissions from children",
      2);
   static SwitchOption interfaceReconstructionOptionOffShell3
     (interfaceReconstructionOption,
      "OffShell3",
      "Use the off-shell masses in the calculation veto the emissions from the children."
      " veto in generation of emissions from children using cut-off for second parton",
      3);
 
   static Switch<QTildeShowerHandler,unsigned int> interfaceSpinCorrelations
     ("SpinCorrelations",
      "Treatment of spin correlations in the parton shower",
      &QTildeShowerHandler::_spinOpt, 1, false, false);
   static SwitchOption interfaceSpinCorrelationsOff
     (interfaceSpinCorrelations,
      "No",
      "No spin correlations",
      0);
   static SwitchOption interfaceSpinCorrelationsSpin
     (interfaceSpinCorrelations,
      "Yes",
      "Include the azimuthal spin correlations only",
      1);
 
   static Switch<QTildeShowerHandler,unsigned int> interfaceSoftCorrelations
     ("SoftCorrelations",
      "Option for the treatment of soft correlations in the parton shower",
      &QTildeShowerHandler::_softOpt, 2, false, false);
   static SwitchOption interfaceSoftCorrelationsNone
     (interfaceSoftCorrelations,
      "No",
      "No soft correlations",
      0);
   static SwitchOption interfaceSoftCorrelationsFull
     (interfaceSoftCorrelations,
      "Full",
      "Use the full eikonal",
      1);
   static SwitchOption interfaceSoftCorrelationsSingular
     (interfaceSoftCorrelations,
      "Singular",
      "Use original Webber-Marchisini form",
      2);
 
   static Switch<QTildeShowerHandler,bool> interfaceHardPOWHEG
     ("HardPOWHEG",
      "Treatment of powheg emissions which are too hard to have a shower interpretation",
      &QTildeShowerHandler::_hardPOWHEG, false, false, false);
   static SwitchOption interfaceHardPOWHEGAsShower
     (interfaceHardPOWHEG,
      "AsShower",
      "Still interpret as shower emissions",
      false);
   static SwitchOption interfaceHardPOWHEGRealEmission
     (interfaceHardPOWHEG,
      "RealEmission",
      "Generate shower from the real emmission configuration",
      true);
 
   static Parameter<QTildeShowerHandler,unsigned int> interfaceMaxTryFSR
     ("MaxTryFSR",
      "The maximum number of attempted FSR emissions in"
      " the generation of the FSR",
      &QTildeShowerHandler::_maxTryFSR, 100000, 10, 100000000,
      false, false, Interface::limited);
 
   static Parameter<QTildeShowerHandler,unsigned int> interfaceMaxFailFSR
     ("MaxFailFSR",
      "Maximum number of failures generating the FSR",
      &QTildeShowerHandler::_maxFailFSR, 100, 1, 100000000,
      false, false, Interface::limited);
 
   static Parameter<QTildeShowerHandler,double> interfaceFSRFailureFraction
     ("FSRFailureFraction",
      "Maximum fraction of events allowed to fail due to too many FSR emissions",
      &QTildeShowerHandler::_fracFSR, 0.001, 1e-10, 1,
      false, false, Interface::limited);
 
 }
 
 tPPair QTildeShowerHandler::cascade(tSubProPtr sub,
 				    XCPtr xcomb) {
   // use me for reference in tex file etc
   useMe();
   prepareCascade(sub);
   // set things up in the base class
   resetWeights();
   hard_=ShowerTreePtr();
   decay_.clear();
   done_.clear();
   // check if anything needs doing
   if ( !doFSR() && ! doISR() )
     return sub->incoming();
   // start of the try block for the whole showering process
   unsigned int countFailures=0;
   while (countFailures<maxtry()) {
     try {
       decay_.clear();
       done_.clear();
       PerturbativeProcessPtr hard;
       DecayProcessMap decay;
       splitHardProcess(firstInteraction() ? tagged() :
       		       tPVector(currentSubProcess()->outgoing().begin(),
       				currentSubProcess()->outgoing().end()),
       		       hard,decay);
       ShowerTree::constructTrees(hard_,decay_,hard,decay);
       // if no hard process
       if(!hard_)  throw Exception() << "Shower starting with a decay"
 				    << "is not implemented" 
 				    << Exception::runerror;
       // perform the shower for the hard process
       showerHardProcess(hard_,xcomb);
       done_.push_back(hard_);
       hard_->updateAfterShower(decay_);
       // if no decaying particles to shower break out of the loop
       if(decay_.empty()) break;
       // shower the decay products
       while(!decay_.empty()) {
 	// find particle whose production process has been showered
 	ShowerDecayMap::iterator dit = decay_.begin();
 	while(!dit->second->parent()->hasShowered() && dit!=decay_.end()) ++dit;
 	assert(dit!=decay_.end());
 	// get the particle
 	ShowerTreePtr decayingTree = dit->second;
 	// remove it from the multimap
 	decay_.erase(dit);
 	// make sure the particle has been decayed
 	QTildeShowerHandler::decay(decayingTree,decay_);
 	// now shower the decay
 	showerDecay(decayingTree);
 	done_.push_back(decayingTree);
 	decayingTree->updateAfterShower(decay_);
       }
       // suceeded break out of the loop
       break;
     }
     catch (KinematicsReconstructionVeto) {
       resetWeights();
       ++countFailures;
     }
   }
   // if loop exited because of too many tries, throw event away
   if (countFailures >= maxtry()) {
     resetWeights();
     hard_=ShowerTreePtr();
     decay_.clear();
     done_.clear();
     throw Exception() << "Too many tries for main while loop "
 		      << "in ShowerHandler::cascade()." 
 		      << Exception::eventerror; 	
   }
   //enter the particles in the event record
   fillEventRecord();
   // clear storage
   hard_=ShowerTreePtr();
   decay_.clear();
   done_.clear();
   // non hadronic case return
   if (!isResolvedHadron(incomingBeams().first ) && 
       !isResolvedHadron(incomingBeams().second) )
     return incomingBeams();
   // remake the remnants (needs to be after the colours are sorted
   //                       out in the insertion into the event record)
   if ( firstInteraction() ) return remakeRemnant(sub->incoming());
   //Return the new pair of incoming partons. remakeRemnant is not
   //necessary here, because the secondary interactions are not yet
   //connected to the remnants.
   return make_pair(findFirstParton(sub->incoming().first ),
 		   findFirstParton(sub->incoming().second));
 }
 
 void QTildeShowerHandler::fillEventRecord() {
   // create a new step 
   StepPtr pstep = newStep();
   assert(!done_.empty());
   assert(done_[0]->isHard());
   // insert the steps
   for(unsigned int ix=0;ix<done_.size();++ix) {
     done_[ix]->fillEventRecord(pstep,doISR(),doFSR());
   }
 }
 
 HardTreePtr QTildeShowerHandler::generateCKKW(ShowerTreePtr ) const {
   return HardTreePtr();
 }
 
 void QTildeShowerHandler::doinit() {
   ShowerHandler::doinit();
   // interactions may have been changed through a setup file so we
   // clear it up here
   // calculate max no of FSR vetos
   _maxFailFSR = max(int(_maxFailFSR), int(_fracFSR*double(generator()->N())));
 }
 
 void QTildeShowerHandler::generateIntrinsicpT(vector<ShowerProgenitorPtr> particlesToShower) {
   _intrinsic.clear();
   if ( !ipTon() || !doISR() ) return;
   // don't do anything for the moment for secondary scatters
   if( !firstInteraction() ) return;
   // generate intrinsic pT
   for(unsigned int ix=0;ix<particlesToShower.size();++ix) {
     // only consider initial-state particles
     if(particlesToShower[ix]->progenitor()->isFinalState()) continue;
     if(!particlesToShower[ix]->progenitor()->dataPtr()->coloured()) continue;
     Energy ipt;
     if(UseRandom::rnd() > _beta) {
       ipt=_iptrms*sqrt(-log(UseRandom::rnd()));
     }
     else {
       ipt=_gamma*sqrt(pow(1.+sqr(_iptmax/_gamma), UseRandom::rnd())-1.);
     }
     pair<Energy,double> pt = make_pair(ipt,UseRandom::rnd(Constants::twopi));
     _intrinsic[particlesToShower[ix]] = pt;
   }
 }
 
 void QTildeShowerHandler::setupMaximumScales(const vector<ShowerProgenitorPtr> & p,
 				 XCPtr xcomb) {
   // let POWHEG events radiate freely
   if(_hardEmission==2&&hardTree()) {
     vector<ShowerProgenitorPtr>::const_iterator ckt = p.begin();
     for (; ckt != p.end(); ckt++) (*ckt)->maxHardPt(Constants::MaxEnergy);
     return;
   }
   // return if no vetos
   if (!restrictPhasespace()) return; 
   // find out if hard partonic subprocess.
   bool isPartonic(false); 
   map<ShowerProgenitorPtr,ShowerParticlePtr>::const_iterator 
     cit = _currenttree->incomingLines().begin();
   Lorentz5Momentum pcm;
   for(; cit!=currentTree()->incomingLines().end(); ++cit) {
     pcm += cit->first->progenitor()->momentum();
     isPartonic |= cit->first->progenitor()->coloured();
   }
   // find minimum pt from hard process, the maximum pt from all outgoing
   // coloured lines (this is simpler and more general than
   // 2stu/(s^2+t^2+u^2)).  Maximum scale for scattering processes will
   // be transverse mass.
   Energy ptmax = generator()->maximumCMEnergy();
   // general case calculate the scale  
   if ( !hardScaleIsMuF() || (hardVetoReadOption()&&!firstInteraction()) ) {
     // scattering process
     if(currentTree()->isHard()) {
       assert(xcomb);
       // coloured incoming particles
       if (isPartonic) {
 	map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator 
 	  cjt = currentTree()->outgoingLines().begin();
 	for(; cjt!=currentTree()->outgoingLines().end(); ++cjt) {
 	  if (cjt->first->progenitor()->coloured())
 	    ptmax = min(ptmax,cjt->first->progenitor()->momentum().mt());
 	}
       }
       if (ptmax == generator()->maximumCMEnergy() ) ptmax = pcm.m();
       if(hardScaleIsMuF()&&hardVetoReadOption()&&
 	 !firstInteraction()) {
 	ptmax=min(ptmax,sqrt(xcomb->lastShowerScale()));
       }
     } 
     // decay, incoming() is the decaying particle.
     else { 
       ptmax = currentTree()->incomingLines().begin()->first
 	->progenitor()->momentum().mass(); 
     }
   }
   // hepeup.SCALUP is written into the lastXComb by the
   // LesHouchesReader itself - use this by user's choice. 
   // Can be more general than this. 
   else {
     if(currentTree()->isHard()) {
       assert(xcomb);
       ptmax = sqrt( xcomb->lastShowerScale() );
     }
     else {
       ptmax = currentTree()->incomingLines().begin()->first
 	->progenitor()->momentum().mass(); 
     }
   }
   ptmax *= hardScaleFactor();
   // set maxHardPt for all progenitors.  For partonic processes this
   // is now the max pt in the FS, for non-partonic processes or
   // processes with no coloured FS the invariant mass of the IS
   vector<ShowerProgenitorPtr>::const_iterator ckt = p.begin();
   for (; ckt != p.end(); ckt++) (*ckt)->maxHardPt(ptmax);
 }
 
 void QTildeShowerHandler::setupHardScales(const vector<ShowerProgenitorPtr> & p,
 					  XCPtr xcomb) {
   if ( hardScaleIsMuF() &&
        (!hardVetoReadOption() || firstInteraction()) ) {
     Energy hardScale = ZERO;
     if(currentTree()->isHard()) {
       assert(xcomb);
       hardScale = sqrt( xcomb->lastShowerScale() );
     }
     else {
       hardScale = currentTree()->incomingLines().begin()->first
 	->progenitor()->momentum().mass(); 
     }
     hardScale *= hardScaleFactor();
     vector<ShowerProgenitorPtr>::const_iterator ckt = p.begin();
     for (; ckt != p.end(); ckt++) (*ckt)->hardScale(hardScale);
     muPt = hardScale;
   }
 }
 
 void QTildeShowerHandler::showerHardProcess(ShowerTreePtr hard, XCPtr xcomb) {
   _hardme = HwMEBasePtr();
   // extract the matrix element
   tStdXCombPtr lastXC = dynamic_ptr_cast<tStdXCombPtr>(xcomb);
   if(lastXC) {
     _hardme = dynamic_ptr_cast<HwMEBasePtr>(lastXC->matrixElement());
   }
   _decayme = HwDecayerBasePtr();
   // set the current tree
   currentTree(hard);
   hardTree(HardTreePtr());
   // work out the type of event
   currentTree()->xcombPtr(dynamic_ptr_cast<StdXCombPtr>(xcomb));
   currentTree()->identifyEventType();
   checkFlags();
   // generate the showering
   doShowering(true,xcomb);
 }
 
 RealEmissionProcessPtr QTildeShowerHandler::hardMatrixElementCorrection(bool hard) {
   // set the initial enhancement factors for the soft correction
   _initialenhance = 1.;
   _finalenhance   = 1.;
   // see if we can get the correction from the matrix element
   // or decayer
   RealEmissionProcessPtr real;
   if(hard) {
     if(_hardme&&_hardme->hasMECorrection()) {
       _hardme->initializeMECorrection(_currenttree->perturbativeProcess(),
      				      _initialenhance,_finalenhance);
       if(hardMEC())
      	real = 
 	  _hardme->applyHardMatrixElementCorrection(_currenttree->perturbativeProcess());
     }
   }
   else {
     if(_decayme&&_decayme->hasMECorrection()) {
       _decayme->initializeMECorrection(_currenttree->perturbativeProcess(),
    				       _initialenhance,_finalenhance);
       if(hardMEC())
    	real = _decayme->applyHardMatrixElementCorrection(_currenttree->perturbativeProcess());
     }
   }
   return real;
 }
 
 ShowerParticleVector QTildeShowerHandler::createTimeLikeChildren(tShowerParticlePtr, IdList ids) {
   // Create the ShowerParticle objects for the two children of
   // the emitting particle; set the parent/child relationship
   // if same as definition create particles, otherwise create cc
   ShowerParticleVector children;
   for(unsigned int ix=0;ix<2;++ix) {
     children.push_back(new_ptr(ShowerParticle(ids[ix+1],true)));
     if(children[ix]->id()==_progenitor->id()&&!ids[ix+1]->stable())
       children[ix]->set5Momentum(Lorentz5Momentum(_progenitor->progenitor()->mass()));
     else
       children[ix]->set5Momentum(Lorentz5Momentum(ids[ix+1]->mass()));
   }
   return children;
 }
 
 bool QTildeShowerHandler::timeLikeShower(tShowerParticlePtr particle, 
 					 ShowerInteraction::Type type,
 					 Branching fb, bool first) {
   // don't do anything if not needed
   if(_limitEmissions == 1 || hardOnly() || 
      ( _limitEmissions == 2 && _nfs != 0) ||
      ( _limitEmissions == 4 && _nfs + _nis != 0) ) {
     if(particle->spinInfo()) particle->spinInfo()->develop();
     return false;
   }
   // too many tries
   if(_nFSR>=_maxTryFSR) {
     ++_nFailedFSR;
     // too many failed events
     if(_nFailedFSR>=_maxFailFSR)
       throw Exception() << "Too many events have failed due to too many shower emissions, in\n"
 			<< "QTildeShowerHandler::timeLikeShower(). Terminating run\n"
 			<< Exception::runerror;
     throw Exception() << "Too many attempted emissions in QTildeShowerHandler::timeLikeShower()\n"
 		      << Exception::eventerror;
   }
   // generate the emission
   ShowerParticleVector children;
   int ntry=0;
   // generate the emission
   if(!fb.kinematics) 
     fb = selectTimeLikeBranching(particle,type,HardBranchingPtr());
   // no emission, return
   if(!fb.kinematics) {
     if(particle->spinInfo()) particle->spinInfo()->develop();
     return false;
   }
   Branching fc[2];
   bool setupChildren = true;
   while (ntry<50) {
     fc[0] = Branching();
     fc[1] = Branching();
     ++ntry;
     assert(fb.kinematics);
     // has emitted
     // Assign the shower kinematics to the emitting particle.
     if(setupChildren) {
       ++_nFSR;
       particle->showerKinematics(fb.kinematics);
       // check highest pT
       if(fb.kinematics->pT()>progenitor()->highestpT())
 	progenitor()->highestpT(fb.kinematics->pT());
       // create the children
       children = createTimeLikeChildren(particle,fb.ids);
       // update the children
       particle->showerKinematics()->
 	updateChildren(particle, children,fb.type,_reconOpt>=3);
       // update number of emissions
       ++_nfs;
       if(_limitEmissions!=0) {
 	if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
 	if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
 	if(particle->spinInfo()) particle->spinInfo()->develop();
 	return true;
       }
       setupChildren = false;
     }
     // select branchings for children
     fc[0] = selectTimeLikeBranching(children[0],type,HardBranchingPtr());
     fc[1] = selectTimeLikeBranching(children[1],type,HardBranchingPtr());
     // old default
     if(_reconOpt==0) {
       // shower the first  particle
       if(fc[0].kinematics) timeLikeShower(children[0],type,fc[0],false);
       if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
       // shower the second particle
       if(fc[1].kinematics) timeLikeShower(children[1],type,fc[1],false);
       if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
       break;
     }
     // Herwig default
     else if(_reconOpt==1) {
       // shower the first  particle
       if(fc[0].kinematics) timeLikeShower(children[0],type,fc[0],false);
       if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
       // shower the second particle
       if(fc[1].kinematics) timeLikeShower(children[1],type,fc[1],false);
       if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
       // branching has happened
       particle->showerKinematics()->updateParent(particle, children,fb.type);
       // clean up the vetoed emission
       if(particle->virtualMass()==ZERO) {
    	particle->showerKinematics(ShoKinPtr());
    	for(unsigned int ix=0;ix<children.size();++ix)
    	  particle->abandonChild(children[ix]);
    	children.clear();
    	if(particle->spinInfo()) particle->spinInfo()->decayVertex(VertexPtr());
 	particle->vetoEmission(fb.type,fb.kinematics->scale());
 	// generate the new emission
 	fb = selectTimeLikeBranching(particle,type,HardBranchingPtr());
 	// no emission, return
 	if(!fb.kinematics) {
 	  if(particle->spinInfo()) particle->spinInfo()->develop();
 	  return false;
 	}
 	setupChildren = true;
 	continue;
       }
       else
 	break;
     }
     // veto children
     else if(_reconOpt>=2) {
       // cut-off masses for the branching
       const vector<Energy> & virtualMasses = fb.sudakov->virtualMasses(fb.ids);
       // compute the masses of the children
       Energy masses[3];
       for(unsigned int ix=0;ix<2;++ix) {
    	if(fc[ix].kinematics) {
    	  const vector<Energy> & vm = fc[ix].sudakov->virtualMasses(fc[ix].ids);
    	  Energy2 q2 = 
    	    fc[ix].kinematics->z()*(1.-fc[ix].kinematics->z())*sqr(fc[ix].kinematics->scale());
    	  if(fc[ix].ids[0]->id()!=ParticleID::g) q2 += sqr(vm[0]);
    	  masses[ix+1] = sqrt(q2);
    	}
    	else {
    	  masses[ix+1] = virtualMasses[ix+1];
    	}
       }
       masses[0] = fb.ids[0]->id()!=ParticleID::g ? virtualMasses[0] : ZERO;
       double z = fb.kinematics->z();
       Energy2 pt2 = z*(1.-z)*(z*(1.-z)*sqr(fb.kinematics->scale()) + sqr(masses[0]))
    	- sqr(masses[1])*(1.-z) - sqr(masses[2])*z;
       if(pt2>=ZERO) {
 	break;
       }
       else {
 	// reset the scales for the children
 	for(unsigned int ix=0;ix<2;++ix) {
 	  if(fc[ix].kinematics)
 	    children[ix]->vetoEmission(fc[ix].type,fc[ix].kinematics->scale());
 	  else
 	    children[ix]->vetoEmission(ShowerPartnerType::QCDColourLine,ZERO);
 	  children[ix]->virtualMass(ZERO);
 	} 
       }
     }
   };
   if(_reconOpt>=2) {
     // shower the first  particle
     if(fc[0].kinematics) timeLikeShower(children[0],type,fc[0],false);
     if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
     // shower the second particle
     if(fc[1].kinematics) timeLikeShower(children[1],type,fc[1],false);
     if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
     // branching has happened
       particle->showerKinematics()->updateParent(particle, children,fb.type);
   }
   if(first&&!children.empty())
     particle->showerKinematics()->resetChildren(particle,children);
   if(particle->spinInfo()) particle->spinInfo()->develop();
   return true;
 }
 
 bool 
 QTildeShowerHandler::spaceLikeShower(tShowerParticlePtr particle, PPtr beam,
 			 ShowerInteraction::Type type) {
   //using the pdf's associated with the ShowerHandler assures, that
   //modified pdf's are used for the secondary interactions via 
   //CascadeHandler::resetPDFs(...)
   tcPDFPtr pdf;
   if(firstPDF().particle() == _beam)
     pdf = firstPDF().pdf();
   if(secondPDF().particle() == _beam)
     pdf = secondPDF().pdf();
   Energy freeze = pdfFreezingScale();
   // don't do anything if not needed
   if(_limitEmissions == 2  || hardOnly() ||
      ( _limitEmissions == 1 && _nis != 0 ) ||
      ( _limitEmissions == 4 && _nis + _nfs != 0 ) ) {
     if(particle->spinInfo()) particle->spinInfo()->develop();
     return false;
   }
   Branching bb;
   // generate branching
   while (true) {
     bb=_splittingGenerator->chooseBackwardBranching(*particle,beam,
 						    _initialenhance,
 						    _beam,type,
 						    pdf,freeze);
     // return if no emission
     if(!bb.kinematics) {
       if(particle->spinInfo()) particle->spinInfo()->develop();
       return false;
     }
     // if not vetoed break
     if(!spaceLikeVetoed(bb,particle)) break;
     // otherwise reset scale and continue
     particle->vetoEmission(bb.type,bb.kinematics->scale());
     if(particle->spinInfo()) particle->spinInfo()->decayVertex(VertexPtr());
   }
   // assign the splitting function and shower kinematics
   particle->showerKinematics(bb.kinematics);
   if(bb.kinematics->pT()>progenitor()->highestpT())
     progenitor()->highestpT(bb.kinematics->pT());
   // For the time being we are considering only 1->2 branching
   // particles as in Sudakov form factor
   tcPDPtr part[2]={bb.ids[0],bb.ids[2]};
   // Now create the actual particles, make the otherChild a final state
   // particle, while the newParent is not
   ShowerParticlePtr newParent  = new_ptr(ShowerParticle(part[0],false));
   ShowerParticlePtr otherChild = new_ptr(ShowerParticle(part[1],true,true));
   ShowerParticleVector theChildren;
   theChildren.push_back(particle); 
   theChildren.push_back(otherChild);
   //this updates the evolution scale
   particle->showerKinematics()->
     updateParent(newParent, theChildren,bb.type);
   // update the history if needed
   _currenttree->updateInitialStateShowerProduct(_progenitor,newParent);
   _currenttree->addInitialStateBranching(particle,newParent,otherChild);
   // for the reconstruction of kinematics, parent/child
   // relationships are according to the branching process:
   // now continue the shower
   ++_nis;
   bool emitted = _limitEmissions==0 ? 
     spaceLikeShower(newParent,beam,type) : false;
   if(newParent->spinInfo()) newParent->spinInfo()->develop();
   // now reconstruct the momentum
   if(!emitted) {
     if(_intrinsic.find(_progenitor)==_intrinsic.end()) {
       bb.kinematics->updateLast(newParent,ZERO,ZERO);
     }
     else {
       pair<Energy,double> kt=_intrinsic[_progenitor];
       bb.kinematics->updateLast(newParent,
 				kt.first*cos(kt.second),
 				kt.first*sin(kt.second));
     }
   }
   particle->showerKinematics()->
     updateChildren(newParent, theChildren,bb.type,false);
   if(_limitEmissions!=0) {
     if(particle->spinInfo()) particle->spinInfo()->develop();
     return true;
   }
   // perform the shower of the final-state particle
   timeLikeShower(otherChild,type,Branching(),true);
   updateHistory(otherChild);
   if(theChildren[1]->spinInfo()) theChildren[1]->spinInfo()->develop();
   // return the emitted
   if(particle->spinInfo()) particle->spinInfo()->develop();
   return true;
 }
 
 void QTildeShowerHandler::showerDecay(ShowerTreePtr decay) {
   // work out the type of event
   currentTree()->xcombPtr(StdXCombPtr());
   currentTree()->identifyEventType();
   _decayme = HwDecayerBasePtr();
   _hardme  = HwMEBasePtr();
   // find the decayer
   // try the normal way if possible
   tDMPtr dm = decay->incomingLines().begin()->first->original()   ->decayMode();
   if(!dm) dm = decay->incomingLines().begin()->first->copy()      ->decayMode();
   if(!dm) dm = decay->incomingLines().begin()->first->progenitor()->decayMode();
   // otherwise make a string and look it up
   if(!dm) {
     string tag = decay->incomingLines().begin()->first->original()->dataPtr()->name() 
       + "->";
     OrderedParticles outgoing;
     for(map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator 
 	  it=decay->outgoingLines().begin();it!=decay->outgoingLines().end();++it) {
       if(abs(decay->incomingLines().begin()->first->original()->id()) == ParticleID::t &&
 	 abs(it->first->original()->id())==ParticleID::Wplus &&
 	 decay->treelinks().size() == 1) {
 	ShowerTreePtr Wtree = decay->treelinks().begin()->first;
 	for(map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator
 	      it2=Wtree->outgoingLines().begin();it2!=Wtree->outgoingLines().end();++it2) {
 	  outgoing.insert(it2->first->original()->dataPtr());
 	}
       }
       else {
 	outgoing.insert(it->first->original()->dataPtr());
       }
     }
     for(OrderedParticles::const_iterator it=outgoing.begin(); it!=outgoing.end();++it) {
       if(it!=outgoing.begin()) tag += ",";
       tag +=(**it).name();
     }
     tag += ";";
     dm = findDecayMode(tag);
   }
   if(dm) _decayme = dynamic_ptr_cast<HwDecayerBasePtr>(dm->decayer());
   // set the ShowerTree to be showered
   currentTree(decay);
   decay->applyTransforms();
   hardTree(HardTreePtr());
   // generate the showering
   doShowering(false,XCPtr());
   // if no vetos 
   // force calculation of spin correlations
   SpinPtr spInfo = decay->incomingLines().begin()->first->progenitor()->spinInfo();
   if(spInfo) {
     if(!spInfo->developed()) spInfo->needsUpdate();
     spInfo->develop();
   }
 }
 
 bool QTildeShowerHandler::spaceLikeDecayShower(tShowerParticlePtr particle,
 				   const ShowerParticle::EvolutionScales & maxScales,
 				   Energy minmass,ShowerInteraction::Type type,
 				   Branching fb) {
   // too many tries
   if(_nFSR>=_maxTryFSR) {
     ++_nFailedFSR;
     // too many failed events
     if(_nFailedFSR>=_maxFailFSR)
       throw Exception() << "Too many events have failed due to too many shower emissions, in\n"
 			<< "QTildeShowerHandler::timeLikeShower(). Terminating run\n"
 			<< Exception::runerror;
     throw Exception() << "Too many attempted emissions in QTildeShowerHandler::timeLikeShower()\n"
 		      << Exception::eventerror;
   }
   // generate the emission
   ShowerParticleVector children;
   int ntry=0;
   // generate the emission
   if(!fb.kinematics) 
     fb = selectSpaceLikeDecayBranching(particle,maxScales,minmass,type,
 				       HardBranchingPtr());
   // no emission, return
   if(!fb.kinematics) return false;
   Branching fc[2];
   bool setupChildren = true;
   while (ntry<50) {
     if(particle->virtualMass()==ZERO) 
       particle->virtualMass(_progenitor->progenitor()->mass());
     fc[0] = Branching();
     fc[1] = Branching();
     ++ntry;
     assert(fb.kinematics);
     // has emitted
     // Assign the shower kinematics to the emitting particle.
     if(setupChildren) {
       ++_nFSR;
       // Assign the shower kinematics to the emitting particle.
       particle->showerKinematics(fb.kinematics);
       if(fb.kinematics->pT()>progenitor()->highestpT())
 	progenitor()->highestpT(fb.kinematics->pT());
       // create the ShowerParticle objects for the two children
       children = createTimeLikeChildren(particle,fb.ids);
       // updateChildren the children
       particle->showerKinematics()->
 	updateChildren(particle, children, fb.type,_reconOpt>=3);
       setupChildren = false;
     }
     // select branchings for children
     fc[0] = selectSpaceLikeDecayBranching(children[0],maxScales,minmass,
 					  type,HardBranchingPtr());
     fc[1] = selectTimeLikeBranching      (children[1],type,HardBranchingPtr());
     // old default
     if(_reconOpt==0) {
       // shower the first  particle
       _currenttree->updateInitialStateShowerProduct(_progenitor,children[0]);
       _currenttree->addInitialStateBranching(particle,children[0],children[1]);
       if(fc[0].kinematics) spaceLikeDecayShower(children[0],maxScales,minmass,type,Branching());
       // shower the second particle
       if(fc[1].kinematics) timeLikeShower(children[1],type,fc[1],true);
       updateHistory(children[1]);
       // branching has happened
       break;
     }
     // Herwig default
     else if(_reconOpt==1) {
       // shower the first  particle
       _currenttree->updateInitialStateShowerProduct(_progenitor,children[0]);
       _currenttree->addInitialStateBranching(particle,children[0],children[1]);
       if(fc[0].kinematics) spaceLikeDecayShower(children[0],maxScales,minmass,type,Branching());
       // shower the second particle
       if(fc[1].kinematics) timeLikeShower(children[1],type,fc[1],true);
       updateHistory(children[1]);
       // branching has happened
       particle->showerKinematics()->updateParent(particle, children,fb.type);
       // clean up the vetoed emission
       if(particle->virtualMass()==ZERO) {
     	particle->showerKinematics(ShoKinPtr());
    	for(unsigned int ix=0;ix<children.size();++ix)
    	  particle->abandonChild(children[ix]);
     	children.clear();
  	particle->vetoEmission(fb.type,fb.kinematics->scale());
  	// generate the new emission
   	fb = selectSpaceLikeDecayBranching(particle,maxScales,minmass,type,
 				       HardBranchingPtr());
  	// no emission, return
   	if(!fb.kinematics) {
   	  return false;
    	}
   	setupChildren = true;
    	continue;
       }
       else
    	break;
     }
     else if(_reconOpt>=2) {
       // cut-off masses for the branching
       const vector<Energy> & virtualMasses = fb.sudakov->virtualMasses(fb.ids);
       // compute the masses of the children
       Energy masses[3];
       // space-like children
       masses[1] = children[0]->virtualMass();
       // time-like child
       if(fc[1].kinematics) {
 	const vector<Energy> & vm = fc[1].sudakov->virtualMasses(fc[1].ids);
 	Energy2 q2 = 
 	  fc[1].kinematics->z()*(1.-fc[1].kinematics->z())*sqr(fc[1].kinematics->scale());
 	if(fc[1].ids[0]->id()!=ParticleID::g) q2 += sqr(vm[0]);
 	masses[2] = sqrt(q2);
       }
       else {
 	masses[2] = virtualMasses[2];
       } 
       masses[0]=particle->virtualMass();
       double z = fb.kinematics->z();
       Energy2 pt2 = (1.-z)*(z*sqr(masses[0])-sqr(masses[1])-z/(1.-z)*sqr(masses[2]));
       if(pt2>=ZERO) {
   	break;
       }
       else {
   	// reset the scales for the children
   	for(unsigned int ix=0;ix<2;++ix) {
   	  if(fc[ix].kinematics)
   	    children[ix]->vetoEmission(fc[ix].type,fc[ix].kinematics->scale());
   	  else {
 	    if(ix==0) 
 	      children[ix]->vetoEmission(ShowerPartnerType::QCDColourLine,Constants::MaxEnergy);
 	    else
 	      children[ix]->vetoEmission(ShowerPartnerType::QCDColourLine,ZERO);
 	  }
    	} 
 	children[0]->virtualMass(_progenitor->progenitor()->mass());
 	children[1]->virtualMass(ZERO);
       }
     }
   };
   if(_reconOpt>=2) {
     // In the case of splittings which involves coloured particles,
     // set properly the colour flow of the branching.
     // update the history if needed
     _currenttree->updateInitialStateShowerProduct(_progenitor,children[0]);
     _currenttree->addInitialStateBranching(particle,children[0],children[1]);
     // shower the first  particle
     if(fc[0].kinematics) spaceLikeDecayShower(children[0],maxScales,minmass,type,Branching());
     // shower the second particle
     if(fc[1].kinematics) timeLikeShower(children[1],type,fc[1],true);
     updateHistory(children[1]);
     // branching has happened
     particle->showerKinematics()->updateParent(particle, children,fb.type);
   }
   // branching has happened
   return true;
 }
 
 vector<ShowerProgenitorPtr> QTildeShowerHandler::setupShower(bool hard) {
   RealEmissionProcessPtr real;
   // generate hard me if needed
   if(_hardEmission==1) {
     real = hardMatrixElementCorrection(hard);
     if(real&&!real->outgoing().empty()) setupMECorrection(real);
   }
   // generate POWHEG hard emission if needed
   else if(_hardEmission==2) 
     hardestEmission(hard);
   // set the initial colour partners
   setEvolutionPartners(hard,interaction_,false);
   // get the particles to be showered
   vector<ShowerProgenitorPtr> particlesToShower = 
     currentTree()->extractProgenitors();
   // return the answer
   return particlesToShower;
 }
 
 void QTildeShowerHandler::setEvolutionPartners(bool hard,ShowerInteraction::Type type,
 					       bool clear) {
   // match the particles in the ShowerTree and hardTree
   if(hardTree() && !hardTree()->connect(currentTree()))
     throw Exception() << "Can't match trees in "
 		      << "QTildeShowerHandler::setEvolutionPartners()"
 		      << Exception::eventerror;
   // extract the progenitors
   vector<ShowerParticlePtr> particles = 
     currentTree()->extractProgenitorParticles();
   // clear the partners if needed
   if(clear) {
     for(unsigned int ix=0;ix<particles.size();++ix) {
       particles[ix]->partner(ShowerParticlePtr());
       particles[ix]->clearPartners();
     }
   }
   // sort out the colour partners
   if(hardTree()) {
     // find the partner
     for(unsigned int ix=0;ix<particles.size();++ix) {
       tShowerParticlePtr partner = hardTree()->particles()[particles[ix]]->branchingParticle()->partner();
       if(!partner) continue;
       for(map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator
 	    it=hardTree()->particles().begin();
 	  it!=hardTree()->particles().end();++it) {
 	if(it->second->branchingParticle()==partner) {
 	  particles[ix]->partner(it->first);
 	  break;
 	}
       }
       if(!particles[ix]->partner()) 
 	throw Exception() << "Can't match partners in "
 			  << "QTildeShowerHandler::setEvolutionPartners()"
 			  << Exception::eventerror;
     }
   }
 
   // Set the initial evolution scales
   showerModel()->partnerFinder()->
     setInitialEvolutionScales(particles,!hard,interaction_,!_hardtree);
   if(hardTree() && _hardPOWHEG) {
     bool tooHard=false;
     map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
       eit=hardTree()->particles().end();
     for(unsigned int ix=0;ix<particles.size();++ix) {
       map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
 	mit = hardTree()->particles().find(particles[ix]);
       Energy hardScale(ZERO);
       ShowerPartnerType::Type type(ShowerPartnerType::Undefined);
       // final-state
       if(particles[ix]->isFinalState()) {
 	if(mit!= eit && !mit->second->children().empty()) {
 	  hardScale = mit->second->scale();
 	  type = mit->second->type();
 	}
       }
       // initial-state
       else {
 	if(mit!= eit && mit->second->parent()) {
 	  hardScale = mit->second->parent()->scale();
 	  type = mit->second->parent()->type();
 	}
       }
       if(type!=ShowerPartnerType::Undefined) {
 	if(type==ShowerPartnerType::QED) {
 	  tooHard |= particles[ix]->scales().QED_noAO<hardScale;
 	}
 	else if(type==ShowerPartnerType::QCDColourLine) {
 	  tooHard |= particles[ix]->scales().QCD_c_noAO<hardScale;
 	}
 	else if(type==ShowerPartnerType::QCDAntiColourLine) {
 	  tooHard |= particles[ix]->scales().QCD_ac_noAO<hardScale;
 	}
       }
     }
     if(tooHard) convertHardTree(hard,type);
   }
 }
 
 void QTildeShowerHandler::updateHistory(tShowerParticlePtr particle) {
   if(!particle->children().empty()) {
     ShowerParticleVector theChildren;
     for(unsigned int ix=0;ix<particle->children().size();++ix) {
       ShowerParticlePtr part = dynamic_ptr_cast<ShowerParticlePtr>
 	(particle->children()[ix]);
       theChildren.push_back(part);
     }
     // update the history if needed
     if(particle==_currenttree->getFinalStateShowerProduct(_progenitor))
       _currenttree->updateFinalStateShowerProduct(_progenitor,
 						  particle,theChildren);
     _currenttree->addFinalStateBranching(particle,theChildren);
     for(unsigned int ix=0;ix<theChildren.size();++ix)
       updateHistory(theChildren[ix]);
   }
 }
 
 bool QTildeShowerHandler::startTimeLikeShower(ShowerInteraction::Type type) {
   _nFSR = 0;
   // initialize basis vectors etc
   progenitor()->progenitor()->initializeFinalState();
+  if(!progenitor()->progenitor()->partner()) return false;
   if(hardTree()) {
     map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
       eit=hardTree()->particles().end(),
       mit = hardTree()->particles().find(progenitor()->progenitor());
     if( mit != eit && !mit->second->children().empty() ) {
       bool output=truncatedTimeLikeShower(progenitor()->progenitor(),
 					  mit->second ,type,Branching(),true);
       if(output) updateHistory(progenitor()->progenitor());
       return output;
     }
   }
   // do the shower
   bool output = hardOnly() ? false :
     timeLikeShower(progenitor()->progenitor() ,type,Branching(),true) ;
   if(output) updateHistory(progenitor()->progenitor());
   return output;
 }
 
 bool QTildeShowerHandler::startSpaceLikeShower(PPtr parent, ShowerInteraction::Type type) {
   // initialise the basis vectors
   progenitor()->progenitor()->initializeInitialState(parent);
+  if(!progenitor()->progenitor()->partner()) return false;
   if(hardTree()) {
     map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
       eit =hardTree()->particles().end(),
       mit = hardTree()->particles().find(progenitor()->progenitor());
     if( mit != eit && mit->second->parent() ) {
       return truncatedSpaceLikeShower( progenitor()->progenitor(),
 				       parent, mit->second->parent(), type );
     } 
   }
   // perform the shower
   return  hardOnly() ? false :
     spaceLikeShower(progenitor()->progenitor(),parent,type);
 }
 
 bool QTildeShowerHandler::
 startSpaceLikeDecayShower(const ShowerParticle::EvolutionScales & maxScales,
 			  Energy minimumMass,ShowerInteraction::Type type) {
   _nFSR = 0;
   // set up the particle basis vectors
   progenitor()->progenitor()->initializeDecay();
+  if(!progenitor()->progenitor()->partner()) return false;
   if(hardTree()) {
     map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
       eit =hardTree()->particles().end(),
       mit = hardTree()->particles().find(progenitor()->progenitor());
     if( mit != eit && mit->second->parent() ) {
       HardBranchingPtr branch=mit->second;
       while(branch->parent()) branch=branch->parent();
       return truncatedSpaceLikeDecayShower(progenitor()->progenitor(),maxScales,
 					   minimumMass, branch ,type, Branching());
     }
   }
   // perform the shower
   return  hardOnly() ? false :
     spaceLikeDecayShower(progenitor()->progenitor(),maxScales,minimumMass,type,Branching());
 }
 
 bool QTildeShowerHandler::timeLikeVetoed(const Branching & fb,
 			     ShowerParticlePtr particle) {
   // work out type of interaction
   ShowerInteraction::Type type = convertInteraction(fb.type);
   // check whether emission was harder than largest pt of hard subprocess
   if ( restrictPhasespace() && fb.kinematics->pT() > _progenitor->maxHardPt() ) 
     return true;
   // soft matrix element correction veto
   if( softMEC()) {
     if(_hardme && _hardme->hasMECorrection()) {
       if(_hardme->softMatrixElementVeto(_progenitor,particle,fb))
 	return true;
     }
     else if(_decayme && _decayme->hasMECorrection()) {
       if(_decayme->softMatrixElementVeto(_progenitor,particle,fb))
 	return true;
     }
   }
   // veto on maximum pt
   if(fb.kinematics->pT()>_progenitor->maximumpT(type)) return true;
   // general vetos
   if (fb.kinematics && !_vetoes.empty()) {
     bool vetoed=false;
     for (vector<ShowerVetoPtr>::iterator v = _vetoes.begin();
 	 v != _vetoes.end(); ++v) {
       bool test = (**v).vetoTimeLike(_progenitor,particle,fb);
       switch((**v).vetoType()) {
       case ShowerVeto::Emission:
 	vetoed |= test;
 	break;
       case ShowerVeto::Shower:
 	if(test) throw VetoShower();
 	break;
       case ShowerVeto::Event:
 	if(test) throw Veto();
 	break;
       }
     }
     if(vetoed) return true;
   }
   if ( firstInteraction() &&
        profileScales() ) {
     double weight = 
       profileScales()->
       hardScaleProfile(_progenitor->hardScale(),fb.kinematics->pT());
     if ( UseRandom::rnd() > weight )
       return true;
   }
   return false;
 }
 
 bool QTildeShowerHandler::spaceLikeVetoed(const Branching & bb,
 			      ShowerParticlePtr particle) {
   // work out type of interaction
   ShowerInteraction::Type type = convertInteraction(bb.type);
   // check whether emission was harder than largest pt of hard subprocess
   if (restrictPhasespace() && bb.kinematics->pT() > _progenitor->maxHardPt())
     return true;
   // apply the soft correction
   if( softMEC() && _hardme && _hardme->hasMECorrection() ) {
     if(_hardme->softMatrixElementVeto(_progenitor,particle,bb))
       return true;
   }
   // the more general vetos
 
   // check vs max pt for the shower
   if(bb.kinematics->pT()>_progenitor->maximumpT(type)) return true;
 
   if (!_vetoes.empty()) {
     bool vetoed=false;
     for (vector<ShowerVetoPtr>::iterator v = _vetoes.begin();
 	 v != _vetoes.end(); ++v) {
       bool test = (**v).vetoSpaceLike(_progenitor,particle,bb);
       switch ((**v).vetoType()) {
       case ShowerVeto::Emission:
 	vetoed |= test;
 	break;
       case ShowerVeto::Shower:
 	if(test) throw VetoShower();
 	break;
       case ShowerVeto::Event:
 	if(test) throw Veto();
 	break;
       }
     }
     if (vetoed) return true;
   }
   if ( firstInteraction() &&
        profileScales() ) {
     double weight = 
       profileScales()->
       hardScaleProfile(_progenitor->hardScale(),bb.kinematics->pT());
     if ( UseRandom::rnd() > weight )
       return true;
   }
   return false;
 }
 
 bool QTildeShowerHandler::spaceLikeDecayVetoed( const Branching & fb,
 				    ShowerParticlePtr particle) {
   // work out type of interaction
   ShowerInteraction::Type type = convertInteraction(fb.type);
   // apply the soft correction
   if( softMEC() && _decayme && _decayme->hasMECorrection() ) {
     if(_decayme->softMatrixElementVeto(_progenitor,particle,fb))
       return true;
   }
   // veto on hardest pt in the shower
   if(fb.kinematics->pT()> _progenitor->maximumpT(type)) return true;
   // general vetos
   if (!_vetoes.empty()) {
     bool vetoed=false;
     for (vector<ShowerVetoPtr>::iterator v = _vetoes.begin();
 	 v != _vetoes.end(); ++v) {
       bool test = (**v).vetoSpaceLike(_progenitor,particle,fb);
       switch((**v).vetoType()) {
       case ShowerVeto::Emission:
 	vetoed |= test;
 	break;
       case ShowerVeto::Shower:
 	if(test) throw VetoShower();
 	break;
       case ShowerVeto::Event:
 	if(test) throw Veto();
 	break;
       }
       if (vetoed) return true;
     }
   }
   return false;
 }
 
 void QTildeShowerHandler::hardestEmission(bool hard) {
   HardTreePtr ISRTree;
   // internal POWHEG in production or decay
   if( (( _hardme  &&  _hardme->hasPOWHEGCorrection()!=0 ) ||
        ( _decayme && _decayme->hasPOWHEGCorrection()!=0 ) ) ) {
     RealEmissionProcessPtr real;
     unsigned int type(0);
     // production
     if(_hardme) {
       assert(hard);
       real = _hardme->generateHardest( currentTree()->perturbativeProcess(),
 				       interaction_);
       type = _hardme->hasPOWHEGCorrection();
     }
     // decay
     else {
       assert(!hard);
       real = _decayme->generateHardest( currentTree()->perturbativeProcess() );
       type = _decayme->hasPOWHEGCorrection();
     }
     if(real) {
       // set up ther hard tree
       if(!real->outgoing().empty()) _hardtree = new_ptr(HardTree(real));
       // set up the vetos
       currentTree()->setVetoes(real->pT(),type);
     }
     // store initial state POWHEG radiation
     if(_hardtree && _hardme && _hardme->hasPOWHEGCorrection()==1) 
       ISRTree = _hardtree;
   }
   else if (hard) {
     // Get minimum pT cutoff used in shower approximation
     Energy maxpt = 1.*GeV;
     int colouredIn  = 0;
     int colouredOut = 0;
     for( map< ShowerProgenitorPtr, tShowerParticlePtr >::iterator it
 	   = currentTree()->outgoingLines().begin(); 
 	 it != currentTree()->outgoingLines().end(); ++it ) {
       if( it->second->coloured() ) colouredOut+=1;
     }  
     for( map< ShowerProgenitorPtr, ShowerParticlePtr >::iterator it
 	   = currentTree()->incomingLines().begin(); 
 	 it != currentTree()->incomingLines().end(); ++it ) {
       if( ! it->second->coloured() ) colouredIn+=1;
     }
 
     if ( currentTree()->showerApproximation() ){
       if ( currentTree()->showerApproximation()->ffPtCut() == currentTree()->showerApproximation()->fiPtCut() &&
 	   currentTree()->showerApproximation()->ffPtCut() == currentTree()->showerApproximation()->iiPtCut() ) 
 	maxpt = currentTree()->showerApproximation()->ffPtCut();
       else if ( colouredIn == 2 && colouredOut == 0 )
 	maxpt = currentTree()->showerApproximation()->iiPtCut();
       else if ( colouredIn == 0 && colouredOut > 1 )
 	maxpt = currentTree()->showerApproximation()->ffPtCut();
       else if ( colouredIn == 2 && colouredOut == 1 )
 	maxpt = min(currentTree()->showerApproximation()->iiPtCut(), currentTree()->showerApproximation()->fiPtCut());
       else if ( colouredIn == 1 && colouredOut > 1 )
 	maxpt = min(currentTree()->showerApproximation()->ffPtCut(), currentTree()->showerApproximation()->fiPtCut());
       else 
 	maxpt = min(min(currentTree()->showerApproximation()->iiPtCut(), currentTree()->showerApproximation()->fiPtCut()), 
 		    currentTree()->showerApproximation()->ffPtCut());
     }
 
     // Generate hardtree from born and real emission subprocesses
     _hardtree = generateCKKW(currentTree());
 
     // Find transverse momentum of hardest emission
     if (_hardtree){
       for(set<HardBranchingPtr>::iterator it=_hardtree->branchings().begin();
      	  it!=_hardtree->branchings().end();++it) {
       	if ((*it)->parent() && (*it)->status()==HardBranching::Incoming)
       	  maxpt=(*it)->branchingParticle()->momentum().perp();
       	if ((*it)->children().size()==2 && (*it)->status()==HardBranching::Outgoing){
 	  if ((*it)->branchingParticle()->id()!=21 &&
 	      abs((*it)->branchingParticle()->id())>5 ){
 	    if ((*it)->children()[0]->branchingParticle()->id()==21 ||
 		abs((*it)->children()[0]->branchingParticle()->id())<6)
 	      maxpt=(*it)->children()[0]->branchingParticle()->momentum().perp();
 	    else if ((*it)->children()[1]->branchingParticle()->id()==21 ||
 		     abs((*it)->children()[1]->branchingParticle()->id())<6)
 	      maxpt=(*it)->children()[1]->branchingParticle()->momentum().perp();
 	  }
 	  else {
 	    if ( abs((*it)->branchingParticle()->id())<6){
 	      if (abs((*it)->children()[0]->branchingParticle()->id())<6)
 		maxpt = (*it)->children()[1]->branchingParticle()->momentum().perp();
 	      else 
 		maxpt = (*it)->children()[0]->branchingParticle()->momentum().perp();
 	    }
 	    else maxpt = (*it)->children()[1]->branchingParticle()->momentum().perp();
 	  }
       	}
       } 
     }
      
     
     // Hardest (pt) emission should be the first powheg emission.
     maxpt=min(sqrt(lastXCombPtr()->lastShowerScale()),maxpt);
 
     // Set maxpt to pT of emission when showering POWHEG real-emission subprocesses
     if (!currentTree()->isPowhegSEvent() && !currentTree()->isPowhegHEvent()){
       vector<int> outGluon;
       vector<int> outQuark;
       map< ShowerProgenitorPtr, tShowerParticlePtr >::iterator it;
       for( it = currentTree()->outgoingLines().begin(); 
 	   it != currentTree()->outgoingLines().end(); ++it ) {
 	if ( abs(it->second->id())< 6) outQuark.push_back(it->second->id());
 	if ( it->second->id()==21 )    outGluon.push_back(it->second->id());
       } 
       if (outGluon.size() + outQuark.size() == 1){
 	for( it = currentTree()->outgoingLines().begin(); 
 	     it != currentTree()->outgoingLines().end(); ++it ) {
 	  if ( abs(it->second->id())< 6 || it->second->id()==21 )
 	    maxpt = it->second->momentum().perp();
 	}
       }
       else if (outGluon.size() + outQuark.size() > 1){
 	// assume qqbar pair from a Z/gamma
 	if (outGluon.size()==1 && outQuark.size() == 2 && outQuark[0]==-outQuark[1]){
 	  for( it = currentTree()->outgoingLines().begin(); 
 	       it != currentTree()->outgoingLines().end(); ++it ) {
 	    if ( it->second->id()==21 )
 	      maxpt = it->second->momentum().perp();
 	  }
 	}
 	// otherwise take the lowest pT avoiding born DY events
 	else {
 	  maxpt = generator()->maximumCMEnergy();
 	  for( it = currentTree()->outgoingLines().begin(); 
 	       it != currentTree()->outgoingLines().end(); ++it ) {
 	    if ( abs(it->second->id())< 6 || it->second->id()==21 )
 	      maxpt = min(maxpt,it->second->momentum().perp());
 	  }
 	}
       }
     } 
 
     // set maximum pT for subsequent emissions from S events
     if ( currentTree()->isPowhegSEvent()  || (!currentTree()->isPowhegSEvent() && !currentTree()->isPowhegHEvent())){
       for( map< ShowerProgenitorPtr, tShowerParticlePtr >::iterator it
 	     = currentTree()->outgoingLines().begin(); 
 	   it != currentTree()->outgoingLines().end(); ++it ) {
 	if( ! it->second->coloured() ) continue;
 	it->first->maximumpT(maxpt, ShowerInteraction::QCD  );
       }  
       for( map< ShowerProgenitorPtr, ShowerParticlePtr >::iterator it
 	     = currentTree()->incomingLines().begin(); 
 	   it != currentTree()->incomingLines().end(); ++it ) {
 	if( ! it->second->coloured() ) continue;
 	it->first->maximumpT(maxpt, ShowerInteraction::QCD );
       }
     }  
   }
   else 
     _hardtree = generateCKKW(currentTree());
 
   // if hard me doesn't have a FSR powheg 
   // correction use decay powheg correction
   if (_hardme && _hardme->hasPOWHEGCorrection()<2) {
     addFSRUsingDecayPOWHEG(ISRTree);
   }
   // connect the trees
   if(_hardtree) {
     connectTrees(currentTree(),_hardtree,hard); 
   }
 }
 
 void QTildeShowerHandler::addFSRUsingDecayPOWHEG(HardTreePtr ISRTree) {
   // check for intermediate colour singlet resonance
   const ParticleVector inter =  _hardme->subProcess()->intermediates();
   if (inter.size()!=1 || inter[0]->momentum().m2()/GeV2 < 0 || 
       inter[0]->dataPtr()->iColour()!=PDT::Colour0) {
     return;
   }
    
   // ignore cases where outgoing particles are not coloured
   map<ShowerProgenitorPtr, tShowerParticlePtr > out = currentTree()->outgoingLines();
   if (out.size() != 2 ||
       out. begin()->second->dataPtr()->iColour()==PDT::Colour0 ||
       out.rbegin()->second->dataPtr()->iColour()==PDT::Colour0) {
     return;
   }
 
   // look up decay mode
   tDMPtr dm;
   string tag;
   string inParticle = inter[0]->dataPtr()->name() + "->";
   vector<string> outParticles;
   outParticles.push_back(out.begin ()->first->progenitor()->dataPtr()->name());
   outParticles.push_back(out.rbegin()->first->progenitor()->dataPtr()->name());
   for (int it=0; it<2; ++it){
     tag = inParticle + outParticles[it] + "," + outParticles[(it+1)%2] + ";";
     dm = generator()->findDecayMode(tag);
     if(dm) break;
   }
 
   // get the decayer
   HwDecayerBasePtr decayer;   
   if(dm) decayer = dynamic_ptr_cast<HwDecayerBasePtr>(dm->decayer());
   // check if decayer has a FSR POWHEG correction 
   if (!decayer || decayer->hasPOWHEGCorrection()<2) {
     return;
   }
   // generate the hardest emission
   // create RealEmissionProcess
   PPtr in = new_ptr(*inter[0]);
   RealEmissionProcessPtr newProcess(new_ptr(RealEmissionProcess()));
   newProcess->bornIncoming().push_back(in);
   newProcess->bornOutgoing().push_back(out.begin ()->first->progenitor());
   newProcess->bornOutgoing().push_back(out.rbegin()->first->progenitor());
   // generate the FSR
   newProcess = decayer->generateHardest(newProcess);
   HardTreePtr FSRTree;
   if(newProcess) {
     // set up ther hard tree
     if(!newProcess->outgoing().empty()) FSRTree = new_ptr(HardTree(newProcess));
     // set up the vetos
     currentTree()->setVetoes(newProcess->pT(),2);
   }
   if(!FSRTree) return;
   
   // if there is no ISRTree make _hardtree from FSRTree
   if (!ISRTree){
     vector<HardBranchingPtr> inBranch,hardBranch;
     for(map<ShowerProgenitorPtr,ShowerParticlePtr>::const_iterator
 	  cit =currentTree()->incomingLines().begin();
 	cit!=currentTree()->incomingLines().end();++cit ) {
       inBranch.push_back(new_ptr(HardBranching(cit->second,SudakovPtr(),
 					       HardBranchingPtr(),
 					       HardBranching::Incoming)));
       inBranch.back()->beam(cit->first->original()->parents()[0]);
       hardBranch.push_back(inBranch.back());
     }
     if(inBranch[0]->branchingParticle()->dataPtr()->coloured()) {
       inBranch[0]->colourPartner(inBranch[1]);
       inBranch[1]->colourPartner(inBranch[0]);
     }
     for(set<HardBranchingPtr>::iterator it=FSRTree->branchings().begin();
 	it!=FSRTree->branchings().end();++it) {
       if((**it).branchingParticle()->id()!=in->id()) 
 	hardBranch.push_back(*it);
     } 
     hardBranch[2]->colourPartner(hardBranch[3]);
     hardBranch[3]->colourPartner(hardBranch[2]);
     HardTreePtr newTree = new_ptr(HardTree(hardBranch,inBranch,
 					   ShowerInteraction::QCD));            
     _hardtree = newTree;    
   }
   
   // Otherwise modify the ISRTree to include the emission in FSRTree
   else {
     vector<tShowerParticlePtr> FSROut, ISROut;   
     set<HardBranchingPtr>::iterator itFSR, itISR;
     // get outgoing particles 
     for(itFSR =FSRTree->branchings().begin();
 	itFSR!=FSRTree->branchings().end();++itFSR){
       if ((**itFSR).status()==HardBranching::Outgoing) 
 	FSROut.push_back((*itFSR)->branchingParticle());
     }     
     for(itISR =ISRTree->branchings().begin();
 	itISR!=ISRTree->branchings().end();++itISR){
       if ((**itISR).status()==HardBranching::Outgoing) 
 	ISROut.push_back((*itISR)->branchingParticle());
     }
     
     // find COM frame formed by outgoing particles
     LorentzRotation eventFrameFSR, eventFrameISR;
     eventFrameFSR = ((FSROut[0]->momentum()+FSROut[1]->momentum()).findBoostToCM());  
     eventFrameISR = ((ISROut[0]->momentum()+ISROut[1]->momentum()).findBoostToCM());
 
     // find rotation between ISR and FSR frames
     int j=0;
     if (ISROut[0]->id()!=FSROut[0]->id()) j=1;
     eventFrameISR.rotateZ( (eventFrameFSR*FSROut[0]->momentum()).phi()-
 			   (eventFrameISR*ISROut[j]->momentum()).phi() );
     eventFrameISR.rotateY( (eventFrameFSR*FSROut[0]->momentum()).theta()-
 			   (eventFrameISR*ISROut[j]->momentum()).theta() );
     eventFrameISR.invert();
     
     for (itFSR=FSRTree->branchings().begin();
 	 itFSR!=FSRTree->branchings().end();++itFSR){
       if ((**itFSR).branchingParticle()->id()==in->id()) continue;
       for (itISR =ISRTree->branchings().begin();
 	   itISR!=ISRTree->branchings().end();++itISR){
 	if ((**itISR).status()==HardBranching::Incoming) continue;
 	if ((**itFSR).branchingParticle()->id()==
 	    (**itISR).branchingParticle()->id()){
 	  // rotate FSRTree particle to ISRTree event frame
 	  (**itISR).branchingParticle()->setMomentum(eventFrameISR*
 						     eventFrameFSR*
 						     (**itFSR).branchingParticle()->momentum());
 	  (**itISR).branchingParticle()->rescaleMass();
 	  // add the children of the FSRTree particles to the ISRTree
 	  if(!(**itFSR).children().empty()){
 	    (**itISR).addChild((**itFSR).children()[0]);
 	    (**itISR).addChild((**itFSR).children()[1]);
 	    // rotate momenta to ISRTree event frame
 	    (**itISR).children()[0]->branchingParticle()->setMomentum(eventFrameISR*
 								      eventFrameFSR*
 								      (**itFSR).children()[0]->branchingParticle()->momentum());
 	    (**itISR).children()[1]->branchingParticle()->setMomentum(eventFrameISR*
 								      eventFrameFSR*
 								      (**itFSR).children()[1]->branchingParticle()->momentum());
 	  }
 	}
       }	
     }
     _hardtree = ISRTree;
   }
 }
 
 bool QTildeShowerHandler::truncatedTimeLikeShower(tShowerParticlePtr particle,
 				      HardBranchingPtr branch,
 				      ShowerInteraction::Type type,
 				      Branching fb, bool first) {
   // select a branching if we don't have one
   if(!fb.kinematics)
     fb = selectTimeLikeBranching(particle,type,branch);
   // must be an emission, the forced one it not a truncated one
   assert(fb.kinematics);
   ShowerParticleVector children;
   int ntry=0;
   Branching fc[2];
   bool setupChildren = true;
   while (ntry<50) {
     if(!fc[0].hard) fc[0] = Branching();
     if(!fc[1].hard) fc[1] = Branching();
     ++ntry;
     // Assign the shower kinematics to the emitting particle.
     if(setupChildren) {
       ++_nFSR;
       // Assign the shower kinematics to the emitting particle.
       particle->showerKinematics(fb.kinematics);
       if(fb.kinematics->pT()>progenitor()->highestpT())
 	progenitor()->highestpT(fb.kinematics->pT());
       // create the children
       children = createTimeLikeChildren(particle,fb.ids);
       // update the children
       particle->showerKinematics()->
    	updateChildren(particle, children,fb.type,_reconOpt>=3);
       setupChildren = false;
     }
     // select branchings for children
     if(!fc[0].kinematics) {
       // select branching for first particle
       if(!fb.hard && fb.iout ==1 )
 	fc[0] = selectTimeLikeBranching(children[0],type,branch);
       else if(fb.hard && !branch->children()[0]->children().empty() )
 	fc[0] = selectTimeLikeBranching(children[0],type,branch->children()[0]);
       else
 	fc[0] = selectTimeLikeBranching(children[0],type,HardBranchingPtr());
     }
     // select branching for the second particle
     if(!fc[1].kinematics) {
       // select branching for first particle
       if(!fb.hard && fb.iout ==2 )
 	fc[1] = selectTimeLikeBranching(children[1],type,branch);
       else if(fb.hard && !branch->children()[1]->children().empty() )
 	fc[1] = selectTimeLikeBranching(children[1],type,branch->children()[1]);
       else
 	fc[1] = selectTimeLikeBranching(children[1],type,HardBranchingPtr());
     }
     // old default
     if(_reconOpt==0 || (_reconOpt==1 && fb.hard) ) {
       // shower the first  particle
       if(fc[0].kinematics) {
 	// the parent has truncated emission and following line
 	if(!fb.hard && fb.iout == 1)
 	  truncatedTimeLikeShower(children[0],branch,type,fc[0],false);
 	// hard emission and subsquent hard emissions
 	else if(fb.hard && !branch->children()[0]->children().empty() )
 	  truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[0],false);
 	// normal shower
 	else
 	  timeLikeShower(children[0],type,fc[0],false);
       }
       if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
       // shower the second particle
       if(fc[1].kinematics) {
 	// the parent has truncated emission and following line
 	if(!fb.hard && fb.iout == 2)
 	  truncatedTimeLikeShower(children[1],branch,type,fc[1],false);
 	// hard emission and subsquent hard emissions
 	else if(fb.hard && !branch->children()[1]->children().empty() )
 	  truncatedTimeLikeShower(children[1],branch->children()[1],type,fc[1],false);
 	else
 	  timeLikeShower(children[1],type,fc[1],false);
       }
       if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
       // branching has happened
       particle->showerKinematics()->updateParent(particle, children,fb.type);
       break;
     }
     // H7 default
     else if(_reconOpt==1) {
       // shower the first  particle
       if(fc[0].kinematics) {
 	// the parent has truncated emission and following line
 	if(!fb.hard && fb.iout == 1)
 	  truncatedTimeLikeShower(children[0],branch,type,fc[0],false);
 	else
 	  timeLikeShower(children[0],type,fc[0],false);
       }
       if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
       // shower the second particle
       if(fc[1].kinematics) {
 	// the parent has truncated emission and following line
 	if(!fb.hard && fb.iout == 2)
 	  truncatedTimeLikeShower(children[1],branch,type,fc[1],false);
 	else
 	  timeLikeShower(children[1],type,fc[1],false);
       }
       if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
       // branching has happened
       particle->showerKinematics()->updateParent(particle, children,fb.type);
       // clean up the vetoed emission
       if(particle->virtualMass()==ZERO) {
    	particle->showerKinematics(ShoKinPtr());
     	for(unsigned int ix=0;ix<children.size();++ix)
    	  particle->abandonChild(children[ix]);
     	children.clear();
    	if(particle->spinInfo()) particle->spinInfo()->decayVertex(VertexPtr());
   	particle->vetoEmission(fb.type,fb.kinematics->scale());
    	// generate the new emission
    	fb = selectTimeLikeBranching(particle,type,branch);
 	// must be at least hard emission
 	assert(fb.kinematics);
    	setupChildren = true;
   	continue;
       }
       else
    	break;
     }
     else if(_reconOpt>=2) {
       // cut-off masses for the branching
       const vector<Energy> & virtualMasses = fb.sudakov->virtualMasses(fb.ids);
       // compute the masses of the children
       Energy masses[3];
       for(unsigned int ix=0;ix<2;++ix) {
    	if(fc[ix].kinematics) {
    	  const vector<Energy> & vm = fc[ix].sudakov->virtualMasses(fc[ix].ids);
    	  Energy2 q2 = 
    	    fc[ix].kinematics->z()*(1.-fc[ix].kinematics->z())*sqr(fc[ix].kinematics->scale());
    	  if(fc[ix].ids[0]->id()!=ParticleID::g) q2 += sqr(vm[0]);
    	  masses[ix+1] = sqrt(q2);
    	}
    	else {
    	  masses[ix+1] = virtualMasses[ix+1];
    	}
       }
       masses[0] = fb.ids[0]->id()!=ParticleID::g ? virtualMasses[0] : ZERO;
       double z = fb.kinematics->z();
       Energy2 pt2 = z*(1.-z)*(z*(1.-z)*sqr(fb.kinematics->scale()) + sqr(masses[0]))
    	- sqr(masses[1])*(1.-z) - sqr(masses[2])*z;
       if(pt2>=ZERO) {
   	break;
       }
       // if only the hard emission have to accept it
       else if ((fc[0].hard && !fc[1].kinematics) ||
 	       (fc[1].hard && !fc[0].kinematics) ) {
 	break;
       }
       else {
   	// reset the scales for the children
    	for(unsigned int ix=0;ix<2;++ix) {
 	  if(fc[ix].hard) continue;
    	  if(fc[ix].kinematics && ! fc[ix].hard )
    	    children[ix]->vetoEmission(fc[ix].type,fc[ix].kinematics->scale());
   	  else
   	    children[ix]->vetoEmission(ShowerPartnerType::QCDColourLine,ZERO);
   	  children[ix]->virtualMass(ZERO);
   	} 
       }
     }
   };
   if(_reconOpt>=2) {
     // shower the first  particle
     if(fc[0].kinematics) {
       // the parent has truncated emission and following line
       if(!fb.hard && fb.iout == 1)
 	truncatedTimeLikeShower(children[0],branch,type,fc[0],false);
       // hard emission and subsquent hard emissions
       else if(fb.hard && !branch->children()[0]->children().empty() )
 	truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[0],false);
       // normal shower
       else
 	timeLikeShower(children[0],type,fc[0],false);
     }
     if(children[0]->spinInfo()) children[0]->spinInfo()->develop();
     // shower the second particle
     if(fc[1].kinematics) {
       // the parent has truncated emission and following line
       if(!fb.hard && fb.iout == 2)
 	truncatedTimeLikeShower(children[1],branch,type,fc[1],false);
       // hard emission and subsquent hard emissions
       else if(fb.hard && !branch->children()[1]->children().empty() )
 	truncatedTimeLikeShower(children[1],branch->children()[1],type,fc[1],false);
       else
 	timeLikeShower(children[1],type,fc[1],false);
     }
     if(children[1]->spinInfo()) children[1]->spinInfo()->develop();
     // branching has happened
     particle->showerKinematics()->updateParent(particle, children,fb.type);
   }
   if(first&&!children.empty())
     particle->showerKinematics()->resetChildren(particle,children);
   if(particle->spinInfo()) particle->spinInfo()->develop();
   return true;
 }
 
 bool QTildeShowerHandler::truncatedSpaceLikeShower(tShowerParticlePtr particle, PPtr beam,
 				       HardBranchingPtr branch,
 				       ShowerInteraction::Type type) {
   tcPDFPtr pdf;
   if(firstPDF().particle()  == beamParticle())
     pdf = firstPDF().pdf();
   if(secondPDF().particle() == beamParticle())
     pdf = secondPDF().pdf();
   Energy freeze = pdfFreezingScale();
   Branching bb;
   // parameters of the force branching
   double z(0.);
   HardBranchingPtr timelike;
   for( unsigned int ix = 0; ix < branch->children().size(); ++ix ) {
     if( branch->children()[ix]->status() ==HardBranching::Outgoing) {
       timelike = branch->children()[ix];
     }
     if( branch->children()[ix]->status() ==HardBranching::Incoming )
       z = branch->children()[ix]->z();
   }
   // generate truncated branching
   tcPDPtr part[2];
   if(z>=0.&&z<=1.) {
     while (true) {
       if( !isTruncatedShowerON() || hardOnly() ) break;
       bb = splittingGenerator()->chooseBackwardBranching( *particle, 
 							  beam, 1., beamParticle(), 
 							  type , pdf,freeze);
       if( !bb.kinematics || bb.kinematics->scale() < branch->scale() ) {
 	bb = Branching();
 	break;
       }
       // particles as in Sudakov form factor
       part[0] = bb.ids[0];
       part[1] = bb.ids[2];
       double zsplit = bb.kinematics->z();
       // apply the vetos for the truncated shower
       // if doesn't carry most of momentum
       ShowerInteraction::Type type2 = convertInteraction(bb.type);
       if(type2==branch->sudakov()->interactionType() &&
 	 zsplit < 0.5) {
 	particle->vetoEmission(bb.type,bb.kinematics->scale());
 	continue;
       }
       // others
       if( part[0]->id() != particle->id() || // if particle changes type
 	  bb.kinematics->pT() > progenitor()->maximumpT(type2) ||   // pt veto
 	  bb.kinematics->scale() < branch->scale()) { // angular ordering veto
 	particle->vetoEmission(bb.type,bb.kinematics->scale());
 	continue;
       }
       // and those from the base class
       if(spaceLikeVetoed(bb,particle)) {
 	particle->vetoEmission(bb.type,bb.kinematics->scale());
 	continue;
       }
       break;
     }
   }
   if( !bb.kinematics ) {
     //do the hard emission
     ShoKinPtr kinematics =
       branch->sudakov()->createInitialStateBranching( branch->scale(), z, branch->phi(),
     						      branch->children()[0]->pT() );
     // assign the splitting function and shower kinematics
     particle->showerKinematics( kinematics );
     if(kinematics->pT()>progenitor()->highestpT())
       progenitor()->highestpT(kinematics->pT());
     // For the time being we are considering only 1->2 branching
     // Now create the actual particles, make the otherChild a final state
     // particle, while the newParent is not
     ShowerParticlePtr newParent = 
       new_ptr( ShowerParticle( branch->branchingParticle()->dataPtr(), false ) );
     ShowerParticlePtr otherChild = 
       new_ptr( ShowerParticle( timelike->branchingParticle()->dataPtr(),
     			       true, true ) );
     ShowerParticleVector theChildren;
     theChildren.push_back( particle ); 
     theChildren.push_back( otherChild );
     particle->showerKinematics()->
       updateParent( newParent, theChildren, branch->type());
     // update the history if needed
     currentTree()->updateInitialStateShowerProduct( progenitor(), newParent );
     currentTree()->addInitialStateBranching( particle, newParent, otherChild );
     // for the reconstruction of kinematics, parent/child
     // relationships are according to the branching process:
     // now continue the shower
     bool emitted=false;
     if(!hardOnly()) {
       if( branch->parent() ) {
     	emitted = truncatedSpaceLikeShower( newParent, beam, branch->parent() , type);
       }
       else {
     	emitted = spaceLikeShower( newParent, beam , type);
       }
     }
     if( !emitted ) {
       if( intrinsicpT().find( progenitor() ) == intrinsicpT().end() ) {
     	kinematics->updateLast( newParent, ZERO, ZERO );
       }
       else {
     	pair<Energy,double> kt = intrinsicpT()[progenitor()];
     	kinematics->updateLast( newParent,
     				kt.first*cos( kt.second ),
     				kt.first*sin( kt.second ) );
       }
     }
     particle->showerKinematics()->
       updateChildren( newParent, theChildren,bb.type,false);
     if(hardOnly()) return true;
     // perform the shower of the final-state particle
     if( timelike->children().empty() ) {
       timeLikeShower( otherChild , type,Branching(),true);
     }
     else {
       truncatedTimeLikeShower( otherChild, timelike , type,Branching(), true);
     }
     updateHistory(otherChild);
     // return the emitted
     return true;
   }
   // assign the splitting function and shower kinematics
   particle->showerKinematics( bb.kinematics );
   if(bb.kinematics->pT()>progenitor()->highestpT())
     progenitor()->highestpT(bb.kinematics->pT());
   // For the time being we are considering only 1->2 branching
   // Now create the actual particles, make the otherChild a final state
   // particle, while the newParent is not
   ShowerParticlePtr newParent = new_ptr( ShowerParticle( part[0], false ) );
   ShowerParticlePtr otherChild = new_ptr( ShowerParticle( part[1], true, true ) );
   ShowerParticleVector theChildren; 
   theChildren.push_back( particle ); 
   theChildren.push_back( otherChild );
   particle->showerKinematics()->
     updateParent( newParent, theChildren, bb.type);
   // update the history if needed
   currentTree()->updateInitialStateShowerProduct( progenitor(), newParent );
   currentTree()->addInitialStateBranching( particle, newParent, otherChild );
   // for the reconstruction of kinematics, parent/child
   // relationships are according to the branching process:
   // now continue the shower
   bool emitted = truncatedSpaceLikeShower( newParent, beam, branch,type);
   // now reconstruct the momentum
   if( !emitted ) {
     if( intrinsicpT().find( progenitor() ) == intrinsicpT().end() ) {
       bb.kinematics->updateLast( newParent, ZERO, ZERO );
     }
     else {
       pair<Energy,double> kt = intrinsicpT()[ progenitor() ];
       bb.kinematics->updateLast( newParent,
 				 kt.first*cos( kt.second ),
 				 kt.first*sin( kt.second ) );
     }
   }
   particle->showerKinematics()->
     updateChildren( newParent, theChildren, bb.type,false);
   // perform the shower of the final-state particle
   timeLikeShower( otherChild , type,Branching(),true);
   updateHistory(otherChild);
   // return the emitted
   return true;
 }
 
 bool QTildeShowerHandler::
 truncatedSpaceLikeDecayShower(tShowerParticlePtr particle, 
 			      const ShowerParticle::EvolutionScales & maxScales,
 			      Energy minmass, HardBranchingPtr branch,
 			      ShowerInteraction::Type type, Branching fb) {
   // select a branching if we don't have one
   if(!fb.kinematics)
     fb = selectSpaceLikeDecayBranching(particle,maxScales,minmass,type,branch);
   // must be an emission, the forced one it not a truncated one
   assert(fb.kinematics);
   ShowerParticleVector children;
   int ntry=0;
   Branching fc[2];
   bool setupChildren = true;
   while (ntry<50) {
     if(!fc[0].hard) fc[0] = Branching();
     if(!fc[1].hard) fc[1] = Branching();
     ++ntry;
     if(setupChildren) {
       ++_nFSR;
       // Assign the shower kinematics to the emitting particle.
       particle->showerKinematics(fb.kinematics);
       if(fb.kinematics->pT()>progenitor()->highestpT())
 	progenitor()->highestpT(fb.kinematics->pT());
       // create the ShowerParticle objects for the two children
       children = createTimeLikeChildren(particle,fb.ids);
       // updateChildren the children
       particle->showerKinematics()->
 	updateChildren(particle, children, fb.type,_reconOpt>=3);
       setupChildren = false;
     }
     // select branchings for children
     if(!fc[0].kinematics) {
       if(children[0]->id()==particle->id()) {
 	// select branching for first particle
 	if(!fb.hard)
 	  fc[0] = selectSpaceLikeDecayBranching(children[0],maxScales,minmass,type,branch);
 	else if(fb.hard && ! branch->children()[0]->children().empty() )
 	  fc[0] = selectSpaceLikeDecayBranching(children[0],maxScales,minmass,type,
 						branch->children()[0]);
 	else
 	  fc[0] = selectSpaceLikeDecayBranching(children[0],maxScales,minmass,type,
 						HardBranchingPtr());
       }
       else {
 	// select branching for first particle
 	if(fb.hard && !branch->children()[0]->children().empty() )
 	  fc[0] = selectTimeLikeBranching(children[0],type,branch->children()[0]);
 	else
 	  fc[0] = selectTimeLikeBranching(children[0],type,HardBranchingPtr());
       }
     }
     // select branching for the second particle
      if(!fc[1].kinematics) {
        if(children[1]->id()==particle->id()) {
 	 // select branching for first particle
 	 if(!fb.hard)
 	   fc[1] = selectSpaceLikeDecayBranching(children[1],maxScales,minmass,type,branch);
 	 else if(fb.hard && ! branch->children()[1]->children().empty() )
 	   fc[1] = selectSpaceLikeDecayBranching(children[1],maxScales,minmass,type,
 						 branch->children()[1]);
 	 else
 	   fc[1] = selectSpaceLikeDecayBranching(children[1],maxScales,minmass,type,
 						 HardBranchingPtr());
        }
        else {
 	 if(fb.hard && !branch->children()[1]->children().empty() )
 	   fc[1] = selectTimeLikeBranching(children[1],type,branch->children()[1]);
 	 else
 	   fc[1] = selectTimeLikeBranching(children[1],type,HardBranchingPtr());
        }
      }
     // old default
     if(_reconOpt==0 || (_reconOpt==1 && fb.hard) ) {
       // update the history if needed
       currentTree()->updateInitialStateShowerProduct(progenitor(),children[0]);
       currentTree()->addInitialStateBranching(particle,children[0],children[1]);
       // shower the first  particle
       if(fc[0].kinematics) {
 	if(children[0]->id()==particle->id()) {
 	  if(!fb.hard)
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch,type,fc[0]);
 	  else if(fb.hard && ! branch->children()[0]->children().empty() )
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch->children()[0],type,fc[0]);
 	  else
 	    spaceLikeDecayShower( children[0],maxScales,minmass,type,fc[0]);
 	}
 	else {
 	  if(fb.hard && !branch->children()[0]->children().empty() )
 	    truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[0],false);
 	  // normal shower
 	  else
 	    timeLikeShower(children[0],type,fc[0],false);
 	}
       }
       // shower the second  particle
       if(fc[1].kinematics) {
 	if(children[0]->id()==particle->id()) {
 	  if(!fb.hard)
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch,type,fc[1]);
 	  else if(fb.hard && ! branch->children()[0]->children().empty() )
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch->children()[0],type,fc[1]);
 	  else
 	    spaceLikeDecayShower( children[0],maxScales,minmass,type,fc[1]);
 	}
 	else {
 	  if(fb.hard && !branch->children()[0]->children().empty() )
 	    truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[1],false);
 	  // normal shower
 	  else
 	    timeLikeShower(children[0],type,fc[1],false);
 	}
       }
       updateHistory(children[1]);
       // branching has happened
       break;
     }
     // H7 default
     else if(_reconOpt==1) {
       // update the history if needed
       currentTree()->updateInitialStateShowerProduct(progenitor(),children[0]);
       currentTree()->addInitialStateBranching(particle,children[0],children[1]);
       // shower the first  particle
       if(fc[0].kinematics) {
 	if(children[0]->id()==particle->id()) {
 	  if(!fb.hard)
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch,type,fc[0]);
 	  else if(fb.hard && ! branch->children()[0]->children().empty() )
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch->children()[0],type,fc[0]);
 	  else
 	    spaceLikeDecayShower( children[0],maxScales,minmass,type,fc[0]);
 	}
 	else {
 	  if(fb.hard && !branch->children()[0]->children().empty() )
 	    truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[0],false);
 	  // normal shower
 	  else
 	    timeLikeShower(children[0],type,fc[0],false);
 	}
       }
       // shower the second  particle
       if(fc[1].kinematics) {
 	if(children[0]->id()==particle->id()) {
 	  if(!fb.hard)
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch,type,fc[1]);
 	  else if(fb.hard && ! branch->children()[0]->children().empty() )
 	    truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					   branch->children()[0],type,fc[1]);
 	  else
 	    spaceLikeDecayShower( children[0],maxScales,minmass,type,fc[1]);
 	}
 	else {
 	  if(fb.hard && !branch->children()[0]->children().empty() )
 	    truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[1],false);
 	  // normal shower
 	  else
 	    timeLikeShower(children[0],type,fc[1],false);
 	}
       }
       // clean up the vetoed emission
       if(particle->virtualMass()==ZERO) {
    	particle->showerKinematics(ShoKinPtr());
     	for(unsigned int ix=0;ix<children.size();++ix)
    	  particle->abandonChild(children[ix]);
     	children.clear();
    	particle->vetoEmission(fb.type,fb.kinematics->scale());
     	// generate the new emission
    	fb = selectSpaceLikeDecayBranching(particle,maxScales,minmass,type,branch);
    	// must be at least hard emission
   	assert(fb.kinematics);
    	setupChildren = true;
  	continue;
       }
       else {
 	updateHistory(children[1]);
   	break;
       }
     }
     else if(_reconOpt>=2) {
       // cut-off masses for the branching
       const vector<Energy> & virtualMasses = fb.sudakov->virtualMasses(fb.ids);
       // compute the masses of the children
       Energy masses[3];
       // space-like children
       masses[1] = children[0]->virtualMass();
       // time-like child
       if(fc[1].kinematics) {
 	const vector<Energy> & vm = fc[1].sudakov->virtualMasses(fc[1].ids);
 	Energy2 q2 = 
 	  fc[1].kinematics->z()*(1.-fc[1].kinematics->z())*sqr(fc[1].kinematics->scale());
 	if(fc[1].ids[0]->id()!=ParticleID::g) q2 += sqr(vm[0]);
 	masses[2] = sqrt(q2);
       }
       else {
 	masses[2] = virtualMasses[2];
       } 
       masses[0]=particle->virtualMass();
       double z = fb.kinematics->z();
       Energy2 pt2 = (1.-z)*(z*sqr(masses[0])-sqr(masses[1])-z/(1.-z)*sqr(masses[2]));
       if(pt2>=ZERO) {
   	break;
       }
       else {
   	// reset the scales for the children
   	for(unsigned int ix=0;ix<2;++ix) {
   	  if(fc[ix].kinematics)
   	    children[ix]->vetoEmission(fc[ix].type,fc[ix].kinematics->scale());
   	  else {
 	    if(ix==0) 
 	      children[ix]->vetoEmission(ShowerPartnerType::QCDColourLine,Constants::MaxEnergy);
 	    else
 	      children[ix]->vetoEmission(ShowerPartnerType::QCDColourLine,ZERO);
 	  }
    	} 
 	children[0]->virtualMass(_progenitor->progenitor()->mass());
 	children[1]->virtualMass(ZERO);
       }
     }
   };
   if(_reconOpt>=2) {
     // update the history if needed
     currentTree()->updateInitialStateShowerProduct(progenitor(),children[0]);
     currentTree()->addInitialStateBranching(particle,children[0],children[1]);
     // shower the first  particle
     if(fc[0].kinematics) {
       if(children[0]->id()==particle->id()) {
 	if(!fb.hard)
 	  truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					 branch,type,fc[0]);
 	else if(fb.hard && ! branch->children()[0]->children().empty() )
 	  truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					 branch->children()[0],type,fc[0]);
 	else
 	  spaceLikeDecayShower( children[0],maxScales,minmass,type,fc[0]);
       }
       else {
 	if(fb.hard && !branch->children()[0]->children().empty() )
 	  truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[0],false);
 	// normal shower
 	else
 	  timeLikeShower(children[0],type,fc[0],false);
       }
     }
     // shower the second  particle
     if(fc[1].kinematics) {
       if(children[0]->id()==particle->id()) {
 	if(!fb.hard)
 	  truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					 branch,type,fc[1]);
 	else if(fb.hard && ! branch->children()[0]->children().empty() )
 	  truncatedSpaceLikeDecayShower( children[0],maxScales,minmass,
 					 branch->children()[0],type,fc[1]);
 	else
 	  spaceLikeDecayShower( children[0],maxScales,minmass,type,fc[1]);
       }
       else {
 	if(fb.hard && !branch->children()[0]->children().empty() )
 	  truncatedTimeLikeShower(children[0],branch->children()[0],type,fc[1],false);
 	// normal shower
 	else
 	  timeLikeShower(children[0],type,fc[1],false);
       }
     }
     updateHistory(children[1]);
   }
   return true;
 }
 
 void QTildeShowerHandler::connectTrees(ShowerTreePtr showerTree, 
 				       HardTreePtr hardTree, bool hard ) {
   ShowerParticleVector particles;
   // find the Sudakovs
   for(set<HardBranchingPtr>::iterator cit=hardTree->branchings().begin();
       cit!=hardTree->branchings().end();++cit) {
     // Sudakovs for ISR
     if((**cit).parent()&&(**cit).status()==HardBranching::Incoming) {
       ++_nis;
       vector<long> br(3);
       br[0] = (**cit).parent()->branchingParticle()->id();
       br[1] = (**cit).          branchingParticle()->id();
       br[2] = (**cit).parent()->children()[0]==*cit ?
 	(**cit).parent()->children()[1]->branchingParticle()->id() :
 	(**cit).parent()->children()[0]->branchingParticle()->id();
       BranchingList branchings = splittingGenerator()->initialStateBranchings();
       if(br[1]<0&&br[0]==br[1]) {
 	br[0] = abs(br[0]);
 	br[1] = abs(br[1]);
       }
       else if(br[1]<0) {
 	br[1] = -br[1];
 	br[2] = -br[2];
       }
       long index = abs(br[1]);
       SudakovPtr sudakov;
       for(BranchingList::const_iterator cjt = branchings.lower_bound(index); 
 	  cjt != branchings.upper_bound(index); ++cjt ) {
 	IdList ids = cjt->second.particles;
 	if(ids[0]->id()==br[0]&&ids[1]->id()==br[1]&&ids[2]->id()==br[2]) {
 	  sudakov=cjt->second.sudakov;
 	  break;
 	}
       }
       if(!sudakov) throw Exception() << "Can't find Sudakov for the hard emission in "
 				     << "QTildeShowerHandler::connectTrees() for ISR" 
 				     << Exception::runerror;
       (**cit).parent()->sudakov(sudakov);
     }
     // Sudakovs for FSR
     else if(!(**cit).children().empty()) {
       ++_nfs;
       vector<long> br(3);
       br[0] = (**cit)               .branchingParticle()->id();
       br[1] = (**cit).children()[0]->branchingParticle()->id();
       br[2] = (**cit).children()[1]->branchingParticle()->id();
       BranchingList branchings = splittingGenerator()->finalStateBranchings();
       if(br[0]<0) {
 	br[0] = abs(br[0]);
 	br[1] = abs(br[1]);
 	br[2] = abs(br[2]);
       }
       long index = br[0];
       SudakovPtr sudakov;
       for(BranchingList::const_iterator cjt = branchings.lower_bound(index); 
 	  cjt != branchings.upper_bound(index); ++cjt ) {
 	IdList ids = cjt->second.particles;
 	if(ids[0]->id()==br[0]&&ids[1]->id()==br[1]&&ids[2]->id()==br[2]) {
 	  sudakov=cjt->second.sudakov;
 	  break;
 	}
       }
       if(!sudakov) {
 	throw Exception() << "Can't find Sudakov for the hard emission in "
 			  << "QTildeShowerHandler::connectTrees()" 
 			  << Exception::runerror;
       }
       (**cit).sudakov(sudakov);
     }
   }
   // calculate the evolution scale
   for(set<HardBranchingPtr>::iterator cit=hardTree->branchings().begin();
       cit!=hardTree->branchings().end();++cit) {
     particles.push_back((*cit)->branchingParticle());
   }
   showerModel()->partnerFinder()->
     setInitialEvolutionScales(particles,!hard,interaction_,true);
   hardTree->partnersSet(true);
   // inverse reconstruction
   if(hard) {
     showerModel()->kinematicsReconstructor()->
       deconstructHardJets(hardTree,interaction_);
   }
   else
     showerModel()->kinematicsReconstructor()->
       deconstructDecayJets(hardTree,interaction_);
   // now reset the momenta of the showering particles
   vector<ShowerProgenitorPtr> particlesToShower=showerTree->extractProgenitors();
   // match them
   map<ShowerProgenitorPtr,HardBranchingPtr> partners;
   for(set<HardBranchingPtr>::const_iterator bit=hardTree->branchings().begin();
       bit!=hardTree->branchings().end();++bit) {
     Energy2 dmin( 1e30*GeV2 );
     ShowerProgenitorPtr partner;
     for(vector<ShowerProgenitorPtr>::const_iterator pit=particlesToShower.begin();
 	pit!=particlesToShower.end();++pit) {
       if(partners.find(*pit)!=partners.end()) continue;
       if( (**bit).branchingParticle()->id() !=  (**pit).progenitor()->id() ) continue;
       if( (**bit).branchingParticle()->isFinalState() !=
 	  (**pit).progenitor()->isFinalState() ) continue;
       if( (**pit).progenitor()->isFinalState() ) {
 	Energy2 dtest =
 	  sqr( (**pit).progenitor()->momentum().x() - (**bit).showerMomentum().x() ) +
 	  sqr( (**pit).progenitor()->momentum().y() - (**bit).showerMomentum().y() ) +
 	  sqr( (**pit).progenitor()->momentum().z() - (**bit).showerMomentum().z() ) +
 	  sqr( (**pit).progenitor()->momentum().t() - (**bit).showerMomentum().t() );
 	// add mass difference for identical particles (e.g. Z0 Z0 production)
 	dtest += 1e10*sqr((**pit).progenitor()->momentum().m()-(**bit).showerMomentum().m());
 	if( dtest < dmin ) {
 	  partner = *pit;
 	  dmin = dtest;
 	}
       }
       else {
 	// ensure directions are right
 	if((**pit).progenitor()->momentum().z()/(**bit).showerMomentum().z()>ZERO) {
 	  partner = *pit;
 	  break;
 	}
       }
     }
     if(!partner) throw Exception() << "Failed to match shower and hard trees in QTildeShowerHandler::hardestEmission"
 				   << Exception::eventerror;
     partners[partner] = *bit;
   }
   for(vector<ShowerProgenitorPtr>::const_iterator pit=particlesToShower.begin();
       pit!=particlesToShower.end();++pit) {
     HardBranchingPtr partner = partners[*pit];
     if((**pit).progenitor()->dataPtr()->stable()) {
       (**pit).progenitor()->set5Momentum(partner->showerMomentum());
       (**pit).copy()->set5Momentum(partner->showerMomentum());
     }
     else {
       Lorentz5Momentum oldMomentum = (**pit).progenitor()->momentum();
       Lorentz5Momentum newMomentum = partner->showerMomentum();
       LorentzRotation boost( oldMomentum.findBoostToCM(),oldMomentum.e()/oldMomentum.mass());
       (**pit).progenitor()->transform(boost);
       (**pit).copy()      ->transform(boost);
       boost = LorentzRotation(-newMomentum.findBoostToCM(),newMomentum.e()/newMomentum.mass());
       (**pit).progenitor()->transform(boost);
       (**pit).copy()      ->transform(boost);
     }
   }
   // correction boosts for daughter trees
   for(map<tShowerTreePtr,pair<tShowerProgenitorPtr,tShowerParticlePtr> >::const_iterator 
 	tit  = showerTree->treelinks().begin();
       tit != showerTree->treelinks().end();++tit) {
     ShowerTreePtr decayTree = tit->first;
     map<ShowerProgenitorPtr,ShowerParticlePtr>::const_iterator 
       cit = decayTree->incomingLines().begin();
     // reset the momentum of the decay particle
     Lorentz5Momentum oldMomentum = cit->first->progenitor()->momentum();
     Lorentz5Momentum newMomentum = tit->second.second->momentum();
     LorentzRotation boost( oldMomentum.findBoostToCM(),oldMomentum.e()/oldMomentum.mass());
     decayTree->transform(boost,true);
     boost = LorentzRotation(-newMomentum.findBoostToCM(),newMomentum.e()/newMomentum.mass());
     decayTree->transform(boost,true);
   }
 }
 
 void QTildeShowerHandler::doShowering(bool hard,XCPtr xcomb) {
   // zero number of emissions
   _nis = _nfs = 0;
   // if MC@NLO H event and limited emissions
   // indicate both final and initial state emission
   if ( currentTree()->isMCatNLOHEvent() && _limitEmissions != 0 ) {
     _nis = _nfs = 1;
   }
   // extract particles to shower
   vector<ShowerProgenitorPtr> particlesToShower(setupShower(hard));
   // check if we should shower
   bool colCharge = false;
   for(unsigned int ix=0;ix<particlesToShower.size();++ix) {
     if(particlesToShower[ix]->progenitor()->dataPtr()->coloured() ||
        particlesToShower[ix]->progenitor()->dataPtr()->charged()) {
       colCharge = true;
       break;
     }
   }
   if(!colCharge) {
     _currenttree->hasShowered(true);
     return;
   }
   // setup the maximum scales for the shower
   if (restrictPhasespace()) setupMaximumScales(particlesToShower,xcomb);
   // set the hard scales for the profiles
   setupHardScales(particlesToShower,xcomb);
   // specific stuff for hard processes and decays
   Energy minmass(ZERO), mIn(ZERO);
   // hard process generate the intrinsic p_T once and for all
   if(hard) {
     generateIntrinsicpT(particlesToShower);
   }
   // decay compute the minimum mass of the final-state
   else {
     for(unsigned int ix=0;ix<particlesToShower.size();++ix) {
       if(particlesToShower[ix]->progenitor()->isFinalState()) {
 	if(particlesToShower[ix]->progenitor()->dataPtr()->stable()) 
 	  minmass += particlesToShower[ix]->progenitor()->dataPtr()->constituentMass();
 	else
 	  minmass += particlesToShower[ix]->progenitor()->mass();
       }
       else {
 	mIn = particlesToShower[ix]->progenitor()->mass();
       }
     }
     // throw exception if decay can't happen
     if ( minmass > mIn ) {
       throw Exception() << "Evolver.cc: Mass of decaying particle is "
 			<< "below constituent masses of decay products."
 			<< Exception::eventerror;
     }
   }
   // create random particle vector (only need to do once)
   vector<ShowerProgenitorPtr> tmp;
   unsigned int nColouredIncoming = 0;
   while(particlesToShower.size()>0){
     unsigned int xx=UseRandom::irnd(particlesToShower.size());
     tmp.push_back(particlesToShower[xx]);
     particlesToShower.erase(particlesToShower.begin()+xx);
   }
   particlesToShower=tmp;
   for(unsigned int ix=0;ix<particlesToShower.size();++ix) {
     if(!particlesToShower[ix]->progenitor()->isFinalState() &&
        particlesToShower[ix]->progenitor()->coloured()) ++nColouredIncoming;
   }
   bool switchRecon = hard && nColouredIncoming !=1;
   // main shower loop
   unsigned int ntry(0);
   bool reconstructed = false;
   do {
     // clear results of last attempt if needed
     if(ntry!=0) {
       currentTree()->clear();
       setEvolutionPartners(hard,interaction_,true);
       _nis = _nfs = 0;
       // if MC@NLO H event and limited emissions
       // indicate both final and initial state emission
       if ( currentTree()->isMCatNLOHEvent() && _limitEmissions != 0 ) {
 	_nis = _nfs = 1;
       }
       for(unsigned int ix=0; ix<particlesToShower.size();++ix) {
 	SpinPtr spin = particlesToShower[ix]->progenitor()->spinInfo();
 	if(spin && spin->decayVertex() &&
 	   dynamic_ptr_cast<tcSVertexPtr>(spin->decayVertex())) {
 	  spin->decayVertex(VertexPtr());
 	}
       }
     }
     // loop over particles
     for(unsigned int ix=0;ix<particlesToShower.size();++ix) {
       // extract the progenitor
       progenitor(particlesToShower[ix]);
       // final-state radiation
       if(progenitor()->progenitor()->isFinalState()) {
 	if(!doFSR()) continue;
 	// perform shower
 	progenitor()->hasEmitted(startTimeLikeShower(interaction_));
       }
       // initial-state radiation
       else {
 	if(!doISR()) continue;
 	// hard process
 	if(hard) {
 	  // get the PDF
 	  setBeamParticle(_progenitor->beam());
 	  assert(beamParticle());
 	  // perform the shower
 	  // set the beam particle
 	  tPPtr beamparticle=progenitor()->original();
 	  if(!beamparticle->parents().empty()) 
 	    beamparticle=beamparticle->parents()[0];
 	  // generate the shower
 	  progenitor()->hasEmitted(startSpaceLikeShower(beamparticle,
 							interaction_));
 	}
 	// decay
 	else {
 	  // skip colour and electrically neutral particles
 	  if(!progenitor()->progenitor()->dataPtr()->coloured() &&
 	     !progenitor()->progenitor()->dataPtr()->charged()) {
 	    progenitor()->hasEmitted(false);
 	    continue;
 	  }
 	  // perform shower
 	  // set the scales correctly. The current scale is the maximum scale for
 	  // emission not the starting scale
 	  ShowerParticle::EvolutionScales maxScales(progenitor()->progenitor()->scales());
 	  progenitor()->progenitor()->scales() = ShowerParticle::EvolutionScales();
 	  if(progenitor()->progenitor()->dataPtr()->charged()) {
 	    progenitor()->progenitor()->scales().QED      = progenitor()->progenitor()->mass();
 	    progenitor()->progenitor()->scales().QED_noAO = progenitor()->progenitor()->mass();
 	  }
 	  if(progenitor()->progenitor()->hasColour()) {
 	    progenitor()->progenitor()->scales().QCD_c       = progenitor()->progenitor()->mass();
 	    progenitor()->progenitor()->scales().QCD_c_noAO  = progenitor()->progenitor()->mass();
 	  }
 	  if(progenitor()->progenitor()->hasAntiColour()) {
 	    progenitor()->progenitor()->scales().QCD_ac      = progenitor()->progenitor()->mass();
 	    progenitor()->progenitor()->scales().QCD_ac_noAO = progenitor()->progenitor()->mass();
 	  }
 	  // perform the shower
 	  progenitor()->hasEmitted(startSpaceLikeDecayShower(maxScales,minmass,
 							     interaction_));
 	}
       }
     }
     // do the kinematic reconstruction, checking if it worked
     reconstructed = hard ?
       showerModel()->kinematicsReconstructor()->
       reconstructHardJets (currentTree(),intrinsicpT(),interaction_,
 			   switchRecon && ntry>maximumTries()/2) :
       showerModel()->kinematicsReconstructor()->
       reconstructDecayJets(currentTree(),interaction_);
   }
   while(!reconstructed&&maximumTries()>++ntry);
   // check if failed to generate the shower
   if(ntry==maximumTries()) {
     if(hard)
       throw ShowerHandler::ShowerTriesVeto(ntry);
     else
       throw Exception() << "Failed to generate the shower after "
 			<< ntry << " attempts in QTildeShowerHandler::showerDecay()"
 			<< Exception::eventerror;
   }
   // tree has now showered
   _currenttree->hasShowered(true);
   hardTree(HardTreePtr());
 }
 
 void QTildeShowerHandler:: convertHardTree(bool hard,ShowerInteraction::Type type) {
   map<ColinePtr,ColinePtr> cmap;
   // incoming particles
   for(map<ShowerProgenitorPtr,ShowerParticlePtr>::const_iterator 
 	cit=currentTree()->incomingLines().begin();cit!=currentTree()->incomingLines().end();++cit) {
     map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
       mit = hardTree()->particles().find(cit->first->progenitor());
     // put the colour lines in the map
     ShowerParticlePtr oldParticle = cit->first->progenitor();
     ShowerParticlePtr newParticle = mit->second->branchingParticle();
     ColinePtr cLine = oldParticle->    colourLine();
     ColinePtr aLine = oldParticle->antiColourLine();
     if(newParticle->colourLine() &&
        cmap.find(newParticle->    colourLine())==cmap.end())
       cmap[newParticle->    colourLine()] = cLine;
     if(newParticle->antiColourLine() &&
        cmap.find(newParticle->antiColourLine())==cmap.end())
       cmap[newParticle->antiColourLine()] = aLine;
     // check whether or not particle emits
     bool emission = mit->second->parent();
     if(emission) {
       if(newParticle->colourLine()) {
 	ColinePtr ctemp = newParticle->    colourLine();
 	ctemp->removeColoured(newParticle);
       }
       if(newParticle->antiColourLine()) {
 	ColinePtr ctemp = newParticle->antiColourLine();
 	ctemp->removeAntiColoured(newParticle);
       }
       newParticle = mit->second->parent()->branchingParticle();
     }
     // get the new colour lines
     ColinePtr newCLine,newALine;
     // sort out colour lines
     if(newParticle->colourLine()) {
       ColinePtr ctemp = newParticle->    colourLine();
       ctemp->removeColoured(newParticle);
       if(cmap.find(ctemp)!=cmap.end()) {
 	newCLine = cmap[ctemp];
       }
       else {
 	newCLine = new_ptr(ColourLine());
 	cmap[ctemp] = newCLine;
       }
     }
     // and anticolour lines
     if(newParticle->antiColourLine()) {
       ColinePtr ctemp = newParticle->antiColourLine();
       ctemp->removeAntiColoured(newParticle);
       if(cmap.find(ctemp)!=cmap.end()) {
 	newALine = cmap[ctemp];
       }
       else {
 	newALine = new_ptr(ColourLine());
 	cmap[ctemp] = newALine;
       }
     }
     // remove colour lines from old particle
     if(aLine) {
       aLine->removeAntiColoured(cit->first->copy());
       aLine->removeAntiColoured(cit->first->progenitor());
     }
     if(cLine) {
       cLine->removeColoured(cit->first->copy());
       cLine->removeColoured(cit->first->progenitor());
     }
     // add particle to colour lines
     if(newCLine) newCLine->addColoured    (newParticle);
     if(newALine) newALine->addAntiColoured(newParticle);
     // insert new particles
     cit->first->copy(newParticle);
     ShowerParticlePtr sp(new_ptr(ShowerParticle(*newParticle,1,false)));
     cit->first->progenitor(sp);
     currentTree()->incomingLines()[cit->first]=sp;
     cit->first->perturbative(!emission);
     // and the emitted particle if needed
     if(emission) {
       ShowerParticlePtr newOut = mit->second->parent()->children()[1]->branchingParticle();
       if(newOut->colourLine()) {
 	ColinePtr ctemp = newOut->    colourLine();
 	ctemp->removeColoured(newOut);
 	assert(cmap.find(ctemp)!=cmap.end());
 	cmap[ctemp]->addColoured    (newOut);
       }
       if(newOut->antiColourLine()) {
 	ColinePtr ctemp = newOut->antiColourLine();
 	ctemp->removeAntiColoured(newOut);
 	assert(cmap.find(ctemp)!=cmap.end());
 	cmap[ctemp]->addAntiColoured(newOut);
       }
       ShowerParticlePtr sout=new_ptr(ShowerParticle(*newOut,1,true));
       ShowerProgenitorPtr out=new_ptr(ShowerProgenitor(cit->first->original(),newOut,sout));
       out->perturbative(false);
       currentTree()->outgoingLines().insert(make_pair(out,sout));
     }
     if(hard) {
       // sort out the value of x
       if(mit->second->beam()->momentum().z()>ZERO) {
 	sp->x(newParticle->momentum(). plus()/mit->second->beam()->momentum(). plus());
       }
       else {
 	sp->x(newParticle->momentum().minus()/mit->second->beam()->momentum().minus());
       }
     }
   }
   // outgoing particles
   for(map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator 
 	cit=currentTree()->outgoingLines().begin();cit!=currentTree()->outgoingLines().end();++cit) {
     map<tShowerTreePtr,pair<tShowerProgenitorPtr,
 			    tShowerParticlePtr> >::const_iterator tit;
     for(tit  = currentTree()->treelinks().begin();
 	tit != currentTree()->treelinks().end();++tit) {
       if(tit->second.first && tit->second.second==cit->first->progenitor())
 	break;
     }
     map<ShowerParticlePtr,tHardBranchingPtr>::const_iterator 
       mit = hardTree()->particles().find(cit->first->progenitor());
     if(mit==hardTree()->particles().end()) continue;
     // put the colour lines in the map
     ShowerParticlePtr oldParticle = cit->first->progenitor();
     ShowerParticlePtr newParticle = mit->second->branchingParticle();
     ShowerParticlePtr newOut;
     ColinePtr cLine = oldParticle->    colourLine();
     ColinePtr aLine = oldParticle->antiColourLine();
     if(newParticle->colourLine() &&
        cmap.find(newParticle->    colourLine())==cmap.end())
       cmap[newParticle->    colourLine()] = cLine;
     if(newParticle->antiColourLine() &&
        cmap.find(newParticle->antiColourLine())==cmap.end())
       cmap[newParticle->antiColourLine()] = aLine;
     // check whether or not particle emits
     bool emission = !mit->second->children().empty();
     if(emission) {
       if(newParticle->colourLine()) {
 	ColinePtr ctemp = newParticle->    colourLine();
 	ctemp->removeColoured(newParticle);
       }
       if(newParticle->antiColourLine()) {
 	ColinePtr ctemp = newParticle->antiColourLine();
 	ctemp->removeAntiColoured(newParticle);
       }
       newParticle = mit->second->children()[0]->branchingParticle();
       newOut      = mit->second->children()[1]->branchingParticle();
       if(newParticle->id()!=oldParticle->id()&&newParticle->id()==newOut->id())
 	swap(newParticle,newOut);
     }
     // get the new colour lines
     ColinePtr newCLine,newALine;
     // sort out colour lines
     if(newParticle->colourLine()) {
       ColinePtr ctemp = newParticle->    colourLine();
       ctemp->removeColoured(newParticle);
       if(cmap.find(ctemp)!=cmap.end()) {
 	newCLine = cmap[ctemp];
       }
       else {
 	newCLine = new_ptr(ColourLine());
 	cmap[ctemp] = newCLine;
       }
     }
     // and anticolour lines
     if(newParticle->antiColourLine()) {
       ColinePtr ctemp = newParticle->antiColourLine();
       ctemp->removeAntiColoured(newParticle);
       if(cmap.find(ctemp)!=cmap.end()) {
 	newALine = cmap[ctemp];
       }
       else {
 	newALine = new_ptr(ColourLine());
 	cmap[ctemp] = newALine;
       }
     }
     // remove colour lines from old particle
     if(aLine) {
       aLine->removeAntiColoured(cit->first->copy());
       aLine->removeAntiColoured(cit->first->progenitor());
     }
     if(cLine) {
       cLine->removeColoured(cit->first->copy());
       cLine->removeColoured(cit->first->progenitor());
     }
     // special for unstable particles
     if(newParticle->id()==oldParticle->id() &&
        (tit!=currentTree()->treelinks().end()||!oldParticle->dataPtr()->stable())) {
       Lorentz5Momentum oldMomentum = oldParticle->momentum();
       Lorentz5Momentum newMomentum = newParticle->momentum();
       LorentzRotation boost( oldMomentum.findBoostToCM(),oldMomentum.e()/oldMomentum.mass());
       if(tit!=currentTree()->treelinks().end()) tit->first->transform(boost,false);
       oldParticle->transform(boost);
       boost = LorentzRotation(-newMomentum.findBoostToCM(),newMomentum.e()/newMomentum.mass());
       oldParticle->transform(boost);
       if(tit!=currentTree()->treelinks().end()) tit->first->transform(boost,false);
       newParticle=oldParticle;
     }
     // add particle to colour lines
     if(newCLine) newCLine->addColoured    (newParticle);
     if(newALine) newALine->addAntiColoured(newParticle);
     // insert new particles
     cit->first->copy(newParticle);
     ShowerParticlePtr sp(new_ptr(ShowerParticle(*newParticle,1,true)));
     cit->first->progenitor(sp);
     currentTree()->outgoingLines()[cit->first]=sp;
     cit->first->perturbative(!emission);
     // and the emitted particle if needed
     if(emission) {
       if(newOut->colourLine()) {
 	ColinePtr ctemp = newOut->    colourLine();
 	ctemp->removeColoured(newOut);
 	assert(cmap.find(ctemp)!=cmap.end());
 	cmap[ctemp]->addColoured    (newOut);
       }
       if(newOut->antiColourLine()) {
 	ColinePtr ctemp = newOut->antiColourLine();
 	ctemp->removeAntiColoured(newOut);
 	assert(cmap.find(ctemp)!=cmap.end());
 	cmap[ctemp]->addAntiColoured(newOut);
       }
       ShowerParticlePtr sout=new_ptr(ShowerParticle(*newOut,1,true));
       ShowerProgenitorPtr out=new_ptr(ShowerProgenitor(cit->first->original(),newOut,sout));
       out->perturbative(false);
       currentTree()->outgoingLines().insert(make_pair(out,sout));
     }
     // update any decay products
     if(tit!=currentTree()->treelinks().end())
       currentTree()->updateLink(tit->first,make_pair(cit->first,sp));
   }
   // reset the tree
   currentTree()->resetShowerProducts();
   // reextract the particles and set the colour partners
   vector<ShowerParticlePtr> particles = 
     currentTree()->extractProgenitorParticles();
   // clear the partners
   for(unsigned int ix=0;ix<particles.size();++ix) {
     particles[ix]->partner(ShowerParticlePtr());
     particles[ix]->clearPartners();
   }
   // clear the tree
   hardTree(HardTreePtr());
   // Set the initial evolution scales
   showerModel()->partnerFinder()->
     setInitialEvolutionScales(particles,!hard,type,!_hardtree);
 }
 
 Branching QTildeShowerHandler::selectTimeLikeBranching(tShowerParticlePtr particle,
 						       ShowerInteraction::Type type,
 						       HardBranchingPtr branch) {
   Branching fb;
   unsigned int iout=0;
   while (true) {
     // break if doing truncated shower and no truncated shower needed
     if(branch && (!isTruncatedShowerON()||hardOnly())) break;
     fb=_splittingGenerator->chooseForwardBranching(*particle,_finalenhance,type);
     // no emission break
     if(!fb.kinematics) break;
     // special for truncated shower
     if(branch) {
       // check haven't evolved too far
       if(fb.kinematics->scale() < branch->scale()) {
 	fb=Branching();
 	break;
       }
       // find the truncated line
       iout=0;
       if(fb.ids[1]->id()!=fb.ids[2]->id()) {
 	if(fb.ids[1]->id()==particle->id())       iout=1;
 	else if (fb.ids[2]->id()==particle->id()) iout=2;
       }
       else if(fb.ids[1]->id()==particle->id()) {
 	if(fb.kinematics->z()>0.5) iout=1;
 	else                       iout=2;
       }
       // apply the vetos for the truncated shower
       // no flavour changing branchings
       if(iout==0) {
 	particle->vetoEmission(fb.type,fb.kinematics->scale());
 	continue;
       }
       double zsplit = iout==1 ? fb.kinematics->z() : 1-fb.kinematics->z();
       // only if same interaction for forced branching
       ShowerInteraction::Type type2 = convertInteraction(fb.type);
       // and evolution
       if(type2==branch->sudakov()->interactionType()) {
 	if(zsplit < 0.5 || // hardest line veto
 	   fb.kinematics->scale()*zsplit < branch->scale() ) { // angular ordering veto
 	  particle->vetoEmission(fb.type,fb.kinematics->scale());
 	  continue;
 	}
       }
       // pt veto
       if(fb.kinematics->pT() > progenitor()->maximumpT(type2)) {
 	particle->vetoEmission(fb.type,fb.kinematics->scale());
 	continue;
       }
     }
     // standard vetos for all emissions
     if(timeLikeVetoed(fb,particle)) {
       particle->vetoEmission(fb.type,fb.kinematics->scale());
       if(particle->spinInfo()) particle->spinInfo()->decayVertex(VertexPtr());
       continue;
     }
     // special for already decayed particles
     // don't allow flavour changing branchings
     bool vetoDecay = false;
     for(map<tShowerTreePtr,pair<tShowerProgenitorPtr,
 	  tShowerParticlePtr> >::const_iterator tit  = currentTree()->treelinks().begin();
 	tit != currentTree()->treelinks().end();++tit) {
       if(tit->second.first == progenitor()) {
 	map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator 
 	  it = currentTree()->outgoingLines().find(progenitor());
 	if(it!=currentTree()->outgoingLines().end() && particle == it->second &&
 	   fb.ids[0]!=fb.ids[1] && fb.ids[1]!=fb.ids[2]) {
 	  vetoDecay = true;
 	  break;
 	}
       }
     }
     if(vetoDecay) {
       particle->vetoEmission(fb.type,fb.kinematics->scale());
       if(particle->spinInfo()) particle->spinInfo()->decayVertex(VertexPtr());
       continue;
     }
     break;
   }
   // normal case
   if(!branch) {
     if(fb.kinematics) fb.hard = false;
     return fb;
   }
   // truncated emission
   if(fb.kinematics) {
     fb.hard = false;
     fb.iout = iout;
     return fb;
   }
   // otherwise need to return the hard emission
   // construct the kinematics for the hard emission
   ShoKinPtr showerKin=
     branch->sudakov()->createFinalStateBranching(branch->scale(),
 	                                         branch->children()[0]->z(),
 	                                         branch->phi(),
 						 branch->children()[0]->pT());
   IdList idlist(3);
   idlist[0] = particle->dataPtr();
   idlist[1] = branch->children()[0]->branchingParticle()->dataPtr();
   idlist[2] = branch->children()[1]->branchingParticle()->dataPtr();
   fb = Branching( showerKin, idlist, branch->sudakov(),branch->type() );
   fb.hard = true;
   fb.iout=0;
   // return it
   return fb;
 }
 
 Branching QTildeShowerHandler::selectSpaceLikeDecayBranching(tShowerParticlePtr particle,
 						 const ShowerParticle::EvolutionScales & maxScales,
 						 Energy minmass,ShowerInteraction::Type type,
 						 HardBranchingPtr branch) {
   Branching fb;
   unsigned int iout=0;
   while (true) {
     // break if doing truncated shower and no truncated shower needed
     if(branch && (!isTruncatedShowerON()||hardOnly())) break;
     // select branching
     fb=_splittingGenerator->chooseDecayBranching(*particle,maxScales,minmass,
 						 _initialenhance,type);
     // return if no radiation
     if(!fb.kinematics) break;
     // special for truncated shower
     if(branch) {
       // check haven't evolved too far
       if(fb.kinematics->scale() < branch->scale()) {
 	fb=Branching();
 	break;
       }
       // find the truncated line
       iout=0;
       if(fb.ids[1]->id()!=fb.ids[2]->id()) {
 	if(fb.ids[1]->id()==particle->id())       iout=1;
 	else if (fb.ids[2]->id()==particle->id()) iout=2;
       }
       else if(fb.ids[1]->id()==particle->id()) {
 	if(fb.kinematics->z()>0.5) iout=1;
 	else                       iout=2;
       }
       // apply the vetos for the truncated shower
       // no flavour changing branchings
       if(iout==0) {
 	particle->vetoEmission(fb.type,fb.kinematics->scale());
 	continue;
       }
       ShowerInteraction::Type type2 = convertInteraction(fb.type);
       double zsplit = iout==1 ? fb.kinematics->z() : 1-fb.kinematics->z();
       if(type2==branch->sudakov()->interactionType()) {
 	if(zsplit < 0.5 || // hardest line veto
 	   fb.kinematics->scale()*zsplit < branch->scale() ) { // angular ordering veto
 	  particle->vetoEmission(fb.type,fb.kinematics->scale());
 	  continue;
 	}
       }
       // pt veto
       if(fb.kinematics->pT() > progenitor()->maximumpT(type2)) {
 	particle->vetoEmission(fb.type,fb.kinematics->scale());
 	continue;
       }
     }
     // if not vetoed break
     if(spaceLikeDecayVetoed(fb,particle)) {
       // otherwise reset scale and continue
       particle->vetoEmission(fb.type,fb.kinematics->scale());
       continue;
     }
     break;
   }
   // normal case
   if(!branch) {
     if(fb.kinematics) fb.hard = false;
     return fb;
   }
   // truncated emission
   if(fb.kinematics) {
     fb.hard = false;
     fb.iout = iout;
     return fb;
   }
   // otherwise need to return the hard emission
   // construct the kinematics for the hard emission
   ShoKinPtr showerKin=
     branch->sudakov()->createDecayBranching(branch->scale(),
 					    branch->children()[0]->z(),
 					    branch->phi(),
 					    branch->children()[0]->pT());
    IdList idlist(3);
    idlist[0] = particle->dataPtr();
    idlist[1] = branch->children()[0]->branchingParticle()->dataPtr();
    idlist[2] = branch->children()[1]->branchingParticle()->dataPtr();
    // create the branching
    fb = Branching( showerKin, idlist, branch->sudakov(),ShowerPartnerType::QCDColourLine  );
    fb.hard=true;
    fb.iout=0;
    // return it
   return fb;
 }
 
 void QTildeShowerHandler::checkFlags() {
   string error = "Inconsistent hard emission set-up in QTildeShowerHandler::showerHardProcess(). "; 
   if ( ( currentTree()->isMCatNLOSEvent() || currentTree()->isMCatNLOHEvent() ) ) {
     if (_hardEmission ==2 )
       throw Exception() << error
 			<< "Cannot generate POWHEG matching with MC@NLO shower "
 			<< "approximation.  Add 'set Evolver:HardEmission 0' to input file."
 			<< Exception::runerror;
     if ( canHandleMatchboxTrunc() )
       throw Exception() << error
 			<< "Cannot use truncated qtilde shower with MC@NLO shower "
 			<< "approximation.  Set LHCGenerator:EventHandler"
 			<< ":CascadeHandler to '/Herwig/Shower/ShowerHandler' or "
 			<< "'/Herwig/Shower/Dipole/DipoleShowerHandler'."
 			<< Exception::runerror;
   }
   else if ( ((currentTree()->isPowhegSEvent() || currentTree()->isPowhegHEvent()) ) &&
 	    _hardEmission != 2){
     if ( canHandleMatchboxTrunc())
       throw Exception() << error
 			<< "Unmatched events requested for POWHEG shower "
 			<< "approximation.  Set Evolver:HardEmission to "
 			<< "'POWHEG'."
 			<< Exception::runerror;
     else if (_hardEmissionWarn) {
       _hardEmissionWarn = false;
       _hardEmission=2;
       throw Exception() << error
 			<< "Unmatched events requested for POWHEG shower "
 			<< "approximation. Changing Evolver:HardEmission from "
 			<< _hardEmission << " to 2"
 			<< Exception::warning;
     }
   }
 
   if ( currentTree()->isPowhegSEvent() || currentTree()->isPowhegHEvent()) {
     if (currentTree()->showerApproximation()->needsTruncatedShower() &&
 	!canHandleMatchboxTrunc() )
       throw Exception() << error
 			<< "Current shower handler cannot generate truncated shower.  "
 			<< "Set Generator:EventHandler:CascadeHandler to "
 			<< "'/Herwig/Shower/PowhegShowerHandler'."
 			<< Exception::runerror;
   }
   else if ( currentTree()->truncatedShower() && _missingTruncWarn) {
     _missingTruncWarn=false;
     throw Exception() << "Warning: POWHEG shower approximation used without "
 		      << "truncated shower.  Set Generator:EventHandler:"
 		      << "CascadeHandler to '/Herwig/Shower/PowhegShowerHandler' and "
 		      << "'MEMatching:TruncatedShower Yes'."
 		      << Exception::warning;   
   }
   // else if ( !dipme && _hardEmissionMode > 1 && 
   // 	    firstInteraction())
   //   throw Exception() << error
   // 		      << "POWHEG matching requested for LO events.  Include "
   // 		      << "'set Factory:ShowerApproximation MEMatching' in input file."
   // 		      << Exception::runerror;
 }
 
 
 tPPair QTildeShowerHandler::remakeRemnant(tPPair oldp){
   // get the parton extractor
   PartonExtractor & pex = *lastExtractor();
   // get the new partons
   tPPair newp = make_pair(findFirstParton(oldp.first ), 
 			  findFirstParton(oldp.second));
   // if the same do nothing
   if(newp == oldp) return oldp;
   // Creates the new remnants and returns the new PartonBinInstances
   // ATTENTION Broken here for very strange configuration
   PBIPair newbins = pex.newRemnants(oldp, newp, newStep());
   newStep()->addIntermediate(newp.first);
   newStep()->addIntermediate(newp.second);
   // return the new partons
   return newp;
 }
 
 PPtr QTildeShowerHandler::findFirstParton(tPPtr seed) const{
   if(seed->parents().empty()) return seed;
   tPPtr parent = seed->parents()[0];
   //if no parent there this is a loose end which will 
   //be connected to the remnant soon.
   if(!parent || parent == incomingBeams().first || 
      parent == incomingBeams().second ) return seed;
   else return findFirstParton(parent);
 }
 
 void QTildeShowerHandler::decay(ShowerTreePtr tree, ShowerDecayMap & decay) {
   // must be one incoming particle
   assert(tree->incomingLines().size()==1);
   // apply any transforms
   tree->applyTransforms();
   // if already decayed return
   if(!tree->outgoingLines().empty()) return;
   // now we need to replace the particle with a new copy after the shower
   // find particle after the shower
   map<tShowerTreePtr,pair<tShowerProgenitorPtr,tShowerParticlePtr> >::const_iterator
     tit = tree->parent()->treelinks().find(tree);
   assert(tit!=tree->parent()->treelinks().end());
   ShowerParticlePtr newparent=tit->second.second;
   PerturbativeProcessPtr newProcess =  new_ptr(PerturbativeProcess());
   newProcess->incoming().push_back(make_pair(newparent,PerturbativeProcessPtr()));
   DecayProcessMap decayMap;
   ShowerHandler::decay(newProcess,decayMap);
   ShowerTree::constructTrees(tree,decay,newProcess,decayMap);
 }
 
 namespace {
 
   ShowerProgenitorPtr
   findFinalStateLine(ShowerTreePtr tree, long id, Lorentz5Momentum momentum) { 
     map<ShowerProgenitorPtr,tShowerParticlePtr>::iterator partner;
     Energy2 dmin(1e30*GeV2);
     for(map<ShowerProgenitorPtr,tShowerParticlePtr>::iterator 
 	  cit =tree->outgoingLines().begin(); cit!=tree->outgoingLines().end(); ++cit) {
       if(cit->second->id()!=id) continue;
       Energy2 test = 
 	sqr(cit->second->momentum().x()-momentum.x())+
 	sqr(cit->second->momentum().y()-momentum.y())+
 	sqr(cit->second->momentum().z()-momentum.z())+
 	sqr(cit->second->momentum().t()-momentum.t());
       if(test<dmin) {
 	dmin    = test;
 	partner = cit;
       }
     }
     return partner->first;
   }
 
   ShowerProgenitorPtr 
   findInitialStateLine(ShowerTreePtr tree, long id, Lorentz5Momentum momentum) { 
     map<ShowerProgenitorPtr,ShowerParticlePtr>::iterator partner;
     Energy2 dmin(1e30*GeV2);
     for(map<ShowerProgenitorPtr,ShowerParticlePtr>::iterator 
 	  cit =tree->incomingLines().begin(); cit!=tree->incomingLines().end(); ++cit) {
       if(cit->second->id()!=id) continue;
       Energy2 test = 
 	sqr(cit->second->momentum().x()-momentum.x())+
 	sqr(cit->second->momentum().y()-momentum.y())+
 	sqr(cit->second->momentum().z()-momentum.z())+
 	sqr(cit->second->momentum().t()-momentum.t());
       if(test<dmin) {
 	dmin    = test;
 	partner = cit;
       }
     }
     return partner->first;
   }
 
   void fixSpectatorColours(PPtr newSpect,ShowerProgenitorPtr oldSpect,
 			   ColinePair & cline,ColinePair & aline, bool reconnect) {
     cline.first  = oldSpect->progenitor()->colourLine();
     cline.second = newSpect->colourLine();
     aline.first  = oldSpect->progenitor()->antiColourLine();
     aline.second = newSpect->antiColourLine();
     if(!reconnect) return;
     if(cline.first) {
       cline.first ->removeColoured(oldSpect->copy());
       cline.first ->removeColoured(oldSpect->progenitor());
       cline.second->removeColoured(newSpect);
       cline.first ->addColoured(newSpect);
     }
     if(aline.first) {
       aline.first ->removeAntiColoured(oldSpect->copy());
       aline.first ->removeAntiColoured(oldSpect->progenitor());
       aline.second->removeAntiColoured(newSpect);
       aline.first ->addAntiColoured(newSpect);
     }
   }
 
   void fixInitialStateEmitter(ShowerTreePtr tree, PPtr newEmit,PPtr emitted, ShowerProgenitorPtr emitter,
 			      ColinePair cline,ColinePair aline,double x) {
     // sort out the colours
     if(emitted->dataPtr()->iColour()==PDT::Colour8) {
       // emitter
       if(cline.first && cline.first == emitter->progenitor()->antiColourLine() &&
 	 cline.second !=newEmit->antiColourLine()) {
 	// sort out not radiating line
 	ColinePtr col = emitter->progenitor()->colourLine();
 	if(col) {
 	  col->removeColoured(emitter->copy());
 	  col->removeColoured(emitter->progenitor());
 	  newEmit->colourLine()->removeColoured(newEmit);
 	  col->addColoured(newEmit);
 	}
       }
       else if(aline.first && aline.first == emitter->progenitor()->colourLine() &&
 	      aline.second !=newEmit->colourLine()) {
 	// sort out not radiating line
 	ColinePtr anti = emitter->progenitor()->antiColourLine();
 	if(anti) {
 	  anti->removeAntiColoured(emitter->copy());
 	  anti->removeAntiColoured(emitter->progenitor());
 	  newEmit->colourLine()->removeAntiColoured(newEmit);
 	  anti->addAntiColoured(newEmit);
 	}
       }
       else
 	assert(false);
       // emitted
       if(cline.first && cline.second==emitted->colourLine()) {
 	cline.second->removeColoured(emitted);
 	cline.first->addColoured(emitted);
       }
       else if(aline.first && aline.second==emitted->antiColourLine()) {
 	aline.second->removeAntiColoured(emitted);
 	aline.first->addAntiColoured(emitted);
       }
       else
 	assert(false);
     }
     else {
       if(emitter->progenitor()->antiColourLine() ) {
 	ColinePtr col = emitter->progenitor()->antiColourLine();
 	col->removeAntiColoured(emitter->copy());
 	col->removeAntiColoured(emitter->progenitor());
  	if(newEmit->antiColourLine()) {
 	  newEmit->antiColourLine()->removeAntiColoured(newEmit);
 	  col->addAntiColoured(newEmit);
 	}
 	else if (emitted->colourLine()) {
 	  emitted->colourLine()->removeColoured(emitted);
 	  col->addColoured(emitted);
 	}
 	else
 	  assert(false);
       }
       if(emitter->progenitor()->colourLine() ) {
 	ColinePtr col = emitter->progenitor()->colourLine();
 	col->removeColoured(emitter->copy());
 	col->removeColoured(emitter->progenitor());
  	if(newEmit->colourLine()) {
 	  newEmit->colourLine()->removeColoured(newEmit);
 	  col->addColoured(newEmit);
 	}
 	else if (emitted->antiColourLine()) {
 	  emitted->antiColourLine()->removeAntiColoured(emitted);
 	  col->addAntiColoured(emitted);
 	}
 	else
 	  assert(false);
       }
     }
     // update the emitter
     emitter->copy(newEmit);
     ShowerParticlePtr sp = new_ptr(ShowerParticle(*newEmit,1,false));
     sp->x(x);
     emitter->progenitor(sp);
     tree->incomingLines()[emitter]=sp;
     emitter->perturbative(false);
     // add emitted
     sp=new_ptr(ShowerParticle(*emitted,1,true));
     ShowerProgenitorPtr gluon=new_ptr(ShowerProgenitor(emitter->original(),emitted,sp));
     gluon->perturbative(false);
     tree->outgoingLines().insert(make_pair(gluon,sp));
   }
 
   void fixFinalStateEmitter(ShowerTreePtr tree, PPtr newEmit,PPtr emitted, ShowerProgenitorPtr emitter,
 			    ColinePair cline,ColinePair aline) {
     map<tShowerTreePtr,pair<tShowerProgenitorPtr,tShowerParticlePtr> >::const_iterator tit;
     // special case if decayed
     for(tit  = tree->treelinks().begin(); tit != tree->treelinks().end();++tit) {
       if(tit->second.first && tit->second.second==emitter->progenitor())
 	break;
     }
     // sort out the colour lines
     if(cline.first && cline.first == emitter->progenitor()->antiColourLine() &&
        cline.second !=newEmit->antiColourLine()) {
       // sort out not radiating line
       ColinePtr col = emitter->progenitor()->colourLine();
       if(col) {
 	col->removeColoured(emitter->copy());
 	col->removeColoured(emitter->progenitor());
 	newEmit->colourLine()->removeColoured(newEmit);
 	col->addColoured(newEmit);
       }
     }
     else if(aline.first && aline.first == emitter->progenitor()->colourLine() &&
 	    aline.second !=newEmit->colourLine()) {
       // sort out not radiating line
       ColinePtr anti = emitter->progenitor()->antiColourLine();
       if(anti) {
 	anti->removeAntiColoured(emitter->copy());
 	anti->removeAntiColoured(emitter->progenitor());
 	newEmit->colourLine()->removeAntiColoured(newEmit);
 	anti->addAntiColoured(newEmit);
       }
     }
     else
       assert(false);
     // update the emitter
     emitter->copy(newEmit);
     ShowerParticlePtr sp = new_ptr(ShowerParticle(*newEmit,1,true));
     emitter->progenitor(sp);
     tree->outgoingLines()[emitter]=sp;
     emitter->perturbative(false);
     // update for decaying particles
     if(tit!=tree->treelinks().end())
       tree->updateLink(tit->first,make_pair(emitter,sp));
     // add the emitted particle
     // sort out the colour
     if(cline.first && cline.second==emitted->antiColourLine()) {
       cline.second->removeAntiColoured(emitted);
       cline.first->addAntiColoured(emitted);
     }
     else if(aline.first && aline.second==emitted->colourLine()) {
       aline.second->removeColoured(emitted);
       aline.first->addColoured(emitted);
     }
     else
       assert(false);
     sp=new_ptr(ShowerParticle(*emitted,1,true));
     ShowerProgenitorPtr gluon=new_ptr(ShowerProgenitor(emitter->original(),
 						       emitted,sp));
     gluon->perturbative(false);
     tree->outgoingLines().insert(make_pair(gluon,sp));
   }
   
 }
 
 void QTildeShowerHandler::setupMECorrection(RealEmissionProcessPtr real) {
   assert(real);
   currentTree()->hardMatrixElementCorrection(true);
   // II emission
   if(real->emitter()   < real->incoming().size() &&
      real->spectator() < real->incoming().size()) {
     // recoiling system
     for( map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator 
 	   cjt= currentTree()->outgoingLines().begin();
 	 cjt != currentTree()->outgoingLines().end();++cjt ) {
       cjt->first->progenitor()->transform(real->transformation());
       cjt->first->copy()->transform(real->transformation());
     }
     // the the radiating system
     ShowerProgenitorPtr emitter,spectator;
     unsigned int iemit  = real->emitter();
     unsigned int ispect = real->spectator();
     int ig = int(real->emitted())-int(real->incoming().size());
     emitter = findInitialStateLine(currentTree(),
 				   real->bornIncoming()[iemit]->id(),
 				   real->bornIncoming()[iemit]->momentum());
     spectator = findInitialStateLine(currentTree(),
 				     real->bornIncoming()[ispect]->id(),
 				     real->bornIncoming()[ispect]->momentum());
     // sort out the colours
     ColinePair cline,aline;
     fixSpectatorColours(real->incoming()[ispect],spectator,cline,aline,true);
     // update the spectator
     spectator->copy(real->incoming()[ispect]);
     ShowerParticlePtr sp(new_ptr(ShowerParticle(*real->incoming()[ispect],1,false)));
     sp->x(ispect ==0 ? real->x().first :real->x().second);
     spectator->progenitor(sp);
     currentTree()->incomingLines()[spectator]=sp;
     spectator->perturbative(true);
     // now for the emitter
     fixInitialStateEmitter(currentTree(),real->incoming()[iemit],real->outgoing()[ig],
 			   emitter,cline,aline,iemit ==0 ? real->x().first :real->x().second);
   }
   // FF emission
   else if(real->emitter()   >= real->incoming().size() &&
 	  real->spectator() >= real->incoming().size()) {
     assert(real->outgoing()[real->emitted()-real->incoming().size()]->id()==ParticleID::g);
     // find the emitter and spectator in the shower tree
     ShowerProgenitorPtr emitter,spectator;
     int iemit = int(real->emitter())-int(real->incoming().size());
     emitter = findFinalStateLine(currentTree(),
 				 real->bornOutgoing()[iemit]->id(),
 				 real->bornOutgoing()[iemit]->momentum());
     int ispect = int(real->spectator())-int(real->incoming().size());
     spectator = findFinalStateLine(currentTree(),
 				   real->bornOutgoing()[ispect]->id(),
 				   real->bornOutgoing()[ispect]->momentum());
     map<tShowerTreePtr,pair<tShowerProgenitorPtr,tShowerParticlePtr> >::const_iterator tit;
     // first the spectator
     // special case if decayed
     for(tit  = currentTree()->treelinks().begin(); tit != currentTree()->treelinks().end();++tit) {
       if(tit->second.first && tit->second.second==spectator->progenitor())
     	break;
     }
     // sort out the colours
     ColinePair cline,aline;
     fixSpectatorColours(real->outgoing()[ispect],spectator,cline,aline,true);
     // update the spectator
     spectator->copy(real->outgoing()[ispect]);
     ShowerParticlePtr sp(new_ptr(ShowerParticle(*real->outgoing()[ispect],1,true)));
     spectator->progenitor(sp);
     currentTree()->outgoingLines()[spectator]=sp;
     spectator->perturbative(true);
     // update for decaying particles
     if(tit!=currentTree()->treelinks().end())
       currentTree()->updateLink(tit->first,make_pair(spectator,sp));
     // now the emitting particle
     int ig = int(real->emitted())-int(real->incoming().size());
     fixFinalStateEmitter(currentTree(),real->outgoing()[iemit],
 			 real->outgoing()[ig],
 			 emitter,cline,aline);
   }
   // IF emission
   else {
     // scattering process
     if(real->incoming().size()==2) {
       ShowerProgenitorPtr emitter,spectator;
       unsigned int iemit  = real->emitter();
       unsigned int ispect = real->spectator();
       int ig = int(real->emitted())-int(real->incoming().size());
       ColinePair cline,aline;
       // incoming spectator
       if(ispect<2) {
 	spectator = findInitialStateLine(currentTree(),
 					 real->bornIncoming()[ispect]->id(),
 					 real->bornIncoming()[ispect]->momentum());
 	fixSpectatorColours(real->incoming()[ispect],spectator,cline,aline,true);
 	// update the spectator
 	spectator->copy(real->incoming()[ispect]);
 	ShowerParticlePtr sp(new_ptr(ShowerParticle(*real->incoming()[ispect],1,false)));
 	sp->x(ispect ==0 ? real->x().first :real->x().second);
 	spectator->progenitor(sp);
 	currentTree()->incomingLines()[spectator]=sp;
 	spectator->perturbative(true);
       }
       // outgoing spectator
       else {
 	spectator = findFinalStateLine(currentTree(),
 				       real->bornOutgoing()[ispect-real->incoming().size()]->id(),
 				       real->bornOutgoing()[ispect-real->incoming().size()]->momentum());
 	// special case if decayed
 	map<tShowerTreePtr,pair<tShowerProgenitorPtr,tShowerParticlePtr> >::const_iterator tit;
 	for(tit  = currentTree()->treelinks().begin(); tit != currentTree()->treelinks().end();++tit) {
 	  if(tit->second.first && tit->second.second==spectator->progenitor())
 	    break;
 	}
 	fixSpectatorColours(real->outgoing()[ispect-real->incoming().size()],spectator,cline,aline,true);
 	// update the spectator
 	spectator->copy(real->outgoing()[ispect-real->incoming().size()]);
 	ShowerParticlePtr sp(new_ptr(ShowerParticle(*real->outgoing()[ispect-real->incoming().size()],1,true)));
 	spectator->progenitor(sp);
 	currentTree()->outgoingLines()[spectator]=sp;
 	spectator->perturbative(true);
 	// update for decaying particles
 	if(tit!=currentTree()->treelinks().end())
 	  currentTree()->updateLink(tit->first,make_pair(spectator,sp));
       }
       // incoming emitter
       if(iemit<2) {
 	emitter = findInitialStateLine(currentTree(),
 				       real->bornIncoming()[iemit]->id(),
 				       real->bornIncoming()[iemit]->momentum());
 	fixInitialStateEmitter(currentTree(),real->incoming()[iemit],real->outgoing()[ig],
 			       emitter,aline,cline,iemit ==0 ? real->x().first :real->x().second);
       }
       // outgoing emitter
       else {
 	emitter = findFinalStateLine(currentTree(),
 				     real->bornOutgoing()[iemit-real->incoming().size()]->id(),
 				     real->bornOutgoing()[iemit-real->incoming().size()]->momentum());
 	fixFinalStateEmitter(currentTree(),real->outgoing()[iemit-real->incoming().size()],
 			     real->outgoing()[ig],emitter,aline,cline);
       }
     }
     // decay process
     else {
       assert(real->spectator()==0);
       unsigned int iemit  = real->emitter()-real->incoming().size();
       int ig = int(real->emitted())-int(real->incoming().size());
       ColinePair cline,aline;
       // incoming spectator
       ShowerProgenitorPtr spectator = findInitialStateLine(currentTree(),
 							   real->bornIncoming()[0]->id(),
 							   real->bornIncoming()[0]->momentum());
       fixSpectatorColours(real->incoming()[0],spectator,cline,aline,false);
       // find the emitter
       ShowerProgenitorPtr emitter = 
 	findFinalStateLine(currentTree(),
 			   real->bornOutgoing()[iemit]->id(),
 			   real->bornOutgoing()[iemit]->momentum());
       // recoiling system
       for( map<ShowerProgenitorPtr,tShowerParticlePtr>::const_iterator 
 	     cjt= currentTree()->outgoingLines().begin();
 	   cjt != currentTree()->outgoingLines().end();++cjt ) {
 	if(cjt->first==emitter) continue;
 	cjt->first->progenitor()->transform(real->transformation());
 	cjt->first->copy()->transform(real->transformation());
       }
       // sort out the emitter
       fixFinalStateEmitter(currentTree(),real->outgoing()[iemit],
 			   real->outgoing()[ig],emitter,aline,cline);
     }
   }
   // clean up the shower tree
   _currenttree->resetShowerProducts();
 }
diff --git a/Tests/Makefile.am b/Tests/Makefile.am
--- a/Tests/Makefile.am
+++ b/Tests/Makefile.am
@@ -1,365 +1,365 @@
 AUTOMAKE_OPTIONS = -Wno-portability
 AM_LDFLAGS += -module -avoid-version -rpath /dummy/path/not/used
 
 EXTRA_DIST = Inputs python Rivet 
 
 dist-hook:
 	rm -rf $(distdir)/Inputs/.svn
 	rm -rf $(distdir)/python/.svn
 	rm -rf $(distdir)/Rivet/.svn
 
 EXTRA_LTLIBRARIES = LeptonTest.la GammaTest.la HadronTest.la DISTest.la
 
 if WANT_LIBFASTJET
 EXTRA_LTLIBRARIES += HadronJetTest.la LeptonJetTest.la
 HadronJetTest_la_SOURCES = \
 Hadron/VHTest.h Hadron/VHTest.cc\
 Hadron/VTest.h Hadron/VTest.cc\
 Hadron/HTest.h Hadron/HTest.cc
 HadronJetTest_la_CPPFLAGS = $(AM_CPPFLAGS) $(FASTJETINCLUDE) \
 -I$(FASTJETPATH)
 HadronJetTest_la_LIBADD = $(FASTJETLIBS) 
 LeptonJetTest_la_SOURCES = \
 Lepton/TopDecay.h Lepton/TopDecay.cc
 LeptonJetTest_la_CPPFLAGS = $(AM_CPPFLAGS) $(FASTJETINCLUDE) \
 -I$(FASTJETPATH)
 LeptonJetTest_la_LIBADD = $(FASTJETLIBS) 
 endif
 
 LeptonTest_la_SOURCES = \
 Lepton/VVTest.h Lepton/VVTest.cc \
 Lepton/VBFTest.h Lepton/VBFTest.cc \
 Lepton/VHTest.h Lepton/VHTest.cc \
 Lepton/FermionTest.h Lepton/FermionTest.cc
 
 GammaTest_la_SOURCES = \
 Gamma/GammaMETest.h  Gamma/GammaMETest.cc \
 Gamma/GammaPMETest.h Gamma/GammaPMETest.cc
 
 DISTest_la_SOURCES = \
 DIS/DISTest.h  DIS/DISTest.cc
 
 HadronTest_la_SOURCES = \
 Hadron/HadronVVTest.h  Hadron/HadronVVTest.cc\
 Hadron/HadronVBFTest.h  Hadron/HadronVBFTest.cc\
 Hadron/WHTest.h  Hadron/WHTest.cc\
 Hadron/ZHTest.h  Hadron/ZHTest.cc\
 Hadron/VGammaTest.h  Hadron/VGammaTest.cc\
 Hadron/ZJetTest.h  Hadron/ZJetTest.cc\
 Hadron/WJetTest.h  Hadron/WJetTest.cc\
 Hadron/QQHTest.h  Hadron/QQHTest.cc
 
 
 REPO = $(top_builddir)/src/HerwigDefaults.rpo
 HERWIG = $(top_builddir)/src/Herwig
 HWREAD = $(HERWIG) read --repo $(REPO) -L $(builddir)/.libs -i $(top_builddir)/src
 HWRUN = $(HERWIG) run
 
 tests : tests-LEP tests-DIS tests-LHC tests-Gamma
 
 if WANT_LIBFASTJET
 tests-LEP : test-LEP-VV test-LEP-VH test-LEP-VBF test-LEP-BB test-LEP-Quarks test-LEP-Leptons \
             test-LEP-default test-LEP-Powheg test-LEP-TopDecay
 else
 tests-LEP : test-LEP-VV test-LEP-VH test-LEP-VBF test-LEP-BB test-LEP-Quarks test-LEP-Leptons
 endif
 
 tests-DIS : test-DIS-Charged test-DIS-Neutral
 
 if WANT_LIBFASTJET
 tests-LHC : test-LHC-WW test-LHC-WZ test-LHC-ZZ test-LHC-ZGamma test-LHC-WGamma \
 	    test-LHC-ZH test-LHC-WH test-LHC-ZJet test-LHC-WJet test-LHC-Z test-LHC-W test-LHC-ZZVBF test-LHC-VBF \
 	    test-LHC-WWVBF test-LHC-bbH test-LHC-ttH test-LHC-GammaGamma test-LHC-GammaJet test-LHC-Higgs \
 	    test-LHC-HiggsJet test-LHC-QCDFast test-LHC-QCD test-LHC-Top test-LHC-Bottom \
             test-LHC-WHJet test-LHC-ZHJet test-LHC-HJet test-LHC-ZShower test-LHC-WShower\
             test-LHC-WHJet-Powheg test-LHC-ZHJet-Powheg test-LHC-HJet-Powheg \
             test-LHC-ZShower-Powheg test-LHC-WShower-Powheg
 else
 tests-LHC : test-LHC-WW test-LHC-WZ test-LHC-ZZ test-LHC-ZGamma test-LHC-WGamma \
 	    test-LHC-ZH test-LHC-WH test-LHC-ZJet test-LHC-WJet test-LHC-Z test-LHC-W test-LHC-ZZVBF test-LHC-VBF \
 	    test-LHC-WWVBF test-LHC-bbH test-LHC-ttH test-LHC-GammaGamma test-LHC-GammaJet test-LHC-Higgs \
 	    test-LHC-HiggsJet test-LHC-QCDFast test-LHC-QCD test-LHC-Top
 endif
 
 tests-Gamma : test-Gamma-FF test-Gamma-WW test-Gamma-P
 
 if WANT_LIBFASTJET 
 test-LEP-% : Inputs/LEP-%.in LeptonTest.la LeptonJetTest.la
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 else
 test-LEP-% : Inputs/LEP-%.in LeptonTest.la
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 endif
 
 Rivet-LHC-Matchbox-% : Rivet/LHC-Matchbox-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet-TVT-Matchbox-% : Rivet/TVT-Matchbox-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet-TVT-Dipole-% : Rivet/TVT-Dipole-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet-LHC-Dipole-% : Rivet/LHC-Dipole-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet/LEP-%.in :
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/DIS-%.in : 
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/BFactory-%.in:
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/TVT-%.in:
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/LHC-%.in:
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/Star-%.in:
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/SppS-%.in:
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet/ISR-%.in:
 	python/make_input_files.py $(notdir $(subst .in,,$@))
 
 Rivet-LEP-Matchbox-% : Rivet/LEP-Matchbox-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet-LEP-Dipole-% : Rivet/LEP-Dipole-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet-BFactory-Matchbox-% : Rivet/BFactory-Matchbox-%.in
 	if [ ! -d Rivet-$(notdir $(subst .in,,$<))  ]; then mkdir Rivet-$(notdir $(subst .in,,$<)); fi;
 	cd Rivet-$(notdir $(subst .in,,$<)); echo `pwd`; \
 	../$(HERWIG) read --repo ../$(REPO) -L ../$(top_builddir)/lib -i ../$(top_builddir)/src ../$<; \
 	../$(HERWIG) run $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}; \
 	mv $(notdir $(subst .in,.yoda,$<)) ..; \
 	cd ..
 
 Rivet-LEP-% : Rivet/LEP-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-BFactory-% : Rivet/BFactory-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-TVT-% : Rivet/TVT-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-DIS-% : Rivet/DIS-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-LHC-% : Rivet/LHC-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-Star-% : Rivet/Star-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-SppS-% : Rivet/SppS-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-ISR-% : Rivet/ISR-%.in
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 Rivet-inputfiles: $(shell echo Rivet/LEP{,-Powheg,-Matchbox,-Dipole,-Matchbox-Powheg}-{10,22,35,44,91,130,133,136,161,172,177,183,189,192,196,197,200,202,206,91-nopi}.in) \
                   $(shell echo Rivet/LEP{,-Powheg,-Matchbox-Powheg}-14.in) \
                   $(shell echo Rivet/BFactory{,-Powheg,-Matchbox,-Dipole,-Matchbox-Powheg}-{10.52,10.52-sym,10.54,10.45}.in) \
                   $(shell echo Rivet/BFactory-{Upsilon,Upsilon2,Upsilon4,Tau,10.58-res}.in) \
                   $(shell echo Rivet/DIS{,-NoME,-Powheg,-Matchbox,-Dipole,-Matchbox-Powheg}-{e--LowQ2,e+-LowQ2,e+-HighQ2}.in) \
                   $(shell echo Rivet/TVT{,-Powheg,-Matchbox,-Dipole,-Matchbox-Powheg}-{Run-I-Z,Run-I-W,Run-I-WZ,Run-II-Z-e,Run-II-Z-{,LowMass-,HighMass-}mu,Run-II-W}.in) \
 	          $(shell echo Rivet/TVT-Run-II-{DiPhoton-GammaGamma,DiPhoton-GammaJet,PromptPhoton}.in) \
 	          $(shell echo Rivet/TVT-Powheg-Run-II-{DiPhoton-GammaGamma,DiPhoton-GammaJet}.in) \
                   $(shell echo Rivet/TVT{,-Dipole,-Matchbox,-Matchbox-Powheg}-{Run-II-Jets-{0..11},Run-I-Jets-{1..8}}.in ) \
 	          $(shell echo Rivet/TVT{,-Dipole,-Matchbox,-Matchbox-Powheg}-{630-Jets-{1..3},300-Jets-1,900-Jets-1}.in ) \
                   $(shell echo Rivet/TVT-{Run-I,Run-II,300,630,900}-UE.in) \
                   $(shell echo Rivet/LHC{,-Dipole,-Matchbox,-Matchbox-Powheg}-7-Jets-{0..15}.in ) \
 	          $(shell echo Rivet/LHC-{900,2360,2760,7,8,13}-UE.in ) \
 	          $(shell echo Rivet/LHC-{900,7}-UE-Long.in ) \
 		  $(shell echo Rivet/LHC{,-Dipole,-Matchbox,-Matchbox-Powheg}-7-Charm-{1..5}.in) \
 		  $(shell echo Rivet/LHC{,-Dipole,-Matchbox,-Matchbox-Powheg}-7-Bottom-{0..8}.in) \
 		  $(shell echo Rivet/LHC{,-Matchbox,-Matchbox-Powheg}-7-Top-{L,SL,All}.in) \
 		  $(shell echo Rivet/LHC{,-Matchbox,-Matchbox-Powheg}-8-Top-All.in) \
                   $(shell echo Rivet/Star-{UE,Jets-{1..4}}.in ) \
 	          $(shell echo Rivet/SppS-{200,500,900,546}-UE.in ) \
                   $(shell echo Rivet/LHC{,-Matchbox,-Matchbox-Powheg,-Powheg,-Dipole}-{W-{e,mu},13-Z-{e,mu},Z-{e,mu,mu-SOPHTY},Z-LowMass-{e,mu},Z-MedMass-e,WZ,WW-{emu,ll},ZZ-{ll,lv},W-Z-{e,mu},8-Z-mu}.in) \
                   $(shell echo Rivet/LHC-7-{W,Z}Gamma-{e,mu}.in) \
 	          $(shell echo Rivet/LHC{,-Matchbox,-Matchbox-Powheg,-Dipole}-{7-W-Jet-{1..3}-e,7-Z-Jet-{0..3}-e,7-Z-Jet-0-mu}.in) \
 	          $(shell echo Rivet/LHC{-Matchbox,-Matchbox-Powheg,-Dipole}-{Z-b,Z-bb,W-b,8-Z-jj}.in) \
                   $(shell echo Rivet/LHC-7-PromptPhoton-{1..4}.in) Rivet/LHC-GammaGamma-7.in \
 	          $(shell echo Rivet/LHC{,-Powheg}-7-{DiPhoton-GammaGamma,DiPhoton-GammaJet}.in) \
                   $(shell echo Rivet/LHC{,-Powheg,-Matchbox,-Matchbox-Powheg,-Dipole}-{ggH,VBF,WH,ZH}.in) \
                   $(shell echo Rivet/LHC{,-Powheg,-Matchbox,-Matchbox-Powheg,-Dipole}-8-{ggH,VBF,WH,ZH}{,-GammaGamma}.in) \
                   $(shell echo Rivet/LHC{,-Matchbox,-Matchbox-Powheg,-Dipole}-ggHJet.in)
 #                  $(shell echo Rivet/ISR-{30,44,53,62}-UE.in ) $(shell echo Rivet/SppS-{53,63}-UE.in )
 
 Rivet-LEP: $(shell echo Rivet-LEP{,-Powheg,-Matchbox,-Dipole}-{10,14,22,35,44,91,130,133,136,161,172,177,183,189,192,196,197,200,202,206,91-nopi})
 	rm -rf Rivet-LEP
 	python/merge-LEP LEP
 	python/merge-LEP LEP-Powheg
 	python/merge-LEP LEP-Matchbox
 	python/merge-LEP LEP-Dipole
 	rivet-mkhtml -o Rivet-LEP LEP.yoda:Hw++ LEP-Powheg.yoda:Hw++-Powheg LEP-Matchbox.yoda:Hw++-Matchbox LEP-Dipole.yoda:Hw++-Dipole
 
 Rivet-BFactory: $(shell echo Rivet-BFactory{,-Powheg,-Matchbox,-Dipole}-{10.52,10.52-sym,10.54,10.45}) \
                 $(shell echo Rivet-BFactory-{Upsilon,Upsilon2,Upsilon4,Tau,10.58-res,10.58})
 	rm -rf Rivet-BFactory
 	python/merge-BFactory BFactory
 	python/merge-BFactory BFactory-Powheg
 	python/merge-BFactory BFactory-Matchbox
 	python/merge-BFactory BFactory-Dipole
 	rivet-mkhtml -o Rivet-BFactory BFactory.yoda:Hw++ BFactory-Powheg.yoda:Hw++-Powheg BFactory-Matchbox.yoda:Hw++-Matchbox BFactory-Dipole.yoda:Hw++-Dipole
 
 Rivet-DIS: $(shell echo Rivet-DIS{,-NoME,-Powheg,-Matchbox,-Dipole}-{e--LowQ2,e+-LowQ2,e+-HighQ2})
 	rm -rf Rivet-DIS
 	python/merge-DIS DIS 
 	python/merge-DIS DIS-Powheg
 	python/merge-DIS DIS-NoME
 	python/merge-DIS DIS-Matchbox
 	python/merge-DIS DIS-Dipole
 	rivet-mkhtml -o Rivet-DIS DIS.yoda:Hw++ DIS-Powheg.yoda:Hw++-Powheg DIS-NoME.yoda:Hw++-NoME DIS-Matchbox.yoda:Hw++-Matchbox DIS-Dipole.yoda:Hw++-Dipole
 
 Rivet-TVT-WZ:  $(shell echo Rivet-TVT{,-Powheg,-Matchbox,-Dipole}-{Run-I-Z,Run-I-W,Run-I-WZ,Run-II-Z-{e,{,LowMass-,HighMass-}mu},Run-II-W})
 	rm -rf Rivet-TVT-WZ
 	python/merge-TVT-EW TVT-Run-II-W.yoda TVT-Run-II-Z-{e,{,LowMass-,HighMass-}mu}.yoda\
                             TVT-Run-I-{W,Z,WZ}.yoda -o TVT-WZ.yoda
 	python/merge-TVT-EW TVT-Powheg-Run-II-W.yoda   TVT-Powheg-Run-II-Z-{e,{,LowMass-,HighMass-}mu}.yoda\
                             TVT-Powheg-Run-I-{W,Z,WZ}.yoda -o TVT-Powheg-WZ.yoda
 	python/merge-TVT-EW TVT-Matchbox-Run-II-W.yoda   TVT-Matchbox-Run-II-Z-{e,{,LowMass-,HighMass-}mu}.yoda\
                             TVT-Matchbox-Run-I-{W,Z,WZ}.yoda -o TVT-Matchbox-WZ.yoda
 	python/merge-TVT-EW TVT-Dipole-Run-II-W.yoda   TVT-Dipole-Run-II-Z-{e,{,LowMass-,HighMass-}mu}.yoda\
                             TVT-Dipole-Run-I-{W,Z,WZ}.yoda -o TVT-Dipole-WZ.yoda
 	rivet-mkhtml -o Rivet-TVT-WZ TVT-WZ.yoda:Hw++ TVT-Powheg-WZ.yoda:Hw++-Powheg TVT-Matchbox-WZ.yoda:Hw++-Matchbox TVT-Dipole-WZ.yoda:Hw++-Dipole
 
 Rivet-TVT-Photon: $(shell echo Rivet-TVT-Run-II-{DiPhoton-GammaGamma,DiPhoton-GammaJet,PromptPhoton}) \
                   $(shell echo Rivet-TVT-Powheg-Run-II-{DiPhoton-GammaGamma,DiPhoton-GammaJet})
 	rm -rf Rivet-TVT-Photon
 	python/merge-TVT-Photon TVT -o TVT-Photon.yoda
 	python/merge-TVT-Photon TVT-Powheg -o TVT-Powheg-Photon.yoda
 	rivet-mkhtml -o Rivet-TVT-Photon TVT-Photon.yoda:Hw TVT-Powheg-Photon.yoda:Hw-Powheg
 
 Rivet-TVT-Jets:  $(shell echo Rivet-TVT-{Run-II-Jets-{0..11},Run-I-Jets-{1..8}} ) \
 	         $(shell echo Rivet-TVT-{630-Jets-{1..3},300-Jets-1,900-Jets-1} ) \
                  $(shell echo Rivet-TVT-{Run-I,Run-II,300,630,900}-UE)
 	python/merge-TVT-Energy TVT
 	rivet-merge-CDF_2012_NOTE10874 TVT-300-Energy.yoda TVT-900-Energy.yoda TVT-1960-Energy.yoda
 	flat2yoda RatioPlots.dat -o TVT-RatioPlots.yoda
 	rm -rf Rivet-TVT-Jets
 	python/merge-TVT-Jets TVT
 	rivet-mkhtml -o Rivet-TVT-Jets TVT-Jets.yoda:Hw++
 
 Rivet-LHC-Jets: $(shell echo Rivet-LHC-7-Jets-{0..15} ) \
 	        $(shell echo Rivet-LHC-{900,2360,2760,7,8,13}-UE ) \
 	        $(shell echo Rivet-LHC-{900,7}-UE-Long ) \
 		$(shell echo Rivet-LHC-7-Charm-{1..5}) \
 		$(shell echo Rivet-LHC-7-Bottom-{0..8}) \
 		$(shell echo Rivet-LHC-7-Top-{L,SL,All})\
 		$(shell echo Rivet-LHC-8-Top-All)
 	rm -rf Rivet-LHC-Jets
-	python/merge-LHC-Jets
+	python/merge-LHC-Jets LHC
 	rivet-mkhtml -o Rivet-LHC-Jets LHC-Jets.yoda:Hw++
 
 Rivet-Star: $(shell echo Rivet-Star-{UE,Jets-{1..4}} ) 
 	rm -rf Rivet-Star
 	python/merge-Star Star
 	rivet-mkhtml -o Rivet-Star Star.yoda
 
 Rivet-SppS: $(shell echo Rivet-ISR-{30,44,53,62}-UE ) \
 	    $(shell echo Rivet-SppS-{53,63,200,500,900,546}-UE )
 	rm -rf Rivet-SppS
 	python/merge-SppS SppS
 	rivet-mkhtml -o Rivet-SppS SppS.yoda
 
 Rivet-LHC-EW: $(shell echo Rivet-LHC{,-Matchbox,-Powheg,-Dipole}-{13-Z-{e,mu},W-{e,mu},Z-{e,mu,mu-SOPHTY},Z-LowMass-{e,mu},Z-MedMass-e,WZ,WW-{emu,ll},ZZ-{ll,lv},W-Z-{e,mu},8-Z-mu}) \
 	      $(shell echo Rivet-LHC{,-Matchbox,-Dipole}-{7-W-Jet-{1..3}-e,7-Z-Jet-{0..3}-e,7-Z-Jet-0-mu}) \
 	      $(shell echo Rivet-LHC{-Matchbox,-Dipole}-{Z-b,Z-bb,W-b,8-Z-jj}) \
               $(shell echo Rivet-LHC-7-{W,Z}Gamma-{e,mu}) \
 	rm -rf Rivet-LHC-EW;
-	python/merge-LHC-EW LHC-{13-Z-{e,mu},W-{e,mu},Z-{e,mu},Z-LowMass-{e,mu},Z-MedMass-e,W-Z-{e,mu},WW-{emu,ll},WZ,ZZ-{ll,lv}}.yoda LHC-7-{W,Z}-Jet-{1,2,3}-e.yoda -o LHC-EW.yoda;
+	python/merge-LHC-EW LHC-{13-Z-{e,mu},W-{e,mu},Z-{e,mu},Z-LowMass-{e,mu},Z-MedMass-e,W-Z-{e,mu},WW-{emu,ll},WZ,ZZ-{ll,lv}}.yoda LHC-7-{W,Z}-Jet-{1,2,3}-e.yoda LHC-7-{W,Z}Gamma-{e,mu}.yoda -o LHC-EW.yoda;
 	python/merge-LHC-EW LHC-Matchbox-{13-Z-{e,mu},W-{e,mu},Z-{e,mu},Z-LowMass-{e,mu},Z-MedMass-e,W-Z-{e,mu},WW-{emu,ll},WZ,ZZ-{ll,lv}}.yoda LHC-Matchbox-7-{W,Z}-Jet-{1,2,3}-e.yoda -o LHC-Matchbox-EW.yoda;
 	python/merge-LHC-EW LHC-Dipole-{13-Z-{e,mu},W-{e,mu},Z-{e,mu},Z-LowMass-{e,mu},Z-MedMass-e,W-Z-{e,mu},WW-{emu,ll},WZ,ZZ-{ll,lv}}.yoda LHC-Dipole-7-{W,Z}-Jet-{1,2,3}-e.yoda -o LHC-Dipole-EW.yoda;
 	python/merge-LHC-EW LHC-Powheg-{W-{e,mu},Z-{e,mu},Z-LowMass-{e,mu},Z-MedMass-e,W-Z-{e,mu},WW-{emu,ll},WZ,ZZ-{ll,lv}}.yoda -o LHC-Powheg-EW.yoda;
 	rivet-mkhtml -o Rivet-LHC-EW LHC-EW.yoda:Hw++ LHC-Powheg-EW.yoda:Hw++-Powheg LHC-Matchbox-EW.yoda:Hw++-Matchbox LHC-Matchbox-Z-b.yoda:Hw++-Matchbox-Zb \
                                      LHC-Matchbox-Z-bb.yoda:Hw++-Matchbox-Zbb LHC-Matchbox-W-b.yoda:Hw++-Matchbox-W-bb LHC-Dipole-EW.yoda:Hw++-Dipole \
-                                     LHC-Dipole-Z-b.yoda:Hw++-Dipole-Zb LHC-Dipole-Z-bb.yoda:Hw++-Dipole-Zbb LHC-Dipole-W-b.yoda:Hw++-Dipole-W-bb;
-
+                                     LHC-Dipole-Z-b.yoda:Hw++-Dipole-Zb LHC-Dipole-Z-bb.yoda:Hw++-Dipole-Zbb LHC-Dipole-W-b.yoda:Hw++-Dipole-W-bb \
+                                     LHC-Z-mu-SOPHTY.yoda:Hw++ LHC-Powheg-Z-mu-SOPHTY.yoda:Hw++-Powheg LHC-Matchbox-Z-mu-SOPHTY.yoda:Hw++-Matchbox
 Rivet-LHC-Photon: $(shell echo Rivet-LHC-7-PromptPhoton-{1..4}) Rivet-LHC-GammaGamma-7 \
 	          $(shell echo Rivet-LHC{,-Powheg}-7-{DiPhoton-GammaGamma,DiPhoton-GammaJet})
 	rm -rf Rivet-LHC-Photon
 	python/merge-LHC-Photon LHC -o LHC-Photon.yoda
 	python/merge-LHC-Photon LHC-Powheg -o LHC-Powheg-Photon.yoda
 	rivet-mkhtml -o Rivet-LHC-Photon LHC-Photon.yoda:Hw LHC-Powheg-Photon.yoda:Hw-Powheg
 
 Rivet-LHC-Higgs:  $(shell echo Rivet-LHC{,-Powheg}-{ggH,VBF,WH,ZH})\
                   $(shell echo Rivet-LHC{,-Powheg}-8-{ggH,VBF,WH,ZH}{,-GammaGamma}) Rivet-LHC-ggHJet
 	rm -rf Rivet-LHC-Higgs
 	rivet-mkhtml -o Rivet-LHC-Higgs LHC-Powheg-ggH.yoda:gg-Powheg LHC-ggH.yoda:gg LHC-ggHJet.yoda:HJet \
                         LHC-Powheg-VBF.yoda:VBF-Powheg LHC-VBF.yoda:VBF LHC-WH.yoda:WH LHC-ZH.yoda:ZH \
                         LHC-Powheg-WH.yoda:WH-Powheg LHC-Powheg-ZH.yoda:ZH-Powheg
 
 tests-Rivet : Rivet-LEP Rivet-BFactory Rivet-DIS Rivet-TVT-WZ Rivet-TVT-Photon Rivet-TVT-Jets Rivet-LHC-Jets Rivet-Star Rivet-SppS Rivet-LHC-EW Rivet-LHC-Photon
 
 
 test-Gamma-% : Inputs/Gamma-%.in GammaTest.la
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 test-DIS-% : Inputs/DIS-%.in DISTest.la
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 
 if WANT_LIBFASTJET 
 test-LHC-% : Inputs/LHC-%.in HadronTest.la GammaTest.la HadronJetTest.la
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 else
 test-LHC-% : Inputs/LHC-%.in HadronTest.la GammaTest.la
 	$(HWREAD) $<
 	$(HWRUN) $(notdir $(subst .in,.run,$<)) -N $${NUMEVENTS:-10000}
 endif
 
 clean-local:
 	rm -f *.out *.log *.tex *.top *.run *.dump *.mult *.Bmult *.yoda
diff --git a/Tests/Rivet/LHC/LHC-W-e.in b/Tests/Rivet/LHC/LHC-W-e.in
--- a/Tests/Rivet/LHC/LHC-W-e.in
+++ b/Tests/Rivet/LHC/LHC-W-e.in
@@ -1,21 +1,21 @@
 ##################################################
 # select the analyses
 ##################################################
 # general analysis
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 MC_WJETS
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 MC_WPOL
 # ATLAS W+jets
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2010_S8919674
 # ATLAS W pT
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2011_I925932
 # ATLAS W kT scales
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1217867
 # W DPI
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1216670
 # W +b 
-insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1219109
+insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1219109_EL
 # ATLAS W
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2011_I928289_W
 # ATLAS W+jets
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2014_I1319490
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2014_I1319490_EL
\ No newline at end of file
diff --git a/Tests/Rivet/LHC/LHC-W-mu.in b/Tests/Rivet/LHC/LHC-W-mu.in
--- a/Tests/Rivet/LHC/LHC-W-mu.in
+++ b/Tests/Rivet/LHC/LHC-W-mu.in
@@ -1,25 +1,25 @@
 ##################################################
 # select the analyses
 ##################################################
 # ATLAS W asymetry
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2011_S9002537
 # ATLAS W+jets
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2010_S8919674
 # ATLAS W pT
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2011_I925932
 # ATLAS W+jets
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2012_I1083318
 # ATLAS W kT scales
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1217867
 # CMS double parton scattering
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 CMS_2013_I1272853
 # W DPI
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1216670
 # CMS W+ jets
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 CMS_2014_I1303894
 # ATLAS W
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2011_I928289_W
 # ATLAS W+jets
 insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2014_I1319490_MU
 # W +b 
-insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1219109
+insert /Herwig/Analysis/RivetAnalysis:Analyses 0 ATLAS_2013_I1219109_MU
diff --git a/Tests/python/make_input_files.py b/Tests/python/make_input_files.py
--- a/Tests/python/make_input_files.py
+++ b/Tests/python/make_input_files.py
@@ -1,1386 +1,1385 @@
 #! /usr/bin/env python
 import logging,sys,os
 from string import strip, Template
 
 import sys
 if sys.version_info[:3] < (2,4,0):
     print "rivet scripts require Python version >= 2.4.0... exiting"
     sys.exit(1)
 
 if __name__ == "__main__":
     import logging
     from optparse import OptionParser, OptionGroup
     parser = OptionParser(usage="%prog name [...]")
 
 (opts, args) = parser.parse_args()
 ## Check args
 if len(args) != 1:
     logging.error("Must specify at least input file")
     sys.exit(1)
 
 name=args[0]
 
 collider=""
 # select the template to load
 # collider
 parameters = {}
 if(name.find("BFactory")==0) :
     collider="BFactory"
 elif(name.find("LEP")==0) :
     collider="LEP"
 elif(name.find("DIS")==0) :
     collider="DIS"
 elif(name.find("TVT")==0) :
     collider="TVT"
 elif(name.find("LHC-GammaGamma")==0) :
     collider="LHC-GammaGamma"
 elif(name.find("LHC")==0) :
     collider="LHC"
 elif(name.find("ISR")==0) :
     collider="ISR"
 elif(name.find("SppS")==0) :
     collider="SppS"
 elif(name.find("Star")==0) :
     collider="Star"
 simulation=""
 istart = 1
 print name
 if(name.find("Matchbox-Powheg")>0) :
     istart = 3
     simulation="Matchbox"
     parameters["shower"] = "read Matchbox/Powheg-DefaultShower.in\n"
 elif(name.find("Matchbox")>0) :
     istart = 2
     simulation="Matchbox"
     parameters["shower"] = "read Matchbox/MCatNLO-DefaultShower.in\n"
 elif(name.find("Dipole")>0) :
     istart = 2
     simulation="Matchbox"
     parameters["shower"]  = "read Matchbox/MCatNLO-DipoleShower.in\n"
 elif(name.find("Powheg")>0) :
     istart = 2
     simulation="Powheg"
 
 if(simulation=="Matchbox") :
     parameters["bscheme"] = "read Matchbox/FiveFlavourScheme.in\n"
     if(parameters["shower"].find("Dipole")>=0) :
         parameters["bscheme"] += "read Matchbox/FiveFlavourNoBMassScheme.in\n"
     if(collider.find("DIS")<0) :
         parameters["nlo"] = "read Matchbox/MadGraph-OpenLoops.in\n"
 
 if(collider=="") :
     logging.error("Can\'t find collider")
     sys.exit(1)
 
 # find the template
 if(simulation=="") :
     if(collider.find("LHC-GammaGamma") >=0) :
         istart += 1
         templateName="Hadron-Gamma.in"
     elif(collider.find("TVT")>=0 or collider.find("LHC") >=0 or
        collider.find("ISR")>=0 or collider.find("SppS")>=0 or
        collider.find("Star")>=0) :
         templateName="Hadron.in"
     elif(collider.find("BFactory")<0) :
         templateName= "%s.in" % (collider)
     else :
         templateName= "LEP.in"
 else :
     if(collider.find("TVT")>=0 or collider.find("LHC") >=0 or
        collider.find("ISR")>=0 or collider.find("SppS")>=0 or
        collider.find("Star")>=0) :
         templateName= "Hadron-%s.in" % (simulation) 
     elif(collider.find("BFactory")<0) :
         templateName= "%s-%s.in" % (collider,simulation) 
     else :
         templateName= "LEP-%s.in" % (simulation) 
 with open(os.path.join("Rivet/Templates",templateName), 'r') as f:
     templateText = f.read()
 template = Template( templateText )
 # work out the name of the parameter file
 nameSplit=name.split("-")
 parameterName=nameSplit[istart]
 for i in range(istart+1,len(nameSplit)) :
     parameterName += "-%s" % nameSplit[i] 
 
 # work out the process and parameters
 process=""
 # Bfactory
 if(collider=="BFactory") :
     if(simulation=="") :
         if(parameterName=="10.58-res") :
             process += "\ncreate Herwig::MEee2VectorMeson /Herwig/MatrixElements/MEUpsilon HwMELepton.so\nset /Herwig/MatrixElements/MEUpsilon:VectorMeson /Herwig/Particles/Upsilon(4S)\nset /Herwig/MatrixElements/MEUpsilon:Coupling 0.0004151809\nset /Herwig/MatrixElements/SimpleEE:MatrixElements 0 /Herwig/MatrixElements/MEUpsilon"
         elif(parameterName=="10.58") :
             process += "\ncreate Herwig::MEee2VectorMeson /Herwig/MatrixElements/MEUpsilon HwMELepton.so\nset /Herwig/MatrixElements/MEUpsilon:VectorMeson /Herwig/Particles/Upsilon(4S)\nset /Herwig/MatrixElements/MEUpsilon:Coupling 0.0004151809\ninsert /Herwig/MatrixElements/SimpleEE:MatrixElements 0 /Herwig/MatrixElements/MEUpsilon\n"
             process += "set /Herwig/MatrixElements/MEee2gZ2qq:MaximumFlavour 4\n"
         else :
             process += "set /Herwig/MatrixElements/MEee2gZ2qq:MaximumFlavour 4\n"
     elif(simulation=="Powheg") :
         process = "set /Herwig/MatrixElements/PowhegMEee2gZ2qq:MaximumFlavour 4\n"
     elif(simulation=="Matchbox" ) :
         process = "do Factory:Process e- e+ -> u ubar\ndo Factory:Process e- e+ -> d dbar\ndo Factory:Process e- e+ -> c cbar\ndo Factory:Process e- e+ -> s sbar\n"
 # DIS
 elif(collider=="DIS") :
     if(simulation=="") :
         if(parameterName.find("NoME")>=0) :
             process = "set /Herwig/Shower/ShowerHandler:MECorrMode 0"
             parameterName=parameterName.replace("NoME-","")
         else :
             process = ""
     elif(simulation=="Powheg") :
         process = ""
     elif(simulation=="Matchbox" ) :
         if(parameterName.find("e-")>=0) :
             process="do Factory:Process e- p -> e- j"
         else :
             process="do Factory:Process e+ p -> e+ j"
 # LEP
 elif(collider=="LEP") :
     if(simulation=="") :
         process=""
         if(parameterName=="10") :
             process="set /Herwig/MatrixElements/MEee2gZ2qq:MaximumFlavour 4"
     elif(simulation=="Powheg") :
         process=""
         if(parameterName=="10") :
             process="set /Herwig/MatrixElements/PowhegMEee2gZ2qq:MaximumFlavour 4"
     elif(simulation=="Matchbox" ) :
         if(parameterName=="10") :
             process="do Factory:Process e- e+ -> u ubar\ndo Factory:Process e- e+ -> d dbar\ndo Factory:Process e- e+ -> c cbar\ndo Factory:Process e- e+ -> s sbar"
         else :
             process="do Factory:Process e- e+ -> j j"
 # TVT
 elif(collider=="TVT") :
     process="set /Herwig/Generators/EventGenerator:EventHandler:BeamB /Herwig/Particles/pbar-\n"
     if(parameterName.find("Run-II")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 1960.0\n"
     elif(parameterName.find("Run-I")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 1800.0\n"
     elif(parameterName.find("900")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 900.0\n"
     elif(parameterName.find("630")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 630.0\n"
     elif(parameterName.find("300")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 300.0\n"
 
     if(simulation=="") :
         if(parameterName.find("PromptPhoton")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaJet\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 15.\n"
         elif(parameterName.find("DiPhoton-GammaGamma")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGamma\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaGamma","")
         elif(parameterName.find("DiPhoton-GammaJet")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaJet\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaJet","")
         elif(parameterName.find("UE")>=0) :
             process += "insert SimpleQCD:MatrixElements[0] MEMinBias\n"
             process += "set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             process += "set /Herwig/Generators/EventGenerator:EventHandler:Cuts /Herwig/Cuts/MinBiasCuts\n"
             process += "create Herwig::MPIXSecReweighter /Herwig/Generators/MPIXSecReweighter\n"
             process += "insert /Herwig/Generators/EventGenerator:EventHandler:PostSubProcessHandlers 0 /Herwig/Generators/MPIXSecReweighter\n"
             process += "set /Herwig/Decays/DecayHandler:LifeTimeOption 0\n"
             process += "set /Herwig/Decays/DecayHandler:MaxLifeTime 10*mm\n"
         elif(parameterName.find("Jets")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEQCD2to2\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("Run-II-Jets-10")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 500.*GeV\n"
             elif(parameterName.find("Run-II-Jets-11")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 900.*GeV\n"
             elif(parameterName.find("Run-I-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
             elif(parameterName.find("Run-I-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 40.\n"
             elif(parameterName.find("Run-I-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 65.\n"
             elif(parameterName.find("Run-I-Jets-4")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 90.\n"
             elif(parameterName.find("Run-I-Jets-5")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 160.\n"
             elif(parameterName.find("Run-I-Jets-6")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 100.*GeV\n"
             elif(parameterName.find("Run-I-Jets-7")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 400.*GeV\n"
             elif(parameterName.find("Run-I-Jets-8")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 700.*GeV\n"
             elif(parameterName.find("Run-II-Jets-0")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 15.\n"
             elif(parameterName.find("Run-II-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 25.\n"
             elif(parameterName.find("Run-II-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 40.\n"
             elif(parameterName.find("Run-II-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 60.\n"
             elif(parameterName.find("Run-II-Jets-4")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 85.\n"
             elif(parameterName.find("Run-II-Jets-5")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 110.\n"
             elif(parameterName.find("Run-II-Jets-6")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 160.\n"
             elif(parameterName.find("Run-II-Jets-7")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 250.\n"
             elif(parameterName.find("Run-II-Jets-8")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 100.*GeV\n"
             elif(parameterName.find("Run-II-Jets-9")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 300.*GeV\n"
             elif(parameterName.find("900-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 10.\n"
             elif(parameterName.find("300-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 6.\n"
             elif(parameterName.find("630-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
             elif(parameterName.find("630-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 40.\n"
             elif(parameterName.find("630-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 75.\n"
             elif(parameterName.find("900-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 10.\n"
         elif(parameterName.find("Run-I-WZ")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Electron\ninsert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Electron\n"
         elif(parameterName.find("Run-I-W")>=0 or parameterName.find("Run-II-W")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Electron\n"
         elif(parameterName.find("Run-I-Z")>=0 or parameterName.find("Run-II-Z-e")>=0) :
             process +="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Electron\n"
         elif(parameterName.find("Run-II-Z-LowMass-mu")>=0) :
             process +="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 25*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 70*GeV\n"
         elif(parameterName.find("Run-II-Z-HighMass-mu")>=0) :
             process +="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 150*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 600*GeV\n"
         elif(parameterName.find("Run-II-Z-mu")>=0) :
             process +="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
     elif(simulation=="Powheg") :
         if(parameterName.find("Run-I-WZ")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2W2ff\nset PowhegMEqq2W2ff:Process Electron\ninsert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Electron\n"
         elif(parameterName.find("Run-I-W")>=0 or parameterName.find("Run-II-W")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2W2ff\nset PowhegMEqq2W2ff:Process Electron\n"
         elif(parameterName.find("Run-I-Z")>=0 or parameterName.find("Run-II-Z-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Electron\n"
         elif(parameterName.find("Run-II-Z-LowMass-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Muon\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 25*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 70*GeV\n"
         elif(parameterName.find("Run-II-Z-HighMass-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Muon\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 150*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 600*GeV\n"
         elif(parameterName.find("Run-II-Z-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Muon\n"
         elif(parameterName.find("DiPhoton-GammaGamma")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGammaPowheg\n"
             process+="set MEGammaGammaPowheg:Process GammaGamma\n"
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGamma\n"
             process+="set MEGammaGamma:Process gg\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaGamma","")
         elif(parameterName.find("DiPhoton-GammaJet")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGammaPowheg\n"
             process+="set MEGammaGammaPowheg:Process VJet\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaJet","")
     elif(simulation=="Matchbox" ) :
         if(parameterName.find("Jets")>=0) :
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 0\n"
             process+="do Factory:Process p p j j\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/MaxJetPtScale\n"
             process+="set  /Herwig/Cuts/Cuts:JetFinder  /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("Run-II-Jets-10")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 500.*GeV\n"
             elif(parameterName.find("Run-II-Jets-11")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 900.*GeV\n"
             elif(parameterName.find("Run-II-Jets-12")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 300.*GeV\n"
             elif(parameterName.find("Run-I-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.\n"
             elif(parameterName.find("Run-I-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 40.\n"
             elif(parameterName.find("Run-I-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 65.\n"
             elif(parameterName.find("Run-I-Jets-4")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 90.\n"
             elif(parameterName.find("Run-I-Jets-5")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 160.\n"
             elif(parameterName.find("Run-I-Jets-6")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 100.*GeV\n"
             elif(parameterName.find("Run-I-Jets-7")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 400.*GeV\n"
             elif(parameterName.find("Run-I-Jets-8")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 700.*GeV\n"
             elif(parameterName.find("Run-II-Jets-0")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 15.\n"
             elif(parameterName.find("Run-II-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 25.\n"
             elif(parameterName.find("Run-II-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 40.\n"
             elif(parameterName.find("Run-II-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 60.\n"
             elif(parameterName.find("Run-II-Jets-4")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 85.\n"
             elif(parameterName.find("Run-II-Jets-5")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 110.\n"
             elif(parameterName.find("Run-II-Jets-6")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 160.\n"
             elif(parameterName.find("Run-II-Jets-7")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 250.\n"
             elif(parameterName.find("Run-II-Jets-8")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 100.*GeV\n"
             elif(parameterName.find("Run-II-Jets-9")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 300.*GeV\n"
             elif(parameterName.find("900-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 10.\n"
             elif(parameterName.find("300-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 6.\n"
             elif(parameterName.find("630-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.\n"
             elif(parameterName.find("630-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 40.\n"
             elif(parameterName.find("630-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 75.\n"
             elif(parameterName.find("900-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 10.\n"
         elif(parameterName.find("Run-I-WZ")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p pbar e+ e-\ndo Factory:Process p pbar e+ nu\ndo Factory:Process p pbar e- nu\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Run-I-W")>=0 or parameterName.find("Run-II-W")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p pbar e+ nu\ndo Factory:Process p pbar e- nu\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Run-I-Z")>=0 or parameterName.find("Run-II-Z-e")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p pbar e+ e-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Run-II-Z-LowMass-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p pbar mu+ mu-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 25*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 70*GeV\n"
         elif(parameterName.find("Run-II-Z-HighMass-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p pbar mu+ mu-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 150.*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 600*GeV\n"
         elif(parameterName.find("Run-II-Z-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p pbar mu+ mu-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
 # Star
 elif(collider=="Star" ) :
     process = "set /Herwig/Decays/DecayHandler:LifeTimeOption 0\n"
     process+= "set /Herwig/Decays/DecayHandler:MaxLifeTime 10*mm\n"
     process+= "set /Herwig/Generators/EventGenerator:EventHandler:BeamB /Herwig/Particles/p+\n"
     process+= "set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 200.0\n"
     process+= "set /Herwig/Cuts/QCDCuts:X2Min 0.01\n"
     if(simulation=="") :
         if(parameterName.find("UE")>=0) :
             process += "insert SimpleQCD:MatrixElements[0] MEMinBias\n"
             process += "set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             process += "set /Herwig/Generators/EventGenerator:EventHandler:Cuts /Herwig/Cuts/MinBiasCuts\n"
             process += "create Herwig::MPIXSecReweighter /Herwig/Generators/MPIXSecReweighter\n"
             process += "insert /Herwig/Generators/EventGenerator:EventHandler:PostSubProcessHandlers 0 /Herwig/Generators/MPIXSecReweighter\n"
         else :
             process+="insert SimpleQCD:MatrixElements[0] MEQCD2to2\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 2.\n"
             elif(parameterName.find("Jets-2")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             elif(parameterName.find("Jets-3")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
             elif(parameterName.find("Jets-4")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 25.\n"
     else :
         logging.error("Star not supported for %s " % simulation)
         sys.exit(1)
 # ISR and SppS
 elif(collider=="ISR" or collider =="SppS" ) :
     process="set /Herwig/Decays/DecayHandler:LifeTimeOption 0\n"
     process+="set /Herwig/Decays/DecayHandler:MaxLifeTime 10*mm\n"
     if(collider=="SppS") :
         process ="set /Herwig/Generators/EventGenerator:EventHandler:BeamB /Herwig/Particles/pbar-\n"
     if(parameterName.find("30")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 30.4\n"
     elif(parameterName.find("44")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 44.4\n"
     elif(parameterName.find("53")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 53.0\n"
     elif(parameterName.find("62")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 62.2\n"
     elif(parameterName.find("63")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 63.0\n"
     elif(parameterName.find("200")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 200.0\n"
     elif(parameterName.find("500")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 500.0\n"
     elif(parameterName.find("546")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 546.0\n"
     elif(parameterName.find("900")>=0) :
         process+="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 900.0\n"
     if(simulation=="") :
         process += "insert SimpleQCD:MatrixElements[0] MEMinBias\n"
         process += "set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
         process += "set /Herwig/Generators/EventGenerator:EventHandler:Cuts /Herwig/Cuts/MinBiasCuts\n"
         process += "create Herwig::MPIXSecReweighter /Herwig/Generators/MPIXSecReweighter\n"
         process += "insert /Herwig/Generators/EventGenerator:EventHandler:PostSubProcessHandlers 0 /Herwig/Generators/MPIXSecReweighter\n"
     else :
         logging.error(" SppS and ISR not supported for %s " % simulation)
         sys.exit(1)
 # LHC
 elif(collider=="LHC") :
     if(parameterName.find("7-")==0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 7000.0\n"
     elif(parameterName.find("8-")==0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 8000.0\n"
     elif(parameterName.find("13-")==0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 13000.0\n"
     elif(parameterName.find("900")==0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 900.0\n"
     elif(parameterName.find("2360")==0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 2360.0\n"
     elif(parameterName.find("2760")==0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 2760.0\n"
     else :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 7000.0\n"
     if(simulation=="") :
         if(parameterName.find("8-VBF")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2HiggsVBF\n"
         elif(parameterName.find("VBF")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="insert SimpleQCD:MatrixElements[0] MEPP2HiggsVBF\n"
         elif(parameterName.find("ggHJet")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHiggsJet\n"
         elif(parameterName.find("8-ggH")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEHiggs\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHiggsJet\n"
             process+="set MEHiggsJet:Process qqbar\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("ggH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHiggs\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHiggsJet\n"
             process+="set MEHiggsJet:Process qqbar\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("PromptPhoton")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaJet\n"
             if(parameterName.find("PromptPhoton-1")>=0) :
                 process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             elif(parameterName.find("PromptPhoton-2")>=0) :
                 process+="set /Herwig/Cuts/PhotonKtCut:MinKT 25.\n"
             elif(parameterName.find("PromptPhoton-3")>=0) :
                 process+="set /Herwig/Cuts/PhotonKtCut:MinKT 80.\n"
             elif(parameterName.find("PromptPhoton-4")>=0) :
                 process+="set /Herwig/Cuts/PhotonKtCut:MinKT 150.\n"
         elif(parameterName.find("DiPhoton-GammaGamma")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGamma\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaGamma","")
         elif(parameterName.find("DiPhoton-GammaJet")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaJet\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaJet","")
         elif(parameterName.find("8-WH")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2WH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("8-ZH")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2ZH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("WH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->b,bbar;\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes W+->nu_e,e+; W+->nu_mu,mu+;\n"
             process+="insert SimpleQCD:MatrixElements[0] MEPP2WH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("ZH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->b,bbar;\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes Z0->e-,e+; Z0->mu-,mu+;\n"
             process+="insert SimpleQCD:MatrixElements[0] MEPP2ZH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("UE")>=0) :
             process += "insert SimpleQCD:MatrixElements[0] MEMinBias\n"
             process += "set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             process += "set /Herwig/Generators/EventGenerator:EventHandler:Cuts /Herwig/Cuts/MinBiasCuts\n"
             process += "create Herwig::MPIXSecReweighter /Herwig/Generators/MPIXSecReweighter\n"
             process += "insert /Herwig/Generators/EventGenerator:EventHandler:PostSubProcessHandlers 0 /Herwig/Generators/MPIXSecReweighter\n"
             if(parameterName.find("Long")>=0) :
                 process += "set /Herwig/Decays/DecayHandler:MaxLifeTime 100*mm\n"
         elif(parameterName.find("7-Jets")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEQCD2to2\n"
             process+="set MEQCD2to2:MaximumFlavour 5\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("7-Jets-0")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             elif(parameterName.find("7-Jets-10")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 200.*GeV\n"
             elif(parameterName.find("7-Jets-11")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 600.*GeV\n"
             elif(parameterName.find("7-Jets-12")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 1000.*GeV\n"
             elif(parameterName.find("7-Jets-13")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 1600.*GeV\n"
             elif(parameterName.find("7-Jets-14")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 2200.*GeV\n"
             elif(parameterName.find("7-Jets-15")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 2800.*GeV\n"
             elif(parameterName.find("7-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 10.\n"
             elif(parameterName.find("7-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
             elif(parameterName.find("7-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 40.\n"
             elif(parameterName.find("7-Jets-4")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 70.\n"
             elif(parameterName.find("7-Jets-5")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 150.\n"
             elif(parameterName.find("7-Jets-6")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 200.\n"
             elif(parameterName.find("7-Jets-7")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 300.\n"
             elif(parameterName.find("7-Jets-8")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 500.\n"
             elif(parameterName.find("7-Jets-9")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 90.*GeV\n"
         elif(parameterName.find("7-Charm")>=0 or \
              parameterName.find("7-Bottom")>=0) :
             if(parameterName.find("7-Bottom")>=0) :
                 process+="cp MEHeavyQuark MEBottom\n" 
                 process+="set MEBottom:QuarkType Bottom\n"
                 process+="insert SimpleQCD:MatrixElements[0] MEBottom\n"
             else : 
                 process+="cp MEHeavyQuark MECharm\n" 
                 process+="set MECharm:QuarkType Charm\n"
                 process+="insert SimpleQCD:MatrixElements[0] MECharm\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("7-Heavy-0")>=0) :
                 if(parameterName.find("7-Bottom")>=0) :
                     process+="set MEBottom:Process Pair\n" 
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 0.\n"
             elif(parameterName.find("-1")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             elif(parameterName.find("-2")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 20.\n"
             elif(parameterName.find("-3")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 50.\n"
             elif(parameterName.find("-4")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 80.\n"
             elif(parameterName.find("-5")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 110.\n"
             elif(parameterName.find("-6")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 90.*GeV\n"
             elif(parameterName.find("-7")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 340.*GeV\n"
             elif(parameterName.find("-8")>=0) :
                 process+="set /Herwig/Cuts/JetKtCut:MinKT 30.\n"
                 process+="set /Herwig/Cuts/QCDCuts:MHatMin 500.*GeV\n"
         elif(parameterName.find("Top-L")>=0) :
             process+="set MEHeavyQuark:QuarkType Top\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHeavyQuark\n"
             process+="do /Herwig/Particles/t:SelectDecayModes t->nu_e,e+,b; t->nu_mu,mu+,b;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("Top-SL")>=0) :
             process+="set MEHeavyQuark:QuarkType Top\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHeavyQuark\n"
             process+="set /Herwig/Particles/t:Synchronized Not_synchronized\n"
             process+="set /Herwig/Particles/tbar:Synchronized Not_synchronized\n"
             process+="do /Herwig/Particles/t:SelectDecayModes t->nu_e,e+,b; t->nu_mu,mu+,b;\n"
             process+="do /Herwig/Particles/tbar:SelectDecayModes tbar->b,bbar,cbar; tbar->bbar,cbar,d; tbar->bbar,cbar,s; tbar->bbar,s,ubar; tbar->bbar,ubar,d;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("Top-All")>=0) :
             process+="set MEHeavyQuark:QuarkType Top\n"
             process+="insert SimpleQCD:MatrixElements[0] MEHeavyQuark\n"
         elif(parameterName.find("WZ")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VV\nset MEPP2VV:Process WZ\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+; /Herwig/Particles/W+/W+->nu_mu,mu+;\n"
             process+="do /Herwig/Particles/W-:SelectDecayModes /Herwig/Particles/W-/W-->nu_ebar,e-; /Herwig/Particles/W-/W-->nu_mubar,mu-;\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("WW-emu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VV\nset MEPP2VV:Process WW\n"
             process+="set /Herwig/Particles/W+:Synchronized 0\n"
             process+="set /Herwig/Particles/W-:Synchronized 0\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+;\n"
             process+="do /Herwig/Particles/W-:SelectDecayModes /Herwig/Particles/W-/W-->nu_mubar,mu-;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("WW-ll")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VV\nset MEPP2VV:Process WW\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+; /Herwig/Particles/W+/W+->nu_mu,mu+; /Herwig/Particles/W+/W+->nu_tau,tau+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("ZZ-ll")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VV\nset MEPP2VV:Process ZZ\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+; /Herwig/Particles/Z0/Z0->tau-,tau+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("ZZ-lv")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VV\nset MEPP2VV:Process ZZ\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+; /Herwig/Particles/Z0/Z0->tau-,tau+; /Herwig/Particles/Z0/Z0->nu_e,nu_ebar; /Herwig/Particles/Z0/Z0->nu_mu,nu_mubar; /Herwig/Particles/Z0/Z0->nu_tau,nu_taubar;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("W-Z-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Electron\n"
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Electron\n"
         elif(parameterName.find("W-Z-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Muon\n"
         elif(parameterName.find("W-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Electron\n"
         elif(parameterName.find("W-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Muon\n"
         elif(parameterName.find("Z-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Electron\n"
         elif(parameterName.find("Z-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
         elif(parameterName.find("Z-LowMass-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Electron\n"
             process+="set /Herwig/Cuts/QCDCuts:MHatMin 20.*GeV\nset /Herwig/Cuts/MassCut:MinM 20.*GeV\nset /Herwig/Cuts/MassCut:MaxM 70.*GeV\n"
         elif(parameterName.find("Z-MedMass-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Electron\n"
             process+="set /Herwig/Cuts/QCDCuts:MHatMin 40.*GeV\nset /Herwig/Cuts/MassCut:MinM 40.*GeV\nset /Herwig/Cuts/MassCut:MaxM 130.*GeV\n"
         elif(parameterName.find("Z-LowMass-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
             process+="set /Herwig/Cuts/QCDCuts:MHatMin 10.*GeV\nset /Herwig/Cuts/MassCut:MinM 10.*GeV\nset /Herwig/Cuts/MassCut:MaxM 70.*GeV\n"
         elif(parameterName.find("W-Jet")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEWJet\nset MEWJet:WDecay Electron\n"
             if(parameterName.find("W-Jet-1-e")>=0) :
                 process+="set /Herwig/Cuts/WBosonKtCut:MinKT 100.0*GeV\n"
                 parameterName=parameterName.replace("W-Jet-1-e","W-Jet-e")
             elif(parameterName.find("W-Jet-2-e")>=0) :
                 process+="set /Herwig/Cuts/WBosonKtCut:MinKT 190.0*GeV\n"
                 parameterName=parameterName.replace("W-Jet-2-e","W-Jet-e")
             elif(parameterName.find("W-Jet-3-e")>=0) :
                 process+="set /Herwig/Cuts/WBosonKtCut:MinKT 270.0*GeV\n"
                 parameterName=parameterName.replace("W-Jet-3-e","W-Jet-e")
         elif(parameterName.find("Z-Jet")>=0) :
             if(parameterName.find("-e")>=0) :
                 process+="insert SimpleQCD:MatrixElements[0] MEZJet\nset MEZJet:ZDecay Electron\n"
                 if(parameterName.find("Z-Jet-0-e")>=0) :
                     process+="set /Herwig/Cuts/ZBosonKtCut:MinKT 35.0*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-0-e","Z-Jet-e")
                 elif(parameterName.find("Z-Jet-1-e")>=0) :
                     process+="set /Herwig/Cuts/ZBosonKtCut:MinKT 100.0*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-1-e","Z-Jet-e")
                 elif(parameterName.find("Z-Jet-2-e")>=0) :
                     process+="set /Herwig/Cuts/ZBosonKtCut:MinKT 190.0*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-2-e","Z-Jet-e")
                 elif(parameterName.find("Z-Jet-3-e")>=0) :
                     process+="set /Herwig/Cuts/ZBosonKtCut:MinKT 270.0*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-3-e","Z-Jet-e")
             else :
                 process+="insert SimpleQCD:MatrixElements[0] MEZJet\nset MEZJet:ZDecay Muon\n"
                 process+="set /Herwig/Cuts/ZBosonKtCut:MinKT 35.0*GeV\n"
                 parameterName=parameterName.replace("Z-Jet-0-mu","Z-Jet-mu")
         elif(parameterName.find("WGamma")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VGamma\nset MEPP2VGamma:Process 1\nset MEPP2VGamma:MassOption 1\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 10.\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             if(parameterName.find("-e")>=0) :
                 process+="do /Herwig/Particles/W+:SelectDecayModes W+->nu_e,e+;\n"
             else :
                 process+="do /Herwig/Particles/W+:SelectDecayModes W+->nu_mu,mu+;\n"
         elif(parameterName.find("ZGamma")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEPP2VGamma\nset MEPP2VGamma:Process 2\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 10.\n"
-            process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             if(parameterName.find("-e")>=0) :
                 process+="do /Herwig/Particles/Z0:SelectDecayModes Z0->e-,e+;\n"
             else :
                 process+="do /Herwig/Particles/Z0:SelectDecayModes Z0->mu-,mu+;\n"
         else :
             logging.error(" Process %s not supported for internal matrix elements" % name)
             sys.exit(1)
     elif(simulation=="Powheg") :
         if(parameterName.find("8-VBF")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2HiggsVBF\n"
         elif(parameterName.find("VBF")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2HiggsVBF\n"
         elif(parameterName.find("ggHJet")>=0) :
             logging.error(" Process %s not supported for POWHEG matrix elements" % name)
             sys.exit(1)
         elif(parameterName.find("8-ggH")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEHiggs\n"
         elif(parameterName.find("ggH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEHiggs\n"
         elif(parameterName.find("8-WH")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2WH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("8-ZH")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2ZH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("WH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->b,bbar;\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes W+->nu_e,e+; W+->nu_mu,mu+;\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2WH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("ZH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->b,bbar;\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes Z0->e-,e+; Z0->mu-,mu+;\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2ZH\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 0.0*GeV\n"
         elif(parameterName.find("UE")>=0) :
             logging.error(" Process %s not supported for powheg matrix elements" % name)
             sys.exit(1)
         elif(parameterName.find("WZ")>=0) :
             process+="create Herwig::HwDecayHandler /Herwig/NewPhysics/DecayHandler\n"
             process+="set /Herwig/NewPhysics/DecayHandler:NewStep No\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 0 /Herwig/Particles/tau-\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 1 /Herwig/Particles/tau+\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PreCascadeHandlers 0 /Herwig/NewPhysics/DecayHandler\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2VV\nset PowhegMEPP2VV:Process WZ\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+; /Herwig/Particles/W+/W+->nu_mu,mu+;\n"
             process+="do /Herwig/Particles/W-:SelectDecayModes /Herwig/Particles/W-/W-->nu_ebar,e-; /Herwig/Particles/W-/W-->nu_mubar,mu-;\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("WW-emu")>=0) :
             process+="create Herwig::HwDecayHandler /Herwig/NewPhysics/DecayHandler\n"
             process+="set /Herwig/NewPhysics/DecayHandler:NewStep No\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 0 /Herwig/Particles/tau-\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 1 /Herwig/Particles/tau+\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PreCascadeHandlers 0 /Herwig/NewPhysics/DecayHandler\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2VV\nset PowhegMEPP2VV:Process WW\n"
             process+="set /Herwig/Particles/W+:Synchronized 0\n"
             process+="set /Herwig/Particles/W-:Synchronized 0\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+;\n"
             process+="do /Herwig/Particles/W-:SelectDecayModes /Herwig/Particles/W-/W-->nu_mubar,mu-;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("WW-ll")>=0) :
             process+="create Herwig::HwDecayHandler /Herwig/NewPhysics/DecayHandler\n"
             process+="set /Herwig/NewPhysics/DecayHandler:NewStep No\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 0 /Herwig/Particles/tau-\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 1 /Herwig/Particles/tau+\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PreCascadeHandlers 0 /Herwig/NewPhysics/DecayHandler\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2VV\nset PowhegMEPP2VV:Process WW\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+; /Herwig/Particles/W+/W+->nu_mu,mu+; /Herwig/Particles/W+/W+->nu_tau,tau+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("ZZ-ll")>=0) :
             process+="create Herwig::HwDecayHandler /Herwig/NewPhysics/DecayHandler\n"
             process+="set /Herwig/NewPhysics/DecayHandler:NewStep No\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 0 /Herwig/Particles/tau-\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 1 /Herwig/Particles/tau+\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PreCascadeHandlers 0 /Herwig/NewPhysics/DecayHandler\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2VV\nset PowhegMEPP2VV:Process ZZ\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+; /Herwig/Particles/Z0/Z0->tau-,tau+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("ZZ-lv")>=0) :
             process+="create Herwig::HwDecayHandler /Herwig/NewPhysics/DecayHandler\n"
             process+="set /Herwig/NewPhysics/DecayHandler:NewStep No\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 0 /Herwig/Particles/tau-\n"
             process+="insert /Herwig/NewPhysics/DecayHandler:Excluded 1 /Herwig/Particles/tau+\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PreCascadeHandlers 0 /Herwig/NewPhysics/DecayHandler\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEPP2VV\nset PowhegMEPP2VV:Process ZZ\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+; /Herwig/Particles/Z0/Z0->tau-,tau+; /Herwig/Particles/Z0/Z0->nu_e,nu_ebar; /Herwig/Particles/Z0/Z0->nu_mu,nu_mubar; /Herwig/Particles/Z0/Z0->nu_tau,nu_taubar;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("W-Z-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Electron\n"
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2W2ff\nset PowhegMEqq2W2ff:Process Electron\n"
         elif(parameterName.find("W-Z-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEqq2gZ2ff\nset MEqq2gZ2ff:Process Muon\n"
             process+="insert SimpleQCD:MatrixElements[0] MEqq2W2ff\nset MEqq2W2ff:Process Muon\n"
         elif(parameterName.find("W-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2W2ff\nset PowhegMEqq2W2ff:Process Electron\n"
         elif(parameterName.find("W-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2W2ff\nset PowhegMEqq2W2ff:Process Muon\n"
         elif(parameterName.find("Z-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Electron\n"
         elif(parameterName.find("Z-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Muon\n"
         elif(parameterName.find("Z-LowMass-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Electron\n"
             process+="set /Herwig/Cuts/QCDCuts:MHatMin 20.*GeV\nset /Herwig/Cuts/MassCut:MinM 20.*GeV\nset /Herwig/Cuts/MassCut:MaxM 70.*GeV\n"
         elif(parameterName.find("Z-MedMass-e")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Electron\n"
             process+="set /Herwig/Cuts/QCDCuts:MHatMin 40.*GeV\nset /Herwig/Cuts/MassCut:MinM 40.*GeV\nset /Herwig/Cuts/MassCut:MaxM 130.*GeV\n"
         elif(parameterName.find("Z-LowMass-mu")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] PowhegMEqq2gZ2ff\nset PowhegMEqq2gZ2ff:Process Muon\n"
             process+="set /Herwig/Cuts/QCDCuts:MHatMin 10.*GeV\nset /Herwig/Cuts/MassCut:MinM 10.*GeV\nset /Herwig/Cuts/MassCut:MaxM 70.*GeV\n"
         elif(parameterName.find("DiPhoton-GammaGamma")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGammaPowheg\n"
             process+="set MEGammaGammaPowheg:Process GammaGamma\n"
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGamma\n"
             process+="set MEGammaGamma:Process gg\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaGamma","")
         elif(parameterName.find("DiPhoton-GammaJet")>=0) :
             process+="insert SimpleQCD:MatrixElements[0] MEGammaGammaPowheg\n"
             process+="set MEGammaGammaPowheg:Process VJet\n"
             process+="set /Herwig/Cuts/PhotonKtCut:MinKT 5.\n"
             process+="set /Herwig/Cuts/JetKtCut:MinKT 5.\n"
             parameterName=parameterName.replace("-GammaJet","")
         else :
             logging.error(" Process %s not supported for internal POWHEG matrix elements" % name)
             sys.exit(1)
             
     elif(simulation=="Matchbox" ) :
         if(parameterName.find("8-VBF")>=0) :
             parameters["nlo"] = "read Matchbox/VBFNLO.in\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 3\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/Z0\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/W+\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/W-\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/gamma\n"
             process+="do Factory:DiagramGenerator:TimeLikeRange 0 0\n"
             process+="do Factory:Process p p h0 j j\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
             if(parameterName.find("GammaGamma")>=0) :
                process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
                process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("VBF")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             parameters["nlo"] = "read Matchbox/VBFNLO.in\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 3\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/Z0\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/W+\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/W-\n"
             process+="insert Factory:DiagramGenerator:RestrictLines 0 /Herwig/Particles/gamma\n"
             process+="do Factory:DiagramGenerator:TimeLikeRange 0 0\n"
             process+="do Factory:Process p p h0 j j\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
         elif(parameterName.find("ggHJet")>=0) :
             parameters["nlo"] = "read Matchbox/MadGraph-GoSam.in\nread Matchbox/HiggsEffective.in\n"
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="set Factory:OrderInAlphaS 3\nset Factory:OrderInAlphaEW 1\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p h0 j\n"
             process+="set /Herwig/Cuts/Cuts:JetFinder /Herwig/Cuts/JetFinder\n"
             process+="insert /Herwig/Cuts/Cuts:MultiCuts 0 /Herwig/Cuts/JetCuts\n"
             process+="insert /Herwig/Cuts/JetCuts:JetRegions 0 /Herwig/Cuts/FirstJet\n"
             process+="set /Herwig/Cuts/FirstJet:PtMin 20.\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
         elif(parameterName.find("8-ggH")>=0) :
             parameters["nlo"] = "read Matchbox/MadGraph-GoSam.in\nread Matchbox/HiggsEffective.in\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 1\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p h0\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
             if(parameterName.find("GammaGamma")>=0) :
                process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
                process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("ggH")>=0) :
             parameters["nlo"] = "read Matchbox/MadGraph-GoSam.in\nread Matchbox/HiggsEffective.in\n"
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->tau-,tau+;\n"
             process+="set /Herwig/Particles/tau-:Stable Stable\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 1\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p h0\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
         elif(parameterName.find("8-WH")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p W+ h0\n"
             process+="do Factory:Process p p W- h0\n"
             process+="set /Herwig/Particles/W+:HardProcessWidth 0.\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
             if(parameterName.find("GammaGamma")>=0) :
                process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
                process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("8-ZH")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="set /Herwig/Particles/Z0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p Z0 h0\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 125.7\n"
             if(parameterName.find("GammaGamma")>=0) :
                process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
                process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("WH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->b,bbar;\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 3\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p e+ nu h0\n"
             process+="do Factory:Process p p e- nu h0\n"
             process+="do Factory:Process p p mu+ nu h0\n"
             process+="do Factory:Process p p mu- nu h0\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("ZH")>=0) :
             process+="do /Herwig/Particles/h0:SelectDecayModes h0->b,bbar;\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 3\n"
             process+="set /Herwig/Particles/h0:HardProcessWidth 0.\n"
             process+="do Factory:Process p p e+ e- h0\n"
             process+="do Factory:Process p p mu+ mu- h0\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("UE")>=0) :
             logging.error(" Process %s not supported for Matchbox matrix elements" % name)
             sys.exit(1)
         elif(parameterName.find("7-Jets")>=0) :
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 0\n"
             process+="do Factory:Process p p j j\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/MaxJetPtScale\n"
             process+="set  /Herwig/Cuts/Cuts:JetFinder  /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("7-Jets-0")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 5.\n"
             elif(parameterName.find("7-Jets-10")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 200.*GeV\n"
             elif(parameterName.find("7-Jets-11")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 600.*GeV\n"
             elif(parameterName.find("7-Jets-12")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 1000.*GeV\n"
             elif(parameterName.find("7-Jets-13")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 1600.*GeV\n"
             elif(parameterName.find("7-Jets-14")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 2200.*GeV\n"
             elif(parameterName.find("7-Jets-15")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 2800.*GeV\n"
             elif(parameterName.find("7-Jets-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 10.\n"
             elif(parameterName.find("7-Jets-2")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.\n"
             elif(parameterName.find("7-Jets-3")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 40.\n"
             elif(parameterName.find("7-Jets-4")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 70.\n"
             elif(parameterName.find("7-Jets-5")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 150.\n"
             elif(parameterName.find("7-Jets-6")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 200.\n"
             elif(parameterName.find("7-Jets-7")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 300.\n"
             elif(parameterName.find("7-Jets-8")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 500.\n"
             elif(parameterName.find("7-Jets-9")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.*GeV\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 90.*GeV\n"
         elif(parameterName.find("7-Charm")>=0 or \
              parameterName.find("7-Bottom")>=0) :
             parameters["bscheme"]="read Matchbox/FourFlavourScheme.in"
             process+="set /Herwig/Particles/b:HardProcessMass 4.2*GeV\n"
             process+="set /Herwig/Particles/bbar:HardProcessMass 4.2*GeV\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 0\n"
             if(parameterName.find("7-Bottom")>=0) :
                 process+="do Factory:Process p p b bbar\n"
             else:
                 process+="do Factory:Process p p c cbar\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/MaxJetPtScale\n"
             process+="set  /Herwig/Cuts/Cuts:JetFinder  /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="set /Herwig/UnderlyingEvent/MPIHandler:IdenticalToUE 0\n"
             if(parameterName.find("-0")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 0.\n"
             elif(parameterName.find("-1")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 5.\n"
             elif(parameterName.find("-2")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 20.\n"
             elif(parameterName.find("-3")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 50.\n"
             elif(parameterName.find("-4")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 80.\n"
             elif(parameterName.find("-5")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 110.\n"
             elif(parameterName.find("-6")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 90.*GeV\n"
             elif(parameterName.find("-7")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 340.*GeV\n"
             elif(parameterName.find("-8")>=0) :
                 process+="insert /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 30.\n"
                 process+="set /Herwig/Cuts/SecondJet:PtMin 25.\n"
                 process+="create ThePEG::JetPairRegion /Herwig/Cuts/JetPairMass JetCuts.so\n"
                 process+="set /Herwig/Cuts/JetPairMass:FirstRegion /Herwig/Cuts/FirstJet\n"
                 process+="set /Herwig/Cuts/JetPairMass:SecondRegion /Herwig/Cuts/SecondJet\n"
                 process+="insert /Herwig/Cuts/JetCuts:JetPairRegions 0  /Herwig/Cuts/JetPairMass\n"
                 process+="set /Herwig/Cuts/JetPairMass:MassMin 500.*GeV\n"
         elif(parameterName.find("Top-L")>=0) :
             process+="set /Herwig/Particles/t:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/tbar:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 0\n"
             process+="do Factory:Process p p t tbar\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/TopPairMTScale\n"
             process+="do /Herwig/Particles/t:SelectDecayModes t->nu_e,e+,b; t->nu_mu,mu+,b;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("Top-SL")>=0) :
             process+="set /Herwig/Particles/t:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/tbar:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 0\n"
             process+="do Factory:Process p p t tbar\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/TopPairMTScale\n"
             process+="set /Herwig/Particles/t:Synchronized Not_synchronized\n"
             process+="set /Herwig/Particles/tbar:Synchronized Not_synchronized\n"
             process+="do /Herwig/Particles/t:SelectDecayModes t->nu_e,e+,b; t->nu_mu,mu+,b;\n"
             process+="do /Herwig/Particles/tbar:SelectDecayModes tbar->b,bbar,cbar; tbar->bbar,cbar,d; tbar->bbar,cbar,s; tbar->bbar,s,ubar; tbar->bbar,ubar,d;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
         elif(parameterName.find("Top-All")>=0) :
             process+="set /Herwig/Particles/t:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/tbar:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 0\n"
             process+="do Factory:Process p p t tbar\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/TopPairMTScale\n"
         elif(parameterName.find("WZ")>=0) :
             process+="set /Herwig/Particles/W+:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/W-:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/Z0:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p W+ Z0\ndo Factory:Process p p W- Z0\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 171.6*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+; /Herwig/Particles/W+/W+->nu_mu,mu+;\n"
             process+="do /Herwig/Particles/W-:SelectDecayModes /Herwig/Particles/W-/W-->nu_ebar,e-; /Herwig/Particles/W-/W-->nu_mubar,mu-;\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("WW-emu")>=0) :
             process+="set /Herwig/Particles/W+:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/W-:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/Z0:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p W+ W-\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 160.8*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/Particles/W+:Synchronized 0\n"
             process+="set /Herwig/Particles/W-:Synchronized 0\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+;\n"
             process+="do /Herwig/Particles/W-:SelectDecayModes /Herwig/Particles/W-/W-->nu_mubar,mu-;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("WW-ll")>=0) :
             process+="set /Herwig/Particles/W+:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/W-:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/Z0:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p W+ W-\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 160.8*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="do /Herwig/Particles/W+:SelectDecayModes /Herwig/Particles/W+/W+->nu_e,e+; /Herwig/Particles/W+/W+->nu_mu,mu+; /Herwig/Particles/W+/W+->nu_tau,tau+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("ZZ-ll")>=0) :
             process+="set /Herwig/Particles/W+:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/W-:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/Z0:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p Z0 Z0\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 182.2*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+; /Herwig/Particles/Z0/Z0->tau-,tau+;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("ZZ-lv")>=0) :
             process+="set /Herwig/Particles/W+:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/W-:HardProcessWidth 0.*GeV\n"
             process+="set /Herwig/Particles/Z0:HardProcessWidth 0.*GeV\n"
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p Z0 Z0\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 182.2*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="do /Herwig/Particles/Z0:SelectDecayModes /Herwig/Particles/Z0/Z0->e-,e+; /Herwig/Particles/Z0/Z0->mu-,mu+; /Herwig/Particles/Z0/Z0->tau-,tau+; /Herwig/Particles/Z0/Z0->nu_e,nu_ebar; /Herwig/Particles/Z0/Z0->nu_mu,nu_mubar; /Herwig/Particles/Z0/Z0->nu_tau,nu_taubar;\n"
             process+="create Herwig::BranchingRatioReweighter /Herwig/Generators/BRReweighter\n"
             process+="insert /Herwig/Generators/EventGenerator:EventHandler:PostHadronizationHandlers 0 /Herwig/Generators/BRReweighter\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("W-Z-e")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\n"
             process+="do Factory:Process p p e+ e-\ndo Factory:Process p p e+ nu\ndo Factory:Process p p e- nu\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("W-Z-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\n"
             process+="do Factory:Process p p mu+ mu-\ndo Factory:Process p p mu+ nu\ndo Factory:Process p p mu- nu\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("W-e")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ nu\ndo Factory:Process p p e- nu\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("W-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p mu+ nu\ndo Factory:Process p p mu- nu\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Z-e")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ e-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Z-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p mu+ mu-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Z-jj")>=0) :
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 2\n"
             process+="do Factory:Process p p e+ e- j j\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set  /Herwig/Cuts/Cuts:JetFinder  /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
             process+="set /Herwig/Cuts/FirstJet:PtMin 40.*GeV\n"
             process+="set /Herwig/Cuts/SecondJet:PtMin 30.*GeV\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Z-LowMass-e")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ e-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 20*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 70*GeV\n"
         elif(parameterName.find("Z-MedMass-e")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ e-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 40*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 130*GeV\n"
         elif(parameterName.find("Z-LowMass-mu")>=0) :
             process+="set Factory:OrderInAlphaS 0\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p mu+ mu-\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/LeptonPairMassScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 10*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 70*GeV\n"
         elif(parameterName.find("W-Jet")>=0) :
             process+="set Factory:OrderInAlphaS 1\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ nu j\ndo Factory:Process p p e- nu j\n\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/HTScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
             process+="set /Herwig/Cuts/Cuts:JetFinder /Herwig/Cuts/JetFinder\n"
             process+="insert /Herwig/Cuts/Cuts:MultiCuts 0 /Herwig/Cuts/JetCuts\n"
             process+="insert /Herwig/Cuts/JetCuts:JetRegions 0 /Herwig/Cuts/FirstJet\n"
             if(parameterName.find("W-Jet-1-e")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 100.*GeV\n"
                 parameterName=parameterName.replace("W-Jet-1-e","W-Jet-e")
             elif(parameterName.find("W-Jet-2-e")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 190.0*GeV\n"
                 parameterName=parameterName.replace("W-Jet-2-e","W-Jet-e")
             elif(parameterName.find("W-Jet-3-e")>=0) :
                 process+="set /Herwig/Cuts/FirstJet:PtMin 270.0*GeV\n"
                 parameterName=parameterName.replace("W-Jet-3-e","W-Jet-e")
         elif(parameterName.find("Z-Jet")>=0) :
             process+="set Factory:OrderInAlphaS 1\nset Factory:OrderInAlphaEW 2\n"
             if(parameterName.find("-e")>=0) :
                 process+="do Factory:Process p p e+ e- j\n"
                 if(parameterName.find("Z-Jet-0-e")>=0) :
                     process+="set /Herwig/Cuts/FirstJet:PtMin 35.*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-0-e","Z-Jet-e")
                 elif(parameterName.find("Z-Jet-1-e")>=0) :
                     process+="set /Herwig/Cuts/FirstJet:PtMin 100.*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-1-e","Z-Jet-e")
                 elif(parameterName.find("Z-Jet-2-e")>=0) :
                     process+="set /Herwig/Cuts/FirstJet:PtMin 190.0*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-2-e","Z-Jet-e")
                 elif(parameterName.find("Z-Jet-3-e")>=0) :
                     process+="set /Herwig/Cuts/FirstJet:PtMin 270.0*GeV\n"
                     parameterName=parameterName.replace("Z-Jet-3-e","Z-Jet-e")
             else :
                 process+="do Factory:Process p p mu+ mu- j\n"
                 process+="set /Herwig/Cuts/FirstJet:PtMin 35.*GeV\n"
                 parameterName=parameterName.replace("Z-Jet-0-mu","Z-Jet-mu")
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
             process+="set Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/HTScale\n"
             process+="set /Herwig/Cuts/Cuts:JetFinder /Herwig/Cuts/JetFinder\n"
             process+="insert /Herwig/Cuts/Cuts:MultiCuts 0 /Herwig/Cuts/JetCuts\n"
             process+="insert /Herwig/Cuts/JetCuts:JetRegions 0 /Herwig/Cuts/FirstJet\n"
         elif(parameterName.find("Z-bb")>=0) :
             parameters["bscheme"]="read Matchbox/FourFlavourScheme.in"
             process+="set /Herwig/Particles/b:HardProcessMass 4.2*GeV\nset /Herwig/Particles/bbar:HardProcessMass 4.2*GeV\n"
             process+="set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ e- b bbar\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 91.2*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 66*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 116*GeV\n"
             process+="set /Herwig/Cuts/Cuts:JetFinder /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/SecondJet\n"
             process+="set  /Herwig/Cuts/FirstJet:PtMin 18.*GeV\n"
             process+="set  /Herwig/Cuts/SecondJet:PtMin 15.*GeV\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         elif(parameterName.find("Z-b")>=0) :
             process+="do Factory:StartParticleGroup bjet\n"
             process+="insert Factory:ParticleGroup 0 /Herwig/Particles/b\n"
             process+="insert Factory:ParticleGroup 0 /Herwig/Particles/bbar\n"
             process+="do Factory:EndParticleGroup\n"
             process+="set Factory:OrderInAlphaS 1\nset Factory:OrderInAlphaEW 2\ndo Factory:Process p p e+ e- bjet\n"
             process+="set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 91.2*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
             process+="set /Herwig/Cuts/Cuts:JetFinder /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="set  /Herwig/Cuts/FirstJet:PtMin 15.*GeV\n"
         elif(parameterName.find("W-b")>=0) :
             parameters["bscheme"]="read Matchbox/FourFlavourScheme.in"
             process += "set /Herwig/Particles/b:HardProcessMass 4.2*GeV\nset /Herwig/Particles/bbar:HardProcessMass 4.2*GeV\n"
             process += "set Factory:OrderInAlphaS 2\nset Factory:OrderInAlphaEW 2\n"
             process += "do Factory:Process p p e+  nu b bbar\ndo Factory:Process p p e-  nu b bbar\n"
             process += "do Factory:Process p p mu+ nu b bbar\ndo Factory:Process p p mu- nu b bbar\n"
             process += "set /Herwig/MatrixElements/Matchbox/Scales/FixedScale:FixedScale 80.4*GeV\nset Factory:ScaleChoice /Herwig/MatrixElements/Matchbox/Scales/FixedScale\n"
             process+="set /Herwig/Cuts/Cuts:JetFinder /Herwig/Cuts/JetFinder\n"
             process+="insert  /Herwig/Cuts/Cuts:MultiCuts 0  /Herwig/Cuts/JetCuts\n"
             process+="insert  /Herwig/Cuts/JetCuts:JetRegions 0  /Herwig/Cuts/FirstJet\n"
             process+="set  /Herwig/Cuts/FirstJet:PtMin 30.*GeV\n"
             process+="set /Herwig/Cuts/LeptonPairMassCut:MinMass 60*GeV\nset /Herwig/Cuts/LeptonPairMassCut:MaxMass 120*GeV\n"
         else :
             logging.error(" Process %s not supported for Matchbox matrix elements" % name)
             sys.exit(1)
 # LHC-GammaGamma
 elif(collider=="LHC-GammaGamma" ) :
     if(parameterName.find("-7-")>=0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 7000.0\n"
     elif(parameterName.find("-8-")>=0) :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 8000.0\n"
     else :
         process="set /Herwig/Generators/EventGenerator:EventHandler:LuminosityFunction:Energy 7000.0\n"
     if(simulation=="") :
         if(parameterName.find("7")>=0) :
             process += "insert SimpleQCD:MatrixElements 0 /Herwig/MatrixElements/MEgg2ff\n"
             process += "set /Herwig/MatrixElements/MEgg2ff:Process Muon\n"
         else :
             logging.error(" Process %s not supported for default matrix elements" % name)
             sys.exit(1)
     else :
         logging.error("LHC-GammaGamma not supported for %s " % simulation)
         sys.exit(1)
 
 
 parameters['parameterFile'] = os.path.join(collider,collider+"-"+parameterName+".in")
 parameters['runname'] = name
 parameters['process'] = process
 
 # write the file
 if(simulation=="Matchbox" ) :
     with open(os.path.join("Rivet",name+".in") ,'w') as f:
         f.write( template.substitute(parameters))
 else :
     with open(os.path.join("Rivet",name+".in") ,'w') as f:
         f.write( template.substitute(parameters))
 
 
 
 
 
 
diff --git a/Tests/python/merge-LHC-EW b/Tests/python/merge-LHC-EW
--- a/Tests/python/merge-LHC-EW
+++ b/Tests/python/merge-LHC-EW
@@ -1,152 +1,157 @@
 #! /usr/bin/env python
 import logging
 import sys
 import os, yoda
 
 """%prog
 
 Script for merging aida files
 
 """
 
 import sys
 if sys.version_info[:3] < (2,4,0):
     print "rivet scripts require Python version >= 2.4.0... exiting"
     sys.exit(1)
 
 if __name__ == "__main__":
     import logging
     from optparse import OptionParser, OptionGroup
     parser = OptionParser(usage="%prog aidafile aidafile2 [...]")
     parser.add_option("-o", "--out", dest="OUTFILE", default="-")
     verbgroup = OptionGroup(parser, "Verbosity control")
     verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL",
                          default=logging.INFO, help="print debug (very verbose) messages")
     verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL",
                          default=logging.INFO, help="be very quiet")
     parser.add_option_group(verbgroup)
     (opts, args) = parser.parse_args()
     logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s")
 
     ## Check args
     if len(args) < 1:
         logging.error("Must specify at least one AIDA histogram file")
         sys.exit(1)
 
     ## Get histos
     outhistos={}
     for file in args:
         print file
         if not os.access(file, os.R_OK):
             logging.error("%s can not be read" % file)
             break
         try:
             aos = yoda.read(file)
         except:
             logging.error("%s can not be parsed as XML" % file)
             break
         ## Get histos from this YODA file
         for aopath, ao in aos.iteritems() :
             if(aopath.find("ATLAS_2010_S8919674")>0) :
                 if((aopath.find("d01")>0 or aopath.find("d05")>0 or 
                     aopath.find("d07")>0) and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif((aopath.find("d02")>0 or aopath.find("d06")>0 or 
                       aopath.find("d08")>0) and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2011_S9131140")>0) :
                 if(aopath.find("d01")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("d02")>0 and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2011_I925932")>0) :
                 if(aopath.find("d01")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("d02")>0 and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2011_I945498")>0) :
                 if(aopath.find("y01")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("y02")>0 and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("y03")>0 and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2013_I1217867")>0) :
                 if(aopath.find("y01")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("y02")>0 and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
             elif (aopath.find("CMS_2012_I941555")>0) :
                 if((aopath.find("y01")>0 or aopath.find("y03")>0 ) and file.find("-mu")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("y02")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2014_I1300647" )>0) :
                 if(aopath.find("y01")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif((not aopath.find("y01")>0) and file.find("-mu")>0) :
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2014_I1288706" )>0) :
                 if(aopath.find("y02")>0 and file.find("-e")>0) : 
                     outhistos[aopath] = ao
                 elif(aopath.find("y01")>0 and file.find("-mu")>0) :
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2012_I1204784" )>0) :
                 if( file.find("-e")>0 and
                     ( aopath.find("d03")>0 or 
                       ((aopath.find("d01")>0 or aopath.find("d02")>0) and aopath.find("y01")>0))) : 
                     outhistos[aopath] = ao
                 elif(file.find("-mu")>0 and
                      ( aopath.find("d04")>0 or 
                        ((aopath.find("d01")>0 or aopath.find("d02")>0) and aopath.find("y02")>0))) : 
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2014_I1312627_EL") >0) :
                 if(file.find("-e")>0) :
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2014_I1312627_MU") >0) :
                 if(file.find("-mu")>0) :
                     outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2014_I1312627") >0) :
                 if(file.find("-e")>0) :
                     outhistos[aopath] = ao
             elif (aopath.find("CMS_2013_I1224539_WJET" )>0) :
                 if(file.find("-1-e")>0 and (aopath.find("d52")>0 or aopath.find("d53")>0 or aopath.find("d56")>0 or aopath.find("d57")>0 or aopath.find("d60")>0 or aopath.find("d61")>0 or aopath.find("d64")>0 or aopath.find("d65")>0 or aopath.find("d68")>0 or aopath.find("d69")>0 or aopath.find("d72")>0)) :
                     outhistos[aopath] = ao
                 elif(file.find("-2-e")>0 and (aopath.find("d54")>0 or aopath.find("d58")>0 or aopath.find("d62")>0 or aopath.find("d66")>0 or aopath.find("d70")>0 or aopath.find("d73")>0)) :
                     outhistos[aopath] = ao
                 elif(file.find("-3-e")>0 and (aopath.find("d55")>0 or aopath.find("d59")>0 or aopath.find("d63")>0 or aopath.find("d67")>0 or aopath.find("d71")>0 or aopath.find("d74")>0)) :
                     outhistos[aopath] = ao
             elif (aopath.find("CMS_2013_I1224539_ZJET" )>0) :
                 if(file.find("-1-e")>0 and (aopath.find("d29")>0 or aopath.find("d30")>0 or aopath.find("d33")>0 or aopath.find("d34")>0 or aopath.find("d37")>0 or aopath.find("d38")>0 or aopath.find("d41")>0 or aopath.find("d42")>0 or aopath.find("d45")>0 or aopath.find("d46")>0 or aopath.find("d49")>0)) :
                     outhistos[aopath] = ao
                 elif(file.find("-2-e")>0 and (aopath.find("d31")>0 or aopath.find("d35")>0 or aopath.find("d39")>0 or aopath.find("d43")>0 or aopath.find("d47")>0 or aopath.find("d50")>0)) :
                     outhistos[aopath] = ao
                 elif(file.find("-3-e")>0 and (aopath.find("d32")>0 or aopath.find("d36")>0 or aopath.find("d40")>0 or aopath.find("d44")>0 or aopath.find("d48")>0 or aopath.find("d51")>0)) :
                     outhistos[aopath] = ao
             elif (aopath.find("CMS_2013_I1258128")>0) :
                 if(aopath.find("d01")>0 or aopath.find("d02")>0 or
                    aopath.find("d03")>0 or aopath.find("d04")>0) :
                     outhistos[aopath] = ao
             elif (aopath.find("CMS_2013_I1209721" )>0 and file.find("-0")>0 ) :
                 outhistos[aopath] = ao
             elif (aopath.find("ATLAS_2011_I928289")>0) :
                 if(file.find("-e")>=0 and (aopath.find("y01")>=0 or aopath.find("y02")>=0)) :
                     outhistos[aopath] = ao
                 elif(file.find("-mu")>=0 and (aopath.find("y03")>=0 or aopath.find("y04")>=0)) :
                     outhistos[aopath] = ao
             elif (aopath.find("CMS_2013_I1122847")>0) :
                 if(file.find("-mu")>=0 and aopath.find("d01")>=0 ) :
                     outhistos[aopath] = ao
                 elif(file.find("-e")>=0 and (aopath.find("d02")>=0 or aopath.find("d03")>=0)) :
                     outhistos[aopath] = ao
+            elif (aopath.find("ATLAS_2016_I1424838")>0) :
+                if(file.find("-mu")>=0 and aopath.find("x02")>=0 ) :
+                    outhistos[aopath] = ao
+                elif(file.find("-e")>=0 and (aopath.find("x01")>=0)) :
+                    outhistos[aopath] = ao
             elif (aopath.find("CMS_2015_I1310737")>0) :
                 if aopath in outhistos :
                     outhistos[aopath] += ao
                 else :
                     outhistos[aopath] = ao
             else :
                 outhistos[aopath] = ao
 
     # Choose output file
     yoda.writeYODA(outhistos,opts.OUTFILE)
     sys.exit(0)
diff --git a/Tests/python/merge-LHC-Jets b/Tests/python/merge-LHC-Jets
--- a/Tests/python/merge-LHC-Jets
+++ b/Tests/python/merge-LHC-Jets
@@ -1,1300 +1,1297 @@
 #! /usr/bin/env python
 import logging
 import sys
 
 if sys.version_info[:3] < (2,4,0):
     print "rivet scripts require Python version >= 2.4.0... exiting"
     sys.exit(1)
 
 import os, yoda
 
 # #############################################
 
 
 def fillAbove(scale,desthisto, sourcehistosbyptmin) :
     pthigh= 1e100
     ptlow =-1e100
     for pt, h in sorted(sourcehistosbyptmin.iteritems(),reverse=True):
         ptlow=pt
         if(type(desthisto)==yoda.core.Scatter2D) :
             for i in range(0,h.numPoints) :
                 xMin = h.points[i].x-h.points[i].xErrs.minus
                 if( xMin*scale >= ptlow and 
                     xMin*scale <  pthigh ) :
                     desthisto.addPoint(h.points[i])
         elif(type(desthisto)==yoda.core.Profile1D) :
             for i in range(0,h.numBins) :
                 if(h.bins[i].xMin*scale  >= ptlow and 
                    h.bins[i].xMin*scale  <  pthigh ) :
                     desthisto.bins[i] += h.bins[i]
         elif(type(desthisto)==yoda.core.Histo1D) :
             for i in range(0,h.numBins) :
                 if(h.bins[i].xMin*scale  >= ptlow and 
                    h.bins[i].xMin*scale  <  pthigh ) :
                     desthisto.bins[i] += h.bins[i]
         else :
             logging.error("Can't merge %s, unknown type" % desthisto.path)
             sys.exit(1)
         pthigh=pt
 
 def mergeByPt(hpath, sqrts, scale=1.) :
     global inhistos_pt
     global outhistos
     try:
         fillAbove(scale,outhistos[hpath], inhistos_pt[hpath][float(sqrts)])
     except:
         pass
 
 def mergeByMass(hpath, sqrts, scale=1.):
     global inhistos_mass
     global outhistos
     try:
         fillAbove(scale,outhistos[hpath], inhistos_mass[hpath][float(sqrts)])
     except:
         pass
 
 def useOnePt(hpath, sqrts, ptmin):
     global inhistos_pt
     global outhistos
     try:
        ## Find best pT_min match
         ptmins = inhistos_pt[hpath][float(sqrts)].keys()
         closest_ptmin = None
         for ptm in ptmins:
             if closest_ptmin is None or \
                     abs(ptm-float(ptmin)) < abs(closest_ptmin-float(ptmin)):
                 closest_ptmin = ptm
         if closest_ptmin != float(ptmin):
             logging.warning("Inexact match for requested pTmin=%s: " % ptmin + \
                                 "using pTmin=%e instead" % closest_ptmin)
         outhistos[hpath] =  inhistos_pt[hpath][float(sqrts)][closest_ptmin]
     except:
         pass
 
 def useOneMass(hpath, sqrts, ptmin):
     global inhistos_pt
     global outhistos
     try:
        ## Find best pT_min match
         ptmins = inhistos_mass[hpath][float(sqrts)].keys()
         closest_ptmin = None
         for ptm in ptmins:
             if closest_ptmin is None or \
                     abs(ptm-float(ptmin)) < abs(closest_ptmin-float(ptmin)):
                 closest_ptmin = ptm
         if closest_ptmin != float(ptmin):
             logging.warning("Inexact match for requested pTmin=%s: " % ptmin + \
                                 "using pTmin=%e instead" % closest_ptmin)
         outhistos[hpath] =  inhistos_mass[hpath][float(sqrts)][closest_ptmin]
     except:
         pass
 
 # #######################################
 
 if __name__ == "__main__":
     import logging
     from optparse import OptionParser, OptionGroup
     parser = OptionParser(usage="%prog name")
     verbgroup = OptionGroup(parser, "Verbosity control")
     parser.add_option("--with-ue",
                       action='store_true' ,
                       dest="ue",
                       default=True,
                       help="Include UE analyses")
     parser.add_option("--without-ue",
                       action='store_false',
                       dest="ue",
                       default=True,
                       help="Don\'t include UE analyses")
     verbgroup.add_option("-v", "--verbose", action="store_const", const=logging.DEBUG, dest="LOGLEVEL",
                          default=logging.INFO, help="print debug (very verbose) messages")
     verbgroup.add_option("-q", "--quiet", action="store_const", const=logging.WARNING, dest="LOGLEVEL",
                          default=logging.INFO, help="be very quiet")
     parser.add_option_group(verbgroup)
     (opts, args) = parser.parse_args()
     logging.basicConfig(level=opts.LOGLEVEL, format="%(message)s")
 
     (opts, args) = parser.parse_args()
 
     ## Check args
     if len(args) < 1:
         logging.error("Must specify at least the name of the files")
         sys.exit(1)
  
 yodafiles=["-7-Jets-1.yoda","-7-Jets-2.yoda",
            "-7-Jets-3.yoda","-7-Jets-4.yoda","-7-Jets-5.yoda",
            "-7-Jets-6.yoda","-7-Jets-7.yoda","-7-Jets-8.yoda",
            "-7-Bottom-0.yoda","-7-Bottom-1.yoda","-7-Bottom-2.yoda",
            "-7-Bottom-3.yoda","-7-Bottom-4.yoda","-7-Bottom-5.yoda",
            "-7-Charm-1.yoda","-7-Charm-2.yoda",
            "-7-Charm-3.yoda","-7-Charm-4.yoda","-7-Charm-5.yoda",
-           "-7-Top-SL.yoda","-7-Top-L.yoda","-7-Top-All.yoda"]
+           "-7-Top-SL.yoda","-7-Top-L.yoda","-7-Top-All.yoda","-8-Top-All.yoda"]
 
 if(opts.ue) :
     yodafiles += ["-7-Jets-0.yoda","-900-UE.yoda"   ,"-2360-UE.yoda"    ,"-2760-UE.yoda"    ,
                   "-7-UE.yoda"     ,"-900-UE-Long.yoda","-8-UE.yoda",
                   "-7-UE-Long.yoda","-13-UE.yoda"]
 ## Get histos
 inhistos_pt   = {}
 inhistos_mass = {}
 outhistos={}
 weights = {}
 for f in yodafiles:
     file=args[0]+f
     sqrts=7000
     if(file.find("-900-UE")>0) :
         sqrts=900
         ptmin=0.
     elif(file.find("-2360-UE")>0) :
         sqrts=2360
         ptmin=0.
     elif(file.find("-2760-UE")>0) :
         sqrts=2760
         ptmin=0.
     elif(file.find("-7-UE")>0) :
         ptmin=0.
     elif(file.find("-13-UE")>0) :
         ptmin=0.
         sqrts=13000
     elif(file.find("-7-Jets-0")>0) :
         ptmin=4.
     elif(file.find("-7-Jets-1")>0) :
         if( not opts.ue) :
             ptmin = 10.
         else :
             ptmin = 20.
     elif(file.find("-7-Jets-2")>0) :
         ptmin=40.
     elif(file.find("-7-Jets-3")>0) :
         ptmin=80.
     elif(file.find("-7-Jets-4")>0) :
         ptmin=110.
     elif(file.find("-7-Jets-5")>0) :
         ptmin=210.
     elif(file.find("-7-Jets-6")>0) :
         ptmin=260.
     elif(file.find("-7-Jets-7")>0) :
         ptmin=400.
     elif(file.find("-7-Jets-8")>0) :
         ptmin=600.
     elif(file.find("-7-Bottom-0")>0) :
         ptmin=0.
     elif(file.find("-7-Bottom-1")>0 or file.find("-7-Charm-1")>0) :
         ptmin=10.
     elif(file.find("-7-Bottom-2")>0 or file.find("-7-Charm-2")>0) :
         ptmin=30.
     elif(file.find("-7-Bottom-3")>0 or file.find("-7-Charm-3")>0) :
         ptmin=70.
     elif(file.find("-7-Bottom-4")>0 or file.find("-7-Charm-4")>0) :
         ptmin=100.
     elif(file.find("-7-Bottom-5")>0 or file.find("-7-Charm-5")>0) :
         ptmin=130.
     elif(file.find("-7-Top-SL.yoda")>0 or file.find("-7-Top-L.yoda")>0 or \
          file.find("-7-Top-All.yoda")>0):
         ptmin=0.
     if not os.access(file, os.R_OK):
         logging.error("%s can not be read" % file)
         continue
     try:
         aos = yoda.read(file)
     except:
         logging.error("%s can not be parsed as YODA" % file)
         continue
     ## Get histos from this YODA file
     for aopath, ao in aos.iteritems() :
         if(aopath.find("S8924791")>0 or 
            aopath.find("S8971293")>0 or 
            aopath.find("S8817804")>0 or 
            aopath.find("I1082936")>0 or 
            aopath.find("S8994773")>0 or 
            aopath.find("S8918562")>0 or 
            aopath.find("S8624100")>0 or 
            aopath.find("S8625980")>0 or 
            aopath.find("S8894728")>0 or 
            aopath.find("S8957746")>0 or 
            aopath.find("S9126244")>0 or 
            aopath.find("S9120041")>0 or 
            aopath.find("S8950903")>0 or 
            aopath.find("S9086218")>0 or 
            aopath.find("S9088458")>0 or 
            aopath.find("I919017" )>0 or
            aopath.find("I926145" )>0 or
            aopath.find("S8941262")>0 or
            aopath.find("S8973270")>0 or
            aopath.find("I1118269")>0 or
            aopath.find("I1188891")>0 or
            aopath.find("I1082009")>0 or
            aopath.find("I1087342")>0 or
            aopath.find("S9035664")>0 or
            aopath.find("I1125575")>0 or
            aopath.find("I1094564")>0 or
            aopath.find("I930220")>0 or
            aopath.find("I1224539")>0 or
            aopath.find("I1273574")>0 or
            aopath.find("I1261026")>0 or
            aopath.find("I1307243")>0 or
            aopath.find("I1325553")>0 or
            aopath.find("I1298810")>0 or
            aopath.find("CMS_2012_PAS_QCD_11_010")>0 or
            aopath.find("CMS_2013_I1208923")>0 or
            aopath.find("ATLAS_2014_I1298811")>0) :
            if not inhistos_pt.has_key(aopath):
                inhistos_pt[aopath] = {}
            tmpE = inhistos_pt[aopath]
            if not tmpE.has_key(sqrts):
                tmpE[sqrts] = {}
            if not tmpE[sqrts].has_key(ptmin):
                tmpE[sqrts][ptmin] = ao
            else:
                tmpE[sqrts][ptmin] += ao
                #raise Exception("A set with ptmin = %s already exists" % ( ptmin))
-
-
-
         else :
             if(aopath.find("I1243871")>0) :
                 if(aopath.find("x01")>0 and file.find("-7-Top-L.yoda")>0 ) :
                     outhistos[aopath] = ao
                 elif(aopath.find("x02")>0 and file.find("-7-Top-SL.yoda")>0 ) :
                     outhistos[aopath] = ao
             else :
                 outhistos[aopath] = ao
 
 yodafiles=["-7-Jets-1.yoda" ,"-7-Jets-9.yoda" ,"-7-Jets-10.yoda",
            "-7-Jets-11.yoda","-7-Jets-12.yoda","-7-Jets-13.yoda",
            "-7-Jets-14.yoda","-7-Jets-15.yoda",
            "-7-Bottom-6.yoda","-7-Bottom-7.yoda","-7-Bottom-8.yoda"]
 
 for f in yodafiles:
     file=args[0]+f
     if(file.find("-7-Jets-1.yoda")>0) :
         sqrts=7000
         mass=0
     if(file.find("-7-Jets-9.yoda")>0) :
         sqrts=7000
         mass=100
     elif(file.find("-7-Jets-10.yoda")>0) :
         sqrts=7000
         mass=250
     elif(file.find("-7-Jets-11.yoda")>0) :
         sqrts=7000
         mass=650
     elif(file.find("-7-Jets-12.yoda")>0) :
         sqrts=7000
         mass=1100
     elif(file.find("-7-Jets-13.yoda")>0) :
         sqrts=7000
         mass=1700
     elif(file.find("-7-Jets-14.yoda")>0) :
         sqrts=7000
         mass=2300
     elif(file.find("-7-Jets-15.yoda")>0) :
         sqrts=7000
         mass=2900
     elif(file.find("-7-Bottom-6.yoda")>0) :
         sqrts=7000
         mass=110
     elif(file.find("-7-Bottom-7.yoda")>0) :
         sqrts=7000
         mass=370
     elif(file.find("-7-Bottom-8.yoda")>0) :
         sqrts=7000
         mass=550
     if not os.access(file, os.R_OK):
         logging.error("%s can not be read" % file)
         continue
     try:
         aos = yoda.read(file)
     except:
         logging.error("%s can not be parsed as YODA" % file)
         continue
     ## Get histos from this YODA file
     for aopath, ao in aos.iteritems() :
         if(aopath.find("8817804")>0 or
            aopath.find("1082936")>0 or
            aopath.find("I930220")>0 or
            aopath.find("1261026")>0 or
            aopath.find("1090423")>0 or
            aopath.find("1268975")>0 or
            aopath.find("CMS_2013_I1208923")>0) :
            if not inhistos_mass.has_key(aopath):
                inhistos_mass[aopath] = {}
            tmpE = inhistos_mass[aopath]
            if not tmpE.has_key(sqrts):
                tmpE[sqrts] = {}
            tmpP = tmpE[sqrts]
            if not tmpP.has_key(mass):
                tmpP[mass] = ao
            else:
                 raise Exception("A set with mass = %s already exists" % ( mass))
 
 ## Make empty output histos if needed
 for hpath,hsets in inhistos_pt.iteritems():
     if( hpath.find("8924791")>0  or 
         hpath.find("8971293")>0 or 
         hpath.find("8817804")>0 or 
         hpath.find("8968497")>0 or 
         (hpath.find("9120041")>0 and (hpath.find("d01")>0 or hpath.find("d02")>0)) or 
         hpath.find("9126244")>0 or 
         hpath.find("926145") >0 or 
         hpath.find("9086218")>0 or 
         hpath.find("1082936")>0 or 
         hpath.find("8941262")>0 or 
         hpath.find("1118269")>0 or 
         hpath.find("1087342")>0 or 
         hpath.find("1188891")>0 or
         hpath.find("919017")>0  or
         hpath.find("9035664")>0 or
         hpath.find("1125575")>0 or
         hpath.find("1094564")>0 or
         hpath.find("I930220")>0 or
         hpath.find("S9088458")>0 or 
         hpath.find("I1273574")>0 or 
         hpath.find("I1261026")>0 or 
         hpath.find("I1090423")>0 or
         hpath.find("QCD_11_010")>0 or
         hpath.find("1298811"   )>0 or
         hpath.find("I1325553"  )>0 or
         hpath.find("I1298810"  )>0 or
         hpath.find("1307243"   )>0 or
         hpath.find("CMS_2013_I1208923"   )>0) :
         if(type(hsets.values()[0].values()[0])==yoda.core.Scatter2D) :
             outhistos[hpath] = yoda.core.Scatter2D(hsets.values()[0].values()[0].path,
                                                    hsets.values()[0].values()[0].title)
         elif(type(hsets.values()[0].values()[0])==yoda.core.Profile1D) :
             outhistos[hpath] = yoda.core.Profile1D(hsets.values()[0].values()[0].path,
                                                    hsets.values()[0].values()[0].title)
             for i in range(0,hsets.values()[0].values()[0].numBins) :
                 outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin,
                                         hsets.values()[0].values()[0].bins[i].xMax)
         elif(type(hsets.values()[0].values()[0])==yoda.core.Histo1D) :
             outhistos[hpath] = yoda.core.Histo1D(hsets.values()[0].values()[0].path,
                                                 hsets.values()[0].values()[0].title)
             for i in range(0,hsets.values()[0].values()[0].numBins) :
                 outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin,
                                         hsets.values()[0].values()[0].bins[i].xMax)
         else :
             logging.error("Histogram %s is of unknown type" % hpath)
             sys.exit(1) 
 
 ## Make empty output histos if needed
 for hpath,hsets in inhistos_mass.iteritems():
     if(hpath.find("1268975")>0) :
         if(type(hsets.values()[0].values()[0])==yoda.core.Scatter2D) :
             outhistos[hpath] = yoda.core.Scatter2D(hsets.values()[0].values()[0].path,
                                                    hsets.values()[0].values()[0].title)
         elif(type(hsets.values()[0].values()[0])==yoda.core.Profile1D) :
             outhistos[hpath] = yoda.core.Profile1D(hsets.values()[0].values()[0].path,
                                                    hsets.values()[0].values()[0].title)
             for i in range(0,hsets.values()[0].values()[0].numBins) :
                 outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin,
                                         hsets.values()[0].values()[0].bins[i].xMax)
         elif(type(hsets.values()[0].values()[0])==yoda.core.Histo1D) :
             outhistos[hpath] = yoda.core.Histo1D(hsets.values()[0].values()[0].path,
                                                 hsets.values()[0].values()[0].title)
             for i in range(0,hsets.values()[0].values()[0].numBins) :
                 outhistos[hpath].addBin(hsets.values()[0].values()[0].bins[i].xMin,
                                         hsets.values()[0].values()[0].bins[i].xMax)
         else :
             logging.error("Histogram %s is of unknown type" % hpath)
             sys.exit(1)
         
 
 logging.info("Processing CMS_2011_S8957746")
 useOnePt("/CMS_2011_S8957746/d01-x01-y01", "7000", "80" )
 useOnePt("/CMS_2011_S8957746/d02-x01-y01", "7000", "80" )
 useOnePt("/CMS_2011_S8957746/d03-x01-y01", "7000", "110" )
 useOnePt("/CMS_2011_S8957746/d04-x01-y01", "7000", "110" )
 useOnePt("/CMS_2011_S8957746/d05-x01-y01", "7000", "210" )
 useOnePt("/CMS_2011_S8957746/d06-x01-y01", "7000", "210" )
 
 logging.info("Processing ATLAS_2010_S8894728")
 useOnePt("/ATLAS_2010_S8894728/d01-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d01-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d01-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d02-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d02-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d02-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d03-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d03-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d03-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d04-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d04-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d04-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d05-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d06-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d07-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d08-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d09-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d09-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d09-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d10-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d10-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d10-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d11-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d11-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d11-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d12-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d12-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d12-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d13-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d13-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d13-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d13-x01-y04",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d14-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d14-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d14-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d14-x01-y04", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d15-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d15-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d15-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d15-x01-y04",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d16-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d16-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d16-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d16-x01-y04", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d17-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d17-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d17-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d18-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d18-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d18-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d19-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d19-x01-y02",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d19-x01-y03",  "900", "0" )
 useOnePt("/ATLAS_2010_S8894728/d20-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d20-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d20-x01-y03", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d21-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8894728/d22-x01-y01", "7000", "0" )
 
 logging.info("Processing ATLAS_2011_S8994773")
 useOnePt("/ATLAS_2011_S8994773/d01-x01-y01", "900", "0" )
 useOnePt("/ATLAS_2011_S8994773/d02-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2011_S8994773/d03-x01-y01", "900", "0" )
 useOnePt("/ATLAS_2011_S8994773/d04-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2011_S8994773/d13-x01-y01", "900", "0" )
 useOnePt("/ATLAS_2011_S8994773/d13-x01-y02", "900", "0" )
 useOnePt("/ATLAS_2011_S8994773/d13-x01-y03", "900", "0" )
 useOnePt("/ATLAS_2011_S8994773/d14-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2011_S8994773/d14-x01-y02", "7000", "0" )
 useOnePt("/ATLAS_2011_S8994773/d14-x01-y03", "7000", "0" )
 
 logging.info("Processing ALICE_2010_S8624100")
 useOnePt("/ALICE_2010_S8624100/d11-x01-y01", "900", "0" )
 useOnePt("/ALICE_2010_S8624100/d12-x01-y01", "900", "0" )
 useOnePt("/ALICE_2010_S8624100/d13-x01-y01", "900", "0" )
 useOnePt("/ALICE_2010_S8624100/d17-x01-y01","2360", "0" )
 useOnePt("/ALICE_2010_S8624100/d18-x01-y01","2360", "0" )
 useOnePt("/ALICE_2010_S8624100/d19-x01-y01","2360", "0" )
 
 logging.info("Processing ALICE_2010_S8625980")
 useOnePt("/ALICE_2010_S8625980/d03-x01-y01", "7000", "0" )
 useOnePt("/ALICE_2010_S8625980/d04-x01-y01",  "900", "0" )
 useOnePt("/ALICE_2010_S8625980/d05-x01-y01", "2360", "0" )
 useOnePt("/ALICE_2010_S8625980/d06-x01-y01", "7000", "0" )
 
 logging.info("Processing ATLAS_2010_S8918562")
 useOnePt("/ATLAS_2010_S8918562/d01-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d02-x01-y01", "2360", "0" )
 useOnePt("/ATLAS_2010_S8918562/d03-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d04-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d05-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d06-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d07-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d08-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d09-x01-y01", "2360", "0" )
 useOnePt("/ATLAS_2010_S8918562/d10-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d11-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d12-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d13-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d14-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d15-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d16-x01-y01", "2360", "0" )
 useOnePt("/ATLAS_2010_S8918562/d17-x01-y01", "7000", "0" )
 
 
 useOnePt("/ATLAS_2010_S8918562/d18-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d19-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d20-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d21-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d22-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d23-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d24-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d25-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d26-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d27-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d28-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d29-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d30-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d31-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d32-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d33-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d34-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d35-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d36-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d37-x01-y01", "7000", "0" )
 useOnePt("/ATLAS_2010_S8918562/d38-x01-y01",  "900", "0" )
 useOnePt("/ATLAS_2010_S8918562/d39-x01-y01", "7000", "0" )
 
 
 
 logging.info("Processing ATLAS_2011_S8971293")
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y03", "7000", "210" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y04", "7000", "260" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y05", "7000", "260" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y06", "7000", "400" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y07", "7000", "400" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y08", "7000", "600" )
 useOnePt("/ATLAS_2011_S8971293/d01-x01-y09", "7000", "600" )
 logging.info("Processing ATLAS_2011_S8924791")
 useOnePt("/ATLAS_2011_S8924791/d01-x01-y01", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x01-y02", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x02-y01", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x02-y02", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x03-y01", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x03-y02", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x04-y01", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x04-y02", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x05-y01", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x05-y02", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x06-y01", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d01-x06-y02", "7000", "30" )
 useOnePt("/ATLAS_2011_S8924791/d02-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x01-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x02-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x02-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x03-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x03-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x04-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x04-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x05-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x05-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x06-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d02-x06-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x01-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x02-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x02-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x03-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x03-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x04-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x04-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x05-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x05-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x06-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d03-x06-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S8924791/d04-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x01-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x02-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x02-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x03-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x03-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x04-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x04-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x05-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x05-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x06-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d04-x06-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S8924791/d05-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x02-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x02-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x03-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x03-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x04-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x04-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x05-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x05-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x06-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d05-x06-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x02-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x02-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x03-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x03-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x04-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x04-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x05-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x05-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x06-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d06-x06-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S8924791/d07-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x01-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x02-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x02-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x03-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x03-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x04-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x04-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x05-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x05-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x06-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d07-x06-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S8924791/d08-x01-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x01-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x02-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x02-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x03-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x03-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x04-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x04-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x05-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x05-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x06-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d08-x06-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x01-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x01-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x02-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x02-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x03-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x03-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x04-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x04-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x05-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x05-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x06-y01", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d09-x06-y02", "7000", "260" )
 useOnePt("/ATLAS_2011_S8924791/d10-x01-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x01-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x02-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x02-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x03-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x03-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x04-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x04-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x05-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x05-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x06-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d10-x06-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x01-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x01-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x02-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x02-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x03-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x03-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x04-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x04-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x05-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x05-y02", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x06-y01", "7000", "400" )
 useOnePt("/ATLAS_2011_S8924791/d11-x06-y02", "7000", "400" )
 logging.info("Processing ATLAS_2010_S8817804")
 mergeByPt("/ATLAS_2010_S8817804/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d03-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d04-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d05-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d06-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d07-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d08-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d09-x01-y01", "7000")
 mergeByPt("/ATLAS_2010_S8817804/d10-x01-y01", "7000")
 
 mergeByMass("/ATLAS_2010_S8817804/d11-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d12-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d13-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d14-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d15-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d16-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d17-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d18-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d19-x01-y01", "7000")
 mergeByMass("/ATLAS_2010_S8817804/d20-x01-y01", "7000")
 
 useOneMass("/ATLAS_2010_S8817804/d21-x01-y01", "7000", "300" )
 useOneMass("/ATLAS_2010_S8817804/d22-x01-y01", "7000", "300" )
 useOneMass("/ATLAS_2010_S8817804/d23-x01-y01", "7000", "800" )
 useOneMass("/ATLAS_2010_S8817804/d24-x01-y01", "7000", "300" )
 useOneMass("/ATLAS_2010_S8817804/d25-x01-y01", "7000", "300" )
 useOneMass("/ATLAS_2010_S8817804/d26-x01-y01", "7000", "800" )
 
 
 logging.info("Processing ATLAS_2011_I930220")
 mergeByPt("/ATLAS_2011_I930220/d01-x01-y01",  "7000" )
 mergeByPt("/ATLAS_2011_I930220/d02-x01-y01",  "7000" )
 mergeByPt("/ATLAS_2011_I930220/d03-x01-y01",  "7000" )
 mergeByPt("/ATLAS_2011_I930220/d04-x01-y01",  "7000" )
 mergeByPt("/ATLAS_2011_I930220/d05-x01-y01",  "7000" )
 mergeByPt("/ATLAS_2011_I930220/d06-x01-y01",  "7000" )
 mergeByMass("/ATLAS_2011_I930220/d07-x01-y01", "7000")
 useOneMass("/ATLAS_2011_I930220/d08-x01-y01", "7000", "110" )
 useOneMass("/ATLAS_2011_I930220/d09-x01-y01", "7000", "110" )
 useOneMass("/ATLAS_2011_I930220/d10-x01-y01", "7000", "370" )
 
 logging.info("Processing ATLAS_2012_I1082936")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y02", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y03", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y04", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y05", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y06", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d01-x01-y07", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y02", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y03", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y04", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y05", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y06", "7000")
 mergeByPt("/ATLAS_2012_I1082936/d02-x01-y07", "7000")
 
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y01", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y02", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y03", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y04", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y05", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y06", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y07", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y08", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d03-x01-y09", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y01", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y02", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y03", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y04", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y05", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y06", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y07", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y08", "7000", 1000.)
 mergeByMass("/ATLAS_2012_I1082936/d04-x01-y09", "7000", 1000.)
 
 
 logging.info("Processing CMS_2011_S8968497")
 
 useOneMass("/CMS_2011_S8968497/d01-x01-y01", "7000", "2000" )
 useOneMass("/CMS_2011_S8968497/d02-x01-y01", "7000", "1200" )
 useOneMass("/CMS_2011_S8968497/d03-x01-y01", "7000", "1200" )
 useOneMass("/CMS_2011_S8968497/d04-x01-y01", "7000", "800" )
 useOneMass("/CMS_2011_S8968497/d05-x01-y01", "7000", "800" )
 useOneMass("/CMS_2011_S8968497/d06-x01-y01", "7000", "300" )
 useOneMass("/CMS_2011_S8968497/d07-x01-y01", "7000", "300" )
 useOneMass("/CMS_2011_S8968497/d08-x01-y01", "7000", "300" )
 useOneMass("/CMS_2011_S8968497/d09-x01-y01", "7000", "100" )
 
 
 logging.info("Processing ATLAS_2011_S9126244")
 mergeByPt("/ATLAS_2011_S9126244/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d01-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d02-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d03-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d03-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d04-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d04-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d05-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d05-x01-y02", "7000")
 
 
 useOnePt("/ATLAS_2011_S9126244/d06-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d06-x01-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d07-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d07-x01-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d08-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d08-x01-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d09-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d09-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d10-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d10-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d11-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d11-x01-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d12-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d12-x01-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d13-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d13-x01-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d14-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d14-x01-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d15-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d15-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d16-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d16-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d17-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d17-x01-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d18-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d18-x01-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d19-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d20-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d21-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d22-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d23-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d24-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d25-x01-y01", "7000", "210" )
 mergeByPt("/ATLAS_2011_S9126244/d26-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d26-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d27-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d27-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d28-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d28-x01-y02", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d29-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9126244/d29-x01-y02", "7000")
 useOnePt("/ATLAS_2011_S9126244/d30-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d31-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d32-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d33-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d34-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d35-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d36-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d37-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d37-x01-y02", "7000", "40" )
 useOnePt("/ATLAS_2011_S9126244/d38-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d38-x01-y02", "7000", "80" )
 useOnePt("/ATLAS_2011_S9126244/d39-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d39-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d40-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d40-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d41-x01-y01", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d41-x01-y02", "7000", "110" )
 useOnePt("/ATLAS_2011_S9126244/d42-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d42-x01-y02", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d43-x01-y01", "7000", "210" )
 useOnePt("/ATLAS_2011_S9126244/d43-x01-y02", "7000", "210" )
 
 # CMS_2011_S9120041 UE analysis
 logging.info("Processing CMS_2011_S9120041")
 mergeByPt("/CMS_2011_S9120041/d01-x01-y01", "7000")
 mergeByPt("/CMS_2011_S9120041/d02-x01-y01", "7000")
 if(opts.ue) :
     useOnePt("/CMS_2011_S9120041/d03-x01-y01",  "900", "0" )
     useOnePt("/CMS_2011_S9120041/d04-x01-y01",  "900", "0" )
     useOnePt("/CMS_2011_S9120041/d05-x01-y01", "7000", "0" )
     useOnePt("/CMS_2011_S9120041/d06-x01-y01", "7000", "0" )
     useOnePt("/CMS_2011_S9120041/d07-x01-y01", "7000", "0" )
     useOnePt("/CMS_2011_S9120041/d11-x01-y01",  "900", "0" )
     useOnePt("/CMS_2011_S9120041/d12-x01-y01",  "900", "0" )
     useOnePt("/CMS_2011_S9120041/d13-x01-y01",  "900", "0" )
     useOnePt("/CMS_2011_S9120041/d08-x01-y01", "7000", "20" )
     useOnePt("/CMS_2011_S9120041/d09-x01-y01", "7000", "20" )
     useOnePt("/CMS_2011_S9120041/d10-x01-y01", "7000", "20" )
 else :
     useOnePt("/CMS_2011_S9120041/d08-x01-y01", "7000", "10" )
     useOnePt("/CMS_2011_S9120041/d09-x01-y01", "7000", "10" )
     useOnePt("/CMS_2011_S9120041/d10-x01-y01", "7000", "10" )
 
 # CMS dijet decorrelation
 logging.info("Processing CMS_2011_S8950903")
 useOnePt("/CMS_2011_S8950903/d01-x01-y01", "7000", "80" )
 useOnePt("/CMS_2011_S8950903/d02-x01-y01", "7000", "110" )
 useOnePt("/CMS_2011_S8950903/d03-x01-y01", "7000", "110" )
 useOnePt("/CMS_2011_S8950903/d04-x01-y01", "7000", "210" )
 useOnePt("/CMS_2011_S8950903/d05-x01-y01", "7000", "260" )
 
 # CMS jet cross section
 logging.info("Processing CMS_2011_S9086218")
 mergeByPt("/CMS_2011_S9086218/d01-x01-y01", "7000")
 mergeByPt("/CMS_2011_S9086218/d02-x01-y01", "7000")
 mergeByPt("/CMS_2011_S9086218/d03-x01-y01", "7000")
 mergeByPt("/CMS_2011_S9086218/d04-x01-y01", "7000")
 mergeByPt("/CMS_2011_S9086218/d05-x01-y01", "7000")
 mergeByPt("/CMS_2011_S9086218/d06-x01-y01", "7000")
 
 # CMS 2/3 jet cross section ratio
 logging.info("Processing CMS_2011_S9086218")
 mergeByPt("/CMS_2011_S9088458/d01-x01-y01", "7000",500.)
 
 # ATLAS track jet
 logging.info("Processing ATLAS_2011_I919017")
 for d in range(1,3) :
     for y in range(1,5) :
         mergeByPt("/ATLAS_2011_I919017/d0%s-x01-y0%s" % (d,y), "7000")
         if( opts.ue) :
             for x in range(2,6) :
                 for y in ["01","02","06","07","11","12","16","17","21","22"] :
                     useOnePt("/ATLAS_2011_I919017/d01-x0%s-y%s" % (x,y),  "7000",  "0" )
                 for y in ["03","04","08","09","13","14","18","19","23","24"] :
                     useOnePt("/ATLAS_2011_I919017/d01-x0%s-y%s" % (x,y),  "7000",  "4" )
             for y in range(5,30,5) :
                 if(y < 10) :
                     useOnePt("/ATLAS_2011_I919017/d01-x0%s-y0%s" % (x,y) ,  "7000", "20" )
                 else :
                     useOnePt("/ATLAS_2011_I919017/d01-x0%s-y%s"  % (x,y) ,  "7000", "20" )
         else :
             for x in range(2,6) :
                 for y in range(5,30,5) :
                     if(y < 10) :
                         useOnePt("/ATLAS_2011_I919017/d01-x0%s-y0%s" % (x,y) ,  "7000", "10" )
                     else :
                         useOnePt("/ATLAS_2011_I919017/d01-x0%s-y%s"  % (x,y) ,  "7000", "10" )
 
 logging.info("Processing ATLAS_2011_I926145")
 mergeByPt("/ATLAS_2011_I926145/d01-x01-y01", "7000",1.5)
 mergeByPt("/ATLAS_2011_I926145/d02-x01-y01", "7000",1.5)
 mergeByPt("/ATLAS_2011_I926145/d03-x01-y01", "7000",1.5)
 
 logging.info("Processing CMS_2011_S8941262")
 useOnePt("/CMS_2011_S8941262/d01-x01-y01",  "7000", "10" )
 useOnePt("/CMS_2011_S8941262/d03-x01-y01",  "7000", "10" )
 mergeByPt("/CMS_2011_S8941262/d02-x01-y01", "7000",1.5)
 
 logging.info("Processing CMS_2011_S8973270")
 useOnePt("/CMS_2011_S8973270/d01-x01-y01",  "7000", "70" )
 useOnePt("/CMS_2011_S8973270/d02-x01-y01",  "7000", "100" )
 useOnePt("/CMS_2011_S8973270/d03-x01-y01",  "7000", "130" )
 useOnePt("/CMS_2011_S8973270/d04-x01-y01",  "7000", "70" )
 useOnePt("/CMS_2011_S8973270/d05-x01-y01",  "7000", "100" )
 useOnePt("/CMS_2011_S8973270/d06-x01-y01",  "7000", "130" )
 
 logging.info("Processing ATLAS_2012_I1082009")
 useOnePt("/ATLAS_2012_I1082009/d08-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2012_I1082009/d09-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2012_I1082009/d10-x01-y01", "7000", "40" )
 useOnePt("/ATLAS_2012_I1082009/d11-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2012_I1082009/d12-x01-y01", "7000", "80" )
 useOnePt("/ATLAS_2012_I1082009/d13-x01-y01", "7000", "40" )
 
 logging.info("Processing ATLAS_2012_I1118269")
 mergeByPt("/ATLAS_2012_I1118269/d01-x01-y01", "7000")
 useOnePt("/ATLAS_2012_I1118269/d02-x01-y01", "7000", "10" )
 
 logging.info("Processing ATLAS_2012_I1188891")
 mergeByPt("/ATLAS_2012_I1188891/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1188891/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1188891/d03-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1188891/d04-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1188891/d05-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1188891/d06-x01-y01", "7000")
 
 logging.info("Processing CMS_2012_I1087342")
 mergeByPt("/CMS_2012_I1087342/d01-x01-y01", "7000")
 mergeByPt("/CMS_2012_I1087342/d02-x01-y01", "7000")
 mergeByPt("/CMS_2012_I1087342/d03-x01-y01", "7000")
 logging.info("Processing CMS_2012_PAS_QCD_11_010")
 mergeByPt("/CMS_2012_PAS_QCD_11_010/d01-x01-y01", "7000")
 mergeByPt("/CMS_2012_PAS_QCD_11_010/d02-x01-y01", "7000")
 mergeByPt("/CMS_2012_PAS_QCD_11_010/d03-x01-y01", "7000")
 mergeByPt("/CMS_2012_PAS_QCD_11_010/d04-x01-y01", "7000")
 
 logging.info("Processing ATLAS_2011_S9035664")
 mergeByPt("/ATLAS_2011_S9035664/d11-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d12-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d13-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d14-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d15-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d16-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d17-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d18-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d20-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d21-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d22-x01-y01", "7000")
 mergeByPt("/ATLAS_2011_S9035664/d23-x01-y01", "7000")
 
 logging.info("Processing ATLAS_2012_I1125575")
 mergeByPt("/ATLAS_2012_I1125575/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x01-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x02-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x02-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x03-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x03-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x04-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x04-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x05-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d01-x05-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x01-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x02-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x02-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x03-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x03-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x04-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x04-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x05-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d02-x05-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x01-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x01-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x02-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x02-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x03-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x03-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x04-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x04-y02", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x05-y01", "7000")
 mergeByPt("/ATLAS_2012_I1125575/d03-x05-y02", "7000")
 for d in range(4,7) :
     for x in range(1,6) :
         if(opts.ue) :
             for y in range(1,9) :
                 useOnePt("/ATLAS_2012_I1125575/d0%s-x0%s-y0%s" % (d,x,y),  "7000", "0" )
             for y in ["09","10","11","12","13","14","15","16"] :
                 useOnePt("/ATLAS_2012_I1125575/d0%s-x0%s-y%s" % (d,x,y),  "7000", "0" )
             for y in range(17,19) :
                 useOnePt("/ATLAS_2012_I1125575/d0%s-x0%s-y%s" % (d,x,y),  "7000", "20" )
         else :
             for y in range(17,19) :
                 useOnePt("/ATLAS_2012_I1125575/d0%s-x0%s-y%s" % (d,x,y),  "7000", "10" )
         for y in range(19,21) :
             useOnePt("/ATLAS_2012_I1125575/d0%s-x0%s-y%s" % (d,x,y),  "7000", "40" )
 
 # ATLAS_2012_I1094564
 useOnePt("/ATLAS_2012_I1094564/d01-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d02-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d03-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d04-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d05-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d06-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d07-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d08-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d09-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d10-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d11-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d12-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d13-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d14-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d15-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d16-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d17-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d18-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d19-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d20-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d21-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d22-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d23-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d24-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d25-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d26-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d27-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d28-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d29-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d30-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d31-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d32-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d33-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2012_I1094564/d34-x01-y01",  "7000", "260" )
 useOnePt("/ATLAS_2012_I1094564/d35-x01-y01",  "7000", "400" )
 useOnePt("/ATLAS_2012_I1094564/d36-x01-y01",  "7000", "400" )
 
 logging.info("Processing CMS_2013_I1224539_DIJET")
 useOnePt("/CMS_2013_I1224539_DIJET/d01-x01-y01",  "7000", "210" )
 useOnePt("/CMS_2013_I1224539_DIJET/d02-x01-y01",  "7000", "260" )
 useOnePt("/CMS_2013_I1224539_DIJET/d03-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d04-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d05-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d06-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d07-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d08-x01-y01",  "7000", "210" )
 useOnePt("/CMS_2013_I1224539_DIJET/d09-x01-y01",  "7000", "260" )
 useOnePt("/CMS_2013_I1224539_DIJET/d10-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d11-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d12-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d13-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d14-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d15-x01-y01",  "7000", "210" )
 useOnePt("/CMS_2013_I1224539_DIJET/d16-x01-y01",  "7000", "260" )
 useOnePt("/CMS_2013_I1224539_DIJET/d17-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d18-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d19-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d20-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d21-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d22-x01-y01",  "7000", "210" )
 useOnePt("/CMS_2013_I1224539_DIJET/d23-x01-y01",  "7000", "260" )
 useOnePt("/CMS_2013_I1224539_DIJET/d24-x01-y01",  "7000", "400" )
 useOnePt("/CMS_2013_I1224539_DIJET/d25-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d26-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d27-x01-y01",  "7000", "600" )
 useOnePt("/CMS_2013_I1224539_DIJET/d28-x01-y01",  "7000", "600" )
 
 useOnePt("/CMS_2013_I1273574/d01-x01-y01",  "7000", "80" )
 mergeByPt("/CMS_2013_I1273574/d02-x01-y01", "7000",1.)
 useOnePt("/CMS_2013_I1273574/d03-x01-y01",  "7000", "80" )
 useOnePt("/CMS_2013_I1273574/d04-x01-y01",  "7000", "80" )
 useOnePt("/CMS_2013_I1273574/d05-x01-y01",  "7000", "80" )
 useOnePt("/CMS_2013_I1273574/d06-x01-y01",  "7000", "80" )
 mergeByPt("/CMS_2013_I1273574/d07-x01-y01", "7000",1.)
 useOnePt("/CMS_2013_I1273574/d08-x01-y01",  "7000", "80" )
 mergeByPt("/CMS_2013_I1273574/d09-x01-y01", "7000",1.)
 useOnePt("/CMS_2013_I1273574/d10-x01-y01",  "7000", "80" )
 mergeByPt("/CMS_2013_I1273574/d11-x01-y01", "7000",1.)
 
 useOnePt("/CMS_2013_I1261026/d01-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d02-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d03-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d04-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d05-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d06-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d07-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d08-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d09-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d10-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d11-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d12-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d13-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d14-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d15-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d16-x01-y01",  "7000", "0" )
 useOnePt("/CMS_2013_I1261026/d17-x01-y01",  "7000", "0" )
 
 
 useOneMass("/CMS_2012_I1090423/d01-x01-y01", "7000", "2000" )
 useOneMass("/CMS_2012_I1090423/d02-x01-y01", "7000", "2000" )
 useOneMass("/CMS_2012_I1090423/d03-x01-y01", "7000", "1200" )
 useOneMass("/CMS_2012_I1090423/d04-x01-y01", "7000", "1200" )
 useOneMass("/CMS_2012_I1090423/d05-x01-y01", "7000", "1200" )
 useOneMass("/CMS_2012_I1090423/d06-x01-y01", "7000", "800" )
 useOneMass("/CMS_2012_I1090423/d07-x01-y01", "7000", "800" )
 useOneMass("/CMS_2012_I1090423/d08-x01-y01", "7000", "300" )
 useOneMass("/CMS_2012_I1090423/d09-x01-y01", "7000", "300" )
 
 logging.info("Processing ATLAS_2014_I1298811")
 mergeByPt("/ATLAS_2014_I1298811/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d01-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d02-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d03-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d03-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d04-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d04-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d05-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d05-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d06-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d06-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d07-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d07-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d08-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d08-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d09-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d09-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d10-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1298811/d10-x01-y02", "7000")
 useOnePt("/ATLAS_2014_I1298811/d11-x01-y01",  "7000", "0" )
 useOnePt("/ATLAS_2014_I1298811/d12-x01-y01",  "7000", "0" )
 
 useOnePt("/ATLAS_2014_I1298811/d13-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d13-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d14-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d14-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d15-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d15-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d25-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d25-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d26-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d26-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d27-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d27-x01-y02",  "7000", "4" )
 
 useOnePt("/ATLAS_2014_I1298811/d16-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d16-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d17-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d17-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d18-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d18-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d28-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d28-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d29-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d29-x01-y02",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d30-x01-y01",  "7000", "4" )
 useOnePt("/ATLAS_2014_I1298811/d30-x01-y02",  "7000", "4" )
 
 useOnePt("/ATLAS_2014_I1298811/d19-x01-y01",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d19-x01-y02",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d20-x01-y01",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d20-x01-y02",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d21-x01-y01",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d21-x01-y02",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d31-x01-y01",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d31-x01-y02",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d32-x01-y01",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d32-x01-y02",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d33-x01-y01",  "7000", "40" )
 useOnePt("/ATLAS_2014_I1298811/d33-x01-y02",  "7000", "40" )
 
 useOnePt("/ATLAS_2014_I1298811/d22-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d22-x01-y02",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d23-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d23-x01-y02",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d24-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d24-x01-y02",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d34-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d34-x01-y02",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d35-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d35-x01-y02",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d36-x01-y01",  "7000", "210" )
 useOnePt("/ATLAS_2014_I1298811/d36-x01-y02",  "7000", "210" )
 
 
 logging.info("Processing ATLAS_2014_I1268975")
 mergeByMass("/ATLAS_2014_I1268975/d01-x01-y01", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d01-x01-y02", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d01-x01-y03", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d01-x01-y04", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d01-x01-y05", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d01-x01-y06", "7000", 1000.)
 
 mergeByMass("/ATLAS_2014_I1268975/d02-x01-y01", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d02-x01-y02", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d02-x01-y03", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d02-x01-y04", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d02-x01-y05", "7000", 1000.)
 mergeByMass("/ATLAS_2014_I1268975/d02-x01-y06", "7000", 1000.)
 
 logging.info("Processing ATLAS_2014_I1307243")
 useOnePt( "/ATLAS_2014_I1307243/d01-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d02-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d03-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d04-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d05-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d06-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d07-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d08-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d09-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d10-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d11-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d12-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d13-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d14-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d15-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d16-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d17-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d18-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d19-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d20-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d21-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d22-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d23-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d24-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d25-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d26-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d27-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d28-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d29-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d30-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d31-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d32-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d33-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d34-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d35-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d36-x01-y01",  "7000", "80" )
 useOnePt( "/ATLAS_2014_I1307243/d37-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d38-x01-y01", "7000")
 useOnePt( "/ATLAS_2014_I1307243/d39-x01-y01",  "7000", "80" )
 mergeByPt("/ATLAS_2014_I1307243/d40-x01-y01", "7000")
 
 
 logging.info("Processing ATLAS_2014_I1325553")
 mergeByPt("/ATLAS_2014_I1325553/d01-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d01-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d01-x01-y03", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d01-x01-y04", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d01-x01-y05", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d01-x01-y06", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d02-x01-y01", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d02-x01-y02", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d02-x01-y03", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d02-x01-y04", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d02-x01-y05", "7000")
 mergeByPt("/ATLAS_2014_I1325553/d02-x01-y06", "7000")
 
 logging.info("Processing CMS_2013_I1208923")
 for i in range(1,6) :
     mergeByPt  ("/CMS_2013_I1208923/d01-x01-y0%s" % i, "7000")
     mergeByMass("/CMS_2013_I1208923/d02-x01-y0%s" % i, "7000", 1.)
 
 logging.info("Processing CMS_2014_I1298810")
 for i in range(1,19) :
     if(i<10) :
         mergeByPt("/CMS_2014_I1298810/d0"+str(i)+"-x01-y01", "7000")
     else :
         mergeByPt("/CMS_2014_I1298810/d"+str(i)+"-x01-y01", "7000")
 
 # Choose output file
 name = args[0]+"-Jets.yoda"
 yoda.writeYODA(outhistos,name)
 sys.exit(0)
diff --git a/Tests/python/merge-TVT-Photon b/Tests/python/merge-TVT-Photon
old mode 100644
new mode 100755
diff --git a/src/defaults/Shower.in b/src/defaults/Shower.in
--- a/src/defaults/Shower.in
+++ b/src/defaults/Shower.in
@@ -1,295 +1,296 @@
 # -*- ThePEG-repository -*-
 
 ############################################################
 # Setup of default parton shower
 #
 # Useful switches for users are marked near the top of 
 # this file.
 #
 # Don't edit this file directly, but reset the switches
 # in your own input files!
 ############################################################
 library HwMPI.so
 library HwShower.so
 library HwMatching.so
 
 mkdir /Herwig/Shower
 cd /Herwig/Shower
 
 create Herwig::QTildeShowerHandler ShowerHandler
 newdef ShowerHandler:MPIHandler /Herwig/UnderlyingEvent/MPIHandler
 newdef ShowerHandler:RemDecayer /Herwig/Partons/RemnantDecayer
 # use LO PDFs for Shower, can be changed later
 newdef ShowerHandler:PDFA /Herwig/Partons/ShowerLOPDF
 newdef ShowerHandler:PDFB /Herwig/Partons/ShowerLOPDF
 newdef ShowerHandler:PDFARemnant /Herwig/Partons/RemnantPDF
 newdef ShowerHandler:PDFBRemnant /Herwig/Partons/RemnantPDF
 
 #####################################
 # initial setup, don't change these!
 #####################################
 create Herwig::SplittingGenerator SplittingGenerator
 create Herwig::ShowerAlphaQCD AlphaQCD
 create Herwig::ShowerAlphaQED AlphaQED
 create Herwig::QTildeModel ShowerModel
 create Herwig::QTildeFinder PartnerFinder
 newdef PartnerFinder:PartnerMethod 1
 newdef PartnerFinder:ScaleChoice 1
 create Herwig::QTildeReconstructor KinematicsReconstructor
 newdef KinematicsReconstructor:ReconstructionOption Colour3
 newdef KinematicsReconstructor:InitialStateReconOption SofterFraction
 newdef KinematicsReconstructor:InitialInitialBoostOption LongTransBoost
 
 newdef /Herwig/Partons/RemnantDecayer:AlphaS  AlphaQCD
 newdef /Herwig/Partons/RemnantDecayer:AlphaEM AlphaQED
 
 newdef ShowerModel:PartnerFinder PartnerFinder
 newdef ShowerModel:KinematicsReconstructor KinematicsReconstructor
 newdef ShowerHandler:ShowerModel ShowerModel
 newdef ShowerHandler:SplittingGenerator SplittingGenerator
 newdef ShowerHandler:SpinCorrelations Yes
 newdef ShowerHandler:SoftCorrelations Singular
 
 ##################################################################
 # Intrinsic pT
 #
 # Recommended: 
 # 1.9 GeV for Tevatron W/Z production.
 # 2.1 GeV for LHC W/Z production at 10 TeV
 # 2.2 GeV for LHC W/Z production at 14 TeV
 #
 # Set all parameters to 0 to disable
 ##################################################################
 newdef ShowerHandler:IntrinsicPtGaussian 1.3*GeV
 newdef ShowerHandler:IntrinsicPtBeta  	0
 newdef ShowerHandler:IntrinsicPtGamma 	0*GeV
 newdef ShowerHandler:IntrinsicPtIptmax   0*GeV
 #############################################################
 # Set up truncated shower handler.
 #############################################################
 
 create Herwig::PowhegShowerHandler PowhegShowerHandler
 set PowhegShowerHandler:MPIHandler /Herwig/UnderlyingEvent/MPIHandler
 set PowhegShowerHandler:RemDecayer /Herwig/Partons/RemnantDecayer
 newdef PowhegShowerHandler:PDFA /Herwig/Partons/ShowerLOPDF
 newdef PowhegShowerHandler:PDFB /Herwig/Partons/ShowerLOPDF
 newdef PowhegShowerHandler:PDFARemnant /Herwig/Partons/RemnantPDF
 newdef PowhegShowerHandler:PDFBRemnant /Herwig/Partons/RemnantPDF
 newdef PowhegShowerHandler:MPIHandler /Herwig/UnderlyingEvent/MPIHandler
 newdef PowhegShowerHandler:RemDecayer /Herwig/Partons/RemnantDecayer
 newdef PowhegShowerHandler:PDFA /Herwig/Partons/ShowerLOPDF
 newdef PowhegShowerHandler:PDFB /Herwig/Partons/ShowerLOPDF
 newdef PowhegShowerHandler:PDFARemnant /Herwig/Partons/RemnantPDF
 newdef PowhegShowerHandler:PDFBRemnant /Herwig/Partons/RemnantPDF
 newdef PowhegShowerHandler:ShowerModel ShowerModel
 newdef PowhegShowerHandler:SplittingGenerator SplittingGenerator
 newdef PowhegShowerHandler:Interactions QCDandQED
 newdef PowhegShowerHandler:SpinCorrelations Yes
 newdef PowhegShowerHandler:SoftCorrelations Singular
 newdef PowhegShowerHandler:IntrinsicPtGaussian 1.3*GeV
 newdef PowhegShowerHandler:IntrinsicPtBeta  	0
 newdef PowhegShowerHandler:IntrinsicPtGamma 	0*GeV
 newdef PowhegShowerHandler:IntrinsicPtIptmax   0*GeV
+newdef PowhegShowerHandler:ReconstructionOption OffShell3
 
 #############################################################
 # End of interesting user servicable section.
 #
 # Anything that follows below should only be touched if you 
 # know what you're doing. 
 #
 # Really.
 #############################################################
 #
 # a few default values
 newdef ShowerHandler:MECorrMode 1
 newdef ShowerHandler:ReconstructionOption OffShell3
 newdef AlphaQCD:ScaleFactor 1.0
 newdef AlphaQCD:NPAlphaS 2
 newdef AlphaQCD:Qmin 0.935
 newdef AlphaQCD:NumberOfLoops 2
 newdef AlphaQCD:InputOption 1
 newdef AlphaQCD:AlphaMZ 0.134
 #
 #
 # Lets set up all the splittings
 create Herwig::HalfHalfOneSplitFn QtoQGammaSplitFn
 set QtoQGammaSplitFn:InteractionType QED
 set QtoQGammaSplitFn:ColourStructure ChargedChargedNeutral
 set QtoQGammaSplitFn:AngularOrdered Yes
 
 create Herwig::HalfHalfOneSplitFn QtoQGSplitFn
 newdef QtoQGSplitFn:InteractionType QCD
 newdef QtoQGSplitFn:ColourStructure TripletTripletOctet
 set QtoQGSplitFn:AngularOrdered Yes
 
 create Herwig::OneOneOneSplitFn GtoGGSplitFn
 newdef GtoGGSplitFn:InteractionType QCD
 newdef GtoGGSplitFn:ColourStructure OctetOctetOctet
 set GtoGGSplitFn:AngularOrdered Yes
 
 create Herwig::OneHalfHalfSplitFn GtoQQbarSplitFn
 newdef GtoQQbarSplitFn:InteractionType QCD
 newdef GtoQQbarSplitFn:ColourStructure OctetTripletTriplet
 set GtoQQbarSplitFn:AngularOrdered No
 
 create Herwig::OneHalfHalfSplitFn GammatoQQbarSplitFn
 newdef GammatoQQbarSplitFn:InteractionType QED
 newdef GammatoQQbarSplitFn:ColourStructure NeutralChargedCharged
 set GammatoQQbarSplitFn:AngularOrdered No
 
 create Herwig::HalfOneHalfSplitFn QtoGQSplitFn
 newdef QtoGQSplitFn:InteractionType QCD
 newdef QtoGQSplitFn:ColourStructure TripletOctetTriplet
 set QtoGQSplitFn:AngularOrdered Yes
 
 create Herwig::HalfOneHalfSplitFn QtoGammaQSplitFn
 newdef QtoGammaQSplitFn:InteractionType QED
 newdef QtoGammaQSplitFn:ColourStructure ChargedNeutralCharged
 set QtoGammaQSplitFn:AngularOrdered Yes
 #
 # Now the Sudakovs
 create Herwig::QTildeSudakov SudakovCommon
 newdef SudakovCommon:Alpha AlphaQCD
 newdef SudakovCommon:cutoffKinScale 0.0*GeV
 newdef SudakovCommon:PDFmax 1.0
 newdef SudakovCommon:CutOffOption pT
 newdef SudakovCommon:pTmin 1.67*GeV
 
 cp SudakovCommon QtoQGSudakov
 newdef QtoQGSudakov:SplittingFunction QtoQGSplitFn
 newdef QtoQGSudakov:PDFmax 1.9
 
 cp SudakovCommon QtoQGammaSudakov
 set QtoQGammaSudakov:SplittingFunction QtoQGammaSplitFn
 set QtoQGammaSudakov:Alpha AlphaQED
 set QtoQGammaSudakov:PDFmax 1.9
 
 cp QtoQGammaSudakov LtoLGammaSudakov
 
 cp SudakovCommon GtoGGSudakov
 newdef GtoGGSudakov:SplittingFunction GtoGGSplitFn
 newdef GtoGGSudakov:PDFmax 2.0
 
 cp SudakovCommon GtoQQbarSudakov
 newdef GtoQQbarSudakov:SplittingFunction GtoQQbarSplitFn
 newdef GtoQQbarSudakov:PDFmax 120.0
 
 cp SudakovCommon GammatoQQbarSudakov
 newdef GammatoQQbarSudakov:SplittingFunction GammatoQQbarSplitFn
 newdef GammatoQQbarSudakov:PDFmax 120.0
 
 cp SudakovCommon GtobbbarSudakov
 newdef GtobbbarSudakov:SplittingFunction GtoQQbarSplitFn
 newdef GtobbbarSudakov:PDFmax 40000.0
 
 cp SudakovCommon GtoccbarSudakov
 newdef GtoccbarSudakov:SplittingFunction GtoQQbarSplitFn
 newdef GtoccbarSudakov:PDFmax 2000.0
 
 cp SudakovCommon QtoGQSudakov
 newdef QtoGQSudakov:SplittingFunction QtoGQSplitFn
 
 cp SudakovCommon QtoGammaQSudakov
 newdef QtoGammaQSudakov:SplittingFunction QtoGammaQSplitFn
 
 cp SudakovCommon utoGuSudakov
 newdef utoGuSudakov:SplittingFunction QtoGQSplitFn
 newdef utoGuSudakov:PDFFactor OverOneMinusZ
 newdef utoGuSudakov:PDFmax 5.0
 
 cp SudakovCommon dtoGdSudakov
 newdef dtoGdSudakov:SplittingFunction QtoGQSplitFn
 newdef dtoGdSudakov:PDFFactor OverOneMinusZ
 
 
 #
 # Now add the final splittings
 #
 do SplittingGenerator:AddFinalSplitting u->u,g; QtoQGSudakov
 do SplittingGenerator:AddFinalSplitting d->d,g; QtoQGSudakov
 do SplittingGenerator:AddFinalSplitting s->s,g; QtoQGSudakov
 do SplittingGenerator:AddFinalSplitting c->c,g; QtoQGSudakov
 do SplittingGenerator:AddFinalSplitting b->b,g; QtoQGSudakov
 do SplittingGenerator:AddFinalSplitting t->t,g; QtoQGSudakov
 #
 do SplittingGenerator:AddFinalSplitting g->g,g; GtoGGSudakov
 #
 do SplittingGenerator:AddFinalSplitting g->u,ubar; GtoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting g->d,dbar; GtoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting g->s,sbar; GtoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting g->c,cbar; GtoccbarSudakov
 do SplittingGenerator:AddFinalSplitting g->b,bbar; GtobbbarSudakov
 do SplittingGenerator:AddFinalSplitting g->t,tbar; GtoQQbarSudakov
 #
 do SplittingGenerator:AddFinalSplitting gamma->u,ubar; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->d,dbar; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->s,sbar; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->c,cbar; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->b,bbar; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->t,tbar; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->e-,e+; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->mu-,mu+; GammatoQQbarSudakov
 do SplittingGenerator:AddFinalSplitting gamma->tau-,tau+; GammatoQQbarSudakov
 #
 do SplittingGenerator:AddFinalSplitting u->u,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddFinalSplitting d->d,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddFinalSplitting s->s,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddFinalSplitting c->c,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddFinalSplitting b->b,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddFinalSplitting t->t,gamma; QtoQGammaSudakov
 
 do SplittingGenerator:AddFinalSplitting e-->e-,gamma; LtoLGammaSudakov
 do SplittingGenerator:AddFinalSplitting mu-->mu-,gamma; LtoLGammaSudakov
 do SplittingGenerator:AddFinalSplitting tau-->tau-,gamma; LtoLGammaSudakov
 #
 # Now lets add the initial splittings. Remember the form a->b,c; means
 # that particle a is the particle given and we backward branch to
 # particle b which is initial state and particle c which is final state
 #
 do SplittingGenerator:AddInitialSplitting u->u,g; QtoQGSudakov
 do SplittingGenerator:AddInitialSplitting d->d,g; QtoQGSudakov
 do SplittingGenerator:AddInitialSplitting s->s,g; QtoQGSudakov
 do SplittingGenerator:AddInitialSplitting c->c,g; QtoQGSudakov
 do SplittingGenerator:AddInitialSplitting b->b,g; QtoQGSudakov
 do SplittingGenerator:AddInitialSplitting u->u,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddInitialSplitting d->d,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddInitialSplitting s->s,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddInitialSplitting c->c,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddInitialSplitting b->b,gamma; QtoQGammaSudakov
 do SplittingGenerator:AddInitialSplitting t->t,gamma; QtoQGammaSudakov
 
 do SplittingGenerator:AddInitialSplitting g->g,g; GtoGGSudakov
 #
 do SplittingGenerator:AddInitialSplitting g->d,dbar; GtoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting g->u,ubar; GtoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting g->s,sbar; GtoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting g->c,cbar; GtoccbarSudakov
 do SplittingGenerator:AddInitialSplitting g->b,bbar; GtobbbarSudakov
 #
 do SplittingGenerator:AddInitialSplitting gamma->d,dbar; GammatoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting gamma->u,ubar; GammatoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting gamma->s,sbar; GammatoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting gamma->c,cbar; GammatoQQbarSudakov
 do SplittingGenerator:AddInitialSplitting gamma->b,bbar; GammatoQQbarSudakov
 #
 do SplittingGenerator:AddInitialSplitting d->g,d; dtoGdSudakov
 do SplittingGenerator:AddInitialSplitting u->g,u; utoGuSudakov
 do SplittingGenerator:AddInitialSplitting s->g,s; QtoGQSudakov
 do SplittingGenerator:AddInitialSplitting c->g,c; QtoGQSudakov
 do SplittingGenerator:AddInitialSplitting b->g,b; QtoGQSudakov
 do SplittingGenerator:AddInitialSplitting dbar->g,dbar; dtoGdSudakov
 do SplittingGenerator:AddInitialSplitting ubar->g,ubar; utoGuSudakov
 do SplittingGenerator:AddInitialSplitting sbar->g,sbar; QtoGQSudakov
 do SplittingGenerator:AddInitialSplitting cbar->g,cbar; QtoGQSudakov
 do SplittingGenerator:AddInitialSplitting bbar->g,bbar; QtoGQSudakov
 #
 do SplittingGenerator:AddInitialSplitting d->gamma,d; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting u->gamma,u; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting s->gamma,s; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting c->gamma,c; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting b->gamma,b; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting dbar->gamma,dbar; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting ubar->gamma,ubar; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting sbar->gamma,sbar; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting cbar->gamma,cbar; QtoGammaQSudakov
 do SplittingGenerator:AddInitialSplitting bbar->gamma,bbar; QtoGammaQSudakov