Print

Print


Commit in slic/src on MAIN
LcioHitsCollectionBuilder.cc+15-181.20 -> 1.21
LcioMcpFactory.cc+151-1371.20 -> 1.21
+166-155
2 modified files
fix contrib combining for lcio 1.60 and greater; include spin and colorflow in LCIO output (confirmed working in lcsim)

slic/src
LcioHitsCollectionBuilder.cc 1.20 -> 1.21
diff -u -r1.20 -r1.21
--- LcioHitsCollectionBuilder.cc	23 Aug 2011 22:42:26 -0000	1.20
+++ LcioHitsCollectionBuilder.cc	1 Sep 2011 21:13:09 -0000	1.21
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/LcioHitsCollectionBuilder.cc,v 1.20 2011/08/23 22:42:26 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioHitsCollectionBuilder.cc,v 1.21 2011/09/01 21:13:09 jeremy Exp $
 
 // SLIC
 #include "LcioHitsCollectionBuilder.hh"
@@ -51,9 +51,7 @@
 }
 
 LcioHitsCollectionBuilder::~LcioHitsCollectionBuilder()
-{
-    ;
-}
+{;}
 
 // create the hit collections
 void LcioHitsCollectionBuilder::createHitCollections()
@@ -372,7 +370,6 @@
     {
         // Pass a ref to contrib list, which will get filled.
         combineMcpHitContribs(g4CalHit->getMcpHitContribList(), contribs);
-
     }
     // Otherwise, use the complete list from the CalHit.
     else
@@ -384,15 +381,13 @@
     size_t ncontrib = 0;
     for (McpHitContribList::const_iterator iter = contribs.begin(); iter!=contribs.end(); iter++)
     {
-
         // This contrib.
         const McpHitContrib& contrib = (*iter);
 
         // Get the MCParticle pointer from the track ID.
-        MCParticleImpl* contribMcp = m_mcpManager->getMaps()->findMcpFromTrackID(
-                contrib.getTrackID());
+        MCParticleImpl* contribMcp = m_mcpManager->getMaps()->findMcpFromTrackID(contrib.getTrackID());
 
-        if (contribMcp!=0)
+        if (contribMcp != 0)
         {
             // Add the MCParticle contribution to the hit.
 #if LCIO_VERSION_GE(1, 60)                
@@ -404,7 +399,7 @@
                     contrib.getPDGID(),
                     const_cast<float*>(contrib.getPosition()));
 #else
-            // Older LCIO versions do not include step position.
+            // Older LCIO versions do not include the step position.
             simCalHit->addMCParticleContribution(
                     contribMcp,
                     (float)(contrib.getEdep()/GeV),
@@ -430,21 +425,21 @@
 #endif
 }
 
-void LcioHitsCollectionBuilder::combineMcpHitContribs(const McpHitContribList& long_contrib,
-        McpHitContribList& combined_contrib)
+void LcioHitsCollectionBuilder::combineMcpHitContribs(const McpHitContribList& longContrib,
+        McpHitContribList& combinedContrib)
 {
-    combined_contrib.clear();
+    combinedContrib.clear();
 
     // iterate over long list (one entry for every hit)
-    for (McpHitContribList::const_iterator iter = long_contrib.begin(); iter!=long_contrib.end(); iter++)
+    for (McpHitContribList::const_iterator iter = longContrib.begin(); iter!=longContrib.end(); iter++)
     {
-        int trk_id = (*iter).getTrackID();
+        int trkId = (*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)))
+        if ((trk_contrib = findMcpHitContribByTrackID((*iter).getTrackID(), combinedContrib)))
         {
             // Add to the energy deposition.
             trk_contrib->incrEdep((*iter).getEdep());
@@ -456,8 +451,10 @@
         else
         {
             // Create a new contribution.
-            combined_contrib.push_back(
-                    McpHitContrib(trk_id, (*iter).getEdep(), 0, (*iter).getGlobalTime()));
+            combinedContrib.push_back(McpHitContrib(trkId,
+                            (*iter).getEdep(),
+                            (*iter).getPDGID(),
+                            (*iter).getGlobalTime()));
         }
     }
 }

slic/src
LcioMcpFactory.cc 1.20 -> 1.21
diff -u -r1.20 -r1.21
--- LcioMcpFactory.cc	23 Aug 2011 22:42:27 -0000	1.20
+++ LcioMcpFactory.cc	1 Sep 2011 21:13:09 -0000	1.21
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/src/LcioMcpFactory.cc,v 1.20 2011/08/23 22:42:27 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/LcioMcpFactory.cc,v 1.21 2011/09/01 21:13:09 jeremy Exp $
 #include "LcioMcpFactory.hh"
 
 // slic
@@ -29,7 +29,7 @@
 namespace slic
 {
     LcioMcpFactory::LcioMcpFactory(LcioMcpManager* manager)
-        : Module( "LcioMcpFactory" ),
+        : Module("LcioMcpFactory"),
           m_manager(manager),
           m_finalColl(0),
           m_currentTrajectoryContainer(0)
@@ -47,22 +47,22 @@
         m_currentTrajectoryContainer = event->GetTrajectoryContainer();
 
         // Check if using StdHep or LCIO e.g. a file-based source?
-        if ( EventSourceManager::instance()->isFileSource() ) {
+        if (EventSourceManager::instance()->isFileSource()) {
             // Create from the initial coll of Mcp.
-            createFinalMcpCollectionFromInitial( m_manager->getInitialMcpCollection() );
+            createFinalMcpCollectionFromInitial(m_manager->getInitialMcpCollection());
         }
         // G4 source using trajectories only.
         else 
         {
             // Create from trajectory container of current G4Event.
-            createFinalMcpCollectionFromTrajectoryContainer( m_currentTrajectoryContainer );
+            createFinalMcpCollectionFromTrajectoryContainer(m_currentTrajectoryContainer);
         }
 
         // Fill supplementary collection with MCParticle endpoint energies.
         fillMcpEndPointEnergy(m_finalColl);
     }
 
-    IMPL::MCParticleImpl* LcioMcpFactory::createMcpFromTrajectory( Trajectory* trj)
+    IMPL::MCParticleImpl* LcioMcpFactory::createMcpFromTrajectory(Trajectory* trj)
     {
 #ifdef SLIC_LOG
         log() << LOG::debug << "createMcpFromTrajectory() - trackId: " << trj->GetTrackID() << LOG::done;
@@ -73,12 +73,12 @@
         MCParticleImpl* mcp = new MCParticleImpl();
 
         // PDG
-        mcp->setPDG( trj->GetPDGEncoding() );
+        mcp->setPDG(trj->GetPDGEncoding());
 
         // mom
-        G4ThreeVector mom = trj->GetInitialMomentum() / GeV;
-        float fmom[3] = { mom.x(), mom.y(), mom.z() };
-        mcp->setMomentum( fmom );
+        G4ThreeVector mom = trj->GetInitialMomentum()/GeV;
+        float fmom[3] = {mom.x(), mom.y(), mom.z()};
+        mcp->setMomentum(fmom);
 
         // Get particle def.
         const G4ParticleDefinition* pdef = trj->GetParticleDefinition();
@@ -112,44 +112,44 @@
         // Use Geant4's mass from the particle definition, which is appropriate for SM particles.
         else
         {
-            m = trj->GetParticleDefinition()->GetPDGMass() / GeV;
+            m = trj->GetParticleDefinition()->GetPDGMass()/GeV;
 #ifdef SLIC_LOG
             log() << "mass from pdef: " << m << LOG::endl;
 #endif
         }
 
         // mass
-        mcp->setMass( m );
+        mcp->setMass(m);
 
         // charge
-        mcp->setCharge( trj->GetCharge() );
+        mcp->setCharge(trj->GetCharge());
 
         // begin and end points
         G4int npts = trj->GetPointEntries();
 
         // begin pnt
-        G4VTrajectoryPoint* beginTrjPnt = trj->GetPoint( 0 );
-        G4ThreeVector beginPos = beginTrjPnt->GetPosition() / mm;
-        double fBeginPos[3] = { beginPos.x(), beginPos.y(), beginPos.z() };
-        mcp->setVertex( fBeginPos );
+        G4VTrajectoryPoint* beginTrjPnt = trj->GetPoint(0);
+        G4ThreeVector beginPos = beginTrjPnt->GetPosition()/mm;
+        double fBeginPos[3] = {beginPos.x(), beginPos.y(), beginPos.z()};
+        mcp->setVertex(fBeginPos);
 
         // end pnt
-        G4VTrajectoryPoint* endTrjPnt = trj->GetPoint( npts - 1 );
-        G4ThreeVector endPos = endTrjPnt->GetPosition() / mm;
-        double fEndPos[3] = { endPos.x(), endPos.y(), endPos.z() };
-        mcp->setEndpoint( fEndPos );
+        G4VTrajectoryPoint* endTrjPnt = trj->GetPoint(npts - 1);
+        G4ThreeVector endPos = endTrjPnt->GetPosition()/mm;
+        double fEndPos[3] = {endPos.x(), endPos.y(), endPos.z()};
+        mcp->setEndpoint(fEndPos);
 
         // time
-        mcp->setTime( trj->GetGlobalTime() );
+        mcp->setTime(trj->GetGlobalTime());
 
         // set status codes from trajectory info (with no dep on any associated Mcps)
-        LcioMcpStatusSetter::setMcpStatusCodesFromTrajectory( trj, mcp );
+        LcioMcpStatusSetter::setMcpStatusCodesFromTrajectory(trj, mcp);
 
         // add to map of trkID -> mcp
 #ifdef SLIC_LOG
         log() << LOG::debug << "adding trackId <" << trj->GetTrackID() << "> to MCP <" << mcp << "> link." << LOG::done;
 #endif
-        m_manager->getMaps()->addTrackIDToMcpLink( trj->GetTrackID(), mcp );
+        m_manager->getMaps()->addTrackIDToMcpLink(trj->GetTrackID(), mcp);
 
         return mcp;
     }
@@ -159,33 +159,32 @@
     {
         if ( m_currentTrajectoryContainer ) 
         {
-
             // loop over trj cont
             int n_trj = m_currentTrajectoryContainer->entries();
             for ( int i = 0;
                   i < n_trj;
                   i++ ) 
             {               
-                Trajectory* trj = static_cast<Trajectory*> ( ( *m_currentTrajectoryContainer )[i] );
+                Trajectory* trj = static_cast<Trajectory*>((*m_currentTrajectoryContainer)[i]);
 
                 // Only add primary trajectories; daughters are picked up within.
-                if ( trj->GetParentID() == 0 ) 
+                if (trj->GetParentID() == 0) 
                 {
 #ifdef SLIC_LOG
                     log() << LOG::debug << "Making primary MCParticle for trajectory with trackID <" << trj->GetTrackID() << ">." << LOG::done;
 #endif
 
                     // Create MCParticle output from trajectory.
-                    MCParticleImpl* mcp = createMcpFromTrajectory( trj );
+                    MCParticleImpl* mcp = createMcpFromTrajectory(trj);
 
                     // Add to the final MCParticle collection.
-                    m_finalColl->addElement( mcp );
+                    m_finalColl->addElement(mcp);
 
                     // Process the daughters.
 #ifdef SLIC_LOG
                     log() << LOG::debug << "Making primary MCParticle for trajectory with trackID <" << trj->GetTrackID() << ">." << LOG::done;
 #endif
-                    addMcpDaughtersFromTrajectoryContainer( mcp, trj->GetTrackID() );
+                    addMcpDaughtersFromTrajectoryContainer(mcp, trj->GetTrackID());
                 }
             }
         }
@@ -199,8 +198,8 @@
         
     }
 
-    void LcioMcpFactory::addMcpDaughtersFromTrajectoryContainer( MCParticleImpl* parMcp,
-                                                                 int parTrkID)
+    void LcioMcpFactory::addMcpDaughtersFromTrajectoryContainer(MCParticleImpl* parMcp,
+                                                                int parTrkID)
     {
 #ifdef SLIC_LOG
         log() << LOG::debug << "addMcpDaughtersFromTraj - parTrkId <" << parTrkID << ">." << LOG::done;
@@ -212,20 +211,20 @@
               i < n_trj;
               i++ ) 
         {
-            Trajectory* trj = static_cast<Trajectory*> ( ( *m_currentTrajectoryContainer)[i] );
+            Trajectory* trj = static_cast<Trajectory*>((*m_currentTrajectoryContainer)[i]);
 
             if ( trj->GetParentID() == parTrkID ) 
             {
 
                 // lkp dau Mcp by track ID
-                MCParticleImpl* dauMcp = m_manager->getMaps()->findMcpFromTrackID( trj->GetTrackID() );
+                MCParticleImpl* dauMcp = m_manager->getMaps()->findMcpFromTrackID(trj->GetTrackID());
 
-                if ( dauMcp == 0 ) 
+                if (dauMcp == 0) 
                 {                    
-                    dauMcp = createMcpFromTrajectory( trj );
+                    dauMcp = createMcpFromTrajectory(trj);
                 }
 
-                if ( dauMcp == 0 )
+                if (dauMcp == 0)
                     G4Exception("Failed to create MCParticle.");
 
                 // add this to final coll
@@ -244,40 +243,43 @@
     void LcioMcpFactory::createFinalMcpCollectionFromInitial(EVENT::LCCollection* mcpVecInitial)
     {
         // coll must exist
-        if ( mcpVecInitial ) {
-
+        if (mcpVecInitial)
+        {
             // get num Mcp in coll
             int numInitMcp = mcpVecInitial->getNumberOfElements();
 
             // coll must have members
-            if ( numInitMcp > 0 ) {
-
+            if (numInitMcp > 0)
+            {
                 // loop over input Mcp coll
-                for ( int i=0; i < numInitMcp; i++ ) {
+                for (int i=0; i < numInitMcp; i++)
+                {
 
 #ifdef SLIC_LOG
                     log() << LOG::debug << "proc initial MCP: " << i << LOG::done;
 #endif        
 
                     // get Mcp
-                    MCParticleImpl* mcp = static_cast<MCParticleImpl*> ( mcpVecInitial->getElementAt( i ) );
+                    MCParticleImpl* mcp = static_cast<MCParticleImpl*>(mcpVecInitial->getElementAt(i));
 
                     // create only from Mcp primaries, e.g. no parents
-                    if ( LcioMcpUtil::isPrimary( mcp ) ) {
-
+                    if (LcioMcpUtil::isPrimary(mcp))
+                    {
 #ifdef SLIC_LOG
                         log() << LOG::debug << "isPrimary" << LOG::done;
 #endif
 
-                        createMcpFromInitialRecurse( mcp );
+                        createMcpFromInitialRecurse(mcp);
                     }
                 }
             }
-            else {
+            else
+            {
                 G4Exception("Initial McpVec has no members.");
             }
         }
-        else {
+        else
+        {
             G4Exception("Initial McpVec ptr is null.");
         }
     }
@@ -291,27 +293,27 @@
         MCParticleImpl* mcp = 0;
 
         // find associated primary
-        G4PrimaryParticle* g4primary = m_manager->getMaps()->findPrimaryFromMcp( mcpInit );
+        G4PrimaryParticle* g4primary = m_manager->getMaps()->findPrimaryFromMcp(mcpInit);
 
         // no associated primary with this initial mcp?
-        if( !g4primary ) {
-
+        if (!g4primary)
+        {
 #ifdef SLIC_LOG
             log() << LOG::debug << "initialOnly" << LOG::done;
 #endif
 
             // create from initial Mcp only
-            mcp = createMcpFromInitialOnly( mcpInit );
+            mcp = createMcpFromInitialOnly(mcpInit);
         }
         // create from primary
-        else {
-
+        else
+        {
 #ifdef SLIC_LOG
             log() << LOG::debug << "fromPrimary" << LOG::done;
 #endif
 
             // create it from primary
-            mcp = createMcpFromPrimary( g4primary, mcpInit );
+            mcp = createMcpFromPrimary(g4primary, mcpInit);
         }
 
         // return the output MCP
@@ -323,25 +325,24 @@
         log() << LOG::debug << "createMcpFromInitialOnly: " << m_manager->getMCParticleIndex(m_manager->getInitialMcpCollection(), mcpInit) << LOG::done;
 
         // copy shallow the initial
-        MCParticleImpl* mcp = createMcpShallowCopy( mcpInit );
+        MCParticleImpl* mcp = createMcpShallowCopy(mcpInit);
 
         // should add to Mcp map here?
-        m_manager->getMaps()->addInitialMcpToFinalMcpLink( mcpInit, mcp);
+        m_manager->getMaps()->addInitialMcpToFinalMcpLink(mcpInit, mcp);
 
         // given initial, create and add daughters
-        addMcpDaughtersFromInitial( mcp, mcpInit );
+        addMcpDaughtersFromInitial(mcp, mcpInit);
 
         // add to final coll
-        m_finalColl->addElement( mcp );
+        m_finalColl->addElement(mcp);
 
         return mcp;
     }
 
-    IMPL::MCParticleImpl* LcioMcpFactory::createMcpFromPrimary(G4PrimaryParticle* primary,
-                                                               EVENT::MCParticle* mcpInit)
+    IMPL::MCParticleImpl* LcioMcpFactory::createMcpFromPrimary(G4PrimaryParticle* primary, EVENT::MCParticle* mcpInit)
     {
 #ifdef SLIC_LOG
-        log() << LOG::done << "createMcpFromPrimary - MCP idx <" << m_manager->getMCParticleIndex( m_manager->getInitialMcpCollection(), mcpInit) << ">" << LOG::done;
+        log() << LOG::done << "createMcpFromPrimary - MCP idx <" << m_manager->getMCParticleIndex(m_manager->getInitialMcpCollection(), mcpInit) << ">" << LOG::done;
 #endif
 
         int trkID = primary->GetTrackID();
@@ -355,17 +356,18 @@
 #endif
 
         MCParticleImpl* mcp = 0;
-        Trajectory* trj = TrajectoryManager::instance()->findTrajectory( trkID );
+        Trajectory* trj = TrajectoryManager::instance()->findTrajectory(trkID);
 
         // No trajectory was created.        
-        if ( !trj ) {
+        if (!trj)
+        {
 
 #ifdef SLIC_LOG
             log() << LOG::debug << "initialAndPrimary" << LOG::done;
 #endif
 
             // Recursively create particles from primary and initial MCParticles.
-            mcp = createMcpFromInitialAndPrimary( primary, mcpInit );
+            mcp = createMcpFromInitialAndPrimary(primary, mcpInit);
 
         }
         // Found a trajectory.
@@ -377,18 +379,18 @@
 #endif
 
             // Recursively create MCParticles from a trajectory and the initial MCParticle.
-            mcp = createMcpFromInitialAndTrajectory( trj, mcpInit );
+            mcp = createMcpFromInitialAndTrajectory(trj, mcpInit);
 
         }
 
         // Set generator status from initial particle.
-        mcp->setGeneratorStatus( mcpInit->getGeneratorStatus() );
+        mcp->setGeneratorStatus(mcpInit->getGeneratorStatus());
 
         // Primary particles do not originate in the simulation.
-        mcp->setCreatedInSimulation( false );
+        mcp->setCreatedInSimulation(false);
         
         // Link the input MCP to an output MCP.         
-        m_manager->getMaps()->addInitialMcpToFinalMcpLink( mcpInit, mcp);
+        m_manager->getMaps()->addInitialMcpToFinalMcpLink(mcpInit, mcp);
 
 
 //#ifdef SLIC_LOG
@@ -398,7 +400,7 @@
         // Link the track ID to the output particle.
         if (trkID > 0)
         {
-            m_manager->getMaps()->addTrackIDToMcpLink( trkID, mcp );
+            m_manager->getMaps()->addTrackIDToMcpLink(trkID, mcp);
         }
         else
         {
@@ -421,20 +423,20 @@
          * Create new Mcp from primary particle,
          * shallow copy only (no recursion).
          */
-        MCParticleImpl* mcp = createMcpFromPrimaryShallowCopy( primary );
+        MCParticleImpl* mcpNew = createMcpFromPrimaryShallowCopy(primary);
 
         /* Get vertex from initial particle, because primary does not have it -- was immediately decayed */
-        double vtx[3] = { mcpInit->getVertex()[0], mcpInit->getVertex()[1], mcpInit->getVertex()[2] };
-        mcp->setVertex( vtx );
+        double vtx[3] = {mcpInit->getVertex()[0], mcpInit->getVertex()[1], mcpInit->getVertex()[2]};
+        mcpNew->setVertex(vtx);
 
         /* setup primary's daughters */
-        createDaughtersFromPrimary( primary, /* this primary */
-                                    mcpInit, /* associated initial Mcp particle */
-                                    mcp      /* parent Mcp particle */
+        createDaughtersFromPrimary(primary, /* this primary */
+                                   mcpInit, /* associated initial Mcp particle */
+                                   mcpNew      /* parent Mcp particle */
             );
 
 #ifdef SLIC_DEBUG
-        if ( mcp->getDaughters().size() == 0 ) 
+        if (mcpNew->getDaughters().size() == 0)
         {
 #ifdef SLIC_LOG
             log() << LOG::debug << "No Mcp daughters added." << LOG::done;
@@ -442,24 +444,28 @@
         }
 #endif
 
+        // Copy spin and color flow information if LCIO version is compatible.
+#if LCIO_VERSION_GE(1, 60)
+        copySpinAndColorFlow(mcpInit, mcpNew);
+#endif
+
         // done with particle; add to coll
-        m_finalColl->addElement( mcp );
+        m_finalColl->addElement(mcpNew);
 
-        return mcp;
+        return mcpNew;
     }
 
-    IMPL::MCParticleImpl* LcioMcpFactory::createMcpFromInitialAndTrajectory(Trajectory* trj,
-                                                                            EVENT::MCParticle* mcpInit)
+    IMPL::MCParticleImpl* LcioMcpFactory::createMcpFromInitialAndTrajectory(Trajectory* trj, EVENT::MCParticle* mcpInit)
     {
 #ifdef SLIC_LOG
-        log() << LOG::done << "createMcpFromInitialAndTrajectory: " << m_manager->getMCParticleIndex( m_manager->getInitialMcpCollection(), mcpInit ) << LOG::done;
+        log() << LOG::done << "createMcpFromInitialAndTrajectory: " << m_manager->getMCParticleIndex(m_manager->getInitialMcpCollection(), mcpInit) << LOG::done;
 #endif
 
         // shallow copy create with basic info and no daughters
-        IMPL::MCParticleImpl* mcp = createMcpFromTrajectory( trj );
+        IMPL::MCParticleImpl* mcp = createMcpFromTrajectory(trj);
 
         // set generator status and created in sim flag
-        LcioMcpStatusSetter::setGeneratorStatus( mcpInit, mcp );
+        LcioMcpStatusSetter::setGeneratorStatus(mcpInit, mcp);
 
         // loop over all trajectories to find trajectory daughter
         int numTrj = m_currentTrajectoryContainer->entries();
@@ -476,26 +482,26 @@
 //        }
 //#endif
 
-        for( int j=0; j < numTrj; j++ ) 
+        for(int j=0; j<numTrj; j++)
         {
 
-            Trajectory* thisTrj = static_cast<Trajectory*> ( ( *m_currentTrajectoryContainer ) [j] );
+            Trajectory* thisTrj = static_cast<Trajectory*>((*m_currentTrajectoryContainer)[j]);
 
             // found daughter
-            if ( thisTrj->GetParentID() == trj->GetTrackID() ) 
+            if (thisTrj->GetParentID() == trj->GetTrackID())
             {
 #ifdef SLIC_LOG
                 log() << LOG::debug << "Trajectory with trackID <" << trj->GetTrackID() << "> has parent with trackID <" << thisTrj->GetParentID() << ">" << LOG::done;
 #endif
 
                 // find matching primary Mcp input particle
-                MCParticle* mcpPrim = m_manager->getMaps()->findPrimaryInitialMcpFromTrajectory( thisTrj );
+                MCParticle* mcpPrim = m_manager->getMaps()->findPrimaryInitialMcpFromTrajectory(thisTrj);
 
                 // create MCP output particle from this input daughter
-                MCParticleImpl* mcpDauNew = createMcpFromInitialAndTrajectory( thisTrj, mcpPrim );
+                MCParticleImpl* mcpDauNew = createMcpFromInitialAndTrajectory(thisTrj, mcpPrim);
 
                 // set parent link of new daughter
-                mcpDauNew->addParent( mcp );
+                mcpDauNew->addParent(mcp);
             }
             // DEBUG
             //else 
@@ -506,44 +512,32 @@
         }
 
         // add to collection
-        m_finalColl->addElement( mcp );
+        m_finalColl->addElement(mcp);
 
         return mcp;
     }
 
     IMPL::MCParticleImpl* LcioMcpFactory::createMcpShallowCopy(EVENT::MCParticle* mcp)
     {
-
         IMPL::MCParticleImpl* mcpNew = new IMPL::MCParticleImpl();
 
-        mcpNew->setPDG( mcp->getPDG() );
-
-        float p[3] = { mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2] };
-        mcpNew->setMomentum( p );
+        mcpNew->setPDG(mcp->getPDG());
 
-        mcpNew->setMass( mcp->getMass() );
+        float p[3] = {mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2]};
 
-        double vtx[3] = { mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2] };
-        mcpNew->setVertex( vtx );
+        mcpNew->setMomentum(p);
+        mcpNew->setMass(mcp->getMass());
 
-        mcpNew->setGeneratorStatus( mcp->getGeneratorStatus() );
+        double vtx[3] = {mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2]};
+        mcpNew->setVertex(vtx);
 
-        mcpNew->setSimulatorStatus( 0 );
-
-        mcpNew->setCharge( mcp->getCharge() );
-
-        mcpNew->setTime( mcp->getTime() );
+        mcpNew->setGeneratorStatus(mcp->getGeneratorStatus());
+        mcpNew->setSimulatorStatus(0);
+        mcpNew->setCharge(mcp->getCharge());
+        mcpNew->setTime(mcp->getTime());
 
 #if LCIO_VERSION_GE(1, 60)
-        const float* spin1 = mcp->getSpin();
-        float spin2[3];
-        spin2[0] = spin1[0];
-        spin2[1] = spin1[1];
-        spin2[2] = spin1[2];
-        //std::cout << "spin = " << spin2[0] << ", " << spin2[1] << ", " << spin2[2] << std::endl; // debug
-        mcpNew->setSpin(spin2);
-
-        // TODO: Set colorflow here.
+        copySpinAndColorFlow(mcp, mcpNew);
 #endif
 
         return mcpNew;
@@ -592,22 +586,22 @@
 
         // loop over primary daughters
         G4PrimaryParticle* primDau = primary->GetDaughter();
-        while ( primDau ) {
+        while (primDau) {
 
             // find input Mcp for the primary dau
-            MCParticle* mcpDau = m_manager->getMaps()->findDaughterMcpFromPrimary( mcpInit,
-                                                                                   primDau );
+            MCParticle* mcpDau = m_manager->getMaps()->findDaughterMcpFromPrimary(mcpInit, primDau);
 
             // must find it or die
-            if ( 0 == mcpDau ) {
-                G4Exception( "Mcp daughter was not found." );
+            if (0 == mcpDau)
+            {
+                G4Exception("Mcp daughter was not found.");
             }
 
             // create dau Mcp
-            MCParticleImpl* mcpDauNew = createMcpFromPrimary( primDau, mcpDau );
+            MCParticleImpl* mcpDauNew = createMcpFromPrimary(primDau, mcpDau);
 
             // make mcpPar the parent
-            mcpDauNew->addParent( mcpPar );
+            mcpDauNew->addParent(mcpPar);
 
             // get next primary dau
             primDau = primDau->GetNext();
@@ -623,23 +617,23 @@
 
         int numDau = mcpInit->getDaughters().size();
 
-        for ( int i=0; i < numDau; i++ ) {
-
+        for (int i=0; i < numDau; i++)
+        {
             // child of input particle
             MCParticle* mcpChildInit = mcpInit->getDaughters()[i];
 
             // use a search function to avoid insert when null!
-            MCParticleImpl* mcpChildFinal = m_manager->getMaps()->findFinalParticleFromInitial( mcpChildInit );
+            MCParticleImpl* mcpChildFinal = m_manager->getMaps()->findFinalParticleFromInitial(mcpChildInit);
 
             // if not added already
-            if ( mcpChildFinal == 0 ) {
-
+            if (mcpChildFinal == 0)
+            {
                 // create daughter
-                mcpChildFinal = createMcpFromInitialRecurse( mcpChildInit );
+                mcpChildFinal = createMcpFromInitialRecurse(mcpChildInit);
             }
 
             // add parent regardless of above; maybe new MCP or already created
-            mcpChildFinal->addParent( mcpNew );
+            mcpChildFinal->addParent(mcpNew);
         }
     }
 
@@ -647,26 +641,46 @@
     {
         /* Add endpoint energies to LCGenericObject collection. */
         LcioMcpMaps* maps = LcioMcpManager::instance()->getMaps();
-        LCCollectionVec* epColl = new LCCollectionVec( LCIO::LCGENERICOBJECT );
-        for ( LCCollectionVec::iterator it = mcpColl->begin();
-              it != mcpColl->end();
-              it++ ) {
+        LCCollectionVec* epColl = new LCCollectionVec(LCIO::LCGENERICOBJECT);
+        for (LCCollectionVec::iterator it = mcpColl->begin(); it != mcpColl->end(); it++ ) {
 
             MCParticle* mcp = static_cast<MCParticle*>(*it);
             G4int trkID = maps->findTrackIDFromFinalMcp(mcp);
             double epE = -1.0;
-            if ( trkID != -1 ) {
+            if (trkID != -1)
+            {
                 Trajectory* trj = TrajectoryManager::instance()->findTrajectory(trkID);
 
-                if ( 0 != trj ) {
+                if (0 != trj)
+                {
                     epE = trj->getEndPointEnergy();
                 }
             }
 
             LCGenericObjectImpl* obj = new LCGenericObjectImpl();
-            obj->setFloatVal( 0, epE );
-            epColl->push_back( obj );
+            obj->setFloatVal(0, epE);
+            epColl->push_back(obj);
         }
-        LcioManager::instance()->getCurrentLCEvent()->addCollection( epColl, "MCParticleEndPointEnergy" );
+        LcioManager::instance()->getCurrentLCEvent()->addCollection(epColl, "MCParticleEndPointEnergy");
+    }
+
+#if LCIO_VERSION_GE(1, 60)
+    void LcioMcpFactory::copySpinAndColorFlow(MCParticle* mcp1, MCParticle* mcp2)
+    {
+        // Set spin.
+        const float* spin1 = mcp1->getSpin();
+        float spin2[3];
+        spin2[0] = spin1[0];
+        spin2[1] = spin1[1];
+        spin2[2] = spin1[2];
+        ((IMPL::MCParticleImpl*)mcp2)->setSpin(spin2);
+
+        // Set color flow.
+        const int* cf1 = mcp1->getColorFlow();
+        int cf2[2];
+        cf2[0] = cf1[0];
+        cf2[1] = cf1[1];
+        ((IMPL::MCParticleImpl*)mcp2)->setColorFlow(cf2);
     }
+#endif
 }
CVSspam 0.2.8