CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/GeneratorInterface/Pythia8Interface/src/JetMatchingHook.cc

Go to the documentation of this file.
00001 #include "GeneratorInterface/Pythia8Interface/interface/JetMatchingHook.h"
00002 #include "GeneratorInterface/PartonShowerVeto/interface/JetMatchingMadgraph.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005 #include "HepMC/HEPEVT_Wrapper.h"
00006 
00007 using namespace gen;
00008 using namespace Pythia8;
00009 
00010 
00011 JetMatchingHook::JetMatchingHook( const edm::ParameterSet& ps, Info* info )
00012    : UserHooks(), fRunBlock(0), fEventBlock(0), fEventNumber(0), fInfoPtr(info), fJetMatching(0)
00013 {
00014 
00015    assert( fInfoPtr );
00016    
00017    std::string scheme = ps.getParameter<std::string>("scheme");
00018 
00019    if ( scheme == "Madgraph" )
00020    {
00021       fJetMatching = new JetMatchingMadgraph(ps);
00022    }
00023    else if ( scheme == "MLM" || scheme == "Alpgen" )
00024    {
00025         throw cms::Exception("JetMatching")
00026         << "Port of " << scheme << "scheme \"" << "\""
00027         " for parton-shower matching is still in progress."
00028         << std::endl;
00029    }
00030    else
00031       throw cms::Exception("InvalidJetMatching")
00032       << "Unknown scheme \"" << scheme << "\""
00033       " specified for parton-shower matching."
00034       << std::endl;
00035  
00036 }
00037 
00038 JetMatchingHook::~JetMatchingHook()
00039 {
00040    if ( fJetMatching ) delete fJetMatching;
00041 }
00042 
00043 void JetMatchingHook::init ( lhef::LHERunInfo* runInfo )
00044 {
00045 
00046    setLHERunInfo( runInfo );
00047    if ( !fRunBlock )
00048    {
00049       throw cms::Exception("JetMatching")
00050       << "Invalid RunInfo" << std::endl;
00051    
00052    }
00053    fJetMatching->init( runInfo );
00054    return; 
00055 
00056 }
00057 
00058 void JetMatchingHook::beforeHadronization( lhef::LHEEvent* lhee )
00059 {
00060 
00061    setLHEEvent( lhee );   
00062    fJetMatching->beforeHadronisation( lhee );
00063       
00064    fJetMatching->beforeHadronisationExec();  
00065 
00066    return;   
00067 
00068 }
00069 
00070 bool JetMatchingHook::doVetoPartonLevel( const Event& event )
00071 {
00072             
00073    omitResonanceDecays(event); 
00074    
00075    subEvent(event,true);
00076    setHEPEVT( workEvent );
00077    
00078    if ( !hepeup_.nup || fJetMatching->isMatchingDone() )
00079    {
00080       return true;
00081    }
00082    
00083    // Note from JY:
00084    // match(...)input agrs here are reserved for future development and are irrelevat at this point
00085    // just for future references, they're: 
00086    // const HepMC::GenEvent* partonLevel,
00087    // const HepMC::GenEvent *finalState,
00088    // bool showeredFinalState
00089    //
00090    bool jmtch = fJetMatching->match( 0, 0, true ); // true if veto-ed, false if accepted (not veto-ed)
00091    if ( jmtch )
00092    {
00093       return true;
00094    }
00095          
00096    // Do not veto events that got this far
00097    //
00098    return false;
00099 
00100 }
00101 
00102 void JetMatchingHook::setHEPEVT( const Event& event )
00103 {
00104 
00105    int index = 0;
00106    for ( int iprt=1; iprt<event.size(); iprt++ ) // from 0-entry (system) or from 1st entry ???
00107    {
00108    
00109       const Particle& part = event[iprt];
00110       if ( part.status() != 62 ) continue;
00111       index++;
00112       HepMC::HEPEVT_Wrapper::set_id( index, part.id() );
00113       HepMC::HEPEVT_Wrapper::set_status( index, 1 ); 
00114       //
00115       // Please note that we do NOT boost along Z (unlike in Py6) because we get to matching 
00116       // later in the event development, so boost isn't necessary
00117       //
00118       HepMC::HEPEVT_Wrapper::set_momentum( index, part.px(), part.py(), part.pz(), part.e() );
00119       HepMC::HEPEVT_Wrapper::set_mass( index, part.m() );
00120       HepMC::HEPEVT_Wrapper::set_position( index, part.xProd(), part.yProd(), part.zProd(), part.tProd() );
00121       //
00122       // at this point we do NOT attepmt to figure out and set mother-daughter links (although in Py we do)
00123       //
00124       HepMC::HEPEVT_Wrapper::set_parents( index, 0, 0 ); 
00125       HepMC::HEPEVT_Wrapper::set_children( index, 0, 0 );
00126       
00127    }   
00128 
00129    HepMC::HEPEVT_Wrapper::set_number_entries( index );
00130    
00131    HepMC::HEPEVT_Wrapper::set_event_number( fEventNumber ); // well, if you know it... well, it's one of the counters...
00132    
00133    // HepMC::HEPEVT_Wrapper::print_hepevt();
00134 
00135    return;
00136 
00137 }
00138 
00139 /* Oct.2011 - Note from JY:
00140    This is an attempt to mimic Py6 routine PYVETO, including boost along Z and mother-daughter links.
00141    It's unclear if we'll ever need thsoe details, but for now I keep the commented code here, just in case...
00142 
00143 void JetMatchingHook::setHEPEVT( const Event& event )
00144 {
00145 
00146    HepMC::HEPEVT_Wrapper::zero_everything();
00147    
00148    int index = 0;
00149    std::vector<int> IndexContainer;
00150    IndexContainer.clear();
00151    int status = 0;
00152    for ( int iprt=1; iprt<event.size(); iprt++ ) // from 0-entry (system) or from 1st entry ???
00153    {
00154    
00155       const Particle& part = event[iprt];
00156       
00157       if ( abs(part.status()) < 22 ) continue; // below 10 is "service"
00158                                                // 11-19 are beam particles; below 10 is "service"
00159                                                // 21 is incoming partons
00160       if ( part.status() < -23 ) continue; // intermediate steps in the event development 
00161                                            // BUT already decayed/branched/fragmented/...
00162       // so we get here if status=+/-22 or +/-23, or remaining particles with status >30 
00163       //
00164       IndexContainer.push_back( iprt );
00165       index++;
00166       HepMC::HEPEVT_Wrapper::set_id( index, part.id() );
00167       // HepMC::HEPEVT_Wrapper::set_status( index, event.statusHepMC(iprt) ); 
00168       status = 1;
00169       if (abs(part.status()) == 22 || abs(part.status()) == 23 )
00170       {
00171          // HepMC::HEPEVT_Wrapper::set_status( index, 2 );
00172          status = 2;
00173       }
00174       HepMC::HEPEVT_Wrapper::set_status( index, status );
00175       // needs to be boosted along z-axis !!!
00176       // this is from Py6/pyveto code:
00177       // C...Define longitudinal boost from initiator rest frame to cm frame
00178       // - need to replicate !!!
00179       // GAMMA=0.5D0*(VINT(141)+VINT(142))/SQRT(VINT(141)*VINT(142))
00180       // GABEZ=0.5D0*(VINT(141)-VINT(142))/SQRT(VINT(141)*VINT(142))
00181       double x1 = fInfoPtr->x1();
00182       double x2 = fInfoPtr->x2();
00183       double dot = x1*x2;
00184       assert( dot );
00185       double gamma = 0.5 * ( x1+x2 ) / std::sqrt( dot );
00186       double gabez = 0.5 * ( x1-x2 ) / std::sqrt( dot );
00187       double pz = gamma*part.pz() + gabez*part.e();
00188       double e  = gamma*part.e()  + gabez*part.pz();
00189       HepMC::HEPEVT_Wrapper::set_momentum( index, part.px(), part.py(), pz, e );
00190       HepMC::HEPEVT_Wrapper::set_mass( index, part.m() );
00191       HepMC::HEPEVT_Wrapper::set_position( index, part.xProd(), part.yProd(), part.zProd(), part.tProd() );
00192       HepMC::HEPEVT_Wrapper::set_parents( index, 0, 0 ); // for some, mother will need to be re-set properly !
00193       HepMC::HEPEVT_Wrapper::set_children( index, 0, 0 );
00194       if ( status == 2 ) continue; 
00195       int parentId = part.mother1();
00196       int parentPrevId = 0;
00197       
00198       while ( parentId > 0 )
00199       {               
00200          if ( parentId == part.mother2() ) // carbon copy
00201          {
00202             parentPrevId = parentId;
00203             parentId = event[parentPrevId].mother1();
00204             continue;
00205          }
00206          
00207          // we get here if not a carbon copy, but a result of a process
00208          if ( parentId < parentPrevId ) // normal process
00209          {
00210             parentPrevId = parentId;
00211             parentId = event[parentPrevId].mother1();
00212          }
00213          else if ( parentId > parentPrevId || parentId > iprt ) // "circular"/"forward-pointing parent" - intermediate process
00214          {
00215             parentId = -1;
00216             break;
00217          }
00218          
00219          if ( parentId < part.mother2() ) // normal process
00220          {
00221             parentPrevId = parentId;
00222             parentId = event[parentPrevId].mother1();
00223          }
00224          
00225          if ( abs(event[parentId].status()) == 22 || abs(event[parentId].status())== 23 ) // hard block
00226          {
00227             break;
00228          } 
00229          
00230          if ( abs(event[parentId].status()) < 22 ) // incoming
00231          {
00232             parentId = -1;
00233             break;
00234          } 
00235       }
00236 
00237       if ( parentId > 0 )
00238       {
00239          for ( int idx=0; idx<(int)IndexContainer.size(); idx++ )
00240          {
00241             if ( parentId == IndexContainer[idx] )
00242             {
00243                HepMC::HEPEVT_Wrapper::set_parents( index, idx+1, idx+1 ); // probably need to check status of index-particle in HEPEVT - has to be 2 !!!
00244                break;
00245             }
00246          }
00247       }
00248         
00249    }
00250    
00251    HepMC::HEPEVT_Wrapper::set_number_entries( index );
00252    
00253    HepMC::HEPEVT_Wrapper::set_event_number( fEventNumber ); // well, if you know it... well, it's one of the counters...
00254    
00255    HepMC::HEPEVT_Wrapper::print_hepevt();
00256    
00257    return;
00258 
00259 }
00260 */