slic/src
diff -u -r1.19 -r1.20
--- LcioHitsCollectionBuilder.cc 26 Jul 2010 19:40:28 -0000 1.19
+++ LcioHitsCollectionBuilder.cc 23 Aug 2011 22:42:26 -0000 1.20
@@ -1,11 +1,12 @@
-// $Header: /cvs/lcd/slic/src/LcioHitsCollectionBuilder.cc,v 1.19 2010/07/26 19:40:28 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioHitsCollectionBuilder.cc,v 1.20 2011/08/23 22:42:26 jeremy Exp $
+// SLIC
#include "LcioHitsCollectionBuilder.hh"
-// lcdd
+// LCDD
#include "StringUtil.hh"
-// slic
+// SLIC
#include "LcioMcpManager.hh"
#include "HitsCollectionUtil.hh"
#include "SlicApplication.hh"
@@ -15,9 +16,10 @@
#include "IMPL/LCFlagImpl.h"
#include "IMPL/MCParticleImpl.h"
-// geant4
+// Geant4
#include "G4SDManager.hh"
+// LCIO
using IMPL::SimCalorimeterHitImpl;
using IMPL::SimTrackerHitImpl;
using IMPL::MCParticleImpl;
@@ -26,490 +28,514 @@
using IMPL::LCCollectionVec;
using EVENT::LCIO;
-namespace CLHEP {}
+namespace CLHEP
+{}
using namespace CLHEP;
+
using std::string;
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 );
- }
+ // Set store momentum bit for TrackerHits
+ m_trkCollFlag.setBit(LCIO::THBIT_MOMENTUM);
+}
- LcioHitsCollectionBuilder::~LcioHitsCollectionBuilder()
- {;}
+LcioHitsCollectionBuilder::~LcioHitsCollectionBuilder()
+{
+ ;
+}
- // create the hit collections
- void LcioHitsCollectionBuilder::createHitCollections()
- {
- // fetch HCIDs
- std::vector<int> hcids = HitsCollectionUtil::getHCIDs();
+// create the hit collections
+void LcioHitsCollectionBuilder::createHitCollections()
+{
+ // fetch HCIDs
+ std::vector<int> hcids = HitsCollectionUtil::getHCIDs();
- // fetch hit collection of event
- G4HCofThisEvent* HCE = m_currentG4Event->GetHCofThisEvent();
+ // fetch hit collection of event
+ G4HCofThisEvent* HCE = m_currentG4Event->GetHCofThisEvent();
- // HC table
- G4HCtable* HCtbl = G4SDManager::GetSDMpointer()->GetHCtable();
+ // HC table
+ G4HCtable* HCtbl = G4SDManager::GetSDMpointer()->GetHCtable();
- // HCID
- G4int hcid;
+ // HCID
+ G4int hcid;
- LCCollectionVec* collVec = 0;
+ LCCollectionVec* collVec = 0;
+ for (std::vector<int>::const_iterator iter = hcids.begin(); iter!=hcids.end(); iter++)
+ {
+ hcid = *iter;
- for (std::vector<int>::const_iterator iter = hcids.begin();
- iter != hcids.end();
- iter++)
- {
-
- hcid = *iter;
-
#ifdef SLIC_LOG
- log().debug(" Creating hits collections for HCID: " + StringUtil::toString( hcid ) );
+ log().debug(" Creating hits collections for HCID: " + StringUtil::toString( hcid ) );
#endif
-
- // retrieve Sensitive Detector ptr
- G4SensitiveDetector* SD = static_cast<G4SensitiveDetector*>( G4SDManager::GetSDMpointer()->FindSensitiveDetector( HCtbl->GetSDname( hcid ) ) );
-
- // get hits collection
- for (int i = 0; i < SD->getNumberOfHitsCollections(); i++)
- {
- if (SD->getHCID(i)==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->getNumberOfHitsCollections(); i++)
+ {
+ if (SD->getHCID(i)==hcid)
+ {
+ G4VHitsCollection* HC = HCE->GetHC(hcid);
+
+ // add a LCCollectionVec if got a HC
+ if (HC)
{
- G4VHitsCollection* HC = HCE->GetHC( hcid );
+ // 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
+ collVec = createCollectionVec(HC, SD->getType());
- // 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
- collVec = 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();
-#if LCIO_VERSION_GE( 1, 7)
- collVec->parameters().setValue(LCIO::CellIDEncoding, id) ;
+ // Store the cellID description into the LCIO::cellIDEncoding parameter in the collection.
+ if (SD->getIdSpec())
+ {
+ std::string id = SD->getIdSpec()->getFieldDescription();
+#if LCIO_VERSION_GE(1, 7)
+ collVec->parameters().setValue(LCIO::CellIDEncoding, id);
#else
- collVec->parameters().setValue("CellIDEncoding", id) ;
+ collVec->parameters().setValue("CellIDEncoding", id);
#endif
- }
+ }
- // Check for existing collection.
- if (containsCollection( m_currentLCEvent, HC->GetName() ) )
- {
+ // Check for existing collection.
+ if (containsCollection(m_currentLCEvent, HC->GetName()))
+ {
#ifdef SLIC_LOG
- log().debug("Adding hits to existing collection " + HC->GetName() + ".");
+ log().debug("Adding hits to existing collection " + HC->GetName() + ".");
#endif
- // Update existing collection.
- // TODO: Check for matching id scheme and flags!
- LCCollectionVec* collection = (LCCollectionVec*) m_currentLCEvent->getCollection( HC->GetName() );
- collection->insert( collection->begin(), collVec->begin(), collVec->end() );
- }
- // No collection found.
- else
- {
+ // Update existing collection.
+ // TODO: Check for matching id scheme and flags!
+ LCCollectionVec * collection =
+ (LCCollectionVec*)m_currentLCEvent->getCollection(HC->GetName());
+ collection->insert(collection->begin(), collVec->begin(), collVec->end());
+ }
+ // No collection found.
+ else
+ {
#ifdef SLIC_LOG
- log().debug("Creating new hit collection collection " + HC->GetName() + ".");
+ log().debug("Creating new hit collection collection " + HC->GetName() + ".");
#endif
- // Add new collection vector to LCEvent.
- m_currentLCEvent->addCollection( collVec, HC->GetName() );
- }
- }
-
- else {
- G4Exception( "LcioHitsCollectionBuilder::createHitCollections() - No collection found for Hits Collection ID");
+ // Add new collection vector to LCEvent.
+ m_currentLCEvent->addCollection(collVec, 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;
-
- // create the CollectionVec (decides which overloaded subfunction to call)
- IMPL::LCCollectionVec* LcioHitsCollectionBuilder::createCollectionVec(G4VHitsCollection* g4HC,
- G4SensitiveDetector::EType SDtype)
+ // cal hits
+ if (SDtype==G4SensitiveDetector::eCalorimeter)
{
- // vec to create
- LCCollectionVec* collVec = 0;
+ collVec = createCalorimeterCollectionVec(g4HC);
+ }
+ // tracker hits
+ else if (SDtype==G4SensitiveDetector::eTracker)
+ {
+ collVec = createTrackerCollectionVec(g4HC);
+ }
+ // unknown type of hit
+ else
+ {
+ G4Exception("Unknown HC type.");
+ }
- // 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;
+}
- return collVec;
- }
+LCCollectionVec* LcioHitsCollectionBuilder::createTrackerCollectionVec(G4VHitsCollection* g4HC)
+{
+ // create Lcio tracker coll
+ LCCollectionVec* collVec = new LCCollectionVec(LCIO::SIMTRACKERHIT);
- 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);
- // cast to G4 trk HC
- G4TrackerHitsCollection* trkHits =
- dynamic_cast<G4TrackerHitsCollection*> (g4HC);
+ // call overloaded save function for trk hits
+ saveHits(trkHits, collVec);
- // call overloaded save function for trk hits
- saveHits(trkHits,
- collVec);
+ // set trk flags
+ collVec->setFlag(m_trkCollFlag.getFlag());
- // set trk flags
- collVec->setFlag( m_trkCollFlag.getFlag() );
+ return collVec;
+}
- return collVec;
- }
+LCCollectionVec* LcioHitsCollectionBuilder::createCalorimeterCollectionVec(G4VHitsCollection* g4HC)
+{
+ // create Lcio cal coll
+ LCCollectionVec* collVec = new LCCollectionVec(LCIO::SIMCALORIMETERHIT);
- 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);
- // cast to G4 cal HC
- G4CalorimeterHitsCollection* calHits
- = dynamic_cast<G4CalorimeterHitsCollection*> (g4HC);
+ // call overloaded save function for cal hits
+ saveHits(calHits, collVec);
- // call overloaded save function for cal hits
- saveHits(calHits,
- collVec);
+ // set cal flags
+ collVec->setFlag(m_calCollFlag.getFlag());
- // set cal flags
- collVec->setFlag( m_calCollFlag.getFlag() );
+ return collVec;
+}
- return collVec;
- }
+void LcioHitsCollectionBuilder::setCalFlagDefaults()
+{
+ m_calCollFlag.setBit(LCIO::CHBIT_LONG);
+ m_calCollFlag.setBit(LCIO::CHBIT_ID1);
+}
- 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();
- void LcioHitsCollectionBuilder::setEndcapFlag(G4SensitiveDetector* g4sd)
+ // set for cal
+ if (g4sd->getType()==G4SensitiveDetector::eCalorimeter)
{
- 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 );
- }
+ if (ec_flag)
+ {
+ m_calCollFlag.unsetBit(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 );
- }
+ else
+ {
+ m_calCollFlag.setBit(LCIO::CHBIT_BARREL);
}
}
-
- // save cal hits
- void LcioHitsCollectionBuilder::saveHits(G4CalorimeterHitsCollection* calHits,
- IMPL::LCCollectionVec* lcioColl)
+ // set for trk
+ else if (g4sd->getType()==G4SensitiveDetector::eTracker)
{
- 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 ) );
+ if (ec_flag)
+ {
+ m_trkCollFlag.unsetBit(LCIO::THBIT_BARREL);
+ }
+ else
+ {
+ m_trkCollFlag.setBit(LCIO::THBIT_BARREL);
}
}
+}
- // save trk hits
- void LcioHitsCollectionBuilder::saveHits(G4TrackerHitsCollection* trkHits,
- IMPL::LCCollectionVec* lcioColl)
+// save cal hits
+void LcioHitsCollectionBuilder::saveHits(G4CalorimeterHitsCollection* calHits,
+ IMPL::LCCollectionVec* lcioColl)
+{
+ size_t s = calHits->GetSize();
+ for (size_t i = 0; i<s; i++)
{
- 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 ) );
- }
+ G4CalorimeterHit* calHit = static_cast<G4CalorimeterHit*> (calHits->GetHit(i));
+ lcioColl->push_back(createHit(calHit));
}
+}
- // create cal hit from G4
- IMPL::SimCalorimeterHitImpl* LcioHitsCollectionBuilder::createHit(G4CalorimeterHit* 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++)
{
- SimCalorimeterHitImpl* simCalHit = new SimCalorimeterHitImpl();
+ G4TrackerHit* trkHit = static_cast<G4TrackerHit*> (trkHits->GetHit(i));
+ lcioColl->push_back(createHit(trkHit));
+ }
+}
- // set cellid from cal hit's id64
- const Id64bit& id64 = calHit->getId64bit();
- simCalHit->setCellID0( id64.getId0() );
- simCalHit->setCellID1( id64.getId1() );
+// create cal hit from G4
+IMPL::SimCalorimeterHitImpl* LcioHitsCollectionBuilder::createHit(G4CalorimeterHit* calHit)
+{
+ SimCalorimeterHitImpl* simCalHit = new SimCalorimeterHitImpl();
- // position
- const Hep3Vector hitPos = calHit->getPos();
- float pos[3] = { hitPos.x(), hitPos.y(), hitPos.z() };
- simCalHit->setPosition( pos );
+ // 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");
- }
-#endif
-
- return simCalHit;
+ const McpHitContribList& contribs = calHit->getMcpHitContribList();
+ double totE = 0;
+ for ( McpHitContribList::const_iterator iter = contribs.begin();
+ iter != contribs.end();
+ iter++ )
+ {
+ totE += (*iter).getEdep();
}
- // create trk hit from G4
- IMPL::SimTrackerHitImpl* LcioHitsCollectionBuilder::createHit(G4TrackerHit* trkHit)
+ // sanity check so that new and old edeps must match
+ if (abs( totE/GeV - simCalHit->getEnergy() ) > ( 0.001 * totE ) )
{
- SimTrackerHitImpl* simTrkHit = new SimTrackerHitImpl();
+ 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
- // position in mm
- const Hep3Vector hitPos = trkHit->getPos();
- double pos[3] = { hitPos.x(), hitPos.y(), hitPos.z() };
- simTrkHit->setPosition( pos );
+ return simCalHit;
+}
- // momentum in GeV
- const G4ThreeVector& momentum = trkHit->getMomentum();
- simTrkHit->setMomentum( momentum.x()/GeV, momentum.y()/GeV, momentum.z()/GeV);
+// create trk hit from G4
+IMPL::SimTrackerHitImpl* LcioHitsCollectionBuilder::createHit(G4TrackerHit* trkHit)
+{
+ SimTrackerHitImpl* simTrkHit = new SimTrackerHitImpl();
- // pathLength = distance between exit and entry points in mm
- simTrkHit->setPathLength( trkHit->getLength() );
+ // 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->setEDep(edep/GeV);
+
+ // time in NS
+ float tEdep = trkHit->getTdep();
+ simTrkHit->setTime(tEdep);
+
+ // Cell ID.
+#if LCIO_VERSION_GE(1, 60)
+ // New method for 64-bit IDs.
+ simTrkHit->setCellID0(trkHit->getId());
+#else
+ // Old method for 32-bit IDs.
+ simTrkHit->setCellID(trkHit->getId());
+#endif
- // dEdx in GeV (LCIO units)
- float edep = trkHit->getEdep();
- simTrkHit->setEDep( edep / GeV );
+ // MCP using McpManager
+ MCParticleImpl* mcp = m_mcpManager->getMaps()->findMcpFromTrackID(trkHit->getTrackID());
- // time in NS
- float tEdep = trkHit->getTdep();
- simTrkHit->setTime(tEdep);
+ if (!mcp)
+ {
+ log().error(
+ "No MCP found for trackID <"+StringUtil::toString(trkHit->getTrackID())
+ +"> for trk hit.");
+ }
+ else
+ {
+ simTrkHit->setMCParticle(mcp);
+ }
- // id
- simTrkHit->setCellID( trkHit->getId() );
+ return simTrkHit;
+}
- // MCP using McpManager
- MCParticleImpl* mcp = m_mcpManager->getMaps()->findMcpFromTrackID( trkHit->getTrackID() );
+// add an MCParticle hit contribution from G4 to LCIO
+void LcioHitsCollectionBuilder::addMcpContribs(G4CalorimeterHit* g4CalHit,
+ IMPL::SimCalorimeterHitImpl* simCalHit)
+{
+ // Create empty hit contrib list.
+ McpHitContribList contribs;
- if ( !mcp )
- {
- log().error("No MCP found for trackID <" + StringUtil::toString( trkHit->getTrackID() ) + "> for trk hit.");
- }
- else
- {
- simTrkHit->setMCParticle( mcp );
- }
+ // Use aggregation of contribs by track ID if CHBIT_PDG is not set.
+ if (!m_calCollFlag.bitSet(LCIO::CHBIT_PDG))
+ {
+ // Pass a ref to contrib list, which will get filled.
+ combineMcpHitContribs(g4CalHit->getMcpHitContribList(), contribs);
- return simTrkHit;
+ }
+ // Otherwise, use the complete list from the CalHit.
+ else
+ {
+ contribs = g4CalHit->getMcpHitContribList();
}
- // add an MCParticle hit contribution from G4 to LCIO
- void LcioHitsCollectionBuilder::addMcpContribs( G4CalorimeterHit* g4CalHit, IMPL::SimCalorimeterHitImpl* simCalHit)
+ // Add contribs to the LCIO MCParticle.
+ size_t ncontrib = 0;
+ for (McpHitContribList::const_iterator iter = contribs.begin(); iter!=contribs.end(); iter++)
{
- // Create empty hit contrib list.
- McpHitContribList contribs;
- // Use aggregation of contribs by track ID if CHBIT_PDG is not set.
- if ( !m_calCollFlag.bitSet(LCIO::CHBIT_PDG) )
- {
- // Pass a ref to contrib list, which will get filled.
- combineMcpHitContribs( g4CalHit->getMcpHitContribList(),
- contribs );
+ // This contrib.
+ const McpHitContrib& contrib = (*iter);
- }
- // Otherwise, use the complete list from the CalHit.
- else
- {
- contribs = g4CalHit->getMcpHitContribList();
- }
+ // Get the MCParticle pointer from the track ID.
+ MCParticleImpl* contribMcp = m_mcpManager->getMaps()->findMcpFromTrackID(
+ contrib.getTrackID());
- // Add contribs to the LCIO MCParticle.
- size_t ncontrib = 0;
- for ( McpHitContribList::const_iterator iter = contribs.begin();
- iter != contribs.end();
- iter++ )
+ if (contribMcp!=0)
{
-
- // This contrib.
- const McpHitContrib& contrib = ( *iter );
-
- // Get the MCParticle pointer from the track ID.
- MCParticleImpl* contribMcp = m_mcpManager->getMaps()->findMcpFromTrackID( contrib.getTrackID() );
-
- if ( contribMcp != 0 )
- {
- // Add the MCParticle contribution to the hit.
- simCalHit->addMCParticleContribution(contribMcp,
- contrib.getEdep() / GeV,
- contrib.getGlobalTime(),
- contrib.getPDGID()
- );
- ++ncontrib;
- }
- // Problem! Contributing particle is missing from MCParticle list.
-#ifdef SLIC_LOG
- else
- {
- log() << LOG::always << "ERROR: Could not find MCParticle from track ID <" << contrib.getTrackID() << ">." << LOG::endl;
- }
+ // Add the MCParticle contribution to the hit.
+#if LCIO_VERSION_GE(1, 60)
+ // Newer LCIO versions have the step position for contributions.
+ simCalHit->addMCParticleContribution(
+ contribMcp,
+ (float)(contrib.getEdep()/GeV),
+ (float)(contrib.getGlobalTime()),
+ contrib.getPDGID(),
+ const_cast<float*>(contrib.getPosition()));
+#else
+ // Older LCIO versions do not include step position.
+ simCalHit->addMCParticleContribution(
+ contribMcp,
+ (float)(contrib.getEdep()/GeV),
+ (float)contrib.getGlobalTime(),
+ contrib.getPDGID());
#endif
+ ++ncontrib;
}
-
-#ifdef SLIC_LOG
- if ( ncontrib == 0 )
+ // Problem! Contributing particle is missing from MCParticle list.
+#ifdef SLIC_LOG
+ else
{
- log().error("No hit contribs for sim cal hit.");
+ log() << LOG::always << "ERROR: Could not find MCParticle from track ID <" << contrib.getTrackID() << ">." << LOG::endl;
}
#endif
}
- void LcioHitsCollectionBuilder::combineMcpHitContribs(const McpHitContribList& long_contrib,
- McpHitContribList& combined_contrib)
+#ifdef SLIC_LOG
+ if ( ncontrib == 0 )
{
- 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++ )
- {
+ log().error("No hit contribs for sim cal hit.");
+ }
+#endif
+}
- int trk_id = (*iter).getTrackID();
+void LcioHitsCollectionBuilder::combineMcpHitContribs(const McpHitContribList& long_contrib,
+ McpHitContribList& combined_contrib)
+{
+ combined_contrib.clear();
- //log().debug("Combining hits on trk_id: " + StringUtil::toString( trk_id ) );
+ // 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();
- // old track id in new combined list?
- McpHitContrib* trk_contrib = 0;
- if ( ( trk_contrib = findMcpHitContribByTrackID( (*iter).getTrackID(), combined_contrib ) ) )
- {
- // += edep
- trk_contrib->incrEdep( (*iter).getEdep() );
+ //log().debug("Combining hits on trk_id: " + StringUtil::toString( trk_id ) );
- // set min time
- trk_contrib->setMinTime( (*iter).getGlobalTime() );
- }
- // no existing contrib
- else
- {
- //log().debug("New hit edep <" + StringUtil::toString( (*iter).getEdep() ) + ">");
+ // old track id in new combined list?
+ McpHitContrib* trk_contrib = 0;
+ if ((trk_contrib = findMcpHitContribByTrackID((*iter).getTrackID(), combined_contrib)))
+ {
+ // Add to the energy deposition.
+ trk_contrib->incrEdep((*iter).getEdep());
- // create new contrib
- combined_contrib.push_back(McpHitContrib(trk_id,
- (*iter).getEdep(),
- 0,
- (*iter).getGlobalTime() ) );
- }
+ // Set the minimum time.
+ trk_contrib->setMinTime((*iter).getGlobalTime());
+ }
+ // no existing contrib
+ else
+ {
+ // Create a new contribution.
+ combined_contrib.push_back(
+ McpHitContrib(trk_id, (*iter).getEdep(), 0, (*iter).getGlobalTime()));
}
}
+}
- McpHitContrib* LcioHitsCollectionBuilder::findMcpHitContribByTrackID(int trk_id, McpHitContribList& contribs)
+McpHitContrib* LcioHitsCollectionBuilder::findMcpHitContribByTrackID(int trk_id,
+ McpHitContribList& contribs)
+{
+ McpHitContrib* c = 0;
+ for (McpHitContribList::iterator iter = contribs.begin(); iter!=contribs.end(); iter++)
{
- McpHitContrib* c = 0;
- for ( McpHitContribList::iterator iter = contribs.begin();
- iter != contribs.end();
- iter++ )
- {
- if ( ( *iter ).getTrackID() == trk_id )
- {
- c = &( *iter );
- break;
- }
+ if ((*iter).getTrackID()==trk_id)
+ {
+ c = &(*iter);
+ break;
}
-
- return c;
}
- EVENT::LCEvent* LcioHitsCollectionBuilder::createHCsFromG4Event(const G4Event* g4evt, EVENT::LCEvent* lcevt)
- {
- // set instance vars
- m_currentG4Event = g4evt;
- m_currentLCEvent = lcevt;
+ return c;
+}
- // call real HC creation function
- createHitCollections();
+EVENT::LCEvent* LcioHitsCollectionBuilder::createHCsFromG4Event(const G4Event* g4evt,
+ EVENT::LCEvent* lcevt)
+{
+ // set instance vars
+ m_currentG4Event = g4evt;
+ m_currentLCEvent = lcevt;
- // return evt pntr, which is same as input
- return m_currentLCEvent;
- }
+ // call real HC creation function
+ createHitCollections();
+
+ // return evt pntr, which is same as input
+ return m_currentLCEvent;
+}
- void LcioHitsCollectionBuilder::setLongFlag(bool setting)
+void LcioHitsCollectionBuilder::setLongFlag(bool setting)
+{
+ if (setting)
{
- if ( setting ) {
- m_calCollFlag.setBit( LCIO::CHBIT_LONG );
- }
- else {
- m_calCollFlag.unsetBit( LCIO::CHBIT_LONG );
- }
+ 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)
+void LcioHitsCollectionBuilder::setPDGFlag(bool setting)
+{
+ if (setting)
{
- if ( setting ) {
- m_calCollFlag.setBit( LCIO::CHBIT_PDG );
- }
- else {
- m_calCollFlag.setBit( LCIO::CHBIT_PDG );
- }
+ 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
- }
+}
- bool LcioHitsCollectionBuilder::containsCollection(EVENT::LCEvent* event, const string& collectionName)
+bool LcioHitsCollectionBuilder::containsCollection(EVENT::LCEvent* event,
+ const string& collectionName)
+{
+ for (std::vector<string>::const_iterator iter = event->getCollectionNames()->begin(); iter
+ !=event->getCollectionNames()->end(); iter++)
{
- for (std::vector<string>::const_iterator iter = event->getCollectionNames()->begin();
- iter != event->getCollectionNames()->end();
- iter++)
+ const string thisName = *iter;
+ if (thisName.compare(collectionName)==0)
{
- const string thisName = *iter;
- if (thisName.compare(collectionName) == 0)
- {
- return true;
- }
+ return true;
}
- return false;
}
+ return false;
}
+} // namespace