41#include "JetSplitMergeTool.hh" 
   43#include "JetDistances.hh" 
   44#include "CommonUtils.hh" 
   46#include "fastjet/internal/base.hh" 
   48FASTJET_BEGIN_NAMESPACE
 
   52JetSplitMergeTool::JetSplitMergeTool()
 
   56JetSplitMergeTool::~JetSplitMergeTool()
 
   62int JetSplitMergeTool::execute( jetcollection_t* theJets )
 
   73  jetcollection_t::iterator itrB = theJets->begin();
 
   74  jetcollection_t::iterator itrE = theJets->end(); 
 
   77  for (;itrB!=itrE;itrB++) {
 
   78    Jet* j = 
new Jet(); j->addJet(*itrB);
 
   80    m_preJet.push_back(j);    
 
   94  jetcollection_t::iterator it = m_jet.begin();
 
   95  jetcollection_t::iterator itE = m_jet.end();
 
   97    theJets->push_back(*it);
 
  107void JetSplitMergeTool::split_merge()
 
  109  if ( m_preJet.size() >= 2 ) {
 
  111      sort_list_et(m_preJet);
 
  113      jetcollection_t::iterator itr;
 
  114      jetcollection_t::iterator first = m_preJet.begin();
 
  115      jetcollection_t::iterator last  = m_preJet.end();
 
  119      bool overlap = 
false;
 
  121      for (;itr != last;++itr) {      
 
  122        double etaF = (*first)->eta();
 
  123        double phiF = (*first)->phi();
 
  124        double etaS = (*itr)->eta();
 
  125        double phiS = (*itr)->phi();
 
  127        Jet* oJet = jet_from_overlap( (*first),*itr);   
 
  130        Jet::constit_vect_t::iterator itro  = oJet->firstConstituent();
 
  131        Jet::constit_vect_t::iterator itroE = oJet->lastConstituent();
 
  133        if ( oJet->getConstituentNum() != 0 ) {
 
  137          double f = sqrt(pow(oJet->px,2)+pow(oJet->py,2))/
 
  138            sqrt(pow((*itr)->px,2)+pow((*itr)->py,2));
 
  144            for ( ;itro != itroE; ++itro ) j->removeConstituent(*itro);
 
  145            (*first)->addJet(*itr);
 
  154            for ( ;itro != itroE; ++itro ) {          
 
  156              double deta1 = etaF - (*itro)->eta();
 
  157              double dphi1 = fabs(JetDistances::deltaPhi(phiF,(*itro)->phi()));
 
  158              double dist1 = pow( deta1 , 2 ) + pow( dphi1 , 2 );
 
  161              double deta2 = etaS - (*itro)->eta();
 
  162              double dphi2 = fabs(JetDistances::deltaPhi(phiS,(*itro)->phi()));
 
  163              double dist2 = pow( deta2 , 2 ) + pow( dphi2 , 2 );
 
  166              if ( dist1 > dist2 ) (*first)->removeConstituent(*itro);
 
  167              if ( dist1 <= dist2 ) (*itr)->removeConstituent(*itro);   
 
  182      if ( overlap == 
false ) {
 
  183        m_jet.push_back(*first);
 
  185        m_preJet.erase(first);      
 
  188    } 
while ( m_preJet.size() != 0 );    
 
  190  else if ( m_preJet.size() == 1) {
 
  191    m_jet.push_back( *(m_preJet.begin()) );
 
  206double JetSplitMergeTool::etaTrue(Jet::constit_vect_t::iterator pj)
 
  208  double s = ((*pj)->e() > 0) ? +1.0 : -1.0;
 
  209  double px = (*pj)->px;
 
  210  double py = (*pj)->py;
 
  211  double pz = (*pj)->pz;
 
  212  double theta = acos(pz*s/sqrt(px*px+py*py+pz*pz));
 
  213  return -log(tan(theta/2.0));
 
  216double JetSplitMergeTool::phiTrue(Jet::constit_vect_t::iterator pj)
 
  218  double s = ((*pj)->e() > 0) ? +1.0 : -1.0;
 
  219  double px = (*pj)->px;
 
  220  double py = (*pj)->py;
 
  221  return atan2(py*s,px*s);
 
double theta(const PseudoJet &a, const PseudoJet &b)
returns the angle between a and b