From 127d3a34d29ed4885939ea40c52d19bfbd3a1dc9 Mon Sep 17 00:00:00 2001
From: Dave Casper <dcasper@uci.edu>
Date: Thu, 16 Jan 2020 03:24:16 +0000
Subject: [PATCH] Add/reorganize Calypso examples

---
 .../GeoModelTest/CMakeLists.txt               |  0
 .../GeoModelTest/python/GeoModelTestConfig.py |  0
 .../GeoModelTest/python/__init__.py           |  0
 .../GeoModelTest/share/geoDebug.py            |  0
 .../GeoModelTest/src/GeoModelTestAlg.cxx      |  0
 .../GeoModelTest/src/GeoModelTestAlg.h        |  0
 .../src/components/GeoModelTest_entries.cxx   |  0
 .../SimHitExample/CMakeLists.txt              | 15 +++++
 .../share/SimHitExample_jobOptions.py         | 16 +++++
 .../SimHitExample/src/SimHitAlg.cxx           | 58 +++++++++++++++++++
 .../SimHitExample/src/SimHitAlg.h             | 27 +++++++++
 .../src/components/SimHitExample_entries.cxx  |  3 +
 Tracker/TrackerSimEvent/src/FaserSiHit.cxx    |  2 +-
 13 files changed, 120 insertions(+), 1 deletion(-)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/CMakeLists.txt (100%)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/python/GeoModelTestConfig.py (100%)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/python/__init__.py (100%)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/share/geoDebug.py (100%)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/src/GeoModelTestAlg.cxx (100%)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/src/GeoModelTestAlg.h (100%)
 rename {DetectorDescription/GeoModel => Control/CalypsoExample}/GeoModelTest/src/components/GeoModelTest_entries.cxx (100%)
 create mode 100644 Control/CalypsoExample/SimHitExample/CMakeLists.txt
 create mode 100644 Control/CalypsoExample/SimHitExample/share/SimHitExample_jobOptions.py
 create mode 100644 Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx
 create mode 100644 Control/CalypsoExample/SimHitExample/src/SimHitAlg.h
 create mode 100644 Control/CalypsoExample/SimHitExample/src/components/SimHitExample_entries.cxx

diff --git a/DetectorDescription/GeoModel/GeoModelTest/CMakeLists.txt b/Control/CalypsoExample/GeoModelTest/CMakeLists.txt
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/CMakeLists.txt
rename to Control/CalypsoExample/GeoModelTest/CMakeLists.txt
diff --git a/DetectorDescription/GeoModel/GeoModelTest/python/GeoModelTestConfig.py b/Control/CalypsoExample/GeoModelTest/python/GeoModelTestConfig.py
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/python/GeoModelTestConfig.py
rename to Control/CalypsoExample/GeoModelTest/python/GeoModelTestConfig.py
diff --git a/DetectorDescription/GeoModel/GeoModelTest/python/__init__.py b/Control/CalypsoExample/GeoModelTest/python/__init__.py
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/python/__init__.py
rename to Control/CalypsoExample/GeoModelTest/python/__init__.py
diff --git a/DetectorDescription/GeoModel/GeoModelTest/share/geoDebug.py b/Control/CalypsoExample/GeoModelTest/share/geoDebug.py
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/share/geoDebug.py
rename to Control/CalypsoExample/GeoModelTest/share/geoDebug.py
diff --git a/DetectorDescription/GeoModel/GeoModelTest/src/GeoModelTestAlg.cxx b/Control/CalypsoExample/GeoModelTest/src/GeoModelTestAlg.cxx
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/src/GeoModelTestAlg.cxx
rename to Control/CalypsoExample/GeoModelTest/src/GeoModelTestAlg.cxx
diff --git a/DetectorDescription/GeoModel/GeoModelTest/src/GeoModelTestAlg.h b/Control/CalypsoExample/GeoModelTest/src/GeoModelTestAlg.h
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/src/GeoModelTestAlg.h
rename to Control/CalypsoExample/GeoModelTest/src/GeoModelTestAlg.h
diff --git a/DetectorDescription/GeoModel/GeoModelTest/src/components/GeoModelTest_entries.cxx b/Control/CalypsoExample/GeoModelTest/src/components/GeoModelTest_entries.cxx
similarity index 100%
rename from DetectorDescription/GeoModel/GeoModelTest/src/components/GeoModelTest_entries.cxx
rename to Control/CalypsoExample/GeoModelTest/src/components/GeoModelTest_entries.cxx
diff --git a/Control/CalypsoExample/SimHitExample/CMakeLists.txt b/Control/CalypsoExample/SimHitExample/CMakeLists.txt
new file mode 100644
index 00000000..44195b2b
--- /dev/null
+++ b/Control/CalypsoExample/SimHitExample/CMakeLists.txt
@@ -0,0 +1,15 @@
+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
diff --git a/Control/CalypsoExample/SimHitExample/share/SimHitExample_jobOptions.py b/Control/CalypsoExample/SimHitExample/share/SimHitExample_jobOptions.py
new file mode 100644
index 00000000..6b173f04
--- /dev/null
+++ b/Control/CalypsoExample/SimHitExample/share/SimHitExample_jobOptions.py
@@ -0,0 +1,16 @@
+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
diff --git a/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx
new file mode 100644
index 00000000..6e937ba7
--- /dev/null
+++ b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.cxx
@@ -0,0 +1,58 @@
+#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
diff --git a/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h
new file mode 100644
index 00000000..cfc1d0d3
--- /dev/null
+++ b/Control/CalypsoExample/SimHitExample/src/SimHitAlg.h
@@ -0,0 +1,27 @@
+#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
diff --git a/Control/CalypsoExample/SimHitExample/src/components/SimHitExample_entries.cxx b/Control/CalypsoExample/SimHitExample/src/components/SimHitExample_entries.cxx
new file mode 100644
index 00000000..caba1d27
--- /dev/null
+++ b/Control/CalypsoExample/SimHitExample/src/components/SimHitExample_entries.cxx
@@ -0,0 +1,3 @@
+#include "../SimHitAlg.h"
+
+DECLARE_COMPONENT( SimHitAlg )
\ No newline at end of file
diff --git a/Tracker/TrackerSimEvent/src/FaserSiHit.cxx b/Tracker/TrackerSimEvent/src/FaserSiHit.cxx
index c622b461..80b632ff 100644
--- a/Tracker/TrackerSimEvent/src/FaserSiHit.cxx
+++ b/Tracker/TrackerSimEvent/src/FaserSiHit.cxx
@@ -161,7 +161,7 @@ int FaserSiHit::getSensor() 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 << "          Plane Number   " << getPlane() << std::endl;
   std::cout << "          Row Number     " << getRow() << std::endl;
-- 
GitLab