Commit 063cd93c authored by Scott Snyder's avatar Scott Snyder Committed by Graeme Stewart
Browse files

Migrate AlgTool -> AthAlgTool. (AnalysisTools-00-06-02)

parent 7025c8f3
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_AANTEVENTCONTEXT_H
#define ANALYSISTOOLS_AANTEVENTCONTEXT_H
#include "GaudiKernel/IEvtSelector.h"
class IOpaqueAddress;
class AANTEventContext : virtual public IEvtSelector::Context {
public:
/// Constructor
AANTEventContext(const IEvtSelector* selector);
/// Copy constructor
AANTEventContext(const AANTEventContext& ctxt);
/// Assignment
AANTEventContext& operator= (const AANTEventContext& ctxt);
/// Destructor
virtual ~AANTEventContext();
/// Inequality operator.
virtual void* identifier() const;
private:
const IEvtSelector* m_evtSelector;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_AANTEVENTSELECTOR_H
#define ANALYSISTOOLS_AANTEVENTSELECTOR_H
// AANTEventSelector
// Include files.
#include "Python.h"
#include "AthenaBaseComps/AthService.h"
#include "GaudiKernel/IEvtSelector.h"
#include "GaudiKernel/IProperty.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/Bootstrap.h"
#include "Rtypes.h"
// Forward declarations.
class ISvcLocator;
class StoreGateSvc;
class TChain;
// Class AANTEventSelector.
class AANTEventSelector : virtual public AthService,
virtual public IEvtSelector,
virtual public IProperty
{
public:
// Standard Constructor.
AANTEventSelector(const std::string& name, ISvcLocator* svcloc);
// Standard Destructor.
~AANTEventSelector();
// Implementation of Service base class methods.
virtual StatusCode initialize();
// Implementation of the IEvtSelector interface methods.
virtual StatusCode createContext(Context*& it) const;
virtual StatusCode next(Context& it) const;
virtual StatusCode next(Context& it, int jump) const;
virtual StatusCode previous(Context& it) const;
virtual StatusCode previous(Context& it, int jump) const;
virtual StatusCode last(Context& it) const;
virtual StatusCode rewind(Context& it) const;
virtual StatusCode createAddress(const Context& it,IOpaqueAddress*& iop) const;
virtual StatusCode releaseContext(Context*& it) const;
virtual StatusCode resetCriteria(const std::string& criteria, Context& context) const;
// Implementation of IInterface methods.
virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface);
private:
// StoreGateSvc
StoreGateSvc *m_storeGate;
// property
StringArrayProperty m_inputCollectionsProp;
// Number of events to skip at the beginning
int m_skipEvents;
// Number of Events read so far.
mutable long m_numEvents;
// Total number of events
long m_totalNEvents;
// name of converter for TTree
std::string m_strConverter;
// name of selection criteria
std::string m_strSelection;
// TChain
TChain *m_tree;
Long64_t m_runNumber;
Long64_t m_eventNumber;
// Py I/F
PyObject *m_convFunc;
PyObject *m_selectionFunc;
};
struct AANTTreeGate
{
public:
static void setTree (TChain *chain) { m_tree = chain;}
static TChain * getTree () { return m_tree; }
private:
static TChain *m_tree;
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_AANTUPLEPARAMS_H
#define ANALYSISTOOLS_AANTUPLEPARAMS_H
namespace AANTupleParams
{
/// constants for AANTupleStream
static const char* c_tokenBranchName __attribute__((unused)) = "Token";
static const char* c_attributeListLayoutName __attribute__((unused)) = "Schema";
static const std::string c_treeName = "CollectionTree";
static const std::string c_streamName = "AANT";
/// ID of TTree
static const std::string c_TreeID = "/"+c_streamName+"/"+c_treeName;
// attributes
static const char* name_RunNumber __attribute__((unused)) = "RunNumber";
static const char* name_EventNumber __attribute__((unused)) = "EventNumber";
}
#endif
// dear emacs, this is -*- C++ -*-
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_AANTUPLESTREAM_H
#define ANALYSISTOOLS_AANTUPLESTREAM_H 1
#include "GaudiKernel/IAddressCreator.h"
#include "GaudiKernel/ServiceHandle.h"
#include "GaudiKernel/IIoComponent.h"
#include "AthenaBaseComps/AthAlgorithm.h"
#include <map>
#include <vector>
namespace coral
{
class AttributeList;
class AttributeListSpecification;
}
class StoreGateSvc;
class ITHistSvc;
class TFile;
class TTree;
class TBranch;
class AANTupleStream : virtual public IIoComponent,
public AthAlgorithm
{
public:
/// Standard AANTupleStream Constructor
AANTupleStream(const std::string& name, ISvcLocator* pSvcLocator);
/// Standard Destructor
virtual ~AANTupleStream();
/// Initialize AANTupleStream
virtual StatusCode initialize();
/// Terminate AANTupleStream
virtual StatusCode finalize();
/// Working entry point
virtual StatusCode execute();
private:
/// Initialize the output collection
StatusCode initCollection();
/// Get ref from a proxy
StatusCode getRef(CLID id, const std::string& key,
std::string& ref);
/// Split the address to get pool token
StatusCode splitAddress( const std::string& address,
const std::string& match,
std::string& address_header,
std::string& address_data ) const;
/// initialize sub-algos
StatusCode initialize_subAlgos ();
/// execute sub-algos
StatusCode execute_subAlgos ();
/// write schema of AttributeList
void writeAttributeListSpecification();
/// setup Tree
void setupTree();
/// write Token and AttributeList
bool writeTokenAttrList( const std::string& token, const coral::AttributeList& attributeList );
/// get filter alogs
StatusCode getFilters();
/// check filters passed
bool isEventAccepted() const;
StatusCode initSchema();
/** @brief callback method to reinitialize the internal state of
* the component for I/O purposes (e.g. upon @c fork(2))
*/
StatusCode io_reinit ();
/// Persistency service
ServiceHandle<IAddressCreator> m_persSvc;
/// Collection attribute specification
coral::AttributeListSpecification* m_attribSpec;
/// Name of the output collection
std::string m_fileName;
/// Vector of extra parent ref names to register in collection
StringArrayProperty m_extraRefNames;
/// Flag to signal whether or not to write input data header
BooleanProperty m_writeInputDH;
/// Flag to signal whether data header exists
BooleanProperty m_existDH;
/// Name of Stream
std::string m_streamName;
/// write schema in execute()
BooleanProperty m_lateSchema;
/// macro
std::string m_macro;
/// first event
bool m_schemaDone;
/// Name of the output tree
std::string m_treeName;
/// Vector of names of Algorithms that this stream accepts
std::vector<std::string> m_acceptNames;
/// Vector of Algorithms that this stream accepts
std::vector<Algorithm*> m_acceptAlgs;
/// TTree
TTree * m_tree;
/// TBranch which contains Token info
TBranch * m_tokenBranch;
/// THistSvc
ServiceHandle<ITHistSvc> m_tHistSvc;
// Sub-algorithms as given in jobOptions type/name
std::vector<std::string> m_membersNames;
/// for string branches
static const unsigned int c_maxLengthOfStrings = 5000;
char m_tokenCString[c_maxLengthOfStrings];
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_ANALYSISTOOLS_H
#define ANALYSISTOOLS_ANALYSISTOOLS_H
/**
This class structure is needed for component library
@author Tadashi Maeno
*/
#include "AnalysisTools/IAnalysisTools.h"
// interface ID
static const InterfaceID IID_IAnalysisTools("AnalysisTools", 1, 0);
class AnalysisTools : public IAnalysisTools
{
public:
/** constructor
*/
AnalysisTools ( const std::string& type, const std::string& name,
const IInterface* parent ) ;
/** initialize
*/
StatusCode initialize();
/** InterfaceID
*/
static const InterfaceID& interfaceID( )
{ return IID_IAnalysisTools; }
};
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_ANALYSISTOOLSDICT_H
#define ANALYSISTOOLS_ANALYSISTOOLSDICT_H 1
#include "AnalysisTools/AANTEventSelector.h"
#include "AnalysisTools/IAnalysisTools.h"
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef ANALYSISTOOLS_IANALYSISTOOLS_H
#define ANALYSISTOOLS_IANALYSISTOOLS_H
/**
This class provides a common interface to Analysis Tools
@author Tadashi Maeno
*/
#include <vector>
#include "AthenaBaseComps/AthAlgTool.h"
#include "NavFourMom/INavigable4MomentumCollection.h"
#include "McParticleEvent/TruthParticleContainer.h"
#include "AnalysisUtils/AnalysisMisc.h"
//class INavigable4Momentum;
//class INavigable4MomentumCollection; //this causes a problem in client packages (eg. AnalysisExamples) because it is now a typedef
class StoreGateSvc;
class IAnalysisTools : public AthAlgTool
{
public:
/** constructor
*/
IAnalysisTools ( const std::string& type, const std::string& name,
const IInterface* parent )
: AthAlgTool(type,name,parent)
{}
/** destructor
*/
virtual ~IAnalysisTools () {}
/** \Delta\phi
*/
double deltaPhi (const INavigable4Momentum *p1, const INavigable4Momentum *p2) const;
/** \Delta{R}
*/
double deltaR (const INavigable4Momentum *p1, const INavigable4Momentum *p2) const;
/** Invariant mass : 2 body
*/
double imass2 (const INavigable4Momentum *p1, const INavigable4Momentum *p2) const;
/** Invariant mass : 4 body
*/
double imass4 (const INavigable4Momentum *p1, const INavigable4Momentum *p2,
const INavigable4Momentum *p3, const INavigable4Momentum *p4) const;
/** find the closest (in R) element in a collection to an INavigable4Momentum
not check PDG ID
@param index [out] index of the closest element
@param deltaR [out] \Delta{R}
@return true if found
*/
template <class COLL> bool matchR
(const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR) const;
template <class COLL> bool matchR
(const double eta, const double phi, COLL *coll, int &index, double &deltaR) const;
bool matchR (const INavigable4Momentum *t, const TruthParticleContainer *coll,
int &index, double &deltaR, const bool genOnly=true) const
{
return AnalysisUtils::Match::R(t->eta(), t->phi(), coll, index, deltaR, genOnly);
}
bool matchR (const double eta, const double phi, const TruthParticleContainer *coll,
int &index, double &deltaR, const bool genOnly=true) const
{
return AnalysisUtils::Match::R(eta, phi, coll, index, deltaR, genOnly);
}
/** find the closest (in R) element in a collection to an INavigable4Momentum
not check PDG ID but a condition on E
@param index [out] index of the closest element
@param deltaR [out] \Delta{R}
@return true if found
*/
template <class COLL> bool matchR
(const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR, double &deltaE) const;
template <class COLL> bool matchR
(const double eta, const double phi, const double e, COLL *coll, int &index,
double &deltaR, double &deltaE) const;
bool matchR (const double eta, const double phi, const double e, const TruthParticleContainer *coll, int &index,
double &deltaR, double &deltaE, const bool genOnly=true) const
{
return AnalysisUtils::Match::R(eta, phi, e, coll, index, deltaR, deltaE, genOnly);
}
bool matchR (const INavigable4Momentum *t, const TruthParticleContainer *coll, int &index,
double &deltaR, double &deltaE, const bool genOnly=true) const
{
return AnalysisUtils::Match::R(t->eta(), t->phi(), t->e(), coll, index, deltaR, deltaE, genOnly);
}
/** find the closest (in R) element in a collection to an INavigable4Momentum
not check PDG ID
@param element [out] pointer to the closest element
@param deltaR [out] \Delta{R}
@return true if found
*/
template <class COLL, class ELEMENT> bool matchR
(const INavigable4Momentum *t, COLL *coll, ELEMENT *&element, double &deltaR) const;
template <class COLL, class ELEMENT> bool matchR
(const double eta, const double phi, COLL *coll, ELEMENT *&element, double &deltaR) const;
bool matchR (const INavigable4Momentum *t, const TruthParticleContainer *coll, const TruthParticle *&element,
double &deltaR, const bool genOnly=true) const
{
int index = 0;
bool ret = AnalysisUtils::Match::R(t,coll,index,deltaR, genOnly);
if (!ret) return false;
element = (*coll)[index];
return true;
}
bool matchR (const double eta, const double phi, const TruthParticleContainer *coll, const TruthParticle *&element,
double &deltaR, const bool genOnly=true) const
{
int index;
bool ret = AnalysisUtils::Match::R(eta,phi,coll,index,deltaR,genOnly);
if (!ret) return false;
element = (*coll)[index];
return true;
}
/** find the closest (in R) element in a collection to an INavigable4Momentum
not check PDG ID - with a condition on E
@param element [out] pointer to the closest element
@param deltaR [out] \Delta{R}
@return true if found
*/
template <class COLL, class ELEMENT> bool matchR
(const INavigable4Momentum *t, COLL *coll, ELEMENT *&element, double &deltaR, double &deltaE) const;
template <class COLL, class ELEMENT> bool matchR
(const double eta, const double phi, const double e, COLL *coll, ELEMENT *&element,
double &deltaR, double &deltaE) const;
bool matchR (const INavigable4Momentum *t, const TruthParticleContainer *coll, const TruthParticle *&element,
double &deltaR, double &deltaE, const bool genOnly=true) const
{
int index = -1;
bool ret = AnalysisUtils::Match::R(t,coll,index,deltaR, deltaE, genOnly);
if (!ret || index == -1) return false;
element = (*coll)[index];
return true;
}
bool matchR (const double eta, const double phi, const double e, const TruthParticleContainer *coll,
const TruthParticle *&element, double &deltaR, double &deltaE, const bool genOnly=true) const
{
int index = -1;
bool ret = AnalysisUtils::Match::R(eta,phi,e,coll,index,deltaR,deltaE,genOnly);
if (!ret || -1 == index) return false;
element = (*coll)[index];
return true;
}
/** find the closest (in R) element in a collection to an INavigable4Momentum
@param index [out] index of the closest element
@param deltaR [out] \Delta{R}
@return true if found
*/
template <class COLL> bool matchR
(const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR, const int pdg) const;
template <class COLL> bool matchR
(const double eta, const double phi, COLL *coll, int &index, double &deltaR, const int pdg) const;
bool matchR (const double eta, const double phi, const TruthParticleContainer *coll, int &index,
double &deltaR, const int pdg, const bool genOnly=true) const
{
return AnalysisUtils::Match::R(eta, phi, coll, index, deltaR, pdg, genOnly);
}
bool matchR (const INavigable4Momentum *t, const TruthParticleContainer *coll, int &index,
double &deltaR, const int pdg, const bool genOnly=true) const
{
return AnalysisUtils::Match::R(t->eta(), t->phi(), coll, index, deltaR, pdg, genOnly);
}
/** find the closest (in R) element in a collection to an INavigable4Momentum
@param index [out] index of the closest element
@param deltaR [out] \Delta{R}
@return true if found
*/
template <class COLL> bool matchR
(const INavigable4Momentum *t, COLL *coll, int &index, double &deltaR, const int pdg,
double &deltaE) const;
template <class COLL> bool matchR
(const double eta, const double phi, const double e, COLL *coll, int &index, double &deltaR,
const int pdg, double &deltaE) const;
bool matchR (const double eta, const double phi, const double e, const TruthParticleContainer *coll,