Print

Print


Commit in projects/lcdd/branches/v05-00-00-dev on MAIN
include/lcdd/detectors/SensitiveDetectorFactory.hh+23244 -> 3245
src/lcdd/detectors/SensitiveDetectorFactory.cc+44-373244 -> 3245
+46-37
2 modified files
Create DDSegmentation perhaps a bit more cleanly.

projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors
SensitiveDetectorFactory.hh 3244 -> 3245
--- projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors/SensitiveDetectorFactory.hh	2014-08-11 18:31:50 UTC (rev 3244)
+++ projects/lcdd/branches/v05-00-00-dev/include/lcdd/detectors/SensitiveDetectorFactory.hh	2014-08-11 19:00:16 UTC (rev 3245)
@@ -85,6 +85,8 @@
      * @return True if segmentation tag is valid; false if not.
      */
     static bool isSegmentationTag(const std::string& s);
+
+    static void createDDSegmentation(CalorimeterSD* calorimeter, ContentSequence* seq);
 };
 
 #endif

projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors
SensitiveDetectorFactory.cc 3244 -> 3245
--- projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/SensitiveDetectorFactory.cc	2014-08-11 18:31:50 UTC (rev 3244)
+++ projects/lcdd/branches/v05-00-00-dev/src/lcdd/detectors/SensitiveDetectorFactory.cc	2014-08-11 19:00:16 UTC (rev 3245)
@@ -123,41 +123,6 @@
             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));
@@ -166,8 +131,13 @@
         // Set the IdSpec.
         sensitiveDetector->setIdSpec(idspec);
 
+        // Create DDSegmentation if exists, which requires idspec and SensitiveDetector to be instantiated beforehand.
+        // FIXME: This is a weird place for this to happen I guess.
+        if (dynamic_cast<CalorimeterSD*>(sensitiveDetector) != NULL)
+            createDDSegmentation((CalorimeterSD*)sensitiveDetector, seq);
+
         // Add the list of HitProcessors.  This will automatically cause the HitProcessor setup code
-        // to be called to configure it for this SD.
+        // to be called in order to configure it for this SD.
         sensitiveDetector->addHitProcessors(hitProcessors);
 
         // Register the SensitiveDetector with the LCDDProcessor.
@@ -181,6 +151,42 @@
     return sensitiveDetector;
 }
 
+void SensitiveDetectorFactory::createDDSegmentation(CalorimeterSD* calorimeter, ContentSequence* seq) {
+    size_t count = seq->size();
+    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(calorimeter->getIdSpec()->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);
+
+            calorimeter->setDDSegmentation(cartesianGridXY);
+        }
+    }
+}
+
 SensitiveDetector* SensitiveDetectorFactory::createCalorimeter(const SAXObject* object, const std::vector<G4String>& hitsCollections) {
     const SensitiveDetectorType* sensitiveDetectorType = dynamic_cast<const SensitiveDetectorType*>(object);
     Segmentation* segmentation = 0;
@@ -198,9 +204,10 @@
         }
     }
 
+    // Create the CalorimeterSD object.
     CalorimeterSD* calorimeter = new CalorimeterSD(sensitiveDetectorType->get_name(), hitsCollections, segmentation);
 
-    // Create the calorimeter SD.
+    // Return the detector that was created.
     return calorimeter;
 }
 
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