lcdd/src
diff -u -r1.35 -r1.36
--- G4CalorimeterSD.cc 10 Oct 2007 22:38:10 -0000 1.35
+++ G4CalorimeterSD.cc 10 Dec 2007 17:24:22 -0000 1.36
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/G4CalorimeterSD.cc,v 1.35 2007/10/10 22:38:10 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4CalorimeterSD.cc,v 1.36 2007/12/10 17:24:22 wenzel Exp $
#include "G4CalorimeterSD.hh"
// lcdd
@@ -21,228 +21,297 @@
#include <vector>
G4CalorimeterSD::G4CalorimeterSD(G4String sdName,
- G4String hcName,
- G4Segmentation* sdSeg,
- HitComparator* compare)
- : G4SensitiveDetector(sdName,
- hcName,
- G4SensitiveDetector::eCalorimeter),
- m_segmentation(sdSeg),
- m_HC(0)
-{
- if ( compare == 0 ) {
- m_hitCompare = new PositionComparator();
- }
- else {
- m_hitCompare = compare;
- }
+ G4String hcName,
+ G4Segmentation* sdSeg,
+ HitComparator* compare)
+: G4SensitiveDetector(sdName,
+ hcName,
+ G4SensitiveDetector::eCalorimeter),
+ m_segmentation(sdSeg) {
+ HC_vector.push_back(m_collection);
+ m_hits.clear();
+ hits_vector.clear();
+ hits_vector.push_back(m_hits);
+ if ( compare == 0 ) {
+ m_hitCompare = new PositionComparator();
+ }
+ else {
+ m_hitCompare = compare;
+ }
}
-G4CalorimeterSD::~G4CalorimeterSD()
-{}
-bool G4CalorimeterSD::isValidVolume(G4LogicalVolume* lv)
-{
- bool valid = G4SensitiveDetector::isValidVolume(lv);
-
- if ( valid ) {
- valid = m_segmentation->isValidSolid( lv->GetSolid() );
- }
-
- return valid;
+G4CalorimeterSD::G4CalorimeterSD(G4String sdName,
+ G4String hcName[],
+ G4int NrofHC,
+ G4Segmentation* sdSeg,
+ HitComparator* compare )
+: G4SensitiveDetector(sdName,
+ hcName,
+ NrofHC,
+ G4SensitiveDetector::eCalorimeter),
+ m_segmentation(sdSeg) {
+ m_hits.clear();
+ hits_vector.clear();
+ hits_vector.push_back(m_hits);
+ for (int i = 0;i<m_NrofHC;i++) {
+ hits_vector.push_back(m_hits);
+ hits_vector[i].clear();
+ HC_vector.push_back(m_collection);
+// hits_vector[i].push_back(m_hits);
+ }
+
+ if ( compare == 0 ) {
+ m_hitCompare = new PositionComparator();
+ }
+ else {
+ m_hitCompare = compare;
+ }
}
-void G4CalorimeterSD::Initialize(G4HCofThisEvent *HCE)
-{
- clearHits();
- // new cal hits collection
- m_HC = new G4CalorimeterHitsCollection( GetName(), collectionName[0] );
+G4CalorimeterSD::~G4CalorimeterSD()
+{}
- // set HCID
- if ( getHCID() < 0) {
- setHCID( GetCollectionID(0) );
- }
+bool G4CalorimeterSD::isValidVolume(G4LogicalVolume* lv) {
+ bool valid = G4SensitiveDetector::isValidVolume(lv);
+
+ if ( valid ) {
+ valid = m_segmentation->isValidSolid( lv->GetSolid() );
+ }
+
+ return valid;
+}
- // add collection to HC of event
- HCE->AddHitsCollection( getHCID(), m_HC );
+void G4CalorimeterSD::Initialize(G4HCofThisEvent *HCE) {
+
+ clearallHits();
+ //clearHits();
+ // new cal hits collection
+ for(int i= 0; i < m_NrofHC; i++) {
+ HC_vector[i]=new G4CalorimeterHitsCollection( GetName(), collectionName[i] );
+ // set HCID
+ if ( getHCID(i) < 0) {
+ setHCID( GetCollectionID(i), i );
+ }
+
+ // add collection to HC of event
+ HCE->AddHitsCollection( getHCID(i), HC_vector[i] );
+ }
}
-G4Segmentation* G4CalorimeterSD::getSegmentation() const
-{
- return m_segmentation;
+G4Segmentation* G4CalorimeterSD::getSegmentation() const {
+ return m_segmentation;
}
-G4bool G4CalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
-{
+G4bool G4CalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
#ifdef G4VERBOSE
- if ( getVerbose() > 0 ) {
- std::cout << "G4CalorimeterSD::ProcessHits - " << this->GetName() << std::endl;
- }
+ if ( getVerbose() > 0 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - " << this->GetName() << std::endl;
+ }
#endif
-
- // set cached step
- G4SensitiveDetector::ProcessHits(aStep, 0);
-
- // get the edep
- G4double theEdep = edep();
-
- // This needs to be a <= comparison for cutting on 0.
- // Allow passthrough of geantinos w/ 0 edep.
- if ( theEdep <= getEcut() && !isGeantino() ) {
+
+// set cached step
+ G4SensitiveDetector::ProcessHits(aStep, 0);
+
+// get the edep
+ G4double theEdep = edep();
+
+// This needs to be a <= comparison for cutting on 0.
+// Allow passthrough of geantinos w/ 0 edep.
+ if ( theEdep <= getEcut() && !isGeantino() ) {
+#ifdef G4VERBOSE
+ if ( getVerbose() > 2 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - cut on edep " << theEdep << std::endl;
+ }
+#endif
+ return false;
+ }
+
+// get global cell pos from seg
+ G4ThreeVector globalCellPos = m_segmentation->getGlobalHitPos( aStep );
+
+// reset the seg bins
+ m_segmentation->resetBins();
+
+// set the seg bins
+ m_segmentation->setBins( aStep );
+
+// create id and pack into 64
+ Id64bit id64 = makeId();
+
+// DEBUG: Compute step midpoint and compare to the cell pos
#ifdef G4VERBOSE
if ( getVerbose() > 2 ) {
- std::cout << "G4CalorimeterSD::ProcessHits - cut on edep " << theEdep << std::endl;
+ G4ThreeVector globalMidPos = midPosition();
+ std::cout << "globalMidPos " << globalMidPos << std::endl;
+ std::cout << "globalCellPos - globalMidPos = " << globalCellPos - globalMidPos << std::endl;
}
#endif
- return false;
- }
-
- // get global cell pos from seg
- G4ThreeVector globalCellPos = m_segmentation->getGlobalHitPos( aStep );
-
- // reset the seg bins
- m_segmentation->resetBins();
-
- // set the seg bins
- m_segmentation->setBins( aStep );
-
- // create id and pack into 64
- Id64bit id64 = makeId();
-
- // DEBUG: Compute step midpoint and compare to the cell pos
+
+// find hit by simple lkp of new hit with above info
+ G4CalorimeterHit* thisHit = new G4CalorimeterHit(theEdep, globalCellPos);
+ thisHit->setId64bit( id64.getId0(), id64.getId1() );
+ G4CalorimeterHit* fndHit = 0;
+
+// hit is not found?
+ if ( !( fndHit = findHit( thisHit ) ) ) {
+
#ifdef G4VERBOSE
- if ( getVerbose() > 2 ) {
- G4ThreeVector globalMidPos = midPosition();
- std::cout << "globalMidPos " << globalMidPos << std::endl;
- std::cout << "globalCellPos - globalMidPos = " << globalCellPos - globalMidPos << std::endl;
- }
+ if ( getVerbose() > 1 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - new hit" << std::endl;
+ }
#endif
-
- // find hit by simple lkp of new hit with above info
- G4CalorimeterHit* thisHit = new G4CalorimeterHit(theEdep, globalCellPos);
- thisHit->setId64bit( id64.getId0(), id64.getId1() );
- G4CalorimeterHit* fndHit = 0;
-
- // hit is not found?
- if ( !( fndHit = findHit( thisHit ) ) ) {
-
-#ifdef G4VERBOSE
- if ( getVerbose() > 1 ) {
- std::cout << "G4CalorimeterSD::ProcessHits - new hit" << std::endl;
+// add it to lkp map
+ hits_vector[0].push_back(thisHit);
+// add to the HC
+ // add to the HC
+ HC_vector[0]->insert(thisHit);
}
+// found a hit
+ else {
+
+#ifdef G4VERBOSE
+ if ( getVerbose() > 2 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - existing hit" << std::endl;
+ }
#endif
+
+// don't need to insert thisHit, so delete it
+ delete thisHit;
+ thisHit = 0;
+
+// incr total edep of the hit
+ fndHit->incrEdep(theEdep);
+
+// for setting contrib
+ thisHit = fndHit;
+ }
+
+// add McpHitContrib to this hit, setting info from step info
+ thisHit->addMcpHitContrib( McpHitContrib( aStep ) );
+
+ return true;
+}
+
+G4CalorimeterHit* G4CalorimeterSD::findHit(G4CalorimeterHit* aHit) const {
+ G4CalorimeterHit* fndHit = 0;
+ for (G4CalorimeterHitList::const_iterator iter = hits_vector[0].begin();
+ iter != hits_vector[0].end();
+ iter++) {
+ if ( m_hitCompare->compare(**iter, *aHit) ) {
+ fndHit = *iter;
+ break;
+ }
+ }
+ return fndHit;
+}
- // add it to lkp map
- m_hits.push_back(thisHit);
+G4CalorimeterHit* G4CalorimeterSD::findHit(G4CalorimeterHit* aHit, G4int nHC) const {
+ G4CalorimeterHit* fndHit = 0;
+ for (G4CalorimeterHitList::const_iterator iter = hits_vector[nHC].begin();
+ iter != hits_vector[nHC].end();
+ iter++) {
+ if ( m_hitCompare->compare(**iter, *aHit) ) {
+ fndHit = *iter;
+ break;
+ }
+ }
+ return fndHit;
+}
- // add to the HC
- m_HC->insert(thisHit);
- }
- // found a hit
- else {
+std::ostream& G4CalorimeterSD::printHits(std::ostream& os) {
+ for(int i= 0; i < m_NrofHC; i++) {
+ os << "Hit collection Nr.: "<< i<< std::endl;
+ for (G4CalorimeterHitList::const_iterator iter = hits_vector[i].begin();
+ iter != hits_vector[i].end();
+ iter++ ) {
+ os << **iter;
+ }
+ }
+ os << std::endl;
+ return os;
+}
+void G4CalorimeterSD::EndOfEvent(G4HCofThisEvent *) {
+ // Store the number of hits for interactive printing.
+ nhits_vector[0] = HC_vector[0]->GetSize();
+
#ifdef G4VERBOSE
- if ( getVerbose() > 2 ) {
- std::cout << "G4CalorimeterSD::ProcessHits - existing hit" << std::endl;
+ if ( getVerbose() > 0 ) {
+ std::cout << GetName() << " has " << HC_vector[0]->GetSize() << " hits." << std::endl;
+ }
+ if ( getVerbose() > 1 ) {
+ printHits( std::cout );
}
#endif
+}
- // don't need to insert thisHit, so delete it
- delete thisHit;
- thisHit = 0;
-
- // incr total edep of the hit
- fndHit->incrEdep(theEdep);
-
- // for setting contrib
- thisHit = fndHit;
- }
-
- // add McpHitContrib to this hit, setting info from step info
- thisHit->addMcpHitContrib( McpHitContrib( aStep ) );
-
- return true;
+std::ostream& G4CalorimeterSD::printBasicInfo(std::ostream& os) {
+ 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;
}
-G4CalorimeterHit* G4CalorimeterSD::findHit(G4CalorimeterHit* aHit) const
-{
- G4CalorimeterHit* fndHit = 0;
- for (G4CalorimeterHitList::const_iterator iter = m_hits.begin();
- iter != m_hits.end();
- iter++) {
- if ( m_hitCompare->compare(**iter, *aHit) ) {
- fndHit = *iter;
- break;
+double G4CalorimeterSD::getEdep() const {
+ double edep=0.0;
+ for ( G4CalorimeterHitList::const_iterator it = hits_vector[0].begin();
+ it != hits_vector[0].end();
+ it++ ) {
+ edep += (*it)->getEdep();
}
- }
- return fndHit;
+ return edep;
}
-std::ostream& G4CalorimeterSD::printHits(std::ostream& os)
-{
- for (G4CalorimeterHitList::const_iterator iter = m_hits.begin();
- iter != m_hits.end();
- iter++ ) {
- os << **iter;
- }
- os << std::endl;
- return os;
+double G4CalorimeterSD::getEdep(G4int nHC) const {
+ double edep=0.0;
+ for ( G4CalorimeterHitList::const_iterator it = hits_vector[nHC].begin();
+ it != hits_vector[nHC].end();
+ it++ ) {
+ edep += (*it)->getEdep();
+ }
+ return edep;
}
-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
+void G4CalorimeterSD::clearallHits() {
+ for(int i= 0; i < m_NrofHC; i++) {
+ hits_vector[i].clear();
+ nhits_vector[i]=0;
+ }
}
-std::ostream& G4CalorimeterSD::printBasicInfo(std::ostream& os)
-{
- 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;
- }
+void G4CalorimeterSD::clearHits() {
+ hits_vector[0].clear();
+ nhits_vector[0]=0;
+}
- os << std::endl;
- return os;
+void G4CalorimeterSD::clearHits(G4int nHC) {
+
+ hits_vector[nHC].clear();
+ nhits_vector[nHC]=0;
+
}
-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()
-{
- m_hits.clear();
- m_nhits=0;
+G4CalorimeterSD::G4CalorimeterHitList G4CalorimeterSD::getCalorimeterHitList() {
+ return hits_vector[0];
}
-G4CalorimeterSD::G4CalorimeterHitList G4CalorimeterSD::getCalorimeterHitList()
-{
- return m_hits;
+G4CalorimeterSD::G4CalorimeterHitList G4CalorimeterSD::getCalorimeterHitList(G4int nHC) {
+ return hits_vector[nHC];
}
lcdd/src
diff -u -r1.1 -r1.2
--- G4OpticalCalorimeter.cc 5 Jul 2007 22:27:35 -0000 1.1
+++ G4OpticalCalorimeter.cc 10 Dec 2007 17:24:22 -0000 1.2
@@ -1,110 +1,224 @@
-// $Header: /cvs/lcd/lcdd/src/G4OpticalCalorimeter.cc,v 1.1 2007/07/05 22:27:35 jeremy Exp $
-
-#include "G4OpticalCalorimeterSD.hh"
-
-// geant4
-#include "G4OpticalPhoton.hh"
-#include "G4TransportationManager.hh"
-#include "G4VProcess.hh"
-
-// lcdd
-#include "G4Segmentation.hh"
-
-G4OpticalCalorimeterSD::G4OpticalCalorimeterSD(G4String sdName,
- G4String hcName,
- G4Segmentation* sdSeg,
- HitComparator* compare)
- : G4CalorimeterSD(sdName,
- hcName,
- sdSeg,
- compare)
-{}
-
-G4OpticalCalorimeterSD::~G4OpticalCalorimeterSD()
-{}
-
-G4bool G4OpticalCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
-{
- // set cached step
- G4SensitiveDetector::ProcessHits(aStep, 0);
-
- G4Track * aTrack = aStep->GetTrack();
-
- // particle is optical photon:
- if(aTrack->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) {
-
- if(aTrack->GetParentID()==0) {
- // particle is primary
- aTrack->SetTrackStatus(fStopAndKill);
- return false;
- }
-
- // particle is secondary
- G4String processname = aTrack->GetCreatorProcess()->G4VProcess::GetProcessName();
-
- if(processname != "Cerenkov") {
- aTrack->SetTrackStatus(fStopAndKill);
- return false;
- }
-
- G4ThreeVector myPoint = aStep->GetPreStepPoint()->GetPosition();
- G4Navigator* theNavigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
- G4VPhysicalVolume* myVolume = theNavigator->LocateGlobalPointAndSetup(myPoint);
-
- if ( getVerbose() > 2 ) {
- G4cout << "Physical volume = " << myVolume->GetName() << G4endl;
- G4cout << "Point of interaction = " << myPoint<< G4endl;
- G4cout << "sdname " << GetName() << " hcname " <<collectionName[0]<< G4endl;
- }
-
- G4double theEdep = aTrack->GetTotalEnergy()/eV;// total photon energy
-
- // get global cell pos from seg
- G4ThreeVector globalCellPos = m_segmentation->getGlobalHitPos( aStep );
-
- // reset the seg bins
- m_segmentation->resetBins();
-
- // set the seg bins
- m_segmentation->setBins( aStep );
-
- // create id and pack into 64
- Id64bit id64 = makeId();
-
- // find hit by simple lkp of new hit with above info
- G4CalorimeterHit* thisHit = new G4CalorimeterHit(theEdep, globalCellPos);
- thisHit->setId64bit( id64.getId0(), id64.getId1() );
- G4CalorimeterHit* fndHit = 0;
- // hit is not found?
- if ( !( fndHit = findHit( thisHit ) ) ) {
-
- // add it to lkp map
- m_hits.push_back(thisHit);
-
- // add to the HC
- m_HC->insert(thisHit);
- }
- // found a hit
- else {
-
- // don't need to insert thisHit, so delete it
- delete thisHit;
- thisHit = 0;
-
- // incr total edep of the hit
- fndHit->incrEdep(theEdep);
-
- // for setting contrib
- thisHit = fndHit;
- }
-
- // add McpHitContrib to this hit, setting info from step info
- thisHit->addMcpHitContrib( McpHitContrib( aStep ) );
- aTrack->SetTrackStatus(fStopAndKill); // don't step photon any further
-
- return true;
- }
- else {
- return false;
- }
-}
+// $Header: /cvs/lcd/lcdd/src/G4OpticalCalorimeter.cc,v 1.2 2007/12/10 17:24:22 wenzel Exp $
+
+#include "G4OpticalCalorimeterSD.hh"
+
+// geant4
+#include "G4OpticalPhoton.hh"
+#include "G4TransportationManager.hh"
+#include "G4VProcess.hh"
+
+// lcdd
+#include "G4Segmentation.hh"
+//
+// Constructor for the case only one Hit Collection is given
+// In this case the only the energy deposited by aborbed Cerenkov
+// photons is stored. Probably this will be dropped in the
+// near future
+//
+G4OpticalCalorimeterSD::G4OpticalCalorimeterSD(G4String sdName,
+ G4String hcName,
+ G4Segmentation* sdSeg,
+ HitComparator* compare)
+ : G4CalorimeterSD(sdName,
+ hcName,
+ sdSeg,
+ compare)
+{
+
+ }
+//
+// Constructor for multiple Hit Collections:
+//
+// The current implementation uses the first Hit
+// Collection for the Cerenkov Photons and the second Collection
+// to store the ionization losses.
+// If more than 2 collections are given the additional Hit collections will
+// be ignored
+//
+G4OpticalCalorimeterSD::G4OpticalCalorimeterSD(G4String sdName,
+ G4String hcName[],
+ G4int NrofReadouts,
+ G4Segmentation* sdSeg,
+ HitComparator* compare)
+ : G4CalorimeterSD(sdName,
+ hcName,
+ NrofReadouts,
+ sdSeg,
+ compare)
+{
+
+ }
+
+G4OpticalCalorimeterSD::~G4OpticalCalorimeterSD()
+{}
+
+G4bool G4OpticalCalorimeterSD::ProcessHits(G4Step* aStep, G4TouchableHistory*)
+{
+ // set cached step
+ G4SensitiveDetector::ProcessHits(aStep, 0);
+ G4Track * aTrack = aStep->GetTrack();
+
+
+ if(aTrack->GetCreatorProcess()==0)
+ {
+ return false;
+ }
+
+
+ // check that particle is optical photon:
+ if(aTrack->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) {
+ if(aTrack->GetParentID()==0) {
+ // particle is primary
+ aTrack->SetTrackStatus(fStopAndKill);
+ return false;
+ }
+
+ // particle is secondary
+ G4String processname = aTrack->GetCreatorProcess()->G4VProcess::GetProcessName();
+ // deal only with Cerenkov photons
+ if(processname != "Cerenkov") {
+ aTrack->SetTrackStatus(fStopAndKill);
+ return false;
+ }
+
+ G4ThreeVector myPoint = aStep->GetPreStepPoint()->GetPosition();
+ G4Navigator* theNavigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
+ G4VPhysicalVolume* myVolume = theNavigator->LocateGlobalPointAndSetup(myPoint);
+
+ if ( getVerbose() > 2 ) {
+ G4cout << "Physical volume = " << myVolume->GetName() << G4endl;
+ G4cout << "Point of interaction = " << myPoint<< G4endl;
+ G4cout << "sdname " << GetName() << " hcname " <<collectionName[0]<< G4endl;
+ }
+
+ G4double theEdep = aTrack->GetTotalEnergy();// total photon energy
+ // get global cell pos from seg
+ G4ThreeVector globalCellPos = m_segmentation->getGlobalHitPos( aStep );
+
+ // reset the seg bins
+ m_segmentation->resetBins();
+
+ // set the seg bins
+ m_segmentation->setBins( aStep );
+
+ // create id and pack into 64
+ Id64bit id64 = makeId();
+
+ // find hit by simple lkp of new hit with above info
+ G4CalorimeterHit* thisHit = new G4CalorimeterHit(theEdep, globalCellPos);
+ thisHit->setId64bit( id64.getId0(), id64.getId1() );
+ G4CalorimeterHit* fndHit = 0;
+ // hit is not found?
+ if ( !( fndHit = findHit( thisHit,eCerenkov ) ) ) {
+
+ // add it to lkp map
+ hits_vector[eCerenkov].push_back(thisHit);
+
+ // add to the HC
+ HC_vector[eCerenkov]->insert(thisHit);
+ }
+ // found a hit
+ else {
+
+ // don't need to insert thisHit, so delete it
+ delete thisHit;
+ thisHit = 0;
+
+ // incr total edep of the hit
+ fndHit->incrEdep(theEdep);
+
+ // for setting contrib
+ thisHit = fndHit;
+ }
+
+ // add McpHitContrib to this hit, setting info from step info
+ thisHit->addMcpHitContrib( McpHitContrib( aStep ) );
+ aTrack->SetTrackStatus(fStopAndKill); // don't step photon any further
+
+ return true;
+ } // end optical photon treatment
+ else if (m_NrofHC>1) {
+ // here we deal with everything but the optical photon.
+ // get the edep
+
+ G4double theEdep = edep();
+ // This needs to be a <= comparison for cutting on 0.
+ // Allow passthrough of geantinos w/ 0 edep.
+ if ( theEdep <= getEcut() && !isGeantino() ) {
+#ifdef G4VERBOSE
+ if ( getVerbose() > 2 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - cut on edep " << theEdep << std::endl;
+ }
+#endif
+ return false;
+ }
+
+ // get global cell pos from seg
+ G4ThreeVector globalCellPos = m_segmentation->getGlobalHitPos( aStep );
+ // reset the seg bins
+ m_segmentation->resetBins();
+
+ // set the seg bins
+ m_segmentation->setBins( aStep );
+
+ // create id and pack into 64
+ Id64bit id64 = makeId();
+
+ // DEBUG: Compute step midpoint and compare to the cell pos
+#ifdef G4VERBOSE
+ if ( getVerbose() > 2 ) {
+ G4ThreeVector globalMidPos = midPosition();
+ std::cout << "globalMidPos " << globalMidPos << std::endl;
+ std::cout << "globalCellPos - globalMidPos = " << globalCellPos - globalMidPos << std::endl;
+ }
+#endif
+
+ // find hit by simple lkp of new hit with above info
+ G4CalorimeterHit* thisHit = new G4CalorimeterHit(theEdep, globalCellPos);
+ thisHit->setId64bit( id64.getId0(), id64.getId1() );
+ G4CalorimeterHit* fndHit = 0;
+
+ // hit is not found?
+ if ( !( fndHit = findHit( thisHit,eEdep ) ) ) {
+
+#ifdef G4VERBOSE
+ if ( getVerbose() > 1 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - new hit" << std::endl;
+ }
+#endif
+
+ // add it to lkp map
+ hits_vector[eEdep].push_back(thisHit);
+ // add to the HC
+ HC_vector[eEdep]->insert(thisHit);
+
+ }
+ // found a hit
+ else {
+
+#ifdef G4VERBOSE
+ if ( getVerbose() > 2 ) {
+ std::cout << "G4CalorimeterSD::ProcessHits - existing hit" << std::endl;
+ }
+#endif
+
+ // don't need to insert thisHit, so delete it
+ delete thisHit;
+ thisHit = 0;
+
+ // incr total edep of the hit
+ fndHit->incrEdep(theEdep);
+
+ // for setting contrib
+ thisHit = fndHit;
+ }
+
+ // add McpHitContrib to this hit, setting info from step info
+ thisHit->addMcpHitContrib( McpHitContrib( aStep ) );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
lcdd/src
diff -u -r1.13 -r1.14
--- G4SensitiveDetector.cc 12 Jul 2007 18:09:01 -0000 1.13
+++ G4SensitiveDetector.cc 10 Dec 2007 17:24:22 -0000 1.14
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/lcdd/src/G4SensitiveDetector.cc,v 1.13 2007/07/12 18:09:01 jeremy Exp $
+// $Header: /cvs/lcd/lcdd/src/G4SensitiveDetector.cc,v 1.14 2007/12/10 17:24:22 wenzel Exp $
#include "G4SensitiveDetector.hh"
@@ -25,142 +25,172 @@
const std::string& G4SensitiveDetector::noneStr = "none";
G4SensitiveDetector::G4SensitiveDetector(G4String sdName,
- G4String hcName,
- EType sdType)
- : G4VSensitiveDetector(sdName),
- m_HCID(-1),
- m_idspec(0),
- 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()
-{}
-
-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_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)
-{
- os << "number of hits: " << this->getNumberOfHits() << std::endl;
- return os;
-}
-
-std::ostream& G4SensitiveDetector::printEdep(std::ostream& os)
-{
- 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)
-{
- 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;
-}
+ G4String hcName,
+ EType sdType)
+ : G4VSensitiveDetector(sdName),
+ m_NrofHC(1),
+ 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 element in the vectors:
+
+ HCID_vector.clear();
+ nhits_vector.clear();
+ idspec_vector.clear();
+ ecut_vector.clear();
+
+ HCID_vector.push_back(-1);
+ nhits_vector.push_back(-1);
+ ecut_vector.push_back(0);
+ idspec_vector.push_back(NULL);
+ }
+
+ G4SensitiveDetector::G4SensitiveDetector(G4String sdName,
+ G4String hcName[],
+ G4int NrofHC,
+ EType sdType)
+ : G4VSensitiveDetector(sdName),
+ m_NrofHC(NrofHC),
+ m_type(sdType) {
+ HCID_vector.clear();
+ nhits_vector.clear();
+ idspec_vector.clear();
+ ecut_vector.clear();
+ for(int i= 0; i < m_NrofHC; i++) {
+ // insert hits collection name into SD's name vector
+ collectionName.insert(hcName[i]);
+ HCID_vector.push_back(-1);
+ nhits_vector.push_back(-1);
+ ecut_vector.push_back(0);
+ idspec_vector.push_back(NULL);
+ }
+
+ // 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: " << HCID_vector[0]<< std::endl;
+ os << "energy cut: " << G4BestUnit( ecut_vector[0], "Energy" ) << std::endl;
+ os << "endcap flag: " << m_endcap << std::endl;
+ os << "verbose level: " << m_verbose << std::endl;
+
+ if ( idspec_vector[0] != 0 ) {
+ os << "id spec: " << idspec_vector[0]->getName() << std::endl;
+ os << "id fields:";
+ for ( IdSpec::IdFields::const_iterator it = idspec_vector[0]->IdFieldsBegin();
+ it != idspec_vector[0]->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;
+ }
+ 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) {
+ os << "number of hits: " << this->getNumberOfHits() << std::endl;
+ return os;
+ }
+
+ std::ostream& G4SensitiveDetector::printEdep(std::ostream& os) {
+ 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) {
+ 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;
+ }