Skip to content
Snippets Groups Projects
Commit e2030019 authored by Dave Casper's avatar Dave Casper
Browse files

Merge remote-tracking branch 'upstream/master'

parents 5b2ec6a8 a6bd35c2
No related branches found
No related tags found
No related merge requests found
Showing
with 120 additions and 1 deletion
atlas_subdir( SimHitExample )
atlas_depends_on_subdirs( PRIVATE
Generators/GeneratorObjects
Control/AthenaBaseComps
Tracker/TrackerSimEvent
)
atlas_add_component( SimHitExample
src/SimHitAlg.cxx
src/components/SimHitExample_entries.cxx
LINK_LIBRARIES AthenaBaseComps GeneratorObjects TrackerSimEvent
)
atlas_install_joboptions( share/*.py )
\ No newline at end of file
from AthenaCommon.GlobalFlags import globalflags
globalflags.InputFormat.set_Value_and_Lock('pool')
import AthenaPoolCnvSvc.ReadAthenaPool
svcMgr.EventSelector.InputCollections = ["g4.HITS.root"]
alg = CfgMgr.SimHitAlg()
athAlgSeq += alg
theApp.EvtMax=-1
alg.McEventCollection = "TruthEvent"
svcMgr += CfgMgr.THistSvc()
svcMgr.THistSvc.Output += ["HIST DATAFILE='myHistoFile.root' OPT='RECREATE'"]
\ No newline at end of file
#include "SimHitAlg.h"
SimHitAlg::SimHitAlg(const std::string& name, ISvcLocator* pSvcLocator)
: AthHistogramAlgorithm(name, pSvcLocator) { m_hist = nullptr; }
SimHitAlg::~SimHitAlg() { }
StatusCode SimHitAlg::initialize()
{
// initialize a histogram
// letter at end of TH1 indicated variable type (D double, F float etc)
m_hist = new TH1D("eLoss", "SCT Hit Energy Loss", 100, 0, 1); //first string is root object name, second is histogram title
ATH_CHECK(histSvc()->regHist("/HIST/myhist", m_hist));
// initialize data handle keys
ATH_CHECK( m_mcEventKey.initialize() );
ATH_CHECK( m_faserSiHitKey.initialize() );
ATH_MSG_INFO( "Using GenEvent collection with key " << m_mcEventKey.key());
ATH_MSG_INFO( "Using Faser SiHit collection with key " << m_faserSiHitKey.key());
return StatusCode::SUCCESS;
}
StatusCode SimHitAlg::execute()
{
// Handles created from handle keys behave like pointers to the corresponding container
SG::ReadHandle<McEventCollection> h_mcEvents(m_mcEventKey);
ATH_MSG_INFO("Read McEventContainer with " << h_mcEvents->size() << " events");
if (h_mcEvents->size() == 0) return StatusCode::FAILURE;
SG::ReadHandle<FaserSiHitCollection> h_siHits(m_faserSiHitKey);
ATH_MSG_INFO("Read FaserSiHitCollection with " << h_siHits->size() << " hits");
// Since we have no pile-up, there should always be a single GenEvent in the container
const HepMC::GenEvent* ev = (*h_mcEvents)[0];
if (ev == nullptr)
{
ATH_MSG_FATAL("GenEvent pointer is null");
return StatusCode::FAILURE;
}
ATH_MSG_INFO("Event contains " << ev->particles_size() << " truth particles" );
// The hit container might be empty because particles missed the wafers
if (h_siHits->size() == 0) return StatusCode::SUCCESS;
// Loop over all hits; print and fill histogram
for (const FaserSiHit& hit : *h_siHits)
{
hit.print();
m_hist->Fill( hit.energyLoss() );
}
return StatusCode::SUCCESS;
}
StatusCode SimHitAlg::finalize()
{
return StatusCode::SUCCESS;
}
\ No newline at end of file
#include "AthenaBaseComps/AthHistogramAlgorithm.h"
#include "GeneratorObjects/McEventCollection.h"
#include "TrackerSimEvent/FaserSiHitCollection.h"
#include <TH1.h>
/* SimHit reading example - Ryan Rice-Smith, UC Irvine */
class SimHitAlg : public AthHistogramAlgorithm
{
public:
SimHitAlg(const std::string& name, ISvcLocator* pSvcLocator);
virtual ~SimHitAlg();
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
private:
TH1* m_hist; // Example histogram
// Read handle keys for data containers
// Any other event data can be accessed identically
// Note the key names ("GEN_EVENT" or "SCT_Hits") are Gaudi properties and can be configured at run-time
SG::ReadHandleKey<McEventCollection> m_mcEventKey { this, "McEventCollection", "GEN_EVENT" };
SG::ReadHandleKey<FaserSiHitCollection> m_faserSiHitKey { this, "FaserSiHitCollection", "SCT_Hits" };
};
\ No newline at end of file
#include "../SimHitAlg.h"
DECLARE_COMPONENT( SimHitAlg )
\ No newline at end of file
...@@ -161,7 +161,7 @@ int FaserSiHit::getSensor() const { ...@@ -161,7 +161,7 @@ int FaserSiHit::getSensor() const {
} }
void FaserSiHit::print() const { void FaserSiHit::print() const {
std::cout << "*** Veto Hit " << std::endl; std::cout << "*** Faser Si Hit " << std::endl;
std::cout << " Station Number " << getStation() << std::endl; std::cout << " Station Number " << getStation() << std::endl;
std::cout << " Plane Number " << getPlane() << std::endl; std::cout << " Plane Number " << getPlane() << std::endl;
std::cout << " Row Number " << getRow() << std::endl; std::cout << " Row Number " << getRow() << std::endl;
......
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