Skip to content
Snippets Groups Projects
Commit b55021bb authored by Ben Couturier's avatar Ben Couturier Committed by Mark Smith
Browse files

Import TupleB2XMother

parent df75ba64
No related branches found
No related tags found
3 merge requests!1039Fixed formatting,!1000Fixed formatting,!897Import TupleB2XMother
......@@ -33,6 +33,7 @@ gaudi_add_module(DecayTreeTupleMC
src/TupleToolMCPVAssociation.cpp
src/TupleToolMCTruth.cpp
src/TupleToolPV2MC.cpp
src/TupleToolB2XMother.cpp
LINK
Analysis::DecayTreeTupleBaseLib
Gaudi::GaudiAlgLib
......
/*****************************************************************************\
* (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
// from Gaudi
#include <Event/MCParticle.h>
#include <Event/Particle.h>
#include <GaudiAlg/Tuple.h>
#include <GaudiAlg/TupleObj.h>
#include <GenEvent/HepMCUtils.h>
#include <algorithm>
#include "TupleToolB2XMother.h"
//-----------------------------------------------------------------------------
// Implementation file for class : TupleToolB2XMother
//
// 2016-01-06 : Benedetto Gianluca Siddi
//-----------------------------------------------------------------------------
// Declaration of the Tool Factory
DECLARE_COMPONENT( TupleToolB2XMother )
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
TupleToolB2XMother::TupleToolB2XMother( const std::string& type, const std::string& name, const IInterface* parent )
: TupleToolBase( type, name, parent ) {
declareInterface<IMCParticleTupleTool>( this );
}
//=============================================================================
StatusCode TupleToolB2XMother::initialize() {
const StatusCode sc = TupleToolBase::initialize();
if ( sc.isFailure() ) return sc;
return StatusCode::SUCCESS;
}
//===========================================================================================
StatusCode TupleToolB2XMother::fill( const MCParticle* /* top */, const MCParticle* mcp, const std::string& head,
Tuples::Tuple& tuple ) {
if ( msgLevel( MSG::DEBUG ) ) debug() << "TupleToolB2XMother::fill entry:" << m_entry << endmsg;
// set test true
bool fromB = false;
bool fromD = false;
std::vector<int> ancestorIDs;
std::vector<int> ancestorKeys;
if ( mcp ) {
Int_t IDmcp = mcp->particleID().pid();
if ( msgLevel( MSG::DEBUG ) )
debug() << "HEAD: " << fullName( head ) << "\t"
<< "mcp ID: " << IDmcp << "\t" << endmsg;
const MCParticle* PMother = (const MCParticle*)ancestor( mcp, ancestorIDs, ancestorKeys );
fromB = PMother->particleID().hasBottom();
fromD = PMother->particleID().hasCharm();
}
const std::vector<int>::size_type ANCESTOR_NB = 15;
int vancestorIDs[ANCESTOR_NB] = {0};
int vancestorKeys[ANCESTOR_NB] = {0};
std::copy_n( ancestorIDs.begin(), std::min( ANCESTOR_NB, ancestorIDs.size() ), vancestorIDs );
std::copy_n( ancestorKeys.begin(), std::min( ANCESTOR_NB, ancestorKeys.size() ), vancestorKeys );
const std::string prefix = fullName( head );
debug() << "IDsSize: " << ancestorIDs.size() << "\t KeysSize: " << ancestorKeys.size() << endmsg;
bool test = true;
test &= tuple->column( prefix + "_PANC_fromB", fromB );
test &= tuple->column( prefix + "_PANC_fromD", fromD );
test &= tuple->array( prefix + "_PANC_IDs", vancestorIDs, vancestorIDs + sizeof( vancestorIDs ) / sizeof( int ) );
test &= tuple->array( prefix + "_PANC_Keys", vancestorKeys, vancestorKeys + sizeof( vancestorKeys ) / sizeof( int ) );
test &= tuple->column( prefix + "_N_ANC", (int)ancestorKeys.size() );
if ( test ) m_entry++;
return StatusCode( test );
}
//=============================================================================
// Get ancestor
//=============================================================================
const LHCb::MCParticle* TupleToolB2XMother::ancestor( const LHCb::MCParticle* imc, std::vector<int>& ancIDs,
std::vector<int>& ancKeys ) const {
if ( msgLevel( MSG::DEBUG ) ) {
debug() << "Part PID " << imc->particleID() << endmsg;
debug() << "Part Key " << imc->key() << endmsg;
}
ancIDs.push_back( imc->particleID().pid() );
ancKeys.push_back( imc->key() );
if ( imc->mother() ) {
const LHCb::MCParticle* mc_mom = imc->mother();
return ancestor( mc_mom, ancIDs, ancKeys );
} else {
return imc;
}
}
/*****************************************************************************\
* (c) Copyright 2022 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
#ifndef TupleToolB2XMother_H
#define TupleToolB2XMother_H 1
// Include files
// from Gaudi
//#include "GaudiAlg/GaudiTool.h"
#include "DecayTreeTupleBase/TupleToolBase.h"
#include "Kernel/IMCParticleTupleTool.h" // Interface
using namespace LHCb;
/** @class TupleToolB2XMother TupleToolB2XMother.h
*
* \brief extract ID and key of MC ancestor particles in a list.
*
* Extract columns with the list of ancestor IDs and ancestor keys for specified particles,
* as well as whether they are from B or D quarks.
*
* Tuple columns:
* - _PANC_IDs: ancestors particle IDs
* - _PANC_Keys: ancestors unique keys
* - _PANC_fromB: whether the particle if froma B quark
* - _PANC_fromD: : whether the particle if froma D quark
* - _N_ANC: number of ancestors
*
* \sa DecayTreeTuple
*
* @author Benedetto Gianluca Siddi
* @date 2016-01-07
*/
class TupleToolB2XMother : public TupleToolBase, virtual public IMCParticleTupleTool {
public:
/// Standard constructor
TupleToolB2XMother( const std::string& type, const std::string& name, const IInterface* parent );
virtual ~TupleToolB2XMother() = default; ///< Destructor
virtual StatusCode initialize() override;
virtual StatusCode fill( const LHCb::MCParticle*, const LHCb::MCParticle*, const std::string&,
Tuples::Tuple& ) override;
protected:
private:
const LHCb::MCParticle* ancestor( const LHCb::MCParticle*, std::vector<int>&, std::vector<int>& ) const;
int m_entry = 0;
};
#endif // TupleToolB2XMother_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment