7 added + 10 modified, total 17 files
lcdd/include
diff -N CellReadout2D.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CellReadout2D.hh 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,133 @@
+#ifndef lcdd_CellReadout2D_hh
+#define lcdd_CellReadout2D_hh 1
+
+#include <vector>
+#include <map>
+
+/**
+ * 2D cell readout with positive coordinate system originating
+ * at the upper left of a box volume. Cells are numbered from x,y = (1,1).
+ */
+class CellReadout2D
+{
+
+public:
+
+ typedef std::pair<int, int> Cell;
+ typedef std::pair<double, double> PositionXY;
+
+
+ virtual ~CellReadout2D();
+
+ CellReadout2D(double cellSizeX, double cellSizeY);
+
+ /**
+ * Get the X cell size.
+ */
+ virtual double getCellSizeX();
+
+ /**
+ * Get the Y cell size.
+ */
+ virtual double getCellSizeY();
+
+ /**
+ * Get the full dimension of the readout in X.
+ */
+ virtual double getDimensionX();
+
+ /**
+ * Get the full dimension of the readout in Y.
+ */
+ virtual double getDimensionY();
+
+ /**
+ * Get the local position of the cell.
+ */
+ virtual PositionXY getPosition(Cell);
+
+ /**
+ * Get the cell from a position.
+ */
+ virtual Cell getCell(PositionXY);
+
+ /**
+ * Get the X bin from a position.
+ */
+ virtual int getCellX(double x);
+
+ /**
+ * Get Y bin from a position.
+ */
+ virtual int getCellY(double y);
+
+ /*
+ * Get the X position from an X bin value.
+ */
+ virtual double getPositionX(int x);
+
+ /**
+ * Get the Y position from a Y bin value.
+ */
+ virtual double getPositionY(int y);
+
+ /**
+ * Get the neighbors of a cell.
+ */
+ virtual std::vector<Cell> getNeighbors(Cell);
+
+ /**
+ * Get a pair of indices representing a cell. This method should check that the indices are valid.
+ */
+ virtual Cell createCell(int x, int y);
+
+ /**
+ * Check if an X index is valid.
+ */
+ virtual bool isValidX(int x);
+
+ /**
+ * Check if a Y index is valid.
+ */
+ virtual bool isValidY(int y);
+
+ /**
+ * Check if a local X position is inside this readout.
+ */
+ virtual bool isInsideX(double x);
+
+ /**
+ * Check if a local Y position is inside this readout.
+ */
+ virtual bool isInsideY(double y);
+
+ /**
+ * Given a cell index, return the corresponding coordinate.
+ */
+ virtual double getCoordinate(int u, double cellSize);
+
+ /**
+ * Given a coordinate in the readout's reference frame, return the corresponding coordinate.
+ */
+ virtual int getIndex(double x, double cellSize);
+
+ /**
+ * Set the X dimension of the readout.
+ */
+ virtual void setDimensionX(double x);
+
+ /**
+ * Set the Y dimension of the readout.
+ */
+ virtual void setDimensionY(double y);
+
+private:
+
+ double m_cellSizeX;
+ double m_cellSizeY;
+
+ double m_dimensionX;
+ double m_dimensionY;
+};
+
+#endif
lcdd/include
diff -N CellReadout2DSegmentation.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CellReadout2DSegmentation.hh 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,40 @@
+#ifndef lcdd_CellReadout2DSegmentation_hh
+#define lcdd_CellReadout2DSegmentation_hh 1
+
+// LCDD
+#include "G4Segmentation.hh"
+#include "CellReadout2D.hh"
+
+// Geant4
+#include "G4ThreeVector.hh"
+
+class G4Step;
+
+/**
+ * Adapt a CellReadout2D to the LCDD Segmentation interface.
+ */
+class CellReadout2DSegmentation : public G4Segmentation
+{
+
+public:
+
+ CellReadout2DSegmentation(double cellSizeX, double cellSizeY);
+
+ virtual ~CellReadout2DSegmentation();
+
+ G4ThreeVector getGlobalHitPos(const G4Step*);
+
+ void setBins(const G4Step*);
+
+ void setBinNames();
+
+ void setup(const G4Step*);
+
+ CellReadout2D::PositionXY localToReadoutCoordinates(G4ThreeVector&);
+
+private:
+
+ CellReadout2D* m_readout;
+};
+
+#endif
lcdd/include
diff -N CellReadout2DSegmentationType.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CellReadout2DSegmentationType.hh 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,58 @@
+// $Header: /cvs/lcd/lcdd/include/CellReadout2DSegmentationType.hh,v 1.1 2013/05/30 00:04:12 jeremy Exp $
+
+#ifndef lcdd_CellReadout2DSegmentationType_hh
+#define lcdd_CellReadout2DSegmentationType_hh 1
+
+#include "SegmentationType.hh"
+
+#include <string>
+
+class CellReadout2DSegmentationType : public SegmentationType
+{
+
+public:
+
+ CellReadout2DSegmentationType() {}
+
+ virtual ~CellReadout2DSegmentationType() {}
+
+public:
+
+ void setCellSizeX(const std::string& cellSizeX)
+ {
+ m_cellSizeX = cellSizeX;
+ }
+
+ void setCellSizeY(const std::string& cellSizeY)
+ {
+ m_cellSizeY = cellSizeY;
+ }
+
+ void setLengthUnit(const std::string& lengthUnit)
+ {
+ m_lengthUnit = lengthUnit;
+ }
+
+ const std::string& getCellSizeX()
+ {
+ return m_cellSizeX;
+ }
+
+ const std::string& getCellSizeY()
+ {
+ return m_cellSizeY;
+ }
+
+ const std::string& getLengthUnit()
+ {
+ return m_lengthUnit;
+ }
+
+protected:
+
+ std::string m_cellSizeX;
+ std::string m_cellSizeY;
+ std::string m_lengthUnit;
+};
+
+#endif
lcdd/include
diff -N cell_readout_2d.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ cell_readout_2d.hh 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,31 @@
+// $Header: /cvs/lcd/lcdd/include/cell_readout_2d.hh,v 1.1 2013/05/30 00:04:12 jeremy Exp $
+
+#ifndef lcdd_cell_readout_2d_hh
+#define lcdd_cell_readout_2d_hh 1
+
+// LCDD
+#include "CellReadout2DSegmentationType.hh"
+
+// GDML
+#include "Saxana/SAXObject.h"
+
+class cell_readout_2d: public SAXObject, public CellReadout2DSegmentationType
+{
+
+public:
+
+ cell_readout_2d()
+ {
+ }
+
+ virtual ~cell_readout_2d()
+ {
+ }
+
+ virtual SAXObject::Type type()
+ {
+ return SAXObject::element;
+ }
+};
+
+#endif
lcdd/include
diff -u -r1.17 -r1.18
--- G4Segmentation.hh 30 Oct 2009 23:16:59 -0000 1.17
+++ G4Segmentation.hh 30 May 2013 00:04:12 -0000 1.18
@@ -12,131 +12,135 @@
/**
* @class G4Segmentation
* @brief Segmentation base class.
+ * @todo Add method setVolume(G4LogicalVolume*) for setting up segmentation with current step volume.
*/
class G4Segmentation
{
- public:
- enum EType { eProjective=1, eNonprojective };
- typedef std::vector<std::string> BinNames;
-
- public:
- G4Segmentation(EType segType, int nbins = 2);
- virtual ~G4Segmentation();
-
- public:
-
- /**
- * Compute the global hit position from a step.
- */
- virtual G4ThreeVector getGlobalHitPos(const G4Step* aStep);
-
- /**
- * Set the identifier bin values from a step.
- */
- virtual void setBins(const G4Step*) = 0;
-
- /**
- * Add valid bin names to this segmentation.
- */
- virtual void setBinNames() = 0;
-
- /**
- * Compute the bin given a coordinate in one dimension.
- */
- static int computeBin(double localDim, double gridDim)
- {
- return int(floor(localDim / gridDim ) );
+public:
+ enum EType
+ {
+ eProjective = 1, eNonprojective
+ };
+ typedef std::vector<std::string> BinNames;
- }
+public:
+ G4Segmentation(EType segType, int nbins = 2);
+ virtual ~G4Segmentation();
- /**
- * Compute the coordinate in one dimension given a bin value.
- */
- static double computeDim(const int &bin, const double &incr)
- {
- return (double(bin) + .5) * incr;
- }
+public:
- // DEPRECATED
- // Used by G4OpticalCalorimeter only.
- virtual G4ThreeVector getGlobalHitPosPreStep(const G4StepPoint* aPreStepPoint);
-
- // DEPRECATED
- // Used by G4OpticalCalorimeter only.
- G4ThreeVector getLocalHitPos(const G4ThreeVector& localStepPos);
-
- void resetBins();
-
- EType getType();
-
- inline const G4String& getTypeString()
- {
- static G4String typestr;
- if ( m_type == eProjective ) {
- typestr = "Projective";
- }
- else if ( m_type == eNonprojective ) {
- typestr = "Nonprojective";
- }
- else {
- typestr = "Unknown";
- }
+ /**
+ * Compute the global hit position from a step.
+ */
+ virtual G4ThreeVector getGlobalHitPos(const G4Step* aStep);
- return typestr;
- }
+ /**
+ * Set the identifier bin values from a step.
+ */
+ virtual void setBins(const G4Step*) = 0;
- inline int getBin(int idx)
- {
- return m_bins.at( idx );
- }
+ /**
+ * Add valid bin names to this segmentation.
+ */
+ virtual void setBinNames() = 0;
- inline const std::string& getBinName(int idx)
- {
- return m_binNames.at(idx);
- }
+ /**
+ * Compute the bin given a coordinate in one dimension.
+ */
+ static int computeBin(double localDim, double gridDim)
+ {
+ return int(floor(localDim / gridDim));
- inline void addBinName(const std::string& binName)
- {
- m_binNames.push_back(binName);
- }
+ }
- void setBin(int binIdx, int binVal);
+ /**
+ * Compute the coordinate in one dimension given a bin value.
+ */
+ static double computeDim(const int &bin, const double &incr)
+ {
+ return (double(bin) + .5) * incr;
+ }
- int getNumberOfBins();
+ // DEPRECATED
+ // Used by G4OpticalCalorimeter only.
+ virtual G4ThreeVector getGlobalHitPosPreStep(const G4StepPoint* aPreStepPoint);
- const std::vector<int>& getBins();
+ // DEPRECATED
+ // Used by G4OpticalCalorimeter only.
+ G4ThreeVector getLocalHitPos(const G4ThreeVector& localStepPos);
- const std::vector<std::string>& getBinNames()
- {
- return m_binNames;
- }
+ void resetBins();
+
+ EType getType();
- // Print the bins.
- void printOutBins(std::ostream& os)
- {
- printOutBins( os, m_bins );
+ inline const G4String& getTypeString()
+ {
+ static G4String typestr;
+ if (m_type == eProjective) {
+ typestr = "Projective";
+ }
+ else if (m_type == eNonprojective) {
+ typestr = "Nonprojective";
+ }
+ else {
+ typestr = "Unknown";
}
- static void printOutBins(std::ostream& os, const std::vector<int>& bins);
+ return typestr;
+ }
+
+ inline int getBin(int idx)
+ {
+ return m_bins.at(idx);
+ }
+
+ inline const std::string& getBinName(int idx)
+ {
+ return m_binNames.at(idx);
+ }
+
+ inline void addBinName(const std::string& binName)
+ {
+ m_binNames.push_back(binName);
+ }
+
+ void setBin(int binIdx, int binVal);
+
+ int getNumberOfBins();
+
+ const std::vector<int>& getBins();
+
+ const std::vector<std::string>& getBinNames()
+ {
+ return m_binNames;
+ }
+
+ // Print the bins.
+ void printOutBins(std::ostream& os)
+ {
+ printOutBins(os, m_bins);
+ }
+
+ static void printOutBins(std::ostream& os, const std::vector<int>& bins);
- /*
- * Check whether the solid is valid for this segmentation.
- */
- virtual bool isValidSolid(G4VSolid*);
+ /*
+ * Check whether the solid is valid for this segmentation.
+ */
+ virtual bool isValidSolid(G4VSolid*);
- private:
+private:
- // bin values
- std::vector<int> m_bins;
+ // bin values
+ std::vector<int> m_bins;
- // bin names
- BinNames m_binNames;
+ // bin names
+ BinNames m_binNames;
- // number of numbers
- int m_numBins;
+ // number of numbers
+ int m_numBins;
- // type of segmentation
- EType m_type;
+ // type of segmentation
+ EType m_type;
};
#endif
lcdd/include
diff -u -r1.18 -r1.19
--- ReadoutUtil.hh 1 Apr 2008 19:53:02 -0000 1.18
+++ ReadoutUtil.hh 30 May 2013 00:04:12 -0000 1.19
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/include/ReadoutUtil.hh,v 1.18 2008/04/01 19:53:02 wenzel Exp $
+// $Header: /cvs/lcd/lcdd/include/ReadoutUtil.hh,v 1.19 2013/05/30 00:04:12 jeremy Exp $
#ifndef LCDD_READOUTUTIL_HH
#define LCDD_READOUTUTIL_HH 1
@@ -34,13 +34,11 @@
public:
- static G4ThreeVector computeThreeVectorMean(const G4ThreeVector& vec1,
- const G4ThreeVector& vec2);
+ static G4ThreeVector computeThreeVectorMean(const G4ThreeVector& vec1, const G4ThreeVector& vec2);
static G4ThreeVector computeMidPos(const G4Step* aStep);
- static G4double computeDistance(const G4ThreeVector& vec1,
- const G4ThreeVector& vec2);
+ static G4double computeDistance(const G4ThreeVector& vec1, const G4ThreeVector& vec2);
static G4double computeDistance(const G4Step* aStep);
@@ -49,8 +47,7 @@
static G4TouchableHandle getTouchableFromStep(const G4Step* aStep);
- static G4ThreeVector getVolumeGlobalPosition(const G4StepPoint* aStepPoint,
- const G4ThreeVector& pnt );
+ static G4ThreeVector getVolumeGlobalPosition(const G4StepPoint* aStepPoint, const G4ThreeVector& pnt );
static G4ThreeVector getVolumeGlobalPosition(const G4StepPoint* aStepPoint);
@@ -64,14 +61,10 @@
static double getTubsThickness(const G4Tubs* tubs);
- static G4ThreeVector transformLocalToGlobal(const G4Step* aStep,
- const G4ThreeVector& localPos);
- static G4ThreeVector transformLocalToGlobal(const G4StepPoint* aPreStepPoint,
- const G4ThreeVector& localPos);
- static G4ThreeVector transformGlobalToLocal(const G4Step* aStep,
- const G4ThreeVector& globalPos);
- static G4ThreeVector transformGlobalToLocal(const G4StepPoint* aPreStepPoint,
- const G4ThreeVector& globalPos);
+ static G4ThreeVector transformLocalToGlobal(const G4Step* aStep, const G4ThreeVector& localPos);
+ static G4ThreeVector transformLocalToGlobal(const G4StepPoint* aPreStepPoint, const G4ThreeVector& localPos);
+ static G4ThreeVector transformGlobalToLocal(const G4Step* aStep, const G4ThreeVector& globalPos);
+ static G4ThreeVector transformGlobalToLocal(const G4StepPoint* aPreStepPoint, const G4ThreeVector& globalPos);
static int getVolumeNumber(G4TouchableHandle theTouchable, int historyDepth = -1);
lcdd/schemas/lcdd/1.0
diff -u -r1.7 -r1.8
--- lcdd_sensitive_detectors.xsd 7 Dec 2010 01:03:13 -0000 1.7
+++ lcdd_sensitive_detectors.xsd 30 May 2013 00:04:12 -0000 1.8
@@ -224,7 +224,30 @@
</xs:extension>
</xs:complexContent>
</xs:complexType>
-
+
+ <xs:complexType name="CellReadout2DSegmentationType">
+ <xs:annotation>
+ <xs:documentation>
+ CellReadout2D segmentation type.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexContent>
+ <xs:extension base="SegmentationType">
+ <xs:attribute name="cell_size_x" type="xs:double" use="required"/>
+ <xs:attribute name="cell_size_y" type="xs:double" use="required"/>
+ <xs:attribute default="mm" name="lunit" type="xs:string"/>
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+
+ <xs:element name="cell_readout_2d" substitutionGroup="segmentation" type="CellReadout2DSegmentationType">
+ <xs:annotation>
+ <xs:documentation>
+ The element definition for the CellReadout2DSegmentationType.
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
+
<xs:element name="grid_xyz" substitutionGroup="segmentation" type="NonprojectiveSegmentationType">
<xs:annotation>
<xs:documentation>
lcdd/src
diff -N CellReadout2D.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CellReadout2D.cc 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,135 @@
+#include "CellReadout2D.hh"
+
+#include <cmath>
+#include <iostream>
+
+CellReadout2D::CellReadout2D(double cellSizeX, double cellSizeY)
+ //: m_cellSizeX(cellSizeX), m_cellSizeY(m_cellSizeY)
+{
+ m_cellSizeX = cellSizeX;
+ m_cellSizeY = cellSizeY;
+ //std::cout << "args x,y: " << cellSizeX << " " << cellSizeY << std::endl;
+ std::cout << "CellReadout2D(x,y): " << m_cellSizeX << " " << m_cellSizeY << std::endl;
+}
+
+CellReadout2D::~CellReadout2D()
+{
+}
+
+double CellReadout2D::getCellSizeX()
+{
+ return m_cellSizeX;
+}
+
+double CellReadout2D::getCellSizeY()
+{
+ return m_cellSizeY;
+}
+
+double CellReadout2D::getDimensionX()
+{
+ return m_dimensionX;
+}
+
+double CellReadout2D::getDimensionY()
+{
+ return m_dimensionY;
+}
+
+int CellReadout2D::getCellX(double x)
+{
+ return getIndex(x, m_cellSizeX);
+}
+
+
+int CellReadout2D::getCellY(double y)
+{
+ return getIndex(y, m_cellSizeY);
+}
+
+CellReadout2D::PositionXY CellReadout2D::getPosition(CellReadout2D::Cell cell)
+{
+ int ix = cell.first;
+ int iy = cell.second;
+ PositionXY pos;
+ pos.first = getPositionX(ix);
+ pos.second = getPositionY(iy);
+ return pos;
+}
+
+double CellReadout2D::getCoordinate(int i, double cellSize)
+{
+ return (i*cellSize)-cellSize/2;
+}
+
+int CellReadout2D::getIndex(double x, double cellSize)
+{
+ std::cout << "getIndex(x,cellSize): " << x << " " << cellSize << std::endl;
+ std::cout << "floor(x/cellSize): " << std::floor(x/cellSize) << std::endl;
+ return std::floor(x/cellSize)+1;
+}
+
+double CellReadout2D::getPositionX(int ix)
+{
+ return getCoordinate(ix, m_cellSizeX);
+}
+
+double CellReadout2D::getPositionY(int iy)
+{
+ return getCoordinate(iy, m_cellSizeY);
+}
+
+CellReadout2D::Cell CellReadout2D::getCell(PositionXY xy)
+{
+ Cell cell;
+ cell.first = getCellX(xy.first);
+ cell.second = getCellY(xy.second);
+ return cell;
+}
+
+std::vector<CellReadout2D::Cell> CellReadout2D::getNeighbors(CellReadout2D::Cell cell)
+{
+ // TODO: implement me
+}
+
+CellReadout2D::Cell CellReadout2D::createCell(int x, int y)
+{
+ Cell cell;
+ cell.first = x;
+ cell.second = y;
+ return cell;
+}
+
+bool CellReadout2D::isValidX(int x)
+{
+ // FIXME: dummy implementation
+ return true;
+}
+
+bool CellReadout2D::isValidY(int y)
+{
+ // FIXME: dummy implementation
+ return true;
+}
+
+bool CellReadout2D::isInsideX(double x)
+{
+ // FIXME: dummy implementation
+ return true;
+}
+
+bool CellReadout2D::isInsideY(double y)
+{
+ // FIXME: dummy implementation
+ return true;
+}
+
+void CellReadout2D::setDimensionX(double dimensionX)
+{
+ m_dimensionX = dimensionX;
+}
+
+void CellReadout2D::setDimensionY(double dimensionY)
+{
+ m_dimensionY = dimensionY;
+}
lcdd/src
diff -N CellReadout2DSegmentation.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ CellReadout2DSegmentation.cc 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,92 @@
+#include "CellReadout2DSegmentation.hh"
+
+// Geant4
+#include "G4Step.hh"
+#include "G4Box.hh"
+
+// LCDD
+#include "ReadoutUtil.hh"
+
+// STL
+#include <cmath>
+
+CellReadout2DSegmentation::CellReadout2DSegmentation(double cellSizeX, double cellSizeY)
+ : G4Segmentation(G4Segmentation::eNonprojective, 2) {
+ m_readout = new CellReadout2D(cellSizeX, cellSizeY);
+ setBinNames();
+}
+
+CellReadout2DSegmentation::~CellReadout2DSegmentation() {
+ delete m_readout;
+}
+
+G4ThreeVector CellReadout2DSegmentation::getGlobalHitPos(const G4Step* aStep)
+{
+ // TODO: implement me
+}
+
+void CellReadout2DSegmentation::setBins(const G4Step* aStep)
+{
+ std::cout << "setBins" << std::endl;
+
+ std::cout << "cellSize(x,y): " << m_readout->getCellSizeX() << " " << m_readout->getCellSizeY() << std::endl;
+
+ // Set state from current step.
+ setup(aStep);
+
+ std::cout.precision(15);
+
+ std::cout << "dimension x: " << m_readout->getDimensionX() << std::endl;
+ std::cout << "dimension y: " << m_readout->getDimensionY() << std::endl;
+
+ // Compute the global mid-point of the step.
+ G4ThreeVector globalStepPos = ReadoutUtil::computeMidPos(aStep);
+
+ // Compute the local step position from the global mid-point.
+ G4ThreeVector localStepPos = ReadoutUtil::transformGlobalToLocal(aStep, globalStepPos);
+
+ std::cout << "localStepPos: " << localStepPos.x() << ", " << localStepPos.y() << ", " << localStepPos.z() << std::endl;
+
+ // Compute the X and Y readout coordinates from the local position.
+ CellReadout2D::PositionXY xy = localToReadoutCoordinates(localStepPos);
+
+ std::cout << "readout coordinates: " << xy.first << " " << xy.second << std::endl;
+
+ // Get the cell for the position.
+ CellReadout2D::Cell cell = m_readout->getCell(xy);
+
+ std::cout << "cell(ix,iy): " << cell.first << " " << cell.second << std::endl;
+
+ // Set bin values.
+ this->setBin(0, xy.first);
+ this->setBin(1, xy.second);
+
+ std::cout << std::endl;
+}
+
+void CellReadout2DSegmentation::setBinNames()
+{
+ addBinName("ix");
+ addBinName("iy");
+}
+
+void CellReadout2DSegmentation::setup(const G4Step* aStep)
+{
+ // Set dimensions from box volume.
+ G4VSolid* solid = ReadoutUtil::getSolidFromStepPoint(aStep->GetPreStepPoint());
+ G4Box* box = dynamic_cast<G4Box*>(solid);
+ if (0 == box) {
+ std::cerr << "Volume is not a box" << std::endl;
+ G4Exception("", "", FatalException, "CellReadout2D points to shape that is not a box.");
+ }
+ m_readout->setDimensionX(box->GetXHalfLength() * 2);
+ m_readout->setDimensionY(box->GetYHalfLength() * 2);
+}
+
+CellReadout2D::PositionXY CellReadout2DSegmentation::localToReadoutCoordinates(G4ThreeVector& vec)
+{
+ CellReadout2D::PositionXY xy;
+ xy.first = vec.x() + m_readout->getDimensionX() / 2.0;
+ xy.second = vec.y() + m_readout->getDimensionY() / 2.0;
+ return xy;
+}
lcdd/src
diff -N cell_readout_2dProcess.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ cell_readout_2dProcess.cc 30 May 2013 00:04:12 -0000 1.1
@@ -0,0 +1,77 @@
+// $Header: /cvs/lcd/lcdd/src/cell_readout_2dProcess.cc,v 1.1 2013/05/30 00:04:12 jeremy Exp $
+
+// 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"
+
+// LCDD
+#include "cell_readout_2d.hh"
+
+// std
+#include <iostream>
+
+class cell_readout_2dProcess: public SAXStateProcess
+{
+
+public:
+
+ cell_readout_2dProcess(const ProcessingContext* context = 0)
+ : SAXStateProcess(context), m_obj(0)
+ {
+ }
+
+ virtual ~cell_readout_2dProcess()
+ {
+ }
+
+ virtual const SAXComponentObject* Build() const
+ {
+ return this;
+ }
+
+ virtual void StartElement(const std::string& name, const ASCIIAttributeList& attrs)
+ {
+ std::cout << "cell_readout_2dProcess::StartElement: " << name << std::endl;
+
+ SAXObject** obj = Context()->GetTopObject();
+
+ cell_readout_2d* np = new cell_readout_2d;
+
+ np->setLengthUnit(attrs.getValue("lunit"));
+
+ np->setCellSizeX(attrs.getValue("cell_size_x"));
+ np->setCellSizeY(attrs.getValue("cell_size_y"));
+
+ m_obj = np;
+ *obj = np;
+ }
+
+ 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 = "cell_readout_2d";
+ return tag;
+ }
+
+private:
+
+ SAXObject* m_obj;
+};
+
+DECLARE_PROCESS_FACTORY(cell_readout_2dProcess)
lcdd/src
diff -u -r1.39 -r1.40
--- G4CalorimeterSD.cc 23 Aug 2011 22:40:52 -0000 1.39
+++ G4CalorimeterSD.cc 30 May 2013 00:04:12 -0000 1.40
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/G4CalorimeterSD.cc,v 1.39 2011/08/23 22:40:52 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4CalorimeterSD.cc,v 1.40 2013/05/30 00:04:12 jeremy Exp $
#include "G4CalorimeterSD.hh"
// lcdd
@@ -128,8 +128,7 @@
// This needs to be a <= comparison for cutting on 0,
// Geantinos, which always have 0 edep, are allowed.
- if (theEdep <= getEcut() && !isGeantino())
- {
+ if (theEdep <= getEcut() && !isGeantino()) {
#ifdef G4VERBOSE
if (getVerbose() > 2) {
std::cout << "G4CalorimeterSD::ProcessHits - cut on edep " << theEdep << std::endl;
@@ -165,12 +164,10 @@
G4CalorimeterHit* fndHit = 0;
// hit is not found?
- if (!( fndHit = findHit(thisHit)))
- {
+ if (!( fndHit = findHit(thisHit))) {
#ifdef G4VERBOSE
- if (getVerbose() > 1)
- {
+ if (getVerbose() > 1) {
std::cout << "G4CalorimeterSD::ProcessHits - new hit" << std::endl;
}
#endif
lcdd/src
diff -u -r1.9 -r1.10
--- G4SegmentationFactory.cc 1 Feb 2012 10:28:56 -0000 1.9
+++ G4SegmentationFactory.cc 30 May 2013 00:04:12 -0000 1.10
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/G4SegmentationFactory.cc,v 1.9 2012/02/01 10:28:56 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4SegmentationFactory.cc,v 1.10 2013/05/30 00:04:12 jeremy Exp $
// GDML
#include "Saxana/SAXObject.h"
@@ -14,6 +14,7 @@
#include "nonprojective_cylinder.hh"
#include "projective_cylinder.hh"
#include "projective_zplane.hh"
+#include "cell_readout_2d.hh"
// LCDD G4 segmentation bindings
#include "G4Segmentation.hh"
@@ -22,98 +23,85 @@
#include "G4ProjectiveCylinderSegmentation.hh"
#include "G4ProjectiveZPlaneSegmentation.hh"
#include "G4NonprojectiveCylinderSegmentation.hh"
+#include "CellReadout2DSegmentation.hh"
#include <iostream>
G4Segmentation* G4SegmentationFactory::createSegmentation(SAXObject* obj, const std::string& tag)
{
+ //std::cout << "creating segmentation" << std::endl;
+
G4Segmentation* seg = 0;
GDMLExpressionEvaluator* calc = GDMLProcessor::GetInstance()->GetEvaluator();
- if ( tag == "projective_cylinder" )
- {
- //std::cout << "add projective_cylinder here" << std::endl;
-
- projective_cylinder* prj = dynamic_cast<projective_cylinder*> ( obj );
-
+ if (tag == "projective_cylinder") {
+ projective_cylinder* prj = dynamic_cast<projective_cylinder*>(obj);
if (prj) {
int ntheta, nphi;
std::string sval = prj->get_ntheta();
- ntheta = (int)calc->Eval( sval );
+ ntheta = (int) calc->Eval(sval);
sval = prj->get_nphi();
- nphi = (int)calc->Eval( sval );
-
+ nphi = (int) calc->Eval(sval);
seg = new G4ProjectiveCylinderSegmentation(ntheta, nphi);
- }
- else
- {
+ } else {
std::cerr << "Failed cast to projective_cylinder!" << std::endl;
}
- }
- // GridXYZ
- else if ( tag == "grid_xyz" )
- {
- grid_xyz* np = dynamic_cast<grid_xyz*> ( obj );
- if (np)
- {
+
+ } else if (tag == "grid_xyz") {
+ // GridXYZ
+ grid_xyz* np = dynamic_cast<grid_xyz*>(obj);
+ if (np) {
double gsx, gsy, gsz;
gsx = gsy = gsz = 0.;
std::string lunit = np->get_lunit();
std::string sval = np->get_gridSizeX();
sval += "*" + lunit;
- gsx = calc->Eval( sval );
+ gsx = calc->Eval(sval);
sval = np->get_gridSizeY();
sval += "*" + lunit;
- gsy = calc->Eval( sval );
+ gsy = calc->Eval(sval);
sval = np->get_gridSizeZ();
sval += "*" + lunit;
- gsz = calc->Eval( sval );
+ gsz = calc->Eval(sval);
//std::cout << "grid x, y, z: " << gsx << ", " << gsy << ", " << gsz << std::endl;
seg = new G4GridXYZSegmentation(gsx,
- gsy,
- gsz);
- }
- else
- {
+ gsy,
+ gsz);
+ } else {
std::cerr << "Failed cast to grid_xyz!" << std::endl;
}
- }
+ }
// GlobalGridXY
- else if ( tag == "global_grid_xy" )
- {
- global_grid_xy* gridxy = dynamic_cast<global_grid_xy*> ( obj );
- if (gridxy)
- {
+ else if (tag == "global_grid_xy") {
+ global_grid_xy* gridxy = dynamic_cast<global_grid_xy*>(obj);
+ if (gridxy) {
double gsx, gsy;
gsx = gsy = 0.;
std::string lunit = gridxy->get_lunit();
std::string sval = gridxy->get_gridSizeX();
sval += "*" + lunit;
- gsx = calc->Eval( sval );
+ gsx = calc->Eval(sval);
sval = gridxy->get_gridSizeY();
sval += "*" + lunit;
- gsy = calc->Eval( sval );
+ gsy = calc->Eval(sval);
seg = new G4GlobalGridXYSegmentation(gsx, gsy);
- }
- else
- {
+ } else {
std::cerr << "Failed cast to global_grid_xy!" << std::endl;
- }
- }
- // handle NP cylinder
- else if ( tag == "nonprojective_cylinder" ) {
-
+ }
+ } else if (tag == "nonprojective_cylinder") {
+ // handle NP cylinder
+
//std::cout << "add nonprojective_cylinder here" << std::endl;
- nonprojective_cylinder* np = dynamic_cast<nonprojective_cylinder*> ( obj );
+ nonprojective_cylinder* np = dynamic_cast<nonprojective_cylinder*>(obj);
if (np) {
double gsp = 0;
@@ -123,53 +111,67 @@
std::string sval = np->get_gridSizePhi();
sval += "*" + lunit;
- gsp = calc->Eval( sval );
+ gsp = calc->Eval(sval);
sval = np->get_gridSizeZ();
sval += "*" + lunit;
- gsz = calc->Eval( sval );
+ gsz = calc->Eval(sval);
- seg = new G4NonprojectiveCylinderSegmentation( gsp, gsz );
- }
- else {
+ seg = new G4NonprojectiveCylinderSegmentation(gsp, gsz);
+ } else {
std::cerr << "Failed cast to nonprojective_cylinder!" << std::endl;
}
- }
- // handle projective_zplane
- else if ( tag == "projective_zplane" )
- {
-
+ } else if (tag == "projective_zplane") {
+ // handle projective_zplane
+
//std::cout << "add projective_zplane here" << std::endl;
-
- projective_zplane* prj = dynamic_cast<projective_zplane*> ( obj );
-
- if ( prj ) {
-
+
+ projective_zplane* prj = dynamic_cast<projective_zplane*>(obj);
+
+ if (prj) {
+
int ntheta, nphi;
std::string sval = prj->get_ntheta();
- ntheta = (int)calc->Eval( sval );
+ ntheta = (int) calc->Eval(sval);
sval = prj->get_nphi();
- nphi = (int)calc->Eval( sval );
-
+ nphi = (int) calc->Eval(sval);
+
//std::cout << "ntheta, nphi : "
// << ntheta << ", "
// << nphi << std::endl;
-
+
seg = new G4ProjectiveZPlaneSegmentation(ntheta, nphi);
- } // prj exists
- else
- {
+ } else {
std::cerr << "Failed cast to projective_zplane!" << std::endl;
} // prj no exist
- } // projective_zplane
- // bad segmentation tag
- else
- {
+ } else if (tag == "cell_readout_2d") {
+
+ //std::cout << "building cell_readout_2d" << std::endl;
+
+ cell_readout_2d* elem = dynamic_cast<cell_readout_2d*>(obj);
+ if (0 != elem) {
+ double cellSizeX, cellSizeY;
+ cellSizeX = cellSizeY = 0;
+ std::string lengthUnit = elem->getLengthUnit();
+
+ std::string val = elem->getCellSizeX();
+ val += "*" + lengthUnit;
+ cellSizeX = calc->Eval(val);
+
+ val = elem->getCellSizeY();
+ val += "*" + lengthUnit;
+ cellSizeY = calc->Eval(val);
+
+ std::cout << "G4SegmentationFactory creating CellReadout2DSegmentation(x,y): " << cellSizeX << " " << cellSizeY << std::endl;
+
+ seg = new CellReadout2DSegmentation(cellSizeX, cellSizeY);
+ }
+ } else {
+ // bad segmentation tag
std::cerr << "Unknown child tag for calorimeter: " << tag << "." << std::endl;
}
- if (seg == 0)
- {
+ if (seg == 0) {
G4Exception("", "", FatalException, "Failed to create segmentation.");
}
lcdd/src
diff -u -r1.16 -r1.17
--- G4SensitiveDetector.cc 12 May 2008 21:13:01 -0000 1.16
+++ G4SensitiveDetector.cc 30 May 2013 00:04:12 -0000 1.17
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/G4SensitiveDetector.cc,v 1.16 2008/05/12 21:13:01 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4SensitiveDetector.cc,v 1.17 2013/05/30 00:04:12 jeremy Exp $
#include "G4SensitiveDetector.hh"
@@ -28,181 +28,190 @@
const std::string& G4SensitiveDetector::noneStr = "none";
G4SensitiveDetector::G4SensitiveDetector(G4String sdName,
- G4String hcName,
- EType sdType)
- : G4VSensitiveDetector(sdName),
- m_idspec(0),
- m_type(sdType)
+ G4String hcName,
+ EType sdType)
+:
+ G4VSensitiveDetector(sdName),
+ m_idspec(0),
+ m_type(sdType)
{
// insert hits collection name into SD's name vector
collectionName.insert(hcName);
-
+
// register detector with G4SDManager
G4SDManager::GetSDMpointer()->AddNewDetector(this);
-
+
// Create the command messenger.
m_messenger = new SensitiveDetectorMessenger(this);
-
+
// Only one HC
m_hcids.clear();
m_hcids.push_back(-1);
}
G4SensitiveDetector::G4SensitiveDetector(G4String sdName,
- const vector<G4String>& hcNames,
- EType sdType)
- : G4VSensitiveDetector(sdName),
- m_idspec(0),
- m_type(sdType)
+ const vector<G4String>& hcNames,
+ EType sdType)
+:
+ G4VSensitiveDetector(sdName),
+ m_idspec(0),
+ m_type(sdType)
{
m_hcids.clear();
-
- for (int i=0; i < (int)hcNames.size(); i++)
- {
+
+ for (int i = 0; i < (int) hcNames.size(); i++) {
// insert hits collection name into SD's name vector
collectionName.insert(hcNames[i]);
m_hcids.push_back(-1);
}
-
+
// register detector with G4SDManager
G4SDManager::GetSDMpointer()->AddNewDetector(this);
-
+
// Create the command messenger.
m_messenger = new SensitiveDetectorMessenger(this);
}
G4SensitiveDetector::~G4SensitiveDetector()
-{}
+{
+}
+
+void G4SensitiveDetector::Initialize(G4HCofThisEvent *)
+{
+ // no-op
+}
+
+void G4SensitiveDetector::EndOfEvent(G4HCofThisEvent *)
+{
+ // no-op
+}
+
+G4bool G4SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
+{
+ // set cached step
+ setStep(aStep);
+
+ // doesn't write a hit
+ return false;
+}
+
+const std::string& G4SensitiveDetector::getTypeString() const
+{
+ if (m_type == eTracker) {
+ return trackerStr;
+ }
+ else if (m_type == eCalorimeter) {
+ return calorimeterStr;
+ }
+ return noneStr;
+}
+
+std::ostream& G4SensitiveDetector::printBasicInfo(std::ostream& os)
+{
+ os << "name: " << GetName() << std::endl;
+ os << "type: " << m_type << std::endl;
+ os << "hits collection: " << this->getHCName() << std::endl;
+ os << "hits collection ID: " << m_hcids[0] << std::endl;
+ os << "energy cut: " << G4BestUnit(m_ecut, "Energy") << std::endl;
+ os << "endcap flag: " << m_endcap << std::endl;
+ os << "verbose level: " << m_verbose << std::endl;
+
+ if (m_idspec != 0) {
+ os << "id spec: " << m_idspec->getName() << std::endl;
+ os << "id fields:";
+ for (IdSpec::IdFields::const_iterator it = m_idspec->IdFieldsBegin();
+ it != m_idspec->IdFieldsEnd();
+ it++) {
+ os << " " << (*it)->getLabel();
+ }
+ os << std::endl;
+ } else {
+ os << "idspec points to null!" << std::endl;
+ }
-void G4SensitiveDetector::Initialize(G4HCofThisEvent *)
+ return os;
+}
+
+Id64bit G4SensitiveDetector::makeId() const
{
- // no-op
+ std::cout << "makeId" << std::endl;
+
+ Id64bit id64;
+
+ if (hasIdSpec()) {
+
+ std::cout << "creating ordered id vec" << std::endl;
+
+ // get idvec ordered by this idspec
+ const IdVec ids = IdFactory::createOrderedIdVec(step(), this);
+
+ std::cout << "creating id 64 bit" << std::endl;
+
+ // pack into 64 bit cell id
+ id64 = IdFactory::createId64bit(ids, getIdSpec());
+ }
+
+ std::cout << "returning id" << std::endl;
+
+ return id64;
}
-void G4SensitiveDetector::EndOfEvent(G4HCofThisEvent *)
+G4VHitsCollection* G4SensitiveDetector::getHitsCollection() const
{
- // no-op
-}
-
-G4bool G4SensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*)
-{
- // set cached step
- setStep(aStep);
-
- // doesn't write a hit
- return false;
-}
-
-const std::string& G4SensitiveDetector::getTypeString() const
-{
- if ( m_type == eTracker ) {
- return trackerStr;
- }
- else if ( m_type == eCalorimeter ) {
- return calorimeterStr;
- }
- return noneStr;
-}
-
-std::ostream& G4SensitiveDetector::printBasicInfo(std::ostream& os)
-{
- os << "name: " << GetName() << std::endl;
- os << "type: " << m_type << std::endl;
- os << "hits collection: " << this->getHCName() << std::endl;
- os << "hits collection ID: " << m_hcids[0]<< std::endl;
- os << "energy cut: " << G4BestUnit( m_ecut, "Energy" ) << std::endl;
- os << "endcap flag: " << m_endcap << std::endl;
- os << "verbose level: " << m_verbose << std::endl;
-
- if ( m_idspec != 0 )
- {
- os << "id spec: " << m_idspec->getName() << std::endl;
- os << "id fields:";
- for ( IdSpec::IdFields::const_iterator it = m_idspec->IdFieldsBegin();
- it != m_idspec->IdFieldsEnd();
- it++ ) {
- os << " " << (*it)->getLabel();
- }
- os << std::endl;
- }
- else
- {
- os << "idspec points to null!" << std::endl;
- }
-
- return os;
-}
-
-Id64bit G4SensitiveDetector::makeId() const
-{
- Id64bit id64;
-
- if ( hasIdSpec() ) {
-
- // get idvec ordered by this idspec
- const IdVec ids = IdFactory::createOrderedIdVec( step(), this );
-
- // pack into 64 bit cell id
- id64 = IdFactory::createId64bit( ids, getIdSpec() );
- }
-
- return id64;
-}
-
-G4VHitsCollection* G4SensitiveDetector::getHitsCollection() const
-{
- G4VHitsCollection* hc = 0;
- if ( this->getHCID() != -1 ) {
- hc = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetHCofThisEvent()->GetHC( this->getHCID() );
- }
- return hc;
-}
-
-G4VHitsCollection* G4SensitiveDetector::getHitsCollection(G4int nHC) const
-{
- G4VHitsCollection* hc = 0;
- if ( this->getHCID(nHC) != -1 ) {
- hc = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetHCofThisEvent()->GetHC( this->getHCID(nHC) );
- }
- return hc;
+ G4VHitsCollection* hc = 0;
+ if (this->getHCID() != -1) {
+ hc = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetHCofThisEvent()->GetHC(
+ this->getHCID());
+ }
+ return hc;
}
-std::ostream& G4SensitiveDetector::printNumberOfHits(std::ostream& os)
+G4VHitsCollection* G4SensitiveDetector::getHitsCollection(G4int nHC) const
+ {
+ G4VHitsCollection* hc = 0;
+ if (this->getHCID(nHC) != -1) {
+ hc = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetHCofThisEvent()->GetHC(
+ this->getHCID(nHC));
+ }
+ return hc;
+}
+
+std::ostream& G4SensitiveDetector::printNumberOfHits(std::ostream& os)
{
- for (int i = 0; i < getNumberOfHitsCollections(); i++)
- {
+ for (int i = 0; i < getNumberOfHitsCollections(); i++)
+ {
os << getHitsCollection(i)->GetName() << " " << getHitsCollection(i)->GetSize() << std::endl;
}
return os;
}
-
-std::ostream& G4SensitiveDetector::printEdep(std::ostream& os)
+
+std::ostream& G4SensitiveDetector::printEdep(std::ostream& os)
{
- os << "total edep: " << G4BestUnit( this->getEdep(), "Energy" ) << std::endl;
- return os;
+ os << "total edep: " << G4BestUnit(this->getEdep(), "Energy") << std::endl;
+ return os;
}
-
-std::vector<G4LogicalVolume*> G4SensitiveDetector::getLogicalVolumes() const
+
+std::vector<G4LogicalVolume*> G4SensitiveDetector::getLogicalVolumes() const
{
- std::vector<G4LogicalVolume*> volumes;
- for ( G4LogicalVolumeStore::const_iterator it = G4LogicalVolumeStore::GetInstance()->begin();
- it != G4LogicalVolumeStore::GetInstance()->end();
- it++ ) {
- if ( (*it)->GetSensitiveDetector() == this ) {
- volumes.push_back( *it );
- }
- }
- return volumes;
-}
-
-std::ostream& G4SensitiveDetector::printVolumes(std::ostream& os)
-{
- std::vector<G4LogicalVolume*> volumes = this->getLogicalVolumes();
-
- for ( std::vector<G4LogicalVolume*>::const_iterator it = volumes.begin();
- it != volumes.end();
- it++ ) {
- std::cout << (*it)->GetName() << std::endl;
- }
- return os;
+ std::vector<G4LogicalVolume*> volumes;
+ for (G4LogicalVolumeStore::const_iterator it = G4LogicalVolumeStore::GetInstance()->begin();
+ it != G4LogicalVolumeStore::GetInstance()->end();
+ it++) {
+ if ((*it)->GetSensitiveDetector() == this) {
+ volumes.push_back(*it);
+ }
+ }
+ return volumes;
+}
+
+std::ostream& G4SensitiveDetector::printVolumes(std::ostream& os)
+{
+ std::vector<G4LogicalVolume*> volumes = this->getLogicalVolumes();
+
+ for (std::vector<G4LogicalVolume*>::const_iterator it = volumes.begin();
+ it != volumes.end();
+ it++) {
+ std::cout << (*it)->GetName() << std::endl;
+ }
+ return os;
}
lcdd/src
diff -u -r1.26 -r1.27
--- IdFactory.cc 1 Feb 2012 10:28:56 -0000 1.26
+++ IdFactory.cc 30 May 2013 00:04:12 -0000 1.27
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/IdFactory.cc,v 1.26 2012/02/01 10:28:56 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/IdFactory.cc,v 1.27 2013/05/30 00:04:12 jeremy Exp $
// set for verbose output from this class
//#define ID_DEBUG 1
@@ -23,370 +23,378 @@
Id64bit IdFactory::createId64bit(const IdVec& idvec, IdSpec* idspec)
{
#ifdef ID_DEBUG
- G4cout << G4endl;
- G4cout.setf( ios::hex );
- G4cout << "IdFactory::createId64bit()" << G4endl;
- G4cout << "idvec size: " << idvec.size() << G4endl;
- G4cout << "idspec numFields: " << idspec->getNumFields() << G4endl;
- G4cout << "idspec bitLength: " << idspec->getBitLength() << G4endl;
+ G4cout << G4endl;
+ G4cout.setf( ios::hex );
+ G4cout << "IdFactory::createId64bit()" << G4endl;
+ G4cout << "idvec size: " << idvec.size() << G4endl;
+ G4cout << "idspec numFields: " << idspec->getNumFields() << G4endl;
+ G4cout << "idspec bitLength: " << idspec->getBitLength() << G4endl;
#endif
- /* IdVec (expanded id) size must equal IdSpec size or die. */
- if ( idvec.size() != idspec->getNumFields() ) {
- G4Exception("", "", FatalException, "idspec size != idvec size.");
- }
+ /* IdVec (expanded id) size must equal IdSpec size or die. */
+ if (idvec.size() != idspec->getNumFields()) {
+ G4Exception("", "", FatalException, "idspec size != idvec size.");
+ }
- /* Make a 64-bit id to return. */
- Id64bit id64;
+ /* Make a 64-bit id to return. */
+ Id64bit id64;
- /* A 2 member array for cell ids 1 & 2 (2x32-bit int). */
- Bits id64_val[2] = { 0, 0 };
- size_t id64_val_idx = 0;
+ /* A 2 member array for cell ids 1 & 2 (2x32-bit int). */
+ Bits id64_val[2] = { 0, 0 };
+ size_t id64_val_idx = 0;
- /* Ptr to value of current idx. */
- Bits* id64_val_ptr = &id64_val[id64_val_idx];
+ /* Ptr to value of current idx. */
+ Bits* id64_val_ptr = &id64_val[id64_val_idx];
- /* Ptr to the current idfield. */
- IdField* id_field = 0;
+ /* Ptr to the current idfield. */
+ IdField* id_field = 0;
- /* Flag indicating that next 32-bit id has been reached. */
- bool next_id = false;
+ /* Flag indicating that next 32-bit id has been reached. */
+ bool next_id = false;
- /* loop vars */
- IdField::SizeType field_bit_len = 0;
- Bits curr_bit = 0;
- IdSpec::SizeType idspec_idx = 0;
+ /* loop vars */
+ IdField::SizeType field_bit_len = 0;
+ Bits curr_bit = 0;
+ IdSpec::SizeType idspec_idx = 0;
- /* Loop over the IdVec, packing its values into the 64-bit Id
+ /* Loop over the IdVec, packing its values into the 64-bit Id
using information from the IdSpec. */
- for (IdVec::ElementVector::const_iterator iter = idvec.getFieldsBegin();
- iter != idvec.getFieldsEnd();
- iter++) {
-
- /* field ptr from idspec */
- id_field = idspec->getIdField( idspec_idx );
- assert( id_field );
-
- /* id value of field */
- Id64bit::ElementType field_val = (Id64bit::ElementType) *iter;
-
- /* field length */
- field_bit_len = id_field->getLength();
-
- /* field start */
- Bits field_start = id_field->getStart();
-
- /* Don't allow crossing of 32-bit boundary.
- FIXME: See http://jira.slac.stanford.edu/browse/LCDD-21
- */
- if ( ( field_start < 32 ) && (field_start + field_bit_len > 32 ) ) {
- G4cerr << "Field <" << id_field->getLabel() << "> crosses the 32-bit boundary." << G4endl;
- G4Exception("", "", FatalException, "Fields are not allowed to cross the 32-bit boundary.");
- }
- /* check if on 2nd dbl word. */
- else if ( field_start >= 32 ) {
+ for (IdVec::ElementVector::const_iterator iter = idvec.getFieldsBegin();
+ iter != idvec.getFieldsEnd();
+ iter++) {
+
+ /* field ptr from idspec */
+ id_field = idspec->getIdField(idspec_idx);
+ assert( id_field);
+
+ /* id value of field */
+ Id64bit::ElementType field_val = (Id64bit::ElementType) *iter;
+
+ /* field length */
+ field_bit_len = id_field->getLength();
- /* If 1st time, set id val pntr. */
- if (!next_id) {
+ /* field start */
+ Bits field_start = id_field->getStart();
+
+ /* Don't allow crossing of 32-bit boundary.
+ FIXME: See http://jira.slac.stanford.edu/browse/LCDD-21
+ */
+ if ((field_start < 32) && (field_start + field_bit_len > 32)) {
+ G4cerr << "Field <" << id_field->getLabel() << "> crosses the 32-bit boundary." << G4endl;
+ G4Exception("", "", FatalException, "Fields are not allowed to cross the 32-bit boundary.");
+ }
+ /* check if on 2nd dbl word. */
+ else if (field_start >= 32) {
+
+ /* If 1st time, set id val pntr. */
+ if (!next_id) {
#ifdef ID_DEBUG
- G4cout << "setting ptr to next id" << G4endl;
+ G4cout << "setting ptr to next id" << G4endl;
#endif
- ++id64_val_idx;
- id64_val_ptr = &id64_val[id64_val_idx];
- next_id = true;
- }
+ ++id64_val_idx;
+ id64_val_ptr = &id64_val[id64_val_idx];
+ next_id = true;
+ }
- /* Adjust start idx for position in next 32-bit id. */
- field_start -= 32;
- }
+ /* Adjust start idx for position in next 32-bit id. */
+ field_start -= 32;
+ }
- Bits field_mask = makeBitMask(field_bit_len);
+ Bits field_mask = makeBitMask(field_bit_len);
#ifdef ID_DEBUG
- G4cout << "idspec_idx: " << dec << idspec_idx << G4endl;
- G4cout << "shifting left: " << dec << field_bit_len << G4endl;
- G4cout << "curr_bit: " << dec << curr_bit << G4endl;
- G4cout << "field_label: " << id_field->getLabel() << G4endl;
- G4cout << "field_start: " << field_start << G4endl;
- G4cout << "field_val (dec): " << dec << field_val << G4endl;
- G4cout << "field_val (hex): " << hex << field_val << G4endl;
- G4cout << "field_bit_len: " << dec << field_bit_len << G4endl;
- G4cout << "field_mask: " << hex << field_mask << G4endl;
-#endif
-
- /* For positive values, check that this value doesn't overflow the assigned length. */
- // if ( field_val > 0 ) {
- if ( checkOverflow(field_val, field_mask) != 0 ) {
- G4cerr << "Value <" << field_val
- << "> is too big for the field <"
- << id_field->getLabel() << ">, len <"
- << field_bit_len << ">." << G4endl;
- G4Exception("", "", FatalException, "Value too large for field.");
- }
- // }
- // else {
- // }
+ G4cout << "idspec_idx: " << dec << idspec_idx << G4endl;
+ G4cout << "shifting left: " << dec << field_bit_len << G4endl;
+ G4cout << "curr_bit: " << dec << curr_bit << G4endl;
+ G4cout << "field_label: " << id_field->getLabel() << G4endl;
+ G4cout << "field_start: " << field_start << G4endl;
+ G4cout << "field_val (dec): " << dec << field_val << G4endl;
+ G4cout << "field_val (hex): " << hex << field_val << G4endl;
+ G4cout << "field_bit_len: " << dec << field_bit_len << G4endl;
+ G4cout << "field_mask: " << hex << field_mask << G4endl;
+#endif
+
+ /* For positive values, check that this value doesn't overflow the assigned length. */
+ // if ( field_val > 0 ) {
+ if (checkOverflow(field_val, field_mask) != 0) {
+ G4cerr << "Value <" << field_val
+ << "> is too big for the field <"
+ << id_field->getLabel() << ">, len <"
+ << field_bit_len << ">." << G4endl;
+ G4Exception("", "", FatalException, "Value too large for field.");
+ }
+ // }
+ // else {
+ // }
#ifdef ID_DEBUG
- G4cout << "field_mask: " << hex << field_mask << G4endl;
+ G4cout << "field_mask: " << hex << field_mask << G4endl;
#endif
- /* Apply bit mask and shift to proper left pos. */
- Bits field_val_shifted_masked = ( field_val & field_mask ) << field_start;
+ /* Apply bit mask and shift to proper left pos. */
+ Bits field_val_shifted_masked = (field_val & field_mask) << field_start;
- /* AND into the current id val. */
- (*id64_val_ptr) = (*id64_val_ptr) | field_val_shifted_masked;
+ /* AND into the current id val. */
+ (*id64_val_ptr) = (*id64_val_ptr) | field_val_shifted_masked;
- /* Set current bit to next start pos. */
- curr_bit += id_field->getLength();
+ /* Set current bit to next start pos. */
+ curr_bit += id_field->getLength();
#ifdef ID_DEBUG
- G4cout << "id64_val (hex): " << hex << *id64_val_ptr << G4endl;
- G4cout << G4endl;
+ G4cout << "id64_val (hex): " << hex << *id64_val_ptr << G4endl;
+ G4cout << G4endl;
#endif
- /* Increment the idspec idx. */
- ++idspec_idx;
- }
+ /* Increment the idspec idx. */
+ ++idspec_idx;
+ }
#ifdef ID_DEBUG
- G4cout << "end curr_bit: " << dec << curr_bit << G4endl;
- G4cout << "end id64[0]: " << hex << id64_val[0] << G4endl;
- G4cout << "end id64[1]: " << hex << id64_val[1] << G4endl;
- G4cout.unsetf( ios::hex );
- G4cout << G4endl << G4endl;
+ G4cout << "end curr_bit: " << dec << curr_bit << G4endl;
+ G4cout << "end id64[0]: " << hex << id64_val[0] << G4endl;
+ G4cout << "end id64[1]: " << hex << id64_val[1] << G4endl;
+ G4cout.unsetf( ios::hex );
+ G4cout << G4endl << G4endl;
#endif
- /* Set the two 32-bit ids in the packed id to return. */
- id64.setId0( id64_val[0] );
- id64.setId1( id64_val[1] );
+ /* Set the two 32-bit ids in the packed id to return. */
+ id64.setId0(id64_val[0]);
+ id64.setId1(id64_val[1]);
- return id64;
+ return id64;
}
inline IdFactory::Bits IdFactory::makeBitMask(IdField::SizeType len)
{
- return (Bits)((1 << len) - 1);
+ return (Bits) ((1 << len) - 1);
}
inline IdFactory::Bits IdFactory::checkOverflow(Id64bit::ElementType val, Bits mask)
{
- Bits xbits = 0x0;
+ Bits xbits = 0x0;
- /* get flipped mask of all 1's in positions that should be masked off for this val */
- Bits flipMask = mask ^ MASK_ON;
+ /* get flipped mask of all 1's in positions that should be masked off for this val */
+ Bits flipMask = mask ^ MASK_ON;
- /* mask off all the valid bits, leaving overflow bits */
- Id64bit::ElementType overflow = (val & flipMask);
+ /* mask off all the valid bits, leaving overflow bits */
+ Id64bit::ElementType overflow = (val & flipMask);
- /* for pos vals, check that no bits past max bit are = 1 */
- if ( val >= 0 ) {
- xbits = (Bits) ((flipMask) & overflow);
- }
- /* for neg vals, check that no bits past max bit are = 0 */
- else {
- xbits = (Bits) ((flipMask) ^ overflow);
- }
+ /* for pos vals, check that no bits past max bit are = 1 */
+ if (val >= 0) {
+ xbits = (Bits) ((flipMask) & overflow);
+ }
+ /* for neg vals, check that no bits past max bit are = 0 */
+ else {
+ xbits = (Bits) ((flipMask) ^ overflow);
+ }
#ifdef ID_DEBUG
- G4cout << "flipMask: " << hex << flipMask << G4endl;
- G4cout << "overflow: " << hex << overflow << G4endl;
- G4cout << "overflow bits (hex): " << hex << xbits << G4endl;
+ G4cout << "flipMask: " << hex << flipMask << G4endl;
+ G4cout << "overflow: " << hex << overflow << G4endl;
+ G4cout << "overflow bits (hex): " << hex << xbits << G4endl;
#endif
- return xbits;
+ return xbits;
}
IdVec IdFactory::createOrderedIdVec(G4Step* aStep, const G4SensitiveDetector* sd)
{
- assert( aStep );
- assert( sd );
+ std::cout << "createOrderedIdVec" << std::endl;
- IdSpec* idspec = sd->getIdSpec();
- IdVec ids;
+ assert(aStep);
+ assert(sd);
- G4Segmentation* seg = 0;
- if ( sd->getType() == G4SensitiveDetector::eCalorimeter ) {
- seg = (dynamic_cast<const G4CalorimeterSD*> ( sd ) )->getSegmentation();
- }
+ IdSpec* idspec = sd->getIdSpec();
+ IdVec ids;
- if ( idspec ) {
- for ( IdSpec::IdFields::const_iterator iter = idspec->IdFieldsBegin();
- iter != idspec->IdFieldsEnd();
- iter++ ) {
+ G4Segmentation* seg = 0;
+ if (sd->getType() == G4SensitiveDetector::eCalorimeter) {
+ seg = (dynamic_cast<const G4CalorimeterSD*>(sd))->getSegmentation();
+ }
- IdField* f = *iter;
+ if (idspec) {
+ for (IdSpec::IdFields::const_iterator iter = idspec->IdFieldsBegin();
+ iter != idspec->IdFieldsEnd();
+ iter++) {
- int bin_val = 0;
- bool fnd_it = false;
+ IdField* f = *iter;
+
+ int bin_val = 0;
+ bool fnd_it = false;
#ifdef ID_DEBUG
- G4cout << "handling field: " << f->getLabel() << G4endl;
+ G4cout << "handling field: " << f->getLabel() << G4endl;
#endif
- // look in seg, if exists
- if ( seg ) {
- int bin_idx = IdFactory::findFieldIdxInSegmentation( seg, f->getLabel() );
+ // look in seg, if exists
+ if (seg) {
+ int bin_idx = IdFactory::findFieldIdxInSegmentation(seg, f->getLabel());
- if ( bin_idx != -1 ) {
- bin_val = seg->getBin( bin_idx );
- fnd_it = true;
- }
+ if (bin_idx != -1) {
+ std::cout << "getting bin: " << bin_idx << std::endl;
+ bin_val = seg->getBin(bin_idx);
+ std::cout << "got bin val: " << bin_val << std::endl;
+ fnd_it = true;
+ }
#ifdef ID_DEBUG
- else {
- G4cout << "not in segmentation" << G4endl;
- }
+ else {
+ G4cout << "not in segmentation" << G4endl;
+ }
#endif
- }
+ }
- // find in PV ids
- if ( !fnd_it ) {
- std::vector<G4VPhysicalVolume*> pv_list = ReadoutUtil::getPhysVolList( aStep );
+ // find in PV ids
+ if (!fnd_it) {
+ std::vector<G4VPhysicalVolume*> pv_list = ReadoutUtil::getPhysVolList(aStep);
- if ( hasPhysVolId( pv_list, f->getLabel() ) ) {
- fnd_it = true;
- bin_val = findIdInPhysVols( pv_list, f->getLabel() );
- }
+ if (hasPhysVolId(pv_list, f->getLabel())) {
+ fnd_it = true;
+ bin_val = findIdInPhysVols(pv_list, f->getLabel());
+ }
#ifdef ID_DEBUG
- else {
- G4cout << "not in physvolids" << G4endl;
- }
+ else {
+ G4cout << "not in physvolids" << G4endl;
+ }
#endif
- }
+ }
- /* Find in copy numbers of the volume. */
- if (!fnd_it && f->getLabel() == "volume" ) {
- bin_val = ReadoutUtil::getVolumeNumber( aStep->GetPreStepPoint()->GetTouchableHandle() );
+ /* Find in copy numbers of the volume. */
+ if (!fnd_it && f->getLabel() == "volume") {
+ bin_val = ReadoutUtil::getVolumeNumber(aStep->GetPreStepPoint()->GetTouchableHandle());
- if ( -1 == bin_val ) {
- G4Exception("", "", FatalException, "Valid copy number not found for PV.");
- }
- else {
- fnd_it = true;
- }
- }
+ if (-1 == bin_val) {
+ G4Exception("", "", FatalException, "Valid copy number not found for PV.");
+ }
+ else {
+ fnd_it = true;
+ }
+ }
#ifdef ID_DEBUG
- else {
- G4cout << "not in volume (copyNum)" << G4endl;
- }
+ else {
+ G4cout << "not in volume (copyNum)" << G4endl;
+ }
#endif
- // Push back zero as the default value for field not found.
- ids.push_back( bin_val );
+ // Push back zero as the default value for field not found.
+ ids.push_back(bin_val);
#ifdef ID_DEBUG
- G4cout << "set bin val: " << bin_val << G4endl << G4endl;
+ G4cout << "set bin val: " << bin_val << G4endl << G4endl;
#endif
+ }
}
- }
- return ids;
+ return ids;
}
int IdFactory::findFieldIdxInSegmentation(G4Segmentation* seg, const std::string& field_name)
{
- const std::vector<std::string>& bin_names = seg->getBinNames();
+ const std::vector<std::string>& bin_names = seg->getBinNames();
- int bin_count = 0;
- bool fnd = false;
- for ( std::vector<std::string>::const_iterator iter = bin_names.begin();
- iter != bin_names.end();
- iter++ ) {
- if (*iter == field_name ) {
- fnd = true;
- break;
+ int bin_count = 0;
+ bool fnd = false;
+ for (std::vector<std::string>::const_iterator iter = bin_names.begin();
+ iter != bin_names.end();
+ iter++) {
+ if (*iter == field_name) {
+ fnd = true;
+ break;
+ }
+ ++bin_count;
}
- ++bin_count;
- }
- if ( !fnd ) {
- bin_count = -1;
- }
+ if (!fnd) {
+ bin_count = -1;
+ }
- return bin_count;
+ return bin_count;
}
int IdFactory::findIdInPhysVols(const std::vector<G4VPhysicalVolume*>& pvs, const std::string& field_name)
{
- IdManager* id_mgr = IdManager::instance();
+ IdManager* id_mgr = IdManager::instance();
#ifdef ID_DEBUG
- G4cout << "looking for field_name match on <" << field_name << ">" << G4endl;
+ G4cout << "looking for field_name match on <" << field_name << ">" << G4endl;
#endif
- int id = 0;
- G4VPhysicalVolume* pv = 0;
- bool fnd = false;
+ int id = 0;
+ G4VPhysicalVolume* pv = 0;
+ bool fnd = false;
- for ( std::vector<G4VPhysicalVolume*>::const_iterator iter_pv = pvs.begin();
- iter_pv != pvs.end();
- iter_pv++ ) {
- pv = *iter_pv;
+ for (std::vector<G4VPhysicalVolume*>::const_iterator iter_pv = pvs.begin();
+ iter_pv != pvs.end();
+ iter_pv++) {
+ pv = *iter_pv;
#ifdef ID_DEBUG
- G4cout << "searching in ids of PV <" << pv->GetName() << ">" << G4endl;
+ G4cout << "searching in ids of PV <" << pv->GetName() << ">" << G4endl;
#endif
- if ( id_mgr->hasPhysVolIds( pv ) ) {
- PhysVolId::PhysVolIds pvids = id_mgr->getPhysVolIds( pv );
- for ( PhysVolId::PhysVolIds::const_iterator iter = pvids.begin();
- iter != pvids.end();
- iter++ ) {
+ if (id_mgr->hasPhysVolIds(pv)) {
+ PhysVolId::PhysVolIds pvids = id_mgr->getPhysVolIds(pv);
+ for (PhysVolId::PhysVolIds::const_iterator iter = pvids.begin();
+ iter != pvids.end();
+ iter++) {
#ifdef ID_DEBUG
- G4cout << "current field <" << (*iter).getFieldName() << ">" << G4endl;
+ G4cout << "current field <" << (*iter).getFieldName() << ">" << G4endl;
#endif
- if ( (*iter).getFieldName() == field_name ) {
+ if ((*iter).getFieldName() == field_name) {
#ifdef ID_DEBUG
- G4cout << "found a match" << G4endl;
+ G4cout << "found a match" << G4endl;
#endif
- id = (*iter).getValue();
- fnd = true;
- break;
- }
+ id = (*iter).getValue();
+ fnd = true;
+ break;
+ }
#ifdef ID_DEBUG
- else {
- G4cout << "no match on this PV" << G4endl;
- }
+ else {
+ G4cout << "no match on this PV" << G4endl;
+ }
#endif
- }
- }
+ }
+ }
- if (fnd) { break; }
- }
+ if (fnd) {
+ break;
+ }
+ }
- return id;
+ return id;
}
bool IdFactory::hasPhysVolId(const std::vector<G4VPhysicalVolume*>& pvs, const std::string& field_name)
{
- IdManager* id_mgr = IdManager::instance();
+ IdManager* id_mgr = IdManager::instance();
- G4VPhysicalVolume* pv = 0;
- bool fnd = false;
+ G4VPhysicalVolume* pv = 0;
+ bool fnd = false;
- for ( std::vector<G4VPhysicalVolume*>::const_iterator iter_pv = pvs.begin();
- iter_pv != pvs.end();
- iter_pv++ ) {
- pv = *iter_pv;
-
- if ( id_mgr->hasPhysVolIds( pv ) ) {
- PhysVolId::PhysVolIds pvids = id_mgr->getPhysVolIds( pv );
- for ( PhysVolId::PhysVolIds::const_iterator iter = pvids.begin();
- iter != pvids.end();
- iter++ ) {
-
- if ( (*iter).getFieldName() == field_name ) {
- fnd = true;
- break;
- }
- }
+ for (std::vector<G4VPhysicalVolume*>::const_iterator iter_pv = pvs.begin();
+ iter_pv != pvs.end();
+ iter_pv++) {
+ pv = *iter_pv;
+
+ if (id_mgr->hasPhysVolIds(pv)) {
+ PhysVolId::PhysVolIds pvids = id_mgr->getPhysVolIds(pv);
+ for (PhysVolId::PhysVolIds::const_iterator iter = pvids.begin();
+ iter != pvids.end();
+ iter++) {
+
+ if ((*iter).getFieldName() == field_name) {
+ fnd = true;
+ break;
+ }
+ }
+ }
+
+ if (fnd) {
+ break;
+ }
}
- if (fnd) { break; }
- }
-
- return fnd;
+ return fnd;
}
lcdd/src
diff -u -r1.29 -r1.30
--- LCDDLibLoad.cc 3 Oct 2012 00:48:25 -0000 1.29
+++ LCDDLibLoad.cc 30 May 2013 00:04:12 -0000 1.30
@@ -31,6 +31,7 @@
LOAD_COMPONENT(projective_zplaneProcess);
LOAD_COMPONENT(nonprojective_cylinderProcess);
LOAD_COMPONENT(global_grid_xyProcess);
+ LOAD_COMPONENT(cell_readout_2dProcess);
// Ids
LOAD_COMPONENT(idspecProcess);
lcdd/src
diff -u -r1.23 -r1.24
--- SensitiveDetectorFactory.cc 1 Feb 2012 10:28:56 -0000 1.23
+++ SensitiveDetectorFactory.cc 30 May 2013 00:04:12 -0000 1.24
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/SensitiveDetectorFactory.cc,v 1.23 2012/02/01 10:28:56 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/SensitiveDetectorFactory.cc,v 1.24 2013/05/30 00:04:12 jeremy Exp $
#include "SensitiveDetectorFactory.hh"
// lcdd
@@ -13,98 +13,90 @@
#include "StringUtil.hh"
G4SensitiveDetector* SensitiveDetectorFactory::createSensitiveDetector(
- const SAXObject* object )
+ const SAXObject* object)
{
+ //std::cout << "create SD" << std::endl;
+
G4SensitiveDetector* sd = 0;
const SensitiveDetectorType* sdt =
- dynamic_cast< const SensitiveDetectorType* > ( object );
+ dynamic_cast<const SensitiveDetectorType*>(object);
- if ( sdt )
- {
+ if (sdt) {
std::string sd_type = sdt->get_type();
/* Create calorimeter subdetector. */
// TODO Check if "calorimeter" in the sd_type.
- if ( sd_type == "calorimeter" || sd_type == "optical_calorimeter" || sd_type
- == "unsegmented_calorimeter" )
- {
- sd = createCalorimeterSD( object );
+ if (sd_type == "calorimeter" || sd_type == "optical_calorimeter" || sd_type == "unsegmented_calorimeter") {
+ //std::cout << "creating calorimeter" << std::endl;
+ sd = createCalorimeterSD(object);
}
/* Create tracker subdetector. */
- else if ( sd_type == "tracker" )
- {
- sd = createTrackerSD( object );
+ else if (sd_type == "tracker") {
+ sd = createTrackerSD(object);
}
/* Create scorer subdetector. */
- else if ( sd_type == "scorer" )
- {
- sd = createScorerSD( object );
- }
- /* Type not recognized. */
- else
- {
+ else if (sd_type == "scorer") {
+ sd = createScorerSD(object);
+ } else {
+ /* Type not recognized. */
G4cerr << "Invalid sd_type <" << sd_type << ">." << G4endl;
- G4Exception( "", "", FatalException, "Unknown SD type. Check the LCDD file." );
+ G4Exception("", "", FatalException, "Unknown SD type. Check the LCDD file.");
}
// set ecut and verbose
- setBaseSensitiveDetectorAttributes( sd, sdt );
+ setBaseSensitiveDetectorAttributes(sd, sdt);
// find idspec
- IdSpec* idspec = findIdSpec( sdt );
+ IdSpec* idspec = findIdSpec(sdt);
// set idspec, if exists (null is ok)
- if ( idspec != 0 )
- {
- sd->setIdSpec( idspec );
+ if (idspec != 0)
+ {
+ sd->setIdSpec(idspec);
}
// register the SD
std::string sdName = sd->GetName();
- LCDDProcessor::instance()->addSensitiveDetector( sdName, sd );
- }
- else
- {
+ LCDDProcessor::instance()->addSensitiveDetector(sdName, sd);
+ } else {
G4Exception("", "", FatalException, "Failed cast to SensitiveDetectorType.");
}
return sd;
}
-G4CalorimeterSD* SensitiveDetectorFactory::createCalorimeterSD( const SAXObject* object )
+G4CalorimeterSD* SensitiveDetectorFactory::createCalorimeterSD(const SAXObject* object)
{
G4CalorimeterSD* sd = 0;
G4Segmentation* seg = 0;
const SensitiveDetectorType* sdt =
- dynamic_cast< const SensitiveDetectorType* > ( object );
+ dynamic_cast<const SensitiveDetectorType*>(object);
std::string sd_type = sdt->get_type();
// Create the segmentation.
- ContentSequence* seq = const_cast< ContentSequence* > ( sdt->get_content() );
+ ContentSequence* seq = const_cast<ContentSequence*>(sdt->get_content());
size_t count = seq->size();
// Look for segmentation tag.
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 );
+ 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 ) )
- {
- seg = G4SegmentationFactory::createSegmentation( segitem.object, segitem.tag );
+ if (isSegmentationTag(child_tag)) {
+ seg = G4SegmentationFactory::createSegmentation(segitem.object, segitem.tag);
fnd_seg = true;
break;
}
}
// Get the calorimeter XML object.
- const calorimeter* cal = dynamic_cast< const calorimeter* > ( object );
+ const calorimeter* cal = dynamic_cast<const calorimeter*>(object);
// Find out hit aggregation algorithm.
const std::string& hitCompareStr = cal->get_compare();
@@ -113,23 +105,19 @@
HitComparator* hitCompare = 0;
// Find the IdSpec.
- IdSpec* idspec = findIdSpec( sdt );
+ IdSpec* idspec = findIdSpec(sdt);
- if ( hitCompareStr != "id" && hitCompareStr != "position" )
- {
- G4cerr << "Invalid selection for hit comparison <" << hitCompareStr << ">, for calorimeter <" << sdt->get_name() << ">." << G4endl;
+ if (hitCompareStr != "id" && hitCompareStr != "position") {
+ G4cerr << "Invalid selection for hit comparison <" << hitCompareStr << ">, for calorimeter <"
+ << sdt->get_name() << ">." << G4endl;
G4Exception("", "", FatalException, "Invalid selection for hit comparison.");
}
// Compare on IDs.
- if ( hitCompareStr == "id" )
- {
- if ( idspec )
- {
+ if (hitCompareStr == "id") {
+ if (idspec) {
hitCompare = new IdComparator();
- }
- else
- {
+ } else {
std::cerr << "WARNING: IdSpec for <" << sdt->get_name()
<< "> does not exist! Position comparison will be used for hit aggregation instead of id."
<< std::endl;
@@ -137,43 +125,35 @@
}
// Compare on position.
- if ( !hitCompare )
- {
+ if (!hitCompare) {
hitCompare = new PositionComparator();
}
- if ( sd_type == "calorimeter" )
- {
+ if (sd_type == "calorimeter") {
sd = new G4CalorimeterSD(
sdt->get_name(),
sdt->get_hitsCollectionName(),
seg,
- hitCompare );
+ hitCompare);
}
- else if ( sd_type == "optical_calorimeter" )
- {
+ else if (sd_type == "optical_calorimeter") {
//
// in case of optical alorimeter there are 2 hit collections
//
//G4String hcnames[2];
// TODO Fix hardcoded collection names.
- std::vector< G4String > hcnames;
- hcnames.push_back( "Edep_" + sdt->get_hitsCollectionName() );
- hcnames.push_back( "Ceren_" + sdt->get_hitsCollectionName() );
+ std::vector<G4String> hcnames;
+ hcnames.push_back("Edep_" + sdt->get_hitsCollectionName());
+ hcnames.push_back("Ceren_" + sdt->get_hitsCollectionName());
//std::cout<< " now creating optical calorimeter"<<std::endl;
- sd = new G4OpticalCalorimeterSD( sdt->get_name(), hcnames, seg, hitCompare );
- }
- else if ( sd_type == "unsegmented_calorimeter" )
- {
+ sd = new G4OpticalCalorimeterSD(sdt->get_name(), hcnames, seg, hitCompare);
+ } else if (sd_type == "unsegmented_calorimeter") {
// Segmentation could be null but that is fine for this type of calorimeter.
sd = new G4UnsegmentedCalorimeterSD(
sdt->get_name(),
sdt->get_hitsCollectionName(),
- seg );
- }
- else
- {
-
+ seg);
+ } else {
G4cerr << "Unknown sensitive detector type: " << sd_type << G4endl;
G4Exception("SensitiveDetectorFactory", "", FatalException, "Unknown sensitive detector type.");
}
@@ -181,75 +161,70 @@
return sd;
}
-G4TrackerSD* SensitiveDetectorFactory::createTrackerSD( const SAXObject* object )
+G4TrackerSD* SensitiveDetectorFactory::createTrackerSD(const SAXObject* object)
{
- const tracker* trk = dynamic_cast< const tracker* > ( object );
+ const tracker* trk = dynamic_cast<const tracker*>(object);
- bool combineHits = StringUtil::toBool( trk->get_combine_hits() );
+ bool combineHits = StringUtil::toBool(trk->get_combine_hits());
G4TrackerSD* sd = 0;
std::string nm = trk->get_name();
std::string hc = trk->get_hitsCollectionName();
- if ( checkHCName( hc ) )
- {
- G4Exception("SensitiveDetectorFactory", "", FatalException, "Name of the hits collection is invalid.");
+ if (checkHCName(hc)) {
+ G4Exception("SensitiveDetectorFactory", "", FatalException,
+ "Name of the hits collection is invalid.");
}
/* tracker that aggregates hits */
- if ( combineHits )
- {
- sd = new G4TrackerCombineSD( nm, hc );
- }
- /* regular tracker */
- else
- {
- sd = new G4TrackerSD( nm, hc );
+ if (combineHits) {
+ sd = new G4TrackerCombineSD(nm, hc);
+ } else {
+ /* regular tracker */
+ sd = new G4TrackerSD(nm, hc);
}
return sd;
}
-G4ScorerSD* SensitiveDetectorFactory::createScorerSD( const SAXObject* object )
+G4ScorerSD* SensitiveDetectorFactory::createScorerSD(const SAXObject* object)
{
- const scorer * scr = dynamic_cast< const scorer* > ( object );
+ const scorer * scr = dynamic_cast<const scorer*>(object);
G4ScorerSD* sd = 0;
std::string nm = scr->get_name();
std::string hc = scr->get_hitsCollectionName();
- if ( checkHCName( hc ) )
- {
- G4Exception("SensitiveDetectorFactory", "", FatalException, "Name of the hits collections is invalid.");
+ if (checkHCName(hc)) {
+ G4Exception("SensitiveDetectorFactory", "", FatalException,
+ "Name of the hits collections is invalid.");
}
- sd = new G4ScorerSD( nm, hc );
+ sd = new G4ScorerSD(nm, hc);
return sd;
}
-IdSpec* SensitiveDetectorFactory::findIdSpec( const SensitiveDetectorType* sdt )
+IdSpec* SensitiveDetectorFactory::findIdSpec(const SensitiveDetectorType* sdt)
{
IdSpec* idspec = 0;
- ContentSequence* seq = const_cast< ContentSequence* > ( sdt->get_content() );
+ ContentSequence* seq = const_cast<ContentSequence*>(sdt->get_content());
size_t count = seq->size();
- for ( size_t i = 0; i < count; i++ )
- {
+ for (size_t i = 0; i < count; i++) {
- std::string child_tag = seq->content( i ).tag;
+ std::string child_tag = seq->content(i).tag;
// find idspec
- if ( child_tag == "idspecref" )
- {
+ if (child_tag == "idspecref") {
IdSpecType::idspecref* id_ref =
- dynamic_cast< IdSpecType::idspecref* > ( seq->content( i ).object );
+ dynamic_cast<IdSpecType::idspecref*>(seq->content(i).object);
- idspec = IdManager::instance()->getIdSpec( id_ref->get_ref() );
+ idspec = IdManager::instance()->getIdSpec(id_ref->get_ref());
- if ( idspec == 0 )
- {
- G4cerr << "IdSpec <" << id_ref->get_ref() << "> referenced by detector <" << sdt->get_name() << "> does not exist." << G4endl;
+ if (idspec == 0) {
+ G4cerr << "IdSpec <" << id_ref->get_ref() << "> referenced by detector <" << sdt->get_name()
+ << "> does not exist." << G4endl;
G4Exception("", "", FatalException, "IdSpec does not exist.");
}
@@ -261,63 +236,58 @@
void SensitiveDetectorFactory::setBaseSensitiveDetectorAttributes(
G4SensitiveDetector* sd,
- const SensitiveDetectorType* sdt )
+ const SensitiveDetectorType* sdt)
{
- sd->setEcut( SensitiveDetectorFactory::computeEcut( sdt ) );
- sd->setVerbose( SensitiveDetectorFactory::convertVerbose( sdt ) );
- sd->setEndcapFlag( StringUtil::toBool( sdt->get_endcap_flag() ) );
+ sd->setEcut(SensitiveDetectorFactory::computeEcut(sdt));
+ sd->setVerbose(SensitiveDetectorFactory::convertVerbose(sdt));
+ sd->setEndcapFlag(StringUtil::toBool(sdt->get_endcap_flag()));
}
-double SensitiveDetectorFactory::computeEcut( const SensitiveDetectorType* sdt )
+double SensitiveDetectorFactory::computeEcut(const SensitiveDetectorType* sdt)
{
GDMLExpressionEvaluator* calc = GDMLProcessor::GetInstance()->GetEvaluator();
std::string sval = sdt->get_ecut();
sval += "*" + sdt->get_eunit();
- double ecut = calc->Eval( sval );
+ double ecut = calc->Eval(sval);
return ecut;
}
-int SensitiveDetectorFactory::convertVerbose( const SensitiveDetectorType* sdt )
+int SensitiveDetectorFactory::convertVerbose(const SensitiveDetectorType* sdt)
{
GDMLExpressionEvaluator* calc = GDMLProcessor::GetInstance()->GetEvaluator();
std::string sval = sdt->get_verbose();
- int verbose = ( int ) calc->Eval( sval );
+ int verbose = (int) calc->Eval(sval);
return verbose;
}
// NOTE: New segmentations must appear here!
-bool SensitiveDetectorFactory::isSegmentationTag( const std::string& s )
+bool SensitiveDetectorFactory::isSegmentationTag(const std::string& s)
{
// @todo Fix this to know all segmentation types automatically somehow. (schema?)
- return ( s == "projective_cylinder" || s == "grid_xyz" || s == "global_grid_xy" || s
- == "nonprojective_cylinder" || s == "projective_zplane" );
+ return (s == "projective_cylinder" || s == "grid_xyz" || s == "global_grid_xy" || s
+ == "nonprojective_cylinder" || s == "projective_zplane" || s == "cell_readout_2d");
}
-bool SensitiveDetectorFactory::checkHCName( const std::string& s )
+bool SensitiveDetectorFactory::checkHCName(const std::string& s)
{
bool bad = false;
// is size <= 1 ?
- if ( s.size() <= 1 )
- {
+ if (s.size() <= 1) {
bad = true;
//std::cerr << "HCName <" << s << "> is not enough characters." << std::endl;
}
- else
- {
+ else {
LCDDProcessor* proc = LCDDProcessor::instance();
- for ( LCDDProcessor::SensitiveDetectors::const_iterator iter =
+ for (LCDDProcessor::SensitiveDetectors::const_iterator iter =
proc->getSensitiveDetectorsBegin(); iter
- != proc->getSensitiveDetectorsBegin(); iter++ )
- {
- if ( iter->second->getHCName() == s )
- {
+ != proc->getSensitiveDetectorsBegin(); iter++) {
+ if (iter->second->getHCName() == s) {
bad = true;
//std::cerr << "HCName <" << s << "> already assigned to SD <" << iter->second->GetName() << ">." << std::endl;
break;
}
}
}
-
return bad;
}
lcdd/src
diff -u -r1.15 -r1.16
--- calorimeterSubscriber.cc 30 Mar 2006 19:43:58 -0000 1.15
+++ calorimeterSubscriber.cc 30 May 2013 00:04:12 -0000 1.16
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/calorimeterSubscriber.cc,v 1.15 2006/03/30 19:43:58 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/calorimeterSubscriber.cc,v 1.16 2013/05/30 00:04:12 jeremy Exp $
// GDML
#include "Saxana/SAXSubscriber.h"
@@ -22,32 +22,33 @@
#include <sstream>
/**
- @class calorimeterSubscriber
- @brief SAX subscriber for calorimeter element.
- @note Delegates to SensitiveDetectorFactory to create G4CalorimeterSD object.
-*/
-class calorimeterSubscriber : virtual public SAXSubscriber
+ @class calorimeterSubscriber
+ @brief SAX subscriber for calorimeter element.
+ @note Delegates to SensitiveDetectorFactory to create G4CalorimeterSD object.
+ */
+class calorimeterSubscriber: virtual public SAXSubscriber
{
public:
- virtual const SAXComponentObject* Build() const
- {
- return this;
- }
+ virtual const SAXComponentObject* Build() const
+ {
+ return this;
+ }
public:
- calorimeterSubscriber()
- {
- Subscribe("calorimeter");
- }
-
- virtual ~calorimeterSubscriber()
- {}
-
- virtual void Activate(const SAXObject* object)
- {
- // use factory to create this SD
- SensitiveDetectorFactory::createSensitiveDetector( object );
- }
+ calorimeterSubscriber()
+ {
+ Subscribe("calorimeter");
+ }
+
+ virtual ~calorimeterSubscriber()
+ {
+ }
+
+ virtual void Activate(const SAXObject* object)
+ {
+ // use factory to create this SD
+ SensitiveDetectorFactory::createSensitiveDetector(object);
+ }
};
DECLARE_SUBSCRIBER_FACTORY(calorimeterSubscriber)
CVSspam 0.2.12