예제 #1
0
// ============================================================================
StatusCode GaudiPython::TupleDecorator::farray
( const Tuples::Tuple&       tuple  ,
  const std::string&         name   ,
  const std::vector<double>& data   ,
  const std::string&         length ,
  const size_t               maxv   )
{
  if ( !tuple.valid() ) { return StatusCode::FAILURE ; }
  return tuple->farray( name , data.begin() , data.end() , length , maxv ) ;
}
예제 #2
0
// ============================================================================
StatusCode GaudiPython::TupleDecorator::farray
( const Tuples::Tuple&       tuple  ,
  const std::string&         name   ,
  const CLHEP::HepVector&    data   ,
  const std::string&         length ,
  const size_t               maxv   )
{
  if ( !tuple.valid() ) { return StatusCode::FAILURE ; }
  // use the trick!
  const double* begin = &(data[0]);
  const double* end   =   begin + data.num_row() ;
  return tuple->farray ( name , begin , end , length , maxv ) ;
}
StatusCode TupleToolTagging::fill( const Particle* mother
                                   , const Particle* P
                                   , const std::string& head
                                   , Tuples::Tuple& tuple )
{
  const std::string prefix=fullName(head);

  Assert( P && mother && m_dva && m_tagging,
          "Should not happen, you are inside TupleToolTagging.cpp" );

  std::string loc = objectLocation( P->parent() );

  // nothing to tag on something which is not a B
  if( !P->particleID().hasBottom() ) return StatusCode::SUCCESS;

  if( msgLevel( MSG::DEBUG ) ){
    debug() << " Going to Save Tagging information for B candidate "
            << endreq;
  }

  FlavourTag theTag;
  FlavourTags* tags = NULL;
  bool check = false;

  StatusCode sc=StatusCode::SUCCESS;

  boost::replace_all( loc, "/Particles", "/FlavourTags" );
  if( m_useFTonDST ) {
    if( exist < LHCb::FlavourTags > (loc,IgnoreRootInTES))
      tags = get< LHCb::FlavourTags > (loc,IgnoreRootInTES );
  }
  
  if (tags) {
    for(FlavourTags::const_iterator it = tags->begin(); it != tags->end(); ++it) {
      if( P != (**it).taggedB()) continue;
      theTag =  **it;
      check = true;
    }
    if (!check) sc = StatusCode::FAILURE;
  } else {
    const VertexBase* v = m_dva->bestVertex( mother );
    const RecVertex* vtx = dynamic_cast<const RecVertex*>(v);
    if( !vtx ){
      sc = m_tagging->tag( theTag, P );
    } else {
      sc = m_tagging->tag( theTag, P, vtx );
    }
  }
  // try to find unphysical defaults
  int dec = 0;
  double omega = 0.5;
  int decOS = 0;
  double omegaOS = 0.5;

  if( sc ){
    dec = theTag.decision();
    omega = theTag.omega(); // predicted wrong tag fraction.
    decOS = theTag.decisionOS();
    omegaOS = theTag.omegaOS(); // predicted wrong tag fraction.
  } else {
    Warning("The tagging algorithm failed");
  }

  bool test = true;
  test &= tuple->column( prefix+"_TAGDECISION" , dec );
  test &= tuple->column( prefix+"_TAGOMEGA" , omega );
  test &= tuple->column( prefix+"_TAGDECISION_OS" , decOS );
  test &= tuple->column( prefix+"_TAGOMEGA_OS" , omegaOS );

  int taggers_code = 0;
  // intialize tagger by tagger W :

  std::vector<Tagger> taggers = theTag.taggers();

  for(size_t i=0; i<taggers.size(); ++i) {
    int tdec = taggers[i].decision();

    if(tdec) switch ( taggers[i].type() ) {
    case Tagger::OS_Charm    : taggers_code +=1000000000 *(tdec+2); break;
    case Tagger::SS_Proton   : taggers_code += 100000000 *(tdec+2); break;
    case Tagger::OS_nnetKaon : taggers_code +=  10000000 *(tdec+2); break;
    case Tagger::SS_nnetKaon : taggers_code +=   1000000 *(tdec+2); break;
    case Tagger::OS_Muon     : taggers_code +=    100000 *(tdec+2); break;
    case Tagger::OS_Electron : taggers_code +=     10000 *(tdec+2); break;
    case Tagger::OS_Kaon     : taggers_code +=      1000 *(tdec+2); break;
    case Tagger::SS_Kaon     : taggers_code +=       100 *(tdec+2); break;
    case Tagger::SS_Pion     : taggers_code +=        10 *(tdec+2); break;
    case Tagger::VtxCharge   : taggers_code +=         1 *(tdec+2); break;

    }
  }
  
  test &= tuple->column( prefix+"_TAGGER" , taggers_code);
 
  if(isVerbose())  
  {    
    // Initialize all columns to default values
    for(size_t i=0; i<m_activeTaggers.size(); i++) {
        std::string active = m_activeTaggers[i];

        test &= tuple->column( prefix+"_"+active+"_DEC",  (short int)0 );
        test &= tuple->column( prefix+"_"+active+"_PROB", (float)0.5 );
        
        if(m_extendedTagging){
          if( true ) {
            std::vector<double> id, p, px, py, pz, pt, theta, phi;
            std::vector<double> pid_e, pid_mu, pid_k, pid_p;
            std::vector<double> ip, chi2, bip, bchi2, bp_chi2;
            
            const std::string num_name = prefix+"_"+active+"_PARTICLES_NUM";
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_ID", id.begin(), id.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_P", p.begin(), p.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PX", px.begin(), px.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PY", py.begin(), py.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PZ", pz.begin(), pz.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PT", pt.begin(), pt.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_THETA", theta.begin(), theta.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PHI", phi.begin(), phi.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PIDe", pid_e.begin(), pid_e.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PIDmu", pid_mu.begin(), pid_mu.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PIDk", pid_k.begin(), pid_k.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_PIDp", pid_p.begin(), pid_p.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_IP_OWNPV", ip.begin(), ip.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_IPCHI2_OWNPV", chi2.begin(), chi2.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_IP_BVertex", bip.begin(), bip.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_IPCHI2_BVertex", bchi2.begin(), bchi2.end(), num_name, 20 );
            test &= tuple->farray( prefix+"_"+active+"_PARTICLES_CHI2_BpVertex", bp_chi2.begin(), bp_chi2.end(), num_name, 20 );
            }
         }
                
    }  

    for(size_t i=0; i<taggers.size(); i++) {
      std::string name = m_tagger_map[(int)taggers[i].type()];

      //loop over active taggers only
      if(std::find(m_activeTaggers.begin(), m_activeTaggers.end(), name) != m_activeTaggers.end()) {
        Tagger tagger = taggers[i];

        test &= tuple->column( prefix+"_"+name+"_DEC",  tagger.decision() );
        test &= tuple->column( prefix+"_"+name+"_PROB", tagger.omega()    );

        if(m_extendedTagging){
          // Save interesting tagging data
          std::vector<double> id, p, px, py, pz, pt, theta, phi;
          std::vector<double> pid_e, pid_mu, pid_k, pid_p;
          std::vector<double> ip, chi2, bip, bchi2, bp_chi2;
          
          SmartRefVector<LHCb::Particle> parts = tagger.taggerParts();
          for(SmartRefVector<LHCb::Particle>::const_iterator it=parts.begin();
              it != parts.end(); it++) {
            
            VerboseData data = getVerboseData(*it, P);
            
            id.push_back(data.id);
            p.push_back(data.p);
            px.push_back(data.px);
            py.push_back(data.py);
            pz.push_back(data.pz);
            pt.push_back(data.pt);
            theta.push_back(data.theta);
            phi.push_back(data.phi);
            pid_e.push_back(data.pid_e);
            pid_mu.push_back(data.pid_mu);
            pid_k.push_back(data.pid_k);
            pid_p.push_back(data.pid_p);
            ip.push_back(data.ip);
            chi2.push_back(data.chi2);
            bip.push_back(data.bip);
            bchi2.push_back(data.bchi2);
            bp_chi2.push_back(data.bp_chi2);
          }
          
          const std::string num_name = prefix+"_"+name+"_PARTICLES_NUM";
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_ID", id.begin(), id.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_P", p.begin(), p.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PX", px.begin(), px.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PY", py.begin(), py.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PZ", pz.begin(), pz.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PT", pt.begin(), pt.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_THETA", theta.begin(), theta.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PHI", phi.begin(), phi.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PIDe", pid_e.begin(), pid_e.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PIDmu", pid_mu.begin(), pid_mu.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PIDk", pid_k.begin(), pid_k.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_PIDp", pid_p.begin(), pid_p.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_IP_OWNPV", ip.begin(), ip.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_IPCHI2_OWNPV", chi2.begin(), chi2.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_IP_BVertex", bip.begin(), bip.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_IPCHI2_BVertex", bchi2.begin(), bchi2.end(), num_name, 20 );
          test &= tuple->farray( prefix+"_"+name+"_PARTICLES_CHI2_BpVertex", bp_chi2.begin(), bp_chi2.end(), num_name, 20 );
        }        
      }      
    }    
  }
  

  if( msgLevel( MSG::DEBUG ) ){
    debug() << "Tagging summary: decision: " << dec
            << ", omega=" << omega << endreq;
  }

  return StatusCode(test);

}
//=========================================================================
//  Fill PV for all PV
//=========================================================================
StatusCode TupleToolGeometry::fillMinIP( const Particle* P,
                                         const std::string& prefix,
                                         Tuples::Tuple& tuple ) const
{
  bool test = true ;
  // minimum IP
  double ipmin = -1;
  double minchi2 = -1 ;

  double ipminnextbest = -1;
  double minchi2nextbest = -1;
  if(msgLevel(MSG::VERBOSE)) verbose() << "Looking for Min IP"  << endmsg  ;
  const RecVertex::Range PV = m_dva->primaryVertices();
  if(msgLevel(MSG::VERBOSE)) verbose() << "PV size: "  << PV.size() << endmsg  ;
  std::vector<double> ips, ipchi2s, diras;
  if ( !PV.empty() )
  {
    if(msgLevel(MSG::VERBOSE)) verbose() << "Filling IP " << prefix + "_MINIP : "
                                         << P << " PVs:" << PV.size() << endmsg ;

    for ( RecVertex::Range::const_iterator pv = PV.begin() ; pv!=PV.end() ; ++pv)
    {
      RecVertex newPV(**pv);
      if (m_refitPVs)
      {

        StatusCode scfit = m_pvReFitter->remove(P, &newPV);
        if(!scfit) { Warning("ReFitter fails!",StatusCode::SUCCESS,10).ignore(); continue; }
      }

      double ip, chi2;
      //StatusCode test2 = m_dist->distance ( P, *pv, ip, chi2 );

      LHCb::VertexBase* newPVPtr = (LHCb::VertexBase*)&newPV;
      StatusCode test2 = m_dist->distance ( P, newPVPtr, ip, chi2 );
      ips.push_back(ip);
      ipchi2s.push_back(chi2);
      if (P->endVertex()) diras.push_back(dira(newPVPtr,P));
      if( test2 && isVerbose() )
      {
        if ((ip<ipmin) || (ipmin<0.))
        {
          ipminnextbest = ipmin;
          ipmin = ip ;
        }
        else
        {
          if((ip < ipminnextbest) || (ipminnextbest < 0))
          {
            ipminnextbest = ip;
          }
        }

        if ((chi2<minchi2) || (minchi2<0.))
        {
          minchi2nextbest = minchi2;
          minchi2 = chi2 ;
        }
        else
        {
          if((chi2 < minchi2nextbest) || (minchi2nextbest < 0))
          {
            minchi2nextbest = chi2;
          }
        }
      }
    }
  }
  if (isVerbose()){
    if ( msgLevel(MSG::VERBOSE) )
    {
      verbose() << "Filling IP " << prefix + "_MINIP " << ipmin << " at " << minchi2 << endmsg  ;
      verbose() << "Filling IP next best " << prefix + "_MINIP " << ipminnextbest << " at "
                << minchi2nextbest << endmsg  ;
    }
    test &= tuple->column( prefix + "_MINIP", ipmin );
    test &= tuple->column( prefix + "_MINIPCHI2", minchi2 );
    
    test &= tuple->column( prefix + "_MINIPNEXTBEST", ipminnextbest );
    test &= tuple->column( prefix + "_MINIPCHI2NEXTBEST", minchi2nextbest );
  }
  if (m_fillMultiPV){
    test &= tuple->farray( prefix + "_AllIP", ips, "nPV", m_maxPV );
    test &= tuple->farray( prefix + "_AllIPchi2", ipchi2s, "nPV", m_maxPV );
    if (!diras.empty()) test &= tuple->farray( prefix + "_AllDIRA", diras, "nPV", m_maxPV );
    // --------------------------------------------------
  }
  
  if(msgLevel(MSG::VERBOSE))
    verbose() << "Return from fillMinIP: " << prefix  << " " << test << endmsg;
  if (!test)  Warning("Error in fillMinIP",1,StatusCode::FAILURE);
  return StatusCode(test) ;
}