slic/src
diff -u -r1.3 -r1.4
--- HitsCollectionUtil.cc 10 Dec 2007 17:27:18 -0000 1.3
+++ HitsCollectionUtil.cc 12 Dec 2007 03:19:13 -0000 1.4
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/HitsCollectionUtil.cc,v 1.3 2007/12/10 17:27:18 wenzel Exp $
+// $Header: /cvs/lcd/slic/src/HitsCollectionUtil.cc,v 1.4 2007/12/12 03:19:13 jeremy Exp $
#include "HitsCollectionUtil.hh"
// lcdd
@@ -10,36 +10,52 @@
#include "G4HCtable.hh"
#include "G4EventManager.hh"
#include "G4Event.hh"
-#include <set>
-namespace slic {
- std::vector<int> HitsCollectionUtil::getHCIDs() {
-
+
+// stl
+#include <vector>
+#include <algorithm>
+
+namespace slic
+{
+ std::vector<G4SensitiveDetector*> HitsCollectionUtil::getSensitiveDetectors()
+ {
G4SDManager* SDmgr = G4SDManager::GetSDMpointer();
G4HCtable* HCtbl = SDmgr->GetHCtable();
G4int num_entries = HCtbl->entries();
- // use set to make sure that every sensitive detector is only queried once for its Hit Collections
- std::set<G4SensitiveDetector*> usedSD;
- std::set<G4SensitiveDetector*>::const_iterator usedSDiter;
- std::vector<int> hcids;
+
+ std::vector<G4SensitiveDetector*> sds;
+
for (G4int i = 0;i < num_entries;i++) {
// get the name of this SD
G4String sdname = HCtbl->GetSDname( i );
// retrieve corresponding Sensitive Detector from Geant4 store and cast to LCDD type
- G4SensitiveDetector* SD =
+ G4SensitiveDetector* sd =
static_cast<G4SensitiveDetector*> ( G4SDManager::GetSDMpointer()->FindSensitiveDetector( sdname ) );
- if (SD) {usedSD.insert(SD);}
+ // Add, checking for dups.
+ if (sd && std::find(sds.begin(), sds.end(), sd) == sds.end()) sds.push_back(sd);
}
- usedSDiter = usedSD.begin();
- for ( usedSDiter = usedSD.begin( ); usedSDiter != usedSD.end( ); usedSDiter++ ) {
- G4SensitiveDetector* SD2 = (*usedSDiter);
- for(G4int j= 0; j < SD2->getNrofHC(); j++) {
- hcids.push_back( SD2->getHCID(j) );
+ return sds;
+ }
+
+ std::vector<int> HitsCollectionUtil::getHCIDs()
+ {
+ std::vector<int> hcids;
+ const std::vector<G4SensitiveDetector*>& sds = getSensitiveDetectors();
+ for ( std::vector<G4SensitiveDetector*>::const_iterator it = sds.begin();
+ it != sds.end();
+ it++ )
+ {
+ G4SensitiveDetector* sd = (*it);
+ for( int i = 0; i < sd->getNumberOfHitsCollections(); i++)
+ {
+ hcids.push_back( sd->getHCID(i) );
}
}
return hcids;
}
- std::vector<std::string> HitsCollectionUtil::getHCNames() {
+ std::vector<std::string> HitsCollectionUtil::getHCNames()
+ {
std::vector<int> hcids = getHCIDs();
const G4Event* currEvent =
slic/src
diff -u -r1.13 -r1.14
--- LcioHitsCollectionBuilder.cc 10 Dec 2007 17:27:17 -0000 1.13
+++ LcioHitsCollectionBuilder.cc 12 Dec 2007 03:19:13 -0000 1.14
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/LcioHitsCollectionBuilder.cc,v 1.13 2007/12/10 17:27:17 wenzel Exp $
+// $Header: /cvs/lcd/slic/src/LcioHitsCollectionBuilder.cc,v 1.14 2007/12/12 03:19:13 jeremy Exp $
#include "LcioHitsCollectionBuilder.hh"
@@ -32,440 +32,440 @@
namespace slic
{
- LcioHitsCollectionBuilder::LcioHitsCollectionBuilder()
- : Module("LcioHitsCollectionBuilder"),
- m_storeMomentum( 0 )
- {
- // set local LcioMcpManager ptr
- m_mcpManager = LcioMcpManager::instance();
+ LcioHitsCollectionBuilder::LcioHitsCollectionBuilder()
+ : Module("LcioHitsCollectionBuilder"),
+ m_storeMomentum( 0 )
+ {
+ // set local LcioMcpManager ptr
+ m_mcpManager = LcioMcpManager::instance();
- // setup default coll flag for cal hits
- setCalFlagDefaults();
+ // setup default coll flag for cal hits
+ setCalFlagDefaults();
- // Set store momentum bit for TrackerHits
- m_trkCollFlag.setBit( LCIO::THBIT_MOMENTUM );
- }
-
- LcioHitsCollectionBuilder::~LcioHitsCollectionBuilder()
- {;}
-
- // create the hit collections
- void LcioHitsCollectionBuilder::createHitCollections()
- {
- // fetch HCIDs
- std::vector<int> hcids = HitsCollectionUtil::getHCIDs();
+ // Set store momentum bit for TrackerHits
+ m_trkCollFlag.setBit( LCIO::THBIT_MOMENTUM );
+ }
- // fetch hit collection of event
- G4HCofThisEvent* HCE = m_currentG4Event->GetHCofThisEvent();
+ LcioHitsCollectionBuilder::~LcioHitsCollectionBuilder()
+ {;}
- // HC table
- G4HCtable* HCtbl = G4SDManager::GetSDMpointer()->GetHCtable();
+ // create the hit collections
+ void LcioHitsCollectionBuilder::createHitCollections()
+ {
+ // fetch HCIDs
+ std::vector<int> hcids = HitsCollectionUtil::getHCIDs();
- // HCID
- G4int hcid;
+ // fetch hit collection of event
+ G4HCofThisEvent* HCE = m_currentG4Event->GetHCofThisEvent();
- LCCollectionVec* collVect = 0;
+ // HC table
+ G4HCtable* HCtbl = G4SDManager::GetSDMpointer()->GetHCtable();
+ // HCID
+ G4int hcid;
- for (std::vector<int>::const_iterator iter = hcids.begin();
- iter != hcids.end();
- iter++) {
+ LCCollectionVec* collVect = 0;
- hcid = *iter;
- log().debug(" Creating hits collections for HCID: " + StringUtil::toString( hcid ) );
- // retrieve Sensitive Detector ptr
- G4SensitiveDetector* SD =
- static_cast<G4SensitiveDetector*>
- ( G4SDManager::GetSDMpointer()->FindSensitiveDetector( HCtbl->GetSDname( hcid ) ) );
+ for (std::vector<int>::const_iterator iter = hcids.begin();
+ iter != hcids.end();
+ iter++)
+ {
+
+ hcid = *iter;
+
+ log().debug(" Creating hits collections for HCID: " + StringUtil::toString( hcid ) );
+
+ // retrieve Sensitive Detector ptr
+ G4SensitiveDetector* SD = static_cast<G4SensitiveDetector*>( G4SDManager::GetSDMpointer()->FindSensitiveDetector( HCtbl->GetSDname( hcid ) ) );
- // get hits collection
- for (int i =0;i<SD->getNrofHC();i++)
- {
- if (SD->getHCID(i)==hcid)
- {
- G4VHitsCollection* HC = HCE->GetHC( hcid );
-
- // add a LCCollectionVec if got a HC
- if ( HC ) {
-
- // set LCIO endcap bit in the flag (i.e. CHBIT_BARREL ) according to SDs setting
- setEndcapFlag( SD );
-
- // create collection vector based on type of SD
- collVect = createCollectionVec( HC, SD->getType() );
-
- // Store the cellID description into the LCIO::cellIDEncoding parameter in the collection.
- if ( SD->getIdSpec() ) {
- std::string id = SD->getIdSpec()->getFieldDescription();
- collVect->parameters().setValue(LCIO::CellIDEncoding, id) ;
- }
-
- // add collection vector to LCEvent
- m_currentLCEvent->addCollection( collVect, HC->GetName() );
- }
+ // get hits collection
+ for (int i = 0; i < SD->getNumberOfHitsCollections(); i++)
+ {
+ if (SD->getHCID(i)==hcid)
+ {
+ G4VHitsCollection* HC = HCE->GetHC( hcid );
+
+ // add a LCCollectionVec if got a HC
+ if ( HC ) {
+
+ // set LCIO endcap bit in the flag (i.e. CHBIT_BARREL ) according to SDs setting
+ setEndcapFlag( SD );
+
+ // create collection vector based on type of SD
+ collVect = createCollectionVec( HC, SD->getType() );
+
+ // Store the cellID description into the LCIO::cellIDEncoding parameter in the collection.
+ if ( SD->getIdSpec() ) {
+ std::string id = SD->getIdSpec()->getFieldDescription();
+ collVect->parameters().setValue(LCIO::CellIDEncoding, id) ;
+ }
+
+ // add collection vector to LCEvent
+ m_currentLCEvent->addCollection( collVect, HC->GetName() );
+ }
- else {
- G4Exception( "LcioHitsCollectionBuilder::createHitCollections() - No collection found for Hits Collection ID");
- }
- }
- }
- }
- }
- // create the CollectionVec (decides which overloaded subfunction to call)
- IMPL::LCCollectionVec* LcioHitsCollectionBuilder::createCollectionVec(G4VHitsCollection* g4HC,
- G4SensitiveDetector::EType SDtype)
- {
- // vec to create
- LCCollectionVec* collVec = 0;
-
- // cal hits
- if ( SDtype == G4SensitiveDetector::eCalorimeter ) {
- collVec = createCalorimeterCollectionVec(g4HC);
- }
- // tracker hits
- else if ( SDtype == G4SensitiveDetector::eTracker ) {
- collVec = createTrackerCollectionVec(g4HC);
- }
- // unknown type of hit
- else {
- G4Exception( "Unknown HC type." );
- }
-
- return collVec;
- }
-
- LCCollectionVec* LcioHitsCollectionBuilder::createTrackerCollectionVec(G4VHitsCollection* g4HC)
- {
- // create Lcio tracker coll
- LCCollectionVec* collVec = new LCCollectionVec( LCIO::SIMTRACKERHIT );
-
- // cast to G4 trk HC
- G4TrackerHitsCollection* trkHits =
- dynamic_cast<G4TrackerHitsCollection*> (g4HC);
-
- // call overloaded save function for trk hits
- saveHits(trkHits,
- collVec);
-
- // set trk flags
- collVec->setFlag( m_trkCollFlag.getFlag() );
-
- return collVec;
- }
-
- LCCollectionVec* LcioHitsCollectionBuilder::createCalorimeterCollectionVec(G4VHitsCollection* g4HC)
- {
- // create Lcio cal coll
- LCCollectionVec* collVec = new LCCollectionVec(LCIO::SIMCALORIMETERHIT);
-
- // cast to G4 cal HC
- G4CalorimeterHitsCollection* calHits
- = dynamic_cast<G4CalorimeterHitsCollection*> (g4HC);
-
- // call overloaded save function for cal hits
- saveHits(calHits,
- collVec);
-
- // set cal flags
- collVec->setFlag( m_calCollFlag.getFlag() );
-
- return collVec;
- }
-
- void LcioHitsCollectionBuilder::setCalFlagDefaults()
- {
- m_calCollFlag.setBit( LCIO::CHBIT_LONG );
- m_calCollFlag.setBit( LCIO::CHBIT_ID1 );
- }
-
- void LcioHitsCollectionBuilder::setEndcapFlag(G4SensitiveDetector* g4sd)
- {
- bool ec_flag = g4sd->getEndcapFlag();
-
- // set for cal
- if ( g4sd->getType() == G4SensitiveDetector::eCalorimeter ) {
- if ( ec_flag ) {
- m_calCollFlag.unsetBit( LCIO::CHBIT_BARREL );
- }
- else {
- m_calCollFlag.setBit( LCIO::CHBIT_BARREL );
- }
- }
- // set for trk
- else if ( g4sd->getType() == G4SensitiveDetector::eTracker ) {
- if ( ec_flag ) {
- m_trkCollFlag.unsetBit( LCIO::THBIT_BARREL );
- }
- else {
- m_trkCollFlag.setBit( LCIO::THBIT_BARREL );
- }
- }
- }
-
- // save cal hits
- void LcioHitsCollectionBuilder::saveHits(G4CalorimeterHitsCollection* calHits,
- IMPL::LCCollectionVec* lcioColl)
- {
- size_t s = calHits->GetSize();
- for ( size_t i = 0;
- i < s;
- i++ ) {
- G4CalorimeterHit* calHit =
- static_cast<G4CalorimeterHit*> ( calHits->GetHit(i) );
- lcioColl->push_back( createHit( calHit ) );
- }
- }
-
- // save trk hits
- void LcioHitsCollectionBuilder::saveHits(G4TrackerHitsCollection* trkHits,
- IMPL::LCCollectionVec* lcioColl)
- {
- size_t s = trkHits->GetSize();
- for ( size_t i = 0;
- i < s;
- i++ ) {
- G4TrackerHit* trkHit =
- static_cast<G4TrackerHit*> ( trkHits->GetHit( i ) );
- lcioColl->push_back( createHit( trkHit ) );
- }
- }
-
- // create cal hit from G4
- IMPL::SimCalorimeterHitImpl* LcioHitsCollectionBuilder::createHit(G4CalorimeterHit* calHit)
- {
- SimCalorimeterHitImpl* simCalHit = new SimCalorimeterHitImpl();
-
- // set cellid from cal hit's id64
- const Id64bit& id64 = calHit->getId64bit();
- simCalHit->setCellID0( id64.getId0() );
- simCalHit->setCellID1( id64.getId1() );
-
- // position
- const Hep3Vector hitPos = calHit->getPos();
- float pos[3] = { hitPos.x(), hitPos.y(), hitPos.z() };
- simCalHit->setPosition( pos );
+ else {
+ G4Exception( "LcioHitsCollectionBuilder::createHitCollections() - No collection found for Hits Collection ID");
+ }
+ }
+ }
+ }
+ }
+ // create the CollectionVec (decides which overloaded subfunction to call)
+ IMPL::LCCollectionVec* LcioHitsCollectionBuilder::createCollectionVec(G4VHitsCollection* g4HC,
+ G4SensitiveDetector::EType SDtype)
+ {
+ // vec to create
+ LCCollectionVec* collVec = 0;
+
+ // cal hits
+ if ( SDtype == G4SensitiveDetector::eCalorimeter ) {
+ collVec = createCalorimeterCollectionVec(g4HC);
+ }
+ // tracker hits
+ else if ( SDtype == G4SensitiveDetector::eTracker ) {
+ collVec = createTrackerCollectionVec(g4HC);
+ }
+ // unknown type of hit
+ else {
+ G4Exception( "Unknown HC type." );
+ }
+
+ return collVec;
+ }
+
+ LCCollectionVec* LcioHitsCollectionBuilder::createTrackerCollectionVec(G4VHitsCollection* g4HC)
+ {
+ // create Lcio tracker coll
+ LCCollectionVec* collVec = new LCCollectionVec( LCIO::SIMTRACKERHIT );
+
+ // cast to G4 trk HC
+ G4TrackerHitsCollection* trkHits =
+ dynamic_cast<G4TrackerHitsCollection*> (g4HC);
+
+ // call overloaded save function for trk hits
+ saveHits(trkHits,
+ collVec);
+
+ // set trk flags
+ collVec->setFlag( m_trkCollFlag.getFlag() );
+
+ return collVec;
+ }
+
+ LCCollectionVec* LcioHitsCollectionBuilder::createCalorimeterCollectionVec(G4VHitsCollection* g4HC)
+ {
+ // create Lcio cal coll
+ LCCollectionVec* collVec = new LCCollectionVec(LCIO::SIMCALORIMETERHIT);
+
+ // cast to G4 cal HC
+ G4CalorimeterHitsCollection* calHits
+ = dynamic_cast<G4CalorimeterHitsCollection*> (g4HC);
+
+ // call overloaded save function for cal hits
+ saveHits(calHits,
+ collVec);
+
+ // set cal flags
+ collVec->setFlag( m_calCollFlag.getFlag() );
+
+ return collVec;
+ }
+
+ void LcioHitsCollectionBuilder::setCalFlagDefaults()
+ {
+ m_calCollFlag.setBit( LCIO::CHBIT_LONG );
+ m_calCollFlag.setBit( LCIO::CHBIT_ID1 );
+ }
+
+ void LcioHitsCollectionBuilder::setEndcapFlag(G4SensitiveDetector* g4sd)
+ {
+ bool ec_flag = g4sd->getEndcapFlag();
+
+ // set for cal
+ if ( g4sd->getType() == G4SensitiveDetector::eCalorimeter ) {
+ if ( ec_flag ) {
+ m_calCollFlag.unsetBit( LCIO::CHBIT_BARREL );
+ }
+ else {
+ m_calCollFlag.setBit( LCIO::CHBIT_BARREL );
+ }
+ }
+ // set for trk
+ else if ( g4sd->getType() == G4SensitiveDetector::eTracker ) {
+ if ( ec_flag ) {
+ m_trkCollFlag.unsetBit( LCIO::THBIT_BARREL );
+ }
+ else {
+ m_trkCollFlag.setBit( LCIO::THBIT_BARREL );
+ }
+ }
+ }
+
+ // save cal hits
+ void LcioHitsCollectionBuilder::saveHits(G4CalorimeterHitsCollection* calHits,
+ IMPL::LCCollectionVec* lcioColl)
+ {
+ size_t s = calHits->GetSize();
+ for ( size_t i = 0;
+ i < s;
+ i++ ) {
+ G4CalorimeterHit* calHit =
+ static_cast<G4CalorimeterHit*> ( calHits->GetHit(i) );
+ lcioColl->push_back( createHit( calHit ) );
+ }
+ }
+
+ // save trk hits
+ void LcioHitsCollectionBuilder::saveHits(G4TrackerHitsCollection* trkHits,
+ IMPL::LCCollectionVec* lcioColl)
+ {
+ size_t s = trkHits->GetSize();
+ for ( size_t i = 0;
+ i < s;
+ i++ ) {
+ G4TrackerHit* trkHit =
+ static_cast<G4TrackerHit*> ( trkHits->GetHit( i ) );
+ lcioColl->push_back( createHit( trkHit ) );
+ }
+ }
+
+ // create cal hit from G4
+ IMPL::SimCalorimeterHitImpl* LcioHitsCollectionBuilder::createHit(G4CalorimeterHit* calHit)
+ {
+ SimCalorimeterHitImpl* simCalHit = new SimCalorimeterHitImpl();
+
+ // set cellid from cal hit's id64
+ const Id64bit& id64 = calHit->getId64bit();
+ simCalHit->setCellID0( id64.getId0() );
+ simCalHit->setCellID1( id64.getId1() );
+
+ // position
+ const Hep3Vector hitPos = calHit->getPos();
+ float pos[3] = { hitPos.x(), hitPos.y(), hitPos.z() };
+ simCalHit->setPosition( pos );
- // copy Mcp contrib info; energy is also incremented by contrib addition
- addMcpContribs( calHit, simCalHit );
+ // copy Mcp contrib info; energy is also incremented by contrib addition
+ addMcpContribs( calHit, simCalHit );
- // compare edep of calHit with simHit when debugging
+ // compare edep of calHit with simHit when debugging
#ifdef SLIC_DEBUG
- const McpHitContribList& contribs = calHit->getMcpHitContribList();
- double totE = 0;
- for ( McpHitContribList::const_iterator iter = contribs.begin();
- iter != contribs.end();
- iter++ ){
- totE += (*iter).getEdep();
- }
-
- // sanity check so that new and old edeps must match
- if (abs( totE/GeV - simCalHit->getEnergy() ) > ( 0.001 * totE ) ) {
- log() << LOG::debug << "g4 hit E: " << totE << LOG::done;
- log() << LOG::debug << "sim hit E: " << simCalHit->getEnergy() << LOG::done;
- G4Exception("LCIO simCalHit E != G4 CalHit E, within tolerance");
- }
+ const McpHitContribList& contribs = calHit->getMcpHitContribList();
+ double totE = 0;
+ for ( McpHitContribList::const_iterator iter = contribs.begin();
+ iter != contribs.end();
+ iter++ ){
+ totE += (*iter).getEdep();
+ }
+
+ // sanity check so that new and old edeps must match
+ if (abs( totE/GeV - simCalHit->getEnergy() ) > ( 0.001 * totE ) ) {
+ log() << LOG::debug << "g4 hit E: " << totE << LOG::done;
+ log() << LOG::debug << "sim hit E: " << simCalHit->getEnergy() << LOG::done;
+ G4Exception("LCIO simCalHit E != G4 CalHit E, within tolerance");
+ }
#endif
- return simCalHit;
- }
-
- // create trk hit from G4
- IMPL::SimTrackerHitImpl* LcioHitsCollectionBuilder::createHit(G4TrackerHit* trkHit)
- {
- SimTrackerHitImpl* simTrkHit = new SimTrackerHitImpl();
-
- // position in mm
- const Hep3Vector hitPos = trkHit->getPos();
- double pos[3] = { hitPos.x(), hitPos.y(), hitPos.z() };
- simTrkHit->setPosition( pos );
-
- // momentum in GeV
- const G4ThreeVector& momentum = trkHit->getMomentum();
- simTrkHit->setMomentum( momentum.x()/GeV, momentum.y()/GeV, momentum.z()/GeV);
-
- // pathLength = distance between exit and entry points in mm
- simTrkHit->setPathLength( trkHit->getLength() );
-
- // dEdx in GeV (LCIO units)
- float edep = trkHit->getEdep();
- simTrkHit->setdEdx( edep / GeV );
-
- // time in NS
- float tEdep = trkHit->getTdep();
- simTrkHit->setTime(tEdep);
-
- // id
- simTrkHit->setCellID( trkHit->getId() );
-
- // MCP using McpManager
- MCParticleImpl* mcp = m_mcpManager->getMaps()->findMcpFromTrackID( trkHit->getTrackID() );
-
- if ( !mcp ) {
- log().error("No MCP found for trackID <" + StringUtil::toString( trkHit->getTrackID() ) + "> for trk hit.");
- }
- else {
- simTrkHit->setMCParticle( mcp );
- }
-
- return simTrkHit;
- }
-
- // add an MCParticle hit contribution from G4 to LCIO
- void LcioHitsCollectionBuilder::addMcpContribs( G4CalorimeterHit* g4CalHit, IMPL::SimCalorimeterHitImpl* simCalHit)
- {
- // create empty hit contrib list
- McpHitContribList contribs;
-
- // aggregation of contribs by track ID if CHBIT_PDG is not set
- if ( !m_calCollFlag.bitSet(LCIO::CHBIT_PDG) ) {
-
- // pass ref to contrib list, which will get filled
- combineMcpHitContribs( g4CalHit->getMcpHitContribList(),
- contribs );
-
- }
- // otherwise use the complete list from cal hit
- else {
-
- // set contrib list to cal contribs
- contribs = g4CalHit->getMcpHitContribList();
+ return simCalHit;
}
- // add contribs to LCIO Mcp
- size_t ncontrib = 0;
- for ( McpHitContribList::const_iterator iter = contribs.begin();
- iter != contribs.end();
- iter++ ) {
-
- // get this contrib
- const McpHitContrib& contrib = ( *iter );
-
- // fetch associcated MCP pointer by trackID
- MCParticleImpl* contribMcp = m_mcpManager->getMaps()->findMcpFromTrackID( contrib.getTrackID() );
-
- if ( contribMcp != 0 ) {
-
- // add the Mcp contrib to the Lcio cal hit
- simCalHit->addMCParticleContribution(contribMcp,
- contrib.getEdep() / GeV,
- contrib.getGlobalTime(),
- contrib.getPDGID()
- );
- ++ncontrib;
- }
- }
+ // create trk hit from G4
+ IMPL::SimTrackerHitImpl* LcioHitsCollectionBuilder::createHit(G4TrackerHit* trkHit)
+ {
+ SimTrackerHitImpl* simTrkHit = new SimTrackerHitImpl();
+
+ // position in mm
+ const Hep3Vector hitPos = trkHit->getPos();
+ double pos[3] = { hitPos.x(), hitPos.y(), hitPos.z() };
+ simTrkHit->setPosition( pos );
+
+ // momentum in GeV
+ const G4ThreeVector& momentum = trkHit->getMomentum();
+ simTrkHit->setMomentum( momentum.x()/GeV, momentum.y()/GeV, momentum.z()/GeV);
+
+ // pathLength = distance between exit and entry points in mm
+ simTrkHit->setPathLength( trkHit->getLength() );
+
+ // dEdx in GeV (LCIO units)
+ float edep = trkHit->getEdep();
+ simTrkHit->setdEdx( edep / GeV );
+
+ // time in NS
+ float tEdep = trkHit->getTdep();
+ simTrkHit->setTime(tEdep);
+
+ // id
+ simTrkHit->setCellID( trkHit->getId() );
+
+ // MCP using McpManager
+ MCParticleImpl* mcp = m_mcpManager->getMaps()->findMcpFromTrackID( trkHit->getTrackID() );
+
+ if ( !mcp ) {
+ log().error("No MCP found for trackID <" + StringUtil::toString( trkHit->getTrackID() ) + "> for trk hit.");
+ }
+ else {
+ simTrkHit->setMCParticle( mcp );
+ }
+
+ return simTrkHit;
+ }
+
+ // add an MCParticle hit contribution from G4 to LCIO
+ void LcioHitsCollectionBuilder::addMcpContribs( G4CalorimeterHit* g4CalHit, IMPL::SimCalorimeterHitImpl* simCalHit)
+ {
+ // create empty hit contrib list
+ McpHitContribList contribs;
+
+ // aggregation of contribs by track ID if CHBIT_PDG is not set
+ if ( !m_calCollFlag.bitSet(LCIO::CHBIT_PDG) ) {
+
+ // pass ref to contrib list, which will get filled
+ combineMcpHitContribs( g4CalHit->getMcpHitContribList(),
+ contribs );
+
+ }
+ // otherwise use the complete list from cal hit
+ else {
+
+ // set contrib list to cal contribs
+ contribs = g4CalHit->getMcpHitContribList();
+ }
+
+ // add contribs to LCIO Mcp
+ size_t ncontrib = 0;
+ for ( McpHitContribList::const_iterator iter = contribs.begin();
+ iter != contribs.end();
+ iter++ ) {
+
+ // get this contrib
+ const McpHitContrib& contrib = ( *iter );
+
+ // fetch associcated MCP pointer by trackID
+ MCParticleImpl* contribMcp = m_mcpManager->getMaps()->findMcpFromTrackID( contrib.getTrackID() );
+
+ if ( contribMcp != 0 ) {
+
+ // add the Mcp contrib to the Lcio cal hit
+ simCalHit->addMCParticleContribution(contribMcp,
+ contrib.getEdep() / GeV,
+ contrib.getGlobalTime(),
+ contrib.getPDGID()
+ );
+ ++ncontrib;
+ }
+ }
#ifdef SLIC_LOG
- if ( ncontrib == 0 ) {
- log().error("No hit contribs for sim cal hit.");
- }
+ if ( ncontrib == 0 ) {
+ log().error("No hit contribs for sim cal hit.");
+ }
#endif
- }
-
- void LcioHitsCollectionBuilder::combineMcpHitContribs(const McpHitContribList& long_contrib,
- McpHitContribList& combined_contrib)
- {
- combined_contrib.clear();
-
- // iterate over long list (one entry for every hit)
- for ( McpHitContribList::const_iterator iter = long_contrib.begin();
- iter != long_contrib.end();
- iter++ ) {
-
- int trk_id = (*iter).getTrackID();
-
- //log().debug("Combining hits on trk_id: " + StringUtil::toString( trk_id ) );
+ }
- // old track id in new combined list?
- McpHitContrib* trk_contrib = 0;
- if ( ( trk_contrib = findMcpHitContribByTrackID( (*iter).getTrackID(), combined_contrib ) ) ) {
+ void LcioHitsCollectionBuilder::combineMcpHitContribs(const McpHitContribList& long_contrib,
+ McpHitContribList& combined_contrib)
+ {
+ combined_contrib.clear();
+
+ // iterate over long list (one entry for every hit)
+ for ( McpHitContribList::const_iterator iter = long_contrib.begin();
+ iter != long_contrib.end();
+ iter++ ) {
+
+ int trk_id = (*iter).getTrackID();
+
+ //log().debug("Combining hits on trk_id: " + StringUtil::toString( trk_id ) );
+
+ // old track id in new combined list?
+ McpHitContrib* trk_contrib = 0;
+ if ( ( trk_contrib = findMcpHitContribByTrackID( (*iter).getTrackID(), combined_contrib ) ) ) {
- //log().debug("Incr edep <" + StringUtil::toString( (*iter).getEdep() ) + ">");
+ //log().debug("Incr edep <" + StringUtil::toString( (*iter).getEdep() ) + ">");
- // += edep
- trk_contrib->incrEdep( (*iter).getEdep() );
+ // += edep
+ trk_contrib->incrEdep( (*iter).getEdep() );
- // set min time
- trk_contrib->setMinTime( (*iter).getGlobalTime() );
- }
- // no existing contrib
- else {
-
- //log().debug("New hit edep <" + StringUtil::toString( (*iter).getEdep() ) + ">");
-
- // create new contrib
- combined_contrib.push_back(McpHitContrib(trk_id,
- (*iter).getEdep(),
- 0,
- (*iter).getGlobalTime() ) );
- }
- }
- }
-
- McpHitContrib* LcioHitsCollectionBuilder::findMcpHitContribByTrackID(int trk_id,
- McpHitContribList& contribs)
- {
- McpHitContrib* c = 0;
- for ( McpHitContribList::iterator iter = contribs.begin();
- iter != contribs.end();
- iter++ ) {
- if ( (*iter).getTrackID() == trk_id ) {
+ // set min time
+ trk_contrib->setMinTime( (*iter).getGlobalTime() );
+ }
+ // no existing contrib
+ else {
+
+ //log().debug("New hit edep <" + StringUtil::toString( (*iter).getEdep() ) + ">");
+
+ // create new contrib
+ combined_contrib.push_back(McpHitContrib(trk_id,
+ (*iter).getEdep(),
+ 0,
+ (*iter).getGlobalTime() ) );
+ }
+ }
+ }
+
+ McpHitContrib* LcioHitsCollectionBuilder::findMcpHitContribByTrackID(int trk_id,
+ McpHitContribList& contribs)
+ {
+ McpHitContrib* c = 0;
+ for ( McpHitContribList::iterator iter = contribs.begin();
+ iter != contribs.end();
+ iter++ ) {
+ if ( (*iter).getTrackID() == trk_id ) {
#ifdef SLIC_LOG
- log() << LOG::debug << "found match on trkID <" << trk_id << ">" << LOG::done;
+ log() << LOG::debug << "found match on trkID <" << trk_id << ">" << LOG::done;
#endif
- c = &(*iter);
- break;
- }
- }
+ c = &(*iter);
+ break;
+ }
+ }
#ifdef SLIC_LOG
- log() << LOG::debug << "returning McpHitContrib ptr <" << c << ">" << LOG::done;
+ log() << LOG::debug << "returning McpHitContrib ptr <" << c << ">" << LOG::done;
#endif
- return c;
- }
-
- EVENT::LCEvent* LcioHitsCollectionBuilder::createHCsFromG4Event(const G4Event* g4evt, EVENT::LCEvent* lcevt)
- {
- // set instance vars
- m_currentG4Event = g4evt;
- m_currentLCEvent = lcevt;
-
- // call real HC creation function
- createHitCollections();
-
- // return evt pntr, which is same as input
- return m_currentLCEvent;
- }
-
- void LcioHitsCollectionBuilder::setLongFlag(bool setting)
- {
- if ( setting ) {
- m_calCollFlag.setBit( LCIO::CHBIT_LONG );
- }
- else {
- m_calCollFlag.unsetBit( LCIO::CHBIT_LONG );
+ return c;
}
+ EVENT::LCEvent* LcioHitsCollectionBuilder::createHCsFromG4Event(const G4Event* g4evt, EVENT::LCEvent* lcevt)
+ {
+ // set instance vars
+ m_currentG4Event = g4evt;
+ m_currentLCEvent = lcevt;
+
+ // call real HC creation function
+ createHitCollections();
+
+ // return evt pntr, which is same as input
+ return m_currentLCEvent;
+ }
+
+ void LcioHitsCollectionBuilder::setLongFlag(bool setting)
+ {
+ if ( setting ) {
+ m_calCollFlag.setBit( LCIO::CHBIT_LONG );
+ }
+ else {
+ m_calCollFlag.unsetBit( LCIO::CHBIT_LONG );
+ }
+
#ifdef SLIC_LOG
- log().verbose("Set CHBIT_LONG: " + StringUtil::toString( setting ) );
+ log().verbose("Set CHBIT_LONG: " + StringUtil::toString( setting ) );
#endif
- }
-
- void LcioHitsCollectionBuilder::setPDGFlag(bool setting)
- {
- if ( setting ) {
- m_calCollFlag.setBit( LCIO::CHBIT_PDG );
- }
- else {
- m_calCollFlag.setBit( LCIO::CHBIT_PDG );
}
+ void LcioHitsCollectionBuilder::setPDGFlag(bool setting)
+ {
+ if ( setting ) {
+ m_calCollFlag.setBit( LCIO::CHBIT_PDG );
+ }
+ else {
+ m_calCollFlag.setBit( LCIO::CHBIT_PDG );
+ }
+
#ifdef SLIC_LOG
- log().verbose("Set CHBIT_PDG: " + StringUtil::toString( setting ) );
+ log().verbose("Set CHBIT_PDG: " + StringUtil::toString( setting ) );
#endif
- }
+ }
}