CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/GeneratorInterface/Pythia8Interface/src/EmissionVetoHook1.cc

Go to the documentation of this file.
00001 #include "GeneratorInterface/Pythia8Interface/interface/EmissionVetoHook1.h"
00002 
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 void EmissionVetoHook1::fatalEmissionVeto(string message) {
00005   throw edm::Exception(edm::errors::Configuration,"Pythia8Interface")
00006     << "EmissionVeto: " << message << endl;
00007 }
00008 
00009 //--------------------------------------------------------------------------
00010 
00011 // Routines to calculate the pT (according to pTdefMode) in a splitting:
00012 //   ISR: i (radiator after)  -> j (emitted after) k (radiator before)
00013 //   FSR: i (radiator before) -> j (emitted after) k (radiator after)
00014 // For the Pythia pT definition, a recoiler (after) must be specified.
00015 
00016 // Compute the Pythia pT separation. Based on pTLund function in History.cc
00017 double EmissionVetoHook1::pTpythia(const Pythia8::Event &e, int RadAfterBranch,
00018                                    int EmtAfterBranch, int RecAfterBranch, bool FSR) {
00019 
00020   // Convenient shorthands for later
00021   Pythia8::Vec4 radVec = e[RadAfterBranch].p();
00022   Pythia8::Vec4 emtVec = e[EmtAfterBranch].p();
00023   Pythia8::Vec4 recVec = e[RecAfterBranch].p();
00024   int  radID  = e[RadAfterBranch].id();
00025 
00026   // Calculate virtuality of splitting
00027   double sign = (FSR) ? 1. : -1.;
00028   Pythia8::Vec4 Q(radVec + sign * emtVec); 
00029   double Qsq = sign * Q.m2Calc();
00030 
00031   // Mass term of radiator
00032   double m2Rad = (abs(radID) >= 4 && abs(radID) < 7) ?
00033                   Pythia8::pow2(particleDataPtr->m0(radID)) : 0.;
00034 
00035   // z values for FSR and ISR
00036   double z, pTnow;
00037   if (FSR) {
00038     // Construct 2 -> 3 variables
00039     Pythia8::Vec4 sum = radVec + recVec + emtVec;
00040     double m2Dip = sum.m2Calc();
00041     double x1 = 2. * (sum * radVec) / m2Dip;
00042     double x3 = 2. * (sum * emtVec) / m2Dip;
00043     z     = x1 / (x1 + x3);
00044     pTnow = z * (1. - z);
00045 
00046   } else {
00047     // Construct dipoles before/after splitting
00048     Pythia8::Vec4 qBR(radVec - emtVec + recVec);
00049     Pythia8::Vec4 qAR(radVec + recVec);
00050     z     = qBR.m2Calc() / qAR.m2Calc();
00051     pTnow = (1. - z);
00052   }
00053 
00054   // Virtuality with correct sign
00055   pTnow *= (Qsq - sign * m2Rad);
00056 
00057   // Can get negative pT for massive splittings
00058   if (pTnow < 0.) {
00059     cout << "Warning: pTpythia was negative" << endl;
00060     return -1.;
00061   }
00062 
00063 #ifdef DBGOUTPUT
00064   cout << "pTpythia: rad = " << RadAfterBranch << ", emt = "
00065        << EmtAfterBranch << ", rec = " << RecAfterBranch
00066        << ", pTnow = " << sqrt(pTnow) << endl;
00067 #endif
00068 
00069   // Return pT
00070   return sqrt(pTnow);
00071 }
00072 
00073 // Compute the POWHEG pT separation between i and j
00074 double EmissionVetoHook1::pTpowheg(const Pythia8::Event &e, int i, int j, bool FSR) {
00075 
00076   // pT value for FSR and ISR
00077   double pTnow = 0.;
00078   if (FSR) {
00079     // POWHEG d_ij (in CM frame). Note that the incoming beams have not
00080     // been updated in the parton systems pointer yet (i.e. prior to any
00081     // potential recoil).
00082     int iInA = partonSystemsPtr->getInA(0);
00083     int iInB = partonSystemsPtr->getInB(0);
00084     double betaZ = - ( e[iInA].pz() + e[iInB].pz() ) /
00085                      ( e[iInA].e()  + e[iInB].e()  );
00086     Pythia8::Vec4 iVecBst(e[i].p()), jVecBst(e[j].p());
00087     iVecBst.bst(0., 0., betaZ);
00088     jVecBst.bst(0., 0., betaZ);
00089     pTnow = sqrt( (iVecBst + jVecBst).m2Calc() *
00090                   iVecBst.e() * jVecBst.e() /
00091                   Pythia8::pow2(iVecBst.e() + jVecBst.e()) );
00092 
00093   } else {
00094     // POWHEG pT_ISR is just kinematic pT
00095     pTnow = e[j].pT();
00096   }
00097 
00098   // Check result
00099   if (pTnow < 0.) {
00100     cout << "Warning: pTpowheg was negative" << endl;
00101     return -1.;
00102   }
00103 
00104 #ifdef DBGOUTPUT
00105   cout << "pTpowheg: i = " << i << ", j = " << j
00106        << ", pTnow = " << pTnow << endl;
00107 #endif
00108 
00109    return pTnow;
00110 }
00111 
00112 // Calculate pT for a splitting based on pTdefMode.
00113 // If j is -1, all final-state partons are tried.
00114 // If i, k, r and xSR are -1, then all incoming and outgoing 
00115 // partons are tried.
00116 // xSR set to 0 means ISR, while xSR set to 1 means FSR
00117 double EmissionVetoHook1::pTcalc(const Pythia8::Event &e, int i, int j, int k, int r, int xSRin) {
00118 
00119   // Loop over ISR and FSR if necessary
00120   double pTemt = -1., pTnow;
00121   int xSR1 = (xSRin == -1) ? 0 : xSRin;
00122   int xSR2 = (xSRin == -1) ? 2 : xSRin + 1;
00123   for (int xSR = xSR1; xSR < xSR2; xSR++) {
00124     // FSR flag
00125     bool FSR = (xSR == 0) ? false : true;
00126 
00127     // If all necessary arguments have been given, then directly calculate.
00128     // POWHEG ISR and FSR, need i and j.
00129     if ((pTdefMode == 0 || pTdefMode == 1) && i > 0 && j > 0) {
00130       pTemt = pTpowheg(e, i, j, (pTdefMode == 0) ? false : FSR);
00131 
00132     // Pythia ISR, need i, j and r.
00133     } else if (!FSR && pTdefMode == 2 && i > 0 && j > 0 && r > 0) {
00134       pTemt = pTpythia(e, i, j, r, FSR);
00135 
00136     // Pythia FSR, need k, j and r.
00137     } else if (FSR && pTdefMode == 2 && j > 0 && k > 0 && r > 0) {
00138       pTemt = pTpythia(e, k, j, r, FSR);
00139 
00140     // Otherwise need to try all possible combintations.
00141     } else {
00142       // Start by finding incoming legs to the hard system after
00143       // branching (radiator after branching, i for ISR).
00144       // Use partonSystemsPtr to find incoming just prior to the
00145       // branching and track mothers.
00146       int iInA = partonSystemsPtr->getInA(0);
00147       int iInB = partonSystemsPtr->getInB(0);
00148       while (e[iInA].mother1() != 1) { iInA = e[iInA].mother1(); }
00149       while (e[iInB].mother1() != 2) { iInB = e[iInB].mother1(); }
00150 
00151       // If we do not have j, then try all final-state partons
00152       int jNow = (j > 0) ? j : 0;
00153       int jMax = (j > 0) ? j + 1 : e.size();
00154       for (; jNow < jMax; jNow++) {
00155 
00156         // Final-state and coloured jNow only
00157         if (!e[jNow].isFinal() || e[jNow].colType() == 0) continue;
00158 
00159         // POWHEG
00160         if (pTdefMode == 0 || pTdefMode == 1) {
00161 
00162           // ISR - only done once as just kinematical pT
00163           if (!FSR) {
00164             pTnow = pTpowheg(e, iInA, jNow, (pTdefMode == 0) ? false : FSR);
00165             if (pTnow > 0.) pTemt = (pTemt < 0) ? pTnow : min(pTemt, pTnow);
00166   
00167           // FSR - try all outgoing partons from system before branching 
00168           // as i. Note that for the hard system, there is no 
00169           // "before branching" information.
00170           } else {
00171     
00172             int outSize = partonSystemsPtr->sizeOut(0);
00173             for (int iMem = 0; iMem < outSize; iMem++) {
00174               int iNow = partonSystemsPtr->getOut(0, iMem);
00175 
00176               // Coloured only, i != jNow and no carbon copies
00177               if (iNow == jNow || e[iNow].colType() == 0) continue;
00178               if (jNow == e[iNow].daughter1() 
00179                   && jNow == e[iNow].daughter2()) continue;
00180 
00181               pTnow = pTpowheg(e, iNow, jNow, (pTdefMode == 0) 
00182                 ? false : FSR);
00183               if (pTnow > 0.) pTemt = (pTemt < 0) 
00184                 ? pTnow : min(pTemt, pTnow);
00185             } // for (iMem)
00186   
00187           } // if (!FSR)
00188   
00189         // Pythia
00190         } else if (pTdefMode == 2) {
00191   
00192           // ISR - other incoming as recoiler
00193           if (!FSR) {
00194             pTnow = pTpythia(e, iInA, jNow, iInB, FSR);
00195             if (pTnow > 0.) pTemt = (pTemt < 0) ? pTnow : min(pTemt, pTnow);
00196             pTnow = pTpythia(e, iInB, jNow, iInA, FSR);
00197             if (pTnow > 0.) pTemt = (pTemt < 0) ? pTnow : min(pTemt, pTnow);
00198   
00199           // FSR - try all final-state coloured partons as radiator
00200           //       after emission (k).
00201           } else {
00202             for (int kNow = 0; kNow < e.size(); kNow++) {
00203               if (kNow == jNow || !e[kNow].isFinal() ||
00204                   e[kNow].colType() == 0) continue;
00205   
00206               // For this kNow, need to have a recoiler.
00207               // Try two incoming.
00208               pTnow = pTpythia(e, kNow, jNow, iInA, FSR);
00209               if (pTnow > 0.) pTemt = (pTemt < 0) 
00210                 ? pTnow : min(pTemt, pTnow);
00211               pTnow = pTpythia(e, kNow, jNow, iInB, FSR);
00212               if (pTnow > 0.) pTemt = (pTemt < 0) 
00213                 ? pTnow : min(pTemt, pTnow);
00214 
00215               // Try all other outgoing.
00216               for (int rNow = 0; rNow < e.size(); rNow++) {
00217                 if (rNow == kNow || rNow == jNow ||
00218                     !e[rNow].isFinal() || e[rNow].colType() == 0) continue;
00219                 pTnow = pTpythia(e, kNow, jNow, rNow, FSR);
00220                 if (pTnow > 0.) pTemt = (pTemt < 0) 
00221                   ? pTnow : min(pTemt, pTnow);
00222               } // for (rNow)
00223   
00224             } // for (kNow)
00225           } // if (!FSR)
00226         } // if (pTdefMode)
00227       } // for (j)
00228     }
00229   } // for (xSR)
00230 
00231 #ifdef DBGOUTPUT
00232   cout << "pTcalc: i = " << i << ", j = " << j << ", k = " << k
00233        << ", r = " << r << ", xSR = " << xSRin
00234        << ", pTemt = " << pTemt << endl;
00235 #endif
00236 
00237   return pTemt;
00238 }
00239 
00240 //--------------------------------------------------------------------------
00241 
00242 // Extraction of pThard based on the incoming event.
00243 // Assume that all the final-state particles are in a continuous block
00244 // at the end of the event and the final entry is the POWHEG emission.
00245 // If there is no POWHEG emission, then pThard is set to Qfac.
00246 
00247 bool EmissionVetoHook1::doVetoMPIStep(int nMPI, const Pythia8::Event &e) {
00248   // Extra check on nMPI
00249   if (nMPI > 1) return false;
00250 
00251   // Find if there is a POWHEG emission. Go backwards through the
00252   // event record until there is a non-final particle. Also sum pT and
00253   // find pT_1 for possible MPI vetoing
00254   int count = 0, inonfinal = 0;
00255   double pT1 = 0., pTsum = 0.;
00256   for (int i = e.size() - 1; i > 0; i--) {
00257     inonfinal = i;
00258     if (e[i].isFinal()) {
00259       count++;
00260       pT1    = e[i].pT();
00261       pTsum += e[i].pT();
00262     } else break;
00263   }
00264 
00265   nFinal = nFinalExt;
00266 
00267   if (nFinal < 0) {      // nFinal is not specified from external, try to find out
00268     int first = -1, myid;
00269     int last = -1;
00270     for(int ip = 2; ip < e.size(); ip++) {
00271       myid = e[ip].id();
00272       if(abs(myid) < 6 || abs(myid) == 21) continue;
00273       first = ip;
00274       break;
00275     }
00276     if(first < 0) fatalEmissionVeto(string("signal particles not found"));
00277     for(int ip = first; ip < e.size(); ip++) {
00278       myid = e[ip].id();
00279       if(abs(myid) < 6 || abs(myid) == 21) continue;
00280       last = ip;
00281     }
00282     nFinal = last - inonfinal;
00283   }
00284 
00285   // Extra check that we have the correct final state
00286   if (count != nFinal && count != nFinal + 1)
00287     fatalEmissionVeto(string("Wrong number of final state particles in event"));
00288 
00289   // Flag if POWHEG radiation present and index
00290   bool isEmt = (count == nFinal) ? false : true;
00291   int  iEmt  = (isEmt) ? e.size() - 1 : -1;
00292 
00293   // If there is no radiation or if pThardMode is 0 then set pThard to Qfac.
00294   if (!isEmt || pThardMode == 0) {
00295     pThard = infoPtr->QFac();
00296       
00297   // If pThardMode is 1 then the pT of the POWHEG emission is checked against
00298   // all other incoming and outgoing partons, with the minimal value taken
00299   } else if (pThardMode == 1) {
00300     pThard = pTcalc(e, -1, iEmt, -1, -1, -1);
00301 
00302   // If pThardMode is 2, then the pT of all final-state partons is checked
00303   // against all other incoming and outgoing partons, with the minimal value
00304   // taken
00305   } else if (pThardMode == 2) {
00306     pThard = pTcalc(e, -1, -1, -1, -1, -1);
00307 
00308   }
00309 
00310   // Find MPI veto pT if necessary
00311   if (MPIvetoOn) {
00312     pTMPI = (isEmt) ? pTsum / 2. : pT1;
00313   }
00314 
00315   if(Verbosity)
00316     cout << "doVetoMPIStep: Qfac = " << infoPtr->QFac()
00317          << ", pThard = " << pThard << endl << endl;
00318 
00319   // Initialise other variables
00320   accepted   = false;
00321   nAcceptSeq = 0;
00322 
00323   // Do not veto the event
00324   return false;
00325 }
00326 
00327 //--------------------------------------------------------------------------
00328 
00329 // ISR veto
00330 
00331 bool EmissionVetoHook1::doVetoISREmission(int, const Pythia8::Event &e, int iSys) {
00332   // Must be radiation from the hard system
00333   if (iSys != 0) return false;
00334 
00335   // If we already have accepted 'vetoCount' emissions in a row, do nothing
00336   if (vetoOn && nAcceptSeq >= vetoCount) return false;
00337 
00338   // Pythia radiator after, emitted and recoiler after.
00339   int iRadAft = -1, iEmt = -1, iRecAft = -1;
00340   for (int i = e.size() - 1; i > 0; i--) {
00341     if      (iRadAft == -1 && e[i].status() == -41) iRadAft = i;
00342     else if (iEmt    == -1 && e[i].status() ==  43) iEmt    = i;
00343     else if (iRecAft == -1 && e[i].status() == -42) iRecAft = i;
00344     if (iRadAft != -1 && iEmt != -1 && iRecAft != -1) break;
00345   }
00346   if (iRadAft == -1 || iEmt == -1 || iRecAft == -1) {
00347     e.list();
00348     fatalEmissionVeto(string("Couldn't find Pythia ISR emission"));
00349   }
00350 
00351   // pTemtMode == 0: pT of emitted w.r.t. radiator
00352   // pTemtMode == 1: min(pT of emitted w.r.t. all incoming/outgoing)
00353   // pTemtMode == 2: min(pT of all outgoing w.r.t. all incoming/outgoing)
00354   int xSR      = (pTemtMode == 0) ? 0       : -1;
00355   int i        = (pTemtMode == 0) ? iRadAft : -1;
00356   int j        = (pTemtMode != 2) ? iEmt    : -1;
00357   int k        = -1;
00358   int r        = (pTemtMode == 0) ? iRecAft : -1;
00359   double pTemt = pTcalc(e, i, j, k, r, xSR);
00360 
00361 #ifdef DBGOUTPUT
00362   cout << "doVetoISREmission: pTemt = " << pTemt << endl << endl;
00363 #endif
00364 
00365   // Veto if pTemt > pThard
00366   if (pTemt > pThard) {
00367     nAcceptSeq = 0;
00368     nISRveto++;
00369     return true;
00370   }
00371 
00372   // Else mark that an emission has been accepted and continue
00373   nAcceptSeq++;
00374   accepted = true;
00375   return false;
00376 }
00377 
00378 //--------------------------------------------------------------------------
00379 
00380 // FSR veto
00381 
00382 bool EmissionVetoHook1::doVetoFSREmission(int, const Pythia8::Event &e, int iSys, bool) {
00383   // Must be radiation from the hard system
00384   if (iSys != 0) return false;
00385 
00386   // If we already have accepted 'vetoCount' emissions in a row, do nothing
00387   if (vetoOn && nAcceptSeq >= vetoCount) return false;
00388 
00389   // Pythia radiator (before and after), emitted and recoiler (after)
00390   int iRecAft = e.size() - 1;
00391   int iEmt    = e.size() - 2;
00392   int iRadAft = e.size() - 3;
00393   int iRadBef = e[iEmt].mother1();
00394   if ( (e[iRecAft].status() != 52 && e[iRecAft].status() != -53) ||
00395        e[iEmt].status() != 51 || e[iRadAft].status() != 51) {
00396     e.list();
00397     fatalEmissionVeto(string("Couldn't find Pythia FSR emission"));
00398   }
00399 
00400   // Behaviour based on pTemtMode:
00401   //  0 - pT of emitted w.r.t. radiator before
00402   //  1 - min(pT of emitted w.r.t. all incoming/outgoing)
00403   //  2 - min(pT of all outgoing w.r.t. all incoming/outgoing)
00404   int xSR = (pTemtMode == 0) ? 1       : -1;
00405   int i   = (pTemtMode == 0) ? iRadBef : -1;
00406   int k   = (pTemtMode == 0) ? iRadAft : -1;
00407   int r   = (pTemtMode == 0) ? iRecAft : -1;
00408 
00409   // When pTemtMode is 0 or 1, iEmt has been selected
00410   double pTemt = -1.;
00411   if (pTemtMode == 0 || pTemtMode == 1) {
00412     // Which parton is emitted, based on emittedMode:
00413     //  0 - Pythia definition of emitted
00414     //  1 - Pythia definition of radiated after emission
00415     //  2 - Random selection of emitted or radiated after emission
00416     //  3 - Try both emitted and radiated after emission
00417     int j = iRadAft;
00418     if (emittedMode == 0 || (emittedMode == 2 && rndmPtr->flat() < 0.5)) j++;
00419 
00420     for (int jLoop = 0; jLoop < 2; jLoop++) {
00421       if      (jLoop == 0) pTemt = pTcalc(e, i, j, k, r, xSR);
00422       else if (jLoop == 1) pTemt = min(pTemt, pTcalc(e, i, j, k, r, xSR));
00423   
00424       // For emittedMode == 3, have tried iRadAft, now try iEmt
00425       if (emittedMode != 3) break;
00426       if (k != -1) swap(j, k); else j = iEmt;
00427     }
00428 
00429   // If pTemtMode is 2, then try all final-state partons as emitted
00430   } else if (pTemtMode == 2) {
00431     pTemt = pTcalc(e, i, -1, k, r, xSR);
00432 
00433   }
00434 
00435 #ifdef DBGOUTPUT
00436   cout << "doVetoFSREmission: pTemt = " << pTemt << endl << endl;
00437 #endif
00438 
00439   // Veto if pTemt > pThard
00440   if (pTemt > pThard) {
00441     nAcceptSeq = 0;
00442     nFSRveto++;
00443     return true;
00444   }
00445 
00446   // Else mark that an emission has been accepted and continue
00447   nAcceptSeq++;
00448   accepted = true;
00449   return false;
00450 }
00451 
00452 //--------------------------------------------------------------------------
00453 
00454 // MPI veto
00455 
00456 bool EmissionVetoHook1::doVetoMPIEmission(int, const Pythia8::Event &e) {
00457   if (MPIvetoOn) {
00458     if (e[e.size() - 1].pT() > pTMPI) {
00459 #ifdef DBGOUTPUT
00460       cout << "doVetoMPIEmission: pTnow = " << e[e.size() - 1].pT()
00461            << ", pTMPI = " << pTMPI << endl << endl;
00462 #endif
00463       return true;
00464     }
00465   }
00466   return false;
00467 }
00468