6 modified files
lcdd/include
diff -u -r1.8 -r1.9
--- G4CalorimeterSD.hh 5 Sep 2006 23:25:19 -0000 1.8
+++ G4CalorimeterSD.hh 18 Dec 2006 21:21:20 -0000 1.9
@@ -1,13 +1,14 @@
-#ifndef G4CALORIMETERSD_HH
-#define G4CALORIMETERSD_HH
+#ifndef LCDD_G4CALORIMETERSD_HH
+#define LCDD_G4CALORIMETERSD_HH
+// geant4
#include "G4SensitiveDetector.hh"
#include "G4CalorimeterHit.hh"
-#include <iostream>
-
+// lcdd
#include "HitComparator.hh"
+// lcdd
class G4Segmentation;
/**
@@ -40,11 +41,13 @@
G4CalorimeterHit* findHit(G4CalorimeterHit* aHit) const;
- void printHits(std::ostream&);
+ std::ostream& printHits(std::ostream& os) const;
+
+ void clearHits();
+
+ virtual std::ostream& printBasicInfo(std::ostream& os) const;
- void clearHits() {
- m_hits.clear();
- }
+ virtual double getEdep() const;
protected:
virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*);
lcdd/include
diff -u -r1.12 -r1.13
--- G4SensitiveDetector.hh 5 Sep 2006 23:25:20 -0000 1.12
+++ G4SensitiveDetector.hh 18 Dec 2006 21:21:20 -0000 1.13
@@ -1,24 +1,31 @@
#ifndef G4SENSITIVEDETECTOR_HH
#define G4SENSITIVEDETECTOR_HH 1
-// G4
+// geant4
#include "G4VSensitiveDetector.hh"
-#include "globals.hh"
+#include "G4UnitsTable.hh"
-// LCDD
-#include "G4StepReadout.hh"
+// lcdd
+#include "StepReadout.hh"
#include "IdSpec.hh"
#include "Id64bit.hh"
+class G4UImessenger;
+class G4VHitsCollection;
+
/**
* @class G4SensitiveDetector
* @brief Basic implementation of G4VSensitiveDetector.
* @note Primary settings include verbosity, energy cut,
* IdSpec, and HC ID.
-*/
-class G4SensitiveDetector : public G4VSensitiveDetector, protected G4StepReadout
+ */
+class G4SensitiveDetector : public G4VSensitiveDetector, protected StepReadout
{
public:
+
+ /**
+ * EType indicates the basic type of detector, e.g. tracker or calorimeter.
+ */
enum EType { eNone=0, eTracker=1, eCalorimeter=2 };
static const std::string& trackerStr;
@@ -33,76 +40,198 @@
virtual ~G4SensitiveDetector();
public:
+
+ /**
+ * Geant4 initialization function called at beginning of event.
+ */
virtual void Initialize(G4HCofThisEvent *);
+
+ /**
+ * Geant4 EndOfEvent hook.
+ */
virtual void EndOfEvent(G4HCofThisEvent *);
protected:
+
+ /**
+ * Geant4 function to make hits from the step.
+ */
virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*);
public:
+
+ /**
+ * Return the type of this detector encoded as an int.
+ */
+ inline G4SensitiveDetector::EType getType() const
+ {
+ return m_type;
+ }
- EType getType() const;
- const std::string& getTypeString() const;
-
- G4int getHCID() const;
-
- virtual bool isValidVolume(G4LogicalVolume* lv);
+ /**
+ * Return the type of this detector encoded as a string.
+ */
+ inline const std::string& getTypeString() const;
+
+ /**
+ * Return the hits collection ID associated with this detector.
+ */
+ inline G4int getHCID() const
+ {
+ return m_HCID;
+ }
- const std::string& getHCName()
+ /**
+ * Check whether the G4LogicalVolume can be readout by this detector.
+ */
+ inline virtual bool isValidVolume(G4LogicalVolume* lv);
+
+ /**
+ * Return the hits collection name associated with this detector.
+ */
+ inline const std::string& getHCName() const
{
return collectionName[0];
}
- void setVerbose(unsigned int v)
+ /**
+ * Set the verbosity level of this detector.
+ */
+ inline void setVerbose(unsigned int v)
{
+ std::cout << "setVerbose " << v << std::endl;
m_verbose = v;
}
- unsigned int getVerbose()
+ /**
+ * Get the verbosity level of this detector.
+ */
+ inline const unsigned int getVerbose() const
{
return m_verbose;
}
- G4double getEcut()
+ /**
+ * Return the hit energy cut of this detector.
+ */
+ inline G4double getEcut()
{
return m_ecut;
}
- void setEcut(G4double ec)
+ /**
+ * Set the hit energy cut of this detector.
+ */
+ inline void setEcut(G4double ec)
{
+ G4cout << this->GetName() << " - hit energy cut set to " << ec << G4endl;
m_ecut = ec;
}
- void setIdSpec(IdSpec* idspec)
+ /**
+ * Set the identifier specification for this detector.
+ */
+ inline void setIdSpec(IdSpec* idspec)
{
m_idspec = idspec;
}
- IdSpec* getIdSpec() const
+ /**
+ * Return the identifier specification for this detector.
+ */
+ inline IdSpec* getIdSpec() const
{
return m_idspec;
}
- bool hasIdSpec() const
+ /**
+ * Returns whether or not this detector has an associated identifier specification.
+ */
+ inline bool hasIdSpec() const
{
return ( m_idspec != 0 );
}
+ /**
+ * Create a 64-bit identifier based on the current step information.
+ */
Id64bit makeId() const;
- void setEndcapFlag( bool ec = true )
+ /**
+ * Set the endcap flag.
+ */
+ inline void setEndcapFlag( bool ec = true )
{
m_endcap = ec;
}
- bool getEndcapFlag()
+ /**
+ * Return the endcap flag.
+ */
+ inline bool getEndcapFlag()
{
return m_endcap;
}
+ /**
+ * Print basic information about this detector to the output stream.
+ */
+ virtual std::ostream& printBasicInfo(std::ostream& os) const;
+
+ /**
+ * Print the number of hits to the output stream.
+ */
+ virtual std::ostream& printNumberOfHits(std::ostream& os) const;
+
+ /**
+ * Print the number of hits to the output stream.
+ */
+ virtual std::ostream& printEdep(std::ostream& os) const;
+
+ /**
+ * Print the names of volumes associated to this detector.
+ */
+ virtual std::ostream& printVolumes(std::ostream& os) const;
+
+ /**
+ * Print the list of hits. Subclasses must implement this.
+ */
+ virtual std::ostream& printHits(std::ostream& os) const { return os; }
+
+ /**
+ * Retrieve the hits collection associated with this detector,
+ * using the hits collection ID (HCID).
+ */
+ G4VHitsCollection* getHitsCollection() const;
+
+ /**
+ * Return the number of hits. The m_nhits variable should
+ * be set by a subclass for this value to have any meaning.
+ */
+ inline int getNumberOfHits() const { return m_nhits;}
+
+ /**
+ * Return the total energy deposition from the hits of this detector.
+ * Requires access to concrete hit types, so this function must be
+ * implemented by subclasses.
+ */
+ virtual double getEdep() const { return 0.0;}
+
+ /**
+ * Return a list of G4LogicalVolume objects that have been assigned
+ * this sensitive detector.
+ */
+ std::vector<G4LogicalVolume*> getLogicalVolumes() const;
+
protected:
- void setHCID(G4int hcid);
+ /**
+ * Set the hits collection ID corresponding to this detector.
+ */
+ inline void setHCID(G4int hcid)
+ {
+ m_HCID = hcid;
+ }
protected:
@@ -125,6 +254,13 @@
// type = calorimeter or tracker
EType m_type;
+
+ // The Geant4 command messenger associated with this detector.
+ G4UImessenger* m_messenger;
+
+protected:
+ // Hit counter.
+ int m_nhits;
};
#endif
lcdd/include
diff -u -r1.13 -r1.14
--- G4TrackerSD.hh 5 Sep 2006 23:25:20 -0000 1.13
+++ G4TrackerSD.hh 18 Dec 2006 21:21:20 -0000 1.14
@@ -25,13 +25,18 @@
public:
virtual void Initialize(G4HCofThisEvent *);
virtual void EndOfEvent(G4HCofThisEvent *);
- void printHits(std::ostream&);
+ std::ostream& printHits(std::ostream& os) const;
+ double getEdep() const;
+
+ void clearHits();
+
protected:
virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*);
protected:
G4TrackerHitsCollection* m_HC;
+ G4TrackerHitList m_hits;
};
#endif
lcdd/src
diff -u -r1.27 -r1.28
--- G4CalorimeterSD.cc 8 Dec 2006 00:43:49 -0000 1.27
+++ G4CalorimeterSD.cc 18 Dec 2006 21:21:20 -0000 1.28
@@ -1,7 +1,7 @@
-// $Header: /cvs/lcd/lcdd/src/G4CalorimeterSD.cc,v 1.27 2006/12/08 00:43:49 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4CalorimeterSD.cc,v 1.28 2006/12/18 21:21:20 jeremy Exp $
#include "G4CalorimeterSD.hh"
-// LCDD
+// lcdd
#include "G4Segmentation.hh"
#include "ReadoutUtil.hh"
#include "McpHitContrib.hh"
@@ -9,14 +9,15 @@
#include "IdManager.hh"
#include "PositionComparator.hh"
-// G4
+// geant4
#include "G4Track.hh"
#include "G4StepPoint.hh"
#include "G4Timer.hh"
-// std
-#include <vector>
+// stl
#include <iostream>
+#include <string>
+#include <vector>
G4CalorimeterSD::G4CalorimeterSD(G4String sdName,
G4String hcName,
@@ -52,6 +53,8 @@
void G4CalorimeterSD::Initialize(G4HCofThisEvent *HCE)
{
+ clearHits();
+
// new cal hits collection
m_HC = new G4CalorimeterHitsCollection( GetName(), collectionName[0] );
@@ -71,6 +74,12 @@
G4bool G4CalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
{
+#ifdef G4VERBOSE
+ if ( getVerbose() > 0 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - " << this->GetName() << std::endl;
+ }
+#endif
+
// set cached step
G4SensitiveDetector::ProcessHits(aStep, 0);
@@ -95,7 +104,6 @@
Id64bit id64 = makeId();
// DEBUG: Compute step midpoint and compare to the cell pos
-#ifdef G4DEBUG
#ifdef G4VERBOSE
if ( getVerbose() > 1 ) {
G4ThreeVector globalMidPos = midPosition();
@@ -103,7 +111,6 @@
std::cout << "globalCellPos - globalMidPos = " << globalCellPos - globalMidPos << std::endl;
}
#endif
-#endif
// find hit by simple lkp of new hit with above info
G4CalorimeterHit* thisHit = new G4CalorimeterHit(theEdep, globalCellPos);
@@ -153,9 +160,9 @@
return fndHit;
}
-void G4CalorimeterSD::printHits(std::ostream& os)
+std::ostream& G4CalorimeterSD::printHits(std::ostream& os) const
{
- for (G4CalorimeterHitList::iterator iter = m_hits.begin();
+ for (G4CalorimeterHitList::const_iterator iter = m_hits.begin();
iter != m_hits.end();
iter++ ) {
os << **iter;
@@ -165,15 +172,55 @@
void G4CalorimeterSD::EndOfEvent(G4HCofThisEvent *)
{
+ // Store the number of hits for interactive printing.
+ m_nhits = m_HC->GetSize();
+
#ifdef G4VERBOSE
if ( getVerbose() > 0 ) {
std::cout << GetName() << " has " << m_HC->GetSize() << " hits." << std::endl;
}
-
if ( getVerbose() > 1 ) {
printHits ( std::cout );
}
#endif
+}
+
+std::ostream& G4CalorimeterSD::printBasicInfo(std::ostream& os) const
+{
+ G4SensitiveDetector::printBasicInfo( os );
+
+ os << "segmentation type: " << m_segmentation->getTypeString() << std::endl;
+
+ os << "segmentation bins:";
+
+ for ( std::vector<std::string>::const_iterator it = m_segmentation->getBinNames().begin();
+ it != m_segmentation->getBinNames().end();
+ it++ ) {
+ os << " " << *it;
+ }
+
+ os << std::endl;
+
+ return os;
+}
- clearHits();
+double G4CalorimeterSD::getEdep() const
+{
+ double edep=0.0;
+ for ( G4CalorimeterHitList::const_iterator it = m_hits.begin();
+ it != m_hits.end();
+ it++ ) {
+ edep += (*it)->getEdep();
+ }
+ return edep;
+}
+
+void G4CalorimeterSD::clearHits() {
+// for ( G4CalorimeterHitList::iterator it = m_hits.begin();
+// it != m_hits.end();
+// it++ ) {
+// delete *it;
+// }
+ m_hits.clear();
+ m_nhits=0;
}
lcdd/src
diff -u -r1.10 -r1.11
--- G4SensitiveDetector.cc 31 Mar 2006 01:09:38 -0000 1.10
+++ G4SensitiveDetector.cc 18 Dec 2006 21:21:20 -0000 1.11
@@ -1,16 +1,23 @@
-// $Header: /cvs/lcd/lcdd/src/G4SensitiveDetector.cc,v 1.10 2006/03/31 01:09:38 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4SensitiveDetector.cc,v 1.11 2006/12/18 21:21:20 jeremy Exp $
+
#include "G4SensitiveDetector.hh"
-// LCDD
-#include "G4StepReadout.hh"
+// lcdd
#include "IdManager.hh"
#include "IdFactory.hh"
+#include "SensitiveDetectorMessenger.hh"
#include "TrackInformation.hh"
-// G4
+// geant4
+#include "G4EventManager.hh"
+#include "G4Event.hh"
#include "G4SDManager.hh"
+#include "G4UImessenger.hh"
+#include "G4VHitsCollection.hh"
+#include "G4LogicalVolumeStore.hh"
+#include "G4UnitsTable.hh"
-// std
+// stl
#include <iostream>
const std::string& G4SensitiveDetector::trackerStr = "tracker";
@@ -23,13 +30,17 @@
: G4VSensitiveDetector(sdName),
m_HCID(-1),
m_idspec(0),
- m_type(sdType)
+ m_type(sdType),
+ m_nhits(-1)
{
// 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);
}
G4SensitiveDetector::~G4SensitiveDetector()
@@ -65,11 +76,6 @@
return false;
}
-G4SensitiveDetector::EType G4SensitiveDetector::getType() const
-{
- return m_type;
-}
-
const std::string& G4SensitiveDetector::getTypeString() const
{
if ( m_type == eTracker ) {
@@ -81,29 +87,91 @@
return noneStr;
}
-
-G4int G4SensitiveDetector::getHCID() const
-{
- return m_HCID;
-}
-
-void G4SensitiveDetector::setHCID(G4int hcid)
+std::ostream& G4SensitiveDetector::printBasicInfo(std::ostream& os) const
{
- m_HCID = hcid;
+ os << "name: " << this->GetName() << std::endl;
+ os << "type: " << m_type << std::endl;
+ os << "hits collection: " << this->getHCName() << std::endl;
+ os << "hits collection ID: " << m_HCID << 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 << "no id spec" << 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;
+}
+
+std::ostream& G4SensitiveDetector::printNumberOfHits(std::ostream& os) const
+{
+ os << "number of hits: " << this->getNumberOfHits() << std::endl;
+ return os;
+}
+
+std::ostream& G4SensitiveDetector::printEdep(std::ostream& os) const
+{
+ os << "total edep: " << G4BestUnit( this->getEdep(), "Energy" ) << std::endl;
+ return os;
+}
+
+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) const
+{
+ 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.28 -r1.29
--- G4TrackerSD.cc 31 Mar 2006 01:09:38 -0000 1.28
+++ G4TrackerSD.cc 18 Dec 2006 21:21:20 -0000 1.29
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/G4TrackerSD.cc,v 1.28 2006/03/31 01:09:38 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4TrackerSD.cc,v 1.29 2006/12/18 21:21:20 jeremy Exp $
// LCDD
#include "IdManager.hh"
@@ -18,13 +18,17 @@
hcName,
G4SensitiveDetector::eTracker),
m_HC(0)
-{}
+{
+ m_hits.clear();
+}
G4TrackerSD::~G4TrackerSD()
{}
void G4TrackerSD::Initialize(G4HCofThisEvent *HCE)
{
+ clearHits();
+
// create tracker hits coll
m_HC = new G4TrackerHitsCollection( GetName(), collectionName[0] );
@@ -81,19 +85,26 @@
// add to HC
m_HC->insert(trkHit);
+ m_hits.push_back( trkHit );
+
return true;
}
-void G4TrackerSD::printHits(std::ostream& os)
+std::ostream& G4TrackerSD::printHits(std::ostream& os) const
{
- for (size_t i = 0; i < m_HC->GetSize(); i++) {
- os << const_cast<const G4TrackerHit&>(*(dynamic_cast<G4TrackerHit*>(m_HC->GetHit(i))));
+ for (G4TrackerHitList::iterator iter = m_hits.begin();
+ iter != m_hits.end();
+ iter++ ) {
+ os << **iter;
}
os << std::endl;
}
void G4TrackerSD::EndOfEvent(G4HCofThisEvent *)
{
+ // Store the number of hits for possible interactive printing.
+ m_nhits = m_hits.size();
+
#ifdef G4VERBOSE
if ( getVerbose() > 0 ) {
std::cout << GetName() << " has " << m_HC->GetSize() << " hits." << std::endl;
@@ -104,3 +115,25 @@
}
#endif
}
+
+double G4TrackerSD::getEdep() const
+{
+ double edep=0.0;
+ for ( G4TrackerHitList::const_iterator it = m_hits.begin();
+ it != m_hits.end();
+ it++ ) {
+ edep += (*it)->getEdep();
+ }
+ return edep;
+}
+
+void G4TrackerSD::clearHits()
+{
+ //for ( G4TrackerHitList::iterator it = m_hits.begin();
+ // it != m_hits.end();
+ // it++ ) {
+ // delete *it;
+ // }
+ m_hits.clear();
+ m_nhits=0;
+}
CVSspam 0.2.8