Commit in projects/lcdd/branches/v05-00-00-dev on MAIN
CMakeLists.txt+11-33241 -> 3242
examples/segmentation/CartesianGridXY.lcdd+136added 3242
include/lcdd/detectors/CalorimeterSD.hh+24-63241 -> 3242
                      /DDSegmentationCalorimeterHitProcessor.hh+57added 3242
include/lcdd/hits/CalorimeterHitMap.hh+23241 -> 3242
include/lcdd/id/IdFactory.hh+53241 -> 3242
include/lcdd/schema/CartesianGridXYType.hh+63added 3242
                   /cartesian_grid_xy.hh+45added 3242
src/lcdd/core/LCDDLibLoad.cc+33241 -> 3242
src/lcdd/detectors/CalorimeterSD.cc+26-23241 -> 3242
                  /DDSegmentationCalorimeterHitProcessor.cc+106added 3242
                  /HitProcessorManager.cc+33241 -> 3242
                  /SensitiveDetectorFactory.cc+51-53241 -> 3242
src/lcdd/hits/CalorimeterHitMap.cc+43241 -> 3242
src/lcdd/id/IdFactory.cc+213241 -> 3242
src/lcdd/processes/cartesian_grid_xyProcess.cc+79added 3242
src/lcdd/segmentation/SegmentationFactory.cc+1-13241 -> 3242
+637-17
6 added + 11 modified, total 17 files
Proof of concept for reading out hits using a DDSegmentation Segmentation object.  (Checkpointing first possibly working version.)

projects/lcdd/branches/v05-00-00-dev
CMakeLists.txt 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/CMakeLists.txt	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/CMakeLists.txt	2014-08-08 22:30:20 UTC (rev 3242)
@@ -50,6 +50,14 @@
     MESSAGE( STATUS "Found GDML: ${GDML_DIR}" )
 ENDIF()
 
+# find DDSegmentation
+FIND_PACKAGE(DDSegmentation REQUIRED)
+if ( NOT DDSegmentation_FOUND )
+    MESSAGE( FATAL_ERROR "DDSegmentation was not found!  Define DDSegmentation_DIR when calling cmake." )
+ELSE()
+    MESSAGE( STATUS "Found DDSegmentation: ${DDSegmentation_DIR}" )
+ENDIF()
+
 # local includes
 SET( LCDD_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include )
 INCLUDE_DIRECTORIES( ${LCDD_INCLUDE_DIR} )
@@ -65,13 +73,13 @@
 ADD_DEFINITIONS( ${Geant4_DEFINITIONS} )
 
 # include directories
-INCLUDE_DIRECTORIES( ${XERCES_INCLUDE_DIR} ${Geant4_INCLUDE_DIRS} ${GDML_INCLUDE_DIRS} )
+INCLUDE_DIRECTORIES( ${XERCES_INCLUDE_DIR} ${Geant4_INCLUDE_DIRS} ${GDML_INCLUDE_DIRS} ${DDSegmentation_INCLUDE_DIRS} )
 
 # add GDML link directory
-LINK_DIRECTORIES( ${GDML_LIBRARY_DIR} )
+LINK_DIRECTORIES( ${GDML_LIBRARY_DIR} ${DDSegmentation_LIBRARY_DIR} )
 
 # libraries
-LINK_LIBRARIES( ${XERCES_LIBRARY} ${Geant4_LIBRARIES} ${GDML_LIBRARY} )
+LINK_LIBRARIES( ${XERCES_LIBRARY} ${Geant4_LIBRARIES} ${GDML_LIBRARY} ${DDSegmentation_LIBRARIES} )
 
 # output shared library
 ADD_LIBRARY( lcdd SHARED ${library_sources} )

projects/lcdd/branches/v05-00-00-dev/examples/segmentation
CartesianGridXY.lcdd added at 3242
--- projects/lcdd/branches/v05-00-00-dev/examples/segmentation/CartesianGridXY.lcdd	                        (rev 0)
+++ projects/lcdd/branches/v05-00-00-dev/examples/segmentation/CartesianGridXY.lcdd	2014-08-08 22:30:20 UTC (rev 3242)
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lcdd xmlns:lcdd="http://www.lcsim.org/schemas/lcdd/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcdd/2.0/lcdd.xsd">
+  <header>
+    <detector name="CartesianGridXy" />
+  </header>
+  <iddict>
+    <idspec name="CalHits" length="64">
+    <!--
+      <idfield signed="false" label="system" length="3" start="0" />
+      <idfield signed="false" label="layer" length="7" start="3" />
+      <idfield signed="false" label="slice" length="2" start="10" />
+    -->      
+      <idfield signed="true" label="x" length="32" start="0" />
+      <idfield signed="true" label="y" length="32" start="32" />
+    </idspec>
+  </iddict>
+  <sensitive_detectors>
+    <calorimeter name="Cal" hits_collection="CalHits">
+      <idspecref ref="CalHits" />
+      <hit_processor type="DDSegmentationCalorimeterHitProcessor" />
+<!--      
+      <cartesian_grid_xy grid_size_x="1.0" grid_size_y="1.5" offset_x="0.1" offset_y="0.2" />
+-->      
+      <cartesian_grid_xy grid_size_x="1.0" grid_size_y="1.0" offset_x="0.0" offset_y="0.0" />
+    </calorimeter>
+  </sensitive_detectors>
+  <limits />
+  <regions>
+    <region name="TrackingRegion" store_secondaries="true" cut="10.0" lunit="mm" threshold="1.0" eunit="MeV" />
+  </regions>
+  <display />
+  <gdml>
+    <define>
+      <rotation name="identity_rot" x="0.0" y="0.0" z="0.0" unit="radian" />
+      <position name="identity_pos" x="0.0" y="0.0" z="0.0" unit="mm" />
+      <constant name="tracking_region_radius" value="0.5*m" />
+      <constant name="tracking_region_zmax" value="1.0*m" />
+      <constant name="world_x" value="5.0*m" />
+      <constant name="world_y" value="5.0*m" />
+      <constant name="world_z" value="5.0*m" />
+      <constant name="box_x" value="1.0*m" />
+      <constant name="box_y" value="1.0*m" />
+      <constant name="box_z" value="1.0*m" />
+      <position name="TestBeamCalorimeterTest_position" x="0.0" y="0.0" z="0.0" unit="mm" />
+      <position name="TestBeamCalorimeterTest_layerType0_slice0_position" x="0.0" y="0.0" z="0.0" unit="mm" />
+      <position name="TestBeamCalorimeterTest_layer0_position" x="0.0" y="0.0" z="0.0" unit="mm" />
+    </define>
+    <materials>
+      <element name="N" formula="N" Z="7.0">
+        <atom type="A" unit="g/mol" value="14.00674" />
+      </element>
+      <element name="O" formula="O" Z="8.0">
+        <atom type="A" unit="g/mol" value="15.9994" />
+      </element>
+      <element name="Ar" formula="Ar" Z="18.0">
+        <atom type="A" unit="g/mol" value="39.948" />
+      </element>
+      <material name="Air">
+        <D type="density" unit="g/cm3" value="0.0012" />
+        <fraction n="0.754" ref="N" />
+        <fraction n="0.234" ref="O" />
+        <fraction n="0.012" ref="Ar" />
+      </material>
+      <element name="Fe" formula="Fe" Z="26.0">
+        <atom type="A" unit="g/mol" value="55.845" />
+      </element>
+      <element name="C" formula="C" Z="6.0">
+        <atom type="A" unit="g/mol" value="12.0107" />
+      </element>
+      <material name="Steel235">
+        <D value="7.85" unit="g/cm3" />
+        <fraction n="0.998" ref="Fe" />
+        <fraction n=".002" ref="C" />
+      </material>
+    </materials>
+    <solids>
+      <box name="world_box" x="world_x" y="world_y" z="world_z" />
+      <tube name="tracking_cylinder" deltaphi="6.283185307179586" rmin="0.0" rmax="tracking_region_radius" z="tracking_region_zmax" />
+      <box name="TestBeamCalorimeterTest_box" x="box_x" y="box_y" z="box_z" />
+      <box name="TestBeamCalorimeterTest_layerType0_box" x="box_x" y="box_y" z="box_z" />
+      <box name="TestBeamCalorimeterTest_layerType0_slice0_box" x="box_x" y="box_y" z="box_z" />
+    </solids>
+    <structure>
+      <volume name="TestBeamCalorimeterTest_layerType0_slice0">
+        <materialref ref="Steel235" />
+        <solidref ref="TestBeamCalorimeterTest_layerType0_slice0_box" />
+        <sdref ref="Cal" />
+      </volume>
+      <volume name="TestBeamCalorimeterTest_layerType0">
+        <materialref ref="Air" />
+        <solidref ref="TestBeamCalorimeterTest_layerType0_box" />
+        <physvol>
+          <volumeref ref="TestBeamCalorimeterTest_layerType0_slice0" />
+          <positionref ref="TestBeamCalorimeterTest_layerType0_slice0_position" />
+          <rotationref ref="identity_rot" />
+          <physvolid field_name="slice" value="1" />
+        </physvol>
+      </volume>
+      <volume name="TestBeamCalorimeterTest_envelope">
+        <materialref ref="Air" />
+        <solidref ref="TestBeamCalorimeterTest_box" />
+        <physvol>
+          <volumeref ref="TestBeamCalorimeterTest_layerType0" />
+          <positionref ref="TestBeamCalorimeterTest_layer0_position" />
+          <rotationref ref="identity_rot" />
+          <physvolid field_name="layer" value="2" />
+        </physvol>
+      </volume>
+      <volume name="tracking_volume">
+        <materialref ref="Air" />
+        <solidref ref="tracking_cylinder" />
+        <physvol>
+          <volumeref ref="TestBeamCalorimeterTest_envelope" />
+          <positionref ref="TestBeamCalorimeterTest_position" />
+          <rotationref ref="identity_rot" />
+          <physvolid field_name="system" value="3" />
+        </physvol>
+        <regionref ref="TrackingRegion" />
+      </volume>
+      <volume name="world_volume">
+        <materialref ref="Air" />
+        <solidref ref="world_box" />
+        <physvol>
+          <volumeref ref="tracking_volume" />
+          <positionref ref="identity_pos" />
+          <rotationref ref="identity_rot" />
+        </physvol>
+      </volume>
+    </structure>
+    <setup name="Default" version="1.0">
+      <world ref="world_volume" />
+    </setup>
+  </gdml>
+  <fields />
+</lcdd>
+

projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors
CalorimeterSD.hh 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors/CalorimeterSD.hh	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors/CalorimeterSD.hh	2014-08-08 22:30:20 UTC (rev 3242)
@@ -8,6 +8,11 @@
 #include "lcdd/hits/CalorimeterHitMap.hh"
 #include "lcdd/segmentation/Segmentation.hh"
 
+// DD4HEP
+#include "DDSegmentation/Segmentation.h"
+
+#include <vector>
+
 /**
  * @brief The implementation of a calorimeter that accumulates energy depositions by event.
  */
@@ -29,7 +34,7 @@
      * @param[in] sdSeg    The detector's segmentation object for dividing into artificial cells.
      * @param[in] compare  The hit comparator to be used by this detector.
      */
-    CalorimeterSD(G4String sdName, G4String hcName, Segmentation* sdSeg);
+    CalorimeterSD(G4String sensitiveDetectorName, G4String hitsCollectionName, Segmentation* segmentation);
 
     /**
      * Class constructor.
@@ -38,7 +43,7 @@
      * @param[in] sdSeg    The detector's segmentation object for dividing into artificial cells.
      * @param[in] compare  The hit comparator to be used by this detector.
      */
-    CalorimeterSD(G4String sdName, const std::vector<G4String>& hcNames, Segmentation* sdSeg);
+    CalorimeterSD(G4String sensitiveDetectorName, const std::vector<G4String>& hitsCollectionName, Segmentation* segmentation);
 
     /**
      * Class destructor.
@@ -70,13 +75,18 @@
     Segmentation* getSegmentation() const;
 
     /**
-     * Print out the hit data to an output stream.
-     * @param[in] os The output stream.
-     * @return The same output stream.
+     * Set the DD4hep Segmentation of this Calorimeter.
+     * @param[in] segmentation The Segmentation object.
      */
-    //std::ostream& printHits(std::ostream& os);
+    void setDDSegmentation(DD4hep::DDSegmentation::Segmentation* segmentation);
 
     /**
+     * Get the DD4HEP Segmentation of this CalorimeterSD.
+     * @return The DD4HEP Segmentation or NULL if not set.
+     */
+    DD4hep::DDSegmentation::Segmentation* getDDSegmentation() const;
+
+    /**
      * Print the calorimeter's basic information.
      * @param[in] os The output stream.
      * @return The same output stream.
@@ -99,6 +109,12 @@
      */
     CalorimeterHit* findHit(const Id64bit& id, int collectionIndex = 0);
 
+    /**
+     * Get a CalorimeterHitMap by collection index.
+     * @return The CalorimeterHitMap by collection index.
+     */
+    CalorimeterHitMap* getCalorimeterHitMap(int index);
+
 protected:
 
     /**
@@ -113,6 +129,8 @@
     // The calorimeter's virtual segmentation.
     Segmentation* _segmentation;
 
+    DD4hep::DDSegmentation::Segmentation* _ddsegmentation;
+
     // Pointers to current hits collections.
     std::vector<CalorimeterHitsCollection*> _hitsCollections;
 

projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors
DDSegmentationCalorimeterHitProcessor.hh added at 3242
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors/DDSegmentationCalorimeterHitProcessor.hh	                        (rev 0)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors/DDSegmentationCalorimeterHitProcessor.hh	2014-08-08 22:30:20 UTC (rev 3242)
@@ -0,0 +1,57 @@
+/*
+ * DDSegmentationCalorimeterHitProcessor.hh
+ *
+ *  Created on: Aug 8, 2014
+ *      Author: jeremym
+ */
+#ifndef LCDD_DETECTORS_DDSEGMENTATIONCALORIMETERHITPROCESSOR_HH_
+#define LCDD_DETECTORS_DDSEGMENTATIONCALORIMETERHITPROCESSOR_HH_ 1
+
+// LCDD
+#include "lcdd/detectors/CalorimeterHitProcessor.hh"
+#include "lcdd/detectors/HitProcessorFactory.hh"
+
+/**
+ * @brief
+ * Implementation of hit processing behavior using the DDSegmentation API for the Segmentation.
+ */
+class DDSegmentationCalorimeterHitProcessor: public CalorimeterHitProcessor {
+
+public:
+
+    /**
+     * Class constructor.
+     */
+    DDSegmentationCalorimeterHitProcessor();
+
+    /**
+     * Class destructor.
+     */
+    virtual ~DDSegmentationCalorimeterHitProcessor();
+
+    /**
+     * Process steps to produce hits.
+     * @param[in] step A G4Step object.
+     */
+    bool processHits(G4Step* step);
+};
+
+/**
+ * @brief
+ * The factory for creating new DDSegmentationCalorimeterHitProcessor objects
+ */
+class DDSegmentationCalorimeterHitProcessorFactory: public HitProcessorFactory {
+
+public:
+
+    HitProcessor* createHitProcessor() {
+        return new DDSegmentationCalorimeterHitProcessor();
+    }
+
+    const std::string& handlesType() {
+        static std::string typeName = "DDSegmentationCalorimeterHitProcessor";
+        return typeName;
+    }
+};
+
+#endif /* LCDD_DETECTORS_DDSEGMENTATIONCALORIMETERHITPROCESSOR_HH_ */

projects/lcdd/branches/v05-00-00-dev/include/lcdd/hits
CalorimeterHitMap.hh 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/hits/CalorimeterHitMap.hh	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/hits/CalorimeterHitMap.hh	2014-08-08 22:30:20 UTC (rev 3242)
@@ -47,6 +47,8 @@
      */
     CalorimeterHit* get(const Id64bit& id);
 
+    CalorimeterHit* get(Id64bit::ValueType);
+
     /**
      * Get the size of the map.
      * @return The size of the map.

projects/lcdd/branches/v05-00-00-dev/include/lcdd/id
IdFactory.hh 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/id/IdFactory.hh	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/id/IdFactory.hh	2014-08-08 22:30:20 UTC (rev 3242)
@@ -9,6 +9,9 @@
 #include <iostream>
 #include <vector>
 
+// DD4HEP
+#include "DDSegmentation/Segmentation.h"
+
 // LCDD
 class Segmentation;
 
@@ -61,6 +64,8 @@
      */
     static IdVec createOrderedIdVec(G4Step* aStep, const SensitiveDetector* sd);
 
+    static DD4hep::DDSegmentation::VolumeID createVolumeId(G4Step*, IdSpec*);
+
 private:
 
     /*

projects/lcdd/branches/v05-00-00-dev/include/lcdd/schema
CartesianGridXYType.hh added at 3242
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/schema/CartesianGridXYType.hh	                        (rev 0)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/schema/CartesianGridXYType.hh	2014-08-08 22:30:20 UTC (rev 3242)
@@ -0,0 +1,63 @@
+/*
+ * CartesianGridXYType.hh
+ *
+ *  Created on: Aug 7, 2014
+ *      Author: jeremym
+ */
+#ifndef LCDD_SCHEMA_CARTESIANGRIDXYTYPE_HH_
+#define LCDD_SCHEMA_CARTESIANGRIDXYTYPE_HH_ 1
+
+// LCDD
+#include "SegmentationType.hh"
+
+class CartesianGridXYType: public SegmentationType {
+
+public:
+
+    CartesianGridXYType() {
+    }
+
+    virtual ~CartesianGridXYType() {
+    }
+
+    void set_grid_size_x(const std::string grid_size_x) {
+        _grid_size_x = grid_size_x;
+    }
+
+    const std::string& get_grid_size_x() {
+        return _grid_size_x;
+    }
+
+    void set_grid_size_y(const std::string grid_size_y) {
+        _grid_size_y = grid_size_y;
+    }
+
+    const std::string& get_grid_size_y() {
+        return _grid_size_y;
+    }
+
+    void set_offset_x(const std::string offset_x) {
+        _offset_x = offset_x;
+    }
+
+    const std::string& get_offset_x() {
+        return _offset_x;
+    }
+
+    void set_offset_y(const std::string offset_y) {
+        _offset_y = offset_y;
+    }
+
+    const std::string& get_offset_y() {
+        return _offset_y;
+    }
+
+private:
+
+    std::string _grid_size_x;
+    std::string _grid_size_y;
+    std::string _offset_x;
+    std::string _offset_y;
+};
+
+#endif /* CARTESIANGRIDXYTYPE_HH_ */

projects/lcdd/branches/v05-00-00-dev/include/lcdd/schema
cartesian_grid_xy.hh added at 3242
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/schema/cartesian_grid_xy.hh	                        (rev 0)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/schema/cartesian_grid_xy.hh	2014-08-08 22:30:20 UTC (rev 3242)
@@ -0,0 +1,45 @@
+/*
+ * cartesian_grid_xy.hh
+ *
+ *  Created on: Aug 7, 2014
+ *      Author: jeremym
+ */
+
+#ifndef LCDD_SCHEMA_CARTESIAN_GRID_XY_HH_
+#define LCDD_SCHEMA_CARTESIAN_GRID_XY_HH_ 1
+
+// LCDD
+#include "lcdd/schema/CartesianGridXYType.hh"
+
+// GDML
+#include "Saxana/SAXObject.h"
+
+/**
+ * @brief cartesian_grid_xy element from the schema.
+ */
+class cartesian_grid_xy: public SAXObject, public CartesianGridXYType {
+
+public:
+
+    /**
+     * Class constructor.
+     */
+    cartesian_grid_xy() {
+    }
+
+    /**
+     * Class destructor.
+     */
+    virtual ~cartesian_grid_xy() {
+    }
+
+    /**
+     * Get the type of this SAXObject.
+     * @return The type of this SAXObject.
+     */
+    virtual SAXObject::Type type() {
+        return SAXObject::element;
+    }
+};
+
+#endif /* CARTESIAN_GRID_XY_HH_ */

projects/lcdd/branches/v05-00-00-dev/src/lcdd/core
LCDDLibLoad.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/core/LCDDLibLoad.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/core/LCDDLibLoad.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -35,6 +35,9 @@
     LOAD_COMPONENT (global_grid_xyProcess);
     LOAD_COMPONENT (cell_readout_2dProcess);
 
+    // DDSegmentation
+    LOAD_COMPONENT (cartesian_grid_xyProcess);
+
     // Ids
     LOAD_COMPONENT (idspecProcess);
     LOAD_COMPONENT (idfieldProcess);

projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors
CalorimeterSD.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/CalorimeterSD.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/CalorimeterSD.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -12,19 +12,31 @@
 using std::vector;
 
 CalorimeterSD::CalorimeterSD(G4String sdName, G4String hcName, Segmentation* sdSeg) :
-        SensitiveDetector(sdName, hcName, SensitiveDetector::eCalorimeter), _segmentation(sdSeg) {
+        SensitiveDetector(sdName, hcName, SensitiveDetector::eCalorimeter), _segmentation(sdSeg), _ddsegmentation(NULL) {
     // Setup a dummy hits collection that will be overridden later.
     _hitsCollections.push_back(NULL);
 }
 
 CalorimeterSD::CalorimeterSD(G4String sdName, const vector<G4String>& hcNames, Segmentation* sdSeg) :
-        SensitiveDetector(sdName, hcNames, SensitiveDetector::eCalorimeter), _segmentation(sdSeg) {
+        SensitiveDetector(sdName, hcNames, SensitiveDetector::eCalorimeter), _segmentation(sdSeg), _ddsegmentation(NULL) {
     // Setup entries for each hits collection.  These null pointers will be overridden later.
     for (int i = 0; i < (int) hcNames.size(); i++) {
         _hitsCollections.push_back(NULL);
     }
 }
 
+/*
+CalorimeterSD::CalorimeterSD(
+        G4String sensitiveDetectorName,
+        const vector<G4String>& hitsCollectionNames,
+        DD4hep::DDSegmentation::Segmentation* segmentation) :
+        SensitiveDetector(sensitiveDetectorName, hitsCollectionNames, SensitiveDetector::eCalorimeter), _ddsegmentation(segmentation) {
+    for (int i = 0; i < (int) hitsCollectionNames.size(); i++) {
+        _hitsCollections.push_back(NULL);
+    }
+}
+*/
+
 CalorimeterSD::~CalorimeterSD() {
 }
 
@@ -62,10 +74,18 @@
     }
 }
 
+void CalorimeterSD::setDDSegmentation(DD4hep::DDSegmentation::Segmentation* ddsegmentation) {
+    _ddsegmentation = ddsegmentation;
+}
+
 Segmentation* CalorimeterSD::getSegmentation() const {
     return _segmentation;
 }
 
+DD4hep::DDSegmentation::Segmentation* CalorimeterSD::getDDSegmentation() const {
+    return _ddsegmentation;
+}
+
 G4bool CalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
     return SensitiveDetector::ProcessHits(aStep, 0);
 }
@@ -100,3 +120,7 @@
 CalorimeterHit* CalorimeterSD::findHit(const Id64bit& id, int collectionIndex) {
     return _hitMaps[collectionIndex]->get(id);
 }
+
+CalorimeterHitMap* CalorimeterSD::getCalorimeterHitMap(int collectionIndex) {
+    return _hitMaps[collectionIndex];
+}

projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors
DDSegmentationCalorimeterHitProcessor.cc added at 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/DDSegmentationCalorimeterHitProcessor.cc	                        (rev 0)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/DDSegmentationCalorimeterHitProcessor.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -0,0 +1,106 @@
+/*
+ * DDSegmentationCalorimeterHitProcessor.cc
+ *
+ *  Created on: Aug 8, 2014
+ *      Author: jeremym
+ */
+
+#include "lcdd/detectors/DDSegmentationCalorimeterHitProcessor.hh"
+
+// LCDD
+#include "lcdd/detectors/CurrentTrackState.hh"
+#include "lcdd/hits/CalorimeterHitMap.hh"
+#include "lcdd/id/IdFactory.hh"
+
+// DD4hep
+#include "DDSegmentation/Segmentation.h"
+
+// Geant4
+#include "G4Geantino.hh"
+#include "G4ChargedGeantino.hh"
+
+DDSegmentationCalorimeterHitProcessor::DDSegmentationCalorimeterHitProcessor() {
+}
+
+DDSegmentationCalorimeterHitProcessor::~DDSegmentationCalorimeterHitProcessor() {
+}
+
+bool DDSegmentationCalorimeterHitProcessor::processHits(G4Step* step) {
+
+    //G4cout << "DDSegmentationCalorimeterHitProcessor::processHits" << G4endl;
+
+    // Get the energy deposition.
+    G4double edep = step->GetTotalEnergyDeposit();
+
+    // Check for Geantino particle type.
+    G4ParticleDefinition* def = step->GetTrack()->GetDefinition();
+    bool isGeantino = false;
+    if (def == G4Geantino::Definition() || def == G4ChargedGeantino::Definition()) {
+        isGeantino = true;
+    }
+
+    // Cut on energy deposition <= cut but allow Geantinos.
+    if (edep <= _calorimeter->getEnergyCut() && isGeantino == false) {
+        return false;
+    }
+
+    DD4hep::DDSegmentation::Segmentation* segmentation = _calorimeter->getDDSegmentation();
+
+    // Compute the global midpoint of the step.
+    G4ThreeVector globalMidPoint = (0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition()));
+
+    // Create the global position for input to Segmentation.
+    DD4hep::DDSegmentation::Vector3D globalPosition = DD4hep::DDSegmentation::Vector3D(globalMidPoint.x(), globalMidPoint.y(), globalMidPoint.z());
+
+    // Get touchable from PreStepPoint.
+    G4TouchableHandle touchable = step->GetPreStepPoint()->GetTouchableHandle();
+
+    // Compute local position.
+    G4ThreeVector localPosition = touchable->GetHistory()->GetTopTransform().TransformPoint(globalMidPoint);
+
+    // Create the VolumeID.
+    DD4hep::DDSegmentation::VolumeID volumeId = IdFactory::createVolumeId(step, _calorimeter->getIdSpec());
+
+    // Get the encoded 64-bit cell ID from the Segmentation.
+    long cellId = segmentation->cellID(localPosition, globalPosition, volumeId);
+
+    segmentation->decoder()->setValue(cellId);
+
+    //int ix = segmentation->decoder()->index("x");
+    //int iy = segmentation->decoder()->index("y");
+
+    //G4cout << "x = " << segmentation->decoder()[(int)ix] << G4endl;
+    //G4cout << "y = " << segmentation->decoder()[(int)iy] << G4endl;
+
+    // Check for an existing hit with this identifier.
+    CalorimeterHit* hit = _calorimeter->getCalorimeterHitMap(getCollectionIndex())->get(cellId);
+
+    // Was there a hit found with this identifier?
+    if (hit == NULL) {
+
+        int id0 = cellId & 0xFFFF0000;
+        int id1 = (cellId & 0x0000FFFF) << 32;
+        Id64bit id = Id64bit(id0, id1);
+
+        // Get the global cell position from the Segmentation.
+        DD4hep::DDSegmentation::Vector3D globalCellPosition = segmentation->position(cellId);
+
+        // No hit was found, so a new one is created.
+        hit = new CalorimeterHit(id, edep, G4ThreeVector(globalCellPosition.x(), globalCellPosition.y(), globalCellPosition.z()));
+
+        // Add the new hit to the calorimeter.
+        _calorimeter->addHit(hit, _collectionIndex);
+
+    } else {
+
+        // Add energy deposition to an existing hit.
+        hit->addEdep(edep);
+    }
+
+    // Add hit contribution to the hit.
+    // FIXME: This should pass a pointer to a new object.  It is copied, which is inefficient.
+    hit->addHitContribution(HitContribution(CurrentTrackState::getCurrentTrackID(), step));
+
+    // Return true, indicating that a hit was added or modified.
+    return true;
+}

projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors
HitProcessorManager.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/HitProcessorManager.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/HitProcessorManager.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -4,6 +4,7 @@
 #include "lcdd/detectors/BasicCalorimeterHitProcessor.hh"
 #include "lcdd/detectors/BasicTrackerHitProcessor.hh"
 #include "lcdd/detectors/ScoringTrackerHitProcessor.hh"
+#include "lcdd/detectors/DDSegmentationCalorimeterHitProcessor.hh"
 
 HitProcessorManager* HitProcessorManager::_manager = 0;
 
@@ -25,6 +26,8 @@
     registerFactory(new BasicCalorimeterHitProcessorFactory());
     registerFactory(new ScoringTrackerHitProcessorFactory());
     registerFactory(new BasicTrackerHitProcessorFactory());
+
+    registerFactory(new DDSegmentationCalorimeterHitProcessorFactory());
 }
 
 void HitProcessorManager::registerFactory(HitProcessorFactory* factory) {

projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors
SensitiveDetectorFactory.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/SensitiveDetectorFactory.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/SensitiveDetectorFactory.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -10,7 +10,17 @@
 #include "lcdd/detectors/ScoringTrackerHitProcessor.hh"
 #include "lcdd/schema/hit_processor.hh"
 
+// GDML
+#include "G4Evaluator/GDMLExpressionEvaluator.h"
+
+#include "lcdd/schema/cartesian_grid_xy.hh"
+
+// DD4hep
+#include "DDSegmentation/CartesianGridXY.h"
+using DD4hep::DDSegmentation::CartesianGridXY;
+
 #include <algorithm>
+#include <exception>
 
 SensitiveDetector* SensitiveDetectorFactory::createSensitiveDetector(const SAXObject* object) {
 
@@ -113,6 +123,41 @@
             G4Exception("", "", FatalException, "Unknown sensitive detector type.");
         }
 
+        // TEST: Create DDSegmentation if exists.
+        for (size_t i = 0; i < count; i++) {
+            std::string childTag = seq->content(i).tag;
+            const ContentGroup::ContentItem& segitem = seq->content(i);
+            if (childTag == "cartesian_grid_xy") {
+                cartesian_grid_xy* element = dynamic_cast<cartesian_grid_xy*>(segitem.object);
+                CartesianGridXY* cartesianGridXY = new CartesianGridXY(idspec->getFieldDescription());
+
+                GDMLExpressionEvaluator* calc = GDMLProcessor::GetInstance()->GetEvaluator();
+
+                // FIXME: These calculations should apply a length unit, too.
+                double gridSizeX, gridSizeY, offsetX, offsetY;
+                gridSizeX = gridSizeY = offsetX = offsetY = 0;
+
+                std::string rawValue = element->get_grid_size_x();
+                gridSizeX = calc->Eval(rawValue);
+
+                rawValue = element->get_grid_size_y();
+                gridSizeY = calc->Eval(rawValue);
+
+                rawValue = element->get_offset_x();
+                offsetX = calc->Eval(rawValue);
+
+                rawValue = element->get_offset_y();
+                offsetY = calc->Eval(rawValue);
+
+                cartesianGridXY->setGridSizeX(gridSizeX);
+                cartesianGridXY->setGridSizeY(gridSizeY);
+                cartesianGridXY->setOffsetX(offsetX);
+                cartesianGridXY->setOffsetX(offsetY);
+
+                ((CalorimeterSD*)sensitiveDetector)->setDDSegmentation(cartesianGridXY);
+            }
+        }
+
         // Set the base attributes.
         sensitiveDetector->setEcut(SensitiveDetectorFactory::computeEcut(sensitiveDetectorType));
         sensitiveDetector->setVerbose(SensitiveDetectorFactory::convertVerbose(sensitiveDetectorType));
@@ -143,20 +188,20 @@
     // Create the segmentation child object prior to the calorimeter.
     ContentSequence* seq = const_cast<ContentSequence*>(sensitiveDetectorType->get_content());
     size_t count = seq->size();
-    bool fnd_seg = false;
     for (size_t i = 0; i < count; i++) {
         std::string child_tag = seq->content(i).tag;
         const ContentGroup::ContentItem& segitem = seq->content(i);
         // Create segmentation using factory.
         if (isSegmentationTag(child_tag)) {
             segmentation = SegmentationFactory::createSegmentation(segitem.object, segitem.tag);
-            fnd_seg = true;
             break;
         }
     }
 
+    CalorimeterSD* calorimeter = new CalorimeterSD(sensitiveDetectorType->get_name(), hitsCollections, segmentation);
+
     // Create the calorimeter SD.
-    return new CalorimeterSD(sensitiveDetectorType->get_name(), hitsCollections, segmentation);
+    return calorimeter;
 }
 
 TrackerSD* SensitiveDetectorFactory::createTracker(const SAXObject* object, const std::vector<G4String>& hitsCollections) {
@@ -185,8 +230,9 @@
 }
 
 bool SensitiveDetectorFactory::isSegmentationTag(const std::string& s) {
-    // FIXME This should automatically know all segmentation types somehow.
-    //       Can this be read from the schema?
+    // FIXME This should automatically know all segmentation types.
+    //       Can they be read from the schema?
     //       http://xerces-c.sourcearchive.com/documentation/3.1.1-1/SchemaGrammar_8hpp_source.html
     return (s == "projective_cylinder" || s == "grid_xyz" || s == "global_grid_xy" || s == "projective_zplane" || s == "cell_readout_2d");
+            //|| s == "cartesian_grid_xy");
 }

projects/lcdd/branches/v05-00-00-dev/src/lcdd/hits
CalorimeterHitMap.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/hits/CalorimeterHitMap.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/hits/CalorimeterHitMap.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -15,6 +15,10 @@
     return _map[id.getValue()];
 }
 
+CalorimeterHit* CalorimeterHitMap::get(Id64bit::ValueType value) {
+    return _map[value];
+}
+
 void CalorimeterHitMap::clear() {
     _map.clear();
 }

projects/lcdd/branches/v05-00-00-dev/src/lcdd/id
IdFactory.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/id/IdFactory.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/id/IdFactory.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -381,3 +381,24 @@
 
     return fnd;
 }
+
+DD4hep::DDSegmentation::VolumeID IdFactory::createVolumeId(G4Step* aStep, IdSpec* idspec) {
+    //std::cout << "IdFactory::createVolumeId" << std::endl;
+    IdVec idvec;
+    for (IdSpec::IdFields::const_iterator iter = idspec->IdFieldsBegin(); iter != idspec->IdFieldsEnd(); iter++) {
+        IdField* field = *iter;
+        std::vector<G4VPhysicalVolume*> pvolumes = ReadoutUtil::getPhysVolList(aStep);
+        if (hasPhysVolId(pvolumes, field->getLabel())) {
+            int pvolId = findIdInPhysVols(pvolumes, field->getLabel());
+            //G4cout << "VolumeId::" << field->getLabel() << " = " << pvolId << G4endl;
+            idvec.addFieldValue(pvolId);
+        } else {
+            idvec.addFieldValue(0);
+        }
+    }
+    G4cout << G4endl;
+    Id64bit id = IdFactory::createIdentifier(idvec, idspec);
+    id.encode();
+    Id64bit::ValueType volId = id.getValue();
+    return (DD4hep::DDSegmentation::VolumeID)volId;
+}

projects/lcdd/branches/v05-00-00-dev/src/lcdd/processes
cartesian_grid_xyProcess.cc added at 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/processes/cartesian_grid_xyProcess.cc	                        (rev 0)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/processes/cartesian_grid_xyProcess.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -0,0 +1,79 @@
+/*
+ * cartesian_grid_xyProcess.cc
+ *
+ *  Created on: Aug 7, 2014
+ *      Author: jeremym
+ */
+// GDML
+#include "Saxana/ProcessingConfigurator.h"
+#include "Saxana/ProcessingContext.h"
+#include "Saxana/SAXProcessor.h"
+#include "Saxana/StateStack.h"
+#include "Saxana/SAXProcessingState.h"
+#include "Saxana/SAXStateProcess.h"
+#include "Saxana/SAXComponentFactory.h"
+
+#include "lcdd/schema/cartesian_grid_xy.hh"
+
+// STL
+#include <iostream>
+
+/**
+ * @brief The SAX process for cell_readout_2d elements.
+ */
+class cartesian_grid_xyProcess: public SAXStateProcess {
+
+public:
+
+    cartesian_grid_xyProcess(const ProcessingContext* context = 0) :
+            SAXStateProcess(context), m_obj(0) {
+    }
+
+    virtual ~cartesian_grid_xyProcess() {
+    }
+
+    virtual const SAXComponentObject* Build() const {
+        return this;
+    }
+
+    virtual void StartElement(const std::string& name, const ASCIIAttributeList& attrs) {
+        std::cout << "cartesian_grid_xyProcess::StartElement: " << name << std::endl;
+
+        SAXObject** obj = Context()->GetTopObject();
+
+        cartesian_grid_xy* element = new cartesian_grid_xy;
+
+        element->set_grid_size_x(attrs.getValue("grid_size_x"));
+        element->set_grid_size_y(attrs.getValue("grid_size_y"));
+        element->set_offset_x(attrs.getValue("offset_x"));
+        element->set_offset_y(attrs.getValue("offset_y"));
+
+        std::cout << "grid_size_x: " << element->get_grid_size_x() << std::endl;
+        std::cout << "grid_size_y: " << element->get_grid_size_y() << std::endl;
+        std::cout << "offset_x: " << element->get_offset_x() << std::endl;
+        std::cout << "offset_y: " << element->get_offset_y() << std::endl;
+
+        m_obj = element;
+        *obj = element;
+    }
+
+    virtual void EndElement(const std::string&) {
+    }
+
+    virtual void Characters(const std::string&) {
+    }
+
+    virtual void StackPopNotify(const std::string&) {
+    }
+
+    virtual const std::string& State() const {
+        static std::string tag = "cartesian_grid_xy";
+        return tag;
+    }
+
+private:
+
+    SAXObject* m_obj;
+};
+
+DECLARE_PROCESS_FACTORY(cartesian_grid_xyProcess)

projects/lcdd/branches/v05-00-00-dev/src/lcdd/segmentation
SegmentationFactory.cc 3241 -> 3242
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/segmentation/SegmentationFactory.cc	2014-08-07 20:42:31 UTC (rev 3241)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/segmentation/SegmentationFactory.cc	2014-08-08 22:30:20 UTC (rev 3242)
@@ -127,7 +127,7 @@
         std::cerr << "Unknown child tag for calorimeter: " << tag << "." << std::endl;
     }
 
-    if (seg == 0) {
+    if (seg == NULL) {
         G4Exception("", "", FatalException, "Failed to create segmentation.");
     }
 
SVNspam 0.1


Use REPLY-ALL to reply to list

To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1