lcdd/src
diff -u -r1.20 -r1.21
--- SensitiveDetectorFactory.cc 30 Oct 2009 23:16:59 -0000 1.20
+++ SensitiveDetectorFactory.cc 7 Dec 2010 00:52:00 -0000 1.21
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/SensitiveDetectorFactory.cc,v 1.20 2009/10/30 23:16:59 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/SensitiveDetectorFactory.cc,v 1.21 2010/12/07 00:52:00 jeremy Exp $
#include "SensitiveDetectorFactory.hh"
// lcdd
@@ -6,56 +6,65 @@
#include "G4ScorerSD.hh"
#include "G4TrackerSD.hh"
#include "G4OpticalCalorimeterSD.hh"
-#include "G4CalorimeterSD.hh"
+#include "G4UnsegmentedCalorimeterSD.hh"
+//#include "G4CalorimeterSD.hh"
#include "PositionComparator.hh"
#include "IdComparator.hh"
#include "StringUtil.hh"
-G4SensitiveDetector* SensitiveDetectorFactory::createSensitiveDetector(const SAXObject* object)
+G4SensitiveDetector* SensitiveDetectorFactory::createSensitiveDetector(
+ const SAXObject* object )
{
G4SensitiveDetector* sd = 0;
- const SensitiveDetectorType* sdt = dynamic_cast<const SensitiveDetectorType*> ( object );
+ const SensitiveDetectorType* sdt =
+ dynamic_cast< const SensitiveDetectorType* > ( object );
- if ( sdt ) {
+ if ( sdt )
+ {
std::string sd_type = sdt->get_type();
- /* create calorimeter */
- if ( sd_type == "calorimeter" || sd_type == "optical_calorimeter" ) {
+ /* Create calorimeter subdetector. */
+ if ( sd_type == "calorimeter" || sd_type == "optical_calorimeter" || sd_type
+ == "unsegmented_calorimeter" )
+ {
sd = createCalorimeterSD( object );
}
- /* create tracker */
- else if ( sd_type == "tracker" ) {
+ /* Create tracker subdetector. */
+ else if ( sd_type == "tracker" )
+ {
sd = createTrackerSD( object );
}
- /* create scorer */
- else if ( sd_type == "scorer" ) {
+ /* Create scorer subdetector. */
+ else if ( sd_type == "scorer" )
+ {
sd = createScorerSD( object );
}
- /* invalid type */
- else {
+ /* Type not recognized. */
+ else
+ {
G4cerr << "Invalid sd_type <" << sd_type << ">." << G4endl;
G4Exception( "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);
+ LCDDProcessor::instance()->addSensitiveDetector( sdName, sd );
}
- else
+ else
{
G4Exception( "Failed cast to SensitiveDetectorType." );
}
@@ -63,28 +72,29 @@
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 );
+ const SensitiveDetectorType* sdt =
+ 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++)
+ for ( size_t i = 0; i < count; i++ )
{
- std::string child_tag = seq->content(i).tag;
- const ContentGroup::ContentItem& segitem = seq->content(i);
+ std::string child_tag = seq->content( i ).tag;
+ const ContentGroup::ContentItem& segitem = seq->content( i );
// Create segmentation using factory.
- if ( isSegmentationTag( child_tag ) )
+ if ( isSegmentationTag( child_tag ) )
{
seg = G4SegmentationFactory::createSegmentation( segitem.object, segitem.tag );
fnd_seg = true;
@@ -92,88 +102,99 @@
}
}
- if ( !fnd_seg )
- {
- G4Exception("FATAL ERROR: Segmentation tag is required to create a calorimeter.");
- }
+ //if ( !fnd_seg )
+ //{
+ // G4Exception( "FATAL ERROR: Segmentation tag is required to create a calorimeter." );
+ //}
- const calorimeter* cal = dynamic_cast<const calorimeter*>( object );
- const std::string& hitCompareStr = cal->get_compare();
+ // create SD with seg and comparator
+ if ( seg )
+ {
+ const calorimeter* cal = dynamic_cast< const calorimeter* > ( object );
- // Comparison algorithm to be used for combining hits, to be determined from SD.
- HitComparator* hitCompare = 0;
+ const std::string& hitCompareStr = cal->get_compare();
- // Find the IdSpec.
- IdSpec* idspec = findIdSpec( sdt );
+ // Comparison algorithm to be used for combining hits, to be determined from SD.
+ HitComparator* hitCompare = 0;
- if ( hitCompareStr != "id" && hitCompareStr != "position" )
- {
- G4Exception("Invalid selection for hit comparison <" + hitCompareStr + ">, for calorimeter <" + sdt->get_name() + ">.");
- }
+ // Find the IdSpec.
+ IdSpec* idspec = findIdSpec( sdt );
- // Compare on IDs.
- if ( hitCompareStr == "id" )
- {
- if ( idspec )
+ if ( hitCompareStr != "id" && hitCompareStr != "position" )
{
- hitCompare = new IdComparator();
+ G4Exception( "Invalid selection for hit comparison <" + hitCompareStr
+ + ">, for calorimeter <" + sdt->get_name() + ">." );
}
- else
+
+ // Compare on IDs.
+ if ( hitCompareStr == "id" )
{
- std::cerr << "WARNING: IdSpec for <" << sdt->get_name() << "> does not exist! Position comparison will be used for hit aggregation instead of id." << std::endl;
+ if ( idspec )
+ {
+ hitCompare = new IdComparator();
+ }
+ 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;
+ }
}
- }
- // Compare on position.
- if ( !hitCompare )
- {
- hitCompare = new PositionComparator();
- }
-
- // create SD with seg and comparator
- if ( seg )
- {
+ // Compare on position.
+ if ( !hitCompare )
+ {
+ hitCompare = new PositionComparator();
+ }
- if ( sd_type == "calorimeter" )
+ if ( sd_type == "calorimeter" )
{
- sd = new G4CalorimeterSD(sdt->get_name(),
- sdt->get_hitsCollectionName(),
- seg,
- hitCompare);
+ sd = new G4CalorimeterSD(
+ sdt->get_name(),
+ sdt->get_hitsCollectionName(),
+ seg,
+ 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];
- 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);
+ sd = new G4OpticalCalorimeterSD( sdt->get_name(), hcnames, seg, hitCompare );
}
- else
+ else
{
- G4Exception("SensitiveDetectorFactory - Unknown sensitive detector type: " + sd_type);
+ G4Exception( "SensitiveDetectorFactory - Unknown sensitive detector type: "
+ + sd_type );
}
}
// shouldn't happen if fnd_seg fails...
- else
+ else
{
- G4Exception( "FATAL ERROR: G4SegmentationFactory returned a NULL pointer!" );
+ if ( sd_type == "unsegmented_calorimeter" )
+ {
+ sd = new G4UnsegmentedCalorimeterSD(
+ sdt->get_name(),
+ sdt->get_hitsCollectionName() );
+ }
+ else
+ {
+ G4Exception( "Segmentation is required for segmented calorimeter types." );
+ }
}
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() );
@@ -182,67 +203,68 @@
std::string nm = trk->get_name();
std::string hc = trk->get_hitsCollectionName();
- if (checkHCName(hc))
+ if ( checkHCName( hc ) )
{
- G4Exception("SensitiveDetectorFactory - There was a problem with the name of the hits collection.");
+ G4Exception(
+ "SensitiveDetectorFactory - There was a problem with the name of the hits collection." );
}
/* tracker that aggregates hits */
- if ( combineHits )
+ if ( combineHits )
{
- sd = new G4TrackerCombineSD(nm,
- hc);
+ sd = new G4TrackerCombineSD( nm, hc );
}
/* regular tracker */
- else
+ else
{
- sd = new G4TrackerSD(nm,
- hc);
+ 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) )
+ if ( checkHCName( hc ) )
{
- G4Exception("SensitiveDetectorFactory - There was a problem with the name of the hits collection.");
+ G4Exception(
+ "SensitiveDetectorFactory - There was a problem with the name of the hits collection." );
}
- 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() );
- if (idspec == 0)
+ if ( idspec == 0 )
{
- G4Exception("The IdSpec <" + id_ref->get_ref() + "> referenced by detector <" + sdt->get_name() + "> does not exist!");
+ G4Exception( "The IdSpec <" + id_ref->get_ref()
+ + "> referenced by detector <" + sdt->get_name()
+ + "> does not exist!" );
}
break;
@@ -251,14 +273,16 @@
return idspec;
}
-void SensitiveDetectorFactory::setBaseSensitiveDetectorAttributes(G4SensitiveDetector* sd, const SensitiveDetectorType* sdt)
+void SensitiveDetectorFactory::setBaseSensitiveDetectorAttributes(
+ G4SensitiveDetector* sd,
+ const SensitiveDetectorType* sdt )
{
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();
@@ -267,43 +291,40 @@
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" );
}
-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 = proc->getSensitiveDetectorsBegin();
- iter != proc->getSensitiveDetectorsBegin();
- iter++ )
+ for ( LCDDProcessor::SensitiveDetectors::const_iterator iter =
+ proc->getSensitiveDetectorsBegin(); iter
+ != proc->getSensitiveDetectorsBegin(); iter++ )
{
- if (iter->second->getHCName() == s )
+ if ( iter->second->getHCName() == s )
{
bad = true;
//std::cerr << "HCName <" << s << "> already assigned to SD <" << iter->second->GetName() << ">." << std::endl;