Skip to content

Commit

Permalink
configure hypo tool and new Electron class
Browse files Browse the repository at this point in the history
  • Loading branch information
jlieberm committed May 16, 2024
1 parent 80f7f37 commit 002c207
Show file tree
Hide file tree
Showing 21 changed files with 349 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ add_subdirectory( events/CaloCluster )
add_subdirectory( events/EventInfo )
add_subdirectory( events/TruthParticle )
add_subdirectory( events/CaloRings )
add_subdirectory( events/Particle)

# reconstruction package
add_subdirectory( reconstruction/calorimeter/CaloCellBuilder )
Expand Down Expand Up @@ -100,6 +101,7 @@ add_library(lorenzetti SHARED
$<TARGET_OBJECTS:EventInfo>
$<TARGET_OBJECTS:TruthParticle>
$<TARGET_OBJECTS:CaloRings>
$<TARGET_OBJECTS:Particle>
$<TARGET_OBJECTS:SpacePoint>
$<TARGET_OBJECTS:CaloCellBuilder>
$<TARGET_OBJECTS:CaloClusterBuilder>
Expand Down
15 changes: 15 additions & 0 deletions events/Particle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

file(GLOB SOURCES src/*.cxx )
file(GLOB_RECURSE HEADERS Particle/*.h)

include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../core/GaugiKernel)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../core/G4Kernel)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../CaloCell)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../CaloCluster)

ROOT_GENERATE_DICTIONARY(ParticleDict ${HEADERS} LINKDEF ${CMAKE_CURRENT_SOURCE_DIR}/src/LinkDef.h MODULE Particle)

add_library(Particle OBJECT ${SOURCES} ParticleDict.cxx)
install(FILES ${HEADERS} DESTINATION Particle)
gaugi_install_python_modules( ${CMAKE_CURRENT_SOURCE_DIR}/python Particle)
48 changes: 48 additions & 0 deletions events/Particle/Particle/Electron.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef Electron_h
#define Electron_h

#include "CaloCluster/CaloCluster.h"
#include "CaloCell/CaloCell.h"
#include "GaugiKernel/EDM.h"
#include "GaugiKernel/macros.h"
#include <cmath>

namespace xAOD{

class Electron: public Gaugi::EDM
{
public:

/*! Contructor */
Electron();
/*! Contructor */
/*! Destructor */
~Electron()=default;

/*! The eta center of the cluster given by the simulation (RoI) */
PRIMITIVE_SETTER_AND_GETTER( float, m_eta, setEta, eta );
/*! The phi center of the cluster given by the simulation (RoI) */
PRIMITIVE_SETTER_AND_GETTER( float, m_phi, setPhi, phi );
/*! set/get energy */
PRIMITIVE_SETTER_AND_GETTER( float, m_e, setE, e );
/*! set/get transverse energy */
PRIMITIVE_SETTER_AND_GETTER( float, m_et, setEt, et );

void setDecisions (std::vector<bool> decisions ){ for (auto dec : decisions) m_decisions.push_back(dec); }
std::vector<bool> getDecisions() const {return m_decisions;}

void setCaloCluster( const xAOD::CaloCluster *clus ){ m_caloCluster=clus; };
const xAOD::CaloCluster* caloCluster() const { return m_caloCluster; };

private:
float m_e;
float m_et;
float m_eta;
float m_phi;

std::vector<bool> m_decisions;

const xAOD::CaloCluster *m_caloCluster;
};
}
#endif
11 changes: 11 additions & 0 deletions events/Particle/Particle/ElectronContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ElectronContainer_h
#define ElectronContainer_h

/** simulator includes **/
#include "Particle/Electron.h"
#include "GaugiKernel/DataVector.h"

namespace xAOD{
typedef SG::DataVector<xAOD::Electron> ElectronContainer;
}
#endif
38 changes: 38 additions & 0 deletions events/Particle/Particle/ElectronConverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef ElectronConverter_h
#define ElectronConverter_h

/** simulator includes **/
#include "Particle/Electron.h"
#include "CaloCluster/CaloClusterConverter.h"

namespace xAOD{

struct Electron_t{
int cluster_link;
float e;
float et;
float eta;
float phi;
std::vector<bool> decisions;
};

class ElectronConverter{

public:
ElectronConverter()=default;
~ElectronConverter()=default;

// convert a class object into a struct
bool convert( const Electron *, Electron_t & , cluster_links_t &) ;
bool convert( const Electron_t &electron_t, Electron *&electron );

private:

};



}
#endif


4 changes: 4 additions & 0 deletions events/Particle/python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

__all__ = []


11 changes: 11 additions & 0 deletions events/Particle/src/Electron.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Particle/Electron.h"
#include "G4Kernel/CaloPhiRange.h"

using namespace xAOD;


Electron::Electron():
EDM(),
m_caloCluster(nullptr)
{}

38 changes: 38 additions & 0 deletions events/Particle/src/ElectronConverter.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include "Particle/ElectronConverter.h"
//#include "G4Kernel/macros.h"

#include<iostream>
using namespace xAOD;
using namespace std;


bool ElectronConverter::convert( const Electron *electron, Electron_t &electron_t, cluster_links_t &cluster_links )
{
if(electron){

electron_t.cluster_link = cluster_links[electron->caloCluster()];
electron_t.eta = electron->eta();
electron_t.phi = electron->phi();
electron_t.et = electron->et();
electron_t.e = electron->e();
for (auto dec : electron->getDecisions() ) electron_t.decisions.push_back(dec);
return true;
}
return false;
}


bool ElectronConverter::convert( const Electron_t &electron_t, Electron *&electron)
{

electron = new xAOD::Electron();
electron->setEta(electron_t.eta);
electron->setPhi(electron_t.phi);
electron->setEt(electron_t.et);
electron->setE(electron_t.e);
electron->setDecisions(electron_t.decisions);

return true;

}
16 changes: 16 additions & 0 deletions events/Particle/src/LinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


#include "Particle/ElectronConverter.h"

#ifdef __CINT__


#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclass;
#pragma link C++ struct xAOD::Electron_t+;
#pragma link C++ class std::vector< xAOD::Electron_t >+;


#endif
1 change: 1 addition & 0 deletions physics/egamma/CaloCutBasedHypo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ file(GLOB SOURCES src/*.cxx)
file(GLOB_RECURSE HEADERS src/CaloCutBasedHypo.h )

include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../events/Particle)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../events/CaloCluster)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../events/CaloCell)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../events/CaloRings)
Expand Down
26 changes: 24 additions & 2 deletions physics/egamma/CaloCutBasedHypo/python/CaloCutBasedHypoTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,39 @@

class CaloCutBasedHypoTool( Cpp ):
def __init__( self, name,
InputClusterKey : str,
OutputElectronKey: str,
OutputLevel : str=0,
TightCuts : list=[],
MediumCuts : list=[],
LooseCuts : list=[],
VLooseCuts : list=[],
):
Cpp.__init__(self, ROOT.CaloCutBasedHypoTool(name) )
self.setProperty( "InputClusterKey" , InputClusterKey )
self.setProperty( "OutputElectronKey" , OutputElectronKey)
self.setProperty( "OutputLevel" , OutputLevel )
self.setProperty( "TightCuts" , TightCuts )
self.setProperty( "MediumCuts" , MediumCuts )
self.setProperty( "LooseCuts" , LooseCuts )
self.setProperty( "VLooseCuts" , VLooseCuts )



def CaloCutBasedHypoCfg( name : str,
InputClusterKey : str,
OutputElectronKey: str,
OutputLevel : int=0,

):

from .CaloCutMaps import CutBasedIsEM
hypo = CaloCutBasedHypoTool( "CaloCutBasedHypoTool",
OutputLevel = OutputLevel)
InputClusterKey = InputClusterKey,
OutputElectronKey = OutputElectronKey,
TightCuts = CutBasedIsEM().getCuts('tight'),
MediumCuts = CutBasedIsEM().getCuts('medium'),
LooseCuts = CutBasedIsEM().getCuts('loose'),
VLooseCuts = CutBasedIsEM().getCuts('vloose'),
OutputLevel = OutputLevel)
return hypo

24 changes: 24 additions & 0 deletions physics/egamma/CaloCutBasedHypo/python/CaloCutMaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
__all__ = ['CutBasedIsEM']

class CutBasedIsEM:
def __init__(self):

self.etHadCut = {'loose':[0.1218],
'medium':[0.0270375],
'tight':[0.0270375],
'vloose': [0.157]}

self.rEtaCut={'loose':[0.57],
'medium':[0.814625],
'tight':[0.83125],
'vloose':[0.752]}

self.eRatioCut = {'loose':[0.47],
'medium':[0.57],
'tight':[0.65],
'vloose':[0.52]}

def getCuts(self,workingPoint):
return [self.etHadCut[workingPoint],
self.rEtaCut[workingPoint],
self.eRatioCut[workingPoint],]
59 changes: 57 additions & 2 deletions physics/egamma/CaloCutBasedHypo/src/CaloCutBasedHypoTool.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ CaloCutBasedHypoTool::CaloCutBasedHypoTool( std::string name ) :
IMsgService(name),
Algorithm()
{
declareProperty( "OutputLevel" , m_outputLevel=1 );
declareProperty( "InputClusterKey", m_clusterKey="Clusters" );
declareProperty( "OutputElectronKey", m_electronKey="Electrons" );
declareProperty( "OutputLevel" , m_outputLevel=1 );
declareProperty( "TightCuts", m_tightCuts );
declareProperty( "MediumCuts", m_mediumCuts );
declareProperty( "LooseCuts", m_looseCuts );
declareProperty( "VLooseCuts", m_vlooseCuts );
}

//!=====================================================================
Expand All @@ -31,6 +37,7 @@ CaloCutBasedHypoTool::~CaloCutBasedHypoTool()

StatusCode CaloCutBasedHypoTool::initialize()
{
CHECK_INIT();
return StatusCode::SUCCESS;
}

Expand Down Expand Up @@ -59,7 +66,6 @@ StatusCode CaloCutBasedHypoTool::execute( EventContext &/*ctx*/, const G4Step *

StatusCode CaloCutBasedHypoTool::execute( EventContext &ctx, int /*evt*/ ) const
{
MSG_INFO("running hypo code");
return post_execute(ctx);
}

Expand All @@ -74,6 +80,27 @@ StatusCode CaloCutBasedHypoTool::finalize()

StatusCode CaloCutBasedHypoTool::post_execute( EventContext &ctx ) const
{
SG::WriteHandle<xAOD::ElectronContainer> electron(m_electronKey, ctx);
electron.record( std::unique_ptr<xAOD::ElectronContainer>(new xAOD::ElectronContainer()) );

SG::ReadHandle<xAOD::CaloClusterContainer> clusters(m_clusterKey, ctx);

for( const auto* clus : **clusters.ptr()){
auto el = new xAOD::Electron();
std::vector<bool> decisions;
decisions.push_back(computeDecision(clus,"tight"));
decisions.push_back(computeDecision(clus,"medium"));
decisions.push_back(computeDecision(clus,"loose"));
decisions.push_back(computeDecision(clus,"vloose"));
el->setDecisions(decisions);
el->setEta(clus->eta());
el->setPhi(clus->phi());
el->setEt(clus->et());
el->setE(clus->e());
el->setCaloCluster( clus );
electron->push_back( el );

}
return StatusCode::SUCCESS;
}

Expand All @@ -86,6 +113,34 @@ StatusCode CaloCutBasedHypoTool::fillHistograms(EventContext &ctx ) const

//!=====================================================================

bool CaloCutBasedHypoTool::computeDecision(const xAOD::CaloCluster* cluster, std::string workingPoint) const{
if (workingPoint == "tight"){
if (cluster->rhad() > m_tightCuts[0]) return false;
if (cluster->reta() < m_tightCuts[1]) return false;
if (cluster->eratio() < m_tightCuts[2]) return false;
return true;
}
if (workingPoint == "medium"){
if (cluster->rhad() > m_mediumCuts[0]) return false;
if (cluster->reta() < m_mediumCuts[1]) return false;
if (cluster->eratio() < m_mediumCuts[2]) return false;
return true;
}
if (workingPoint == "loose"){
if (cluster->rhad() > m_looseCuts[0]) return false;
if (cluster->reta() < m_looseCuts[1]) return false;
if (cluster->eratio() < m_looseCuts[2]) return false;
return true;
}
if (workingPoint == "vloose"){
if (cluster->rhad() > m_vlooseCuts[0]) return false;
if (cluster->reta() < m_vlooseCuts[1]) return false;
if (cluster->eratio() < m_vlooseCuts[2]) return false;
return true;
}
MSG_DEBUG("No working point adressed. Rejecting by default");
return false;

}


Loading

0 comments on commit 002c207

Please sign in to comment.