Commit dad4bab1 authored by Christos Anastopoulos's avatar Christos Anastopoulos Committed by Graeme Stewart
Browse files

Add Accessor for OQ word (xAODEgamma-00-01-24)

	* Add Accessor for OQ word
	* Tagged as xAODEgamma-00-01-24

2014-12-16 Christos Anastopoulos <Christos.Anastopoulos@cern.ch>

	* Organise the Helpers a bit better
	* Tagged as xAODEgamma-00-01-23

2014-12-15 Christos Anastopoulos <Christos.Anastopoulos@cern.ch>

	* Helper function for getting the Truth "Mother" electron
	* After popular request add a first implementation
	* Tagged as xAODEgamma-00-01-22

2014-12-11 Christos Anastopoulos <Christos.Anastopoulos@cern.ch>

	* Add new isolation methods (hope the last one from xAODPrimitives)
	* Tagged as xAODEgamma-00-01-21

...
(Long ChangeLog diff - truncated)
parent a5f5522c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/ */
// $Id: EgammaAccessors_v1.cxx 620915 2014-10-09 15:50:27Z christos $ // $Id: EgammaAccessors_v1.cxx 630766 2014-11-25 00:34:26Z christos $
// System include(s): // System include(s):
#include <iostream> #include <iostream>
...@@ -76,11 +76,48 @@ namespace xAOD { ...@@ -76,11 +76,48 @@ namespace xAOD {
DEFINE_ACCESSOR( float, depth ); DEFINE_ACCESSOR( float, depth );
default: default:
std::cerr << "xAOD::Egamma_v1 ERROR Unknown float ShowerShapeType (" std::cerr << "xAOD::Egamma ERROR Unknown float ShowerShapeType ("
<< type << ") requested" << std::endl; << type << ") requested" << std::endl;
return 0; return 0;
} }
} }
SG::AuxElement::Accessor< char >*
selectionMenuAccessorV1( xAOD::EgammaParameters::SelectionMenu menu )
{
switch( menu ) {
DEFINE_ACCESSOR( char, Loose);
DEFINE_ACCESSOR( char, Medium);
DEFINE_ACCESSOR( char, Tight);
DEFINE_ACCESSOR( char, LHLoose);
DEFINE_ACCESSOR( char, LHMedium);
DEFINE_ACCESSOR( char, LHTight);
DEFINE_ACCESSOR( char, MultiLepton);
default:
std::cerr << "xAOD::Egamma ERROR Unknown char ElectronSelectionMenu ("
<< menu << ") requested" << std::endl;
return 0;
}
}
SG::AuxElement::Accessor< unsigned int >*
selectionisEMAccessorV1( xAOD::EgammaParameters::SelectionisEM isEM )
{
switch( isEM ) {
DEFINE_ACCESSOR( unsigned int, isEMLoose);
DEFINE_ACCESSOR( unsigned int, isEMMedium);
DEFINE_ACCESSOR( unsigned int, isEMTight);
DEFINE_ACCESSOR( unsigned int, isEMLHLoose);
DEFINE_ACCESSOR( unsigned int, isEMLHMedium);
DEFINE_ACCESSOR( unsigned int, isEMLHTight);
DEFINE_ACCESSOR( unsigned int, isEMMultiLepton);
default:
std::cerr << "xAOD::Egamma ERROR Unknown unsigned int ElectronSelectionisEM ("
<< isEM << ") requested" << std::endl;
return 0;
}
}
} // namespace xAOD } // namespace xAOD
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/ */
// $Id: EgammaAccessors_v1.h 617292 2014-09-17 18:22:08Z christos $ // $Id: EgammaAccessors_v1.h 630766 2014-11-25 00:34:26Z christos $
#ifndef XAOD_EGAMMAACCESSORS_V1_H #ifndef XAOD_EGAMMAACCESSORS_V1_H
#define XAOD_EGAMMAACCESSORS_V1_H #define XAOD_EGAMMAACCESSORS_V1_H
...@@ -24,6 +24,12 @@ namespace xAOD { ...@@ -24,6 +24,12 @@ namespace xAOD {
SG::AuxElement::Accessor< float >* SG::AuxElement::Accessor< float >*
showerShapeAccessorV1( xAOD::EgammaParameters::ShowerShapeType type ); showerShapeAccessorV1( xAOD::EgammaParameters::ShowerShapeType type );
SG::AuxElement::Accessor< char >*
selectionMenuAccessorV1( xAOD::EgammaParameters::SelectionMenu menu ) ;
SG::AuxElement::Accessor< unsigned int >*
selectionisEMAccessorV1( xAOD::EgammaParameters::SelectionisEM isEM ) ;
} // namespace xAOD } // namespace xAOD
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "xAODEgamma/EgammaTruthxAODHelpers.h"
#include "xAODEgamma/Egamma.h"
#include "xAODEgamma/Photon.h"
#include "xAODEgamma/Electron.h"
#include "xAODTruth/TruthVertex.h"
#include "xAODTruth/TruthParticle.h"
#include "xAODTruth/TruthParticleContainer.h"
#include "xAODEgamma/ElectronContainer.h"
#include "xAODEgamma/PhotonContainer.h"
// ==================================================================
const xAOD::TruthParticle* xAOD::EgammaHelpers::getTruthParticle(const xAOD::IParticle* particle, bool debug /* =false */){
return getLink<xAOD::TruthParticle>(particle, "truthParticleLink", debug);
}
int xAOD::EgammaHelpers::getParticleTruthType(const xAOD::IParticle* particle){
static SG::AuxElement::Accessor<int> tT("truthType") ;
if (!tT.isAvailable(*particle)) return 0;
return tT(*particle);
}
int xAOD::EgammaHelpers::getParticleTruthOrigin(const xAOD::IParticle* particle){
static SG::AuxElement::Accessor<int> tO("truthOrigin") ;
if (!tO.isAvailable(*particle)) return 0;
return tO(*particle);
}
// ==================================================================
const xAOD::Electron* xAOD::EgammaHelpers::getRecoElectron(const xAOD::TruthParticle* particle, bool debug /* =false */){
return getLink<xAOD::Electron>(particle, "recoElectronLink", debug);
}
const xAOD::Photon* xAOD::EgammaHelpers::getRecoPhoton(const xAOD::TruthParticle* particle, bool debug /* =false */){
return getLink<xAOD::Photon>(particle, "recoPhotonLink", debug);
}
// ==================================================================
//Is the object matched to a true converted photon with R < maxRadius
bool xAOD::EgammaHelpers::isTrueConvertedPhoton(const xAOD::Photon* ph, float maxRadius /* = 800. */){
const xAOD::TruthParticle *truthPh = xAOD::EgammaHelpers::getTruthParticle(ph);
if (!truthPh) {return false;}
// In older versions egammaTruthParticles did not have a decay vertex associated
// so we look for the original truth particle
if (truthPh->hasDecayVtx()){
return isTrueConvertedPhoton(truthPh, maxRadius);
}
const xAOD::TruthParticle *orgTruthPh = xAOD::EgammaHelpers::getTruthParticle(truthPh);
if (!orgTruthPh){ return false;}
return xAOD::EgammaHelpers::isTrueConvertedPhoton(orgTruthPh, maxRadius);
}
//Is the true object a converted photon with R < maxRadius
bool xAOD::EgammaHelpers::isTrueConvertedPhoton(const xAOD::TruthParticle* truthPh, float maxRadius /*= 800.*/){
return (truthPh->pdgId() == 22 && truthPh->hasDecayVtx()
&& truthPh->decayVtx()->perp() < maxRadius);
}
// ==================================================================
const xAOD::TruthParticle* xAOD::EgammaHelpers::getMotherElectron(const xAOD::Electron* el){
const xAOD::TruthParticle *truthel = xAOD::EgammaHelpers::getTruthParticle(el);
return getMotherElectron(truthel);
}
const xAOD::TruthParticle* xAOD::EgammaHelpers::getMotherElectron(const xAOD::TruthParticle* truthel){
if (!truthel || truthel->absPdgId()!=11){ //Truth must exist and be an electron
return 0;
}
for (size_t i =0;i < truthel->nParents();++i){ //Loop over the truth electron parents
const xAOD::TruthParticle *elparent = truthel->parent(i);
if(elparent->absPdgId() ==11){ //e->gamma+e case
return elparent;
}
else if(elparent->pdgId() ==22) { //Photon parent, lets check if it comes from an electron
//Loop over the truth photon parents (electron grandparents)
for (size_t j =0 ;j<elparent->nParents();++j){
const xAOD::TruthParticle *elgrandparent = elparent->parent(j);
if(elgrandparent->absPdgId() ==11){ //Photon comes from an electron
return elgrandparent;
}
}//Loop over grandparents
} // Parent is Photon
}//Loop over parents
return 0;
}
// ==================================================================
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "xAODEgamma/versions/Egamma_v1.h" #include "xAODEgamma/versions/Egamma_v1.h"
#include "EgammaAccessors_v1.h" #include "EgammaAccessors_v1.h"
#include "xAODPrimitives/tools/getIsolationAccessor.h" #include "xAODPrimitives/tools/getIsolationAccessor.h"
#include "xAODPrimitives/tools/getIsolationCorrectionAccessor.h"
#include <stdexcept> #include <stdexcept>
namespace xAOD { namespace xAOD {
...@@ -117,6 +117,11 @@ namespace xAOD { ...@@ -117,6 +117,11 @@ namespace xAOD {
Egamma_v1::EgammaCovMatrix_t Egamma_v1::covMatrix() const{ Egamma_v1::EgammaCovMatrix_t Egamma_v1::covMatrix() const{
static Accessor< std::vector<float> > acc( "EgammaCovarianceMatrix" ); static Accessor< std::vector<float> > acc( "EgammaCovarianceMatrix" );
if(!acc.isAvailable( *this) ) {
EgammaCovMatrix_t dummy;
dummy.setZero();
return dummy;
}
const std::vector<float>& v = acc(*this); const std::vector<float>& v = acc(*this);
return Eigen::Map<const EgammaCovMatrix_t> (v.data()); return Eigen::Map<const EgammaCovMatrix_t> (v.data());
} }
...@@ -147,13 +152,13 @@ namespace xAOD { ...@@ -147,13 +152,13 @@ namespace xAOD {
/////////////// /////////////// shower shapes
bool Egamma_v1::showerShapeValue(float& value, const EgammaParameters::ShowerShapeType information) const { bool Egamma_v1::showerShapeValue(float& value, const EgammaParameters::ShowerShapeType information) const {
xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information ); xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information );
if( ! acc ) { if( !acc ) {
return false; return false;
} }
if(! acc->isAvailable( *this) ) { if(!acc->isAvailable( *this) ) {
return false; return false;
} }
// Retrieve the value: // Retrieve the value:
...@@ -163,26 +168,26 @@ namespace xAOD { ...@@ -163,26 +168,26 @@ namespace xAOD {
float Egamma_v1::showerShapeValue(const EgammaParameters::ShowerShapeType information) const { float Egamma_v1::showerShapeValue(const EgammaParameters::ShowerShapeType information) const {
xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information ); xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information );
if(! acc ) throw std::runtime_error( "Unknown/Unavailable Shower Shape type requested" ); if(!acc ) throw std::runtime_error( "Unknown/Unavailable Shower Shape type requested" );
return ( *acc )( *this ); return ( *acc )( *this );
} }
bool Egamma_v1::setShowerShapeValue(float value, const EgammaParameters::ShowerShapeType information){ bool Egamma_v1::setShowerShapeValue(float value, const EgammaParameters::ShowerShapeType information){
xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information ); xAOD::Egamma_v1::Accessor< float >* acc = showerShapeAccessorV1( information );
if( ! acc ) return false; if( !acc ) return false;
// Set the value: // Set the value:
( *acc )( *this ) = value; ( *acc )( *this ) = value;
return true; return true;
} }
/////////////// /////////////// Isolation value
bool Egamma_v1::isolationValue(float& value, const Iso::IsolationType information) const { bool Egamma_v1::isolationValue(float& value, const Iso::IsolationType information) const {
SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information ); SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information );
if( ! acc ) { if( !acc ) {
return false; return false;
} }
if(! acc->isAvailable( *this) ) { if(!acc->isAvailable( *this) ) {
return false; return false;
} }
// Retrieve the value: // Retrieve the value:
...@@ -192,22 +197,140 @@ namespace xAOD { ...@@ -192,22 +197,140 @@ namespace xAOD {
float Egamma_v1::isolationValue( const Iso::IsolationType information) const { float Egamma_v1::isolationValue( const Iso::IsolationType information) const {
SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information ); SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information );
if( ! acc ) throw std::runtime_error( "Unknown/Unavailable Isolation type requested" ); if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation type requested" );
return ( *acc )( *this ); return ( *acc )( *this );
} }
bool Egamma_v1::setIsolationValue(float value, const Iso::IsolationType information) { bool Egamma_v1::setIsolationValue(float value, const Iso::IsolationType information) {
SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information ); SG::AuxElement::Accessor< float >* acc = getIsolationAccessor( information );
if( ! acc ) return false; if( !acc ) return false;
// Set the value:
( *acc )( *this ) = value;
return true;
}
/////////////// Isolation corrections
bool Egamma_v1::isolationCaloCorrection(float& value, const Iso::IsolationFlavour flavour, const Iso::IsolationCaloCorrection corr,
const Iso::IsolationCorrectionParameter param) const{
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr,param);
if( !acc ) {
return false;
}
if(!acc->isAvailable( *this) ) {
return false;
}
// Retrieve the value:
value = ( *acc )( *this );
return true;
}
float Egamma_v1::isolationCaloCorrection(const Iso::IsolationFlavour flavour, const Iso::IsolationCaloCorrection corr,
const Iso::IsolationCorrectionParameter param) const{
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr,param);
if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation correction requested" );
return ( *acc )( *this );
}
bool Egamma_v1::setIsolationCaloCorrection(float value, const Iso::IsolationFlavour flavour, const Iso::IsolationCaloCorrection corr,
const Iso::IsolationCorrectionParameter param){
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr,param);
if( !acc ) return false;
// Set the value:
( *acc )( *this ) = value;
return true;
}
bool Egamma_v1::isolationCaloCorrection(float& value, Iso::IsolationType type , Iso::IsolationCaloCorrection corr) const{
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(type,corr);
if( !acc ) {
return false;
}
if(!acc->isAvailable( *this) ) {
return false;
}
// Retrieve the value:
value = ( *acc )( *this );
return true;
}
float Egamma_v1::isolationCaloCorrection(Iso::IsolationType type, Iso::IsolationCaloCorrection corr) const{
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(type,corr);
if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation correction requested" );
return ( *acc )( *this );
}
bool Egamma_v1::setIsolationCaloCorrection(float value, Iso::IsolationType type, Iso::IsolationCaloCorrection corr){
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(type,corr);
if( !acc ) return false;
// Set the value:
( *acc )( *this ) = value;
return true;
}
bool Egamma_v1::isolationTrackCorrection(float& value, const Iso::IsolationFlavour flavour, const Iso::IsolationTrackCorrection corr) const{
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr);
if( !acc ) {
return false;
}
if(!acc->isAvailable( *this) ) {
return false;
}
// Retrieve the value:
value = ( *acc )( *this );
return true;
}
float Egamma_v1::isolationTrackCorrection(const Iso::IsolationFlavour flavour, const Iso::IsolationTrackCorrection corr) const{
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr);
if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation correction requested" );
return ( *acc )( *this );
}
bool Egamma_v1::setIsolationTrackCorrection(float value, const Iso::IsolationFlavour flavour, const Iso::IsolationTrackCorrection corr){
SG::AuxElement::Accessor< float >* acc = getIsolationCorrectionAccessor(flavour,corr);
if( !acc ) return false;
// Set the value: // Set the value:
( *acc )( *this ) = value; ( *acc )( *this ) = value;
return true; return true;
} }
bool Egamma_v1::isolationCorrectionBitset(uint32_t& value, const Iso::IsolationFlavour flavour ) const{
SG::AuxElement::Accessor< uint32_t >* acc = getIsolationCorrectionBitsetAccessor( flavour );
if( !acc ) {
return false;
}
if(!acc->isAvailable( *this) ) {
return false;
}
// Retrieve the value:
value = ( *acc )( *this );
return true;
}
uint32_t Egamma_v1::isolationCorrectionBitset(const Iso::IsolationFlavour flavour ) const{
SG::AuxElement::Accessor< uint32_t >* acc = getIsolationCorrectionBitsetAccessor( flavour );
if( !acc ) throw std::runtime_error( "Unknown/Unavailable Isolation BitSet requested" );
return ( *acc )( *this );
}
bool Egamma_v1::setIsolationCorrectionBitset(uint32_t value, const Iso::IsolationFlavour flavour ) {
SG::AuxElement::Accessor< uint32_t >* acc = getIsolationCorrectionBitsetAccessor( flavour );
if( !acc ) return false;
// Set the value:
( *acc )( *this ) = value;
return true;
}
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
/// Implementation of the CaloCluster accessor functions /// Implementation of the CaloCluster accessor functions
size_t Egamma_v1::nCaloClusters() const { size_t Egamma_v1::nCaloClusters() const {
static SG::AuxElement::Accessor< Egamma_v1::CLELVec_t > static SG::AuxElement::Accessor< Egamma_v1::CLELVec_t >
...@@ -251,16 +374,75 @@ namespace xAOD { ...@@ -251,16 +374,75 @@ namespace xAOD {
uint32_t OQ = acc( *this ); uint32_t OQ = acc( *this );
return (OQ & mask)==0; return (OQ & mask)==0;
} }
uint32_t Egamma_v1::OQ() const{
static Accessor< uint32_t > acc( "OQ" );
return acc( *this) ;
}
void Egamma_v1::setOQ(uint32_t newOQ) { void Egamma_v1::setOQ(uint32_t newOQ) {
static Accessor< uint32_t > acc( "OQ" ); static Accessor< uint32_t > acc( "OQ" );
acc( *this) = newOQ; acc( *this) = newOQ;
} }
/////////// ///////////
///Selectors / isEM and all that
///First with enums (static accessor no lookup => faster but less flexible)
bool Egamma_v1::passSelection(bool& value, const xAOD::EgammaParameters::SelectionMenu menu ) const {
SG::AuxElement::Accessor< char >* acc = selectionMenuAccessorV1( menu );
if( !acc ) {
return false;
}
if(!acc->isAvailable( *this) ) {
return false;
}
value= (*acc)( *this );
return true;
}
bool Egamma_v1::passSelection(const xAOD::EgammaParameters::SelectionMenu menu ) const {
SG::AuxElement::Accessor< char >* acc = selectionMenuAccessorV1( menu );
if(!acc ) throw std::runtime_error( "Unknown/Unavailable bool selection menu requested" );
return (*acc)( *this );
}
void Egamma_v1::setPassSelection(bool value, const xAOD::EgammaParameters::SelectionMenu menu){
SG::AuxElement::Accessor< char >* acc = selectionMenuAccessorV1( menu );
( *acc )( *this )=value;
return;
}
bool Egamma_v1::selectionisEM(unsigned int& value, const xAOD::EgammaParameters::SelectionisEM isEM) const {
SG::AuxElement::Accessor< unsigned int >* acc = selectionisEMAccessorV1( isEM );
if(!acc ) {
return false;
}
if(!acc->isAvailable( *this) ) {
return false;
}
value= (*acc)( *this );
return true;
}
unsigned int Egamma_v1::selectionisEM(const xAOD::EgammaParameters::SelectionisEM isEM) const {
SG::AuxElement::Accessor< unsigned int >* acc = selectionisEMAccessorV1( isEM );
if(!acc ) throw std::runtime_error( "Unknown/Unavailable unsigned int isEM requested" );
return (*acc)( *this );
}
void Egamma_v1::setSelectionisEM(unsigned int value, const xAOD::EgammaParameters::SelectionisEM isEM){
SG::AuxElement::Accessor< unsigned int >* acc = selectionisEMAccessorV1( isEM );
( *acc )( *this )=value;
return;
}
///Then with strings (full flexibility)
bool Egamma_v1::passSelection(bool& value, const std::string& menu ) const { bool Egamma_v1::passSelection(bool& value, const std::string& menu ) const {
SG::AuxElement::Accessor< char > acc( menu ); SG::AuxElement::Accessor< char > acc( menu );
if(! acc.isAvailable( *this) ) { if(!acc.isAvailable( *this) ) {
return false; return false;
} }
value= (acc)( *this ); value= (acc)( *this );
...@@ -277,8 +459,47 @@ namespace xAOD { ...@@ -277,8 +459,47 @@ namespace xAOD {
( acc )( *this )=value; ( acc )( *this )=value;
return; return;
} }
bool Egamma_v1::selectionisEM(unsigned int& value, const std::string& isEM) const{
SG::AuxElement::Accessor< unsigned int > acc( isEM );
if(!acc.isAvailable( *this) ) {
return false;
}
value= (acc)( *this );
return true;
}
unsigned int Egamma_v1::selectionisEM(const std::string& isEM) const{
SG::AuxElement::Accessor< unsigned int > acc( isEM );
return (acc)( *this );
}
void Egamma_v1::setSelectionisEM(unsigned int value, const std::string& isEM){
SG::AuxElement::Accessor< unsigned int > acc( isEM );
( acc )( *this )=value;
return;
}
bool Egamma_v1::likelihoodValue(float& value, const std::string& LHValue/*=std::string("LHValue")*/) const{
SG::AuxElement::Accessor<float> acc( LHValue );
if(!acc.isAvailable( *this) ) {
return false;
}
value= (acc)( *this );
return true;
}