Skip to content

Commit

Permalink
reshape
Browse files Browse the repository at this point in the history
  • Loading branch information
jodafons committed Oct 6, 2023
1 parent 372e9d8 commit 98e2b10
Show file tree
Hide file tree
Showing 37 changed files with 520 additions and 431 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ add_subdirectory( core/G4Kernel )
# event packages
add_subdirectory( events/CaloHit )
add_subdirectory( events/CaloCell )
#add_subdirectory( events/SpacePoint )
add_subdirectory( events/SpacePoint )
#add_subdirectory( events/CaloCluster )
add_subdirectory( events/EventInfo )
add_subdirectory( events/TruthParticle )
Expand Down Expand Up @@ -99,7 +99,7 @@ add_library(lorenzetti SHARED
$<TARGET_OBJECTS:EventInfo>
$<TARGET_OBJECTS:TruthParticle>
#$<TARGET_OBJECTS:CaloRings>
#$<TARGET_OBJECTS:SpacePoint>
$<TARGET_OBJECTS:SpacePoint>
$<TARGET_OBJECTS:CaloCellBuilder>
#$<TARGET_OBJECTS:CaloClusterBuilder>
#$<TARGET_OBJECTS:CaloRingsBuilder>
Expand Down
10 changes: 8 additions & 2 deletions core/G4Kernel/python/ComponentAccumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

class ComponentAccumulator( Logger ):

__allow_keys = ["NumberOfThreads", "OutputFile", "RunVis", "Seed", "Timeout", "VisMac"]
__allow_keys = [
"Seed",
"NumberOfThreads",
"OutputFile",
"RunVis",
"Timeout",
"VisMac",
]

def __init__( self, name , detector, **kw):

Expand Down Expand Up @@ -96,7 +103,6 @@ def detector(self):
def merge(self):
files = ' '.join(self.outputFiles)
command = f"hadd -f {self.OutputFile} {files}"
print( command )
os.system(command)
# remove thread files
for fname in self.outputFiles:
Expand Down
15 changes: 9 additions & 6 deletions core/G4Kernel/python/EventReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
class EventReader( Logger ):

__allow_keys = [
"EventKey",
"TruthKey",
"SeedKey",
# input
"InputFileName",
# outputs
"OutputEventKey",
"OutputTruthKey",
"OutputSeedKey",
# parameters
"BunchDuration",
"FileName",
]


Expand All @@ -28,9 +31,9 @@ def __init__( self, name, **kw ):
for key, value in kw.items():
self.setProperty( key,value )

if self.getProperty("FileName") != "":
if self.getProperty("InputFileName") != "":
from ROOT import TFile, TTree
f = TFile( self.getProperty("FileName") )
f = TFile( self.getProperty("InputFileName") )
t = f.Get("particles")
self.__entries = t.GetEntries()
f.Close()
Expand Down
24 changes: 13 additions & 11 deletions core/G4Kernel/src/EventReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ EventReader::EventReader(std::string name):
PrimaryGenerator(),
m_evt(0)
{
ROOT::EnableThreadSafety();
declareProperty( "FileName", m_filename="" );
declareProperty( "EventKey", m_eventKey="EventInfo" );
declareProperty( "TruthKey", m_truthKey="Particles" );
declareProperty( "SeedKey" , m_seedKey="Seed" );
declareProperty( "BunchDuration", m_bc_duration=25*ns );
ROOT::EnableThreadSafety();

declareProperty( "InputFileName" , m_filename="" );
declareProperty( "OutputEventKey" , m_eventKey="EventInfo" );
declareProperty( "OutputTruthKey" , m_truthKey="Particles" );
declareProperty( "OutputSeedKey" , m_seedKey="Seed" );
declareProperty( "BunchDuration" , m_bc_duration=25*ns );

}

PrimaryGenerator* EventReader::copy()
{
auto *gun = new EventReader(getLogName());
gun->setProperty( "FileName", m_filename );
gun->setProperty( "EventKey", m_eventKey );
gun->setProperty( "TruthKey", m_truthKey );
gun->setProperty( "SeedKey" , m_seedKey );
gun->setProperty( "BunchDuration", m_bc_duration);
gun->setProperty( "InputFileName" , m_filename );
gun->setProperty( "OutputEventKey", m_eventKey );
gun->setProperty( "OutputTruthKey", m_truthKey );
gun->setProperty( "OutputSeedKey" , m_seedKey );
gun->setProperty( "BunchDuration" , m_bc_duration);
return gun;
}

Expand Down
21 changes: 7 additions & 14 deletions events/CaloCell/CaloCell/CaloCellConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
/** simulator includes **/
#include "CaloCell/CaloCellContainer.h"
#include "CaloCell/CaloDetDescriptor.h"
#include "GaugiKernel/DataHandle.h"

namespace xAOD{

namespace xAOD{

typedef std::map<const xAOD::CaloCell*, int> cell_links_t;

Expand Down Expand Up @@ -48,35 +49,27 @@ namespace xAOD{
int cell_link;
};

class CaloCellConverter: public MsgService{
class CaloCellConverter{

public:
CaloCellConverter( std::string seedKey, float etaWindow, float phiWindow):
IMsgService(),m_seedKey(seedKey), m_etaWindow(etaWindow), m_phiWindow(phiWindow){;};
m_seedKey(seedKey), m_etaWindow(etaWindow), m_phiWindow(phiWindow){;};

~CaloCellConverter()=default;

std::string key(){return m_key;};

bool serialize( std::string &, SG::EventContext &/*ctx*/, TTree * );
bool deserialize( std::string &, int &, TTree *, SG::EventContext &/*ctx*/);
bool serialize( std::string &, SG::EventContext &/*ctx*/, TTree * ) const;
bool deserialize( std::string &, int &, TTree *, SG::EventContext &/*ctx*/) const;

private:

// convert a class object into a struct
bool convert(const CaloCell * , CaloCell_t & , int link) const;
bool convert(const CaloCell_t & , CaloCell *& ) const;
bool convert(const CaloDetDescriptor * , CaloDetDescriptor_t &, int link ) const;
bool convert(const CaloDetDescriptor_t &, CaloDetDescriptor *& ) const;

template <class T> bool InitBranch(TTree* fChain, std::string branch_name, T* param) const;
private:

std::vector<xAOD::CaloCell_t> m_cells_t;
std::vector<xAOD::CaloDetDescriptor_t> m_descriptors_t;
std::string m_seedKey;
float m_etaWindow, m_phiWindow;

std::string m_key;
};
}
#endif
Expand Down
57 changes: 16 additions & 41 deletions events/CaloCell/src/CaloCellConverter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,27 @@ bool CaloCellConverter::convert( const CaloCell_t &cell_t, CaloCell *&cell ) con
}


bool CaloCellConverter::serialize( std::string &key, SG::EventContext &ctx, TTree *tree)
bool CaloCellConverter::serialize( std::string &key, SG::EventContext &ctx, TTree *tree) const
{
m_key = "CaloCellContainer_" + key;

m_cells_t.clear();
m_descriptors_t.clear();
std::vector<xAOD::CaloCell_t> cells_t;
std::vector<xAOD::CaloDetDescriptor_t> descriptors_t;

MSG_INFO( "Create and link all branches..." );
tree->Branch( m_key.c_str() , &m_cells_t );
// aux container for calo cells
tree->Branch( ("CaloDetDescriptorContainer_"+key).c_str(), &m_descriptors_t );
auto branch_cells = tree->Branch( ("CaloCellContainer_" + key).c_str() , &cells_t );
auto branch_desc = tree->Branch( ("CaloDetDescriptorContainer_"+key).c_str(), &descriptors_t );


MSG_DEBUG("Serialize CaloCells...");
xAOD::cell_links_t cell_links;
xAOD::cell_links_t cell_links;

SG::ReadHandle<xAOD::CaloCellContainer> container(key, ctx);
if( !container.isValid() )
{
MSG_FATAL("It's not possible to read the xAOD::CaloCellContainer from this Contaxt using this key " << key );
return false;
}

SG::ReadHandle<xAOD::EventSeedContainer> seeds( m_seedKey, ctx);
if( !seeds.isValid() )
{
MSG_FATAL("It's not possible to read the xAOD::EventSeedContainer from this Context using this key " << m_seedKey );
return false;
}

int link = 0; // decorate all cells
Expand All @@ -147,31 +142,28 @@ bool CaloCellConverter::serialize( std::string &key, SG::EventContext &ctx, TTre
convert( descriptor, descriptor_t, link);
link++;
}
m_cells_t.push_back(cell_t);
m_descriptors_t.push_back(descriptor_t);
cells_t.push_back(cell_t);
descriptors_t.push_back(descriptor_t);
}// check if cell is inside of the window
}// loop over all cells
}// loop over all seeds

branch_cells->Fill();
branch_desc->Fill();

return true;
}


bool CaloCellConverter::deserialize( std::string &key , int &evt, TTree* tree, SG::EventContext &ctx)
bool CaloCellConverter::deserialize( std::string &key , int &evt, TTree* tree, SG::EventContext &ctx) const
{
m_key = "CaloCellContainer_" + key;
std::vector<xAOD::CaloCell_t> cells_t;
std::vector<xAOD::CaloDetDescriptor_t> descriptors_t;

MSG_DEBUG( "Link all branches..." );

InitBranch( tree, m_key.c_str() , &cells_t );
// aux container for calo cells
InitBranch( tree, ("CaloDetDescriptorContainer_"+key).c_str() , &descriptors_t );

tree->SetBranchAddress( ("CaloCellContainer_" +key).c_str() , &cells_t );
tree->SetBranchAddress( ("CaloDetDescriptorContainer_"+key).c_str() , &descriptors_t );
tree->GetEntry( evt );

// deserialize Cells
std::map<int, xAOD::CaloDetDescriptor*> descriptor_links;

int link=0;
Expand All @@ -196,20 +188,3 @@ bool CaloCellConverter::deserialize( std::string &key , int &evt, TTree* tree, S

return true;
}


template <class T>
bool CaloCellConverter::InitBranch(TTree* fChain, std::string branch_name, T* seedam) const
{
std::string bname = branch_name;
if (fChain->GetAlias(bname.c_str()))
bname = std::string(fChain->GetAlias(bname.c_str()));

if (!fChain->FindBranch(bname.c_str()) ) {
MSG_WARNING( "unknown branch " << bname );
return false;
}
fChain->SetBranchStatus(bname.c_str(), 1.);
fChain->SetBranchAddress(bname.c_str(), seedam);
return true;
}
26 changes: 9 additions & 17 deletions events/CaloHit/CaloHit/CaloHitConverter.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef CaloHitConverter_h
#define CaloHitConverter_h

/** simulator includes **/
#include "CaloHit/CaloHitContainer.h"
#include "GaugiKernel/DataHandle.h"

namespace xAOD{

Expand All @@ -26,36 +26,28 @@ namespace xAOD{
};


class CaloHitConverter: public MsgService{
class CaloHitConverter{

public:

CaloHitConverter( std::string seedKey, bool onlyRoi,
float etaWindow, float phiWindow):IMsgService(),m_seedKey(seedKey), m_onlyRoi(onlyRoi),
m_etaWindow(etaWindow),m_phiWindow(phiWindow){;};
CaloHitConverter( std::string seedKey, bool onlyRoi, float etaWindow, float phiWindow):
m_seedKey(seedKey), m_onlyRoi(onlyRoi),m_etaWindow(etaWindow),m_phiWindow(phiWindow){;};

~CaloHitConverter()=default;

std::string key(){return m_key;};

bool serialize( std::string &, SG::EventContext &/*ctx*/, TTree *);
bool deserialize( std::string &, int &, TTree *, SG::EventContext &/*ctx*/);

private:

// convert a class object into a struct
bool serialize( std::string &, SG::EventContext &/*ctx*/, TTree *) const;
bool deserialize( std::string &, int &, TTree *, SG::EventContext &/*ctx*/) const;
bool convert(const CaloHit *truth, CaloHit_t &truth_t ) const;
bool convert(const CaloHit_t & , CaloHit *&) const;
template <class T> bool InitBranch(TTree* fChain, std::string branch_name, T* param) const;


private:

std::string m_seedKey;
bool m_onlyRoi;
float m_etaWindow;
float m_phiWindow;

std::vector<xAOD::CaloHit_t> m_hits_t;

std::string m_key;
};

}
Expand Down
Loading

0 comments on commit 98e2b10

Please sign in to comment.